Skip to content

Commit

Permalink
refactor(core): move run from CellView to ExecutableCellView
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk committed Sep 18, 2024
1 parent 9387fb3 commit cd81655
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
34 changes: 34 additions & 0 deletions .changeset/cyan-weeks-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
'@difizen/libro-prompt-cell': patch
'@difizen/libro-sql-cell': patch
'@difizen/libro-core': patch
'@difizen/libro-l10n': patch
'@difizen/libro-lab': patch
'@difizen/libro-docs': patch
'@difizen/libro-code-cell': patch
'@difizen/libro-code-editor': patch
'@difizen/libro-codemirror': patch
'@difizen/libro-cofine-editor': patch
'@difizen/libro-cofine-editor-contribution': patch
'@difizen/libro-cofine-editor-core': patch
'@difizen/libro-cofine-textmate': patch
'@difizen/libro-common': patch
'@difizen/libro-jupyter': patch
'@difizen/libro-kernel': patch
'@difizen/libro-language-client': patch
'@difizen/libro-lsp': patch
'@difizen/libro-markdown': patch
'@difizen/libro-markdown-cell': patch
'@difizen/libro-output': patch
'@difizen/libro-raw-cell': patch
'@difizen/libro-rendermime': patch
'@difizen/libro-search': patch
'@difizen/libro-search-code-cell': patch
'@difizen/libro-shared-model': patch
'@difizen/libro-terminal': patch
'@difizen/libro-toc': patch
'@difizen/libro-virtualized': patch
'@difizen/libro-widget': patch
---

1. add sql cell & 2.refactor(core): move run from CellView to ExecutableCellView
4 changes: 0 additions & 4 deletions packages/libro-core/src/cell/libro-cell-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ export class LibroCellModel extends Model implements CellModel {
return { ...this._decodeObject, value: this.value };
}

async run() {
return true;
}

toJSON(): Omit<ICell, 'outputs'> {
return {
id: this.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/libro-core/src/cell/libro-cell-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class LibroCellView extends BaseView implements CellView {
super.dispose();
}
toJSON(): LibroCell {
const meta = { ...(this.model.toJSON() as LibroCell) };
const meta = { ...(this.model.toJSON() as LibroCell), outputs: [] };
const modelContribution = this.cellService.findModelProvider(this.model.options);
if (modelContribution?.cellMeta.nbformatType) {
meta.metadata.libroCellType = modelContribution?.cellMeta.type;
Expand Down
4 changes: 3 additions & 1 deletion packages/libro-core/src/cell/libro-executable-cell-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EditorCellView, LibroEditorCellView } from './libro-edit-cell-view.js';
import { ExecutableCellModel } from './libro-executable-cell-model.js';

interface ExecutableCellView extends EditorCellView {
run: () => Promise<boolean>;
clearExecution: () => void;

outputArea: BaseOutputArea;
Expand All @@ -27,7 +28,8 @@ export const ExecutableCellView = {
'outputArea' in arg &&
typeof (arg as any).outputArea === 'object' &&
'clearExecution' in arg &&
typeof (arg as any).clearExecution === 'function'
typeof (arg as any).clearExecution === 'function' &&
typeof (arg as any).run === 'function'
);
},
};
Expand Down
2 changes: 0 additions & 2 deletions packages/libro-core/src/libro-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@ export interface CellView extends View {
blur: () => void;
focus: (isEdit: boolean) => void;

run: () => Promise<boolean>;

shouldEnterEditorMode: (e: React.FocusEvent<HTMLElement>) => boolean;

hasCellHidden: () => boolean;
Expand Down
11 changes: 6 additions & 5 deletions packages/libro-core/src/libro-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ export class LibroView extends BaseView implements NotebookView {

executeCellRun(cell: CellView) {
this.runCellEmitter.fire(cell);
return cell.run();
if (ExecutableCellView.is(cell)) {
return cell.run();
} else {
return undefined;
}
}

runCells = async (cells: CellView[]) => {
Expand All @@ -594,10 +598,7 @@ export class LibroView extends BaseView implements NotebookView {

return Promise.all(
cells.map((cell) => {
if (ExecutableCellModel.is(cell.model)) {
return this.executeCellRun(cell);
}
return undefined;
return this.executeCellRun(cell);
}),
)
.then((resultList) => {
Expand Down

0 comments on commit cd81655

Please sign in to comment.