@floegence/floe-webapp-core 0.86.54 → 0.86.55

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,5 +1,5 @@
1
1
  import { type JSX } from 'solid-js';
2
- export interface SurfaceAnchoredLayerProps {
2
+ export interface SurfaceAnchoredLayerProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style' | 'ref'> {
3
3
  anchor: HTMLElement | undefined;
4
4
  /** Changes when the anchor moves through a transform; no idle polling is used. */
5
5
  revision?: unknown;
@@ -11,8 +11,14 @@ export interface SurfaceAnchoredLayerProps {
11
11
  narrowTop?: number;
12
12
  bottom: number;
13
13
  };
14
+ /** Auto places object tools above/below; side panels prefer the requested side and flip when needed. */
15
+ placement?: 'auto' | 'right' | 'left';
16
+ gap?: number;
14
17
  children: JSX.Element;
15
18
  class?: string;
19
+ style?: JSX.CSSProperties;
20
+ layerRef?: (element: HTMLDivElement) => void;
21
+ onAnchorDisconnect?: () => void;
16
22
  }
17
23
  /** Object-attached tools remain in screen pixels within the owning surface. */
18
24
  export declare function SurfaceAnchoredLayer(props: SurfaceAnchoredLayerProps): JSX.Element;
@@ -1,101 +1,128 @@
1
- import { createComponent as p, memo as k } from "solid-js/web";
2
- import { createSignal as l, createEffect as z, onCleanup as g, onMount as T, Show as V } from "solid-js";
3
- import { SurfaceFloatingLayer as $ } from "./SurfaceFloatingLayer.js";
4
- import { resolveFloatingBoundary as j } from "./surfaceFloatingBoundary.js";
5
- import { resolveSurfacePortalHost as E } from "./dialogSurfaceScope.js";
6
- function N(n) {
7
- const [O, R] = l(!1), [S, F] = l({
1
+ import { createComponent as E, mergeProps as K, memo as N } from "solid-js/web";
2
+ import { splitProps as Q, createSignal as l, createEffect as R, onCleanup as O, onMount as U, Show as X } from "solid-js";
3
+ import { SurfaceFloatingLayer as Z } from "./SurfaceFloatingLayer.js";
4
+ import { resolveFloatingBoundary as _ } from "./surfaceFloatingBoundary.js";
5
+ import { observeViewport as ee } from "../../viewport.js";
6
+ import { resolveSurfacePortalHost as L } from "./dialogSurfaceScope.js";
7
+ function se(C) {
8
+ const [o, H] = Q(C, ["anchor", "revision", "topOffset", "reservedSpace", "placement", "gap", "children", "class", "style", "layerRef", "onAnchorDisconnect"]), [P, $] = l(!1), [B, V] = l({
8
9
  x: 0,
9
10
  y: 0
10
- }), [L, A] = l("above"), [x, y] = l(!1), [C, P] = l(480), [M, B] = l();
11
- let d;
12
- const Y = () => {
13
- d = void 0;
14
- const o = n.anchor, r = M();
15
- if (!o || !r) return;
16
- const t = j(E({
17
- owner: o
11
+ }), [Y, q] = l("above"), [S, w] = l(!1), [D, W] = l(480), [z, k] = l();
12
+ let m, x = !1;
13
+ const [A, T] = l({
14
+ x: 0,
15
+ y: 0
16
+ }), [j, G] = l(0), I = () => {
17
+ m = void 0;
18
+ const n = o.anchor, h = z();
19
+ if (!n || !h) return;
20
+ if (!n.isConnected) {
21
+ w(!1), x || o.onAnchorDisconnect?.(), x = !0;
22
+ return;
23
+ }
24
+ x = !1;
25
+ const t = _(L({
26
+ owner: n
18
27
  }));
19
28
  if (!t) {
20
- y(!1);
29
+ w(!1);
21
30
  return;
22
31
  }
23
- const e = o.getBoundingClientRect(), q = Math.max(120, t.width - 24);
24
- P(q);
25
- const a = r.getBoundingClientRect(), H = (Math.max(t.left, e.left) + Math.min(t.right, e.right)) / 2;
26
- let f = Math.max(t.left + 12, Math.min(H - a.width / 2, t.right - a.width - 12));
27
- const u = e.top - (n.topOffset ?? 0), m = u - a.height - 12, h = n.reservedSpace, v = t.top + (window.matchMedia("(max-width:760px)").matches ? h?.narrowTop ?? h?.top ?? 12 : h?.top ?? 12), b = Math.max(v, t.bottom - (h?.bottom ?? 12) - a.height), w = (W) => Math.max(v, Math.min(W, b));
28
- let s = m, c = "above";
29
- m < v ? e.bottom + 12 <= b ? (s = e.bottom + 12, c = "below") : m >= t.top + 12 ? c = "above" : e.bottom + a.height + 12 <= t.bottom - 12 ? (s = e.bottom + 12, c = "below") : e.right + a.width + 24 <= t.right ? (f = e.right + 12, s = w(u), c = "right") : e.left - a.width - 24 >= t.left ? (f = e.left - a.width - 12, s = w(u), c = "left") : (s = w(m), c = "edge") : s = Math.min(s, b), A(c), F({
30
- x: Math.round(f),
32
+ const e = n.getBoundingClientRect(), f = Math.max(120, t.width - 24);
33
+ W(f);
34
+ const r = h.getBoundingClientRect(), J = (Math.max(t.left, e.left) + Math.min(t.right, e.right)) / 2;
35
+ let d = Math.max(t.left + 12, Math.min(J - r.width / 2, t.right - r.width - 12));
36
+ const y = e.top - (o.topOffset ?? 0), i = Math.max(0, o.gap ?? 12), g = y - r.height - i, p = o.reservedSpace, u = t.top + (window.matchMedia("(max-width:760px)").matches ? p?.narrowTop ?? p?.top ?? 12 : p?.top ?? 12), M = Math.max(u, t.bottom - (p?.bottom ?? 12) - r.height), b = (v) => Math.max(u, Math.min(v, M));
37
+ G(Math.max(0, t.bottom - (p?.bottom ?? 12) - u));
38
+ let s = g, a = "above";
39
+ if (o.placement === "right" || o.placement === "left") {
40
+ const v = e.right + i + r.width <= t.right - 12, F = e.left - i - r.width >= t.left + 12;
41
+ a = o.placement, a === "right" && !v && F ? a = "left" : a === "left" && !F && v && (a = "right"), d = Math.max(t.left + 12, Math.min(a === "right" ? e.right + i : e.left - r.width - i, t.right - r.width - 12)), s = b(e.top + e.height / 2 - r.height / 2);
42
+ } else g < u ? e.bottom + i <= M ? (s = e.bottom + i, a = "below") : g >= t.top + 12 ? a = "above" : e.bottom + r.height + i <= t.bottom - 12 ? (s = e.bottom + i, a = "below") : e.right + r.width + i + 12 <= t.right ? (d = e.right + i, s = b(y), a = "right") : e.left - r.width - i - 12 >= t.left ? (d = e.left - r.width - i, s = b(y), a = "left") : (s = b(g), a = "edge") : s = Math.min(s, M);
43
+ T({
44
+ x: Math.max(18, Math.min(e.left + e.width / 2 - d, Math.max(18, r.width - 18))),
45
+ y: Math.max(18, Math.min(e.top + e.height / 2 - s, Math.max(18, r.height - 18)))
46
+ }), q(a), V({
47
+ x: Math.round(d),
31
48
  y: Math.round(s)
32
- }), y(e.right > t.left && e.left < t.right && e.bottom > t.top && e.top < t.bottom);
33
- }, i = () => {
34
- d === void 0 && typeof requestAnimationFrame == "function" && (d = requestAnimationFrame(Y));
49
+ }), w(e.right > t.left && e.left < t.right && e.bottom > t.top && e.top < t.bottom);
50
+ }, c = () => {
51
+ m === void 0 && typeof requestAnimationFrame == "function" && (m = requestAnimationFrame(I));
35
52
  };
36
- return z(() => {
37
- n.anchor, n.revision, n.topOffset, n.reservedSpace, i();
38
- }), z(() => {
39
- const o = M();
40
- if (!o || typeof ResizeObserver > "u") return;
41
- const r = new ResizeObserver(i);
42
- r.observe(o), g(() => r.disconnect());
43
- }), T(() => {
44
- R(!0);
45
- const o = typeof ResizeObserver == "function" ? new ResizeObserver(i) : void 0, r = E({
46
- owner: n.anchor
53
+ return R(() => {
54
+ o.anchor, o.revision, o.topOffset, o.reservedSpace, o.placement, o.gap, c();
55
+ }), R(() => {
56
+ const n = z();
57
+ if (!n || typeof ResizeObserver > "u") return;
58
+ const h = new ResizeObserver(c);
59
+ h.observe(n), O(() => h.disconnect());
60
+ }), U(() => $(!0)), R(() => {
61
+ if (!P()) return;
62
+ const n = o.anchor, h = typeof ResizeObserver == "function" ? new ResizeObserver(c) : void 0, t = L({
63
+ owner: n
47
64
  }).boundaryHost;
48
- r && o?.observe(r);
49
- const t = new MutationObserver(i);
50
- let e = n.anchor?.parentElement;
51
- for (; e && (t.observe(e, {
65
+ t && h?.observe(t), n && h?.observe(n);
66
+ const e = new MutationObserver(c);
67
+ n && e.observe(n, {
52
68
  attributes: !0,
53
69
  attributeFilter: ["style"]
54
- }), e !== r); )
55
- e = e.parentElement;
56
- window.addEventListener("resize", i), window.addEventListener("scroll", i, !0), i(), g(() => {
57
- o?.disconnect(), t.disconnect(), window.removeEventListener("resize", i), window.removeEventListener("scroll", i, !0);
58
70
  });
59
- }), g(() => {
60
- d !== void 0 && cancelAnimationFrame(d);
61
- }), p(V, {
71
+ let f = n?.parentElement;
72
+ for (; f && (e.observe(f, {
73
+ attributes: !0,
74
+ attributeFilter: ["style"],
75
+ childList: !0
76
+ }), f !== t); )
77
+ f = f.parentElement;
78
+ const r = ee(window, c);
79
+ window.addEventListener("scroll", c, !0), c(), O(() => {
80
+ h?.disconnect(), e.disconnect(), r(), window.removeEventListener("scroll", c, !0);
81
+ });
82
+ }), O(() => {
83
+ m !== void 0 && cancelAnimationFrame(m);
84
+ }), E(X, {
62
85
  get when() {
63
- return k(() => !!O())() && n.anchor;
86
+ return N(() => !!P())() && o.anchor;
64
87
  },
65
88
  get children() {
66
- return p($, {
89
+ return E(Z, K(H, {
67
90
  get owner() {
68
- return n.anchor;
91
+ return o.anchor;
69
92
  },
70
93
  get position() {
71
- return S();
94
+ return B();
72
95
  },
73
96
  get class() {
74
- return n.class;
97
+ return o.class;
75
98
  },
76
99
  get "data-placement"() {
77
- return L();
100
+ return Y();
78
101
  },
79
102
  get inert() {
80
- return !x();
103
+ return !S();
81
104
  },
82
105
  get style() {
83
106
  return {
84
- visibility: x() ? "visible" : "hidden",
85
- "max-width": `${C()}px`,
86
- "z-index": 60
107
+ ...o.style,
108
+ "--floe-anchored-layer-anchor-x": `${A().x}px`,
109
+ "--floe-anchored-layer-anchor-y": `${A().y}px`,
110
+ "--floe-anchored-layer-max-height": `${j()}px`,
111
+ visibility: S() ? "visible" : "hidden",
112
+ "max-width": `${D()}px`,
113
+ "z-index": o.style?.["z-index"] ?? 60
87
114
  };
88
115
  },
89
- layerRef: (o) => {
90
- B(o), i();
116
+ layerRef: (n) => {
117
+ k(n), o.layerRef?.(n), c();
91
118
  },
92
119
  get children() {
93
- return n.children;
120
+ return o.children;
94
121
  }
95
- });
122
+ }));
96
123
  }
97
124
  });
98
125
  }
99
126
  export {
100
- N as SurfaceAnchoredLayer
127
+ se as SurfaceAnchoredLayer
101
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.86.54",
3
+ "version": "0.86.55",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",