@window-splitter/state 1.1.1 → 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 +31 -0
- package/dist/commonjs/index.d.ts +9 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +19 -5
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +9 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +19 -5
- package/dist/esm/index.js.map +1 -1
- package/package.json +19 -19
- package/src/index.ts +36 -6
- 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
|
@@ -290,6 +290,15 @@ interface ExpandPanelEvent extends ControlledCollapseToggle {
|
|
|
290
290
|
resolve?: () => void;
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
+
interface UpdateItemIndexEvent {
|
|
294
|
+
/** Update the index of a panel */
|
|
295
|
+
type: "updateItemIndex";
|
|
296
|
+
/** The panel to update */
|
|
297
|
+
itemId: string;
|
|
298
|
+
/** The new index of the panel */
|
|
299
|
+
index: number;
|
|
300
|
+
}
|
|
301
|
+
|
|
293
302
|
interface SetPanelPixelSizeEvent {
|
|
294
303
|
/**
|
|
295
304
|
* This event is used by the imperative panel API.
|
|
@@ -354,7 +363,8 @@ export type GroupMachineEvent =
|
|
|
354
363
|
| RebindPanelCallbacksEvent
|
|
355
364
|
| UpdateConstraintsEvent
|
|
356
365
|
| LockGroupEvent
|
|
357
|
-
| UnlockGroupEvent
|
|
366
|
+
| UnlockGroupEvent
|
|
367
|
+
| UpdateItemIndexEvent;
|
|
358
368
|
|
|
359
369
|
type EventForType<T extends GroupMachineEvent["type"]> = Extract<
|
|
360
370
|
GroupMachineEvent,
|
|
@@ -1175,7 +1185,11 @@ function updateLayout(
|
|
|
1175
1185
|
): Partial<GroupMachineContextValue> {
|
|
1176
1186
|
const handleIndex = getPanelHandleIndex(context, dragEvent.handleId);
|
|
1177
1187
|
const handle = context.items[handleIndex] as PanelHandleData;
|
|
1178
|
-
|
|
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];
|
|
1179
1193
|
|
|
1180
1194
|
let moveAmount =
|
|
1181
1195
|
context.orientation === "horizontal"
|
|
@@ -2042,6 +2056,13 @@ export function groupMachine(
|
|
|
2042
2056
|
}
|
|
2043
2057
|
|
|
2044
2058
|
switch (event.type) {
|
|
2059
|
+
case "updateItemIndex":
|
|
2060
|
+
context.items = sortWithOrder(
|
|
2061
|
+
context.items.map((item) =>
|
|
2062
|
+
item.id === event.itemId ? { ...item, order: event.index } : item
|
|
2063
|
+
)
|
|
2064
|
+
);
|
|
2065
|
+
break;
|
|
2045
2066
|
case "registerPanel":
|
|
2046
2067
|
context.items = addDeDuplicatedItems(context.items, {
|
|
2047
2068
|
type: "panel",
|
|
@@ -2079,11 +2100,20 @@ export function groupMachine(
|
|
|
2079
2100
|
event.data.collapsed &&
|
|
2080
2101
|
event.data.collapsedSize
|
|
2081
2102
|
) {
|
|
2082
|
-
currentValue =
|
|
2103
|
+
currentValue = {
|
|
2104
|
+
type: "pixel",
|
|
2105
|
+
value: getUnitPixelValue(context, event.data.collapsedSize),
|
|
2106
|
+
};
|
|
2083
2107
|
} else if (event.data.default) {
|
|
2084
|
-
currentValue =
|
|
2108
|
+
currentValue = {
|
|
2109
|
+
type: "pixel",
|
|
2110
|
+
value: getUnitPixelValue(context, event.data.default),
|
|
2111
|
+
};
|
|
2085
2112
|
} else {
|
|
2086
|
-
currentValue =
|
|
2113
|
+
currentValue = {
|
|
2114
|
+
type: "pixel",
|
|
2115
|
+
value: getUnitPixelValue(context, event.data.min),
|
|
2116
|
+
};
|
|
2087
2117
|
}
|
|
2088
2118
|
|
|
2089
2119
|
const newItems = addDeDuplicatedItems(context.items, {
|
|
@@ -2231,7 +2261,7 @@ export function groupMachine(
|
|
|
2231
2261
|
panel,
|
|
2232
2262
|
getUnitPixelValue(context, parseUnit(event.size))
|
|
2233
2263
|
);
|
|
2234
|
-
const isBigger = newSize
|
|
2264
|
+
const isBigger = newSize.gt(current);
|
|
2235
2265
|
const delta = isBigger
|
|
2236
2266
|
? newSize.minus(current)
|
|
2237
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",
|