@tmagic/editor 1.8.0-beta.7 → 1.8.0-beta.8

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.
Files changed (36) hide show
  1. package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +10 -6
  2. package/dist/es/index.js +6 -4
  3. package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +2 -2
  4. package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +38 -26
  5. package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +5 -1
  6. package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +158 -301
  7. package/dist/es/layouts/history-list/composables.js +23 -55
  8. package/dist/es/layouts/history-list/useHistoryList.js +56 -0
  9. package/dist/es/layouts/history-list/useHistoryRevert.js +304 -0
  10. package/dist/es/services/codeBlock.js +32 -28
  11. package/dist/es/services/dataSource.js +43 -34
  12. package/dist/es/services/editor.js +31 -26
  13. package/dist/es/services/history.js +268 -384
  14. package/dist/es/style.css +12 -0
  15. package/dist/es/utils/history.js +35 -47
  16. package/dist/style.css +12 -0
  17. package/dist/tmagic-editor.umd.cjs +3774 -3003
  18. package/package.json +7 -7
  19. package/src/components/CompareForm.vue +14 -6
  20. package/src/index.ts +2 -0
  21. package/src/layouts/NavMenu.vue +2 -2
  22. package/src/layouts/history-list/GroupRow.vue +10 -0
  23. package/src/layouts/history-list/HistoryDiffDialog.vue +6 -1
  24. package/src/layouts/history-list/HistoryListPanel.vue +53 -250
  25. package/src/layouts/history-list/PageTab.vue +4 -4
  26. package/src/layouts/history-list/composables.ts +52 -90
  27. package/src/layouts/history-list/useHistoryList.ts +60 -0
  28. package/src/layouts/history-list/useHistoryRevert.ts +400 -0
  29. package/src/services/codeBlock.ts +30 -29
  30. package/src/services/dataSource.ts +37 -37
  31. package/src/services/editor.ts +32 -29
  32. package/src/services/history.ts +340 -430
  33. package/src/theme/history-list-panel.scss +14 -0
  34. package/src/type.ts +174 -92
  35. package/src/utils/history.ts +52 -67
  36. package/types/index.d.ts +429 -281
@@ -0,0 +1,56 @@
1
+ import { useServices } from "../../hooks/use-services.js";
2
+ import { computed, reactive } from "vue";
3
+ //#region packages/editor/src/layouts/history-list/useHistoryList.ts
4
+ /**
5
+ * 历史记录面板共享逻辑:
6
+ * - 暴露三类历史的聚合数据(页面 / 数据源 / 代码块);
7
+ * - 提供折叠状态管理;
8
+ * - 提供操作描述文案生成器。
9
+ *
10
+ * 所有数据基于 historyService 的 reactive state 派生,自动跟随历史变化刷新。
11
+ */
12
+ var useHistoryList = () => {
13
+ const { editorService, historyService } = useServices();
14
+ /**
15
+ * 折叠状态:key 形如 `pg-${组内首步 index}` / `ds-${id}-${组内首步 index}` / `cb-${id}-${组内首步 index}`。
16
+ * 用组内首步的稳定 index(而非展示位置)作为 key,确保历史数据更新后已展开的分组状态保持不变。
17
+ * 合并组默认展开;仅当值为 `false` 时表示收起。
18
+ */
19
+ const expanded = reactive({});
20
+ const toggleGroup = (key) => {
21
+ expanded[key] = expanded[key] === false;
22
+ };
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
+ /** 页面 tab 倒序展示(最新一组在最上面)。 */
27
+ const pageGroupsDisplay = computed(() => pageGroups.value.slice().reverse());
28
+ /**
29
+ * 把按时间正序的 group 列表,再按 id 聚拢成 bucket(同 id 的所有分组放一起)。
30
+ * 每个 bucket 内部仍然按时间倒序展示(最近的操作最先看到)。
31
+ */
32
+ const groupByTarget = (groups) => {
33
+ const map = /* @__PURE__ */ new Map();
34
+ groups.forEach((g) => {
35
+ const list = map.get(g.id) ?? [];
36
+ list.push(g);
37
+ map.set(g.id, list);
38
+ });
39
+ return Array.from(map.entries()).map(([id, gs]) => ({
40
+ id,
41
+ groups: gs.slice().reverse()
42
+ }));
43
+ };
44
+ return {
45
+ expanded,
46
+ toggleGroup,
47
+ pageGroups,
48
+ dataSourceGroups,
49
+ codeBlockGroups,
50
+ pageGroupsDisplay,
51
+ dataSourceGroupsByTarget: computed(() => groupByTarget(dataSourceGroups.value)),
52
+ codeBlockGroupsByTarget: computed(() => groupByTarget(codeBlockGroups.value))
53
+ };
54
+ };
55
+ //#endregion
56
+ export { useHistoryList };
@@ -0,0 +1,304 @@
1
+ import { confirmHistoryAction } from "./composables.js";
2
+ import { tMagicMessage } from "@tmagic/design";
3
+ import { createApp, getCurrentInstance } from "vue";
4
+ //#region packages/editor/src/layouts/history-list/useHistoryRevert.ts
5
+ /**
6
+ * 构造差异弹窗入参:仅 update(前后值都存在)可对比。
7
+ * - 页面(无 id):在全部分组中按 index 定位 step,目标 id 取自快照;
8
+ * - 数据源 / 代码块(带 id):先匹配分组 id 再按 index 定位。
9
+ * 无可对比内容(多节点 / add / remove)或定位不到时返回 null。
10
+ */
11
+ var buildDiffPayload = (source, index, id) => {
12
+ for (const group of source.groups()) {
13
+ if (id !== void 0 && group.id !== id) continue;
14
+ const step = group.steps.find((s) => s.index === index)?.step;
15
+ if (!step) continue;
16
+ const oldSchema = step.diff?.[0]?.oldSchema;
17
+ const newSchema = step.diff?.[0]?.newSchema;
18
+ if (!oldSchema || !newSchema) return null;
19
+ const targetId = id ?? newSchema.id ?? oldSchema.id;
20
+ const type = source.resolveType?.(newSchema, oldSchema);
21
+ return {
22
+ category: source.category,
23
+ ...type !== void 0 ? { type } : {},
24
+ lastValue: oldSchema,
25
+ value: newSchema,
26
+ currentValue: (targetId !== void 0 ? source.getCurrent(targetId) : null) || null,
27
+ targetLabel: source.resolveLabel(newSchema, oldSchema, targetId),
28
+ id: targetId
29
+ };
30
+ }
31
+ return null;
32
+ };
33
+ /**
34
+ * 按需动态 import 并挂载一个游离的 HistoryDiffDialog,返回其实例与清理函数。
35
+ * 通过继承 appContext 复用全局组件 / 指令 / provide / 插件(Element Plus、@tmagic/form 字段组件等),
36
+ * 弹窗组件动态 import,避免拖累其它消费者。供「确认回滚」与「查看差异」两种交互共用。
37
+ */
38
+ var mountHistoryDiffDialog = async (options) => {
39
+ const { default: historyDiffDialog } = await import("./HistoryDiffDialog.js");
40
+ const container = document.createElement("div");
41
+ container.style.display = "none";
42
+ document.body.appendChild(container);
43
+ const app = createApp(historyDiffDialog, {
44
+ services: options.services,
45
+ isConfirm: options.isConfirm,
46
+ extendState: options.extendState,
47
+ loadConfig: options.loadConfig,
48
+ selfDiffFieldTypes: options.selfDiffFieldTypes,
49
+ onClose: options.onClose
50
+ });
51
+ if (options.appContext) Object.assign(app._context, options.appContext);
52
+ const instance = app.mount(container);
53
+ const destroy = () => {
54
+ setTimeout(() => {
55
+ try {
56
+ app.unmount();
57
+ } catch {}
58
+ container.parentNode?.removeChild(container);
59
+ }, 300);
60
+ };
61
+ return {
62
+ instance,
63
+ destroy
64
+ };
65
+ };
66
+ /**
67
+ * 动态挂载一个「确认回滚」模式的 HistoryDiffDialog,等待用户确认:
68
+ * - 用户点「确定回滚」resolve(true),取消 / 关闭 resolve(false);
69
+ * - 确认流程结束后自动卸载。
70
+ */
71
+ var confirmRevertWithDiffDialog = async (payload, options) => {
72
+ const { instance, destroy } = await mountHistoryDiffDialog({
73
+ ...options,
74
+ isConfirm: true
75
+ });
76
+ try {
77
+ return await instance.confirm(payload);
78
+ } finally {
79
+ destroy();
80
+ }
81
+ };
82
+ /**
83
+ * 动态挂载一个「查看差异」模式(只读)的 HistoryDiffDialog 并打开:
84
+ * 弹窗保持打开直到用户关闭,关闭(close 事件)后自动卸载并清理容器。
85
+ */
86
+ var viewHistoryDiffDialog = async (payload, options) => {
87
+ const handle = {};
88
+ const { instance, destroy } = await mountHistoryDiffDialog({
89
+ ...options,
90
+ isConfirm: false,
91
+ onClose: () => handle.destroy?.()
92
+ });
93
+ handle.destroy = destroy;
94
+ instance.open(payload);
95
+ };
96
+ /**
97
+ * 历史记录「单步回滚」与「查看差异」的完整交互流程,供历史面板与业务方共用。
98
+ *
99
+ * 单步回滚(类 git revert):
100
+ * 1. 前置校验:目标数据已被删除(update 写回目标 / 页面 remove 的原父容器缺失)时给出「回滚失败」提示并中止;
101
+ * 2. 二次确认:可差异对比的步骤(单实体 update)弹出差异确认弹窗,其余步骤弹普通二次确认框;
102
+ * 3. 用户确认后执行对应 service 的 revert(页面 / 数据源 / 代码块)。
103
+ *
104
+ * 查看差异:可差异对比的步骤动态挂载只读 HistoryDiffDialog 展示前后值差异。
105
+ *
106
+ * 上述弹窗均按需动态挂载 HistoryDiffDialog 实现,业务方无需自行挂载任何弹窗。
107
+ *
108
+ * 返回的能力分三组:
109
+ * - 内置三类(页面 / 数据源 / 代码块):`onPageRevert` / `onDataSourceRevert` / `onCodeBlockRevert` 单步回滚,
110
+ * `onPageDiff` / `onDataSourceDiff` / `onCodeBlockDiff` 查看差异,及配套的 `buildXxxDiffPayload` / `isXxxRevertTargetMissing`;
111
+ * - 业务自有历史(如管理台「模块」):`confirmAndRevert` / `viewDiff` 复用同一套交互流程,由业务方自行构造差异入参;
112
+ * 即上述内置三类本质上是它们各自预置好 payload 构造与 service.revert 的特例。
113
+ *
114
+ * 业务方可在拿到 Editor 实例暴露的 `services` 后直接 import 调用:
115
+ *
116
+ * ```ts
117
+ * import { useHistoryRevert } from '@tmagic/editor';
118
+ *
119
+ * const { onPageRevert, onPageDiff } = useHistoryRevert(editorRef.value); // editorRef.value 即 Editor 暴露的 services
120
+ * await onPageRevert(index); // 弹出差异 / 二次确认弹窗后回滚
121
+ * onPageDiff(index); // 弹出只读差异弹窗查看前后值差异
122
+ * ```
123
+ */
124
+ var useHistoryRevert = (services, options = {}) => {
125
+ const { editorService, dataSourceService, codeBlockService, historyService } = services;
126
+ const appContext = options.appContext ?? getCurrentInstance()?.appContext ?? null;
127
+ const { extendState } = options;
128
+ /** 目标数据已被删除、无法回滚时的统一提示。 */
129
+ const showRevertTargetMissing = () => {
130
+ tMagicMessage.error("回滚失败:该记录对应的数据已被删除");
131
+ };
132
+ /**
133
+ * 「回滚」二次确认:新增 / 删除 / 多节点更新等无法做差异对比的步骤,
134
+ * 不弹差异弹窗,改用一个普通确认框替代「确定回滚」按钮,避免点击后无任何提示直接执行。
135
+ * 用户取消时返回 false,调用方据此中止回滚。
136
+ */
137
+ const confirmRevert = () => confirmHistoryAction("确定回滚该步骤吗?回滚会将该操作作为一条新记录反向应用(新增将被删除、删除将被还原),不影响后续历史记录。");
138
+ /**
139
+ * 「回滚」统一确认入口:可差异对比的步骤动态挂载 HistoryDiffDialog 走差异确认弹窗,
140
+ * 无法对比的步骤(add / remove / 多节点更新)回退到普通二次确认框。
141
+ * `extra` 供业务自有历史(如模块)透传自定义表单配置加载等渲染入参。
142
+ */
143
+ const runRevert = (payload, extra) => {
144
+ if (payload) return confirmRevertWithDiffDialog(payload, {
145
+ appContext,
146
+ extendState,
147
+ services,
148
+ ...extra
149
+ });
150
+ return confirmRevert();
151
+ };
152
+ const buildPageDiffPayload = (index) => buildDiffPayload({
153
+ category: "node",
154
+ groups: () => historyService.getHistoryGroups("page", editorService.get("page")?.id),
155
+ getCurrent: (id) => editorService.getNodeById(id),
156
+ resolveType: (n, o) => n.type || o.type || "",
157
+ resolveLabel: (n, o) => n.name || o.name || n.type || o.type || ""
158
+ }, index);
159
+ const buildDataSourceDiffPayload = (id, index) => buildDiffPayload({
160
+ category: "data-source",
161
+ groups: () => historyService.getHistoryGroups("dataSource"),
162
+ getCurrent: (id) => dataSourceService.getDataSourceById(`${id}`),
163
+ resolveType: (n, o) => n.type || o.type || "base",
164
+ resolveLabel: (n, o, id) => n.title || o.title || `${id}`
165
+ }, index, id);
166
+ const buildCodeBlockDiffPayload = (id, index) => buildDiffPayload({
167
+ category: "code-block",
168
+ groups: () => historyService.getHistoryGroups("codeBlock"),
169
+ getCurrent: (id) => codeBlockService.getCodeContentById(id),
170
+ resolveLabel: (n, o, id) => n.name || o.name || `${id}`
171
+ }, index, id);
172
+ /**
173
+ * 回滚前置校验:若该历史步骤回滚所依赖的目标数据已被删除,则无法回滚。
174
+ * - update(把旧值写回):被修改的目标必须仍存在;
175
+ * - 页面 remove(还原被删节点):被删节点的原父容器必须仍存在,否则无处插回;
176
+ * add(回滚即删除)即使目标已不在,也已达成「删除」目的,不视为失败。
177
+ */
178
+ const isPageRevertTargetMissing = (index) => {
179
+ const step = historyService.getStepList("page", editorService.get("page")?.id)[index]?.step;
180
+ if (!step) return false;
181
+ if (step.opType === "update") return (step.diff ?? []).some((item) => {
182
+ const id = item.newSchema?.id ?? item.oldSchema?.id;
183
+ return id !== void 0 && !editorService.getNodeById(id, false);
184
+ });
185
+ if (step.opType === "remove") return (step.diff ?? []).some((item) => item.parentId !== void 0 && !editorService.getNodeById(item.parentId, false));
186
+ return false;
187
+ };
188
+ /** 数据源 update 步骤回滚时,对应数据源必须仍存在(已删除则无处写回旧值)。 */
189
+ const isDataSourceRevertTargetMissing = (id, index) => {
190
+ const step = historyService.getStepList("dataSource", id)[index]?.step;
191
+ return Boolean(step?.opType === "update" && !dataSourceService.getDataSourceById(`${id}`));
192
+ };
193
+ /** 代码块 update 步骤回滚时,对应代码块必须仍存在(已删除则无处写回旧值)。 */
194
+ const isCodeBlockRevertTargetMissing = (id, index) => {
195
+ const step = historyService.getStepList("codeBlock", id)[index]?.step;
196
+ return Boolean(step?.opType === "update" && !codeBlockService.getCodeContentById(id));
197
+ };
198
+ const onPageRevert = (index) => {
199
+ if (isPageRevertTargetMissing(index)) {
200
+ showRevertTargetMissing();
201
+ return Promise.resolve(null);
202
+ }
203
+ return runRevert(buildPageDiffPayload(index)).then((result) => result ? editorService.revertPageStep(index) : null);
204
+ };
205
+ const onDataSourceRevert = (id, index) => {
206
+ if (isDataSourceRevertTargetMissing(id, index)) {
207
+ showRevertTargetMissing();
208
+ return Promise.resolve(null);
209
+ }
210
+ return runRevert(buildDataSourceDiffPayload(id, index)).then((result) => result ? dataSourceService.revert(id, index) : null);
211
+ };
212
+ const onCodeBlockRevert = (id, index) => {
213
+ if (isCodeBlockRevertTargetMissing(id, index)) {
214
+ showRevertTargetMissing();
215
+ return Promise.resolve(null);
216
+ }
217
+ return runRevert(buildCodeBlockDiffPayload(id, index)).then((result) => result ? codeBlockService.revert(id, index) : null);
218
+ };
219
+ /**
220
+ * 「查看差异」:可差异对比的步骤(单实体 update)动态挂载只读 HistoryDiffDialog 展示前后值差异,
221
+ * 无可对比内容(add / remove / 多节点更新)时不弹窗、静默返回。
222
+ */
223
+ const onPageDiff = (index) => {
224
+ const payload = buildPageDiffPayload(index);
225
+ if (payload) return viewHistoryDiffDialog(payload, {
226
+ appContext,
227
+ extendState,
228
+ services
229
+ });
230
+ };
231
+ const onDataSourceDiff = (id, index) => {
232
+ const payload = buildDataSourceDiffPayload(id, index);
233
+ if (payload) return viewHistoryDiffDialog(payload, {
234
+ appContext,
235
+ extendState,
236
+ services
237
+ });
238
+ };
239
+ const onCodeBlockDiff = (id, index) => {
240
+ const payload = buildCodeBlockDiffPayload(id, index);
241
+ if (payload) return viewHistoryDiffDialog(payload, {
242
+ appContext,
243
+ extendState,
244
+ services
245
+ });
246
+ };
247
+ /**
248
+ * 业务自有历史(如管理台「模块」)的「单步回滚」统一入口:
249
+ * 复用与页面/数据源/代码块一致的「目标校验 → 差异/二次确认弹窗 → 反向回滚」流程,
250
+ * 内置三类只是它的特例(各自预置了 buildXxxDiffPayload + service.revert)。
251
+ *
252
+ * 用户取消或前置校验未过时返回 null,确认并执行回滚后返回 `revert()` 的结果。
253
+ *
254
+ * ```ts
255
+ * await confirmAndRevert({
256
+ * diffPayload: oldSchema && newSchema ? { category: 'module', lastValue: oldSchema, value: newSchema, ... } : null,
257
+ * loadConfig: (ctx) => loadModFormConfig(modTypeId, values),
258
+ * selfDiffFieldTypes: ['mod-cond'],
259
+ * revert: () => moduleHistoryStore.revert(id, index),
260
+ * });
261
+ * ```
262
+ */
263
+ const confirmAndRevert = async (revertOptions) => {
264
+ if (revertOptions.isTargetMissing?.()) {
265
+ showRevertTargetMissing();
266
+ return null;
267
+ }
268
+ if (!await runRevert(revertOptions.diffPayload ?? null, {
269
+ loadConfig: revertOptions.loadConfig,
270
+ selfDiffFieldTypes: revertOptions.selfDiffFieldTypes
271
+ })) return null;
272
+ return await revertOptions.revert();
273
+ };
274
+ /**
275
+ * 业务自有历史的「查看差异」统一入口:传入自行构造的差异入参即弹出只读差异弹窗,
276
+ * 可透传 `loadConfig` / `selfDiffFieldTypes`。payload 为 null(不可对比)时静默返回。
277
+ */
278
+ const viewDiff = (payload, extra) => {
279
+ if (payload) return viewHistoryDiffDialog(payload, {
280
+ appContext,
281
+ extendState,
282
+ services,
283
+ ...extra
284
+ });
285
+ };
286
+ return {
287
+ onPageRevert,
288
+ onDataSourceRevert,
289
+ onCodeBlockRevert,
290
+ onPageDiff,
291
+ onDataSourceDiff,
292
+ onCodeBlockDiff,
293
+ buildPageDiffPayload,
294
+ buildDataSourceDiffPayload,
295
+ buildCodeBlockDiffPayload,
296
+ isPageRevertTargetMissing,
297
+ isDataSourceRevertTargetMissing,
298
+ isCodeBlockRevertTargetMissing,
299
+ confirmAndRevert,
300
+ viewDiff
301
+ };
302
+ };
303
+ //#endregion
304
+ export { useHistoryRevert };
@@ -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) this.lastPushedHistoryId = history_default.pushCodeBlock(id, {
125
- oldContent,
126
- newContent,
127
- changeRecords,
128
- historyDescription,
129
- source: historySource
130
- })?.uuid ?? null;
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 oldContent = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
218
+ const oldValue = currentDsl[id] ? cloneDeep$1(currentDsl[id]) : null;
216
219
  delete currentDsl[id];
217
- if (oldContent && !doNotPushHistory) {
218
- const uuid = history_default.pushCodeBlock(id, {
219
- oldContent,
220
- newContent: null,
220
+ if (oldValue && !doNotPushHistory) {
221
+ const step = createStackStep(id, {
222
+ oldValue,
223
+ newValue: null,
221
224
  historyDescription,
222
225
  source: historySource
223
- })?.uuid;
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.undoCodeBlock(id);
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.redoCodeBlock(id);
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.canUndoCodeBlock(id);
306
+ return history_default.canUndo("codeBlock", id);
303
307
  }
304
308
  /** 是否可对指定代码块重做。 */
305
309
  canRedo(id) {
306
- return history_default.canRedoCodeBlock(id);
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.getCodeBlockCursor(id);
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.getCodeBlockStepList(id)[index];
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.findCodeBlockStepLocationByUuid(uuid);
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.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
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.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
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.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
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.getCodeBlockStepList(id).slice(-1)[0]?.step ?? null;
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 });