@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<li
|
|
3
3
|
class="m-editor-history-list-item m-editor-history-list-group"
|
|
4
|
-
:class="{ 'is-undone': !applied, 'is-merged': merged, 'is-current': isCurrent }"
|
|
4
|
+
:class="{ 'is-undone': !group.applied, 'is-merged': merged, 'is-current': group.isCurrent }"
|
|
5
5
|
>
|
|
6
6
|
<div
|
|
7
7
|
class="m-editor-history-list-group-head"
|
|
@@ -10,41 +10,53 @@
|
|
|
10
10
|
@click="onHeadClick"
|
|
11
11
|
>
|
|
12
12
|
<span class="m-editor-history-list-item-index" :title="headIndexTitle">{{ headIndexLabel }}</span>
|
|
13
|
-
<span class="m-editor-history-list-item-op" :class="`op-${opType}`">{{ opLabel(opType) }}</span>
|
|
14
|
-
<span class="m-editor-history-list-item-desc">{{ desc }}</span>
|
|
13
|
+
<span class="m-editor-history-list-item-op" :class="`op-${group.opType}`">{{ opLabel(group.opType) }}</span>
|
|
14
|
+
<span class="m-editor-history-list-item-desc">{{ group.desc }}</span>
|
|
15
15
|
|
|
16
|
-
<span
|
|
17
|
-
v-if="!merged && sourceLabel(source)"
|
|
18
|
-
class="m-editor-history-list-item-source"
|
|
19
|
-
:title="`操作途径:${sourceLabel(source)}`"
|
|
20
|
-
>{{ sourceLabel(source) }}</span
|
|
21
|
-
>
|
|
22
|
-
|
|
23
|
-
<span v-if="!merged && time" class="m-editor-history-list-item-time" :title="timeTitle || time">{{ time }}</span>
|
|
24
|
-
|
|
25
|
-
<span v-if="merged" class="m-editor-history-list-item-merge">合并 {{ stepCount }} 步</span>
|
|
16
|
+
<span v-if="headSaved" class="m-editor-history-list-item-saved" title="该记录为最近一次保存的状态">已保存</span>
|
|
26
17
|
|
|
27
18
|
<span
|
|
28
|
-
v-if="!merged && headRevertable"
|
|
29
|
-
class="m-editor-history-list-item-
|
|
30
|
-
title="将该步骤的修改作为一次新操作反向应用(不影响后续历史)"
|
|
31
|
-
@click.stop="onRevertClick(subSteps[0].index)"
|
|
32
|
-
>回滚</span
|
|
19
|
+
v-if="!merged && (headRevertable || headDiffable || canHeadGoto)"
|
|
20
|
+
class="m-editor-history-list-item-actions"
|
|
33
21
|
>
|
|
22
|
+
<span
|
|
23
|
+
v-if="headRevertable"
|
|
24
|
+
class="m-editor-history-list-item-revert"
|
|
25
|
+
title="将该步骤的修改作为一次新操作反向应用(不影响后续历史)"
|
|
26
|
+
@click.stop="onRevertClick(group.subSteps[0].index)"
|
|
27
|
+
>回滚</span
|
|
28
|
+
>
|
|
29
|
+
<span
|
|
30
|
+
v-if="canHeadGoto"
|
|
31
|
+
class="m-editor-history-list-item-goto"
|
|
32
|
+
title="回到该记录"
|
|
33
|
+
@click.stop="onGotoClick(group.subSteps[0].index)"
|
|
34
|
+
>回到</span
|
|
35
|
+
>
|
|
36
|
+
<span
|
|
37
|
+
v-if="headDiffable"
|
|
38
|
+
class="m-editor-history-list-item-diff"
|
|
39
|
+
title="查看修改差异"
|
|
40
|
+
@click.stop="onDiffClick(group.subSteps[0].index)"
|
|
41
|
+
>查看差异</span
|
|
42
|
+
>
|
|
43
|
+
</span>
|
|
44
|
+
|
|
34
45
|
<span
|
|
35
|
-
v-if="!merged &&
|
|
36
|
-
class="m-editor-history-list-item-
|
|
37
|
-
title="
|
|
38
|
-
|
|
39
|
-
>回到</span
|
|
46
|
+
v-if="!merged && sourceLabel(group.source)"
|
|
47
|
+
class="m-editor-history-list-item-source"
|
|
48
|
+
:title="`操作途径:${sourceLabel(group.source)}`"
|
|
49
|
+
>{{ sourceLabel(group.source) }}</span
|
|
40
50
|
>
|
|
51
|
+
|
|
41
52
|
<span
|
|
42
|
-
v-if="!merged &&
|
|
43
|
-
class="m-editor-history-list-item-
|
|
44
|
-
title="
|
|
45
|
-
|
|
46
|
-
>查看差异</span
|
|
53
|
+
v-if="!merged && group.time"
|
|
54
|
+
class="m-editor-history-list-item-time"
|
|
55
|
+
:title="group.timeTitle || group.time"
|
|
56
|
+
>{{ group.time }}</span
|
|
47
57
|
>
|
|
58
|
+
|
|
59
|
+
<span v-if="merged" class="m-editor-history-list-item-merge">合并 {{ stepCount }} 步</span>
|
|
48
60
|
<span v-if="merged" class="m-editor-history-list-group-toggle" :class="{ 'is-expanded': expanded }">▾</span>
|
|
49
61
|
</div>
|
|
50
62
|
|
|
@@ -52,11 +64,39 @@
|
|
|
52
64
|
<li
|
|
53
65
|
v-for="s in subStepsDisplay"
|
|
54
66
|
:key="s.index"
|
|
55
|
-
:class="{ 'is-undone': !s.applied, 'is-current': s.isCurrent }"
|
|
67
|
+
:class="{ 'is-undone': !s.applied, 'is-current': s.isCurrent, 'is-clickable': selectEnabled }"
|
|
56
68
|
:title="subStepTitle(s)"
|
|
69
|
+
@click="onSubStepClick(s.index)"
|
|
57
70
|
>
|
|
58
71
|
<span class="m-editor-history-list-item-index">#{{ s.index + 1 }}</span>
|
|
59
72
|
<span class="m-editor-history-list-substep-desc">{{ s.desc }}</span>
|
|
73
|
+
<span v-if="s.saved" class="m-editor-history-list-item-saved" title="该记录为最近一次保存的状态">已保存</span>
|
|
74
|
+
<span
|
|
75
|
+
v-if="s.revertable || s.diffable || (gotoEnabled && !s.isCurrent)"
|
|
76
|
+
class="m-editor-history-list-item-actions"
|
|
77
|
+
>
|
|
78
|
+
<span
|
|
79
|
+
v-if="s.revertable"
|
|
80
|
+
class="m-editor-history-list-item-revert"
|
|
81
|
+
title="将该步骤的修改作为一次新操作反向应用(不影响后续历史)"
|
|
82
|
+
@click.stop="onRevertClick(s.index)"
|
|
83
|
+
>回滚</span
|
|
84
|
+
>
|
|
85
|
+
<span
|
|
86
|
+
v-if="gotoEnabled && !s.isCurrent"
|
|
87
|
+
class="m-editor-history-list-item-goto"
|
|
88
|
+
title="回到该记录"
|
|
89
|
+
@click.stop="onGotoClick(s.index)"
|
|
90
|
+
>回到</span
|
|
91
|
+
>
|
|
92
|
+
<span
|
|
93
|
+
v-if="s.diffable"
|
|
94
|
+
class="m-editor-history-list-item-diff"
|
|
95
|
+
title="查看修改差异"
|
|
96
|
+
@click.stop="onDiffClick(s.index)"
|
|
97
|
+
>查看差异</span
|
|
98
|
+
>
|
|
99
|
+
</span>
|
|
60
100
|
<span
|
|
61
101
|
v-if="sourceLabel(s.source)"
|
|
62
102
|
class="m-editor-history-list-item-source"
|
|
@@ -64,27 +104,6 @@
|
|
|
64
104
|
>{{ sourceLabel(s.source) }}</span
|
|
65
105
|
>
|
|
66
106
|
<span v-if="s.time" class="m-editor-history-list-item-time" :title="s.timeTitle || s.time">{{ s.time }}</span>
|
|
67
|
-
<span
|
|
68
|
-
v-if="s.revertable"
|
|
69
|
-
class="m-editor-history-list-item-revert"
|
|
70
|
-
title="将该步骤的修改作为一次新操作反向应用(不影响后续历史)"
|
|
71
|
-
@click.stop="onRevertClick(s.index)"
|
|
72
|
-
>回滚</span
|
|
73
|
-
>
|
|
74
|
-
<span
|
|
75
|
-
v-if="gotoEnabled && !s.isCurrent"
|
|
76
|
-
class="m-editor-history-list-item-goto"
|
|
77
|
-
title="回到该记录"
|
|
78
|
-
@click.stop="onGotoClick(s.index)"
|
|
79
|
-
>回到</span
|
|
80
|
-
>
|
|
81
|
-
<span
|
|
82
|
-
v-if="s.diffable"
|
|
83
|
-
class="m-editor-history-list-item-diff"
|
|
84
|
-
title="查看修改差异"
|
|
85
|
-
@click.stop="onDiffClick(s.index)"
|
|
86
|
-
>查看差异</span
|
|
87
|
-
>
|
|
88
107
|
</li>
|
|
89
108
|
</ul>
|
|
90
109
|
</li>
|
|
@@ -93,8 +112,7 @@
|
|
|
93
112
|
<script lang="ts" setup>
|
|
94
113
|
import { computed } from 'vue';
|
|
95
114
|
|
|
96
|
-
import type {
|
|
97
|
-
|
|
115
|
+
import type { HistoryRowGroup, HistoryRowStep } from './composables';
|
|
98
116
|
import { opLabel, sourceLabel } from './composables';
|
|
99
117
|
|
|
100
118
|
defineOptions({
|
|
@@ -103,67 +121,42 @@ defineOptions({
|
|
|
103
121
|
|
|
104
122
|
const props = withDefaults(
|
|
105
123
|
defineProps<{
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/** 操作类型:`add` / `remove` / `update`,用于决定操作徽标的颜色和文案。 */
|
|
113
|
-
opType: HistoryOpType;
|
|
114
|
-
/** 组的整体描述文案,由上层根据 step / group 计算后传入,例如 "修改 button · style.color"。 */
|
|
115
|
-
desc: string;
|
|
116
|
-
/** 组的操作途径(一般取组内最近一步),用于头部展示「画布 / 树面板 / 配置面板…」标签。 */
|
|
117
|
-
source?: HistoryOpSource;
|
|
118
|
-
/** 组头部展示的时间文案(一般为组内最近一步的时间),为空时不渲染。 */
|
|
119
|
-
time?: string;
|
|
120
|
-
/** 组头部时间的 title 悬浮提示(完整时间),缺省时回退为 time。 */
|
|
121
|
-
timeTitle?: string;
|
|
122
|
-
/** 组内的 step 总数,仅在 merged 为 true 时显示为 "合并 N 步"。 */
|
|
123
|
-
stepCount: number;
|
|
124
|
-
/** 子步列表,用于在展开状态下逐条展示每个 step 的索引、应用状态与描述文案。 */
|
|
125
|
-
subSteps: {
|
|
126
|
-
index: number;
|
|
127
|
-
applied: boolean;
|
|
128
|
-
desc: string;
|
|
129
|
-
isCurrent?: boolean;
|
|
130
|
-
diffable?: boolean;
|
|
131
|
-
/** 是否可对该子步执行「回滚」(已应用 + 业务侧确认支持反向)。父级根据 step 与 applied 决定。 */
|
|
132
|
-
revertable?: boolean;
|
|
133
|
-
/** 该子步的操作途径,用于展示「画布 / 树面板 / 配置面板…」标签。 */
|
|
134
|
-
source?: HistoryOpSource;
|
|
135
|
-
/** 该子步的时间文案,为空时不渲染。 */
|
|
136
|
-
time?: string;
|
|
137
|
-
/** 该子步时间的 title 悬浮提示(完整时间),缺省时回退为 time。 */
|
|
138
|
-
timeTitle?: string;
|
|
139
|
-
}[];
|
|
140
|
-
/** 当前组是否处于展开状态。仅在 merged 为 true 时生效,控制子步列表是否渲染。 */
|
|
124
|
+
/**
|
|
125
|
+
* 该组的视图模型(由 `toRowGroup` 统一派生):包含 key、应用状态、操作类型、描述、
|
|
126
|
+
* 来源 / 时间等头部信息以及子步列表。原先散落的十余个扁平 props 收敛于此单一对象。
|
|
127
|
+
*/
|
|
128
|
+
group: HistoryRowGroup;
|
|
129
|
+
/** 当前组是否处于展开状态(合并组默认展开)。仅在合并组(子步数 > 1)时生效,控制子步列表是否渲染。 */
|
|
141
130
|
expanded: boolean;
|
|
142
|
-
/** 是否为当前所在的分组(包含栈中最近一次已应用步骤的那一组),UI 高亮展示。 */
|
|
143
|
-
isCurrent?: boolean;
|
|
144
131
|
/**
|
|
145
132
|
* 是否支持「跳转到该记录」(goto)。默认 true。
|
|
146
133
|
* 为 false 时:单步组头部与子步条目都不再可点击跳转、也不会触发 goto 事件,
|
|
147
134
|
* 仅保留合并组头部的展开 / 收起能力,以及查看差异、回滚等其它入口。
|
|
148
135
|
*/
|
|
149
136
|
gotoEnabled?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* 是否支持「点击记录选中对应节点」。默认 false(仅页面 tab 启用,数据源 / 代码块无节点概念)。
|
|
139
|
+
* 为 true 时:点击单步组头部、子步条目或合并组头部都会发出 `select` 事件(携带对应 step 索引),
|
|
140
|
+
* 由上层解析出节点 id 并在画布选中;合并组头部同时保留展开 / 收起能力。
|
|
141
|
+
*/
|
|
142
|
+
selectEnabled?: boolean;
|
|
150
143
|
}>(),
|
|
151
144
|
{
|
|
152
|
-
isCurrent: false,
|
|
153
145
|
gotoEnabled: true,
|
|
146
|
+
selectEnabled: false,
|
|
154
147
|
},
|
|
155
148
|
);
|
|
156
149
|
|
|
157
150
|
const emit = defineEmits<{
|
|
158
151
|
/**
|
|
159
|
-
* 用户点击合并组头部时触发,携带
|
|
152
|
+
* 用户点击合并组头部时触发,携带 group.key;上层用其切换 expanded 状态。
|
|
160
153
|
* 对单步组(非合并)头部点击不会发该事件——因为单步组没有"展开"的概念。
|
|
161
154
|
*/
|
|
162
155
|
(_e: 'toggle', _key: string): void;
|
|
163
156
|
/**
|
|
164
157
|
* 用户希望跳转到该记录时触发,携带"目标 step 在所属栈中的索引"——上层据此计算目标 cursor (= index + 1)。
|
|
165
158
|
* 触发场景:
|
|
166
|
-
* -
|
|
159
|
+
* - 单步组(非合并)头部:取该唯一 step 的 index;
|
|
167
160
|
* - 子步条目:取该子步的 index。
|
|
168
161
|
* 合并组头部不再触发 goto,避免与展开/收起冲突;用户应展开后点具体子步精准跳转。
|
|
169
162
|
* 当前所在的步骤(isCurrent)始终不会触发 goto。
|
|
@@ -171,7 +164,7 @@ const emit = defineEmits<{
|
|
|
171
164
|
(_e: 'goto', _index: number): void;
|
|
172
165
|
/**
|
|
173
166
|
* 用户希望查看该 step 的修改差异(旧值 vs 新值)。
|
|
174
|
-
* 只在 step 满足"前后值都存在"(如 update / 数据源、代码块的 update
|
|
167
|
+
* 只在 step 满足"前后值都存在"(如 update / 数据源、代码块的 update)时由 `toRowGroup` 标记 `diffable=true`。
|
|
175
168
|
* payload 为该 step 在所属栈中的索引,由上层根据 index 取 step 内容并展示对比。
|
|
176
169
|
*/
|
|
177
170
|
(_e: 'diff-step', _index: number): void;
|
|
@@ -180,26 +173,48 @@ const emit = defineEmits<{
|
|
|
180
173
|
* payload 为该 step 在所属栈中的索引。仅在单步组头部(headRevertable)或合并组的可回滚子步上触发。
|
|
181
174
|
*/
|
|
182
175
|
(_e: 'revert-step', _index: number): void;
|
|
176
|
+
/**
|
|
177
|
+
* 用户希望「选中该记录对应的节点」。payload 为该 step 在所属栈中的索引,
|
|
178
|
+
* 由上层据 index 取出 step、解析出节点 id 并在画布选中。仅在 `selectEnabled` 为 true 时触发。
|
|
179
|
+
*/
|
|
180
|
+
(_e: 'select', _index: number): void;
|
|
183
181
|
}>();
|
|
184
182
|
|
|
183
|
+
/** 子步数大于 1 即为合并组:决定是否展示合并标记与可展开的子步列表。 */
|
|
184
|
+
const merged = computed(() => props.group.subSteps.length > 1);
|
|
185
|
+
|
|
186
|
+
/** 组内 step 总数,仅在合并组时显示为 "合并 N 步"。 */
|
|
187
|
+
const stepCount = computed(() => props.group.subSteps.length);
|
|
188
|
+
|
|
185
189
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
190
|
+
* 头部可点击的场景:
|
|
191
|
+
* - 合并组:点击切换展开 / 收起;
|
|
192
|
+
* - 开启 `selectEnabled`(页面 tab):点击选中对应节点。
|
|
193
|
+
* 单步组的跳转仍由头部的「回到」按钮触发。
|
|
188
194
|
*/
|
|
189
|
-
const isHeadClickable = computed(() => props.
|
|
195
|
+
const isHeadClickable = computed(() => merged.value || props.selectEnabled);
|
|
190
196
|
|
|
191
197
|
const headTitle = computed(() => {
|
|
192
|
-
if (
|
|
193
|
-
|
|
198
|
+
if (merged.value) {
|
|
199
|
+
const expandHint = props.expanded ? '点击收起子步' : '点击展开子步';
|
|
200
|
+
return props.selectEnabled ? `${expandHint}(并选中该节点)` : expandHint;
|
|
201
|
+
}
|
|
202
|
+
if (props.selectEnabled) return '点击选中该节点';
|
|
203
|
+
if (props.group.isCurrent) return '当前所在记录';
|
|
194
204
|
return '';
|
|
195
205
|
});
|
|
196
206
|
|
|
197
207
|
/**
|
|
198
|
-
*
|
|
208
|
+
* 头部点击行为:
|
|
209
|
+
* - 开启 selectEnabled 时,发出 select(携带组内首步 index,上层据此选中节点);
|
|
210
|
+
* - 合并组同时切换展开 / 收起。
|
|
199
211
|
*/
|
|
200
212
|
const onHeadClick = () => {
|
|
201
|
-
if (props.
|
|
202
|
-
emit('
|
|
213
|
+
if (props.selectEnabled && props.group.subSteps.length) {
|
|
214
|
+
emit('select', props.group.subSteps[0].index);
|
|
215
|
+
}
|
|
216
|
+
if (merged.value) {
|
|
217
|
+
emit('toggle', props.group.key);
|
|
203
218
|
}
|
|
204
219
|
};
|
|
205
220
|
|
|
@@ -208,45 +223,65 @@ const onGotoClick = (index: number) => {
|
|
|
208
223
|
emit('goto', index);
|
|
209
224
|
};
|
|
210
225
|
|
|
226
|
+
/** 点击子步行:开启 selectEnabled 时选中该子步对应的节点。 */
|
|
227
|
+
const onSubStepClick = (index: number) => {
|
|
228
|
+
if (!props.selectEnabled) return;
|
|
229
|
+
emit('select', index);
|
|
230
|
+
};
|
|
231
|
+
|
|
211
232
|
const subStepTitle = (s: { isCurrent?: boolean }) => {
|
|
233
|
+
if (props.selectEnabled) return '点击选中该节点';
|
|
212
234
|
if (s.isCurrent) return '当前所在记录';
|
|
213
235
|
return '';
|
|
214
236
|
};
|
|
215
237
|
|
|
238
|
+
/**
|
|
239
|
+
* 头部是否展示「已保存」标记:
|
|
240
|
+
* - 单步组:取该唯一子步的 saved;
|
|
241
|
+
* - 合并组:组内任一子步为已保存即在头部提示(具体落在哪一步可展开查看)。
|
|
242
|
+
*/
|
|
243
|
+
const headSaved = computed(() =>
|
|
244
|
+
merged.value ? props.group.subSteps.some((s) => s.saved) : Boolean(props.group.subSteps[0]?.saved),
|
|
245
|
+
);
|
|
246
|
+
|
|
216
247
|
/** 单步组头部是否展示"查看差异"入口:要求该唯一子步本身可对比。 */
|
|
217
|
-
const headDiffable = computed(() => !
|
|
248
|
+
const headDiffable = computed(() => !merged.value && Boolean(props.group.subSteps[0]?.diffable));
|
|
218
249
|
|
|
219
250
|
/** 单步组头部是否展示"回滚"入口:要求该唯一子步本身可回滚(已应用)。 */
|
|
220
|
-
const headRevertable = computed(() => !
|
|
251
|
+
const headRevertable = computed(() => !merged.value && Boolean(props.group.subSteps[0]?.revertable));
|
|
252
|
+
|
|
253
|
+
/** 单步组头部是否展示"回到"入口:可跳转、非当前、且存在唯一子步。 */
|
|
254
|
+
const canHeadGoto = computed(
|
|
255
|
+
() => !merged.value && props.gotoEnabled && !props.group.isCurrent && props.group.subSteps.length > 0,
|
|
256
|
+
);
|
|
221
257
|
|
|
222
258
|
/**
|
|
223
259
|
* 合并组展开后的子步渲染顺序:与外层分组列表保持一致——倒序展示(最新的子步在最上方)。
|
|
224
260
|
* 外层 page tab / bucket 都已对 groups 做了 reverse,子步沿用同样的视觉规则更直观。
|
|
225
261
|
* 注意:仅用于渲染,原 `subSteps` 保持时间正序,`headIndexLabel` 等基于首尾索引的展示语义不变。
|
|
226
262
|
*/
|
|
227
|
-
const subStepsDisplay = computed(() => props.subSteps.slice().reverse());
|
|
263
|
+
const subStepsDisplay = computed<HistoryRowStep[]>(() => props.group.subSteps.slice().reverse());
|
|
228
264
|
|
|
229
265
|
/**
|
|
230
266
|
* 头部索引展示:
|
|
231
|
-
* -
|
|
267
|
+
* - 单步组(非合并):显示该唯一 step 的编号,如 `#5`;
|
|
232
268
|
* - 合并组:显示组内 step 的编号范围,如 `#3-#7`(首尾相同则退化为 `#5`)。
|
|
233
269
|
*
|
|
234
270
|
* 这里展示的是 step.index + 1(与子步列表 `#{{ s.index + 1 }}` 保持一致),从 1 起编号更符合直觉。
|
|
235
271
|
*/
|
|
236
272
|
const headIndexLabel = computed(() => {
|
|
237
|
-
const list = props.subSteps;
|
|
273
|
+
const list = props.group.subSteps;
|
|
238
274
|
if (!list.length) return '';
|
|
239
275
|
const first = list[0].index + 1;
|
|
240
276
|
const last = list[list.length - 1].index + 1;
|
|
241
|
-
if (!
|
|
277
|
+
if (!merged.value || first === last) return `#${first}`;
|
|
242
278
|
return `#${first}-#${last}`;
|
|
243
279
|
});
|
|
244
280
|
|
|
245
281
|
const headIndexTitle = computed(() => {
|
|
246
|
-
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
} 共 ${props.subSteps.length} 条历史步骤`;
|
|
282
|
+
const list = props.group.subSteps;
|
|
283
|
+
if (!merged.value) return `历史步骤编号 #${list[0]?.index + 1}`;
|
|
284
|
+
return `合并了第 ${list[0]?.index + 1} 至第 ${list[list.length - 1]?.index + 1} 共 ${list.length} 条历史步骤`;
|
|
250
285
|
});
|
|
251
286
|
|
|
252
287
|
const onDiffClick = (index: number) => {
|
|
@@ -1,76 +1,74 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
>
|
|
13
|
-
<div v-if="
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<
|
|
17
|
-
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</TMagicRadioGroup>
|
|
23
|
-
|
|
24
|
-
<TMagicRadioGroup v-model="mode" size="small" class="m-editor-history-diff-dialog-mode">
|
|
25
|
-
<TMagicRadioButton value="before">与修改前对比</TMagicRadioButton>
|
|
26
|
-
<TMagicRadioButton value="current" :disabled="!hasCurrent">与当前对比</TMagicRadioButton>
|
|
27
|
-
</TMagicRadioGroup>
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
2
|
+
<TMagicDialog
|
|
3
|
+
v-model="visible"
|
|
4
|
+
class="m-editor-history-diff-dialog"
|
|
5
|
+
:title="dialogTitle"
|
|
6
|
+
top="5vh"
|
|
7
|
+
destroy-on-close
|
|
8
|
+
append-to-body
|
|
9
|
+
:width="width"
|
|
10
|
+
@close="onClose"
|
|
11
|
+
>
|
|
12
|
+
<div v-if="payload && visible" class="m-editor-history-diff-dialog-body">
|
|
13
|
+
<div v-if="onConfirm" class="m-editor-history-diff-dialog-notice">仅回滚有差异的字段</div>
|
|
14
|
+
|
|
15
|
+
<div class="m-editor-history-diff-dialog-header">
|
|
16
|
+
<span class="m-editor-history-diff-dialog-target">{{ targetText }}</span>
|
|
17
|
+
<div class="m-editor-history-diff-dialog-controls">
|
|
18
|
+
<TMagicRadioGroup v-model="viewMode" size="small" class="m-editor-history-diff-dialog-view">
|
|
19
|
+
<TMagicRadioButton value="form">表单对比</TMagicRadioButton>
|
|
20
|
+
<TMagicRadioButton value="code">源码对比</TMagicRadioButton>
|
|
21
|
+
</TMagicRadioGroup>
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<span v-if="mode === 'current' && isSameAsCurrent" class="m-editor-history-diff-dialog-tip">
|
|
36
|
-
当前值与该步修改后一致,无差异
|
|
37
|
-
</span>
|
|
23
|
+
<TMagicRadioGroup v-model="mode" size="small" class="m-editor-history-diff-dialog-mode">
|
|
24
|
+
<TMagicRadioButton value="before">与修改前对比</TMagicRadioButton>
|
|
25
|
+
<TMagicRadioButton value="current" :disabled="!hasCurrent">与当前对比</TMagicRadioButton>
|
|
26
|
+
</TMagicRadioGroup>
|
|
38
27
|
</div>
|
|
28
|
+
</div>
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
:extend-state="extendState"
|
|
48
|
-
:load-config="loadConfig"
|
|
49
|
-
:self-diff-field-types="selfDiffFieldTypes"
|
|
50
|
-
height="70vh"
|
|
51
|
-
/>
|
|
52
|
-
|
|
53
|
-
<CodeEditor
|
|
54
|
-
v-else
|
|
55
|
-
type="diff"
|
|
56
|
-
language="json"
|
|
57
|
-
:init-values="leftValue"
|
|
58
|
-
:modified-values="rightValue"
|
|
59
|
-
:options="codeDiffOptions"
|
|
60
|
-
disabled-full-screen
|
|
61
|
-
height="70vh"
|
|
62
|
-
/>
|
|
30
|
+
<div class="m-editor-history-diff-dialog-legend">
|
|
31
|
+
<TMagicTag size="small" type="danger">{{ leftLabel }}</TMagicTag>
|
|
32
|
+
<span class="m-editor-history-diff-dialog-arrow">→</span>
|
|
33
|
+
<TMagicTag size="small" type="success">{{ rightLabel }}</TMagicTag>
|
|
34
|
+
<span v-if="mode === 'current' && isSameAsCurrent" class="m-editor-history-diff-dialog-tip">
|
|
35
|
+
当前值与该步修改后一致,无差异
|
|
36
|
+
</span>
|
|
63
37
|
</div>
|
|
64
38
|
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
39
|
+
<CompareForm
|
|
40
|
+
v-if="viewMode === 'form'"
|
|
41
|
+
:category="payload.category"
|
|
42
|
+
:type="payload.type"
|
|
43
|
+
:data-source-type="payload.dataSourceType"
|
|
44
|
+
:value="rightValue"
|
|
45
|
+
:last-value="leftValue"
|
|
46
|
+
:extend-state="extendState"
|
|
47
|
+
:load-config="loadConfig"
|
|
48
|
+
:self-diff-field-types="selfDiffFieldTypes"
|
|
49
|
+
height="70vh"
|
|
50
|
+
/>
|
|
51
|
+
|
|
52
|
+
<CodeEditor
|
|
53
|
+
v-else
|
|
54
|
+
type="diff"
|
|
55
|
+
language="json"
|
|
56
|
+
:init-values="leftValue"
|
|
57
|
+
:modified-values="rightValue"
|
|
58
|
+
:options="codeDiffOptions"
|
|
59
|
+
disabled-full-screen
|
|
60
|
+
height="70vh"
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<template #footer>
|
|
65
|
+
<template v-if="isConfirm">
|
|
66
|
+
<TMagicButton size="small" @click="visible = false">取消</TMagicButton>
|
|
67
|
+
<TMagicButton size="small" type="primary" @click="onConfirmClick">确定回滚</TMagicButton>
|
|
71
68
|
</template>
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
<TMagicButton v-else size="small" @click="visible = false">关闭</TMagicButton>
|
|
70
|
+
</template>
|
|
71
|
+
</TMagicDialog>
|
|
74
72
|
</template>
|
|
75
73
|
|
|
76
74
|
<script lang="ts" setup>
|
|
@@ -102,6 +100,7 @@ const props = withDefaults(
|
|
|
102
100
|
*/
|
|
103
101
|
loadConfig?: CompareFormLoadConfig;
|
|
104
102
|
width?: string;
|
|
103
|
+
isConfirm?: boolean;
|
|
105
104
|
onConfirm?: () => void;
|
|
106
105
|
selfDiffFieldTypes?: string[];
|
|
107
106
|
}>(),
|
|
@@ -178,10 +177,15 @@ const isSameAsCurrent = computed(() => {
|
|
|
178
177
|
return isEqual(payload.value.value, payload.value.currentValue);
|
|
179
178
|
});
|
|
180
179
|
|
|
180
|
+
/** confirm() 的 resolve,仅在「等待用户确认回滚」期间存在 */
|
|
181
|
+
let confirmResolve: ((_value: boolean) => void) | null = null;
|
|
182
|
+
|
|
181
183
|
const onConfirmClick = () => {
|
|
182
|
-
|
|
184
|
+
props.onConfirm?.();
|
|
183
185
|
|
|
184
|
-
|
|
186
|
+
// 用户确认回滚:resolve(true),并清空以避免随后 visible=false 再 resolve(false)
|
|
187
|
+
confirmResolve?.(true);
|
|
188
|
+
confirmResolve = null;
|
|
185
189
|
|
|
186
190
|
visible.value = false;
|
|
187
191
|
};
|
|
@@ -210,6 +214,24 @@ const open = (p: DiffDialogPayload) => {
|
|
|
210
214
|
visible.value = true;
|
|
211
215
|
};
|
|
212
216
|
|
|
217
|
+
/**
|
|
218
|
+
* 以 Promise 形式打开确认回滚弹窗:
|
|
219
|
+
* - 用户点击「确定回滚」时 resolve(true);
|
|
220
|
+
* - 取消 / 关闭 / 按 Esc 等其他方式关闭弹窗时 resolve(false)。
|
|
221
|
+
*
|
|
222
|
+
* 同一时刻只允许一个待确认流程,重复调用会先 resolve(false) 掉上一个。
|
|
223
|
+
*/
|
|
224
|
+
const confirm = (p: DiffDialogPayload): Promise<boolean> => {
|
|
225
|
+
// 终止上一个未完成的确认流程,避免悬挂的 Promise
|
|
226
|
+
confirmResolve?.(false);
|
|
227
|
+
confirmResolve = null;
|
|
228
|
+
|
|
229
|
+
return new Promise<boolean>((resolve) => {
|
|
230
|
+
confirmResolve = resolve;
|
|
231
|
+
open(p);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
213
235
|
const close = () => {
|
|
214
236
|
visible.value = false;
|
|
215
237
|
};
|
|
@@ -218,6 +240,9 @@ const close = () => {
|
|
|
218
240
|
watch(visible, (v) => {
|
|
219
241
|
if (!v) {
|
|
220
242
|
payload.value = null;
|
|
243
|
+
// 非「确定回滚」方式关闭(取消 / Esc / 点遮罩等)时,resolve(false)
|
|
244
|
+
confirmResolve?.(false);
|
|
245
|
+
confirmResolve = null;
|
|
221
246
|
}
|
|
222
247
|
});
|
|
223
248
|
|
|
@@ -227,6 +252,7 @@ const onClose = () => {
|
|
|
227
252
|
|
|
228
253
|
defineExpose({
|
|
229
254
|
open,
|
|
255
|
+
confirm,
|
|
230
256
|
close,
|
|
231
257
|
});
|
|
232
258
|
</script>
|