crelte 0.1.3 → 0.2.1
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/CrelteRequest.d.ts +11 -6
- package/dist/CrelteRequest.d.ts.map +1 -1
- package/dist/CrelteRequest.js +14 -14
- package/dist/graphql/GraphQl.d.ts +1 -1
- package/dist/graphql/GraphQl.d.ts.map +1 -1
- package/dist/graphql/GraphQl.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +11 -5
- package/dist/init/server.d.ts +2 -0
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +24 -10
- package/dist/init/shared.d.ts +3 -3
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +1 -1
- package/dist/loadData/index.d.ts +11 -5
- package/dist/loadData/index.d.ts.map +1 -1
- package/dist/loadData/index.js +15 -6
- package/dist/routing/History.d.ts +5 -3
- package/dist/routing/History.d.ts.map +1 -1
- package/dist/routing/History.js +9 -4
- package/dist/routing/InnerRouter.d.ts +31 -21
- package/dist/routing/InnerRouter.d.ts.map +1 -1
- package/dist/routing/InnerRouter.js +98 -76
- package/dist/routing/PageLoader.d.ts +4 -5
- package/dist/routing/PageLoader.d.ts.map +1 -1
- package/dist/routing/PageLoader.js +5 -5
- package/dist/routing/Request.d.ts +15 -2
- package/dist/routing/Request.d.ts.map +1 -1
- package/dist/routing/Request.js +22 -1
- package/dist/routing/Route.d.ts +61 -25
- package/dist/routing/Route.d.ts.map +1 -1
- package/dist/routing/Route.js +90 -41
- package/dist/routing/Router.d.ts +34 -13
- package/dist/routing/Router.d.ts.map +1 -1
- package/dist/routing/Router.js +102 -49
- package/package.json +3 -2
- package/src/CrelteRequest.ts +14 -19
- package/src/graphql/GraphQl.ts +5 -2
- package/src/index.ts +26 -3
- package/src/init/client.ts +14 -10
- package/src/init/server.ts +31 -11
- package/src/init/shared.ts +4 -4
- package/src/loadData/index.ts +47 -15
- package/src/routing/History.ts +12 -5
- package/src/routing/InnerRouter.ts +109 -82
- package/src/routing/PageLoader.ts +7 -17
- package/src/routing/Request.ts +28 -6
- package/src/routing/Route.ts +115 -52
- package/src/routing/Router.ts +123 -59
- package/LICENSE.md +0 -41
package/dist/routing/Route.d.ts
CHANGED
|
@@ -10,17 +10,18 @@ export type RouteOptions = {
|
|
|
10
10
|
*
|
|
11
11
|
* - `'init'`: is set on the first page load
|
|
12
12
|
* - `'manual'`: is set when a route is triggered manually via `Router.open`
|
|
13
|
-
* - `'live-preview-init'`: is set on the first page load in live preview mode
|
|
14
13
|
* - `'click'`: is set when a route is triggered by a click event
|
|
15
14
|
* - `'pop'`: is set when a route is triggered by a popstate event (back/forward)
|
|
15
|
+
* - `'replace'`: is set when a route is replaced via `Router.replaceState`
|
|
16
|
+
* - `'push'`: is set when a route is pushed via `Router.pushState`
|
|
17
|
+
*
|
|
18
|
+
* ## Note
|
|
19
|
+
* `replace` and `push` will not call loadData
|
|
16
20
|
*/
|
|
17
|
-
export type RouteOrigin = 'init' | '
|
|
21
|
+
export type RouteOrigin = 'init' | 'manual' | 'click' | 'pop' | 'replace' | 'push';
|
|
18
22
|
/**
|
|
19
23
|
* A Route contains information about the current page for example the url and
|
|
20
|
-
* the site
|
|
21
|
-
*
|
|
22
|
-
* ## Note
|
|
23
|
-
* Never update the route directly, clone it before
|
|
24
|
+
* the site
|
|
24
25
|
*/
|
|
25
26
|
export default class Route {
|
|
26
27
|
/**
|
|
@@ -28,11 +29,25 @@ export default class Route {
|
|
|
28
29
|
*/
|
|
29
30
|
url: URL;
|
|
30
31
|
/**
|
|
31
|
-
* The site of the route
|
|
32
|
+
* The site of the route
|
|
33
|
+
*
|
|
34
|
+
* ## Note
|
|
35
|
+
* The site might not always match with the current route
|
|
36
|
+
* but be the site default site or one that matches the
|
|
37
|
+
* users language.
|
|
38
|
+
*
|
|
39
|
+
* If that is important call `route.siteMatches()` to verify
|
|
32
40
|
*/
|
|
33
|
-
site: Site
|
|
41
|
+
site: Site;
|
|
34
42
|
/**
|
|
35
43
|
* The scroll position of the current route
|
|
44
|
+
*
|
|
45
|
+
* ## Note
|
|
46
|
+
* This does not have to represent the current scroll position
|
|
47
|
+
* should more be used internally.
|
|
48
|
+
*
|
|
49
|
+
* It might be useful for a new request to specify the wanted
|
|
50
|
+
* scroll position
|
|
36
51
|
*/
|
|
37
52
|
scrollY: number | null;
|
|
38
53
|
/**
|
|
@@ -47,7 +62,7 @@ export default class Route {
|
|
|
47
62
|
/**
|
|
48
63
|
* Creates a new Route
|
|
49
64
|
*/
|
|
50
|
-
constructor(url: string | URL, site: Site
|
|
65
|
+
constructor(url: string | URL, site: Site, opts?: RouteOptions);
|
|
51
66
|
/**
|
|
52
67
|
* Returns the uri of the route
|
|
53
68
|
*
|
|
@@ -55,12 +70,13 @@ export default class Route {
|
|
|
55
70
|
*
|
|
56
71
|
* ## Example
|
|
57
72
|
* ```
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
73
|
+
* const site = _; // site with url https://example.com/fo
|
|
74
|
+
* const route = new Route('https://example.com/foo/bar/', site);
|
|
75
|
+
* console.log(route.uri); // '/bar'
|
|
60
76
|
*
|
|
61
|
-
* const
|
|
62
|
-
* const route2 = new Route('https://example.com/foo/bar/?a=1',
|
|
63
|
-
* console.log(route2.uri); // '/bar'
|
|
77
|
+
* const site2 = _; // site with url https://example.com/other
|
|
78
|
+
* const route2 = new Route('https://example.com/foo/bar/?a=1', site2);
|
|
79
|
+
* console.log(route2.uri); // '/foo/bar'
|
|
64
80
|
* ```
|
|
65
81
|
*/
|
|
66
82
|
get uri(): string;
|
|
@@ -71,12 +87,13 @@ export default class Route {
|
|
|
71
87
|
*
|
|
72
88
|
* ## Example
|
|
73
89
|
* ```
|
|
90
|
+
* const site = _; // site with url https://example.com/foo
|
|
74
91
|
* const route = new Route('https://example.com/foo/bar/', null);
|
|
75
|
-
* console.log(route.baseUrl); // 'https://example.com'
|
|
92
|
+
* console.log(route.baseUrl); // 'https://example.com/foo'
|
|
76
93
|
*
|
|
77
|
-
* const
|
|
78
|
-
* const route2 = new Route('https://example.com/foo/bar/',
|
|
79
|
-
* console.log(route2.baseUrl); // 'https://example.com
|
|
94
|
+
* const site2 = _; // site with url https://example.com/other
|
|
95
|
+
* const route2 = new Route('https://example.com/foo/bar/', site2);
|
|
96
|
+
* console.log(route2.baseUrl); // 'https://example.com'
|
|
80
97
|
* ```
|
|
81
98
|
*/
|
|
82
99
|
get baseUrl(): string;
|
|
@@ -103,13 +120,6 @@ export default class Route {
|
|
|
103
120
|
* ```
|
|
104
121
|
*/
|
|
105
122
|
get hash(): string;
|
|
106
|
-
/**
|
|
107
|
-
* Checks if the route is equal to another route
|
|
108
|
-
*
|
|
109
|
-
* This checks all properties of the url but search params do not have to be
|
|
110
|
-
* in the same order
|
|
111
|
-
*/
|
|
112
|
-
eq(route: Route): boolean;
|
|
113
123
|
/**
|
|
114
124
|
* Checks if there are previous routes which would allow it to go back
|
|
115
125
|
*/
|
|
@@ -138,6 +148,32 @@ export default class Route {
|
|
|
138
148
|
* ```
|
|
139
149
|
*/
|
|
140
150
|
setSearchParam(key: string, value?: string | number | null): void;
|
|
151
|
+
inLivePreview(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Returns if the site matches the url
|
|
154
|
+
*/
|
|
155
|
+
siteMatches(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if the route is equal to another route
|
|
158
|
+
*
|
|
159
|
+
* This checks all properties of the url but search params do not have to be
|
|
160
|
+
* in the same order
|
|
161
|
+
*/
|
|
162
|
+
eq(route: Route | null): boolean | null;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if the route is equal to another route
|
|
165
|
+
*
|
|
166
|
+
* This does not check the search params or hash
|
|
167
|
+
*/
|
|
168
|
+
eqUrl(route: Route | null): boolean | null;
|
|
169
|
+
/**
|
|
170
|
+
* Checks if the search params are equal to another route
|
|
171
|
+
*/
|
|
172
|
+
eqSearch(route: Route | null): boolean | null;
|
|
173
|
+
/**
|
|
174
|
+
* Checks if the hash is equal to another route
|
|
175
|
+
*/
|
|
176
|
+
eqHash(route: Route | null): boolean | null;
|
|
141
177
|
/**
|
|
142
178
|
* Create a copy of the request
|
|
143
179
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../../../src/routing/Route.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../../../src/routing/Route.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,WAAW,GACpB,MAAM,GACN,QAAQ,GACR,OAAO,GACP,KAAK,GACL,SAAS,GACT,MAAM,CAAC;AAEV;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IACzB;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;;;;;;OASG;IACH,IAAI,EAAE,IAAI,CAAC;IAEX;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;gBACS,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE,YAAiB;IASlE;;;;;;;;;;;;;;;OAeG;IACH,IAAI,GAAG,IAAI,MAAM,CAQhB;IAED;;;;;;;;;;;;;;;OAeG;IACH,IAAI,OAAO,IAAI,MAAM,CAIpB;IAED;;;;;;;;;;;OAWG;IACH,IAAI,MAAM,IAAI,eAAe,CAE5B;IAED;;;;;;;;OAQG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;;;;;;;OAQG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI1C;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQ1D,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,WAAW,IAAI,OAAO;IAatB;;;;;OAKG;IACH,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAStB;;;;OAIG;IACH,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAQzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAkB5B;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAI1B;;OAEG;IACH,KAAK;IAQL,cAAc;IACd,cAAc,CAAC,KAAK,EAAE,GAAG;IAQzB,cAAc;IACd,QAAQ,IAAI,GAAG;CAQf"}
|
package/dist/routing/Route.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { trimSlashEnd } from './utils.js';
|
|
2
2
|
/**
|
|
3
3
|
* A Route contains information about the current page for example the url and
|
|
4
|
-
* the site
|
|
5
|
-
*
|
|
6
|
-
* ## Note
|
|
7
|
-
* Never update the route directly, clone it before
|
|
4
|
+
* the site
|
|
8
5
|
*/
|
|
9
6
|
export default class Route {
|
|
10
7
|
/**
|
|
@@ -12,11 +9,25 @@ export default class Route {
|
|
|
12
9
|
*/
|
|
13
10
|
url;
|
|
14
11
|
/**
|
|
15
|
-
* The site of the route
|
|
12
|
+
* The site of the route
|
|
13
|
+
*
|
|
14
|
+
* ## Note
|
|
15
|
+
* The site might not always match with the current route
|
|
16
|
+
* but be the site default site or one that matches the
|
|
17
|
+
* users language.
|
|
18
|
+
*
|
|
19
|
+
* If that is important call `route.siteMatches()` to verify
|
|
16
20
|
*/
|
|
17
21
|
site;
|
|
18
22
|
/**
|
|
19
23
|
* The scroll position of the current route
|
|
24
|
+
*
|
|
25
|
+
* ## Note
|
|
26
|
+
* This does not have to represent the current scroll position
|
|
27
|
+
* should more be used internally.
|
|
28
|
+
*
|
|
29
|
+
* It might be useful for a new request to specify the wanted
|
|
30
|
+
* scroll position
|
|
20
31
|
*/
|
|
21
32
|
scrollY;
|
|
22
33
|
/**
|
|
@@ -45,17 +56,17 @@ export default class Route {
|
|
|
45
56
|
*
|
|
46
57
|
* ## Example
|
|
47
58
|
* ```
|
|
48
|
-
* const
|
|
49
|
-
*
|
|
59
|
+
* const site = _; // site with url https://example.com/fo
|
|
60
|
+
* const route = new Route('https://example.com/foo/bar/', site);
|
|
61
|
+
* console.log(route.uri); // '/bar'
|
|
50
62
|
*
|
|
51
|
-
* const
|
|
52
|
-
* const route2 = new Route('https://example.com/foo/bar/?a=1',
|
|
53
|
-
* console.log(route2.uri); // '/bar'
|
|
63
|
+
* const site2 = _; // site with url https://example.com/other
|
|
64
|
+
* const route2 = new Route('https://example.com/foo/bar/?a=1', site2);
|
|
65
|
+
* console.log(route2.uri); // '/foo/bar'
|
|
54
66
|
* ```
|
|
55
67
|
*/
|
|
56
68
|
get uri() {
|
|
57
|
-
|
|
58
|
-
if (this.site) {
|
|
69
|
+
if (this.siteMatches()) {
|
|
59
70
|
return trimSlashEnd(this.url.pathname.substring(this.site.uri.length));
|
|
60
71
|
}
|
|
61
72
|
return trimSlashEnd(this.url.pathname);
|
|
@@ -67,16 +78,17 @@ export default class Route {
|
|
|
67
78
|
*
|
|
68
79
|
* ## Example
|
|
69
80
|
* ```
|
|
81
|
+
* const site = _; // site with url https://example.com/foo
|
|
70
82
|
* const route = new Route('https://example.com/foo/bar/', null);
|
|
71
|
-
* console.log(route.baseUrl); // 'https://example.com'
|
|
83
|
+
* console.log(route.baseUrl); // 'https://example.com/foo'
|
|
72
84
|
*
|
|
73
|
-
* const
|
|
74
|
-
* const route2 = new Route('https://example.com/foo/bar/',
|
|
75
|
-
* console.log(route2.baseUrl); // 'https://example.com
|
|
85
|
+
* const site2 = _; // site with url https://example.com/other
|
|
86
|
+
* const route2 = new Route('https://example.com/foo/bar/', site2);
|
|
87
|
+
* console.log(route2.baseUrl); // 'https://example.com'
|
|
76
88
|
* ```
|
|
77
89
|
*/
|
|
78
90
|
get baseUrl() {
|
|
79
|
-
if (this.
|
|
91
|
+
if (this.siteMatches())
|
|
80
92
|
return trimSlashEnd(this.site.url.href);
|
|
81
93
|
return this.url.origin;
|
|
82
94
|
}
|
|
@@ -107,30 +119,6 @@ export default class Route {
|
|
|
107
119
|
get hash() {
|
|
108
120
|
return this.url.hash;
|
|
109
121
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Checks if the route is equal to another route
|
|
112
|
-
*
|
|
113
|
-
* This checks all properties of the url but search params do not have to be
|
|
114
|
-
* in the same order
|
|
115
|
-
*/
|
|
116
|
-
eq(route) {
|
|
117
|
-
const searchEq = (a, b) => {
|
|
118
|
-
if (a.size !== b.size)
|
|
119
|
-
return false;
|
|
120
|
-
a.sort();
|
|
121
|
-
b.sort();
|
|
122
|
-
const aEntries = Array.from(a.entries());
|
|
123
|
-
const bEntries = Array.from(b.entries());
|
|
124
|
-
return aEntries
|
|
125
|
-
.map((a, i) => [a, bEntries[i]])
|
|
126
|
-
.every(([[ak, av], [bk, bv]]) => ak === bk && av === bv);
|
|
127
|
-
};
|
|
128
|
-
return (route &&
|
|
129
|
-
this.url.pathname === route.url.pathname &&
|
|
130
|
-
this.url.origin === route.url.origin &&
|
|
131
|
-
searchEq(this.search, route.search) &&
|
|
132
|
-
this.hash === route.hash);
|
|
133
|
-
}
|
|
134
122
|
/**
|
|
135
123
|
* Checks if there are previous routes which would allow it to go back
|
|
136
124
|
*/
|
|
@@ -170,6 +158,67 @@ export default class Route {
|
|
|
170
158
|
this.search.delete(key);
|
|
171
159
|
}
|
|
172
160
|
}
|
|
161
|
+
inLivePreview() {
|
|
162
|
+
return !!this.search.get('x-craft-live-preview');
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Returns if the site matches the url
|
|
166
|
+
*/
|
|
167
|
+
siteMatches() {
|
|
168
|
+
if (this.url.origin !== this.site.url.origin)
|
|
169
|
+
return false;
|
|
170
|
+
// now we need to validate the pathname we should make sure both end with a slash
|
|
171
|
+
// todo can we do this better?
|
|
172
|
+
// make sure that urls like pathname: /abcbc and site: /abc don't match
|
|
173
|
+
return (this.url.pathname + '/').startsWith(
|
|
174
|
+
// uri never returns a slash at the end
|
|
175
|
+
this.site.uri + '/');
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the route is equal to another route
|
|
179
|
+
*
|
|
180
|
+
* This checks all properties of the url but search params do not have to be
|
|
181
|
+
* in the same order
|
|
182
|
+
*/
|
|
183
|
+
eq(route) {
|
|
184
|
+
return (route &&
|
|
185
|
+
this.eqUrl(route) &&
|
|
186
|
+
this.eqSearch(route) &&
|
|
187
|
+
this.eqHash(route));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks if the route is equal to another route
|
|
191
|
+
*
|
|
192
|
+
* This does not check the search params or hash
|
|
193
|
+
*/
|
|
194
|
+
eqUrl(route) {
|
|
195
|
+
return (route &&
|
|
196
|
+
this.url.pathname === route.url.pathname &&
|
|
197
|
+
this.url.origin === route.url.origin);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Checks if the search params are equal to another route
|
|
201
|
+
*/
|
|
202
|
+
eqSearch(route) {
|
|
203
|
+
const searchEq = (a, b) => {
|
|
204
|
+
if (a.size !== b.size)
|
|
205
|
+
return false;
|
|
206
|
+
a.sort();
|
|
207
|
+
b.sort();
|
|
208
|
+
const aEntries = Array.from(a.entries());
|
|
209
|
+
const bEntries = Array.from(b.entries());
|
|
210
|
+
return aEntries
|
|
211
|
+
.map((a, i) => [a, bEntries[i]])
|
|
212
|
+
.every(([[ak, av], [bk, bv]]) => ak === bk && av === bv);
|
|
213
|
+
};
|
|
214
|
+
return route && searchEq(this.search, route.search);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Checks if the hash is equal to another route
|
|
218
|
+
*/
|
|
219
|
+
eqHash(route) {
|
|
220
|
+
return route && this.hash === route.hash;
|
|
221
|
+
}
|
|
173
222
|
/**
|
|
174
223
|
* Create a copy of the request
|
|
175
224
|
*/
|
package/dist/routing/Router.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Route from './Route.js';
|
|
|
2
2
|
import Site, { SiteFromGraphQl } from './Site.js';
|
|
3
3
|
import { LoadFn } from './PageLoader.js';
|
|
4
4
|
import { Readable } from 'crelte-std/stores';
|
|
5
|
-
import Request from './Request.js';
|
|
5
|
+
import Request, { RequestOptions } from './Request.js';
|
|
6
6
|
export type RouterOptions = {
|
|
7
7
|
preloadOnMouseOver?: boolean;
|
|
8
8
|
debugTiming?: boolean;
|
|
@@ -11,7 +11,8 @@ export type RouterOptions = {
|
|
|
11
11
|
* internal only
|
|
12
12
|
*/
|
|
13
13
|
type Internal = {
|
|
14
|
-
onLoaded: (success: boolean, req: Request,
|
|
14
|
+
onLoaded: (success: boolean, req: Request, ready: () => any) => void;
|
|
15
|
+
onNothingLoaded: (req: Request, ready: () => void) => void;
|
|
15
16
|
onLoad: LoadFn;
|
|
16
17
|
domReady: (req: Request) => void;
|
|
17
18
|
initClient: () => void;
|
|
@@ -21,7 +22,6 @@ type ServerInited = {
|
|
|
21
22
|
success: boolean;
|
|
22
23
|
redirect: boolean;
|
|
23
24
|
req: Request;
|
|
24
|
-
site: Site;
|
|
25
25
|
props: any;
|
|
26
26
|
};
|
|
27
27
|
export default class Router {
|
|
@@ -43,7 +43,6 @@ export default class Router {
|
|
|
43
43
|
* The loading progress, the value is between 0 and 1
|
|
44
44
|
*/
|
|
45
45
|
private _loadingProgress;
|
|
46
|
-
private _onRouteEv;
|
|
47
46
|
private _onRequest;
|
|
48
47
|
/** @hidden */
|
|
49
48
|
_internal: Internal;
|
|
@@ -73,10 +72,13 @@ export default class Router {
|
|
|
73
72
|
/**
|
|
74
73
|
* Open a new route
|
|
75
74
|
*
|
|
76
|
-
* @param target the target to open can be an url or a
|
|
75
|
+
* @param target the target to open can be an url, a route or a request
|
|
77
76
|
* the url needs to start with http or with a / which will be considered as
|
|
78
77
|
* the site baseUrl
|
|
79
78
|
*
|
|
79
|
+
* ## Note
|
|
80
|
+
* The origin will always be set to 'manual'
|
|
81
|
+
*
|
|
80
82
|
* ## Example
|
|
81
83
|
* ```
|
|
82
84
|
* import { getRouter } from 'crelte';
|
|
@@ -88,13 +90,18 @@ export default class Router {
|
|
|
88
90
|
* // the following page will be opened https://example.com/de/foo/bar
|
|
89
91
|
* ```
|
|
90
92
|
*/
|
|
91
|
-
open(target: string | URL | Route): void;
|
|
93
|
+
open(target: string | URL | Route | Request, opts?: RequestOptions): void;
|
|
92
94
|
/**
|
|
93
|
-
* This pushes the
|
|
95
|
+
* This pushes the new route without triggering a new pageload
|
|
94
96
|
*
|
|
95
97
|
* You can use this when using pagination for example change the route object
|
|
96
98
|
* (search argument) and then call pushState
|
|
97
99
|
*
|
|
100
|
+
* ## Note
|
|
101
|
+
* This will always set the origin to 'push'
|
|
102
|
+
* And will clear the scrollY value if you not provide a new one via the `opts`
|
|
103
|
+
* This will disableLoadData by default if you not provide an override via the `opts`
|
|
104
|
+
*
|
|
98
105
|
* ## Example
|
|
99
106
|
* ```
|
|
100
107
|
* import { getRouter } from 'crelte';
|
|
@@ -107,12 +114,21 @@ export default class Router {
|
|
|
107
114
|
* router.pushState(route);
|
|
108
115
|
* ```
|
|
109
116
|
*/
|
|
110
|
-
|
|
117
|
+
push(route: Route | Request, opts?: RequestOptions): void;
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated use push instead
|
|
120
|
+
*/
|
|
121
|
+
pushState(route: Route | Request): void;
|
|
111
122
|
/**
|
|
112
123
|
* This replaces the state of the route without triggering an event
|
|
113
124
|
*
|
|
114
125
|
* You can use this when using some filters for example a search filter
|
|
115
126
|
*
|
|
127
|
+
* ## Note
|
|
128
|
+
* This will always set the origin to 'replace'
|
|
129
|
+
* And will clear the scrollY value if you not provide a new one via the `opts`
|
|
130
|
+
* This will disableLoadData by default if you not provide an override via the `opts`
|
|
131
|
+
*
|
|
116
132
|
* ## Example
|
|
117
133
|
* ```
|
|
118
134
|
* import { getRouter } from 'crelte';
|
|
@@ -125,7 +141,11 @@ export default class Router {
|
|
|
125
141
|
* router.replaceState(route);
|
|
126
142
|
* ```
|
|
127
143
|
*/
|
|
128
|
-
|
|
144
|
+
replace(route: Route | Request, opts?: RequestOptions): void;
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated use replace instead
|
|
147
|
+
*/
|
|
148
|
+
replaceState(route: Route | Request): void;
|
|
129
149
|
/**
|
|
130
150
|
* Checks if there are previous routes which would allow it to go back
|
|
131
151
|
*/
|
|
@@ -141,12 +161,12 @@ export default class Router {
|
|
|
141
161
|
/**
|
|
142
162
|
* Add a listener for the onRoute event
|
|
143
163
|
*
|
|
144
|
-
* This
|
|
145
|
-
*
|
|
164
|
+
* This will trigger every time a new route is set
|
|
165
|
+
* and is equivalent to router.route.subscribe(fn)
|
|
146
166
|
*
|
|
147
167
|
* @returns a function to remove the listener
|
|
148
168
|
*/
|
|
149
|
-
onRoute(fn: (route: Route
|
|
169
|
+
onRoute(fn: (route: Route) => void): () => void;
|
|
150
170
|
/**
|
|
151
171
|
* Add a listener for the onRequest event
|
|
152
172
|
*
|
|
@@ -154,7 +174,7 @@ export default class Router {
|
|
|
154
174
|
*
|
|
155
175
|
* @returns a function to remove the listener
|
|
156
176
|
*/
|
|
157
|
-
onRequest(fn: (req: Request
|
|
177
|
+
onRequest(fn: (req: Request) => void): () => void;
|
|
158
178
|
private setNewRoute;
|
|
159
179
|
private _initClient;
|
|
160
180
|
private _initServer;
|
|
@@ -162,6 +182,7 @@ export default class Router {
|
|
|
162
182
|
private destroyRequest;
|
|
163
183
|
private _onPreload;
|
|
164
184
|
private _onLoaded;
|
|
185
|
+
private _onNothingLoaded;
|
|
165
186
|
private _onProgress;
|
|
166
187
|
}
|
|
167
188
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../../src/routing/Router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAElD,OAAmB,EAAE,MAAM,EAAgB,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAY,MAAM,mBAAmB,CAAC;AAEvD,OAAO,OAAO,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../../../src/routing/Router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAElD,OAAmB,EAAE,MAAM,EAAgB,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,QAAQ,EAAY,MAAM,mBAAmB,CAAC;AAEvD,OAAO,OAAO,EAAE,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAWF;;GAEG;AACH,KAAK,QAAQ,GAAG;I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