@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.
Files changed (43) hide show
  1. package/.tshy/commonjs.json +1 -0
  2. package/.tshy/esm.json +1 -0
  3. package/.tshy-build/esm/index.d.ts +327 -0
  4. package/.tshy-build/esm/index.d.ts.map +1 -0
  5. package/.tshy-build/esm/index.js +964 -0
  6. package/.tshy-build/esm/index.js.map +1 -0
  7. package/.tshy-build/esm/package.json +3 -0
  8. package/.turbo/turbo-build.log +1 -1
  9. package/.turbo/turbo-lint.log +1 -1
  10. package/.turbo/turbo-test.log +1023 -129
  11. package/coverage/clover.xml +358 -345
  12. package/coverage/coverage-final.json +1 -1
  13. package/coverage/index.html +18 -18
  14. package/coverage/index.ts.html +624 -402
  15. package/dist/commonjs/index.d.ts +22 -9
  16. package/dist/commonjs/index.d.ts.map +1 -1
  17. package/dist/commonjs/index.js +189 -134
  18. package/dist/commonjs/index.js.map +1 -1
  19. package/dist/esm/index.d.ts +22 -9
  20. package/dist/esm/index.d.ts.map +1 -1
  21. package/dist/esm/index.js +188 -114
  22. package/dist/esm/index.js.map +1 -1
  23. package/package.json +6 -6
  24. package/src/index.ts +279 -153
  25. package/src/machine.test.ts +174 -85
  26. package/src/package.json +3 -0
  27. package/src/utils.test.ts +22 -9
  28. package/dist/commonjs/machine.test.d.ts +0 -5
  29. package/dist/commonjs/machine.test.d.ts.map +0 -1
  30. package/dist/commonjs/machine.test.js +0 -1038
  31. package/dist/commonjs/machine.test.js.map +0 -1
  32. package/dist/commonjs/utils.test.d.ts +0 -2
  33. package/dist/commonjs/utils.test.d.ts.map +0 -1
  34. package/dist/commonjs/utils.test.js +0 -79
  35. package/dist/commonjs/utils.test.js.map +0 -1
  36. package/dist/esm/machine.test.d.ts +0 -5
  37. package/dist/esm/machine.test.d.ts.map +0 -1
  38. package/dist/esm/machine.test.js +0 -1036
  39. package/dist/esm/machine.test.js.map +0 -1
  40. package/dist/esm/utils.test.d.ts +0 -2
  41. package/dist/esm/utils.test.d.ts.map +0 -1
  42. package/dist/esm/utils.test.js +0 -77
  43. package/dist/esm/utils.test.js.map +0 -1
@@ -1,1038 +0,0 @@
1
- "use strict";
2
- /**
3
- * @vitest-environment jsdom
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const vitest_1 = require("vitest");
7
- const index_js_1 = require("./index.js");
8
- const xstate_1 = require("xstate");
9
- // import { spring } from "framer-motion";
10
- function getTemplate(actor) {
11
- return (0, index_js_1.buildTemplate)(actor.getSnapshot().context);
12
- }
13
- const handleSize = {
14
- type: "pixel",
15
- value: 10,
16
- };
17
- function dragHandle(actor, options) {
18
- for (let i = 0; i < Math.abs(options.delta); i++) {
19
- actor.send({
20
- type: "dragHandle",
21
- handleId: options.id,
22
- value: (0, index_js_1.dragHandlePayload)({
23
- orientation: options.orientation || "horizontal",
24
- delta: options.delta > 0 ? 1 : -1,
25
- shiftKey: options.shiftKey,
26
- }),
27
- });
28
- }
29
- }
30
- function sendAll(actor, events) {
31
- for (const event of events) {
32
- actor.send(event);
33
- }
34
- }
35
- function capturePixelValues(actor, cb) {
36
- const firstHandle = actor
37
- .getSnapshot()
38
- .context.items.find((i) => (0, index_js_1.isPanelHandle)(i));
39
- if (firstHandle) {
40
- actor.send({ type: "dragHandleStart", handleId: firstHandle.id });
41
- }
42
- cb();
43
- if (firstHandle) {
44
- actor.send({ type: "dragHandleEnd", handleId: firstHandle.id });
45
- }
46
- }
47
- function waitForIdle(actor) {
48
- return new Promise((resolve) => {
49
- setInterval(() => {
50
- const snapshot = actor.getSnapshot();
51
- if (snapshot.value === "idle") {
52
- resolve();
53
- }
54
- }, 100);
55
- });
56
- }
57
- function initializeSizes(actor, options) {
58
- const context = actor.getSnapshot().context;
59
- const { orientation, items } = context;
60
- const template = (0, index_js_1.buildTemplate)(context);
61
- const div = document.createElement("div");
62
- div.style.width = `${options.width}px`;
63
- div.style.height = `${options.height}px`;
64
- div.style.display = "grid";
65
- div.id = "group";
66
- if (orientation === "horizontal") {
67
- div.style.gridTemplateColumns = template;
68
- }
69
- else {
70
- div.style.gridTemplateRows = template;
71
- }
72
- for (let i = 0; i < items.length; i++) {
73
- div.appendChild(document.createElement("div"));
74
- }
75
- document.body.appendChild(div);
76
- const childrenSizes = {};
77
- div.childNodes.forEach((node, index) => {
78
- const item = items[index];
79
- if (node instanceof HTMLElement && item) {
80
- const rect = node.getBoundingClientRect();
81
- childrenSizes[item.id] = {
82
- width: rect.width,
83
- height: rect.height,
84
- };
85
- }
86
- });
87
- actor.send({
88
- type: "setSize",
89
- size: { width: options.width, height: options.height },
90
- });
91
- actor.send({
92
- type: "setActualItemsSize",
93
- childrenSizes,
94
- });
95
- }
96
- (0, vitest_1.describe)("constraints", () => {
97
- (0, vitest_1.test)("works with 2 simple panels - horizontal", () => {
98
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
99
- input: { groupId: "group" },
100
- }).start();
101
- sendAll(actor, [
102
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
103
- {
104
- type: "registerPanelHandle",
105
- data: { id: "resizer-1", size: handleSize },
106
- },
107
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-2" }) },
108
- ]);
109
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(0px, 1fr)"`);
110
- initializeSizes(actor, { width: 500, height: 200 });
111
- // Drag the resizer to the right
112
- capturePixelValues(actor, () => {
113
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
114
- dragHandle(actor, { id: "resizer-1", delta: 10 });
115
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"255px 10px 235px"`);
116
- });
117
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(0.5204081632653061 * (100% - 10px)), 100%)) 10px minmax(0px, min(calc(0.47959183673469385 * (100% - 10px)), 100%))"`);
118
- // Drag the resizer to the left
119
- capturePixelValues(actor, () => {
120
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"255px 10px 235px"`);
121
- dragHandle(actor, { id: "resizer-1", delta: -20 });
122
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"235px 10px 255px"`);
123
- });
124
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(0.47959183673469385 * (100% - 10px)), 100%)) 10px minmax(0px, min(calc(0.5204081632653061 * (100% - 10px)), 100%))"`);
125
- });
126
- (0, vitest_1.test)("works with 2 simple panels - vertical", () => {
127
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
128
- input: { orientation: "vertical", groupId: "group" },
129
- }).start();
130
- sendAll(actor, [
131
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
132
- {
133
- type: "registerPanelHandle",
134
- data: { id: "resizer-1", size: handleSize },
135
- },
136
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-2" }) },
137
- ]);
138
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(0px, 1fr)"`);
139
- initializeSizes(actor, { width: 200, height: 500 });
140
- // Drag the resizer down
141
- capturePixelValues(actor, () => {
142
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
143
- dragHandle(actor, {
144
- id: "resizer-1",
145
- delta: 10,
146
- orientation: "vertical",
147
- });
148
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"255px 10px 235px"`);
149
- });
150
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(0.5204081632653061 * (100% - 10px)), 100%)) 10px minmax(0px, min(calc(0.47959183673469385 * (100% - 10px)), 100%))"`);
151
- // Drag the resizer to the up
152
- capturePixelValues(actor, () => {
153
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"255px 10px 235px"`);
154
- dragHandle(actor, {
155
- id: "resizer-1",
156
- delta: -20,
157
- orientation: "vertical",
158
- });
159
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"235px 10px 255px"`);
160
- });
161
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(0.47959183673469385 * (100% - 10px)), 100%)) 10px minmax(0px, min(calc(0.5204081632653061 * (100% - 10px)), 100%))"`);
162
- });
163
- (0, vitest_1.test)("doesn't register a panel with the same id twice", () => {
164
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
165
- input: {
166
- groupId: "group",
167
- initialItems: [(0, index_js_1.initializePanel)({ id: "panel-1" })],
168
- },
169
- }).start();
170
- actor.send({
171
- type: "registerPanel",
172
- data: (0, index_js_1.initializePanel)({ id: "panel-1" }),
173
- });
174
- (0, vitest_1.expect)(actor.getSnapshot().context.items).toHaveLength(1);
175
- });
176
- (0, vitest_1.test)("works with 2 simple panels as input", () => {
177
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
178
- input: {
179
- groupId: "group",
180
- initialItems: [
181
- (0, index_js_1.initializePanel)({ id: "panel-1" }),
182
- {
183
- type: "handle",
184
- id: "resizer-1",
185
- size: { type: "pixel", value: 10 },
186
- },
187
- (0, index_js_1.initializePanel)({ id: "panel-2" }),
188
- ],
189
- },
190
- }).start();
191
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(0px, 1fr)"`);
192
- initializeSizes(actor, { width: 500, height: 200 });
193
- capturePixelValues(actor, () => {
194
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
195
- });
196
- });
197
- (0, vitest_1.test)("no delta does nothing", () => {
198
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
199
- input: {
200
- groupId: "group",
201
- initialItems: [
202
- (0, index_js_1.initializePanel)({ id: "panel-1" }),
203
- {
204
- type: "handle",
205
- id: "resizer-1",
206
- size: { type: "pixel", value: 10 },
207
- },
208
- (0, index_js_1.initializePanel)({ id: "panel-2" }),
209
- ],
210
- },
211
- }).start();
212
- initializeSizes(actor, { width: 500, height: 200 });
213
- capturePixelValues(actor, () => {
214
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
215
- actor.send({
216
- type: "dragHandle",
217
- handleId: "resizer-1",
218
- value: (0, index_js_1.dragHandlePayload)({ delta: 0, orientation: "horizontal" }),
219
- });
220
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
221
- });
222
- });
223
- (0, vitest_1.test)("shift key makes it drag more", () => {
224
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
225
- input: {
226
- groupId: "group",
227
- initialItems: [
228
- (0, index_js_1.initializePanel)({ id: "panel-1" }),
229
- {
230
- type: "handle",
231
- id: "resizer-1",
232
- size: { type: "pixel", value: 10 },
233
- },
234
- (0, index_js_1.initializePanel)({ id: "panel-2" }),
235
- ],
236
- },
237
- }).start();
238
- initializeSizes(actor, { width: 500, height: 200 });
239
- capturePixelValues(actor, () => {
240
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
241
- dragHandle(actor, { id: "resizer-1", delta: -1, shiftKey: true });
242
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"230px 10px 260px"`);
243
- });
244
- });
245
- (0, vitest_1.test)("works with percentages", () => {
246
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
247
- input: {
248
- groupId: "group",
249
- initialItems: [
250
- (0, index_js_1.initializePanel)({ id: "panel-1", min: "40%" }),
251
- {
252
- type: "handle",
253
- id: "resizer-1",
254
- size: { type: "pixel", value: 10 },
255
- },
256
- (0, index_js_1.initializePanel)({ id: "panel-2", min: "10%", default: "30%" }),
257
- ],
258
- },
259
- }).start();
260
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(40%, 1fr) 10px 30%"`);
261
- initializeSizes(actor, { width: 500, height: 200 });
262
- capturePixelValues(actor, () => {
263
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"340px 10px 150px"`);
264
- dragHandle(actor, { id: "resizer-1", delta: -200 });
265
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"200px 10px 290px"`);
266
- });
267
- });
268
- (0, vitest_1.test)("supports max", () => {
269
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
270
- input: {
271
- groupId: "group",
272
- initialItems: [
273
- (0, index_js_1.initializePanel)({ id: "panel-1", max: "90%" }),
274
- {
275
- type: "handle",
276
- id: "resizer-1",
277
- size: { type: "pixel", value: 10 },
278
- },
279
- (0, index_js_1.initializePanel)({ id: "panel-2", default: "30%" }),
280
- ],
281
- },
282
- }).start();
283
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 90%) 10px 30%"`);
284
- initializeSizes(actor, { width: 500, height: 200 });
285
- capturePixelValues(actor, () => {
286
- dragHandle(actor, { id: "resizer-1", delta: 400 });
287
- });
288
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(0.9183673469387755 * (100% - 10px)), 90%)) 10px minmax(0px, min(calc(0.08163265306122448 * (100% - 10px)), 100%))"`);
289
- });
290
- (0, vitest_1.test)("panel can have a min", () => {
291
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
292
- input: { groupId: "group" },
293
- }).start();
294
- sendAll(actor, [
295
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
296
- {
297
- type: "registerPanelHandle",
298
- data: { id: "resizer-1", size: handleSize },
299
- },
300
- {
301
- type: "registerPanel",
302
- data: (0, index_js_1.initializePanel)({ id: "panel-2", min: "100px" }),
303
- },
304
- ]);
305
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(100px, 1fr)"`);
306
- initializeSizes(actor, { width: 500, height: 200 });
307
- capturePixelValues(actor, () => {
308
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
309
- dragHandle(actor, { id: "resizer-1", delta: 200 });
310
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
311
- });
312
- });
313
- (0, vitest_1.test)("panel can have a max", () => {
314
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
315
- input: { groupId: "group" },
316
- }).start();
317
- sendAll(actor, [
318
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
319
- {
320
- type: "registerPanelHandle",
321
- data: { id: "resizer-1", size: handleSize },
322
- },
323
- {
324
- type: "registerPanel",
325
- data: (0, index_js_1.initializePanel)({ id: "panel-2", max: "300px" }),
326
- },
327
- ]);
328
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(0px, 300px)"`);
329
- initializeSizes(actor, { width: 500, height: 200 });
330
- // Drag the resizer to the right
331
- capturePixelValues(actor, () => {
332
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"190px 10px 300px"`);
333
- dragHandle(actor, { id: "resizer-1", delta: -200 });
334
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"190px 10px 300px"`);
335
- });
336
- });
337
- (0, vitest_1.test)("panel can have a default size", () => {
338
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
339
- input: { groupId: "group" },
340
- }).start();
341
- sendAll(actor, [
342
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
343
- {
344
- type: "registerPanelHandle",
345
- data: { id: "resizer-1", size: handleSize },
346
- },
347
- {
348
- type: "registerPanel",
349
- data: (0, index_js_1.initializePanel)({ id: "panel-2", default: "300px" }),
350
- },
351
- ]);
352
- initializeSizes(actor, { width: 500, height: 200 });
353
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, min(calc(1 * (100% - 310px)), 100%)) 10px minmax(0px, min(calc(1.5789473684210527 * (100% - 310px)), 100%))"`);
354
- capturePixelValues(actor, () => {
355
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"190px 10px 300px"`);
356
- });
357
- });
358
- (0, vitest_1.test)("dragging eats space from multiple panels in front of it", () => {
359
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
360
- input: { groupId: "group" },
361
- }).start();
362
- sendAll(actor, [
363
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
364
- {
365
- type: "registerPanelHandle",
366
- data: { id: "resizer-1", size: handleSize },
367
- },
368
- {
369
- type: "registerPanel",
370
- data: (0, index_js_1.initializePanel)({
371
- id: "panel-2",
372
- min: "200px",
373
- default: "300px",
374
- }),
375
- },
376
- {
377
- type: "registerPanelHandle",
378
- data: { id: "resizer-2", size: handleSize },
379
- },
380
- {
381
- type: "registerPanel",
382
- data: (0, index_js_1.initializePanel)({ id: "panel-3", min: "100px" }),
383
- },
384
- ]);
385
- initializeSizes(actor, { width: 500, height: 200 });
386
- capturePixelValues(actor, () => {
387
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"80px 10px 300px 10px 100px"`);
388
- dragHandle(actor, { id: "resizer-1", delta: 160 });
389
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"180px 10px 200px 10px 100px"`);
390
- });
391
- });
392
- (0, vitest_1.test)("can set a panel's size", () => {
393
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
394
- input: {
395
- groupId: "group",
396
- initialItems: [
397
- (0, index_js_1.initializePanel)({ id: "panel-1" }),
398
- {
399
- type: "handle",
400
- id: "resizer-1",
401
- size: { type: "pixel", value: 10 },
402
- },
403
- (0, index_js_1.initializePanel)({ id: "panel-2" }),
404
- ],
405
- },
406
- }).start();
407
- initializeSizes(actor, { width: 500, height: 200 });
408
- actor.send({
409
- type: "setPanelPixelSize",
410
- panelId: "panel-1",
411
- size: "100px",
412
- });
413
- capturePixelValues(actor, () => {
414
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"100px 10px 390px"`);
415
- });
416
- actor.send({
417
- type: "setPanelPixelSize",
418
- panelId: "panel-1",
419
- size: "25%",
420
- });
421
- capturePixelValues(actor, () => {
422
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"125px 10px 365px"`);
423
- });
424
- });
425
- (0, vitest_1.test)("can update orientation at runtime", () => {
426
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
427
- input: { groupId: "group" },
428
- }).start();
429
- sendAll(actor, [
430
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
431
- {
432
- type: "registerPanelHandle",
433
- data: { id: "resizer-1", size: handleSize },
434
- },
435
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-2" }) },
436
- ]);
437
- initializeSizes(actor, { width: 500, height: 200 });
438
- capturePixelValues(actor, () => {
439
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
440
- });
441
- actor.send({ type: "setOrientation", orientation: "vertical" });
442
- capturePixelValues(actor, () => {
443
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"95px 10px 95px"`);
444
- });
445
- });
446
- });
447
- (0, vitest_1.describe)("collapsible panel", () => {
448
- // const springAnimation = spring({
449
- // keyframes: [0, 1],
450
- // velocity: 1,
451
- // stiffness: 100,
452
- // damping: 10,
453
- // mass: 1.0,
454
- // });
455
- // const springEasing = (t: number) => springAnimation.next(t * 1000).value;
456
- vitest_1.test.each([
457
- undefined,
458
- "ease-in-out",
459
- // The math is wrong, enable after Decimal128
460
- // { duration: 1000, easing: springEasing },
461
- ])("panel can be collapsible: %s", async (animation) => {
462
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
463
- input: { groupId: "group" },
464
- }).start();
465
- sendAll(actor, [
466
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
467
- {
468
- type: "registerPanelHandle",
469
- data: { id: "resizer-1", size: handleSize },
470
- },
471
- {
472
- type: "registerPanel",
473
- data: (0, index_js_1.initializePanel)({
474
- id: "panel-2",
475
- collapsible: true,
476
- min: "100px",
477
- collapseAnimation: animation,
478
- }),
479
- },
480
- ]);
481
- (0, vitest_1.expect)(getTemplate(actor)).toBe("minmax(0px, 1fr) 10px minmax(100px, 1fr)");
482
- initializeSizes(actor, { width: 500, height: 200 });
483
- // Test dragging to collapse the panel
484
- capturePixelValues(actor, () => {
485
- (0, vitest_1.expect)(getTemplate(actor)).toBe("245px 10px 245px");
486
- // Drag into the drag buffer but not past it
487
- dragHandle(actor, { id: "resizer-1", delta: 160 });
488
- (0, vitest_1.expect)(getTemplate(actor)).toBe("390px 10px 100px");
489
- // Drag past the drag buffer and collapse the panel
490
- dragHandle(actor, { id: "resizer-1", delta: 100 });
491
- (0, vitest_1.expect)(getTemplate(actor)).toBe("490px 10px 0px");
492
- });
493
- (0, vitest_1.expect)(getTemplate(actor)).toBe("minmax(0px, min(calc(1 * (100% - 10px)), 100%)) 10px 0px");
494
- // Test dragging to expand the panel
495
- capturePixelValues(actor, () => {
496
- (0, vitest_1.expect)(getTemplate(actor)).toBe("490px 10px 0px");
497
- // Stays oollapsed in the buffer
498
- dragHandle(actor, { id: "resizer-1", delta: -30 });
499
- (0, vitest_1.expect)(getTemplate(actor)).toBe("490px 10px 0px");
500
- // Opens once the buffer is cleared
501
- dragHandle(actor, { id: "resizer-1", delta: -20 });
502
- (0, vitest_1.expect)(getTemplate(actor)).toBe("390px 10px 100px");
503
- });
504
- actor.send({ type: "collapsePanel", panelId: "panel-2" });
505
- await waitForIdle(actor);
506
- capturePixelValues(actor, () => {
507
- (0, vitest_1.expect)(getTemplate(actor)).toBe("490px 10px 0px");
508
- });
509
- });
510
- (0, vitest_1.test)("collapsible panel can have collapsed size - right", async () => {
511
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
512
- input: { groupId: "group" },
513
- }).start();
514
- sendAll(actor, [
515
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
516
- {
517
- type: "registerPanelHandle",
518
- data: { id: "resizer-1", size: handleSize },
519
- },
520
- {
521
- type: "registerPanel",
522
- data: (0, index_js_1.initializePanel)({
523
- id: "panel-2",
524
- collapsible: true,
525
- defaultCollapsed: true,
526
- min: "200px",
527
- collapsedSize: "60px",
528
- }),
529
- },
530
- ]);
531
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px 60px"`);
532
- initializeSizes(actor, { width: 500, height: 200 });
533
- capturePixelValues(actor, () => {
534
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"430px 10px 60px"`);
535
- // Drag into the the panel
536
- dragHandle(actor, { id: "resizer-1", delta: 50 });
537
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"430px 10px 60px"`);
538
- // Drag into the start
539
- dragHandle(actor, { id: "resizer-1", delta: -50 });
540
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"430px 10px 60px"`);
541
- // Drag into the drag buffer but not past it
542
- dragHandle(actor, { id: "resizer-1", delta: -25 });
543
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"430px 10px 60px"`);
544
- // Drag past the buffer
545
- dragHandle(actor, { id: "resizer-1", delta: -25 });
546
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"290px 10px 200px"`);
547
- });
548
- });
549
- (0, vitest_1.test)("can expand default collapsed panel via event", async () => {
550
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
551
- input: { groupId: "group" },
552
- }).start();
553
- sendAll(actor, [
554
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
555
- {
556
- type: "registerPanelHandle",
557
- data: { id: "resizer-1", size: handleSize },
558
- },
559
- {
560
- type: "registerPanel",
561
- data: (0, index_js_1.initializePanel)({
562
- id: "panel-2",
563
- collapsible: true,
564
- defaultCollapsed: true,
565
- min: "200px",
566
- collapsedSize: "60px",
567
- }),
568
- },
569
- ]);
570
- initializeSizes(actor, { width: 500, height: 200 });
571
- actor.send({ type: "expandPanel", panelId: "panel-2" });
572
- await waitForIdle(actor);
573
- capturePixelValues(actor, () => {
574
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"290px 10px 200px"`);
575
- });
576
- });
577
- (0, vitest_1.test)("collapsible panel can have collapsed size - left", async () => {
578
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
579
- input: { groupId: "group" },
580
- }).start();
581
- sendAll(actor, [
582
- {
583
- type: "registerPanel",
584
- data: (0, index_js_1.initializePanel)({
585
- id: "panel-2",
586
- collapsible: true,
587
- defaultCollapsed: true,
588
- min: "200px",
589
- collapsedSize: "60px",
590
- }),
591
- },
592
- {
593
- type: "registerPanelHandle",
594
- data: { id: "resizer-1", size: handleSize },
595
- },
596
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
597
- ]);
598
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"60px 10px minmax(0px, 1fr)"`);
599
- initializeSizes(actor, { width: 500, height: 200 });
600
- capturePixelValues(actor, () => {
601
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"60px 10px 430px"`);
602
- // Drag into the the panel
603
- dragHandle(actor, { id: "resizer-1", delta: -50 });
604
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"60px 10px 430px"`);
605
- // Drag to the start
606
- dragHandle(actor, { id: "resizer-1", delta: 50 });
607
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"60px 10px 430px"`);
608
- // Drag into the drag buffer but not past it
609
- dragHandle(actor, { id: "resizer-1", delta: 25 });
610
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"60px 10px 430px"`);
611
- // Drag past the buffer
612
- dragHandle(actor, { id: "resizer-1", delta: 25 });
613
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"200px 10px 290px"`);
614
- });
615
- });
616
- (0, vitest_1.test)("collapsible remembers last position", async () => {
617
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
618
- input: { groupId: "group" },
619
- }).start();
620
- sendAll(actor, [
621
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
622
- {
623
- type: "registerPanelHandle",
624
- data: { id: "resizer-1", size: handleSize },
625
- },
626
- {
627
- type: "registerPanel",
628
- data: (0, index_js_1.initializePanel)({
629
- id: "panel-2",
630
- collapsible: true,
631
- min: "200px",
632
- collapsedSize: "60px",
633
- }),
634
- },
635
- ]);
636
- initializeSizes(actor, { width: 500, height: 200 });
637
- capturePixelValues(actor, () => {
638
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
639
- dragHandle(actor, { id: "resizer-1", delta: -50 });
640
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"195px 10px 295px"`);
641
- });
642
- actor.send({ type: "collapsePanel", panelId: "panel-2" });
643
- await waitForIdle(actor);
644
- capturePixelValues(actor, () => {
645
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"430px 10px 60px"`);
646
- });
647
- actor.send({ type: "expandPanel", panelId: "panel-2" });
648
- await waitForIdle(actor);
649
- capturePixelValues(actor, () => {
650
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"195px 10px 295px"`);
651
- });
652
- });
653
- (0, vitest_1.test)("panel can collapse can subscribe to collapsed state", () => {
654
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
655
- input: { groupId: "group" },
656
- }).start();
657
- const spy = vitest_1.vi.fn();
658
- sendAll(actor, [
659
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
660
- {
661
- type: "registerPanelHandle",
662
- data: { id: "resizer-1", size: handleSize },
663
- },
664
- {
665
- type: "registerPanel",
666
- data: (0, index_js_1.initializePanel)({
667
- id: "panel-2",
668
- collapsible: true,
669
- min: "100px",
670
- onCollapseChange: {
671
- current: spy,
672
- },
673
- }),
674
- },
675
- ]);
676
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(100px, 1fr)"`);
677
- initializeSizes(actor, { width: 500, height: 200 });
678
- // collapse the panel
679
- capturePixelValues(actor, () => {
680
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
681
- // Drag into the drag buffer but not past it
682
- dragHandle(actor, { id: "resizer-1", delta: 160 });
683
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
684
- // Drag past the drag buffer and collapse the panel
685
- dragHandle(actor, { id: "resizer-1", delta: 100 });
686
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(true);
687
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"490px 10px 0px"`);
688
- });
689
- spy.mockReset();
690
- // expand the panel
691
- capturePixelValues(actor, () => {
692
- // The panel doesn't actually expand yet
693
- dragHandle(actor, { id: "resizer-1", delta: -150 });
694
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"290px 10px 200px"`);
695
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(false);
696
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"290px 10px 200px"`);
697
- // Actually collapse the panel
698
- actor.send({
699
- type: "expandPanel",
700
- panelId: "panel-2",
701
- controlled: true,
702
- });
703
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"290px 10px 200px"`);
704
- });
705
- });
706
- (0, vitest_1.test)("should be able to trigger collapse/expand via event", async () => {
707
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
708
- input: { groupId: "group" },
709
- }).start();
710
- sendAll(actor, [
711
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
712
- {
713
- type: "registerPanelHandle",
714
- data: { id: "resizer-1", size: handleSize },
715
- },
716
- {
717
- type: "registerPanel",
718
- data: (0, index_js_1.initializePanel)({
719
- id: "panel-2",
720
- collapsible: true,
721
- min: "100px",
722
- default: "100px",
723
- }),
724
- },
725
- ]);
726
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px 100px"`);
727
- initializeSizes(actor, { width: 500, height: 200 });
728
- capturePixelValues(actor, () => {
729
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
730
- });
731
- actor.send({ type: "collapsePanel", panelId: "panel-2" });
732
- await waitForIdle(actor);
733
- capturePixelValues(actor, () => {
734
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"490px 10px 0px"`);
735
- });
736
- actor.send({ type: "expandPanel", panelId: "panel-2" });
737
- await waitForIdle(actor);
738
- capturePixelValues(actor, () => {
739
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
740
- });
741
- });
742
- (0, vitest_1.test)("panel collapse can be controlled", async () => {
743
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
744
- input: { groupId: "group" },
745
- }).start();
746
- const spy = vitest_1.vi.fn();
747
- sendAll(actor, [
748
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
749
- {
750
- type: "registerPanelHandle",
751
- data: { id: "resizer-1", size: handleSize },
752
- },
753
- {
754
- type: "registerPanel",
755
- data: (0, index_js_1.initializePanel)({
756
- id: "panel-2",
757
- collapsible: true,
758
- min: "100px",
759
- // This marks the collapse as controlled
760
- collapsed: false,
761
- collapsedSize: "20px",
762
- onCollapseChange: {
763
- current: spy,
764
- },
765
- }),
766
- },
767
- ]);
768
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"minmax(0px, 1fr) 10px minmax(100px, 1fr)"`);
769
- initializeSizes(actor, { width: 500, height: 200 });
770
- // collapse the panel via drag
771
- capturePixelValues(actor, () => {
772
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
773
- dragHandle(actor, { id: "resizer-1", delta: 160 });
774
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
775
- // The panel doesn't actually collapse yet
776
- dragHandle(actor, { id: "resizer-1", delta: 100 });
777
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(true);
778
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"390px 10px 100px"`);
779
- // Actually collapse the panel
780
- actor.send({
781
- type: "collapsePanel",
782
- panelId: "panel-2",
783
- controlled: true,
784
- });
785
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"470px 10px 20px"`);
786
- });
787
- spy.mockReset();
788
- // expand the panel via drag
789
- capturePixelValues(actor, () => {
790
- // The panel doesn't actually expand yet
791
- dragHandle(actor, { id: "resizer-1", delta: -150 });
792
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"470px 10px 20px"`);
793
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(false);
794
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"470px 10px 20px"`);
795
- // Actually collapse the panel
796
- actor.send({
797
- type: "expandPanel",
798
- panelId: "panel-2",
799
- controlled: true,
800
- });
801
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"319px 10px 171px"`);
802
- });
803
- spy.mockReset();
804
- actor.send({ type: "collapsePanel", panelId: "panel-2" });
805
- await waitForIdle(actor);
806
- // collapse the panel via drag
807
- capturePixelValues(actor, () => {
808
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"319px 10px 171px"`);
809
- });
810
- actor.send({ type: "expandPanel", panelId: "panel-2" });
811
- await waitForIdle(actor);
812
- // collapse the panel via drag
813
- capturePixelValues(actor, () => {
814
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"319px 10px 171px"`);
815
- });
816
- });
817
- });
818
- (0, vitest_1.describe)("conditional panel", () => {
819
- (0, vitest_1.test)("panel can be conditionally rendered", () => {
820
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
821
- input: { groupId: "group" },
822
- }).start();
823
- sendAll(actor, [
824
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
825
- {
826
- type: "registerPanelHandle",
827
- data: { id: "resizer-1", size: handleSize },
828
- },
829
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-2" }) },
830
- ]);
831
- initializeSizes(actor, { width: 500, height: 200 });
832
- capturePixelValues(actor, () => {
833
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
834
- });
835
- sendAll(actor, [
836
- {
837
- type: "registerPanelHandle",
838
- data: { id: "resizer-2", size: handleSize },
839
- },
840
- {
841
- type: "registerDynamicPanel",
842
- data: (0, index_js_1.initializePanel)({ id: "panel-3", min: "100px" }),
843
- },
844
- ]);
845
- capturePixelValues(actor, () => {
846
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 140px 10px 100px"`);
847
- });
848
- sendAll(actor, [
849
- { type: "unregisterPanelHandle", id: "resizer-2" },
850
- { type: "unregisterPanel", id: "panel-3" },
851
- ]);
852
- capturePixelValues(actor, () => {
853
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 250px"`);
854
- });
855
- });
856
- (0, vitest_1.test)("collapsed panel can be conditionally rendered", () => {
857
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
858
- input: { groupId: "group" },
859
- }).start();
860
- sendAll(actor, [
861
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
862
- {
863
- type: "registerPanelHandle",
864
- data: { id: "resizer-1", size: handleSize },
865
- },
866
- {
867
- type: "registerPanel",
868
- data: (0, index_js_1.initializePanel)({ id: "panel-2" }),
869
- },
870
- ]);
871
- initializeSizes(actor, { width: 500, height: 200 });
872
- capturePixelValues(actor, () => {
873
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
874
- });
875
- sendAll(actor, [
876
- {
877
- type: "registerPanelHandle",
878
- data: { id: "resizer-2", size: handleSize },
879
- },
880
- {
881
- type: "registerDynamicPanel",
882
- data: (0, index_js_1.initializePanel)({
883
- id: "panel-3",
884
- min: "100px",
885
- collapsible: true,
886
- defaultCollapsed: true,
887
- }),
888
- },
889
- ]);
890
- capturePixelValues(actor, () => {
891
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 240px 10px 0px"`);
892
- });
893
- sendAll(actor, [
894
- { type: "unregisterPanelHandle", id: "resizer-2" },
895
- { type: "unregisterPanel", id: "panel-3" },
896
- ]);
897
- capturePixelValues(actor, () => {
898
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 250px"`);
899
- });
900
- });
901
- (0, vitest_1.test)("panel can be conditionally rendered at default width", () => {
902
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
903
- input: { groupId: "group" },
904
- }).start();
905
- sendAll(actor, [
906
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
907
- {
908
- type: "registerPanelHandle",
909
- data: { id: "resizer-1", size: handleSize },
910
- },
911
- {
912
- type: "registerPanel",
913
- data: (0, index_js_1.initializePanel)({ id: "panel-2" }),
914
- },
915
- ]);
916
- initializeSizes(actor, { width: 500, height: 200 });
917
- capturePixelValues(actor, () => {
918
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
919
- });
920
- sendAll(actor, [
921
- {
922
- type: "registerPanelHandle",
923
- data: { id: "resizer-2", size: handleSize },
924
- },
925
- {
926
- type: "registerDynamicPanel",
927
- data: (0, index_js_1.initializePanel)({
928
- id: "panel-3",
929
- default: "125px",
930
- }),
931
- },
932
- ]);
933
- capturePixelValues(actor, () => {
934
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 115px 10px 125px"`);
935
- });
936
- sendAll(actor, [
937
- { type: "unregisterPanelHandle", id: "resizer-2" },
938
- { type: "unregisterPanel", id: "panel-3" },
939
- ]);
940
- capturePixelValues(actor, () => {
941
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 250px"`);
942
- });
943
- });
944
- (0, vitest_1.test)("panel can be conditionally rendered w/order", () => {
945
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
946
- input: { groupId: "group" },
947
- }).start();
948
- sendAll(actor, [
949
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-1" }) },
950
- {
951
- type: "registerPanelHandle",
952
- data: { id: "resizer-1", size: handleSize },
953
- },
954
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "panel-2" }) },
955
- ]);
956
- initializeSizes(actor, { width: 500, height: 200 });
957
- capturePixelValues(actor, () => {
958
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
959
- });
960
- sendAll(actor, [
961
- {
962
- type: "registerPanelHandle",
963
- data: { id: "resizer-2", size: handleSize, order: 1 },
964
- },
965
- {
966
- type: "registerDynamicPanel",
967
- data: {
968
- ...(0, index_js_1.initializePanel)({ id: "panel-3", min: "100px" }),
969
- order: 2,
970
- },
971
- },
972
- ]);
973
- capturePixelValues(actor, () => {
974
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 100px 10px 140px"`);
975
- });
976
- sendAll(actor, [
977
- { type: "unregisterPanelHandle", id: "resizer-2" },
978
- { type: "unregisterPanel", id: "panel-3" },
979
- ]);
980
- capturePixelValues(actor, () => {
981
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 250px"`);
982
- });
983
- sendAll(actor, [
984
- { type: "unregisterPanelHandle", id: "resizer-2" },
985
- { type: "unregisterPanel", id: "panel-3" },
986
- ]);
987
- capturePixelValues(actor, () => {
988
- (0, vitest_1.expect)(getTemplate(actor)).toMatchInlineSnapshot(`"240px 10px 250px"`);
989
- });
990
- });
991
- });
992
- (0, vitest_1.describe)("errors", () => {
993
- (0, vitest_1.test)("throws for invalid units", () => {
994
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
995
- input: { groupId: "group" },
996
- }).start();
997
- (0, vitest_1.expect)(() => actor.send({
998
- type: "registerPanel",
999
- // @ts-expect-error Testing the error
1000
- data: (0, index_js_1.initializePanel)({ id: "panel-1", min: "40fr" }),
1001
- })).toThrowErrorMatchingInlineSnapshot(`[Error: Invalid unit: 40fr]`);
1002
- });
1003
- (0, vitest_1.test)("throws when using invalid panel IDs", () => {
1004
- const spy = vitest_1.vi.fn();
1005
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
1006
- input: { groupId: "group" },
1007
- }).start();
1008
- actor.subscribe({ error: spy });
1009
- actor.send({
1010
- type: "registerPanel",
1011
- data: (0, index_js_1.initializePanel)({ id: "panel-1" }),
1012
- });
1013
- actor.send({
1014
- type: "setPanelPixelSize",
1015
- panelId: "panel-2",
1016
- size: "100px",
1017
- });
1018
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(new Error("Expected panel with id: panel-2"));
1019
- });
1020
- (0, vitest_1.test)("throws when using invalid handle IDs", () => {
1021
- const spy = vitest_1.vi.fn();
1022
- const actor = (0, xstate_1.createActor)(index_js_1.groupMachine, {
1023
- input: { groupId: "group" },
1024
- }).start();
1025
- actor.subscribe({ error: spy });
1026
- sendAll(actor, [
1027
- { type: "registerPanel", data: (0, index_js_1.initializePanel)({ id: "handle-2" }) },
1028
- { type: "dragHandleStart", handleId: "handle-2" },
1029
- {
1030
- type: "dragHandle",
1031
- handleId: "handle-2",
1032
- value: (0, index_js_1.dragHandlePayload)({ delta: 100, orientation: "horizontal" }),
1033
- },
1034
- ]);
1035
- (0, vitest_1.expect)(spy).toHaveBeenCalledWith(new Error("Expected panel handle with id: handle-2"));
1036
- });
1037
- });
1038
- //# sourceMappingURL=machine.test.js.map