@form-create/view-design 2.5.11 → 2.5.15

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.11
2
+ * @form-create/view-design v2.5.15
3
3
  * (c) 2018-2021 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -267,6 +267,12 @@
267
267
  }
268
268
  },
269
269
  watch: {
270
+ 'formCreateInject.options': {
271
+ handler: function handler() {
272
+ this.update();
273
+ },
274
+ deep: true
275
+ },
270
276
  value: function value() {
271
277
  this.update();
272
278
  }
@@ -277,8 +283,12 @@
277
283
  };
278
284
  },
279
285
  methods: {
286
+ options: function options() {
287
+ var opt = this.formCreateInject.options;
288
+ return Array.isArray(opt) ? opt : [];
289
+ },
280
290
  onInput: function onInput(n) {
281
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
291
+ this.$emit('input', this.options().filter(function (opt) {
282
292
  return n.indexOf(opt.label) !== -1;
283
293
  }).map(function (opt) {
284
294
  return opt.value;
@@ -289,7 +299,7 @@
289
299
  update: function update() {
290
300
  var _this = this;
291
301
 
292
- this.trueValue = this.value ? this.formCreateInject.options.filter(function (opt) {
302
+ this.trueValue = this.value ? this.options().filter(function (opt) {
293
303
  return _this.value.indexOf(opt.value) !== -1;
294
304
  }).map(function (option) {
295
305
  return option.label;
@@ -308,7 +318,7 @@
308
318
  "on": {
309
319
  "input": this.onInput
310
320
  }
311
- }]), [this.formCreateInject.options.map(function (opt, index) {
321
+ }]), [this.options().map(function (opt, index) {
312
322
  var props = _objectSpread2({}, opt);
313
323
 
314
324
  delete props.value;
@@ -831,6 +841,12 @@
831
841
  value: {}
832
842
  },
833
843
  watch: {
844
+ 'formCreateInject.options': {
845
+ handler: function handler() {
846
+ this.update();
847
+ },
848
+ deep: true
849
+ },
834
850
  value: function value() {
835
851
  this.update();
836
852
  }
@@ -841,8 +857,12 @@
841
857
  };
842
858
  },
843
859
  methods: {
860
+ options: function options() {
861
+ var opt = this.formCreateInject.options;
862
+ return Array.isArray(opt) ? opt : [];
863
+ },
844
864
  onInput: function onInput(n) {
845
- this.$emit('input', this.formCreateInject.options.filter(function (opt) {
865
+ this.$emit('input', this.options().filter(function (opt) {
846
866
  return opt.label === n;
847
867
  }).reduce(function (initial, opt) {
848
868
  return opt.value;
@@ -851,7 +871,7 @@
851
871
  update: function update() {
852
872
  var _this = this;
853
873
 
854
- this.trueValue = this.formCreateInject.options.filter(function (opt) {
874
+ this.trueValue = this.options().filter(function (opt) {
855
875
  return opt.value === _this.value;
856
876
  }).reduce(function (initial, opt) {
857
877
  return opt.label;
@@ -870,7 +890,7 @@
870
890
  "on": {
871
891
  "input": this.onInput
872
892
  }
873
- }]), [this.formCreateInject.options.map(function (opt, index) {
893
+ }]), [this.options().map(function (opt, index) {
874
894
  var props = _objectSpread2({}, opt);
875
895
 
876
896
  delete props.value;
@@ -916,7 +936,8 @@
916
936
  }
917
937
  },
918
938
  render: function render(h, ctx) {
919
- return h("Select", helper([{}, ctx.data]), [ctx.props.formCreateInject.options.map(function (props, index) {
939
+ var options = ctx.props.formCreateInject.options;
940
+ return h("Select", helper([{}, ctx.data]), [(Array.isArray(options) ? options : []).map(function (props, index) {
920
941
  var slot = props.slot;
921
942
  return h("Option", {
922
943
  "props": _objectSpread2({}, props),
@@ -1320,7 +1341,8 @@
1320
1341
  return {
1321
1342
  len: 0,
1322
1343
  cacheRule: {},
1323
- cacheValue: {}
1344
+ cacheValue: {},
1345
+ type: undefined
1324
1346
  };
1325
1347
  },
1326
1348
  computed: {
@@ -1492,7 +1514,7 @@
1492
1514
  this.addRule(i, true);
1493
1515
  },
1494
1516
  del: function del(index, key) {
1495
- if (this.disabled || false === this.onBeforeRemove(this.value)) {
1517
+ if (this.disabled || false === this.onBeforeRemove(this.value, index)) {
1496
1518
  return;
1497
1519
  }
1498
1520
 
@@ -1565,6 +1587,7 @@
1565
1587
  }
1566
1588
  },
1567
1589
  created: function created() {
1590
+ this.type = this.formCreateInject.form.$form();
1568
1591
  var d = (this.expand || 0) - this.value.length;
1569
1592
 
1570
1593
  if (d > 0) {
@@ -1581,6 +1604,7 @@
1581
1604
  var h = arguments[0];
1582
1605
  var keys = Object.keys(this.cacheRule);
1583
1606
  var button = this.button;
1607
+ var Type = this.type;
1584
1608
  return keys.length === 0 ? this.$scopedSlots["default"] ? this.$scopedSlots["default"]({
1585
1609
  vm: this,
1586
1610
  add: this.add
@@ -1610,7 +1634,7 @@
1610
1634
  "attrs": {
1611
1635
  "span": button ? 20 : 24
1612
1636
  }
1613
- }, [h("FormItem", [h("FormCreate", helper([{
1637
+ }, [h("FormItem", [h(Type, helper([{
1614
1638
  "key": key
1615
1639
  }, {
1616
1640
  "on": {
@@ -1642,9 +1666,6 @@
1642
1666
  }
1643
1667
  }, [_this9.makeIcon(keys.length, index, key)]) : null]);
1644
1668
  })]);
1645
- },
1646
- beforeMount: function beforeMount() {
1647
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1648
1669
  }
1649
1670
  };
1650
1671
  }
@@ -1686,7 +1707,8 @@
1686
1707
  data: function data() {
1687
1708
  return {
1688
1709
  cacheRule: {},
1689
- cacheValue: {}
1710
+ cacheValue: {},
1711
+ type: undefined
1690
1712
  };
1691
1713
  },
1692
1714
  watch: {
@@ -1748,13 +1770,15 @@
1748
1770
  },
1749
1771
  created: function created() {
1750
1772
  this.addRule();
1773
+ this.type = this.formCreateInject.form.$form();
1751
1774
  },
1752
1775
  render: function render() {
1753
1776
  var h = arguments[0];
1754
1777
  var _this$cacheRule = this.cacheRule,
1755
1778
  rule = _this$cacheRule.rule,
1756
1779
  options = _this$cacheRule.options;
1757
- return h("FormCreate", helper([{}, {
1780
+ var Type = this.type;
1781
+ return h(Type, helper([{}, {
1758
1782
  "on": {
1759
1783
  'update:value': this.formData,
1760
1784
  'emit-event': this.emitEvent,
@@ -1767,9 +1791,6 @@
1767
1791
  "extendOption": true
1768
1792
  }
1769
1793
  }]));
1770
- },
1771
- beforeMount: function beforeMount() {
1772
- this.$options.components.FormCreate = this.formCreateInject.form.$form();
1773
1794
  }
1774
1795
  };
1775
1796
 
@@ -1894,6 +1915,7 @@
1894
1915
  Object.keys(this.formCreate.prop).forEach(function (k) {
1895
1916
  extend(_this2.$options[k], _this2.formCreate.prop[k]);
1896
1917
  });
1918
+ this.$emit('beforeCreate', this.formCreate.api());
1897
1919
  }
1898
1920
  };
1899
1921
  }
@@ -1974,6 +1996,20 @@
1974
1996
  return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
1975
1997
  }
1976
1998
 
1999
+ function format(type, msg, rule) {
2000
+ return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2001
+ }
2002
+ function tip(msg, rule) {
2003
+ console.warn(format('tip', msg, rule));
2004
+ }
2005
+ function err(msg, rule) {
2006
+ console.error(format('err', msg, rule));
2007
+ }
2008
+ function logError(e) {
2009
+ err(e.toString());
2010
+ console.error(e);
2011
+ }
2012
+
1977
2013
  function deepExtend(origin) {
1978
2014
  var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1979
2015
  var mode = arguments.length > 2 ? arguments[2] : undefined;
@@ -2002,14 +2038,18 @@
2002
2038
  }
2003
2039
 
2004
2040
  origin[key] = deepExtend(origin[key], clone, mode);
2005
- } else if (is.Undef(clone)) {
2006
- $set(origin, key, clone);
2007
- } else if (clone.__json !== undefined) {
2008
- $set(origin, key, clone.__json);
2009
- } else if (clone.__origin !== undefined) {
2010
- $set(origin, key, clone.__origin);
2011
2041
  } else {
2012
2042
  $set(origin, key, clone);
2043
+
2044
+ if (!is.Undef(clone)) {
2045
+ if (clone.__json !== undefined) {
2046
+ origin[key].__json = clone.__json;
2047
+ }
2048
+
2049
+ if (clone.__origin !== undefined) {
2050
+ origin[key].__origin = clone.__origin;
2051
+ }
2052
+ }
2013
2053
  }
2014
2054
  }
2015
2055
  }
@@ -2024,20 +2064,6 @@
2024
2064
  }).value;
2025
2065
  }
2026
2066
 
2027
- function format(type, msg, rule) {
2028
- return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
2029
- }
2030
- function tip(msg, rule) {
2031
- console.warn(format('tip', msg, rule));
2032
- }
2033
- function err(msg, rule) {
2034
- console.error(format('err', msg, rule));
2035
- }
2036
- function logError(e) {
2037
- err(e.toString());
2038
- console.error(e);
2039
- }
2040
-
2041
2067
  var PREFIX = '[[FORM-CREATE-PREFIX-';
2042
2068
  var SUFFIX = '-FORM-CREATE-SUFFIX]]';
2043
2069
  var $T = '$FN:';
@@ -2114,8 +2140,8 @@
2114
2140
  };
2115
2141
  } //todo 优化位置
2116
2142
 
2117
- function copyRule(rule, mode) {
2118
- return copyRules([rule], mode || false)[0];
2143
+ function copyRule(rule) {
2144
+ return copyRules([rule])[0];
2119
2145
  }
2120
2146
  function copyRules(rules, mode) {
2121
2147
  return deepExtend([], _toConsumableArray(rules), mode || false);
@@ -2306,11 +2332,6 @@
2306
2332
  }
2307
2333
 
2308
2334
  var api = {
2309
- helper: {
2310
- tidyFields: tidyFields,
2311
- props: props
2312
- },
2313
-
2314
2335
  get config() {
2315
2336
  return h.options;
2316
2337
  },
@@ -2454,6 +2475,12 @@
2454
2475
  });
2455
2476
  h.refresh();
2456
2477
  },
2478
+ all: function all(origin) {
2479
+ return Object.keys(h.ctxs).map(function (k) {
2480
+ var ctx = h.ctxs[k];
2481
+ return origin ? ctx.origin : ctx.rule;
2482
+ });
2483
+ },
2457
2484
  model: function model(origin) {
2458
2485
  return h.fields().reduce(function (initial, key) {
2459
2486
  var ctx = h.fieldCtx[key][0];
@@ -2641,13 +2668,26 @@
2641
2668
  nextRefresh: function nextRefresh(fn) {
2642
2669
  h.nextRefresh();
2643
2670
  fn && invoke(fn);
2671
+ },
2672
+ emit: function emit(name) {
2673
+ var _h$vm;
2674
+
2675
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2676
+ args[_key3 - 1] = arguments[_key3];
2677
+ }
2678
+
2679
+ (_h$vm = h.vm).$emit.apply(_h$vm, [name].concat(args));
2680
+ },
2681
+ helper: {
2682
+ tidyFields: tidyFields,
2683
+ props: props
2644
2684
  }
2645
2685
  };
2646
2686
  ['on', 'once', 'off', 'set'].forEach(function (n) {
2647
2687
  api[n] = function () {
2648
- var _h$vm;
2688
+ var _h$vm2;
2649
2689
 
2650
- (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2690
+ (_h$vm2 = h.vm)["$".concat(n)].apply(_h$vm2, arguments);
2651
2691
  };
2652
2692
  });
2653
2693
  api.changeValue = api.changeField = api.setValue;
@@ -2872,6 +2912,7 @@
2872
2912
  renderCtx: function renderCtx(ctx, parent) {
2873
2913
  if (ctx.type === 'hidden') return;
2874
2914
  var rule = ctx.rule;
2915
+ var preview = this.options.preview || false;
2875
2916
 
2876
2917
  if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2877
2918
  var vn;
@@ -2922,12 +2963,13 @@
2922
2963
  vn = this.vm.$scopedSlots[slot]({
2923
2964
  rule: rule,
2924
2965
  prop: prop,
2966
+ preview: preview,
2925
2967
  children: children,
2926
2968
  api: this.$handle.api,
2927
2969
  model: prop.model || {}
2928
2970
  });
2929
2971
  } else {
2930
- vn = ctx.parser.render(children, ctx);
2972
+ vn = preview ? ctx.parser.preview(children, ctx) : ctx.parser.render(children, ctx);
2931
2973
  }
2932
2974
  }
2933
2975
 
@@ -2992,20 +3034,26 @@
2992
3034
  var _this7 = this;
2993
3035
 
2994
3036
  if (!this.vm.ctxInject[ctx.id]) {
2995
- $set(this.vm.ctxInject, ctx.id, {});
3037
+ $set(this.vm.ctxInject, ctx.id, {
3038
+ api: this.$handle.api,
3039
+ form: this.fc.create,
3040
+ subForm: function subForm(_subForm) {
3041
+ _this7.$handle.addSubForm(ctx, _subForm);
3042
+ },
3043
+ options: [],
3044
+ children: [],
3045
+ prop: {},
3046
+ preview: false,
3047
+ field: ctx.field,
3048
+ rule: ctx.rule
3049
+ });
2996
3050
  }
2997
3051
 
2998
3052
  var inject = this.vm.ctxInject[ctx.id];
2999
3053
  extend(inject, {
3000
- api: this.$handle.api,
3001
- form: this.fc.create,
3002
- subForm: function subForm(_subForm) {
3003
- _this7.$handle.addSubForm(ctx, _subForm);
3004
- },
3005
- field: ctx.field,
3054
+ preview: this.options.preview || false,
3006
3055
  options: ctx.prop.options,
3007
3056
  children: ctx.rule.children,
3008
- rule: ctx.rule,
3009
3057
  prop: function () {
3010
3058
  var temp = _objectSpread2({}, ctx.prop);
3011
3059
 
@@ -3031,6 +3079,9 @@
3031
3079
  on: {
3032
3080
  'hook:mounted': function hookMounted() {
3033
3081
  _this8.onMounted(ctx);
3082
+ },
3083
+ 'fc.sub-form': function fcSubForm(subForm) {
3084
+ _this8.$handle.addSubForm(ctx, subForm);
3034
3085
  }
3035
3086
  }
3036
3087
  }];
@@ -3912,6 +3963,7 @@
3912
3963
  this.refresh();
3913
3964
  this.bus.$off('next-tick', this.nextReload);
3914
3965
  this.bus.$once('next-tick', this.nextReload);
3966
+ this.vm.$emit('update', this.api);
3915
3967
  },
3916
3968
  //todo 组件生成全部通过 alias
3917
3969
  refresh: function refresh() {
@@ -3947,7 +3999,7 @@
3947
3999
  function useInput(Handler) {
3948
4000
  extend(Handler.prototype, {
3949
4001
  getValue: function getValue(ctx) {
3950
- if (!hasProperty(ctx, 'cacheValue')) {
4002
+ if (is.Undef(ctx.cacheValue)) {
3951
4003
  ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3952
4004
  }
3953
4005
 
@@ -4071,7 +4123,7 @@
4071
4123
  return JSON.stringify(ctx.rule.value) !== JSON.stringify(value);
4072
4124
  },
4073
4125
  isQuote: function isQuote(ctx, value) {
4074
- return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
4126
+ return value === ctx.rule.value || is.Object(value) || Array.isArray(value) || is.Function(value);
4075
4127
  },
4076
4128
  refreshUpdate: function refreshUpdate(ctx, val) {
4077
4129
  var _this4 = this;
@@ -4092,6 +4144,7 @@
4092
4144
  if (this.refreshControl(ctx)) {
4093
4145
  this.$render.clearCacheAll();
4094
4146
  this.loadRule();
4147
+ this.vm.$emit('update', this.api);
4095
4148
  this.refresh();
4096
4149
  }
4097
4150
 
@@ -4137,6 +4190,9 @@
4137
4190
  render: function render(children, ctx) {
4138
4191
  return ctx.$render.defaultRender(ctx, children);
4139
4192
  },
4193
+ preview: function preview(children, ctx) {
4194
+ return ctx.$render.defaultRender(ctx, children);
4195
+ },
4140
4196
  mergeProp: function mergeProp(ctx) {}
4141
4197
  };
4142
4198
 
@@ -4263,6 +4319,8 @@
4263
4319
  }
4264
4320
 
4265
4321
  _flag && _this.loadChildren(n, ctx);
4322
+
4323
+ _this.vm.$emit('update', _this.api);
4266
4324
  });
4267
4325
  }
4268
4326
 
@@ -4798,6 +4856,11 @@
4798
4856
 
4799
4857
  function run(inject, rule, api) {
4800
4858
  var option = inject.value;
4859
+
4860
+ if (is.Function(option)) {
4861
+ option = option(rule, api);
4862
+ }
4863
+
4801
4864
  option = parseOpt(option);
4802
4865
 
4803
4866
  if (!option || !option.action) {
@@ -4908,9 +4971,7 @@
4908
4971
 
4909
4972
 
4910
4973
  function FormCreateFactory(config) {
4911
- var _fragment = _vue.extend(fragment);
4912
-
4913
- var components = _defineProperty({}, fragment.name, _fragment);
4974
+ var components = _defineProperty({}, fragment.name, fragment);
4914
4975
 
4915
4976
  var parsers = {};
4916
4977
  var directives = {};
@@ -4975,6 +5036,10 @@
4975
5036
 
4976
5037
  function $form() {
4977
5038
  return _vue.extend($FormCreate(FormCreate));
5039
+ }
5040
+
5041
+ function $vnode() {
5042
+ return _vue.extend(fragment);
4978
5043
  } //todo 检查回调函数作用域
4979
5044
 
4980
5045
 
@@ -5096,6 +5161,7 @@
5096
5161
  },
5097
5162
  created: function created() {
5098
5163
  this.$handle.init();
5164
+ this.vm.$emit('created', this.api());
5099
5165
  },
5100
5166
  api: function api() {
5101
5167
  return this.$handle.api;
@@ -5117,7 +5183,7 @@
5117
5183
  component: component,
5118
5184
  directive: directive,
5119
5185
  register: register,
5120
- fragment: _fragment,
5186
+ $vnode: $vnode,
5121
5187
  parser: parser,
5122
5188
  use: use,
5123
5189
  factory: factory,
@@ -5126,6 +5192,7 @@
5126
5192
  copyRules: copyRules,
5127
5193
  fetch: fetch,
5128
5194
  $form: $form,
5195
+ parseFn: parseFn,
5129
5196
  parseJson: parseJson,
5130
5197
  toJson: toJson,
5131
5198
  init: function init(rules) {
@@ -5171,7 +5238,7 @@
5171
5238
  useAttr($formCreate);
5172
5239
  Vue.prototype.$formCreate = $formCreate;
5173
5240
  Vue.component('FormCreate', $form());
5174
- Vue.component('FcFragment', _fragment);
5241
+ Vue.component('FcFragment', $vnode());
5175
5242
  }
5176
5243
  });
5177
5244
  }
@@ -5560,34 +5627,12 @@
5560
5627
  return !(!title.title && !title["native"] || isFalse(title.show));
5561
5628
  },
5562
5629
  makeInfo: function makeInfo(rule, uni) {
5563
- var _this = this;
5564
5630
 
5565
5631
  var titleProp = rule.title;
5566
5632
  var infoProp = rule.info;
5567
5633
  var children = [titleProp.title];
5568
5634
 
5569
- var titleFn = function titleFn(pop) {
5570
- return _this.$r(mergeProps([titleProp, {
5571
- props: titleProp,
5572
- slot: titleProp.slot || (pop ? 'default' : 'label'),
5573
- key: "".concat(uni, "tit"),
5574
- type: titleProp.type || 'span'
5575
- }]), children);
5576
- };
5577
-
5578
- if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5579
- if (infoProp.icon !== false) {
5580
- children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5581
- type: 'icon',
5582
- props: {
5583
- type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5584
- size: 16
5585
- },
5586
- style: 'margin-top: -1px',
5587
- key: "".concat(uni, "i")
5588
- }));
5589
- }
5590
-
5635
+ if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"]) && !isFalse(infoProp.icon)) {
5591
5636
  var prop = {
5592
5637
  type: infoProp.type || 'poptip',
5593
5638
  props: _objectSpread2({}, infoProp),
@@ -5600,10 +5645,23 @@
5600
5645
  prop.props[field] = infoProp.info;
5601
5646
  }
5602
5647
 
5603
- return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5648
+ children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), [this.$r({
5649
+ type: 'icon',
5650
+ props: {
5651
+ type: infoProp.icon === true ? iviewConfig.infoIcon : infoProp.icon,
5652
+ size: 16
5653
+ },
5654
+ style: 'margin-top: -1px',
5655
+ key: "".concat(uni, "i")
5656
+ })]));
5604
5657
  }
5605
5658
 
5606
- return titleFn();
5659
+ return this.$r(mergeProps([titleProp, {
5660
+ props: titleProp,
5661
+ slot: titleProp.slot || 'label',
5662
+ key: "".concat(uni, "tit"),
5663
+ type: titleProp.type || 'span'
5664
+ }]), children);
5607
5665
  },
5608
5666
  makeCol: function makeCol(rule, uni, children) {
5609
5667
  var col = rule.col;
@@ -6033,7 +6091,7 @@
6033
6091
  function ivuFormCreate() {
6034
6092
  return FormCreateFactory({
6035
6093
  ui: "".concat("view-design"),
6036
- version: "".concat("2.5.11"),
6094
+ version: "".concat("2.5.15"),
6037
6095
  manager: manager,
6038
6096
  install: install,
6039
6097
  extendApi: extendApi,