Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
package.lib.components.VDataTable.composables.group.mjs.map Maven / Gradle / Ivy
{"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","disableSort","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 {\n type: 'item'\n raw: T\n}\n\nexport interface Group {\n type: 'group'\n depth: number\n id: string\n key: string\n value: any\n items: readonly (T | Group)[]\n}\n\nexport const makeDataTableGroupProps = propsFactory({\n groupBy: {\n type: Array as PropType,\n default: () => ([]),\n },\n}, 'DataTable-group')\n\nconst VDataTableGroupSymbol: InjectionKey<{\n opened: Ref>\n toggleGroup: (group: Group) => void\n isGroupOpen: (group: Group) => boolean\n sortByWithGroups: Ref\n groupBy: Ref\n extractRows: (items: (DataTableItem | Group)[]) => 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: {\n groupBy: Ref\n sortBy: Ref\n disableSort?: Ref\n}) {\n const { disableSort, groupBy, sortBy } = options\n const opened = ref(new Set())\n\n const sortByWithGroups = computed(() => {\n return groupBy.value.map(val => ({\n ...val,\n order: val.order ?? false,\n })).concat(disableSort?.value ? [] : 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 (items: readonly (T | Group)[]) {\n function dive (group: Group): 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 (items: readonly T[], groupBy: string) {\n if (!items.length) return []\n\n const groups = new Map()\n for (const item of items) {\n const value = getObjectValueByPath(item.raw, groupBy)\n\n if (!groups.has(value)) {\n groups.set(value, [])\n }\n groups.get(value)!.push(item)\n }\n\n return groups\n}\n\nfunction groupItems (items: readonly T[], groupBy: readonly string[], depth = 0, prefix = 'root') {\n if (!groupBy.length) return []\n\n const groupedItems = groupItemsByProperty(items, groupBy[0])\n const groups: Group[] = []\n\n const rest = groupBy.slice(1)\n groupedItems.forEach((items, value) => {\n const key = groupBy[0]\n const id = `${prefix}_${key}_${value}`\n groups.push({\n depth,\n id,\n key,\n value,\n items: rest.length ? groupItems(items, rest, depth + 1, id) : items,\n type: 'group',\n })\n })\n\n return groups\n}\n\nfunction flattenItems (items: readonly (T | Group)[], opened: Set): readonly (T | Group)[] {\n const flatItems: (T | Group)[] = []\n\n for (const item of items) {\n // TODO: make this better\n if ('type' in item && item.type === 'group') {\n if (item.value != null) {\n flatItems.push(item)\n }\n\n if (opened.has(item.id) || item.value == null) {\n flatItems.push(...flattenItems(item.items, opened))\n }\n } else {\n flatItems.push(item)\n }\n }\n\n return flatItems\n}\n\nexport function useGroupedItems (\n items: Ref,\n groupBy: Ref,\n opened: Ref>\n) {\n const flatItems = computed(() => {\n if (!groupBy.value.length) return items.value\n\n const groupedItems = groupItems(items.value, groupBy.value.map(item => item.key))\n\n return flattenItems(groupedItems, opened.value)\n })\n\n return { flatItems }\n}\n"],"mappings":"AAAA;AAAA,SACSA,eAAe,iDAExB;AACA,SAASC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,GAAG,QAAQ,KAAK;AAAA,SAC3CC,oBAAoB,EAAEC,YAAY,mCAE3C;AAmBA,OAAO,MAAMC,uBAAuB,GAAGD,YAAY,CAAC;EAClDE,OAAO,EAAE;IACPC,IAAI,EAAEC,KAAsC;IAC5CC,OAAO,EAAEA,CAAA,KAAO;EAClB;AACF,CAAC,EAAE,iBAAiB,CAAC;AAErB,MAAMC,qBAOJ,GAAGC,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AAO3C,OAAO,SAASC,aAAaA,CAAEC,KAAiB,EAAE;EAChD,MAAMR,OAAO,GAAGR,eAAe,CAACgB,KAAK,EAAE,SAAS,CAAC;EAEjD,OAAO;IAAER;EAAQ,CAAC;AACpB;AAEA,OAAO,SAASS,cAAcA,CAAEC,OAI/B,EAAE;EACD,MAAM;IAAEC,WAAW;IAAEX,OAAO;IAAEY;EAAO,CAAC,GAAGF,OAAO;EAChD,MAAMG,MAAM,GAAGjB,GAAG,CAAC,IAAIkB,GAAG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