@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.
@@ -2105,6 +2105,7 @@
2105
2105
  }
2106
2106
  },
2107
2107
  extendOption: Boolean,
2108
+ driver: String,
2108
2109
  modelValue: Object,
2109
2110
  disabled: {
2110
2111
  type: Boolean,
@@ -2221,9 +2222,15 @@
2221
2222
  var emit$form = debounce(function () {
2222
2223
  fc.bus.$emit('$loadData.$form');
2223
2224
  }, 100);
2225
+
2226
+ var emit$change = function emit$change(field) {
2227
+ fc.bus.$emit('change-$form.' + field);
2228
+ };
2229
+
2224
2230
  vue.onMounted(function () {
2225
2231
  if (parent) {
2226
2232
  fapi.top.bus.$on('$loadData.$form', emit$topForm);
2233
+ fapi.top.bus.$on('change', emit$change);
2227
2234
  }
2228
2235
 
2229
2236
  fc.mounted();
@@ -2231,6 +2238,7 @@
2231
2238
  vue.onBeforeUnmount(function () {
2232
2239
  if (parent) {
2233
2240
  fapi.top.bus.$off('$loadData.$form', emit$topForm);
2241
+ fapi.top.bus.$off('change', emit$change);
2234
2242
  }
2235
2243
 
2236
2244
  styleEl && document.head.removeChild(styleEl);
@@ -3446,6 +3454,9 @@
3446
3454
  setData: function setData(id, data) {
3447
3455
  return h.fc.setData(id, data);
3448
3456
  },
3457
+ refreshData: function refreshData(id) {
3458
+ return h.fc.refreshData(id);
3459
+ },
3449
3460
  helper: {
3450
3461
  tidyFields: tidyFields,
3451
3462
  props: props
@@ -3807,7 +3818,7 @@
3807
3818
  return vn;
3808
3819
  },
3809
3820
  getModelField: function getModelField(ctx) {
3810
- 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';
3821
+ 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';
3811
3822
  },
3812
3823
  isFragment: function isFragment(ctx) {
3813
3824
  return ctx.type === 'fragment' || ctx.type === 'template';
@@ -3941,10 +3952,18 @@
3941
3952
  },
3942
3953
  defaultRender: function defaultRender(ctx, children) {
3943
3954
  var prop = ctx.prop;
3944
- if (prop.component) return this.vNode.makeComponent(prop.component, prop, children);
3955
+
3956
+ if (prop.component) {
3957
+ if (typeof prop.component === 'string') {
3958
+ return this.vNode.make(prop.component, prop, children);
3959
+ } else {
3960
+ return this.vNode.makeComponent(prop.component, prop, children);
3961
+ }
3962
+ }
3963
+
3945
3964
  if (this.vNode[ctx.type]) return this.vNode[ctx.type](prop, children);
3946
3965
  if (this.vNode[ctx.originType]) return this.vNode[ctx.originType](prop, children);
3947
- return this.vNode.make(lower(ctx.originType), prop, children);
3966
+ return this.vNode.make(lower(prop.type), prop, children);
3948
3967
  },
3949
3968
  renderRule: function renderRule(rule, children, origin) {
3950
3969
  var _this9 = this;
@@ -4141,7 +4160,9 @@
4141
4160
  var _this3 = this;
4142
4161
 
4143
4162
  if (str && typeof str === 'string' && str.indexOf('{{') > -1 && str.indexOf('}}') > -1) {
4163
+ var tmp = str;
4144
4164
  var vars = extractVar(str);
4165
+ var lastVal;
4145
4166
  vars.forEach(function (v) {
4146
4167
  var split = v.split('||');
4147
4168
  var field = split[0].trim();
@@ -4149,9 +4170,14 @@
4149
4170
  if (field) {
4150
4171
  var def = (split[1] || '').trim();
4151
4172
  var val = get ? get(field, def) : _this3.fc.getLoadData(field, def);
4173
+ lastVal = val;
4152
4174
  str = str.replaceAll("{{".concat(v, "}}"), val == null ? '' : val);
4153
4175
  }
4154
4176
  });
4177
+
4178
+ if (vars.length === 1 && tmp === "{{".concat(vars[0], "}}")) {
4179
+ return lastVal;
4180
+ }
4155
4181
  }
4156
4182
 
4157
4183
  return str;
@@ -5115,7 +5141,19 @@
5115
5141
  var _this2 = this;
5116
5142
 
5117
5143
  var data = vue.reactive({});
5118
- this.fields().reduce(function (initial, field) {
5144
+ var fields = this.fields();
5145
+
5146
+ if (this.options.appendValue !== false) {
5147
+ Object.keys(this.appendData).reduce(function (initial, field) {
5148
+ if (fields.indexOf(field) === -1) {
5149
+ initial[field] = vue.toRef(_this2.appendData, field);
5150
+ }
5151
+
5152
+ return initial;
5153
+ }, data);
5154
+ }
5155
+
5156
+ fields.reduce(function (initial, field) {
5119
5157
  var ctx = _this2.getCtx(field);
5120
5158
 
5121
5159
  initial[field] = vue.toRef(ctx.rule, 'value');
@@ -5156,7 +5194,7 @@
5156
5194
  return this.deferSyncFn.sync = true;
5157
5195
  }
5158
5196
 
5159
- this.vm.setupState.updateValue(_objectSpread2(_objectSpread2({}, this.options.appendValue !== false ? this.appendData : {}), this.form));
5197
+ this.vm.setupState.updateValue(_objectSpread2({}, this.form));
5160
5198
  },
5161
5199
  isChange: function isChange(ctx, value) {
5162
5200
  return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
@@ -5228,9 +5266,17 @@
5228
5266
  },
5229
5267
  mounted: function mounted(ctx) {},
5230
5268
  render: function render(children, ctx) {
5269
+ if (ctx.$handle.fc.renderDriver && ctx.$handle.fc.renderDriver.defaultRender) {
5270
+ return ctx.$handle.fc.renderDriver.defaultRender(ctx, children);
5271
+ }
5272
+
5231
5273
  return ctx.$render.defaultRender(ctx, children);
5232
5274
  },
5233
5275
  preview: function preview(children, ctx) {
5276
+ if (ctx.$handle.fc.renderDriver && ctx.$handle.fc.renderDriver.defaultPreview) {
5277
+ return ctx.$handle.fc.renderDriver.defaultPreview(ctx, children);
5278
+ }
5279
+
5234
5280
  return this.render(children, ctx);
5235
5281
  },
5236
5282
  mergeProp: function mergeProp(ctx) {}
@@ -5289,6 +5335,18 @@
5289
5335
  },
5290
5336
  getParser: function getParser(ctx) {
5291
5337
  var list = this.fc.parsers;
5338
+ var renderDriver = this.fc.renderDriver;
5339
+
5340
+ if (renderDriver) {
5341
+ var _list = renderDriver.parsers || {};
5342
+
5343
+ var parser = _list[ctx.originType] || _list[toCase(ctx.type)] || _list[ctx.trueType];
5344
+
5345
+ if (parser) {
5346
+ return parser;
5347
+ }
5348
+ }
5349
+
5292
5350
  return list[ctx.originType] || list[toCase(ctx.type)] || list[ctx.trueType] || BaseParser;
5293
5351
  },
5294
5352
  bindParser: function bindParser(ctx) {
@@ -5486,7 +5544,7 @@
5486
5544
 
5487
5545
  this.deferSyncValue(function () {
5488
5546
  o && o.forEach(function (child) {
5489
- if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx && child.__fc__.root !== n) {
5547
+ if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx) {
5490
5548
  _this2.rmCtx(child.__fc__);
5491
5549
  }
5492
5550
  });
@@ -6037,6 +6095,17 @@
6037
6095
  }), opt, this.mergeOptionsRule);
6038
6096
  },
6039
6097
  updateOptions: function updateOptions(options) {
6098
+ var _this3 = this;
6099
+
6100
+ if (this.$handle.fc.renderDriver && this.$handle.fc.renderDriver.updateOptions) {
6101
+ invoke(function () {
6102
+ _this3.$handle.fc.renderDriver.updateOptions(options, {
6103
+ handle: _this3.$handle,
6104
+ api: _this3.$handle.api
6105
+ });
6106
+ });
6107
+ }
6108
+
6040
6109
  this.options = this.mergeOptions([options], this.getDefaultOptions());
6041
6110
  this.update();
6042
6111
  },
@@ -6074,7 +6143,18 @@
6074
6143
  value = deepCopy(value);
6075
6144
  }
6076
6145
 
6077
- deepSet(inject.getProp(), attr.to || 'options', value);
6146
+ var _rule = attr.modify ? rule : inject.getProp();
6147
+
6148
+ if (attr.to === 'child') {
6149
+ if (_rule.children) {
6150
+ _rule.children[0] = value;
6151
+ } else {
6152
+ _rule.children = [value];
6153
+ }
6154
+ } else {
6155
+ deepSet(_rule, attr.to || 'options', value);
6156
+ }
6157
+
6078
6158
  api.sync(rule);
6079
6159
  }, attr.wait || 300));
6080
6160
 
@@ -6203,7 +6283,11 @@
6203
6283
  }
6204
6284
  };
6205
6285
 
6206
- fetchAttr._fn[inject.id] = fc.watchLoadData(debounce(function (get) {
6286
+ fetchAttr._fn[inject.id] = fc.watchLoadData(debounce(function (get, change) {
6287
+ if (change && option.watch === false) {
6288
+ return fetchAttr._fn[inject.id]();
6289
+ }
6290
+
6207
6291
  var _option = fc.$handle.loadFetchVar(deepCopy(option), get);
6208
6292
 
6209
6293
  var config = _objectSpread2(_objectSpread2({
@@ -6261,7 +6345,7 @@
6261
6345
  });
6262
6346
  });
6263
6347
  });
6264
- }, option.wait || 1000));
6348
+ }, option.wait || 600));
6265
6349
  }
6266
6350
 
6267
6351
  var fetchAttr = {
@@ -6413,6 +6497,7 @@
6413
6497
  var parsers = {};
6414
6498
  var directives = {};
6415
6499
  var modelFields = {};
6500
+ var drivers = {};
6416
6501
  var useApps = [];
6417
6502
  var listener = [];
6418
6503
  var extendApiFn = [config.extendApi];
@@ -6571,18 +6656,31 @@
6571
6656
  formulas[name] = fn;
6572
6657
  }
6573
6658
 
6574
- function emitData(id) {
6575
- Object.keys(instance).forEach(function (v) {
6576
- var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
6577
- apis.forEach(function (that) {
6578
- that.bus.$emit('$loadData.' + id);
6659
+ function setDriver(name, driver) {
6660
+ if (driver.parsers) {
6661
+ Object.keys(driver.parsers).forEach(function (k) {
6662
+ driver.parsers[k] = setPrototypeOf(driver.parsers[k], BaseParser);
6579
6663
  });
6580
- });
6664
+ }
6665
+
6666
+ driver.name = name;
6667
+ drivers[name] = driver;
6668
+ }
6669
+
6670
+ function refreshData(id) {
6671
+ if (id) {
6672
+ Object.keys(instance).forEach(function (v) {
6673
+ var apis = Array.isArray(instance[v]) ? instance[v] : [instance[v]];
6674
+ apis.forEach(function (that) {
6675
+ that.bus.$emit('$loadData.' + id);
6676
+ });
6677
+ });
6678
+ }
6581
6679
  }
6582
6680
 
6583
6681
  function setData(id, data) {
6584
6682
  loadData[id] = data;
6585
- emitData(id);
6683
+ refreshData(id);
6586
6684
  }
6587
6685
 
6588
6686
  function setDataDriver(id, data) {
@@ -6626,7 +6724,7 @@
6626
6724
 
6627
6725
  function removeData(id) {
6628
6726
  delete loadData[id];
6629
- emitData(id);
6727
+ refreshData(id);
6630
6728
  }
6631
6729
 
6632
6730
  function on(name, callback) {
@@ -6656,13 +6754,15 @@
6656
6754
  components: components,
6657
6755
  directives: directives
6658
6756
  },
6757
+ drivers: drivers,
6758
+ renderDriver: null,
6659
6759
  setData: setData,
6660
6760
  getData: getData,
6661
- emitData: emitData,
6761
+ refreshData: refreshData,
6662
6762
  loadData: loadData,
6663
6763
  CreateNode: CreateNode,
6664
6764
  bus: new Mitt(),
6665
- unwatch: null,
6765
+ unwatch: [],
6666
6766
  options: vue.ref({}),
6667
6767
  extendApiFn: extendApiFn,
6668
6768
  fetchCache: new WeakMap()
@@ -6699,7 +6799,7 @@
6699
6799
  var _this2 = this;
6700
6800
 
6701
6801
  if (this.isSub()) {
6702
- this.unwatch = vue.watch(function () {
6802
+ this.unwatch.push(vue.watch(function () {
6703
6803
  return _this2.vm.setupState.parent.setupState.fc.options.value;
6704
6804
  }, function () {
6705
6805
  _this2.initOptions();
@@ -6707,9 +6807,11 @@
6707
6807
  _this2.$handle.api.refresh();
6708
6808
  }, {
6709
6809
  deep: true
6710
- });
6810
+ }));
6711
6811
  }
6712
6812
 
6813
+ var driver = this.vm.setupState.parent ? this.vm.setupState.parent.setupState.fc.renderDriver : this.vm.props.driver;
6814
+ this.renderDriver = this.drivers[driver];
6713
6815
  this.initOptions();
6714
6816
  this.$handle.init();
6715
6817
  },
@@ -6756,13 +6858,26 @@
6756
6858
  _this3.fetchCache.set(option, res);
6757
6859
  }
6758
6860
 
6759
- _this3.bus.$emit('$loadData.$globalData');
6861
+ _this3.bus.$emit('$loadData.$globalData.' + key);
6760
6862
  } else {
6761
6863
  _this3.fetchCache["delete"](option);
6762
6864
  }
6763
- }, option.wait || 1000);
6865
+ }, option.wait || 600);
6866
+
6867
+ var _emit = function _emit(data) {
6868
+ _this3.fetchCache.set(option, {
6869
+ status: true,
6870
+ data: data
6871
+ });
6872
+
6873
+ _this3.bus.$emit('$loadData.$globalData.' + key);
6874
+ };
6764
6875
 
6765
6876
  var callback = function callback(get, change) {
6877
+ if (change && option.watch === false) {
6878
+ return unwatch();
6879
+ }
6880
+
6766
6881
  if (change) {
6767
6882
  reload();
6768
6883
  return;
@@ -6771,16 +6886,42 @@
6771
6886
  var options = _this3.$handle.loadFetchVar(copy$1(option), get);
6772
6887
 
6773
6888
  _this3.$handle.api.fetch(options).then(function (res) {
6774
- _this3.fetchCache.set(option, {
6775
- status: true,
6776
- data: res
6777
- });
6778
-
6779
- _this3.bus.$emit('$loadData.$globalData');
6889
+ _emit(res);
6890
+ })["catch"](function (e) {
6891
+ _emit(null);
6780
6892
  });
6781
6893
  };
6782
6894
 
6783
6895
  var unwatch = this.watchLoadData(callback);
6896
+ this.unwatch.push(unwatch);
6897
+ return val;
6898
+ }
6899
+ }
6900
+ },
6901
+ globalVarDriver: function globalVarDriver(id) {
6902
+ var _this4 = this;
6903
+
6904
+ var split = id.split('.');
6905
+ var key = split.shift();
6906
+ var option = this.options.value.globalVariable && this.options.value.globalVariable[key];
6907
+
6908
+ if (option) {
6909
+ var handle = is.Function(option) ? option : option.handle;
6910
+
6911
+ if (handle) {
6912
+ var val;
6913
+ var unwatch = this.watchLoadData(function (get, change) {
6914
+ if (change) {
6915
+ unwatch();
6916
+
6917
+ _this4.bus.$emit('$loadData.$var.' + key);
6918
+ }
6919
+
6920
+ val = invoke(function () {
6921
+ return handle(get, _this4.$handle.api);
6922
+ });
6923
+ });
6924
+ this.unwatch.push(unwatch);
6784
6925
  return val;
6785
6926
  }
6786
6927
  }
@@ -6801,6 +6942,9 @@
6801
6942
  } else if (key === '$globalData') {
6802
6943
  val = this.globalDataDriver(split.join('.'));
6803
6944
  split = [];
6945
+ } else if (key === '$var') {
6946
+ val = this.globalVarDriver(split.join('.'));
6947
+ split = [];
6804
6948
  } else {
6805
6949
  val = getData(id, def);
6806
6950
  split = [];
@@ -6811,11 +6955,10 @@
6811
6955
  }
6812
6956
  }
6813
6957
 
6814
- console.log(id, val);
6815
6958
  return val == null || val === '' ? def : val;
6816
6959
  },
6817
6960
  watchLoadData: function watchLoadData(fn) {
6818
- var _this4 = this;
6961
+ var _this5 = this;
6819
6962
 
6820
6963
  var unwatch = {};
6821
6964
 
@@ -6830,13 +6973,14 @@
6830
6973
  return unwatch[id].val;
6831
6974
  }
6832
6975
 
6833
- var val = _this4.getLoadData(id, def);
6834
-
6835
- var key = id.split('.').shift();
6976
+ var val = _this5.getLoadData(id, def);
6836
6977
 
6837
- var callback = function callback() {
6978
+ var split = id.split('.');
6979
+ var key = split.shift();
6980
+ var key2 = split.shift() || '';
6981
+ var callback = debounce(function () {
6838
6982
  if (key !== id) {
6839
- var temp = _this4.getLoadData(id, def);
6983
+ var temp = _this5.getLoadData(id, def);
6840
6984
 
6841
6985
  if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
6842
6986
  unwatch[id].val = temp;
@@ -6845,13 +6989,21 @@
6845
6989
  } else {
6846
6990
  run(true);
6847
6991
  }
6848
- };
6992
+ }, 0);
6849
6993
 
6850
- _this4.bus.$on('$loadData.' + key, callback);
6994
+ _this5.bus.$on('$loadData.' + key, callback);
6995
+
6996
+ if (key2) {
6997
+ _this5.bus.$on('$loadData.' + key + '.' + key2, callback);
6998
+ }
6851
6999
 
6852
7000
  unwatch[id] = {
6853
7001
  fn: function fn() {
6854
- _this4.bus.$off('$loadData.' + key, callback);
7002
+ _this5.bus.$off('$loadData.' + key, callback);
7003
+
7004
+ if (key2) {
7005
+ _this5.bus.$off('$loadData.' + key + '.' + key2, callback);
7006
+ }
6855
7007
  },
6856
7008
  val: val
6857
7009
  };
@@ -6859,12 +7011,16 @@
6859
7011
  };
6860
7012
 
6861
7013
  run(false);
6862
- return function () {
7014
+
7015
+ var un = function un() {
6863
7016
  Object.keys(unwatch).forEach(function (k) {
6864
7017
  return unwatch[k].fn();
6865
7018
  });
6866
7019
  unwatch = {};
6867
7020
  };
7021
+
7022
+ this.unwatch.push(un);
7023
+ return un;
6868
7024
  },
6869
7025
  isSub: function isSub() {
6870
7026
  return this.vm.setupState.parent && this.vm.props.extendOption;
@@ -6916,7 +7072,7 @@
6916
7072
  this.$handle.mounted();
6917
7073
  },
6918
7074
  unmount: function unmount() {
6919
- var _this5 = this;
7075
+ var _this6 = this;
6920
7076
 
6921
7077
  if (this.name) {
6922
7078
  if (this.inFor) {
@@ -6928,16 +7084,19 @@
6928
7084
  }
6929
7085
 
6930
7086
  listener.forEach(function (item) {
6931
- _this5.bus.$off(item.name, item.callback);
7087
+ _this6.bus.$off(item.name, item.callback);
6932
7088
  });
6933
- this.unwatch && this.unwatch();
7089
+ this.unwatch.forEach(function (fn) {
7090
+ return fn();
7091
+ });
7092
+ this.unwatch = [];
6934
7093
  this.$handle.reloadRule([]);
6935
7094
  },
6936
7095
  updated: function updated() {
6937
- var _this6 = this;
7096
+ var _this7 = this;
6938
7097
 
6939
7098
  this.$handle.bindNextTick(function () {
6940
- return _this6.bus.$emit('next-tick', _this6.$handle.api);
7099
+ return _this7.bus.$emit('next-tick', _this7.$handle.api);
6941
7100
  });
6942
7101
  }
6943
7102
  });
@@ -6951,11 +7110,13 @@
6951
7110
  setDataDriver: setDataDriver,
6952
7111
  setData: setData,
6953
7112
  removeData: removeData,
7113
+ refreshData: refreshData,
6954
7114
  maker: maker,
6955
7115
  component: component,
6956
7116
  directive: directive,
6957
7117
  setModelField: setModelField,
6958
7118
  setFormula: setFormula,
7119
+ setDriver: setDriver,
6959
7120
  register: register,
6960
7121
  $vnode: $vnode,
6961
7122
  parser: parser,
@@ -7917,7 +8078,7 @@
7917
8078
  function elmFormCreate() {
7918
8079
  return FormCreateFactory({
7919
8080
  ui: 'element-ui',
7920
- version: '3.2.1',
8081
+ version: '3.2.2',
7921
8082
  manager: manager,
7922
8083
  extendApi: extendApi,
7923
8084
  install: install,