@window-splitter/state 1.1.3 → 1.1.5--canary.f61d2d9.0
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 +17 -0
- package/dist/commonjs/index.d.ts +9 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +36 -4
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/test-utils.d.ts +1 -1
- package/dist/commonjs/test-utils.d.ts.map +1 -1
- package/dist/commonjs/test-utils.js +2 -2
- package/dist/commonjs/test-utils.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 +36 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/test-utils.d.ts +1 -1
- package/dist/esm/test-utils.d.ts.map +1 -1
- package/dist/esm/test-utils.js +2 -2
- package/dist/esm/test-utils.js.map +1 -1
- package/package.json +19 -19
- package/src/index.ts +40 -4
- package/src/machine.test.ts +303 -0
- package/src/test-utils.ts +7 -2
- package/.turbo/turbo-lint.log +0 -18
- package/LICENSE +0 -7
package/dist/esm/test-utils.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export interface Actor {
|
|
|
6
6
|
current: State;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
export declare function createActor(input: Partial<GroupMachineContextValue>, onChange?: (context: GroupMachineContextValue) => void): Actor;
|
|
9
|
+
export declare function createActor(input: Partial<GroupMachineContextValue>, onChange?: (context: GroupMachineContextValue) => void, getGroupElement?: () => HTMLElement | null): Actor;
|
|
10
10
|
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACxB,MAAM,EACN,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,wBAAwB,CAAC;IAChC,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC;CAC3B;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,CAAC,wBAAwB,CAAC,EACxC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,wBAAwB,EACxB,MAAM,EACN,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,wBAAwB,CAAC;IAChC,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,CAAA;KAAE,CAAC;CAC3B;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,CAAC,wBAAwB,CAAC,EACxC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,EACtD,eAAe,CAAC,EAAE,MAAM,WAAW,GAAG,IAAI,GACzC,KAAK,CAYP"}
|
package/dist/esm/test-utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { groupMachine, } from "./index.js";
|
|
2
|
-
export function createActor(input, onChange) {
|
|
3
|
-
const [context, send, state] = groupMachine(input, onChange);
|
|
2
|
+
export function createActor(input, onChange, getGroupElement) {
|
|
3
|
+
const [context, send, state] = groupMachine(input, onChange, getGroupElement);
|
|
4
4
|
return {
|
|
5
5
|
send,
|
|
6
6
|
value: context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,YAAY,CAAC;AAQpB,MAAM,UAAU,WAAW,CACzB,KAAwC,EACxC,QAAsD;
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,YAAY,CAAC;AAQpB,MAAM,UAAU,WAAW,CACzB,KAAwC,EACxC,QAAsD,EACtD,eAA0C;IAE1C,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,YAAY,CACzC,KAAK,EACL,QAAQ,EACR,eAAe,CAChB,CAAC;IAEF,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,OAAO;QACd,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import {\n groupMachine,\n GroupMachineContextValue,\n SendFn,\n State,\n} from \"./index.js\";\n\nexport interface Actor {\n send: SendFn;\n value: GroupMachineContextValue;\n state: { current: State };\n}\n\nexport function createActor(\n input: Partial<GroupMachineContextValue>,\n onChange?: (context: GroupMachineContextValue) => void,\n getGroupElement?: () => HTMLElement | null\n): Actor {\n const [context, send, state] = groupMachine(\n input,\n onChange,\n getGroupElement\n );\n\n return {\n send,\n value: context,\n state,\n };\n}\n"]}
|
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.5--canary.f61d2d9.0",
|
|
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,21 +19,29 @@
|
|
|
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
|
+
},
|
|
22
30
|
"license": "MIT",
|
|
23
31
|
"devDependencies": {
|
|
24
|
-
"@internal/eslint-config": "1.1.
|
|
32
|
+
"@internal/eslint-config": "1.1.5--canary.f61d2d9.0",
|
|
25
33
|
"@testing-library/react": "^16.0.0",
|
|
26
34
|
"@types/big.js": "^6.2.2",
|
|
27
|
-
"@vitest/browser": "
|
|
28
|
-
"@vitest/coverage-istanbul": "
|
|
29
|
-
"eslint": "
|
|
35
|
+
"@vitest/browser": "catalog:",
|
|
36
|
+
"@vitest/coverage-istanbul": "catalog:",
|
|
37
|
+
"eslint": "catalog:",
|
|
30
38
|
"framer-motion": "^11.3.28",
|
|
31
39
|
"jsdom": "^24.1.1",
|
|
32
|
-
"playwright": "
|
|
40
|
+
"playwright": "catalog:",
|
|
33
41
|
"tiny-cookie": "^2.5.1",
|
|
34
|
-
"tshy": "
|
|
35
|
-
"typescript": "
|
|
36
|
-
"vitest": "
|
|
42
|
+
"tshy": "catalog:",
|
|
43
|
+
"typescript": "catalog:",
|
|
44
|
+
"vitest": "catalog:"
|
|
37
45
|
},
|
|
38
46
|
"dependencies": {
|
|
39
47
|
"big.js": "^6.2.1"
|
|
@@ -69,13 +77,5 @@
|
|
|
69
77
|
"window"
|
|
70
78
|
],
|
|
71
79
|
"types": "./dist/commonjs/index.d.ts",
|
|
72
|
-
"gitHead": "
|
|
73
|
-
|
|
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
|
-
}
|
|
80
|
+
"gitHead": "f61d2d9e76797f8d8a4061be8952e8ad6ca2f7be"
|
|
81
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1638,7 +1638,7 @@ function handleOverflow(context: GroupMachineContextValue) {
|
|
|
1638
1638
|
const totalSize = pixelItems.reduce((acc, i) => acc.add(i), new Big(0));
|
|
1639
1639
|
const overflow = totalSize.abs().sub(groupSize);
|
|
1640
1640
|
|
|
1641
|
-
if (overflow.
|
|
1641
|
+
if (overflow.abs().lt(1) || groupSize.eq(0)) {
|
|
1642
1642
|
return context;
|
|
1643
1643
|
}
|
|
1644
1644
|
|
|
@@ -1827,7 +1827,15 @@ let groupId = 0;
|
|
|
1827
1827
|
|
|
1828
1828
|
export function groupMachine(
|
|
1829
1829
|
input: Partial<GroupMachineContextValue>,
|
|
1830
|
-
onUpdate?: (context: GroupMachineContextValue) => void
|
|
1830
|
+
onUpdate?: (context: GroupMachineContextValue) => void,
|
|
1831
|
+
/**
|
|
1832
|
+
* A lazy getter for the group's DOM element. When provided and it returns
|
|
1833
|
+
* an element, `applyDelta` frames during collapse/expand animations write
|
|
1834
|
+
* the grid template directly to the DOM and skip `onUpdate` — avoiding a
|
|
1835
|
+
* full reactive re-render per animation frame. Other events still call
|
|
1836
|
+
* `onUpdate` as usual.
|
|
1837
|
+
*/
|
|
1838
|
+
getGroupElement?: () => HTMLElement | null
|
|
1831
1839
|
) {
|
|
1832
1840
|
const abortController = new AbortController();
|
|
1833
1841
|
const state = {
|
|
@@ -2042,6 +2050,8 @@ export function groupMachine(
|
|
|
2042
2050
|
}
|
|
2043
2051
|
|
|
2044
2052
|
function send(event: GroupMachineEvent) {
|
|
2053
|
+
let skipOnUpdate = false;
|
|
2054
|
+
|
|
2045
2055
|
switch (event.type) {
|
|
2046
2056
|
case "lockGroup":
|
|
2047
2057
|
locked = true;
|
|
@@ -2183,6 +2193,15 @@ export function groupMachine(
|
|
|
2183
2193
|
actions.onAutosave();
|
|
2184
2194
|
break;
|
|
2185
2195
|
case "setActualItemsSize": {
|
|
2196
|
+
// During direct-DOM animations the machine writes grid-template to the
|
|
2197
|
+
// DOM each frame, which causes panel sizes to change, which fires the
|
|
2198
|
+
// ResizeObserver in measureGroupChildren, which sends this event.
|
|
2199
|
+
// Ignore it so we don't trigger an onUpdate and re-render mid-animation.
|
|
2200
|
+
if (state.current === "togglingCollapse" && getGroupElement) {
|
|
2201
|
+
skipOnUpdate = true;
|
|
2202
|
+
break;
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2186
2205
|
const withLastKnownSize = context.items.map((i) => {
|
|
2187
2206
|
if (!isPanelData(i)) return i;
|
|
2188
2207
|
const lastKnownSize = event.childrenSizes[i.id] || i.lastKnownSize;
|
|
@@ -2216,7 +2235,7 @@ export function groupMachine(
|
|
|
2216
2235
|
context.items = withLastKnownSize;
|
|
2217
2236
|
} else if (
|
|
2218
2237
|
totalSize > getGroupSize(context) &&
|
|
2219
|
-
state.current
|
|
2238
|
+
state.current === "idle"
|
|
2220
2239
|
) {
|
|
2221
2240
|
context.items = handleOverflow({
|
|
2222
2241
|
...context,
|
|
@@ -2365,11 +2384,28 @@ export function groupMachine(
|
|
|
2365
2384
|
})
|
|
2366
2385
|
);
|
|
2367
2386
|
actions.onResize();
|
|
2387
|
+
|
|
2388
|
+
if (getGroupElement) {
|
|
2389
|
+
const el = getGroupElement();
|
|
2390
|
+
|
|
2391
|
+
if (el) {
|
|
2392
|
+
const template = buildTemplate(context);
|
|
2393
|
+
|
|
2394
|
+
if (context.orientation === "horizontal") {
|
|
2395
|
+
el.style.gridTemplateColumns = template;
|
|
2396
|
+
} else {
|
|
2397
|
+
el.style.gridTemplateRows = template;
|
|
2398
|
+
}
|
|
2399
|
+
skipOnUpdate = true;
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2368
2402
|
break;
|
|
2369
2403
|
}
|
|
2370
2404
|
}
|
|
2371
2405
|
|
|
2372
|
-
|
|
2406
|
+
if (!skipOnUpdate) {
|
|
2407
|
+
onUpdate?.(context);
|
|
2408
|
+
}
|
|
2373
2409
|
}
|
|
2374
2410
|
|
|
2375
2411
|
return [context, send, state] as const;
|
package/src/machine.test.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
getPanelGroupPixelSizes,
|
|
11
11
|
getPanelPercentageSize,
|
|
12
12
|
getPanelPixelSize,
|
|
13
|
+
GroupMachineContextValue,
|
|
13
14
|
GroupMachineEvent,
|
|
14
15
|
initializePanel,
|
|
15
16
|
initializePanelHandleData,
|
|
@@ -537,6 +538,308 @@ describe("constraints", () => {
|
|
|
537
538
|
await waitForIdle(actor);
|
|
538
539
|
});
|
|
539
540
|
|
|
541
|
+
describe("direct-DOM animation path (getGroupElement)", () => {
|
|
542
|
+
function setupCollapsibleActor(
|
|
543
|
+
groupEl: HTMLElement,
|
|
544
|
+
onUpdate?: (context: GroupMachineContextValue) => void
|
|
545
|
+
) {
|
|
546
|
+
return createActor(
|
|
547
|
+
{ groupId: "group" },
|
|
548
|
+
onUpdate,
|
|
549
|
+
() => groupEl
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function registerCollapsibleLayout(actor: Actor) {
|
|
554
|
+
sendAll(actor, [
|
|
555
|
+
{
|
|
556
|
+
type: "registerPanel",
|
|
557
|
+
data: initializePanel({ id: "panel-1" }),
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
type: "registerPanelHandle",
|
|
561
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
type: "registerPanel",
|
|
565
|
+
data: initializePanel({
|
|
566
|
+
id: "panel-2",
|
|
567
|
+
collapsible: true,
|
|
568
|
+
min: "100px",
|
|
569
|
+
default: "200px",
|
|
570
|
+
collapseAnimation: {
|
|
571
|
+
easing: "ease-in-out",
|
|
572
|
+
duration: 5000, // Long animation so we can intercept mid-flight
|
|
573
|
+
},
|
|
574
|
+
}),
|
|
575
|
+
},
|
|
576
|
+
]);
|
|
577
|
+
|
|
578
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
test("applyDelta writes grid template directly to the DOM element when getGroupElement is provided", async () => {
|
|
582
|
+
const groupEl = document.createElement("div");
|
|
583
|
+
groupEl.style.display = "grid";
|
|
584
|
+
document.body.appendChild(groupEl);
|
|
585
|
+
|
|
586
|
+
const actor = setupCollapsibleActor(groupEl);
|
|
587
|
+
registerCollapsibleLayout(actor);
|
|
588
|
+
|
|
589
|
+
const templateBefore = groupEl.style.gridTemplateColumns;
|
|
590
|
+
|
|
591
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
592
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
593
|
+
|
|
594
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
595
|
+
|
|
596
|
+
const templateAfter = groupEl.style.gridTemplateColumns;
|
|
597
|
+
expect(templateAfter).toBeTruthy();
|
|
598
|
+
expect(templateAfter).not.toEqual(templateBefore);
|
|
599
|
+
|
|
600
|
+
await waitForIdle(actor);
|
|
601
|
+
document.body.removeChild(groupEl);
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
test("onUpdate is NOT called during applyDelta when getGroupElement returns an element", async () => {
|
|
605
|
+
const groupEl = document.createElement("div");
|
|
606
|
+
document.body.appendChild(groupEl);
|
|
607
|
+
|
|
608
|
+
let updateCount = 0;
|
|
609
|
+
const actor = setupCollapsibleActor(groupEl, () => {
|
|
610
|
+
updateCount++;
|
|
611
|
+
});
|
|
612
|
+
registerCollapsibleLayout(actor);
|
|
613
|
+
|
|
614
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
615
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
616
|
+
|
|
617
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
618
|
+
// The collapsePanel event itself fires onUpdate (transition + prepare),
|
|
619
|
+
// but the per-frame applyDelta events do NOT.
|
|
620
|
+
const updatesAfterAnimationStarted = updateCount;
|
|
621
|
+
|
|
622
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
623
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
624
|
+
expect(updateCount).toBe(updatesAfterAnimationStarted);
|
|
625
|
+
|
|
626
|
+
await waitForIdle(actor);
|
|
627
|
+
document.body.removeChild(groupEl);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
test("onUpdate IS called after animation ends (final sync)", async () => {
|
|
631
|
+
const groupEl = document.createElement("div");
|
|
632
|
+
document.body.appendChild(groupEl);
|
|
633
|
+
|
|
634
|
+
let updateCount = 0;
|
|
635
|
+
const actor = setupCollapsibleActor(groupEl, () => {
|
|
636
|
+
updateCount++;
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
// Short animation so it completes quickly
|
|
640
|
+
sendAll(actor, [
|
|
641
|
+
{
|
|
642
|
+
type: "registerPanel",
|
|
643
|
+
data: initializePanel({ id: "panel-1" }),
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
type: "registerPanelHandle",
|
|
647
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
type: "registerPanel",
|
|
651
|
+
data: initializePanel({
|
|
652
|
+
id: "panel-2",
|
|
653
|
+
collapsible: true,
|
|
654
|
+
min: "100px",
|
|
655
|
+
default: "200px",
|
|
656
|
+
collapseAnimation: {
|
|
657
|
+
easing: "linear",
|
|
658
|
+
duration: 50,
|
|
659
|
+
},
|
|
660
|
+
}),
|
|
661
|
+
},
|
|
662
|
+
]);
|
|
663
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
664
|
+
|
|
665
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
666
|
+
await waitForIdle(actor);
|
|
667
|
+
|
|
668
|
+
expect(actor.state.current).toBe("idle");
|
|
669
|
+
expect(updateCount).toBeGreaterThan(0);
|
|
670
|
+
|
|
671
|
+
document.body.removeChild(groupEl);
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
test("behavior unchanged when getGroupElement is omitted (onUpdate fires per frame)", async () => {
|
|
675
|
+
let updateCount = 0;
|
|
676
|
+
const actor = createActor({ groupId: "group" }, () => {
|
|
677
|
+
updateCount++;
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
sendAll(actor, [
|
|
681
|
+
{
|
|
682
|
+
type: "registerPanel",
|
|
683
|
+
data: initializePanel({ id: "panel-1" }),
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
type: "registerPanelHandle",
|
|
687
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
type: "registerPanel",
|
|
691
|
+
data: initializePanel({
|
|
692
|
+
id: "panel-2",
|
|
693
|
+
collapsible: true,
|
|
694
|
+
min: "100px",
|
|
695
|
+
default: "200px",
|
|
696
|
+
collapseAnimation: {
|
|
697
|
+
easing: "ease-in-out",
|
|
698
|
+
duration: 5000,
|
|
699
|
+
},
|
|
700
|
+
}),
|
|
701
|
+
},
|
|
702
|
+
]);
|
|
703
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
704
|
+
|
|
705
|
+
const updatesBeforeAnimation = updateCount;
|
|
706
|
+
|
|
707
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
708
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
709
|
+
|
|
710
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
711
|
+
expect(updateCount).toBeGreaterThan(updatesBeforeAnimation);
|
|
712
|
+
|
|
713
|
+
await waitForIdle(actor);
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
test("onResize still fires each frame during applyDelta", async () => {
|
|
717
|
+
const groupEl = document.createElement("div");
|
|
718
|
+
document.body.appendChild(groupEl);
|
|
719
|
+
|
|
720
|
+
let resizeCount = 0;
|
|
721
|
+
const actor = createActor(
|
|
722
|
+
{ groupId: "group" },
|
|
723
|
+
() => {},
|
|
724
|
+
() => groupEl
|
|
725
|
+
);
|
|
726
|
+
|
|
727
|
+
sendAll(actor, [
|
|
728
|
+
{
|
|
729
|
+
type: "registerPanel",
|
|
730
|
+
data: initializePanel({
|
|
731
|
+
id: "panel-1",
|
|
732
|
+
}),
|
|
733
|
+
},
|
|
734
|
+
{
|
|
735
|
+
type: "registerPanelHandle",
|
|
736
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
type: "registerPanel",
|
|
740
|
+
data: initializePanel({
|
|
741
|
+
id: "panel-2",
|
|
742
|
+
collapsible: true,
|
|
743
|
+
min: "100px",
|
|
744
|
+
default: "200px",
|
|
745
|
+
collapseAnimation: {
|
|
746
|
+
easing: "ease-in-out",
|
|
747
|
+
duration: 5000,
|
|
748
|
+
},
|
|
749
|
+
onResize: {
|
|
750
|
+
current: () => {
|
|
751
|
+
resizeCount++;
|
|
752
|
+
},
|
|
753
|
+
},
|
|
754
|
+
}),
|
|
755
|
+
},
|
|
756
|
+
]);
|
|
757
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
758
|
+
|
|
759
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
760
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
761
|
+
|
|
762
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
763
|
+
expect(resizeCount).toBeGreaterThan(0);
|
|
764
|
+
|
|
765
|
+
await waitForIdle(actor);
|
|
766
|
+
document.body.removeChild(groupEl);
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
test("overflow measurements should not collapse panels during animation", async () => {
|
|
771
|
+
const actor = createActor({ groupId: "group" });
|
|
772
|
+
|
|
773
|
+
sendAll(actor, [
|
|
774
|
+
{
|
|
775
|
+
type: "registerPanel",
|
|
776
|
+
data: initializePanel({
|
|
777
|
+
id: "panel-1",
|
|
778
|
+
collapsible: true,
|
|
779
|
+
collapsedSize: "60px",
|
|
780
|
+
default: "140px",
|
|
781
|
+
}),
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
type: "registerPanelHandle",
|
|
785
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
type: "registerPanel",
|
|
789
|
+
data: initializePanel({
|
|
790
|
+
id: "panel-2",
|
|
791
|
+
collapsible: true,
|
|
792
|
+
default: "140px",
|
|
793
|
+
collapseAnimation: {
|
|
794
|
+
easing: "ease-in-out",
|
|
795
|
+
duration: 500,
|
|
796
|
+
},
|
|
797
|
+
}),
|
|
798
|
+
},
|
|
799
|
+
]);
|
|
800
|
+
|
|
801
|
+
actor.send({
|
|
802
|
+
type: "setSize",
|
|
803
|
+
size: { width: 300, height: 200 },
|
|
804
|
+
});
|
|
805
|
+
actor.send({
|
|
806
|
+
type: "setActualItemsSize",
|
|
807
|
+
childrenSizes: {
|
|
808
|
+
"panel-1": { width: 140, height: 200 },
|
|
809
|
+
"panel-2": { width: 140, height: 200 },
|
|
810
|
+
},
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
const panelBefore = actor.value.items.find(
|
|
814
|
+
(item) => isPanelData(item) && item.id === "panel-1"
|
|
815
|
+
);
|
|
816
|
+
expect(panelBefore?.collapsed).toBe(false);
|
|
817
|
+
|
|
818
|
+
actor.send({
|
|
819
|
+
type: "collapsePanel",
|
|
820
|
+
panelId: "panel-2",
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
824
|
+
|
|
825
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
826
|
+
|
|
827
|
+
actor.send({
|
|
828
|
+
type: "setActualItemsSize",
|
|
829
|
+
childrenSizes: {
|
|
830
|
+
"panel-1": { width: 200, height: 200 },
|
|
831
|
+
"panel-2": { width: 200, height: 200 },
|
|
832
|
+
},
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
const panelAfter = actor.value.items.find(
|
|
836
|
+
(item) => isPanelData(item) && item.id === "panel-1"
|
|
837
|
+
);
|
|
838
|
+
expect(panelAfter?.collapsed).toBe(false);
|
|
839
|
+
|
|
840
|
+
await waitForIdle(actor);
|
|
841
|
+
});
|
|
842
|
+
|
|
540
843
|
test("supports 1 panel being collapsed with another panel expanding to fill", () => {
|
|
541
844
|
const actor = createActor({
|
|
542
845
|
groupId: "group",
|
package/src/test-utils.ts
CHANGED
|
@@ -13,9 +13,14 @@ export interface Actor {
|
|
|
13
13
|
|
|
14
14
|
export function createActor(
|
|
15
15
|
input: Partial<GroupMachineContextValue>,
|
|
16
|
-
onChange?: (context: GroupMachineContextValue) => void
|
|
16
|
+
onChange?: (context: GroupMachineContextValue) => void,
|
|
17
|
+
getGroupElement?: () => HTMLElement | null
|
|
17
18
|
): Actor {
|
|
18
|
-
const [context, send, state] = groupMachine(
|
|
19
|
+
const [context, send, state] = groupMachine(
|
|
20
|
+
input,
|
|
21
|
+
onChange,
|
|
22
|
+
getGroupElement
|
|
23
|
+
);
|
|
19
24
|
|
|
20
25
|
return {
|
|
21
26
|
send,
|
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.
|