@form-create/element-ui 3.0.0-alpha.2 → 3.0.0-alpha.3

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.0.0-alpha.2
2
+ * @form-create/element-ui v3.0.0-alpha.3
3
3
  * (c) 2018-2021 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -234,25 +234,30 @@
234
234
  var trueValue = vue.ref([]);
235
235
  var value = vue.toRef(props, 'modelValue');
236
236
 
237
- var _options = vue.computed(function () {
238
- return Array.isArray(options) ? options : [];
239
- });
237
+ var _options = function _options() {
238
+ return Array.isArray(options.value) ? options.value : [];
239
+ };
240
240
 
241
241
  var update = function update() {
242
- trueValue.value = value.value ? _options.value.filter(function (opt) {
242
+ trueValue.value = value.value ? _options().filter(function (opt) {
243
243
  return value.value.indexOf(opt.value) !== -1;
244
244
  }).map(function (option) {
245
245
  return option.label;
246
246
  }) : [];
247
247
  };
248
248
 
249
- update();
249
+ vue.watch(options, function () {
250
+ update();
251
+ }, {
252
+ deep: true,
253
+ immediate: true
254
+ });
250
255
  return {
251
256
  options: _options,
252
257
  trueValue: trueValue,
253
258
  value: value,
254
259
  onInput: function onInput(n) {
255
- _.emit('update:modelValue', _options.value.filter(function (opt) {
260
+ _.emit('update:modelValue', _options().filter(function (opt) {
256
261
  return n.indexOf(opt.label) !== -1;
257
262
  }).map(function (opt) {
258
263
  return opt.value;
@@ -280,7 +285,7 @@
280
285
  "onUpdate:modelValue": this.onInput
281
286
  }), _objectSpread2({
282
287
  "default": function _default() {
283
- return [_this.options.map(function (opt, index) {
288
+ return [_this.options().map(function (opt, index) {
284
289
  var props = _objectSpread2({}, opt);
285
290
 
286
291
  delete props.value;
@@ -855,25 +860,30 @@
855
860
  var trueValue = vue.ref([]);
856
861
  var value = vue.toRef(props, 'modelValue');
857
862
 
858
- var _options = vue.computed(function () {
859
- return Array.isArray(options) ? options : [];
860
- });
863
+ var _options = function _options() {
864
+ return Array.isArray(options.value) ? options.value : [];
865
+ };
861
866
 
862
867
  var update = function update() {
863
- trueValue.value = _options.value.filter(function (opt) {
868
+ trueValue.value = _options().filter(function (opt) {
864
869
  return opt.value === value.value;
865
870
  }).reduce(function (initial, opt) {
866
871
  return opt.label;
867
872
  }, '');
868
873
  };
869
874
 
870
- update();
875
+ vue.watch(options, function () {
876
+ update();
877
+ }, {
878
+ deep: true,
879
+ immediate: true
880
+ });
871
881
  return {
872
882
  options: _options,
873
883
  trueValue: trueValue,
874
884
  value: value,
875
885
  onInput: function onInput(n) {
876
- _.emit('update:modelValue', _options.value.filter(function (opt) {
886
+ _.emit('update:modelValue', _options().filter(function (opt) {
877
887
  return opt.label === n;
878
888
  }).reduce(function (initial, opt) {
879
889
  return opt.value;
@@ -899,7 +909,7 @@
899
909
  "onUpdate:modelValue": this.onInput
900
910
  }), _objectSpread2({
901
911
  "default": function _default() {
902
- return [_this.options.map(function (opt, index) {
912
+ return [_this.options().map(function (opt, index) {
903
913
  var props = _objectSpread2({}, opt);
904
914
 
905
915
  delete props.value;
@@ -932,9 +942,9 @@
932
942
 
933
943
  var value = vue.toRef(props, 'modelValue');
934
944
 
935
- var _options = vue.computed(function () {
936
- return Array.isArray(options) ? options : [];
937
- });
945
+ var _options = function _options() {
946
+ return Array.isArray(options.value) ? options.value : [];
947
+ };
938
948
 
939
949
  return {
940
950
  options: _options,
@@ -953,7 +963,7 @@
953
963
  }
954
964
  }), _objectSpread2({
955
965
  "default": function _default() {
956
- return [_this.options.map(function (props, index) {
966
+ return [_this.options().map(function (props, index) {
957
967
  return vue.createVNode(vue.resolveComponent("ElOption"), vue.mergeProps(props, {
958
968
  "key": '' + index + props.value
959
969
  }), null);
@@ -1071,7 +1081,8 @@
1071
1081
  uploadList: [],
1072
1082
  previewVisible: false,
1073
1083
  previewImage: '',
1074
- fileList: []
1084
+ fileList: [],
1085
+ cacheFiles: []
1075
1086
  };
1076
1087
  },
1077
1088
  created: function created() {
@@ -1170,7 +1181,7 @@
1170
1181
  }
1171
1182
 
1172
1183
  return vue.createVNode("div", {
1173
- "class": 'fc-upload-cover'
1184
+ "class": "fc-upload-cover"
1174
1185
  }, [icons]);
1175
1186
  }
1176
1187
  },
@@ -1180,7 +1191,7 @@
1180
1191
  return this.uploadList.map(function (file, index) {
1181
1192
  return vue.createVNode("div", {
1182
1193
  "key": _this3.key(index),
1183
- "class": 'fc-files'
1194
+ "class": "fc-files"
1184
1195
  }, [file.percentage !== undefined && file.status !== 'success' ? _this3.makeProgress(file, index) : [_this3.makeItem(file, index), _this3.makeIcons(file, index)]]);
1185
1196
  });
1186
1197
  },
@@ -1201,7 +1212,7 @@
1201
1212
  }), _objectSpread2({
1202
1213
  "default": function _default() {
1203
1214
  return [isShow ? ((_this$$slots$default = (_this$$slots = _this4.$slots)["default"]) === null || _this$$slots$default === void 0 ? void 0 : _this$$slots$default.call(_this$$slots)) || vue.createVNode("div", {
1204
- "class": 'fc-upload-btn'
1215
+ "class": "fc-upload-btn"
1205
1216
  }, [vue.createVNode("i", {
1206
1217
  "class": "el-icon-upload2"
1207
1218
  }, null)]) : undefined];
@@ -1214,7 +1225,11 @@
1214
1225
  }).filter(function (url) {
1215
1226
  return url !== undefined;
1216
1227
  });
1217
- this.$emit('update:modelValue', this.limit === 1 ? files[0] || '' : files);
1228
+
1229
+ if (this.cacheFiles.length !== files.length) {
1230
+ this.cacheFiles = _toConsumableArray(files);
1231
+ this.$emit('update:modelValue', this.limit === 1 ? files[0] || '' : files);
1232
+ }
1218
1233
  },
1219
1234
  handleCancel: function handleCancel() {
1220
1235
  this.previewVisible = false;
@@ -1224,7 +1239,7 @@
1224
1239
  var _this5 = this;
1225
1240
 
1226
1241
  return vue.createVNode("div", {
1227
- "class": '_fc-upload'
1242
+ "class": "_fc-upload"
1228
1243
  }, [[this.$attrs.showFileList ? [] : this.makeFiles(), this.makeUpload()], vue.createVNode(vue.resolveComponent("ElDialog"), {
1229
1244
  "appendToBody": true,
1230
1245
  "modal": this.previewMask,
@@ -1754,14 +1769,14 @@
1754
1769
  modelValue: Object,
1755
1770
  api: Object
1756
1771
  },
1757
- emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync'],
1772
+ emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1758
1773
  render: function render() {
1759
1774
  return this.fc.render();
1760
1775
  },
1761
1776
  setup: function setup(props) {
1762
1777
  var vm = vue.getCurrentInstance();
1763
1778
  vue.provide('parentFC', vm);
1764
- var parent = vue.inject('parentFC');
1779
+ var parent = vue.inject('parentFC', null);
1765
1780
 
1766
1781
  var _toRefs = vue.toRefs(props),
1767
1782
  rule = _toRefs.rule,
@@ -1956,14 +1971,18 @@
1956
1971
  }
1957
1972
 
1958
1973
  origin[key] = deepExtend(origin[key], clone, mode);
1959
- } else if (is.Undef(clone)) {
1960
- $set(origin, key, clone);
1961
- } else if (clone.__json !== undefined) {
1962
- $set(origin, key, clone.__json);
1963
- } else if (clone.__origin !== undefined) {
1964
- $set(origin, key, clone.__origin);
1965
1974
  } else {
1966
1975
  $set(origin, key, clone);
1976
+
1977
+ if (!is.Undef(clone)) {
1978
+ if (clone.__json !== undefined) {
1979
+ origin[key].__json = clone.__json;
1980
+ }
1981
+
1982
+ if (clone.__origin !== undefined) {
1983
+ origin[key].__origin = clone.__origin;
1984
+ }
1985
+ }
1967
1986
  }
1968
1987
  }
1969
1988
  }
@@ -2344,11 +2363,6 @@
2344
2363
  }
2345
2364
 
2346
2365
  var api = {
2347
- helper: {
2348
- tidyFields: tidyFields,
2349
- props: props
2350
- },
2351
-
2352
2366
  get config() {
2353
2367
  return h.options;
2354
2368
  },
@@ -2496,6 +2510,12 @@
2496
2510
  });
2497
2511
  h.refresh();
2498
2512
  },
2513
+ all: function all(origin) {
2514
+ return Object.keys(h.ctxs).map(function (k) {
2515
+ var ctx = h.ctxs[k];
2516
+ return origin ? ctx.origin : ctx.rule;
2517
+ });
2518
+ },
2499
2519
  model: function model(origin) {
2500
2520
  return h.fields().reduce(function (initial, key) {
2501
2521
  var ctx = h.fieldCtx[key][0];
@@ -2681,6 +2701,15 @@
2681
2701
  nextRefresh: function nextRefresh(fn) {
2682
2702
  h.nextRefresh();
2683
2703
  fn && invoke(fn);
2704
+ },
2705
+ emit: function emit(name) {
2706
+ var _h$vm;
2707
+
2708
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2709
+ args[_key3 - 1] = arguments[_key3];
2710
+ }
2711
+
2712
+ (_h$vm = h.vm).emit.apply(_h$vm, [name].concat(args));
2684
2713
  }
2685
2714
  };
2686
2715
  ['on', 'once', 'off', 'set'].forEach(function (n) {
@@ -2826,6 +2855,7 @@
2826
2855
 
2827
2856
  if (ctx.type === 'hidden') return;
2828
2857
  var rule = ctx.rule;
2858
+ var preview = this.options.preview || false;
2829
2859
 
2830
2860
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2831
2861
  var vn;
@@ -2861,12 +2891,13 @@
2861
2891
  _vn = _this4.vm.slots[slot]({
2862
2892
  rule: rule,
2863
2893
  prop: prop,
2894
+ preview: preview,
2864
2895
  children: children,
2865
2896
  api: _this4.$handle.api,
2866
2897
  model: prop.model || {}
2867
2898
  });
2868
2899
  } else {
2869
- _vn = ctx.parser.render(_this4.renderChildren(ctx), ctx);
2900
+ _vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2870
2901
  }
2871
2902
 
2872
2903
  _vn = _this4.renderSides(_vn, ctx);
@@ -2935,6 +2966,7 @@
2935
2966
  var _this6 = this;
2936
2967
 
2937
2968
  return {
2969
+ preview: this.options.preview || false,
2938
2970
  api: this.$handle.api,
2939
2971
  form: this.fc.create,
2940
2972
  subForm: function subForm(_subForm) {
@@ -3832,6 +3864,7 @@
3832
3864
  this.refresh();
3833
3865
  this.bus.$off('next-tick', this.nextReload);
3834
3866
  this.bus.$once('next-tick', this.nextReload);
3867
+ this.bus.$emit('update', this.api);
3835
3868
  },
3836
3869
  //todo 组件生成全部通过 alias
3837
3870
  refresh: function refresh() {
@@ -3955,7 +3988,7 @@
3955
3988
  this.vm.setupState.updateValue(_objectSpread2({}, this.form));
3956
3989
  },
3957
3990
  isChange: function isChange(ctx, value) {
3958
- return JSON.stringify(this.getFormData(ctx)) !== JSON.stringify(value);
3991
+ return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
3959
3992
  },
3960
3993
  isQuote: function isQuote(ctx, value) {
3961
3994
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
@@ -3979,6 +4012,7 @@
3979
4012
  if (this.refreshControl(ctx)) {
3980
4013
  this.$render.clearCacheAll();
3981
4014
  this.loadRule();
4015
+ this.bus.$emit('update', this.api);
3982
4016
  this.refresh();
3983
4017
  }
3984
4018
 
@@ -4006,6 +4040,10 @@
4006
4040
  });
4007
4041
  }
4008
4042
 
4043
+ function strFn(key, val) {
4044
+ return typeof val === 'function' ? '' + val : val;
4045
+ }
4046
+
4009
4047
  var BaseParser = {
4010
4048
  init: function init(ctx) {},
4011
4049
  toFormValue: function toFormValue(value, ctx) {
@@ -4018,6 +4056,9 @@
4018
4056
  render: function render(children, ctx) {
4019
4057
  return ctx.$render.defaultRender(ctx, children);
4020
4058
  },
4059
+ preview: function preview(children, ctx) {
4060
+ return ctx.$render.defaultRender(ctx, children);
4061
+ },
4021
4062
  mergeProp: function mergeProp(ctx) {}
4022
4063
  };
4023
4064
 
@@ -4143,7 +4184,12 @@
4143
4184
  _this.rmCtx(child.__fc__);
4144
4185
  }
4145
4186
  });
4146
- is.trueArray(n) && _this.loadChildren(n, ctx);
4187
+
4188
+ if (is.trueArray(n)) {
4189
+ _this.loadChildren(n, ctx);
4190
+
4191
+ _this.bus.$emit('update', _this.api);
4192
+ }
4147
4193
  });
4148
4194
  }
4149
4195
 
@@ -4215,8 +4261,8 @@
4215
4261
  this.$render.clearCache(ctx);
4216
4262
  ctx["delete"]();
4217
4263
  this.effect(ctx, 'deleted');
4218
- input && !this.fieldCtx[field] && this.vm.emit('removeField', field, ctx.rule, this.api);
4219
- ctx.rule.__ctrl || this.vm.emit('removeRule', ctx.rule, this.api);
4264
+ input && !this.fieldCtx[field] && this.vm.emit('remove-field', field, ctx.rule, this.api);
4265
+ ctx.rule.__ctrl || this.vm.emit('remove-rule', ctx.rule, this.api);
4220
4266
  return ctx;
4221
4267
  }
4222
4268
  });
@@ -4705,6 +4751,11 @@
4705
4751
 
4706
4752
  function run(inject, rule, api) {
4707
4753
  var option = inject.value;
4754
+
4755
+ if (is.Function(option)) {
4756
+ option = option(rule, api);
4757
+ }
4758
+
4708
4759
  option = parseOpt(option);
4709
4760
 
4710
4761
  if (!option || !option.action) {
@@ -5029,6 +5080,7 @@
5029
5080
  copyRules: copyRules,
5030
5081
  fetch: fetch,
5031
5082
  $form: $form,
5083
+ parseFn: parseFn,
5032
5084
  parseJson: parseJson,
5033
5085
  toJson: toJson
5034
5086
  });
@@ -5437,40 +5489,35 @@
5437
5489
  var form = this.options.form;
5438
5490
  var children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5439
5491
 
5440
- var titleFn = function titleFn() {
5441
- return _this4.$r(mergeProps([titleProp, {
5442
- props: titleProp,
5443
- key: "".concat(uni, "tit"),
5444
- type: titleProp.type || 'span'
5445
- }]), children);
5446
- };
5447
-
5448
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5449
- if (infoProp.icon !== false) {
5450
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5451
- type: 'i',
5452
- "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5453
- key: "".concat(uni, "i")
5454
- }, {}, true));
5455
- }
5456
-
5492
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5457
5493
  var prop = {
5458
5494
  type: infoProp.type || 'popover',
5459
5495
  props: _objectSpread2({}, infoProp),
5460
5496
  key: "".concat(uni, "pop")
5461
5497
  };
5498
+ delete prop.props.icon;
5499
+ delete prop.props.show;
5500
+ delete prop.props.info;
5462
5501
  var field = 'content';
5463
5502
 
5464
5503
  if (infoProp.info && !hasProperty(prop.props, field)) {
5465
5504
  prop.props[field] = infoProp.info;
5466
5505
  }
5467
5506
 
5468
- return this.$r(mergeProps([infoProp, prop]), _defineProperty({}, titleProp.slot || (isTip ? 'default' : 'reference'), function () {
5469
- return titleFn();
5470
- }));
5507
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), _defineProperty({}, titleProp.slot || (isTip ? 'default' : 'reference'), function () {
5508
+ return _this4.$r({
5509
+ type: 'i',
5510
+ "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5511
+ key: "".concat(uni, "i")
5512
+ }, {}, true);
5513
+ })));
5471
5514
  }
5472
5515
 
5473
- return titleFn();
5516
+ return this.$r(mergeProps([titleProp, {
5517
+ props: titleProp,
5518
+ key: "".concat(uni, "tit"),
5519
+ type: titleProp.type || 'span'
5520
+ }]), children);
5474
5521
  },
5475
5522
  makeCol: function makeCol(rule, uni, children) {
5476
5523
  var col = rule.col;
@@ -5828,7 +5875,7 @@
5828
5875
  function elmFormCreate() {
5829
5876
  return FormCreateFactory({
5830
5877
  ui: 'element-ui',
5831
- version: '3.0.0-alpha.2',
5878
+ version: '3.0.0-alpha.3',
5832
5879
  manager: manager,
5833
5880
  appUse: appUse,
5834
5881
  extendApi: extendApi,