@window-splitter/state 0.2.2 → 0.2.3--canary.823a479.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/.tshy/commonjs.json +1 -0
- package/.tshy/esm.json +1 -0
- package/.tshy-build/esm/index.d.ts +327 -0
- package/.tshy-build/esm/index.d.ts.map +1 -0
- package/.tshy-build/esm/index.js +964 -0
- package/.tshy-build/esm/index.js.map +1 -0
- package/.tshy-build/esm/package.json +3 -0
- package/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +1023 -129
- package/coverage/clover.xml +358 -345
- package/coverage/coverage-final.json +1 -1
- package/coverage/index.html +18 -18
- package/coverage/index.ts.html +624 -402
- package/dist/commonjs/index.d.ts +22 -9
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +189 -134
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +22 -9
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +188 -114
- package/dist/esm/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +279 -153
- package/src/machine.test.ts +174 -85
- package/src/package.json +3 -0
- package/src/utils.test.ts +22 -9
- package/dist/commonjs/machine.test.d.ts +0 -5
- package/dist/commonjs/machine.test.d.ts.map +0 -1
- package/dist/commonjs/machine.test.js +0 -1038
- package/dist/commonjs/machine.test.js.map +0 -1
- package/dist/commonjs/utils.test.d.ts +0 -2
- package/dist/commonjs/utils.test.d.ts.map +0 -1
- package/dist/commonjs/utils.test.js +0 -79
- package/dist/commonjs/utils.test.js.map +0 -1
- package/dist/esm/machine.test.d.ts +0 -5
- package/dist/esm/machine.test.d.ts.map +0 -1
- package/dist/esm/machine.test.js +0 -1036
- package/dist/esm/machine.test.js.map +0 -1
- package/dist/esm/utils.test.d.ts +0 -2
- package/dist/esm/utils.test.d.ts.map +0 -1
- package/dist/esm/utils.test.js +0 -77
- package/dist/esm/utils.test.js.map +0 -1
package/dist/commonjs/index.js
CHANGED
|
@@ -1,35 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.groupMachine = void 0;
|
|
7
|
+
exports.makePercentUnit = makePercentUnit;
|
|
8
|
+
exports.makePixelUnit = makePixelUnit;
|
|
9
|
+
exports.prepareSnapshot = prepareSnapshot;
|
|
30
10
|
exports.isPanelData = isPanelData;
|
|
31
11
|
exports.isPanelHandle = isPanelHandle;
|
|
32
12
|
exports.initializePanel = initializePanel;
|
|
13
|
+
exports.initializePanelHandleData = initializePanelHandleData;
|
|
33
14
|
exports.parseUnit = parseUnit;
|
|
34
15
|
exports.getUnitPercentageValue = getUnitPercentageValue;
|
|
35
16
|
exports.getGroupSize = getGroupSize;
|
|
@@ -43,15 +24,15 @@ exports.dragHandlePayload = dragHandlePayload;
|
|
|
43
24
|
const rafz_1 = require("@react-spring/rafz");
|
|
44
25
|
const xstate_1 = require("xstate");
|
|
45
26
|
const invariant_1 = __importDefault(require("invariant"));
|
|
46
|
-
const
|
|
27
|
+
const big_js_1 = __importDefault(require("big.js"));
|
|
47
28
|
// #region Constants
|
|
48
29
|
/** The default amount a user can `dragOvershoot` before the panel collapses */
|
|
49
30
|
const COLLAPSE_THRESHOLD = 50;
|
|
50
31
|
function makePercentUnit(value) {
|
|
51
|
-
return { type: "percent", value };
|
|
32
|
+
return { type: "percent", value: new big_js_1.default(value) };
|
|
52
33
|
}
|
|
53
34
|
function makePixelUnit(value) {
|
|
54
|
-
return { type: "pixel", value };
|
|
35
|
+
return { type: "pixel", value: new big_js_1.default(value) };
|
|
55
36
|
}
|
|
56
37
|
function getCollapseAnimation(panel) {
|
|
57
38
|
let easeFn = collapseAnimations.linear;
|
|
@@ -70,13 +51,47 @@ function getCollapseAnimation(panel) {
|
|
|
70
51
|
}
|
|
71
52
|
return { ease: easeFn, duration };
|
|
72
53
|
}
|
|
54
|
+
/** Copied from https://github.com/d3/d3-ease */
|
|
73
55
|
const collapseAnimations = {
|
|
74
|
-
"ease-in-out":
|
|
75
|
-
|
|
76
|
-
|
|
56
|
+
"ease-in-out": function quadInOut(t) {
|
|
57
|
+
return ((t *= 2) <= 1 ? t * t : --t * (2 - t) + 1) / 2;
|
|
58
|
+
},
|
|
59
|
+
bounce: function backInOut(t) {
|
|
60
|
+
const s = 1.70158;
|
|
61
|
+
return (((t *= 2) < 1
|
|
62
|
+
? t * t * ((s + 1) * t - s)
|
|
63
|
+
: (t -= 2) * t * ((s + 1) * t + s) + 2) / 2);
|
|
64
|
+
},
|
|
65
|
+
linear: function linear(t) {
|
|
66
|
+
return +t;
|
|
67
|
+
},
|
|
77
68
|
};
|
|
78
69
|
// #endregion
|
|
79
70
|
// #region Helpers
|
|
71
|
+
function prepareSnapshot(snapshot) {
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
const snapshotContext = snapshot
|
|
74
|
+
.context;
|
|
75
|
+
snapshotContext.dragOvershoot = new big_js_1.default(snapshotContext.dragOvershoot);
|
|
76
|
+
for (const item of snapshotContext.items) {
|
|
77
|
+
if (isPanelData(item)) {
|
|
78
|
+
item.currentValue.value = new big_js_1.default(item.currentValue.value);
|
|
79
|
+
if (item.collapsedSize) {
|
|
80
|
+
item.collapsedSize.value = new big_js_1.default(item.collapsedSize.value);
|
|
81
|
+
}
|
|
82
|
+
if (item.min) {
|
|
83
|
+
item.min.value = new big_js_1.default(item.min.value);
|
|
84
|
+
}
|
|
85
|
+
if (item.max && item.max !== "1fr") {
|
|
86
|
+
item.max.value = new big_js_1.default(item.max.value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
item.size.value = new big_js_1.default(item.size.value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return snapshot;
|
|
94
|
+
}
|
|
80
95
|
/** Assert that the provided event is one of the accepted types */
|
|
81
96
|
function isEvent(event, eventType) {
|
|
82
97
|
(0, invariant_1.default)(eventType.includes(event.type), `Invalid event type: ${eventType}. Expected: ${eventType.join(" | ")}`);
|
|
@@ -114,6 +129,13 @@ function initializePanel(item) {
|
|
|
114
129
|
};
|
|
115
130
|
return { ...data, currentValue: makePixelUnit(-1) };
|
|
116
131
|
}
|
|
132
|
+
function initializePanelHandleData(item) {
|
|
133
|
+
return {
|
|
134
|
+
type: "handle",
|
|
135
|
+
...item,
|
|
136
|
+
size: parseUnit(item.size),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
117
139
|
/** Parse a `Unit` string or `clamp` value */
|
|
118
140
|
function parseUnit(unit) {
|
|
119
141
|
if (unit === "1fr") {
|
|
@@ -130,9 +152,9 @@ function parseUnit(unit) {
|
|
|
130
152
|
/** Convert a `Unit` to a percentage of the group size */
|
|
131
153
|
function getUnitPercentageValue(groupsSize, unit) {
|
|
132
154
|
if (unit.type === "pixel") {
|
|
133
|
-
return unit.value
|
|
155
|
+
return groupsSize === 0 ? 0 : unit.value.div(groupsSize).toNumber();
|
|
134
156
|
}
|
|
135
|
-
return unit.value;
|
|
157
|
+
return unit.value.toNumber();
|
|
136
158
|
}
|
|
137
159
|
function getGroupSize(context) {
|
|
138
160
|
return context.orientation === "horizontal"
|
|
@@ -144,11 +166,16 @@ function getUnitPixelValue(context, unit) {
|
|
|
144
166
|
const parsed = unit === "1fr" ? parseUnit(unit) : unit;
|
|
145
167
|
return parsed.type === "pixel"
|
|
146
168
|
? parsed.value
|
|
147
|
-
: (parsed.value
|
|
169
|
+
: new big_js_1.default(parsed.value).div(100).mul(getGroupSize(context));
|
|
148
170
|
}
|
|
149
171
|
/** Clamp a new `currentValue` given the panel's constraints. */
|
|
150
172
|
function clampUnit(context, item, value) {
|
|
151
|
-
|
|
173
|
+
const min = getUnitPixelValue(context, item.min);
|
|
174
|
+
const max = getUnitPixelValue(context, item.max);
|
|
175
|
+
if (value.gte(min) && value.lte(max)) {
|
|
176
|
+
return value;
|
|
177
|
+
}
|
|
178
|
+
return value.lt(min) ? min : max;
|
|
152
179
|
}
|
|
153
180
|
/** Get a panel with a particular ID. */
|
|
154
181
|
function getPanelWithId(context, panelId) {
|
|
@@ -230,15 +257,20 @@ function sortWithOrder(items) {
|
|
|
230
257
|
return withoutOrder;
|
|
231
258
|
}
|
|
232
259
|
/** Check if the panel has space available to add to */
|
|
233
|
-
function panelHasSpace(context, item) {
|
|
260
|
+
function panelHasSpace(context, item, adjustment) {
|
|
234
261
|
(0, invariant_1.default)(item.currentValue.type === "pixel", `panelHasSpace only works with number values: ${item.id} ${item.currentValue}`);
|
|
235
262
|
if (item.collapsible && !item.collapsed) {
|
|
236
263
|
return true;
|
|
237
264
|
}
|
|
238
|
-
|
|
265
|
+
if (adjustment === "add") {
|
|
266
|
+
return (item.currentValue.value.gte(getUnitPixelValue(context, item.min)) &&
|
|
267
|
+
item.currentValue.value.lt(getUnitPixelValue(context, item.max)));
|
|
268
|
+
}
|
|
269
|
+
return (item.currentValue.value.gt(getUnitPixelValue(context, item.min)) &&
|
|
270
|
+
item.currentValue.value.lte(getUnitPixelValue(context, item.max)));
|
|
239
271
|
}
|
|
240
272
|
/** Search in a `direction` for a panel that still has space to expand. */
|
|
241
|
-
function findPanelWithSpace(context, items, start, direction, disregardCollapseBuffer) {
|
|
273
|
+
function findPanelWithSpace(context, items, start, direction, adjustment, disregardCollapseBuffer) {
|
|
242
274
|
const slice = direction === -1 ? items.slice(0, start + 1).reverse() : items.slice(start);
|
|
243
275
|
for (const panel of slice) {
|
|
244
276
|
if (!isPanelData(panel)) {
|
|
@@ -247,36 +279,36 @@ function findPanelWithSpace(context, items, start, direction, disregardCollapseB
|
|
|
247
279
|
const targetPanel = disregardCollapseBuffer
|
|
248
280
|
? createUnrestrainedPanel(context, panel)
|
|
249
281
|
: panel;
|
|
250
|
-
if (panelHasSpace(context, targetPanel)) {
|
|
282
|
+
if (panelHasSpace(context, targetPanel, adjustment)) {
|
|
251
283
|
return panel;
|
|
252
284
|
}
|
|
253
285
|
}
|
|
254
286
|
}
|
|
255
287
|
/** Add up all the static values in the layout */
|
|
256
288
|
function getStaticWidth(context) {
|
|
257
|
-
let width = 0;
|
|
289
|
+
let width = new big_js_1.default(0);
|
|
258
290
|
for (const item of context.items) {
|
|
259
291
|
if (isPanelHandle(item)) {
|
|
260
|
-
width
|
|
292
|
+
width = width.add(item.size.value);
|
|
261
293
|
}
|
|
262
294
|
else if (isPanelData(item) &&
|
|
263
295
|
item.collapsed &&
|
|
264
296
|
item.currentValue.type === "pixel") {
|
|
265
|
-
width
|
|
297
|
+
width = width.add(item.currentValue.value);
|
|
266
298
|
}
|
|
267
299
|
else if (isPanelData(item) &&
|
|
268
300
|
item.default &&
|
|
269
301
|
item.default.type === "pixel") {
|
|
270
|
-
width
|
|
302
|
+
width = width.add(item.default.value);
|
|
271
303
|
}
|
|
272
304
|
}
|
|
273
305
|
return width;
|
|
274
306
|
}
|
|
275
307
|
function formatUnit(unit) {
|
|
276
308
|
if (unit.type === "pixel") {
|
|
277
|
-
return `${unit.value}px`;
|
|
309
|
+
return `${unit.value.toNumber()}px`;
|
|
278
310
|
}
|
|
279
|
-
return `${unit.value}%`;
|
|
311
|
+
return `${unit.value.toNumber()}%`;
|
|
280
312
|
}
|
|
281
313
|
/** Build the grid template from the item values. */
|
|
282
314
|
function buildTemplate(context) {
|
|
@@ -286,7 +318,10 @@ function buildTemplate(context) {
|
|
|
286
318
|
if (item.type === "panel") {
|
|
287
319
|
const min = formatUnit(item.min);
|
|
288
320
|
if (item.currentValue.type === "pixel" &&
|
|
289
|
-
item.currentValue.value !== -1) {
|
|
321
|
+
item.currentValue.value.toNumber() !== -1) {
|
|
322
|
+
if (item.currentValue.value.toNumber() < 0) {
|
|
323
|
+
return "0px";
|
|
324
|
+
}
|
|
290
325
|
return formatUnit(item.currentValue);
|
|
291
326
|
}
|
|
292
327
|
else if (item.currentValue.type === "percent") {
|
|
@@ -315,11 +350,11 @@ function addDeDuplicatedItems(items, newItem) {
|
|
|
315
350
|
}
|
|
316
351
|
return sortWithOrder([...restItems, newItem]);
|
|
317
352
|
}
|
|
318
|
-
function createUnrestrainedPanel(
|
|
353
|
+
function createUnrestrainedPanel(_, data) {
|
|
319
354
|
return {
|
|
320
355
|
...data,
|
|
321
|
-
min: makePixelUnit(
|
|
322
|
-
max: makePixelUnit(
|
|
356
|
+
min: makePixelUnit(-100000),
|
|
357
|
+
max: makePixelUnit(100000),
|
|
323
358
|
};
|
|
324
359
|
}
|
|
325
360
|
// #endregion
|
|
@@ -383,8 +418,10 @@ function prepareItems(context) {
|
|
|
383
418
|
if (item.currentValue.type === "pixel") {
|
|
384
419
|
continue;
|
|
385
420
|
}
|
|
386
|
-
|
|
387
|
-
|
|
421
|
+
const pixel = new big_js_1.default(getGroupSize(context))
|
|
422
|
+
.minus(staticWidth)
|
|
423
|
+
.mul(item.currentValue.value);
|
|
424
|
+
item.currentValue = makePixelUnit(pixel.toNumber());
|
|
388
425
|
}
|
|
389
426
|
return newItems;
|
|
390
427
|
}
|
|
@@ -404,60 +441,64 @@ function updateLayout(context, dragEvent) {
|
|
|
404
441
|
}
|
|
405
442
|
const moveDirection = moveAmount / Math.abs(moveAmount);
|
|
406
443
|
// Go forward into the shrinking panels to find a panel that still has space.
|
|
407
|
-
const panelBefore = findPanelWithSpace(context, newItems, handleIndex + moveDirection, moveDirection, dragEvent.disregardCollapseBuffer);
|
|
444
|
+
const panelBefore = findPanelWithSpace(context, newItems, handleIndex + moveDirection, moveDirection, "subtract", dragEvent.disregardCollapseBuffer);
|
|
408
445
|
// No panel with space, just record the drag overshoot
|
|
409
446
|
if (!panelBefore) {
|
|
410
447
|
return {
|
|
411
|
-
dragOvershoot: context.dragOvershoot
|
|
448
|
+
dragOvershoot: context.dragOvershoot.add(moveAmount),
|
|
412
449
|
};
|
|
413
450
|
}
|
|
414
451
|
(0, invariant_1.default)(isPanelData(panelBefore), `Expected panel before: ${handle.id}`);
|
|
415
452
|
const panelAfter = newItems[handleIndex - moveDirection];
|
|
416
453
|
(0, invariant_1.default)(panelAfter && isPanelData(panelAfter), `Expected panel after: ${handle.id}`);
|
|
417
|
-
|
|
454
|
+
if (panelAfter.currentValue.value.eq(getUnitPixelValue(context, panelAfter.max))) {
|
|
455
|
+
return {
|
|
456
|
+
dragOvershoot: context.dragOvershoot.add(moveAmount),
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const newDragOvershoot = context.dragOvershoot.add(moveAmount);
|
|
418
460
|
// Don't let the panel expand until the threshold is reached
|
|
419
461
|
if (!dragEvent.disregardCollapseBuffer) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
462
|
+
const isInLeftBuffer = newDragOvershoot.lt(0) && moveDirection > 0;
|
|
463
|
+
const isInLeftOvershoot = newDragOvershoot.gt(0) && moveDirection > 0;
|
|
464
|
+
const isInRightBuffer = newDragOvershoot.gt(0) && moveDirection < 0;
|
|
465
|
+
const isInRightOvershoot = newDragOvershoot.lt(0) && moveDirection < 0;
|
|
466
|
+
const potentialNewValue = panelAfter.currentValue.value.add(new big_js_1.default(newDragOvershoot).mul(isInRightBuffer ? moveDirection : 1));
|
|
467
|
+
const min = getUnitPixelValue(context, panelAfter.min);
|
|
468
|
+
const isInDragBugger = newDragOvershoot.abs().lt(COLLAPSE_THRESHOLD) &&
|
|
469
|
+
panelAfter.collapsible &&
|
|
470
|
+
panelAfter.collapsed &&
|
|
471
|
+
(isInLeftOvershoot || isInRightOvershoot);
|
|
472
|
+
if (potentialNewValue.lte(min) &&
|
|
473
|
+
(newDragOvershoot.eq(0) ||
|
|
429
474
|
isInRightBuffer ||
|
|
430
475
|
isInLeftBuffer ||
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
potentialNewValue < min) {
|
|
434
|
-
return { dragOvershoot: newDragOvershoot };
|
|
435
|
-
}
|
|
476
|
+
isInDragBugger)) {
|
|
477
|
+
return { dragOvershoot: newDragOvershoot };
|
|
436
478
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
479
|
+
}
|
|
480
|
+
// Don't let the panel collapse until the threshold is reached
|
|
481
|
+
if (panelBefore.collapsible &&
|
|
482
|
+
panelBefore.currentValue.value ===
|
|
483
|
+
getUnitPixelValue(context, panelBefore.min)) {
|
|
484
|
+
const potentialNewValue = panelBefore.currentValue.value.sub(newDragOvershoot.abs());
|
|
485
|
+
if (newDragOvershoot.abs().lt(COLLAPSE_THRESHOLD) &&
|
|
486
|
+
potentialNewValue.gt(getUnitPixelValue(context, panelBefore.collapsedSize))) {
|
|
487
|
+
return { dragOvershoot: newDragOvershoot };
|
|
447
488
|
}
|
|
448
489
|
}
|
|
449
490
|
// Apply the move amount to the panel before the slider
|
|
450
491
|
const unrestrainedPanelBefore = createUnrestrainedPanel(context, panelBefore);
|
|
451
492
|
const panelBeforePreviousValue = panelBefore.currentValue.value;
|
|
452
|
-
const panelBeforeNewValueRaw = panelBefore.currentValue.value
|
|
493
|
+
const panelBeforeNewValueRaw = panelBefore.currentValue.value.minus(new big_js_1.default(moveAmount).mul(moveDirection));
|
|
453
494
|
let panelBeforeNewValue = dragEvent.disregardCollapseBuffer
|
|
454
495
|
? clampUnit(context, unrestrainedPanelBefore, panelBeforeNewValueRaw)
|
|
455
496
|
: clampUnit(context, panelBefore, panelBeforeNewValueRaw);
|
|
456
497
|
// Also apply the move amount the panel after the slider
|
|
457
498
|
const unrestrainedPanelAfter = createUnrestrainedPanel(context, panelAfter);
|
|
458
499
|
const panelAfterPreviousValue = panelAfter.currentValue.value;
|
|
459
|
-
const applied = panelBeforePreviousValue
|
|
460
|
-
const panelAfterNewValueRaw = panelAfter.currentValue.value
|
|
500
|
+
const applied = panelBeforePreviousValue.minus(panelBeforeNewValue);
|
|
501
|
+
const panelAfterNewValueRaw = panelAfter.currentValue.value.add(applied);
|
|
461
502
|
let panelAfterNewValue = dragEvent.disregardCollapseBuffer
|
|
462
503
|
? clampUnit(context, unrestrainedPanelAfter, panelAfterNewValueRaw)
|
|
463
504
|
: clampUnit(context, panelAfter, panelAfterNewValueRaw);
|
|
@@ -479,23 +520,23 @@ function updateLayout(context, dragEvent) {
|
|
|
479
520
|
// Calculate the amount "extra" after the minSize the panel should grow
|
|
480
521
|
const extra =
|
|
481
522
|
// Take the size it was at
|
|
482
|
-
getUnitPixelValue(context, panelAfter.collapsedSize)
|
|
523
|
+
getUnitPixelValue(context, panelAfter.collapsedSize)
|
|
483
524
|
// Add in the full overshoot so the cursor is near the slider
|
|
484
|
-
|
|
525
|
+
.add(context.dragOvershoot.abs())
|
|
485
526
|
// Subtract the min size of the panel
|
|
486
|
-
panelAfterNewValue
|
|
527
|
+
.sub(panelAfterNewValue
|
|
487
528
|
// Then re-add the move amount
|
|
488
|
-
Math.abs(moveAmount);
|
|
529
|
+
.add(Math.abs(moveAmount)));
|
|
489
530
|
panelAfter.collapsed = false;
|
|
490
|
-
if (extra
|
|
491
|
-
panelAfterNewValue
|
|
531
|
+
if (extra.gt(0)) {
|
|
532
|
+
panelAfterNewValue = panelAfterNewValue.add(extra);
|
|
492
533
|
}
|
|
493
|
-
panelBeforeNewValue
|
|
534
|
+
panelBeforeNewValue = panelBeforeNewValue
|
|
494
535
|
// Subtract the delta of the after panel's size
|
|
495
|
-
panelAfterNewValue
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
536
|
+
.minus(panelAfterNewValue
|
|
537
|
+
.minus(panelAfterPreviousValue)
|
|
538
|
+
// And then re-apply the movement value
|
|
539
|
+
.minus(Math.abs(moveAmount)));
|
|
499
540
|
if (panelAfter.onCollapseChange?.current &&
|
|
500
541
|
!panelAfter.collapseIsControlled &&
|
|
501
542
|
!dragEvent.controlled) {
|
|
@@ -518,22 +559,21 @@ function updateLayout(context, dragEvent) {
|
|
|
518
559
|
panelBefore.collapsed = true;
|
|
519
560
|
panelBeforeNewValue = getUnitPixelValue(context, panelBefore.collapsedSize);
|
|
520
561
|
// Add the extra space created to the before panel
|
|
521
|
-
panelAfterNewValue
|
|
562
|
+
panelAfterNewValue = panelAfterNewValue.add(panelBeforePreviousValue.minus(panelBeforeNewValue));
|
|
522
563
|
if (panelBefore.onCollapseChange?.current &&
|
|
523
564
|
!panelBefore.collapseIsControlled &&
|
|
524
565
|
!dragEvent.controlled) {
|
|
525
566
|
panelBefore.onCollapseChange.current(true);
|
|
526
567
|
}
|
|
527
568
|
}
|
|
528
|
-
panelBefore.currentValue =
|
|
529
|
-
panelAfter.currentValue =
|
|
530
|
-
const leftoverSpace = getGroupSize(context)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
return { items: newItems, dragOvershoot: 0 };
|
|
569
|
+
panelBefore.currentValue = { type: "pixel", value: panelBeforeNewValue };
|
|
570
|
+
panelAfter.currentValue = { type: "pixel", value: panelAfterNewValue };
|
|
571
|
+
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)));
|
|
572
|
+
if (leftoverSpace.gt(0)) {
|
|
573
|
+
panelBefore.currentValue.value =
|
|
574
|
+
panelBefore.currentValue.value.add(leftoverSpace);
|
|
575
|
+
}
|
|
576
|
+
return { items: newItems };
|
|
537
577
|
}
|
|
538
578
|
/** Converts the items to percentages */
|
|
539
579
|
function commitLayout(context) {
|
|
@@ -557,7 +597,10 @@ function commitLayout(context) {
|
|
|
557
597
|
}
|
|
558
598
|
newItems[index] = {
|
|
559
599
|
...item,
|
|
560
|
-
currentValue:
|
|
600
|
+
currentValue: {
|
|
601
|
+
type: "percent",
|
|
602
|
+
value: item.currentValue.value.div(new big_js_1.default(getGroupSize(context)).sub(staticWidth)),
|
|
603
|
+
},
|
|
561
604
|
};
|
|
562
605
|
});
|
|
563
606
|
return newItems;
|
|
@@ -577,7 +620,7 @@ function dragHandlePayload({ delta, orientation, shiftKey = false, }) {
|
|
|
577
620
|
/** Iteratively applies a large delta value simulating a user's drag */
|
|
578
621
|
function iterativelyUpdateLayout({ context, handleId, delta, direction, controlled, disregardCollapseBuffer, }) {
|
|
579
622
|
let newContext = context;
|
|
580
|
-
for (let i = 0; i <
|
|
623
|
+
for (let i = 0; i < delta.abs().toNumber(); i++) {
|
|
581
624
|
newContext = updateLayout({
|
|
582
625
|
...context,
|
|
583
626
|
...newContext,
|
|
@@ -597,10 +640,11 @@ function iterativelyUpdateLayout({ context, handleId, delta, direction, controll
|
|
|
597
640
|
function applyDeltaInBothDirections(context, newItems, itemIndex, delta) {
|
|
598
641
|
let hasTriedBothDirections = false;
|
|
599
642
|
let direction = 1;
|
|
643
|
+
let deltaLeft = new big_js_1.default(delta);
|
|
600
644
|
// Starting from where the items was removed add space to the panels around it.
|
|
601
645
|
// This is only needed for conditional rendering.
|
|
602
|
-
while (
|
|
603
|
-
const targetPanel = findPanelWithSpace(context, newItems, itemIndex + direction, direction);
|
|
646
|
+
while (deltaLeft.toNumber() !== 0) {
|
|
647
|
+
const targetPanel = findPanelWithSpace(context, newItems, itemIndex + direction, direction, delta.gt(0) ? "add" : "subtract");
|
|
604
648
|
if (!targetPanel) {
|
|
605
649
|
if (hasTriedBothDirections) {
|
|
606
650
|
break;
|
|
@@ -612,44 +656,47 @@ function applyDeltaInBothDirections(context, newItems, itemIndex, delta) {
|
|
|
612
656
|
}
|
|
613
657
|
}
|
|
614
658
|
const oldValue = targetPanel.currentValue.value;
|
|
615
|
-
const newValue = clampUnit(context, targetPanel, oldValue
|
|
659
|
+
const newValue = clampUnit(context, targetPanel, oldValue.add(deltaLeft));
|
|
616
660
|
targetPanel.currentValue.value = newValue;
|
|
617
|
-
|
|
661
|
+
deltaLeft = deltaLeft.sub(newValue.sub(oldValue));
|
|
618
662
|
direction = direction === 1 ? -1 : 1;
|
|
619
663
|
}
|
|
620
664
|
}
|
|
621
665
|
const animationActor = (0, xstate_1.fromPromise)(({ input: { send, context, event } }) => new Promise((resolve) => {
|
|
622
666
|
const panel = getPanelWithId(context, event.panelId);
|
|
623
667
|
const handle = getHandleForPanelId(context, event.panelId);
|
|
624
|
-
let direction = handle.direction;
|
|
625
|
-
let fullDelta = 0;
|
|
668
|
+
let direction = new big_js_1.default(handle.direction);
|
|
669
|
+
let fullDelta = new big_js_1.default(0);
|
|
626
670
|
if (event.type === "expandPanel") {
|
|
627
|
-
fullDelta =
|
|
628
|
-
(panel.sizeBeforeCollapse ?? getUnitPixelValue(context, panel.min)) -
|
|
629
|
-
panel.currentValue.value;
|
|
671
|
+
fullDelta = new big_js_1.default(panel.sizeBeforeCollapse ?? getUnitPixelValue(context, panel.min)).minus(panel.currentValue.value);
|
|
630
672
|
}
|
|
631
673
|
else {
|
|
632
674
|
const collapsedSize = getUnitPixelValue(context, panel.collapsedSize);
|
|
633
|
-
panel.sizeBeforeCollapse = panel.currentValue.value;
|
|
634
|
-
direction
|
|
635
|
-
fullDelta = panel.currentValue.value
|
|
675
|
+
panel.sizeBeforeCollapse = panel.currentValue.value.toNumber();
|
|
676
|
+
direction = direction.mul(new big_js_1.default(-1));
|
|
677
|
+
fullDelta = panel.currentValue.value.minus(collapsedSize);
|
|
636
678
|
}
|
|
637
679
|
const fps = 60;
|
|
638
680
|
const { duration, ease } = getCollapseAnimation(panel);
|
|
639
681
|
const totalFrames = Math.ceil(panel.collapseAnimation ? duration / (1000 / fps) : 1);
|
|
640
682
|
let frame = 0;
|
|
641
|
-
let appliedDelta = 0;
|
|
683
|
+
let appliedDelta = new big_js_1.default(0);
|
|
642
684
|
function renderFrame() {
|
|
643
|
-
const progress =
|
|
644
|
-
const e = panel.collapseAnimation ? ease(progress) : 1;
|
|
645
|
-
const delta = (
|
|
646
|
-
send({
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
685
|
+
const progress = ++frame / totalFrames;
|
|
686
|
+
const e = new big_js_1.default(panel.collapseAnimation ? ease(progress) : 1);
|
|
687
|
+
const delta = e.mul(fullDelta).sub(appliedDelta).mul(direction);
|
|
688
|
+
send({
|
|
689
|
+
type: "applyDelta",
|
|
690
|
+
handleId: handle.item.id,
|
|
691
|
+
delta: delta.toNumber(),
|
|
692
|
+
});
|
|
693
|
+
appliedDelta = appliedDelta.add(delta
|
|
694
|
+
.abs()
|
|
695
|
+
.mul((delta.gt(0) && direction.lt(0)) ||
|
|
696
|
+
(delta.lt(0) && direction.gt(0))
|
|
697
|
+
? -1
|
|
698
|
+
: 1));
|
|
699
|
+
if (e.eq(1)) {
|
|
653
700
|
const action = event.type === "expandPanel" ? "expand" : "collapse";
|
|
654
701
|
resolve({ panelId: panel.id, action });
|
|
655
702
|
return false;
|
|
@@ -669,7 +716,7 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
669
716
|
size: { width: 0, height: 0 },
|
|
670
717
|
items: input.initialItems || [],
|
|
671
718
|
orientation: input.orientation || "horizontal",
|
|
672
|
-
dragOvershoot: 0,
|
|
719
|
+
dragOvershoot: new big_js_1.default(0),
|
|
673
720
|
autosaveId: input.autosaveId,
|
|
674
721
|
groupId: input.groupId,
|
|
675
722
|
}),
|
|
@@ -852,23 +899,29 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
852
899
|
});
|
|
853
900
|
const itemIndex = newItems.findIndex((item) => item.id === event.data.id);
|
|
854
901
|
const newContext = { ...context, items: newItems };
|
|
855
|
-
const overflowDueToHandles = context.items
|
|
902
|
+
const overflowDueToHandles = context.items
|
|
903
|
+
.reduce((acc, i) => {
|
|
856
904
|
if (isPanelHandle(i)) {
|
|
857
|
-
return acc
|
|
905
|
+
return acc.add(getUnitPixelValue(context, i.size));
|
|
858
906
|
}
|
|
859
|
-
return acc
|
|
860
|
-
},
|
|
861
|
-
|
|
907
|
+
return acc.add(i.currentValue.value);
|
|
908
|
+
}, new big_js_1.default(0))
|
|
909
|
+
.minus(getGroupSize(context));
|
|
910
|
+
applyDeltaInBothDirections(newContext, newItems, itemIndex, currentValue.value.add(overflowDueToHandles).neg());
|
|
862
911
|
return newItems;
|
|
863
912
|
},
|
|
864
913
|
}),
|
|
865
914
|
assignPanelHandleData: (0, xstate_1.assign)({
|
|
866
915
|
items: ({ context, event }) => {
|
|
867
916
|
isEvent(event, ["registerPanelHandle"]);
|
|
917
|
+
const unit = parseUnit(event.data.size);
|
|
868
918
|
return addDeDuplicatedItems(context.items, {
|
|
869
919
|
type: "handle",
|
|
870
920
|
...event.data,
|
|
871
|
-
size:
|
|
921
|
+
size: {
|
|
922
|
+
type: "pixel",
|
|
923
|
+
value: new big_js_1.default(unit.value),
|
|
924
|
+
},
|
|
872
925
|
});
|
|
873
926
|
},
|
|
874
927
|
}),
|
|
@@ -896,7 +949,7 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
896
949
|
enqueue.assign(updateLayout(context, event));
|
|
897
950
|
}),
|
|
898
951
|
commit: (0, xstate_1.assign)({
|
|
899
|
-
dragOvershoot: 0,
|
|
952
|
+
dragOvershoot: new big_js_1.default(0),
|
|
900
953
|
items: ({ context }) => commitLayout(context),
|
|
901
954
|
}),
|
|
902
955
|
onApplyDelta: (0, xstate_1.assign)(({ context, event }) => {
|
|
@@ -918,7 +971,9 @@ exports.groupMachine = (0, xstate_1.createMachine)({
|
|
|
918
971
|
const current = panel.currentValue.value;
|
|
919
972
|
const newSize = clampUnit(context, panel, getUnitPixelValue(context, parseUnit(event.size)));
|
|
920
973
|
const isBigger = newSize > current;
|
|
921
|
-
const delta = isBigger
|
|
974
|
+
const delta = isBigger
|
|
975
|
+
? newSize.minus(current)
|
|
976
|
+
: current.minus(newSize);
|
|
922
977
|
enqueue.assign(iterativelyUpdateLayout({
|
|
923
978
|
context,
|
|
924
979
|
direction: (handle.direction * (isBigger ? 1 : -1)),
|