VList.mjs.map 15 KB

1
  1. {"version":3,"file":"VList.mjs","names":["VListChildren","createList","makeBorderProps","useBorder","useBackgroundColor","makeComponentProps","provideDefaults","makeDensityProps","useDensity","makeDimensionProps","useDimension","makeElevationProps","useElevation","makeItemsProps","makeNestedProps","useNested","makeRoundedProps","useRounded","makeTagProps","makeThemeProps","provideTheme","makeVariantProps","computed","ref","shallowRef","toRef","focusChild","genericComponent","getPropertyFromItem","pick","propsFactory","useRender","isPrimitive","value","transformItem","props","item","type","itemType","title","itemTitle","itemValue","undefined","children","itemChildren","itemProps","_props","transformItems","raw","items","array","push","useListItems","makeVListProps","baseColor","String","activeColor","activeClass","bgColor","disabled","Boolean","lines","default","nav","selectStrategy","openStrategy","variant","VList","name","emits","val","setup","_ref","slots","themeClasses","backgroundColorClasses","backgroundColorStyles","borderClasses","densityClasses","dimensionStyles","elevationClasses","roundedClasses","open","select","lineClasses","color","VListGroup","VListItem","density","isFocused","contentRef","onFocusin","e","onFocusout","onFocus","relatedTarget","contains","focus","onKeydown","key","preventDefault","location","_createVNode","tag","class","style"],"sources":["../../../src/components/VList/VList.tsx"],"sourcesContent":["// Styles\nimport './VList.sass'\n\n// Components\nimport { VListChildren } from './VListChildren'\n\n// Composables\nimport { createList } from './list'\nimport { makeBorderProps, useBorder } from '@/composables/border'\nimport { useBackgroundColor } from '@/composables/color'\nimport { makeComponentProps } from '@/composables/component'\nimport { provideDefaults } from '@/composables/defaults'\nimport { makeDensityProps, useDensity } from '@/composables/density'\nimport { makeDimensionProps, useDimension } from '@/composables/dimensions'\nimport { makeElevationProps, useElevation } from '@/composables/elevation'\nimport { makeItemsProps } from '@/composables/list-items'\nimport { makeNestedProps, useNested } from '@/composables/nested/nested'\nimport { makeRoundedProps, useRounded } from '@/composables/rounded'\nimport { makeTagProps } from '@/composables/tag'\nimport { makeThemeProps, provideTheme } from '@/composables/theme'\nimport { makeVariantProps } from '@/composables/variant'\n\n// Utilities\nimport { computed, ref, shallowRef, toRef } from 'vue'\nimport { focusChild, genericComponent, getPropertyFromItem, pick, propsFactory, useRender } from '@/util'\n\n// Types\nimport type { PropType } from 'vue'\nimport type { VListChildrenSlots } from './VListChildren'\nimport type { ItemProps, ListItem } from '@/composables/list-items'\nimport type { GenericProps } from '@/util'\n\nexport interface InternalListItem<T = any> extends ListItem<T> {\n type?: 'item' | 'subheader' | 'divider'\n}\n\nfunction isPrimitive (value: unknown): value is string | number | boolean {\n return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'\n}\n\nfunction transformItem (props: ItemProps & { itemType: string }, item: any): InternalListItem {\n const type = getPropertyFromItem(item, props.itemType, 'item')\n const title = isPrimitive(item) ? item : getPropertyFromItem(item, props.itemTitle)\n const value = getPropertyFromItem(item, props.itemValue, undefined)\n const children = getPropertyFromItem(item, props.itemChildren)\n const itemProps = props.itemProps === true ? pick(item, ['children'])[1] : getPropertyFromItem(item, props.itemProps)\n\n const _props = {\n title,\n value,\n ...itemProps,\n }\n\n return {\n type,\n title: _props.title,\n value: _props.value,\n props: _props,\n children: type === 'item' && children ? transformItems(props, children) : undefined,\n raw: item,\n }\n}\n\nfunction transformItems (props: ItemProps & { itemType: string }, items: (string | object)[]) {\n const array: InternalListItem[] = []\n\n for (const item of items) {\n array.push(transformItem(props, item))\n }\n\n return array\n}\n\nfunction useListItems (props: ItemProps & { itemType: string }) {\n const items = computed(() => transformItems(props, props.items))\n\n return { items }\n}\n\nexport const makeVListProps = propsFactory({\n baseColor: String,\n /* @deprecated */\n activeColor: String,\n activeClass: String,\n bgColor: String,\n disabled: Boolean,\n lines: {\n type: [Boolean, String] as PropType<'one' | 'two' | 'three' | false>,\n default: 'one',\n },\n nav: Boolean,\n\n ...makeNestedProps({\n selectStrategy: 'single-leaf' as const,\n openStrategy: 'list' as const,\n }),\n ...makeBorderProps(),\n ...makeComponentProps(),\n ...makeDensityProps(),\n ...makeDimensionProps(),\n ...makeElevationProps(),\n itemType: {\n type: String,\n default: 'type',\n },\n ...makeItemsProps(),\n ...makeRoundedProps(),\n ...makeTagProps(),\n ...makeThemeProps(),\n ...makeVariantProps({ variant: 'text' } as const),\n}, 'VList')\n\nexport const VList = genericComponent<new <T>(\n props: {\n items?: T[]\n },\n slots: VListChildrenSlots<T>\n) => GenericProps<typeof props, typeof slots>>()({\n name: 'VList',\n\n props: makeVListProps(),\n\n emits: {\n 'update:selected': (val: unknown[]) => true,\n 'update:opened': (val: unknown[]) => true,\n 'click:open': (value: { id: unknown, value: boolean, path: unknown[] }) => true,\n 'click:select': (value: { id: unknown, value: boolean, path: unknown[] }) => true,\n },\n\n setup (props, { slots }) {\n const { items } = useListItems(props)\n const { themeClasses } = provideTheme(props)\n const { backgroundColorClasses, backgroundColorStyles } = useBackgroundColor(toRef(props, 'bgColor'))\n const { borderClasses } = useBorder(props)\n const { densityClasses } = useDensity(props)\n const { dimensionStyles } = useDimension(props)\n const { elevationClasses } = useElevation(props)\n const { roundedClasses } = useRounded(props)\n const { open, select } = useNested(props)\n const lineClasses = computed(() => props.lines ? `v-list--${props.lines}-line` : undefined)\n const activeColor = toRef(props, 'activeColor')\n const baseColor = toRef(props, 'baseColor')\n const color = toRef(props, 'color')\n\n createList()\n\n provideDefaults({\n VListGroup: {\n activeColor,\n baseColor,\n color,\n },\n VListItem: {\n activeClass: toRef(props, 'activeClass'),\n activeColor,\n baseColor,\n color,\n density: toRef(props, 'density'),\n disabled: toRef(props, 'disabled'),\n lines: toRef(props, 'lines'),\n nav: toRef(props, 'nav'),\n variant: toRef(props, 'variant'),\n },\n })\n\n const isFocused = shallowRef(false)\n const contentRef = ref<HTMLElement>()\n function onFocusin (e: FocusEvent) {\n isFocused.value = true\n }\n\n function onFocusout (e: FocusEvent) {\n isFocused.value = false\n }\n\n function onFocus (e: FocusEvent) {\n if (\n !isFocused.value &&\n !(e.relatedTarget && contentRef.value?.contains(e.relatedTarget as Node))\n ) focus()\n }\n\n function onKeydown (e: KeyboardEvent) {\n if (!contentRef.value) return\n\n if (e.key === 'ArrowDown') {\n focus('next')\n } else if (e.key === 'ArrowUp') {\n focus('prev')\n } else if (e.key === 'Home') {\n focus('first')\n } else if (e.key === 'End') {\n focus('last')\n } else {\n return\n }\n\n e.preventDefault()\n }\n\n function focus (location?: 'next' | 'prev' | 'first' | 'last') {\n if (contentRef.value) {\n return focusChild(contentRef.value, location)\n }\n }\n\n useRender(() => {\n return (\n <props.tag\n ref={ contentRef }\n class={[\n 'v-list',\n {\n 'v-list--disabled': props.disabled,\n 'v-list--nav': props.nav,\n },\n themeClasses.value,\n backgroundColorClasses.value,\n borderClasses.value,\n densityClasses.value,\n elevationClasses.value,\n lineClasses.value,\n roundedClasses.value,\n props.class,\n ]}\n style={[\n backgroundColorStyles.value,\n dimensionStyles.value,\n props.style,\n ]}\n tabindex={ (props.disabled || isFocused.value) ? -1 : 0 }\n role=\"listbox\"\n aria-activedescendant={ undefined }\n onFocusin={ onFocusin }\n onFocusout={ onFocusout }\n onFocus={ onFocus }\n onKeydown={ onKeydown }\n >\n <VListChildren items={ items.value } v-slots={ slots }></VListChildren>\n </props.tag>\n )\n })\n\n return {\n open,\n select,\n focus,\n }\n },\n})\n\nexport type VList = InstanceType<typeof VList>\n"],"mappings":";AAAA;AACA;;AAEA;AAAA,SACSA,aAAa,+BAEtB;AAAA,SACSC,UAAU;AAAA,SACVC,eAAe,EAAEC,SAAS;AAAA,SAC1BC,kBAAkB;AAAA,SAClBC,kBAAkB;AAAA,SAClBC,eAAe;AAAA,SACfC,gBAAgB,EAAEC,UAAU;AAAA,SAC5BC,kBAAkB,EAAEC,YAAY;AAAA,SAChCC,kBAAkB,EAAEC,YAAY;AAAA,SAChCC,cAAc;AAAA,SACdC,eAAe,EAAEC,SAAS;AAAA,SAC1BC,gBAAgB,EAAEC,UAAU;AAAA,SAC5BC,YAAY;AAAA,SACZC,cAAc,EAAEC,YAAY;AAAA,SAC5BC,gBAAgB,yCAEzB;AACA,SAASC,QAAQ,EAAEC,GAAG,EAAEC,UAAU,EAAEC,KAAK,QAAQ,KAA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