@window-splitter/state 0.8.3 → 0.8.4

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
  }
@@ -670,7 +676,8 @@ function updateLayout(context, dragEvent) {
670
676
  panelAfter.collapsed = false;
671
677
  if (panelAfter.onCollapseChange?.current &&
672
678
  !panelAfter.collapseIsControlled &&
673
- !dragEvent.controlled) {
679
+ !dragEvent.controlled &&
680
+ !dragEvent.isVirtual) {
674
681
  panelAfter.onCollapseChange.current(false);
675
682
  }
676
683
  }
@@ -692,7 +699,8 @@ function updateLayout(context, dragEvent) {
692
699
  panelAfterNewValue = panelAfterNewValue.add(panelBeforePreviousValue.minus(panelBeforeNewValue));
693
700
  if (panelBefore.onCollapseChange?.current &&
694
701
  !panelBefore.collapseIsControlled &&
695
- !dragEvent.controlled) {
702
+ !dragEvent.controlled &&
703
+ !dragEvent.isVirtual) {
696
704
  panelBefore.onCollapseChange.current(true);
697
705
  }
698
706
  }
@@ -747,7 +755,7 @@ export function dragHandlePayload({ delta, orientation = "horizontal", shiftKey
747
755
  };
748
756
  }
749
757
  /** Iteratively applies a large delta value simulating a user's drag */
750
- function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, }) {
758
+ function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, isVirtual, }) {
751
759
  let newContext = context;
752
760
  for (let i = 0; i < delta.abs().toNumber(); i++) {
753
761
  newContext = updateLayout({
@@ -758,6 +766,7 @@ function iterativelyUpdateLayout({ context, handleId, delta, direction, controll
758
766
  type: "collapsePanel",
759
767
  controlled,
760
768
  disregardCollapseBuffer,
769
+ isVirtual,
761
770
  value: dragHandlePayload({
762
771
  delta: direction,
763
772
  orientation: context.orientation,
@@ -1006,6 +1015,9 @@ export function groupMachine(input, onUpdate) {
1006
1015
  if (panel.collapsed) {
1007
1016
  panel.currentValue = panel.collapsedSize;
1008
1017
  }
1018
+ if (!panel.collapseIsControlled) {
1019
+ panel.onCollapseChange?.current?.(panel.collapsed);
1020
+ }
1009
1021
  actions.commit();
1010
1022
  },
1011
1023
  };
@@ -1035,6 +1047,7 @@ export function groupMachine(input, onUpdate) {
1035
1047
  controlled: event.controlled,
1036
1048
  delta: delta,
1037
1049
  direction: handle.direction,
1050
+ isVirtual: true,
1038
1051
  }),
1039
1052
  };
1040
1053
  const updatedPanel = interimContext.items.find((i) => i.id === event.panelId);
@@ -1203,7 +1216,8 @@ export function groupMachine(input, onUpdate) {
1203
1216
  if (useLastKnownSize) {
1204
1217
  context.items = withLastKnownSize;
1205
1218
  }
1206
- else if (totalSize > getGroupSize(context)) {
1219
+ else if (totalSize > getGroupSize(context) &&
1220
+ state.current !== "dragging") {
1207
1221
  context.items = handleOverflow({
1208
1222
  ...context,
1209
1223
  items: prepareItems({ ...context, items: withLastKnownSize }),