UNPKG

element-plus

Version:

A Component Library for Vue 3

1 lines 2.66 kB
{"version":3,"file":"cache-options.mjs","sources":["../../../../../../packages/components/tree-select/src/cache-options.ts"],"sourcesContent":["import { defineComponent, inject, watch } from 'vue'\nimport { selectKey } from '@element-plus/components/select'\nimport { isClient } from '@element-plus/utils'\n\nimport type { SelectContext } from '@element-plus/components/select'\nimport type { PropType } from 'vue'\n\n// same as el-option instance,\n// these are required for `cachedOptions`\nexport type CacheOption = {\n value: string | number | boolean | object\n currentLabel: string | number\n isDisabled: boolean\n}\n\nexport default defineComponent({\n props: {\n data: {\n type: Array as PropType<CacheOption[]>,\n default: () => [],\n },\n },\n setup(props) {\n const select = inject(selectKey) as NonNullable<SelectContext>\n\n watch(\n () => props.data,\n () => {\n props.data.forEach((item) => {\n if (!select.states.cachedOptions.has(item.value)) {\n // TODO: the type of 'item' is not compatible with the type of 'cachedOptions',\n // which may indicate potential runtime issues.\n // @ts-expect-error\n select.states.cachedOptions.set(item.value, item)\n }\n })\n\n // fork from packages/select/src/useSelect.ts#330\n const inputs = select.selectRef?.querySelectorAll('input') || []\n if (\n isClient &&\n !Array.from(inputs).includes(\n document.activeElement as HTMLInputElement\n )\n ) {\n select.setSelected()\n }\n },\n { flush: 'post', immediate: true }\n )\n\n return () => undefined\n },\n})\n"],"names":[],"mappings":";;;;AAeA,mBAAe,eAAA,CAAgB;AAAA,EAC7B,KAAA,EAAO;AAAA,IACL,IAAA,EAAM;AAAA,MACJ,IAAA,EAAM,KAAA;AAAA,MACN,OAAA,EAAS,MAAM;AAAC;AAClB,GACF;AAAA,EACA,MAAM,KAAA,EAAO;AACX,IAAA,MAAM,MAAA,GAAS,OAAO,SAAS,CAAA;AAE/B,IAAA,KAAA;AAAA,MACE,MAAM,KAAA,CAAM,IAAA;AAAA,MACZ,MAAM;AA3BZ,QAAA,IAAA,EAAA;AA4BQ,QAAA,KAAA,CAAM,IAAA,CAAK,OAAA,CAAQ,CAAC,IAAA,KAAS;AAC3B,UAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,cAAc,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA,EAAG;AAIhD,YAAA,MAAA,CAAO,MAAA,CAAO,aAAA,CAAc,GAAA,CAAI,IAAA,CAAK,OAAO,IAAI,CAAA;AAAA,UAClD;AAAA,QACF,CAAC,CAAA;AAGD,QAAA,MAAM,WAAS,EAAA,GAAA,MAAA,CAAO,SAAA,KAAP,IAAA,GAAA,MAAA,GAAA,EAAA,CAAkB,gBAAA,CAAiB,aAAY,EAAC;AAC/D,QAAA,IACE,QAAA,IACA,CAAC,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA,CAAE,QAAA;AAAA,UAClB,QAAA,CAAS;AAAA,SACX,EACA;AACA,UAAA,MAAA,CAAO,WAAA,EAAY;AAAA,QACrB;AAAA,MACF,CAAA;AAAA,MACA,EAAE,KAAA,EAAO,MAAA,EAAQ,SAAA,EAAW,IAAA;AAAK,KACnC;AAEA,IAAA,OAAO,MAAM,MAAA;AAAA,EACf;AACF,CAAC,CAAA;;;;"}