react-panel-layout 0.4.2 → 0.5.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.
Files changed (76) hide show
  1. package/dist/FloatingPanelFrame-6W5OexYe.js +98 -0
  2. package/dist/FloatingPanelFrame-6W5OexYe.js.map +1 -0
  3. package/dist/FloatingPanelFrame-D9Cp2al1.cjs +2 -0
  4. package/dist/FloatingPanelFrame-D9Cp2al1.cjs.map +1 -0
  5. package/dist/GridLayout-BzrIDrC9.js +1465 -0
  6. package/dist/GridLayout-BzrIDrC9.js.map +1 -0
  7. package/dist/GridLayout-ZrOhoLLB.cjs +2 -0
  8. package/dist/GridLayout-ZrOhoLLB.cjs.map +1 -0
  9. package/dist/PanelSystemContext.d.ts +9 -0
  10. package/dist/components/grid/GridLayerList.d.ts +3 -0
  11. package/dist/components/grid/GridLayout.d.ts +5 -0
  12. package/dist/components/paneling/FloatingPanelFrame.d.ts +4 -0
  13. package/dist/components/window/FloatingWindow.d.ts +15 -0
  14. package/dist/config/panelRouter.d.ts +2 -2
  15. package/dist/config.cjs +1 -1
  16. package/dist/config.cjs.map +1 -1
  17. package/dist/config.js +1 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/constants/styles.d.ts +3 -1
  20. package/dist/floating.cjs +1 -1
  21. package/dist/floating.js +1 -1
  22. package/dist/hooks/ContentCacheContext.d.ts +59 -0
  23. package/dist/hooks/useContainerScroll.d.ts +23 -0
  24. package/dist/hooks/useContentCache.d.ts +67 -0
  25. package/dist/hooks/useDocumentScroll.d.ts +13 -0
  26. package/dist/hooks/useScrollContainer.d.ts +21 -0
  27. package/dist/index.cjs +2 -2
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.js +950 -878
  31. package/dist/index.js.map +1 -1
  32. package/dist/modules/grid/GridLayoutContext.d.ts +5 -0
  33. package/dist/modules/grid/resizeHandles.d.ts +14 -0
  34. package/dist/modules/grid/trackUtils.d.ts +29 -0
  35. package/dist/modules/grid/useGridTracks.d.ts +6 -15
  36. package/dist/modules/grid/useLayerInteractions.d.ts +2 -1
  37. package/dist/modules/window/useFloatingState.d.ts +9 -0
  38. package/dist/pivot.cjs +1 -1
  39. package/dist/pivot.js +1 -1
  40. package/dist/sticky-header/StickyHeader.d.ts +53 -0
  41. package/dist/sticky-header/index.d.ts +7 -0
  42. package/dist/sticky-header/types.d.ts +50 -0
  43. package/dist/sticky-header.cjs +2 -0
  44. package/dist/sticky-header.cjs.map +1 -0
  45. package/dist/sticky-header.js +198 -0
  46. package/dist/sticky-header.js.map +1 -0
  47. package/dist/styles-CA2_zLZt.js +52 -0
  48. package/dist/{styles-DcG3aIFx.cjs.map → styles-CA2_zLZt.js.map} +1 -1
  49. package/dist/styles-PsqGOEJP.cjs +2 -0
  50. package/dist/styles-PsqGOEJP.cjs.map +1 -0
  51. package/dist/types.d.ts +79 -4
  52. package/dist/useIsomorphicLayoutEffect-DGRNF4Lf.cjs +2 -0
  53. package/dist/useIsomorphicLayoutEffect-DGRNF4Lf.cjs.map +1 -0
  54. package/dist/useIsomorphicLayoutEffect-DhmEnmZ_.js +6 -0
  55. package/dist/useIsomorphicLayoutEffect-DhmEnmZ_.js.map +1 -0
  56. package/dist/usePivot-BS-DGfwd.cjs +2 -0
  57. package/dist/usePivot-BS-DGfwd.cjs.map +1 -0
  58. package/dist/usePivot-BvOGxLQQ.js +124 -0
  59. package/dist/usePivot-BvOGxLQQ.js.map +1 -0
  60. package/dist/utils/css.d.ts +19 -0
  61. package/package.json +6 -1
  62. package/dist/FloatingPanelFrame-SOrLGjZd.js +0 -67
  63. package/dist/FloatingPanelFrame-SOrLGjZd.js.map +0 -1
  64. package/dist/FloatingPanelFrame-XtBcHANI.cjs +0 -2
  65. package/dist/FloatingPanelFrame-XtBcHANI.cjs.map +0 -1
  66. package/dist/GridLayout-CLvW8jID.js +0 -1352
  67. package/dist/GridLayout-CLvW8jID.js.map +0 -1
  68. package/dist/GridLayout-qufTyOQM.cjs +0 -2
  69. package/dist/GridLayout-qufTyOQM.cjs.map +0 -1
  70. package/dist/styles-DcG3aIFx.cjs +0 -2
  71. package/dist/styles-w0ZixggV.js +0 -51
  72. package/dist/styles-w0ZixggV.js.map +0 -1
  73. package/dist/usePivot-C8q0pMgW.cjs +0 -2
  74. package/dist/usePivot-C8q0pMgW.cjs.map +0 -1
  75. package/dist/usePivot-z9gumDf-.js +0 -97
  76. package/dist/usePivot-z9gumDf-.js.map +0 -1
@@ -1,1352 +0,0 @@
1
- import { jsxs as G, Fragment as N, jsx as h } from "react/jsx-runtime";
2
- import * as i from "react";
3
- import { F as _t, e as $t, a as Gt, b as Ft } from "./FloatingPanelFrame-SOrLGjZd.js";
4
- import { C as Ot, D as Wt, m as Bt, n as Yt, o as Xt, p as Vt, q as Ut, r as jt, G as B, s as D, t as Zt, u as Kt, v as qt, R as ct, w as Jt, x as J } from "./styles-w0ZixggV.js";
5
- import { createPortal as Qt } from "react-dom";
6
- import { u as te, a as Rt } from "./usePivot-z9gumDf-.js";
7
- const ee = () => {
8
- const t = /* @__PURE__ */ new Map();
9
- return (e) => {
10
- if (!e)
11
- return;
12
- const n = t.get(e);
13
- if (n !== void 0)
14
- return n;
15
- const r = t.size;
16
- return t.set(e, r), r;
17
- };
18
- }, ne = ee(), Q = /* @__PURE__ */ new Map(), re = (t) => {
19
- const e = `ovs-threshold:${t.threshold}-rootMargin:${t.rootMargin}-root:${ne(t.root)}`;
20
- if (Q.has(e))
21
- return Q.get(e);
22
- const n = new class {
23
- #t = /* @__PURE__ */ new Map();
24
- #e = new IntersectionObserver((r) => {
25
- r.forEach((o) => {
26
- const s = this.#t.get(o.target);
27
- s && s(o);
28
- });
29
- }, t);
30
- observe(r, o) {
31
- return this.#t.set(r, o), this.#e.observe(r), () => {
32
- this.#t.delete(r), this.#e.unobserve(r);
33
- };
34
- }
35
- }();
36
- return Q.set(e, n), n;
37
- }, ut = Object.freeze({
38
- x: 0,
39
- y: 0,
40
- width: 0,
41
- height: 0,
42
- top: 0,
43
- right: 0,
44
- bottom: 0,
45
- left: 0
46
- });
47
- function oe(t, { threshold: e = 0, rootMargin: n = "0px", root: r = null }) {
48
- const [o, s] = i.useState(null);
49
- return i.useEffect(() => {
50
- const c = t.current;
51
- return c ? re({
52
- threshold: e,
53
- rootMargin: n,
54
- root: r
55
- }).observe(c, (a) => {
56
- s({
57
- isIntersecting: a.isIntersecting,
58
- boundingClientRect: a.boundingClientRect,
59
- intersectionRatio: a.intersectionRatio,
60
- intersectionRect: a.intersectionRect,
61
- rootBounds: a.rootBounds,
62
- target: a.target,
63
- time: a.time
64
- });
65
- }) : void 0;
66
- }, [t, e, n, r]), i.useMemo(() => ({
67
- isIntersecting: o?.isIntersecting ?? !1,
68
- boundingClientRect: o?.boundingClientRect ?? ut,
69
- intersectionRatio: o?.intersectionRatio ?? 0,
70
- intersectionRect: o?.intersectionRect ?? ut,
71
- rootBounds: o?.rootBounds ?? null,
72
- target: o?.target ?? t.current,
73
- time: o?.time ?? 0
74
- }), [o, t]);
75
- }
76
- const lt = {
77
- position: "fixed",
78
- inset: 0,
79
- background: Ot
80
- }, se = {
81
- willChange: "transform"
82
- }, dt = {
83
- left: {
84
- top: 0,
85
- bottom: 0,
86
- left: 0,
87
- transform: "translateX(-100%)"
88
- },
89
- right: {
90
- top: 0,
91
- bottom: 0,
92
- right: 0,
93
- transform: "translateX(100%)"
94
- },
95
- top: {
96
- top: 0,
97
- left: 0,
98
- right: 0,
99
- transform: "translateY(-100%)"
100
- },
101
- bottom: {
102
- bottom: 0,
103
- left: 0,
104
- right: 0,
105
- transform: "translateY(100%)"
106
- }
107
- }, ie = (t, e, n) => t === "none" ? void 0 : `transform ${e ?? Wt} ${n ?? Bt}`, ae = (t, e) => t ? e : !1, ce = {
108
- marginLeft: "auto",
109
- border: "none",
110
- background: "transparent",
111
- cursor: "pointer",
112
- fontSize: jt
113
- }, ue = ({ header: t, dismissible: e, onClose: n }) => {
114
- if (!t)
115
- return null;
116
- const r = t.showCloseButton ?? !0, o = ae(e, r);
117
- return /* @__PURE__ */ h(i.Activity, { mode: t ? "visible" : "hidden", children: /* @__PURE__ */ G(
118
- Gt,
119
- {
120
- style: { padding: `${Vt} ${Ut}`, gap: Xt },
121
- children: [
122
- /* @__PURE__ */ h(i.Activity, { mode: t ? "visible" : "hidden", children: /* @__PURE__ */ h(Ft, { children: t.title }) }),
123
- /* @__PURE__ */ h(i.Activity, { mode: o ? "visible" : "hidden", children: /* @__PURE__ */ h("button", { style: ce, onClick: n, "aria-label": "Close drawer", type: "button", children: "×" }) })
124
- ]
125
- }
126
- ) });
127
- }, le = ({ header: t, dismissible: e, onClose: n, chrome: r, children: o }) => r ? /* @__PURE__ */ G(_t, { style: { height: "100%", borderRadius: 0 }, children: [
128
- /* @__PURE__ */ h(ue, { header: t, dismissible: e, onClose: n }),
129
- /* @__PURE__ */ h(
130
- $t,
131
- {
132
- style: { padding: Yt, flex: 1, display: "flex", flexDirection: "column" },
133
- children: o
134
- }
135
- )
136
- ] }) : /* @__PURE__ */ h(N, { children: o }), de = ({
137
- id: t,
138
- config: e,
139
- isOpen: n,
140
- onClose: r,
141
- children: o,
142
- zIndex: s,
143
- width: c,
144
- height: u,
145
- position: a
146
- }) => {
147
- const {
148
- dismissible: d = !0,
149
- header: g,
150
- chrome: f = !0,
151
- inline: m = !1,
152
- transitionMode: w = "css",
153
- transitionDuration: E,
154
- transitionEasing: z
155
- } = e, L = i.useCallback((y) => y ? y.left !== void 0 ? "left" : y.right !== void 0 ? "right" : y.top !== void 0 ? "top" : y.bottom !== void 0 ? "bottom" : "right" : "right", [])(a), F = {
156
- left: "translateX(0)",
157
- right: "translateX(0)",
158
- top: "translateY(0)",
159
- bottom: "translateY(0)"
160
- }, T = i.useMemo(() => {
161
- const y = ie(w, E, z), I = {
162
- ...se,
163
- ...m ? { position: "absolute" } : { position: "fixed" },
164
- ...dt[L],
165
- transform: n ? F[L] : dt[L].transform,
166
- transition: y
167
- };
168
- return s !== void 0 && (I.zIndex = s), c !== void 0 && (I.width = typeof c == "number" ? `${c}px` : c), u !== void 0 && (I.height = typeof u == "number" ? `${u}px` : u), I;
169
- }, [u, m, n, L, E, z, w, c, s]), M = g?.title ?? e.ariaLabel ?? "Drawer", k = i.useMemo(() => {
170
- const y = m ? { ...lt, position: "absolute" } : lt, I = w === "none" ? void 0 : `opacity ${E ?? "220ms"} ease`;
171
- return {
172
- ...y,
173
- opacity: n ? 1 : 0,
174
- pointerEvents: n ? "auto" : "none",
175
- transition: I,
176
- zIndex: s !== void 0 ? s - 1 : void 0
177
- };
178
- }, [m, n, E, w, s]);
179
- return /* @__PURE__ */ G(N, { children: [
180
- /* @__PURE__ */ h("div", { style: k, onClick: d ? r : void 0 }),
181
- /* @__PURE__ */ h(
182
- "div",
183
- {
184
- "data-layer-id": t,
185
- "data-placement": L,
186
- style: T,
187
- role: "dialog",
188
- "aria-modal": d ? !0 : void 0,
189
- "aria-hidden": n ? void 0 : !0,
190
- "aria-label": M,
191
- children: /* @__PURE__ */ h(le, { header: g, dismissible: d, onClose: r, chrome: f, children: o })
192
- }
193
- )
194
- ] });
195
- }, fe = (t, e) => new Promise((n) => {
196
- let r = !1;
197
- const o = () => {
198
- r || (r = !0, t.removeEventListener("transitionend", s), n());
199
- }, s = (c) => {
200
- c.target === t && o();
201
- };
202
- t.addEventListener("transitionend", s), setTimeout(o, e + 50);
203
- }), Pt = async (t, e, n, r) => {
204
- switch (e) {
205
- case "none":
206
- t();
207
- return;
208
- case "css":
209
- t(), n && await fe(n, r);
210
- return;
211
- }
212
- }, kn = (t) => {
213
- const [e, n] = i.useState({}), r = i.useRef(t);
214
- r.current = t;
215
- const o = i.useCallback(
216
- async (a, d, g) => {
217
- const { mode: f = "none", element: m, duration: w = 300 } = g ?? {};
218
- await Pt(() => {
219
- n((P) => P[a] === d ? P : { ...P, [a]: d });
220
- }, f, m?.current, w);
221
- const z = r.current;
222
- d ? z?.onOpen?.(a) : z?.onClose?.(a), z?.onTransitionEnd?.(a, d);
223
- },
224
- []
225
- ), s = i.useCallback((a) => e[a] ?? !1, [e]), c = i.useCallback(
226
- (a, d) => o(a, !0, d),
227
- [o]
228
- ), u = i.useCallback(
229
- (a, d) => o(a, !1, d),
230
- [o]
231
- );
232
- return { state: s, open: c, close: u };
233
- }, pe = (t) => {
234
- if (!t)
235
- return 300;
236
- const e = t.match(/(\d+)/);
237
- return e ? parseInt(e[1], 10) : 300;
238
- }, ge = (t) => {
239
- const [e, n] = i.useState(() => {
240
- const a = {};
241
- return t.forEach((d) => {
242
- d.drawer && (a[d.id] = d.drawer.defaultOpen ?? !1);
243
- }), a;
244
- }), r = i.useMemo(() => {
245
- const a = /* @__PURE__ */ new Map();
246
- return t.forEach((d) => a.set(d.id, d)), a;
247
- }, [t]), o = i.useCallback(
248
- async (a, d, g) => {
249
- const f = r.get(a);
250
- if (!f?.drawer)
251
- return;
252
- const m = g?.mode ?? f.drawer.transitionMode ?? "css", w = g?.duration ?? pe(f.drawer.transitionDuration), E = g?.element?.current;
253
- await Pt(() => {
254
- f.drawer?.open === void 0 && n((P) => P[a] === d ? P : { ...P, [a]: d }), f.drawer?.onStateChange?.(d);
255
- }, m, E, w);
256
- },
257
- [r]
258
- ), s = i.useCallback(
259
- (a) => {
260
- const d = r.get(a);
261
- return d?.drawer?.open !== void 0 ? d.drawer.open : e[a] ?? !1;
262
- },
263
- [r, e]
264
- ), c = i.useCallback(
265
- (a, d) => o(a, !0, d),
266
- [o]
267
- ), u = i.useCallback(
268
- (a, d) => o(a, !1, d),
269
- [o]
270
- );
271
- return { state: s, open: c, close: u };
272
- }, he = ({ layers: t }) => {
273
- const e = ge(t), n = i.useMemo(() => t.filter((o) => o.drawer), [t]), r = i.useMemo(() => {
274
- const o = /* @__PURE__ */ new Map();
275
- return n.forEach((s) => {
276
- o.set(s.id, () => e.close(s.id));
277
- }), o;
278
- }, [n, e.close]);
279
- return /* @__PURE__ */ h(N, { children: n.map((o) => {
280
- if (!o.drawer)
281
- return null;
282
- const s = e.state(o.id), c = r.get(o.id);
283
- return c ? /* @__PURE__ */ h(
284
- de,
285
- {
286
- id: o.id,
287
- config: o.drawer,
288
- isOpen: s,
289
- onClose: c,
290
- zIndex: o.zIndex,
291
- width: o.width,
292
- height: o.height,
293
- position: o.position,
294
- children: o.component
295
- },
296
- o.id
297
- ) : null;
298
- }) });
299
- }, yt = i.createContext(null), me = ({ value: t, children: e }) => /* @__PURE__ */ h(yt.Provider, { value: t, children: e }), Lt = () => {
300
- const t = i.useContext(yt);
301
- if (!t)
302
- throw new Error("useGridLayoutContext must be used within a GridLayoutProvider.");
303
- return t;
304
- }, Mt = i.createContext(null), be = () => {
305
- const t = i.useContext(Mt);
306
- if (!t)
307
- throw new Error("usePanelSystem must be used within a PanelSystemProvider.");
308
- return t;
309
- }, we = ({ config: t, layers: e, style: n, children: r }) => {
310
- const o = i.useMemo(() => {
311
- const c = /* @__PURE__ */ new Map();
312
- return e.forEach((u) => {
313
- c.set(u.id, u);
314
- }), c;
315
- }, [e]), s = i.useMemo(
316
- () => ({
317
- config: t,
318
- style: n,
319
- layers: {
320
- defs: e,
321
- layerById: o
322
- }
323
- }),
324
- [t, n, e, o]
325
- );
326
- return /* @__PURE__ */ h(Mt.Provider, { value: s, children: r });
327
- }, Dt = i.createContext(null), Tt = ({ layerId: t, children: e }) => {
328
- const n = i.useMemo(() => ({ layerId: t }), [t]);
329
- return /* @__PURE__ */ h(Dt.Provider, { value: n, children: e });
330
- }, An = () => {
331
- const t = i.useContext(Dt);
332
- if (!t)
333
- throw new Error("useLayerInstance must be used within a LayerInstanceProvider.");
334
- return t;
335
- }, ft = (t, e, n) => {
336
- if (typeof t == "number" && Number.isFinite(t))
337
- return t;
338
- throw new Error(`Popup layer "${n}" requires a numeric "${e}" value.`);
339
- }, It = (t, e) => {
340
- if (!t)
341
- throw new Error(`Popup layer "${e}" must define position (left/top).`);
342
- return {
343
- left: ft(t.left, "left", e),
344
- top: ft(t.top, "top", e)
345
- };
346
- }, Y = (t) => `${Math.round(t)}`, _ = (t) => {
347
- if (t !== void 0)
348
- return t ? "yes" : "no";
349
- }, ve = (t, e, n, r, o) => {
350
- const s = {}, c = It(e, t);
351
- if (typeof n != "number" || typeof r != "number")
352
- throw new Error(`Popup layer "${t}" requires numeric width/height.`);
353
- s.width = Y(n), s.height = Y(r), s.left = Y(c.left), s.top = Y(c.top);
354
- const u = o?.features;
355
- if (u) {
356
- const a = _(u.toolbar), d = _(u.menubar), g = _(u.location), f = _(u.status), m = _(u.resizable), w = _(u.scrollbars);
357
- a !== void 0 && (s.toolbar = a), d !== void 0 && (s.menubar = d), g !== void 0 && (s.location = g), f !== void 0 && (s.status = f), m !== void 0 && (s.resizable = m), w !== void 0 && (s.scrollbars = w);
358
- }
359
- return Object.entries(s).map(([a, d]) => `${a}=${d}`).join(",");
360
- }, pt = (t, e, n, r, o) => {
361
- const s = It(n, e);
362
- if (typeof r != "number" || typeof o != "number")
363
- throw new Error(`Popup layer "${e}" requires numeric width/height.`);
364
- t.moveTo(Math.round(s.left), Math.round(s.top)), t.resizeTo(Math.round(r), Math.round(o));
365
- }, Ee = ({ layer: t }) => {
366
- const e = t.floating;
367
- if (!e)
368
- throw new Error(`Layer "${t.id}" is missing floating configuration required for popup mode.`);
369
- if ((e.mode ?? "embedded") !== "popup")
370
- throw new Error(`PopupLayerPortal received layer "${t.id}" that is not configured for popup mode.`);
371
- const r = i.useRef(null), o = i.useRef(null), [s, c] = i.useState(!1);
372
- return i.useEffect(() => {
373
- if (typeof window > "u")
374
- return;
375
- const u = ve(t.id, t.position, t.width, t.height, e.popup), a = e.popup?.name ?? t.id, d = Se(
376
- a,
377
- u,
378
- {
379
- position: t.position,
380
- size: { width: t.width, height: t.height }
381
- },
382
- e.popup
383
- );
384
- if (!d)
385
- throw new Error(`Failed to open popup window for layer "${t.id}".`);
386
- const g = d;
387
- o.current = g, e.popup?.focus !== !1 && g.focus(), g.document.title || (g.document.title = t.id), g.document.body.innerHTML = "";
388
- const f = g.document.createElement("div");
389
- f.dataset.layerId = t.id, g.document.body.appendChild(f), r.current = f, c(!0), pt(g, t.id, t.position, t.width, t.height);
390
- const m = () => {
391
- o.current = null, r.current = null, c(!1);
392
- };
393
- return g.addEventListener("beforeunload", m), () => {
394
- g.removeEventListener("beforeunload", m), e.popup?.closeOnUnmount !== !1 && g.close(), o.current = null, r.current = null, c(!1);
395
- };
396
- }, [
397
- e.popup?.closeOnUnmount,
398
- e.popup?.features?.location,
399
- e.popup?.features?.menubar,
400
- e.popup?.features?.resizable,
401
- e.popup?.features?.scrollbars,
402
- e.popup?.features?.status,
403
- e.popup?.features?.toolbar,
404
- e.popup?.focus,
405
- e.popup?.name,
406
- t.id
407
- ]), i.useEffect(() => {
408
- const u = o.current;
409
- u && pt(u, t.id, t.position, t.width, t.height);
410
- }, [t.position?.left, t.position?.top, t.height, t.width, t.id]), !s || !r.current ? null : Qt(/* @__PURE__ */ h(Tt, { layerId: t.id, children: t.component }), r.current);
411
- }, Se = (t, e, n, r) => {
412
- const o = r?.createWindow;
413
- return o ? o({ name: t, features: e, bounds: n }) : window.open("", t, e);
414
- }, xt = {
415
- position: "absolute",
416
- pointerEvents: "auto",
417
- boxSizing: "border-box",
418
- background: "transparent",
419
- border: "none"
420
- }, Ce = {
421
- ...xt,
422
- width: D,
423
- height: D,
424
- zIndex: 2
425
- }, ze = {
426
- ...xt,
427
- zIndex: 1
428
- }, Re = {
429
- "top-left": {
430
- top: 0,
431
- left: 0,
432
- transform: "translate(-50%, -50%)",
433
- cursor: "nwse-resize"
434
- },
435
- "top-right": {
436
- top: 0,
437
- right: 0,
438
- transform: "translate(50%, -50%)",
439
- cursor: "nesw-resize"
440
- },
441
- "bottom-left": {
442
- bottom: 0,
443
- left: 0,
444
- transform: "translate(-50%, 50%)",
445
- cursor: "nesw-resize"
446
- },
447
- "bottom-right": {
448
- bottom: 0,
449
- right: 0,
450
- transform: "translate(50%, 50%)",
451
- cursor: "nwse-resize"
452
- }
453
- }, Pe = {
454
- left: {
455
- top: D,
456
- bottom: D,
457
- left: 0,
458
- width: B,
459
- transform: "translateX(-50%)",
460
- cursor: "ew-resize"
461
- },
462
- right: {
463
- top: D,
464
- bottom: D,
465
- right: 0,
466
- width: B,
467
- transform: "translateX(50%)",
468
- cursor: "ew-resize"
469
- },
470
- top: {
471
- left: D,
472
- right: D,
473
- top: 0,
474
- height: B,
475
- transform: "translateY(-50%)",
476
- cursor: "ns-resize"
477
- },
478
- bottom: {
479
- left: D,
480
- right: D,
481
- bottom: 0,
482
- height: B,
483
- transform: "translateY(50%)",
484
- cursor: "ns-resize"
485
- }
486
- }, ye = [
487
- { key: "top-left", variant: "corner", horizontal: "left", vertical: "top" },
488
- { key: "top-right", variant: "corner", horizontal: "right", vertical: "top" },
489
- { key: "bottom-left", variant: "corner", horizontal: "left", vertical: "bottom" },
490
- { key: "bottom-right", variant: "corner", horizontal: "right", vertical: "bottom" },
491
- { key: "left", variant: "edge", horizontal: "left" },
492
- { key: "right", variant: "edge", horizontal: "right" },
493
- { key: "top", variant: "edge", vertical: "top" },
494
- { key: "bottom", variant: "edge", vertical: "bottom" }
495
- ], Le = ({ layerId: t, onPointerDown: e }) => /* @__PURE__ */ h(N, { children: ye.map((n) => {
496
- const r = n.variant === "corner" ? Ce : ze, o = n.variant === "corner" ? Re[n.key] : Pe[n.key], s = { ...r, ...o }, c = n.variant === "corner" ? { "data-resize-corner": n.key } : { "data-resize-edge": n.key };
497
- return /* @__PURE__ */ h(
498
- "div",
499
- {
500
- role: "presentation",
501
- "aria-hidden": "true",
502
- style: s,
503
- ...c,
504
- "data-layer-id": t,
505
- onPointerDown: (u) => e(n, u)
506
- },
507
- n.key
508
- );
509
- }) }), Me = ({ pivot: t }) => {
510
- const { Outlet: e } = te({
511
- items: t.items,
512
- activeId: t.activeId,
513
- defaultActiveId: t.defaultActiveId,
514
- onActiveChange: t.onActiveChange,
515
- transitionMode: t.transitionMode
516
- });
517
- return /* @__PURE__ */ h(e, {});
518
- }, kt = i.memo(({ layer: t }) => t.pivot ? /* @__PURE__ */ h(Me, { pivot: t.pivot }) : /* @__PURE__ */ h(N, { children: t.component }));
519
- kt.displayName = "LayerContent";
520
- const At = i.memo(({ layerId: t, isResizable: e, onPointerDown: n }) => e ? /* @__PURE__ */ h(Le, { layerId: t, onPointerDown: n }) : null);
521
- At.displayName = "LayerResizeHandles";
522
- const Ht = i.memo(({ layer: t, handleLayerPointerDown: e }) => {
523
- const { getLayerRenderState: n } = Lt(), { style: r, isResizable: o, isResizing: s, onResizeHandlePointerDown: c } = n(t), u = i.useMemo(() => {
524
- const d = {};
525
- return t.gridArea && (d.gridArea = t.gridArea), t.gridRow && (d.gridRow = t.gridRow), t.gridColumn && (d.gridColumn = t.gridColumn), d;
526
- }, [t.gridArea, t.gridRow, t.gridColumn]), a = i.useMemo(() => {
527
- const d = { ...r, ...u };
528
- return o ? { ...d, position: "relative" } : d;
529
- }, [r, u, o]);
530
- return /* @__PURE__ */ G(
531
- "div",
532
- {
533
- "data-layer-id": t.id,
534
- "data-draggable": !!t.floating?.draggable,
535
- "data-resizable": o,
536
- "data-resizing": s,
537
- style: a,
538
- onPointerDown: e,
539
- children: [
540
- /* @__PURE__ */ h(Tt, { layerId: t.id, children: /* @__PURE__ */ h(kt, { layer: t }) }),
541
- /* @__PURE__ */ h(At, { layerId: t.id, isResizable: o, onPointerDown: c })
542
- ]
543
- }
544
- );
545
- });
546
- Ht.displayName = "EmbeddedLayer";
547
- const De = ({ layers: t }) => {
548
- const { handleLayerPointerDown: e } = Lt();
549
- return /* @__PURE__ */ h(N, { children: t.map((n) => {
550
- const r = n.floating?.mode ?? "embedded";
551
- return n.floating && r === "popup" ? /* @__PURE__ */ h(Ee, { layer: n }, n.id) : /* @__PURE__ */ h(Ht, { layer: n, handleLayerPointerDown: e }, n.id);
552
- }) });
553
- };
554
- function $(t) {
555
- const e = i.useRef(t);
556
- return e.current = t, i.useCallback((...n) => {
557
- const r = e.current;
558
- if (r)
559
- return r(...n);
560
- }, []);
561
- }
562
- function tt(t, e) {
563
- const n = $(e.onMove), r = $(e.onUp), o = $(e.onCancel);
564
- i.useEffect(() => {
565
- if (t)
566
- return e.onMove && document.addEventListener("pointermove", n, { passive: !1 }), e.onUp && document.addEventListener("pointerup", r), e.onCancel && document.addEventListener("pointercancel", o), () => {
567
- e.onMove && document.removeEventListener("pointermove", n), e.onUp && document.removeEventListener("pointerup", r), e.onCancel && document.removeEventListener("pointercancel", o);
568
- };
569
- }, [t, e.onMove, e.onUp, e.onCancel, n, r, o]);
570
- }
571
- function Te(t, e, n) {
572
- i.useEffect(() => {
573
- const r = t.current;
574
- if (!(!e || !r || n === void 0))
575
- return r.setPointerCapture(n), () => {
576
- r.hasPointerCapture && r.hasPointerCapture(n) && r.releasePointerCapture(n);
577
- };
578
- }, [t, e, n]);
579
- }
580
- function Ie(t, e, n = ["pointerdown", "pointermove", "pointerup"]) {
581
- i.useEffect(() => {
582
- const r = t.current;
583
- if (!e || !r)
584
- return;
585
- const o = (s) => {
586
- s.preventDefault();
587
- };
588
- return n.forEach((s) => {
589
- r.addEventListener(s, o, { passive: !1 });
590
- }), () => {
591
- n.forEach((s) => {
592
- r.removeEventListener(s, o);
593
- });
594
- };
595
- }, [t, e, n]);
596
- }
597
- function xe(t, e, n) {
598
- const { onMove: r, onUp: o, onCancel: s, pointerId: c, capturePointer: u = !0, preventDefaults: a = !0 } = n;
599
- tt(e, { onMove: r, onUp: o, onCancel: s }), Te(t, e ? u : !1, c), Ie(t, e ? a : !1);
600
- }
601
- const ke = (t) => {
602
- const e = i.useRef(null), n = i.useRef(null), r = i.useRef(0), [o, s] = i.useState(!1), c = $((f) => {
603
- t.onResize?.(f);
604
- }), u = i.useCallback(
605
- (f) => t.axis === "x" ? f.clientX : f.clientY,
606
- [t.axis]
607
- ), a = i.useCallback(
608
- (f) => {
609
- f.preventDefault(), e.current = f.currentTarget, n.current = f.pointerId, r.current = u(f), s(!0);
610
- },
611
- [u]
612
- ), d = i.useCallback(
613
- (f) => {
614
- const m = u(f), w = m - r.current;
615
- w !== 0 && (r.current = m, c(w));
616
- },
617
- [u, c]
618
- ), g = i.useCallback(() => {
619
- s(!1), n.current = null;
620
- }, []);
621
- return xe(e, o, {
622
- onMove: d,
623
- onUp: g,
624
- pointerId: n.current ?? void 0,
625
- capturePointer: !0,
626
- preventDefaults: !1
627
- }), {
628
- ref: e,
629
- onPointerDown: a,
630
- isDragging: o
631
- };
632
- }, Ae = ({
633
- element: t,
634
- component: e
635
- }) => i.forwardRef(({ children: n, ...r }, o) => t ? i.cloneElement(
636
- t,
637
- { ...r, ref: o },
638
- n ?? t.props.children
639
- ) : e ? /* @__PURE__ */ h(e, { ...r, ref: o, children: n }) : /* @__PURE__ */ h("div", { ...r, ref: o, children: n }));
640
- function He({
641
- element: t,
642
- component: e
643
- }) {
644
- return i.useMemo(
645
- () => Ae({
646
- element: t,
647
- component: e
648
- }),
649
- [e, t]
650
- );
651
- }
652
- const Ne = {
653
- position: "absolute",
654
- zIndex: Jt
655
- }, _e = {
656
- vertical: {
657
- width: ct,
658
- height: "100%",
659
- top: 0,
660
- cursor: "col-resize"
661
- },
662
- horizontal: {
663
- width: "100%",
664
- height: ct,
665
- left: 0,
666
- cursor: "row-resize"
667
- }
668
- }, $e = {
669
- idle: qt,
670
- hovered: Kt,
671
- dragging: Zt
672
- }, Ge = ({
673
- direction: t,
674
- onResize: e,
675
- component: n,
676
- element: r,
677
- children: o
678
- }) => {
679
- const s = t === "vertical" ? "x" : "y", { ref: c, isDragging: u, onPointerDown: a } = ke({ axis: s, onResize: e }), [d, g] = i.useState(!1), f = i.useCallback(() => {
680
- g(!0);
681
- }, []), m = i.useCallback(() => {
682
- g(!1);
683
- }, []), w = He({
684
- element: r,
685
- component: n
686
- }), E = i.useMemo(() => u ? "dragging" : d ? "hovered" : "idle", [u, d]), z = i.useMemo(() => ({
687
- ...Ne,
688
- ..._e[t],
689
- backgroundColor: $e[E],
690
- touchAction: "none"
691
- }), [t, E]);
692
- return /* @__PURE__ */ h(
693
- w,
694
- {
695
- ref: c,
696
- style: z,
697
- role: "separator",
698
- "aria-orientation": t,
699
- "aria-hidden": void 0,
700
- "data-resize-handle": "true",
701
- "data-direction": t,
702
- "data-is-dragging": u ? "true" : void 0,
703
- onPointerDown: a,
704
- onPointerEnter: f,
705
- onPointerLeave: m,
706
- children: o
707
- }
708
- );
709
- }, gt = {
710
- position: "absolute",
711
- pointerEvents: "auto"
712
- }, ht = ({
713
- direction: t,
714
- trackIndex: e,
715
- align: n,
716
- gap: r,
717
- span: o,
718
- onResize: s
719
- }) => {
720
- const c = t === "col" ? "vertical" : "horizontal", u = i.useCallback(
721
- (g) => {
722
- const f = n === "start" ? -g : g;
723
- s(t, e, f);
724
- },
725
- [n, t, e, s]
726
- ), a = i.useMemo(() => t === "col" ? {
727
- gridColumn: `${e + 1} / ${e + 2}`,
728
- gridRow: `${o.start} / ${o.end}`
729
- } : {
730
- gridRow: `${e + 1} / ${e + 2}`,
731
- gridColumn: `${o.start} / ${o.end}`
732
- }, [t, e, o]), d = i.useMemo(() => {
733
- const f = Math.max(0, r) / 2 + J / 2;
734
- return t === "col" ? {
735
- ...gt,
736
- width: J,
737
- height: "100%",
738
- top: 0,
739
- bottom: 0,
740
- ...n === "start" ? { left: -f } : { right: -f }
741
- } : {
742
- ...gt,
743
- width: "100%",
744
- height: J,
745
- left: 0,
746
- right: 0,
747
- ...n === "start" ? { top: -f } : { bottom: -f }
748
- };
749
- }, [n, t, r]);
750
- return /* @__PURE__ */ h("div", { "data-resizable": "true", style: { ...a, position: "relative", pointerEvents: "none" }, children: /* @__PURE__ */ h("div", { "data-direction": c, "data-align": n, "data-handle": "true", style: d, children: /* @__PURE__ */ h(Ge, { direction: c, onResize: u }) }) });
751
- }, Fe = (t) => {
752
- const e = /* @__PURE__ */ new Map();
753
- t.forEach((r, o) => {
754
- r.forEach((s, c) => {
755
- if (!s || s === ".")
756
- return;
757
- const u = e.get(s);
758
- if (u) {
759
- const d = {
760
- rowStart: Math.min(u.rowStart, o),
761
- rowEnd: Math.max(u.rowEnd, o),
762
- colStart: Math.min(u.colStart, c),
763
- colEnd: Math.max(u.colEnd, c)
764
- };
765
- e.set(s, d);
766
- return;
767
- }
768
- const a = {
769
- rowStart: o,
770
- rowEnd: o,
771
- colStart: c,
772
- colEnd: c
773
- };
774
- e.set(s, a);
775
- });
776
- });
777
- const n = /* @__PURE__ */ new Map();
778
- return e.forEach((r, o) => {
779
- const s = r.rowStart + 1, c = r.rowEnd + 2, u = r.colStart + 1, a = r.colEnd + 2, d = {
780
- gridArea: o,
781
- gridRow: `${s} / ${c}`,
782
- gridColumn: `${u} / ${a}`
783
- };
784
- n.set(o, d);
785
- }), n;
786
- }, Oe = (t, e) => {
787
- if ((t.positionMode ?? "grid") !== "grid")
788
- return t;
789
- const r = t.gridArea ?? t.id, o = e.get(r);
790
- if (!o)
791
- return t;
792
- const s = !t.gridArea, c = !t.gridRow, u = !t.gridColumn;
793
- return !s && !c && !u ? t : {
794
- ...t,
795
- gridArea: s ? o.gridArea : t.gridArea,
796
- gridRow: c ? o.gridRow : t.gridRow,
797
- gridColumn: u ? o.gridColumn : t.gridColumn
798
- };
799
- }, We = (t, e) => {
800
- const n = i.useMemo(() => Fe(t.areas), [t.areas]), r = i.useMemo(() => e.map((u) => Oe(u, n)), [e, n]), o = i.useMemo(
801
- () => r.filter((u) => u.visible !== !1),
802
- [r]
803
- ), s = i.useMemo(
804
- () => o.filter((u) => !u.drawer),
805
- [o]
806
- ), c = i.useMemo(() => {
807
- const u = /* @__PURE__ */ new Map();
808
- return r.forEach((a) => {
809
- u.set(a.id, a);
810
- }), u;
811
- }, [r]);
812
- return {
813
- normalizedLayers: r,
814
- visibleLayers: o,
815
- regularLayers: s,
816
- layerById: c
817
- };
818
- }, j = (t, e) => `${t}-${e}`, Be = (t, e, n, r) => {
819
- const o = j(n, r), s = e[o];
820
- return s !== void 0 ? `${s}px` : t.size;
821
- }, mt = (t, e, n) => t.map((r, o) => Be(r, e, n, o)).join(" "), X = (t, e) => t.reduce((n, r, o) => (r.resizable && r.size.endsWith("px") && (n[j(e, o)] = parseInt(r.size, 10)), n), {}), Ye = (t, e, n) => {
822
- const r = e !== void 0 ? Math.max(t, e) : t;
823
- return n !== void 0 ? Math.min(r, n) : r;
824
- }, Xe = (t, e, n) => {
825
- const r = t + e;
826
- return Ye(r, n.minSize, n.maxSize);
827
- }, Ve = (t, e, n, r, o) => {
828
- const s = j(t, e);
829
- return (c) => {
830
- const u = Xe(n, r, o);
831
- return { ...c, [s]: u };
832
- };
833
- }, bt = (t, e) => {
834
- const n = t.length, r = [];
835
- for (let c = 0; c < n; c++) {
836
- const u = t[c], a = u[e], d = u[e + 1];
837
- a !== d && r.push(c);
838
- }
839
- if (r.length === 0)
840
- return { start: 1, end: n + 1 };
841
- const o = Math.min(...r), s = Math.max(...r);
842
- return { start: o + 1, end: s + 2 };
843
- }, wt = (t, e) => {
844
- const n = t[e], r = t[e + 1], o = n?.length ?? 0, s = [];
845
- for (let a = 0; a < o; a++) {
846
- const d = n?.[a], g = r?.[a];
847
- d !== g && s.push(a);
848
- }
849
- if (s.length === 0)
850
- return { start: 1, end: o + 1 };
851
- const c = Math.min(...s), u = Math.max(...s);
852
- return { start: c + 1, end: u + 2 };
853
- }, Ue = (t, e) => {
854
- if (t.length === 0)
855
- return [];
856
- const n = e.length;
857
- if (t.length === 1)
858
- return t[0]?.resizable ? [{ trackIndex: 0, align: "end", span: { start: 1, end: n + 1 } }] : [];
859
- const r = [];
860
- return Array.from({ length: t.length - 1 }, (s, c) => c).forEach((s) => {
861
- const c = t[s];
862
- if (t[s + 1]?.resizable) {
863
- const a = bt(e, s);
864
- r.push({ trackIndex: s + 1, align: "start", span: a });
865
- return;
866
- }
867
- if (c?.resizable) {
868
- const a = bt(e, s);
869
- r.push({ trackIndex: s, align: "end", span: a });
870
- }
871
- }), r;
872
- }, je = (t, e) => {
873
- if (t.length === 0)
874
- return [];
875
- const n = e[0]?.length ?? 0;
876
- if (t.length === 1)
877
- return t[0]?.resizable ? [{ trackIndex: 0, align: "end", span: { start: 1, end: n + 1 } }] : [];
878
- const r = [];
879
- return Array.from({ length: t.length - 1 }, (s, c) => c).forEach((s) => {
880
- const c = t[s];
881
- if (t[s + 1]?.resizable) {
882
- const a = wt(e, s);
883
- r.push({ trackIndex: s + 1, align: "start", span: a });
884
- return;
885
- }
886
- if (c?.resizable) {
887
- const a = wt(e, s);
888
- r.push({ trackIndex: s, align: "end", span: a });
889
- }
890
- }), r;
891
- }, Ze = (t) => {
892
- if (!t)
893
- return { rowGap: 0, columnGap: 0 };
894
- const e = t.split(/\s+/).map((r) => r.trim()).filter(Boolean), n = (r) => {
895
- const o = r.match(/^(-?\d+(?:\.\d+)?)px$/);
896
- return o ? Number.parseFloat(o[1]) : 0;
897
- };
898
- if (e.length === 1) {
899
- const r = n(e[0]);
900
- return { rowGap: r, columnGap: r };
901
- }
902
- return {
903
- rowGap: n(e[0]),
904
- columnGap: n(e[1])
905
- };
906
- }, Ke = (t) => t !== void 0 ? { gap: t } : {}, qe = (t, e, n, r) => {
907
- const o = j(n, r), s = t[o];
908
- return s !== void 0 ? s : e.size.endsWith("px") ? Number.parseInt(e.size, 10) : 300;
909
- }, Je = (t, e) => {
910
- const [n, r] = i.useState(() => ({
911
- ...X(t.columns, "col"),
912
- ...X(t.rows, "row")
913
- }));
914
- Rt(() => {
915
- const g = {
916
- ...X(t.columns, "col"),
917
- ...X(t.rows, "row")
918
- };
919
- r((f) => {
920
- const m = /* @__PURE__ */ new Set([...Object.keys(f), ...Object.keys(g)]);
921
- return Array.from(m).some((E) => f[E] !== g[E]) ? g : f;
922
- });
923
- }, [t.columns, t.rows]);
924
- const o = i.useMemo(() => t.areas.map((g) => `"${g.join(" ")}"`).join(" "), [t.areas]), s = i.useMemo(() => Ze(t.gap), [t.gap]), c = i.useMemo(
925
- () => Ue(t.columns, t.areas),
926
- [t.columns, t.areas]
927
- ), u = i.useMemo(
928
- () => je(t.rows, t.areas),
929
- [t.rows, t.areas]
930
- ), a = i.useMemo(() => ({
931
- ...t.style,
932
- ...e,
933
- gridTemplateAreas: o,
934
- gridTemplateRows: mt(t.rows, n, "row"),
935
- gridTemplateColumns: mt(t.columns, n, "col"),
936
- ...Ke(t.gap)
937
- }), [o, t.columns, t.gap, t.rows, t.style, e, n]), d = i.useCallback(
938
- (g, f, m) => {
939
- const E = (g === "row" ? t.rows : t.columns)[f];
940
- if (!E || !E.resizable)
941
- return;
942
- const z = qe(n, E, g, f);
943
- r(Ve(g, f, z, m, E));
944
- },
945
- [t.columns, t.rows, n]
946
- );
947
- return {
948
- columnHandles: c,
949
- rowHandles: u,
950
- gapSizes: s,
951
- gridStyle: a,
952
- handleResize: d
953
- };
954
- }, Qe = (t, e = Number.NEGATIVE_INFINITY, n = Number.POSITIVE_INFINITY) => Math.min(Math.max(t, e), n), Hn = (t, e) => typeof t != "number" || !Number.isFinite(t) ? e : t, tn = (t) => t.positionMode ? t.positionMode : t.floating ? (t.floating.mode ?? "embedded") === "embedded" ? "absolute" : "relative" : "grid", en = (t) => ({ position: t === "grid" ? "relative" : t }), nn = (t, e) => e !== "grid" ? {} : {
955
- gridArea: t.gridArea,
956
- gridRow: t.gridRow,
957
- gridColumn: t.gridColumn
958
- }, rn = (t) => t ? {
959
- top: t.top,
960
- right: t.right,
961
- bottom: t.bottom,
962
- left: t.left
963
- } : {}, on = (t) => t !== void 0 ? { zIndex: t } : {}, sn = (t, e) => ({
964
- width: t,
965
- height: e
966
- }), an = (t, e) => t.pointerEvents !== void 0 ? typeof t.pointerEvents == "boolean" ? { pointerEvents: t.pointerEvents ? "auto" : "none" } : { pointerEvents: t.pointerEvents } : e === "absolute" || e === "fixed" ? { pointerEvents: "auto" } : {}, cn = (t) => t.position, un = (t) => ({
967
- width: t.width,
968
- height: t.height
969
- }), ln = (t) => t.zIndex, dn = (t) => {
970
- const e = tn(t), n = cn(t), r = un(t), o = ln(t);
971
- return {
972
- ...t.style,
973
- ...en(e),
974
- ...nn(t, e),
975
- ...rn(n),
976
- ...on(o),
977
- ...sn(r.width, r.height),
978
- ...an(t, e)
979
- };
980
- }, fn = (t) => {
981
- const e = t.floating;
982
- return e ? e.mode ?? "embedded" : null;
983
- }, H = (t) => fn(t) !== "embedded" ? null : t.floating ?? null, vt = (t) => t instanceof HTMLElement ? ["INPUT", "TEXTAREA", "SELECT", "BUTTON"].includes(t.tagName) : !1, Et = (t, e, n) => {
984
- const r = e ?? Number.NEGATIVE_INFINITY, o = n ?? Number.POSITIVE_INFINITY;
985
- return Qe(t, r, o);
986
- }, St = (t, e, n) => {
987
- if (typeof t == "number" && Number.isFinite(t))
988
- return t;
989
- throw new Error(
990
- `Floating layer "${n}" must provide a numeric "${e}" value when draggable mode is enabled.`
991
- );
992
- }, Ct = (t) => {
993
- if (!H(t))
994
- throw new Error(`Floating layer "${t.id}" is missing floating configuration required for dragging.`);
995
- const n = t.position;
996
- if (!n)
997
- throw new Error(`Floating layer "${t.id}" must define position with left and top values.`);
998
- return {
999
- left: St(n.left, "left", t.id),
1000
- top: St(n.top, "top", t.id)
1001
- };
1002
- }, pn = (t) => {
1003
- const e = H(t);
1004
- return e ? e.constraints ?? {} : {};
1005
- }, gn = (t, e, n) => t ? t === "left" ? e - n : e + n : e, hn = (t, e, n) => t ? t === "top" ? e - n : e + n : e, mn = (t, e, n) => !t || t === "right" ? e : e + n, bn = (t, e, n) => !t || t === "bottom" ? e : e + n, et = (t, e) => t ? t.dataset.layerId === e ? t : et(t.parentElement, e) : null, nt = (t, e, n) => !t || n?.(t) ? null : e(t) ? t : nt(t.parentElement, e, n), wn = (t) => t instanceof HTMLElement ? nt(
1006
- t,
1007
- (e) => e.dataset.dragHandle === "true",
1008
- (e) => e.dataset.dragIgnore === "true"
1009
- ) : null, zt = (t) => t instanceof HTMLElement ? nt(
1010
- t,
1011
- (e) => e.dataset.resizeCorner !== void 0 || e.dataset.resizeEdge !== void 0
1012
- ) !== null : !1, V = (t) => {
1013
- const e = H(t);
1014
- return e ? e.resizable === !0 : !1;
1015
- }, U = (t) => {
1016
- if (!H(t))
1017
- return null;
1018
- const n = Sn(t);
1019
- if (!n)
1020
- throw new Error(`Floating layer "${t.id}" must define width and height when resizable or draggable.`);
1021
- return {
1022
- width: n.width,
1023
- height: n.height
1024
- };
1025
- }, vn = (t, e, n) => {
1026
- const r = t.filter(V).reduce((f, m) => {
1027
- if (n === m.id) {
1028
- const E = e[m.id];
1029
- if (E)
1030
- return f[m.id] = E, f;
1031
- }
1032
- const w = U(m);
1033
- return w && (f[m.id] = w), f;
1034
- }, {}), o = Object.keys(e), s = Object.keys(r), c = o.length !== s.length, u = o.some((f) => !Object.prototype.hasOwnProperty.call(r, f)), a = c ? !0 : u, d = s.some((f) => {
1035
- const m = e[f], w = r[f];
1036
- return !m || !w ? !0 : m.width !== w.width || m.height !== w.height;
1037
- });
1038
- return {
1039
- sizes: r,
1040
- changed: a ? !0 : d
1041
- };
1042
- }, En = ({
1043
- layers: t,
1044
- layerById: e
1045
- }) => {
1046
- const [n, r] = i.useState(null), [o, s] = i.useState(null), [c, u] = i.useState({}), [a, d] = i.useState({}), g = i.useRef(null), f = i.useRef(null), m = $((p, l) => {
1047
- e.get(p)?.floating?.onMove?.(l);
1048
- }), w = $((p, l) => {
1049
- e.get(p)?.floating?.onResize?.(l);
1050
- });
1051
- Rt(() => {
1052
- const { sizes: p, changed: l } = vn(t, a, o);
1053
- l && d(p);
1054
- }, [t, o]);
1055
- const E = i.useCallback(
1056
- (p, l, b, v) => {
1057
- const S = Ct(l), R = c[p] ?? { x: 0, y: 0 }, C = {
1058
- pointerStartX: v.clientX,
1059
- pointerStartY: v.clientY,
1060
- initialTranslationX: R.x,
1061
- initialTranslationY: R.y,
1062
- baseLeft: S.left,
1063
- baseTop: S.top,
1064
- layerId: p,
1065
- pointerId: v.pointerId,
1066
- target: b
1067
- };
1068
- if (C.target.setPointerCapture)
1069
- try {
1070
- C.target.setPointerCapture(C.pointerId);
1071
- } catch {
1072
- }
1073
- g.current = C, r(p);
1074
- },
1075
- [c]
1076
- ), z = i.useCallback(
1077
- (p) => {
1078
- const l = p.target, b = wn(l);
1079
- if (!b)
1080
- return;
1081
- const v = b.closest("[data-layer-id]")?.getAttribute("data-layer-id");
1082
- if (!v)
1083
- return;
1084
- const S = e.get(v);
1085
- if (!S)
1086
- return;
1087
- const R = H(S);
1088
- if (!(!R || R.draggable !== !0) && !vt(p.target) && !zt(p.target) && b) {
1089
- const C = et(b, v);
1090
- if (!C)
1091
- return;
1092
- E(v, S, C, p);
1093
- return;
1094
- }
1095
- },
1096
- [E, e]
1097
- ), P = i.useCallback(
1098
- (p, l) => {
1099
- const b = e.get(p), v = b ? H(b) : null;
1100
- if (!b || !v || v.draggable !== !0 || vt(l.target) || zt(l.target))
1101
- return;
1102
- const S = et(l.currentTarget, p);
1103
- S && E(p, b, S, l);
1104
- },
1105
- [E, e]
1106
- ), L = i.useCallback(
1107
- (p, l, b) => {
1108
- const v = e.get(p);
1109
- if (!v || !V(v))
1110
- return;
1111
- const S = a[p] ?? U(v);
1112
- if (!S)
1113
- return;
1114
- const R = Ct(v), C = pn(v), x = c[p] ?? { x: 0, y: 0 };
1115
- if (b.stopPropagation(), b.preventDefault(), b.currentTarget.setPointerCapture)
1116
- try {
1117
- b.currentTarget.setPointerCapture(b.pointerId);
1118
- } catch {
1119
- }
1120
- f.current = {
1121
- layerId: p,
1122
- pointerId: b.pointerId,
1123
- horizontalEdge: l.horizontal,
1124
- verticalEdge: l.vertical,
1125
- startX: b.clientX,
1126
- startY: b.clientY,
1127
- startWidth: S.width,
1128
- startHeight: S.height,
1129
- startPosition: x,
1130
- baseLeft: R.left,
1131
- baseTop: R.top,
1132
- minWidth: C.minWidth,
1133
- maxWidth: C.maxWidth,
1134
- minHeight: C.minHeight,
1135
- maxHeight: C.maxHeight,
1136
- target: b.currentTarget
1137
- }, s(p);
1138
- },
1139
- [e, c, a]
1140
- ), F = i.useCallback(
1141
- (p) => {
1142
- const l = g.current;
1143
- if (!l)
1144
- return;
1145
- const b = p.clientX - l.pointerStartX, v = p.clientY - l.pointerStartY, S = {
1146
- x: l.initialTranslationX + b,
1147
- y: l.initialTranslationY + v
1148
- };
1149
- u((R) => ({ ...R, [l.layerId]: S })), m(l.layerId, {
1150
- left: l.baseLeft + S.x,
1151
- top: l.baseTop + S.y
1152
- });
1153
- },
1154
- [m]
1155
- ), T = i.useCallback(
1156
- (p) => {
1157
- const l = f.current;
1158
- if (!l || l.pointerId !== p.pointerId || !e.get(l.layerId))
1159
- return;
1160
- const v = p.clientX - l.startX, S = p.clientY - l.startY, R = gn(l.horizontalEdge, l.startWidth, v), C = hn(l.verticalEdge, l.startHeight, S), x = Et(R, l.minWidth, l.maxWidth), A = Et(C, l.minHeight, l.maxHeight), O = l.startWidth - x, Z = l.startHeight - A, st = mn(
1161
- l.horizontalEdge,
1162
- l.startPosition.x,
1163
- O
1164
- ), Nt = bn(l.verticalEdge, l.startPosition.y, Z), K = a[l.layerId], it = { width: x, height: A };
1165
- (!K || K.width !== x || K.height !== A) && (d((q) => ({
1166
- ...q,
1167
- [l.layerId]: it
1168
- })), w(l.layerId, it));
1169
- const at = c[l.layerId] ?? { x: 0, y: 0 }, W = { x: st, y: Nt };
1170
- (at.x !== W.x || at.y !== W.y) && (u((q) => ({
1171
- ...q,
1172
- [l.layerId]: W
1173
- })), m(l.layerId, {
1174
- left: l.baseLeft + W.x,
1175
- top: l.baseTop + W.y
1176
- }));
1177
- },
1178
- [e, c, a, m, w]
1179
- ), M = i.useCallback((p) => {
1180
- const l = g.current;
1181
- if (l) {
1182
- if (l.pointerId === p.pointerId && l.target.releasePointerCapture)
1183
- try {
1184
- l.target.releasePointerCapture(l.pointerId);
1185
- } catch {
1186
- }
1187
- g.current = null;
1188
- }
1189
- r(null);
1190
- }, []), k = i.useCallback((p) => {
1191
- const l = f.current;
1192
- if (l) {
1193
- if (l.pointerId === p.pointerId && l.target.releasePointerCapture)
1194
- try {
1195
- l.target.releasePointerCapture(l.pointerId);
1196
- } catch {
1197
- }
1198
- f.current = null;
1199
- }
1200
- s(null);
1201
- }, []);
1202
- tt(n !== null, {
1203
- onMove: F,
1204
- onUp: M,
1205
- onCancel: M
1206
- }), tt(o !== null, {
1207
- onMove: T,
1208
- onUp: k,
1209
- onCancel: k
1210
- });
1211
- const y = i.useCallback(
1212
- (p) => {
1213
- const l = dn(p), b = H(p);
1214
- if (!b || b.draggable !== !0)
1215
- return l;
1216
- const v = c[p.id], S = n === p.id, R = o === p.id, C = v ? { transform: `translate(${v.x}px, ${v.y}px)` } : {}, x = a[p.id], A = V(p) ? U(p) : null, O = x ?? A, Z = O ? { width: `${O.width}px`, height: `${O.height}px` } : {};
1217
- return {
1218
- ...l,
1219
- ...Z,
1220
- ...C,
1221
- ...S || R ? { cursor: "grabbing" } : {}
1222
- };
1223
- },
1224
- [n, c, a, o]
1225
- ), I = i.useCallback(
1226
- (p) => {
1227
- if (!V(p))
1228
- return { isResizable: !1 };
1229
- const b = a[p.id], v = U(p);
1230
- return (b ?? v) !== null ? { isResizable: !0, onPointerDown: (x, A) => {
1231
- L(p.id, x, A);
1232
- } } : { isResizable: !1 };
1233
- },
1234
- [L, a]
1235
- ), rt = i.useCallback(
1236
- (p) => {
1237
- const { isResizable: l, onPointerDown: b } = I(p), v = y(p), S = o === p.id;
1238
- return {
1239
- style: v,
1240
- isResizable: l,
1241
- isResizing: S,
1242
- onResizeHandlePointerDown: (R, C) => {
1243
- b && b(R, C);
1244
- }
1245
- };
1246
- },
1247
- [y, I, o]
1248
- ), ot = i.useCallback(
1249
- (p) => ({
1250
- "data-drag-handle": "true",
1251
- role: "button",
1252
- "aria-roledescription": "Drag handle",
1253
- "aria-label": "Drag layer",
1254
- onPointerDown: (l) => {
1255
- P(p, l);
1256
- }
1257
- }),
1258
- [P]
1259
- );
1260
- return {
1261
- providerValue: i.useMemo(
1262
- () => ({
1263
- handleLayerPointerDown: z,
1264
- getLayerRenderState: rt,
1265
- getLayerHandleProps: ot
1266
- }),
1267
- [ot, rt, z]
1268
- ),
1269
- draggingLayerId: n,
1270
- resizingLayerId: o
1271
- };
1272
- }, Sn = (t) => {
1273
- if (typeof t.width == "number" && typeof t.height == "number")
1274
- return { width: t.width, height: t.height };
1275
- }, Cn = {
1276
- display: "grid",
1277
- width: "100%",
1278
- height: "100%"
1279
- }, zn = {
1280
- touchAction: "none",
1281
- WebkitTouchCallout: "none",
1282
- WebkitUserSelect: "none",
1283
- userSelect: "none"
1284
- }, Nn = ({ config: t, layers: e, style: n }) => {
1285
- const r = i.useRef(null), { isIntersecting: o } = oe(r, { threshold: 0 });
1286
- return /* @__PURE__ */ h(we, { config: t, layers: e, style: n, children: /* @__PURE__ */ h(Rn, { gridRef: r, isIntersecting: o }) });
1287
- }, Rn = ({ gridRef: t, isIntersecting: e }) => {
1288
- const { config: n, style: r, layers: o } = be(), { normalizedLayers: s, visibleLayers: c, regularLayers: u, layerById: a } = We(n, o.defs), { columnHandles: d, rowHandles: g, gapSizes: f, gridStyle: m, handleResize: w } = Je(n, r), { providerValue: E, draggingLayerId: z, resizingLayerId: P } = En({
1289
- layers: s,
1290
- layerById: a
1291
- }), L = z ? !0 : !!P, F = i.useMemo(() => ({
1292
- ...Cn,
1293
- ...m,
1294
- ...L ? zn : {}
1295
- }), [m, L]);
1296
- return /* @__PURE__ */ G(N, { children: [
1297
- /* @__PURE__ */ G(
1298
- "div",
1299
- {
1300
- ref: t,
1301
- style: F,
1302
- "data-dragging": !!z,
1303
- "data-resizing": !!P,
1304
- "data-visible": e,
1305
- children: [
1306
- /* @__PURE__ */ h(me, { value: E, children: /* @__PURE__ */ h(De, { layers: u }) }),
1307
- d.map(({ trackIndex: T, align: M, span: k }) => /* @__PURE__ */ h(
1308
- ht,
1309
- {
1310
- direction: "col",
1311
- trackIndex: T,
1312
- align: M,
1313
- gap: f.columnGap,
1314
- span: k,
1315
- onResize: w
1316
- },
1317
- `col-${T}:${M}`
1318
- )),
1319
- g.map(({ trackIndex: T, align: M, span: k }) => /* @__PURE__ */ h(
1320
- ht,
1321
- {
1322
- direction: "row",
1323
- trackIndex: T,
1324
- align: M,
1325
- gap: f.rowGap,
1326
- span: k,
1327
- onResize: w
1328
- },
1329
- `row-${T}:${M}`
1330
- ))
1331
- ]
1332
- }
1333
- ),
1334
- /* @__PURE__ */ h(he, { layers: c })
1335
- ] });
1336
- };
1337
- export {
1338
- de as D,
1339
- Nn as G,
1340
- Ge as R,
1341
- An as a,
1342
- Lt as b,
1343
- $ as c,
1344
- He as d,
1345
- Qe as e,
1346
- he as f,
1347
- kn as g,
1348
- Pt as r,
1349
- Hn as t,
1350
- ke as u
1351
- };
1352
- //# sourceMappingURL=GridLayout-CLvW8jID.js.map