@tmagic/editor 1.3.1 → 1.3.3

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 (51) hide show
  1. package/dist/style.css +50 -0
  2. package/dist/tmagic-editor.js +578 -574
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +590 -585
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +15 -13
  7. package/src/components/CodeBlockEditor.vue +6 -4
  8. package/src/fields/DataSourceSelect.vue +15 -9
  9. package/src/hooks/index.ts +1 -0
  10. package/src/hooks/use-code-block-edit.ts +2 -0
  11. package/src/hooks/use-float-box.ts +153 -0
  12. package/src/index.ts +1 -0
  13. package/src/initService.ts +12 -11
  14. package/src/layouts/Framework.vue +10 -1
  15. package/src/layouts/sidebar/Sidebar.vue +90 -5
  16. package/src/layouts/sidebar/code-block/CodeBlockList.vue +2 -1
  17. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +11 -10
  18. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +6 -4
  19. package/src/layouts/sidebar/data-source/DataSourceList.vue +9 -8
  20. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +15 -15
  21. package/src/layouts/sidebar/layer/use-drag.ts +4 -0
  22. package/src/layouts/sidebar/layer/use-node-status.ts +20 -15
  23. package/src/services/dataSource.ts +4 -0
  24. package/src/services/dep.ts +22 -284
  25. package/src/services/ui.ts +15 -0
  26. package/src/theme/code-block.scss +5 -0
  27. package/src/theme/floatbox.scss +48 -0
  28. package/src/theme/sidebar.scss +1 -0
  29. package/src/theme/theme.scss +1 -0
  30. package/src/type.ts +30 -20
  31. package/types/components/CodeBlockEditor.vue.d.ts +3 -0
  32. package/types/fields/DataSourceSelect.vue.d.ts +6 -4
  33. package/types/hooks/index.d.ts +1 -0
  34. package/types/hooks/use-code-block-edit.d.ts +26 -46
  35. package/types/hooks/use-data-source-method.d.ts +26 -46
  36. package/types/hooks/use-float-box.d.ts +15 -0
  37. package/types/index.d.ts +1 -0
  38. package/types/layouts/PropsPanel.vue.d.ts +92 -59
  39. package/types/layouts/sidebar/Sidebar.vue.d.ts +1 -2
  40. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +1 -1
  41. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +3 -1
  42. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -0
  43. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +1 -1
  44. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +15 -2
  45. package/types/layouts/sidebar/layer/use-click.d.ts +7 -46
  46. package/types/services/dataSource.d.ts +10 -2
  47. package/types/services/dep.d.ts +12 -112
  48. package/types/services/ui.d.ts +8 -0
  49. package/types/type.d.ts +23 -18
  50. package/src/utils/dep.ts +0 -81
  51. package/types/utils/dep.d.ts +0 -6
@@ -1,14 +1,17 @@
1
- import { defineComponent, ref, watch, onMounted, onUnmounted, openBlock, createElementBlock, createBlock, Teleport, createElementVNode, normalizeClass, normalizeStyle, createVNode, unref, computed, reactive, resolveComponent, inject, withCtx, Fragment, createTextVNode, createCommentVNode, toRaw, resolveDynamicComponent, nextTick, mergeProps, toDisplayString, renderList, watchEffect, withModifiers, renderSlot, createSlots, normalizeProps, markRaw, getCurrentInstance, withDirectives, vShow, createStaticVNode, provide, Transition, toHandlers, mergeDefaults } from 'vue';
1
+ import { defineComponent, ref, watch, onMounted, onUnmounted, openBlock, createElementBlock, createBlock, Teleport, createElementVNode, normalizeClass, normalizeStyle, createVNode, unref, computed, reactive, resolveComponent, inject, withCtx, Fragment, resolveDynamicComponent, createTextVNode, createCommentVNode, toRaw, nextTick, mergeProps, toDisplayString, renderList, watchEffect, withModifiers, renderSlot, createSlots, normalizeProps, markRaw, getCurrentInstance, withDirectives, vShow, createStaticVNode, provide, Transition, toHandlers, mergeDefaults } from 'vue';
2
2
  import { FullScreen, Edit, View, Coin, Delete, Plus, Close, ArrowDown, Grid, Memo, ScaleToOriginal, ZoomOut, ZoomIn, Right, Back, Search, Aim, ArrowRight, CopyDocument, DocumentCopy, Files, Hide, Goods, List, EditPen, Top, Bottom, ArrowLeftBold, ArrowRightBold, CaretBottom } from '@element-plus/icons-vue';
3
3
  import { throttle, isEmpty, cloneDeep, mergeWith, isObject, uniq, map, has, pick, keys } from 'lodash-es';
4
4
  import * as monaco from 'monaco-editor';
5
5
  import serialize from 'serialize-javascript';
6
6
  import { TMagicButton, TMagicCard, tMagicMessage, TMagicDialog, TMagicTag, tMagicMessageBox, TMagicIcon, getConfig as getConfig$1, TMagicSwitch, TMagicInput, TMagicTooltip, TMagicScrollbar, TMagicDivider, TMagicDropdown, TMagicDropdownMenu, TMagicDropdownItem, TMagicTree, TMagicPopover, TMagicCollapse, TMagicCollapseItem } from '@tmagic/design';
7
7
  import { HookType, NodeType, ActionType } from '@tmagic/schema';
8
- import { MFormDrawer, MForm, createValues, MSelect } from '@tmagic/form';
8
+ import { MFormBox, MFormDrawer, MForm, createValues, MSelect } from '@tmagic/form';
9
9
  import { MagicTable } from '@tmagic/table';
10
- import { guid, isPop, getNodePath, isNumber, isPage, toLine, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getDefaultValueFromFields, getKeys, addClassName, removeClassName, removeClassNameByClassName, getNodes, isObject as isObject$1 } from '@tmagic/utils';
10
+ import { guid, isPop, getNodePath, isNumber, isPage, toLine, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, getDefaultValueFromFields, getKeys, addClassName, removeClassName, removeClassNameByClassName, getNodes } from '@tmagic/utils';
11
11
  import Gesto from 'gesto';
12
+ import Moveable from 'moveable';
13
+ import { DepTargetType, Watcher, createCodeBlockTarget, createDataSourceTarget, createDataSourceMethodTarget, createDataSourceCondTarget } from '@tmagic/dep';
14
+ export { DepTargetType } from '@tmagic/dep';
12
15
  import StageCore, { GuidesType, StageDragStatus, getOffset, calcValueByFontsize, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType } from '@tmagic/stage';
13
16
  import { EventEmitter } from 'events';
14
17
  import { DEFAULT_EVENTS, DEFAULT_METHODS } from '@tmagic/core';
@@ -41,8 +44,9 @@ const _sfc_main$T = /* @__PURE__ */ defineComponent({
41
44
  parse: { type: Boolean, default: false }
42
45
  },
43
46
  emits: ["initd", "save"],
44
- setup(__props, { expose: __expose, emit }) {
47
+ setup(__props, { expose: __expose, emit: __emit }) {
45
48
  const props = __props;
49
+ const emit = __emit;
46
50
  const toString = (v, language) => {
47
51
  let value = "";
48
52
  if (typeof v !== "string") {
@@ -225,7 +229,8 @@ const _sfc_main$S = /* @__PURE__ */ defineComponent({
225
229
  lastValues: {}
226
230
  },
227
231
  emits: ["change"],
228
- setup(__props, { emit }) {
232
+ setup(__props, { emit: __emit }) {
233
+ const emit = __emit;
229
234
  const props = __props;
230
235
  const save = (v) => {
231
236
  props.model[props.name] = v;
@@ -264,8 +269,9 @@ const _sfc_main$R = /* @__PURE__ */ defineComponent({
264
269
  lastValues: {}
265
270
  },
266
271
  emits: ["change"],
267
- setup(__props, { emit }) {
272
+ setup(__props, { emit: __emit }) {
268
273
  const props = __props;
274
+ const emit = __emit;
269
275
  const formConfig = computed(() => {
270
276
  const { codeOptions, ...config } = props.config;
271
277
  return {
@@ -343,9 +349,10 @@ const _sfc_main$Q = /* @__PURE__ */ defineComponent({
343
349
  lastValues: {}
344
350
  },
345
351
  emits: ["change"],
346
- setup(__props, { emit }) {
347
- const props = __props;
352
+ setup(__props, { emit: __emit }) {
353
+ const emit = __emit;
348
354
  const services = inject("services");
355
+ const props = __props;
349
356
  const codeConfig = computed(() => ({
350
357
  type: "group-list",
351
358
  name: "hookData",
@@ -411,11 +418,13 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
411
418
  content: {},
412
419
  disabled: { type: Boolean },
413
420
  isDataSource: { type: Boolean },
414
- dataSourceType: {}
421
+ dataSourceType: {},
422
+ slideType: {}
415
423
  },
416
424
  emits: ["submit"],
417
- setup(__props, { expose: __expose, emit }) {
425
+ setup(__props, { expose: __expose, emit: __emit }) {
418
426
  const props = __props;
427
+ const emit = __emit;
419
428
  const services = inject("services");
420
429
  const difVisible = ref(false);
421
430
  const height = ref(globalThis.innerHeight);
@@ -582,7 +591,7 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
582
591
  });
583
592
  return (_ctx, _cache) => {
584
593
  return openBlock(), createElementBlock(Fragment, null, [
585
- createVNode(unref(MFormDrawer), {
594
+ (openBlock(), createBlock(resolveDynamicComponent(_ctx.slideType === "box" ? unref(MFormBox) : unref(MFormDrawer)), {
586
595
  class: "m-editor-code-block-editor",
587
596
  ref_key: "fomDrawer",
588
597
  ref: fomDrawer,
@@ -613,7 +622,7 @@ const _sfc_main$P = /* @__PURE__ */ defineComponent({
613
622
  })
614
623
  ]),
615
624
  _: 1
616
- }, 8, ["title", "width", "config", "values", "disabled"]),
625
+ }, 40, ["title", "width", "config", "values", "disabled"])),
617
626
  createVNode(unref(TMagicDialog), {
618
627
  modelValue: difVisible.value,
619
628
  "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => difVisible.value = $event),
@@ -1122,12 +1131,14 @@ class DataSource extends BaseService {
1122
1131
  };
1123
1132
  this.get("dataSources").push(newConfig);
1124
1133
  this.emit("add", newConfig);
1134
+ return newConfig;
1125
1135
  }
1126
1136
  update(config) {
1127
1137
  const dataSources = this.get("dataSources");
1128
1138
  const index = dataSources.findIndex((ds) => ds.id === config.id);
1129
1139
  dataSources[index] = cloneDeep(config);
1130
1140
  this.emit("update", config);
1141
+ return config;
1131
1142
  }
1132
1143
  remove(id) {
1133
1144
  const dataSources = this.get("dataSources");
@@ -1550,14 +1561,6 @@ var KeyBindingCommand = /* @__PURE__ */ ((KeyBindingCommand2) => {
1550
1561
  KeyBindingCommand2["SWITCH_NODE"] = "tmagic-system-switch-node";
1551
1562
  return KeyBindingCommand2;
1552
1563
  })(KeyBindingCommand || {});
1553
- var DepTargetType = /* @__PURE__ */ ((DepTargetType2) => {
1554
- DepTargetType2["DEFAULT"] = "default";
1555
- DepTargetType2["CODE_BLOCK"] = "code-block";
1556
- DepTargetType2["DATA_SOURCE"] = "data-source";
1557
- DepTargetType2["DATA_SOURCE_METHOD"] = "data-source-method";
1558
- DepTargetType2["DATA_SOURCE_COND"] = "data-source-cond";
1559
- return DepTargetType2;
1560
- })(DepTargetType || {});
1561
1564
  var DragType = /* @__PURE__ */ ((DragType2) => {
1562
1565
  DragType2["COMPONENT_LIST"] = "component-list";
1563
1566
  DragType2["LAYER_TREE"] = "layer-tree";
@@ -2977,8 +2980,9 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
2977
2980
  paramsConfig: {}
2978
2981
  },
2979
2982
  emits: ["change"],
2980
- setup(__props, { emit }) {
2983
+ setup(__props, { emit: __emit }) {
2981
2984
  const props = __props;
2985
+ const emit = __emit;
2982
2986
  const form = ref();
2983
2987
  const getFormConfig = (items = []) => [
2984
2988
  {
@@ -3102,6 +3106,7 @@ const useCodeBlockEdit = (codeBlockService) => {
3102
3106
  if (!codeId.value)
3103
3107
  return;
3104
3108
  await codeBlockService?.setCodeDslById(codeId.value, values);
3109
+ tMagicMessage.success("代码块保存成功");
3105
3110
  codeBlockEditor.value?.hide();
3106
3111
  };
3107
3112
  return {
@@ -3134,9 +3139,10 @@ const _sfc_main$M = /* @__PURE__ */ defineComponent({
3134
3139
  lastValues: {}
3135
3140
  },
3136
3141
  emits: ["change"],
3137
- setup(__props, { emit }) {
3138
- const props = __props;
3142
+ setup(__props, { emit: __emit }) {
3139
3143
  const services = inject("services");
3144
+ const emit = __emit;
3145
+ const props = __props;
3140
3146
  const getParamItemsConfig = (codeId) => {
3141
3147
  if (!codeDsl.value || !codeId)
3142
3148
  return [];
@@ -3245,8 +3251,9 @@ const _sfc_main$L = /* @__PURE__ */ defineComponent({
3245
3251
  lastValues: {}
3246
3252
  },
3247
3253
  emits: ["change"],
3248
- setup(__props, { emit }) {
3254
+ setup(__props, { emit: __emit }) {
3249
3255
  const props = __props;
3256
+ const emit = __emit;
3250
3257
  const services = inject("services");
3251
3258
  const addDialog = ref();
3252
3259
  const fieldValues = ref({});
@@ -3530,9 +3537,10 @@ const _sfc_main$K = /* @__PURE__ */ defineComponent({
3530
3537
  lastValues: {}
3531
3538
  },
3532
3539
  emits: ["change"],
3533
- setup(__props, { emit }) {
3534
- const props = __props;
3540
+ setup(__props, { emit: __emit }) {
3535
3541
  const services = inject("services");
3542
+ const emit = __emit;
3543
+ const props = __props;
3536
3544
  const dataSources = computed(() => services?.dataSourceService.get("dataSources"));
3537
3545
  const getOptionChildren = (fields = []) => fields.map((field) => ({
3538
3546
  label: field.title || field.name,
@@ -3590,8 +3598,9 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
3590
3598
  lastValues: {}
3591
3599
  },
3592
3600
  emits: ["change"],
3593
- setup(__props, { emit }) {
3601
+ setup(__props, { emit: __emit }) {
3594
3602
  const props = __props;
3603
+ const emit = __emit;
3595
3604
  const { dataSourceService } = inject("services") || {};
3596
3605
  const autocomplete = ref();
3597
3606
  const isFocused = ref(false);
@@ -3899,8 +3908,9 @@ const _sfc_main$I = /* @__PURE__ */ defineComponent({
3899
3908
  lastValues: {}
3900
3909
  },
3901
3910
  emits: ["change"],
3902
- setup(__props, { emit }) {
3911
+ setup(__props, { emit: __emit }) {
3903
3912
  const props = __props;
3913
+ const emit = __emit;
3904
3914
  const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
3905
3915
  const methodColumns = [
3906
3916
  {
@@ -4004,10 +4014,11 @@ const _sfc_main$H = /* @__PURE__ */ defineComponent({
4004
4014
  lastValues: {}
4005
4015
  },
4006
4016
  emits: ["change"],
4007
- setup(__props, { emit }) {
4008
- const props = __props;
4017
+ setup(__props, { emit: __emit }) {
4009
4018
  const services = inject("services");
4019
+ const emit = __emit;
4010
4020
  const dataSourceService = services?.dataSourceService;
4021
+ const props = __props;
4011
4022
  const dataSources = computed(() => dataSourceService?.get("dataSources"));
4012
4023
  const getParamItemsConfig = ([dataSourceId, medthodName] = ["", ""]) => {
4013
4024
  if (!dataSourceId)
@@ -4125,8 +4136,9 @@ const _sfc_main$G = /* @__PURE__ */ defineComponent({
4125
4136
  lastValues: {}
4126
4137
  },
4127
4138
  emits: ["change"],
4128
- setup(__props, { emit }) {
4139
+ setup(__props, { emit: __emit }) {
4129
4140
  const props = __props;
4141
+ const emit = __emit;
4130
4142
  const services = inject("services");
4131
4143
  const width = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
4132
4144
  const addDialog = ref();
@@ -4356,18 +4368,20 @@ const _sfc_main$F = /* @__PURE__ */ defineComponent({
4356
4368
  lastValues: {}
4357
4369
  },
4358
4370
  emits: ["change"],
4359
- setup(__props, { emit }) {
4371
+ setup(__props, { emit: __emit }) {
4372
+ const emit = __emit;
4360
4373
  const props = __props;
4361
4374
  const { dataSourceService } = inject("services") || {};
4362
4375
  const dataSources = computed(() => dataSourceService?.get("dataSources") || []);
4363
4376
  const selectConfig = computed(() => {
4364
- const { type, dataSourceType, ...config } = props.config;
4377
+ const { type, dataSourceType, value, ...config } = props.config;
4378
+ const valueIsId = props.config.value === "id";
4365
4379
  return {
4366
4380
  ...config,
4367
4381
  type: "select",
4368
4382
  valueKey: "dataSourceId",
4369
- options: dataSources.value.filter((ds) => !dataSourceType || ds.type === dataSourceType).map((ds) => ({
4370
- value: {
4383
+ options: dataSources.value.filter((ds) => !props.config.dataSourceType || ds.type === props.config.dataSourceType).map((ds) => ({
4384
+ value: valueIsId ? ds.id : {
4371
4385
  isBindDataSource: true,
4372
4386
  dataSourceType: ds.type,
4373
4387
  dataSourceId: ds.id
@@ -4416,8 +4430,9 @@ const _sfc_main$E = /* @__PURE__ */ defineComponent({
4416
4430
  lastValues: {}
4417
4431
  },
4418
4432
  emits: ["change"],
4419
- setup(__props, { emit }) {
4433
+ setup(__props, { emit: __emit }) {
4420
4434
  const props = __props;
4435
+ const emit = __emit;
4421
4436
  const services = inject("services");
4422
4437
  const editorService = services?.editorService;
4423
4438
  const dataSourceService = services?.dataSourceService;
@@ -4680,8 +4695,9 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
4680
4695
  lastValues: {}
4681
4696
  },
4682
4697
  emits: ["change"],
4683
- setup(__props, { emit }) {
4698
+ setup(__props, { emit: __emit }) {
4684
4699
  const props = __props;
4700
+ const emit = __emit;
4685
4701
  const records = ref([]);
4686
4702
  watchEffect(() => {
4687
4703
  records.value = Object.entries(props.model[props.name] || {});
@@ -4784,8 +4800,9 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
4784
4800
  lastValues: {}
4785
4801
  },
4786
4802
  emits: ["change"],
4787
- setup(__props, { emit }) {
4803
+ setup(__props, { emit: __emit }) {
4788
4804
  const props = __props;
4805
+ const emit = __emit;
4789
4806
  const services = inject("services");
4790
4807
  const mForm = inject("mForm");
4791
4808
  const val = computed(() => props.model[props.name]);
@@ -4959,7 +4976,8 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4959
4976
  },
4960
4977
  __name: "Resizer",
4961
4978
  emits: ["change"],
4962
- setup(__props, { emit }) {
4979
+ setup(__props, { emit: __emit }) {
4980
+ const emit = __emit;
4963
4981
  const target = ref();
4964
4982
  const { isDraging } = useGetSo(target, emit);
4965
4983
  return (_ctx, _cache) => {
@@ -4990,7 +5008,8 @@ const _sfc_main$A = /* @__PURE__ */ defineComponent({
4990
5008
  centerClass: {}
4991
5009
  },
4992
5010
  emits: ["update:left", "change", "update:right"],
4993
- setup(__props, { expose: __expose, emit }) {
5011
+ setup(__props, { expose: __expose, emit: __emit }) {
5012
+ const emit = __emit;
4994
5013
  const props = __props;
4995
5014
  const el = ref();
4996
5015
  const hasLeft = computed(() => typeof props.left !== "undefined");
@@ -5179,7 +5198,8 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
5179
5198
  const root = computed(() => editorService?.get("root"));
5180
5199
  const pageLength = computed(() => editorService?.get("pageLength") || 0);
5181
5200
  const showSrc = computed(() => uiService?.get("showSrc"));
5182
- const leftColumnWidthCacheData = Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
5201
+ const getLeftColumnWidthCacheData = () => Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
5202
+ const leftColumnWidthCacheData = getLeftColumnWidthCacheData();
5183
5203
  const RightColumnWidthCacheData = Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH;
5184
5204
  const columnWidth = ref({
5185
5205
  left: leftColumnWidthCacheData,
@@ -5209,6 +5229,12 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
5209
5229
  globalThis.localStorage.setItem(LEFT_COLUMN_WIDTH_STORAGE_KEY, `${left}`);
5210
5230
  }
5211
5231
  );
5232
+ watch(
5233
+ () => uiService?.get("hideSlideBar"),
5234
+ (hideSlideBar) => {
5235
+ columnWidth.value.left = hideSlideBar ? 0 : getLeftColumnWidthCacheData();
5236
+ }
5237
+ );
5212
5238
  const columnWidthChange = (columnW) => {
5213
5239
  columnWidth.value.left = columnW.left;
5214
5240
  columnWidth.value.center = columnW.center;
@@ -5637,7 +5663,8 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
5637
5663
  extendState: { type: Function }
5638
5664
  },
5639
5665
  emits: ["mounted"],
5640
- setup(__props, { expose: __expose, emit }) {
5666
+ setup(__props, { expose: __expose, emit: __emit }) {
5667
+ const emit = __emit;
5641
5668
  const internalInstance = getCurrentInstance();
5642
5669
  const values = ref({});
5643
5670
  const configForm = ref();
@@ -5701,13 +5728,145 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
5701
5728
  }
5702
5729
  });
5703
5730
 
5731
+ const useFloatBox = (slideKeys) => {
5732
+ const services = inject("services");
5733
+ const moveable = ref();
5734
+ const floatBox = ref();
5735
+ const floatBoxStates = computed(() => services?.uiService.get("floatBox"));
5736
+ const curKey = ref("");
5737
+ const target = computed(
5738
+ () => floatBox.value ? floatBox.value.find((item) => item.classList.contains(`m-editor-float-box-${curKey.value}`)) : void 0
5739
+ );
5740
+ const showingBoxKeys = computed(
5741
+ () => [...floatBoxStates.value?.keys() ?? []].filter((key) => floatBoxStates.value?.get(key)?.status)
5742
+ );
5743
+ const isDraging = ref(false);
5744
+ const showFloatBox = async (key) => {
5745
+ const curBoxStatus = floatBoxStates.value?.get(curKey.value)?.status;
5746
+ if (curKey.value === key && curBoxStatus)
5747
+ return;
5748
+ curKey.value = key;
5749
+ setSlideState(key, {
5750
+ zIndex: getMaxZIndex() + 1,
5751
+ status: true
5752
+ });
5753
+ await nextTick();
5754
+ if (moveable.value) {
5755
+ moveable.value.target = target.value;
5756
+ moveable.value.dragTarget = getDragTarget();
5757
+ moveable.value.updateRect();
5758
+ } else {
5759
+ initFloatBoxMoveable();
5760
+ }
5761
+ };
5762
+ const setSlideState = (key, data) => {
5763
+ const slideState = floatBoxStates.value?.get(key);
5764
+ if (!slideState)
5765
+ return;
5766
+ floatBoxStates.value?.set(key, {
5767
+ ...slideState,
5768
+ ...data
5769
+ });
5770
+ };
5771
+ const getDragTarget = (key) => `.m-editor-float-box-header-${key ?? curKey.value}`;
5772
+ const closeFloatBox = (key) => {
5773
+ setSlideState(key, {
5774
+ status: false
5775
+ });
5776
+ if (!floatBoxStates.value?.values)
5777
+ return;
5778
+ const keys = [...floatBoxStates.value?.keys()];
5779
+ const values = [...floatBoxStates.value?.values()];
5780
+ const lastFloatBoxLen = values.filter((state) => state.status).length;
5781
+ if (lastFloatBoxLen === 0) {
5782
+ moveable.value?.destroy();
5783
+ moveable.value = void 0;
5784
+ return;
5785
+ }
5786
+ if (key === curKey.value) {
5787
+ const zIndexList = values.filter((item) => item.status).map((item) => item.zIndex);
5788
+ const maxZIndex = Math.max(...zIndexList);
5789
+ const key2 = keys.find((key3) => floatBoxStates.value?.get(key3)?.zIndex === maxZIndex);
5790
+ if (!key2)
5791
+ return;
5792
+ showFloatBox(key2);
5793
+ }
5794
+ };
5795
+ const getMaxZIndex = () => {
5796
+ if (!floatBoxStates.value?.values())
5797
+ return 0;
5798
+ const list = [...floatBoxStates.value?.values()].map((state) => state.zIndex);
5799
+ return Math.max(...list) ?? 0;
5800
+ };
5801
+ const initFloatBoxMoveable = () => {
5802
+ const dragTarget = getDragTarget();
5803
+ moveable.value = new Moveable(document.body, {
5804
+ target: target.value,
5805
+ draggable: true,
5806
+ resizable: true,
5807
+ edge: true,
5808
+ keepRatio: false,
5809
+ origin: false,
5810
+ snappable: true,
5811
+ dragTarget,
5812
+ dragTargetSelf: false,
5813
+ linePadding: 10,
5814
+ controlPadding: 10,
5815
+ elementGuidelines: [...floatBoxStates.value?.keys() ?? []].map((key) => getDragTarget(key)),
5816
+ bounds: { left: 0, top: 0, right: 0, bottom: 0, position: "css" }
5817
+ });
5818
+ moveable.value.on("drag", (e) => {
5819
+ e.target.style.transform = e.transform;
5820
+ });
5821
+ moveable.value.on("resize", (e) => {
5822
+ e.target.style.width = `${e.width}px`;
5823
+ e.target.style.height = `${e.height}px`;
5824
+ e.target.style.transform = e.drag.transform;
5825
+ });
5826
+ };
5827
+ const dragendHandler = (key, e) => {
5828
+ setSlideState(key, {
5829
+ left: e.clientX,
5830
+ top: e.clientY
5831
+ });
5832
+ showFloatBox(key);
5833
+ isDraging.value = false;
5834
+ };
5835
+ document.body.addEventListener("dragover", (e) => {
5836
+ if (!isDraging.value)
5837
+ return;
5838
+ e.preventDefault();
5839
+ });
5840
+ const dragstartHandler = () => isDraging.value = true;
5841
+ watch(
5842
+ () => slideKeys.value,
5843
+ () => {
5844
+ services?.uiService.setFloatBox(slideKeys.value);
5845
+ },
5846
+ {
5847
+ deep: true,
5848
+ immediate: true
5849
+ }
5850
+ );
5851
+ return {
5852
+ showFloatBox,
5853
+ closeFloatBox,
5854
+ dragstartHandler,
5855
+ dragendHandler,
5856
+ floatBoxStates,
5857
+ floatBox,
5858
+ showingBoxKeys
5859
+ };
5860
+ };
5861
+
5704
5862
  const _sfc_main$u = /* @__PURE__ */ defineComponent({
5705
5863
  ...{
5706
5864
  name: "MEditorSearchInput"
5707
5865
  },
5708
5866
  __name: "SearchInput",
5709
5867
  emits: ["search"],
5710
- setup(__props, { emit }) {
5868
+ setup(__props, { emit: __emit }) {
5869
+ const emit = __emit;
5711
5870
  const filterText = ref("");
5712
5871
  let timer = null;
5713
5872
  const filterTextChangeHandler = () => {
@@ -5803,8 +5962,9 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
5803
5962
  customError: { type: Function }
5804
5963
  },
5805
5964
  emits: ["edit", "remove"],
5806
- setup(__props, { expose: __expose, emit }) {
5965
+ setup(__props, { expose: __expose, emit: __emit }) {
5807
5966
  const props = __props;
5967
+ const emit = __emit;
5808
5968
  const { codeBlockService, depService, editorService } = inject("services") || {};
5809
5969
  const codeList = computed(
5810
5970
  () => Object.values(depService?.getTargets(DepTargetType.CODE_BLOCK) || {}).map((target) => {
@@ -5958,7 +6118,8 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
5958
6118
  },
5959
6119
  __name: "CodeBlockListPanel",
5960
6120
  props: {
5961
- customError: { type: Function }
6121
+ customError: { type: Function },
6122
+ slideType: {}
5962
6123
  },
5963
6124
  setup(__props) {
5964
6125
  const { codeBlockService } = inject("services") || {};
@@ -5969,52 +6130,55 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
5969
6130
  codeBlockList.value?.filter(val);
5970
6131
  };
5971
6132
  return (_ctx, _cache) => {
5972
- return openBlock(), createBlock(unref(TMagicScrollbar), { class: "m-editor-code-block-list m-editor-dep-list-panel" }, {
5973
- default: withCtx(() => [
5974
- renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
5975
- createElementVNode("div", _hoisted_1$f, [
5976
- createVNode(_sfc_main$u, { onSearch: filterTextChangeHandler }),
5977
- editable.value ? (openBlock(), createBlock(unref(TMagicButton), {
5978
- key: 0,
5979
- class: "create-code-button",
5980
- type: "primary",
5981
- size: "small",
5982
- onClick: unref(createCodeBlock)
5983
- }, {
5984
- default: withCtx(() => [
5985
- createTextVNode("新增")
5986
- ]),
5987
- _: 1
5988
- }, 8, ["onClick"])) : createCommentVNode("", true),
5989
- renderSlot(_ctx.$slots, "code-block-panel-search")
5990
- ])
5991
- ]),
5992
- createVNode(_sfc_main$r, {
5993
- ref_key: "codeBlockList",
5994
- ref: codeBlockList,
5995
- "custom-error": _ctx.customError,
5996
- onEdit: unref(editCode),
5997
- onRemove: unref(deleteCode)
5998
- }, {
5999
- "code-block-panel-tool": withCtx(({ id, data }) => [
6000
- renderSlot(_ctx.$slots, "code-block-panel-tool", {
6001
- id,
6002
- data
6003
- })
6133
+ return openBlock(), createElementBlock(Fragment, null, [
6134
+ createVNode(unref(TMagicScrollbar), { class: "m-editor-code-block-list m-editor-dep-list-panel" }, {
6135
+ default: withCtx(() => [
6136
+ renderSlot(_ctx.$slots, "code-block-panel-header", {}, () => [
6137
+ createElementVNode("div", _hoisted_1$f, [
6138
+ createVNode(_sfc_main$u, { onSearch: filterTextChangeHandler }),
6139
+ editable.value ? (openBlock(), createBlock(unref(TMagicButton), {
6140
+ key: 0,
6141
+ class: "create-code-button",
6142
+ type: "primary",
6143
+ size: "small",
6144
+ onClick: unref(createCodeBlock)
6145
+ }, {
6146
+ default: withCtx(() => [
6147
+ createTextVNode("新增")
6148
+ ]),
6149
+ _: 1
6150
+ }, 8, ["onClick"])) : createCommentVNode("", true),
6151
+ renderSlot(_ctx.$slots, "code-block-panel-search")
6152
+ ])
6004
6153
  ]),
6005
- _: 3
6006
- }, 8, ["custom-error", "onEdit", "onRemove"]),
6007
- unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$P, {
6008
- key: 0,
6009
- ref_key: "codeBlockEditor",
6010
- ref: codeBlockEditor,
6011
- disabled: !editable.value,
6012
- content: unref(codeConfig),
6013
- onSubmit: unref(submitCodeBlockHandler)
6014
- }, null, 8, ["disabled", "content", "onSubmit"])) : createCommentVNode("", true)
6015
- ]),
6016
- _: 3
6017
- });
6154
+ createVNode(_sfc_main$r, {
6155
+ ref_key: "codeBlockList",
6156
+ ref: codeBlockList,
6157
+ "custom-error": _ctx.customError,
6158
+ onEdit: unref(editCode),
6159
+ onRemove: unref(deleteCode)
6160
+ }, {
6161
+ "code-block-panel-tool": withCtx(({ id, data }) => [
6162
+ renderSlot(_ctx.$slots, "code-block-panel-tool", {
6163
+ id,
6164
+ data
6165
+ })
6166
+ ]),
6167
+ _: 3
6168
+ }, 8, ["custom-error", "onEdit", "onRemove"])
6169
+ ]),
6170
+ _: 3
6171
+ }),
6172
+ unref(codeConfig) ? (openBlock(), createBlock(_sfc_main$P, {
6173
+ key: 0,
6174
+ ref_key: "codeBlockEditor",
6175
+ ref: codeBlockEditor,
6176
+ disabled: !editable.value,
6177
+ content: unref(codeConfig),
6178
+ slideType: _ctx.slideType,
6179
+ onSubmit: unref(submitCodeBlockHandler)
6180
+ }, null, 8, ["disabled", "content", "slideType", "onSubmit"])) : createCommentVNode("", true)
6181
+ ], 64);
6018
6182
  };
6019
6183
  }
6020
6184
  });
@@ -6027,11 +6191,13 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
6027
6191
  props: {
6028
6192
  title: {},
6029
6193
  values: {},
6030
- disabled: { type: Boolean }
6194
+ disabled: { type: Boolean },
6195
+ slideType: {}
6031
6196
  },
6032
6197
  emits: ["submit"],
6033
- setup(__props, { expose: __expose, emit }) {
6198
+ setup(__props, { expose: __expose, emit: __emit }) {
6034
6199
  const props = __props;
6200
+ const emit = __emit;
6035
6201
  const services = inject("services");
6036
6202
  const size = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get("columnWidth").left || 0));
6037
6203
  const fomDrawer = ref();
@@ -6056,7 +6222,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
6056
6222
  }
6057
6223
  });
6058
6224
  return (_ctx, _cache) => {
6059
- return openBlock(), createBlock(unref(MFormDrawer), {
6225
+ return openBlock(), createBlock(resolveDynamicComponent(_ctx.slideType === "box" ? unref(MFormBox) : unref(MFormDrawer)), {
6060
6226
  ref_key: "fomDrawer",
6061
6227
  ref: fomDrawer,
6062
6228
  "label-width": "80px",
@@ -6068,7 +6234,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
6068
6234
  disabled: _ctx.disabled,
6069
6235
  onSubmit: submitHandler,
6070
6236
  onError: errorHandler
6071
- }, null, 8, ["title", "width", "config", "values", "disabled"]);
6237
+ }, null, 40, ["title", "width", "config", "values", "disabled"]);
6072
6238
  };
6073
6239
  }
6074
6240
  });
@@ -6085,7 +6251,8 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
6085
6251
  },
6086
6252
  __name: "DataSourceList",
6087
6253
  emits: ["edit", "remove"],
6088
- setup(__props, { expose: __expose, emit }) {
6254
+ setup(__props, { expose: __expose, emit: __emit }) {
6255
+ const emit = __emit;
6089
6256
  const { depService, editorService, dataSourceService } = inject("services") || {};
6090
6257
  const editable = computed(() => dataSourceService?.get("editable") ?? true);
6091
6258
  const dataSources = computed(() => dataSourceService?.get("dataSources") || []);
@@ -6111,9 +6278,9 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
6111
6278
  };
6112
6279
  const list = computed(
6113
6280
  () => dataSources.value.map((ds) => {
6114
- const dsDeps = dsDep.value[ds.id].deps;
6115
- const dsMethodDeps = dsMethodDep.value[ds.id].deps;
6116
- const dsCondDeps = dsCondDep.value[ds.id].deps;
6281
+ const dsDeps = dsDep.value[ds.id]?.deps || {};
6282
+ const dsMethodDeps = dsMethodDep.value[ds.id]?.deps || {};
6283
+ const dsCondDeps = dsCondDep.value[ds.id]?.deps || {};
6117
6284
  const children = [];
6118
6285
  mergeChildren(children, dsDeps);
6119
6286
  mergeChildren(children, dsMethodDeps, "method");
@@ -6235,6 +6402,9 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
6235
6402
  name: "MEditorDataSourceListPanel"
6236
6403
  },
6237
6404
  __name: "DataSourceListPanel",
6405
+ props: {
6406
+ slideType: {}
6407
+ },
6238
6408
  setup(__props) {
6239
6409
  const { dataSourceService } = inject("services") || {};
6240
6410
  const editDialog = ref();
@@ -6269,7 +6439,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
6269
6439
  dataSourceValues.value = {
6270
6440
  ...dataSourceService?.getDataSourceById(id)
6271
6441
  };
6272
- dialogTitle.value = `新增${dataSourceValues.value.title || ""}`;
6442
+ dialogTitle.value = `编辑${dataSourceValues.value.title || ""}`;
6273
6443
  editDialog.value.show();
6274
6444
  };
6275
6445
  const removeHandler = (id) => {
@@ -6288,64 +6458,62 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
6288
6458
  dataSourceList.value?.filter(val);
6289
6459
  };
6290
6460
  return (_ctx, _cache) => {
6291
- return openBlock(), createBlock(unref(TMagicScrollbar), { class: "data-source-list-panel m-editor-dep-list-panel" }, {
6292
- default: withCtx(() => [
6293
- createElementVNode("div", _hoisted_1$d, [
6294
- createVNode(_sfc_main$u, { onSearch: filterTextChangeHandler }),
6295
- editable.value ? (openBlock(), createBlock(unref(TMagicPopover), {
6296
- key: 0,
6297
- placement: "right"
6298
- }, {
6299
- reference: withCtx(() => [
6300
- createVNode(unref(TMagicButton), {
6301
- type: "primary",
6302
- size: "small"
6303
- }, {
6304
- default: withCtx(() => [
6305
- createTextVNode("新增")
6306
- ]),
6307
- _: 1
6308
- })
6309
- ]),
6310
- default: withCtx(() => [
6311
- createElementVNode("div", _hoisted_2$a, [
6312
- (openBlock(true), createElementBlock(Fragment, null, renderList(datasourceTypeList.value, (item, index) => {
6313
- return openBlock(), createBlock(_sfc_main$x, {
6314
- data: {
6315
- type: "button",
6316
- text: item.text,
6317
- handler: () => {
6318
- addHandler(item.type);
6319
- }
6320
- },
6321
- key: index
6322
- }, null, 8, ["data"]);
6323
- }), 128))
6324
- ])
6325
- ]),
6326
- _: 1
6327
- })) : createCommentVNode("", true)
6328
- ]),
6329
- createVNode(_sfc_main$o, {
6330
- onEdit: editHandler,
6331
- onRemove: removeHandler
6332
- }, {
6333
- "data-source-panel-tool": withCtx(({ data }) => [
6334
- renderSlot(_ctx.$slots, "data-source-panel-tool", { data })
6461
+ return openBlock(), createElementBlock(Fragment, null, [
6462
+ createVNode(unref(TMagicScrollbar), { class: "data-source-list-panel m-editor-dep-list-panel" }, {
6463
+ default: withCtx(() => [
6464
+ createElementVNode("div", _hoisted_1$d, [
6465
+ createVNode(_sfc_main$u, { onSearch: filterTextChangeHandler }),
6466
+ editable.value ? (openBlock(), createBlock(unref(TMagicPopover), {
6467
+ key: 0,
6468
+ placement: "right"
6469
+ }, {
6470
+ reference: withCtx(() => [
6471
+ createVNode(unref(TMagicButton), {
6472
+ type: "primary",
6473
+ size: "small"
6474
+ }, {
6475
+ default: withCtx(() => [
6476
+ createTextVNode("新增")
6477
+ ]),
6478
+ _: 1
6479
+ })
6480
+ ]),
6481
+ default: withCtx(() => [
6482
+ createElementVNode("div", _hoisted_2$a, [
6483
+ (openBlock(true), createElementBlock(Fragment, null, renderList(datasourceTypeList.value, (item, index) => {
6484
+ return openBlock(), createBlock(_sfc_main$x, {
6485
+ data: {
6486
+ type: "button",
6487
+ text: item.text,
6488
+ handler: () => {
6489
+ addHandler(item.type);
6490
+ }
6491
+ },
6492
+ key: index
6493
+ }, null, 8, ["data"]);
6494
+ }), 128))
6495
+ ])
6496
+ ]),
6497
+ _: 1
6498
+ })) : createCommentVNode("", true)
6335
6499
  ]),
6336
- _: 3
6337
- }),
6338
- createVNode(_sfc_main$p, {
6339
- ref_key: "editDialog",
6340
- ref: editDialog,
6341
- disabled: !editable.value,
6342
- values: dataSourceValues.value,
6343
- title: dialogTitle.value,
6344
- onSubmit: submitDataSourceHandler
6345
- }, null, 8, ["disabled", "values", "title"])
6346
- ]),
6347
- _: 3
6348
- });
6500
+ createVNode(_sfc_main$o, {
6501
+ onEdit: editHandler,
6502
+ onRemove: removeHandler
6503
+ })
6504
+ ]),
6505
+ _: 1
6506
+ }),
6507
+ createVNode(_sfc_main$p, {
6508
+ ref_key: "editDialog",
6509
+ ref: editDialog,
6510
+ disabled: !editable.value,
6511
+ values: dataSourceValues.value,
6512
+ title: dialogTitle.value,
6513
+ slideType: _ctx.slideType,
6514
+ onSubmit: submitDataSourceHandler
6515
+ }, null, 8, ["disabled", "values", "title", "slideType"])
6516
+ ], 64);
6349
6517
  };
6350
6518
  }
6351
6519
  });
@@ -6379,9 +6547,9 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
6379
6547
  indent: { default: 0 }
6380
6548
  },
6381
6549
  emits: ["node-dragstart", "node-dragleave", "node-dragend", "node-contextmenu", "node-mouseenter", "node-click"],
6382
- setup(__props, { emit }) {
6383
- const props = __props;
6550
+ setup(__props, { emit: __emit }) {
6384
6551
  const treeEmit = inject("treeEmit");
6552
+ const props = __props;
6385
6553
  const nodeStatus = computed(
6386
6554
  () => props.nodeStatusMap?.get(props.data.id) || {
6387
6555
  selected: false,
@@ -6491,7 +6659,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
6491
6659
  emptyText: { default: "暂无数据" }
6492
6660
  },
6493
6661
  emits: ["node-dragover", "node-dragstart", "node-dragleave", "node-dragend", "node-contextmenu", "node-mouseenter", "node-click"],
6494
- setup(__props, { emit }) {
6662
+ setup(__props, { emit: __emit }) {
6663
+ const emit = __emit;
6495
6664
  provide("treeEmit", emit);
6496
6665
  const handleDragOver = (event) => {
6497
6666
  emit("node-dragover", event);
@@ -6536,8 +6705,9 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
6536
6705
  autoHide: { type: Boolean, default: true }
6537
6706
  },
6538
6707
  emits: ["hide", "show", "mouseenter"],
6539
- setup(__props, { expose: __expose, emit }) {
6708
+ setup(__props, { expose: __expose, emit: __emit }) {
6540
6709
  const props = __props;
6710
+ const emit = __emit;
6541
6711
  const menu = ref();
6542
6712
  const buttons = ref();
6543
6713
  const subMenu = ref();
@@ -6805,8 +6975,9 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
6805
6975
  layerContentMenu: {}
6806
6976
  },
6807
6977
  emits: ["collapse-all"],
6808
- setup(__props, { expose: __expose, emit }) {
6978
+ setup(__props, { expose: __expose, emit: __emit }) {
6809
6979
  const props = __props;
6980
+ const emit = __emit;
6810
6981
  const services = inject("services");
6811
6982
  const menu = ref();
6812
6983
  const node = computed(() => services?.editorService.get("node"));
@@ -7089,6 +7260,9 @@ const useDrag = (services) => {
7089
7260
  return;
7090
7261
  removeStatusClass(dragState.container);
7091
7262
  if (node && dragState.dragOverNodeId && dragState.dropType && services) {
7263
+ if (dragState.dragOverNodeId === node.id) {
7264
+ return;
7265
+ }
7092
7266
  const targetInfo = services.editorService.getNodeInfo(dragState.dragOverNodeId, false);
7093
7267
  const targetNode = targetInfo.node;
7094
7268
  let targetParent = targetInfo.parent;
@@ -7324,7 +7498,7 @@ const useKeybinding = (services, contianer) => {
7324
7498
  };
7325
7499
  };
7326
7500
 
7327
- const createPageNodeStatus = (services, pageId) => {
7501
+ const createPageNodeStatus = (services, pageId, initalLayerNodeStatus) => {
7328
7502
  const map = /* @__PURE__ */ new Map();
7329
7503
  map.set(pageId, {
7330
7504
  visible: true,
@@ -7334,12 +7508,15 @@ const createPageNodeStatus = (services, pageId) => {
7334
7508
  });
7335
7509
  services?.editorService.getNodeById(pageId)?.items.forEach(
7336
7510
  (node) => traverseNode(node, (node2) => {
7337
- map.set(node2.id, {
7338
- visible: true,
7339
- expand: false,
7340
- selected: false,
7341
- draggable: true
7342
- });
7511
+ map.set(
7512
+ node2.id,
7513
+ initalLayerNodeStatus?.get(node2.id) || {
7514
+ visible: true,
7515
+ expand: false,
7516
+ selected: false,
7517
+ draggable: true
7518
+ }
7519
+ );
7343
7520
  })
7344
7521
  );
7345
7522
  return map;
@@ -7351,12 +7528,12 @@ const useNodeStatus = (services, page) => {
7351
7528
  () => page.value ? nodeStatusMaps.value.get(page.value.id) : /* @__PURE__ */ new Map()
7352
7529
  );
7353
7530
  watch(
7354
- () => page.value?.id,
7355
- (pageId) => {
7356
- if (!pageId || nodeStatusMaps.value.has(pageId)) {
7531
+ page,
7532
+ (page2) => {
7533
+ if (!page2) {
7357
7534
  return;
7358
7535
  }
7359
- nodeStatusMaps.value.set(pageId, createPageNodeStatus(services, pageId));
7536
+ nodeStatusMaps.value.set(page2.id, createPageNodeStatus(services, page2.id, nodeStatusMaps.value.get(page2.id)));
7360
7537
  },
7361
7538
  {
7362
7539
  immediate: true
@@ -7629,11 +7806,14 @@ const _hoisted_1$8 = {
7629
7806
  class: "m-editor-sidebar"
7630
7807
  };
7631
7808
  const _hoisted_2$6 = { class: "m-editor-sidebar-header" };
7632
- const _hoisted_3$3 = ["onClick"];
7809
+ const _hoisted_3$3 = ["onClick", "onDragend"];
7633
7810
  const _hoisted_4$3 = {
7634
7811
  key: 1,
7635
7812
  class: "magic-editor-tab-panel-title"
7636
7813
  };
7814
+ const _hoisted_5$3 = { class: "m-editor-float-box-list" };
7815
+ const _hoisted_6$2 = ["onClick"];
7816
+ const _hoisted_7 = { class: "m-editor-float-box-body" };
7637
7817
  const _sfc_main$e = /* @__PURE__ */ defineComponent({
7638
7818
  ...{
7639
7819
  name: "MEditorSidebar"
@@ -7645,6 +7825,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
7645
7825
  },
7646
7826
  setup(__props, { expose: __expose }) {
7647
7827
  const props = __props;
7828
+ const services = inject("services");
7648
7829
  const activeTabName = ref(props.data?.status);
7649
7830
  const getItemConfig = (data) => {
7650
7831
  const map = {
@@ -7673,7 +7854,12 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
7673
7854
  icon: EditPen,
7674
7855
  text: "代码编辑",
7675
7856
  component: _sfc_main$q,
7676
- slots: {}
7857
+ slots: {},
7858
+ boxComponentConfig: {
7859
+ props: {
7860
+ slideType: "box"
7861
+ }
7862
+ }
7677
7863
  },
7678
7864
  "data-source": {
7679
7865
  $key: "data-source",
@@ -7681,7 +7867,12 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
7681
7867
  icon: Coin,
7682
7868
  text: "数据源",
7683
7869
  component: _sfc_main$n,
7684
- slots: {}
7870
+ slots: {},
7871
+ boxComponentConfig: {
7872
+ props: {
7873
+ slideType: "box"
7874
+ }
7875
+ }
7685
7876
  }
7686
7877
  };
7687
7878
  return typeof data === "string" ? map[data] : data;
@@ -7693,119 +7884,182 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
7693
7884
  activeTabName.value = status || "0";
7694
7885
  }
7695
7886
  );
7887
+ const slideKeys = computed(() => sideBarItems.value.map((sideBarItem) => sideBarItem.$key));
7888
+ const { showFloatBox, closeFloatBox, dragstartHandler, dragendHandler, floatBoxStates, floatBox, showingBoxKeys } = useFloatBox(slideKeys);
7889
+ watch(
7890
+ () => showingBoxKeys.value.length,
7891
+ () => {
7892
+ const isActiveTabShow = showingBoxKeys.value.some(
7893
+ (key) => activeTabName.value === sideBarItems.value.find((v) => v.$key === key)?.text
7894
+ );
7895
+ if (!isActiveTabShow && activeTabName.value)
7896
+ return;
7897
+ const nextSlideBarItem = sideBarItems.value.find((sideBarItem) => !showingBoxKeys.value.includes(sideBarItem.$key));
7898
+ if (!nextSlideBarItem) {
7899
+ activeTabName.value = "";
7900
+ services?.uiService.set("hideSlideBar", true);
7901
+ return;
7902
+ }
7903
+ services?.uiService.set("hideSlideBar", false);
7904
+ activeTabName.value = nextSlideBarItem?.text;
7905
+ }
7906
+ );
7696
7907
  __expose({
7697
7908
  activeTabName
7698
7909
  });
7699
7910
  return (_ctx, _cache) => {
7700
- return _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
7701
- createElementVNode("div", _hoisted_2$6, [
7911
+ return openBlock(), createElementBlock(Fragment, null, [
7912
+ _ctx.data.type === "tabs" && _ctx.data.items.length ? (openBlock(), createElementBlock("div", _hoisted_1$8, [
7913
+ createElementVNode("div", _hoisted_2$6, [
7914
+ (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
7915
+ return withDirectives((openBlock(), createElementBlock("div", {
7916
+ class: normalizeClass(["m-editor-sidebar-header-item", { "is-active": activeTabName.value === config.text }]),
7917
+ key: config.$key ?? index,
7918
+ onClick: ($event) => activeTabName.value = config.text || `${index}`,
7919
+ draggable: "true",
7920
+ onDragstart: _cache[0] || (_cache[0] = //@ts-ignore
7921
+ (...args) => unref(dragstartHandler) && unref(dragstartHandler)(...args)),
7922
+ onDragend: ($event) => unref(dragendHandler)(config.$key, $event)
7923
+ }, [
7924
+ config.icon ? (openBlock(), createBlock(_sfc_main$N, {
7925
+ key: 0,
7926
+ icon: config.icon
7927
+ }, null, 8, ["icon"])) : createCommentVNode("", true),
7928
+ config.text ? (openBlock(), createElementBlock("div", _hoisted_4$3, toDisplayString(config.text), 1)) : createCommentVNode("", true)
7929
+ ], 42, _hoisted_3$3)), [
7930
+ [vShow, !unref(floatBoxStates)?.get(config.$key)?.status]
7931
+ ]);
7932
+ }), 128))
7933
+ ]),
7702
7934
  (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
7703
- return openBlock(), createElementBlock("div", {
7704
- class: normalizeClass(["m-editor-sidebar-header-item", { "is-active": activeTabName.value === config.text }]),
7705
- key: config.$key ?? index,
7706
- onClick: ($event) => activeTabName.value = config.text || `${index}`
7935
+ return withDirectives((openBlock(), createElementBlock("div", {
7936
+ class: "m-editor-sidebar-content",
7937
+ key: config.$key ?? index
7707
7938
  }, [
7708
- config.icon ? (openBlock(), createBlock(_sfc_main$N, {
7709
- key: 0,
7710
- icon: config.icon
7711
- }, null, 8, ["icon"])) : createCommentVNode("", true),
7712
- config.text ? (openBlock(), createElementBlock("div", _hoisted_4$3, toDisplayString(config.text), 1)) : createCommentVNode("", true)
7713
- ], 10, _hoisted_3$3);
7939
+ config && !unref(floatBoxStates)?.get(config.$key)?.status ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({ key: 0 }, config.props || {}, toHandlers(config?.listeners || {})), createSlots({ _: 2 }, [
7940
+ config.$key === "component-list" || config.slots?.componentListPanelHeader ? {
7941
+ name: "component-list-panel-header",
7942
+ fn: withCtx(() => [
7943
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : config.slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
7944
+ ]),
7945
+ key: "0"
7946
+ } : void 0,
7947
+ config.$key === "component-list" || config.slots?.componentListItem ? {
7948
+ name: "component-list-item",
7949
+ fn: withCtx(({ component }) => [
7950
+ config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
7951
+ key: 0,
7952
+ component
7953
+ }) : config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListItem), {
7954
+ key: 1,
7955
+ component
7956
+ }, null, 8, ["component"])) : createCommentVNode("", true)
7957
+ ]),
7958
+ key: "1"
7959
+ } : void 0,
7960
+ config.$key === "layer" || config.slots?.layerPanelHeader ? {
7961
+ name: "layer-panel-header",
7962
+ fn: withCtx(() => [
7963
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
7964
+ ]),
7965
+ key: "2"
7966
+ } : void 0,
7967
+ config.$key === "code-block" || config.slots?.codeBlockPanelHeader ? {
7968
+ name: "code-block-panel-header",
7969
+ fn: withCtx(() => [
7970
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : config.slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
7971
+ ]),
7972
+ key: "3"
7973
+ } : void 0,
7974
+ config.$key === "code-block" || config.slots?.codeBlockPanelTool ? {
7975
+ name: "code-block-panel-tool",
7976
+ fn: withCtx(({ id, data }) => [
7977
+ config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
7978
+ key: 0,
7979
+ id,
7980
+ data
7981
+ }) : config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
7982
+ ]),
7983
+ key: "4"
7984
+ } : void 0,
7985
+ config.$key === "layer" || config.slots?.layerNodeContent ? {
7986
+ name: "layer-node-content",
7987
+ fn: withCtx(({ data: nodeData }) => [
7988
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
7989
+ key: 0,
7990
+ data: nodeData
7991
+ }) : config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeContent), {
7992
+ key: 1,
7993
+ data: nodeData
7994
+ }, null, 8, ["data"])) : createCommentVNode("", true)
7995
+ ]),
7996
+ key: "5"
7997
+ } : void 0,
7998
+ config.$key === "layer" || config.slots?.layerNodeTool ? {
7999
+ name: "layer-node-tool",
8000
+ fn: withCtx(({ data: nodeData }) => [
8001
+ config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-tool", {
8002
+ key: 0,
8003
+ data: nodeData
8004
+ }) : config.slots?.layerNodeTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeTool), {
8005
+ key: 1,
8006
+ data: nodeData
8007
+ }, null, 8, ["data"])) : createCommentVNode("", true)
8008
+ ]),
8009
+ key: "6"
8010
+ } : void 0,
8011
+ config.$key === "data-source" || config.slots?.codeBlockPanelTool ? {
8012
+ name: "data-source-panel-tool",
8013
+ fn: withCtx(({ data }) => [
8014
+ config.$key === "data-source" ? renderSlot(_ctx.$slots, "data-source-panel-tool", {
8015
+ key: 0,
8016
+ data
8017
+ }) : config.slots?.DataSourcePanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.DataSourcePanelTool), { key: 1 })) : createCommentVNode("", true)
8018
+ ]),
8019
+ key: "7"
8020
+ } : void 0
8021
+ ]), 1040)) : createCommentVNode("", true)
8022
+ ])), [
8023
+ [vShow, activeTabName.value === config.text]
8024
+ ]);
7714
8025
  }), 128))
7715
- ]),
7716
- (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
7717
- return withDirectives((openBlock(), createElementBlock("div", {
7718
- class: "m-editor-sidebar-content",
7719
- key: config.$key ?? index
7720
- }, [
7721
- config ? (openBlock(), createBlock(resolveDynamicComponent(config.component), mergeProps({ key: 0 }, config.props || {}, toHandlers(config?.listeners || {})), createSlots({ _: 2 }, [
7722
- config.$key === "component-list" || config.slots?.componentListPanelHeader ? {
7723
- name: "component-list-panel-header",
7724
- fn: withCtx(() => [
7725
- config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-panel-header", { key: 0 }) : config.slots?.componentListPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListPanelHeader), { key: 1 })) : createCommentVNode("", true)
7726
- ]),
7727
- key: "0"
7728
- } : void 0,
7729
- config.$key === "component-list" || config.slots?.componentListItem ? {
7730
- name: "component-list-item",
7731
- fn: withCtx(({ component }) => [
7732
- config.$key === "component-list" ? renderSlot(_ctx.$slots, "component-list-item", {
7733
- key: 0,
7734
- component
7735
- }) : config.slots?.componentListItem ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.componentListItem), {
7736
- key: 1,
7737
- component
7738
- }, null, 8, ["component"])) : createCommentVNode("", true)
7739
- ]),
7740
- key: "1"
7741
- } : void 0,
7742
- config.$key === "layer" || config.slots?.layerPanelHeader ? {
7743
- name: "layer-panel-header",
7744
- fn: withCtx(() => [
7745
- config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-panel-header", { key: 0 }) : config.slots?.layerPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerPanelHeader), { key: 1 })) : createCommentVNode("", true)
7746
- ]),
7747
- key: "2"
7748
- } : void 0,
7749
- config.$key === "code-block" || config.slots?.codeBlockPanelHeader ? {
7750
- name: "code-block-panel-header",
7751
- fn: withCtx(() => [
7752
- config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-header", { key: 0 }) : config.slots?.codeBlockPanelHeader ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelHeader), { key: 1 })) : createCommentVNode("", true)
7753
- ]),
7754
- key: "3"
7755
- } : void 0,
7756
- config.$key === "code-block" || config.slots?.codeBlockPanelTool ? {
7757
- name: "code-block-panel-tool",
7758
- fn: withCtx(({ id, data }) => [
7759
- config.$key === "code-block" ? renderSlot(_ctx.$slots, "code-block-panel-tool", {
7760
- key: 0,
7761
- id,
7762
- data
7763
- }) : config.slots?.codeBlockPanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.codeBlockPanelTool), { key: 1 })) : createCommentVNode("", true)
7764
- ]),
7765
- key: "4"
7766
- } : void 0,
7767
- config.$key === "layer" || config.slots?.layerNodeContent ? {
7768
- name: "layer-node-content",
7769
- fn: withCtx(({ data: nodeData }) => [
7770
- config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-content", {
7771
- key: 0,
7772
- data: nodeData
7773
- }) : config.slots?.layerNodeContent ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeContent), {
7774
- key: 1,
7775
- data: nodeData
7776
- }, null, 8, ["data"])) : createCommentVNode("", true)
7777
- ]),
7778
- key: "5"
7779
- } : void 0,
7780
- config.$key === "layer" || config.slots?.layerNodeTool ? {
7781
- name: "layer-node-tool",
7782
- fn: withCtx(({ data: nodeData }) => [
7783
- config.$key === "layer" ? renderSlot(_ctx.$slots, "layer-node-tool", {
7784
- key: 0,
7785
- data: nodeData
7786
- }) : config.slots?.layerNodeTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.layerNodeTool), {
7787
- key: 1,
7788
- data: nodeData
7789
- }, null, 8, ["data"])) : createCommentVNode("", true)
7790
- ]),
7791
- key: "6"
7792
- } : void 0,
7793
- config.$key === "data-source" || config.slots?.codeBlockPanelTool ? {
7794
- name: "data-source-panel-tool",
7795
- fn: withCtx(({ data }) => [
7796
- config.$key === "data-source" ? renderSlot(_ctx.$slots, "data-source-panel-tool", {
7797
- key: 0,
7798
- data
7799
- }) : config.slots?.DataSourcePanelTool ? (openBlock(), createBlock(resolveDynamicComponent(config.slots.DataSourcePanelTool), { key: 1 })) : createCommentVNode("", true)
7800
- ]),
7801
- key: "7"
7802
- } : void 0
7803
- ]), 1040)) : createCommentVNode("", true)
7804
- ])), [
7805
- [vShow, activeTabName.value === config.text]
7806
- ]);
7807
- }), 128))
7808
- ])) : createCommentVNode("", true);
8026
+ ])) : createCommentVNode("", true),
8027
+ (openBlock(), createBlock(Teleport, { to: "body" }, [
8028
+ createElementVNode("div", _hoisted_5$3, [
8029
+ (openBlock(true), createElementBlock(Fragment, null, renderList(sideBarItems.value, (config, index) => {
8030
+ return withDirectives((openBlock(), createElementBlock("div", {
8031
+ key: config.$key ?? index,
8032
+ ref_for: true,
8033
+ ref_key: "floatBox",
8034
+ ref: floatBox,
8035
+ class: normalizeClass(["m-editor-float-box", `m-editor-float-box-${config.$key}`]),
8036
+ style: normalizeStyle({
8037
+ left: `${unref(floatBoxStates)?.get(config.$key)?.left}px`,
8038
+ top: `${unref(floatBoxStates)?.get(config.$key)?.top}px`,
8039
+ zIndex: unref(floatBoxStates)?.get(config.$key)?.zIndex
8040
+ })
8041
+ }, [
8042
+ createElementVNode("div", {
8043
+ class: normalizeClass(["m-editor-float-box-header", `m-editor-float-box-header-${config.$key}`]),
8044
+ onClick: ($event) => unref(showFloatBox)(config.$key)
8045
+ }, [
8046
+ createElementVNode("div", null, toDisplayString(config.text), 1),
8047
+ createVNode(_sfc_main$N, {
8048
+ class: "m-editor-float-box-close",
8049
+ icon: unref(Close),
8050
+ onClick: withModifiers(($event) => unref(closeFloatBox)(config.$key), ["stop"])
8051
+ }, null, 8, ["icon", "onClick"])
8052
+ ], 10, _hoisted_6$2),
8053
+ createElementVNode("div", _hoisted_7, [
8054
+ config && unref(floatBoxStates)?.get(config.$key)?.status ? (openBlock(), createBlock(resolveDynamicComponent(config.boxComponentConfig?.component || config.component), mergeProps({ key: 0 }, config.boxComponentConfig?.props || config.props || {}, toHandlers(config?.listeners || {})), null, 16)) : createCommentVNode("", true)
8055
+ ])
8056
+ ], 6)), [
8057
+ [vShow, unref(floatBoxStates)?.get(config.$key)?.status]
8058
+ ]);
8059
+ }), 128))
8060
+ ])
8061
+ ]))
8062
+ ], 64);
7809
8063
  };
7810
8064
  }
7811
8065
  });
@@ -7950,8 +8204,9 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
7950
8204
  pos: {}
7951
8205
  },
7952
8206
  emits: ["scroll"],
7953
- setup(__props, { emit }) {
8207
+ setup(__props, { emit: __emit }) {
7954
8208
  const props = __props;
8209
+ const emit = __emit;
7955
8210
  const bar = ref();
7956
8211
  const thumb = ref();
7957
8212
  const thumbSize = computed(() => props.size * (props.size / props.scrollSize));
@@ -8153,7 +8408,9 @@ const state = reactive({
8153
8408
  showGuides: true,
8154
8409
  showRule: true,
8155
8410
  propsPanelSize: "small",
8156
- showAddPageButton: true
8411
+ showAddPageButton: true,
8412
+ floatBox: /* @__PURE__ */ new Map(),
8413
+ hideSlideBar: false
8157
8414
  });
8158
8415
  class Ui extends BaseService {
8159
8416
  constructor() {
@@ -8193,6 +8450,19 @@ class Ui extends BaseService {
8193
8450
  }
8194
8451
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
8195
8452
  }
8453
+ async setFloatBox(keys) {
8454
+ const map = state.floatBox;
8455
+ for (const key of keys) {
8456
+ if (map.get(key))
8457
+ continue;
8458
+ map.set(key, {
8459
+ status: false,
8460
+ zIndex: 99,
8461
+ top: 0,
8462
+ left: 0
8463
+ });
8464
+ }
8465
+ }
8196
8466
  resetState() {
8197
8467
  this.set("showSrc", false);
8198
8468
  this.set("uiSelectMode", false);
@@ -8405,8 +8675,9 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
8405
8675
  pinned: { type: Boolean }
8406
8676
  },
8407
8677
  emits: ["close", "update:pinned", "change"],
8408
- setup(__props, { emit }) {
8678
+ setup(__props, { emit: __emit }) {
8409
8679
  const props = __props;
8680
+ const emit = __emit;
8410
8681
  const pinHandler = () => {
8411
8682
  emit("update:pinned", !props.pinned);
8412
8683
  };
@@ -9469,254 +9740,41 @@ class ComponentList extends BaseService {
9469
9740
  }
9470
9741
  const componentListService = new ComponentList();
9471
9742
 
9472
- class Target extends EventEmitter {
9473
- /**
9474
- * 如何识别目标
9475
- */
9476
- isTarget;
9477
- /**
9478
- * 目标id,不可重复
9479
- * 例如目标是代码块,则为代码块id
9480
- */
9481
- id;
9482
- /**
9483
- * 目标名称,用于显示在依赖列表中
9484
- */
9485
- name;
9486
- /**
9487
- * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type
9488
- */
9489
- type = DepTargetType.DEFAULT;
9490
- /**
9491
- * 依赖详情
9492
- * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }
9493
- */
9494
- deps = reactive({});
9495
- constructor(options) {
9496
- super();
9497
- this.isTarget = options.isTarget;
9498
- this.id = options.id;
9499
- this.name = options.name;
9500
- if (options.type) {
9501
- this.type = options.type;
9502
- }
9503
- }
9504
- /**
9505
- * 更新依赖
9506
- * @param node 节点配置
9507
- * @param key 哪个key配置了这个目标的id
9508
- */
9509
- updateDep(node, key) {
9510
- const dep = this.deps[node.id] || {
9511
- name: node.name,
9512
- keys: []
9513
- };
9514
- if (node.name) {
9515
- dep.name = node.name;
9516
- }
9517
- this.deps[node.id] = dep;
9518
- if (dep.keys.indexOf(key) === -1) {
9519
- dep.keys.push(key);
9520
- }
9521
- this.emit("change");
9522
- }
9523
- /**
9524
- * 删除依赖
9525
- * @param node 哪个节点的依赖需要移除,如果为空,则移除所有依赖
9526
- * @param key 节点下哪个key需要移除,如果为空,则移除改节点下的所有依赖key
9527
- * @returns void
9528
- */
9529
- removeDep(node, key) {
9530
- if (!node) {
9531
- Object.keys(this.deps).forEach((depKey) => {
9532
- delete this.deps[depKey];
9533
- });
9534
- this.emit("change");
9535
- return;
9536
- }
9537
- const dep = this.deps[node.id];
9538
- if (!dep)
9539
- return;
9540
- if (key) {
9541
- const index = dep.keys.indexOf(key);
9542
- dep.keys.splice(index, 1);
9543
- if (dep.keys.length === 0) {
9544
- delete this.deps[node.id];
9545
- }
9546
- } else {
9547
- delete this.deps[node.id];
9548
- }
9549
- this.emit("change");
9550
- }
9551
- /**
9552
- * 判断指定节点下的指定key是否存在在依赖列表中
9553
- * @param node 哪个节点
9554
- * @param key 哪个key
9555
- * @returns boolean
9556
- */
9557
- hasDep(node, key) {
9558
- const dep = this.deps[node.id];
9559
- return Boolean(dep?.keys.find((d) => d === key));
9560
- }
9561
- destroy() {
9562
- this.removeAllListeners();
9743
+ class Dep extends BaseService {
9744
+ watcher = new Watcher({ initialTargets: reactive({}) });
9745
+ removeTargets(type = DepTargetType.DEFAULT) {
9746
+ this.watcher.removeTargets(type);
9747
+ this.emit("remove-target");
9563
9748
  }
9564
- }
9565
- class Watcher extends EventEmitter {
9566
- targets = reactive({});
9567
- /**
9568
- * 获取指定类型中的所有target
9569
- * @param type 分类
9570
- * @returns Target[]
9571
- */
9572
9749
  getTargets(type = DepTargetType.DEFAULT) {
9573
- return this.targets[type] || {};
9574
- }
9575
- /**
9576
- * 添加新的目标
9577
- * @param target Target
9578
- */
9579
- addTarget(target) {
9580
- const targets = this.getTargets(target.type) || {};
9581
- this.targets[target.type] = targets;
9582
- targets[target.id] = target;
9583
- this.emit("add-target", target);
9750
+ return this.watcher.getTargets(type);
9584
9751
  }
9585
- /**
9586
- * 获取指定id的target
9587
- * @param id target id
9588
- * @returns Target
9589
- */
9590
9752
  getTarget(id) {
9591
- const allTargets = Object.values(this.targets);
9592
- for (const targets of allTargets) {
9593
- if (targets[id]) {
9594
- return targets[id];
9595
- }
9596
- }
9753
+ return this.watcher.getTarget(id);
9597
9754
  }
9598
- /**
9599
- * 判断是否存在指定id的target
9600
- * @param id target id
9601
- * @returns boolean
9602
- */
9603
- hasTarget(id) {
9604
- const allTargets = Object.values(this.targets);
9605
- for (const targets of allTargets) {
9606
- if (targets[id]) {
9607
- return true;
9608
- }
9609
- }
9610
- return false;
9755
+ addTarget(target) {
9756
+ this.watcher.addTarget(target);
9757
+ this.emit("add-target", target);
9611
9758
  }
9612
- /**
9613
- * 删除指定id的target
9614
- * @param id target id
9615
- */
9616
9759
  removeTarget(id) {
9617
- const allTargets = Object.values(this.targets);
9618
- for (const targets of allTargets) {
9619
- if (targets[id]) {
9620
- targets[id].destroy();
9621
- delete targets[id];
9622
- }
9623
- }
9624
- this.emit("remove-target");
9625
- }
9626
- /**
9627
- * 删除指定分类的所有target
9628
- * @param type 分类
9629
- * @returns void
9630
- */
9631
- removeTargets(type = DepTargetType.DEFAULT) {
9632
- const targets = this.targets[type];
9633
- if (!targets)
9634
- return;
9635
- for (const target of Object.values(targets)) {
9636
- target.destroy();
9637
- }
9638
- delete this.targets[type];
9760
+ this.watcher.removeTarget(id);
9639
9761
  this.emit("remove-target");
9640
9762
  }
9641
- /**
9642
- * 删除所有target
9643
- */
9644
9763
  clearTargets() {
9645
- Object.keys(this.targets).forEach((key) => {
9646
- delete this.targets[key];
9647
- });
9764
+ this.watcher.clearTargets();
9648
9765
  }
9649
- /**
9650
- * 收集依赖
9651
- * @param nodes 需要收集的节点
9652
- * @param deep 是否需要收集子节点
9653
- */
9654
9766
  collect(nodes, deep = false) {
9655
- Object.values(this.targets).forEach((targets) => {
9656
- Object.values(targets).forEach((target) => {
9657
- nodes.forEach((node) => {
9658
- target.removeDep(node);
9659
- this.collectItem(node, target, deep);
9660
- });
9661
- });
9662
- });
9767
+ this.watcher.collect(nodes, deep);
9663
9768
  this.emit("collected", nodes, deep);
9664
9769
  }
9665
- /**
9666
- * 清除依赖
9667
- * @param nodes 需要清除依赖的节点
9668
- */
9669
9770
  clear(nodes) {
9670
- const clearedItemsNodeIds = [];
9671
- Object.values(this.targets).forEach((targets) => {
9672
- Object.values(targets).forEach((target) => {
9673
- if (nodes) {
9674
- nodes.forEach((node) => {
9675
- target.removeDep(node);
9676
- if (Array.isArray(node.items) && node.items.length && !clearedItemsNodeIds.includes(node.id)) {
9677
- clearedItemsNodeIds.push(node.id);
9678
- this.clear(node.items);
9679
- }
9680
- });
9681
- } else {
9682
- target.removeDep();
9683
- }
9684
- });
9685
- });
9771
+ return this.watcher.clear(nodes);
9686
9772
  }
9687
- collectItem(node, target, deep = false) {
9688
- const collectTarget = (config, prop = "") => {
9689
- const doCollect = (key, value) => {
9690
- const keyIsItems = key === "items";
9691
- const fullKey = prop ? `${prop}.${key}` : key;
9692
- if (target.isTarget(fullKey, value)) {
9693
- target.updateDep(node, fullKey);
9694
- this.emit("update-dep", node, fullKey);
9695
- } else if (!keyIsItems && Array.isArray(value)) {
9696
- value.forEach((item, index) => {
9697
- if (isObject$1(item)) {
9698
- collectTarget(item, `${fullKey}.${index}`);
9699
- }
9700
- });
9701
- } else if (isObject$1(value)) {
9702
- collectTarget(value, fullKey);
9703
- }
9704
- if (keyIsItems && deep && Array.isArray(value)) {
9705
- value.forEach((child) => {
9706
- this.collectItem(child, target, deep);
9707
- });
9708
- }
9709
- };
9710
- Object.entries(config).forEach(([key, value]) => {
9711
- if (typeof value === "undefined" || value === "")
9712
- return;
9713
- doCollect(key, value);
9714
- });
9715
- };
9716
- collectTarget(node);
9773
+ hasTarget(id) {
9774
+ return this.watcher.hasTarget(id);
9717
9775
  }
9718
9776
  }
9719
- const depService = new Watcher();
9777
+ const depService = new Dep();
9720
9778
 
9721
9779
  let eventMap = reactive({});
9722
9780
  let methodMap = reactive({});
@@ -9940,61 +9998,6 @@ const defaultEditorProps = {
9940
9998
  codeOptions: () => ({})
9941
9999
  };
9942
10000
 
9943
- const createCodeBlockTarget = (id, codeBlock) => new Target({
9944
- type: DepTargetType.CODE_BLOCK,
9945
- id,
9946
- name: codeBlock.name,
9947
- isTarget: (key, value) => {
9948
- if (id === value) {
9949
- return true;
9950
- }
9951
- if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
9952
- const index = value.hookData.findIndex((item) => item.codeId === id);
9953
- return Boolean(index > -1);
9954
- }
9955
- return false;
9956
- }
9957
- });
9958
- const createDataSourceTarget = (id) => new Target({
9959
- type: DepTargetType.DATA_SOURCE,
9960
- id,
9961
- isTarget: (key, value) => {
9962
- if (value?.isBindDataSource && value.dataSourceId || typeof value === "string" && value.includes(`${id}`)) {
9963
- return true;
9964
- }
9965
- if (!Array.isArray(value) || typeof value[0] !== "string") {
9966
- return false;
9967
- }
9968
- const [prefixId] = value;
9969
- const prefixIndex = prefixId.indexOf(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX);
9970
- if (prefixIndex === -1) {
9971
- return false;
9972
- }
9973
- const dsId = prefixId.substring(prefixIndex + DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX.length);
9974
- return dsId === id && Boolean(dataSourceService.getDataSourceById(id));
9975
- }
9976
- });
9977
- const createDataSourceCondTarget = (id) => new Target({
9978
- type: DepTargetType.DATA_SOURCE_COND,
9979
- id,
9980
- isTarget: (key, value) => {
9981
- if (!Array.isArray(value) || value[0] !== id || !`${key}`.startsWith("displayConds"))
9982
- return false;
9983
- const ds = dataSourceService.getDataSourceById(id);
9984
- return Boolean(ds?.fields?.find((field) => field.name === value[1]));
9985
- }
9986
- });
9987
- const createDataSourceMethodTarget = (id) => new Target({
9988
- type: DepTargetType.DATA_SOURCE_METHOD,
9989
- id,
9990
- isTarget: (key, value) => {
9991
- if (!Array.isArray(value) || value[0] !== id)
9992
- return false;
9993
- const ds = dataSourceService.getDataSourceById(id);
9994
- return Boolean(ds?.methods?.find((method) => method.name === value[1]));
9995
- }
9996
- });
9997
-
9998
10001
  const initServiceState = (props, {
9999
10002
  editorService,
10000
10003
  historyService,
@@ -10200,9 +10203,9 @@ const initServiceEvents = (props, emit, { editorService, codeBlockService, dataS
10200
10203
  depService.on("dep-update", depUpdateHandler);
10201
10204
  depService.on("collected", collectedHandler);
10202
10205
  const initDataSourceDepTarget = (ds) => {
10203
- depService.addTarget(createDataSourceTarget(ds.id));
10204
- depService.addTarget(createDataSourceMethodTarget(ds.id));
10205
- depService.addTarget(createDataSourceCondTarget(ds.id));
10206
+ depService.addTarget(createDataSourceTarget(ds, reactive({})));
10207
+ depService.addTarget(createDataSourceMethodTarget(ds, reactive({})));
10208
+ depService.addTarget(createDataSourceCondTarget(ds, reactive({})));
10206
10209
  };
10207
10210
  const rootChangeHandler = async (value, preValue) => {
10208
10211
  if (!value)
@@ -10342,7 +10345,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
10342
10345
  extendFormState: { type: Function }
10343
10346
  }, defaultEditorProps),
10344
10347
  emits: ["props-panel-mounted", "update:modelValue"],
10345
- setup(__props, { expose: __expose, emit }) {
10348
+ setup(__props, { expose: __expose, emit: __emit }) {
10349
+ const emit = __emit;
10346
10350
  const props = __props;
10347
10351
  const services = {
10348
10352
  componentListService,
@@ -10510,5 +10514,5 @@ const index = {
10510
10514
  }
10511
10515
  };
10512
10516
 
10513
- export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$P as CodeBlockEditor, _sfc_main$r as CodeBlockList, _sfc_main$q as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$Q as CodeSelect, _sfc_main$M as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$k as ContentMenu, _sfc_main$K as DataSourceFieldSelect, _sfc_main$L as DataSourceFields, _sfc_main$J as DataSourceInput, _sfc_main$H as DataSourceMethodSelect, _sfc_main$I as DataSourceMethods, _sfc_main$G as DataSourceMocks, _sfc_main$F as DataSourceSelect, DepTargetType, DragType, _sfc_main$E as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$N as Icon, KeyBindingCommand, _sfc_main$D as KeyValue, Keys, LayerOffset, _sfc_main$g as LayerPanel, Layout, _sfc_main$A as LayoutContainer, _sfc_main$v as PropsPanel, _sfc_main$B as Resizer, _sfc_main$A as SplitView, _sfc_main$T as TMagicCodeEditor, _sfc_main as TMagicEditor, _sfc_main$x as ToolButton, UI_SELECT_MODE_EVENT_NAME, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, error, eventTabConfig, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getDisplayField, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setChilrenLayout, setConfig, setLayout, storageService, styleTabConfig, traverseNode, uiService, useCodeBlockEdit, useDataSourceMethod, useStage, warn };
10517
+ export { CODE_DRAFT_STORAGE_KEY, COPY_STORAGE_KEY, _sfc_main$P as CodeBlockEditor, _sfc_main$r as CodeBlockList, _sfc_main$q as CodeBlockListPanel, CodeDeleteErrorType, _sfc_main$Q as CodeSelect, _sfc_main$M as CodeSelectCol, ColumnLayout, _sfc_main$f as ComponentListPanel, _sfc_main$k as ContentMenu, _sfc_main$K as DataSourceFieldSelect, _sfc_main$L as DataSourceFields, _sfc_main$J as DataSourceInput, _sfc_main$H as DataSourceMethodSelect, _sfc_main$I as DataSourceMethods, _sfc_main$G as DataSourceMocks, _sfc_main$F as DataSourceSelect, DragType, _sfc_main$E as EventSelect, Fixed2Other, H_GUIDE_LINE_STORAGE_KEY, _sfc_main$N as Icon, KeyBindingCommand, _sfc_main$D as KeyValue, Keys, LayerOffset, _sfc_main$g as LayerPanel, Layout, _sfc_main$A as LayoutContainer, _sfc_main$v as PropsPanel, _sfc_main$B as Resizer, _sfc_main$A as SplitView, _sfc_main$T as TMagicCodeEditor, _sfc_main as TMagicEditor, _sfc_main$x as ToolButton, UI_SELECT_MODE_EVENT_NAME, V_GUIDE_LINE_STORAGE_KEY, advancedTabConfig, beforePaste, change2Fixed, codeBlockService, dataSourceService, debug, index as default, depService, displayTabConfig, editorService, error, eventTabConfig, eventsService, fillConfig, fixNodeLeft, fixNodePosition, generatePageName, generatePageNameByApp, getAddParent, getConfig, getDefaultConfig, getDisplayField, getFormConfig, getFormValue, getGuideLineFromCache, getInitPositionStyle, getNodeIndex, getPageList, getPageNameList, getPositionInContainer, getRelativeStyle, historyService, info, isFixed, log, propsService, serializeConfig, setChilrenLayout, setConfig, setLayout, storageService, styleTabConfig, traverseNode, uiService, useCodeBlockEdit, useDataSourceMethod, useFloatBox, useStage, warn };
10514
10518
  //# sourceMappingURL=tmagic-editor.js.map