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

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