@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,10 +1,10 @@
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.
6
6
  */
7
- import { defineComponent, toRefs, inject, ref, toRef, computed, resolveComponent, createVNode, mergeProps as mergeProps$1, isVNode, nextTick, markRaw, reactive, getCurrentInstance, provide, onMounted, onBeforeUnmount, onUpdated, watch, customRef, withDirectives, resolveDirective, createApp, h } from 'vue';
7
+ import { defineComponent, toRefs, inject, ref, toRef, watch, resolveComponent, createVNode, mergeProps as mergeProps$1, isVNode, nextTick, markRaw, reactive, getCurrentInstance, provide, onMounted, onBeforeUnmount, onUpdated, computed, customRef, withDirectives, resolveDirective, createApp, h } from 'vue';
8
8
  import ElementPlus from 'element-plus';
9
9
 
10
10
  function ownKeys(object, enumerableOnly) {
@@ -227,25 +227,30 @@ var Checkbox = defineComponent({
227
227
  var trueValue = ref([]);
228
228
  var value = toRef(props, 'modelValue');
229
229
 
230
- var _options = computed(function () {
231
- return Array.isArray(options) ? options : [];
232
- });
230
+ var _options = function _options() {
231
+ return Array.isArray(options.value) ? options.value : [];
232
+ };
233
233
 
234
234
  var update = function update() {
235
- trueValue.value = value.value ? _options.value.filter(function (opt) {
235
+ trueValue.value = value.value ? _options().filter(function (opt) {
236
236
  return value.value.indexOf(opt.value) !== -1;
237
237
  }).map(function (option) {
238
238
  return option.label;
239
239
  }) : [];
240
240
  };
241
241
 
242
- update();
242
+ watch(options, function () {
243
+ update();
244
+ }, {
245
+ deep: true,
246
+ immediate: true
247
+ });
243
248
  return {
244
249
  options: _options,
245
250
  trueValue: trueValue,
246
251
  value: value,
247
252
  onInput: function onInput(n) {
248
- _.emit('update:modelValue', _options.value.filter(function (opt) {
253
+ _.emit('update:modelValue', _options().filter(function (opt) {
249
254
  return n.indexOf(opt.label) !== -1;
250
255
  }).map(function (opt) {
251
256
  return opt.value;
@@ -273,7 +278,7 @@ var Checkbox = defineComponent({
273
278
  "onUpdate:modelValue": this.onInput
274
279
  }), _objectSpread2({
275
280
  "default": function _default() {
276
- return [_this.options.map(function (opt, index) {
281
+ return [_this.options().map(function (opt, index) {
277
282
  var props = _objectSpread2({}, opt);
278
283
 
279
284
  delete props.value;
@@ -848,25 +853,30 @@ var Radio = defineComponent({
848
853
  var trueValue = ref([]);
849
854
  var value = toRef(props, 'modelValue');
850
855
 
851
- var _options = computed(function () {
852
- return Array.isArray(options) ? options : [];
853
- });
856
+ var _options = function _options() {
857
+ return Array.isArray(options.value) ? options.value : [];
858
+ };
854
859
 
855
860
  var update = function update() {
856
- trueValue.value = _options.value.filter(function (opt) {
861
+ trueValue.value = _options().filter(function (opt) {
857
862
  return opt.value === value.value;
858
863
  }).reduce(function (initial, opt) {
859
864
  return opt.label;
860
865
  }, '');
861
866
  };
862
867
 
863
- update();
868
+ watch(options, function () {
869
+ update();
870
+ }, {
871
+ deep: true,
872
+ immediate: true
873
+ });
864
874
  return {
865
875
  options: _options,
866
876
  trueValue: trueValue,
867
877
  value: value,
868
878
  onInput: function onInput(n) {
869
- _.emit('update:modelValue', _options.value.filter(function (opt) {
879
+ _.emit('update:modelValue', _options().filter(function (opt) {
870
880
  return opt.label === n;
871
881
  }).reduce(function (initial, opt) {
872
882
  return opt.value;
@@ -892,7 +902,7 @@ var Radio = defineComponent({
892
902
  "onUpdate:modelValue": this.onInput
893
903
  }), _objectSpread2({
894
904
  "default": function _default() {
895
- return [_this.options.map(function (opt, index) {
905
+ return [_this.options().map(function (opt, index) {
896
906
  var props = _objectSpread2({}, opt);
897
907
 
898
908
  delete props.value;
@@ -925,9 +935,9 @@ var Select = defineComponent({
925
935
 
926
936
  var value = toRef(props, 'modelValue');
927
937
 
928
- var _options = computed(function () {
929
- return Array.isArray(options) ? options : [];
930
- });
938
+ var _options = function _options() {
939
+ return Array.isArray(options.value) ? options.value : [];
940
+ };
931
941
 
932
942
  return {
933
943
  options: _options,
@@ -946,7 +956,7 @@ var Select = defineComponent({
946
956
  }
947
957
  }), _objectSpread2({
948
958
  "default": function _default() {
949
- return [_this.options.map(function (props, index) {
959
+ return [_this.options().map(function (props, index) {
950
960
  return createVNode(resolveComponent("ElOption"), mergeProps$1(props, {
951
961
  "key": '' + index + props.value
952
962
  }), null);
@@ -1064,7 +1074,8 @@ var Upload = defineComponent({
1064
1074
  uploadList: [],
1065
1075
  previewVisible: false,
1066
1076
  previewImage: '',
1067
- fileList: []
1077
+ fileList: [],
1078
+ cacheFiles: []
1068
1079
  };
1069
1080
  },
1070
1081
  created: function created() {
@@ -1163,7 +1174,7 @@ var Upload = defineComponent({
1163
1174
  }
1164
1175
 
1165
1176
  return createVNode("div", {
1166
- "class": 'fc-upload-cover'
1177
+ "class": "fc-upload-cover"
1167
1178
  }, [icons]);
1168
1179
  }
1169
1180
  },
@@ -1173,7 +1184,7 @@ var Upload = defineComponent({
1173
1184
  return this.uploadList.map(function (file, index) {
1174
1185
  return createVNode("div", {
1175
1186
  "key": _this3.key(index),
1176
- "class": 'fc-files'
1187
+ "class": "fc-files"
1177
1188
  }, [file.percentage !== undefined && file.status !== 'success' ? _this3.makeProgress(file, index) : [_this3.makeItem(file, index), _this3.makeIcons(file, index)]]);
1178
1189
  });
1179
1190
  },
@@ -1194,7 +1205,7 @@ var Upload = defineComponent({
1194
1205
  }), _objectSpread2({
1195
1206
  "default": function _default() {
1196
1207
  return [isShow ? ((_this$$slots$default = (_this$$slots = _this4.$slots)["default"]) === null || _this$$slots$default === void 0 ? void 0 : _this$$slots$default.call(_this$$slots)) || createVNode("div", {
1197
- "class": 'fc-upload-btn'
1208
+ "class": "fc-upload-btn"
1198
1209
  }, [createVNode("i", {
1199
1210
  "class": "el-icon-upload2"
1200
1211
  }, null)]) : undefined];
@@ -1207,7 +1218,11 @@ var Upload = defineComponent({
1207
1218
  }).filter(function (url) {
1208
1219
  return url !== undefined;
1209
1220
  });
1210
- this.$emit('update:modelValue', this.limit === 1 ? files[0] || '' : files);
1221
+
1222
+ if (this.cacheFiles.length !== files.length) {
1223
+ this.cacheFiles = _toConsumableArray(files);
1224
+ this.$emit('update:modelValue', this.limit === 1 ? files[0] || '' : files);
1225
+ }
1211
1226
  },
1212
1227
  handleCancel: function handleCancel() {
1213
1228
  this.previewVisible = false;
@@ -1217,7 +1232,7 @@ var Upload = defineComponent({
1217
1232
  var _this5 = this;
1218
1233
 
1219
1234
  return createVNode("div", {
1220
- "class": '_fc-upload'
1235
+ "class": "_fc-upload"
1221
1236
  }, [[this.$attrs.showFileList ? [] : this.makeFiles(), this.makeUpload()], createVNode(resolveComponent("ElDialog"), {
1222
1237
  "appendToBody": true,
1223
1238
  "modal": this.previewMask,
@@ -1747,14 +1762,14 @@ function $FormCreate(FormCreate) {
1747
1762
  modelValue: Object,
1748
1763
  api: Object
1749
1764
  },
1750
- emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync'],
1765
+ emits: ['update:api', 'update:modelValue', 'mounted', 'submit', 'change', 'emit-event', 'control', 'remove-rule', 'remove-field', 'sync', 'reload', 'repeat-field', 'update'],
1751
1766
  render: function render() {
1752
1767
  return this.fc.render();
1753
1768
  },
1754
1769
  setup: function setup(props) {
1755
1770
  var vm = getCurrentInstance();
1756
1771
  provide('parentFC', vm);
1757
- var parent = inject('parentFC');
1772
+ var parent = inject('parentFC', null);
1758
1773
 
1759
1774
  var _toRefs = toRefs(props),
1760
1775
  rule = _toRefs.rule,
@@ -1949,14 +1964,18 @@ function deepExtend(origin) {
1949
1964
  }
1950
1965
 
1951
1966
  origin[key] = deepExtend(origin[key], clone, mode);
1952
- } else if (is.Undef(clone)) {
1953
- $set(origin, key, clone);
1954
- } else if (clone.__json !== undefined) {
1955
- $set(origin, key, clone.__json);
1956
- } else if (clone.__origin !== undefined) {
1957
- $set(origin, key, clone.__origin);
1958
1967
  } else {
1959
1968
  $set(origin, key, clone);
1969
+
1970
+ if (!is.Undef(clone)) {
1971
+ if (clone.__json !== undefined) {
1972
+ origin[key].__json = clone.__json;
1973
+ }
1974
+
1975
+ if (clone.__origin !== undefined) {
1976
+ origin[key].__origin = clone.__origin;
1977
+ }
1978
+ }
1960
1979
  }
1961
1980
  }
1962
1981
  }
@@ -2337,11 +2356,6 @@ function Api(h) {
2337
2356
  }
2338
2357
 
2339
2358
  var api = {
2340
- helper: {
2341
- tidyFields: tidyFields,
2342
- props: props
2343
- },
2344
-
2345
2359
  get config() {
2346
2360
  return h.options;
2347
2361
  },
@@ -2489,6 +2503,12 @@ function Api(h) {
2489
2503
  });
2490
2504
  h.refresh();
2491
2505
  },
2506
+ all: function all(origin) {
2507
+ return Object.keys(h.ctxs).map(function (k) {
2508
+ var ctx = h.ctxs[k];
2509
+ return origin ? ctx.origin : ctx.rule;
2510
+ });
2511
+ },
2492
2512
  model: function model(origin) {
2493
2513
  return h.fields().reduce(function (initial, key) {
2494
2514
  var ctx = h.fieldCtx[key][0];
@@ -2674,6 +2694,15 @@ function Api(h) {
2674
2694
  nextRefresh: function nextRefresh(fn) {
2675
2695
  h.nextRefresh();
2676
2696
  fn && invoke(fn);
2697
+ },
2698
+ emit: function emit(name) {
2699
+ var _h$vm;
2700
+
2701
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2702
+ args[_key3 - 1] = arguments[_key3];
2703
+ }
2704
+
2705
+ (_h$vm = h.vm).emit.apply(_h$vm, [name].concat(args));
2677
2706
  }
2678
2707
  };
2679
2708
  ['on', 'once', 'off', 'set'].forEach(function (n) {
@@ -2819,6 +2848,7 @@ function useRender$1(Render) {
2819
2848
 
2820
2849
  if (ctx.type === 'hidden') return;
2821
2850
  var rule = ctx.rule;
2851
+ var preview = this.options.preview || false;
2822
2852
 
2823
2853
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2824
2854
  var vn;
@@ -2854,12 +2884,13 @@ function useRender$1(Render) {
2854
2884
  _vn = _this4.vm.slots[slot]({
2855
2885
  rule: rule,
2856
2886
  prop: prop,
2887
+ preview: preview,
2857
2888
  children: children,
2858
2889
  api: _this4.$handle.api,
2859
2890
  model: prop.model || {}
2860
2891
  });
2861
2892
  } else {
2862
- _vn = ctx.parser.render(_this4.renderChildren(ctx), ctx);
2893
+ _vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2863
2894
  }
2864
2895
 
2865
2896
  _vn = _this4.renderSides(_vn, ctx);
@@ -2928,6 +2959,7 @@ function useRender$1(Render) {
2928
2959
  var _this6 = this;
2929
2960
 
2930
2961
  return {
2962
+ preview: this.options.preview || false,
2931
2963
  api: this.$handle.api,
2932
2964
  form: this.fc.create,
2933
2965
  subForm: function subForm(_subForm) {
@@ -3825,6 +3857,7 @@ function useLoader(Handler) {
3825
3857
  this.refresh();
3826
3858
  this.bus.$off('next-tick', this.nextReload);
3827
3859
  this.bus.$once('next-tick', this.nextReload);
3860
+ this.bus.$emit('update', this.api);
3828
3861
  },
3829
3862
  //todo 组件生成全部通过 alias
3830
3863
  refresh: function refresh() {
@@ -3948,7 +3981,7 @@ function useInput(Handler) {
3948
3981
  this.vm.setupState.updateValue(_objectSpread2({}, this.form));
3949
3982
  },
3950
3983
  isChange: function isChange(ctx, value) {
3951
- return JSON.stringify(this.getFormData(ctx)) !== JSON.stringify(value);
3984
+ return JSON.stringify(this.getFormData(ctx), strFn) !== JSON.stringify(value, strFn);
3952
3985
  },
3953
3986
  isQuote: function isQuote(ctx, value) {
3954
3987
  return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
@@ -3972,6 +4005,7 @@ function useInput(Handler) {
3972
4005
  if (this.refreshControl(ctx)) {
3973
4006
  this.$render.clearCacheAll();
3974
4007
  this.loadRule();
4008
+ this.bus.$emit('update', this.api);
3975
4009
  this.refresh();
3976
4010
  }
3977
4011
 
@@ -3999,6 +4033,10 @@ function useInput(Handler) {
3999
4033
  });
4000
4034
  }
4001
4035
 
4036
+ function strFn(key, val) {
4037
+ return typeof val === 'function' ? '' + val : val;
4038
+ }
4039
+
4002
4040
  var BaseParser = {
4003
4041
  init: function init(ctx) {},
4004
4042
  toFormValue: function toFormValue(value, ctx) {
@@ -4011,6 +4049,9 @@ var BaseParser = {
4011
4049
  render: function render(children, ctx) {
4012
4050
  return ctx.$render.defaultRender(ctx, children);
4013
4051
  },
4052
+ preview: function preview(children, ctx) {
4053
+ return ctx.$render.defaultRender(ctx, children);
4054
+ },
4014
4055
  mergeProp: function mergeProp(ctx) {}
4015
4056
  };
4016
4057
 
@@ -4136,7 +4177,12 @@ function useContext(Handler) {
4136
4177
  _this.rmCtx(child.__fc__);
4137
4178
  }
4138
4179
  });
4139
- is.trueArray(n) && _this.loadChildren(n, ctx);
4180
+
4181
+ if (is.trueArray(n)) {
4182
+ _this.loadChildren(n, ctx);
4183
+
4184
+ _this.bus.$emit('update', _this.api);
4185
+ }
4140
4186
  });
4141
4187
  }
4142
4188
 
@@ -4208,8 +4254,8 @@ function useContext(Handler) {
4208
4254
  this.$render.clearCache(ctx);
4209
4255
  ctx["delete"]();
4210
4256
  this.effect(ctx, 'deleted');
4211
- input && !this.fieldCtx[field] && this.vm.emit('removeField', field, ctx.rule, this.api);
4212
- ctx.rule.__ctrl || this.vm.emit('removeRule', ctx.rule, this.api);
4257
+ input && !this.fieldCtx[field] && this.vm.emit('remove-field', field, ctx.rule, this.api);
4258
+ ctx.rule.__ctrl || this.vm.emit('remove-rule', ctx.rule, this.api);
4213
4259
  return ctx;
4214
4260
  }
4215
4261
  });
@@ -4698,6 +4744,11 @@ function parseOpt(option) {
4698
4744
 
4699
4745
  function run(inject, rule, api) {
4700
4746
  var option = inject.value;
4747
+
4748
+ if (is.Function(option)) {
4749
+ option = option(rule, api);
4750
+ }
4751
+
4701
4752
  option = parseOpt(option);
4702
4753
 
4703
4754
  if (!option || !option.action) {
@@ -5022,6 +5073,7 @@ function FormCreateFactory(config) {
5022
5073
  copyRules: copyRules,
5023
5074
  fetch: fetch,
5024
5075
  $form: $form,
5076
+ parseFn: parseFn,
5025
5077
  parseJson: parseJson,
5026
5078
  toJson: toJson
5027
5079
  });
@@ -5430,40 +5482,35 @@ var manager = {
5430
5482
  var form = this.options.form;
5431
5483
  var children = [(titleProp.title || '') + (form.labelSuffix || form['label-suffix'] || '')];
5432
5484
 
5433
- var titleFn = function titleFn() {
5434
- return _this4.$r(mergeProps([titleProp, {
5435
- props: titleProp,
5436
- key: "".concat(uni, "tit"),
5437
- type: titleProp.type || 'span'
5438
- }]), children);
5439
- };
5440
-
5441
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5442
- if (infoProp.icon !== false) {
5443
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5444
- type: 'i',
5445
- "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5446
- key: "".concat(uni, "i")
5447
- }, {}, true));
5448
- }
5449
-
5485
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5450
5486
  var prop = {
5451
5487
  type: infoProp.type || 'popover',
5452
5488
  props: _objectSpread2({}, infoProp),
5453
5489
  key: "".concat(uni, "pop")
5454
5490
  };
5491
+ delete prop.props.icon;
5492
+ delete prop.props.show;
5493
+ delete prop.props.info;
5455
5494
  var field = 'content';
5456
5495
 
5457
5496
  if (infoProp.info && !hasProperty(prop.props, field)) {
5458
5497
  prop.props[field] = infoProp.info;
5459
5498
  }
5460
5499
 
5461
- return this.$r(mergeProps([infoProp, prop]), _defineProperty({}, titleProp.slot || (isTip ? 'default' : 'reference'), function () {
5462
- return titleFn();
5463
- }));
5500
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), _defineProperty({}, titleProp.slot || (isTip ? 'default' : 'reference'), function () {
5501
+ return _this4.$r({
5502
+ type: 'i',
5503
+ "class": infoProp.icon === true ? 'el-icon-warning' : infoProp.icon,
5504
+ key: "".concat(uni, "i")
5505
+ }, {}, true);
5506
+ })));
5464
5507
  }
5465
5508
 
5466
- return titleFn();
5509
+ return this.$r(mergeProps([titleProp, {
5510
+ props: titleProp,
5511
+ key: "".concat(uni, "tit"),
5512
+ type: titleProp.type || 'span'
5513
+ }]), children);
5467
5514
  },
5468
5515
  makeCol: function makeCol(rule, uni, children) {
5469
5516
  var col = rule.col;
@@ -5821,7 +5868,7 @@ function appUse(app) {
5821
5868
  function elmFormCreate() {
5822
5869
  return FormCreateFactory({
5823
5870
  ui: 'element-ui',
5824
- version: '3.0.0-alpha.2',
5871
+ version: '3.0.0-alpha.3',
5825
5872
  manager: manager,
5826
5873
  appUse: appUse,
5827
5874
  extendApi: extendApi,