@window-splitter/state 0.3.1 → 0.4.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.
@@ -372,7 +372,12 @@ describe("constraints", () => {
372
372
  ],
373
373
  },
374
374
  }).start();
375
+
375
376
  initializeSizes(actor, { width: 500, height: 200 });
377
+ expect(spy).toHaveBeenCalledWith({
378
+ percentage: 0.5,
379
+ pixel: 250,
380
+ });
376
381
 
377
382
  capturePixelValues(actor, () => {
378
383
  dragHandle(actor, { id: "resizer-1", delta: 100 });
@@ -464,7 +469,7 @@ describe("constraints", () => {
464
469
  }).start();
465
470
 
466
471
  expect(getTemplate(actor)).toMatchInlineSnapshot(
467
- `"minmax(0px, 90%) 10px 30%"`
472
+ `"minmax(0px, 90%) 10px minmax(30%, 1fr)"`
468
473
  );
469
474
  initializeSizes(actor, { width: 500, height: 200 });
470
475
 
@@ -474,6 +479,29 @@ describe("constraints", () => {
474
479
  });
475
480
  });
476
481
 
482
+ test("supports 1 panel being collapsed with another panel expanding to fill", () => {
483
+ const actor = createActor(groupMachine, {
484
+ input: {
485
+ groupId: "group",
486
+ initialItems: [
487
+ initializePanel({ id: "panel-1", default: "200px", min: "200px" }),
488
+ initializePanelHandleData({ id: "resizer-1", size: "10px" }),
489
+ initializePanel({
490
+ id: "panel-2",
491
+ min: "200px",
492
+ collapsible: true,
493
+ collapsedSize: "60px",
494
+ defaultCollapsed: true,
495
+ }),
496
+ ],
497
+ },
498
+ }).start();
499
+
500
+ expect(getTemplate(actor)).toMatchInlineSnapshot(
501
+ `"minmax(200px, 1fr) 10px 60px"`
502
+ );
503
+ });
504
+
477
505
  test("panel can have a min", () => {
478
506
  const actor = createActor(groupMachine, {
479
507
  input: { groupId: "group" },
@@ -727,7 +755,7 @@ describe("collapsible panel", () => {
727
755
  capturePixelValues(actor, () => {
728
756
  expect(getTemplate(actor)).toBe("490px 10px 0px");
729
757
 
730
- // Stays oollapsed in the buffer
758
+ // Stays collapsed in the buffer
731
759
  dragHandle(actor, { id: "resizer-1", delta: -30 });
732
760
  expect(getTemplate(actor)).toBe("490px 10px 0px");
733
761
 
@@ -1273,6 +1301,189 @@ describe("collapsible panel", () => {
1273
1301
  expect(getTemplate(actor)).toMatchInlineSnapshot(`"245px 10px 245px"`);
1274
1302
  });
1275
1303
  });
1304
+
1305
+ describe("constraints", () => {
1306
+ test("on render", async () => {
1307
+ const actor = createActor(groupMachine, {
1308
+ input: { groupId: "group" },
1309
+ }).start();
1310
+
1311
+ sendAll(actor, [
1312
+ {
1313
+ type: "registerPanel",
1314
+ data: initializePanel({ id: "panel-1", min: "200px" }),
1315
+ },
1316
+ {
1317
+ type: "registerPanelHandle",
1318
+ data: { id: "resizer-1", size: "10px" },
1319
+ },
1320
+ {
1321
+ type: "registerPanel",
1322
+ data: initializePanel({
1323
+ id: "panel-2",
1324
+ collapsible: true,
1325
+ min: "300px",
1326
+ collapsedSize: "60px",
1327
+ }),
1328
+ },
1329
+ ]);
1330
+
1331
+ expect(getTemplate(actor)).toBe(
1332
+ "minmax(200px, 1fr) 10px minmax(300px, 1fr)"
1333
+ );
1334
+ initializeSizes(actor, { width: 400, height: 200 });
1335
+ actor.send({
1336
+ type: "setSize",
1337
+ size: { width: 400, height: 200 },
1338
+ handleOverflow: true,
1339
+ });
1340
+ // There wasn't enough space to render the panel so the last one is collapsed
1341
+ expect(getTemplate(actor)).toBe(
1342
+ "minmax(200px, min(calc(1 * (100% - 70px)), 100%)) 10px 60px"
1343
+ );
1344
+ });
1345
+
1346
+ test("on resize", async () => {
1347
+ const actor = createActor(groupMachine, {
1348
+ input: { groupId: "group" },
1349
+ }).start();
1350
+
1351
+ sendAll(actor, [
1352
+ {
1353
+ type: "registerPanel",
1354
+ data: initializePanel({ id: "panel-1", min: "200px" }),
1355
+ },
1356
+ {
1357
+ type: "registerPanelHandle",
1358
+ data: { id: "resizer-1", size: "10px" },
1359
+ },
1360
+ {
1361
+ type: "registerPanel",
1362
+ data: initializePanel({
1363
+ id: "panel-2",
1364
+ collapsible: true,
1365
+ min: "300px",
1366
+ collapsedSize: "60px",
1367
+ }),
1368
+ },
1369
+ ]);
1370
+
1371
+ expect(getTemplate(actor)).toBe(
1372
+ "minmax(200px, 1fr) 10px minmax(300px, 1fr)"
1373
+ );
1374
+ initializeSizes(actor, { width: 500, height: 200 });
1375
+ expect(getTemplate(actor)).toBe(
1376
+ "minmax(200px, min(calc(0.40816326530612244898 * (100% - 10px)), 100%)) 10px minmax(300px, min(calc(0.61224489795918367347 * (100% - 10px)), 100%))"
1377
+ );
1378
+
1379
+ actor.send({
1380
+ type: "setSize",
1381
+ size: { width: 400, height: 200 },
1382
+ handleOverflow: true,
1383
+ });
1384
+ // There wasn't enough space to render the panel so the last one is collapsed
1385
+ expect(getTemplate(actor)).toBe(
1386
+ "minmax(200px, min(calc(1 * (100% - 70px)), 100%)) 10px 60px"
1387
+ );
1388
+ });
1389
+
1390
+ test("cannot expand panel via event", async () => {
1391
+ const actor = createActor(groupMachine, {
1392
+ input: { groupId: "group" },
1393
+ }).start();
1394
+
1395
+ sendAll(actor, [
1396
+ {
1397
+ type: "registerPanel",
1398
+ data: initializePanel({ id: "panel-1", min: "200px" }),
1399
+ },
1400
+ {
1401
+ type: "registerPanelHandle",
1402
+ data: { id: "resizer-1", size: "10px" },
1403
+ },
1404
+ {
1405
+ type: "registerPanel",
1406
+ data: initializePanel({
1407
+ id: "panel-2",
1408
+ collapsible: true,
1409
+ min: "300px",
1410
+ collapsedSize: "60px",
1411
+ }),
1412
+ },
1413
+ ]);
1414
+
1415
+ expect(getTemplate(actor)).toBe(
1416
+ "minmax(200px, 1fr) 10px minmax(300px, 1fr)"
1417
+ );
1418
+ initializeSizes(actor, { width: 400, height: 200 });
1419
+ actor.send({
1420
+ type: "setSize",
1421
+ size: { width: 400, height: 200 },
1422
+ handleOverflow: true,
1423
+ });
1424
+ // There wasn't enough space to render the panel so the last one is collapsed
1425
+ expect(getTemplate(actor)).toBe(
1426
+ "minmax(200px, min(calc(1 * (100% - 70px)), 100%)) 10px 60px"
1427
+ );
1428
+
1429
+ actor.send({
1430
+ type: "expandPanel",
1431
+ panelId: "panel-2",
1432
+ });
1433
+ await waitForIdle(actor);
1434
+
1435
+ // There wasn't enough space to render the panel so the last one is collapsed
1436
+ expect(getTemplate(actor)).toBe(
1437
+ "minmax(200px, min(calc(1 * (100% - 70px)), 100%)) 10px 60px"
1438
+ );
1439
+ });
1440
+
1441
+ test("cannot expand panel via drag", async () => {
1442
+ const actor = createActor(groupMachine, {
1443
+ input: { groupId: "group" },
1444
+ }).start();
1445
+
1446
+ sendAll(actor, [
1447
+ {
1448
+ type: "registerPanel",
1449
+ data: initializePanel({ id: "panel-1", min: "200px" }),
1450
+ },
1451
+ {
1452
+ type: "registerPanelHandle",
1453
+ data: { id: "resizer-1", size: "10px" },
1454
+ },
1455
+ {
1456
+ type: "registerPanel",
1457
+ data: initializePanel({
1458
+ id: "panel-2",
1459
+ collapsible: true,
1460
+ min: "300px",
1461
+ collapsedSize: "60px",
1462
+ }),
1463
+ },
1464
+ ]);
1465
+
1466
+ expect(getTemplate(actor)).toBe(
1467
+ "minmax(200px, 1fr) 10px minmax(300px, 1fr)"
1468
+ );
1469
+ initializeSizes(actor, { width: 400, height: 200 });
1470
+ actor.send({
1471
+ type: "setSize",
1472
+ size: { width: 400, height: 200 },
1473
+ handleOverflow: true,
1474
+ });
1475
+ // There wasn't enough space to render the panel so the last one is collapsed
1476
+ expect(getTemplate(actor)).toBe(
1477
+ "minmax(200px, min(calc(1 * (100% - 70px)), 100%)) 10px 60px"
1478
+ );
1479
+
1480
+ // Drag the resizer to the right
1481
+ capturePixelValues(actor, () => {
1482
+ dragHandle(actor, { id: "resizer-1", delta: -400 });
1483
+ expect(getTemplate(actor)).toBe("330px 10px 60px");
1484
+ });
1485
+ });
1486
+ });
1276
1487
  });
1277
1488
 
1278
1489
  describe("conditional panel", () => {
@@ -1721,3 +1932,39 @@ describe("utils", async () => {
1721
1932
  expect(newSnapshot).toMatchSnapshot();
1722
1933
  });
1723
1934
  });
1935
+
1936
+ describe("static at rest", () => {
1937
+ test("a panel can be pixels when resting", async () => {
1938
+ const actor = createActor(groupMachine, {
1939
+ input: {
1940
+ groupId: "group",
1941
+ initialItems: [
1942
+ initializePanel({
1943
+ id: "panel-1",
1944
+ min: "20px",
1945
+ max: "200px",
1946
+ isStaticAtRest: true,
1947
+ }),
1948
+ initializePanelHandleData({ id: "resizer-1", size: "10px" }),
1949
+ initializePanel({ id: "panel-2", min: "50px" }),
1950
+ initializePanelHandleData({ id: "resizer-2", size: "10px" }),
1951
+ initializePanel({ id: "panel-3", min: "50px" }),
1952
+ ],
1953
+ },
1954
+ }).start();
1955
+
1956
+ initializeSizes(actor, { width: 500, height: 200 });
1957
+
1958
+ expect(getTemplate(actor)).toMatchInlineSnapshot(
1959
+ `"clamp(20px, 200px, 200px) 10px minmax(50px, min(calc(0.5 * (100% - 220px)), 100%)) 10px minmax(50px, min(calc(0.5 * (100% - 220px)), 100%))"`
1960
+ );
1961
+
1962
+ capturePixelValues(actor, () => {
1963
+ dragHandle(actor, { id: "resizer-1", delta: -10 });
1964
+ });
1965
+
1966
+ expect(getTemplate(actor)).toMatchInlineSnapshot(
1967
+ `"clamp(20px, 190px, 200px) 10px minmax(50px, min(calc(0.51724137931034482759 * (100% - 210px)), 100%)) 10px minmax(50px, min(calc(0.48275862068965517241 * (100% - 210px)), 100%))"`
1968
+ );
1969
+ });
1970
+ });