@window-splitter/state 0.5.8 → 0.6.1

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.
@@ -0,0 +1,25 @@
1
+ import {
2
+ groupMachine,
3
+ GroupMachineContextValue,
4
+ SendFn,
5
+ State,
6
+ } from "./index.js";
7
+
8
+ export interface Actor {
9
+ send: SendFn;
10
+ value: GroupMachineContextValue;
11
+ state: { current: State };
12
+ }
13
+
14
+ export function createActor(
15
+ input: Partial<GroupMachineContextValue>,
16
+ onChange?: (context: GroupMachineContextValue) => void
17
+ ): Actor {
18
+ const [context, send, state] = groupMachine(input, onChange);
19
+
20
+ return {
21
+ send,
22
+ value: context,
23
+ state,
24
+ };
25
+ }
package/src/utils.test.ts CHANGED
@@ -3,13 +3,12 @@ import { expect, test, describe } from "vitest";
3
3
  import {
4
4
  getUnitPercentageValue,
5
5
  getCollapsiblePanelForHandleId,
6
- groupMachine,
7
6
  initializePanel,
8
7
  getCursor,
9
8
  initializePanelHandleData,
10
9
  } from "./index.js";
11
- import { createActor } from "xstate";
12
10
  import Big from "big.js";
11
+ import { createActor } from "./test-utils.js";
13
12
 
14
13
  describe("getUnitPercentageValue", () => {
15
14
  test("works with pixels", () => {
@@ -39,79 +38,69 @@ describe("getUnitPercentageValue", () => {
39
38
 
40
39
  describe("getCollapsiblePanelForHandleId", () => {
41
40
  test("works with left collapsible panel", () => {
42
- const actor = createActor(groupMachine, {
43
- input: {
44
- groupId: "group",
45
- initialItems: [
46
- initializePanel({ id: "panel-1", collapsible: true }),
47
- {
48
- type: "handle",
49
- id: "resizer-1",
50
- size: { type: "pixel", value: new Big(10) },
51
- },
52
- initializePanel({ id: "panel-2" }),
53
- ],
54
- },
55
- }).start();
41
+ const actor = createActor({
42
+ groupId: "group",
43
+ items: [
44
+ initializePanel({ id: "panel-1", collapsible: true }),
45
+ {
46
+ type: "handle",
47
+ id: "resizer-1",
48
+ size: { type: "pixel", value: new Big(10) },
49
+ },
50
+ initializePanel({ id: "panel-2" }),
51
+ ],
52
+ });
56
53
 
57
- expect(
58
- getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
59
- ?.id
60
- ).toBe("panel-1");
54
+ expect(getCollapsiblePanelForHandleId(actor.value, "resizer-1")?.id).toBe(
55
+ "panel-1"
56
+ );
61
57
  });
62
58
 
63
59
  test("works with right collapsible panel", () => {
64
- const actor = createActor(groupMachine, {
65
- input: {
66
- groupId: "group",
67
- initialItems: [
68
- initializePanel({ id: "panel-1" }),
69
- {
70
- type: "handle",
71
- id: "resizer-1",
72
- size: { type: "pixel", value: new Big(10) },
73
- },
74
- initializePanel({ id: "panel-2", collapsible: true }),
75
- ],
76
- },
77
- }).start();
60
+ const actor = createActor({
61
+ groupId: "group",
62
+ items: [
63
+ initializePanel({ id: "panel-1" }),
64
+ {
65
+ type: "handle",
66
+ id: "resizer-1",
67
+ size: { type: "pixel", value: new Big(10) },
68
+ },
69
+ initializePanel({ id: "panel-2", collapsible: true }),
70
+ ],
71
+ });
78
72
 
79
- expect(
80
- getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
81
- ?.id
82
- ).toBe("panel-2");
73
+ expect(getCollapsiblePanelForHandleId(actor.value, "resizer-1")?.id).toBe(
74
+ "panel-2"
75
+ );
83
76
  });
84
77
 
85
78
  test("throws when no items", () => {
86
- const actor = createActor(groupMachine, {
87
- input: {
88
- groupId: "group",
89
- initialItems: [],
90
- },
91
- }).start();
79
+ const actor = createActor({
80
+ groupId: "group",
81
+ items: [],
82
+ });
92
83
 
93
84
  expect(() =>
94
- getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
85
+ getCollapsiblePanelForHandleId(actor.value, "resizer-1")
95
86
  ).toThrowErrorMatchingInlineSnapshot(`[Error: No items in group]`);
96
87
  });
97
88
 
98
89
  test("throws when no collapsible panel", () => {
99
- const actor = createActor(groupMachine, {
100
- input: {
101
- groupId: "group",
102
- initialItems: [
103
- initializePanel({ id: "panel-1" }),
104
- {
105
- type: "handle",
106
- id: "resizer-1",
107
- size: { type: "pixel", value: new Big(10) },
108
- },
109
- ],
110
- },
111
- }).start();
90
+ const actor = createActor({
91
+ groupId: "group",
92
+ items: [
93
+ initializePanel({ id: "panel-1" }),
94
+ {
95
+ type: "handle",
96
+ id: "resizer-1",
97
+ size: { type: "pixel", value: new Big(10) },
98
+ },
99
+ ],
100
+ });
112
101
 
113
102
  expect(() =>
114
- getCollapsiblePanelForHandleId(actor.getSnapshot().context, "resizer-1")
103
+ getCollapsiblePanelForHandleId(actor.value, "resizer-1")
115
104
  ).toThrowErrorMatchingInlineSnapshot(
116
105
  `[Error: No collapsible panel found for handle: resizer-1]`
117
106
  );