@form-create/view-design 2.5.25 → 2.5.26

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/view-design v2.5.25
2
+ * @form-create/view-design v2.5.26
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -1673,7 +1673,7 @@
1673
1673
  "attrs": {
1674
1674
  "span": button ? 20 : 24
1675
1675
  }
1676
- }, [h("FormItem", [h(Type, helper([{
1676
+ }, [h(Type, helper([{
1677
1677
  "key": key
1678
1678
  }, {
1679
1679
  "on": {
@@ -1698,7 +1698,7 @@
1698
1698
  extendOption: true,
1699
1699
  inFor: true
1700
1700
  }
1701
- }]))])]), button ? h("Col", helper([{}, {
1701
+ }]))]), button ? h("Col", helper([{}, {
1702
1702
  "props": {
1703
1703
  span: 2,
1704
1704
  pull: 1,
@@ -1911,7 +1911,7 @@
1911
1911
  value: {
1912
1912
  handler: function handler(n) {
1913
1913
  if (JSON.stringify(n || {}) === this.updateValue) return;
1914
- this.$f.setValue(n || {});
1914
+ this.$f.config.forceCoverValue ? this.$f.coverValue(n || {}) : this.$f.setValue(n || {});
1915
1915
  },
1916
1916
  deep: true
1917
1917
  },
@@ -2151,7 +2151,11 @@
2151
2151
  return rule;
2152
2152
  }
2153
2153
  function getRule(rule) {
2154
- return is.Function(rule.getRule) ? rule.getRule() : rule;
2154
+ var r = is.Function(rule.getRule) ? rule.getRule() : rule;
2155
+ if (!r.type) {
2156
+ r.type = 'input';
2157
+ }
2158
+ return r;
2155
2159
  }
2156
2160
  function mergeGlobal(target, merge) {
2157
2161
  if (!target) return merge;
@@ -2321,15 +2325,19 @@
2321
2325
  return copy(ctx.rule.value);
2322
2326
  },
2323
2327
  coverValue: function coverValue(formData) {
2328
+ var data = _objectSpread2({}, formData || {});
2324
2329
  h.deferSyncValue(function () {
2325
2330
  api.fields().forEach(function (key) {
2326
2331
  var ctxs = h.fieldCtx[key];
2327
- if (!ctxs) return h.appendData[key] = formData[key];
2328
- var flag = hasProperty(formData, key);
2329
- ctxs.forEach(function (ctx) {
2330
- ctx.rule.value = flag ? formData[key] : undefined;
2331
- });
2332
+ if (ctxs) {
2333
+ var flag = hasProperty(data, key);
2334
+ ctxs.forEach(function (ctx) {
2335
+ ctx.rule.value = flag ? data[key] : undefined;
2336
+ });
2337
+ delete data[key];
2338
+ }
2332
2339
  });
2340
+ extend(h.appendData, data);
2333
2341
  });
2334
2342
  },
2335
2343
  setValue: function setValue(field) {
@@ -2549,6 +2557,16 @@
2549
2557
  $set(ctx.rule.effect, attr, value);
2550
2558
  }
2551
2559
  },
2560
+ clearEffectData: function clearEffectData(id, attr) {
2561
+ var ctx = h.getCtx(id);
2562
+ if (ctx) {
2563
+ if (attr && attr[0] === '$') {
2564
+ attr = attr.substr(1);
2565
+ }
2566
+ ctx.clearEffectData(attr);
2567
+ api.sync(id);
2568
+ }
2569
+ },
2552
2570
  updateValidate: function updateValidate(id, validate, merge) {
2553
2571
  if (merge) {
2554
2572
  api.mergeRule(id, {
@@ -3345,7 +3363,7 @@
3345
3363
  __fc__: enumerable(ctx, true)
3346
3364
  });
3347
3365
  }
3348
- function RuleContext(handle, rule) {
3366
+ function RuleContext(handle, rule, defaultValue) {
3349
3367
  var id = uniqueId();
3350
3368
  extend(this, {
3351
3369
  id: id,
@@ -3365,7 +3383,7 @@
3365
3383
  payload: {},
3366
3384
  input: !!rule.field,
3367
3385
  el: undefined,
3368
- defaultValue: rule.field ? deepCopy(rule.value) : undefined,
3386
+ defaultValue: rule.field ? deepCopy(defaultValue) : undefined,
3369
3387
  field: rule.field || undefined
3370
3388
  });
3371
3389
  this.updateType();
@@ -3381,7 +3399,11 @@
3381
3399
  return this.payload[name];
3382
3400
  },
3383
3401
  clearEffectData: function clearEffectData(name) {
3384
- delete this.payload[name];
3402
+ if (name === undefined) {
3403
+ this.payload = {};
3404
+ } else {
3405
+ delete this.payload[name];
3406
+ }
3385
3407
  },
3386
3408
  updateKey: function updateKey(flag) {
3387
3409
  this.key = uniqueId();
@@ -3600,7 +3622,6 @@
3600
3622
  rules.map(function (_rule, index) {
3601
3623
  if (parent && (is.String(_rule) || is.Undef(_rule))) return;
3602
3624
  if (!_this6.pageEnd && !parent && index >= _this6.first) return;
3603
- if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
3604
3625
  if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
3605
3626
  loadChildren(_rule.__fc__.rule.children, _rule.__fc__);
3606
3627
  return _rule.__fc__;
@@ -3618,8 +3639,10 @@
3618
3639
  var ctx;
3619
3640
  var isCopy = false;
3620
3641
  var isInit = !!_rule.__fc__;
3642
+ var defaultValue = rule.value;
3621
3643
  if (isInit) {
3622
3644
  ctx = _rule.__fc__;
3645
+ defaultValue = ctx.defaultValue;
3623
3646
  var check = !ctx.check(_this6);
3624
3647
  if (ctx.deleted) {
3625
3648
  if (check) {
@@ -3640,7 +3663,8 @@
3640
3663
  }
3641
3664
  }
3642
3665
  if (!ctx) {
3643
- ctx = new RuleContext(_this6, _this6.parseRule(_rule));
3666
+ var _rule2 = _this6.parseRule(_rule);
3667
+ ctx = new RuleContext(_this6, _rule2, isInit ? defaultValue : _rule2.value);
3644
3668
  _this6.bindParser(ctx);
3645
3669
  } else {
3646
3670
  if (ctx.originType !== ctx.rule.type) {
@@ -3930,7 +3954,7 @@
3930
3954
  if (this.deferSyncFn) {
3931
3955
  return this.deferSyncFn.sync = true;
3932
3956
  }
3933
- this.vm._updateValue(_objectSpread2({}, this.form));
3957
+ this.vm._updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue ? this.appendData : {}), this.form));
3934
3958
  },
3935
3959
  isChange: function isChange(ctx, value) {
3936
3960
  return JSON.stringify(ctx.rule.value, strFn) !== JSON.stringify(value === null ? undefined : value, strFn);
@@ -4213,6 +4237,9 @@
4213
4237
  var ps = this.fc.providers;
4214
4238
  Object.keys(ps).forEach(function (k) {
4215
4239
  var prop = ps[k];
4240
+ if (is.Function(prop)) {
4241
+ prop = prop(_this.fc);
4242
+ }
4216
4243
  prop._c = getComponent(prop);
4217
4244
  _this.onEffect(prop);
4218
4245
  _this.providers[k] = prop;
@@ -4587,17 +4614,84 @@
4587
4614
  render: function render(children) {}
4588
4615
  });
4589
4616
 
4590
- var $fetch = {
4591
- name: 'fetch',
4592
- loaded: function loaded() {
4593
- run.apply(void 0, arguments);
4594
- },
4595
- watch: function watch(inject, rule, api) {
4596
- if (!run(inject, rule, api)) {
4597
- inject.clearProp();
4598
- api.sync(rule);
4617
+ var fetch$1 = function fetch(fc) {
4618
+ function parseOpt(option) {
4619
+ if (is.String(option)) {
4620
+ option = {
4621
+ action: option,
4622
+ to: 'options'
4623
+ };
4599
4624
  }
4625
+ return option;
4600
4626
  }
4627
+ function run(inject, rule, api) {
4628
+ var option = inject.value;
4629
+ if (is.Function(option)) {
4630
+ option = option(rule, api);
4631
+ }
4632
+ option = parseOpt(option);
4633
+ if (!option || !option.action) {
4634
+ return false;
4635
+ }
4636
+ if (!option.to) {
4637
+ option.to = 'options';
4638
+ }
4639
+ var _onError = option.onError;
4640
+ var check = function check() {
4641
+ if (!inject.getValue()) {
4642
+ inject.clearProp();
4643
+ api.sync(rule);
4644
+ return true;
4645
+ }
4646
+ };
4647
+ var set = function set(val) {
4648
+ if (val === undefined) {
4649
+ inject.clearProp();
4650
+ api.sync(rule);
4651
+ } else {
4652
+ deepSet(inject.getProp(), option.to, val);
4653
+ }
4654
+ };
4655
+ invoke(function () {
4656
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4657
+ onSuccess: function onSuccess(body) {
4658
+ if (check()) return;
4659
+ var fn = function fn(v) {
4660
+ return v.data;
4661
+ };
4662
+ if (is.Function(option.parse)) {
4663
+ fn = option.parse;
4664
+ }
4665
+ set(fn(body, rule, api));
4666
+ api.sync(rule);
4667
+ },
4668
+ onError: function onError(e) {
4669
+ set(undefined);
4670
+ if (check()) return;
4671
+ (_onError || function (e) {
4672
+ return err(e.message || 'fetch fail ' + option.action);
4673
+ })(e, rule, api);
4674
+ }
4675
+ }), {
4676
+ inject: inject,
4677
+ rule: rule,
4678
+ api: api
4679
+ });
4680
+ });
4681
+ return true;
4682
+ }
4683
+ return {
4684
+ name: 'fetch',
4685
+ loaded: function loaded() {
4686
+ run.apply(void 0, arguments);
4687
+ },
4688
+ watch: function watch(inject, rule, api) {
4689
+ if (!run(inject, rule, api)) {
4690
+ inject.clearProp();
4691
+ api.sync(rule);
4692
+ }
4693
+ }
4694
+ };
4601
4695
  };
4602
4696
  var $required = {
4603
4697
  name: 'required',
@@ -4643,69 +4737,8 @@
4643
4737
  return val;
4644
4738
  }
4645
4739
  }
4646
- function parseOpt(option) {
4647
- if (is.String(option)) {
4648
- option = {
4649
- action: option,
4650
- to: 'options'
4651
- };
4652
- }
4653
- return option;
4654
- }
4655
- function run(inject, rule, api) {
4656
- var option = inject.value;
4657
- if (is.Function(option)) {
4658
- option = option(rule, api);
4659
- }
4660
- option = parseOpt(option);
4661
- if (!option || !option.action) {
4662
- return false;
4663
- }
4664
- if (!option.to) {
4665
- option.to = 'options';
4666
- }
4667
- var _onError = option.onError;
4668
- var check = function check() {
4669
- if (!inject.getValue()) {
4670
- inject.clearProp();
4671
- api.sync(rule);
4672
- return true;
4673
- }
4674
- };
4675
- var set = function set(val) {
4676
- if (val === undefined) {
4677
- inject.clearProp();
4678
- api.sync(rule);
4679
- } else {
4680
- deepSet(inject.getProp(), option.to, val);
4681
- }
4682
- };
4683
- invoke(function () {
4684
- return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4685
- onSuccess: function onSuccess(body) {
4686
- if (check()) return;
4687
- var fn = function fn(v) {
4688
- return v.data;
4689
- };
4690
- if (is.Function(option.parse)) {
4691
- fn = option.parse;
4692
- }
4693
- set(fn(body, rule, api));
4694
- api.sync(rule);
4695
- },
4696
- onError: function onError(e) {
4697
- set(undefined);
4698
- if (check()) return;
4699
- (_onError || function (e) {
4700
- return err(e.message || 'fetch fail ' + option.action);
4701
- })(e, rule, api);
4702
- }
4703
- }));
4704
- });
4705
- return true;
4706
- }
4707
4740
  var $provider = {
4708
- fetch: $fetch,
4741
+ fetch: fetch$1,
4709
4742
  required: $required
4710
4743
  };
4711
4744
 
@@ -5853,7 +5886,7 @@
5853
5886
  function ivuFormCreate() {
5854
5887
  return FormCreateFactory({
5855
5888
  ui: "".concat("view-design"),
5856
- version: "".concat("2.5.25"),
5889
+ version: "".concat("2.5.26"),
5857
5890
  manager: manager,
5858
5891
  install: install,
5859
5892
  extendApi: extendApi,