@form-create/element-ui 3.1.2 → 3.1.5

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.2
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.
@@ -795,6 +795,7 @@ var Frame = defineComponent({
795
795
  try {
796
796
  if (this.helper === true) {
797
797
  iframe['form_create_helper'] = {
798
+ api: this.formCreateInject.api,
798
799
  close: function close(field) {
799
800
  _this7.valid(field);
800
801
 
@@ -1267,9 +1268,28 @@ var is = {
1267
1268
  },
1268
1269
  trueArray: function trueArray(data) {
1269
1270
  return Array.isArray(data) && data.length > 0;
1271
+ },
1272
+ Function: function Function(v) {
1273
+ var type = this.getType(v);
1274
+ return type === 'Function' || type === 'AsyncFunction';
1275
+ },
1276
+ getType: function getType(v) {
1277
+ var str = Object.prototype.toString.call(v);
1278
+ return /^\[object (.*)\]$/.exec(str)[1];
1279
+ },
1280
+ empty: function empty(value) {
1281
+ if (value === undefined || value === null) {
1282
+ return true;
1283
+ }
1284
+
1285
+ if (Array.isArray(value) && Array.isArray(value) && !value.length) {
1286
+ return true;
1287
+ }
1288
+
1289
+ return typeof value === 'string' && !value;
1270
1290
  }
1271
1291
  };
1272
- ['Date', 'Object', 'Function', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
1292
+ ['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
1273
1293
  is[t] = function (arg) {
1274
1294
  return is.type(arg, t);
1275
1295
  };
@@ -1337,6 +1357,81 @@ function render$1(_ctx, _cache, $props, $setup, $data, $options) {
1337
1357
 
1338
1358
  script$1.render = render$1;
1339
1359
 
1360
+ function $set(target, field, value) {
1361
+ target[field] = value;
1362
+ }
1363
+ function $del(target, field) {
1364
+ delete target[field];
1365
+ }
1366
+
1367
+ function deepExtend(origin) {
1368
+ var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1369
+ var mode = arguments.length > 2 ? arguments[2] : undefined;
1370
+ var isArr = false;
1371
+
1372
+ for (var key in target) {
1373
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
1374
+ var clone = target[key];
1375
+
1376
+ if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
1377
+ var nst = origin[key] === undefined;
1378
+
1379
+ if (isArr) {
1380
+ isArr = false;
1381
+ nst && $set(origin, key, []);
1382
+ } else if (clone._clone && mode !== undefined) {
1383
+ if (mode) {
1384
+ clone = clone.getRule();
1385
+ nst && $set(origin, key, {});
1386
+ } else {
1387
+ $set(origin, key, clone._clone());
1388
+ continue;
1389
+ }
1390
+ } else {
1391
+ nst && $set(origin, key, {});
1392
+ }
1393
+
1394
+ origin[key] = deepExtend(origin[key], clone, mode);
1395
+ } else {
1396
+ $set(origin, key, clone);
1397
+
1398
+ if (!is.Undef(clone)) {
1399
+ if (!is.Undef(clone.__json)) {
1400
+ origin[key].__json = clone.__json;
1401
+ }
1402
+
1403
+ if (!is.Undef(clone.__origin)) {
1404
+ origin[key].__origin = clone.__origin;
1405
+ }
1406
+ }
1407
+ }
1408
+ }
1409
+ }
1410
+
1411
+ return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
1412
+ return !v || !v.__ctrl;
1413
+ }) : origin;
1414
+ }
1415
+ function deepCopy(value) {
1416
+ return deepExtend({}, {
1417
+ value: value
1418
+ }).value;
1419
+ }
1420
+
1421
+ var _extends = Object.assign || function (a) {
1422
+ for (var b, c = 1; c < arguments.length; c++) {
1423
+ for (var d in b = arguments[c], b) {
1424
+ Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
1425
+ }
1426
+ }
1427
+
1428
+ return a;
1429
+ };
1430
+
1431
+ function extend() {
1432
+ return _extends.apply(this, arguments);
1433
+ }
1434
+
1340
1435
  function _isSlot(s) {
1341
1436
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
1342
1437
  }
@@ -1367,6 +1462,7 @@ var Group = defineComponent({
1367
1462
  return [];
1368
1463
  }
1369
1464
  },
1465
+ defaultValue: Object,
1370
1466
  disabled: {
1371
1467
  type: Boolean,
1372
1468
  "default": false
@@ -1436,8 +1532,6 @@ var Group = defineComponent({
1436
1532
  for (var _i2 = 0; _i2 < len; _i2++) {
1437
1533
  this.removeRule(keys[total - _i2 - 1]);
1438
1534
  }
1439
-
1440
- this.subForm();
1441
1535
  }
1442
1536
 
1443
1537
  n.forEach(function (val, i) {
@@ -1445,8 +1539,7 @@ var Group = defineComponent({
1445
1539
  });
1446
1540
  }
1447
1541
  },
1448
- deep: true,
1449
- flush: 'post'
1542
+ deep: true
1450
1543
  }
1451
1544
  },
1452
1545
  methods: {
@@ -1503,6 +1596,13 @@ var Group = defineComponent({
1503
1596
  submitBtn: false,
1504
1597
  resetBtn: false
1505
1598
  };
1599
+
1600
+ if (this.defaultValue) {
1601
+ if (!options.formData) options.formData = {};
1602
+ var defVal = deepCopy(this.defaultValue);
1603
+ extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
1604
+ }
1605
+
1506
1606
  this.cacheRule[++this.len] = {
1507
1607
  rule: rule,
1508
1608
  options: options
@@ -1518,7 +1618,7 @@ var Group = defineComponent({
1518
1618
  var _this4 = this;
1519
1619
 
1520
1620
  this.cacheRule[key].$f = $f;
1521
- this.subForm();
1621
+ this.formData(key, $f.formData());
1522
1622
  nextTick(function () {
1523
1623
  if (_this4.syncDisabled) {
1524
1624
  $f.disabled(_this4.disabled);
@@ -1527,15 +1627,8 @@ var Group = defineComponent({
1527
1627
  _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
1528
1628
  });
1529
1629
  },
1530
- subForm: function subForm() {
1531
- var _this5 = this;
1532
-
1533
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
1534
- return _this5.cacheRule[k].$f;
1535
- }));
1536
- },
1537
1630
  removeRule: function removeRule(key, emit) {
1538
- var _this6 = this;
1631
+ var _this5 = this;
1539
1632
 
1540
1633
  var index = Object.keys(this.cacheRule).indexOf(key);
1541
1634
  delete this.cacheRule[key];
@@ -1543,7 +1636,7 @@ var Group = defineComponent({
1543
1636
 
1544
1637
  if (emit) {
1545
1638
  nextTick(function () {
1546
- return _this6.$emit('remove', index);
1639
+ return _this5.$emit('remove', index);
1547
1640
  });
1548
1641
  }
1549
1642
  },
@@ -1561,7 +1654,6 @@ var Group = defineComponent({
1561
1654
  }
1562
1655
 
1563
1656
  this.removeRule(key, true);
1564
- this.subForm();
1565
1657
  this.modelValue.splice(index, 1);
1566
1658
  this.input(this.modelValue);
1567
1659
  },
@@ -1577,14 +1669,14 @@ var Group = defineComponent({
1577
1669
  });
1578
1670
  },
1579
1671
  delIcon: function delIcon(index, key) {
1580
- var _this7 = this;
1672
+ var _this6 = this;
1581
1673
 
1582
1674
  return createVNode(resolveComponent("ElIcon"), {
1583
1675
  "key": "d".concat(key),
1584
1676
  "class": "el-icon-remove-outline",
1585
1677
  "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
1586
1678
  "onClick": function onClick() {
1587
- return _this7.del(index, key);
1679
+ return _this6.del(index, key);
1588
1680
  }
1589
1681
  }, {
1590
1682
  "default": function _default() {
@@ -1593,7 +1685,7 @@ var Group = defineComponent({
1593
1685
  });
1594
1686
  },
1595
1687
  makeIcon: function makeIcon(total, index, key) {
1596
- var _this8 = this;
1688
+ var _this7 = this;
1597
1689
 
1598
1690
  if (this.$slots.button) {
1599
1691
  return this.$slots.button({
@@ -1602,7 +1694,7 @@ var Group = defineComponent({
1602
1694
  vm: this,
1603
1695
  key: key,
1604
1696
  del: function del() {
1605
- return _this8.del(index, key);
1697
+ return _this7.del(index, key);
1606
1698
  },
1607
1699
  add: this.add
1608
1700
  });
@@ -1637,7 +1729,7 @@ var Group = defineComponent({
1637
1729
  }
1638
1730
  },
1639
1731
  render: function render() {
1640
- var _this9 = this;
1732
+ var _this8 = this;
1641
1733
 
1642
1734
  var keys = Object.keys(this.cacheRule);
1643
1735
  var button = this.button;
@@ -1658,9 +1750,9 @@ var Group = defineComponent({
1658
1750
  }, [keys.map(function (key, index) {
1659
1751
  var _slot;
1660
1752
 
1661
- var _this9$cacheRule$key = _this9.cacheRule[key],
1662
- rule = _this9$cacheRule$key.rule,
1663
- 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;
1664
1756
  return createVNode(resolveComponent("ElRow"), {
1665
1757
  "align": "middle",
1666
1758
  "type": "flex",
@@ -1676,19 +1768,20 @@ var Group = defineComponent({
1676
1768
  "default": function _default() {
1677
1769
  return [createVNode(Type, {
1678
1770
  "key": key,
1771
+ "inFor": true,
1679
1772
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
1680
- return _this9.formData(key, formData);
1773
+ return _this8.formData(key, formData);
1681
1774
  },
1682
- "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],
1683
1776
  "onEmit-event": function onEmitEvent(name) {
1684
1777
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1685
1778
  args[_key - 1] = arguments[_key];
1686
1779
  }
1687
1780
 
1688
- return _this9.emitEvent(name, args, index, key);
1781
+ return _this8.emitEvent(name, args, index, key);
1689
1782
  },
1690
1783
  "onUpdate:api": function onUpdateApi($f) {
1691
- return _this9.add$f(index, key, $f);
1784
+ return _this8.add$f(index, key, $f);
1692
1785
  },
1693
1786
  "rule": rule,
1694
1787
  "option": options,
@@ -1701,7 +1794,7 @@ var Group = defineComponent({
1701
1794
  "span": 2,
1702
1795
  "pull": 1,
1703
1796
  "push": 1
1704
- }, _isSlot(_slot = _this9.makeIcon(keys.length, index, key)) ? _slot : {
1797
+ }, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
1705
1798
  "default": function _default() {
1706
1799
  return [_slot];
1707
1800
  }
@@ -1778,7 +1871,6 @@ var Sub = defineComponent({
1778
1871
  var _this = this;
1779
1872
 
1780
1873
  this.subApi = api;
1781
- this.formCreateInject.subForm(api);
1782
1874
  nextTick(function () {
1783
1875
  _this.syncDisabled && api.disabled(_this.disabled);
1784
1876
 
@@ -1825,6 +1917,21 @@ script.render = render;
1825
1917
  var components = [Checkbox, Frame, Radio, Select, Tree, Upload, Group, Sub, script];
1826
1918
 
1827
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
+
1828
1935
  function $FormCreate(FormCreate) {
1829
1936
  return defineComponent({
1830
1937
  name: NAME$1,
@@ -1845,7 +1952,12 @@ function $FormCreate(FormCreate) {
1845
1952
  extendOption: Boolean,
1846
1953
  modelValue: Object,
1847
1954
  api: Object,
1848
- name: String
1955
+ name: String,
1956
+ subForm: {
1957
+ type: Boolean,
1958
+ "default": true
1959
+ },
1960
+ inFor: Boolean
1849
1961
  },
1850
1962
  emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1851
1963
  render: function render() {
@@ -1858,7 +1970,9 @@ function $FormCreate(FormCreate) {
1858
1970
 
1859
1971
  var _toRefs = toRefs(props),
1860
1972
  rule = _toRefs.rule,
1861
- modelValue = _toRefs.modelValue;
1973
+ modelValue = _toRefs.modelValue,
1974
+ subForm = _toRefs.subForm,
1975
+ inFor = _toRefs.inFor;
1862
1976
 
1863
1977
  var data = reactive({
1864
1978
  ctxInject: {},
@@ -1870,16 +1984,60 @@ function $FormCreate(FormCreate) {
1870
1984
  });
1871
1985
  var fc = new FormCreate(vm);
1872
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
+
1873
2025
  onMounted(function () {
1874
2026
  fc.mounted();
1875
2027
  });
1876
2028
  onBeforeUnmount(function () {
2029
+ rmSubForm();
1877
2030
  data.destroyed = true;
1878
2031
  fc.unmount();
1879
2032
  });
1880
2033
  onUpdated(function () {
1881
2034
  fc.updated();
1882
2035
  });
2036
+ watch(subForm, function (n) {
2037
+ n ? addSubForm() : rmSubForm();
2038
+ }, {
2039
+ immediate: true
2040
+ });
1883
2041
  watch(function () {
1884
2042
  return _toConsumableArray(rule.value);
1885
2043
  }, function (n) {
@@ -1894,8 +2052,8 @@ function $FormCreate(FormCreate) {
1894
2052
  fapi.refresh();
1895
2053
  });
1896
2054
  watch(modelValue, function (n) {
1897
- if (JSON.stringify(n) === data.updateValue) return;
1898
- fapi.setValue(n);
2055
+ if (JSON.stringify(n || {}) === data.updateValue) return;
2056
+ fapi.setValue(n || {});
1899
2057
  }, {
1900
2058
  deep: true
1901
2059
  });
@@ -1925,27 +2083,6 @@ function $FormCreate(FormCreate) {
1925
2083
  });
1926
2084
  }
1927
2085
 
1928
- function $set(target, field, value) {
1929
- target[field] = value;
1930
- }
1931
- function $del(target, field) {
1932
- delete target[field];
1933
- }
1934
-
1935
- var _extends = Object.assign || function (a) {
1936
- for (var b, c = 1; c < arguments.length; c++) {
1937
- for (var d in b = arguments[c], b) {
1938
- Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
1939
- }
1940
- }
1941
-
1942
- return a;
1943
- };
1944
-
1945
- function extend() {
1946
- return _extends.apply(this, arguments);
1947
- }
1948
-
1949
2086
  var normalMerge = ['props'];
1950
2087
  var toArrayMerge = ['class', 'style', 'directives'];
1951
2088
  var functionalMerge = ['on'];
@@ -2015,67 +2152,13 @@ var mergeFn = function mergeFn(fn1, fn2) {
2015
2152
  };
2016
2153
  };
2017
2154
 
2018
- var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key'];
2155
+ var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate'];
2019
2156
  var arrayAttrs = ['validate', 'children', 'control'];
2020
2157
  var normalAttrs = ['effect'];
2021
2158
  function attrs() {
2022
2159
  return [].concat(keyAttrs, _toConsumableArray(normalMerge), _toConsumableArray(toArrayMerge), _toConsumableArray(functionalMerge), arrayAttrs, normalAttrs);
2023
2160
  }
2024
2161
 
2025
- function deepExtend(origin) {
2026
- var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2027
- var mode = arguments.length > 2 ? arguments[2] : undefined;
2028
- var isArr = false;
2029
-
2030
- for (var key in target) {
2031
- if (Object.prototype.hasOwnProperty.call(target, key)) {
2032
- var clone = target[key];
2033
-
2034
- if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
2035
- var nst = origin[key] === undefined;
2036
-
2037
- if (isArr) {
2038
- isArr = false;
2039
- nst && $set(origin, key, []);
2040
- } else if (clone._clone && mode !== undefined) {
2041
- if (mode) {
2042
- clone = clone.getRule();
2043
- nst && $set(origin, key, {});
2044
- } else {
2045
- $set(origin, key, clone._clone());
2046
- continue;
2047
- }
2048
- } else {
2049
- nst && $set(origin, key, {});
2050
- }
2051
-
2052
- origin[key] = deepExtend(origin[key], clone, mode);
2053
- } else {
2054
- $set(origin, key, clone);
2055
-
2056
- if (!is.Undef(clone)) {
2057
- if (!is.Undef(clone.__json)) {
2058
- origin[key].__json = clone.__json;
2059
- }
2060
-
2061
- if (!is.Undef(clone.__origin)) {
2062
- origin[key].__origin = clone.__origin;
2063
- }
2064
- }
2065
- }
2066
- }
2067
- }
2068
-
2069
- return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
2070
- return !v || !v.__ctrl;
2071
- }) : origin;
2072
- }
2073
- function deepCopy(value) {
2074
- return deepExtend({}, {
2075
- value: value
2076
- }).value;
2077
- }
2078
-
2079
2162
  function format(type, msg, rule) {
2080
2163
  return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2081
2164
  }
@@ -2233,14 +2316,14 @@ function makeSlotBag() {
2233
2316
  if (!slotBag[slot]) slotBag[slot] = [];
2234
2317
  slotBag[slot].push(vnFn);
2235
2318
  },
2236
- getSlot: function getSlot(slot) {
2319
+ getSlot: function getSlot(slot, val) {
2237
2320
  slot = slotName(slot);
2238
2321
  var children = [];
2239
2322
  (slotBag[slot] || []).forEach(function (fn) {
2240
2323
  if (Array.isArray(fn)) {
2241
2324
  children.push.apply(children, _toConsumableArray(fn));
2242
2325
  } else if (is.Function(fn)) {
2243
- var res = fn();
2326
+ var res = fn.apply(void 0, _toConsumableArray(val || []));
2244
2327
 
2245
2328
  if (Array.isArray(res)) {
2246
2329
  children.push.apply(children, _toConsumableArray(res));
@@ -2259,7 +2342,11 @@ function makeSlotBag() {
2259
2342
  var slots = {};
2260
2343
  Object.keys(slotBag).forEach(function (k) {
2261
2344
  slots[k] = function () {
2262
- return _this.getSlot(k);
2345
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2346
+ args[_key] = arguments[_key];
2347
+ }
2348
+
2349
+ return _this.getSlot(k, args);
2263
2350
  };
2264
2351
  });
2265
2352
  return slots;
@@ -2683,6 +2770,25 @@ function Api(h) {
2683
2770
  return origin ? ctx.origin : ctx.rule;
2684
2771
  }
2685
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
+ },
2686
2792
  updateValidate: function updateValidate(id, validate, merge) {
2687
2793
  if (merge) {
2688
2794
  api.mergeRule(id, {
@@ -2985,6 +3091,25 @@ function useRender$1(Render) {
2985
3091
  }
2986
3092
 
2987
3093
  vn = function vn() {
3094
+ for (var _len = arguments.length, slotValue = new Array(_len), _key = 0; _key < _len; _key++) {
3095
+ slotValue[_key] = arguments[_key];
3096
+ }
3097
+
3098
+ var inject = {
3099
+ rule: rule,
3100
+ prop: prop,
3101
+ preview: preview,
3102
+ api: _this4.$handle.api,
3103
+ model: prop.model || {},
3104
+ slotValue: slotValue
3105
+ };
3106
+
3107
+ if (slotValue.length && rule.slotUpdate) {
3108
+ invoke(function () {
3109
+ return rule.slotUpdate(inject);
3110
+ });
3111
+ }
3112
+
2988
3113
  var children = {};
2989
3114
 
2990
3115
  var _load = ctx.loadChildrenPending();
@@ -3000,14 +3125,8 @@ function useRender$1(Render) {
3000
3125
  var _vn;
3001
3126
 
3002
3127
  if (slot) {
3003
- _vn = slot({
3004
- rule: rule,
3005
- prop: prop,
3006
- preview: preview,
3007
- children: children,
3008
- api: _this4.$handle.api,
3009
- model: prop.model || {}
3010
- });
3128
+ inject.children = children;
3129
+ _vn = slot(inject);
3011
3130
  } else {
3012
3131
  _vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
3013
3132
  }
@@ -3086,11 +3205,15 @@ function useRender$1(Render) {
3086
3205
  subForm: function subForm(_subForm) {
3087
3206
  _this6.$handle.addSubForm(ctx, _subForm);
3088
3207
  },
3208
+ getSubForm: function getSubForm() {
3209
+ return _this6.$handle.subForm[ctx.id];
3210
+ },
3089
3211
  options: [],
3090
3212
  children: [],
3091
3213
  preview: false,
3092
3214
  field: ctx.field,
3093
- rule: ctx.rule
3215
+ rule: ctx.rule,
3216
+ input: ctx.input
3094
3217
  };
3095
3218
  }
3096
3219
 
@@ -3125,12 +3248,17 @@ function useRender$1(Render) {
3125
3248
 
3126
3249
  if (!custom && ctx.input) {
3127
3250
  var field = this.getModelField(ctx);
3128
- props.push({
3129
- on: _defineProperty({}, "update:".concat(field), function update(value) {
3251
+ var model = {
3252
+ callback: function callback(value) {
3130
3253
  _this7.onInput(ctx, value);
3131
- }),
3132
- props: _defineProperty({}, field, this.$handle.getFormData(ctx))
3254
+ },
3255
+ value: this.$handle.getFormData(ctx)
3256
+ };
3257
+ props.push({
3258
+ on: _defineProperty({}, "update:".concat(field), model.callback),
3259
+ props: _defineProperty({}, field, model.value)
3133
3260
  });
3261
+ ctx.prop.model = model;
3134
3262
  }
3135
3263
 
3136
3264
  mergeProps(props, ctx.prop);
@@ -4183,9 +4311,7 @@ function useInput(Handler) {
4183
4311
  delete this.appendData[rule.field];
4184
4312
  },
4185
4313
  addSubForm: function addSubForm(ctx, subForm) {
4186
- if (ctx.input) {
4187
- this.subForm[ctx.id] = subForm;
4188
- }
4314
+ this.subForm[ctx.id] = subForm;
4189
4315
  },
4190
4316
  deferSyncValue: function deferSyncValue(fn, sync) {
4191
4317
  if (!this.deferSyncFn) {
@@ -4364,10 +4490,10 @@ function useContext(Handler) {
4364
4490
  watchCtx: function watchCtx(ctx) {
4365
4491
  var _this = this;
4366
4492
 
4367
- var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update'];
4493
+ var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'slotUpdate'];
4368
4494
  var all = attrs();
4369
4495
  all.filter(function (k) {
4370
- return k[0] !== '_' && none.indexOf(k) === -1;
4496
+ return k[0] !== '_' && k[0] !== '$' && none.indexOf(k) === -1;
4371
4497
  }).forEach(function (key) {
4372
4498
  var ref = toRef(ctx.rule, key);
4373
4499
  var flag = key === 'children';
@@ -4572,10 +4698,21 @@ function useEffect(Handler) {
4572
4698
  watchEffect: function watchEffect(ctx) {
4573
4699
  var _this3 = this;
4574
4700
 
4701
+ var effect = {};
4575
4702
  Object.keys(ctx.rule.effect || {}).forEach(function (k) {
4576
- ctx.watch.push(watch(function () {
4703
+ effect[k] = function () {
4577
4704
  return ctx.rule.effect[k];
4578
- }, function (n) {
4705
+ };
4706
+ });
4707
+ Object.keys(ctx.rule).forEach(function (k) {
4708
+ if (k[0] === '$') {
4709
+ effect[k.substr(1)] = function () {
4710
+ return ctx.rule[k];
4711
+ };
4712
+ }
4713
+ });
4714
+ Object.keys(effect).forEach(function (k) {
4715
+ ctx.watch.push(watch(effect[k], function (n) {
4579
4716
  _this3.effect(ctx, 'watch', _defineProperty({}, k, n));
4580
4717
  }, {
4581
4718
  deep: true
@@ -4599,7 +4736,12 @@ function useEffect(Handler) {
4599
4736
  }, event);
4600
4737
  },
4601
4738
  getEffect: function getEffect(rule, name) {
4602
- if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];else return undefined;
4739
+ if (hasProperty(rule, '$' + name)) {
4740
+ return rule['$' + name];
4741
+ }
4742
+
4743
+ if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];
4744
+ return undefined;
4603
4745
  },
4604
4746
  emitEffect: function emitEffect(_ref, event, append) {
4605
4747
  var _this4 = this;
@@ -4610,7 +4752,13 @@ function useEffect(Handler) {
4610
4752
  type = _ref.type,
4611
4753
  custom = _ref.custom;
4612
4754
  if (!type || ['fcFragment', 'fragment'].indexOf(type) > -1) return;
4613
- var effect = custom ? custom : rule.effect || {};
4755
+ var effect = custom ? custom : Object.keys(rule).reduce(function (i, k) {
4756
+ if (k[0] === '$') {
4757
+ i[k.substr(1)] = rule[k];
4758
+ }
4759
+
4760
+ return i;
4761
+ }, _objectSpread2({}, rule.effect || {}));
4614
4762
  Object.keys(effect).forEach(function (attr) {
4615
4763
  var p = _this4.providers[attr];
4616
4764
  if (!p || p.input && !input) return;
@@ -5045,6 +5193,10 @@ function run(inject, rule, api) {
5045
5193
  return true;
5046
5194
  }
5047
5195
 
5196
+ var $provider = {
5197
+ fetch: $fetch
5198
+ };
5199
+
5048
5200
  var name$6 = 'html';
5049
5201
  var html = {
5050
5202
  name: name$6,
@@ -5104,9 +5256,9 @@ function FormCreateFactory(config) {
5104
5256
  var directives = {};
5105
5257
  var modelFields = {};
5106
5258
  var useApps = [];
5107
- var providers = {
5108
- fetch: $fetch
5109
- };
5259
+
5260
+ var providers = _objectSpread2({}, $provider);
5261
+
5110
5262
  var maker = makerFactory();
5111
5263
  var globalConfig = {
5112
5264
  global: {}
@@ -5116,7 +5268,9 @@ function FormCreateFactory(config) {
5116
5268
  exportAttrs(config.attrs || {});
5117
5269
 
5118
5270
  function getApi(name) {
5119
- return instance[name];
5271
+ var val = instance[name];
5272
+ if (Array.isArray(val)) return _toConsumableArray(val);
5273
+ return val;
5120
5274
  }
5121
5275
 
5122
5276
  function useApp(fn) {
@@ -5213,8 +5367,25 @@ function FormCreateFactory(config) {
5213
5367
  return vm.$refs.fc.fapi;
5214
5368
  }
5215
5369
 
5216
- function factory() {
5217
- return FormCreateFactory(config);
5370
+ function factory(inherit) {
5371
+ var _config = _objectSpread2({}, config);
5372
+
5373
+ if (inherit) {
5374
+ _config.inherit = {
5375
+ components: components,
5376
+ parsers: parsers,
5377
+ directives: directives,
5378
+ modelFields: modelFields,
5379
+ providers: providers,
5380
+ useApps: useApps,
5381
+ maker: maker,
5382
+ data: data
5383
+ };
5384
+ } else {
5385
+ delete _config.inherit;
5386
+ }
5387
+
5388
+ return FormCreateFactory(_config);
5218
5389
  }
5219
5390
 
5220
5391
  function setModelField(name, field) {
@@ -5234,6 +5405,7 @@ function FormCreateFactory(config) {
5234
5405
  modelFields: modelFields,
5235
5406
  rules: vm.props.rule,
5236
5407
  name: vm.props.name,
5408
+ inFor: vm.props.inFor,
5237
5409
  prop: {
5238
5410
  components: components,
5239
5411
  directives: directives
@@ -5260,7 +5432,12 @@ function FormCreateFactory(config) {
5260
5432
  this.$handle = new Handler(this);
5261
5433
 
5262
5434
  if (this.name) {
5263
- 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
+ }
5264
5441
  }
5265
5442
  }
5266
5443
 
@@ -5328,7 +5505,12 @@ function FormCreateFactory(config) {
5328
5505
  },
5329
5506
  unmount: function unmount() {
5330
5507
  if (this.name) {
5331
- 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
+ }
5332
5514
  }
5333
5515
 
5334
5516
  this.unwatch && this.unwatch();
@@ -5407,6 +5589,19 @@ function FormCreateFactory(config) {
5407
5589
  });
5408
5590
  });
5409
5591
  parser(html);
5592
+
5593
+ if (config.inherit) {
5594
+ var inherit = config.inherit;
5595
+ inherit.components && extend(components, inherit.components);
5596
+ inherit.parsers && extend(parsers, inherit.parsers);
5597
+ inherit.directives && extend(directives, inherit.directives);
5598
+ inherit.modelFields && extend(modelFields, inherit.modelFields);
5599
+ inherit.providers && extend(providers, inherit.providers);
5600
+ inherit.useApps && extend(useApps, inherit.useApps);
5601
+ inherit.maker && extend(maker, inherit.maker);
5602
+ inherit.data && extend(data, inherit.data);
5603
+ }
5604
+
5410
5605
  return create;
5411
5606
  }
5412
5607
 
@@ -6168,11 +6363,57 @@ function extendApi(api, h) {
6168
6363
  return api;
6169
6364
  }
6170
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
+
6171
6411
  function install(FormCreate) {
6172
6412
  FormCreate.componentAlias(alias);
6173
6413
  components.forEach(function (component) {
6174
6414
  FormCreate.component(component.name, component);
6175
6415
  });
6416
+ FormCreate.register(required);
6176
6417
  parsers.forEach(function (parser) {
6177
6418
  FormCreate.parser(parser);
6178
6419
  });
@@ -6190,7 +6431,7 @@ function install(FormCreate) {
6190
6431
  function elmFormCreate() {
6191
6432
  return FormCreateFactory({
6192
6433
  ui: 'element-ui',
6193
- version: '3.1.2',
6434
+ version: '3.1.4',
6194
6435
  manager: manager,
6195
6436
  extendApi: extendApi,
6196
6437
  install: install,