@floegence/floe-webapp-core 0.100.0 → 0.101.1

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.
@@ -1,6 +1,8 @@
1
1
  import { type JSX } from 'solid-js';
2
2
  export interface SurfaceAnchoredLayerProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style' | 'ref'> {
3
3
  anchor: HTMLElement | undefined;
4
+ /** Global navigation may escape its source surface while retaining the anchor. */
5
+ portalScope?: 'surface' | 'viewport';
4
6
  /** Changes when the anchor moves through a transform; no idle polling is used. */
5
7
  revision?: unknown;
6
8
  /** Screen-space clearance above labels outside the object bounds. */
@@ -1,66 +1,64 @@
1
- import { createComponent as E, mergeProps as K, memo as N } from "solid-js/web";
2
- import { splitProps as Q, createSignal as f, createEffect as M, onCleanup as R, onMount as U, Show as Z, untrack as _ } from "solid-js";
1
+ import { createComponent as L, mergeProps as K, memo as N } from "solid-js/web";
2
+ import { splitProps as Q, createSignal as m, createEffect as M, onCleanup as S, onMount as U, Show as Z, untrack as _ } from "solid-js";
3
3
  import { SurfaceFloatingLayer as tt } from "./SurfaceFloatingLayer.js";
4
4
  import { resolveFloatingBoundary as et } from "./surfaceFloatingBoundary.js";
5
5
  import { observeViewport as ot } from "../../viewport.js";
6
- import { resolveSurfacePortalHost as L } from "./dialogSurfaceScope.js";
7
- function lt(H) {
8
- const [e, $] = Q(H, ["anchor", "revision", "topOffset", "reservedSpace", "placement", "align", "gap", "children", "class", "style", "layerRef", "onAnchorDisconnect"]), [S, k] = f(!1), [q, B] = f({
6
+ import { resolveSurfacePortalHost as nt } from "./dialogSurfaceScope.js";
7
+ function ht(H) {
8
+ const [e, $] = Q(H, ["anchor", "portalScope", "revision", "topOffset", "reservedSpace", "placement", "align", "gap", "children", "class", "style", "layerRef", "onAnchorDisconnect"]), [R, k] = m(!1), [q, B] = m({
9
9
  x: 0,
10
10
  y: 0
11
- }), [V, Y] = f("above"), [A, v] = f(!1), [D, T] = f(480), [F, W] = f();
12
- let m, w = !1;
13
- const [O, X] = f({
11
+ }), [V, Y] = m("above"), [A, b] = m(!1), [D, T] = m(480), [F, W] = m();
12
+ let d, w = !1;
13
+ const [O, X] = m({
14
14
  x: 0,
15
15
  y: 0
16
- }), [j, G] = f(0), P = () => {
17
- m = void 0;
16
+ }), [j, G] = m(0), P = () => nt({
17
+ owner: e.portalScope === "viewport" ? document.documentElement : e.anchor
18
+ }), z = () => {
19
+ d = void 0;
18
20
  const n = e.anchor, l = F();
19
21
  if (!n || !l) return;
20
22
  if (!n.isConnected) {
21
- v(!1), w || e.onAnchorDisconnect?.(), w = !0;
23
+ b(!1), w || e.onAnchorDisconnect?.(), w = !0;
22
24
  return;
23
25
  }
24
26
  w = !1;
25
- const o = et(L({
26
- owner: n
27
- }));
27
+ const o = et(P());
28
28
  if (!o) {
29
- v(!1);
29
+ b(!1);
30
30
  return;
31
31
  }
32
- const t = n.getBoundingClientRect(), s = e.reservedSpace, d = o.top + (window.matchMedia("(max-width:760px)").matches ? s?.narrowTop ?? s?.top ?? 12 : s?.top ?? 12);
33
- T(Math.max(120, o.width - 24)), G(Math.max(0, o.bottom - (s?.bottom ?? 12) - d));
34
- const i = l.getBoundingClientRect(), I = (Math.max(o.left, t.left) + Math.min(o.right, t.right)) / 2, z = getComputedStyle(n).direction === "rtl", J = e.align === "start" ? z ? t.right - i.width : t.left : e.align === "end" ? z ? t.left : t.right - i.width : I - i.width / 2;
35
- let p = Math.max(o.left + 12, Math.min(J, o.right - i.width - 12));
36
- const x = t.top - (e.topOffset ?? 0), r = Math.max(0, e.gap ?? 12), g = x - i.height - r, y = Math.max(d, o.bottom - (s?.bottom ?? 12) - i.height), u = (b) => Math.max(d, Math.min(b, y));
32
+ const t = n.getBoundingClientRect(), s = e.reservedSpace, f = o.top + (window.matchMedia("(max-width:760px)").matches ? s?.narrowTop ?? s?.top ?? 12 : s?.top ?? 12);
33
+ T(Math.max(120, o.width - 24)), G(Math.max(0, o.bottom - (s?.bottom ?? 12) - f));
34
+ const r = l.getBoundingClientRect(), I = (Math.max(o.left, t.left) + Math.min(o.right, t.right)) / 2, C = getComputedStyle(n).direction === "rtl", J = e.align === "start" ? C ? t.right - r.width : t.left : e.align === "end" ? C ? t.left : t.right - r.width : I - r.width / 2;
35
+ let p = Math.max(o.left + 12, Math.min(J, o.right - r.width - 12));
36
+ const x = t.top - (e.topOffset ?? 0), i = Math.max(0, e.gap ?? 12), g = x - r.height - i, y = Math.max(f, o.bottom - (s?.bottom ?? 12) - r.height), u = (v) => Math.max(f, Math.min(v, y));
37
37
  let c = g, a = "above";
38
38
  if (e.placement === "right" || e.placement === "left") {
39
- const b = t.right + r + i.width <= o.right - 12, C = t.left - r - i.width >= o.left + 12;
40
- a = e.placement, a === "right" && !b && C ? a = "left" : a === "left" && !C && b && (a = "right"), p = Math.max(o.left + 12, Math.min(a === "right" ? t.right + r : t.left - i.width - r, o.right - i.width - 12)), c = u(t.top + t.height / 2 - i.height / 2);
41
- } else g < d ? t.bottom + r <= y ? (c = t.bottom + r, a = "below") : g >= o.top + 12 ? a = "above" : t.bottom + i.height + r <= o.bottom - 12 ? (c = t.bottom + r, a = "below") : t.right + i.width + r + 12 <= o.right ? (p = t.right + r, c = u(x), a = "right") : t.left - i.width - r - 12 >= o.left ? (p = t.left - i.width - r, c = u(x), a = "left") : (c = u(g), a = "edge") : c = Math.min(c, y);
39
+ const v = t.right + i + r.width <= o.right - 12, E = t.left - i - r.width >= o.left + 12;
40
+ a = e.placement, a === "right" && !v && E ? a = "left" : a === "left" && !E && v && (a = "right"), p = Math.max(o.left + 12, Math.min(a === "right" ? t.right + i : t.left - r.width - i, o.right - r.width - 12)), c = u(t.top + t.height / 2 - r.height / 2);
41
+ } else g < f ? t.bottom + i <= y ? (c = t.bottom + i, a = "below") : g >= o.top + 12 ? a = "above" : t.bottom + r.height + i <= o.bottom - 12 ? (c = t.bottom + i, a = "below") : t.right + r.width + i + 12 <= o.right ? (p = t.right + i, c = u(x), a = "right") : t.left - r.width - i - 12 >= o.left ? (p = t.left - r.width - i, c = u(x), a = "left") : (c = u(g), a = "edge") : c = Math.min(c, y);
42
42
  X({
43
- x: Math.max(18, Math.min(t.left + t.width / 2 - p, Math.max(18, i.width - 18))),
44
- y: Math.max(18, Math.min(t.top + t.height / 2 - c, Math.max(18, i.height - 18)))
43
+ x: Math.max(18, Math.min(t.left + t.width / 2 - p, Math.max(18, r.width - 18))),
44
+ y: Math.max(18, Math.min(t.top + t.height / 2 - c, Math.max(18, r.height - 18)))
45
45
  }), Y(a), B({
46
46
  x: Math.round(p),
47
47
  y: Math.round(c)
48
- }), v(t.right > o.left && t.left < o.right && t.bottom > o.top && t.top < o.bottom);
48
+ }), b(t.right > o.left && t.left < o.right && t.bottom > o.top && t.top < o.bottom);
49
49
  }, h = () => {
50
- m === void 0 && typeof requestAnimationFrame == "function" && (m = requestAnimationFrame(P));
50
+ d === void 0 && typeof requestAnimationFrame == "function" && (d = requestAnimationFrame(z));
51
51
  };
52
52
  return M(() => {
53
- e.anchor, e.revision, e.topOffset, e.reservedSpace, e.placement, e.align, e.gap, h();
53
+ e.anchor, e.portalScope, e.revision, e.topOffset, e.reservedSpace, e.placement, e.align, e.gap, h();
54
54
  }), M(() => {
55
55
  const n = F();
56
56
  if (!n || typeof ResizeObserver > "u") return;
57
57
  const l = new ResizeObserver(h);
58
- l.observe(n), R(() => l.disconnect());
58
+ l.observe(n), S(() => l.disconnect());
59
59
  }), U(() => k(!0)), M(() => {
60
- if (!S()) return;
61
- const n = e.anchor, l = typeof ResizeObserver == "function" ? new ResizeObserver(h) : void 0, o = L({
62
- owner: n
63
- }).boundaryHost;
60
+ if (!R()) return;
61
+ const n = e.anchor, l = typeof ResizeObserver == "function" ? new ResizeObserver(h) : void 0, o = P().boundaryHost;
64
62
  o && l?.observe(o), n && l?.observe(n);
65
63
  const t = new MutationObserver(h);
66
64
  n && t.observe(n, {
@@ -74,21 +72,24 @@ function lt(H) {
74
72
  childList: !0
75
73
  }), s !== o); )
76
74
  s = s.parentElement;
77
- const d = ot(window, h);
78
- window.addEventListener("scroll", h, !0), h(), R(() => {
79
- l?.disconnect(), t.disconnect(), d(), window.removeEventListener("scroll", h, !0);
75
+ const f = ot(window, h);
76
+ window.addEventListener("scroll", h, !0), h(), S(() => {
77
+ l?.disconnect(), t.disconnect(), f(), window.removeEventListener("scroll", h, !0);
80
78
  });
81
- }), R(() => {
82
- m !== void 0 && cancelAnimationFrame(m);
83
- }), E(Z, {
79
+ }), S(() => {
80
+ d !== void 0 && cancelAnimationFrame(d);
81
+ }), L(Z, {
84
82
  get when() {
85
- return N(() => !!S())() && e.anchor;
83
+ return N(() => !!R())() && e.anchor;
86
84
  },
87
85
  get children() {
88
- return E(tt, K($, {
86
+ return L(tt, K($, {
89
87
  get owner() {
90
88
  return e.anchor;
91
89
  },
90
+ get portalScope() {
91
+ return e.portalScope;
92
+ },
92
93
  get position() {
93
94
  return q();
94
95
  },
@@ -114,7 +115,7 @@ function lt(H) {
114
115
  },
115
116
  layerRef: (n) => {
116
117
  W(n), e.layerRef?.(n), queueMicrotask(() => _(() => {
117
- n.isConnected && (m !== void 0 && cancelAnimationFrame(m), P());
118
+ n.isConnected && (d !== void 0 && cancelAnimationFrame(d), z());
118
119
  }));
119
120
  },
120
121
  get children() {
@@ -125,5 +126,5 @@ function lt(H) {
125
126
  });
126
127
  }
127
128
  export {
128
- lt as SurfaceAnchoredLayer
129
+ ht as SurfaceAnchoredLayer
129
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.100.0",
3
+ "version": "0.101.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",