Vulture/VApp/node_modules/vuetify/lib/components/VDataTable/composables/group.mjs.map

1 line
9.9 KiB
Plaintext
Raw Permalink Normal View History

{"version":3,"file":"group.mjs","names":["useProxiedModel","computed","inject","provide","ref","getObjectValueByPath","propsFactory","makeDataTableGroupProps","groupBy","type","Array","default","VDataTableGroupSymbol","Symbol","for","createGroupBy","props","provideGroupBy","options","sortBy","opened","Set","sortByWithGroups","value","map","val","order","concat","isGroupOpen","group","has","id","toggleGroup","newOpened","add","delete","extractRows","items","dive","arr","item","push","key","depth","data","useGroupBy","Error","groupItemsByProperty","length","groups","Map","raw","set","get","groupItems","arguments","undefined","prefix","groupedItems","rest","slice","forEach","flattenItems","flatItems","useGroupedItems"],"sources":["../../../../src/components/VDataTable/composables/group.ts"],"sourcesContent":["// Composables\nimport { useProxiedModel } from '@/composables/proxiedModel'\n\n// Utilities\nimport { computed, inject, provide, ref } from 'vue'\nimport { getObjectValueByPath, propsFactory } from '@/util'\n\n// Types\nimport type { InjectionKey, PropType, Ref } from 'vue'\nimport type { SortItem } from './sort'\nimport type { DataTableItem } from '../types'\n\nexport interface GroupableItem<T = any> {\n type: 'item'\n raw: T\n}\n\nexport interface Group<T = any> {\n type: 'group'\n depth: number\n id: string\n key: string\n value: any\n items: readonly (T | Group<T>)[]\n}\n\nexport const makeDataTableGroupProps = propsFactory({\n groupBy: {\n type: Array as PropType<readonly SortItem[]>,\n default: () => ([]),\n },\n}, 'DataTable-group')\n\nconst VDataTableGroupSymbol: InjectionKey<{\n opened: Ref<Set<string>>\n toggleGroup: (group: Group) => void\n isGroupOpen: (group: Group) => boolean\n sortByWithGroups: Ref<SortItem[]>\n groupBy: Ref<readonly SortItem[]>\n extractRows: (items: (DataTableItem | Group<DataTableItem>)[]) => DataTableItem[]\n}> = Symbol.for('vuetify:data-table-group')\n\ntype GroupProps = {\n groupBy: readonly SortItem[]\n 'onUpdate:groupBy': ((value: SortItem[]) => void) | undefined\n}\n\nexport function createGroupBy (props: GroupProps) {\n const groupBy = useProxiedModel(props, 'groupBy')\n\n return { groupBy }\n}\n\nexport function provideGroupBy (options: { groupBy: Ref<readonly SortItem[]>, sortBy: Ref<readonly SortItem[]> }) {\n const { groupBy, sortBy } = options\n const opened = ref(new Set<string>())\n\n const sortByWithGroups = computed(() => {\n return groupBy.value.map<SortItem>(val => ({\n ...val,\n order: val.order ?? false,\n })).concat(sortBy.value)\n })\n\n function isGroupOpen (group: Group) {\n return opened.value.has(group.id)\n }\n\n function toggleGroup (group: Group) {\n const newOpened = new Set(opened.value)\n if (!isGroupOpen(group)) newOpened.add(group.id)\n else newOpened.delete(group.id)\n\n opened.value = newOpened\n }\n\n function extractRows <T extends GroupableItem> (items: readonly (T | Group<T>)[]) {\n function dive (group: Group<T>): T[] {\n const arr = []\n\n for (const item of group.items) {\n if ('type' in item && item.type === 'group') {\n arr.push(...dive(item))\n } else {\n arr.push(item as T)\n }\n }\n\n return arr\n }\n return dive({ type: 'group', items, id: 'dummy', key: 'dummy', value: 'dummy', depth: 0 })\n }\n\n // onBeforeMount(() => {\n // for (const key of groupedItems.value.keys()) {\n // opened.value.add(key)\n // }\n // })\n\n const data = { sortByWithGroups, toggleGroup, opened, groupBy, extractRows, isGroupOpen }\n\n provide(VDataTableGroupSymbol, data)\n\n return data\n}\n\nexport function useGroupBy () {\n const data = inject(VDataTableGroupSymbol)\n\n if (!data) throw new Error('Missing group!')\n\n return data\n}\n\nfunction groupItemsByProperty <T extends GroupableItem> (items: readonly T[], groupBy: string) {\n if (!items.length) return []\n\n const groups = new Map<any, T[]>()\n for (const item of items) {\n const value = getObjectValueByPath(item.raw, groupBy)\n\n if (!grou