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