@window-splitter/state 0.4.2 → 0.4.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/.turbo/turbo-lint.log +5 -0
- package/.turbo/turbo-test.log +2678 -0
- package/CHANGELOG.md +13 -0
- package/dist/commonjs/index.d.ts +9 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +74 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +9 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +72 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +108 -2
package/src/index.ts
CHANGED
|
@@ -182,6 +182,17 @@ interface RebindPanelCallbacksEvent {
|
|
|
182
182
|
data: Pick<PanelData, "id" | "onCollapseChange" | "onResize">;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
interface UpdateConstraintsEvent {
|
|
186
|
+
/** Update the constraints of a panel */
|
|
187
|
+
type: "updateConstraints";
|
|
188
|
+
data:
|
|
189
|
+
| Pick<
|
|
190
|
+
PanelData,
|
|
191
|
+
"id" | "min" | "max" | "default" | "collapsedSize" | "isStaticAtRest"
|
|
192
|
+
>
|
|
193
|
+
| Pick<PanelHandleData, "id" | "size">;
|
|
194
|
+
}
|
|
195
|
+
|
|
185
196
|
interface RegisterDynamicPanelEvent extends Omit<RegisterPanelEvent, "type"> {
|
|
186
197
|
/** Register a new panel with the state machine */
|
|
187
198
|
type: "registerDynamicPanel";
|
|
@@ -336,7 +347,9 @@ export type GroupMachineEvent =
|
|
|
336
347
|
| SetPanelPixelSizeEvent
|
|
337
348
|
| ApplyDeltaEvent
|
|
338
349
|
| SetActualItemsSizeEvent
|
|
339
|
-
| RebindPanelCallbacksEvent
|
|
350
|
+
| RebindPanelCallbacksEvent
|
|
351
|
+
| UpdateConstraintsEvent;
|
|
352
|
+
|
|
340
353
|
type EventForType<T extends GroupMachineEvent["type"]> = Extract<
|
|
341
354
|
GroupMachineEvent,
|
|
342
355
|
{ type: T }
|
|
@@ -500,6 +513,64 @@ export function initializePanel(
|
|
|
500
513
|
>;
|
|
501
514
|
}
|
|
502
515
|
|
|
516
|
+
function eq(a: ParsedUnit, b: ParsedUnit) {
|
|
517
|
+
return a.type === b.type && a.value.eq(b.value);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export function haveConstraintsChangedForPanel(
|
|
521
|
+
a: Omit<PanelData, "id" | "currentValue">,
|
|
522
|
+
b: Omit<PanelData, "id" | "currentValue">
|
|
523
|
+
) {
|
|
524
|
+
if (!eq(a.min, b.min)) {
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (
|
|
529
|
+
(a.max === "1fr" && b.max !== "1fr") ||
|
|
530
|
+
(a.max !== "1fr" && b.max === "1fr") ||
|
|
531
|
+
(a.max !== "1fr" && b.max !== "1fr" && !eq(a.max, b.max))
|
|
532
|
+
) {
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (
|
|
537
|
+
(a.default && !b.default) ||
|
|
538
|
+
(!a.default && b.default) ||
|
|
539
|
+
(a.default && b.default && !eq(a.default, b.default))
|
|
540
|
+
) {
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (!eq(a.collapsedSize, b.collapsedSize)) {
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
if (a.isStaticAtRest !== b.isStaticAtRest) {
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (a.collapseAnimation !== b.collapseAnimation) {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (a.collapsible !== b.collapsible) {
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export function haveConstraintsChangedForPanelHandle(
|
|
564
|
+
a: Omit<PanelHandleData, "id">,
|
|
565
|
+
b: Omit<PanelHandleData, "id">
|
|
566
|
+
) {
|
|
567
|
+
if (!eq(a.size, b.size)) {
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
|
|
503
574
|
export function initializePanelHandleData(item: InitializePanelHandleData) {
|
|
504
575
|
return {
|
|
505
576
|
type: "handle" as const,
|
|
@@ -1652,7 +1723,19 @@ export const groupMachine = createMachine(
|
|
|
1652
1723
|
on: {
|
|
1653
1724
|
setActualItemsSize: { actions: ["recordActualItemSize", "onResize"] },
|
|
1654
1725
|
registerPanel: { actions: ["assignPanelData"] },
|
|
1655
|
-
rebindPanelCallbacks: {
|
|
1726
|
+
rebindPanelCallbacks: {
|
|
1727
|
+
actions: ["rebindPanelCallbacks"],
|
|
1728
|
+
},
|
|
1729
|
+
updateConstraints: {
|
|
1730
|
+
actions: [
|
|
1731
|
+
"prepare",
|
|
1732
|
+
"updateConstraints",
|
|
1733
|
+
"onClearLastKnownSize",
|
|
1734
|
+
"commit",
|
|
1735
|
+
"onResize",
|
|
1736
|
+
"onAutosave",
|
|
1737
|
+
],
|
|
1738
|
+
},
|
|
1656
1739
|
registerDynamicPanel: {
|
|
1657
1740
|
actions: [
|
|
1658
1741
|
"prepare",
|
|
@@ -1878,6 +1961,29 @@ export const groupMachine = createMachine(
|
|
|
1878
1961
|
return context.items;
|
|
1879
1962
|
},
|
|
1880
1963
|
}),
|
|
1964
|
+
updateConstraints: assign({
|
|
1965
|
+
items: ({ context, event }) => {
|
|
1966
|
+
isEvent(event, ["updateConstraints"]);
|
|
1967
|
+
|
|
1968
|
+
for (const item of context.items) {
|
|
1969
|
+
if (isPanelData(item) && item.id === event.data.id) {
|
|
1970
|
+
const panel = event.data as PanelData;
|
|
1971
|
+
item.min = panel.min;
|
|
1972
|
+
item.max = panel.max;
|
|
1973
|
+
item.default = panel.default;
|
|
1974
|
+
item.collapsedSize = panel.collapsedSize;
|
|
1975
|
+
item.isStaticAtRest = panel.isStaticAtRest;
|
|
1976
|
+
item.collapseAnimation = panel.collapseAnimation;
|
|
1977
|
+
item.collapsible = panel.collapsible;
|
|
1978
|
+
} else if (isPanelHandle(item) && item.id === event.data.id) {
|
|
1979
|
+
const handle = event.data as PanelHandleData;
|
|
1980
|
+
item.size = handle.size;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
return context.items;
|
|
1985
|
+
},
|
|
1986
|
+
}),
|
|
1881
1987
|
onRegisterDynamicPanel: assign({
|
|
1882
1988
|
items: ({ context, event }) => {
|
|
1883
1989
|
isEvent(event, ["registerDynamicPanel"]);
|