@window-splitter/solid 0.8.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/.storybook/main.ts +24 -0
- package/.storybook/preview.ts +14 -0
- package/.tshy/build.json +8 -0
- package/.tshy/esm.json +18 -0
- package/.turbo/turbo-build.log +5 -0
- package/.turbo/turbo-lint.log +5 -0
- package/CHANGELOG.md +66 -0
- package/README.md +54 -0
- package/dist/esm/SolidWIndowSplitter.d.ts +19 -0
- package/dist/esm/SolidWIndowSplitter.d.ts.map +1 -0
- package/dist/esm/SolidWIndowSplitter.jsx +506 -0
- package/dist/esm/SolidWIndowSplitter.jsx.map +1 -0
- package/dist/esm/SolidWindowSplitter.stories.d.ts +52 -0
- package/dist/esm/SolidWindowSplitter.stories.d.ts.map +1 -0
- package/dist/esm/SolidWindowSplitter.stories.jsx +470 -0
- package/dist/esm/SolidWindowSplitter.stories.jsx.map +1 -0
- package/dist/esm/SolidWindowSplitter.test.d.ts +2 -0
- package/dist/esm/SolidWindowSplitter.test.d.ts.map +1 -0
- package/dist/esm/SolidWindowSplitter.test.jsx +197 -0
- package/dist/esm/SolidWindowSplitter.test.jsx.map +1 -0
- package/dist/esm/context.d.ts +18 -0
- package/dist/esm/context.d.ts.map +1 -0
- package/dist/esm/context.jsx +38 -0
- package/dist/esm/context.jsx.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/mergeSolidAttributes.d.ts +6 -0
- package/dist/esm/mergeSolidAttributes.d.ts.map +1 -0
- package/dist/esm/mergeSolidAttributes.js +45 -0
- package/dist/esm/mergeSolidAttributes.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/doctor-storybook.log +29 -0
- package/eslint.config.js +10 -0
- package/index.html +11 -0
- package/package.json +104 -0
- package/rsbuild.config.js +25 -0
- package/src/SolidWIndowSplitter.tsx +683 -0
- package/src/SolidWindowSplitter.stories.tsx +689 -0
- package/src/SolidWindowSplitter.test.tsx +333 -0
- package/src/__snapshots__/SolidWindowSplitter.test.tsx.snap +56 -0
- package/src/context.tsx +58 -0
- package/src/index.ts +1 -0
- package/src/mergeSolidAttributes.ts +61 -0
- package/tsconfig.json +8 -0
- package/vite.config.js +6 -0
- package/vitest.config.ts +22 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { test, expect, describe, vi, afterEach } from "vitest";
|
|
2
|
+
import { cleanup, fireEvent, render, waitFor } from "@solidjs/testing-library";
|
|
3
|
+
import * as Cookies from "tiny-cookie";
|
|
4
|
+
|
|
5
|
+
import { PanelGroupHandle, PanelHandle } from "@window-splitter/interface";
|
|
6
|
+
import {
|
|
7
|
+
Autosave,
|
|
8
|
+
AutosaveCollapsible,
|
|
9
|
+
Collapsible,
|
|
10
|
+
ConditionalPanel,
|
|
11
|
+
Simple,
|
|
12
|
+
VerticalLayout,
|
|
13
|
+
DynamicConstraints,
|
|
14
|
+
AutosaveCookie,
|
|
15
|
+
} from "./SolidWindowSplitter.stories.jsx";
|
|
16
|
+
import { createTestUtils, dragHandle } from "@window-splitter/interface/test";
|
|
17
|
+
|
|
18
|
+
const { expectTemplate, waitForMeasurement, waitForCondition } =
|
|
19
|
+
createTestUtils({ waitFor });
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
cleanup();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("horizontal layout", async () => {
|
|
26
|
+
let handle: PanelGroupHandle | null = null!;
|
|
27
|
+
|
|
28
|
+
const { getByText } = render(() => (
|
|
29
|
+
<div style={{ width: "500px" }}>
|
|
30
|
+
<Simple handle={(v) => (handle = v)} />
|
|
31
|
+
</div>
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
await waitForMeasurement(handle);
|
|
35
|
+
|
|
36
|
+
expect(getByText("Panel 1")).toBeInTheDocument();
|
|
37
|
+
expect(getByText("Panel 2")).toBeInTheDocument();
|
|
38
|
+
|
|
39
|
+
await expectTemplate(handle, "244px 10px 244px");
|
|
40
|
+
|
|
41
|
+
// Should respect the min
|
|
42
|
+
await dragHandle({ delta: 300 });
|
|
43
|
+
await expectTemplate(handle, "388px 10px 100px");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("vertical layout", async () => {
|
|
47
|
+
let handle: PanelGroupHandle | null = null!;
|
|
48
|
+
|
|
49
|
+
const { getByText } = render(() => (
|
|
50
|
+
<div style={{ width: "500px" }}>
|
|
51
|
+
<VerticalLayout handle={(v) => (handle = v)} />
|
|
52
|
+
</div>
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
await waitForMeasurement(handle);
|
|
56
|
+
|
|
57
|
+
expect(getByText("top")).toBeInTheDocument();
|
|
58
|
+
expect(getByText("middle")).toBeInTheDocument();
|
|
59
|
+
expect(getByText("bottom")).toBeInTheDocument();
|
|
60
|
+
|
|
61
|
+
await expectTemplate(handle, "96px 10px 108px 10px 96px");
|
|
62
|
+
|
|
63
|
+
// Should respect the min
|
|
64
|
+
await dragHandle({ delta: 100, orientation: "vertical" });
|
|
65
|
+
await expectTemplate(handle, "172px 10px 64px 10px 64px");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("Conditional Panels", async () => {
|
|
69
|
+
let handle: PanelGroupHandle | null = null!;
|
|
70
|
+
|
|
71
|
+
const { getByText } = render(() => (
|
|
72
|
+
<div style={{ width: "500px" }}>
|
|
73
|
+
<ConditionalPanel handle={(v) => (handle = v)} />
|
|
74
|
+
</div>
|
|
75
|
+
));
|
|
76
|
+
|
|
77
|
+
await waitForMeasurement(handle);
|
|
78
|
+
await expectTemplate(handle, "244px 10px 244px");
|
|
79
|
+
|
|
80
|
+
getByText("Expand").click();
|
|
81
|
+
await expectTemplate(handle, "244px 10px 134px 10px 100px");
|
|
82
|
+
|
|
83
|
+
getByText("Close").click();
|
|
84
|
+
await expectTemplate(handle, "244px 10px 244px");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("Dynamic constraints", async () => {
|
|
88
|
+
let handle: PanelGroupHandle | null = null!;
|
|
89
|
+
|
|
90
|
+
const { getByText } = render(() => (
|
|
91
|
+
<div style={{ width: "1000px" }}>
|
|
92
|
+
<DynamicConstraints handle={(v) => (handle = v)} />
|
|
93
|
+
</div>
|
|
94
|
+
));
|
|
95
|
+
|
|
96
|
+
await waitForMeasurement(handle);
|
|
97
|
+
await expectTemplate(handle, "100px 10px 178px 10px 700px");
|
|
98
|
+
|
|
99
|
+
getByText("Toggle Custom").click();
|
|
100
|
+
await expectTemplate(handle, "500px 10px 178px 10px 300px");
|
|
101
|
+
|
|
102
|
+
getByText("Toggle Custom").click();
|
|
103
|
+
await expectTemplate(handle, "400px 10px 178px 10px 400px");
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("Autosave", () => {
|
|
107
|
+
test("localStorage", async () => {
|
|
108
|
+
localStorage.clear();
|
|
109
|
+
|
|
110
|
+
let handle: PanelGroupHandle | null = null!;
|
|
111
|
+
|
|
112
|
+
render(() => (
|
|
113
|
+
<div style={{ width: "500px" }}>
|
|
114
|
+
<Autosave handle={(v) => (handle = v)} />
|
|
115
|
+
</div>
|
|
116
|
+
));
|
|
117
|
+
|
|
118
|
+
await waitForMeasurement(handle);
|
|
119
|
+
await expectTemplate(handle, "244px 10px 244px");
|
|
120
|
+
|
|
121
|
+
await dragHandle({ delta: 100 });
|
|
122
|
+
await expectTemplate(handle, "342px 10px 146px");
|
|
123
|
+
|
|
124
|
+
await waitForCondition(() =>
|
|
125
|
+
Boolean(localStorage.getItem("autosave-example-solid"))
|
|
126
|
+
);
|
|
127
|
+
const obj = JSON.parse(
|
|
128
|
+
localStorage.getItem("autosave-example-solid") || "{}"
|
|
129
|
+
);
|
|
130
|
+
expect(obj.items).toMatchSnapshot();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("callback", async () => {
|
|
134
|
+
localStorage.clear();
|
|
135
|
+
|
|
136
|
+
let handle: PanelGroupHandle | null = null!;
|
|
137
|
+
|
|
138
|
+
const spy = vi.fn();
|
|
139
|
+
|
|
140
|
+
render(() => (
|
|
141
|
+
<div style={{ width: "500px" }}>
|
|
142
|
+
<AutosaveCollapsible
|
|
143
|
+
handle={(v) => (handle = v)}
|
|
144
|
+
onCollapseChange={spy}
|
|
145
|
+
/>
|
|
146
|
+
</div>
|
|
147
|
+
));
|
|
148
|
+
|
|
149
|
+
await dragHandle({ delta: -200 });
|
|
150
|
+
await expectTemplate(handle, "100px 10px 388px");
|
|
151
|
+
expect(spy).toHaveBeenCalledWith(true);
|
|
152
|
+
|
|
153
|
+
cleanup();
|
|
154
|
+
|
|
155
|
+
render(() => (
|
|
156
|
+
<div style={{ width: "500px" }}>
|
|
157
|
+
<AutosaveCollapsible
|
|
158
|
+
handle={(v) => (handle = v)}
|
|
159
|
+
onCollapseChange={spy}
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
));
|
|
163
|
+
|
|
164
|
+
await expectTemplate(handle, "100px 10px 388px");
|
|
165
|
+
await dragHandle({ delta: 200 });
|
|
166
|
+
expect(spy).toHaveBeenCalledWith(false);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("cookie", async () => {
|
|
170
|
+
// clear cookies
|
|
171
|
+
document.cookie = "test=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
|
172
|
+
|
|
173
|
+
let handle: PanelGroupHandle | null = null!;
|
|
174
|
+
|
|
175
|
+
render(() => (
|
|
176
|
+
<div style={{ width: "502px" }}>
|
|
177
|
+
<AutosaveCookie handle={(v) => (handle = v)} />
|
|
178
|
+
</div>
|
|
179
|
+
));
|
|
180
|
+
|
|
181
|
+
await waitForMeasurement(handle);
|
|
182
|
+
await expectTemplate(handle, "245px 10px 245px");
|
|
183
|
+
|
|
184
|
+
await dragHandle({ delta: 100 });
|
|
185
|
+
await expectTemplate(handle, "343px 10px 147px");
|
|
186
|
+
|
|
187
|
+
await waitForCondition(() =>
|
|
188
|
+
document.cookie.includes("autosave-cookie-solid")
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(document.cookie).toMatchSnapshot();
|
|
192
|
+
|
|
193
|
+
const snapshot = Cookies.get("autosave-cookie-solid");
|
|
194
|
+
|
|
195
|
+
cleanup();
|
|
196
|
+
|
|
197
|
+
render(() => (
|
|
198
|
+
<div style={{ width: "500px" }}>
|
|
199
|
+
<AutosaveCookie
|
|
200
|
+
handle={(v) => (handle = v)}
|
|
201
|
+
snapshot={snapshot ? JSON.parse(snapshot) : undefined}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
));
|
|
205
|
+
|
|
206
|
+
await expectTemplate(handle, "341.609375px 10px 146.390625px");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("Keyboard interactions with collapsed panels", async () => {
|
|
211
|
+
let handle: PanelGroupHandle | null = null!;
|
|
212
|
+
|
|
213
|
+
render(() => (
|
|
214
|
+
<div style={{ width: "500px" }}>
|
|
215
|
+
<Collapsible handle={(v) => (handle = v)} />
|
|
216
|
+
</div>
|
|
217
|
+
));
|
|
218
|
+
|
|
219
|
+
await waitForMeasurement(handle);
|
|
220
|
+
await expectTemplate(handle, "209px 10px 209px 10px 60px");
|
|
221
|
+
|
|
222
|
+
const resizer2 = document.getElementById("resizer-2")!;
|
|
223
|
+
fireEvent.keyDown(resizer2, { key: "Enter" });
|
|
224
|
+
await expectTemplate(handle, "209px 10px 169px 10px 100px");
|
|
225
|
+
|
|
226
|
+
fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
|
|
227
|
+
fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
|
|
228
|
+
fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
|
|
229
|
+
fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
|
|
230
|
+
await expectTemplate(handle, "209px 10px 165px 10px 104px");
|
|
231
|
+
|
|
232
|
+
fireEvent.keyDown(resizer2, { key: "ArrowLeft", shiftKey: true });
|
|
233
|
+
await expectTemplate(
|
|
234
|
+
handle,
|
|
235
|
+
"209.03125px 10px 149.984375px 10px 118.984375px"
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
fireEvent.keyDown(resizer2, { key: "Enter" });
|
|
239
|
+
await expectTemplate(handle, "209.03125px 10px 208.96875px 10px 60px");
|
|
240
|
+
|
|
241
|
+
fireEvent.keyDown(resizer2, { key: "Enter" });
|
|
242
|
+
await expectTemplate(handle, "209.0625px 10px 149.96875px 10px 118.96875px");
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("imperative panel API", async () => {
|
|
246
|
+
test("panel group", async () => {
|
|
247
|
+
let handle: PanelGroupHandle;
|
|
248
|
+
|
|
249
|
+
render(() => (
|
|
250
|
+
<div style={{ width: "500px" }}>
|
|
251
|
+
<Collapsible handle={(v) => (handle = v)} />
|
|
252
|
+
</div>
|
|
253
|
+
));
|
|
254
|
+
|
|
255
|
+
await waitForMeasurement(handle!);
|
|
256
|
+
|
|
257
|
+
expect(handle!.getPercentageSizes()).toMatchInlineSnapshot(`
|
|
258
|
+
[
|
|
259
|
+
0.5,
|
|
260
|
+
0.020080321285140562,
|
|
261
|
+
0.5,
|
|
262
|
+
0.020080321285140562,
|
|
263
|
+
0.12048192771084337,
|
|
264
|
+
]
|
|
265
|
+
`);
|
|
266
|
+
|
|
267
|
+
expect(handle!.getPixelSizes()).toMatchInlineSnapshot(`
|
|
268
|
+
[
|
|
269
|
+
209,
|
|
270
|
+
10,
|
|
271
|
+
209,
|
|
272
|
+
10,
|
|
273
|
+
60,
|
|
274
|
+
]
|
|
275
|
+
`);
|
|
276
|
+
|
|
277
|
+
await expectTemplate(handle!, "209px 10px 209px 10px 60px");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("panel", async () => {
|
|
281
|
+
let handle: PanelGroupHandle;
|
|
282
|
+
let rightHandle: PanelHandle;
|
|
283
|
+
let leftHandle: PanelHandle;
|
|
284
|
+
|
|
285
|
+
render(() => (
|
|
286
|
+
<div style={{ width: "500px" }}>
|
|
287
|
+
<Collapsible
|
|
288
|
+
handle={(v) => (handle = v)}
|
|
289
|
+
rightPanelHandle={(v) => (rightHandle = v)}
|
|
290
|
+
leftPanelHandle={(v) => (leftHandle = v)}
|
|
291
|
+
/>
|
|
292
|
+
</div>
|
|
293
|
+
));
|
|
294
|
+
|
|
295
|
+
await waitForMeasurement(handle!);
|
|
296
|
+
|
|
297
|
+
expect(rightHandle!.isCollapsed()).toBe(true);
|
|
298
|
+
expect(rightHandle!.isExpanded()).toBe(false);
|
|
299
|
+
|
|
300
|
+
rightHandle!.expand();
|
|
301
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
302
|
+
|
|
303
|
+
expect(rightHandle!.isCollapsed()).toBe(false);
|
|
304
|
+
expect(rightHandle!.isExpanded()).toBe(true);
|
|
305
|
+
|
|
306
|
+
rightHandle!.collapse();
|
|
307
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
308
|
+
|
|
309
|
+
expect(rightHandle!.isCollapsed()).toBe(true);
|
|
310
|
+
expect(rightHandle!.isExpanded()).toBe(false);
|
|
311
|
+
|
|
312
|
+
// Test the non controlled version
|
|
313
|
+
|
|
314
|
+
expect(leftHandle!.isCollapsed()).toBe(false);
|
|
315
|
+
expect(leftHandle!.isExpanded()).toBe(true);
|
|
316
|
+
|
|
317
|
+
leftHandle!.collapse();
|
|
318
|
+
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
319
|
+
|
|
320
|
+
expect(leftHandle!.isCollapsed()).toBe(true);
|
|
321
|
+
expect(leftHandle!.isExpanded()).toBe(false);
|
|
322
|
+
expect(rightHandle!.getPercentageSize()).toBe(
|
|
323
|
+
leftHandle!.getPercentageSize()
|
|
324
|
+
);
|
|
325
|
+
expect(rightHandle!.getPixelSize()).toBe(leftHandle!.getPixelSize());
|
|
326
|
+
|
|
327
|
+
leftHandle!.expand();
|
|
328
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
329
|
+
|
|
330
|
+
expect(leftHandle!.isCollapsed()).toBe(false);
|
|
331
|
+
expect(leftHandle!.isExpanded()).toBe(true);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Autosave > cookie 1`] = `"autosave-cookie-solid=%7B%22size%22%3A%7B%22x%22%3A0%2C%22y%22%3A0%2C%22width%22%3A500%2C%22height%22%3A198%2C%22top%22%3A0%2C%22right%22%3A500%2C%22bottom%22%3A198%2C%22left%22%3A0%7D%2C%22items%22%3A%5B%7B%22type%22%3A%22panel%22%2C%22currentValue%22%3A%7B%22type%22%3A%22percent%22%2C%22value%22%3A%220.7%22%7D%2C%22min%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22max%22%3A%221fr%22%2C%22collapsedSize%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22onCollapseChange%22%3A%7B%7D%2C%22onResize%22%3A%7B%7D%2C%22collapseIsControlled%22%3Afalse%2C%22id%22%3A%221%22%7D%2C%7B%22type%22%3A%22handle%22%2C%22size%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%2210%22%7D%2C%22id%22%3A%22resizer1%22%7D%2C%7B%22type%22%3A%22panel%22%2C%22currentValue%22%3A%7B%22type%22%3A%22percent%22%2C%22value%22%3A%220.3%22%7D%2C%22min%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22max%22%3A%221fr%22%2C%22collapsedSize%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22onCollapseChange%22%3A%7B%7D%2C%22onResize%22%3A%7B%7D%2C%22collapseIsControlled%22%3Afalse%2C%22id%22%3A%222%22%7D%5D%2C%22orientation%22%3A%22horizontal%22%2C%22dragOvershoot%22%3A%220%22%2C%22groupId%22%3A%22autosave-cookie-solid%22%2C%22autosaveStrategy%22%3A%22cookie%22%7D"`;
|
|
4
|
+
|
|
5
|
+
exports[`Autosave > localStorage 1`] = `
|
|
6
|
+
[
|
|
7
|
+
{
|
|
8
|
+
"collapseIsControlled": false,
|
|
9
|
+
"collapsedSize": {
|
|
10
|
+
"type": "pixel",
|
|
11
|
+
"value": "0",
|
|
12
|
+
},
|
|
13
|
+
"currentValue": {
|
|
14
|
+
"type": "percent",
|
|
15
|
+
"value": "0.70081967213114754098",
|
|
16
|
+
},
|
|
17
|
+
"id": "1",
|
|
18
|
+
"max": "1fr",
|
|
19
|
+
"min": {
|
|
20
|
+
"type": "pixel",
|
|
21
|
+
"value": "0",
|
|
22
|
+
},
|
|
23
|
+
"onCollapseChange": {},
|
|
24
|
+
"onResize": {},
|
|
25
|
+
"type": "panel",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "resizer",
|
|
29
|
+
"size": {
|
|
30
|
+
"type": "pixel",
|
|
31
|
+
"value": "10",
|
|
32
|
+
},
|
|
33
|
+
"type": "handle",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"collapseIsControlled": false,
|
|
37
|
+
"collapsedSize": {
|
|
38
|
+
"type": "pixel",
|
|
39
|
+
"value": "0",
|
|
40
|
+
},
|
|
41
|
+
"currentValue": {
|
|
42
|
+
"type": "percent",
|
|
43
|
+
"value": "0.29918032786885245902",
|
|
44
|
+
},
|
|
45
|
+
"id": "2",
|
|
46
|
+
"max": "1fr",
|
|
47
|
+
"min": {
|
|
48
|
+
"type": "pixel",
|
|
49
|
+
"value": "0",
|
|
50
|
+
},
|
|
51
|
+
"onCollapseChange": {},
|
|
52
|
+
"onResize": {},
|
|
53
|
+
"type": "panel",
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
`;
|
package/src/context.tsx
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createContext, useContext, Accessor, JSXElement } from "solid-js";
|
|
2
|
+
import { GroupMachineContextValue, SendFn } from "@window-splitter/state";
|
|
3
|
+
|
|
4
|
+
export const InitialPrerenderContext = createContext<Accessor<boolean>>(
|
|
5
|
+
() => false
|
|
6
|
+
);
|
|
7
|
+
export const MachineActorContext = createContext<SendFn | undefined>();
|
|
8
|
+
export const GroupIdContext = createContext<string | undefined>();
|
|
9
|
+
export const MachineStateContext = createContext<
|
|
10
|
+
Accessor<GroupMachineContextValue | undefined> | undefined
|
|
11
|
+
>();
|
|
12
|
+
|
|
13
|
+
export function useInitialPrerenderContext() {
|
|
14
|
+
const context = useContext(InitialPrerenderContext);
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function useMachineActor() {
|
|
19
|
+
const context = useContext(MachineActorContext);
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useGroupId() {
|
|
24
|
+
const context = useContext(GroupIdContext);
|
|
25
|
+
return context;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useMachineState() {
|
|
29
|
+
const context = useContext(MachineStateContext);
|
|
30
|
+
return context;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Create a provider component that bundles all the contexts together
|
|
34
|
+
export function GroupMachineProvider(props: {
|
|
35
|
+
children: JSXElement;
|
|
36
|
+
groupId: string;
|
|
37
|
+
send: SendFn;
|
|
38
|
+
state: Accessor<GroupMachineContextValue | undefined>;
|
|
39
|
+
initialPrerender?: Accessor<boolean>;
|
|
40
|
+
}) {
|
|
41
|
+
return (
|
|
42
|
+
<InitialPrerenderContext.Provider
|
|
43
|
+
value={props.initialPrerender ?? (() => false)}
|
|
44
|
+
>
|
|
45
|
+
{/* The rule is wrong. the docs even suggust this pattern */}
|
|
46
|
+
{/* eslint-disable-next-line solid/reactivity */}
|
|
47
|
+
<GroupIdContext.Provider value={props.groupId}>
|
|
48
|
+
{/* eslint-disable-next-line solid/reactivity */}
|
|
49
|
+
<MachineActorContext.Provider value={props.send}>
|
|
50
|
+
{/* eslint-disable-next-line solid/reactivity */}
|
|
51
|
+
<MachineStateContext.Provider value={props.state}>
|
|
52
|
+
{props.children}
|
|
53
|
+
</MachineStateContext.Provider>
|
|
54
|
+
</MachineActorContext.Provider>
|
|
55
|
+
</GroupIdContext.Provider>
|
|
56
|
+
</InitialPrerenderContext.Provider>
|
|
57
|
+
);
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./SolidWIndowSplitter.js";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { mergeAttributes as mergeAttributesBase } from "@window-splitter/interface";
|
|
3
|
+
|
|
4
|
+
export type MaybeAccessor<T> = T | (() => T);
|
|
5
|
+
|
|
6
|
+
export function mergeSolidAttributes<T>(source: MaybeAccessor<T>): T;
|
|
7
|
+
export function mergeSolidAttributes<T, U>(
|
|
8
|
+
source: MaybeAccessor<T>,
|
|
9
|
+
source1: MaybeAccessor<U>
|
|
10
|
+
): T & U;
|
|
11
|
+
export function mergeSolidAttributes<T, U, V>(
|
|
12
|
+
source: MaybeAccessor<T>,
|
|
13
|
+
source1: MaybeAccessor<U>,
|
|
14
|
+
source2: MaybeAccessor<V>
|
|
15
|
+
): T & U & V;
|
|
16
|
+
export function mergeSolidAttributes<T, U, V, W>(
|
|
17
|
+
source: MaybeAccessor<T>,
|
|
18
|
+
source1: MaybeAccessor<U>,
|
|
19
|
+
source2: MaybeAccessor<V>,
|
|
20
|
+
source3: MaybeAccessor<W>
|
|
21
|
+
): T & U & V & W;
|
|
22
|
+
export function mergeSolidAttributes(...sources: any[]) {
|
|
23
|
+
const target = {};
|
|
24
|
+
for (let i = 0; i < sources.length; i++) {
|
|
25
|
+
let source = sources[i];
|
|
26
|
+
if (typeof source === "function") source = source();
|
|
27
|
+
if (source) {
|
|
28
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
29
|
+
for (const key in descriptors) {
|
|
30
|
+
if (key in target) continue;
|
|
31
|
+
Object.defineProperty(target, key, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get() {
|
|
34
|
+
let e = {};
|
|
35
|
+
if (
|
|
36
|
+
key === "style" ||
|
|
37
|
+
key === "class" ||
|
|
38
|
+
key === "className" ||
|
|
39
|
+
key.startsWith("on")
|
|
40
|
+
) {
|
|
41
|
+
for (let j = 0; j < sources.length; j++) {
|
|
42
|
+
let s = sources[j];
|
|
43
|
+
if (typeof s === "function") s = s();
|
|
44
|
+
e = mergeAttributesBase(e, { [key]: (s || {})[key] });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (e as any)[key];
|
|
48
|
+
}
|
|
49
|
+
for (let j = sources.length - 1; j >= 0; j--) {
|
|
50
|
+
let s = sources[j];
|
|
51
|
+
if (typeof s === "function") s = s();
|
|
52
|
+
const v = (s || {})[key];
|
|
53
|
+
if (v !== undefined) return v;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return target;
|
|
61
|
+
}
|
package/tsconfig.json
ADDED
package/vite.config.js
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import solidPlugin from "vite-plugin-solid";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [solidPlugin()],
|
|
6
|
+
build: {
|
|
7
|
+
target: "esnext",
|
|
8
|
+
},
|
|
9
|
+
test: {
|
|
10
|
+
coverage: {
|
|
11
|
+
provider: "istanbul",
|
|
12
|
+
include: ["**/*.tsx", "!**/*.stories.tsx", "!**/*.test.tsx"],
|
|
13
|
+
reporter: ["text", "html", "json-summary", "json"],
|
|
14
|
+
reportOnFailure: true,
|
|
15
|
+
},
|
|
16
|
+
browser: {
|
|
17
|
+
enabled: true,
|
|
18
|
+
provider: "playwright",
|
|
19
|
+
instances: [{ browser: "chromium" }],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|