@form-create/element-ui 3.1.3 → 3.1.6

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,10 +1,10 @@
1
1
  /*!
2
- * @form-create/element-ui v3.1.3
2
+ * @form-create/element-ui v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
6
6
  */
7
- import { defineComponent, toRef, resolveComponent, createVNode, mergeProps as mergeProps$1, openBlock, createElementBlock, createElementVNode, isVNode, nextTick, Fragment, markRaw, reactive, getCurrentInstance, provide, inject, toRefs, onMounted, onBeforeUnmount, onUpdated, watch, computed, customRef, withDirectives, resolveDirective, createApp, h, ref } from 'vue';
7
+ import { defineComponent, toRef, resolveComponent, createVNode, mergeProps as mergeProps$1, openBlock, createElementBlock, createElementVNode, isVNode, nextTick, Fragment, markRaw, reactive, getCurrentInstance, provide, inject, toRefs, onMounted, onBeforeUnmount, onUpdated, watch, computed, withDirectives, resolveDirective, createApp, h, ref } from 'vue';
8
8
 
9
9
  function ownKeys(object, enumerableOnly) {
10
10
  var keys = Object.keys(object);
@@ -1495,6 +1495,26 @@ var Group = defineComponent({
1495
1495
  },
1496
1496
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
1497
1497
  watch: {
1498
+ rule: {
1499
+ handler: function handler(n, o) {
1500
+ var _this = this;
1501
+
1502
+ Object.keys(this.cacheRule).forEach(function (v) {
1503
+ var item = _this.cacheRule[v];
1504
+
1505
+ if (n === o) {
1506
+ deepExtend(item.rule, n);
1507
+ } else {
1508
+ var val = item.$f.formData();
1509
+ item.$f.once('reloading', function () {
1510
+ item.$f.setValue(val);
1511
+ });
1512
+ item.rule = deepCopy(n);
1513
+ }
1514
+ });
1515
+ },
1516
+ deep: true
1517
+ },
1498
1518
  disabled: function disabled(n) {
1499
1519
  if (this.syncDisabled) {
1500
1520
  var lst = this.cacheRule;
@@ -1512,7 +1532,7 @@ var Group = defineComponent({
1512
1532
  },
1513
1533
  modelValue: {
1514
1534
  handler: function handler(n) {
1515
- var _this = this;
1535
+ var _this2 = this;
1516
1536
 
1517
1537
  n = n || [];
1518
1538
  var keys = Object.keys(this.cacheRule),
@@ -1532,17 +1552,14 @@ var Group = defineComponent({
1532
1552
  for (var _i2 = 0; _i2 < len; _i2++) {
1533
1553
  this.removeRule(keys[total - _i2 - 1]);
1534
1554
  }
1535
-
1536
- this.subForm();
1537
1555
  }
1538
1556
 
1539
1557
  n.forEach(function (val, i) {
1540
- _this.setValue(keys[i], n[i]);
1558
+ _this2.setValue(keys[i], n[i]);
1541
1559
  });
1542
1560
  }
1543
1561
  },
1544
- deep: true,
1545
- flush: 'post'
1562
+ deep: true
1546
1563
  }
1547
1564
  },
1548
1565
  methods: {
@@ -1557,7 +1574,7 @@ var Group = defineComponent({
1557
1574
  this.$emit('change', value);
1558
1575
  },
1559
1576
  formData: function formData(key, _formData) {
1560
- var _this2 = this;
1577
+ var _this3 = this;
1561
1578
 
1562
1579
  var cacheRule = this.cacheRule;
1563
1580
  var keys = Object.keys(cacheRule);
@@ -1569,10 +1586,10 @@ var Group = defineComponent({
1569
1586
  }
1570
1587
 
1571
1588
  var value = keys.map(function (k) {
1572
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
1573
- var value = _this2.field ? data[_this2.field] || null : data;
1589
+ var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
1590
+ var value = _this3.field ? data[_this3.field] || null : data;
1574
1591
 
1575
- _this2.cache(k, value);
1592
+ _this3.cache(k, value);
1576
1593
 
1577
1594
  return value;
1578
1595
  });
@@ -1592,7 +1609,7 @@ var Group = defineComponent({
1592
1609
  this.cache(key, value);
1593
1610
  },
1594
1611
  addRule: function addRule(i, emit) {
1595
- var _this3 = this;
1612
+ var _this4 = this;
1596
1613
 
1597
1614
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
1598
1615
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -1613,31 +1630,23 @@ var Group = defineComponent({
1613
1630
 
1614
1631
  if (emit) {
1615
1632
  nextTick(function () {
1616
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
1633
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
1617
1634
  });
1618
1635
  }
1619
1636
  },
1620
1637
  add$f: function add$f(i, key, $f) {
1621
- var _this4 = this;
1638
+ var _this5 = this;
1622
1639
 
1623
1640
  this.cacheRule[key].$f = $f;
1624
- this.subForm();
1625
1641
  this.formData(key, $f.formData());
1626
1642
  nextTick(function () {
1627
- if (_this4.syncDisabled) {
1628
- $f.disabled(_this4.disabled);
1643
+ if (_this5.syncDisabled) {
1644
+ $f.disabled(_this5.disabled);
1629
1645
  }
1630
1646
 
1631
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
1647
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
1632
1648
  });
1633
1649
  },
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
1650
  removeRule: function removeRule(key, emit) {
1642
1651
  var _this6 = this;
1643
1652
 
@@ -1665,7 +1674,6 @@ var Group = defineComponent({
1665
1674
  }
1666
1675
 
1667
1676
  this.removeRule(key, true);
1668
- this.subForm();
1669
1677
  this.modelValue.splice(index, 1);
1670
1678
  this.input(this.modelValue);
1671
1679
  },
@@ -1780,6 +1788,7 @@ var Group = defineComponent({
1780
1788
  "default": function _default() {
1781
1789
  return [createVNode(Type, {
1782
1790
  "key": key,
1791
+ "inFor": true,
1783
1792
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
1784
1793
  return _this9.formData(key, formData);
1785
1794
  },
@@ -1882,7 +1891,6 @@ var Sub = defineComponent({
1882
1891
  var _this = this;
1883
1892
 
1884
1893
  this.subApi = api;
1885
- this.formCreateInject.subForm(api);
1886
1894
  nextTick(function () {
1887
1895
  _this.syncDisabled && api.disabled(_this.disabled);
1888
1896
 
@@ -1929,6 +1937,21 @@ script.render = render;
1929
1937
  var components = [Checkbox, Frame, Radio, Select, Tree, Upload, Group, Sub, script];
1930
1938
 
1931
1939
  var NAME$1 = 'FormCreate';
1940
+
1941
+ var getRuleInject = function getRuleInject(vm, parent) {
1942
+ if (!vm || vm === parent) {
1943
+ return;
1944
+ }
1945
+
1946
+ if (vm.ctx.formCreateInject) {
1947
+ return vm.ctx.formCreateInject;
1948
+ }
1949
+
1950
+ if (vm.parent) {
1951
+ return getRuleInject(vm.parent, parent);
1952
+ }
1953
+ };
1954
+
1932
1955
  function $FormCreate(FormCreate) {
1933
1956
  return defineComponent({
1934
1957
  name: NAME$1,
@@ -1949,7 +1972,12 @@ function $FormCreate(FormCreate) {
1949
1972
  extendOption: Boolean,
1950
1973
  modelValue: Object,
1951
1974
  api: Object,
1952
- name: String
1975
+ name: String,
1976
+ subForm: {
1977
+ type: Boolean,
1978
+ "default": true
1979
+ },
1980
+ inFor: Boolean
1953
1981
  },
1954
1982
  emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1955
1983
  render: function render() {
@@ -1962,7 +1990,9 @@ function $FormCreate(FormCreate) {
1962
1990
 
1963
1991
  var _toRefs = toRefs(props),
1964
1992
  rule = _toRefs.rule,
1965
- modelValue = _toRefs.modelValue;
1993
+ modelValue = _toRefs.modelValue,
1994
+ subForm = _toRefs.subForm,
1995
+ inFor = _toRefs.inFor;
1966
1996
 
1967
1997
  var data = reactive({
1968
1998
  ctxInject: {},
@@ -1970,20 +2000,64 @@ function $FormCreate(FormCreate) {
1970
2000
  isShow: true,
1971
2001
  unique: 1,
1972
2002
  renderRule: _toConsumableArray(rule.value || []),
1973
- updateValue: JSON.stringify(modelValue)
2003
+ updateValue: JSON.stringify(modelValue || {})
1974
2004
  });
1975
2005
  var fc = new FormCreate(vm);
1976
2006
  var fapi = fc.api();
2007
+ var isMore = inFor.value;
2008
+
2009
+ var addSubForm = function addSubForm() {
2010
+ if (parent) {
2011
+ var _inject = getRuleInject(vm, parent);
2012
+
2013
+ if (_inject) {
2014
+ var sub;
2015
+
2016
+ if (isMore) {
2017
+ sub = toArray(_inject.getSubForm());
2018
+ sub.push(fapi);
2019
+ } else {
2020
+ sub = fapi;
2021
+ }
2022
+
2023
+ _inject.subForm(sub);
2024
+ }
2025
+ }
2026
+ };
2027
+
2028
+ var rmSubForm = function rmSubForm() {
2029
+ var inject = getRuleInject(vm, parent);
2030
+
2031
+ if (inject) {
2032
+ if (isMore) {
2033
+ var sub = toArray(inject.getSubForm());
2034
+ var idx = sub.indexOf(fapi);
2035
+
2036
+ if (idx > -1) {
2037
+ sub.splice(idx, 1);
2038
+ }
2039
+ } else {
2040
+ inject.subForm();
2041
+ }
2042
+ }
2043
+ };
2044
+
1977
2045
  onMounted(function () {
1978
2046
  fc.mounted();
1979
2047
  });
1980
2048
  onBeforeUnmount(function () {
2049
+ rmSubForm();
1981
2050
  data.destroyed = true;
1982
2051
  fc.unmount();
1983
2052
  });
1984
2053
  onUpdated(function () {
1985
2054
  fc.updated();
1986
2055
  });
2056
+ watch(subForm, function (n) {
2057
+ n ? addSubForm() : rmSubForm();
2058
+ }, {
2059
+ immediate: true
2060
+ });
1987
2061
  watch(function () {
1988
2062
  return _toConsumableArray(rule.value);
1989
2063
  }, function (n) {
@@ -1998,8 +2072,8 @@ function $FormCreate(FormCreate) {
1998
2072
  fapi.refresh();
1999
2073
  });
2000
2074
  watch(modelValue, function (n) {
2001
- if (JSON.stringify(n) === data.updateValue) return;
2002
- fapi.setValue(n);
2075
+ if (JSON.stringify(n || {}) === data.updateValue) return;
2076
+ fapi.setValue(n || {});
2003
2077
  }, {
2004
2078
  deep: true
2005
2079
  });
@@ -2098,7 +2172,7 @@ var mergeFn = function mergeFn(fn1, fn2) {
2098
2172
  };
2099
2173
  };
2100
2174
 
2101
- var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate'];
2175
+ var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate', 'computed', 'preview', 'component', 'cache'];
2102
2176
  var arrayAttrs = ['validate', 'children', 'control'];
2103
2177
  var normalAttrs = ['effect'];
2104
2178
  function attrs() {
@@ -2486,7 +2560,7 @@ function Api(h) {
2486
2560
  if (!ctx) return initial;
2487
2561
  initial[ctx.field] = copy(ctx.rule.value);
2488
2562
  return initial;
2489
- }, copy(h.appendData));
2563
+ }, {});
2490
2564
  },
2491
2565
  getValue: function getValue(field) {
2492
2566
  var ctx = h.getFieldCtx(field);
@@ -2716,6 +2790,25 @@ function Api(h) {
2716
2790
  return origin ? ctx.origin : ctx.rule;
2717
2791
  }
2718
2792
  },
2793
+ setEffect: function setEffect(id, attr, value) {
2794
+ var ctx = h.getCtx(id);
2795
+
2796
+ if (ctx && attr) {
2797
+ if (attr[0] === '$') {
2798
+ attr = attr.substr(1);
2799
+ }
2800
+
2801
+ if (hasProperty(ctx.rule, '$' + attr)) {
2802
+ $set(ctx.rule, '$' + attr, value);
2803
+ }
2804
+
2805
+ if (!hasProperty(ctx.rule, 'effect')) {
2806
+ ctx.rule.effect = {};
2807
+ }
2808
+
2809
+ $set(ctx.rule.effect, attr, value);
2810
+ }
2811
+ },
2719
2812
  updateValidate: function updateValidate(id, validate, merge) {
2720
2813
  if (merge) {
2721
2814
  api.mergeRule(id, {
@@ -2998,7 +3091,6 @@ function useRender$1(Render) {
2998
3091
  try {
2999
3092
  if (ctx.type === 'hidden') return;
3000
3093
  var rule = ctx.rule;
3001
- var preview = this.options.preview || false;
3002
3094
 
3003
3095
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
3004
3096
  var vn;
@@ -3010,7 +3102,10 @@ function useRender$1(Render) {
3010
3102
  this.setOptions(ctx);
3011
3103
  this.ctxProp(ctx);
3012
3104
  var prop = ctx.prop;
3105
+ prop.preview = !!(hasProperty(prop, 'preview') ? prop.preview : this.options.preview || false);
3013
3106
  prop.props.formCreateInject = this.injectProp(ctx);
3107
+ var cacheFlag = prop.cache !== false;
3108
+ var preview = prop.preview;
3014
3109
 
3015
3110
  if (prop.hidden) {
3016
3111
  this.setCache(ctx, undefined, parent);
@@ -3068,18 +3163,18 @@ function useRender$1(Render) {
3068
3163
  _vn = _this4.display(_vn);
3069
3164
  }
3070
3165
 
3071
- _this4.setCache(ctx, function () {
3166
+ cacheFlag && _this4.setCache(ctx, function () {
3072
3167
  return _vn;
3073
3168
  }, parent);
3074
-
3075
3169
  return _vn;
3076
3170
  };
3077
3171
 
3078
3172
  this.setCache(ctx, vn, parent);
3079
- return vn;
3080
3173
  }
3081
3174
 
3082
- return this.getCache(ctx);
3175
+ return function () {
3176
+ return _this4.getCache(ctx).apply(void 0, arguments);
3177
+ };
3083
3178
  } catch (e) {
3084
3179
  console.error(e);
3085
3180
  return;
@@ -3132,17 +3227,21 @@ function useRender$1(Render) {
3132
3227
  subForm: function subForm(_subForm) {
3133
3228
  _this6.$handle.addSubForm(ctx, _subForm);
3134
3229
  },
3230
+ getSubForm: function getSubForm() {
3231
+ return _this6.$handle.subForm[ctx.id];
3232
+ },
3135
3233
  options: [],
3136
3234
  children: [],
3137
3235
  preview: false,
3138
3236
  field: ctx.field,
3139
- rule: ctx.rule
3237
+ rule: ctx.rule,
3238
+ input: ctx.input
3140
3239
  };
3141
3240
  }
3142
3241
 
3143
3242
  var inject = state.ctxInject[ctx.id];
3144
3243
  extend(inject, {
3145
- preview: this.options.preview || false,
3244
+ preview: ctx.prop.preview,
3146
3245
  options: ctx.prop.options,
3147
3246
  children: ctx.loadChildrenPending()
3148
3247
  });
@@ -3220,6 +3319,7 @@ function useRender$1(Render) {
3220
3319
  },
3221
3320
  defaultRender: function defaultRender(ctx, children) {
3222
3321
  var prop = ctx.prop;
3322
+ if (prop.component) return this.vNode.makeComponent(prop.component, prop, children);
3223
3323
  if (this.vNode[ctx.type]) return this.vNode[ctx.type](prop, children);
3224
3324
  if (this.vNode[ctx.originType]) return this.vNode[ctx.originType](prop, children);
3225
3325
  return this.vNode.make(lower(ctx.originType), prop, children);
@@ -3694,11 +3794,7 @@ extend(RuleContext.prototype, {
3694
3794
  this.$handle.appendLink(this);
3695
3795
  },
3696
3796
  watchTo: function watchTo() {
3697
- var _this4 = this;
3698
-
3699
- nextTick(function () {
3700
- _this4.$handle && _this4.$handle.watchCtx(_this4);
3701
- });
3797
+ this.$handle.watchCtx(this);
3702
3798
  },
3703
3799
  "delete": function _delete() {
3704
3800
  var undef = void 0;
@@ -3727,15 +3823,15 @@ extend(RuleContext.prototype, {
3727
3823
  this.ctrlRule = [];
3728
3824
  },
3729
3825
  rm: function rm() {
3730
- var _this5 = this;
3826
+ var _this4 = this;
3731
3827
 
3732
3828
  var _rm = function _rm() {
3733
- var index = _this5.root.indexOf(_this5.origin);
3829
+ var index = _this4.root.indexOf(_this4.origin);
3734
3830
 
3735
3831
  if (index > -1) {
3736
- _this5.root.splice(index, 1);
3832
+ _this4.root.splice(index, 1);
3737
3833
 
3738
- _this5.$handle && _this5.$handle.refresh();
3834
+ _this4.$handle && _this4.$handle.refresh();
3739
3835
  }
3740
3836
  };
3741
3837
 
@@ -3746,17 +3842,17 @@ extend(RuleContext.prototype, {
3746
3842
  }
3747
3843
 
3748
3844
  this.$handle.noWatch(function () {
3749
- _this5.$handle.deferSyncValue(function () {
3750
- _this5.rmCtrl();
3845
+ _this4.$handle.deferSyncValue(function () {
3846
+ _this4.rmCtrl();
3751
3847
 
3752
3848
  _rm();
3753
3849
 
3754
- _this5.$handle.rmCtx(_this5);
3850
+ _this4.$handle.rmCtx(_this4);
3755
3851
 
3756
- extend(_this5, {
3852
+ extend(_this4, {
3757
3853
  root: []
3758
3854
  });
3759
- }, _this5.input);
3855
+ }, _this4.input);
3760
3856
  });
3761
3857
  },
3762
3858
  update: function update(handle, init) {
@@ -3860,13 +3956,13 @@ function useLoader(Handler) {
3860
3956
  return _this5.loadRule();
3861
3957
  }
3862
3958
 
3959
+ _this5.syncForm();
3960
+
3863
3961
  if (_this5.pageEnd) {
3864
3962
  _this5.bus.$emit('load-end');
3865
3963
  }
3866
3964
 
3867
3965
  _this5.vm.setupState.renderRule();
3868
-
3869
- _this5.syncForm();
3870
3966
  });
3871
3967
  },
3872
3968
  loadChildren: function loadChildren(children, parent) {
@@ -3881,8 +3977,8 @@ function useLoader(Handler) {
3881
3977
  if (this.cycleLoad) {
3882
3978
  return this.loadRule();
3883
3979
  } else {
3884
- this.bus.$emit('load-end');
3885
3980
  this.syncForm();
3981
+ this.bus.$emit('load-end');
3886
3982
  }
3887
3983
 
3888
3984
  this.$render.clearCache(parent);
@@ -4126,19 +4222,27 @@ function useLoader(Handler) {
4126
4222
  this.clearNextTick();
4127
4223
  this.initData(rules);
4128
4224
  this.fc.rules = rules;
4129
- this.bus.$once('load-end', function () {
4130
- Object.keys(ctxs).filter(function (id) {
4131
- return _this8.ctxs[id] === undefined;
4132
- }).forEach(function (id) {
4133
- return _this8.rmCtx(ctxs[id]);
4225
+ this.deferSyncValue(function () {
4226
+ _this8.bus.$once('load-end', function () {
4227
+ Object.keys(ctxs).filter(function (id) {
4228
+ return _this8.ctxs[id] === undefined;
4229
+ }).forEach(function (id) {
4230
+ return _this8.rmCtx(ctxs[id]);
4231
+ });
4232
+
4233
+ _this8.$render.clearCacheAll();
4134
4234
  });
4135
4235
 
4136
- _this8.$render.clearCacheAll();
4236
+ _this8.reloading = true;
4237
+
4238
+ _this8.loadRule();
4239
+
4240
+ _this8.reloading = false;
4241
+
4242
+ _this8.refresh();
4243
+
4244
+ _this8.bus.$emit('reloading', _this8.api);
4137
4245
  });
4138
- this.reloading = true;
4139
- this.loadRule();
4140
- this.reloading = false;
4141
- this.refresh();
4142
4246
  this.bus.$off('next-tick', this.nextReload);
4143
4247
  this.bus.$once('next-tick', this.nextReload);
4144
4248
  this.bus.$emit('update', this.api);
@@ -4204,28 +4308,14 @@ function useInput(Handler) {
4204
4308
  syncForm: function syncForm() {
4205
4309
  var _this = this;
4206
4310
 
4311
+ var data = reactive({});
4207
4312
  this.fields().reduce(function (initial, field) {
4208
4313
  var ctx = _this.getCtx(field);
4209
4314
 
4210
4315
  initial[field] = toRef(ctx.rule, 'value');
4211
4316
  return initial;
4212
- }, Object.keys(this.appendData).reduce(function (initial, field) {
4213
- initial[field] = customRef(function (track, trigger) {
4214
- return {
4215
- get: function get() {
4216
- track();
4217
- return _this.appendData[field];
4218
- },
4219
- set: function set(val) {
4220
- trigger();
4221
- _this.appendData[field] = val;
4222
-
4223
- _this.syncValue();
4224
- }
4225
- };
4226
- });
4227
- return initial;
4228
- }, this.form));
4317
+ }, data);
4318
+ this.form = data;
4229
4319
  this.syncValue();
4230
4320
  },
4231
4321
  appendValue: function appendValue(rule) {
@@ -4234,9 +4324,7 @@ function useInput(Handler) {
4234
4324
  delete this.appendData[rule.field];
4235
4325
  },
4236
4326
  addSubForm: function addSubForm(ctx, subForm) {
4237
- if (ctx.input) {
4238
- this.subForm[ctx.id] = subForm;
4239
- }
4327
+ this.subForm[ctx.id] = subForm;
4240
4328
  },
4241
4329
  deferSyncValue: function deferSyncValue(fn, sync) {
4242
4330
  if (!this.deferSyncFn) {
@@ -4334,11 +4422,46 @@ var BaseParser = {
4334
4422
  return ctx.$render.defaultRender(ctx, children);
4335
4423
  },
4336
4424
  preview: function preview(children, ctx) {
4337
- return ctx.$render.defaultRender(ctx, children);
4425
+ return this.render(children, ctx);
4338
4426
  },
4339
4427
  mergeProp: function mergeProp(ctx) {}
4340
4428
  };
4341
4429
 
4430
+ var _ = {
4431
+ sum: function sum(arr) {
4432
+ if (Array.isArray(arr)) {
4433
+ var val = 0;
4434
+ arr.map(function (v) {
4435
+ return val += v || 0;
4436
+ });
4437
+ return val;
4438
+ }
4439
+ },
4440
+ column: function column(arr, field) {
4441
+ if (Array.isArray(arr)) {
4442
+ return arr.map(function (v) {
4443
+ return v[field];
4444
+ });
4445
+ }
4446
+
4447
+ return [];
4448
+ },
4449
+ get: function get(obj, field, def) {
4450
+ var lst = field.split('.');
4451
+ var val = obj;
4452
+
4453
+ for (var i = 0; i < lst.length; i++) {
4454
+ if (hasProperty(val, lst[i])) {
4455
+ val = val[lst[i]];
4456
+ } else {
4457
+ return def === undefined ? 0 : def;
4458
+ }
4459
+ }
4460
+
4461
+ return val;
4462
+ }
4463
+ };
4464
+ var noneKey = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'slotUpdate', 'computed', 'component', 'cache'];
4342
4465
  function useContext(Handler) {
4343
4466
  extend(Handler.prototype, {
4344
4467
  getCtx: function getCtx(id) {
@@ -4415,10 +4538,9 @@ function useContext(Handler) {
4415
4538
  watchCtx: function watchCtx(ctx) {
4416
4539
  var _this = this;
4417
4540
 
4418
- var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'slotUpdate'];
4419
4541
  var all = attrs();
4420
4542
  all.filter(function (k) {
4421
- return k[0] !== '_' && k[0] !== '$' && none.indexOf(k) === -1;
4543
+ return k[0] !== '_' && k[0] !== '$' && noneKey.indexOf(k) === -1;
4422
4544
  }).forEach(function (key) {
4423
4545
  var ref = toRef(ctx.rule, key);
4424
4546
  var flag = key === 'children';
@@ -4481,11 +4603,36 @@ function useContext(Handler) {
4481
4603
  return val.value;
4482
4604
  }, function () {
4483
4605
  var formValue = ctx.parser.toFormValue(val.value, ctx);
4606
+ formValue = formValue === null ? undefined : formValue;
4484
4607
 
4485
4608
  if (_this.isChange(ctx, formValue)) {
4486
4609
  _this.setValue(ctx, val.value, formValue, true);
4487
4610
  }
4488
4611
  }));
4612
+ this.bus.$once('load-end', function () {
4613
+ var computedRef = toRef(ctx.rule, 'computed');
4614
+ ctx.watch.push(watch(function () {
4615
+ var computed = computedRef.value;
4616
+ if (!computed) return undefined;
4617
+ var fn;
4618
+
4619
+ if (is.Function(computed)) {
4620
+ fn = function fn() {
4621
+ return computed(_this.api.form, _this.api);
4622
+ };
4623
+ } else {
4624
+ fn = function fn() {
4625
+ return new Function('_', "with(this){ return ".concat(computed, " }")).call(_this.api.form, _);
4626
+ };
4627
+ }
4628
+
4629
+ return invoke(fn, undefined);
4630
+ }, function (n) {
4631
+ val.value = n;
4632
+ }, {
4633
+ immediate: !!computedRef.value
4634
+ }));
4635
+ });
4489
4636
  }
4490
4637
 
4491
4638
  this.watchEffect(ctx);
@@ -4526,6 +4673,7 @@ function useContext(Handler) {
4526
4673
  $del(this.formData, id);
4527
4674
  $del(this.subForm, id);
4528
4675
  $del(this.vm.setupState.ctxInject, id);
4676
+ input && $del(this.form, field);
4529
4677
  input && this.rmIdCtx(ctx, field, 'field');
4530
4678
  name && this.rmIdCtx(ctx, name, 'name');
4531
4679
  this.deferSyncValue(function () {
@@ -4922,6 +5070,14 @@ function CreateNodeFactory() {
4922
5070
  make: function make(tag, data, children) {
4923
5071
  return makeDirective(data, this.h(tag, toProps(data), children));
4924
5072
  },
5073
+ makeComponent: function makeComponent(type, data, children) {
5074
+ try {
5075
+ return makeDirective(data, createVNode(type, toProps(data), children));
5076
+ } catch (e) {
5077
+ console.error(e);
5078
+ return createVNode('');
5079
+ }
5080
+ },
4925
5081
  h: function h(tag, data, children) {
4926
5082
  var isNativeTag = getCurrentInstance().appContext.config.isNativeTag(tag);
4927
5083
 
@@ -5048,44 +5204,6 @@ var $fetch = {
5048
5204
  }
5049
5205
  }
5050
5206
  };
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
5207
 
5090
5208
  function parseOpt(option) {
5091
5209
  if (is.String(option)) {
@@ -5157,8 +5275,7 @@ function run(inject, rule, api) {
5157
5275
  }
5158
5276
 
5159
5277
  var $provider = {
5160
- fetch: $fetch,
5161
- required: $required
5278
+ fetch: $fetch
5162
5279
  };
5163
5280
 
5164
5281
  var name$6 = 'html';
@@ -5232,7 +5349,9 @@ function FormCreateFactory(config) {
5232
5349
  exportAttrs(config.attrs || {});
5233
5350
 
5234
5351
  function getApi(name) {
5235
- return instance[name];
5352
+ var val = instance[name];
5353
+ if (Array.isArray(val)) return _toConsumableArray(val);
5354
+ return val;
5236
5355
  }
5237
5356
 
5238
5357
  function useApp(fn) {
@@ -5367,6 +5486,7 @@ function FormCreateFactory(config) {
5367
5486
  modelFields: modelFields,
5368
5487
  rules: vm.props.rule,
5369
5488
  name: vm.props.name,
5489
+ inFor: vm.props.inFor,
5370
5490
  prop: {
5371
5491
  components: components,
5372
5492
  directives: directives
@@ -5374,7 +5494,7 @@ function FormCreateFactory(config) {
5374
5494
  CreateNode: CreateNode,
5375
5495
  bus: new Mitt(),
5376
5496
  unwatch: null,
5377
- options: ref({}),
5497
+ options: ref(vm.props.option || {}),
5378
5498
  extendApi: config.extendApi || function (api) {
5379
5499
  return api;
5380
5500
  }
@@ -5393,7 +5513,12 @@ function FormCreateFactory(config) {
5393
5513
  this.$handle = new Handler(this);
5394
5514
 
5395
5515
  if (this.name) {
5396
- instance[this.name] = this.api();
5516
+ if (this.inFor) {
5517
+ if (!instance[this.name]) instance[this.name] = [];
5518
+ instance[this.name].push(this.api());
5519
+ } else {
5520
+ instance[this.name] = this.api();
5521
+ }
5397
5522
  }
5398
5523
  }
5399
5524
 
@@ -5413,7 +5538,7 @@ function FormCreateFactory(config) {
5413
5538
  });
5414
5539
  }
5415
5540
 
5416
- this.initOptions(this.vm.props.option || {});
5541
+ this.initOptions(this.options || {});
5417
5542
  this.$handle.init();
5418
5543
  },
5419
5544
  isSub: function isSub() {
@@ -5461,7 +5586,12 @@ function FormCreateFactory(config) {
5461
5586
  },
5462
5587
  unmount: function unmount() {
5463
5588
  if (this.name) {
5464
- delete instance[this.name];
5589
+ if (this.inFor) {
5590
+ var idx = instance[this.name].indexOf(this.api());
5591
+ instance[this.name].splice(idx, 1);
5592
+ } else {
5593
+ delete instance[this.name];
5594
+ }
5465
5595
  }
5466
5596
 
5467
5597
  this.unwatch && this.unwatch();
@@ -6314,11 +6444,61 @@ function extendApi(api, h) {
6314
6444
  return api;
6315
6445
  }
6316
6446
 
6447
+ var required = {
6448
+ name: 'required',
6449
+ load: function load(inject, rule, api) {
6450
+ var val = parseVal(inject.getValue());
6451
+
6452
+ if (val.required === false) {
6453
+ inject.clearProp();
6454
+ } else {
6455
+ var validate = _objectSpread2({
6456
+ required: true,
6457
+ validator: function validator(_, v, call) {
6458
+ is.empty(v) ? call(validate.message) : call();
6459
+ }
6460
+ }, val);
6461
+
6462
+ if (!validate.message) {
6463
+ validate.message = rule.title + ' is required';
6464
+ }
6465
+
6466
+ inject.getProp().validate = [validate];
6467
+ }
6468
+
6469
+ api.sync(rule);
6470
+ },
6471
+ watch: function watch() {
6472
+ required.load.apply(required, arguments);
6473
+ }
6474
+ };
6475
+
6476
+ function parseVal(val) {
6477
+ if (is.Boolean(val)) {
6478
+ return {
6479
+ required: val
6480
+ };
6481
+ } else if (is.String(val)) {
6482
+ return {
6483
+ message: val
6484
+ };
6485
+ } else if (is.Function(val)) {
6486
+ return {
6487
+ validator: val
6488
+ };
6489
+ } else if (!is.Object(val)) {
6490
+ return {};
6491
+ } else {
6492
+ return val;
6493
+ }
6494
+ }
6495
+
6317
6496
  function install(FormCreate) {
6318
6497
  FormCreate.componentAlias(alias);
6319
6498
  components.forEach(function (component) {
6320
6499
  FormCreate.component(component.name, component);
6321
6500
  });
6501
+ FormCreate.register(required);
6322
6502
  parsers.forEach(function (parser) {
6323
6503
  FormCreate.parser(parser);
6324
6504
  });
@@ -6336,7 +6516,7 @@ function install(FormCreate) {
6336
6516
  function elmFormCreate() {
6337
6517
  return FormCreateFactory({
6338
6518
  ui: 'element-ui',
6339
- version: '3.1.3',
6519
+ version: '3.1.6',
6340
6520
  manager: manager,
6341
6521
  extendApi: extendApi,
6342
6522
  install: install,