@window-splitter/state 1.1.2 → 1.1.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +24 -52
- package/CHANGELOG.md +35 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +6 -4
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +8 -4
- package/src/machine.test.ts +147 -0
- package/.turbo/turbo-lint.log +0 -18
- package/LICENSE +0 -7
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@window-splitter/state",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.4",
|
|
6
6
|
"description": "A state machine for a WAI-ARIA compliant window splitter",
|
|
7
7
|
"homepage": "https://react-window-splitter-six.vercel.app",
|
|
8
8
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@internal/eslint-config": "1.1.
|
|
32
|
+
"@internal/eslint-config": "1.1.4",
|
|
33
33
|
"@testing-library/react": "^16.0.0",
|
|
34
34
|
"@types/big.js": "^6.2.2",
|
|
35
35
|
"@vitest/browser": "catalog:",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"window"
|
|
78
78
|
],
|
|
79
79
|
"types": "./dist/commonjs/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "df18ce3b7488d52f8d91ae7000f5dcaec65f6bdd"
|
|
81
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -1185,7 +1185,11 @@ function updateLayout(
|
|
|
1185
1185
|
): Partial<GroupMachineContextValue> {
|
|
1186
1186
|
const handleIndex = getPanelHandleIndex(context, dragEvent.handleId);
|
|
1187
1187
|
const handle = context.items[handleIndex] as PanelHandleData;
|
|
1188
|
-
|
|
1188
|
+
// Check if items need to be prepared (have non-pixel values)
|
|
1189
|
+
const needsPrepare = context.items.some(
|
|
1190
|
+
(item) => isPanelData(item) && item.currentValue.type !== "pixel"
|
|
1191
|
+
);
|
|
1192
|
+
const newItems = needsPrepare ? prepareItems(context) : [...context.items];
|
|
1189
1193
|
|
|
1190
1194
|
let moveAmount =
|
|
1191
1195
|
context.orientation === "horizontal"
|
|
@@ -1634,7 +1638,7 @@ function handleOverflow(context: GroupMachineContextValue) {
|
|
|
1634
1638
|
const totalSize = pixelItems.reduce((acc, i) => acc.add(i), new Big(0));
|
|
1635
1639
|
const overflow = totalSize.abs().sub(groupSize);
|
|
1636
1640
|
|
|
1637
|
-
if (overflow.
|
|
1641
|
+
if (overflow.abs().lt(1) || groupSize.eq(0)) {
|
|
1638
1642
|
return context;
|
|
1639
1643
|
}
|
|
1640
1644
|
|
|
@@ -2212,7 +2216,7 @@ export function groupMachine(
|
|
|
2212
2216
|
context.items = withLastKnownSize;
|
|
2213
2217
|
} else if (
|
|
2214
2218
|
totalSize > getGroupSize(context) &&
|
|
2215
|
-
state.current
|
|
2219
|
+
state.current === "idle"
|
|
2216
2220
|
) {
|
|
2217
2221
|
context.items = handleOverflow({
|
|
2218
2222
|
...context,
|
|
@@ -2257,7 +2261,7 @@ export function groupMachine(
|
|
|
2257
2261
|
panel,
|
|
2258
2262
|
getUnitPixelValue(context, parseUnit(event.size))
|
|
2259
2263
|
);
|
|
2260
|
-
const isBigger = newSize
|
|
2264
|
+
const isBigger = newSize.gt(current);
|
|
2261
2265
|
const delta = isBigger
|
|
2262
2266
|
? newSize.minus(current)
|
|
2263
2267
|
: current.minus(newSize);
|
package/src/machine.test.ts
CHANGED
|
@@ -13,9 +13,11 @@ import {
|
|
|
13
13
|
GroupMachineEvent,
|
|
14
14
|
initializePanel,
|
|
15
15
|
initializePanelHandleData,
|
|
16
|
+
isPanelData,
|
|
16
17
|
isPanelHandle,
|
|
17
18
|
prepareSnapshot,
|
|
18
19
|
} from "./index.js";
|
|
20
|
+
import Big from "big.js";
|
|
19
21
|
import { spring } from "framer-motion";
|
|
20
22
|
import * as Cookies from "tiny-cookie";
|
|
21
23
|
import { Actor, createActor } from "./test-utils.js";
|
|
@@ -464,6 +466,151 @@ describe("constraints", () => {
|
|
|
464
466
|
});
|
|
465
467
|
});
|
|
466
468
|
|
|
469
|
+
// Test for https://github.com/hipstersmoothie/window-splitter/issues/79
|
|
470
|
+
// The bug: applyDelta in togglingCollapse state calls updateLayout without
|
|
471
|
+
// ensuring items are in pixel format first. If items somehow end up in
|
|
472
|
+
// percentage format during the animation, it fails.
|
|
473
|
+
test("applyDelta should handle percentage format items during animation", async () => {
|
|
474
|
+
const actor = createActor({ groupId: "group" });
|
|
475
|
+
|
|
476
|
+
sendAll(actor, [
|
|
477
|
+
{ type: "registerPanel", data: initializePanel({ id: "panel-1" }) },
|
|
478
|
+
{
|
|
479
|
+
type: "registerPanelHandle",
|
|
480
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: "registerPanel",
|
|
484
|
+
data: initializePanel({
|
|
485
|
+
id: "panel-2",
|
|
486
|
+
collapsible: true,
|
|
487
|
+
min: "100px",
|
|
488
|
+
default: "200px",
|
|
489
|
+
collapseAnimation: {
|
|
490
|
+
easing: "ease-in-out",
|
|
491
|
+
duration: 5000, // Long animation so we can intercept
|
|
492
|
+
},
|
|
493
|
+
}),
|
|
494
|
+
},
|
|
495
|
+
]);
|
|
496
|
+
|
|
497
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
498
|
+
|
|
499
|
+
// Start the collapse animation - this transitions to togglingCollapse
|
|
500
|
+
actor.send({
|
|
501
|
+
type: "collapsePanel",
|
|
502
|
+
panelId: "panel-2",
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// Wait a tick for the animation to start
|
|
506
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
507
|
+
|
|
508
|
+
// Verify we're in togglingCollapse state
|
|
509
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
510
|
+
|
|
511
|
+
// Now simulate a scenario where items got back into percentage format
|
|
512
|
+
// (e.g., from autosave restoration or some edge case)
|
|
513
|
+
const groupSize = 500;
|
|
514
|
+
const staticWidth = 10;
|
|
515
|
+
const availableSpace = groupSize - staticWidth;
|
|
516
|
+
|
|
517
|
+
for (const item of actor.value.items) {
|
|
518
|
+
if (isPanelData(item) && !item.collapsed) {
|
|
519
|
+
const pixelValue = item.currentValue.value.toNumber();
|
|
520
|
+
item.currentValue = {
|
|
521
|
+
type: "percent",
|
|
522
|
+
value: new Big(pixelValue).div(availableSpace),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Send an applyDelta event - this is what the animation actor sends
|
|
528
|
+
// Before the fix, this should throw because updateLayout is called
|
|
529
|
+
// with percentage items
|
|
530
|
+
actor.send({
|
|
531
|
+
type: "applyDelta",
|
|
532
|
+
handleId: "resizer-1",
|
|
533
|
+
panelId: "panel-2",
|
|
534
|
+
delta: 10,
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
await waitForIdle(actor);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
test("overflow measurements should not collapse panels during animation", async () => {
|
|
542
|
+
const actor = createActor({ groupId: "group" });
|
|
543
|
+
|
|
544
|
+
sendAll(actor, [
|
|
545
|
+
{
|
|
546
|
+
type: "registerPanel",
|
|
547
|
+
data: initializePanel({
|
|
548
|
+
id: "panel-1",
|
|
549
|
+
collapsible: true,
|
|
550
|
+
collapsedSize: "60px",
|
|
551
|
+
default: "140px",
|
|
552
|
+
}),
|
|
553
|
+
},
|
|
554
|
+
{
|
|
555
|
+
type: "registerPanelHandle",
|
|
556
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
type: "registerPanel",
|
|
560
|
+
data: initializePanel({
|
|
561
|
+
id: "panel-2",
|
|
562
|
+
collapsible: true,
|
|
563
|
+
default: "140px",
|
|
564
|
+
collapseAnimation: {
|
|
565
|
+
easing: "ease-in-out",
|
|
566
|
+
duration: 500,
|
|
567
|
+
},
|
|
568
|
+
}),
|
|
569
|
+
},
|
|
570
|
+
]);
|
|
571
|
+
|
|
572
|
+
actor.send({
|
|
573
|
+
type: "setSize",
|
|
574
|
+
size: { width: 300, height: 200 },
|
|
575
|
+
});
|
|
576
|
+
actor.send({
|
|
577
|
+
type: "setActualItemsSize",
|
|
578
|
+
childrenSizes: {
|
|
579
|
+
"panel-1": { width: 140, height: 200 },
|
|
580
|
+
"panel-2": { width: 140, height: 200 },
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
const panelBefore = actor.value.items.find(
|
|
585
|
+
(item) => isPanelData(item) && item.id === "panel-1"
|
|
586
|
+
);
|
|
587
|
+
expect(panelBefore?.collapsed).toBe(false);
|
|
588
|
+
|
|
589
|
+
actor.send({
|
|
590
|
+
type: "collapsePanel",
|
|
591
|
+
panelId: "panel-2",
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
595
|
+
|
|
596
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
597
|
+
|
|
598
|
+
actor.send({
|
|
599
|
+
type: "setActualItemsSize",
|
|
600
|
+
childrenSizes: {
|
|
601
|
+
"panel-1": { width: 200, height: 200 },
|
|
602
|
+
"panel-2": { width: 200, height: 200 },
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
const panelAfter = actor.value.items.find(
|
|
607
|
+
(item) => isPanelData(item) && item.id === "panel-1"
|
|
608
|
+
);
|
|
609
|
+
expect(panelAfter?.collapsed).toBe(false);
|
|
610
|
+
|
|
611
|
+
await waitForIdle(actor);
|
|
612
|
+
});
|
|
613
|
+
|
|
467
614
|
test("supports 1 panel being collapsed with another panel expanding to fill", () => {
|
|
468
615
|
const actor = createActor({
|
|
469
616
|
groupId: "group",
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
> @window-splitter/state@1.1.0 lint /Users/alisowski/Documents/react-window-splitter/packages/state
|
|
4
|
-
> eslint .
|
|
5
|
-
|
|
6
|
-
=============
|
|
7
|
-
|
|
8
|
-
WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.
|
|
9
|
-
|
|
10
|
-
You may find that it works just fine, or you may not.
|
|
11
|
-
|
|
12
|
-
SUPPORTED TYPESCRIPT VERSIONS: >=4.7.4 <5.6.0
|
|
13
|
-
|
|
14
|
-
YOUR TYPESCRIPT VERSION: 5.8.3
|
|
15
|
-
|
|
16
|
-
Please only submit bug reports when using the officially supported version.
|
|
17
|
-
|
|
18
|
-
=============
|
package/LICENSE
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright 2025 Andrew Lisowski
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|