cache-options.mjs 990 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { defineComponent, inject, watch } from 'vue';
  2. import { selectKey } from '../../select/src/token.mjs';
  3. import { isClient } from '@vueuse/core';
  4. var CacheOptions = defineComponent({
  5. props: {
  6. data: {
  7. type: Array,
  8. default: () => []
  9. }
  10. },
  11. setup(props) {
  12. const select = inject(selectKey);
  13. watch(
  14. () => props.data,
  15. () => {
  16. var _a;
  17. props.data.forEach((item) => {
  18. if (!select.states.cachedOptions.has(item.value)) {
  19. select.states.cachedOptions.set(item.value, item);
  20. }
  21. });
  22. const inputs = ((_a = select.selectRef) == null ? void 0 : _a.querySelectorAll("input")) || [];
  23. if (isClient && !Array.from(inputs).includes(
  24. document.activeElement
  25. )) {
  26. select.setSelected();
  27. }
  28. },
  29. { flush: "post", immediate: true }
  30. );
  31. return () => void 0;
  32. }
  33. });
  34. export { CacheOptions as default };
  35. //# sourceMappingURL=cache-options.mjs.map