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IAAA,eAAe,GAAA;AACb,YAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,MAAN,EAAc,2BAAd,CAApC;AAEA,aAAO,OAAO,IAAI;AAChB,SAAC,OAAD,GAAW;AADK,OAAlB;AAGD,KAPM;;AAQP,IAAA,UAAU,GAAA;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,QAAA,WAAW,CAAC,2BAA2B,KAAK,MAAL,IAAe,YAAY,EAAvD,EAA2D,IAA3D,CAAX;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,CAAf","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"} |