@volverjs/ui-vue 0.0.10-beta.24 → 0.0.10-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { inject, computed, toRef, unref, defineComponent, useAttrs, toRefs, ref, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, provide, watchEffect, reactive, Fragment, renderList, createBlock, mergeProps, withCtx } from "vue";
1
+ import { inject, computed, toRef, unref, defineComponent, useAttrs, toRefs, ref, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, provide, watchEffect, reactive, onMounted, nextTick, Fragment, renderList, createBlock, mergeProps, createSlots, withCtx } from "vue";
2
2
  import mitt from "mitt";
3
3
  import { uid } from "uid";
4
4
  import { useVModel, useLocalStorage } from "@vueuse/core";
@@ -567,7 +567,8 @@ const VvAccordionGroupProps = {
567
567
  * VModel
568
568
  */
569
569
  modelValue: {
570
- type: [String, Array]
570
+ type: [String, Array],
571
+ default: void 0
571
572
  },
572
573
  /**
573
574
  * Accordion items
@@ -624,7 +625,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
624
625
  }
625
626
  });
626
627
  const accordionNames = reactive(/* @__PURE__ */ new Set());
627
- let modelValue = ref(/* @__PURE__ */ new Set());
628
+ let storeModelValue = ref();
628
629
  watch(
629
630
  () => props.storeKey,
630
631
  (newKey, oldKey) => {
@@ -632,69 +633,83 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
632
633
  localStorage.removeItem(oldKey);
633
634
  }
634
635
  if (newKey) {
635
- modelValue = useLocalStorage(newKey, modelValue.value);
636
+ storeModelValue = useLocalStorage(newKey, storeModelValue.value);
636
637
  return;
637
638
  }
638
- modelValue = ref(new Set(modelValue.value));
639
- },
640
- { immediate: true }
641
- );
642
- watch(
643
- [modelValue, accordionNames, () => props.not, () => props.collapse],
644
- () => {
645
- if (props.not) {
646
- emit(
647
- "update:modelValue",
648
- [...accordionNames].filter(
649
- (name) => !modelValue.value.has(name)
650
- )
651
- );
652
- return;
653
- }
654
- if (props.collapse) {
655
- emit("update:modelValue", [...modelValue.value]);
656
- return;
657
- }
658
- emit("update:modelValue", modelValue.value.values().next().value);
639
+ storeModelValue = ref(storeModelValue.value);
659
640
  },
660
641
  {
661
- deep: true,
662
642
  immediate: true
663
643
  }
664
644
  );
665
- watch(
666
- () => props.modelValue,
667
- (newValue, oldValue) => {
668
- if (newValue === void 0 || newValue === null || JSON.stringify(newValue) === JSON.stringify(oldValue)) {
669
- return;
645
+ const localModelValue = computed({
646
+ get: () => {
647
+ if (props.modelValue !== null && props.modelValue !== void 0) {
648
+ return props.modelValue;
649
+ }
650
+ return storeModelValue.value;
651
+ },
652
+ set: (newValue) => {
653
+ emit("update:modelValue", newValue);
654
+ storeModelValue.value = newValue;
655
+ }
656
+ });
657
+ const expandedAccordions = computed({
658
+ get: () => {
659
+ if (localModelValue.value === void 0) {
660
+ return /* @__PURE__ */ new Set();
670
661
  }
671
662
  let toReturn = /* @__PURE__ */ new Set();
672
663
  if (props.not) {
673
- if (typeof newValue === "string") {
664
+ if (typeof localModelValue.value === "string") {
674
665
  toReturn = new Set(
675
- [...accordionNames].filter((name) => name !== newValue)
666
+ [...accordionNames].filter(
667
+ (name) => name !== localModelValue.value
668
+ )
676
669
  );
677
- } else if (Array.isArray(newValue)) {
670
+ } else if (Array.isArray(localModelValue.value)) {
678
671
  toReturn = new Set(
679
672
  [...accordionNames].filter(
680
- (name) => !newValue.includes(name)
673
+ (name) => !localModelValue.value.includes(
674
+ name
675
+ )
681
676
  )
682
677
  );
683
678
  }
684
- } else if (typeof newValue === "string") {
685
- toReturn = /* @__PURE__ */ new Set([newValue]);
686
- } else if (Array.isArray(newValue)) {
687
- toReturn = new Set(newValue);
679
+ } else if (typeof localModelValue.value === "string") {
680
+ toReturn = /* @__PURE__ */ new Set([localModelValue.value]);
681
+ } else if (Array.isArray(localModelValue.value)) {
682
+ toReturn = new Set(localModelValue.value);
688
683
  }
689
- for (const name of accordionNames) {
690
- bus.emit("toggle", { name, value: toReturn.has(name) });
691
- }
692
- modelValue.value = toReturn;
684
+ return toReturn;
693
685
  },
694
- {
695
- immediate: true
686
+ set: (newValue) => {
687
+ if (props.not) {
688
+ localModelValue.value = [...accordionNames].filter(
689
+ (name) => !newValue.has(name)
690
+ );
691
+ return;
692
+ }
693
+ if (props.collapse) {
694
+ localModelValue.value = [...newValue];
695
+ return;
696
+ }
697
+ localModelValue.value = newValue.values().next().value;
696
698
  }
697
- );
699
+ });
700
+ onMounted(() => {
701
+ if (props.not && localModelValue.value === void 0) {
702
+ localModelValue.value = props.collapse ? [] : [...accordionNames.values()].splice(1, accordionNames.size);
703
+ }
704
+ nextTick(() => {
705
+ for (const name of accordionNames) {
706
+ bus.emit("toggle", {
707
+ name,
708
+ value: expandedAccordions.value.has(name)
709
+ });
710
+ }
711
+ });
712
+ });
698
713
  const bus = mitt();
699
714
  useProvideGroupState(INJECTION_KEY_ACCORDION_GROUP, {
700
715
  disabled,
@@ -708,19 +723,22 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
708
723
  accordionNames.delete(name);
709
724
  });
710
725
  bus.on("toggle", ({ name, value }) => {
726
+ const newValue = new Set(expandedAccordions.value);
711
727
  if (value) {
712
728
  if (!props.collapse) {
713
- for (const item of modelValue.value) {
729
+ for (const item of newValue) {
714
730
  if (item !== name) {
715
731
  bus.emit("toggle", { name: item, value: false });
716
732
  }
717
733
  }
718
- modelValue.value.clear();
734
+ newValue.clear();
719
735
  }
720
- modelValue.value.add(name);
736
+ newValue.add(name);
737
+ expandedAccordions.value = newValue;
721
738
  return;
722
739
  }
723
- modelValue.value.delete(name);
740
+ newValue.delete(name);
741
+ expandedAccordions.value = newValue;
724
742
  });
725
743
  const expand = (name) => {
726
744
  if (typeof name === "string") {
@@ -754,7 +772,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
754
772
  }
755
773
  };
756
774
  bus.on("collapse", ({ name }) => collapse(name));
757
- __expose({ modelValue, expand, collapse });
775
+ __expose({ expandedAccordions, expand, collapse });
758
776
  const bemCssClasses = useModifiers(
759
777
  "vv-accordion-group",
760
778
  modifiers,
@@ -770,7 +788,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
770
788
  },
771
789
  [
772
790
  renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({
773
- modelValue: unref(modelValue),
791
+ expandedAccordions: unref(expandedAccordions),
774
792
  expand,
775
793
  collapse
776
794
  })), () => [
@@ -787,16 +805,25 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
787
805
  title: item.title,
788
806
  content: item.content
789
807
  }),
790
- {
791
- header: withCtx((data) => [
792
- renderSlot(_ctx.$slots, `header::${item.name}`, normalizeProps(guardReactiveProps(data)))
793
- ]),
794
- details: withCtx((data) => [
795
- renderSlot(_ctx.$slots, `details::${item.name}`, normalizeProps(guardReactiveProps(data)))
796
- ]),
808
+ createSlots({
797
809
  _: 2
798
810
  /* DYNAMIC */
799
- },
811
+ }, [
812
+ _ctx.$slots[`summary::${item.name}`] ? {
813
+ name: "summary",
814
+ fn: withCtx((data) => [
815
+ renderSlot(_ctx.$slots, `summary::${item.name}`, normalizeProps(guardReactiveProps(data)))
816
+ ]),
817
+ key: "0"
818
+ } : void 0,
819
+ _ctx.$slots[`content::${item.name}`] ? {
820
+ name: "default",
821
+ fn: withCtx((data) => [
822
+ renderSlot(_ctx.$slots, `content::${item.name}`, normalizeProps(guardReactiveProps(data)))
823
+ ]),
824
+ key: "1"
825
+ } : void 0
826
+ ]),
800
827
  1040
801
828
  /* FULL_PROPS, DYNAMIC_SLOTS */
802
829
  );
@@ -1 +1 @@
1
- !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("vue"),require("mitt"),require("uid"),require("@vueuse/core")):"function"==typeof define&&define.amd?define(["vue","mitt","uid","@vueuse/core"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).VvAccordionGroup=o(e.vue,e.mitt,e.uid,e.core)}(this,(function(e,o,t,a){"use strict";var n=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(n||{}),r=(e=>(e.before="before",e.after="after",e))(r||{}),l=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(l||{}),i=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(i||{});const u=Symbol.for("accordionGroup"),s=(Boolean,Boolean,Boolean,Boolean,{modifiers:{type:[String,Array],default:void 0}});r.before,n.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,l.button,i.button;const d={...s,name:String,title:String,content:String,modelValue:{type:Boolean,default:void 0},disabled:Boolean,not:Boolean};function c(o){const{group:t,isInGroup:a}=function(o){const t=e.inject(o,void 0),a=e.computed((()=>void 0!==t));return{group:t,isInGroup:a,getGroupOrLocalRef:function(o,a,n){const r=null==t?void 0:t[o];if(r)return e.computed({get:()=>r.value,set(e){r.value=e}});const l=e.toRef(a,o);return e.computed({get:()=>l.value,set(e){n&&n(`update:${o}`,e)}})}}}(u),n=e.computed((()=>Boolean(o.disabled||(null==t?void 0:t.disabled.value)))),r=e.computed((()=>{let e=o.modifiers,a=null==t?void 0:t.modifiers.value;const n=new Set;return e&&(Array.isArray(e)||(e=e.split(" ")),e.forEach((e=>n.add(e)))),a&&(Array.isArray(a)||(a=a.split(" ")),a.forEach((e=>n.add(e)))),Array.from(n)}));return{isInGroup:a,group:t,modifiers:r,disabled:n,bus:null==t?void 0:t.bus}}function m(o,t,a){return e.computed((()=>{const n={[o]:!0},r="string"==typeof(null==t?void 0:t.value)?t.value.split(" "):null==t?void 0:t.value;return r&&Array.isArray(r)&&r.forEach((e=>{e&&(n[`${o}--${e}`]=!0)})),a&&Object.keys(a.value).forEach((t=>{n[`${o}--${t}`]=e.unref(a.value[t])})),n}))}const p=["id","open"],f=["aria-controls","aria-expanded"],v=["aria-hidden"],g=e.defineComponent({name:"VvAccordion",props:d,emits:["update:modelValue"],setup(o,{expose:n,emit:r}){const l=o,i=e.useAttrs(),u=r,s=a.useVModel(l,"modelValue",u),d=e.computed((()=>l.name||(null==i?void 0:i.id)||t.uid())),{title:g,content:y,not:b}=e.toRefs(l),{isInGroup:B,modifiers:S,disabled:x,bus:A}=c(l),h=e.ref(!1);e.watch(s,(e=>{"boolean"==typeof e&&(h.value=b.value?!e:e)}),{immediate:!0}),e.watch(h,(e=>{s.value=b.value?!e:e})),null==A||A.on("toggle",(({name:e,value:o})=>{e===d.value&&(h.value=o)}));const V=()=>{x.value||(B.value?null==A||A.emit("toggle",{name:d.value,value:!h.value}):h.value=!h.value)};e.watch(d,((e,o)=>{A&&(o&&o!==e&&A.emit("unregister",{name:o}),A.emit("register",{name:e}))}),{immediate:!0}),e.onBeforeUnmount((()=>{A&&A.emit("unregister",{name:d.value})}));const w=()=>{h.value||V()},E=()=>{h.value&&V()},k=e=>{A?A.emit("expand",{name:e}):console.warn(`[VvAccordion]: You are trying to expand accordion group of "${d.value}" but it is not in a group`)},$=e=>{A?null==A||A.emit("collapse",{name:e}):console.warn(`[VvAccordion]: You are trying to collapse accordion group of "${d.value}" but it is not in a group`)};n({isExpanded:h,expand:w,collapse:E,groupExpand:k,groupCollapse:$});const P=m("vv-accordion",S,e.computed((()=>({disabled:x.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("details",{id:e.unref(d),class:e.normalizeClass(e.unref(P)),open:e.unref(h)},[e.createElementVNode("summary",{"aria-controls":e.unref(d),"aria-expanded":e.unref(h),class:"vv-accordion__summary",onClick:t[0]||(t[0]=e.withModifiers((e=>V()),["prevent"]))},[e.renderSlot(o.$slots,"summary",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(h),expand:w,collapse:E,groupExpand:k,groupCollapse:$})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(g)),1)]))],8,f),e.createElementVNode("div",{"aria-hidden":!e.unref(h),class:"vv-accordion__content"},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(h),expand:w,collapse:E,groupExpand:k,groupCollapse:$})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(y)),1)]))],8,v)],10,p))}}),y={...s,modelValue:{type:[String,Array]},items:{type:Array,default:()=>[]},collapse:Boolean,itemModifiers:{type:[String,Array],default:""},disabled:Boolean,not:Boolean,storeKey:String};return e.defineComponent({name:"VvAccordionGroup",props:y,emits:["update:modelValue"],setup(t,{expose:n,emit:r}){const l=t,i=r,{disabled:s,modifiers:d,itemModifiers:c,items:p}=e.toRefs(l);e.watchEffect((()=>{"string"==typeof l.modelValue&&l.collapse&&console.warn("[VvAccordionGroup]: modelValue is a string but collapse is true.")}));const f=e.reactive(new Set);let v=e.ref(new Set);e.watch((()=>l.storeKey),((o,t)=>{t&&t!==o&&localStorage.removeItem(t),v=o?a.useLocalStorage(o,v.value):e.ref(new Set(v.value))}),{immediate:!0}),e.watch([v,f,()=>l.not,()=>l.collapse],(()=>{l.not?i("update:modelValue",[...f].filter((e=>!v.value.has(e)))):l.collapse?i("update:modelValue",[...v.value]):i("update:modelValue",v.value.values().next().value)}),{deep:!0,immediate:!0}),e.watch((()=>l.modelValue),((e,o)=>{if(null==e||JSON.stringify(e)===JSON.stringify(o))return;let t=new Set;l.not?"string"==typeof e?t=new Set([...f].filter((o=>o!==e))):Array.isArray(e)&&(t=new Set([...f].filter((o=>!e.includes(o))))):"string"==typeof e?t=new Set([e]):Array.isArray(e)&&(t=new Set(e));for(const a of f)y.emit("toggle",{name:a,value:t.has(a)});v.value=t}),{immediate:!0});const y=o();var b,B;b=u,B={disabled:s,modifiers:c,bus:y},e.provide(b,B),y.on("register",(({name:e})=>{f.add(e)})),y.on("unregister",(({name:e})=>{f.delete(e)})),y.on("toggle",(({name:e,value:o})=>{if(o){if(!l.collapse){for(const o of v.value)o!==e&&y.emit("toggle",{name:o,value:!1});v.value.clear()}v.value.add(e)}else v.value.delete(e)}));const S=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)y.emit("toggle",{name:o,value:!0});else for(const o of f)y.emit("toggle",{name:o,value:!0});else y.emit("toggle",{name:e,value:!0})};y.on("expand",(({name:e})=>S(e)));const x=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)y.emit("toggle",{name:o,value:!1});else for(const o of f)y.emit("toggle",{name:o,value:!1});else y.emit("toggle",{name:e,value:!1})};y.on("collapse",(({name:e})=>x(e))),n({modelValue:v,expand:S,collapse:x});const A=m("vv-accordion-group",d,e.computed((()=>({disabled:s.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(A))},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({modelValue:e.unref(v),expand:S,collapse:x})),(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p),(t=>(e.openBlock(),e.createBlock(g,e.mergeProps({key:t.title},{name:t.name,title:t.title,content:t.content}),{header:e.withCtx((a=>[e.renderSlot(o.$slots,`header::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),details:e.withCtx((a=>[e.renderSlot(o.$slots,`details::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),_:2},1040)))),128))]))],2))}})}));
1
+ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("vue"),require("mitt"),require("uid"),require("@vueuse/core")):"function"==typeof define&&define.amd?define(["vue","mitt","uid","@vueuse/core"],o):(e="undefined"!=typeof globalThis?globalThis:e||self).VvAccordionGroup=o(e.vue,e.mitt,e.uid,e.core)}(this,(function(e,o,t,a){"use strict";var n=(e=>(e.left="left",e.right="right",e.top="top",e.bottom="bottom",e))(n||{}),l=(e=>(e.before="before",e.after="after",e))(l||{}),r=(e=>(e.button="button",e.submit="submit",e.reset="reset",e))(r||{}),i=(e=>(e.nuxtLink="nuxt-link",e.routerLink="router-link",e.a="a",e.button="button",e))(i||{});const u=Symbol.for("accordionGroup"),s=(Boolean,Boolean,Boolean,Boolean,{modifiers:{type:[String,Array],default:void 0}});l.before,n.bottom,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,r.button,i.button;const d={...s,name:String,title:String,content:String,modelValue:{type:Boolean,default:void 0},disabled:Boolean,not:Boolean};function c(o){const{group:t,isInGroup:a}=function(o){const t=e.inject(o,void 0),a=e.computed((()=>void 0!==t));return{group:t,isInGroup:a,getGroupOrLocalRef:function(o,a,n){const l=null==t?void 0:t[o];if(l)return e.computed({get:()=>l.value,set(e){l.value=e}});const r=e.toRef(a,o);return e.computed({get:()=>r.value,set(e){n&&n(`update:${o}`,e)}})}}}(u),n=e.computed((()=>Boolean(o.disabled||(null==t?void 0:t.disabled.value)))),l=e.computed((()=>{let e=o.modifiers,a=null==t?void 0:t.modifiers.value;const n=new Set;return e&&(Array.isArray(e)||(e=e.split(" ")),e.forEach((e=>n.add(e)))),a&&(Array.isArray(a)||(a=a.split(" ")),a.forEach((e=>n.add(e)))),Array.from(n)}));return{isInGroup:a,group:t,modifiers:l,disabled:n,bus:null==t?void 0:t.bus}}function m(o,t,a){return e.computed((()=>{const n={[o]:!0},l="string"==typeof(null==t?void 0:t.value)?t.value.split(" "):null==t?void 0:t.value;return l&&Array.isArray(l)&&l.forEach((e=>{e&&(n[`${o}--${e}`]=!0)})),a&&Object.keys(a.value).forEach((t=>{n[`${o}--${t}`]=e.unref(a.value[t])})),n}))}const p=["id","open"],v=["aria-controls","aria-expanded"],f=["aria-hidden"],g=e.defineComponent({name:"VvAccordion",props:d,emits:["update:modelValue"],setup(o,{expose:n,emit:l}){const r=o,i=e.useAttrs(),u=l,s=a.useVModel(r,"modelValue",u),d=e.computed((()=>r.name||(null==i?void 0:i.id)||t.uid())),{title:g,content:y,not:b}=e.toRefs(r),{isInGroup:x,modifiers:A,disabled:B,bus:S}=c(r),V=e.ref(!1);e.watch(s,(e=>{"boolean"==typeof e&&(V.value=b.value?!e:e)}),{immediate:!0}),e.watch(V,(e=>{s.value=b.value?!e:e})),null==S||S.on("toggle",(({name:e,value:o})=>{e===d.value&&(V.value=o)}));const h=()=>{B.value||(x.value?null==S||S.emit("toggle",{name:d.value,value:!V.value}):V.value=!V.value)};e.watch(d,((e,o)=>{S&&(o&&o!==e&&S.emit("unregister",{name:o}),S.emit("register",{name:e}))}),{immediate:!0}),e.onBeforeUnmount((()=>{S&&S.emit("unregister",{name:d.value})}));const w=()=>{V.value||h()},k=()=>{V.value&&h()},$=e=>{S?S.emit("expand",{name:e}):console.warn(`[VvAccordion]: You are trying to expand accordion group of "${d.value}" but it is not in a group`)},E=e=>{S?null==S||S.emit("collapse",{name:e}):console.warn(`[VvAccordion]: You are trying to collapse accordion group of "${d.value}" but it is not in a group`)};n({isExpanded:V,expand:w,collapse:k,groupExpand:$,groupCollapse:E});const P=m("vv-accordion",A,e.computed((()=>({disabled:B.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("details",{id:e.unref(d),class:e.normalizeClass(e.unref(P)),open:e.unref(V)},[e.createElementVNode("summary",{"aria-controls":e.unref(d),"aria-expanded":e.unref(V),class:"vv-accordion__summary",onClick:t[0]||(t[0]=e.withModifiers((e=>h()),["prevent"]))},[e.renderSlot(o.$slots,"summary",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(V),expand:w,collapse:k,groupExpand:$,groupCollapse:E})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(g)),1)]))],8,v),e.createElementVNode("div",{"aria-hidden":!e.unref(V),class:"vv-accordion__content"},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({isExpanded:e.unref(V),expand:w,collapse:k,groupExpand:$,groupCollapse:E})),(()=>[e.createTextVNode(e.toDisplayString(e.unref(y)),1)]))],8,f)],10,p))}}),y={...s,modelValue:{type:[String,Array],default:void 0},items:{type:Array,default:()=>[]},collapse:Boolean,itemModifiers:{type:[String,Array],default:""},disabled:Boolean,not:Boolean,storeKey:String};return e.defineComponent({name:"VvAccordionGroup",props:y,emits:["update:modelValue"],setup(t,{expose:n,emit:l}){const r=t,i=l,{disabled:s,modifiers:d,itemModifiers:c,items:p}=e.toRefs(r);e.watchEffect((()=>{"string"==typeof r.modelValue&&r.collapse&&console.warn("[VvAccordionGroup]: modelValue is a string but collapse is true.")}));const v=e.reactive(new Set);let f=e.ref();e.watch((()=>r.storeKey),((o,t)=>{t&&t!==o&&localStorage.removeItem(t),f=o?a.useLocalStorage(o,f.value):e.ref(f.value)}),{immediate:!0});const y=e.computed({get:()=>null!==r.modelValue&&void 0!==r.modelValue?r.modelValue:f.value,set:e=>{i("update:modelValue",e),f.value=e}}),b=e.computed({get:()=>{if(void 0===y.value)return new Set;let e=new Set;return r.not?"string"==typeof y.value?e=new Set([...v].filter((e=>e!==y.value))):Array.isArray(y.value)&&(e=new Set([...v].filter((e=>!y.value.includes(e))))):"string"==typeof y.value?e=new Set([y.value]):Array.isArray(y.value)&&(e=new Set(y.value)),e},set:e=>{r.not?y.value=[...v].filter((o=>!e.has(o))):r.collapse?y.value=[...e]:y.value=e.values().next().value}});e.onMounted((()=>{r.not&&void 0===y.value&&(y.value=r.collapse?[]:[...v.values()].splice(1,v.size)),e.nextTick((()=>{for(const e of v)x.emit("toggle",{name:e,value:b.value.has(e)})}))}));const x=o();var A,B;A=u,B={disabled:s,modifiers:c,bus:x},e.provide(A,B),x.on("register",(({name:e})=>{v.add(e)})),x.on("unregister",(({name:e})=>{v.delete(e)})),x.on("toggle",(({name:e,value:o})=>{const t=new Set(b.value);if(o){if(!r.collapse){for(const o of t)o!==e&&x.emit("toggle",{name:o,value:!1});t.clear()}return t.add(e),void(b.value=t)}t.delete(e),b.value=t}));const S=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)x.emit("toggle",{name:o,value:!0});else for(const o of v)x.emit("toggle",{name:o,value:!0});else x.emit("toggle",{name:e,value:!0})};x.on("expand",(({name:e})=>S(e)));const V=e=>{if("string"!=typeof e)if(Array.isArray(e))for(const o of e)x.emit("toggle",{name:o,value:!1});else for(const o of v)x.emit("toggle",{name:o,value:!1});else x.emit("toggle",{name:e,value:!1})};x.on("collapse",(({name:e})=>V(e))),n({expandedAccordions:b,expand:S,collapse:V});const h=m("vv-accordion-group",d,e.computed((()=>({disabled:s.value}))));return(o,t)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(h))},[e.renderSlot(o.$slots,"default",e.normalizeProps(e.guardReactiveProps({expandedAccordions:e.unref(b),expand:S,collapse:V})),(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p),(t=>(e.openBlock(),e.createBlock(g,e.mergeProps({key:t.title},{name:t.name,title:t.title,content:t.content}),e.createSlots({_:2},[o.$slots[`summary::${t.name}`]?{name:"summary",fn:e.withCtx((a=>[e.renderSlot(o.$slots,`summary::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),key:"0"}:void 0,o.$slots[`content::${t.name}`]?{name:"default",fn:e.withCtx((a=>[e.renderSlot(o.$slots,`content::${t.name}`,e.normalizeProps(e.guardReactiveProps(a)))])),key:"1"}:void 0]),1040)))),128))]))],2))}})}));
@@ -1,6 +1,7 @@
1
1
  declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
2
2
  modelValue: {
3
3
  type: globalThis.PropType<string | string[] | undefined>;
4
+ default: undefined;
4
5
  };
5
6
  items: {
6
7
  type: globalThis.PropType<import(".").VvAccordionGroupItem[]>;
@@ -19,7 +20,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
19
20
  default: undefined;
20
21
  };
21
22
  }, {
22
- modelValue: globalThis.Ref<Set<string> & Omit<Set<string>, keyof Set<any>>>;
23
+ expandedAccordions: globalThis.WritableComputedRef<Set<string>>;
23
24
  expand: (name?: string | string[]) => void;
24
25
  collapse: (name?: string | string[]) => void;
25
26
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
@@ -27,6 +28,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
27
28
  }, string, import("vue").PublicProps, Readonly<globalThis.ExtractPropTypes<{
28
29
  modelValue: {
29
30
  type: globalThis.PropType<string | string[] | undefined>;
31
+ default: undefined;
30
32
  };
31
33
  items: {
32
34
  type: globalThis.PropType<import(".").VvAccordionGroupItem[]>;
@@ -47,13 +49,26 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
47
49
  }>>, {
48
50
  collapse: boolean;
49
51
  disabled: boolean;
52
+ modelValue: string | string[] | undefined;
50
53
  not: boolean;
51
54
  modifiers: string | string[];
52
55
  items: import(".").VvAccordionGroupItem[];
53
56
  itemModifiers: string | string[];
54
- }, {}>, Partial<Record<`header::${string}`, (_: any) => any>> & Partial<Record<`details::${string}`, (_: any) => any>> & {
57
+ }, {}>, Partial<Record<`summary::${string}`, (_: {
58
+ isExpanded: boolean;
59
+ expand: () => void;
60
+ collapse: () => void;
61
+ groupExpand: (name?: string | string[] | undefined) => void;
62
+ groupCollapse: (name?: string | string[] | undefined) => void;
63
+ }) => any>> & Partial<Record<`content::${string}`, (_: {
64
+ isExpanded: boolean;
65
+ expand: () => void;
66
+ collapse: () => void;
67
+ groupExpand: (name?: string | string[] | undefined) => void;
68
+ groupCollapse: (name?: string | string[] | undefined) => void;
69
+ }) => any>> & {
55
70
  default?(_: {
56
- modelValue: Set<string> & Omit<Set<string>, keyof Set<any>>;
71
+ expandedAccordions: Set<string>;
57
72
  expand: (name?: string | string[]) => void;
58
73
  collapse: (name?: string | string[]) => void;
59
74
  }): any;
@@ -11,6 +11,7 @@ export declare const VvAccordionGroupProps: {
11
11
  */
12
12
  modelValue: {
13
13
  type: globalThis.PropType<string | string[] | undefined>;
14
+ default: undefined;
14
15
  };
15
16
  /**
16
17
  * Accordion items
@@ -1,4 +1,4 @@
1
- import { inject, computed, toRef, unref, defineComponent, useAttrs, toRefs, ref, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, provide, watchEffect, reactive, Fragment, renderList, createBlock, mergeProps, withCtx, resolveDynamicComponent, mergeDefaults, createCommentVNode, createVNode, TransitionGroup, toHandlers, useSlots, isRef, h, onMounted, withDirectives, vModelCheckbox, createSlots, nextTick, Transition, normalizeStyle, vShow, vModelSelect, vModelText, vModelRadio } from "vue";
1
+ import { inject, computed, toRef, unref, defineComponent, useAttrs, toRefs, ref, watch, onBeforeUnmount, openBlock, createElementBlock, normalizeClass, createElementVNode, withModifiers, renderSlot, normalizeProps, guardReactiveProps, createTextVNode, toDisplayString, provide, watchEffect, reactive, onMounted, nextTick, Fragment, renderList, createBlock, mergeProps, createSlots, withCtx, resolveDynamicComponent, mergeDefaults, createCommentVNode, createVNode, TransitionGroup, toHandlers, useSlots, isRef, h, withDirectives, vModelCheckbox, Transition, normalizeStyle, vShow, vModelSelect, vModelText, vModelRadio } from "vue";
2
2
  import { uid } from "uid";
3
3
  import { useVModel, useLocalStorage, useMutationObserver, onClickOutside, useFocusWithin, onKeyStroke, useElementHover, useFocus, useElementVisibility, refDebounced, computedAsync } from "@vueuse/core";
4
4
  import mitt from "mitt";
@@ -879,7 +879,8 @@ const VvAccordionGroupProps = {
879
879
  * VModel
880
880
  */
881
881
  modelValue: {
882
- type: [String, Array]
882
+ type: [String, Array],
883
+ default: void 0
883
884
  },
884
885
  /**
885
886
  * Accordion items
@@ -936,7 +937,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
936
937
  }
937
938
  });
938
939
  const accordionNames = reactive(/* @__PURE__ */ new Set());
939
- let modelValue = ref(/* @__PURE__ */ new Set());
940
+ let storeModelValue = ref();
940
941
  watch(
941
942
  () => props.storeKey,
942
943
  (newKey, oldKey) => {
@@ -944,69 +945,83 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
944
945
  localStorage.removeItem(oldKey);
945
946
  }
946
947
  if (newKey) {
947
- modelValue = useLocalStorage(newKey, modelValue.value);
948
- return;
949
- }
950
- modelValue = ref(new Set(modelValue.value));
951
- },
952
- { immediate: true }
953
- );
954
- watch(
955
- [modelValue, accordionNames, () => props.not, () => props.collapse],
956
- () => {
957
- if (props.not) {
958
- emit(
959
- "update:modelValue",
960
- [...accordionNames].filter(
961
- (name) => !modelValue.value.has(name)
962
- )
963
- );
964
- return;
965
- }
966
- if (props.collapse) {
967
- emit("update:modelValue", [...modelValue.value]);
948
+ storeModelValue = useLocalStorage(newKey, storeModelValue.value);
968
949
  return;
969
950
  }
970
- emit("update:modelValue", modelValue.value.values().next().value);
951
+ storeModelValue = ref(storeModelValue.value);
971
952
  },
972
953
  {
973
- deep: true,
974
954
  immediate: true
975
955
  }
976
956
  );
977
- watch(
978
- () => props.modelValue,
979
- (newValue, oldValue) => {
980
- if (newValue === void 0 || newValue === null || JSON.stringify(newValue) === JSON.stringify(oldValue)) {
981
- return;
957
+ const localModelValue = computed({
958
+ get: () => {
959
+ if (props.modelValue !== null && props.modelValue !== void 0) {
960
+ return props.modelValue;
961
+ }
962
+ return storeModelValue.value;
963
+ },
964
+ set: (newValue) => {
965
+ emit("update:modelValue", newValue);
966
+ storeModelValue.value = newValue;
967
+ }
968
+ });
969
+ const expandedAccordions = computed({
970
+ get: () => {
971
+ if (localModelValue.value === void 0) {
972
+ return /* @__PURE__ */ new Set();
982
973
  }
983
974
  let toReturn = /* @__PURE__ */ new Set();
984
975
  if (props.not) {
985
- if (typeof newValue === "string") {
976
+ if (typeof localModelValue.value === "string") {
986
977
  toReturn = new Set(
987
- [...accordionNames].filter((name) => name !== newValue)
978
+ [...accordionNames].filter(
979
+ (name) => name !== localModelValue.value
980
+ )
988
981
  );
989
- } else if (Array.isArray(newValue)) {
982
+ } else if (Array.isArray(localModelValue.value)) {
990
983
  toReturn = new Set(
991
984
  [...accordionNames].filter(
992
- (name) => !newValue.includes(name)
985
+ (name) => !localModelValue.value.includes(
986
+ name
987
+ )
993
988
  )
994
989
  );
995
990
  }
996
- } else if (typeof newValue === "string") {
997
- toReturn = /* @__PURE__ */ new Set([newValue]);
998
- } else if (Array.isArray(newValue)) {
999
- toReturn = new Set(newValue);
1000
- }
1001
- for (const name of accordionNames) {
1002
- bus.emit("toggle", { name, value: toReturn.has(name) });
991
+ } else if (typeof localModelValue.value === "string") {
992
+ toReturn = /* @__PURE__ */ new Set([localModelValue.value]);
993
+ } else if (Array.isArray(localModelValue.value)) {
994
+ toReturn = new Set(localModelValue.value);
1003
995
  }
1004
- modelValue.value = toReturn;
996
+ return toReturn;
1005
997
  },
1006
- {
1007
- immediate: true
998
+ set: (newValue) => {
999
+ if (props.not) {
1000
+ localModelValue.value = [...accordionNames].filter(
1001
+ (name) => !newValue.has(name)
1002
+ );
1003
+ return;
1004
+ }
1005
+ if (props.collapse) {
1006
+ localModelValue.value = [...newValue];
1007
+ return;
1008
+ }
1009
+ localModelValue.value = newValue.values().next().value;
1008
1010
  }
1009
- );
1011
+ });
1012
+ onMounted(() => {
1013
+ if (props.not && localModelValue.value === void 0) {
1014
+ localModelValue.value = props.collapse ? [] : [...accordionNames.values()].splice(1, accordionNames.size);
1015
+ }
1016
+ nextTick(() => {
1017
+ for (const name of accordionNames) {
1018
+ bus.emit("toggle", {
1019
+ name,
1020
+ value: expandedAccordions.value.has(name)
1021
+ });
1022
+ }
1023
+ });
1024
+ });
1010
1025
  const bus = mitt();
1011
1026
  useProvideGroupState(INJECTION_KEY_ACCORDION_GROUP, {
1012
1027
  disabled,
@@ -1020,19 +1035,22 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
1020
1035
  accordionNames.delete(name);
1021
1036
  });
1022
1037
  bus.on("toggle", ({ name, value }) => {
1038
+ const newValue = new Set(expandedAccordions.value);
1023
1039
  if (value) {
1024
1040
  if (!props.collapse) {
1025
- for (const item of modelValue.value) {
1041
+ for (const item of newValue) {
1026
1042
  if (item !== name) {
1027
1043
  bus.emit("toggle", { name: item, value: false });
1028
1044
  }
1029
1045
  }
1030
- modelValue.value.clear();
1046
+ newValue.clear();
1031
1047
  }
1032
- modelValue.value.add(name);
1048
+ newValue.add(name);
1049
+ expandedAccordions.value = newValue;
1033
1050
  return;
1034
1051
  }
1035
- modelValue.value.delete(name);
1052
+ newValue.delete(name);
1053
+ expandedAccordions.value = newValue;
1036
1054
  });
1037
1055
  const expand = (name) => {
1038
1056
  if (typeof name === "string") {
@@ -1066,7 +1084,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
1066
1084
  }
1067
1085
  };
1068
1086
  bus.on("collapse", ({ name }) => collapse(name));
1069
- __expose({ modelValue, expand, collapse });
1087
+ __expose({ expandedAccordions, expand, collapse });
1070
1088
  const bemCssClasses = useModifiers(
1071
1089
  "vv-accordion-group",
1072
1090
  modifiers,
@@ -1082,7 +1100,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
1082
1100
  },
1083
1101
  [
1084
1102
  renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps({
1085
- modelValue: unref(modelValue),
1103
+ expandedAccordions: unref(expandedAccordions),
1086
1104
  expand,
1087
1105
  collapse
1088
1106
  })), () => [
@@ -1099,16 +1117,25 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
1099
1117
  title: item.title,
1100
1118
  content: item.content
1101
1119
  }),
1102
- {
1103
- header: withCtx((data) => [
1104
- renderSlot(_ctx.$slots, `header::${item.name}`, normalizeProps(guardReactiveProps(data)))
1105
- ]),
1106
- details: withCtx((data) => [
1107
- renderSlot(_ctx.$slots, `details::${item.name}`, normalizeProps(guardReactiveProps(data)))
1108
- ]),
1120
+ createSlots({
1109
1121
  _: 2
1110
1122
  /* DYNAMIC */
1111
- },
1123
+ }, [
1124
+ _ctx.$slots[`summary::${item.name}`] ? {
1125
+ name: "summary",
1126
+ fn: withCtx((data) => [
1127
+ renderSlot(_ctx.$slots, `summary::${item.name}`, normalizeProps(guardReactiveProps(data)))
1128
+ ]),
1129
+ key: "0"
1130
+ } : void 0,
1131
+ _ctx.$slots[`content::${item.name}`] ? {
1132
+ name: "default",
1133
+ fn: withCtx((data) => [
1134
+ renderSlot(_ctx.$slots, `content::${item.name}`, normalizeProps(guardReactiveProps(data)))
1135
+ ]),
1136
+ key: "1"
1137
+ } : void 0
1138
+ ]),
1112
1139
  1040
1113
1140
  /* FULL_PROPS, DYNAMIC_SLOTS */
1114
1141
  );