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.composables.list-items.mjs.map Maven / Gradle / Ivy
{"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 extends InternalItem {\n title: string\n props: {\n [key: string]: any\n title: string\n value: any\n }\n children?: ListItem[]\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,\n default: () => ([]),\n },\n itemTitle: {\n type: [String, Array, Function] as PropType,\n default: 'title',\n },\n itemValue: {\n type: [String, Array, Function] as PropType,\n default: 'value',\n },\n itemChildren: {\n type: [Boolean, String, Array, Function] as PropType,\n default: 'children',\n },\n itemProps: {\n type: [Boolean, String, Array, Function] as PropType,\n default: 'props',\n },\n returnObject: Boolean,\n valueComparator: {\n type: Function as PropType,\n default: deepEqual,\n },\n}, 'list-items')\n\nexport function transformItem (props: Omit, 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, 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)\n : value.map(({ value }) => value)\n }\n\n return { items, transformIn, transformOut }\n}\n"],"mappings":"AAAA;AACA,SAASA,QAAQ,QAAQ,KAAK;AAAA,SACrBC,SAAS,EAAEC,mBAAmB,EAAEC,IAAI,EAAEC,YAAY,6BAE3D;AAyBA;AACA,OAAO,MAAMC,cAAc,GAAGD,YAAY,CAAC;EACzCE,KAAK,EAAE;IACLC,IAAI,EAAEC,KAAqC;IAC3CC,OAAO,EAAEA,CAAA,KAAO;EAClB,CAAC;EACDC,SAAS,EAAE;IACTH,IAAI,EAAE,CAACI,MAAM,EAAEH,KAAK,EAAEI,QAAQ,CAA4B;IAC1DH,OAAO,EAAE;EACX,CAAC;EACDI,SAAS,EAAE;IACTN,IAAI,EAAE,CAACI,MAAM,EAAEH,KAAK,EAAEI,QAAQ,CAA4B;IAC1D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