@tmagic/editor 1.8.0-beta.4 → 1.8.0-beta.5
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 +1 -1
- package/dist/es/components/ToolButton.vue_vue_type_script_setup_true_lang.js +6 -6
- package/dist/es/index.js +6 -3
- package/dist/es/initService.js +1 -1
- package/dist/es/layouts/Framework.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 +19 -55
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +22 -39
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +149 -103
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +32 -8
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +333 -211
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +28 -7
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +47 -60
- package/dist/es/layouts/history-list/composables.js +73 -32
- package/dist/es/layouts/page-bar/PageBar.vue_vue_type_script_setup_true_lang.js +4 -2
- package/dist/es/layouts/sidebar/Sidebar.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/services/codeBlock.js +85 -37
- package/dist/es/services/dataSource.js +62 -26
- package/dist/es/services/editor.js +243 -100
- package/dist/es/services/history.js +270 -206
- package/dist/es/services/ui.js +3 -0
- package/dist/es/style.css +49 -6
- package/dist/es/utils/editor.js +35 -1
- package/dist/es/utils/history.js +223 -0
- package/dist/es/utils/indexed-db.js +86 -0
- package/dist/es/utils/undo-redo.js +60 -1
- package/dist/style.css +49 -6
- package/dist/tmagic-editor.umd.cjs +1799 -905
- package/package.json +7 -7
- package/src/components/CompareForm.vue +3 -1
- package/src/components/ToolButton.vue +2 -2
- package/src/index.ts +1 -0
- package/src/initService.ts +1 -1
- package/src/layouts/Framework.vue +1 -1
- package/src/layouts/history-list/Bucket.vue +34 -71
- package/src/layouts/history-list/BucketTab.vue +46 -54
- package/src/layouts/history-list/GroupRow.vue +146 -111
- package/src/layouts/history-list/HistoryDiffDialog.vue +94 -68
- package/src/layouts/history-list/HistoryListPanel.vue +296 -113
- package/src/layouts/history-list/InitialRow.vue +25 -9
- package/src/layouts/history-list/PageTab.vue +57 -51
- package/src/layouts/history-list/composables.ts +157 -36
- package/src/layouts/page-bar/PageBar.vue +4 -2
- package/src/layouts/sidebar/Sidebar.vue +6 -1
- package/src/services/codeBlock.ts +107 -37
- package/src/services/dataSource.ts +89 -40
- package/src/services/editor.ts +370 -134
- package/src/services/history.ts +305 -203
- package/src/services/ui.ts +7 -0
- package/src/theme/history-list-panel.scss +72 -5
- package/src/theme/page-bar.scss +0 -4
- package/src/type.ts +167 -63
- package/src/utils/editor.ts +41 -1
- package/src/utils/history.ts +298 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/indexed-db.ts +122 -0
- package/src/utils/undo-redo.ts +88 -0
- package/types/index.d.ts +783 -291
package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -4,11 +4,17 @@ import { describeCodeBlockGroup, describeCodeBlockStep, describeDataSourceGroup,
|
|
|
4
4
|
import BucketTab_default from "./BucketTab.js";
|
|
5
5
|
import HistoryDiffDialog_default from "./HistoryDiffDialog.js";
|
|
6
6
|
import PageTab_default from "./PageTab.js";
|
|
7
|
-
import { TMagicButton, TMagicPopover, TMagicTabs, TMagicTooltip, getDesignConfig } from "@tmagic/design";
|
|
8
|
-
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, inject, markRaw, mergeProps, normalizeProps, openBlock, ref, renderList, resolveDynamicComponent,
|
|
7
|
+
import { TMagicButton, TMagicPopover, TMagicTabs, TMagicTooltip, getDesignConfig, tMagicMessage, tMagicMessageBox } from "@tmagic/design";
|
|
8
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, guardReactiveProps, inject, markRaw, mergeProps, normalizeProps, openBlock, ref, renderList, resolveDynamicComponent, toHandlers, unref, useTemplateRef, watch, withCtx } from "vue";
|
|
9
9
|
import { Clock, Close } from "@element-plus/icons-vue";
|
|
10
10
|
//#region packages/editor/src/layouts/history-list/HistoryListPanel.vue?vue&type=script&setup=true&lang.ts
|
|
11
11
|
var _hoisted_1 = { class: "m-editor-history-list" };
|
|
12
|
+
/**
|
|
13
|
+
* 构造差异弹窗入参:仅 update(前后值都存在)可对比。
|
|
14
|
+
* - 页面(无 id):在全部分组中按 index 定位 step,目标 id 取自快照;
|
|
15
|
+
* - 数据源 / 代码块(带 id):先匹配分组 id 再按 index 定位。
|
|
16
|
+
* 无可对比内容(多节点 / add / remove)或定位不到时返回 null。
|
|
17
|
+
*/
|
|
12
18
|
var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
13
19
|
name: "MEditorHistoryListPanel",
|
|
14
20
|
__name: "HistoryListPanel",
|
|
@@ -37,7 +43,10 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
37
43
|
const ClockIcon = markRaw(Clock);
|
|
38
44
|
const CloseIcon = markRaw(Close);
|
|
39
45
|
const activeTab = ref("page");
|
|
40
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* 面板显隐受控:reference 图标点击切换,右上角关闭按钮置为 false。
|
|
48
|
+
* 点击面板以外区域的自动收起由 TMagicPopover 通过 v-model:visible 回写完成。
|
|
49
|
+
*/
|
|
41
50
|
const visible = ref(false);
|
|
42
51
|
const tabPaneComponent = getDesignConfig("components")?.tabPane;
|
|
43
52
|
/**
|
|
@@ -47,7 +56,7 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
47
56
|
const extraTabs = inject("historyListExtraTabs", []);
|
|
48
57
|
/** label 支持字符串或函数,函数形式便于展示动态数量等内容。 */
|
|
49
58
|
const resolveTabLabel = (tab) => typeof tab.label === "function" ? tab.label() : tab.label;
|
|
50
|
-
const { editorService, dataSourceService, codeBlockService, historyService, propsService } = useServices();
|
|
59
|
+
const { editorService, dataSourceService, codeBlockService, historyService, propsService, stageOverlayService } = useServices();
|
|
51
60
|
/**
|
|
52
61
|
* 数据源 / 代码块功能可被业务方通过 `disabledDataSource` / `disabledCodeBlock` 禁用,
|
|
53
62
|
* 禁用后对应的历史记录 tab 不再展示。若当前激活的 tab 恰好被禁用,则回退到「页面」tab。
|
|
@@ -64,15 +73,60 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
64
73
|
*/
|
|
65
74
|
const extendFormState = inject("extendFormState", void 0);
|
|
66
75
|
const { expanded, toggleGroup, pageGroups, dataSourceGroups, codeBlockGroups, pageGroupsDisplay, dataSourceGroupsByTarget, codeBlockGroupsByTarget } = useHistoryList();
|
|
76
|
+
/**
|
|
77
|
+
* 当前活动页的「加载/初始」标记记录(设置 root 时生成),透传给 PageTab 的底部初始行展示。
|
|
78
|
+
* 基于 historyService 的 reactive state 派生,活动页切换或标记写入后自动刷新。
|
|
79
|
+
*/
|
|
80
|
+
const pageMarker = computed(() => historyService.getPageMarker());
|
|
67
81
|
/** 数据源 step 仅 update(前后 schema 都存在)时可查看差异。 */
|
|
68
|
-
const isDataSourceStepDiffable = (step) => Boolean(step.oldSchema && step.newSchema);
|
|
82
|
+
const isDataSourceStepDiffable = (step) => Boolean(step.diff?.[0]?.oldSchema && step.diff?.[0]?.newSchema);
|
|
69
83
|
/** 代码块 step 仅 update(前后 content 都存在)时可查看差异。 */
|
|
70
|
-
const isCodeBlockStepDiffable = (step) => Boolean(step.
|
|
84
|
+
const isCodeBlockStepDiffable = (step) => Boolean(step.diff?.[0]?.oldSchema && step.diff?.[0]?.newSchema);
|
|
85
|
+
/**
|
|
86
|
+
* 数据源 / 代码块两类 bucket 历史的整体渲染配置:把 title / prefix 与各自的描述、
|
|
87
|
+
* 可差异、可回滚判定收敛为单一对象整体注入 BucketTab,组件内部按需读取。
|
|
88
|
+
*/
|
|
89
|
+
const dataSourceConfig = {
|
|
90
|
+
title: "数据源",
|
|
91
|
+
prefix: "ds",
|
|
92
|
+
describeGroup: describeDataSourceGroup,
|
|
93
|
+
describeStep: describeDataSourceStep,
|
|
94
|
+
isStepDiffable: isDataSourceStepDiffable,
|
|
95
|
+
isStepRevertable: isDataSourceStepRevertable
|
|
96
|
+
};
|
|
97
|
+
const codeBlockConfig = {
|
|
98
|
+
title: "代码块",
|
|
99
|
+
prefix: "cb",
|
|
100
|
+
describeGroup: describeCodeBlockGroup,
|
|
101
|
+
describeStep: describeCodeBlockStep,
|
|
102
|
+
isStepDiffable: isCodeBlockStepDiffable,
|
|
103
|
+
isStepRevertable: isCodeBlockStepRevertable
|
|
104
|
+
};
|
|
71
105
|
/** 把"目标 step 索引"翻译成"目标 cursor"(已应用步骤数量)。 */
|
|
72
106
|
const indexToCursor = (index) => index + 1;
|
|
73
107
|
const onPageGoto = (index) => {
|
|
74
108
|
editorService.gotoPageStep(indexToCursor(index));
|
|
75
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* 点击页面历史记录行:选中该记录对应的画布节点。
|
|
112
|
+
* - 从目标 step 的 diff 中取节点 id(优先 newSchema,回退 oldSchema),按出现顺序找到第一个当前仍存在的节点;
|
|
113
|
+
* - 与图层树点击选中一致:editorService.select + 画布 / overlay 画布 select 三者联动;
|
|
114
|
+
* - 该 step 涉及的节点都已不存在(如删除记录、被撤销的新增)时给出提示,不做选中。
|
|
115
|
+
*/
|
|
116
|
+
const onPageSelect = async (index) => {
|
|
117
|
+
const step = historyService.getPageStepList()[index]?.step;
|
|
118
|
+
if (!step) return;
|
|
119
|
+
const targetId = (step.diff ?? []).map((item) => item.newSchema?.id ?? item.oldSchema?.id).find((id) => id !== void 0 && id !== null && editorService.getNodeById(id, false));
|
|
120
|
+
if (targetId === void 0 || targetId === null) {
|
|
121
|
+
tMagicMessage.warning("该记录对应的节点已不存在,无法选中");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const node = editorService.getNodeById(targetId, false);
|
|
125
|
+
if (!node) return;
|
|
126
|
+
await editorService.select(node);
|
|
127
|
+
editorService.get("stage")?.select(targetId);
|
|
128
|
+
stageOverlayService.get("stage")?.select(targetId);
|
|
129
|
+
};
|
|
76
130
|
const onDataSourceGoto = (id, index) => {
|
|
77
131
|
dataSourceService.goto(id, indexToCursor(index));
|
|
78
132
|
};
|
|
@@ -93,71 +147,53 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
93
147
|
codeBlockService.goto(id, 0);
|
|
94
148
|
};
|
|
95
149
|
const diffDialogRef = useTemplateRef("diffDialog");
|
|
150
|
+
const confirmDialogRef = useTemplateRef("confirmDialog");
|
|
96
151
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* `currentValue` 取自 editorService 中该节点当前实际值,用于支持「与当前对比」。
|
|
100
|
-
* 无可对比内容(如多节点 / add / remove)时返回 null。
|
|
152
|
+
* 三类历史(页面 / 数据源 / 代码块)差异弹窗入参的构造差异,收敛为一份配置:
|
|
153
|
+
* 仅「分组来源、当前值读取、类型 / 展示名提取」不同,定位 step、校验前后值、组装 payload 的流程共用。
|
|
101
154
|
*/
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
const
|
|
155
|
+
const buildDiffPayload = (source, index, id) => {
|
|
156
|
+
for (const group of source.groups()) {
|
|
157
|
+
if (id !== void 0 && group.id !== id) continue;
|
|
158
|
+
const step = group.steps.find((s) => s.index === index)?.step;
|
|
159
|
+
if (!step) continue;
|
|
160
|
+
const oldSchema = step.diff?.[0]?.oldSchema;
|
|
161
|
+
const newSchema = step.diff?.[0]?.newSchema;
|
|
162
|
+
if (!oldSchema || !newSchema) return null;
|
|
163
|
+
const targetId = id ?? newSchema.id ?? oldSchema.id;
|
|
164
|
+
const type = source.resolveType?.(newSchema, oldSchema);
|
|
112
165
|
return {
|
|
113
|
-
category:
|
|
114
|
-
type,
|
|
115
|
-
lastValue:
|
|
116
|
-
value:
|
|
117
|
-
currentValue:
|
|
118
|
-
targetLabel:
|
|
119
|
-
id:
|
|
166
|
+
category: source.category,
|
|
167
|
+
...type !== void 0 ? { type } : {},
|
|
168
|
+
lastValue: oldSchema,
|
|
169
|
+
value: newSchema,
|
|
170
|
+
currentValue: (targetId !== void 0 ? source.getCurrent(targetId) : null) || null,
|
|
171
|
+
targetLabel: source.resolveLabel(newSchema, oldSchema, targetId),
|
|
172
|
+
id: targetId
|
|
120
173
|
};
|
|
121
174
|
}
|
|
122
175
|
return null;
|
|
123
176
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
value: newSchema,
|
|
145
|
-
currentValue: currentSchema || null,
|
|
146
|
-
targetLabel: newSchema.title || oldSchema.title || `${id}`,
|
|
147
|
-
id
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
const buildCodeBlockDiffPayload = (id, index) => findGroupStep(historyService.getCodeBlockHistoryGroups(), id, index, ({ oldContent, newContent }) => {
|
|
151
|
-
if (!oldContent || !newContent) return null;
|
|
152
|
-
return {
|
|
153
|
-
category: "code-block",
|
|
154
|
-
lastValue: oldContent,
|
|
155
|
-
value: newContent,
|
|
156
|
-
currentValue: codeBlockService.getCodeContentById(id) || null,
|
|
157
|
-
targetLabel: newContent.name || oldContent.name || `${id}`,
|
|
158
|
-
id
|
|
159
|
-
};
|
|
160
|
-
});
|
|
177
|
+
const buildPageDiffPayload = (index) => buildDiffPayload({
|
|
178
|
+
category: "node",
|
|
179
|
+
groups: () => historyService.getPageHistoryGroups(),
|
|
180
|
+
getCurrent: (id) => editorService.getNodeById(id),
|
|
181
|
+
resolveType: (n, o) => n.type || o.type || "",
|
|
182
|
+
resolveLabel: (n, o) => n.name || o.name || n.type || o.type || ""
|
|
183
|
+
}, index);
|
|
184
|
+
const buildDataSourceDiffPayload = (id, index) => buildDiffPayload({
|
|
185
|
+
category: "data-source",
|
|
186
|
+
groups: () => historyService.getDataSourceHistoryGroups(),
|
|
187
|
+
getCurrent: (id) => dataSourceService.getDataSourceById(`${id}`),
|
|
188
|
+
resolveType: (n, o) => n.type || o.type || "base",
|
|
189
|
+
resolveLabel: (n, o, id) => n.title || o.title || `${id}`
|
|
190
|
+
}, index, id);
|
|
191
|
+
const buildCodeBlockDiffPayload = (id, index) => buildDiffPayload({
|
|
192
|
+
category: "code-block",
|
|
193
|
+
groups: () => historyService.getCodeBlockHistoryGroups(),
|
|
194
|
+
getCurrent: (id) => codeBlockService.getCodeContentById(id),
|
|
195
|
+
resolveLabel: (n, o, id) => n.name || o.name || `${id}`
|
|
196
|
+
}, index, id);
|
|
161
197
|
const onPageDiff = (index) => {
|
|
162
198
|
const payload = buildPageDiffPayload(index);
|
|
163
199
|
if (payload) diffDialogRef.value?.open(payload);
|
|
@@ -170,173 +206,259 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /* @__PURE__
|
|
|
170
206
|
const payload = buildCodeBlockDiffPayload(id, index);
|
|
171
207
|
if (payload) diffDialogRef.value?.open(payload);
|
|
172
208
|
};
|
|
173
|
-
const onConfirmRevert = shallowRef();
|
|
174
209
|
/**
|
|
175
|
-
*
|
|
210
|
+
* 「回滚」统一入口:把目标历史步骤的修改作为一次新操作反向应用(类 git revert),
|
|
176
211
|
* 不破坏原有栈结构。各 service 内部完成反向 + 入栈,并自带描述用于面板展示。
|
|
177
212
|
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
213
|
+
* 交互:
|
|
214
|
+
* - 可差异对比的步骤(单节点 / 单实体 update):弹出差异弹窗供用户确认,点「确定回滚」再执行;
|
|
215
|
+
* - 无法对比的步骤(add / remove / 多节点更新,payload 为 null):弹出普通二次确认框,确认后执行。
|
|
216
|
+
*
|
|
217
|
+
* 页面 / 数据源 / 代码块三类回滚仅「差异入参构造」与「实际 revert 调用」不同,
|
|
218
|
+
* 由调用方分别传入 payload 与 revert,公共的弹窗 / 确认流程在此收敛。
|
|
180
219
|
*/
|
|
220
|
+
const runRevert = (payload) => {
|
|
221
|
+
if (payload && confirmDialogRef.value) return confirmDialogRef.value.confirm(payload);
|
|
222
|
+
return confirmRevert();
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* 回滚前置校验:若该历史步骤回滚所依赖的目标数据已被删除,则无法回滚。
|
|
226
|
+
* - update(把旧值写回):被修改的目标必须仍存在;
|
|
227
|
+
* - 页面 remove(还原被删节点):被删节点的原父容器必须仍存在,否则无处插回;
|
|
228
|
+
* add(回滚即删除)即使目标已不在,也已达成「删除」目的,不视为失败。
|
|
229
|
+
*
|
|
230
|
+
* 命中时弹出「回滚失败」提示并返回 true,调用方据此中止本次回滚。
|
|
231
|
+
*/
|
|
232
|
+
const isPageRevertTargetMissing = (index) => {
|
|
233
|
+
const step = historyService.getPageStepList()[index]?.step;
|
|
234
|
+
if (!step) return false;
|
|
235
|
+
if (step.opType === "update") return (step.diff ?? []).some((item) => {
|
|
236
|
+
const id = item.newSchema?.id ?? item.oldSchema?.id;
|
|
237
|
+
return id !== void 0 && !editorService.getNodeById(id, false);
|
|
238
|
+
});
|
|
239
|
+
if (step.opType === "remove") return (step.diff ?? []).some((item) => item.parentId !== void 0 && !editorService.getNodeById(item.parentId, false));
|
|
240
|
+
return false;
|
|
241
|
+
};
|
|
242
|
+
/** 数据源 update 步骤回滚时,对应数据源必须仍存在(已删除则无处写回旧值)。 */
|
|
243
|
+
const isDataSourceRevertTargetMissing = (id, index) => {
|
|
244
|
+
const step = historyService.getDataSourceStepList(id)[index]?.step;
|
|
245
|
+
return Boolean(step && step.opType === "update" && !dataSourceService.getDataSourceById(`${id}`));
|
|
246
|
+
};
|
|
247
|
+
/** 代码块 update 步骤回滚时,对应代码块必须仍存在(已删除则无处写回旧值)。 */
|
|
248
|
+
const isCodeBlockRevertTargetMissing = (id, index) => {
|
|
249
|
+
const step = historyService.getCodeBlockStepList(id)[index]?.step;
|
|
250
|
+
return Boolean(step && step.opType === "update" && !codeBlockService.getCodeContentById(id));
|
|
251
|
+
};
|
|
252
|
+
/** 目标数据已被删除、无法回滚时的统一提示。 */
|
|
253
|
+
const showRevertTargetMissing = () => {
|
|
254
|
+
tMagicMessage.error("回滚失败:该记录对应的数据已被删除");
|
|
255
|
+
};
|
|
181
256
|
const onPageRevert = (index) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
257
|
+
if (isPageRevertTargetMissing(index)) {
|
|
258
|
+
showRevertTargetMissing();
|
|
259
|
+
return Promise.resolve(null);
|
|
260
|
+
}
|
|
261
|
+
return runRevert(buildPageDiffPayload(index)).then((result) => result ? editorService.revertPageStep(index) : null);
|
|
186
262
|
};
|
|
187
263
|
const onDataSourceRevert = (id, index) => {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
264
|
+
if (isDataSourceRevertTargetMissing(id, index)) {
|
|
265
|
+
showRevertTargetMissing();
|
|
266
|
+
return Promise.resolve(null);
|
|
267
|
+
}
|
|
268
|
+
return runRevert(buildDataSourceDiffPayload(id, index)).then((result) => result ? dataSourceService.revert(id, index) : null);
|
|
192
269
|
};
|
|
193
270
|
const onCodeBlockRevert = (id, index) => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
271
|
+
if (isCodeBlockRevertTargetMissing(id, index)) {
|
|
272
|
+
showRevertTargetMissing();
|
|
273
|
+
return Promise.resolve(null);
|
|
274
|
+
}
|
|
275
|
+
return runRevert(buildCodeBlockDiffPayload(id, index)).then((result) => result ? codeBlockService.revert(id, index) : null);
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* 「回滚」二次确认:新增 / 删除 / 多节点更新等无法做差异对比的步骤,
|
|
279
|
+
* 不弹差异弹窗,改用一个普通确认框替代「确定回滚」按钮,避免点击后无任何提示直接执行。
|
|
280
|
+
* 用户取消时返回 false,调用方据此中止回滚。
|
|
281
|
+
*/
|
|
282
|
+
const confirmRevert = () => confirmDialog("确定回滚该步骤吗?回滚会将该操作作为一条新记录反向应用(新增将被删除、删除将被还原),不影响后续历史记录。");
|
|
283
|
+
/**
|
|
284
|
+
* 通用二次确认弹窗:清空历史 / 无法差异对比的回滚等会改变状态的操作,先弹出确认框,
|
|
285
|
+
* 用户点击「确定」返回 true,取消(confirm reject)时返回 false 并静默忽略。
|
|
286
|
+
*/
|
|
287
|
+
const confirmDialog = async (message) => {
|
|
288
|
+
try {
|
|
289
|
+
await tMagicMessageBox.confirm(message, "提示", {
|
|
290
|
+
confirmButtonText: "确定",
|
|
291
|
+
cancelButtonText: "取消",
|
|
292
|
+
type: "warning"
|
|
293
|
+
});
|
|
294
|
+
return true;
|
|
295
|
+
} catch (e) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
/**
|
|
300
|
+
* 把内存中(已清空对应类别后的)历史状态重新写回 IndexedDB,
|
|
301
|
+
* 使本地持久化的那份与内存保持一致——即「连同本地保存的一并删除」。
|
|
302
|
+
* 不支持 IndexedDB 或写入失败时静默忽略(内存清空已生效)。
|
|
303
|
+
*/
|
|
304
|
+
const syncIndexedDB = async () => {
|
|
305
|
+
try {
|
|
306
|
+
await historyService.saveToIndexedDB();
|
|
307
|
+
} catch (e) {}
|
|
308
|
+
};
|
|
309
|
+
const onPageClear = async () => {
|
|
310
|
+
if (await confirmDialog("确定清空当前页面的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
311
|
+
historyService.clearPage();
|
|
312
|
+
await syncIndexedDB();
|
|
313
|
+
}
|
|
198
314
|
};
|
|
199
|
-
const
|
|
200
|
-
|
|
315
|
+
const onDataSourceClear = async () => {
|
|
316
|
+
if (await confirmDialog("确定清空数据源的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
317
|
+
historyService.clearDataSource();
|
|
318
|
+
await syncIndexedDB();
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
const onCodeBlockClear = async () => {
|
|
322
|
+
if (await confirmDialog("确定清空代码块的历史记录吗?清空后将无法撤销/重做之前的操作,本地保存的记录也会一并删除。")) {
|
|
323
|
+
historyService.clearCodeBlock();
|
|
324
|
+
await syncIndexedDB();
|
|
325
|
+
}
|
|
201
326
|
};
|
|
202
327
|
return (_ctx, _cache) => {
|
|
203
|
-
return openBlock(), createElementBlock(Fragment, null, [
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
trigger: "click",
|
|
207
|
-
visible: visible.value,
|
|
208
|
-
width: 660
|
|
209
|
-
}, {
|
|
210
|
-
reference: withCtx(() => [createVNode(unref(TMagicTooltip), {
|
|
211
|
-
effect: "dark",
|
|
328
|
+
return openBlock(), createElementBlock(Fragment, null, [
|
|
329
|
+
createVNode(unref(TMagicPopover), {
|
|
330
|
+
"popper-class": "m-editor-history-list-popover",
|
|
212
331
|
placement: "bottom",
|
|
213
|
-
|
|
332
|
+
trigger: "click",
|
|
333
|
+
visible: visible.value,
|
|
334
|
+
"onUpdate:visible": _cache[3] || (_cache[3] = ($event) => visible.value = $event),
|
|
335
|
+
width: 660
|
|
214
336
|
}, {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
337
|
+
reference: withCtx(() => [createVNode(unref(TMagicTooltip), {
|
|
338
|
+
effect: "dark",
|
|
339
|
+
placement: "bottom",
|
|
340
|
+
content: "历史记录"
|
|
219
341
|
}, {
|
|
220
|
-
|
|
342
|
+
default: withCtx(() => [createVNode(unref(TMagicButton), {
|
|
343
|
+
size: "small",
|
|
344
|
+
link: "",
|
|
345
|
+
onClick: _cache[2] || (_cache[2] = ($event) => visible.value = !visible.value)
|
|
346
|
+
}, {
|
|
347
|
+
icon: withCtx(() => [createVNode(Icon_default, { icon: unref(ClockIcon) }, null, 8, ["icon"])]),
|
|
348
|
+
_: 1
|
|
349
|
+
})]),
|
|
221
350
|
_: 1
|
|
222
351
|
})]),
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
placement: "top",
|
|
228
|
-
content: "关闭"
|
|
229
|
-
}, {
|
|
230
|
-
default: withCtx(() => [createVNode(unref(TMagicButton), {
|
|
231
|
-
class: "m-editor-history-list-close",
|
|
232
|
-
size: "small",
|
|
233
|
-
link: "",
|
|
234
|
-
onClick: _cache[0] || (_cache[0] = ($event) => visible.value = false)
|
|
352
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1, [createVNode(unref(TMagicTooltip), {
|
|
353
|
+
effect: "dark",
|
|
354
|
+
placement: "top",
|
|
355
|
+
content: "关闭"
|
|
235
356
|
}, {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
class: "m-editor-history-list-tabs"
|
|
244
|
-
}, {
|
|
245
|
-
default: withCtx(() => [
|
|
246
|
-
(openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(guardReactiveProps(unref(tabPaneComponent)?.props({
|
|
247
|
-
name: "page",
|
|
248
|
-
label: `页面 (${unref(pageGroups).length})`
|
|
249
|
-
}) || {})), {
|
|
250
|
-
default: withCtx(() => [createVNode(PageTab_default, {
|
|
251
|
-
list: unref(pageGroupsDisplay),
|
|
252
|
-
expanded: unref(expanded),
|
|
253
|
-
onToggle: unref(toggleGroup),
|
|
254
|
-
onGoto: onPageGoto,
|
|
255
|
-
onGotoInitial: onPageGotoInitial,
|
|
256
|
-
onDiffStep: onPageDiff,
|
|
257
|
-
onRevertStep: onPageRevert
|
|
258
|
-
}, null, 8, [
|
|
259
|
-
"list",
|
|
260
|
-
"expanded",
|
|
261
|
-
"onToggle"
|
|
262
|
-
])]),
|
|
263
|
-
_: 1
|
|
264
|
-
}, 16)),
|
|
265
|
-
!disabledDataSource.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 0 }, unref(tabPaneComponent)?.props({
|
|
266
|
-
name: "data-source",
|
|
267
|
-
label: `数据源 (${unref(dataSourceGroups).length})`
|
|
268
|
-
}) || {})), {
|
|
269
|
-
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
270
|
-
title: "数据源",
|
|
271
|
-
prefix: "ds",
|
|
272
|
-
buckets: unref(dataSourceGroupsByTarget),
|
|
273
|
-
expanded: unref(expanded),
|
|
274
|
-
"describe-group": unref(describeDataSourceGroup),
|
|
275
|
-
"describe-step": unref(describeDataSourceStep),
|
|
276
|
-
"is-step-diffable": isDataSourceStepDiffable,
|
|
277
|
-
"is-step-revertable": unref(isDataSourceStepRevertable),
|
|
278
|
-
onToggle: unref(toggleGroup),
|
|
279
|
-
onGoto: onDataSourceGoto,
|
|
280
|
-
onGotoInitial: onDataSourceGotoInitial,
|
|
281
|
-
onDiffStep: onDataSourceDiff,
|
|
282
|
-
onRevertStep: onDataSourceRevert
|
|
283
|
-
}, null, 8, [
|
|
284
|
-
"buckets",
|
|
285
|
-
"expanded",
|
|
286
|
-
"describe-group",
|
|
287
|
-
"describe-step",
|
|
288
|
-
"is-step-revertable",
|
|
289
|
-
"onToggle"
|
|
290
|
-
])]),
|
|
291
|
-
_: 1
|
|
292
|
-
}, 16)) : createCommentVNode("v-if", true),
|
|
293
|
-
!disabledCodeBlock.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 1 }, unref(tabPaneComponent)?.props({
|
|
294
|
-
name: "code-block",
|
|
295
|
-
label: `代码块 (${unref(codeBlockGroups).length})`
|
|
296
|
-
}) || {})), {
|
|
297
|
-
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
298
|
-
title: "代码块",
|
|
299
|
-
prefix: "cb",
|
|
300
|
-
buckets: unref(codeBlockGroupsByTarget),
|
|
301
|
-
expanded: unref(expanded),
|
|
302
|
-
"describe-group": unref(describeCodeBlockGroup),
|
|
303
|
-
"describe-step": unref(describeCodeBlockStep),
|
|
304
|
-
"is-step-diffable": isCodeBlockStepDiffable,
|
|
305
|
-
"is-step-revertable": unref(isCodeBlockStepRevertable),
|
|
306
|
-
onToggle: unref(toggleGroup),
|
|
307
|
-
onGoto: onCodeBlockGoto,
|
|
308
|
-
onGotoInitial: onCodeBlockGotoInitial,
|
|
309
|
-
onDiffStep: onCodeBlockDiff,
|
|
310
|
-
onRevertStep: onCodeBlockRevert
|
|
311
|
-
}, null, 8, [
|
|
312
|
-
"buckets",
|
|
313
|
-
"expanded",
|
|
314
|
-
"describe-group",
|
|
315
|
-
"describe-step",
|
|
316
|
-
"is-step-revertable",
|
|
317
|
-
"onToggle"
|
|
318
|
-
])]),
|
|
357
|
+
default: withCtx(() => [createVNode(unref(TMagicButton), {
|
|
358
|
+
class: "m-editor-history-list-close",
|
|
359
|
+
size: "small",
|
|
360
|
+
link: "",
|
|
361
|
+
onClick: _cache[0] || (_cache[0] = ($event) => visible.value = false)
|
|
362
|
+
}, {
|
|
363
|
+
icon: withCtx(() => [createVNode(Icon_default, { icon: unref(CloseIcon) }, null, 8, ["icon"])]),
|
|
319
364
|
_: 1
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
365
|
+
})]),
|
|
366
|
+
_: 1
|
|
367
|
+
}), createVNode(unref(TMagicTabs), {
|
|
368
|
+
modelValue: activeTab.value,
|
|
369
|
+
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => activeTab.value = $event),
|
|
370
|
+
class: "m-editor-history-list-tabs"
|
|
371
|
+
}, {
|
|
372
|
+
default: withCtx(() => [
|
|
373
|
+
(openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(guardReactiveProps(unref(tabPaneComponent)?.props({
|
|
374
|
+
name: "page",
|
|
375
|
+
label: `页面 (${unref(pageGroups).length})`
|
|
376
|
+
}) || {})), {
|
|
377
|
+
default: withCtx(() => [createVNode(PageTab_default, {
|
|
378
|
+
list: unref(pageGroupsDisplay),
|
|
379
|
+
expanded: unref(expanded),
|
|
380
|
+
marker: pageMarker.value,
|
|
381
|
+
onToggle: unref(toggleGroup),
|
|
382
|
+
onGoto: onPageGoto,
|
|
383
|
+
onGotoInitial: onPageGotoInitial,
|
|
384
|
+
onDiffStep: onPageDiff,
|
|
385
|
+
onRevertStep: onPageRevert,
|
|
386
|
+
onSelect: onPageSelect,
|
|
387
|
+
onClear: onPageClear
|
|
388
|
+
}, null, 8, [
|
|
389
|
+
"list",
|
|
390
|
+
"expanded",
|
|
391
|
+
"marker",
|
|
392
|
+
"onToggle"
|
|
393
|
+
])]),
|
|
394
|
+
_: 1
|
|
395
|
+
}, 16)),
|
|
396
|
+
!disabledDataSource.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 0 }, unref(tabPaneComponent)?.props({
|
|
397
|
+
name: "data-source",
|
|
398
|
+
label: `数据源 (${unref(dataSourceGroups).length})`
|
|
399
|
+
}) || {})), {
|
|
400
|
+
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
401
|
+
config: dataSourceConfig,
|
|
402
|
+
buckets: unref(dataSourceGroupsByTarget),
|
|
403
|
+
expanded: unref(expanded),
|
|
404
|
+
onToggle: unref(toggleGroup),
|
|
405
|
+
onGoto: onDataSourceGoto,
|
|
406
|
+
onGotoInitial: onDataSourceGotoInitial,
|
|
407
|
+
onDiffStep: onDataSourceDiff,
|
|
408
|
+
onRevertStep: onDataSourceRevert,
|
|
409
|
+
onClear: onDataSourceClear
|
|
410
|
+
}, null, 8, [
|
|
411
|
+
"buckets",
|
|
412
|
+
"expanded",
|
|
413
|
+
"onToggle"
|
|
414
|
+
])]),
|
|
415
|
+
_: 1
|
|
416
|
+
}, 16)) : createCommentVNode("v-if", true),
|
|
417
|
+
!disabledCodeBlock.value ? (openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), normalizeProps(mergeProps({ key: 1 }, unref(tabPaneComponent)?.props({
|
|
418
|
+
name: "code-block",
|
|
419
|
+
label: `代码块 (${unref(codeBlockGroups).length})`
|
|
420
|
+
}) || {})), {
|
|
421
|
+
default: withCtx(() => [createVNode(BucketTab_default, {
|
|
422
|
+
config: codeBlockConfig,
|
|
423
|
+
buckets: unref(codeBlockGroupsByTarget),
|
|
424
|
+
expanded: unref(expanded),
|
|
425
|
+
onToggle: unref(toggleGroup),
|
|
426
|
+
onGoto: onCodeBlockGoto,
|
|
427
|
+
onGotoInitial: onCodeBlockGotoInitial,
|
|
428
|
+
onDiffStep: onCodeBlockDiff,
|
|
429
|
+
onRevertStep: onCodeBlockRevert,
|
|
430
|
+
onClear: onCodeBlockClear
|
|
431
|
+
}, null, 8, [
|
|
432
|
+
"buckets",
|
|
433
|
+
"expanded",
|
|
434
|
+
"onToggle"
|
|
435
|
+
])]),
|
|
436
|
+
_: 1
|
|
437
|
+
}, 16)) : createCommentVNode("v-if", true),
|
|
438
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(extraTabs), (tab) => {
|
|
439
|
+
return openBlock(), createBlock(resolveDynamicComponent(unref(tabPaneComponent)?.component || "el-tab-pane"), mergeProps({ key: tab.name }, { ref_for: true }, unref(tabPaneComponent)?.props({
|
|
440
|
+
name: tab.name,
|
|
441
|
+
label: resolveTabLabel(tab)
|
|
442
|
+
}) || {}), {
|
|
443
|
+
default: withCtx(() => [(openBlock(), createBlock(resolveDynamicComponent(tab.component), mergeProps({ ref_for: true }, tab.props || {}, toHandlers(tab.listeners || {})), null, 16))]),
|
|
444
|
+
_: 2
|
|
445
|
+
}, 1040);
|
|
446
|
+
}), 128))
|
|
447
|
+
]),
|
|
448
|
+
_: 1
|
|
449
|
+
}, 8, ["modelValue"])])]),
|
|
331
450
|
_: 1
|
|
332
|
-
}, 8, ["
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
"extend-state"
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
451
|
+
}, 8, ["visible"]),
|
|
452
|
+
createVNode(HistoryDiffDialog_default, {
|
|
453
|
+
ref: "diffDialog",
|
|
454
|
+
"extend-state": unref(extendFormState)
|
|
455
|
+
}, null, 8, ["extend-state"]),
|
|
456
|
+
createVNode(HistoryDiffDialog_default, {
|
|
457
|
+
ref: "confirmDialog",
|
|
458
|
+
"is-confirm": true,
|
|
459
|
+
"extend-state": unref(extendFormState)
|
|
460
|
+
}, null, 8, ["extend-state"])
|
|
461
|
+
], 64);
|
|
340
462
|
};
|
|
341
463
|
}
|
|
342
464
|
});
|