element-plus
Version:
A Component Library for Vue 3
1 lines • 1.93 kB
Source Map (JSON)
{"version":3,"file":"steps.mjs","names":[],"sources":["../../../../../../packages/components/tour/src/steps.ts"],"sourcesContent":["import { defineComponent } from 'vue'\nimport { flattedChildren, isArray } from '@element-plus/utils'\n\nimport type { FlattenVNodes } from '@element-plus/utils'\nimport type { Component, VNode } from 'vue'\n\nexport default defineComponent({\n name: 'ElTourSteps',\n props: {\n current: {\n type: Number,\n default: 0,\n },\n },\n emits: ['update-total'],\n setup(props, { slots, emit }) {\n let cacheTotal = 0\n\n return () => {\n const children = slots.default?.()!\n const result: VNode[] = []\n let total = 0\n\n function filterSteps(children?: FlattenVNodes) {\n if (!isArray(children)) return\n ;(children as VNode[]).forEach((item) => {\n const name = ((item?.type || {}) as Component)?.name\n\n if (name === 'ElTourStep') {\n result.push(item)\n total += 1\n }\n })\n }\n\n if (children.length) {\n filterSteps(flattedChildren(children![0]?.children))\n }\n\n if (cacheTotal !== total) {\n cacheTotal = total\n emit('update-total', total)\n }\n\n if (result.length) {\n return result[props.current]\n }\n return null\n }\n },\n})\n"],"mappings":";;;;;AAMA,oBAAe,gBAAgB;CAC7B,MAAM;CACN,OAAO,EACL,SAAS;EACP,MAAM;EACN,SAAS;EACV,EACF;CACD,OAAO,CAAC,eAAe;CACvB,MAAM,OAAO,EAAE,OAAO,QAAQ;EAC5B,IAAI,aAAa;AAEjB,eAAa;GACX,MAAM,WAAW,MAAM,WAAW;GAClC,MAAM,SAAkB,EAAE;GAC1B,IAAI,QAAQ;GAEZ,SAAS,YAAY,UAA0B;AAC7C,QAAI,CAAC,QAAQ,SAAS,CAAE;AACvB,IAAC,SAAqB,SAAS,SAAS;AAGvC,UAFe,MAAM,QAAQ,EAAE,GAAiB,SAEnC,cAAc;AACzB,aAAO,KAAK,KAAK;AACjB,eAAS;;MAEX;;AAGJ,OAAI,SAAS,OACX,aAAY,gBAAgB,SAAU,IAAI,SAAS,CAAC;AAGtD,OAAI,eAAe,OAAO;AACxB,iBAAa;AACb,SAAK,gBAAgB,MAAM;;AAG7B,OAAI,OAAO,OACT,QAAO,OAAO,MAAM;AAEtB,UAAO;;;CAGZ,CAAC"}