@tmagic/editor 1.0.0-beta.12 → 1.0.0-beta.13

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 (77) hide show
  1. package/coverage/clover.xml +1444 -0
  2. package/coverage/coverage-final.json +34 -0
  3. package/coverage/lcov-report/Icon.vue.html +172 -0
  4. package/coverage/lcov-report/ToolButton.vue.html +655 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +206 -0
  9. package/coverage/lcov-report/layouts/sidebar/LayerMenu.vue.html +364 -0
  10. package/coverage/lcov-report/layouts/sidebar/index.html +116 -0
  11. package/coverage/lcov-report/prettify.css +1 -0
  12. package/coverage/lcov-report/prettify.js +2 -0
  13. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  14. package/coverage/lcov-report/sorter.js +196 -0
  15. package/coverage/lcov-report/src/Editor.vue.html +787 -0
  16. package/coverage/lcov-report/src/components/Icon.vue.html +172 -0
  17. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +283 -0
  18. package/coverage/lcov-report/src/components/ToolButton.vue.html +655 -0
  19. package/coverage/lcov-report/src/components/index.html +146 -0
  20. package/coverage/lcov-report/src/index.html +131 -0
  21. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +214 -0
  22. package/coverage/lcov-report/src/layouts/Framework.vue.html +304 -0
  23. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +208 -0
  24. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +316 -0
  25. package/coverage/lcov-report/src/layouts/Resizer.vue.html +268 -0
  26. package/coverage/lcov-report/src/layouts/index.html +176 -0
  27. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +292 -0
  28. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +364 -0
  29. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +853 -0
  30. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +343 -0
  31. package/coverage/lcov-report/src/layouts/sidebar/index.html +161 -0
  32. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +631 -0
  33. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +766 -0
  34. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +421 -0
  35. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +586 -0
  36. package/coverage/lcov-report/src/layouts/workspace/index.html +161 -0
  37. package/coverage/lcov-report/src/services/BaseService.ts.html +643 -0
  38. package/coverage/lcov-report/src/services/componentList.ts.html +229 -0
  39. package/coverage/lcov-report/src/services/editor.ts.html +1984 -0
  40. package/coverage/lcov-report/src/services/events.ts.html +331 -0
  41. package/coverage/lcov-report/src/services/history.ts.html +457 -0
  42. package/coverage/lcov-report/src/services/index.html +206 -0
  43. package/coverage/lcov-report/src/services/props.ts.html +418 -0
  44. package/coverage/lcov-report/src/services/ui.ts.html +514 -0
  45. package/coverage/lcov-report/src/type.ts.html +850 -0
  46. package/coverage/lcov-report/src/utils/compose.ts.html +184 -0
  47. package/coverage/lcov-report/src/utils/config.ts.html +172 -0
  48. package/coverage/lcov-report/src/utils/editor.ts.html +838 -0
  49. package/coverage/lcov-report/src/utils/index.html +221 -0
  50. package/coverage/lcov-report/src/utils/index.ts.html +151 -0
  51. package/coverage/lcov-report/src/utils/logger.ts.html +226 -0
  52. package/coverage/lcov-report/src/utils/props.ts.html +739 -0
  53. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +733 -0
  54. package/coverage/lcov-report/src/utils/undo-redo.ts.html +313 -0
  55. package/coverage/lcov-report/utils/index.html +116 -0
  56. package/coverage/lcov-report/utils/undo-redo.ts.html +313 -0
  57. package/coverage/lcov.info +3407 -0
  58. package/dist/style.css +3 -2
  59. package/dist/tmagic-editor.es.js +326 -194
  60. package/dist/tmagic-editor.es.js.map +1 -1
  61. package/dist/tmagic-editor.umd.js +328 -197
  62. package/dist/tmagic-editor.umd.js.map +1 -1
  63. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +1 -1
  64. package/dist/types/src/services/editor.d.ts +5 -2
  65. package/dist/types/src/services/ui.d.ts +1 -0
  66. package/dist/types/src/utils/editor.d.ts +2 -2
  67. package/package.json +18 -9
  68. package/src/components/ScrollViewer.vue +1 -1
  69. package/src/components/ToolButton.vue +3 -3
  70. package/src/layouts/workspace/Workspace.vue +74 -16
  71. package/src/services/BaseService.ts +1 -1
  72. package/src/services/editor.ts +65 -9
  73. package/src/services/ui.ts +5 -0
  74. package/src/theme/layer-panel.scss +1 -0
  75. package/src/utils/editor.ts +6 -2
  76. package/tsconfig.json +0 -9
  77. package/vite.config.ts +0 -30
@@ -8,7 +8,7 @@
8
8
 
9
9
  function _interopNamespace(e) {
10
10
  if (e && e.__esModule) return e;
11
- var n = {__proto__: null, [Symbol.toStringTag]: 'Module'};
11
+ var n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
12
12
  if (e) {
13
13
  Object.keys(e).forEach(function (k) {
14
14
  if (k !== 'default') {
@@ -360,9 +360,6 @@
360
360
  const getConfig = (key) => $TMAGIC_EDITOR[key];
361
361
 
362
362
  class UndoRedo {
363
- elementList;
364
- listCursor;
365
- listMaxSize;
366
363
  constructor(listMaxSize = 200) {
367
364
  const minListMaxSize = 2;
368
365
  this.elementList = [];
@@ -453,7 +450,7 @@
453
450
  }
454
451
  let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
455
452
  for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
456
- returnValue = await afterMethod(...beforeArgs, returnValue);
453
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
457
454
  if (isError(returnValue))
458
455
  throw returnValue;
459
456
  }
@@ -463,12 +460,12 @@
463
460
  }
464
461
  };
465
462
  class BaseService extends events.EventEmitter {
466
- pluginOptionsList = {};
467
- middleware = {};
468
- taskList = [];
469
- doingTask = false;
470
463
  constructor(methods = [], serialMethods = []) {
471
464
  super();
465
+ this.pluginOptionsList = {};
466
+ this.middleware = {};
467
+ this.taskList = [];
468
+ this.doingTask = false;
472
469
  methods.forEach((propertyName) => {
473
470
  const scope = this;
474
471
  const sourceMethod = scope[propertyName];
@@ -525,14 +522,14 @@
525
522
  }
526
523
 
527
524
  class History extends BaseService {
528
- state = vue.reactive({
529
- pageSteps: {},
530
- pageId: void 0,
531
- canRedo: false,
532
- canUndo: false
533
- });
534
525
  constructor() {
535
526
  super([]);
527
+ this.state = vue.reactive({
528
+ pageSteps: {},
529
+ pageId: void 0,
530
+ canRedo: false,
531
+ canUndo: false
532
+ });
536
533
  this.on("change", this.setCanUndoRedo);
537
534
  }
538
535
  changePage(page) {
@@ -598,12 +595,12 @@
598
595
  var historyService = new History();
599
596
 
600
597
  class Props extends BaseService {
601
- state = vue.reactive({
602
- propsConfigMap: {},
603
- propsValueMap: {}
604
- });
605
598
  constructor() {
606
599
  super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
600
+ this.state = vue.reactive({
601
+ propsConfigMap: {},
602
+ propsValueMap: {}
603
+ });
607
604
  }
608
605
  setPropsConfigs(configs) {
609
606
  Object.keys(configs).forEach((type) => {
@@ -826,16 +823,6 @@
826
823
  };
827
824
 
828
825
  class Editor$1 extends BaseService {
829
- isHistoryStateChange = false;
830
- state = vue.reactive({
831
- root: null,
832
- page: null,
833
- parent: null,
834
- node: null,
835
- stage: null,
836
- highlightNode: null,
837
- modifiedNodeIds: /* @__PURE__ */ new Map()
838
- });
839
826
  constructor() {
840
827
  super([
841
828
  "getLayout",
@@ -852,6 +839,16 @@
852
839
  "redo",
853
840
  "highlight"
854
841
  ], ["select", "update", "moveLayer"]);
842
+ this.isHistoryStateChange = false;
843
+ this.state = vue.reactive({
844
+ root: null,
845
+ page: null,
846
+ parent: null,
847
+ node: null,
848
+ stage: null,
849
+ highlightNode: null,
850
+ modifiedNodeIds: /* @__PURE__ */ new Map()
851
+ });
855
852
  }
856
853
  set(name, value) {
857
854
  this.state[name] = value;
@@ -863,7 +860,7 @@
863
860
  return this.state[name];
864
861
  }
865
862
  getNodeInfo(id) {
866
- const root = this.get("root");
863
+ const root = vue.toRaw(this.get("root"));
867
864
  if (!root)
868
865
  return {};
869
866
  if (id === root.id) {
@@ -894,11 +891,13 @@
894
891
  const { parent } = this.getNodeInfo(id);
895
892
  return parent;
896
893
  }
897
- async getLayout(node) {
898
- if (node.layout) {
899
- return node.layout;
894
+ async getLayout(parent, node) {
895
+ if (node && typeof node !== "function" && isFixed(node))
896
+ return Layout.FIXED;
897
+ if (parent.layout) {
898
+ return parent.layout;
900
899
  }
901
- if (!node.style?.position) {
900
+ if (!parent.style?.position) {
902
901
  return Layout.RELATIVE;
903
902
  }
904
903
  return Layout.ABSOLUTE;
@@ -915,6 +914,28 @@
915
914
  }
916
915
  return node;
917
916
  }
917
+ async selectNextNode() {
918
+ const node = vue.toRaw(this.get("node"));
919
+ if (!node || utils.isPage(node) || node.type === schema.NodeType.ROOT)
920
+ return node;
921
+ const parent = vue.toRaw(this.getParentById(node.id));
922
+ if (!parent)
923
+ return node;
924
+ const index = getNodeIndex(node, parent);
925
+ const nextNode = parent.items[index + 1] || parent.items[0];
926
+ await this.select(nextNode);
927
+ this.get("stage")?.select(nextNode.id);
928
+ return nextNode;
929
+ }
930
+ async selectNextPage() {
931
+ const root = vue.toRaw(this.get("root"));
932
+ const page = vue.toRaw(this.get("page"));
933
+ const index = getNodeIndex(page, root);
934
+ const nextPage = root.items[index + 1] || root.items[0];
935
+ await this.select(nextPage);
936
+ this.get("stage")?.select(nextPage.id);
937
+ return nextPage;
938
+ }
918
939
  highlight(config2) {
919
940
  const { node } = this.selectedConfigExceptionHandler(config2);
920
941
  const currentHighlightNode = this.get("highlightNode");
@@ -922,7 +943,8 @@
922
943
  return;
923
944
  this.set("highlightNode", node);
924
945
  }
925
- async add({ type, ...config2 }, parent) {
946
+ async add(addNode, parent) {
947
+ const { type, ...config2 } = addNode;
926
948
  const curNode = this.get("node");
927
949
  let parentNode;
928
950
  if (type === schema.NodeType.PAGE) {
@@ -936,7 +958,7 @@
936
958
  }
937
959
  if (!parentNode)
938
960
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
939
- const layout = await this.getLayout(parentNode);
961
+ const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
940
962
  const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
941
963
  if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
942
964
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
@@ -1064,7 +1086,7 @@
1064
1086
  async alignCenter(config2) {
1065
1087
  const parent = this.get("parent");
1066
1088
  const node = this.get("node");
1067
- const layout = await this.getLayout(parent);
1089
+ const layout = await this.getLayout(vue.toRaw(parent), vue.toRaw(node));
1068
1090
  if (layout === Layout.RELATIVE) {
1069
1091
  return;
1070
1092
  }
@@ -1101,6 +1123,26 @@
1101
1123
  await this.changeHistoryState(value);
1102
1124
  return value;
1103
1125
  }
1126
+ async move(left, top) {
1127
+ const node = vue.toRaw(this.get("node"));
1128
+ if (!node || utils.isPage(node))
1129
+ return;
1130
+ const { style, id } = node;
1131
+ if (!style || style.position !== "absolute")
1132
+ return;
1133
+ if (top && !utils.isNumber(style.top))
1134
+ return;
1135
+ if (left && !utils.isNumber(style.left))
1136
+ return;
1137
+ this.update({
1138
+ id,
1139
+ style: {
1140
+ ...style,
1141
+ left: Number(style.left) + left,
1142
+ top: Number(style.top) + top
1143
+ }
1144
+ });
1145
+ }
1104
1146
  destroy() {
1105
1147
  this.removeAllListeners();
1106
1148
  this.set("root", null);
@@ -1843,8 +1885,8 @@
1843
1885
  name: gesto
1844
1886
  license: MIT
1845
1887
  author: Daybrush
1846
- repository: git+https://github.com/daybrush/gesture.git
1847
- version: 1.5.0
1888
+ repository: git+https://github.com/daybrush/gesto.git
1889
+ version: 1.7.0
1848
1890
  */
1849
1891
 
1850
1892
  /*! *****************************************************************************
@@ -2013,19 +2055,6 @@
2013
2055
 
2014
2056
  var __proto = ClientStore.prototype;
2015
2057
 
2016
- __proto.addClients = function (clients) {
2017
- if (clients === void 0) {
2018
- clients = this.prevClients;
2019
- }
2020
-
2021
- var position = this.getPosition(clients);
2022
- var deltaX = position.deltaX,
2023
- deltaY = position.deltaY;
2024
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2025
- this.prevClients = clients;
2026
- return position;
2027
- };
2028
-
2029
2058
  __proto.getAngle = function (clients) {
2030
2059
  if (clients === void 0) {
2031
2060
  clients = this.prevClients;
@@ -2042,8 +2071,17 @@
2042
2071
  return getRotatiion(clients) - getRotatiion(this.startClients);
2043
2072
  };
2044
2073
 
2045
- __proto.getPosition = function (clients) {
2046
- return getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2074
+ __proto.getPosition = function (clients, isAdd) {
2075
+ if (clients === void 0) {
2076
+ clients = this.prevClients;
2077
+ }
2078
+
2079
+ var position = getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2080
+ var deltaX = position.deltaX,
2081
+ deltaY = position.deltaY;
2082
+ this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2083
+ this.prevClients = clients;
2084
+ return position;
2047
2085
  };
2048
2086
 
2049
2087
  __proto.getPositions = function (clients) {
@@ -2092,10 +2130,6 @@
2092
2130
  client.clientX -= deltaX;
2093
2131
  client.clientY -= deltaY;
2094
2132
  });
2095
- this.prevClients.forEach(function (client) {
2096
- client.clientX -= deltaX;
2097
- client.clientY -= deltaY;
2098
- });
2099
2133
  };
2100
2134
 
2101
2135
  return ClientStore;
@@ -2134,6 +2168,7 @@
2134
2168
  _this.targets = [];
2135
2169
  _this.prevTime = 0;
2136
2170
  _this.doubleFlag = false;
2171
+ _this._dragFlag = false;
2137
2172
 
2138
2173
  _this.onDragStart = function (e, isTrusted) {
2139
2174
  if (isTrusted === void 0) {
@@ -2164,7 +2199,8 @@
2164
2199
  if (checkInput || activeElement === target) {
2165
2200
  // force false or already focused.
2166
2201
  return false;
2167
- }
2202
+ } // no focus
2203
+
2168
2204
 
2169
2205
  if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2170
2206
  return false;
@@ -2180,6 +2216,7 @@
2180
2216
  _this.clientStores = [new ClientStore(getEventClients(e))];
2181
2217
  _this.flag = true;
2182
2218
  _this.isDrag = false;
2219
+ _this._dragFlag = true;
2183
2220
  _this.datas = {};
2184
2221
 
2185
2222
  if (preventRightClick && (e.which === 3 || e.button === 2)) {
@@ -2195,7 +2232,14 @@
2195
2232
  inputEvent: e,
2196
2233
  isTrusted: isTrusted,
2197
2234
  isDouble: _this.doubleFlag
2198
- }, _this.getCurrentStore().getPosition()));
2235
+ }, _this.getCurrentStore().getPosition(), {
2236
+ preventDefault: function () {
2237
+ e.preventDefault();
2238
+ },
2239
+ preventDrag: function () {
2240
+ _this._dragFlag = false;
2241
+ }
2242
+ }));
2199
2243
 
2200
2244
  if (result === false) {
2201
2245
  _this.initDrag();
@@ -2244,24 +2288,26 @@
2244
2288
 
2245
2289
  var result = _this.moveClients(clients, e, false);
2246
2290
 
2247
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2248
- var dragResult = _this.emit("drag", __assign({}, result, {
2249
- isScroll: !!isScroll,
2250
- inputEvent: e
2251
- }));
2291
+ if (_this._dragFlag) {
2292
+ if (_this.pinchFlag || result.deltaX || result.deltaY) {
2293
+ var dragResult = _this.emit("drag", __assign({}, result, {
2294
+ isScroll: !!isScroll,
2295
+ inputEvent: e
2296
+ }));
2252
2297
 
2253
- if (dragResult === false) {
2254
- _this.stop();
2298
+ if (dragResult === false) {
2299
+ _this.stop();
2255
2300
 
2256
- return;
2301
+ return;
2302
+ }
2257
2303
  }
2258
- }
2259
2304
 
2260
- if (_this.pinchFlag) {
2261
- _this.onPinch(e, clients);
2305
+ if (_this.pinchFlag) {
2306
+ _this.onPinch(e, clients);
2307
+ }
2262
2308
  }
2263
2309
 
2264
- _this.getCurrentStore().addClients(clients);
2310
+ _this.getCurrentStore().getPosition(clients, true);
2265
2311
  };
2266
2312
 
2267
2313
  _this.onDragEnd = function (e) {
@@ -2279,7 +2325,7 @@
2279
2325
 
2280
2326
  _this.flag = false;
2281
2327
 
2282
- var position = _this.getCurrentStore().getPosition();
2328
+ var position = _this._getPosition();
2283
2329
 
2284
2330
  var currentTime = now();
2285
2331
  var isDouble = !_this.isDrag && _this.doubleFlag;
@@ -2473,7 +2519,23 @@
2473
2519
  return this;
2474
2520
  };
2475
2521
  /**
2476
- * Set the event data while dragging.
2522
+ * Get the current event state while dragging.
2523
+ */
2524
+
2525
+
2526
+ __proto.getCurrentEvent = function (inputEvent) {
2527
+ return __assign({
2528
+ datas: this.datas
2529
+ }, this._getPosition(), {
2530
+ movement: this.getMovement(),
2531
+ isDrag: this.isDrag,
2532
+ isPinch: this.isPinch,
2533
+ isScroll: false,
2534
+ inputEvent: inputEvent
2535
+ });
2536
+ };
2537
+ /**
2538
+ * Get & Set the event data while dragging.
2477
2539
  */
2478
2540
 
2479
2541
 
@@ -2589,9 +2651,12 @@
2589
2651
  };
2590
2652
 
2591
2653
  __proto.moveClients = function (clients, inputEvent, isAdd) {
2592
- var store = this.getCurrentStore();
2593
- var position = store[isAdd ? "addClients" : "getPosition"](clients);
2594
- this.isDrag = true;
2654
+ var position = this._getPosition(clients, isAdd);
2655
+
2656
+ if (position.deltaX || position.deltaY) {
2657
+ this.isDrag = true;
2658
+ }
2659
+
2595
2660
  return __assign({
2596
2661
  datas: this.datas
2597
2662
  }, position, {
@@ -2603,6 +2668,25 @@
2603
2668
  });
2604
2669
  };
2605
2670
 
2671
+ __proto._getPosition = function (clients, isAdd) {
2672
+ var store = this.getCurrentStore();
2673
+ var position = store.getPosition(clients, isAdd);
2674
+
2675
+ var _a = this.clientStores.slice(1).reduce(function (prev, cur) {
2676
+ var storePosition = cur.getPosition();
2677
+ prev.distX += storePosition.distX;
2678
+ prev.distY += storePosition.distY;
2679
+ return prev;
2680
+ }, position),
2681
+ distX = _a.distX,
2682
+ distY = _a.distY;
2683
+
2684
+ return __assign({}, position, {
2685
+ distX: distX,
2686
+ distY: distY
2687
+ });
2688
+ };
2689
+
2606
2690
  return Gesto;
2607
2691
  }(EventEmitter$1);
2608
2692
 
@@ -2789,11 +2873,11 @@
2789
2873
  setup(props) {
2790
2874
  const services = vue.inject("services");
2791
2875
  const uiService = services?.uiService;
2792
- const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2793
- const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2794
2876
  const zoom = vue.computed(() => uiService?.get("zoom") ?? 1);
2795
2877
  const showGuides = vue.computed(() => uiService?.get("showGuides") ?? true);
2796
2878
  const showRule = vue.computed(() => uiService?.get("showRule") ?? true);
2879
+ const zoomInHandler = () => uiService?.zoom(0.1);
2880
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
2797
2881
  const item = vue.computed(() => {
2798
2882
  if (typeof props.data !== "string") {
2799
2883
  return props.data;
@@ -3851,33 +3935,104 @@
3851
3935
  var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3852
3936
 
3853
3937
  class ScrollViewer$1 {
3854
- enter = false;
3855
- targetEnter = false;
3856
- keydown = false;
3857
- container;
3858
- target;
3859
- zoom = 1;
3860
- scrollLeft = 0;
3861
- scrollTop = 0;
3862
- x = 0;
3863
- y = 0;
3864
- resizeObserver = new ResizeObserver((entries) => {
3865
- for (const { contentRect } of entries) {
3866
- const { width, height } = contentRect;
3867
- const targetRect = this.target.getBoundingClientRect();
3868
- const targetWidth = targetRect.width * this.zoom;
3869
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3870
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3871
- if (targetWidth < width) {
3872
- this.target._left = 0;
3873
- }
3874
- if (targetHeight < height) {
3875
- this.target._top = 0;
3938
+ constructor(options) {
3939
+ this.enter = false;
3940
+ this.targetEnter = false;
3941
+ this.keydown = false;
3942
+ this.zoom = 1;
3943
+ this.scrollLeft = 0;
3944
+ this.scrollTop = 0;
3945
+ this.x = 0;
3946
+ this.y = 0;
3947
+ this.resizeObserver = new ResizeObserver((entries) => {
3948
+ for (const { contentRect } of entries) {
3949
+ const { width, height } = contentRect;
3950
+ const targetRect = this.target.getBoundingClientRect();
3951
+ const targetWidth = targetRect.width * this.zoom;
3952
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
3953
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3954
+ if (targetWidth < width) {
3955
+ this.target._left = 0;
3956
+ }
3957
+ if (targetHeight < height) {
3958
+ this.target._top = 0;
3959
+ }
3960
+ this.scroll();
3876
3961
  }
3962
+ });
3963
+ this.wheelHandler = (event) => {
3964
+ if (this.targetEnter)
3965
+ return;
3966
+ const { deltaX, deltaY, currentTarget } = event;
3967
+ if (currentTarget !== this.container)
3968
+ return;
3969
+ this.setScrollOffset(deltaX, deltaY);
3877
3970
  this.scroll();
3878
- }
3879
- });
3880
- constructor(options) {
3971
+ this.scrollLeft = this.target._left;
3972
+ this.scrollTop = this.target._top;
3973
+ };
3974
+ this.mouseEnterHandler = () => {
3975
+ this.enter = true;
3976
+ };
3977
+ this.mouseLeaveHandler = () => {
3978
+ this.enter = false;
3979
+ };
3980
+ this.targetMouseEnterHandler = () => {
3981
+ this.targetEnter = true;
3982
+ };
3983
+ this.targetMouseLeaveHandler = () => {
3984
+ this.targetEnter = false;
3985
+ };
3986
+ this.mousedownHandler = (event) => {
3987
+ if (!this.keydown)
3988
+ return;
3989
+ event.stopImmediatePropagation();
3990
+ event.stopPropagation();
3991
+ this.target.style.cursor = "grabbing";
3992
+ this.x = event.clientX;
3993
+ this.y = event.clientY;
3994
+ document.addEventListener("mousemove", this.mousemoveHandler);
3995
+ document.addEventListener("mouseup", this.mouseupHandler);
3996
+ };
3997
+ this.mouseupHandler = () => {
3998
+ this.x = 0;
3999
+ this.y = 0;
4000
+ this.scrollLeft = this.target._left;
4001
+ this.scrollTop = this.target._top;
4002
+ this.removeHandler();
4003
+ };
4004
+ this.mousemoveHandler = (event) => {
4005
+ event.stopImmediatePropagation();
4006
+ event.stopPropagation();
4007
+ const deltaX = event.clientX - this.x;
4008
+ const deltaY = event.clientY - this.y;
4009
+ this.setScrollOffset(deltaX, deltaY);
4010
+ this.scroll();
4011
+ };
4012
+ this.keydownHandler = (event) => {
4013
+ if (event.code === Keys.ESCAPE && this.enter) {
4014
+ event.preventDefault();
4015
+ event.stopImmediatePropagation();
4016
+ event.stopPropagation();
4017
+ }
4018
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
4019
+ return;
4020
+ }
4021
+ this.keydown = true;
4022
+ this.target.style.cursor = "grab";
4023
+ this.container.addEventListener("mousedown", this.mousedownHandler);
4024
+ };
4025
+ this.keyupHandler = (event) => {
4026
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
4027
+ return;
4028
+ }
4029
+ event.preventDefault();
4030
+ event.stopImmediatePropagation();
4031
+ event.stopPropagation();
4032
+ this.keydown = false;
4033
+ event.preventDefault();
4034
+ this.removeHandler();
4035
+ };
3881
4036
  this.container = options.container;
3882
4037
  this.target = options.target;
3883
4038
  this.zoom = options.zoom;
@@ -3913,79 +4068,6 @@
3913
4068
  document.removeEventListener("mousemove", this.mousemoveHandler);
3914
4069
  document.removeEventListener("mouseup", this.mouseupHandler);
3915
4070
  }
3916
- wheelHandler = (event) => {
3917
- if (this.targetEnter)
3918
- return;
3919
- const { deltaX, deltaY, currentTarget } = event;
3920
- if (currentTarget !== this.container)
3921
- return;
3922
- this.setScrollOffset(deltaX, deltaY);
3923
- this.scroll();
3924
- this.scrollLeft = this.target._left;
3925
- this.scrollTop = this.target._top;
3926
- };
3927
- mouseEnterHandler = () => {
3928
- this.enter = true;
3929
- };
3930
- mouseLeaveHandler = () => {
3931
- this.enter = false;
3932
- };
3933
- targetMouseEnterHandler = () => {
3934
- this.targetEnter = true;
3935
- };
3936
- targetMouseLeaveHandler = () => {
3937
- this.targetEnter = false;
3938
- };
3939
- mousedownHandler = (event) => {
3940
- if (!this.keydown)
3941
- return;
3942
- event.stopImmediatePropagation();
3943
- event.stopPropagation();
3944
- this.target.style.cursor = "grabbing";
3945
- this.x = event.clientX;
3946
- this.y = event.clientY;
3947
- document.addEventListener("mousemove", this.mousemoveHandler);
3948
- document.addEventListener("mouseup", this.mouseupHandler);
3949
- };
3950
- mouseupHandler = () => {
3951
- this.x = 0;
3952
- this.y = 0;
3953
- this.scrollLeft = this.target._left;
3954
- this.scrollTop = this.target._top;
3955
- this.removeHandler();
3956
- };
3957
- mousemoveHandler = (event) => {
3958
- event.stopImmediatePropagation();
3959
- event.stopPropagation();
3960
- const deltaX = event.clientX - this.x;
3961
- const deltaY = event.clientY - this.y;
3962
- this.setScrollOffset(deltaX, deltaY);
3963
- this.scroll();
3964
- };
3965
- keydownHandler = (event) => {
3966
- if (event.code === Keys.ESCAPE && this.enter) {
3967
- event.preventDefault();
3968
- event.stopImmediatePropagation();
3969
- event.stopPropagation();
3970
- }
3971
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3972
- return;
3973
- }
3974
- this.keydown = true;
3975
- this.target.style.cursor = "grab";
3976
- this.container.addEventListener("mousedown", this.mousedownHandler);
3977
- };
3978
- keyupHandler = (event) => {
3979
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3980
- return;
3981
- }
3982
- event.preventDefault();
3983
- event.stopImmediatePropagation();
3984
- event.stopPropagation();
3985
- this.keydown = false;
3986
- event.preventDefault();
3987
- this.removeHandler();
3988
- };
3989
4071
  setScrollOffset(deltaX, deltaY) {
3990
4072
  const { width, height } = this.container.getBoundingClientRect();
3991
4073
  const targetRect = this.target.getBoundingClientRect();
@@ -4046,7 +4128,7 @@
4046
4128
  el,
4047
4129
  style: vue.computed(() => `
4048
4130
  width: ${props.width}px;
4049
- height: ${props.height}px;
4131
+ height: ${(props.height || 0) - 40}px;
4050
4132
  position: absolute;
4051
4133
  margin-top: 30px;
4052
4134
  `)
@@ -4391,29 +4473,74 @@
4391
4473
  const mouseenterHandler = () => {
4392
4474
  workspace.value?.focus();
4393
4475
  };
4394
- const mouseleaveHandler = () => {
4395
- workspace.value?.blur();
4396
- };
4397
4476
  vue.onMounted(() => {
4398
4477
  workspace.value?.addEventListener("mouseenter", mouseenterHandler);
4399
- workspace.value?.addEventListener("mouseleave", mouseleaveHandler);
4400
4478
  keycon = new KeyController__default["default"](workspace.value);
4401
- keycon.keyup("delete", () => {
4402
- node.value && services?.editorService.remove(node.value);
4403
- }).keyup(["ctrl", "c"], () => {
4479
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4480
+ const ctrl = isMac ? "meta" : "ctrl";
4481
+ keycon.keyup("delete", (e) => {
4482
+ e.inputEvent.preventDefault();
4483
+ if (!node.value || utils.isPage(node.value))
4484
+ return;
4485
+ services?.editorService.remove(node.value);
4486
+ }).keydown([ctrl, "c"], (e) => {
4487
+ e.inputEvent.preventDefault();
4404
4488
  node.value && services?.editorService.copy(node.value);
4405
- }).keyup(["ctrl", "v"], () => {
4489
+ }).keyup([ctrl, "v"], (e) => {
4490
+ e.inputEvent.preventDefault();
4406
4491
  node.value && services?.editorService.paste();
4407
- }).keyup(["ctrl", "x"], () => {
4408
- if (node.value && services) {
4409
- services.editorService.copy(node.value);
4410
- services.editorService.remove(node.value);
4411
- }
4492
+ }).keyup([ctrl, "x"], (e) => {
4493
+ e.inputEvent.preventDefault();
4494
+ if (!node.value || utils.isPage(node.value))
4495
+ return;
4496
+ services?.editorService.copy(node.value);
4497
+ services?.editorService.remove(node.value);
4498
+ }).keydown([ctrl, "z"], (e) => {
4499
+ e.inputEvent.preventDefault();
4500
+ services?.editorService.undo();
4501
+ }).keydown([ctrl, "shift", "z"], (e) => {
4502
+ e.inputEvent.preventDefault();
4503
+ services?.editorService.redo();
4504
+ }).keydown("up", (e) => {
4505
+ e.inputEvent.preventDefault();
4506
+ services?.editorService.move(0, -1);
4507
+ }).keydown("down", (e) => {
4508
+ e.inputEvent.preventDefault();
4509
+ services?.editorService.move(0, 1);
4510
+ }).keydown("left", (e) => {
4511
+ e.inputEvent.preventDefault();
4512
+ services?.editorService.move(-1, 0);
4513
+ }).keydown("right", (e) => {
4514
+ e.inputEvent.preventDefault();
4515
+ services?.editorService.move(1, 0);
4516
+ }).keydown([ctrl, "up"], (e) => {
4517
+ e.inputEvent.preventDefault();
4518
+ services?.editorService.move(0, -10);
4519
+ }).keydown([ctrl, "down"], (e) => {
4520
+ e.inputEvent.preventDefault();
4521
+ services?.editorService.move(0, 10);
4522
+ }).keydown([ctrl, "left"], (e) => {
4523
+ e.inputEvent.preventDefault();
4524
+ services?.editorService.move(-10, 0);
4525
+ }).keydown([ctrl, "right"], (e) => {
4526
+ e.inputEvent.preventDefault();
4527
+ services?.editorService.move(10, 0);
4528
+ }).keydown("tab", (e) => {
4529
+ e.inputEvent.preventDefault();
4530
+ services?.editorService.selectNextNode();
4531
+ }).keydown([ctrl, "tab"], (e) => {
4532
+ e.inputEvent.preventDefault();
4533
+ services?.editorService.selectNextPage();
4534
+ }).keydown([ctrl, "="], (e) => {
4535
+ e.inputEvent.preventDefault();
4536
+ services?.uiService.zoom(0.1);
4537
+ }).keydown([ctrl, "-"], (e) => {
4538
+ e.inputEvent.preventDefault();
4539
+ services?.uiService.zoom(-0.1);
4412
4540
  });
4413
4541
  });
4414
4542
  vue.onUnmounted(() => {
4415
4543
  workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
4416
- workspace.value?.removeEventListener("mouseleave", mouseleaveHandler);
4417
4544
  keycon.destroy();
4418
4545
  });
4419
4546
  return {
@@ -4453,11 +4580,11 @@
4453
4580
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4454
4581
 
4455
4582
  class ComponentList extends BaseService {
4456
- state = vue.reactive({
4457
- list: []
4458
- });
4459
4583
  constructor() {
4460
4584
  super([]);
4585
+ this.state = vue.reactive({
4586
+ list: []
4587
+ });
4461
4588
  }
4462
4589
  setList(componentGroupList) {
4463
4590
  this.state.list = componentGroupList;
@@ -4523,6 +4650,11 @@
4523
4650
  get(name) {
4524
4651
  return state[name];
4525
4652
  }
4653
+ zoom(zoom) {
4654
+ this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
4655
+ if (this.get("zoom") < 0.1)
4656
+ this.set("zoom", 0.1);
4657
+ }
4526
4658
  setColumnWidth({ left, center, right }) {
4527
4659
  const columnWidth = {
4528
4660
  ...vue.toRaw(this.get("columnWidth"))
@@ -4775,8 +4907,7 @@
4775
4907
  exports.uiService = uiService;
4776
4908
  exports.warn = warn;
4777
4909
 
4778
- Object.defineProperty(exports, '__esModule', { value: true });
4779
- exports[Symbol.toStringTag] = 'Module';
4910
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4780
4911
 
4781
4912
  }));
4782
4913
  //# sourceMappingURL=tmagic-editor.umd.js.map