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6BACQ;AACb,UAAM,OAAO,GAAG,mCAAqB,KAAK,MAA1B,EAAkC,2BAAlC,CAAhB;AAEA,aAAO,OAAO,wBACX,OADW,EACD,EADC,CAAd;AAGD,KAPM;AAQP,IAAA,UARO,wBAQG;AACR,UAAI,KAAK,YAAL,IACF,CAAC,KAAK,KAAL,CAAW,OADV,IAEF,KAAK,WAFH,IAGF;AACA;AACA,WAAK,MAAL,KAAgB,EALd,IAKoB;AACtB,WAAK,MAAL,KAAgB,IANd,IAMsB;AACxB,WAAK,MAAL,KAAgB,QAPlB,CAO2B;AAP3B,QAQE;AAEF,UAAI,MAAJ;;AACA,UAAI,KAAK,MAAL,KAAgB,KAApB,EAA2B;AACzB;AACA,QAAA,MAAM,GAAG,QAAQ,CAAC,aAAT,CAAuB,YAAvB,CAAT;AACD,OAHD,MAGO,IAAI,OAAO,KAAK,MAAZ,KAAuB,QAA3B,EAAqC;AAC1C;AACA,QAAA,MAAM,GAAG,QAAQ,CAAC,aAAT,CAAuB,KAAK,MAA5B,CAAT;AACD,OAHM,MAGA;AACL;AACA,QAAA,MAAM,GAAG,KAAK,MAAd;AACD;;AAED,UAAI,CAAC,MAAL,EAAa;AACX,oEAAuC,KAAK,MAAL,IAAe,YAAtD,GAAsE,IAAtE;AACA;AACD;;AAED,MAAA,MAAM,CAAC,YAAP,CACE,KAAK,KAAL,CAAW,OADb,EAEE,MAAM,CAAC,UAFT;AAKA,WAAK,WAAL,GAAmB,IAAnB;AACD;AA1CM;AA3EQ,CAJJ,C","sourcesContent":["// Mixins\nimport Bootable from '../bootable'\n\n// Utilities\nimport { getObjectValueByPath } from '../../util/helpers'\nimport mixins, { ExtractVue } from '../../util/mixins'\nimport { consoleWarn } from '../../util/console'\n\n// Types\nimport Vue, { PropOptions } from 'vue'\nimport { VNode } from 'vue/types'\n\ninterface options extends Vue {\n $el: HTMLElement\n $refs: {\n content: HTMLElement\n }\n}\n\nfunction validateAttachTarget (val: any) {\n const type = typeof val\n\n if (type === 'boolean' || type === 'string') return true\n\n return val.nodeType === Node.ELEMENT_NODE\n}\n\n/* @vue/component */\nexport default mixins<options &\n /* eslint-disable indent */\n ExtractVue<typeof Bootable>\n /* eslint-enable indent */\n>(Bootable).extend({\n name: 'detachable',\n\n props: {\n attach: {\n default: false,\n validator: validateAttachTarget,\n } as PropOptions<boolean | string | Element>,\n contentClass: {\n type: String,\n default: '',\n },\n },\n\n data: () => ({\n activatorNode: null as null | VNode | VNode[],\n hasDetached: false,\n }),\n\n watch: {\n attach () {\n this.hasDetached = false\n this.initDetach()\n },\n hasContent: 'initDetach',\n },\n\n beforeMount () {\n this.$nextTick(() => {\n if (this.activatorNode) {\n const activator = Array.isArray(this.activatorNode) ? this.activatorNode : [this.activatorNode]\n\n activator.forEach(node => {\n if (!node.elm) return\n if (!this.$el.parentNode) return\n\n const target = this.$el === this.$el.parentNode.firstChild\n ? this.$el\n : this.$el.nextSibling\n\n this.$el.parentNode.insertBefore(node.elm, target)\n })\n }\n })\n },\n\n mounted () {\n this.eager && this.initDetach()\n },\n\n deactivated () {\n this.isActive = false\n },\n\n beforeDestroy () {\n // IE11 Fix\n try {\n if (\n this.$refs.content &&\n this.$refs.content.parentNode\n ) {\n this.$refs.content.parentNode.removeChild(this.$refs.content)\n }\n\n if (this.activatorNode) {\n const activator = Array.isArray(this.activatorNode) ? this.activatorNode : [this.activatorNode]\n activator.forEach(node => {\n node.elm &&\n node.elm.parentNode &&\n node.elm.parentNode.removeChild(node.elm)\n })\n }\n } catch (e) { console.log(e) }\n },\n\n methods: {\n getScopeIdAttrs () {\n const scopeId = getObjectValueByPath(this.$vnode, 'context.$options._scopeId')\n\n return scopeId && {\n [scopeId]: '',\n }\n },\n initDetach () {\n if (this._isDestroyed ||\n !this.$refs.content ||\n this.hasDetached ||\n // Leave menu in place if attached\n // and dev has not changed target\n this.attach === '' || // If used as a boolean prop (<v-menu attach>)\n this.attach === true || // If bound to a boolean (<v-menu :attach=\"true\">)\n this.attach === 'attach' // If bound as boolean prop in pug (v-menu(attach))\n ) return\n\n let target\n if (this.attach === false) {\n // Default, detach to app\n target = document.querySelector('[data-app]')\n } else if (typeof this.attach === 'string') {\n // CSS selector\n target = document.querySelector(this.attach)\n } else {\n // DOM Element\n target = this.attach\n }\n\n if (!target) {\n consoleWarn(`Unable to locate target ${this.attach || '[data-app]'}`, this)\n return\n }\n\n target.insertBefore(\n this.$refs.content,\n target.firstChild\n )\n\n this.hasDetached = true\n },\n },\n})\n"],"sourceRoot":"","file":"index.js"} |