UNPKG

@nextcloud/vue

Version:
48 lines (47 loc) 2.47 kB
import "../assets/index6.css"; import { Dropdown as r } from "floating-vue"; import { createFocusTrap as s } from "focus-trap"; import { g as a } from "../chunks/focusTrap-173aba65.mjs"; import { n as p } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs"; const n = { name: "NcPopover", components: { Dropdown: r }, inheritAttrs: !1, props: { popoverBaseClass: { type: String, default: "" }, focusTrap: { type: Boolean, default: !0 }, setReturnFocus: { default: void 0, type: [HTMLElement, SVGElement, String, Boolean] } }, emits: ["after-show", "after-hide"], beforeDestroy() { this.clearFocusTrap(), this.clearEscapeStopPropagation(); }, methods: { getPopoverContentElement() { var e, t; return (t = (e = this.$refs.popover) == null ? void 0 : e.$refs.popperContent) == null ? void 0 : t.$el; }, async useFocusTrap() { if (await this.$nextTick(), !this.focusTrap) return; const e = this.getPopoverContentElement(); e && (this.$focusTrap = s(e, { escapeDeactivates: !1, allowOutsideClick: !0, setReturnFocus: this.setReturnFocus, trapStack: a() }), this.$focusTrap.activate()); }, clearFocusTrap(e = {}) { var t; try { (t = this.$focusTrap) == null || t.deactivate(e), this.$focusTrap = null; } catch (o) { console.warn(o); } }, addEscapeStopPropagation() { var e; (e = this.getPopoverContentElement()) == null || e.addEventListener("keydown", this.stopKeydownEscapeHandler); }, clearEscapeStopPropagation() { var e; (e = this.getPopoverContentElement()) == null || e.removeEventListener("keydown", this.stopKeydownEscapeHandler); }, stopKeydownEscapeHandler(e) { e.type === "keydown" && e.key === "Escape" && e.stopPropagation(); }, afterShow() { this.$nextTick(() => { this.$emit("after-show"), this.useFocusTrap(), this.addEscapeStopPropagation(); }); }, afterHide() { this.$emit("after-hide"), this.clearFocusTrap(), this.clearEscapeStopPropagation(); } } }; var i = function() { var e = this, t = e._self._c; return t("Dropdown", e._g(e._b({ ref: "popover", attrs: { distance: 10, "arrow-padding": 10, "no-auto-focus": !0, "popper-class": e.popoverBaseClass }, on: { "apply-show": e.afterShow, "apply-hide": e.afterHide }, scopedSlots: e._u([{ key: "popper", fn: function() { return [e._t("default")]; }, proxy: !0 }], null, !0) }, "Dropdown", e.$attrs, !1), e.$listeners), [e._t("trigger")], 2); }, c = [], l = p(n, i, c, !1, null, null, null, null); const w = l.exports; export { w as default };