@difizen/libro-core 0.1.1 → 0.1.2
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/es/add-cell/index.less +1 -1
- package/es/add-cell/libro-add-cell-slot-contribution.d.ts +1 -2
- package/es/add-cell/libro-add-cell-slot-contribution.d.ts.map +1 -1
- package/es/add-cell/libro-add-cell-slot-contribution.js +12 -6
- package/es/add-cell/libro-add-cell-view.d.ts +4 -4
- package/es/add-cell/libro-add-cell-view.d.ts.map +1 -1
- package/es/add-cell/libro-add-cell-view.js +4 -6
- package/es/cell/libro-cell-contribution.d.ts +1 -2
- package/es/cell/libro-cell-contribution.d.ts.map +1 -1
- package/es/cell/libro-cell-contribution.js +14 -8
- package/es/cell/libro-cell-model.d.ts +9 -0
- package/es/cell/libro-cell-model.d.ts.map +1 -1
- package/es/cell/libro-cell-model.js +53 -11
- package/es/cell/libro-cell-protocol.d.ts +2 -0
- package/es/cell/libro-cell-protocol.d.ts.map +1 -1
- package/es/cell/libro-cell-view.d.ts +6 -2
- package/es/cell/libro-cell-view.d.ts.map +1 -1
- package/es/cell/libro-cell-view.js +54 -24
- package/es/cell/libro-edit-cell-view.d.ts +6 -12
- package/es/cell/libro-edit-cell-view.d.ts.map +1 -1
- package/es/cell/libro-edit-cell-view.js +9 -4
- package/es/cell/libro-executable-cell-view.d.ts +2 -0
- package/es/cell/libro-executable-cell-view.d.ts.map +1 -1
- package/es/cell/libro-executable-cell-view.js +4 -1
- package/es/collapse-service.d.ts +1 -1
- package/es/collapse-service.d.ts.map +1 -1
- package/es/collapse-service.js +1 -1
- package/es/command/document-commands.d.ts +1 -2
- package/es/command/document-commands.d.ts.map +1 -1
- package/es/command/document-commands.js +3 -2
- package/es/command/kernel-command.d.ts.map +1 -1
- package/es/command/kernel-command.js +3 -0
- package/es/command/libro-command-contribution.d.ts +0 -1
- package/es/command/libro-command-contribution.d.ts.map +1 -1
- package/es/command/libro-command-contribution.js +179 -129
- package/es/command/libro-command-register.d.ts +0 -1
- package/es/command/libro-command-register.d.ts.map +1 -1
- package/es/command/libro-command-register.js +13 -7
- package/es/command/notebook-commands.d.ts.map +1 -1
- package/es/command/notebook-commands.js +17 -4
- package/es/components/cell-protocol.d.ts +5 -5
- package/es/components/cell-protocol.d.ts.map +1 -1
- package/es/components/dnd-cell-item-render.d.ts +6 -2
- package/es/components/dnd-cell-item-render.d.ts.map +1 -1
- package/es/components/dnd-cell-item-render.js +194 -89
- package/es/components/dnd-component/custom-drag-layer.d.ts +1 -1
- package/es/components/dnd-component/custom-drag-layer.d.ts.map +1 -1
- package/es/components/dnd-component/custom-drag-layer.js +3 -4
- package/es/components/dnd-component/default-dnd-content.d.ts +2 -1
- package/es/components/dnd-component/default-dnd-content.d.ts.map +1 -1
- package/es/components/dnd-component/default-dnd-content.js +100 -44
- package/es/components/dnd-component/dnd-context.js +1 -1
- package/es/components/dnd-component/dnd-list.d.ts +9 -5
- package/es/components/dnd-component/dnd-list.d.ts.map +1 -1
- package/es/components/dnd-component/dnd-list.js +93 -26
- package/es/components/dnd-component/index.d.ts +1 -1
- package/es/components/dnd-component/index.d.ts.map +1 -1
- package/es/components/dnd-component/index.js +2 -2
- package/es/components/dnd-component/index.less +8 -0
- package/es/components/dnd-component/overscanIndices-getter.d.ts +22 -0
- package/es/components/dnd-component/overscanIndices-getter.d.ts.map +1 -0
- package/es/components/dnd-component/overscanIndices-getter.js +58 -0
- package/es/components/dnd-component/virtualized-manager.d.ts +19 -0
- package/es/components/dnd-component/virtualized-manager.d.ts.map +1 -0
- package/es/components/dnd-component/virtualized-manager.js +60 -0
- package/es/components/index.d.ts +2 -2
- package/es/components/index.d.ts.map +1 -1
- package/es/components/index.js +2 -2
- package/es/components/libro-virtualized-render.d.ts +15 -0
- package/es/components/libro-virtualized-render.d.ts.map +1 -0
- package/es/components/libro-virtualized-render.js +174 -0
- package/es/content/index.d.ts +1 -0
- package/es/content/index.d.ts.map +1 -1
- package/es/content/index.js +2 -1
- package/es/content/libro-content-contribution.d.ts +2 -2
- package/es/content/libro-content-contribution.d.ts.map +1 -1
- package/es/content/libro-content-contribution.js +2 -3
- package/es/content/libro-content-module.d.ts.map +1 -1
- package/es/content/libro-content-module.js +3 -2
- package/es/content/libro-content-protocol.d.ts +5 -0
- package/es/content/libro-content-protocol.d.ts.map +1 -1
- package/es/content/libro-content-protocol.js +2 -1
- package/es/content/libro-content-service.d.ts +5 -3
- package/es/content/libro-content-service.d.ts.map +1 -1
- package/es/content/libro-content-service.js +36 -8
- package/es/content/libro-save-content-contribution.d.ts +6 -0
- package/es/content/libro-save-content-contribution.d.ts.map +1 -0
- package/es/content/libro-save-content-contribution.js +27 -0
- package/es/formatter/index.d.ts +6 -0
- package/es/formatter/index.d.ts.map +1 -0
- package/es/formatter/index.js +5 -0
- package/es/formatter/libro-formatter-json-contribution.d.ts +18 -0
- package/es/formatter/libro-formatter-json-contribution.d.ts.map +1 -0
- package/es/formatter/libro-formatter-json-contribution.js +41 -0
- package/es/formatter/libro-formatter-manager.d.ts +16 -0
- package/es/formatter/libro-formatter-manager.d.ts.map +1 -0
- package/es/formatter/libro-formatter-manager.js +86 -0
- package/es/formatter/libro-formatter-module.d.ts +3 -0
- package/es/formatter/libro-formatter-module.d.ts.map +1 -0
- package/es/formatter/libro-formatter-module.js +7 -0
- package/es/formatter/libro-formatter-protocol.d.ts +37 -0
- package/es/formatter/libro-formatter-protocol.d.ts.map +1 -0
- package/es/formatter/libro-formatter-protocol.js +18 -0
- package/es/formatter/libro-formatter-string-contribution.d.ts +18 -0
- package/es/formatter/libro-formatter-string-contribution.d.ts.map +1 -0
- package/es/formatter/libro-formatter-string-contribution.js +41 -0
- package/es/formatter/libro-formatter-trans-default-contribution.d.ts +7 -0
- package/es/formatter/libro-formatter-trans-default-contribution.d.ts.map +1 -0
- package/es/formatter/libro-formatter-trans-default-contribution.js +19 -0
- package/es/index.d.ts +5 -1
- package/es/index.d.ts.map +1 -1
- package/es/index.js +6 -2
- package/es/index.less +135 -58
- package/es/libro-context-key.d.ts.map +1 -1
- package/es/libro-model.d.ts +13 -2
- package/es/libro-model.d.ts.map +1 -1
- package/es/libro-model.js +149 -70
- package/es/libro-protocol.d.ts +44 -2
- package/es/libro-protocol.d.ts.map +1 -1
- package/es/libro-protocol.js +16 -3
- package/es/libro-service.d.ts +1 -1
- package/es/libro-service.d.ts.map +1 -1
- package/es/libro-service.js +29 -20
- package/es/{configuration/libro-configuration-contribution.d.ts → libro-setting-contribution.d.ts} +2 -2
- package/es/libro-setting-contribution.d.ts.map +1 -0
- package/es/{configuration/libro-configuration-contribution.js → libro-setting-contribution.js} +8 -9
- package/es/{configuration/libro-configuration.d.ts → libro-setting.d.ts} +3 -2
- package/es/libro-setting.d.ts.map +1 -0
- package/es/{configuration/libro-configuration.js → libro-setting.js} +17 -7
- package/es/libro-view.d.ts +21 -8
- package/es/libro-view.d.ts.map +1 -1
- package/es/libro-view.js +477 -338
- package/es/material-from-designer.d.ts +3 -0
- package/es/material-from-designer.d.ts.map +1 -1
- package/es/material-from-designer.js +112 -1
- package/es/module.d.ts.map +1 -1
- package/es/module.js +20 -5
- package/es/output/output-area.d.ts +3 -4
- package/es/output/output-area.d.ts.map +1 -1
- package/es/output/output-area.js +23 -16
- package/es/output/output-contribution.d.ts +0 -1
- package/es/output/output-contribution.d.ts.map +1 -1
- package/es/output/output-contribution.js +14 -9
- package/es/output/output-model.d.ts +2 -2
- package/es/output/output-model.d.ts.map +1 -1
- package/es/output/output-model.js +2 -2
- package/es/output/output-protocol.d.ts.map +1 -1
- package/es/output/output-protocol.js +0 -2
- package/es/settings/index.d.ts +5 -0
- package/es/settings/index.d.ts.map +1 -0
- package/es/settings/index.js +4 -0
- package/es/settings/index.less +3 -0
- package/es/settings/module.d.ts +3 -0
- package/es/settings/module.d.ts.map +1 -0
- package/es/settings/module.js +4 -0
- package/es/settings/setting-editor/configuration-panel-view.d.ts +13 -0
- package/es/settings/setting-editor/configuration-panel-view.d.ts.map +1 -0
- package/es/settings/setting-editor/configuration-panel-view.js +115 -0
- package/es/settings/setting-editor/configuration-render-contribution.d.ts +6 -0
- package/es/settings/setting-editor/configuration-render-contribution.d.ts.map +1 -0
- package/es/settings/setting-editor/configuration-render-contribution.js +77 -0
- package/es/settings/setting-editor/default-node-render.d.ts +9 -0
- package/es/settings/setting-editor/default-node-render.d.ts.map +1 -0
- package/es/settings/setting-editor/default-node-render.js +79 -0
- package/es/settings/setting-editor/index.d.ts +7 -0
- package/es/settings/setting-editor/index.d.ts.map +1 -0
- package/es/settings/setting-editor/index.js +6 -0
- package/es/settings/setting-editor/index.less +12 -0
- package/es/settings/setting-editor/module.d.ts +3 -0
- package/es/settings/setting-editor/module.d.ts.map +1 -0
- package/es/settings/setting-editor/module.js +7 -0
- package/es/settings/setting-editor/setting-editor-view.d.ts +15 -0
- package/es/settings/setting-editor/setting-editor-view.d.ts.map +1 -0
- package/es/settings/setting-editor/setting-editor-view.js +169 -0
- package/es/settings/setting-editor/setting-tree-service.d.ts +9 -0
- package/es/settings/setting-editor/setting-tree-service.d.ts.map +1 -0
- package/es/settings/setting-editor/setting-tree-service.js +118 -0
- package/es/settings/setting-editor/setting-tree-view.d.ts +19 -0
- package/es/settings/setting-editor/setting-tree-view.d.ts.map +1 -0
- package/es/settings/setting-editor/setting-tree-view.js +88 -0
- package/es/settings/settings-contribution.d.ts +7 -0
- package/es/settings/settings-contribution.d.ts.map +1 -0
- package/es/settings/settings-contribution.js +36 -0
- package/es/settings/settings-modal.d.ts +5 -0
- package/es/settings/settings-modal.d.ts.map +1 -0
- package/es/settings/settings-modal.js +53 -0
- package/es/settings/settings-modal.less +3 -0
- package/es/settings/settings-protocol.d.ts +4 -0
- package/es/settings/settings-protocol.d.ts.map +1 -0
- package/es/settings/settings-protocol.js +5 -0
- package/es/slot/libro-slot-manager.d.ts +2 -2
- package/es/slot/libro-slot-manager.d.ts.map +1 -1
- package/es/slot/libro-slot-manager.js +14 -8
- package/es/slot/libro-slot-view.d.ts +3 -3
- package/es/slot/libro-slot-view.d.ts.map +1 -1
- package/es/slot/libro-slot-view.js +2 -2
- package/es/theme/libro-color-registry.d.ts.map +1 -1
- package/es/theme/libro-color-registry.js +7 -0
- package/es/toolbar/all-outputs-scroll-icon.d.ts +3 -0
- package/es/toolbar/all-outputs-scroll-icon.d.ts.map +1 -0
- package/es/toolbar/all-outputs-scroll-icon.js +10 -0
- package/es/toolbar/libro-toolbar.d.ts +2 -1
- package/es/toolbar/libro-toolbar.d.ts.map +1 -1
- package/es/toolbar/libro-toolbar.js +44 -8
- package/es/toolbar/restart-clear-outputs-modal.d.ts +1 -2
- package/es/toolbar/restart-clear-outputs-modal.d.ts.map +1 -1
- package/es/toolbar/restart-clear-outputs-modal.js +2 -2
- package/es/toolbar/shutdown-modal.d.ts +1 -2
- package/es/toolbar/shutdown-modal.d.ts.map +1 -1
- package/es/toolbar/shutdown-modal.js +2 -2
- package/es/toolbar/side-toolar-more-select.d.ts.map +1 -1
- package/es/toolbar/side-toolar-more-select.js +2 -2
- package/es/virtualized-manager-helper.d.ts +11 -0
- package/es/virtualized-manager-helper.d.ts.map +1 -0
- package/es/virtualized-manager-helper.js +51 -0
- package/es/virtualized-manager.d.ts +19 -0
- package/es/virtualized-manager.d.ts.map +1 -0
- package/es/virtualized-manager.js +61 -0
- package/package.json +9 -6
- package/src/add-cell/index.less +1 -1
- package/src/add-cell/libro-add-cell-slot-contribution.ts +1 -4
- package/src/add-cell/libro-add-cell-view.tsx +13 -6
- package/src/cell/libro-cell-contribution.ts +2 -6
- package/src/cell/libro-cell-model.ts +57 -4
- package/src/cell/libro-cell-protocol.ts +2 -0
- package/src/cell/libro-cell-view.tsx +21 -9
- package/src/cell/libro-edit-cell-view.tsx +10 -9
- package/src/cell/libro-executable-cell-view.ts +6 -1
- package/src/collapse-service.ts +1 -1
- package/src/command/document-commands.ts +3 -5
- package/src/command/kernel-command.ts +3 -0
- package/src/command/libro-command-contribution.ts +107 -91
- package/src/command/libro-command-register.ts +1 -4
- package/src/command/notebook-commands.ts +16 -3
- package/src/components/cell-protocol.ts +5 -5
- package/src/components/dnd-cell-item-render.tsx +239 -92
- package/src/components/dnd-component/custom-drag-layer.tsx +5 -6
- package/src/components/dnd-component/default-dnd-content.tsx +113 -42
- package/src/components/dnd-component/dnd-context.tsx +1 -1
- package/src/components/dnd-component/dnd-list.tsx +135 -43
- package/src/components/dnd-component/index.less +8 -0
- package/src/components/dnd-component/index.tsx +1 -1
- package/src/components/dnd-component/overscanIndices-getter.ts +92 -0
- package/src/components/dnd-component/virtualized-manager.ts +34 -0
- package/src/components/index.ts +2 -2
- package/src/components/libro-virtualized-render.tsx +178 -0
- package/src/content/index.ts +1 -0
- package/src/content/libro-content-contribution.ts +2 -3
- package/src/content/libro-content-module.ts +11 -3
- package/src/content/libro-content-protocol.ts +6 -0
- package/src/content/libro-content-service.ts +26 -8
- package/src/content/libro-save-content-contribution.ts +12 -0
- package/src/formatter/index.ts +5 -0
- package/src/formatter/libro-formatter-json-contribution.ts +42 -0
- package/src/formatter/libro-formatter-manager.ts +85 -0
- package/src/formatter/libro-formatter-module.ts +19 -0
- package/src/formatter/libro-formatter-protocol.ts +63 -0
- package/src/formatter/libro-formatter-string-contribution.ts +41 -0
- package/src/formatter/libro-formatter-trans-default-contribution.ts +15 -0
- package/src/index.less +135 -58
- package/src/index.tsx +6 -1
- package/src/libro-context-key.ts +3 -3
- package/src/libro-model.ts +87 -23
- package/src/libro-protocol.ts +81 -4
- package/src/libro-service.ts +4 -13
- package/src/{configuration/libro-configuration-contribution.ts → libro-setting-contribution.ts} +7 -8
- package/src/{configuration/libro-configuration.ts → libro-setting.ts} +18 -7
- package/src/libro-view.tsx +273 -141
- package/src/material-from-designer.tsx +93 -1
- package/src/module.ts +29 -7
- package/src/output/output-area.tsx +18 -12
- package/src/output/output-contribution.ts +2 -6
- package/src/output/output-model.tsx +3 -3
- package/src/output/output-protocol.ts +0 -1
- package/src/settings/index.less +3 -0
- package/src/settings/index.ts +4 -0
- package/src/settings/module.ts +8 -0
- package/src/settings/setting-editor/configuration-panel-view.tsx +89 -0
- package/src/settings/setting-editor/configuration-render-contribution.ts +81 -0
- package/src/settings/setting-editor/default-node-render.tsx +65 -0
- package/src/settings/setting-editor/index.less +12 -0
- package/src/settings/setting-editor/index.ts +6 -0
- package/src/settings/setting-editor/module.ts +17 -0
- package/src/settings/setting-editor/setting-editor-view.tsx +93 -0
- package/src/settings/setting-editor/setting-tree-service.ts +82 -0
- package/src/settings/setting-editor/setting-tree-view.tsx +95 -0
- package/src/settings/settings-contribution.tsx +24 -0
- package/src/settings/settings-modal.less +3 -0
- package/src/settings/settings-modal.tsx +50 -0
- package/src/settings/settings-protocol.ts +7 -0
- package/src/slot/libro-slot-manager.ts +1 -3
- package/src/slot/libro-slot-view.tsx +2 -5
- package/src/theme/libro-color-registry.ts +6 -0
- package/src/toolbar/all-outputs-scroll-icon.tsx +19 -0
- package/src/toolbar/libro-toolbar.tsx +30 -5
- package/src/toolbar/restart-clear-outputs-modal.tsx +3 -3
- package/src/toolbar/shutdown-modal.tsx +3 -3
- package/src/toolbar/side-toolar-more-select.tsx +2 -1
- package/src/virtualized-manager-helper.ts +29 -0
- package/src/virtualized-manager.ts +34 -0
- package/es/configuration/libro-configuration-contribution.d.ts.map +0 -1
- package/es/configuration/libro-configuration.d.ts.map +0 -1
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
+
import { AutoSizer, List } from '@difizen/libro-virtualized';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
import { EditorCellView } from '../cell/index.js';
|
|
7
|
+
import type { CellView, ScrollParams } from '../libro-protocol.js';
|
|
8
|
+
import type { LibroView } from '../libro-view.js';
|
|
9
|
+
|
|
10
|
+
import { DndCellRender } from './dnd-component/index.js';
|
|
11
|
+
|
|
12
|
+
interface LibroVirtualizedRowProps {
|
|
13
|
+
style: Record<string, string>;
|
|
14
|
+
cell: CellView;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const LibroVirtualizedRow: React.FC<LibroVirtualizedRowProps> = memo(
|
|
18
|
+
function LibroVirtualizedRow({ style, cell }: LibroVirtualizedRowProps) {
|
|
19
|
+
const itemRef = useRef(null);
|
|
20
|
+
|
|
21
|
+
// MarkDown Cell 需要隐藏其在虚拟滚动部分的占位div
|
|
22
|
+
const isHidden = cell.hasInputHidden;
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div ref={itemRef} style={{ ...style, visibility: 'hidden' }}>
|
|
26
|
+
{isHidden || !cell.renderEditorIntoVirtualized || !EditorCellView.is(cell) ? (
|
|
27
|
+
<></>
|
|
28
|
+
) : (
|
|
29
|
+
// cell.editorView && <ViewRender view={cell.editorView} />
|
|
30
|
+
cell.renderEditor && cell.renderEditor()
|
|
31
|
+
)}
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// 已经在上层判断是否为虚拟滚动
|
|
38
|
+
export const LibroCellsOutputRender: React.FC<{
|
|
39
|
+
cells: CellView[];
|
|
40
|
+
libroView: LibroView;
|
|
41
|
+
addCellButtons: ReactNode;
|
|
42
|
+
}> = ({ cells, libroView, addCellButtons }) => {
|
|
43
|
+
const parentRef = useRef(null);
|
|
44
|
+
const listRef = useRef<List | null>(null);
|
|
45
|
+
const noEditorAreaRef = useRef<HTMLDivElement | null>(null);
|
|
46
|
+
|
|
47
|
+
const [editorsOffset, setEditorsOffset] = useState<number[]>([]);
|
|
48
|
+
|
|
49
|
+
const editorAreaHeight = useMemo(() => {
|
|
50
|
+
const inputHeight = cells.map((cell: CellView) => {
|
|
51
|
+
if (cell.editorAreaHeight) {
|
|
52
|
+
return cell.editorAreaHeight;
|
|
53
|
+
} else {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return inputHeight;
|
|
58
|
+
}, [cells]);
|
|
59
|
+
|
|
60
|
+
const noEditorAreaHeight = useMemo(() => {
|
|
61
|
+
// 如果只有一个Cell,则它的最小高度是200,防止右侧边栏被隐藏。
|
|
62
|
+
const lastCellHeight = Math.max(
|
|
63
|
+
cells[cells.length - 1].noEditorAreaHeight || 0,
|
|
64
|
+
120,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const outputHeight = cells.map((cell: CellView, idx: number) => {
|
|
68
|
+
if (idx === cells.length - 1) {
|
|
69
|
+
return lastCellHeight;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (cell.noEditorAreaHeight) {
|
|
73
|
+
return cell.noEditorAreaHeight;
|
|
74
|
+
} else {
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (addCellButtons) {
|
|
80
|
+
outputHeight.push(90);
|
|
81
|
+
} //
|
|
82
|
+
|
|
83
|
+
return outputHeight;
|
|
84
|
+
}, [cells, addCellButtons]);
|
|
85
|
+
|
|
86
|
+
const totalSize = useMemo(
|
|
87
|
+
() => noEditorAreaHeight.reduce((pre, cur) => pre + cur),
|
|
88
|
+
[noEditorAreaHeight],
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!listRef || !listRef.current || !libroView.model) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
libroView.model.onScrollToCellView((params: ScrollParams) => {
|
|
97
|
+
// listRef.current!.scrollToRow(index);
|
|
98
|
+
listRef.current!.scrollToLine(params.cellIndex, params.lineIndex || 1);
|
|
99
|
+
});
|
|
100
|
+
return () => {
|
|
101
|
+
libroView.model.disposeScrollToCellViewEmitter();
|
|
102
|
+
};
|
|
103
|
+
}, [listRef, libroView]);
|
|
104
|
+
|
|
105
|
+
// 在Cell的高度变化时,触发重新计算所有Cell的高度偏移值
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (!noEditorAreaRef.current) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const newCellOffsets: number[] = [];
|
|
112
|
+
const childNum = noEditorAreaRef.current.childNodes.length || 0;
|
|
113
|
+
noEditorAreaRef.current.childNodes.forEach((child, index) => {
|
|
114
|
+
// 最后一个child元素是 addCellButtons
|
|
115
|
+
if (index === childNum - 1) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const offsetTop = (child as HTMLDivElement).offsetTop;
|
|
120
|
+
|
|
121
|
+
let offset = 0;
|
|
122
|
+
if (cells[index].calcEditorOffset) {
|
|
123
|
+
offset += cells[index].calcEditorOffset!();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
newCellOffsets[index] = offsetTop + offset;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
setEditorsOffset(newCellOffsets);
|
|
130
|
+
}, [noEditorAreaRef.current, cells]);
|
|
131
|
+
|
|
132
|
+
// 绘制所有的非编辑器区域
|
|
133
|
+
const noEditorArea = useMemo(() => {
|
|
134
|
+
return (
|
|
135
|
+
<div
|
|
136
|
+
style={{
|
|
137
|
+
position: 'absolute',
|
|
138
|
+
visibility: 'visible',
|
|
139
|
+
width: '100%',
|
|
140
|
+
height: '100%',
|
|
141
|
+
}}
|
|
142
|
+
ref={noEditorAreaRef}
|
|
143
|
+
>
|
|
144
|
+
{cells
|
|
145
|
+
.filter((cell) => cell.collapsedHidden === false)
|
|
146
|
+
.map((cell, index) => {
|
|
147
|
+
return <DndCellRender cell={cell} key={cell.id} index={index} />;
|
|
148
|
+
})}
|
|
149
|
+
{addCellButtons}
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}, [cells, addCellButtons]);
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<AutoSizer style={{ height: '100%', width: '100%' }} ref={parentRef}>
|
|
156
|
+
{({ width, height }: { width: number; height: number }) => {
|
|
157
|
+
return (
|
|
158
|
+
<List
|
|
159
|
+
ref={listRef}
|
|
160
|
+
width={width}
|
|
161
|
+
height={height}
|
|
162
|
+
rowCount={cells.length}
|
|
163
|
+
rowHeight={50}
|
|
164
|
+
// rowHeight={getOrCreateCache(libroView.id).rowHeight}
|
|
165
|
+
rowRenderer={({ key, index, style }: any) => (
|
|
166
|
+
<LibroVirtualizedRow key={key} style={style} cell={cells[index]} />
|
|
167
|
+
)}
|
|
168
|
+
cellsHeight={noEditorAreaHeight}
|
|
169
|
+
totalSize={totalSize}
|
|
170
|
+
editorAreaHeight={editorAreaHeight}
|
|
171
|
+
noEditorArea={noEditorArea}
|
|
172
|
+
editorsOffset={editorsOffset}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}}
|
|
176
|
+
</AutoSizer>
|
|
177
|
+
);
|
|
178
|
+
};
|
package/src/content/index.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
1
|
import { singleton } from '@difizen/mana-app';
|
|
3
2
|
|
|
4
3
|
import { ContentContribution } from './libro-content-protocol.js';
|
|
5
4
|
|
|
6
5
|
@singleton({ contrib: ContentContribution })
|
|
7
6
|
export class DefaultContentContribution implements ContentContribution {
|
|
8
|
-
canHandle = (
|
|
9
|
-
loadContent(
|
|
7
|
+
canHandle = (options: Record<string, any>, model: any) => 1;
|
|
8
|
+
loadContent(options: Record<string, any>, model: any) {
|
|
10
9
|
return Promise.resolve({
|
|
11
10
|
metadata: {},
|
|
12
11
|
cells: [],
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { ManaModule } from '@difizen/mana-app';
|
|
2
2
|
|
|
3
3
|
import { DefaultContentContribution } from './libro-content-contribution.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ContentContribution,
|
|
6
|
+
ContentSaveContribution,
|
|
7
|
+
} from './libro-content-protocol.js';
|
|
5
8
|
import { LibroContentService } from './libro-content-service.js';
|
|
9
|
+
import { DefaultSaveContentContribution } from './libro-save-content-contribution.js';
|
|
6
10
|
|
|
7
11
|
export const LibroContentModule = ManaModule.create()
|
|
8
|
-
.contribution(ContentContribution)
|
|
9
|
-
.register(
|
|
12
|
+
.contribution(ContentContribution, ContentSaveContribution)
|
|
13
|
+
.register(
|
|
14
|
+
DefaultContentContribution,
|
|
15
|
+
LibroContentService,
|
|
16
|
+
DefaultSaveContentContribution,
|
|
17
|
+
);
|
|
@@ -6,3 +6,9 @@ export interface ContentContribution {
|
|
|
6
6
|
canHandle: (options: Record<string, any>, model: any) => number;
|
|
7
7
|
loadContent: (options: Record<string, any>, model: any) => Promise<INotebookContent>;
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
export const ContentSaveContribution = Syringe.defineToken('ContentSaveContribution');
|
|
11
|
+
export interface ContentSaveContribution {
|
|
12
|
+
canHandle: (options: Record<string, any>, model: any) => number;
|
|
13
|
+
saveContent: (options: Record<string, any>, model: any) => Promise<void>;
|
|
14
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import type { Contribution } from '@difizen/mana-app';
|
|
2
2
|
import { contrib, Priority, singleton } from '@difizen/mana-app';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ContentContribution,
|
|
6
|
+
ContentSaveContribution,
|
|
7
|
+
} from './libro-content-protocol.js';
|
|
5
8
|
|
|
6
9
|
@singleton()
|
|
7
10
|
export class LibroContentService {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
11
|
+
@contrib(ContentContribution)
|
|
12
|
+
contentProvider: Contribution.Provider<ContentContribution>;
|
|
13
|
+
|
|
14
|
+
@contrib(ContentSaveContribution)
|
|
15
|
+
contentSaveProvider: Contribution.Provider<ContentSaveContribution>;
|
|
16
|
+
|
|
15
17
|
protected findProvider(
|
|
16
18
|
options: Record<string, any>,
|
|
17
19
|
model: any,
|
|
@@ -27,4 +29,20 @@ export class LibroContentService {
|
|
|
27
29
|
loadLibroContent(options: Record<string, any>, model: any) {
|
|
28
30
|
return this.findProvider(options, model).loadContent(options, model);
|
|
29
31
|
}
|
|
32
|
+
|
|
33
|
+
protected findSaveProvider(
|
|
34
|
+
options: Record<string, any>,
|
|
35
|
+
model: any,
|
|
36
|
+
): ContentSaveContribution {
|
|
37
|
+
const prioritized = Priority.sortSync(
|
|
38
|
+
this.contentSaveProvider.getContributions(),
|
|
39
|
+
(contribution) => contribution.canHandle(options, model),
|
|
40
|
+
);
|
|
41
|
+
const sorted = prioritized.map((c) => c.value);
|
|
42
|
+
return sorted[0]!;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
saveLibroContent(options: Record<string, any>, model: any) {
|
|
46
|
+
return this.findSaveProvider(options, model).saveContent(options, model);
|
|
47
|
+
}
|
|
30
48
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { ContentSaveContribution } from './libro-content-protocol.js';
|
|
5
|
+
|
|
6
|
+
@singleton({ contrib: ContentSaveContribution })
|
|
7
|
+
export class DefaultSaveContentContribution implements ContentSaveContribution {
|
|
8
|
+
canHandle = (options: Record<string, any>, model: any) => 1;
|
|
9
|
+
saveContent(options: Record<string, any>, model: any) {
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
3
|
+
import { singleton } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DefaultDecodedFormatter,
|
|
7
|
+
FormatterContribution,
|
|
8
|
+
} from './libro-formatter-protocol.js';
|
|
9
|
+
import type { DefaultEncodedFormatter } from './libro-formatter-protocol.js';
|
|
10
|
+
|
|
11
|
+
@singleton({ contrib: FormatterContribution })
|
|
12
|
+
export class FormatterJsonContribution
|
|
13
|
+
implements FormatterContribution<DefaultDecodedFormatter>
|
|
14
|
+
{
|
|
15
|
+
formatter = 'formatter-json';
|
|
16
|
+
formatterOptions?: object;
|
|
17
|
+
canHandle = (libroFormatter: string) => {
|
|
18
|
+
if (libroFormatter === this.formatter) {
|
|
19
|
+
return 100;
|
|
20
|
+
}
|
|
21
|
+
return 1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
encode = (source: DefaultDecodedFormatter) => {
|
|
25
|
+
return {
|
|
26
|
+
source: source.value,
|
|
27
|
+
metadata: {
|
|
28
|
+
libroFormatter: 'formatter-string',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
34
|
+
return {
|
|
35
|
+
value: concatMultilineString(formatterValue.source),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
validate = (source: DefaultDecodedFormatter): source is DefaultDecodedFormatter => {
|
|
40
|
+
return DefaultDecodedFormatter.is(source);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { contrib, Priority, singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { CellModelContribution } from '../cell/index.js';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
FormatterContribution,
|
|
8
|
+
FormatterTransContribution,
|
|
9
|
+
} from './libro-formatter-protocol.js';
|
|
10
|
+
import type { DefaultEncodedFormatter } from './libro-formatter-protocol.js';
|
|
11
|
+
|
|
12
|
+
@singleton()
|
|
13
|
+
export class LibroFormatterManager<T, U> {
|
|
14
|
+
@contrib(FormatterContribution)
|
|
15
|
+
protected readonly formatterProvider: Contribution.Provider<FormatterContribution<T>>;
|
|
16
|
+
@contrib(FormatterTransContribution)
|
|
17
|
+
protected readonly formatterTransProvider: Contribution.Provider<
|
|
18
|
+
FormatterTransContribution<T, U>
|
|
19
|
+
>;
|
|
20
|
+
protected readonly cellModelProvider: Contribution.Provider<CellModelContribution>;
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
@contrib(CellModelContribution)
|
|
24
|
+
cellModelProvider: Contribution.Provider<CellModelContribution>,
|
|
25
|
+
) {
|
|
26
|
+
this.cellModelProvider = cellModelProvider;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected findFormatterProvider(
|
|
30
|
+
libroFormatter: string,
|
|
31
|
+
options?: object,
|
|
32
|
+
): FormatterContribution<T> {
|
|
33
|
+
const prioritized = Priority.sortSync(
|
|
34
|
+
this.formatterProvider.getContributions(),
|
|
35
|
+
(contribution) => contribution.canHandle(libroFormatter, options),
|
|
36
|
+
);
|
|
37
|
+
const sorted = prioritized.map((c) => c.value);
|
|
38
|
+
return sorted[0]!;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected findFormatterTransProvider(
|
|
42
|
+
origin: string,
|
|
43
|
+
target: string,
|
|
44
|
+
): FormatterTransContribution<T, U> {
|
|
45
|
+
const prioritized = Priority.sortSync(
|
|
46
|
+
this.formatterTransProvider.getContributions(),
|
|
47
|
+
(contribution) => {
|
|
48
|
+
if (origin === contribution.origin && target === contribution.target) {
|
|
49
|
+
return contribution.priority;
|
|
50
|
+
}
|
|
51
|
+
return 1;
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
const sorted = prioritized.map((c) => c.value);
|
|
55
|
+
return sorted[0]!;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
encode(libroFormatter: string, source: T): DefaultEncodedFormatter {
|
|
59
|
+
const formatter = this.findFormatterProvider(libroFormatter);
|
|
60
|
+
return formatter.encode(source);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
decode(libroFormatter: string, formatterValue: DefaultEncodedFormatter): T {
|
|
64
|
+
const formatter = this.findFormatterProvider(libroFormatter);
|
|
65
|
+
return formatter.decode(formatterValue);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
adapter(libroFormatter: string, formatterValue: DefaultEncodedFormatter): U {
|
|
69
|
+
const originFormatter = this.findFormatterProvider(
|
|
70
|
+
formatterValue.metadata.libroFormatter,
|
|
71
|
+
);
|
|
72
|
+
const originDecodedValue = originFormatter.decode(formatterValue);
|
|
73
|
+
const targetFormatter = this.findFormatterProvider(libroFormatter);
|
|
74
|
+
if (targetFormatter.validate(originDecodedValue)) {
|
|
75
|
+
return originDecodedValue as unknown as U;
|
|
76
|
+
} else {
|
|
77
|
+
const formatterTransProvider = this.findFormatterTransProvider(
|
|
78
|
+
formatterValue.metadata.libroFormatter,
|
|
79
|
+
libroFormatter,
|
|
80
|
+
);
|
|
81
|
+
const decodedValue = formatterTransProvider.decodedValueTrans(originDecodedValue);
|
|
82
|
+
return decodedValue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import { FormatterJsonContribution } from './libro-formatter-json-contribution.js';
|
|
4
|
+
import { LibroFormatterManager } from './libro-formatter-manager.js';
|
|
5
|
+
import {
|
|
6
|
+
FormatterContribution,
|
|
7
|
+
FormatterTransContribution,
|
|
8
|
+
} from './libro-formatter-protocol.js';
|
|
9
|
+
import { FormatterStringContribution } from './libro-formatter-string-contribution.js';
|
|
10
|
+
import { FormatterTransDefaultContribution } from './libro-formatter-trans-default-contribution.js';
|
|
11
|
+
|
|
12
|
+
export const LibroFormatterModule = ManaModule.create()
|
|
13
|
+
.contribution(FormatterContribution, FormatterTransContribution)
|
|
14
|
+
.register(
|
|
15
|
+
LibroFormatterManager,
|
|
16
|
+
FormatterStringContribution,
|
|
17
|
+
FormatterJsonContribution,
|
|
18
|
+
FormatterTransDefaultContribution,
|
|
19
|
+
);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { MultilineString } from '@difizen/libro-common';
|
|
2
|
+
import { Syringe } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
export const FormatterContribution = Syringe.defineToken('FormatterContribution');
|
|
5
|
+
|
|
6
|
+
export interface FormatterContribution<T> {
|
|
7
|
+
formatter: string;
|
|
8
|
+
formatterOptions?: object;
|
|
9
|
+
canHandle: (libroFormatter: string, options?: object) => number;
|
|
10
|
+
encode: (source: T) => DefaultEncodedFormatter;
|
|
11
|
+
decode: (formatterValue: DefaultEncodedFormatter) => T;
|
|
12
|
+
validate: (source: T) => source is T;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const FormatterTransContribution = Syringe.defineToken(
|
|
16
|
+
'FormatterTransContribution',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export interface FormatterTransContribution<T, U> {
|
|
20
|
+
origin?: string;
|
|
21
|
+
target?: string;
|
|
22
|
+
priority: number;
|
|
23
|
+
decodedValueTrans: (source: T) => U;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DefaultEncodedFormatter {
|
|
27
|
+
source: MultilineString;
|
|
28
|
+
metadata: {
|
|
29
|
+
libroFormatter: string;
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
};
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DefaultDecodedFormatter {
|
|
36
|
+
value: string;
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const DefaultDecodedFormatter = {
|
|
41
|
+
is: (arg: Record<any, any> | undefined): arg is DefaultDecodedFormatter => {
|
|
42
|
+
return (
|
|
43
|
+
!!arg &&
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
'value' in arg &&
|
|
46
|
+
typeof (arg as any).value === 'string'
|
|
47
|
+
);
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const DefaultEncodedFormatter = {
|
|
52
|
+
is: (arg: Record<any, any> | undefined): arg is DefaultEncodedFormatter => {
|
|
53
|
+
return (
|
|
54
|
+
!!arg &&
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
'source' in arg &&
|
|
57
|
+
'metadata' in arg &&
|
|
58
|
+
'libroFormatter' in arg['metadata'] &&
|
|
59
|
+
typeof (arg as any).metadata.libroFormatter === 'string' &&
|
|
60
|
+
typeof (arg as any).metadata === 'object'
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { concatMultilineString } from '@difizen/libro-common';
|
|
3
|
+
import { singleton } from '@difizen/mana-app';
|
|
4
|
+
|
|
5
|
+
import type { DefaultEncodedFormatter } from './libro-formatter-protocol.js';
|
|
6
|
+
import {
|
|
7
|
+
DefaultDecodedFormatter,
|
|
8
|
+
FormatterContribution,
|
|
9
|
+
} from './libro-formatter-protocol.js';
|
|
10
|
+
|
|
11
|
+
@singleton({ contrib: FormatterContribution })
|
|
12
|
+
export class FormatterStringContribution
|
|
13
|
+
implements FormatterContribution<DefaultDecodedFormatter>
|
|
14
|
+
{
|
|
15
|
+
formatter = 'formatter-string';
|
|
16
|
+
formatterOptions?: object;
|
|
17
|
+
|
|
18
|
+
canHandle = (libroFormatter: string) => {
|
|
19
|
+
if (libroFormatter === this.formatter) {
|
|
20
|
+
return 100;
|
|
21
|
+
}
|
|
22
|
+
return 1;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
encode = (source: DefaultDecodedFormatter) => {
|
|
26
|
+
return {
|
|
27
|
+
source: source.value,
|
|
28
|
+
metadata: {
|
|
29
|
+
libroFormatter: 'formatter-string',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
35
|
+
return { value: concatMultilineString(formatterValue.source) };
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
validate = (source: DefaultDecodedFormatter): source is DefaultDecodedFormatter => {
|
|
39
|
+
return DefaultDecodedFormatter.is(source);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import { singleton } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import type { DefaultDecodedFormatter } from './libro-formatter-protocol.js';
|
|
5
|
+
import { FormatterTransContribution } from './libro-formatter-protocol.js';
|
|
6
|
+
|
|
7
|
+
@singleton({ contrib: FormatterTransContribution })
|
|
8
|
+
export class FormatterTransDefaultContribution
|
|
9
|
+
implements
|
|
10
|
+
FormatterTransContribution<DefaultDecodedFormatter, DefaultDecodedFormatter>
|
|
11
|
+
{
|
|
12
|
+
priority = 1;
|
|
13
|
+
|
|
14
|
+
decodedValueTrans = (source: DefaultDecodedFormatter) => source;
|
|
15
|
+
}
|