@tmagic/editor 1.8.0-beta.7 → 1.8.0-manmanyu.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.
- package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +13 -3
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +6 -5
- package/dist/es/components/ContentMenu.vue_vue_type_script_setup_true_lang.js +11 -4
- package/dist/es/components/FloatingBox.vue_vue_type_script_setup_true_lang.js +9 -4
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +68 -43
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/fields/CondOpSelect.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +10 -7
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceInput.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +4 -1
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/DisplayConds.vue_vue_type_script_setup_true_lang.js +8 -2
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +101 -64
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/PageFragmentSelect.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/StyleSetter/Index.vue_vue_type_script_setup_true_lang.js +5 -4
- package/dist/es/fields/StyleSetter/components/BackgroundPosition.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/fields/StyleSetter/components/Border.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/StyleSetter/icons/align-items/Center.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/FlexEnd.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/FlexStart.js +31 -0
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceAround.js +50 -0
- package/dist/es/fields/StyleSetter/icons/align-items/SpaceBetween.js +50 -0
- package/dist/es/fields/StyleSetter/icons/background-repeat/NoRepeat.js +6 -6
- package/dist/es/fields/StyleSetter/icons/background-repeat/Repeat.js +5 -2
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatX.js +28 -5
- package/dist/es/fields/StyleSetter/icons/background-repeat/RepeatY.js +31 -5
- package/dist/es/fields/StyleSetter/icons/flex-direction/Column.js +10 -2
- package/dist/es/fields/StyleSetter/icons/flex-direction/ColumnReverse.js +10 -2
- package/dist/es/fields/StyleSetter/icons/flex-direction/Row.js +10 -2
- package/dist/es/fields/StyleSetter/icons/flex-direction/RowReverse.js +10 -2
- package/dist/es/fields/StyleSetter/icons/justify-content/Center.js +16 -2
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexEnd.js +18 -2
- package/dist/es/fields/StyleSetter/icons/justify-content/FlexStart.js +18 -2
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceAround.js +36 -2
- package/dist/es/fields/StyleSetter/icons/justify-content/SpaceBetween.js +32 -2
- package/dist/es/fields/StyleSetter/pro/Background.vue_vue_type_script_setup_true_lang.js +11 -6
- package/dist/es/fields/StyleSetter/pro/Font.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/StyleSetter/pro/Layout.vue_vue_type_script_setup_true_lang.js +82 -46
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +4 -1
- package/dist/es/icons/DatasourceIcon.js +17 -0
- package/dist/es/index.js +5 -3
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +14 -10
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +38 -26
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +5 -1
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +135 -288
- package/dist/es/layouts/history-list/composables.js +23 -55
- package/dist/es/layouts/history-list/useHistoryList.js +56 -0
- package/dist/es/layouts/history-list/useHistoryRevert.js +304 -0
- package/dist/es/services/history.js +18 -1
- package/dist/es/style.css +306 -37
- package/dist/es/utils/const.js +1 -1
- package/dist/es/utils/props.js +137 -31
- package/dist/style.css +306 -37
- package/dist/themes/magic-admin.css +2316 -0
- package/dist/tmagic-editor.umd.cjs +4427 -2871
- package/package.json +7 -7
- package/src/Editor.vue +13 -1
- package/src/components/CompareForm.vue +14 -6
- package/src/components/ContentMenu.vue +10 -2
- package/src/components/FloatingBox.vue +13 -2
- package/src/editorProps.ts +9 -0
- package/src/fields/CodeSelect.vue +51 -40
- package/src/fields/CodeSelectCol.vue +1 -0
- package/src/fields/DataSourceFieldSelect/Index.vue +14 -5
- package/src/fields/DisplayConds.vue +4 -1
- package/src/fields/EventSelect.vue +58 -32
- package/src/fields/StyleSetter/Index.vue +1 -4
- package/src/fields/StyleSetter/components/Border.vue +1 -1
- package/src/fields/StyleSetter/icons/align-items/Center.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/FlexEnd.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/FlexStart.vue +19 -0
- package/src/fields/StyleSetter/icons/align-items/SpaceAround.vue +34 -0
- package/src/fields/StyleSetter/icons/align-items/SpaceBetween.vue +34 -0
- package/src/fields/StyleSetter/icons/align-items/index copy.ts +5 -0
- package/src/fields/StyleSetter/icons/align-items/index.ts +5 -0
- package/src/fields/StyleSetter/icons/background-repeat/NoRepeat.vue +20 -4
- package/src/fields/StyleSetter/icons/background-repeat/Repeat.vue +10 -28
- package/src/fields/StyleSetter/icons/background-repeat/RepeatX.vue +4 -5
- package/src/fields/StyleSetter/icons/background-repeat/RepeatY.vue +4 -5
- package/src/fields/StyleSetter/icons/flex-direction/Column.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/ColumnReverse.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/Row.vue +4 -3
- package/src/fields/StyleSetter/icons/flex-direction/RowReverse.vue +4 -3
- package/src/fields/StyleSetter/icons/justify-content/Center.vue +5 -2
- package/src/fields/StyleSetter/icons/justify-content/FlexEnd.vue +15 -2
- package/src/fields/StyleSetter/icons/justify-content/FlexStart.vue +15 -2
- package/src/fields/StyleSetter/icons/justify-content/SpaceAround.vue +28 -3
- package/src/fields/StyleSetter/icons/justify-content/SpaceBetween.vue +28 -2
- package/src/fields/StyleSetter/pro/Background.vue +11 -5
- package/src/fields/StyleSetter/pro/Font.vue +3 -3
- package/src/fields/StyleSetter/pro/Layout.vue +105 -28
- package/src/fields/UISelect.vue +1 -1
- package/src/icons/DatasourceIcon.vue +7 -0
- package/src/index.ts +2 -0
- package/src/layouts/Framework.vue +7 -1
- package/src/layouts/NavMenu.vue +2 -2
- package/src/layouts/history-list/GroupRow.vue +10 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +6 -1
- package/src/layouts/history-list/HistoryListPanel.vue +53 -250
- package/src/layouts/history-list/PageTab.vue +4 -4
- package/src/layouts/history-list/composables.ts +52 -90
- package/src/layouts/history-list/useHistoryList.ts +60 -0
- package/src/layouts/history-list/useHistoryRevert.ts +400 -0
- package/src/services/codeBlock.ts +30 -29
- package/src/services/dataSource.ts +37 -37
- package/src/services/editor.ts +32 -29
- package/src/services/history.ts +340 -430
- package/src/theme/code-block.scss +37 -0
- package/src/theme/common/var.scss +1 -1
- package/src/theme/component-list-panel.scss +2 -2
- package/src/theme/data-source-field.scss +4 -0
- package/src/theme/display-conds.scss +11 -0
- package/src/theme/event.scss +55 -1
- package/src/theme/history-list-panel.scss +23 -9
- package/src/theme/props-panel.scss +2 -1
- package/src/theme/style-setter/border.scss +14 -5
- package/src/theme/theme.scss +1 -0
- package/src/theme/themes/magic-admin/index.scss +125 -0
- package/src/type.ts +174 -92
- package/src/utils/const.ts +2 -1
- package/src/utils/history.ts +52 -67
- package/src/utils/props.ts +138 -9
- package/types/index.d.ts +156 -13
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { computed, reactive } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { useServices } from '@editor/hooks/use-services';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 历史记录面板共享逻辑:
|
|
7
|
+
* - 暴露三类历史的聚合数据(页面 / 数据源 / 代码块);
|
|
8
|
+
* - 提供折叠状态管理;
|
|
9
|
+
* - 提供操作描述文案生成器。
|
|
10
|
+
*
|
|
11
|
+
* 所有数据基于 historyService 的 reactive state 派生,自动跟随历史变化刷新。
|
|
12
|
+
*/
|
|
13
|
+
export const useHistoryList = () => {
|
|
14
|
+
const { editorService, historyService } = useServices();
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 折叠状态:key 形如 `pg-${组内首步 index}` / `ds-${id}-${组内首步 index}` / `cb-${id}-${组内首步 index}`。
|
|
18
|
+
* 用组内首步的稳定 index(而非展示位置)作为 key,确保历史数据更新后已展开的分组状态保持不变。
|
|
19
|
+
* 合并组默认展开;仅当值为 `false` 时表示收起。
|
|
20
|
+
*/
|
|
21
|
+
const expanded = reactive<Record<string, boolean>>({});
|
|
22
|
+
const toggleGroup = (key: string) => {
|
|
23
|
+
expanded[key] = expanded[key] === false;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const pageGroups = computed(() => historyService.getHistoryGroups('page', editorService.get('page')?.id));
|
|
27
|
+
const dataSourceGroups = computed(() => historyService.getHistoryGroups('dataSource'));
|
|
28
|
+
const codeBlockGroups = computed(() => historyService.getHistoryGroups('codeBlock'));
|
|
29
|
+
|
|
30
|
+
/** 页面 tab 倒序展示(最新一组在最上面)。 */
|
|
31
|
+
const pageGroupsDisplay = computed(() => pageGroups.value.slice().reverse());
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 把按时间正序的 group 列表,再按 id 聚拢成 bucket(同 id 的所有分组放一起)。
|
|
35
|
+
* 每个 bucket 内部仍然按时间倒序展示(最近的操作最先看到)。
|
|
36
|
+
*/
|
|
37
|
+
const groupByTarget = <G extends { id: string | number }>(groups: G[]) => {
|
|
38
|
+
const map = new Map<string | number, G[]>();
|
|
39
|
+
groups.forEach((g) => {
|
|
40
|
+
const list = map.get(g.id) ?? [];
|
|
41
|
+
list.push(g);
|
|
42
|
+
map.set(g.id, list);
|
|
43
|
+
});
|
|
44
|
+
return Array.from(map.entries()).map(([id, gs]) => ({ id, groups: gs.slice().reverse() }));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const dataSourceGroupsByTarget = computed(() => groupByTarget(dataSourceGroups.value));
|
|
48
|
+
const codeBlockGroupsByTarget = computed(() => groupByTarget(codeBlockGroups.value));
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
expanded,
|
|
52
|
+
toggleGroup,
|
|
53
|
+
pageGroups,
|
|
54
|
+
dataSourceGroups,
|
|
55
|
+
codeBlockGroups,
|
|
56
|
+
pageGroupsDisplay,
|
|
57
|
+
dataSourceGroupsByTarget,
|
|
58
|
+
codeBlockGroupsByTarget,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { createApp, getCurrentInstance } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ConfirmAndRevertOptions,
|
|
7
|
+
CustomDiffFormOptions,
|
|
8
|
+
DiffDialogPayload,
|
|
9
|
+
Services,
|
|
10
|
+
UseHistoryRevertOptions,
|
|
11
|
+
} from '@editor/type';
|
|
12
|
+
|
|
13
|
+
import { confirmHistoryAction } from './composables';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 三类历史(页面 / 数据源 / 代码块)差异弹窗入参的构造差异,收敛为一份配置:
|
|
17
|
+
* 仅「分组来源、当前值读取、类型 / 展示名提取」不同,定位 step、校验前后值、组装 payload 的流程共用。
|
|
18
|
+
*/
|
|
19
|
+
interface DiffPayloadSource {
|
|
20
|
+
/** 表单类别:节点 / 数据源 / 代码块。 */
|
|
21
|
+
category: DiffDialogPayload['category'];
|
|
22
|
+
/** 该类别按时间正序的历史分组列表(含已撤销)。 */
|
|
23
|
+
groups: () => { id?: string | number; steps: { index: number; step: { diff?: any[] } }[] }[];
|
|
24
|
+
/** 读取目标当前实际值,用于「与当前对比」;不存在时返回空即禁用对比。 */
|
|
25
|
+
getCurrent: (_id: string | number) => Record<string, any> | null | undefined;
|
|
26
|
+
/** 由新/旧快照提取展示名(含各自的兜底,如节点回退 type、数据源 / 代码块回退 id)。 */
|
|
27
|
+
resolveLabel: (_newSchema: Record<string, any>, _oldSchema: Record<string, any>, _id: string | number) => string;
|
|
28
|
+
/** 由新/旧快照提取类型;代码块无 type 字段则不传。 */
|
|
29
|
+
resolveType?: (_newSchema: Record<string, any>, _oldSchema: Record<string, any>) => string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 构造差异弹窗入参:仅 update(前后值都存在)可对比。
|
|
34
|
+
* - 页面(无 id):在全部分组中按 index 定位 step,目标 id 取自快照;
|
|
35
|
+
* - 数据源 / 代码块(带 id):先匹配分组 id 再按 index 定位。
|
|
36
|
+
* 无可对比内容(多节点 / add / remove)或定位不到时返回 null。
|
|
37
|
+
*/
|
|
38
|
+
const buildDiffPayload = (source: DiffPayloadSource, index: number, id?: string | number): DiffDialogPayload | null => {
|
|
39
|
+
for (const group of source.groups()) {
|
|
40
|
+
if (id !== undefined && group.id !== id) continue;
|
|
41
|
+
const step = group.steps.find((s) => s.index === index)?.step;
|
|
42
|
+
if (!step) continue;
|
|
43
|
+
const oldSchema = step.diff?.[0]?.oldSchema as Record<string, any> | undefined;
|
|
44
|
+
const newSchema = step.diff?.[0]?.newSchema as Record<string, any> | undefined;
|
|
45
|
+
if (!oldSchema || !newSchema) return null;
|
|
46
|
+
const targetId = id ?? newSchema.id ?? oldSchema.id;
|
|
47
|
+
const type = source.resolveType?.(newSchema, oldSchema);
|
|
48
|
+
return {
|
|
49
|
+
category: source.category,
|
|
50
|
+
...(type !== undefined ? { type } : {}),
|
|
51
|
+
lastValue: oldSchema,
|
|
52
|
+
value: newSchema,
|
|
53
|
+
currentValue: (targetId !== undefined ? source.getCurrent(targetId) : null) || null,
|
|
54
|
+
targetLabel: source.resolveLabel(newSchema, oldSchema, targetId),
|
|
55
|
+
id: targetId,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
interface MountedDiffDialog {
|
|
62
|
+
instance: {
|
|
63
|
+
open: (_payload: DiffDialogPayload) => void;
|
|
64
|
+
confirm: (_payload: DiffDialogPayload) => Promise<boolean>;
|
|
65
|
+
};
|
|
66
|
+
/** 卸载弹窗并清理容器(延迟以等待关闭过渡播放完成,避免动画被强行打断)。 */
|
|
67
|
+
destroy: () => void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 按需动态 import 并挂载一个游离的 HistoryDiffDialog,返回其实例与清理函数。
|
|
72
|
+
* 通过继承 appContext 复用全局组件 / 指令 / provide / 插件(Element Plus、@tmagic/form 字段组件等),
|
|
73
|
+
* 弹窗组件动态 import,避免拖累其它消费者。供「确认回滚」与「查看差异」两种交互共用。
|
|
74
|
+
*/
|
|
75
|
+
const mountHistoryDiffDialog = async (
|
|
76
|
+
options: Pick<UseHistoryRevertOptions, 'appContext' | 'extendState'> &
|
|
77
|
+
CustomDiffFormOptions & {
|
|
78
|
+
services: Pick<Services, 'editorService' | 'dataSourceService' | 'codeBlockService' | 'historyService'>;
|
|
79
|
+
isConfirm?: boolean;
|
|
80
|
+
onClose?: () => void;
|
|
81
|
+
},
|
|
82
|
+
): Promise<MountedDiffDialog> => {
|
|
83
|
+
const { default: historyDiffDialog } = await import('./HistoryDiffDialog.vue');
|
|
84
|
+
|
|
85
|
+
const container = document.createElement('div');
|
|
86
|
+
container.style.display = 'none';
|
|
87
|
+
document.body.appendChild(container);
|
|
88
|
+
|
|
89
|
+
const app = createApp(historyDiffDialog, {
|
|
90
|
+
services: options.services,
|
|
91
|
+
isConfirm: options.isConfirm,
|
|
92
|
+
extendState: options.extendState,
|
|
93
|
+
loadConfig: options.loadConfig,
|
|
94
|
+
selfDiffFieldTypes: options.selfDiffFieldTypes,
|
|
95
|
+
onClose: options.onClose,
|
|
96
|
+
});
|
|
97
|
+
if (options.appContext) {
|
|
98
|
+
Object.assign(app._context, options.appContext);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const instance = app.mount(container) as unknown as MountedDiffDialog['instance'];
|
|
102
|
+
|
|
103
|
+
const destroy = () => {
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
try {
|
|
106
|
+
app.unmount();
|
|
107
|
+
} catch {
|
|
108
|
+
// ignore
|
|
109
|
+
}
|
|
110
|
+
container.parentNode?.removeChild(container);
|
|
111
|
+
}, 300);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return { instance, destroy };
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 动态挂载一个「确认回滚」模式的 HistoryDiffDialog,等待用户确认:
|
|
119
|
+
* - 用户点「确定回滚」resolve(true),取消 / 关闭 resolve(false);
|
|
120
|
+
* - 确认流程结束后自动卸载。
|
|
121
|
+
*/
|
|
122
|
+
const confirmRevertWithDiffDialog = async (
|
|
123
|
+
payload: DiffDialogPayload,
|
|
124
|
+
options: Pick<UseHistoryRevertOptions, 'appContext' | 'extendState'> &
|
|
125
|
+
CustomDiffFormOptions & {
|
|
126
|
+
services: Pick<Services, 'editorService' | 'dataSourceService' | 'codeBlockService' | 'historyService'>;
|
|
127
|
+
},
|
|
128
|
+
): Promise<boolean> => {
|
|
129
|
+
const { instance, destroy } = await mountHistoryDiffDialog({
|
|
130
|
+
...options,
|
|
131
|
+
isConfirm: true,
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
return await instance.confirm(payload);
|
|
135
|
+
} finally {
|
|
136
|
+
destroy();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 动态挂载一个「查看差异」模式(只读)的 HistoryDiffDialog 并打开:
|
|
142
|
+
* 弹窗保持打开直到用户关闭,关闭(close 事件)后自动卸载并清理容器。
|
|
143
|
+
*/
|
|
144
|
+
const viewHistoryDiffDialog = async (
|
|
145
|
+
payload: DiffDialogPayload,
|
|
146
|
+
options: Pick<UseHistoryRevertOptions, 'appContext' | 'extendState'> &
|
|
147
|
+
CustomDiffFormOptions & {
|
|
148
|
+
services: Pick<Services, 'editorService' | 'dataSourceService' | 'codeBlockService' | 'historyService'>;
|
|
149
|
+
},
|
|
150
|
+
): Promise<void> => {
|
|
151
|
+
// onClose 在用户关闭弹窗时才触发,此时 handle.destroy 早已赋值。
|
|
152
|
+
const handle: { destroy?: () => void } = {};
|
|
153
|
+
const { instance, destroy } = await mountHistoryDiffDialog({
|
|
154
|
+
...options,
|
|
155
|
+
isConfirm: false,
|
|
156
|
+
onClose: () => handle.destroy?.(),
|
|
157
|
+
});
|
|
158
|
+
handle.destroy = destroy;
|
|
159
|
+
instance.open(payload);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 历史记录「单步回滚」与「查看差异」的完整交互流程,供历史面板与业务方共用。
|
|
164
|
+
*
|
|
165
|
+
* 单步回滚(类 git revert):
|
|
166
|
+
* 1. 前置校验:目标数据已被删除(update 写回目标 / 页面 remove 的原父容器缺失)时给出「回滚失败」提示并中止;
|
|
167
|
+
* 2. 二次确认:可差异对比的步骤(单实体 update)弹出差异确认弹窗,其余步骤弹普通二次确认框;
|
|
168
|
+
* 3. 用户确认后执行对应 service 的 revert(页面 / 数据源 / 代码块)。
|
|
169
|
+
*
|
|
170
|
+
* 查看差异:可差异对比的步骤动态挂载只读 HistoryDiffDialog 展示前后值差异。
|
|
171
|
+
*
|
|
172
|
+
* 上述弹窗均按需动态挂载 HistoryDiffDialog 实现,业务方无需自行挂载任何弹窗。
|
|
173
|
+
*
|
|
174
|
+
* 返回的能力分三组:
|
|
175
|
+
* - 内置三类(页面 / 数据源 / 代码块):`onPageRevert` / `onDataSourceRevert` / `onCodeBlockRevert` 单步回滚,
|
|
176
|
+
* `onPageDiff` / `onDataSourceDiff` / `onCodeBlockDiff` 查看差异,及配套的 `buildXxxDiffPayload` / `isXxxRevertTargetMissing`;
|
|
177
|
+
* - 业务自有历史(如管理台「模块」):`confirmAndRevert` / `viewDiff` 复用同一套交互流程,由业务方自行构造差异入参;
|
|
178
|
+
* 即上述内置三类本质上是它们各自预置好 payload 构造与 service.revert 的特例。
|
|
179
|
+
*
|
|
180
|
+
* 业务方可在拿到 Editor 实例暴露的 `services` 后直接 import 调用:
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { useHistoryRevert } from '@tmagic/editor';
|
|
184
|
+
*
|
|
185
|
+
* const { onPageRevert, onPageDiff } = useHistoryRevert(editorRef.value); // editorRef.value 即 Editor 暴露的 services
|
|
186
|
+
* await onPageRevert(index); // 弹出差异 / 二次确认弹窗后回滚
|
|
187
|
+
* onPageDiff(index); // 弹出只读差异弹窗查看前后值差异
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export const useHistoryRevert = (
|
|
191
|
+
services: Pick<Services, 'editorService' | 'dataSourceService' | 'codeBlockService' | 'historyService'>,
|
|
192
|
+
options: UseHistoryRevertOptions = {},
|
|
193
|
+
) => {
|
|
194
|
+
const { editorService, dataSourceService, codeBlockService, historyService } = services;
|
|
195
|
+
// 自动捕获调用方所在组件的 appContext(在 setup 中调用时),业务方亦可显式覆盖。
|
|
196
|
+
const appContext = options.appContext ?? getCurrentInstance()?.appContext ?? null;
|
|
197
|
+
const { extendState } = options;
|
|
198
|
+
|
|
199
|
+
/** 目标数据已被删除、无法回滚时的统一提示。 */
|
|
200
|
+
const showRevertTargetMissing = () => {
|
|
201
|
+
tMagicMessage.error('回滚失败:该记录对应的数据已被删除');
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 「回滚」二次确认:新增 / 删除 / 多节点更新等无法做差异对比的步骤,
|
|
206
|
+
* 不弹差异弹窗,改用一个普通确认框替代「确定回滚」按钮,避免点击后无任何提示直接执行。
|
|
207
|
+
* 用户取消时返回 false,调用方据此中止回滚。
|
|
208
|
+
*/
|
|
209
|
+
const confirmRevert = (): Promise<boolean> =>
|
|
210
|
+
confirmHistoryAction(
|
|
211
|
+
'确定回滚该步骤吗?回滚会将该操作作为一条新记录反向应用(新增将被删除、删除将被还原),不影响后续历史记录。',
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 「回滚」统一确认入口:可差异对比的步骤动态挂载 HistoryDiffDialog 走差异确认弹窗,
|
|
216
|
+
* 无法对比的步骤(add / remove / 多节点更新)回退到普通二次确认框。
|
|
217
|
+
* `extra` 供业务自有历史(如模块)透传自定义表单配置加载等渲染入参。
|
|
218
|
+
*/
|
|
219
|
+
const runRevert = (payload: DiffDialogPayload | null, extra?: CustomDiffFormOptions): Promise<boolean> => {
|
|
220
|
+
if (payload) {
|
|
221
|
+
return confirmRevertWithDiffDialog(payload, { appContext, extendState, services, ...extra });
|
|
222
|
+
}
|
|
223
|
+
return confirmRevert();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const buildPageDiffPayload = (index: number): DiffDialogPayload | null =>
|
|
227
|
+
buildDiffPayload(
|
|
228
|
+
{
|
|
229
|
+
category: 'node',
|
|
230
|
+
groups: () => historyService.getHistoryGroups('page', editorService.get('page')?.id),
|
|
231
|
+
getCurrent: (id) => editorService.getNodeById(id) as Record<string, any> | null,
|
|
232
|
+
resolveType: (n, o) => n.type || o.type || '',
|
|
233
|
+
resolveLabel: (n, o) => n.name || o.name || n.type || o.type || '',
|
|
234
|
+
},
|
|
235
|
+
index,
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
const buildDataSourceDiffPayload = (id: string | number, index: number): DiffDialogPayload | null =>
|
|
239
|
+
buildDiffPayload(
|
|
240
|
+
{
|
|
241
|
+
category: 'data-source',
|
|
242
|
+
groups: () => historyService.getHistoryGroups('dataSource'),
|
|
243
|
+
getCurrent: (id) => dataSourceService.getDataSourceById(`${id}`) as Record<string, any> | null,
|
|
244
|
+
resolveType: (n, o) => n.type || o.type || 'base',
|
|
245
|
+
resolveLabel: (n, o, id) => n.title || o.title || `${id}`,
|
|
246
|
+
},
|
|
247
|
+
index,
|
|
248
|
+
id,
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
const buildCodeBlockDiffPayload = (id: string | number, index: number): DiffDialogPayload | null =>
|
|
252
|
+
buildDiffPayload(
|
|
253
|
+
{
|
|
254
|
+
category: 'code-block',
|
|
255
|
+
groups: () => historyService.getHistoryGroups('codeBlock'),
|
|
256
|
+
getCurrent: (id) => codeBlockService.getCodeContentById(id) as Record<string, any> | null,
|
|
257
|
+
resolveLabel: (n, o, id) => n.name || o.name || `${id}`,
|
|
258
|
+
},
|
|
259
|
+
index,
|
|
260
|
+
id,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* 回滚前置校验:若该历史步骤回滚所依赖的目标数据已被删除,则无法回滚。
|
|
265
|
+
* - update(把旧值写回):被修改的目标必须仍存在;
|
|
266
|
+
* - 页面 remove(还原被删节点):被删节点的原父容器必须仍存在,否则无处插回;
|
|
267
|
+
* add(回滚即删除)即使目标已不在,也已达成「删除」目的,不视为失败。
|
|
268
|
+
*/
|
|
269
|
+
const isPageRevertTargetMissing = (index: number): boolean => {
|
|
270
|
+
const step = historyService.getStepList('page', editorService.get('page')?.id)[index]?.step;
|
|
271
|
+
if (!step) return false;
|
|
272
|
+
if (step.opType === 'update') {
|
|
273
|
+
return (step.diff ?? []).some((item) => {
|
|
274
|
+
const id = item.newSchema?.id ?? item.oldSchema?.id;
|
|
275
|
+
return id !== undefined && !editorService.getNodeById(id, false);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (step.opType === 'remove') {
|
|
279
|
+
return (step.diff ?? []).some(
|
|
280
|
+
(item) => item.parentId !== undefined && !editorService.getNodeById(item.parentId, false),
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
return false;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/** 数据源 update 步骤回滚时,对应数据源必须仍存在(已删除则无处写回旧值)。 */
|
|
287
|
+
const isDataSourceRevertTargetMissing = (id: string | number, index: number): boolean => {
|
|
288
|
+
const step = historyService.getStepList('dataSource', id)[index]?.step;
|
|
289
|
+
return Boolean(step?.opType === 'update' && !dataSourceService.getDataSourceById(`${id}`));
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/** 代码块 update 步骤回滚时,对应代码块必须仍存在(已删除则无处写回旧值)。 */
|
|
293
|
+
const isCodeBlockRevertTargetMissing = (id: string | number, index: number): boolean => {
|
|
294
|
+
const step = historyService.getStepList('codeBlock', id)[index]?.step;
|
|
295
|
+
return Boolean(step?.opType === 'update' && !codeBlockService.getCodeContentById(id));
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const onPageRevert = (index: number) => {
|
|
299
|
+
if (isPageRevertTargetMissing(index)) {
|
|
300
|
+
showRevertTargetMissing();
|
|
301
|
+
return Promise.resolve(null);
|
|
302
|
+
}
|
|
303
|
+
return runRevert(buildPageDiffPayload(index)).then((result) =>
|
|
304
|
+
result ? editorService.revertPageStep(index) : null,
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const onDataSourceRevert = (id: string | number, index: number) => {
|
|
309
|
+
if (isDataSourceRevertTargetMissing(id, index)) {
|
|
310
|
+
showRevertTargetMissing();
|
|
311
|
+
return Promise.resolve(null);
|
|
312
|
+
}
|
|
313
|
+
return runRevert(buildDataSourceDiffPayload(id, index)).then((result) =>
|
|
314
|
+
result ? dataSourceService.revert(id, index) : null,
|
|
315
|
+
);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const onCodeBlockRevert = (id: string | number, index: number) => {
|
|
319
|
+
if (isCodeBlockRevertTargetMissing(id, index)) {
|
|
320
|
+
showRevertTargetMissing();
|
|
321
|
+
return Promise.resolve(null);
|
|
322
|
+
}
|
|
323
|
+
return runRevert(buildCodeBlockDiffPayload(id, index)).then((result) =>
|
|
324
|
+
result ? codeBlockService.revert(id, index) : null,
|
|
325
|
+
);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 「查看差异」:可差异对比的步骤(单实体 update)动态挂载只读 HistoryDiffDialog 展示前后值差异,
|
|
330
|
+
* 无可对比内容(add / remove / 多节点更新)时不弹窗、静默返回。
|
|
331
|
+
*/
|
|
332
|
+
const onPageDiff = (index: number): Promise<void> | void => {
|
|
333
|
+
const payload = buildPageDiffPayload(index);
|
|
334
|
+
if (payload) return viewHistoryDiffDialog(payload, { appContext, extendState, services });
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
const onDataSourceDiff = (id: string | number, index: number): Promise<void> | void => {
|
|
338
|
+
const payload = buildDataSourceDiffPayload(id, index);
|
|
339
|
+
if (payload) return viewHistoryDiffDialog(payload, { appContext, extendState, services });
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const onCodeBlockDiff = (id: string | number, index: number): Promise<void> | void => {
|
|
343
|
+
const payload = buildCodeBlockDiffPayload(id, index);
|
|
344
|
+
if (payload) return viewHistoryDiffDialog(payload, { appContext, extendState, services });
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* 业务自有历史(如管理台「模块」)的「单步回滚」统一入口:
|
|
349
|
+
* 复用与页面/数据源/代码块一致的「目标校验 → 差异/二次确认弹窗 → 反向回滚」流程,
|
|
350
|
+
* 内置三类只是它的特例(各自预置了 buildXxxDiffPayload + service.revert)。
|
|
351
|
+
*
|
|
352
|
+
* 用户取消或前置校验未过时返回 null,确认并执行回滚后返回 `revert()` 的结果。
|
|
353
|
+
*
|
|
354
|
+
* ```ts
|
|
355
|
+
* await confirmAndRevert({
|
|
356
|
+
* diffPayload: oldSchema && newSchema ? { category: 'module', lastValue: oldSchema, value: newSchema, ... } : null,
|
|
357
|
+
* loadConfig: (ctx) => loadModFormConfig(modTypeId, values),
|
|
358
|
+
* selfDiffFieldTypes: ['mod-cond'],
|
|
359
|
+
* revert: () => moduleHistoryStore.revert(id, index),
|
|
360
|
+
* });
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
const confirmAndRevert = async <T = unknown>(revertOptions: ConfirmAndRevertOptions<T>): Promise<T | null> => {
|
|
364
|
+
if (revertOptions.isTargetMissing?.()) {
|
|
365
|
+
showRevertTargetMissing();
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const confirmed = await runRevert(revertOptions.diffPayload ?? null, {
|
|
369
|
+
loadConfig: revertOptions.loadConfig,
|
|
370
|
+
selfDiffFieldTypes: revertOptions.selfDiffFieldTypes,
|
|
371
|
+
});
|
|
372
|
+
if (!confirmed) return null;
|
|
373
|
+
return await revertOptions.revert();
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 业务自有历史的「查看差异」统一入口:传入自行构造的差异入参即弹出只读差异弹窗,
|
|
378
|
+
* 可透传 `loadConfig` / `selfDiffFieldTypes`。payload 为 null(不可对比)时静默返回。
|
|
379
|
+
*/
|
|
380
|
+
const viewDiff = (payload: DiffDialogPayload | null, extra?: CustomDiffFormOptions): Promise<void> | void => {
|
|
381
|
+
if (payload) return viewHistoryDiffDialog(payload, { appContext, extendState, services, ...extra });
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
onPageRevert,
|
|
386
|
+
onDataSourceRevert,
|
|
387
|
+
onCodeBlockRevert,
|
|
388
|
+
onPageDiff,
|
|
389
|
+
onDataSourceDiff,
|
|
390
|
+
onCodeBlockDiff,
|
|
391
|
+
buildPageDiffPayload,
|
|
392
|
+
buildDataSourceDiffPayload,
|
|
393
|
+
buildCodeBlockDiffPayload,
|
|
394
|
+
isPageRevertTargetMissing,
|
|
395
|
+
isDataSourceRevertTargetMissing,
|
|
396
|
+
isCodeBlockRevertTargetMissing,
|
|
397
|
+
confirmAndRevert,
|
|
398
|
+
viewDiff,
|
|
399
|
+
};
|
|
400
|
+
};
|
|
@@ -39,7 +39,7 @@ import type {
|
|
|
39
39
|
import { CODE_DRAFT_STORAGE_KEY } from '@editor/type';
|
|
40
40
|
import { getEditorConfig } from '@editor/utils/config';
|
|
41
41
|
import { COPY_CODE_STORAGE_KEY } from '@editor/utils/editor';
|
|
42
|
-
import { describeRevertStep, getLastPushedHistoryIds } from '@editor/utils/history';
|
|
42
|
+
import { createStackStep, describeRevertStep, getLastPushedHistoryIds } from '@editor/utils/history';
|
|
43
43
|
|
|
44
44
|
import BaseService from './BaseService';
|
|
45
45
|
|
|
@@ -188,14 +188,14 @@ class CodeBlock extends BaseService {
|
|
|
188
188
|
const newContent = cloneDeep(codeDsl[id]);
|
|
189
189
|
|
|
190
190
|
if (!doNotPushHistory) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
191
|
+
const step = createStackStep<CodeBlockContent, CodeBlockStepValue>(id, {
|
|
192
|
+
oldValue: oldContent,
|
|
193
|
+
newValue: newContent,
|
|
194
|
+
changeRecords,
|
|
195
|
+
historyDescription,
|
|
196
|
+
source: historySource,
|
|
197
|
+
});
|
|
198
|
+
this.lastPushedHistoryId = (step ? historyService.push('codeBlock', step, id) : null)?.uuid ?? null;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
this.emit('addOrUpdate', id, codeDsl[id]);
|
|
@@ -301,17 +301,18 @@ class CodeBlock extends BaseService {
|
|
|
301
301
|
|
|
302
302
|
codeIds.forEach((id) => {
|
|
303
303
|
// 历史记录:删除前快照内容;不存在的 id 直接跳过历史推入
|
|
304
|
-
const
|
|
304
|
+
const oldValue: CodeBlockContent | null = currentDsl[id] ? cloneDeep(currentDsl[id]) : null;
|
|
305
305
|
|
|
306
306
|
delete currentDsl[id];
|
|
307
307
|
|
|
308
|
-
if (
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
308
|
+
if (oldValue && !doNotPushHistory) {
|
|
309
|
+
const step = createStackStep<CodeBlockContent, CodeBlockStepValue>(id, {
|
|
310
|
+
oldValue,
|
|
311
|
+
newValue: null,
|
|
312
312
|
historyDescription,
|
|
313
313
|
source: historySource,
|
|
314
|
-
})
|
|
314
|
+
});
|
|
315
|
+
const uuid = step ? historyService.push('codeBlock', step, id)?.uuid : undefined;
|
|
315
316
|
if (uuid) this.lastDeletedHistoryIds.push(uuid);
|
|
316
317
|
}
|
|
317
318
|
|
|
@@ -385,7 +386,7 @@ class CodeBlock extends BaseService {
|
|
|
385
386
|
* @returns 撤销的 step;栈不存在或已无可撤销时返回 null
|
|
386
387
|
*/
|
|
387
388
|
public async undo(id: Id): Promise<CodeBlockStepValue | null> {
|
|
388
|
-
const step = historyService.
|
|
389
|
+
const step = historyService.undo('codeBlock', id);
|
|
389
390
|
if (!step) return null;
|
|
390
391
|
await this.applyHistoryStep(step, true);
|
|
391
392
|
return step;
|
|
@@ -397,7 +398,7 @@ class CodeBlock extends BaseService {
|
|
|
397
398
|
* @returns 重做的 step;栈不存在或已无可重做时返回 null
|
|
398
399
|
*/
|
|
399
400
|
public async redo(id: Id): Promise<CodeBlockStepValue | null> {
|
|
400
|
-
const step = historyService.
|
|
401
|
+
const step = historyService.redo('codeBlock', id);
|
|
401
402
|
if (!step) return null;
|
|
402
403
|
await this.applyHistoryStep(step, false);
|
|
403
404
|
return step;
|
|
@@ -405,12 +406,12 @@ class CodeBlock extends BaseService {
|
|
|
405
406
|
|
|
406
407
|
/** 是否可对指定代码块撤销。 */
|
|
407
408
|
public canUndo(id: Id): boolean {
|
|
408
|
-
return historyService.
|
|
409
|
+
return historyService.canUndo('codeBlock', id);
|
|
409
410
|
}
|
|
410
411
|
|
|
411
412
|
/** 是否可对指定代码块重做。 */
|
|
412
413
|
public canRedo(id: Id): boolean {
|
|
413
|
-
return historyService.
|
|
414
|
+
return historyService.canRedo('codeBlock', id);
|
|
414
415
|
}
|
|
415
416
|
|
|
416
417
|
/**
|
|
@@ -421,7 +422,7 @@ class CodeBlock extends BaseService {
|
|
|
421
422
|
* @returns 实际移动到的最终游标位置
|
|
422
423
|
*/
|
|
423
424
|
public async goto(id: Id, targetCursor: number): Promise<number> {
|
|
424
|
-
let cursor = historyService.
|
|
425
|
+
let cursor = historyService.getCursor('codeBlock', id);
|
|
425
426
|
const target = Math.max(0, targetCursor);
|
|
426
427
|
while (cursor > target) {
|
|
427
428
|
const step = await this.undo(id);
|
|
@@ -447,14 +448,14 @@ class CodeBlock extends BaseService {
|
|
|
447
448
|
* @returns 反向后产生的新 step;目标不存在 / 未应用时返回 null
|
|
448
449
|
*/
|
|
449
450
|
public async revert(id: Id, index: number): Promise<CodeBlockStepValue | null> {
|
|
450
|
-
const list = historyService.
|
|
451
|
+
const list = historyService.getStepList('codeBlock', id);
|
|
451
452
|
const entry = list[index];
|
|
452
453
|
if (!entry?.applied) return null;
|
|
453
454
|
// 更新类步骤(前后 content 都存在)必须带 changeRecords 才支持回滚,否则只能整内容替换,会冲掉后续无关变更。
|
|
454
455
|
const { oldSchema, newSchema, changeRecords } = entry.step.diff?.[0] ?? {};
|
|
455
456
|
|
|
456
457
|
if (oldSchema && newSchema && !changeRecords?.length) return null;
|
|
457
|
-
const description = `回滚 #${index + 1}: ${describeRevertStep<CodeBlockContent>(entry.step.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
458
|
+
const description = `回滚 #${index + 1}: ${describeRevertStep<CodeBlockContent>(entry.step.data.id, entry.step.diff?.[0], (s) => s.name)}`;
|
|
458
459
|
return await this.applyRevertStep(entry.step, description);
|
|
459
460
|
}
|
|
460
461
|
|
|
@@ -468,7 +469,7 @@ class CodeBlock extends BaseService {
|
|
|
468
469
|
public async revertById(uuids: string[]): Promise<(CodeBlockStepValue | null)[]> {
|
|
469
470
|
const results: (CodeBlockStepValue | null)[] = [];
|
|
470
471
|
for (const uuid of uuids) {
|
|
471
|
-
const location = historyService.
|
|
472
|
+
const location = historyService.findStepLocationByUuid('codeBlock', uuid);
|
|
472
473
|
results.push(location ? await this.revert(location.id, location.index) : null);
|
|
473
474
|
}
|
|
474
475
|
return results;
|
|
@@ -564,19 +565,19 @@ class CodeBlock extends BaseService {
|
|
|
564
565
|
step: CodeBlockStepValue,
|
|
565
566
|
historyDescription: string,
|
|
566
567
|
): Promise<CodeBlockStepValue | null> {
|
|
567
|
-
const { id } = step;
|
|
568
|
+
const { id } = step.data;
|
|
568
569
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
569
570
|
|
|
570
571
|
// 原本是新增 → revert 即删除
|
|
571
572
|
if (!oldSchema && newSchema) {
|
|
572
573
|
await this.deleteCodeDslByIds([id], { historyDescription, historySource: 'rollback' });
|
|
573
|
-
return historyService.
|
|
574
|
+
return historyService.getStepList('codeBlock', id).slice(-1)[0]?.step ?? null;
|
|
574
575
|
}
|
|
575
576
|
|
|
576
577
|
// 原本是删除 → revert 即写回
|
|
577
578
|
if (oldSchema && !newSchema) {
|
|
578
579
|
this.setCodeDslByIdSync(id, cloneDeep(oldSchema), true, { historyDescription, historySource: 'rollback' });
|
|
579
|
-
return historyService.
|
|
580
|
+
return historyService.getStepList('codeBlock', id).slice(-1)[0]?.step ?? null;
|
|
580
581
|
}
|
|
581
582
|
|
|
582
583
|
if (!oldSchema || !newSchema) return null;
|
|
@@ -600,11 +601,11 @@ class CodeBlock extends BaseService {
|
|
|
600
601
|
historyDescription,
|
|
601
602
|
historySource: 'rollback',
|
|
602
603
|
});
|
|
603
|
-
return historyService.
|
|
604
|
+
return historyService.getStepList('codeBlock', id).slice(-1)[0]?.step ?? null;
|
|
604
605
|
}
|
|
605
606
|
|
|
606
607
|
this.setCodeDslByIdSync(id, cloneDeep(oldSchema), true, { historyDescription, historySource: 'rollback' });
|
|
607
|
-
return historyService.
|
|
608
|
+
return historyService.getStepList('codeBlock', id).slice(-1)[0]?.step ?? null;
|
|
608
609
|
}
|
|
609
610
|
|
|
610
611
|
/**
|
|
@@ -622,7 +623,7 @@ class CodeBlock extends BaseService {
|
|
|
622
623
|
* @param reverse true=撤销,false=重做
|
|
623
624
|
*/
|
|
624
625
|
private async applyHistoryStep(step: CodeBlockStepValue, reverse: boolean): Promise<void> {
|
|
625
|
-
const { id } = step;
|
|
626
|
+
const { id } = step.data;
|
|
626
627
|
const { oldSchema, newSchema, changeRecords } = step.diff?.[0] ?? {};
|
|
627
628
|
|
|
628
629
|
// 新增 / 删除:直接 set 或 delete,不走 patch 逻辑
|