valyrian.js 7.1.1 → 7.1.2
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/dist/router/index.d.ts +2 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +18 -5
- package/dist/router/index.mjs +18 -5
- package/lib/router/index.ts +22 -6
- package/package.json +1 -1
package/dist/router/index.d.ts
CHANGED
|
@@ -28,8 +28,9 @@ interface RouterInterface {
|
|
|
28
28
|
path: string;
|
|
29
29
|
params: Record<string, string | number | any>;
|
|
30
30
|
matches: string[];
|
|
31
|
+
pathPrefix: string;
|
|
31
32
|
add(method: string, ...args: Middlewares): Router;
|
|
32
|
-
use(...args: string
|
|
33
|
+
use(...args: (string | Middleware | Router)[]): Router;
|
|
33
34
|
routes(): string[];
|
|
34
35
|
go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/router/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,aAAa,EACb,uBAAuB,EASxB,MAAM,aAAa,CAAC;AAErB,UAAU,OAAO;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,uBAAuB,KAAK,KAAK,CAAC;CAC1G;AAED,UAAU,UAAU;IAElB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GACpB,OAAO,CAAC,GAAG,GAAG,SAAS,GA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js");
|
|
|
28
28
|
function flat(array) {
|
|
29
29
|
return Array.isArray(array) ? array.flat(Infinity) : [array];
|
|
30
30
|
}
|
|
31
|
+
function getPathWithoutPrefix(path, prefix) {
|
|
32
|
+
return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), ""));
|
|
33
|
+
}
|
|
34
|
+
function getPathWithoutLastSlash(path) {
|
|
35
|
+
let pathWithoutLastSlash = path.replace(/\/$/, "");
|
|
36
|
+
if (pathWithoutLastSlash === "") {
|
|
37
|
+
pathWithoutLastSlash = "/";
|
|
38
|
+
}
|
|
39
|
+
return pathWithoutLastSlash;
|
|
40
|
+
}
|
|
31
41
|
var addPath = ({
|
|
32
42
|
router,
|
|
33
43
|
method,
|
|
@@ -71,7 +81,7 @@ function searchMiddlewares(router, path) {
|
|
|
71
81
|
}
|
|
72
82
|
matches.push(...match);
|
|
73
83
|
if (item.method === "add") {
|
|
74
|
-
router.path = item.path;
|
|
84
|
+
router.path = getPathWithoutPrefix(item.path, router.pathPrefix);
|
|
75
85
|
break;
|
|
76
86
|
}
|
|
77
87
|
}
|
|
@@ -117,11 +127,14 @@ var Router = class {
|
|
|
117
127
|
this.pathPrefix = pathPrefix;
|
|
118
128
|
}
|
|
119
129
|
add(path, ...middlewares) {
|
|
120
|
-
|
|
130
|
+
let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
131
|
+
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
121
132
|
return this;
|
|
122
133
|
}
|
|
123
134
|
use(...middlewares) {
|
|
124
|
-
let path =
|
|
135
|
+
let path = getPathWithoutLastSlash(
|
|
136
|
+
`${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
|
|
137
|
+
);
|
|
125
138
|
for (const item of middlewares) {
|
|
126
139
|
if (item instanceof Router) {
|
|
127
140
|
const subrouter = item;
|
|
@@ -148,7 +161,7 @@ var Router = class {
|
|
|
148
161
|
if (!path) {
|
|
149
162
|
throw new Error("router.url.required");
|
|
150
163
|
}
|
|
151
|
-
|
|
164
|
+
let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
152
165
|
const parts = constructedPath.split("?", 2);
|
|
153
166
|
this.url = constructedPath;
|
|
154
167
|
this.query = parseQuery(parts[1]);
|
|
@@ -197,7 +210,7 @@ function mountRouter(elementContainer, router) {
|
|
|
197
210
|
localRedirect = router.go.bind(router);
|
|
198
211
|
if (!import_valyrian.isNodeJs) {
|
|
199
212
|
let onPopStateGoToRoute = function() {
|
|
200
|
-
let pathWithoutPrefix = document.location.pathname
|
|
213
|
+
let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
201
214
|
router.go(pathWithoutPrefix, void 0, true);
|
|
202
215
|
};
|
|
203
216
|
window.addEventListener("popstate", onPopStateGoToRoute, false);
|
package/dist/router/index.mjs
CHANGED
|
@@ -11,6 +11,16 @@ import {
|
|
|
11
11
|
function flat(array) {
|
|
12
12
|
return Array.isArray(array) ? array.flat(Infinity) : [array];
|
|
13
13
|
}
|
|
14
|
+
function getPathWithoutPrefix(path, prefix) {
|
|
15
|
+
return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), ""));
|
|
16
|
+
}
|
|
17
|
+
function getPathWithoutLastSlash(path) {
|
|
18
|
+
let pathWithoutLastSlash = path.replace(/\/$/, "");
|
|
19
|
+
if (pathWithoutLastSlash === "") {
|
|
20
|
+
pathWithoutLastSlash = "/";
|
|
21
|
+
}
|
|
22
|
+
return pathWithoutLastSlash;
|
|
23
|
+
}
|
|
14
24
|
var addPath = ({
|
|
15
25
|
router,
|
|
16
26
|
method,
|
|
@@ -54,7 +64,7 @@ function searchMiddlewares(router, path) {
|
|
|
54
64
|
}
|
|
55
65
|
matches.push(...match);
|
|
56
66
|
if (item.method === "add") {
|
|
57
|
-
router.path = item.path;
|
|
67
|
+
router.path = getPathWithoutPrefix(item.path, router.pathPrefix);
|
|
58
68
|
break;
|
|
59
69
|
}
|
|
60
70
|
}
|
|
@@ -100,11 +110,14 @@ var Router = class {
|
|
|
100
110
|
this.pathPrefix = pathPrefix;
|
|
101
111
|
}
|
|
102
112
|
add(path, ...middlewares) {
|
|
103
|
-
|
|
113
|
+
let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
114
|
+
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
104
115
|
return this;
|
|
105
116
|
}
|
|
106
117
|
use(...middlewares) {
|
|
107
|
-
let path =
|
|
118
|
+
let path = getPathWithoutLastSlash(
|
|
119
|
+
`${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
|
|
120
|
+
);
|
|
108
121
|
for (const item of middlewares) {
|
|
109
122
|
if (item instanceof Router) {
|
|
110
123
|
const subrouter = item;
|
|
@@ -131,7 +144,7 @@ var Router = class {
|
|
|
131
144
|
if (!path) {
|
|
132
145
|
throw new Error("router.url.required");
|
|
133
146
|
}
|
|
134
|
-
|
|
147
|
+
let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
135
148
|
const parts = constructedPath.split("?", 2);
|
|
136
149
|
this.url = constructedPath;
|
|
137
150
|
this.query = parseQuery(parts[1]);
|
|
@@ -180,7 +193,7 @@ function mountRouter(elementContainer, router) {
|
|
|
180
193
|
localRedirect = router.go.bind(router);
|
|
181
194
|
if (!isNodeJs) {
|
|
182
195
|
let onPopStateGoToRoute = function() {
|
|
183
|
-
let pathWithoutPrefix = document.location.pathname
|
|
196
|
+
let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
184
197
|
router.go(pathWithoutPrefix, void 0, true);
|
|
185
198
|
};
|
|
186
199
|
window.addEventListener("popstate", onPopStateGoToRoute, false);
|
package/lib/router/index.ts
CHANGED
|
@@ -52,10 +52,11 @@ interface RouterInterface {
|
|
|
52
52
|
path: string;
|
|
53
53
|
params: Record<string, string | number | any>;
|
|
54
54
|
matches: string[];
|
|
55
|
+
pathPrefix: string;
|
|
55
56
|
// eslint-disable-next-line no-unused-vars
|
|
56
57
|
add(method: string, ...args: Middlewares): Router;
|
|
57
58
|
// eslint-disable-next-line no-unused-vars
|
|
58
|
-
use(...args: string
|
|
59
|
+
use(...args: (string | Middleware | Router)[]): Router;
|
|
59
60
|
|
|
60
61
|
routes(): string[];
|
|
61
62
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -71,6 +72,18 @@ function flat(array: any) {
|
|
|
71
72
|
return Array.isArray(array) ? array.flat(Infinity) : [array];
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
function getPathWithoutPrefix(path: string, prefix: string) {
|
|
76
|
+
return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), ""));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getPathWithoutLastSlash(path: string) {
|
|
80
|
+
let pathWithoutLastSlash = path.replace(/\/$/, "");
|
|
81
|
+
if (pathWithoutLastSlash === "") {
|
|
82
|
+
pathWithoutLastSlash = "/";
|
|
83
|
+
}
|
|
84
|
+
return pathWithoutLastSlash;
|
|
85
|
+
}
|
|
86
|
+
|
|
74
87
|
const addPath = ({
|
|
75
88
|
router,
|
|
76
89
|
method,
|
|
@@ -145,7 +158,7 @@ function searchMiddlewares(router: RouterInterface, path: string): Middlewares {
|
|
|
145
158
|
matches.push(...match);
|
|
146
159
|
|
|
147
160
|
if (item.method === "add") {
|
|
148
|
-
router.path = item.path;
|
|
161
|
+
router.path = getPathWithoutPrefix(item.path, router.pathPrefix);
|
|
149
162
|
break;
|
|
150
163
|
}
|
|
151
164
|
}
|
|
@@ -211,12 +224,15 @@ export class Router implements RouterInterface {
|
|
|
211
224
|
}
|
|
212
225
|
|
|
213
226
|
add(path: string, ...middlewares: Middlewares): Router {
|
|
214
|
-
|
|
227
|
+
let pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
228
|
+
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
215
229
|
return this;
|
|
216
230
|
}
|
|
217
231
|
|
|
218
232
|
use(...middlewares: Middlewares | Router[] | string[]): Router {
|
|
219
|
-
let path =
|
|
233
|
+
let path = getPathWithoutLastSlash(
|
|
234
|
+
`${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
|
|
235
|
+
);
|
|
220
236
|
|
|
221
237
|
for (const item of middlewares) {
|
|
222
238
|
if (item instanceof Router) {
|
|
@@ -249,7 +265,7 @@ export class Router implements RouterInterface {
|
|
|
249
265
|
throw new Error("router.url.required");
|
|
250
266
|
}
|
|
251
267
|
|
|
252
|
-
|
|
268
|
+
let constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
253
269
|
const parts = constructedPath.split("?", 2);
|
|
254
270
|
this.url = constructedPath;
|
|
255
271
|
this.query = parseQuery(parts[1]);
|
|
@@ -309,7 +325,7 @@ export function mountRouter(elementContainer: string | any, router: Router): voi
|
|
|
309
325
|
|
|
310
326
|
if (!isNodeJs) {
|
|
311
327
|
function onPopStateGoToRoute(): void {
|
|
312
|
-
let pathWithoutPrefix = document.location.pathname
|
|
328
|
+
let pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
313
329
|
(router as unknown as Router).go(pathWithoutPrefix, undefined, true);
|
|
314
330
|
}
|
|
315
331
|
window.addEventListener("popstate", onPopStateGoToRoute, false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valyrian.js",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.2",
|
|
4
4
|
"description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
|
|
5
5
|
"repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
|
|
6
6
|
"author": "Masquerade <christian@masquerade-circus.net>",
|