@form-create/component-elm-group 3.2.19 → 3.2.22

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,10 +1,10 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.2.19
2
+ * @form-create/component-elm-group v3.2.22
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
6
6
  */
7
- import { defineComponent, markRaw, nextTick, createVNode, watch, mergeProps } from 'vue';
7
+ import { defineComponent, markRaw, nextTick, createVNode, mergeProps } from 'vue';
8
8
 
9
9
  function ownKeys(object, enumerableOnly) {
10
10
  var keys = Object.keys(object);
@@ -398,7 +398,7 @@ var Group = defineComponent({
398
398
  var keys = this.sort;
399
399
 
400
400
  if (keys.filter(function (k) {
401
- return cacheRule[k].$f;
401
+ return cacheRule[k] && cacheRule[k].$f;
402
402
  }).length !== keys.length) {
403
403
  return;
404
404
  }
@@ -451,6 +451,7 @@ var Group = defineComponent({
451
451
  rule: rule,
452
452
  options: options
453
453
  };
454
+ this.sort = Object.keys(this.cacheRule);
454
455
 
455
456
  if (emit) {
456
457
  nextTick(function () {
@@ -472,6 +473,7 @@ var Group = defineComponent({
472
473
  var index = Object.keys(this.cacheRule).indexOf(key);
473
474
  delete this.cacheRule[key];
474
475
  delete this.cacheValue[key];
476
+ this.sort = Object.keys(this.cacheRule);
475
477
 
476
478
  if (emit) {
477
479
  nextTick(function () {
@@ -594,15 +596,6 @@ var Group = defineComponent({
594
596
  }
595
597
  },
596
598
  created: function created() {
597
- var _this12 = this;
598
-
599
- watch(function () {
600
- return _objectSpread2({}, _this12.cacheRule);
601
- }, function (n) {
602
- _this12.sort = Object.keys(n);
603
- }, {
604
- immediate: true
605
- });
606
599
  var d = (this.expand || 0) - this.modelValue.length;
607
600
 
608
601
  for (var i = 0; i < this.modelValue.length; i++) {
@@ -614,7 +607,7 @@ var Group = defineComponent({
614
607
  }
615
608
  },
616
609
  render: function render() {
617
- var _this13 = this;
610
+ var _this12 = this;
618
611
 
619
612
  var keys = this.sort;
620
613
  var button = this.button;
@@ -628,10 +621,10 @@ var Group = defineComponent({
628
621
  "class": "_fc-group-plus-minus _fc-group-add fc-clock",
629
622
  "onClick": this.add
630
623
  }, null) : keys.map(function (key, index) {
631
- var _this13$cacheRule$key = _this13.cacheRule[key],
632
- rule = _this13$cacheRule$key.rule,
633
- options = _this13$cacheRule$key.options;
634
- var btn = button && !disabled ? _this13.makeIcon(keys.length, index, key) : [];
624
+ var _this12$cacheRule$key = _this12.cacheRule[key],
625
+ rule = _this12$cacheRule$key.rule,
626
+ options = _this12$cacheRule$key.options;
627
+ var btn = button && !disabled ? _this12.makeIcon(keys.length, index, key) : [];
635
628
  return createVNode("div", {
636
629
  "class": "_fc-group-container",
637
630
  "key": key
@@ -640,20 +633,20 @@ var Group = defineComponent({
640
633
  }, {
641
634
  disabled: disabled,
642
635
  'onUpdate:modelValue': function onUpdateModelValue(formData) {
643
- return _this13.formData(key, formData);
636
+ return _this12.formData(key, formData);
644
637
  },
645
638
  'onEmit-event': function onEmitEvent(name) {
646
639
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
647
640
  args[_key - 1] = arguments[_key];
648
641
  }
649
642
 
650
- return _this13.emitEvent(name, args, index, key);
643
+ return _this12.emitEvent(name, args, index, key);
651
644
  },
652
645
  'onUpdate:api': function onUpdateApi($f) {
653
- return _this13.add$f(index, key, $f);
646
+ return _this12.add$f(index, key, $f);
654
647
  },
655
648
  inFor: true,
656
- modelValue: _this13.field ? _defineProperty({}, _this13.field, _this13._value(_this13.modelValue[index])) : _this13.modelValue[index],
649
+ modelValue: _this12.field ? _defineProperty({}, _this12.field, _this12._value(_this12.modelValue[index])) : _this12.modelValue[index],
657
650
  rule: rule,
658
651
  option: options,
659
652
  extendOption: true
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.2.19
2
+ * @form-create/component-elm-group v3.2.22
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
6
6
  */
7
- import{defineComponent as t,markRaw as e,nextTick as r,createVNode as n,watch as o,mergeProps as i}from"vue";function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function a(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t){return function(t){if(Array.isArray(t))return f(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return f(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return f(t,e)}(t)||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 f(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var d={type:function(t,e){return Object.prototype.toString.call(t)==="[object "+e+"]"},Undef:function(t){return null==t},Element:function(t){return"object"===c(t)&&null!==t&&1===t.nodeType&&!d.Object(t)},trueArray:function(t){return Array.isArray(t)&&t.length>0},Function:function(t){var e=this.getType(t);return"Function"===e||"AsyncFunction"===e},getType:function(t){var e=Object.prototype.toString.call(t);return/^\[object (.*)\]$/.exec(e)[1]},empty:function(t){return null==t||(!(!Array.isArray(t)||!Array.isArray(t)||t.length)||"string"==typeof t&&!t)}};function p(t,e,r){t[e]=r}function h(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=!1;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var i=e[o];if((n=Array.isArray(i))||d.Object(i)){var u=void 0===t[o];if(n)n=!1,u&&p(t,o,[]);else if(i._clone&&void 0!==r){if(!r){p(t,o,i._clone());continue}i=i.getRule(),u&&p(t,o,{})}else u&&p(t,o,{});t[o]=h(t[o],i,r)}else p(t,o,i),d.Undef(i)||(d.Undef(i.__json)||(t[o].__json=i.__json),d.Undef(i.__origin)||(t[o].__origin=i.__origin))}return void 0!==r&&Array.isArray(t)?t.filter((function(t){return!t||!t.__ctrl})):t}function m(t){return h({},{value:t}).value}["Date","Object","String","Boolean","Array","Number"].forEach((function(t){d[t]=function(e){return d.type(e,t)}}));var g=Object.assign||function(t){for(var e,r=1;r<arguments.length;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&p(t,n,e[n]);return t};!function(t,e){void 0===e&&(e={});var r=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}}('._fc-group{display:flex;flex-direction:column;justify-content:center;min-height:38px;width:100%}._fc-group-disabled ._fc-group-add,._fc-group-disabled ._fc-group-btn{cursor:not-allowed}._fc-group-handle{background-color:#fff;border:1px dashed #d9d9d9;border-radius:15px;bottom:-15px;display:flex;flex-direction:row;padding:3px 8px;position:absolute;right:30px}._fc-group-btn{cursor:pointer}._fc-group-idx{align-items:center;background:#eee;border-radius:15px;bottom:-15px;display:flex;font-weight:700;height:30px;justify-content:center;left:10px;position:absolute;width:30px}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{border:1px dashed #d9d9d9;border-radius:5px;display:flex;flex-direction:column;margin:5px 5px 25px;padding:20px 20px 25px;position:relative}._fc-group-arrow{height:20px;position:relative;width:20px}._fc-group-arrow:before{border-left:2px solid #999;border-top:2px solid #999;content:"";height:9px;left:5px;position:absolute;top:8px;transform:rotate(45deg);width:9px}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{cursor:pointer;height:20px;position:relative;width:20px}._fc-group-plus-minus:after,._fc-group-plus-minus:before{background-color:#409eff;content:"";height:2px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:60%}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{border:1px solid rgba(64,158,255,.5);border-radius:15px;cursor:pointer;height:25px;width:25px}._fc-group-add._fc-group-plus-minus:after,._fc-group-add._fc-group-plus-minus:before{width:50%}');var y=t({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,sortBtn:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object,parse:Function},data:function(){return{len:0,cacheRule:{},cacheValue:{},sort:[],form:e(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove","add"],watch:{rule:{handler:function(t,e){var r=this;Object.keys(this.cacheRule).forEach((function(n){var o=r.cacheRule[n];if(o.$f){var i=o.$f.formData();if(t===e)o.$f.deferSyncValue((function(){h(o.rule,t),o.$f.setValue(i)}),!0);else{var u=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(u)})),o.rule=m(t)}}}))},deep:!0},expand:function(t){var e=t-this.modelValue.length;e>0&&this.expandRule(e)},modelValue:{handler:function(t){var e=this;t=t||[];var r=this.sort,n=r.length,o=n-t.length;if(o<0){for(var i=o;i<0;i++)this.addRule(t.length+i,!0);for(var u=0;u<n;u++)this.setValue(r[u],t[u])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(r[n-a-1]);t.forEach((function(n,o){e.setValue(r[o],t[o])}))}},deep:!0}},methods:{_value:function(t){return t&&(e=t,r=this.field,{}.hasOwnProperty.call(e,r))?t[this.field]:t;var e,r},cache:function(t,e){this.cacheValue[t]=JSON.stringify(e)},input:function(t){this.$emit("update:modelValue",t),this.$emit("change",t)},formData:function(t,e){var r=this,n=this.cacheRule,o=this.sort;if(o.filter((function(t){return n[t].$f})).length===o.length){var i=o.map((function(n){var o=t===n?e:a({},r.cacheRule[n].$f.form),i=r.field?o[r.field]||null:o;return r.cache(n,i),i}));this.input(i)}},setValue:function(t,e){var r=this.field;r&&(e=l({},r,this._value(e))),this.cacheValue[t]!==JSON.stringify(r?e[r]:e)&&(this.cacheRule[t].$f&&this.cacheRule[t].$f.coverValue(e),this.cache(t,e))},addRule:function(t,e){var n=this,o=this.formCreateInject.form.copyRules(this.rule||[]),i=this.options?a({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){i.formData||(i.formData={});var u=m(this.defaultValue);!function(){g.apply(this,arguments)}(i.formData,this.field?l({},this.field,u):u)}this.parse&&this.parse({rule:o,options:i,index:this.sort.length}),this.cacheRule[++this.len]={rule:o,options:i},e&&r((function(){return n.$emit("add",o,Object.keys(n.cacheRule).length-1)}))},add$f:function(t,e,n){var o=this;this.cacheRule[e].$f=n,r((function(){o.$emit("itemMounted",n,Object.keys(o.cacheRule).indexOf(e))}))},removeRule:function(t,e){var n=this,o=Object.keys(this.cacheRule).indexOf(t);delete this.cacheRule[t],delete this.cacheValue[t],e&&r((function(){return n.$emit("remove",o)}))},add:function(t){if(!this.disabled&&!1!==this.onBeforeAdd(this.modelValue)){var e=s(this.modelValue);e.push(this.defaultValue?m(this.defaultValue):this.field?null:{}),this.input(e)}},del:function(t,e){if(!this.disabled&&!1!==this.onBeforeRemove(this.modelValue,t)){this.removeRule(e,!0);var r=s(this.modelValue);r.splice(t,1),this.input(r)}},addIcon:function(t){return n("div",{class:"_fc-group-btn _fc-group-plus-minus",onClick:this.add},null)},delIcon:function(t,e){var r=this;return n("div",{class:"_fc-group-btn _fc-group-plus-minus _fc-group-minus",onClick:function(){return r.del(t,e)}},null)},sortUpIcon:function(t){var e=this;return n("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-up",onClick:function(){return e.changeSort(t,-1)}},null)},sortDownIcon:function(t){var e=this;return n("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-down",onClick:function(){return e.changeSort(t,1)}},null)},changeSort:function(t,e){var r=this,n=this.sort[t];this.sort[t]=this.sort[t+e],this.sort[t+e]=n,this.formCreateInject.subForm(this.sort.map((function(t){return r.cacheRule[t].$f}))),this.formData(0)},makeIcon:function(t,e,r){var n=this;if(this.$slots.button)return this.$slots.button({total:t,index:e,vm:this,key:r,del:function(){return n.del(e,r)},add:this.add});var o=[];return(!this.max||t<this.max)&&t===e+1&&o.push(this.addIcon(r)),t>this.min&&o.push(this.delIcon(e,r)),this.sortBtn&&e&&o.push(this.sortUpIcon(e)),this.sortBtn&&e!==t-1&&o.push(this.sortDownIcon(e)),o},emitEvent:function(t,e,r,n){this.$emit.apply(this,[t].concat(s(e),[this.cacheRule[n].$f,r]))},expandRule:function(t){for(var e=0;e<t;e++)this.addRule(e)}},created:function(){var t=this;o((function(){return a({},t.cacheRule)}),(function(e){t.sort=Object.keys(e)}),{immediate:!0});for(var e=(this.expand||0)-this.modelValue.length,r=0;r<this.modelValue.length;r++)this.addRule(r);e>0&&this.expandRule(e)},render:function(){var t=this,e=this.sort,r=this.button,o=this.form,u=this.disabled,a=0===e.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):n("div",{key:"a_def",class:"_fc-group-plus-minus _fc-group-add fc-clock",onClick:this.add},null):e.map((function(a,c){var s=t.cacheRule[a],f=s.rule,d=s.options,p=r&&!u?t.makeIcon(e.length,c,a):[];return n("div",{class:"_fc-group-container",key:a},[n(o,i({key:a},{disabled:u,"onUpdate:modelValue":function(e){return t.formData(a,e)},"onEmit-event":function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return t.emitEvent(e,n,c,a)},"onUpdate:api":function(e){return t.add$f(c,a,e)},inFor:!0,modelValue:t.field?l({},t.field,t._value(t.modelValue[c])):t.modelValue[c],rule:f,option:d,extendOption:!0}),null),n("div",{class:"_fc-group-idx"},[c+1]),p.length?n("div",{class:"_fc-group-handle fc-clock"},[p]):null])}));return n("div",{key:"con",class:"_fc-group "+(u?"_fc-group-disabled":"")},[a])}});export{y as default};
7
+ import{defineComponent as t,markRaw as e,nextTick as r,createVNode as n,mergeProps as o}from"vue";function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){c(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}function c(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(t,e)}(t)||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 s(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var f={type:function(t,e){return Object.prototype.toString.call(t)==="[object "+e+"]"},Undef:function(t){return null==t},Element:function(t){return"object"===a(t)&&null!==t&&1===t.nodeType&&!f.Object(t)},trueArray:function(t){return Array.isArray(t)&&t.length>0},Function:function(t){var e=this.getType(t);return"Function"===e||"AsyncFunction"===e},getType:function(t){var e=Object.prototype.toString.call(t);return/^\[object (.*)\]$/.exec(e)[1]},empty:function(t){return null==t||(!(!Array.isArray(t)||!Array.isArray(t)||t.length)||"string"==typeof t&&!t)}};function d(t,e,r){t[e]=r}function p(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=!1;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var i=e[o];if((n=Array.isArray(i))||f.Object(i)){var u=void 0===t[o];if(n)n=!1,u&&d(t,o,[]);else if(i._clone&&void 0!==r){if(!r){d(t,o,i._clone());continue}i=i.getRule(),u&&d(t,o,{})}else u&&d(t,o,{});t[o]=p(t[o],i,r)}else d(t,o,i),f.Undef(i)||(f.Undef(i.__json)||(t[o].__json=i.__json),f.Undef(i.__origin)||(t[o].__origin=i.__origin))}return void 0!==r&&Array.isArray(t)?t.filter((function(t){return!t||!t.__ctrl})):t}function h(t){return p({},{value:t}).value}["Date","Object","String","Boolean","Array","Number"].forEach((function(t){f[t]=function(e){return f.type(e,t)}}));var m=Object.assign||function(t){for(var e,r=1;r<arguments.length;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&d(t,n,e[n]);return t};!function(t,e){void 0===e&&(e={});var r=e.insertAt;if(t&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t))}}('._fc-group{display:flex;flex-direction:column;justify-content:center;min-height:38px;width:100%}._fc-group-disabled ._fc-group-add,._fc-group-disabled ._fc-group-btn{cursor:not-allowed}._fc-group-handle{background-color:#fff;border:1px dashed #d9d9d9;border-radius:15px;bottom:-15px;display:flex;flex-direction:row;padding:3px 8px;position:absolute;right:30px}._fc-group-btn{cursor:pointer}._fc-group-idx{align-items:center;background:#eee;border-radius:15px;bottom:-15px;display:flex;font-weight:700;height:30px;justify-content:center;left:10px;position:absolute;width:30px}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{border:1px dashed #d9d9d9;border-radius:5px;display:flex;flex-direction:column;margin:5px 5px 25px;padding:20px 20px 25px;position:relative}._fc-group-arrow{height:20px;position:relative;width:20px}._fc-group-arrow:before{border-left:2px solid #999;border-top:2px solid #999;content:"";height:9px;left:5px;position:absolute;top:8px;transform:rotate(45deg);width:9px}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{cursor:pointer;height:20px;position:relative;width:20px}._fc-group-plus-minus:after,._fc-group-plus-minus:before{background-color:#409eff;content:"";height:2px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:60%}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{border:1px solid rgba(64,158,255,.5);border-radius:15px;cursor:pointer;height:25px;width:25px}._fc-group-add._fc-group-plus-minus:after,._fc-group-add._fc-group-plus-minus:before{width:50%}');var g=t({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,sortBtn:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object,parse:Function},data:function(){return{len:0,cacheRule:{},cacheValue:{},sort:[],form:e(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove","add"],watch:{rule:{handler:function(t,e){var r=this;Object.keys(this.cacheRule).forEach((function(n){var o=r.cacheRule[n];if(o.$f){var i=o.$f.formData();if(t===e)o.$f.deferSyncValue((function(){p(o.rule,t),o.$f.setValue(i)}),!0);else{var u=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(u)})),o.rule=h(t)}}}))},deep:!0},expand:function(t){var e=t-this.modelValue.length;e>0&&this.expandRule(e)},modelValue:{handler:function(t){var e=this;t=t||[];var r=this.sort,n=r.length,o=n-t.length;if(o<0){for(var i=o;i<0;i++)this.addRule(t.length+i,!0);for(var u=0;u<n;u++)this.setValue(r[u],t[u])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(r[n-a-1]);t.forEach((function(n,o){e.setValue(r[o],t[o])}))}},deep:!0}},methods:{_value:function(t){return t&&(e=t,r=this.field,{}.hasOwnProperty.call(e,r))?t[this.field]:t;var e,r},cache:function(t,e){this.cacheValue[t]=JSON.stringify(e)},input:function(t){this.$emit("update:modelValue",t),this.$emit("change",t)},formData:function(t,e){var r=this,n=this.cacheRule,o=this.sort;if(o.filter((function(t){return n[t]&&n[t].$f})).length===o.length){var i=o.map((function(n){var o=t===n?e:u({},r.cacheRule[n].$f.form),i=r.field?o[r.field]||null:o;return r.cache(n,i),i}));this.input(i)}},setValue:function(t,e){var r=this.field;r&&(e=c({},r,this._value(e))),this.cacheValue[t]!==JSON.stringify(r?e[r]:e)&&(this.cacheRule[t].$f&&this.cacheRule[t].$f.coverValue(e),this.cache(t,e))},addRule:function(t,e){var n=this,o=this.formCreateInject.form.copyRules(this.rule||[]),i=this.options?u({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){i.formData||(i.formData={});var a=h(this.defaultValue);!function(){m.apply(this,arguments)}(i.formData,this.field?c({},this.field,a):a)}this.parse&&this.parse({rule:o,options:i,index:this.sort.length}),this.cacheRule[++this.len]={rule:o,options:i},this.sort=Object.keys(this.cacheRule),e&&r((function(){return n.$emit("add",o,Object.keys(n.cacheRule).length-1)}))},add$f:function(t,e,n){var o=this;this.cacheRule[e].$f=n,r((function(){o.$emit("itemMounted",n,Object.keys(o.cacheRule).indexOf(e))}))},removeRule:function(t,e){var n=this,o=Object.keys(this.cacheRule).indexOf(t);delete this.cacheRule[t],delete this.cacheValue[t],this.sort=Object.keys(this.cacheRule),e&&r((function(){return n.$emit("remove",o)}))},add:function(t){if(!this.disabled&&!1!==this.onBeforeAdd(this.modelValue)){var e=l(this.modelValue);e.push(this.defaultValue?h(this.defaultValue):this.field?null:{}),this.input(e)}},del:function(t,e){if(!this.disabled&&!1!==this.onBeforeRemove(this.modelValue,t)){this.removeRule(e,!0);var r=l(this.modelValue);r.splice(t,1),this.input(r)}},addIcon:function(t){return n("div",{class:"_fc-group-btn _fc-group-plus-minus",onClick:this.add},null)},delIcon:function(t,e){var r=this;return n("div",{class:"_fc-group-btn _fc-group-plus-minus _fc-group-minus",onClick:function(){return r.del(t,e)}},null)},sortUpIcon:function(t){var e=this;return n("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-up",onClick:function(){return e.changeSort(t,-1)}},null)},sortDownIcon:function(t){var e=this;return n("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-down",onClick:function(){return e.changeSort(t,1)}},null)},changeSort:function(t,e){var r=this,n=this.sort[t];this.sort[t]=this.sort[t+e],this.sort[t+e]=n,this.formCreateInject.subForm(this.sort.map((function(t){return r.cacheRule[t].$f}))),this.formData(0)},makeIcon:function(t,e,r){var n=this;if(this.$slots.button)return this.$slots.button({total:t,index:e,vm:this,key:r,del:function(){return n.del(e,r)},add:this.add});var o=[];return(!this.max||t<this.max)&&t===e+1&&o.push(this.addIcon(r)),t>this.min&&o.push(this.delIcon(e,r)),this.sortBtn&&e&&o.push(this.sortUpIcon(e)),this.sortBtn&&e!==t-1&&o.push(this.sortDownIcon(e)),o},emitEvent:function(t,e,r,n){this.$emit.apply(this,[t].concat(l(e),[this.cacheRule[n].$f,r]))},expandRule:function(t){for(var e=0;e<t;e++)this.addRule(e)}},created:function(){for(var t=(this.expand||0)-this.modelValue.length,e=0;e<this.modelValue.length;e++)this.addRule(e);t>0&&this.expandRule(t)},render:function(){var t=this,e=this.sort,r=this.button,i=this.form,u=this.disabled,a=0===e.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):n("div",{key:"a_def",class:"_fc-group-plus-minus _fc-group-add fc-clock",onClick:this.add},null):e.map((function(a,l){var s=t.cacheRule[a],f=s.rule,d=s.options,p=r&&!u?t.makeIcon(e.length,l,a):[];return n("div",{class:"_fc-group-container",key:a},[n(i,o({key:a},{disabled:u,"onUpdate:modelValue":function(e){return t.formData(a,e)},"onEmit-event":function(e){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return t.emitEvent(e,n,l,a)},"onUpdate:api":function(e){return t.add$f(l,a,e)},inFor:!0,modelValue:t.field?c({},t.field,t._value(t.modelValue[l])):t.modelValue[l],rule:f,option:d,extendOption:!0}),null),n("div",{class:"_fc-group-idx"},[l+1]),p.length?n("div",{class:"_fc-group-handle fc-clock"},[p]):null])}));return n("div",{key:"con",class:"_fc-group "+(u?"_fc-group-disabled":"")},[a])}});export{g as default};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.2.19
2
+ * @form-create/component-elm-group v3.2.22
3
3
  * (c) 2018-2025 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
@@ -402,7 +402,7 @@
402
402
  var keys = this.sort;
403
403
 
404
404
  if (keys.filter(function (k) {
405
- return cacheRule[k].$f;
405
+ return cacheRule[k] && cacheRule[k].$f;
406
406
  }).length !== keys.length) {
407
407
  return;
408
408
  }
@@ -455,6 +455,7 @@
455
455
  rule: rule,
456
456
  options: options
457
457
  };
458
+ this.sort = Object.keys(this.cacheRule);
458
459
 
459
460
  if (emit) {
460
461
  vue.nextTick(function () {
@@ -476,6 +477,7 @@
476
477
  var index = Object.keys(this.cacheRule).indexOf(key);
477
478
  delete this.cacheRule[key];
478
479
  delete this.cacheValue[key];
480
+ this.sort = Object.keys(this.cacheRule);
479
481
 
480
482
  if (emit) {
481
483
  vue.nextTick(function () {
@@ -598,15 +600,6 @@
598
600
  }
599
601
  },
600
602
  created: function created() {
601
- var _this12 = this;
602
-
603
- vue.watch(function () {
604
- return _objectSpread2({}, _this12.cacheRule);
605
- }, function (n) {
606
- _this12.sort = Object.keys(n);
607
- }, {
608
- immediate: true
609
- });
610
603
  var d = (this.expand || 0) - this.modelValue.length;
611
604
 
612
605
  for (var i = 0; i < this.modelValue.length; i++) {
@@ -618,7 +611,7 @@
618
611
  }
619
612
  },
620
613
  render: function render() {
621
- var _this13 = this;
614
+ var _this12 = this;
622
615
 
623
616
  var keys = this.sort;
624
617
  var button = this.button;
@@ -632,10 +625,10 @@
632
625
  "class": "_fc-group-plus-minus _fc-group-add fc-clock",
633
626
  "onClick": this.add
634
627
  }, null) : keys.map(function (key, index) {
635
- var _this13$cacheRule$key = _this13.cacheRule[key],
636
- rule = _this13$cacheRule$key.rule,
637
- options = _this13$cacheRule$key.options;
638
- var btn = button && !disabled ? _this13.makeIcon(keys.length, index, key) : [];
628
+ var _this12$cacheRule$key = _this12.cacheRule[key],
629
+ rule = _this12$cacheRule$key.rule,
630
+ options = _this12$cacheRule$key.options;
631
+ var btn = button && !disabled ? _this12.makeIcon(keys.length, index, key) : [];
639
632
  return vue.createVNode("div", {
640
633
  "class": "_fc-group-container",
641
634
  "key": key
@@ -644,20 +637,20 @@
644
637
  }, {
645
638
  disabled: disabled,
646
639
  'onUpdate:modelValue': function onUpdateModelValue(formData) {
647
- return _this13.formData(key, formData);
640
+ return _this12.formData(key, formData);
648
641
  },
649
642
  'onEmit-event': function onEmitEvent(name) {
650
643
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
651
644
  args[_key - 1] = arguments[_key];
652
645
  }
653
646
 
654
- return _this13.emitEvent(name, args, index, key);
647
+ return _this12.emitEvent(name, args, index, key);
655
648
  },
656
649
  'onUpdate:api': function onUpdateApi($f) {
657
- return _this13.add$f(index, key, $f);
650
+ return _this12.add$f(index, key, $f);
658
651
  },
659
652
  inFor: true,
660
- modelValue: _this13.field ? _defineProperty({}, _this13.field, _this13._value(_this13.modelValue[index])) : _this13.modelValue[index],
653
+ modelValue: _this12.field ? _defineProperty({}, _this12.field, _this12._value(_this12.modelValue[index])) : _this12.modelValue[index],
661
654
  rule: rule,
662
655
  option: options,
663
656
  extendOption: true
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-elm-group v3.2.19
2
+ * @form-create/component-elm-group v3.2.22
3
3
  * (c) 2018-2025 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 r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e){return o="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},o(e)}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(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 r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))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 r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var c={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===o(e)&&null!==e&&1===e.nodeType&&!c.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)}};function l(e,t,r){e[t]=r}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((n=Array.isArray(i))||c.Object(i)){var u=void 0===e[o];if(n)n=!1,u&&l(e,o,[]);else if(i._clone&&void 0!==r){if(!r){l(e,o,i._clone());continue}i=i.getRule(),u&&l(e,o,{})}else u&&l(e,o,{});e[o]=s(e[o],i,r)}else l(e,o,i),c.Undef(i)||(c.Undef(i.__json)||(e[o].__json=i.__json),c.Undef(i.__origin)||(e[o].__origin=i.__origin))}return void 0!==r&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function f(e){return s({},{value:e}).value}["Date","Object","String","Boolean","Array","Number"].forEach((function(e){c[e]=function(t){return c.type(t,e)}}));var d=Object.assign||function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&l(e,n,t[n]);return e};!function(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('._fc-group{display:flex;flex-direction:column;justify-content:center;min-height:38px;width:100%}._fc-group-disabled ._fc-group-add,._fc-group-disabled ._fc-group-btn{cursor:not-allowed}._fc-group-handle{background-color:#fff;border:1px dashed #d9d9d9;border-radius:15px;bottom:-15px;display:flex;flex-direction:row;padding:3px 8px;position:absolute;right:30px}._fc-group-btn{cursor:pointer}._fc-group-idx{align-items:center;background:#eee;border-radius:15px;bottom:-15px;display:flex;font-weight:700;height:30px;justify-content:center;left:10px;position:absolute;width:30px}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{border:1px dashed #d9d9d9;border-radius:5px;display:flex;flex-direction:column;margin:5px 5px 25px;padding:20px 20px 25px;position:relative}._fc-group-arrow{height:20px;position:relative;width:20px}._fc-group-arrow:before{border-left:2px solid #999;border-top:2px solid #999;content:"";height:9px;left:5px;position:absolute;top:8px;transform:rotate(45deg);width:9px}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{cursor:pointer;height:20px;position:relative;width:20px}._fc-group-plus-minus:after,._fc-group-plus-minus:before{background-color:#409eff;content:"";height:2px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:60%}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{border:1px solid rgba(64,158,255,.5);border-radius:15px;cursor:pointer;height:25px;width:25px}._fc-group-add._fc-group-plus-minus:after,._fc-group-add._fc-group-plus-minus:before{width:50%}');var p=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,sortBtn:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object,parse:Function},data:function(){return{len:0,cacheRule:{},cacheValue:{},sort:[],form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove","add"],watch:{rule:{handler:function(e,t){var r=this;Object.keys(this.cacheRule).forEach((function(n){var o=r.cacheRule[n];if(o.$f){var i=o.$f.formData();if(e===t)o.$f.deferSyncValue((function(){s(o.rule,e),o.$f.setValue(i)}),!0);else{var u=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(u)})),o.rule=f(e)}}}))},deep:!0},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var r=this.sort,n=r.length,o=n-e.length;if(o<0){for(var i=o;i<0;i++)this.addRule(e.length+i,!0);for(var u=0;u<n;u++)this.setValue(r[u],e[u])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(r[n-a-1]);e.forEach((function(n,o){t.setValue(r[o],e[o])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,r=this.field,{}.hasOwnProperty.call(t,r))?e[this.field]:e;var t,r},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 r=this,o=this.cacheRule,i=this.sort;if(i.filter((function(e){return o[e].$f})).length===i.length){var u=i.map((function(o){var i=e===o?t:n({},r.cacheRule[o].$f.form),u=r.field?i[r.field]||null:i;return r.cache(o,u),u}));this.input(u)}},setValue:function(e,t){var r=this.field;r&&(t=i({},r,this._value(t))),this.cacheValue[e]!==JSON.stringify(r?t[r]:t)&&(this.cacheRule[e].$f&&this.cacheRule[e].$f.coverValue(t),this.cache(e,t))},addRule:function(e,r){var o=this,u=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?n({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var c=f(this.defaultValue);!function(){d.apply(this,arguments)}(a.formData,this.field?i({},this.field,c):c)}this.parse&&this.parse({rule:u,options:a,index:this.sort.length}),this.cacheRule[++this.len]={rule:u,options:a},r&&t.nextTick((function(){return o.$emit("add",u,Object.keys(o.cacheRule).length-1)}))},add$f:function(e,r,n){var o=this;this.cacheRule[r].$f=n,t.nextTick((function(){o.$emit("itemMounted",n,Object.keys(o.cacheRule).indexOf(r))}))},removeRule:function(e,r){var n=this,o=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],r&&t.nextTick((function(){return n.$emit("remove",o)}))},add:function(e){if(!this.disabled&&!1!==this.onBeforeAdd(this.modelValue)){var t=u(this.modelValue);t.push(this.defaultValue?f(this.defaultValue):this.field?null:{}),this.input(t)}},del:function(e,t){if(!this.disabled&&!1!==this.onBeforeRemove(this.modelValue,e)){this.removeRule(t,!0);var r=u(this.modelValue);r.splice(e,1),this.input(r)}},addIcon:function(e){return t.createVNode("div",{class:"_fc-group-btn _fc-group-plus-minus",onClick:this.add},null)},delIcon:function(e,r){var n=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-plus-minus _fc-group-minus",onClick:function(){return n.del(e,r)}},null)},sortUpIcon:function(e){var r=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-up",onClick:function(){return r.changeSort(e,-1)}},null)},sortDownIcon:function(e){var r=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-down",onClick:function(){return r.changeSort(e,1)}},null)},changeSort:function(e,t){var r=this,n=this.sort[e];this.sort[e]=this.sort[e+t],this.sort[e+t]=n,this.formCreateInject.subForm(this.sort.map((function(e){return r.cacheRule[e].$f}))),this.formData(0)},makeIcon:function(e,t,r){var n=this;if(this.$slots.button)return this.$slots.button({total:e,index:t,vm:this,key:r,del:function(){return n.del(t,r)},add:this.add});var o=[];return(!this.max||e<this.max)&&e===t+1&&o.push(this.addIcon(r)),e>this.min&&o.push(this.delIcon(t,r)),this.sortBtn&&t&&o.push(this.sortUpIcon(t)),this.sortBtn&&t!==e-1&&o.push(this.sortDownIcon(t)),o},emitEvent:function(e,t,r,n){this.$emit.apply(this,[e].concat(u(t),[this.cacheRule[n].$f,r]))},expandRule:function(e){for(var t=0;t<e;t++)this.addRule(t)}},created:function(){var e=this;t.watch((function(){return n({},e.cacheRule)}),(function(t){e.sort=Object.keys(t)}),{immediate:!0});for(var r=(this.expand||0)-this.modelValue.length,o=0;o<this.modelValue.length;o++)this.addRule(o);r>0&&this.expandRule(r)},render:function(){var e=this,r=this.sort,n=this.button,o=this.form,u=this.disabled,a=0===r.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode("div",{key:"a_def",class:"_fc-group-plus-minus _fc-group-add fc-clock",onClick:this.add},null):r.map((function(a,c){var l=e.cacheRule[a],s=l.rule,f=l.options,d=n&&!u?e.makeIcon(r.length,c,a):[];return t.createVNode("div",{class:"_fc-group-container",key:a},[t.createVNode(o,t.mergeProps({key:a},{disabled:u,"onUpdate:modelValue":function(t){return e.formData(a,t)},"onEmit-event":function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return e.emitEvent(t,n,c,a)},"onUpdate:api":function(t){return e.add$f(c,a,t)},inFor:!0,modelValue:e.field?i({},e.field,e._value(e.modelValue[c])):e.modelValue[c],rule:s,option:f,extendOption:!0}),null),t.createVNode("div",{class:"_fc-group-idx"},[c+1]),d.length?t.createVNode("div",{class:"_fc-group-handle fc-clock"},[d]):null])}));return t.createVNode("div",{key:"con",class:"_fc-group "+(u?"_fc-group-disabled":"")},[a])}});e.default=p,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 r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e){return o="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},o(e)}function i(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(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 r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))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 r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var c={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===o(e)&&null!==e&&1===e.nodeType&&!c.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)}};function l(e,t,r){e[t]=r}function s(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,n=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((n=Array.isArray(i))||c.Object(i)){var u=void 0===e[o];if(n)n=!1,u&&l(e,o,[]);else if(i._clone&&void 0!==r){if(!r){l(e,o,i._clone());continue}i=i.getRule(),u&&l(e,o,{})}else u&&l(e,o,{});e[o]=s(e[o],i,r)}else l(e,o,i),c.Undef(i)||(c.Undef(i.__json)||(e[o].__json=i.__json),c.Undef(i.__origin)||(e[o].__origin=i.__origin))}return void 0!==r&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function f(e){return s({},{value:e}).value}["Date","Object","String","Boolean","Array","Number"].forEach((function(e){c[e]=function(t){return c.type(t,e)}}));var d=Object.assign||function(e){for(var t,r=1;r<arguments.length;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&l(e,n,t[n]);return e};!function(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('._fc-group{display:flex;flex-direction:column;justify-content:center;min-height:38px;width:100%}._fc-group-disabled ._fc-group-add,._fc-group-disabled ._fc-group-btn{cursor:not-allowed}._fc-group-handle{background-color:#fff;border:1px dashed #d9d9d9;border-radius:15px;bottom:-15px;display:flex;flex-direction:row;padding:3px 8px;position:absolute;right:30px}._fc-group-btn{cursor:pointer}._fc-group-idx{align-items:center;background:#eee;border-radius:15px;bottom:-15px;display:flex;font-weight:700;height:30px;justify-content:center;left:10px;position:absolute;width:30px}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{border:1px dashed #d9d9d9;border-radius:5px;display:flex;flex-direction:column;margin:5px 5px 25px;padding:20px 20px 25px;position:relative}._fc-group-arrow{height:20px;position:relative;width:20px}._fc-group-arrow:before{border-left:2px solid #999;border-top:2px solid #999;content:"";height:9px;left:5px;position:absolute;top:8px;transform:rotate(45deg);width:9px}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{cursor:pointer;height:20px;position:relative;width:20px}._fc-group-plus-minus:after,._fc-group-plus-minus:before{background-color:#409eff;content:"";height:2px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:60%}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{border:1px solid rgba(64,158,255,.5);border-radius:15px;cursor:pointer;height:25px;width:25px}._fc-group-add._fc-group-plus-minus:after,._fc-group-add._fc-group-plus-minus:before{width:50%}');var p=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,sortBtn:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object,parse:Function},data:function(){return{len:0,cacheRule:{},cacheValue:{},sort:[],form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove","add"],watch:{rule:{handler:function(e,t){var r=this;Object.keys(this.cacheRule).forEach((function(n){var o=r.cacheRule[n];if(o.$f){var i=o.$f.formData();if(e===t)o.$f.deferSyncValue((function(){s(o.rule,e),o.$f.setValue(i)}),!0);else{var u=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(u)})),o.rule=f(e)}}}))},deep:!0},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var r=this.sort,n=r.length,o=n-e.length;if(o<0){for(var i=o;i<0;i++)this.addRule(e.length+i,!0);for(var u=0;u<n;u++)this.setValue(r[u],e[u])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(r[n-a-1]);e.forEach((function(n,o){t.setValue(r[o],e[o])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,r=this.field,{}.hasOwnProperty.call(t,r))?e[this.field]:e;var t,r},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 r=this,o=this.cacheRule,i=this.sort;if(i.filter((function(e){return o[e]&&o[e].$f})).length===i.length){var u=i.map((function(o){var i=e===o?t:n({},r.cacheRule[o].$f.form),u=r.field?i[r.field]||null:i;return r.cache(o,u),u}));this.input(u)}},setValue:function(e,t){var r=this.field;r&&(t=i({},r,this._value(t))),this.cacheValue[e]!==JSON.stringify(r?t[r]:t)&&(this.cacheRule[e].$f&&this.cacheRule[e].$f.coverValue(t),this.cache(e,t))},addRule:function(e,r){var o=this,u=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?n({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var c=f(this.defaultValue);!function(){d.apply(this,arguments)}(a.formData,this.field?i({},this.field,c):c)}this.parse&&this.parse({rule:u,options:a,index:this.sort.length}),this.cacheRule[++this.len]={rule:u,options:a},this.sort=Object.keys(this.cacheRule),r&&t.nextTick((function(){return o.$emit("add",u,Object.keys(o.cacheRule).length-1)}))},add$f:function(e,r,n){var o=this;this.cacheRule[r].$f=n,t.nextTick((function(){o.$emit("itemMounted",n,Object.keys(o.cacheRule).indexOf(r))}))},removeRule:function(e,r){var n=this,o=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],this.sort=Object.keys(this.cacheRule),r&&t.nextTick((function(){return n.$emit("remove",o)}))},add:function(e){if(!this.disabled&&!1!==this.onBeforeAdd(this.modelValue)){var t=u(this.modelValue);t.push(this.defaultValue?f(this.defaultValue):this.field?null:{}),this.input(t)}},del:function(e,t){if(!this.disabled&&!1!==this.onBeforeRemove(this.modelValue,e)){this.removeRule(t,!0);var r=u(this.modelValue);r.splice(e,1),this.input(r)}},addIcon:function(e){return t.createVNode("div",{class:"_fc-group-btn _fc-group-plus-minus",onClick:this.add},null)},delIcon:function(e,r){var n=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-plus-minus _fc-group-minus",onClick:function(){return n.del(e,r)}},null)},sortUpIcon:function(e){var r=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-up",onClick:function(){return r.changeSort(e,-1)}},null)},sortDownIcon:function(e){var r=this;return t.createVNode("div",{class:"_fc-group-btn _fc-group-arrow _fc-group-down",onClick:function(){return r.changeSort(e,1)}},null)},changeSort:function(e,t){var r=this,n=this.sort[e];this.sort[e]=this.sort[e+t],this.sort[e+t]=n,this.formCreateInject.subForm(this.sort.map((function(e){return r.cacheRule[e].$f}))),this.formData(0)},makeIcon:function(e,t,r){var n=this;if(this.$slots.button)return this.$slots.button({total:e,index:t,vm:this,key:r,del:function(){return n.del(t,r)},add:this.add});var o=[];return(!this.max||e<this.max)&&e===t+1&&o.push(this.addIcon(r)),e>this.min&&o.push(this.delIcon(t,r)),this.sortBtn&&t&&o.push(this.sortUpIcon(t)),this.sortBtn&&t!==e-1&&o.push(this.sortDownIcon(t)),o},emitEvent:function(e,t,r,n){this.$emit.apply(this,[e].concat(u(t),[this.cacheRule[n].$f,r]))},expandRule:function(e){for(var t=0;t<e;t++)this.addRule(t)}},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,r=this.sort,n=this.button,o=this.form,u=this.disabled,a=0===r.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode("div",{key:"a_def",class:"_fc-group-plus-minus _fc-group-add fc-clock",onClick:this.add},null):r.map((function(a,c){var l=e.cacheRule[a],s=l.rule,f=l.options,d=n&&!u?e.makeIcon(r.length,c,a):[];return t.createVNode("div",{class:"_fc-group-container",key:a},[t.createVNode(o,t.mergeProps({key:a},{disabled:u,"onUpdate:modelValue":function(t){return e.formData(a,t)},"onEmit-event":function(t){for(var r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return e.emitEvent(t,n,c,a)},"onUpdate:api":function(t){return e.add$f(c,a,t)},inFor:!0,modelValue:e.field?i({},e.field,e._value(e.modelValue[c])):e.modelValue[c],rule:s,option:f,extendOption:!0}),null),t.createVNode("div",{class:"_fc-group-idx"},[c+1]),d.length?t.createVNode("div",{class:"_fc-group-handle fc-clock"},[d]):null])}));return t.createVNode("div",{key:"con",class:"_fc-group "+(u?"_fc-group-disabled":"")},[a])}});e.default=p,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.2.19",
3
+ "version": "3.2.22",
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": "7f6e8182998699e87103b58f2f9afa00044dd205"
50
+ "gitHead": "24a3a213a19fbfcd2235fed94c9009db4afd93a6"
51
51
  }
package/src/component.jsx CHANGED
@@ -135,7 +135,7 @@ export default defineComponent({
135
135
  formData(key, formData) {
136
136
  const cacheRule = this.cacheRule;
137
137
  const keys = this.sort;
138
- if (keys.filter(k => cacheRule[k].$f).length !== keys.length) {
138
+ if (keys.filter(k => cacheRule[k] && cacheRule[k].$f).length !== keys.length) {
139
139
  return;
140
140
  }
141
141
  const value = keys.map(k => {
@@ -170,6 +170,7 @@ export default defineComponent({
170
170
  }
171
171
  this.parse && this.parse({rule, options, index: this.sort.length});
172
172
  this.cacheRule[++this.len] = {rule, options};
173
+ this.sort = Object.keys(this.cacheRule);
173
174
  if (emit) {
174
175
  nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
175
176
  }
@@ -184,6 +185,7 @@ export default defineComponent({
184
185
  const index = Object.keys(this.cacheRule).indexOf(key);
185
186
  delete this.cacheRule[key];
186
187
  delete this.cacheValue[key];
188
+ this.sort = Object.keys(this.cacheRule);
187
189
  if (emit) {
188
190
  nextTick(() => this.$emit('remove', index));
189
191
  }
@@ -265,9 +267,6 @@ export default defineComponent({
265
267
  }
266
268
  },
267
269
  created() {
268
- watch(() => ({...this.cacheRule}), (n) => {
269
- this.sort = Object.keys(n);
270
- }, {immediate: true})
271
270
  const d = (this.expand || 0) - this.modelValue.length;
272
271
  for (let i = 0; i < this.modelValue.length; i++) {
273
272
  this.addRule(i);