@form-create/element-ui 3.2.22 → 3.2.24

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.22
2
+ * @form-create/element-ui v3.2.24
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create
5
5
  * Released under the MIT License.
@@ -2353,7 +2353,7 @@ function parseFn(fn, mode) {
2353
2353
  v.__inject = true;
2354
2354
  return v;
2355
2355
  } else if (v.indexOf('$FNX:') === 0) {
2356
- v = makeFn('function($inject){' + v.substring(5) + '}');
2356
+ v = makeFn('function($inject){\n' + v.substring(5) + '\n}');
2357
2357
  v.__json = fn;
2358
2358
  v.__inject = true;
2359
2359
  return v;
@@ -2648,6 +2648,68 @@ function convertFieldToConditions(field) {
2648
2648
  });
2649
2649
  return conditions.join(' && ');
2650
2650
  }
2651
+ function parseTemplateToTree(template) {
2652
+ var tokens = [];
2653
+ var current = '';
2654
+ var depth = 0;
2655
+
2656
+ for (var i = 0; i < template.length; i++) {
2657
+ var _char = template[i];
2658
+
2659
+ if (_char === '[') {
2660
+ if (depth === 0 && current) {
2661
+ tokens.push({
2662
+ type: 'key',
2663
+ value: current
2664
+ });
2665
+ current = '';
2666
+ }
2667
+
2668
+ depth++;
2669
+ current += _char;
2670
+ } else if (_char === ']') {
2671
+ depth--;
2672
+ current += _char;
2673
+
2674
+ if (depth === 0) {
2675
+ tokens.push({
2676
+ type: 'bracket',
2677
+ value: parseTemplateToTree(current.slice(1, -1))
2678
+ });
2679
+ current = '';
2680
+ }
2681
+ } else if (_char === '.' && depth === 0) {
2682
+ if (current) {
2683
+ tokens.push({
2684
+ type: 'key',
2685
+ value: current
2686
+ });
2687
+ current = '';
2688
+ }
2689
+ } else {
2690
+ current += _char;
2691
+ }
2692
+ }
2693
+
2694
+ if (current) {
2695
+ tokens.push({
2696
+ type: 'key',
2697
+ value: current
2698
+ });
2699
+ }
2700
+
2701
+ return tokens.map(function (token) {
2702
+ if (token.type === 'key') {
2703
+ return {
2704
+ key: token.value
2705
+ };
2706
+ } else {
2707
+ return {
2708
+ children: token.value
2709
+ };
2710
+ }
2711
+ });
2712
+ }
2651
2713
 
2652
2714
  var _getGroupInject = function getGroupInject(vm, parent) {
2653
2715
  if (!vm || vm === parent) {
@@ -2844,10 +2906,10 @@ function $FormCreate(FormCreate, components, directives) {
2844
2906
  fapi.scope.bus.$off('$loadData.$scopeForm', emit$scopeForm);
2845
2907
  }
2846
2908
 
2847
- styleEl && document.head.removeChild(styleEl);
2848
2909
  rmSubForm();
2849
2910
  data.destroyed = true;
2850
2911
  fc.unmount();
2912
+ styleEl && (styleEl.parentNode || styleEl.parentElement) && document.head.removeChild(styleEl);
2851
2913
  });
2852
2914
  onUpdated(function () {
2853
2915
  fc.updated();
@@ -3740,9 +3802,7 @@ function Api(h) {
3740
3802
 
3741
3803
  if (!config) {
3742
3804
  resolve(h.fc.loadData[name]);
3743
- }
3744
-
3745
- if (config.type === 'fetch') {
3805
+ } else if (config.type === 'fetch') {
3746
3806
  api.fetch(config).then(function (res) {
3747
3807
  resolve(res);
3748
3808
  })["catch"](inject);
@@ -4611,6 +4671,58 @@ function useInject(Handler) {
4611
4671
  if (str && typeof str === 'string' && str.indexOf('{{') > -1 && str.indexOf('}}') > -1) {
4612
4672
  var tmp = str;
4613
4673
  var vars = extractVar(str);
4674
+
4675
+ var getValue = function getValue(field) {
4676
+ var flag = false;
4677
+ var val;
4678
+
4679
+ if (group && field.indexOf('$form.') === 0) {
4680
+ var _split = field.split('.');
4681
+
4682
+ _split.shift();
4683
+
4684
+ if (hasProperty(group.value, _split[0])) {
4685
+ flag = true;
4686
+ val = get ? get({
4687
+ id: '$form.' + _split[0] + '_' + group.rule.__fc__.id,
4688
+ getValue: function getValue() {
4689
+ return deepGet(group.value, _split);
4690
+ }
4691
+ }) : deepGet(group.value, _split);
4692
+ }
4693
+ }
4694
+
4695
+ if (!flag) {
4696
+ val = get ? get(field) : _this3.fc.getLoadData(field);
4697
+ }
4698
+
4699
+ return val;
4700
+ };
4701
+
4702
+ var treeToVal = function treeToVal(tree) {
4703
+ var fields = [];
4704
+ tree.forEach(function (item) {
4705
+ if (item.key) {
4706
+ fields.push(item.key);
4707
+ } else if (item.children) {
4708
+ fields.push(treeToVal(item.children));
4709
+ }
4710
+ });
4711
+ var flag = false;
4712
+ fields.forEach(function (field, idx) {
4713
+ if (field != null && (field.indexOf('\'') === 0 || field.indexOf('"') === 0)) {
4714
+ fields[idx] = field.slice(1, -1);
4715
+ flag = true;
4716
+ }
4717
+ });
4718
+
4719
+ if (fields.length === 1 && (flag || !isNaN(Number(fields[0])))) {
4720
+ return fields[0];
4721
+ }
4722
+
4723
+ return getValue(fields.join('.'));
4724
+ };
4725
+
4614
4726
  var lastVal;
4615
4727
  vars.forEach(function (v) {
4616
4728
  var split = v.split('||');
@@ -4618,27 +4730,13 @@ function useInject(Handler) {
4618
4730
 
4619
4731
  if (field) {
4620
4732
  var def = (split[1] || '').trim();
4621
- var val;
4622
- var flag = false;
4623
-
4624
- if (group && field.indexOf('$form.') === 0) {
4625
- var _split = field.split('.');
4626
-
4627
- _split.shift();
4628
-
4629
- if (hasProperty(group.value, _split[0])) {
4630
- flag = true;
4631
- val = get ? get({
4632
- id: '$form.' + _split[0] + '_' + group.rule.__fc__.id,
4633
- getValue: function getValue() {
4634
- return deepGet(group.value, _split);
4635
- }
4636
- }) : deepGet(group.value, _split);
4637
- }
4638
- }
4733
+ var tree = parseTemplateToTree(field);
4734
+ var val = invoke(function () {
4735
+ return treeToVal(tree);
4736
+ });
4639
4737
 
4640
- if (!flag) {
4641
- val = get ? get(field, def) : _this3.fc.getLoadData(field, def);
4738
+ if ((val == null || val === '') && split.length > 1) {
4739
+ val = def;
4642
4740
  }
4643
4741
 
4644
4742
  lastVal = val;
@@ -4963,6 +5061,9 @@ extend(RuleContext.prototype, {
4963
5061
  initNone: function initNone() {
4964
5062
  this.none = !(is.Undef(this.prop.display) || !!this.prop.display);
4965
5063
  },
5064
+ hasHidden: function hasHidden() {
5065
+ return !!this.rule.hidden || (this.parent ? this.parent.hasHidden() : false);
5066
+ },
4966
5067
  injectValidate: function injectValidate() {
4967
5068
  return this.prop.validate;
4968
5069
  },
@@ -5638,10 +5739,11 @@ function useInput(Handler) {
5638
5739
 
5639
5740
  fields.reduce(function (initial, field) {
5640
5741
  var ctx = (_this3.fieldCtx[field] || []).filter(function (ctx) {
5641
- return !_this3.isIgnore(ctx.rule);
5642
- })[0] || _this3.fieldCtx[field][0];
5742
+ return !_this3.isIgnore(ctx);
5743
+ })[0];
5643
5744
 
5644
- if (_this3.isIgnore(ctx.rule)) {
5745
+ if (!ctx) {
5746
+ ctx = _this3.fieldCtx[field][0];
5645
5747
  ignoreFields.push(field);
5646
5748
  }
5647
5749
 
@@ -5652,8 +5754,8 @@ function useInput(Handler) {
5652
5754
  this.ignoreFields = ignoreFields;
5653
5755
  this.syncValue();
5654
5756
  },
5655
- isIgnore: function isIgnore(rule) {
5656
- return rule.ignore === true || rule.ignore === 'hidden' && rule.hidden || this.options.ignoreHiddenFields && rule.hidden;
5757
+ isIgnore: function isIgnore(ctx) {
5758
+ return ctx.rule.ignore === true || (ctx.rule.ignore === 'hidden' || this.options.ignoreHiddenFields) && ctx.hasHidden();
5657
5759
  },
5658
5760
  appendValue: function appendValue(rule) {
5659
5761
  if ((!rule.field || !hasProperty(this.appendData, rule.field)) && !this.options.forceCoverValue) {
@@ -6069,7 +6171,6 @@ function useContext(Handler) {
6069
6171
  }
6070
6172
 
6071
6173
  Object.keys(computedRule).forEach(function (k) {
6072
- var oldValue = undefined;
6073
6174
  var computedValue = computed(function () {
6074
6175
  var item = computedRule[k];
6075
6176
  if (!item) return undefined;
@@ -6077,7 +6178,7 @@ function useContext(Handler) {
6077
6178
  var value = _this.compute(ctx, item);
6078
6179
 
6079
6180
  if (item.linkage && value === oldValueTag) {
6080
- return oldValue;
6181
+ return oldValueTag;
6081
6182
  }
6082
6183
 
6083
6184
  return value;
@@ -6098,10 +6199,15 @@ function useContext(Handler) {
6098
6199
  }
6099
6200
 
6100
6201
  ctx.watch.push(watch(computedValue, function (n) {
6101
- oldValue = n;
6202
+ if (n === oldValueTag) {
6203
+ return;
6204
+ }
6205
+
6102
6206
  setTimeout(function () {
6103
6207
  callback(n);
6104
6208
  });
6209
+ }, {
6210
+ deep: true
6105
6211
  }));
6106
6212
  });
6107
6213
  });
@@ -6123,7 +6229,7 @@ function useContext(Handler) {
6123
6229
  if (before === false) {
6124
6230
  callback();
6125
6231
  } else {
6126
- var key = _this2.validator(value, validate);
6232
+ var key = _this2.validator(ctx, value, validate);
6127
6233
 
6128
6234
  if (!key) {
6129
6235
  if (validate.validator) {
@@ -6176,7 +6282,9 @@ function useContext(Handler) {
6176
6282
  var formatRule = Array.isArray(invalid.rule) ? invalid.rule.join(',') : '' + invalid.rule;
6177
6283
  return this.api.t(invalid.key === 'required' ? invalid.key : 'validate.' + invalid.key, (_this$api$t = {}, _defineProperty(_this$api$t, invalid.key, formatRule), _defineProperty(_this$api$t, "title", (_ctx$refRule2 = ctx.refRule) === null || _ctx$refRule2 === void 0 ? void 0 : (_ctx$refRule2$__$titl = _ctx$refRule2.__$title) === null || _ctx$refRule2$__$titl === void 0 ? void 0 : _ctx$refRule2$__$titl.value), _this$api$t));
6178
6284
  },
6179
- validator: function validator(value, validate) {
6285
+ validator: function validator(ctx, value, validate) {
6286
+ var _this3 = this;
6287
+
6180
6288
  var isEmpty = is.empty(value);
6181
6289
 
6182
6290
  if (isEmpty) {
@@ -6370,6 +6478,15 @@ function useContext(Handler) {
6370
6478
  };
6371
6479
  }
6372
6480
 
6481
+ break;
6482
+
6483
+ case 'computed':
6484
+ if (!_this3.compute(ctx, rule)) {
6485
+ return {
6486
+ v: key
6487
+ };
6488
+ }
6489
+
6373
6490
  break;
6374
6491
  }
6375
6492
  };
@@ -6381,7 +6498,7 @@ function useContext(Handler) {
6381
6498
  }
6382
6499
  },
6383
6500
  compute: function compute(ctx, item) {
6384
- var _this3 = this;
6501
+ var _this4 = this;
6385
6502
 
6386
6503
  var fn;
6387
6504
 
@@ -6407,7 +6524,7 @@ function useContext(Handler) {
6407
6524
  var field = null;
6408
6525
 
6409
6526
  if (one.variable) {
6410
- field = JSON.stringify(_this3.fc.getLoadData(one.variable) || '');
6527
+ field = JSON.stringify(_this4.fc.getLoadData(one.variable) || '');
6411
6528
  } else if (one.field) {
6412
6529
  field = convertFieldToConditions(one.field || '');
6413
6530
  } else if (!one.mode) {
@@ -6428,11 +6545,11 @@ function useContext(Handler) {
6428
6545
  flag = false;
6429
6546
  } else if (is.Function(one.handler)) {
6430
6547
  flag = invoke(function () {
6431
- return one.handler(_this3.api, ctx.rule);
6548
+ return one.handler(_this4.api, ctx.rule);
6432
6549
  });
6433
6550
  } else {
6434
6551
  flag = invoke(function () {
6435
- return new Function('$condition', '$val', '$form', '$scope', '$group', '$rule', "with($form){with($scope){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}}")).call(_this3.api.form, condition, one.value, _this3.api.top.form, _this3.api.top === _this3.api.scope ? {} : _this3.api.scope.form, group ? _this3.subRuleData[group.id] || {} : {}, ctx.rule);
6552
+ return new Function('$condition', '$val', '$form', '$scope', '$group', '$rule', "with($form){with($scope){with(this){with($group){ return $condition['".concat(one.condition, "'](").concat(field, ", ").concat(compare ? compare : '$val', "); }}}}")).call(_this4.api.form, condition, one.value, _this4.api.top.form, _this4.api.top === _this4.api.scope ? {} : _this4.api.scope.form, group ? _this4.subRuleData[group.id] || {} : {}, ctx.rule);
6436
6553
  });
6437
6554
  }
6438
6555
 
@@ -6461,27 +6578,27 @@ function useContext(Handler) {
6461
6578
 
6462
6579
  if (item.linkage) {
6463
6580
  return val ? invoke(function () {
6464
- return _this3.computeValue(item.linkage, ctx, group);
6581
+ return _this4.computeValue(item.linkage, ctx, group);
6465
6582
  }, undefined) : oldValueTag;
6466
6583
  }
6467
6584
 
6468
6585
  return val;
6469
6586
  } else if (is.Function(item)) {
6470
6587
  fn = function fn() {
6471
- return item(_this3.api.form, _this3.api);
6588
+ return item(_this4.api.form, _this4.api);
6472
6589
  };
6473
6590
  } else {
6474
6591
  var _group = ctx.getParentGroup();
6475
6592
 
6476
6593
  fn = function fn() {
6477
- return _this3.computeValue(item, ctx, _group);
6594
+ return _this4.computeValue(item, ctx, _group);
6478
6595
  };
6479
6596
  }
6480
6597
 
6481
6598
  return invoke(fn, undefined);
6482
6599
  },
6483
6600
  computeValue: function computeValue(str, ctx, group) {
6484
- var _this4 = this;
6601
+ var _this5 = this;
6485
6602
 
6486
6603
  var that = this;
6487
6604
  var formulas = Object.keys(this.fc.formulas).reduce(function (obj, k) {
@@ -6503,35 +6620,35 @@ function useContext(Handler) {
6503
6620
  return obj;
6504
6621
  }, {});
6505
6622
  return invoke(function () {
6506
- return new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', "with($form){with($scope){with(this){with($group){with($formulas){ return ".concat(str, " }}}}}")).call(_this4.api.form, formulas, _this4.api.top.form, _this4.api.top === _this4.api.scope ? {} : _this4.api.scope.form, group ? _this4.subRuleData[group.id] || {} : {}, ctx.rule, _this4.api);
6623
+ return new Function('$formulas', '$form', '$scope', '$group', '$rule', '$api', "with($form){with($scope){with(this){with($group){with($formulas){ return ".concat(str, " }}}}}")).call(_this5.api.form, formulas, _this5.api.top.form, _this5.api.top === _this5.api.scope ? {} : _this5.api.scope.form, group ? _this5.subRuleData[group.id] || {} : {}, ctx.rule, _this5.api);
6507
6624
  }, undefined);
6508
6625
  },
6509
6626
  updateChildren: function updateChildren(ctx, n, o) {
6510
- var _this5 = this;
6627
+ var _this6 = this;
6511
6628
 
6512
6629
  this.deferSyncValue(function () {
6513
6630
  o && o.forEach(function (child) {
6514
6631
  if ((n || []).indexOf(child) === -1 && child && !is.String(child) && child.__fc__ && child.__fc__.parent === ctx) {
6515
- _this5.rmCtx(child.__fc__);
6632
+ _this6.rmCtx(child.__fc__);
6516
6633
  }
6517
6634
  });
6518
6635
 
6519
6636
  if (is.trueArray(n)) {
6520
- _this5.loadChildren(n, ctx);
6637
+ _this6.loadChildren(n, ctx);
6521
6638
 
6522
- _this5.bus.$emit('update', _this5.api);
6639
+ _this6.bus.$emit('update', _this6.api);
6523
6640
  }
6524
6641
  });
6525
6642
  },
6526
6643
  rmSub: function rmSub(sub) {
6527
- var _this6 = this;
6644
+ var _this7 = this;
6528
6645
 
6529
6646
  is.trueArray(sub) && sub.forEach(function (r) {
6530
- r && r.__fc__ && _this6.rmCtx(r.__fc__);
6647
+ r && r.__fc__ && _this7.rmCtx(r.__fc__);
6531
6648
  });
6532
6649
  },
6533
6650
  rmCtx: function rmCtx(ctx) {
6534
- var _this7 = this;
6651
+ var _this8 = this;
6535
6652
 
6536
6653
  if (ctx.deleted) return;
6537
6654
  var id = ctx.id,
@@ -6560,19 +6677,19 @@ function useContext(Handler) {
6560
6677
  }
6561
6678
 
6562
6679
  this.deferSyncValue(function () {
6563
- if (!_this7.reloading) {
6680
+ if (!_this8.reloading) {
6564
6681
  if (ctx.parser.loadChildren !== false) {
6565
6682
  var children = ctx.getPending('children', ctx.rule.children);
6566
6683
 
6567
6684
  if (is.trueArray(children)) {
6568
6685
  children.forEach(function (h) {
6569
- return h.__fc__ && _this7.rmCtx(h.__fc__);
6686
+ return h && h.__fc__ && _this8.rmCtx(h.__fc__);
6570
6687
  });
6571
6688
  }
6572
6689
  }
6573
6690
 
6574
- if (ctx.root === _this7.rules) {
6575
- _this7.vm.setupState.renderRule();
6691
+ if (ctx.root === _this8.rules) {
6692
+ _this8.vm.setupState.renderRule();
6576
6693
  }
6577
6694
  }
6578
6695
  }, input);
@@ -7013,7 +7130,9 @@ function makeDirective(data, vn) {
7013
7130
  function CreateNodeFactory() {
7014
7131
  var aliasMap = {};
7015
7132
 
7016
- function CreateNode() {}
7133
+ function CreateNode(vm) {
7134
+ this.vm = vm;
7135
+ }
7017
7136
 
7018
7137
  extend(CreateNode.prototype, {
7019
7138
  make: function make(tag, data, children) {
@@ -7028,7 +7147,7 @@ function CreateNodeFactory() {
7028
7147
  }
7029
7148
  },
7030
7149
  h: function h(tag, data, children) {
7031
- var isNativeTag = getCurrentInstance().appContext.config.isNativeTag(tag);
7150
+ var isNativeTag = this.vm.appContext.config.isNativeTag(tag);
7032
7151
 
7033
7152
  if (isNativeTag) {
7034
7153
  delete data.formCreateInject;
@@ -7183,14 +7302,30 @@ var loadData = function loadData(fc) {
7183
7302
  attrs.forEach(function (attr) {
7184
7303
  if (attr && (attr.attr || attr.template)) {
7185
7304
  var fn = function fn(get) {
7305
+ var group;
7306
+
7307
+ if (rule && rule.__fc__) {
7308
+ group = rule.__fc__.getParentGroup();
7309
+ }
7310
+
7186
7311
  var value;
7187
7312
 
7188
7313
  if (attr.template) {
7189
- value = fc.$handle.loadStrVar(attr.template, get);
7314
+ value = fc.$handle.loadStrVar(attr.template, get, group ? {
7315
+ rule: rule,
7316
+ value: fc.$handle.subRuleData[group.id] || {}
7317
+ } : null);
7190
7318
  } else if (attr.handler && is.Function(attr.handler)) {
7191
7319
  value = attr.handler(get, rule, api);
7192
7320
  } else {
7193
- value = get(attr.attr, attr["default"]);
7321
+ value = fc.$handle.loadStrVar("{{".concat(attr.attr, "}}"), get, group ? {
7322
+ rule: rule,
7323
+ value: fc.$handle.subRuleData[group.id] || {}
7324
+ } : null);
7325
+ }
7326
+
7327
+ if ((value == null || value === '') && attr["default"] != null) {
7328
+ value = attr["default"];
7194
7329
  }
7195
7330
 
7196
7331
  if (attr.copy !== false) {
@@ -8326,7 +8461,7 @@ function FormCreateFactory(config) {
8326
8461
 
8327
8462
  if (!unwatch[id]) {
8328
8463
  return;
8329
- } else if (JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
8464
+ } else if ((temp instanceof Function || is.Object(temp) || Array.isArray(temp)) && temp === unwatch[id].val || JSON.stringify(temp) !== JSON.stringify(unwatch[id].val)) {
8330
8465
  unwatch[id].val = temp;
8331
8466
  run(true);
8332
8467
  }
@@ -9468,7 +9603,7 @@ function install(FormCreate) {
9468
9603
  function elmFormCreate() {
9469
9604
  return FormCreateFactory({
9470
9605
  ui: 'element-ui',
9471
- version: '3.2.22',
9606
+ version: '3.2.24',
9472
9607
  manager: manager,
9473
9608
  extendApi: extendApi,
9474
9609
  install: install,