@form-create/element-ui 3.2.1 → 3.2.2

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.2.1
2
+ * @form-create/element-ui v3.2.2
3
3
  * (c) 2018-2024 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -2101,6 +2101,7 @@ function $FormCreate(FormCreate, components, directives) {
2101
2101
  }
2102
2102
  },
2103
2103
  extendOption: Boolean,
2104
+ driver: String,
2104
2105
  modelValue: Object,
2105
2106
  disabled: {
2106
2107
  type: Boolean,
@@ -2217,9 +2218,15 @@ function $FormCreate(FormCreate, components, directives) {
2217
2218
  var emit$form = debounce(function () {
2218
2219
  fc.bus.$emit('$loadData.$form');
2219
2220
  }, 100);
2221
+
2222
+ var emit$change = function emit$change(field) {
2223
+ fc.bus.$emit('change-$form.' + field);
2224
+ };
2225
+
2220
2226
  onMounted(function () {
2221
2227
  if (parent) {
2222
2228
  fapi.top.bus.$on('$loadData.$form', emit$topForm);
2229
+ fapi.top.bus.$on('change', emit$change);
2223
2230
  }
2224
2231
 
2225
2232
  fc.mounted();
@@ -2227,6 +2234,7 @@ function $FormCreate(FormCreate, components, directives) {
2227
2234
  onBeforeUnmount(function () {
2228
2235
  if (parent) {
2229
2236
  fapi.top.bus.$off('$loadData.$form', emit$topForm);
2237
+ fapi.top.bus.$off('change', emit$change);
2230
2238
  }
2231
2239
 
2232
2240
  styleEl && document.head.removeChild(styleEl);
@@ -3442,6 +3450,9 @@ function Api(h) {
3442
3450
  setData: function setData(id, data) {
3443
3451
  return h.fc.setData(id, data);
3444
3452
  },
3453
+ refreshData: function refreshData(id) {
3454
+ return h.fc.refreshData(id);
3455
+ },
3445
3456
  helper: {
3446
3457
  tidyFields: tidyFields,
3447
3458
  props: props
@@ -3803,7 +3814,7 @@ function useRender$1(Render) {
3803
3814
  return vn;
3804
3815
  },
3805
3816
  getModelField: function getModelField(ctx) {
3806
- return ctx.rule.modelField || ctx.parser.modelField || this.fc.modelFields[this.vNode.aliasMap[ctx.type]] || this.fc.modelFields[ctx.type] || this.fc.modelFields[ctx.originType] || 'modelValue';
3817
+ return ctx.prop.modelField || ctx.parser.modelField || this.fc.modelFields[this.vNode.aliasMap[ctx.type]] || this.fc.modelFields[ctx.type] || this.fc.modelFields[ctx.originType] || 'modelValue';
3807
3818
  },
3808
3819
  isFragment: function isFragment(ctx) {
3809
3820
  return ctx.type === 'fragment' || ctx.type === 'template';
@@ -3937,10 +3948,18 @@ function useRender$1(Render) {
3937
3948
  },
3938
3949
  defaultRender: function defaultRender(ctx, children) {
3939
3950
  var prop = ctx.prop;
3940
- if (prop.component) return this.vNode.makeComponent(prop.component, prop, children);
3951
+
3952
+ if (prop.component) {
3953
+ if (typeof prop.component === 'string') {
3954
+ return this.vNode.make(prop.component, prop, children);
3955
+ } else {
3956
+ return this.vNode.makeComponent(prop.component, prop, children);
3957
+ }
3958
+ }
3959
+
3941
3960
  if (this.vNode[ctx.type]) return this.vNode[ctx.type](prop, children);
3942
3961
  if (this.vNode[ctx.originType]) return this.vNode[ctx.originType](prop, children);
3943
- return this.vNode.make(lower(ctx.originType), prop, children);
3962
+ return this.vNode.make(lower(prop.type), prop, children);
3944
3963
  },
3945
3964
  renderRule: function renderRule(rule, children, origin) {
3946
3965
  var _this9 = this;
@@ -4137,7 +4156,9 @@ function useInject(Handler) {
4137
4156
  var _this3 = this;
4138
4157
 
4139
4158
  if (str && typeof str === 'string' && str.indexOf('{{') > -1 && str.indexOf('}}') > -1) {
4159
+ var tmp = str;
4140
4160
  var vars = extractVar(str);
4161
+ var lastVal;
4141
4162
  vars.forEach(function (v) {
4142
4163
  var split = v.split('||');
4143
4164
  var field = split[0].trim();
@@ -4145,9 +4166,14 @@ function useInject(Handler) {
4145
4166
  if (field) {
4146
4167
  var def = (split[1] || '').trim();
4147
4168
  var val = get ? get(field, def) : _this3.fc.getLoadData(field, def);
4169
+ lastVal = val;
4148
4170
  str = str.replaceAll("{{".concat(v, "}}"), val == null ? '' : val);
4149
4171
  }
4150
4172
  });
4173
+
4174
+ if (vars.length === 1 && tmp === "{{".concat(vars[0], "}}")) {
4175
+ return lastVal;
4176
+ }
4151
4177
  }
4152
4178
 
4153
4179
  return str;
@@ -5111,7 +5137,19 @@ function useInput(Handler) {
5111
5137
  var _this2 = this;
5112
5138
 
5113
5139
  var data = reactive({});
5114
- this.fields().reduce(function (initial, field) {
5140
+ var fields = this.fields();
5141
+
5142
+ if (this.options.appendValue !== false) {
5143
+ Object.keys(this.appendData).reduce(function (initial, field) {
5144
+ if (fields.indexOf(field) === -1) {
5145
+ initial[field] = toRef(_this2.appendData, field);
5146
+ }
5147
+
5148
+ return initial;
5149
+ }, data);
5150
+ }
5151
+
5152
+ fields.reduce(function (initial, field) {
5115
5153
  var ctx = _this2.getCtx(field);
5116
5154
 
5117
5155
  initial[field] = toRef(ctx.rule, 'value');
@@ -5152,7 +5190,7 @@ function useInput(Handler) {
5152
5190
  return this.deferSyncFn.sync = true;
5153
5191
  }
5154
5192
 
5155
- this.vm.setupState.updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue !== false ? this.appendData : {}), this.form));
5193
+ this.vm.setupState.updateValue(_objectSpread2({}, this.form));
5156
5194
  },
5157
5195
  isChange: function isChange(ctx, value) {
5158
5196
  return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
@@ -5224,9 +5262,17 @@ var BaseParser = {
5224
5262
  },
5225
5263
  mounted: function mounted(ctx) {},
5226
5264
  render: function render(children, ctx) {
5265
+ if (ctx.$handle.fc.renderDriver && ctx.$handle.fc.renderDriver.defaultRender) {
5266
+ return ctx.$handle.fc.renderDriver.defaultRender(ctx, children);
5267
+ }
5268
+
5227
5269
  return ctx.$render.defaultRender(ctx, children);
5228
5270
  },
5229
5271
  preview: function preview(children, ctx) {
5272
+ if (ctx.$handle.fc.renderDriver && ctx.$handle.fc.renderDriver.defaultPreview) {
5273
+ return ctx.$handle.fc.renderDriver.defaultPreview(ctx, children);
5274
+ }
5275
+
5230
5276
  return this.render(children, ctx);
5231
5277
  },
5232
5278
  mergeProp: function mergeProp(ctx) {}
@@ -5285,6 +5331,18 @@ function useContext(Handler) {
5285
5331
  },
5286
5332
  getParser: function getParser(ctx) {
5287
5333
  var list = this.fc.parsers;
5334
+ var renderDriver = this.fc.renderDriver;
5335
+
5336
+ if (renderDriver) {
5337
+ var _list = renderDriver.parsers || {};
5338
+
5339
+ var parser = _list[ctx.originType] || _list[toCase(ctx.type)] || _list[ctx.trueType];
5340
+
5341
+ if (parser) {
5342
+ return parser;
5343
+ }
5344
+ }
5345
+
5288
5346
  return list[ctx.originType] || list[toCase(ctx.type)] || list[ctx.trueType] || BaseParser;
5289
5347
  },
5290
5348
  bindParser: function bindParser(ctx) {
@@ -5482,7 +5540,7 @@ function useContext(Handler) {
5482
5540
 
5483
5541
  this.deferSyncValue(function () {
5484
5542
  o && o.forEach(function (child) {
5485
- if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx && child.__fc__.root !== n) {
5543
+ if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx) {
5486
5544
  _this2.rmCtx(child.__fc__);
5487
5545
  }
5488
5546
  });
@@ -6033,6 +6091,17 @@ extend(Manager.prototype, {
6033
6091
  }), opt, this.mergeOptionsRule);
6034
6092
  },
6035
6093
  updateOptions: function updateOptions(options) {
6094
+ var _this3 = this;
6095
+
6096
+ if (this.$handle.fc.renderDriver && this.$handle.fc.renderDriver.updateOptions) {
6097
+ invoke(function () {
6098
+ _this3.$handle.fc.renderDriver.updateOptions(options, {
6099
+ handle: _this3.$handle,
6100
+ api: _this3.$handle.api
6101
+ });
6102
+ });
6103
+ }
6104
+
6036
6105
  this.options = this.mergeOptions([options], this.getDefaultOptions());
6037
6106
  this.update();
6038
6107
  },
@@ -6070,7 +6139,18 @@ var loadData = function loadData(fc) {
6070
6139
  value = deepCopy(value);
6071
6140
  }
6072
6141
 
6073
- deepSet(inject.getProp(), attr.to || 'options', value);
6142
+ var _rule = attr.modify ? rule : inject.getProp();
6143
+
6144
+ if (attr.to === 'child') {
6145
+ if (_rule.children) {
6146
+ _rule.children[0] = value;
6147
+ } else {
6148
+ _rule.children = [value];
6149
+ }
6150
+ } else {
6151
+ deepSet(_rule, attr.to || 'options', value);
6152
+ }
6153
+
6074
6154
  api.sync(rule);
6075
6155
  }, attr.wait || 300));
6076
6156
 
@@ -6199,7 +6279,11 @@ var fetch = function fetch(fc) {
6199
6279
  }
6200
6280
  };
6201
6281
 
6202
- fetchAttr._fn[inject.id] = fc.watchLoadData(debounce(function (get) {
6282
+ fetchAttr._fn[inject.id] = fc.watchLoadData(debounce(function (get, change) {
6283
+ if (change && option.watch === false) {
6284
+ return fetchAttr._fn[inject.id]();
6285
+ }
6286
+
6203
6287
  var _option = fc.$handle.loadFetchVar(deepCopy(option), get);
6204
6288
 
6205
6289
  var config = _objectSpread2(_objectSpread2({
@@ -6257,7 +6341,7 @@ var fetch = function fetch(fc) {
6257
6341
  });
6258
6342
  });
6259
6343
  });
6260
- }, option.wait || 1000));
6344
+ }, option.wait || 600));
6261
6345
  }
6262
6346
 
6263
6347
  var fetchAttr = {
@@ -6409,6 +6493,7 @@ function FormCreateFactory(config) {
6409
6493
  var parsers = {};
6410
6494
  var directives = {};
6411
6495
  var modelFields = {};
6496
+ var drivers = {};
6412
6497
  var useApps = [];
6413
6498
  var listener = [];
6414
6499
  var extendApiFn = [config.extendApi];
@@ -6567,18 +6652,31 @@ function FormCreateFactory(config) {
6567
6652
  formulas[name] = fn;
6568
6653
  }
6569
6654
 
6570
- function emitData(id) {
6571
- Object.keys(instance).forEach(function (v) {
6572
- var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
6573
- apis.forEach(function (that) {
6574
- that.bus.$emit('$loadData.' + id);
6655
+ function setDriver(name, driver) {
6656
+ if (driver.parsers) {
6657
+ Object.keys(driver.parsers).forEach(function (k) {
6658
+ driver.parsers[k] = setPrototypeOf(driver.parsers[k], BaseParser);
6575
6659
  });
6576
- });
6660
+ }
6661
+
6662
+ driver.name = name;
6663
+ drivers[name] = driver;
6664
+ }
6665
+
6666
+ function refreshData(id) {
6667
+ if (id) {
6668
+ Object.keys(instance).forEach(function (v) {
6669
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
6670
+ apis.forEach(function (that) {
6671
+ that.bus.$emit('$loadData.' + id);
6672
+ });
6673
+ });
6674
+ }
6577
6675
  }
6578
6676
 
6579
6677
  function setData(id, data) {
6580
6678
  loadData[id] = data;
6581
- emitData(id);
6679
+ refreshData(id);
6582
6680
  }
6583
6681
 
6584
6682
  function setDataDriver(id, data) {
@@ -6622,7 +6720,7 @@ function FormCreateFactory(config) {
6622
6720
 
6623
6721
  function removeData(id) {
6624
6722
  delete loadData[id];
6625
- emitData(id);
6723
+ refreshData(id);
6626
6724
  }
6627
6725
 
6628
6726
  function on(name, callback) {
@@ -6652,13 +6750,15 @@ function FormCreateFactory(config) {
6652
6750
  components: components,
6653
6751
  directives: directives
6654
6752
  },
6753
+ drivers: drivers,
6754
+ renderDriver: null,
6655
6755
  setData: setData,
6656
6756
  getData: getData,
6657
- emitData: emitData,
6757
+ refreshData: refreshData,
6658
6758
  loadData: loadData,
6659
6759
  CreateNode: CreateNode,
6660
6760
  bus: new Mitt(),
6661
- unwatch: null,
6761
+ unwatch: [],
6662
6762
  options: ref({}),
6663
6763
  extendApiFn: extendApiFn,
6664
6764
  fetchCache: new WeakMap()
@@ -6695,7 +6795,7 @@ function FormCreateFactory(config) {
6695
6795
  var _this2 = this;
6696
6796
 
6697
6797
  if (this.isSub()) {
6698
- this.unwatch = watch(function () {
6798
+ this.unwatch.push(watch(function () {
6699
6799
  return _this2.vm.setupState.parent.setupState.fc.options.value;
6700
6800
  }, function () {
6701
6801
  _this2.initOptions();
@@ -6703,9 +6803,11 @@ function FormCreateFactory(config) {
6703
6803
  _this2.$handle.api.refresh();
6704
6804
  }, {
6705
6805
  deep: true
6706
- });
6806
+ }));
6707
6807
  }
6708
6808
 
6809
+ var driver = this.vm.setupState.parent ? this.vm.setupState.parent.setupState.fc.renderDriver : this.vm.props.driver;
6810
+ this.renderDriver = this.drivers[driver];
6709
6811
  this.initOptions();
6710
6812
  this.$handle.init();
6711
6813
  },
@@ -6752,13 +6854,26 @@ function FormCreateFactory(config) {
6752
6854
  _this3.fetchCache.set(option, res);
6753
6855
  }
6754
6856
 
6755
- _this3.bus.$emit('$loadData.$globalData');
6857
+ _this3.bus.$emit('$loadData.$globalData.' + key);
6756
6858
  } else {
6757
6859
  _this3.fetchCache["delete"](option);
6758
6860
  }
6759
- }, option.wait || 1000);
6861
+ }, option.wait || 600);
6862
+
6863
+ var _emit = function _emit(data) {
6864
+ _this3.fetchCache.set(option, {
6865
+ status: true,
6866
+ data: data
6867
+ });
6868
+
6869
+ _this3.bus.$emit('$loadData.$globalData.' + key);
6870
+ };
6760
6871
 
6761
6872
  var callback = function callback(get, change) {
6873
+ if (change && option.watch === false) {
6874
+ return unwatch();
6875
+ }
6876
+
6762
6877
  if (change) {
6763
6878
  reload();
6764
6879
  return;
@@ -6767,16 +6882,42 @@ function FormCreateFactory(config) {
6767
6882
  var options = _this3.$handle.loadFetchVar(copy$1(option), get);
6768
6883
 
6769
6884
  _this3.$handle.api.fetch(options).then(function (res) {
6770
- _this3.fetchCache.set(option, {
6771
- status: true,
6772
- data: res
6773
- });
6774
-
6775
- _this3.bus.$emit('$loadData.$globalData');
6885
+ _emit(res);
6886
+ })["catch"](function (e) {
6887
+ _emit(null);
6776
6888
  });
6777
6889
  };
6778
6890
 
6779
6891
  var unwatch = this.watchLoadData(callback);
6892
+ this.unwatch.push(unwatch);
6893
+ return val;
6894
+ }
6895
+ }
6896
+ },
6897
+ globalVarDriver: function globalVarDriver(id) {
6898
+ var _this4 = this;
6899
+
6900
+ var split = id.split('.');
6901
+ var key = split.shift();
6902
+ var option = this.options.value.globalVariable && this.options.value.globalVariable[key];
6903
+
6904
+ if (option) {
6905
+ var handle = is.Function(option) ? option : option.handle;
6906
+
6907
+ if (handle) {
6908
+ var val;
6909
+ var unwatch = this.watchLoadData(function (get, change) {
6910
+ if (change) {
6911
+ unwatch();
6912
+
6913
+ _this4.bus.$emit('$loadData.$var.' + key);
6914
+ }
6915
+
6916
+ val = invoke(function () {
6917
+ return handle(get, _this4.$handle.api);
6918
+ });
6919
+ });
6920
+ this.unwatch.push(unwatch);
6780
6921
  return val;
6781
6922
  }
6782
6923
  }
@@ -6797,6 +6938,9 @@ function FormCreateFactory(config) {
6797
6938
  } else if (key === '$globalData') {
6798
6939
  val = this.globalDataDriver(split.join('.'));
6799
6940
  split = [];
6941
+ } else if (key === '$var') {
6942
+ val = this.globalVarDriver(split.join('.'));
6943
+ split = [];
6800
6944
  } else {
6801
6945
  val = getData(id, def);
6802
6946
  split = [];
@@ -6807,11 +6951,10 @@ function FormCreateFactory(config) {
6807
6951
  }
6808
6952
  }
6809
6953
 
6810
- console.log(id, val);
6811
6954
  return val == null || val === '' ? def : val;
6812
6955
  },
6813
6956
  watchLoadData: function watchLoadData(fn) {
6814
- var _this4 = this;
6957
+ var _this5 = this;
6815
6958
 
6816
6959
  var unwatch = {};
6817
6960
 
@@ -6826,13 +6969,14 @@ function FormCreateFactory(config) {
6826
6969
  return unwatch[id].val;
6827
6970
  }
6828
6971
 
6829
- var val = _this4.getLoadData(id, def);
6830
-
6831
- var key = id.split('.').shift();
6972
+ var val = _this5.getLoadData(id, def);
6832
6973
 
6833
- var callback = function callback() {
6974
+ var split = id.split('.');
6975
+ var key = split.shift();
6976
+ var key2 = split.shift() || '';
6977
+ var callback = debounce(function () {
6834
6978
  if (key !== id) {
6835
- var temp = _this4.getLoadData(id, def);
6979
+ var temp = _this5.getLoadData(id, def);
6836
6980
 
6837
6981
  if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
6838
6982
  unwatch[id].val = temp;
@@ -6841,13 +6985,21 @@ function FormCreateFactory(config) {
6841
6985
  } else {
6842
6986
  run(true);
6843
6987
  }
6844
- };
6988
+ }, 0);
6845
6989
 
6846
- _this4.bus.$on('$loadData.' + key, callback);
6990
+ _this5.bus.$on('$loadData.' + key, callback);
6991
+
6992
+ if (key2) {
6993
+ _this5.bus.$on('$loadData.' + key + '.' + key2, callback);
6994
+ }
6847
6995
 
6848
6996
  unwatch[id] = {
6849
6997
  fn: function fn() {
6850
- _this4.bus.$off('$loadData.' + key, callback);
6998
+ _this5.bus.$off('$loadData.' + key, callback);
6999
+
7000
+ if (key2) {
7001
+ _this5.bus.$off('$loadData.' + key + '.' + key2, callback);
7002
+ }
6851
7003
  },
6852
7004
  val: val
6853
7005
  };
@@ -6855,12 +7007,16 @@ function FormCreateFactory(config) {
6855
7007
  };
6856
7008
 
6857
7009
  run(false);
6858
- return function () {
7010
+
7011
+ var un = function un() {
6859
7012
  Object.keys(unwatch).forEach(function (k) {
6860
7013
  return unwatch[k].fn();
6861
7014
  });
6862
7015
  unwatch = {};
6863
7016
  };
7017
+
7018
+ this.unwatch.push(un);
7019
+ return un;
6864
7020
  },
6865
7021
  isSub: function isSub() {
6866
7022
  return this.vm.setupState.parent && this.vm.props.extendOption;
@@ -6912,7 +7068,7 @@ function FormCreateFactory(config) {
6912
7068
  this.$handle.mounted();
6913
7069
  },
6914
7070
  unmount: function unmount() {
6915
- var _this5 = this;
7071
+ var _this6 = this;
6916
7072
 
6917
7073
  if (this.name) {
6918
7074
  if (this.inFor) {
@@ -6924,16 +7080,19 @@ function FormCreateFactory(config) {
6924
7080
  }
6925
7081
 
6926
7082
  listener.forEach(function (item) {
6927
- _this5.bus.$off(item.name, item.callback);
7083
+ _this6.bus.$off(item.name, item.callback);
6928
7084
  });
6929
- this.unwatch && this.unwatch();
7085
+ this.unwatch.forEach(function (fn) {
7086
+ return fn();
7087
+ });
7088
+ this.unwatch = [];
6930
7089
  this.$handle.reloadRule([]);
6931
7090
  },
6932
7091
  updated: function updated() {
6933
- var _this6 = this;
7092
+ var _this7 = this;
6934
7093
 
6935
7094
  this.$handle.bindNextTick(function () {
6936
- return _this6.bus.$emit('next-tick', _this6.$handle.api);
7095
+ return _this7.bus.$emit('next-tick', _this7.$handle.api);
6937
7096
  });
6938
7097
  }
6939
7098
  });
@@ -6947,11 +7106,13 @@ function FormCreateFactory(config) {
6947
7106
  setDataDriver: setDataDriver,
6948
7107
  setData: setData,
6949
7108
  removeData: removeData,
7109
+ refreshData: refreshData,
6950
7110
  maker: maker,
6951
7111
  component: component,
6952
7112
  directive: directive,
6953
7113
  setModelField: setModelField,
6954
7114
  setFormula: setFormula,
7115
+ setDriver: setDriver,
6955
7116
  register: register,
6956
7117
  $vnode: $vnode,
6957
7118
  parser: parser,
@@ -7913,7 +8074,7 @@ function install(FormCreate) {
7913
8074
  function elmFormCreate() {
7914
8075
  return FormCreateFactory({
7915
8076
  ui: 'element-ui',
7916
- version: '3.2.1',
8077
+ version: '3.2.2',
7917
8078
  manager: manager,
7918
8079
  extendApi: extendApi,
7919
8080
  install: install,