@tmagic/editor 1.4.16 → 1.5.0-beta.0

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 (135) hide show
  1. package/dist/style.css +2 -2
  2. package/dist/tmagic-editor.js +274 -265
  3. package/dist/tmagic-editor.umd.cjs +275 -262
  4. package/package.json +11 -15
  5. package/src/components/CodeParams.vue +1 -1
  6. package/src/editorProps.ts +2 -1
  7. package/src/fields/DataSourceInput.vue +2 -2
  8. package/src/fields/UISelect.vue +20 -15
  9. package/src/hooks/use-stage.ts +13 -7
  10. package/src/initService.ts +50 -53
  11. package/src/layouts/workspace/viewer/NodeListMenu.vue +2 -1
  12. package/src/layouts/workspace/viewer/Stage.vue +4 -3
  13. package/src/services/editor.ts +2 -2
  14. package/src/services/stageOverlay.ts +3 -1
  15. package/src/theme/page-bar.scss +2 -2
  16. package/src/utils/data-source/index.ts +25 -23
  17. package/src/utils/editor.ts +4 -3
  18. package/src/utils/index.ts +4 -0
  19. package/src/utils/operator.ts +3 -2
  20. package/src/utils/props.ts +2 -1
  21. package/types/index.d.ts +6484 -49
  22. package/src/shims-vue.d.ts +0 -6
  23. package/types/Editor.vue.d.ts +0 -2313
  24. package/types/components/CodeBlockEditor.vue.d.ts +0 -33
  25. package/types/components/CodeParams.vue.d.ts +0 -28
  26. package/types/components/ContentMenu.vue.d.ts +0 -81
  27. package/types/components/FloatingBox.vue.d.ts +0 -70
  28. package/types/components/Icon.vue.d.ts +0 -15
  29. package/types/components/Resizer.vue.d.ts +0 -16
  30. package/types/components/ScrollBar.vue.d.ts +0 -25
  31. package/types/components/ScrollViewer.vue.d.ts +0 -81
  32. package/types/components/SearchInput.vue.d.ts +0 -6
  33. package/types/components/SplitView.vue.d.ts +0 -72
  34. package/types/components/ToolButton.vue.d.ts +0 -41
  35. package/types/components/Tree.vue.d.ts +0 -83
  36. package/types/components/TreeNode.vue.d.ts +0 -83
  37. package/types/editorProps.d.ts +0 -111
  38. package/types/fields/Code.vue.d.ts +0 -44
  39. package/types/fields/CodeLink.vue.d.ts +0 -24
  40. package/types/fields/CodeSelect.vue.d.ts +0 -28
  41. package/types/fields/CodeSelectCol.vue.d.ts +0 -31
  42. package/types/fields/CondOpSelect.vue.d.ts +0 -17
  43. package/types/fields/DataSourceFieldSelect/FieldSelect.vue.d.ts +0 -36
  44. package/types/fields/DataSourceFieldSelect/Index.vue.d.ts +0 -31
  45. package/types/fields/DataSourceFields.vue.d.ts +0 -44
  46. package/types/fields/DataSourceInput.vue.d.ts +0 -34
  47. package/types/fields/DataSourceMethodSelect.vue.d.ts +0 -31
  48. package/types/fields/DataSourceMethods.vue.d.ts +0 -34
  49. package/types/fields/DataSourceMocks.vue.d.ts +0 -41
  50. package/types/fields/DataSourceSelect.vue.d.ts +0 -31
  51. package/types/fields/DisplayConds.vue.d.ts +0 -37
  52. package/types/fields/EventSelect.vue.d.ts +0 -17
  53. package/types/fields/KeyValue.vue.d.ts +0 -36
  54. package/types/fields/PageFragmentSelect.vue.d.ts +0 -31
  55. package/types/fields/UISelect.vue.d.ts +0 -20
  56. package/types/hooks/index.d.ts +0 -6
  57. package/types/hooks/use-code-block-edit.d.ts +0 -189
  58. package/types/hooks/use-data-source-edit.d.ts +0 -176
  59. package/types/hooks/use-data-source-method.d.ts +0 -187
  60. package/types/hooks/use-editor-content-height.d.ts +0 -3
  61. package/types/hooks/use-filter.d.ts +0 -7
  62. package/types/hooks/use-float-box.d.ts +0 -17
  63. package/types/hooks/use-getso.d.ts +0 -5
  64. package/types/hooks/use-next-float-box-position.d.ts +0 -15
  65. package/types/hooks/use-node-status.d.ts +0 -16
  66. package/types/hooks/use-stage.d.ts +0 -3
  67. package/types/hooks/use-window-rect.d.ts +0 -6
  68. package/types/icons/AppManageIcon.vue.d.ts +0 -2
  69. package/types/icons/CenterIcon.vue.d.ts +0 -2
  70. package/types/icons/CodeIcon.vue.d.ts +0 -2
  71. package/types/icons/FolderMinusIcon.vue.d.ts +0 -2
  72. package/types/icons/PinIcon.vue.d.ts +0 -2
  73. package/types/icons/PinnedIcon.vue.d.ts +0 -2
  74. package/types/initService.d.ts +0 -9
  75. package/types/layouts/AddPageBox.vue.d.ts +0 -15
  76. package/types/layouts/CodeEditor.vue.d.ts +0 -80
  77. package/types/layouts/Framework.vue.d.ts +0 -25
  78. package/types/layouts/NavMenu.vue.d.ts +0 -35
  79. package/types/layouts/PropsPanel.vue.d.ts +0 -535
  80. package/types/layouts/page-bar/AddButton.vue.d.ts +0 -16
  81. package/types/layouts/page-bar/PageBar.vue.d.ts +0 -36
  82. package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +0 -29
  83. package/types/layouts/page-bar/PageList.vue.d.ts +0 -27
  84. package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +0 -20
  85. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -10
  86. package/types/layouts/sidebar/Sidebar.vue.d.ts +0 -51
  87. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +0 -32
  88. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +0 -24
  89. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +0 -31
  90. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +0 -18
  91. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +0 -10
  92. package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +0 -41
  93. package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +0 -16
  94. package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +0 -25
  95. package/types/layouts/sidebar/layer/use-click.d.ts +0 -119
  96. package/types/layouts/sidebar/layer/use-drag.d.ts +0 -14
  97. package/types/layouts/sidebar/layer/use-keybinding.d.ts +0 -6
  98. package/types/layouts/sidebar/layer/use-node-status.d.ts +0 -16
  99. package/types/layouts/workspace/Breadcrumb.vue.d.ts +0 -2
  100. package/types/layouts/workspace/Workspace.vue.d.ts +0 -41
  101. package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +0 -2
  102. package/types/layouts/workspace/viewer/Stage.vue.d.ts +0 -34
  103. package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +0 -2
  104. package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +0 -42
  105. package/types/services/BaseService.d.ts +0 -65
  106. package/types/services/codeBlock.d.ts +0 -130
  107. package/types/services/componentList.d.ts +0 -16
  108. package/types/services/dataSource.d.ts +0 -68
  109. package/types/services/dep.d.ts +0 -33
  110. package/types/services/editor.d.ts +0 -180
  111. package/types/services/events.d.ts +0 -18
  112. package/types/services/history.d.ts +0 -26
  113. package/types/services/keybinding.d.ts +0 -40
  114. package/types/services/props.d.ts +0 -92
  115. package/types/services/stageOverlay.d.ts +0 -30
  116. package/types/services/storage.d.ts +0 -65
  117. package/types/services/ui.d.ts +0 -77
  118. package/types/type.d.ts +0 -657
  119. package/types/utils/compose.d.ts +0 -5
  120. package/types/utils/config.d.ts +0 -4
  121. package/types/utils/content-menu.d.ts +0 -7
  122. package/types/utils/data-source/formConfigs/base.d.ts +0 -2
  123. package/types/utils/data-source/formConfigs/http.d.ts +0 -3
  124. package/types/utils/data-source/index.d.ts +0 -10
  125. package/types/utils/editor.d.ts +0 -59
  126. package/types/utils/idle-task.d.ts +0 -13
  127. package/types/utils/index.d.ts +0 -6
  128. package/types/utils/keybinding-config.d.ts +0 -7
  129. package/types/utils/logger.d.ts +0 -5
  130. package/types/utils/monaco-editor.d.ts +0 -2
  131. package/types/utils/operator.d.ts +0 -21
  132. package/types/utils/props.d.ts +0 -23
  133. package/types/utils/scroll-viewer.d.ts +0 -37
  134. package/types/utils/tree.d.ts +0 -3
  135. package/types/utils/undo-redo.d.ts +0 -12
@@ -840,7 +840,7 @@
840
840
  items: [
841
841
  {
842
842
  type: "display-conds",
843
- name: "displayConds",
843
+ name: schema.NODE_CONDS_KEY,
844
844
  titlePrefix: "条件组",
845
845
  defaultValue: []
846
846
  }
@@ -1116,8 +1116,8 @@
1116
1116
  };
1117
1117
  const fixNodeLeft = (config, parent, doc) => {
1118
1118
  if (!doc || !config.style || !utils.isNumber(config.style.left)) return config.style?.left;
1119
- const el = doc.getElementById(`${config.id}`);
1120
- const parentEl = doc.getElementById(`${parent.id}`);
1119
+ const el = utils.getElById()(doc, `${config.id}`);
1120
+ const parentEl = utils.getElById()(doc, `${parent.id}`);
1121
1121
  const left = Number(config.style?.left) || 0;
1122
1122
  if (el && parentEl) {
1123
1123
  const calcParentOffsetWidth = utils.calcValueByFontsize(doc, parentEl.offsetWidth);
@@ -2314,7 +2314,7 @@
2314
2314
  const stage = this.get("stage");
2315
2315
  const doc = stage?.renderer.contentWindow?.document;
2316
2316
  if (doc) {
2317
- const el = doc.getElementById(`${node.id}`);
2317
+ const el = utils.getElById()(doc, node.id);
2318
2318
  const parentEl = layout === Layout.FIXED ? doc.body : el?.offsetParent;
2319
2319
  if (parentEl && el) {
2320
2320
  node.style.left = utils.calcValueByFontsize(doc, (parentEl.clientWidth - el.clientWidth) / 2);
@@ -2659,7 +2659,8 @@
2659
2659
  };
2660
2660
  const getPositionInContainer = (position = {}, id, doc) => {
2661
2661
  let { left = 0, top = 0 } = position;
2662
- const parentEl = editorService.get("stage")?.renderer?.contentWindow?.document.getElementById(`${id}`);
2662
+ const stageDoc = editorService.get("stage")?.renderer?.contentWindow?.document;
2663
+ const parentEl = stageDoc && utils.getElById()(stageDoc, `${id}`);
2663
2664
  const parentElRect = parentEl?.getBoundingClientRect();
2664
2665
  left = left - utils.calcValueByFontsize(doc, parentElRect?.left || 0);
2665
2666
  top = top - utils.calcValueByFontsize(doc, parentElRect?.top || 0);
@@ -2886,7 +2887,7 @@
2886
2887
  * context:上下文对象
2887
2888
  *
2888
2889
  * interface Content {
2889
- * app: AppCore;
2890
+ * app: TMagicApp;
2890
2891
  * dataSource: HttpDataSource;
2891
2892
  * }
2892
2893
  *
@@ -2903,7 +2904,7 @@
2903
2904
  * context:上下文对象
2904
2905
  *
2905
2906
  * interface Content {
2906
- * app: AppCore;
2907
+ * app: TMagicApp;
2907
2908
  * dataSource: HttpDataSource;
2908
2909
  * }
2909
2910
  *
@@ -2917,7 +2918,7 @@
2917
2918
  };
2918
2919
  const getDisplayField = (dataSources, key) => {
2919
2920
  const displayState = [];
2920
- const matches = key.matchAll(/\$\{([\s\S]+?)\}/g);
2921
+ const matches = key.matchAll(utils.dataSourceTemplateRegExp);
2921
2922
  let index = 0;
2922
2923
  for (const match of matches) {
2923
2924
  if (typeof match.index === "undefined") break;
@@ -2928,7 +2929,7 @@
2928
2929
  let dsText = "";
2929
2930
  let ds;
2930
2931
  let fields;
2931
- match[1].replaceAll(/\[(\d+)\]/g, ".$1").split(".").forEach((item, index2) => {
2932
+ utils.getKeysArray(match[1]).forEach((item, index2) => {
2932
2933
  if (index2 === 0) {
2933
2934
  ds = dataSources.find((ds2) => ds2.id === item);
2934
2935
  dsText += ds?.title || item;
@@ -2989,6 +2990,189 @@
2989
2990
  };
2990
2991
  const removeDataSourceFieldPrefix = (id) => id?.replace(utils.DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, "") || "";
2991
2992
 
2993
+ globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb) {
2994
+ const start = Date.now();
2995
+ return setTimeout(() => {
2996
+ cb({
2997
+ didTimeout: false,
2998
+ timeRemaining() {
2999
+ return Math.max(0, 50 - (Date.now() - start));
3000
+ }
3001
+ });
3002
+ }, 1);
3003
+ };
3004
+ class IdleTask extends events.EventEmitter {
3005
+ taskList = [];
3006
+ taskHandle = null;
3007
+ enqueueTask(taskHandler, taskData) {
3008
+ this.taskList.push({
3009
+ handler: taskHandler,
3010
+ data: taskData
3011
+ });
3012
+ if (!this.taskHandle) {
3013
+ this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
3014
+ }
3015
+ }
3016
+ on(eventName, listener) {
3017
+ return super.on(eventName, listener);
3018
+ }
3019
+ once(eventName, listener) {
3020
+ return super.once(eventName, listener);
3021
+ }
3022
+ emit(eventName, ...args) {
3023
+ return super.emit(eventName, ...args);
3024
+ }
3025
+ runTaskQueue(deadline) {
3026
+ while ((deadline.timeRemaining() > 15 || deadline.didTimeout) && this.taskList.length) {
3027
+ const task = this.taskList.shift();
3028
+ task.handler(task.data);
3029
+ }
3030
+ if (this.taskList.length) {
3031
+ this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
3032
+ } else {
3033
+ this.taskHandle = 0;
3034
+ this.emit("finish");
3035
+ }
3036
+ }
3037
+ }
3038
+
3039
+ class ScrollViewer extends events.EventEmitter {
3040
+ container;
3041
+ target;
3042
+ zoom = 1;
3043
+ scrollLeft = 0;
3044
+ scrollTop = 0;
3045
+ scrollHeight = 0;
3046
+ scrollWidth = 0;
3047
+ width = 0;
3048
+ height = 0;
3049
+ translateXCorrectionValue = 0;
3050
+ translateYCorrectionValue = 0;
3051
+ correctionScrollSize = {
3052
+ width: 0,
3053
+ height: 0
3054
+ };
3055
+ resizeObserver = new ResizeObserver(() => {
3056
+ this.setSize();
3057
+ this.setScrollSize();
3058
+ });
3059
+ constructor(options) {
3060
+ super();
3061
+ this.container = options.container;
3062
+ this.target = options.target;
3063
+ this.zoom = options.zoom;
3064
+ if (this.correctionScrollSize) {
3065
+ this.correctionScrollSize = {
3066
+ ...this.correctionScrollSize,
3067
+ ...options.correctionScrollSize
3068
+ };
3069
+ }
3070
+ this.container.addEventListener("wheel", this.wheelHandler, false);
3071
+ this.setSize();
3072
+ this.setScrollSize();
3073
+ this.resizeObserver.observe(this.container);
3074
+ this.resizeObserver.observe(this.target);
3075
+ }
3076
+ destroy() {
3077
+ this.resizeObserver.disconnect();
3078
+ this.container.removeEventListener("wheel", this.wheelHandler, false);
3079
+ this.removeAllListeners();
3080
+ }
3081
+ setZoom(zoom) {
3082
+ this.zoom = zoom;
3083
+ this.setScrollSize();
3084
+ }
3085
+ scrollTo({ left, top }) {
3086
+ if (typeof left !== "undefined") {
3087
+ this.scrollLeft = left;
3088
+ }
3089
+ if (typeof top !== "undefined") {
3090
+ this.scrollTop = top;
3091
+ }
3092
+ const translateX = -this.scrollLeft + this.translateXCorrectionValue;
3093
+ const translateY = -this.scrollTop + this.translateYCorrectionValue;
3094
+ this.target.style.transform = `translate(${translateX}px, ${translateY}px)`;
3095
+ }
3096
+ wheelHandler = (event) => {
3097
+ const { deltaX, deltaY, currentTarget } = event;
3098
+ if (currentTarget !== this.container) return;
3099
+ let top;
3100
+ if (this.scrollHeight > this.height) {
3101
+ top = this.scrollTop + this.getPos(deltaY, this.scrollTop, this.scrollHeight, this.height);
3102
+ }
3103
+ let left;
3104
+ if (this.scrollWidth > this.width) {
3105
+ left = this.scrollLeft + this.getPos(deltaX, this.scrollLeft, this.scrollWidth, this.width);
3106
+ }
3107
+ this.scrollTo({ left, top });
3108
+ this.emit("scroll", {
3109
+ scrollLeft: this.scrollLeft,
3110
+ scrollTop: this.scrollTop,
3111
+ scrollHeight: this.scrollHeight,
3112
+ scrollWidth: this.scrollWidth
3113
+ });
3114
+ };
3115
+ getPos(delta, scrollPos, scrollSize, size) {
3116
+ let pos = 0;
3117
+ if (delta < 0) {
3118
+ if (scrollPos > 0) {
3119
+ pos = Math.max(delta, -scrollPos);
3120
+ }
3121
+ } else {
3122
+ const leftPos = scrollSize - size - scrollPos;
3123
+ if (leftPos > 0) {
3124
+ pos = Math.min(delta, leftPos);
3125
+ }
3126
+ }
3127
+ return pos;
3128
+ }
3129
+ setScrollSize = () => {
3130
+ const targetRect = this.target.getBoundingClientRect();
3131
+ this.scrollWidth = targetRect.width * this.zoom + this.correctionScrollSize.width;
3132
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
3133
+ this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + this.correctionScrollSize.height;
3134
+ let left;
3135
+ let top;
3136
+ if (this.scrollWidth < this.width) {
3137
+ left = 0;
3138
+ this.translateXCorrectionValue = 0;
3139
+ } else {
3140
+ this.translateXCorrectionValue = (this.scrollWidth - this.width) / 2;
3141
+ }
3142
+ if (this.scrollHeight < this.height) {
3143
+ top = 0;
3144
+ this.translateYCorrectionValue = 0;
3145
+ } else {
3146
+ this.translateYCorrectionValue = (this.scrollHeight - this.height) / 2;
3147
+ }
3148
+ this.scrollTo({
3149
+ left,
3150
+ top
3151
+ });
3152
+ this.emit("scroll", {
3153
+ scrollLeft: this.scrollLeft,
3154
+ scrollTop: this.scrollTop,
3155
+ scrollHeight: this.scrollHeight,
3156
+ scrollWidth: this.scrollWidth
3157
+ });
3158
+ };
3159
+ setSize = () => {
3160
+ const { width, height } = this.container.getBoundingClientRect();
3161
+ this.width = width;
3162
+ this.height = height;
3163
+ };
3164
+ }
3165
+
3166
+ const updateStatus = (nodeStatusMap, id, status) => {
3167
+ const nodeStatus = nodeStatusMap.get(id);
3168
+ if (!nodeStatus) return;
3169
+ utils.getKeys(status).forEach((key) => {
3170
+ if (nodeStatus[key] !== void 0 && status[key] !== void 0) {
3171
+ nodeStatus[key] = Boolean(status[key]);
3172
+ }
3173
+ });
3174
+ };
3175
+
2992
3176
  const _sfc_main$T = /* @__PURE__ */ vue.defineComponent({
2993
3177
  ...{
2994
3178
  name: "MEditorCodeParams"
@@ -3011,7 +3195,7 @@
3011
3195
  type: "fieldset",
3012
3196
  items,
3013
3197
  legend: "参数",
3014
- labelWidth: "70px",
3198
+ labelWidth: "120px",
3015
3199
  name: props.name
3016
3200
  }
3017
3201
  ];
@@ -3709,29 +3893,34 @@
3709
3893
  editorService.set("stageLoading", false);
3710
3894
  });
3711
3895
  stage.on("select", (el) => {
3712
- if (`${editorService.get("node")?.id}` === el.id && editorService.get("nodes").length === 1) return;
3713
- editorService.select(el.id);
3896
+ const id = utils.getIdFromEl()(el);
3897
+ if (`${editorService.get("node")?.id}` === id && editorService.get("nodes").length === 1) return;
3898
+ id && editorService.select(id);
3714
3899
  });
3715
3900
  stage.on("highlight", (el) => {
3716
- editorService.highlight(el.id);
3901
+ const id = utils.getIdFromEl()(el);
3902
+ id && editorService.highlight(id);
3717
3903
  });
3718
3904
  stage.on("multi-select", (els) => {
3719
- editorService.multiSelect(els.map((el) => el.id));
3905
+ const ids = els.map((el) => utils.getIdFromEl()(el)).filter((id) => Boolean(id));
3906
+ editorService.multiSelect(ids);
3720
3907
  });
3721
3908
  stage.on("update", (ev) => {
3722
3909
  if (ev.parentEl) {
3723
3910
  for (const data of ev.data) {
3724
- editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
3911
+ const id = utils.getIdFromEl()(data.el);
3912
+ const pId = utils.getIdFromEl()(ev.parentEl);
3913
+ id && pId && editorService.moveToContainer({ id, style: data.style }, pId);
3725
3914
  }
3726
3915
  return;
3727
3916
  }
3728
- editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
3917
+ editorService.update(ev.data.map((data) => ({ id: utils.getIdFromEl()(data.el) || "", style: data.style })));
3729
3918
  });
3730
3919
  stage.on("sort", (ev) => {
3731
3920
  editorService.sort(ev.src, ev.dist);
3732
3921
  });
3733
3922
  stage.on("remove", (ev) => {
3734
- const nodes = ev.data.map(({ el }) => editorService.getNodeById(el.id));
3923
+ const nodes = ev.data.map(({ el }) => editorService.getNodeById(utils.getIdFromEl()(el) || ""));
3735
3924
  editorService.remove(nodes.filter((node) => Boolean(node)));
3736
3925
  });
3737
3926
  stage.on("select-parent", () => {
@@ -4643,7 +4832,7 @@
4643
4832
  const fieldQuerySearch = (queryString, leftAngleIndex, dotIndex, cb) => {
4644
4833
  let result = [];
4645
4834
  const dsKey = queryString.substring(leftAngleIndex + 1, dotIndex);
4646
- const keys = dsKey.replaceAll(/\[(\d+)\]/g, ".$1").split(".");
4835
+ const keys = utils.getKeysArray(dsKey);
4647
4836
  const dsId = keys.shift();
4648
4837
  const ds = dataSources.value.find((ds2) => ds2.id === dsId);
4649
4838
  if (!ds) {
@@ -6405,10 +6594,11 @@
6405
6594
  globalThis.document.removeEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler);
6406
6595
  };
6407
6596
  const clickHandler = ({ detail }) => {
6408
- if (detail.id) {
6409
- props.model[props.name] = detail.id;
6410
- emit("change", detail.id);
6411
- mForm?.$emit("field-change", props.prop, detail.id);
6597
+ const id = utils.getIdFromEl()(detail);
6598
+ if (id) {
6599
+ props.model[props.name] = id;
6600
+ emit("change", id);
6601
+ mForm?.$emit("field-change", props.prop, id);
6412
6602
  }
6413
6603
  if (cancelHandler) {
6414
6604
  cancelHandler();
@@ -6432,19 +6622,22 @@
6432
6622
  }
6433
6623
  };
6434
6624
  const selectNode = async (id) => {
6435
- await services?.editorService.select(id);
6436
- services?.editorService.get("stage")?.select(id);
6437
- services?.stageOverlayService.get("stage")?.select(id);
6625
+ if (!services) return;
6626
+ await services.editorService.select(id);
6627
+ services.editorService.get("stage")?.select(id);
6628
+ services.stageOverlayService.get("stage")?.select(id);
6438
6629
  };
6439
6630
  const highlight = lodashEs.throttle((id) => {
6440
- services?.editorService.highlight(id);
6441
- services?.editorService.get("stage")?.highlight(id);
6442
- services?.stageOverlayService.get("stage")?.highlight(id);
6631
+ if (!services) return;
6632
+ services.editorService.highlight(id);
6633
+ services.editorService.get("stage")?.highlight(id);
6634
+ services.stageOverlayService.get("stage")?.highlight(id);
6443
6635
  }, 150);
6444
6636
  const unhighlight = () => {
6445
- services?.editorService.set("highlightNode", null);
6446
- services?.editorService.get("stage")?.clearHighlight();
6447
- services?.stageOverlayService.get("stage")?.clearHighlight();
6637
+ if (!services) return;
6638
+ services.editorService.set("highlightNode", null);
6639
+ services.editorService.get("stage")?.clearHighlight();
6640
+ services.stageOverlayService.get("stage")?.clearHighlight();
6448
6641
  };
6449
6642
  return (_ctx, _cache) => {
6450
6643
  return uiSelectMode.value ? (vue.openBlock(), vue.createElementBlock("div", {
@@ -7920,16 +8113,6 @@
7920
8113
  }
7921
8114
  });
7922
8115
 
7923
- const updateStatus = (nodeStatusMap, id, status) => {
7924
- const nodeStatus = nodeStatusMap.get(id);
7925
- if (!nodeStatus) return;
7926
- utils.getKeys(status).forEach((key) => {
7927
- if (nodeStatus[key] !== void 0 && status[key] !== void 0) {
7928
- nodeStatus[key] = Boolean(status[key]);
7929
- }
7930
- });
7931
- };
7932
-
7933
8116
  const _hoisted_1$9 = ["draggable", "data-node-id", "data-parent-id", "data-parents-id", "data-is-container"];
7934
8117
  const _hoisted_2$6 = { class: "tree-node-label" };
7935
8118
  const _hoisted_3$3 = { class: "tree-node-tool" };
@@ -10184,133 +10367,6 @@
10184
10367
  }
10185
10368
  });
10186
10369
 
10187
- class ScrollViewer extends events.EventEmitter {
10188
- container;
10189
- target;
10190
- zoom = 1;
10191
- scrollLeft = 0;
10192
- scrollTop = 0;
10193
- scrollHeight = 0;
10194
- scrollWidth = 0;
10195
- width = 0;
10196
- height = 0;
10197
- translateXCorrectionValue = 0;
10198
- translateYCorrectionValue = 0;
10199
- correctionScrollSize = {
10200
- width: 0,
10201
- height: 0
10202
- };
10203
- resizeObserver = new ResizeObserver(() => {
10204
- this.setSize();
10205
- this.setScrollSize();
10206
- });
10207
- constructor(options) {
10208
- super();
10209
- this.container = options.container;
10210
- this.target = options.target;
10211
- this.zoom = options.zoom;
10212
- if (this.correctionScrollSize) {
10213
- this.correctionScrollSize = {
10214
- ...this.correctionScrollSize,
10215
- ...options.correctionScrollSize
10216
- };
10217
- }
10218
- this.container.addEventListener("wheel", this.wheelHandler, false);
10219
- this.setSize();
10220
- this.setScrollSize();
10221
- this.resizeObserver.observe(this.container);
10222
- this.resizeObserver.observe(this.target);
10223
- }
10224
- destroy() {
10225
- this.resizeObserver.disconnect();
10226
- this.container.removeEventListener("wheel", this.wheelHandler, false);
10227
- this.removeAllListeners();
10228
- }
10229
- setZoom(zoom) {
10230
- this.zoom = zoom;
10231
- this.setScrollSize();
10232
- }
10233
- scrollTo({ left, top }) {
10234
- if (typeof left !== "undefined") {
10235
- this.scrollLeft = left;
10236
- }
10237
- if (typeof top !== "undefined") {
10238
- this.scrollTop = top;
10239
- }
10240
- const translateX = -this.scrollLeft + this.translateXCorrectionValue;
10241
- const translateY = -this.scrollTop + this.translateYCorrectionValue;
10242
- this.target.style.transform = `translate(${translateX}px, ${translateY}px)`;
10243
- }
10244
- wheelHandler = (event) => {
10245
- const { deltaX, deltaY, currentTarget } = event;
10246
- if (currentTarget !== this.container) return;
10247
- let top;
10248
- if (this.scrollHeight > this.height) {
10249
- top = this.scrollTop + this.getPos(deltaY, this.scrollTop, this.scrollHeight, this.height);
10250
- }
10251
- let left;
10252
- if (this.scrollWidth > this.width) {
10253
- left = this.scrollLeft + this.getPos(deltaX, this.scrollLeft, this.scrollWidth, this.width);
10254
- }
10255
- this.scrollTo({ left, top });
10256
- this.emit("scroll", {
10257
- scrollLeft: this.scrollLeft,
10258
- scrollTop: this.scrollTop,
10259
- scrollHeight: this.scrollHeight,
10260
- scrollWidth: this.scrollWidth
10261
- });
10262
- };
10263
- getPos(delta, scrollPos, scrollSize, size) {
10264
- let pos = 0;
10265
- if (delta < 0) {
10266
- if (scrollPos > 0) {
10267
- pos = Math.max(delta, -scrollPos);
10268
- }
10269
- } else {
10270
- const leftPos = scrollSize - size - scrollPos;
10271
- if (leftPos > 0) {
10272
- pos = Math.min(delta, leftPos);
10273
- }
10274
- }
10275
- return pos;
10276
- }
10277
- setScrollSize = () => {
10278
- const targetRect = this.target.getBoundingClientRect();
10279
- this.scrollWidth = targetRect.width * this.zoom + this.correctionScrollSize.width;
10280
- const targetMarginTop = Number(this.target.style.marginTop) || 0;
10281
- this.scrollHeight = (targetRect.height + targetMarginTop) * this.zoom + this.correctionScrollSize.height;
10282
- let left;
10283
- let top;
10284
- if (this.scrollWidth < this.width) {
10285
- left = 0;
10286
- this.translateXCorrectionValue = 0;
10287
- } else {
10288
- this.translateXCorrectionValue = (this.scrollWidth - this.width) / 2;
10289
- }
10290
- if (this.scrollHeight < this.height) {
10291
- top = 0;
10292
- this.translateYCorrectionValue = 0;
10293
- } else {
10294
- this.translateYCorrectionValue = (this.scrollHeight - this.height) / 2;
10295
- }
10296
- this.scrollTo({
10297
- left,
10298
- top
10299
- });
10300
- this.emit("scroll", {
10301
- scrollLeft: this.scrollLeft,
10302
- scrollTop: this.scrollTop,
10303
- scrollHeight: this.scrollHeight,
10304
- scrollWidth: this.scrollWidth
10305
- });
10306
- };
10307
- setSize = () => {
10308
- const { width, height } = this.container.getBoundingClientRect();
10309
- this.width = width;
10310
- this.height = height;
10311
- };
10312
- }
10313
-
10314
10370
  const _sfc_main$9 = /* @__PURE__ */ vue.defineComponent({
10315
10371
  ...{
10316
10372
  name: "MEditorScrollBar"
@@ -10526,7 +10582,7 @@
10526
10582
  vue.nextTick(() => unWatch());
10527
10583
  stage2.on("select", (el, event) => {
10528
10584
  const els = stage2.renderer.getElementsFromPoint(event) || [];
10529
- const ids = els.map((el2) => el2.id).filter((id) => Boolean(id));
10585
+ const ids = els.map((el2) => utils.getIdFromEl()(el2)).filter((id) => Boolean(id));
10530
10586
  buttonVisible.value = ids.length > 3;
10531
10587
  filterTextChangeHandler(ids);
10532
10588
  });
@@ -10955,8 +11011,9 @@
10955
11011
  const doc = stage?.renderer.contentWindow?.document;
10956
11012
  const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
10957
11013
  let parent = page.value;
10958
- if (parentEl) {
10959
- parent = services?.editorService.getNodeById(parentEl.id, false);
11014
+ const parentId = utils.getIdFromEl()(parentEl);
11015
+ if (parentId) {
11016
+ parent = services?.editorService.getNodeById(parentId, false);
10960
11017
  }
10961
11018
  if (parent && stageContainer.value && stage) {
10962
11019
  const layout = await services?.editorService.getLayout(parent);
@@ -11534,52 +11591,6 @@
11534
11591
  }
11535
11592
  const dataSourceService = new DataSource();
11536
11593
 
11537
- globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb) {
11538
- const start = Date.now();
11539
- return setTimeout(() => {
11540
- cb({
11541
- didTimeout: false,
11542
- timeRemaining() {
11543
- return Math.max(0, 50 - (Date.now() - start));
11544
- }
11545
- });
11546
- }, 1);
11547
- };
11548
- class IdleTask extends events.EventEmitter {
11549
- taskList = [];
11550
- taskHandle = null;
11551
- enqueueTask(taskHandler, taskData) {
11552
- this.taskList.push({
11553
- handler: taskHandler,
11554
- data: taskData
11555
- });
11556
- if (!this.taskHandle) {
11557
- this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
11558
- }
11559
- }
11560
- on(eventName, listener) {
11561
- return super.on(eventName, listener);
11562
- }
11563
- once(eventName, listener) {
11564
- return super.once(eventName, listener);
11565
- }
11566
- emit(eventName, ...args) {
11567
- return super.emit(eventName, ...args);
11568
- }
11569
- runTaskQueue(deadline) {
11570
- while ((deadline.timeRemaining() > 15 || deadline.didTimeout) && this.taskList.length) {
11571
- const task = this.taskList.shift();
11572
- task.handler(task.data);
11573
- }
11574
- if (this.taskList.length) {
11575
- this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
11576
- } else {
11577
- this.taskHandle = 0;
11578
- this.emit("finish");
11579
- }
11580
- }
11581
- }
11582
-
11583
11594
  const idleTask = new IdleTask();
11584
11595
  class Dep extends BaseService {
11585
11596
  watcher = new dep.Watcher({ initialTargets: vue.reactive({}) });
@@ -12021,7 +12032,8 @@
12021
12032
  subStage?.renderer.contentWindow?.magic.onPageElUpdate(wrapDiv);
12022
12033
  });
12023
12034
  if (await stageOptions?.canSelect?.(contentEl)) {
12024
- subStage?.select(contentEl.id);
12035
+ const id = utils.getIdFromEl()(contentEl);
12036
+ id && subStage?.select(id);
12025
12037
  }
12026
12038
  }
12027
12039
  updateHandler = () => {
@@ -12072,7 +12084,7 @@
12072
12084
  eventMethodList: () => ({}),
12073
12085
  datasourceValues: () => ({}),
12074
12086
  datasourceConfigs: () => ({}),
12075
- canSelect: (el) => Boolean(el.id),
12087
+ canSelect: (el) => Boolean(utils.getIdFromEl()(el)),
12076
12088
  isContainer: (el) => el.classList.contains("magic-ui-container"),
12077
12089
  codeOptions: () => ({})
12078
12090
  };
@@ -12217,6 +12229,44 @@
12217
12229
  });
12218
12230
  };
12219
12231
  const initServiceEvents = (props, emit, { editorService, codeBlockService, dataSourceService, depService }) => {
12232
+ const rootChangeHandler = async (value, preValue) => {
12233
+ if (!value) return;
12234
+ value.codeBlocks = value.codeBlocks || {};
12235
+ value.dataSources = value.dataSources || [];
12236
+ codeBlockService.setCodeDsl(value.codeBlocks);
12237
+ dataSourceService.set("dataSources", value.dataSources);
12238
+ depService.removeTargets(dep.DepTargetType.CODE_BLOCK);
12239
+ Object.entries(value.codeBlocks).forEach(([id, code]) => {
12240
+ depService.addTarget(dep.createCodeBlockTarget(id, code));
12241
+ });
12242
+ dataSourceService.get("dataSources").forEach((ds) => {
12243
+ initDataSourceDepTarget(ds);
12244
+ });
12245
+ if (Array.isArray(value.items)) {
12246
+ collectIdle(value.items, true);
12247
+ } else {
12248
+ depService.clear();
12249
+ delete value.dataSourceDeps;
12250
+ delete value.dataSourceCondDeps;
12251
+ }
12252
+ const nodeId = editorService.get("node")?.id || props.defaultSelected;
12253
+ let node;
12254
+ if (nodeId) {
12255
+ node = editorService.getNodeById(nodeId);
12256
+ }
12257
+ if (node && node !== value) {
12258
+ await editorService.select(node.id);
12259
+ } else if (value.items?.length) {
12260
+ await editorService.select(value.items[0]);
12261
+ } else if (value.id) {
12262
+ editorService.set("nodes", [value]);
12263
+ editorService.set("parent", null);
12264
+ editorService.set("page", null);
12265
+ }
12266
+ if (vue.toRaw(value) !== vue.toRaw(preValue)) {
12267
+ emit("update:modelValue", value);
12268
+ }
12269
+ };
12220
12270
  const getApp = () => {
12221
12271
  const stage = editorService.get("stage");
12222
12272
  return stage?.renderer.runtime?.getApp?.();
@@ -12296,45 +12346,6 @@
12296
12346
  depService.addTarget(dep.createDataSourceMethodTarget(ds, vue.reactive({})));
12297
12347
  depService.addTarget(dep.createDataSourceCondTarget(ds, vue.reactive({})));
12298
12348
  };
12299
- const rootChangeHandler = async (value, preValue) => {
12300
- if (!value) return;
12301
- value.codeBlocks = value.codeBlocks || {};
12302
- value.dataSources = value.dataSources || [];
12303
- codeBlockService.setCodeDsl(value.codeBlocks);
12304
- dataSourceService.set("dataSources", value.dataSources);
12305
- depService.removeTargets(dep.DepTargetType.CODE_BLOCK);
12306
- Object.entries(value.codeBlocks).forEach(([id, code]) => {
12307
- depService.addTarget(dep.createCodeBlockTarget(id, code));
12308
- });
12309
- dataSourceService.get("dataSources").forEach((ds) => {
12310
- initDataSourceDepTarget(ds);
12311
- });
12312
- if (Array.isArray(value.items)) {
12313
- value.items.forEach((page) => {
12314
- depService.collectIdle([page], { pageId: page.id }, true);
12315
- });
12316
- } else {
12317
- depService.clear();
12318
- delete value.dataSourceDeps;
12319
- }
12320
- const nodeId = editorService.get("node")?.id || props.defaultSelected;
12321
- let node;
12322
- if (nodeId) {
12323
- node = editorService.getNodeById(nodeId);
12324
- }
12325
- if (node && node !== value) {
12326
- await editorService.select(node.id);
12327
- } else if (value.items?.length) {
12328
- await editorService.select(value.items[0]);
12329
- } else if (value.id) {
12330
- editorService.set("nodes", [value]);
12331
- editorService.set("parent", null);
12332
- editorService.set("page", null);
12333
- }
12334
- if (vue.toRaw(value) !== vue.toRaw(preValue)) {
12335
- emit("update:modelValue", value);
12336
- }
12337
- };
12338
12349
  const collectIdle = (nodes, deep) => {
12339
12350
  nodes.forEach((node) => {
12340
12351
  let pageId;
@@ -12357,7 +12368,7 @@
12357
12368
  depService.clear(nodes);
12358
12369
  };
12359
12370
  const historyChangeHandler = (page) => {
12360
- depService.collectIdle([page], { pageId: page.id }, true);
12371
+ collectIdle([page], true);
12361
12372
  };
12362
12373
  editorService.on("history-change", historyChangeHandler);
12363
12374
  editorService.on("root-change", rootChangeHandler);
@@ -12384,9 +12395,7 @@
12384
12395
  const root = editorService.get("root");
12385
12396
  removeDataSourceTarget(config.id);
12386
12397
  initDataSourceDepTarget(config);
12387
- (root?.items || []).forEach((page) => {
12388
- depService.collectIdle([page], { pageId: page.id }, true);
12389
- });
12398
+ collectIdle(root?.items || [], true);
12390
12399
  };
12391
12400
  const removeDataSourceTarget = (id) => {
12392
12401
  depService.removeTarget(id, dep.DepTargetType.DATA_SOURCE);
@@ -12697,6 +12706,7 @@
12697
12706
  exports.FloatingBox = _sfc_main$Q;
12698
12707
  exports.H_GUIDE_LINE_STORAGE_KEY = H_GUIDE_LINE_STORAGE_KEY;
12699
12708
  exports.Icon = _sfc_main$Y;
12709
+ exports.IdleTask = IdleTask;
12700
12710
  exports.KeyBindingCommand = KeyBindingCommand;
12701
12711
  exports.KeyValue = _sfc_main$D;
12702
12712
  exports.Keys = Keys;
@@ -12707,12 +12717,14 @@
12707
12717
  exports.PageFragmentSelect = _sfc_main$C;
12708
12718
  exports.PropsPanel = _sfc_main$p;
12709
12719
  exports.Resizer = _sfc_main$A;
12720
+ exports.ScrollViewer = ScrollViewer;
12710
12721
  exports.SideItemKey = SideItemKey;
12711
12722
  exports.SplitView = _sfc_main$z;
12712
12723
  exports.TMagicCodeEditor = _sfc_main$X;
12713
12724
  exports.TMagicEditor = _sfc_main;
12714
12725
  exports.ToolButton = _sfc_main$y;
12715
12726
  exports.UI_SELECT_MODE_EVENT_NAME = UI_SELECT_MODE_EVENT_NAME;
12727
+ exports.UndoRedo = UndoRedo;
12716
12728
  exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
12717
12729
  exports.advancedTabConfig = advancedTabConfig;
12718
12730
  exports.arrayOptions = arrayOptions;
@@ -12766,6 +12778,7 @@
12766
12778
  exports.styleTabConfig = styleTabConfig;
12767
12779
  exports.traverseNode = traverseNode;
12768
12780
  exports.uiService = uiService;
12781
+ exports.updateStatus = updateStatus;
12769
12782
  exports.useCodeBlockEdit = useCodeBlockEdit;
12770
12783
  exports.useDataSourceMethod = useDataSourceMethod;
12771
12784
  exports.useEditorContentHeight = useEditorContentHeight;