@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
30 lines (29 loc) • 1.48 kB
JavaScript
//#region src/controllers/focus-modality-controller.ts
var e = class {
constructor(e, t = null) {
this.pointerJustUsed = !1, this.handlePointerDown = () => {
this.pointerJustUsed = !0, this.pointerTimeoutId !== void 0 && clearTimeout(this.pointerTimeoutId), this.pointerTimeoutId = window.setTimeout(() => {
this.pointerJustUsed = !1, this.pointerTimeoutId = void 0;
}, 0);
}, this.handleFocusIn = () => {
this.setNavtype(this.pointerJustUsed ? "pointer" : void 0);
}, this.handleFocusOut = (e) => {
this.host.contains(e.relatedTarget) || this.setNavtype(void 0);
}, this.host = e, this.targetSelector = t, e.addController(this);
}
hostConnected() {
this.host.addEventListener("pointerdown", this.handlePointerDown, !0), this.host.addEventListener("focusin", this.handleFocusIn), this.host.addEventListener("focusout", this.handleFocusOut);
}
hostDisconnected() {
this.host.removeEventListener("pointerdown", this.handlePointerDown, !0), this.host.removeEventListener("focusin", this.handleFocusIn), this.host.removeEventListener("focusout", this.handleFocusOut), this.pointerTimeoutId !== void 0 && (clearTimeout(this.pointerTimeoutId), this.pointerTimeoutId = void 0);
}
getTarget() {
return this.targetSelector === null ? this.host : this.host.querySelector(this.targetSelector);
}
setNavtype(e) {
let t = this.getTarget();
t && (e === void 0 ? delete t.dataset.navtype : t.dataset.navtype = e);
}
};
//#endregion
export { e as t };