@tmagic/editor 1.8.0-manmanyu.12 → 1.8.0-manmanyu.13
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 +9 -7
- package/dist/es/layouts/history-list/BucketTab.vue_vue_type_script_setup_true_lang.js +4 -7
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +5 -14
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +3 -3
- package/dist/es/layouts/history-list/useHistoryRevert.js +19 -18
- package/dist/es/services/codeBlock.js +0 -3
- package/dist/es/services/dataSource.js +0 -3
- package/dist/es/services/editor.js +0 -52
- package/dist/tmagic-editor.umd.cjs +93 -111
- package/package.json +7 -7
- package/src/layouts/history-list/HistoryDiffDialog.vue +12 -4
- package/src/layouts/history-list/useHistoryRevert.ts +21 -5
- package/src/type.ts +19 -0
- package/types/index.d.ts +20 -118
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useServices } from "../hooks/use-services.js";
|
|
1
2
|
import { getCodeBlockFormConfig } from "../utils/code-block.js";
|
|
2
3
|
import { MForm } from "@tmagic/form";
|
|
3
4
|
import { HookType } from "@tmagic/core";
|
|
@@ -22,10 +23,11 @@ var CompareForm_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
22
23
|
baseFormState: {},
|
|
23
24
|
selfDiffFieldTypes: {},
|
|
24
25
|
loadConfig: {},
|
|
25
|
-
services: {}
|
|
26
|
+
services: { default: () => useServices() }
|
|
26
27
|
},
|
|
27
28
|
setup(__props, { expose: __expose }) {
|
|
28
29
|
const props = __props;
|
|
30
|
+
const { propsService, dataSourceService, codeBlockService, editorService } = props.services;
|
|
29
31
|
provide("services", props.services);
|
|
30
32
|
const config = ref([]);
|
|
31
33
|
/** vs-code 编辑器的 monaco 配置项,沿用 Editor 顶层 provide('codeOptions', ...) 的注入。 */
|
|
@@ -105,17 +107,16 @@ var CompareForm_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
105
107
|
* 作为 ctx.defaultLoadConfig 透传给自定义 `loadConfig`,方便复用与二次加工。
|
|
106
108
|
*/
|
|
107
109
|
const defaultLoadConfig = async () => {
|
|
108
|
-
if (!props.services) return [];
|
|
109
110
|
switch (props.category) {
|
|
110
111
|
case "node":
|
|
111
112
|
if (!props.type) return [];
|
|
112
|
-
return removeStyleDisplayConfig(await
|
|
113
|
-
case "data-source": return
|
|
113
|
+
return removeStyleDisplayConfig(await propsService.getPropsConfig(props.type, { node: props.value }));
|
|
114
|
+
case "data-source": return dataSourceService.getFormConfig(props.type || "base").map((item) => "type" in item && item.type === "tab" ? {
|
|
114
115
|
...item,
|
|
115
116
|
active: "fields"
|
|
116
117
|
} : item);
|
|
117
118
|
case "code-block": return getCodeBlockFormConfig({
|
|
118
|
-
paramColConfig:
|
|
119
|
+
paramColConfig: codeBlockService.getParamsColConfig(),
|
|
119
120
|
isDataSource: () => Boolean(props.dataSourceType),
|
|
120
121
|
dataSourceType: () => props.dataSourceType,
|
|
121
122
|
codeOptions,
|
|
@@ -154,9 +155,10 @@ var CompareForm_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defi
|
|
|
154
155
|
* - services:整个 useServices() 返回的服务集合;
|
|
155
156
|
* - stage:当前 editorService.get('stage') 的最新值。
|
|
156
157
|
*/
|
|
158
|
+
const stage = computed(() => editorService.get("stage"));
|
|
157
159
|
watchEffect(() => {
|
|
158
|
-
if (formRef.value
|
|
159
|
-
formRef.value.formState.stage =
|
|
160
|
+
if (formRef.value) {
|
|
161
|
+
formRef.value.formState.stage = stage.value;
|
|
160
162
|
formRef.value.formState.services = props.services;
|
|
161
163
|
}
|
|
162
164
|
});
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import Bucket_default from "./Bucket.js";
|
|
2
2
|
import { TMagicScrollbar } from "@tmagic/design";
|
|
3
|
-
import { Fragment, createBlock,
|
|
3
|
+
import { Fragment, createBlock, createElementBlock, createElementVNode, createVNode, defineComponent, openBlock, renderList, unref, withCtx } from "vue";
|
|
4
4
|
//#region packages/editor/src/layouts/history-list/BucketTab.vue?vue&type=script&setup=true&lang.ts
|
|
5
5
|
var _hoisted_1 = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "m-editor-history-list-empty"
|
|
8
8
|
};
|
|
9
|
-
var _hoisted_2 = {
|
|
10
|
-
key: 0,
|
|
11
|
-
class: "m-editor-history-list-toolbar"
|
|
12
|
-
};
|
|
9
|
+
var _hoisted_2 = { class: "m-editor-history-list-toolbar" };
|
|
13
10
|
var _hoisted_3 = ["title"];
|
|
14
11
|
var BucketTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
15
12
|
name: "MEditorHistoryListBucketTab",
|
|
@@ -29,11 +26,11 @@ var BucketTab_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ define
|
|
|
29
26
|
],
|
|
30
27
|
setup(__props) {
|
|
31
28
|
return (_ctx, _cache) => {
|
|
32
|
-
return !__props.buckets.length ? (openBlock(), createElementBlock("div", _hoisted_1, "暂无操作记录")) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
29
|
+
return !__props.buckets.length ? (openBlock(), createElementBlock("div", _hoisted_1, "暂无操作记录")) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createElementVNode("div", _hoisted_2, [createElementVNode("span", {
|
|
33
30
|
class: "m-editor-history-list-clear",
|
|
34
31
|
title: `清空${__props.config.title}的历史记录`,
|
|
35
32
|
onClick: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("clear"))
|
|
36
|
-
}, "清空", 8, _hoisted_3)])
|
|
33
|
+
}, "清空", 8, _hoisted_3)]), createVNode(unref(TMagicScrollbar), { "max-height": "360px" }, {
|
|
37
34
|
default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.buckets, (bucket) => {
|
|
38
35
|
return openBlock(), createBlock(Bucket_default, {
|
|
39
36
|
key: `${__props.config.prefix}-${bucket.id}`,
|
package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useServices } from "../../hooks/use-services.js";
|
|
1
2
|
import CodeEditor_default from "../CodeEditor.js";
|
|
2
3
|
import CompareForm_default from "../../components/CompareForm.js";
|
|
3
4
|
import { TMagicButton, TMagicDialog, TMagicRadioButton, TMagicRadioGroup, TMagicTag } from "@tmagic/design";
|
|
@@ -24,7 +25,7 @@ var HistoryDiffDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*
|
|
|
24
25
|
name: "MEditorHistoryDiffDialog",
|
|
25
26
|
__name: "HistoryDiffDialog",
|
|
26
27
|
props: {
|
|
27
|
-
services: {},
|
|
28
|
+
services: { default: () => useServices() },
|
|
28
29
|
extendState: {},
|
|
29
30
|
loadConfig: {},
|
|
30
31
|
width: { default: "900px" },
|
|
@@ -65,13 +66,6 @@ var HistoryDiffDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*
|
|
|
65
66
|
};
|
|
66
67
|
const dialogTitle = computed(() => props.onConfirm ? "确认回滚" : "查看修改差异");
|
|
67
68
|
const hasCurrent = computed(() => payload.value?.currentValue !== void 0 && payload.value?.currentValue !== null);
|
|
68
|
-
/** 是否存在该步「修改后的值」:不存在(如仅删除)时「与修改前对比」无意义,置灰禁用。 */
|
|
69
|
-
const hasValue = computed(() => payload.value?.value !== void 0 && payload.value?.value !== null);
|
|
70
|
-
/**
|
|
71
|
-
* 计算 open 时的初始对比模式:
|
|
72
|
-
* 没有「修改后的值」但有当前值时(「与修改前对比」不可用),默认进入「与当前对比」;否则默认「与修改前对比」。
|
|
73
|
-
*/
|
|
74
|
-
const resolveInitialMode = () => !hasValue.value && hasCurrent.value ? "current" : "before";
|
|
75
69
|
/** 左侧(旧/参照)值 */
|
|
76
70
|
const leftValue = computed(() => {
|
|
77
71
|
if (!payload.value) return {};
|
|
@@ -114,7 +108,7 @@ var HistoryDiffDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*
|
|
|
114
108
|
});
|
|
115
109
|
const open = (p) => {
|
|
116
110
|
payload.value = p;
|
|
117
|
-
mode.value =
|
|
111
|
+
mode.value = "before";
|
|
118
112
|
viewMode.value = "form";
|
|
119
113
|
visible.value = true;
|
|
120
114
|
};
|
|
@@ -206,13 +200,10 @@ var HistoryDiffDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*
|
|
|
206
200
|
size: "small",
|
|
207
201
|
class: "m-editor-history-diff-dialog-mode"
|
|
208
202
|
}, {
|
|
209
|
-
default: withCtx(() => [createVNode(unref(TMagicRadioButton), {
|
|
210
|
-
value: "before",
|
|
211
|
-
disabled: !hasValue.value
|
|
212
|
-
}, {
|
|
203
|
+
default: withCtx(() => [createVNode(unref(TMagicRadioButton), { value: "before" }, {
|
|
213
204
|
default: withCtx(() => [..._cache[7] || (_cache[7] = [createTextVNode("与修改前对比", -1)])]),
|
|
214
205
|
_: 1
|
|
215
|
-
}
|
|
206
|
+
}), createVNode(unref(TMagicRadioButton), {
|
|
216
207
|
value: "current",
|
|
217
208
|
disabled: !hasCurrent.value
|
|
218
209
|
}, {
|
package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js
CHANGED
|
@@ -150,12 +150,12 @@ var HistoryListPanel_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/
|
|
|
150
150
|
/**
|
|
151
151
|
* 「单步回滚」与「查看差异」的完整逻辑收敛到 useHistoryRevert,面板与业务方共用:
|
|
152
152
|
* 二者均由 useHistoryRevert 内部按需动态挂载 HistoryDiffDialog,
|
|
153
|
-
* 业务方亦可直接 import useHistoryRevert(
|
|
153
|
+
* 业务方亦可直接 import useHistoryRevert(services) 调用,无需自行挂载任何弹窗。
|
|
154
154
|
*/
|
|
155
|
-
const { onPageRevert, onDataSourceRevert, onCodeBlockRevert, onPageDiff, onDataSourceDiff, onCodeBlockDiff } = useHistoryRevert({
|
|
155
|
+
const { onPageRevert, onDataSourceRevert, onCodeBlockRevert, onPageDiff, onDataSourceDiff, onCodeBlockDiff } = useHistoryRevert(services, {
|
|
156
156
|
extendState: extendFormState,
|
|
157
157
|
getPropsPanelFormState
|
|
158
|
-
}
|
|
158
|
+
});
|
|
159
159
|
/**
|
|
160
160
|
* 把内存中(已清空对应类别后的)历史状态重新写回 IndexedDB,
|
|
161
161
|
* 使本地持久化的那份与内存保持一致——即「连同本地保存的一并删除」。
|
|
@@ -118,12 +118,13 @@ var viewHistoryDiffDialog = async (payload, options) => {
|
|
|
118
118
|
* ```ts
|
|
119
119
|
* import { useHistoryRevert } from '@tmagic/editor';
|
|
120
120
|
*
|
|
121
|
-
* const { onPageRevert, onPageDiff } = useHistoryRevert(
|
|
121
|
+
* const { onPageRevert, onPageDiff } = useHistoryRevert(editorRef.value); // editorRef.value 即 Editor 暴露的 services
|
|
122
122
|
* await onPageRevert(index); // 弹出差异 / 二次确认弹窗后回滚
|
|
123
123
|
* onPageDiff(index); // 弹出只读差异弹窗查看前后值差异
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
126
|
-
var useHistoryRevert = (options = {}
|
|
126
|
+
var useHistoryRevert = (services, options = {}) => {
|
|
127
|
+
const { editorService, dataSourceService, codeBlockService, historyService } = services;
|
|
127
128
|
const appContext = options.appContext ?? getCurrentInstance()?.appContext ?? null;
|
|
128
129
|
const { extendState, getPropsPanelFormState } = options;
|
|
129
130
|
/** 目标数据已被删除、无法回滚时的统一提示。 */
|
|
@@ -152,22 +153,22 @@ var useHistoryRevert = (options = {}, services) => {
|
|
|
152
153
|
};
|
|
153
154
|
const buildPageDiffPayload = (index) => buildDiffPayload({
|
|
154
155
|
category: "node",
|
|
155
|
-
groups: () =>
|
|
156
|
-
getCurrent: (id) =>
|
|
156
|
+
groups: () => historyService.getHistoryGroups("page", editorService.get("page")?.id),
|
|
157
|
+
getCurrent: (id) => editorService.getNodeById(id),
|
|
157
158
|
resolveType: (n, o) => n.type || o.type || "",
|
|
158
159
|
resolveLabel: (n, o) => n.name || o.name || n.type || o.type || ""
|
|
159
160
|
}, index);
|
|
160
161
|
const buildDataSourceDiffPayload = (id, index) => buildDiffPayload({
|
|
161
162
|
category: "data-source",
|
|
162
|
-
groups: () =>
|
|
163
|
-
getCurrent: (id) =>
|
|
163
|
+
groups: () => historyService.getHistoryGroups("dataSource"),
|
|
164
|
+
getCurrent: (id) => dataSourceService.getDataSourceById(`${id}`),
|
|
164
165
|
resolveType: (n, o) => n.type || o.type || "base",
|
|
165
166
|
resolveLabel: (n, o, id) => n.title || o.title || `${id}`
|
|
166
167
|
}, index, id);
|
|
167
168
|
const buildCodeBlockDiffPayload = (id, index) => buildDiffPayload({
|
|
168
169
|
category: "code-block",
|
|
169
|
-
groups: () =>
|
|
170
|
-
getCurrent: (id) =>
|
|
170
|
+
groups: () => historyService.getHistoryGroups("codeBlock"),
|
|
171
|
+
getCurrent: (id) => codeBlockService.getCodeContentById(id),
|
|
171
172
|
resolveLabel: (n, o, id) => n.name || o.name || `${id}`
|
|
172
173
|
}, index, id);
|
|
173
174
|
/**
|
|
@@ -177,45 +178,45 @@ var useHistoryRevert = (options = {}, services) => {
|
|
|
177
178
|
* add(回滚即删除)即使目标已不在,也已达成「删除」目的,不视为失败。
|
|
178
179
|
*/
|
|
179
180
|
const isPageRevertTargetMissing = (index) => {
|
|
180
|
-
const step =
|
|
181
|
+
const step = historyService.getStepList("page", editorService.get("page")?.id)[index]?.step;
|
|
181
182
|
if (!step) return false;
|
|
182
183
|
if (step.opType === "update") return (step.diff ?? []).some((item) => {
|
|
183
184
|
const id = item.newSchema?.id ?? item.oldSchema?.id;
|
|
184
|
-
return id !== void 0 && !
|
|
185
|
+
return id !== void 0 && !editorService.getNodeById(id, false);
|
|
185
186
|
});
|
|
186
|
-
if (step.opType === "remove") return (step.diff ?? []).some((item) => item.parentId !== void 0 && !
|
|
187
|
+
if (step.opType === "remove") return (step.diff ?? []).some((item) => item.parentId !== void 0 && !editorService.getNodeById(item.parentId, false));
|
|
187
188
|
return false;
|
|
188
189
|
};
|
|
189
190
|
/** 数据源 update 步骤回滚时,对应数据源必须仍存在(已删除则无处写回旧值)。 */
|
|
190
191
|
const isDataSourceRevertTargetMissing = (id, index) => {
|
|
191
|
-
const step =
|
|
192
|
-
return Boolean(step?.opType === "update" && !
|
|
192
|
+
const step = historyService.getStepList("dataSource", id)[index]?.step;
|
|
193
|
+
return Boolean(step?.opType === "update" && !dataSourceService.getDataSourceById(`${id}`));
|
|
193
194
|
};
|
|
194
195
|
/** 代码块 update 步骤回滚时,对应代码块必须仍存在(已删除则无处写回旧值)。 */
|
|
195
196
|
const isCodeBlockRevertTargetMissing = (id, index) => {
|
|
196
|
-
const step =
|
|
197
|
-
return Boolean(step?.opType === "update" && !
|
|
197
|
+
const step = historyService.getStepList("codeBlock", id)[index]?.step;
|
|
198
|
+
return Boolean(step?.opType === "update" && !codeBlockService.getCodeContentById(id));
|
|
198
199
|
};
|
|
199
200
|
const onPageRevert = (index) => {
|
|
200
201
|
if (isPageRevertTargetMissing(index)) {
|
|
201
202
|
showRevertTargetMissing();
|
|
202
203
|
return Promise.resolve(null);
|
|
203
204
|
}
|
|
204
|
-
return runRevert(buildPageDiffPayload(index), { compareFormState: getPropsPanelFormState?.() }).then((result) => result ?
|
|
205
|
+
return runRevert(buildPageDiffPayload(index), { compareFormState: getPropsPanelFormState?.() }).then((result) => result ? editorService.revertPageStep(index) : null);
|
|
205
206
|
};
|
|
206
207
|
const onDataSourceRevert = (id, index) => {
|
|
207
208
|
if (isDataSourceRevertTargetMissing(id, index)) {
|
|
208
209
|
showRevertTargetMissing();
|
|
209
210
|
return Promise.resolve(null);
|
|
210
211
|
}
|
|
211
|
-
return runRevert(buildDataSourceDiffPayload(id, index)).then((result) => result ?
|
|
212
|
+
return runRevert(buildDataSourceDiffPayload(id, index)).then((result) => result ? dataSourceService.revert(id, index) : null);
|
|
212
213
|
};
|
|
213
214
|
const onCodeBlockRevert = (id, index) => {
|
|
214
215
|
if (isCodeBlockRevertTargetMissing(id, index)) {
|
|
215
216
|
showRevertTargetMissing();
|
|
216
217
|
return Promise.resolve(null);
|
|
217
218
|
}
|
|
218
|
-
return runRevert(buildCodeBlockDiffPayload(id, index)).then((result) => result ?
|
|
219
|
+
return runRevert(buildCodeBlockDiffPayload(id, index)).then((result) => result ? codeBlockService.revert(id, index) : null);
|
|
219
220
|
};
|
|
220
221
|
/**
|
|
221
222
|
* 「查看差异」:可差异对比的步骤(单实体 update)动态挂载只读 HistoryDiffDialog 展示前后值差异,
|
|
@@ -56,7 +56,6 @@ var CodeBlock = class extends BaseService {
|
|
|
56
56
|
async setCodeDsl(codeDsl) {
|
|
57
57
|
this.state.codeDsl = codeDsl;
|
|
58
58
|
this.emit("code-dsl-change", this.state.codeDsl);
|
|
59
|
-
this.emit("change", this.state.codeDsl);
|
|
60
59
|
}
|
|
61
60
|
/**
|
|
62
61
|
* 获取活动的代码块dsl数据源(默认从dsl中的codeBlocks字段读取)
|
|
@@ -133,7 +132,6 @@ var CodeBlock = class extends BaseService {
|
|
|
133
132
|
this.lastPushedHistoryId = (step ? history_default.push("codeBlock", step, id) : null)?.uuid ?? null;
|
|
134
133
|
}
|
|
135
134
|
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
136
|
-
this.emit("change", this.getCodeDsl());
|
|
137
135
|
}
|
|
138
136
|
/**
|
|
139
137
|
* 根据代码块id数组获取代码dsl
|
|
@@ -231,7 +229,6 @@ var CodeBlock = class extends BaseService {
|
|
|
231
229
|
}
|
|
232
230
|
this.emit("remove", id);
|
|
233
231
|
});
|
|
234
|
-
this.emit("change", this.getCodeDsl());
|
|
235
232
|
}
|
|
236
233
|
/**
|
|
237
234
|
* 下列 *AndGetHistoryId 方法与对应的写入方法行为完全一致,
|
|
@@ -102,7 +102,6 @@ var DataSource = class extends BaseService {
|
|
|
102
102
|
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, newConfig.id) : null)?.uuid ?? null;
|
|
103
103
|
}
|
|
104
104
|
this.emit("add", newConfig);
|
|
105
|
-
this.emit("change", this.get("dataSources"));
|
|
106
105
|
return newConfig;
|
|
107
106
|
}
|
|
108
107
|
/**
|
|
@@ -133,7 +132,6 @@ var DataSource = class extends BaseService {
|
|
|
133
132
|
oldConfig,
|
|
134
133
|
changeRecords
|
|
135
134
|
});
|
|
136
|
-
this.emit("change", this.get("dataSources"));
|
|
137
135
|
return newConfig;
|
|
138
136
|
}
|
|
139
137
|
/**
|
|
@@ -158,7 +156,6 @@ var DataSource = class extends BaseService {
|
|
|
158
156
|
this.lastPushedHistoryId = (step ? history_default.push("dataSource", step, id) : null)?.uuid ?? null;
|
|
159
157
|
}
|
|
160
158
|
this.emit("remove", id);
|
|
161
|
-
this.emit("change", this.get("dataSources"));
|
|
162
159
|
}
|
|
163
160
|
/**
|
|
164
161
|
* 下列 *AndGetHistoryId 方法与对应的 add / update / remove 行为完全一致,
|
|
@@ -335,13 +335,6 @@ var Editor = class extends BaseService {
|
|
|
335
335
|
} else this.selectionBeforeOp = null;
|
|
336
336
|
}
|
|
337
337
|
this.emit("add", newNodes);
|
|
338
|
-
this.emit("change", {
|
|
339
|
-
type: "add",
|
|
340
|
-
data: newNodes.map((node) => ({
|
|
341
|
-
node,
|
|
342
|
-
page: this.getPageOfNode(node.id)
|
|
343
|
-
}))
|
|
344
|
-
});
|
|
345
338
|
return Array.isArray(addNode) ? newNodes : newNodes[0];
|
|
346
339
|
}
|
|
347
340
|
async doRemove(node, { doNotSelect = false, doNotSwitchPage = false } = {}) {
|
|
@@ -405,10 +398,6 @@ var Editor = class extends BaseService {
|
|
|
405
398
|
async remove(nodeOrNodeList, { doNotSelect = false, doNotSwitchPage = false, doNotPushHistory = false, historyDescription, historySource } = {}) {
|
|
406
399
|
this.captureSelectionBeforeOp();
|
|
407
400
|
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
|
408
|
-
const changeItems = nodes.map((node) => ({
|
|
409
|
-
node,
|
|
410
|
-
page: this.getPageOfNode(node.id)
|
|
411
|
-
}));
|
|
412
401
|
const removedItems = [];
|
|
413
402
|
let pageForOp = null;
|
|
414
403
|
if (!(isPage(nodes[0]) || isPageFragment(nodes[0]))) for (const n of nodes) {
|
|
@@ -438,10 +427,6 @@ var Editor = class extends BaseService {
|
|
|
438
427
|
});
|
|
439
428
|
else this.selectionBeforeOp = null;
|
|
440
429
|
this.emit("remove", nodes);
|
|
441
|
-
this.emit("change", {
|
|
442
|
-
type: "remove",
|
|
443
|
-
data: changeItems
|
|
444
|
-
});
|
|
445
430
|
}
|
|
446
431
|
async doUpdate(config, { changeRecords = [], historySource } = {}) {
|
|
447
432
|
if (!this.get("root")) throw new Error("root为空");
|
|
@@ -527,13 +512,6 @@ var Editor = class extends BaseService {
|
|
|
527
512
|
} else this.selectionBeforeOp = null;
|
|
528
513
|
}
|
|
529
514
|
this.emit("update", updateData);
|
|
530
|
-
this.emit("change", {
|
|
531
|
-
type: "update",
|
|
532
|
-
data: updateData.map((node) => ({
|
|
533
|
-
node,
|
|
534
|
-
page: this.getPageOfNode(node.newNode.id)
|
|
535
|
-
}))
|
|
536
|
-
});
|
|
537
515
|
return Array.isArray(config) ? updateData.map((item) => item.newNode) : updateData[0].newNode;
|
|
538
516
|
}
|
|
539
517
|
/**
|
|
@@ -699,14 +677,6 @@ var Editor = class extends BaseService {
|
|
|
699
677
|
});
|
|
700
678
|
} else this.selectionBeforeOp = null;
|
|
701
679
|
this.emit("move-layer", offset);
|
|
702
|
-
this.emit("change", {
|
|
703
|
-
type: "move-layer",
|
|
704
|
-
data: [{
|
|
705
|
-
node,
|
|
706
|
-
page: this.getPageOfNode(node.id)
|
|
707
|
-
}],
|
|
708
|
-
offset
|
|
709
|
-
});
|
|
710
680
|
}
|
|
711
681
|
/**
|
|
712
682
|
* 移动一个或多个节点到指定容器中。
|
|
@@ -836,15 +806,6 @@ var Editor = class extends BaseService {
|
|
|
836
806
|
configs,
|
|
837
807
|
targetParent
|
|
838
808
|
});
|
|
839
|
-
this.emit("change", {
|
|
840
|
-
type: "drag-to",
|
|
841
|
-
data: configs.map((node) => ({
|
|
842
|
-
node,
|
|
843
|
-
page: this.getPageOfNode(node.id)
|
|
844
|
-
})),
|
|
845
|
-
targetIndex,
|
|
846
|
-
targetParent
|
|
847
|
-
});
|
|
848
809
|
}
|
|
849
810
|
/**
|
|
850
811
|
* 下列 *AndGetHistoryId 方法与对应的普通操作(add / remove / update ...)行为完全一致,
|
|
@@ -1103,19 +1064,6 @@ var Editor = class extends BaseService {
|
|
|
1103
1064
|
addModifiedNodeId(id) {
|
|
1104
1065
|
this.get("modifiedNodeIds").set(id, id);
|
|
1105
1066
|
}
|
|
1106
|
-
/**
|
|
1107
|
-
* 获取指定节点所属的页面 / 页面片:
|
|
1108
|
-
* - 普通节点返回其所在的 page;
|
|
1109
|
-
* - 节点本身就是 page / pageFragment 时返回它自己;
|
|
1110
|
-
* - 找不到时返回 null。
|
|
1111
|
-
* 供 `change` 事件携带「变更节点对应的 page」(而非编辑器当前选中页)。
|
|
1112
|
-
*/
|
|
1113
|
-
getPageOfNode(id) {
|
|
1114
|
-
const { node, page } = this.getNodeInfo(id, false);
|
|
1115
|
-
if (page) return page;
|
|
1116
|
-
if (node && (isPage(node) || isPageFragment(node))) return node;
|
|
1117
|
-
return null;
|
|
1118
|
-
}
|
|
1119
1067
|
captureSelectionBeforeOp() {
|
|
1120
1068
|
if (this.selectionBeforeOp) return;
|
|
1121
1069
|
this.selectionBeforeOp = this.get("nodes").map((n) => n.id);
|