@window-splitter/state 0.4.0 → 0.4.1
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 +4 -5
- package/.turbo/turbo-test.log +1192 -4322
- package/CHANGELOG.md +22 -0
- package/coverage/coverage-final.json +1 -1
- package/coverage/coverage-summary.json +2 -2
- package/coverage/index.html +21 -21
- package/coverage/index.ts.html +1310 -1022
- package/dist/commonjs/index.d.ts +11 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +106 -29
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +11 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +106 -29
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -3
- package/src/__snapshots__/machine.test.ts.snap +82 -2
- package/src/index.ts +136 -37
- package/src/machine.test.ts +144 -58
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export interface PanelData extends Omit<Constraints, "min" | "max" | "collapsedS
|
|
|
82
82
|
duration: number;
|
|
83
83
|
easing: CollapseAnimation | ((t: number) => number);
|
|
84
84
|
};
|
|
85
|
+
lastKnownSize?: Rect;
|
|
85
86
|
}
|
|
86
87
|
/** Copied from https://github.com/d3/d3-ease */
|
|
87
88
|
declare const collapseAnimations: {
|
|
@@ -154,7 +155,6 @@ interface SetSizeEvent {
|
|
|
154
155
|
/** Set the size of the whole group */
|
|
155
156
|
type: "setSize";
|
|
156
157
|
size: Rect;
|
|
157
|
-
handleOverflow?: boolean;
|
|
158
158
|
}
|
|
159
159
|
interface SetActualItemsSizeEvent {
|
|
160
160
|
/** Set the size of the whole group */
|
|
@@ -213,10 +213,18 @@ export interface GroupMachineContextValue {
|
|
|
213
213
|
/** How much the drag has overshot the handle */
|
|
214
214
|
dragOvershoot: Big.Big;
|
|
215
215
|
groupId: string;
|
|
216
|
+
/**
|
|
217
|
+
* How to save the persisted state
|
|
218
|
+
*/
|
|
219
|
+
autosaveStrategy?: "localStorage" | "cookie";
|
|
216
220
|
}
|
|
221
|
+
export type GroupMachineSnapshot = Snapshot<unknown> & {
|
|
222
|
+
context: GroupMachineContextValue;
|
|
223
|
+
value: string;
|
|
224
|
+
};
|
|
217
225
|
export type GroupMachineEvent = RegisterPanelEvent | RegisterDynamicPanelEvent | UnregisterPanelEvent | RegisterPanelHandleEvent | UnregisterPanelHandleEvent | DragHandleEvent | SetSizeEvent | SetOrientationEvent | DragHandleStartEvent | DragHandleEndEvent | CollapsePanelEvent | ExpandPanelEvent | SetPanelPixelSizeEvent | ApplyDeltaEvent | SetActualItemsSizeEvent;
|
|
218
226
|
export declare function getCursor(context: Pick<GroupMachineContextValue, "dragOvershoot" | "orientation">): "w-resize" | "e-resize" | "ew-resize" | "n-resize" | "s-resize" | "ns-resize";
|
|
219
|
-
export declare function prepareSnapshot(snapshot:
|
|
227
|
+
export declare function prepareSnapshot(snapshot: GroupMachineSnapshot): GroupMachineSnapshot;
|
|
220
228
|
/** Determine if an item is a panel */
|
|
221
229
|
export declare function isPanelData(value: unknown): value is PanelData;
|
|
222
230
|
/** Determine if an item is a panel handle */
|
|
@@ -330,6 +338,7 @@ export declare const groupMachine: import("xstate").StateMachine<GroupMachineCon
|
|
|
330
338
|
orientation?: Orientation;
|
|
331
339
|
groupId: string;
|
|
332
340
|
initialItems?: Item[];
|
|
341
|
+
autosaveStrategy?: "localStorage" | "cookie";
|
|
333
342
|
}, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, any>;
|
|
334
343
|
export {};
|
|
335
344
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,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AsB,CACpC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE,MAAM,UAKhB;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,OAAO,EAAE,wBAAwB,UA6D9D;AA8BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,mCAAmC;AACnC,wBAAgB,YAAY,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,EAAE,CAoCtE;AA8SD,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAA0B,EAC1B,QAAgB,GACjB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;;;;;;;;;EAWA;AA4PD,eAAO,MAAM,YAAY;kBAOH,WAAW;aAChB,MAAM;mBACA,IAAI,EAAE;uBACF,cAAc,GAAG,QAAQ;wGAucnD,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -24,6 +24,7 @@ exports.getPanelPercentageSize = getPanelPercentageSize;
|
|
|
24
24
|
exports.buildTemplate = buildTemplate;
|
|
25
25
|
exports.prepareItems = prepareItems;
|
|
26
26
|
exports.dragHandlePayload = dragHandlePayload;
|
|
27
|
+
const universal_cookie_1 = __importDefault(require("universal-cookie"));
|
|
27
28
|
const rafz_1 = require("@react-spring/rafz");
|
|
28
29
|
const xstate_1 = require("xstate");
|
|
29
30
|
const invariant_1 = __importDefault(require("invariant"));
|
|
@@ -96,9 +97,7 @@ function getCursor(context) {
|
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
function prepareSnapshot(snapshot) {
|
|
99
|
-
|
|
100
|
-
const snapshotContext = snapshot
|
|
101
|
-
.context;
|
|
100
|
+
const snapshotContext = snapshot.context;
|
|
102
101
|
snapshotContext.dragOvershoot = new big_js_1.default(snapshotContext.dragOvershoot);
|
|
103
102
|
for (const item of snapshotContext.items) {
|
|
104
103
|
if (isPanelData(item)) {
|
|
@@ -375,6 +374,7 @@ function getPanelPercentageSize(context, panelId) {
|
|
|
375
374
|
/** Build the grid template from the item values. */
|
|
376
375
|
function buildTemplate(context) {
|
|
377
376
|
const staticWidth = getStaticWidth(context);
|
|
377
|
+
let hasSeenFillPanel = false;
|
|
378
378
|
return context.items
|
|
379
379
|
.map((item) => {
|
|
380
380
|
if (item.type === "panel") {
|
|
@@ -388,6 +388,12 @@ function buildTemplate(context) {
|
|
|
388
388
|
return formatUnit(item.currentValue);
|
|
389
389
|
}
|
|
390
390
|
else if (item.currentValue.type === "percent") {
|
|
391
|
+
if (!hasSeenFillPanel &&
|
|
392
|
+
(item.max === "1fr" ||
|
|
393
|
+
(item.max.type === "percent" && item.max.value.eq(100)))) {
|
|
394
|
+
hasSeenFillPanel = true;
|
|
395
|
+
return `minmax(${min}, 1fr)`;
|
|
396
|
+
}
|
|
391
397
|
const max = item.max === "1fr" ? "100%" : formatUnit(item.max);
|
|
392
398
|
return `minmax(${min}, min(calc(${item.currentValue.value} * (100% - ${staticWidth}px)), ${max}))`;
|
|
393
399
|
}
|
|
@@ -493,6 +499,13 @@ function prepareItems(context) {
|
|
|
493
499
|
newItems.push({ ...item });
|
|
494
500
|
continue;
|
|
495
501
|
}
|
|
502
|
+
if (item.lastKnownSize) {
|
|
503
|
+
const lastSize = makePixelUnit(context.orientation === "horizontal"
|
|
504
|
+
? item.lastKnownSize.width
|
|
505
|
+
: item.lastKnownSize.height);
|
|
506
|
+
newItems.push({ ...item, currentValue: lastSize });
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
496
509
|
if (item.currentValue.type === "pixel") {
|
|
497
510
|
newItems.push({ ...item });
|
|
498
511
|
continue;
|
|
@@ -802,6 +815,9 @@ function handleOverflow(context) {
|
|
|
802
815
|
}
|
|
803
816
|
return { ...newContext, items: commitLayout(newContext) };
|
|
804
817
|
}
|
|
818
|
+
function clearLastKnownSize(items) {
|
|
819
|
+
return items.map((i) => ({ ...i, lastKnownSize: undefined }));
|
|
820
|
+
}
|
|
805
821
|
function getDeltaForEvent(context, event) {
|
|
806
822
|
const panel = getPanelWithId(context, event.panelId);
|
|
807
823
|
if (event.type === "expandPanel") {
|
|
@@ -861,15 +877,17 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
861
877
|
orientation: input.orientation || "horizontal",
|
|
862
878
|
dragOvershoot: new big_js_1.default(0),
|
|
863
879
|
groupId: input.groupId,
|
|
880
|
+
autosaveStrategy: input.autosaveStrategy,
|
|
864
881
|
}),
|
|
865
882
|
states: {
|
|
866
883
|
idle: {
|
|
884
|
+
entry: ["onAutosave"],
|
|
867
885
|
on: {
|
|
868
|
-
setActualItemsSize: { actions: ["recordActualItemSize", "onResize"] },
|
|
869
886
|
dragHandleStart: { target: "dragging" },
|
|
870
887
|
setPanelPixelSize: {
|
|
871
888
|
actions: [
|
|
872
889
|
"prepare",
|
|
890
|
+
"onClearLastKnownSize",
|
|
873
891
|
"onSetPanelSize",
|
|
874
892
|
"commit",
|
|
875
893
|
"onResize",
|
|
@@ -897,7 +915,9 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
897
915
|
dragging: {
|
|
898
916
|
entry: ["prepare"],
|
|
899
917
|
on: {
|
|
900
|
-
dragHandle: {
|
|
918
|
+
dragHandle: {
|
|
919
|
+
actions: ["onClearLastKnownSize", "onDragHandle", "onResize"],
|
|
920
|
+
},
|
|
901
921
|
dragHandleEnd: { target: "idle" },
|
|
902
922
|
collapsePanel: {
|
|
903
923
|
guard: "shouldCollapseToggle",
|
|
@@ -908,16 +928,16 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
908
928
|
actions: "runCollapseToggle",
|
|
909
929
|
},
|
|
910
930
|
},
|
|
911
|
-
exit: ["commit"
|
|
931
|
+
exit: ["commit"],
|
|
912
932
|
},
|
|
913
933
|
togglingCollapse: {
|
|
914
|
-
entry: ["prepare"],
|
|
934
|
+
entry: ["prepare", "onClearLastKnownSize"],
|
|
915
935
|
invoke: {
|
|
916
936
|
src: "animation",
|
|
917
937
|
input: (i) => ({ ...i, send: i.self.send }),
|
|
918
938
|
onDone: {
|
|
919
939
|
target: "idle",
|
|
920
|
-
actions: ["onToggleCollapseComplete", "commit"
|
|
940
|
+
actions: ["onToggleCollapseComplete", "commit"],
|
|
921
941
|
},
|
|
922
942
|
},
|
|
923
943
|
on: {
|
|
@@ -926,25 +946,43 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
926
946
|
},
|
|
927
947
|
},
|
|
928
948
|
on: {
|
|
949
|
+
setActualItemsSize: { actions: ["recordActualItemSize", "onResize"] },
|
|
929
950
|
registerPanel: { actions: ["assignPanelData"] },
|
|
930
951
|
registerDynamicPanel: {
|
|
931
952
|
actions: [
|
|
932
953
|
"prepare",
|
|
933
954
|
"onRegisterDynamicPanel",
|
|
955
|
+
"onClearLastKnownSize",
|
|
934
956
|
"commit",
|
|
935
957
|
"onResize",
|
|
936
958
|
"onAutosave",
|
|
937
959
|
],
|
|
938
960
|
},
|
|
939
961
|
unregisterPanel: {
|
|
940
|
-
actions: [
|
|
962
|
+
actions: [
|
|
963
|
+
"prepare",
|
|
964
|
+
"removeItem",
|
|
965
|
+
"onClearLastKnownSize",
|
|
966
|
+
"commit",
|
|
967
|
+
"onResize",
|
|
968
|
+
"onAutosave",
|
|
969
|
+
],
|
|
941
970
|
},
|
|
942
971
|
registerPanelHandle: { actions: ["assignPanelHandleData"] },
|
|
943
972
|
unregisterPanelHandle: {
|
|
944
|
-
actions: [
|
|
973
|
+
actions: [
|
|
974
|
+
"prepare",
|
|
975
|
+
"removeItem",
|
|
976
|
+
"onClearLastKnownSize",
|
|
977
|
+
"commit",
|
|
978
|
+
"onResize",
|
|
979
|
+
"onAutosave",
|
|
980
|
+
],
|
|
945
981
|
},
|
|
946
982
|
setSize: { actions: ["updateSize", "onResize"] },
|
|
947
|
-
setOrientation: {
|
|
983
|
+
setOrientation: {
|
|
984
|
+
actions: ["updateOrientation", "onClearLastKnownSize", "onResize"],
|
|
985
|
+
},
|
|
948
986
|
},
|
|
949
987
|
}, {
|
|
950
988
|
guards: {
|
|
@@ -986,6 +1024,24 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
986
1024
|
animation: animationActor,
|
|
987
1025
|
},
|
|
988
1026
|
actions: {
|
|
1027
|
+
onAutosave: ({ context, self }) => {
|
|
1028
|
+
if (!context.autosaveStrategy || typeof window === "undefined") {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const snapshot = self.getPersistedSnapshot();
|
|
1032
|
+
snapshot.context.items = clearLastKnownSize(context.items);
|
|
1033
|
+
snapshot.value = "idle";
|
|
1034
|
+
const data = JSON.stringify(snapshot);
|
|
1035
|
+
if (context.autosaveStrategy === "localStorage") {
|
|
1036
|
+
localStorage.setItem(context.groupId, data);
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1040
|
+
const ActualClass = universal_cookie_1.default.default || universal_cookie_1.default;
|
|
1041
|
+
const cookies = new ActualClass(null, { path: "/" });
|
|
1042
|
+
cookies.set(context.groupId, data, { path: "/", maxAge: 31536000 });
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
989
1045
|
notifyCollapseToggle: ({ context, event }) => {
|
|
990
1046
|
isEvent(event, ["collapsePanel", "expandPanel"]);
|
|
991
1047
|
const panel = getPanelWithId(context, event.panelId);
|
|
@@ -1009,8 +1065,7 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
1009
1065
|
}),
|
|
1010
1066
|
onToggleCollapseComplete: (0, xstate_1.assign)({
|
|
1011
1067
|
items: ({ context, event: e }) => {
|
|
1012
|
-
|
|
1013
|
-
const output = e.output;
|
|
1068
|
+
const { output } = e;
|
|
1014
1069
|
(0, invariant_1.default)(output, "Expected output from animation actor");
|
|
1015
1070
|
const panel = getPanelWithId(context, output.panelId);
|
|
1016
1071
|
panel.collapsed = output.action === "collapse";
|
|
@@ -1020,27 +1075,42 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
1020
1075
|
return context.items;
|
|
1021
1076
|
},
|
|
1022
1077
|
}),
|
|
1023
|
-
updateSize: (0, xstate_1.
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
1028
|
-
else {
|
|
1029
|
-
enqueue.assign({ size: event.size });
|
|
1030
|
-
}
|
|
1078
|
+
updateSize: (0, xstate_1.assign)({
|
|
1079
|
+
size: ({ event }) => {
|
|
1080
|
+
isEvent(event, ["setSize"]);
|
|
1081
|
+
return event.size;
|
|
1082
|
+
},
|
|
1031
1083
|
}),
|
|
1032
1084
|
recordActualItemSize: (0, xstate_1.assign)({
|
|
1033
1085
|
items: ({ context, event }) => {
|
|
1034
1086
|
isEvent(event, ["setActualItemsSize"]);
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1087
|
+
const withLastKnownSize = context.items.map((i) => {
|
|
1088
|
+
if (!isPanelData(i))
|
|
1089
|
+
return i;
|
|
1090
|
+
const lastKnownSize = event.childrenSizes[i.id] || i.lastKnownSize;
|
|
1091
|
+
return { ...i, lastKnownSize };
|
|
1092
|
+
});
|
|
1093
|
+
let totalSize = 0;
|
|
1094
|
+
for (const item of withLastKnownSize) {
|
|
1095
|
+
if (isPanelData(item)) {
|
|
1096
|
+
const size = item.lastKnownSize?.[context.orientation === "horizontal" ? "width" : "height"];
|
|
1097
|
+
// If any size is 0 don't handle overflow
|
|
1098
|
+
if (!size) {
|
|
1099
|
+
return withLastKnownSize;
|
|
1100
|
+
}
|
|
1101
|
+
totalSize += size;
|
|
1102
|
+
}
|
|
1103
|
+
else {
|
|
1104
|
+
totalSize += item.size.value.toNumber();
|
|
1040
1105
|
}
|
|
1041
|
-
item.currentValue = makePixelUnit(orientation === "horizontal" ? size.width : size.height);
|
|
1042
1106
|
}
|
|
1043
|
-
|
|
1107
|
+
if (totalSize > getGroupSize(context)) {
|
|
1108
|
+
return handleOverflow({
|
|
1109
|
+
...context,
|
|
1110
|
+
items: prepareItems({ ...context, items: withLastKnownSize }),
|
|
1111
|
+
}).items;
|
|
1112
|
+
}
|
|
1113
|
+
return withLastKnownSize;
|
|
1044
1114
|
},
|
|
1045
1115
|
}),
|
|
1046
1116
|
updateOrientation: (0, xstate_1.assign)({
|
|
@@ -1049,6 +1119,9 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
1049
1119
|
return event.orientation;
|
|
1050
1120
|
},
|
|
1051
1121
|
}),
|
|
1122
|
+
onClearLastKnownSize: (0, xstate_1.assign)({
|
|
1123
|
+
items: ({ context }) => clearLastKnownSize(context.items),
|
|
1124
|
+
}),
|
|
1052
1125
|
assignPanelData: (0, xstate_1.assign)({
|
|
1053
1126
|
items: ({ context, event }) => {
|
|
1054
1127
|
isEvent(event, ["registerPanel"]);
|
|
@@ -1168,7 +1241,11 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
1168
1241
|
onResize: ({ context }) => {
|
|
1169
1242
|
for (const item of context.items) {
|
|
1170
1243
|
if (isPanelData(item)) {
|
|
1171
|
-
const pixel =
|
|
1244
|
+
const pixel = item.lastKnownSize
|
|
1245
|
+
? new big_js_1.default(context.orientation === "horizontal"
|
|
1246
|
+
? item.lastKnownSize.width
|
|
1247
|
+
: item.lastKnownSize.height)
|
|
1248
|
+
: clampUnit(context, item, getUnitPixelValue(context, item.currentValue));
|
|
1172
1249
|
const groupSize = getGroupSize(context);
|
|
1173
1250
|
item.onResize?.current?.({
|
|
1174
1251
|
pixel: pixel.toNumber(),
|