{"version":3,"file":"cache-options.mjs","names":[],"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"],"mappings":";;;;;AAeA,4BAAe,gBAAgB;CAC7B,OAAO,EACL,MAAM;EACJ,MAAM;EACN,eAAe,EAAE;EAClB,EACF;CACD,MAAM,OAAO;EACX,MAAM,SAAS,OAAO,UAAU;AAEhC,cACQ,MAAM,YACN;AACJ,SAAM,KAAK,SAAS,SAAS;AAC3B,QAAI,CAAC,OAAO,OAAO,cAAc,IAAI,KAAK,MAAM,CAI9C,QAAO,OAAO,cAAc,IAAI,KAAK,OAAO,KAAK;KAEnD;GAGF,MAAM,SAAS,OAAO,WAAW,iBAAiB,QAAQ,IAAI,EAAE;AAChE,OACE,YACA,CAAC,MAAM,KAAK,OAAO,CAAC,SAClB,SAAS,cACV,CAED,QAAO,aAAa;KAGxB;GAAE,OAAO;GAAQ,WAAW;GAAM,CACnC;AAED,eAAa;;CAEhB,CAAC"}