@window-splitter/state 1.1.4 → 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/dist/commonjs/index.d.ts +9 -1
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +34 -2
- 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 +34 -2
- 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 +3 -3
- package/src/index.ts +38 -2
- package/src/machine.test.ts +229 -0
- package/src/test-utils.ts +7 -2
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": {
|
|
@@ -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.5--canary.f61d2d9.0",
|
|
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": "f61d2d9e76797f8d8a4061be8952e8ad6ca2f7be"
|
|
81
81
|
}
|
package/src/index.ts
CHANGED
|
@@ -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;
|
|
@@ -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,234 @@ 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
|
+
});
|
|
540
769
|
|
|
541
770
|
test("overflow measurements should not collapse panels during animation", async () => {
|
|
542
771
|
const actor = createActor({ 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,
|