UNPKG

hongluan-ui

Version:
1 lines 4.76 kB
{"version":3,"file":"tour.mjs","sources":["../../../../../../packages/components/tour/src/tour.vue"],"sourcesContent":["<template>\n <teleport :to=\"appendTo\">\n <div :class=\"kls\" v-bind=\"$attrs\">\n <hl-tour-mask\n :visible=\"mergedShowMask\"\n :fill=\"mergedMaskStyle?.color\"\n :style=\"mergedMaskStyle?.style\"\n :pos=\"pos\"\n :z-index=\"mergedZIndex\"\n :target-area-clickable=\"targetAreaClickable\"\n />\n <hl-tour-content\n v-if=\"modelValue\"\n :key=\"current\"\n :reference=\"triggerTarget\"\n :placement=\"mergedPlacement\"\n :show-arrow=\"mergedShowArrow\"\n :z-index=\"mergedZIndex\"\n :style=\"mergedContentStyle\"\n @close=\"onEscClose\"\n >\n <hl-tour-steps :current=\"current\" @update-total=\"onUpdateTotal\">\n <slot></slot>\n </hl-tour-steps>\n </hl-tour-content>\n </div>\n </teleport>\n <!-- just for IDE -->\n <slot v-if=\"false\" name=\"indicators\" :current=\"current + 1\" :total=\"total\"></slot>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, provide, ref, toRef, useSlots, watch } from 'vue'\nimport { useVModel } from '@vueuse/core'\nimport { useNamespace, useZIndex } from '@hongluan-ui/hooks'\nimport { isBoolean } from '@hongluan-ui/utils'\nimport HlTourMask from './mask.vue'\nimport HlTourContent from './content.vue'\nimport HlTourSteps from './steps'\nimport { tourEmits, tourProps } from './tour'\nimport { tourKey, useTarget } from './helper'\nimport type { TourStepProps } from './step'\n\ndefineOptions({\n name: 'Tour',\n})\n\nconst props = defineProps(tourProps)\nconst emit = defineEmits(tourEmits)\n\nconst { namespace } = useNamespace('tour')\nconst total = ref(0)\nconst currentStep = ref<TourStepProps>()\n\nconst current = useVModel(props, 'current', emit, {\n passive: true,\n})\n\nconst currentTarget = computed(() => currentStep.value?.target)\n\nconst kls = computed(() => [\n namespace.value,\n mergedType.value === 'primary' ? 'tour-primary' : '',\n])\n\nconst mergedPlacement = computed(\n () => currentStep.value?.placement || props.placement,\n)\n\nconst mergedContentStyle = computed(\n () => currentStep.value?.contentStyle ?? props.contentStyle,\n)\n\nconst mergedMask = computed(() => currentStep.value?.mask ?? props.mask)\nconst mergedShowMask = computed(() => !!mergedMask.value && props.modelValue)\nconst mergedMaskStyle = computed(() =>\n isBoolean(mergedMask.value) ? undefined : mergedMask.value,\n)\n\nconst mergedShowArrow = computed(\n () =>\n !!currentTarget.value && (currentStep.value?.showArrow ?? props.showArrow),\n)\n\nconst mergedScrollIntoViewOptions = computed(\n () => currentStep.value?.scrollIntoViewOptions ?? props.scrollIntoViewOptions,\n)\nconst mergedType = computed(() => currentStep.value?.type ?? props.type)\n\nconst { nextZIndex } = useZIndex()\nconst nowZIndex = nextZIndex()\nconst mergedZIndex = computed(() => props.zIndex ?? nowZIndex)\n\nconst { mergedPosInfo: pos, triggerTarget } = useTarget(\n currentTarget,\n toRef(props, 'modelValue'),\n toRef(props, 'gap'),\n mergedMask,\n mergedScrollIntoViewOptions,\n)\n\nwatch(\n () => props.modelValue,\n val => {\n if (!val) {\n current.value = 0\n }\n },\n)\n\nconst onEscClose = () => {\n if (props.closeOnPressEscape) {\n emit('update:modelValue', false)\n emit('close', current.value)\n }\n}\nconst onUpdateTotal = (val: number) => {\n total.value = val\n}\n\nconst slots = useSlots()\n\nprovide(tourKey, {\n currentStep,\n current,\n total,\n showClose: toRef(props, 'showClose'),\n mergedType: mergedType as any,\n slots,\n updateModelValue(modelValue) {\n emit('update:modelValue', modelValue)\n },\n onClose() {\n emit('close', current.value)\n },\n onFinish() {\n emit('finish')\n },\n onChange() {\n emit('change', current.value)\n },\n})\n</script>\n"],"names":[],"mappings":";;;;;;;;;;;;;oCA2Cc;AAAA,EACZ,MAAM;AACR;;;;;;;AAKA,UAAM,EAAE,cAAc,aAAa,MAAM;AACzC,UAAM,QAAQ,IAAI,CAAC;AACnB,UAAM,cAAc;AAEpB,UAAM,UAAU,UAAU,OAAO,WAAW,MAAM;AAAA,MAChD,SAAS;AAAA,KACV;AAED,UAAM,gBAAgB,SAAS,MAAM;AAErC,UAAM;AAAqB,MACzB,UAAU;AAAA,MACV;AAAkD,IACpD;AAEA;AAIA,0DACoB;AAGpB;AACA,UAAM,0BAA0B,OAAO;AACvC,UAAM;AAIN,qCACE,4CACwC;AAG1C;AAGA,UAAM;AAEN,UAAM,EAAE;AACR,sBAAkB;AAClB;AAEA,UAAM,sBAAsB;AAQ5B,UACE,MAAM;AAEJ,gBAAU;AACR;AAAgB;AAClB,IACF;AAGF,UAAM;AACJ,UAAI,MAAM;AACR,aAAK,qBAAqB,KAAK;AAC/B;AAA2B;AAC7B;AAEF;AACE;AAAc,IAChB;AAEA,UAAM;AAEN;AAAiB,MACf;AAAA;AACA;AACA;AACmC,MACnC;AAAA,MACA;AAAA,MACA;AACE;AAAoC;AACtC,MACA,UAAU;AACR;AAA2B;AAC7B,MACA;AACE;AAAa,MACf;AAAA;AAEE,aAAK,uBAAuB;AAAA;AAC9B,KACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}