react-resizable-panels 4.0.0-alpha.1 → 4.0.0-alpha.2

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,21 +1,74 @@
1
1
  "use client";
2
- import { jsx as F } from "react/jsx-runtime";
3
- import { useId as Pe, useLayoutEffect as Ee, useEffect as Ce, useRef as I, useCallback as fe, createContext as Me, useImperativeHandle as de, useState as M, useMemo as pe, useSyncExternalStore as Ge, useContext as Ie } from "react";
4
- function Oe(e, t) {
2
+ import { jsx as j } from "react/jsx-runtime";
3
+ import { useId as De, useLayoutEffect as Te, useEffect as Ae, useRef as D, useCallback as ge, createContext as $e, useImperativeHandle as Se, useState as R, useMemo as xe, useSyncExternalStore as Ne, useContext as _e } from "react";
4
+ function re(e, t) {
5
+ return t.sort(
6
+ e === "horizontal" ? Fe : He
7
+ );
8
+ }
9
+ function Fe(e, t) {
10
+ const n = e.element.offsetLeft - t.element.offsetLeft;
11
+ return n !== 0 ? n : e.element.offsetWidth - t.element.offsetWidth;
12
+ }
13
+ function He(e, t) {
14
+ const n = e.element.offsetTop - t.element.offsetTop;
15
+ return n !== 0 ? n : e.element.offsetHeight - t.element.offsetHeight;
16
+ }
17
+ function ze(e) {
18
+ const { element: t, orientation: n, panels: o, separators: s } = e, i = re(
19
+ n,
20
+ Array.from(t.children).filter((c) => c instanceof HTMLElement).map((c) => ({ element: c }))
21
+ ).map(({ element: c }) => c), a = [];
22
+ let r, l;
23
+ for (const c of i) {
24
+ const u = o.find(
25
+ (f) => f.element === c
26
+ );
27
+ if (u) {
28
+ if (r) {
29
+ const f = r.element.getBoundingClientRect(), m = c.getBoundingClientRect();
30
+ a.push({
31
+ group: e,
32
+ panels: [r, u],
33
+ separator: l,
34
+ rect: n === "horizontal" ? new DOMRect(
35
+ f.right,
36
+ m.top,
37
+ m.left - f.right,
38
+ m.height
39
+ ) : new DOMRect(
40
+ m.left,
41
+ f.bottom,
42
+ m.width,
43
+ m.top - f.bottom
44
+ )
45
+ });
46
+ }
47
+ r = u, l = void 0;
48
+ } else {
49
+ const f = s.find(
50
+ (m) => m.element === c
51
+ );
52
+ f ? l = f : (r = void 0, l = void 0);
53
+ }
54
+ }
55
+ return a;
56
+ }
57
+ function je(e, t) {
5
58
  const n = getComputedStyle(e), o = parseFloat(n.fontSize);
6
59
  return t * o;
7
60
  }
8
- function ke(e, t) {
61
+ function We(e, t) {
9
62
  const n = getComputedStyle(e.ownerDocument.body), o = parseFloat(n.fontSize);
10
63
  return t * o;
11
64
  }
12
- function Ae(e) {
65
+ function Ue(e) {
13
66
  return e / 100 * window.innerHeight;
14
67
  }
15
- function Ne(e) {
68
+ function Be(e) {
16
69
  return e / 100 * window.innerWidth;
17
70
  }
18
- function $e(e) {
71
+ function Ke(e) {
19
72
  switch (typeof e) {
20
73
  case "number":
21
74
  return [e, "px"];
@@ -25,13 +78,13 @@ function $e(e) {
25
78
  }
26
79
  }
27
80
  }
28
- function j({
81
+ function Y({
29
82
  groupSize: e,
30
83
  panelElement: t,
31
84
  styleProp: n
32
85
  }) {
33
86
  let o;
34
- const [s, i] = $e(n);
87
+ const [s, i] = Ke(n);
35
88
  switch (i) {
36
89
  case "%": {
37
90
  o = s / 100 * e;
@@ -42,72 +95,72 @@ function j({
42
95
  break;
43
96
  }
44
97
  case "rem": {
45
- o = ke(t, s);
98
+ o = We(t, s);
46
99
  break;
47
100
  }
48
101
  case "em": {
49
- o = Oe(t, s);
102
+ o = je(t, s);
50
103
  break;
51
104
  }
52
105
  case "vh": {
53
- o = Ae(s);
106
+ o = Ue(s);
54
107
  break;
55
108
  }
56
109
  case "vw": {
57
- o = Ne(s);
110
+ o = Be(s);
58
111
  break;
59
112
  }
60
113
  }
61
114
  return o;
62
115
  }
63
- function L(e) {
116
+ function C(e) {
64
117
  return parseFloat(e.toFixed(3));
65
118
  }
66
- function Q({
119
+ function le({
67
120
  group: e
68
121
  }) {
69
122
  const { orientation: t, panels: n } = e;
70
123
  return n.reduce((o, s) => (o += t === "horizontal" ? s.element.offsetWidth : s.element.offsetHeight, o), 0);
71
124
  }
72
- function ae(e) {
73
- const { panels: t } = e, n = Q({ group: e });
125
+ function pe(e) {
126
+ const { panels: t } = e, n = le({ group: e });
74
127
  return t.map((o) => {
75
128
  const { element: s, panelConstraints: i } = o;
76
129
  let a = 0;
77
130
  if (i.collapsedSize) {
78
- const u = j({
131
+ const u = Y({
79
132
  groupSize: n,
80
133
  panelElement: s,
81
134
  styleProp: i.collapsedSize
82
135
  });
83
- a = L(u / n * 100);
136
+ a = C(u / n * 100);
84
137
  }
85
138
  let r;
86
139
  if (i.defaultSize) {
87
- const u = j({
140
+ const u = Y({
88
141
  groupSize: n,
89
142
  panelElement: s,
90
143
  styleProp: i.defaultSize
91
144
  });
92
- r = L(u / n * 100);
145
+ r = C(u / n * 100);
93
146
  }
94
147
  let l = 0;
95
148
  if (i.minSize) {
96
- const u = j({
149
+ const u = Y({
97
150
  groupSize: n,
98
151
  panelElement: s,
99
152
  styleProp: i.minSize
100
153
  });
101
- l = L(u / n * 100);
154
+ l = C(u / n * 100);
102
155
  }
103
156
  let c = 100;
104
157
  if (i.maxSize) {
105
- const u = j({
158
+ const u = Y({
106
159
  groupSize: n,
107
160
  panelElement: s,
108
161
  styleProp: i.maxSize
109
162
  });
110
- c = L(u / n * 100);
163
+ c = C(u / n * 100);
111
164
  }
112
165
  return {
113
166
  collapsedSize: a,
@@ -119,7 +172,11 @@ function ae(e) {
119
172
  };
120
173
  });
121
174
  }
122
- class De {
175
+ function S(e, t = "Assertion error") {
176
+ if (!e)
177
+ throw console.error(t), Error(t);
178
+ }
179
+ class Ve {
123
180
  #e = {};
124
181
  addListener(t, n) {
125
182
  const o = this.#e[t];
@@ -158,83 +215,403 @@ class De {
158
215
  }
159
216
  }
160
217
  }
161
- let E = {
218
+ function L(e, t, n = 0) {
219
+ return Math.abs(C(e) - C(t)) <= n;
220
+ }
221
+ let P = {
162
222
  cursorFlags: 0,
163
223
  interactionState: {
164
224
  state: "inactive"
165
225
  },
166
226
  mountedGroups: /* @__PURE__ */ new Map()
167
227
  };
168
- const T = new De();
169
- function O() {
170
- return E;
228
+ const A = new Ve();
229
+ function k() {
230
+ return P;
171
231
  }
172
- function G(e) {
173
- const t = typeof e == "function" ? e(E) : e;
174
- return E === t || (E = {
175
- ...E,
232
+ function M(e) {
233
+ const t = typeof e == "function" ? e(P) : e;
234
+ if (P === t)
235
+ return P;
236
+ const n = P;
237
+ return P = {
238
+ ...P,
176
239
  ...t
177
- }, t.cursorFlags !== void 0 && T.emit("cursorFlagsChange", E.cursorFlags), t.interactionState !== void 0 && T.emit("interactionStateChange", E.interactionState), t.mountedGroups !== void 0 && T.emit("mountedGroupsChange", E.mountedGroups)), E;
240
+ }, t.cursorFlags !== void 0 && A.emit("cursorFlagsChange", P.cursorFlags), t.interactionState !== void 0 && A.emit("interactionStateChange", P.interactionState), t.mountedGroups !== void 0 && (P.mountedGroups.forEach((o, s) => {
241
+ o.derivedPanelConstraints.forEach((i) => {
242
+ if (i.collapsible) {
243
+ const { layout: a } = n.mountedGroups.get(s) ?? {};
244
+ if (a) {
245
+ const r = L(
246
+ i.collapsedSize,
247
+ o.layout[i.panelId]
248
+ ), l = L(
249
+ i.collapsedSize,
250
+ a[i.panelId]
251
+ );
252
+ r && !l && (s.inMemoryLastExpandedPanelSizes[i.panelId] = a[i.panelId]);
253
+ }
254
+ }
255
+ });
256
+ }), A.emit("mountedGroupsChange", P.mountedGroups)), P;
178
257
  }
179
- const Te = (e) => e, V = () => {
180
- }, he = 1, me = 2, ve = 4, ge = 8, le = {
181
- coarse: 10,
182
- precise: 5
183
- };
184
- function X(e, t) {
185
- return t.sort(
186
- e === "horizontal" ? _e : Fe
187
- );
258
+ function Xe(e, t) {
259
+ if (e.length !== t.length)
260
+ return !1;
261
+ for (let n = 0; n < e.length; n++)
262
+ if (e[n] != t[n])
263
+ return !1;
264
+ return !0;
188
265
  }
189
- function _e(e, t) {
190
- const n = e.element.offsetLeft - t.element.offsetLeft;
191
- return n !== 0 ? n : e.element.offsetWidth - t.element.offsetWidth;
266
+ function W(e, t) {
267
+ return L(e, t) ? 0 : e > t ? 1 : -1;
192
268
  }
193
- function Fe(e, t) {
194
- const n = e.element.offsetTop - t.element.offsetTop;
195
- return n !== 0 ? n : e.element.offsetHeight - t.element.offsetHeight;
269
+ function _({
270
+ panelConstraints: e,
271
+ size: t
272
+ }) {
273
+ const {
274
+ collapsedSize: n = 0,
275
+ collapsible: o,
276
+ maxSize: s = 100,
277
+ minSize: i = 0
278
+ } = e;
279
+ if (W(t, i) < 0)
280
+ if (o) {
281
+ const a = (n + i) / 2;
282
+ W(t, a) < 0 ? t = n : t = i;
283
+ } else
284
+ t = i;
285
+ return t = Math.min(s, t), t = C(t), t;
196
286
  }
197
- function He(e) {
198
- const { element: t, orientation: n, panels: o, separators: s } = e, i = X(
199
- n,
200
- Array.from(t.children).filter((c) => c instanceof HTMLElement).map((c) => ({ element: c }))
201
- ).map(({ element: c }) => c), a = [];
202
- let r, l;
203
- for (const c of i) {
204
- const u = o.find(
205
- (d) => d.element === c
287
+ function Q({
288
+ delta: e,
289
+ initialLayout: t,
290
+ panelConstraints: n,
291
+ pivotIndices: o,
292
+ prevLayout: s,
293
+ trigger: i
294
+ }) {
295
+ if (L(e, 0))
296
+ return t;
297
+ const a = Object.values(t), r = Object.values(s), l = [...a], [c, u] = o;
298
+ S(c != null, "Invalid first pivot index"), S(u != null, "Invalid second pivot index");
299
+ let f = 0;
300
+ if (i === "keyboard") {
301
+ {
302
+ const p = e < 0 ? u : c, d = n[p];
303
+ S(
304
+ d,
305
+ `Panel constraints not found for index ${p}`
306
+ );
307
+ const {
308
+ collapsedSize: h = 0,
309
+ collapsible: v,
310
+ minSize: z = 0
311
+ } = d;
312
+ if (v) {
313
+ const x = a[p];
314
+ if (S(
315
+ x != null,
316
+ `Previous layout not found for panel index ${p}`
317
+ ), L(x, h)) {
318
+ const y = z - x;
319
+ W(y, Math.abs(e)) > 0 && (e = e < 0 ? 0 - y : y);
320
+ }
321
+ }
322
+ }
323
+ {
324
+ const p = e < 0 ? c : u, d = n[p];
325
+ S(
326
+ d,
327
+ `No panel constraints found for index ${p}`
328
+ );
329
+ const {
330
+ collapsedSize: h = 0,
331
+ collapsible: v,
332
+ minSize: z = 0
333
+ } = d;
334
+ if (v) {
335
+ const x = a[p];
336
+ if (S(
337
+ x != null,
338
+ `Previous layout not found for panel index ${p}`
339
+ ), L(x, z)) {
340
+ const y = x - h;
341
+ W(y, Math.abs(e)) > 0 && (e = e < 0 ? 0 - y : y);
342
+ }
343
+ }
344
+ }
345
+ }
346
+ {
347
+ const p = e < 0 ? 1 : -1;
348
+ let d = e < 0 ? u : c, h = 0;
349
+ for (; ; ) {
350
+ const z = a[d];
351
+ S(
352
+ z != null,
353
+ `Previous layout not found for panel index ${d}`
354
+ );
355
+ const y = _({
356
+ panelConstraints: n[d],
357
+ size: 100
358
+ }) - z;
359
+ if (h += y, d += p, d < 0 || d >= n.length)
360
+ break;
361
+ }
362
+ const v = Math.min(Math.abs(e), Math.abs(h));
363
+ e = e < 0 ? 0 - v : v;
364
+ }
365
+ {
366
+ let d = e < 0 ? c : u;
367
+ for (; d >= 0 && d < n.length; ) {
368
+ const h = Math.abs(e) - Math.abs(f), v = a[d];
369
+ S(
370
+ v != null,
371
+ `Previous layout not found for panel index ${d}`
372
+ );
373
+ const z = v - h, x = _({
374
+ panelConstraints: n[d],
375
+ size: z
376
+ });
377
+ if (!L(v, x) && (f += v - x, l[d] = x, f.toFixed(3).localeCompare(Math.abs(e).toFixed(3), void 0, {
378
+ numeric: !0
379
+ }) >= 0))
380
+ break;
381
+ e < 0 ? d-- : d++;
382
+ }
383
+ }
384
+ if (Xe(r, l))
385
+ return s;
386
+ {
387
+ const p = e < 0 ? u : c, d = a[p];
388
+ S(
389
+ d != null,
390
+ `Previous layout not found for panel index ${p}`
206
391
  );
207
- if (u) {
208
- if (r) {
209
- const d = r.element.getBoundingClientRect(), p = c.getBoundingClientRect();
210
- a.push({
211
- group: e,
212
- panels: [r, u],
213
- separator: l,
214
- rect: n === "horizontal" ? new DOMRect(
215
- d.right,
216
- p.top,
217
- p.left - d.right,
218
- p.height
219
- ) : new DOMRect(
220
- p.left,
221
- d.bottom,
222
- p.width,
223
- p.top - d.bottom
224
- )
392
+ const h = d + f, v = _({
393
+ panelConstraints: n[p],
394
+ size: h
395
+ });
396
+ if (l[p] = v, !L(v, h)) {
397
+ let z = h - v, y = e < 0 ? u : c;
398
+ for (; y >= 0 && y < n.length; ) {
399
+ const w = l[y];
400
+ S(
401
+ w != null,
402
+ `Previous layout not found for panel index ${y}`
403
+ );
404
+ const G = w + z, O = _({
405
+ panelConstraints: n[y],
406
+ size: G
225
407
  });
408
+ if (L(w, O) || (z -= O - w, l[y] = O), L(z, 0))
409
+ break;
410
+ e > 0 ? y-- : y++;
226
411
  }
227
- r = u, l = void 0;
228
- } else {
229
- const d = s.find(
230
- (p) => p.element === c
231
- );
232
- d ? l = d : (r = void 0, l = void 0);
233
412
  }
234
413
  }
235
- return a;
414
+ const m = Object.values(l).reduce(
415
+ (p, d) => d + p,
416
+ 0
417
+ );
418
+ if (!L(m, 100, 0.1))
419
+ return s;
420
+ const g = Object.keys(s);
421
+ return l.reduce((p, d, h) => (p[g[h]] = d, p), {});
236
422
  }
237
- function je(e, t) {
423
+ function J(e) {
424
+ const t = e.parentElement;
425
+ S(t, "Parent group element not found");
426
+ const { mountedGroups: n } = k();
427
+ for (const [o] of n)
428
+ if (o.element === t)
429
+ return o;
430
+ throw Error("Could not find parent Group for separator element");
431
+ }
432
+ function ee(e, t) {
433
+ if (Object.keys(e).length !== Object.keys(t).length)
434
+ return !1;
435
+ for (const n in e)
436
+ if (W(e[n], t[n]) !== 0)
437
+ return !1;
438
+ return !0;
439
+ }
440
+ function F({
441
+ layout: e,
442
+ panelConstraints: t
443
+ }) {
444
+ const o = [...Object.values(e)], s = o.reduce(
445
+ (r, l) => r + l,
446
+ 0
447
+ );
448
+ if (o.length !== t.length)
449
+ throw Error(
450
+ `Invalid ${t.length} panel layout: ${o.map((r) => `${r}%`).join(", ")}`
451
+ );
452
+ if (!L(s, 100) && o.length > 0)
453
+ for (let r = 0; r < t.length; r++) {
454
+ const l = o[r];
455
+ S(l != null, `No layout data found for index ${r}`);
456
+ const c = 100 / s * l;
457
+ o[r] = c;
458
+ }
459
+ let i = 0;
460
+ for (let r = 0; r < t.length; r++) {
461
+ const l = o[r];
462
+ S(l != null, `No layout data found for index ${r}`);
463
+ const c = _({
464
+ panelConstraints: t[r],
465
+ size: l
466
+ });
467
+ l != c && (i += l - c, o[r] = c);
468
+ }
469
+ if (!L(i, 0))
470
+ for (let r = 0; r < t.length; r++) {
471
+ const l = o[r];
472
+ S(l != null, `No layout data found for index ${r}`);
473
+ const c = l + i, u = _({
474
+ panelConstraints: t[r],
475
+ size: c
476
+ });
477
+ if (l !== u && (i -= u - l, o[r] = u, L(i, 0)))
478
+ break;
479
+ }
480
+ const a = Object.keys(e);
481
+ return o.reduce((r, l, c) => (r[a[c]] = l, r), {});
482
+ }
483
+ function be({
484
+ groupId: e
485
+ }) {
486
+ const t = () => {
487
+ const { mountedGroups: n } = k();
488
+ for (const [o, s] of n)
489
+ if (o.id === e)
490
+ return { group: o, ...s };
491
+ throw Error(`Group ${e} not found`);
492
+ };
493
+ return {
494
+ getLayout() {
495
+ const { layout: n } = t();
496
+ return n;
497
+ },
498
+ setLayout(n) {
499
+ const {
500
+ derivedPanelConstraints: o,
501
+ group: s,
502
+ layout: i,
503
+ separatorToPanels: a
504
+ } = t(), r = F({
505
+ layout: n,
506
+ panelConstraints: o
507
+ });
508
+ return ee(i, r) || M((l) => ({
509
+ mountedGroups: new Map(l.mountedGroups).set(s, {
510
+ derivedPanelConstraints: o,
511
+ layout: r,
512
+ separatorToPanels: a
513
+ })
514
+ })), r;
515
+ }
516
+ };
517
+ }
518
+ function we(e) {
519
+ const { mountedGroups: t } = k(), n = t.get(e);
520
+ return S(n, `Mounted Group ${e.id} not found`), n;
521
+ }
522
+ function T(e, t) {
523
+ const n = J(e), o = we(n), s = n.separators.find(
524
+ (f) => f.element === e
525
+ );
526
+ S(s, "Matching separator not found");
527
+ const i = o.separatorToPanels.get(s);
528
+ S(i, "Matching panels not found");
529
+ const a = i.map((f) => n.panels.indexOf(f)), l = be({ groupId: n.id }).getLayout(), c = Q({
530
+ delta: t,
531
+ initialLayout: l,
532
+ panelConstraints: o.derivedPanelConstraints,
533
+ pivotIndices: a,
534
+ prevLayout: l,
535
+ trigger: "keyboard"
536
+ }), u = F({
537
+ layout: c,
538
+ panelConstraints: o.derivedPanelConstraints
539
+ });
540
+ ee(l, u) || M((f) => ({
541
+ mountedGroups: new Map(f.mountedGroups).set(n, {
542
+ derivedPanelConstraints: o.derivedPanelConstraints,
543
+ layout: u,
544
+ separatorToPanels: o.separatorToPanels
545
+ })
546
+ }));
547
+ }
548
+ function me(e) {
549
+ if (e.defaultPrevented)
550
+ return;
551
+ const t = e.currentTarget, n = J(t);
552
+ if (!n.disabled)
553
+ switch (e.key) {
554
+ case "ArrowDown": {
555
+ e.preventDefault(), n.orientation === "vertical" && T(t, 5);
556
+ break;
557
+ }
558
+ case "ArrowLeft": {
559
+ e.preventDefault(), n.orientation === "horizontal" && T(t, -5);
560
+ break;
561
+ }
562
+ case "ArrowRight": {
563
+ e.preventDefault(), n.orientation === "horizontal" && T(t, 5);
564
+ break;
565
+ }
566
+ case "ArrowUp": {
567
+ e.preventDefault(), n.orientation === "vertical" && T(t, -5);
568
+ break;
569
+ }
570
+ case "End": {
571
+ e.preventDefault(), T(t, 100);
572
+ break;
573
+ }
574
+ case "Enter": {
575
+ e.preventDefault();
576
+ const o = J(t), { derivedPanelConstraints: s, layout: i, separatorToPanels: a } = we(o), r = o.separators.find(
577
+ (f) => f.element === t
578
+ );
579
+ S(r, "Matching separator not found");
580
+ const l = a.get(r);
581
+ S(l, "Matching panels not found");
582
+ const c = l[0], u = s.find(
583
+ (f) => f.panelId === c.id
584
+ );
585
+ if (S(u, "Panel metadata not found"), u.collapsible) {
586
+ const f = i[c.id], m = u.collapsedSize === f ? o.inMemoryLastExpandedPanelSizes[c.id] ?? u.minSize : u.collapsedSize;
587
+ T(t, m - f);
588
+ }
589
+ break;
590
+ }
591
+ case "F6": {
592
+ e.preventDefault();
593
+ const s = J(t).separators.map(
594
+ (l) => l.element
595
+ ), i = Array.from(s).findIndex(
596
+ (l) => l === e.currentTarget
597
+ );
598
+ S(i !== null, "Index not found");
599
+ const a = e.shiftKey ? i > 0 ? i - 1 : s.length - 1 : i + 1 < s.length ? i + 1 : 0;
600
+ s[a].focus();
601
+ break;
602
+ }
603
+ case "Home": {
604
+ e.preventDefault(), T(t, -100);
605
+ break;
606
+ }
607
+ }
608
+ }
609
+ const Ye = (e) => e, oe = () => {
610
+ }, Le = 1, Pe = 2, Ee = 4, Re = 8, he = {
611
+ coarse: 10,
612
+ precise: 5
613
+ };
614
+ function Ze(e, t) {
238
615
  return {
239
616
  x: e.x >= t.left && e.x <= t.right ? 0 : Math.min(
240
617
  Math.abs(e.x - t.left),
@@ -246,13 +623,13 @@ function je(e, t) {
246
623
  )
247
624
  };
248
625
  }
249
- function We(e, t, n) {
626
+ function qe(e, t, n) {
250
627
  let o, s = {
251
628
  x: 1 / 0,
252
629
  y: 1 / 0
253
630
  };
254
631
  for (const i of t) {
255
- const a = je(n, i.rect);
632
+ const a = Ze(n, i.rect);
256
633
  switch (e) {
257
634
  case "horizontal": {
258
635
  a.x <= s.x && (o = i, s = a);
@@ -269,33 +646,33 @@ function We(e, t, n) {
269
646
  hitRegion: o
270
647
  } : void 0;
271
648
  }
272
- let W;
273
- function Ue() {
274
- return W === void 0 && (typeof matchMedia == "function" ? W = !!matchMedia("(pointer:coarse)").matches : W = !1), W;
649
+ let Z;
650
+ function Je() {
651
+ return Z === void 0 && (typeof matchMedia == "function" ? Z = !!matchMedia("(pointer:coarse)").matches : Z = !1), Z;
275
652
  }
276
- function ye(e, t) {
653
+ function Ce(e, t) {
277
654
  const n = [];
278
655
  return t.forEach((o, s) => {
279
656
  if (s.disabled)
280
657
  return;
281
- const i = Ue() ? le.coarse : le.precise, a = He(s), r = We(s.orientation, a, {
658
+ const i = Je() ? he.coarse : he.precise, a = ze(s), r = qe(s.orientation, a, {
282
659
  x: e.clientX,
283
660
  y: e.clientY
284
661
  });
285
662
  r && r.distance.x <= i && r.distance.y <= i && n.push(r.hitRegion);
286
663
  }), n;
287
664
  }
288
- function ce(e) {
665
+ function ve(e) {
289
666
  if (e.defaultPrevented)
290
667
  return;
291
- const { mountedGroups: t } = O(), n = ye(e, t), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
668
+ const { mountedGroups: t } = k(), n = Ce(e, t), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
292
669
  n.forEach((r) => {
293
670
  o.add(r.group), r.panels.forEach((c) => {
294
671
  s.add(c);
295
672
  }), r.separator && i.add(r.separator);
296
673
  const l = t.get(r.group);
297
674
  l && a.set(r.group, l.layout);
298
- }), G({
675
+ }), M({
299
676
  interactionState: {
300
677
  hitRegions: n,
301
678
  initialLayoutMap: a,
@@ -304,7 +681,7 @@ function ce(e) {
304
681
  }
305
682
  }), n.length && e.preventDefault();
306
683
  }
307
- function Be({
684
+ function Qe({
308
685
  cursorFlags: e,
309
686
  groups: t,
310
687
  state: n
@@ -331,7 +708,7 @@ function Be({
331
708
  return null;
332
709
  switch (n) {
333
710
  case "active": {
334
- const i = (e & he) !== 0, a = (e & me) !== 0, r = (e & ve) !== 0, l = (e & ge) !== 0;
711
+ const i = (e & Le) !== 0, a = (e & Pe) !== 0, r = (e & Ee) !== 0, l = (e & Re) !== 0;
335
712
  if (e) {
336
713
  if (i)
337
714
  return r ? "se-resize" : l ? "ne-resize" : "e-resize";
@@ -347,174 +724,40 @@ function Be({
347
724
  }
348
725
  return o > 0 && s > 0 ? "move" : o > 0 ? "ew-resize" : "ns-resize";
349
726
  }
350
- let K = null, P;
351
- function Y() {
352
- P === void 0 && (P = new CSSStyleSheet(), document.adoptedStyleSheets = [P]);
353
- const { cursorFlags: e, interactionState: t } = O();
727
+ let ie = null, I;
728
+ function se() {
729
+ I === void 0 && (I = new CSSStyleSheet(), document.adoptedStyleSheets = [I]);
730
+ const { cursorFlags: e, interactionState: t } = k();
354
731
  switch (t.state) {
355
732
  case "active":
356
733
  case "hover": {
357
- const n = Be({
734
+ const n = Qe({
358
735
  cursorFlags: e,
359
736
  groups: t.hitRegions.map((o) => o.group),
360
737
  state: t.state
361
738
  });
362
- if (K === n)
739
+ if (ie === n)
363
740
  return;
364
- K = n, n ? P.cssRules.length === 0 ? P.insertRule(`*{cursor: ${n} !important;}`) : P.replaceSync(`*{cursor: ${n} !important;}`) : P.cssRules.length === 1 && P.deleteRule(0);
741
+ ie = n, n ? I.cssRules.length === 0 ? I.insertRule(`*{cursor: ${n} !important;}`) : I.replaceSync(`*{cursor: ${n} !important;}`) : I.cssRules.length === 1 && I.deleteRule(0);
365
742
  break;
366
743
  }
367
744
  case "inactive": {
368
- K = null, P.cssRules.length === 1 && P.deleteRule(0);
745
+ ie = null, I.cssRules.length === 1 && I.deleteRule(0);
369
746
  break;
370
747
  }
371
748
  }
372
749
  }
373
- function C(e, t = "Assertion error") {
374
- if (!e)
375
- throw console.error(t), Error(t);
376
- }
377
- function Ve(e, t) {
378
- if (e.length !== t.length)
379
- return !1;
380
- for (let n = 0; n < e.length; n++)
381
- if (e[n] != t[n])
382
- return !1;
383
- return !0;
384
- }
385
- function w(e, t, n = 0) {
386
- return Math.abs(L(e) - L(t)) <= n;
387
- }
388
- function Z(e, t) {
389
- return w(e, t) ? 0 : e > t ? 1 : -1;
390
- }
391
- function D({
392
- panelConstraints: e,
393
- size: t
394
- }) {
395
- const {
396
- collapsedSize: n = 0,
397
- collapsible: o,
398
- maxSize: s = 100,
399
- minSize: i = 0
400
- } = e;
401
- if (Z(t, i) < 0)
402
- if (o) {
403
- const a = (n + i) / 2;
404
- Z(t, a) < 0 ? t = n : t = i;
405
- } else
406
- t = i;
407
- return t = Math.min(s, t), t = L(t), t;
408
- }
409
- function Ke({
410
- delta: e,
411
- initialLayout: t,
412
- panelConstraints: n,
413
- pivotIndices: o,
414
- prevLayout: s,
415
- trigger: i
416
- }) {
417
- if (w(e, 0))
418
- return t;
419
- const a = Object.values(t), r = Object.values(s), l = [...a], [c, u] = o;
420
- C(c != null, "Invalid first pivot index"), C(u != null, "Invalid second pivot index");
421
- let d = 0;
422
- {
423
- const h = e < 0 ? 1 : -1;
424
- let f = e < 0 ? u : c, v = 0;
425
- for (; ; ) {
426
- const x = a[f];
427
- C(
428
- x != null,
429
- `Previous layout not found for panel index ${f}`
430
- );
431
- const S = D({
432
- panelConstraints: n[f],
433
- size: 100
434
- }) - x;
435
- if (v += S, f += h, f < 0 || f >= n.length)
436
- break;
437
- }
438
- const g = Math.min(Math.abs(e), Math.abs(v));
439
- e = e < 0 ? 0 - g : g;
440
- }
441
- {
442
- let f = e < 0 ? c : u;
443
- for (; f >= 0 && f < n.length; ) {
444
- const v = Math.abs(e) - Math.abs(d), g = a[f];
445
- C(
446
- g != null,
447
- `Previous layout not found for panel index ${f}`
448
- );
449
- const x = g - v, z = D({
450
- panelConstraints: n[f],
451
- size: x
452
- });
453
- if (!w(g, z) && (d += g - z, l[f] = z, d.toFixed(3).localeCompare(Math.abs(e).toFixed(3), void 0, {
454
- numeric: !0
455
- }) >= 0))
456
- break;
457
- e < 0 ? f-- : f++;
458
- }
459
- }
460
- if (Ve(r, l))
461
- return s;
462
- {
463
- const h = e < 0 ? u : c, f = a[h];
464
- C(
465
- f != null,
466
- `Previous layout not found for panel index ${h}`
467
- );
468
- const v = f + d, g = D({
469
- panelConstraints: n[h],
470
- size: v
471
- });
472
- if (l[h] = g, !w(g, v)) {
473
- let x = v - g, S = e < 0 ? u : c;
474
- for (; S >= 0 && S < n.length; ) {
475
- const R = l[S];
476
- C(
477
- R != null,
478
- `Previous layout not found for panel index ${S}`
479
- );
480
- const k = R + x, A = D({
481
- panelConstraints: n[S],
482
- size: k
483
- });
484
- if (w(R, A) || (x -= A - R, l[S] = A), w(x, 0))
485
- break;
486
- e > 0 ? S-- : S++;
487
- }
488
- }
489
- }
490
- const p = Object.values(l).reduce(
491
- (h, f) => f + h,
492
- 0
493
- );
494
- if (!w(p, 100, 0.1))
495
- return s;
496
- const m = Object.keys(s);
497
- return l.reduce((h, f, v) => (h[m[v]] = f, h), {});
498
- }
499
- function ee(e, t) {
500
- if (Object.keys(e).length !== Object.keys(t).length)
501
- return !1;
502
- for (const n in e)
503
- if (Z(e[n], t[n]) !== 0)
504
- return !1;
505
- return !0;
506
- }
507
- function U(e) {
750
+ function q(e) {
508
751
  if (e.defaultPrevented)
509
752
  return;
510
- const { interactionState: t, mountedGroups: n } = O();
753
+ const { interactionState: t, mountedGroups: n } = k();
511
754
  switch (t.state) {
512
755
  case "active": {
513
756
  if (
514
757
  // Skip this check for "pointerleave" events, else Firefox triggers a false positive (see #514)
515
758
  e.type !== "pointerleave" && e.buttons === 0
516
759
  ) {
517
- G(
760
+ M(
518
761
  (i) => i.interactionState.state === "inactive" ? i : {
519
762
  cursorFlags: 0,
520
763
  interactionState: {
@@ -530,103 +773,108 @@ function U(e) {
530
773
  const { disableCursor: a, element: r, orientation: l, panels: c } = i.group;
531
774
  let u = 0;
532
775
  t.state === "active" && (l === "horizontal" ? u = (e.clientX - t.pointerDownAtPoint.x) / r.offsetWidth * 100 : u = (e.clientY - t.pointerDownAtPoint.y) / r.offsetHeight * 100);
533
- const d = t.initialLayoutMap.get(
776
+ const f = t.initialLayoutMap.get(
534
777
  i.group
535
- ), { derivedPanelConstraints: p, layout: m } = n.get(i.group) ?? {};
536
- if (p && d && m) {
537
- const h = Ke({
778
+ ), {
779
+ derivedPanelConstraints: m,
780
+ layout: g,
781
+ separatorToPanels: p
782
+ } = n.get(i.group) ?? {};
783
+ if (m && f && g && p) {
784
+ const d = Q({
538
785
  delta: u,
539
- initialLayout: d,
540
- panelConstraints: p,
541
- pivotIndices: i.panels.map((f) => c.indexOf(f)),
542
- prevLayout: m,
786
+ initialLayout: f,
787
+ panelConstraints: m,
788
+ pivotIndices: i.panels.map((h) => c.indexOf(h)),
789
+ prevLayout: g,
543
790
  trigger: "mouse-or-touch"
544
791
  });
545
- if (ee(h, m)) {
792
+ if (ee(d, g)) {
546
793
  if (u !== 0 && !a)
547
794
  switch (l) {
548
795
  case "horizontal": {
549
- o |= u < 0 ? he : me;
796
+ o |= u < 0 ? Le : Pe;
550
797
  break;
551
798
  }
552
799
  case "vertical": {
553
- o |= u < 0 ? ve : ge;
800
+ o |= u < 0 ? Ee : Re;
554
801
  break;
555
802
  }
556
803
  }
557
804
  } else {
558
805
  s.set(i.group, {
559
- derivedPanelConstraints: p,
560
- layout: h
806
+ derivedPanelConstraints: m,
807
+ layout: d,
808
+ separatorToPanels: p
561
809
  });
562
- const f = i.group.panels.map(({ id: v }) => v).join(",");
563
- i.group.inMemoryLayouts[f] = h;
810
+ const h = i.group.panels.map(({ id: v }) => v).join(",");
811
+ i.group.inMemoryLayouts[h] = d;
564
812
  }
565
813
  }
566
- }), G({
814
+ }), M({
567
815
  cursorFlags: o,
568
816
  mountedGroups: s
569
- }), Y();
817
+ }), se();
570
818
  break;
571
819
  }
572
820
  default: {
573
- const o = ye(e, n);
574
- o.length === 0 ? t.state !== "inactive" && G({
821
+ const o = Ce(e, n);
822
+ o.length === 0 ? t.state !== "inactive" && M({
575
823
  interactionState: { state: "inactive" }
576
- }) : G({
824
+ }) : M({
577
825
  interactionState: {
578
826
  hitRegions: o,
579
827
  state: "hover"
580
828
  }
581
- }), Y();
829
+ }), se();
582
830
  break;
583
831
  }
584
832
  }
585
833
  }
586
- function ue(e) {
834
+ function ye(e) {
587
835
  if (e.defaultPrevented)
588
836
  return;
589
837
  e.preventDefault();
590
- const { interactionState: t } = O();
838
+ const { interactionState: t } = k();
591
839
  switch (t.state) {
592
840
  case "active":
593
- G({
841
+ M({
594
842
  cursorFlags: 0,
595
843
  interactionState: {
596
844
  state: "inactive"
597
845
  }
598
- }), Y();
846
+ }), se();
599
847
  }
600
848
  }
601
- function Xe(e) {
849
+ function et(e) {
602
850
  let t = 0, n = 0;
603
851
  const o = {};
604
852
  for (const i of e)
605
853
  if (i.defaultSize !== void 0) {
606
854
  t++;
607
- const a = L(i.defaultSize);
855
+ const a = C(i.defaultSize);
608
856
  n += a, o[i.panelId] = a;
609
857
  } else
610
858
  o[i.panelId] = void 0;
611
859
  const s = e.length - t;
612
860
  if (s !== 0) {
613
- const i = L((100 - n) / s);
861
+ const i = C((100 - n) / s);
614
862
  for (const a of e)
615
863
  a.defaultSize === void 0 && (o[a.panelId] = i);
616
864
  }
617
865
  return o;
618
866
  }
619
- function Ye(e, t, n) {
867
+ function tt(e, t, n) {
620
868
  const o = n[0];
621
869
  if (!o)
622
870
  return;
623
871
  const s = e.panels.find((a) => a.element === t);
624
872
  if (!s || !s.onResize)
625
873
  return;
626
- const i = Q({ group: e });
874
+ const i = le({ group: e });
627
875
  s.onResize(
628
876
  {
629
- asPercentage: L(
877
+ asPercentage: C(
630
878
  o.inlineSize / i * 100
631
879
  ),
632
880
  inPixels: o.inlineSize
@@ -634,105 +882,71 @@ function Ye(e, t, n) {
634
882
  s.id
635
883
  );
636
884
  }
637
- function q({
638
- layout: e,
639
- panelConstraints: t
640
- }) {
641
- const o = [...Object.values(e)], s = o.reduce(
642
- (r, l) => r + l,
643
- 0
644
- );
645
- if (o.length !== t.length)
646
- throw Error(
647
- `Invalid ${t.length} panel layout: ${o.map((r) => `${r}%`).join(", ")}`
648
- );
649
- if (!w(s, 100) && o.length > 0)
650
- for (let r = 0; r < t.length; r++) {
651
- const l = o[r];
652
- C(l != null, `No layout data found for index ${r}`);
653
- const c = 100 / s * l;
654
- o[r] = c;
655
- }
656
- let i = 0;
657
- for (let r = 0; r < t.length; r++) {
658
- const l = o[r];
659
- C(l != null, `No layout data found for index ${r}`);
660
- const c = D({
661
- panelConstraints: t[r],
662
- size: l
663
- });
664
- l != c && (i += l - c, o[r] = c);
665
- }
666
- if (!w(i, 0))
667
- for (let r = 0; r < t.length; r++) {
668
- const l = o[r];
669
- C(l != null, `No layout data found for index ${r}`);
670
- const c = l + i, u = D({
671
- panelConstraints: t[r],
672
- size: c
673
- });
674
- if (l !== u && (i -= u - l, o[r] = u, w(i, 0)))
675
- break;
676
- }
677
- const a = Object.keys(e);
678
- return o.reduce((r, l, c) => (r[a[c]] = l, r), {});
679
- }
680
- function Ze(e) {
681
- let t = !1;
682
- const n = new ResizeObserver((l) => {
683
- for (const c of l) {
684
- const { borderBoxSize: u, target: d } = c;
685
- d === e.element ? t && G((p) => {
686
- const m = p.mountedGroups.get(e);
687
- if (m) {
688
- const h = ae(e), f = m.layout, v = q({
689
- layout: f,
690
- panelConstraints: h
885
+ function nt(e) {
886
+ let t = !0;
887
+ const n = new ResizeObserver((c) => {
888
+ for (const u of c) {
889
+ const { borderBoxSize: f, target: m } = u;
890
+ m === e.element ? t && M((g) => {
891
+ const p = g.mountedGroups.get(e);
892
+ if (p) {
893
+ const d = pe(e), h = p.layout, v = F({
894
+ layout: h,
895
+ panelConstraints: d
691
896
  });
692
897
  return {
693
- mountedGroups: new Map(p.mountedGroups).set(e, {
694
- derivedPanelConstraints: h,
695
- layout: v
898
+ mountedGroups: new Map(g.mountedGroups).set(e, {
899
+ derivedPanelConstraints: d,
900
+ layout: v,
901
+ separatorToPanels: p.separatorToPanels
696
902
  })
697
903
  };
698
904
  }
699
- return p;
700
- }) : Ye(e, d, u);
905
+ return g;
906
+ }) : tt(e, m, f);
701
907
  }
702
908
  });
703
- n.observe(e.element), e.panels.forEach((l) => {
704
- l.onResize && n.observe(l.element);
909
+ n.observe(e.element), e.panels.forEach((c) => {
910
+ c.onResize && n.observe(c.element);
705
911
  });
706
- const o = ae(e), s = e.panels.map(({ id: l }) => l).join(","), i = e.inMemoryLayouts[s] ?? e.defaultLayout ?? Xe(o), a = q({
912
+ const o = pe(e), s = e.panels.map(({ id: c }) => c).join(","), i = e.inMemoryLayouts[s] ?? e.defaultLayout ?? et(o), a = F({
707
913
  layout: i,
708
914
  panelConstraints: o
709
- }), r = G((l) => ({
710
- mountedGroups: new Map(l.mountedGroups).set(e, {
915
+ }), r = ze(e), l = M((c) => ({
916
+ mountedGroups: new Map(c.mountedGroups).set(e, {
711
917
  derivedPanelConstraints: o,
712
- layout: a
918
+ layout: a,
919
+ separatorToPanels: new Map(
920
+ r.filter((u) => u.separator).map((u) => [u.separator, u.panels])
921
+ )
713
922
  })
714
923
  }));
715
- return t = !0, r.mountedGroups.size === 1 && (window.addEventListener("pointerdown", ce), window.addEventListener("pointerleave", U), window.addEventListener("pointermove", U), window.addEventListener("pointerup", ue)), function() {
716
- const c = G((u) => {
717
- const d = new Map(u.mountedGroups);
718
- return d.delete(e), { mountedGroups: d };
924
+ return e.separators.forEach((c) => {
925
+ c.element.addEventListener("keydown", me);
926
+ }), l.mountedGroups.size === 1 && (window.addEventListener("pointerdown", ve), window.addEventListener("pointerleave", q), window.addEventListener("pointermove", q), window.addEventListener("pointerup", ye)), function() {
927
+ t = !1;
928
+ const u = M((f) => {
929
+ const m = new Map(f.mountedGroups);
930
+ return m.delete(e), { mountedGroups: m };
719
931
  });
720
- t = !1, c.mountedGroups.size === 0 && (window.removeEventListener("pointerdown", ce), window.removeEventListener("pointerleave", U), window.removeEventListener("pointermove", U), window.removeEventListener("pointerup", ue)), n.disconnect();
932
+ e.separators.forEach((f) => {
933
+ f.element.removeEventListener("keydown", me);
934
+ }), u.mountedGroups.size === 0 && (window.removeEventListener("pointerdown", ve), window.removeEventListener("pointerleave", q), window.removeEventListener("pointermove", q), window.removeEventListener("pointerup", ye)), n.disconnect();
721
935
  };
722
936
  }
723
- function te(e) {
724
- const t = Pe();
937
+ function ce(e) {
938
+ const t = De();
725
939
  return `${e ?? t}`;
726
940
  }
727
- const _ = typeof window < "u" ? Ee : Ce;
728
- function ne(e) {
729
- const t = I(e);
730
- return _(() => {
941
+ const H = typeof window < "u" ? Te : Ae;
942
+ function ue(e) {
943
+ const t = D(e);
944
+ return H(() => {
731
945
  t.current = e;
732
- }, [e]), fe((n) => t.current?.(n), [t]);
946
+ }, [e]), ge((n) => t.current?.(n), [t]);
733
947
  }
734
- function oe(...e) {
735
- return ne((t) => {
948
+ function fe(...e) {
949
+ return ue((t) => {
736
950
  e.forEach((n) => {
737
951
  if (n)
738
952
  switch (typeof n) {
@@ -748,54 +962,25 @@ function oe(...e) {
748
962
  });
749
963
  });
750
964
  }
751
- const Se = "--react-resizable-panels--panel--pointer-events";
752
- function xe(e, t) {
965
+ const Me = "--react-resizable-panels--panel--pointer-events";
966
+ function Ge(e, t) {
753
967
  const n = e.replace(/[^a-zA-Z0-9\-_]/g, ""), o = t.replace(/[^a-zA-Z0-9\-_]/g, "");
754
968
  return `--react-resizable-panels--${n}--${o}`;
755
969
  }
756
- const ze = Me(null);
757
- function qe({
758
- groupId: e
759
- }) {
760
- const t = () => {
761
- const { mountedGroups: n } = O();
762
- for (const [o, { derivedPanelConstraints: s, layout: i }] of n)
763
- if (o.id === e)
764
- return { derivedPanelConstraints: s, group: o, layout: i };
765
- throw Error(`Group ${e} not found`);
766
- };
767
- return {
768
- getLayout() {
769
- const { layout: n } = t();
770
- return n;
771
- },
772
- setLayout(n) {
773
- const { derivedPanelConstraints: o, group: s, layout: i } = t(), a = q({
774
- layout: n,
775
- panelConstraints: o
776
- });
777
- return ee(i, a) || G((r) => ({
778
- mountedGroups: new Map(r.mountedGroups).set(s, {
779
- derivedPanelConstraints: o,
780
- layout: a
781
- })
782
- })), a;
783
- }
784
- };
785
- }
786
- function Je(e, t) {
787
- const n = I({
970
+ const Ie = $e(null);
971
+ function ot(e, t) {
972
+ const n = D({
788
973
  getLayout: () => ({}),
789
- setLayout: Te
974
+ setLayout: Ye
790
975
  });
791
- de(t, () => n.current, []), _(() => {
976
+ Se(t, () => n.current, []), H(() => {
792
977
  Object.assign(
793
978
  n.current,
794
- qe({ groupId: e })
979
+ be({ groupId: e })
795
980
  );
796
981
  });
797
982
  }
798
- function rt({
983
+ function ft({
799
984
  children: e,
800
985
  className: t,
801
986
  defaultLayout: n,
@@ -808,95 +993,97 @@ function rt({
808
993
  orientation: c = "horizontal",
809
994
  style: u
810
995
  }) {
811
- const d = I({}), p = ne((y) => {
812
- ee(d.current, y) || (d.current = y, l?.(y));
813
- }), m = te(r), [h, f] = M(!1), [v, g] = M(null), x = I({}), [z, S] = M(n ?? {}), [R, k] = M([]), [A, re] = M([]), be = oe(g, i);
814
- Je(m, a);
815
- const we = pe(
996
+ const f = D({}), m = ue((b) => {
997
+ ee(f.current, b) || (f.current = b, l?.(b));
998
+ }), g = ce(r), [p, d] = R(!1), [h, v] = R(null), [z, x] = R(n ?? {}), [y, w] = R([]), [G, O] = R([]), te = D({}), U = D({}), B = fe(v, i);
999
+ ot(g, a);
1000
+ const K = xe(
816
1001
  () => ({
817
- id: m,
1002
+ id: g,
818
1003
  orientation: c,
819
- registerPanel: (y) => (k((b) => X(c, [...b, y])), () => {
820
- k((b) => b.filter((N) => N !== y));
1004
+ registerPanel: (b) => (w((E) => re(c, [...E, b])), () => {
1005
+ w((E) => E.filter(($) => $ !== b));
821
1006
  }),
822
- registerSeparator: (y) => (re(
823
- (b) => X(c, [...b, y])
1007
+ registerSeparator: (b) => (O(
1008
+ (E) => re(c, [...E, b])
824
1009
  ), () => {
825
- re(
826
- (b) => b.filter((N) => N !== y)
1010
+ O(
1011
+ (E) => E.filter(($) => $ !== b)
827
1012
  );
828
1013
  })
829
1014
  }),
830
- [m, c]
1015
+ [g, c]
831
1016
  );
832
- _(() => {
833
- if (v !== null && R.length > 0) {
834
- const y = {
1017
+ H(() => {
1018
+ if (h !== null && y.length > 0) {
1019
+ const b = {
835
1020
  defaultLayout: n,
836
1021
  disableCursor: !!o,
837
1022
  disabled: !!s,
838
- element: v,
839
- id: m,
840
- inMemoryLayouts: x.current,
1023
+ element: h,
1024
+ id: g,
1025
+ inMemoryLastExpandedPanelSizes: te.current,
1026
+ inMemoryLayouts: U.current,
841
1027
  orientation: c,
842
- panels: R,
843
- separators: A
844
- }, b = Ze(y), B = O().mountedGroups.get(y);
845
- B && (S(B.layout), p?.(B.layout));
846
- const Le = T.addListener(
1028
+ panels: y,
1029
+ separators: G
1030
+ }, E = nt(b), ne = k().mountedGroups.get(b);
1031
+ ne && (x(ne.layout), m?.(ne.layout));
1032
+ const ke = A.addListener(
847
1033
  "interactionStateChange",
848
- (H) => {
849
- switch (H.state) {
1034
+ (X) => {
1035
+ switch (X.state) {
850
1036
  case "active":
851
1037
  case "hover": {
852
- f(
853
- H.hitRegions.some(
854
- ($) => $.group === y
1038
+ d(
1039
+ X.hitRegions.some(
1040
+ (N) => N.group === b
855
1041
  )
856
1042
  );
857
1043
  break;
858
1044
  }
859
1045
  }
860
1046
  }
861
- ), Re = T.addListener(
1047
+ ), Oe = A.addListener(
862
1048
  "mountedGroupsChange",
863
- (H) => {
864
- const $ = H.get(y);
865
- $ && $.derivedPanelConstraints.length > 0 && (S($.layout), p?.($.layout));
1049
+ (X) => {
1050
+ const N = X.get(b);
1051
+ N && N.derivedPanelConstraints.length > 0 && (x(N.layout), m?.(N.layout));
866
1052
  }
867
1053
  );
868
1054
  return () => {
869
- b(), Le(), Re();
1055
+ E(), ke(), Oe();
870
1056
  };
871
1057
  }
872
1058
  }, [
873
1059
  n,
874
1060
  o,
875
1061
  s,
876
- v,
1062
+ h,
1063
+ g,
877
1064
  m,
878
- p,
879
1065
  c,
880
- R,
881
- A
1066
+ y,
1067
+ G
882
1068
  ]);
883
- const se = {
884
- [Se]: h ? "none" : void 0
1069
+ const V = {
1070
+ [Me]: p ? "none" : void 0
885
1071
  };
886
- for (const y in z) {
887
- const b = xe(m, y), N = z[y];
888
- se[b] = N;
1072
+ for (const b in z) {
1073
+ const E = Ge(g, b), $ = z[b];
1074
+ V[E] = $;
889
1075
  }
890
- return /* @__PURE__ */ F(ze.Provider, { value: we, children: /* @__PURE__ */ F(
1076
+ return /* @__PURE__ */ j(Ie.Provider, { value: K, children: /* @__PURE__ */ j(
891
1077
  "div",
892
1078
  {
893
1079
  "aria-orientation": c,
894
1080
  className: t,
895
- "data-group": m,
896
- ref: be,
1081
+ "data-group": !0,
1082
+ "data-testid": r ?? void 0,
1083
+ ref: B,
897
1084
  style: {
898
1085
  ...u,
899
- ...se,
1086
+ ...V,
900
1087
  display: "flex",
901
1088
  flexDirection: c === "horizontal" ? "row" : "column",
902
1089
  flexWrap: "nowrap"
@@ -905,34 +1092,34 @@ function rt({
905
1092
  }
906
1093
  ) });
907
1094
  }
908
- function J(e) {
1095
+ function ae(e) {
909
1096
  return `react-resizable-panels:${e}`;
910
1097
  }
911
- function Qe({
1098
+ function it({
912
1099
  id: e,
913
1100
  layout: t,
914
1101
  storage: n
915
1102
  }) {
916
1103
  try {
917
- const o = J(e);
1104
+ const o = ae(e);
918
1105
  n.setItem(o, JSON.stringify(t));
919
1106
  } catch (o) {
920
1107
  console.error(o);
921
1108
  }
922
1109
  }
923
- function st({
1110
+ function dt({
924
1111
  groupId: e,
925
1112
  storage: t
926
1113
  }) {
927
- const n = Ge(
928
- et,
929
- () => t.getItem(J(e)),
930
- () => t.getItem(J(e))
931
- ), o = pe(
1114
+ const n = Ne(
1115
+ rt,
1116
+ () => t.getItem(ae(e)),
1117
+ () => t.getItem(ae(e))
1118
+ ), o = xe(
932
1119
  () => n ? JSON.parse(n) : null,
933
1120
  [n]
934
- ), s = fe(
935
- (i) => Qe({
1121
+ ), s = ge(
1122
+ (i) => it({
936
1123
  id: e,
937
1124
  layout: i,
938
1125
  storage: t
@@ -944,26 +1131,26 @@ function st({
944
1131
  onLayoutChange: s
945
1132
  };
946
1133
  }
947
- function et() {
1134
+ function rt() {
948
1135
  return function() {
949
1136
  };
950
1137
  }
951
- function at() {
952
- return M(null);
1138
+ function pt() {
1139
+ return R(null);
953
1140
  }
954
- function lt() {
955
- return I(null);
1141
+ function mt() {
1142
+ return D(null);
956
1143
  }
957
- function ie() {
958
- const e = Ie(ze);
959
- return C(e, "Unexpected"), e;
1144
+ function de() {
1145
+ const e = _e(Ie);
1146
+ return S(e, "Unexpected"), e;
960
1147
  }
961
- function tt({
1148
+ function st({
962
1149
  groupId: e,
963
1150
  panelId: t
964
1151
  }) {
965
1152
  const n = () => {
966
- const { mountedGroups: a } = O();
1153
+ const { mountedGroups: a } = k();
967
1154
  for (const [r, { derivedPanelConstraints: l, layout: c }] of a)
968
1155
  if (r.id === e)
969
1156
  return { derivedPanelConstraints: l, group: r, layout: c };
@@ -1004,39 +1191,39 @@ function tt({
1004
1191
  },
1005
1192
  isCollapsed: () => {
1006
1193
  const { collapsible: a, collapsedSize: r } = o(), l = i();
1007
- return a && w(r, l);
1194
+ return a && L(r, l);
1008
1195
  },
1009
1196
  resize: (a) => {
1010
1197
  if (i() !== a)
1011
1198
  switch (typeof a) {
1012
1199
  case "number": {
1013
- const { group: l } = n(), c = Q({ group: l });
1014
- L(a / c * 100);
1200
+ const { group: l } = n(), c = le({ group: l });
1201
+ C(a / c * 100);
1015
1202
  break;
1016
1203
  }
1017
1204
  }
1018
1205
  }
1019
1206
  };
1020
1207
  }
1021
- function nt(e, t) {
1022
- const { id: n } = ie(), o = I({
1023
- collapse: V,
1024
- expand: V,
1208
+ function at(e, t) {
1209
+ const { id: n } = de(), o = D({
1210
+ collapse: oe,
1211
+ expand: oe,
1025
1212
  getSize: () => ({
1026
1213
  asPercentage: 0,
1027
1214
  inPixels: 0
1028
1215
  }),
1029
1216
  isCollapsed: () => !1,
1030
- resize: V
1217
+ resize: oe
1031
1218
  });
1032
- de(t, () => o.current, []), _(() => {
1219
+ Se(t, () => o.current, []), H(() => {
1033
1220
  Object.assign(
1034
1221
  o.current,
1035
- tt({ groupId: n, panelId: e })
1222
+ st({ groupId: n, panelId: e })
1036
1223
  );
1037
1224
  });
1038
1225
  }
1039
- function ct({
1226
+ function ht({
1040
1227
  children: e,
1041
1228
  className: t,
1042
1229
  collapsedSize: n = 0,
@@ -1048,18 +1235,18 @@ function ct({
1048
1235
  minSize: l = "0",
1049
1236
  onResize: c,
1050
1237
  panelRef: u,
1051
- style: d
1238
+ style: f
1052
1239
  }) {
1053
- const p = !!a, m = te(a), [h, f] = M(null), v = oe(f, i), { id: g, registerPanel: x } = ie(), z = c !== null, S = ne((k) => {
1054
- c?.(k, a);
1240
+ const m = !!a, g = ce(a), [p, d] = R(null), h = fe(d, i), { id: v, registerPanel: z } = de(), x = c !== null, y = ue((G) => {
1241
+ c?.(G, a);
1055
1242
  });
1056
- _(() => {
1057
- if (h !== null)
1058
- return x({
1059
- element: h,
1060
- id: m,
1061
- idIsStable: p,
1062
- onResize: z ? S : void 0,
1243
+ H(() => {
1244
+ if (p !== null)
1245
+ return z({
1246
+ element: p,
1247
+ id: g,
1248
+ idIsStable: m,
1249
+ onResize: x ? y : void 0,
1063
1250
  panelConstraints: {
1064
1251
  collapsedSize: n,
1065
1252
  collapsible: o,
@@ -1072,39 +1259,40 @@ function ct({
1072
1259
  n,
1073
1260
  o,
1074
1261
  s,
1075
- h,
1076
- z,
1077
- m,
1078
1262
  p,
1263
+ x,
1264
+ g,
1265
+ m,
1079
1266
  r,
1080
1267
  l,
1081
- S,
1082
- x
1083
- ]), nt(m, u);
1084
- const R = xe(g, m);
1085
- return /* @__PURE__ */ F(
1268
+ y,
1269
+ z
1270
+ ]), at(g, u);
1271
+ const w = Ge(v, g);
1272
+ return /* @__PURE__ */ j(
1086
1273
  "div",
1087
1274
  {
1088
- "data-panel": m,
1089
- ref: v,
1275
+ "data-panel": !0,
1276
+ "data-testid": a ?? void 0,
1277
+ ref: h,
1090
1278
  style: {
1091
1279
  flexBasis: 0,
1092
- flexGrow: `var(${R}, 1)`,
1280
+ flexGrow: `var(${w}, 1)`,
1093
1281
  flexShrink: 1,
1094
1282
  // Prevent Panel content from interfering with panel size
1095
1283
  overflow: "hidden",
1096
1284
  // Disable pointer events inside of a panel during resize
1097
1285
  // This avoid edge cases like nested iframes
1098
- pointerEvents: `var(${Se})`
1286
+ pointerEvents: `var(${Me})`
1099
1287
  },
1100
- children: /* @__PURE__ */ F(
1288
+ children: /* @__PURE__ */ j(
1101
1289
  "div",
1102
1290
  {
1103
1291
  className: t,
1104
1292
  style: {
1105
1293
  width: "100%",
1106
1294
  height: "100%",
1107
- ...d
1295
+ ...f
1108
1296
  },
1109
1297
  children: e
1110
1298
  }
@@ -1112,48 +1300,117 @@ function ct({
1112
1300
  }
1113
1301
  );
1114
1302
  }
1115
- function ut() {
1116
- return M(null);
1303
+ function vt() {
1304
+ return R(null);
1117
1305
  }
1118
- function ft() {
1119
- return I(null);
1306
+ function yt() {
1307
+ return D(null);
1120
1308
  }
1121
- function dt({
1309
+ function lt({
1310
+ layout: e,
1311
+ panelConstraints: t,
1312
+ panelId: n,
1313
+ panelIndex: o
1314
+ }) {
1315
+ let s, i;
1316
+ const a = e[n], r = t.find(
1317
+ (l) => l.panelId === n
1318
+ );
1319
+ if (r) {
1320
+ const l = r.maxSize, c = i = r.collapsible ? r.collapsedSize : r.minSize, u = [o, o + 1];
1321
+ i = F({
1322
+ layout: Q({
1323
+ delta: c - a,
1324
+ initialLayout: e,
1325
+ panelConstraints: t,
1326
+ pivotIndices: u,
1327
+ prevLayout: e,
1328
+ trigger: "keyboard"
1329
+ }),
1330
+ panelConstraints: t
1331
+ })[n], s = F({
1332
+ layout: Q({
1333
+ delta: l - a,
1334
+ initialLayout: e,
1335
+ panelConstraints: t,
1336
+ pivotIndices: u,
1337
+ prevLayout: e,
1338
+ trigger: "keyboard"
1339
+ }),
1340
+ panelConstraints: t
1341
+ })[n];
1342
+ }
1343
+ return {
1344
+ valueMax: s,
1345
+ valueMin: i,
1346
+ valueNow: a
1347
+ };
1348
+ }
1349
+ function gt({
1122
1350
  children: e,
1123
1351
  className: t,
1124
1352
  elementRef: n,
1125
1353
  id: o,
1126
1354
  style: s
1127
1355
  }) {
1128
- const i = te(o), [a, r] = M(null), [l, c] = M("inactive"), u = oe(r, n), { orientation: d, registerSeparator: p } = ie(), m = d === "horizontal" ? "vertical" : "horizontal";
1129
- return _(() => {
1130
- if (a !== null) {
1131
- const h = {
1132
- element: a,
1356
+ const i = ce(o), [a, r] = R({}), [l, c] = R("inactive"), [u, f] = R(null), m = fe(f, n), {
1357
+ id: g,
1358
+ orientation: p,
1359
+ registerSeparator: d
1360
+ } = de(), h = p === "horizontal" ? "vertical" : "horizontal";
1361
+ return H(() => {
1362
+ if (u !== null) {
1363
+ const v = {
1364
+ element: u,
1133
1365
  id: i
1134
- }, f = p(h), v = T.addListener(
1366
+ }, z = d(v), x = A.addListener(
1135
1367
  "interactionStateChange",
1136
- (g) => {
1368
+ (w) => {
1137
1369
  c(
1138
- g.state !== "inactive" && g.hitRegions.some(
1139
- (x) => x.separator === h
1140
- ) ? g.state : "inactive"
1370
+ w.state !== "inactive" && w.hitRegions.some(
1371
+ (G) => G.separator === v
1372
+ ) ? w.state : "inactive"
1373
+ );
1374
+ }
1375
+ ), y = A.addListener(
1376
+ "mountedGroupsChange",
1377
+ (w) => {
1378
+ w.forEach(
1379
+ ({ derivedPanelConstraints: G, layout: O, separatorToPanels: te }, U) => {
1380
+ if (U.id === g) {
1381
+ const B = te.get(v);
1382
+ if (B) {
1383
+ const K = B[0], V = U.panels.indexOf(K);
1384
+ r(
1385
+ lt({
1386
+ layout: O,
1387
+ panelConstraints: G,
1388
+ panelId: K.id,
1389
+ panelIndex: V
1390
+ })
1391
+ );
1392
+ }
1393
+ }
1394
+ }
1141
1395
  );
1142
1396
  }
1143
1397
  );
1144
1398
  return () => {
1145
- f(), v();
1399
+ x(), y(), z();
1146
1400
  };
1147
1401
  }
1148
- }, [a, i, p]), /* @__PURE__ */ F(
1402
+ }, [u, g, i, d]), /* @__PURE__ */ j(
1149
1403
  "div",
1150
1404
  {
1151
- "aria-orientation": m,
1405
+ "aria-orientation": h,
1406
+ "aria-valuemax": a.valueMax,
1407
+ "aria-valuemin": a.valueMin,
1408
+ "aria-valuenow": a.valueNow,
1152
1409
  children: e,
1153
1410
  className: t,
1154
- "data-separator": i,
1155
- "data-separator-state": l,
1156
- ref: u,
1411
+ "data-separator": l,
1412
+ "data-testid": o ?? void 0,
1413
+ ref: m,
1157
1414
  role: "separator",
1158
1415
  style: {
1159
1416
  flexBasis: "auto",
@@ -1166,13 +1423,13 @@ function dt({
1166
1423
  );
1167
1424
  }
1168
1425
  export {
1169
- rt as Group,
1170
- ct as Panel,
1171
- dt as Separator,
1172
- st as useDefaultLayout,
1173
- at as useGroupCallbackRef,
1174
- lt as useGroupRef,
1175
- ut as usePanelCallbackRef,
1176
- ft as usePanelRef
1426
+ ft as Group,
1427
+ ht as Panel,
1428
+ gt as Separator,
1429
+ dt as useDefaultLayout,
1430
+ pt as useGroupCallbackRef,
1431
+ mt as useGroupRef,
1432
+ vt as usePanelCallbackRef,
1433
+ yt as usePanelRef
1177
1434
  };
1178
1435
  //# sourceMappingURL=react-resizable-panels.js.map