@window-splitter/state 0.2.4 → 0.3.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/.turbo/turbo-build.log +4 -5
- package/.turbo/turbo-lint.log +9 -1
- package/.turbo/turbo-test.log +4717 -1160
- package/CHANGELOG.md +41 -0
- package/README.md +119 -1
- package/coverage/coverage-final.json +1 -1
- package/coverage/coverage-summary.json +3 -0
- package/coverage/index.html +19 -19
- package/coverage/index.ts.html +872 -377
- package/dist/commonjs/index.d.ts +22 -12
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +109 -25
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +22 -12
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +106 -25
- package/dist/esm/index.js.map +1 -1
- package/package.json +12 -9
- package/src/__snapshots__/machine.test.ts.snap +73 -0
- package/src/index.ts +151 -35
- package/src/machine.test.ts +327 -9
- package/src/utils.test.ts +86 -0
- package/vitest.config.ts +2 -0
- package/coverage/clover.xml +0 -363
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
# v0.3.0 (Sun Aug 18 2024)
|
|
2
|
+
|
|
3
|
+
#### 🚀 Enhancement
|
|
4
|
+
|
|
5
|
+
- Add `onResize` prop to Panel [#28](https://github.com/hipstersmoothie/react-window-splitter/pull/28) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
6
|
+
|
|
7
|
+
#### 🐛 Bug Fix
|
|
8
|
+
|
|
9
|
+
- Add `onResize` prop to `Panel` ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
10
|
+
- 100 [#26](https://github.com/hipstersmoothie/react-window-splitter/pull/26) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
11
|
+
- 100 ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
12
|
+
- add coverage for PRs [#25](https://github.com/hipstersmoothie/react-window-splitter/pull/25) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
13
|
+
- testing ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
14
|
+
- add coverage for PRs ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
15
|
+
- Add react tests [#24](https://github.com/hipstersmoothie/react-window-splitter/pull/24) ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
16
|
+
- add docs for state machine usage ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
17
|
+
|
|
18
|
+
#### ⚠️ Pushed to `main`
|
|
19
|
+
|
|
20
|
+
- improve test coverage in state machine ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
21
|
+
|
|
22
|
+
#### Authors: 1
|
|
23
|
+
|
|
24
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# v0.2.5 (Thu Aug 15 2024)
|
|
29
|
+
|
|
30
|
+
#### ⚠️ Pushed to `main`
|
|
31
|
+
|
|
32
|
+
- add more docs to state machine + add defaults to params ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
33
|
+
- fix repo/description ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
34
|
+
- upgrade deps ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
35
|
+
|
|
36
|
+
#### Authors: 1
|
|
37
|
+
|
|
38
|
+
- Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
1
42
|
# v0.2.4 (Thu Aug 15 2024)
|
|
2
43
|
|
|
3
44
|
#### 🐛 Bug Fix
|
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# `@window-splitter/state`
|
|
2
2
|
|
|
3
|
-
A state machine for
|
|
3
|
+
A state machine for a WAI-ARIA compliant window splitter.
|
|
4
|
+
This package can be used to build your own window splitter for a framework or even vanilla html/js.
|
|
5
|
+
|
|
6
|
+
If you're using a framework like React, you can use the `react-window-splitter` package instead.
|
|
4
7
|
|
|
5
8
|
[Read the full docs](https://react-window-splitter-six.vercel.app)
|
|
6
9
|
|
|
@@ -11,3 +14,118 @@ npm install @window-splitter/state
|
|
|
11
14
|
yarn add @window-splitter/state
|
|
12
15
|
pnpm add @window-splitter/state
|
|
13
16
|
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
This is an example of how to use the machine to create a window splitter.
|
|
21
|
+
This is very simplified and only shows the basics of how to use the state machine.
|
|
22
|
+
Actually integrating with a framework would look a lot different.
|
|
23
|
+
|
|
24
|
+
In a vanilla html/js application you would have something like this:
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<div id="group">
|
|
28
|
+
<div id="panel-1">Panel-1</div>
|
|
29
|
+
<div id="resizer-1"></div>
|
|
30
|
+
<div id="panel-2">Panel-2</div>
|
|
31
|
+
</div>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
And then you would have some javascript to setup the state machine and send events to it.
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import {
|
|
38
|
+
groupMachine,
|
|
39
|
+
initializePanel,
|
|
40
|
+
initializePanelHandleData,
|
|
41
|
+
} from "@window-splitter/state";
|
|
42
|
+
import { createActor } from "xstate";
|
|
43
|
+
|
|
44
|
+
// Setup the state machine
|
|
45
|
+
const actor = createActor(groupMachine, {
|
|
46
|
+
input: { groupId: "group" },
|
|
47
|
+
}).start();
|
|
48
|
+
|
|
49
|
+
// Register the panels with the state machine
|
|
50
|
+
actor.send({
|
|
51
|
+
type: "registerPanel",
|
|
52
|
+
data: initializePanel({ id: "panel-1" }),
|
|
53
|
+
});
|
|
54
|
+
actor.send({
|
|
55
|
+
type: "registerPanelHandle",
|
|
56
|
+
data: initializePanelHandleData({ id: "resizer-1", size: "10px" }),
|
|
57
|
+
});
|
|
58
|
+
actor.send({
|
|
59
|
+
type: "registerPanel",
|
|
60
|
+
data: initializePanel({ id: "panel-2" }),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Set the size of the group, typically measured in the browser after the initial render
|
|
64
|
+
actor.send({ type: "setSize", size: { width: 500, height: 200 } });
|
|
65
|
+
// The state machine relies on css grid to calculate the initial sizes of the panels
|
|
66
|
+
// This next action would be sent after measuring the initial sizes rendered by the browser
|
|
67
|
+
actor.send({
|
|
68
|
+
type: "setActualItemsSize",
|
|
69
|
+
childrenSizes: {
|
|
70
|
+
"panel-1": { width: 245, height: 200 },
|
|
71
|
+
"panel-2": { width: 245, height: 200 },
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Send some events to drag a handle
|
|
76
|
+
actor.send({ type: "dragHandleStart", handleId: "resizer-1" });
|
|
77
|
+
actor.send({
|
|
78
|
+
type: "dragHandle",
|
|
79
|
+
handleId: "resizer-1",
|
|
80
|
+
value: dragHandlePayload({ delta: 10 }),
|
|
81
|
+
});
|
|
82
|
+
actor.send({ type: "dragHandleEnd", handleId: "resizer-1" });
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API
|
|
86
|
+
|
|
87
|
+
### `groupMachine`
|
|
88
|
+
|
|
89
|
+
The state machine is exported as `groupMachine` and can be used to create a window splitter.
|
|
90
|
+
|
|
91
|
+
#### `groupMachine.input`
|
|
92
|
+
|
|
93
|
+
The context of the state machine is an object with the following shape:
|
|
94
|
+
|
|
95
|
+
- `orientation`: The orientation of the group. This can be either `"horizontal"` or `"vertical"`
|
|
96
|
+
- `groupId`: The id of the group
|
|
97
|
+
- `initialItems`: An array of items to initialize the group with.
|
|
98
|
+
|
|
99
|
+
#### Events
|
|
100
|
+
|
|
101
|
+
For a full list of events and their payloads see the [source code](https://github.com/hipstersmoothie/react-window-splitter/blob/main/packages/state/src/index.ts).
|
|
102
|
+
|
|
103
|
+
- `registerPanel`: Register a new panel with the state machine
|
|
104
|
+
- `registerDynamicPanel`: Register a new panel after the initial render
|
|
105
|
+
- `unregisterPanel`: Unregister a panel from the state machine
|
|
106
|
+
- `registerPanelHandle`: Register a new panel handle with the state machine
|
|
107
|
+
- `unregisterPanelHandle`: Unregister a panel handle from the state machine
|
|
108
|
+
- `setSize`: Set the size of the group after the initial render
|
|
109
|
+
- `setActualItemsSize`: Set the size of the group items after the initial render
|
|
110
|
+
- `setOrientation`: Set the orientation of the group
|
|
111
|
+
- `dragHandleStart`: Start a drag interaction
|
|
112
|
+
- `dragHandle`: Update the layout according to how the handle moved
|
|
113
|
+
- `dragHandleEnd`: End a drag interaction
|
|
114
|
+
- `collapsePanel`: Collapse a panel
|
|
115
|
+
- `expandPanel`: Expand a panel
|
|
116
|
+
- `setPanelPixelSize`: Set the size of a panel in pixels
|
|
117
|
+
|
|
118
|
+
### Utilities
|
|
119
|
+
|
|
120
|
+
- `buildTemplate` - Build the grid template from the item values.
|
|
121
|
+
- `getCollapsiblePanelForHandleId` - Get the handle closest to the target panel.
|
|
122
|
+
- `getGroupSize` - Get the size of the group in pixels.
|
|
123
|
+
- `getPanelWithId` - Get a panel with a particular ID.
|
|
124
|
+
- `getUnitPercentageValue` - Converts a `Unit` to a percentage of the group size.
|
|
125
|
+
- `getUnitPixelValue` - Converts a `Unit` to a pixel value.
|
|
126
|
+
- `initializePanel` - Initialize a panel for registration with the state machine.
|
|
127
|
+
- `InitializePanelHandleData` - Initialize a panel handle for registration with the state machine.
|
|
128
|
+
- `isPanelData` - Check if the provided item is a panel data object.
|
|
129
|
+
- `isPanelHandle` - Check if the provided item is a panel handle object.
|
|
130
|
+
- `parseUnit` - Parse a `Unit` from a string.
|
|
131
|
+
- `prepareSnapshot` - For usage with restoring a saved layout state
|