@form-create/component-elm-group 3.1.3 → 3.1.6

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.
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.1.3
2
+ * @form-create/component-elm-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
@@ -344,6 +344,26 @@ var Group = defineComponent({
344
344
  },
345
345
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
346
346
  watch: {
347
+ rule: {
348
+ handler: function handler(n, o) {
349
+ var _this = this;
350
+
351
+ Object.keys(this.cacheRule).forEach(function (v) {
352
+ var item = _this.cacheRule[v];
353
+
354
+ if (n === o) {
355
+ deepExtend(item.rule, n);
356
+ } else {
357
+ var val = item.$f.formData();
358
+ item.$f.once('reloading', function () {
359
+ item.$f.setValue(val);
360
+ });
361
+ item.rule = deepCopy(n);
362
+ }
363
+ });
364
+ },
365
+ deep: true
366
+ },
347
367
  disabled: function disabled(n) {
348
368
  if (this.syncDisabled) {
349
369
  var lst = this.cacheRule;
@@ -361,7 +381,7 @@ var Group = defineComponent({
361
381
  },
362
382
  modelValue: {
363
383
  handler: function handler(n) {
364
- var _this = this;
384
+ var _this2 = this;
365
385
 
366
386
  n = n || [];
367
387
  var keys = Object.keys(this.cacheRule),
@@ -381,17 +401,14 @@ var Group = defineComponent({
381
401
  for (var _i2 = 0; _i2 < len; _i2++) {
382
402
  this.removeRule(keys[total - _i2 - 1]);
383
403
  }
384
-
385
- this.subForm();
386
404
  }
387
405
 
388
406
  n.forEach(function (val, i) {
389
- _this.setValue(keys[i], n[i]);
407
+ _this2.setValue(keys[i], n[i]);
390
408
  });
391
409
  }
392
410
  },
393
- deep: true,
394
- flush: 'post'
411
+ deep: true
395
412
  }
396
413
  },
397
414
  methods: {
@@ -406,7 +423,7 @@ var Group = defineComponent({
406
423
  this.$emit('change', value);
407
424
  },
408
425
  formData: function formData(key, _formData) {
409
- var _this2 = this;
426
+ var _this3 = this;
410
427
 
411
428
  var cacheRule = this.cacheRule;
412
429
  var keys = Object.keys(cacheRule);
@@ -418,10 +435,10 @@ var Group = defineComponent({
418
435
  }
419
436
 
420
437
  var value = keys.map(function (k) {
421
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
422
- var value = _this2.field ? data[_this2.field] || null : data;
438
+ var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
439
+ var value = _this3.field ? data[_this3.field] || null : data;
423
440
 
424
- _this2.cache(k, value);
441
+ _this3.cache(k, value);
425
442
 
426
443
  return value;
427
444
  });
@@ -441,7 +458,7 @@ var Group = defineComponent({
441
458
  this.cache(key, value);
442
459
  },
443
460
  addRule: function addRule(i, emit) {
444
- var _this3 = this;
461
+ var _this4 = this;
445
462
 
446
463
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
447
464
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -462,31 +479,23 @@ var Group = defineComponent({
462
479
 
463
480
  if (emit) {
464
481
  nextTick(function () {
465
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
482
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
466
483
  });
467
484
  }
468
485
  },
469
486
  add$f: function add$f(i, key, $f) {
470
- var _this4 = this;
487
+ var _this5 = this;
471
488
 
472
489
  this.cacheRule[key].$f = $f;
473
- this.subForm();
474
490
  this.formData(key, $f.formData());
475
491
  nextTick(function () {
476
- if (_this4.syncDisabled) {
477
- $f.disabled(_this4.disabled);
492
+ if (_this5.syncDisabled) {
493
+ $f.disabled(_this5.disabled);
478
494
  }
479
495
 
480
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
496
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
481
497
  });
482
498
  },
483
- subForm: function subForm() {
484
- var _this5 = this;
485
-
486
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
487
- return _this5.cacheRule[k].$f;
488
- }));
489
- },
490
499
  removeRule: function removeRule(key, emit) {
491
500
  var _this6 = this;
492
501
 
@@ -514,7 +523,6 @@ var Group = defineComponent({
514
523
  }
515
524
 
516
525
  this.removeRule(key, true);
517
- this.subForm();
518
526
  this.modelValue.splice(index, 1);
519
527
  this.input(this.modelValue);
520
528
  },
@@ -629,6 +637,7 @@ var Group = defineComponent({
629
637
  "default": function _default() {
630
638
  return [createVNode(Type, {
631
639
  "key": key,
640
+ "inFor": true,
632
641
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
633
642
  return _this9.formData(key, formData);
634
643
  },
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.1.3
2
+ * @form-create/component-elm-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
6
6
  */
7
- import{openBlock as e,createElementBlock as t,createElementVNode as n,defineComponent as r,markRaw as o,nextTick as i,createVNode as l,resolveComponent as u,isVNode as a}from"vue";function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){d(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e){return function(e){if(Array.isArray(e))return m(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return m(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return m(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var p={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===f(e)&&null!==e&&1===e.nodeType&&!p.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){p[e]=function(t){return p.type(t,e)}}));var y={name:"IconCirclePlus"},b={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},v=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];y.render=function(n,r,o,i,l,u){return e(),t("svg",b,v)};var g={name:"IconRemove"},O={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},j=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function R(e,t,n){e[t]=n}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((r=Array.isArray(i))||p.Object(i)){var l=void 0===e[o];if(r)r=!1,l&&R(e,o,[]);else if(i._clone&&void 0!==n){if(!n){R(e,o,i._clone());continue}i=i.getRule(),l&&R(e,o,{})}else l&&R(e,o,{});e[o]=V(e[o],i,n)}else R(e,o,i),p.Undef(i)||(p.Undef(i.__json)||(e[o].__json=i.__json),p.Undef(i.__origin)||(e[o].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function w(e){return V({},{value:e}).value}g.render=function(n,r,o,i,l,u){return e(),t("svg",O,j)};var x=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&R(e,r,t[r]);return e};var A=r({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:o(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),r=n.length,o=r-e.length;if(o<0){for(var i=o;i<0;i++)this.addRule(e.length+i);for(var l=0;l<r;l++)this.setValue(n[l],e[l])}else{if(o>0){for(var u=0;u<o;u++)this.removeRule(n[r-u-1]);this.subForm()}e.forEach((function(r,o){t.setValue(n[o],e[o])}))}},deep:!0,flush:"post"}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,o=Object.keys(r);if(o.filter((function(e){return r[e].$f})).length===o.length){var i=o.map((function(r){var o=e===r?t:s({},n.cacheRule[r].$f.form),i=n.field?o[n.field]||null:o;return n.cache(r,i),i}));this.input(i)}},setValue:function(e,t){var n=this.field;n&&(t=d({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,t){var n=this,r=this.formCreateInject.form.copyRules(this.rule||[]),o=this.options?s({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){o.formData||(o.formData={});var l=w(this.defaultValue);!function(){x.apply(this,arguments)}(o.formData,this.field?d({},this.field,l):l)}this.cacheRule[++this.len]={rule:r,options:o},t&&i((function(){return n.$emit("add",r,Object.keys(n.cacheRule).length-1)}))},add$f:function(e,t,n){var r=this;this.cacheRule[t].$f=n,this.subForm(),this.formData(t,n.formData()),i((function(){r.syncDisabled&&n.disabled(r.disabled),r.$emit("itemMounted",n,Object.keys(r.cacheRule).indexOf(t))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},removeRule:function(e,t){var n=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],t&&i((function(){return n.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.subForm(),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return l(u("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}})},delIcon:function(e,t){var n=this;return l(u("ElIcon"),{key:"d".concat(t),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return n.del(e,t)}},{default:function(){return[l(g,null,null)]}})},makeIcon:function(e,t,n){var r=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return r.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,r){this.$emit.apply(this,[e].concat(h(t),[this.cacheRule[r].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,t=Object.keys(this.cacheRule),n=this.button,r=this.form;return 0===t.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):l(u("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}}):l("div",{key:2},[t.map((function(o,i){var c,s=e.cacheRule[o],f=s.rule,h=s.options;return l(u("ElRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(u("ElCol"),{span:n?20:24},{default:function(){return[l(u("ElFormItem"),null,{default:function(){return[l(r,{key:o,"onUpdate:modelValue":function(t){return e.formData(o,t)},modelValue:e.field?d({},e.field,e._value(e.modelValue[i])):e.modelValue[i],"onEmit-event":function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),l=1;l<n;l++)r[l-1]=arguments[l];return e.emitEvent(t,r,i,o)},"onUpdate:api":function(t){return e.add$f(i,o,t)},rule:f,option:h,extendOption:!0},null)]}})]}}),n?l(u("ElCol"),{span:2,pull:1,push:1},(s=c=e.makeIcon(t.length,i,o),"function"==typeof s||"[object Object]"===Object.prototype.toString.call(s)&&!a(s)?c:{default:function(){return[c]}})):null];var s}})}))])}});export{A as default};
7
+ import{openBlock as e,createElementBlock as t,createElementVNode as n,defineComponent as r,markRaw as o,nextTick as i,createVNode as l,resolveComponent as a,isVNode as u}from"vue";function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function f(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){d(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var m={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===s(e)&&null!==e&&1===e.nodeType&&!m.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){m[e]=function(t){return m.type(t,e)}}));var y={name:"IconCirclePlus"},b={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},v=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];y.render=function(n,r,o,i,l,a){return e(),t("svg",b,v)};var g={name:"IconRemove"},O={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},j=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function R(e,t,n){e[t]=n}function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((r=Array.isArray(i))||m.Object(i)){var l=void 0===e[o];if(r)r=!1,l&&R(e,o,[]);else if(i._clone&&void 0!==n){if(!n){R(e,o,i._clone());continue}i=i.getRule(),l&&R(e,o,{})}else l&&R(e,o,{});e[o]=V(e[o],i,n)}else R(e,o,i),m.Undef(i)||(m.Undef(i.__json)||(e[o].__json=i.__json),m.Undef(i.__origin)||(e[o].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function w(e){return V({},{value:e}).value}g.render=function(n,r,o,i,l,a){return e(),t("svg",O,j)};var x=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&R(e,r,t[r]);return e};var A=r({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:o(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{rule:{handler:function(e,t){var n=this;Object.keys(this.cacheRule).forEach((function(r){var o=n.cacheRule[r];if(e===t)V(o.rule,e);else{var i=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(i)})),o.rule=w(e)}}))},deep:!0},disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),r=n.length,o=r-e.length;if(o<0){for(var i=o;i<0;i++)this.addRule(e.length+i);for(var l=0;l<r;l++)this.setValue(n[l],e[l])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(n[r-a-1]);e.forEach((function(r,o){t.setValue(n[o],e[o])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,o=Object.keys(r);if(o.filter((function(e){return r[e].$f})).length===o.length){var i=o.map((function(r){var o=e===r?t:f({},n.cacheRule[r].$f.form),i=n.field?o[n.field]||null:o;return n.cache(r,i),i}));this.input(i)}},setValue:function(e,t){var n=this.field;n&&(t=d({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,t){var n=this,r=this.formCreateInject.form.copyRules(this.rule||[]),o=this.options?f({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){o.formData||(o.formData={});var l=w(this.defaultValue);!function(){x.apply(this,arguments)}(o.formData,this.field?d({},this.field,l):l)}this.cacheRule[++this.len]={rule:r,options:o},t&&i((function(){return n.$emit("add",r,Object.keys(n.cacheRule).length-1)}))},add$f:function(e,t,n){var r=this;this.cacheRule[t].$f=n,this.formData(t,n.formData()),i((function(){r.syncDisabled&&n.disabled(r.disabled),r.$emit("itemMounted",n,Object.keys(r.cacheRule).indexOf(t))}))},removeRule:function(e,t){var n=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],t&&i((function(){return n.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return l(a("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}})},delIcon:function(e,t){var n=this;return l(a("ElIcon"),{key:"d".concat(t),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return n.del(e,t)}},{default:function(){return[l(g,null,null)]}})},makeIcon:function(e,t,n){var r=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return r.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,r){this.$emit.apply(this,[e].concat(h(t),[this.cacheRule[r].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,t=Object.keys(this.cacheRule),n=this.button,r=this.form;return 0===t.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):l(a("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}}):l("div",{key:2},[t.map((function(o,i){var c,f=e.cacheRule[o],s=f.rule,h=f.options;return l(a("ElRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(a("ElCol"),{span:n?20:24},{default:function(){return[l(a("ElFormItem"),null,{default:function(){return[l(r,{key:o,inFor:!0,"onUpdate:modelValue":function(t){return e.formData(o,t)},modelValue:e.field?d({},e.field,e._value(e.modelValue[i])):e.modelValue[i],"onEmit-event":function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),l=1;l<n;l++)r[l-1]=arguments[l];return e.emitEvent(t,r,i,o)},"onUpdate:api":function(t){return e.add$f(i,o,t)},rule:s,option:h,extendOption:!0},null)]}})]}}),n?l(a("ElCol"),{span:2,pull:1,push:1},(f=c=e.makeIcon(t.length,i,o),"function"==typeof f||"[object Object]"===Object.prototype.toString.call(f)&&!u(f)?c:{default:function(){return[c]}})):null];var f}})}))])}});export{A as default};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.1.3
2
+ * @form-create/component-elm-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
@@ -348,6 +348,26 @@
348
348
  },
349
349
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
350
350
  watch: {
351
+ rule: {
352
+ handler: function handler(n, o) {
353
+ var _this = this;
354
+
355
+ Object.keys(this.cacheRule).forEach(function (v) {
356
+ var item = _this.cacheRule[v];
357
+
358
+ if (n === o) {
359
+ deepExtend(item.rule, n);
360
+ } else {
361
+ var val = item.$f.formData();
362
+ item.$f.once('reloading', function () {
363
+ item.$f.setValue(val);
364
+ });
365
+ item.rule = deepCopy(n);
366
+ }
367
+ });
368
+ },
369
+ deep: true
370
+ },
351
371
  disabled: function disabled(n) {
352
372
  if (this.syncDisabled) {
353
373
  var lst = this.cacheRule;
@@ -365,7 +385,7 @@
365
385
  },
366
386
  modelValue: {
367
387
  handler: function handler(n) {
368
- var _this = this;
388
+ var _this2 = this;
369
389
 
370
390
  n = n || [];
371
391
  var keys = Object.keys(this.cacheRule),
@@ -385,17 +405,14 @@
385
405
  for (var _i2 = 0; _i2 < len; _i2++) {
386
406
  this.removeRule(keys[total - _i2 - 1]);
387
407
  }
388
-
389
- this.subForm();
390
408
  }
391
409
 
392
410
  n.forEach(function (val, i) {
393
- _this.setValue(keys[i], n[i]);
411
+ _this2.setValue(keys[i], n[i]);
394
412
  });
395
413
  }
396
414
  },
397
- deep: true,
398
- flush: 'post'
415
+ deep: true
399
416
  }
400
417
  },
401
418
  methods: {
@@ -410,7 +427,7 @@
410
427
  this.$emit('change', value);
411
428
  },
412
429
  formData: function formData(key, _formData) {
413
- var _this2 = this;
430
+ var _this3 = this;
414
431
 
415
432
  var cacheRule = this.cacheRule;
416
433
  var keys = Object.keys(cacheRule);
@@ -422,10 +439,10 @@
422
439
  }
423
440
 
424
441
  var value = keys.map(function (k) {
425
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
426
- var value = _this2.field ? data[_this2.field] || null : data;
442
+ var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
443
+ var value = _this3.field ? data[_this3.field] || null : data;
427
444
 
428
- _this2.cache(k, value);
445
+ _this3.cache(k, value);
429
446
 
430
447
  return value;
431
448
  });
@@ -445,7 +462,7 @@
445
462
  this.cache(key, value);
446
463
  },
447
464
  addRule: function addRule(i, emit) {
448
- var _this3 = this;
465
+ var _this4 = this;
449
466
 
450
467
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
451
468
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -466,31 +483,23 @@
466
483
 
467
484
  if (emit) {
468
485
  vue.nextTick(function () {
469
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
486
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
470
487
  });
471
488
  }
472
489
  },
473
490
  add$f: function add$f(i, key, $f) {
474
- var _this4 = this;
491
+ var _this5 = this;
475
492
 
476
493
  this.cacheRule[key].$f = $f;
477
- this.subForm();
478
494
  this.formData(key, $f.formData());
479
495
  vue.nextTick(function () {
480
- if (_this4.syncDisabled) {
481
- $f.disabled(_this4.disabled);
496
+ if (_this5.syncDisabled) {
497
+ $f.disabled(_this5.disabled);
482
498
  }
483
499
 
484
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
500
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
485
501
  });
486
502
  },
487
- subForm: function subForm() {
488
- var _this5 = this;
489
-
490
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
491
- return _this5.cacheRule[k].$f;
492
- }));
493
- },
494
503
  removeRule: function removeRule(key, emit) {
495
504
  var _this6 = this;
496
505
 
@@ -518,7 +527,6 @@
518
527
  }
519
528
 
520
529
  this.removeRule(key, true);
521
- this.subForm();
522
530
  this.modelValue.splice(index, 1);
523
531
  this.input(this.modelValue);
524
532
  },
@@ -633,6 +641,7 @@
633
641
  "default": function _default() {
634
642
  return [vue.createVNode(Type, {
635
643
  "key": key,
644
+ "inFor": true,
636
645
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
637
646
  return _this9.formData(key, formData);
638
647
  },
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.1.3
2
+ * @form-create/component-elm-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
6
6
  */
7
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var u={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!u.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){u[e]=function(t){return u.type(t,e)}}));var c={name:"IconCirclePlus"},s={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},f=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];c.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",s,f)};var d={name:"IconRemove"},h={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},m=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function p(e,t,n){e[t]=n}function y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,o=!1;for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];if((o=Array.isArray(i))||u.Object(i)){var l=void 0===e[r];if(o)o=!1,l&&p(e,r,[]);else if(i._clone&&void 0!==n){if(!n){p(e,r,i._clone());continue}i=i.getRule(),l&&p(e,r,{})}else l&&p(e,r,{});e[r]=y(e[r],i,n)}else p(e,r,i),u.Undef(i)||(u.Undef(i.__json)||(e[r].__json=i.__json),u.Undef(i.__origin)||(e[r].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function b(e){return y({},{value:e}).value}d.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",h,m)};var v=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&p(e,o,t[o]);return e};var g=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var i=r;i<0;i++)this.addRule(e.length+i);for(var l=0;l<o;l++)this.setValue(n[l],e[l])}else{if(r>0){for(var a=0;a<r;a++)this.removeRule(n[o-a-1]);this.subForm()}e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0,flush:"post"}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,i=Object.keys(r);if(i.filter((function(e){return r[e].$f})).length===i.length){var l=i.map((function(r){var i=e===r?t:o({},n.cacheRule[r].$f.form),l=n.field?i[n.field]||null:i;return n.cache(r,l),l}));this.input(l)}},setValue:function(e,t){var n=this.field;n&&(t=i({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var u=b(this.defaultValue);!function(){v.apply(this,arguments)}(a.formData,this.field?i({},this.field,u):u)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return r.$emit("add",l,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.subForm(),this.formData(n,o.formData()),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.subForm(),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(d,null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(l(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(t.resolveComponent("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}}):t.createVNode("div",{key:2},[n.map((function(l,a){var u,c=e.cacheRule[l],s=c.rule,f=c.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:l,"onUpdate:modelValue":function(t){return e.formData(l,t)},modelValue:e.field?i({},e.field,e._value(e.modelValue[a])):e.modelValue[a],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(c=u=e.makeIcon(n.length,a,l),"function"==typeof c||"[object Object]"===Object.prototype.toString.call(c)&&!t.isVNode(c)?u:{default:function(){return[u]}})):null];var c}})}))])}});e.default=g,Object.defineProperty(e,"__esModule",{value:!0})}));
7
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var u={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!u.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){u[e]=function(t){return u.type(t,e)}}));var c={name:"IconCirclePlus"},s={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},f=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];c.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",s,f)};var d={name:"IconRemove"},h={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},p=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function m(e,t,n){e[t]=n}function y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,o=!1;for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];if((o=Array.isArray(i))||u.Object(i)){var l=void 0===e[r];if(o)o=!1,l&&m(e,r,[]);else if(i._clone&&void 0!==n){if(!n){m(e,r,i._clone());continue}i=i.getRule(),l&&m(e,r,{})}else l&&m(e,r,{});e[r]=y(e[r],i,n)}else m(e,r,i),u.Undef(i)||(u.Undef(i.__json)||(e[r].__json=i.__json),u.Undef(i.__origin)||(e[r].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function v(e){return y({},{value:e}).value}d.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",h,p)};var b=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&m(e,o,t[o]);return e};var g=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{rule:{handler:function(e,t){var n=this;Object.keys(this.cacheRule).forEach((function(o){var r=n.cacheRule[o];if(e===t)y(r.rule,e);else{var i=r.$f.formData();r.$f.once("reloading",(function(){r.$f.setValue(i)})),r.rule=v(e)}}))},deep:!0},disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var i=r;i<0;i++)this.addRule(e.length+i);for(var l=0;l<o;l++)this.setValue(n[l],e[l])}else{if(r>0)for(var a=0;a<r;a++)this.removeRule(n[o-a-1]);e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,i=Object.keys(r);if(i.filter((function(e){return r[e].$f})).length===i.length){var l=i.map((function(r){var i=e===r?t:o({},n.cacheRule[r].$f.form),l=n.field?i[n.field]||null:i;return n.cache(r,l),l}));this.input(l)}},setValue:function(e,t){var n=this.field;n&&(t=i({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var u=v(this.defaultValue);!function(){b.apply(this,arguments)}(a.formData,this.field?i({},this.field,u):u)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return r.$emit("add",l,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.formData(n,o.formData()),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(d,null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(l(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(t.resolveComponent("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}}):t.createVNode("div",{key:2},[n.map((function(l,a){var u,c=e.cacheRule[l],s=c.rule,f=c.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:l,inFor:!0,"onUpdate:modelValue":function(t){return e.formData(l,t)},modelValue:e.field?i({},e.field,e._value(e.modelValue[a])):e.modelValue[a],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(c=u=e.makeIcon(n.length,a,l),"function"==typeof c||"[object Object]"===Object.prototype.toString.call(c)&&!t.isVNode(c)?u:{default:function(){return[u]}})):null];var c}})}))])}});e.default=g,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-create/component-elm-group",
3
- "version": "3.1.3",
3
+ "version": "3.1.6",
4
4
  "description": "@form-create/element-ui 内置组件",
5
5
  "main": "./dist/index.min.js",
6
6
  "module": "./dist/index.esm.js",
@@ -47,5 +47,5 @@
47
47
  "esm"
48
48
  ]
49
49
  },
50
- "gitHead": "7188700dc7590edc798b756d6d4d353b9b004512"
50
+ "gitHead": "9d63687a68a176d73b663191119d01271430b682"
51
51
  }
package/src/component.jsx CHANGED
@@ -2,11 +2,12 @@ import {hasProperty} from '@form-create/utils/lib/type';
2
2
  import {defineComponent, markRaw, nextTick} from 'vue';
3
3
  import IconCirclePlus from './IconCirclePlus.vue';
4
4
  import IconRemove from './IconRemove.vue';
5
- import {deepCopy} from '@form-create/utils/lib/deepextend';
5
+ import deepExtend, {deepCopy} from '@form-create/utils/lib/deepextend';
6
6
  import extend from '@form-create/utils/lib/extend';
7
7
 
8
8
  const NAME = 'fcGroup';
9
9
 
10
+
10
11
  export default defineComponent({
11
12
  name: NAME,
12
13
  props: {
@@ -65,6 +66,23 @@ export default defineComponent({
65
66
  },
66
67
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
67
68
  watch: {
69
+ rule: {
70
+ handler(n, o) {
71
+ Object.keys(this.cacheRule).forEach(v => {
72
+ const item = this.cacheRule[v];
73
+ if (n === o) {
74
+ deepExtend(item.rule, n)
75
+ } else {
76
+ const val = item.$f.formData();
77
+ item.$f.once('reloading', () => {
78
+ item.$f.setValue(val);
79
+ })
80
+ item.rule = deepCopy(n);
81
+ }
82
+ })
83
+ },
84
+ deep: true
85
+ },
68
86
  disabled(n) {
69
87
  if (this.syncDisabled) {
70
88
  const lst = this.cacheRule;
@@ -95,7 +113,6 @@ export default defineComponent({
95
113
  for (let i = 0; i < len; i++) {
96
114
  this.removeRule(keys[total - i - 1]);
97
115
  }
98
- this.subForm();
99
116
  }
100
117
  n.forEach((val, i) => {
101
118
  this.setValue(keys[i], n[i]);
@@ -103,7 +120,6 @@ export default defineComponent({
103
120
  }
104
121
  },
105
122
  deep: true,
106
- flush: 'post',
107
123
  }
108
124
  },
109
125
  methods: {
@@ -159,7 +175,6 @@ export default defineComponent({
159
175
  },
160
176
  add$f(i, key, $f) {
161
177
  this.cacheRule[key].$f = $f;
162
- this.subForm();
163
178
  this.formData(key, $f.formData());
164
179
  nextTick(() => {
165
180
  if (this.syncDisabled) {
@@ -168,9 +183,6 @@ export default defineComponent({
168
183
  this.$emit('itemMounted', $f, Object.keys(this.cacheRule).indexOf(key));
169
184
  });
170
185
  },
171
- subForm() {
172
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(k => this.cacheRule[k].$f));
173
- },
174
186
  removeRule(key, emit) {
175
187
  const index = Object.keys(this.cacheRule).indexOf(key);
176
188
  delete this.cacheRule[key];
@@ -191,7 +203,6 @@ export default defineComponent({
191
203
  return;
192
204
  }
193
205
  this.removeRule(key, true);
194
- this.subForm();
195
206
  this.modelValue.splice(index, 1);
196
207
  this.input(this.modelValue);
197
208
  },
@@ -263,7 +274,7 @@ export default defineComponent({
263
274
  return <ElRow align="middle" type="flex" key={key}
264
275
  style="border-bottom:1px dashed #DCDFE6;margin-bottom:10px;">
265
276
  <ElCol span={button ? 20 : 24}><ElFormItem><Type
266
- key={key}
277
+ key={key} inFor={true}
267
278
  onUpdate:modelValue={(formData) => this.formData(key, formData)}
268
279
  modelValue={this.field ? {[this.field]: this._value(this.modelValue[index])} : this.modelValue[index]}
269
280
  onEmit-event={(name, ...args) => this.emitEvent(name, args, index, key)}