Vulture/VApp/node_modules/vuetify/lib/composables/list-items.mjs.map

1 line
7.0 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"list-items.mjs","names":["computed","deepEqual","getPropertyFromItem","omit","propsFactory","makeItemsProps","items","type","Array","default","itemTitle","String","Function","itemValue","itemChildren","Boolean","itemProps","returnObject","valueComparator","transformItem","props","item","title","value","children","isArray","undefined","_props","transformItems","raw","array","push","useItems","hasNullItem","some","transformIn","filter","v","map","find","transformOut","_ref","_ref2"],"sources":["../../src/composables/list-items.ts"],"sourcesContent":["// Utilities\nimport { computed } from 'vue'\nimport { deepEqual, getPropertyFromItem, omit, propsFactory } from '@/util'\n\n// Types\nimport type { PropType } from 'vue'\nimport type { InternalItem } from '@/composables/filter'\nimport type { SelectItemKey } from '@/util'\n\nexport interface ListItem<T = any> extends InternalItem<T> {\n title: string\n props: {\n [key: string]: any\n title: string\n value: any\n }\n children?: ListItem<T>[]\n}\n\nexport interface ItemProps {\n items: any[]\n itemTitle: SelectItemKey\n itemValue: SelectItemKey\n itemChildren: SelectItemKey\n itemProps: SelectItemKey\n returnObject: boolean\n valueComparator: typeof deepEqual\n}\n\n// Composables\nexport const makeItemsProps = propsFactory({\n items: {\n type: Array as PropType<ItemProps['items']>,\n default: () => ([]),\n },\n itemTitle: {\n type: [String, Array, Function] as PropType<SelectItemKey>,\n default: 'title',\n },\n itemValue: {\n type: [String, Array, Function] as PropType<SelectItemKey>,\n default: 'value',\n },\n itemChildren: {\n type: [Boolean, String, Array, Function] as PropType<SelectItemKey>,\n default: 'children',\n },\n itemProps: {\n type: [Boolean, String, Array, Function] as PropType<SelectItemKey>,\n default: 'props',\n },\n returnObject: Boolean,\n valueComparator: {\n type: Function as PropType<typeof deepEqual>,\n default: deepEqual,\n },\n}, 'list-items')\n\nexport function transformItem (props: Omit<ItemProps, 'items'>, item: any): ListItem {\n const title = getPropertyFromItem(item, props.itemTitle, item)\n const value = getPropertyFromItem(item, props.itemValue, title)\n const children = getPropertyFromItem(item, props.itemChildren)\n const itemProps = props.itemProps === true\n ? typeof item === 'object' && item != null && !Array.isArray(item)\n ? 'children' in item\n ? omit(item, ['children'])\n : item\n : undefined\n : getPropertyFromItem(item, props.itemProps)\n\n const _props = {\n title,\n value,\n ...itemProps,\n }\n\n return {\n title: String(_props.title ?? ''),\n value: _props.value,\n props: _props,\n children: Array.isArray(children) ? transformItems(props, children) : undefined,\n raw: item,\n }\n}\n\nexport function transformItems (props: Omit<ItemProps, 'items'>, items: ItemProps['items']) {\n const array: ListItem[] = []\n\n for (const item of items) {\n array.push(transformItem(props, item))\n }\n\n return array\n}\n\nexport function useItems (props: ItemProps) {\n const items = computed(() => transformItems(props, props.items))\n const hasNullItem = computed(() => items.value.some(item => item.value === null))\n\n function transformIn (value: any[]): ListItem[] {\n if (!hasNullItem.value) {\n // When the model value is null, return an InternalItem\n // based on null only if null is one of the items\n value = value.filter(v => v !== null)\n }\n\n return value.map(v => {\n if (props.returnObject && typeof v === 'string') {\n // String model value means value is a custom input value from combobox\n // Don't look up existing items if the model value is a string\n return transformItem(props, v)\n }\n return items.value.find(item => props.valueComparator(v, item.value)) || transformItem(props, v)\n })\n }\n\n function transformOut (value: ListItem[]): any[] {\n return props.returnObject\n ? value.map(({ raw }) => raw)