@form-create/element-ui 3.1.12 → 3.1.13

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.12
2
+ * @form-create/element-ui v3.1.13
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1792,31 +1792,27 @@ var Group = defineComponent({
1792
1792
  "span": button ? 20 : 24
1793
1793
  }, {
1794
1794
  "default": function _default() {
1795
- return [createVNode(resolveComponent("ElFormItem"), null, {
1796
- "default": function _default() {
1797
- return [createVNode(Type, {
1798
- "key": key,
1799
- "inFor": true,
1800
- "onUpdate:modelValue": function onUpdateModelValue(formData) {
1801
- return _this9.formData(key, formData);
1802
- },
1803
- "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1804
- "onEmit-event": function onEmitEvent(name) {
1805
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1806
- args[_key - 1] = arguments[_key];
1807
- }
1808
-
1809
- return _this9.emitEvent(name, args, index, key);
1810
- },
1811
- "onUpdate:api": function onUpdateApi($f) {
1812
- return _this9.add$f(index, key, $f);
1813
- },
1814
- "rule": rule,
1815
- "option": options,
1816
- "extendOption": true
1817
- }, null)];
1818
- }
1819
- })];
1795
+ return [createVNode(Type, {
1796
+ "key": key,
1797
+ "inFor": true,
1798
+ "onUpdate:modelValue": function onUpdateModelValue(formData) {
1799
+ return _this9.formData(key, formData);
1800
+ },
1801
+ "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
1802
+ "onEmit-event": function onEmitEvent(name) {
1803
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1804
+ args[_key - 1] = arguments[_key];
1805
+ }
1806
+
1807
+ return _this9.emitEvent(name, args, index, key);
1808
+ },
1809
+ "onUpdate:api": function onUpdateApi($f) {
1810
+ return _this9.add$f(index, key, $f);
1811
+ },
1812
+ "rule": rule,
1813
+ "option": options,
1814
+ "extendOption": true
1815
+ }, null)];
1820
1816
  }
1821
1817
  }), button ? createVNode(resolveComponent("ElCol"), {
1822
1818
  "span": 2,
@@ -2080,10 +2076,12 @@ function $FormCreate(FormCreate) {
2080
2076
  }, function (n) {
2081
2077
  fc.initOptions(n);
2082
2078
  fapi.refresh();
2079
+ }, {
2080
+ deep: true
2083
2081
  });
2084
2082
  watch(modelValue, function (n) {
2085
2083
  if (JSON.stringify(n || {}) === data.updateValue) return;
2086
- fapi.setValue(n || {});
2084
+ fapi.config.forceCoverValue ? fapi.coverValue(n || {}) : fapi.setValue(n || {});
2087
2085
  }, {
2088
2086
  deep: true
2089
2087
  });
@@ -2299,7 +2297,13 @@ function mergeRule(rule, merge) {
2299
2297
  return rule;
2300
2298
  }
2301
2299
  function getRule(rule) {
2302
- return is.Function(rule.getRule) ? rule.getRule() : rule;
2300
+ var r = is.Function(rule.getRule) ? rule.getRule() : rule;
2301
+
2302
+ if (!r.type) {
2303
+ r.type = 'input';
2304
+ }
2305
+
2306
+ return r;
2303
2307
  }
2304
2308
  function mergeGlobal(target, merge) {
2305
2309
  if (!target) return merge;
@@ -2578,15 +2582,21 @@ function Api(h) {
2578
2582
  return copy(ctx.rule.value);
2579
2583
  },
2580
2584
  coverValue: function coverValue(formData) {
2585
+ var data = _objectSpread2({}, formData || {});
2586
+
2581
2587
  h.deferSyncValue(function () {
2582
2588
  api.fields().forEach(function (key) {
2583
2589
  var ctxs = h.fieldCtx[key];
2584
- if (!ctxs) return h.appendData[key] = formData[key];
2585
- var flag = hasProperty(formData, key);
2586
- ctxs.forEach(function (ctx) {
2587
- ctx.rule.value = flag ? formData[key] : undefined;
2588
- });
2590
+
2591
+ if (ctxs) {
2592
+ var flag = hasProperty(formData, key);
2593
+ ctxs.forEach(function (ctx) {
2594
+ ctx.rule.value = flag ? formData[key] : undefined;
2595
+ });
2596
+ delete data[key];
2597
+ }
2589
2598
  });
2599
+ extend(h.appendData, data);
2590
2600
  });
2591
2601
  },
2592
2602
  setValue: function setValue(field) {
@@ -2819,6 +2829,18 @@ function Api(h) {
2819
2829
  $set(ctx.rule.effect, attr, value);
2820
2830
  }
2821
2831
  },
2832
+ clearEffectData: function clearEffectData(id, attr) {
2833
+ var ctx = h.getCtx(id);
2834
+
2835
+ if (ctx) {
2836
+ if (attr && attr[0] === '$') {
2837
+ attr = attr.substr(1);
2838
+ }
2839
+
2840
+ ctx.clearEffectData(attr);
2841
+ api.sync(id);
2842
+ }
2843
+ },
2822
2844
  updateValidate: function updateValidate(id, validate, merge) {
2823
2845
  if (merge) {
2824
2846
  api.mergeRule(id, {
@@ -3628,7 +3650,7 @@ function bind(ctx) {
3628
3650
  });
3629
3651
  }
3630
3652
 
3631
- function RuleContext(handle, rule) {
3653
+ function RuleContext(handle, rule, defaultValue) {
3632
3654
  var id = uniqueId();
3633
3655
  var isInput = !!rule.field;
3634
3656
  extend(this, {
@@ -3652,7 +3674,7 @@ function RuleContext(handle, rule) {
3652
3674
  refRule: {},
3653
3675
  input: isInput,
3654
3676
  el: undefined,
3655
- defaultValue: isInput ? deepCopy(rule.value) : undefined,
3677
+ defaultValue: isInput ? deepCopy(defaultValue) : undefined,
3656
3678
  field: rule.field || undefined
3657
3679
  });
3658
3680
  this.updateType();
@@ -3765,7 +3787,11 @@ extend(RuleContext.prototype, {
3765
3787
  return this.payload[name];
3766
3788
  },
3767
3789
  clearEffectData: function clearEffectData(name) {
3768
- delete this.payload[name];
3790
+ if (name === undefined) {
3791
+ this.payload = {};
3792
+ } else {
3793
+ delete this.payload[name];
3794
+ }
3769
3795
  },
3770
3796
  updateKey: function updateKey(flag) {
3771
3797
  this.key = uniqueId();
@@ -4026,7 +4052,6 @@ function useLoader(Handler) {
4026
4052
  rules.map(function (_rule, index) {
4027
4053
  if (parent && (is.String(_rule) || is.Undef(_rule))) return;
4028
4054
  if (!_this6.pageEnd && !parent && index >= _this6.first) return;
4029
- if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
4030
4055
 
4031
4056
  if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
4032
4057
  loadChildren(_rule.__fc__.loadChildrenPending(), _rule.__fc__);
@@ -4050,9 +4075,11 @@ function useLoader(Handler) {
4050
4075
  var ctx;
4051
4076
  var isCopy = false;
4052
4077
  var isInit = !!_rule.__fc__;
4078
+ var defaultValue = rule.value;
4053
4079
 
4054
4080
  if (isInit) {
4055
4081
  ctx = _rule.__fc__;
4082
+ defaultValue = ctx.defaultValue;
4056
4083
  var check = !ctx.check(_this6);
4057
4084
 
4058
4085
  if (ctx.deleted) {
@@ -4077,7 +4104,9 @@ function useLoader(Handler) {
4077
4104
  }
4078
4105
 
4079
4106
  if (!ctx) {
4080
- ctx = new RuleContext(_this6, _this6.parseRule(_rule));
4107
+ var _rule2 = _this6.parseRule(_rule);
4108
+
4109
+ ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
4081
4110
 
4082
4111
  _this6.bindParser(ctx);
4083
4112
  } else {
@@ -4775,6 +4804,11 @@ function useEffect(Handler) {
4775
4804
  var ps = this.fc.providers;
4776
4805
  Object.keys(ps).forEach(function (k) {
4777
4806
  var prop = ps[k];
4807
+
4808
+ if (is.Function(prop)) {
4809
+ prop = prop(_this.fc);
4810
+ }
4811
+
4778
4812
  prop._c = getComponent(prop);
4779
4813
 
4780
4814
  _this.onEffect(prop);
@@ -5008,7 +5042,7 @@ function getBody(xhr) {
5008
5042
  }
5009
5043
  }
5010
5044
 
5011
- function fetch(option) {
5045
+ function fetch$1(option) {
5012
5046
  if (typeof XMLHttpRequest === 'undefined') {
5013
5047
  return;
5014
5048
  }
@@ -5221,97 +5255,103 @@ extend(Manager.prototype, {
5221
5255
  render: function render(children) {}
5222
5256
  });
5223
5257
 
5224
- var $fetch = {
5225
- name: 'fetch',
5226
- loaded: function loaded() {
5227
- run.apply(void 0, arguments);
5228
- },
5229
- watch: function watch(inject, rule, api) {
5230
- if (!run(inject, rule, api)) {
5231
- inject.clearProp();
5232
- api.sync(rule);
5258
+ var fetch = function fetch(fc) {
5259
+ function parseOpt(option) {
5260
+ if (is.String(option)) {
5261
+ option = {
5262
+ action: option,
5263
+ to: 'options'
5264
+ };
5233
5265
  }
5234
- }
5235
- };
5236
5266
 
5237
- function parseOpt(option) {
5238
- if (is.String(option)) {
5239
- option = {
5240
- action: option,
5241
- to: 'options'
5242
- };
5267
+ return option;
5243
5268
  }
5244
5269
 
5245
- return option;
5246
- }
5270
+ function run(inject, rule, api) {
5271
+ var option = inject.value;
5247
5272
 
5248
- function run(inject, rule, api) {
5249
- var option = inject.value;
5273
+ if (is.Function(option)) {
5274
+ option = option(rule, api);
5275
+ }
5250
5276
 
5251
- if (is.Function(option)) {
5252
- option = option(rule, api);
5253
- }
5277
+ option = parseOpt(option);
5254
5278
 
5255
- option = parseOpt(option);
5279
+ if (!option || !option.action) {
5280
+ return false;
5281
+ }
5256
5282
 
5257
- if (!option || !option.action) {
5258
- return false;
5259
- }
5283
+ if (!option.to) {
5284
+ option.to = 'options';
5285
+ }
5260
5286
 
5261
- if (!option.to) {
5262
- option.to = 'options';
5263
- }
5287
+ var _onError = option.onError;
5264
5288
 
5265
- var _onError = option.onError;
5289
+ var check = function check() {
5290
+ if (!inject.getValue()) {
5291
+ inject.clearProp();
5292
+ api.sync(rule);
5293
+ return true;
5294
+ }
5295
+ };
5266
5296
 
5267
- var check = function check() {
5268
- if (!inject.getValue()) {
5269
- inject.clearProp();
5270
- api.sync(rule);
5271
- return true;
5272
- }
5273
- };
5297
+ var set = function set(val) {
5298
+ if (val === undefined) {
5299
+ inject.clearProp();
5300
+ api.sync(rule);
5301
+ } else {
5302
+ deepSet(inject.getProp(), option.to, val);
5303
+ }
5304
+ };
5274
5305
 
5275
- var set = function set(val) {
5276
- if (val === undefined) {
5277
- inject.clearProp();
5278
- api.sync(rule);
5279
- } else {
5280
- deepSet(inject.getProp(), option.to, val);
5281
- }
5282
- };
5306
+ invoke(function () {
5307
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5308
+ onSuccess: function onSuccess(body) {
5309
+ if (check()) return;
5283
5310
 
5284
- invoke(function () {
5285
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
5286
- onSuccess: function onSuccess(body) {
5287
- if (check()) return;
5311
+ var fn = function fn(v) {
5312
+ return v.data;
5313
+ };
5288
5314
 
5289
- var fn = function fn(v) {
5290
- return v.data;
5291
- };
5315
+ if (is.Function(option.parse)) {
5316
+ fn = option.parse;
5317
+ }
5318
+
5319
+ set(fn(body, rule, api));
5320
+ api.sync(rule);
5321
+ },
5322
+ onError: function onError(e) {
5323
+ set(undefined);
5324
+ if (check()) return;
5292
5325
 
5293
- if (is.Function(option.parse)) {
5294
- fn = option.parse;
5326
+ (_onError || function (e) {
5327
+ return err(e.message || 'fetch fail ' + option.action);
5328
+ })(e, rule, api);
5295
5329
  }
5330
+ }), {
5331
+ inject: inject,
5332
+ rule: rule,
5333
+ api: api
5334
+ });
5335
+ });
5336
+ return true;
5337
+ }
5296
5338
 
5297
- set(fn(body, rule, api));
5339
+ return {
5340
+ name: 'fetch',
5341
+ loaded: function loaded() {
5342
+ run.apply(void 0, arguments);
5343
+ },
5344
+ watch: function watch(inject, rule, api) {
5345
+ if (!run(inject, rule, api)) {
5346
+ inject.clearProp();
5298
5347
  api.sync(rule);
5299
- },
5300
- onError: function onError(e) {
5301
- set(undefined);
5302
- if (check()) return;
5303
-
5304
- (_onError || function (e) {
5305
- return err(e.message || 'fetch fail ' + option.action);
5306
- })(e, rule, api);
5307
5348
  }
5308
- }));
5309
- });
5310
- return true;
5311
- }
5349
+ }
5350
+ };
5351
+ };
5312
5352
 
5313
5353
  var $provider = {
5314
- fetch: $fetch
5354
+ fetch: fetch
5315
5355
  };
5316
5356
 
5317
5357
  var name$6 = 'html';
@@ -5659,7 +5699,7 @@ function FormCreateFactory(config) {
5659
5699
  componentAlias: componentAlias,
5660
5700
  copyRule: copyRule,
5661
5701
  copyRules: copyRules,
5662
- fetch: fetch,
5702
+ fetch: fetch$1,
5663
5703
  $form: $form,
5664
5704
  parseFn: parseFn,
5665
5705
  parseJson: parseJson,
@@ -6568,7 +6608,7 @@ function install(FormCreate) {
6568
6608
  function elmFormCreate() {
6569
6609
  return FormCreateFactory({
6570
6610
  ui: 'element-ui',
6571
- version: '3.1.12',
6611
+ version: '3.1.13',
6572
6612
  manager: manager,
6573
6613
  extendApi: extendApi,
6574
6614
  install: install,