@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/dist/esm/index.js CHANGED
@@ -154,6 +154,9 @@ function eq(a, b) {
154
154
  return a.type === b.type && a.value.eq(b.value);
155
155
  }
156
156
  export function haveConstraintsChangedForPanel(a, b) {
157
+ if (!b) {
158
+ return true;
159
+ }
157
160
  if (!eq(a.min, b.min)) {
158
161
  return true;
159
162
  }
@@ -190,6 +193,9 @@ export function haveConstraintsChangedForPanel(a, b) {
190
193
  return false;
191
194
  }
192
195
  export function haveConstraintsChangedForPanelHandle(a, b) {
196
+ if (!b) {
197
+ return true;
198
+ }
193
199
  if (!eq(a.size, b.size)) {
194
200
  return true;
195
201
  }
@@ -640,7 +646,8 @@ function updateLayout(context, dragEvent) {
640
646
  else if (panelAfter.collapsible && panelAfter.collapsed) {
641
647
  if (panelAfter.onCollapseChange?.current &&
642
648
  panelAfter.collapseIsControlled &&
643
- !dragEvent.controlled) {
649
+ !dragEvent.controlled &&
650
+ !dragEvent.isVirtual) {
644
651
  panelAfter.onCollapseChange.current(false);
645
652
  return { dragOvershoot: newDragOvershoot };
646
653
  }
@@ -670,7 +677,8 @@ function updateLayout(context, dragEvent) {
670
677
  panelAfter.collapsed = false;
671
678
  if (panelAfter.onCollapseChange?.current &&
672
679
  !panelAfter.collapseIsControlled &&
673
- !dragEvent.controlled) {
680
+ !dragEvent.controlled &&
681
+ !dragEvent.isVirtual) {
674
682
  panelAfter.onCollapseChange.current(false);
675
683
  }
676
684
  }
@@ -681,7 +689,8 @@ function updateLayout(context, dragEvent) {
681
689
  panelBeforeIsAboutToCollapse) {
682
690
  if (panelBefore.onCollapseChange?.current &&
683
691
  panelBefore.collapseIsControlled &&
684
- !dragEvent.controlled) {
692
+ !dragEvent.controlled &&
693
+ !dragEvent.isVirtual) {
685
694
  panelBefore.onCollapseChange.current(true);
686
695
  return { dragOvershoot: newDragOvershoot };
687
696
  }
@@ -692,7 +701,8 @@ function updateLayout(context, dragEvent) {
692
701
  panelAfterNewValue = panelAfterNewValue.add(panelBeforePreviousValue.minus(panelBeforeNewValue));
693
702
  if (panelBefore.onCollapseChange?.current &&
694
703
  !panelBefore.collapseIsControlled &&
695
- !dragEvent.controlled) {
704
+ !dragEvent.controlled &&
705
+ !dragEvent.isVirtual) {
696
706
  panelBefore.onCollapseChange.current(true);
697
707
  }
698
708
  }
@@ -747,7 +757,7 @@ export function dragHandlePayload({ delta, orientation = "horizontal", shiftKey
747
757
  };
748
758
  }
749
759
  /** Iteratively applies a large delta value simulating a user's drag */
750
- function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, }) {
760
+ function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, isVirtual, }) {
751
761
  let newContext = context;
752
762
  for (let i = 0; i < delta.abs().toNumber(); i++) {
753
763
  newContext = updateLayout({
@@ -758,6 +768,7 @@ function iterativelyUpdateLayout({ context, handleId, delta, direction, controll
758
768
  type: "collapsePanel",
759
769
  controlled,
760
770
  disregardCollapseBuffer,
771
+ isVirtual,
761
772
  value: dragHandlePayload({
762
773
  delta: direction,
763
774
  orientation: context.orientation,
@@ -1006,6 +1017,9 @@ export function groupMachine(input, onUpdate) {
1006
1017
  if (panel.collapsed) {
1007
1018
  panel.currentValue = panel.collapsedSize;
1008
1019
  }
1020
+ if (!panel.collapseIsControlled) {
1021
+ panel.onCollapseChange?.current?.(panel.collapsed);
1022
+ }
1009
1023
  actions.commit();
1010
1024
  },
1011
1025
  };
@@ -1035,6 +1049,7 @@ export function groupMachine(input, onUpdate) {
1035
1049
  controlled: event.controlled,
1036
1050
  delta: delta,
1037
1051
  direction: handle.direction,
1052
+ isVirtual: true,
1038
1053
  }),
1039
1054
  };
1040
1055
  const updatedPanel = interimContext.items.find((i) => i.id === event.panelId);
@@ -1203,7 +1218,8 @@ export function groupMachine(input, onUpdate) {
1203
1218
  if (useLastKnownSize) {
1204
1219
  context.items = withLastKnownSize;
1205
1220
  }
1206
- else if (totalSize > getGroupSize(context)) {
1221
+ else if (totalSize > getGroupSize(context) &&
1222
+ state.current !== "dragging") {
1207
1223
  context.items = handleOverflow({
1208
1224
  ...context,
1209
1225
  items: prepareItems({ ...context, items: withLastKnownSize }),