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AAvC;AACA,WAAG,aAAH,GAAmB,OAAnB;AACD,KAfY;AAiBb,UAjBa,kBAiBL,EAjBK,EAiBU;AACrB,YAAI,CAAC,GAAG,aAAR,EAAuB;AAEvB,YAAM,MAAM,SAAS,aAAT,CAAuB,YAAvB,KACV,SAAS,IADX,CAHqB,CAIL;AAChB,eAAO,IAAI,mBAAJ,CAAwB,OAAxB,EAAiC,GAAG,aAApC,EAAmD,IAAnD,CAAP;AACA,eAAO,GAAG,aAAV;AACD;AAxBY,C","sourcesContent":["import { VNodeDirective } from 'vue/types/vnode'\n\ninterface ClickOutsideBindingArgs {\n closeConditional?: (e: Event) => boolean\n include?: () => HTMLElement[]\n}\n\ninterface ClickOutsideDirective extends VNodeDirective {\n value?: (e: Event) => void\n args?: ClickOutsideBindingArgs\n}\n\nfunction closeConditional () {\n return false\n}\n\nfunction directive (e: PointerEvent, el: HTMLElement, binding: ClickOutsideDirective): void {\n // Args may not always be supplied\n binding.args = binding.args || {}\n\n // If no closeConditional was supplied assign a default\n const isActive = (binding.args.closeConditional || closeConditional)\n\n // The include element callbacks below can be expensive\n // so we should avoid calling them when we're not active.\n // Explicitly check for false to allow fallback compatibility\n // with non-toggleable components\n if (!e || isActive(e) === false) return\n\n // If click was triggered programmaticaly (domEl.click()) then\n // it shouldn't be treated as click-outside\n // Chrome/Firefox support isTrusted property\n // IE/Edge support pointerType property (empty if not triggered\n // by pointing device)\n if (('isTrusted' in e && !e.isTrusted) ||\n ('pointerType' in e && !e.pointerType)\n ) return\n\n // Check if additional elements were passed to be included in check\n // (click must be outside all included elements, if any)\n const elements = (binding.args.include || (() => []))()\n // Add the root element for the component this directive was defined on\n elements.push(el)\n\n // Check if it's a click outside our elements, and then if our callback returns true.\n // Non-toggleable components should take action in their callback and return falsy.\n // Toggleable can return true if it wants to deactivate.\n // Note that, because we're in the capture phase, this callback will occur before\n // the bubbling click event on any outside elements.\n !elements.some(el => el.contains(e.target as Node)) && setTimeout(() => {\n isActive(e) && binding.value && binding.value(e)\n }, 0)\n}\n\nexport default {\n // [data-app] may not be found\n // if using bind, inserted makes\n // sure that the root element is\n // available, iOS does not support\n // clicks on body\n inserted (el: HTMLElement, binding: ClickOutsideDirective) {\n const onClick = (e: Event) => directive(e as PointerEvent, el, binding)\n // iOS does not recognize click events on document\n // or body, this is the entire purpose of the v-app\n // component and [data-app], stop removing this\n const app = document.querySelector('[data-app]') ||\n document.body // This is only for unit tests\n app.addEventListener('click', onClick, true)\n el._clickOutside = onClick\n },\n\n unbind (el: HTMLElement) {\n if (!el._clickOutside) return\n\n const app = document.querySelector('[data-app]') ||\n document.body // This is only for unit tests\n app && app.removeEventListener('click', el._clickOutside, true)\n delete el._clickOutside\n }\n}\n"],"sourceRoot":""}
|