UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

1 lines 5.98 kB
{"version":3,"file":"breadcrumb.vue2.mjs","sources":["../../../components/breadcrumb/breadcrumb.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { BreadcrumbItem } from '@/components/breadcrumb-item'\nimport { Renderer } from '@/components/renderer'\n\nimport { computed, provide, reactive, toRef, watch } from 'vue'\n\nimport { emitEvent, useNameHelper, useProps } from '@vexip-ui/config'\nimport { callIfFunc, debounceMinor, isNull } from '@vexip-ui/utils'\nimport { breadcrumbProps } from './props'\nimport { BREADCRUMB_STATE } from './symbol'\n\nimport type {\n BreadcrumbItemState,\n BreadcrumbOptions,\n BreadcrumbSlots,\n BreadcrumbState,\n SelectEvent\n} from './symbol'\n\ndefineOptions({ name: 'Breadcrumb' })\n\nconst _props = defineProps(breadcrumbProps)\nconst props = useProps('breadcrumb', _props, {\n separator: '/',\n border: false,\n options: {\n default: () => [],\n static: true\n },\n router: null,\n slots: () => ({})\n})\n\nconst slots = defineSlots<BreadcrumbSlots>()\n\nconst nh = useNameHelper('breadcrumb')\nconst itemStates = new Set<BreadcrumbItemState>()\n\nconst className = computed(() => {\n return {\n [nh.b()]: true,\n [nh.bs('vars')]: true,\n [nh.bm('inherit')]: props.inherit,\n [nh.bm('border')]: props.border\n }\n})\nconst normalizedOptions = computed(() => {\n if (props.router && !props.options?.length) {\n const matched = props.router.currentRoute.value.matched\n const options: BreadcrumbOptions[] = []\n\n for (const route of matched) {\n const meta = (route.meta || {}) as any\n\n if (meta.menu === false) {\n continue\n }\n\n options.push({\n label: meta.label || route.path,\n name: meta.name || route.name\n })\n }\n\n return options\n }\n\n return props.options.map(option => {\n if (typeof option === 'string') {\n return { label: option }\n }\n\n return option\n })\n})\n\nconst refreshLabels = debounceMinor(() => {\n Array.from(itemStates).forEach((item, index) => {\n if (isNull(item.label)) {\n item.label = index + 1\n }\n })\n})\n\nconst state: BreadcrumbState = reactive({\n separator: toRef(props, 'separator'),\n separatorRenderer: null,\n increaseItem,\n decreaseItem,\n handleSelect,\n refreshLabels,\n handleSeparatorClick\n})\n\nprovide(BREADCRUMB_STATE, state)\n\nwatch(\n [() => slots.separator, () => props.slots.separator],\n ([slotValue, propValue]) => {\n state.separatorRenderer = slotValue\n ? data => slotValue(data)\n : propValue\n ? data => propValue(data)\n : null\n },\n { immediate: true }\n)\n\nfunction increaseItem(item: BreadcrumbItemState) {\n itemStates.add(item)\n refreshLabels()\n}\n\nfunction decreaseItem(item: BreadcrumbItemState) {\n itemStates.delete(item)\n refreshLabels()\n}\n\nfunction handleSelect(label: string | number) {\n emitEvent(props.onSelect as SelectEvent, label)\n}\n\nfunction handleSeparatorClick(label: string | number) {\n emitEvent(props.onSeparatorClick as SelectEvent, label)\n}\n</script>\n\n<template>\n <ol :class=\"className\">\n <slot>\n <Renderer :renderer=\"props.slots.default\">\n <BreadcrumbItem\n v-for=\"(option, index) in normalizedOptions\"\n :key=\"option.label\"\n :label=\"option.label\"\n >\n <slot name=\"item\" :option=\"option\" :index=\"index\">\n <Renderer :renderer=\"props.slots.item\" :data=\"{ option, index }\">\n {{ option.name ? callIfFunc(option.name) : option.label }}\n </Renderer>\n </slot>\n </BreadcrumbItem>\n </Renderer>\n </slot>\n </ol>\n</template>\n"],"names":["props","useProps","__props","slots","_useSlots","nh","useNameHelper","itemStates","className","computed","normalizedOptions","_a","matched","options","route","meta","option","refreshLabels","debounceMinor","item","index","isNull","state","reactive","toRef","increaseItem","decreaseItem","handleSelect","handleSeparatorClick","provide","BREADCRUMB_STATE","watch","slotValue","propValue","data","label","emitEvent"],"mappings":";;;;;;;;;;;;;;AAsBM,UAAAA,IAAQC,EAAS,cADRC,GAC8B;AAAA,MAC3C,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,SAAS,MAAM,CAAC;AAAA,QAChB,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,MACR,OAAO,OAAO,CAAC;A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