@difizen/libro-core 0.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/es/add-cell/index.d.ts +4 -0
- package/es/add-cell/index.d.ts.map +1 -0
- package/es/add-cell/index.js +3 -0
- package/es/add-cell/index.less +38 -0
- package/es/add-cell/libro-add-cell-module.d.ts +3 -0
- package/es/add-cell/libro-add-cell-module.d.ts.map +1 -0
- package/es/add-cell/libro-add-cell-module.js +4 -0
- package/es/add-cell/libro-add-cell-slot-contribution.d.ts +12 -0
- package/es/add-cell/libro-add-cell-slot-contribution.d.ts.map +1 -0
- package/es/add-cell/libro-add-cell-slot-contribution.js +53 -0
- package/es/add-cell/libro-add-cell-view.d.ts +21 -0
- package/es/add-cell/libro-add-cell-view.d.ts.map +1 -0
- package/es/add-cell/libro-add-cell-view.js +129 -0
- package/es/cell/index.d.ts +10 -0
- package/es/cell/index.d.ts.map +1 -0
- package/es/cell/index.js +9 -0
- package/es/cell/libro-cell-contribution.d.ts +13 -0
- package/es/cell/libro-cell-contribution.d.ts.map +1 -0
- package/es/cell/libro-cell-contribution.js +41 -0
- package/es/cell/libro-cell-model.d.ts +19 -0
- package/es/cell/libro-cell-model.d.ts.map +1 -0
- package/es/cell/libro-cell-model.js +103 -0
- package/es/cell/libro-cell-module.d.ts +10 -0
- package/es/cell/libro-cell-module.d.ts.map +1 -0
- package/es/cell/libro-cell-module.js +30 -0
- package/es/cell/libro-cell-protocol.d.ts +42 -0
- package/es/cell/libro-cell-protocol.d.ts.map +1 -0
- package/es/cell/libro-cell-protocol.js +11 -0
- package/es/cell/libro-cell-service.d.ts +28 -0
- package/es/cell/libro-cell-service.d.ts.map +1 -0
- package/es/cell/libro-cell-service.js +242 -0
- package/es/cell/libro-cell-view.d.ts +65 -0
- package/es/cell/libro-cell-view.d.ts.map +1 -0
- package/es/cell/libro-cell-view.js +191 -0
- package/es/cell/libro-edit-cell-view.d.ts +32 -0
- package/es/cell/libro-edit-cell-view.d.ts.map +1 -0
- package/es/cell/libro-edit-cell-view.js +72 -0
- package/es/cell/libro-executable-cell-model.d.ts +14 -0
- package/es/cell/libro-executable-cell-model.d.ts.map +1 -0
- package/es/cell/libro-executable-cell-model.js +7 -0
- package/es/cell/libro-executable-cell-view.d.ts +27 -0
- package/es/cell/libro-executable-cell-view.d.ts.map +1 -0
- package/es/cell/libro-executable-cell-view.js +66 -0
- package/es/cell/libro-markdown-cell-model.d.ts +9 -0
- package/es/cell/libro-markdown-cell-model.d.ts.map +1 -0
- package/es/cell/libro-markdown-cell-model.js +7 -0
- package/es/collapse-service.d.ts +36 -0
- package/es/collapse-service.d.ts.map +1 -0
- package/es/collapse-service.js +55 -0
- package/es/command/document-commands.d.ts +6 -0
- package/es/command/document-commands.d.ts.map +1 -0
- package/es/command/document-commands.js +13 -0
- package/es/command/index.d.ts +7 -0
- package/es/command/index.d.ts.map +1 -0
- package/es/command/index.js +6 -0
- package/es/command/kernel-command.d.ts +5 -0
- package/es/command/kernel-command.d.ts.map +1 -0
- package/es/command/kernel-command.js +39 -0
- package/es/command/libro-command-contribution.d.ts +14 -0
- package/es/command/libro-command-contribution.d.ts.map +1 -0
- package/es/command/libro-command-contribution.js +1751 -0
- package/es/command/libro-command-register.d.ts +22 -0
- package/es/command/libro-command-register.d.ts.map +1 -0
- package/es/command/libro-command-register.js +105 -0
- package/es/command/module.d.ts +3 -0
- package/es/command/module.d.ts.map +1 -0
- package/es/command/module.js +4 -0
- package/es/command/notebook-commands.d.ts +6 -0
- package/es/command/notebook-commands.d.ts.map +1 -0
- package/es/command/notebook-commands.js +468 -0
- package/es/components/cell-protocol.d.ts +20 -0
- package/es/components/cell-protocol.d.ts.map +1 -0
- package/es/components/cell-protocol.js +4 -0
- package/es/components/dnd-cell-item-render.d.ts +12 -0
- package/es/components/dnd-cell-item-render.d.ts.map +1 -0
- package/es/components/dnd-cell-item-render.js +253 -0
- package/es/components/dnd-component/custom-drag-layer.d.ts +9 -0
- package/es/components/dnd-component/custom-drag-layer.d.ts.map +1 -0
- package/es/components/dnd-component/custom-drag-layer.js +141 -0
- package/es/components/dnd-component/default-dnd-content.d.ts +10 -0
- package/es/components/dnd-component/default-dnd-content.d.ts.map +1 -0
- package/es/components/dnd-component/default-dnd-content.js +257 -0
- package/es/components/dnd-component/dnd-context.d.ts +3 -0
- package/es/components/dnd-component/dnd-context.d.ts.map +1 -0
- package/es/components/dnd-component/dnd-context.js +20 -0
- package/es/components/dnd-component/dnd-list.d.ts +10 -0
- package/es/components/dnd-component/dnd-list.d.ts.map +1 -0
- package/es/components/dnd-component/dnd-list.js +115 -0
- package/es/components/dnd-component/index.d.ts +5 -0
- package/es/components/dnd-component/index.d.ts.map +1 -0
- package/es/components/dnd-component/index.js +4 -0
- package/es/components/index.d.ts +6 -0
- package/es/components/index.d.ts.map +1 -0
- package/es/components/index.js +5 -0
- package/es/components/libro-component.d.ts +5 -0
- package/es/components/libro-component.d.ts.map +1 -0
- package/es/components/libro-component.js +35 -0
- package/es/components/libro-side-toolbar-menu.d.ts +21 -0
- package/es/components/libro-side-toolbar-menu.d.ts.map +1 -0
- package/es/components/libro-side-toolbar-menu.js +58 -0
- package/es/components/libro-view-header.d.ts +3 -0
- package/es/components/libro-view-header.d.ts.map +1 -0
- package/es/components/libro-view-header.js +37 -0
- package/es/configuration/libro-configuration-contribution.d.ts +5 -0
- package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
- package/es/configuration/libro-configuration-contribution.js +24 -0
- package/es/configuration/libro-configuration.d.ts +10 -0
- package/es/configuration/libro-configuration.d.ts.map +1 -0
- package/es/configuration/libro-configuration.js +81 -0
- package/es/content/index.d.ts +5 -0
- package/es/content/index.d.ts.map +1 -0
- package/es/content/index.js +4 -0
- package/es/content/libro-content-contribution.d.ts +11 -0
- package/es/content/libro-content-contribution.d.ts.map +1 -0
- package/es/content/libro-content-contribution.js +32 -0
- package/es/content/libro-content-module.d.ts +3 -0
- package/es/content/libro-content-module.d.ts.map +1 -0
- package/es/content/libro-content-module.js +5 -0
- package/es/content/libro-content-protocol.d.ts +8 -0
- package/es/content/libro-content-protocol.d.ts.map +1 -0
- package/es/content/libro-content-protocol.js +2 -0
- package/es/content/libro-content-service.d.ts +9 -0
- package/es/content/libro-content-service.d.ts.map +1 -0
- package/es/content/libro-content-service.js +35 -0
- package/es/index.d.ts +20 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +19 -0
- package/es/index.less +682 -0
- package/es/libro-context-key.d.ts +22 -0
- package/es/libro-context-key.d.ts.map +1 -0
- package/es/libro-context-key.js +80 -0
- package/es/libro-keybind-registry.d.ts +5 -0
- package/es/libro-keybind-registry.d.ts.map +1 -0
- package/es/libro-keybind-registry.js +68 -0
- package/es/libro-model.d.ts +129 -0
- package/es/libro-model.d.ts.map +1 -0
- package/es/libro-model.js +803 -0
- package/es/libro-protocol.d.ts +241 -0
- package/es/libro-protocol.d.ts.map +1 -0
- package/es/libro-protocol.js +34 -0
- package/es/libro-service.d.ts +34 -0
- package/es/libro-service.d.ts.map +1 -0
- package/es/libro-service.js +180 -0
- package/es/libro-view-tracker.d.ts +6 -0
- package/es/libro-view-tracker.d.ts.map +1 -0
- package/es/libro-view-tracker.js +13 -0
- package/es/libro-view.d.ts +151 -0
- package/es/libro-view.d.ts.map +1 -0
- package/es/libro-view.js +1963 -0
- package/es/material-from-designer.d.ts +27 -0
- package/es/material-from-designer.d.ts.map +1 -0
- package/es/material-from-designer.js +550 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +55 -0
- package/es/output/index.d.ts +6 -0
- package/es/output/index.d.ts.map +1 -0
- package/es/output/index.js +5 -0
- package/es/output/output-area.d.ts +51 -0
- package/es/output/output-area.d.ts.map +1 -0
- package/es/output/output-area.js +346 -0
- package/es/output/output-contribution.d.ts +11 -0
- package/es/output/output-contribution.d.ts.map +1 -0
- package/es/output/output-contribution.js +31 -0
- package/es/output/output-model.d.ts +27 -0
- package/es/output/output-model.d.ts.map +1 -0
- package/es/output/output-model.js +95 -0
- package/es/output/output-module.d.ts +3 -0
- package/es/output/output-module.d.ts.map +1 -0
- package/es/output/output-module.js +6 -0
- package/es/output/output-protocol.d.ts +130 -0
- package/es/output/output-protocol.d.ts.map +1 -0
- package/es/output/output-protocol.js +18 -0
- package/es/slot/index.d.ts +5 -0
- package/es/slot/index.d.ts.map +1 -0
- package/es/slot/index.js +4 -0
- package/es/slot/libro-slot-manager.d.ts +13 -0
- package/es/slot/libro-slot-manager.d.ts.map +1 -0
- package/es/slot/libro-slot-manager.js +57 -0
- package/es/slot/libro-slot-protocol.d.ts +19 -0
- package/es/slot/libro-slot-protocol.d.ts.map +1 -0
- package/es/slot/libro-slot-protocol.js +5 -0
- package/es/slot/libro-slot-view.d.ts +9 -0
- package/es/slot/libro-slot-view.d.ts.map +1 -0
- package/es/slot/libro-slot-view.js +81 -0
- package/es/slot/module.d.ts +3 -0
- package/es/slot/module.d.ts.map +1 -0
- package/es/slot/module.js +5 -0
- package/es/theme/libro-color-registry.d.ts +6 -0
- package/es/theme/libro-color-registry.d.ts.map +1 -0
- package/es/theme/libro-color-registry.js +494 -0
- package/es/toolbar/change-cell-to-selector.d.ts +5 -0
- package/es/toolbar/change-cell-to-selector.d.ts.map +1 -0
- package/es/toolbar/change-cell-to-selector.js +48 -0
- package/es/toolbar/hide-all-selector.d.ts +5 -0
- package/es/toolbar/hide-all-selector.d.ts.map +1 -0
- package/es/toolbar/hide-all-selector.js +99 -0
- package/es/toolbar/index.d.ts +4 -0
- package/es/toolbar/index.d.ts.map +1 -0
- package/es/toolbar/index.js +3 -0
- package/es/toolbar/index.less +59 -0
- package/es/toolbar/libro-toolbar-protocol.d.ts +4 -0
- package/es/toolbar/libro-toolbar-protocol.d.ts.map +1 -0
- package/es/toolbar/libro-toolbar-protocol.js +1 -0
- package/es/toolbar/libro-toolbar.d.ts +8 -0
- package/es/toolbar/libro-toolbar.d.ts.map +1 -0
- package/es/toolbar/libro-toolbar.js +223 -0
- package/es/toolbar/module.d.ts +3 -0
- package/es/toolbar/module.d.ts.map +1 -0
- package/es/toolbar/module.js +5 -0
- package/es/toolbar/restart-clear-outputs-contribution.d.ts +5 -0
- package/es/toolbar/restart-clear-outputs-contribution.d.ts.map +1 -0
- package/es/toolbar/restart-clear-outputs-contribution.js +23 -0
- package/es/toolbar/restart-clear-outputs-modal.d.ts +6 -0
- package/es/toolbar/restart-clear-outputs-modal.d.ts.map +1 -0
- package/es/toolbar/restart-clear-outputs-modal.js +30 -0
- package/es/toolbar/save-icon.d.ts +3 -0
- package/es/toolbar/save-icon.d.ts.map +1 -0
- package/es/toolbar/save-icon.js +54 -0
- package/es/toolbar/shutdown-contribution.d.ts +5 -0
- package/es/toolbar/shutdown-contribution.d.ts.map +1 -0
- package/es/toolbar/shutdown-contribution.js +23 -0
- package/es/toolbar/shutdown-modal.d.ts +6 -0
- package/es/toolbar/shutdown-modal.d.ts.map +1 -0
- package/es/toolbar/shutdown-modal.js +30 -0
- package/es/toolbar/side-toolar-more-select.d.ts +4 -0
- package/es/toolbar/side-toolar-more-select.d.ts.map +1 -0
- package/es/toolbar/side-toolar-more-select.js +161 -0
- package/es/typings/index.d.ts +1 -0
- package/package.json +70 -0
- package/src/add-cell/index.less +38 -0
- package/src/add-cell/index.ts +3 -0
- package/src/add-cell/libro-add-cell-module.ts +9 -0
- package/src/add-cell/libro-add-cell-slot-contribution.ts +31 -0
- package/src/add-cell/libro-add-cell-view.tsx +101 -0
- package/src/cell/README.md +14 -0
- package/src/cell/index.ts +9 -0
- package/src/cell/libro-cell-contribution.ts +38 -0
- package/src/cell/libro-cell-model.ts +61 -0
- package/src/cell/libro-cell-module.ts +40 -0
- package/src/cell/libro-cell-protocol.ts +53 -0
- package/src/cell/libro-cell-service.ts +157 -0
- package/src/cell/libro-cell-view.tsx +128 -0
- package/src/cell/libro-edit-cell-view.tsx +60 -0
- package/src/cell/libro-executable-cell-model.ts +32 -0
- package/src/cell/libro-executable-cell-view.ts +74 -0
- package/src/cell/libro-markdown-cell-model.ts +20 -0
- package/src/collapse-service.ts +69 -0
- package/src/command/document-commands.ts +18 -0
- package/src/command/index.ts +6 -0
- package/src/command/kernel-command.ts +41 -0
- package/src/command/libro-command-contribution.ts +1339 -0
- package/src/command/libro-command-register.ts +171 -0
- package/src/command/module.ts +9 -0
- package/src/command/notebook-commands.ts +498 -0
- package/src/components/cell-protocol.ts +22 -0
- package/src/components/dnd-cell-item-render.tsx +308 -0
- package/src/components/dnd-component/custom-drag-layer.tsx +145 -0
- package/src/components/dnd-component/default-dnd-content.tsx +275 -0
- package/src/components/dnd-component/dnd-context.tsx +28 -0
- package/src/components/dnd-component/dnd-list.tsx +116 -0
- package/src/components/dnd-component/index.tsx +4 -0
- package/src/components/index.ts +5 -0
- package/src/components/libro-component.tsx +30 -0
- package/src/components/libro-side-toolbar-menu.tsx +82 -0
- package/src/components/libro-view-header.tsx +33 -0
- package/src/configuration/libro-configuration-contribution.ts +29 -0
- package/src/configuration/libro-configuration.ts +88 -0
- package/src/content/index.ts +4 -0
- package/src/content/libro-content-contribution.ts +17 -0
- package/src/content/libro-content-module.ts +9 -0
- package/src/content/libro-content-protocol.ts +8 -0
- package/src/content/libro-content-service.ts +30 -0
- package/src/index.less +682 -0
- package/src/index.tsx +19 -0
- package/src/libro-context-key.ts +80 -0
- package/src/libro-keybind-registry.ts +43 -0
- package/src/libro-model.ts +614 -0
- package/src/libro-protocol.ts +322 -0
- package/src/libro-service.ts +121 -0
- package/src/libro-view-tracker.ts +9 -0
- package/src/libro-view.tsx +1399 -0
- package/src/material-from-designer.tsx +457 -0
- package/src/module.ts +90 -0
- package/src/output/index.ts +5 -0
- package/src/output/output-area.tsx +255 -0
- package/src/output/output-contribution.ts +18 -0
- package/src/output/output-model.tsx +66 -0
- package/src/output/output-module.ts +10 -0
- package/src/output/output-protocol.ts +164 -0
- package/src/slot/index.ts +4 -0
- package/src/slot/libro-slot-manager.ts +37 -0
- package/src/slot/libro-slot-protocol.ts +28 -0
- package/src/slot/libro-slot-view.tsx +51 -0
- package/src/slot/module.ts +9 -0
- package/src/theme/libro-color-registry.ts +371 -0
- package/src/toolbar/change-cell-to-selector.tsx +58 -0
- package/src/toolbar/hide-all-selector.tsx +126 -0
- package/src/toolbar/index.less +59 -0
- package/src/toolbar/index.ts +3 -0
- package/src/toolbar/libro-toolbar-protocol.ts +4 -0
- package/src/toolbar/libro-toolbar.tsx +192 -0
- package/src/toolbar/module.ts +11 -0
- package/src/toolbar/restart-clear-outputs-contribution.tsx +10 -0
- package/src/toolbar/restart-clear-outputs-modal.tsx +37 -0
- package/src/toolbar/save-icon.tsx +47 -0
- package/src/toolbar/shutdown-contribution.tsx +10 -0
- package/src/toolbar/shutdown-modal.tsx +37 -0
- package/src/toolbar/side-toolar-more-select.tsx +172 -0
- package/src/typings/index.d.ts +1 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { Priority, prop } from '@difizen/mana-app';
|
|
3
|
+
import { ApplicationContribution, ViewManager } from '@difizen/mana-app';
|
|
4
|
+
import { contrib, inject, singleton } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
import type { CellView, CellModel, CellOptions } from '../libro-protocol.js';
|
|
7
|
+
import { LibroService } from '../libro-service.js';
|
|
8
|
+
|
|
9
|
+
import type { CellMeta } from './libro-cell-protocol.js';
|
|
10
|
+
import {
|
|
11
|
+
CellService,
|
|
12
|
+
getLibroCellType,
|
|
13
|
+
CellViewContribution,
|
|
14
|
+
CellModelContribution,
|
|
15
|
+
} from './libro-cell-protocol.js';
|
|
16
|
+
|
|
17
|
+
@singleton({ contrib: [CellService, ApplicationContribution] })
|
|
18
|
+
export class LibroCellService implements CellService, ApplicationContribution {
|
|
19
|
+
@prop()
|
|
20
|
+
cellsMeta: CellMeta[] = [];
|
|
21
|
+
|
|
22
|
+
protected readonly modelProvider: Contribution.Provider<CellModelContribution>;
|
|
23
|
+
protected readonly viewProvider: Contribution.Provider<CellViewContribution>;
|
|
24
|
+
protected cellTypeToModelContribution: Map<string, CellModelContribution> = new Map();
|
|
25
|
+
protected readonly viewManager: ViewManager;
|
|
26
|
+
protected modelCache: Map<string, Map<string, CellModel>> = new Map();
|
|
27
|
+
|
|
28
|
+
libroService: LibroService;
|
|
29
|
+
constructor(
|
|
30
|
+
@inject(ViewManager)
|
|
31
|
+
viewManager: ViewManager,
|
|
32
|
+
@inject(LibroService) libroService: LibroService,
|
|
33
|
+
@contrib(CellModelContribution)
|
|
34
|
+
modelProvider: Contribution.Provider<CellModelContribution>,
|
|
35
|
+
@contrib(CellViewContribution)
|
|
36
|
+
viewProvider: Contribution.Provider<CellViewContribution>,
|
|
37
|
+
) {
|
|
38
|
+
this.modelProvider = modelProvider;
|
|
39
|
+
this.viewProvider = viewProvider;
|
|
40
|
+
this.viewManager = viewManager;
|
|
41
|
+
this.libroService = libroService;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected getContributionDefaultCellOption(ctb: CellModelContribution): CellOptions {
|
|
45
|
+
if (ctb.getDefaultCellOption) {
|
|
46
|
+
return ctb.getDefaultCellOption();
|
|
47
|
+
}
|
|
48
|
+
return this.cellTypeToOption(ctb.cellMeta.type);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
initialize() {
|
|
52
|
+
const prioritized = this.getDefaultOptionModelContributionPrioritized();
|
|
53
|
+
const metas: CellMeta[] = [];
|
|
54
|
+
prioritized.forEach((item) => {
|
|
55
|
+
if (!this.cellTypeToModelContribution.get(item.cellMeta.type)) {
|
|
56
|
+
this.cellTypeToModelContribution.set(item.cellMeta.type, item);
|
|
57
|
+
metas.push(item.cellMeta);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.cellsMeta = metas;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getDefaultCellOption(cellType: string) {
|
|
64
|
+
const contribution = this.cellTypeToModelContribution.get(cellType);
|
|
65
|
+
if (!contribution) {
|
|
66
|
+
throw new Error(`no cell model contribution found for cell type ${cellType}`);
|
|
67
|
+
}
|
|
68
|
+
return this.getContributionDefaultCellOption(contribution);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected cellTypeToOption(cellType: string): CellOptions {
|
|
72
|
+
return { cell: { cell_type: cellType, source: '', metadata: {} } };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getModelFromCache(groupId: string, modelId: string) {
|
|
76
|
+
return this.modelCache.get(groupId)?.get(modelId);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
async getOrCreateModel(options: CellOptions, cacheGroupId = ''): Promise<CellModel> {
|
|
81
|
+
let cellmodelCache = this.modelCache.get(cacheGroupId);
|
|
82
|
+
|
|
83
|
+
if (!cellmodelCache) {
|
|
84
|
+
cellmodelCache = new Map();
|
|
85
|
+
this.modelCache.set(cacheGroupId, cellmodelCache);
|
|
86
|
+
}
|
|
87
|
+
if (options.modelId) {
|
|
88
|
+
const exist = this.modelCache.get(cacheGroupId)?.get(options.modelId);
|
|
89
|
+
if (exist) {
|
|
90
|
+
return exist;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const modelProvider = this.findModelProvider(options);
|
|
94
|
+
if (!modelProvider) {
|
|
95
|
+
throw new Error('no cell model provider found');
|
|
96
|
+
}
|
|
97
|
+
const model = await modelProvider.createModel(options);
|
|
98
|
+
cellmodelCache.set(model.id, model);
|
|
99
|
+
return model;
|
|
100
|
+
}
|
|
101
|
+
async getOrCreateView(options: CellOptions, parentId: string): Promise<CellView> {
|
|
102
|
+
const model = await this.getOrCreateModel(options, parentId);
|
|
103
|
+
const viewProvider = this.findViewProvider(options);
|
|
104
|
+
if (!viewProvider) {
|
|
105
|
+
throw new Error('no cell view provider found');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const cellViewPromise = this.viewManager.getOrCreateView(viewProvider.view, {
|
|
109
|
+
...options,
|
|
110
|
+
modelId: model.id,
|
|
111
|
+
parentId: parentId,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const cellView = await cellViewPromise;
|
|
115
|
+
const parent = this.libroService.getViewCache().get(parentId);
|
|
116
|
+
if (parent) {
|
|
117
|
+
cellView.parent = parent;
|
|
118
|
+
}
|
|
119
|
+
return cellView;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
findViewProvider(options: CellOptions): CellViewContribution | undefined {
|
|
123
|
+
const prioritized = Priority.sortSync(
|
|
124
|
+
this.viewProvider.getContributions(),
|
|
125
|
+
(contribution) => this.canHandleOption(contribution, options),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const sorted = prioritized.map((c) => c.value);
|
|
129
|
+
return sorted[0];
|
|
130
|
+
}
|
|
131
|
+
findModelProvider(options: CellOptions): CellModelContribution | undefined {
|
|
132
|
+
const prioritized = Priority.sortSync(
|
|
133
|
+
this.modelProvider.getContributions(),
|
|
134
|
+
(contribution) => this.canHandleOption(contribution, options),
|
|
135
|
+
);
|
|
136
|
+
const sorted = prioritized.map((c) => c.value);
|
|
137
|
+
return sorted[0];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected getDefaultOptionModelContributionPrioritized(): CellModelContribution[] {
|
|
141
|
+
const prioritized = Priority.sortSync(
|
|
142
|
+
this.modelProvider.getContributions(),
|
|
143
|
+
(contribution) => {
|
|
144
|
+
const options = this.getContributionDefaultCellOption(contribution);
|
|
145
|
+
return this.canHandleOption(contribution, options);
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
const sorted = prioritized.map((c) => c.value);
|
|
149
|
+
return sorted;
|
|
150
|
+
}
|
|
151
|
+
protected canHandleOption(
|
|
152
|
+
ctb: CellModelContribution | CellViewContribution,
|
|
153
|
+
options: CellOptions,
|
|
154
|
+
) {
|
|
155
|
+
return ctb.canHandle(options, getLibroCellType(options));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { ViewComponent } from '@difizen/mana-app';
|
|
2
|
+
import { useInject, watch } from '@difizen/mana-app';
|
|
3
|
+
import { BaseView, view, ViewInstance, ViewOption } from '@difizen/mana-app';
|
|
4
|
+
import { inject } from '@difizen/mana-app';
|
|
5
|
+
import { DisposableCollection } from '@difizen/mana-app';
|
|
6
|
+
import { prop } from '@difizen/mana-app';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import type { CellViewOptions, CellModel } from '../libro-protocol.js';
|
|
10
|
+
import type { CellView, NotebookView } from '../libro-protocol.js';
|
|
11
|
+
|
|
12
|
+
import { CellService } from './libro-cell-protocol.js';
|
|
13
|
+
import type { LibroCell } from './libro-cell-protocol.js';
|
|
14
|
+
import { ExecutableCellModel } from './libro-executable-cell-model.js';
|
|
15
|
+
|
|
16
|
+
export const LibroCellComponent = React.forwardRef(function LibroCellComponent() {
|
|
17
|
+
const instance = useInject<LibroCellView>(ViewInstance);
|
|
18
|
+
return <>{instance.model.value}</>;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
@view('libro-cell-view')
|
|
22
|
+
export class LibroCellView extends BaseView implements CellView {
|
|
23
|
+
protected override toDispose = new DisposableCollection();
|
|
24
|
+
options: CellViewOptions;
|
|
25
|
+
|
|
26
|
+
@prop()
|
|
27
|
+
model: CellModel;
|
|
28
|
+
protected cellService: CellService;
|
|
29
|
+
override view: ViewComponent = LibroCellComponent;
|
|
30
|
+
parent!: NotebookView;
|
|
31
|
+
|
|
32
|
+
@prop()
|
|
33
|
+
override className?: string | undefined = 'libro-cell-view-container';
|
|
34
|
+
|
|
35
|
+
@prop()
|
|
36
|
+
hasInputHidden: boolean;
|
|
37
|
+
|
|
38
|
+
@prop()
|
|
39
|
+
collapsedHidden = false;
|
|
40
|
+
|
|
41
|
+
@prop()
|
|
42
|
+
hasModal = false;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
46
|
+
@inject(CellService) cellService: CellService,
|
|
47
|
+
) {
|
|
48
|
+
super();
|
|
49
|
+
this.cellService = cellService;
|
|
50
|
+
this.options = options;
|
|
51
|
+
this.hasInputHidden = false;
|
|
52
|
+
|
|
53
|
+
const model = cellService.getModelFromCache(options.parentId, options.modelId);
|
|
54
|
+
if (!model) {
|
|
55
|
+
console.warn('cell model does not exist');
|
|
56
|
+
throw new Error('cell model does not exist');
|
|
57
|
+
}
|
|
58
|
+
this.model = model;
|
|
59
|
+
this.cellWatch();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
cellWatch() {
|
|
63
|
+
this.toDispose.push(
|
|
64
|
+
watch(this.model, 'value', () => {
|
|
65
|
+
this.parent.model.onChange?.();
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
this.toDispose.push(
|
|
69
|
+
watch(this.model, 'type', () => {
|
|
70
|
+
this.parent.model.onChange?.();
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
if (ExecutableCellModel.is(this.model)) {
|
|
74
|
+
this.toDispose.push(
|
|
75
|
+
watch(this.model, 'executeCount', () => {
|
|
76
|
+
this.parent.model.onChange?.();
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
hasCellHidden() {
|
|
83
|
+
return this.hasInputHidden;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async run() {
|
|
87
|
+
return Promise.resolve(true);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
+
shouldEnterEditorMode(_e: React.FocusEvent<HTMLElement>) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
blur() {
|
|
96
|
+
//
|
|
97
|
+
}
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
+
focus(_isEdit: boolean) {
|
|
100
|
+
//
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
disposed = false;
|
|
104
|
+
override dispose() {
|
|
105
|
+
if (!this.disposed) {
|
|
106
|
+
this.toDispose.dispose();
|
|
107
|
+
super.dispose();
|
|
108
|
+
}
|
|
109
|
+
this.disposed = true;
|
|
110
|
+
}
|
|
111
|
+
toJSON(): LibroCell {
|
|
112
|
+
const meta = { ...(this.model.toJSON() as LibroCell) };
|
|
113
|
+
const modelContribution = this.cellService.findModelProvider(this.model.options);
|
|
114
|
+
if (modelContribution?.cellMeta.nbformatType) {
|
|
115
|
+
meta.metadata.libroCellType = modelContribution?.cellMeta.type;
|
|
116
|
+
meta.cell_type = modelContribution?.cellMeta.nbformatType;
|
|
117
|
+
}
|
|
118
|
+
return meta;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
toJSONWithoutId = () => {
|
|
122
|
+
const JsonObject = this.toJSON();
|
|
123
|
+
delete JsonObject.id;
|
|
124
|
+
return {
|
|
125
|
+
...JsonObject,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IEditor, IRange } from '@difizen/libro-code-editor';
|
|
2
|
+
import { prop } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import type { CellView } from '../libro-protocol.js';
|
|
5
|
+
import { isCellView } from '../libro-protocol.js';
|
|
6
|
+
|
|
7
|
+
import { LibroCellView } from './libro-cell-view.js';
|
|
8
|
+
|
|
9
|
+
export interface EditorCellView extends CellView {
|
|
10
|
+
editor: IEditor | undefined;
|
|
11
|
+
|
|
12
|
+
redo: () => void;
|
|
13
|
+
|
|
14
|
+
undo: () => void;
|
|
15
|
+
getSelections: () => IRange[];
|
|
16
|
+
getSelectionsOffsetAt: (selection: IRange) => {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const EditorCellView = {
|
|
23
|
+
is: (arg: Record<any, any> | undefined): arg is EditorCellView => {
|
|
24
|
+
return (
|
|
25
|
+
!!arg &&
|
|
26
|
+
isCellView(arg as any) &&
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
'redo' in arg &&
|
|
29
|
+
typeof (arg as any).redo === 'function' &&
|
|
30
|
+
'undo' in arg &&
|
|
31
|
+
typeof (arg as any).undo === 'function'
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 带有编辑器能力的cell view,例如raw、markdown、python、sql等
|
|
38
|
+
* 超出编辑器的相关能力放在其他的更高抽象中
|
|
39
|
+
*/
|
|
40
|
+
export abstract class LibroEditorCellView
|
|
41
|
+
extends LibroCellView
|
|
42
|
+
implements EditorCellView
|
|
43
|
+
{
|
|
44
|
+
@prop()
|
|
45
|
+
editor: IEditor | undefined;
|
|
46
|
+
|
|
47
|
+
abstract getSelections: () => IRange[];
|
|
48
|
+
abstract getSelectionsOffsetAt: (selection: IRange) => { start: number; end: number };
|
|
49
|
+
get wrapperCls() {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
redo(): void {
|
|
54
|
+
this.editor?.redo();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
undo(): void {
|
|
58
|
+
this.editor?.undo();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExecutionCount } from '@difizen/libro-common';
|
|
2
|
+
import type { Emitter } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export interface ExecutableCellModel {
|
|
5
|
+
// 执行中
|
|
6
|
+
executing: boolean;
|
|
7
|
+
|
|
8
|
+
// 执行次数
|
|
9
|
+
executeCount: ExecutionCount;
|
|
10
|
+
|
|
11
|
+
hasOutputHidden: boolean;
|
|
12
|
+
|
|
13
|
+
hasOutputsScrolled: boolean;
|
|
14
|
+
|
|
15
|
+
// Emitter Msg
|
|
16
|
+
msgChangeEmitter: Emitter<any>;
|
|
17
|
+
|
|
18
|
+
clearExecution: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ExecutableCellModel = {
|
|
22
|
+
is: (arg: Record<any, any> | undefined): arg is ExecutableCellModel => {
|
|
23
|
+
return (
|
|
24
|
+
!!arg &&
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
'executing' in arg &&
|
|
27
|
+
typeof (arg as any).executing === 'boolean' &&
|
|
28
|
+
'executeCount' in arg &&
|
|
29
|
+
(typeof (arg as any).executeCount === 'number' || !(arg as any).executeCount)
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { watch } from '@difizen/mana-app';
|
|
2
|
+
import { ViewOption } from '@difizen/mana-app';
|
|
3
|
+
import { inject } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { CellModel } from '../libro-protocol.js';
|
|
6
|
+
import type { CellViewOptions } from '../libro-protocol.js';
|
|
7
|
+
import type { BaseOutputArea } from '../output/index.js';
|
|
8
|
+
|
|
9
|
+
import { CellService } from './libro-cell-protocol.js';
|
|
10
|
+
import { EditorCellView, LibroEditorCellView } from './libro-edit-cell-view.js';
|
|
11
|
+
import { ExecutableCellModel } from './libro-executable-cell-model.js';
|
|
12
|
+
|
|
13
|
+
interface ExecutableCellView extends EditorCellView {
|
|
14
|
+
clearExecution: () => void;
|
|
15
|
+
|
|
16
|
+
outputArea: BaseOutputArea;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ExecutableCellView = {
|
|
20
|
+
is: (arg: Record<any, any> | undefined): arg is ExecutableCellView => {
|
|
21
|
+
return (
|
|
22
|
+
!!arg &&
|
|
23
|
+
EditorCellView.is(arg as any) &&
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
'outputArea' in arg &&
|
|
26
|
+
typeof (arg as any).outputArea === 'object' &&
|
|
27
|
+
'clearExecution' in arg &&
|
|
28
|
+
typeof (arg as any).clearExecution === 'function'
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 带有编辑器、执行、output相关能力的cell view,例如python、sql
|
|
35
|
+
* model 必须为 ExecutableCellModel
|
|
36
|
+
*/
|
|
37
|
+
export abstract class LibroExecutableCellView
|
|
38
|
+
extends LibroEditorCellView
|
|
39
|
+
implements ExecutableCellView
|
|
40
|
+
{
|
|
41
|
+
declare model: CellModel & ExecutableCellModel;
|
|
42
|
+
|
|
43
|
+
declare outputArea: BaseOutputArea;
|
|
44
|
+
|
|
45
|
+
constructor(
|
|
46
|
+
@inject(ViewOption) options: CellViewOptions,
|
|
47
|
+
@inject(CellService) cellService: CellService,
|
|
48
|
+
) {
|
|
49
|
+
super(options, cellService);
|
|
50
|
+
this.outputWatch();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
clearExecution: () => void = () => {
|
|
54
|
+
//
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
override hasCellHidden() {
|
|
58
|
+
if (
|
|
59
|
+
!ExecutableCellModel.is(this.model) ||
|
|
60
|
+
(this.outputArea && this.outputArea.length < 1)
|
|
61
|
+
) {
|
|
62
|
+
return this.hasInputHidden;
|
|
63
|
+
}
|
|
64
|
+
return this.hasInputHidden && this.model.hasOutputHidden;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
outputWatch() {
|
|
68
|
+
this.toDispose.push(
|
|
69
|
+
watch(this.outputArea, 'outputs', () => {
|
|
70
|
+
this.parent.model.onChange?.();
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CellModel } from '../libro-protocol.js';
|
|
2
|
+
|
|
3
|
+
export interface LibroMarkdownCellModel extends CellModel {
|
|
4
|
+
isEdit: boolean;
|
|
5
|
+
|
|
6
|
+
preview: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const LibroMarkdownCellModel = {
|
|
10
|
+
is: (arg: Record<any, any> | undefined): arg is LibroMarkdownCellModel => {
|
|
11
|
+
return (
|
|
12
|
+
!!arg &&
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
'isEdit' in arg &&
|
|
15
|
+
typeof (arg as any).isEdit === 'boolean' &&
|
|
16
|
+
'preview' in arg &&
|
|
17
|
+
typeof (arg as any).preview === 'string'
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { inject, prop, transient } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { CellView } from './libro-protocol.js';
|
|
4
|
+
import type { LibroView } from './libro-view.js';
|
|
5
|
+
|
|
6
|
+
export interface CollapseServiceOption {
|
|
7
|
+
view: LibroView;
|
|
8
|
+
}
|
|
9
|
+
export const CollapseServiceOption = Symbol('CollapseServiceOption');
|
|
10
|
+
|
|
11
|
+
export type CollapseServiceFactory = (option: CollapseServiceOption) => CollapseService;
|
|
12
|
+
export const CollapseServiceFactory = Symbol('CollapseServiceFactory');
|
|
13
|
+
|
|
14
|
+
export interface CellCollapsible {
|
|
15
|
+
/**
|
|
16
|
+
* 是否折叠子项
|
|
17
|
+
*/
|
|
18
|
+
headingCollapsed: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 折叠的子项的数量
|
|
21
|
+
*/
|
|
22
|
+
collapsibleChildNumber: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const CellCollapsible = {
|
|
26
|
+
is: (arg: Record<any, any> | undefined): arg is CellCollapsible => {
|
|
27
|
+
return (
|
|
28
|
+
!!arg &&
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
'headingCollapsed' in arg &&
|
|
31
|
+
typeof (arg as any).headingCollapsed === 'boolean'
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface CollapseService {
|
|
37
|
+
collapserVisible: boolean;
|
|
38
|
+
|
|
39
|
+
view: LibroView;
|
|
40
|
+
|
|
41
|
+
setHeadingCollapse: (cell: CellView, collapsing: boolean) => void;
|
|
42
|
+
|
|
43
|
+
getCollapsibleChildNumber: (cell: CellView) => number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const CollapseService = Symbol('CollapseService');
|
|
47
|
+
|
|
48
|
+
@transient({ token: CollapseService })
|
|
49
|
+
export class DefaultCollapseService implements CollapseService {
|
|
50
|
+
@prop()
|
|
51
|
+
collapserVisible = false;
|
|
52
|
+
|
|
53
|
+
view: LibroView;
|
|
54
|
+
|
|
55
|
+
constructor(@inject(CollapseServiceOption) option: CollapseServiceOption) {
|
|
56
|
+
this.view = option.view;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setHeadingCollapse(cell: CellView, collapsing: boolean) {
|
|
60
|
+
if (CellCollapsible.is(cell)) {
|
|
61
|
+
cell.headingCollapsed = collapsing;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
+
getCollapsibleChildNumber(_cell: CellView) {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SaveOutlined, SettingOutlined } from '@ant-design/icons';
|
|
2
|
+
import type { Command } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export const DocumentCommands: Record<
|
|
5
|
+
string,
|
|
6
|
+
Command & { keybind?: string | string[] | undefined; when?: string | undefined }
|
|
7
|
+
> = {
|
|
8
|
+
Save: {
|
|
9
|
+
id: 'document:save',
|
|
10
|
+
icon: SaveOutlined,
|
|
11
|
+
label: 'SAVE',
|
|
12
|
+
keybind: 'ctrlcmd+s',
|
|
13
|
+
},
|
|
14
|
+
OpenSettings: {
|
|
15
|
+
id: 'document.notebook.open_setting',
|
|
16
|
+
icon: SettingOutlined,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Command } from '@difizen/mana-app';
|
|
2
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
3
|
+
|
|
4
|
+
export const KernelCommands: Record<string, Command & { keybind?: string }> = {
|
|
5
|
+
//#region libro command
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
|
|
9
|
+
//#region jupyterlab command
|
|
10
|
+
ChangeKernel: {
|
|
11
|
+
id: 'notebook:change-kernel',
|
|
12
|
+
label: `Change Kernel`,
|
|
13
|
+
},
|
|
14
|
+
GetKernel: {
|
|
15
|
+
id: 'notebook:get-kernel',
|
|
16
|
+
label: `Get Kernel`,
|
|
17
|
+
},
|
|
18
|
+
InterruptKernel: {
|
|
19
|
+
id: 'notebook:interrupt-kernel',
|
|
20
|
+
label: `Interrupt Kernel`,
|
|
21
|
+
},
|
|
22
|
+
ReconnectToKernel: {
|
|
23
|
+
id: 'notebook:reconnect-to-kernel',
|
|
24
|
+
label: `Reconnect to Kernel`,
|
|
25
|
+
},
|
|
26
|
+
RestartKernel: {
|
|
27
|
+
id: 'notebook:restart-kernel',
|
|
28
|
+
label: l10n.t('Restart Kernel…'),
|
|
29
|
+
},
|
|
30
|
+
ShutdownKernel: {
|
|
31
|
+
id: 'notebook:shutdown-kernel',
|
|
32
|
+
label: `Shutdown Kernel`,
|
|
33
|
+
},
|
|
34
|
+
ShowKernelStatus: {
|
|
35
|
+
id: 'notebook:show-kernel-status',
|
|
36
|
+
},
|
|
37
|
+
ShowKernelStatusAndSelector: {
|
|
38
|
+
id: 'notebook:show-kernel-status-and-selector',
|
|
39
|
+
},
|
|
40
|
+
//#endregion
|
|
41
|
+
};
|