@window-splitter/state 0.2.4 → 0.3.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 +4 -5
- package/.turbo/turbo-lint.log +9 -1
- package/.turbo/turbo-test.log +4717 -1160
- package/CHANGELOG.md +41 -0
- package/README.md +119 -1
- package/coverage/coverage-final.json +1 -1
- package/coverage/coverage-summary.json +3 -0
- package/coverage/index.html +19 -19
- package/coverage/index.ts.html +872 -377
- package/dist/commonjs/index.d.ts +22 -12
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +109 -25
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +22 -12
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +106 -25
- package/dist/esm/index.js.map +1 -1
- package/package.json +12 -9
- package/src/__snapshots__/machine.test.ts.snap +73 -0
- package/src/index.ts +151 -35
- package/src/machine.test.ts +327 -9
- package/src/utils.test.ts +86 -0
- package/vitest.config.ts +2 -0
- package/coverage/clover.xml +0 -363
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export type PixelUnit = `${number}px`;
|
|
|
4
4
|
export type PercentUnit = `${number}%`;
|
|
5
5
|
export type Unit = PixelUnit | PercentUnit;
|
|
6
6
|
type Orientation = "horizontal" | "vertical";
|
|
7
|
-
interface ParsedPercentUnit {
|
|
7
|
+
export interface ParsedPercentUnit {
|
|
8
8
|
type: "percent";
|
|
9
9
|
value: Big.Big;
|
|
10
10
|
}
|
|
11
|
-
interface ParsedPixelUnit {
|
|
11
|
+
export interface ParsedPixelUnit {
|
|
12
12
|
type: "pixel";
|
|
13
13
|
value: Big.Big;
|
|
14
14
|
}
|
|
@@ -54,6 +54,10 @@ export interface PanelData extends Omit<Constraints, "min" | "max" | "collapsedS
|
|
|
54
54
|
onCollapseChange?: {
|
|
55
55
|
current: ((isCollapsed: boolean) => void) | null | undefined;
|
|
56
56
|
};
|
|
57
|
+
/** A ref to the latest "onResize" function provided by the user */
|
|
58
|
+
onResize?: {
|
|
59
|
+
current: OnResizeCallback | null | undefined;
|
|
60
|
+
};
|
|
57
61
|
/**
|
|
58
62
|
* The current value for the item in the grid
|
|
59
63
|
*/
|
|
@@ -104,7 +108,7 @@ interface UnregisterPanelEvent {
|
|
|
104
108
|
id: string;
|
|
105
109
|
}
|
|
106
110
|
export type InitializePanelHandleData = Omit<PanelHandleData, "type" | "size"> & {
|
|
107
|
-
size: PixelUnit
|
|
111
|
+
size: PixelUnit;
|
|
108
112
|
};
|
|
109
113
|
interface RegisterPanelHandleEvent {
|
|
110
114
|
/** Register a new panel handle with the state machine */
|
|
@@ -200,16 +204,20 @@ export interface GroupMachineContextValue {
|
|
|
200
204
|
orientation: Orientation;
|
|
201
205
|
/** How much the drag has overshot the handle */
|
|
202
206
|
dragOvershoot: Big.Big;
|
|
203
|
-
/** An id to use for autosaving the layout */
|
|
204
|
-
autosaveId?: string;
|
|
205
207
|
groupId: string;
|
|
206
208
|
}
|
|
207
209
|
export type GroupMachineEvent = RegisterPanelEvent | RegisterDynamicPanelEvent | UnregisterPanelEvent | RegisterPanelHandleEvent | UnregisterPanelHandleEvent | DragHandleEvent | SetSizeEvent | SetOrientationEvent | DragHandleStartEvent | DragHandleEndEvent | CollapsePanelEvent | ExpandPanelEvent | SetPanelPixelSizeEvent | ApplyDeltaEvent | SetActualItemsSizeEvent;
|
|
210
|
+
export declare function getCursor(context: Pick<GroupMachineContextValue, "dragOvershoot" | "orientation">): "w-resize" | "e-resize" | "ew-resize" | "n-resize" | "s-resize" | "ns-resize";
|
|
208
211
|
export declare function prepareSnapshot(snapshot: Snapshot<unknown>): Snapshot<unknown>;
|
|
209
212
|
/** Determine if an item is a panel */
|
|
210
213
|
export declare function isPanelData(value: unknown): value is PanelData;
|
|
211
214
|
/** Determine if an item is a panel handle */
|
|
212
215
|
export declare function isPanelHandle(value: unknown): value is PanelHandleData;
|
|
216
|
+
type OnResizeSize = {
|
|
217
|
+
pixel: number;
|
|
218
|
+
percentage: number;
|
|
219
|
+
};
|
|
220
|
+
export type OnResizeCallback = (size: OnResizeSize) => void;
|
|
213
221
|
interface InitializePanelOptions {
|
|
214
222
|
min?: Unit;
|
|
215
223
|
max?: Unit;
|
|
@@ -220,6 +228,9 @@ interface InitializePanelOptions {
|
|
|
220
228
|
onCollapseChange?: {
|
|
221
229
|
current: ((isCollapsed: boolean) => void) | null | undefined;
|
|
222
230
|
};
|
|
231
|
+
onResize?: {
|
|
232
|
+
current: OnResizeCallback | null | undefined;
|
|
233
|
+
};
|
|
223
234
|
collapseAnimation?: PanelData["collapseAnimation"];
|
|
224
235
|
defaultCollapsed?: boolean;
|
|
225
236
|
id?: string;
|
|
@@ -230,7 +241,7 @@ type InitializePanelOptionsWithId = InitializePanelOptions & {
|
|
|
230
241
|
export declare function initializePanel(item: InitializePanelOptionsWithId): PanelData;
|
|
231
242
|
export declare function initializePanel(item: InitializePanelOptions): Omit<PanelData, "id">;
|
|
232
243
|
export declare function initializePanelHandleData(item: InitializePanelHandleData): {
|
|
233
|
-
size:
|
|
244
|
+
size: ParsedPixelUnit;
|
|
234
245
|
id: string;
|
|
235
246
|
order?: number | undefined;
|
|
236
247
|
type: "handle";
|
|
@@ -240,8 +251,6 @@ export declare function parseUnit(unit: Unit | "1fr"): ParsedUnit;
|
|
|
240
251
|
/** Convert a `Unit` to a percentage of the group size */
|
|
241
252
|
export declare function getUnitPercentageValue(groupsSize: number, unit: ParsedUnit): number;
|
|
242
253
|
export declare function getGroupSize(context: GroupMachineContextValue): number;
|
|
243
|
-
/** Get the size of a panel in pixels */
|
|
244
|
-
export declare function getUnitPixelValue(context: GroupMachineContextValue, unit: ParsedUnit | "1fr"): Big.Big;
|
|
245
254
|
/** Get a panel with a particular ID. */
|
|
246
255
|
export declare function getPanelWithId(context: GroupMachineContextValue, panelId: string): PanelData;
|
|
247
256
|
/**
|
|
@@ -249,6 +258,10 @@ export declare function getPanelWithId(context: GroupMachineContextValue, panelI
|
|
|
249
258
|
* Will first check the left panel then the right.
|
|
250
259
|
*/
|
|
251
260
|
export declare function getCollapsiblePanelForHandleId(context: GroupMachineContextValue, handleId: string): PanelData;
|
|
261
|
+
export declare function getPanelGroupPixelSizes(context: GroupMachineContextValue): number[];
|
|
262
|
+
export declare function getPanelPixelSize(context: GroupMachineContextValue, panelId: string): number;
|
|
263
|
+
export declare function getPanelGroupPercentageSizes(context: GroupMachineContextValue): number[];
|
|
264
|
+
export declare function getPanelPercentageSize(context: GroupMachineContextValue, panelId: string): number;
|
|
252
265
|
/** Build the grid template from the item values. */
|
|
253
266
|
export declare function buildTemplate(context: GroupMachineContextValue): string;
|
|
254
267
|
/**
|
|
@@ -301,11 +314,9 @@ export declare function buildTemplate(context: GroupMachineContextValue): string
|
|
|
301
314
|
*/
|
|
302
315
|
/** Converts the items to pixels */
|
|
303
316
|
export declare function prepareItems(context: GroupMachineContextValue): Item[];
|
|
304
|
-
/** Converts the items to percentages */
|
|
305
|
-
export declare function commitLayout(context: GroupMachineContextValue): Item[];
|
|
306
317
|
export declare function dragHandlePayload({ delta, orientation, shiftKey, }: {
|
|
307
318
|
delta: number;
|
|
308
|
-
orientation
|
|
319
|
+
orientation?: Orientation;
|
|
309
320
|
shiftKey?: boolean;
|
|
310
321
|
}): {
|
|
311
322
|
readonly type: "move";
|
|
@@ -318,7 +329,6 @@ export declare function dragHandlePayload({ delta, orientation, shiftKey, }: {
|
|
|
318
329
|
readonly deltaY: number;
|
|
319
330
|
};
|
|
320
331
|
export declare const groupMachine: import("xstate").StateMachine<GroupMachineContextValue, RegisterPanelEvent | RegisterDynamicPanelEvent | UnregisterPanelEvent | RegisterPanelHandleEvent | UnregisterPanelHandleEvent | DragHandleStartEvent | DragHandleEvent | DragHandleEndEvent | SetSizeEvent | SetActualItemsSizeEvent | ApplyDeltaEvent | SetOrientationEvent | CollapsePanelEvent | ExpandPanelEvent | SetPanelPixelSizeEvent, Record<string, import("xstate").AnyActorRef>, import("xstate").ProvidedActor, import("xstate").ParameterizedObject, import("xstate").ParameterizedObject, string, import("xstate").StateValue, string, {
|
|
321
|
-
autosaveId?: string;
|
|
322
332
|
orientation?: Orientation;
|
|
323
333
|
groupId: string;
|
|
324
334
|
initialItems?: Item[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,QAAQ,EACT,MAAM,QAAQ,CAAC;AAEhB,OAAO,GAAG,MAAM,QAAQ,CAAC;AAWzB,MAAM,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,CAAC;AACtC,MAAM,MAAM,WAAW,GAAG,GAAG,MAAM,GAAG,CAAC;AACvC,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3C,KAAK,WAAW,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,QAAQ,EACT,MAAM,QAAQ,CAAC;AAEhB,OAAO,GAAG,MAAM,QAAQ,CAAC;AAWzB,MAAM,MAAM,SAAS,GAAG,GAAG,MAAM,IAAI,CAAC;AACtC,MAAM,MAAM,WAAW,GAAG,GAAG,MAAM,GAAG,CAAC;AACvC,MAAM,MAAM,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3C,KAAK,WAAW,GAAG,YAAY,GAAG,UAAU,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC;CAChB;AAED,KAAK,UAAU,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAEtD,wBAAgB,eAAe,C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@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.groupMachine = void 0;
|
|
7
7
|
exports.makePercentUnit = makePercentUnit;
|
|
8
8
|
exports.makePixelUnit = makePixelUnit;
|
|
9
|
+
exports.getCursor = getCursor;
|
|
9
10
|
exports.prepareSnapshot = prepareSnapshot;
|
|
10
11
|
exports.isPanelData = isPanelData;
|
|
11
12
|
exports.isPanelHandle = isPanelHandle;
|
|
@@ -14,12 +15,14 @@ exports.initializePanelHandleData = initializePanelHandleData;
|
|
|
14
15
|
exports.parseUnit = parseUnit;
|
|
15
16
|
exports.getUnitPercentageValue = getUnitPercentageValue;
|
|
16
17
|
exports.getGroupSize = getGroupSize;
|
|
17
|
-
exports.getUnitPixelValue = getUnitPixelValue;
|
|
18
18
|
exports.getPanelWithId = getPanelWithId;
|
|
19
19
|
exports.getCollapsiblePanelForHandleId = getCollapsiblePanelForHandleId;
|
|
20
|
+
exports.getPanelGroupPixelSizes = getPanelGroupPixelSizes;
|
|
21
|
+
exports.getPanelPixelSize = getPanelPixelSize;
|
|
22
|
+
exports.getPanelGroupPercentageSizes = getPanelGroupPercentageSizes;
|
|
23
|
+
exports.getPanelPercentageSize = getPanelPercentageSize;
|
|
20
24
|
exports.buildTemplate = buildTemplate;
|
|
21
25
|
exports.prepareItems = prepareItems;
|
|
22
|
-
exports.commitLayout = commitLayout;
|
|
23
26
|
exports.dragHandlePayload = dragHandlePayload;
|
|
24
27
|
const rafz_1 = require("@react-spring/rafz");
|
|
25
28
|
const xstate_1 = require("xstate");
|
|
@@ -41,8 +44,8 @@ function getCollapseAnimation(panel) {
|
|
|
41
44
|
if (typeof panel.collapseAnimation === "string") {
|
|
42
45
|
easeFn = collapseAnimations[panel.collapseAnimation];
|
|
43
46
|
}
|
|
44
|
-
else
|
|
45
|
-
duration = panel.collapseAnimation.duration
|
|
47
|
+
else {
|
|
48
|
+
duration = panel.collapseAnimation.duration;
|
|
46
49
|
easeFn =
|
|
47
50
|
typeof panel.collapseAnimation.easing === "function"
|
|
48
51
|
? panel.collapseAnimation.easing
|
|
@@ -68,6 +71,30 @@ const collapseAnimations = {
|
|
|
68
71
|
};
|
|
69
72
|
// #endregion
|
|
70
73
|
// #region Helpers
|
|
74
|
+
function getCursor(context) {
|
|
75
|
+
if (context.orientation === "horizontal") {
|
|
76
|
+
if (context.dragOvershoot.gt(0)) {
|
|
77
|
+
return "w-resize";
|
|
78
|
+
}
|
|
79
|
+
else if (context.dragOvershoot.lt(0)) {
|
|
80
|
+
return "e-resize";
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return "ew-resize";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (context.dragOvershoot.gt(0)) {
|
|
88
|
+
return "n-resize";
|
|
89
|
+
}
|
|
90
|
+
else if (context.dragOvershoot.lt(0)) {
|
|
91
|
+
return "s-resize";
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return "ns-resize";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
71
98
|
function prepareSnapshot(snapshot) {
|
|
72
99
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
100
|
const snapshotContext = snapshot
|
|
@@ -76,12 +103,8 @@ function prepareSnapshot(snapshot) {
|
|
|
76
103
|
for (const item of snapshotContext.items) {
|
|
77
104
|
if (isPanelData(item)) {
|
|
78
105
|
item.currentValue.value = new big_js_1.default(item.currentValue.value);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
if (item.min) {
|
|
83
|
-
item.min.value = new big_js_1.default(item.min.value);
|
|
84
|
-
}
|
|
106
|
+
item.collapsedSize.value = new big_js_1.default(item.collapsedSize.value);
|
|
107
|
+
item.min.value = new big_js_1.default(item.min.value);
|
|
85
108
|
if (item.max && item.max !== "1fr") {
|
|
86
109
|
item.max.value = new big_js_1.default(item.max.value);
|
|
87
110
|
}
|
|
@@ -111,6 +134,20 @@ function isPanelHandle(value) {
|
|
|
111
134
|
value.type === "handle");
|
|
112
135
|
}
|
|
113
136
|
function initializePanel(item) {
|
|
137
|
+
const onResize = () => {
|
|
138
|
+
let lastCall = null;
|
|
139
|
+
// Memo-ize so we only call the callback once per size
|
|
140
|
+
return ((size) => {
|
|
141
|
+
if (!lastCall ||
|
|
142
|
+
(lastCall.pixel === size.pixel &&
|
|
143
|
+
lastCall.percentage === size.percentage)) {
|
|
144
|
+
lastCall = size;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
lastCall = size;
|
|
148
|
+
item.onResize?.current?.(size);
|
|
149
|
+
});
|
|
150
|
+
};
|
|
114
151
|
const data = {
|
|
115
152
|
type: "panel",
|
|
116
153
|
min: parseUnit(item.min || "0px"),
|
|
@@ -121,6 +158,7 @@ function initializePanel(item) {
|
|
|
121
158
|
collapsible: item.collapsible,
|
|
122
159
|
collapsedSize: parseUnit(item.collapsedSize ?? "0px"),
|
|
123
160
|
onCollapseChange: item.onCollapseChange,
|
|
161
|
+
onResize: { current: onResize() },
|
|
124
162
|
collapseIsControlled: typeof item.collapsed !== "undefined",
|
|
125
163
|
sizeBeforeCollapse: undefined,
|
|
126
164
|
id: item.id,
|
|
@@ -133,7 +171,9 @@ function initializePanelHandleData(item) {
|
|
|
133
171
|
return {
|
|
134
172
|
type: "handle",
|
|
135
173
|
...item,
|
|
136
|
-
size: typeof item.size === "string"
|
|
174
|
+
size: typeof item.size === "string"
|
|
175
|
+
? parseUnit(item.size)
|
|
176
|
+
: item.size,
|
|
137
177
|
};
|
|
138
178
|
}
|
|
139
179
|
/** Parse a `Unit` string or `clamp` value */
|
|
@@ -305,6 +345,32 @@ function formatUnit(unit) {
|
|
|
305
345
|
}
|
|
306
346
|
return `${unit.value.toNumber()}%`;
|
|
307
347
|
}
|
|
348
|
+
function getPanelGroupPixelSizes(context) {
|
|
349
|
+
return prepareItems(context).map((i) => isPanelData(i)
|
|
350
|
+
? i.currentValue.value.toNumber()
|
|
351
|
+
: getUnitPixelValue(context, i.size).toNumber());
|
|
352
|
+
}
|
|
353
|
+
function getPanelPixelSize(context, panelId) {
|
|
354
|
+
const p = getPanelWithId({ ...context, items: prepareItems(context) }, panelId);
|
|
355
|
+
return p.currentValue.value.toNumber();
|
|
356
|
+
}
|
|
357
|
+
function getPanelGroupPercentageSizes(context) {
|
|
358
|
+
const clamped = commitLayout({
|
|
359
|
+
...context,
|
|
360
|
+
items: prepareItems(context),
|
|
361
|
+
});
|
|
362
|
+
return clamped.map((i) => {
|
|
363
|
+
if (isPanelHandle(i)) {
|
|
364
|
+
return getUnitPercentageValue(getGroupSize(context), i.size);
|
|
365
|
+
}
|
|
366
|
+
return getUnitPercentageValue(getGroupSize(context), i.currentValue);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
function getPanelPercentageSize(context, panelId) {
|
|
370
|
+
const items = prepareItems(context);
|
|
371
|
+
const p = getPanelWithId({ ...context, items }, panelId);
|
|
372
|
+
return getUnitPercentageValue(getGroupSize(context), p.currentValue);
|
|
373
|
+
}
|
|
308
374
|
/** Build the grid template from the item values. */
|
|
309
375
|
function buildTemplate(context) {
|
|
310
376
|
const staticWidth = getStaticWidth(context);
|
|
@@ -314,9 +380,6 @@ function buildTemplate(context) {
|
|
|
314
380
|
const min = formatUnit(item.min);
|
|
315
381
|
if (item.currentValue.type === "pixel" &&
|
|
316
382
|
item.currentValue.value.toNumber() !== -1) {
|
|
317
|
-
if (item.currentValue.value.toNumber() < 0) {
|
|
318
|
-
return "0px";
|
|
319
|
-
}
|
|
320
383
|
return formatUnit(item.currentValue);
|
|
321
384
|
}
|
|
322
385
|
else if (item.currentValue.type === "percent") {
|
|
@@ -564,7 +627,7 @@ function updateLayout(context, dragEvent) {
|
|
|
564
627
|
panelBefore.currentValue = { type: "pixel", value: panelBeforeNewValue };
|
|
565
628
|
panelAfter.currentValue = { type: "pixel", value: panelAfterNewValue };
|
|
566
629
|
const leftoverSpace = new big_js_1.default(getGroupSize(context)).minus(newItems.reduce((acc, b) => acc.add(isPanelData(b) ? b.currentValue.value : b.size.value), new big_js_1.default(0)));
|
|
567
|
-
if (leftoverSpace.
|
|
630
|
+
if (!leftoverSpace.eq(0)) {
|
|
568
631
|
panelBefore.currentValue.value =
|
|
569
632
|
panelBefore.currentValue.value.add(leftoverSpace);
|
|
570
633
|
}
|
|
@@ -600,7 +663,7 @@ function commitLayout(context) {
|
|
|
600
663
|
});
|
|
601
664
|
return newItems;
|
|
602
665
|
}
|
|
603
|
-
function dragHandlePayload({ delta, orientation, shiftKey = false, }) {
|
|
666
|
+
function dragHandlePayload({ delta, orientation = "horizontal", shiftKey = false, }) {
|
|
604
667
|
return {
|
|
605
668
|
type: "move",
|
|
606
669
|
pointerType: "keyboard",
|
|
@@ -712,7 +775,6 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
712
775
|
items: input.initialItems || [],
|
|
713
776
|
orientation: input.orientation || "horizontal",
|
|
714
777
|
dragOvershoot: new big_js_1.default(0),
|
|
715
|
-
autosaveId: input.autosaveId,
|
|
716
778
|
groupId: input.groupId,
|
|
717
779
|
}),
|
|
718
780
|
states: {
|
|
@@ -721,7 +783,13 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
721
783
|
setActualItemsSize: { actions: ["recordActualItemSize"] },
|
|
722
784
|
dragHandleStart: { target: "dragging" },
|
|
723
785
|
setPanelPixelSize: {
|
|
724
|
-
actions: [
|
|
786
|
+
actions: [
|
|
787
|
+
"prepare",
|
|
788
|
+
"onSetPanelSize",
|
|
789
|
+
"commit",
|
|
790
|
+
"onResize",
|
|
791
|
+
"onAutosave",
|
|
792
|
+
],
|
|
725
793
|
},
|
|
726
794
|
collapsePanel: [
|
|
727
795
|
{
|
|
@@ -742,7 +810,7 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
742
810
|
dragging: {
|
|
743
811
|
entry: ["prepare"],
|
|
744
812
|
on: {
|
|
745
|
-
dragHandle: { actions: ["onDragHandle"] },
|
|
813
|
+
dragHandle: { actions: ["onDragHandle", "onResize"] },
|
|
746
814
|
dragHandleEnd: { target: "idle" },
|
|
747
815
|
collapsePanel: {
|
|
748
816
|
guard: "shouldCollapseToggle",
|
|
@@ -766,24 +834,30 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
766
834
|
},
|
|
767
835
|
},
|
|
768
836
|
on: {
|
|
769
|
-
applyDelta: { actions: ["onApplyDelta"] },
|
|
837
|
+
applyDelta: { actions: ["onApplyDelta", "onResize"] },
|
|
770
838
|
},
|
|
771
839
|
},
|
|
772
840
|
},
|
|
773
841
|
on: {
|
|
774
842
|
registerPanel: { actions: ["assignPanelData"] },
|
|
775
843
|
registerDynamicPanel: {
|
|
776
|
-
actions: [
|
|
844
|
+
actions: [
|
|
845
|
+
"prepare",
|
|
846
|
+
"onRegisterDynamicPanel",
|
|
847
|
+
"commit",
|
|
848
|
+
"onResize",
|
|
849
|
+
"onAutosave",
|
|
850
|
+
],
|
|
777
851
|
},
|
|
778
852
|
unregisterPanel: {
|
|
779
|
-
actions: ["prepare", "removeItem", "commit", "onAutosave"],
|
|
853
|
+
actions: ["prepare", "removeItem", "commit", "onResize", "onAutosave"],
|
|
780
854
|
},
|
|
781
855
|
registerPanelHandle: { actions: ["assignPanelHandleData"] },
|
|
782
856
|
unregisterPanelHandle: {
|
|
783
|
-
actions: ["prepare", "removeItem", "commit", "onAutosave"],
|
|
857
|
+
actions: ["prepare", "removeItem", "commit", "onResize", "onAutosave"],
|
|
784
858
|
},
|
|
785
|
-
setSize: { actions: ["updateSize"] },
|
|
786
|
-
setOrientation: { actions: ["updateOrientation"] },
|
|
859
|
+
setSize: { actions: ["updateSize", "onResize"] },
|
|
860
|
+
setOrientation: { actions: ["updateOrientation", "onResize"] },
|
|
787
861
|
},
|
|
788
862
|
}, {
|
|
789
863
|
guards: {
|
|
@@ -978,6 +1052,16 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
978
1052
|
delta,
|
|
979
1053
|
}));
|
|
980
1054
|
}),
|
|
1055
|
+
onResize: ({ context }) => {
|
|
1056
|
+
for (const item of context.items) {
|
|
1057
|
+
if (isPanelData(item)) {
|
|
1058
|
+
item.onResize?.current?.({
|
|
1059
|
+
pixel: getUnitPixelValue(context, item.currentValue).toNumber(),
|
|
1060
|
+
percentage: getUnitPercentageValue(getGroupSize(context), item.currentValue),
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
},
|
|
981
1065
|
},
|
|
982
1066
|
});
|
|
983
1067
|
// #endregion
|