@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.
@@ -1532,8 +1532,6 @@ var Group = defineComponent({
1532
1532
  for (var _i2 = 0; _i2 < len; _i2++) {
1533
1533
  this.removeRule(keys[total - _i2 - 1]);
1534
1534
  }
1535
-
1536
- this.subForm();
1537
1535
  }
1538
1536
 
1539
1537
  n.forEach(function (val, i) {
@@ -1541,8 +1539,7 @@ var Group = defineComponent({
1541
1539
  });
1542
1540
  }
1543
1541
  },
1544
- deep: true,
1545
- flush: 'post'
1542
+ deep: true
1546
1543
  }
1547
1544
  },
1548
1545
  methods: {
@@ -1621,7 +1618,6 @@ var Group = defineComponent({
1621
1618
  var _this4 = this;
1622
1619
 
1623
1620
  this.cacheRule[key].$f = $f;
1624
- this.subForm();
1625
1621
  this.formData(key, $f.formData());
1626
1622
  nextTick(function () {
1627
1623
  if (_this4.syncDisabled) {
@@ -1631,15 +1627,8 @@ var Group = defineComponent({
1631
1627
  _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
1632
1628
  });
1633
1629
  },
1634
- subForm: function subForm() {
1635
- var _this5 = this;
1636
-
1637
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
1638
- return _this5.cacheRule[k].$f;
1639
- }));
1640
- },
1641
1630
  removeRule: function removeRule(key, emit) {
1642
- var _this6 = this;
1631
+ var _this5 = this;
1643
1632
 
1644
1633
  var index = Object.keys(this.cacheRule).indexOf(key);
1645
1634
  delete this.cacheRule[key];
@@ -1647,7 +1636,7 @@ var Group = defineComponent({
1647
1636
 
1648
1637
  if (emit) {
1649
1638
  nextTick(function () {
1650
- return _this6.$emit('remove', index);
1639
+ return _this5.$emit('remove', index);
1651
1640
  });
1652
1641
  }
1653
1642
  },
@@ -1665,7 +1654,6 @@ var Group = defineComponent({
1665
1654
  }
1666
1655
 
1667
1656
  this.removeRule(key, true);
1668
- this.subForm();
1669
1657
  this.modelValue.splice(index, 1);
1670
1658
  this.input(this.modelValue);
1671
1659
  },
@@ -1681,14 +1669,14 @@ var Group = defineComponent({
1681
1669
  });
1682
1670
  },
1683
1671
  delIcon: function delIcon(index, key) {
1684
- var _this7 = this;
1672
+ var _this6 = this;
1685
1673
 
1686
1674
  return createVNode(resolveComponent("ElIcon"), {
1687
1675
  "key": "d".concat(key),
1688
1676
  "class": "el-icon-remove-outline",
1689
1677
  "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
1690
1678
  "onClick": function onClick() {
1691
- return _this7.del(index, key);
1679
+ return _this6.del(index, key);
1692
1680
  }
1693
1681
  }, {
1694
1682
  "default": function _default() {
@@ -1697,7 +1685,7 @@ var Group = defineComponent({
1697
1685
  });
1698
1686
  },
1699
1687
  makeIcon: function makeIcon(total, index, key) {
1700
- var _this8 = this;
1688
+ var _this7 = this;
1701
1689
 
1702
1690
  if (this.$slots.button) {
1703
1691
  return this.$slots.button({
@@ -1706,7 +1694,7 @@ var Group = defineComponent({
1706
1694
  vm: this,
1707
1695
  key: key,
1708
1696
  del: function del() {
1709
- return _this8.del(index, key);
1697
+ return _this7.del(index, key);
1710
1698
  },
1711
1699
  add: this.add
1712
1700
  });
@@ -1741,7 +1729,7 @@ var Group = defineComponent({
1741
1729
  }
1742
1730
  },
1743
1731
  render: function render() {
1744
- var _this9 = this;
1732
+ var _this8 = this;
1745
1733
 
1746
1734
  var keys = Object.keys(this.cacheRule);
1747
1735
  var button = this.button;
@@ -1762,9 +1750,9 @@ var Group = defineComponent({
1762
1750
  }, [keys.map(function (key, index) {
1763
1751
  var _slot;
1764
1752
 
1765
- var _this9$cacheRule$key = _this9.cacheRule[key],
1766
- rule = _this9$cacheRule$key.rule,
1767
- options = _this9$cacheRule$key.options;
1753
+ var _this8$cacheRule$key = _this8.cacheRule[key],
1754
+ rule = _this8$cacheRule$key.rule,
1755
+ options = _this8$cacheRule$key.options;
1768
1756
  return createVNode(resolveComponent("ElRow"), {
1769
1757
  "align": "middle",
1770
1758
  "type": "flex",
@@ -1780,19 +1768,20 @@ var Group = defineComponent({
1780
1768
  "default": function _default() {
1781
1769
  return [createVNode(Type, {
1782
1770
  "key": key,
1771
+ "inFor": true,
1783
1772
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
1784
- return _this9.formData(key, formData);
1773
+ return _this8.formData(key, formData);
1785
1774
  },
1786
- "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1775
+ "modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
1787
1776
  "onEmit-event": function onEmitEvent(name) {
1788
1777
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1789
1778
  args[_key - 1] = arguments[_key];
1790
1779
  }
1791
1780
 
1792
- return _this9.emitEvent(name, args, index, key);
1781
+ return _this8.emitEvent(name, args, index, key);
1793
1782
  },
1794
1783
  "onUpdate:api": function onUpdateApi($f) {
1795
- return _this9.add$f(index, key, $f);
1784
+ return _this8.add$f(index, key, $f);
1796
1785
  },
1797
1786
  "rule": rule,
1798
1787
  "option": options,
@@ -1805,7 +1794,7 @@ var Group = defineComponent({
1805
1794
  "span": 2,
1806
1795
  "pull": 1,
1807
1796
  "push": 1
1808
- }, _isSlot(_slot = _this9.makeIcon(keys.length, index, key)) ? _slot : {
1797
+ }, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
1809
1798
  "default": function _default() {
1810
1799
  return [_slot];
1811
1800
  }
@@ -1882,7 +1871,6 @@ var Sub = defineComponent({
1882
1871
  var _this = this;
1883
1872
 
1884
1873
  this.subApi = api;
1885
- this.formCreateInject.subForm(api);
1886
1874
  nextTick(function () {
1887
1875
  _this.syncDisabled && api.disabled(_this.disabled);
1888
1876
 
@@ -1929,6 +1917,21 @@ script.render = render;
1929
1917
  var components = [Checkbox, Frame, Radio, Select, Tree, Upload, Group, Sub, script];
1930
1918
 
1931
1919
  var NAME$1 = 'FormCreate';
1920
+
1921
+ var getRuleInject = function getRuleInject(vm, parent) {
1922
+ if (vm === parent) {
1923
+ return;
1924
+ }
1925
+
1926
+ if (vm.ctx.formCreateInject) {
1927
+ return vm.ctx.formCreateInject;
1928
+ }
1929
+
1930
+ if (vm.parent) {
1931
+ return getRuleInject(vm.parent, parent);
1932
+ }
1933
+ };
1934
+
1932
1935
  function $FormCreate(FormCreate) {
1933
1936
  return defineComponent({
1934
1937
  name: NAME$1,
@@ -1949,7 +1952,12 @@ function $FormCreate(FormCreate) {
1949
1952
  extendOption: Boolean,
1950
1953
  modelValue: Object,
1951
1954
  api: Object,
1952
- name: String
1955
+ name: String,
1956
+ subForm: {
1957
+ type: Boolean,
1958
+ "default": true
1959
+ },
1960
+ inFor: Boolean
1953
1961
  },
1954
1962
  emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1955
1963
  render: function render() {
@@ -1962,7 +1970,9 @@ function $FormCreate(FormCreate) {
1962
1970
 
1963
1971
  var _toRefs = toRefs(props),
1964
1972
  rule = _toRefs.rule,
1965
- modelValue = _toRefs.modelValue;
1973
+ modelValue = _toRefs.modelValue,
1974
+ subForm = _toRefs.subForm,
1975
+ inFor = _toRefs.inFor;
1966
1976
 
1967
1977
  var data = reactive({
1968
1978
  ctxInject: {},
@@ -1974,16 +1984,60 @@ function $FormCreate(FormCreate) {
1974
1984
  });
1975
1985
  var fc = new FormCreate(vm);
1976
1986
  var fapi = fc.api();
1987
+ var isMore = inFor.value;
1988
+
1989
+ var addSubForm = function addSubForm() {
1990
+ if (parent) {
1991
+ var _inject = getRuleInject(vm, parent);
1992
+
1993
+ if (_inject) {
1994
+ var sub;
1995
+
1996
+ if (isMore) {
1997
+ sub = toArray(_inject.getSubForm());
1998
+ sub.push(fapi);
1999
+ } else {
2000
+ sub = fapi;
2001
+ }
2002
+
2003
+ _inject.subForm(sub);
2004
+ }
2005
+ }
2006
+ };
2007
+
2008
+ var rmSubForm = function rmSubForm() {
2009
+ var inject = getRuleInject(vm, parent);
2010
+
2011
+ if (inject) {
2012
+ if (isMore) {
2013
+ var sub = toArray(inject.getSubForm());
2014
+ var idx = sub.indexOf(fapi);
2015
+
2016
+ if (idx > -1) {
2017
+ sub.splice(idx, 1);
2018
+ }
2019
+ } else {
2020
+ inject.subForm();
2021
+ }
2022
+ }
2023
+ };
2024
+
1977
2025
  onMounted(function () {
1978
2026
  fc.mounted();
1979
2027
  });
1980
2028
  onBeforeUnmount(function () {
2029
+ rmSubForm();
1981
2030
  data.destroyed = true;
1982
2031
  fc.unmount();
1983
2032
  });
1984
2033
  onUpdated(function () {
1985
2034
  fc.updated();
1986
2035
  });
2036
+ watch(subForm, function (n) {
2037
+ n ? addSubForm() : rmSubForm();
2038
+ }, {
2039
+ immediate: true
2040
+ });
1987
2041
  watch(function () {
1988
2042
  return _toConsumableArray(rule.value);
1989
2043
  }, function (n) {
@@ -1998,8 +2052,8 @@ function $FormCreate(FormCreate) {
1998
2052
  fapi.refresh();
1999
2053
  });
2000
2054
  watch(modelValue, function (n) {
2001
- if (JSON.stringify(n) === data.updateValue) return;
2002
- fapi.setValue(n);
2055
+ if (JSON.stringify(n || {}) === data.updateValue) return;
2056
+ fapi.setValue(n || {});
2003
2057
  }, {
2004
2058
  deep: true
2005
2059
  });
@@ -2716,6 +2770,25 @@ function Api(h) {
2716
2770
  return origin ? ctx.origin : ctx.rule;
2717
2771
  }
2718
2772
  },
2773
+ setEffect: function setEffect(id, attr, value) {
2774
+ var ctx = h.getCtx(id);
2775
+
2776
+ if (ctx && attr) {
2777
+ if (attr[0] === '$') {
2778
+ attr = attr.substr(1);
2779
+ }
2780
+
2781
+ if (hasProperty(ctx.rule, '$' + attr)) {
2782
+ $set(ctx.rule, '$' + attr, value);
2783
+ }
2784
+
2785
+ if (!hasProperty(ctx.rule, 'effect')) {
2786
+ ctx.rule.effect = {};
2787
+ }
2788
+
2789
+ $set(ctx.rule.effect, attr, value);
2790
+ }
2791
+ },
2719
2792
  updateValidate: function updateValidate(id, validate, merge) {
2720
2793
  if (merge) {
2721
2794
  api.mergeRule(id, {
@@ -3132,11 +3205,15 @@ function useRender$1(Render) {
3132
3205
  subForm: function subForm(_subForm) {
3133
3206
  _this6.$handle.addSubForm(ctx, _subForm);
3134
3207
  },
3208
+ getSubForm: function getSubForm() {
3209
+ return _this6.$handle.subForm[ctx.id];
3210
+ },
3135
3211
  options: [],
3136
3212
  children: [],
3137
3213
  preview: false,
3138
3214
  field: ctx.field,
3139
- rule: ctx.rule
3215
+ rule: ctx.rule,
3216
+ input: ctx.input
3140
3217
  };
3141
3218
  }
3142
3219
 
@@ -4234,9 +4311,7 @@ function useInput(Handler) {
4234
4311
  delete this.appendData[rule.field];
4235
4312
  },
4236
4313
  addSubForm: function addSubForm(ctx, subForm) {
4237
- if (ctx.input) {
4238
- this.subForm[ctx.id] = subForm;
4239
- }
4314
+ this.subForm[ctx.id] = subForm;
4240
4315
  },
4241
4316
  deferSyncValue: function deferSyncValue(fn, sync) {
4242
4317
  if (!this.deferSyncFn) {
@@ -5048,44 +5123,6 @@ var $fetch = {
5048
5123
  }
5049
5124
  }
5050
5125
  };
5051
- var $required = {
5052
- name: 'required',
5053
- load: function load(inject, rule) {
5054
- var val = parseVa(inject.getValue());
5055
-
5056
- var validate = _objectSpread2(_objectSpread2({}, val), {}, {
5057
- required: true,
5058
- validator: function validator(_, v) {
5059
- return new Promise(function (resolve, reject) {
5060
- is.empty(v) ? reject(validate.message) : resolve();
5061
- });
5062
- }
5063
- });
5064
-
5065
- if (!validate.message) {
5066
- validate.message = rule.title + ' is required';
5067
- }
5068
-
5069
- inject.getProp().validate = [validate];
5070
- },
5071
- watch: function watch() {
5072
- $required.load.apply($required, arguments);
5073
- }
5074
- };
5075
-
5076
- function parseVa(val) {
5077
- if (is.Boolean(val)) {
5078
- return {};
5079
- } else if (is.String(val)) {
5080
- return {
5081
- message: val
5082
- };
5083
- } else if (!is.Object(val)) {
5084
- return {};
5085
- } else {
5086
- return val;
5087
- }
5088
- }
5089
5126
 
5090
5127
  function parseOpt(option) {
5091
5128
  if (is.String(option)) {
@@ -5157,8 +5194,7 @@ function run(inject, rule, api) {
5157
5194
  }
5158
5195
 
5159
5196
  var $provider = {
5160
- fetch: $fetch,
5161
- required: $required
5197
+ fetch: $fetch
5162
5198
  };
5163
5199
 
5164
5200
  var name$6 = 'html';
@@ -5232,7 +5268,9 @@ function FormCreateFactory(config) {
5232
5268
  exportAttrs(config.attrs || {});
5233
5269
 
5234
5270
  function getApi(name) {
5235
- return instance[name];
5271
+ var val = instance[name];
5272
+ if (Array.isArray(val)) return _toConsumableArray(val);
5273
+ return val;
5236
5274
  }
5237
5275
 
5238
5276
  function useApp(fn) {
@@ -5367,6 +5405,7 @@ function FormCreateFactory(config) {
5367
5405
  modelFields: modelFields,
5368
5406
  rules: vm.props.rule,
5369
5407
  name: vm.props.name,
5408
+ inFor: vm.props.inFor,
5370
5409
  prop: {
5371
5410
  components: components,
5372
5411
  directives: directives
@@ -5393,7 +5432,12 @@ function FormCreateFactory(config) {
5393
5432
  this.$handle = new Handler(this);
5394
5433
 
5395
5434
  if (this.name) {
5396
- instance[this.name] = this.api();
5435
+ if (this.inFor) {
5436
+ if (!instance[this.name]) instance[this.name] = [];
5437
+ instance[this.name].push(this.api());
5438
+ } else {
5439
+ instance[this.name] = this.api();
5440
+ }
5397
5441
  }
5398
5442
  }
5399
5443
 
@@ -5461,7 +5505,12 @@ function FormCreateFactory(config) {
5461
5505
  },
5462
5506
  unmount: function unmount() {
5463
5507
  if (this.name) {
5464
- delete instance[this.name];
5508
+ if (this.inFor) {
5509
+ var idx = instance[this.name].indexOf(this.api());
5510
+ instance[this.name].splice(idx, 1);
5511
+ } else {
5512
+ delete instance[this.name];
5513
+ }
5465
5514
  }
5466
5515
 
5467
5516
  this.unwatch && this.unwatch();
@@ -6314,11 +6363,57 @@ function extendApi(api, h) {
6314
6363
  return api;
6315
6364
  }
6316
6365
 
6366
+ var required = {
6367
+ name: 'required',
6368
+ load: function load(inject, rule, api) {
6369
+ var val = parseVa(inject.getValue());
6370
+
6371
+ if (val.required === false) {
6372
+ inject.clearProp();
6373
+ } else {
6374
+ var validate = _objectSpread2(_objectSpread2({}, val), {}, {
6375
+ required: true,
6376
+ validator: function validator(_, v, call) {
6377
+ is.empty(v) ? call(validate.message) : call();
6378
+ }
6379
+ });
6380
+
6381
+ if (!validate.message) {
6382
+ validate.message = rule.title + ' is required';
6383
+ }
6384
+
6385
+ inject.getProp().validate = [validate];
6386
+ }
6387
+
6388
+ api.sync(rule);
6389
+ },
6390
+ watch: function watch() {
6391
+ required.load.apply(required, arguments);
6392
+ }
6393
+ };
6394
+
6395
+ function parseVa(val) {
6396
+ if (is.Boolean(val)) {
6397
+ return {
6398
+ required: val
6399
+ };
6400
+ } else if (is.String(val)) {
6401
+ return {
6402
+ message: val
6403
+ };
6404
+ } else if (!is.Object(val)) {
6405
+ return {};
6406
+ } else {
6407
+ return val;
6408
+ }
6409
+ }
6410
+
6317
6411
  function install(FormCreate) {
6318
6412
  FormCreate.componentAlias(alias);
6319
6413
  components.forEach(function (component) {
6320
6414
  FormCreate.component(component.name, component);
6321
6415
  });
6416
+ FormCreate.register(required);
6322
6417
  parsers.forEach(function (parser) {
6323
6418
  FormCreate.parser(parser);
6324
6419
  });
@@ -6336,7 +6431,7 @@ function install(FormCreate) {
6336
6431
  function elmFormCreate() {
6337
6432
  return FormCreateFactory({
6338
6433
  ui: 'element-ui',
6339
- version: '3.1.3',
6434
+ version: '3.1.4',
6340
6435
  manager: manager,
6341
6436
  extendApi: extendApi,
6342
6437
  install: install,