@form-create/element-ui 3.1.3 → 3.1.4

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/element-ui v3.1.3
2
+ * @form-create/element-ui v3.1.4
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1536,8 +1536,6 @@
1536
1536
  for (var _i2 = 0; _i2 < len; _i2++) {
1537
1537
  this.removeRule(keys[total - _i2 - 1]);
1538
1538
  }
1539
-
1540
- this.subForm();
1541
1539
  }
1542
1540
 
1543
1541
  n.forEach(function (val, i) {
@@ -1545,8 +1543,7 @@
1545
1543
  });
1546
1544
  }
1547
1545
  },
1548
- deep: true,
1549
- flush: 'post'
1546
+ deep: true
1550
1547
  }
1551
1548
  },
1552
1549
  methods: {
@@ -1625,7 +1622,6 @@
1625
1622
  var _this4 = this;
1626
1623
 
1627
1624
  this.cacheRule[key].$f = $f;
1628
- this.subForm();
1629
1625
  this.formData(key, $f.formData());
1630
1626
  vue.nextTick(function () {
1631
1627
  if (_this4.syncDisabled) {
@@ -1635,15 +1631,8 @@
1635
1631
  _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
1636
1632
  });
1637
1633
  },
1638
- subForm: function subForm() {
1639
- var _this5 = this;
1640
-
1641
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
1642
- return _this5.cacheRule[k].$f;
1643
- }));
1644
- },
1645
1634
  removeRule: function removeRule(key, emit) {
1646
- var _this6 = this;
1635
+ var _this5 = this;
1647
1636
 
1648
1637
  var index = Object.keys(this.cacheRule).indexOf(key);
1649
1638
  delete this.cacheRule[key];
@@ -1651,7 +1640,7 @@
1651
1640
 
1652
1641
  if (emit) {
1653
1642
  vue.nextTick(function () {
1654
- return _this6.$emit('remove', index);
1643
+ return _this5.$emit('remove', index);
1655
1644
  });
1656
1645
  }
1657
1646
  },
@@ -1669,7 +1658,6 @@
1669
1658
  }
1670
1659
 
1671
1660
  this.removeRule(key, true);
1672
- this.subForm();
1673
1661
  this.modelValue.splice(index, 1);
1674
1662
  this.input(this.modelValue);
1675
1663
  },
@@ -1685,14 +1673,14 @@
1685
1673
  });
1686
1674
  },
1687
1675
  delIcon: function delIcon(index, key) {
1688
- var _this7 = this;
1676
+ var _this6 = this;
1689
1677
 
1690
1678
  return vue.createVNode(vue.resolveComponent("ElIcon"), {
1691
1679
  "key": "d".concat(key),
1692
1680
  "class": "el-icon-remove-outline",
1693
1681
  "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
1694
1682
  "onClick": function onClick() {
1695
- return _this7.del(index, key);
1683
+ return _this6.del(index, key);
1696
1684
  }
1697
1685
  }, {
1698
1686
  "default": function _default() {
@@ -1701,7 +1689,7 @@
1701
1689
  });
1702
1690
  },
1703
1691
  makeIcon: function makeIcon(total, index, key) {
1704
- var _this8 = this;
1692
+ var _this7 = this;
1705
1693
 
1706
1694
  if (this.$slots.button) {
1707
1695
  return this.$slots.button({
@@ -1710,7 +1698,7 @@
1710
1698
  vm: this,
1711
1699
  key: key,
1712
1700
  del: function del() {
1713
- return _this8.del(index, key);
1701
+ return _this7.del(index, key);
1714
1702
  },
1715
1703
  add: this.add
1716
1704
  });
@@ -1745,7 +1733,7 @@
1745
1733
  }
1746
1734
  },
1747
1735
  render: function render() {
1748
- var _this9 = this;
1736
+ var _this8 = this;
1749
1737
 
1750
1738
  var keys = Object.keys(this.cacheRule);
1751
1739
  var button = this.button;
@@ -1766,9 +1754,9 @@
1766
1754
  }, [keys.map(function (key, index) {
1767
1755
  var _slot;
1768
1756
 
1769
- var _this9$cacheRule$key = _this9.cacheRule[key],
1770
- rule = _this9$cacheRule$key.rule,
1771
- options = _this9$cacheRule$key.options;
1757
+ var _this8$cacheRule$key = _this8.cacheRule[key],
1758
+ rule = _this8$cacheRule$key.rule,
1759
+ options = _this8$cacheRule$key.options;
1772
1760
  return vue.createVNode(vue.resolveComponent("ElRow"), {
1773
1761
  "align": "middle",
1774
1762
  "type": "flex",
@@ -1784,19 +1772,20 @@
1784
1772
  "default": function _default() {
1785
1773
  return [vue.createVNode(Type, {
1786
1774
  "key": key,
1775
+ "inFor": true,
1787
1776
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
1788
- return _this9.formData(key, formData);
1777
+ return _this8.formData(key, formData);
1789
1778
  },
1790
- "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1779
+ "modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
1791
1780
  "onEmit-event": function onEmitEvent(name) {
1792
1781
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1793
1782
  args[_key - 1] = arguments[_key];
1794
1783
  }
1795
1784
 
1796
- return _this9.emitEvent(name, args, index, key);
1785
+ return _this8.emitEvent(name, args, index, key);
1797
1786
  },
1798
1787
  "onUpdate:api": function onUpdateApi($f) {
1799
- return _this9.add$f(index, key, $f);
1788
+ return _this8.add$f(index, key, $f);
1800
1789
  },
1801
1790
  "rule": rule,
1802
1791
  "option": options,
@@ -1809,7 +1798,7 @@
1809
1798
  "span": 2,
1810
1799
  "pull": 1,
1811
1800
  "push": 1
1812
- }, _isSlot(_slot = _this9.makeIcon(keys.length, index, key)) ? _slot : {
1801
+ }, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
1813
1802
  "default": function _default() {
1814
1803
  return [_slot];
1815
1804
  }
@@ -1886,7 +1875,6 @@
1886
1875
  var _this = this;
1887
1876
 
1888
1877
  this.subApi = api;
1889
- this.formCreateInject.subForm(api);
1890
1878
  vue.nextTick(function () {
1891
1879
  _this.syncDisabled && api.disabled(_this.disabled);
1892
1880
 
@@ -1933,6 +1921,21 @@
1933
1921
  var components = [Checkbox, Frame, Radio, Select, Tree, Upload, Group, Sub, script];
1934
1922
 
1935
1923
  var NAME$1 = 'FormCreate';
1924
+
1925
+ var getRuleInject = function getRuleInject(vm, parent) {
1926
+ if (vm === parent) {
1927
+ return;
1928
+ }
1929
+
1930
+ if (vm.ctx.formCreateInject) {
1931
+ return vm.ctx.formCreateInject;
1932
+ }
1933
+
1934
+ if (vm.parent) {
1935
+ return getRuleInject(vm.parent, parent);
1936
+ }
1937
+ };
1938
+
1936
1939
  function $FormCreate(FormCreate) {
1937
1940
  return vue.defineComponent({
1938
1941
  name: NAME$1,
@@ -1953,7 +1956,12 @@
1953
1956
  extendOption: Boolean,
1954
1957
  modelValue: Object,
1955
1958
  api: Object,
1956
- name: String
1959
+ name: String,
1960
+ subForm: {
1961
+ type: Boolean,
1962
+ "default": true
1963
+ },
1964
+ inFor: Boolean
1957
1965
  },
1958
1966
  emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1959
1967
  render: function render() {
@@ -1966,7 +1974,9 @@
1966
1974
 
1967
1975
  var _toRefs = vue.toRefs(props),
1968
1976
  rule = _toRefs.rule,
1969
- modelValue = _toRefs.modelValue;
1977
+ modelValue = _toRefs.modelValue,
1978
+ subForm = _toRefs.subForm,
1979
+ inFor = _toRefs.inFor;
1970
1980
 
1971
1981
  var data = vue.reactive({
1972
1982
  ctxInject: {},
@@ -1978,16 +1988,60 @@
1978
1988
  });
1979
1989
  var fc = new FormCreate(vm);
1980
1990
  var fapi = fc.api();
1991
+ var isMore = inFor.value;
1992
+
1993
+ var addSubForm = function addSubForm() {
1994
+ if (parent) {
1995
+ var _inject = getRuleInject(vm, parent);
1996
+
1997
+ if (_inject) {
1998
+ var sub;
1999
+
2000
+ if (isMore) {
2001
+ sub = toArray(_inject.getSubForm());
2002
+ sub.push(fapi);
2003
+ } else {
2004
+ sub = fapi;
2005
+ }
2006
+
2007
+ _inject.subForm(sub);
2008
+ }
2009
+ }
2010
+ };
2011
+
2012
+ var rmSubForm = function rmSubForm() {
2013
+ var inject = getRuleInject(vm, parent);
2014
+
2015
+ if (inject) {
2016
+ if (isMore) {
2017
+ var sub = toArray(inject.getSubForm());
2018
+ var idx = sub.indexOf(fapi);
2019
+
2020
+ if (idx > -1) {
2021
+ sub.splice(idx, 1);
2022
+ }
2023
+ } else {
2024
+ inject.subForm();
2025
+ }
2026
+ }
2027
+ };
2028
+
1981
2029
  vue.onMounted(function () {
1982
2030
  fc.mounted();
1983
2031
  });
1984
2032
  vue.onBeforeUnmount(function () {
2033
+ rmSubForm();
1985
2034
  data.destroyed = true;
1986
2035
  fc.unmount();
1987
2036
  });
1988
2037
  vue.onUpdated(function () {
1989
2038
  fc.updated();
1990
2039
  });
2040
+ vue.watch(subForm, function (n) {
2041
+ n ? addSubForm() : rmSubForm();
2042
+ }, {
2043
+ immediate: true
2044
+ });
1991
2045
  vue.watch(function () {
1992
2046
  return _toConsumableArray(rule.value);
1993
2047
  }, function (n) {
@@ -2002,8 +2056,8 @@
2002
2056
  fapi.refresh();
2003
2057
  });
2004
2058
  vue.watch(modelValue, function (n) {
2005
- if (JSON.stringify(n) === data.updateValue) return;
2006
- fapi.setValue(n);
2059
+ if (JSON.stringify(n || {}) === data.updateValue) return;
2060
+ fapi.setValue(n || {});
2007
2061
  }, {
2008
2062
  deep: true
2009
2063
  });
@@ -2720,6 +2774,25 @@
2720
2774
  return origin ? ctx.origin : ctx.rule;
2721
2775
  }
2722
2776
  },
2777
+ setEffect: function setEffect(id, attr, value) {
2778
+ var ctx = h.getCtx(id);
2779
+
2780
+ if (ctx && attr) {
2781
+ if (attr[0] === '$') {
2782
+ attr = attr.substr(1);
2783
+ }
2784
+
2785
+ if (hasProperty(ctx.rule, '$' + attr)) {
2786
+ $set(ctx.rule, '$' + attr, value);
2787
+ }
2788
+
2789
+ if (!hasProperty(ctx.rule, 'effect')) {
2790
+ ctx.rule.effect = {};
2791
+ }
2792
+
2793
+ $set(ctx.rule.effect, attr, value);
2794
+ }
2795
+ },
2723
2796
  updateValidate: function updateValidate(id, validate, merge) {
2724
2797
  if (merge) {
2725
2798
  api.mergeRule(id, {
@@ -3136,11 +3209,15 @@
3136
3209
  subForm: function subForm(_subForm) {
3137
3210
  _this6.$handle.addSubForm(ctx, _subForm);
3138
3211
  },
3212
+ getSubForm: function getSubForm() {
3213
+ return _this6.$handle.subForm[ctx.id];
3214
+ },
3139
3215
  options: [],
3140
3216
  children: [],
3141
3217
  preview: false,
3142
3218
  field: ctx.field,
3143
- rule: ctx.rule
3219
+ rule: ctx.rule,
3220
+ input: ctx.input
3144
3221
  };
3145
3222
  }
3146
3223
 
@@ -4238,9 +4315,7 @@
4238
4315
  delete this.appendData[rule.field];
4239
4316
  },
4240
4317
  addSubForm: function addSubForm(ctx, subForm) {
4241
- if (ctx.input) {
4242
- this.subForm[ctx.id] = subForm;
4243
- }
4318
+ this.subForm[ctx.id] = subForm;
4244
4319
  },
4245
4320
  deferSyncValue: function deferSyncValue(fn, sync) {
4246
4321
  if (!this.deferSyncFn) {
@@ -5052,44 +5127,6 @@
5052
5127
  }
5053
5128
  }
5054
5129
  };
5055
- var $required = {
5056
- name: 'required',
5057
- load: function load(inject, rule) {
5058
- var val = parseVa(inject.getValue());
5059
-
5060
- var validate = _objectSpread2(_objectSpread2({}, val), {}, {
5061
- required: true,
5062
- validator: function validator(_, v) {
5063
- return new Promise(function (resolve, reject) {
5064
- is.empty(v) ? reject(validate.message) : resolve();
5065
- });
5066
- }
5067
- });
5068
-
5069
- if (!validate.message) {
5070
- validate.message = rule.title + ' is required';
5071
- }
5072
-
5073
- inject.getProp().validate = [validate];
5074
- },
5075
- watch: function watch() {
5076
- $required.load.apply($required, arguments);
5077
- }
5078
- };
5079
-
5080
- function parseVa(val) {
5081
- if (is.Boolean(val)) {
5082
- return {};
5083
- } else if (is.String(val)) {
5084
- return {
5085
- message: val
5086
- };
5087
- } else if (!is.Object(val)) {
5088
- return {};
5089
- } else {
5090
- return val;
5091
- }
5092
- }
5093
5130
 
5094
5131
  function parseOpt(option) {
5095
5132
  if (is.String(option)) {
@@ -5161,8 +5198,7 @@
5161
5198
  }
5162
5199
 
5163
5200
  var $provider = {
5164
- fetch: $fetch,
5165
- required: $required
5201
+ fetch: $fetch
5166
5202
  };
5167
5203
 
5168
5204
  var name$6 = 'html';
@@ -5236,7 +5272,9 @@
5236
5272
  exportAttrs(config.attrs || {});
5237
5273
 
5238
5274
  function getApi(name) {
5239
- return instance[name];
5275
+ var val = instance[name];
5276
+ if (Array.isArray(val)) return _toConsumableArray(val);
5277
+ return val;
5240
5278
  }
5241
5279
 
5242
5280
  function useApp(fn) {
@@ -5371,6 +5409,7 @@
5371
5409
  modelFields: modelFields,
5372
5410
  rules: vm.props.rule,
5373
5411
  name: vm.props.name,
5412
+ inFor: vm.props.inFor,
5374
5413
  prop: {
5375
5414
  components: components,
5376
5415
  directives: directives
@@ -5397,7 +5436,12 @@
5397
5436
  this.$handle = new Handler(this);
5398
5437
 
5399
5438
  if (this.name) {
5400
- instance[this.name] = this.api();
5439
+ if (this.inFor) {
5440
+ if (!instance[this.name]) instance[this.name] = [];
5441
+ instance[this.name].push(this.api());
5442
+ } else {
5443
+ instance[this.name] = this.api();
5444
+ }
5401
5445
  }
5402
5446
  }
5403
5447
 
@@ -5465,7 +5509,12 @@
5465
5509
  },
5466
5510
  unmount: function unmount() {
5467
5511
  if (this.name) {
5468
- delete instance[this.name];
5512
+ if (this.inFor) {
5513
+ var idx = instance[this.name].indexOf(this.api());
5514
+ instance[this.name].splice(idx, 1);
5515
+ } else {
5516
+ delete instance[this.name];
5517
+ }
5469
5518
  }
5470
5519
 
5471
5520
  this.unwatch && this.unwatch();
@@ -6318,11 +6367,57 @@
6318
6367
  return api;
6319
6368
  }
6320
6369
 
6370
+ var required = {
6371
+ name: 'required',
6372
+ load: function load(inject, rule, api) {
6373
+ var val = parseVa(inject.getValue());
6374
+
6375
+ if (val.required === false) {
6376
+ inject.clearProp();
6377
+ } else {
6378
+ var validate = _objectSpread2(_objectSpread2({}, val), {}, {
6379
+ required: true,
6380
+ validator: function validator(_, v, call) {
6381
+ is.empty(v) ? call(validate.message) : call();
6382
+ }
6383
+ });
6384
+
6385
+ if (!validate.message) {
6386
+ validate.message = rule.title + ' is required';
6387
+ }
6388
+
6389
+ inject.getProp().validate = [validate];
6390
+ }
6391
+
6392
+ api.sync(rule);
6393
+ },
6394
+ watch: function watch() {
6395
+ required.load.apply(required, arguments);
6396
+ }
6397
+ };
6398
+
6399
+ function parseVa(val) {
6400
+ if (is.Boolean(val)) {
6401
+ return {
6402
+ required: val
6403
+ };
6404
+ } else if (is.String(val)) {
6405
+ return {
6406
+ message: val
6407
+ };
6408
+ } else if (!is.Object(val)) {
6409
+ return {};
6410
+ } else {
6411
+ return val;
6412
+ }
6413
+ }
6414
+
6321
6415
  function install(FormCreate) {
6322
6416
  FormCreate.componentAlias(alias);
6323
6417
  components.forEach(function (component) {
6324
6418
  FormCreate.component(component.name, component);
6325
6419
  });
6420
+ FormCreate.register(required);
6326
6421
  parsers.forEach(function (parser) {
6327
6422
  FormCreate.parser(parser);
6328
6423
  });
@@ -6340,7 +6435,7 @@
6340
6435
  function elmFormCreate() {
6341
6436
  return FormCreateFactory({
6342
6437
  ui: 'element-ui',
6343
- version: '3.1.3',
6438
+ version: '3.1.4',
6344
6439
  manager: manager,
6345
6440
  extendApi: extendApi,
6346
6441
  install: install,