@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,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('@element-plus/icons'), require('lodash-es'), require('monaco-editor'), require('@tmagic/schema'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('gesto'), require('element-plus'), require('keycon'), require('@tmagic/stage')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', '@element-plus/icons', 'lodash-es', 'monaco-editor', '@tmagic/schema', '@tmagic/utils', 'events', '@tmagic/core', 'gesto', 'element-plus', 'keycon', '@tmagic/stage'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.schema, global.utils, global.events, global.core, global.Gesto, global.elementPlus, global.KeyController, global.StageCore));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.Vue, global.serialize, global.icons, global.lodashEs, global.monaco, global.schema, global.utils, global.events, global.core, global.Gesto, global.ElementPlus, global.KeyController, global.StageCore));
5
5
  })(this, (function (exports, vue, serialize, icons, lodashEs, monaco, schema, utils, events, core, Gesto, elementPlus, KeyController, StageCore) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -684,10 +684,10 @@
684
684
  }
685
685
  return value;
686
686
  }
687
- return lodashEs.cloneDeep({
687
+ return {
688
688
  ...getDefaultPropsValue(type),
689
- ...lodashEs.mergeWith(this.state.propsValueMap[type] || {}, defaultValue)
690
- });
689
+ ...lodashEs.mergeWith(lodashEs.cloneDeep(this.state.propsValueMap[type] || {}), lodashEs.cloneDeep(defaultValue))
690
+ };
691
691
  }
692
692
  }
693
693
  var propsService = new Props();
@@ -772,9 +772,12 @@
772
772
  };
773
773
  const setTop2Middle = (node, parentNode, stage) => {
774
774
  const style = node.style || {};
775
- const height = style.height || 0;
776
- if (!stage || typeof style.top !== "undefined" || !parentNode.style || !utils.isNumber(height))
775
+ let height = style.height || 0;
776
+ if (!stage || typeof style.top !== "undefined" || !parentNode.style)
777
777
  return style;
778
+ if (!utils.isNumber(height)) {
779
+ height = 0;
780
+ }
778
781
  const { height: parentHeight } = parentNode.style;
779
782
  if (utils.isPage(parentNode)) {
780
783
  const { scrollTop = 0, wrapperHeight } = stage.mask;
@@ -963,6 +966,13 @@
963
966
  } else {
964
967
  historyService.empty();
965
968
  }
969
+ if (node?.id) {
970
+ this.get("stage")?.renderer.runtime?.getApp?.()?.emit("editor:select", {
971
+ node,
972
+ page,
973
+ parent
974
+ }, utils.getNodePath(node.id, this.get("root").items));
975
+ }
966
976
  this.emit("select", node);
967
977
  return node;
968
978
  }
@@ -1151,6 +1161,9 @@
1151
1161
  ...position
1152
1162
  };
1153
1163
  }
1164
+ if (utils.isPage(config)) {
1165
+ config.name = generatePageNameByApp(this.get("root"));
1166
+ }
1154
1167
  return await this.add(config);
1155
1168
  }
1156
1169
  async alignCenter(config2) {
@@ -1160,7 +1173,17 @@
1160
1173
  if (layout === Layout.RELATIVE) {
1161
1174
  return;
1162
1175
  }
1163
- if (parent.style?.width && node.style?.width) {
1176
+ if (!node.style)
1177
+ return;
1178
+ const stage = this.get("stage");
1179
+ const doc = stage?.renderer.contentWindow?.document;
1180
+ if (doc) {
1181
+ const parentEl = doc.getElementById(`${parent.id}`);
1182
+ const el = doc.getElementById(`${node.id}`);
1183
+ if (parentEl && el) {
1184
+ node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
1185
+ }
1186
+ } else if (parent.style && utils.isNumber(parent.style?.width) && utils.isNumber(node.style?.width)) {
1164
1187
  node.style.left = (parent.style.width - node.style.width) / 2;
1165
1188
  }
1166
1189
  await this.update(node);
@@ -1174,9 +1197,9 @@
1174
1197
  const node = this.get("node");
1175
1198
  const brothers = parent?.items || [];
1176
1199
  const index = brothers.findIndex((item) => `${item.id}` === `${node?.id}`);
1177
- if (offset === LayerOffset.BOTTOM) {
1200
+ if (offset === LayerOffset.TOP) {
1178
1201
  brothers.splice(brothers.length - 1, 0, brothers.splice(index, 1)[0]);
1179
- } else if (offset === LayerOffset.TOP) {
1202
+ } else if (offset === LayerOffset.BOTTOM) {
1180
1203
  brothers.splice(0, 0, brothers.splice(index, 1)[0]);
1181
1204
  } else {
1182
1205
  brothers.splice(index + parseInt(`${offset}`, 10), 0, brothers.splice(index, 1)[0]);
@@ -2244,9 +2267,14 @@
2244
2267
  menuData: {
2245
2268
  type: Array,
2246
2269
  default: () => []
2270
+ },
2271
+ isSubMenu: {
2272
+ type: Boolean,
2273
+ default: false
2247
2274
  }
2248
2275
  },
2249
- setup() {
2276
+ emits: ["hide", "show"],
2277
+ setup(props, { emit }) {
2250
2278
  const menu = vue.ref();
2251
2279
  const subMenu = vue.ref();
2252
2280
  const visible = vue.ref(false);
@@ -2256,15 +2284,31 @@
2256
2284
  top: "0"
2257
2285
  });
2258
2286
  const hide = () => {
2287
+ if (!visible.value)
2288
+ return;
2259
2289
  visible.value = false;
2290
+ subMenu.value?.hide();
2291
+ emit("hide");
2292
+ };
2293
+ const hideHandler = (e) => {
2294
+ const target = e.target;
2295
+ if (!visible.value || !target) {
2296
+ return;
2297
+ }
2298
+ if (menu.value?.contains(target) || subMenu.value?.$el?.contains(target)) {
2299
+ return;
2300
+ }
2301
+ hide();
2260
2302
  };
2261
2303
  vue.onMounted(() => {
2262
- globalThis.addEventListener("mousedown", (e) => {
2263
- if (!visible.value || e.target && menu.value?.contains(e.target)) {
2264
- return;
2265
- }
2266
- hide();
2267
- }, true);
2304
+ if (props.isSubMenu)
2305
+ return;
2306
+ globalThis.addEventListener("mousedown", hideHandler, true);
2307
+ });
2308
+ vue.onUnmounted(() => {
2309
+ if (props.isSubMenu)
2310
+ return;
2311
+ globalThis.removeEventListener("mousedown", hideHandler, true);
2268
2312
  });
2269
2313
  return {
2270
2314
  menu,
@@ -2274,18 +2318,21 @@
2274
2318
  subMenuData,
2275
2319
  hide,
2276
2320
  show(e) {
2277
- visible.value = true;
2278
- vue.nextTick(() => {
2279
- const menuHeight = menu.value?.clientHeight || 0;
2280
- let top = e.clientY;
2281
- if (menuHeight + e.clientY > document.body.clientHeight) {
2282
- top = document.body.clientHeight - menuHeight;
2283
- }
2284
- menuStyle.value = {
2285
- top: `${top}px`,
2286
- left: `${e.clientX}px`
2287
- };
2288
- });
2321
+ setTimeout(() => {
2322
+ visible.value = true;
2323
+ vue.nextTick(() => {
2324
+ const menuHeight = menu.value?.clientHeight || 0;
2325
+ let top = e.clientY;
2326
+ if (menuHeight + e.clientY > document.body.clientHeight) {
2327
+ top = document.body.clientHeight - menuHeight;
2328
+ }
2329
+ menuStyle.value = {
2330
+ top: `${top}px`,
2331
+ left: `${e.clientX}px`
2332
+ };
2333
+ emit("show");
2334
+ });
2335
+ }, 300);
2289
2336
  },
2290
2337
  showSubMenu(item) {
2291
2338
  const menuItem = item;
@@ -2306,7 +2353,7 @@
2306
2353
  function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
2307
2354
  const _component_tool_button = vue.resolveComponent("tool-button");
2308
2355
  const _component_content_menu = vue.resolveComponent("content-menu", true);
2309
- return _ctx.menuData.length ? vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
2356
+ return _ctx.menuData.length && _ctx.visible ? (vue.openBlock(), vue.createElementBlock("div", {
2310
2357
  key: 0,
2311
2358
  class: "magic-editor-content-menu",
2312
2359
  ref: "menu",
@@ -2327,12 +2374,12 @@
2327
2374
  vue.createVNode(_component_content_menu, {
2328
2375
  class: "sub-menu",
2329
2376
  ref: "subMenu",
2330
- "menu-data": _ctx.subMenuData
2331
- }, null, 8, ["menu-data"])
2377
+ "menu-data": _ctx.subMenuData,
2378
+ "is-sub-menu": true,
2379
+ onHide: _ctx.hide
2380
+ }, null, 8, ["menu-data", "onHide"])
2332
2381
  ]))
2333
- ], 4)), [
2334
- [vue.vShow, _ctx.visible]
2335
- ]) : vue.createCommentVNode("", true);
2382
+ ], 4)) : vue.createCommentVNode("", true);
2336
2383
  }
2337
2384
  var ContentMenu = /* @__PURE__ */ _export_sfc(_sfc_main$a, [["render", _sfc_render$a]]);
2338
2385
 
@@ -2345,6 +2392,7 @@
2345
2392
  const isRoot = vue.computed(() => node.value?.type === schema.NodeType.ROOT);
2346
2393
  const isPage = vue.computed(() => node.value?.type === schema.NodeType.PAGE);
2347
2394
  const componentList = vue.computed(() => services?.componentListService.getList() || []);
2395
+ const layerContentMenu = vue.inject("layerContentMenu", []);
2348
2396
  const createMenuItems = (group) => group.items.map((component) => ({
2349
2397
  text: component.text,
2350
2398
  type: "button",
@@ -2409,7 +2457,8 @@
2409
2457
  handler: () => {
2410
2458
  node.value && services?.editorService.remove(node.value);
2411
2459
  }
2412
- }
2460
+ },
2461
+ ...layerContentMenu
2413
2462
  ]),
2414
2463
  show(e) {
2415
2464
  menu.value?.show(e);
@@ -2632,7 +2681,7 @@
2632
2681
  components: { MIcon },
2633
2682
  props: {
2634
2683
  data: {
2635
- type: Object
2684
+ type: [Object, String]
2636
2685
  }
2637
2686
  },
2638
2687
  setup(props) {
@@ -3200,6 +3249,7 @@
3200
3249
  const node = vue.computed(() => editorService?.get("node"));
3201
3250
  const parent = vue.computed(() => editorService?.get("parent"));
3202
3251
  const isPage = vue.computed(() => node.value?.type === schema.NodeType.PAGE);
3252
+ const stageContentMenu = vue.inject("stageContentMenu", []);
3203
3253
  vue.onMounted(() => {
3204
3254
  const data = globalThis.localStorage.getItem(COPY_STORAGE_KEY);
3205
3255
  canPaste.value = data !== "undefined" && !!data;
@@ -3235,8 +3285,17 @@
3235
3285
  text: "\u7C98\u8D34",
3236
3286
  display: () => canPaste.value,
3237
3287
  handler: () => {
3238
- const top = menu.value?.$el.offsetTop || 0;
3239
- const left = menu.value?.$el.offsetLeft || 0;
3288
+ const stage = editorService?.get("stage");
3289
+ const rect = menu.value?.$el.getBoundingClientRect();
3290
+ const parentRect = stage?.container?.getBoundingClientRect();
3291
+ let left = (rect?.left || 0) - (parentRect?.left || 0);
3292
+ let top = (rect?.top || 0) - (parentRect?.top || 0);
3293
+ if (node.value?.items && stage) {
3294
+ const parentEl = stage.renderer.contentWindow?.document.getElementById(`${node.value.id}`);
3295
+ const parentElRect = parentEl?.getBoundingClientRect();
3296
+ left = left - (parentElRect?.left || 0);
3297
+ top = top - (parentElRect?.top || 0);
3298
+ }
3240
3299
  editorService?.paste({ left, top });
3241
3300
  }
3242
3301
  },
@@ -3303,7 +3362,8 @@
3303
3362
  handler: () => {
3304
3363
  editorService?.get("stage").clearGuides();
3305
3364
  }
3306
- }
3365
+ },
3366
+ ...stageContentMenu
3307
3367
  ]),
3308
3368
  show(e) {
3309
3369
  menu.value?.show(e);
@@ -3533,10 +3593,7 @@
3533
3593
  keycon = new KeyController__default["default"](workspace.value);
3534
3594
  const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
3535
3595
  const ctrl = isMac ? "meta" : "ctrl";
3536
- keycon.keydown((e) => {
3537
- console.log(e);
3538
- e.inputEvent.preventDefault();
3539
- }).keyup("delete", (e) => {
3596
+ keycon.keyup("delete", (e) => {
3540
3597
  e.inputEvent.preventDefault();
3541
3598
  if (!node.value || utils.isPage(node.value))
3542
3599
  return;
@@ -3546,46 +3603,65 @@
3546
3603
  if (!node.value || utils.isPage(node.value))
3547
3604
  return;
3548
3605
  services?.editorService.remove(node.value);
3549
- }).keydown([ctrl, "c"], () => {
3606
+ }).keydown([ctrl, "c"], (e) => {
3607
+ e.inputEvent.preventDefault();
3550
3608
  node.value && services?.editorService.copy(node.value);
3551
- }).keydown([ctrl, "v"], () => {
3609
+ }).keydown([ctrl, "v"], (e) => {
3610
+ e.inputEvent.preventDefault();
3552
3611
  node.value && services?.editorService.paste();
3553
- }).keydown([ctrl, "x"], () => {
3612
+ }).keydown([ctrl, "x"], (e) => {
3613
+ e.inputEvent.preventDefault();
3554
3614
  if (!node.value || utils.isPage(node.value))
3555
3615
  return;
3556
3616
  services?.editorService.copy(node.value);
3557
3617
  services?.editorService.remove(node.value);
3558
- }).keydown([ctrl, "z"], () => {
3618
+ }).keydown([ctrl, "z"], (e) => {
3619
+ e.inputEvent.preventDefault();
3559
3620
  services?.editorService.undo();
3560
- }).keydown([ctrl, "shift", "z"], () => {
3621
+ }).keydown([ctrl, "shift", "z"], (e) => {
3622
+ e.inputEvent.preventDefault();
3561
3623
  services?.editorService.redo();
3562
- }).keydown("up", () => {
3624
+ }).keydown("up", (e) => {
3625
+ e.inputEvent.preventDefault();
3563
3626
  services?.editorService.move(0, -1);
3564
- }).keydown("down", () => {
3627
+ }).keydown("down", (e) => {
3628
+ e.inputEvent.preventDefault();
3565
3629
  services?.editorService.move(0, 1);
3566
- }).keydown("left", () => {
3630
+ }).keydown("left", (e) => {
3631
+ e.inputEvent.preventDefault();
3567
3632
  services?.editorService.move(-1, 0);
3568
- }).keydown("right", () => {
3633
+ }).keydown("right", (e) => {
3634
+ e.inputEvent.preventDefault();
3569
3635
  services?.editorService.move(1, 0);
3570
- }).keydown([ctrl, "up"], () => {
3636
+ }).keydown([ctrl, "up"], (e) => {
3637
+ e.inputEvent.preventDefault();
3571
3638
  services?.editorService.move(0, -10);
3572
- }).keydown([ctrl, "down"], () => {
3639
+ }).keydown([ctrl, "down"], (e) => {
3640
+ e.inputEvent.preventDefault();
3573
3641
  services?.editorService.move(0, 10);
3574
- }).keydown([ctrl, "left"], () => {
3642
+ }).keydown([ctrl, "left"], (e) => {
3643
+ e.inputEvent.preventDefault();
3575
3644
  services?.editorService.move(-10, 0);
3576
- }).keydown([ctrl, "right"], () => {
3645
+ }).keydown([ctrl, "right"], (e) => {
3646
+ e.inputEvent.preventDefault();
3577
3647
  services?.editorService.move(10, 0);
3578
- }).keydown("tab", () => {
3648
+ }).keydown("tab", (e) => {
3649
+ e.inputEvent.preventDefault();
3579
3650
  services?.editorService.selectNextNode();
3580
- }).keydown([ctrl, "tab"], () => {
3651
+ }).keydown([ctrl, "tab"], (e) => {
3652
+ e.inputEvent.preventDefault();
3581
3653
  services?.editorService.selectNextPage();
3582
- }).keydown([ctrl, "="], () => {
3654
+ }).keydown([ctrl, "="], (e) => {
3655
+ e.inputEvent.preventDefault();
3583
3656
  services?.uiService.zoom(0.1);
3584
- }).keydown([ctrl, "numpadplus"], () => {
3657
+ }).keydown([ctrl, "numpadplus"], (e) => {
3658
+ e.inputEvent.preventDefault();
3585
3659
  services?.uiService.zoom(0.1);
3586
- }).keydown([ctrl, "-"], () => {
3660
+ }).keydown([ctrl, "-"], (e) => {
3661
+ e.inputEvent.preventDefault();
3587
3662
  services?.uiService.zoom(-0.1);
3588
- }).keydown([ctrl, "numpad-"], () => {
3663
+ }).keydown([ctrl, "numpad-"], (e) => {
3664
+ e.inputEvent.preventDefault();
3589
3665
  services?.uiService.zoom(-0.1);
3590
3666
  });
3591
3667
  });
@@ -3785,6 +3861,14 @@
3785
3861
  sidebar: {
3786
3862
  type: Object
3787
3863
  },
3864
+ layerContentMenu: {
3865
+ type: Array,
3866
+ default: () => []
3867
+ },
3868
+ stageContentMenu: {
3869
+ type: Array,
3870
+ default: () => []
3871
+ },
3788
3872
  menu: {
3789
3873
  type: Object,
3790
3874
  default: () => ({ left: [], right: [] })
@@ -3870,6 +3954,8 @@
3870
3954
  uiService
3871
3955
  };
3872
3956
  vue.provide("services", services);
3957
+ vue.provide("layerContentMenu", props.layerContentMenu);
3958
+ vue.provide("stageContentMenu", props.stageContentMenu);
3873
3959
  return services;
3874
3960
  }
3875
3961
  });