Skip to content

Commit 6b18588

Browse files
committed
WIP: filtering; cell type-checking issue
1 parent afb459e commit 6b18588

5 files changed

Lines changed: 46 additions & 37 deletions

File tree

packages/frontend/src/analysis/analysis_editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function AnalysisNotebookEditor(props: { liveAnalysis: LiveAnalysisDoc })
3737
notebook={liveDoc().doc.notebook}
3838
changeNotebook={(f) => liveDoc().changeDoc((doc) => f(doc.notebook))}
3939
formalCellEditor={AnalysisCellEditor}
40-
cellConstructors={cellConstructors()}
40+
cellConstructors={cellConstructors}
4141
noShortcuts={true}
4242
/>
4343
</LiveAnalysisContext.Provider>

packages/frontend/src/diagram/diagram_editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function DiagramNotebookEditor(props: { liveDiagram: LiveDiagramDoc }) {
4141
liveDoc().changeDoc((doc) => f(doc.notebook));
4242
}}
4343
formalCellEditor={DiagramCellEditor}
44-
cellConstructors={cellConstructors()}
44+
cellConstructors={cellConstructors}
4545
cellLabel={judgmentLabel}
4646
duplicateCell={duplicateDiagramJudgment}
4747
/>

packages/frontend/src/model/model_editor.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ import {
2626
export function ModelNotebookEditor(props: { liveModel: LiveModelDoc }) {
2727
const liveDoc = () => props.liveModel.liveDoc;
2828

29-
const cellConstructors = () => {
30-
// const cells = liveDoc().doc.notebook.cellOrder;
31-
// console.log(cells);
32-
29+
const cellConstructors = (cellType?: string, cellName?: string) => {
3330
const theory = props.liveModel.theory();
34-
return theory ? modelCellConstructors(theory) : [];
31+
return theory ? modelCellConstructors(theory, cellType, cellName) : [];
3532
};
3633

3734
return (
@@ -44,7 +41,7 @@ export function ModelNotebookEditor(props: { liveModel: LiveModelDoc }) {
4441
liveDoc().changeDoc((doc) => f(doc.notebook));
4542
}}
4643
formalCellEditor={ModelCellEditor}
47-
cellConstructors={cellConstructors()}
44+
cellConstructors={cellConstructors}
4845
cellLabel={judgmentLabel}
4946
duplicateCell={duplicateModelJudgment}
5047
/>
@@ -57,7 +54,6 @@ export function ModelCellEditor(props: FormalCellEditorProps<ModelJudgment>) {
5754
const liveModel = useContext(LiveModelContext);
5855
invariant(liveModel, "Live model should be provided as context");
5956

60-
console.log(props);
6157
return (
6258
<Switch>
6359
<Match when={props.content.tag === "object" && liveModel().theory()}>
@@ -98,9 +94,9 @@ export function ModelCellEditor(props: FormalCellEditorProps<ModelJudgment>) {
9894
);
9995
}
10096

101-
function modelCellConstructors(theory: Theory): CellConstructor<ModelJudgment>[] {
97+
function modelCellConstructors(theory: Theory, cellType?: string, cellName?: string): CellConstructor<ModelJudgment>[] {
10298
const constructors: CellConstructor<ModelJudgment>[] = [];
103-
if (theory.theory.canInstantiateModels()) {
99+
if (theory.theory.canInstantiateModels() && !cellType && !cellName) {
104100
constructors.push({
105101
name: "Instantiate",
106102
description: "Instantiate an existing model into this one",
@@ -111,8 +107,14 @@ function modelCellConstructors(theory: Theory): CellConstructor<ModelJudgment>[]
111107
});
112108
}
113109

114-
for (const meta of theory.modelTypes ?? []) {
115-
constructors.push(modelCellConstructor(meta));
110+
for (const meta of theory.modelTypes ?? []) {
111+
if (cellName && cellType) {
112+
if ((meta.name !== cellName) && (meta.tag == cellType)) {
113+
constructors.push(modelCellConstructor(meta))
114+
}
115+
} else {
116+
constructors.push(modelCellConstructor(meta))
117+
}
116118
}
117119
return constructors;
118120
}

packages/frontend/src/notebook/notebook_cell.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@
5050
/* border-radius: 50%; */
5151
top: -2px;
5252
}
53+
54+
button.plain {
55+
background: transparent;
56+
border: none;
57+
color: darkgray;
58+
font-size: 11pt;
59+
}

packages/frontend/src/notebook/notebook_editor.tsx

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function NotebookEditor<T>(props: {
7272
changeNotebook: (f: (nb: Notebook<T>) => void) => void;
7373

7474
formalCellEditor: Component<FormalCellEditorProps<T>>;
75-
cellConstructors?: CellConstructor<T>[];
75+
cellConstructors: (cellType?: string, cellName?: string) => CellConstructor<T>[];
7676
cellLabel?: (content: T) => string | undefined;
7777

7878
/** Called to duplicate an existing cell.
@@ -163,17 +163,16 @@ export function NotebookEditor<T>(props: {
163163
props.changeNotebook((nb) => {
164164
NotebookUtils.retypeCell(nb, i, mutator);
165165
});
166-
setActiveCell(i);
167166
};
168167

169-
const cellConstructors = (): CellConstructor<T>[] => [
170-
{
171-
name: "Text",
172-
description: "Start writing text",
173-
shortcut: ["T"],
174-
construct: () => newRichTextCell(),
175-
},
176-
...(props.cellConstructors ?? []),
168+
const cellConstructors = (cellType?: string, cellName?: string): CellConstructor<T>[] => [
169+
...((cellType && cellName) ? [] : [{
170+
name: "Text",
171+
description: "Start writing text",
172+
shortcut: ["T"],
173+
construct: () => newRichTextCell(),
174+
}]),
175+
...(props.cellConstructors(cellType, cellName) ?? []),
177176
];
178177

179178
const replaceCommands = (i: number): Completion[] =>
@@ -187,8 +186,8 @@ export function NotebookEditor<T>(props: {
187186
};
188187
});
189188

190-
const retypeCommands = (i: number): Completion[] =>
191-
cellConstructors().map((cc) => {
189+
const retypeCommands = (i: number, cellType?: string, cellName?: string): Completion[] =>
190+
cellConstructors(cellType, cellName).map((cc) => {
192191
const { name, description, shortcut } = cc;
193192
return {
194193
name,
@@ -327,18 +326,21 @@ export function NotebookEditor<T>(props: {
327326
const cell = props.notebook.cellContents[cellId];
328327
invariant(cell, `Failed to find contents for cell '${cellId}'`);
329328

330-
// const tag = (cell.tag === "formal" ? props.cellLabel?.(cell.content) : undefined) as string;
331329
const cellName = (cell: Cell<T>) =>
332330
(cell.tag === "formal"
333331
? props.cellLabel?.(cell.content)
334332
: undefined) as string;
335-
// const cellType = isFormalCell(cell)
336-
// ? isObType(cell.content)
337-
// ? "ObType"
338-
// : isMorType(cell.content)
339-
// ? "MorType"
340-
// : ""
341-
// : "";
333+
334+
const cellType = (cell: Cell<T>) =>
335+
cell.tag === "formal" ? ((isObType(cell.content)) ? "ObType" : "MorType") : undefined;
336+
337+
// if (isObType(cellContent) && isObType(newCell.content)) {
338+
// cellContent.obType = newCell.content.obType;
339+
// } else if (isMorType(cellContent) && isMorType(newCell.content)) {
340+
// cellContent.morType = newCell.content.morType;
341+
// }
342+
343+
// const cellType = "ObType";
342344

343345
if (cell.tag !== "rich-text") {
344346
cellActions.duplicate = () => {
@@ -360,13 +362,11 @@ export function NotebookEditor<T>(props: {
360362
cellId={cell.id}
361363
index={i()}
362364
actions={cellActions}
363-
tag={
364-
cellName(cell)
365-
}
365+
tag={cellName(cell)}
366366
currentDropTarget={currentDropTarget()}
367367
setCurrentDropTarget={setCurrentDropTarget}
368368
isActive={isActive()}
369-
replaceCommands={retypeCommands(i())}
369+
replaceCommands={retypeCommands(i(), cellType(cell), cellName(cell))}
370370
>
371371
<Switch>
372372
<Match when={cell.tag === "rich-text"}>

0 commit comments

Comments
 (0)