@form-create/view-design 2.5.32 → 2.5.33

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.32
2
+ * @form-create/view-design v2.5.33
3
3
  * (c) 2018-2023 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -937,10 +937,7 @@
937
937
  }
938
938
  },
939
939
  render: function render(h, ctx) {
940
- var options = ctx.props.formCreateInject.options;
941
- return h("Select", helper([{}, ctx.data, {
942
- "ref": "el"
943
- }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
940
+ var makeOption = function makeOption(props, index) {
944
941
  var slot = props.slot;
945
942
  return h("Option", helper([{}, {
946
943
  "props": props
@@ -949,6 +946,22 @@
949
946
  }]), [slot ? h("template", {
950
947
  "slot": props.slotName || 'default'
951
948
  }, [is.Function(slot) ? props.slot(h) : slot]) : null]);
949
+ };
950
+ var makeOptionGroup = function makeOptionGroup(props, index) {
951
+ return h("OptionGroup", {
952
+ "attrs": {
953
+ "label": props.label
954
+ },
955
+ "key": '' + index + '-' + props.label
956
+ }, [is.trueArray(props.options) && props.options.map(function (v, index) {
957
+ return makeOption(v, index);
958
+ })]);
959
+ };
960
+ var options = ctx.props.formCreateInject.options;
961
+ return h("Select", helper([{}, ctx.data, {
962
+ "ref": "el"
963
+ }]), [(Array.isArray(options) ? options : []).map(function (props, index) {
964
+ return hasProperty(props || '', 'options') ? makeOptionGroup(props, index) : makeOption(props, index);
952
965
  }), ctx.children]);
953
966
  },
954
967
  mounted: function mounted() {
@@ -1496,9 +1509,6 @@
1496
1509
  n.forEach(function (val, i) {
1497
1510
  _this2.setValue(keys[i], n[i]);
1498
1511
  });
1499
- if (o.length && !n.length) {
1500
- this.input([]);
1501
- }
1502
1512
  }
1503
1513
  }
1504
1514
  },
@@ -1540,7 +1550,7 @@
1540
1550
  return;
1541
1551
  }
1542
1552
  this.cache(key, value);
1543
- $f.coverValue(value || {});
1553
+ $f && $f.coverValue(value || {});
1544
1554
  },
1545
1555
  addRule: function addRule(i, emit) {
1546
1556
  var _this4 = this;
@@ -3572,7 +3582,8 @@
3572
3582
  vm: handle.vm,
3573
3583
  trueType: handle.getType(this.originType),
3574
3584
  vNode: handle.$render.vNode,
3575
- updated: false
3585
+ updated: false,
3586
+ cacheValue: this.rule.value
3576
3587
  });
3577
3588
  !init && this.unwatch();
3578
3589
  this.watchTo();
@@ -3815,6 +3826,7 @@
3815
3826
  ctx.root = rules;
3816
3827
  _this6.setCtx(ctx);
3817
3828
  !isCopy && !isInit && _this6.effect(ctx, 'load');
3829
+ _this6.effect(ctx, 'created');
3818
3830
  ctx.parser.loadChildren === false || loadChildren(ctx.rule.children, ctx);
3819
3831
  if (!parent) {
3820
3832
  var _preIndex = preIndex(index);
@@ -4500,6 +4512,7 @@
4500
4512
  data.mergeProp = function (prop) {
4501
4513
  return mergeRule(data.getProp(), [prop]);
4502
4514
  };
4515
+ data.id = ctx.id;
4503
4516
  }
4504
4517
  _this4.bus.$emit("p:".concat(attr, ":").concat(_type, ":").concat(p.input ? 1 : 0), event, [data, rule, _this4.api]);
4505
4518
  });
@@ -4513,9 +4526,12 @@
4513
4526
  }
4514
4527
  function getComponent(p) {
4515
4528
  var c = p.components;
4516
- if (Array.isArray(c)) return unique(c.filter(function (v) {
4517
- return v !== '*';
4518
- }));else if (is.String(c)) return [c];else return false;
4529
+ if (Array.isArray(c)) {
4530
+ var arr = unique(c.filter(function (v) {
4531
+ return v !== '*';
4532
+ }));
4533
+ return arr.length ? arr : false;
4534
+ } else if (is.String(c)) return [c];else return false;
4519
4535
  }
4520
4536
 
4521
4537
  function Handler(fc) {
@@ -4768,6 +4784,52 @@
4768
4784
  render: function render(children) {}
4769
4785
  });
4770
4786
 
4787
+ var loadData = function loadData(fc) {
4788
+ var loadData = {
4789
+ name: 'loadData',
4790
+ _fn: [],
4791
+ created: function created(inject, rule, api) {
4792
+ this.deleted(inject);
4793
+ var attrs = toArray(inject.getValue());
4794
+ var events = [];
4795
+ attrs.forEach(function (attr) {
4796
+ if (attr) {
4797
+ var on = function on() {
4798
+ if (attr.watch !== false) {
4799
+ fc.bus.$off('p.loadData.' + attr.attr, on);
4800
+ fc.bus.$once('p.loadData.' + attr.attr, on);
4801
+ }
4802
+ var value = undefined;
4803
+ if (attr.attr) {
4804
+ value = fc.loadData[attr.attr] || attr["default"];
4805
+ if (attr.copy) {
4806
+ value = deepCopy(value);
4807
+ }
4808
+ }
4809
+ deepSet(inject.getProp(), attr.to || 'options', value);
4810
+ api.sync(rule);
4811
+ };
4812
+ events.push(function () {
4813
+ return fc.bus.$off('p.loadData.' + attr.attr, on);
4814
+ });
4815
+ on();
4816
+ }
4817
+ });
4818
+ this._fn[inject.id] = events;
4819
+ },
4820
+ deleted: function deleted(inject) {
4821
+ if (this._fn[inject.id]) {
4822
+ this._fn[inject.id].forEach(function (un) {
4823
+ un();
4824
+ });
4825
+ delete this._fn[inject.id];
4826
+ }
4827
+ inject.clearProp();
4828
+ }
4829
+ };
4830
+ loadData.watch = loadData.created;
4831
+ return loadData;
4832
+ };
4771
4833
  var componentValidate = {
4772
4834
  name: 'componentValidate',
4773
4835
  load: function load(attr, rule, api) {
@@ -4809,12 +4871,21 @@
4809
4871
  }
4810
4872
  function run(inject, rule, api) {
4811
4873
  var option = inject.value;
4874
+ var set = function set(val) {
4875
+ if (val === undefined) {
4876
+ inject.clearProp();
4877
+ api.sync(rule);
4878
+ } else {
4879
+ deepSet(inject.getProp(), option.to || 'options', val);
4880
+ }
4881
+ };
4812
4882
  if (is.Function(option)) {
4813
4883
  option = option(rule, api);
4814
4884
  }
4815
4885
  option = parseOpt(option);
4816
4886
  if (!option || !option.action) {
4817
- return false;
4887
+ set(undefined);
4888
+ return;
4818
4889
  }
4819
4890
  if (!option.to) {
4820
4891
  option.to = 'options';
@@ -4827,61 +4898,66 @@
4827
4898
  return true;
4828
4899
  }
4829
4900
  };
4830
- var set = function set(val) {
4831
- if (val === undefined) {
4832
- inject.clearProp();
4901
+ var config = _objectSpread2(_objectSpread2({
4902
+ headers: {}
4903
+ }, option), {}, {
4904
+ onSuccess: function onSuccess(body, flag) {
4905
+ if (check()) return;
4906
+ var fn = function fn(v) {
4907
+ return flag ? v : v.data;
4908
+ };
4909
+ if (is.Function(option.parse)) {
4910
+ fn = option.parse;
4911
+ } else if (option.parse && is.String(option.parse)) {
4912
+ fn = function fn(v) {
4913
+ option.parse.split('.').forEach(function (k) {
4914
+ if (v) {
4915
+ v = v[k];
4916
+ }
4917
+ });
4918
+ return v;
4919
+ };
4920
+ }
4921
+ set(fn(body, rule, api));
4833
4922
  api.sync(rule);
4834
- } else {
4835
- deepSet(inject.getProp(), option.to, val);
4923
+ },
4924
+ onError: function onError(e) {
4925
+ set(undefined);
4926
+ if (check()) return;
4927
+ (_onError || function (e) {
4928
+ return err(e.message || 'fetch fail ' + option.action);
4929
+ })(e, rule, api);
4836
4930
  }
4837
- };
4931
+ });
4932
+ fc.options.beforeFetch && invoke(function () {
4933
+ return fc.options.beforeFetch(config, {
4934
+ rule: rule,
4935
+ api: api
4936
+ });
4937
+ });
4938
+ if (is.Function(option.action)) {
4939
+ option.action(rule, api).then(function (val) {
4940
+ config.onSuccess(val, true);
4941
+ })["catch"](function (e) {
4942
+ config.onError(e);
4943
+ });
4944
+ return;
4945
+ }
4838
4946
  invoke(function () {
4839
- return fc.create.fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4840
- onSuccess: function onSuccess(body) {
4841
- if (check()) return;
4842
- var fn = function fn(v) {
4843
- return v.data;
4844
- };
4845
- if (is.Function(option.parse)) {
4846
- fn = option.parse;
4847
- } else if (option.parse && is.String(option.parse)) {
4848
- fn = function fn(v) {
4849
- option.parse.split('.').forEach(function (k) {
4850
- if (v) {
4851
- v = v[k];
4852
- }
4853
- });
4854
- return v;
4855
- };
4856
- }
4857
- set(fn(body, rule, api));
4858
- api.sync(rule);
4859
- },
4860
- onError: function onError(e) {
4861
- set(undefined);
4862
- if (check()) return;
4863
- (_onError || function (e) {
4864
- return err(e.message || 'fetch fail ' + option.action);
4865
- })(e, rule, api);
4866
- }
4867
- }), {
4947
+ return fc.create.fetch(config, {
4868
4948
  inject: inject,
4869
4949
  rule: rule,
4870
4950
  api: api
4871
4951
  });
4872
4952
  });
4873
- return true;
4874
4953
  }
4875
4954
  return {
4876
4955
  name: 'fetch',
4877
4956
  loaded: function loaded() {
4878
4957
  run.apply(void 0, arguments);
4879
4958
  },
4880
- watch: function watch(inject, rule, api) {
4881
- if (!run(inject, rule, api)) {
4882
- inject.clearProp();
4883
- api.sync(rule);
4884
- }
4959
+ watch: function watch() {
4960
+ run.apply(void 0, arguments);
4885
4961
  }
4886
4962
  };
4887
4963
  };
@@ -4935,6 +5011,7 @@
4935
5011
  }
4936
5012
  var $provider = {
4937
5013
  fetch: fetch$1,
5014
+ loadData: loadData,
4938
5015
  required: $required,
4939
5016
  componentValidate: componentValidate
4940
5017
  };
@@ -5017,13 +5094,18 @@
5017
5094
  var globalConfig = {
5018
5095
  global: {}
5019
5096
  };
5020
- var data = {};
5097
+ var loadData = {};
5021
5098
  var CreateNode = CreateNodeFactory();
5022
5099
  exportAttrs(config.attrs || {});
5023
5100
  function getApi(name) {
5024
5101
  var val = instance[name];
5025
- if (Array.isArray(val)) return _toConsumableArray(val);
5026
- return val;
5102
+ if (Array.isArray(val)) {
5103
+ return val.map(function (v) {
5104
+ return v.api();
5105
+ });
5106
+ } else if (val) {
5107
+ return val.api();
5108
+ }
5027
5109
  }
5028
5110
  function directive() {
5029
5111
  var data = nameProp.apply(void 0, arguments);
@@ -5065,6 +5147,22 @@
5065
5147
  components[name] = component;
5066
5148
  if (component.formCreateParser) parser(name, component.formCreateParser);
5067
5149
  }
5150
+ function _emitData(id) {
5151
+ Object.keys(instance).forEach(function (v) {
5152
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
5153
+ apis.forEach(function (that) {
5154
+ that.bus.$emit('p.loadData.' + id);
5155
+ });
5156
+ });
5157
+ }
5158
+ function setData(id, data) {
5159
+ loadData[id] = data;
5160
+ _emitData(id);
5161
+ }
5162
+ function removeData(id) {
5163
+ delete loadData[id];
5164
+ _emitData(id);
5165
+ }
5068
5166
  function $form() {
5069
5167
  return _vue.extend($FormCreate(FormCreate));
5070
5168
  }
@@ -5091,7 +5189,7 @@
5091
5189
  directives: directives,
5092
5190
  providers: providers,
5093
5191
  maker: maker,
5094
- data: data
5192
+ loadData: loadData
5095
5193
  };
5096
5194
  } else {
5097
5195
  delete _config.inherit;
@@ -5107,12 +5205,13 @@
5107
5205
  parsers: parsers,
5108
5206
  providers: providers,
5109
5207
  rules: Array.isArray(rules) ? rules : [],
5110
- name: vm.$options.propsData.name,
5208
+ name: vm.$options.propsData.name || uniqueId(),
5111
5209
  inFor: vm.$options.propsData.inFor,
5112
5210
  prop: {
5113
5211
  components: components,
5114
5212
  directives: directives
5115
5213
  },
5214
+ loadData: loadData,
5116
5215
  CreateNode: CreateNode,
5117
5216
  bus: new _vue(),
5118
5217
  unwatch: null,
@@ -5126,9 +5225,9 @@
5126
5225
  if (this.name) {
5127
5226
  if (this.inFor) {
5128
5227
  if (!instance[this.name]) instance[this.name] = [];
5129
- instance[this.name].push(this.api());
5228
+ instance[this.name].push(this);
5130
5229
  } else {
5131
- instance[this.name] = this.api();
5230
+ instance[this.name] = this;
5132
5231
  }
5133
5232
  }
5134
5233
  }
@@ -5163,8 +5262,11 @@
5163
5262
  h.reloadRule([]);
5164
5263
  if (_this2.name) {
5165
5264
  if (_this2.inFor) {
5166
- var idx = instance[_this2.name].indexOf(_this2.api());
5265
+ var idx = instance[_this2.name].indexOf(_this2);
5167
5266
  instance[_this2.name].splice(idx, 1);
5267
+ if (!instance[_this2.name].length) {
5268
+ delete instance[_this2.name];
5269
+ }
5168
5270
  } else {
5169
5271
  delete instance[_this2.name];
5170
5272
  }
@@ -5224,7 +5326,8 @@
5224
5326
  extend(formCreate, {
5225
5327
  version: config.version,
5226
5328
  ui: config.ui,
5227
- data: data,
5329
+ setData: setData,
5330
+ removeData: removeData,
5228
5331
  maker: maker,
5229
5332
  component: component,
5230
5333
  directive: directive,
@@ -5297,7 +5400,7 @@
5297
5400
  inherit.directives && extend(directives, inherit.directives);
5298
5401
  inherit.providers && extend(providers, inherit.providers);
5299
5402
  inherit.maker && extend(maker, inherit.maker);
5300
- inherit.data && extend(data, inherit.data);
5403
+ inherit.loadData && extend(loadData, inherit.loadData);
5301
5404
  }
5302
5405
  return create;
5303
5406
  }
@@ -6071,7 +6174,7 @@
6071
6174
  function ivuFormCreate() {
6072
6175
  return FormCreateFactory({
6073
6176
  ui: "".concat("view-design"),
6074
- version: "".concat("2.5.32"),
6177
+ version: "".concat("2.5.33"),
6075
6178
  manager: manager,
6076
6179
  install: install,
6077
6180
  extendApi: extendApi,