react-resizable-panels 4.0.5 → 4.0.6

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.
@@ -5,7 +5,7 @@ function z(e, t = "Assertion error") {
5
5
  if (!e)
6
6
  throw Error(t);
7
7
  }
8
- function se(e, t) {
8
+ function re(e, t) {
9
9
  return t.sort(
10
10
  e === "horizontal" ? je : Be
11
11
  );
@@ -18,8 +18,14 @@ function Be(e, t) {
18
18
  const n = e.element.offsetTop - t.element.offsetTop;
19
19
  return n !== 0 ? n : e.element.offsetHeight - t.element.offsetHeight;
20
20
  }
21
+ function te({
22
+ group: e
23
+ }) {
24
+ const { orientation: t, panels: n } = e;
25
+ return n.reduce((o, r) => (o += t === "horizontal" ? r.element.offsetWidth : r.element.offsetHeight, o), 0);
26
+ }
21
27
  function we(e) {
22
- const { element: t, orientation: n, panels: o, separators: r } = e, s = se(
28
+ const { element: t, orientation: n, panels: o, separators: r } = e, s = re(
23
29
  n,
24
30
  Array.from(t.children).filter((l) => l instanceof HTMLElement).map((l) => ({ element: l }))
25
31
  ).map(({ element: l }) => l), c = [];
@@ -33,6 +39,7 @@ function we(e) {
33
39
  const u = i.element.getBoundingClientRect(), m = l.getBoundingClientRect();
34
40
  c.push({
35
41
  group: e,
42
+ groupSize: te({ group: e }),
36
43
  panels: [i, f],
37
44
  separator: a,
38
45
  rect: n === "horizontal" ? new DOMRect(
@@ -120,14 +127,8 @@ function J({
120
127
  function I(e) {
121
128
  return parseFloat(e.toFixed(3));
122
129
  }
123
- function ae({
124
- group: e
125
- }) {
126
- const { orientation: t, panels: n } = e;
127
- return n.reduce((o, r) => (o += t === "horizontal" ? r.element.offsetWidth : r.element.offsetHeight, o), 0);
128
- }
129
130
  function pe(e) {
130
- const { panels: t } = e, n = ae({ group: e });
131
+ const { panels: t } = e, n = te({ group: e });
131
132
  return t.map((o) => {
132
133
  const { element: r, panelConstraints: s } = o;
133
134
  let c = 0;
@@ -255,7 +256,7 @@ function C(e) {
255
256
  });
256
257
  }), A.emit("mountedGroupsChange", R.mountedGroups)), R;
257
258
  }
258
- const Ze = (e) => e, oe = () => {
259
+ const Ze = (e) => e, ie = () => {
259
260
  }, Le = 1, Pe = 2, Ee = 4, Re = 8, me = {
260
261
  coarse: 10,
261
262
  precise: 5
@@ -303,7 +304,7 @@ function Je({
303
304
  }
304
305
  return o > 0 && r > 0 ? "move" : o > 0 ? "ew-resize" : "ns-resize";
305
306
  }
306
- let ie, k;
307
+ let se, k;
307
308
  function le() {
308
309
  k === void 0 && (k = new CSSStyleSheet(), document.adoptedStyleSheets = [k]);
309
310
  const { cursorFlags: e, interactionState: t } = O();
@@ -315,13 +316,13 @@ function le() {
315
316
  groups: t.hitRegions.map((r) => r.group),
316
317
  state: t.state
317
318
  }), o = `*{cursor: ${n} !important; ${t.state === "active" ? "touch-action: none;" : ""} }`;
318
- if (ie === o)
319
+ if (se === o)
319
320
  return;
320
- ie = o, n ? k.cssRules.length === 0 ? k.insertRule(o) : k.replaceSync(o) : k.cssRules.length === 1 && k.deleteRule(0);
321
+ se = o, n ? k.cssRules.length === 0 ? k.insertRule(o) : k.replaceSync(o) : k.cssRules.length === 1 && k.deleteRule(0);
321
322
  break;
322
323
  }
323
324
  case "inactive": {
324
- ie = void 0, k.cssRules.length === 1 && k.deleteRule(0);
325
+ se = void 0, k.cssRules.length === 1 && k.deleteRule(0);
325
326
  break;
326
327
  }
327
328
  }
@@ -378,15 +379,15 @@ function B({
378
379
  const {
379
380
  collapsedSize: v = 0,
380
381
  collapsible: h,
381
- minSize: g = 0
382
+ minSize: x = 0
382
383
  } = p;
383
384
  if (h) {
384
- const x = c[d];
385
+ const S = c[d];
385
386
  if (z(
386
- x != null,
387
+ S != null,
387
388
  `Previous layout not found for panel index ${d}`
388
- ), w(x, v)) {
389
- const y = g - x;
389
+ ), w(S, v)) {
390
+ const y = x - S;
390
391
  j(y, Math.abs(e)) > 0 && (e = e < 0 ? 0 - y : y);
391
392
  }
392
393
  }
@@ -400,15 +401,15 @@ function B({
400
401
  const {
401
402
  collapsedSize: v = 0,
402
403
  collapsible: h,
403
- minSize: g = 0
404
+ minSize: x = 0
404
405
  } = p;
405
406
  if (h) {
406
- const x = c[d];
407
+ const S = c[d];
407
408
  if (z(
408
- x != null,
409
+ S != null,
409
410
  `Previous layout not found for panel index ${d}`
410
- ), w(x, g)) {
411
- const y = x - v;
411
+ ), w(S, x)) {
412
+ const y = S - v;
412
413
  j(y, Math.abs(e)) > 0 && (e = e < 0 ? 0 - y : y);
413
414
  }
414
415
  }
@@ -418,15 +419,15 @@ function B({
418
419
  const d = e < 0 ? 1 : -1;
419
420
  let p = e < 0 ? f : l, v = 0;
420
421
  for (; ; ) {
421
- const g = c[p];
422
+ const x = c[p];
422
423
  z(
423
- g != null,
424
+ x != null,
424
425
  `Previous layout not found for panel index ${p}`
425
426
  );
426
427
  const y = F({
427
428
  panelConstraints: n[p],
428
429
  size: 100
429
- }) - g;
430
+ }) - x;
430
431
  if (v += y, p += d, p < 0 || p >= n.length)
431
432
  break;
432
433
  }
@@ -441,11 +442,11 @@ function B({
441
442
  h != null,
442
443
  `Previous layout not found for panel index ${p}`
443
444
  );
444
- const g = h - v, x = F({
445
+ const x = h - v, S = F({
445
446
  panelConstraints: n[p],
446
- size: g
447
+ size: x
447
448
  });
448
- if (!w(h, x) && (u += h - x, a[p] = x, u.toFixed(3).localeCompare(Math.abs(e).toFixed(3), void 0, {
449
+ if (!w(h, S) && (u += h - S, a[p] = S, u.toFixed(3).localeCompare(Math.abs(e).toFixed(3), void 0, {
449
450
  numeric: !0
450
451
  }) >= 0))
451
452
  break;
@@ -465,18 +466,18 @@ function B({
465
466
  size: v
466
467
  });
467
468
  if (a[d] = h, !w(h, v)) {
468
- let g = v - h, y = e < 0 ? f : l;
469
+ let x = v - h, y = e < 0 ? f : l;
469
470
  for (; y >= 0 && y < n.length; ) {
470
471
  const L = a[y];
471
472
  z(
472
473
  L != null,
473
474
  `Previous layout not found for panel index ${y}`
474
475
  );
475
- const P = L + g, E = F({
476
+ const P = L + x, E = F({
476
477
  panelConstraints: n[y],
477
478
  size: P
478
479
  });
479
- if (w(L, E) || (g -= E - L, a[y] = E), w(g, 0))
480
+ if (w(L, E) || (x -= E - L, a[y] = E), w(x, 0))
480
481
  break;
481
482
  e > 0 ? y-- : y++;
482
483
  }
@@ -488,8 +489,8 @@ function B({
488
489
  );
489
490
  if (!w(m, 100, 0.1))
490
491
  return r;
491
- const S = Object.keys(r);
492
- return a.reduce((d, p, v) => (d[S[v]] = p, d), {});
492
+ const g = Object.keys(r);
493
+ return a.reduce((d, p, v) => (d[g[v]] = p, d), {});
493
494
  }
494
495
  function U(e, t) {
495
496
  if (Object.keys(e).length !== Object.keys(t).length)
@@ -509,43 +510,43 @@ function Ce({
509
510
  let s = 0;
510
511
  const c = new Map(o);
511
512
  t.forEach((i) => {
512
- const { disableCursor: a, element: l, orientation: f, panels: u } = i.group;
513
- let m = 0;
514
- r ? f === "horizontal" ? m = (e.clientX - r.x) / l.offsetWidth * 100 : m = (e.clientY - r.y) / l.offsetHeight * 100 : f === "horizontal" ? m = e.clientX < 0 ? -100 : 100 : m = e.clientY < 0 ? -100 : 100;
515
- const S = n.get(i.group), {
516
- derivedPanelConstraints: d,
517
- layout: p,
518
- separatorToPanels: v
519
- } = o.get(i.group) ?? {};
520
- if (d && S && p && v) {
521
- const h = B({
522
- delta: m,
523
- initialLayout: S,
524
- panelConstraints: d,
525
- pivotIndices: i.panels.map((g) => u.indexOf(g)),
526
- prevLayout: p,
513
+ const { group: a, groupSize: l } = i, { disableCursor: f, orientation: u, panels: m } = a;
514
+ let g = 0;
515
+ r ? u === "horizontal" ? g = (e.clientX - r.x) / l * 100 : g = (e.clientY - r.y) / l * 100 : u === "horizontal" ? g = e.clientX < 0 ? -100 : 100 : g = e.clientY < 0 ? -100 : 100;
516
+ const d = n.get(a), {
517
+ derivedPanelConstraints: p,
518
+ layout: v,
519
+ separatorToPanels: h
520
+ } = o.get(a) ?? {};
521
+ if (p && d && v && h) {
522
+ const x = B({
523
+ delta: g,
524
+ initialLayout: d,
525
+ panelConstraints: p,
526
+ pivotIndices: i.panels.map((S) => m.indexOf(S)),
527
+ prevLayout: v,
527
528
  trigger: "mouse-or-touch"
528
529
  });
529
- if (U(h, p)) {
530
- if (m !== 0 && !a)
531
- switch (f) {
530
+ if (U(x, v)) {
531
+ if (g !== 0 && !f)
532
+ switch (u) {
532
533
  case "horizontal": {
533
- s |= m < 0 ? Le : Pe;
534
+ s |= g < 0 ? Le : Pe;
534
535
  break;
535
536
  }
536
537
  case "vertical": {
537
- s |= m < 0 ? Ee : Re;
538
+ s |= g < 0 ? Ee : Re;
538
539
  break;
539
540
  }
540
541
  }
541
542
  } else {
542
543
  c.set(i.group, {
543
- derivedPanelConstraints: d,
544
- layout: h,
545
- separatorToPanels: v
544
+ derivedPanelConstraints: p,
545
+ layout: x,
546
+ separatorToPanels: h
546
547
  });
547
- const g = i.group.panels.map(({ id: x }) => x).join(",");
548
- i.group.inMemoryLayouts[g] = h;
548
+ const S = i.group.panels.map(({ id: y }) => y).join(",");
549
+ i.group.inMemoryLayouts[S] = x;
549
550
  }
550
551
  }
551
552
  }), C({
@@ -905,7 +906,7 @@ function it(e, t, n) {
905
906
  const r = e.panels.find((c) => c.element === t);
906
907
  if (!r || !r.onResize)
907
908
  return;
908
- const s = ae({ group: e });
909
+ const s = te({ group: e });
909
910
  r.onResize(
910
911
  {
911
912
  asPercentage: I(
@@ -924,24 +925,24 @@ function st(e) {
924
925
  );
925
926
  const n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), r = new ResizeObserver((u) => {
926
927
  for (const m of u) {
927
- const { borderBoxSize: S, target: d } = m;
928
+ const { borderBoxSize: g, target: d } = m;
928
929
  d === e.element ? t && C((p) => {
929
930
  const v = p.mountedGroups.get(e);
930
931
  if (v) {
931
- const h = pe(e), g = v.layout, x = $({
932
- layout: g,
932
+ const h = pe(e), x = v.layout, S = $({
933
+ layout: x,
933
934
  panelConstraints: h
934
935
  });
935
936
  return {
936
937
  mountedGroups: new Map(p.mountedGroups).set(e, {
937
938
  derivedPanelConstraints: h,
938
- layout: x,
939
+ layout: S,
939
940
  separatorToPanels: v.separatorToPanels
940
941
  })
941
942
  };
942
943
  }
943
944
  return p;
944
- }) : it(e, d, S);
945
+ }) : it(e, d, g);
945
946
  }
946
947
  });
947
948
  r.observe(e.element), e.panels.forEach((u) => {
@@ -969,12 +970,12 @@ function st(e) {
969
970
  ), o.add(u.id), u.element.addEventListener("keydown", ve);
970
971
  }), f.mountedGroups.size === 1 && (window.addEventListener("pointerdown", ge), window.addEventListener("pointermove", ye), window.addEventListener("pointerup", Se)), function() {
971
972
  t = !1;
972
- const m = C((S) => {
973
- const d = new Map(S.mountedGroups);
973
+ const m = C((g) => {
974
+ const d = new Map(g.mountedGroups);
974
975
  return d.delete(e), { mountedGroups: d };
975
976
  });
976
- e.element.removeEventListener("pointerleave", he), e.separators.forEach((S) => {
977
- S.element.removeEventListener("keydown", ve);
977
+ e.element.removeEventListener("pointerleave", he), e.separators.forEach((g) => {
978
+ g.element.removeEventListener("keydown", ve);
978
979
  }), m.mountedGroups.size === 0 && (window.removeEventListener("pointerdown", ge), window.removeEventListener("pointermove", ye), window.removeEventListener("pointerup", Se)), r.disconnect();
979
980
  };
980
981
  }
@@ -1038,19 +1039,19 @@ function ht({
1038
1039
  style: f,
1039
1040
  ...u
1040
1041
  }) {
1041
- const m = T({}), S = ue((b) => {
1042
+ const m = T({}), g = ue((b) => {
1042
1043
  U(m.current, b) || (m.current = b, a?.(b));
1043
- }), d = ce(i), [p, v] = G(!1), [h, g] = G(null), [x, y] = G(n ?? {}), [L, P] = G([]), [E, K] = G([]), te = T({}), V = T({}), X = fe(g, s);
1044
+ }), d = ce(i), [p, v] = G(!1), [h, x] = G(null), [S, y] = G(n ?? {}), [L, P] = G([]), [E, K] = G([]), ne = T({}), V = T({}), X = fe(x, s);
1044
1045
  rt(d, c);
1045
1046
  const Y = be(
1046
1047
  () => ({
1047
1048
  id: d,
1048
1049
  orientation: l,
1049
- registerPanel: (b) => (P((M) => se(l, [...M, b])), () => {
1050
+ registerPanel: (b) => (P((M) => re(l, [...M, b])), () => {
1050
1051
  P((M) => M.filter((N) => N !== b));
1051
1052
  }),
1052
1053
  registerSeparator: (b) => (K(
1053
- (M) => se(l, [...M, b])
1054
+ (M) => re(l, [...M, b])
1054
1055
  ), () => {
1055
1056
  K(
1056
1057
  (M) => M.filter((N) => N !== b)
@@ -1067,13 +1068,13 @@ function ht({
1067
1068
  disabled: !!r,
1068
1069
  element: h,
1069
1070
  id: d,
1070
- inMemoryLastExpandedPanelSizes: te.current,
1071
+ inMemoryLastExpandedPanelSizes: ne.current,
1071
1072
  inMemoryLayouts: V.current,
1072
1073
  orientation: l,
1073
1074
  panels: L,
1074
1075
  separators: E
1075
- }, M = st(b), ne = O().mountedGroups.get(b);
1076
- ne && (y(ne.layout), S?.(ne.layout));
1076
+ }, M = st(b), oe = O().mountedGroups.get(b);
1077
+ oe && (y(oe.layout), g?.(oe.layout));
1077
1078
  const De = A.addListener(
1078
1079
  "interactionStateChange",
1079
1080
  (Z) => {
@@ -1093,7 +1094,7 @@ function ht({
1093
1094
  "mountedGroupsChange",
1094
1095
  (Z) => {
1095
1096
  const _ = Z.get(b);
1096
- _ && _.derivedPanelConstraints.length > 0 && (y(_.layout), S?.(_.layout));
1097
+ _ && _.derivedPanelConstraints.length > 0 && (y(_.layout), g?.(_.layout));
1097
1098
  }
1098
1099
  );
1099
1100
  return () => {
@@ -1106,7 +1107,7 @@ function ht({
1106
1107
  r,
1107
1108
  h,
1108
1109
  d,
1109
- S,
1110
+ g,
1110
1111
  l,
1111
1112
  L,
1112
1113
  E
@@ -1114,8 +1115,8 @@ function ht({
1114
1115
  const q = {
1115
1116
  [ke]: p ? "none" : void 0
1116
1117
  };
1117
- for (const b in x) {
1118
- const M = Oe(d, b), N = x[b];
1118
+ for (const b in S) {
1119
+ const M = Oe(d, b), N = S[b];
1119
1120
  q[M] = N;
1120
1121
  }
1121
1122
  return /* @__PURE__ */ W(Te.Provider, { value: Y, children: /* @__PURE__ */ W(
@@ -1139,7 +1140,7 @@ function ht({
1139
1140
  }
1140
1141
  ) });
1141
1142
  }
1142
- function re(e) {
1143
+ function ae(e) {
1143
1144
  return `react-resizable-panels:${e}`;
1144
1145
  }
1145
1146
  function at({
@@ -1148,7 +1149,7 @@ function at({
1148
1149
  storage: n
1149
1150
  }) {
1150
1151
  try {
1151
- const o = re(e);
1152
+ const o = ae(e);
1152
1153
  n.setItem(o, JSON.stringify(t));
1153
1154
  } catch (o) {
1154
1155
  console.error(o);
@@ -1160,8 +1161,8 @@ function vt({
1160
1161
  }) {
1161
1162
  const n = He(
1162
1163
  lt,
1163
- () => t.getItem(re(e)),
1164
- () => t.getItem(re(e))
1164
+ () => t.getItem(ae(e)),
1165
+ () => t.getItem(ae(e))
1165
1166
  ), o = be(
1166
1167
  () => n ? JSON.parse(n) : void 0,
1167
1168
  [n]
@@ -1234,11 +1235,11 @@ function ct({
1234
1235
  group: f,
1235
1236
  layout: u,
1236
1237
  separatorToPanels: m
1237
- } = n(), S = f.panels.findIndex((h) => h.id === t), d = S === f.panels.length - 1, p = B({
1238
+ } = n(), g = f.panels.findIndex((h) => h.id === t), d = g === f.panels.length - 1, p = B({
1238
1239
  delta: d ? a - i : i - a,
1239
1240
  initialLayout: u,
1240
1241
  panelConstraints: l,
1241
- pivotIndices: d ? [S - 1, S] : [S, S + 1],
1242
+ pivotIndices: d ? [g - 1, g] : [g, g + 1],
1242
1243
  prevLayout: u,
1243
1244
  trigger: "imperative-api"
1244
1245
  }), v = $({
@@ -1278,7 +1279,7 @@ function ct({
1278
1279
  let l;
1279
1280
  switch (typeof i) {
1280
1281
  case "number": {
1281
- const { group: f } = n(), u = ae({ group: f });
1282
+ const { group: f } = n(), u = te({ group: f });
1282
1283
  l = I(i / u * 100);
1283
1284
  break;
1284
1285
  }
@@ -1294,14 +1295,14 @@ function ct({
1294
1295
  }
1295
1296
  function ut(e, t) {
1296
1297
  const { id: n } = de(), o = T({
1297
- collapse: oe,
1298
- expand: oe,
1298
+ collapse: ie,
1299
+ expand: ie,
1299
1300
  getSize: () => ({
1300
1301
  asPercentage: 0,
1301
1302
  inPixels: 0
1302
1303
  }),
1303
1304
  isCollapsed: () => !1,
1304
- resize: oe
1305
+ resize: ie
1305
1306
  });
1306
1307
  ze(t, () => o.current, []), H(() => {
1307
1308
  Object.assign(
@@ -1325,15 +1326,15 @@ function St({
1325
1326
  style: u,
1326
1327
  ...m
1327
1328
  }) {
1328
- const S = !!c, d = ce(c), [p, v] = G(null), h = fe(v, s), { id: g, registerPanel: x } = de(), y = l !== null, L = ue((E) => {
1329
+ const g = !!c, d = ce(c), [p, v] = G(null), h = fe(v, s), { id: x, registerPanel: S } = de(), y = l !== null, L = ue((E) => {
1329
1330
  l?.(E, c);
1330
1331
  });
1331
1332
  H(() => {
1332
1333
  if (p !== null)
1333
- return x({
1334
+ return S({
1334
1335
  element: p,
1335
1336
  id: d,
1336
- idIsStable: S,
1337
+ idIsStable: g,
1337
1338
  onResize: y ? L : void 0,
1338
1339
  panelConstraints: {
1339
1340
  collapsedSize: n,
@@ -1350,13 +1351,13 @@ function St({
1350
1351
  p,
1351
1352
  y,
1352
1353
  d,
1353
- S,
1354
+ g,
1354
1355
  i,
1355
1356
  a,
1356
1357
  L,
1357
- x
1358
+ S
1358
1359
  ]), ut(d, f);
1359
- const P = Oe(g, d);
1360
+ const P = Oe(x, d);
1360
1361
  return /* @__PURE__ */ W(
1361
1362
  "div",
1362
1363
  {
@@ -1462,22 +1463,22 @@ function bt({
1462
1463
  style: r,
1463
1464
  ...s
1464
1465
  }) {
1465
- const c = ce(o), [i, a] = G({}), [l, f] = G("inactive"), [u, m] = G(null), S = fe(m, n), {
1466
+ const c = ce(o), [i, a] = G({}), [l, f] = G("inactive"), [u, m] = G(null), g = fe(m, n), {
1466
1467
  id: d,
1467
1468
  orientation: p,
1468
1469
  registerSeparator: v
1469
1470
  } = de(), h = p === "horizontal" ? "vertical" : "horizontal";
1470
1471
  return H(() => {
1471
1472
  if (u !== null) {
1472
- const g = {
1473
+ const x = {
1473
1474
  element: u,
1474
1475
  id: c
1475
- }, x = v(g), y = A.addListener(
1476
+ }, S = v(x), y = A.addListener(
1476
1477
  "interactionStateChange",
1477
1478
  (P) => {
1478
1479
  f(
1479
1480
  P.state !== "inactive" && P.hitRegions.some(
1480
- (E) => E.separator === g
1481
+ (E) => E.separator === x
1481
1482
  ) ? P.state : "inactive"
1482
1483
  );
1483
1484
  }
@@ -1485,9 +1486,9 @@ function bt({
1485
1486
  "mountedGroupsChange",
1486
1487
  (P) => {
1487
1488
  P.forEach(
1488
- ({ derivedPanelConstraints: E, layout: K, separatorToPanels: te }, V) => {
1489
+ ({ derivedPanelConstraints: E, layout: K, separatorToPanels: ne }, V) => {
1489
1490
  if (V.id === d) {
1490
- const X = te.get(g);
1491
+ const X = ne.get(x);
1491
1492
  if (X) {
1492
1493
  const Y = X[0], q = V.panels.indexOf(Y);
1493
1494
  a(
@@ -1505,7 +1506,7 @@ function bt({
1505
1506
  }
1506
1507
  );
1507
1508
  return () => {
1508
- y(), L(), x();
1509
+ y(), L(), S();
1509
1510
  };
1510
1511
  }
1511
1512
  }, [u, d, c, v]), /* @__PURE__ */ W(
@@ -1522,7 +1523,7 @@ function bt({
1522
1523
  "data-separator": l,
1523
1524
  "data-testid": c,
1524
1525
  id: c,
1525
- ref: S,
1526
+ ref: g,
1526
1527
  role: "separator",
1527
1528
  style: {
1528
1529
  flexBasis: "auto",