1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
|
{"version":3,"file":"select.mjs","names":["useProxiedModel","computed","inject","provide","deepEqual","propsFactory","wrapInArray","singleSelectStrategy","showSelectAll","allSelected","select","_ref","items","value","Set","selectAll","_ref2","selected","pageSelectStrategy","_ref3","currentPage","_ref4","item","add","delete","_ref5","allSelectStrategy","_ref6","allItems","_ref7","_ref8","makeDataTableSelectProps","showSelect","Boolean","selectStrategy","type","String","Object","default","modelValue","Array","valueComparator","Function","VDataTableSelectionSymbol","Symbol","for","provideSelection","props","_ref9","v","map","find","values","allSelectable","filter","selectable","currentPageSelectable","isSelected","every","has","isSomeSelected","some","newSelected","toggleSelect","someSelected","size","length","data","useSelection","Error"],"sources":["../../../../src/components/VDataTable/composables/select.ts"],"sourcesContent":["// Composables\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Utilities\nimport { computed, inject, provide } from 'vue'\nimport { deepEqual, propsFactory, wrapInArray } from '@/util'\n\n// Types\nimport type { InjectionKey, PropType, Ref } from 'vue'\nimport type { DataTableItemProps } from './items'\nimport type { EventProp } from '@/util'\n\nexport interface SelectableItem {\n value: any\n selectable: boolean\n}\n\nexport interface DataTableSelectStrategy {\n showSelectAll: boolean\n allSelected: (data: {\n allItems: SelectableItem[]\n currentPage: SelectableItem[]\n }) => SelectableItem[]\n select: (data: {\n items: SelectableItem[]\n value: boolean\n selected: Set<unknown>\n }) => Set<unknown>\n selectAll: (data: {\n value: boolean\n allItems: SelectableItem[]\n currentPage: SelectableItem[]\n selected: Set<unknown>\n }) => Set<unknown>\n}\n\ntype SelectionProps = Pick<DataTableItemProps, 'itemValue'> & {\n modelValue: readonly any[]\n selectStrategy: 'single' | 'page' | 'all'\n valueComparator: typeof deepEqual\n 'onUpdate:modelValue': EventProp<[any[]]> | undefined\n}\n\nconst singleSelectStrategy: DataTableSelectStrategy = {\n showSelectAll: false,\n allSelected: () => [],\n select: ({ items, value }) => {\n return new Set(value ? [items[0]?.value] : [])\n },\n selectAll: ({ selected }) => selected,\n}\n\nconst pageSelectStrategy: DataTableSelectStrategy = {\n showSelectAll: true,\n allSelected: ({ currentPage }) => currentPage,\n select: ({ items, value, selected }) => {\n for (const item of items) {\n if (value) selected.add(item.value)\n else selected.delete(item.value)\n }\n\n return selected\n },\n selectAll: ({ value, currentPage, selected }) => pageSelectStrategy.select({ items: currentPage, value, selected }),\n}\n\nconst allSelectStrategy: DataTableSelectStrategy = {\n showSelectAll: true,\n allSelected: ({ allItems }) => allItems,\n select: ({ items, value, selected }) => {\n for (const item of items) {\n if (value) selected.add(item.value)\n else selected.delete(item.value)\n }\n\n return selected\n },\n selectAll: ({ value, allItems, selected }) => allSelectStrategy.select({ items: allItems, value, selected }),\n}\n\nexport const makeDataTableSelectProps = propsFactory({\n showSelect: Boolean,\n selectStrategy: {\n type: [String, Object] as PropType<'single' | 'page' | 'all'>,\n default: 'page',\n },\n modelValue: {\n type: Array as PropType<readonly any[]>,\n default: () => ([]),\n },\n valueComparator: {\n type: Function as PropType<typeof deepEqual>,\n default: deepEqual,\n },\n}, 'DataTable-select')\n\nexport const VDataTableSelectionSymbol: InjectionKey<ReturnType<typeof provideSelection>> = Symbol.for('vuetify:data-table-selection')\n\nexport function provideSelection (\n props: SelectionProps,\n { allItems, currentPage }: { allItems: Ref<SelectableItem[]>, currentPage: Ref<SelectableItem[]> }\n) {\n const selected = useProxiedModel(props, 'modelValue', props.modelValue, v => {\n return new Set(wrapInArray(v).map(v => {\n
|