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