UNPKG

hongluan-ui

Version:
1 lines 3.06 kB
{"version":3,"file":"use-expand.mjs","sources":["../../../../../../../packages/components/simple-table/src/composables/use-expand.ts"],"sourcesContent":["import { getCurrentInstance, ref, watch } from 'vue'\n\nimport type { Ref } from 'vue'\nimport type { GetRowKey } from '../simple-table'\nimport type { Indexable } from '@hongluan-ui/utils'\n\nfunction useExpand({ expandRowKeys, defaultExpandAll, getRowKey }: {\n defaultExpandAll: Ref<boolean>\n expandRowKeys: Ref<string[]>\n getRowKey: GetRowKey\n}) {\n const allExpandKeys = ref<Indexable<boolean>>(expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {} as Record<string, boolean>))\n\n const { emit } = getCurrentInstance()!\n\n const expandedKeyExisted = (row: unknown, slotName: string): boolean => {\n if (!slotName) return false\n const rowKey = getRowKey(row) + slotName\n return rowKey in allExpandKeys.value ? allExpandKeys.value[rowKey] : defaultExpandAll.value\n }\n const toggleExpandRow = (row: unknown, slotName: string) => {\n const key = getRowKey(row)\n toggleExpand(key, slotName)\n }\n const toggleExpand = (key: string, slotName: string) => {\n const rowKey = key + slotName\n allExpandKeys.value[rowKey] = rowKey in allExpandKeys.value ? !allExpandKeys.value[rowKey] : !defaultExpandAll.value\n emit('expand', allExpandKeys.value[rowKey], rowKey, slotName)\n }\n\n watch(expandRowKeys, () => {\n allExpandKeys.value = expandRowKeys.value.reduce((prev, cur) => (prev[cur] = true, prev), {} as Record<string, boolean>)\n })\n\n return {\n expandedKeyExisted,\n toggleExpandRow,\n toggleExpand,\n }\n}\n\nexport { useExpand }\n"],"names":[],"mappings":";;AACA,SAAS,SAAS,CAAC,EAAE,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,EAAE;AACnE,EAAE,MAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,EA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