@form-create/element-ui 2.5.25 → 2.5.27

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 v2.5.25
2
+ * @form-create/element-ui v2.5.27
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1676,7 +1676,7 @@
1676
1676
  "attrs": {
1677
1677
  "span": button ? 20 : 24
1678
1678
  }
1679
- }, [h("ElFormItem", [h(Type, helper([{
1679
+ }, [h(Type, helper([{
1680
1680
  "key": key
1681
1681
  }, {
1682
1682
  "on": {
@@ -1701,7 +1701,7 @@
1701
1701
  extendOption: true,
1702
1702
  inFor: true
1703
1703
  }
1704
- }]))])]), button ? h("ElCol", helper([{}, {
1704
+ }]))]), button ? h("ElCol", helper([{}, {
1705
1705
  "props": {
1706
1706
  span: 2,
1707
1707
  pull: 1,
@@ -1904,7 +1904,7 @@
1904
1904
  value: {
1905
1905
  handler: function handler(n) {
1906
1906
  if (JSON.stringify(n || {}) === this.updateValue) return;
1907
- this.$f.setValue(n || {});
1907
+ this.$f.config.forceCoverValue ? this.$f.coverValue(n || {}) : this.$f.setValue(n || {});
1908
1908
  },
1909
1909
  deep: true
1910
1910
  },
@@ -2144,7 +2144,11 @@
2144
2144
  return rule;
2145
2145
  }
2146
2146
  function getRule(rule) {
2147
- return is.Function(rule.getRule) ? rule.getRule() : rule;
2147
+ var r = is.Function(rule.getRule) ? rule.getRule() : rule;
2148
+ if (!r.type) {
2149
+ r.type = 'input';
2150
+ }
2151
+ return r;
2148
2152
  }
2149
2153
  function mergeGlobal(target, merge) {
2150
2154
  if (!target) return merge;
@@ -2314,15 +2318,19 @@
2314
2318
  return copy(ctx.rule.value);
2315
2319
  },
2316
2320
  coverValue: function coverValue(formData) {
2321
+ var data = _objectSpread2({}, formData || {});
2317
2322
  h.deferSyncValue(function () {
2318
2323
  api.fields().forEach(function (key) {
2319
2324
  var ctxs = h.fieldCtx[key];
2320
- if (!ctxs) return h.appendData[key] = formData[key];
2321
- var flag = hasProperty(formData, key);
2322
- ctxs.forEach(function (ctx) {
2323
- ctx.rule.value = flag ? formData[key] : undefined;
2324
- });
2325
+ if (ctxs) {
2326
+ var flag = hasProperty(data, key);
2327
+ ctxs.forEach(function (ctx) {
2328
+ ctx.rule.value = flag ? data[key] : undefined;
2329
+ });
2330
+ delete data[key];
2331
+ }
2325
2332
  });
2333
+ extend(h.appendData, data);
2326
2334
  });
2327
2335
  },
2328
2336
  setValue: function setValue(field) {
@@ -2542,6 +2550,16 @@
2542
2550
  $set(ctx.rule.effect, attr, value);
2543
2551
  }
2544
2552
  },
2553
+ clearEffectData: function clearEffectData(id, attr) {
2554
+ var ctx = h.getCtx(id);
2555
+ if (ctx) {
2556
+ if (attr && attr[0] === '$') {
2557
+ attr = attr.substr(1);
2558
+ }
2559
+ ctx.clearEffectData(attr);
2560
+ api.sync(id);
2561
+ }
2562
+ },
2545
2563
  updateValidate: function updateValidate(id, validate, merge) {
2546
2564
  if (merge) {
2547
2565
  api.mergeRule(id, {
@@ -2699,7 +2717,7 @@
2699
2717
 
2700
2718
  var id = 0;
2701
2719
  function uniqueId() {
2702
- return Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
2720
+ return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
2703
2721
  }
2704
2722
 
2705
2723
  function deepSet(data, idx, val) {
@@ -3338,7 +3356,7 @@
3338
3356
  __fc__: enumerable(ctx, true)
3339
3357
  });
3340
3358
  }
3341
- function RuleContext(handle, rule) {
3359
+ function RuleContext(handle, rule, defaultValue) {
3342
3360
  var id = uniqueId();
3343
3361
  extend(this, {
3344
3362
  id: id,
@@ -3358,7 +3376,7 @@
3358
3376
  payload: {},
3359
3377
  input: !!rule.field,
3360
3378
  el: undefined,
3361
- defaultValue: rule.field ? deepCopy(rule.value) : undefined,
3379
+ defaultValue: rule.field ? deepCopy(defaultValue) : undefined,
3362
3380
  field: rule.field || undefined
3363
3381
  });
3364
3382
  this.updateType();
@@ -3374,7 +3392,11 @@
3374
3392
  return this.payload[name];
3375
3393
  },
3376
3394
  clearEffectData: function clearEffectData(name) {
3377
- delete this.payload[name];
3395
+ if (name === undefined) {
3396
+ this.payload = {};
3397
+ } else {
3398
+ delete this.payload[name];
3399
+ }
3378
3400
  },
3379
3401
  updateKey: function updateKey(flag) {
3380
3402
  this.key = uniqueId();
@@ -3593,7 +3615,6 @@
3593
3615
  rules.map(function (_rule, index) {
3594
3616
  if (parent && (is.String(_rule) || is.Undef(_rule))) return;
3595
3617
  if (!_this6.pageEnd && !parent && index >= _this6.first) return;
3596
- if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
3597
3618
  if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
3598
3619
  loadChildren(_rule.__fc__.rule.children, _rule.__fc__);
3599
3620
  return _rule.__fc__;
@@ -3611,8 +3632,10 @@
3611
3632
  var ctx;
3612
3633
  var isCopy = false;
3613
3634
  var isInit = !!_rule.__fc__;
3635
+ var defaultValue = rule.value;
3614
3636
  if (isInit) {
3615
3637
  ctx = _rule.__fc__;
3638
+ defaultValue = ctx.defaultValue;
3616
3639
  var check = !ctx.check(_this6);
3617
3640
  if (ctx.deleted) {
3618
3641
  if (check) {
@@ -3633,7 +3656,8 @@
3633
3656
  }
3634
3657
  }
3635
3658
  if (!ctx) {
3636
- ctx = new RuleContext(_this6, _this6.parseRule(_rule));
3659
+ var _rule2 = _this6.parseRule(_rule);
3660
+ ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
3637
3661
  _this6.bindParser(ctx);
3638
3662
  } else {
3639
3663
  if (ctx.originType !== ctx.rule.type) {
@@ -3923,7 +3947,7 @@
3923
3947
  if (this.deferSyncFn) {
3924
3948
  return this.deferSyncFn.sync = true;
3925
3949
  }
3926
- this.vm._updateValue(_objectSpread2({}, this.form));
3950
+ this.vm._updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue ? this.appendData : {}), this.form));
3927
3951
  },
3928
3952
  isChange: function isChange(ctx, value) {
3929
3953
  return JSON.stringify(ctx.rule.value, strFn) !== JSON.stringify(value === null ? undefined : value, strFn);
@@ -4099,7 +4123,7 @@
4099
4123
  var _flag = is.trueArray(n);
4100
4124
  _this.deferSyncValue(function () {
4101
4125
  if (n !== o) {
4102
- _this.rmSub(o);
4126
+ _this.rmSub(o, ctx);
4103
4127
  _this.$render.initOrgChildren();
4104
4128
  }
4105
4129
  _flag && _this.loadChildren(n, ctx);
@@ -4107,6 +4131,7 @@
4107
4131
  });
4108
4132
  }
4109
4133
  _this.$render.clearCache(ctx);
4134
+ _this.refresh();
4110
4135
  _this.watching = false;
4111
4136
  }, {
4112
4137
  deep: !flag,
@@ -4115,10 +4140,10 @@
4115
4140
  });
4116
4141
  this.watchEffect(ctx);
4117
4142
  },
4118
- rmSub: function rmSub(sub) {
4143
+ rmSub: function rmSub(sub, ctx) {
4119
4144
  var _this2 = this;
4120
4145
  is.trueArray(sub) && sub.forEach(function (r) {
4121
- r && r.__fc__ && _this2.rmCtx(r.__fc__);
4146
+ r && r.__fc__ && r.__fc__.parent === ctx && _this2.rmCtx(r.__fc__);
4122
4147
  });
4123
4148
  },
4124
4149
  rmCtx: function rmCtx(ctx) {
@@ -4206,6 +4231,9 @@
4206
4231
  var ps = this.fc.providers;
4207
4232
  Object.keys(ps).forEach(function (k) {
4208
4233
  var prop = ps[k];
4234
+ if (is.Function(prop)) {
4235
+ prop = prop(_this.fc);
4236
+ }
4209
4237
  prop._c = getComponent(prop);
4210
4238
  _this.onEffect(prop);
4211
4239
  _this.providers[k] = prop;
@@ -4580,17 +4608,84 @@
4580
4608
  render: function render(children) {}
4581
4609
  });
4582
4610
 
4583
- var $fetch = {
4584
- name: 'fetch',
4585
- loaded: function loaded() {
4586
- run.apply(void 0, arguments);
4587
- },
4588
- watch: function watch(inject, rule, api) {
4589
- if (!run(inject, rule, api)) {
4590
- inject.clearProp();
4591
- api.sync(rule);
4611
+ var fetch$1 = function fetch(fc) {
4612
+ function parseOpt(option) {
4613
+ if (is.String(option)) {
4614
+ option = {
4615
+ action: option,
4616
+ to: 'options'
4617
+ };
4618
+ }
4619
+ return option;
4620
+ }
4621
+ function run(inject, rule, api) {
4622
+ var option = inject.value;
4623
+ if (is.Function(option)) {
4624
+ option = option(rule, api);
4592
4625
  }
4626
+ option = parseOpt(option);
4627
+ if (!option || !option.action) {
4628
+ return false;
4629
+ }
4630
+ if (!option.to) {
4631
+ option.to = 'options';
4632
+ }
4633
+ var _onError = option.onError;
4634
+ var check = function check() {
4635
+ if (!inject.getValue()) {
4636
+ inject.clearProp();
4637
+ api.sync(rule);
4638
+ return true;
4639
+ }
4640
+ };
4641
+ var set = function set(val) {
4642
+ if (val === undefined) {
4643
+ inject.clearProp();
4644
+ api.sync(rule);
4645
+ } else {
4646
+ deepSet(inject.getProp(), option.to, val);
4647
+ }
4648
+ };
4649
+ invoke(function () {
4650
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4651
+ onSuccess: function onSuccess(body) {
4652
+ if (check()) return;
4653
+ var fn = function fn(v) {
4654
+ return v.data;
4655
+ };
4656
+ if (is.Function(option.parse)) {
4657
+ fn = option.parse;
4658
+ }
4659
+ set(fn(body, rule, api));
4660
+ api.sync(rule);
4661
+ },
4662
+ onError: function onError(e) {
4663
+ set(undefined);
4664
+ if (check()) return;
4665
+ (_onError || function (e) {
4666
+ return err(e.message || 'fetch fail ' + option.action);
4667
+ })(e, rule, api);
4668
+ }
4669
+ }), {
4670
+ inject: inject,
4671
+ rule: rule,
4672
+ api: api
4673
+ });
4674
+ });
4675
+ return true;
4593
4676
  }
4677
+ return {
4678
+ name: 'fetch',
4679
+ loaded: function loaded() {
4680
+ run.apply(void 0, arguments);
4681
+ },
4682
+ watch: function watch(inject, rule, api) {
4683
+ if (!run(inject, rule, api)) {
4684
+ inject.clearProp();
4685
+ api.sync(rule);
4686
+ }
4687
+ }
4688
+ };
4594
4689
  };
4595
4690
  var $required = {
4596
4691
  name: 'required',
@@ -4636,69 +4731,8 @@
4636
4731
  return val;
4637
4732
  }
4638
4733
  }
4639
- function parseOpt(option) {
4640
- if (is.String(option)) {
4641
- option = {
4642
- action: option,
4643
- to: 'options'
4644
- };
4645
- }
4646
- return option;
4647
- }
4648
- function run(inject, rule, api) {
4649
- var option = inject.value;
4650
- if (is.Function(option)) {
4651
- option = option(rule, api);
4652
- }
4653
- option = parseOpt(option);
4654
- if (!option || !option.action) {
4655
- return false;
4656
- }
4657
- if (!option.to) {
4658
- option.to = 'options';
4659
- }
4660
- var _onError = option.onError;
4661
- var check = function check() {
4662
- if (!inject.getValue()) {
4663
- inject.clearProp();
4664
- api.sync(rule);
4665
- return true;
4666
- }
4667
- };
4668
- var set = function set(val) {
4669
- if (val === undefined) {
4670
- inject.clearProp();
4671
- api.sync(rule);
4672
- } else {
4673
- deepSet(inject.getProp(), option.to, val);
4674
- }
4675
- };
4676
- invoke(function () {
4677
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4678
- onSuccess: function onSuccess(body) {
4679
- if (check()) return;
4680
- var fn = function fn(v) {
4681
- return v.data;
4682
- };
4683
- if (is.Function(option.parse)) {
4684
- fn = option.parse;
4685
- }
4686
- set(fn(body, rule, api));
4687
- api.sync(rule);
4688
- },
4689
- onError: function onError(e) {
4690
- set(undefined);
4691
- if (check()) return;
4692
- (_onError || function (e) {
4693
- return err(e.message || 'fetch fail ' + option.action);
4694
- })(e, rule, api);
4695
- }
4696
- }));
4697
- });
4698
- return true;
4699
- }
4700
4734
  var $provider = {
4701
- fetch: $fetch,
4735
+ fetch: fetch$1,
4702
4736
  required: $required
4703
4737
  };
4704
4738
 
@@ -5807,7 +5841,7 @@
5807
5841
  function elmFormCreate() {
5808
5842
  return FormCreateFactory({
5809
5843
  ui: "".concat("element-ui"),
5810
- version: "".concat("2.5.25"),
5844
+ version: "".concat("2.5.27"),
5811
5845
  manager: manager,
5812
5846
  extendApi: extendApi,
5813
5847
  install: install,