@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
@@ -4,10 +4,11 @@ import * as monaco from 'monaco-editor';
4
4
  import { Plus, Edit, ArrowDown, Grid, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Delete, Files, Coin, ArrowLeftBold, ArrowRightBold, CaretBottom } from '@element-plus/icons';
5
5
  import { NodeType } from '@tmagic/schema';
6
6
  import { cloneDeep, random, mergeWith, throttle } from 'lodash-es';
7
- import { toLine, isPop, getNodePath } from '@tmagic/utils';
7
+ import { toLine, isPop, getNodePath, isNumber, isPage } from '@tmagic/utils';
8
8
  import { EventEmitter as EventEmitter$2 } from 'events';
9
9
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
10
10
  import { ElMessage } from 'element-plus';
11
+ import KeyController from 'keycon';
11
12
  import StageCore from '@tmagic/stage';
12
13
 
13
14
  var _export_sfc = (sfc, props) => {
@@ -341,9 +342,6 @@ const setConfig = (option) => {
341
342
  const getConfig = (key) => $TMAGIC_EDITOR[key];
342
343
 
343
344
  class UndoRedo {
344
- elementList;
345
- listCursor;
346
- listMaxSize;
347
345
  constructor(listMaxSize = 200) {
348
346
  const minListMaxSize = 2;
349
347
  this.elementList = [];
@@ -434,7 +432,7 @@ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethod
434
432
  }
435
433
  let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
436
434
  for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
437
- returnValue = await afterMethod(...beforeArgs, returnValue);
435
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
438
436
  if (isError(returnValue))
439
437
  throw returnValue;
440
438
  }
@@ -444,12 +442,12 @@ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethod
444
442
  }
445
443
  };
446
444
  class BaseService extends EventEmitter$2 {
447
- pluginOptionsList = {};
448
- middleware = {};
449
- taskList = [];
450
- doingTask = false;
451
445
  constructor(methods = [], serialMethods = []) {
452
446
  super();
447
+ this.pluginOptionsList = {};
448
+ this.middleware = {};
449
+ this.taskList = [];
450
+ this.doingTask = false;
453
451
  methods.forEach((propertyName) => {
454
452
  const scope = this;
455
453
  const sourceMethod = scope[propertyName];
@@ -506,14 +504,14 @@ class BaseService extends EventEmitter$2 {
506
504
  }
507
505
 
508
506
  class History extends BaseService {
509
- state = reactive({
510
- pageSteps: {},
511
- pageId: void 0,
512
- canRedo: false,
513
- canUndo: false
514
- });
515
507
  constructor() {
516
508
  super([]);
509
+ this.state = reactive({
510
+ pageSteps: {},
511
+ pageId: void 0,
512
+ canRedo: false,
513
+ canUndo: false
514
+ });
517
515
  this.on("change", this.setCanUndoRedo);
518
516
  }
519
517
  changePage(page) {
@@ -579,12 +577,12 @@ class History extends BaseService {
579
577
  var historyService = new History();
580
578
 
581
579
  class Props extends BaseService {
582
- state = reactive({
583
- propsConfigMap: {},
584
- propsValueMap: {}
585
- });
586
580
  constructor() {
587
581
  super(["setPropsConfig", "getPropsConfig", "setPropsValue", "getPropsValue"]);
582
+ this.state = reactive({
583
+ propsConfigMap: {},
584
+ propsValueMap: {}
585
+ });
588
586
  }
589
587
  setPropsConfigs(configs) {
590
588
  Object.keys(configs).forEach((type) => {
@@ -609,7 +607,7 @@ class Props extends BaseService {
609
607
  setPropsValue(type, value) {
610
608
  this.state.propsValueMap[type] = value;
611
609
  }
612
- async getPropsValue(type) {
610
+ async getPropsValue(type, defaultValue = {}) {
613
611
  if (type === "area") {
614
612
  const value = await this.getPropsValue("button");
615
613
  value.className = "action-area";
@@ -621,6 +619,7 @@ class Props extends BaseService {
621
619
  }
622
620
  return cloneDeep({
623
621
  ...getDefaultPropsValue(type),
622
+ ...defaultValue,
624
623
  ...this.state.propsValueMap[type] || {}
625
624
  });
626
625
  }
@@ -682,7 +681,7 @@ const updatePopId = (oldId, popId, pageConfig) => {
682
681
  };
683
682
  const setNewItemId = (config, parent) => {
684
683
  const oldId = config.id;
685
- config.id = generateId(config.type);
684
+ config.id = generateId(config.type || "component");
686
685
  config.name = `${config.name?.replace(/_(\d+)$/, "")}_${config.id}`;
687
686
  if (isPop(config) && parent?.type === NodeType.PAGE) {
688
687
  updatePopId(oldId, config.id, parent);
@@ -705,11 +704,25 @@ const toRelative = (node) => {
705
704
  };
706
705
  return node;
707
706
  };
708
- const initPosition = (node, layout) => {
707
+ const setTop2Middle = (node, parentNode, stage) => {
708
+ const style = node.style || {};
709
+ const height = style.height || 0;
710
+ if (!stage || style.top || !parentNode.style || !isNumber(height))
711
+ return style;
712
+ const { height: parentHeight } = parentNode.style;
713
+ if (isPage(parentNode)) {
714
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
715
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
716
+ } else {
717
+ style.top = (parentHeight - height) / 2;
718
+ }
719
+ return style;
720
+ };
721
+ const initPosition = (node, layout, parentNode, stage) => {
709
722
  if (layout === Layout.ABSOLUTE) {
710
723
  node.style = {
711
724
  position: "absolute",
712
- ...node.style || {}
725
+ ...setTop2Middle(node, parentNode, stage)
713
726
  };
714
727
  return node;
715
728
  }
@@ -756,7 +769,9 @@ const Fixed2Other = async (node, root, getLayout) => {
756
769
  const cur = path.pop();
757
770
  const offset = {
758
771
  left: cur?.style?.left || 0,
759
- top: cur?.style?.top || 0
772
+ top: cur?.style?.top || 0,
773
+ right: "",
774
+ bottom: ""
760
775
  };
761
776
  path.forEach((value) => {
762
777
  offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
@@ -790,16 +805,6 @@ const error = (...args) => {
790
805
  };
791
806
 
792
807
  class Editor$1 extends BaseService {
793
- isHistoryStateChange = false;
794
- state = reactive({
795
- root: null,
796
- page: null,
797
- parent: null,
798
- node: null,
799
- stage: null,
800
- highlightNode: null,
801
- modifiedNodeIds: /* @__PURE__ */ new Map()
802
- });
803
808
  constructor() {
804
809
  super([
805
810
  "getLayout",
@@ -816,6 +821,16 @@ class Editor$1 extends BaseService {
816
821
  "redo",
817
822
  "highlight"
818
823
  ], ["select", "update", "moveLayer"]);
824
+ this.isHistoryStateChange = false;
825
+ this.state = reactive({
826
+ root: null,
827
+ page: null,
828
+ parent: null,
829
+ node: null,
830
+ stage: null,
831
+ highlightNode: null,
832
+ modifiedNodeIds: /* @__PURE__ */ new Map()
833
+ });
819
834
  }
820
835
  set(name, value) {
821
836
  this.state[name] = value;
@@ -827,7 +842,7 @@ class Editor$1 extends BaseService {
827
842
  return this.state[name];
828
843
  }
829
844
  getNodeInfo(id) {
830
- const root = this.get("root");
845
+ const root = toRaw(this.get("root"));
831
846
  if (!root)
832
847
  return {};
833
848
  if (id === root.id) {
@@ -858,11 +873,13 @@ class Editor$1 extends BaseService {
858
873
  const { parent } = this.getNodeInfo(id);
859
874
  return parent;
860
875
  }
861
- async getLayout(node) {
862
- if (node.layout) {
863
- return node.layout;
876
+ async getLayout(parent, node) {
877
+ if (node && typeof node !== "function" && isFixed(node))
878
+ return Layout.FIXED;
879
+ if (parent.layout) {
880
+ return parent.layout;
864
881
  }
865
- if (!node.style?.position) {
882
+ if (!parent.style?.position) {
866
883
  return Layout.RELATIVE;
867
884
  }
868
885
  return Layout.ABSOLUTE;
@@ -879,6 +896,28 @@ class Editor$1 extends BaseService {
879
896
  }
880
897
  return node;
881
898
  }
899
+ async selectNextNode() {
900
+ const node = toRaw(this.get("node"));
901
+ if (!node || isPage(node) || node.type === NodeType.ROOT)
902
+ return node;
903
+ const parent = toRaw(this.getParentById(node.id));
904
+ if (!parent)
905
+ return node;
906
+ const index = getNodeIndex(node, parent);
907
+ const nextNode = parent.items[index + 1] || parent.items[0];
908
+ await this.select(nextNode);
909
+ this.get("stage")?.select(nextNode.id);
910
+ return nextNode;
911
+ }
912
+ async selectNextPage() {
913
+ const root = toRaw(this.get("root"));
914
+ const page = toRaw(this.get("page"));
915
+ const index = getNodeIndex(page, root);
916
+ const nextPage = root.items[index + 1] || root.items[0];
917
+ await this.select(nextPage);
918
+ this.get("stage")?.select(nextPage.id);
919
+ return nextPage;
920
+ }
882
921
  highlight(config2) {
883
922
  const { node } = this.selectedConfigExceptionHandler(config2);
884
923
  const currentHighlightNode = this.get("highlightNode");
@@ -886,7 +925,8 @@ class Editor$1 extends BaseService {
886
925
  return;
887
926
  this.set("highlightNode", node);
888
927
  }
889
- async add({ type, ...config2 }, parent) {
928
+ async add(addNode, parent) {
929
+ const { type, ...config2 } = addNode;
890
930
  const curNode = this.get("node");
891
931
  let parentNode;
892
932
  if (type === NodeType.PAGE) {
@@ -900,8 +940,8 @@ class Editor$1 extends BaseService {
900
940
  }
901
941
  if (!parentNode)
902
942
  throw new Error("\u672A\u627E\u5230\u7236\u5143\u7D20");
903
- const layout = await this.getLayout(parentNode);
904
- const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type)), ...config2 }, layout);
943
+ const layout = await this.getLayout(toRaw(parentNode), addNode);
944
+ const newNode = initPosition({ ...toRaw(await propsService.getPropsValue(type, config2)) }, layout, parentNode, this.get("stage"));
905
945
  if ((parentNode?.type === NodeType.ROOT || curNode.type === NodeType.ROOT) && newNode.type !== NodeType.PAGE) {
906
946
  throw new Error("app\u4E0B\u4E0D\u80FD\u6DFB\u52A0\u7EC4\u4EF6");
907
947
  }
@@ -978,8 +1018,8 @@ class Editor$1 extends BaseService {
978
1018
  parentNodeItems[index] = newConfig;
979
1019
  if (`${newConfig.id}` === `${this.get("node").id}`) {
980
1020
  this.set("node", newConfig);
981
- this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
982
1021
  }
1022
+ this.get("stage")?.update({ config: cloneDeep(newConfig), root: this.get("root") });
983
1023
  if (newConfig.type === NodeType.PAGE) {
984
1024
  this.set("page", newConfig);
985
1025
  }
@@ -1028,7 +1068,7 @@ class Editor$1 extends BaseService {
1028
1068
  async alignCenter(config2) {
1029
1069
  const parent = this.get("parent");
1030
1070
  const node = this.get("node");
1031
- const layout = await this.getLayout(parent);
1071
+ const layout = await this.getLayout(toRaw(parent), toRaw(node));
1032
1072
  if (layout === Layout.RELATIVE) {
1033
1073
  return;
1034
1074
  }
@@ -1065,6 +1105,26 @@ class Editor$1 extends BaseService {
1065
1105
  await this.changeHistoryState(value);
1066
1106
  return value;
1067
1107
  }
1108
+ async move(left, top) {
1109
+ const node = toRaw(this.get("node"));
1110
+ if (!node || isPage(node))
1111
+ return;
1112
+ const { style, id } = node;
1113
+ if (!style || style.position !== "absolute")
1114
+ return;
1115
+ if (top && !isNumber(style.top))
1116
+ return;
1117
+ if (left && !isNumber(style.left))
1118
+ return;
1119
+ this.update({
1120
+ id,
1121
+ style: {
1122
+ ...style,
1123
+ left: Number(style.left) + left,
1124
+ top: Number(style.top) + top
1125
+ }
1126
+ });
1127
+ }
1068
1128
  destroy() {
1069
1129
  this.removeAllListeners();
1070
1130
  this.set("root", null);
@@ -1097,7 +1157,12 @@ class Editor$1 extends BaseService {
1097
1157
  this.isHistoryStateChange = true;
1098
1158
  await this.update(value.data);
1099
1159
  this.set("modifiedNodeIds", value.modifiedNodeIds);
1100
- setTimeout(() => value.nodeId && this.select(value.nodeId), 0);
1160
+ setTimeout(async () => {
1161
+ if (!value.nodeId)
1162
+ return;
1163
+ await this.select(value.nodeId);
1164
+ this.get("stage")?.select(value.nodeId);
1165
+ }, 0);
1101
1166
  }
1102
1167
  async toggleFixedPosition(dist, src, root) {
1103
1168
  let newConfig = cloneDeep(dist);
@@ -1321,7 +1386,7 @@ const fillConfig = (config = []) => [
1321
1386
  type: "select",
1322
1387
  options: (mForm, { model }) => {
1323
1388
  const node = editorService.getNodeById(model.to);
1324
- if (!node)
1389
+ if (!node?.type)
1325
1390
  return [];
1326
1391
  return eventsService.getMethod(node.type).map((option) => ({
1327
1392
  text: option.label,
@@ -1802,8 +1867,8 @@ Copyright (c) 2019 Daybrush
1802
1867
  name: gesto
1803
1868
  license: MIT
1804
1869
  author: Daybrush
1805
- repository: git+https://github.com/daybrush/gesture.git
1806
- version: 1.5.0
1870
+ repository: git+https://github.com/daybrush/gesto.git
1871
+ version: 1.7.0
1807
1872
  */
1808
1873
 
1809
1874
  /*! *****************************************************************************
@@ -1972,19 +2037,6 @@ function () {
1972
2037
 
1973
2038
  var __proto = ClientStore.prototype;
1974
2039
 
1975
- __proto.addClients = function (clients) {
1976
- if (clients === void 0) {
1977
- clients = this.prevClients;
1978
- }
1979
-
1980
- var position = this.getPosition(clients);
1981
- var deltaX = position.deltaX,
1982
- deltaY = position.deltaY;
1983
- this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
1984
- this.prevClients = clients;
1985
- return position;
1986
- };
1987
-
1988
2040
  __proto.getAngle = function (clients) {
1989
2041
  if (clients === void 0) {
1990
2042
  clients = this.prevClients;
@@ -2001,8 +2053,17 @@ function () {
2001
2053
  return getRotatiion(clients) - getRotatiion(this.startClients);
2002
2054
  };
2003
2055
 
2004
- __proto.getPosition = function (clients) {
2005
- return getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2056
+ __proto.getPosition = function (clients, isAdd) {
2057
+ if (clients === void 0) {
2058
+ clients = this.prevClients;
2059
+ }
2060
+
2061
+ var position = getPosition(clients || this.prevClients, this.prevClients, this.startClients);
2062
+ var deltaX = position.deltaX,
2063
+ deltaY = position.deltaY;
2064
+ this.movement += Math.sqrt(deltaX * deltaX + deltaY * deltaY);
2065
+ this.prevClients = clients;
2066
+ return position;
2006
2067
  };
2007
2068
 
2008
2069
  __proto.getPositions = function (clients) {
@@ -2051,10 +2112,6 @@ function () {
2051
2112
  client.clientX -= deltaX;
2052
2113
  client.clientY -= deltaY;
2053
2114
  });
2054
- this.prevClients.forEach(function (client) {
2055
- client.clientX -= deltaX;
2056
- client.clientY -= deltaY;
2057
- });
2058
2115
  };
2059
2116
 
2060
2117
  return ClientStore;
@@ -2093,6 +2150,7 @@ function (_super) {
2093
2150
  _this.targets = [];
2094
2151
  _this.prevTime = 0;
2095
2152
  _this.doubleFlag = false;
2153
+ _this._dragFlag = false;
2096
2154
 
2097
2155
  _this.onDragStart = function (e, isTrusted) {
2098
2156
  if (isTrusted === void 0) {
@@ -2123,7 +2181,8 @@ function (_super) {
2123
2181
  if (checkInput || activeElement === target) {
2124
2182
  // force false or already focused.
2125
2183
  return false;
2126
- }
2184
+ } // no focus
2185
+
2127
2186
 
2128
2187
  if (activeElement && hasContentEditable && activeElement.isContentEditable && activeElement.contains(target)) {
2129
2188
  return false;
@@ -2139,6 +2198,7 @@ function (_super) {
2139
2198
  _this.clientStores = [new ClientStore(getEventClients(e))];
2140
2199
  _this.flag = true;
2141
2200
  _this.isDrag = false;
2201
+ _this._dragFlag = true;
2142
2202
  _this.datas = {};
2143
2203
 
2144
2204
  if (preventRightClick && (e.which === 3 || e.button === 2)) {
@@ -2154,7 +2214,14 @@ function (_super) {
2154
2214
  inputEvent: e,
2155
2215
  isTrusted: isTrusted,
2156
2216
  isDouble: _this.doubleFlag
2157
- }, _this.getCurrentStore().getPosition()));
2217
+ }, _this.getCurrentStore().getPosition(), {
2218
+ preventDefault: function () {
2219
+ e.preventDefault();
2220
+ },
2221
+ preventDrag: function () {
2222
+ _this._dragFlag = false;
2223
+ }
2224
+ }));
2158
2225
 
2159
2226
  if (result === false) {
2160
2227
  _this.initDrag();
@@ -2203,24 +2270,26 @@ function (_super) {
2203
2270
 
2204
2271
  var result = _this.moveClients(clients, e, false);
2205
2272
 
2206
- if (_this.pinchFlag || result.deltaX || result.deltaY) {
2207
- var dragResult = _this.emit("drag", __assign({}, result, {
2208
- isScroll: !!isScroll,
2209
- inputEvent: e
2210
- }));
2273
+ if (_this._dragFlag) {
2274
+ if (_this.pinchFlag || result.deltaX || result.deltaY) {
2275
+ var dragResult = _this.emit("drag", __assign({}, result, {
2276
+ isScroll: !!isScroll,
2277
+ inputEvent: e
2278
+ }));
2211
2279
 
2212
- if (dragResult === false) {
2213
- _this.stop();
2280
+ if (dragResult === false) {
2281
+ _this.stop();
2214
2282
 
2215
- return;
2283
+ return;
2284
+ }
2216
2285
  }
2217
- }
2218
2286
 
2219
- if (_this.pinchFlag) {
2220
- _this.onPinch(e, clients);
2287
+ if (_this.pinchFlag) {
2288
+ _this.onPinch(e, clients);
2289
+ }
2221
2290
  }
2222
2291
 
2223
- _this.getCurrentStore().addClients(clients);
2292
+ _this.getCurrentStore().getPosition(clients, true);
2224
2293
  };
2225
2294
 
2226
2295
  _this.onDragEnd = function (e) {
@@ -2238,7 +2307,7 @@ function (_super) {
2238
2307
 
2239
2308
  _this.flag = false;
2240
2309
 
2241
- var position = _this.getCurrentStore().getPosition();
2310
+ var position = _this._getPosition();
2242
2311
 
2243
2312
  var currentTime = now();
2244
2313
  var isDouble = !_this.isDrag && _this.doubleFlag;
@@ -2432,7 +2501,23 @@ function (_super) {
2432
2501
  return this;
2433
2502
  };
2434
2503
  /**
2435
- * Set the event data while dragging.
2504
+ * Get the current event state while dragging.
2505
+ */
2506
+
2507
+
2508
+ __proto.getCurrentEvent = function (inputEvent) {
2509
+ return __assign({
2510
+ datas: this.datas
2511
+ }, this._getPosition(), {
2512
+ movement: this.getMovement(),
2513
+ isDrag: this.isDrag,
2514
+ isPinch: this.isPinch,
2515
+ isScroll: false,
2516
+ inputEvent: inputEvent
2517
+ });
2518
+ };
2519
+ /**
2520
+ * Get & Set the event data while dragging.
2436
2521
  */
2437
2522
 
2438
2523
 
@@ -2548,9 +2633,12 @@ function (_super) {
2548
2633
  };
2549
2634
 
2550
2635
  __proto.moveClients = function (clients, inputEvent, isAdd) {
2551
- var store = this.getCurrentStore();
2552
- var position = store[isAdd ? "addClients" : "getPosition"](clients);
2553
- this.isDrag = true;
2636
+ var position = this._getPosition(clients, isAdd);
2637
+
2638
+ if (position.deltaX || position.deltaY) {
2639
+ this.isDrag = true;
2640
+ }
2641
+
2554
2642
  return __assign({
2555
2643
  datas: this.datas
2556
2644
  }, position, {
@@ -2562,6 +2650,25 @@ function (_super) {
2562
2650
  });
2563
2651
  };
2564
2652
 
2653
+ __proto._getPosition = function (clients, isAdd) {
2654
+ var store = this.getCurrentStore();
2655
+ var position = store.getPosition(clients, isAdd);
2656
+
2657
+ var _a = this.clientStores.slice(1).reduce(function (prev, cur) {
2658
+ var storePosition = cur.getPosition();
2659
+ prev.distX += storePosition.distX;
2660
+ prev.distY += storePosition.distY;
2661
+ return prev;
2662
+ }, position),
2663
+ distX = _a.distX,
2664
+ distY = _a.distY;
2665
+
2666
+ return __assign({}, position, {
2667
+ distX: distX,
2668
+ distY: distY
2669
+ });
2670
+ };
2671
+
2565
2672
  return Gesto;
2566
2673
  }(EventEmitter$1);
2567
2674
 
@@ -2748,11 +2855,11 @@ const _sfc_main$c = defineComponent({
2748
2855
  setup(props) {
2749
2856
  const services = inject("services");
2750
2857
  const uiService = services?.uiService;
2751
- const zoomInHandler = () => uiService?.set("zoom", zoom.value + 0.1);
2752
- const zoomOutHandler = () => uiService?.set("zoom", zoom.value - 0.1);
2753
2858
  const zoom = computed(() => uiService?.get("zoom") ?? 1);
2754
2859
  const showGuides = computed(() => uiService?.get("showGuides") ?? true);
2755
2860
  const showRule = computed(() => uiService?.get("showRule") ?? true);
2861
+ const zoomInHandler = () => uiService?.zoom(0.1);
2862
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
2756
2863
  const item = computed(() => {
2757
2864
  if (typeof props.data !== "string") {
2758
2865
  return props.data;
@@ -3044,9 +3151,9 @@ const _sfc_main$a = defineComponent({
3044
3151
  curFormConfig.value = [];
3045
3152
  return;
3046
3153
  }
3047
- values.value = node.value;
3048
3154
  const type = node.value.type || (node.value.items ? "container" : "text");
3049
3155
  curFormConfig.value = await services?.propsService.getPropsConfig(type) || [];
3156
+ values.value = node.value;
3050
3157
  };
3051
3158
  watchEffect(init);
3052
3159
  services?.propsService.on("props-configs-change", init);
@@ -3104,11 +3211,11 @@ const _sfc_main$9 = defineComponent({
3104
3211
  searchText,
3105
3212
  collapseValue,
3106
3213
  list,
3107
- appendComponent({ text, type, ...config }) {
3214
+ appendComponent({ text, type, data = {} }) {
3108
3215
  services?.editorService.add({
3109
3216
  name: text,
3110
3217
  type,
3111
- ...config
3218
+ ...data
3112
3219
  });
3113
3220
  }
3114
3221
  };
@@ -3198,7 +3305,8 @@ const _sfc_main$8 = defineComponent({
3198
3305
  append(config) {
3199
3306
  services?.editorService.add({
3200
3307
  name: config.text,
3201
- type: config.type
3308
+ type: config.type,
3309
+ ...config.data || {}
3202
3310
  });
3203
3311
  },
3204
3312
  remove() {
@@ -3809,33 +3917,104 @@ function _sfc_render$5(_ctx, _cache, $props, $setup, $data, $options) {
3809
3917
  var PageBar = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$5]]);
3810
3918
 
3811
3919
  class ScrollViewer$1 {
3812
- enter = false;
3813
- targetEnter = false;
3814
- keydown = false;
3815
- container;
3816
- target;
3817
- zoom = 1;
3818
- scrollLeft = 0;
3819
- scrollTop = 0;
3820
- x = 0;
3821
- y = 0;
3822
- resizeObserver = new ResizeObserver((entries) => {
3823
- for (const { contentRect } of entries) {
3824
- const { width, height } = contentRect;
3825
- const targetRect = this.target.getBoundingClientRect();
3826
- const targetWidth = targetRect.width * this.zoom;
3827
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
3828
- const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3829
- if (targetWidth < width) {
3830
- this.target._left = 0;
3831
- }
3832
- if (targetHeight < height) {
3833
- this.target._top = 0;
3920
+ constructor(options) {
3921
+ this.enter = false;
3922
+ this.targetEnter = false;
3923
+ this.keydown = false;
3924
+ this.zoom = 1;
3925
+ this.scrollLeft = 0;
3926
+ this.scrollTop = 0;
3927
+ this.x = 0;
3928
+ this.y = 0;
3929
+ this.resizeObserver = new ResizeObserver((entries) => {
3930
+ for (const { contentRect } of entries) {
3931
+ const { width, height } = contentRect;
3932
+ const targetRect = this.target.getBoundingClientRect();
3933
+ const targetWidth = targetRect.width * this.zoom;
3934
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
3935
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
3936
+ if (targetWidth < width) {
3937
+ this.target._left = 0;
3938
+ }
3939
+ if (targetHeight < height) {
3940
+ this.target._top = 0;
3941
+ }
3942
+ this.scroll();
3834
3943
  }
3944
+ });
3945
+ this.wheelHandler = (event) => {
3946
+ if (this.targetEnter)
3947
+ return;
3948
+ const { deltaX, deltaY, currentTarget } = event;
3949
+ if (currentTarget !== this.container)
3950
+ return;
3951
+ this.setScrollOffset(deltaX, deltaY);
3835
3952
  this.scroll();
3836
- }
3837
- });
3838
- constructor(options) {
3953
+ this.scrollLeft = this.target._left;
3954
+ this.scrollTop = this.target._top;
3955
+ };
3956
+ this.mouseEnterHandler = () => {
3957
+ this.enter = true;
3958
+ };
3959
+ this.mouseLeaveHandler = () => {
3960
+ this.enter = false;
3961
+ };
3962
+ this.targetMouseEnterHandler = () => {
3963
+ this.targetEnter = true;
3964
+ };
3965
+ this.targetMouseLeaveHandler = () => {
3966
+ this.targetEnter = false;
3967
+ };
3968
+ this.mousedownHandler = (event) => {
3969
+ if (!this.keydown)
3970
+ return;
3971
+ event.stopImmediatePropagation();
3972
+ event.stopPropagation();
3973
+ this.target.style.cursor = "grabbing";
3974
+ this.x = event.clientX;
3975
+ this.y = event.clientY;
3976
+ document.addEventListener("mousemove", this.mousemoveHandler);
3977
+ document.addEventListener("mouseup", this.mouseupHandler);
3978
+ };
3979
+ this.mouseupHandler = () => {
3980
+ this.x = 0;
3981
+ this.y = 0;
3982
+ this.scrollLeft = this.target._left;
3983
+ this.scrollTop = this.target._top;
3984
+ this.removeHandler();
3985
+ };
3986
+ this.mousemoveHandler = (event) => {
3987
+ event.stopImmediatePropagation();
3988
+ event.stopPropagation();
3989
+ const deltaX = event.clientX - this.x;
3990
+ const deltaY = event.clientY - this.y;
3991
+ this.setScrollOffset(deltaX, deltaY);
3992
+ this.scroll();
3993
+ };
3994
+ this.keydownHandler = (event) => {
3995
+ if (event.code === Keys.ESCAPE && this.enter) {
3996
+ event.preventDefault();
3997
+ event.stopImmediatePropagation();
3998
+ event.stopPropagation();
3999
+ }
4000
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
4001
+ return;
4002
+ }
4003
+ this.keydown = true;
4004
+ this.target.style.cursor = "grab";
4005
+ this.container.addEventListener("mousedown", this.mousedownHandler);
4006
+ };
4007
+ this.keyupHandler = (event) => {
4008
+ if (event.code !== Keys.ESCAPE || !this.keydown) {
4009
+ return;
4010
+ }
4011
+ event.preventDefault();
4012
+ event.stopImmediatePropagation();
4013
+ event.stopPropagation();
4014
+ this.keydown = false;
4015
+ event.preventDefault();
4016
+ this.removeHandler();
4017
+ };
3839
4018
  this.container = options.container;
3840
4019
  this.target = options.target;
3841
4020
  this.zoom = options.zoom;
@@ -3871,79 +4050,6 @@ class ScrollViewer$1 {
3871
4050
  document.removeEventListener("mousemove", this.mousemoveHandler);
3872
4051
  document.removeEventListener("mouseup", this.mouseupHandler);
3873
4052
  }
3874
- wheelHandler = (event) => {
3875
- if (this.targetEnter)
3876
- return;
3877
- const { deltaX, deltaY, currentTarget } = event;
3878
- if (currentTarget !== this.container)
3879
- return;
3880
- this.setScrollOffset(deltaX, deltaY);
3881
- this.scroll();
3882
- this.scrollLeft = this.target._left;
3883
- this.scrollTop = this.target._top;
3884
- };
3885
- mouseEnterHandler = () => {
3886
- this.enter = true;
3887
- };
3888
- mouseLeaveHandler = () => {
3889
- this.enter = false;
3890
- };
3891
- targetMouseEnterHandler = () => {
3892
- this.targetEnter = true;
3893
- };
3894
- targetMouseLeaveHandler = () => {
3895
- this.targetEnter = false;
3896
- };
3897
- mousedownHandler = (event) => {
3898
- if (!this.keydown)
3899
- return;
3900
- event.stopImmediatePropagation();
3901
- event.stopPropagation();
3902
- this.target.style.cursor = "grabbing";
3903
- this.x = event.clientX;
3904
- this.y = event.clientY;
3905
- document.addEventListener("mousemove", this.mousemoveHandler);
3906
- document.addEventListener("mouseup", this.mouseupHandler);
3907
- };
3908
- mouseupHandler = () => {
3909
- this.x = 0;
3910
- this.y = 0;
3911
- this.scrollLeft = this.target._left;
3912
- this.scrollTop = this.target._top;
3913
- this.removeHandler();
3914
- };
3915
- mousemoveHandler = (event) => {
3916
- event.stopImmediatePropagation();
3917
- event.stopPropagation();
3918
- const deltaX = event.clientX - this.x;
3919
- const deltaY = event.clientY - this.y;
3920
- this.setScrollOffset(deltaX, deltaY);
3921
- this.scroll();
3922
- };
3923
- keydownHandler = (event) => {
3924
- if (event.code === Keys.ESCAPE && this.enter) {
3925
- event.preventDefault();
3926
- event.stopImmediatePropagation();
3927
- event.stopPropagation();
3928
- }
3929
- if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
3930
- return;
3931
- }
3932
- this.keydown = true;
3933
- this.target.style.cursor = "grab";
3934
- this.container.addEventListener("mousedown", this.mousedownHandler);
3935
- };
3936
- keyupHandler = (event) => {
3937
- if (event.code !== Keys.ESCAPE || !this.keydown) {
3938
- return;
3939
- }
3940
- event.preventDefault();
3941
- event.stopImmediatePropagation();
3942
- event.stopPropagation();
3943
- this.keydown = false;
3944
- event.preventDefault();
3945
- this.removeHandler();
3946
- };
3947
4053
  setScrollOffset(deltaX, deltaY) {
3948
4054
  const { width, height } = this.container.getBoundingClientRect();
3949
4055
  const targetRect = this.target.getBoundingClientRect();
@@ -4004,7 +4110,7 @@ const _sfc_main$4 = defineComponent({
4004
4110
  el,
4005
4111
  style: computed(() => `
4006
4112
  width: ${props.width}px;
4007
- height: ${props.height}px;
4113
+ height: ${(props.height || 0) - 40}px;
4008
4114
  position: absolute;
4009
4115
  margin-top: 30px;
4010
4116
  `)
@@ -4343,12 +4449,93 @@ const _sfc_main$1 = defineComponent({
4343
4449
  },
4344
4450
  setup() {
4345
4451
  const services = inject("services");
4452
+ const workspace = ref();
4453
+ const node = computed(() => services?.editorService.get("node"));
4454
+ let keycon;
4455
+ const mouseenterHandler = () => {
4456
+ workspace.value?.focus();
4457
+ };
4458
+ onMounted(() => {
4459
+ workspace.value?.addEventListener("mouseenter", mouseenterHandler);
4460
+ keycon = new KeyController(workspace.value);
4461
+ const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
4462
+ const ctrl = isMac ? "meta" : "ctrl";
4463
+ keycon.keyup("delete", (e) => {
4464
+ e.inputEvent.preventDefault();
4465
+ if (!node.value || isPage(node.value))
4466
+ return;
4467
+ services?.editorService.remove(node.value);
4468
+ }).keydown([ctrl, "c"], (e) => {
4469
+ e.inputEvent.preventDefault();
4470
+ node.value && services?.editorService.copy(node.value);
4471
+ }).keyup([ctrl, "v"], (e) => {
4472
+ e.inputEvent.preventDefault();
4473
+ node.value && services?.editorService.paste();
4474
+ }).keyup([ctrl, "x"], (e) => {
4475
+ e.inputEvent.preventDefault();
4476
+ if (!node.value || isPage(node.value))
4477
+ return;
4478
+ services?.editorService.copy(node.value);
4479
+ services?.editorService.remove(node.value);
4480
+ }).keydown([ctrl, "z"], (e) => {
4481
+ e.inputEvent.preventDefault();
4482
+ services?.editorService.undo();
4483
+ }).keydown([ctrl, "shift", "z"], (e) => {
4484
+ e.inputEvent.preventDefault();
4485
+ services?.editorService.redo();
4486
+ }).keydown("up", (e) => {
4487
+ e.inputEvent.preventDefault();
4488
+ services?.editorService.move(0, -1);
4489
+ }).keydown("down", (e) => {
4490
+ e.inputEvent.preventDefault();
4491
+ services?.editorService.move(0, 1);
4492
+ }).keydown("left", (e) => {
4493
+ e.inputEvent.preventDefault();
4494
+ services?.editorService.move(-1, 0);
4495
+ }).keydown("right", (e) => {
4496
+ e.inputEvent.preventDefault();
4497
+ services?.editorService.move(1, 0);
4498
+ }).keydown([ctrl, "up"], (e) => {
4499
+ e.inputEvent.preventDefault();
4500
+ services?.editorService.move(0, -10);
4501
+ }).keydown([ctrl, "down"], (e) => {
4502
+ e.inputEvent.preventDefault();
4503
+ services?.editorService.move(0, 10);
4504
+ }).keydown([ctrl, "left"], (e) => {
4505
+ e.inputEvent.preventDefault();
4506
+ services?.editorService.move(-10, 0);
4507
+ }).keydown([ctrl, "right"], (e) => {
4508
+ e.inputEvent.preventDefault();
4509
+ services?.editorService.move(10, 0);
4510
+ }).keydown("tab", (e) => {
4511
+ e.inputEvent.preventDefault();
4512
+ services?.editorService.selectNextNode();
4513
+ }).keydown([ctrl, "tab"], (e) => {
4514
+ e.inputEvent.preventDefault();
4515
+ services?.editorService.selectNextPage();
4516
+ }).keydown([ctrl, "="], (e) => {
4517
+ e.inputEvent.preventDefault();
4518
+ services?.uiService.zoom(0.1);
4519
+ }).keydown([ctrl, "-"], (e) => {
4520
+ e.inputEvent.preventDefault();
4521
+ services?.uiService.zoom(-0.1);
4522
+ });
4523
+ });
4524
+ onUnmounted(() => {
4525
+ workspace.value?.removeEventListener("mouseenter", mouseenterHandler);
4526
+ keycon.destroy();
4527
+ });
4346
4528
  return {
4529
+ workspace,
4347
4530
  page: computed(() => services?.editorService.get("page"))
4348
4531
  };
4349
4532
  }
4350
4533
  });
4351
- const _hoisted_1 = { class: "m-editor-workspace" };
4534
+ const _hoisted_1 = {
4535
+ class: "m-editor-workspace",
4536
+ tabindex: "1",
4537
+ ref: "workspace"
4538
+ };
4352
4539
  function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4353
4540
  const _component_magic_stage = resolveComponent("magic-stage");
4354
4541
  const _component_page_bar = resolveComponent("page-bar");
@@ -4370,16 +4557,16 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4370
4557
  ]),
4371
4558
  _: 3
4372
4559
  })
4373
- ]);
4560
+ ], 512);
4374
4561
  }
4375
4562
  var Workspace = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
4376
4563
 
4377
4564
  class ComponentList extends BaseService {
4378
- state = reactive({
4379
- list: []
4380
- });
4381
4565
  constructor() {
4382
4566
  super([]);
4567
+ this.state = reactive({
4568
+ list: []
4569
+ });
4383
4570
  }
4384
4571
  setList(componentGroupList) {
4385
4572
  this.state.list = componentGroupList;
@@ -4445,6 +4632,11 @@ class Ui extends BaseService {
4445
4632
  get(name) {
4446
4633
  return state[name];
4447
4634
  }
4635
+ zoom(zoom) {
4636
+ this.set("zoom", (this.get("zoom") * 100 + zoom * 100) / 100);
4637
+ if (this.get("zoom") < 0.1)
4638
+ this.set("zoom", 0.1);
4639
+ }
4448
4640
  setColumnWidth({ left, center, right }) {
4449
4641
  const columnWidth = {
4450
4642
  ...toRaw(this.get("columnWidth"))