@tmagic/editor 1.5.0-beta.14 → 1.5.0-beta.16

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 (42) hide show
  1. package/dist/style.css +61 -6
  2. package/dist/tmagic-editor.js +507 -242
  3. package/dist/tmagic-editor.umd.cjs +507 -243
  4. package/package.json +12 -10
  5. package/src/components/CodeBlockEditor.vue +11 -5
  6. package/src/components/CodeParams.vue +3 -3
  7. package/src/fields/Code.vue +1 -2
  8. package/src/fields/CodeSelect.vue +13 -11
  9. package/src/fields/CodeSelectCol.vue +32 -5
  10. package/src/fields/CondOpSelect.vue +5 -2
  11. package/src/fields/DataSourceFields.vue +31 -12
  12. package/src/fields/DataSourceMethods.vue +72 -14
  13. package/src/fields/DisplayConds.vue +8 -3
  14. package/src/fields/EventSelect.vue +25 -8
  15. package/src/fields/KeyValue.vue +15 -10
  16. package/src/hooks/index.ts +0 -1
  17. package/src/hooks/use-code-block-edit.ts +1 -1
  18. package/src/hooks/use-data-source-edit.ts +3 -2
  19. package/src/initService.ts +105 -25
  20. package/src/layouts/Framework.vue +0 -3
  21. package/src/layouts/PropsPanel.vue +3 -3
  22. package/src/layouts/page-bar/PageBar.vue +46 -3
  23. package/src/layouts/page-bar/PageBarScrollContainer.vue +49 -24
  24. package/src/layouts/page-bar/PageList.vue +4 -2
  25. package/src/layouts/sidebar/Sidebar.vue +3 -0
  26. package/src/layouts/sidebar/code-block/CodeBlockList.vue +6 -1
  27. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
  28. package/src/layouts/sidebar/data-source/DataSourceList.vue +6 -1
  29. package/src/layouts/workspace/Workspace.vue +5 -2
  30. package/src/layouts/workspace/viewer/Stage.vue +12 -5
  31. package/src/services/dataSource.ts +12 -5
  32. package/src/services/dep.ts +49 -11
  33. package/src/services/editor.ts +26 -11
  34. package/src/theme/page-bar.scss +24 -9
  35. package/src/theme/search-input.scss +1 -0
  36. package/src/utils/data-source/formConfigs/http.ts +2 -0
  37. package/src/utils/data-source/index.ts +2 -2
  38. package/src/utils/editor.ts +78 -2
  39. package/src/utils/idle-task.ts +34 -3
  40. package/src/utils/props.ts +3 -3
  41. package/types/index.d.ts +805 -1170
  42. package/src/hooks/use-data-source-method.ts +0 -100
@@ -7,15 +7,15 @@ export { default as formPlugin } from '@tmagic/form';
7
7
  import tablePlugin__default, { MagicTable } from '@tmagic/table';
8
8
  export * from '@tmagic/table';
9
9
  export { default as tablePlugin } from '@tmagic/table';
10
- import { defineComponent, openBlock, createBlock, unref, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, ref, watch, onMounted, onBeforeUnmount, Teleport, normalizeStyle, computed, reactive, resolveComponent, inject, createCommentVNode, Fragment, renderList, mergeProps, mergeModels, useModel, nextTick, provide, renderSlot, toDisplayString, createTextVNode, isRef, createStaticVNode, watchEffect, withModifiers, toHandlers, resolveDirective, withDirectives, createSlots, markRaw, getCurrentInstance, vShow, Transition, mergeDefaults } from 'vue';
10
+ import { defineComponent, openBlock, createBlock, unref, withCtx, createVNode, createElementVNode, createElementBlock, normalizeClass, resolveDynamicComponent, toRaw, ref, watch, onMounted, onBeforeUnmount, Teleport, normalizeStyle, computed, reactive, resolveComponent, inject, createCommentVNode, Fragment, renderList, mergeProps, mergeModels, useModel, nextTick, provide, renderSlot, toDisplayString, createTextVNode, isRef, createStaticVNode, watchEffect, withModifiers, toHandlers, createSlots, markRaw, getCurrentInstance, withDirectives, vShow, Transition, resolveDirective, mergeDefaults } from 'vue';
11
11
  import { Edit, FullScreen, View, Close, Coin, Delete, Plus, ArrowDown, ArrowLeftBold, ArrowRightBold, Files, Search, CaretBottom, DocumentCopy, Grid, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Document, ArrowRight, CopyDocument, Hide, Goods, List, EditPen, CloseBold, Top, Bottom } from '@element-plus/icons-vue';
12
- import { throttle, isEmpty, cloneDeep, mergeWith, isObject, uniq, get, map, has, pick, keys } from 'lodash-es';
12
+ import { throttle, isEmpty, isObject, cloneDeep, mergeWith, uniq, get, map, has, pick, keys } from 'lodash-es';
13
13
  import serialize from 'serialize-javascript';
14
14
  import { emmetHTML, emmetCSS } from 'emmet-monaco-es';
15
15
  import * as monaco from 'monaco-editor';
16
16
  import { HookCodeType, HookType, NODE_CONDS_KEY, Target, Watcher, NodeType, ActionType, DepTargetType, DEFAULT_EVENTS, DEFAULT_METHODS, createCodeBlockTarget, createDataSourceTarget, createDataSourceMethodTarget, createDataSourceCondTarget } from '@tmagic/core';
17
17
  export { DepTargetType } from '@tmagic/core';
18
- import { isPage, isPageFragment, isPop, getNodePath, isNumber, getElById, calcValueByFontsize, toLine, guid, getValueByKeyPath, setValueByKeyPath, getNodeInfo, dataSourceTemplateRegExp, getKeysArray, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getKeys, convertToNumber, getIdFromEl, traverseNode, getDefaultValueFromFields, DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, removeClassName, addClassName, removeClassNameByClassName, getNodes } from '@tmagic/utils';
18
+ import { isPage, isPageFragment, isPop, getNodePath, isNumber, getElById, calcValueByFontsize, isValueIncludeDataSource, toLine, guid, getValueByKeyPath, setValueByKeyPath, getNodeInfo, dataSourceTemplateRegExp, getKeysArray, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getKeys, convertToNumber, getIdFromEl, traverseNode, getDefaultValueFromFields, DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, removeClassName, addClassName, removeClassNameByClassName, getNodes } from '@tmagic/utils';
19
19
  export * from '@tmagic/utils';
20
20
  import VanillaMoveable from 'moveable';
21
21
  import StageCore__default, { isFixed, GuidesType, getOffset, RenderType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
@@ -23,6 +23,7 @@ export * from '@tmagic/stage';
23
23
  export { default as StageCore } from '@tmagic/stage';
24
24
  import { EventEmitter } from 'events';
25
25
  import Gesto from 'gesto';
26
+ import { detailedDiff } from 'deep-object-diff';
26
27
  import Sortable from 'sortablejs';
27
28
  import KeyController from 'keycon';
28
29
 
@@ -290,9 +291,7 @@ const _sfc_main$W = /* @__PURE__ */ defineComponent({
290
291
  emits: ["change"],
291
292
  setup(__props, { emit: __emit }) {
292
293
  const emit = __emit;
293
- const props = __props;
294
294
  const save = (v) => {
295
- props.model[props.name] = v;
296
295
  emit("change", v);
297
296
  };
298
297
  return (_ctx, _cache) => {
@@ -442,11 +441,13 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
442
441
  { value: HookCodeType.DATA_SOURCE_METHOD, text: "数据源方法" }
443
442
  ],
444
443
  defaultValue: "code",
445
- onChange: (mForm, v, { model }) => {
444
+ onChange: (mForm, v, { model, prop, changeRecords }) => {
446
445
  if (v === HookCodeType.DATA_SOURCE_METHOD) {
447
446
  model.codeId = [];
447
+ changeRecords.push({ propPath: prop.replace("codeType", "codeId"), value: [] });
448
448
  } else {
449
449
  model.codeId = "";
450
+ changeRecords.push({ propPath: prop.replace("codeType", "codeId"), value: "" });
450
451
  }
451
452
  return v;
452
453
  }
@@ -485,9 +486,7 @@ const _sfc_main$U = /* @__PURE__ */ defineComponent({
485
486
  immediate: true
486
487
  }
487
488
  );
488
- const changeHandler = async () => {
489
- emit("change", props.model[props.name]);
490
- };
489
+ const changeHandler = (v, eventData) => emit("change", v, eventData);
491
490
  return (_ctx, _cache) => {
492
491
  return openBlock(), createElementBlock("div", {
493
492
  class: normalizeClass(["m-fields-code-select", _ctx.config.className])
@@ -569,7 +568,7 @@ const styleTabConfig = {
569
568
  fieldConfig: {
570
569
  type: "text"
571
570
  },
572
- disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
571
+ disabled: (_vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
573
572
  },
574
573
  {
575
574
  type: "data-source-field-select",
@@ -590,7 +589,7 @@ const styleTabConfig = {
590
589
  fieldConfig: {
591
590
  type: "text"
592
591
  },
593
- disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
592
+ disabled: (_vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
594
593
  }
595
594
  ]
596
595
  },
@@ -839,7 +838,7 @@ const advancedTabConfig = {
839
838
  };
840
839
  const displayTabConfig = {
841
840
  title: "显示条件",
842
- display: (vm, { model }) => model.type !== "page",
841
+ display: (_vm, { model }) => model.type !== "page",
843
842
  items: [
844
843
  {
845
844
  type: "display-conds",
@@ -1163,6 +1162,55 @@ const moveItemsInContainer = (sourceIndices, parent, targetIndex) => {
1163
1162
  }
1164
1163
  }
1165
1164
  };
1165
+ const isIncludeDataSourceByDiffAddResult = (diffResult) => {
1166
+ for (const value of Object.values(diffResult)) {
1167
+ const result = isValueIncludeDataSource(value);
1168
+ if (result) {
1169
+ return true;
1170
+ }
1171
+ if (isObject(value)) {
1172
+ return isIncludeDataSourceByDiffAddResult(value);
1173
+ }
1174
+ }
1175
+ return false;
1176
+ };
1177
+ const isIncludeDataSourceByDiffUpdatedResult = (diffResult, oldNode) => {
1178
+ for (const [key, value] of Object.entries(diffResult)) {
1179
+ if (isValueIncludeDataSource(value)) {
1180
+ return true;
1181
+ }
1182
+ if (isValueIncludeDataSource(oldNode[key])) {
1183
+ return true;
1184
+ }
1185
+ if (isObject(value)) {
1186
+ return isIncludeDataSourceByDiffUpdatedResult(value, oldNode[key]);
1187
+ }
1188
+ }
1189
+ return false;
1190
+ };
1191
+ const isIncludeDataSource = (node, oldNode) => {
1192
+ const diffResult = detailedDiff(oldNode, node);
1193
+ let isIncludeDataSource2 = false;
1194
+ if (diffResult.updated) {
1195
+ if (diffResult.updated[NODE_CONDS_KEY]) {
1196
+ return true;
1197
+ }
1198
+ isIncludeDataSource2 = isIncludeDataSourceByDiffUpdatedResult(diffResult.updated, oldNode);
1199
+ if (isIncludeDataSource2) return true;
1200
+ }
1201
+ if (diffResult.added) {
1202
+ isIncludeDataSource2 = isIncludeDataSourceByDiffAddResult(diffResult.added);
1203
+ if (isIncludeDataSource2) return true;
1204
+ }
1205
+ if (diffResult.deleted) {
1206
+ if (diffResult.deleted[NODE_CONDS_KEY]) {
1207
+ return true;
1208
+ }
1209
+ isIncludeDataSource2 = isIncludeDataSourceByDiffAddResult(diffResult.deleted);
1210
+ if (isIncludeDataSource2) return true;
1211
+ }
1212
+ return isIncludeDataSource2;
1213
+ };
1166
1214
 
1167
1215
  const compose = (middleware, isAsync) => {
1168
1216
  if (!Array.isArray(middleware)) throw new TypeError("Middleware 必须是一个数组!");
@@ -2115,13 +2163,13 @@ class Editor extends BaseService {
2115
2163
  }
2116
2164
  this.emit("remove", nodes);
2117
2165
  }
2118
- async doUpdate(config) {
2166
+ async doUpdate(config, { changeRecords = [] } = {}) {
2119
2167
  const root = this.get("root");
2120
2168
  if (!root) throw new Error("root为空");
2121
2169
  if (!config?.id) throw new Error("没有配置或者配置缺少id值");
2122
2170
  const info = this.getNodeInfo(config.id, false);
2123
2171
  if (!info.node) throw new Error(`获取不到id为${config.id}的节点`);
2124
- const node = cloneDeep(toRaw(info.node));
2172
+ const node = toRaw(info.node);
2125
2173
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, root);
2126
2174
  newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue, key) => {
2127
2175
  if (typeof srcValue === "undefined" && Object.hasOwn(newConfig, key)) {
@@ -2137,7 +2185,11 @@ class Editor extends BaseService {
2137
2185
  if (!newConfig.type) throw new Error("配置缺少type值");
2138
2186
  if (newConfig.type === NodeType.ROOT) {
2139
2187
  this.set("root", newConfig);
2140
- return newConfig;
2188
+ return {
2189
+ oldNode: node,
2190
+ newNode: newConfig,
2191
+ changeRecords
2192
+ };
2141
2193
  }
2142
2194
  const { parent } = info;
2143
2195
  if (!parent) throw new Error("获取不到父级节点");
@@ -2158,21 +2210,25 @@ class Editor extends BaseService {
2158
2210
  this.set("page", newConfig);
2159
2211
  }
2160
2212
  this.addModifiedNodeId(newConfig.id);
2161
- return newConfig;
2213
+ return {
2214
+ oldNode: node,
2215
+ newNode: newConfig,
2216
+ changeRecords
2217
+ };
2162
2218
  }
2163
2219
  /**
2164
2220
  * 更新节点
2165
2221
  * @param config 新的节点配置,配置中需要有id信息
2166
2222
  * @returns 更新后的节点配置
2167
2223
  */
2168
- async update(config) {
2224
+ async update(config, data = {}) {
2169
2225
  const nodes = Array.isArray(config) ? config : [config];
2170
- const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
2171
- if (newNodes[0]?.type !== NodeType.ROOT) {
2226
+ const updateData = await Promise.all(nodes.map((node) => this.doUpdate(node, data)));
2227
+ if (updateData[0].oldNode?.type !== NodeType.ROOT) {
2172
2228
  this.pushHistoryState();
2173
2229
  }
2174
- this.emit("update", newNodes);
2175
- return Array.isArray(config) ? newNodes : newNodes[0];
2230
+ this.emit("update", updateData);
2231
+ return Array.isArray(config) ? updateData.map((item) => item.newNode) : updateData[0].newNode;
2176
2232
  }
2177
2233
  /**
2178
2234
  * 将id为id1的组件移动到id为id2的组件位置上,例如:[1,2,3,4] -> sort(1,3) -> [2,1,3,4]
@@ -2366,7 +2422,7 @@ class Editor extends BaseService {
2366
2422
  parent.items?.splice(index, 1);
2367
2423
  await stage.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
2368
2424
  const layout = await this.getLayout(target);
2369
- const newConfig = mergeWith(cloneDeep(node), config, (objValue, srcValue) => {
2425
+ const newConfig = mergeWith(cloneDeep(node), config, (_objValue, srcValue) => {
2370
2426
  if (Array.isArray(srcValue)) {
2371
2427
  return srcValue;
2372
2428
  }
@@ -2732,6 +2788,7 @@ const HttpFormConfig = [
2732
2788
  name: "params",
2733
2789
  type: "key-value",
2734
2790
  defaultValue: {},
2791
+ advanced: true,
2735
2792
  text: "参数"
2736
2793
  },
2737
2794
  {
@@ -2745,6 +2802,7 @@ const HttpFormConfig = [
2745
2802
  name: "headers",
2746
2803
  type: "key-value",
2747
2804
  defaultValue: {},
2805
+ advanced: true,
2748
2806
  text: "请求头"
2749
2807
  }
2750
2808
  ]
@@ -2799,7 +2857,7 @@ const fillConfig = (config) => [
2799
2857
  },
2800
2858
  {
2801
2859
  title: "请求参数裁剪",
2802
- display: (formState, { model }) => model.type === "http",
2860
+ display: (_formState, { model }) => model.type === "http",
2803
2861
  items: [
2804
2862
  {
2805
2863
  name: "beforeRequest",
@@ -2811,7 +2869,7 @@ const fillConfig = (config) => [
2811
2869
  },
2812
2870
  {
2813
2871
  title: "响应数据裁剪",
2814
- display: (formState, { model }) => model.type === "http",
2872
+ display: (_formState, { model }) => model.type === "http",
2815
2873
  items: [
2816
2874
  {
2817
2875
  name: "afterResponse",
@@ -2978,6 +3036,10 @@ globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb)
2978
3036
  class IdleTask extends EventEmitter {
2979
3037
  taskList = [];
2980
3038
  taskHandle = null;
3039
+ constructor() {
3040
+ super();
3041
+ this.setMaxListeners(1e3);
3042
+ }
2981
3043
  enqueueTask(taskHandler, taskData) {
2982
3044
  this.taskList.push({
2983
3045
  handler: taskHandler,
@@ -2987,6 +3049,9 @@ class IdleTask extends EventEmitter {
2987
3049
  this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
2988
3050
  }
2989
3051
  }
3052
+ clearTasks() {
3053
+ this.taskList = [];
3054
+ }
2990
3055
  on(eventName, listener) {
2991
3056
  return super.on(eventName, listener);
2992
3057
  }
@@ -2997,9 +3062,27 @@ class IdleTask extends EventEmitter {
2997
3062
  return super.emit(eventName, ...args);
2998
3063
  }
2999
3064
  runTaskQueue(deadline) {
3000
- while ((deadline.timeRemaining() > 10 || deadline.didTimeout) && this.taskList.length) {
3001
- const task = this.taskList.shift();
3002
- task.handler(task.data);
3065
+ while (deadline.timeRemaining() > 0 && this.taskList.length) {
3066
+ const timeRemaining = deadline.timeRemaining();
3067
+ let times = 0;
3068
+ if (timeRemaining <= 5) {
3069
+ times = 10;
3070
+ } else if (timeRemaining <= 10) {
3071
+ times = 100;
3072
+ } else if (timeRemaining <= 15) {
3073
+ times = 300;
3074
+ } else {
3075
+ times = 600;
3076
+ }
3077
+ for (let i = 0; i < times; i++) {
3078
+ const task = this.taskList.shift();
3079
+ if (task) {
3080
+ task.handler(task.data);
3081
+ }
3082
+ if (this.taskList.length === 0) {
3083
+ break;
3084
+ }
3085
+ }
3003
3086
  }
3004
3087
  if (this.taskList.length) {
3005
3088
  this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 300 });
@@ -3184,10 +3267,10 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
3184
3267
  }))
3185
3268
  )
3186
3269
  );
3187
- const onParamsChangeHandler = async () => {
3270
+ const onParamsChangeHandler = async (v, eventData) => {
3188
3271
  try {
3189
3272
  const value = await form.value?.submitForm(true);
3190
- emit("change", value);
3273
+ emit("change", value, eventData);
3191
3274
  } catch (e) {
3192
3275
  error(e);
3193
3276
  }
@@ -3280,9 +3363,26 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
3280
3363
  return codeId;
3281
3364
  }
3282
3365
  };
3283
- const onParamsChangeHandler = (value) => {
3366
+ const onCodeIdChangeHandler = (value) => {
3284
3367
  props.model.params = value.params;
3285
- emit("change", props.model);
3368
+ emit("change", props.model, {
3369
+ changeRecords: [
3370
+ {
3371
+ propPath: props.prop,
3372
+ value: value[props.name]
3373
+ }
3374
+ ]
3375
+ });
3376
+ };
3377
+ const onParamsChangeHandler = (value, eventData) => {
3378
+ props.model.params = value.params;
3379
+ emit("change", props.model, {
3380
+ ...eventData,
3381
+ changeRecords: (eventData.changeRecords || []).map((item) => ({
3382
+ prop: `${props.prop.replace(props.name, "")}${item.propPath}`,
3383
+ value: item.value
3384
+ }))
3385
+ });
3286
3386
  };
3287
3387
  const editCode = (id) => {
3288
3388
  eventBus?.emit("edit-code", id);
@@ -3295,7 +3395,7 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
3295
3395
  config: selectConfig,
3296
3396
  model: _ctx.model,
3297
3397
  size: _ctx.size,
3298
- onChange: onParamsChangeHandler
3398
+ onChange: onCodeIdChangeHandler
3299
3399
  }, null, 8, ["model", "size"]),
3300
3400
  _ctx.model[_ctx.name] && hasCodeBlockSidePanel.value ? (openBlock(), createBlock(unref(TMagicButton), {
3301
3401
  key: 0,
@@ -3594,7 +3694,7 @@ const useCodeBlockEdit = (codeBlockService) => {
3594
3694
  }
3595
3695
  codeConfig.value = {
3596
3696
  name: "",
3597
- content: `({app, params}) => {
3697
+ content: `({app, params, flowState}) => {
3598
3698
  // place your code here
3599
3699
  }`,
3600
3700
  params: []
@@ -3640,78 +3740,6 @@ const useCodeBlockEdit = (codeBlockService) => {
3640
3740
  };
3641
3741
  };
3642
3742
 
3643
- const useDataSourceMethod = () => {
3644
- const codeConfig = ref();
3645
- const codeBlockEditor = ref();
3646
- const dataSource = ref();
3647
- const dataSourceMethod = ref("");
3648
- return {
3649
- codeConfig,
3650
- codeBlockEditor,
3651
- createCode: async (model) => {
3652
- codeConfig.value = {
3653
- name: "",
3654
- content: `({ params, dataSource, app }) => {
3655
- // place your code here
3656
- }`,
3657
- params: []
3658
- };
3659
- await nextTick();
3660
- dataSource.value = model;
3661
- dataSourceMethod.value = "";
3662
- codeBlockEditor.value?.show();
3663
- },
3664
- editCode: async (model, methodName) => {
3665
- const method = model.methods?.find((method2) => method2.name === methodName);
3666
- if (!method) {
3667
- tMagicMessage.error("获取数据源方法失败");
3668
- return;
3669
- }
3670
- let codeContent = method.content || `({ params, dataSource, app }) => {
3671
- // place your code here
3672
- }`;
3673
- if (typeof codeContent !== "string") {
3674
- codeContent = codeContent.toString();
3675
- }
3676
- codeConfig.value = {
3677
- ...cloneDeep(method),
3678
- content: codeContent
3679
- };
3680
- await nextTick();
3681
- dataSource.value = model;
3682
- dataSourceMethod.value = methodName;
3683
- codeBlockEditor.value?.show();
3684
- },
3685
- deleteCode: async (model, methodName) => {
3686
- if (!model.methods) return;
3687
- const index = model.methods.findIndex((method) => method.name === methodName);
3688
- if (index === -1) {
3689
- return;
3690
- }
3691
- model.methods.splice(index, 1);
3692
- },
3693
- submitCode: (values) => {
3694
- if (!dataSource.value) return;
3695
- if (!dataSource.value.methods) {
3696
- dataSource.value.methods = [];
3697
- }
3698
- if (values.content) {
3699
- const parseDSL = getEditorConfig("parseDSL");
3700
- if (typeof values.content === "string") {
3701
- values.content = parseDSL(values.content);
3702
- }
3703
- }
3704
- if (dataSourceMethod.value) {
3705
- const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
3706
- dataSource.value.methods.splice(index, 1, values);
3707
- } else {
3708
- dataSource.value.methods.push(values);
3709
- }
3710
- codeBlockEditor.value?.hide();
3711
- }
3712
- };
3713
- };
3714
-
3715
3743
  const state = reactive({
3716
3744
  uiSelectMode: false,
3717
3745
  showSrc: false,
@@ -4198,14 +4226,28 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4198
4226
  calcBoxPosition();
4199
4227
  addDialogVisible.value = true;
4200
4228
  };
4201
- const fieldChange = ({ index, ...value }) => {
4229
+ const fieldChange = ({ index, ...value }, data) => {
4230
+ addDialogVisible.value = false;
4202
4231
  if (index > -1) {
4203
- props.model[props.name][index] = value;
4232
+ emit("change", value, {
4233
+ modifyKey: index,
4234
+ changeRecords: (data.changeRecords || []).map((item) => ({
4235
+ propPath: `${props.prop}.${index}.${item.propPath}`,
4236
+ value: item.value
4237
+ }))
4238
+ });
4204
4239
  } else {
4205
- props.model[props.name].push(value);
4240
+ const modifyKey = props.model[props.name].length;
4241
+ emit("change", value, {
4242
+ modifyKey,
4243
+ changeRecords: [
4244
+ {
4245
+ propPath: `${props.prop}.${modifyKey}`,
4246
+ value
4247
+ }
4248
+ ]
4249
+ });
4206
4250
  }
4207
- addDialogVisible.value = false;
4208
- emit("change", props.model[props.name]);
4209
4251
  };
4210
4252
  const fieldColumns = [
4211
4253
  {
@@ -4399,9 +4441,8 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4399
4441
  const addFromJsonFromChange = ({ data }) => {
4400
4442
  try {
4401
4443
  const value = JSON.parse(data);
4402
- props.model[props.name] = getFieldsConfig(value, props.model[props.name]);
4403
4444
  addFromJsonDialogVisible.value = false;
4404
- emit("change", props.model[props.name]);
4445
+ emit("change", getFieldsConfig(value, props.model[props.name]));
4405
4446
  } catch (e) {
4406
4447
  tMagicMessage.error(e.message);
4407
4448
  }
@@ -5185,9 +5226,9 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5185
5226
  }
5186
5227
  }
5187
5228
  ]);
5188
- const submitForm = (values) => {
5229
+ const submitForm = (values, data) => {
5189
5230
  changedValue.value = void 0;
5190
- emit("submit", values);
5231
+ emit("submit", values, data);
5191
5232
  };
5192
5233
  const errorHandler = (error) => {
5193
5234
  tMagicMessage.error(error.message);
@@ -5208,7 +5249,7 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5208
5249
  type: "warning",
5209
5250
  distinguishCancelAndClose: true
5210
5251
  }).then(() => {
5211
- changedValue.value && submitForm(changedValue.value);
5252
+ changedValue.value && submitForm(changedValue.value, { changeRecords: formBox.value?.form?.changeRecords });
5212
5253
  done();
5213
5254
  }).catch((action) => {
5214
5255
  done(action === "cancel");
@@ -5372,7 +5413,9 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5372
5413
  setup(__props, { emit: __emit }) {
5373
5414
  const props = __props;
5374
5415
  const emit = __emit;
5375
- const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
5416
+ const codeConfig = ref();
5417
+ const codeBlockEditor = ref();
5418
+ let editIndex = -1;
5376
5419
  const methodColumns = [
5377
5420
  {
5378
5421
  label: "名称",
@@ -5397,16 +5440,29 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5397
5440
  actions: [
5398
5441
  {
5399
5442
  text: "编辑",
5400
- handler: (row) => {
5401
- editCode(props.model, row.name);
5402
- emit("change", props.model[props.name]);
5443
+ handler: (method, index) => {
5444
+ let codeContent = method.content || `({ params, dataSource, app }) => {
5445
+ // place your code here
5446
+ }`;
5447
+ if (typeof codeContent !== "string") {
5448
+ codeContent = codeContent.toString();
5449
+ }
5450
+ codeConfig.value = {
5451
+ ...cloneDeep(method),
5452
+ content: codeContent
5453
+ };
5454
+ editIndex = index;
5455
+ nextTick(() => {
5456
+ codeBlockEditor.value?.show();
5457
+ });
5403
5458
  }
5404
5459
  },
5405
5460
  {
5406
5461
  text: "删除",
5407
5462
  buttonType: "danger",
5408
- handler: (row) => {
5409
- deleteCode(props.model, row.name);
5463
+ handler: async (row, index) => {
5464
+ await tMagicMessageBox.confirm(`确定删除${row.name}?`, "提示");
5465
+ props.model[props.name].splice(index, 1);
5410
5466
  emit("change", props.model[props.name]);
5411
5467
  }
5412
5468
  }
@@ -5414,12 +5470,48 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5414
5470
  }
5415
5471
  ];
5416
5472
  const createCodeHandler = () => {
5417
- createCode(props.model);
5418
- emit("change", props.model[props.name]);
5473
+ codeConfig.value = {
5474
+ name: "",
5475
+ content: `({ params, dataSource, app, flowState }) => {
5476
+ // place your code here
5477
+ }`,
5478
+ params: []
5479
+ };
5480
+ editIndex = -1;
5481
+ nextTick(() => {
5482
+ codeBlockEditor.value?.show();
5483
+ });
5419
5484
  };
5420
- const submitCodeHandler = (values) => {
5421
- submitCode(values);
5422
- emit("change", props.model[props.name]);
5485
+ const submitCodeHandler = (value, data) => {
5486
+ if (value.content) {
5487
+ const parseDSL = getEditorConfig("parseDSL");
5488
+ if (typeof value.content === "string") {
5489
+ value.content = parseDSL(value.content);
5490
+ }
5491
+ }
5492
+ if (editIndex > -1) {
5493
+ emit("change", value, {
5494
+ modifyKey: editIndex,
5495
+ changeRecords: (data.changeRecords || []).map((item) => ({
5496
+ propPath: `${props.prop}.${editIndex}.${item.propPath}`,
5497
+ value: item.value
5498
+ }))
5499
+ });
5500
+ } else {
5501
+ const modifyKey = props.model[props.name].length;
5502
+ emit("change", value, {
5503
+ modifyKey,
5504
+ changeRecords: [
5505
+ {
5506
+ propPath: `${props.prop}.${modifyKey}`,
5507
+ value
5508
+ }
5509
+ ]
5510
+ });
5511
+ }
5512
+ editIndex = -1;
5513
+ codeConfig.value = void 0;
5514
+ codeBlockEditor.value?.hide();
5423
5515
  };
5424
5516
  return (_ctx, _cache) => {
5425
5517
  return openBlock(), createElementBlock("div", _hoisted_1$p, [
@@ -5441,12 +5533,12 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5441
5533
  _: 1
5442
5534
  }, 8, ["disabled"])
5443
5535
  ]),
5444
- unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$L, {
5536
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$L, {
5445
5537
  key: 0,
5446
5538
  ref_key: "codeBlockEditor",
5447
5539
  ref: codeBlockEditor,
5448
5540
  disabled: _ctx.disabled,
5449
- content: unref(codeConfig),
5541
+ content: codeConfig.value,
5450
5542
  "is-data-source": true,
5451
5543
  "data-source-type": _ctx.model.type,
5452
5544
  onSubmit: submitCodeHandler
@@ -6044,8 +6136,11 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
6044
6136
  }
6045
6137
  ]
6046
6138
  }));
6047
- const changeHandler = (v) => {
6048
- emit("change", v);
6139
+ const changeHandler = (v, eventData) => {
6140
+ if (!Array.isArray(props.model[props.name])) {
6141
+ props.model[props.name] = [];
6142
+ }
6143
+ emit("change", v, eventData);
6049
6144
  };
6050
6145
  return (_ctx, _cache) => {
6051
6146
  return openBlock(), createBlock(unref(MGroupList), {
@@ -6329,17 +6424,19 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6329
6424
  if (!props.model[props.name]) {
6330
6425
  props.model[props.name] = [];
6331
6426
  }
6332
- props.model[props.name].push(defaultEvent);
6333
- onChangeHandler();
6427
+ emit("change", defaultEvent, {
6428
+ modifyKey: props.model[props.name].length
6429
+ });
6334
6430
  };
6335
6431
  const removeEvent = (index) => {
6336
6432
  if (!props.name) return;
6337
6433
  props.model[props.name].splice(index, 1);
6338
- onChangeHandler();
6434
+ emit("change", props.model[props.name]);
6339
6435
  };
6340
- const onChangeHandler = () => {
6341
- emit("change", props.model);
6436
+ const eventNameChangeHandler = (v, eventData) => {
6437
+ emit("change", props.model[props.name], eventData);
6342
6438
  };
6439
+ const onChangeHandler = (v, eventData) => emit("change", props.model[props.name], eventData);
6343
6440
  return (_ctx, _cache) => {
6344
6441
  const _component_m_form_table = resolveComponent("m-form-table");
6345
6442
  return openBlock(), createElementBlock("div", _hoisted_1$l, [
@@ -6370,6 +6467,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6370
6467
  key: index,
6371
6468
  disabled: _ctx.disabled,
6372
6469
  size: _ctx.size,
6470
+ prop: `${_ctx.prop}.${index}`,
6373
6471
  config: actionsConfig.value,
6374
6472
  model: cardItem,
6375
6473
  "label-width": _ctx.config.labelWidth || "100px",
@@ -6382,8 +6480,9 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6382
6480
  model: cardItem,
6383
6481
  disabled: _ctx.disabled,
6384
6482
  size: _ctx.size,
6385
- onChange: onChangeHandler
6386
- }, null, 8, ["config", "model", "disabled", "size"]),
6483
+ prop: `${_ctx.prop}.${index}`,
6484
+ onChange: eventNameChangeHandler
6485
+ }, null, 8, ["config", "model", "disabled", "size", "prop"]),
6387
6486
  createVNode(unref(TMagicButton), {
6388
6487
  style: { "color": "#f56c6c" },
6389
6488
  link: "",
@@ -6394,7 +6493,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6394
6493
  }, null, 8, ["icon", "disabled", "size", "onClick"])
6395
6494
  ]),
6396
6495
  _: 2
6397
- }, 1032, ["disabled", "size", "config", "model", "label-width"]);
6496
+ }, 1032, ["disabled", "size", "prop", "config", "model", "label-width"]);
6398
6497
  }), 128))
6399
6498
  ]))
6400
6499
  ]);
@@ -6447,14 +6546,18 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6447
6546
  const records = ref([]);
6448
6547
  const showCode = ref(false);
6449
6548
  watchEffect(() => {
6450
- const initValues = Object.entries(props.model[props.name] || {});
6451
- for (const [, value] of initValues) {
6452
- if (typeof value !== "string") {
6453
- showCode.value = true;
6454
- break;
6549
+ if (typeof props.model[props.name] === "function") {
6550
+ showCode.value = true;
6551
+ } else {
6552
+ const initValues = Object.entries(props.model[props.name] || {});
6553
+ for (const [, value] of initValues) {
6554
+ if (typeof value !== "string") {
6555
+ showCode.value = true;
6556
+ break;
6557
+ }
6455
6558
  }
6559
+ records.value = initValues;
6456
6560
  }
6457
- records.value = initValues;
6458
6561
  });
6459
6562
  const getValue = () => {
6460
6563
  const record = {};
@@ -6536,7 +6639,7 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6536
6639
  key: 1,
6537
6640
  height: "200px",
6538
6641
  "init-values": _ctx.model[_ctx.name],
6539
- language: "json",
6642
+ language: "javascript",
6540
6643
  options: {
6541
6644
  readOnly: _ctx.disabled
6542
6645
  },
@@ -7204,7 +7307,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7204
7307
  pageBarSortOptions: {},
7205
7308
  length: {}
7206
7309
  },
7207
- setup(__props) {
7310
+ setup(__props, { expose: __expose }) {
7208
7311
  const props = __props;
7209
7312
  const services = inject("services");
7210
7313
  const editorService = services?.editorService;
@@ -7234,23 +7337,28 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7234
7337
  });
7235
7338
  let translateLeft = 0;
7236
7339
  const scroll = (type) => {
7237
- if (!itemsContainer.value) return;
7340
+ if (!itemsContainer.value || !canScroll.value) return;
7238
7341
  const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
7239
7342
  if (type === "left") {
7240
- translateLeft += 100;
7241
- if (translateLeft > 0) {
7242
- translateLeft = 0;
7243
- }
7343
+ scrollTo(translateLeft + 200);
7244
7344
  } else if (type === "right") {
7245
- translateLeft -= 100;
7246
- if (-translateLeft > maxScrollLeft) {
7247
- translateLeft = -maxScrollLeft;
7248
- }
7345
+ scrollTo(translateLeft - 200);
7249
7346
  } else if (type === "start") {
7250
- translateLeft = 0;
7347
+ scrollTo(0);
7251
7348
  } else if (type === "end") {
7252
- translateLeft = -maxScrollLeft;
7349
+ scrollTo(-maxScrollLeft);
7350
+ }
7351
+ };
7352
+ const scrollTo = (value) => {
7353
+ if (!itemsContainer.value || !canScroll.value) return;
7354
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
7355
+ if (value >= 0) {
7356
+ value = 0;
7357
+ }
7358
+ if (-value > maxScrollLeft) {
7359
+ value = -maxScrollLeft;
7253
7360
  }
7361
+ translateLeft = value;
7254
7362
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
7255
7363
  };
7256
7364
  watch(
@@ -7258,11 +7366,13 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7258
7366
  (length = 0, preLength = 0) => {
7259
7367
  setTimeout(() => {
7260
7368
  setCanScroll();
7261
- if (length < preLength) {
7262
- scroll("start");
7263
- } else {
7264
- scroll("end");
7265
- }
7369
+ nextTick(() => {
7370
+ if (length < preLength || preLength === 0) {
7371
+ scroll("start");
7372
+ } else {
7373
+ scroll("end");
7374
+ }
7375
+ });
7266
7376
  if (length > 1) {
7267
7377
  const el = document.querySelector(".m-editor-page-bar-items");
7268
7378
  let beforeDragList = [];
@@ -7299,6 +7409,14 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7299
7409
  immediate: true
7300
7410
  }
7301
7411
  );
7412
+ __expose({
7413
+ itemsContainerWidth,
7414
+ scroll,
7415
+ scrollTo,
7416
+ getTranslateLeft() {
7417
+ return translateLeft;
7418
+ }
7419
+ });
7302
7420
  return (_ctx, _cache) => {
7303
7421
  return openBlock(), createElementBlock("div", {
7304
7422
  class: "m-editor-page-bar",
@@ -7306,25 +7424,24 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7306
7424
  ref: pageBar
7307
7425
  }, [
7308
7426
  renderSlot(_ctx.$slots, "prepend"),
7309
- canScroll.value ? (openBlock(), createElementBlock("div", {
7310
- key: 0,
7311
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
7312
- onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
7313
- }, [
7314
- createVNode(_sfc_main$Y, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
7315
- ])) : createCommentVNode("", true),
7316
7427
  _ctx.length ? (openBlock(), createElementBlock("div", {
7317
- key: 1,
7428
+ key: 0,
7318
7429
  class: "m-editor-page-bar-items",
7319
7430
  ref_key: "itemsContainer",
7320
- ref: itemsContainer,
7321
- style: normalizeStyle(`width: ${itemsContainerWidth.value}px`)
7431
+ ref: itemsContainer
7322
7432
  }, [
7323
7433
  renderSlot(_ctx.$slots, "default")
7324
- ], 4)) : createCommentVNode("", true),
7434
+ ], 512)) : createCommentVNode("", true),
7435
+ canScroll.value ? (openBlock(), createElementBlock("div", {
7436
+ key: 1,
7437
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon m-editor-page-bar-item-left-icon",
7438
+ onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
7439
+ }, [
7440
+ createVNode(_sfc_main$Y, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
7441
+ ])) : createCommentVNode("", true),
7325
7442
  canScroll.value ? (openBlock(), createElementBlock("div", {
7326
7443
  key: 2,
7327
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
7444
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon m-editor-page-bar-item-right-icon",
7328
7445
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
7329
7446
  }, [
7330
7447
  createVNode(_sfc_main$Y, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
@@ -7352,8 +7469,9 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
7352
7469
  const uiService = services?.uiService;
7353
7470
  const editorService = services?.editorService;
7354
7471
  const showPageListButton = computed(() => uiService?.get("showPageListButton"));
7355
- const switchPage = (id) => {
7356
- editorService?.select(id);
7472
+ const page = computed(() => editorService?.get("page"));
7473
+ const switchPage = async (id) => {
7474
+ await editorService?.select(id);
7357
7475
  };
7358
7476
  return (_ctx, _cache) => {
7359
7477
  return showPageListButton.value ? (openBlock(), createElementBlock("div", _hoisted_1$e, [
@@ -7380,6 +7498,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
7380
7498
  data: {
7381
7499
  type: "button",
7382
7500
  text: item.devconfig?.tabName || item.name || item.id,
7501
+ className: item.id === page.value?.id ? "active" : "",
7383
7502
  handler: () => switchPage(item.id)
7384
7503
  },
7385
7504
  key: index
@@ -7460,7 +7579,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
7460
7579
  });
7461
7580
 
7462
7581
  const _hoisted_1$c = { class: "m-editor-page-bar-tabs" };
7463
- const _hoisted_2$5 = ["page-id", "onClick"];
7582
+ const _hoisted_2$5 = ["data-page-id", "onClick"];
7464
7583
  const _hoisted_3$2 = { class: "m-editor-page-bar-title" };
7465
7584
  const _hoisted_4$2 = ["title"];
7466
7585
  const _sfc_main$t = /* @__PURE__ */ defineComponent({
@@ -7511,9 +7630,38 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7511
7630
  const remove = (node) => {
7512
7631
  editorService?.remove(node);
7513
7632
  };
7633
+ const pageBarScrollContainer = ref();
7634
+ const pageBarItems = ref();
7635
+ watch(page, (page2) => {
7636
+ if (!page2 || !pageBarScrollContainer.value?.itemsContainerWidth || !pageBarItems.value || pageBarItems.value.length < 2) {
7637
+ return;
7638
+ }
7639
+ const firstItem = pageBarItems.value[0];
7640
+ const lastItem = pageBarItems.value[pageBarItems.value.length - 1];
7641
+ if (page2.id === firstItem.dataset.pageId) {
7642
+ pageBarScrollContainer.value.scroll("start");
7643
+ } else if (page2.id === lastItem.dataset.pageId) {
7644
+ pageBarScrollContainer.value.scroll("end");
7645
+ } else {
7646
+ const pageItem = pageBarItems.value.find((item) => item.dataset.pageId === page2.id);
7647
+ if (!pageItem) {
7648
+ return;
7649
+ }
7650
+ const pageItemRect = pageItem.getBoundingClientRect();
7651
+ const offsetLeft = pageItemRect.left - firstItem.getBoundingClientRect().left;
7652
+ const { itemsContainerWidth } = pageBarScrollContainer.value;
7653
+ const left = itemsContainerWidth - offsetLeft - pageItemRect.width;
7654
+ const translateLeft = pageBarScrollContainer.value.getTranslateLeft();
7655
+ if (offsetLeft + translateLeft < 0 || offsetLeft + pageItemRect.width > itemsContainerWidth - translateLeft) {
7656
+ pageBarScrollContainer.value.scrollTo(left);
7657
+ }
7658
+ }
7659
+ });
7514
7660
  return (_ctx, _cache) => {
7515
7661
  return openBlock(), createElementBlock("div", _hoisted_1$c, [
7516
7662
  createVNode(_sfc_main$w, {
7663
+ ref_key: "pageBarScrollContainer",
7664
+ ref: pageBarScrollContainer,
7517
7665
  "page-bar-sort-options": _ctx.pageBarSortOptions,
7518
7666
  length: list.value.length
7519
7667
  }, {
@@ -7536,8 +7684,11 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7536
7684
  (openBlock(true), createElementBlock(Fragment, null, renderList(list.value, (item) => {
7537
7685
  return openBlock(), createElementBlock("div", {
7538
7686
  class: normalizeClass(["m-editor-page-bar-item", { active: page.value?.id === item.id }]),
7687
+ ref_for: true,
7688
+ ref_key: "pageBarItems",
7689
+ ref: pageBarItems,
7539
7690
  key: item.id,
7540
- "page-id": item.id,
7691
+ "data-page-id": item.id,
7541
7692
  onClick: ($event) => switchPage(item.id)
7542
7693
  }, [
7543
7694
  createElementVNode("div", _hoisted_3$2, [
@@ -7669,7 +7820,6 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7669
7820
  const root = computed(() => editorService?.get("root"));
7670
7821
  const page = computed(() => editorService?.get("page"));
7671
7822
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
7672
- const stageLoading = computed(() => editorService?.get("stageLoading") || false);
7673
7823
  const showSrc = computed(() => uiService?.get("showSrc"));
7674
7824
  const getLeftColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
7675
7825
  const getRightColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH;
@@ -7720,7 +7870,6 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7720
7870
  }
7721
7871
  };
7722
7872
  return (_ctx, _cache) => {
7723
- const _directive_loading = resolveDirective("loading");
7724
7873
  return openBlock(), createElementBlock("div", {
7725
7874
  class: "m-editor",
7726
7875
  ref_key: "content",
@@ -7737,9 +7886,8 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7737
7886
  options: unref(codeOptions),
7738
7887
  onSave: saveCode
7739
7888
  }, null, 8, ["init-values", "options"])
7740
- ]) : withDirectives((openBlock(), createBlock(_sfc_main$z, {
7889
+ ]) : (openBlock(), createBlock(_sfc_main$z, {
7741
7890
  key: 1,
7742
- "element-loading-text": "Runtime 加载中...",
7743
7891
  ref_key: "splitView",
7744
7892
  ref: splitView,
7745
7893
  class: "m-editor-content",
@@ -7799,9 +7947,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7799
7947
  ]),
7800
7948
  key: "0"
7801
7949
  } : void 0
7802
- ]), 1032, ["left", "right", "width"])), [
7803
- [_directive_loading, stageLoading.value]
7804
- ]),
7950
+ ]), 1032, ["left", "right", "width"])),
7805
7951
  renderSlot(_ctx.$slots, "content-after"),
7806
7952
  renderSlot(_ctx.$slots, "footer")
7807
7953
  ], 512);
@@ -8050,10 +8196,10 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
8050
8196
  configForm.value.formState.stage = stage.value;
8051
8197
  }
8052
8198
  });
8053
- const submit = async () => {
8199
+ const submit = async (v, eventData) => {
8054
8200
  try {
8055
8201
  const values2 = await configForm.value?.submitForm();
8056
- services?.editorService.update(values2);
8202
+ services?.editorService.update(values2, { changeRecords: eventData.changeRecords });
8057
8203
  } catch (e) {
8058
8204
  emit("submit-error", e);
8059
8205
  }
@@ -8355,6 +8501,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8355
8501
  const emit = __emit;
8356
8502
  const services = inject("services");
8357
8503
  const { codeBlockService, depService, editorService } = services || {};
8504
+ const collecting = computed(() => depService?.get("collecting"));
8358
8505
  const codeList = computed(
8359
8506
  () => Object.entries(codeBlockService?.getCodeDsl() || {}).map(([codeId, code]) => {
8360
8507
  const target = depService?.getTarget(codeId, DepTargetType.CODE_BLOCK);
@@ -8454,8 +8601,19 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8454
8601
  }, toDisplayString(data.name) + " " + toDisplayString(data.key ? `(${data.key})` : ""), 3)
8455
8602
  ]),
8456
8603
  "tree-node-tool": withCtx(({ data }) => [
8457
- data.type === "code" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8604
+ collecting.value && data.type === "code" ? (openBlock(), createBlock(unref(TMagicTag), {
8458
8605
  key: 0,
8606
+ type: "info",
8607
+ size: "small",
8608
+ style: { "margin-right": "5px" }
8609
+ }, {
8610
+ default: withCtx(() => _cache[0] || (_cache[0] = [
8611
+ createTextVNode("依赖收集中")
8612
+ ])),
8613
+ _: 1
8614
+ })) : createCommentVNode("", true),
8615
+ data.type === "code" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8616
+ key: 1,
8459
8617
  effect: "dark",
8460
8618
  content: editable.value ? "编辑" : "查看",
8461
8619
  placement: "bottom"
@@ -8470,7 +8628,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8470
8628
  _: 2
8471
8629
  }, 1032, ["content"])) : createCommentVNode("", true),
8472
8630
  data.type === "code" && editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
8473
- key: 1,
8631
+ key: 2,
8474
8632
  effect: "dark",
8475
8633
  content: "删除",
8476
8634
  placement: "bottom"
@@ -8586,9 +8744,9 @@ const useDataSourceEdit = (dataSourceService) => {
8586
8744
  dialogTitle.value = `编辑${dataSourceValues.value.title || ""}`;
8587
8745
  editDialog.value.show();
8588
8746
  };
8589
- const submitDataSourceHandler = (value) => {
8747
+ const submitDataSourceHandler = (value, eventData) => {
8590
8748
  if (value.id) {
8591
- dataSourceService?.update(value);
8749
+ dataSourceService?.update(value, { changeRecords: eventData.changeRecords });
8592
8750
  } else {
8593
8751
  dataSourceService?.add(value);
8594
8752
  }
@@ -8635,8 +8793,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
8635
8793
  initValues.value = props.values;
8636
8794
  dataSourceConfig.value = services?.dataSourceService.getFormConfig(initValues.value.type) || [];
8637
8795
  });
8638
- const submitHandler = (values) => {
8639
- emit("submit", values);
8796
+ const submitHandler = (values, data) => {
8797
+ emit("submit", values, data);
8640
8798
  };
8641
8799
  const errorHandler = (error) => {
8642
8800
  tMagicMessage.error(error.message);
@@ -8692,6 +8850,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8692
8850
  setup(__props, { expose: __expose, emit: __emit }) {
8693
8851
  const emit = __emit;
8694
8852
  const { depService, editorService, dataSourceService } = inject("services") || {};
8853
+ const collecting = computed(() => depService?.get("collecting"));
8695
8854
  const editable = computed(() => dataSourceService?.get("editable") ?? true);
8696
8855
  const dataSources = computed(() => dataSourceService?.get("dataSources") || []);
8697
8856
  const dsDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE) || {});
@@ -8797,8 +8956,19 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8797
8956
  }, toDisplayString(data.name) + " " + toDisplayString(data.key ? `(${data.key})` : ""), 3)
8798
8957
  ]),
8799
8958
  "tree-node-tool": withCtx(({ data }) => [
8800
- data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8959
+ collecting.value && data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTag), {
8801
8960
  key: 0,
8961
+ type: "info",
8962
+ size: "small",
8963
+ style: { "margin-right": "5px" }
8964
+ }, {
8965
+ default: withCtx(() => _cache[0] || (_cache[0] = [
8966
+ createTextVNode("依赖收集中")
8967
+ ])),
8968
+ _: 1
8969
+ })) : createCommentVNode("", true),
8970
+ data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8971
+ key: 1,
8802
8972
  effect: "dark",
8803
8973
  content: editable.value ? "编辑" : "查看",
8804
8974
  placement: "bottom"
@@ -8813,7 +8983,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8813
8983
  _: 2
8814
8984
  }, 1032, ["content"])) : createCommentVNode("", true),
8815
8985
  data.type === "ds" && editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
8816
- key: 1,
8986
+ key: 2,
8817
8987
  effect: "dark",
8818
8988
  content: "删除",
8819
8989
  placement: "bottom"
@@ -10079,6 +10249,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10079
10249
  setup(__props, { expose: __expose }) {
10080
10250
  const props = __props;
10081
10251
  const services = inject("services");
10252
+ const collecting = computed(() => services?.depService.get("collecting"));
10082
10253
  const columnLeftWidth = computed(() => services?.uiService.get("columnWidth")[ColumnLayout.LEFT] || 0);
10083
10254
  const { height: editorContentHeight } = useEditorContentHeight();
10084
10255
  const columnLeftHeight = ref(0);
@@ -10221,7 +10392,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10221
10392
  ]),
10222
10393
  (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
10223
10394
  return withDirectives((openBlock(), createElementBlock("div", {
10224
- class: "m-editor-sidebar-content",
10395
+ class: normalizeClass(["m-editor-sidebar-content", { "m-editor-dep-collecting": collecting.value }]),
10225
10396
  key: config.$key ?? index
10226
10397
  }, [
10227
10398
  config?.component && !unref(floatBoxStates)[config.$key]?.status ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({
@@ -10347,7 +10518,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10347
10518
  key: "11"
10348
10519
  } : void 0
10349
10520
  ]), 1040)) : createCommentVNode("", true)
10350
- ])), [
10521
+ ], 2)), [
10351
10522
  [vShow, [config.text, config.$key, `${index}`].includes(activeTabName.value)]
10352
10523
  ]);
10353
10524
  }), 128))
@@ -10928,15 +11099,17 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
10928
11099
  },
10929
11100
  __name: "Stage",
10930
11101
  props: {
11102
+ stageOptions: {},
10931
11103
  stageContentMenu: {},
10932
11104
  disabledStageOverlay: { type: Boolean, default: false },
10933
11105
  customContentMenu: {}
10934
11106
  },
10935
11107
  setup(__props) {
11108
+ const props = __props;
10936
11109
  let stage = null;
10937
11110
  let runtime = null;
10938
11111
  const services = inject("services");
10939
- const stageOptions = inject("stageOptions");
11112
+ const stageLoading = computed(() => services?.editorService.get("stageLoading") || false);
10940
11113
  const stageWrap = ref();
10941
11114
  const stageContainer = ref();
10942
11115
  const menu = ref();
@@ -10951,8 +11124,8 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
10951
11124
  watchEffect(() => {
10952
11125
  if (stage || !page.value) return;
10953
11126
  if (!stageContainer.value) return;
10954
- if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
10955
- stage = useStage(stageOptions);
11127
+ if (!(props.stageOptions?.runtimeUrl || props.stageOptions?.render) || !root.value) return;
11128
+ stage = useStage(props.stageOptions);
10956
11129
  stage.on("select", () => {
10957
11130
  stageWrap.value?.container?.focus();
10958
11131
  });
@@ -10972,6 +11145,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
10972
11145
  });
10973
11146
  onBeforeUnmount(() => {
10974
11147
  stage?.destroy();
11148
+ services?.editorService.set("stage", null);
10975
11149
  });
10976
11150
  watch(zoom, (zoom2) => {
10977
11151
  if (!stage || !zoom2) return;
@@ -11039,7 +11213,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11039
11213
  if (!config || config.dragType !== DragType.COMPONENT_LIST) return;
11040
11214
  e.preventDefault();
11041
11215
  const doc = stage?.renderer?.contentWindow?.document;
11042
- const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
11216
+ const parentEl = doc?.querySelector(
11217
+ `.${props.stageOptions?.containerHighlightClassName}`
11218
+ );
11043
11219
  let parent = page.value;
11044
11220
  const parentId = getIdFromEl()(parentEl);
11045
11221
  if (parentId) {
@@ -11078,11 +11254,13 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11078
11254
  }
11079
11255
  };
11080
11256
  return (_ctx, _cache) => {
11081
- return openBlock(), createBlock(_sfc_main$8, {
11257
+ const _directive_loading = resolveDirective("loading");
11258
+ return withDirectives((openBlock(), createBlock(_sfc_main$8, {
11082
11259
  class: "m-editor-stage",
11083
11260
  ref_key: "stageWrap",
11084
11261
  ref: stageWrap,
11085
11262
  tabindex: "-1",
11263
+ "element-loading-text": "Runtime 加载中...",
11086
11264
  width: stageRect.value?.width,
11087
11265
  height: stageRect.value?.height,
11088
11266
  "wrap-width": stageContainerRect.value?.width,
@@ -11119,7 +11297,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11119
11297
  createVNode(_sfc_main$7)
11120
11298
  ]),
11121
11299
  _: 1
11122
- }, 8, ["width", "height", "wrap-width", "wrap-height", "zoom"]);
11300
+ }, 8, ["width", "height", "wrap-width", "wrap-height", "zoom"])), [
11301
+ [_directive_loading, stageLoading.value]
11302
+ ]);
11123
11303
  };
11124
11304
  }
11125
11305
  });
@@ -11181,18 +11361,20 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
11181
11361
  customContentMenu: {}
11182
11362
  },
11183
11363
  setup(__props) {
11364
+ const stageOptions = inject("stageOptions");
11184
11365
  const services = inject("services");
11185
11366
  const page = computed(() => services?.editorService.get("page"));
11186
11367
  return (_ctx, _cache) => {
11187
11368
  return openBlock(), createElementBlock("div", _hoisted_1, [
11188
11369
  createVNode(_sfc_main$2),
11189
11370
  renderSlot(_ctx.$slots, "stage", {}, () => [
11190
- page.value ? (openBlock(), createBlock(_sfc_main$3, {
11371
+ page.value && (unref(stageOptions)?.render || unref(stageOptions)?.runtimeUrl) ? (openBlock(), createBlock(_sfc_main$3, {
11191
11372
  key: 0,
11373
+ "stage-options": unref(stageOptions),
11192
11374
  "disabled-stage-overlay": _ctx.disabledStageOverlay,
11193
11375
  "stage-content-menu": _ctx.stageContentMenu,
11194
11376
  "custom-content-menu": _ctx.customContentMenu
11195
- }, null, 8, ["disabled-stage-overlay", "stage-content-menu", "custom-content-menu"])) : createCommentVNode("", true)
11377
+ }, null, 8, ["stage-options", "disabled-stage-overlay", "stage-content-menu", "custom-content-menu"])) : createCommentVNode("", true)
11196
11378
  ]),
11197
11379
  renderSlot(_ctx.$slots, "workspace-content")
11198
11380
  ]);
@@ -11542,12 +11724,17 @@ class DataSource extends BaseService {
11542
11724
  this.emit("add", newConfig);
11543
11725
  return newConfig;
11544
11726
  }
11545
- update(config) {
11727
+ update(config, { changeRecords = [] } = {}) {
11546
11728
  const dataSources = this.get("dataSources");
11547
11729
  const index = dataSources.findIndex((ds) => ds.id === config.id);
11548
- dataSources[index] = cloneDeep(config);
11549
- this.emit("update", config);
11550
- return config;
11730
+ const oldConfig = dataSources[index];
11731
+ const newConfig = cloneDeep(config);
11732
+ dataSources[index] = newConfig;
11733
+ this.emit("update", newConfig, {
11734
+ oldConfig,
11735
+ changeRecords
11736
+ });
11737
+ return newConfig;
11551
11738
  }
11552
11739
  remove(id) {
11553
11740
  const dataSources = this.get("dataSources");
@@ -11623,7 +11810,16 @@ const dataSourceService = new DataSource();
11623
11810
 
11624
11811
  const idleTask = new IdleTask();
11625
11812
  class Dep extends BaseService {
11813
+ state = reactive({
11814
+ collecting: false
11815
+ });
11626
11816
  watcher = new Watcher({ initialTargets: reactive({}) });
11817
+ set(name, value) {
11818
+ this.state[name] = value;
11819
+ }
11820
+ get(name) {
11821
+ return this.state[name];
11822
+ }
11627
11823
  removeTargets(type = DepTargetType.DEFAULT) {
11628
11824
  this.watcher.removeTargets(type);
11629
11825
  const targets = this.watcher.getTargets(type);
@@ -11650,34 +11846,30 @@ class Dep extends BaseService {
11650
11846
  this.watcher.clearTargets();
11651
11847
  }
11652
11848
  collect(nodes, depExtendedData = {}, deep = false, type) {
11849
+ this.set("collecting", true);
11653
11850
  this.watcher.collectByCallback(nodes, type, ({ node, target }) => {
11654
11851
  this.collectNode(node, target, depExtendedData, deep);
11655
11852
  });
11853
+ this.set("collecting", false);
11656
11854
  this.emit("collected", nodes, deep);
11657
11855
  }
11658
11856
  collectIdle(nodes, depExtendedData = {}, deep = false, type) {
11857
+ this.set("collecting", true);
11659
11858
  let startTask = false;
11660
11859
  this.watcher.collectByCallback(nodes, type, ({ node, target }) => {
11661
11860
  startTask = true;
11662
- idleTask.enqueueTask(
11663
- ({ node: node2, deep: deep2, target: target2 }) => {
11664
- this.collectNode(node2, target2, depExtendedData, deep2);
11665
- },
11666
- {
11667
- node,
11668
- deep,
11669
- target
11670
- }
11671
- );
11861
+ this.enqueueTask(node, target, depExtendedData, deep);
11672
11862
  });
11673
11863
  return new Promise((resolve) => {
11674
11864
  if (!startTask) {
11675
11865
  this.emit("collected", nodes, deep);
11866
+ this.set("collecting", false);
11676
11867
  resolve();
11677
11868
  return;
11678
11869
  }
11679
11870
  idleTask.once("finish", () => {
11680
11871
  this.emit("collected", nodes, deep);
11872
+ this.set("collecting", false);
11681
11873
  resolve();
11682
11874
  });
11683
11875
  });
@@ -11706,6 +11898,9 @@ class Dep extends BaseService {
11706
11898
  hasSpecifiedTypeTarget(type = DepTargetType.DEFAULT) {
11707
11899
  return this.watcher.hasSpecifiedTypeTarget(type);
11708
11900
  }
11901
+ clearIdleTasks() {
11902
+ idleTask.clearTasks();
11903
+ }
11709
11904
  on(eventName, listener) {
11710
11905
  return super.on(eventName, listener);
11711
11906
  }
@@ -11715,6 +11910,23 @@ class Dep extends BaseService {
11715
11910
  emit(eventName, ...args) {
11716
11911
  return super.emit(eventName, ...args);
11717
11912
  }
11913
+ enqueueTask(node, target, depExtendedData, deep) {
11914
+ idleTask.enqueueTask(
11915
+ ({ node: node2, deep: deep2, target: target2 }) => {
11916
+ this.collectNode(node2, target2, depExtendedData, deep2);
11917
+ },
11918
+ {
11919
+ node,
11920
+ deep: false,
11921
+ target
11922
+ }
11923
+ );
11924
+ if (deep && Array.isArray(node.items) && node.items.length) {
11925
+ node.items.forEach((item) => {
11926
+ this.enqueueTask(item, target, depExtendedData, deep);
11927
+ });
11928
+ }
11929
+ }
11718
11930
  }
11719
11931
  const depService = new Dep();
11720
11932
 
@@ -12288,6 +12500,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12288
12500
  initDataSourceDepTarget(ds);
12289
12501
  });
12290
12502
  if (Array.isArray(value.items)) {
12503
+ depService.clearIdleTasks();
12291
12504
  collectIdle(value.items, true);
12292
12505
  } else {
12293
12506
  depService.clear();
@@ -12312,10 +12525,20 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12312
12525
  emit("update:modelValue", value);
12313
12526
  }
12314
12527
  };
12315
- const getApp = () => {
12316
- const stage = editorService.get("stage");
12317
- return stage?.renderer?.runtime?.getApp?.();
12318
- };
12528
+ const stage = computed(() => editorService.get("stage"));
12529
+ watch(stage, (stage2) => {
12530
+ if (!stage2) {
12531
+ return;
12532
+ }
12533
+ stage2.on("rerender", () => {
12534
+ const node = editorService.get("node");
12535
+ if (!node) return;
12536
+ collectIdle([node], true).then(() => {
12537
+ afterUpdateNodes([node]);
12538
+ });
12539
+ });
12540
+ });
12541
+ const getApp = () => stage.value?.renderer?.runtime?.getApp?.();
12319
12542
  const updateDataSourceSchema = (nodes, deep) => {
12320
12543
  const root = editorService.get("root");
12321
12544
  const app = getApp();
@@ -12327,8 +12550,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12327
12550
  if (root?.dataSources) {
12328
12551
  getApp()?.dataSourceManager?.updateSchema(root.dataSources);
12329
12552
  }
12330
- const stage = editorService.get("stage");
12331
- if (!root || !stage) return;
12553
+ if (!root || !stage.value) return;
12332
12554
  const allNodes = [];
12333
12555
  if (deep) {
12334
12556
  nodes.forEach((node) => {
@@ -12345,7 +12567,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12345
12567
  deps.forEach((dep) => {
12346
12568
  Object.keys(dep).forEach((id) => {
12347
12569
  const node = allNodes.find((node2) => node2.id === id);
12348
- node && stage.update({
12570
+ node && stage.value?.update({
12349
12571
  config: cloneDeep(node),
12350
12572
  parentId: editorService.getParentById(node.id)?.id,
12351
12573
  root: cloneDeep(root)
@@ -12356,13 +12578,8 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12356
12578
  const afterUpdateNodes = (nodes) => {
12357
12579
  const root = editorService.get("root");
12358
12580
  if (!root) return;
12359
- const stage = editorService.get("stage");
12360
- const app = getApp();
12361
- if (app?.dsl) {
12362
- app.dsl.dataSourceDeps = root.dataSourceDeps;
12363
- }
12364
12581
  for (const node of nodes) {
12365
- stage?.update({
12582
+ stage.value?.update({
12366
12583
  config: cloneDeep(node),
12367
12584
  parentId: editorService.getParentById(node.id)?.id,
12368
12585
  root: cloneDeep(root)
@@ -12395,8 +12612,17 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12395
12612
  delete root.dataSourceCondDeps[id];
12396
12613
  }
12397
12614
  };
12615
+ const depCollectedHandler = () => {
12616
+ const root = editorService.get("root");
12617
+ if (!root) return;
12618
+ const app = getApp();
12619
+ if (app?.dsl) {
12620
+ app.dsl.dataSourceDeps = root.dataSourceDeps;
12621
+ }
12622
+ };
12398
12623
  depService.on("add-target", targetAddHandler);
12399
12624
  depService.on("remove-target", targetRemoveHandler);
12625
+ depService.on("collected", depCollectedHandler);
12400
12626
  const initDataSourceDepTarget = (ds) => {
12401
12627
  depService.addTarget(createDataSourceTarget(ds, reactive({})));
12402
12628
  depService.addTarget(createDataSourceMethodTarget(ds, reactive({})));
@@ -12419,10 +12645,31 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12419
12645
  afterUpdateNodes(nodes);
12420
12646
  });
12421
12647
  };
12422
- const nodeUpdateHandler = (nodes) => {
12423
- collectIdle(nodes, true).then(() => {
12424
- afterUpdateNodes(nodes);
12648
+ const nodeUpdateHandler = (data) => {
12649
+ const needRecollectNodes = [];
12650
+ const normalNodes = [];
12651
+ data.forEach(({ newNode, oldNode, changeRecords }) => {
12652
+ if (changeRecords?.length) {
12653
+ for (const record of changeRecords) {
12654
+ if (!record.propPath || new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond`).test(record.propPath) || new RegExp(`${NODE_CONDS_KEY}.(\\d)+.cond.(\\d)+.value`).test(record.propPath) || record.propPath === NODE_CONDS_KEY || isValueIncludeDataSource(record.value)) {
12655
+ needRecollectNodes.push(newNode);
12656
+ } else {
12657
+ normalNodes.push(newNode);
12658
+ }
12659
+ }
12660
+ } else if (isIncludeDataSource(newNode, oldNode)) {
12661
+ needRecollectNodes.push(newNode);
12662
+ } else {
12663
+ normalNodes.push(newNode);
12664
+ }
12425
12665
  });
12666
+ if (needRecollectNodes.length) {
12667
+ collectIdle(needRecollectNodes, true).then(() => {
12668
+ afterUpdateNodes(needRecollectNodes);
12669
+ });
12670
+ } else if (normalNodes.length) {
12671
+ afterUpdateNodes(normalNodes);
12672
+ }
12426
12673
  };
12427
12674
  const nodeRemoveHandler = (nodes) => {
12428
12675
  depService.clear(nodes);
@@ -12453,13 +12700,30 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12453
12700
  initDataSourceDepTarget(config);
12454
12701
  getApp()?.dataSourceManager?.addDataSource(config);
12455
12702
  };
12456
- const dataSourceUpdateHandler = (config) => {
12703
+ const dataSourceUpdateHandler = (config, { changeRecords }) => {
12704
+ let needRecollectDep = false;
12705
+ for (const changeRecord of changeRecords) {
12706
+ if (!changeRecord.propPath) {
12707
+ continue;
12708
+ }
12709
+ needRecollectDep = changeRecord.propPath === "fields" || changeRecord.propPath === "methods" || /fields.(\d)+.name/.test(changeRecord.propPath) || /fields.(\d)+$/.test(changeRecord.propPath) || /methods.(\d)+.name/.test(changeRecord.propPath) || /methods.(\d)+$/.test(changeRecord.propPath);
12710
+ if (needRecollectDep) {
12711
+ break;
12712
+ }
12713
+ }
12457
12714
  const root = editorService.get("root");
12458
- removeDataSourceTarget(config.id);
12459
- initDataSourceDepTarget(config);
12460
- collectIdle(root?.items || [], true).then(() => {
12461
- updateDataSourceSchema(root?.items || [], true);
12462
- });
12715
+ if (needRecollectDep) {
12716
+ if (Array.isArray(root?.items)) {
12717
+ depService.clearIdleTasks();
12718
+ removeDataSourceTarget(config.id);
12719
+ initDataSourceDepTarget(config);
12720
+ collectIdle(root.items, true).then(() => {
12721
+ updateDataSourceSchema(root?.items || [], true);
12722
+ });
12723
+ }
12724
+ } else if (root?.dataSources) {
12725
+ getApp()?.dataSourceManager?.updateSchema(root.dataSources);
12726
+ }
12463
12727
  };
12464
12728
  const removeDataSourceTarget = (id) => {
12465
12729
  depService.removeTarget(id, DepTargetType.DATA_SOURCE);
@@ -12481,6 +12745,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12481
12745
  onBeforeUnmount(() => {
12482
12746
  depService.off("add-target", targetAddHandler);
12483
12747
  depService.off("remove-target", targetRemoveHandler);
12748
+ depService.off("collected", depCollectedHandler);
12484
12749
  editorService.off("history-change", historyChangeHandler);
12485
12750
  editorService.off("root-change", rootChangeHandler);
12486
12751
  editorService.off("add", nodeAddHandler);
@@ -12753,4 +13018,4 @@ const index = {
12753
13018
  }
12754
13019
  };
12755
13020
 
12756
- export { CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$L as CodeBlockEditor, _sfc_main$l as CodeBlockList, _sfc_main$k as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$U as CodeSelect, _sfc_main$S as CodeSelectCol, ColumnLayout, _sfc_main$b as ComponentListPanel, _sfc_main$R as CondOpSelect, _sfc_main$g as ContentMenu, _sfc_main$j as DataSourceConfigPanel, _sfc_main$N as DataSourceFieldSelect, _sfc_main$P as DataSourceFields, _sfc_main$M as DataSourceInput, _sfc_main$J as DataSourceMethodSelect, _sfc_main$K as DataSourceMethods, _sfc_main$I as DataSourceMocks, _sfc_main$H as DataSourceSelect, _sfc_main$G as DisplayConds, DragType, _sfc_main$F as EventSelect, Fixed2Other, _sfc_main$Q as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$Y as Icon, IdleTask, KeyBindingCommand, _sfc_main$D as KeyValue, Keys, LayerOffset, _sfc_main$c as LayerPanel, Layout, _sfc_main$z as LayoutContainer, _sfc_main$C as PageFragmentSelect, _sfc_main$p as PropsPanel, _sfc_main$A as Resizer, ScrollViewer, SideItemKey, _sfc_main$z as SplitView, _sfc_main$X as TMagicCodeEditor, _sfc_main as TMagicEditor, _sfc_main$y as ToolButton, _sfc_main$m as Tree, _sfc_main$n as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, arrayOptions, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, eqOptions, error, eventTabConfig, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getDefaultConfig, getDisplayField, getEditorConfig, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, log, moveItemsInContainer, numberOptions, propsService, removeDataSourceFieldPrefix, serializeConfig, setChildrenLayout, setEditorConfig, setLayout, stageOverlayService, storageService, styleTabConfig, uiService, updateStatus, useCodeBlockEdit, useDataSourceMethod, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useNextFloatBoxPosition, useNodeStatus$1 as useNodeStatus, useStage, useWindowRect, warn };
13021
+ export { CODE_DRAFT_STORAGE_KEY, COPY_CODE_STORAGE_KEY, COPY_DS_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$L as CodeBlockEditor, _sfc_main$l as CodeBlockList, _sfc_main$k as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$U as CodeSelect, _sfc_main$S as CodeSelectCol, ColumnLayout, _sfc_main$b as ComponentListPanel, _sfc_main$R as CondOpSelect, _sfc_main$g as ContentMenu, _sfc_main$j as DataSourceConfigPanel, _sfc_main$N as DataSourceFieldSelect, _sfc_main$P as DataSourceFields, _sfc_main$M as DataSourceInput, _sfc_main$J as DataSourceMethodSelect, _sfc_main$K as DataSourceMethods, _sfc_main$I as DataSourceMocks, _sfc_main$H as DataSourceSelect, _sfc_main$G as DisplayConds, DragType, _sfc_main$F as EventSelect, Fixed2Other, _sfc_main$Q as FloatingBox, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$Y as Icon, IdleTask, KeyBindingCommand, _sfc_main$D as KeyValue, Keys, LayerOffset, _sfc_main$c as LayerPanel, Layout, _sfc_main$z as LayoutContainer, _sfc_main$C as PageFragmentSelect, _sfc_main$p as PropsPanel, _sfc_main$A as Resizer, ScrollViewer, SideItemKey, _sfc_main$z as SplitView, _sfc_main$X as TMagicCodeEditor, _sfc_main as TMagicEditor, _sfc_main$y as ToolButton, _sfc_main$m as Tree, _sfc_main$n as TreeNode, UI_SELECT_MODE_EVENT_NAME, UndoRedo, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, arrayOptions, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, eqOptions, error, eventTabConfig, eventsService, fillConfig$1 as fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getCascaderOptionsFromFields, getDefaultConfig, getDisplayField, getEditorConfig, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageFragmentList, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isIncludeDataSource, log, moveItemsInContainer, numberOptions, propsService, removeDataSourceFieldPrefix, serializeConfig, setChildrenLayout, setEditorConfig, setLayout, stageOverlayService, storageService, styleTabConfig, uiService, updateStatus, useCodeBlockEdit, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useNextFloatBoxPosition, useNodeStatus$1 as useNodeStatus, useStage, useWindowRect, warn };