@tmagic/editor 1.8.0-manmanyu.8 → 1.8.0-manmanyu.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/components/CompareForm.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/index.js +2 -2
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +28 -18
- package/dist/es/layouts/history-list/useHistoryList.js +4 -4
- package/dist/es/layouts/history-list/useHistoryRevert.js +6 -6
- 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 +259 -392
- package/dist/es/utils/history.js +35 -47
- package/dist/tmagic-editor.umd.cjs +443 -558
- package/package.json +7 -7
- package/types/index.d.ts +314 -273
|
@@ -103,7 +103,10 @@ var CompareForm_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ de
|
|
|
103
103
|
case "node":
|
|
104
104
|
if (!props.type) return [];
|
|
105
105
|
return removeStyleDisplayConfig(await propsService.getPropsConfig(props.type, { node: props.value }));
|
|
106
|
-
case "data-source": return dataSourceService.getFormConfig(props.type || "base")
|
|
106
|
+
case "data-source": return dataSourceService.getFormConfig(props.type || "base").map((item) => "type" in item && item.type === "tab" ? {
|
|
107
|
+
...item,
|
|
108
|
+
active: "fields"
|
|
109
|
+
} : item);
|
|
107
110
|
case "code-block": return getCodeBlockFormConfig({
|
|
108
111
|
paramColConfig: codeBlockService.getParamsColConfig(),
|
|
109
112
|
isDataSource: () => Boolean(props.dataSourceType),
|
package/dist/es/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { advancedTabConfig, arrayOptions, displayTabConfig, eqOptions, eventTabC
|
|
|
4
4
|
import props_default from "./services/props.js";
|
|
5
5
|
import { getEditorConfig, setEditorConfig } from "./utils/config.js";
|
|
6
6
|
import { UndoRedo } from "./utils/undo-redo.js";
|
|
7
|
-
import { createStackStep, describeRevertStep, deserializeStacks,
|
|
7
|
+
import { createStackStep, describeRevertStep, deserializeStacks, detectStackOpType, detectTargetId, detectTargetName, getLastPushedHistoryIds, getOrCreateStack, markStackSaved, mergeSteps, serializeStacks, undoFloor } from "./utils/history.js";
|
|
8
8
|
import { idbDelete, idbGet, idbSet, isIndexedDBSupported, openIndexedDB } from "./utils/indexed-db.js";
|
|
9
9
|
import history_default from "./services/history.js";
|
|
10
10
|
import storage_default from "./services/storage.js";
|
|
@@ -85,4 +85,4 @@ export * from "@tmagic/table";
|
|
|
85
85
|
export * from "@tmagic/stage";
|
|
86
86
|
export * from "@tmagic/design";
|
|
87
87
|
export * from "@tmagic/utils";
|
|
88
|
-
export { CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CodeBlockEditor_default as CodeBlockEditor, CodeBlockList_default as CodeBlockList, CodeBlockListPanel_default as CodeBlockListPanel, CodeDeleteErrorType, CodeSelect_default as CodeSelect, CodeSelectCol_default as CodeSelectCol, ColumnLayout, CompareForm_default as CompareForm, ComponentListPanel_default as ComponentListPanel, CondOpSelect_default as CondOpSelect, ContentMenu_default as ContentMenu, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, DataSourceAddButton_default as DataSourceAddButton, DataSourceConfigPanel_default as DataSourceConfigPanel, Index_default as DataSourceFieldSelect, DataSourceFields_default as DataSourceFields, DataSourceInput_default as DataSourceInput, DataSourceMethodSelect_default as DataSourceMethodSelect, DataSourceMethods_default as DataSourceMethods, DataSourceMocks_default as DataSourceMocks, DataSourceSelect_default as DataSourceSelect, DepTargetType, DisplayConds_default as DisplayConds, DragType, EventSelect_default as EventSelect, Fixed2Other, FloatingBox_default as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, HistoryDiffDialog_default as HistoryDiffDialog, Bucket_default as HistoryListBucket, BucketTab_default as HistoryListBucketTab, Icon_default as Icon, IdleTask, KeyBindingCommand, KeyValue_default as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, LayerOffset, LayerPanel_default as LayerPanel, Layout, SplitView_default as LayoutContainer, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, PROPS_PANEL_WIDTH_STORAGE_KEY, PageFragmentSelect_default as PageFragmentSelect, FormPanel_default as PropsFormPanel, PropsPanel_default as PropsPanel, RIGHT_COLUMN_WIDTH_STORAGE_KEY, Resizer_default as Resizer, ScrollViewer, SideItemKey, SplitView_default as SplitView, StageCore, Index_default$1 as StyleSetter, CodeEditor_default as TMagicCodeEditor, Editor_default as TMagicEditor, ToolButton_default as ToolButton, Tree_default as Tree, TreeNode_default as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, arrayOptions, beforePaste, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, codeBlock_default as codeBlockService, collectRelatedNodes, confirmHistoryAction, createStackStep, dataSource_default as dataSourceService, debug, plugin_default as default, defaultIsExpandable, dep_default as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin,
|
|
88
|
+
export { CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, CodeBlockEditor_default as CodeBlockEditor, CodeBlockList_default as CodeBlockList, CodeBlockListPanel_default as CodeBlockListPanel, CodeDeleteErrorType, CodeSelect_default as CodeSelect, CodeSelectCol_default as CodeSelectCol, ColumnLayout, CompareForm_default as CompareForm, ComponentListPanel_default as ComponentListPanel, CondOpSelect_default as CondOpSelect, ContentMenu_default as ContentMenu, DEFAULT_LEFT_COLUMN_WIDTH, DEFAULT_RIGHT_COLUMN_WIDTH, DataSourceAddButton_default as DataSourceAddButton, DataSourceConfigPanel_default as DataSourceConfigPanel, Index_default as DataSourceFieldSelect, DataSourceFields_default as DataSourceFields, DataSourceInput_default as DataSourceInput, DataSourceMethodSelect_default as DataSourceMethodSelect, DataSourceMethods_default as DataSourceMethods, DataSourceMocks_default as DataSourceMocks, DataSourceSelect_default as DataSourceSelect, DepTargetType, DisplayConds_default as DisplayConds, DragType, EventSelect_default as EventSelect, Fixed2Other, FloatingBox_default as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, HistoryDiffDialog_default as HistoryDiffDialog, Bucket_default as HistoryListBucket, BucketTab_default as HistoryListBucketTab, Icon_default as Icon, IdleTask, KeyBindingCommand, KeyValue_default as KeyValue, Keys, LEFT_COLUMN_WIDTH_STORAGE_KEY, LayerOffset, LayerPanel_default as LayerPanel, Layout, SplitView_default as LayoutContainer, MIN_CENTER_COLUMN_WIDTH, MIN_LEFT_COLUMN_WIDTH, MIN_RIGHT_COLUMN_WIDTH, PROPS_PANEL_WIDTH_STORAGE_KEY, PageFragmentSelect_default as PageFragmentSelect, FormPanel_default as PropsFormPanel, PropsPanel_default as PropsPanel, RIGHT_COLUMN_WIDTH_STORAGE_KEY, Resizer_default as Resizer, ScrollViewer, SideItemKey, SplitView_default as SplitView, StageCore, Index_default$1 as StyleSetter, CodeEditor_default as TMagicCodeEditor, Editor_default as TMagicEditor, ToolButton_default as ToolButton, Tree_default as Tree, TreeNode_default as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, arrayOptions, beforePaste, buildChangeRecords, calcAlignCenterStyle, calcLayerTargetIndex, calcMoveStyle, canUsePluginMethods, change2Fixed, classifyDragSources, codeBlock_default as codeBlockService, collectRelatedNodes, confirmHistoryAction, createStackStep, dataSource_default as dataSourceService, debug, plugin_default as default, defaultIsExpandable, dep_default as depService, describeRevertStep, describeStepForRevert, deserializeStacks, designPlugin, detectStackOpType, detectTargetId, detectTargetName, displayTabConfig, editorNodeMergeCustomizer, editor_default as editorService, eqOptions, error, eventTabConfig, events_default as eventsService, fillConfig, fixNodeLeft, fixNodePosition, formPlugin, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getCodeBlockFormConfig, getDefaultConfig, getDisplayField, getEditorConfig, getFieldType, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getLastPushedHistoryIds, getNodeIndex, getOrCreateStack, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, history_default as historyService, idbDelete, idbGet, idbSet, info, isIncludeDataSource, isIndexedDBSupported, monaco_editor_default as loadMonaco, log, markStackSaved, mergeSteps, moveItemsInContainer, numberOptions, openIndexedDB, props_default as propsService, resolveSelectedNode, serializeConfig, serializeStacks, setChildrenLayout, setEditorConfig, setLayout, stageOverlay_default as stageOverlayService, storage_default as storageService, styleTabConfig, tablePlugin, toggleFixedPosition, ui_default as uiService, undoFloor, updateStatus, useCodeBlockEdit, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useHistoryRevert, useNextFloatBoxPosition, useNodeStatus, useServices, useStage, useWindowRect, warn };
|
|
@@ -55,7 +55,7 @@ var NavMenu_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
55
55
|
className: "undo",
|
|
56
56
|
icon: markRaw(Back),
|
|
57
57
|
tooltip: `后退(${ctrl}+z)`,
|
|
58
|
-
disabled: () => !historyService.
|
|
58
|
+
disabled: () => !historyService.canUndo("page", editorService.get("page")?.id),
|
|
59
59
|
handler: () => editorService.undo()
|
|
60
60
|
});
|
|
61
61
|
break;
|
|
@@ -65,7 +65,7 @@ var NavMenu_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
65
65
|
className: "redo",
|
|
66
66
|
icon: markRaw(Right),
|
|
67
67
|
tooltip: `前进(${ctrl}+Shift+z)`,
|
|
68
|
-
disabled: () => !historyService.
|
|
68
|
+
disabled: () => !historyService.canRedo("page", editorService.get("page")?.id),
|
|
69
69
|
handler: () => editorService.redo()
|
|
70
70
|
});
|
|
71
71
|
break;
|
package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -73,27 +73,35 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
73
73
|
* 当前活动页的「加载/初始」标记记录(设置 root 时生成),透传给 PageTab 的底部初始行展示。
|
|
74
74
|
* 基于 historyService 的 reactive state 派生,活动页切换或标记写入后自动刷新。
|
|
75
75
|
*/
|
|
76
|
-
const pageMarker = computed(() => historyService.
|
|
76
|
+
const pageMarker = computed(() => historyService.getMarker("page", editorService.get("page")?.id));
|
|
77
|
+
/**
|
|
78
|
+
* 各历史类型的展示名称(页面 / 数据源 / 代码块),由 historyService.state.stepNames 配置,
|
|
79
|
+
* 业务方可通过 historyService.setStepName / registerStepType 覆盖。基于 reactive state 派生,配置变更后自动刷新。
|
|
80
|
+
*/
|
|
81
|
+
const pageName = computed(() => historyService.getStepName("page"));
|
|
82
|
+
const dataSourceName = computed(() => historyService.getStepName("dataSource"));
|
|
83
|
+
const codeBlockName = computed(() => historyService.getStepName("codeBlock"));
|
|
77
84
|
/** 代码块 step 仅 update(前后 content 都存在)时可查看差异。 */
|
|
78
85
|
const isStepDiffable = (step) => Boolean(step.diff?.[0]?.oldSchema && step.diff?.[0]?.newSchema);
|
|
79
86
|
/**
|
|
80
87
|
* 数据源 / 代码块两类 bucket 历史的整体渲染配置:把 title / prefix 与各自的描述、
|
|
81
88
|
* 可差异、可回滚判定收敛为单一对象整体注入 BucketTab,组件内部按需读取。
|
|
89
|
+
* title / 描述回退名取自可配置的展示名称,故用 computed 使其随 stepNames 变更刷新。
|
|
82
90
|
*/
|
|
83
|
-
const dataSourceConfig = {
|
|
84
|
-
title:
|
|
91
|
+
const dataSourceConfig = computed(() => ({
|
|
92
|
+
title: dataSourceName.value,
|
|
85
93
|
prefix: "ds",
|
|
86
|
-
describeStep: (step) => describeStep(step, (schema) => schema?.title,
|
|
94
|
+
describeStep: (step) => describeStep(step, (schema) => schema?.title, dataSourceName.value),
|
|
87
95
|
isStepDiffable,
|
|
88
96
|
isStepRevertable: isSingleDiffStepRevertable
|
|
89
|
-
};
|
|
90
|
-
const codeBlockConfig = {
|
|
91
|
-
title:
|
|
97
|
+
}));
|
|
98
|
+
const codeBlockConfig = computed(() => ({
|
|
99
|
+
title: codeBlockName.value,
|
|
92
100
|
prefix: "cb",
|
|
93
|
-
describeStep: (step) => describeStep(step, (content) => content?.name,
|
|
101
|
+
describeStep: (step) => describeStep(step, (content) => content?.name, codeBlockName.value),
|
|
94
102
|
isStepDiffable,
|
|
95
103
|
isStepRevertable: isSingleDiffStepRevertable
|
|
96
|
-
};
|
|
104
|
+
}));
|
|
97
105
|
/** 把"目标 step 索引"翻译成"目标 cursor"(已应用步骤数量)。 */
|
|
98
106
|
const indexToCursor = (index) => index + 1;
|
|
99
107
|
const onPageGoto = (index) => {
|
|
@@ -106,7 +114,7 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
106
114
|
* - 该 step 涉及的节点都已不存在(如删除记录、被撤销的新增)时给出提示,不做选中。
|
|
107
115
|
*/
|
|
108
116
|
const onPageSelect = async (index) => {
|
|
109
|
-
const step = historyService.
|
|
117
|
+
const step = historyService.getStepList("page", editorService.get("page")?.id)[index]?.step;
|
|
110
118
|
if (!step) return;
|
|
111
119
|
const targetId = (step.diff ?? []).map((item) => item.newSchema?.id ?? item.oldSchema?.id).find((id) => id !== void 0 && id !== null && editorService.getNodeById(id, false));
|
|
112
120
|
if (targetId === void 0 || targetId === null) {
|
|
@@ -156,19 +164,19 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
156
164
|
};
|
|
157
165
|
const onPageClear = async () => {
|
|
158
166
|
if (await confirmHistoryAction("确定清空当前页面的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
159
|
-
historyService.
|
|
167
|
+
historyService.clear("page", editorService.get("page")?.id);
|
|
160
168
|
await syncIndexedDB();
|
|
161
169
|
}
|
|
162
170
|
};
|
|
163
171
|
const onDataSourceClear = async () => {
|
|
164
172
|
if (await confirmHistoryAction("确定清空数据源的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
165
|
-
historyService.
|
|
173
|
+
historyService.clear("dataSource");
|
|
166
174
|
await syncIndexedDB();
|
|
167
175
|
}
|
|
168
176
|
};
|
|
169
177
|
const onCodeBlockClear = async () => {
|
|
170
178
|
if (await confirmHistoryAction("确定清空代码块的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
171
|
-
historyService.
|
|
179
|
+
historyService.clear("codeBlock");
|
|
172
180
|
await syncIndexedDB();
|
|
173
181
|
}
|
|
174
182
|
};
|
|
@@ -219,7 +227,7 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
219
227
|
default: withCtx(() => [
|
|
220
228
|
(openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(guardReactiveProps(unref(tabPaneComponent)?.props({
|
|
221
229
|
name: "page",
|
|
222
|
-
label:
|
|
230
|
+
label: `${pageName.value} (${unref(pageGroups).length})`
|
|
223
231
|
}) || {})), {
|
|
224
232
|
default: withCtx(() => [createVNode(PageTab_default, {
|
|
225
233
|
list: unref(pageGroupsDisplay),
|
|
@@ -244,10 +252,10 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
244
252
|
}, 16)),
|
|
245
253
|
!disabledDataSource.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 0 }, unref(tabPaneComponent)?.props({
|
|
246
254
|
name: "data-source",
|
|
247
|
-
label:
|
|
255
|
+
label: `${dataSourceName.value} (${unref(dataSourceGroups).length})`
|
|
248
256
|
}) || {})), {
|
|
249
257
|
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
250
|
-
config: dataSourceConfig,
|
|
258
|
+
config: dataSourceConfig.value,
|
|
251
259
|
buckets: unref(dataSourceGroupsByTarget),
|
|
252
260
|
expanded: unref(expanded),
|
|
253
261
|
onToggle: unref(toggleGroup),
|
|
@@ -257,6 +265,7 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
257
265
|
onRevertStep: unref(onDataSourceRevert),
|
|
258
266
|
onClear: onDataSourceClear
|
|
259
267
|
}, null, 8, [
|
|
268
|
+
"config",
|
|
260
269
|
"buckets",
|
|
261
270
|
"expanded",
|
|
262
271
|
"onToggle",
|
|
@@ -267,10 +276,10 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
267
276
|
}, 16)) : createCommentVNode("v-if", true),
|
|
268
277
|
!disabledCodeBlock.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 1 }, unref(tabPaneComponent)?.props({
|
|
269
278
|
name: "code-block",
|
|
270
|
-
label:
|
|
279
|
+
label: `${codeBlockName.value} (${unref(codeBlockGroups).length})`
|
|
271
280
|
}) || {})), {
|
|
272
281
|
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
273
|
-
config: codeBlockConfig,
|
|
282
|
+
config: codeBlockConfig.value,
|
|
274
283
|
buckets: unref(codeBlockGroupsByTarget),
|
|
275
284
|
expanded: unref(expanded),
|
|
276
285
|
onToggle: unref(toggleGroup),
|
|
@@ -280,6 +289,7 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
280
289
|
onRevertStep: unref(onCodeBlockRevert),
|
|
281
290
|
onClear: onCodeBlockClear
|
|
282
291
|
}, null, 8, [
|
|
292
|
+
"config",
|
|
283
293
|
"buckets",
|
|
284
294
|
"expanded",
|
|
285
295
|
"onToggle",
|
|
@@ -10,7 +10,7 @@ import { computed, reactive } from "vue";
|
|
|
10
10
|
* 所有数据基于 historyService 的 reactive state 派生,自动跟随历史变化刷新。
|
|
11
11
|
*/
|
|
12
12
|
var useHistoryList = () => {
|
|
13
|
-
const { historyService } = useServices();
|
|
13
|
+
const { editorService, historyService } = useServices();
|
|
14
14
|
/**
|
|
15
15
|
* 折叠状态:key 形如 `pg-${组内首步 index}` / `ds-${id}-${组内首步 index}` / `cb-${id}-${组内首步 index}`。
|
|
16
16
|
* 用组内首步的稳定 index(而非展示位置)作为 key,确保历史数据更新后已展开的分组状态保持不变。
|
|
@@ -20,9 +20,9 @@ var useHistoryList = () => {
|
|
|
20
20
|
const toggleGroup = (key) => {
|
|
21
21
|
expanded[key] = expanded[key] === false;
|
|
22
22
|
};
|
|
23
|
-
const pageGroups = computed(() => historyService.
|
|
24
|
-
const dataSourceGroups = computed(() => historyService.
|
|
25
|
-
const codeBlockGroups = computed(() => historyService.
|
|
23
|
+
const pageGroups = computed(() => historyService.getHistoryGroups("page", editorService.get("page")?.id));
|
|
24
|
+
const dataSourceGroups = computed(() => historyService.getHistoryGroups("dataSource"));
|
|
25
|
+
const codeBlockGroups = computed(() => historyService.getHistoryGroups("codeBlock"));
|
|
26
26
|
/** 页面 tab 倒序展示(最新一组在最上面)。 */
|
|
27
27
|
const pageGroupsDisplay = computed(() => pageGroups.value.slice().reverse());
|
|
28
28
|
/**
|
|
@@ -151,21 +151,21 @@ var useHistoryRevert = (services, options = {}) => {
|
|
|
151
151
|
};
|
|
152
152
|
const buildPageDiffPayload = (index) => buildDiffPayload({
|
|
153
153
|
category: "node",
|
|
154
|
-
groups: () => historyService.
|
|
154
|
+
groups: () => historyService.getHistoryGroups("page", editorService.get("page")?.id),
|
|
155
155
|
getCurrent: (id) => editorService.getNodeById(id),
|
|
156
156
|
resolveType: (n, o) => n.type || o.type || "",
|
|
157
157
|
resolveLabel: (n, o) => n.name || o.name || n.type || o.type || ""
|
|
158
158
|
}, index);
|
|
159
159
|
const buildDataSourceDiffPayload = (id, index) => buildDiffPayload({
|
|
160
160
|
category: "data-source",
|
|
161
|
-
groups: () => historyService.
|
|
161
|
+
groups: () => historyService.getHistoryGroups("dataSource"),
|
|
162
162
|
getCurrent: (id) => dataSourceService.getDataSourceById(`${id}`),
|
|
163
163
|
resolveType: (n, o) => n.type || o.type || "base",
|
|
164
164
|
resolveLabel: (n, o, id) => n.title || o.title || `${id}`
|
|
165
165
|
}, index, id);
|
|
166
166
|
const buildCodeBlockDiffPayload = (id, index) => buildDiffPayload({
|
|
167
167
|
category: "code-block",
|
|
168
|
-
groups: () => historyService.
|
|
168
|
+
groups: () => historyService.getHistoryGroups("codeBlock"),
|
|
169
169
|
getCurrent: (id) => codeBlockService.getCodeContentById(id),
|
|
170
170
|
resolveLabel: (n, o, id) => n.name || o.name || `${id}`
|
|
171
171
|
}, index, id);
|
|
@@ -176,7 +176,7 @@ var useHistoryRevert = (services, options = {}) => {
|
|
|
176
176
|
* add(回滚即删除)即使目标已不在,也已达成「删除」目的,不视为失败。
|
|
177
177
|
*/
|
|
178
178
|
const isPageRevertTargetMissing = (index) => {
|
|
179
|
-
const step = historyService.
|
|
179
|
+
const step = historyService.getStepList("page", editorService.get("page")?.id)[index]?.step;
|
|
180
180
|
if (!step) return false;
|
|
181
181
|
if (step.opType === "update") return (step.diff ?? []).some((item) => {
|
|
182
182
|
const id = item.newSchema?.id ?? item.oldSchema?.id;
|
|
@@ -187,12 +187,12 @@ var useHistoryRevert = (services, options = {}) => {
|
|
|
187
187
|
};
|
|
188
188
|
/** 数据源 update 步骤回滚时,对应数据源必须仍存在(已删除则无处写回旧值)。 */
|
|
189
189
|
const isDataSourceRevertTargetMissing = (id, index) => {
|
|
190
|
-
const step = historyService.
|
|
190
|
+
const step = historyService.getStepList("dataSource", id)[index]?.step;
|
|
191
191
|
return Boolean(step?.opType === "update" && !dataSourceService.getDataSourceById(`${id}`));
|
|
192
192
|
};
|
|
193
193
|
/** 代码块 update 步骤回滚时,对应代码块必须仍存在(已删除则无处写回旧值)。 */
|
|
194
194
|
const isCodeBlockRevertTargetMissing = (id, index) => {
|
|
195
|
-
const step = historyService.
|
|
195
|
+
const step = historyService.getStepList("codeBlock", id)[index]?.step;
|
|
196
196
|
return Boolean(step?.opType === "update" && !codeBlockService.getCodeContentById(id));
|
|
197
197
|
};
|
|
198
198
|
const onPageRevert = (index) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CODE_DRAFT_STORAGE_KEY } from "../type.js";
|
|
2
2
|
import BaseService from "./BaseService.js";
|
|
3
3
|
import { getEditorConfig } from "../utils/config.js";
|
|
4
|
-
import { describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
4
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
5
5
|
import history_default from "./history.js";
|
|
6
6
|
import storage_default, { Protocol } from "./storage.js";
|
|
7
7
|
import { COPY_CODE_STORAGE_KEY } from "../utils/editor.js";
|
|
@@ -121,13 +121,16 @@ var CodeBlock = class extends BaseService {
|
|
|
121
121
|
...codeConfigProcessed
|
|
122
122
|
};
|
|
123
123
|
const newContent = cloneDeep$1(codeDsl[id]);
|
|
124
|
-
if (!doNotPushHistory)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
if (!doNotPushHistory) {
|
|
125
|
+
const step = createStackStep(id, {
|
|
126
|
+
oldValue: oldContent,
|
|
127
|
+
newValue: newContent,
|
|
128
|
+
changeRecords,
|
|
129
|
+
historyDescription,
|
|
130
|
+
source: historySource
|
|
131
|
+
});
|
|
132
|
+
this.lastPushedHistoryId = (step ? history_default.push("codeBlock", step, id) : null)?.uuid ?? null;
|
|
133
|
+
}
|
|
131
134
|
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
132
135
|
}
|
|
133
136
|
/**
|
|
@@ -212,15 +215,16 @@ var CodeBlock = class extends BaseService {
|
|
|
212
215
|
if (!currentDsl) return;
|
|
213
216
|
this.lastDeletedHistoryIds = [];
|
|
214
217
|
codeIds.forEach((id) => {
|
|
215
|
-
const
|
|
218
|
+
const oldValue = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
|
|
216
219
|
delete currentDsl[id];
|
|
217
|
-
if (
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
220
|
+
if (oldValue && !doNotPushHistory) {
|
|
221
|
+
const step = createStackStep(id, {
|
|
222
|
+
oldValue,
|
|
223
|
+
newValue: null,
|
|
221
224
|
historyDescription,
|
|
222
225
|
source: historySource
|
|
223
|
-
})
|
|
226
|
+
});
|
|
227
|
+
const uuid = step ? history_default.push("codeBlock", step, id)?.uuid : void 0;
|
|
224
228
|
if (uuid) this.lastDeletedHistoryIds.push(uuid);
|
|
225
229
|
}
|
|
226
230
|
this.emit("remove", id);
|
|
@@ -281,7 +285,7 @@ var CodeBlock = class extends BaseService {
|
|
|
281
285
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
282
286
|
*/
|
|
283
287
|
async undo(id) {
|
|
284
|
-
const step = history_default.
|
|
288
|
+
const step = history_default.undo("codeBlock", id);
|
|
285
289
|
if (!step) return null;
|
|
286
290
|
await this.applyHistoryStep(step, true);
|
|
287
291
|
return step;
|
|
@@ -292,18 +296,18 @@ var CodeBlock = class extends BaseService {
|
|
|
292
296
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
293
297
|
*/
|
|
294
298
|
async redo(id) {
|
|
295
|
-
const step = history_default.
|
|
299
|
+
const step = history_default.redo("codeBlock", id);
|
|
296
300
|
if (!step) return null;
|
|
297
301
|
await this.applyHistoryStep(step, false);
|
|
298
302
|
return step;
|
|
299
303
|
}
|
|
300
304
|
/** 是否可对指定代码块撤销。 */
|
|
301
305
|
canUndo(id) {
|
|
302
|
-
return history_default.
|
|
306
|
+
return history_default.canUndo("codeBlock", id);
|
|
303
307
|
}
|
|
304
308
|
/** 是否可对指定代码块重做。 */
|
|
305
309
|
canRedo(id) {
|
|
306
|
-
return history_default.
|
|
310
|
+
return history_default.canRedo("codeBlock", id);
|
|
307
311
|
}
|
|
308
312
|
/**
|
|
309
313
|
* 跳转指定代码块的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
@@ -313,7 +317,7 @@ var CodeBlock = class extends BaseService {
|
|
|
313
317
|
* @returns 实际移动到的最终游标位置
|
|
314
318
|
*/
|
|
315
319
|
async goto(id, targetCursor) {
|
|
316
|
-
let cursor = history_default.
|
|
320
|
+
let cursor = history_default.getCursor("codeBlock", id);
|
|
317
321
|
const target = Math.max(0, targetCursor);
|
|
318
322
|
while (cursor > target) {
|
|
319
323
|
if (!await this.undo(id)) break;
|
|
@@ -336,11 +340,11 @@ var CodeBlock = class extends BaseService {
|
|
|
336
340
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
337
341
|
*/
|
|
338
342
|
async revert(id, index) {
|
|
339
|
-
const entry = history_default.
|
|
343
|
+
const entry = history_default.getStepList("codeBlock", id)[index];
|
|
340
344
|
if (!entry?.applied) return null;
|
|
341
345
|
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
342
346
|
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
343
|
-
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
347
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.data.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
344
348
|
return await this.applyRevertStep(entry.step, description);
|
|
345
349
|
}
|
|
346
350
|
/**
|
|
@@ -353,7 +357,7 @@ var CodeBlock = class extends BaseService {
|
|
|
353
357
|
async revertById(uuids) {
|
|
354
358
|
const results = [];
|
|
355
359
|
for (const uuid of uuids) {
|
|
356
|
-
const location = history_default.
|
|
360
|
+
const location = history_default.findStepLocationByUuid("codeBlock", uuid);
|
|
357
361
|
results.push(location ? await this.revert(location.id, location.index) : null);
|
|
358
362
|
}
|
|
359
363
|
return results;
|
|
@@ -423,21 +427,21 @@ var CodeBlock = class extends BaseService {
|
|
|
423
427
|
* 差异仅在于通过公开的 setCodeDslByIdSync / deleteCodeDslByIds 触发 push。
|
|
424
428
|
*/
|
|
425
429
|
async applyRevertStep(step, historyDescription) {
|
|
426
|
-
const { id } = step;
|
|
430
|
+
const { id } = step.data;
|
|
427
431
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
428
432
|
if (!oldSchema && newSchema) {
|
|
429
433
|
await this.deleteCodeDslByIds([id], {
|
|
430
434
|
historyDescription,
|
|
431
435
|
historySource: "rollback"
|
|
432
436
|
});
|
|
433
|
-
return history_default.
|
|
437
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
434
438
|
}
|
|
435
439
|
if (oldSchema && !newSchema) {
|
|
436
440
|
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
437
441
|
historyDescription,
|
|
438
442
|
historySource: "rollback"
|
|
439
443
|
});
|
|
440
|
-
return history_default.
|
|
444
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
441
445
|
}
|
|
442
446
|
if (!oldSchema || !newSchema) return null;
|
|
443
447
|
if (changeRecords?.length) {
|
|
@@ -458,13 +462,13 @@ var CodeBlock = class extends BaseService {
|
|
|
458
462
|
historyDescription,
|
|
459
463
|
historySource: "rollback"
|
|
460
464
|
});
|
|
461
|
-
return history_default.
|
|
465
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
462
466
|
}
|
|
463
467
|
this.setCodeDslByIdSync(id, cloneDeep$1(oldSchema), true, {
|
|
464
468
|
historyDescription,
|
|
465
469
|
historySource: "rollback"
|
|
466
470
|
});
|
|
467
|
-
return history_default.
|
|
471
|
+
return history_default.getStepList("codeBlock", id).slice(-1)[0]?.step ?? null;
|
|
468
472
|
}
|
|
469
473
|
/**
|
|
470
474
|
* 把一条历史 step 应用到当前代码块服务上。
|
|
@@ -481,7 +485,7 @@ var CodeBlock = class extends BaseService {
|
|
|
481
485
|
* @param reverse true=撤销,false=重做
|
|
482
486
|
*/
|
|
483
487
|
async applyHistoryStep(step, reverse) {
|
|
484
|
-
const { id } = step;
|
|
488
|
+
const { id } = step.data;
|
|
485
489
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
486
490
|
if (!oldSchema && newSchema) {
|
|
487
491
|
if (reverse) await this.deleteCodeDslByIds([id], { doNotPushHistory: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BaseService from "./BaseService.js";
|
|
2
|
-
import { describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
2
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from "../utils/history.js";
|
|
3
3
|
import history_default from "./history.js";
|
|
4
4
|
import storage_default, { Protocol } from "./storage.js";
|
|
5
5
|
import { COPY_DS_STORAGE_KEY } from "../utils/editor.js";
|
|
@@ -92,12 +92,15 @@ var DataSource = class extends BaseService {
|
|
|
92
92
|
id: config.id && !this.getDataSourceById(config.id) ? config.id : this.createId()
|
|
93
93
|
};
|
|
94
94
|
this.get("dataSources").push(newConfig);
|
|
95
|
-
if (!doNotPushHistory)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
if (!doNotPushHistory) {
|
|
96
|
+
const step = createStackStep(newConfig.id, {
|
|
97
|
+
oldValue: null,
|
|
98
|
+
newValue: newConfig,
|
|
99
|
+
historyDescription,
|
|
100
|
+
source: historySource
|
|
101
|
+
});
|
|
102
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
103
|
+
}
|
|
101
104
|
this.emit("add", newConfig);
|
|
102
105
|
return newConfig;
|
|
103
106
|
}
|
|
@@ -115,13 +118,16 @@ var DataSource = class extends BaseService {
|
|
|
115
118
|
const oldConfig = dataSources[index];
|
|
116
119
|
const newConfig = cloneDeep$1(config);
|
|
117
120
|
dataSources[index] = newConfig;
|
|
118
|
-
if (!doNotPushHistory)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
if (!doNotPushHistory) {
|
|
122
|
+
const step = createStackStep(newConfig.id, {
|
|
123
|
+
oldValue: oldConfig ? cloneDeep$1(oldConfig) : null,
|
|
124
|
+
newValue: newConfig,
|
|
125
|
+
changeRecords,
|
|
126
|
+
historyDescription,
|
|
127
|
+
source: historySource
|
|
128
|
+
});
|
|
129
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
130
|
+
}
|
|
125
131
|
this.emit("update", newConfig, {
|
|
126
132
|
oldConfig,
|
|
127
133
|
changeRecords
|
|
@@ -140,12 +146,15 @@ var DataSource = class extends BaseService {
|
|
|
140
146
|
const index = dataSources.findIndex((ds) => ds.id === id);
|
|
141
147
|
const oldConfig = index !== -1 ? dataSources[index] : null;
|
|
142
148
|
dataSources.splice(index, 1);
|
|
143
|
-
if (oldConfig && !doNotPushHistory)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
+
if (oldConfig && !doNotPushHistory) {
|
|
150
|
+
const step = createStackStep(id, {
|
|
151
|
+
oldValue: cloneDeep$1(oldConfig),
|
|
152
|
+
newValue: null,
|
|
153
|
+
historyDescription,
|
|
154
|
+
source: historySource
|
|
155
|
+
});
|
|
156
|
+
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, id) : null)?.uuid ?? null;
|
|
157
|
+
}
|
|
149
158
|
this.emit("remove", id);
|
|
150
159
|
}
|
|
151
160
|
/**
|
|
@@ -191,7 +200,7 @@ var DataSource = class extends BaseService {
|
|
|
191
200
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
192
201
|
*/
|
|
193
202
|
undo(id) {
|
|
194
|
-
const step = history_default.
|
|
203
|
+
const step = history_default.undo("dataSource", id);
|
|
195
204
|
if (!step) return null;
|
|
196
205
|
this.applyHistoryStep(step, true);
|
|
197
206
|
return step;
|
|
@@ -202,18 +211,18 @@ var DataSource = class extends BaseService {
|
|
|
202
211
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
203
212
|
*/
|
|
204
213
|
redo(id) {
|
|
205
|
-
const step = history_default.
|
|
214
|
+
const step = history_default.redo("dataSource", id);
|
|
206
215
|
if (!step) return null;
|
|
207
216
|
this.applyHistoryStep(step, false);
|
|
208
217
|
return step;
|
|
209
218
|
}
|
|
210
219
|
/** 是否可对指定数据源撤销。 */
|
|
211
220
|
canUndo(id) {
|
|
212
|
-
return history_default.
|
|
221
|
+
return history_default.canUndo("dataSource", id);
|
|
213
222
|
}
|
|
214
223
|
/** 是否可对指定数据源重做。 */
|
|
215
224
|
canRedo(id) {
|
|
216
|
-
return history_default.
|
|
225
|
+
return history_default.canRedo("dataSource", id);
|
|
217
226
|
}
|
|
218
227
|
/**
|
|
219
228
|
* 跳转指定数据源的历史栈到目标游标。语义同 editor.gotoPageStep。
|
|
@@ -223,7 +232,7 @@ var DataSource = class extends BaseService {
|
|
|
223
232
|
* @returns 实际移动到的最终游标位置
|
|
224
233
|
*/
|
|
225
234
|
goto(id, targetCursor) {
|
|
226
|
-
let cursor = history_default.
|
|
235
|
+
let cursor = history_default.getCursor("dataSource", id);
|
|
227
236
|
const target = Math.max(0, targetCursor);
|
|
228
237
|
while (cursor > target) {
|
|
229
238
|
if (!this.undo(id)) break;
|
|
@@ -246,11 +255,11 @@ var DataSource = class extends BaseService {
|
|
|
246
255
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
247
256
|
*/
|
|
248
257
|
revert(id, index) {
|
|
249
|
-
const entry = history_default.
|
|
258
|
+
const entry = history_default.getStepList("dataSource", id)[index];
|
|
250
259
|
if (!entry?.applied) return null;
|
|
251
260
|
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
252
261
|
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
253
|
-
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.id, entry.step.diff?.[0], (s) => s.title)}`;
|
|
262
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep(entry.step.data.id, entry.step.diff?.[0], (s) => s.title)}`;
|
|
254
263
|
return this.applyRevertStep(entry.step, description);
|
|
255
264
|
}
|
|
256
265
|
/**
|
|
@@ -262,7 +271,7 @@ var DataSource = class extends BaseService {
|
|
|
262
271
|
*/
|
|
263
272
|
revertById(uuids) {
|
|
264
273
|
return uuids.map((uuid) => {
|
|
265
|
-
const location = history_default.
|
|
274
|
+
const location = history_default.findStepLocationByUuid("dataSource", uuid);
|
|
266
275
|
if (!location) return null;
|
|
267
276
|
return this.revert(location.id, location.index);
|
|
268
277
|
});
|
|
@@ -325,21 +334,21 @@ var DataSource = class extends BaseService {
|
|
|
325
334
|
* 同构,差异仅在于走对应的公共 add / update / remove 而不是带 doNotPushHistory 的版本。
|
|
326
335
|
*/
|
|
327
336
|
applyRevertStep(step, historyDescription) {
|
|
328
|
-
const { id } = step;
|
|
337
|
+
const { id } = step.data;
|
|
329
338
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
330
339
|
if (!oldSchema && newSchema) {
|
|
331
340
|
this.remove(`${id}`, {
|
|
332
341
|
historyDescription,
|
|
333
342
|
historySource: "rollback"
|
|
334
343
|
});
|
|
335
|
-
return history_default.
|
|
344
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
336
345
|
}
|
|
337
346
|
if (oldSchema && !newSchema) {
|
|
338
347
|
this.add(cloneDeep$1(oldSchema), {
|
|
339
348
|
historyDescription,
|
|
340
349
|
historySource: "rollback"
|
|
341
350
|
});
|
|
342
|
-
return history_default.
|
|
351
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
343
352
|
}
|
|
344
353
|
if (!oldSchema || !newSchema) return null;
|
|
345
354
|
if (changeRecords?.length) {
|
|
@@ -360,13 +369,13 @@ var DataSource = class extends BaseService {
|
|
|
360
369
|
historyDescription,
|
|
361
370
|
historySource: "rollback"
|
|
362
371
|
});
|
|
363
|
-
return history_default.
|
|
372
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
364
373
|
}
|
|
365
374
|
this.update(cloneDeep$1(oldSchema), {
|
|
366
375
|
historyDescription,
|
|
367
376
|
historySource: "rollback"
|
|
368
377
|
});
|
|
369
|
-
return history_default.
|
|
378
|
+
return history_default.getStepList("dataSource", id).slice(-1)[0]?.step ?? null;
|
|
370
379
|
}
|
|
371
380
|
/**
|
|
372
381
|
* 把一条历史 step 应用到当前数据源服务上。
|
|
@@ -383,7 +392,7 @@ var DataSource = class extends BaseService {
|
|
|
383
392
|
* @param reverse true=撤销,false=重做
|
|
384
393
|
*/
|
|
385
394
|
applyHistoryStep(step, reverse) {
|
|
386
|
-
const { id } = step;
|
|
395
|
+
const { id } = step.data;
|
|
387
396
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
388
397
|
if (!oldSchema && newSchema) {
|
|
389
398
|
if (reverse) this.remove(`${id}`, { doNotPushHistory: true });
|