@flight-framework/router 0.4.0 → 0.5.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/README.md +488 -488
- package/dist/index.d.ts +2 -2
- package/dist/index.js +34 -0
- package/dist/preact/index.d.ts +4 -4
- package/dist/preact/index.js +69 -2
- package/dist/{prefetch-COkjiZgH.d.ts → prefetch-C_RFFXW0.d.ts} +11 -1
- package/dist/react/index.d.ts +17 -5
- package/dist/react/index.js +65 -3
- package/dist/solid/index.d.ts +3 -3
- package/dist/solid/index.js +67 -0
- package/dist/svelte/index.d.ts +2 -2
- package/dist/svelte/index.js +34 -0
- package/dist/vue/index.d.ts +2 -2
- package/dist/vue/index.js +66 -0
- package/package.json +94 -94
- package/LICENSE +0 -21
package/dist/vue/index.js
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
// src/context.ts
|
|
2
2
|
var isBrowser = typeof window !== "undefined";
|
|
3
|
+
function createSetSearchParams() {
|
|
4
|
+
return (nextInit, navigateOptions = {}) => {
|
|
5
|
+
if (!isBrowser) return;
|
|
6
|
+
const currentUrl = new URL(window.location.href);
|
|
7
|
+
let newSearchParams;
|
|
8
|
+
if (typeof nextInit === "function") {
|
|
9
|
+
newSearchParams = nextInit(new URLSearchParams(currentUrl.search));
|
|
10
|
+
} else if (nextInit instanceof URLSearchParams) {
|
|
11
|
+
newSearchParams = nextInit;
|
|
12
|
+
} else {
|
|
13
|
+
newSearchParams = new URLSearchParams();
|
|
14
|
+
for (const [key, value] of Object.entries(nextInit)) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
for (const v of value) {
|
|
17
|
+
newSearchParams.append(key, v);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
newSearchParams.set(key, value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const newUrl = `${currentUrl.pathname}${newSearchParams.toString() ? `?${newSearchParams.toString()}` : ""}${currentUrl.hash}`;
|
|
25
|
+
if (navigateOptions.replace) {
|
|
26
|
+
window.history.replaceState(navigateOptions.state ?? null, "", newUrl);
|
|
27
|
+
} else {
|
|
28
|
+
window.history.pushState(navigateOptions.state ?? null, "", newUrl);
|
|
29
|
+
}
|
|
30
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
var globalSetSearchParams = createSetSearchParams();
|
|
3
34
|
var currentContext = {
|
|
4
35
|
path: "/",
|
|
5
36
|
searchParams: new URLSearchParams(),
|
|
37
|
+
setSearchParams: globalSetSearchParams,
|
|
6
38
|
navigate: () => {
|
|
7
39
|
},
|
|
8
40
|
back: () => {
|
|
@@ -56,6 +88,7 @@ function initRouter(options = {}) {
|
|
|
56
88
|
currentContext = {
|
|
57
89
|
path,
|
|
58
90
|
searchParams,
|
|
91
|
+
setSearchParams: globalSetSearchParams,
|
|
59
92
|
navigate: navigateTo,
|
|
60
93
|
back: () => isBrowser && window.history.back(),
|
|
61
94
|
forward: () => isBrowser && window.history.forward()
|
|
@@ -117,6 +150,7 @@ if (typeof globalThis !== "undefined") {
|
|
|
117
150
|
return {
|
|
118
151
|
path: basePath && path.startsWith(basePath) ? path.slice(basePath.length) || "/" : path,
|
|
119
152
|
searchParams,
|
|
153
|
+
setSearchParams: globalSetSearchParams,
|
|
120
154
|
navigate: navigateTo,
|
|
121
155
|
back: () => isBrowser && window.history.back(),
|
|
122
156
|
forward: () => isBrowser && window.history.forward()
|
|
@@ -566,12 +600,44 @@ function navigateTo2(to, options = {}) {
|
|
|
566
600
|
window.scrollTo({ top: 0, left: 0, behavior: "instant" });
|
|
567
601
|
}
|
|
568
602
|
}
|
|
603
|
+
function createSetSearchParams2() {
|
|
604
|
+
return (nextInit, navigateOptions = {}) => {
|
|
605
|
+
if (!isBrowser6) return;
|
|
606
|
+
const currentUrl = new URL(window.location.href);
|
|
607
|
+
let newSearchParams;
|
|
608
|
+
if (typeof nextInit === "function") {
|
|
609
|
+
newSearchParams = nextInit(new URLSearchParams(currentUrl.search));
|
|
610
|
+
} else if (nextInit instanceof URLSearchParams) {
|
|
611
|
+
newSearchParams = nextInit;
|
|
612
|
+
} else {
|
|
613
|
+
newSearchParams = new URLSearchParams();
|
|
614
|
+
for (const [key, value] of Object.entries(nextInit)) {
|
|
615
|
+
if (Array.isArray(value)) {
|
|
616
|
+
for (const v of value) {
|
|
617
|
+
newSearchParams.append(key, v);
|
|
618
|
+
}
|
|
619
|
+
} else {
|
|
620
|
+
newSearchParams.set(key, value);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
const newUrl = `${currentUrl.pathname}${newSearchParams.toString() ? `?${newSearchParams.toString()}` : ""}${currentUrl.hash}`;
|
|
625
|
+
if (navigateOptions.replace) {
|
|
626
|
+
window.history.replaceState(navigateOptions.state ?? null, "", newUrl);
|
|
627
|
+
} else {
|
|
628
|
+
window.history.pushState(navigateOptions.state ?? null, "", newUrl);
|
|
629
|
+
}
|
|
630
|
+
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
var globalSetSearchParams2 = createSetSearchParams2();
|
|
569
634
|
function RouterProvider2(props, { slots }) {
|
|
570
635
|
const path = ref2(isBrowser6 ? window.location.pathname : props.initialPath || "/");
|
|
571
636
|
const searchParams = ref2(isBrowser6 ? new URLSearchParams(window.location.search) : new URLSearchParams());
|
|
572
637
|
const routerState = ref2({
|
|
573
638
|
path: path.value,
|
|
574
639
|
searchParams: searchParams.value,
|
|
640
|
+
setSearchParams: globalSetSearchParams2,
|
|
575
641
|
navigate: navigateTo2,
|
|
576
642
|
back: () => isBrowser6 && window.history.back(),
|
|
577
643
|
forward: () => isBrowser6 && window.history.forward()
|
package/package.json
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@flight-framework/router",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Agnostic client-side routing primitives for Flight Framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./react": {
|
|
15
|
+
"types": "./dist/react/index.d.ts",
|
|
16
|
+
"import": "./dist/react/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./vue": {
|
|
19
|
+
"types": "./dist/vue/index.d.ts",
|
|
20
|
+
"import": "./dist/vue/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./svelte": {
|
|
23
|
+
"types": "./dist/svelte/index.d.ts",
|
|
24
|
+
"import": "./dist/svelte/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./solid": {
|
|
27
|
+
"types": "./dist/solid/index.d.ts",
|
|
28
|
+
"import": "./dist/solid/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./preact": {
|
|
31
|
+
"types": "./dist/preact/index.d.ts",
|
|
32
|
+
"import": "./dist/preact/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"dev": "tsup --watch"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"flight",
|
|
45
|
+
"router",
|
|
46
|
+
"spa",
|
|
47
|
+
"navigation",
|
|
48
|
+
"ssr",
|
|
49
|
+
"react",
|
|
50
|
+
"vue",
|
|
51
|
+
"svelte",
|
|
52
|
+
"solid",
|
|
53
|
+
"preact"
|
|
54
|
+
],
|
|
55
|
+
"author": "Flight Framework",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "https://github.com/EliosLT/Flight-framework",
|
|
60
|
+
"directory": "packages/router"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/react": "^19.0.0",
|
|
64
|
+
"@types/react-dom": "^19.0.0",
|
|
65
|
+
"preact": "^10.19.0",
|
|
66
|
+
"solid-js": "^1.8.0",
|
|
67
|
+
"tsup": "^8.0.0",
|
|
68
|
+
"typescript": "^5.3.0",
|
|
69
|
+
"vue": "^3.4.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"preact": ">=10.0.0",
|
|
73
|
+
"react": ">=18.0.0",
|
|
74
|
+
"solid-js": ">=1.0.0",
|
|
75
|
+
"svelte": ">=4.0.0",
|
|
76
|
+
"vue": ">=3.0.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"react": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"vue": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"svelte": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"solid-js": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"preact": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
95
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-2026 Flight Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|