@tmagic/editor 1.0.0-beta.3 → 1.0.0-beta.6

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