@form-create/view-design 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/view-design v2.5.25
2
+ * @form-create/view-design 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.
@@ -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, {
@@ -2706,7 +2724,7 @@
2706
2724
 
2707
2725
  var id = 0;
2708
2726
  function uniqueId() {
2709
- return Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
2727
+ return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
2710
2728
  }
2711
2729
 
2712
2730
  function deepSet(data, idx, val) {
@@ -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);
@@ -4106,7 +4130,7 @@
4106
4130
  var _flag = is.trueArray(n);
4107
4131
  _this.deferSyncValue(function () {
4108
4132
  if (n !== o) {
4109
- _this.rmSub(o);
4133
+ _this.rmSub(o, ctx);
4110
4134
  _this.$render.initOrgChildren();
4111
4135
  }
4112
4136
  _flag && _this.loadChildren(n, ctx);
@@ -4114,6 +4138,7 @@
4114
4138
  });
4115
4139
  }
4116
4140
  _this.$render.clearCache(ctx);
4141
+ _this.refresh();
4117
4142
  _this.watching = false;
4118
4143
  }, {
4119
4144
  deep: !flag,
@@ -4122,10 +4147,10 @@
4122
4147
  });
4123
4148
  this.watchEffect(ctx);
4124
4149
  },
4125
- rmSub: function rmSub(sub) {
4150
+ rmSub: function rmSub(sub, ctx) {
4126
4151
  var _this2 = this;
4127
4152
  is.trueArray(sub) && sub.forEach(function (r) {
4128
- r && r.__fc__ && _this2.rmCtx(r.__fc__);
4153
+ r && r.__fc__ && r.__fc__.parent === ctx && _this2.rmCtx(r.__fc__);
4129
4154
  });
4130
4155
  },
4131
4156
  rmCtx: function rmCtx(ctx) {
@@ -4213,6 +4238,9 @@
4213
4238
  var ps = this.fc.providers;
4214
4239
  Object.keys(ps).forEach(function (k) {
4215
4240
  var prop = ps[k];
4241
+ if (is.Function(prop)) {
4242
+ prop = prop(_this.fc);
4243
+ }
4216
4244
  prop._c = getComponent(prop);
4217
4245
  _this.onEffect(prop);
4218
4246
  _this.providers[k] = prop;
@@ -4587,17 +4615,84 @@
4587
4615
  render: function render(children) {}
4588
4616
  });
4589
4617
 
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);
4618
+ var fetch$1 = function fetch(fc) {
4619
+ function parseOpt(option) {
4620
+ if (is.String(option)) {
4621
+ option = {
4622
+ action: option,
4623
+ to: 'options'
4624
+ };
4599
4625
  }
4626
+ return option;
4600
4627
  }
4628
+ function run(inject, rule, api) {
4629
+ var option = inject.value;
4630
+ if (is.Function(option)) {
4631
+ option = option(rule, api);
4632
+ }
4633
+ option = parseOpt(option);
4634
+ if (!option || !option.action) {
4635
+ return false;
4636
+ }
4637
+ if (!option.to) {
4638
+ option.to = 'options';
4639
+ }
4640
+ var _onError = option.onError;
4641
+ var check = function check() {
4642
+ if (!inject.getValue()) {
4643
+ inject.clearProp();
4644
+ api.sync(rule);
4645
+ return true;
4646
+ }
4647
+ };
4648
+ var set = function set(val) {
4649
+ if (val === undefined) {
4650
+ inject.clearProp();
4651
+ api.sync(rule);
4652
+ } else {
4653
+ deepSet(inject.getProp(), option.to, val);
4654
+ }
4655
+ };
4656
+ invoke(function () {
4657
+ return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4658
+ onSuccess: function onSuccess(body) {
4659
+ if (check()) return;
4660
+ var fn = function fn(v) {
4661
+ return v.data;
4662
+ };
4663
+ if (is.Function(option.parse)) {
4664
+ fn = option.parse;
4665
+ }
4666
+ set(fn(body, rule, api));
4667
+ api.sync(rule);
4668
+ },
4669
+ onError: function onError(e) {
4670
+ set(undefined);
4671
+ if (check()) return;
4672
+ (_onError || function (e) {
4673
+ return err(e.message || 'fetch fail ' + option.action);
4674
+ })(e, rule, api);
4675
+ }
4676
+ }), {
4677
+ inject: inject,
4678
+ rule: rule,
4679
+ api: api
4680
+ });
4681
+ });
4682
+ return true;
4683
+ }
4684
+ return {
4685
+ name: 'fetch',
4686
+ loaded: function loaded() {
4687
+ run.apply(void 0, arguments);
4688
+ },
4689
+ watch: function watch(inject, rule, api) {
4690
+ if (!run(inject, rule, api)) {
4691
+ inject.clearProp();
4692
+ api.sync(rule);
4693
+ }
4694
+ }
4695
+ };
4601
4696
  };
4602
4697
  var $required = {
4603
4698
  name: 'required',
@@ -4643,69 +4738,8 @@
4643
4738
  return val;
4644
4739
  }
4645
4740
  }
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
4741
  var $provider = {
4708
- fetch: $fetch,
4742
+ fetch: fetch$1,
4709
4743
  required: $required
4710
4744
  };
4711
4745
 
@@ -5853,7 +5887,7 @@
5853
5887
  function ivuFormCreate() {
5854
5888
  return FormCreateFactory({
5855
5889
  ui: "".concat("view-design"),
5856
- version: "".concat("2.5.25"),
5890
+ version: "".concat("2.5.27"),
5857
5891
  manager: manager,
5858
5892
  install: install,
5859
5893
  extendApi: extendApi,