@tmagic/editor 1.0.0-beta.1

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.
Files changed (98) hide show
  1. package/dist/style.css +505 -0
  2. package/dist/tmagic-editor.es.js +4233 -0
  3. package/dist/tmagic-editor.es.js.map +1 -0
  4. package/dist/tmagic-editor.umd.js +4276 -0
  5. package/dist/tmagic-editor.umd.js.map +1 -0
  6. package/dist/types/src/Editor.vue.d.ts +136 -0
  7. package/dist/types/src/components/Icon.vue.d.ts +13 -0
  8. package/dist/types/src/components/ToolButton.vue.d.ts +35 -0
  9. package/dist/types/src/fields/Code.vue.d.ts +24 -0
  10. package/dist/types/src/fields/CodeLink.vue.d.ts +54 -0
  11. package/dist/types/src/fields/UISelect.vue.d.ts +32 -0
  12. package/dist/types/src/index.d.ts +19 -0
  13. package/dist/types/src/layouts/AddPageBox.vue.d.ts +5 -0
  14. package/dist/types/src/layouts/CodeEditor.vue.d.ts +46 -0
  15. package/dist/types/src/layouts/Framework.vue.d.ts +11 -0
  16. package/dist/types/src/layouts/NavMenu.vue.d.ts +24 -0
  17. package/dist/types/src/layouts/PropsPanel.vue.d.ts +13 -0
  18. package/dist/types/src/layouts/Resizer.vue.d.ts +13 -0
  19. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +12 -0
  20. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +31 -0
  21. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +973 -0
  22. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +27 -0
  23. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +11 -0
  24. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +153 -0
  25. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +18 -0
  26. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +37 -0
  27. package/dist/types/src/services/BaseService.d.ts +56 -0
  28. package/dist/types/src/services/editor.d.ts +122 -0
  29. package/dist/types/src/services/events.d.ts +16 -0
  30. package/dist/types/src/services/history.d.ts +51 -0
  31. package/dist/types/src/services/props.d.ts +36 -0
  32. package/dist/types/src/services/ui.d.ts +26 -0
  33. package/dist/types/src/shims-vue.d.ts +6 -0
  34. package/dist/types/src/type.d.ts +183 -0
  35. package/dist/types/src/utils/compose.d.ts +5 -0
  36. package/dist/types/src/utils/config.d.ts +4 -0
  37. package/dist/types/src/utils/editor.d.ts +45 -0
  38. package/dist/types/src/utils/index.d.ts +4 -0
  39. package/dist/types/src/utils/logger.d.ts +5 -0
  40. package/dist/types/src/utils/props.d.ts +49 -0
  41. package/dist/types/src/utils/undo-redo.d.ts +12 -0
  42. package/dist/types/src/vite-env.d.ts +1 -0
  43. package/package.json +57 -0
  44. package/src/Editor.vue +234 -0
  45. package/src/components/Icon.vue +29 -0
  46. package/src/components/ToolButton.vue +188 -0
  47. package/src/fields/Code.vue +35 -0
  48. package/src/fields/CodeLink.vue +81 -0
  49. package/src/fields/UISelect.vue +100 -0
  50. package/src/index.ts +63 -0
  51. package/src/layouts/AddPageBox.vue +41 -0
  52. package/src/layouts/CodeEditor.vue +188 -0
  53. package/src/layouts/Framework.vue +73 -0
  54. package/src/layouts/NavMenu.vue +37 -0
  55. package/src/layouts/PropsPanel.vue +81 -0
  56. package/src/layouts/Resizer.vue +61 -0
  57. package/src/layouts/sidebar/ComponentListPanel.vue +69 -0
  58. package/src/layouts/sidebar/LayerMenu.vue +117 -0
  59. package/src/layouts/sidebar/LayerPanel.vue +209 -0
  60. package/src/layouts/sidebar/Sidebar.vue +86 -0
  61. package/src/layouts/workspace/PageBar.vue +83 -0
  62. package/src/layouts/workspace/Stage.vue +221 -0
  63. package/src/layouts/workspace/ViewerMenu.vue +110 -0
  64. package/src/layouts/workspace/Workspace.vue +98 -0
  65. package/src/services/BaseService.ts +138 -0
  66. package/src/services/componentList.ts +48 -0
  67. package/src/services/editor.ts +521 -0
  68. package/src/services/events.ts +82 -0
  69. package/src/services/history.ts +124 -0
  70. package/src/services/props.ts +110 -0
  71. package/src/services/ui.ts +101 -0
  72. package/src/shims-vue.d.ts +6 -0
  73. package/src/theme/code-editor.scss +7 -0
  74. package/src/theme/common/var.scss +13 -0
  75. package/src/theme/component-list-panel.scss +102 -0
  76. package/src/theme/content-menu.scss +39 -0
  77. package/src/theme/framework.scss +72 -0
  78. package/src/theme/index.scss +13 -0
  79. package/src/theme/layer-panel.scss +68 -0
  80. package/src/theme/nav-menu.scss +69 -0
  81. package/src/theme/page-bar.scss +31 -0
  82. package/src/theme/props-panel.scss +17 -0
  83. package/src/theme/resizer.scss +51 -0
  84. package/src/theme/ruler.scss +38 -0
  85. package/src/theme/sidebar.scss +97 -0
  86. package/src/theme/stage.scss +22 -0
  87. package/src/theme/workspace.scss +5 -0
  88. package/src/type.ts +236 -0
  89. package/src/utils/compose.ts +33 -0
  90. package/src/utils/config.ts +29 -0
  91. package/src/utils/editor.ts +244 -0
  92. package/src/utils/index.ts +22 -0
  93. package/src/utils/logger.ts +47 -0
  94. package/src/utils/props.ts +218 -0
  95. package/src/utils/undo-redo.ts +76 -0
  96. package/src/vite-env.d.ts +1 -0
  97. package/tsconfig.json +9 -0
  98. package/vite.config.ts +30 -0
@@ -0,0 +1,4233 @@
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, createElementBlock, createElementVNode, toDisplayString, withModifiers, createCommentVNode, watch, onMounted, onUnmounted, reactive, toRaw, createVNode, withCtx, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, createTextVNode, normalizeProps, mergeProps, getCurrentInstance, withDirectives, vShow, Teleport, toHandlers, createSlots, nextTick, provide } from 'vue';
2
+ import serialize from 'serialize-javascript';
3
+ import { asyncLoadJs, toLine, isPop, getNodePath } from '@tmagic/utils';
4
+ import { Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Delete, Files, Coin, CaretBottom } from '@element-plus/icons';
5
+ import { cloneDeep, random } from 'lodash-es';
6
+ import { EventEmitter as EventEmitter$2 } from 'events';
7
+ import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
8
+ import { ElMessage } from 'element-plus';
9
+ import StageCore from '@tmagic/stage';
10
+
11
+ var _export_sfc = (sfc, props) => {
12
+ const target = sfc.__vccOpts || sfc;
13
+ for (const [key, val] of props) {
14
+ target[key] = val;
15
+ }
16
+ return target;
17
+ };
18
+
19
+ const _sfc_main$j = defineComponent({
20
+ name: "m-fields-vs-code",
21
+ props: ["model", "name", "config", "prop"],
22
+ emits: ["change"],
23
+ setup(props, { emit }) {
24
+ const language = computed(() => props.config.language || "javascript");
25
+ const height = computed(() => `${document.body.clientHeight - 168}px`);
26
+ return {
27
+ height,
28
+ language,
29
+ save(v) {
30
+ props.model[props.name] = v;
31
+ emit("change", v);
32
+ }
33
+ };
34
+ }
35
+ });
36
+ function _sfc_render$j(_ctx, _cache, $props, $setup, $data, $options) {
37
+ const _component_magic_code_editor = resolveComponent("magic-code-editor");
38
+ return openBlock(), createBlock(_component_magic_code_editor, {
39
+ style: normalizeStyle(`height: ${_ctx.height}`),
40
+ "init-values": _ctx.model[_ctx.name],
41
+ language: _ctx.language,
42
+ onSave: _ctx.save
43
+ }, null, 8, ["style", "init-values", "language", "onSave"]);
44
+ }
45
+ var Code = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["render", _sfc_render$j]]);
46
+
47
+ const _sfc_main$i = defineComponent({
48
+ name: "m-fields-code-link",
49
+ props: {
50
+ config: {
51
+ type: Object
52
+ },
53
+ model: {
54
+ type: Object
55
+ },
56
+ name: {
57
+ type: String
58
+ },
59
+ prop: {
60
+ type: String
61
+ }
62
+ },
63
+ emits: ["change"],
64
+ setup(props, { emit }) {
65
+ const modelValue = ref({
66
+ form: {}
67
+ });
68
+ watchEffect(() => {
69
+ if (!props.model || !props.name)
70
+ return;
71
+ modelValue.value.form[props.name] = serialize(props.model[props.name], {
72
+ space: 2,
73
+ unsafe: true
74
+ }).replace(/"(\w+)":\s/g, "$1: ");
75
+ });
76
+ return {
77
+ modelValue,
78
+ formConfig: computed(() => ({
79
+ ...props.config,
80
+ text: "",
81
+ type: "link",
82
+ form: [
83
+ {
84
+ name: props.name,
85
+ type: "vs-code"
86
+ }
87
+ ]
88
+ })),
89
+ changeHandler(v) {
90
+ if (!props.name || !props.model)
91
+ return;
92
+ try {
93
+ props.model[props.name] = eval(`${v[props.name]}`);
94
+ emit("change", props.model[props.name]);
95
+ } catch (e) {
96
+ console.error(e);
97
+ }
98
+ }
99
+ };
100
+ }
101
+ });
102
+ function _sfc_render$i(_ctx, _cache, $props, $setup, $data, $options) {
103
+ const _component_m_fields_link = resolveComponent("m-fields-link");
104
+ return openBlock(), createBlock(_component_m_fields_link, {
105
+ config: _ctx.formConfig,
106
+ model: _ctx.modelValue,
107
+ name: "form",
108
+ onChange: _ctx.changeHandler
109
+ }, null, 8, ["config", "model", "onChange"]);
110
+ }
111
+ var CodeLink = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["render", _sfc_render$i]]);
112
+
113
+ var UISelect_vue_vue_type_style_index_0_lang = '';
114
+
115
+ const _sfc_main$h = defineComponent({
116
+ name: "m-fields-ui-select",
117
+ props: {
118
+ labelWidth: String,
119
+ config: Object,
120
+ model: Object,
121
+ prop: {
122
+ type: String,
123
+ default() {
124
+ return "";
125
+ }
126
+ },
127
+ name: String
128
+ },
129
+ emits: ["change"],
130
+ setup(props, { emit }) {
131
+ const services = inject("services");
132
+ const mForm = inject("mForm");
133
+ const val = computed(() => props.model[props.name]);
134
+ const uiSelectMode = ref(false);
135
+ const cancelHandler = () => {
136
+ if (!services?.uiService)
137
+ return;
138
+ services.uiService.set("uiSelectMode", false);
139
+ uiSelectMode.value = false;
140
+ globalThis.document.removeEventListener("ui-select", clickHandler);
141
+ };
142
+ const clickHandler = ({ detail }) => {
143
+ if (detail.id) {
144
+ props.model[props.name] = detail.id;
145
+ emit("change", detail.id);
146
+ mForm?.$emit("field-change", props.prop, detail.id);
147
+ }
148
+ if (cancelHandler) {
149
+ cancelHandler();
150
+ }
151
+ };
152
+ return {
153
+ val,
154
+ uiSelectMode,
155
+ toName: computed(() => {
156
+ const config = services?.editorService.getNodeById(val.value);
157
+ return config?.name || "";
158
+ }),
159
+ startSelect() {
160
+ if (!services?.uiService)
161
+ return;
162
+ services.uiService.set("uiSelectMode", true);
163
+ uiSelectMode.value = true;
164
+ globalThis.document.addEventListener("ui-select", clickHandler);
165
+ },
166
+ cancelHandler,
167
+ deleteHandler() {
168
+ if (props.model) {
169
+ props.model[props.name] = "";
170
+ emit("change", "");
171
+ mForm?.$emit("field-change", props.prop, "");
172
+ }
173
+ }
174
+ };
175
+ }
176
+ });
177
+ const _hoisted_1$d = /* @__PURE__ */ createElementVNode("i", {
178
+ class: "el-icon-delete",
179
+ style: { "color": "rgb(221, 75, 57)" }
180
+ }, "\u53D6\u6D88", -1);
181
+ const _hoisted_2$7 = [
182
+ _hoisted_1$d
183
+ ];
184
+ const _hoisted_3$5 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-thumb" }, null, -1);
185
+ function _sfc_render$h(_ctx, _cache, $props, $setup, $data, $options) {
186
+ return _ctx.uiSelectMode ? (openBlock(), createElementBlock("div", {
187
+ key: 0,
188
+ class: "m-fields-ui-select",
189
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.cancelHandler && _ctx.cancelHandler(...args))
190
+ }, _hoisted_2$7)) : (openBlock(), createElementBlock("div", {
191
+ key: 1,
192
+ class: "m-fields-ui-select",
193
+ onClick: _cache[2] || (_cache[2] = (...args) => _ctx.startSelect && _ctx.startSelect(...args))
194
+ }, [
195
+ _hoisted_3$5,
196
+ createElementVNode("span", null, toDisplayString(_ctx.val ? _ctx.toName + "_" + _ctx.val : "\u70B9\u51FB\u6B64\u5904\u9009\u62E9"), 1),
197
+ _ctx.val ? (openBlock(), createElementBlock("i", {
198
+ key: 0,
199
+ class: "el-icon-delete",
200
+ onClick: _cache[1] || (_cache[1] = withModifiers((...args) => _ctx.deleteHandler && _ctx.deleteHandler(...args), ["stop"]))
201
+ })) : createCommentVNode("", true)
202
+ ]));
203
+ }
204
+ var uiSelect = /* @__PURE__ */ _export_sfc(_sfc_main$h, [["render", _sfc_render$h]]);
205
+
206
+ const initEditor = () => {
207
+ if (globalThis.monaco) {
208
+ Promise.resolve(globalThis.monaco);
209
+ }
210
+ return asyncLoadJs(`https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs/loader.min.js`).then(() => {
211
+ globalThis.require.config({
212
+ paths: { vs: `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs` }
213
+ });
214
+ return new Promise((resolve) => {
215
+ globalThis.require(["vs/editor/editor.main"], () => {
216
+ resolve(globalThis.monaco);
217
+ });
218
+ });
219
+ });
220
+ };
221
+ const toString = (v, language) => {
222
+ let value = "";
223
+ if (typeof v !== "string") {
224
+ value = serialize(v, {
225
+ space: 2,
226
+ unsafe: true
227
+ }).replace(/"(\w+)":\s/g, "$1: ");
228
+ } else {
229
+ value = v;
230
+ }
231
+ if (language === "javascript" && value.startsWith("{") && value.endsWith("}")) {
232
+ value = `(${value})`;
233
+ }
234
+ return value;
235
+ };
236
+ const _sfc_main$g = defineComponent({
237
+ name: "magic-code-editor",
238
+ props: {
239
+ initValues: {
240
+ type: [String, Object]
241
+ },
242
+ modifiedValues: {
243
+ type: [String, Object]
244
+ },
245
+ type: {
246
+ type: [String],
247
+ default: () => ""
248
+ },
249
+ language: {
250
+ type: [String],
251
+ default: () => "javascript"
252
+ }
253
+ },
254
+ emits: ["inited", "save"],
255
+ setup(props, { emit }) {
256
+ let vsEditor = null;
257
+ const values = ref("");
258
+ const loading = ref(false);
259
+ const codeEditor = ref();
260
+ const setEditorValue = (v, m) => {
261
+ values.value = toString(v, props.language);
262
+ if (props.type === "diff") {
263
+ const originalModel = globalThis.monaco.editor.createModel(values.value, "text/javascript");
264
+ const modifiedModel = globalThis.monaco.editor.createModel(toString(m, props.language), "text/javascript");
265
+ return vsEditor.setModel({
266
+ original: originalModel,
267
+ modified: modifiedModel
268
+ });
269
+ }
270
+ return vsEditor.setValue?.(values.value);
271
+ };
272
+ const resizeHandler = () => {
273
+ vsEditor?.layout();
274
+ };
275
+ const getEditorValue = () => vsEditor.getValue?.() || "";
276
+ const init = async () => {
277
+ if (!codeEditor.value)
278
+ return;
279
+ vsEditor = globalThis.monaco.editor[props.type === "diff" ? "createDiffEditor" : "create"](codeEditor.value, {
280
+ value: values.value,
281
+ language: props.language,
282
+ tabSize: 2,
283
+ theme: "vs-dark",
284
+ fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
285
+ fontSize: 15,
286
+ formatOnPaste: true
287
+ });
288
+ setEditorValue(props.initValues, props.modifiedValues);
289
+ loading.value = false;
290
+ emit("inited", vsEditor);
291
+ codeEditor.value.addEventListener("keydown", (e) => {
292
+ if (e.keyCode === 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
293
+ e.preventDefault();
294
+ emit("save", getEditorValue());
295
+ }
296
+ });
297
+ if (props.type !== "diff") {
298
+ vsEditor.onDidBlurEditorWidget(() => {
299
+ emit("save", getEditorValue());
300
+ });
301
+ }
302
+ globalThis.addEventListener("resize", resizeHandler);
303
+ };
304
+ watch(() => props.initValues, (v, preV) => {
305
+ if (vsEditor && v !== preV) {
306
+ setEditorValue(props.initValues, props.modifiedValues);
307
+ }
308
+ }, {
309
+ deep: true,
310
+ immediate: true
311
+ });
312
+ onMounted(async () => {
313
+ loading.value = true;
314
+ await initEditor();
315
+ if (!globalThis.monaco) {
316
+ const interval = setInterval(() => {
317
+ if (globalThis.monaco) {
318
+ clearInterval(interval);
319
+ init();
320
+ }
321
+ }, 300);
322
+ } else {
323
+ init();
324
+ }
325
+ });
326
+ onUnmounted(() => {
327
+ globalThis.removeEventListener("resize", resizeHandler);
328
+ });
329
+ return {
330
+ values,
331
+ loading,
332
+ codeEditor,
333
+ getEditor() {
334
+ return vsEditor;
335
+ },
336
+ setEditorValue,
337
+ focus() {
338
+ vsEditor.focus();
339
+ }
340
+ };
341
+ }
342
+ });
343
+ const _hoisted_1$c = {
344
+ ref: "codeEditor",
345
+ class: "magic-code-editor"
346
+ };
347
+ function _sfc_render$g(_ctx, _cache, $props, $setup, $data, $options) {
348
+ return openBlock(), createElementBlock("div", _hoisted_1$c, null, 512);
349
+ }
350
+ var CodeEditor = /* @__PURE__ */ _export_sfc(_sfc_main$g, [["render", _sfc_render$g]]);
351
+
352
+ let $TMAGIC_EDITOR = {};
353
+ const setConfig = (option) => {
354
+ $TMAGIC_EDITOR = option;
355
+ };
356
+ const getConfig = (key) => $TMAGIC_EDITOR[key];
357
+
358
+ class UndoRedo {
359
+ elementList;
360
+ listCursor;
361
+ listMaxSize;
362
+ constructor(listMaxSize = 200) {
363
+ const minListMaxSize = 2;
364
+ this.elementList = [];
365
+ this.listCursor = 0;
366
+ this.listMaxSize = listMaxSize > minListMaxSize ? listMaxSize : minListMaxSize;
367
+ }
368
+ pushElement(element) {
369
+ this.elementList.splice(this.listCursor, this.elementList.length - this.listCursor, cloneDeep(element));
370
+ this.listCursor += 1;
371
+ if (this.elementList.length > this.listMaxSize) {
372
+ this.elementList.shift();
373
+ this.listCursor -= 1;
374
+ }
375
+ }
376
+ canUndo() {
377
+ return this.listCursor > 1;
378
+ }
379
+ undo() {
380
+ if (!this.canUndo()) {
381
+ return null;
382
+ }
383
+ this.listCursor -= 1;
384
+ return this.getCurrentElement();
385
+ }
386
+ canRedo() {
387
+ return this.elementList.length > this.listCursor;
388
+ }
389
+ redo() {
390
+ if (!this.canRedo()) {
391
+ return null;
392
+ }
393
+ this.listCursor += 1;
394
+ return this.getCurrentElement();
395
+ }
396
+ getCurrentElement() {
397
+ if (this.listCursor < 1) {
398
+ return null;
399
+ }
400
+ return cloneDeep(this.elementList[this.listCursor - 1]);
401
+ }
402
+ }
403
+
404
+ const compose = (middleware) => {
405
+ if (!Array.isArray(middleware))
406
+ throw new TypeError("Middleware \u5FC5\u987B\u662F\u4E00\u4E2A\u6570\u7EC4!");
407
+ for (const fn of middleware) {
408
+ if (typeof fn !== "function")
409
+ throw new TypeError("Middleware \u5FC5\u987B\u7531\u51FD\u6570\u7EC4\u6210!");
410
+ }
411
+ return (args, next) => {
412
+ let index = -1;
413
+ return dispatch(0);
414
+ function dispatch(i) {
415
+ if (i <= index)
416
+ return Promise.reject(new Error("next() \u88AB\u591A\u6B21\u8C03\u7528"));
417
+ index = i;
418
+ let fn = middleware[i];
419
+ if (i === middleware.length && next)
420
+ fn = next;
421
+ if (!fn)
422
+ return Promise.resolve();
423
+ try {
424
+ return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
425
+ } catch (err) {
426
+ return Promise.reject(err);
427
+ }
428
+ }
429
+ };
430
+ };
431
+
432
+ const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
433
+ const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
434
+ class BaseService extends EventEmitter$2 {
435
+ pluginOptionsList = {};
436
+ middleware = {};
437
+ constructor(methods) {
438
+ super();
439
+ methods.forEach((propertyName) => {
440
+ const scope = this;
441
+ const sourceMethod = scope[propertyName];
442
+ const beforeMethodName = methodName("before", propertyName);
443
+ const afterMethodName = methodName("after", propertyName);
444
+ this.pluginOptionsList[beforeMethodName] = [];
445
+ this.pluginOptionsList[afterMethodName] = [];
446
+ this.middleware[propertyName] = [];
447
+ const fn = compose(this.middleware[propertyName]);
448
+ Object.defineProperty(scope, propertyName, {
449
+ value: async (...args) => {
450
+ let beforeArgs = args;
451
+ for (const beforeMethod of this.pluginOptionsList[beforeMethodName]) {
452
+ let beforeReturnValue = await beforeMethod(...beforeArgs) || [];
453
+ if (isError(beforeReturnValue))
454
+ throw beforeReturnValue;
455
+ if (!Array.isArray(beforeReturnValue)) {
456
+ beforeReturnValue = [beforeReturnValue];
457
+ }
458
+ beforeArgs = beforeArgs.map((v, index) => {
459
+ if (typeof beforeReturnValue[index] === "undefined")
460
+ return v;
461
+ return beforeReturnValue[index];
462
+ });
463
+ }
464
+ let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
465
+ for (const afterMethod of this.pluginOptionsList[afterMethodName]) {
466
+ returnValue = await afterMethod(...beforeArgs, returnValue);
467
+ if (isError(returnValue))
468
+ throw returnValue;
469
+ }
470
+ return returnValue;
471
+ }
472
+ });
473
+ });
474
+ }
475
+ use(options) {
476
+ Object.entries(options).forEach(([methodName2, method]) => {
477
+ if (typeof method === "function")
478
+ this.middleware[methodName2].push(method);
479
+ });
480
+ }
481
+ usePlugin(options) {
482
+ Object.entries(options).forEach(([methodName2, method]) => {
483
+ if (typeof method === "function")
484
+ this.pluginOptionsList[methodName2].push(method);
485
+ });
486
+ }
487
+ }
488
+
489
+ class History extends BaseService {
490
+ state = reactive({
491
+ pageSteps: {},
492
+ pageId: void 0,
493
+ canRedo: false,
494
+ canUndo: false
495
+ });
496
+ constructor() {
497
+ super([]);
498
+ this.on("change", this.setCanUndoRedo);
499
+ }
500
+ changePage(page) {
501
+ if (!page)
502
+ return;
503
+ this.state.pageId = page.id;
504
+ if (!this.state.pageSteps[this.state.pageId]) {
505
+ const undoRedo = new UndoRedo();
506
+ undoRedo.pushElement({
507
+ data: page,
508
+ modifiedNodeIds: /* @__PURE__ */ new Map(),
509
+ nodeId: page.id
510
+ });
511
+ this.state.pageSteps[this.state.pageId] = undoRedo;
512
+ }
513
+ this.setCanUndoRedo();
514
+ }
515
+ empty() {
516
+ this.state.pageId = void 0;
517
+ this.state.pageSteps = {};
518
+ this.state.canRedo = false;
519
+ this.state.canUndo = false;
520
+ }
521
+ push(state) {
522
+ const undoRedo = this.getUndoRedo();
523
+ if (!undoRedo)
524
+ return null;
525
+ undoRedo.pushElement(state);
526
+ this.emit("change", state);
527
+ return state;
528
+ }
529
+ undo() {
530
+ const undoRedo = this.getUndoRedo();
531
+ if (!undoRedo)
532
+ return null;
533
+ const state = undoRedo.undo();
534
+ this.emit("change", state);
535
+ return state;
536
+ }
537
+ redo() {
538
+ const undoRedo = this.getUndoRedo();
539
+ if (!undoRedo)
540
+ return null;
541
+ const state = undoRedo.redo();
542
+ this.emit("change", state);
543
+ return state;
544
+ }
545
+ destroy() {
546
+ this.empty();
547
+ this.removeAllListeners();
548
+ }
549
+ getUndoRedo() {
550
+ if (!this.state.pageId)
551
+ return null;
552
+ return this.state.pageSteps[this.state.pageId];
553
+ }
554
+ setCanUndoRedo() {
555
+ const undoRedo = this.getUndoRedo();
556
+ this.state.canRedo = undoRedo?.canRedo() || false;
557
+ this.state.canUndo = undoRedo?.canUndo() || false;
558
+ }
559
+ }
560
+ var historyService = new History();
561
+
562
+ class Props extends BaseService {
563
+ state = reactive({
564
+ propsConfigMap: {},
565
+ propsValueMap: {}
566
+ });
567
+ constructor() {
568
+ super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
569
+ }
570
+ setPropsConfigs(configs) {
571
+ Object.keys(configs).forEach((type) => {
572
+ this.setPropsConfig(toLine(type), configs[type]);
573
+ });
574
+ this.emit("props-configs-change");
575
+ }
576
+ setPropsConfig(type, config) {
577
+ this.state.propsConfigMap[type] = fillConfig(Array.isArray(config) ? config : [config]);
578
+ }
579
+ async getPropsConfig(type) {
580
+ if (type === "area") {
581
+ return await this.getPropsConfig("button");
582
+ }
583
+ return cloneDeep(this.state.propsConfigMap[type] || DEFAULT_CONFIG);
584
+ }
585
+ setPropsValues(values) {
586
+ Object.keys(values).forEach((type) => {
587
+ this.setPropsValue(toLine(type), values[type]);
588
+ });
589
+ }
590
+ setPropsValue(type, value) {
591
+ this.state.propsValueMap[type] = value;
592
+ }
593
+ async getPropsValue(type) {
594
+ if (type === "area") {
595
+ const value = await this.getPropsValue("button");
596
+ value.className = "action-area";
597
+ value.text = "";
598
+ if (value.style) {
599
+ value.style.backgroundColor = "rgba(255, 255, 255, 0)";
600
+ }
601
+ return value;
602
+ }
603
+ return cloneDeep({
604
+ ...getDefaultPropsValue(type),
605
+ ...this.state.propsValueMap[type] || {}
606
+ });
607
+ }
608
+ }
609
+ var propsService = new Props();
610
+
611
+ var LayerOffset = /* @__PURE__ */ ((LayerOffset2) => {
612
+ LayerOffset2["TOP"] = "top";
613
+ LayerOffset2["BOTTOM"] = "bottom";
614
+ return LayerOffset2;
615
+ })(LayerOffset || {});
616
+ var Layout = /* @__PURE__ */ ((Layout2) => {
617
+ Layout2["FLEX"] = "flex";
618
+ Layout2["FIXED"] = "fixed";
619
+ Layout2["RELATIVE"] = "relative";
620
+ Layout2["ABSOLUTE"] = "absolute";
621
+ return Layout2;
622
+ })(Layout || {});
623
+
624
+ const COPY_STORAGE_KEY = "$MagicEditorCopyData";
625
+ const generateId = (type) => `${type}_${random(1e4, false)}`;
626
+ const getPageList = (app) => {
627
+ if (app.items && Array.isArray(app.items)) {
628
+ return app.items.filter((item) => item.type === "page");
629
+ }
630
+ return [];
631
+ };
632
+ const getPageNameList = (pages) => pages.map((page) => page.name || "index");
633
+ const generatePageName = (pageNameList) => {
634
+ let pageLength = pageNameList.length;
635
+ if (!pageLength)
636
+ return "index";
637
+ let pageName = `page_${pageLength}`;
638
+ while (pageNameList.includes(pageName)) {
639
+ pageLength += 1;
640
+ pageName = `page_${pageLength}`;
641
+ }
642
+ return pageName;
643
+ };
644
+ const generatePageNameByApp = (app) => generatePageName(getPageNameList(getPageList(app)));
645
+ const updatePopId = (oldId, popId, pageConfig) => {
646
+ pageConfig.items?.forEach((config) => {
647
+ if (config.pop === oldId) {
648
+ config.pop = popId;
649
+ return;
650
+ }
651
+ if (config.popId === oldId) {
652
+ config.popId = popId;
653
+ return;
654
+ }
655
+ if (Array.isArray(config.items)) {
656
+ updatePopId(oldId, popId, config);
657
+ }
658
+ });
659
+ };
660
+ const setNewItemId = (config, parent) => {
661
+ const oldId = config.id;
662
+ config.id = generateId(config.type);
663
+ config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
664
+ if (isPop(config) && parent?.type === "page") {
665
+ updatePopId(oldId, config.id, parent);
666
+ }
667
+ if (config.items && Array.isArray(config.items)) {
668
+ config.items.forEach((item) => setNewItemId(item, config));
669
+ }
670
+ };
671
+ const isFixed = (node) => node.style?.position === "fixed";
672
+ const getNodeIndex = (node, parent) => {
673
+ const items = parent?.items || [];
674
+ return items.findIndex((item) => `${item.id}` === `${node.id}`);
675
+ };
676
+ const toRelative = (node) => {
677
+ node.style = {
678
+ ...node.style || {},
679
+ position: "relative",
680
+ top: 0,
681
+ left: 0
682
+ };
683
+ return node;
684
+ };
685
+ const initPosition = (node, layout) => {
686
+ if (layout === Layout.ABSOLUTE) {
687
+ node.style = {
688
+ position: "absolute",
689
+ ...node.style || {}
690
+ };
691
+ return node;
692
+ }
693
+ if (layout === Layout.RELATIVE) {
694
+ return toRelative(node);
695
+ }
696
+ return node;
697
+ };
698
+ const setLayout = (node, layout) => {
699
+ node.items?.forEach((child) => {
700
+ if (isPop(child))
701
+ return;
702
+ child.style = child.style || {};
703
+ if (child.style.position === "fixed")
704
+ return;
705
+ if (layout !== Layout.RELATIVE) {
706
+ child.style.position = "absolute";
707
+ } else {
708
+ toRelative(child);
709
+ child.style.right = "auto";
710
+ child.style.bottom = "auto";
711
+ }
712
+ });
713
+ return node;
714
+ };
715
+ const change2Fixed = (node, root) => {
716
+ const path = getNodePath(node.id, root.items);
717
+ const offset = {
718
+ left: 0,
719
+ top: 0
720
+ };
721
+ path.forEach((value) => {
722
+ offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
723
+ offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
724
+ });
725
+ node.style = {
726
+ ...node.style || {},
727
+ ...offset
728
+ };
729
+ return node;
730
+ };
731
+ const Fixed2Other = async (node, root, getLayout) => {
732
+ const path = getNodePath(node.id, root.items);
733
+ const cur = path.pop();
734
+ const offset = {
735
+ left: cur?.style?.left || 0,
736
+ top: cur?.style?.top || 0
737
+ };
738
+ path.forEach((value) => {
739
+ offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
740
+ offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
741
+ });
742
+ const parent = path.pop();
743
+ if (!parent) {
744
+ return toRelative(node);
745
+ }
746
+ const layout = await getLayout(parent);
747
+ if (layout !== Layout.RELATIVE) {
748
+ node.style = {
749
+ ...node.style || {},
750
+ ...offset,
751
+ position: "absolute"
752
+ };
753
+ return node;
754
+ }
755
+ return toRelative(node);
756
+ };
757
+ const defaults = (object, source) => {
758
+ let o = source;
759
+ if (Array.isArray(object)) {
760
+ o = object;
761
+ }
762
+ Object.entries(o).forEach(([key, value]) => {
763
+ if (typeof object[key] === "undefined") {
764
+ object[key] = value;
765
+ return;
766
+ }
767
+ if (value && typeof value !== "string" && Object.keys(value).length) {
768
+ object[key] = defaults(cloneDeep(object[key]), value);
769
+ }
770
+ });
771
+ return object;
772
+ };
773
+
774
+ const log = (...args) => {
775
+ };
776
+ const info = (...args) => {
777
+ };
778
+ const warn = (...args) => {
779
+ };
780
+ const debug = (...args) => {
781
+ };
782
+ const error = (...args) => {
783
+ };
784
+
785
+ class Editor$1 extends BaseService {
786
+ isHistoryStateChange = false;
787
+ state = reactive({
788
+ root: null,
789
+ page: null,
790
+ parent: null,
791
+ node: null,
792
+ stage: null,
793
+ modifiedNodeIds: /* @__PURE__ */ new Map()
794
+ });
795
+ constructor() {
796
+ super([
797
+ "getLayout",
798
+ "select",
799
+ "add",
800
+ "remove",
801
+ "update",
802
+ "sort",
803
+ "copy",
804
+ "paste",
805
+ "alignCenter",
806
+ "moveLayer",
807
+ "undo",
808
+ "redo"
809
+ ]);
810
+ }
811
+ set(name, value) {
812
+ this.state[name] = value;
813
+ if (name === "root") {
814
+ this.emit("root-change", value);
815
+ }
816
+ }
817
+ get(name) {
818
+ return this.state[name];
819
+ }
820
+ getNodeInfo(id) {
821
+ const root = this.get("root");
822
+ if (!root)
823
+ return {};
824
+ if (id === root.id) {
825
+ return { node: root };
826
+ }
827
+ const path = getNodePath(id, root.items);
828
+ if (!path.length)
829
+ return {};
830
+ path.unshift(root);
831
+ const info = {};
832
+ info.node = path[path.length - 1];
833
+ info.parent = path[path.length - 2];
834
+ path.forEach((item) => {
835
+ if (item.type === "page") {
836
+ info.page = item;
837
+ return;
838
+ }
839
+ });
840
+ return info;
841
+ }
842
+ getNodeById(id) {
843
+ const { node } = this.getNodeInfo(id);
844
+ return node;
845
+ }
846
+ getParentById(id) {
847
+ if (!this.get("root"))
848
+ return;
849
+ const { parent } = this.getNodeInfo(id);
850
+ return parent;
851
+ }
852
+ async getLayout(node) {
853
+ if (node.layout) {
854
+ return node.layout;
855
+ }
856
+ if (!node.style?.position) {
857
+ return Layout.RELATIVE;
858
+ }
859
+ return Layout.ABSOLUTE;
860
+ }
861
+ async select(config2) {
862
+ let id;
863
+ if (typeof config2 === "string" || typeof config2 === "number") {
864
+ id = config2;
865
+ } else {
866
+ id = config2.id;
867
+ }
868
+ if (!id) {
869
+ throw new Error("\u6CA1\u6709ID\uFF0C\u65E0\u6CD5\u9009\u4E2D");
870
+ }
871
+ const { node, parent, page } = this.getNodeInfo(id);
872
+ if (!node)
873
+ throw new Error("\u83B7\u53D6\u4E0D\u5230\u7EC4\u4EF6\u4FE1\u606F");
874
+ this.set("node", node);
875
+ this.set("page", page || null);
876
+ this.set("parent", parent || null);
877
+ if (page) {
878
+ historyService.changePage(toRaw(page));
879
+ } else {
880
+ historyService.empty();
881
+ }
882
+ return node;
883
+ }
884
+ async add({ type, ...config2 }, parent) {
885
+ const curNode = this.get("node");
886
+ let parentNode;
887
+ if (type === "page") {
888
+ parentNode = this.get("root");
889
+ } else if (parent && typeof parent !== "function") {
890
+ parentNode = parent;
891
+ } else if (curNode.items) {
892
+ parentNode = curNode;
893
+ } else {
894
+ parentNode = this.getParentById(curNode.id);
895
+ }
896
+ if (!parentNode)
897
+ throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
898
+ const layout = await this.getLayout(parentNode);
899
+ const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
900
+ if ((parentNode?.type === "app" || curNode.type === "app") && newNode.type !== "page") {
901
+ throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
902
+ }
903
+ parentNode?.items?.push(newNode);
904
+ await this.get("stage")?.add({ config: cloneDeep(newNode), root: cloneDeep(this.get("root")) });
905
+ await this.select(newNode);
906
+ this.addModifiedNodeId(newNode.id);
907
+ this.pushHistoryState();
908
+ return newNode;
909
+ }
910
+ async remove(node) {
911
+ if (!node?.id)
912
+ return;
913
+ const root = this.get("root");
914
+ if (!root)
915
+ throw new Error("\u6CA1\u6709root");
916
+ const { parent, node: curNode } = this.getNodeInfo(node.id);
917
+ if (!parent || !curNode)
918
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
919
+ const index = getNodeIndex(curNode, parent);
920
+ if (typeof index !== "number" || index === -1)
921
+ throw new Error("\u627E\u4E0D\u8981\u5220\u9664\u7684\u8282\u70B9");
922
+ parent.items?.splice(index, 1);
923
+ this.get("stage")?.remove({ id: node.id, root: this.get("root") });
924
+ if (node.type === "page") {
925
+ await this.select(root.items[0] || root);
926
+ } else {
927
+ await this.select(parent);
928
+ }
929
+ this.addModifiedNodeId(parent.id);
930
+ this.pushHistoryState();
931
+ return node;
932
+ }
933
+ async update(config2) {
934
+ if (!config2?.id)
935
+ throw new Error("\u6CA1\u6709\u914D\u7F6E\u6216\u8005\u914D\u7F6E\u7F3A\u5C11id\u503C");
936
+ const info = this.getNodeInfo(config2.id);
937
+ if (!info.node)
938
+ throw new Error(`\u83B7\u53D6\u4E0D\u5230id\u4E3A${config2.id}\u7684\u8282\u70B9`);
939
+ const node = cloneDeep(toRaw(info.node));
940
+ const { parent } = info;
941
+ if (!parent)
942
+ throw new Error("\u83B7\u53D6\u4E0D\u5230\u7236\u7EA7\u8282\u70B9");
943
+ let newConfig = await this.toggleFixedPosition(toRaw(config2), node, this.get("root"));
944
+ defaults(newConfig, node);
945
+ if (!newConfig.type)
946
+ throw new Error("\u914D\u7F6E\u7F3A\u5C11type\u503C");
947
+ if (newConfig.type === "app") {
948
+ this.set("root", newConfig);
949
+ return newConfig;
950
+ }
951
+ const parentNodeItems = parent.items;
952
+ const index = getNodeIndex(newConfig, parent);
953
+ if (!parentNodeItems || typeof index === "undefined" || index === -1)
954
+ throw new Error("\u66F4\u65B0\u7684\u8282\u70B9\u672A\u627E\u5230");
955
+ const newLayout = await this.getLayout(newConfig);
956
+ const layout = await this.getLayout(node);
957
+ if (newLayout !== layout) {
958
+ newConfig = setLayout(newConfig, newLayout);
959
+ }
960
+ parentNodeItems[index] = newConfig;
961
+ if (newConfig.id === this.get("node").id) {
962
+ this.set("node", newConfig);
963
+ }
964
+ this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
965
+ if (newConfig.type === "page") {
966
+ this.set("page", newConfig);
967
+ }
968
+ this.addModifiedNodeId(newConfig.id);
969
+ this.pushHistoryState();
970
+ return newConfig;
971
+ }
972
+ async sort(id1, id2) {
973
+ const node = this.get("node");
974
+ const parent = cloneDeep(toRaw(this.get("parent")));
975
+ const index2 = parent.items.findIndex((node2) => `${node2.id}` === `${id2}`);
976
+ if (index2 < 0)
977
+ return;
978
+ const index1 = parent.items.findIndex((node2) => `${node2.id}` === `${id1}`);
979
+ parent.items.splice(index2, 0, ...parent.items.splice(index1, 1));
980
+ await this.update(parent);
981
+ await this.select(node);
982
+ this.addModifiedNodeId(parent.id);
983
+ this.pushHistoryState();
984
+ }
985
+ async copy(config2) {
986
+ globalThis.localStorage.setItem(COPY_STORAGE_KEY, serialize(config2));
987
+ }
988
+ async paste(position = {}) {
989
+ const configStr = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
990
+ let config = {};
991
+ if (!configStr) {
992
+ return;
993
+ }
994
+ try {
995
+ eval(`config = ${configStr}`);
996
+ } catch (e) {
997
+ console.error(e);
998
+ return;
999
+ }
1000
+ setNewItemId(config, this.get("root"));
1001
+ if (config.style) {
1002
+ config.style = {
1003
+ ...config.style,
1004
+ ...position
1005
+ };
1006
+ }
1007
+ return await this.add(config);
1008
+ }
1009
+ async alignCenter(config2) {
1010
+ const parent = this.get("parent");
1011
+ const node = this.get("node");
1012
+ const layout = await this.getLayout(parent);
1013
+ if (layout === Layout.RELATIVE) {
1014
+ return;
1015
+ }
1016
+ if (parent.style?.width && node.style?.width) {
1017
+ node.style.left = (parent.style.width - node.style.width) / 2;
1018
+ }
1019
+ await this.update(node);
1020
+ this.get("stage")?.update({ config: cloneDeep(toRaw(node)), root: this.get("root") });
1021
+ this.addModifiedNodeId(config2.id);
1022
+ this.pushHistoryState();
1023
+ return config2;
1024
+ }
1025
+ async moveLayer(offset) {
1026
+ const parent = this.get("parent");
1027
+ const node = this.get("node");
1028
+ const brothers = parent?.items || [];
1029
+ const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
1030
+ if (offset === LayerOffset.BOTTOM) {
1031
+ brothers.splice(brothers.length - 1, 0, brothers.splice(index, 1)[0]);
1032
+ } else if (offset === LayerOffset.TOP) {
1033
+ brothers.splice(0, 0, brothers.splice(index, 1)[0]);
1034
+ } else {
1035
+ brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
1036
+ }
1037
+ this.get("stage")?.update({ config: cloneDeep(toRaw(parent)), root: this.get("root") });
1038
+ }
1039
+ async undo() {
1040
+ const value = historyService.undo();
1041
+ await this.changeHistoryState(value);
1042
+ return value;
1043
+ }
1044
+ async redo() {
1045
+ const value = historyService.redo();
1046
+ await this.changeHistoryState(value);
1047
+ return value;
1048
+ }
1049
+ destroy() {
1050
+ this.removeAllListeners();
1051
+ this.set("root", null);
1052
+ this.set("node", null);
1053
+ this.set("page", null);
1054
+ this.set("parent", null);
1055
+ }
1056
+ resetModifiedNodeId() {
1057
+ this.get("modifiedNodeIds").clear();
1058
+ }
1059
+ addModifiedNodeId(id) {
1060
+ if (!this.isHistoryStateChange) {
1061
+ this.get("modifiedNodeIds").set(id, id);
1062
+ }
1063
+ }
1064
+ pushHistoryState() {
1065
+ const curNode = cloneDeep(toRaw(this.get("node")));
1066
+ if (!this.isHistoryStateChange) {
1067
+ historyService.push({
1068
+ data: cloneDeep(toRaw(this.get("page"))),
1069
+ modifiedNodeIds: this.get("modifiedNodeIds"),
1070
+ nodeId: curNode.id
1071
+ });
1072
+ }
1073
+ this.isHistoryStateChange = false;
1074
+ }
1075
+ async changeHistoryState(value) {
1076
+ if (!value)
1077
+ return;
1078
+ this.isHistoryStateChange = true;
1079
+ await this.update(value.data);
1080
+ this.set("modifiedNodeIds", value.modifiedNodeIds);
1081
+ setTimeout(() => value.nodeId && this.select(value.nodeId), 0);
1082
+ }
1083
+ async toggleFixedPosition(dist, src, root) {
1084
+ let newConfig = cloneDeep(dist);
1085
+ if (!isPop(src) && newConfig.style?.position) {
1086
+ if (isFixed(newConfig) && !isFixed(src)) {
1087
+ newConfig = change2Fixed(newConfig, root);
1088
+ } else if (!isFixed(newConfig) && isFixed(src)) {
1089
+ newConfig = await Fixed2Other(newConfig, root, this.getLayout);
1090
+ }
1091
+ }
1092
+ return newConfig;
1093
+ }
1094
+ }
1095
+ var editorService = new Editor$1();
1096
+
1097
+ const eventMap = reactive({});
1098
+ const methodMap = reactive({});
1099
+ class Events extends BaseService {
1100
+ constructor() {
1101
+ super([]);
1102
+ }
1103
+ init(componentGroupList) {
1104
+ componentGroupList.forEach((group) => {
1105
+ group.items.forEach((element) => {
1106
+ const type = toLine(element.type);
1107
+ if (!this.getEvent(type)) {
1108
+ this.setEvent(type, DEFAULT_EVENTS);
1109
+ }
1110
+ if (!this.getMethod(type)) {
1111
+ this.setMethod(type, DEFAULT_METHODS);
1112
+ }
1113
+ });
1114
+ });
1115
+ }
1116
+ setEvents(events) {
1117
+ Object.keys(events).forEach((type) => {
1118
+ this.setEvent(toLine(type), events[type] || []);
1119
+ });
1120
+ }
1121
+ setEvent(type, events) {
1122
+ eventMap[type] = [...DEFAULT_EVENTS, ...events];
1123
+ }
1124
+ getEvent(type) {
1125
+ return cloneDeep(eventMap[type] || DEFAULT_EVENTS);
1126
+ }
1127
+ setMethods(methods) {
1128
+ Object.keys(methods).forEach((type) => {
1129
+ this.setMethod(toLine(type), methods[type] || []);
1130
+ });
1131
+ }
1132
+ setMethod(type, method) {
1133
+ methodMap[type] = [...DEFAULT_METHODS, ...method];
1134
+ }
1135
+ getMethod(type) {
1136
+ return cloneDeep(methodMap[type] || DEFAULT_METHODS);
1137
+ }
1138
+ }
1139
+ var eventsService = new Events();
1140
+
1141
+ const fillConfig = (config = []) => [
1142
+ {
1143
+ type: "tab",
1144
+ items: [
1145
+ {
1146
+ title: "\u5C5E\u6027",
1147
+ labelWidth: "80px",
1148
+ items: [
1149
+ {
1150
+ text: "type",
1151
+ name: "type",
1152
+ type: "hidden"
1153
+ },
1154
+ {
1155
+ name: "id",
1156
+ type: "display",
1157
+ text: "id"
1158
+ },
1159
+ {
1160
+ name: "name",
1161
+ text: "\u7EC4\u4EF6\u540D\u79F0"
1162
+ },
1163
+ ...config
1164
+ ]
1165
+ },
1166
+ {
1167
+ title: "\u6837\u5F0F",
1168
+ labelWidth: "80px",
1169
+ items: [
1170
+ {
1171
+ name: "style",
1172
+ items: [
1173
+ {
1174
+ type: "fieldset",
1175
+ legend: "\u4F4D\u7F6E",
1176
+ items: [
1177
+ {
1178
+ name: "position",
1179
+ type: "checkbox",
1180
+ activeValue: "fixed",
1181
+ inactiveValue: "absolute",
1182
+ defaultValue: "absolute",
1183
+ text: "\u56FA\u5B9A\u5B9A\u4F4D"
1184
+ },
1185
+ {
1186
+ name: "left",
1187
+ text: "left"
1188
+ },
1189
+ {
1190
+ name: "top",
1191
+ text: "top",
1192
+ disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
1193
+ },
1194
+ {
1195
+ name: "right",
1196
+ text: "right"
1197
+ },
1198
+ {
1199
+ name: "bottom",
1200
+ text: "bottom",
1201
+ disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
1202
+ }
1203
+ ]
1204
+ },
1205
+ {
1206
+ type: "fieldset",
1207
+ legend: "\u76D2\u5B50",
1208
+ items: [
1209
+ {
1210
+ name: "width",
1211
+ text: "\u5BBD\u5EA6"
1212
+ },
1213
+ {
1214
+ name: "height",
1215
+ text: "\u9AD8\u5EA6"
1216
+ }
1217
+ ]
1218
+ },
1219
+ {
1220
+ type: "fieldset",
1221
+ legend: "\u80CC\u666F",
1222
+ items: [
1223
+ {
1224
+ name: "backgroundImage",
1225
+ text: "\u80CC\u666F\u56FE"
1226
+ },
1227
+ {
1228
+ name: "backgroundColor",
1229
+ text: "\u80CC\u666F\u989C\u8272",
1230
+ type: "colorPicker"
1231
+ },
1232
+ {
1233
+ name: "backgroundRepeat",
1234
+ text: "\u80CC\u666F\u56FE\u91CD\u590D",
1235
+ type: "select",
1236
+ defaultValue: "no-repeat",
1237
+ options: [
1238
+ { text: "repeat", value: "repeat" },
1239
+ { text: "repeat-x", value: "repeat-x" },
1240
+ { text: "repeat-y", value: "repeat-y" },
1241
+ { text: "no-repeat", value: "no-repeat" },
1242
+ { text: "inherit", value: "inherit" }
1243
+ ]
1244
+ },
1245
+ {
1246
+ name: "backgroundSize",
1247
+ text: "\u80CC\u666F\u56FE\u5927\u5C0F",
1248
+ defaultValue: "100% 100%"
1249
+ }
1250
+ ]
1251
+ }
1252
+ ]
1253
+ }
1254
+ ]
1255
+ },
1256
+ {
1257
+ title: "\u4E8B\u4EF6",
1258
+ items: [
1259
+ {
1260
+ type: "table",
1261
+ name: "events",
1262
+ items: [
1263
+ {
1264
+ name: "name",
1265
+ label: "\u4E8B\u4EF6\u540D",
1266
+ type: "select",
1267
+ options: (mForm, { formValue }) => eventsService.getEvent(formValue.type).map((option) => ({
1268
+ text: option.label,
1269
+ value: option.value
1270
+ }))
1271
+ },
1272
+ {
1273
+ name: "to",
1274
+ label: "\u8054\u52A8\u7EC4\u4EF6",
1275
+ type: "ui-select"
1276
+ },
1277
+ {
1278
+ name: "method",
1279
+ label: "\u52A8\u4F5C",
1280
+ type: "select",
1281
+ options: (mForm, { model }) => {
1282
+ const node = editorService.getNodeById(model.to);
1283
+ if (!node)
1284
+ return [];
1285
+ return eventsService.getMethod(node.type).map((option) => ({
1286
+ text: option.label,
1287
+ value: option.value
1288
+ }));
1289
+ }
1290
+ }
1291
+ ]
1292
+ }
1293
+ ]
1294
+ },
1295
+ {
1296
+ title: "\u9AD8\u7EA7",
1297
+ labelWidth: "80px",
1298
+ items: [
1299
+ {
1300
+ type: "code-link",
1301
+ name: "created",
1302
+ text: "created",
1303
+ formTitle: "created"
1304
+ }
1305
+ ]
1306
+ }
1307
+ ]
1308
+ }
1309
+ ];
1310
+ const DEFAULT_CONFIG = fillConfig([]);
1311
+ const getDefaultPropsValue = (type) => ({
1312
+ type,
1313
+ id: generateId(type),
1314
+ style: {},
1315
+ name: type
1316
+ });
1317
+
1318
+ const _sfc_main$f = defineComponent({
1319
+ components: { Plus },
1320
+ setup() {
1321
+ const services = inject("services");
1322
+ return {
1323
+ clickHandler() {
1324
+ const { editorService } = services || {};
1325
+ if (!editorService)
1326
+ return;
1327
+ editorService.add({
1328
+ type: "page",
1329
+ name: generatePageNameByApp(toRaw(editorService.get("root")))
1330
+ });
1331
+ }
1332
+ };
1333
+ }
1334
+ });
1335
+ const _hoisted_1$b = { class: "m-editor-empty-panel" };
1336
+ const _hoisted_2$6 = { class: "m-editor-empty-content" };
1337
+ const _hoisted_3$4 = /* @__PURE__ */ createElementVNode("p", null, "\u65B0\u589E\u9875\u9762", -1);
1338
+ function _sfc_render$f(_ctx, _cache, $props, $setup, $data, $options) {
1339
+ const _component_plus = resolveComponent("plus");
1340
+ const _component_el_icon = resolveComponent("el-icon");
1341
+ return openBlock(), createElementBlock("div", _hoisted_1$b, [
1342
+ createElementVNode("div", _hoisted_2$6, [
1343
+ createElementVNode("div", {
1344
+ class: "m-editor-empty-button",
1345
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.clickHandler && _ctx.clickHandler(...args))
1346
+ }, [
1347
+ createElementVNode("div", null, [
1348
+ createVNode(_component_el_icon, null, {
1349
+ default: withCtx(() => [
1350
+ createVNode(_component_plus)
1351
+ ]),
1352
+ _: 1
1353
+ })
1354
+ ]),
1355
+ _hoisted_3$4
1356
+ ])
1357
+ ])
1358
+ ]);
1359
+ }
1360
+ var AddPageBox = /* @__PURE__ */ _export_sfc(_sfc_main$f, [["render", _sfc_render$f]]);
1361
+
1362
+ /*
1363
+ Copyright (c) 2018 Daybrush
1364
+ @name: @daybrush/utils
1365
+ license: MIT
1366
+ author: Daybrush
1367
+ repository: https://github.com/daybrush/utils
1368
+ @version 1.6.0
1369
+ */
1370
+ /**
1371
+ * get string "object"
1372
+ * @memberof Consts
1373
+ * @example
1374
+ import {OBJECT} from "@daybrush/utils";
1375
+
1376
+ console.log(OBJECT); // "object"
1377
+ */
1378
+
1379
+ var OBJECT = "object";
1380
+ /**
1381
+ * Check the type that the value is object.
1382
+ * @memberof Utils
1383
+ * @param {string} value - Value to check the type
1384
+ * @return {} true if the type is correct, false otherwise
1385
+ * @example
1386
+ import {isObject} from "@daybrush/utils";
1387
+
1388
+ console.log(isObject({})); // true
1389
+ console.log(isObject(undefined)); // false
1390
+ console.log(isObject("")); // false
1391
+ console.log(isObject(null)); // false
1392
+ */
1393
+
1394
+ function isObject(value) {
1395
+ return value && typeof value === OBJECT;
1396
+ }
1397
+ /**
1398
+ * Date.now() method
1399
+ * @memberof CrossBrowser
1400
+ * @return {number} milliseconds
1401
+ * @example
1402
+ import {now} from "@daybrush/utils";
1403
+
1404
+ console.log(now()); // 12121324241(milliseconds)
1405
+ */
1406
+
1407
+ function now() {
1408
+ return Date.now ? Date.now() : new Date().getTime();
1409
+ }
1410
+ /**
1411
+ * Returns the index of the first element in the array that satisfies the provided testing function.
1412
+ * @function
1413
+ * @memberof CrossBrowser
1414
+ * @param - The array `findIndex` was called upon.
1415
+ * @param - A function to execute on each value in the array until the function returns true, indicating that the satisfying element was found.
1416
+ * @param - Returns defaultIndex if not found by the function.
1417
+ * @example
1418
+ import { findIndex } from "@daybrush/utils";
1419
+
1420
+ findIndex([{a: 1}, {a: 2}, {a: 3}, {a: 4}], ({ a }) => a === 2); // 1
1421
+ */
1422
+
1423
+ function findIndex(arr, callback, defaultIndex) {
1424
+ if (defaultIndex === void 0) {
1425
+ defaultIndex = -1;
1426
+ }
1427
+
1428
+ var length = arr.length;
1429
+
1430
+ for (var i = 0; i < length; ++i) {
1431
+ if (callback(arr[i], i, arr)) {
1432
+ return i;
1433
+ }
1434
+ }
1435
+
1436
+ return defaultIndex;
1437
+ }
1438
+ /**
1439
+ * Sets up a function that will be called whenever the specified event is delivered to the target
1440
+ * @memberof DOM
1441
+ * @param - event target
1442
+ * @param - A case-sensitive string representing the event type to listen for.
1443
+ * @param - The object which receives a notification (an object that implements the Event interface) when an event of the specified type occurs
1444
+ * @param - An options object that specifies characteristics about the event listener.
1445
+ * @example
1446
+ import {addEvent} from "@daybrush/utils";
1447
+
1448
+ addEvent(el, "click", e => {
1449
+ console.log(e);
1450
+ });
1451
+ */
1452
+
1453
+ function addEvent(el, type, listener, options) {
1454
+ el.addEventListener(type, listener, options);
1455
+ }
1456
+ /**
1457
+ * removes from the EventTarget an event listener previously registered with EventTarget.addEventListener()
1458
+ * @memberof DOM
1459
+ * @param - event target
1460
+ * @param - A case-sensitive string representing the event type to listen for.
1461
+ * @param - The EventListener function of the event handler to remove from the event target.
1462
+ * @param - An options object that specifies characteristics about the event listener.
1463
+ * @example
1464
+ import {addEvent, removeEvent} from "@daybrush/utils";
1465
+ const listener = e => {
1466
+ console.log(e);
1467
+ };
1468
+ addEvent(el, "click", listener);
1469
+ removeEvent(el, "click", listener);
1470
+ */
1471
+
1472
+ function removeEvent(el, type, listener, options) {
1473
+ el.removeEventListener(type, listener, options);
1474
+ }
1475
+
1476
+ /*
1477
+ Copyright (c) 2019 Daybrush
1478
+ name: @scena/event-emitter
1479
+ license: MIT
1480
+ author: Daybrush
1481
+ repository: git+https://github.com/daybrush/gesture.git
1482
+ version: 1.0.5
1483
+ */
1484
+
1485
+ /*! *****************************************************************************
1486
+ Copyright (c) Microsoft Corporation.
1487
+
1488
+ Permission to use, copy, modify, and/or distribute this software for any
1489
+ purpose with or without fee is hereby granted.
1490
+
1491
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1492
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1493
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1494
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1495
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1496
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1497
+ PERFORMANCE OF THIS SOFTWARE.
1498
+ ***************************************************************************** */
1499
+ var __assign$1 = function () {
1500
+ __assign$1 = Object.assign || function __assign(t) {
1501
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1502
+ s = arguments[i];
1503
+
1504
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1505
+ }
1506
+
1507
+ return t;
1508
+ };
1509
+
1510
+ return __assign$1.apply(this, arguments);
1511
+ };
1512
+ function __spreadArrays() {
1513
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1514
+
1515
+ for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
1516
+
1517
+ return r;
1518
+ }
1519
+
1520
+ /**
1521
+ * Implement EventEmitter on object or component.
1522
+ */
1523
+
1524
+ var EventEmitter =
1525
+ /*#__PURE__*/
1526
+ function () {
1527
+ function EventEmitter() {
1528
+ this._events = {};
1529
+ }
1530
+ /**
1531
+ * Add a listener to the registered event.
1532
+ * @param - Name of the event to be added
1533
+ * @param - listener function of the event to be added
1534
+ * @example
1535
+ * import EventEmitter from "@scena/event-emitter";
1536
+ * cosnt emitter = new EventEmitter();
1537
+ *
1538
+ * // Add listener in "a" event
1539
+ * emitter.on("a", () => {
1540
+ * });
1541
+ * // Add listeners
1542
+ * emitter.on({
1543
+ * a: () => {},
1544
+ * b: () => {},
1545
+ * });
1546
+ */
1547
+
1548
+
1549
+ var __proto = EventEmitter.prototype;
1550
+
1551
+ __proto.on = function (eventName, listener) {
1552
+ if (isObject(eventName)) {
1553
+ for (var name in eventName) {
1554
+ this.on(name, eventName[name]);
1555
+ }
1556
+ } else {
1557
+ this._addEvent(eventName, listener, {});
1558
+ }
1559
+
1560
+ return this;
1561
+ };
1562
+ /**
1563
+ * Remove listeners registered in the event target.
1564
+ * @param - Name of the event to be removed
1565
+ * @param - listener function of the event to be removed
1566
+ * @example
1567
+ * import EventEmitter from "@scena/event-emitter";
1568
+ * cosnt emitter = new EventEmitter();
1569
+ *
1570
+ * // Remove all listeners.
1571
+ * emitter.off();
1572
+ *
1573
+ * // Remove all listeners in "A" event.
1574
+ * emitter.off("a");
1575
+ *
1576
+ *
1577
+ * // Remove "listener" listener in "a" event.
1578
+ * emitter.off("a", listener);
1579
+ */
1580
+
1581
+
1582
+ __proto.off = function (eventName, listener) {
1583
+ if (!eventName) {
1584
+ this._events = {};
1585
+ } else if (isObject(eventName)) {
1586
+ for (var name in eventName) {
1587
+ this.off(name);
1588
+ }
1589
+ } else if (!listener) {
1590
+ this._events[eventName] = [];
1591
+ } else {
1592
+ var events = this._events[eventName];
1593
+
1594
+ if (events) {
1595
+ var index = findIndex(events, function (e) {
1596
+ return e.listener === listener;
1597
+ });
1598
+
1599
+ if (index > -1) {
1600
+ events.splice(index, 1);
1601
+ }
1602
+ }
1603
+ }
1604
+
1605
+ return this;
1606
+ };
1607
+ /**
1608
+ * Add a disposable listener and Use promise to the registered event.
1609
+ * @param - Name of the event to be added
1610
+ * @param - disposable listener function of the event to be added
1611
+ * @example
1612
+ * import EventEmitter from "@scena/event-emitter";
1613
+ * cosnt emitter = new EventEmitter();
1614
+ *
1615
+ * // Add a disposable listener in "a" event
1616
+ * emitter.once("a", () => {
1617
+ * });
1618
+ *
1619
+ * // Use Promise
1620
+ * emitter.once("a").then(e => {
1621
+ * });
1622
+ */
1623
+
1624
+
1625
+ __proto.once = function (eventName, listener) {
1626
+ var _this = this;
1627
+
1628
+ if (listener) {
1629
+ this._addEvent(eventName, listener, {
1630
+ once: true
1631
+ });
1632
+ }
1633
+
1634
+ return new Promise(function (resolve) {
1635
+ _this._addEvent(eventName, resolve, {
1636
+ once: true
1637
+ });
1638
+ });
1639
+ };
1640
+ /**
1641
+ * Fires an event to call listeners.
1642
+ * @param - Event name
1643
+ * @param - Event parameter
1644
+ * @return If false, stop the event.
1645
+ * @example
1646
+ *
1647
+ * import EventEmitter from "@scena/event-emitter";
1648
+ *
1649
+ *
1650
+ * const emitter = new EventEmitter();
1651
+ *
1652
+ * emitter.on("a", e => {
1653
+ * });
1654
+ *
1655
+ *
1656
+ * emitter.emit("a", {
1657
+ * a: 1,
1658
+ * });
1659
+ */
1660
+
1661
+
1662
+ __proto.emit = function (eventName, param) {
1663
+ var _this = this;
1664
+
1665
+ if (param === void 0) {
1666
+ param = {};
1667
+ }
1668
+
1669
+ var events = this._events[eventName];
1670
+
1671
+ if (!eventName || !events) {
1672
+ return true;
1673
+ }
1674
+
1675
+ var isStop = false;
1676
+ param.eventType = eventName;
1677
+
1678
+ param.stop = function () {
1679
+ isStop = true;
1680
+ };
1681
+
1682
+ param.currentTarget = this;
1683
+
1684
+ __spreadArrays(events).forEach(function (info) {
1685
+ info.listener(param);
1686
+
1687
+ if (info.once) {
1688
+ _this.off(eventName, info.listener);
1689
+ }
1690
+ });
1691
+
1692
+ return !isStop;
1693
+ };
1694
+ /**
1695
+ * Fires an event to call listeners.
1696
+ * @param - Event name
1697
+ * @param - Event parameter
1698
+ * @return If false, stop the event.
1699
+ * @example
1700
+ *
1701
+ * import EventEmitter from "@scena/event-emitter";
1702
+ *
1703
+ *
1704
+ * const emitter = new EventEmitter();
1705
+ *
1706
+ * emitter.on("a", e => {
1707
+ * });
1708
+ *
1709
+ *
1710
+ * emitter.emit("a", {
1711
+ * a: 1,
1712
+ * });
1713
+ */
1714
+
1715
+ /**
1716
+ * Fires an event to call listeners.
1717
+ * @param - Event name
1718
+ * @param - Event parameter
1719
+ * @return If false, stop the event.
1720
+ * @example
1721
+ *
1722
+ * import EventEmitter from "@scena/event-emitter";
1723
+ *
1724
+ *
1725
+ * const emitter = new EventEmitter();
1726
+ *
1727
+ * emitter.on("a", e => {
1728
+ * });
1729
+ *
1730
+ * // emit
1731
+ * emitter.trigger("a", {
1732
+ * a: 1,
1733
+ * });
1734
+ */
1735
+
1736
+
1737
+ __proto.trigger = function (eventName, param) {
1738
+ if (param === void 0) {
1739
+ param = {};
1740
+ }
1741
+
1742
+ return this.emit(eventName, param);
1743
+ };
1744
+
1745
+ __proto._addEvent = function (eventName, listener, options) {
1746
+ var events = this._events;
1747
+ events[eventName] = events[eventName] || [];
1748
+ var listeners = events[eventName];
1749
+ listeners.push(__assign$1({
1750
+ listener: listener
1751
+ }, options));
1752
+ };
1753
+
1754
+ return EventEmitter;
1755
+ }();
1756
+
1757
+ var EventEmitter$1 = EventEmitter;
1758
+
1759
+ /*
1760
+ Copyright (c) 2019 Daybrush
1761
+ name: gesto
1762
+ license: MIT
1763
+ author: Daybrush
1764
+ repository: git+https://github.com/daybrush/gesture.git
1765
+ version: 1.5.0
1766
+ */
1767
+
1768
+ /*! *****************************************************************************
1769
+ Copyright (c) Microsoft Corporation. All rights reserved.
1770
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1771
+ this file except in compliance with the License. You may obtain a copy of the
1772
+ License at http://www.apache.org/licenses/LICENSE-2.0
1773
+
1774
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1775
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1776
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1777
+ MERCHANTABLITY OR NON-INFRINGEMENT.
1778
+
1779
+ See the Apache Version 2.0 License for specific language governing permissions
1780
+ and limitations under the License.
1781
+ ***************************************************************************** */
1782
+
1783
+ /* global Reflect, Promise */
1784
+ var extendStatics = function (d, b) {
1785
+ extendStatics = Object.setPrototypeOf || {
1786
+ __proto__: []
1787
+ } instanceof Array && function (d, b) {
1788
+ d.__proto__ = b;
1789
+ } || function (d, b) {
1790
+ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1791
+ };
1792
+
1793
+ return extendStatics(d, b);
1794
+ };
1795
+
1796
+ function __extends(d, b) {
1797
+ extendStatics(d, b);
1798
+
1799
+ function __() {
1800
+ this.constructor = d;
1801
+ }
1802
+
1803
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1804
+ }
1805
+ var __assign = function () {
1806
+ __assign = Object.assign || function __assign(t) {
1807
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1808
+ s = arguments[i];
1809
+
1810
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1811
+ }
1812
+
1813
+ return t;
1814
+ };
1815
+
1816
+ return __assign.apply(this, arguments);
1817
+ };
1818
+
1819
+ function getRad(pos1, pos2) {
1820
+ var distX = pos2[0] - pos1[0];
1821
+ var distY = pos2[1] - pos1[1];
1822
+ var rad = Math.atan2(distY, distX);
1823
+ return rad >= 0 ? rad : rad + Math.PI * 2;
1824
+ }
1825
+ function getRotatiion(touches) {
1826
+ return getRad([touches[0].clientX, touches[0].clientY], [touches[1].clientX, touches[1].clientY]) / Math.PI * 180;
1827
+ }
1828
+ function isMultiTouch(e) {
1829
+ return e.touches && e.touches.length >= 2;
1830
+ }
1831
+ function getEventClients(e) {
1832
+ if (e.touches) {
1833
+ return getClients(e.touches);
1834
+ } else {
1835
+ return [getClient(e)];
1836
+ }
1837
+ }
1838
+ function getPosition(clients, prevClients, startClients) {
1839
+ var length = startClients.length;
1840
+
1841
+ var _a = getAverageClient(clients, length),
1842
+ clientX = _a.clientX,
1843
+ clientY = _a.clientY,
1844
+ originalClientX = _a.originalClientX,
1845
+ originalClientY = _a.originalClientY;
1846
+
1847
+ var _b = getAverageClient(prevClients, length),
1848
+ prevX = _b.clientX,
1849
+ prevY = _b.clientY;
1850
+
1851
+ var _c = getAverageClient(startClients, length),
1852
+ startX = _c.clientX,
1853
+ startY = _c.clientY;
1854
+
1855
+ var deltaX = clientX - prevX;
1856
+ var deltaY = clientY - prevY;
1857
+ var distX = clientX - startX;
1858
+ var distY = clientY - startY;
1859
+ return {
1860
+ clientX: originalClientX,
1861
+ clientY: originalClientY,
1862
+ deltaX: deltaX,
1863
+ deltaY: deltaY,
1864
+ distX: distX,
1865
+ distY: distY
1866
+ };
1867
+ }
1868
+ function getDist(clients) {
1869
+ return Math.sqrt(Math.pow(clients[0].clientX - clients[1].clientX, 2) + Math.pow(clients[0].clientY - clients[1].clientY, 2));
1870
+ }
1871
+ function getClients(touches) {
1872
+ var length = Math.min(touches.length, 2);
1873
+ var clients = [];
1874
+
1875
+ for (var i = 0; i < length; ++i) {
1876
+ clients.push(getClient(touches[i]));
1877
+ }
1878
+
1879
+ return clients;
1880
+ }
1881
+ function getClient(e) {
1882
+ return {
1883
+ clientX: e.clientX,
1884
+ clientY: e.clientY
1885
+ };
1886
+ }
1887
+ function getAverageClient(clients, length) {
1888
+ if (length === void 0) {
1889
+ length = clients.length;
1890
+ }
1891
+
1892
+ var sumClient = {
1893
+ clientX: 0,
1894
+ clientY: 0,
1895
+ originalClientX: 0,
1896
+ originalClientY: 0
1897
+ };
1898
+
1899
+ for (var i = 0; i < length; ++i) {
1900
+ var client = clients[i];
1901
+ sumClient.originalClientX += "originalClientX" in client ? client.originalClientX : client.clientX;
1902
+ sumClient.originalClientY += "originalClientY" in client ? client.originalClientY : client.clientY;
1903
+ sumClient.clientX += client.clientX;
1904
+ sumClient.clientY += client.clientY;
1905
+ }
1906
+
1907
+ if (!length) {
1908
+ return sumClient;
1909
+ }
1910
+
1911
+ return {
1912
+ clientX: sumClient.clientX / length,
1913
+ clientY: sumClient.clientY / length,
1914
+ originalClientX: sumClient.originalClientX / length,
1915
+ originalClientY: sumClient.originalClientY / length
1916
+ };
1917
+ }
1918
+
1919
+ var ClientStore =
1920
+ /*#__PURE__*/
1921
+ function () {
1922
+ function ClientStore(clients) {
1923
+ this.prevClients = [];
1924
+ this.startClients = [];
1925
+ this.movement = 0;
1926
+ this.length = 0;
1927
+ this.startClients = clients;
1928
+ this.prevClients = clients;
1929
+ this.length = clients.length;
1930
+ }
1931
+
1932
+ var __proto = ClientStore.prototype;
1933
+
1934
+ __proto.addClients = function (clients) {
1935
+ if (clients === void 0) {
1936
+ clients = this.prevClients;
1937
+ }
1938
+
1939
+ var position = this.getPosition(clients);
1940
+ var deltaX = position.deltaX,
1941
+ deltaY = position.deltaY;
1942
+ this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
1943
+ this.prevClients = clients;
1944
+ return position;
1945
+ };
1946
+
1947
+ __proto.getAngle = function (clients) {
1948
+ if (clients === void 0) {
1949
+ clients = this.prevClients;
1950
+ }
1951
+
1952
+ return getRotatiion(clients);
1953
+ };
1954
+
1955
+ __proto.getRotation = function (clients) {
1956
+ if (clients === void 0) {
1957
+ clients = this.prevClients;
1958
+ }
1959
+
1960
+ return getRotatiion(clients) - getRotatiion(this.startClients);
1961
+ };
1962
+
1963
+ __proto.getPosition = function (clients) {
1964
+ return getPosition(clients || this.prevClients, this.prevClients, this.startClients);
1965
+ };
1966
+
1967
+ __proto.getPositions = function (clients) {
1968
+ if (clients === void 0) {
1969
+ clients = this.prevClients;
1970
+ }
1971
+
1972
+ var prevClients = this.prevClients;
1973
+ return this.startClients.map(function (startClient, i) {
1974
+ return getPosition([clients[i]], [prevClients[i]], [startClient]);
1975
+ });
1976
+ };
1977
+
1978
+ __proto.getMovement = function (clients) {
1979
+ var movement = this.movement;
1980
+
1981
+ if (!clients) {
1982
+ return movement;
1983
+ }
1984
+
1985
+ var currentClient = getAverageClient(clients, this.length);
1986
+ var prevClient = getAverageClient(this.prevClients, this.length);
1987
+ var deltaX = currentClient.clientX - prevClient.clientX;
1988
+ var deltaY = currentClient.clientY - prevClient.clientY;
1989
+ return Math.sqrt(deltaX * deltaX + deltaY * deltaY) + movement;
1990
+ };
1991
+
1992
+ __proto.getDistance = function (clients) {
1993
+ if (clients === void 0) {
1994
+ clients = this.prevClients;
1995
+ }
1996
+
1997
+ return getDist(clients);
1998
+ };
1999
+
2000
+ __proto.getScale = function (clients) {
2001
+ if (clients === void 0) {
2002
+ clients = this.prevClients;
2003
+ }
2004
+
2005
+ return getDist(clients) / getDist(this.startClients);
2006
+ };
2007
+
2008
+ __proto.move = function (deltaX, deltaY) {
2009
+ this.startClients.forEach(function (client) {
2010
+ client.clientX -= deltaX;
2011
+ client.clientY -= deltaY;
2012
+ });
2013
+ this.prevClients.forEach(function (client) {
2014
+ client.clientX -= deltaX;
2015
+ client.clientY -= deltaY;
2016
+ });
2017
+ };
2018
+
2019
+ return ClientStore;
2020
+ }();
2021
+
2022
+ var INPUT_TAGNAMES = ["textarea", "input"];
2023
+ /**
2024
+ * You can set up drag, pinch events in any browser.
2025
+ */
2026
+
2027
+ var Gesto =
2028
+ /*#__PURE__*/
2029
+ function (_super) {
2030
+ __extends(Gesto, _super);
2031
+ /**
2032
+ *
2033
+ */
2034
+
2035
+
2036
+ function Gesto(targets, options) {
2037
+ if (options === void 0) {
2038
+ options = {};
2039
+ }
2040
+
2041
+ var _this = _super.call(this) || this;
2042
+
2043
+ _this.options = {};
2044
+ _this.flag = false;
2045
+ _this.pinchFlag = false;
2046
+ _this.datas = {};
2047
+ _this.isDrag = false;
2048
+ _this.isPinch = false;
2049
+ _this.isMouse = false;
2050
+ _this.isTouch = false;
2051
+ _this.clientStores = [];
2052
+ _this.targets = [];
2053
+ _this.prevTime = 0;
2054
+ _this.doubleFlag = false;
2055
+
2056
+ _this.onDragStart = function (e, isTrusted) {
2057
+ if (isTrusted === void 0) {
2058
+ isTrusted = true;
2059
+ }
2060
+
2061
+ if (!_this.flag && e.cancelable === false) {
2062
+ return;
2063
+ }
2064
+
2065
+ var _a = _this.options,
2066
+ container = _a.container,
2067
+ pinchOutside = _a.pinchOutside,
2068
+ preventRightClick = _a.preventRightClick,
2069
+ preventDefault = _a.preventDefault,
2070
+ checkInput = _a.checkInput;
2071
+ var isTouch = _this.isTouch;
2072
+ var isDragStart = !_this.flag;
2073
+
2074
+ if (isDragStart) {
2075
+ var activeElement = document.activeElement;
2076
+ var target = e.target;
2077
+ var tagName = target.tagName.toLowerCase();
2078
+ var hasInput = INPUT_TAGNAMES.indexOf(tagName) > -1;
2079
+ var hasContentEditable = target.isContentEditable;
2080
+
2081
+ if (hasInput || hasContentEditable) {
2082
+ if (checkInput || activeElement === target) {
2083
+ // force false or already focused.
2084
+ return false;
2085
+ }
2086
+
2087
+ if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2088
+ return false;
2089
+ }
2090
+ } else if ((preventDefault || e.type === "touchstart") && activeElement) {
2091
+ var activeTagName = activeElement.tagName;
2092
+
2093
+ if (activeElement.isContentEditable || INPUT_TAGNAMES.indexOf(activeTagName) > -1) {
2094
+ activeElement.blur();
2095
+ }
2096
+ }
2097
+
2098
+ _this.clientStores = [new ClientStore(getEventClients(e))];
2099
+ _this.flag = true;
2100
+ _this.isDrag = false;
2101
+ _this.datas = {};
2102
+
2103
+ if (preventRightClick && (e.which === 3 || e.button === 2)) {
2104
+ _this.initDrag();
2105
+
2106
+ return false;
2107
+ }
2108
+
2109
+ _this.doubleFlag = now() - _this.prevTime < 200;
2110
+
2111
+ var result = _this.emit("dragStart", __assign({
2112
+ datas: _this.datas,
2113
+ inputEvent: e,
2114
+ isTrusted: isTrusted,
2115
+ isDouble: _this.doubleFlag
2116
+ }, _this.getCurrentStore().getPosition()));
2117
+
2118
+ if (result === false) {
2119
+ _this.initDrag();
2120
+ }
2121
+
2122
+ _this.flag && preventDefault && e.preventDefault();
2123
+ }
2124
+
2125
+ if (!_this.flag) {
2126
+ return false;
2127
+ }
2128
+
2129
+ var timer = 0;
2130
+
2131
+ if (isDragStart && isTouch && pinchOutside) {
2132
+ timer = setTimeout(function () {
2133
+ addEvent(container, "touchstart", _this.onDragStart, {
2134
+ passive: false
2135
+ });
2136
+ });
2137
+ }
2138
+
2139
+ if (!isDragStart && isTouch && pinchOutside) {
2140
+ removeEvent(container, "touchstart", _this.onDragStart);
2141
+ }
2142
+
2143
+ if (_this.flag && isMultiTouch(e)) {
2144
+ clearTimeout(timer);
2145
+
2146
+ if (isDragStart && e.touches.length !== e.changedTouches.length) {
2147
+ return;
2148
+ }
2149
+
2150
+ if (!_this.pinchFlag) {
2151
+ _this.onPinchStart(e);
2152
+ }
2153
+ }
2154
+ };
2155
+
2156
+ _this.onDrag = function (e, isScroll) {
2157
+ if (!_this.flag) {
2158
+ return;
2159
+ }
2160
+
2161
+ var clients = getEventClients(e);
2162
+
2163
+ var result = _this.moveClients(clients, e, false);
2164
+
2165
+ if (_this.pinchFlag || result.deltaX || result.deltaY) {
2166
+ var dragResult = _this.emit("drag", __assign({}, result, {
2167
+ isScroll: !!isScroll,
2168
+ inputEvent: e
2169
+ }));
2170
+
2171
+ if (dragResult === false) {
2172
+ _this.stop();
2173
+
2174
+ return;
2175
+ }
2176
+ }
2177
+
2178
+ if (_this.pinchFlag) {
2179
+ _this.onPinch(e, clients);
2180
+ }
2181
+
2182
+ _this.getCurrentStore().addClients(clients);
2183
+ };
2184
+
2185
+ _this.onDragEnd = function (e) {
2186
+ if (!_this.flag) {
2187
+ return;
2188
+ }
2189
+
2190
+ var _a = _this.options,
2191
+ pinchOutside = _a.pinchOutside,
2192
+ container = _a.container;
2193
+
2194
+ if (_this.isTouch && pinchOutside) {
2195
+ removeEvent(container, "touchstart", _this.onDragStart);
2196
+ }
2197
+
2198
+ _this.flag = false;
2199
+
2200
+ var position = _this.getCurrentStore().getPosition();
2201
+
2202
+ var currentTime = now();
2203
+ var isDouble = !_this.isDrag && _this.doubleFlag;
2204
+ _this.prevTime = _this.isDrag || isDouble ? 0 : currentTime;
2205
+
2206
+ _this.emit("dragEnd", __assign({
2207
+ datas: _this.datas,
2208
+ isDouble: isDouble,
2209
+ isDrag: _this.isDrag,
2210
+ isClick: !_this.isDrag,
2211
+ inputEvent: e
2212
+ }, position));
2213
+
2214
+ if (_this.pinchFlag) {
2215
+ _this.onPinchEnd(e);
2216
+ }
2217
+
2218
+ _this.clientStores = [];
2219
+ };
2220
+
2221
+ _this.onBlur = function () {
2222
+ _this.onDragEnd();
2223
+ };
2224
+
2225
+ var elements = [].concat(targets);
2226
+ _this.options = __assign({
2227
+ checkInput: false,
2228
+ container: elements.length > 1 ? window : elements[0],
2229
+ preventRightClick: true,
2230
+ preventDefault: true,
2231
+ checkWindowBlur: false,
2232
+ pinchThreshold: 0,
2233
+ events: ["touch", "mouse"]
2234
+ }, options);
2235
+ var _a = _this.options,
2236
+ container = _a.container,
2237
+ events = _a.events,
2238
+ checkWindowBlur = _a.checkWindowBlur;
2239
+ _this.isTouch = events.indexOf("touch") > -1;
2240
+ _this.isMouse = events.indexOf("mouse") > -1;
2241
+ _this.targets = elements;
2242
+
2243
+ if (_this.isMouse) {
2244
+ elements.forEach(function (el) {
2245
+ addEvent(el, "mousedown", _this.onDragStart);
2246
+ });
2247
+ addEvent(container, "mousemove", _this.onDrag);
2248
+ addEvent(container, "mouseup", _this.onDragEnd);
2249
+ addEvent(container, "contextmenu", _this.onDragEnd);
2250
+ }
2251
+
2252
+ if (checkWindowBlur) {
2253
+ addEvent(window, "blur", _this.onBlur);
2254
+ }
2255
+
2256
+ if (_this.isTouch) {
2257
+ var passive_1 = {
2258
+ passive: false
2259
+ };
2260
+ elements.forEach(function (el) {
2261
+ addEvent(el, "touchstart", _this.onDragStart, passive_1);
2262
+ });
2263
+ addEvent(container, "touchmove", _this.onDrag, passive_1);
2264
+ addEvent(container, "touchend", _this.onDragEnd, passive_1);
2265
+ addEvent(container, "touchcancel", _this.onDragEnd, passive_1);
2266
+ }
2267
+
2268
+ return _this;
2269
+ }
2270
+ /**
2271
+ * Stop Gesto's drag events.
2272
+ */
2273
+
2274
+
2275
+ var __proto = Gesto.prototype;
2276
+
2277
+ __proto.stop = function () {
2278
+ this.isDrag = false;
2279
+ this.flag = false;
2280
+ this.clientStores = [];
2281
+ this.datas = {};
2282
+ };
2283
+ /**
2284
+ * The total moved distance
2285
+ */
2286
+
2287
+
2288
+ __proto.getMovement = function (clients) {
2289
+ return this.getCurrentStore().getMovement(clients) + this.clientStores.slice(1).reduce(function (prev, cur) {
2290
+ return prev + cur.movement;
2291
+ }, 0);
2292
+ };
2293
+ /**
2294
+ * Whether to drag
2295
+ */
2296
+
2297
+
2298
+ __proto.isDragging = function () {
2299
+ return this.isDrag;
2300
+ };
2301
+ /**
2302
+ * Whether to start drag
2303
+ */
2304
+
2305
+
2306
+ __proto.isFlag = function () {
2307
+ return this.flag;
2308
+ };
2309
+ /**
2310
+ * Whether to start pinch
2311
+ */
2312
+
2313
+
2314
+ __proto.isPinchFlag = function () {
2315
+ return this.pinchFlag;
2316
+ };
2317
+ /**
2318
+ * Whether to start double click
2319
+ */
2320
+
2321
+
2322
+ __proto.isDoubleFlag = function () {
2323
+ return this.doubleFlag;
2324
+ };
2325
+ /**
2326
+ * Whether to pinch
2327
+ */
2328
+
2329
+
2330
+ __proto.isPinching = function () {
2331
+ return this.isPinch;
2332
+ };
2333
+ /**
2334
+ * If a scroll event occurs, it is corrected by the scroll distance.
2335
+ */
2336
+
2337
+
2338
+ __proto.scrollBy = function (deltaX, deltaY, e, isCallDrag) {
2339
+ if (isCallDrag === void 0) {
2340
+ isCallDrag = true;
2341
+ }
2342
+
2343
+ if (!this.flag) {
2344
+ return;
2345
+ }
2346
+
2347
+ this.clientStores[0].move(deltaX, deltaY);
2348
+ isCallDrag && this.onDrag(e, true);
2349
+ };
2350
+ /**
2351
+ * Create a virtual drag event.
2352
+ */
2353
+
2354
+
2355
+ __proto.move = function (_a, inputEvent) {
2356
+ var deltaX = _a[0],
2357
+ deltaY = _a[1];
2358
+ var store = this.getCurrentStore();
2359
+ var nextClients = store.prevClients;
2360
+ return this.moveClients(nextClients.map(function (_a) {
2361
+ var clientX = _a.clientX,
2362
+ clientY = _a.clientY;
2363
+ return {
2364
+ clientX: clientX + deltaX,
2365
+ clientY: clientY + deltaY,
2366
+ originalClientX: clientX,
2367
+ originalClientY: clientY
2368
+ };
2369
+ }), inputEvent, true);
2370
+ };
2371
+ /**
2372
+ * The dragStart event is triggered by an external event.
2373
+ */
2374
+
2375
+
2376
+ __proto.triggerDragStart = function (e) {
2377
+ this.onDragStart(e, false);
2378
+ };
2379
+ /**
2380
+ * Set the event data while dragging.
2381
+ */
2382
+
2383
+
2384
+ __proto.setEventDatas = function (datas) {
2385
+ var currentDatas = this.datas;
2386
+
2387
+ for (var name in datas) {
2388
+ currentDatas[name] = datas[name];
2389
+ }
2390
+
2391
+ return this;
2392
+ };
2393
+ /**
2394
+ * Set the event data while dragging.
2395
+ */
2396
+
2397
+
2398
+ __proto.getEventDatas = function () {
2399
+ return this.datas;
2400
+ };
2401
+ /**
2402
+ * Unset Gesto
2403
+ */
2404
+
2405
+
2406
+ __proto.unset = function () {
2407
+ var _this = this;
2408
+
2409
+ var targets = this.targets;
2410
+ var container = this.options.container;
2411
+ this.off();
2412
+ removeEvent(window, "blur", this.onBlur);
2413
+
2414
+ if (this.isMouse) {
2415
+ targets.forEach(function (target) {
2416
+ removeEvent(target, "mousedown", _this.onDragStart);
2417
+ });
2418
+ removeEvent(container, "mousemove", this.onDrag);
2419
+ removeEvent(container, "mouseup", this.onDragEnd);
2420
+ removeEvent(container, "contextmenu", this.onDragEnd);
2421
+ }
2422
+
2423
+ if (this.isTouch) {
2424
+ targets.forEach(function (target) {
2425
+ removeEvent(target, "touchstart", _this.onDragStart);
2426
+ });
2427
+ removeEvent(container, "touchstart", this.onDragStart);
2428
+ removeEvent(container, "touchmove", this.onDrag);
2429
+ removeEvent(container, "touchend", this.onDragEnd);
2430
+ removeEvent(container, "touchcancel", this.onDragEnd);
2431
+ }
2432
+ };
2433
+
2434
+ __proto.onPinchStart = function (e) {
2435
+ var pinchThreshold = this.options.pinchThreshold;
2436
+
2437
+ if (this.isDrag && this.getMovement() > pinchThreshold) {
2438
+ return;
2439
+ }
2440
+
2441
+ var store = new ClientStore(getEventClients(e));
2442
+ this.pinchFlag = true;
2443
+ this.clientStores.splice(0, 0, store);
2444
+ var result = this.emit("pinchStart", __assign({
2445
+ datas: this.datas,
2446
+ angle: store.getAngle(),
2447
+ touches: this.getCurrentStore().getPositions()
2448
+ }, store.getPosition(), {
2449
+ inputEvent: e
2450
+ }));
2451
+
2452
+ if (result === false) {
2453
+ this.pinchFlag = false;
2454
+ }
2455
+ };
2456
+
2457
+ __proto.onPinch = function (e, clients) {
2458
+ if (!this.flag || !this.pinchFlag || clients.length < 2) {
2459
+ return;
2460
+ }
2461
+
2462
+ var store = this.getCurrentStore();
2463
+ this.isPinch = true;
2464
+ this.emit("pinch", __assign({
2465
+ datas: this.datas,
2466
+ movement: this.getMovement(clients),
2467
+ angle: store.getAngle(clients),
2468
+ rotation: store.getRotation(clients),
2469
+ touches: store.getPositions(clients),
2470
+ scale: store.getScale(clients),
2471
+ distance: store.getDistance(clients)
2472
+ }, store.getPosition(clients), {
2473
+ inputEvent: e
2474
+ }));
2475
+ };
2476
+
2477
+ __proto.onPinchEnd = function (e) {
2478
+ if (!this.pinchFlag) {
2479
+ return;
2480
+ }
2481
+
2482
+ var isPinch = this.isPinch;
2483
+ this.isPinch = false;
2484
+ this.pinchFlag = false;
2485
+ var store = this.getCurrentStore();
2486
+ this.emit("pinchEnd", __assign({
2487
+ datas: this.datas,
2488
+ isPinch: isPinch,
2489
+ touches: store.getPositions()
2490
+ }, store.getPosition(), {
2491
+ inputEvent: e
2492
+ }));
2493
+ this.isPinch = false;
2494
+ this.pinchFlag = false;
2495
+ };
2496
+
2497
+ __proto.initDrag = function () {
2498
+ this.clientStores = [];
2499
+ this.pinchFlag = false;
2500
+ this.doubleFlag = false;
2501
+ this.prevTime = 0;
2502
+ this.flag = false;
2503
+ };
2504
+
2505
+ __proto.getCurrentStore = function () {
2506
+ return this.clientStores[0];
2507
+ };
2508
+
2509
+ __proto.moveClients = function (clients, inputEvent, isAdd) {
2510
+ var store = this.getCurrentStore();
2511
+ var position = store[isAdd ? "addClients" : "getPosition"](clients);
2512
+ this.isDrag = true;
2513
+ return __assign({
2514
+ datas: this.datas
2515
+ }, position, {
2516
+ movement: this.getMovement(clients),
2517
+ isDrag: this.isDrag,
2518
+ isPinch: this.isPinch,
2519
+ isScroll: false,
2520
+ inputEvent: inputEvent
2521
+ });
2522
+ };
2523
+
2524
+ return Gesto;
2525
+ }(EventEmitter$1);
2526
+
2527
+ var Gesto$1 = Gesto;
2528
+
2529
+ const _sfc_main$e = defineComponent({
2530
+ name: "m-editor-resize",
2531
+ props: {
2532
+ type: {
2533
+ type: String
2534
+ }
2535
+ },
2536
+ setup(props) {
2537
+ const services = inject("services");
2538
+ const target = ref();
2539
+ let getso;
2540
+ onMounted(() => {
2541
+ if (!target.value)
2542
+ return;
2543
+ getso = new Gesto$1(target.value, {
2544
+ container: window,
2545
+ pinchOutside: true
2546
+ }).on("drag", (e) => {
2547
+ if (!target.value || !services)
2548
+ return;
2549
+ let { left, right } = {
2550
+ ...toRaw(services.uiService.get("columnWidth"))
2551
+ };
2552
+ if (props.type === "left") {
2553
+ left += e.deltaX;
2554
+ } else if (props.type === "right") {
2555
+ right -= e.deltaX;
2556
+ }
2557
+ services.uiService.set("columnWidth", {
2558
+ left,
2559
+ right
2560
+ });
2561
+ });
2562
+ });
2563
+ onUnmounted(() => {
2564
+ getso?.unset();
2565
+ });
2566
+ return {
2567
+ target
2568
+ };
2569
+ }
2570
+ });
2571
+ const _hoisted_1$a = {
2572
+ ref: "target",
2573
+ class: "m-editor-resizer"
2574
+ };
2575
+ function _sfc_render$e(_ctx, _cache, $props, $setup, $data, $options) {
2576
+ return openBlock(), createElementBlock("span", _hoisted_1$a, [
2577
+ renderSlot(_ctx.$slots, "default")
2578
+ ], 512);
2579
+ }
2580
+ var Resizer = /* @__PURE__ */ _export_sfc(_sfc_main$e, [["render", _sfc_render$e]]);
2581
+
2582
+ const _sfc_main$d = defineComponent({
2583
+ components: {
2584
+ AddPageBox,
2585
+ Resizer
2586
+ },
2587
+ setup() {
2588
+ const services = inject("services");
2589
+ const root = computed(() => services?.editorService.get("root"));
2590
+ return {
2591
+ root,
2592
+ pageLength: computed(() => root.value?.items?.length || 0),
2593
+ showSrc: computed(() => services?.uiService.get("showSrc")),
2594
+ columnWidth: computed(() => services?.uiService.get("columnWidth")),
2595
+ saveCode(value) {
2596
+ try {
2597
+ services?.editorService.set("root", eval(value));
2598
+ } catch (e) {
2599
+ console.error(e);
2600
+ }
2601
+ }
2602
+ };
2603
+ }
2604
+ });
2605
+ const _hoisted_1$9 = { class: "m-editor" };
2606
+ const _hoisted_2$5 = {
2607
+ key: 1,
2608
+ class: "m-editor-content"
2609
+ };
2610
+ function _sfc_render$d(_ctx, _cache, $props, $setup, $data, $options) {
2611
+ const _component_magic_code_editor = resolveComponent("magic-code-editor");
2612
+ const _component_resizer = resolveComponent("resizer");
2613
+ const _component_el_scrollbar = resolveComponent("el-scrollbar");
2614
+ const _component_add_page_box = resolveComponent("add-page-box");
2615
+ return openBlock(), createElementBlock("div", _hoisted_1$9, [
2616
+ renderSlot(_ctx.$slots, "nav", { class: "m-editor-nav-menu" }),
2617
+ _ctx.showSrc ? (openBlock(), createBlock(_component_magic_code_editor, {
2618
+ key: 0,
2619
+ class: "m-editor-content",
2620
+ "init-values": _ctx.root,
2621
+ onSave: _ctx.saveCode
2622
+ }, null, 8, ["init-values", "onSave"])) : (openBlock(), createElementBlock("div", _hoisted_2$5, [
2623
+ createElementVNode("div", {
2624
+ class: "m-editor-framework-left",
2625
+ style: normalizeStyle(`width: ${_ctx.columnWidth?.left}px`)
2626
+ }, [
2627
+ renderSlot(_ctx.$slots, "sidebar")
2628
+ ], 4),
2629
+ createVNode(_component_resizer, { type: "left" }),
2630
+ _ctx.pageLength > 0 ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
2631
+ createElementVNode("div", {
2632
+ class: "m-editor-framework-center",
2633
+ style: normalizeStyle(`width: ${_ctx.columnWidth?.center}px`)
2634
+ }, [
2635
+ renderSlot(_ctx.$slots, "workspace")
2636
+ ], 4),
2637
+ createVNode(_component_resizer, { type: "right" }),
2638
+ createElementVNode("div", {
2639
+ class: "m-editor-framework-right",
2640
+ style: normalizeStyle(`width: ${_ctx.columnWidth?.right}px`)
2641
+ }, [
2642
+ createVNode(_component_el_scrollbar, null, {
2643
+ default: withCtx(() => [
2644
+ renderSlot(_ctx.$slots, "propsPanel")
2645
+ ]),
2646
+ _: 3
2647
+ })
2648
+ ], 4)
2649
+ ], 64)) : renderSlot(_ctx.$slots, "empty", { key: 1 }, () => [
2650
+ createVNode(_component_add_page_box)
2651
+ ])
2652
+ ]))
2653
+ ]);
2654
+ }
2655
+ var Framework = /* @__PURE__ */ _export_sfc(_sfc_main$d, [["render", _sfc_render$d]]);
2656
+
2657
+ const _sfc_main$c = defineComponent({
2658
+ name: "m-icon",
2659
+ components: { Edit },
2660
+ props: {
2661
+ icon: {
2662
+ type: [String, Object]
2663
+ }
2664
+ },
2665
+ setup() {
2666
+ return {
2667
+ toRaw
2668
+ };
2669
+ }
2670
+ });
2671
+ const _hoisted_1$8 = ["src"];
2672
+ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
2673
+ const _component_edit = resolveComponent("edit");
2674
+ const _component_el_icon = resolveComponent("el-icon");
2675
+ return !_ctx.icon ? (openBlock(), createBlock(_component_el_icon, { key: 0 }, {
2676
+ default: withCtx(() => [
2677
+ createVNode(_component_edit)
2678
+ ]),
2679
+ _: 1
2680
+ })) : typeof _ctx.icon === "string" && _ctx.icon.startsWith("http") ? (openBlock(), createElementBlock("img", {
2681
+ key: 1,
2682
+ src: _ctx.icon
2683
+ }, null, 8, _hoisted_1$8)) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
2684
+ key: 2,
2685
+ class: normalizeClass(_ctx.icon)
2686
+ }, null, 2)) : (openBlock(), createBlock(_component_el_icon, { key: 3 }, {
2687
+ default: withCtx(() => [
2688
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.toRaw(_ctx.icon))))
2689
+ ]),
2690
+ _: 1
2691
+ }));
2692
+ }
2693
+ var MIcon = /* @__PURE__ */ _export_sfc(_sfc_main$c, [["render", _sfc_render$c]]);
2694
+
2695
+ const _sfc_main$b = defineComponent({
2696
+ components: { MIcon, ArrowDown },
2697
+ props: {
2698
+ data: {
2699
+ type: [Object, String],
2700
+ require: true,
2701
+ default: () => ({
2702
+ type: "text",
2703
+ display: false
2704
+ })
2705
+ }
2706
+ },
2707
+ setup(props) {
2708
+ const services = inject("services");
2709
+ const uiService = services?.uiService;
2710
+ const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2711
+ const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2712
+ const zoom = computed(() => uiService?.get("zoom") ?? 1);
2713
+ const showGuides = computed(() => uiService?.get("showGuides") ?? true);
2714
+ const showRule = computed(() => uiService?.get("showRule") ?? true);
2715
+ const item = computed(() => {
2716
+ if (typeof props.data !== "string") {
2717
+ return props.data;
2718
+ }
2719
+ switch (props.data) {
2720
+ case "/":
2721
+ return {
2722
+ type: "divider"
2723
+ };
2724
+ case "zoom":
2725
+ return {
2726
+ type: "zoom"
2727
+ };
2728
+ case "delete":
2729
+ return {
2730
+ type: "button",
2731
+ icon: Delete,
2732
+ tooltip: "\u522A\u9664",
2733
+ disabled: () => services?.editorService.get("node")?.type === "page",
2734
+ handler: () => services?.editorService.remove(services?.editorService.get("node"))
2735
+ };
2736
+ case "undo":
2737
+ return {
2738
+ type: "button",
2739
+ icon: Back,
2740
+ tooltip: "\u540E\u9000",
2741
+ disabled: () => !services?.historyService.state.canUndo,
2742
+ handler: () => services?.editorService.undo()
2743
+ };
2744
+ case "redo":
2745
+ return {
2746
+ type: "button",
2747
+ icon: Right,
2748
+ tooltip: "\u524D\u8FDB",
2749
+ disabled: () => !services?.historyService.state.canRedo,
2750
+ handler: () => services?.editorService.redo()
2751
+ };
2752
+ case "zoom-in":
2753
+ return {
2754
+ type: "button",
2755
+ icon: ZoomIn,
2756
+ tooltip: "\u653E\u5927",
2757
+ handler: zoomInHandler
2758
+ };
2759
+ case "zoom-out":
2760
+ return {
2761
+ type: "button",
2762
+ icon: ZoomOut,
2763
+ tooltip: "\u7E2E\u5C0F",
2764
+ handler: zoomOutHandler
2765
+ };
2766
+ case "rule":
2767
+ return {
2768
+ type: "button",
2769
+ icon: ScaleToOriginal,
2770
+ tooltip: showRule.value ? "\u9690\u85CF\u6807\u5C3A" : "\u663E\u793A\u6807\u5C3A",
2771
+ handler: () => uiService?.set("showRule", !showRule.value)
2772
+ };
2773
+ case "guides":
2774
+ return {
2775
+ type: "button",
2776
+ icon: Grid,
2777
+ tooltip: showGuides.value ? "\u9690\u85CF\u53C2\u8003\u7EBF" : "\u663E\u793A\u53C2\u8003\u7EBF",
2778
+ handler: () => uiService?.set("showGuides", !showGuides.value)
2779
+ };
2780
+ default:
2781
+ return {
2782
+ type: "text",
2783
+ text: props.data
2784
+ };
2785
+ }
2786
+ });
2787
+ const disabled = computed(() => {
2788
+ if (typeof item.value === "string")
2789
+ return false;
2790
+ if (item.value.type === "component")
2791
+ return false;
2792
+ if (typeof item.value.disabled === "function") {
2793
+ return item.value.disabled(services);
2794
+ }
2795
+ return item.value.disabled;
2796
+ });
2797
+ return {
2798
+ ZoomIn,
2799
+ ZoomOut,
2800
+ item,
2801
+ zoom,
2802
+ disabled,
2803
+ display: computed(() => {
2804
+ if (!item.value)
2805
+ return false;
2806
+ if (typeof item.value === "string")
2807
+ return true;
2808
+ if (typeof item.value.display === "function") {
2809
+ return item.value.display(services);
2810
+ }
2811
+ return item.value.display ?? true;
2812
+ }),
2813
+ zoomInHandler,
2814
+ zoomOutHandler,
2815
+ dropdownHandler(command) {
2816
+ if (command.item.handler) {
2817
+ command.item.handler(services);
2818
+ }
2819
+ },
2820
+ buttonHandler(item2) {
2821
+ if (disabled.value)
2822
+ return;
2823
+ if (typeof item2.handler === "function") {
2824
+ item2.handler?.(services);
2825
+ }
2826
+ }
2827
+ };
2828
+ }
2829
+ });
2830
+ const _hoisted_1$7 = {
2831
+ key: 0,
2832
+ class: "menu-item"
2833
+ };
2834
+ const _hoisted_2$4 = {
2835
+ key: 1,
2836
+ class: "menu-item-text"
2837
+ };
2838
+ const _hoisted_3$3 = {
2839
+ class: "menu-item-text",
2840
+ style: { "margin": "0 5px" }
2841
+ };
2842
+ const _hoisted_4$3 = { class: "el-dropdown-link menubar-menu-button" };
2843
+ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
2844
+ const _component_el_divider = resolveComponent("el-divider");
2845
+ const _component_m_icon = resolveComponent("m-icon");
2846
+ const _component_el_button = resolveComponent("el-button");
2847
+ const _component_el_tooltip = resolveComponent("el-tooltip");
2848
+ const _component_arrow_down = resolveComponent("arrow-down");
2849
+ const _component_el_icon = resolveComponent("el-icon");
2850
+ const _component_el_dropdown_item = resolveComponent("el-dropdown-item");
2851
+ const _component_el_dropdown_menu = resolveComponent("el-dropdown-menu");
2852
+ const _component_el_dropdown = resolveComponent("el-dropdown");
2853
+ return _ctx.display ? (openBlock(), createElementBlock("div", _hoisted_1$7, [
2854
+ _ctx.item.type === "divider" ? (openBlock(), createBlock(_component_el_divider, {
2855
+ key: 0,
2856
+ direction: "vertical"
2857
+ })) : _ctx.item.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_2$4, toDisplayString(_ctx.item.text), 1)) : _ctx.item.type === "zoom" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
2858
+ createVNode(_component_m_icon, {
2859
+ icon: _ctx.ZoomIn,
2860
+ onClick: _ctx.zoomInHandler
2861
+ }, null, 8, ["icon", "onClick"]),
2862
+ createElementVNode("span", _hoisted_3$3, toDisplayString(parseInt(`${_ctx.zoom * 100}`, 10)) + "%", 1),
2863
+ createVNode(_component_m_icon, {
2864
+ icon: _ctx.ZoomOut,
2865
+ onClick: _ctx.zoomOutHandler
2866
+ }, null, 8, ["icon", "onClick"])
2867
+ ], 64)) : _ctx.item.type === "button" ? (openBlock(), createBlock(_component_el_tooltip, {
2868
+ key: 3,
2869
+ effect: "dark",
2870
+ placement: "bottom-start",
2871
+ content: _ctx.item.tooltip || _ctx.item.text
2872
+ }, {
2873
+ default: withCtx(() => [
2874
+ createVNode(_component_el_button, {
2875
+ size: "small",
2876
+ type: "text",
2877
+ disabled: _ctx.disabled,
2878
+ onClick: _cache[0] || (_cache[0] = ($event) => _ctx.buttonHandler(_ctx.item))
2879
+ }, {
2880
+ default: withCtx(() => [
2881
+ createVNode(_component_m_icon, {
2882
+ icon: _ctx.item.icon
2883
+ }, null, 8, ["icon"]),
2884
+ createElementVNode("span", null, toDisplayString(_ctx.item.text), 1)
2885
+ ]),
2886
+ _: 1
2887
+ }, 8, ["disabled"])
2888
+ ]),
2889
+ _: 1
2890
+ }, 8, ["content"])) : _ctx.item.type === "dropdown" ? (openBlock(), createBlock(_component_el_dropdown, {
2891
+ key: 4,
2892
+ trigger: "click",
2893
+ disabled: _ctx.disabled,
2894
+ onCommand: _ctx.dropdownHandler
2895
+ }, {
2896
+ dropdown: withCtx(() => [
2897
+ _ctx.item.items && _ctx.item.items.length ? (openBlock(), createBlock(_component_el_dropdown_menu, { key: 0 }, {
2898
+ default: withCtx(() => [
2899
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.item.items, (subItem, index) => {
2900
+ return openBlock(), createBlock(_component_el_dropdown_item, {
2901
+ key: index,
2902
+ command: { item: _ctx.item, subItem }
2903
+ }, {
2904
+ default: withCtx(() => [
2905
+ createTextVNode(toDisplayString(subItem.text), 1)
2906
+ ]),
2907
+ _: 2
2908
+ }, 1032, ["command"]);
2909
+ }), 128))
2910
+ ]),
2911
+ _: 1
2912
+ })) : createCommentVNode("", true)
2913
+ ]),
2914
+ default: withCtx(() => [
2915
+ createElementVNode("span", _hoisted_4$3, [
2916
+ createTextVNode(toDisplayString(_ctx.item.text), 1),
2917
+ createVNode(_component_el_icon, { class: "el-icon--right" }, {
2918
+ default: withCtx(() => [
2919
+ createVNode(_component_arrow_down)
2920
+ ]),
2921
+ _: 1
2922
+ })
2923
+ ])
2924
+ ]),
2925
+ _: 1
2926
+ }, 8, ["disabled", "onCommand"])) : _ctx.item.type === "component" ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.item.component), normalizeProps(mergeProps({ key: 5 }, _ctx.item.props || {})), null, 16)) : createCommentVNode("", true)
2927
+ ])) : createCommentVNode("", true);
2928
+ }
2929
+ var ToolButton = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
2930
+
2931
+ const _sfc_main$a = defineComponent({
2932
+ name: "nav-menu",
2933
+ components: { ToolButton },
2934
+ props: {
2935
+ data: {
2936
+ type: Object,
2937
+ default: () => ({})
2938
+ },
2939
+ height: {
2940
+ type: Number
2941
+ }
2942
+ },
2943
+ setup(props) {
2944
+ return {
2945
+ keys: computed(() => Object.keys(props.data))
2946
+ };
2947
+ }
2948
+ });
2949
+ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2950
+ const _component_tool_button = resolveComponent("tool-button");
2951
+ return openBlock(), createElementBlock("div", {
2952
+ class: "m-editor-nav-menu",
2953
+ style: normalizeStyle({ height: `${_ctx.height}px` })
2954
+ }, [
2955
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.keys, (key) => {
2956
+ return openBlock(), createElementBlock("div", {
2957
+ class: normalizeClass(`menu-${key}`),
2958
+ key
2959
+ }, [
2960
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.data[key], (item, index) => {
2961
+ return openBlock(), createBlock(_component_tool_button, {
2962
+ data: item,
2963
+ key: index
2964
+ }, null, 8, ["data"]);
2965
+ }), 128))
2966
+ ], 2);
2967
+ }), 128))
2968
+ ], 4);
2969
+ }
2970
+ var NavMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2971
+
2972
+ const _sfc_main$9 = defineComponent({
2973
+ name: "m-editor-props-panel",
2974
+ emits: ["mounted"],
2975
+ setup(props, { emit }) {
2976
+ const internalInstance = getCurrentInstance();
2977
+ const values = ref({});
2978
+ const configForm = ref();
2979
+ const curFormConfig = ref([]);
2980
+ const services = inject("services");
2981
+ const init = async () => {
2982
+ const node = services?.editorService.get("node");
2983
+ if (!node) {
2984
+ curFormConfig.value = [];
2985
+ return;
2986
+ }
2987
+ if (node.devconfig && node.style && !isNaN(+node.style.height) && !isNaN(+node.style.width)) {
2988
+ node.devconfig.ratio = node.style.height / node.style.width || 1;
2989
+ }
2990
+ values.value = node;
2991
+ const type = node.type || (node.items ? "container" : "text");
2992
+ curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
2993
+ };
2994
+ watchEffect(init);
2995
+ services?.propsService.on("props-configs-change", init);
2996
+ onMounted(() => {
2997
+ emit("mounted", internalInstance);
2998
+ });
2999
+ return {
3000
+ values,
3001
+ configForm,
3002
+ curFormConfig,
3003
+ async submit() {
3004
+ try {
3005
+ const values2 = await configForm.value?.submitForm();
3006
+ services?.editorService.update(values2);
3007
+ } catch (e) {
3008
+ console.error(e);
3009
+ ElMessage.closeAll();
3010
+ ElMessage.error({
3011
+ duration: 1e4,
3012
+ showClose: true,
3013
+ message: e.message,
3014
+ dangerouslyUseHTMLString: true
3015
+ });
3016
+ }
3017
+ }
3018
+ };
3019
+ }
3020
+ });
3021
+ function _sfc_render$9(_ctx, _cache, $props, $setup, $data, $options) {
3022
+ const _component_m_form = resolveComponent("m-form");
3023
+ return openBlock(), createBlock(_component_m_form, {
3024
+ class: "m-editor-props-panel",
3025
+ ref: "configForm",
3026
+ size: "small",
3027
+ "init-values": _ctx.values,
3028
+ config: _ctx.curFormConfig,
3029
+ onChange: _ctx.submit
3030
+ }, null, 8, ["init-values", "config", "onChange"]);
3031
+ }
3032
+ var PropsPanel = /* @__PURE__ */ _export_sfc(_sfc_main$9, [["render", _sfc_render$9]]);
3033
+
3034
+ const _sfc_main$8 = defineComponent({
3035
+ name: "ui-component-panel",
3036
+ components: { MIcon },
3037
+ setup() {
3038
+ const searchText = ref("");
3039
+ const services = inject("services");
3040
+ const list = computed(() => services?.componentListService.getList().map((group) => ({
3041
+ ...group,
3042
+ items: group.items.filter((item) => item.text.includes(searchText.value))
3043
+ })));
3044
+ const collapseValue = computed(() => Array(list.value?.length).fill(1).map((x, i) => i));
3045
+ return {
3046
+ searchText,
3047
+ collapseValue,
3048
+ list,
3049
+ appendComponent({ text, type, ...config }) {
3050
+ services?.editorService.add({
3051
+ name: text,
3052
+ type,
3053
+ ...config
3054
+ });
3055
+ }
3056
+ };
3057
+ }
3058
+ });
3059
+ const _hoisted_1$6 = /* @__PURE__ */ createElementVNode("i", { class: "el-icon-s-grid" }, null, -1);
3060
+ const _hoisted_2$3 = ["onClick"];
3061
+ function _sfc_render$8(_ctx, _cache, $props, $setup, $data, $options) {
3062
+ const _component_el_input = resolveComponent("el-input");
3063
+ const _component_m_icon = resolveComponent("m-icon");
3064
+ const _component_el_tooltip = resolveComponent("el-tooltip");
3065
+ const _component_el_collapse_item = resolveComponent("el-collapse-item");
3066
+ const _component_el_collapse = resolveComponent("el-collapse");
3067
+ const _component_el_scrollbar = resolveComponent("el-scrollbar");
3068
+ return openBlock(), createBlock(_component_el_scrollbar, null, {
3069
+ default: withCtx(() => [
3070
+ createVNode(_component_el_collapse, {
3071
+ class: "ui-component-panel",
3072
+ "model-value": _ctx.collapseValue
3073
+ }, {
3074
+ default: withCtx(() => [
3075
+ createVNode(_component_el_input, {
3076
+ "prefix-icon": "el-icon-search",
3077
+ placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3078
+ class: "search-input",
3079
+ size: "small",
3080
+ clearable: "",
3081
+ modelValue: _ctx.searchText,
3082
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.searchText = $event)
3083
+ }, null, 8, ["modelValue"]),
3084
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.list, (group, index) => {
3085
+ return openBlock(), createElementBlock(Fragment, null, [
3086
+ group.items && group.items.length ? (openBlock(), createBlock(_component_el_collapse_item, {
3087
+ key: index,
3088
+ name: index
3089
+ }, {
3090
+ title: withCtx(() => [
3091
+ _hoisted_1$6,
3092
+ createTextVNode(toDisplayString(group.title), 1)
3093
+ ]),
3094
+ default: withCtx(() => [
3095
+ (openBlock(true), createElementBlock(Fragment, null, renderList(group.items, (item) => {
3096
+ return openBlock(), createElementBlock("div", {
3097
+ class: "component-item",
3098
+ key: item.type,
3099
+ onClick: ($event) => _ctx.appendComponent(item)
3100
+ }, [
3101
+ createVNode(_component_m_icon, {
3102
+ icon: item.icon
3103
+ }, null, 8, ["icon"]),
3104
+ createVNode(_component_el_tooltip, {
3105
+ effect: "dark",
3106
+ placement: "bottom",
3107
+ content: item.text
3108
+ }, {
3109
+ default: withCtx(() => [
3110
+ createElementVNode("span", null, toDisplayString(item.text), 1)
3111
+ ]),
3112
+ _: 2
3113
+ }, 1032, ["content"])
3114
+ ], 8, _hoisted_2$3);
3115
+ }), 128))
3116
+ ]),
3117
+ _: 2
3118
+ }, 1032, ["name"])) : createCommentVNode("", true)
3119
+ ], 64);
3120
+ }), 256))
3121
+ ]),
3122
+ _: 1
3123
+ }, 8, ["model-value"])
3124
+ ]),
3125
+ _: 1
3126
+ });
3127
+ }
3128
+ var ComponentListPanel = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["render", _sfc_render$8]]);
3129
+
3130
+ const _sfc_main$7 = defineComponent({
3131
+ name: "magic-editor-content-menu",
3132
+ props: {
3133
+ componentGroupList: {
3134
+ type: Array,
3135
+ default: () => []
3136
+ }
3137
+ },
3138
+ setup(props) {
3139
+ const services = inject("services");
3140
+ const subVisible = ref(false);
3141
+ const node = computed(() => services?.editorService.get("node"));
3142
+ return {
3143
+ subVisible,
3144
+ node,
3145
+ menu: computed(() => ({
3146
+ app: [
3147
+ {
3148
+ type: "page",
3149
+ text: "\u9875\u9762"
3150
+ }
3151
+ ],
3152
+ component: props.componentGroupList
3153
+ })),
3154
+ append(config) {
3155
+ services?.editorService.add({
3156
+ name: config.text,
3157
+ type: config.type
3158
+ });
3159
+ },
3160
+ remove() {
3161
+ node.value && services?.editorService.remove(node.value);
3162
+ },
3163
+ copy(node2) {
3164
+ services?.editorService.copy(node2);
3165
+ },
3166
+ setSubVisiable(v) {
3167
+ subVisible.value = v;
3168
+ }
3169
+ };
3170
+ }
3171
+ });
3172
+ const _hoisted_1$5 = {
3173
+ key: 0,
3174
+ class: "magic-editor-content-menu"
3175
+ };
3176
+ const _hoisted_2$2 = ["onClick"];
3177
+ const _hoisted_3$2 = ["onClick"];
3178
+ const _hoisted_4$2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3179
+ function _sfc_render$7(_ctx, _cache, $props, $setup, $data, $options) {
3180
+ const _component_el_scrollbar = resolveComponent("el-scrollbar");
3181
+ return _ctx.node ? (openBlock(), createElementBlock("div", _hoisted_1$5, [
3182
+ _ctx.node.items ? (openBlock(), createElementBlock("div", {
3183
+ key: 0,
3184
+ class: "magic-editor-content-menu-item",
3185
+ onMouseenter: _cache[0] || (_cache[0] = ($event) => _ctx.setSubVisiable(true)),
3186
+ onMouseleave: _cache[1] || (_cache[1] = ($event) => _ctx.setSubVisiable(false))
3187
+ }, " \u65B0\u589E ", 32)) : createCommentVNode("", true),
3188
+ _ctx.node.type !== "app" ? (openBlock(), createElementBlock("div", {
3189
+ key: 1,
3190
+ class: "magic-editor-content-menu-item",
3191
+ onClick: _cache[2] || (_cache[2] = () => _ctx.copy(_ctx.node))
3192
+ }, "\u590D\u5236")) : createCommentVNode("", true),
3193
+ _ctx.node.type !== "app" && _ctx.node.type !== "page" ? (openBlock(), createElementBlock("div", {
3194
+ key: 2,
3195
+ class: "magic-editor-content-menu-item",
3196
+ onClick: _cache[3] || (_cache[3] = () => _ctx.remove())
3197
+ }, " \u5220\u9664 ")) : createCommentVNode("", true),
3198
+ withDirectives(createElementVNode("div", {
3199
+ class: "subMenu",
3200
+ onMouseenter: _cache[5] || (_cache[5] = ($event) => _ctx.setSubVisiable(true)),
3201
+ onMouseleave: _cache[6] || (_cache[6] = ($event) => _ctx.setSubVisiable(false))
3202
+ }, [
3203
+ createVNode(_component_el_scrollbar, null, {
3204
+ default: withCtx(() => [
3205
+ _ctx.node.type === "tabs" ? (openBlock(), createElementBlock("div", {
3206
+ key: 0,
3207
+ class: "magic-editor-content-menu-item",
3208
+ onClick: _cache[4] || (_cache[4] = () => _ctx.append({
3209
+ type: "tab-pane"
3210
+ }))
3211
+ }, " \u6807\u7B7E ")) : _ctx.node.type === "app" ? (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.menu.app, (item) => {
3212
+ return openBlock(), createElementBlock("div", {
3213
+ class: "magic-editor-content-menu-item",
3214
+ key: item.type,
3215
+ onClick: () => _ctx.append(item)
3216
+ }, toDisplayString(item.text), 9, _hoisted_2$2);
3217
+ }), 128)) : _ctx.node.items ? (openBlock(true), createElementBlock(Fragment, { key: 2 }, renderList(_ctx.menu.component, (list) => {
3218
+ return openBlock(), createElementBlock("div", {
3219
+ key: list.title
3220
+ }, [
3221
+ (openBlock(true), createElementBlock(Fragment, null, renderList(list.items, (item) => {
3222
+ return openBlock(), createElementBlock(Fragment, null, [
3223
+ item ? (openBlock(), createElementBlock("div", {
3224
+ class: "magic-editor-content-menu-item",
3225
+ key: item.type,
3226
+ onClick: () => _ctx.append(item)
3227
+ }, toDisplayString(item.text), 9, _hoisted_3$2)) : createCommentVNode("", true)
3228
+ ], 64);
3229
+ }), 256)),
3230
+ _hoisted_4$2
3231
+ ]);
3232
+ }), 128)) : createCommentVNode("", true)
3233
+ ]),
3234
+ _: 1
3235
+ })
3236
+ ], 544), [
3237
+ [vShow, _ctx.subVisible]
3238
+ ])
3239
+ ])) : createCommentVNode("", true);
3240
+ }
3241
+ var LayerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$7, [["render", _sfc_render$7]]);
3242
+
3243
+ const select = (data, editorService) => {
3244
+ if (!data.id) {
3245
+ throw new Error("\u6CA1\u6709id");
3246
+ }
3247
+ editorService?.select(data);
3248
+ };
3249
+ const useDrop = (tree, editorService) => ({
3250
+ allowDrop: (draggingNode, dropNode, type) => {
3251
+ const { data } = dropNode || {};
3252
+ const { data: ingData } = draggingNode;
3253
+ const { type: ingType } = ingData;
3254
+ if (ingType !== "page" && data.type === "page")
3255
+ return false;
3256
+ if (ingType === "page" && data.type !== "page")
3257
+ return false;
3258
+ if (!data || !data.type)
3259
+ return false;
3260
+ if (["prev", "next"].includes(type))
3261
+ return true;
3262
+ if (data.items || data.type === "container")
3263
+ return true;
3264
+ return false;
3265
+ },
3266
+ handleDragEnd() {
3267
+ if (!tree.value)
3268
+ return;
3269
+ const { data } = tree.value;
3270
+ const [page] = data;
3271
+ editorService?.update(page);
3272
+ }
3273
+ });
3274
+ const useStatus = (tree, editorService) => {
3275
+ const page = computed(() => editorService?.get("page"));
3276
+ watchEffect(() => {
3277
+ if (!tree.value)
3278
+ return;
3279
+ const node = editorService?.get("node");
3280
+ node && tree.value.setCurrentKey(node.id, true);
3281
+ const parent = editorService?.get("parent");
3282
+ if (!parent?.id)
3283
+ return;
3284
+ const treeNode = tree.value.getNode(parent.id);
3285
+ treeNode?.updateChildren();
3286
+ });
3287
+ return {
3288
+ values: computed(() => page.value ? [page.value] : []),
3289
+ loadItems: (node, resolve) => {
3290
+ if (Array.isArray(node.data)) {
3291
+ return resolve(node.data);
3292
+ }
3293
+ if (Array.isArray(node.data?.items)) {
3294
+ return resolve(node.data?.items);
3295
+ }
3296
+ resolve([]);
3297
+ }
3298
+ };
3299
+ };
3300
+ const useFilter = (tree) => ({
3301
+ filterText: ref(""),
3302
+ filterNode: (value, data) => {
3303
+ if (!value) {
3304
+ return true;
3305
+ }
3306
+ let name = "";
3307
+ if (data.name) {
3308
+ name = data.name;
3309
+ } else if (data.type) {
3310
+ name = data.type;
3311
+ } else if (data.items) {
3312
+ name = "container";
3313
+ }
3314
+ return name.indexOf(value) !== -1;
3315
+ },
3316
+ filterTextChangeHandler(val) {
3317
+ tree.value?.filter(val);
3318
+ }
3319
+ });
3320
+ const useContentMenu = (editorService) => {
3321
+ const menuStyle = ref({
3322
+ position: "absolute",
3323
+ left: "0",
3324
+ top: "0",
3325
+ display: "none"
3326
+ });
3327
+ onMounted(() => {
3328
+ document.addEventListener("click", () => {
3329
+ menuStyle.value.display = "none";
3330
+ }, true);
3331
+ });
3332
+ return {
3333
+ menuStyle,
3334
+ contextmenu(event, data) {
3335
+ const bodyHeight = globalThis.document.body.clientHeight;
3336
+ const left = `${event.clientX + 20}px`;
3337
+ let top = `${event.clientY - 10}px`;
3338
+ if (event.clientY + 300 > bodyHeight) {
3339
+ top = `${bodyHeight - 300}px`;
3340
+ }
3341
+ menuStyle.value.left = left;
3342
+ menuStyle.value.top = top;
3343
+ menuStyle.value.display = "";
3344
+ select(data, editorService);
3345
+ }
3346
+ };
3347
+ };
3348
+ const _sfc_main$6 = defineComponent({
3349
+ name: "magic-editor-layer-panel",
3350
+ components: { LayerMenu },
3351
+ setup() {
3352
+ const services = inject("services");
3353
+ const tree = ref();
3354
+ const editorService = services?.editorService;
3355
+ return {
3356
+ tree,
3357
+ ...useDrop(tree, editorService),
3358
+ ...useStatus(tree, editorService),
3359
+ ...useFilter(tree),
3360
+ ...useContentMenu(editorService),
3361
+ clickHandler(data) {
3362
+ if (services?.uiService.get("uiSelectMode")) {
3363
+ document.dispatchEvent(new CustomEvent("ui-select", { detail: data }));
3364
+ return;
3365
+ }
3366
+ select(data, editorService);
3367
+ }
3368
+ };
3369
+ }
3370
+ });
3371
+ function _sfc_render$6(_ctx, _cache, $props, $setup, $data, $options) {
3372
+ const _component_el_input = resolveComponent("el-input");
3373
+ const _component_el_tree = resolveComponent("el-tree");
3374
+ const _component_layer_menu = resolveComponent("layer-menu");
3375
+ const _component_el_scrollbar = resolveComponent("el-scrollbar");
3376
+ return openBlock(), createBlock(_component_el_scrollbar, { class: "magic-editor-layer-panel" }, {
3377
+ default: withCtx(() => [
3378
+ createVNode(_component_el_input, {
3379
+ class: "filterInput",
3380
+ size: "small",
3381
+ placeholder: "\u8F93\u5165\u5173\u952E\u5B57\u8FDB\u884C\u8FC7\u6EE4",
3382
+ clearable: "",
3383
+ modelValue: _ctx.filterText,
3384
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.filterText = $event),
3385
+ onChange: _ctx.filterTextChangeHandler
3386
+ }, null, 8, ["modelValue", "onChange"]),
3387
+ _ctx.values.length ? (openBlock(), createBlock(_component_el_tree, {
3388
+ key: 0,
3389
+ ref: "tree",
3390
+ "node-key": "id",
3391
+ draggable: "",
3392
+ load: _ctx.loadItems,
3393
+ data: _ctx.values,
3394
+ "expand-on-click-node": false,
3395
+ "highlight-current": true,
3396
+ props: {
3397
+ children: "items"
3398
+ },
3399
+ "filter-node-method": _ctx.filterNode,
3400
+ "allow-drop": _ctx.allowDrop,
3401
+ onNodeClick: _ctx.clickHandler,
3402
+ onNodeContextmenu: _ctx.contextmenu,
3403
+ onNodeDragEnd: _ctx.handleDragEnd,
3404
+ "empty-text": "\u9875\u9762\u7A7A\u8361\u8361\u7684"
3405
+ }, {
3406
+ default: withCtx(({ node, data }) => [
3407
+ renderSlot(_ctx.$slots, "layer-node-content", {
3408
+ node,
3409
+ data
3410
+ }, () => [
3411
+ createElementVNode("span", null, toDisplayString(`${data.name} (${data.id})`), 1)
3412
+ ])
3413
+ ]),
3414
+ _: 3
3415
+ }, 8, ["load", "data", "filter-node-method", "allow-drop", "onNodeClick", "onNodeContextmenu", "onNodeDragEnd"])) : createCommentVNode("", true),
3416
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
3417
+ createVNode(_component_layer_menu, {
3418
+ style: normalizeStyle(_ctx.menuStyle)
3419
+ }, null, 8, ["style"])
3420
+ ]))
3421
+ ]),
3422
+ _: 3
3423
+ });
3424
+ }
3425
+ var LayerPanel = /* @__PURE__ */ _export_sfc(_sfc_main$6, [["render", _sfc_render$6]]);
3426
+
3427
+ const _sfc_main$5 = defineComponent({
3428
+ name: "m-sidebar",
3429
+ components: { MIcon },
3430
+ props: {
3431
+ data: {
3432
+ type: Object,
3433
+ default: () => ({ type: "tabs", status: "\u7EC4\u4EF6", items: ["component-list", "layer"] })
3434
+ }
3435
+ },
3436
+ setup(props) {
3437
+ const activeTabName = ref(props.data?.status);
3438
+ watch(() => props.data?.status, (status) => {
3439
+ activeTabName.value = status || "0";
3440
+ });
3441
+ return {
3442
+ activeTabName,
3443
+ items: computed(() => props.data?.items.map((item) => {
3444
+ if (typeof item !== "string") {
3445
+ return item;
3446
+ }
3447
+ switch (item) {
3448
+ case "component-list":
3449
+ return {
3450
+ type: "component",
3451
+ icon: Coin,
3452
+ text: "\u7EC4\u4EF6",
3453
+ component: ComponentListPanel,
3454
+ slots: {}
3455
+ };
3456
+ case "layer":
3457
+ return {
3458
+ type: "component",
3459
+ icon: Files,
3460
+ text: "\u5DF2\u9009\u7EC4\u4EF6",
3461
+ component: LayerPanel,
3462
+ slots: {}
3463
+ };
3464
+ default:
3465
+ return {};
3466
+ }
3467
+ }))
3468
+ };
3469
+ }
3470
+ });
3471
+ const _hoisted_1$4 = {
3472
+ key: 1,
3473
+ class: "magic-editor-tab-panel-title"
3474
+ };
3475
+ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3476
+ const _component_m_icon = resolveComponent("m-icon");
3477
+ const _component_el_tab_pane = resolveComponent("el-tab-pane");
3478
+ const _component_el_tabs = resolveComponent("el-tabs");
3479
+ return _ctx.data.type === "tabs" ? (openBlock(), createBlock(_component_el_tabs, {
3480
+ key: 0,
3481
+ class: "m-editor-sidebar",
3482
+ modelValue: _ctx.activeTabName,
3483
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => _ctx.activeTabName = $event),
3484
+ type: "card",
3485
+ "tab-position": "left"
3486
+ }, {
3487
+ default: withCtx(() => [
3488
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.items, (item) => {
3489
+ return openBlock(), createBlock(_component_el_tab_pane, {
3490
+ key: item.text,
3491
+ name: item.text
3492
+ }, {
3493
+ label: withCtx(() => [
3494
+ createElementVNode("span", null, [
3495
+ item.icon ? (openBlock(), createBlock(_component_m_icon, {
3496
+ key: 0,
3497
+ icon: item.icon
3498
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
3499
+ item.text ? (openBlock(), createElementBlock("div", _hoisted_1$4, toDisplayString(item.text), 1)) : createCommentVNode("", true)
3500
+ ])
3501
+ ]),
3502
+ default: withCtx(() => [
3503
+ (openBlock(), createBlock(resolveDynamicComponent(item.component), mergeProps(item.props || {}, toHandlers(item.listeners || {})), createSlots({ _: 2 }, [
3504
+ item.slots?.layerNodeContent ? {
3505
+ name: "layer-node-content",
3506
+ fn: withCtx(({ data, node }) => [
3507
+ (openBlock(), createBlock(resolveDynamicComponent(item.slots.layerNodeContent), {
3508
+ data,
3509
+ node
3510
+ }, null, 8, ["data", "node"]))
3511
+ ])
3512
+ } : void 0
3513
+ ]), 1040))
3514
+ ]),
3515
+ _: 2
3516
+ }, 1032, ["name"]);
3517
+ }), 128))
3518
+ ]),
3519
+ _: 1
3520
+ }, 8, ["modelValue"])) : createCommentVNode("", true);
3521
+ }
3522
+ var Sidebar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3523
+
3524
+ const _sfc_main$4 = defineComponent({
3525
+ components: { CaretBottom, Plus },
3526
+ setup() {
3527
+ const services = inject("services");
3528
+ const editorService = services?.editorService;
3529
+ return {
3530
+ root: computed(() => editorService?.get("root")),
3531
+ page: computed(() => editorService?.get("page")),
3532
+ switchPage(page) {
3533
+ editorService?.select(page);
3534
+ },
3535
+ addPage() {
3536
+ if (!editorService)
3537
+ return;
3538
+ const pageConfig = {
3539
+ type: "page",
3540
+ name: generatePageNameByApp(toRaw(editorService.get("root")))
3541
+ };
3542
+ editorService.add(pageConfig);
3543
+ },
3544
+ copy(node) {
3545
+ node && editorService?.copy(node);
3546
+ editorService?.paste({
3547
+ left: 0,
3548
+ top: 0
3549
+ });
3550
+ },
3551
+ remove(node) {
3552
+ editorService?.remove(node);
3553
+ }
3554
+ };
3555
+ }
3556
+ });
3557
+ const _hoisted_1$3 = { class: "m-editor-page-bar" };
3558
+ const _hoisted_2$1 = ["onClick"];
3559
+ const _hoisted_3$1 = ["onClick"];
3560
+ const _hoisted_4$1 = ["onClick"];
3561
+ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
3562
+ const _component_plus = resolveComponent("plus");
3563
+ const _component_el_icon = resolveComponent("el-icon");
3564
+ const _component_caret_bottom = resolveComponent("caret-bottom");
3565
+ const _component_el_popover = resolveComponent("el-popover");
3566
+ return openBlock(), createElementBlock("div", _hoisted_1$3, [
3567
+ createElementVNode("div", {
3568
+ class: "m-editor-page-bar-item",
3569
+ onClick: _cache[0] || (_cache[0] = (...args) => _ctx.addPage && _ctx.addPage(...args))
3570
+ }, [
3571
+ createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-add-icon" }, {
3572
+ default: withCtx(() => [
3573
+ createVNode(_component_plus)
3574
+ ]),
3575
+ _: 1
3576
+ })
3577
+ ]),
3578
+ _ctx.root ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(_ctx.root.items, (item) => {
3579
+ return openBlock(), createElementBlock("div", {
3580
+ key: item.key,
3581
+ class: normalizeClass(["m-editor-page-bar-item", { active: _ctx.page?.id === item.id }]),
3582
+ onClick: ($event) => _ctx.switchPage(item)
3583
+ }, [
3584
+ renderSlot(_ctx.$slots, "page-bar-title", { page: item }, () => [
3585
+ createElementVNode("span", null, toDisplayString(item.name), 1)
3586
+ ]),
3587
+ createVNode(_component_el_popover, {
3588
+ placement: "top",
3589
+ width: 160,
3590
+ trigger: "hover"
3591
+ }, {
3592
+ reference: withCtx(() => [
3593
+ createVNode(_component_el_icon, { class: "m-editor-page-bar-menu-icon" }, {
3594
+ default: withCtx(() => [
3595
+ createVNode(_component_caret_bottom)
3596
+ ]),
3597
+ _: 1
3598
+ })
3599
+ ]),
3600
+ default: withCtx(() => [
3601
+ createElementVNode("div", null, [
3602
+ renderSlot(_ctx.$slots, "page-bar-popover", { page: item }, () => [
3603
+ createElementVNode("div", {
3604
+ class: "magic-editor-content-menu-item",
3605
+ onClick: () => _ctx.copy(item)
3606
+ }, "\u590D\u5236", 8, _hoisted_3$1),
3607
+ createElementVNode("div", {
3608
+ class: "magic-editor-content-menu-item",
3609
+ onClick: () => _ctx.remove(item)
3610
+ }, "\u5220\u9664", 8, _hoisted_4$1)
3611
+ ])
3612
+ ])
3613
+ ]),
3614
+ _: 2
3615
+ }, 1024)
3616
+ ], 10, _hoisted_2$1);
3617
+ }), 128)) : createCommentVNode("", true)
3618
+ ]);
3619
+ }
3620
+ var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$4]]);
3621
+
3622
+ const _sfc_main$3 = defineComponent({
3623
+ name: "magic-editor-ui-viewer-menu",
3624
+ setup() {
3625
+ const services = inject("services");
3626
+ const editorService = services?.editorService;
3627
+ const menu = ref();
3628
+ const canPaste = ref(false);
3629
+ const canCenter = ref(false);
3630
+ const node = computed(() => editorService?.get("node"));
3631
+ const parent = computed(() => editorService?.get("parent"));
3632
+ onMounted(() => {
3633
+ const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3634
+ canPaste.value = data !== "undefined" && !!data;
3635
+ });
3636
+ watch(parent, async () => {
3637
+ if (!parent.value || !editorService)
3638
+ return canCenter.value = false;
3639
+ const layout = await editorService.getLayout(parent.value);
3640
+ canCenter.value = [Layout.ABSOLUTE, Layout.FIXED].includes(layout) && !["app", "page", "pop"].includes(`${node.value?.type}`);
3641
+ }, { immediate: true });
3642
+ return {
3643
+ menu,
3644
+ canPaste,
3645
+ canDelete: computed(() => node.value?.type !== "page"),
3646
+ canMoveZPos: computed(() => node.value?.type !== "page"),
3647
+ canCenter,
3648
+ center() {
3649
+ node.value && editorService?.alignCenter(node.value);
3650
+ },
3651
+ copy() {
3652
+ node.value && editorService?.copy(node.value);
3653
+ canPaste.value = true;
3654
+ },
3655
+ paste() {
3656
+ const top = menu.value?.offsetTop || 0;
3657
+ const left = menu.value?.offsetLeft || 0;
3658
+ editorService?.paste({ left, top });
3659
+ },
3660
+ remove() {
3661
+ node.value && editorService?.remove(node.value);
3662
+ },
3663
+ top() {
3664
+ editorService?.moveLayer(LayerOffset.TOP);
3665
+ },
3666
+ bottom() {
3667
+ editorService?.moveLayer(LayerOffset.BOTTOM);
3668
+ },
3669
+ topItem() {
3670
+ editorService?.moveLayer(1);
3671
+ },
3672
+ bottomItem() {
3673
+ editorService?.moveLayer(-1);
3674
+ },
3675
+ clearGuides() {
3676
+ editorService?.get("stage").clearGuides();
3677
+ }
3678
+ };
3679
+ }
3680
+ });
3681
+ const _hoisted_1$2 = {
3682
+ class: "magic-editor-content-menu",
3683
+ ref: "menu"
3684
+ };
3685
+ const _hoisted_2 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3686
+ const _hoisted_3 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3687
+ const _hoisted_4 = /* @__PURE__ */ createElementVNode("div", { class: "separation" }, null, -1);
3688
+ function _sfc_render$3(_ctx, _cache, $props, $setup, $data, $options) {
3689
+ return openBlock(), createElementBlock("div", _hoisted_1$2, [
3690
+ createElementVNode("div", null, [
3691
+ _ctx.canCenter ? (openBlock(), createElementBlock("div", {
3692
+ key: 0,
3693
+ class: "magic-editor-content-menu-item",
3694
+ onClick: _cache[0] || (_cache[0] = () => _ctx.center())
3695
+ }, "\u6C34\u5E73\u5C45\u4E2D")) : createCommentVNode("", true),
3696
+ createElementVNode("div", {
3697
+ class: "magic-editor-content-menu-item",
3698
+ onClick: _cache[1] || (_cache[1] = () => _ctx.copy())
3699
+ }, "\u590D\u5236"),
3700
+ _ctx.canPaste ? (openBlock(), createElementBlock("div", {
3701
+ key: 1,
3702
+ class: "magic-editor-content-menu-item",
3703
+ onClick: _cache[2] || (_cache[2] = (...args) => _ctx.paste && _ctx.paste(...args))
3704
+ }, "\u7C98\u8D34")) : createCommentVNode("", true),
3705
+ _ctx.canMoveZPos ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
3706
+ _hoisted_2,
3707
+ createElementVNode("div", {
3708
+ class: "magic-editor-content-menu-item",
3709
+ onClick: _cache[3] || (_cache[3] = (...args) => _ctx.topItem && _ctx.topItem(...args))
3710
+ }, "\u4E0A\u79FB\u4E00\u5C42"),
3711
+ createElementVNode("div", {
3712
+ class: "magic-editor-content-menu-item",
3713
+ onClick: _cache[4] || (_cache[4] = (...args) => _ctx.bottomItem && _ctx.bottomItem(...args))
3714
+ }, "\u4E0B\u79FB\u4E00\u5C42"),
3715
+ createElementVNode("div", {
3716
+ class: "magic-editor-content-menu-item",
3717
+ onClick: _cache[5] || (_cache[5] = (...args) => _ctx.top && _ctx.top(...args))
3718
+ }, "\u7F6E\u9876"),
3719
+ createElementVNode("div", {
3720
+ class: "magic-editor-content-menu-item",
3721
+ onClick: _cache[6] || (_cache[6] = (...args) => _ctx.bottom && _ctx.bottom(...args))
3722
+ }, "\u7F6E\u5E95")
3723
+ ], 64)) : createCommentVNode("", true),
3724
+ _ctx.canDelete ? (openBlock(), createElementBlock(Fragment, { key: 3 }, [
3725
+ _hoisted_3,
3726
+ createElementVNode("div", {
3727
+ class: "magic-editor-content-menu-item",
3728
+ onClick: _cache[7] || (_cache[7] = () => _ctx.remove())
3729
+ }, "\u5220\u9664")
3730
+ ], 64)) : createCommentVNode("", true),
3731
+ _hoisted_4,
3732
+ createElementVNode("div", {
3733
+ class: "magic-editor-content-menu-item",
3734
+ onClick: _cache[8] || (_cache[8] = (...args) => _ctx.clearGuides && _ctx.clearGuides(...args))
3735
+ }, "\u6E05\u7A7A\u53C2\u8003\u7EBF")
3736
+ ])
3737
+ ], 512);
3738
+ }
3739
+ var ViewerMenu = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["render", _sfc_render$3]]);
3740
+
3741
+ const useMenu = () => {
3742
+ const menu = ref();
3743
+ const menuStyle = ref({
3744
+ display: "none",
3745
+ left: "0",
3746
+ top: "0"
3747
+ });
3748
+ onMounted(() => {
3749
+ document.addEventListener("click", () => {
3750
+ menuStyle.value.display = "none";
3751
+ }, true);
3752
+ });
3753
+ return {
3754
+ menu,
3755
+ menuStyle,
3756
+ contextmenuHandler(e) {
3757
+ e.preventDefault();
3758
+ const menuHeight = menu.value?.$el.clientHeight;
3759
+ let top = e.clientY;
3760
+ if (menuHeight + e.clientY > document.body.clientHeight) {
3761
+ top = document.body.clientHeight - menuHeight;
3762
+ }
3763
+ menuStyle.value = {
3764
+ display: "block",
3765
+ top: `${top}px`,
3766
+ left: `${e.clientX}px`
3767
+ };
3768
+ }
3769
+ };
3770
+ };
3771
+ const _sfc_main$2 = defineComponent({
3772
+ name: "magic-stage",
3773
+ components: {
3774
+ ViewerMenu
3775
+ },
3776
+ props: {
3777
+ render: {
3778
+ type: Function
3779
+ },
3780
+ runtimeUrl: String,
3781
+ root: {
3782
+ type: Object
3783
+ },
3784
+ page: {
3785
+ type: Object
3786
+ },
3787
+ node: {
3788
+ type: Object
3789
+ },
3790
+ uiSelectMode: {
3791
+ type: Boolean
3792
+ },
3793
+ zoom: {
3794
+ type: Number
3795
+ },
3796
+ canSelect: {
3797
+ type: Function,
3798
+ default: (el) => Boolean(el.id)
3799
+ },
3800
+ moveableOptions: {
3801
+ type: [Object, Function],
3802
+ default: () => (core) => ({
3803
+ container: core?.renderer?.contentWindow?.document.getElementById("app")
3804
+ })
3805
+ }
3806
+ },
3807
+ emits: ["select", "update", "sort"],
3808
+ setup(props, { emit }) {
3809
+ const services = inject("services");
3810
+ const stageContainer = ref();
3811
+ const stageStyle = computed(() => ({
3812
+ ...services?.uiService.get("stageStyle"),
3813
+ transform: `scale(${props.zoom}) translate3d(0, -50%, 0)`
3814
+ }));
3815
+ let stage = null;
3816
+ let runtime = null;
3817
+ watchEffect(() => {
3818
+ if (stage)
3819
+ return;
3820
+ if (!stageContainer.value)
3821
+ return;
3822
+ if (!(props.runtimeUrl || props.render) || !props.root)
3823
+ return;
3824
+ stage = new StageCore({
3825
+ render: props.render,
3826
+ runtimeUrl: props.runtimeUrl,
3827
+ zoom: props.zoom,
3828
+ canSelect: (el, stop) => {
3829
+ const elCanSelect = props.canSelect(el);
3830
+ if (props.uiSelectMode && elCanSelect) {
3831
+ document.dispatchEvent(new CustomEvent("ui-select", { detail: el }));
3832
+ return stop();
3833
+ }
3834
+ return elCanSelect;
3835
+ },
3836
+ moveableOptions: props.moveableOptions
3837
+ });
3838
+ services?.editorService.set("stage", stage);
3839
+ stage?.mount(stageContainer.value);
3840
+ stage?.on("select", (el) => emit("select", el));
3841
+ stage?.on("update", (ev) => {
3842
+ emit("update", { id: ev.el.id, style: ev.style });
3843
+ });
3844
+ stage?.on("sort", (ev) => {
3845
+ emit("sort", ev);
3846
+ });
3847
+ stage?.on("changeGuides", () => {
3848
+ services?.uiService.set("showGuides", true);
3849
+ });
3850
+ if (!props.node?.id)
3851
+ return;
3852
+ stage?.on("runtime-ready", (rt) => {
3853
+ runtime = rt;
3854
+ props.root && runtime?.updateRootConfig(cloneDeep(toRaw(props.root)));
3855
+ props.page?.id && runtime?.updatePageId?.(props.page.id);
3856
+ setTimeout(() => {
3857
+ props.node && stage?.select(toRaw(props.node.id));
3858
+ });
3859
+ });
3860
+ });
3861
+ watch(() => props.zoom, (zoom) => {
3862
+ if (!stage || !zoom)
3863
+ return;
3864
+ stage?.setZoom(zoom);
3865
+ });
3866
+ watch(() => props.root, (root) => {
3867
+ if (runtime && root) {
3868
+ runtime.updateRootConfig(cloneDeep(toRaw(root)));
3869
+ }
3870
+ });
3871
+ onUnmounted(() => {
3872
+ stage?.destroy();
3873
+ services?.editorService.set("stage", null);
3874
+ });
3875
+ return {
3876
+ stageStyle,
3877
+ ...useMenu(),
3878
+ stageContainer
3879
+ };
3880
+ }
3881
+ });
3882
+ const _hoisted_1$1 = { class: "m-editor-stage" };
3883
+ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
3884
+ const _component_viewer_menu = resolveComponent("viewer-menu");
3885
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
3886
+ createElementVNode("div", {
3887
+ class: "m-editor-stage-container",
3888
+ ref: "stageContainer",
3889
+ style: normalizeStyle(_ctx.stageStyle),
3890
+ onContextmenu: _cache[0] || (_cache[0] = (...args) => _ctx.contextmenuHandler && _ctx.contextmenuHandler(...args))
3891
+ }, null, 36),
3892
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
3893
+ createVNode(_component_viewer_menu, {
3894
+ ref: "menu",
3895
+ style: normalizeStyle(_ctx.menuStyle)
3896
+ }, null, 8, ["style"])
3897
+ ]))
3898
+ ]);
3899
+ }
3900
+ var MagicStage = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["render", _sfc_render$2]]);
3901
+
3902
+ const _sfc_main$1 = defineComponent({
3903
+ name: "m-editor-workspace",
3904
+ components: {
3905
+ PageBar,
3906
+ MagicStage
3907
+ },
3908
+ props: {
3909
+ runtimeUrl: String,
3910
+ render: {
3911
+ type: Function
3912
+ },
3913
+ moveableOptions: {
3914
+ type: [Object, Function]
3915
+ },
3916
+ canSelect: {
3917
+ type: Function
3918
+ }
3919
+ },
3920
+ setup() {
3921
+ const services = inject("services");
3922
+ const node = computed(() => services?.editorService.get("node"));
3923
+ const stage = computed(() => services?.editorService.get("stage"));
3924
+ watch([() => node.value?.id, stage], ([id, stage2]) => {
3925
+ nextTick(() => {
3926
+ id && stage2?.select(id);
3927
+ });
3928
+ });
3929
+ return {
3930
+ uiSelectMode: computed(() => services?.uiService.get("uiSelectMode")),
3931
+ root: computed(() => services?.editorService.get("root")),
3932
+ page: computed(() => services?.editorService.get("page")),
3933
+ zoom: computed(() => services?.uiService.get("zoom")),
3934
+ node,
3935
+ selectHandler(el) {
3936
+ services?.editorService.select(el.id);
3937
+ },
3938
+ updateNodeHandler(node2) {
3939
+ services?.editorService.update(node2);
3940
+ },
3941
+ sortNodeHandler(ev) {
3942
+ services?.editorService.sort(ev.src, ev.dist);
3943
+ }
3944
+ };
3945
+ }
3946
+ });
3947
+ const _hoisted_1 = { class: "m-editor-workspace" };
3948
+ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
3949
+ const _component_magic_stage = resolveComponent("magic-stage");
3950
+ const _component_page_bar = resolveComponent("page-bar");
3951
+ return openBlock(), createElementBlock("div", _hoisted_1, [
3952
+ (openBlock(), createBlock(_component_magic_stage, {
3953
+ key: _ctx.page?.id,
3954
+ "runtime-url": _ctx.runtimeUrl,
3955
+ render: _ctx.render,
3956
+ "ui-select-mode": _ctx.uiSelectMode,
3957
+ root: _ctx.root,
3958
+ page: _ctx.page,
3959
+ node: _ctx.node,
3960
+ zoom: _ctx.zoom,
3961
+ "moveable-options": _ctx.moveableOptions,
3962
+ "can-select": _ctx.canSelect,
3963
+ onSelect: _ctx.selectHandler,
3964
+ onUpdate: _ctx.updateNodeHandler,
3965
+ onSort: _ctx.sortNodeHandler
3966
+ }, null, 8, ["runtime-url", "render", "ui-select-mode", "root", "page", "node", "zoom", "moveable-options", "can-select", "onSelect", "onUpdate", "onSort"])),
3967
+ renderSlot(_ctx.$slots, "workspace-content"),
3968
+ createVNode(_component_page_bar, null, {
3969
+ "page-bar-title": withCtx(({ page }) => [
3970
+ renderSlot(_ctx.$slots, "page-bar-title", { page })
3971
+ ]),
3972
+ "page-bar-popover": withCtx(({ page }) => [
3973
+ renderSlot(_ctx.$slots, "page-bar-popover", { page })
3974
+ ]),
3975
+ _: 3
3976
+ })
3977
+ ]);
3978
+ }
3979
+ var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
3980
+
3981
+ class ComponentList extends BaseService {
3982
+ state = reactive({
3983
+ list: []
3984
+ });
3985
+ constructor() {
3986
+ super([]);
3987
+ }
3988
+ setList(componentGroupList) {
3989
+ this.state.list = componentGroupList;
3990
+ }
3991
+ getList() {
3992
+ return this.state.list;
3993
+ }
3994
+ }
3995
+ var componentListService = new ComponentList();
3996
+
3997
+ const state = reactive({
3998
+ uiSelectMode: false,
3999
+ showSrc: false,
4000
+ zoom: 1,
4001
+ stageStyle: {},
4002
+ columnWidth: {
4003
+ left: 310,
4004
+ center: globalThis.document.body.clientWidth - 310 - 400,
4005
+ right: 400
4006
+ },
4007
+ showGuides: true,
4008
+ showRule: true
4009
+ });
4010
+ class Ui extends BaseService {
4011
+ constructor() {
4012
+ super([]);
4013
+ globalThis.addEventListener("resize", () => {
4014
+ this.setColumnWidth({
4015
+ center: "auto"
4016
+ });
4017
+ });
4018
+ }
4019
+ set(name, value) {
4020
+ const mask = editorService.get("stage")?.mask;
4021
+ if (name === "columnWidth") {
4022
+ this.setColumnWidth(value);
4023
+ return;
4024
+ }
4025
+ if (name === "showGuides") {
4026
+ mask?.showGuides(value);
4027
+ }
4028
+ if (name === "showRule") {
4029
+ mask?.showRule(value);
4030
+ }
4031
+ state[name] = value;
4032
+ }
4033
+ get(name) {
4034
+ return state[name];
4035
+ }
4036
+ setColumnWidth({ left, center, right }) {
4037
+ const columnWidth = {
4038
+ ...toRaw(this.get("columnWidth"))
4039
+ };
4040
+ if (left) {
4041
+ columnWidth.left = left;
4042
+ }
4043
+ if (right) {
4044
+ columnWidth.right = right;
4045
+ }
4046
+ if (!center || center === "auto") {
4047
+ const bodyWidth = globalThis.document.body.clientWidth;
4048
+ columnWidth.center = bodyWidth - (columnWidth?.left || 0) - (columnWidth?.right || 0);
4049
+ } else {
4050
+ columnWidth.center = center;
4051
+ }
4052
+ state.columnWidth = columnWidth;
4053
+ }
4054
+ }
4055
+ var uiService = new Ui();
4056
+
4057
+ const _sfc_main = defineComponent({
4058
+ name: "m-editor",
4059
+ components: {
4060
+ NavMenu,
4061
+ Sidebar,
4062
+ Workspace,
4063
+ PropsPanel,
4064
+ Framework
4065
+ },
4066
+ props: {
4067
+ modelValue: {
4068
+ type: Object,
4069
+ default: () => ({}),
4070
+ require: true
4071
+ },
4072
+ componentGroupList: {
4073
+ type: Array,
4074
+ default: () => []
4075
+ },
4076
+ sidebar: {
4077
+ type: Object
4078
+ },
4079
+ menu: {
4080
+ type: Object,
4081
+ default: () => ({ left: [], right: [] })
4082
+ },
4083
+ render: {
4084
+ type: Function
4085
+ },
4086
+ runtimeUrl: String,
4087
+ propsConfigs: {
4088
+ type: Object,
4089
+ default: () => ({})
4090
+ },
4091
+ propsValues: {
4092
+ type: Object,
4093
+ default: () => ({})
4094
+ },
4095
+ eventMethodList: {
4096
+ type: Object,
4097
+ default: () => ({})
4098
+ },
4099
+ moveableOptions: {
4100
+ type: [Object, Function]
4101
+ },
4102
+ defaultSelected: {
4103
+ type: [Number, String]
4104
+ },
4105
+ canSelect: {
4106
+ type: Function
4107
+ },
4108
+ stageStyle: {
4109
+ type: [String, Object]
4110
+ }
4111
+ },
4112
+ emits: ["props-panel-mounted", "update:modelValue"],
4113
+ setup(props, { emit }) {
4114
+ editorService.on("root-change", () => {
4115
+ const node = editorService.get("node") || props.defaultSelected;
4116
+ node && editorService.select(node);
4117
+ emit("update:modelValue", toRaw(editorService.get("root")));
4118
+ });
4119
+ watch(() => props.modelValue, (modelValue) => editorService.set("root", modelValue), {
4120
+ immediate: true
4121
+ });
4122
+ watch(() => props.componentGroupList, (componentGroupList) => componentListService.setList(componentGroupList), {
4123
+ immediate: true
4124
+ });
4125
+ watch(() => props.propsConfigs, (configs) => propsService.setPropsConfigs(configs), {
4126
+ immediate: true
4127
+ });
4128
+ watch(() => props.propsValues, (values) => propsService.setPropsValues(values), {
4129
+ immediate: true
4130
+ });
4131
+ watch(() => props.eventMethodList, (eventMethodList) => {
4132
+ const eventsList = {};
4133
+ const methodsList = {};
4134
+ Object.keys(eventMethodList).forEach((type) => {
4135
+ eventsList[type] = eventMethodList[type].events;
4136
+ methodsList[type] = eventMethodList[type].methods;
4137
+ });
4138
+ eventsService.setEvents(eventsList);
4139
+ eventsService.setMethods(methodsList);
4140
+ }, {
4141
+ immediate: true
4142
+ });
4143
+ watch(() => props.defaultSelected, (defaultSelected) => defaultSelected && editorService.select(defaultSelected), {
4144
+ immediate: true
4145
+ });
4146
+ watch(() => props.stageStyle, (stageStyle) => uiService.set("stageStyle", stageStyle), {
4147
+ immediate: true
4148
+ });
4149
+ onUnmounted(() => editorService.destroy());
4150
+ const services = {
4151
+ componentListService,
4152
+ eventsService,
4153
+ historyService,
4154
+ propsService,
4155
+ editorService,
4156
+ uiService
4157
+ };
4158
+ provide("services", services);
4159
+ return services;
4160
+ }
4161
+ });
4162
+ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
4163
+ const _component_nav_menu = resolveComponent("nav-menu");
4164
+ const _component_sidebar = resolveComponent("sidebar");
4165
+ const _component_workspace = resolveComponent("workspace");
4166
+ const _component_props_panel = resolveComponent("props-panel");
4167
+ const _component_framework = resolveComponent("framework");
4168
+ return openBlock(), createBlock(_component_framework, null, {
4169
+ nav: withCtx(() => [
4170
+ renderSlot(_ctx.$slots, "nav", { editorService: _ctx.editorService }, () => [
4171
+ createVNode(_component_nav_menu, { data: _ctx.menu }, null, 8, ["data"])
4172
+ ])
4173
+ ]),
4174
+ sidebar: withCtx(() => [
4175
+ renderSlot(_ctx.$slots, "sidebar", { editorService: _ctx.editorService }, () => [
4176
+ createVNode(_component_sidebar, { data: _ctx.sidebar }, null, 8, ["data"])
4177
+ ])
4178
+ ]),
4179
+ workspace: withCtx(() => [
4180
+ renderSlot(_ctx.$slots, "workspace", {}, () => [
4181
+ createVNode(_component_workspace, {
4182
+ "runtime-url": _ctx.runtimeUrl,
4183
+ render: _ctx.render,
4184
+ "moveable-options": _ctx.moveableOptions,
4185
+ "can-select": _ctx.canSelect
4186
+ }, {
4187
+ "workspace-content": withCtx(() => [
4188
+ renderSlot(_ctx.$slots, "workspace-content", { editorService: _ctx.editorService })
4189
+ ]),
4190
+ "page-bar-title": withCtx(({ page }) => [
4191
+ renderSlot(_ctx.$slots, "page-bar-title", { page })
4192
+ ]),
4193
+ "page-bar-popover": withCtx(({ page }) => [
4194
+ renderSlot(_ctx.$slots, "page-bar-popover", { page })
4195
+ ]),
4196
+ _: 3
4197
+ }, 8, ["runtime-url", "render", "moveable-options", "can-select"])
4198
+ ])
4199
+ ]),
4200
+ propsPanel: withCtx(() => [
4201
+ renderSlot(_ctx.$slots, "propsPanel", {}, () => [
4202
+ createVNode(_component_props_panel, {
4203
+ ref: "propsPanel",
4204
+ onMounted: _cache[0] || (_cache[0] = (instance) => _ctx.$emit("props-panel-mounted", instance))
4205
+ }, null, 512)
4206
+ ])
4207
+ ]),
4208
+ empty: withCtx(() => [
4209
+ renderSlot(_ctx.$slots, "empty", { editorService: _ctx.editorService })
4210
+ ]),
4211
+ _: 3
4212
+ });
4213
+ }
4214
+ var Editor = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
4215
+
4216
+ var index$1 = '';
4217
+
4218
+ const defaultInstallOpt = {};
4219
+ var index = {
4220
+ install: (app, opt) => {
4221
+ const option = Object.assign(defaultInstallOpt, opt || {});
4222
+ app.config.globalProperties.$TMAGIC_EDITOR = option;
4223
+ setConfig(option);
4224
+ app.component(Editor.name, Editor);
4225
+ app.component(uiSelect.name, uiSelect);
4226
+ app.component(CodeLink.name, CodeLink);
4227
+ app.component(Code.name, Code);
4228
+ app.component(CodeEditor.name, CodeEditor);
4229
+ }
4230
+ };
4231
+
4232
+ export { COPY_STORAGE_KEY, ComponentListPanel, DEFAULT_CONFIG, Fixed2Other, LayerOffset, LayerPanel, Layout, PropsPanel, CodeEditor as TMagicCodeEditor, Editor as TMagicEditor, change2Fixed, debug, index as default, defaults, editorService, error, eventsService, fillConfig, generateId, generatePageName, generatePageNameByApp, getConfig, getDefaultPropsValue, getNodeIndex, getPageList, getPageNameList, historyService, info, initPosition, isFixed, log, propsService, setConfig, setLayout, setNewItemId, toRelative, uiService, warn };
4233
+ //# sourceMappingURL=tmagic-editor.es.js.map