@tmagic/editor 1.0.0-rc.3 → 1.0.0-rc.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 (63) hide show
  1. package/coverage/clover.xml +505 -446
  2. package/coverage/coverage-final.json +10 -10
  3. package/coverage/lcov-report/index.html +60 -60
  4. package/coverage/lcov-report/src/Editor.vue.html +48 -9
  5. package/coverage/lcov-report/src/components/ContentMenu.vue.html +143 -44
  6. package/coverage/lcov-report/src/components/Icon.vue.html +2 -2
  7. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +1 -1
  8. package/coverage/lcov-report/src/components/ToolButton.vue.html +25 -25
  9. package/coverage/lcov-report/src/components/index.html +20 -20
  10. package/coverage/lcov-report/src/index.html +15 -15
  11. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +1 -1
  12. package/coverage/lcov-report/src/layouts/Framework.vue.html +1 -1
  13. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +1 -1
  14. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +1 -1
  15. package/coverage/lcov-report/src/layouts/Resizer.vue.html +1 -1
  16. package/coverage/lcov-report/src/layouts/index.html +1 -1
  17. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +1 -1
  18. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +27 -18
  19. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +1 -1
  20. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +1 -1
  21. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +2 -2
  22. package/coverage/lcov-report/src/layouts/sidebar/index.html +19 -19
  23. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +1 -1
  24. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +1 -1
  25. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +78 -33
  26. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +79 -34
  27. package/coverage/lcov-report/src/layouts/workspace/index.html +28 -28
  28. package/coverage/lcov-report/src/services/BaseService.ts.html +2 -2
  29. package/coverage/lcov-report/src/services/componentList.ts.html +1 -1
  30. package/coverage/lcov-report/src/services/editor.ts.html +102 -12
  31. package/coverage/lcov-report/src/services/events.ts.html +1 -1
  32. package/coverage/lcov-report/src/services/history.ts.html +1 -1
  33. package/coverage/lcov-report/src/services/index.html +15 -15
  34. package/coverage/lcov-report/src/services/props.ts.html +4 -4
  35. package/coverage/lcov-report/src/services/ui.ts.html +1 -1
  36. package/coverage/lcov-report/src/type.ts.html +1 -1
  37. package/coverage/lcov-report/src/utils/compose.ts.html +1 -1
  38. package/coverage/lcov-report/src/utils/config.ts.html +1 -1
  39. package/coverage/lcov-report/src/utils/editor.ts.html +21 -9
  40. package/coverage/lcov-report/src/utils/index.html +12 -12
  41. package/coverage/lcov-report/src/utils/index.ts.html +1 -1
  42. package/coverage/lcov-report/src/utils/logger.ts.html +1 -1
  43. package/coverage/lcov-report/src/utils/props.ts.html +1 -1
  44. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +1 -1
  45. package/coverage/lcov-report/src/utils/undo-redo.ts.html +1 -1
  46. package/coverage/lcov.info +1132 -986
  47. package/dist/tmagic-editor.es.js +148 -62
  48. package/dist/tmagic-editor.es.js.map +1 -1
  49. package/dist/tmagic-editor.umd.js +148 -62
  50. package/dist/tmagic-editor.umd.js.map +1 -1
  51. package/dist/types/src/Editor.vue.d.ts +19 -1
  52. package/dist/types/src/services/BaseService.d.ts +1 -1
  53. package/package.json +7 -7
  54. package/src/Editor.vue +14 -1
  55. package/src/components/ContentMenu.vue +59 -26
  56. package/src/layouts/sidebar/LayerMenu.vue +3 -0
  57. package/src/layouts/sidebar/TabPane.vue +1 -1
  58. package/src/layouts/workspace/ViewerMenu.vue +17 -2
  59. package/src/layouts/workspace/Workspace.vue +38 -23
  60. package/src/services/BaseService.ts +1 -1
  61. package/src/services/editor.ts +33 -3
  62. package/src/services/props.ts +3 -3
  63. package/src/utils/editor.ts +6 -2
@@ -1,4 +1,4 @@
1
- import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, withDirectives, Teleport, vShow, toHandlers, createSlots, provide } from 'vue';
1
+ import { defineComponent, computed, resolveComponent, openBlock, createBlock, normalizeStyle, ref, watchEffect, inject, markRaw, createElementBlock, createVNode, withCtx, withModifiers, createCommentVNode, createTextVNode, toDisplayString, watch, onMounted, onUnmounted, reactive, toRaw, createElementVNode, renderSlot, Fragment, normalizeClass, resolveDynamicComponent, renderList, normalizeProps, mergeProps, getCurrentInstance, nextTick, Teleport, toHandlers, createSlots, provide } from 'vue';
2
2
  import serialize from 'serialize-javascript';
3
3
  import { Delete, Pointer, Close, Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Files, DocumentCopy, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom, Top, Bottom } from '@element-plus/icons';
4
4
  import { throttle, cloneDeep, mergeWith, random } from 'lodash-es';
@@ -666,10 +666,10 @@ class Props extends BaseService {
666
666
  }
667
667
  return value;
668
668
  }
669
- return cloneDeep({
669
+ return {
670
670
  ...getDefaultPropsValue(type),
671
- ...mergeWith(this.state.propsValueMap[type] || {}, defaultValue)
672
- });
671
+ ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), cloneDeep(defaultValue))
672
+ };
673
673
  }
674
674
  }
675
675
  var propsService = new Props();
@@ -754,9 +754,12 @@ const toRelative = (node) => {
754
754
  };
755
755
  const setTop2Middle = (node, parentNode, stage) => {
756
756
  const style = node.style || {};
757
- const height = style.height || 0;
758
- if (!stage || typeof style.top !== "undefined" || !parentNode.style || !isNumber(height))
757
+ let height = style.height || 0;
758
+ if (!stage || typeof style.top !== "undefined" || !parentNode.style)
759
759
  return style;
760
+ if (!isNumber(height)) {
761
+ height = 0;
762
+ }
760
763
  const { height: parentHeight } = parentNode.style;
761
764
  if (isPage(parentNode)) {
762
765
  const { scrollTop = 0, wrapperHeight } = stage.mask;
@@ -945,6 +948,13 @@ class Editor$1 extends BaseService {
945
948
  } else {
946
949
  historyService.empty();
947
950
  }
951
+ if (node?.id) {
952
+ this.get("stage")?.renderer.runtime?.getApp?.()?.emit("editor:select", {
953
+ node,
954
+ page,
955
+ parent
956
+ }, getNodePath(node.id, this.get("root").items));
957
+ }
948
958
  this.emit("select", node);
949
959
  return node;
950
960
  }
@@ -1133,6 +1143,9 @@ class Editor$1 extends BaseService {
1133
1143
  ...position
1134
1144
  };
1135
1145
  }
1146
+ if (isPage(config)) {
1147
+ config.name = generatePageNameByApp(this.get("root"));
1148
+ }
1136
1149
  return await this.add(config);
1137
1150
  }
1138
1151
  async alignCenter(config2) {
@@ -1142,7 +1155,17 @@ class Editor$1 extends BaseService {
1142
1155
  if (layout === Layout.RELATIVE) {
1143
1156
  return;
1144
1157
  }
1145
- if (parent.style?.width && node.style?.width) {
1158
+ if (!node.style)
1159
+ return;
1160
+ const stage = this.get("stage");
1161
+ const doc = stage?.renderer.contentWindow?.document;
1162
+ if (doc) {
1163
+ const parentEl = doc.getElementById(`${parent.id}`);
1164
+ const el = doc.getElementById(`${node.id}`);
1165
+ if (parentEl && el) {
1166
+ node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
1167
+ }
1168
+ } else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
1146
1169
  node.style.left = (parent.style.width - node.style.width) / 2;
1147
1170
  }
1148
1171
  await this.update(node);
@@ -1156,9 +1179,9 @@ class Editor$1 extends BaseService {
1156
1179
  const node = this.get("node");
1157
1180
  const brothers = parent?.items || [];
1158
1181
  const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
1159
- if (offset === LayerOffset.BOTTOM) {
1182
+ if (offset === LayerOffset.TOP) {
1160
1183
  brothers.splice(brothers.length - 1, 0, brothers.splice(index, 1)[0]);
1161
- } else if (offset === LayerOffset.TOP) {
1184
+ } else if (offset === LayerOffset.BOTTOM) {
1162
1185
  brothers.splice(0, 0, brothers.splice(index, 1)[0]);
1163
1186
  } else {
1164
1187
  brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
@@ -2226,9 +2249,14 @@ const _sfc_main$a = defineComponent({
2226
2249
  menuData: {
2227
2250
  type: Array,
2228
2251
  default: () => []
2252
+ },
2253
+ isSubMenu: {
2254
+ type: Boolean,
2255
+ default: false
2229
2256
  }
2230
2257
  },
2231
- setup() {
2258
+ emits: ["hide", "show"],
2259
+ setup(props, { emit }) {
2232
2260
  const menu = ref();
2233
2261
  const subMenu = ref();
2234
2262
  const visible = ref(false);
@@ -2238,15 +2266,31 @@ const _sfc_main$a = defineComponent({
2238
2266
  top: "0"
2239
2267
  });
2240
2268
  const hide = () => {
2269
+ if (!visible.value)
2270
+ return;
2241
2271
  visible.value = false;
2272
+ subMenu.value?.hide();
2273
+ emit("hide");
2274
+ };
2275
+ const hideHandler = (e) => {
2276
+ const target = e.target;
2277
+ if (!visible.value || !target) {
2278
+ return;
2279
+ }
2280
+ if (menu.value?.contains(target) || subMenu.value?.$el?.contains(target)) {
2281
+ return;
2282
+ }
2283
+ hide();
2242
2284
  };
2243
2285
  onMounted(() => {
2244
- globalThis.addEventListener("mousedown", (e) => {
2245
- if (!visible.value || e.target && menu.value?.contains(e.target)) {
2246
- return;
2247
- }
2248
- hide();
2249
- }, true);
2286
+ if (props.isSubMenu)
2287
+ return;
2288
+ globalThis.addEventListener("mousedown", hideHandler, true);
2289
+ });
2290
+ onUnmounted(() => {
2291
+ if (props.isSubMenu)
2292
+ return;
2293
+ globalThis.removeEventListener("mousedown", hideHandler, true);
2250
2294
  });
2251
2295
  return {
2252
2296
  menu,
@@ -2256,18 +2300,21 @@ const _sfc_main$a = defineComponent({
2256
2300
  subMenuData,
2257
2301
  hide,
2258
2302
  show(e) {
2259
- visible.value = true;
2260
- nextTick(() => {
2261
- const menuHeight = menu.value?.clientHeight || 0;
2262
- let top = e.clientY;
2263
- if (menuHeight + e.clientY > document.body.clientHeight) {
2264
- top = document.body.clientHeight - menuHeight;
2265
- }
2266
- menuStyle.value = {
2267
- top: `${top}px`,
2268
- left: `${e.clientX}px`
2269
- };
2270
- });
2303
+ setTimeout(() => {
2304
+ visible.value = true;
2305
+ nextTick(() => {
2306
+ const menuHeight = menu.value?.clientHeight || 0;
2307
+ let top = e.clientY;
2308
+ if (menuHeight + e.clientY > document.body.clientHeight) {
2309
+ top = document.body.clientHeight - menuHeight;
2310
+ }
2311
+ menuStyle.value = {
2312
+ top: `${top}px`,
2313
+ left: `${e.clientX}px`
2314
+ };
2315
+ emit("show");
2316
+ });
2317
+ }, 300);
2271
2318
  },
2272
2319
  showSubMenu(item) {
2273
2320
  const menuItem = item;
@@ -2288,7 +2335,7 @@ const _sfc_main$a = defineComponent({
2288
2335
  function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2289
2336
  const _component_tool_button = resolveComponent("tool-button");
2290
2337
  const _component_content_menu = resolveComponent("content-menu", true);
2291
- return _ctx.menuData.length ? withDirectives((openBlock(), createElementBlock("div", {
2338
+ return _ctx.menuData.length && _ctx.visible ? (openBlock(), createElementBlock("div", {
2292
2339
  key: 0,
2293
2340
  class: "magic-editor-content-menu",
2294
2341
  ref: "menu",
@@ -2309,12 +2356,12 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2309
2356
  createVNode(_component_content_menu, {
2310
2357
  class: "sub-menu",
2311
2358
  ref: "subMenu",
2312
- "menu-data": _ctx.subMenuData
2313
- }, null, 8, ["menu-data"])
2359
+ "menu-data": _ctx.subMenuData,
2360
+ "is-sub-menu": true,
2361
+ onHide: _ctx.hide
2362
+ }, null, 8, ["menu-data", "onHide"])
2314
2363
  ]))
2315
- ], 4)), [
2316
- [vShow, _ctx.visible]
2317
- ]) : createCommentVNode("", true);
2364
+ ], 4)) : createCommentVNode("", true);
2318
2365
  }
2319
2366
  var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2320
2367
 
@@ -2327,6 +2374,7 @@ const _sfc_main$9 = defineComponent({
2327
2374
  const isRoot = computed(() => node.value?.type === NodeType.ROOT);
2328
2375
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
2329
2376
  const componentList = computed(() => services?.componentListService.getList() || []);
2377
+ const layerContentMenu = inject("layerContentMenu", []);
2330
2378
  const createMenuItems = (group) => group.items.map((component) => ({
2331
2379
  text: component.text,
2332
2380
  type: "button",
@@ -2391,7 +2439,8 @@ const _sfc_main$9 = defineComponent({
2391
2439
  handler: () => {
2392
2440
  node.value && services?.editorService.remove(node.value);
2393
2441
  }
2394
- }
2442
+ },
2443
+ ...layerContentMenu
2395
2444
  ]),
2396
2445
  show(e) {
2397
2446
  menu.value?.show(e);
@@ -2614,7 +2663,7 @@ const _sfc_main$7 = defineComponent({
2614
2663
  components: { MIcon },
2615
2664
  props: {
2616
2665
  data: {
2617
- type: Object
2666
+ type: [Object, String]
2618
2667
  }
2619
2668
  },
2620
2669
  setup(props) {
@@ -3182,6 +3231,7 @@ const _sfc_main$3 = defineComponent({
3182
3231
  const node = computed(() => editorService?.get("node"));
3183
3232
  const parent = computed(() => editorService?.get("parent"));
3184
3233
  const isPage = computed(() => node.value?.type === NodeType.PAGE);
3234
+ const stageContentMenu = inject("stageContentMenu", []);
3185
3235
  onMounted(() => {
3186
3236
  const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3187
3237
  canPaste.value = data !== "undefined" && !!data;
@@ -3217,8 +3267,17 @@ const _sfc_main$3 = defineComponent({
3217
3267
  text: "\u7C98\u8D34",
3218
3268
  display: () => canPaste.value,
3219
3269
  handler: () => {
3220
- const top = menu.value?.$el.offsetTop || 0;
3221
- const left = menu.value?.$el.offsetLeft || 0;
3270
+ const stage = editorService?.get("stage");
3271
+ const rect = menu.value?.$el.getBoundingClientRect();
3272
+ const parentRect = stage?.container?.getBoundingClientRect();
3273
+ let left = (rect?.left || 0) - (parentRect?.left || 0);
3274
+ let top = (rect?.top || 0) - (parentRect?.top || 0);
3275
+ if (node.value?.items && stage) {
3276
+ const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
3277
+ const parentElRect = parentEl?.getBoundingClientRect();
3278
+ left = left - (parentElRect?.left || 0);
3279
+ top = top - (parentElRect?.top || 0);
3280
+ }
3222
3281
  editorService?.paste({ left, top });
3223
3282
  }
3224
3283
  },
@@ -3285,7 +3344,8 @@ const _sfc_main$3 = defineComponent({
3285
3344
  handler: () => {
3286
3345
  editorService?.get("stage").clearGuides();
3287
3346
  }
3288
- }
3347
+ },
3348
+ ...stageContentMenu
3289
3349
  ]),
3290
3350
  show(e) {
3291
3351
  menu.value?.show(e);
@@ -3515,10 +3575,7 @@ const _sfc_main$1 = defineComponent({
3515
3575
  keycon = new KeyController(workspace.value);
3516
3576
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
3517
3577
  const ctrl = isMac ? "meta" : "ctrl";
3518
- keycon.keydown((e) => {
3519
- console.log(e);
3520
- e.inputEvent.preventDefault();
3521
- }).keyup("delete", (e) => {
3578
+ keycon.keyup("delete", (e) => {
3522
3579
  e.inputEvent.preventDefault();
3523
3580
  if (!node.value || isPage(node.value))
3524
3581
  return;
@@ -3528,46 +3585,65 @@ const _sfc_main$1 = defineComponent({
3528
3585
  if (!node.value || isPage(node.value))
3529
3586
  return;
3530
3587
  services?.editorService.remove(node.value);
3531
- }).keydown([ctrl, "c"], () => {
3588
+ }).keydown([ctrl, "c"], (e) => {
3589
+ e.inputEvent.preventDefault();
3532
3590
  node.value && services?.editorService.copy(node.value);
3533
- }).keydown([ctrl, "v"], () => {
3591
+ }).keydown([ctrl, "v"], (e) => {
3592
+ e.inputEvent.preventDefault();
3534
3593
  node.value && services?.editorService.paste();
3535
- }).keydown([ctrl, "x"], () => {
3594
+ }).keydown([ctrl, "x"], (e) => {
3595
+ e.inputEvent.preventDefault();
3536
3596
  if (!node.value || isPage(node.value))
3537
3597
  return;
3538
3598
  services?.editorService.copy(node.value);
3539
3599
  services?.editorService.remove(node.value);
3540
- }).keydown([ctrl, "z"], () => {
3600
+ }).keydown([ctrl, "z"], (e) => {
3601
+ e.inputEvent.preventDefault();
3541
3602
  services?.editorService.undo();
3542
- }).keydown([ctrl, "shift", "z"], () => {
3603
+ }).keydown([ctrl, "shift", "z"], (e) => {
3604
+ e.inputEvent.preventDefault();
3543
3605
  services?.editorService.redo();
3544
- }).keydown("up", () => {
3606
+ }).keydown("up", (e) => {
3607
+ e.inputEvent.preventDefault();
3545
3608
  services?.editorService.move(0, -1);
3546
- }).keydown("down", () => {
3609
+ }).keydown("down", (e) => {
3610
+ e.inputEvent.preventDefault();
3547
3611
  services?.editorService.move(0, 1);
3548
- }).keydown("left", () => {
3612
+ }).keydown("left", (e) => {
3613
+ e.inputEvent.preventDefault();
3549
3614
  services?.editorService.move(-1, 0);
3550
- }).keydown("right", () => {
3615
+ }).keydown("right", (e) => {
3616
+ e.inputEvent.preventDefault();
3551
3617
  services?.editorService.move(1, 0);
3552
- }).keydown([ctrl, "up"], () => {
3618
+ }).keydown([ctrl, "up"], (e) => {
3619
+ e.inputEvent.preventDefault();
3553
3620
  services?.editorService.move(0, -10);
3554
- }).keydown([ctrl, "down"], () => {
3621
+ }).keydown([ctrl, "down"], (e) => {
3622
+ e.inputEvent.preventDefault();
3555
3623
  services?.editorService.move(0, 10);
3556
- }).keydown([ctrl, "left"], () => {
3624
+ }).keydown([ctrl, "left"], (e) => {
3625
+ e.inputEvent.preventDefault();
3557
3626
  services?.editorService.move(-10, 0);
3558
- }).keydown([ctrl, "right"], () => {
3627
+ }).keydown([ctrl, "right"], (e) => {
3628
+ e.inputEvent.preventDefault();
3559
3629
  services?.editorService.move(10, 0);
3560
- }).keydown("tab", () => {
3630
+ }).keydown("tab", (e) => {
3631
+ e.inputEvent.preventDefault();
3561
3632
  services?.editorService.selectNextNode();
3562
- }).keydown([ctrl, "tab"], () => {
3633
+ }).keydown([ctrl, "tab"], (e) => {
3634
+ e.inputEvent.preventDefault();
3563
3635
  services?.editorService.selectNextPage();
3564
- }).keydown([ctrl, "="], () => {
3636
+ }).keydown([ctrl, "="], (e) => {
3637
+ e.inputEvent.preventDefault();
3565
3638
  services?.uiService.zoom(0.1);
3566
- }).keydown([ctrl, "numpadplus"], () => {
3639
+ }).keydown([ctrl, "numpadplus"], (e) => {
3640
+ e.inputEvent.preventDefault();
3567
3641
  services?.uiService.zoom(0.1);
3568
- }).keydown([ctrl, "-"], () => {
3642
+ }).keydown([ctrl, "-"], (e) => {
3643
+ e.inputEvent.preventDefault();
3569
3644
  services?.uiService.zoom(-0.1);
3570
- }).keydown([ctrl, "numpad-"], () => {
3645
+ }).keydown([ctrl, "numpad-"], (e) => {
3646
+ e.inputEvent.preventDefault();
3571
3647
  services?.uiService.zoom(-0.1);
3572
3648
  });
3573
3649
  });
@@ -3767,6 +3843,14 @@ const _sfc_main = defineComponent({
3767
3843
  sidebar: {
3768
3844
  type: Object
3769
3845
  },
3846
+ layerContentMenu: {
3847
+ type: Array,
3848
+ default: () => []
3849
+ },
3850
+ stageContentMenu: {
3851
+ type: Array,
3852
+ default: () => []
3853
+ },
3770
3854
  menu: {
3771
3855
  type: Object,
3772
3856
  default: () => ({ left: [], right: [] })
@@ -3852,6 +3936,8 @@ const _sfc_main = defineComponent({
3852
3936
  uiService
3853
3937
  };
3854
3938
  provide("services", services);
3939
+ provide("layerContentMenu", props.layerContentMenu);
3940
+ provide("stageContentMenu", props.stageContentMenu);
3855
3941
  return services;
3856
3942
  }
3857
3943
  });