@window-splitter/state 1.1.2 → 1.1.3
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/CHANGELOG.md +18 -0
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +4 -2
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +19 -19
- package/src/index.ts +6 -2
- package/src/machine.test.ts +73 -0
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.3",
|
|
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": {
|
|
@@ -19,29 +19,21 @@
|
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=18.0.0"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tshy",
|
|
24
|
-
"dev": "tshy -w",
|
|
25
|
-
"lint": "eslint .",
|
|
26
|
-
"test": "vitest",
|
|
27
|
-
"test:browser": "vitest",
|
|
28
|
-
"clean": "rm -rf dist .turbo .tshy .tshy-build"
|
|
29
|
-
},
|
|
30
22
|
"license": "MIT",
|
|
31
23
|
"devDependencies": {
|
|
32
|
-
"@internal/eslint-config": "1.1.
|
|
24
|
+
"@internal/eslint-config": "1.1.3",
|
|
33
25
|
"@testing-library/react": "^16.0.0",
|
|
34
26
|
"@types/big.js": "^6.2.2",
|
|
35
|
-
"@vitest/browser": "
|
|
36
|
-
"@vitest/coverage-istanbul": "
|
|
37
|
-
"eslint": "
|
|
27
|
+
"@vitest/browser": "^3.1.2",
|
|
28
|
+
"@vitest/coverage-istanbul": "^3.1.2",
|
|
29
|
+
"eslint": "^9.9.0",
|
|
38
30
|
"framer-motion": "^11.3.28",
|
|
39
31
|
"jsdom": "^24.1.1",
|
|
40
|
-
"playwright": "
|
|
32
|
+
"playwright": "^1.46.0",
|
|
41
33
|
"tiny-cookie": "^2.5.1",
|
|
42
|
-
"tshy": "
|
|
43
|
-
"typescript": "
|
|
44
|
-
"vitest": "
|
|
34
|
+
"tshy": "^3.0.2",
|
|
35
|
+
"typescript": "^5.5.4",
|
|
36
|
+
"vitest": "^3.1.2"
|
|
45
37
|
},
|
|
46
38
|
"dependencies": {
|
|
47
39
|
"big.js": "^6.2.1"
|
|
@@ -77,5 +69,13 @@
|
|
|
77
69
|
"window"
|
|
78
70
|
],
|
|
79
71
|
"types": "./dist/commonjs/index.d.ts",
|
|
80
|
-
"gitHead": "
|
|
81
|
-
|
|
72
|
+
"gitHead": "0fae9dff0a45d9423c1327667de042b70774b8bc",
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tshy",
|
|
75
|
+
"dev": "tshy -w",
|
|
76
|
+
"lint": "eslint .",
|
|
77
|
+
"test": "vitest",
|
|
78
|
+
"test:browser": "vitest",
|
|
79
|
+
"clean": "rm -rf dist .turbo .tshy .tshy-build"
|
|
80
|
+
}
|
|
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"
|
|
@@ -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,77 @@ 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
|
+
|
|
467
540
|
test("supports 1 panel being collapsed with another panel expanding to fill", () => {
|
|
468
541
|
const actor = createActor({
|
|
469
542
|
groupId: "group",
|