@tmagic/form 1.4.7 → 1.4.8

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 (60) hide show
  1. package/dist/tmagic-form.js +54 -108
  2. package/dist/tmagic-form.umd.cjs +54 -108
  3. package/package.json +9 -5
  4. package/src/Form.vue +0 -201
  5. package/src/FormBox.vue +0 -120
  6. package/src/FormDialog.vue +0 -173
  7. package/src/FormDrawer.vue +0 -159
  8. package/src/containers/Col.vue +0 -52
  9. package/src/containers/Container.vue +0 -408
  10. package/src/containers/Fieldset.vue +0 -124
  11. package/src/containers/GroupList.vue +0 -139
  12. package/src/containers/GroupListItem.vue +0 -135
  13. package/src/containers/Panel.vue +0 -99
  14. package/src/containers/Row.vue +0 -54
  15. package/src/containers/Step.vue +0 -82
  16. package/src/containers/Table.vue +0 -648
  17. package/src/containers/Tabs.vue +0 -226
  18. package/src/fields/Cascader.vue +0 -131
  19. package/src/fields/Checkbox.vue +0 -58
  20. package/src/fields/CheckboxGroup.vue +0 -43
  21. package/src/fields/ColorPicker.vue +0 -30
  22. package/src/fields/Date.vue +0 -38
  23. package/src/fields/DateTime.vue +0 -47
  24. package/src/fields/Daterange.vue +0 -99
  25. package/src/fields/Display.vue +0 -21
  26. package/src/fields/DynamicField.vue +0 -90
  27. package/src/fields/Hidden.vue +0 -16
  28. package/src/fields/Link.vue +0 -86
  29. package/src/fields/Number.vue +0 -49
  30. package/src/fields/NumberRange.vue +0 -50
  31. package/src/fields/RadioGroup.vue +0 -28
  32. package/src/fields/Select.vue +0 -449
  33. package/src/fields/Switch.vue +0 -59
  34. package/src/fields/Text.vue +0 -170
  35. package/src/fields/Textarea.vue +0 -46
  36. package/src/fields/Time.vue +0 -34
  37. package/src/fields/Timerange.vue +0 -76
  38. package/src/index.ts +0 -139
  39. package/src/schema.ts +0 -757
  40. package/src/shims-vue.d.ts +0 -6
  41. package/src/theme/date-time.scss +0 -7
  42. package/src/theme/fieldset.scss +0 -28
  43. package/src/theme/form-box.scss +0 -13
  44. package/src/theme/form-dialog.scss +0 -13
  45. package/src/theme/form-drawer.scss +0 -11
  46. package/src/theme/form.scss +0 -43
  47. package/src/theme/group-list.scss +0 -23
  48. package/src/theme/index.scss +0 -14
  49. package/src/theme/link.scss +0 -3
  50. package/src/theme/number-range.scss +0 -8
  51. package/src/theme/panel.scss +0 -24
  52. package/src/theme/select.scss +0 -3
  53. package/src/theme/table.scss +0 -70
  54. package/src/theme/tabs.scss +0 -27
  55. package/src/theme/text.scss +0 -6
  56. package/src/utils/config.ts +0 -27
  57. package/src/utils/containerProps.ts +0 -50
  58. package/src/utils/form.ts +0 -268
  59. package/src/utils/useAddField.ts +0 -40
  60. package/tsconfig.build.json +0 -13
@@ -153,8 +153,7 @@ const getRules = function(mForm, rules = [], props) {
153
153
  });
154
154
  };
155
155
  const initValue = async (mForm, { initValues, config }) => {
156
- if (!Array.isArray(config))
157
- throw new Error("config应该为数组");
156
+ if (!Array.isArray(config)) throw new Error("config应该为数组");
158
157
  let valuesTmp = createValues(mForm, config, toRaw(initValues), {});
159
158
  const [firstForm] = config;
160
159
  if (firstForm && typeof firstForm.onInitValue === "function") {
@@ -208,8 +207,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
208
207
  const expand = ref(false);
209
208
  const name = computed(() => props.config.name || "");
210
209
  const showDiff = computed(() => {
211
- if (!props.isCompare)
212
- return false;
210
+ if (!props.isCompare) return false;
213
211
  const curValue = name.value ? props.model[name.value] : props.model;
214
212
  const lastValue = name.value ? props.lastValues[name.value] : props.lastValues;
215
213
  return !isEqual(curValue, lastValue);
@@ -236,10 +234,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
236
234
  const type = computed(() => {
237
235
  let { type: type2 } = props.config;
238
236
  type2 = type2 && filterFunction(mForm, type2, props);
239
- if (type2 === "form")
240
- return "";
241
- if (type2 === "container")
242
- return "";
237
+ if (type2 === "form") return "";
238
+ if (type2 === "container") return "";
243
239
  return type2?.replace(/([A-Z])/g, "-$1").toLowerCase() || (items.value ? "" : "text");
244
240
  });
245
241
  const display$1 = computed(() => {
@@ -256,10 +252,8 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
256
252
  watch(
257
253
  showDiff,
258
254
  (showDiff2) => {
259
- if (type.value === "hidden")
260
- return;
261
- if (items.value && !text.value && type.value && display$1.value)
262
- return;
255
+ if (type.value === "hidden") return;
256
+ if (items.value && !text.value && type.value && display$1.value) return;
263
257
  if (display$1.value && showDiff2 && type.value) {
264
258
  emit("addDiffCount");
265
259
  }
@@ -795,8 +789,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
795
789
  const changeOrder = (offset = 0) => emit("swap-item", props.index, props.index + offset);
796
790
  const movable = () => {
797
791
  const { movable: movable2 } = props.config;
798
- if (movable2 === void 0)
799
- return true;
792
+ if (movable2 === void 0) return true;
800
793
  if (typeof movable2 === "function") {
801
794
  return movable2(mForm, props.index || 0, props.model, props.groupModel);
802
795
  }
@@ -927,8 +920,7 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
927
920
  const emit = __emit;
928
921
  const mForm = inject("mForm");
929
922
  const addable = computed(() => {
930
- if (!props.name)
931
- return false;
923
+ if (!props.name) return false;
932
924
  if (typeof props.config.addable === "function") {
933
925
  return props.config.addable(mForm, {
934
926
  model: props.model[props.name],
@@ -940,13 +932,11 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
940
932
  return typeof props.config.addable === "undefined" ? true : props.config.addable;
941
933
  });
942
934
  const changeHandler = () => {
943
- if (!props.name)
944
- return false;
935
+ if (!props.name) return false;
945
936
  emit("change", props.model[props.name]);
946
937
  };
947
938
  const addHandler = async () => {
948
- if (!props.name)
949
- return false;
939
+ if (!props.name) return false;
950
940
  let initValues = {};
951
941
  if (typeof props.config.defaultAdd === "function") {
952
942
  initValues = await props.config.defaultAdd(mForm, {
@@ -965,14 +955,12 @@ const _sfc_main$u = /* @__PURE__ */ defineComponent({
965
955
  props.model[props.name].push(groupValue);
966
956
  };
967
957
  const removeHandler = (index) => {
968
- if (!props.name)
969
- return false;
958
+ if (!props.name) return false;
970
959
  props.model[props.name].splice(index, 1);
971
960
  changeHandler();
972
961
  };
973
962
  const swapHandler = (idx1, idx2) => {
974
- if (!props.name)
975
- return false;
963
+ if (!props.name) return false;
976
964
  const [currRow] = props.model[props.name].splice(idx1, 1);
977
965
  props.model[props.name].splice(idx2, 0, currRow);
978
966
  changeHandler();
@@ -1409,10 +1397,8 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1409
1397
  if (tBodyEl) {
1410
1398
  const sortable = Sortable.create(tBodyEl, {
1411
1399
  onEnd: ({ newIndex, oldIndex }) => {
1412
- if (typeof newIndex === "undefined")
1413
- return;
1414
- if (typeof oldIndex === "undefined")
1415
- return;
1400
+ if (typeof newIndex === "undefined") return;
1401
+ if (typeof oldIndex === "undefined") return;
1416
1402
  swapArray(newIndex, oldIndex);
1417
1403
  emit("change", props.model[modelName.value]);
1418
1404
  foreUpdate();
@@ -1442,8 +1428,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1442
1428
  formValue: mForm?.values,
1443
1429
  prop: props.prop
1444
1430
  });
1445
- if (!beforeCheckRes)
1446
- return;
1431
+ if (!beforeCheckRes) return;
1447
1432
  }
1448
1433
  const columns = props.config.items;
1449
1434
  const enumValues = props.config.enum || [];
@@ -1548,8 +1533,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1548
1533
  return fuc;
1549
1534
  };
1550
1535
  const removeHandler = (index) => {
1551
- if (props.disabled)
1552
- return;
1536
+ if (props.disabled) return;
1553
1537
  props.model[modelName.value].splice(index, 1);
1554
1538
  emit("change", props.model[modelName.value]);
1555
1539
  };
@@ -1656,8 +1640,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1656
1640
  };
1657
1641
  const toggleMode = () => {
1658
1642
  const calcLabelWidth = (label) => {
1659
- if (!label)
1660
- return "0px";
1643
+ if (!label) return "0px";
1661
1644
  const zhLength = label.match(/[^\x00-\xff]/g)?.length || 0;
1662
1645
  const chLength = label.length - zhLength;
1663
1646
  return `${Math.max(chLength * 8 + zhLength * 20, 80)}px`;
@@ -1677,8 +1660,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
1677
1660
  });
1678
1661
  };
1679
1662
  const toggleFullscreen = () => {
1680
- if (!mTable.value)
1681
- return;
1663
+ if (!mTable.value) return;
1682
1664
  if (isFullscreen.value) {
1683
1665
  mTable.value.classList.remove("fixed");
1684
1666
  isFullscreen.value = false;
@@ -1993,12 +1975,9 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
1993
1975
  const getActive = (mForm2, props2, activeTabName2) => {
1994
1976
  const { config, model, prop } = props2;
1995
1977
  const { active } = config;
1996
- if (typeof active === "function")
1997
- return active(mForm2, { model, formValue: mForm2?.values, prop });
1998
- if (+activeTabName2 >= props2.config.items.length)
1999
- return "0";
2000
- if (typeof active !== "undefined")
2001
- return active;
1978
+ if (typeof active === "function") return active(mForm2, { model, formValue: mForm2?.values, prop });
1979
+ if (+activeTabName2 >= props2.config.items.length) return "0";
1980
+ if (typeof active !== "undefined") return active;
2002
1981
  return "0";
2003
1982
  };
2004
1983
  const tabClick = (mForm2, tab, props2) => {
@@ -2019,8 +1998,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2019
1998
  const diffCount = ref({});
2020
1999
  const tabs = computed(() => {
2021
2000
  if (props.config.dynamic) {
2022
- if (!props.config.name)
2023
- throw new Error("dynamic tab 必须配置name");
2001
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2024
2002
  return props.model[props.config.name] || [];
2025
2003
  }
2026
2004
  return props.config.items.filter((item) => display(mForm, item.display, props));
@@ -2037,8 +2015,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2037
2015
  const tabItems = (tab) => props.config.dynamic ? props.config.items : tab.items;
2038
2016
  const tabClickHandler = (tab) => tabClick(mForm, tab, props);
2039
2017
  const onTabAdd = () => {
2040
- if (!props.config.name)
2041
- throw new Error("dynamic tab 必须配置name");
2018
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2042
2019
  if (typeof props.config.onTabAdd === "function") {
2043
2020
  props.config.onTabAdd(mForm, {
2044
2021
  model: props.model,
@@ -2054,8 +2031,7 @@ const _sfc_main$o = /* @__PURE__ */ defineComponent({
2054
2031
  mForm?.$emit("field-change", props.prop, props.model[props.config.name]);
2055
2032
  };
2056
2033
  const onTabRemove = (tabName) => {
2057
- if (!props.config.name)
2058
- throw new Error("dynamic tab 必须配置name");
2034
+ if (!props.config.name) throw new Error("dynamic tab 必须配置name");
2059
2035
  if (typeof props.config.onTabRemove === "function") {
2060
2036
  props.config.onTabRemove(mForm, tabName, {
2061
2037
  model: props.model,
@@ -2158,8 +2134,7 @@ const setConfig = (option) => {
2158
2134
  const getConfig = (key) => $MAGIC_FORM[key];
2159
2135
 
2160
2136
  const useAddField = (prop) => {
2161
- if (!prop)
2162
- return;
2137
+ if (!prop) return;
2163
2138
  const mForm = inject("mForm");
2164
2139
  const instance = getCurrentInstance();
2165
2140
  watch(
@@ -2223,8 +2198,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2223
2198
  const setRemoteOptions = async function() {
2224
2199
  const { config } = props;
2225
2200
  const { option } = config;
2226
- if (!option)
2227
- return;
2201
+ if (!option) return;
2228
2202
  let { body } = option;
2229
2203
  const postOptions = {
2230
2204
  url: option.url,
@@ -2269,8 +2243,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
2269
2243
  });
2270
2244
  }
2271
2245
  const changeHandler = () => {
2272
- if (!tMagicCascader.value)
2273
- return;
2246
+ if (!tMagicCascader.value) return;
2274
2247
  tMagicCascader.value.setQuery("");
2275
2248
  tMagicCascader.value.setPreviousQuery(null);
2276
2249
  emit("change", props.model[props.name]);
@@ -2392,10 +2365,8 @@ const _sfc_main$l = /* @__PURE__ */ defineComponent({
2392
2365
  };
2393
2366
  const mForm = inject("mForm");
2394
2367
  const options = computed(() => {
2395
- if (Array.isArray(props.config.options))
2396
- return props.config.options;
2397
- if (typeof props.config.options === "function")
2398
- return filterFunction(mForm, props.config.options, props);
2368
+ if (Array.isArray(props.config.options)) return props.config.options;
2369
+ if (typeof props.config.options === "function") return filterFunction(mForm, props.config.options, props);
2399
2370
  return [];
2400
2371
  });
2401
2372
  return (_ctx, _cache) => {
@@ -2533,12 +2504,9 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2533
2504
  if (!value.value) {
2534
2505
  value.value = [];
2535
2506
  }
2536
- if (!start || !end)
2537
- value.value = [];
2538
- if (start !== preStart)
2539
- value.value[0] = new Date(start);
2540
- if (end !== preEnd)
2541
- value.value[1] = new Date(end);
2507
+ if (!start || !end) value.value = [];
2508
+ if (start !== preStart) value.value[0] = new Date(start);
2509
+ if (end !== preEnd) value.value[1] = new Date(end);
2542
2510
  },
2543
2511
  {
2544
2512
  immediate: true
@@ -2548,8 +2516,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2548
2516
  watch(
2549
2517
  () => props.model[props.name],
2550
2518
  (start, preStart) => {
2551
- if (start !== preStart)
2552
- value.value = start.map((item) => item ? new Date(item) : void 0);
2519
+ if (start !== preStart) value.value = start.map((item) => item ? new Date(item) : void 0);
2553
2520
  },
2554
2521
  {
2555
2522
  immediate: true
@@ -2575,8 +2542,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
2575
2542
  emit(
2576
2543
  "change",
2577
2544
  value2.map((item) => {
2578
- if (item)
2579
- return datetimeFormatter(item, "");
2545
+ if (item) return datetimeFormatter(item, "");
2580
2546
  return void 0;
2581
2547
  })
2582
2548
  );
@@ -2714,14 +2680,12 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
2714
2680
  value: {}
2715
2681
  });
2716
2682
  const changeFieldMap = async () => {
2717
- if (typeof props.config.returnFields !== "function" || !props.model)
2718
- return;
2683
+ if (typeof props.config.returnFields !== "function" || !props.model) return;
2719
2684
  const fields = await props.config.returnFields(props.config, props.model, request);
2720
2685
  fieldMap.value = {};
2721
2686
  fieldLabelMap.value = {};
2722
2687
  fields.forEach((v) => {
2723
- if (typeof v !== "object" || v.name === void 0)
2724
- return;
2688
+ if (typeof v !== "object" || v.name === void 0) return;
2725
2689
  let oldVal = props.model?.[v.name] || "";
2726
2690
  if (!oldVal && v.defaultValue !== void 0) {
2727
2691
  oldVal = v.defaultValue;
@@ -2925,12 +2889,9 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
2925
2889
  const error = [];
2926
2890
  Object.entries(invalidFields).forEach(([, ValidateError]) => {
2927
2891
  ValidateError.forEach(({ field, message }) => {
2928
- if (field && message)
2929
- error.push(`${field} -> ${message}`);
2930
- if (field && !message)
2931
- error.push(`${field} -> 出现错误`);
2932
- if (!field && message)
2933
- error.push(`${message}`);
2892
+ if (field && message) error.push(`${field} -> ${message}`);
2893
+ if (field && !message) error.push(`${field} -> 出现错误`);
2894
+ if (!field && message) error.push(`${message}`);
2934
2895
  });
2935
2896
  });
2936
2897
  throw new Error(error.join("<br>"));
@@ -3453,8 +3414,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3453
3414
  const emit = __emit;
3454
3415
  const optionComponent = getConfig$1("components")?.option;
3455
3416
  const optionGroupComponent = getConfig$1("components")?.optionGroup;
3456
- if (!props.model)
3457
- throw new Error("不能没有model");
3417
+ if (!props.model) throw new Error("不能没有model");
3458
3418
  useAddField(props.prop);
3459
3419
  const tMagicSelect = ref();
3460
3420
  const mForm = inject("mForm");
@@ -3489,16 +3449,14 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3489
3449
  }));
3490
3450
  };
3491
3451
  const getOptions = async () => {
3492
- if (!props.model)
3493
- return [];
3452
+ if (!props.model) return [];
3494
3453
  if (localOptions.value.length) {
3495
3454
  return localOptions.value;
3496
3455
  }
3497
3456
  loading.value = true;
3498
3457
  let items = [];
3499
3458
  const { option } = props.config;
3500
- if (!option)
3501
- return [];
3459
+ if (!option) return [];
3502
3460
  const { root = "", totalKey = "total" } = option;
3503
3461
  let { body = {}, url } = option;
3504
3462
  if (typeof url === "function") {
@@ -3571,8 +3529,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3571
3529
  return pgIndex.value === 0 ? selectedOptions.concat(items) : options.value.concat(items);
3572
3530
  };
3573
3531
  const getInitLocalOption = async () => {
3574
- if (!props.model)
3575
- return [];
3532
+ if (!props.model) return [];
3576
3533
  const value = props.model[props.name];
3577
3534
  const { config } = props;
3578
3535
  localOptions.value = await getOptions();
@@ -3593,11 +3550,9 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3593
3550
  return localOptions.value.filter((item) => equalValue(item.value, value));
3594
3551
  };
3595
3552
  const getInitOption = async () => {
3596
- if (!props.model)
3597
- return [];
3553
+ if (!props.model) return [];
3598
3554
  const { option } = props.config;
3599
- if (!option)
3600
- return [];
3555
+ if (!option) return [];
3601
3556
  const { root = "", initRoot = "" } = option;
3602
3557
  let { initBody = {} } = option;
3603
3558
  let options2 = [];
@@ -3680,8 +3635,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3680
3635
  });
3681
3636
  } else if (props.config.option) {
3682
3637
  onBeforeMount(() => {
3683
- if (!props.model)
3684
- return;
3638
+ if (!props.model) return;
3685
3639
  const v = props.model[props.name];
3686
3640
  if (Array.isArray(v) ? v.length : typeof v !== "undefined") {
3687
3641
  getInitOption().then((data) => {
@@ -3725,10 +3679,8 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
3725
3679
  emit("change", value);
3726
3680
  };
3727
3681
  const visibleHandler = async (visible) => {
3728
- if (!visible)
3729
- return;
3730
- if (!props.config.remote)
3731
- return;
3682
+ if (!visible) return;
3683
+ if (!props.config.remote) return;
3732
3684
  if (query.value && tMagicSelect.value) {
3733
3685
  tMagicSelect.value.setQuery(query.value);
3734
3686
  tMagicSelect.value.setPreviousQuery(query.value);
@@ -3955,8 +3907,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3955
3907
  mForm?.$emit("field-input", props.prop, v);
3956
3908
  };
3957
3909
  const buttonClickHandler = () => {
3958
- if (!appendConfig.value)
3959
- return;
3910
+ if (!appendConfig.value) return;
3960
3911
  if (typeof appendConfig.value.handler === "function") {
3961
3912
  appendConfig.value.handler(mForm, {
3962
3913
  model: props.model,
@@ -3965,10 +3916,8 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
3965
3916
  }
3966
3917
  };
3967
3918
  const keyUpHandler = ($event) => {
3968
- if (!props.model)
3969
- return;
3970
- if (!props.name)
3971
- return;
3919
+ if (!props.model) return;
3920
+ if (!props.name) return;
3972
3921
  const arrowUp = $event.key === "ArrowUp";
3973
3922
  const arrowDown = $event.key === "ArrowDown";
3974
3923
  if (!arrowUp && !arrowDown) {
@@ -4198,12 +4147,9 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
4198
4147
  if (!value.value) {
4199
4148
  value.value = [];
4200
4149
  }
4201
- if (!start || !end)
4202
- value.value = [];
4203
- if (start !== preStart)
4204
- value.value[0] = start;
4205
- if (end !== preEnd)
4206
- value.value[1] = end;
4150
+ if (!start || !end) value.value = [];
4151
+ if (start !== preStart) value.value[0] = start;
4152
+ if (end !== preEnd) value.value[1] = end;
4207
4153
  },
4208
4154
  {
4209
4155
  immediate: true