@tmagic/editor 1.5.0-beta.9 → 1.5.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 (52) hide show
  1. package/dist/style.css +75 -16
  2. package/dist/tmagic-editor.js +797 -518
  3. package/dist/tmagic-editor.umd.cjs +802 -525
  4. package/package.json +12 -10
  5. package/src/Editor.vue +6 -1
  6. package/src/components/CodeBlockEditor.vue +11 -5
  7. package/src/components/CodeParams.vue +3 -3
  8. package/src/editorProps.ts +3 -1
  9. package/src/fields/Code.vue +1 -2
  10. package/src/fields/CodeSelect.vue +13 -11
  11. package/src/fields/CodeSelectCol.vue +32 -5
  12. package/src/fields/CondOpSelect.vue +5 -2
  13. package/src/fields/DataSourceFields.vue +31 -12
  14. package/src/fields/DataSourceMethods.vue +72 -14
  15. package/src/fields/DisplayConds.vue +8 -3
  16. package/src/fields/EventSelect.vue +28 -11
  17. package/src/fields/KeyValue.vue +15 -10
  18. package/src/fields/UISelect.vue +6 -3
  19. package/src/hooks/index.ts +0 -1
  20. package/src/hooks/use-code-block-edit.ts +1 -1
  21. package/src/hooks/use-data-source-edit.ts +3 -2
  22. package/src/hooks/use-filter.ts +1 -1
  23. package/src/hooks/use-node-status.ts +2 -2
  24. package/src/initService.ts +177 -74
  25. package/src/layouts/Framework.vue +8 -4
  26. package/src/layouts/PropsPanel.vue +3 -3
  27. package/src/layouts/page-bar/AddButton.vue +29 -9
  28. package/src/layouts/page-bar/PageBar.vue +78 -65
  29. package/src/layouts/page-bar/PageBarScrollContainer.vue +82 -96
  30. package/src/layouts/page-bar/PageList.vue +5 -3
  31. package/src/layouts/page-bar/Search.vue +67 -0
  32. package/src/layouts/sidebar/Sidebar.vue +3 -0
  33. package/src/layouts/sidebar/code-block/CodeBlockList.vue +6 -1
  34. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
  35. package/src/layouts/sidebar/data-source/DataSourceList.vue +6 -1
  36. package/src/layouts/sidebar/layer/use-node-status.ts +2 -3
  37. package/src/layouts/workspace/Workspace.vue +5 -2
  38. package/src/layouts/workspace/viewer/Stage.vue +23 -5
  39. package/src/services/dataSource.ts +12 -5
  40. package/src/services/dep.ts +61 -13
  41. package/src/services/editor.ts +46 -51
  42. package/src/theme/page-bar.scss +38 -16
  43. package/src/theme/search-input.scss +1 -0
  44. package/src/type.ts +2 -1
  45. package/src/utils/data-source/formConfigs/http.ts +2 -0
  46. package/src/utils/data-source/index.ts +2 -2
  47. package/src/utils/editor.ts +78 -22
  48. package/src/utils/idle-task.ts +36 -4
  49. package/src/utils/props.ts +3 -3
  50. package/types/index.d.ts +835 -1169
  51. package/src/hooks/use-data-source-method.ts +0 -100
  52. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
@@ -1,21 +1,21 @@
1
1
  import designPlugin__default, { TMagicIcon, TMagicButton, TMagicCard, getDesignConfig, TMagicSelect, useZIndex, tMagicMessage, tMagicMessageBox, TMagicCascader, TMagicTooltip, TMagicTag, TMagicDialog, TMagicSwitch, TMagicInput, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicPopover, TMagicScrollbar, TMagicCollapse, TMagicCollapseItem } from '@tmagic/design';
2
2
  export * from '@tmagic/design';
3
3
  export { default as designPlugin } from '@tmagic/design';
4
- import formPlugin__default, { MContainer, MForm, filterFunction, createValues, MFormBox, MSelect, MGroupList, MPanel } from '@tmagic/form';
4
+ import formPlugin__default, { MContainer, MForm, filterFunction, createValues, MFormBox, MSelect, MGroupList, MPanel, createForm } from '@tmagic/form';
5
5
  export * from '@tmagic/form';
6
6
  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';
11
- import { Edit, FullScreen, View, Close, Coin, Delete, Plus, ArrowDown, ArrowLeftBold, ArrowRightBold, Files, CaretBottom, DocumentCopy, Grid, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Document, Search, 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';
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
+ 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, 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, dataSourceTemplateRegExp, getKeysArray, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getKeys, convertToNumber, getIdFromEl, getDefaultValueFromFields, DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, removeClassName, addClassName, removeClassNameByClassName } 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,10 +23,11 @@ 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
 
29
- const _hoisted_1$w = ["src"];
30
+ const _hoisted_1$x = ["src"];
30
31
  const _sfc_main$Y = /* @__PURE__ */ defineComponent({
31
32
  ...{
32
33
  name: "MEditorIcon"
@@ -51,7 +52,7 @@ const _sfc_main$Y = /* @__PURE__ */ defineComponent({
51
52
  class: "magic-editor-icon"
52
53
  }, {
53
54
  default: withCtx(() => [
54
- createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$w)
55
+ createElementVNode("img", { src: _ctx.icon }, null, 8, _hoisted_1$x)
55
56
  ]),
56
57
  _: 1
57
58
  })) : typeof _ctx.icon === "string" ? (openBlock(), createElementBlock("i", {
@@ -79,7 +80,7 @@ const getEditorConfig = (key) => $TMAGIC_EDITOR[key];
79
80
  emmetHTML(monaco);
80
81
  emmetCSS(monaco, ["css", "scss"]);
81
82
 
82
- const _hoisted_1$v = {
83
+ const _hoisted_1$w = {
83
84
  class: /* @__PURE__ */ normalizeClass(`magic-code-editor`)
84
85
  };
85
86
  const _sfc_main$X = /* @__PURE__ */ defineComponent({
@@ -239,7 +240,7 @@ const _sfc_main$X = /* @__PURE__ */ defineComponent({
239
240
  }
240
241
  });
241
242
  return (_ctx, _cache) => {
242
- return openBlock(), createElementBlock("div", _hoisted_1$v, [
243
+ return openBlock(), createElementBlock("div", _hoisted_1$w, [
243
244
  (openBlock(), createBlock(Teleport, {
244
245
  to: "body",
245
246
  disabled: !fullScreen.value
@@ -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",
@@ -1147,15 +1146,6 @@ const serializeConfig = (config) => serialize(config, {
1147
1146
  space: 2,
1148
1147
  unsafe: true
1149
1148
  }).replace(/"(\w+)":\s/g, "$1: ");
1150
- const traverseNode = (node, cb, parents = []) => {
1151
- cb(node, parents);
1152
- if (Array.isArray(node.items) && node.items.length) {
1153
- parents.push(node);
1154
- node.items.forEach((item) => {
1155
- traverseNode(item, cb, [...parents]);
1156
- });
1157
- }
1158
- };
1159
1149
  const moveItemsInContainer = (sourceIndices, parent, targetIndex) => {
1160
1150
  sourceIndices.sort((a, b) => a - b);
1161
1151
  for (let i = sourceIndices.length - 1; i >= 0; i--) {
@@ -1172,6 +1162,55 @@ const moveItemsInContainer = (sourceIndices, parent, targetIndex) => {
1172
1162
  }
1173
1163
  }
1174
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
+ };
1175
1214
 
1176
1215
  const compose = (middleware, isAsync) => {
1177
1216
  if (!Array.isArray(middleware)) throw new TypeError("Middleware 必须是一个数组!");
@@ -1877,28 +1916,7 @@ class Editor extends BaseService {
1877
1916
  if (raw) {
1878
1917
  root = toRaw(root);
1879
1918
  }
1880
- const info = {
1881
- node: null,
1882
- parent: null,
1883
- page: null
1884
- };
1885
- if (!root) return info;
1886
- if (id === root.id) {
1887
- info.node = root;
1888
- return info;
1889
- }
1890
- const path = getNodePath(id, root.items);
1891
- if (!path.length) return info;
1892
- path.unshift(root);
1893
- info.node = path[path.length - 1];
1894
- info.parent = path[path.length - 2];
1895
- path.forEach((item) => {
1896
- if (isPage(item) || isPageFragment(item)) {
1897
- info.page = item;
1898
- return;
1899
- }
1900
- });
1901
- return info;
1919
+ return getNodeInfo(id, root);
1902
1920
  }
1903
1921
  /**
1904
1922
  * 根据ID获取指点节点配置
@@ -2119,10 +2137,10 @@ class Editor extends BaseService {
2119
2137
  const rootItems = root.items || [];
2120
2138
  if (isPage(node)) {
2121
2139
  this.state.pageLength -= 1;
2122
- await selectDefault(getPageList(root));
2140
+ await selectDefault(rootItems);
2123
2141
  } else if (isPageFragment(node)) {
2124
2142
  this.state.pageFragmentLength -= 1;
2125
- await selectDefault(getPageFragmentList(root));
2143
+ await selectDefault(rootItems);
2126
2144
  } else {
2127
2145
  await this.select(parent);
2128
2146
  stage?.select(parent.id);
@@ -2145,13 +2163,13 @@ class Editor extends BaseService {
2145
2163
  }
2146
2164
  this.emit("remove", nodes);
2147
2165
  }
2148
- async doUpdate(config) {
2166
+ async doUpdate(config, { changeRecords = [] } = {}) {
2149
2167
  const root = this.get("root");
2150
2168
  if (!root) throw new Error("root为空");
2151
2169
  if (!config?.id) throw new Error("没有配置或者配置缺少id值");
2152
2170
  const info = this.getNodeInfo(config.id, false);
2153
2171
  if (!info.node) throw new Error(`获取不到id为${config.id}的节点`);
2154
- const node = cloneDeep(toRaw(info.node));
2172
+ const node = toRaw(info.node);
2155
2173
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, root);
2156
2174
  newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue, key) => {
2157
2175
  if (typeof srcValue === "undefined" && Object.hasOwn(newConfig, key)) {
@@ -2167,7 +2185,11 @@ class Editor extends BaseService {
2167
2185
  if (!newConfig.type) throw new Error("配置缺少type值");
2168
2186
  if (newConfig.type === NodeType.ROOT) {
2169
2187
  this.set("root", newConfig);
2170
- return newConfig;
2188
+ return {
2189
+ oldNode: node,
2190
+ newNode: newConfig,
2191
+ changeRecords
2192
+ };
2171
2193
  }
2172
2194
  const { parent } = info;
2173
2195
  if (!parent) throw new Error("获取不到父级节点");
@@ -2184,30 +2206,29 @@ class Editor extends BaseService {
2184
2206
  const targetIndex = nodes.findIndex((nodeItem) => `${nodeItem.id}` === `${newConfig.id}`);
2185
2207
  nodes.splice(targetIndex, 1, newConfig);
2186
2208
  this.set("nodes", [...nodes]);
2187
- this.get("stage")?.update({
2188
- config: cloneDeep(newConfig),
2189
- parentId: parent.id,
2190
- root: cloneDeep(root)
2191
- });
2192
2209
  if (isPage(newConfig) || isPageFragment(newConfig)) {
2193
2210
  this.set("page", newConfig);
2194
2211
  }
2195
2212
  this.addModifiedNodeId(newConfig.id);
2196
- return newConfig;
2213
+ return {
2214
+ oldNode: node,
2215
+ newNode: newConfig,
2216
+ changeRecords
2217
+ };
2197
2218
  }
2198
2219
  /**
2199
2220
  * 更新节点
2200
2221
  * @param config 新的节点配置,配置中需要有id信息
2201
2222
  * @returns 更新后的节点配置
2202
2223
  */
2203
- async update(config) {
2224
+ async update(config, data = {}) {
2204
2225
  const nodes = Array.isArray(config) ? config : [config];
2205
- const newNodes = await Promise.all(nodes.map((node) => this.doUpdate(node)));
2206
- 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) {
2207
2228
  this.pushHistoryState();
2208
2229
  }
2209
- this.emit("update", newNodes);
2210
- 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;
2211
2232
  }
2212
2233
  /**
2213
2234
  * 将id为id1的组件移动到id为id2的组件位置上,例如:[1,2,3,4] -> sort(1,3) -> [2,1,3,4]
@@ -2401,7 +2422,7 @@ class Editor extends BaseService {
2401
2422
  parent.items?.splice(index, 1);
2402
2423
  await stage.remove({ id: node.id, parentId: parent.id, root: cloneDeep(root) });
2403
2424
  const layout = await this.getLayout(target);
2404
- const newConfig = mergeWith(cloneDeep(node), config, (objValue, srcValue) => {
2425
+ const newConfig = mergeWith(cloneDeep(node), config, (_objValue, srcValue) => {
2405
2426
  if (Array.isArray(srcValue)) {
2406
2427
  return srcValue;
2407
2428
  }
@@ -2410,7 +2431,11 @@ class Editor extends BaseService {
2410
2431
  target.items.push(newConfig);
2411
2432
  await stage.select(targetId);
2412
2433
  const targetParent = this.getParentById(target.id);
2413
- await stage.update({ config: cloneDeep(target), parentId: targetParent?.id, root: cloneDeep(root) });
2434
+ await stage.update({
2435
+ config: cloneDeep(target),
2436
+ parentId: targetParent?.id,
2437
+ root: cloneDeep(root)
2438
+ });
2414
2439
  await this.select(newConfig);
2415
2440
  stage.select(newConfig.id);
2416
2441
  this.addModifiedNodeId(target.id);
@@ -2763,6 +2788,7 @@ const HttpFormConfig = [
2763
2788
  name: "params",
2764
2789
  type: "key-value",
2765
2790
  defaultValue: {},
2791
+ advanced: true,
2766
2792
  text: "参数"
2767
2793
  },
2768
2794
  {
@@ -2776,6 +2802,7 @@ const HttpFormConfig = [
2776
2802
  name: "headers",
2777
2803
  type: "key-value",
2778
2804
  defaultValue: {},
2805
+ advanced: true,
2779
2806
  text: "请求头"
2780
2807
  }
2781
2808
  ]
@@ -2830,7 +2857,7 @@ const fillConfig = (config) => [
2830
2857
  },
2831
2858
  {
2832
2859
  title: "请求参数裁剪",
2833
- display: (formState, { model }) => model.type === "http",
2860
+ display: (_formState, { model }) => model.type === "http",
2834
2861
  items: [
2835
2862
  {
2836
2863
  name: "beforeRequest",
@@ -2842,7 +2869,7 @@ const fillConfig = (config) => [
2842
2869
  },
2843
2870
  {
2844
2871
  title: "响应数据裁剪",
2845
- display: (formState, { model }) => model.type === "http",
2872
+ display: (_formState, { model }) => model.type === "http",
2846
2873
  items: [
2847
2874
  {
2848
2875
  name: "afterResponse",
@@ -3009,6 +3036,10 @@ globalThis.requestIdleCallback = globalThis.requestIdleCallback || function(cb)
3009
3036
  class IdleTask extends EventEmitter {
3010
3037
  taskList = [];
3011
3038
  taskHandle = null;
3039
+ constructor() {
3040
+ super();
3041
+ this.setMaxListeners(1e3);
3042
+ }
3012
3043
  enqueueTask(taskHandler, taskData) {
3013
3044
  this.taskList.push({
3014
3045
  handler: taskHandler,
@@ -3018,6 +3049,9 @@ class IdleTask extends EventEmitter {
3018
3049
  this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
3019
3050
  }
3020
3051
  }
3052
+ clearTasks() {
3053
+ this.taskList = [];
3054
+ }
3021
3055
  on(eventName, listener) {
3022
3056
  return super.on(eventName, listener);
3023
3057
  }
@@ -3028,12 +3062,30 @@ class IdleTask extends EventEmitter {
3028
3062
  return super.emit(eventName, ...args);
3029
3063
  }
3030
3064
  runTaskQueue(deadline) {
3031
- while ((deadline.timeRemaining() > 15 || deadline.didTimeout) && this.taskList.length) {
3032
- const task = this.taskList.shift();
3033
- 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
+ }
3034
3086
  }
3035
3087
  if (this.taskList.length) {
3036
- this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 1e4 });
3088
+ this.taskHandle = globalThis.requestIdleCallback(this.runTaskQueue.bind(this), { timeout: 300 });
3037
3089
  } else {
3038
3090
  this.taskHandle = 0;
3039
3091
  this.emit("finish");
@@ -3215,10 +3267,10 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
3215
3267
  }))
3216
3268
  )
3217
3269
  );
3218
- const onParamsChangeHandler = async () => {
3270
+ const onParamsChangeHandler = async (v, eventData) => {
3219
3271
  try {
3220
3272
  const value = await form.value?.submitForm(true);
3221
- emit("change", value);
3273
+ emit("change", value, eventData);
3222
3274
  } catch (e) {
3223
3275
  error(e);
3224
3276
  }
@@ -3238,8 +3290,8 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
3238
3290
  }
3239
3291
  });
3240
3292
 
3241
- const _hoisted_1$u = { class: "m-fields-code-select-col" };
3242
- const _hoisted_2$g = { class: "code-select-container" };
3293
+ const _hoisted_1$v = { class: "m-fields-code-select-col" };
3294
+ const _hoisted_2$h = { class: "code-select-container" };
3243
3295
  const _sfc_main$S = /* @__PURE__ */ defineComponent({
3244
3296
  ...{
3245
3297
  name: "MFieldsCodeSelectCol"
@@ -3311,22 +3363,39 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
3311
3363
  return codeId;
3312
3364
  }
3313
3365
  };
3314
- const onParamsChangeHandler = (value) => {
3366
+ const onCodeIdChangeHandler = (value) => {
3315
3367
  props.model.params = value.params;
3316
- 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
+ });
3317
3386
  };
3318
3387
  const editCode = (id) => {
3319
3388
  eventBus?.emit("edit-code", id);
3320
3389
  };
3321
3390
  return (_ctx, _cache) => {
3322
- return openBlock(), createElementBlock("div", _hoisted_1$u, [
3323
- createElementVNode("div", _hoisted_2$g, [
3391
+ return openBlock(), createElementBlock("div", _hoisted_1$v, [
3392
+ createElementVNode("div", _hoisted_2$h, [
3324
3393
  createVNode(unref(MContainer), {
3325
3394
  class: "select",
3326
3395
  config: selectConfig,
3327
3396
  model: _ctx.model,
3328
3397
  size: _ctx.size,
3329
- onChange: onParamsChangeHandler
3398
+ onChange: onCodeIdChangeHandler
3330
3399
  }, null, 8, ["model", "size"]),
3331
3400
  _ctx.model[_ctx.name] && hasCodeBlockSidePanel.value ? (openBlock(), createBlock(unref(TMagicButton), {
3332
3401
  key: 0,
@@ -3625,7 +3694,7 @@ const useCodeBlockEdit = (codeBlockService) => {
3625
3694
  }
3626
3695
  codeConfig.value = {
3627
3696
  name: "",
3628
- content: `({app, params}) => {
3697
+ content: `({app, params, flowState}) => {
3629
3698
  // place your code here
3630
3699
  }`,
3631
3700
  params: []
@@ -3671,78 +3740,6 @@ const useCodeBlockEdit = (codeBlockService) => {
3671
3740
  };
3672
3741
  };
3673
3742
 
3674
- const useDataSourceMethod = () => {
3675
- const codeConfig = ref();
3676
- const codeBlockEditor = ref();
3677
- const dataSource = ref();
3678
- const dataSourceMethod = ref("");
3679
- return {
3680
- codeConfig,
3681
- codeBlockEditor,
3682
- createCode: async (model) => {
3683
- codeConfig.value = {
3684
- name: "",
3685
- content: `({ params, dataSource, app }) => {
3686
- // place your code here
3687
- }`,
3688
- params: []
3689
- };
3690
- await nextTick();
3691
- dataSource.value = model;
3692
- dataSourceMethod.value = "";
3693
- codeBlockEditor.value?.show();
3694
- },
3695
- editCode: async (model, methodName) => {
3696
- const method = model.methods?.find((method2) => method2.name === methodName);
3697
- if (!method) {
3698
- tMagicMessage.error("获取数据源方法失败");
3699
- return;
3700
- }
3701
- let codeContent = method.content || `({ params, dataSource, app }) => {
3702
- // place your code here
3703
- }`;
3704
- if (typeof codeContent !== "string") {
3705
- codeContent = codeContent.toString();
3706
- }
3707
- codeConfig.value = {
3708
- ...cloneDeep(method),
3709
- content: codeContent
3710
- };
3711
- await nextTick();
3712
- dataSource.value = model;
3713
- dataSourceMethod.value = methodName;
3714
- codeBlockEditor.value?.show();
3715
- },
3716
- deleteCode: async (model, methodName) => {
3717
- if (!model.methods) return;
3718
- const index = model.methods.findIndex((method) => method.name === methodName);
3719
- if (index === -1) {
3720
- return;
3721
- }
3722
- model.methods.splice(index, 1);
3723
- },
3724
- submitCode: (values) => {
3725
- if (!dataSource.value) return;
3726
- if (!dataSource.value.methods) {
3727
- dataSource.value.methods = [];
3728
- }
3729
- if (values.content) {
3730
- const parseDSL = getEditorConfig("parseDSL");
3731
- if (typeof values.content === "string") {
3732
- values.content = parseDSL(values.content);
3733
- }
3734
- }
3735
- if (dataSourceMethod.value) {
3736
- const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
3737
- dataSource.value.methods.splice(index, 1, values);
3738
- } else {
3739
- dataSource.value.methods.push(values);
3740
- }
3741
- codeBlockEditor.value?.hide();
3742
- }
3743
- };
3744
- };
3745
-
3746
3743
  const state = reactive({
3747
3744
  uiSelectMode: false,
3748
3745
  showSrc: false,
@@ -4190,8 +4187,8 @@ const useNodeStatus$1 = (nodeData) => {
4190
4187
  };
4191
4188
  };
4192
4189
 
4193
- const _hoisted_1$t = { class: "m-editor-data-source-fields" };
4194
- const _hoisted_2$f = { class: "m-editor-data-source-fields-footer" };
4190
+ const _hoisted_1$u = { class: "m-editor-data-source-fields" };
4191
+ const _hoisted_2$g = { class: "m-editor-data-source-fields-footer" };
4195
4192
  const _sfc_main$P = /* @__PURE__ */ defineComponent({
4196
4193
  ...{
4197
4194
  name: "MFieldsDataSourceFields"
@@ -4229,14 +4226,28 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4229
4226
  calcBoxPosition();
4230
4227
  addDialogVisible.value = true;
4231
4228
  };
4232
- const fieldChange = ({ index, ...value }) => {
4229
+ const fieldChange = ({ index, ...value }, data) => {
4230
+ addDialogVisible.value = false;
4233
4231
  if (index > -1) {
4234
- 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
+ });
4235
4239
  } else {
4236
- 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
+ });
4237
4250
  }
4238
- addDialogVisible.value = false;
4239
- emit("change", props.model[props.name]);
4240
4251
  };
4241
4252
  const fieldColumns = [
4242
4253
  {
@@ -4430,9 +4441,8 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4430
4441
  const addFromJsonFromChange = ({ data }) => {
4431
4442
  try {
4432
4443
  const value = JSON.parse(data);
4433
- props.model[props.name] = getFieldsConfig(value, props.model[props.name]);
4434
4444
  addFromJsonDialogVisible.value = false;
4435
- emit("change", props.model[props.name]);
4445
+ emit("change", getFieldsConfig(value, props.model[props.name]));
4436
4446
  } catch (e) {
4437
4447
  tMagicMessage.error(e.message);
4438
4448
  }
@@ -4443,12 +4453,12 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4443
4453
  const parentFloating = inject("parentFloating", ref(null));
4444
4454
  const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
4445
4455
  return (_ctx, _cache) => {
4446
- return openBlock(), createElementBlock("div", _hoisted_1$t, [
4456
+ return openBlock(), createElementBlock("div", _hoisted_1$u, [
4447
4457
  createVNode(unref(MagicTable), {
4448
4458
  data: _ctx.model[_ctx.name],
4449
4459
  columns: fieldColumns
4450
4460
  }, null, 8, ["data"]),
4451
- createElementVNode("div", _hoisted_2$f, [
4461
+ createElementVNode("div", _hoisted_2$g, [
4452
4462
  createVNode(unref(TMagicButton), {
4453
4463
  size: "small",
4454
4464
  disabled: _ctx.disabled,
@@ -4521,7 +4531,7 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
4521
4531
  }
4522
4532
  });
4523
4533
 
4524
- const _hoisted_1$s = { class: "m-editor-data-source-field-select" };
4534
+ const _hoisted_1$t = { class: "m-editor-data-source-field-select" };
4525
4535
  const _sfc_main$O = /* @__PURE__ */ defineComponent({
4526
4536
  __name: "FieldSelect",
4527
4537
  props: /* @__PURE__ */ mergeModels({
@@ -4603,7 +4613,7 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
4603
4613
  eventBus?.emit("edit-data-source", removeDataSourceFieldPrefix(id));
4604
4614
  };
4605
4615
  return (_ctx, _cache) => {
4606
- return openBlock(), createElementBlock("div", _hoisted_1$s, [
4616
+ return openBlock(), createElementBlock("div", _hoisted_1$t, [
4607
4617
  _ctx.checkStrictly ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
4608
4618
  createVNode(unref(TMagicSelect), {
4609
4619
  "model-value": selectDataSourceId.value,
@@ -4685,7 +4695,7 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
4685
4695
  }
4686
4696
  });
4687
4697
 
4688
- const _hoisted_1$r = { class: "m-fields-data-source-field-select" };
4698
+ const _hoisted_1$s = { class: "m-fields-data-source-field-select" };
4689
4699
  const _sfc_main$N = /* @__PURE__ */ defineComponent({
4690
4700
  ...{
4691
4701
  name: "MFieldsDataSourceFieldSelect"
@@ -4787,7 +4797,7 @@ const _sfc_main$N = /* @__PURE__ */ defineComponent({
4787
4797
  }
4788
4798
  };
4789
4799
  return (_ctx, _cache) => {
4790
- return openBlock(), createElementBlock("div", _hoisted_1$r, [
4800
+ return openBlock(), createElementBlock("div", _hoisted_1$s, [
4791
4801
  showDataSourceFieldSelect.value || !_ctx.config.fieldConfig ? (openBlock(), createBlock(_sfc_main$O, {
4792
4802
  key: 0,
4793
4803
  "model-value": _ctx.model[_ctx.name],
@@ -4835,8 +4845,8 @@ const _sfc_main$N = /* @__PURE__ */ defineComponent({
4835
4845
  }
4836
4846
  });
4837
4847
 
4838
- const _hoisted_1$q = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
4839
- const _hoisted_2$e = { style: { "font-size": "10px", "color": "rgba(0, 0, 0, 0.6)" } };
4848
+ const _hoisted_1$r = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
4849
+ const _hoisted_2$f = { style: { "font-size": "10px", "color": "rgba(0, 0, 0, 0.6)" } };
4840
4850
  const _hoisted_3$4 = { class: "el-input__inner t-input__inner" };
4841
4851
  const _sfc_main$M = /* @__PURE__ */ defineComponent({
4842
4852
  ...{
@@ -5041,9 +5051,9 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
5041
5051
  createVNode(_sfc_main$Y, { icon: unref(Coin) }, null, 8, ["icon"])
5042
5052
  ]),
5043
5053
  default: withCtx(({ item }) => [
5044
- createElementVNode("div", _hoisted_1$q, [
5054
+ createElementVNode("div", _hoisted_1$r, [
5045
5055
  createElementVNode("div", null, toDisplayString(item.text), 1),
5046
- createElementVNode("span", _hoisted_2$e, toDisplayString(item.value), 1)
5056
+ createElementVNode("span", _hoisted_2$f, toDisplayString(item.value), 1)
5047
5057
  ])
5048
5058
  ]),
5049
5059
  _: 1
@@ -5084,8 +5094,8 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
5084
5094
  }
5085
5095
  });
5086
5096
 
5087
- const _hoisted_1$p = { style: { "display": "flex", "margin-bottom": "10px" } };
5088
- const _hoisted_2$d = { style: { "flex": "1" } };
5097
+ const _hoisted_1$q = { style: { "display": "flex", "margin-bottom": "10px" } };
5098
+ const _hoisted_2$e = { style: { "flex": "1" } };
5089
5099
  const _hoisted_3$3 = { style: { "flex": "1" } };
5090
5100
  const _hoisted_4$3 = { class: "dialog-footer" };
5091
5101
  const _sfc_main$L = /* @__PURE__ */ defineComponent({
@@ -5216,9 +5226,9 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5216
5226
  }
5217
5227
  }
5218
5228
  ]);
5219
- const submitForm = (values) => {
5229
+ const submitForm = (values, data) => {
5220
5230
  changedValue.value = void 0;
5221
- emit("submit", values);
5231
+ emit("submit", values, data);
5222
5232
  };
5223
5233
  const errorHandler = (error) => {
5224
5234
  tMagicMessage.error(error.message);
@@ -5239,7 +5249,7 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5239
5249
  type: "warning",
5240
5250
  distinguishCancelAndClose: true
5241
5251
  }).then(() => {
5242
- changedValue.value && submitForm(changedValue.value);
5252
+ changedValue.value && submitForm(changedValue.value, { changeRecords: formBox.value?.form?.changeRecords });
5243
5253
  done();
5244
5254
  }).catch((action) => {
5245
5255
  done(action === "cancel");
@@ -5338,8 +5348,8 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5338
5348
  ])
5339
5349
  ]),
5340
5350
  default: withCtx(() => [
5341
- createElementVNode("div", _hoisted_1$p, [
5342
- createElementVNode("div", _hoisted_2$d, [
5351
+ createElementVNode("div", _hoisted_1$q, [
5352
+ createElementVNode("div", _hoisted_2$e, [
5343
5353
  createVNode(unref(TMagicTag), {
5344
5354
  size: "small",
5345
5355
  type: "info"
@@ -5381,8 +5391,8 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
5381
5391
  }
5382
5392
  });
5383
5393
 
5384
- const _hoisted_1$o = { class: "m-editor-data-source-methods" };
5385
- const _hoisted_2$c = { class: "m-editor-data-source-methods-footer" };
5394
+ const _hoisted_1$p = { class: "m-editor-data-source-methods" };
5395
+ const _hoisted_2$d = { class: "m-editor-data-source-methods-footer" };
5386
5396
  const _sfc_main$K = /* @__PURE__ */ defineComponent({
5387
5397
  ...{
5388
5398
  name: "MFieldsDataSourceMethods"
@@ -5403,7 +5413,9 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5403
5413
  setup(__props, { emit: __emit }) {
5404
5414
  const props = __props;
5405
5415
  const emit = __emit;
5406
- const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
5416
+ const codeConfig = ref();
5417
+ const codeBlockEditor = ref();
5418
+ let editIndex = -1;
5407
5419
  const methodColumns = [
5408
5420
  {
5409
5421
  label: "名称",
@@ -5428,16 +5440,29 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5428
5440
  actions: [
5429
5441
  {
5430
5442
  text: "编辑",
5431
- handler: (row) => {
5432
- editCode(props.model, row.name);
5433
- 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
+ });
5434
5458
  }
5435
5459
  },
5436
5460
  {
5437
5461
  text: "删除",
5438
5462
  buttonType: "danger",
5439
- handler: (row) => {
5440
- deleteCode(props.model, row.name);
5463
+ handler: async (row, index) => {
5464
+ await tMagicMessageBox.confirm(`确定删除${row.name}?`, "提示");
5465
+ props.model[props.name].splice(index, 1);
5441
5466
  emit("change", props.model[props.name]);
5442
5467
  }
5443
5468
  }
@@ -5445,20 +5470,56 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5445
5470
  }
5446
5471
  ];
5447
5472
  const createCodeHandler = () => {
5448
- createCode(props.model);
5449
- 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
+ });
5450
5484
  };
5451
- const submitCodeHandler = (values) => {
5452
- submitCode(values);
5453
- 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();
5454
5515
  };
5455
5516
  return (_ctx, _cache) => {
5456
- return openBlock(), createElementBlock("div", _hoisted_1$o, [
5517
+ return openBlock(), createElementBlock("div", _hoisted_1$p, [
5457
5518
  createVNode(unref(MagicTable), {
5458
5519
  data: _ctx.model[_ctx.name],
5459
5520
  columns: methodColumns
5460
5521
  }, null, 8, ["data"]),
5461
- createElementVNode("div", _hoisted_2$c, [
5522
+ createElementVNode("div", _hoisted_2$d, [
5462
5523
  createVNode(unref(TMagicButton), {
5463
5524
  size: "small",
5464
5525
  type: "primary",
@@ -5472,12 +5533,12 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5472
5533
  _: 1
5473
5534
  }, 8, ["disabled"])
5474
5535
  ]),
5475
- unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$L, {
5536
+ codeConfig.value ? (openBlock(), createBlock(_sfc_main$L, {
5476
5537
  key: 0,
5477
5538
  ref_key: "codeBlockEditor",
5478
5539
  ref: codeBlockEditor,
5479
5540
  disabled: _ctx.disabled,
5480
- content: unref(codeConfig),
5541
+ content: codeConfig.value,
5481
5542
  "is-data-source": true,
5482
5543
  "data-source-type": _ctx.model.type,
5483
5544
  onSubmit: submitCodeHandler
@@ -5487,8 +5548,8 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
5487
5548
  }
5488
5549
  });
5489
5550
 
5490
- const _hoisted_1$n = { class: "m-fields-data-source-method-select" };
5491
- const _hoisted_2$b = { class: "data-source-method-select-container" };
5551
+ const _hoisted_1$o = { class: "m-fields-data-source-method-select" };
5552
+ const _hoisted_2$c = { class: "data-source-method-select-container" };
5492
5553
  const _sfc_main$J = /* @__PURE__ */ defineComponent({
5493
5554
  ...{
5494
5555
  name: "MFieldsDataSourceMethodSelect"
@@ -5575,8 +5636,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
5575
5636
  eventBus?.emit("edit-data-source", id);
5576
5637
  };
5577
5638
  return (_ctx, _cache) => {
5578
- return openBlock(), createElementBlock("div", _hoisted_1$n, [
5579
- createElementVNode("div", _hoisted_2$b, [
5639
+ return openBlock(), createElementBlock("div", _hoisted_1$o, [
5640
+ createElementVNode("div", _hoisted_2$c, [
5580
5641
  createVNode(unref(MContainer), {
5581
5642
  class: "select",
5582
5643
  config: cascaderConfig.value,
@@ -5619,8 +5680,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
5619
5680
  }
5620
5681
  });
5621
5682
 
5622
- const _hoisted_1$m = { class: "m-editor-data-source-fields" };
5623
- const _hoisted_2$a = { class: "m-editor-data-source-fields-footer" };
5683
+ const _hoisted_1$n = { class: "m-editor-data-source-fields" };
5684
+ const _hoisted_2$b = { class: "m-editor-data-source-fields-footer" };
5624
5685
  const _sfc_main$I = /* @__PURE__ */ defineComponent({
5625
5686
  ...{
5626
5687
  name: "MFieldsDataSourceMocks"
@@ -5825,12 +5886,12 @@ const _sfc_main$I = /* @__PURE__ */ defineComponent({
5825
5886
  const parentFloating = inject("parentFloating", ref(null));
5826
5887
  const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
5827
5888
  return (_ctx, _cache) => {
5828
- return openBlock(), createElementBlock("div", _hoisted_1$m, [
5889
+ return openBlock(), createElementBlock("div", _hoisted_1$n, [
5829
5890
  createVNode(unref(MagicTable), {
5830
5891
  data: _ctx.model[_ctx.name],
5831
5892
  columns
5832
5893
  }, null, 8, ["data"]),
5833
- createElementVNode("div", _hoisted_2$a, [
5894
+ createElementVNode("div", _hoisted_2$b, [
5834
5895
  createVNode(unref(TMagicButton), {
5835
5896
  size: "small",
5836
5897
  type: "primary",
@@ -5872,7 +5933,7 @@ const _sfc_main$I = /* @__PURE__ */ defineComponent({
5872
5933
  }
5873
5934
  });
5874
5935
 
5875
- const _hoisted_1$l = { class: "m-fields-data-source-select" };
5936
+ const _hoisted_1$m = { class: "m-fields-data-source-select" };
5876
5937
  const _sfc_main$H = /* @__PURE__ */ defineComponent({
5877
5938
  ...{
5878
5939
  name: "MFieldsDataSourceSelect"
@@ -5930,7 +5991,7 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
5930
5991
  eventBus?.emit("edit-data-source", id);
5931
5992
  };
5932
5993
  return (_ctx, _cache) => {
5933
- return openBlock(), createElementBlock("div", _hoisted_1$l, [
5994
+ return openBlock(), createElementBlock("div", _hoisted_1$m, [
5934
5995
  createVNode(unref(MSelect), {
5935
5996
  model: _ctx.model,
5936
5997
  name: _ctx.name,
@@ -6075,8 +6136,11 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
6075
6136
  }
6076
6137
  ]
6077
6138
  }));
6078
- const changeHandler = (v) => {
6079
- 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);
6080
6144
  };
6081
6145
  return (_ctx, _cache) => {
6082
6146
  return openBlock(), createBlock(unref(MGroupList), {
@@ -6094,8 +6158,8 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
6094
6158
  }
6095
6159
  });
6096
6160
 
6097
- const _hoisted_1$k = { class: "m-fields-event-select" };
6098
- const _hoisted_2$9 = {
6161
+ const _hoisted_1$l = { class: "m-fields-event-select" };
6162
+ const _hoisted_2$a = {
6099
6163
  key: 1,
6100
6164
  class: "fullWidth"
6101
6165
  };
@@ -6147,7 +6211,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6147
6211
  if (pageFragment) {
6148
6212
  events = [
6149
6213
  {
6150
- label: pageFragment.name || "迭代器容器",
6214
+ label: pageFragment.name || "页面片容器",
6151
6215
  value: pageFragment.id,
6152
6216
  children: events
6153
6217
  }
@@ -6360,20 +6424,22 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6360
6424
  if (!props.model[props.name]) {
6361
6425
  props.model[props.name] = [];
6362
6426
  }
6363
- props.model[props.name].push(defaultEvent);
6364
- onChangeHandler();
6427
+ emit("change", defaultEvent, {
6428
+ modifyKey: props.model[props.name].length
6429
+ });
6365
6430
  };
6366
6431
  const removeEvent = (index) => {
6367
6432
  if (!props.name) return;
6368
6433
  props.model[props.name].splice(index, 1);
6369
- onChangeHandler();
6434
+ emit("change", props.model[props.name]);
6370
6435
  };
6371
- const onChangeHandler = () => {
6372
- emit("change", props.model);
6436
+ const eventNameChangeHandler = (v, eventData) => {
6437
+ emit("change", props.model[props.name], eventData);
6373
6438
  };
6439
+ const onChangeHandler = (v, eventData) => emit("change", props.model[props.name], eventData);
6374
6440
  return (_ctx, _cache) => {
6375
6441
  const _component_m_form_table = resolveComponent("m-form-table");
6376
- return openBlock(), createElementBlock("div", _hoisted_1$k, [
6442
+ return openBlock(), createElementBlock("div", _hoisted_1$l, [
6377
6443
  isOldVersion.value ? (openBlock(), createBlock(_component_m_form_table, {
6378
6444
  key: 0,
6379
6445
  ref: "eventForm",
@@ -6383,7 +6449,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6383
6449
  model: _ctx.model,
6384
6450
  config: tableConfig.value,
6385
6451
  onChange: onChangeHandler
6386
- }, null, 8, ["size", "disabled", "model", "config"])) : (openBlock(), createElementBlock("div", _hoisted_2$9, [
6452
+ }, null, 8, ["size", "disabled", "model", "config"])) : (openBlock(), createElementBlock("div", _hoisted_2$a, [
6387
6453
  createVNode(unref(TMagicButton), {
6388
6454
  class: "create-button",
6389
6455
  type: "primary",
@@ -6401,6 +6467,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6401
6467
  key: index,
6402
6468
  disabled: _ctx.disabled,
6403
6469
  size: _ctx.size,
6470
+ prop: `${_ctx.prop}.${index}`,
6404
6471
  config: actionsConfig.value,
6405
6472
  model: cardItem,
6406
6473
  "label-width": _ctx.config.labelWidth || "100px",
@@ -6413,8 +6480,9 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6413
6480
  model: cardItem,
6414
6481
  disabled: _ctx.disabled,
6415
6482
  size: _ctx.size,
6416
- onChange: onChangeHandler
6417
- }, null, 8, ["config", "model", "disabled", "size"]),
6483
+ prop: `${_ctx.prop}.${index}`,
6484
+ onChange: eventNameChangeHandler
6485
+ }, null, 8, ["config", "model", "disabled", "size", "prop"]),
6418
6486
  createVNode(unref(TMagicButton), {
6419
6487
  style: { "color": "#f56c6c" },
6420
6488
  link: "",
@@ -6425,7 +6493,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6425
6493
  }, null, 8, ["icon", "disabled", "size", "onClick"])
6426
6494
  ]),
6427
6495
  _: 2
6428
- }, 1032, ["disabled", "size", "config", "model", "label-width"]);
6496
+ }, 1032, ["disabled", "size", "prop", "config", "model", "label-width"]);
6429
6497
  }), 128))
6430
6498
  ]))
6431
6499
  ]);
@@ -6433,7 +6501,7 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
6433
6501
  }
6434
6502
  });
6435
6503
 
6436
- const _hoisted_1$j = {
6504
+ const _hoisted_1$k = {
6437
6505
  viewBox: "0 0 32 32",
6438
6506
  version: "1.1",
6439
6507
  xmlns: "http://www.w3.org/2000/svg",
@@ -6446,15 +6514,15 @@ const _sfc_main$E = /* @__PURE__ */ defineComponent({
6446
6514
  __name: "CodeIcon",
6447
6515
  setup(__props) {
6448
6516
  return (_ctx, _cache) => {
6449
- return openBlock(), createElementBlock("svg", _hoisted_1$j, _cache[0] || (_cache[0] = [
6517
+ return openBlock(), createElementBlock("svg", _hoisted_1$k, _cache[0] || (_cache[0] = [
6450
6518
  createStaticVNode('<defs><rect id="path-1" x="0" y="0" width="32" height="32"></rect></defs><g id="组件规范" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="03图标" transform="translate(-561.000000, -2356.000000)"><g id="icon/line/Universal/code" transform="translate(561.000000, 2356.000000)"><g id="路径"><mask id="mask-2" fill="white"><use xlink:href="#path-1"></use></mask><use id="蒙版" fill="#D8D8D8" opacity="0" xlink:href="#path-1"></use><path d="M21.9284587,7.9482233 L29.8079004,15.827665 C29.9055315,15.9252961 29.9055315,16.0835874 29.8079004,16.1812184 L21.9284587,24.0606602 C21.8308276,24.1582912 21.6725364,24.1582912 21.5749053,24.0606602 L20.3374684,22.8232233 C20.2419143,22.7276698 20.2398813,22.5740096 20.331369,22.4759832 L20.3374687,22.4696702 L26.8027181,16.0044417 L20.3374687,9.53921328 C20.2398372,9.44158265 20.2398369,9.2832914 20.3374679,9.18566017 L21.5749053,7.9482233 C21.6725364,7.85059223 21.8308276,7.85059223 21.9284587,7.9482233 Z M10.3999684,7.9482233 L11.6374053,9.18566017 C11.7329594,9.28121371 11.7349925,9.43487387 11.6435048,9.53290029 L11.637405,9.53921328 L5.17215562,16.0044417 L11.637405,22.4696702 C11.7329593,22.5652236 11.7349926,22.7188837 11.643505,22.8169103 L11.6374053,22.8232233 L10.3999684,24.0606602 C10.3023374,24.1582912 10.1440461,24.1582912 10.046415,24.0606602 L2.1669733,16.1812184 C2.06934223,16.0835874 2.06934223,15.9252961 2.1669733,15.827665 L10.046415,7.9482233 C10.1440461,7.85059223 10.3023374,7.85059223 10.3999684,7.9482233 Z M17.2612532,9.29310422 L18.9262468,9.83189578 C19.0576112,9.87440526 19.1296423,10.0153579 19.0871328,10.1467222 L15.0848232,22.514807 C15.0423138,22.6461714 14.9013612,22.7182025 14.7699968,22.675693 L13.1050032,22.1369014 C12.9736388,22.0943919 12.9016077,21.9534393 12.9441172,21.822075 L16.9464268,9.45399022 C16.9889362,9.32262585 17.1298888,9.25059474 17.2612532,9.29310422 Z" id="形状" fill="#1D1F24" mask="url(#mask-2)"></path></g></g><g id="icon切图" transform="translate(226.000000, 1782.000000)"></g></g></g>', 2)
6451
6519
  ]));
6452
6520
  };
6453
6521
  }
6454
6522
  });
6455
6523
 
6456
- const _hoisted_1$i = { class: "m-fields-key-value" };
6457
- const _hoisted_2$8 = { key: 0 };
6524
+ const _hoisted_1$j = { class: "m-fields-key-value" };
6525
+ const _hoisted_2$9 = { key: 0 };
6458
6526
  const _sfc_main$D = /* @__PURE__ */ defineComponent({
6459
6527
  ...{
6460
6528
  name: "MFieldsKeyValue"
@@ -6478,14 +6546,18 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6478
6546
  const records = ref([]);
6479
6547
  const showCode = ref(false);
6480
6548
  watchEffect(() => {
6481
- const initValues = Object.entries(props.model[props.name] || {});
6482
- for (const [, value] of initValues) {
6483
- if (typeof value !== "string") {
6484
- showCode.value = true;
6485
- 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
+ }
6486
6558
  }
6559
+ records.value = initValues;
6487
6560
  }
6488
- records.value = initValues;
6489
6561
  });
6490
6562
  const getValue = () => {
6491
6563
  const record = {};
@@ -6513,8 +6585,8 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6513
6585
  emit("change", v);
6514
6586
  };
6515
6587
  return (_ctx, _cache) => {
6516
- return openBlock(), createElementBlock("div", _hoisted_1$i, [
6517
- !showCode.value ? (openBlock(), createElementBlock("div", _hoisted_2$8, [
6588
+ return openBlock(), createElementBlock("div", _hoisted_1$j, [
6589
+ !showCode.value ? (openBlock(), createElementBlock("div", _hoisted_2$9, [
6518
6590
  (openBlock(true), createElementBlock(Fragment, null, renderList(records.value, (item, index) => {
6519
6591
  return openBlock(), createElementBlock("div", {
6520
6592
  class: "m-fields-key-value-item",
@@ -6567,7 +6639,7 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6567
6639
  key: 1,
6568
6640
  height: "200px",
6569
6641
  "init-values": _ctx.model[_ctx.name],
6570
- language: "json",
6642
+ language: "javascript",
6571
6643
  options: {
6572
6644
  readOnly: _ctx.disabled
6573
6645
  },
@@ -6587,8 +6659,8 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
6587
6659
  }
6588
6660
  });
6589
6661
 
6590
- const _hoisted_1$h = { class: "m-fields-page-fragment-select" };
6591
- const _hoisted_2$7 = { class: "page-fragment-select-container" };
6662
+ const _hoisted_1$i = { class: "m-fields-page-fragment-select" };
6663
+ const _hoisted_2$8 = { class: "page-fragment-select-container" };
6592
6664
  const _sfc_main$C = /* @__PURE__ */ defineComponent({
6593
6665
  ...{
6594
6666
  name: "MFieldsPageFragmentSelect"
@@ -6635,8 +6707,8 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
6635
6707
  };
6636
6708
  return (_ctx, _cache) => {
6637
6709
  const _component_m_form_container = resolveComponent("m-form-container");
6638
- return openBlock(), createElementBlock("div", _hoisted_1$h, [
6639
- createElementVNode("div", _hoisted_2$7, [
6710
+ return openBlock(), createElementBlock("div", _hoisted_1$i, [
6711
+ createElementVNode("div", _hoisted_2$8, [
6640
6712
  createVNode(_component_m_form_container, {
6641
6713
  class: "select",
6642
6714
  config: selectConfig,
@@ -6656,7 +6728,7 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
6656
6728
  }
6657
6729
  });
6658
6730
 
6659
- const _hoisted_1$g = {
6731
+ const _hoisted_1$h = {
6660
6732
  key: 1,
6661
6733
  class: "m-fields-ui-select",
6662
6734
  style: { "display": "flex" }
@@ -6692,7 +6764,10 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
6692
6764
  globalThis.document.removeEventListener(UI_SELECT_MODE_EVENT_NAME, clickHandler);
6693
6765
  };
6694
6766
  const clickHandler = ({ detail }) => {
6695
- const id = getIdFromEl()(detail);
6767
+ let { id } = detail;
6768
+ if (detail.nodeType) {
6769
+ id = getIdFromEl()(detail) || id;
6770
+ }
6696
6771
  if (id) {
6697
6772
  props.model[props.name] = id;
6698
6773
  emit("change", id);
@@ -6756,7 +6831,7 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
6756
6831
  ])),
6757
6832
  _: 1
6758
6833
  }, 8, ["icon", "disabled", "size"])
6759
- ])) : (openBlock(), createElementBlock("div", _hoisted_1$g, [
6834
+ ])) : (openBlock(), createElementBlock("div", _hoisted_1$h, [
6760
6835
  val.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
6761
6836
  createVNode(unref(TMagicTooltip), {
6762
6837
  content: "清除",
@@ -7005,11 +7080,11 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
7005
7080
  }
7006
7081
  });
7007
7082
 
7008
- const _hoisted_1$f = {
7083
+ const _hoisted_1$g = {
7009
7084
  key: 1,
7010
7085
  class: "menu-item-text"
7011
7086
  };
7012
- const _hoisted_2$6 = { class: "el-dropdown-link menubar-menu-button" };
7087
+ const _hoisted_2$7 = { class: "el-dropdown-link menubar-menu-button" };
7013
7088
  const _sfc_main$y = /* @__PURE__ */ defineComponent({
7014
7089
  ...{
7015
7090
  name: "MEditorToolButton"
@@ -7081,7 +7156,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
7081
7156
  _ctx.data.type === "divider" ? (openBlock(), createBlock(unref(TMagicDivider), {
7082
7157
  key: 0,
7083
7158
  direction: _ctx.data.direction || "vertical"
7084
- }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$f, toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
7159
+ }, null, 8, ["direction"])) : _ctx.data.type === "text" ? (openBlock(), createElementBlock("div", _hoisted_1$g, toDisplayString(_ctx.data.text), 1)) : _ctx.data.type === "button" ? (openBlock(), createElementBlock(Fragment, { key: 2 }, [
7085
7160
  _ctx.data.tooltip ? (openBlock(), createBlock(unref(TMagicTooltip), {
7086
7161
  key: 0,
7087
7162
  effect: "dark",
@@ -7146,7 +7221,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
7146
7221
  })) : createCommentVNode("", true)
7147
7222
  ]),
7148
7223
  default: withCtx(() => [
7149
- createElementVNode("span", _hoisted_2$6, [
7224
+ createElementVNode("span", _hoisted_2$7, [
7150
7225
  createTextVNode(toDisplayString(_ctx.data.text), 1),
7151
7226
  createVNode(unref(TMagicIcon), { class: "el-icon--right" }, {
7152
7227
  default: withCtx(() => [
@@ -7163,7 +7238,12 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
7163
7238
  }
7164
7239
  });
7165
7240
 
7166
- const _hoisted_1$e = {
7241
+ const _hoisted_1$f = {
7242
+ key: 0,
7243
+ id: "m-editor-page-bar-add-icon",
7244
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon"
7245
+ };
7246
+ const _hoisted_2$6 = {
7167
7247
  key: 1,
7168
7248
  style: { "width": "21px" }
7169
7249
  };
@@ -7172,35 +7252,51 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
7172
7252
  name: "MEditorPageBarAddButton"
7173
7253
  },
7174
7254
  __name: "AddButton",
7175
- props: {
7176
- type: {}
7177
- },
7178
7255
  setup(__props) {
7179
- const props = __props;
7180
7256
  const services = inject("services");
7181
7257
  const uiService = services?.uiService;
7182
7258
  const editorService = services?.editorService;
7183
7259
  const showAddPageButton = computed(() => uiService?.get("showAddPageButton"));
7184
- const addPage = () => {
7260
+ const addPage = (type) => {
7185
7261
  if (!editorService) return;
7186
7262
  const root = toRaw(editorService.get("root"));
7187
7263
  if (!root) throw new Error("root 不能为空");
7188
7264
  const pageConfig = {
7189
- type: props.type,
7190
- name: generatePageNameByApp(root, props.type),
7265
+ type,
7266
+ name: generatePageNameByApp(root, type),
7191
7267
  items: []
7192
7268
  };
7193
7269
  editorService.add(pageConfig);
7194
7270
  };
7195
7271
  return (_ctx, _cache) => {
7196
- return showAddPageButton.value ? (openBlock(), createElementBlock("div", {
7197
- key: 0,
7198
- id: "m-editor-page-bar-add-icon",
7199
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
7200
- onClick: addPage
7201
- }, [
7202
- createVNode(_sfc_main$Y, { icon: unref(Plus) }, null, 8, ["icon"])
7203
- ])) : (openBlock(), createElementBlock("div", _hoisted_1$e));
7272
+ return showAddPageButton.value ? (openBlock(), createElementBlock("div", _hoisted_1$f, [
7273
+ createVNode(unref(TMagicPopover), { "popper-class": "data-source-list-panel-add-menu" }, {
7274
+ reference: withCtx(() => [
7275
+ createVNode(_sfc_main$Y, { icon: unref(Plus) }, null, 8, ["icon"])
7276
+ ]),
7277
+ default: withCtx(() => [
7278
+ createVNode(_sfc_main$y, {
7279
+ data: {
7280
+ type: "button",
7281
+ text: "页面",
7282
+ handler: () => {
7283
+ addPage(unref(NodeType).PAGE);
7284
+ }
7285
+ }
7286
+ }, null, 8, ["data"]),
7287
+ createVNode(_sfc_main$y, {
7288
+ data: {
7289
+ type: "button",
7290
+ text: "页面片",
7291
+ handler: () => {
7292
+ addPage(unref(NodeType).PAGE_FRAGMENT);
7293
+ }
7294
+ }
7295
+ }, null, 8, ["data"])
7296
+ ]),
7297
+ _: 1
7298
+ })
7299
+ ])) : (openBlock(), createElementBlock("div", _hoisted_2$6));
7204
7300
  };
7205
7301
  }
7206
7302
  });
@@ -7211,10 +7307,10 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7211
7307
  },
7212
7308
  __name: "PageBarScrollContainer",
7213
7309
  props: {
7214
- type: {},
7215
- pageBarSortOptions: {}
7310
+ pageBarSortOptions: {},
7311
+ length: {}
7216
7312
  },
7217
- setup(__props) {
7313
+ setup(__props, { expose: __expose }) {
7218
7314
  const props = __props;
7219
7315
  const services = inject("services");
7220
7316
  const editorService = services?.editorService;
@@ -7225,7 +7321,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7225
7321
  const showPageListButton = computed(() => uiService?.get("showPageListButton"));
7226
7322
  const itemsContainerWidth = ref(0);
7227
7323
  const setCanScroll = () => {
7228
- itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - (showAddPageButton.value ? 37 : 21) - (showPageListButton.value ? 37 : 0);
7324
+ itemsContainerWidth.value = (pageBar.value?.clientWidth || 0) - 37 * 2 - 37 - (showAddPageButton.value ? 37 : 21) - (showPageListButton.value ? 37 : 0);
7229
7325
  nextTick(() => {
7230
7326
  if (itemsContainer.value) {
7231
7327
  canScroll.value = itemsContainer.value.scrollWidth - itemsContainerWidth.value > 1;
@@ -7244,38 +7340,43 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7244
7340
  });
7245
7341
  let translateLeft = 0;
7246
7342
  const scroll = (type) => {
7247
- if (!itemsContainer.value) return;
7343
+ if (!itemsContainer.value || !canScroll.value) return;
7248
7344
  const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
7249
7345
  if (type === "left") {
7250
- translateLeft += 100;
7251
- if (translateLeft > 0) {
7252
- translateLeft = 0;
7253
- }
7346
+ scrollTo(translateLeft + 200);
7254
7347
  } else if (type === "right") {
7255
- translateLeft -= 100;
7256
- if (-translateLeft > maxScrollLeft) {
7257
- translateLeft = -maxScrollLeft;
7258
- }
7348
+ scrollTo(translateLeft - 200);
7259
7349
  } else if (type === "start") {
7260
- translateLeft = 0;
7350
+ scrollTo(0);
7261
7351
  } else if (type === "end") {
7262
- translateLeft = -maxScrollLeft;
7352
+ scrollTo(-maxScrollLeft);
7353
+ }
7354
+ };
7355
+ const scrollTo = (value) => {
7356
+ if (!itemsContainer.value || !canScroll.value) return;
7357
+ const maxScrollLeft = itemsContainer.value.scrollWidth - itemsContainerWidth.value;
7358
+ if (value >= 0) {
7359
+ value = 0;
7263
7360
  }
7361
+ if (-value > maxScrollLeft) {
7362
+ value = -maxScrollLeft;
7363
+ }
7364
+ translateLeft = value;
7264
7365
  itemsContainer.value.style.transform = `translate(${translateLeft}px, 0px)`;
7265
7366
  };
7266
- const pageLength = computed(() => editorService?.get("pageLength") || 0);
7267
- const pageFragmentLength = computed(() => editorService?.get("pageFragmentLength") || 0);
7268
- const crateWatchLength = (length) => watch(
7269
- length,
7270
- (length2 = 0, preLength = 0) => {
7367
+ watch(
7368
+ () => props.length,
7369
+ (length = 0, preLength = 0) => {
7271
7370
  setTimeout(() => {
7272
7371
  setCanScroll();
7273
- if (length2 < preLength) {
7274
- scroll("start");
7275
- } else {
7276
- scroll("end");
7277
- }
7278
- if (length2 > 1) {
7372
+ nextTick(() => {
7373
+ if (length < preLength || preLength === 0) {
7374
+ scroll("start");
7375
+ } else {
7376
+ scroll("end");
7377
+ }
7378
+ });
7379
+ if (length > 1) {
7279
7380
  const el = document.querySelector(".m-editor-page-bar-items");
7280
7381
  let beforeDragList = [];
7281
7382
  const options = {
@@ -7311,25 +7412,14 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7311
7412
  immediate: true
7312
7413
  }
7313
7414
  );
7314
- let unWatchPageLength;
7315
- let unWatchPageFragmentLength;
7316
- watch(
7317
- () => props.type,
7318
- (type) => {
7319
- if (type === NodeType.PAGE) {
7320
- unWatchPageFragmentLength?.();
7321
- unWatchPageFragmentLength = null;
7322
- unWatchPageLength = crateWatchLength(pageLength);
7323
- } else {
7324
- unWatchPageLength?.();
7325
- unWatchPageLength = null;
7326
- unWatchPageFragmentLength = crateWatchLength(pageFragmentLength);
7327
- }
7328
- },
7329
- {
7330
- immediate: true
7415
+ __expose({
7416
+ itemsContainerWidth,
7417
+ scroll,
7418
+ scrollTo,
7419
+ getTranslateLeft() {
7420
+ return translateLeft;
7331
7421
  }
7332
- );
7422
+ });
7333
7423
  return (_ctx, _cache) => {
7334
7424
  return openBlock(), createElementBlock("div", {
7335
7425
  class: "m-editor-page-bar",
@@ -7337,25 +7427,24 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7337
7427
  ref: pageBar
7338
7428
  }, [
7339
7429
  renderSlot(_ctx.$slots, "prepend"),
7340
- canScroll.value ? (openBlock(), createElementBlock("div", {
7430
+ _ctx.length ? (openBlock(), createElementBlock("div", {
7341
7431
  key: 0,
7342
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
7343
- onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
7344
- }, [
7345
- createVNode(_sfc_main$Y, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
7346
- ])) : createCommentVNode("", true),
7347
- _ctx.type === unref(NodeType).PAGE && pageLength.value || _ctx.type === unref(NodeType).PAGE_FRAGMENT && pageFragmentLength.value ? (openBlock(), createElementBlock("div", {
7348
- key: 1,
7349
7432
  class: "m-editor-page-bar-items",
7350
7433
  ref_key: "itemsContainer",
7351
- ref: itemsContainer,
7352
- style: normalizeStyle(`width: ${itemsContainerWidth.value}px`)
7434
+ ref: itemsContainer
7353
7435
  }, [
7354
7436
  renderSlot(_ctx.$slots, "default")
7355
- ], 4)) : createCommentVNode("", true),
7437
+ ], 512)) : createCommentVNode("", true),
7438
+ canScroll.value ? (openBlock(), createElementBlock("div", {
7439
+ key: 1,
7440
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon m-editor-page-bar-item-left-icon",
7441
+ onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
7442
+ }, [
7443
+ createVNode(_sfc_main$Y, { icon: unref(ArrowLeftBold) }, null, 8, ["icon"])
7444
+ ])) : createCommentVNode("", true),
7356
7445
  canScroll.value ? (openBlock(), createElementBlock("div", {
7357
7446
  key: 2,
7358
- class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
7447
+ class: "m-editor-page-bar-item m-editor-page-bar-item-icon m-editor-page-bar-item-right-icon",
7359
7448
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
7360
7449
  }, [
7361
7450
  createVNode(_sfc_main$Y, { icon: unref(ArrowRightBold) }, null, 8, ["icon"])
@@ -7365,7 +7454,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
7365
7454
  }
7366
7455
  });
7367
7456
 
7368
- const _hoisted_1$d = {
7457
+ const _hoisted_1$e = {
7369
7458
  key: 0,
7370
7459
  id: "m-editor-page-bar-list-icon",
7371
7460
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon"
@@ -7383,11 +7472,12 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
7383
7472
  const uiService = services?.uiService;
7384
7473
  const editorService = services?.editorService;
7385
7474
  const showPageListButton = computed(() => uiService?.get("showPageListButton"));
7386
- const switchPage = (id) => {
7387
- editorService?.select(id);
7475
+ const page = computed(() => editorService?.get("page"));
7476
+ const switchPage = async (id) => {
7477
+ await editorService?.select(id);
7388
7478
  };
7389
7479
  return (_ctx, _cache) => {
7390
- return showPageListButton.value ? (openBlock(), createElementBlock("div", _hoisted_1$d, [
7480
+ return showPageListButton.value ? (openBlock(), createElementBlock("div", _hoisted_1$e, [
7391
7481
  createVNode(unref(TMagicPopover), {
7392
7482
  "popper-class": "page-bar-popover",
7393
7483
  placement: "top",
@@ -7411,6 +7501,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
7411
7501
  data: {
7412
7502
  type: "button",
7413
7503
  text: item.devconfig?.tabName || item.name || item.id,
7504
+ className: item.id === page.value?.id ? "active" : "",
7414
7505
  handler: () => switchPage(item.id)
7415
7506
  },
7416
7507
  key: index
@@ -7426,52 +7517,72 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
7426
7517
  }
7427
7518
  });
7428
7519
 
7520
+ const _hoisted_1$d = { class: "m-editor-page-bar-item m-editor-page-bar-item-icon m-editor-page-bar-search" };
7429
7521
  const _sfc_main$u = /* @__PURE__ */ defineComponent({
7430
- ...{
7431
- name: "MEditorPageBarSwitchTypeButton"
7432
- },
7433
- __name: "SwitchTypeButton",
7522
+ __name: "Search",
7434
7523
  props: {
7435
- modelValue: {}
7524
+ "query": {},
7525
+ "queryModifiers": {}
7436
7526
  },
7437
- emits: ["update:modelValue"],
7527
+ emits: /* @__PURE__ */ mergeModels(["search"], ["update:query"]),
7438
7528
  setup(__props, { emit: __emit }) {
7439
- const data = [
7529
+ const emit = __emit;
7530
+ const query = useModel(__props, "query");
7531
+ const formConfig = createForm([
7440
7532
  {
7441
- type: NodeType.PAGE,
7442
- text: "页面"
7533
+ type: "checkbox-group",
7534
+ name: "pageType",
7535
+ options: [
7536
+ {
7537
+ value: NodeType.PAGE,
7538
+ text: "页面"
7539
+ },
7540
+ {
7541
+ value: NodeType.PAGE_FRAGMENT,
7542
+ text: "页面片段"
7543
+ }
7544
+ ]
7443
7545
  },
7444
7546
  {
7445
- type: NodeType.PAGE_FRAGMENT,
7446
- text: "页面片"
7547
+ name: "keyword",
7548
+ type: "text",
7549
+ placeholder: "请输入关键字",
7550
+ clearable: true
7447
7551
  }
7448
- ];
7449
- const emit = __emit;
7450
- const clickHandler = (value) => {
7451
- emit("update:modelValue", value);
7552
+ ]);
7553
+ const visible = ref(false);
7554
+ const onFormChange = (values) => {
7555
+ query.value = values;
7556
+ emit("search", values);
7452
7557
  };
7453
7558
  return (_ctx, _cache) => {
7454
- return openBlock(), createElementBlock(Fragment, null, renderList(data, (item) => {
7455
- return createVNode(unref(TMagicButton), {
7456
- class: normalizeClass(["m-editor-page-bar-switch-type-button", { active: _ctx.modelValue === item.type }]),
7457
- size: "small",
7458
- key: item.type,
7459
- link: "",
7460
- type: _ctx.modelValue === item.type ? "primary" : "",
7461
- onClick: ($event) => clickHandler(item.type)
7462
- }, {
7463
- default: withCtx(() => [
7464
- createTextVNode(toDisplayString(item.text), 1)
7465
- ]),
7466
- _: 2
7467
- }, 1032, ["class", "type", "onClick"]);
7468
- }), 64);
7559
+ return openBlock(), createElementBlock("div", _hoisted_1$d, [
7560
+ createVNode(_sfc_main$Y, {
7561
+ icon: unref(Search),
7562
+ onClick: _cache[0] || (_cache[0] = ($event) => visible.value = !visible.value),
7563
+ class: normalizeClass({ "icon-active": visible.value })
7564
+ }, null, 8, ["icon", "class"]),
7565
+ visible.value ? (openBlock(), createBlock(Teleport, {
7566
+ key: 0,
7567
+ to: ".m-editor-page-bar-tabs"
7568
+ }, [
7569
+ query.value ? (openBlock(), createBlock(unref(MForm), {
7570
+ key: 0,
7571
+ class: "m-editor-page-bar-search-panel",
7572
+ inline: true,
7573
+ config: unref(formConfig),
7574
+ "init-values": query.value,
7575
+ "prevent-submit-default": true,
7576
+ onChange: onFormChange
7577
+ }, null, 8, ["config", "init-values"])) : createCommentVNode("", true)
7578
+ ])) : createCommentVNode("", true)
7579
+ ]);
7469
7580
  };
7470
7581
  }
7471
7582
  });
7472
7583
 
7473
7584
  const _hoisted_1$c = { class: "m-editor-page-bar-tabs" };
7474
- const _hoisted_2$5 = ["page-id", "onClick"];
7585
+ const _hoisted_2$5 = ["data-page-id", "onClick"];
7475
7586
  const _hoisted_3$2 = { class: "m-editor-page-bar-title" };
7476
7587
  const _hoisted_4$2 = ["title"];
7477
7588
  const _sfc_main$t = /* @__PURE__ */ defineComponent({
@@ -7481,63 +7592,33 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7481
7592
  __name: "PageBar",
7482
7593
  props: {
7483
7594
  disabledPageFragment: { type: Boolean },
7484
- pageBarSortOptions: {}
7595
+ pageBarSortOptions: {},
7596
+ filterFunction: { type: Function, default: (page, keyword) => page.name?.includes(keyword) || `${page.id}`.includes(keyword) }
7485
7597
  },
7486
7598
  setup(__props) {
7487
- const active = ref(NodeType.PAGE);
7599
+ const props = __props;
7488
7600
  const services = inject("services");
7489
7601
  const editorService = services?.editorService;
7490
7602
  const root = computed(() => editorService?.get("root"));
7491
7603
  const page = computed(() => editorService?.get("page"));
7492
- const pageList = computed(() => getPageList(root.value));
7493
- const pageFragmentList = computed(() => getPageFragmentList(root.value));
7494
- const list = computed(() => active.value === NodeType.PAGE ? pageList.value : pageFragmentList.value);
7495
- const activePage = ref("");
7496
- const activePageFragment = ref("");
7497
- watch(
7498
- page,
7499
- (page2) => {
7500
- if (!page2) {
7501
- if (active.value === NodeType.PAGE) {
7502
- activePage.value = "";
7503
- }
7504
- if (active.value === NodeType.PAGE_FRAGMENT) {
7505
- activePageFragment.value = "";
7506
- }
7507
- return;
7508
- }
7509
- if (isPage(page2)) {
7510
- activePage.value = page2?.id;
7511
- if (active.value !== NodeType.PAGE) {
7512
- active.value = NodeType.PAGE;
7513
- }
7514
- } else if (isPageFragment(page2)) {
7515
- activePageFragment.value = page2?.id;
7516
- if (active.value !== NodeType.PAGE_FRAGMENT) {
7517
- active.value = NodeType.PAGE_FRAGMENT;
7518
- }
7519
- }
7520
- },
7521
- {
7522
- immediate: true
7523
- }
7524
- );
7525
- watch(active, (active2) => {
7526
- if (active2 === NodeType.PAGE) {
7527
- if (!activePage.value && !pageList.value.length) {
7528
- editorService?.selectRoot();
7529
- return;
7530
- }
7531
- switchPage(activePage.value);
7532
- return;
7604
+ const query = ref({
7605
+ pageType: [NodeType.PAGE, NodeType.PAGE_FRAGMENT],
7606
+ keyword: ""
7607
+ });
7608
+ const list = computed(() => {
7609
+ const { pageType, keyword } = query.value;
7610
+ if (pageType.length === 0) {
7611
+ return [];
7533
7612
  }
7534
- if (active2 === NodeType.PAGE_FRAGMENT) {
7535
- if (!activePageFragment.value && !pageFragmentList.value.length) {
7536
- editorService?.selectRoot();
7537
- return;
7613
+ return (root.value?.items || []).filter((item) => {
7614
+ if (pageType.includes(item.type)) {
7615
+ if (keyword) {
7616
+ return props.filterFunction(item, keyword);
7617
+ }
7618
+ return true;
7538
7619
  }
7539
- switchPage(activePageFragment.value || pageFragmentList.value[0].id);
7540
- }
7620
+ return false;
7621
+ });
7541
7622
  });
7542
7623
  const switchPage = (id) => {
7543
7624
  editorService?.select(id);
@@ -7552,19 +7633,49 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7552
7633
  const remove = (node) => {
7553
7634
  editorService?.remove(node);
7554
7635
  };
7636
+ const pageBarScrollContainer = ref();
7637
+ const pageBarItems = ref();
7638
+ watch(page, (page2) => {
7639
+ if (!page2 || !pageBarScrollContainer.value?.itemsContainerWidth || !pageBarItems.value || pageBarItems.value.length < 2) {
7640
+ return;
7641
+ }
7642
+ const firstItem = pageBarItems.value[0];
7643
+ const lastItem = pageBarItems.value[pageBarItems.value.length - 1];
7644
+ if (page2.id === firstItem.dataset.pageId) {
7645
+ pageBarScrollContainer.value.scroll("start");
7646
+ } else if (page2.id === lastItem.dataset.pageId) {
7647
+ pageBarScrollContainer.value.scroll("end");
7648
+ } else {
7649
+ const pageItem = pageBarItems.value.find((item) => item.dataset.pageId === page2.id);
7650
+ if (!pageItem) {
7651
+ return;
7652
+ }
7653
+ const pageItemRect = pageItem.getBoundingClientRect();
7654
+ const offsetLeft = pageItemRect.left - firstItem.getBoundingClientRect().left;
7655
+ const { itemsContainerWidth } = pageBarScrollContainer.value;
7656
+ const left = itemsContainerWidth - offsetLeft - pageItemRect.width;
7657
+ const translateLeft = pageBarScrollContainer.value.getTranslateLeft();
7658
+ if (offsetLeft + translateLeft < 0 || offsetLeft + pageItemRect.width > itemsContainerWidth - translateLeft) {
7659
+ pageBarScrollContainer.value.scrollTo(left);
7660
+ }
7661
+ }
7662
+ });
7555
7663
  return (_ctx, _cache) => {
7556
7664
  return openBlock(), createElementBlock("div", _hoisted_1$c, [
7557
- !_ctx.disabledPageFragment ? (openBlock(), createBlock(_sfc_main$u, {
7558
- key: 0,
7559
- modelValue: active.value,
7560
- "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => active.value = $event)
7561
- }, null, 8, ["modelValue"])) : createCommentVNode("", true),
7562
7665
  createVNode(_sfc_main$w, {
7563
- type: active.value,
7564
- "page-bar-sort-options": _ctx.pageBarSortOptions
7666
+ ref_key: "pageBarScrollContainer",
7667
+ ref: pageBarScrollContainer,
7668
+ "page-bar-sort-options": _ctx.pageBarSortOptions,
7669
+ length: list.value.length
7565
7670
  }, {
7566
7671
  prepend: withCtx(() => [
7567
- createVNode(_sfc_main$x, { type: active.value }, null, 8, ["type"]),
7672
+ renderSlot(_ctx.$slots, "page-bar-add-button", {}, () => [
7673
+ createVNode(_sfc_main$x)
7674
+ ]),
7675
+ createVNode(_sfc_main$u, {
7676
+ query: query.value,
7677
+ "onUpdate:query": _cache[0] || (_cache[0] = ($event) => query.value = $event)
7678
+ }, null, 8, ["query"]),
7568
7679
  createVNode(_sfc_main$v, { list: list.value }, {
7569
7680
  "page-list-popover": withCtx(({ list: list2 }) => [
7570
7681
  renderSlot(_ctx.$slots, "page-list-popover", { list: list2 })
@@ -7576,8 +7687,11 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7576
7687
  (openBlock(true), createElementBlock(Fragment, null, renderList(list.value, (item) => {
7577
7688
  return openBlock(), createElementBlock("div", {
7578
7689
  class: normalizeClass(["m-editor-page-bar-item", { active: page.value?.id === item.id }]),
7690
+ ref_for: true,
7691
+ ref_key: "pageBarItems",
7692
+ ref: pageBarItems,
7579
7693
  key: item.id,
7580
- "page-id": item.id,
7694
+ "data-page-id": item.id,
7581
7695
  onClick: ($event) => switchPage(item.id)
7582
7696
  }, [
7583
7697
  createElementVNode("div", _hoisted_3$2, [
@@ -7630,7 +7744,7 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
7630
7744
  }), 128))
7631
7745
  ]),
7632
7746
  _: 3
7633
- }, 8, ["type", "page-bar-sort-options"])
7747
+ }, 8, ["page-bar-sort-options", "length"])
7634
7748
  ]);
7635
7749
  };
7636
7750
  }
@@ -7698,7 +7812,8 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7698
7812
  __name: "Framework",
7699
7813
  props: {
7700
7814
  disabledPageFragment: { type: Boolean },
7701
- pageBarSortOptions: {}
7815
+ pageBarSortOptions: {},
7816
+ pageFilterFunction: { type: Function }
7702
7817
  },
7703
7818
  setup(__props) {
7704
7819
  const codeOptions = inject("codeOptions", {});
@@ -7708,7 +7823,6 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7708
7823
  const root = computed(() => editorService?.get("root"));
7709
7824
  const page = computed(() => editorService?.get("page"));
7710
7825
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
7711
- const stageLoading = computed(() => editorService?.get("stageLoading") || false);
7712
7826
  const showSrc = computed(() => uiService?.get("showSrc"));
7713
7827
  const getLeftColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
7714
7828
  const getRightColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH;
@@ -7759,7 +7873,6 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7759
7873
  }
7760
7874
  };
7761
7875
  return (_ctx, _cache) => {
7762
- const _directive_loading = resolveDirective("loading");
7763
7876
  return openBlock(), createElementBlock("div", {
7764
7877
  class: "m-editor",
7765
7878
  ref_key: "content",
@@ -7776,9 +7889,8 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7776
7889
  options: unref(codeOptions),
7777
7890
  onSave: saveCode
7778
7891
  }, null, 8, ["init-values", "options"])
7779
- ]) : withDirectives((openBlock(), createBlock(_sfc_main$z, {
7892
+ ]) : (openBlock(), createBlock(_sfc_main$z, {
7780
7893
  key: 1,
7781
- "element-loading-text": "Runtime 加载中...",
7782
7894
  ref_key: "splitView",
7783
7895
  ref: splitView,
7784
7896
  class: "m-editor-content",
@@ -7805,8 +7917,12 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7805
7917
  renderSlot(_ctx.$slots, "page-bar", {}, () => [
7806
7918
  createVNode(_sfc_main$t, {
7807
7919
  "disabled-page-fragment": _ctx.disabledPageFragment,
7808
- "page-bar-sort-options": _ctx.pageBarSortOptions
7920
+ "page-bar-sort-options": _ctx.pageBarSortOptions,
7921
+ "filter-function": _ctx.pageFilterFunction
7809
7922
  }, {
7923
+ "page-bar-add-button": withCtx(() => [
7924
+ renderSlot(_ctx.$slots, "page-bar-add-button")
7925
+ ]),
7810
7926
  "page-bar-title": withCtx(({ page: page2 }) => [
7811
7927
  renderSlot(_ctx.$slots, "page-bar-title", { page: page2 })
7812
7928
  ]),
@@ -7817,7 +7933,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7817
7933
  renderSlot(_ctx.$slots, "page-list-popover", { list })
7818
7934
  ]),
7819
7935
  _: 3
7820
- }, 8, ["disabled-page-fragment", "page-bar-sort-options"])
7936
+ }, 8, ["disabled-page-fragment", "page-bar-sort-options", "filter-function"])
7821
7937
  ])
7822
7938
  ]),
7823
7939
  _: 2
@@ -7834,9 +7950,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
7834
7950
  ]),
7835
7951
  key: "0"
7836
7952
  } : void 0
7837
- ]), 1032, ["left", "right", "width"])), [
7838
- [_directive_loading, stageLoading.value]
7839
- ]),
7953
+ ]), 1032, ["left", "right", "width"])),
7840
7954
  renderSlot(_ctx.$slots, "content-after"),
7841
7955
  renderSlot(_ctx.$slots, "footer")
7842
7956
  ], 512);
@@ -8085,10 +8199,10 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
8085
8199
  configForm.value.formState.stage = stage.value;
8086
8200
  }
8087
8201
  });
8088
- const submit = async () => {
8202
+ const submit = async (v, eventData) => {
8089
8203
  try {
8090
8204
  const values2 = await configForm.value?.submitForm();
8091
- services?.editorService.update(values2);
8205
+ services?.editorService.update(values2, { changeRecords: eventData.changeRecords });
8092
8206
  } catch (e) {
8093
8207
  emit("submit-error", e);
8094
8208
  }
@@ -8390,6 +8504,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8390
8504
  const emit = __emit;
8391
8505
  const services = inject("services");
8392
8506
  const { codeBlockService, depService, editorService } = services || {};
8507
+ const collecting = computed(() => depService?.get("collecting"));
8393
8508
  const codeList = computed(
8394
8509
  () => Object.entries(codeBlockService?.getCodeDsl() || {}).map(([codeId, code]) => {
8395
8510
  const target = depService?.getTarget(codeId, DepTargetType.CODE_BLOCK);
@@ -8489,8 +8604,19 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8489
8604
  }, toDisplayString(data.name) + " " + toDisplayString(data.key ? `(${data.key})` : ""), 3)
8490
8605
  ]),
8491
8606
  "tree-node-tool": withCtx(({ data }) => [
8492
- data.type === "code" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8607
+ collecting.value && data.type === "code" ? (openBlock(), createBlock(unref(TMagicTag), {
8493
8608
  key: 0,
8609
+ type: "info",
8610
+ size: "small",
8611
+ style: { "margin-right": "5px" }
8612
+ }, {
8613
+ default: withCtx(() => _cache[0] || (_cache[0] = [
8614
+ createTextVNode("依赖收集中")
8615
+ ])),
8616
+ _: 1
8617
+ })) : createCommentVNode("", true),
8618
+ data.type === "code" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8619
+ key: 1,
8494
8620
  effect: "dark",
8495
8621
  content: editable.value ? "编辑" : "查看",
8496
8622
  placement: "bottom"
@@ -8505,7 +8631,7 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
8505
8631
  _: 2
8506
8632
  }, 1032, ["content"])) : createCommentVNode("", true),
8507
8633
  data.type === "code" && editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
8508
- key: 1,
8634
+ key: 2,
8509
8635
  effect: "dark",
8510
8636
  content: "删除",
8511
8637
  placement: "bottom"
@@ -8621,9 +8747,9 @@ const useDataSourceEdit = (dataSourceService) => {
8621
8747
  dialogTitle.value = `编辑${dataSourceValues.value.title || ""}`;
8622
8748
  editDialog.value.show();
8623
8749
  };
8624
- const submitDataSourceHandler = (value) => {
8750
+ const submitDataSourceHandler = (value, eventData) => {
8625
8751
  if (value.id) {
8626
- dataSourceService?.update(value);
8752
+ dataSourceService?.update(value, { changeRecords: eventData.changeRecords });
8627
8753
  } else {
8628
8754
  dataSourceService?.add(value);
8629
8755
  }
@@ -8670,8 +8796,8 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
8670
8796
  initValues.value = props.values;
8671
8797
  dataSourceConfig.value = services?.dataSourceService.getFormConfig(initValues.value.type) || [];
8672
8798
  });
8673
- const submitHandler = (values) => {
8674
- emit("submit", values);
8799
+ const submitHandler = (values, data) => {
8800
+ emit("submit", values, data);
8675
8801
  };
8676
8802
  const errorHandler = (error) => {
8677
8803
  tMagicMessage.error(error.message);
@@ -8727,6 +8853,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8727
8853
  setup(__props, { expose: __expose, emit: __emit }) {
8728
8854
  const emit = __emit;
8729
8855
  const { depService, editorService, dataSourceService } = inject("services") || {};
8856
+ const collecting = computed(() => depService?.get("collecting"));
8730
8857
  const editable = computed(() => dataSourceService?.get("editable") ?? true);
8731
8858
  const dataSources = computed(() => dataSourceService?.get("dataSources") || []);
8732
8859
  const dsDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE) || {});
@@ -8832,8 +8959,19 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8832
8959
  }, toDisplayString(data.name) + " " + toDisplayString(data.key ? `(${data.key})` : ""), 3)
8833
8960
  ]),
8834
8961
  "tree-node-tool": withCtx(({ data }) => [
8835
- data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8962
+ collecting.value && data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTag), {
8836
8963
  key: 0,
8964
+ type: "info",
8965
+ size: "small",
8966
+ style: { "margin-right": "5px" }
8967
+ }, {
8968
+ default: withCtx(() => _cache[0] || (_cache[0] = [
8969
+ createTextVNode("依赖收集中")
8970
+ ])),
8971
+ _: 1
8972
+ })) : createCommentVNode("", true),
8973
+ data.type === "ds" ? (openBlock(), createBlock(unref(TMagicTooltip), {
8974
+ key: 1,
8837
8975
  effect: "dark",
8838
8976
  content: editable.value ? "编辑" : "查看",
8839
8977
  placement: "bottom"
@@ -8848,7 +8986,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
8848
8986
  _: 2
8849
8987
  }, 1032, ["content"])) : createCommentVNode("", true),
8850
8988
  data.type === "ds" && editable.value ? (openBlock(), createBlock(unref(TMagicTooltip), {
8851
- key: 1,
8989
+ key: 2,
8852
8990
  effect: "dark",
8853
8991
  content: "删除",
8854
8992
  placement: "bottom"
@@ -10114,6 +10252,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10114
10252
  setup(__props, { expose: __expose }) {
10115
10253
  const props = __props;
10116
10254
  const services = inject("services");
10255
+ const collecting = computed(() => services?.depService.get("collecting"));
10117
10256
  const columnLeftWidth = computed(() => services?.uiService.get("columnWidth")[ColumnLayout.LEFT] || 0);
10118
10257
  const { height: editorContentHeight } = useEditorContentHeight();
10119
10258
  const columnLeftHeight = ref(0);
@@ -10256,7 +10395,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10256
10395
  ]),
10257
10396
  (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
10258
10397
  return withDirectives((openBlock(), createElementBlock("div", {
10259
- class: "m-editor-sidebar-content",
10398
+ class: normalizeClass(["m-editor-sidebar-content", { "m-editor-dep-collecting": collecting.value }]),
10260
10399
  key: config.$key ?? index
10261
10400
  }, [
10262
10401
  config?.component && !unref(floatBoxStates)[config.$key]?.status ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({
@@ -10382,7 +10521,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
10382
10521
  key: "11"
10383
10522
  } : void 0
10384
10523
  ]), 1040)) : createCommentVNode("", true)
10385
- ])), [
10524
+ ], 2)), [
10386
10525
  [vShow, [config.text, config.$key, `${index}`].includes(activeTabName.value)]
10387
10526
  ]);
10388
10527
  }), 128))
@@ -10963,15 +11102,17 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
10963
11102
  },
10964
11103
  __name: "Stage",
10965
11104
  props: {
11105
+ stageOptions: {},
10966
11106
  stageContentMenu: {},
10967
11107
  disabledStageOverlay: { type: Boolean, default: false },
10968
11108
  customContentMenu: {}
10969
11109
  },
10970
11110
  setup(__props) {
11111
+ const props = __props;
10971
11112
  let stage = null;
10972
11113
  let runtime = null;
10973
11114
  const services = inject("services");
10974
- const stageOptions = inject("stageOptions");
11115
+ const stageLoading = computed(() => services?.editorService.get("stageLoading") || false);
10975
11116
  const stageWrap = ref();
10976
11117
  const stageContainer = ref();
10977
11118
  const menu = ref();
@@ -10986,8 +11127,8 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
10986
11127
  watchEffect(() => {
10987
11128
  if (stage || !page.value) return;
10988
11129
  if (!stageContainer.value) return;
10989
- if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
10990
- stage = useStage(stageOptions);
11130
+ if (!(props.stageOptions?.runtimeUrl || props.stageOptions?.render) || !root.value) return;
11131
+ stage = useStage(props.stageOptions);
10991
11132
  stage.on("select", () => {
10992
11133
  stageWrap.value?.container?.focus();
10993
11134
  });
@@ -11007,14 +11148,23 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11007
11148
  });
11008
11149
  onBeforeUnmount(() => {
11009
11150
  stage?.destroy();
11151
+ services?.editorService.set("stage", null);
11010
11152
  });
11011
11153
  watch(zoom, (zoom2) => {
11012
11154
  if (!stage || !zoom2) return;
11013
11155
  stage.setZoom(zoom2);
11014
11156
  });
11157
+ let timeoutId = null;
11015
11158
  watch(page, (page2) => {
11016
11159
  if (runtime && page2) {
11017
11160
  services?.editorService.set("stageLoading", true);
11161
+ if (timeoutId) {
11162
+ globalThis.clearTimeout(timeoutId);
11163
+ }
11164
+ timeoutId = globalThis.setTimeout(() => {
11165
+ services?.editorService.set("stageLoading", false);
11166
+ timeoutId = null;
11167
+ }, 3e3);
11018
11168
  runtime.updatePageId?.(page2.id);
11019
11169
  nextTick(() => {
11020
11170
  stage?.select(page2.id);
@@ -11066,7 +11216,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11066
11216
  if (!config || config.dragType !== DragType.COMPONENT_LIST) return;
11067
11217
  e.preventDefault();
11068
11218
  const doc = stage?.renderer?.contentWindow?.document;
11069
- const parentEl = doc?.querySelector(`.${stageOptions?.containerHighlightClassName}`);
11219
+ const parentEl = doc?.querySelector(
11220
+ `.${props.stageOptions?.containerHighlightClassName}`
11221
+ );
11070
11222
  let parent = page.value;
11071
11223
  const parentId = getIdFromEl()(parentEl);
11072
11224
  if (parentId) {
@@ -11105,11 +11257,13 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11105
11257
  }
11106
11258
  };
11107
11259
  return (_ctx, _cache) => {
11108
- return openBlock(), createBlock(_sfc_main$8, {
11260
+ const _directive_loading = resolveDirective("loading");
11261
+ return withDirectives((openBlock(), createBlock(_sfc_main$8, {
11109
11262
  class: "m-editor-stage",
11110
11263
  ref_key: "stageWrap",
11111
11264
  ref: stageWrap,
11112
11265
  tabindex: "-1",
11266
+ "element-loading-text": "Runtime 加载中...",
11113
11267
  width: stageRect.value?.width,
11114
11268
  height: stageRect.value?.height,
11115
11269
  "wrap-width": stageContainerRect.value?.width,
@@ -11146,7 +11300,9 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
11146
11300
  createVNode(_sfc_main$7)
11147
11301
  ]),
11148
11302
  _: 1
11149
- }, 8, ["width", "height", "wrap-width", "wrap-height", "zoom"]);
11303
+ }, 8, ["width", "height", "wrap-width", "wrap-height", "zoom"])), [
11304
+ [_directive_loading, stageLoading.value]
11305
+ ]);
11150
11306
  };
11151
11307
  }
11152
11308
  });
@@ -11208,18 +11364,20 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
11208
11364
  customContentMenu: {}
11209
11365
  },
11210
11366
  setup(__props) {
11367
+ const stageOptions = inject("stageOptions");
11211
11368
  const services = inject("services");
11212
11369
  const page = computed(() => services?.editorService.get("page"));
11213
11370
  return (_ctx, _cache) => {
11214
11371
  return openBlock(), createElementBlock("div", _hoisted_1, [
11215
11372
  createVNode(_sfc_main$2),
11216
11373
  renderSlot(_ctx.$slots, "stage", {}, () => [
11217
- page.value ? (openBlock(), createBlock(_sfc_main$3, {
11374
+ page.value && (unref(stageOptions)?.render || unref(stageOptions)?.runtimeUrl) ? (openBlock(), createBlock(_sfc_main$3, {
11218
11375
  key: 0,
11376
+ "stage-options": unref(stageOptions),
11219
11377
  "disabled-stage-overlay": _ctx.disabledStageOverlay,
11220
11378
  "stage-content-menu": _ctx.stageContentMenu,
11221
11379
  "custom-content-menu": _ctx.customContentMenu
11222
- }, null, 8, ["disabled-stage-overlay", "stage-content-menu", "custom-content-menu"])) : createCommentVNode("", true)
11380
+ }, null, 8, ["stage-options", "disabled-stage-overlay", "stage-content-menu", "custom-content-menu"])) : createCommentVNode("", true)
11223
11381
  ]),
11224
11382
  renderSlot(_ctx.$slots, "workspace-content")
11225
11383
  ]);
@@ -11569,12 +11727,17 @@ class DataSource extends BaseService {
11569
11727
  this.emit("add", newConfig);
11570
11728
  return newConfig;
11571
11729
  }
11572
- update(config) {
11730
+ update(config, { changeRecords = [] } = {}) {
11573
11731
  const dataSources = this.get("dataSources");
11574
11732
  const index = dataSources.findIndex((ds) => ds.id === config.id);
11575
- dataSources[index] = cloneDeep(config);
11576
- this.emit("update", config);
11577
- return config;
11733
+ const oldConfig = dataSources[index];
11734
+ const newConfig = cloneDeep(config);
11735
+ dataSources[index] = newConfig;
11736
+ this.emit("update", newConfig, {
11737
+ oldConfig,
11738
+ changeRecords
11739
+ });
11740
+ return newConfig;
11578
11741
  }
11579
11742
  remove(id) {
11580
11743
  const dataSources = this.get("dataSources");
@@ -11650,7 +11813,16 @@ const dataSourceService = new DataSource();
11650
11813
 
11651
11814
  const idleTask = new IdleTask();
11652
11815
  class Dep extends BaseService {
11816
+ state = reactive({
11817
+ collecting: false
11818
+ });
11653
11819
  watcher = new Watcher({ initialTargets: reactive({}) });
11820
+ set(name, value) {
11821
+ this.state[name] = value;
11822
+ }
11823
+ get(name) {
11824
+ return this.state[name];
11825
+ }
11654
11826
  removeTargets(type = DepTargetType.DEFAULT) {
11655
11827
  this.watcher.removeTargets(type);
11656
11828
  const targets = this.watcher.getTargets(type);
@@ -11677,26 +11849,32 @@ class Dep extends BaseService {
11677
11849
  this.watcher.clearTargets();
11678
11850
  }
11679
11851
  collect(nodes, depExtendedData = {}, deep = false, type) {
11852
+ this.set("collecting", true);
11680
11853
  this.watcher.collectByCallback(nodes, type, ({ node, target }) => {
11681
11854
  this.collectNode(node, target, depExtendedData, deep);
11682
11855
  });
11856
+ this.set("collecting", false);
11683
11857
  this.emit("collected", nodes, deep);
11684
11858
  }
11685
11859
  collectIdle(nodes, depExtendedData = {}, deep = false, type) {
11860
+ this.set("collecting", true);
11861
+ let startTask = false;
11686
11862
  this.watcher.collectByCallback(nodes, type, ({ node, target }) => {
11687
- idleTask.enqueueTask(
11688
- ({ node: node2, deep: deep2, target: target2 }) => {
11689
- this.collectNode(node2, target2, depExtendedData, deep2);
11690
- },
11691
- {
11692
- node,
11693
- deep,
11694
- target
11695
- }
11696
- );
11697
- });
11698
- idleTask.once("finish", () => {
11699
- this.emit("collected", nodes, deep);
11863
+ startTask = true;
11864
+ this.enqueueTask(node, target, depExtendedData, deep);
11865
+ });
11866
+ return new Promise((resolve) => {
11867
+ if (!startTask) {
11868
+ this.emit("collected", nodes, deep);
11869
+ this.set("collecting", false);
11870
+ resolve();
11871
+ return;
11872
+ }
11873
+ idleTask.once("finish", () => {
11874
+ this.emit("collected", nodes, deep);
11875
+ this.set("collecting", false);
11876
+ resolve();
11877
+ });
11700
11878
  });
11701
11879
  }
11702
11880
  collectNode(node, target, depExtendedData = {}, deep = false) {
@@ -11723,6 +11901,9 @@ class Dep extends BaseService {
11723
11901
  hasSpecifiedTypeTarget(type = DepTargetType.DEFAULT) {
11724
11902
  return this.watcher.hasSpecifiedTypeTarget(type);
11725
11903
  }
11904
+ clearIdleTasks() {
11905
+ idleTask.clearTasks();
11906
+ }
11726
11907
  on(eventName, listener) {
11727
11908
  return super.on(eventName, listener);
11728
11909
  }
@@ -11732,6 +11913,23 @@ class Dep extends BaseService {
11732
11913
  emit(eventName, ...args) {
11733
11914
  return super.emit(eventName, ...args);
11734
11915
  }
11916
+ enqueueTask(node, target, depExtendedData, deep) {
11917
+ idleTask.enqueueTask(
11918
+ ({ node: node2, deep: deep2, target: target2 }) => {
11919
+ this.collectNode(node2, target2, depExtendedData, deep2);
11920
+ },
11921
+ {
11922
+ node,
11923
+ deep: false,
11924
+ target
11925
+ }
11926
+ );
11927
+ if (deep && Array.isArray(node.items) && node.items.length) {
11928
+ node.items.forEach((item) => {
11929
+ this.enqueueTask(item, target, depExtendedData, deep);
11930
+ });
11931
+ }
11932
+ }
11735
11933
  }
11736
11934
  const depService = new Dep();
11737
11935
 
@@ -12305,6 +12503,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12305
12503
  initDataSourceDepTarget(ds);
12306
12504
  });
12307
12505
  if (Array.isArray(value.items)) {
12506
+ depService.clearIdleTasks();
12308
12507
  collectIdle(value.items, true);
12309
12508
  } else {
12310
12509
  depService.clear();
@@ -12329,15 +12528,66 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12329
12528
  emit("update:modelValue", value);
12330
12529
  }
12331
12530
  };
12332
- const getApp = () => {
12333
- const stage = editorService.get("stage");
12334
- return stage?.renderer?.runtime?.getApp?.();
12335
- };
12336
- const updateDataSourceSchema = () => {
12531
+ const stage = computed(() => editorService.get("stage"));
12532
+ watch(stage, (stage2) => {
12533
+ if (!stage2) {
12534
+ return;
12535
+ }
12536
+ stage2.on("rerender", () => {
12537
+ const node = editorService.get("node");
12538
+ if (!node) return;
12539
+ collectIdle([node], true).then(() => {
12540
+ afterUpdateNodes([node]);
12541
+ });
12542
+ });
12543
+ });
12544
+ const getApp = () => stage.value?.renderer?.runtime?.getApp?.();
12545
+ const updateDataSourceSchema = (nodes, deep) => {
12337
12546
  const root = editorService.get("root");
12547
+ const app = getApp();
12548
+ if (root && app?.dsl) {
12549
+ app.dsl.dataSourceDeps = root.dataSourceDeps;
12550
+ app.dsl.dataSourceCondDeps = root.dataSourceCondDeps;
12551
+ app.dsl.dataSources = root.dataSources;
12552
+ }
12338
12553
  if (root?.dataSources) {
12339
12554
  getApp()?.dataSourceManager?.updateSchema(root.dataSources);
12340
12555
  }
12556
+ if (!root || !stage.value) return;
12557
+ const allNodes = [];
12558
+ if (deep) {
12559
+ nodes.forEach((node) => {
12560
+ traverseNode(node, (node2) => {
12561
+ if (!allNodes.includes(node2)) {
12562
+ allNodes.push(node2);
12563
+ }
12564
+ });
12565
+ });
12566
+ } else {
12567
+ allNodes.push(...nodes);
12568
+ }
12569
+ const deps = Object.values(root.dataSourceDeps || {});
12570
+ deps.forEach((dep) => {
12571
+ Object.keys(dep).forEach((id) => {
12572
+ const node = allNodes.find((node2) => node2.id === id);
12573
+ node && stage.value?.update({
12574
+ config: cloneDeep(node),
12575
+ parentId: editorService.getParentById(node.id)?.id,
12576
+ root: cloneDeep(root)
12577
+ });
12578
+ });
12579
+ });
12580
+ };
12581
+ const afterUpdateNodes = (nodes) => {
12582
+ const root = editorService.get("root");
12583
+ if (!root) return;
12584
+ for (const node of nodes) {
12585
+ stage.value?.update({
12586
+ config: cloneDeep(node),
12587
+ parentId: editorService.getParentById(node.id)?.id,
12588
+ root: cloneDeep(root)
12589
+ });
12590
+ }
12341
12591
  };
12342
12592
  const targetAddHandler = (target) => {
12343
12593
  const root = editorService.get("root");
@@ -12357,59 +12607,32 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12357
12607
  };
12358
12608
  const targetRemoveHandler = (id) => {
12359
12609
  const root = editorService.get("root");
12360
- if (root?.dataSourceDeps) {
12610
+ if (!root) return;
12611
+ if (root.dataSourceDeps) {
12361
12612
  delete root.dataSourceDeps[id];
12362
12613
  }
12363
- if (root?.dataSourceCondDeps) {
12614
+ if (root.dataSourceCondDeps) {
12364
12615
  delete root.dataSourceCondDeps[id];
12365
12616
  }
12366
12617
  };
12367
- const collectedHandler = (nodes, deep) => {
12618
+ const depCollectedHandler = () => {
12368
12619
  const root = editorService.get("root");
12369
- const stage = editorService.get("stage");
12370
- if (!root || !stage) return;
12620
+ if (!root) return;
12371
12621
  const app = getApp();
12372
- if (!app) return;
12373
- if (app.dsl) {
12622
+ if (app?.dsl) {
12374
12623
  app.dsl.dataSourceDeps = root.dataSourceDeps;
12375
- app.dsl.dataSourceCondDeps = root.dataSourceCondDeps;
12376
- app.dsl.dataSources = root.dataSources;
12377
12624
  }
12378
- updateDataSourceSchema();
12379
- const allNodes = [];
12380
- if (deep) {
12381
- nodes.forEach((node) => {
12382
- traverseNode(node, (node2) => {
12383
- if (!allNodes.includes(node2)) {
12384
- allNodes.push(node2);
12385
- }
12386
- });
12387
- });
12388
- } else {
12389
- allNodes.push(...nodes);
12390
- }
12391
- const deps = Object.values(root.dataSourceDeps || {});
12392
- deps.forEach((dep) => {
12393
- Object.keys(dep).forEach((id) => {
12394
- const node = allNodes.find((node2) => node2.id === id);
12395
- node && stage.update({
12396
- config: cloneDeep(node),
12397
- parentId: editorService.getParentById(node.id)?.id,
12398
- root: cloneDeep(root)
12399
- });
12400
- });
12401
- });
12402
12625
  };
12403
12626
  depService.on("add-target", targetAddHandler);
12404
12627
  depService.on("remove-target", targetRemoveHandler);
12405
- depService.on("collected", collectedHandler);
12628
+ depService.on("collected", depCollectedHandler);
12406
12629
  const initDataSourceDepTarget = (ds) => {
12407
12630
  depService.addTarget(createDataSourceTarget(ds, reactive({})));
12408
12631
  depService.addTarget(createDataSourceMethodTarget(ds, reactive({})));
12409
12632
  depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
12410
12633
  };
12411
- const collectIdle = (nodes, deep) => {
12412
- nodes.forEach((node) => {
12634
+ const collectIdle = (nodes, deep) => Promise.all(
12635
+ nodes.map((node) => {
12413
12636
  let pageId;
12414
12637
  if (isPage(node)) {
12415
12638
  pageId = node.id;
@@ -12417,20 +12640,47 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12417
12640
  const info = editorService.getNodeInfo(node.id);
12418
12641
  pageId = info.page?.id;
12419
12642
  }
12420
- depService.collectIdle([node], { pageId }, deep);
12421
- });
12422
- };
12643
+ return depService.collectIdle([node], { pageId }, deep);
12644
+ })
12645
+ );
12423
12646
  const nodeAddHandler = (nodes) => {
12424
- collectIdle(nodes, true);
12647
+ collectIdle(nodes, true).then(() => {
12648
+ afterUpdateNodes(nodes);
12649
+ });
12425
12650
  };
12426
- const nodeUpdateHandler = (nodes) => {
12427
- collectIdle(nodes, true);
12651
+ const nodeUpdateHandler = (data) => {
12652
+ const needRecollectNodes = [];
12653
+ const normalNodes = [];
12654
+ data.forEach(({ newNode, oldNode, changeRecords }) => {
12655
+ if (changeRecords?.length) {
12656
+ for (const record of changeRecords) {
12657
+ 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)) {
12658
+ needRecollectNodes.push(newNode);
12659
+ } else {
12660
+ normalNodes.push(newNode);
12661
+ }
12662
+ }
12663
+ } else if (isIncludeDataSource(newNode, oldNode)) {
12664
+ needRecollectNodes.push(newNode);
12665
+ } else {
12666
+ normalNodes.push(newNode);
12667
+ }
12668
+ });
12669
+ if (needRecollectNodes.length) {
12670
+ collectIdle(needRecollectNodes, true).then(() => {
12671
+ afterUpdateNodes(needRecollectNodes);
12672
+ });
12673
+ } else if (normalNodes.length) {
12674
+ afterUpdateNodes(normalNodes);
12675
+ }
12428
12676
  };
12429
12677
  const nodeRemoveHandler = (nodes) => {
12430
12678
  depService.clear(nodes);
12431
12679
  };
12432
12680
  const historyChangeHandler = (page) => {
12433
- collectIdle([page], true);
12681
+ collectIdle([page], true).then(() => {
12682
+ updateDataSourceSchema([page], true);
12683
+ });
12434
12684
  };
12435
12685
  editorService.on("history-change", historyChangeHandler);
12436
12686
  editorService.on("root-change", rootChangeHandler);
@@ -12453,11 +12703,30 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12453
12703
  initDataSourceDepTarget(config);
12454
12704
  getApp()?.dataSourceManager?.addDataSource(config);
12455
12705
  };
12456
- const dataSourceUpdateHandler = (config) => {
12706
+ const dataSourceUpdateHandler = (config, { changeRecords }) => {
12707
+ let needRecollectDep = false;
12708
+ for (const changeRecord of changeRecords) {
12709
+ if (!changeRecord.propPath) {
12710
+ continue;
12711
+ }
12712
+ 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);
12713
+ if (needRecollectDep) {
12714
+ break;
12715
+ }
12716
+ }
12457
12717
  const root = editorService.get("root");
12458
- removeDataSourceTarget(config.id);
12459
- initDataSourceDepTarget(config);
12460
- collectIdle(root?.items || [], true);
12718
+ if (needRecollectDep) {
12719
+ if (Array.isArray(root?.items)) {
12720
+ depService.clearIdleTasks();
12721
+ removeDataSourceTarget(config.id);
12722
+ initDataSourceDepTarget(config);
12723
+ collectIdle(root.items, true).then(() => {
12724
+ updateDataSourceSchema(root?.items || [], true);
12725
+ });
12726
+ }
12727
+ } else if (root?.dataSources) {
12728
+ getApp()?.dataSourceManager?.updateSchema(root.dataSources);
12729
+ }
12461
12730
  };
12462
12731
  const removeDataSourceTarget = (id) => {
12463
12732
  depService.removeTarget(id, DepTargetType.DATA_SOURCE);
@@ -12465,8 +12734,13 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12465
12734
  depService.removeTarget(id, DepTargetType.DATA_SOURCE_METHOD);
12466
12735
  };
12467
12736
  const dataSourceRemoveHandler = (id) => {
12737
+ const root = editorService.get("root");
12738
+ const nodeIds = Object.keys(root?.dataSourceDeps?.[id] || {});
12739
+ const nodes = getNodes(nodeIds, root?.items);
12740
+ collectIdle(nodes, false).then(() => {
12741
+ updateDataSourceSchema(nodes, false);
12742
+ });
12468
12743
  removeDataSourceTarget(id);
12469
- getApp()?.dataSourceManager?.removeDataSource(id);
12470
12744
  };
12471
12745
  dataSourceService.on("add", dataSourceAddHandler);
12472
12746
  dataSourceService.on("update", dataSourceUpdateHandler);
@@ -12474,7 +12748,7 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
12474
12748
  onBeforeUnmount(() => {
12475
12749
  depService.off("add-target", targetAddHandler);
12476
12750
  depService.off("remove-target", targetRemoveHandler);
12477
- depService.off("collected", collectedHandler);
12751
+ depService.off("collected", depCollectedHandler);
12478
12752
  editorService.off("history-change", historyChangeHandler);
12479
12753
  editorService.off("root-change", rootChangeHandler);
12480
12754
  editorService.off("add", nodeAddHandler);
@@ -12531,7 +12805,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12531
12805
  isContainer: { type: Function },
12532
12806
  customContentMenu: { type: Function },
12533
12807
  extendFormState: { type: Function },
12534
- pageBarSortOptions: {}
12808
+ pageBarSortOptions: {},
12809
+ pageFilterFunction: { type: Function }
12535
12810
  }, defaultEditorProps),
12536
12811
  emits: ["props-panel-mounted", "update:modelValue", "props-form-error", "props-submit-error"],
12537
12812
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -12580,7 +12855,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12580
12855
  return (_ctx, _cache) => {
12581
12856
  return openBlock(), createBlock(_sfc_main$r, {
12582
12857
  "disabled-page-fragment": _ctx.disabledPageFragment,
12583
- "page-bar-sort-options": _ctx.pageBarSortOptions
12858
+ "page-bar-sort-options": _ctx.pageBarSortOptions,
12859
+ "page-filter-function": _ctx.pageFilterFunction
12584
12860
  }, {
12585
12861
  header: withCtx(() => [
12586
12862
  renderSlot(_ctx.$slots, "header")
@@ -12693,6 +12969,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12693
12969
  "page-bar": withCtx(() => [
12694
12970
  renderSlot(_ctx.$slots, "page-bar")
12695
12971
  ]),
12972
+ "page-bar-add-button": withCtx(() => [
12973
+ renderSlot(_ctx.$slots, "page-bar-add-button")
12974
+ ]),
12696
12975
  "page-bar-title": withCtx(({ page }) => [
12697
12976
  renderSlot(_ctx.$slots, "page-bar-title", { page })
12698
12977
  ]),
@@ -12703,7 +12982,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
12703
12982
  renderSlot(_ctx.$slots, "page-list-popover", { list })
12704
12983
  ]),
12705
12984
  _: 3
12706
- }, 8, ["disabled-page-fragment", "page-bar-sort-options"]);
12985
+ }, 8, ["disabled-page-fragment", "page-bar-sort-options", "page-filter-function"]);
12707
12986
  };
12708
12987
  }
12709
12988
  });
@@ -12742,4 +13021,4 @@ const index = {
12742
13021
  }
12743
13022
  };
12744
13023
 
12745
- 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, traverseNode, uiService, updateStatus, useCodeBlockEdit, useDataSourceMethod, useEditorContentHeight, useFilter, useFloatBox, useGetSo, useNextFloatBoxPosition, useNodeStatus$1 as useNodeStatus, useStage, useWindowRect, warn };
13024
+ 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 };