@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,322 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
2
|
+
import type { IModel } from '@difizen/libro-code-editor';
|
|
3
|
+
import type {
|
|
4
|
+
CellType,
|
|
5
|
+
ICell,
|
|
6
|
+
ICellMetadata,
|
|
7
|
+
INotebookContent,
|
|
8
|
+
INotebookMetadata,
|
|
9
|
+
} from '@difizen/libro-common';
|
|
10
|
+
import type { ISharedNotebook } from '@difizen/libro-shared-model';
|
|
11
|
+
import { View } from '@difizen/mana-app';
|
|
12
|
+
import type { Disposable, Event } from '@difizen/mana-app';
|
|
13
|
+
|
|
14
|
+
import type { LibroCell } from './cell/index.js';
|
|
15
|
+
import type { LibroView } from './libro-view.js';
|
|
16
|
+
|
|
17
|
+
export const LibroContextKeys = {
|
|
18
|
+
active: 'active',
|
|
19
|
+
focus: 'focus',
|
|
20
|
+
commandMode: 'commandMode',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const LibroToolbarArea = {
|
|
24
|
+
HeaderLeft: 'header-left',
|
|
25
|
+
HeaderCenter: 'header-center',
|
|
26
|
+
HeaderRight: 'header-right',
|
|
27
|
+
CellTop: 'top',
|
|
28
|
+
CellRight: 'right',
|
|
29
|
+
};
|
|
30
|
+
export const NotebookOption = Symbol('NotebookOption');
|
|
31
|
+
/**
|
|
32
|
+
* Libro 创建参数
|
|
33
|
+
* 默认可 json 序列化
|
|
34
|
+
*/
|
|
35
|
+
export interface NotebookOption extends Options {
|
|
36
|
+
id?: string;
|
|
37
|
+
modelId?: string;
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const ModelFactory = Symbol('ModelFactory');
|
|
42
|
+
export type ModelFactory<T = NotebookOption> = (options: T) => NotebookModel;
|
|
43
|
+
|
|
44
|
+
export const NotebookModel = Symbol('NotebookModel');
|
|
45
|
+
|
|
46
|
+
export type Options = {
|
|
47
|
+
id?: string;
|
|
48
|
+
[key: string]: any;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type NotebookModel = BaseNotebookModel & DndListModel;
|
|
52
|
+
export interface BaseNotebookModel {
|
|
53
|
+
id: string;
|
|
54
|
+
/**
|
|
55
|
+
* The dirty state of the model.
|
|
56
|
+
* #### Notes
|
|
57
|
+
* This should be cleared when the document is loaded from
|
|
58
|
+
* or saved to disk.
|
|
59
|
+
*/
|
|
60
|
+
dirty: boolean;
|
|
61
|
+
executeCount: number;
|
|
62
|
+
lastClipboardInteraction?: string;
|
|
63
|
+
clipboard?: CellView | CellView[];
|
|
64
|
+
active?: CellView | undefined;
|
|
65
|
+
activeIndex: number;
|
|
66
|
+
dndAreaNullEnable: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The read-only state of the model.
|
|
69
|
+
*/
|
|
70
|
+
readOnly: boolean;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The quick edit mode the model.
|
|
74
|
+
*/
|
|
75
|
+
quickEditMode: boolean;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The command mode of the model.
|
|
79
|
+
*/
|
|
80
|
+
commandMode: boolean;
|
|
81
|
+
|
|
82
|
+
trusted: boolean;
|
|
83
|
+
|
|
84
|
+
onCommandModeChanged: Event<boolean>;
|
|
85
|
+
|
|
86
|
+
onContentChanged: Event<boolean>;
|
|
87
|
+
|
|
88
|
+
getCells: () => CellView[];
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Serialize the model to a string.
|
|
92
|
+
*/
|
|
93
|
+
toString: () => string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Deserialize the model from a string.
|
|
97
|
+
*
|
|
98
|
+
* #### Notes
|
|
99
|
+
* Should emit a [contentChanged] signal.
|
|
100
|
+
*/
|
|
101
|
+
fromString: (value: string) => void;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The list of cells in the notebook.
|
|
105
|
+
*/
|
|
106
|
+
cells: CellView[];
|
|
107
|
+
|
|
108
|
+
selections: CellView[];
|
|
109
|
+
|
|
110
|
+
canUndo?: boolean;
|
|
111
|
+
|
|
112
|
+
canRedo?: boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The metadata associated with the notebook.
|
|
116
|
+
*/
|
|
117
|
+
readonly metadata: INotebookMetadata;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The array of deleted cells since the notebook was last run.
|
|
121
|
+
*/
|
|
122
|
+
readonly deletedCells: CellView[];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* If the model is initialized or not.
|
|
126
|
+
*/
|
|
127
|
+
isInitialized: boolean;
|
|
128
|
+
|
|
129
|
+
initialize: () => Promise<CellOptions[]>;
|
|
130
|
+
|
|
131
|
+
options: Options;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* save notebook
|
|
135
|
+
*/
|
|
136
|
+
toJSON: () => INotebookContent;
|
|
137
|
+
|
|
138
|
+
saveNotebookContent: () => Promise<void>;
|
|
139
|
+
|
|
140
|
+
fontSize: number;
|
|
141
|
+
theme: string;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 聚焦
|
|
145
|
+
*/
|
|
146
|
+
focus?: () => void;
|
|
147
|
+
blur?: () => void;
|
|
148
|
+
/**
|
|
149
|
+
* 进入命令模式
|
|
150
|
+
*/
|
|
151
|
+
enterCommandMode?: () => void;
|
|
152
|
+
|
|
153
|
+
enterEditMode?: () => void;
|
|
154
|
+
|
|
155
|
+
onChange?: () => void;
|
|
156
|
+
|
|
157
|
+
interrupt?: () => void;
|
|
158
|
+
|
|
159
|
+
canRun?: () => boolean;
|
|
160
|
+
|
|
161
|
+
restart?: () => void;
|
|
162
|
+
|
|
163
|
+
shutdown?: () => void;
|
|
164
|
+
|
|
165
|
+
undo: () => void;
|
|
166
|
+
|
|
167
|
+
redo: () => void;
|
|
168
|
+
|
|
169
|
+
readonly sharedModel: ISharedNotebook;
|
|
170
|
+
|
|
171
|
+
scrollToView: (cell: CellView) => void;
|
|
172
|
+
|
|
173
|
+
customParams: Record<string, any>;
|
|
174
|
+
getCustomKey: (key: string) => any;
|
|
175
|
+
setCustomKey: (key: string, val: any) => void;
|
|
176
|
+
|
|
177
|
+
libroViewClass: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const notebookViewFactoryId = 'notebook-view-factory';
|
|
181
|
+
|
|
182
|
+
export type NotebookView = LibroView;
|
|
183
|
+
|
|
184
|
+
export interface CellView extends View {
|
|
185
|
+
model: CellModel;
|
|
186
|
+
parent: NotebookView;
|
|
187
|
+
wrapperCls?: string;
|
|
188
|
+
|
|
189
|
+
blur: () => void;
|
|
190
|
+
focus: (isEdit: boolean) => void;
|
|
191
|
+
|
|
192
|
+
run: () => Promise<boolean>;
|
|
193
|
+
|
|
194
|
+
shouldEnterEditorMode: (e: React.FocusEvent<HTMLElement>) => boolean;
|
|
195
|
+
|
|
196
|
+
hasCellHidden: () => boolean;
|
|
197
|
+
|
|
198
|
+
hasInputHidden: boolean;
|
|
199
|
+
|
|
200
|
+
hasModal: boolean;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 是否被折叠隐藏
|
|
204
|
+
*/
|
|
205
|
+
collapsedHidden: boolean;
|
|
206
|
+
|
|
207
|
+
toJSON: () => ICell;
|
|
208
|
+
|
|
209
|
+
toJSONWithoutId: () => ICell;
|
|
210
|
+
}
|
|
211
|
+
export function isCellView(view: View): view is CellView {
|
|
212
|
+
return View.is(view) && 'model' in view;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const CellOptions = Symbol('CellOptions');
|
|
216
|
+
export interface CellOptions {
|
|
217
|
+
// parent?: NotebookView;
|
|
218
|
+
id?: string;
|
|
219
|
+
modelId?: string;
|
|
220
|
+
mimetype?: string;
|
|
221
|
+
cell: LibroCell;
|
|
222
|
+
[key: string]: any;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export const CellViewOptions = Symbol('CellViewOptions');
|
|
226
|
+
export interface CellViewOptions {
|
|
227
|
+
parentId: string;
|
|
228
|
+
id: string;
|
|
229
|
+
modelId: string;
|
|
230
|
+
mimetype?: string;
|
|
231
|
+
cell: ICell;
|
|
232
|
+
[key: string]: any;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface CellModel extends IModel, Disposable {
|
|
236
|
+
/**
|
|
237
|
+
* A unique identifier for the cell.
|
|
238
|
+
*/
|
|
239
|
+
id: string;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* The type of the cell.
|
|
243
|
+
*/
|
|
244
|
+
type: CellType;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* A signal emitted when the content of the model changes.
|
|
248
|
+
*/
|
|
249
|
+
// readonly contentChanged: Event<void>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* A signal emitted when a model state changes.
|
|
253
|
+
*/
|
|
254
|
+
// readonly stateChanged: Event<IContentsChangedArgs<any>>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Whether the cell is trusted.
|
|
258
|
+
*/
|
|
259
|
+
trusted: boolean;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* The metadata associated with the cell.
|
|
263
|
+
*/
|
|
264
|
+
readonly metadata: Partial<ICellMetadata>;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Serialize the model to JSON.
|
|
268
|
+
* 输出时的字段顺序也要保持稳定
|
|
269
|
+
*/
|
|
270
|
+
toJSON: () => Omit<ICell, 'outputs'>;
|
|
271
|
+
options: CellOptions;
|
|
272
|
+
|
|
273
|
+
// run: () => Promise<boolean>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export const NotebookService = Symbol('NotebookService');
|
|
277
|
+
|
|
278
|
+
export interface NotebookService {
|
|
279
|
+
getOrCreateModel: (options: NotebookOption) => NotebookModel;
|
|
280
|
+
getOrCreateView: (options: NotebookOption) => Promise<NotebookView>;
|
|
281
|
+
setActive: (view: NotebookView | undefined) => void;
|
|
282
|
+
onActiveChanged: Event<NotebookView | undefined>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//#region Protocol for drag & drop
|
|
286
|
+
export const DragAreaKey = Symbol('DragAreaKey');
|
|
287
|
+
|
|
288
|
+
export type MouseMode = 'multipleSelection' | 'mouseDown' | 'drag';
|
|
289
|
+
export interface DndListModel {
|
|
290
|
+
mouseMode?: MouseMode;
|
|
291
|
+
active?: CellView | undefined;
|
|
292
|
+
hover?: CellView | undefined;
|
|
293
|
+
selectCell: (cell: CellView) => void;
|
|
294
|
+
addCell: (cell: CellView, position?: number, mode?: string) => void;
|
|
295
|
+
insertCells: (cells: CellView[], position?: number, mode?: string) => void;
|
|
296
|
+
invertCell: (toAddcell: CellView, position: number) => void;
|
|
297
|
+
splitCell: (newCells: CellView[], position: number) => void;
|
|
298
|
+
deleteCell: {
|
|
299
|
+
(id: string): boolean;
|
|
300
|
+
(index: number): boolean;
|
|
301
|
+
(cell: CellView): boolean;
|
|
302
|
+
};
|
|
303
|
+
exchangeCell: {
|
|
304
|
+
(source: CellView, target: CellView): boolean;
|
|
305
|
+
(sourceIndex: number, targetIndex: number): boolean;
|
|
306
|
+
(sourceId: string, targetId: string): boolean;
|
|
307
|
+
};
|
|
308
|
+
exchangeCells: (source: CellView[], targetIndex: number) => void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export interface DndContentProps {
|
|
312
|
+
cell: CellView;
|
|
313
|
+
index: number;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface DndItemProps {
|
|
317
|
+
isDragOver: boolean;
|
|
318
|
+
isDrag: boolean;
|
|
319
|
+
cell: CellView;
|
|
320
|
+
isMouseOverDragArea?: boolean;
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Emitter } from '@difizen/mana-app';
|
|
2
|
+
import { ThemeService, ViewManager } from '@difizen/mana-app';
|
|
3
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
4
|
+
import { prop } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
import type { NotebookOption, NotebookView } from './libro-protocol.js';
|
|
7
|
+
import {
|
|
8
|
+
notebookViewFactoryId,
|
|
9
|
+
ModelFactory,
|
|
10
|
+
NotebookService,
|
|
11
|
+
} from './libro-protocol.js';
|
|
12
|
+
import { LibroViewTracker } from './libro-view-tracker.js';
|
|
13
|
+
|
|
14
|
+
@singleton({ contrib: NotebookService })
|
|
15
|
+
export class LibroService implements NotebookService {
|
|
16
|
+
protected libroModelFactory: ModelFactory;
|
|
17
|
+
protected viewManager: ViewManager;
|
|
18
|
+
protected libroViewTracker: LibroViewTracker;
|
|
19
|
+
|
|
20
|
+
protected themeService: ThemeService;
|
|
21
|
+
@prop()
|
|
22
|
+
themeMode: string;
|
|
23
|
+
constructor(
|
|
24
|
+
@inject(ThemeService) themeService: ThemeService,
|
|
25
|
+
@inject(ModelFactory) libroModelFactory: ModelFactory,
|
|
26
|
+
@inject(ViewManager) viewManager: ViewManager,
|
|
27
|
+
@inject(LibroViewTracker) libroViewTracker: LibroViewTracker,
|
|
28
|
+
) {
|
|
29
|
+
this.themeService = themeService;
|
|
30
|
+
this.themeMode = this.themeService.getCurrentTheme().type;
|
|
31
|
+
this.themeService.onDidColorThemeChange((e) => {
|
|
32
|
+
this.themeMode = e.newTheme.type;
|
|
33
|
+
});
|
|
34
|
+
this.libroModelFactory = libroModelFactory;
|
|
35
|
+
this.viewManager = viewManager;
|
|
36
|
+
this.libroViewTracker = libroViewTracker;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@prop() protected _active?: NotebookView;
|
|
40
|
+
protected onActiveChangedEmitter: Emitter<NotebookView | undefined> = new Emitter();
|
|
41
|
+
get onActiveChanged() {
|
|
42
|
+
return this.onActiveChangedEmitter.event;
|
|
43
|
+
}
|
|
44
|
+
get active(): NotebookView | undefined {
|
|
45
|
+
return this._active;
|
|
46
|
+
}
|
|
47
|
+
set active(value: NotebookView | undefined) {
|
|
48
|
+
this._active = value;
|
|
49
|
+
this.onActiveChangedEmitter.fire(value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@prop() protected _focus?: NotebookView;
|
|
53
|
+
protected onFocusChangedEmitter: Emitter<NotebookView | undefined> = new Emitter();
|
|
54
|
+
get onFocusChanged() {
|
|
55
|
+
return this.onFocusChangedEmitter.event;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected onNotebookViewCreatedEmitter: Emitter<NotebookView> = new Emitter();
|
|
59
|
+
get onNotebookViewCreated() {
|
|
60
|
+
return this.onNotebookViewCreatedEmitter.event;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get focus(): NotebookView | undefined {
|
|
64
|
+
return this._focus;
|
|
65
|
+
}
|
|
66
|
+
set focus(value: NotebookView | undefined) {
|
|
67
|
+
this._focus = value;
|
|
68
|
+
this.onFocusChangedEmitter.fire(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get hasFocus(): boolean {
|
|
72
|
+
return this._hasFocus;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getViewCache(): Map<string, NotebookView> {
|
|
76
|
+
return this.libroViewTracker.viewCache;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
deleteLibroViewFromCache(instance: NotebookView) {
|
|
80
|
+
this.libroViewTracker.viewCache.delete(instance.id);
|
|
81
|
+
this.libroViewTracker.modelCache.delete(instance.model.id);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@prop()
|
|
85
|
+
protected _hasFocus = false;
|
|
86
|
+
|
|
87
|
+
getOrCreateModel(options: NotebookOption) {
|
|
88
|
+
if (options.modelId) {
|
|
89
|
+
const exist = this.libroViewTracker.modelCache.get(options.modelId);
|
|
90
|
+
if (exist) {
|
|
91
|
+
return exist;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const model = this.libroModelFactory(options);
|
|
95
|
+
this.libroViewTracker.modelCache.set(model.id, model);
|
|
96
|
+
return model;
|
|
97
|
+
}
|
|
98
|
+
async getOrCreateView(options: NotebookOption): Promise<NotebookView> {
|
|
99
|
+
const model = this.getOrCreateModel(options);
|
|
100
|
+
const notebookViewPromise = this.viewManager.getOrCreateView<NotebookView>(
|
|
101
|
+
notebookViewFactoryId,
|
|
102
|
+
{
|
|
103
|
+
...(options || {}),
|
|
104
|
+
modelId: model.id,
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
const notebookView = await notebookViewPromise;
|
|
108
|
+
this.libroViewTracker.viewCache.set(notebookView.id, notebookView);
|
|
109
|
+
this.onNotebookViewCreatedEmitter.fire(notebookView);
|
|
110
|
+
return notebookViewPromise;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
setActive(view?: NotebookView): void {
|
|
114
|
+
this._active = view;
|
|
115
|
+
this.onActiveChangedEmitter.fire(view);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setHasFocus(hasFocus: boolean): void {
|
|
119
|
+
this._hasFocus = hasFocus;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { NotebookModel, NotebookView } from './libro-protocol.js';
|
|
4
|
+
|
|
5
|
+
@singleton()
|
|
6
|
+
export class LibroViewTracker {
|
|
7
|
+
viewCache: Map<string, NotebookView> = new Map();
|
|
8
|
+
modelCache: Map<string, NotebookModel> = new Map();
|
|
9
|
+
}
|