@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.3
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 +20 -2
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +18 -110
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/components/CompareForm.js +5 -0
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +171 -0
- package/dist/es/editorProps.js +2 -0
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/fields/CodeLink.vue_vue_type_script_setup_true_lang.js +2 -5
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +18 -2
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +37 -6
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +3 -1
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +15 -7
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +58 -11
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +11 -6
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/es/hooks/use-code-block-edit.js +2 -2
- package/dist/es/hooks/use-stage.js +17 -8
- package/dist/es/index.js +5 -1
- package/dist/es/initService.js +6 -6
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +6 -5
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +12 -7
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +8 -0
- package/dist/es/layouts/history-list/Bucket.js +5 -0
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +103 -0
- package/dist/es/layouts/history-list/BucketTab.js +5 -0
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +73 -0
- package/dist/es/layouts/history-list/GroupRow.js +5 -0
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +198 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.js +5 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +245 -0
- package/dist/es/layouts/history-list/HistoryListPanel.js +5 -0
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +340 -0
- package/dist/es/layouts/history-list/InitialRow.js +5 -0
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +54 -0
- package/dist/es/layouts/history-list/PageTab.js +5 -0
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +105 -0
- package/dist/es/layouts/history-list/composables.js +172 -0
- package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
- package/dist/es/services/BaseService.js +31 -68
- package/dist/es/services/codeBlock.js +205 -8
- package/dist/es/services/componentList.js +2 -2
- package/dist/es/services/dataSource.js +217 -8
- package/dist/es/services/dep.js +21 -9
- package/dist/es/services/editor.js +350 -160
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +410 -12
- package/dist/es/services/keybinding.js +2 -2
- package/dist/es/services/props.js +8 -8
- package/dist/es/services/stageOverlay.js +2 -2
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +2 -2
- package/dist/es/style.css +379 -1
- package/dist/es/utils/code-block.js +122 -0
- package/dist/es/utils/content-menu.js +4 -5
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +2 -2
- package/dist/es/utils/undo-redo.js +20 -0
- package/dist/style.css +379 -1
- package/dist/tmagic-editor.umd.cjs +3331 -787
- package/package.json +7 -7
- package/src/Editor.vue +15 -0
- package/src/components/CodeBlockEditor.vue +20 -109
- package/src/components/CodeParams.vue +6 -0
- package/src/components/CompareForm.vue +238 -0
- package/src/editorProps.ts +9 -0
- package/src/fields/Code.vue +19 -3
- package/src/fields/CodeLink.vue +2 -5
- package/src/fields/CodeSelect.vue +17 -1
- package/src/fields/CodeSelectCol.vue +30 -2
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +7 -1
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +12 -3
- package/src/fields/DataSourceMethodSelect.vue +4 -1
- package/src/fields/DataSourceMethods.vue +14 -4
- package/src/fields/DataSourceMocks.vue +13 -3
- package/src/fields/DataSourceSelect.vue +4 -1
- package/src/fields/EventSelect.vue +57 -8
- package/src/fields/KeyValue.vue +17 -4
- package/src/fields/UISelect.vue +5 -2
- package/src/hooks/use-code-block-edit.ts +5 -2
- package/src/hooks/use-stage.ts +24 -7
- package/src/index.ts +3 -0
- package/src/layouts/CodeEditor.vue +17 -5
- package/src/layouts/Framework.vue +10 -5
- package/src/layouts/NavMenu.vue +9 -0
- package/src/layouts/history-list/Bucket.vue +124 -0
- package/src/layouts/history-list/BucketTab.vue +77 -0
- package/src/layouts/history-list/GroupRow.vue +242 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +231 -0
- package/src/layouts/history-list/HistoryListPanel.vue +380 -0
- package/src/layouts/history-list/InitialRow.vue +52 -0
- package/src/layouts/history-list/PageTab.vue +108 -0
- package/src/layouts/history-list/composables.ts +226 -0
- package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
- package/src/services/BaseService.ts +35 -86
- package/src/services/codeBlock.ts +256 -5
- package/src/services/dataSource.ts +257 -6
- package/src/services/dep.ts +32 -9
- package/src/services/editor.ts +454 -171
- package/src/services/history.ts +455 -8
- package/src/services/props.ts +2 -2
- package/src/theme/history-list-panel.scss +462 -0
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +269 -6
- package/src/utils/code-block.ts +150 -0
- package/src/utils/content-menu.ts +8 -5
- package/src/utils/dep/worker.ts +5 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/undo-redo.ts +23 -0
- package/types/index.d.ts +2274 -819
- package/dist/es/utils/compose.js +0 -44
- package/dist/es/utils/editor-history.js +0 -100
- package/src/utils/compose.ts +0 -52
- package/src/utils/editor-history.ts +0 -138
package/dist/es/utils/compose.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region packages/editor/src/utils/compose.ts
|
|
2
|
-
/**
|
|
3
|
-
* @param {Array} middleware
|
|
4
|
-
* @return {Function}
|
|
5
|
-
*/
|
|
6
|
-
var compose = (middleware, isAsync) => {
|
|
7
|
-
if (!Array.isArray(middleware)) throw new TypeError("Middleware 必须是一个数组!");
|
|
8
|
-
for (const fn of middleware) if (typeof fn !== "function") throw new TypeError("Middleware 必须由函数组成!");
|
|
9
|
-
/**
|
|
10
|
-
* @param {Object} args
|
|
11
|
-
* @return {Promise}
|
|
12
|
-
* @api public
|
|
13
|
-
*/
|
|
14
|
-
return (args, next) => {
|
|
15
|
-
let index = -1;
|
|
16
|
-
return dispatch(0);
|
|
17
|
-
function dispatch(i) {
|
|
18
|
-
if (i <= index) {
|
|
19
|
-
const error = /* @__PURE__ */ new Error("next() 被多次调用");
|
|
20
|
-
if (isAsync) return Promise.reject(error);
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
index = i;
|
|
24
|
-
let fn = middleware[i];
|
|
25
|
-
if (i === middleware.length && next) fn = next;
|
|
26
|
-
if (!fn) {
|
|
27
|
-
if (isAsync) return Promise.resolve();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (isAsync) try {
|
|
31
|
-
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
|
|
32
|
-
} catch (err) {
|
|
33
|
-
return Promise.reject(err);
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
return fn(...args, dispatch.bind(null, i + 1));
|
|
37
|
-
} catch (err) {
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
//#endregion
|
|
44
|
-
export { compose };
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { getNodeIndex } from "./editor.js";
|
|
2
|
-
import { isPage, isPageFragment } from "@tmagic/utils";
|
|
3
|
-
import { NodeType } from "@tmagic/core";
|
|
4
|
-
import { toRaw } from "vue";
|
|
5
|
-
import { cloneDeep } from "lodash-es";
|
|
6
|
-
//#region packages/editor/src/utils/editor-history.ts
|
|
7
|
-
/**
|
|
8
|
-
* 应用 add 类型的历史操作
|
|
9
|
-
* reverse=true(撤销):从父节点中移除已添加的节点
|
|
10
|
-
* reverse=false(重做):重新添加节点到父节点中
|
|
11
|
-
*/
|
|
12
|
-
async function applyHistoryAddOp(step, reverse, ctx) {
|
|
13
|
-
const { root, stage } = ctx;
|
|
14
|
-
if (reverse) for (const node of step.nodes ?? []) {
|
|
15
|
-
const parent = ctx.getNodeById(step.parentId, false);
|
|
16
|
-
if (!parent?.items) continue;
|
|
17
|
-
const idx = getNodeIndex(node.id, parent);
|
|
18
|
-
if (typeof idx === "number" && idx !== -1) parent.items.splice(idx, 1);
|
|
19
|
-
await stage?.remove({
|
|
20
|
-
id: node.id,
|
|
21
|
-
parentId: parent.id,
|
|
22
|
-
root: cloneDeep(root)
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const parent = ctx.getNodeById(step.parentId, false);
|
|
27
|
-
if (parent?.items) for (const node of step.nodes ?? []) {
|
|
28
|
-
const idx = step.indexMap?.[node.id] ?? parent.items.length;
|
|
29
|
-
parent.items.splice(idx, 0, cloneDeep(node));
|
|
30
|
-
await stage?.add({
|
|
31
|
-
config: cloneDeep(node),
|
|
32
|
-
parent: cloneDeep(parent),
|
|
33
|
-
parentId: parent.id,
|
|
34
|
-
root: cloneDeep(root)
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 应用 remove 类型的历史操作
|
|
41
|
-
* reverse=true(撤销):将已删除的节点按原位置重新插入
|
|
42
|
-
* reverse=false(重做):再次删除节点
|
|
43
|
-
*/
|
|
44
|
-
async function applyHistoryRemoveOp(step, reverse, ctx) {
|
|
45
|
-
const { root, stage } = ctx;
|
|
46
|
-
if (reverse) {
|
|
47
|
-
const sorted = [...step.removedItems ?? []].sort((a, b) => a.index - b.index);
|
|
48
|
-
for (const { node, parentId, index } of sorted) {
|
|
49
|
-
const parent = ctx.getNodeById(parentId, false);
|
|
50
|
-
if (!parent?.items) continue;
|
|
51
|
-
parent.items.splice(index, 0, cloneDeep(node));
|
|
52
|
-
await stage?.add({
|
|
53
|
-
config: cloneDeep(node),
|
|
54
|
-
parent: cloneDeep(parent),
|
|
55
|
-
parentId,
|
|
56
|
-
root: cloneDeep(root)
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
} else for (const { node, parentId } of step.removedItems ?? []) {
|
|
60
|
-
const parent = ctx.getNodeById(parentId, false);
|
|
61
|
-
if (!parent?.items) continue;
|
|
62
|
-
const idx = getNodeIndex(node.id, parent);
|
|
63
|
-
if (typeof idx === "number" && idx !== -1) parent.items.splice(idx, 1);
|
|
64
|
-
await stage?.remove({
|
|
65
|
-
id: node.id,
|
|
66
|
-
parentId,
|
|
67
|
-
root: cloneDeep(root)
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 应用 update 类型的历史操作
|
|
73
|
-
* reverse=true(撤销):将节点恢复为 oldNode
|
|
74
|
-
* reverse=false(重做):将节点更新为 newNode
|
|
75
|
-
*/
|
|
76
|
-
async function applyHistoryUpdateOp(step, reverse, ctx) {
|
|
77
|
-
const { root, stage } = ctx;
|
|
78
|
-
const items = step.updatedItems ?? [];
|
|
79
|
-
for (const { oldNode, newNode } of items) {
|
|
80
|
-
const config = reverse ? oldNode : newNode;
|
|
81
|
-
if (config.type === NodeType.ROOT) {
|
|
82
|
-
ctx.setRoot(cloneDeep(config));
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const info = ctx.getNodeInfo(config.id, false);
|
|
86
|
-
if (!info.parent) continue;
|
|
87
|
-
const idx = getNodeIndex(config.id, info.parent);
|
|
88
|
-
if (typeof idx !== "number" || idx === -1) continue;
|
|
89
|
-
info.parent.items[idx] = cloneDeep(config);
|
|
90
|
-
if (isPage(config) || isPageFragment(config)) ctx.setPage(config);
|
|
91
|
-
}
|
|
92
|
-
const curPage = ctx.getPage();
|
|
93
|
-
if (stage && curPage) await stage.update({
|
|
94
|
-
config: cloneDeep(toRaw(curPage)),
|
|
95
|
-
parentId: root.id,
|
|
96
|
-
root: cloneDeep(toRaw(root))
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
//#endregion
|
|
100
|
-
export { applyHistoryAddOp, applyHistoryRemoveOp, applyHistoryUpdateOp };
|
package/src/utils/compose.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {Array} middleware
|
|
3
|
-
* @return {Function}
|
|
4
|
-
*/
|
|
5
|
-
export const compose = (middleware: Function[], isAsync: boolean) => {
|
|
6
|
-
if (!Array.isArray(middleware)) throw new TypeError('Middleware 必须是一个数组!');
|
|
7
|
-
for (const fn of middleware) {
|
|
8
|
-
if (typeof fn !== 'function') throw new TypeError('Middleware 必须由函数组成!');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {Object} args
|
|
13
|
-
* @return {Promise}
|
|
14
|
-
* @api public
|
|
15
|
-
*/
|
|
16
|
-
return (args: any[], next?: Function) => {
|
|
17
|
-
// last called middleware #
|
|
18
|
-
let index = -1;
|
|
19
|
-
return dispatch(0);
|
|
20
|
-
function dispatch(i: number): Promise<void> | void {
|
|
21
|
-
if (i <= index) {
|
|
22
|
-
const error = new Error('next() 被多次调用');
|
|
23
|
-
if (isAsync) {
|
|
24
|
-
return Promise.reject(error);
|
|
25
|
-
}
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
index = i;
|
|
29
|
-
let fn = middleware[i];
|
|
30
|
-
if (i === middleware.length && next) fn = next;
|
|
31
|
-
if (!fn) {
|
|
32
|
-
if (isAsync) {
|
|
33
|
-
return Promise.resolve();
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isAsync) {
|
|
39
|
-
try {
|
|
40
|
-
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
|
|
41
|
-
} catch (err) {
|
|
42
|
-
return Promise.reject(err);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return fn(...args, dispatch.bind(null, i + 1));
|
|
47
|
-
} catch (err) {
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2025 Tencent. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { toRaw } from 'vue';
|
|
20
|
-
import { cloneDeep } from 'lodash-es';
|
|
21
|
-
|
|
22
|
-
import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/core';
|
|
23
|
-
import { NodeType } from '@tmagic/core';
|
|
24
|
-
import type StageCore from '@tmagic/stage';
|
|
25
|
-
import { isPage, isPageFragment } from '@tmagic/utils';
|
|
26
|
-
|
|
27
|
-
import type { EditorNodeInfo, StepValue } from '@editor/type';
|
|
28
|
-
import { getNodeIndex } from '@editor/utils/editor';
|
|
29
|
-
|
|
30
|
-
export interface HistoryOpContext {
|
|
31
|
-
root: MApp;
|
|
32
|
-
stage: StageCore | null;
|
|
33
|
-
getNodeById(id: Id, raw?: boolean): MNode | null;
|
|
34
|
-
getNodeInfo(id: Id, raw?: boolean): EditorNodeInfo;
|
|
35
|
-
setRoot(root: MApp): void;
|
|
36
|
-
setPage(page: MPage | MPageFragment): void;
|
|
37
|
-
getPage(): MPage | MPageFragment | null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 应用 add 类型的历史操作
|
|
42
|
-
* reverse=true(撤销):从父节点中移除已添加的节点
|
|
43
|
-
* reverse=false(重做):重新添加节点到父节点中
|
|
44
|
-
*/
|
|
45
|
-
export async function applyHistoryAddOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
46
|
-
const { root, stage } = ctx;
|
|
47
|
-
|
|
48
|
-
if (reverse) {
|
|
49
|
-
for (const node of step.nodes ?? []) {
|
|
50
|
-
const parent = ctx.getNodeById(step.parentId!, false) as MContainer;
|
|
51
|
-
if (!parent?.items) continue;
|
|
52
|
-
const idx = getNodeIndex(node.id, parent);
|
|
53
|
-
if (typeof idx === 'number' && idx !== -1) {
|
|
54
|
-
parent.items.splice(idx, 1);
|
|
55
|
-
}
|
|
56
|
-
await stage?.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
const parent = ctx.getNodeById(step.parentId!, false) as MContainer;
|
|
60
|
-
if (parent?.items) {
|
|
61
|
-
for (const node of step.nodes ?? []) {
|
|
62
|
-
const idx = step.indexMap?.[node.id] ?? parent.items.length;
|
|
63
|
-
parent.items.splice(idx, 0, cloneDeep(node));
|
|
64
|
-
await stage?.add({
|
|
65
|
-
config: cloneDeep(node),
|
|
66
|
-
parent: cloneDeep(parent),
|
|
67
|
-
parentId: parent.id,
|
|
68
|
-
root: cloneDeep(root),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 应用 remove 类型的历史操作
|
|
77
|
-
* reverse=true(撤销):将已删除的节点按原位置重新插入
|
|
78
|
-
* reverse=false(重做):再次删除节点
|
|
79
|
-
*/
|
|
80
|
-
export async function applyHistoryRemoveOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
81
|
-
const { root, stage } = ctx;
|
|
82
|
-
|
|
83
|
-
if (reverse) {
|
|
84
|
-
const sorted = [...(step.removedItems ?? [])].sort((a, b) => a.index - b.index);
|
|
85
|
-
for (const { node, parentId, index } of sorted) {
|
|
86
|
-
const parent = ctx.getNodeById(parentId, false) as MContainer;
|
|
87
|
-
if (!parent?.items) continue;
|
|
88
|
-
parent.items.splice(index, 0, cloneDeep(node));
|
|
89
|
-
await stage?.add({ config: cloneDeep(node), parent: cloneDeep(parent), parentId, root: cloneDeep(root) });
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
for (const { node, parentId } of step.removedItems ?? []) {
|
|
93
|
-
const parent = ctx.getNodeById(parentId, false) as MContainer;
|
|
94
|
-
if (!parent?.items) continue;
|
|
95
|
-
const idx = getNodeIndex(node.id, parent);
|
|
96
|
-
if (typeof idx === 'number' && idx !== -1) {
|
|
97
|
-
parent.items.splice(idx, 1);
|
|
98
|
-
}
|
|
99
|
-
await stage?.remove({ id: node.id, parentId, root: cloneDeep(root) });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 应用 update 类型的历史操作
|
|
106
|
-
* reverse=true(撤销):将节点恢复为 oldNode
|
|
107
|
-
* reverse=false(重做):将节点更新为 newNode
|
|
108
|
-
*/
|
|
109
|
-
export async function applyHistoryUpdateOp(step: StepValue, reverse: boolean, ctx: HistoryOpContext): Promise<void> {
|
|
110
|
-
const { root, stage } = ctx;
|
|
111
|
-
const items = step.updatedItems ?? [];
|
|
112
|
-
|
|
113
|
-
for (const { oldNode, newNode } of items) {
|
|
114
|
-
const config = reverse ? oldNode : newNode;
|
|
115
|
-
if (config.type === NodeType.ROOT) {
|
|
116
|
-
ctx.setRoot(cloneDeep(config) as MApp);
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
const info = ctx.getNodeInfo(config.id, false);
|
|
120
|
-
if (!info.parent) continue;
|
|
121
|
-
const idx = getNodeIndex(config.id, info.parent);
|
|
122
|
-
if (typeof idx !== 'number' || idx === -1) continue;
|
|
123
|
-
info.parent.items![idx] = cloneDeep(config);
|
|
124
|
-
|
|
125
|
-
if (isPage(config) || isPageFragment(config)) {
|
|
126
|
-
ctx.setPage(config as MPage | MPageFragment);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const curPage = ctx.getPage();
|
|
131
|
-
if (stage && curPage) {
|
|
132
|
-
await stage.update({
|
|
133
|
-
config: cloneDeep(toRaw(curPage)),
|
|
134
|
-
parentId: root.id,
|
|
135
|
-
root: cloneDeep(toRaw(root)),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|