You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
2.0 KiB

{"version":3,"file":"index.mjs","sources":["../../../../../packages/hooks/use-escape-keydown/index.ts"],"sourcesContent":["import { onBeforeUnmount, onMounted } from 'vue'\nimport { isClient } from '@element-plus/utils'\nimport { EVENT_CODE } from '@element-plus/constants'\n\nlet registeredEscapeHandlers: ((e: KeyboardEvent) => void)[] = []\n\nconst cachedHandler = (e: Event) => {\n const event = e as KeyboardEvent\n if (event.key === EVENT_CODE.esc) {\n registeredEscapeHandlers.forEach((registeredHandler) =>\n registeredHandler(event)\n )\n }\n}\n\nexport const useEscapeKeydown = (handler: (e: KeyboardEvent) => void) => {\n onMounted(() => {\n if (registeredEscapeHandlers.length === 0) {\n document.addEventListener('keydown', cachedHandler)\n }\n if (isClient) registeredEscapeHandlers.push(handler)\n })\n\n onBeforeUnmount(() => {\n registeredEscapeHandlers = registeredEscapeHandlers.filter(\n (registeredHandler) => registeredHandler !== handler\n )\n if (registeredEscapeHandlers.length === 0) {\n if (isClient) document.removeEventListener('keydown', cachedHandler)\n }\n })\n}\n"],"names":[],"mappings":";;;;;;AAGA,IAAI,wBAAwB,GAAG,EAAE,CAAC;AAClC,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK;AAC7B,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC;AAClB,EAAE,IAAI,KAAK,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,EAAE;AACpC,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAC,iBAAiB,KAAK,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AACtF,GAAG;AACH,CAAC,CAAC;AACU,MAAC,gBAAgB,GAAG,CAAC,OAAO,KAAK;AAC7C,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,wBAAwB,CAAC,MAAM,KAAK,CAAC,EAAE;AAC/C,MAAM,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAC1D,KAAK;AACL,IAAI,IAAI,QAAQ;AAChB,MAAM,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7C,GAAG,CAAC,CAAC;AACL,EAAE,eAAe,CAAC,MAAM;AACxB,IAAI,wBAAwB,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC,iBAAiB,KAAK,iBAAiB,KAAK,OAAO,CAAC,CAAC;AACrH,IAAI,IAAI,wBAAwB,CAAC,MAAM,KAAK,CAAC,EAAE;AAC/C,MAAM,IAAI,QAAQ;AAClB,QAAQ,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAC/D,KAAK;AACL,GAAG,CAAC,CAAC;AACL;;;;"}