@tmagic/editor 1.0.0-beta.10 → 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 (88) hide show
  1. package/README.md +1 -0
  2. package/coverage/clover.xml +1444 -0
  3. package/coverage/coverage-final.json +34 -0
  4. package/coverage/lcov-report/Icon.vue.html +172 -0
  5. package/coverage/lcov-report/ToolButton.vue.html +655 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/block-navigation.js +87 -0
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +206 -0
  10. package/coverage/lcov-report/layouts/sidebar/LayerMenu.vue.html +364 -0
  11. package/coverage/lcov-report/layouts/sidebar/index.html +116 -0
  12. package/coverage/lcov-report/prettify.css +1 -0
  13. package/coverage/lcov-report/prettify.js +2 -0
  14. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  15. package/coverage/lcov-report/sorter.js +196 -0
  16. package/coverage/lcov-report/src/Editor.vue.html +787 -0
  17. package/coverage/lcov-report/src/components/Icon.vue.html +172 -0
  18. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +283 -0
  19. package/coverage/lcov-report/src/components/ToolButton.vue.html +655 -0
  20. package/coverage/lcov-report/src/components/index.html +146 -0
  21. package/coverage/lcov-report/src/index.html +131 -0
  22. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +214 -0
  23. package/coverage/lcov-report/src/layouts/Framework.vue.html +304 -0
  24. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +208 -0
  25. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +316 -0
  26. package/coverage/lcov-report/src/layouts/Resizer.vue.html +268 -0
  27. package/coverage/lcov-report/src/layouts/index.html +176 -0
  28. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +292 -0
  29. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +364 -0
  30. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +853 -0
  31. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +343 -0
  32. package/coverage/lcov-report/src/layouts/sidebar/index.html +161 -0
  33. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +631 -0
  34. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +766 -0
  35. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +421 -0
  36. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +586 -0
  37. package/coverage/lcov-report/src/layouts/workspace/index.html +161 -0
  38. package/coverage/lcov-report/src/services/BaseService.ts.html +643 -0
  39. package/coverage/lcov-report/src/services/componentList.ts.html +229 -0
  40. package/coverage/lcov-report/src/services/editor.ts.html +1984 -0
  41. package/coverage/lcov-report/src/services/events.ts.html +331 -0
  42. package/coverage/lcov-report/src/services/history.ts.html +457 -0
  43. package/coverage/lcov-report/src/services/index.html +206 -0
  44. package/coverage/lcov-report/src/services/props.ts.html +418 -0
  45. package/coverage/lcov-report/src/services/ui.ts.html +514 -0
  46. package/coverage/lcov-report/src/type.ts.html +850 -0
  47. package/coverage/lcov-report/src/utils/compose.ts.html +184 -0
  48. package/coverage/lcov-report/src/utils/config.ts.html +172 -0
  49. package/coverage/lcov-report/src/utils/editor.ts.html +838 -0
  50. package/coverage/lcov-report/src/utils/index.html +221 -0
  51. package/coverage/lcov-report/src/utils/index.ts.html +151 -0
  52. package/coverage/lcov-report/src/utils/logger.ts.html +226 -0
  53. package/coverage/lcov-report/src/utils/props.ts.html +739 -0
  54. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +733 -0
  55. package/coverage/lcov-report/src/utils/undo-redo.ts.html +313 -0
  56. package/coverage/lcov-report/utils/index.html +116 -0
  57. package/coverage/lcov-report/utils/undo-redo.ts.html +313 -0
  58. package/coverage/lcov.info +3407 -0
  59. package/dist/style.css +3 -2
  60. package/dist/tmagic-editor.es.js +388 -196
  61. package/dist/tmagic-editor.es.js.map +1 -1
  62. package/dist/tmagic-editor.umd.js +393 -202
  63. package/dist/tmagic-editor.umd.js.map +1 -1
  64. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -1
  65. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +1 -1
  66. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +2 -1
  67. package/dist/types/src/services/editor.d.ts +5 -2
  68. package/dist/types/src/services/props.d.ts +1 -1
  69. package/dist/types/src/services/ui.d.ts +1 -0
  70. package/dist/types/src/type.d.ts +3 -1
  71. package/dist/types/src/utils/editor.d.ts +4 -3
  72. package/package.json +28 -9
  73. package/src/components/ScrollViewer.vue +1 -1
  74. package/src/components/ToolButton.vue +3 -3
  75. package/src/layouts/PropsPanel.vue +1 -1
  76. package/src/layouts/sidebar/ComponentListPanel.vue +2 -2
  77. package/src/layouts/sidebar/LayerMenu.vue +1 -0
  78. package/src/layouts/workspace/Workspace.vue +106 -3
  79. package/src/services/BaseService.ts +1 -1
  80. package/src/services/editor.ts +79 -13
  81. package/src/services/props.ts +2 -1
  82. package/src/services/ui.ts +5 -0
  83. package/src/theme/layer-panel.scss +1 -0
  84. package/src/type.ts +3 -1
  85. package/src/utils/editor.ts +31 -6
  86. package/src/utils/props.ts +1 -1
  87. package/tsconfig.json +0 -9
  88. package/vite.config.ts +0 -30
@@ -1,14 +1,14 @@
1
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('@tmagic/schema'), 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', '@tmagic/schema', '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.schema, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.StageCore));
5
- })(this, (function (exports, vue, serialize, monaco, icons, schema, lodashEs, utils, events, core, elementPlus, StageCore) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('serialize-javascript'), require('monaco-editor'), require('@element-plus/icons'), require('@tmagic/schema'), require('lodash-es'), require('@tmagic/utils'), require('events'), require('@tmagic/core'), require('element-plus'), require('keycon'), require('@tmagic/stage')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'serialize-javascript', 'monaco-editor', '@element-plus/icons', '@tmagic/schema', 'lodash-es', '@tmagic/utils', 'events', '@tmagic/core', 'element-plus', 'keycon', '@tmagic/stage'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TMagicEditor = {}, global.vue, global.serialize, global.monaco, global.icons, global.schema, global.lodashEs, global.utils, global.events, global.core, global.elementPlus, global.KeyController, global.StageCore));
5
+ })(this, (function (exports, vue, serialize, monaco, icons, schema, lodashEs, utils, events, core, elementPlus, KeyController, StageCore) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
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') {
@@ -26,6 +26,7 @@
26
26
 
27
27
  var serialize__default = /*#__PURE__*/_interopDefaultLegacy(serialize);
28
28
  var monaco__namespace = /*#__PURE__*/_interopNamespace(monaco);
29
+ var KeyController__default = /*#__PURE__*/_interopDefaultLegacy(KeyController);
29
30
  var StageCore__default = /*#__PURE__*/_interopDefaultLegacy(StageCore);
30
31
 
31
32
  var _export_sfc = (sfc, props) => {
@@ -359,9 +360,6 @@
359
360
  const getConfig = (key) => $TMAGIC_EDITOR[key];
360
361
 
361
362
  class UndoRedo {
362
- elementList;
363
- listCursor;
364
- listMaxSize;
365
363
  constructor(listMaxSize = 200) {
366
364
  const minListMaxSize = 2;
367
365
  this.elementList = [];
@@ -452,7 +450,7 @@
452
450
  }
453
451
  let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
454
452
  for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
455
- returnValue = await afterMethod(...beforeArgs, returnValue);
453
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
456
454
  if (isError(returnValue))
457
455
  throw returnValue;
458
456
  }
@@ -462,12 +460,12 @@
462
460
  }
463
461
  };
464
462
  class BaseService extends events.EventEmitter {
465
- pluginOptionsList = {};
466
- middleware = {};
467
- taskList = [];
468
- doingTask = false;
469
463
  constructor(methods = [], serialMethods = []) {
470
464
  super();
465
+ this.pluginOptionsList = {};
466
+ this.middleware = {};
467
+ this.taskList = [];
468
+ this.doingTask = false;
471
469
  methods.forEach((propertyName) => {
472
470
  const scope = this;
473
471
  const sourceMethod = scope[propertyName];
@@ -524,14 +522,14 @@
524
522
  }
525
523
 
526
524
  class History extends BaseService {
527
- state = vue.reactive({
528
- pageSteps: {},
529
- pageId: void 0,
530
- canRedo: false,
531
- canUndo: false
532
- });
533
525
  constructor() {
534
526
  super([]);
527
+ this.state = vue.reactive({
528
+ pageSteps: {},
529
+ pageId: void 0,
530
+ canRedo: false,
531
+ canUndo: false
532
+ });
535
533
  this.on("change", this.setCanUndoRedo);
536
534
  }
537
535
  changePage(page) {
@@ -597,12 +595,12 @@
597
595
  var historyService = new History();
598
596
 
599
597
  class Props extends BaseService {
600
- state = vue.reactive({
601
- propsConfigMap: {},
602
- propsValueMap: {}
603
- });
604
598
  constructor() {
605
599
  super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
600
+ this.state = vue.reactive({
601
+ propsConfigMap: {},
602
+ propsValueMap: {}
603
+ });
606
604
  }
607
605
  setPropsConfigs(configs) {
608
606
  Object.keys(configs).forEach((type) => {
@@ -627,7 +625,7 @@
627
625
  setPropsValue(type, value) {
628
626
  this.state.propsValueMap[type] = value;
629
627
  }
630
- async getPropsValue(type) {
628
+ async getPropsValue(type, defaultValue = {}) {
631
629
  if (type === "area") {
632
630
  const value = await this.getPropsValue("button");
633
631
  value.className = "action-area";
@@ -639,6 +637,7 @@
639
637
  }
640
638
  return lodashEs.cloneDeep({
641
639
  ...getDefaultPropsValue(type),
640
+ ...defaultValue,
642
641
  ...this.state.propsValueMap[type] || {}
643
642
  });
644
643
  }
@@ -700,7 +699,7 @@
700
699
  };
701
700
  const setNewItemId = (config, parent) => {
702
701
  const oldId = config.id;
703
- config.id = generateId(config.type);
702
+ config.id = generateId(config.type || "component");
704
703
  config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
705
704
  if (utils.isPop(config) && parent?.type === schema.NodeType.PAGE) {
706
705
  updatePopId(oldId, config.id, parent);
@@ -723,11 +722,25 @@
723
722
  };
724
723
  return node;
725
724
  };
726
- const initPosition = (node, layout) => {
725
+ const setTop2Middle = (node, parentNode, stage) => {
726
+ const style = node.style || {};
727
+ const height = style.height || 0;
728
+ if (!stage || style.top || !parentNode.style || !utils.isNumber(height))
729
+ return style;
730
+ const { height: parentHeight } = parentNode.style;
731
+ if (utils.isPage(parentNode)) {
732
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
733
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
734
+ } else {
735
+ style.top = (parentHeight - height) / 2;
736
+ }
737
+ return style;
738
+ };
739
+ const initPosition = (node, layout, parentNode, stage) => {
727
740
  if (layout === Layout.ABSOLUTE) {
728
741
  node.style = {
729
742
  position: "absolute",
730
- ...node.style || {}
743
+ ...setTop2Middle(node, parentNode, stage)
731
744
  };
732
745
  return node;
733
746
  }
@@ -774,7 +787,9 @@
774
787
  const cur = path.pop();
775
788
  const offset = {
776
789
  left: cur?.style?.left || 0,
777
- top: cur?.style?.top || 0
790
+ top: cur?.style?.top || 0,
791
+ right: "",
792
+ bottom: ""
778
793
  };
779
794
  path.forEach((value) => {
780
795
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
@@ -808,16 +823,6 @@
808
823
  };
809
824
 
810
825
  class Editor$1 extends BaseService {
811
- isHistoryStateChange = false;
812
- state = vue.reactive({
813
- root: null,
814
- page: null,
815
- parent: null,
816
- node: null,
817
- stage: null,
818
- highlightNode: null,
819
- modifiedNodeIds: /* @__PURE__ */ new Map()
820
- });
821
826
  constructor() {
822
827
  super([
823
828
  "getLayout",
@@ -834,6 +839,16 @@
834
839
  "redo",
835
840
  "highlight"
836
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
+ });
837
852
  }
838
853
  set(name, value) {
839
854
  this.state[name] = value;
@@ -845,7 +860,7 @@
845
860
  return this.state[name];
846
861
  }
847
862
  getNodeInfo(id) {
848
- const root = this.get("root");
863
+ const root = vue.toRaw(this.get("root"));
849
864
  if (!root)
850
865
  return {};
851
866
  if (id === root.id) {
@@ -876,11 +891,13 @@
876
891
  const { parent } = this.getNodeInfo(id);
877
892
  return parent;
878
893
  }
879
- async getLayout(node) {
880
- if (node.layout) {
881
- 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;
882
899
  }
883
- if (!node.style?.position) {
900
+ if (!parent.style?.position) {
884
901
  return Layout.RELATIVE;
885
902
  }
886
903
  return Layout.ABSOLUTE;
@@ -897,6 +914,28 @@
897
914
  }
898
915
  return node;
899
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
+ }
900
939
  highlight(config2) {
901
940
  const { node } = this.selectedConfigExceptionHandler(config2);
902
941
  const currentHighlightNode = this.get("highlightNode");
@@ -904,7 +943,8 @@
904
943
  return;
905
944
  this.set("highlightNode", node);
906
945
  }
907
- async add({ type, ...config2 }, parent) {
946
+ async add(addNode, parent) {
947
+ const { type, ...config2 } = addNode;
908
948
  const curNode = this.get("node");
909
949
  let parentNode;
910
950
  if (type === schema.NodeType.PAGE) {
@@ -918,8 +958,8 @@
918
958
  }
919
959
  if (!parentNode)
920
960
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
921
- const layout = await this.getLayout(parentNode);
922
- const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
961
+ const layout = await this.getLayout(vue.toRaw(parentNode), addNode);
962
+ const newNode = initPosition({ ...vue.toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
923
963
  if ((parentNode?.type === schema.NodeType.ROOT || curNode.type === schema.NodeType.ROOT) && newNode.type !== schema.NodeType.PAGE) {
924
964
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
925
965
  }
@@ -996,8 +1036,8 @@
996
1036
  parentNodeItems[index] = newConfig;
997
1037
  if (`${newConfig.id}` === `${this.get("node").id}`) {
998
1038
  this.set("node", newConfig);
999
- this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: this.get("root") });
1000
1039
  }
1040
+ this.get("stage")?.update({ config: lodashEs.cloneDeep(newConfig), root: this.get("root") });
1001
1041
  if (newConfig.type === schema.NodeType.PAGE) {
1002
1042
  this.set("page", newConfig);
1003
1043
  }
@@ -1046,7 +1086,7 @@
1046
1086
  async alignCenter(config2) {
1047
1087
  const parent = this.get("parent");
1048
1088
  const node = this.get("node");
1049
- const layout = await this.getLayout(parent);
1089
+ const layout = await this.getLayout(vue.toRaw(parent), vue.toRaw(node));
1050
1090
  if (layout === Layout.RELATIVE) {
1051
1091
  return;
1052
1092
  }
@@ -1083,6 +1123,26 @@
1083
1123
  await this.changeHistoryState(value);
1084
1124
  return value;
1085
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
+ }
1086
1146
  destroy() {
1087
1147
  this.removeAllListeners();
1088
1148
  this.set("root", null);
@@ -1115,7 +1175,12 @@
1115
1175
  this.isHistoryStateChange = true;
1116
1176
  await this.update(value.data);
1117
1177
  this.set("modifiedNodeIds", value.modifiedNodeIds);
1118
- setTimeout(() => value.nodeId && this.select(value.nodeId), 0);
1178
+ setTimeout(async () => {
1179
+ if (!value.nodeId)
1180
+ return;
1181
+ await this.select(value.nodeId);
1182
+ this.get("stage")?.select(value.nodeId);
1183
+ }, 0);
1119
1184
  }
1120
1185
  async toggleFixedPosition(dist, src, root) {
1121
1186
  let newConfig = lodashEs.cloneDeep(dist);
@@ -1339,7 +1404,7 @@
1339
1404
  type: "select",
1340
1405
  options: (mForm, { model }) => {
1341
1406
  const node = editorService.getNodeById(model.to);
1342
- if (!node)
1407
+ if (!node?.type)
1343
1408
  return [];
1344
1409
  return eventsService.getMethod(node.type).map((option) => ({
1345
1410
  text: option.label,
@@ -1820,8 +1885,8 @@
1820
1885
  name: gesto
1821
1886
  license: MIT
1822
1887
  author: Daybrush
1823
- repository: git+https://github.com/daybrush/gesture.git
1824
- version: 1.5.0
1888
+ repository: git+https://github.com/daybrush/gesto.git
1889
+ version: 1.7.0
1825
1890
  */
1826
1891
 
1827
1892
  /*! *****************************************************************************
@@ -1990,19 +2055,6 @@
1990
2055
 
1991
2056
  var __proto = ClientStore.prototype;
1992
2057
 
1993
- __proto.addClients = function (clients) {
1994
- if (clients === void 0) {
1995
- clients = this.prevClients;
1996
- }
1997
-
1998
- var position = this.getPosition(clients);
1999
- var deltaX = position.deltaX,
2000
- deltaY = position.deltaY;
2001
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2002
- this.prevClients = clients;
2003
- return position;
2004
- };
2005
-
2006
2058
  __proto.getAngle = function (clients) {
2007
2059
  if (clients === void 0) {
2008
2060
  clients = this.prevClients;
@@ -2019,8 +2071,17 @@
2019
2071
  return getRotatiion(clients) - getRotatiion(this.startClients);
2020
2072
  };
2021
2073
 
2022
- __proto.getPosition = function (clients) {
2023
- 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;
2024
2085
  };
2025
2086
 
2026
2087
  __proto.getPositions = function (clients) {
@@ -2069,10 +2130,6 @@
2069
2130
  client.clientX -= deltaX;
2070
2131
  client.clientY -= deltaY;
2071
2132
  });
2072
- this.prevClients.forEach(function (client) {
2073
- client.clientX -= deltaX;
2074
- client.clientY -= deltaY;
2075
- });
2076
2133
  };
2077
2134
 
2078
2135
  return ClientStore;
@@ -2111,6 +2168,7 @@
2111
2168
  _this.targets = [];
2112
2169
  _this.prevTime = 0;
2113
2170
  _this.doubleFlag = false;
2171
+ _this._dragFlag = false;
2114
2172
 
2115
2173
  _this.onDragStart = function (e, isTrusted) {
2116
2174
  if (isTrusted === void 0) {
@@ -2141,7 +2199,8 @@
2141
2199
  if (checkInput || activeElement === target) {
2142
2200
  // force false or already focused.
2143
2201
  return false;
2144
- }
2202
+ } // no focus
2203
+
2145
2204
 
2146
2205
  if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2147
2206
  return false;
@@ -2157,6 +2216,7 @@
2157
2216
  _this.clientStores = [new ClientStore(getEventClients(e))];
2158
2217
  _this.flag = true;
2159
2218
  _this.isDrag = false;
2219
+ _this._dragFlag = true;
2160
2220
  _this.datas = {};
2161
2221
 
2162
2222
  if (preventRightClick && (e.which === 3 || e.button === 2)) {
@@ -2172,7 +2232,14 @@
2172
2232
  inputEvent: e,
2173
2233
  isTrusted: isTrusted,
2174
2234
  isDouble: _this.doubleFlag
2175
- }, _this.getCurrentStore().getPosition()));
2235
+ }, _this.getCurrentStore().getPosition(), {
2236
+ preventDefault: function () {
2237
+ e.preventDefault();
2238
+ },
2239
+ preventDrag: function () {
2240
+ _this._dragFlag = false;
2241
+ }
2242
+ }));
2176
2243
 
2177
2244
  if (result === false) {
2178
2245
  _this.initDrag();
@@ -2221,24 +2288,26 @@
2221
2288
 
2222
2289
  var result = _this.moveClients(clients, e, false);
2223
2290
 
2224
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2225
- var dragResult = _this.emit("drag", __assign({}, result, {
2226
- isScroll: !!isScroll,
2227
- inputEvent: e
2228
- }));
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
+ }));
2229
2297
 
2230
- if (dragResult === false) {
2231
- _this.stop();
2298
+ if (dragResult === false) {
2299
+ _this.stop();
2232
2300
 
2233
- return;
2301
+ return;
2302
+ }
2234
2303
  }
2235
- }
2236
2304
 
2237
- if (_this.pinchFlag) {
2238
- _this.onPinch(e, clients);
2305
+ if (_this.pinchFlag) {
2306
+ _this.onPinch(e, clients);
2307
+ }
2239
2308
  }
2240
2309
 
2241
- _this.getCurrentStore().addClients(clients);
2310
+ _this.getCurrentStore().getPosition(clients, true);
2242
2311
  };
2243
2312
 
2244
2313
  _this.onDragEnd = function (e) {
@@ -2256,7 +2325,7 @@
2256
2325
 
2257
2326
  _this.flag = false;
2258
2327
 
2259
- var position = _this.getCurrentStore().getPosition();
2328
+ var position = _this._getPosition();
2260
2329
 
2261
2330
  var currentTime = now();
2262
2331
  var isDouble = !_this.isDrag && _this.doubleFlag;
@@ -2450,7 +2519,23 @@
2450
2519
  return this;
2451
2520
  };
2452
2521
  /**
2453
- * 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.
2454
2539
  */
2455
2540
 
2456
2541
 
@@ -2566,9 +2651,12 @@
2566
2651
  };
2567
2652
 
2568
2653
  __proto.moveClients = function (clients, inputEvent, isAdd) {
2569
- var store = this.getCurrentStore();
2570
- var position = store[isAdd ? "addClients" : "getPosition"](clients);
2571
- this.isDrag = true;
2654
+ var position = this._getPosition(clients, isAdd);
2655
+
2656
+ if (position.deltaX || position.deltaY) {
2657
+ this.isDrag = true;
2658
+ }
2659
+
2572
2660
  return __assign({
2573
2661
  datas: this.datas
2574
2662
  }, position, {
@@ -2580,6 +2668,25 @@
2580
2668
  });
2581
2669
  };
2582
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
+
2583
2690
  return Gesto;
2584
2691
  }(EventEmitter$1);
2585
2692
 
@@ -2766,11 +2873,11 @@
2766
2873
  setup(props) {
2767
2874
  const services = vue.inject("services");
2768
2875
  const uiService = services?.uiService;
2769
- const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2770
- const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2771
2876
  const zoom = vue.computed(() => uiService?.get("zoom") ?? 1);
2772
2877
  const showGuides = vue.computed(() => uiService?.get("showGuides") ?? true);
2773
2878
  const showRule = vue.computed(() => uiService?.get("showRule") ?? true);
2879
+ const zoomInHandler = () => uiService?.zoom(0.1);
2880
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
2774
2881
  const item = vue.computed(() => {
2775
2882
  if (typeof props.data !== "string") {
2776
2883
  return props.data;
@@ -3062,9 +3169,9 @@
3062
3169
  curFormConfig.value = [];
3063
3170
  return;
3064
3171
  }
3065
- values.value = node.value;
3066
3172
  const type = node.value.type || (node.value.items ? "container" : "text");
3067
3173
  curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
3174
+ values.value = node.value;
3068
3175
  };
3069
3176
  vue.watchEffect(init);
3070
3177
  services?.propsService.on("props-configs-change", init);
@@ -3122,11 +3229,11 @@
3122
3229
  searchText,
3123
3230
  collapseValue,
3124
3231
  list,
3125
- appendComponent({ text, type, ...config }) {
3232
+ appendComponent({ text, type, data = {} }) {
3126
3233
  services?.editorService.add({
3127
3234
  name: text,
3128
3235
  type,
3129
- ...config
3236
+ ...data
3130
3237
  });
3131
3238
  }
3132
3239
  };
@@ -3216,7 +3323,8 @@
3216
3323
  append(config) {
3217
3324
  services?.editorService.add({
3218
3325
  name: config.text,
3219
- type: config.type
3326
+ type: config.type,
3327
+ ...config.data || {}
3220
3328
  });
3221
3329
  },
3222
3330
  remove() {
@@ -3827,33 +3935,104 @@
3827
3935
  var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3828
3936
 
3829
3937
  class ScrollViewer$1 {
3830
- enter = false;
3831
- targetEnter = false;
3832
- keydown = false;
3833
- container;
3834
- target;
3835
- zoom = 1;
3836
- scrollLeft = 0;
3837
- scrollTop = 0;
3838
- x = 0;
3839
- y = 0;
3840
- resizeObserver = new ResizeObserver((entries) => {
3841
- for (const { contentRect } of entries) {
3842
- const { width, height } = contentRect;
3843
- const targetRect = this.target.getBoundingClientRect();
3844
- const targetWidth = targetRect.width * this.zoom;
3845
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3846
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3847
- if (targetWidth < width) {
3848
- this.target._left = 0;
3849
- }
3850
- if (targetHeight < height) {
3851
- 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();
3852
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);
3853
3970
  this.scroll();
3854
- }
3855
- });
3856
- 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
+ };
3857
4036
  this.container = options.container;
3858
4037
  this.target = options.target;
3859
4038
  this.zoom = options.zoom;
@@ -3889,79 +4068,6 @@
3889
4068
  document.removeEventListener("mousemove", this.mousemoveHandler);
3890
4069
  document.removeEventListener("mouseup", this.mouseupHandler);
3891
4070
  }
3892
- wheelHandler = (event) => {
3893
- if (this.targetEnter)
3894
- return;
3895
- const { deltaX, deltaY, currentTarget } = event;
3896
- if (currentTarget !== this.container)
3897
- return;
3898
- this.setScrollOffset(deltaX, deltaY);
3899
- this.scroll();
3900
- this.scrollLeft = this.target._left;
3901
- this.scrollTop = this.target._top;
3902
- };
3903
- mouseEnterHandler = () => {
3904
- this.enter = true;
3905
- };
3906
- mouseLeaveHandler = () => {
3907
- this.enter = false;
3908
- };
3909
- targetMouseEnterHandler = () => {
3910
- this.targetEnter = true;
3911
- };
3912
- targetMouseLeaveHandler = () => {
3913
- this.targetEnter = false;
3914
- };
3915
- mousedownHandler = (event) => {
3916
- if (!this.keydown)
3917
- return;
3918
- event.stopImmediatePropagation();
3919
- event.stopPropagation();
3920
- this.target.style.cursor = "grabbing";
3921
- this.x = event.clientX;
3922
- this.y = event.clientY;
3923
- document.addEventListener("mousemove", this.mousemoveHandler);
3924
- document.addEventListener("mouseup", this.mouseupHandler);
3925
- };
3926
- mouseupHandler = () => {
3927
- this.x = 0;
3928
- this.y = 0;
3929
- this.scrollLeft = this.target._left;
3930
- this.scrollTop = this.target._top;
3931
- this.removeHandler();
3932
- };
3933
- mousemoveHandler = (event) => {
3934
- event.stopImmediatePropagation();
3935
- event.stopPropagation();
3936
- const deltaX = event.clientX - this.x;
3937
- const deltaY = event.clientY - this.y;
3938
- this.setScrollOffset(deltaX, deltaY);
3939
- this.scroll();
3940
- };
3941
- keydownHandler = (event) => {
3942
- if (event.code === Keys.ESCAPE && this.enter) {
3943
- event.preventDefault();
3944
- event.stopImmediatePropagation();
3945
- event.stopPropagation();
3946
- }
3947
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3948
- return;
3949
- }
3950
- this.keydown = true;
3951
- this.target.style.cursor = "grab";
3952
- this.container.addEventListener("mousedown", this.mousedownHandler);
3953
- };
3954
- keyupHandler = (event) => {
3955
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3956
- return;
3957
- }
3958
- event.preventDefault();
3959
- event.stopImmediatePropagation();
3960
- event.stopPropagation();
3961
- this.keydown = false;
3962
- event.preventDefault();
3963
- this.removeHandler();
3964
- };
3965
4071
  setScrollOffset(deltaX, deltaY) {
3966
4072
  const { width, height } = this.container.getBoundingClientRect();
3967
4073
  const targetRect = this.target.getBoundingClientRect();
@@ -4022,7 +4128,7 @@
4022
4128
  el,
4023
4129
  style: vue.computed(() => `
4024
4130
  width: ${props.width}px;
4025
- height: ${props.height}px;
4131
+ height: ${(props.height || 0) - 40}px;
4026
4132
  position: absolute;
4027
4133
  margin-top: 30px;
4028
4134
  `)
@@ -4361,12 +4467,93 @@
4361
4467
  },
4362
4468
  setup() {
4363
4469
  const services = vue.inject("services");
4470
+ const workspace = vue.ref();
4471
+ const node = vue.computed(() => services?.editorService.get("node"));
4472
+ let keycon;
4473
+ const mouseenterHandler = () => {
4474
+ workspace.value?.focus();
4475
+ };
4476
+ vue.onMounted(() => {
4477
+ workspace.value?.addEventListener("mouseenter", mouseenterHandler);
4478
+ keycon = new KeyController__default["default"](workspace.value);
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();
4488
+ node.value && services?.editorService.copy(node.value);
4489
+ }).keyup([ctrl, "v"], (e) => {
4490
+ e.inputEvent.preventDefault();
4491
+ node.value && services?.editorService.paste();
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);
4540
+ });
4541
+ });
4542
+ vue.onUnmounted(() => {
4543
+ workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
4544
+ keycon.destroy();
4545
+ });
4364
4546
  return {
4547
+ workspace,
4365
4548
  page: vue.computed(() => services?.editorService.get("page"))
4366
4549
  };
4367
4550
  }
4368
4551
  });
4369
- const _hoisted_1 = { class: "m-editor-workspace" };
4552
+ const _hoisted_1 = {
4553
+ class: "m-editor-workspace",
4554
+ tabindex: "1",
4555
+ ref: "workspace"
4556
+ };
4370
4557
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4371
4558
  const _component_magic_stage = vue.resolveComponent("magic-stage");
4372
4559
  const _component_page_bar = vue.resolveComponent("page-bar");
@@ -4388,16 +4575,16 @@
4388
4575
  ]),
4389
4576
  _: 3
4390
4577
  })
4391
- ]);
4578
+ ], 512);
4392
4579
  }
4393
4580
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4394
4581
 
4395
4582
  class ComponentList extends BaseService {
4396
- state = vue.reactive({
4397
- list: []
4398
- });
4399
4583
  constructor() {
4400
4584
  super([]);
4585
+ this.state = vue.reactive({
4586
+ list: []
4587
+ });
4401
4588
  }
4402
4589
  setList(componentGroupList) {
4403
4590
  this.state.list = componentGroupList;
@@ -4463,6 +4650,11 @@
4463
4650
  get(name) {
4464
4651
  return state[name];
4465
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
+ }
4466
4658
  setColumnWidth({ left, center, right }) {
4467
4659
  const columnWidth = {
4468
4660
  ...vue.toRaw(this.get("columnWidth"))
@@ -4715,8 +4907,7 @@
4715
4907
  exports.uiService = uiService;
4716
4908
  exports.warn = warn;
4717
4909
 
4718
- Object.defineProperty(exports, '__esModule', { value: true });
4719
- exports[Symbol.toStringTag] = 'Module';
4910
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4720
4911
 
4721
4912
  }));
4722
4913
  //# sourceMappingURL=tmagic-editor.umd.js.map