@window-splitter/vue 0.8.5

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,275 @@
1
+ import "../.storybook/preview.css";
2
+
3
+ import { test, expect, describe, vi } from "vitest";
4
+ import { cleanup, getByText, waitFor } from "@testing-library/vue";
5
+ import { fireEvent } from "@testing-library/dom";
6
+ import { composeStories } from "@storybook/vue3";
7
+ import { createTestUtils, dragHandle } from "@window-splitter/interface/test";
8
+ import * as Cookies from "tiny-cookie";
9
+
10
+ import * as stories from "./VueWindowSplitter.stories.js";
11
+ import { PanelGroupHandle, PanelHandle } from "@window-splitter/interface";
12
+
13
+ const {
14
+ Simple,
15
+ Collapsible,
16
+ VerticalLayout,
17
+ ConditionalPanel,
18
+ DynamicConstraints,
19
+ Autosave,
20
+ AutosaveCollapsible,
21
+ AutosaveCookie,
22
+ } = composeStories(stories);
23
+
24
+ const { waitForMeasurement, expectTemplate, waitForCondition } =
25
+ createTestUtils({
26
+ waitFor,
27
+ });
28
+
29
+ test("horizontal layout", async () => {
30
+ const handle = { value: null } as { value: PanelGroupHandle | null };
31
+ await Simple.run({ args: { handle } });
32
+
33
+ await waitForMeasurement(handle.value!);
34
+
35
+ expect(getByText(document.body, "Panel 1")).toBeInTheDocument();
36
+ expect(getByText(document.body, "Panel 2")).toBeInTheDocument();
37
+
38
+ await expectTemplate(handle.value!, "244px 10px 244px");
39
+
40
+ // Should respect the min
41
+ await dragHandle({ delta: 300 });
42
+ await expectTemplate(handle.value!, "388px 10px 100px");
43
+ });
44
+
45
+ test("vertical layout", async () => {
46
+ const handle = { value: null } as { value: PanelGroupHandle | null };
47
+ await VerticalLayout.run({ args: { handle } });
48
+ await waitForMeasurement(handle.value!);
49
+
50
+ expect(getByText(document.body, "top")).toBeInTheDocument();
51
+ expect(getByText(document.body, "middle")).toBeInTheDocument();
52
+ expect(getByText(document.body, "bottom")).toBeInTheDocument();
53
+
54
+ await expectTemplate(handle.value!, "96px 10px 108px 10px 96px");
55
+
56
+ // Should respect the min
57
+ await dragHandle({ delta: 100, orientation: "vertical" });
58
+ await expectTemplate(handle.value!, "172px 10px 64px 10px 64px");
59
+ });
60
+
61
+ test("Conditional Panels", async () => {
62
+ const handle = { value: null } as { value: PanelGroupHandle | null };
63
+ await ConditionalPanel.run({ args: { handle } });
64
+ await waitForMeasurement(handle.value!);
65
+
66
+ await expectTemplate(handle.value!, "244px 10px 244px");
67
+
68
+ getByText(document.body, "Expand").click();
69
+ await expectTemplate(handle.value!, "244px 10px 134px 10px 100px");
70
+
71
+ getByText(document.body, "Close").click();
72
+ await expectTemplate(handle.value!, "244px 10px 244px");
73
+ });
74
+
75
+ test("Dynamic constraints", async () => {
76
+ const handle = { value: null } as { value: PanelGroupHandle | null };
77
+ await DynamicConstraints.run({ args: { handle } });
78
+ await waitForMeasurement(handle.value!);
79
+
80
+ await waitForMeasurement(handle.value!);
81
+ await expectTemplate(handle.value!, "100px 10px 178px 10px 700px");
82
+
83
+ getByText(document.body, "Toggle Custom").click();
84
+ await expectTemplate(handle.value!, "500px 10px 178px 10px 300px");
85
+
86
+ getByText(document.body, "Toggle Custom").click();
87
+ await expectTemplate(handle.value!, "400px 10px 178px 10px 400px");
88
+ });
89
+
90
+ describe("Autosave", () => {
91
+ test("localStorage", async () => {
92
+ localStorage.clear();
93
+
94
+ const handle = { value: null } as { value: PanelGroupHandle | null };
95
+ await Autosave.run({ args: { handle } });
96
+
97
+ await waitForMeasurement(handle.value!);
98
+ await expectTemplate(handle.value!, "244px 10px 244px");
99
+
100
+ await dragHandle({ delta: 100 });
101
+ await expectTemplate(handle.value!, "342px 10px 146px");
102
+
103
+ await waitForCondition(() =>
104
+ Boolean(localStorage.getItem("autosave-example-vue")),
105
+ );
106
+ const obj = JSON.parse(
107
+ localStorage.getItem("autosave-example-vue") || "{}",
108
+ );
109
+ expect(obj.items).toMatchSnapshot();
110
+ });
111
+
112
+ test("callback", async () => {
113
+ localStorage.clear();
114
+
115
+ const handle = { value: null } as { value: PanelGroupHandle | null };
116
+ const spy = vi.fn();
117
+
118
+ await AutosaveCollapsible.run({ args: { handle, onCollapseChange: spy } });
119
+
120
+ await dragHandle({ delta: -200 });
121
+ await expectTemplate(handle.value!, "100px 10px 388px");
122
+ expect(spy).toHaveBeenCalledWith(true);
123
+
124
+ cleanup();
125
+
126
+ const spy2 = vi.fn();
127
+ await AutosaveCollapsible.run({ args: { handle, onCollapseChange: spy2 } });
128
+
129
+ await expectTemplate(handle.value!, "100px 10px 388px");
130
+ await dragHandle({ delta: 200 });
131
+ expect(spy2).toHaveBeenCalledWith(false);
132
+ });
133
+
134
+ test("cookie", async () => {
135
+ // clear cookies
136
+ document.cookie = "test=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
137
+
138
+ const handle = { value: null } as { value: PanelGroupHandle | null };
139
+ await AutosaveCookie.run({ args: { handle } });
140
+
141
+ await waitForMeasurement(handle.value!);
142
+ await expectTemplate(handle.value!, "245px 10px 245px");
143
+
144
+ await dragHandle({ delta: 100 });
145
+ await expectTemplate(handle.value!, "343px 10px 147px");
146
+
147
+ await waitForCondition(() =>
148
+ document.cookie.includes("autosave-cookie-vue"),
149
+ );
150
+
151
+ expect(document.cookie).toMatchSnapshot();
152
+
153
+ const snapshot = Cookies.get("autosave-cookie-vue");
154
+
155
+ cleanup();
156
+
157
+ const handle2 = { value: null } as { value: PanelGroupHandle | null };
158
+ await AutosaveCookie.run({
159
+ args: { handle: handle2, snapshot: JSON.parse(snapshot!) },
160
+ });
161
+
162
+ await expectTemplate(handle2.value!, "343px 10px 147px");
163
+ });
164
+ });
165
+
166
+ test("Keyboard interactions with collapsed panels", async () => {
167
+ const handle = { value: null } as { value: PanelGroupHandle | null };
168
+ await Collapsible.run({ args: { handle } });
169
+
170
+ await waitForMeasurement(handle.value!);
171
+ await expectTemplate(handle.value!, "209px 10px 209px 10px 60px");
172
+
173
+ const resizer2 = document.getElementById("resizer-2")!;
174
+ fireEvent.keyDown(resizer2, { key: "Enter" });
175
+ await expectTemplate(handle.value!, "209px 10px 169px 10px 100px");
176
+
177
+ fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
178
+ fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
179
+ fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
180
+ fireEvent.keyDown(resizer2, { key: "ArrowLeft" });
181
+ await expectTemplate(handle.value!, "209px 10px 165px 10px 104px");
182
+
183
+ fireEvent.keyDown(resizer2, { key: "ArrowLeft", shiftKey: true });
184
+ await expectTemplate(
185
+ handle.value!,
186
+ "209.03125px 10px 149.984375px 10px 118.984375px",
187
+ );
188
+
189
+ fireEvent.keyDown(resizer2, { key: "Enter" });
190
+ await expectTemplate(handle.value!, "209.03125px 10px 208.96875px 10px 60px");
191
+
192
+ fireEvent.keyDown(resizer2, { key: "Enter" });
193
+ await expectTemplate(
194
+ handle.value!,
195
+ "209.0625px 10px 149.96875px 10px 118.96875px",
196
+ );
197
+ });
198
+
199
+ describe("imperative panel API", async () => {
200
+ test("panel group", async () => {
201
+ const handle = { value: null } as { value: PanelGroupHandle | null };
202
+
203
+ await Collapsible.run({ args: { handle } });
204
+ await waitForMeasurement(handle.value!);
205
+
206
+ expect(handle.value!.getPercentageSizes()).toMatchInlineSnapshot(`
207
+ [
208
+ 0.5,
209
+ 0.020080321285140562,
210
+ 0.5,
211
+ 0.020080321285140562,
212
+ 0.12048192771084337,
213
+ ]
214
+ `);
215
+
216
+ expect(handle.value!.getPixelSizes()).toMatchInlineSnapshot(`
217
+ [
218
+ 209,
219
+ 10,
220
+ 209,
221
+ 10,
222
+ 60,
223
+ ]
224
+ `);
225
+
226
+ await expectTemplate(handle.value!, "209px 10px 209px 10px 60px");
227
+ });
228
+
229
+ test("panel", async () => {
230
+ const handle = { value: null } as { value: PanelGroupHandle | null };
231
+ const rightHandle = { value: null } as { value: PanelHandle | null };
232
+ const leftHandle = { value: null } as { value: PanelHandle | null };
233
+
234
+ await Collapsible.run({ args: { handle, leftHandle, rightHandle } });
235
+ await waitForMeasurement(handle.value!);
236
+
237
+ expect(rightHandle.value!.isCollapsed()).toBe(true);
238
+ expect(rightHandle.value!.isExpanded()).toBe(false);
239
+
240
+ rightHandle.value!.expand();
241
+ await new Promise((resolve) => setTimeout(resolve, 2000));
242
+
243
+ expect(rightHandle.value!.isCollapsed()).toBe(false);
244
+ expect(rightHandle.value!.isExpanded()).toBe(true);
245
+
246
+ rightHandle.value!.collapse();
247
+ await new Promise((resolve) => setTimeout(resolve, 2000));
248
+
249
+ expect(rightHandle.value!.isCollapsed()).toBe(true);
250
+ expect(rightHandle.value!.isExpanded()).toBe(false);
251
+
252
+ // Test the non controlled version
253
+
254
+ expect(leftHandle.value!.isCollapsed()).toBe(false);
255
+ expect(leftHandle.value!.isExpanded()).toBe(true);
256
+
257
+ leftHandle.value!.collapse();
258
+ await new Promise((resolve) => setTimeout(resolve, 2000));
259
+
260
+ expect(leftHandle.value!.isCollapsed()).toBe(true);
261
+ expect(leftHandle.value!.isExpanded()).toBe(false);
262
+ expect(rightHandle.value!.getPercentageSize()).toBe(
263
+ leftHandle.value!.getPercentageSize(),
264
+ );
265
+ expect(rightHandle.value!.getPixelSize()).toBe(
266
+ leftHandle.value!.getPixelSize(),
267
+ );
268
+
269
+ leftHandle.value!.expand();
270
+ await new Promise((resolve) => setTimeout(resolve, 5000));
271
+
272
+ expect(leftHandle.value!.isCollapsed()).toBe(false);
273
+ expect(leftHandle.value!.isExpanded()).toBe(true);
274
+ });
275
+ });
@@ -0,0 +1,58 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Autosave > cookie 1`] = `"autosave-cookie-vue=%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%22collapsible%22%3Afalse%2C%22collapsedSize%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22onResize%22%3A%7B%7D%2C%22collapseIsControlled%22%3Afalse%2C%22id%22%3A%22panel-1%22%2C%22isStaticAtRest%22%3Afalse%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%22collapsible%22%3Afalse%2C%22collapsedSize%22%3A%7B%22type%22%3A%22pixel%22%2C%22value%22%3A%220%22%7D%2C%22onResize%22%3A%7B%7D%2C%22collapseIsControlled%22%3Afalse%2C%22id%22%3A%22panel-2%22%2C%22isStaticAtRest%22%3Afalse%7D%5D%2C%22orientation%22%3A%22horizontal%22%2C%22dragOvershoot%22%3A%220%22%2C%22groupId%22%3A%22autosave-cookie-vue%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
+ "collapsible": false,
14
+ "currentValue": {
15
+ "type": "percent",
16
+ "value": "0.70081967213114754098",
17
+ },
18
+ "id": "panel-1",
19
+ "isStaticAtRest": false,
20
+ "max": "1fr",
21
+ "min": {
22
+ "type": "pixel",
23
+ "value": "0",
24
+ },
25
+ "onResize": {},
26
+ "type": "panel",
27
+ },
28
+ {
29
+ "id": "resizer",
30
+ "size": {
31
+ "type": "pixel",
32
+ "value": "10",
33
+ },
34
+ "type": "handle",
35
+ },
36
+ {
37
+ "collapseIsControlled": false,
38
+ "collapsedSize": {
39
+ "type": "pixel",
40
+ "value": "0",
41
+ },
42
+ "collapsible": false,
43
+ "currentValue": {
44
+ "type": "percent",
45
+ "value": "0.29918032786885245902",
46
+ },
47
+ "id": "panel-2",
48
+ "isStaticAtRest": false,
49
+ "max": "1fr",
50
+ "min": {
51
+ "type": "pixel",
52
+ "value": "0",
53
+ },
54
+ "onResize": {},
55
+ "type": "panel",
56
+ },
57
+ ]
58
+ `;
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { default as Panel } from "./Panel.vue";
2
+ export * from "./Panel.vue";
3
+ export { default as PanelGroup } from "./PanelGroup.vue";
4
+ export * from "./PanelGroup.vue";
5
+ export { default as PanelResizer } from "./PanelResizer.vue";
6
+ export * from "./PanelResizer.vue";
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "inlineSources": true,
8
+ "jsx": "react",
9
+ "module": "nodenext",
10
+ "moduleResolution": "nodenext",
11
+ "noUncheckedIndexedAccess": true,
12
+ "resolveJsonModule": true,
13
+ "skipLibCheck": true,
14
+ "sourceMap": true,
15
+ "strict": true,
16
+ "target": "es2022",
17
+ "baseUrl": ".",
18
+ "types": ["@testing-library/jest-dom"]
19
+ },
20
+ "exclude": ["dist/**"]
21
+ }
package/vite.config.js ADDED
@@ -0,0 +1,18 @@
1
+ import vue from "@vitejs/plugin-vue";
2
+ import dts from "vite-plugin-dts";
3
+ import { defineConfig } from "vite";
4
+
5
+ export default defineConfig({
6
+ plugins: [vue(), dts()],
7
+ build: {
8
+ sourcemap: true,
9
+ lib: {
10
+ entry: "./src/index.ts",
11
+ formats: ["es", "cjs"],
12
+ fileName: "index",
13
+ },
14
+ rollupOptions: {
15
+ external: ["vue"],
16
+ },
17
+ },
18
+ });
@@ -0,0 +1,22 @@
1
+ import { defineConfig } from "vitest/config";
2
+ import vuePlugin from "@vitejs/plugin-vue";
3
+
4
+ export default defineConfig({
5
+ plugins: [vuePlugin()],
6
+ build: {
7
+ target: "esnext",
8
+ },
9
+ test: {
10
+ coverage: {
11
+ provider: "istanbul",
12
+ include: ["**/*.vue", "!**/*.stories.ts", "!**/*.test.ts"],
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
+ });