@window-splitter/state 0.2.2

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 (52) hide show
  1. package/.tshy/build.json +8 -0
  2. package/.tshy/commonjs.json +17 -0
  3. package/.tshy/esm.json +16 -0
  4. package/.turbo/turbo-build.log +5 -0
  5. package/.turbo/turbo-lint.log +5 -0
  6. package/.turbo/turbo-test.log +278 -0
  7. package/CHANGELOG.md +191 -0
  8. package/README.md +13 -0
  9. package/coverage/base.css +224 -0
  10. package/coverage/block-navigation.js +87 -0
  11. package/coverage/clover.xml +350 -0
  12. package/coverage/coverage-final.json +2 -0
  13. package/coverage/favicon.png +0 -0
  14. package/coverage/index.html +116 -0
  15. package/coverage/index.ts.html +4627 -0
  16. package/coverage/prettify.css +1 -0
  17. package/coverage/prettify.js +2 -0
  18. package/coverage/sort-arrow-sprite.png +0 -0
  19. package/coverage/sorter.js +196 -0
  20. package/dist/commonjs/index.d.ts +314 -0
  21. package/dist/commonjs/index.d.ts.map +1 -0
  22. package/dist/commonjs/index.js +932 -0
  23. package/dist/commonjs/index.js.map +1 -0
  24. package/dist/commonjs/machine.test.d.ts +5 -0
  25. package/dist/commonjs/machine.test.d.ts.map +1 -0
  26. package/dist/commonjs/machine.test.js +1038 -0
  27. package/dist/commonjs/machine.test.js.map +1 -0
  28. package/dist/commonjs/package.json +3 -0
  29. package/dist/commonjs/utils.test.d.ts +2 -0
  30. package/dist/commonjs/utils.test.d.ts.map +1 -0
  31. package/dist/commonjs/utils.test.js +79 -0
  32. package/dist/commonjs/utils.test.js.map +1 -0
  33. package/dist/esm/index.d.ts +314 -0
  34. package/dist/esm/index.d.ts.map +1 -0
  35. package/dist/esm/index.js +890 -0
  36. package/dist/esm/index.js.map +1 -0
  37. package/dist/esm/machine.test.d.ts +5 -0
  38. package/dist/esm/machine.test.d.ts.map +1 -0
  39. package/dist/esm/machine.test.js +1036 -0
  40. package/dist/esm/machine.test.js.map +1 -0
  41. package/dist/esm/package.json +3 -0
  42. package/dist/esm/utils.test.d.ts +2 -0
  43. package/dist/esm/utils.test.d.ts.map +1 -0
  44. package/dist/esm/utils.test.js +77 -0
  45. package/dist/esm/utils.test.js.map +1 -0
  46. package/eslint.config.js +3 -0
  47. package/package.json +79 -0
  48. package/src/index.ts +1514 -0
  49. package/src/machine.test.ts +1316 -0
  50. package/src/utils.test.ts +104 -0
  51. package/tsconfig.json +3 -0
  52. package/vitest.config.ts +16 -0
@@ -0,0 +1,104 @@
1
+ import { expect, test, describe } from "vitest";
2
+
3
+ import {
4
+ getUnitPercentageValue,
5
+ getCollapsiblePanelForHandleId,
6
+ groupMachine,
7
+ initializePanel,
8
+ } from "./index.js";
9
+ import { createActor } from "xstate";
10
+
11
+ describe("getUnitPercentageValue", () => {
12
+ test("works with pixels", () => {
13
+ expect(getUnitPercentageValue(100, { type: "pixel", value: 100 })).toBe(1);
14
+ expect(getUnitPercentageValue(100, { type: "pixel", value: 50 })).toBe(0.5);
15
+ });
16
+
17
+ test("works with percentages", () => {
18
+ expect(getUnitPercentageValue(100, { type: "percent", value: 1 })).toBe(1);
19
+ expect(getUnitPercentageValue(100, { type: "percent", value: 0.5 })).toBe(
20
+ 0.5
21
+ );
22
+ });
23
+ });
24
+
25
+ describe("getCollapsiblePanelForHandleId", () => {
26
+ test("works with left collapsible panel", () => {
27
+ const actor = createActor(groupMachine, {
28
+ input: {
29
+ groupId: "group",
30
+ initialItems: [
31
+ initializePanel({ id: "panel-1", collapsible: true }),
32
+ {
33
+ type: "handle",
34
+ id: "resizer-1",
35
+ size: { type: "pixel", value: 10 },
36
+ },
37
+ initializePanel({ id: "panel-2" }),
38
+ ],
39
+ },
40
+ }).start();
41
+
42
+ expect(
43
+ getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
44
+ ?.id
45
+ ).toBe("panel-1");
46
+ });
47
+
48
+ test("works with right collapsible panel", () => {
49
+ const actor = createActor(groupMachine, {
50
+ input: {
51
+ groupId: "group",
52
+ initialItems: [
53
+ initializePanel({ id: "panel-1" }),
54
+ {
55
+ type: "handle",
56
+ id: "resizer-1",
57
+ size: { type: "pixel", value: 10 },
58
+ },
59
+ initializePanel({ id: "panel-2", collapsible: true }),
60
+ ],
61
+ },
62
+ }).start();
63
+
64
+ expect(
65
+ getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
66
+ ?.id
67
+ ).toBe("panel-2");
68
+ });
69
+
70
+ test("throws when no items", () => {
71
+ const actor = createActor(groupMachine, {
72
+ input: {
73
+ groupId: "group",
74
+ initialItems: [],
75
+ },
76
+ }).start();
77
+
78
+ expect(() =>
79
+ getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
80
+ ).toThrowErrorMatchingInlineSnapshot(`[Error: No items in group]`);
81
+ });
82
+
83
+ test("throws when no collapsible panel", () => {
84
+ const actor = createActor(groupMachine, {
85
+ input: {
86
+ groupId: "group",
87
+ initialItems: [
88
+ initializePanel({ id: "panel-1" }),
89
+ {
90
+ type: "handle",
91
+ id: "resizer-1",
92
+ size: { type: "pixel", value: 10 },
93
+ },
94
+ ],
95
+ },
96
+ }).start();
97
+
98
+ expect(() =>
99
+ getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
100
+ ).toThrowErrorMatchingInlineSnapshot(
101
+ `[Error: No collapsible panel found for handle: resizer-1]`
102
+ );
103
+ });
104
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "../../tsconfig.json"
3
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ coverage: {
6
+ provider: "istanbul",
7
+ },
8
+ browser: {
9
+ enabled: true,
10
+ name: "chromium",
11
+ provider: "playwright",
12
+ // https://playwright.dev
13
+ providerOptions: {},
14
+ },
15
+ },
16
+ });