@floegence/floe-webapp-core 0.86.34 → 0.86.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ export interface UseOverlayMaskOptions {
8
8
  /** Ordered focus regions that belong to one overlay, including persistent navigation. */
9
9
  focusRoots?: Accessor<readonly HTMLElement[]>;
10
10
  onClose?: () => void;
11
+ /** Outside pointer/focus interactions routed only to the owning overlay layer. */
12
+ onInteractOutside?: (event: PointerEvent | FocusEvent) => void;
11
13
  /** Treat additional nodes as part of the overlay surface (e.g. portaled layers). */
12
14
  containsTarget?: (target: EventTarget | null) => boolean;
13
15
  /** Optional alternate close path for Escape pressed outside the overlay surface. */
@@ -1,65 +1,65 @@
1
- import { createEffect as Q, onCleanup as U } from "solid-js";
2
- import { lockBodyStyle as X } from "../utils/bodyStyleLock.js";
3
- import { deferAfterPaint as K } from "../utils/defer.js";
4
- import { getFocusableElements as x, getFirstFocusableElement as Y } from "../utils/focus.js";
5
- import { matchKeybind as Z } from "../utils/keybind.js";
1
+ import { createEffect as U, onCleanup as X } from "solid-js";
2
+ import { lockBodyStyle as Y } from "../utils/bodyStyleLock.js";
3
+ import { deferAfterPaint as x } from "../utils/defer.js";
4
+ import { getFocusableElements as I, getFirstFocusableElement as Z } from "../utils/focus.js";
5
+ import { matchKeybind as _ } from "../utils/keybind.js";
6
6
  const H = /* @__PURE__ */ new WeakMap();
7
7
  function A(t) {
8
8
  return typeof Node < "u" && t instanceof Node;
9
9
  }
10
- function p(t, o, c) {
10
+ function g(t, o, c) {
11
11
  return c ? c(o) : !t || !A(o) ? !1 : t.contains(o);
12
12
  }
13
- function W(t, o, c, i) {
14
- return c === "none" ? !1 : c === "all" ? !0 : !p(t, o, i);
13
+ function W(t, o, c, f) {
14
+ return c === "none" ? !1 : c === "all" ? !0 : !g(t, o, f);
15
15
  }
16
- function _(t) {
16
+ function $(t) {
17
17
  return typeof t == "function" ? t() ?? [] : t ?? [];
18
18
  }
19
19
  function s(t, o) {
20
20
  return typeof t == "function" ? t() ?? o : t ?? o;
21
21
  }
22
- function $(t, o) {
23
- for (const c of _(o)) {
24
- const i = c.trim();
25
- if (i && Z(t, i))
22
+ function ee(t, o) {
23
+ for (const c of $(o)) {
24
+ const f = c.trim();
25
+ if (f && _(t, f))
26
26
  return !0;
27
27
  }
28
28
  return !1;
29
29
  }
30
- function ue(t) {
31
- const o = () => s(t.lockBodyScroll, !0), c = () => s(t.trapFocus, !0), i = () => {
32
- const f = s(
30
+ function se(t) {
31
+ const o = () => s(t.lockBodyScroll, !0), c = () => s(t.trapFocus, !0), f = () => {
32
+ const l = s(
33
33
  t.closeOnEscape,
34
34
  !0
35
35
  );
36
- return f === !1 ? "none" : f === "inside" ? "inside" : f === "none" ? "none" : "always";
37
- }, I = () => s(t.blockHotkeys, !0), R = () => s(t.restoreFocus, !0), N = () => s(t.blockWheel, "none"), q = () => s(t.blockTouchMove, "none"), j = () => s(t.autoFocus, !0);
38
- Q(() => {
36
+ return l === !1 ? "none" : l === "inside" ? "inside" : l === "none" ? "none" : "always";
37
+ }, R = () => s(t.blockHotkeys, !0), N = () => s(t.restoreFocus, !0), q = () => s(t.blockWheel, "none"), j = () => s(t.blockTouchMove, "none"), z = () => s(t.autoFocus, !0);
38
+ U(() => {
39
39
  if (!t.open() || typeof document > "u") return;
40
- const f = o(), w = c(), v = i(), h = s(t.escapeKeyPhase, "capture"), z = I(), V = R(), g = N(), k = q(), E = j(), d = H.get(document) ?? [];
40
+ const l = o(), L = c(), v = f(), y = s(t.escapeKeyPhase, "capture"), V = R(), G = N(), E = q(), k = j(), b = z(), d = H.get(document) ?? [];
41
41
  H.set(document, d);
42
- const y = {
43
- global: f || v === "always",
44
- contains: (e) => p(t.root(), e, t.containsTarget)
42
+ const h = {
43
+ global: l || v === "always",
44
+ contains: (e) => g(t.root(), e, t.containsTarget)
45
45
  };
46
- d.push(y);
47
- let T = !0;
48
- const l = (e) => T && !d.slice(d.indexOf(y) + 1).some((n) => n.global || n.contains(e)), b = document.activeElement instanceof HTMLElement ? document.activeElement : null, G = f ? X({ overflow: "hidden" }) : null;
49
- K(() => {
46
+ d.push(h);
47
+ let O = !0;
48
+ const a = (e) => O && !d.slice(d.indexOf(h) + 1).some((n) => n.global || n.contains(e)), w = document.activeElement instanceof HTMLElement ? document.activeElement : null, J = l ? Y({ overflow: "hidden" }) : null;
49
+ x(() => {
50
50
  const e = t.root();
51
- if (!e?.isConnected || !l(e) || E === !1 || y.contains(document.activeElement)) return;
52
- const n = typeof E == "object" ? E.selector : void 0, r = (n ? e.querySelector(n) : null) ?? e.querySelector("[data-floe-autofocus]") ?? Y(e) ?? e;
51
+ if (!e?.isConnected || !a(e) || b === !1 || h.contains(document.activeElement)) return;
52
+ const n = typeof b == "object" ? b.selector : void 0, r = (n ? e.querySelector(n) : null) ?? e.querySelector("[data-floe-autofocus]") ?? Z(e) ?? e;
53
53
  try {
54
54
  r.focus({ preventScroll: !0 });
55
55
  } catch {
56
56
  }
57
57
  });
58
- const L = (e) => {
59
- if (e.key !== "Tab" || !l(e.target)) return;
58
+ const T = (e) => {
59
+ if (e.key !== "Tab" || !a(e.target)) return;
60
60
  const n = t.root();
61
61
  if (!n) return;
62
- const m = t.focusRoots?.() ?? [n], r = t.focusRoots ? [...new Set(m.flatMap(x))].filter((u) => u.tabIndex >= 0 && !u.closest('[hidden], [inert], [aria-hidden="true"]')) : x(n);
62
+ const m = t.focusRoots?.() ?? [n], r = t.focusRoots ? [...new Set(m.flatMap(I))].filter((u) => u.tabIndex >= 0 && !u.closest('[hidden], [inert], [aria-hidden="true"]')) : I(n);
63
63
  if (!r.length) {
64
64
  e.preventDefault();
65
65
  try {
@@ -68,30 +68,30 @@ function ue(t) {
68
68
  }
69
69
  return;
70
70
  }
71
- const D = r[0], P = r[r.length - 1], a = document.activeElement instanceof HTMLElement ? document.activeElement : null;
71
+ const P = r[0], K = r[r.length - 1], i = document.activeElement instanceof HTMLElement ? document.activeElement : null;
72
72
  if (t.focusRoots) {
73
- const u = a ? r.indexOf(a) : -1, J = u < 0 ? e.shiftKey ? r.length - 1 : 0 : (u + (e.shiftKey ? -1 : 1) + r.length) % r.length;
74
- e.preventDefault(), r[J]?.focus({ preventScroll: !0 });
73
+ const u = i ? r.indexOf(i) : -1, Q = u < 0 ? e.shiftKey ? r.length - 1 : 0 : (u + (e.shiftKey ? -1 : 1) + r.length) % r.length;
74
+ e.preventDefault(), r[Q]?.focus({ preventScroll: !0 });
75
75
  return;
76
76
  }
77
77
  if (e.shiftKey) {
78
- if (a === D || !a || !m.some((u) => u.contains(a))) {
78
+ if (i === P || !i || !m.some((u) => u.contains(i))) {
79
79
  e.preventDefault();
80
80
  try {
81
- P.focus();
81
+ K.focus();
82
82
  } catch {
83
83
  }
84
84
  }
85
- } else if (a === P || !a || !m.some((u) => u.contains(a))) {
85
+ } else if (i === K || !i || !m.some((u) => u.contains(i))) {
86
86
  e.preventDefault();
87
87
  try {
88
- D.focus();
88
+ P.focus();
89
89
  } catch {
90
90
  }
91
91
  }
92
92
  }, M = (e) => {
93
- if (e.key !== "Escape" || !l(e.target) || h === "bubble" && (e.defaultPrevented || e.isComposing) || v === "none") return;
94
- const n = t.root(), m = p(
93
+ if (e.key !== "Escape" || !a(e.target) || y === "bubble" && (e.defaultPrevented || e.isComposing) || v === "none") return;
94
+ const n = t.root(), m = g(
95
95
  n,
96
96
  A(e.target) ? e.target : document.activeElement,
97
97
  t.containsTarget
@@ -105,41 +105,43 @@ function ue(t) {
105
105
  return;
106
106
  }
107
107
  e.preventDefault(), e.stopImmediatePropagation(), t.onClose?.();
108
- }, O = (e) => {
109
- if (!l(e.target)) return;
110
- const n = t.root();
111
- n && z && p(n, e.target, t.containsTarget) && ($(e, t.allowHotkeys) || e.stopPropagation());
112
108
  }, B = (e) => {
113
- if (!l(e.target)) return;
109
+ if (!a(e.target)) return;
114
110
  const n = t.root();
115
- W(n, e.target, g, t.containsTarget) && e.cancelable && e.preventDefault();
111
+ n && V && g(n, e.target, t.containsTarget) && (ee(e, t.allowHotkeys) || e.stopPropagation());
116
112
  }, F = (e) => {
117
- l(e.target) && e.stopPropagation();
113
+ if (!a(e.target)) return;
114
+ const n = t.root();
115
+ W(n, e.target, E, t.containsTarget) && e.cancelable && e.preventDefault();
118
116
  }, S = (e) => {
119
- if (!l(e.target)) return;
117
+ a(e.target) && e.stopPropagation();
118
+ }, C = (e) => {
119
+ if (!a(e.target)) return;
120
120
  const n = t.root();
121
121
  W(n, e.target, k, t.containsTarget) && e.cancelable && e.preventDefault();
122
+ }, p = (e) => {
123
+ a(e.target) && !h.contains(e.target) && t.onInteractOutside?.(e);
122
124
  };
123
- w && document.addEventListener("keydown", L, !0);
124
- const C = h === "capture" ? window : document;
125
- v !== "none" && C.addEventListener(
125
+ t.onInteractOutside && (document.addEventListener("pointerdown", p, !0), document.addEventListener("focusin", p)), L && document.addEventListener("keydown", T, !0);
126
+ const D = y === "capture" ? window : document;
127
+ v !== "none" && D.addEventListener(
126
128
  "keydown",
127
129
  M,
128
- h === "capture"
129
- ), document.addEventListener("keydown", O), g !== "none" && (document.addEventListener("wheel", B, { capture: !0, passive: !1 }), document.addEventListener("wheel", F)), k !== "none" && document.addEventListener("touchmove", S, {
130
+ y === "capture"
131
+ ), document.addEventListener("keydown", B), E !== "none" && (document.addEventListener("wheel", F, { capture: !0, passive: !1 }), document.addEventListener("wheel", S)), k !== "none" && document.addEventListener("touchmove", C, {
130
132
  capture: !0,
131
133
  passive: !1
132
- }), U(() => {
133
- T = !1, d.splice(d.indexOf(y), 1), w && document.removeEventListener("keydown", L, !0), v !== "none" && C.removeEventListener(
134
+ }), X(() => {
135
+ O = !1, document.removeEventListener("pointerdown", p, !0), document.removeEventListener("focusin", p), d.splice(d.indexOf(h), 1), L && document.removeEventListener("keydown", T, !0), v !== "none" && D.removeEventListener(
134
136
  "keydown",
135
137
  M,
136
- h === "capture"
137
- ), document.removeEventListener("keydown", O), g !== "none" && (document.removeEventListener("wheel", B, !0), document.removeEventListener("wheel", F)), k !== "none" && document.removeEventListener("touchmove", S, !0), G?.(), V && b && b.isConnected && K(() => {
138
+ y === "capture"
139
+ ), document.removeEventListener("keydown", B), E !== "none" && (document.removeEventListener("wheel", F, !0), document.removeEventListener("wheel", S)), k !== "none" && document.removeEventListener("touchmove", C, !0), J?.(), G && w && w.isConnected && x(() => {
138
140
  if (typeof document > "u") return;
139
141
  const e = document.activeElement;
140
142
  if (!(e && e !== document.body && e !== document.documentElement))
141
143
  try {
142
- b.focus({ preventScroll: !0 });
144
+ w.focus({ preventScroll: !0 });
143
145
  } catch {
144
146
  }
145
147
  });
@@ -147,5 +149,5 @@ function ue(t) {
147
149
  });
148
150
  }
149
151
  export {
150
- ue as useOverlayMask
152
+ se as useOverlayMask
151
153
  };