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

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