@form-create/element-ui 3.1.2 → 3.1.3

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.3
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
@@ -1503,6 +1599,13 @@ var Group = defineComponent({
1503
1599
  submitBtn: false,
1504
1600
  resetBtn: false
1505
1601
  };
1602
+
1603
+ if (this.defaultValue) {
1604
+ if (!options.formData) options.formData = {};
1605
+ var defVal = deepCopy(this.defaultValue);
1606
+ extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
1607
+ }
1608
+
1506
1609
  this.cacheRule[++this.len] = {
1507
1610
  rule: rule,
1508
1611
  options: options
@@ -1519,6 +1622,7 @@ var Group = defineComponent({
1519
1622
 
1520
1623
  this.cacheRule[key].$f = $f;
1521
1624
  this.subForm();
1625
+ this.formData(key, $f.formData());
1522
1626
  nextTick(function () {
1523
1627
  if (_this4.syncDisabled) {
1524
1628
  $f.disabled(_this4.disabled);
@@ -1925,27 +2029,6 @@ function $FormCreate(FormCreate) {
1925
2029
  });
1926
2030
  }
1927
2031
 
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
2032
  var normalMerge = ['props'];
1950
2033
  var toArrayMerge = ['class', 'style', 'directives'];
1951
2034
  var functionalMerge = ['on'];
@@ -2015,67 +2098,13 @@ var mergeFn = function mergeFn(fn1, fn2) {
2015
2098
  };
2016
2099
  };
2017
2100
 
2018
- var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key'];
2101
+ var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key', 'slotUpdate'];
2019
2102
  var arrayAttrs = ['validate', 'children', 'control'];
2020
2103
  var normalAttrs = ['effect'];
2021
2104
  function attrs() {
2022
2105
  return [].concat(keyAttrs, _toConsumableArray(normalMerge), _toConsumableArray(toArrayMerge), _toConsumableArray(functionalMerge), arrayAttrs, normalAttrs);
2023
2106
  }
2024
2107
 
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
2108
  function format(type, msg, rule) {
2080
2109
  return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2081
2110
  }
@@ -2233,14 +2262,14 @@ function makeSlotBag() {
2233
2262
  if (!slotBag[slot]) slotBag[slot] = [];
2234
2263
  slotBag[slot].push(vnFn);
2235
2264
  },
2236
- getSlot: function getSlot(slot) {
2265
+ getSlot: function getSlot(slot, val) {
2237
2266
  slot = slotName(slot);
2238
2267
  var children = [];
2239
2268
  (slotBag[slot] || []).forEach(function (fn) {
2240
2269
  if (Array.isArray(fn)) {
2241
2270
  children.push.apply(children, _toConsumableArray(fn));
2242
2271
  } else if (is.Function(fn)) {
2243
- var res = fn();
2272
+ var res = fn.apply(void 0, _toConsumableArray(val || []));
2244
2273
 
2245
2274
  if (Array.isArray(res)) {
2246
2275
  children.push.apply(children, _toConsumableArray(res));
@@ -2259,7 +2288,11 @@ function makeSlotBag() {
2259
2288
  var slots = {};
2260
2289
  Object.keys(slotBag).forEach(function (k) {
2261
2290
  slots[k] = function () {
2262
- return _this.getSlot(k);
2291
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2292
+ args[_key] = arguments[_key];
2293
+ }
2294
+
2295
+ return _this.getSlot(k, args);
2263
2296
  };
2264
2297
  });
2265
2298
  return slots;
@@ -2985,6 +3018,25 @@ function useRender$1(Render) {
2985
3018
  }
2986
3019
 
2987
3020
  vn = function vn() {
3021
+ for (var _len = arguments.length, slotValue = new Array(_len), _key = 0; _key < _len; _key++) {
3022
+ slotValue[_key] = arguments[_key];
3023
+ }
3024
+
3025
+ var inject = {
3026
+ rule: rule,
3027
+ prop: prop,
3028
+ preview: preview,
3029
+ api: _this4.$handle.api,
3030
+ model: prop.model || {},
3031
+ slotValue: slotValue
3032
+ };
3033
+
3034
+ if (slotValue.length && rule.slotUpdate) {
3035
+ invoke(function () {
3036
+ return rule.slotUpdate(inject);
3037
+ });
3038
+ }
3039
+
2988
3040
  var children = {};
2989
3041
 
2990
3042
  var _load = ctx.loadChildrenPending();
@@ -3000,14 +3052,8 @@ function useRender$1(Render) {
3000
3052
  var _vn;
3001
3053
 
3002
3054
  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
- });
3055
+ inject.children = children;
3056
+ _vn = slot(inject);
3011
3057
  } else {
3012
3058
  _vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
3013
3059
  }
@@ -3125,12 +3171,17 @@ function useRender$1(Render) {
3125
3171
 
3126
3172
  if (!custom && ctx.input) {
3127
3173
  var field = this.getModelField(ctx);
3128
- props.push({
3129
- on: _defineProperty({}, "update:".concat(field), function update(value) {
3174
+ var model = {
3175
+ callback: function callback(value) {
3130
3176
  _this7.onInput(ctx, value);
3131
- }),
3132
- props: _defineProperty({}, field, this.$handle.getFormData(ctx))
3177
+ },
3178
+ value: this.$handle.getFormData(ctx)
3179
+ };
3180
+ props.push({
3181
+ on: _defineProperty({}, "update:".concat(field), model.callback),
3182
+ props: _defineProperty({}, field, model.value)
3133
3183
  });
3184
+ ctx.prop.model = model;
3134
3185
  }
3135
3186
 
3136
3187
  mergeProps(props, ctx.prop);
@@ -4364,10 +4415,10 @@ function useContext(Handler) {
4364
4415
  watchCtx: function watchCtx(ctx) {
4365
4416
  var _this = this;
4366
4417
 
4367
- var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update'];
4418
+ var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update', 'slotUpdate'];
4368
4419
  var all = attrs();
4369
4420
  all.filter(function (k) {
4370
- return k[0] !== '_' && none.indexOf(k) === -1;
4421
+ return k[0] !== '_' && k[0] !== '$' && none.indexOf(k) === -1;
4371
4422
  }).forEach(function (key) {
4372
4423
  var ref = toRef(ctx.rule, key);
4373
4424
  var flag = key === 'children';
@@ -4572,10 +4623,21 @@ function useEffect(Handler) {
4572
4623
  watchEffect: function watchEffect(ctx) {
4573
4624
  var _this3 = this;
4574
4625
 
4626
+ var effect = {};
4575
4627
  Object.keys(ctx.rule.effect || {}).forEach(function (k) {
4576
- ctx.watch.push(watch(function () {
4628
+ effect[k] = function () {
4577
4629
  return ctx.rule.effect[k];
4578
- }, function (n) {
4630
+ };
4631
+ });
4632
+ Object.keys(ctx.rule).forEach(function (k) {
4633
+ if (k[0] === '$') {
4634
+ effect[k.substr(1)] = function () {
4635
+ return ctx.rule[k];
4636
+ };
4637
+ }
4638
+ });
4639
+ Object.keys(effect).forEach(function (k) {
4640
+ ctx.watch.push(watch(effect[k], function (n) {
4579
4641
  _this3.effect(ctx, 'watch', _defineProperty({}, k, n));
4580
4642
  }, {
4581
4643
  deep: true
@@ -4599,7 +4661,12 @@ function useEffect(Handler) {
4599
4661
  }, event);
4600
4662
  },
4601
4663
  getEffect: function getEffect(rule, name) {
4602
- if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];else return undefined;
4664
+ if (hasProperty(rule, '$' + name)) {
4665
+ return rule['$' + name];
4666
+ }
4667
+
4668
+ if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];
4669
+ return undefined;
4603
4670
  },
4604
4671
  emitEffect: function emitEffect(_ref, event, append) {
4605
4672
  var _this4 = this;
@@ -4610,7 +4677,13 @@ function useEffect(Handler) {
4610
4677
  type = _ref.type,
4611
4678
  custom = _ref.custom;
4612
4679
  if (!type || ['fcFragment', 'fragment'].indexOf(type) > -1) return;
4613
- var effect = custom ? custom : rule.effect || {};
4680
+ var effect = custom ? custom : Object.keys(rule).reduce(function (i, k) {
4681
+ if (k[0] === '$') {
4682
+ i[k.substr(1)] = rule[k];
4683
+ }
4684
+
4685
+ return i;
4686
+ }, _objectSpread2({}, rule.effect || {}));
4614
4687
  Object.keys(effect).forEach(function (attr) {
4615
4688
  var p = _this4.providers[attr];
4616
4689
  if (!p || p.input && !input) return;
@@ -4975,6 +5048,44 @@ var $fetch = {
4975
5048
  }
4976
5049
  }
4977
5050
  };
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
+ }
4978
5089
 
4979
5090
  function parseOpt(option) {
4980
5091
  if (is.String(option)) {
@@ -5045,6 +5156,11 @@ function run(inject, rule, api) {
5045
5156
  return true;
5046
5157
  }
5047
5158
 
5159
+ var $provider = {
5160
+ fetch: $fetch,
5161
+ required: $required
5162
+ };
5163
+
5048
5164
  var name$6 = 'html';
5049
5165
  var html = {
5050
5166
  name: name$6,
@@ -5104,9 +5220,9 @@ function FormCreateFactory(config) {
5104
5220
  var directives = {};
5105
5221
  var modelFields = {};
5106
5222
  var useApps = [];
5107
- var providers = {
5108
- fetch: $fetch
5109
- };
5223
+
5224
+ var providers = _objectSpread2({}, $provider);
5225
+
5110
5226
  var maker = makerFactory();
5111
5227
  var globalConfig = {
5112
5228
  global: {}
@@ -5213,8 +5329,25 @@ function FormCreateFactory(config) {
5213
5329
  return vm.$refs.fc.fapi;
5214
5330
  }
5215
5331
 
5216
- function factory() {
5217
- return FormCreateFactory(config);
5332
+ function factory(inherit) {
5333
+ var _config = _objectSpread2({}, config);
5334
+
5335
+ if (inherit) {
5336
+ _config.inherit = {
5337
+ components: components,
5338
+ parsers: parsers,
5339
+ directives: directives,
5340
+ modelFields: modelFields,
5341
+ providers: providers,
5342
+ useApps: useApps,
5343
+ maker: maker,
5344
+ data: data
5345
+ };
5346
+ } else {
5347
+ delete _config.inherit;
5348
+ }
5349
+
5350
+ return FormCreateFactory(_config);
5218
5351
  }
5219
5352
 
5220
5353
  function setModelField(name, field) {
@@ -5407,6 +5540,19 @@ function FormCreateFactory(config) {
5407
5540
  });
5408
5541
  });
5409
5542
  parser(html);
5543
+
5544
+ if (config.inherit) {
5545
+ var inherit = config.inherit;
5546
+ inherit.components && extend(components, inherit.components);
5547
+ inherit.parsers && extend(parsers, inherit.parsers);
5548
+ inherit.directives && extend(directives, inherit.directives);
5549
+ inherit.modelFields && extend(modelFields, inherit.modelFields);
5550
+ inherit.providers && extend(providers, inherit.providers);
5551
+ inherit.useApps && extend(useApps, inherit.useApps);
5552
+ inherit.maker && extend(maker, inherit.maker);
5553
+ inherit.data && extend(data, inherit.data);
5554
+ }
5555
+
5410
5556
  return create;
5411
5557
  }
5412
5558
 
@@ -6190,7 +6336,7 @@ function install(FormCreate) {
6190
6336
  function elmFormCreate() {
6191
6337
  return FormCreateFactory({
6192
6338
  ui: 'element-ui',
6193
- version: '3.1.2',
6339
+ version: '3.1.3',
6194
6340
  manager: manager,
6195
6341
  extendApi: extendApi,
6196
6342
  install: install,