@tmagic/editor 1.8.0-manmanyu.8 → 1.8.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/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +22 -13
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +10 -5
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +7 -6
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +21 -119
- package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +21 -5
- package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +62 -16
- package/dist/es/components/Icon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/Resizer.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/es/components/ScrollBar.js +0 -1
- package/dist/es/components/ScrollBar.vue_vue_type_script_setup_true_lang.js +5 -4
- package/dist/es/components/ScrollViewer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SearchInput.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/SplitView.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ToolButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/Tree.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/TreeNode.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/components/ViewForm.js +5 -0
- package/dist/es/components/ViewForm.vue_vue_type_script_setup_true_lang.js +56 -0
- package/dist/es/editorProps.js +7 -1
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +30 -113
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +7 -19
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +7 -6
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +12 -4
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +9 -20
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +2 -2
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +9 -4
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +10 -110
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +52 -363
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +3 -6
- package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +4 -35
- package/dist/es/fields/StyleSetter/components/Box.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/fields/StyleSetter/configs.js +663 -0
- package/dist/es/fields/StyleSetter/icons/align-items/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/FlexEnd.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/FlexStart.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceAround.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceBetween.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +1 -1
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Block.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Flex.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/Inline.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/InlineBlock.js +1 -1
- package/dist/es/fields/StyleSetter/icons/display/None.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +1 -1
- package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +1 -1
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Center.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Left.js +1 -1
- package/dist/es/fields/StyleSetter/icons/text-align/Right.js +1 -1
- package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +29 -106
- package/dist/es/fields/StyleSetter/pro/Border.vue_vue_type_script_setup_true_lang.js +8 -11
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +30 -89
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +29 -297
- package/dist/es/fields/StyleSetter/pro/Position.vue_vue_type_script_setup_true_lang.js +29 -82
- package/dist/es/fields/StyleSetter/pro/Transform.vue_vue_type_script_setup_true_lang.js +8 -24
- package/dist/es/fields/UISelect.js +0 -1
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/configs/codeSelect.js +98 -0
- package/dist/es/fields/configs/displayConds.js +158 -0
- package/dist/es/fields/configs/eventSelect.js +225 -0
- package/dist/es/fields/configs/stickyAddButton.js +21 -0
- package/dist/es/fields/headless-validation.js +139 -0
- package/dist/es/headless.js +2 -0
- package/dist/es/hooks/use-code-block-edit.js +4 -2
- package/dist/es/hooks/use-compare-form.js +101 -0
- package/dist/es/hooks/use-form-context.js +29 -0
- package/dist/es/hooks/use-stage.js +1 -0
- package/dist/es/icons/CenterIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/CodeIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/icons/DatasourceIcon.js +1 -1
- package/dist/es/icons/FolderMinusIcon.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/index.js +17 -9
- package/dist/es/initService.js +52 -16
- package/dist/es/layouts/AddPageBox.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +26 -10
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +11 -8
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/layouts/NavMenuColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +26 -10
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +36 -28
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/history-list/composables.js +1 -1
- package/dist/es/layouts/history-list/useHistoryList.js +4 -4
- package/dist/es/layouts/history-list/useHistoryRevert.js +38 -33
- package/dist/es/layouts/page-bar/AddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageBarScrollContainer.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/PageList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/page-bar/Search.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/props-panel/FormPanel.vue_vue_type_script_setup_true_lang.js +50 -20
- package/dist/es/layouts/props-panel/PropsPanel.vue_vue_type_script_setup_true_lang.js +53 -35
- package/dist/es/layouts/props-panel/use-style-panel.js +3 -2
- package/dist/es/layouts/sidebar/ComponentListPanel.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +21 -36
- package/dist/es/layouts/sidebar/code-block/CodeBlockList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/code-block/CodeBlockListPanel.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/sidebar/code-block/useContentMenu.js +19 -4
- package/dist/es/layouts/sidebar/data-source/DataSourceAddButton.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceConfigPanel.vue_vue_type_script_setup_true_lang.js +9 -4
- package/dist/es/layouts/sidebar/data-source/DataSourceList.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/data-source/DataSourceListPanel.vue_vue_type_script_setup_true_lang.js +4 -4
- package/dist/es/layouts/sidebar/data-source/useContentMenu.js +19 -4
- package/dist/es/layouts/sidebar/layer/LayerMenu.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/layouts/sidebar/layer/LayerNodeContent.js +5 -0
- package/dist/es/layouts/sidebar/layer/LayerNodeContent.vue_vue_type_script_setup_true_lang.js +46 -0
- package/dist/es/layouts/sidebar/layer/LayerNodeTool.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/sidebar/layer/LayerPanel.vue_vue_type_script_setup_true_lang.js +6 -4
- package/dist/es/layouts/sidebar/layer/use-click.js +3 -3
- package/dist/es/layouts/sidebar/layer/use-drag.js +11 -10
- package/dist/es/layouts/sidebar/layer/use-node-status.js +2 -2
- package/dist/es/layouts/workspace/Breadcrumb.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/Workspace.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/NodeListMenu.vue_vue_type_script_setup_true_lang.js +9 -3
- package/dist/es/layouts/workspace/viewer/Stage.vue_vue_type_script_setup_true_lang.js +55 -9
- package/dist/es/layouts/workspace/viewer/StageOverlay.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/layouts/workspace/viewer/ViewerMenu.vue_vue_type_script_setup_true_lang.js +8 -8
- package/dist/es/plugin.js +35 -23
- package/dist/es/services/codeBlock.js +40 -31
- package/dist/es/services/dataSource.js +46 -34
- package/dist/es/services/dep.js +162 -41
- package/dist/es/services/editor.js +373 -137
- package/dist/es/services/events.js +4 -4
- package/dist/es/services/history.js +275 -392
- package/dist/es/services/keybinding.js +3 -3
- package/dist/es/services/props.js +2 -1
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +7 -2
- package/dist/es/style.css +277 -114
- package/dist/es/utils/code-block.js +14 -7
- package/dist/es/utils/config.js +4 -1
- package/dist/es/utils/const.js +2 -2
- package/dist/es/utils/content-menu.js +2 -2
- package/dist/es/utils/data-source/index.js +34 -12
- package/dist/es/utils/dep/collect-worker-client.js +154 -0
- package/dist/es/utils/dep/idle-task.js +70 -22
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +4 -2
- package/dist/es/utils/event.js +135 -0
- package/dist/es/utils/history.js +35 -47
- package/dist/es/utils/monaco-editor.js +22 -6
- package/dist/es/utils/operator.js +2 -2
- package/dist/es/utils/props.js +50 -106
- package/dist/es/utils/type-match-rules.js +356 -0
- package/dist/style.css +277 -114
- package/dist/themes/magic-admin.css +978 -175
- package/dist/tmagic-editor-headless.umd.cjs +10880 -0
- package/dist/tmagic-editor.umd.cjs +13047 -11363
- package/package.json +18 -13
- package/src/Editor.vue +23 -6
- package/src/components/CodeBlockEditor.vue +3 -0
- package/src/components/CodeParams.vue +10 -4
- package/src/components/CompareForm.vue +20 -190
- package/src/components/ContentMenu.vue +34 -6
- package/src/components/FloatingBox.vue +71 -7
- package/src/components/ScrollBar.vue +0 -67
- package/src/components/ViewForm.vue +54 -0
- package/src/editorProps.ts +23 -10
- package/src/fields/Code.vue +1 -1
- package/src/fields/CodeSelect.vue +20 -113
- package/src/fields/CodeSelectCol.vue +1 -1
- package/src/fields/CondOpSelect.vue +5 -26
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +2 -2
- package/src/fields/DataSourceFieldSelect/Index.vue +4 -1
- package/src/fields/DataSourceFields.vue +5 -1
- package/src/fields/DataSourceInput.vue +10 -28
- package/src/fields/DataSourceMethodSelect.vue +1 -1
- package/src/fields/DataSourceMethods.vue +6 -2
- package/src/fields/DataSourceMocks.vue +3 -0
- package/src/fields/DataSourceSelect.vue +1 -1
- package/src/fields/DisplayConds.vue +17 -139
- package/src/fields/EventSelect.vue +29 -416
- package/src/fields/KeyValue.vue +1 -1
- package/src/fields/StyleSetter/Index.vue +2 -8
- package/src/fields/StyleSetter/components/Border.vue +4 -38
- package/src/fields/StyleSetter/components/Box.vue +1 -1
- package/src/fields/StyleSetter/components/Position.vue +1 -1
- package/src/fields/StyleSetter/configs.ts +690 -0
- package/src/fields/StyleSetter/pro/Background.vue +9 -64
- package/src/fields/StyleSetter/pro/Border.vue +5 -16
- package/src/fields/StyleSetter/pro/Font.vue +11 -71
- package/src/fields/StyleSetter/pro/Layout.vue +10 -230
- package/src/fields/StyleSetter/pro/Position.vue +11 -82
- package/src/fields/StyleSetter/pro/Transform.vue +6 -34
- package/src/fields/UISelect.vue +0 -12
- package/src/fields/configs/codeSelect.ts +127 -0
- package/src/fields/configs/displayConds.ts +184 -0
- package/src/fields/configs/eventSelect.ts +309 -0
- package/src/fields/configs/stickyAddButton.ts +32 -0
- package/src/fields/headless-validation.ts +177 -0
- package/src/headless.ts +33 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-compare-form.ts +166 -0
- package/src/hooks/use-form-context.ts +56 -0
- package/src/hooks/use-stage.ts +1 -0
- package/src/index.ts +9 -0
- package/src/initService.ts +73 -18
- package/src/layouts/CodeEditor.vue +32 -6
- package/src/layouts/Framework.vue +7 -6
- package/src/layouts/history-list/BucketTab.vue +2 -2
- package/src/layouts/history-list/HistoryDiffDialog.vue +33 -15
- package/src/layouts/history-list/HistoryListPanel.vue +16 -18
- package/src/layouts/history-list/useHistoryRevert.ts +57 -41
- package/src/layouts/props-panel/FormPanel.vue +75 -20
- package/src/layouts/props-panel/PropsPanel.vue +81 -30
- package/src/layouts/props-panel/use-style-panel.ts +4 -3
- package/src/layouts/sidebar/ComponentListPanel.vue +6 -2
- package/src/layouts/sidebar/Sidebar.vue +5 -3
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +5 -2
- package/src/layouts/sidebar/code-block/useContentMenu.ts +14 -2
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +3 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +3 -3
- package/src/layouts/sidebar/data-source/useContentMenu.ts +14 -2
- package/src/layouts/sidebar/layer/LayerMenu.vue +2 -2
- package/src/layouts/sidebar/layer/LayerNodeContent.vue +57 -0
- package/src/layouts/sidebar/layer/LayerPanel.vue +5 -2
- package/src/layouts/sidebar/layer/use-click.ts +3 -3
- package/src/layouts/sidebar/layer/use-node-status.ts +2 -2
- package/src/layouts/workspace/viewer/NodeListMenu.vue +4 -1
- package/src/layouts/workspace/viewer/Stage.vue +80 -10
- package/src/layouts/workspace/viewer/ViewerMenu.vue +7 -7
- package/src/plugin.ts +35 -25
- package/src/services/codeBlock.ts +4 -0
- package/src/services/dataSource.ts +3 -0
- package/src/services/dep.ts +292 -47
- package/src/services/editor.ts +383 -120
- package/src/services/events.ts +8 -7
- package/src/services/history.ts +22 -1
- package/src/services/keybinding.ts +3 -3
- package/src/services/ui.ts +26 -5
- package/src/theme/code-block.scss +0 -37
- package/src/theme/display-conds.scss +4 -0
- package/src/theme/event.scss +25 -33
- package/src/theme/floating-box.scss +9 -1
- package/src/theme/framework.scss +4 -1
- package/src/theme/layer-node-content.scss +14 -0
- package/src/theme/nav-menu.scss +5 -1
- package/src/theme/props-panel.scss +17 -3
- package/src/theme/scroll-bar.scss +64 -0
- package/src/theme/theme.scss +3 -0
- package/src/theme/themes/magic-admin/index.scss +109 -9
- package/src/theme/ui-select.scss +9 -0
- package/src/type.ts +216 -6
- package/src/utils/code-block.ts +1 -0
- package/src/utils/config.ts +9 -1
- package/src/utils/const.ts +3 -3
- package/src/utils/content-menu.ts +2 -2
- package/src/utils/data-source/index.ts +31 -12
- package/src/utils/dep/collect-worker-client.ts +215 -0
- package/src/utils/dep/idle-task.ts +104 -35
- package/src/utils/dep/worker.ts +113 -9
- package/src/utils/event.ts +237 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/monaco-editor.ts +27 -0
- package/src/utils/operator.ts +2 -2
- package/src/utils/props.ts +61 -122
- package/src/utils/type-match-rules.ts +697 -0
- package/types/headless.d.ts +17 -0
- package/types/index.d.ts +1494 -978
- package/src/fields/StyleSetter/icons/align-items/index copy.ts +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import BaseService from "./BaseService.js";
|
|
2
1
|
import { getEditorConfig } from "../utils/config.js";
|
|
2
|
+
import BaseService from "./BaseService.js";
|
|
3
3
|
import { UndoRedo } from "../utils/undo-redo.js";
|
|
4
|
-
import {
|
|
4
|
+
import { deserializeStacks, getOrCreateStack, markStackSaved, mergeSteps, serializeStacks, undoFloor } from "../utils/history.js";
|
|
5
5
|
import { idbGet, idbSet } from "../utils/indexed-db.js";
|
|
6
6
|
import editor_default from "./editor.js";
|
|
7
7
|
import { guid } from "@tmagic/utils";
|
|
@@ -9,78 +9,92 @@ import { reactive } from "vue";
|
|
|
9
9
|
//#region packages/editor/src/services/history.ts
|
|
10
10
|
var canUsePluginMethods = { sync: [
|
|
11
11
|
"push",
|
|
12
|
-
"pushCodeBlock",
|
|
13
|
-
"pushDataSource",
|
|
14
|
-
"undoCodeBlock",
|
|
15
|
-
"redoCodeBlock",
|
|
16
|
-
"undoDataSource",
|
|
17
|
-
"redoDataSource",
|
|
18
12
|
"undo",
|
|
19
13
|
"redo"
|
|
20
14
|
] };
|
|
15
|
+
/** 各内置历史类型的默认展示名称(用于历史面板 tab / 分组标题等)。扩展类型可通过 registerStepType / setStepName 登记。 */
|
|
16
|
+
var DEFAULT_STEP_NAMES = {
|
|
17
|
+
page: "页面",
|
|
18
|
+
codeBlock: "代码块",
|
|
19
|
+
dataSource: "数据源"
|
|
20
|
+
};
|
|
21
|
+
/** 各历史类型对应的分组 `kind`(展示用):page→page,codeBlock→code-block,dataSource→data-source。扩展类型缺省回退到 stepType 本身。 */
|
|
22
|
+
var STEP_TYPE_KIND = {
|
|
23
|
+
page: "page",
|
|
24
|
+
codeBlock: "code-block",
|
|
25
|
+
dataSource: "data-source"
|
|
26
|
+
};
|
|
21
27
|
/** 历史记录持久化快照的默认存储位置与结构版本。 */
|
|
22
28
|
var DEFAULT_DB_NAME = "tmagic-editor";
|
|
23
29
|
var DEFAULT_STORE_NAME = "history";
|
|
24
30
|
var DEFAULT_KEY = "default";
|
|
25
|
-
var PERSIST_VERSION =
|
|
31
|
+
var PERSIST_VERSION = 3;
|
|
26
32
|
var History = class extends BaseService {
|
|
27
33
|
state = reactive({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
steps: {
|
|
35
|
+
page: {},
|
|
36
|
+
codeBlock: {},
|
|
37
|
+
dataSource: {}
|
|
38
|
+
},
|
|
39
|
+
stepNames: { ...DEFAULT_STEP_NAMES }
|
|
34
40
|
});
|
|
35
41
|
constructor() {
|
|
36
42
|
super([...canUsePluginMethods.sync.map((methodName) => ({
|
|
37
43
|
name: methodName,
|
|
38
44
|
isAsync: false
|
|
39
45
|
}))]);
|
|
40
|
-
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 注册一个扩展历史类型,使其可与内置 `page` / `codeBlock` / `dataSource` 一样走统一的
|
|
49
|
+
* {@link push} / {@link undo} / {@link redo}(按 id 分栈、独立 undo/redo)。
|
|
50
|
+
*
|
|
51
|
+
* @param stepType 自定义历史类型标识(勿与内置类型重名)
|
|
52
|
+
* @param options.event push/undo/redo 后派发的事件名,缺省为 `${stepType}-history-change`
|
|
53
|
+
* @param options.name 历史面板中的展示名称(tab / 分组标题等),缺省回退到 stepType 本身
|
|
54
|
+
*/
|
|
55
|
+
registerStepType(stepType, options = {}) {
|
|
56
|
+
this.getStepBucket(stepType);
|
|
57
|
+
if (options.name !== void 0) this.state.stepNames[stepType] = options.name;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 读取指定历史类型的展示名称(用于历史面板 tab / 分组标题等)。
|
|
61
|
+
* 未登记名称时回退到 stepType 本身。
|
|
62
|
+
*/
|
|
63
|
+
getStepName(stepType) {
|
|
64
|
+
return this.state.stepNames[stepType] ?? `${stepType}`;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 设置指定历史类型的展示名称(用于历史面板 tab / 分组标题等)。
|
|
68
|
+
* 内置 `page` / `codeBlock` / `dataSource` 也可在此覆盖默认中文名。
|
|
69
|
+
*/
|
|
70
|
+
setStepName(stepType, name) {
|
|
71
|
+
this.state.stepNames[stepType] = name;
|
|
41
72
|
}
|
|
42
73
|
reset() {
|
|
43
|
-
this.
|
|
44
|
-
this.state.codeBlockState = {};
|
|
45
|
-
this.state.dataSourceState = {};
|
|
46
|
-
this.resetPage();
|
|
47
|
-
}
|
|
48
|
-
resetPage() {
|
|
49
|
-
this.state.pageId = void 0;
|
|
50
|
-
this.state.canRedo = false;
|
|
51
|
-
this.state.canUndo = false;
|
|
52
|
-
}
|
|
53
|
-
changePage(page) {
|
|
54
|
-
if (!page) return;
|
|
55
|
-
this.state.pageId = page.id;
|
|
56
|
-
if (!this.state.pageSteps[this.state.pageId]) this.state.pageSteps[this.state.pageId] = new UndoRedo();
|
|
57
|
-
this.setCanUndoRedo();
|
|
58
|
-
this.emit("page-change", this.state.pageSteps[this.state.pageId]);
|
|
74
|
+
this.clearAllSteps();
|
|
59
75
|
}
|
|
60
76
|
resetState() {
|
|
61
|
-
this.
|
|
62
|
-
this.state.pageSteps = {};
|
|
63
|
-
this.state.canRedo = false;
|
|
64
|
-
this.state.canUndo = false;
|
|
65
|
-
this.state.codeBlockState = {};
|
|
66
|
-
this.state.dataSourceState = {};
|
|
77
|
+
this.clearAllSteps();
|
|
67
78
|
}
|
|
68
79
|
/**
|
|
69
|
-
*
|
|
80
|
+
* 为指定历史栈(默认 `page`,也适用于 codeBlock / dataSource / 扩展类型)种入一条「初始基线」记录。
|
|
70
81
|
*
|
|
71
|
-
* 该记录是一条 `opType: 'initial'` 的
|
|
82
|
+
* 该记录是一条 `opType: 'initial'` 的 step,作为对应栈 **index 0 的固定底线**:
|
|
72
83
|
* - 它是一条真实入栈的 step(随栈一起持久化),但被钉为撤销/回滚的下限——cursor 永不低于它,
|
|
73
|
-
* 因此不会被 undo / goto / revert 触达(详见 {@link undo} / {@link
|
|
74
|
-
* - 历史面板把它过滤出分组列表(见 {@link
|
|
84
|
+
* 因此不会被 undo / goto / revert 触达(详见 {@link undo} / {@link undoFloor});
|
|
85
|
+
* - 历史面板把它过滤出分组列表(见 {@link getHistoryGroups}),改由底部「初始」行展示。
|
|
75
86
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
87
|
+
* 仅当目标栈为空时种入(保证 initial 一定位于 index 0);已存在 initial 底线时不重复种入。
|
|
88
|
+
*
|
|
89
|
+
* @param stepType 历史类型
|
|
90
|
+
* @param id 目标栈 id(page 为 pageId,其余类型为对应资源 id)
|
|
91
|
+
* @param options 基线展示信息(名称 / 描述 / 来源)
|
|
78
92
|
*/
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
const existing = this.
|
|
93
|
+
setMarker(stepType, id, options = {}) {
|
|
94
|
+
if (!this.isValidStackId(id)) return null;
|
|
95
|
+
const existing = this.getMarker(stepType, id);
|
|
82
96
|
if (existing) return existing;
|
|
83
|
-
const stack = getOrCreateStack(this.
|
|
97
|
+
const stack = getOrCreateStack(this.getStepBucket(stepType), id);
|
|
84
98
|
if (stack.getLength() > 0) return null;
|
|
85
99
|
const marker = {
|
|
86
100
|
uuid: guid(),
|
|
@@ -88,164 +102,95 @@ var History = class extends BaseService {
|
|
|
88
102
|
diff: [],
|
|
89
103
|
data: {
|
|
90
104
|
name: options.name || "",
|
|
91
|
-
id
|
|
105
|
+
id
|
|
106
|
+
},
|
|
107
|
+
extra: {
|
|
108
|
+
...options.extra || {},
|
|
109
|
+
...stepType === "page" ? {
|
|
110
|
+
selectedBefore: [],
|
|
111
|
+
selectedAfter: [],
|
|
112
|
+
modifiedNodeIds: /* @__PURE__ */ new Map()
|
|
113
|
+
} : {}
|
|
92
114
|
},
|
|
93
|
-
selectedBefore: [],
|
|
94
|
-
selectedAfter: [],
|
|
95
|
-
modifiedNodeIds: /* @__PURE__ */ new Map(),
|
|
96
115
|
historyDescription: options.description || "未修改的初始状态",
|
|
97
116
|
timestamp: Date.now(),
|
|
98
117
|
...options.source ? { source: options.source } : {}
|
|
99
118
|
};
|
|
100
119
|
stack.pushElement(marker);
|
|
101
|
-
|
|
102
|
-
|
|
120
|
+
this.emit("marker-change", {
|
|
121
|
+
id,
|
|
122
|
+
marker,
|
|
123
|
+
stepType
|
|
124
|
+
});
|
|
103
125
|
return marker;
|
|
104
126
|
}
|
|
105
127
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
128
|
+
* 读取指定历史栈的初始基线 step(栈 index 0 且 `opType: 'initial'`);
|
|
129
|
+
* 不存在或 id 缺省时返回 undefined。
|
|
108
130
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const first = this.state.pageSteps[targetPageId]?.getElementList()[0];
|
|
131
|
+
getMarker(stepType, id) {
|
|
132
|
+
if (!this.isValidStackId(id)) return void 0;
|
|
133
|
+
const first = this.state.steps[stepType]?.[id]?.getElementList()[0];
|
|
113
134
|
return first?.opType === "initial" ? first : void 0;
|
|
114
135
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*/
|
|
121
|
-
push(state, pageId) {
|
|
122
|
-
const undoRedo = this.getUndoRedo(pageId);
|
|
123
|
-
if (!undoRedo) return null;
|
|
124
|
-
if (state.uuid === void 0) state.uuid = guid();
|
|
125
|
-
if (state.timestamp === void 0) state.timestamp = Date.now();
|
|
126
|
-
undoRedo.pushElement(state);
|
|
127
|
-
if (pageId === void 0 || `${pageId}` === `${this.state.pageId}`) this.emit("change", state);
|
|
128
|
-
return state;
|
|
129
|
-
}
|
|
130
|
-
/** 读取指定页面(缺省当前活动页)历史栈当前游标所在的 step(cursor - 1);无则返回 null。 */
|
|
131
|
-
getCurrentPageStep(pageId) {
|
|
132
|
-
const targetPageId = pageId ?? this.state.pageId;
|
|
133
|
-
if (!targetPageId) return null;
|
|
134
|
-
return this.state.pageSteps[targetPageId]?.getCurrentElement() ?? null;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* 用 `state` 替换指定页面栈当前游标所在的 step(并丢弃其后的重做尾部),游标不变。
|
|
138
|
-
* 用于「连续 set root 记录合并」等就地替换最新一条的场景;替换成功后按需刷新 / 通知。
|
|
139
|
-
*/
|
|
140
|
-
replaceCurrentPageStep(state, pageId) {
|
|
141
|
-
const undoRedo = this.getUndoRedo(pageId);
|
|
142
|
-
if (!undoRedo) return null;
|
|
143
|
-
if (state.uuid === void 0) state.uuid = guid();
|
|
144
|
-
if (state.timestamp === void 0) state.timestamp = Date.now();
|
|
145
|
-
if (!undoRedo.replaceCurrentElement(state)) return null;
|
|
146
|
-
this.emit("change", state);
|
|
147
|
-
return state;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* 推入一条代码块变更记录(与页面/节点完全无关),按 `codeBlockId` 维度独立一份 UndoRedo 栈。
|
|
151
|
-
*
|
|
152
|
-
* - 新增:oldContent = null,newContent = 新内容
|
|
153
|
-
* - 更新:oldContent / newContent 都为对应内容
|
|
154
|
-
* - 删除:newContent = null,oldContent = 删除前内容
|
|
155
|
-
* - `changeRecords` 来自 form 端,撤销/重做时若有则按 propPath 局部覆盖;缺省才退化为整内容替换。
|
|
156
|
-
* - 不直接驱动 codeBlockService,调用方负责实际写回。
|
|
157
|
-
*/
|
|
158
|
-
pushCodeBlock(codeBlockId, payload) {
|
|
159
|
-
const step = createStackStep(codeBlockId, {
|
|
160
|
-
oldValue: payload.oldContent,
|
|
161
|
-
newValue: payload.newContent,
|
|
162
|
-
changeRecords: payload.changeRecords,
|
|
163
|
-
historyDescription: payload.historyDescription,
|
|
164
|
-
source: payload.source
|
|
165
|
-
});
|
|
166
|
-
if (!step) return null;
|
|
167
|
-
getOrCreateStack(this.state.codeBlockState, codeBlockId).pushElement(step);
|
|
168
|
-
this.emit("code-block-history-change", codeBlockId, step);
|
|
169
|
-
return step;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* 推入一条数据源变更记录(与页面/节点完全无关),按 `dataSourceId` 维度独立一份 UndoRedo 栈。
|
|
173
|
-
* 行为同 pushCodeBlock(新增 oldSchema=null;删除 newSchema=null)。
|
|
174
|
-
*/
|
|
175
|
-
pushDataSource(dataSourceId, payload) {
|
|
176
|
-
const step = createStackStep(dataSourceId, {
|
|
177
|
-
oldValue: payload.oldSchema,
|
|
178
|
-
newValue: payload.newSchema,
|
|
179
|
-
changeRecords: payload.changeRecords,
|
|
180
|
-
historyDescription: payload.historyDescription,
|
|
181
|
-
source: payload.source
|
|
182
|
-
});
|
|
183
|
-
if (!step) return null;
|
|
184
|
-
getOrCreateStack(this.state.dataSourceState, dataSourceId).pushElement(step);
|
|
185
|
-
this.emit("data-source-history-change", dataSourceId, step);
|
|
136
|
+
push(stepType, step, id) {
|
|
137
|
+
if (!this.isValidStackId(id)) return null;
|
|
138
|
+
this.fillStepMeta(step);
|
|
139
|
+
getOrCreateStack(this.getStepBucket(stepType), id).pushElement(step);
|
|
140
|
+
this.emit("change", step, stepType, id);
|
|
186
141
|
return step;
|
|
187
142
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const undoRedo = this.state.
|
|
191
|
-
if (!undoRedo) return null;
|
|
192
|
-
const step = undoRedo.undo();
|
|
193
|
-
if (step) this.emit("code-block-history-change", codeBlockId, step);
|
|
194
|
-
return step;
|
|
195
|
-
}
|
|
196
|
-
/** 重做指定代码块的下一次变更。 */
|
|
197
|
-
redoCodeBlock(codeBlockId) {
|
|
198
|
-
const undoRedo = this.state.codeBlockState[codeBlockId];
|
|
199
|
-
if (!undoRedo) return null;
|
|
200
|
-
const step = undoRedo.redo();
|
|
201
|
-
if (step) this.emit("code-block-history-change", codeBlockId, step);
|
|
202
|
-
return step;
|
|
203
|
-
}
|
|
204
|
-
/** 是否可对指定代码块撤销。 */
|
|
205
|
-
canUndoCodeBlock(codeBlockId) {
|
|
206
|
-
return this.state.codeBlockState[codeBlockId]?.canUndo() ?? false;
|
|
207
|
-
}
|
|
208
|
-
/** 是否可对指定代码块重做。 */
|
|
209
|
-
canRedoCodeBlock(codeBlockId) {
|
|
210
|
-
return this.state.codeBlockState[codeBlockId]?.canRedo() ?? false;
|
|
211
|
-
}
|
|
212
|
-
/** 撤销指定数据源的最近一次变更。 */
|
|
213
|
-
undoDataSource(dataSourceId) {
|
|
214
|
-
const undoRedo = this.state.dataSourceState[dataSourceId];
|
|
143
|
+
undo(stepType, id) {
|
|
144
|
+
if (!this.isValidStackId(id)) return null;
|
|
145
|
+
const undoRedo = this.state.steps[stepType]?.[id];
|
|
215
146
|
if (!undoRedo) return null;
|
|
147
|
+
if (undoRedo.getCursor() <= undoFloor(undoRedo)) return null;
|
|
216
148
|
const step = undoRedo.undo();
|
|
217
|
-
if (step) this.emit("
|
|
149
|
+
if (step) this.emit("change", step, stepType, id);
|
|
218
150
|
return step;
|
|
219
151
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const undoRedo = this.state.
|
|
152
|
+
redo(stepType, id) {
|
|
153
|
+
if (!this.isValidStackId(id)) return null;
|
|
154
|
+
const undoRedo = this.state.steps[stepType]?.[id];
|
|
223
155
|
if (!undoRedo) return null;
|
|
224
156
|
const step = undoRedo.redo();
|
|
225
|
-
if (step) this.emit("
|
|
157
|
+
if (step) this.emit("change", step, stepType, id);
|
|
226
158
|
return step;
|
|
227
159
|
}
|
|
228
|
-
/**
|
|
229
|
-
|
|
230
|
-
|
|
160
|
+
/**
|
|
161
|
+
* 是否可对指定历史栈撤销(cursor 高于 initial 基线底线)。
|
|
162
|
+
* @param stepType 历史类型
|
|
163
|
+
* @param id 目标栈 id;缺省 / 无效时返回 false
|
|
164
|
+
*/
|
|
165
|
+
canUndo(stepType, id) {
|
|
166
|
+
if (!this.isValidStackId(id)) return false;
|
|
167
|
+
const undoRedo = this.state.steps[stepType]?.[id];
|
|
168
|
+
return undoRedo ? undoRedo.getCursor() > undoFloor(undoRedo) : false;
|
|
231
169
|
}
|
|
232
|
-
/**
|
|
233
|
-
|
|
234
|
-
|
|
170
|
+
/**
|
|
171
|
+
* 是否可对指定历史栈重做。
|
|
172
|
+
* @param stepType 历史类型
|
|
173
|
+
* @param id 目标栈 id;缺省 / 无效时返回 false
|
|
174
|
+
*/
|
|
175
|
+
canRedo(stepType, id) {
|
|
176
|
+
if (!this.isValidStackId(id)) return false;
|
|
177
|
+
return this.state.steps[stepType]?.[id]?.canRedo() ?? false;
|
|
235
178
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (!
|
|
239
|
-
|
|
240
|
-
const state = undoRedo.undo();
|
|
241
|
-
this.emit("change", state);
|
|
242
|
-
return state;
|
|
179
|
+
/** 读取指定页面历史栈当前游标所在的 step(cursor - 1);无则返回 null。 */
|
|
180
|
+
getCurrentPageStep(pageId) {
|
|
181
|
+
if (!this.isValidStackId(pageId)) return null;
|
|
182
|
+
return this.state.steps.page[pageId]?.getCurrentElement() ?? null;
|
|
243
183
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
184
|
+
/**
|
|
185
|
+
* 用 `state` 替换指定页面栈当前游标所在的 step(并丢弃其后的重做尾部),游标不变。
|
|
186
|
+
* 用于「连续 set root 记录合并」等就地替换最新一条的场景;替换成功后派发 `change`。
|
|
187
|
+
*/
|
|
188
|
+
replaceCurrentStep(stepType, state, id) {
|
|
189
|
+
if (!this.isValidStackId(id)) return null;
|
|
190
|
+
const undoRedo = getOrCreateStack(this.getStepBucket(stepType), id);
|
|
191
|
+
this.fillStepMeta(state);
|
|
192
|
+
if (!undoRedo.replaceCurrentElement(state)) return null;
|
|
193
|
+
this.emit("change", state, stepType, id);
|
|
249
194
|
return state;
|
|
250
195
|
}
|
|
251
196
|
destroy() {
|
|
@@ -254,84 +199,68 @@ var History = class extends BaseService {
|
|
|
254
199
|
this.removeAllPlugins();
|
|
255
200
|
}
|
|
256
201
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
202
|
+
* 清空历史记录栈。统一入口,所有类型(page / codeBlock / dataSource / 扩展)行为一致:
|
|
203
|
+
* - 传入 `id`:仅清空 `stepType` 下该 id 对应的栈;
|
|
204
|
+
* - 缺省 `id`:清空 `stepType` 下的全部栈。
|
|
205
|
+
*
|
|
206
|
+
* 仅删除撤销/重做记录,不会改动 DSL / 代码块 / 数据源本身。清空时会**保留各栈原有的
|
|
207
|
+
* initial 基线**(文案 / 来源),无基线时清空成空栈。清空后派发 `clear`(签名 `(id, stepType)`)。
|
|
208
|
+
*
|
|
209
|
+
* @param stepType 历史类型
|
|
210
|
+
* @param id 目标栈 id;缺省表示清空该类型下全部栈
|
|
259
211
|
*/
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
212
|
+
clear(stepType, id) {
|
|
213
|
+
const bucket = this.state.steps[stepType];
|
|
214
|
+
if (!bucket) return;
|
|
215
|
+
if (this.isValidStackId(id)) this.clearStack(stepType, id);
|
|
216
|
+
else if (id === void 0) Object.keys(bucket).forEach((stackId) => this.clearStack(stepType, stackId));
|
|
217
|
+
else return;
|
|
218
|
+
this.emit("clear", {
|
|
219
|
+
id,
|
|
220
|
+
stepType
|
|
269
221
|
});
|
|
270
|
-
if (`${targetPageId}` === `${this.state.pageId}`) {
|
|
271
|
-
this.setCanUndoRedo();
|
|
272
|
-
this.emit("clear-page", null);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* 清空数据源历史记录栈:传入 `dataSourceId` 仅清空该数据源,缺省清空全部数据源。
|
|
277
|
-
* 仅删除撤销/重做记录,不会改动数据源本身。
|
|
278
|
-
*/
|
|
279
|
-
clearDataSource(dataSourceId) {
|
|
280
|
-
if (dataSourceId !== void 0) delete this.state.dataSourceState[dataSourceId];
|
|
281
|
-
else this.state.dataSourceState = {};
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* 清空代码块历史记录栈:传入 `codeBlockId` 仅清空该代码块,缺省清空全部代码块。
|
|
285
|
-
* 仅删除撤销/重做记录,不会改动代码块本身。
|
|
286
|
-
*/
|
|
287
|
-
clearCodeBlock(codeBlockId) {
|
|
288
|
-
if (codeBlockId !== void 0) delete this.state.codeBlockState[codeBlockId];
|
|
289
|
-
else this.state.codeBlockState = {};
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* 标记「整份 DSL 已保存」:把页面 / 代码块 / 数据源所有栈当前游标所在的记录都标为 `saved`。
|
|
293
|
-
* 适用于「整体落库」场景;若只保存了其中一类,请改用更细粒度的
|
|
294
|
-
* {@link markPageSaved} / {@link markCodeBlockSaved} / {@link markDataSourceSaved}。
|
|
295
|
-
*/
|
|
296
|
-
markSaved() {
|
|
297
|
-
Object.values(this.state.pageSteps).forEach(markStackSaved);
|
|
298
|
-
Object.values(this.state.codeBlockState).forEach(markStackSaved);
|
|
299
|
-
Object.values(this.state.dataSourceState).forEach(markStackSaved);
|
|
300
|
-
this.emit("mark-saved", { kind: "all" });
|
|
301
222
|
}
|
|
302
223
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
224
|
+
* 标记历史记录为「已保存」(把对应栈当前游标所在的记录标为 `saved`)。统一入口:
|
|
225
|
+
* - 缺省 `id`:标记**全部类型、全部栈**(整份 DSL 落库场景),派发 `mark-saved` 且 `kind: 'all'`;
|
|
226
|
+
* - 传入 `id`:仅标记 `stepType` 下该 id 对应的栈,派发 `mark-saved` 且 `kind` 为 `stepType`。
|
|
227
|
+
*
|
|
228
|
+
* 同一栈内任意时刻最多只有一条记录为 `saved`;从 IndexedDB 恢复时游标会被定位到最近一条已保存记录之后。
|
|
229
|
+
*
|
|
230
|
+
* @param stepType 历史类型
|
|
231
|
+
* @param id 目标栈 id;缺省表示标记全部类型 / 全部栈
|
|
305
232
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
/** 标记指定代码块的历史栈当前记录为已保存,仅影响该代码块自己的栈。 */
|
|
316
|
-
markCodeBlockSaved(codeBlockId) {
|
|
317
|
-
if (!codeBlockId) return;
|
|
318
|
-
markStackSaved(this.state.codeBlockState[codeBlockId]);
|
|
233
|
+
markSaved(stepType, id) {
|
|
234
|
+
if (id === void 0) {
|
|
235
|
+
Object.values(this.state.steps).forEach((bucket) => Object.values(bucket).forEach(markStackSaved));
|
|
236
|
+
this.emit("mark-saved", { kind: "all" });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
if (!this.isValidStackId(id)) return;
|
|
240
|
+
markStackSaved(this.state.steps[stepType]?.[id]);
|
|
319
241
|
this.emit("mark-saved", {
|
|
320
|
-
kind:
|
|
321
|
-
id
|
|
242
|
+
kind: stepType,
|
|
243
|
+
id
|
|
322
244
|
});
|
|
323
245
|
}
|
|
324
|
-
/**
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
246
|
+
/**
|
|
247
|
+
* 派发「页面 / 页面片结构变更」事件(`page-structure-change`)。
|
|
248
|
+
*
|
|
249
|
+
* 常规 `editorService.add` / `remove` 页面节点不会写入 `page` 历史栈(见 editor.add / remove 中
|
|
250
|
+
* 对 isPageOrFragment 的分支),因此不会产生任何 historyService 事件。该方法用于在这些
|
|
251
|
+
* 场景(以及 setRoot 整体替换 DSL 增删页面)下,向外统一通知页面结构的增删变化,供业务方感知。
|
|
252
|
+
*
|
|
253
|
+
* 一次操作涉及多个页面时,调用方应把本次增删的页面**合并为一个 change 一次性传入**,
|
|
254
|
+
* 使一次操作只派发一个事件;`add` / `remove` 分别为本次新增与删除的页面列表(其一可为空数组)。
|
|
255
|
+
*
|
|
256
|
+
* @param change 本次结构变更:{ add: 新增的页面列表, remove: 删除的页面列表 }
|
|
257
|
+
*/
|
|
258
|
+
notifyPageStructureChange(change) {
|
|
259
|
+
if (!change.add.length && !change.remove.length) return;
|
|
260
|
+
this.emit("page-structure-change", change);
|
|
332
261
|
}
|
|
333
262
|
/**
|
|
334
|
-
* 把当前内存中的全部历史栈(页面 / 代码块 /
|
|
263
|
+
* 把当前内存中的全部历史栈(页面 / 代码块 / 数据源 / 扩展类型)序列化后写入本地 IndexedDB。
|
|
335
264
|
*
|
|
336
265
|
* - 每个 UndoRedo 栈连同其游标、容量一并保存,恢复后可继续 undo/redo;
|
|
337
266
|
* - `key` 用于区分不同活动页 / 项目(同一 store 下可保存多份快照),缺省为 `default`;
|
|
@@ -340,12 +269,17 @@ var History = class extends BaseService {
|
|
|
340
269
|
*/
|
|
341
270
|
async saveToIndexedDB(options = {}) {
|
|
342
271
|
const { dbName = DEFAULT_DB_NAME, storeName = DEFAULT_STORE_NAME, key = DEFAULT_KEY, appId } = options;
|
|
272
|
+
const steps = {
|
|
273
|
+
page: {},
|
|
274
|
+
codeBlock: {},
|
|
275
|
+
dataSource: {}
|
|
276
|
+
};
|
|
277
|
+
Object.entries(this.state.steps).forEach(([stepType, bucket]) => {
|
|
278
|
+
steps[stepType] = serializeStacks(bucket);
|
|
279
|
+
});
|
|
343
280
|
const snapshot = {
|
|
344
281
|
version: PERSIST_VERSION,
|
|
345
|
-
|
|
346
|
-
pageSteps: serializeStacks(this.state.pageSteps),
|
|
347
|
-
codeBlockState: serializeStacks(this.state.codeBlockState),
|
|
348
|
-
dataSourceState: serializeStacks(this.state.dataSourceState),
|
|
282
|
+
steps,
|
|
349
283
|
savedAt: Date.now()
|
|
350
284
|
};
|
|
351
285
|
await idbSet(this.resolveDbName(dbName, appId), storeName, key, snapshot);
|
|
@@ -356,7 +290,7 @@ var History = class extends BaseService {
|
|
|
356
290
|
* 从本地 IndexedDB 读取此前保存的历史快照并重建全部撤销/重做栈。
|
|
357
291
|
*
|
|
358
292
|
* - 读取到的每个栈都会经 {@link UndoRedo.fromSerialized} 还原(含游标),随后可直接 undo/redo;
|
|
359
|
-
* -
|
|
293
|
+
* - 会整体覆盖当前内存中的历史状态(活动页由 editorService 维护,不在此恢复);
|
|
360
294
|
* - 找不到对应记录时返回 null,且不改动当前状态;
|
|
361
295
|
* - 不支持 IndexedDB 的环境(如 SSR)会 reject。
|
|
362
296
|
*/
|
|
@@ -365,23 +299,21 @@ var History = class extends BaseService {
|
|
|
365
299
|
const snapshot = await idbGet(this.resolveDbName(dbName, appId), storeName, key);
|
|
366
300
|
if (!snapshot) return null;
|
|
367
301
|
const parseDSL = getEditorConfig("parseDSL");
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
302
|
+
const steps = {
|
|
303
|
+
page: {},
|
|
304
|
+
codeBlock: {},
|
|
305
|
+
dataSource: {}
|
|
306
|
+
};
|
|
307
|
+
Object.entries(snapshot.steps).forEach(([stepType, bucket]) => {
|
|
308
|
+
steps[stepType] = deserializeStacks(bucket, parseDSL);
|
|
309
|
+
});
|
|
310
|
+
this.state.steps = steps;
|
|
373
311
|
this.emit("restore-from-indexed-db", snapshot);
|
|
374
312
|
return snapshot;
|
|
375
313
|
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
* 通常 UI 应使用 `getPageHistoryGroups` 取已合并分组的版本;本方法仅为兼容/调试保留。
|
|
380
|
-
*/
|
|
381
|
-
getPageStepList(pageId) {
|
|
382
|
-
const targetPageId = pageId ?? this.state.pageId;
|
|
383
|
-
if (!targetPageId) return [];
|
|
384
|
-
const undoRedo = this.state.pageSteps[targetPageId];
|
|
314
|
+
getStepList(stepType, id) {
|
|
315
|
+
if (!this.isValidStackId(id)) return [];
|
|
316
|
+
const undoRedo = this.state.steps[stepType]?.[id];
|
|
385
317
|
if (!undoRedo) return [];
|
|
386
318
|
const list = undoRedo.getElementList();
|
|
387
319
|
const cursor = undoRedo.getCursor();
|
|
@@ -391,147 +323,103 @@ var History = class extends BaseService {
|
|
|
391
323
|
applied: index < cursor
|
|
392
324
|
}));
|
|
393
325
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const targetPageId = pageId ?? this.state.pageId;
|
|
402
|
-
if (!targetPageId) return [];
|
|
403
|
-
const undoRedo = this.state.pageSteps[targetPageId];
|
|
404
|
-
if (!undoRedo) return [];
|
|
405
|
-
const list = undoRedo.getElementList();
|
|
406
|
-
if (!list.length) return [];
|
|
407
|
-
return mergePageSteps(targetPageId, list, undoRedo.getCursor()).filter((group) => group.opType !== "initial");
|
|
408
|
-
}
|
|
409
|
-
/**
|
|
410
|
-
* 取出全部代码块的历史栈,按 codeBlockId 分桶展示。
|
|
411
|
-
* 同一栈内每条操作记录独立成组,不做相邻 update 合并。
|
|
412
|
-
*/
|
|
413
|
-
getCodeBlockHistoryGroups() {
|
|
414
|
-
const groups = [];
|
|
415
|
-
Object.entries(this.state.codeBlockState).forEach(([id, undoRedo]) => {
|
|
416
|
-
if (!undoRedo) return;
|
|
326
|
+
getHistoryGroups(stepType, id) {
|
|
327
|
+
const bucket = this.state.steps[stepType];
|
|
328
|
+
if (!bucket) return [];
|
|
329
|
+
const kind = STEP_TYPE_KIND[stepType] ?? stepType;
|
|
330
|
+
const collect = (stackId) => {
|
|
331
|
+
const undoRedo = bucket[stackId];
|
|
332
|
+
if (!undoRedo) return [];
|
|
417
333
|
const list = undoRedo.getElementList();
|
|
418
|
-
if (!list.length) return;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* 读取指定页面历史栈的当前游标(已应用步骤数量)。不传则取当前活动页。
|
|
426
|
-
* 没有对应栈时返回 0。
|
|
427
|
-
*/
|
|
428
|
-
getPageCursor(pageId) {
|
|
429
|
-
const targetPageId = pageId ?? this.state.pageId;
|
|
430
|
-
if (!targetPageId) return 0;
|
|
431
|
-
return this.state.pageSteps[targetPageId]?.getCursor() ?? 0;
|
|
432
|
-
}
|
|
433
|
-
/** 读取指定代码块历史栈的当前游标。 */
|
|
434
|
-
getCodeBlockCursor(codeBlockId) {
|
|
435
|
-
return this.state.codeBlockState[codeBlockId]?.getCursor() ?? 0;
|
|
436
|
-
}
|
|
437
|
-
/** 读取指定数据源历史栈的当前游标。 */
|
|
438
|
-
getDataSourceCursor(dataSourceId) {
|
|
439
|
-
return this.state.dataSourceState[dataSourceId]?.getCursor() ?? 0;
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* 取出指定代码块历史栈的平铺步骤列表(含 applied 标记)。供 revert 等按 index 索引步骤使用。
|
|
443
|
-
*/
|
|
444
|
-
getCodeBlockStepList(codeBlockId) {
|
|
445
|
-
const undoRedo = this.state.codeBlockState[codeBlockId];
|
|
446
|
-
if (!undoRedo) return [];
|
|
447
|
-
const list = undoRedo.getElementList();
|
|
448
|
-
const cursor = undoRedo.getCursor();
|
|
449
|
-
return list.map((step, index) => ({
|
|
450
|
-
step,
|
|
451
|
-
index,
|
|
452
|
-
applied: index < cursor
|
|
453
|
-
}));
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* 取出指定数据源历史栈的平铺步骤列表(含 applied 标记)。供 revert 等按 index 索引步骤使用。
|
|
457
|
-
*/
|
|
458
|
-
getDataSourceStepList(dataSourceId) {
|
|
459
|
-
const undoRedo = this.state.dataSourceState[dataSourceId];
|
|
460
|
-
if (!undoRedo) return [];
|
|
461
|
-
const list = undoRedo.getElementList();
|
|
462
|
-
const cursor = undoRedo.getCursor();
|
|
463
|
-
return list.map((step, index) => ({
|
|
464
|
-
step,
|
|
465
|
-
index,
|
|
466
|
-
applied: index < cursor
|
|
467
|
-
}));
|
|
334
|
+
if (!list.length) return [];
|
|
335
|
+
return mergeSteps(kind, stackId, list, undoRedo.getCursor()).filter((group) => group.opType !== "initial");
|
|
336
|
+
};
|
|
337
|
+
if (this.isValidStackId(id)) return collect(id);
|
|
338
|
+
return Object.keys(bucket).flatMap((stackId) => collect(stackId));
|
|
468
339
|
}
|
|
469
340
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
341
|
+
* 读取指定历史栈的当前游标(已应用步骤数量)。统一入口,替代旧的
|
|
342
|
+
* `getPageCursor` / `getCodeBlockCursor` / `getDataSourceCursor`。
|
|
343
|
+
* - `id` 缺省或非法、或对应栈不存在时返回 0;
|
|
344
|
+
* - `stepType` 支持 `page` / `codeBlock` / `dataSource` / 扩展类型。
|
|
472
345
|
*/
|
|
473
|
-
|
|
474
|
-
if (!
|
|
475
|
-
return this.
|
|
346
|
+
getCursor(stepType, id) {
|
|
347
|
+
if (!this.isValidStackId(id)) return 0;
|
|
348
|
+
return this.state.steps[stepType]?.[id]?.getCursor() ?? 0;
|
|
476
349
|
}
|
|
477
350
|
/**
|
|
478
|
-
* 按历史记录 uuid
|
|
479
|
-
*
|
|
351
|
+
* 按历史记录 uuid 在指定历史类型的栈中查找其所属 id 与索引,统一入口,替代旧的
|
|
352
|
+
* `getPageStepIndexByUuid` / `findCodeBlockStepLocationByUuid` / `findDataSourceStepLocationByUuid`。
|
|
353
|
+
*
|
|
354
|
+
* - 传入 `id`:仅在该 id 对应的单个栈中查找(如页面历史按活动页查看,传入 pageId);
|
|
355
|
+
* - 缺省 `id`:遍历该类型下全部栈查找(代码块 / 数据源等按全部资源分桶的场景)。
|
|
356
|
+
*
|
|
357
|
+
* 找不到时返回 null。供「按 uuid 回滚」等需要把 uuid 映射回 (id, index) 的场景使用。
|
|
358
|
+
*
|
|
359
|
+
* @param stepType 历史类型
|
|
360
|
+
* @param uuid 目标历史记录的 uuid
|
|
361
|
+
* @param id 目标栈 id;缺省表示遍历该类型下全部栈
|
|
480
362
|
*/
|
|
481
|
-
|
|
363
|
+
findStepLocationByUuid(stepType, uuid, id) {
|
|
482
364
|
if (!uuid) return null;
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
365
|
+
const bucket = this.state.steps[stepType];
|
|
366
|
+
if (!bucket) return null;
|
|
367
|
+
if (this.isValidStackId(id)) {
|
|
368
|
+
const index = this.getStepList(stepType, id).findIndex((entry) => entry.step.uuid === uuid);
|
|
369
|
+
return index >= 0 ? {
|
|
486
370
|
id,
|
|
487
371
|
index
|
|
488
|
-
};
|
|
372
|
+
} : null;
|
|
489
373
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* 按历史记录 uuid 在全部数据源栈中查找其所属 dataSourceId 与索引。
|
|
494
|
-
* 找不到时返回 null。
|
|
495
|
-
*/
|
|
496
|
-
findDataSourceStepLocationByUuid(uuid) {
|
|
497
|
-
if (!uuid) return null;
|
|
498
|
-
for (const id of Object.keys(this.state.dataSourceState)) {
|
|
499
|
-
const index = this.getDataSourceStepList(id).findIndex((entry) => entry.step.uuid === uuid);
|
|
374
|
+
for (const stackId of Object.keys(bucket)) {
|
|
375
|
+
const index = this.getStepList(stepType, stackId).findIndex((entry) => entry.step.uuid === uuid);
|
|
500
376
|
if (index >= 0) return {
|
|
501
|
-
id,
|
|
377
|
+
id: stackId,
|
|
502
378
|
index
|
|
503
379
|
};
|
|
504
380
|
}
|
|
505
381
|
return null;
|
|
506
382
|
}
|
|
507
|
-
/**
|
|
508
|
-
* 取出全部数据源的历史栈,按 dataSourceId 分桶展示。同上,每条操作独立成组。
|
|
509
|
-
*/
|
|
510
|
-
getDataSourceHistoryGroups() {
|
|
511
|
-
const groups = [];
|
|
512
|
-
Object.entries(this.state.dataSourceState).forEach(([id, undoRedo]) => {
|
|
513
|
-
if (!undoRedo) return;
|
|
514
|
-
const list = undoRedo.getElementList();
|
|
515
|
-
if (!list.length) return;
|
|
516
|
-
const cursor = undoRedo.getCursor();
|
|
517
|
-
groups.push(...mergeStackSteps("data-source", id, list, cursor));
|
|
518
|
-
});
|
|
519
|
-
return groups;
|
|
520
|
-
}
|
|
521
383
|
usePlugin(options) {
|
|
522
384
|
super.usePlugin(options);
|
|
523
385
|
}
|
|
386
|
+
emit(eventName, ...args) {
|
|
387
|
+
return super.emit(eventName, ...args);
|
|
388
|
+
}
|
|
524
389
|
/**
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
|
|
528
|
-
|
|
390
|
+
* 取出指定历史类型的栈桶(`Record<id, UndoRedo>`);不存在时按需创建空桶,
|
|
391
|
+
* 从而支持通过 {@link registerStepType} 或首次 push 动态扩展历史类型。
|
|
392
|
+
*/
|
|
393
|
+
getStepBucket(stepType) {
|
|
394
|
+
if (!this.state.steps[stepType]) this.state.steps[stepType] = {};
|
|
395
|
+
return this.state.steps[stepType];
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 清空单个历史栈并按需重建其 initial 基线(保留原基线的文案 / 来源)。
|
|
529
399
|
*/
|
|
530
|
-
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
|
|
400
|
+
clearStack(stepType, id) {
|
|
401
|
+
const marker = this.getMarker(stepType, id);
|
|
402
|
+
this.getStepBucket(stepType)[id] = new UndoRedo();
|
|
403
|
+
if (marker) this.setMarker(stepType, id, {
|
|
404
|
+
name: marker.data?.name,
|
|
405
|
+
description: marker.historyDescription,
|
|
406
|
+
source: marker.source
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
/** 入栈前补全 step 的 uuid / timestamp(调用方未指定时)。 */
|
|
410
|
+
fillStepMeta(step) {
|
|
411
|
+
if (step.uuid === void 0) step.uuid = guid();
|
|
412
|
+
if (step.timestamp === void 0) step.timestamp = Date.now();
|
|
413
|
+
}
|
|
414
|
+
/** 校验「按 id 分栈」类型(codeBlock / dataSource / 扩展)的 id 是否有效。 */
|
|
415
|
+
isValidStackId(id) {
|
|
416
|
+
return id !== void 0 && id !== null && `${id}` !== "";
|
|
417
|
+
}
|
|
418
|
+
/** 清空全部历史栈内容(保留已注册的类型键,使扩展类型在 reset 后仍可用)。 */
|
|
419
|
+
clearAllSteps() {
|
|
420
|
+
Object.keys(this.state.steps).forEach((stepType) => {
|
|
421
|
+
this.state.steps[stepType] = {};
|
|
422
|
+
});
|
|
535
423
|
}
|
|
536
424
|
/**
|
|
537
425
|
* 把基础 dbName 与当前 DSL(root app)的 id 拼成最终库名,实现不同应用历史隔离。
|
|
@@ -541,11 +429,6 @@ var History = class extends BaseService {
|
|
|
541
429
|
const resolvedAppId = appId ?? editor_default.get("root")?.id;
|
|
542
430
|
return resolvedAppId ? `${dbName}-${resolvedAppId}` : dbName;
|
|
543
431
|
}
|
|
544
|
-
setCanUndoRedo() {
|
|
545
|
-
const undoRedo = this.getUndoRedo();
|
|
546
|
-
this.state.canRedo = undoRedo?.canRedo() || false;
|
|
547
|
-
this.state.canUndo = undoRedo ? undoRedo.getCursor() > undoFloor(undoRedo) : false;
|
|
548
|
-
}
|
|
549
432
|
};
|
|
550
433
|
var history_default = new History();
|
|
551
434
|
//#endregion
|