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