From 83cad8e07619a5ac55b1ef3a7920cc9b025f6fcc Mon Sep 17 00:00:00 2001 From: sunshinesmilelk <1176136681@qq.com> Date: Thu, 17 Oct 2024 12:04:59 +0800 Subject: [PATCH] fix(core): outputs should not be included for editable cell --- packages/libro-core/src/cell/libro-cell-view.tsx | 2 +- .../libro-core/src/cell/libro-executable-cell-view.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/libro-core/src/cell/libro-cell-view.tsx b/packages/libro-core/src/cell/libro-cell-view.tsx index 08b85c65..e6c6bc27 100644 --- a/packages/libro-core/src/cell/libro-cell-view.tsx +++ b/packages/libro-core/src/cell/libro-cell-view.tsx @@ -137,7 +137,7 @@ export class LibroCellView extends BaseView implements CellView { super.dispose(); } toJSON(): LibroCell { - const meta = { ...(this.model.toJSON() as LibroCell), outputs: [] }; + const meta = { ...(this.model.toJSON() as LibroCell) }; const modelContribution = this.cellService.findModelProvider(this.model.options); if (modelContribution?.cellMeta.nbformatType) { meta.metadata.libroCellType = modelContribution?.cellMeta.type; diff --git a/packages/libro-core/src/cell/libro-executable-cell-view.ts b/packages/libro-core/src/cell/libro-executable-cell-view.ts index 59cd6511..892e7b51 100644 --- a/packages/libro-core/src/cell/libro-executable-cell-view.ts +++ b/packages/libro-core/src/cell/libro-executable-cell-view.ts @@ -1,3 +1,4 @@ +import type { ICodeCell } from '@difizen/libro-common'; import { watch } from '@difizen/mana-app'; import { ViewOption } from '@difizen/mana-app'; import { inject } from '@difizen/mana-app'; @@ -6,6 +7,7 @@ import type { CellModel } from '../libro-protocol.js'; import type { CellViewOptions } from '../libro-protocol.js'; import type { BaseOutputArea } from '../output/index.js'; +import type { LibroCell } from './libro-cell-protocol.js'; import { CellService } from './libro-cell-protocol.js'; import { EditorCellView, LibroEditorCellView } from './libro-edit-cell-view.js'; import { ExecutableCellModel } from './libro-executable-cell-model.js'; @@ -78,6 +80,15 @@ export abstract class LibroEditableExecutableCellView }), ); } + + override toJSON(): LibroCell { + const meta = super.toJSON(); + return { + ...meta, + source: meta.source ?? this.options.cell.source, + outputs: this.outputArea?.toJSON() ?? [], + } as ICodeCell; + } } /**