@window-splitter/state 0.8.3 → 0.8.5

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.
package/src/index.ts CHANGED
@@ -530,8 +530,12 @@ function eq(a: ParsedUnit, b: ParsedUnit) {
530
530
 
531
531
  export function haveConstraintsChangedForPanel(
532
532
  a: Omit<PanelData, "id" | "currentValue">,
533
- b: Omit<PanelData, "id" | "currentValue">
533
+ b?: Omit<PanelData, "id" | "currentValue">
534
534
  ) {
535
+ if (!b) {
536
+ return true;
537
+ }
538
+
535
539
  if (!eq(a.min, b.min)) {
536
540
  return true;
537
541
  }
@@ -583,8 +587,12 @@ export function haveConstraintsChangedForPanel(
583
587
 
584
588
  export function haveConstraintsChangedForPanelHandle(
585
589
  a: Omit<PanelHandleData, "id">,
586
- b: Omit<PanelHandleData, "id">
590
+ b?: Omit<PanelHandleData, "id">
587
591
  ) {
592
+ if (!b) {
593
+ return true;
594
+ }
595
+
588
596
  if (!eq(a.size, b.size)) {
589
597
  return true;
590
598
  }
@@ -1090,6 +1098,7 @@ function updateLayout(
1090
1098
  | (DragHandleEvent & {
1091
1099
  controlled?: boolean;
1092
1100
  disregardCollapseBuffer?: never;
1101
+ isVirtual?: boolean;
1093
1102
  })
1094
1103
  | {
1095
1104
  type: "collapsePanel";
@@ -1097,6 +1106,7 @@ function updateLayout(
1097
1106
  handleId: string;
1098
1107
  controlled?: boolean;
1099
1108
  disregardCollapseBuffer?: boolean;
1109
+ isVirtual?: boolean;
1100
1110
  }
1101
1111
  ): Partial<GroupMachineContextValue> {
1102
1112
  const handleIndex = getPanelHandleIndex(context, dragEvent.handleId);
@@ -1239,7 +1249,8 @@ function updateLayout(
1239
1249
  if (
1240
1250
  panelAfter.onCollapseChange?.current &&
1241
1251
  panelAfter.collapseIsControlled &&
1242
- !dragEvent.controlled
1252
+ !dragEvent.controlled &&
1253
+ !dragEvent.isVirtual
1243
1254
  ) {
1244
1255
  panelAfter.onCollapseChange.current(false);
1245
1256
  return { dragOvershoot: newDragOvershoot };
@@ -1281,7 +1292,8 @@ function updateLayout(
1281
1292
  if (
1282
1293
  panelAfter.onCollapseChange?.current &&
1283
1294
  !panelAfter.collapseIsControlled &&
1284
- !dragEvent.controlled
1295
+ !dragEvent.controlled &&
1296
+ !dragEvent.isVirtual
1285
1297
  ) {
1286
1298
  panelAfter.onCollapseChange.current(false);
1287
1299
  }
@@ -1300,7 +1312,8 @@ function updateLayout(
1300
1312
  if (
1301
1313
  panelBefore.onCollapseChange?.current &&
1302
1314
  panelBefore.collapseIsControlled &&
1303
- !dragEvent.controlled
1315
+ !dragEvent.controlled &&
1316
+ !dragEvent.isVirtual
1304
1317
  ) {
1305
1318
  panelBefore.onCollapseChange.current(true);
1306
1319
  return { dragOvershoot: newDragOvershoot };
@@ -1317,7 +1330,8 @@ function updateLayout(
1317
1330
  if (
1318
1331
  panelBefore.onCollapseChange?.current &&
1319
1332
  !panelBefore.collapseIsControlled &&
1320
- !dragEvent.controlled
1333
+ !dragEvent.controlled &&
1334
+ !dragEvent.isVirtual
1321
1335
  ) {
1322
1336
  panelBefore.onCollapseChange.current(true);
1323
1337
  }
@@ -1412,6 +1426,7 @@ function iterativelyUpdateLayout({
1412
1426
  direction,
1413
1427
  controlled,
1414
1428
  disregardCollapseBuffer,
1429
+ isVirtual,
1415
1430
  }: {
1416
1431
  context: GroupMachineContextValue;
1417
1432
  handleId: string;
@@ -1419,6 +1434,11 @@ function iterativelyUpdateLayout({
1419
1434
  direction: -1 | 1;
1420
1435
  controlled?: boolean;
1421
1436
  disregardCollapseBuffer?: boolean;
1437
+ /**
1438
+ * Whether this is just a calculation and not intended to be commmited to layout
1439
+ * no on* callbacks will be called
1440
+ */
1441
+ isVirtual?: boolean;
1422
1442
  }) {
1423
1443
  let newContext: Partial<GroupMachineContextValue> = context;
1424
1444
 
@@ -1433,6 +1453,7 @@ function iterativelyUpdateLayout({
1433
1453
  type: "collapsePanel",
1434
1454
  controlled,
1435
1455
  disregardCollapseBuffer,
1456
+ isVirtual,
1436
1457
  value: dragHandlePayload({
1437
1458
  delta: direction,
1438
1459
  orientation: context.orientation,
@@ -1799,6 +1820,10 @@ export function groupMachine(
1799
1820
  panel.currentValue = panel.collapsedSize;
1800
1821
  }
1801
1822
 
1823
+ if (!panel.collapseIsControlled) {
1824
+ panel.onCollapseChange?.current?.(panel.collapsed);
1825
+ }
1826
+
1802
1827
  actions.commit();
1803
1828
  },
1804
1829
  };
@@ -1831,6 +1856,7 @@ export function groupMachine(
1831
1856
  controlled: event.controlled,
1832
1857
  delta: delta,
1833
1858
  direction: handle.direction,
1859
+ isVirtual: true,
1834
1860
  }),
1835
1861
  };
1836
1862
  const updatedPanel = interimContext.items.find(
@@ -2033,7 +2059,10 @@ export function groupMachine(
2033
2059
 
2034
2060
  if (useLastKnownSize) {
2035
2061
  context.items = withLastKnownSize;
2036
- } else if (totalSize > getGroupSize(context)) {
2062
+ } else if (
2063
+ totalSize > getGroupSize(context) &&
2064
+ state.current !== "dragging"
2065
+ ) {
2037
2066
  context.items = handleOverflow({
2038
2067
  ...context,
2039
2068
  items: prepareItems({ ...context, items: withLastKnownSize }),