UNPKG

vexip-ui

Version:

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

1 lines 3.31 kB
{"version":3,"file":"tour-step.cjs","sources":["../../../components/tour/tour-step.ts"],"sourcesContent":["import { defineComponent, inject, onBeforeUnmount, reactive, renderSlot, watch } from 'vue'\n\nimport { useProps } from '@vexip-ui/config'\nimport { tourStepProps } from './props'\nimport { TOUR_STATE } from './symbol'\n\nimport type { TourPayload, TourStepOptions } from './symbol'\n\ntype StepPropKey = keyof typeof tourStepProps\n\nconst propKeys = Object.keys(tourStepProps) as StepPropKey[]\nconst deepProps: StepPropKey[] = []\nconst ignoredProps: StepPropKey[] = ['renderer']\n\nconst funcProp = {\n default: null,\n isFunc: true,\n static: true,\n}\n\nexport default defineComponent({\n name: 'TourStep',\n props: tourStepProps,\n setup(_props, { slots }) {\n const props = useProps('tourStep', _props, {\n target: {\n default: null,\n static: true,\n },\n placement: 'bottom',\n title: '',\n content: '',\n order: {\n default: 0,\n static: true,\n },\n type: 'default',\n renderer: funcProp,\n })\n\n const tourState = inject(TOUR_STATE, null)\n const options = reactive({}) as TourStepOptions\n\n for (const key of propKeys) {\n if (ignoredProps.includes(key)) continue\n\n watch(\n () => props[key],\n value => {\n ;(options[key as keyof TourStepOptions] as any) = value\n },\n { immediate: true, deep: deepProps.includes(key) },\n )\n }\n\n watch(() => props.renderer, setRenderer)\n\n setRenderer()\n\n tourState?.increaseStep(options)\n\n onBeforeUnmount(() => {\n tourState?.decreaseStep(options)\n })\n\n function setRenderer() {\n if (typeof slots.default === 'function') {\n options.renderer = (payload: TourPayload) => renderSlot(slots, 'default', payload as any)\n } else if (typeof props.renderer === 'function') {\n options.renderer = props.renderer\n } else {\n options.renderer = undefined\n }\n }\n\n return () => null\n },\n})\n"],"names":["propKeys","tourStepProps","deepProps","ignoredProps","funcProp","TourStep","defineComponent","_props","slots","props","useProps","tourState","inject","TOUR_STATE","options","reactive","key","watch","value","setRenderer","onBeforeUnmount","payload","renderSlot"],"mappings":"qHAUMA,EAAW,OAAO,KAAKC,eAAa,EACpCC,EAA2B,CAAC,EAC5BC,EAA8B,CAAC,UAAU,EAEzCC,EAAW,CACf,QAAS,KACT,OAAQ,GACR,OAAQ,EACV,EAEAC,EAAeC,kBAAgB,CAC7B,KAAM,WACN,MAAOL,EAAA,cACP,MAAMM,EAAQ,CAAE,MAAAC,GAAS,CACjB,MAAAC,EAAQC,EAAAA,SAAS,WAAYH,EAAQ,CACzC,OAAQ,CACN,QAAS,KACT,OAAQ,EACV,EACA,UAAW,SACX,MAAO,GACP,QAAS,GACT,MAAO,CACL,QAAS,EACT,OAAQ,EACV,EACA,KAAM,UACN,SAAUH,CAAA,CACX,EAEKO,EAAYC,EAAAA,OAAOC,EAAA,WAAY,IAAI,EACnCC,EAAUC,EAAS,SAAA,EAAE,EAE3B,UAAWC,KAAOhB,EACZG,EAAa,SAASa,CAAG,GAE7BC,EAAA,MACE,IAAMR,EAAMO,CAAG,EACNE,GAAA,CACLJ,EAAQE,CAA4B,EAAYE,CACpD,EACA,CAAE,UAAW,GAAM,KAAMhB,EAAU,SAASc,CAAG,CAAE,CACnD,EAGIC,EAAAA,MAAA,IAAMR,EAAM,SAAUU,CAAW,EAE3BA,EAAA,EAEZR,GAAA,MAAAA,EAAW,aAAaG,GAExBM,EAAAA,gBAAgB,IAAM,CACpBT,GAAA,MAAAA,EAAW,aAAaG,EAAO,CAChC,EAED,SAASK,GAAc,CACjB,OAAOX,EAAM,SAAY,WAC3BM,EAAQ,SAAYO,GAAyBC,EAAW,WAAAd,EAAO,UAAWa,CAAc,EAC/E,OAAOZ,EAAM,UAAa,WACnCK,EAAQ,SAAWL,EAAM,SAEzBK,EAAQ,SAAW,MACrB,CAGF,MAAO,IAAM,IAAA,CAEjB,CAAC"}