UNPKG

vexip-ui

Version:

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

1 lines 4.68 kB
{"version":3,"file":"image-group.vue2.cjs","sources":["../../../components/image/image-group.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ImageViewer } from '@/components/image-viewer'\nimport { Renderer } from '@/components/renderer'\n\nimport { computed, provide, reactive, ref, toRef } from 'vue'\n\nimport { emitEvent, useNameHelper, useProps } from '@vexip-ui/config'\nimport { debounceMinor } from '@vexip-ui/utils'\nimport { imageGroupProps } from './props'\nimport { GROUP_STATE } from './symbol'\n\nimport type { ImageGroupSlots, ImageState } from './symbol'\n\ndefineOptions({ name: 'ImageGroup' })\n\nconst _props = defineProps(imageGroupProps)\nconst props = useProps('imageGroup', _props, {\n showAll: false,\n preview: false,\n viewerTransfer: null,\n slots: () => ({}),\n})\n\nconst slots = defineSlots<ImageGroupSlots>()\n\nconst nh = useNameHelper('image-group')\n\nconst currentActive = ref(false)\nconst currentIndex = ref(0)\nconst imageStates = reactive(new Set<ImageState>())\n\nconst className = computed(() => {\n return [\n nh.b(),\n nh.ns('image-vars'),\n {\n [nh.bm('preview')]: props.preview,\n },\n ]\n})\nconst srcList = computed(() => Array.from(imageStates).map(state => state.src))\n\nconst refreshIndex = debounceMinor(() => {\n const total = imageStates.size\n\n Array.from(imageStates).forEach((item, index) => {\n item.index = index\n item.total = total\n })\n})\n\nprovide(\n GROUP_STATE,\n reactive({\n showAll: toRef(props, 'showAll'),\n preview: toRef(props, 'preview'),\n increaseItem,\n decreaseItem,\n handlePreview,\n }),\n)\n\ndefineExpose({ currentActive, currentIndex })\n\nfunction increaseItem(item: ImageState) {\n imageStates.add(item)\n refreshIndex()\n}\n\nfunction decreaseItem(item: ImageState) {\n imageStates.delete(item)\n refreshIndex()\n}\n\nfunction handlePreview(item: ImageState) {\n currentIndex.value = item.index\n currentActive.value = true\n\n emitEvent(props.onPreview, item.src, Array.from(srcList.value))\n}\n</script>\n\n<template>\n <div :class=\"className\">\n <slot></slot>\n <ImageViewer\n v-if=\"props.preview\"\n v-model:active=\"currentActive\"\n v-model:index=\"currentIndex\"\n :src-list=\"srcList\"\n :transfer=\"props.viewerTransfer\"\n >\n <template v-if=\"slots.preview || props.slots.preview\" #default=\"{ src }\">\n <slot name=\"preview\" :src=\"src\">\n <Renderer :renderer=\"props.slots.preview\" :data=\"{ src }\"></Renderer>\n </slot>\n </template>\n </ImageViewer>\n </div>\n</template>\n"],"names":["_props","__props","props","useProps","slots","_useSlots","nh","useNameHelper","currentActive","ref","currentIndex","imageStates","reactive","className","computed","srcList","state","refreshIndex","debounceMinor","total","item","index","provide","GROUP_STATE","toRef","increaseItem","decreaseItem","handlePreview","__expose","emitEvent","_createElementBlock","_renderSlot","_ctx","_unref","_createBlock","ImageViewer","$event","_withCtx","src","_createVNode","Renderer"],"mappings":"iZAeA,MAAMA,EAASC,EACTC,EAAQC,EAAAA,SAAS,aAAcH,EAAQ,CAC3C,QAAS,GACT,QAAS,GACT,eAAgB,KAChB,MAAO,KAAO,CAAC,EAAA,CAChB,EAEKI,EAAQC,EAAAA,SAAA,EAERC,EAAKC,gBAAc,aAAa,EAEhCC,EAAgBC,MAAI,EAAK,EACzBC,EAAeD,MAAI,CAAC,EACpBE,EAAcC,EAAAA,SAAa,IAAA,GAAiB,EAE5CC,EAAYC,EAAAA,SAAS,IAClB,CACLR,EAAG,EAAE,EACLA,EAAG,GAAG,YAAY,EAClB,CACE,CAACA,EAAG,GAAG,SAAS,CAAC,EAAGJ,EAAM,OAAA,CAE9B,CACD,EACKa,EAAUD,EAAAA,SAAS,IAAM,MAAM,KAAKH,CAAW,EAAE,IAAIK,GAASA,EAAM,GAAG,CAAC,EAExEC,EAAeC,EAAAA,cAAc,IAAM,CACvC,MAAMC,EAAQR,EAAY,KAE1B,MAAM,KAAKA,CAAW,EAAE,QAAQ,CAACS,EAAMC,IAAU,CAC/CD,EAAK,MAAQC,EACbD,EAAK,MAAQD,CAAA,CACd,CAAA,CACF,EAEDG,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