{"version":3,"file":"use-collapse.js","sources":["../../../../../../packages/components/collapse/src/use-collapse.ts"],"sourcesContent":["import { computed, provide, ref, watch } from 'vue'\nimport { ensureArray } from '@element-plus/utils'\nimport { useNamespace } from '@element-plus/hooks'\nimport { CHANGE_EVENT, UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { collapseContextKey } from './constants'\n\nimport type { SetupContext } from 'vue'\nimport type {\n CollapseActiveName,\n CollapseEmits,\n CollapseProps,\n} from './collapse'\n\nexport const useCollapse = (\n props: CollapseProps,\n emit: SetupContext['emit']\n) => {\n const activeNames = ref(ensureArray(props.modelValue))\n\n const setActiveNames = (_activeNames: CollapseActiveName[]) => {\n activeNames.value = _activeNames\n const value = props.accordion ? activeNames.value[0] : activeNames.value\n emit(UPDATE_MODEL_EVENT, value)\n emit(CHANGE_EVENT, value)\n }\n\n const handleItemClick = (name: CollapseActiveName) => {\n if (props.accordion) {\n setActiveNames([activeNames.value[0] === name ? '' : name])\n } else {\n const _activeNames = [...activeNames.value]\n const index = _activeNames.indexOf(name)\n\n if (index > -1) {\n _activeNames.splice(index, 1)\n } else {\n _activeNames.push(name)\n }\n setActiveNames(_activeNames)\n }\n }\n\n watch(\n () => props.modelValue,\n () => (activeNames.value = ensureArray(props.modelValue)),\n { deep: true }\n )\n\n provide(collapseContextKey, {\n activeNames,\n handleItemClick,\n })\n return {\n activeNames,\n setActiveNames,\n }\n}\n\nexport const useCollapseDOM = () => {\n const ns = useNamespace('collapse')\n\n const rootKls = computed(() => ns.b())\n return {\n rootKls,\n }\n}\n"],"names":["ref","ensureArray","UPDATE_MODEL_EVENT","CHANGE_EVENT","watch","provide","collapseContextKey","useNamespace","computed"],"mappings":";;;;;;;;;;;;;AAKY,MAAC,WAAW,GAAG,CAAC,KAAK,EAAE,IAAI,KAAK;AAC5C,EAAE,MAAM,WAAW,GAAGA,OAAG,CAACC,uBAAW,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACzD,EAAE,MAAM,cAA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