primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
1 lines • 14.5 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../src/focustrap/BaseFocusTrap.js","../../src/focustrap/FocusTrap.js"],"sourcesContent":["import BaseDirective from '@primevue/core/basedirective';\nimport FocusTrapStyle from 'primevue/focustrap/style';\n\nconst BaseFocusTrap = BaseDirective.extend({\n style: FocusTrapStyle\n});\n\nexport default BaseFocusTrap;\n","import { createElement, focus, getFirstFocusableElement, getLastFocusableElement, isFocusableElement } from '@primeuix/utils/dom';\nimport { isNotEmpty } from '@primeuix/utils/object';\nimport BaseFocusTrap from './BaseFocusTrap';\n\nconst FocusTrap = BaseFocusTrap.extend('focustrap', {\n mounted(el, binding) {\n const { disabled } = binding.value || {};\n\n if (!disabled) {\n this.createHiddenFocusableElements(el, binding);\n this.bind(el, binding);\n this.autoElementFocus(el, binding);\n }\n\n el.setAttribute('data-pd-focustrap', true);\n\n this.$el = el;\n },\n updated(el, binding) {\n const { disabled } = binding.value || {};\n\n disabled && this.unbind(el);\n },\n unmounted(el) {\n this.unbind(el);\n },\n methods: {\n getComputedSelector(selector) {\n return `:not(.p-hidden-focusable):not([data-p-hidden-focusable=\"true\"])${selector ?? ''}`;\n },\n bind(el, binding) {\n const { onFocusIn, onFocusOut } = binding.value || {};\n\n el.$_pfocustrap_mutationobserver = new MutationObserver((mutationList) => {\n mutationList.forEach((mutation) => {\n if (mutation.type === 'childList' && !el.contains(document.activeElement)) {\n const findNextFocusableElement = (_el) => {\n const focusableElement = isFocusableElement(_el)\n ? isFocusableElement(_el, this.getComputedSelector(el.$_pfocustrap_focusableselector))\n ? _el\n : getFirstFocusableElement(el, this.getComputedSelector(el.$_pfocustrap_focusableselector))\n : getFirstFocusableElement(_el);\n\n return isNotEmpty(focusableElement) ? focusableElement : _el.nextSibling && findNextFocusableElement(_el.nextSibling);\n };\n\n focus(findNextFocusableElement(mutation.nextSibling));\n }\n });\n });\n\n el.$_pfocustrap_mutationobserver.disconnect();\n el.$_pfocustrap_mutationobserver.observe(el, {\n childList: true\n });\n\n el.$_pfocustrap_focusinlistener = (event) => onFocusIn && onFocusIn(event);\n el.$_pfocustrap_focusoutlistener = (event) => onFocusOut && onFocusOut(event);\n\n el.addEventListener('focusin', el.$_pfocustrap_focusinlistener);\n el.addEventListener('focusout', el.$_pfocustrap_focusoutlistener);\n },\n unbind(el) {\n el.$_pfocustrap_mutationobserver && el.$_pfocustrap_mutationobserver.disconnect();\n el.$_pfocustrap_focusinlistener && el.removeEventListener('focusin', el.$_pfocustrap_focusinlistener) && (el.$_pfocustrap_focusinlistener = null);\n el.$_pfocustrap_focusoutlistener && el.removeEventListener('focusout', el.$_pfocustrap_focusoutlistener) && (el.$_pfocustrap_focusoutlistener = null);\n },\n autoFocus(options) {\n this.autoElementFocus(this.$el, { value: { ...options, autoFocus: true } });\n },\n autoElementFocus(el, binding) {\n const { autoFocusSelector = '', firstFocusableSelector = '', autoFocus = false } = binding.value || {};\n let focusableElement = getFirstFocusableElement(el, `[autofocus]${this.getComputedSelector(autoFocusSelector)}`);\n\n autoFocus && !focusableElement && (focusableElement = getFirstFocusableElement(el, this.getComputedSelector(firstFocusableSelector)));\n focus(focusableElement);\n },\n onFirstHiddenElementFocus(event) {\n const { currentTarget, relatedTarget } = event;\n const focusableElement =\n relatedTarget === currentTarget.$_pfocustrap_lasthiddenfocusableelement || !this.$el?.contains(relatedTarget)\n ? getFirstFocusableElement(currentTarget.parentElement, this.getComputedSelector(currentTarget.$_pfocustrap_focusableselector))\n : currentTarget.$_pfocustrap_lasthiddenfocusableelement;\n\n focus(focusableElement);\n },\n onLastHiddenElementFocus(event) {\n const { currentTarget, relatedTarget } = event;\n const focusableElement =\n relatedTarget === currentTarget.$_pfocustrap_firsthiddenfocusableelement || !this.$el?.contains(relatedTarget)\n ? getLastFocusableElement(currentTarget.parentElement, this.getComputedSelector(currentTarget.$_pfocustrap_focusableselector))\n : currentTarget.$_pfocustrap_firsthiddenfocusableelement;\n\n focus(focusableElement);\n },\n createHiddenFocusableElements(el, binding) {\n const { tabIndex = 0, firstFocusableSelector = '', lastFocusableSelector = '' } = binding.value || {};\n\n const createFocusableElement = (onFocus) => {\n return createElement('span', {\n class: 'p-hidden-accessible p-hidden-focusable',\n tabIndex,\n role: 'presentation',\n 'aria-hidden': true,\n 'data-p-hidden-accessible': true,\n 'data-p-hidden-focusable': true,\n onFocus: onFocus?.bind(this)\n });\n };\n\n const firstFocusableElement = createFocusableElement(this.onFirstHiddenElementFocus);\n const lastFocusableElement = createFocusableElement(this.onLastHiddenElementFocus);\n\n firstFocusableElement.$_pfocustrap_lasthiddenfocusableelement = lastFocusableElement;\n firstFocusableElement.$_pfocustrap_focusableselector = firstFocusableSelector;\n firstFocusableElement.setAttribute('data-pc-section', 'firstfocusableelement');\n\n lastFocusableElement.$_pfocustrap_firsthiddenfocusableelement = firstFocusableElement;\n lastFocusableElement.$_pfocustrap_focusableselector = lastFocusableSelector;\n lastFocusableElement.setAttribute('data-pc-section', 'lastfocusableelement');\n\n el.prepend(firstFocusableElement);\n el.append(lastFocusableElement);\n }\n }\n});\n\nexport default FocusTrap;\n"],"names":["BaseFocusTrap","BaseDirective","extend","style","FocusTrapStyle","FocusTrap","mounted","el","binding","_ref","value","disabled","createHiddenFocusableElements","bind","autoElementFocus","setAttribute","$el","updated","_ref2","unbind","unmounted","methods","getComputedSelector","selector","concat","_this","_ref3","onFocusIn","onFocusOut","$_pfocustrap_mutationobserver","MutationObserver","mutationList","forEach","mutation","type","contains","document","activeElement","findNextFocusableElement","_el","focusableElement","isFocusableElement","$_pfocustrap_focusableselector","getFirstFocusableElement","isNotEmpty","nextSibling","focus","disconnect","observe","childList","$_pfocustrap_focusinlistener","event","$_pfocustrap_focusoutlistener","addEventListener","removeEventListener","autoFocus","options","_objectSpread","_ref4","_ref4$autoFocusSelect","autoFocusSelector","_ref4$firstFocusableS","firstFocusableSelector","_ref4$autoFocus","onFirstHiddenElementFocus","_this$$el","currentTarget","relatedTarget","$_pfocustrap_lasthiddenfocusableelement","parentElement","onLastHiddenElementFocus","_this$$el2","$_pfocustrap_firsthiddenfocusableelement","getLastFocusableElement","_this2","_ref5","_ref5$tabIndex","tabIndex","_ref5$firstFocusableS","_ref5$lastFocusableSe","lastFocusableSelector","createFocusableElement","onFocus","createElement","role","firstFocusableElement","lastFocusableElement","prepend","append"],"mappings":";;;;;AAGA,IAAMA,aAAa,GAAGC,aAAa,CAACC,MAAM,CAAC;AACvCC,EAAAA,KAAK,EAAEC;AACX,CAAC,CAAC;;;;;;;;ACDF,IAAMC,SAAS,GAAGL,aAAa,CAACE,MAAM,CAAC,WAAW,EAAE;AAChDI,EAAAA,OAAO,WAAPA,OAAOA,CAACC,EAAE,EAAEC,OAAO,EAAE;AACjB,IAAA,IAAAC,IAAA,GAAqBD,OAAO,CAACE,KAAK,IAAI,EAAE;MAAhCC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;IAEhB,IAAI,CAACA,QAAQ,EAAE;AACX,MAAA,IAAI,CAACC,6BAA6B,CAACL,EAAE,EAAEC,OAAO,CAAC;AAC/C,MAAA,IAAI,CAACK,IAAI,CAACN,EAAE,EAAEC,OAAO,CAAC;AACtB,MAAA,IAAI,CAACM,gBAAgB,CAACP,EAAE,EAAEC,OAAO,CAAC;AACtC;AAEAD,IAAAA,EAAE,CAACQ,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC;IAE1C,IAAI,CAACC,GAAG,GAAGT,EAAE;GAChB;AACDU,EAAAA,OAAO,WAAPA,OAAOA,CAACV,EAAE,EAAEC,OAAO,EAAE;AACjB,IAAA,IAAAU,KAAA,GAAqBV,OAAO,CAACE,KAAK,IAAI,EAAE;MAAhCC,QAAQ,GAAAO,KAAA,CAARP,QAAQ;AAEhBA,IAAAA,QAAQ,IAAI,IAAI,CAACQ,MAAM,CAACZ,EAAE,CAA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