@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.
- package/dist/components/VvAccordionGroup/VvAccordionGroup.es.js +87 -60
- package/dist/components/VvAccordionGroup/VvAccordionGroup.umd.js +1 -1
- package/dist/components/VvAccordionGroup/VvAccordionGroup.vue.d.ts +18 -3
- package/dist/components/VvAccordionGroup/index.d.ts +1 -0
- package/dist/components/index.es.js +87 -60
- package/dist/components/index.umd.js +1 -1
- package/dist/icons.es.js +3 -3
- package/dist/icons.umd.js +1 -1
- package/dist/stories/AccordionGroup/AccordionGroup.stories.d.ts +24 -5
- package/dist/stories/AccordionGroup/AccordionGroupSlots.stories.d.ts +152 -36
- package/package.json +1 -1
- package/src/assets/icons/detailed.json +1 -1
- package/src/assets/icons/normal.json +1 -1
- package/src/assets/icons/simple.json +1 -1
- package/src/components/VvAccordionGroup/VvAccordionGroup.vue +81 -58
- package/src/components/VvAccordionGroup/index.ts +1 -0
- package/src/stories/AccordionGroup/AccordionGroup.settings.ts +2 -2
- package/src/stories/AccordionGroup/AccordionGroup.test.ts +5 -5
|
@@ -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
|
|
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
|
-
|
|
636
|
+
storeModelValue = useLocalStorage(newKey, storeModelValue.value);
|
|
636
637
|
return;
|
|
637
638
|
}
|
|
638
|
-
|
|
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
|
-
|
|
666
|
-
() =>
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
|
664
|
+
if (typeof localModelValue.value === "string") {
|
|
674
665
|
toReturn = new Set(
|
|
675
|
-
[...accordionNames].filter(
|
|
666
|
+
[...accordionNames].filter(
|
|
667
|
+
(name) => name !== localModelValue.value
|
|
668
|
+
)
|
|
676
669
|
);
|
|
677
|
-
} else if (Array.isArray(
|
|
670
|
+
} else if (Array.isArray(localModelValue.value)) {
|
|
678
671
|
toReturn = new Set(
|
|
679
672
|
[...accordionNames].filter(
|
|
680
|
-
(name) => !
|
|
673
|
+
(name) => !localModelValue.value.includes(
|
|
674
|
+
name
|
|
675
|
+
)
|
|
681
676
|
)
|
|
682
677
|
);
|
|
683
678
|
}
|
|
684
|
-
} else if (typeof
|
|
685
|
-
toReturn = /* @__PURE__ */ new Set([
|
|
686
|
-
} else if (Array.isArray(
|
|
687
|
-
toReturn = new Set(
|
|
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
|
-
|
|
690
|
-
bus.emit("toggle", { name, value: toReturn.has(name) });
|
|
691
|
-
}
|
|
692
|
-
modelValue.value = toReturn;
|
|
684
|
+
return toReturn;
|
|
693
685
|
},
|
|
694
|
-
{
|
|
695
|
-
|
|
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
|
|
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
|
-
|
|
734
|
+
newValue.clear();
|
|
719
735
|
}
|
|
720
|
-
|
|
736
|
+
newValue.add(name);
|
|
737
|
+
expandedAccordions.value = newValue;
|
|
721
738
|
return;
|
|
722
739
|
}
|
|
723
|
-
|
|
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({
|
|
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
|
-
|
|
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||{}),
|
|
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
|
-
|
|
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<`
|
|
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
|
-
|
|
71
|
+
expandedAccordions: Set<string>;
|
|
57
72
|
expand: (name?: string | string[]) => void;
|
|
58
73
|
collapse: (name?: string | string[]) => void;
|
|
59
74
|
}): any;
|
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
951
|
+
storeModelValue = ref(storeModelValue.value);
|
|
971
952
|
},
|
|
972
953
|
{
|
|
973
|
-
deep: true,
|
|
974
954
|
immediate: true
|
|
975
955
|
}
|
|
976
956
|
);
|
|
977
|
-
|
|
978
|
-
() =>
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
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
|
|
976
|
+
if (typeof localModelValue.value === "string") {
|
|
986
977
|
toReturn = new Set(
|
|
987
|
-
[...accordionNames].filter(
|
|
978
|
+
[...accordionNames].filter(
|
|
979
|
+
(name) => name !== localModelValue.value
|
|
980
|
+
)
|
|
988
981
|
);
|
|
989
|
-
} else if (Array.isArray(
|
|
982
|
+
} else if (Array.isArray(localModelValue.value)) {
|
|
990
983
|
toReturn = new Set(
|
|
991
984
|
[...accordionNames].filter(
|
|
992
|
-
(name) => !
|
|
985
|
+
(name) => !localModelValue.value.includes(
|
|
986
|
+
name
|
|
987
|
+
)
|
|
993
988
|
)
|
|
994
989
|
);
|
|
995
990
|
}
|
|
996
|
-
} else if (typeof
|
|
997
|
-
toReturn = /* @__PURE__ */ new Set([
|
|
998
|
-
} else if (Array.isArray(
|
|
999
|
-
toReturn = new Set(
|
|
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
|
-
|
|
996
|
+
return toReturn;
|
|
1005
997
|
},
|
|
1006
|
-
{
|
|
1007
|
-
|
|
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
|
|
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
|
-
|
|
1046
|
+
newValue.clear();
|
|
1031
1047
|
}
|
|
1032
|
-
|
|
1048
|
+
newValue.add(name);
|
|
1049
|
+
expandedAccordions.value = newValue;
|
|
1033
1050
|
return;
|
|
1034
1051
|
}
|
|
1035
|
-
|
|
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({
|
|
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
|
-
|
|
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
|
);
|