@window-splitter/state 1.1.4 → 1.1.5--canary.b95ee23.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 +62 -5
- 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 +62 -5
- 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 +65 -6
- package/src/machine.test.ts +257 -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.b95ee23.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.b95ee23.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": "b95ee239cfc6749ef5619a24971ec4e6031b659f"
|
|
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 = {
|
|
@@ -2013,7 +2021,7 @@ export function groupMachine(
|
|
|
2013
2021
|
},
|
|
2014
2022
|
};
|
|
2015
2023
|
|
|
2016
|
-
function transition(to: State) {
|
|
2024
|
+
function transition(to: State): boolean {
|
|
2017
2025
|
// exit
|
|
2018
2026
|
switch (state.current) {
|
|
2019
2027
|
case "dragging":
|
|
@@ -2023,6 +2031,7 @@ export function groupMachine(
|
|
|
2023
2031
|
}
|
|
2024
2032
|
|
|
2025
2033
|
// enter
|
|
2034
|
+
let skipOnUpdate = false;
|
|
2026
2035
|
switch (to) {
|
|
2027
2036
|
case "idle":
|
|
2028
2037
|
actions.onAutosave();
|
|
@@ -2033,15 +2042,39 @@ export function groupMachine(
|
|
|
2033
2042
|
case "togglingCollapse":
|
|
2034
2043
|
actions.prepare();
|
|
2035
2044
|
actions.clearLastKnownSize();
|
|
2045
|
+
// Write post-prepare template to DOM instead of routing through React.
|
|
2046
|
+
// `prepare()` converts % to px (same rendered width) — committing
|
|
2047
|
+
// through React fires a Layout pass before the raf loop starts,
|
|
2048
|
+
// producing a visible hitch on frame 0. Callers propagate the
|
|
2049
|
+
// returned flag into send()'s skipOnUpdate so the trailing onUpdate
|
|
2050
|
+
// there is suppressed too.
|
|
2051
|
+
if (getGroupElement) {
|
|
2052
|
+
const el = getGroupElement();
|
|
2053
|
+
if (el) {
|
|
2054
|
+
const template = buildTemplate(context);
|
|
2055
|
+
if (context.orientation === "horizontal") {
|
|
2056
|
+
el.style.gridTemplateColumns = template;
|
|
2057
|
+
} else {
|
|
2058
|
+
el.style.gridTemplateRows = template;
|
|
2059
|
+
}
|
|
2060
|
+
skipOnUpdate = true;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2036
2063
|
break;
|
|
2037
2064
|
}
|
|
2038
2065
|
|
|
2039
2066
|
state.current = to;
|
|
2040
2067
|
|
|
2041
|
-
|
|
2068
|
+
if (!skipOnUpdate) {
|
|
2069
|
+
onUpdate?.(context);
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
return skipOnUpdate;
|
|
2042
2073
|
}
|
|
2043
2074
|
|
|
2044
2075
|
function send(event: GroupMachineEvent) {
|
|
2076
|
+
let skipOnUpdate = false;
|
|
2077
|
+
|
|
2045
2078
|
switch (event.type) {
|
|
2046
2079
|
case "lockGroup":
|
|
2047
2080
|
locked = true;
|
|
@@ -2183,6 +2216,15 @@ export function groupMachine(
|
|
|
2183
2216
|
actions.onAutosave();
|
|
2184
2217
|
break;
|
|
2185
2218
|
case "setActualItemsSize": {
|
|
2219
|
+
// During direct-DOM animations the machine writes grid-template to the
|
|
2220
|
+
// DOM each frame, which causes panel sizes to change, which fires the
|
|
2221
|
+
// ResizeObserver in measureGroupChildren, which sends this event.
|
|
2222
|
+
// Ignore it so we don't trigger an onUpdate and re-render mid-animation.
|
|
2223
|
+
if (state.current === "togglingCollapse" && getGroupElement) {
|
|
2224
|
+
skipOnUpdate = true;
|
|
2225
|
+
break;
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2186
2228
|
const withLastKnownSize = context.items.map((i) => {
|
|
2187
2229
|
if (!isPanelData(i)) return i;
|
|
2188
2230
|
const lastKnownSize = event.childrenSizes[i.id] || i.lastKnownSize;
|
|
@@ -2290,7 +2332,7 @@ export function groupMachine(
|
|
|
2290
2332
|
const panel = getPanelWithId(context, event.panelId);
|
|
2291
2333
|
|
|
2292
2334
|
if (!panel.collapsed) {
|
|
2293
|
-
transition("togglingCollapse");
|
|
2335
|
+
if (transition("togglingCollapse")) skipOnUpdate = true;
|
|
2294
2336
|
abortController.abort();
|
|
2295
2337
|
animationActor(context, event, send, abortController).then(
|
|
2296
2338
|
(output) => {
|
|
@@ -2313,7 +2355,7 @@ export function groupMachine(
|
|
|
2313
2355
|
const panel = getPanelWithId(context, event.panelId);
|
|
2314
2356
|
|
|
2315
2357
|
if (panel.collapsed) {
|
|
2316
|
-
transition("togglingCollapse");
|
|
2358
|
+
if (transition("togglingCollapse")) skipOnUpdate = true;
|
|
2317
2359
|
abortController.abort();
|
|
2318
2360
|
animationActor(context, event, send, abortController).then(
|
|
2319
2361
|
(output) => {
|
|
@@ -2365,11 +2407,28 @@ export function groupMachine(
|
|
|
2365
2407
|
})
|
|
2366
2408
|
);
|
|
2367
2409
|
actions.onResize();
|
|
2410
|
+
|
|
2411
|
+
if (getGroupElement) {
|
|
2412
|
+
const el = getGroupElement();
|
|
2413
|
+
|
|
2414
|
+
if (el) {
|
|
2415
|
+
const template = buildTemplate(context);
|
|
2416
|
+
|
|
2417
|
+
if (context.orientation === "horizontal") {
|
|
2418
|
+
el.style.gridTemplateColumns = template;
|
|
2419
|
+
} else {
|
|
2420
|
+
el.style.gridTemplateRows = template;
|
|
2421
|
+
}
|
|
2422
|
+
skipOnUpdate = true;
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2368
2425
|
break;
|
|
2369
2426
|
}
|
|
2370
2427
|
}
|
|
2371
2428
|
|
|
2372
|
-
|
|
2429
|
+
if (!skipOnUpdate) {
|
|
2430
|
+
onUpdate?.(context);
|
|
2431
|
+
}
|
|
2373
2432
|
}
|
|
2374
2433
|
|
|
2375
2434
|
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,262 @@ 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("collapsePanel does not fire onUpdate when getGroupElement is provided (frame-0 hitch)", async () => {
|
|
631
|
+
const groupEl = document.createElement("div");
|
|
632
|
+
groupEl.style.display = "grid";
|
|
633
|
+
document.body.appendChild(groupEl);
|
|
634
|
+
|
|
635
|
+
let updateCount = 0;
|
|
636
|
+
const actor = setupCollapsibleActor(groupEl, () => {
|
|
637
|
+
updateCount++;
|
|
638
|
+
});
|
|
639
|
+
registerCollapsibleLayout(actor);
|
|
640
|
+
|
|
641
|
+
const updatesBeforeCollapse = updateCount;
|
|
642
|
+
|
|
643
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
644
|
+
|
|
645
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
646
|
+
// Neither transition() nor send()'s trailing onUpdate should fire —
|
|
647
|
+
// otherwise React commits + Layout runs before frame 1 of the animation.
|
|
648
|
+
expect(updateCount).toBe(updatesBeforeCollapse);
|
|
649
|
+
|
|
650
|
+
// DOM template must be written synchronously so the animation actor
|
|
651
|
+
// starts against pixel-form values.
|
|
652
|
+
expect(groupEl.style.gridTemplateColumns).toBeTruthy();
|
|
653
|
+
|
|
654
|
+
await waitForIdle(actor);
|
|
655
|
+
document.body.removeChild(groupEl);
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
test("onUpdate IS called after animation ends (final sync)", async () => {
|
|
659
|
+
const groupEl = document.createElement("div");
|
|
660
|
+
document.body.appendChild(groupEl);
|
|
661
|
+
|
|
662
|
+
let updateCount = 0;
|
|
663
|
+
const actor = setupCollapsibleActor(groupEl, () => {
|
|
664
|
+
updateCount++;
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
// Short animation so it completes quickly
|
|
668
|
+
sendAll(actor, [
|
|
669
|
+
{
|
|
670
|
+
type: "registerPanel",
|
|
671
|
+
data: initializePanel({ id: "panel-1" }),
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
type: "registerPanelHandle",
|
|
675
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
type: "registerPanel",
|
|
679
|
+
data: initializePanel({
|
|
680
|
+
id: "panel-2",
|
|
681
|
+
collapsible: true,
|
|
682
|
+
min: "100px",
|
|
683
|
+
default: "200px",
|
|
684
|
+
collapseAnimation: {
|
|
685
|
+
easing: "linear",
|
|
686
|
+
duration: 50,
|
|
687
|
+
},
|
|
688
|
+
}),
|
|
689
|
+
},
|
|
690
|
+
]);
|
|
691
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
692
|
+
|
|
693
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
694
|
+
await waitForIdle(actor);
|
|
695
|
+
|
|
696
|
+
expect(actor.state.current).toBe("idle");
|
|
697
|
+
expect(updateCount).toBeGreaterThan(0);
|
|
698
|
+
|
|
699
|
+
document.body.removeChild(groupEl);
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
test("behavior unchanged when getGroupElement is omitted (onUpdate fires per frame)", async () => {
|
|
703
|
+
let updateCount = 0;
|
|
704
|
+
const actor = createActor({ groupId: "group" }, () => {
|
|
705
|
+
updateCount++;
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
sendAll(actor, [
|
|
709
|
+
{
|
|
710
|
+
type: "registerPanel",
|
|
711
|
+
data: initializePanel({ id: "panel-1" }),
|
|
712
|
+
},
|
|
713
|
+
{
|
|
714
|
+
type: "registerPanelHandle",
|
|
715
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
type: "registerPanel",
|
|
719
|
+
data: initializePanel({
|
|
720
|
+
id: "panel-2",
|
|
721
|
+
collapsible: true,
|
|
722
|
+
min: "100px",
|
|
723
|
+
default: "200px",
|
|
724
|
+
collapseAnimation: {
|
|
725
|
+
easing: "ease-in-out",
|
|
726
|
+
duration: 5000,
|
|
727
|
+
},
|
|
728
|
+
}),
|
|
729
|
+
},
|
|
730
|
+
]);
|
|
731
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
732
|
+
|
|
733
|
+
const updatesBeforeAnimation = updateCount;
|
|
734
|
+
|
|
735
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
736
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
737
|
+
|
|
738
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
739
|
+
expect(updateCount).toBeGreaterThan(updatesBeforeAnimation);
|
|
740
|
+
|
|
741
|
+
await waitForIdle(actor);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
test("onResize still fires each frame during applyDelta", async () => {
|
|
745
|
+
const groupEl = document.createElement("div");
|
|
746
|
+
document.body.appendChild(groupEl);
|
|
747
|
+
|
|
748
|
+
let resizeCount = 0;
|
|
749
|
+
const actor = createActor(
|
|
750
|
+
{ groupId: "group" },
|
|
751
|
+
() => {},
|
|
752
|
+
() => groupEl
|
|
753
|
+
);
|
|
754
|
+
|
|
755
|
+
sendAll(actor, [
|
|
756
|
+
{
|
|
757
|
+
type: "registerPanel",
|
|
758
|
+
data: initializePanel({
|
|
759
|
+
id: "panel-1",
|
|
760
|
+
}),
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
type: "registerPanelHandle",
|
|
764
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
type: "registerPanel",
|
|
768
|
+
data: initializePanel({
|
|
769
|
+
id: "panel-2",
|
|
770
|
+
collapsible: true,
|
|
771
|
+
min: "100px",
|
|
772
|
+
default: "200px",
|
|
773
|
+
collapseAnimation: {
|
|
774
|
+
easing: "ease-in-out",
|
|
775
|
+
duration: 5000,
|
|
776
|
+
},
|
|
777
|
+
onResize: {
|
|
778
|
+
current: () => {
|
|
779
|
+
resizeCount++;
|
|
780
|
+
},
|
|
781
|
+
},
|
|
782
|
+
}),
|
|
783
|
+
},
|
|
784
|
+
]);
|
|
785
|
+
initializeSizes(actor, { width: 500, height: 200 });
|
|
786
|
+
|
|
787
|
+
actor.send({ type: "collapsePanel", panelId: "panel-2" });
|
|
788
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
789
|
+
|
|
790
|
+
expect(actor.state.current).toBe("togglingCollapse");
|
|
791
|
+
expect(resizeCount).toBeGreaterThan(0);
|
|
792
|
+
|
|
793
|
+
await waitForIdle(actor);
|
|
794
|
+
document.body.removeChild(groupEl);
|
|
795
|
+
});
|
|
796
|
+
});
|
|
540
797
|
|
|
541
798
|
test("overflow measurements should not collapse panels during animation", async () => {
|
|
542
799
|
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,
|