@tmagic/editor 1.2.9 → 1.2.11
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/style.css +26 -32
- package/dist/tmagic-editor.js +1694 -1342
- package/dist/tmagic-editor.js.map +1 -1
- package/dist/tmagic-editor.umd.cjs +1699 -1344
- package/dist/tmagic-editor.umd.cjs.map +1 -1
- package/package.json +9 -9
- package/src/Editor.vue +10 -240
- package/src/components/CodeDraftEditor.vue +10 -6
- package/src/components/FunctionEditor.vue +1 -1
- package/src/editorProps.ts +135 -0
- package/src/fields/CodeSelect.vue +24 -13
- package/src/fields/CodeSelectCol.vue +117 -0
- package/src/fields/EventSelect.vue +216 -0
- package/src/index.ts +7 -0
- package/src/initService.ts +198 -0
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +49 -127
- package/src/services/codeBlock.ts +29 -150
- package/src/services/dep.ts +328 -0
- package/src/services/editor.ts +2 -28
- package/src/theme/code-block.scss +5 -33
- package/src/theme/event.scss +24 -0
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +18 -3
- package/src/utils/dep.ts +21 -0
- package/src/utils/props.ts +1 -35
- package/types/Editor.vue.d.ts +49 -82
- package/types/editorProps.d.ts +109 -0
- package/types/fields/CodeSelect.vue.d.ts +28 -5
- package/types/fields/CodeSelectCol.vue.d.ts +30 -0
- package/types/fields/EventSelect.vue.d.ts +26 -0
- package/types/index.d.ts +3 -0
- package/types/initService.d.ts +8 -0
- package/types/services/codeBlock.d.ts +3 -36
- package/types/services/dep.d.ts +130 -0
- package/types/services/editor.d.ts +1 -13
- package/types/services/props.d.ts +1 -15
- package/types/type.d.ts +17 -3
- package/types/utils/dep.d.ts +3 -0
- package/types/utils/props.d.ts +2 -16
package/dist/tmagic-editor.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, inject, createCommentVNode, ref,
|
|
1
|
+
import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, unref, reactive, watch, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, inject, createCommentVNode, ref, Fragment, renderList, createTextVNode, withModifiers, toDisplayString, onMounted, onUnmounted, renderSlot, createSlots, normalizeProps, mergeProps, markRaw, getCurrentInstance, watchEffect, provide, withDirectives, Teleport, vShow, nextTick, toHandlers } from 'vue';
|
|
2
2
|
import serialize from 'serialize-javascript';
|
|
3
|
-
import { Edit, View, Delete, Close, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back,
|
|
4
|
-
import { isEmpty, map, throttle, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick,
|
|
3
|
+
import { Edit, View, Delete, Close, Plus, ArrowDown, Grid, Memo, FullScreen, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Search, Files, CopyDocument, Coin, EditPen, ArrowLeftBold, ArrowRightBold, CaretBottom, DocumentCopy, Top, Bottom } from '@element-plus/icons-vue';
|
|
4
|
+
import { isEmpty, map, has, throttle, cloneDeep, mergeWith, isObject, uniq, forIn, difference, union, pick, keys } from 'lodash-es';
|
|
5
5
|
import { createValues, MForm } from '@tmagic/form';
|
|
6
|
-
import { HookType, NodeType } from '@tmagic/schema';
|
|
6
|
+
import { HookType, ActionType, NodeType } from '@tmagic/schema';
|
|
7
7
|
import { TMagicIcon, TMagicButton, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, tMagicMessage, tMagicMessageBox, TMagicCard, TMagicInput, TMagicDialog, TMagicTree, TMagicCollapse, TMagicCollapseItem, getConfig as getConfig$1, TMagicTabs, TMagicPopover } from '@tmagic/design';
|
|
8
8
|
import * as monaco from 'monaco-editor';
|
|
9
|
-
import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
|
|
10
9
|
import Gesto from 'gesto';
|
|
11
10
|
import { isPop, getNodePath, isNumber, isPage, toLine, datetimeFormatter, removeClassNameByClassName } from '@tmagic/utils';
|
|
11
|
+
import StageCore, { GuidesType, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
|
-
import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
|
|
14
13
|
import KeyController from 'keycon';
|
|
14
|
+
import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
|
|
15
15
|
|
|
16
|
-
const __default__$
|
|
16
|
+
const __default__$v = defineComponent({
|
|
17
17
|
name: "MEditorCode"
|
|
18
18
|
});
|
|
19
|
-
const _sfc_main$
|
|
20
|
-
...__default__$
|
|
19
|
+
const _sfc_main$w = /* @__PURE__ */ defineComponent({
|
|
20
|
+
...__default__$v,
|
|
21
21
|
props: {
|
|
22
22
|
model: null,
|
|
23
23
|
name: null,
|
|
@@ -46,11 +46,11 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
const __default__$
|
|
49
|
+
const __default__$u = defineComponent({
|
|
50
50
|
name: "MEditorCodeLink"
|
|
51
51
|
});
|
|
52
|
-
const _sfc_main$
|
|
53
|
-
...__default__$
|
|
52
|
+
const _sfc_main$v = /* @__PURE__ */ defineComponent({
|
|
53
|
+
...__default__$u,
|
|
54
54
|
props: {
|
|
55
55
|
config: null,
|
|
56
56
|
model: null,
|
|
@@ -119,12 +119,12 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
|
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
const _hoisted_1$
|
|
123
|
-
const __default__$
|
|
122
|
+
const _hoisted_1$h = ["src"];
|
|
123
|
+
const __default__$t = defineComponent({
|
|
124
124
|
name: "MEditorIcon"
|
|
125
125
|
});
|
|
126
|
-
const _sfc_main$
|
|
127
|
-
...__default__$
|
|
126
|
+
const _sfc_main$u = /* @__PURE__ */ defineComponent({
|
|
127
|
+
...__default__$t,
|
|
128
128
|
props: {
|
|
129
129
|
icon: null
|
|
130
130
|
},
|
|
@@ -143,7 +143,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
|
|
|
143
143
|
class: "magic-editor-icon"
|
|
144
144
|
}, {
|
|
145
145
|
default: withCtx(() => [
|
|
146
|
-
createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$
|
|
146
|
+
createElementVNode("img", { src: __props.icon }, null, 8, _hoisted_1$h)
|
|
147
147
|
]),
|
|
148
148
|
_: 1
|
|
149
149
|
})) : typeof __props.icon === "string" ? (openBlock(), createElementBlock("i", {
|
|
@@ -162,14 +162,15 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
-
const
|
|
166
|
-
const __default__$q = defineComponent({
|
|
165
|
+
const __default__$s = defineComponent({
|
|
167
166
|
name: "MEditorCodeSelect"
|
|
168
167
|
});
|
|
169
|
-
const _sfc_main$
|
|
170
|
-
...__default__$
|
|
168
|
+
const _sfc_main$t = /* @__PURE__ */ defineComponent({
|
|
169
|
+
...__default__$s,
|
|
171
170
|
props: {
|
|
172
|
-
config:
|
|
171
|
+
config: { default: () => ({
|
|
172
|
+
editable: true
|
|
173
|
+
}) },
|
|
173
174
|
model: null,
|
|
174
175
|
prop: null,
|
|
175
176
|
name: null,
|
|
@@ -180,7 +181,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
180
181
|
const props = __props;
|
|
181
182
|
const services = inject("services");
|
|
182
183
|
const mForm = inject("mForm");
|
|
183
|
-
const codeDsl = computed(() => services?.codeBlockService.
|
|
184
|
+
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
184
185
|
const tableConfig = computed(() => {
|
|
185
186
|
const defaultConfig = {
|
|
186
187
|
dropSort: false,
|
|
@@ -213,7 +214,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
213
214
|
defaultValue: {},
|
|
214
215
|
itemsFunction: (row) => {
|
|
215
216
|
const paramsConfig = getParamsConfig(row.codeId);
|
|
216
|
-
if (
|
|
217
|
+
if (!row.params || isEmpty(row.params)) {
|
|
217
218
|
createValues(mForm, paramsConfig, {}, row.params);
|
|
218
219
|
}
|
|
219
220
|
return paramsConfig;
|
|
@@ -253,6 +254,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
253
254
|
return paramStatements.map((paramState) => ({
|
|
254
255
|
labelWidth: "100px",
|
|
255
256
|
text: paramState.name,
|
|
257
|
+
inline: true,
|
|
256
258
|
...paramState
|
|
257
259
|
}));
|
|
258
260
|
};
|
|
@@ -261,7 +263,9 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
261
263
|
};
|
|
262
264
|
return (_ctx, _cache) => {
|
|
263
265
|
const _component_m_form_table = resolveComponent("m-form-table");
|
|
264
|
-
return openBlock(), createElementBlock("div",
|
|
266
|
+
return openBlock(), createElementBlock("div", {
|
|
267
|
+
class: normalizeClass(["m-fields-code-select", __props.config.className])
|
|
268
|
+
}, [
|
|
265
269
|
createVNode(_component_m_form_table, {
|
|
266
270
|
config: unref(tableConfig),
|
|
267
271
|
model: __props.model[__props.name],
|
|
@@ -272,7 +276,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
272
276
|
onChange: changeHandler
|
|
273
277
|
}, {
|
|
274
278
|
operateCol: withCtx(({ scope }) => [
|
|
275
|
-
scope.row.codeId ? (openBlock(), createBlock(_sfc_main$
|
|
279
|
+
scope.row.codeId && __props.config.editable ? (openBlock(), createBlock(_sfc_main$u, {
|
|
276
280
|
key: 0,
|
|
277
281
|
icon: unref(editable) ? unref(Edit) : unref(View),
|
|
278
282
|
class: "edit-icon",
|
|
@@ -281,6 +285,326 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
|
281
285
|
]),
|
|
282
286
|
_: 1
|
|
283
287
|
}, 8, ["config", "model", "prop", "size"])
|
|
288
|
+
], 2);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const _hoisted_1$g = { class: "m-fields-code-select-col" };
|
|
294
|
+
const __default__$r = defineComponent({
|
|
295
|
+
name: "MEditorCodeSelectCol"
|
|
296
|
+
});
|
|
297
|
+
const _sfc_main$s = /* @__PURE__ */ defineComponent({
|
|
298
|
+
...__default__$r,
|
|
299
|
+
props: {
|
|
300
|
+
config: null,
|
|
301
|
+
model: null,
|
|
302
|
+
prop: null,
|
|
303
|
+
name: null,
|
|
304
|
+
size: null
|
|
305
|
+
},
|
|
306
|
+
emits: ["change"],
|
|
307
|
+
setup(__props, { emit }) {
|
|
308
|
+
const props = __props;
|
|
309
|
+
const services = inject("services");
|
|
310
|
+
const mForm = inject("mForm");
|
|
311
|
+
const codeDsl = computed(() => services?.codeBlockService.getCodeDsl());
|
|
312
|
+
const codeParamsConfig = ref({
|
|
313
|
+
type: "fieldset",
|
|
314
|
+
items: [],
|
|
315
|
+
legend: "\u53C2\u6570",
|
|
316
|
+
labelWidth: "70px",
|
|
317
|
+
name: "params",
|
|
318
|
+
display: false
|
|
319
|
+
});
|
|
320
|
+
const selectConfig = {
|
|
321
|
+
type: "select",
|
|
322
|
+
text: "\u4EE3\u7801\u5757",
|
|
323
|
+
name: "codeId",
|
|
324
|
+
labelWidth: "70px",
|
|
325
|
+
options: () => {
|
|
326
|
+
if (codeDsl.value) {
|
|
327
|
+
return map(codeDsl.value, (value, key) => ({
|
|
328
|
+
text: `${value.name}\uFF08${key}\uFF09`,
|
|
329
|
+
label: `${value.name}\uFF08${key}\uFF09`,
|
|
330
|
+
value: key
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
return [];
|
|
334
|
+
},
|
|
335
|
+
onChange: (formState, codeId, { model }) => {
|
|
336
|
+
model.params = {};
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const getParamItemsConfig = (codeId) => {
|
|
340
|
+
if (!codeDsl.value)
|
|
341
|
+
return [];
|
|
342
|
+
const paramStatements = codeDsl.value[codeId]?.params;
|
|
343
|
+
if (isEmpty(paramStatements))
|
|
344
|
+
return [];
|
|
345
|
+
return paramStatements.map((paramState) => ({
|
|
346
|
+
labelWidth: "100px",
|
|
347
|
+
text: paramState.name,
|
|
348
|
+
...paramState
|
|
349
|
+
}));
|
|
350
|
+
};
|
|
351
|
+
const getCodeParamsConfig = (codeId) => {
|
|
352
|
+
const paramsConfig = getParamItemsConfig(codeId);
|
|
353
|
+
if (!props.model.params || isEmpty(props.model.params)) {
|
|
354
|
+
props.model.params = {};
|
|
355
|
+
createValues(mForm, paramsConfig, {}, props.model.params);
|
|
356
|
+
}
|
|
357
|
+
codeParamsConfig.value = {
|
|
358
|
+
type: "fieldset",
|
|
359
|
+
items: paramsConfig,
|
|
360
|
+
legend: "\u53C2\u6570",
|
|
361
|
+
labelWidth: "70px",
|
|
362
|
+
name: "params",
|
|
363
|
+
display: !isEmpty(paramsConfig)
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
const onParamsChangeHandler = () => {
|
|
367
|
+
emit("change", props.model);
|
|
368
|
+
};
|
|
369
|
+
watch(
|
|
370
|
+
() => props.model.codeId,
|
|
371
|
+
(codeId) => {
|
|
372
|
+
if (!codeId)
|
|
373
|
+
return;
|
|
374
|
+
getCodeParamsConfig(codeId);
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
immediate: true
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
return (_ctx, _cache) => {
|
|
381
|
+
const _component_m_form_container = resolveComponent("m-form-container");
|
|
382
|
+
return openBlock(), createElementBlock("div", _hoisted_1$g, [
|
|
383
|
+
createVNode(_component_m_form_container, {
|
|
384
|
+
config: selectConfig,
|
|
385
|
+
model: __props.model,
|
|
386
|
+
onChange: onParamsChangeHandler
|
|
387
|
+
}, null, 8, ["model"]),
|
|
388
|
+
createVNode(_component_m_form_container, {
|
|
389
|
+
config: codeParamsConfig.value,
|
|
390
|
+
model: __props.model,
|
|
391
|
+
onChange: onParamsChangeHandler
|
|
392
|
+
}, null, 8, ["config", "model"])
|
|
393
|
+
]);
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
const _hoisted_1$f = { class: "m-fields-event-select" };
|
|
399
|
+
const _hoisted_2$7 = {
|
|
400
|
+
key: 1,
|
|
401
|
+
class: "fullWidth"
|
|
402
|
+
};
|
|
403
|
+
const _hoisted_3$4 = /* @__PURE__ */ createTextVNode("\u6DFB\u52A0\u4E8B\u4EF6");
|
|
404
|
+
const __default__$q = defineComponent({
|
|
405
|
+
name: "MEditorEventSelect"
|
|
406
|
+
});
|
|
407
|
+
const _sfc_main$r = /* @__PURE__ */ defineComponent({
|
|
408
|
+
...__default__$q,
|
|
409
|
+
props: {
|
|
410
|
+
config: null,
|
|
411
|
+
model: null,
|
|
412
|
+
prop: null,
|
|
413
|
+
name: null,
|
|
414
|
+
size: null
|
|
415
|
+
},
|
|
416
|
+
emits: ["change"],
|
|
417
|
+
setup(__props, { emit }) {
|
|
418
|
+
const props = __props;
|
|
419
|
+
const services = inject("services");
|
|
420
|
+
const eventNameConfig = computed(() => {
|
|
421
|
+
const defaultEventNameConfig = {
|
|
422
|
+
name: "name",
|
|
423
|
+
text: "\u4E8B\u4EF6",
|
|
424
|
+
type: "select",
|
|
425
|
+
labelWidth: "40px",
|
|
426
|
+
options: (mForm, { formValue }) => services?.eventsService.getEvent(formValue.type).map((option) => ({
|
|
427
|
+
text: option.label,
|
|
428
|
+
value: option.value
|
|
429
|
+
}))
|
|
430
|
+
};
|
|
431
|
+
return { ...defaultEventNameConfig, ...props.config.eventNameConfig };
|
|
432
|
+
});
|
|
433
|
+
const actionTypeConfig = computed(() => {
|
|
434
|
+
const defaultActionTypeConfig = {
|
|
435
|
+
name: "actionType",
|
|
436
|
+
text: "\u8054\u52A8\u7C7B\u578B",
|
|
437
|
+
labelWidth: "70px",
|
|
438
|
+
type: "select",
|
|
439
|
+
defaultValue: ActionType.COMP,
|
|
440
|
+
options: () => [
|
|
441
|
+
{
|
|
442
|
+
text: "\u7EC4\u4EF6",
|
|
443
|
+
label: "\u7EC4\u4EF6",
|
|
444
|
+
value: ActionType.COMP
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
text: "\u4EE3\u7801",
|
|
448
|
+
label: "\u4EE3\u7801",
|
|
449
|
+
value: ActionType.CODE
|
|
450
|
+
}
|
|
451
|
+
]
|
|
452
|
+
};
|
|
453
|
+
return { ...defaultActionTypeConfig, ...props.config.actionTypeConfig };
|
|
454
|
+
});
|
|
455
|
+
const targetCompConfig = computed(() => {
|
|
456
|
+
const defaultTargetCompConfig = {
|
|
457
|
+
name: "to",
|
|
458
|
+
text: "\u8054\u52A8\u7EC4\u4EF6",
|
|
459
|
+
labelWidth: "70px",
|
|
460
|
+
type: "ui-select",
|
|
461
|
+
display: (mForm, { model }) => model.actionType === ActionType.COMP
|
|
462
|
+
};
|
|
463
|
+
return { ...defaultTargetCompConfig, ...props.config.targetCompConfig };
|
|
464
|
+
});
|
|
465
|
+
const compActionConfig = computed(() => {
|
|
466
|
+
const defaultCompActionConfig = {
|
|
467
|
+
name: "method",
|
|
468
|
+
text: "\u52A8\u4F5C",
|
|
469
|
+
labelWidth: "70px",
|
|
470
|
+
type: "select",
|
|
471
|
+
display: (mForm, { model }) => model.actionType === ActionType.COMP,
|
|
472
|
+
options: (mForm, { model }) => {
|
|
473
|
+
const node = services?.editorService.getNodeById(model.to);
|
|
474
|
+
if (!node?.type)
|
|
475
|
+
return [];
|
|
476
|
+
return services?.eventsService.getMethod(node.type).map((option) => ({
|
|
477
|
+
text: option.label,
|
|
478
|
+
value: option.value
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
return { ...defaultCompActionConfig, ...props.config.compActionConfig };
|
|
483
|
+
});
|
|
484
|
+
const codeActionConfig = computed(() => {
|
|
485
|
+
const defaultCodeActionConfig = {
|
|
486
|
+
type: "code-select-col",
|
|
487
|
+
display: (mForm, { model }) => model.actionType === ActionType.CODE
|
|
488
|
+
};
|
|
489
|
+
return { ...defaultCodeActionConfig, ...props.config.codeActionConfig };
|
|
490
|
+
});
|
|
491
|
+
const tableConfig = computed(() => ({
|
|
492
|
+
type: "table",
|
|
493
|
+
name: "events",
|
|
494
|
+
items: [
|
|
495
|
+
{
|
|
496
|
+
name: "name",
|
|
497
|
+
label: "\u4E8B\u4EF6\u540D",
|
|
498
|
+
type: eventNameConfig.value.type,
|
|
499
|
+
options: (mForm, { formValue }) => services?.eventsService.getEvent(formValue.type).map((option) => ({
|
|
500
|
+
text: option.label,
|
|
501
|
+
value: option.value
|
|
502
|
+
}))
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
name: "to",
|
|
506
|
+
label: "\u8054\u52A8\u7EC4\u4EF6",
|
|
507
|
+
type: "ui-select"
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: "method",
|
|
511
|
+
label: "\u52A8\u4F5C",
|
|
512
|
+
type: compActionConfig.value.type,
|
|
513
|
+
options: (mForm, { model }) => {
|
|
514
|
+
const node = services?.editorService.getNodeById(model.to);
|
|
515
|
+
if (!node?.type)
|
|
516
|
+
return [];
|
|
517
|
+
return services?.eventsService.getMethod(node.type).map((option) => ({
|
|
518
|
+
text: option.label,
|
|
519
|
+
value: option.value
|
|
520
|
+
}));
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
}));
|
|
525
|
+
const actionsConfig = computed(() => ({
|
|
526
|
+
items: [
|
|
527
|
+
{
|
|
528
|
+
type: "group-list",
|
|
529
|
+
name: "actions",
|
|
530
|
+
enableToggleMode: false,
|
|
531
|
+
items: [actionTypeConfig.value, targetCompConfig.value, compActionConfig.value, codeActionConfig.value]
|
|
532
|
+
}
|
|
533
|
+
]
|
|
534
|
+
}));
|
|
535
|
+
const isOldVersion = computed(() => {
|
|
536
|
+
if (props.model[props.name].length === 0)
|
|
537
|
+
return false;
|
|
538
|
+
return !has(props.model[props.name][0], "actions");
|
|
539
|
+
});
|
|
540
|
+
const addEvent = () => {
|
|
541
|
+
const defaultEvent = {
|
|
542
|
+
name: "",
|
|
543
|
+
actions: []
|
|
544
|
+
};
|
|
545
|
+
if (!props.model[props.name]) {
|
|
546
|
+
props.model[props.name] = [];
|
|
547
|
+
}
|
|
548
|
+
props.model[props.name].push(defaultEvent);
|
|
549
|
+
onChangeHandler();
|
|
550
|
+
};
|
|
551
|
+
const removeEvent = (index) => {
|
|
552
|
+
if (!props.name)
|
|
553
|
+
return;
|
|
554
|
+
props.model[props.name].splice(index, 1);
|
|
555
|
+
onChangeHandler();
|
|
556
|
+
};
|
|
557
|
+
const onChangeHandler = () => {
|
|
558
|
+
emit("change", props.model);
|
|
559
|
+
};
|
|
560
|
+
return (_ctx, _cache) => {
|
|
561
|
+
const _component_m_form_container = resolveComponent("m-form-container");
|
|
562
|
+
const _component_m_form_panel = resolveComponent("m-form-panel");
|
|
563
|
+
return openBlock(), createElementBlock("div", _hoisted_1$f, [
|
|
564
|
+
unref(isOldVersion) ? (openBlock(), createBlock(_component_m_form_container, {
|
|
565
|
+
key: 0,
|
|
566
|
+
ref: "eventForm",
|
|
567
|
+
size: props.size,
|
|
568
|
+
model: __props.model,
|
|
569
|
+
config: unref(tableConfig),
|
|
570
|
+
onChange: onChangeHandler
|
|
571
|
+
}, null, 8, ["size", "model", "config"])) : (openBlock(), createElementBlock("div", _hoisted_2$7, [
|
|
572
|
+
createVNode(unref(TMagicButton), {
|
|
573
|
+
class: "create-button",
|
|
574
|
+
type: "primary",
|
|
575
|
+
size: "small",
|
|
576
|
+
onClick: _cache[0] || (_cache[0] = ($event) => addEvent())
|
|
577
|
+
}, {
|
|
578
|
+
default: withCtx(() => [
|
|
579
|
+
_hoisted_3$4
|
|
580
|
+
]),
|
|
581
|
+
_: 1
|
|
582
|
+
}),
|
|
583
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.model[__props.name], (cardItem, index) => {
|
|
584
|
+
return openBlock(), createBlock(_component_m_form_panel, {
|
|
585
|
+
key: index,
|
|
586
|
+
config: unref(actionsConfig),
|
|
587
|
+
model: cardItem,
|
|
588
|
+
onChange: onChangeHandler
|
|
589
|
+
}, {
|
|
590
|
+
header: withCtx(() => [
|
|
591
|
+
createVNode(_component_m_form_container, {
|
|
592
|
+
class: "fullWidth",
|
|
593
|
+
config: unref(eventNameConfig),
|
|
594
|
+
model: cardItem,
|
|
595
|
+
onChange: onChangeHandler
|
|
596
|
+
}, null, 8, ["config", "model"]),
|
|
597
|
+
createVNode(unref(TMagicButton), {
|
|
598
|
+
style: { "color": "#f56c6c" },
|
|
599
|
+
text: "",
|
|
600
|
+
icon: unref(Delete),
|
|
601
|
+
onClick: ($event) => removeEvent(index)
|
|
602
|
+
}, null, 8, ["icon", "onClick"])
|
|
603
|
+
]),
|
|
604
|
+
_: 2
|
|
605
|
+
}, 1032, ["config", "model"]);
|
|
606
|
+
}), 128))
|
|
607
|
+
]))
|
|
284
608
|
]);
|
|
285
609
|
};
|
|
286
610
|
}
|
|
@@ -704,341 +1028,211 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
|
|
|
704
1028
|
}
|
|
705
1029
|
});
|
|
706
1030
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
1031
|
+
const fillConfig = (config = []) => [
|
|
1032
|
+
{
|
|
1033
|
+
type: "tab",
|
|
1034
|
+
items: [
|
|
1035
|
+
{
|
|
1036
|
+
title: "\u5C5E\u6027",
|
|
1037
|
+
labelWidth: "80px",
|
|
1038
|
+
items: [
|
|
1039
|
+
{
|
|
1040
|
+
text: "type",
|
|
1041
|
+
name: "type",
|
|
1042
|
+
type: "hidden"
|
|
1043
|
+
},
|
|
1044
|
+
{
|
|
1045
|
+
name: "id",
|
|
1046
|
+
type: "display",
|
|
1047
|
+
text: "id"
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
name: "name",
|
|
1051
|
+
text: "\u7EC4\u4EF6\u540D\u79F0"
|
|
1052
|
+
},
|
|
1053
|
+
...config
|
|
1054
|
+
]
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
title: "\u6837\u5F0F",
|
|
1058
|
+
labelWidth: "80px",
|
|
1059
|
+
items: [
|
|
1060
|
+
{
|
|
1061
|
+
name: "style",
|
|
1062
|
+
items: [
|
|
1063
|
+
{
|
|
1064
|
+
type: "fieldset",
|
|
1065
|
+
legend: "\u4F4D\u7F6E",
|
|
1066
|
+
items: [
|
|
1067
|
+
{
|
|
1068
|
+
name: "position",
|
|
1069
|
+
type: "checkbox",
|
|
1070
|
+
activeValue: "fixed",
|
|
1071
|
+
inactiveValue: "absolute",
|
|
1072
|
+
defaultValue: "absolute",
|
|
1073
|
+
text: "\u56FA\u5B9A\u5B9A\u4F4D"
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
name: "left",
|
|
1077
|
+
text: "left"
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
name: "top",
|
|
1081
|
+
text: "top",
|
|
1082
|
+
disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
name: "right",
|
|
1086
|
+
text: "right"
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
name: "bottom",
|
|
1090
|
+
text: "bottom",
|
|
1091
|
+
disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
|
|
1092
|
+
}
|
|
1093
|
+
]
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
type: "fieldset",
|
|
1097
|
+
legend: "\u76D2\u5B50",
|
|
1098
|
+
items: [
|
|
1099
|
+
{
|
|
1100
|
+
name: "width",
|
|
1101
|
+
text: "\u5BBD\u5EA6"
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
name: "height",
|
|
1105
|
+
text: "\u9AD8\u5EA6"
|
|
1106
|
+
}
|
|
1107
|
+
]
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
type: "fieldset",
|
|
1111
|
+
legend: "\u80CC\u666F",
|
|
1112
|
+
items: [
|
|
1113
|
+
{
|
|
1114
|
+
name: "backgroundImage",
|
|
1115
|
+
text: "\u80CC\u666F\u56FE"
|
|
1116
|
+
},
|
|
1117
|
+
{
|
|
1118
|
+
name: "backgroundColor",
|
|
1119
|
+
text: "\u80CC\u666F\u989C\u8272",
|
|
1120
|
+
type: "colorPicker"
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
name: "backgroundRepeat",
|
|
1124
|
+
text: "\u80CC\u666F\u56FE\u91CD\u590D",
|
|
1125
|
+
type: "select",
|
|
1126
|
+
defaultValue: "no-repeat",
|
|
1127
|
+
options: [
|
|
1128
|
+
{ text: "repeat", value: "repeat" },
|
|
1129
|
+
{ text: "repeat-x", value: "repeat-x" },
|
|
1130
|
+
{ text: "repeat-y", value: "repeat-y" },
|
|
1131
|
+
{ text: "no-repeat", value: "no-repeat" },
|
|
1132
|
+
{ text: "inherit", value: "inherit" }
|
|
1133
|
+
]
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
name: "backgroundSize",
|
|
1137
|
+
text: "\u80CC\u666F\u56FE\u5927\u5C0F",
|
|
1138
|
+
defaultValue: "100% 100%"
|
|
1139
|
+
}
|
|
1140
|
+
]
|
|
1141
|
+
},
|
|
1142
|
+
{
|
|
1143
|
+
type: "fieldset",
|
|
1144
|
+
legend: "\u5B57\u4F53",
|
|
1145
|
+
items: [
|
|
1146
|
+
{
|
|
1147
|
+
name: "color",
|
|
1148
|
+
text: "\u989C\u8272",
|
|
1149
|
+
type: "colorPicker"
|
|
1150
|
+
},
|
|
1151
|
+
{
|
|
1152
|
+
name: "fontSize",
|
|
1153
|
+
text: "\u5927\u5C0F"
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
name: "fontWeight",
|
|
1157
|
+
text: "\u7C97\u7EC6"
|
|
1158
|
+
}
|
|
1159
|
+
]
|
|
1160
|
+
},
|
|
1161
|
+
{
|
|
1162
|
+
type: "fieldset",
|
|
1163
|
+
legend: "\u53D8\u5F62",
|
|
1164
|
+
name: "transform",
|
|
1165
|
+
items: [
|
|
1166
|
+
{
|
|
1167
|
+
name: "rotate",
|
|
1168
|
+
text: "\u65CB\u8F6C\u89D2\u5EA6"
|
|
1169
|
+
},
|
|
1170
|
+
{
|
|
1171
|
+
name: "scale",
|
|
1172
|
+
text: "\u7F29\u653E"
|
|
1173
|
+
}
|
|
1174
|
+
]
|
|
833
1175
|
}
|
|
834
|
-
|
|
835
|
-
});
|
|
836
|
-
if (!this.doingTask) {
|
|
837
|
-
this.doTask();
|
|
1176
|
+
]
|
|
838
1177
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1178
|
+
]
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
title: "\u4E8B\u4EF6",
|
|
1182
|
+
items: [
|
|
1183
|
+
{
|
|
1184
|
+
name: "events",
|
|
1185
|
+
type: "event-select"
|
|
1186
|
+
}
|
|
1187
|
+
]
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
title: "\u9AD8\u7EA7",
|
|
1191
|
+
lazy: true,
|
|
1192
|
+
items: [
|
|
1193
|
+
{
|
|
1194
|
+
name: "created",
|
|
1195
|
+
text: "created",
|
|
1196
|
+
labelWidth: "100px",
|
|
1197
|
+
type: "code-select"
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
name: "mounted",
|
|
1201
|
+
text: "mounted",
|
|
1202
|
+
labelWidth: "100px",
|
|
1203
|
+
type: "code-select"
|
|
1204
|
+
}
|
|
1205
|
+
]
|
|
1206
|
+
}
|
|
1207
|
+
]
|
|
843
1208
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1209
|
+
];
|
|
1210
|
+
|
|
1211
|
+
const log = (...args) => {
|
|
1212
|
+
if (process.env.NODE_ENV === "development") {
|
|
1213
|
+
console.log("magic editor: ", ...args);
|
|
849
1214
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
});
|
|
1215
|
+
};
|
|
1216
|
+
const info = (...args) => {
|
|
1217
|
+
if (process.env.NODE_ENV === "development") {
|
|
1218
|
+
console.info("magic editor: ", ...args);
|
|
855
1219
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
Object.keys(this.middleware).forEach((key) => {
|
|
861
|
-
this.middleware[key] = [];
|
|
862
|
-
});
|
|
1220
|
+
};
|
|
1221
|
+
const warn = (...args) => {
|
|
1222
|
+
if (process.env.NODE_ENV === "development") {
|
|
1223
|
+
console.warn("magic editor: ", ...args);
|
|
863
1224
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
await task();
|
|
869
|
-
task = this.taskList.shift();
|
|
870
|
-
}
|
|
871
|
-
this.doingTask = false;
|
|
1225
|
+
};
|
|
1226
|
+
const debug = (...args) => {
|
|
1227
|
+
if (process.env.NODE_ENV === "development") {
|
|
1228
|
+
console.debug("magic editor: ", ...args);
|
|
872
1229
|
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
pageSteps: {},
|
|
878
|
-
pageId: void 0,
|
|
879
|
-
canRedo: false,
|
|
880
|
-
canUndo: false
|
|
881
|
-
});
|
|
882
|
-
constructor() {
|
|
883
|
-
super([]);
|
|
884
|
-
this.on("change", this.setCanUndoRedo);
|
|
885
|
-
}
|
|
886
|
-
reset() {
|
|
887
|
-
this.state.pageSteps = {};
|
|
888
|
-
this.state.pageId = void 0;
|
|
889
|
-
this.state.canRedo = false;
|
|
890
|
-
this.state.canUndo = false;
|
|
891
|
-
}
|
|
892
|
-
changePage(page) {
|
|
893
|
-
if (!page)
|
|
894
|
-
return;
|
|
895
|
-
this.state.pageId = page.id;
|
|
896
|
-
if (!this.state.pageSteps[this.state.pageId]) {
|
|
897
|
-
const undoRedo = new UndoRedo();
|
|
898
|
-
undoRedo.pushElement({
|
|
899
|
-
data: page,
|
|
900
|
-
modifiedNodeIds: /* @__PURE__ */ new Map(),
|
|
901
|
-
nodeId: page.id
|
|
902
|
-
});
|
|
903
|
-
this.state.pageSteps[this.state.pageId] = undoRedo;
|
|
904
|
-
}
|
|
905
|
-
this.setCanUndoRedo();
|
|
906
|
-
this.emit("page-change", this.state.pageSteps[this.state.pageId]);
|
|
907
|
-
}
|
|
908
|
-
resetState() {
|
|
909
|
-
this.state.pageId = void 0;
|
|
910
|
-
this.state.pageSteps = {};
|
|
911
|
-
this.state.canRedo = false;
|
|
912
|
-
this.state.canUndo = false;
|
|
913
|
-
}
|
|
914
|
-
push(state) {
|
|
915
|
-
const undoRedo = this.getUndoRedo();
|
|
916
|
-
if (!undoRedo)
|
|
917
|
-
return null;
|
|
918
|
-
undoRedo.pushElement(state);
|
|
919
|
-
this.emit("change", state);
|
|
920
|
-
return state;
|
|
921
|
-
}
|
|
922
|
-
undo() {
|
|
923
|
-
const undoRedo = this.getUndoRedo();
|
|
924
|
-
if (!undoRedo)
|
|
925
|
-
return null;
|
|
926
|
-
const state = undoRedo.undo();
|
|
927
|
-
this.emit("change", state);
|
|
928
|
-
return state;
|
|
929
|
-
}
|
|
930
|
-
redo() {
|
|
931
|
-
const undoRedo = this.getUndoRedo();
|
|
932
|
-
if (!undoRedo)
|
|
933
|
-
return null;
|
|
934
|
-
const state = undoRedo.redo();
|
|
935
|
-
this.emit("change", state);
|
|
936
|
-
return state;
|
|
937
|
-
}
|
|
938
|
-
destroy() {
|
|
939
|
-
this.resetState();
|
|
940
|
-
this.removeAllListeners();
|
|
941
|
-
this.removeAllPlugins();
|
|
942
|
-
}
|
|
943
|
-
getUndoRedo() {
|
|
944
|
-
if (!this.state.pageId)
|
|
945
|
-
return null;
|
|
946
|
-
return this.state.pageSteps[this.state.pageId];
|
|
947
|
-
}
|
|
948
|
-
setCanUndoRedo() {
|
|
949
|
-
const undoRedo = this.getUndoRedo();
|
|
950
|
-
this.state.canRedo = undoRedo?.canRedo() || false;
|
|
951
|
-
this.state.canUndo = undoRedo?.canUndo() || false;
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
const historyService = new History();
|
|
955
|
-
|
|
956
|
-
var Protocol = /* @__PURE__ */ ((Protocol2) => {
|
|
957
|
-
Protocol2["OBJECT"] = "object";
|
|
958
|
-
Protocol2["JSON"] = "json";
|
|
959
|
-
Protocol2["STRING"] = "string";
|
|
960
|
-
Protocol2["NUMBER"] = "number";
|
|
961
|
-
Protocol2["BOOLEAN"] = "boolean";
|
|
962
|
-
return Protocol2;
|
|
963
|
-
})(Protocol || {});
|
|
964
|
-
class WebStorage extends BaseService {
|
|
965
|
-
storage = globalThis.localStorage;
|
|
966
|
-
namespace = "tmagic";
|
|
967
|
-
constructor() {
|
|
968
|
-
super(["getStorage", "getNamespace", "clear", "getItem", "removeItem", "setItem"]);
|
|
969
|
-
}
|
|
970
|
-
async getStorage() {
|
|
971
|
-
return this.storage;
|
|
972
|
-
}
|
|
973
|
-
async getNamespace() {
|
|
974
|
-
return this.namespace;
|
|
975
|
-
}
|
|
976
|
-
async clear() {
|
|
977
|
-
const storage2 = await this.getStorage();
|
|
978
|
-
storage2.clear();
|
|
979
|
-
}
|
|
980
|
-
async getItem(key, options = {}) {
|
|
981
|
-
const [storage, namespace] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
982
|
-
const { protocol = options.protocol, item } = this.getValueAndProtocol(
|
|
983
|
-
storage.getItem(`${options.namespace || namespace}:${key}`)
|
|
984
|
-
);
|
|
985
|
-
if (item === null)
|
|
986
|
-
return null;
|
|
987
|
-
switch (protocol) {
|
|
988
|
-
case "object" /* OBJECT */:
|
|
989
|
-
return eval(`(${item})`);
|
|
990
|
-
case "json" /* JSON */:
|
|
991
|
-
return JSON.parse(item);
|
|
992
|
-
case "number" /* NUMBER */:
|
|
993
|
-
return Number(item);
|
|
994
|
-
case "boolean" /* BOOLEAN */:
|
|
995
|
-
return Boolean(item);
|
|
996
|
-
default:
|
|
997
|
-
return item;
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
async key(index) {
|
|
1001
|
-
const storage2 = await this.getStorage();
|
|
1002
|
-
return storage2.key(index);
|
|
1003
|
-
}
|
|
1004
|
-
async removeItem(key2, options2 = {}) {
|
|
1005
|
-
const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
1006
|
-
storage2.removeItem(`${options2.namespace || namespace2}:${key2}`);
|
|
1007
|
-
}
|
|
1008
|
-
async setItem(key2, value, options2 = {}) {
|
|
1009
|
-
const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
1010
|
-
let item2 = value;
|
|
1011
|
-
const protocol2 = options2.protocol ? `${options2.protocol}:` : "";
|
|
1012
|
-
if (typeof value === "string" /* STRING */ || typeof value === "number" /* NUMBER */) {
|
|
1013
|
-
item2 = `${protocol2}${value}`;
|
|
1014
|
-
} else {
|
|
1015
|
-
item2 = `${protocol2}${serialize(value)}`;
|
|
1016
|
-
}
|
|
1017
|
-
storage2.setItem(`${options2.namespace || namespace2}:${key2}`, item2);
|
|
1018
|
-
}
|
|
1019
|
-
destroy() {
|
|
1020
|
-
this.removeAllListeners();
|
|
1021
|
-
this.removeAllPlugins();
|
|
1022
|
-
}
|
|
1023
|
-
getValueAndProtocol(value) {
|
|
1024
|
-
let protocol2 = "";
|
|
1025
|
-
if (value === null) {
|
|
1026
|
-
return {
|
|
1027
|
-
item: value,
|
|
1028
|
-
protocol: protocol2
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
const item2 = value.replace(new RegExp(`^(${Object.values(Protocol).join("|")})(:)(.+)`), (_$0, $1, _$2, $3) => {
|
|
1032
|
-
protocol2 = $1;
|
|
1033
|
-
return $3;
|
|
1034
|
-
});
|
|
1035
|
-
return {
|
|
1036
|
-
protocol: protocol2,
|
|
1037
|
-
item: item2
|
|
1038
|
-
};
|
|
1230
|
+
};
|
|
1231
|
+
const error = (...args) => {
|
|
1232
|
+
if (process.env.NODE_ENV === "development") {
|
|
1233
|
+
console.error("magic editor: ", ...args);
|
|
1039
1234
|
}
|
|
1040
|
-
}
|
|
1041
|
-
const storageService = new WebStorage();
|
|
1235
|
+
};
|
|
1042
1236
|
|
|
1043
1237
|
var ColumnLayout = /* @__PURE__ */ ((ColumnLayout2) => {
|
|
1044
1238
|
ColumnLayout2["LEFT"] = "left";
|
|
@@ -1231,144 +1425,480 @@ const serializeConfig = (config) => serialize(config, {
|
|
|
1231
1425
|
unsafe: true
|
|
1232
1426
|
}).replace(/"(\w+)":\s/g, "$1: ");
|
|
1233
1427
|
|
|
1234
|
-
class
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
"setPropsValue",
|
|
1244
|
-
"getPropsValue",
|
|
1245
|
-
"createId",
|
|
1246
|
-
"setNewItemId",
|
|
1247
|
-
"fillConfig",
|
|
1248
|
-
"getDefaultPropsValue"
|
|
1249
|
-
]);
|
|
1250
|
-
}
|
|
1251
|
-
setPropsConfigs(configs) {
|
|
1252
|
-
Object.keys(configs).forEach((type) => {
|
|
1253
|
-
this.setPropsConfig(toLine(type), configs[type]);
|
|
1254
|
-
});
|
|
1255
|
-
this.emit("props-configs-change");
|
|
1428
|
+
class UndoRedo {
|
|
1429
|
+
elementList;
|
|
1430
|
+
listCursor;
|
|
1431
|
+
listMaxSize;
|
|
1432
|
+
constructor(listMaxSize = 200) {
|
|
1433
|
+
const minListMaxSize = 2;
|
|
1434
|
+
this.elementList = [];
|
|
1435
|
+
this.listCursor = 0;
|
|
1436
|
+
this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
|
|
1256
1437
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1438
|
+
pushElement(element) {
|
|
1439
|
+
this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
|
|
1440
|
+
this.listCursor += 1;
|
|
1441
|
+
if (this.elementList.length > this.listMaxSize) {
|
|
1442
|
+
this.elementList.shift();
|
|
1443
|
+
this.listCursor -= 1;
|
|
1444
|
+
}
|
|
1259
1445
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1446
|
+
canUndo() {
|
|
1447
|
+
return this.listCursor > 1;
|
|
1262
1448
|
}
|
|
1263
|
-
|
|
1264
|
-
if (
|
|
1265
|
-
return
|
|
1449
|
+
undo() {
|
|
1450
|
+
if (!this.canUndo()) {
|
|
1451
|
+
return null;
|
|
1266
1452
|
}
|
|
1267
|
-
|
|
1453
|
+
this.listCursor -= 1;
|
|
1454
|
+
return this.getCurrentElement();
|
|
1268
1455
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
this.setPropsValue(toLine(type), values[type]);
|
|
1272
|
-
});
|
|
1456
|
+
canRedo() {
|
|
1457
|
+
return this.elementList.length > this.listCursor;
|
|
1273
1458
|
}
|
|
1274
|
-
|
|
1275
|
-
this.
|
|
1459
|
+
redo() {
|
|
1460
|
+
if (!this.canRedo()) {
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1463
|
+
this.listCursor += 1;
|
|
1464
|
+
return this.getCurrentElement();
|
|
1276
1465
|
}
|
|
1277
|
-
|
|
1278
|
-
if (
|
|
1279
|
-
|
|
1280
|
-
value.className = "action-area";
|
|
1281
|
-
value.text = "";
|
|
1282
|
-
if (value.style) {
|
|
1283
|
-
value.style.backgroundColor = "rgba(255, 255, 255, 0)";
|
|
1284
|
-
}
|
|
1285
|
-
return value;
|
|
1466
|
+
getCurrentElement() {
|
|
1467
|
+
if (this.listCursor < 1) {
|
|
1468
|
+
return null;
|
|
1286
1469
|
}
|
|
1287
|
-
|
|
1288
|
-
this.createId(type),
|
|
1289
|
-
this.getDefaultPropsValue(type),
|
|
1290
|
-
this.setNewItemId(
|
|
1291
|
-
cloneDeep({
|
|
1292
|
-
type,
|
|
1293
|
-
...defaultValue
|
|
1294
|
-
})
|
|
1295
|
-
)
|
|
1296
|
-
]);
|
|
1297
|
-
return {
|
|
1298
|
-
id,
|
|
1299
|
-
...defaultPropsValue,
|
|
1300
|
-
...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
|
|
1301
|
-
};
|
|
1470
|
+
return cloneDeep(this.elementList[this.listCursor - 1]);
|
|
1302
1471
|
}
|
|
1303
|
-
|
|
1304
|
-
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
const compose = (middleware) => {
|
|
1475
|
+
if (!Array.isArray(middleware))
|
|
1476
|
+
throw new TypeError("Middleware \u5FC5\u987B\u662F\u4E00\u4E2A\u6570\u7EC4!");
|
|
1477
|
+
for (const fn of middleware) {
|
|
1478
|
+
if (typeof fn !== "function")
|
|
1479
|
+
throw new TypeError("Middleware \u5FC5\u987B\u7531\u51FD\u6570\u7EC4\u6210!");
|
|
1305
1480
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1481
|
+
return (args, next) => {
|
|
1482
|
+
let index = -1;
|
|
1483
|
+
return dispatch(0);
|
|
1484
|
+
function dispatch(i) {
|
|
1485
|
+
if (i <= index)
|
|
1486
|
+
return Promise.reject(new Error("next() \u88AB\u591A\u6B21\u8C03\u7528"));
|
|
1487
|
+
index = i;
|
|
1488
|
+
let fn = middleware[i];
|
|
1489
|
+
if (i === middleware.length && next)
|
|
1490
|
+
fn = next;
|
|
1491
|
+
if (!fn)
|
|
1492
|
+
return Promise.resolve();
|
|
1493
|
+
try {
|
|
1494
|
+
return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
|
|
1495
|
+
} catch (err) {
|
|
1496
|
+
return Promise.reject(err);
|
|
1311
1497
|
}
|
|
1312
1498
|
}
|
|
1313
|
-
|
|
1499
|
+
};
|
|
1500
|
+
};
|
|
1501
|
+
|
|
1502
|
+
const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
|
|
1503
|
+
const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
|
|
1504
|
+
const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName, fn) => {
|
|
1505
|
+
try {
|
|
1506
|
+
let beforeArgs = args;
|
|
1507
|
+
for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
|
|
1508
|
+
beforeArgs = await beforeMethod(...beforeArgs) || [];
|
|
1509
|
+
if (isError(beforeArgs))
|
|
1510
|
+
throw beforeArgs;
|
|
1511
|
+
if (!Array.isArray(beforeArgs)) {
|
|
1512
|
+
beforeArgs = [beforeArgs];
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
|
|
1516
|
+
for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
|
|
1517
|
+
returnValue = await afterMethod(returnValue, ...beforeArgs);
|
|
1518
|
+
if (isError(returnValue))
|
|
1519
|
+
throw returnValue;
|
|
1520
|
+
}
|
|
1521
|
+
return returnValue;
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
throw error;
|
|
1314
1524
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1525
|
+
};
|
|
1526
|
+
class BaseService extends EventEmitter {
|
|
1527
|
+
pluginOptionsList = {};
|
|
1528
|
+
middleware = {};
|
|
1529
|
+
taskList = [];
|
|
1530
|
+
doingTask = false;
|
|
1531
|
+
constructor(methods = [], serialMethods = []) {
|
|
1532
|
+
super();
|
|
1533
|
+
methods.forEach((propertyName) => {
|
|
1534
|
+
const scope = this;
|
|
1535
|
+
const sourceMethod = scope[propertyName];
|
|
1536
|
+
const beforeMethodName = methodName("before", propertyName);
|
|
1537
|
+
const afterMethodName = methodName("after", propertyName);
|
|
1538
|
+
this.pluginOptionsList[beforeMethodName] = [];
|
|
1539
|
+
this.pluginOptionsList[afterMethodName] = [];
|
|
1540
|
+
this.middleware[propertyName] = [];
|
|
1541
|
+
const fn = compose(this.middleware[propertyName]);
|
|
1542
|
+
Object.defineProperty(scope, propertyName, {
|
|
1543
|
+
value: async (...args) => {
|
|
1544
|
+
if (!serialMethods.includes(propertyName)) {
|
|
1545
|
+
return doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
|
|
1546
|
+
}
|
|
1547
|
+
const promise = new Promise((resolve, reject) => {
|
|
1548
|
+
this.taskList.push(async () => {
|
|
1549
|
+
try {
|
|
1550
|
+
const value = await doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
|
|
1551
|
+
resolve(value);
|
|
1552
|
+
} catch (e) {
|
|
1553
|
+
reject(e);
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
});
|
|
1557
|
+
if (!this.doingTask) {
|
|
1558
|
+
this.doTask();
|
|
1559
|
+
}
|
|
1560
|
+
return promise;
|
|
1561
|
+
}
|
|
1562
|
+
});
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
use(options) {
|
|
1566
|
+
Object.entries(options).forEach(([methodName2, method]) => {
|
|
1567
|
+
if (typeof method === "function")
|
|
1568
|
+
this.middleware[methodName2].push(method);
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
usePlugin(options) {
|
|
1572
|
+
Object.entries(options).forEach(([methodName2, method]) => {
|
|
1573
|
+
if (typeof method === "function")
|
|
1574
|
+
this.pluginOptionsList[methodName2].push(method);
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
removeAllPlugins() {
|
|
1578
|
+
Object.keys(this.pluginOptionsList).forEach((key) => {
|
|
1579
|
+
this.pluginOptionsList[key] = [];
|
|
1580
|
+
});
|
|
1581
|
+
Object.keys(this.middleware).forEach((key) => {
|
|
1582
|
+
this.middleware[key] = [];
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
async doTask() {
|
|
1586
|
+
this.doingTask = true;
|
|
1587
|
+
let task = this.taskList.shift();
|
|
1588
|
+
while (task) {
|
|
1589
|
+
await task();
|
|
1590
|
+
task = this.taskList.shift();
|
|
1591
|
+
}
|
|
1592
|
+
this.doingTask = false;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
class History extends BaseService {
|
|
1597
|
+
state = reactive({
|
|
1598
|
+
pageSteps: {},
|
|
1599
|
+
pageId: void 0,
|
|
1600
|
+
canRedo: false,
|
|
1601
|
+
canUndo: false
|
|
1602
|
+
});
|
|
1603
|
+
constructor() {
|
|
1604
|
+
super([]);
|
|
1605
|
+
this.on("change", this.setCanUndoRedo);
|
|
1606
|
+
}
|
|
1607
|
+
reset() {
|
|
1608
|
+
this.state.pageSteps = {};
|
|
1609
|
+
this.state.pageId = void 0;
|
|
1610
|
+
this.state.canRedo = false;
|
|
1611
|
+
this.state.canUndo = false;
|
|
1612
|
+
}
|
|
1613
|
+
changePage(page) {
|
|
1614
|
+
if (!page)
|
|
1615
|
+
return;
|
|
1616
|
+
this.state.pageId = page.id;
|
|
1617
|
+
if (!this.state.pageSteps[this.state.pageId]) {
|
|
1618
|
+
const undoRedo = new UndoRedo();
|
|
1619
|
+
undoRedo.pushElement({
|
|
1620
|
+
data: page,
|
|
1621
|
+
modifiedNodeIds: /* @__PURE__ */ new Map(),
|
|
1622
|
+
nodeId: page.id
|
|
1623
|
+
});
|
|
1624
|
+
this.state.pageSteps[this.state.pageId] = undoRedo;
|
|
1625
|
+
}
|
|
1626
|
+
this.setCanUndoRedo();
|
|
1627
|
+
this.emit("page-change", this.state.pageSteps[this.state.pageId]);
|
|
1327
1628
|
}
|
|
1328
1629
|
resetState() {
|
|
1329
|
-
this.state.
|
|
1330
|
-
this.state.
|
|
1630
|
+
this.state.pageId = void 0;
|
|
1631
|
+
this.state.pageSteps = {};
|
|
1632
|
+
this.state.canRedo = false;
|
|
1633
|
+
this.state.canUndo = false;
|
|
1634
|
+
}
|
|
1635
|
+
push(state) {
|
|
1636
|
+
const undoRedo = this.getUndoRedo();
|
|
1637
|
+
if (!undoRedo)
|
|
1638
|
+
return null;
|
|
1639
|
+
undoRedo.pushElement(state);
|
|
1640
|
+
this.emit("change", state);
|
|
1641
|
+
return state;
|
|
1642
|
+
}
|
|
1643
|
+
undo() {
|
|
1644
|
+
const undoRedo = this.getUndoRedo();
|
|
1645
|
+
if (!undoRedo)
|
|
1646
|
+
return null;
|
|
1647
|
+
const state = undoRedo.undo();
|
|
1648
|
+
this.emit("change", state);
|
|
1649
|
+
return state;
|
|
1650
|
+
}
|
|
1651
|
+
redo() {
|
|
1652
|
+
const undoRedo = this.getUndoRedo();
|
|
1653
|
+
if (!undoRedo)
|
|
1654
|
+
return null;
|
|
1655
|
+
const state = undoRedo.redo();
|
|
1656
|
+
this.emit("change", state);
|
|
1657
|
+
return state;
|
|
1331
1658
|
}
|
|
1332
1659
|
destroy() {
|
|
1333
1660
|
this.resetState();
|
|
1334
1661
|
this.removeAllListeners();
|
|
1335
1662
|
this.removeAllPlugins();
|
|
1336
1663
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1664
|
+
getUndoRedo() {
|
|
1665
|
+
if (!this.state.pageId)
|
|
1666
|
+
return null;
|
|
1667
|
+
return this.state.pageSteps[this.state.pageId];
|
|
1668
|
+
}
|
|
1669
|
+
setCanUndoRedo() {
|
|
1670
|
+
const undoRedo = this.getUndoRedo();
|
|
1671
|
+
this.state.canRedo = undoRedo?.canRedo() || false;
|
|
1672
|
+
this.state.canUndo = undoRedo?.canUndo() || false;
|
|
1343
1673
|
}
|
|
1344
1674
|
}
|
|
1345
|
-
const
|
|
1675
|
+
const historyService = new History();
|
|
1346
1676
|
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1677
|
+
var Protocol = /* @__PURE__ */ ((Protocol2) => {
|
|
1678
|
+
Protocol2["OBJECT"] = "object";
|
|
1679
|
+
Protocol2["JSON"] = "json";
|
|
1680
|
+
Protocol2["STRING"] = "string";
|
|
1681
|
+
Protocol2["NUMBER"] = "number";
|
|
1682
|
+
Protocol2["BOOLEAN"] = "boolean";
|
|
1683
|
+
return Protocol2;
|
|
1684
|
+
})(Protocol || {});
|
|
1685
|
+
class WebStorage extends BaseService {
|
|
1686
|
+
storage = globalThis.localStorage;
|
|
1687
|
+
namespace = "tmagic";
|
|
1688
|
+
constructor() {
|
|
1689
|
+
super(["getStorage", "getNamespace", "clear", "getItem", "removeItem", "setItem"]);
|
|
1690
|
+
}
|
|
1691
|
+
async getStorage() {
|
|
1692
|
+
return this.storage;
|
|
1693
|
+
}
|
|
1694
|
+
async getNamespace() {
|
|
1695
|
+
return this.namespace;
|
|
1696
|
+
}
|
|
1697
|
+
async clear() {
|
|
1698
|
+
const storage2 = await this.getStorage();
|
|
1699
|
+
storage2.clear();
|
|
1700
|
+
}
|
|
1701
|
+
async getItem(key, options = {}) {
|
|
1702
|
+
const [storage, namespace] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
1703
|
+
const { protocol = options.protocol, item } = this.getValueAndProtocol(
|
|
1704
|
+
storage.getItem(`${options.namespace || namespace}:${key}`)
|
|
1705
|
+
);
|
|
1706
|
+
if (item === null)
|
|
1707
|
+
return null;
|
|
1708
|
+
switch (protocol) {
|
|
1709
|
+
case "object" /* OBJECT */:
|
|
1710
|
+
return eval(`(${item})`);
|
|
1711
|
+
case "json" /* JSON */:
|
|
1712
|
+
return JSON.parse(item);
|
|
1713
|
+
case "number" /* NUMBER */:
|
|
1714
|
+
return Number(item);
|
|
1715
|
+
case "boolean" /* BOOLEAN */:
|
|
1716
|
+
return Boolean(item);
|
|
1717
|
+
default:
|
|
1718
|
+
return item;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
async key(index) {
|
|
1722
|
+
const storage2 = await this.getStorage();
|
|
1723
|
+
return storage2.key(index);
|
|
1724
|
+
}
|
|
1725
|
+
async removeItem(key2, options2 = {}) {
|
|
1726
|
+
const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
1727
|
+
storage2.removeItem(`${options2.namespace || namespace2}:${key2}`);
|
|
1728
|
+
}
|
|
1729
|
+
async setItem(key2, value, options2 = {}) {
|
|
1730
|
+
const [storage2, namespace2] = await Promise.all([this.getStorage(), this.getNamespace()]);
|
|
1731
|
+
let item2 = value;
|
|
1732
|
+
const protocol2 = options2.protocol ? `${options2.protocol}:` : "";
|
|
1733
|
+
if (typeof value === "string" /* STRING */ || typeof value === "number" /* NUMBER */) {
|
|
1734
|
+
item2 = `${protocol2}${value}`;
|
|
1735
|
+
} else {
|
|
1736
|
+
item2 = `${protocol2}${serialize(value)}`;
|
|
1737
|
+
}
|
|
1738
|
+
storage2.setItem(`${options2.namespace || namespace2}:${key2}`, item2);
|
|
1739
|
+
}
|
|
1740
|
+
destroy() {
|
|
1741
|
+
this.removeAllListeners();
|
|
1742
|
+
this.removeAllPlugins();
|
|
1743
|
+
}
|
|
1744
|
+
getValueAndProtocol(value) {
|
|
1745
|
+
let protocol2 = "";
|
|
1746
|
+
if (value === null) {
|
|
1747
|
+
return {
|
|
1748
|
+
item: value,
|
|
1749
|
+
protocol: protocol2
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
const item2 = value.replace(new RegExp(`^(${Object.values(Protocol).join("|")})(:)(.+)`), (_$0, $1, _$2, $3) => {
|
|
1753
|
+
protocol2 = $1;
|
|
1754
|
+
return $3;
|
|
1755
|
+
});
|
|
1756
|
+
return {
|
|
1757
|
+
protocol: protocol2,
|
|
1758
|
+
item: item2
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
const storageService = new WebStorage();
|
|
1763
|
+
|
|
1764
|
+
class Props extends BaseService {
|
|
1765
|
+
state = reactive({
|
|
1766
|
+
propsConfigMap: {},
|
|
1767
|
+
propsValueMap: {}
|
|
1768
|
+
});
|
|
1769
|
+
constructor() {
|
|
1770
|
+
super([
|
|
1771
|
+
"setPropsConfig",
|
|
1772
|
+
"getPropsConfig",
|
|
1773
|
+
"setPropsValue",
|
|
1774
|
+
"getPropsValue",
|
|
1775
|
+
"createId",
|
|
1776
|
+
"setNewItemId",
|
|
1777
|
+
"fillConfig",
|
|
1778
|
+
"getDefaultPropsValue"
|
|
1779
|
+
]);
|
|
1780
|
+
}
|
|
1781
|
+
setPropsConfigs(configs) {
|
|
1782
|
+
Object.keys(configs).forEach((type) => {
|
|
1783
|
+
this.setPropsConfig(toLine(type), configs[type]);
|
|
1784
|
+
});
|
|
1785
|
+
this.emit("props-configs-change");
|
|
1786
|
+
}
|
|
1787
|
+
async fillConfig(config) {
|
|
1788
|
+
return fillConfig(config);
|
|
1789
|
+
}
|
|
1790
|
+
async setPropsConfig(type, config) {
|
|
1791
|
+
this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
|
|
1792
|
+
}
|
|
1793
|
+
async getPropsConfig(type) {
|
|
1794
|
+
if (type === "area") {
|
|
1795
|
+
return await this.getPropsConfig("button");
|
|
1796
|
+
}
|
|
1797
|
+
return cloneDeep(this.state.propsConfigMap[type] || await this.fillConfig([]));
|
|
1798
|
+
}
|
|
1799
|
+
setPropsValues(values) {
|
|
1800
|
+
Object.keys(values).forEach((type) => {
|
|
1801
|
+
this.setPropsValue(toLine(type), values[type]);
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
async setPropsValue(type, value) {
|
|
1805
|
+
this.state.propsValueMap[type] = value;
|
|
1806
|
+
}
|
|
1807
|
+
async getPropsValue(type, { inputEvent, ...defaultValue } = {}) {
|
|
1808
|
+
if (type === "area") {
|
|
1809
|
+
const value = await this.getPropsValue("button");
|
|
1810
|
+
value.className = "action-area";
|
|
1811
|
+
value.text = "";
|
|
1812
|
+
if (value.style) {
|
|
1813
|
+
value.style.backgroundColor = "rgba(255, 255, 255, 0)";
|
|
1814
|
+
}
|
|
1815
|
+
return value;
|
|
1816
|
+
}
|
|
1817
|
+
const [id, defaultPropsValue, data] = await Promise.all([
|
|
1818
|
+
this.createId(type),
|
|
1819
|
+
this.getDefaultPropsValue(type),
|
|
1820
|
+
this.setNewItemId(
|
|
1821
|
+
cloneDeep({
|
|
1822
|
+
type,
|
|
1823
|
+
...defaultValue
|
|
1824
|
+
})
|
|
1825
|
+
)
|
|
1826
|
+
]);
|
|
1827
|
+
return {
|
|
1828
|
+
id,
|
|
1829
|
+
...defaultPropsValue,
|
|
1830
|
+
...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data)
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
async createId(type) {
|
|
1834
|
+
return `${type}_${this.guid()}`;
|
|
1835
|
+
}
|
|
1836
|
+
async setNewItemId(config) {
|
|
1837
|
+
config.id = await this.createId(config.type || "component");
|
|
1838
|
+
if (config.items && Array.isArray(config.items)) {
|
|
1839
|
+
for (const item of config.items) {
|
|
1840
|
+
await this.setNewItemId(item);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
return config;
|
|
1844
|
+
}
|
|
1845
|
+
async getDefaultPropsValue(type) {
|
|
1846
|
+
return ["page", "container"].includes(type) ? {
|
|
1847
|
+
type,
|
|
1848
|
+
layout: "absolute",
|
|
1849
|
+
style: {},
|
|
1850
|
+
name: type,
|
|
1851
|
+
items: []
|
|
1852
|
+
} : {
|
|
1853
|
+
type,
|
|
1854
|
+
style: {},
|
|
1855
|
+
name: type
|
|
1856
|
+
};
|
|
1857
|
+
}
|
|
1858
|
+
resetState() {
|
|
1859
|
+
this.state.propsConfigMap = {};
|
|
1860
|
+
this.state.propsValueMap = {};
|
|
1861
|
+
}
|
|
1862
|
+
destroy() {
|
|
1863
|
+
this.resetState();
|
|
1864
|
+
this.removeAllListeners();
|
|
1865
|
+
this.removeAllPlugins();
|
|
1866
|
+
}
|
|
1867
|
+
guid(digit = 8) {
|
|
1868
|
+
return "x".repeat(digit).replace(/[xy]/g, (c) => {
|
|
1869
|
+
const r = Math.random() * 16 | 0;
|
|
1870
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1871
|
+
return v.toString(16);
|
|
1872
|
+
});
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
const propsService = new Props();
|
|
1876
|
+
|
|
1877
|
+
const beforePaste = async (position, config) => {
|
|
1878
|
+
if (!config[0]?.style)
|
|
1879
|
+
return config;
|
|
1880
|
+
const curNode = editorService.get("node");
|
|
1881
|
+
const { left: referenceLeft, top: referenceTop } = config[0].style;
|
|
1882
|
+
const pasteConfigs = await Promise.all(
|
|
1883
|
+
config.map(async (configItem) => {
|
|
1884
|
+
const { offsetX = 0, offsetY = 0, ...positionClone } = position;
|
|
1885
|
+
let pastePosition = positionClone;
|
|
1886
|
+
if (!isEmpty(pastePosition) && curNode?.items) {
|
|
1887
|
+
pastePosition = getPositionInContainer(pastePosition, curNode.id);
|
|
1888
|
+
}
|
|
1889
|
+
if (pastePosition.left && configItem.style?.left) {
|
|
1890
|
+
pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
|
|
1891
|
+
}
|
|
1892
|
+
if (pastePosition.top && configItem.style?.top) {
|
|
1893
|
+
pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
|
|
1894
|
+
}
|
|
1895
|
+
const pasteConfig = await propsService.setNewItemId(configItem);
|
|
1896
|
+
if (pasteConfig.style) {
|
|
1897
|
+
const { left, top } = pasteConfig.style;
|
|
1898
|
+
if (typeof left === "number" || !!left && !isNaN(Number(left))) {
|
|
1899
|
+
pasteConfig.style.left = Number(left) + offsetX;
|
|
1900
|
+
}
|
|
1901
|
+
if (typeof top === "number" || !!top && !isNaN(Number(top))) {
|
|
1372
1902
|
pasteConfig.style.top = Number(top) + offsetY;
|
|
1373
1903
|
}
|
|
1374
1904
|
pasteConfig.style = {
|
|
@@ -1451,9 +1981,7 @@ class Editor$1 extends BaseService {
|
|
|
1451
1981
|
"move",
|
|
1452
1982
|
"undo",
|
|
1453
1983
|
"redo",
|
|
1454
|
-
"highlight"
|
|
1455
|
-
"getCodeDsl",
|
|
1456
|
-
"setCodeDsl"
|
|
1984
|
+
"highlight"
|
|
1457
1985
|
],
|
|
1458
1986
|
["select", "update", "moveLayer"]
|
|
1459
1987
|
);
|
|
@@ -1539,7 +2067,7 @@ class Editor$1 extends BaseService {
|
|
|
1539
2067
|
historyService.resetState();
|
|
1540
2068
|
}
|
|
1541
2069
|
if (node?.id) {
|
|
1542
|
-
this.get("stage")?.renderer.runtime?.getApp?.()
|
|
2070
|
+
this.get("stage")?.renderer.runtime?.getApp?.()?.page?.emit(
|
|
1543
2071
|
"editor:select",
|
|
1544
2072
|
{
|
|
1545
2073
|
node,
|
|
@@ -1904,436 +2432,134 @@ class Editor$1 extends BaseService {
|
|
|
1904
2432
|
}
|
|
1905
2433
|
});
|
|
1906
2434
|
newConfig.style = getInitPositionStyle(newConfig.style, layout);
|
|
1907
|
-
target.items.push(newConfig);
|
|
1908
|
-
await stage.select(targetId);
|
|
1909
|
-
const targetParent = this.getParentById(target.id);
|
|
1910
|
-
await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
|
|
1911
|
-
await this.select(newConfig);
|
|
1912
|
-
stage.select(newConfig.id);
|
|
1913
|
-
this.addModifiedNodeId(target.id);
|
|
1914
|
-
this.addModifiedNodeId(parent.id);
|
|
1915
|
-
this.pushHistoryState();
|
|
1916
|
-
return newConfig;
|
|
1917
|
-
}
|
|
1918
|
-
}
|
|
1919
|
-
async undo() {
|
|
1920
|
-
const value = historyService.undo();
|
|
1921
|
-
await this.changeHistoryState(value);
|
|
1922
|
-
return value;
|
|
1923
|
-
}
|
|
1924
|
-
async redo() {
|
|
1925
|
-
const value = historyService.redo();
|
|
1926
|
-
await this.changeHistoryState(value);
|
|
1927
|
-
return value;
|
|
1928
|
-
}
|
|
1929
|
-
async move(left, top) {
|
|
1930
|
-
const node = toRaw(this.get("node"));
|
|
1931
|
-
if (!node || isPage(node))
|
|
1932
|
-
return;
|
|
1933
|
-
const { style, id, type } = node;
|
|
1934
|
-
if (!style || style.position !== "absolute")
|
|
1935
|
-
return;
|
|
1936
|
-
if (top && !isNumber(style.top))
|
|
1937
|
-
return;
|
|
1938
|
-
if (left && !isNumber(style.left))
|
|
1939
|
-
return;
|
|
1940
|
-
this.update({
|
|
1941
|
-
id,
|
|
1942
|
-
type,
|
|
1943
|
-
style: {
|
|
1944
|
-
...style,
|
|
1945
|
-
left: Number(style.left) + left,
|
|
1946
|
-
top: Number(style.top) + top
|
|
1947
|
-
}
|
|
1948
|
-
});
|
|
1949
|
-
}
|
|
1950
|
-
resetState() {
|
|
1951
|
-
this.set("root", null);
|
|
1952
|
-
this.set("node", null);
|
|
1953
|
-
this.set("nodes", []);
|
|
1954
|
-
this.set("page", null);
|
|
1955
|
-
this.set("parent", null);
|
|
1956
|
-
this.set("stage", null);
|
|
1957
|
-
this.set("highlightNode", null);
|
|
1958
|
-
this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
|
|
1959
|
-
this.set("pageLength", 0);
|
|
1960
|
-
}
|
|
1961
|
-
destroy() {
|
|
1962
|
-
this.removeAllListeners();
|
|
1963
|
-
this.resetState();
|
|
1964
|
-
this.removeAllPlugins();
|
|
1965
|
-
}
|
|
1966
|
-
resetModifiedNodeId() {
|
|
1967
|
-
this.get("modifiedNodeIds").clear();
|
|
1968
|
-
}
|
|
1969
|
-
async getCodeDsl() {
|
|
1970
|
-
const root = this.get("root");
|
|
1971
|
-
return root?.codeBlocks || null;
|
|
1972
|
-
}
|
|
1973
|
-
getCodeDslSync() {
|
|
1974
|
-
const root = this.get("root");
|
|
1975
|
-
return root?.codeBlocks || null;
|
|
1976
|
-
}
|
|
1977
|
-
async setCodeDsl(codeDsl) {
|
|
1978
|
-
if (!this.state.root)
|
|
1979
|
-
return;
|
|
1980
|
-
this.state.root.codeBlocks = codeDsl;
|
|
1981
|
-
}
|
|
1982
|
-
addModifiedNodeId(id) {
|
|
1983
|
-
if (!this.isHistoryStateChange) {
|
|
1984
|
-
this.get("modifiedNodeIds").set(id, id);
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
pushHistoryState() {
|
|
1988
|
-
const curNode = cloneDeep(toRaw(this.get("node")));
|
|
1989
|
-
const page = this.get("page");
|
|
1990
|
-
if (!this.isHistoryStateChange && curNode && page) {
|
|
1991
|
-
historyService.push({
|
|
1992
|
-
data: cloneDeep(toRaw(page)),
|
|
1993
|
-
modifiedNodeIds: this.get("modifiedNodeIds"),
|
|
1994
|
-
nodeId: curNode.id
|
|
1995
|
-
});
|
|
1996
|
-
}
|
|
1997
|
-
this.isHistoryStateChange = false;
|
|
1998
|
-
}
|
|
1999
|
-
async changeHistoryState(value) {
|
|
2000
|
-
if (!value)
|
|
2001
|
-
return;
|
|
2002
|
-
this.isHistoryStateChange = true;
|
|
2003
|
-
await this.update(value.data);
|
|
2004
|
-
this.set("modifiedNodeIds", value.modifiedNodeIds);
|
|
2005
|
-
setTimeout(async () => {
|
|
2006
|
-
if (!value.nodeId)
|
|
2007
|
-
return;
|
|
2008
|
-
await this.select(value.nodeId);
|
|
2009
|
-
this.get("stage")?.select(value.nodeId);
|
|
2010
|
-
}, 0);
|
|
2011
|
-
this.emit("history-change", value.data);
|
|
2012
|
-
}
|
|
2013
|
-
async toggleFixedPosition(dist, src, root) {
|
|
2014
|
-
const newConfig = cloneDeep(dist);
|
|
2015
|
-
if (!isPop(src) && newConfig.style?.position) {
|
|
2016
|
-
if (isFixed(newConfig) && !isFixed(src)) {
|
|
2017
|
-
newConfig.style = change2Fixed(newConfig, root);
|
|
2018
|
-
} else if (!isFixed(newConfig) && isFixed(src)) {
|
|
2019
|
-
newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
return newConfig;
|
|
2023
|
-
}
|
|
2024
|
-
selectedConfigExceptionHandler(config) {
|
|
2025
|
-
let id;
|
|
2026
|
-
if (typeof config === "string" || typeof config === "number") {
|
|
2027
|
-
id = config;
|
|
2028
|
-
} else {
|
|
2029
|
-
id = config.id;
|
|
2030
|
-
}
|
|
2031
|
-
if (!id) {
|
|
2032
|
-
throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
|
|
2033
|
-
}
|
|
2034
|
-
const { node, parent, page } = this.getNodeInfo(id);
|
|
2035
|
-
if (!node)
|
|
2036
|
-
throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
|
|
2037
|
-
if (node.id === this.state.root?.id) {
|
|
2038
|
-
throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
|
|
2039
|
-
}
|
|
2040
|
-
return {
|
|
2041
|
-
node,
|
|
2042
|
-
parent,
|
|
2043
|
-
page
|
|
2044
|
-
};
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
const editorService = new Editor$1();
|
|
2048
|
-
|
|
2049
|
-
let eventMap = reactive({});
|
|
2050
|
-
let methodMap = reactive({});
|
|
2051
|
-
class Events extends BaseService {
|
|
2052
|
-
constructor() {
|
|
2053
|
-
super([]);
|
|
2054
|
-
}
|
|
2055
|
-
init(componentGroupList) {
|
|
2056
|
-
componentGroupList.forEach((group) => {
|
|
2057
|
-
group.items.forEach((element) => {
|
|
2058
|
-
const type = toLine(element.type);
|
|
2059
|
-
if (!this.getEvent(type)) {
|
|
2060
|
-
this.setEvent(type, DEFAULT_EVENTS);
|
|
2061
|
-
}
|
|
2062
|
-
if (!this.getMethod(type)) {
|
|
2063
|
-
this.setMethod(type, DEFAULT_METHODS);
|
|
2064
|
-
}
|
|
2065
|
-
});
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
setEvents(events) {
|
|
2069
|
-
Object.keys(events).forEach((type) => {
|
|
2070
|
-
this.setEvent(toLine(type), events[type] || []);
|
|
2071
|
-
});
|
|
2072
|
-
}
|
|
2073
|
-
setEvent(type, events) {
|
|
2074
|
-
eventMap[type] = [...DEFAULT_EVENTS, ...events];
|
|
2075
|
-
}
|
|
2076
|
-
getEvent(type) {
|
|
2077
|
-
return cloneDeep(eventMap[type] || DEFAULT_EVENTS);
|
|
2078
|
-
}
|
|
2079
|
-
setMethods(methods) {
|
|
2080
|
-
Object.keys(methods).forEach((type) => {
|
|
2081
|
-
this.setMethod(toLine(type), methods[type] || []);
|
|
2082
|
-
});
|
|
2083
|
-
}
|
|
2084
|
-
setMethod(type, method) {
|
|
2085
|
-
methodMap[type] = [...DEFAULT_METHODS, ...method];
|
|
2086
|
-
}
|
|
2087
|
-
getMethod(type) {
|
|
2088
|
-
return cloneDeep(methodMap[type] || DEFAULT_METHODS);
|
|
2089
|
-
}
|
|
2090
|
-
resetState() {
|
|
2091
|
-
eventMap = reactive({});
|
|
2092
|
-
methodMap = reactive({});
|
|
2093
|
-
}
|
|
2094
|
-
destroy() {
|
|
2095
|
-
this.resetState();
|
|
2096
|
-
this.removeAllListeners();
|
|
2097
|
-
this.removeAllPlugins();
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
const eventsService = new Events();
|
|
2101
|
-
|
|
2102
|
-
const fillConfig = (config = []) => [
|
|
2103
|
-
{
|
|
2104
|
-
type: "tab",
|
|
2105
|
-
items: [
|
|
2106
|
-
{
|
|
2107
|
-
title: "\u5C5E\u6027",
|
|
2108
|
-
labelWidth: "80px",
|
|
2109
|
-
items: [
|
|
2110
|
-
{
|
|
2111
|
-
text: "type",
|
|
2112
|
-
name: "type",
|
|
2113
|
-
type: "hidden"
|
|
2114
|
-
},
|
|
2115
|
-
{
|
|
2116
|
-
name: "id",
|
|
2117
|
-
type: "display",
|
|
2118
|
-
text: "id"
|
|
2119
|
-
},
|
|
2120
|
-
{
|
|
2121
|
-
name: "name",
|
|
2122
|
-
text: "\u7EC4\u4EF6\u540D\u79F0"
|
|
2123
|
-
},
|
|
2124
|
-
...config
|
|
2125
|
-
]
|
|
2126
|
-
},
|
|
2127
|
-
{
|
|
2128
|
-
title: "\u6837\u5F0F",
|
|
2129
|
-
labelWidth: "80px",
|
|
2130
|
-
items: [
|
|
2131
|
-
{
|
|
2132
|
-
name: "style",
|
|
2133
|
-
items: [
|
|
2134
|
-
{
|
|
2135
|
-
type: "fieldset",
|
|
2136
|
-
legend: "\u4F4D\u7F6E",
|
|
2137
|
-
items: [
|
|
2138
|
-
{
|
|
2139
|
-
name: "position",
|
|
2140
|
-
type: "checkbox",
|
|
2141
|
-
activeValue: "fixed",
|
|
2142
|
-
inactiveValue: "absolute",
|
|
2143
|
-
defaultValue: "absolute",
|
|
2144
|
-
text: "\u56FA\u5B9A\u5B9A\u4F4D"
|
|
2145
|
-
},
|
|
2146
|
-
{
|
|
2147
|
-
name: "left",
|
|
2148
|
-
text: "left"
|
|
2149
|
-
},
|
|
2150
|
-
{
|
|
2151
|
-
name: "top",
|
|
2152
|
-
text: "top",
|
|
2153
|
-
disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
|
|
2154
|
-
},
|
|
2155
|
-
{
|
|
2156
|
-
name: "right",
|
|
2157
|
-
text: "right"
|
|
2158
|
-
},
|
|
2159
|
-
{
|
|
2160
|
-
name: "bottom",
|
|
2161
|
-
text: "bottom",
|
|
2162
|
-
disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
|
|
2163
|
-
}
|
|
2164
|
-
]
|
|
2165
|
-
},
|
|
2166
|
-
{
|
|
2167
|
-
type: "fieldset",
|
|
2168
|
-
legend: "\u76D2\u5B50",
|
|
2169
|
-
items: [
|
|
2170
|
-
{
|
|
2171
|
-
name: "width",
|
|
2172
|
-
text: "\u5BBD\u5EA6"
|
|
2173
|
-
},
|
|
2174
|
-
{
|
|
2175
|
-
name: "height",
|
|
2176
|
-
text: "\u9AD8\u5EA6"
|
|
2177
|
-
}
|
|
2178
|
-
]
|
|
2179
|
-
},
|
|
2180
|
-
{
|
|
2181
|
-
type: "fieldset",
|
|
2182
|
-
legend: "\u80CC\u666F",
|
|
2183
|
-
items: [
|
|
2184
|
-
{
|
|
2185
|
-
name: "backgroundImage",
|
|
2186
|
-
text: "\u80CC\u666F\u56FE"
|
|
2187
|
-
},
|
|
2188
|
-
{
|
|
2189
|
-
name: "backgroundColor",
|
|
2190
|
-
text: "\u80CC\u666F\u989C\u8272",
|
|
2191
|
-
type: "colorPicker"
|
|
2192
|
-
},
|
|
2193
|
-
{
|
|
2194
|
-
name: "backgroundRepeat",
|
|
2195
|
-
text: "\u80CC\u666F\u56FE\u91CD\u590D",
|
|
2196
|
-
type: "select",
|
|
2197
|
-
defaultValue: "no-repeat",
|
|
2198
|
-
options: [
|
|
2199
|
-
{ text: "repeat", value: "repeat" },
|
|
2200
|
-
{ text: "repeat-x", value: "repeat-x" },
|
|
2201
|
-
{ text: "repeat-y", value: "repeat-y" },
|
|
2202
|
-
{ text: "no-repeat", value: "no-repeat" },
|
|
2203
|
-
{ text: "inherit", value: "inherit" }
|
|
2204
|
-
]
|
|
2205
|
-
},
|
|
2206
|
-
{
|
|
2207
|
-
name: "backgroundSize",
|
|
2208
|
-
text: "\u80CC\u666F\u56FE\u5927\u5C0F",
|
|
2209
|
-
defaultValue: "100% 100%"
|
|
2210
|
-
}
|
|
2211
|
-
]
|
|
2212
|
-
},
|
|
2213
|
-
{
|
|
2214
|
-
type: "fieldset",
|
|
2215
|
-
legend: "\u5B57\u4F53",
|
|
2216
|
-
items: [
|
|
2217
|
-
{
|
|
2218
|
-
name: "color",
|
|
2219
|
-
text: "\u989C\u8272",
|
|
2220
|
-
type: "colorPicker"
|
|
2221
|
-
},
|
|
2222
|
-
{
|
|
2223
|
-
name: "fontSize",
|
|
2224
|
-
text: "\u5927\u5C0F"
|
|
2225
|
-
},
|
|
2226
|
-
{
|
|
2227
|
-
name: "fontWeight",
|
|
2228
|
-
text: "\u7C97\u7EC6"
|
|
2229
|
-
}
|
|
2230
|
-
]
|
|
2231
|
-
},
|
|
2232
|
-
{
|
|
2233
|
-
type: "fieldset",
|
|
2234
|
-
legend: "\u53D8\u5F62",
|
|
2235
|
-
name: "transform",
|
|
2236
|
-
items: [
|
|
2237
|
-
{
|
|
2238
|
-
name: "rotate",
|
|
2239
|
-
text: "\u65CB\u8F6C\u89D2\u5EA6"
|
|
2240
|
-
},
|
|
2241
|
-
{
|
|
2242
|
-
name: "scale",
|
|
2243
|
-
text: "\u7F29\u653E"
|
|
2244
|
-
}
|
|
2245
|
-
]
|
|
2246
|
-
}
|
|
2247
|
-
]
|
|
2248
|
-
}
|
|
2249
|
-
]
|
|
2250
|
-
},
|
|
2251
|
-
{
|
|
2252
|
-
title: "\u4E8B\u4EF6",
|
|
2253
|
-
items: [
|
|
2254
|
-
{
|
|
2255
|
-
type: "table",
|
|
2256
|
-
name: "events",
|
|
2257
|
-
items: [
|
|
2258
|
-
{
|
|
2259
|
-
name: "name",
|
|
2260
|
-
label: "\u4E8B\u4EF6\u540D",
|
|
2261
|
-
type: "select",
|
|
2262
|
-
options: (mForm, { formValue }) => eventsService.getEvent(formValue.type).map((option) => ({
|
|
2263
|
-
text: option.label,
|
|
2264
|
-
value: option.value
|
|
2265
|
-
}))
|
|
2266
|
-
},
|
|
2267
|
-
{
|
|
2268
|
-
name: "to",
|
|
2269
|
-
label: "\u8054\u52A8\u7EC4\u4EF6",
|
|
2270
|
-
type: "ui-select"
|
|
2271
|
-
},
|
|
2272
|
-
{
|
|
2273
|
-
name: "method",
|
|
2274
|
-
label: "\u52A8\u4F5C",
|
|
2275
|
-
type: "select",
|
|
2276
|
-
options: (mForm, { model }) => {
|
|
2277
|
-
const node = editorService.getNodeById(model.to);
|
|
2278
|
-
if (!node?.type)
|
|
2279
|
-
return [];
|
|
2280
|
-
return eventsService.getMethod(node.type).map((option) => ({
|
|
2281
|
-
text: option.label,
|
|
2282
|
-
value: option.value
|
|
2283
|
-
}));
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
]
|
|
2287
|
-
}
|
|
2288
|
-
]
|
|
2289
|
-
},
|
|
2290
|
-
{
|
|
2291
|
-
title: "\u9AD8\u7EA7",
|
|
2292
|
-
lazy: true,
|
|
2293
|
-
items: [
|
|
2294
|
-
{
|
|
2295
|
-
name: "created",
|
|
2296
|
-
text: "created",
|
|
2297
|
-
labelWidth: "100px",
|
|
2298
|
-
type: "code-select"
|
|
2299
|
-
},
|
|
2300
|
-
{
|
|
2301
|
-
name: "mounted",
|
|
2302
|
-
text: "mounted",
|
|
2303
|
-
labelWidth: "100px",
|
|
2304
|
-
type: "code-select"
|
|
2305
|
-
}
|
|
2306
|
-
]
|
|
2435
|
+
target.items.push(newConfig);
|
|
2436
|
+
await stage.select(targetId);
|
|
2437
|
+
const targetParent = this.getParentById(target.id);
|
|
2438
|
+
await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root });
|
|
2439
|
+
await this.select(newConfig);
|
|
2440
|
+
stage.select(newConfig.id);
|
|
2441
|
+
this.addModifiedNodeId(target.id);
|
|
2442
|
+
this.addModifiedNodeId(parent.id);
|
|
2443
|
+
this.pushHistoryState();
|
|
2444
|
+
return newConfig;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
async undo() {
|
|
2448
|
+
const value = historyService.undo();
|
|
2449
|
+
await this.changeHistoryState(value);
|
|
2450
|
+
return value;
|
|
2451
|
+
}
|
|
2452
|
+
async redo() {
|
|
2453
|
+
const value = historyService.redo();
|
|
2454
|
+
await this.changeHistoryState(value);
|
|
2455
|
+
return value;
|
|
2456
|
+
}
|
|
2457
|
+
async move(left, top) {
|
|
2458
|
+
const node = toRaw(this.get("node"));
|
|
2459
|
+
if (!node || isPage(node))
|
|
2460
|
+
return;
|
|
2461
|
+
const { style, id, type } = node;
|
|
2462
|
+
if (!style || style.position !== "absolute")
|
|
2463
|
+
return;
|
|
2464
|
+
if (top && !isNumber(style.top))
|
|
2465
|
+
return;
|
|
2466
|
+
if (left && !isNumber(style.left))
|
|
2467
|
+
return;
|
|
2468
|
+
this.update({
|
|
2469
|
+
id,
|
|
2470
|
+
type,
|
|
2471
|
+
style: {
|
|
2472
|
+
...style,
|
|
2473
|
+
left: Number(style.left) + left,
|
|
2474
|
+
top: Number(style.top) + top
|
|
2307
2475
|
}
|
|
2308
|
-
|
|
2476
|
+
});
|
|
2309
2477
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2478
|
+
resetState() {
|
|
2479
|
+
this.set("root", null);
|
|
2480
|
+
this.set("node", null);
|
|
2481
|
+
this.set("nodes", []);
|
|
2482
|
+
this.set("page", null);
|
|
2483
|
+
this.set("parent", null);
|
|
2484
|
+
this.set("stage", null);
|
|
2485
|
+
this.set("highlightNode", null);
|
|
2486
|
+
this.set("modifiedNodeIds", /* @__PURE__ */ new Map());
|
|
2487
|
+
this.set("pageLength", 0);
|
|
2315
2488
|
}
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2489
|
+
destroy() {
|
|
2490
|
+
this.removeAllListeners();
|
|
2491
|
+
this.resetState();
|
|
2492
|
+
this.removeAllPlugins();
|
|
2320
2493
|
}
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
if (process.env.NODE_ENV === "development") {
|
|
2324
|
-
console.warn("magic editor: ", ...args);
|
|
2494
|
+
resetModifiedNodeId() {
|
|
2495
|
+
this.get("modifiedNodeIds").clear();
|
|
2325
2496
|
}
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2497
|
+
addModifiedNodeId(id) {
|
|
2498
|
+
if (!this.isHistoryStateChange) {
|
|
2499
|
+
this.get("modifiedNodeIds").set(id, id);
|
|
2500
|
+
}
|
|
2330
2501
|
}
|
|
2331
|
-
|
|
2332
|
-
const
|
|
2333
|
-
|
|
2334
|
-
|
|
2502
|
+
pushHistoryState() {
|
|
2503
|
+
const curNode = cloneDeep(toRaw(this.get("node")));
|
|
2504
|
+
const page = this.get("page");
|
|
2505
|
+
if (!this.isHistoryStateChange && curNode && page) {
|
|
2506
|
+
historyService.push({
|
|
2507
|
+
data: cloneDeep(toRaw(page)),
|
|
2508
|
+
modifiedNodeIds: this.get("modifiedNodeIds"),
|
|
2509
|
+
nodeId: curNode.id
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
this.isHistoryStateChange = false;
|
|
2335
2513
|
}
|
|
2336
|
-
|
|
2514
|
+
async changeHistoryState(value) {
|
|
2515
|
+
if (!value)
|
|
2516
|
+
return;
|
|
2517
|
+
this.isHistoryStateChange = true;
|
|
2518
|
+
await this.update(value.data);
|
|
2519
|
+
this.set("modifiedNodeIds", value.modifiedNodeIds);
|
|
2520
|
+
setTimeout(async () => {
|
|
2521
|
+
if (!value.nodeId)
|
|
2522
|
+
return;
|
|
2523
|
+
await this.select(value.nodeId);
|
|
2524
|
+
this.get("stage")?.select(value.nodeId);
|
|
2525
|
+
}, 0);
|
|
2526
|
+
this.emit("history-change", value.data);
|
|
2527
|
+
}
|
|
2528
|
+
async toggleFixedPosition(dist, src, root) {
|
|
2529
|
+
const newConfig = cloneDeep(dist);
|
|
2530
|
+
if (!isPop(src) && newConfig.style?.position) {
|
|
2531
|
+
if (isFixed(newConfig) && !isFixed(src)) {
|
|
2532
|
+
newConfig.style = change2Fixed(newConfig, root);
|
|
2533
|
+
} else if (!isFixed(newConfig) && isFixed(src)) {
|
|
2534
|
+
newConfig.style = await Fixed2Other(newConfig, root, this.getLayout);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
return newConfig;
|
|
2538
|
+
}
|
|
2539
|
+
selectedConfigExceptionHandler(config) {
|
|
2540
|
+
let id;
|
|
2541
|
+
if (typeof config === "string" || typeof config === "number") {
|
|
2542
|
+
id = config;
|
|
2543
|
+
} else {
|
|
2544
|
+
id = config.id;
|
|
2545
|
+
}
|
|
2546
|
+
if (!id) {
|
|
2547
|
+
throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
|
|
2548
|
+
}
|
|
2549
|
+
const { node, parent, page } = this.getNodeInfo(id);
|
|
2550
|
+
if (!node)
|
|
2551
|
+
throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
|
|
2552
|
+
if (node.id === this.state.root?.id) {
|
|
2553
|
+
throw new Error("\u4E0D\u80FD\u9009\u6839\u8282\u70B9");
|
|
2554
|
+
}
|
|
2555
|
+
return {
|
|
2556
|
+
node,
|
|
2557
|
+
parent,
|
|
2558
|
+
page
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
const editorService = new Editor$1();
|
|
2337
2563
|
|
|
2338
2564
|
const state = reactive({
|
|
2339
2565
|
uiSelectMode: false,
|
|
@@ -2533,7 +2759,7 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
|
|
|
2533
2759
|
onClick: clickHandler
|
|
2534
2760
|
}, [
|
|
2535
2761
|
createElementVNode("div", null, [
|
|
2536
|
-
createVNode(_sfc_main$
|
|
2762
|
+
createVNode(_sfc_main$u, { icon: unref(Plus) }, null, 8, ["icon"])
|
|
2537
2763
|
]),
|
|
2538
2764
|
_hoisted_3$3
|
|
2539
2765
|
])
|
|
@@ -2764,7 +2990,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
|
|
|
2764
2990
|
disabled: unref(disabled)
|
|
2765
2991
|
}, {
|
|
2766
2992
|
default: withCtx(() => [
|
|
2767
|
-
__props.data.icon ? (openBlock(), createBlock(_sfc_main$
|
|
2993
|
+
__props.data.icon ? (openBlock(), createBlock(_sfc_main$u, {
|
|
2768
2994
|
key: 0,
|
|
2769
2995
|
icon: __props.data.icon
|
|
2770
2996
|
}, null, 8, ["icon"])) : createCommentVNode("", true),
|
|
@@ -2781,7 +3007,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
|
|
|
2781
3007
|
disabled: unref(disabled)
|
|
2782
3008
|
}, {
|
|
2783
3009
|
default: withCtx(() => [
|
|
2784
|
-
__props.data.icon ? (openBlock(), createBlock(_sfc_main$
|
|
3010
|
+
__props.data.icon ? (openBlock(), createBlock(_sfc_main$u, {
|
|
2785
3011
|
key: 0,
|
|
2786
3012
|
icon: __props.data.icon
|
|
2787
3013
|
}, null, 8, ["icon"])) : createCommentVNode("", true),
|
|
@@ -3139,14 +3365,17 @@ const _sfc_main$h = /* @__PURE__ */ defineComponent({
|
|
|
3139
3365
|
const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
|
|
3140
3366
|
if (codeDraft) {
|
|
3141
3367
|
tMagicMessageBox.confirm("\u60A8\u6709\u4EE3\u7801\u4FEE\u6539\u672A\u4FDD\u5B58\uFF0C\u662F\u5426\u4FDD\u5B58\u540E\u518D\u5173\u95ED\uFF1F", "\u63D0\u793A", {
|
|
3142
|
-
confirmButtonText: "\
|
|
3143
|
-
cancelButtonText: "\
|
|
3144
|
-
type: "warning"
|
|
3368
|
+
confirmButtonText: "\u4FDD\u5B58\u5E76\u5173\u95ED",
|
|
3369
|
+
cancelButtonText: "\u76F4\u63A5\u5173\u95ED",
|
|
3370
|
+
type: "warning",
|
|
3371
|
+
distinguishCancelAndClose: true
|
|
3145
3372
|
}).then(async () => {
|
|
3146
3373
|
saveAndClose();
|
|
3147
|
-
}).catch(() => {
|
|
3148
|
-
|
|
3149
|
-
|
|
3374
|
+
}).catch((action) => {
|
|
3375
|
+
if (action === "cancel") {
|
|
3376
|
+
services?.codeBlockService.removeCodeDraft(props.id);
|
|
3377
|
+
emit("close");
|
|
3378
|
+
}
|
|
3150
3379
|
});
|
|
3151
3380
|
} else {
|
|
3152
3381
|
emit("close");
|
|
@@ -3313,7 +3542,7 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
|
|
|
3313
3542
|
codeContent.value = props.content;
|
|
3314
3543
|
});
|
|
3315
3544
|
const initTableModel = () => {
|
|
3316
|
-
const codeDsl = cloneDeep(services?.codeBlockService.
|
|
3545
|
+
const codeDsl = cloneDeep(services?.codeBlockService.getCodeDsl());
|
|
3317
3546
|
if (!codeDsl)
|
|
3318
3547
|
return;
|
|
3319
3548
|
tableModel.value = {
|
|
@@ -3487,22 +3716,10 @@ const _hoisted_3 = /* @__PURE__ */ createTextVNode("\u65B0\u589E");
|
|
|
3487
3716
|
const _hoisted_4 = ["id"];
|
|
3488
3717
|
const _hoisted_5 = { class: "list-item" };
|
|
3489
3718
|
const _hoisted_6 = { class: "code-name" };
|
|
3490
|
-
const _hoisted_7 = {
|
|
3491
|
-
const _hoisted_8 = {
|
|
3719
|
+
const _hoisted_7 = {
|
|
3492
3720
|
key: 0,
|
|
3493
|
-
class: "
|
|
3721
|
+
class: "right-tool"
|
|
3494
3722
|
};
|
|
3495
|
-
const _hoisted_9 = /* @__PURE__ */ createElementVNode("svg", {
|
|
3496
|
-
class: "arrow-left",
|
|
3497
|
-
viewBox: "0 0 1024 1024",
|
|
3498
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
3499
|
-
"data-v-029747aa": ""
|
|
3500
|
-
}, [
|
|
3501
|
-
/* @__PURE__ */ createElementVNode("path", {
|
|
3502
|
-
fill: "currentColor",
|
|
3503
|
-
d: "M609.408 149.376 277.76 489.6a32 32 0 0 0 0 44.672l331.648 340.352a29.12 29.12 0 0 0 41.728 0 30.592 30.592 0 0 0 0-42.752L339.264 511.936l311.872-319.872a30.592 30.592 0 0 0 0-42.688 29.12 29.12 0 0 0-41.728 0z"
|
|
3504
|
-
})
|
|
3505
|
-
], -1);
|
|
3506
3723
|
const __default__$d = defineComponent({
|
|
3507
3724
|
name: "MEditorCodeBlockList"
|
|
3508
3725
|
});
|
|
@@ -3514,64 +3731,23 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3514
3731
|
},
|
|
3515
3732
|
setup(__props) {
|
|
3516
3733
|
const props = __props;
|
|
3517
|
-
const
|
|
3518
|
-
const
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
bindsComp.push({
|
|
3531
|
-
compId,
|
|
3532
|
-
compName: getCompName(compId)
|
|
3533
|
-
});
|
|
3534
|
-
}
|
|
3535
|
-
});
|
|
3536
|
-
return bindsComp;
|
|
3537
|
-
};
|
|
3538
|
-
const refreshCodeList = async () => {
|
|
3539
|
-
const codeDsl = cloneDeep(await services?.codeBlockService.getCodeDsl()) || null;
|
|
3540
|
-
codeCombineInfo.value = cloneDeep(services?.codeBlockService.getCombineInfo()) || null;
|
|
3541
|
-
if (!codeDsl || !codeCombineInfo.value)
|
|
3542
|
-
return;
|
|
3543
|
-
state.codeList = [];
|
|
3544
|
-
forIn(codeDsl, (value, codeId) => {
|
|
3545
|
-
state.codeList.push({
|
|
3546
|
-
id: codeId,
|
|
3547
|
-
name: value.name,
|
|
3548
|
-
codeBlockContent: value,
|
|
3549
|
-
showRelation: true,
|
|
3550
|
-
combineInfo: getBindCompsByCodeId(codeId)
|
|
3551
|
-
});
|
|
3552
|
-
});
|
|
3553
|
-
};
|
|
3554
|
-
watch(
|
|
3555
|
-
() => services?.editorService.get("root"),
|
|
3556
|
-
() => {
|
|
3557
|
-
services?.codeBlockService.refreshAllRelations();
|
|
3558
|
-
refreshCodeList();
|
|
3559
|
-
},
|
|
3560
|
-
{
|
|
3561
|
-
immediate: true
|
|
3562
|
-
}
|
|
3563
|
-
);
|
|
3564
|
-
watch(
|
|
3565
|
-
[() => services?.codeBlockService.getCodeDslSync(), () => services?.codeBlockService.getCombineInfo()],
|
|
3566
|
-
() => {
|
|
3567
|
-
refreshCodeList();
|
|
3568
|
-
},
|
|
3569
|
-
{
|
|
3570
|
-
deep: true
|
|
3571
|
-
}
|
|
3734
|
+
const { codeBlockService, depService, editorService } = inject("services") || {};
|
|
3735
|
+
const codeList = computed(
|
|
3736
|
+
() => Object.values(depService?.targets["code-block"] || {}).map((target) => ({
|
|
3737
|
+
id: target.id,
|
|
3738
|
+
name: target.name,
|
|
3739
|
+
type: "code",
|
|
3740
|
+
children: Object.entries(target.deps).map(([id, dep]) => ({
|
|
3741
|
+
name: dep.name,
|
|
3742
|
+
type: "node",
|
|
3743
|
+
id,
|
|
3744
|
+
children: dep.keys.map((key) => ({ name: key, id: key, type: "key" }))
|
|
3745
|
+
}))
|
|
3746
|
+
}))
|
|
3572
3747
|
);
|
|
3748
|
+
const editable = computed(() => codeBlockService?.getEditStatus());
|
|
3749
|
+
const isShowCodeBlockEditor = computed(() => codeBlockService?.getCodeEditorShowStatus() || false);
|
|
3573
3750
|
const createCodeBlock = async () => {
|
|
3574
|
-
const { codeBlockService } = services || {};
|
|
3575
3751
|
if (!codeBlockService) {
|
|
3576
3752
|
tMagicMessage.error("\u65B0\u589E\u4EE3\u7801\u5757\u5931\u8D25");
|
|
3577
3753
|
return;
|
|
@@ -3588,14 +3764,14 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3588
3764
|
codeBlockService.setCodeEditorContent(true, id);
|
|
3589
3765
|
};
|
|
3590
3766
|
const editCode = async (key) => {
|
|
3591
|
-
|
|
3767
|
+
codeBlockService?.setCodeEditorContent(true, key);
|
|
3592
3768
|
};
|
|
3593
3769
|
const deleteCode = (key) => {
|
|
3594
|
-
const currentCode =
|
|
3595
|
-
const existBinds =
|
|
3596
|
-
const undeleteableList =
|
|
3770
|
+
const currentCode = codeList.value.find((codeItem) => codeItem.id === key);
|
|
3771
|
+
const existBinds = Boolean(currentCode?.children.length);
|
|
3772
|
+
const undeleteableList = codeBlockService?.getUndeletableList() || [];
|
|
3597
3773
|
if (!existBinds && !undeleteableList.includes(key)) {
|
|
3598
|
-
|
|
3774
|
+
codeBlockService?.deleteCodeDslByIds([key]);
|
|
3599
3775
|
} else {
|
|
3600
3776
|
if (typeof props.customError === "function") {
|
|
3601
3777
|
props.customError(key, existBinds ? CodeDeleteErrorType.BIND : CodeDeleteErrorType.UNDELETEABLE);
|
|
@@ -3610,27 +3786,23 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3610
3786
|
if (!value) {
|
|
3611
3787
|
return true;
|
|
3612
3788
|
}
|
|
3613
|
-
return `${data.name}${data.id}`.indexOf(value) !== -1;
|
|
3789
|
+
return `${data.name}${data.id}`.toLocaleLowerCase().indexOf(value.toLocaleLowerCase()) !== -1;
|
|
3614
3790
|
};
|
|
3615
3791
|
const filterTextChangeHandler = (val) => {
|
|
3616
3792
|
tree.value?.filter(val);
|
|
3617
3793
|
};
|
|
3618
|
-
const toggleCombineRelation = (data) => {
|
|
3619
|
-
const { id } = data;
|
|
3620
|
-
const currentCode = state.codeList.find((item) => item.id === id);
|
|
3621
|
-
if (!currentCode)
|
|
3622
|
-
return;
|
|
3623
|
-
currentCode.showRelation = !currentCode?.showRelation;
|
|
3624
|
-
};
|
|
3625
|
-
const getCompName = (compId) => {
|
|
3626
|
-
const node = services?.editorService.getNodeById(compId);
|
|
3627
|
-
return node?.name || String(compId);
|
|
3628
|
-
};
|
|
3629
3794
|
const selectComp = (compId) => {
|
|
3630
|
-
const stage =
|
|
3631
|
-
|
|
3795
|
+
const stage = editorService?.get("stage");
|
|
3796
|
+
editorService?.select(compId);
|
|
3632
3797
|
stage?.select(compId);
|
|
3633
3798
|
};
|
|
3799
|
+
const clickHandler = (data, node) => {
|
|
3800
|
+
if (data.type === "node") {
|
|
3801
|
+
selectComp(data.id);
|
|
3802
|
+
} else if (data.type === "key") {
|
|
3803
|
+
selectComp(node.parent.data.id);
|
|
3804
|
+
}
|
|
3805
|
+
};
|
|
3634
3806
|
return (_ctx, _cache) => {
|
|
3635
3807
|
return openBlock(), createElementBlock("div", _hoisted_1$6, [
|
|
3636
3808
|
renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
|
|
@@ -3660,16 +3832,18 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3660
3832
|
]),
|
|
3661
3833
|
createVNode(unref(TMagicScrollbar), null, {
|
|
3662
3834
|
default: withCtx(() => [
|
|
3663
|
-
|
|
3664
|
-
key: 0,
|
|
3835
|
+
createVNode(unref(TMagicTree), {
|
|
3665
3836
|
ref_key: "tree",
|
|
3666
3837
|
ref: tree,
|
|
3838
|
+
class: "magic-editor-layer-tree",
|
|
3667
3839
|
"node-key": "id",
|
|
3668
3840
|
"empty-text": "\u6682\u65E0\u4EE3\u7801\u5757",
|
|
3669
|
-
|
|
3841
|
+
"default-expand-all": "",
|
|
3842
|
+
"expand-on-click-node": false,
|
|
3843
|
+
data: unref(codeList),
|
|
3670
3844
|
"highlight-current": true,
|
|
3671
3845
|
"filter-node-method": filterNode,
|
|
3672
|
-
onNodeClick:
|
|
3846
|
+
onNodeClick: clickHandler
|
|
3673
3847
|
}, {
|
|
3674
3848
|
default: withCtx(({ data }) => [
|
|
3675
3849
|
createElementVNode("div", {
|
|
@@ -3678,14 +3852,14 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3678
3852
|
}, [
|
|
3679
3853
|
createElementVNode("div", _hoisted_5, [
|
|
3680
3854
|
createElementVNode("span", _hoisted_6, toDisplayString(data.name) + "\uFF08" + toDisplayString(data.id) + "\uFF09", 1),
|
|
3681
|
-
|
|
3855
|
+
data.type === "code" ? (openBlock(), createElementBlock("div", _hoisted_7, [
|
|
3682
3856
|
createVNode(unref(TMagicTooltip), {
|
|
3683
3857
|
effect: "dark",
|
|
3684
3858
|
content: unref(editable) ? "\u7F16\u8F91" : "\u67E5\u770B",
|
|
3685
3859
|
placement: "bottom"
|
|
3686
3860
|
}, {
|
|
3687
3861
|
default: withCtx(() => [
|
|
3688
|
-
createVNode(_sfc_main$
|
|
3862
|
+
createVNode(_sfc_main$u, {
|
|
3689
3863
|
icon: unref(editable) ? unref(Edit) : unref(View),
|
|
3690
3864
|
class: "edit-icon",
|
|
3691
3865
|
onClick: withModifiers(($event) => editCode(`${data.id}`), ["stop"])
|
|
@@ -3693,29 +3867,14 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3693
3867
|
]),
|
|
3694
3868
|
_: 2
|
|
3695
3869
|
}, 1032, ["content"]),
|
|
3696
|
-
data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createBlock(unref(TMagicTooltip), {
|
|
3697
|
-
key: 0,
|
|
3698
|
-
effect: "dark",
|
|
3699
|
-
content: "\u67E5\u770B\u7ED1\u5B9A\u5173\u7CFB",
|
|
3700
|
-
placement: "bottom"
|
|
3701
|
-
}, {
|
|
3702
|
-
default: withCtx(() => [
|
|
3703
|
-
createVNode(_sfc_main$s, {
|
|
3704
|
-
icon: unref(Link),
|
|
3705
|
-
class: "edit-icon",
|
|
3706
|
-
onClick: withModifiers(($event) => toggleCombineRelation(data), ["stop"])
|
|
3707
|
-
}, null, 8, ["icon", "onClick"])
|
|
3708
|
-
]),
|
|
3709
|
-
_: 2
|
|
3710
|
-
}, 1024)) : createCommentVNode("", true),
|
|
3711
3870
|
unref(editable) ? (openBlock(), createBlock(unref(TMagicTooltip), {
|
|
3712
|
-
key:
|
|
3871
|
+
key: 0,
|
|
3713
3872
|
effect: "dark",
|
|
3714
3873
|
content: "\u5220\u9664",
|
|
3715
3874
|
placement: "bottom"
|
|
3716
3875
|
}, {
|
|
3717
3876
|
default: withCtx(() => [
|
|
3718
|
-
createVNode(_sfc_main$
|
|
3877
|
+
createVNode(_sfc_main$u, {
|
|
3719
3878
|
icon: unref(Close),
|
|
3720
3879
|
class: "edit-icon",
|
|
3721
3880
|
onClick: withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
|
|
@@ -3727,29 +3886,12 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
|
|
|
3727
3886
|
id: data.id,
|
|
3728
3887
|
data: data.codeBlockContent
|
|
3729
3888
|
})
|
|
3730
|
-
])
|
|
3731
|
-
])
|
|
3732
|
-
data.showRelation && data.combineInfo && data.combineInfo.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_8, [
|
|
3733
|
-
_hoisted_9,
|
|
3734
|
-
(openBlock(true), createElementBlock(Fragment, null, renderList(data.combineInfo, (comp, index) => {
|
|
3735
|
-
return openBlock(), createBlock(unref(TMagicButton), {
|
|
3736
|
-
key: index,
|
|
3737
|
-
class: "code-comp",
|
|
3738
|
-
size: "small",
|
|
3739
|
-
plain: true,
|
|
3740
|
-
onClick: withModifiers(($event) => selectComp(comp.compId), ["stop"])
|
|
3741
|
-
}, {
|
|
3742
|
-
default: withCtx(() => [
|
|
3743
|
-
createTextVNode(toDisplayString(comp.compName), 1)
|
|
3744
|
-
]),
|
|
3745
|
-
_: 2
|
|
3746
|
-
}, 1032, ["onClick"]);
|
|
3747
|
-
}), 128))
|
|
3748
|
-
])) : createCommentVNode("", true)
|
|
3889
|
+
])) : createCommentVNode("", true)
|
|
3890
|
+
])
|
|
3749
3891
|
], 8, _hoisted_4)
|
|
3750
3892
|
]),
|
|
3751
3893
|
_: 3
|
|
3752
|
-
}, 8, ["data"])
|
|
3894
|
+
}, 8, ["data"])
|
|
3753
3895
|
]),
|
|
3754
3896
|
_: 3
|
|
3755
3897
|
}),
|
|
@@ -3861,7 +4003,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
|
|
|
3861
4003
|
name: `${index}`
|
|
3862
4004
|
}, {
|
|
3863
4005
|
title: withCtx(() => [
|
|
3864
|
-
createVNode(_sfc_main$
|
|
4006
|
+
createVNode(_sfc_main$u, { icon: unref(Grid) }, null, 8, ["icon"]),
|
|
3865
4007
|
createTextVNode(toDisplayString(group.title), 1)
|
|
3866
4008
|
]),
|
|
3867
4009
|
default: withCtx(() => [
|
|
@@ -3876,7 +4018,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
|
|
|
3876
4018
|
onDrag: dragHandler
|
|
3877
4019
|
}, [
|
|
3878
4020
|
renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
|
|
3879
|
-
createVNode(_sfc_main$
|
|
4021
|
+
createVNode(_sfc_main$u, {
|
|
3880
4022
|
icon: item.icon
|
|
3881
4023
|
}, null, 8, ["icon"]),
|
|
3882
4024
|
createVNode(unref(TMagicTooltip), {
|
|
@@ -4477,7 +4619,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
|
|
|
4477
4619
|
(openBlock(), createElementBlock("div", {
|
|
4478
4620
|
key: config.text
|
|
4479
4621
|
}, [
|
|
4480
|
-
config.icon ? (openBlock(), createBlock(_sfc_main$
|
|
4622
|
+
config.icon ? (openBlock(), createBlock(_sfc_main$u, {
|
|
4481
4623
|
key: 0,
|
|
4482
4624
|
icon: config.icon
|
|
4483
4625
|
}, null, 8, ["icon"])) : createCommentVNode("", true),
|
|
@@ -4698,14 +4840,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
|
|
|
4698
4840
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
4699
4841
|
onClick: addPage
|
|
4700
4842
|
}, [
|
|
4701
|
-
createVNode(_sfc_main$
|
|
4843
|
+
createVNode(_sfc_main$u, { icon: unref(Plus) }, null, 8, ["icon"])
|
|
4702
4844
|
])) : (openBlock(), createElementBlock("div", _hoisted_1$1)),
|
|
4703
4845
|
canScroll.value ? (openBlock(), createElementBlock("div", {
|
|
4704
4846
|
key: 2,
|
|
4705
4847
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
4706
4848
|
onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
|
|
4707
4849
|
}, [
|
|
4708
|
-
createVNode(_sfc_main$
|
|
4850
|
+
createVNode(_sfc_main$u, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
|
|
4709
4851
|
])) : createCommentVNode("", true),
|
|
4710
4852
|
unref(pageLength) ? (openBlock(), createElementBlock("div", {
|
|
4711
4853
|
key: 3,
|
|
@@ -4721,7 +4863,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
|
|
|
4721
4863
|
class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
|
|
4722
4864
|
onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
|
|
4723
4865
|
}, [
|
|
4724
|
-
createVNode(_sfc_main$
|
|
4866
|
+
createVNode(_sfc_main$u, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
|
|
4725
4867
|
])) : createCommentVNode("", true)
|
|
4726
4868
|
], 512);
|
|
4727
4869
|
};
|
|
@@ -5612,13 +5754,10 @@ class CodeBlock extends BaseService {
|
|
|
5612
5754
|
id: "",
|
|
5613
5755
|
editable: true,
|
|
5614
5756
|
combineIds: [],
|
|
5615
|
-
undeletableList: []
|
|
5616
|
-
relations: {}
|
|
5757
|
+
undeletableList: []
|
|
5617
5758
|
});
|
|
5618
5759
|
constructor() {
|
|
5619
5760
|
super([
|
|
5620
|
-
"setCodeDsl",
|
|
5621
|
-
"getCodeDsl",
|
|
5622
5761
|
"getCodeContentById",
|
|
5623
5762
|
"getCodeDslByIds",
|
|
5624
5763
|
"getCurrentDsl",
|
|
@@ -5632,17 +5771,10 @@ class CodeBlock extends BaseService {
|
|
|
5632
5771
|
}
|
|
5633
5772
|
async setCodeDsl(codeDsl2) {
|
|
5634
5773
|
this.state.codeDsl = codeDsl2;
|
|
5635
|
-
await editorService.setCodeDsl(this.state.codeDsl);
|
|
5636
5774
|
info("[code-block]:code-dsl-change", this.state.codeDsl);
|
|
5637
5775
|
this.emit("code-dsl-change", this.state.codeDsl);
|
|
5638
5776
|
}
|
|
5639
|
-
|
|
5640
|
-
return this.getCodeDslSync(forceRefresh);
|
|
5641
|
-
}
|
|
5642
|
-
getCodeDslSync(forceRefresh = false) {
|
|
5643
|
-
if (!this.state.codeDsl || forceRefresh) {
|
|
5644
|
-
this.state.codeDsl = editorService.getCodeDslSync();
|
|
5645
|
-
}
|
|
5777
|
+
getCodeDsl() {
|
|
5646
5778
|
return this.state.codeDsl;
|
|
5647
5779
|
}
|
|
5648
5780
|
async getCodeContentById(id2) {
|
|
@@ -5654,28 +5786,20 @@ class CodeBlock extends BaseService {
|
|
|
5654
5786
|
return totalCodeDsl[id2] ?? null;
|
|
5655
5787
|
}
|
|
5656
5788
|
async setCodeDslById(id, codeConfig) {
|
|
5657
|
-
|
|
5789
|
+
const codeDsl = await this.getCodeDsl();
|
|
5790
|
+
if (!codeDsl) {
|
|
5791
|
+
throw new Error("dsl\u4E2D\u6CA1\u6709codeBlocks");
|
|
5792
|
+
}
|
|
5658
5793
|
const codeConfigProcessed = codeConfig;
|
|
5659
5794
|
if (codeConfig.content) {
|
|
5660
5795
|
codeConfigProcessed.content = eval(codeConfig.content);
|
|
5661
5796
|
}
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
|
|
5667
|
-
|
|
5668
|
-
} else {
|
|
5669
|
-
const existContent = codeDsl[id] || {};
|
|
5670
|
-
codeDsl = {
|
|
5671
|
-
...codeDsl,
|
|
5672
|
-
[id]: {
|
|
5673
|
-
...existContent,
|
|
5674
|
-
...codeConfigProcessed
|
|
5675
|
-
}
|
|
5676
|
-
};
|
|
5677
|
-
}
|
|
5678
|
-
await this.setCodeDsl(codeDsl);
|
|
5797
|
+
const existContent = codeDsl[id] || {};
|
|
5798
|
+
codeDsl[id] = {
|
|
5799
|
+
...existContent,
|
|
5800
|
+
...codeConfigProcessed
|
|
5801
|
+
};
|
|
5802
|
+
this.emit("addOrUpdate", id, codeDsl[id]);
|
|
5679
5803
|
}
|
|
5680
5804
|
async getCodeDslByIds(ids) {
|
|
5681
5805
|
const codeDsl2 = await this.getCodeDsl();
|
|
@@ -5716,39 +5840,6 @@ class CodeBlock extends BaseService {
|
|
|
5716
5840
|
getCombineIds() {
|
|
5717
5841
|
return this.state.combineIds;
|
|
5718
5842
|
}
|
|
5719
|
-
addCodeRelationListener() {
|
|
5720
|
-
editorService.on("update", (nodes) => {
|
|
5721
|
-
const relations = cloneDeep(this.state.relations);
|
|
5722
|
-
nodes.forEach((node) => {
|
|
5723
|
-
if (node?.id) {
|
|
5724
|
-
relations[node.id] = [];
|
|
5725
|
-
this.getNodeRelation(node, relations);
|
|
5726
|
-
}
|
|
5727
|
-
});
|
|
5728
|
-
this.state.relations = { ...relations };
|
|
5729
|
-
});
|
|
5730
|
-
editorService.on("remove", (nodes) => {
|
|
5731
|
-
nodes.forEach((node) => {
|
|
5732
|
-
this.state.relations = this.deleteNodeRelation(node, this.state.relations);
|
|
5733
|
-
});
|
|
5734
|
-
});
|
|
5735
|
-
editorService.on("history-change", (page) => {
|
|
5736
|
-
const relations = {};
|
|
5737
|
-
this.getNodeRelation(page, relations, true);
|
|
5738
|
-
this.state.relations = relations;
|
|
5739
|
-
});
|
|
5740
|
-
}
|
|
5741
|
-
refreshAllRelations() {
|
|
5742
|
-
const root = editorService.get("root");
|
|
5743
|
-
if (!root)
|
|
5744
|
-
return;
|
|
5745
|
-
const relations = {};
|
|
5746
|
-
this.getNodeRelation(root, relations, true);
|
|
5747
|
-
this.state.relations = relations;
|
|
5748
|
-
}
|
|
5749
|
-
getCombineInfo() {
|
|
5750
|
-
return this.state.relations;
|
|
5751
|
-
}
|
|
5752
5843
|
getUndeletableList() {
|
|
5753
5844
|
return this.state.undeletableList;
|
|
5754
5845
|
}
|
|
@@ -5766,90 +5857,272 @@ class CodeBlock extends BaseService {
|
|
|
5766
5857
|
}
|
|
5767
5858
|
async deleteCodeDslByIds(codeIds) {
|
|
5768
5859
|
const currentDsl = await this.getCodeDsl();
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5860
|
+
if (!currentDsl)
|
|
5861
|
+
return;
|
|
5862
|
+
codeIds.forEach((id2) => {
|
|
5863
|
+
delete currentDsl[id2];
|
|
5864
|
+
this.emit("remove", id2);
|
|
5865
|
+
});
|
|
5866
|
+
}
|
|
5867
|
+
async getUniqueId() {
|
|
5868
|
+
const newId = `code_${Math.random().toString(10).substring(2).substring(0, 4)}`;
|
|
5869
|
+
const dsl = await this.getCodeDsl();
|
|
5870
|
+
const existedIds = keys(dsl);
|
|
5871
|
+
if (!existedIds.includes(newId))
|
|
5872
|
+
return newId;
|
|
5873
|
+
return await this.getUniqueId();
|
|
5874
|
+
}
|
|
5875
|
+
resetState() {
|
|
5876
|
+
this.state.isShowCodeEditor = false;
|
|
5877
|
+
this.state.codeDsl = null;
|
|
5878
|
+
this.state.id = "";
|
|
5879
|
+
this.state.editable = true;
|
|
5880
|
+
this.state.combineIds = [];
|
|
5881
|
+
this.state.undeletableList = [];
|
|
5882
|
+
}
|
|
5883
|
+
destroy() {
|
|
5884
|
+
this.resetState();
|
|
5885
|
+
this.removeAllListeners();
|
|
5886
|
+
this.removeAllPlugins();
|
|
5887
|
+
}
|
|
5888
|
+
}
|
|
5889
|
+
const codeBlockService = new CodeBlock();
|
|
5890
|
+
|
|
5891
|
+
class ComponentList extends BaseService {
|
|
5892
|
+
state = reactive({
|
|
5893
|
+
list: []
|
|
5894
|
+
});
|
|
5895
|
+
constructor() {
|
|
5896
|
+
super([]);
|
|
5897
|
+
}
|
|
5898
|
+
setList(componentGroupList) {
|
|
5899
|
+
this.state.list = componentGroupList;
|
|
5772
5900
|
}
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
const dsl = await this.getCodeDsl();
|
|
5776
|
-
const existedIds = keys(dsl);
|
|
5777
|
-
if (!existedIds.includes(newId))
|
|
5778
|
-
return newId;
|
|
5779
|
-
return await this.getUniqueId();
|
|
5901
|
+
getList() {
|
|
5902
|
+
return this.state.list;
|
|
5780
5903
|
}
|
|
5781
5904
|
resetState() {
|
|
5782
|
-
this.state.
|
|
5783
|
-
this.state.codeDsl = null;
|
|
5784
|
-
this.state.id = "";
|
|
5785
|
-
this.state.editable = true;
|
|
5786
|
-
this.state.combineIds = [];
|
|
5787
|
-
this.state.undeletableList = [];
|
|
5905
|
+
this.state.list = [];
|
|
5788
5906
|
}
|
|
5789
5907
|
destroy() {
|
|
5790
5908
|
this.resetState();
|
|
5791
5909
|
this.removeAllListeners();
|
|
5792
5910
|
this.removeAllPlugins();
|
|
5793
5911
|
}
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5912
|
+
}
|
|
5913
|
+
const componentListService = new ComponentList();
|
|
5914
|
+
|
|
5915
|
+
class Target extends EventEmitter {
|
|
5916
|
+
isTarget;
|
|
5917
|
+
id;
|
|
5918
|
+
name;
|
|
5919
|
+
type = "default";
|
|
5920
|
+
deps = reactive({});
|
|
5921
|
+
constructor(options) {
|
|
5922
|
+
super();
|
|
5923
|
+
this.isTarget = options.isTarget;
|
|
5924
|
+
this.id = options.id;
|
|
5925
|
+
this.name = options.name;
|
|
5926
|
+
if (options.type) {
|
|
5927
|
+
this.type = options.type;
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5930
|
+
updateDep(node, key) {
|
|
5931
|
+
const dep = this.deps[node.id] || {
|
|
5932
|
+
name: node.name,
|
|
5933
|
+
keys: []
|
|
5934
|
+
};
|
|
5935
|
+
if (node.name) {
|
|
5936
|
+
dep.name = node.name;
|
|
5937
|
+
}
|
|
5938
|
+
this.deps[node.id] = dep;
|
|
5939
|
+
if (dep.keys.indexOf(key) === -1) {
|
|
5940
|
+
dep.keys.push(key);
|
|
5941
|
+
}
|
|
5942
|
+
this.emit("change");
|
|
5943
|
+
}
|
|
5944
|
+
removeDep(node, key) {
|
|
5945
|
+
if (!node) {
|
|
5946
|
+
Object.keys(this.deps).forEach((depKey) => {
|
|
5947
|
+
delete this.deps[depKey];
|
|
5948
|
+
});
|
|
5949
|
+
this.emit("change");
|
|
5950
|
+
return;
|
|
5951
|
+
}
|
|
5952
|
+
const dep = this.deps[node.id];
|
|
5953
|
+
if (!dep)
|
|
5954
|
+
return;
|
|
5955
|
+
if (key) {
|
|
5956
|
+
const index = dep.keys.indexOf(key);
|
|
5957
|
+
dep.keys.splice(index, 1);
|
|
5958
|
+
if (dep.keys.length === 0) {
|
|
5959
|
+
delete this.deps[node.id];
|
|
5803
5960
|
}
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5961
|
+
} else {
|
|
5962
|
+
delete this.deps[node.id];
|
|
5963
|
+
}
|
|
5964
|
+
this.emit("change");
|
|
5965
|
+
}
|
|
5966
|
+
hasDep(node, key) {
|
|
5967
|
+
const dep = this.deps[node.id];
|
|
5968
|
+
return Boolean(dep?.keys.find((d) => d === key));
|
|
5969
|
+
}
|
|
5970
|
+
destroy() {
|
|
5971
|
+
this.removeAllListeners();
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
class Watcher extends EventEmitter {
|
|
5975
|
+
targets = reactive({});
|
|
5976
|
+
getTargets(type = "default") {
|
|
5977
|
+
return this.targets[type] || {};
|
|
5978
|
+
}
|
|
5979
|
+
addTarget(target) {
|
|
5980
|
+
const targets = this.getTargets(target.type) || {};
|
|
5981
|
+
this.targets[target.type] = targets;
|
|
5982
|
+
targets[target.id] = target;
|
|
5983
|
+
this.emit("add-target", target);
|
|
5984
|
+
}
|
|
5985
|
+
getTarget(id) {
|
|
5986
|
+
const allTargets = Object.values(this.targets);
|
|
5987
|
+
for (const targets of allTargets) {
|
|
5988
|
+
if (targets[id]) {
|
|
5989
|
+
return targets[id];
|
|
5809
5990
|
}
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5991
|
+
}
|
|
5992
|
+
}
|
|
5993
|
+
hasTarget(id) {
|
|
5994
|
+
const allTargets = Object.values(this.targets);
|
|
5995
|
+
for (const targets of allTargets) {
|
|
5996
|
+
if (targets[id]) {
|
|
5997
|
+
return true;
|
|
5816
5998
|
}
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5999
|
+
}
|
|
6000
|
+
return false;
|
|
6001
|
+
}
|
|
6002
|
+
removeTarget(id) {
|
|
6003
|
+
const allTargets = Object.values(this.targets);
|
|
6004
|
+
for (const targets of allTargets) {
|
|
6005
|
+
if (targets[id]) {
|
|
6006
|
+
targets[id].destroy();
|
|
6007
|
+
delete targets[id];
|
|
5821
6008
|
}
|
|
6009
|
+
}
|
|
6010
|
+
this.emit("remove-target");
|
|
6011
|
+
}
|
|
6012
|
+
removeTargets(type = "default") {
|
|
6013
|
+
const targets = this.targets[type];
|
|
6014
|
+
if (!targets)
|
|
6015
|
+
return;
|
|
6016
|
+
for (const target of Object.values(targets)) {
|
|
6017
|
+
target.destroy();
|
|
6018
|
+
}
|
|
6019
|
+
delete this.targets[type];
|
|
6020
|
+
this.emit("remove-target");
|
|
6021
|
+
}
|
|
6022
|
+
clearTargets() {
|
|
6023
|
+
Object.keys(this.targets).forEach((key) => {
|
|
6024
|
+
delete this.targets[key];
|
|
6025
|
+
});
|
|
6026
|
+
}
|
|
6027
|
+
collect(nodes, deep = false) {
|
|
6028
|
+
Object.values(this.targets).forEach((targets) => {
|
|
6029
|
+
Object.values(targets).forEach((target) => {
|
|
6030
|
+
nodes.forEach((node) => {
|
|
6031
|
+
target.removeDep(node);
|
|
6032
|
+
this.collectItem(node, target, deep);
|
|
6033
|
+
});
|
|
6034
|
+
});
|
|
5822
6035
|
});
|
|
5823
6036
|
}
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
6037
|
+
clear(nodes) {
|
|
6038
|
+
Object.values(this.targets).forEach((targets) => {
|
|
6039
|
+
Object.values(targets).forEach((target) => {
|
|
6040
|
+
if (nodes) {
|
|
6041
|
+
nodes.forEach((node) => {
|
|
6042
|
+
target.removeDep(node);
|
|
6043
|
+
if (Array.isArray(node.items)) {
|
|
6044
|
+
this.clear(node.items);
|
|
6045
|
+
}
|
|
6046
|
+
});
|
|
6047
|
+
} else {
|
|
6048
|
+
target.removeDep();
|
|
6049
|
+
}
|
|
5831
6050
|
});
|
|
5832
|
-
}
|
|
5833
|
-
|
|
6051
|
+
});
|
|
6052
|
+
}
|
|
6053
|
+
collectItem(node, target, deep = false) {
|
|
6054
|
+
const collectTarget = (config, prop = "") => {
|
|
6055
|
+
const doCollect = (key, value) => {
|
|
6056
|
+
const keyIsItems = key === "items";
|
|
6057
|
+
const fullKey = prop ? `${prop}.${key}` : key;
|
|
6058
|
+
if (target.isTarget(key, value)) {
|
|
6059
|
+
target.updateDep(node, fullKey);
|
|
6060
|
+
} else if (!keyIsItems && Array.isArray(value)) {
|
|
6061
|
+
value.forEach((item, index) => {
|
|
6062
|
+
collectTarget(item, `${fullKey}.${index}`);
|
|
6063
|
+
});
|
|
6064
|
+
} else if (Object.prototype.toString.call(value) === "[object Object]") {
|
|
6065
|
+
collectTarget(value, fullKey);
|
|
6066
|
+
}
|
|
6067
|
+
if (keyIsItems && deep && Array.isArray(value)) {
|
|
6068
|
+
value.forEach((child) => {
|
|
6069
|
+
this.collectItem(child, target, deep);
|
|
6070
|
+
});
|
|
6071
|
+
}
|
|
6072
|
+
};
|
|
6073
|
+
Object.entries(config).forEach(([key, value]) => {
|
|
6074
|
+
doCollect(key, value);
|
|
6075
|
+
});
|
|
6076
|
+
};
|
|
6077
|
+
collectTarget(node);
|
|
5834
6078
|
}
|
|
5835
6079
|
}
|
|
5836
|
-
const
|
|
6080
|
+
const depService = new Watcher();
|
|
5837
6081
|
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
});
|
|
6082
|
+
let eventMap = reactive({});
|
|
6083
|
+
let methodMap = reactive({});
|
|
6084
|
+
class Events extends BaseService {
|
|
5842
6085
|
constructor() {
|
|
5843
6086
|
super([]);
|
|
5844
6087
|
}
|
|
5845
|
-
|
|
5846
|
-
|
|
6088
|
+
init(componentGroupList) {
|
|
6089
|
+
componentGroupList.forEach((group) => {
|
|
6090
|
+
group.items.forEach((element) => {
|
|
6091
|
+
const type = toLine(element.type);
|
|
6092
|
+
if (!this.getEvent(type)) {
|
|
6093
|
+
this.setEvent(type, DEFAULT_EVENTS);
|
|
6094
|
+
}
|
|
6095
|
+
if (!this.getMethod(type)) {
|
|
6096
|
+
this.setMethod(type, DEFAULT_METHODS);
|
|
6097
|
+
}
|
|
6098
|
+
});
|
|
6099
|
+
});
|
|
5847
6100
|
}
|
|
5848
|
-
|
|
5849
|
-
|
|
6101
|
+
setEvents(events) {
|
|
6102
|
+
Object.keys(events).forEach((type) => {
|
|
6103
|
+
this.setEvent(toLine(type), events[type] || []);
|
|
6104
|
+
});
|
|
6105
|
+
}
|
|
6106
|
+
setEvent(type, events) {
|
|
6107
|
+
eventMap[type] = [...DEFAULT_EVENTS, ...events];
|
|
6108
|
+
}
|
|
6109
|
+
getEvent(type) {
|
|
6110
|
+
return cloneDeep(eventMap[type] || DEFAULT_EVENTS);
|
|
6111
|
+
}
|
|
6112
|
+
setMethods(methods) {
|
|
6113
|
+
Object.keys(methods).forEach((type) => {
|
|
6114
|
+
this.setMethod(toLine(type), methods[type] || []);
|
|
6115
|
+
});
|
|
6116
|
+
}
|
|
6117
|
+
setMethod(type, method) {
|
|
6118
|
+
methodMap[type] = [...DEFAULT_METHODS, ...method];
|
|
6119
|
+
}
|
|
6120
|
+
getMethod(type) {
|
|
6121
|
+
return cloneDeep(methodMap[type] || DEFAULT_METHODS);
|
|
5850
6122
|
}
|
|
5851
6123
|
resetState() {
|
|
5852
|
-
|
|
6124
|
+
eventMap = reactive({});
|
|
6125
|
+
methodMap = reactive({});
|
|
5853
6126
|
}
|
|
5854
6127
|
destroy() {
|
|
5855
6128
|
this.resetState();
|
|
@@ -5857,7 +6130,252 @@ class ComponentList extends BaseService {
|
|
|
5857
6130
|
this.removeAllPlugins();
|
|
5858
6131
|
}
|
|
5859
6132
|
}
|
|
5860
|
-
const
|
|
6133
|
+
const eventsService = new Events();
|
|
6134
|
+
|
|
6135
|
+
const editorProps = {
|
|
6136
|
+
modelValue: {
|
|
6137
|
+
type: Object,
|
|
6138
|
+
default: () => ({}),
|
|
6139
|
+
require: true
|
|
6140
|
+
},
|
|
6141
|
+
componentGroupList: {
|
|
6142
|
+
type: Array,
|
|
6143
|
+
default: () => []
|
|
6144
|
+
},
|
|
6145
|
+
sidebar: {
|
|
6146
|
+
type: Object
|
|
6147
|
+
},
|
|
6148
|
+
menu: {
|
|
6149
|
+
type: Object,
|
|
6150
|
+
default: () => ({ left: [], right: [] })
|
|
6151
|
+
},
|
|
6152
|
+
layerContentMenu: {
|
|
6153
|
+
type: Array,
|
|
6154
|
+
default: () => []
|
|
6155
|
+
},
|
|
6156
|
+
stageContentMenu: {
|
|
6157
|
+
type: Array,
|
|
6158
|
+
default: () => []
|
|
6159
|
+
},
|
|
6160
|
+
render: {
|
|
6161
|
+
type: Function
|
|
6162
|
+
},
|
|
6163
|
+
runtimeUrl: String,
|
|
6164
|
+
autoScrollIntoView: Boolean,
|
|
6165
|
+
propsConfigs: {
|
|
6166
|
+
type: Object,
|
|
6167
|
+
default: () => ({})
|
|
6168
|
+
},
|
|
6169
|
+
propsValues: {
|
|
6170
|
+
type: Object,
|
|
6171
|
+
default: () => ({})
|
|
6172
|
+
},
|
|
6173
|
+
eventMethodList: {
|
|
6174
|
+
type: Object,
|
|
6175
|
+
default: () => ({})
|
|
6176
|
+
},
|
|
6177
|
+
moveableOptions: {
|
|
6178
|
+
type: [Object, Function]
|
|
6179
|
+
},
|
|
6180
|
+
defaultSelected: {
|
|
6181
|
+
type: [Number, String]
|
|
6182
|
+
},
|
|
6183
|
+
canSelect: {
|
|
6184
|
+
type: Function,
|
|
6185
|
+
default: (el) => Boolean(el.id)
|
|
6186
|
+
},
|
|
6187
|
+
isContainer: {
|
|
6188
|
+
type: Function,
|
|
6189
|
+
default: (el) => el.classList.contains("magic-ui-container")
|
|
6190
|
+
},
|
|
6191
|
+
containerHighlightClassName: {
|
|
6192
|
+
type: String,
|
|
6193
|
+
default: CONTAINER_HIGHLIGHT_CLASS_NAME
|
|
6194
|
+
},
|
|
6195
|
+
containerHighlightDuration: {
|
|
6196
|
+
type: Number,
|
|
6197
|
+
default: 800
|
|
6198
|
+
},
|
|
6199
|
+
containerHighlightType: {
|
|
6200
|
+
type: String,
|
|
6201
|
+
default: ContainerHighlightType.DEFAULT
|
|
6202
|
+
},
|
|
6203
|
+
stageRect: {
|
|
6204
|
+
type: [String, Object]
|
|
6205
|
+
},
|
|
6206
|
+
codeOptions: {
|
|
6207
|
+
type: Object,
|
|
6208
|
+
default: () => ({})
|
|
6209
|
+
},
|
|
6210
|
+
updateDragEl: {
|
|
6211
|
+
type: Function
|
|
6212
|
+
},
|
|
6213
|
+
disabledDragStart: {
|
|
6214
|
+
type: Boolean
|
|
6215
|
+
}
|
|
6216
|
+
};
|
|
6217
|
+
|
|
6218
|
+
const createCodeBlockTarget = (id, codeBlock) => new Target({
|
|
6219
|
+
type: "code-block",
|
|
6220
|
+
id,
|
|
6221
|
+
name: codeBlock.name,
|
|
6222
|
+
isTarget: (key, value) => {
|
|
6223
|
+
if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
|
|
6224
|
+
const index = value.hookData.findIndex((item) => item.codeId === id);
|
|
6225
|
+
return Boolean(index > -1);
|
|
6226
|
+
}
|
|
6227
|
+
return false;
|
|
6228
|
+
}
|
|
6229
|
+
});
|
|
6230
|
+
|
|
6231
|
+
const initServiceState = (props, {
|
|
6232
|
+
editorService,
|
|
6233
|
+
historyService,
|
|
6234
|
+
componentListService,
|
|
6235
|
+
propsService,
|
|
6236
|
+
eventsService,
|
|
6237
|
+
uiService,
|
|
6238
|
+
codeBlockService
|
|
6239
|
+
}) => {
|
|
6240
|
+
watch(
|
|
6241
|
+
() => props.modelValue,
|
|
6242
|
+
(modelValue) => {
|
|
6243
|
+
editorService.set("root", modelValue);
|
|
6244
|
+
},
|
|
6245
|
+
{
|
|
6246
|
+
immediate: true
|
|
6247
|
+
}
|
|
6248
|
+
);
|
|
6249
|
+
watch(
|
|
6250
|
+
() => props.componentGroupList,
|
|
6251
|
+
(componentGroupList) => componentListService.setList(componentGroupList),
|
|
6252
|
+
{
|
|
6253
|
+
immediate: true
|
|
6254
|
+
}
|
|
6255
|
+
);
|
|
6256
|
+
watch(
|
|
6257
|
+
() => props.propsConfigs,
|
|
6258
|
+
(configs) => propsService.setPropsConfigs(configs),
|
|
6259
|
+
{
|
|
6260
|
+
immediate: true
|
|
6261
|
+
}
|
|
6262
|
+
);
|
|
6263
|
+
watch(
|
|
6264
|
+
() => props.propsValues,
|
|
6265
|
+
(values) => propsService.setPropsValues(values),
|
|
6266
|
+
{
|
|
6267
|
+
immediate: true
|
|
6268
|
+
}
|
|
6269
|
+
);
|
|
6270
|
+
watch(
|
|
6271
|
+
() => props.eventMethodList,
|
|
6272
|
+
(eventMethodList) => {
|
|
6273
|
+
const eventsList = {};
|
|
6274
|
+
const methodsList = {};
|
|
6275
|
+
Object.keys(eventMethodList).forEach((type) => {
|
|
6276
|
+
eventsList[type] = eventMethodList[type].events;
|
|
6277
|
+
methodsList[type] = eventMethodList[type].methods;
|
|
6278
|
+
});
|
|
6279
|
+
eventsService.setEvents(eventsList);
|
|
6280
|
+
eventsService.setMethods(methodsList);
|
|
6281
|
+
},
|
|
6282
|
+
{
|
|
6283
|
+
immediate: true
|
|
6284
|
+
}
|
|
6285
|
+
);
|
|
6286
|
+
watch(
|
|
6287
|
+
() => props.defaultSelected,
|
|
6288
|
+
(defaultSelected) => defaultSelected && editorService.select(defaultSelected),
|
|
6289
|
+
{
|
|
6290
|
+
immediate: true
|
|
6291
|
+
}
|
|
6292
|
+
);
|
|
6293
|
+
watch(
|
|
6294
|
+
() => props.stageRect,
|
|
6295
|
+
(stageRect) => stageRect && uiService.set("stageRect", stageRect),
|
|
6296
|
+
{
|
|
6297
|
+
immediate: true
|
|
6298
|
+
}
|
|
6299
|
+
);
|
|
6300
|
+
onUnmounted(() => {
|
|
6301
|
+
editorService.resetState();
|
|
6302
|
+
historyService.resetState();
|
|
6303
|
+
propsService.resetState();
|
|
6304
|
+
uiService.resetState();
|
|
6305
|
+
componentListService.resetState();
|
|
6306
|
+
codeBlockService.resetState();
|
|
6307
|
+
});
|
|
6308
|
+
};
|
|
6309
|
+
const initServiceEvents = (props, emit, { editorService, codeBlockService, depService }) => {
|
|
6310
|
+
const rootChangeHandler = async (value, preValue) => {
|
|
6311
|
+
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
6312
|
+
let node;
|
|
6313
|
+
if (nodeId) {
|
|
6314
|
+
node = editorService.getNodeById(nodeId);
|
|
6315
|
+
}
|
|
6316
|
+
if (node && node !== value) {
|
|
6317
|
+
await editorService.select(node.id);
|
|
6318
|
+
} else if (value?.items?.length) {
|
|
6319
|
+
await editorService.select(value.items[0]);
|
|
6320
|
+
} else if (value?.id) {
|
|
6321
|
+
editorService.set("nodes", [value]);
|
|
6322
|
+
editorService.set("parent", null);
|
|
6323
|
+
editorService.set("page", null);
|
|
6324
|
+
}
|
|
6325
|
+
if (toRaw(value) !== toRaw(preValue)) {
|
|
6326
|
+
emit("update:modelValue", value);
|
|
6327
|
+
}
|
|
6328
|
+
value.codeBlocks = value.codeBlocks || {};
|
|
6329
|
+
codeBlockService.setCodeDsl(value.codeBlocks);
|
|
6330
|
+
depService.removeTargets("code-block");
|
|
6331
|
+
Object.entries(value.codeBlocks).forEach(([id, code]) => {
|
|
6332
|
+
depService.addTarget(createCodeBlockTarget(id, code));
|
|
6333
|
+
});
|
|
6334
|
+
if (value && Array.isArray(value.items)) {
|
|
6335
|
+
depService.collect(value.items, true);
|
|
6336
|
+
} else {
|
|
6337
|
+
depService.clear();
|
|
6338
|
+
}
|
|
6339
|
+
};
|
|
6340
|
+
const nodeAddHandler = (nodes) => {
|
|
6341
|
+
depService.collect(nodes);
|
|
6342
|
+
};
|
|
6343
|
+
const nodeUpdateHandler = (nodes) => {
|
|
6344
|
+
depService.collect(nodes);
|
|
6345
|
+
};
|
|
6346
|
+
const nodeRemoveHandler = (nodes) => {
|
|
6347
|
+
depService.clear(nodes);
|
|
6348
|
+
};
|
|
6349
|
+
const historyChangeHandler = (page) => {
|
|
6350
|
+
depService.collect([page], true);
|
|
6351
|
+
};
|
|
6352
|
+
editorService.on("history-change", historyChangeHandler);
|
|
6353
|
+
editorService.on("root-change", rootChangeHandler);
|
|
6354
|
+
editorService.on("add", nodeAddHandler);
|
|
6355
|
+
editorService.on("remove", nodeRemoveHandler);
|
|
6356
|
+
editorService.on("update", nodeUpdateHandler);
|
|
6357
|
+
const codeBlockAddOrUpdateHandler = (id, codeBlock) => {
|
|
6358
|
+
if (depService.hasTarget(id)) {
|
|
6359
|
+
depService.getTarget(id).name = codeBlock.name;
|
|
6360
|
+
return;
|
|
6361
|
+
}
|
|
6362
|
+
depService.addTarget(createCodeBlockTarget(id, codeBlock));
|
|
6363
|
+
};
|
|
6364
|
+
const codeBlockRemoveHandler = (id) => {
|
|
6365
|
+
depService.removeTarget(id);
|
|
6366
|
+
};
|
|
6367
|
+
codeBlockService.on("addOrUpdate", codeBlockAddOrUpdateHandler);
|
|
6368
|
+
codeBlockService.on("remove", codeBlockRemoveHandler);
|
|
6369
|
+
onUnmounted(() => {
|
|
6370
|
+
editorService.off("history-change", historyChangeHandler);
|
|
6371
|
+
editorService.off("root-change", rootChangeHandler);
|
|
6372
|
+
editorService.off("add", nodeAddHandler);
|
|
6373
|
+
editorService.off("remove", nodeRemoveHandler);
|
|
6374
|
+
editorService.off("update", nodeUpdateHandler);
|
|
6375
|
+
codeBlockService.off("addOrUpdate", codeBlockAddOrUpdateHandler);
|
|
6376
|
+
codeBlockService.off("remove", codeBlockRemoveHandler);
|
|
6377
|
+
});
|
|
6378
|
+
};
|
|
5861
6379
|
|
|
5862
6380
|
const _sfc_main = defineComponent({
|
|
5863
6381
|
name: "m-editor",
|
|
@@ -5868,179 +6386,9 @@ const _sfc_main = defineComponent({
|
|
|
5868
6386
|
PropsPanel: _sfc_main$i,
|
|
5869
6387
|
Framework: _sfc_main$l
|
|
5870
6388
|
},
|
|
5871
|
-
props:
|
|
5872
|
-
modelValue: {
|
|
5873
|
-
type: Object,
|
|
5874
|
-
default: () => ({}),
|
|
5875
|
-
require: true
|
|
5876
|
-
},
|
|
5877
|
-
componentGroupList: {
|
|
5878
|
-
type: Array,
|
|
5879
|
-
default: () => []
|
|
5880
|
-
},
|
|
5881
|
-
sidebar: {
|
|
5882
|
-
type: Object
|
|
5883
|
-
},
|
|
5884
|
-
menu: {
|
|
5885
|
-
type: Object,
|
|
5886
|
-
default: () => ({ left: [], right: [] })
|
|
5887
|
-
},
|
|
5888
|
-
layerContentMenu: {
|
|
5889
|
-
type: Array,
|
|
5890
|
-
default: () => []
|
|
5891
|
-
},
|
|
5892
|
-
stageContentMenu: {
|
|
5893
|
-
type: Array,
|
|
5894
|
-
default: () => []
|
|
5895
|
-
},
|
|
5896
|
-
render: {
|
|
5897
|
-
type: Function
|
|
5898
|
-
},
|
|
5899
|
-
runtimeUrl: String,
|
|
5900
|
-
autoScrollIntoView: Boolean,
|
|
5901
|
-
propsConfigs: {
|
|
5902
|
-
type: Object,
|
|
5903
|
-
default: () => ({})
|
|
5904
|
-
},
|
|
5905
|
-
propsValues: {
|
|
5906
|
-
type: Object,
|
|
5907
|
-
default: () => ({})
|
|
5908
|
-
},
|
|
5909
|
-
eventMethodList: {
|
|
5910
|
-
type: Object,
|
|
5911
|
-
default: () => ({})
|
|
5912
|
-
},
|
|
5913
|
-
moveableOptions: {
|
|
5914
|
-
type: [Object, Function]
|
|
5915
|
-
},
|
|
5916
|
-
defaultSelected: {
|
|
5917
|
-
type: [Number, String]
|
|
5918
|
-
},
|
|
5919
|
-
canSelect: {
|
|
5920
|
-
type: Function,
|
|
5921
|
-
default: (el) => Boolean(el.id)
|
|
5922
|
-
},
|
|
5923
|
-
isContainer: {
|
|
5924
|
-
type: Function,
|
|
5925
|
-
default: (el) => el.classList.contains("magic-ui-container")
|
|
5926
|
-
},
|
|
5927
|
-
containerHighlightClassName: {
|
|
5928
|
-
type: String,
|
|
5929
|
-
default: CONTAINER_HIGHLIGHT_CLASS_NAME
|
|
5930
|
-
},
|
|
5931
|
-
containerHighlightDuration: {
|
|
5932
|
-
type: Number,
|
|
5933
|
-
default: 800
|
|
5934
|
-
},
|
|
5935
|
-
containerHighlightType: {
|
|
5936
|
-
type: String,
|
|
5937
|
-
default: ContainerHighlightType.DEFAULT
|
|
5938
|
-
},
|
|
5939
|
-
stageRect: {
|
|
5940
|
-
type: [String, Object]
|
|
5941
|
-
},
|
|
5942
|
-
codeOptions: {
|
|
5943
|
-
type: Object,
|
|
5944
|
-
default: () => ({})
|
|
5945
|
-
},
|
|
5946
|
-
updateDragEl: {
|
|
5947
|
-
type: Function
|
|
5948
|
-
},
|
|
5949
|
-
disabledDragStart: {
|
|
5950
|
-
type: Boolean
|
|
5951
|
-
}
|
|
5952
|
-
},
|
|
6389
|
+
props: editorProps,
|
|
5953
6390
|
emits: ["props-panel-mounted", "update:modelValue"],
|
|
5954
6391
|
setup(props, { emit }) {
|
|
5955
|
-
const rootChangeHandler = (value, preValue) => {
|
|
5956
|
-
const nodeId = editorService.get("node")?.id || props.defaultSelected;
|
|
5957
|
-
let node;
|
|
5958
|
-
if (nodeId) {
|
|
5959
|
-
node = editorService.getNodeById(nodeId);
|
|
5960
|
-
}
|
|
5961
|
-
if (node && node !== value) {
|
|
5962
|
-
editorService.select(node.id);
|
|
5963
|
-
} else if (value?.items?.length) {
|
|
5964
|
-
editorService.select(value.items[0]);
|
|
5965
|
-
} else if (value?.id) {
|
|
5966
|
-
editorService.set("nodes", [value]);
|
|
5967
|
-
editorService.set("parent", null);
|
|
5968
|
-
editorService.set("page", null);
|
|
5969
|
-
}
|
|
5970
|
-
if (toRaw(value) !== toRaw(preValue)) {
|
|
5971
|
-
emit("update:modelValue", value);
|
|
5972
|
-
}
|
|
5973
|
-
};
|
|
5974
|
-
editorService.on("root-change", rootChangeHandler);
|
|
5975
|
-
watch(
|
|
5976
|
-
() => props.modelValue,
|
|
5977
|
-
(modelValue) => {
|
|
5978
|
-
editorService.set("root", modelValue);
|
|
5979
|
-
},
|
|
5980
|
-
{
|
|
5981
|
-
immediate: true
|
|
5982
|
-
}
|
|
5983
|
-
);
|
|
5984
|
-
watch(
|
|
5985
|
-
() => props.componentGroupList,
|
|
5986
|
-
(componentGroupList) => componentListService.setList(componentGroupList),
|
|
5987
|
-
{
|
|
5988
|
-
immediate: true
|
|
5989
|
-
}
|
|
5990
|
-
);
|
|
5991
|
-
watch(
|
|
5992
|
-
() => props.propsConfigs,
|
|
5993
|
-
(configs) => propsService.setPropsConfigs(configs),
|
|
5994
|
-
{
|
|
5995
|
-
immediate: true
|
|
5996
|
-
}
|
|
5997
|
-
);
|
|
5998
|
-
watch(
|
|
5999
|
-
() => props.propsValues,
|
|
6000
|
-
(values) => propsService.setPropsValues(values),
|
|
6001
|
-
{
|
|
6002
|
-
immediate: true
|
|
6003
|
-
}
|
|
6004
|
-
);
|
|
6005
|
-
watch(
|
|
6006
|
-
() => props.eventMethodList,
|
|
6007
|
-
(eventMethodList) => {
|
|
6008
|
-
const eventsList = {};
|
|
6009
|
-
const methodsList = {};
|
|
6010
|
-
Object.keys(eventMethodList).forEach((type) => {
|
|
6011
|
-
eventsList[type] = eventMethodList[type].events;
|
|
6012
|
-
methodsList[type] = eventMethodList[type].methods;
|
|
6013
|
-
});
|
|
6014
|
-
eventsService.setEvents(eventsList);
|
|
6015
|
-
eventsService.setMethods(methodsList);
|
|
6016
|
-
},
|
|
6017
|
-
{
|
|
6018
|
-
immediate: true
|
|
6019
|
-
}
|
|
6020
|
-
);
|
|
6021
|
-
watch(
|
|
6022
|
-
() => props.defaultSelected,
|
|
6023
|
-
(defaultSelected) => defaultSelected && editorService.select(defaultSelected),
|
|
6024
|
-
{
|
|
6025
|
-
immediate: true
|
|
6026
|
-
}
|
|
6027
|
-
);
|
|
6028
|
-
watch(
|
|
6029
|
-
() => props.stageRect,
|
|
6030
|
-
(stageRect) => stageRect && uiService.set("stageRect", stageRect),
|
|
6031
|
-
{
|
|
6032
|
-
immediate: true
|
|
6033
|
-
}
|
|
6034
|
-
);
|
|
6035
|
-
onUnmounted(() => {
|
|
6036
|
-
editorService.resetState();
|
|
6037
|
-
historyService.resetState();
|
|
6038
|
-
propsService.resetState();
|
|
6039
|
-
uiService.resetState();
|
|
6040
|
-
componentListService.resetState();
|
|
6041
|
-
codeBlockService.resetState();
|
|
6042
|
-
editorService.off("root-change", rootChangeHandler);
|
|
6043
|
-
});
|
|
6044
6392
|
const services = {
|
|
6045
6393
|
componentListService,
|
|
6046
6394
|
eventsService,
|
|
@@ -6049,8 +6397,11 @@ const _sfc_main = defineComponent({
|
|
|
6049
6397
|
editorService,
|
|
6050
6398
|
uiService,
|
|
6051
6399
|
storageService,
|
|
6052
|
-
codeBlockService
|
|
6400
|
+
codeBlockService,
|
|
6401
|
+
depService
|
|
6053
6402
|
};
|
|
6403
|
+
initServiceEvents(props, emit, services);
|
|
6404
|
+
initServiceState(props, services);
|
|
6054
6405
|
provide("services", services);
|
|
6055
6406
|
provide("codeOptions", props.codeOptions);
|
|
6056
6407
|
provide(
|
|
@@ -6069,7 +6420,6 @@ const _sfc_main = defineComponent({
|
|
|
6069
6420
|
disabledDragStart: props.disabledDragStart
|
|
6070
6421
|
})
|
|
6071
6422
|
);
|
|
6072
|
-
codeBlockService.addCodeRelationListener();
|
|
6073
6423
|
return services;
|
|
6074
6424
|
}
|
|
6075
6425
|
});
|
|
@@ -6180,12 +6530,14 @@ const index = {
|
|
|
6180
6530
|
setConfig(option);
|
|
6181
6531
|
app.component(Editor.name, Editor);
|
|
6182
6532
|
app.component("m-fields-ui-select", _sfc_main$q);
|
|
6183
|
-
app.component("m-fields-code-link", _sfc_main$
|
|
6184
|
-
app.component("m-fields-vs-code", _sfc_main$
|
|
6533
|
+
app.component("m-fields-code-link", _sfc_main$v);
|
|
6534
|
+
app.component("m-fields-vs-code", _sfc_main$w);
|
|
6185
6535
|
app.component("magic-code-editor", _sfc_main$p);
|
|
6186
|
-
app.component("m-fields-code-select", _sfc_main$
|
|
6536
|
+
app.component("m-fields-code-select", _sfc_main$t);
|
|
6537
|
+
app.component("m-fields-code-select-col", _sfc_main$s);
|
|
6538
|
+
app.component("m-fields-event-select", _sfc_main$r);
|
|
6187
6539
|
}
|
|
6188
6540
|
};
|
|
6189
6541
|
|
|
6190
|
-
export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, _sfc_main$
|
|
6542
|
+
export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$e as CodeBlockList, CodeDeleteErrorType, _sfc_main$t as CodeSelect, _sfc_main$s as CodeSelectCol, ColumnLayout, _sfc_main$d as ComponentListPanel, _sfc_main$c as ContentMenu, _sfc_main$r as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$u as Icon, Keys, LayerOffset, _sfc_main$a as LayerPanel, Layout, _sfc_main$n as LayoutContainer, _sfc_main$i as PropsPanel, _sfc_main$p as TMagicCodeEditor, Editor as TMagicEditor, _sfc_main$k as ToolButton, V_GUIDE_LINE_STORAGE_KEY, beforePaste, change2Fixed, codeBlockService, debug, index as default, depService, editorService, error, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setConfig, setLayout, storageService, uiService, useStage, warn };
|
|
6191
6543
|
//# sourceMappingURL=tmagic-editor.js.map
|