UNPKG

vuestic-ui

Version:
1 lines 2.26 kB
{"version":3,"file":"useTeleported.mjs","sources":["../../../../src/composables/useTeleported.ts"],"sourcesContent":["import { getCurrentInstance } from 'vue'\nimport { useCurrentComponentId } from './useCurrentComponentId'\n\nexport const TELEPORT_FROM_ATTR = 'data-va-teleported-from'\nexport const TELEPORT_ATTR = 'data-va-teleported'\n\nexport const findTeleportedFrom = (el: HTMLElement | undefined | null): HTMLElement | null => {\n if (!el) { return null }\n\n const teleportId = el.getAttribute(TELEPORT_ATTR)\n\n if (teleportId === null) { return findTeleportedFrom(el.parentElement) }\n\n return document.querySelector<HTMLElement>(`[${TELEPORT_FROM_ATTR}=\"${teleportId}\"]`)\n}\n\n/**\n * Used in components, which have something to do with Teleport.\n * You need to add `teleportFromAttrs` to the root element of the component,\n * and `teleportedAttrs` to the element, which is teleported.\n *\n * This way you can find the original element, which was teleported from.\n *\n * @notice it is used in `useClickOutside` to track from where teleported originated from.\n */\nexport const useTeleported = () => {\n const componentId = useCurrentComponentId()\n\n const currentInstance = getCurrentInstance()\n\n const scopedDataV = currentInstance?.vnode.scopeId\n\n return {\n teleportFromAttrs: {\n [TELEPORT_FROM_ATTR]: componentId,\n },\n teleportedAttrs: {\n [TELEPORT_ATTR]: componentId,\n ...(scopedDataV ? { [scopedDataV]: '' } : undefined),\n ...currentInstance?.appContext.config?.globalProperties?.$vaColorConfig.getAppStylesRootAttribute(),\n },\n findTeleportedFrom,\n }\n}\n"],"names":[],"mappings":";;AAGO,MAAM,qBAAqB;AAC3B,MAAM,gBAAgB;AAEhB,MAAA,qBAAqB,CAAC,OAA2D;AAC5F,MAAI,CAAC,IAAI;AAAS,WAAA;AAAA,EAAK;AAEjB,QAAA,aAAa,GAAG,aAAa,aAAa;AAEhD,MAAI,eAAe,MAAM;AAAS,WAAA,mBAAmB,GAAG,aAAa;AAAA,EAAE;AAEvE,SAAO,SAAS,cAA2B,IAAI,kBAAkB,KAAK,UAAU,IAAI;AACtF;AAWO,MAAM,gBAAgB,MAAM;;AACjC,QAAM,cAAc;AAEpB,QAAM,kBAAkB;AAElB,QAAA,cAAc,mDAAiB,MAAM;AAEpC,SAAA;AAAA,IACL,mBAAmB;AAAA,MACjB,CAAC,kBAAkB,GAAG;AAAA,IACxB;AAAA,IACA,iBAAiB;AAAA,MACf,CAAC,aAAa,GAAG;AAAA,MACjB,GAAI,cAAc,EAAE,CAAC,WAAW,GAAG,OAAO;AAAA,MAC1C,IAAG,8DAAiB,WAAW,WAA5B,mBAAoC,qBAApC,mBAAsD,eAAe;AAAA,IAC1E;AAAA,IACA;AAAA,EAAA;AAEJ;"}