@tmagic/editor 1.3.0-alpha.16 → 1.3.0-alpha.18

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 +1 -1
  2. package/dist/tmagic-editor.js +933 -673
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +944 -678
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +12 -12
  7. package/src/components/CodeBlockEditor.vue +1 -0
  8. package/src/fields/Code.vue +6 -10
  9. package/src/fields/CodeLink.vue +6 -7
  10. package/src/fields/CodeSelect.vue +5 -8
  11. package/src/fields/CodeSelectCol.vue +4 -15
  12. package/src/fields/DataSourceFieldSelect.vue +47 -0
  13. package/src/fields/DataSourceFields.vue +5 -10
  14. package/src/fields/DataSourceInput.vue +9 -12
  15. package/src/fields/DataSourceMethodSelect.vue +5 -16
  16. package/src/fields/DataSourceMethods.vue +6 -11
  17. package/src/fields/DataSourceSelect.vue +5 -12
  18. package/src/fields/EventSelect.vue +20 -12
  19. package/src/fields/KeyValue.vue +9 -11
  20. package/src/fields/UISelect.vue +19 -10
  21. package/src/index.ts +3 -0
  22. package/src/initService.ts +36 -16
  23. package/src/layouts/sidebar/code-block/CodeBlockList.vue +2 -2
  24. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +1 -0
  25. package/src/layouts/sidebar/data-source/DataSourceList.vue +51 -17
  26. package/src/services/dep.ts +19 -19
  27. package/src/theme/code-editor.scss +1 -1
  28. package/src/type.ts +20 -0
  29. package/src/utils/dep.ts +33 -7
  30. package/src/utils/props.ts +298 -189
  31. package/src/utils/stage.ts +3 -5
  32. package/types/fields/Code.vue.d.ts +11 -26
  33. package/types/fields/CodeLink.vue.d.ts +12 -21
  34. package/types/fields/CodeSelect.vue.d.ts +6 -17
  35. package/types/fields/CodeSelectCol.vue.d.ts +3 -18
  36. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  37. package/types/fields/DataSourceFields.vue.d.ts +7 -20
  38. package/types/fields/DataSourceInput.vue.d.ts +10 -30
  39. package/types/fields/DataSourceMethodSelect.vue.d.ts +3 -18
  40. package/types/fields/DataSourceMethods.vue.d.ts +7 -20
  41. package/types/fields/DataSourceSelect.vue.d.ts +13 -29
  42. package/types/fields/EventSelect.vue.d.ts +2 -13
  43. package/types/fields/KeyValue.vue.d.ts +9 -24
  44. package/types/fields/UISelect.vue.d.ts +2 -11
  45. package/types/index.d.ts +1 -0
  46. package/types/initService.d.ts +1 -1
  47. package/types/services/dep.d.ts +12 -21
  48. package/types/services/props.d.ts +8 -113
  49. package/types/type.d.ts +18 -0
  50. package/types/utils/dep.d.ts +4 -2
  51. package/types/utils/props.d.ts +13 -102
@@ -26,7 +26,7 @@
26
26
  const _hoisted_1$r = {
27
27
  class: /* @__PURE__ */ vue.normalizeClass(`magic-code-editor`)
28
28
  };
29
- const _sfc_main$K = /* @__PURE__ */ vue.defineComponent({
29
+ const _sfc_main$L = /* @__PURE__ */ vue.defineComponent({
30
30
  ...{
31
31
  name: "MEditorCodeEditor"
32
32
  },
@@ -200,7 +200,7 @@
200
200
  }
201
201
  });
202
202
 
203
- const _sfc_main$J = /* @__PURE__ */ vue.defineComponent({
203
+ const _sfc_main$K = /* @__PURE__ */ vue.defineComponent({
204
204
  ...{
205
205
  name: "MEditorCode"
206
206
  },
@@ -208,11 +208,13 @@
208
208
  props: {
209
209
  config: {},
210
210
  model: {},
211
+ initValues: {},
212
+ values: {},
211
213
  name: {},
212
214
  prop: {},
213
- lastValues: {},
214
215
  disabled: { type: Boolean, default: false },
215
- size: {}
216
+ size: {},
217
+ lastValues: {}
216
218
  },
217
219
  emits: ["change"],
218
220
  setup(__props, { emit }) {
@@ -222,7 +224,7 @@
222
224
  emit("change", v);
223
225
  };
224
226
  return (_ctx, _cache) => {
225
- return vue.openBlock(), vue.createBlock(_sfc_main$K, {
227
+ return vue.openBlock(), vue.createBlock(_sfc_main$L, {
226
228
  height: _ctx.config.height,
227
229
  "init-values": _ctx.model[_ctx.name],
228
230
  language: _ctx.config.language,
@@ -242,7 +244,7 @@
242
244
  };
243
245
  const getConfig = (key) => $TMAGIC_EDITOR[key];
244
246
 
245
- const _sfc_main$I = /* @__PURE__ */ vue.defineComponent({
247
+ const _sfc_main$J = /* @__PURE__ */ vue.defineComponent({
246
248
  ...{
247
249
  name: "MEditorCodeLink"
248
250
  },
@@ -250,8 +252,13 @@
250
252
  props: {
251
253
  config: {},
252
254
  model: {},
255
+ initValues: {},
256
+ values: {},
253
257
  name: {},
254
- prop: {}
258
+ prop: {},
259
+ disabled: { type: Boolean },
260
+ size: {},
261
+ lastValues: {}
255
262
  },
256
263
  emits: ["change"],
257
264
  setup(__props, { emit }) {
@@ -316,7 +323,7 @@
316
323
  }
317
324
  });
318
325
 
319
- const _sfc_main$H = /* @__PURE__ */ vue.defineComponent({
326
+ const _sfc_main$I = /* @__PURE__ */ vue.defineComponent({
320
327
  ...{
321
328
  name: "MEditorCodeSelect"
322
329
  },
@@ -324,9 +331,13 @@
324
331
  props: {
325
332
  config: {},
326
333
  model: {},
327
- prop: {},
334
+ initValues: {},
335
+ values: {},
328
336
  name: {},
329
- size: {}
337
+ prop: {},
338
+ disabled: { type: Boolean },
339
+ size: {},
340
+ lastValues: {}
330
341
  },
331
342
  emits: ["change"],
332
343
  setup(__props, { emit }) {
@@ -384,7 +395,7 @@
384
395
  }
385
396
  });
386
397
 
387
- const _sfc_main$G = /* @__PURE__ */ vue.defineComponent({
398
+ const _sfc_main$H = /* @__PURE__ */ vue.defineComponent({
388
399
  ...{
389
400
  name: "MEditorCodeBlockEditor"
390
401
  },
@@ -503,6 +514,7 @@
503
514
  ref_key: "fomDrawer",
504
515
  ref: fomDrawer,
505
516
  "label-width": "80px",
517
+ "close-on-press-escape": false,
506
518
  title: _ctx.content.name,
507
519
  width: size.value,
508
520
  config: functionConfig.value,
@@ -516,7 +528,7 @@
516
528
  }
517
529
  });
518
530
 
519
- const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
531
+ const _sfc_main$G = /* @__PURE__ */ vue.defineComponent({
520
532
  ...{
521
533
  name: "MEditorCodeParams"
522
534
  },
@@ -566,7 +578,7 @@
566
578
  });
567
579
 
568
580
  const _hoisted_1$q = ["src"];
569
- const _sfc_main$E = /* @__PURE__ */ vue.defineComponent({
581
+ const _sfc_main$F = /* @__PURE__ */ vue.defineComponent({
570
582
  ...{
571
583
  name: "MEditorIcon"
572
584
  },
@@ -668,7 +680,7 @@
668
680
 
669
681
  const _hoisted_1$p = { class: "m-fields-code-select-col" };
670
682
  const _hoisted_2$f = { class: "code-select-container" };
671
- const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
683
+ const _sfc_main$E = /* @__PURE__ */ vue.defineComponent({
672
684
  ...{
673
685
  name: "MEditorCodeSelectCol"
674
686
  },
@@ -676,11 +688,13 @@
676
688
  props: {
677
689
  config: {},
678
690
  model: {},
679
- prop: {},
691
+ initValues: {},
692
+ values: {},
680
693
  name: {},
681
- lastValues: {},
694
+ prop: {},
682
695
  disabled: { type: Boolean, default: false },
683
- size: {}
696
+ size: {},
697
+ lastValues: {}
684
698
  },
685
699
  emits: ["change"],
686
700
  setup(__props, { emit }) {
@@ -740,14 +754,14 @@
740
754
  model: _ctx.model,
741
755
  onChange: onParamsChangeHandler
742
756
  }, null, 8, ["model"]),
743
- _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
757
+ _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
744
758
  key: 0,
745
759
  class: "icon",
746
760
  icon: !_ctx.disabled ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
747
761
  onClick: _cache[0] || (_cache[0] = ($event) => vue.unref(editCode)(_ctx.model[_ctx.name]))
748
762
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true)
749
763
  ]),
750
- paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
764
+ paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
751
765
  key: 0,
752
766
  name: "params",
753
767
  model: _ctx.model,
@@ -755,7 +769,7 @@
755
769
  "params-config": paramsConfig.value,
756
770
  onChange: onParamsChangeHandler
757
771
  }, null, 8, ["model", "size", "params-config"])) : vue.createCommentVNode("", true),
758
- vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
772
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$H, {
759
773
  key: 1,
760
774
  ref_key: "codeBlockEditor",
761
775
  ref: codeBlockEditor,
@@ -770,7 +784,7 @@
770
784
 
771
785
  const _hoisted_1$o = { class: "m-editor-data-source-fields" };
772
786
  const _hoisted_2$e = { class: "m-editor-data-source-fields-footer" };
773
- const _sfc_main$C = /* @__PURE__ */ vue.defineComponent({
787
+ const _sfc_main$D = /* @__PURE__ */ vue.defineComponent({
774
788
  ...{
775
789
  name: "MEditorDataSourceFields"
776
790
  },
@@ -778,10 +792,13 @@
778
792
  props: {
779
793
  config: {},
780
794
  model: {},
795
+ initValues: {},
796
+ values: {},
797
+ name: {},
781
798
  prop: {},
782
- lastValues: {},
783
799
  disabled: { type: Boolean, default: false },
784
- name: {}
800
+ size: {},
801
+ lastValues: {}
785
802
  },
786
803
  emits: ["change"],
787
804
  setup(__props, { emit }) {
@@ -945,6 +962,53 @@
945
962
  }
946
963
  });
947
964
 
965
+ const _sfc_main$C = /* @__PURE__ */ vue.defineComponent({
966
+ __name: "DataSourceFieldSelect",
967
+ props: {
968
+ config: {},
969
+ model: {},
970
+ initValues: {},
971
+ values: {},
972
+ name: {},
973
+ prop: {},
974
+ disabled: { type: Boolean, default: false },
975
+ size: {},
976
+ lastValues: {}
977
+ },
978
+ emits: ["change"],
979
+ setup(__props, { emit }) {
980
+ const props = __props;
981
+ const services = vue.inject("services");
982
+ const dataSources = vue.computed(() => services?.dataSourceService.get("dataSources"));
983
+ const cascaderConfig = {
984
+ type: "cascader",
985
+ name: props.name,
986
+ options: () => dataSources.value?.filter((ds) => ds.fields?.length)?.map((ds) => ({
987
+ label: ds.title || ds.id,
988
+ value: ds.id,
989
+ children: ds.fields?.map((field) => ({
990
+ label: field.title,
991
+ value: field.name
992
+ }))
993
+ })) || []
994
+ };
995
+ const onChangeHandler = (value) => {
996
+ emit("change", value);
997
+ };
998
+ return (_ctx, _cache) => {
999
+ const _component_m_form_container = vue.resolveComponent("m-form-container");
1000
+ return vue.openBlock(), vue.createBlock(_component_m_form_container, {
1001
+ config: {
1002
+ ..._ctx.config,
1003
+ ...cascaderConfig
1004
+ },
1005
+ model: _ctx.model,
1006
+ onChange: onChangeHandler
1007
+ }, null, 8, ["config", "model"]);
1008
+ };
1009
+ }
1010
+ });
1011
+
948
1012
  const _hoisted_1$n = { style: { "display": "flex", "flex-direction": "column", "line-height": "1.2em" } };
949
1013
  const _hoisted_2$d = { style: { "font-size": "10px", "color": "rgba(0, 0, 0, 0.6)" } };
950
1014
  const _hoisted_3$5 = { class: "el-input__inner" };
@@ -956,11 +1020,13 @@
956
1020
  props: {
957
1021
  config: {},
958
1022
  model: {},
1023
+ initValues: {},
1024
+ values: {},
959
1025
  name: {},
960
1026
  prop: {},
961
1027
  disabled: { type: Boolean, default: false },
962
- lastValues: {},
963
- size: {}
1028
+ size: {},
1029
+ lastValues: {}
964
1030
  },
965
1031
  emits: ["change"],
966
1032
  setup(__props, { emit }) {
@@ -1167,7 +1233,7 @@
1167
1233
  }
1168
1234
  ), {
1169
1235
  suffix: vue.withCtx(() => [
1170
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Coin) }, null, 8, ["icon"])
1236
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.Coin) }, null, 8, ["icon"])
1171
1237
  ]),
1172
1238
  default: vue.withCtx(({ item }) => [
1173
1239
  vue.createElementVNode("div", _hoisted_1$n, [
@@ -1202,7 +1268,7 @@
1202
1268
  }, 1032, ["size"])) : vue.createCommentVNode("", true)
1203
1269
  ], 64);
1204
1270
  }), 256)),
1205
- vue.createVNode(_sfc_main$E, {
1271
+ vue.createVNode(_sfc_main$F, {
1206
1272
  class: "tmagic-data-source-input-icon",
1207
1273
  icon: vue.unref(iconsVue.Coin)
1208
1274
  }, null, 8, ["icon"])
@@ -1295,10 +1361,13 @@
1295
1361
  props: {
1296
1362
  config: {},
1297
1363
  model: {},
1364
+ initValues: {},
1365
+ values: {},
1366
+ name: {},
1298
1367
  prop: {},
1299
- lastValues: {},
1300
1368
  disabled: { type: Boolean, default: false },
1301
- name: {}
1369
+ size: {},
1370
+ lastValues: {}
1302
1371
  },
1303
1372
  emits: ["change"],
1304
1373
  setup(__props, { emit }) {
@@ -1368,7 +1437,7 @@
1368
1437
  _: 1
1369
1438
  }, 8, ["disabled"])
1370
1439
  ]),
1371
- vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
1440
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$H, {
1372
1441
  key: 0,
1373
1442
  ref_key: "codeBlockEditor",
1374
1443
  ref: codeBlockEditor,
@@ -1391,11 +1460,13 @@
1391
1460
  props: {
1392
1461
  config: {},
1393
1462
  model: {},
1394
- lastValues: {},
1395
- prop: {},
1463
+ initValues: {},
1464
+ values: {},
1396
1465
  name: {},
1466
+ prop: {},
1397
1467
  disabled: { type: Boolean, default: false },
1398
- size: {}
1468
+ size: {},
1469
+ lastValues: {}
1399
1470
  },
1400
1471
  emits: ["change"],
1401
1472
  setup(__props, { emit }) {
@@ -1429,7 +1500,7 @@
1429
1500
  name: props.name,
1430
1501
  labelWidth: "80px",
1431
1502
  options: () => dataSources.value?.filter((ds) => ds.methods?.length)?.map((ds) => ({
1432
- label: `${ds.title}(${ds.id})`,
1503
+ label: ds.title || ds.id,
1433
1504
  value: ds.id,
1434
1505
  children: ds.methods?.map((method) => ({
1435
1506
  label: method.name,
@@ -1467,14 +1538,14 @@
1467
1538
  model: _ctx.model,
1468
1539
  onChange: onChangeHandler
1469
1540
  }, null, 8, ["model"]),
1470
- _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
1541
+ _ctx.model[_ctx.name] ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
1471
1542
  key: 0,
1472
1543
  class: "icon",
1473
1544
  icon: !_ctx.disabled ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
1474
1545
  onClick: editCodeHandler
1475
1546
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true)
1476
1547
  ]),
1477
- paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
1548
+ paramsConfig.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
1478
1549
  key: 0,
1479
1550
  name: "params",
1480
1551
  model: _ctx.model,
@@ -1483,7 +1554,7 @@
1483
1554
  "params-config": paramsConfig.value,
1484
1555
  onChange: onChangeHandler
1485
1556
  }, null, 8, ["model", "size", "disabled", "params-config"])) : vue.createCommentVNode("", true),
1486
- vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
1557
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$H, {
1487
1558
  key: 1,
1488
1559
  ref_key: "codeBlockEditor",
1489
1560
  ref: codeBlockEditor,
@@ -1504,11 +1575,13 @@
1504
1575
  props: {
1505
1576
  config: {},
1506
1577
  model: {},
1578
+ initValues: {},
1579
+ values: {},
1507
1580
  name: {},
1508
1581
  prop: {},
1509
1582
  disabled: { type: Boolean, default: false },
1510
- lastValues: {},
1511
- size: {}
1583
+ size: {},
1584
+ lastValues: {}
1512
1585
  },
1513
1586
  emits: ["change"],
1514
1587
  setup(__props, { emit }) {
@@ -1562,9 +1635,13 @@
1562
1635
  props: {
1563
1636
  config: {},
1564
1637
  model: {},
1565
- prop: {},
1638
+ initValues: {},
1639
+ values: {},
1566
1640
  name: {},
1567
- size: {}
1641
+ prop: {},
1642
+ disabled: { type: Boolean },
1643
+ size: {},
1644
+ lastValues: {}
1568
1645
  },
1569
1646
  emits: ["change"],
1570
1647
  setup(__props, { emit }) {
@@ -1744,26 +1821,30 @@
1744
1821
  isOldVersion.value ? (vue.openBlock(), vue.createBlock(_component_m_form_table, {
1745
1822
  key: 0,
1746
1823
  ref: "eventForm",
1747
- size: props.size,
1748
- model: _ctx.model,
1749
1824
  name: "events",
1825
+ size: _ctx.size,
1826
+ disabled: _ctx.disabled,
1827
+ model: _ctx.model,
1750
1828
  config: tableConfig.value,
1751
1829
  onChange: onChangeHandler
1752
- }, null, 8, ["size", "model", "config"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$a, [
1830
+ }, null, 8, ["size", "disabled", "model", "config"])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$a, [
1753
1831
  vue.createVNode(vue.unref(design.TMagicButton), {
1754
1832
  class: "create-button",
1755
1833
  type: "primary",
1756
- size: "small",
1834
+ size: _ctx.size,
1835
+ disabled: _ctx.disabled,
1757
1836
  onClick: _cache[0] || (_cache[0] = ($event) => addEvent())
1758
1837
  }, {
1759
1838
  default: vue.withCtx(() => [
1760
1839
  vue.createTextVNode("添加事件")
1761
1840
  ]),
1762
1841
  _: 1
1763
- }),
1842
+ }, 8, ["size", "disabled"]),
1764
1843
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.model[_ctx.name], (cardItem, index) => {
1765
1844
  return vue.openBlock(), vue.createBlock(_component_m_form_panel, {
1766
1845
  key: index,
1846
+ disabled: _ctx.disabled,
1847
+ size: _ctx.size,
1767
1848
  config: actionsConfig.value,
1768
1849
  model: cardItem,
1769
1850
  onChange: onChangeHandler
@@ -1773,17 +1854,21 @@
1773
1854
  class: "fullWidth",
1774
1855
  config: eventNameConfig.value,
1775
1856
  model: cardItem,
1857
+ disabled: _ctx.disabled,
1858
+ size: _ctx.size,
1776
1859
  onChange: onChangeHandler
1777
- }, null, 8, ["config", "model"]),
1860
+ }, null, 8, ["config", "model", "disabled", "size"]),
1778
1861
  vue.createVNode(vue.unref(design.TMagicButton), {
1779
1862
  style: { "color": "#f56c6c" },
1780
1863
  text: "",
1781
1864
  icon: vue.unref(iconsVue.Delete),
1865
+ disabled: _ctx.disabled,
1866
+ size: _ctx.size,
1782
1867
  onClick: ($event) => removeEvent(index)
1783
- }, null, 8, ["icon", "onClick"])
1868
+ }, null, 8, ["icon", "disabled", "size", "onClick"])
1784
1869
  ]),
1785
1870
  _: 2
1786
- }, 1032, ["config", "model"]);
1871
+ }, 1032, ["disabled", "size", "config", "model"]);
1787
1872
  }), 128))
1788
1873
  ]))
1789
1874
  ]);
@@ -1801,11 +1886,13 @@
1801
1886
  props: {
1802
1887
  config: {},
1803
1888
  model: {},
1889
+ initValues: {},
1890
+ values: {},
1804
1891
  name: {},
1805
1892
  prop: {},
1806
1893
  disabled: { type: Boolean, default: false },
1807
- lastValues: {},
1808
- size: {}
1894
+ size: {},
1895
+ lastValues: {}
1809
1896
  },
1810
1897
  emits: ["change"],
1811
1898
  setup(__props, { emit }) {
@@ -1863,16 +1950,18 @@
1863
1950
  class: "m-fileds-key-value-delete",
1864
1951
  type: "danger",
1865
1952
  size: _ctx.size,
1953
+ disabled: _ctx.disabled,
1866
1954
  circle: "",
1867
1955
  plain: "",
1868
1956
  icon: vue.unref(iconsVue.Delete),
1869
1957
  onClick: ($event) => deleteHandler(index)
1870
- }, null, 8, ["size", "icon", "onClick"])
1958
+ }, null, 8, ["size", "disabled", "icon", "onClick"])
1871
1959
  ]);
1872
1960
  }), 128)),
1873
1961
  vue.createVNode(vue.unref(design.TMagicButton), {
1874
1962
  type: "primary",
1875
1963
  size: _ctx.size,
1964
+ disabled: _ctx.disabled,
1876
1965
  plain: "",
1877
1966
  icon: vue.unref(iconsVue.Plus),
1878
1967
  onClick: addHandler
@@ -1881,7 +1970,7 @@
1881
1970
  vue.createTextVNode("添加")
1882
1971
  ]),
1883
1972
  _: 1
1884
- }, 8, ["size", "icon"])
1973
+ }, 8, ["size", "disabled", "icon"])
1885
1974
  ]);
1886
1975
  };
1887
1976
  }
@@ -1900,8 +1989,13 @@
1900
1989
  props: {
1901
1990
  config: {},
1902
1991
  model: {},
1992
+ initValues: {},
1993
+ values: {},
1994
+ name: {},
1903
1995
  prop: {},
1904
- name: {}
1996
+ disabled: { type: Boolean },
1997
+ size: {},
1998
+ lastValues: {}
1905
1999
  },
1906
2000
  emits: ["change"],
1907
2001
  setup(__props, { emit }) {
@@ -1966,6 +2060,8 @@
1966
2060
  vue.createVNode(vue.unref(design.TMagicButton), {
1967
2061
  type: "danger",
1968
2062
  icon: vue.unref(iconsVue.Delete),
2063
+ disabled: _ctx.disabled,
2064
+ size: _ctx.size,
1969
2065
  text: "",
1970
2066
  style: { "padding": "0" }
1971
2067
  }, {
@@ -1973,7 +2069,7 @@
1973
2069
  vue.createTextVNode("取消")
1974
2070
  ]),
1975
2071
  _: 1
1976
- }, 8, ["icon"])
2072
+ }, 8, ["icon", "disabled", "size"])
1977
2073
  ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$i, [
1978
2074
  val.value ? (vue.openBlock(), vue.createElementBlock(vue.Fragment, { key: 0 }, [
1979
2075
  vue.createVNode(vue.unref(design.TMagicTooltip), {
@@ -1985,9 +2081,11 @@
1985
2081
  style: { "padding": "0" },
1986
2082
  type: "danger",
1987
2083
  icon: vue.unref(iconsVue.Close),
2084
+ disabled: _ctx.disabled,
2085
+ size: _ctx.size,
1988
2086
  text: "",
1989
2087
  onClick: vue.withModifiers(deleteHandler, ["stop"])
1990
- }, null, 8, ["icon", "onClick"])
2088
+ }, null, 8, ["icon", "disabled", "size", "onClick"])
1991
2089
  ]),
1992
2090
  _: 1
1993
2091
  }),
@@ -1999,6 +2097,8 @@
1999
2097
  vue.createVNode(vue.unref(design.TMagicButton), {
2000
2098
  text: "",
2001
2099
  style: { "padding": "0", "margin": "0" },
2100
+ disabled: _ctx.disabled,
2101
+ size: _ctx.size,
2002
2102
  onClick: _cache[0] || (_cache[0] = ($event) => selectNode(val.value)),
2003
2103
  onMouseenter: _cache[1] || (_cache[1] = ($event) => vue.unref(highlight)(val.value)),
2004
2104
  onMouseleave: unhightlight
@@ -2007,7 +2107,7 @@
2007
2107
  vue.createTextVNode(vue.toDisplayString(`${toName.value}_${val.value}`), 1)
2008
2108
  ]),
2009
2109
  _: 1
2010
- })
2110
+ }, 8, ["disabled", "size"])
2011
2111
  ]),
2012
2112
  _: 1
2013
2113
  })
@@ -2020,13 +2120,15 @@
2020
2120
  vue.createVNode(vue.unref(design.TMagicButton), {
2021
2121
  text: "",
2022
2122
  style: { "padding": "0", "margin": "0" },
2123
+ disabled: _ctx.disabled,
2124
+ size: _ctx.size,
2023
2125
  onClick: startSelect
2024
2126
  }, {
2025
2127
  default: vue.withCtx(() => [
2026
2128
  vue.createTextVNode("点击此处选择")
2027
2129
  ]),
2028
2130
  _: 1
2029
- })
2131
+ }, 8, ["disabled", "size"])
2030
2132
  ]),
2031
2133
  _: 1
2032
2134
  }))
@@ -2213,246 +2315,631 @@
2213
2315
  }
2214
2316
  });
2215
2317
 
2216
- const fillConfig$1 = (config = []) => [
2318
+ const BaseFormConfig = [
2217
2319
  {
2218
- type: "tab",
2320
+ name: "id",
2321
+ type: "hidden"
2322
+ },
2323
+ {
2324
+ name: "type",
2325
+ text: "类型",
2326
+ type: "select",
2327
+ options: [
2328
+ { text: "基础", value: "base" },
2329
+ { text: "HTTP", value: "http" }
2330
+ ],
2331
+ defaultValue: "base"
2332
+ },
2333
+ {
2334
+ name: "title",
2335
+ text: "名称",
2336
+ rules: [
2337
+ {
2338
+ required: true,
2339
+ message: "请输入名称"
2340
+ }
2341
+ ]
2342
+ },
2343
+ {
2344
+ name: "description",
2345
+ text: "描述"
2346
+ }
2347
+ ];
2348
+
2349
+ const HttpFormConfig = [
2350
+ {
2351
+ name: "autoFetch",
2352
+ text: "自动请求",
2353
+ type: "switch",
2354
+ defaultValue: true
2355
+ },
2356
+ {
2357
+ type: "fieldset",
2358
+ name: "options",
2359
+ legend: "HTTP 配置",
2219
2360
  items: [
2220
2361
  {
2221
- title: "属性",
2222
- labelWidth: "80px",
2223
- items: [
2224
- // 组件类型,必须要有
2225
- {
2226
- text: "type",
2227
- name: "type",
2228
- type: "hidden"
2229
- },
2230
- // 组件id,必须要有
2231
- {
2232
- name: "id",
2233
- type: "display",
2234
- text: "id"
2235
- },
2236
- {
2237
- name: "name",
2238
- text: "组件名称"
2239
- },
2240
- ...config
2241
- ]
2362
+ name: "url",
2363
+ text: "URL"
2242
2364
  },
2243
2365
  {
2244
- title: "样式",
2245
- labelWidth: "80px",
2246
- items: [
2247
- {
2248
- name: "style",
2249
- items: [
2250
- {
2251
- type: "fieldset",
2252
- legend: "位置",
2253
- items: [
2254
- {
2255
- name: "position",
2256
- type: "checkbox",
2257
- activeValue: "fixed",
2258
- inactiveValue: "absolute",
2259
- defaultValue: "absolute",
2260
- text: "固定定位"
2261
- },
2262
- {
2263
- name: "left",
2264
- text: "left"
2265
- },
2266
- {
2267
- name: "top",
2268
- text: "top",
2269
- disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
2270
- },
2271
- {
2272
- name: "right",
2273
- text: "right"
2274
- },
2275
- {
2276
- name: "bottom",
2277
- text: "bottom",
2278
- disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
2279
- }
2280
- ]
2281
- },
2282
- {
2283
- type: "fieldset",
2284
- legend: "盒子",
2285
- items: [
2286
- {
2287
- name: "width",
2288
- text: "宽度"
2289
- },
2290
- {
2291
- name: "height",
2292
- text: "高度"
2293
- }
2294
- ]
2295
- },
2296
- {
2297
- type: "fieldset",
2298
- legend: "边框",
2299
- items: [
2300
- {
2301
- name: "borderWidth",
2302
- text: "宽度",
2303
- defaultValue: "0"
2304
- },
2305
- {
2306
- name: "borderColor",
2307
- text: "颜色",
2308
- type: "colorPicker"
2309
- },
2310
- {
2311
- name: "borderStyle",
2312
- text: "样式",
2313
- type: "select",
2314
- defaultValue: "none",
2315
- options: [
2316
- { text: "none", value: "none" },
2317
- { text: "hidden", value: "hidden" },
2318
- { text: "dotted", value: "dotted" },
2319
- { text: "dashed", value: "dashed" },
2320
- { text: "solid", value: "solid" },
2321
- { text: "double", value: "double" },
2322
- { text: "groove", value: "groove" },
2323
- { text: "ridge", value: "ridge" },
2324
- { text: "inset", value: "inset" },
2325
- { text: "outset", value: "outset" }
2326
- ]
2327
- }
2328
- ]
2329
- },
2330
- {
2331
- type: "fieldset",
2332
- legend: "背景",
2333
- items: [
2334
- {
2335
- name: "backgroundImage",
2336
- text: "背景图"
2337
- },
2338
- {
2339
- name: "backgroundColor",
2340
- text: "背景颜色",
2341
- type: "colorPicker"
2342
- },
2343
- {
2344
- name: "backgroundRepeat",
2345
- text: "背景图重复",
2346
- type: "select",
2347
- defaultValue: "no-repeat",
2348
- options: [
2349
- { text: "repeat", value: "repeat" },
2350
- { text: "repeat-x", value: "repeat-x" },
2351
- { text: "repeat-y", value: "repeat-y" },
2352
- { text: "no-repeat", value: "no-repeat" },
2353
- { text: "inherit", value: "inherit" }
2354
- ]
2355
- },
2356
- {
2357
- name: "backgroundSize",
2358
- text: "背景图大小",
2359
- defaultValue: "100% 100%"
2360
- }
2361
- ]
2362
- },
2363
- {
2364
- type: "fieldset",
2365
- legend: "字体",
2366
- items: [
2367
- {
2368
- name: "color",
2369
- text: "颜色",
2370
- type: "colorPicker"
2371
- },
2372
- {
2373
- name: "fontSize",
2374
- text: "大小"
2375
- },
2376
- {
2377
- name: "fontWeight",
2378
- text: "粗细"
2379
- }
2380
- ]
2381
- },
2382
- {
2383
- type: "fieldset",
2384
- legend: "变形",
2385
- name: "transform",
2386
- items: [
2387
- {
2388
- name: "rotate",
2389
- text: "旋转角度"
2390
- },
2391
- {
2392
- name: "scale",
2393
- text: "缩放"
2394
- }
2395
- ]
2396
- }
2397
- ]
2398
- }
2366
+ name: "method",
2367
+ text: "Method",
2368
+ type: "select",
2369
+ options: [
2370
+ { text: "GET", value: "GET" },
2371
+ { text: "POST", value: "POST" },
2372
+ { text: "PUT", value: "PUT" },
2373
+ { text: "DELETE", value: "DELETE" }
2399
2374
  ]
2400
2375
  },
2401
2376
  {
2402
- title: "事件",
2403
- items: [
2404
- {
2405
- name: "events",
2406
- type: "event-select",
2407
- labelWidth: 0
2408
- }
2409
- ]
2377
+ name: "params",
2378
+ type: "key-value",
2379
+ defaultValue: {},
2380
+ text: "参数"
2410
2381
  },
2411
2382
  {
2412
- title: "高级",
2413
- lazy: true,
2414
- items: [
2415
- {
2416
- name: "created",
2417
- text: "created",
2418
- labelWidth: "100px",
2419
- type: "code-select"
2420
- },
2421
- {
2422
- name: "mounted",
2423
- text: "mounted",
2424
- labelWidth: "100px",
2425
- type: "code-select"
2426
- }
2427
- ]
2383
+ name: "data",
2384
+ type: "key-value",
2385
+ defaultValue: {},
2386
+ text: "请求体"
2387
+ },
2388
+ {
2389
+ name: "headers",
2390
+ type: "key-value",
2391
+ defaultValue: {},
2392
+ text: "请求头"
2428
2393
  }
2429
2394
  ]
2430
2395
  }
2431
2396
  ];
2432
2397
 
2433
- const log = (...args) => {
2434
- if (process.env.NODE_ENV === "development") {
2435
- console.log("magic editor: ", ...args);
2436
- }
2437
- };
2438
- const info = (...args) => {
2439
- if (process.env.NODE_ENV === "development") {
2440
- console.info("magic editor: ", ...args);
2441
- }
2442
- };
2443
- const warn = (...args) => {
2444
- if (process.env.NODE_ENV === "development") {
2445
- console.warn("magic editor: ", ...args);
2446
- }
2447
- };
2448
- const debug = (...args) => {
2449
- if (process.env.NODE_ENV === "development") {
2450
- console.debug("magic editor: ", ...args);
2451
- }
2452
- };
2453
- const error = (...args) => {
2454
- if (process.env.NODE_ENV === "development") {
2455
- console.error("magic editor: ", ...args);
2398
+ const fillConfig$1 = (config) => [
2399
+ ...BaseFormConfig,
2400
+ ...config,
2401
+ {
2402
+ type: "panel",
2403
+ title: "数据定义",
2404
+ items: [
2405
+ {
2406
+ name: "fields",
2407
+ type: "data-source-fields",
2408
+ defaultValue: []
2409
+ }
2410
+ ]
2411
+ },
2412
+ {
2413
+ type: "panel",
2414
+ title: "方法定义",
2415
+ items: [
2416
+ {
2417
+ name: "methods",
2418
+ type: "data-source-methods",
2419
+ defaultValue: []
2420
+ }
2421
+ ]
2422
+ }
2423
+ ];
2424
+ const getFormConfig = (type, configs) => {
2425
+ switch (type) {
2426
+ case "base":
2427
+ return fillConfig$1([]);
2428
+ case "http":
2429
+ return fillConfig$1(HttpFormConfig);
2430
+ default:
2431
+ return fillConfig$1(configs[type] || []);
2432
+ }
2433
+ };
2434
+
2435
+ const compose = (middleware) => {
2436
+ if (!Array.isArray(middleware))
2437
+ throw new TypeError("Middleware 必须是一个数组!");
2438
+ for (const fn of middleware) {
2439
+ if (typeof fn !== "function")
2440
+ throw new TypeError("Middleware 必须由函数组成!");
2441
+ }
2442
+ return (args, next) => {
2443
+ let index = -1;
2444
+ return dispatch(0);
2445
+ function dispatch(i) {
2446
+ if (i <= index)
2447
+ return Promise.reject(new Error("next() 被多次调用"));
2448
+ index = i;
2449
+ let fn = middleware[i];
2450
+ if (i === middleware.length && next)
2451
+ fn = next;
2452
+ if (!fn)
2453
+ return Promise.resolve();
2454
+ try {
2455
+ return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
2456
+ } catch (err) {
2457
+ return Promise.reject(err);
2458
+ }
2459
+ }
2460
+ };
2461
+ };
2462
+
2463
+ const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
2464
+ const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
2465
+ const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName, fn) => {
2466
+ try {
2467
+ let beforeArgs = args;
2468
+ for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
2469
+ beforeArgs = await beforeMethod(...beforeArgs) || [];
2470
+ if (isError(beforeArgs))
2471
+ throw beforeArgs;
2472
+ if (!Array.isArray(beforeArgs)) {
2473
+ beforeArgs = [beforeArgs];
2474
+ }
2475
+ }
2476
+ let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
2477
+ for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
2478
+ returnValue = await afterMethod(returnValue, ...beforeArgs);
2479
+ if (isError(returnValue))
2480
+ throw returnValue;
2481
+ }
2482
+ return returnValue;
2483
+ } catch (error) {
2484
+ throw error;
2485
+ }
2486
+ };
2487
+ class BaseService extends events.EventEmitter {
2488
+ pluginOptionsList = {};
2489
+ middleware = {};
2490
+ taskList = [];
2491
+ doingTask = false;
2492
+ constructor(methods = [], serialMethods = []) {
2493
+ super();
2494
+ methods.forEach((propertyName) => {
2495
+ const scope = this;
2496
+ const sourceMethod = scope[propertyName];
2497
+ const beforeMethodName = methodName("before", propertyName);
2498
+ const afterMethodName = methodName("after", propertyName);
2499
+ this.pluginOptionsList[beforeMethodName] = [];
2500
+ this.pluginOptionsList[afterMethodName] = [];
2501
+ this.middleware[propertyName] = [];
2502
+ const fn = compose(this.middleware[propertyName]);
2503
+ Object.defineProperty(scope, propertyName, {
2504
+ value: async (...args) => {
2505
+ if (!serialMethods.includes(propertyName)) {
2506
+ return doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
2507
+ }
2508
+ const promise = new Promise((resolve, reject) => {
2509
+ this.taskList.push(async () => {
2510
+ try {
2511
+ const value = await doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
2512
+ resolve(value);
2513
+ } catch (e) {
2514
+ reject(e);
2515
+ }
2516
+ });
2517
+ });
2518
+ if (!this.doingTask) {
2519
+ this.doTask();
2520
+ }
2521
+ return promise;
2522
+ }
2523
+ });
2524
+ });
2525
+ }
2526
+ use(options) {
2527
+ Object.entries(options).forEach(([methodName2, method]) => {
2528
+ if (typeof method === "function")
2529
+ this.middleware[methodName2].push(method);
2530
+ });
2531
+ }
2532
+ usePlugin(options) {
2533
+ Object.entries(options).forEach(([methodName2, method]) => {
2534
+ if (typeof method === "function")
2535
+ this.pluginOptionsList[methodName2].push(method);
2536
+ });
2537
+ }
2538
+ removeAllPlugins() {
2539
+ Object.keys(this.pluginOptionsList).forEach((key) => {
2540
+ this.pluginOptionsList[key] = [];
2541
+ });
2542
+ Object.keys(this.middleware).forEach((key) => {
2543
+ this.middleware[key] = [];
2544
+ });
2545
+ }
2546
+ async doTask() {
2547
+ this.doingTask = true;
2548
+ let task = this.taskList.shift();
2549
+ while (task) {
2550
+ await task();
2551
+ task = this.taskList.shift();
2552
+ }
2553
+ this.doingTask = false;
2554
+ }
2555
+ }
2556
+
2557
+ class DataSource extends BaseService {
2558
+ state = vue.reactive({
2559
+ dataSources: [],
2560
+ editable: true,
2561
+ configs: {}
2562
+ });
2563
+ set(name, value) {
2564
+ this.state[name] = value;
2565
+ }
2566
+ get(name) {
2567
+ return this.state[name];
2568
+ }
2569
+ getFormConfig(type = "base") {
2570
+ return getFormConfig(type, this.get("configs"));
2571
+ }
2572
+ setFormConfig(type, config) {
2573
+ this.get("configs")[type] = config;
2574
+ }
2575
+ add(config) {
2576
+ const newConfig = {
2577
+ ...config,
2578
+ id: this.createId()
2579
+ };
2580
+ this.get("dataSources").push(newConfig);
2581
+ this.emit("add", newConfig);
2582
+ }
2583
+ update(config) {
2584
+ const dataSources = this.get("dataSources");
2585
+ const index = dataSources.findIndex((ds) => ds.id === config.id);
2586
+ dataSources[index] = lodashEs.cloneDeep(config);
2587
+ this.emit("update", config);
2588
+ }
2589
+ remove(id) {
2590
+ const dataSources = this.get("dataSources");
2591
+ const index = dataSources.findIndex((ds) => ds.id === id);
2592
+ dataSources.splice(index, 1);
2593
+ this.emit("remove", id);
2594
+ }
2595
+ getDataSourceById(id) {
2596
+ return this.get("dataSources").find((ds) => ds.id === id);
2597
+ }
2598
+ resetState() {
2599
+ this.set("dataSources", []);
2600
+ }
2601
+ destroy() {
2602
+ this.removeAllListeners();
2603
+ this.resetState();
2604
+ this.removeAllPlugins();
2605
+ }
2606
+ createId() {
2607
+ return `ds_${utils.guid()}`;
2608
+ }
2609
+ }
2610
+ const dataSourceService = new DataSource();
2611
+
2612
+ const arrayOptions = [
2613
+ { text: "包含", value: "include" },
2614
+ { text: "不包含", value: "not_include" }
2615
+ ];
2616
+ const eqOptions = [
2617
+ { text: "等于", value: "=" },
2618
+ { text: "不等于", value: "!=" }
2619
+ ];
2620
+ const numberOptions = [
2621
+ { text: "大于", value: ">" },
2622
+ { text: "大于等于", value: ">=" },
2623
+ { text: "小于", value: "<" },
2624
+ { text: "小于等于", value: "<=" },
2625
+ { text: "在范围内", value: "between" },
2626
+ { text: "不在范围内", value: "not_between" }
2627
+ ];
2628
+ const styleTabConfig = {
2629
+ title: "样式",
2630
+ labelWidth: "80px",
2631
+ items: [
2632
+ {
2633
+ name: "style",
2634
+ items: [
2635
+ {
2636
+ type: "fieldset",
2637
+ legend: "位置",
2638
+ items: [
2639
+ {
2640
+ name: "position",
2641
+ type: "checkbox",
2642
+ activeValue: "fixed",
2643
+ inactiveValue: "absolute",
2644
+ defaultValue: "absolute",
2645
+ text: "固定定位"
2646
+ },
2647
+ {
2648
+ name: "left",
2649
+ text: "left"
2650
+ },
2651
+ {
2652
+ name: "top",
2653
+ text: "top",
2654
+ disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedBottom"
2655
+ },
2656
+ {
2657
+ name: "right",
2658
+ text: "right"
2659
+ },
2660
+ {
2661
+ name: "bottom",
2662
+ text: "bottom",
2663
+ disabled: (vm, { model }) => model.position === "fixed" && model._magic_position === "fixedTop"
2664
+ }
2665
+ ]
2666
+ },
2667
+ {
2668
+ type: "fieldset",
2669
+ legend: "盒子",
2670
+ items: [
2671
+ {
2672
+ name: "width",
2673
+ text: "宽度"
2674
+ },
2675
+ {
2676
+ name: "height",
2677
+ text: "高度"
2678
+ }
2679
+ ]
2680
+ },
2681
+ {
2682
+ type: "fieldset",
2683
+ legend: "边框",
2684
+ items: [
2685
+ {
2686
+ name: "borderWidth",
2687
+ text: "宽度",
2688
+ defaultValue: "0"
2689
+ },
2690
+ {
2691
+ name: "borderColor",
2692
+ text: "颜色",
2693
+ type: "colorPicker"
2694
+ },
2695
+ {
2696
+ name: "borderStyle",
2697
+ text: "样式",
2698
+ type: "select",
2699
+ defaultValue: "none",
2700
+ options: [
2701
+ { text: "none", value: "none" },
2702
+ { text: "hidden", value: "hidden" },
2703
+ { text: "dotted", value: "dotted" },
2704
+ { text: "dashed", value: "dashed" },
2705
+ { text: "solid", value: "solid" },
2706
+ { text: "double", value: "double" },
2707
+ { text: "groove", value: "groove" },
2708
+ { text: "ridge", value: "ridge" },
2709
+ { text: "inset", value: "inset" },
2710
+ { text: "outset", value: "outset" }
2711
+ ]
2712
+ }
2713
+ ]
2714
+ },
2715
+ {
2716
+ type: "fieldset",
2717
+ legend: "背景",
2718
+ items: [
2719
+ {
2720
+ name: "backgroundImage",
2721
+ text: "背景图"
2722
+ },
2723
+ {
2724
+ name: "backgroundColor",
2725
+ text: "背景颜色",
2726
+ type: "colorPicker"
2727
+ },
2728
+ {
2729
+ name: "backgroundRepeat",
2730
+ text: "背景图重复",
2731
+ type: "select",
2732
+ defaultValue: "no-repeat",
2733
+ options: [
2734
+ { text: "repeat", value: "repeat" },
2735
+ { text: "repeat-x", value: "repeat-x" },
2736
+ { text: "repeat-y", value: "repeat-y" },
2737
+ { text: "no-repeat", value: "no-repeat" },
2738
+ { text: "inherit", value: "inherit" }
2739
+ ]
2740
+ },
2741
+ {
2742
+ name: "backgroundSize",
2743
+ text: "背景图大小",
2744
+ defaultValue: "100% 100%"
2745
+ }
2746
+ ]
2747
+ },
2748
+ {
2749
+ type: "fieldset",
2750
+ legend: "字体",
2751
+ items: [
2752
+ {
2753
+ name: "color",
2754
+ text: "颜色",
2755
+ type: "colorPicker"
2756
+ },
2757
+ {
2758
+ name: "fontSize",
2759
+ text: "大小"
2760
+ },
2761
+ {
2762
+ name: "fontWeight",
2763
+ text: "粗细"
2764
+ }
2765
+ ]
2766
+ },
2767
+ {
2768
+ type: "fieldset",
2769
+ legend: "变形",
2770
+ name: "transform",
2771
+ items: [
2772
+ {
2773
+ name: "rotate",
2774
+ text: "旋转角度"
2775
+ },
2776
+ {
2777
+ name: "scale",
2778
+ text: "缩放"
2779
+ }
2780
+ ]
2781
+ }
2782
+ ]
2783
+ }
2784
+ ]
2785
+ };
2786
+ const eventTabConfig = {
2787
+ title: "事件",
2788
+ items: [
2789
+ {
2790
+ name: "events",
2791
+ type: "event-select"
2792
+ }
2793
+ ]
2794
+ };
2795
+ const advancedTabConfig = {
2796
+ title: "高级",
2797
+ lazy: true,
2798
+ items: [
2799
+ {
2800
+ name: "created",
2801
+ text: "created",
2802
+ labelWidth: "100px",
2803
+ type: "code-select"
2804
+ },
2805
+ {
2806
+ name: "mounted",
2807
+ text: "mounted",
2808
+ labelWidth: "100px",
2809
+ type: "code-select"
2810
+ }
2811
+ ]
2812
+ };
2813
+ const displayTabConfig = {
2814
+ title: "显示条件",
2815
+ display: (vm, { model }) => model.type !== "page",
2816
+ items: [
2817
+ {
2818
+ type: "groupList",
2819
+ name: "displayConds",
2820
+ items: [
2821
+ {
2822
+ type: "table",
2823
+ name: "cond",
2824
+ items: [
2825
+ {
2826
+ type: "data-source-field-select",
2827
+ name: "field",
2828
+ label: "字段"
2829
+ },
2830
+ {
2831
+ type: "select",
2832
+ options: (mForm, { model }) => {
2833
+ const [id, field] = model.field;
2834
+ const ds = dataSourceService.getDataSourceById(id);
2835
+ const type = ds?.fields.find((f) => f.name === field)?.type;
2836
+ if (type === "array") {
2837
+ return arrayOptions;
2838
+ }
2839
+ if (type === "boolean") {
2840
+ return [
2841
+ { text: "是", value: "is" },
2842
+ { text: "不是", value: "not" }
2843
+ ];
2844
+ }
2845
+ if (type === "number") {
2846
+ return [...eqOptions, ...numberOptions];
2847
+ }
2848
+ if (type === "string") {
2849
+ return [...arrayOptions, ...eqOptions];
2850
+ }
2851
+ return [...arrayOptions, ...eqOptions, ...numberOptions];
2852
+ },
2853
+ label: "条件",
2854
+ name: "op"
2855
+ },
2856
+ {
2857
+ label: "值",
2858
+ items: [
2859
+ {
2860
+ name: "value",
2861
+ display: (vm, { model }) => !["between", "not_between", "is", "not"].includes(model.op)
2862
+ },
2863
+ {
2864
+ name: "value",
2865
+ type: "select",
2866
+ options: [
2867
+ { text: "true", value: true },
2868
+ { text: "false", value: false }
2869
+ ],
2870
+ display: (vm, { model }) => ["is", "not"].includes(model.op)
2871
+ },
2872
+ {
2873
+ name: "range",
2874
+ type: "number-range",
2875
+ display: (vm, { model }) => ["between", "not_between"].includes(model.op) && !["is", "not"].includes(model.op)
2876
+ }
2877
+ ]
2878
+ }
2879
+ ]
2880
+ }
2881
+ ]
2882
+ }
2883
+ ]
2884
+ };
2885
+ const fillConfig = (config = []) => [
2886
+ {
2887
+ type: "tab",
2888
+ items: [
2889
+ {
2890
+ title: "属性",
2891
+ labelWidth: "80px",
2892
+ items: [
2893
+ // 组件类型,必须要有
2894
+ {
2895
+ text: "type",
2896
+ name: "type",
2897
+ type: "hidden"
2898
+ },
2899
+ // 组件id,必须要有
2900
+ {
2901
+ name: "id",
2902
+ type: "display",
2903
+ text: "id"
2904
+ },
2905
+ {
2906
+ name: "name",
2907
+ text: "组件名称"
2908
+ },
2909
+ ...config
2910
+ ]
2911
+ },
2912
+ { ...styleTabConfig },
2913
+ { ...eventTabConfig },
2914
+ { ...advancedTabConfig },
2915
+ { ...displayTabConfig }
2916
+ ]
2917
+ }
2918
+ ];
2919
+
2920
+ const log = (...args) => {
2921
+ if (process.env.NODE_ENV === "development") {
2922
+ console.log("magic editor: ", ...args);
2923
+ }
2924
+ };
2925
+ const info = (...args) => {
2926
+ if (process.env.NODE_ENV === "development") {
2927
+ console.info("magic editor: ", ...args);
2928
+ }
2929
+ };
2930
+ const warn = (...args) => {
2931
+ if (process.env.NODE_ENV === "development") {
2932
+ console.warn("magic editor: ", ...args);
2933
+ }
2934
+ };
2935
+ const debug = (...args) => {
2936
+ if (process.env.NODE_ENV === "development") {
2937
+ console.debug("magic editor: ", ...args);
2938
+ }
2939
+ };
2940
+ const error = (...args) => {
2941
+ if (process.env.NODE_ENV === "development") {
2942
+ console.error("magic editor: ", ...args);
2456
2943
  }
2457
2944
  };
2458
2945
 
@@ -2508,6 +2995,14 @@
2508
2995
  KeyBindingCommand2["SWITCH_NODE"] = "tmagic-system-switch-node";
2509
2996
  return KeyBindingCommand2;
2510
2997
  })(KeyBindingCommand || {});
2998
+ var DepTargetType = /* @__PURE__ */ ((DepTargetType2) => {
2999
+ DepTargetType2["DEFAULT"] = "default";
3000
+ DepTargetType2["CODE_BLOCK"] = "code-block";
3001
+ DepTargetType2["DATA_SOURCE"] = "data-source";
3002
+ DepTargetType2["DATA_SOURCE_METHOD"] = "data-source-method";
3003
+ DepTargetType2["DATA_SOURCE_COND"] = "data-source-cond";
3004
+ return DepTargetType2;
3005
+ })(DepTargetType || {});
2511
3006
 
2512
3007
  const COPY_STORAGE_KEY = "$MagicEditorCopyData";
2513
3008
  const getPageList = (app) => {
@@ -2684,158 +3179,36 @@
2684
3179
  this.listCursor += 1;
2685
3180
  if (this.elementList.length > this.listMaxSize) {
2686
3181
  this.elementList.shift();
2687
- this.listCursor -= 1;
2688
- }
2689
- }
2690
- canUndo() {
2691
- return this.listCursor > 1;
2692
- }
2693
- // 返回undo后的当前元素
2694
- undo() {
2695
- if (!this.canUndo()) {
2696
- return null;
2697
- }
2698
- this.listCursor -= 1;
2699
- return this.getCurrentElement();
2700
- }
2701
- canRedo() {
2702
- return this.elementList.length > this.listCursor;
2703
- }
2704
- // 返回redo后的当前元素
2705
- redo() {
2706
- if (!this.canRedo()) {
2707
- return null;
2708
- }
2709
- this.listCursor += 1;
2710
- return this.getCurrentElement();
2711
- }
2712
- getCurrentElement() {
2713
- if (this.listCursor < 1) {
2714
- return null;
2715
- }
2716
- return lodashEs.cloneDeep(this.elementList[this.listCursor - 1]);
2717
- }
2718
- }
2719
-
2720
- const compose = (middleware) => {
2721
- if (!Array.isArray(middleware))
2722
- throw new TypeError("Middleware 必须是一个数组!");
2723
- for (const fn of middleware) {
2724
- if (typeof fn !== "function")
2725
- throw new TypeError("Middleware 必须由函数组成!");
2726
- }
2727
- return (args, next) => {
2728
- let index = -1;
2729
- return dispatch(0);
2730
- function dispatch(i) {
2731
- if (i <= index)
2732
- return Promise.reject(new Error("next() 被多次调用"));
2733
- index = i;
2734
- let fn = middleware[i];
2735
- if (i === middleware.length && next)
2736
- fn = next;
2737
- if (!fn)
2738
- return Promise.resolve();
2739
- try {
2740
- return Promise.resolve(fn(...args, dispatch.bind(null, i + 1)));
2741
- } catch (err) {
2742
- return Promise.reject(err);
2743
- }
2744
- }
2745
- };
2746
- };
2747
-
2748
- const methodName = (prefix, name) => `${prefix}${name[0].toUpperCase()}${name.substring(1)}`;
2749
- const isError = (error) => Object.prototype.toString.call(error) === "[object Error]";
2750
- const doAction = async (args, scope, sourceMethod, beforeMethodName, afterMethodName, fn) => {
2751
- try {
2752
- let beforeArgs = args;
2753
- for (const beforeMethod of scope.pluginOptionsList[beforeMethodName]) {
2754
- beforeArgs = await beforeMethod(...beforeArgs) || [];
2755
- if (isError(beforeArgs))
2756
- throw beforeArgs;
2757
- if (!Array.isArray(beforeArgs)) {
2758
- beforeArgs = [beforeArgs];
2759
- }
2760
- }
2761
- let returnValue = await fn(beforeArgs, sourceMethod.bind(scope));
2762
- for (const afterMethod of scope.pluginOptionsList[afterMethodName]) {
2763
- returnValue = await afterMethod(returnValue, ...beforeArgs);
2764
- if (isError(returnValue))
2765
- throw returnValue;
2766
- }
2767
- return returnValue;
2768
- } catch (error) {
2769
- throw error;
2770
- }
2771
- };
2772
- class BaseService extends events.EventEmitter {
2773
- pluginOptionsList = {};
2774
- middleware = {};
2775
- taskList = [];
2776
- doingTask = false;
2777
- constructor(methods = [], serialMethods = []) {
2778
- super();
2779
- methods.forEach((propertyName) => {
2780
- const scope = this;
2781
- const sourceMethod = scope[propertyName];
2782
- const beforeMethodName = methodName("before", propertyName);
2783
- const afterMethodName = methodName("after", propertyName);
2784
- this.pluginOptionsList[beforeMethodName] = [];
2785
- this.pluginOptionsList[afterMethodName] = [];
2786
- this.middleware[propertyName] = [];
2787
- const fn = compose(this.middleware[propertyName]);
2788
- Object.defineProperty(scope, propertyName, {
2789
- value: async (...args) => {
2790
- if (!serialMethods.includes(propertyName)) {
2791
- return doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
2792
- }
2793
- const promise = new Promise((resolve, reject) => {
2794
- this.taskList.push(async () => {
2795
- try {
2796
- const value = await doAction(args, scope, sourceMethod, beforeMethodName, afterMethodName, fn);
2797
- resolve(value);
2798
- } catch (e) {
2799
- reject(e);
2800
- }
2801
- });
2802
- });
2803
- if (!this.doingTask) {
2804
- this.doTask();
2805
- }
2806
- return promise;
2807
- }
2808
- });
2809
- });
3182
+ this.listCursor -= 1;
3183
+ }
2810
3184
  }
2811
- use(options) {
2812
- Object.entries(options).forEach(([methodName2, method]) => {
2813
- if (typeof method === "function")
2814
- this.middleware[methodName2].push(method);
2815
- });
3185
+ canUndo() {
3186
+ return this.listCursor > 1;
2816
3187
  }
2817
- usePlugin(options) {
2818
- Object.entries(options).forEach(([methodName2, method]) => {
2819
- if (typeof method === "function")
2820
- this.pluginOptionsList[methodName2].push(method);
2821
- });
3188
+ // 返回undo后的当前元素
3189
+ undo() {
3190
+ if (!this.canUndo()) {
3191
+ return null;
3192
+ }
3193
+ this.listCursor -= 1;
3194
+ return this.getCurrentElement();
2822
3195
  }
2823
- removeAllPlugins() {
2824
- Object.keys(this.pluginOptionsList).forEach((key) => {
2825
- this.pluginOptionsList[key] = [];
2826
- });
2827
- Object.keys(this.middleware).forEach((key) => {
2828
- this.middleware[key] = [];
2829
- });
3196
+ canRedo() {
3197
+ return this.elementList.length > this.listCursor;
2830
3198
  }
2831
- async doTask() {
2832
- this.doingTask = true;
2833
- let task = this.taskList.shift();
2834
- while (task) {
2835
- await task();
2836
- task = this.taskList.shift();
3199
+ // 返回redo后的当前元素
3200
+ redo() {
3201
+ if (!this.canRedo()) {
3202
+ return null;
2837
3203
  }
2838
- this.doingTask = false;
3204
+ this.listCursor += 1;
3205
+ return this.getCurrentElement();
3206
+ }
3207
+ getCurrentElement() {
3208
+ if (this.listCursor < 1) {
3209
+ return null;
3210
+ }
3211
+ return lodashEs.cloneDeep(this.elementList[this.listCursor - 1]);
2839
3212
  }
2840
3213
  }
2841
3214
 
@@ -3056,7 +3429,7 @@
3056
3429
  this.emit("props-configs-change");
3057
3430
  }
3058
3431
  async fillConfig(config) {
3059
- return fillConfig$1(config);
3432
+ return fillConfig(config);
3060
3433
  }
3061
3434
  /**
3062
3435
  * 为指定类型组件设置组件属性表单配置
@@ -4094,11 +4467,8 @@
4094
4467
  editorService.sort(ev.src, ev.dist);
4095
4468
  });
4096
4469
  stage.on("remove", (ev) => {
4097
- editorService.remove(
4098
- ev.data.map(({ el }) => ({
4099
- id: el.id
4100
- }))
4101
- );
4470
+ const nodes = ev.data.map(({ el }) => editorService.getNodeById(el.id));
4471
+ editorService.remove(nodes.filter((node) => Boolean(node)));
4102
4472
  });
4103
4473
  stage.on("select-parent", () => {
4104
4474
  const parent = editorService.get("parent");
@@ -4153,7 +4523,7 @@
4153
4523
  onClick: clickHandler
4154
4524
  }, [
4155
4525
  vue.createElementVNode("div", null, [
4156
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
4526
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
4157
4527
  ]),
4158
4528
  _hoisted_3$4
4159
4529
  ])
@@ -4244,7 +4614,7 @@
4244
4614
  vue.renderSlot(_ctx.$slots, "nav"),
4245
4615
  vue.renderSlot(_ctx.$slots, "content-before"),
4246
4616
  showSrc.value ? vue.renderSlot(_ctx.$slots, "src-code", { key: 0 }, () => [
4247
- vue.createVNode(_sfc_main$K, {
4617
+ vue.createVNode(_sfc_main$L, {
4248
4618
  class: "m-editor-content",
4249
4619
  "init-values": root.value,
4250
4620
  options: vue.unref(codeOptions),
@@ -4392,7 +4762,7 @@
4392
4762
  disabled: disabled.value
4393
4763
  }, {
4394
4764
  default: vue.withCtx(() => [
4395
- _ctx.data.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
4765
+ _ctx.data.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
4396
4766
  key: 0,
4397
4767
  icon: _ctx.data.icon
4398
4768
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
@@ -4409,7 +4779,7 @@
4409
4779
  disabled: disabled.value
4410
4780
  }, {
4411
4781
  default: vue.withCtx(() => [
4412
- _ctx.data.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
4782
+ _ctx.data.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
4413
4783
  key: 0,
4414
4784
  icon: _ctx.data.icon
4415
4785
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
@@ -4809,7 +5179,7 @@
4809
5179
  const props = __props;
4810
5180
  const { codeBlockService, depService, editorService } = vue.inject("services") || {};
4811
5181
  const codeList = vue.computed(
4812
- () => Object.values(depService?.targets["code-block"] || {}).map((target) => {
5182
+ () => Object.values(depService?.getTargets(DepTargetType.CODE_BLOCK) || {}).map((target) => {
4813
5183
  const compNodes = Object.entries(target.deps).map(([id, dep]) => ({
4814
5184
  name: dep.name,
4815
5185
  type: "node",
@@ -4916,7 +5286,7 @@
4916
5286
  placement: "bottom"
4917
5287
  }, {
4918
5288
  default: vue.withCtx(() => [
4919
- vue.createVNode(_sfc_main$E, {
5289
+ vue.createVNode(_sfc_main$F, {
4920
5290
  icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
4921
5291
  class: "edit-icon",
4922
5292
  onClick: vue.withModifiers(($event) => editCode(data.id), ["stop"])
@@ -4931,7 +5301,7 @@
4931
5301
  placement: "bottom"
4932
5302
  }, {
4933
5303
  default: vue.withCtx(() => [
4934
- vue.createVNode(_sfc_main$E, {
5304
+ vue.createVNode(_sfc_main$F, {
4935
5305
  icon: vue.unref(iconsVue.Close),
4936
5306
  class: "edit-icon",
4937
5307
  onClick: vue.withModifiers(($event) => deleteCode(`${data.id}`), ["stop"])
@@ -5005,7 +5375,7 @@
5005
5375
  ]),
5006
5376
  _: 3
5007
5377
  }, 8, ["custom-error", "onEdit", "onRemove"]),
5008
- vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$G, {
5378
+ vue.unref(codeConfig) ? (vue.openBlock(), vue.createBlock(_sfc_main$H, {
5009
5379
  key: 0,
5010
5380
  ref_key: "codeBlockEditor",
5011
5381
  ref: codeBlockEditor,
@@ -5069,6 +5439,7 @@
5069
5439
  ref_key: "fomDrawer",
5070
5440
  ref: fomDrawer,
5071
5441
  "label-width": "80px",
5442
+ "close-on-press-escape": false,
5072
5443
  title: _ctx.title,
5073
5444
  width: size.value,
5074
5445
  config: dataSourceConfig.value,
@@ -5097,18 +5468,43 @@
5097
5468
  setup(__props, { expose: __expose, emit }) {
5098
5469
  const { depService, editorService, dataSourceService } = vue.inject("services") || {};
5099
5470
  const editable = vue.computed(() => dataSourceService?.get("editable") ?? true);
5471
+ const dataSources = vue.computed(() => dataSourceService?.get("dataSources") || []);
5472
+ const dsDep = vue.computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE) || {});
5473
+ const dsMethodDep = vue.computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_METHOD) || {});
5474
+ const dsCondDep = vue.computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_COND) || {});
5475
+ const getKeyTreeConfig = (dep, type) => dep.keys.map((key) => ({ name: key, id: key, type: "key", isMethod: type === "method", isCond: type === "cond" }));
5476
+ const getNodeTreeConfig = (id, dep, type) => ({
5477
+ name: dep.name,
5478
+ type: "node",
5479
+ id,
5480
+ children: getKeyTreeConfig(dep, type)
5481
+ });
5100
5482
  const list = vue.computed(
5101
- () => Object.values(depService?.targets["data-source"] || {}).map((target) => ({
5102
- id: target.id,
5103
- name: target.name,
5104
- type: "code",
5105
- children: Object.entries(target.deps).map(([id, dep]) => ({
5106
- name: dep.name,
5107
- type: "node",
5108
- id,
5109
- children: dep.keys.map((key) => ({ name: key, id: key, type: "key" }))
5110
- }))
5111
- }))
5483
+ () => dataSources.value.map((ds) => {
5484
+ const dsDeps = dsDep.value[ds.id].deps;
5485
+ const dsMethodDeps = dsMethodDep.value[ds.id].deps;
5486
+ const dsCondDeps = dsCondDep.value[ds.id].deps;
5487
+ const children = [];
5488
+ const mergeChildren = (deps, type) => {
5489
+ Object.entries(deps).forEach(([id, dep]) => {
5490
+ const nodeItem = children.find((item) => item.id === id);
5491
+ if (nodeItem) {
5492
+ nodeItem.children = nodeItem.children.concat(getKeyTreeConfig(dep, type));
5493
+ } else {
5494
+ children.push(getNodeTreeConfig(id, dep, type));
5495
+ }
5496
+ });
5497
+ };
5498
+ mergeChildren(dsDeps);
5499
+ mergeChildren(dsMethodDeps, "method");
5500
+ mergeChildren(dsCondDeps, "cond");
5501
+ return {
5502
+ id: ds.id,
5503
+ name: ds.title,
5504
+ type: "ds",
5505
+ children
5506
+ };
5507
+ })
5112
5508
  );
5113
5509
  const editHandler = (id) => {
5114
5510
  emit("edit", id);
@@ -5159,27 +5555,27 @@
5159
5555
  class: "list-container"
5160
5556
  }, [
5161
5557
  vue.createElementVNode("div", _hoisted_2$3, [
5162
- data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5558
+ data.type === "code" ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
5163
5559
  key: 0,
5164
5560
  class: "codeIcon",
5165
5561
  icon: vue.unref(iconsVue.Coin)
5166
5562
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5167
- data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
5563
+ data.type === "node" ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
5168
5564
  key: 1,
5169
5565
  class: "compIcon",
5170
5566
  icon: vue.unref(iconsVue.Aim)
5171
5567
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
5172
5568
  vue.createElementVNode("span", {
5173
- class: vue.normalizeClass(["name", { code: data.type === "code", hook: data.type === "key" }])
5174
- }, vue.toDisplayString(data.name) + "" + vue.toDisplayString(data.id) + ")", 3),
5175
- data.type === "code" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$1, [
5569
+ class: vue.normalizeClass(["name", { code: data.type === "ds", hook: data.type === "key" }])
5570
+ }, vue.toDisplayString(data.type === "key" ? data.name : `${data.name}(${data.id})`), 3),
5571
+ data.type === "ds" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$1, [
5176
5572
  vue.createVNode(vue.unref(design.TMagicTooltip), {
5177
5573
  effect: "dark",
5178
5574
  content: editable.value ? "编辑" : "查看",
5179
5575
  placement: "bottom"
5180
5576
  }, {
5181
5577
  default: vue.withCtx(() => [
5182
- vue.createVNode(_sfc_main$E, {
5578
+ vue.createVNode(_sfc_main$F, {
5183
5579
  icon: editable.value ? vue.unref(iconsVue.Edit) : vue.unref(iconsVue.View),
5184
5580
  class: "edit-icon",
5185
5581
  onClick: vue.withModifiers(($event) => editHandler(`${data.id}`), ["stop"])
@@ -5194,7 +5590,7 @@
5194
5590
  placement: "bottom"
5195
5591
  }, {
5196
5592
  default: vue.withCtx(() => [
5197
- vue.createVNode(_sfc_main$E, {
5593
+ vue.createVNode(_sfc_main$F, {
5198
5594
  icon: vue.unref(iconsVue.Close),
5199
5595
  class: "edit-icon",
5200
5596
  onClick: vue.withModifiers(($event) => removeHandler(`${data.id}`), ["stop"])
@@ -5380,7 +5776,7 @@
5380
5776
  name: `${index}`
5381
5777
  }, {
5382
5778
  title: vue.withCtx(() => [
5383
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Grid) }, null, 8, ["icon"]),
5779
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.Grid) }, null, 8, ["icon"]),
5384
5780
  vue.createTextVNode(vue.toDisplayString(group.title), 1)
5385
5781
  ]),
5386
5782
  default: vue.withCtx(() => [
@@ -5395,7 +5791,7 @@
5395
5791
  onDrag: dragHandler
5396
5792
  }, [
5397
5793
  vue.renderSlot(_ctx.$slots, "component-list-item", { component: item }, () => [
5398
- vue.createVNode(_sfc_main$E, {
5794
+ vue.createVNode(_sfc_main$F, {
5399
5795
  icon: item.icon
5400
5796
  }, null, 8, ["icon"]),
5401
5797
  vue.createVNode(vue.unref(design.TMagicTooltip), {
@@ -6158,7 +6554,7 @@
6158
6554
  (vue.openBlock(), vue.createElementBlock("div", {
6159
6555
  key: config.text
6160
6556
  }, [
6161
- config.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$E, {
6557
+ config.icon ? (vue.openBlock(), vue.createBlock(_sfc_main$F, {
6162
6558
  key: 0,
6163
6559
  icon: config.icon
6164
6560
  }, null, 8, ["icon"])) : vue.createCommentVNode("", true),
@@ -6376,14 +6772,14 @@
6376
6772
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
6377
6773
  onClick: addPage
6378
6774
  }, [
6379
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
6775
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.Plus) }, null, 8, ["icon"])
6380
6776
  ])) : (vue.openBlock(), vue.createElementBlock("div", _hoisted_1$3)),
6381
6777
  canScroll.value ? (vue.openBlock(), vue.createElementBlock("div", {
6382
6778
  key: 2,
6383
6779
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
6384
6780
  onClick: _cache[0] || (_cache[0] = ($event) => scroll("left"))
6385
6781
  }, [
6386
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.ArrowLeftBold) }, null, 8, ["icon"])
6782
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.ArrowLeftBold) }, null, 8, ["icon"])
6387
6783
  ])) : vue.createCommentVNode("", true),
6388
6784
  pageLength.value ? (vue.openBlock(), vue.createElementBlock("div", {
6389
6785
  key: 3,
@@ -6399,7 +6795,7 @@
6399
6795
  class: "m-editor-page-bar-item m-editor-page-bar-item-icon",
6400
6796
  onClick: _cache[1] || (_cache[1] = ($event) => scroll("right"))
6401
6797
  }, [
6402
- vue.createVNode(_sfc_main$E, { icon: vue.unref(iconsVue.ArrowRightBold) }, null, 8, ["icon"])
6798
+ vue.createVNode(_sfc_main$F, { icon: vue.unref(iconsVue.ArrowRightBold) }, null, 8, ["icon"])
6403
6799
  ])) : vue.createCommentVNode("", true)
6404
6800
  ], 512);
6405
6801
  };
@@ -7424,178 +7820,6 @@
7424
7820
  }
7425
7821
  const componentListService = new ComponentList();
7426
7822
 
7427
- const BaseFormConfig = [
7428
- {
7429
- name: "id",
7430
- type: "hidden"
7431
- },
7432
- {
7433
- name: "type",
7434
- text: "类型",
7435
- type: "select",
7436
- options: [
7437
- { text: "基础", value: "base" },
7438
- { text: "HTTP", value: "http" }
7439
- ],
7440
- defaultValue: "base"
7441
- },
7442
- {
7443
- name: "title",
7444
- text: "名称",
7445
- rules: [
7446
- {
7447
- required: true,
7448
- message: "请输入名称"
7449
- }
7450
- ]
7451
- },
7452
- {
7453
- name: "description",
7454
- text: "描述"
7455
- }
7456
- ];
7457
-
7458
- const HttpFormConfig = [
7459
- {
7460
- name: "autoFetch",
7461
- text: "自动请求",
7462
- type: "switch",
7463
- defaultValue: true
7464
- },
7465
- {
7466
- type: "fieldset",
7467
- name: "options",
7468
- legend: "HTTP 配置",
7469
- items: [
7470
- {
7471
- name: "url",
7472
- text: "URL"
7473
- },
7474
- {
7475
- name: "method",
7476
- text: "Method",
7477
- type: "select",
7478
- options: [
7479
- { text: "GET", value: "GET" },
7480
- { text: "POST", value: "POST" },
7481
- { text: "PUT", value: "PUT" },
7482
- { text: "DELETE", value: "DELETE" }
7483
- ]
7484
- },
7485
- {
7486
- name: "params",
7487
- type: "key-value",
7488
- defaultValue: {},
7489
- text: "参数"
7490
- },
7491
- {
7492
- name: "data",
7493
- type: "key-value",
7494
- defaultValue: {},
7495
- text: "请求体"
7496
- },
7497
- {
7498
- name: "headers",
7499
- type: "key-value",
7500
- defaultValue: {},
7501
- text: "请求头"
7502
- }
7503
- ]
7504
- }
7505
- ];
7506
-
7507
- const fillConfig = (config) => [
7508
- ...BaseFormConfig,
7509
- ...config,
7510
- {
7511
- type: "panel",
7512
- title: "数据定义",
7513
- items: [
7514
- {
7515
- name: "fields",
7516
- type: "data-source-fields",
7517
- defaultValue: []
7518
- }
7519
- ]
7520
- },
7521
- {
7522
- type: "panel",
7523
- title: "方法定义",
7524
- items: [
7525
- {
7526
- name: "methods",
7527
- type: "data-source-methods",
7528
- defaultValue: []
7529
- }
7530
- ]
7531
- }
7532
- ];
7533
- const getFormConfig = (type, configs) => {
7534
- switch (type) {
7535
- case "base":
7536
- return fillConfig([]);
7537
- case "http":
7538
- return fillConfig(HttpFormConfig);
7539
- default:
7540
- return fillConfig(configs[type] || []);
7541
- }
7542
- };
7543
-
7544
- class DataSource extends BaseService {
7545
- state = vue.reactive({
7546
- dataSources: [],
7547
- editable: true,
7548
- configs: {}
7549
- });
7550
- set(name, value) {
7551
- this.state[name] = value;
7552
- }
7553
- get(name) {
7554
- return this.state[name];
7555
- }
7556
- getFormConfig(type = "base") {
7557
- return getFormConfig(type, this.get("configs"));
7558
- }
7559
- setFormConfig(type, config) {
7560
- this.get("configs")[type] = config;
7561
- }
7562
- add(config) {
7563
- const newConfig = {
7564
- ...config,
7565
- id: this.createId()
7566
- };
7567
- this.get("dataSources").push(newConfig);
7568
- this.emit("add", newConfig);
7569
- }
7570
- update(config) {
7571
- const dataSources = this.get("dataSources");
7572
- const index = dataSources.findIndex((ds) => ds.id === config.id);
7573
- dataSources[index] = lodashEs.cloneDeep(config);
7574
- this.emit("update", config);
7575
- }
7576
- remove(id) {
7577
- const dataSources = this.get("dataSources");
7578
- const index = dataSources.findIndex((ds) => ds.id === id);
7579
- dataSources.splice(index, 1);
7580
- this.emit("remove", id);
7581
- }
7582
- getDataSourceById(id) {
7583
- return this.get("dataSources").find((ds) => ds.id === id);
7584
- }
7585
- resetState() {
7586
- this.set("dataSources", []);
7587
- }
7588
- destroy() {
7589
- this.removeAllListeners();
7590
- this.resetState();
7591
- this.removeAllPlugins();
7592
- }
7593
- createId() {
7594
- return `ds_${utils.guid()}`;
7595
- }
7596
- }
7597
- const dataSourceService = new DataSource();
7598
-
7599
7823
  class Target extends events.EventEmitter {
7600
7824
  /**
7601
7825
  * 如何识别目标
@@ -7613,7 +7837,7 @@
7613
7837
  /**
7614
7838
  * 不同的目标可以进行分类,例如代码块,数据源可以为两个不同的type
7615
7839
  */
7616
- type = "default";
7840
+ type = DepTargetType.DEFAULT;
7617
7841
  /**
7618
7842
  * 依赖详情
7619
7843
  * 实例:{ 'node_id': { name: 'node_name', keys: [ created, mounted ] } }
@@ -7696,7 +7920,7 @@
7696
7920
  * @param type 分类
7697
7921
  * @returns Target[]
7698
7922
  */
7699
- getTargets(type = "default") {
7923
+ getTargets(type = DepTargetType.DEFAULT) {
7700
7924
  return this.targets[type] || {};
7701
7925
  }
7702
7926
  /**
@@ -7755,7 +7979,7 @@
7755
7979
  * @param type 分类
7756
7980
  * @returns void
7757
7981
  */
7758
- removeTargets(type = "default") {
7982
+ removeTargets(type = DepTargetType.DEFAULT) {
7759
7983
  const targets = this.targets[type];
7760
7984
  if (!targets)
7761
7985
  return;
@@ -7821,9 +8045,11 @@
7821
8045
  this.emit("update-dep", node, fullKey);
7822
8046
  } else if (!keyIsItems && Array.isArray(value)) {
7823
8047
  value.forEach((item, index) => {
7824
- collectTarget(item, `${fullKey}.${index}`);
8048
+ if (utils.isObject(item)) {
8049
+ collectTarget(item, `${fullKey}.${index}`);
8050
+ }
7825
8051
  });
7826
- } else if (Object.prototype.toString.call(value) === "[object Object]") {
8052
+ } else if (utils.isObject(value)) {
7827
8053
  collectTarget(value, fullKey);
7828
8054
  }
7829
8055
  if (keyIsItems && deep && Array.isArray(value)) {
@@ -7833,6 +8059,8 @@
7833
8059
  }
7834
8060
  };
7835
8061
  Object.entries(config).forEach(([key, value]) => {
8062
+ if (typeof value === "undefined" || value === "")
8063
+ return;
7836
8064
  doCollect(key, value);
7837
8065
  });
7838
8066
  };
@@ -8268,7 +8496,7 @@
8268
8496
  };
8269
8497
 
8270
8498
  const createCodeBlockTarget = (id, codeBlock) => new Target({
8271
- type: "code-block",
8499
+ type: DepTargetType.CODE_BLOCK,
8272
8500
  id,
8273
8501
  name: codeBlock.name,
8274
8502
  isTarget: (key, value) => {
@@ -8282,15 +8510,34 @@
8282
8510
  return false;
8283
8511
  }
8284
8512
  });
8285
- const createDataSourceTarget = (id, ds) => new Target({
8286
- type: "data-source",
8513
+ const createDataSourceTarget = (id) => new Target({
8514
+ type: DepTargetType.DATA_SOURCE,
8287
8515
  id,
8288
- name: ds.title || `${id}`,
8289
8516
  isTarget: (key, value) => (
8290
8517
  // 关联数据源对象或者在模板在使用数据源
8291
- value.isBindDataSource && value.dataSourceId || typeof value === "string" && value.includes(`${id}`)
8518
+ value?.isBindDataSource && value.dataSourceId || typeof value === "string" && value.includes(`${id}`)
8292
8519
  )
8293
8520
  });
8521
+ const createDataSourceCondTarget = (id) => new Target({
8522
+ type: DepTargetType.DATA_SOURCE_COND,
8523
+ id,
8524
+ isTarget: (key, value) => {
8525
+ if (!Array.isArray(value) || value[0] !== id)
8526
+ return false;
8527
+ const ds = dataSourceService.getDataSourceById(id);
8528
+ return Boolean(ds?.fields?.find((field) => field.name === value[1]));
8529
+ }
8530
+ });
8531
+ const createDataSourceMethodTarget = (id) => new Target({
8532
+ type: DepTargetType.DATA_SOURCE_METHOD,
8533
+ id,
8534
+ isTarget: (key, value) => {
8535
+ if (!Array.isArray(value) || value[0] !== id)
8536
+ return false;
8537
+ const ds = dataSourceService.getDataSourceById(id);
8538
+ return Boolean(ds?.methods?.find((method) => method.name === value[1]));
8539
+ }
8540
+ });
8294
8541
 
8295
8542
  const initServiceState = (props, {
8296
8543
  editorService,
@@ -8393,6 +8640,7 @@
8393
8640
  return;
8394
8641
  if (app.dsl) {
8395
8642
  app.dsl.dataSourceDeps = root.dataSourceDeps;
8643
+ app.dsl.dataSourceCondDeps = root.dataSourceCondDeps;
8396
8644
  app.dsl.dataSources = root.dataSources;
8397
8645
  }
8398
8646
  updateDataSoucreSchema();
@@ -8410,21 +8658,30 @@
8410
8658
  });
8411
8659
  };
8412
8660
  const targetAddHandler = (target) => {
8413
- if (target.type !== "data-source")
8414
- return;
8415
8661
  const root = editorService.get("root");
8416
8662
  if (!root)
8417
8663
  return;
8418
- if (!root.dataSourceDeps) {
8419
- root.dataSourceDeps = {};
8664
+ if (target.type === DepTargetType.DATA_SOURCE) {
8665
+ if (!root.dataSourceDeps) {
8666
+ root.dataSourceDeps = {};
8667
+ }
8668
+ root.dataSourceDeps[target.id] = target.deps;
8669
+ }
8670
+ if (target.type === DepTargetType.DATA_SOURCE_COND) {
8671
+ if (!root.dataSourceCondDeps) {
8672
+ root.dataSourceCondDeps = {};
8673
+ }
8674
+ root.dataSourceCondDeps[target.id] = target.deps;
8420
8675
  }
8421
- root.dataSourceDeps[target.id] = target.deps;
8422
8676
  };
8423
8677
  const targetRemoveHandler = (id) => {
8424
8678
  const root = editorService.get("root");
8425
- if (!root?.dataSourceDeps)
8426
- return;
8427
- delete root.dataSourceDeps[id];
8679
+ if (root?.dataSourceDeps) {
8680
+ delete root.dataSourceDeps[id];
8681
+ }
8682
+ if (root?.dataSourceCondDeps) {
8683
+ delete root.dataSourceCondDeps[id];
8684
+ }
8428
8685
  };
8429
8686
  const depUpdateHandler = (node) => {
8430
8687
  upateNodeWhenDataSourceChange([node]);
@@ -8436,6 +8693,11 @@
8436
8693
  depService.on("remove-target", targetRemoveHandler);
8437
8694
  depService.on("dep-update", depUpdateHandler);
8438
8695
  depService.on("collected", collectedHandler);
8696
+ const initDataSourceDepTarget = (ds) => {
8697
+ depService.addTarget(createDataSourceTarget(ds.id));
8698
+ depService.addTarget(createDataSourceMethodTarget(ds.id));
8699
+ depService.addTarget(createDataSourceCondTarget(ds.id));
8700
+ };
8439
8701
  const rootChangeHandler = async (value, preValue) => {
8440
8702
  const nodeId = editorService.get("node")?.id || props.defaultSelected;
8441
8703
  let node;
@@ -8458,12 +8720,12 @@
8458
8720
  value.dataSources = value.dataSources || [];
8459
8721
  codeBlockService.setCodeDsl(value.codeBlocks);
8460
8722
  dataSourceService.set("dataSources", value.dataSources);
8461
- depService.removeTargets("code-block");
8723
+ depService.removeTargets(DepTargetType.CODE_BLOCK);
8462
8724
  Object.entries(value.codeBlocks).forEach(([id, code]) => {
8463
8725
  depService.addTarget(createCodeBlockTarget(id, code));
8464
8726
  });
8465
8727
  value.dataSources.forEach((ds) => {
8466
- depService.addTarget(createDataSourceTarget(ds.id, ds));
8728
+ initDataSourceDepTarget(ds);
8467
8729
  });
8468
8730
  if (value && Array.isArray(value.items)) {
8469
8731
  depService.collect(value.items, true);
@@ -8502,15 +8764,12 @@
8502
8764
  codeBlockService.on("addOrUpdate", codeBlockAddOrUpdateHandler);
8503
8765
  codeBlockService.on("remove", codeBlockRemoveHandler);
8504
8766
  const dataSourceAddHandler = (config) => {
8505
- depService.addTarget(createDataSourceTarget(config.id, config));
8767
+ initDataSourceDepTarget(config);
8506
8768
  getApp()?.dataSourceManager?.addDataSource(config);
8507
8769
  };
8508
8770
  const dataSourceUpdateHandler = (config) => {
8509
- if (config.title) {
8510
- depService.getTarget(config.id).name = config.title;
8511
- }
8512
8771
  const root = editorService.get("root");
8513
- const targets = depService.getTargets("data-source");
8772
+ const targets = depService.getTargets(DepTargetType.DATA_SOURCE);
8514
8773
  const nodes = utils.getNodes(Object.keys(targets[config.id].deps), root?.items);
8515
8774
  upateNodeWhenDataSourceChange(nodes);
8516
8775
  };
@@ -8712,41 +8971,44 @@
8712
8971
  setConfig(option);
8713
8972
  app.component(Editor.name, Editor);
8714
8973
  app.component("m-fields-ui-select", _sfc_main$v);
8715
- app.component("m-fields-code-link", _sfc_main$I);
8716
- app.component("m-fields-vs-code", _sfc_main$J);
8717
- app.component("magic-code-editor", _sfc_main$K);
8718
- app.component("m-fields-code-select", _sfc_main$H);
8719
- app.component("m-fields-code-select-col", _sfc_main$D);
8974
+ app.component("m-fields-code-link", _sfc_main$J);
8975
+ app.component("m-fields-vs-code", _sfc_main$K);
8976
+ app.component("magic-code-editor", _sfc_main$L);
8977
+ app.component("m-fields-code-select", _sfc_main$I);
8978
+ app.component("m-fields-code-select-col", _sfc_main$E);
8720
8979
  app.component("m-fields-event-select", _sfc_main$x);
8721
- app.component("m-fields-data-source-fields", _sfc_main$C);
8980
+ app.component("m-fields-data-source-fields", _sfc_main$D);
8722
8981
  app.component("m-fields-key-value", _sfc_main$w);
8723
8982
  app.component("m-fields-data-source-input", _sfc_main$B);
8724
8983
  app.component("m-fields-data-source-select", _sfc_main$y);
8725
8984
  app.component("m-fields-data-source-methods", _sfc_main$A);
8726
8985
  app.component("m-fields-data-source-method-select", _sfc_main$z);
8986
+ app.component("m-fields-data-source-field-select", _sfc_main$C);
8727
8987
  }
8728
8988
  };
8729
8989
 
8730
8990
  exports.CODE_DRAFT_STORAGE_KEY = CODE_DRAFT_STORAGE_KEY;
8731
8991
  exports.COPY_STORAGE_KEY = COPY_STORAGE_KEY;
8732
- exports.CodeBlockEditor = _sfc_main$G;
8992
+ exports.CodeBlockEditor = _sfc_main$H;
8733
8993
  exports.CodeBlockList = _sfc_main$k;
8734
8994
  exports.CodeBlockListPanel = _sfc_main$j;
8735
8995
  exports.CodeDeleteErrorType = CodeDeleteErrorType;
8736
- exports.CodeSelect = _sfc_main$H;
8737
- exports.CodeSelectCol = _sfc_main$D;
8996
+ exports.CodeSelect = _sfc_main$I;
8997
+ exports.CodeSelectCol = _sfc_main$E;
8738
8998
  exports.ColumnLayout = ColumnLayout;
8739
8999
  exports.ComponentListPanel = _sfc_main$f;
8740
9000
  exports.ContentMenu = _sfc_main$e;
8741
- exports.DataSourceFields = _sfc_main$C;
9001
+ exports.DataSourceFieldSelect = _sfc_main$C;
9002
+ exports.DataSourceFields = _sfc_main$D;
8742
9003
  exports.DataSourceInput = _sfc_main$B;
8743
9004
  exports.DataSourceMethodSelect = _sfc_main$z;
8744
9005
  exports.DataSourceMethods = _sfc_main$A;
8745
9006
  exports.DataSourceSelect = _sfc_main$y;
9007
+ exports.DepTargetType = DepTargetType;
8746
9008
  exports.EventSelect = _sfc_main$x;
8747
9009
  exports.Fixed2Other = Fixed2Other;
8748
9010
  exports.H_GUIDE_LINE_STORAGE_KEY = H_GUIDE_LINE_STORAGE_KEY;
8749
- exports.Icon = _sfc_main$E;
9011
+ exports.Icon = _sfc_main$F;
8750
9012
  exports.KeyBindingCommand = KeyBindingCommand;
8751
9013
  exports.KeyValue = _sfc_main$w;
8752
9014
  exports.Keys = Keys;
@@ -8757,10 +9019,11 @@
8757
9019
  exports.PropsPanel = _sfc_main$o;
8758
9020
  exports.Resizer = _sfc_main$u;
8759
9021
  exports.SplitView = _sfc_main$t;
8760
- exports.TMagicCodeEditor = _sfc_main$K;
9022
+ exports.TMagicCodeEditor = _sfc_main$L;
8761
9023
  exports.TMagicEditor = Editor;
8762
9024
  exports.ToolButton = _sfc_main$q;
8763
9025
  exports.V_GUIDE_LINE_STORAGE_KEY = V_GUIDE_LINE_STORAGE_KEY;
9026
+ exports.advancedTabConfig = advancedTabConfig;
8764
9027
  exports.beforePaste = beforePaste;
8765
9028
  exports.change2Fixed = change2Fixed;
8766
9029
  exports.codeBlockService = codeBlockService;
@@ -8768,10 +9031,12 @@
8768
9031
  exports.debug = debug;
8769
9032
  exports.default = index;
8770
9033
  exports.depService = depService;
9034
+ exports.displayTabConfig = displayTabConfig;
8771
9035
  exports.editorService = editorService;
8772
9036
  exports.error = error;
9037
+ exports.eventTabConfig = eventTabConfig;
8773
9038
  exports.eventsService = eventsService;
8774
- exports.fillConfig = fillConfig$1;
9039
+ exports.fillConfig = fillConfig;
8775
9040
  exports.fixNodeLeft = fixNodeLeft;
8776
9041
  exports.fixNodePosition = fixNodePosition;
8777
9042
  exports.generatePageName = generatePageName;
@@ -8795,6 +9060,7 @@
8795
9060
  exports.setConfig = setConfig;
8796
9061
  exports.setLayout = setLayout;
8797
9062
  exports.storageService = storageService;
9063
+ exports.styleTabConfig = styleTabConfig;
8798
9064
  exports.uiService = uiService;
8799
9065
  exports.useStage = useStage;
8800
9066
  exports.warn = warn;