crelte 0.1.1 → 0.1.3
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/Crelte.d.ts +89 -25
- package/dist/Crelte.d.ts.map +1 -1
- package/dist/Crelte.js +79 -38
- package/dist/CrelteRequest.d.ts +63 -0
- package/dist/CrelteRequest.d.ts.map +1 -0
- package/dist/CrelteRequest.js +94 -0
- package/dist/blocks/Blocks.d.ts +27 -3
- package/dist/blocks/Blocks.d.ts.map +1 -1
- package/dist/blocks/Blocks.js +8 -0
- package/dist/blocks/Blocks.svelte +1 -1
- package/dist/blocks/Blocks.svelte.d.ts +36 -4
- package/dist/blocks/Blocks.svelte.d.ts.map +1 -1
- package/dist/blocks/index.d.ts +6 -3
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +3 -2
- package/dist/cookies/ServerCookies.d.ts +1 -1
- package/dist/cookies/ServerCookies.d.ts.map +1 -1
- package/dist/cookies/index.d.ts +7 -0
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/graphql/GraphQl.d.ts +53 -14
- package/dist/graphql/GraphQl.d.ts.map +1 -1
- package/dist/graphql/GraphQl.js +44 -23
- package/dist/graphql/index.d.ts +1 -1
- package/dist/graphql/index.d.ts.map +1 -1
- package/dist/graphql/index.js +2 -2
- package/dist/index.d.ts +55 -22
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -23
- package/dist/init/client.d.ts +43 -2
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +26 -6
- package/dist/init/server.d.ts +49 -2
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +56 -6
- package/dist/init/shared.d.ts +5 -4
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +3 -3
- package/dist/loadData/Globals.d.ts +41 -2
- package/dist/loadData/Globals.d.ts.map +1 -1
- package/dist/loadData/Globals.js +33 -5
- package/dist/loadData/index.d.ts +74 -11
- package/dist/loadData/index.d.ts.map +1 -1
- package/dist/loadData/index.js +5 -8
- package/dist/plugins/Events.d.ts +18 -5
- package/dist/plugins/Events.d.ts.map +1 -1
- package/dist/plugins/Events.js +3 -0
- package/dist/plugins/Plugins.d.ts +28 -2
- package/dist/plugins/Plugins.d.ts.map +1 -1
- package/dist/plugins/Plugins.js +8 -0
- package/dist/routing/History.d.ts +3 -0
- package/dist/routing/History.d.ts.map +1 -1
- package/dist/routing/History.js +6 -0
- package/dist/routing/InnerRouter.d.ts +10 -9
- package/dist/routing/InnerRouter.d.ts.map +1 -1
- package/dist/routing/InnerRouter.js +41 -33
- package/dist/routing/PageLoader.d.ts +5 -5
- package/dist/routing/PageLoader.d.ts.map +1 -1
- package/dist/routing/PageLoader.js +7 -7
- package/dist/routing/Request.d.ts +102 -0
- package/dist/routing/Request.d.ts.map +1 -0
- package/dist/routing/Request.js +128 -0
- package/dist/routing/Route.d.ts +73 -5
- package/dist/routing/Route.d.ts.map +1 -1
- package/dist/routing/Route.js +72 -7
- package/dist/routing/Router.d.ts +59 -53
- package/dist/routing/Router.d.ts.map +1 -1
- package/dist/routing/Router.js +92 -117
- package/dist/routing/Site.d.ts +1 -1
- package/dist/routing/Site.js +2 -2
- package/dist/routing/index.d.ts +4 -3
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +2 -1
- package/dist/routing/utils.d.ts +2 -0
- package/dist/routing/utils.d.ts.map +1 -0
- package/dist/routing/utils.js +3 -0
- package/dist/ssr/SsrCache.d.ts +17 -0
- package/dist/ssr/SsrCache.d.ts.map +1 -1
- package/dist/ssr/SsrCache.js +17 -4
- package/dist/ssr/SsrComponents.d.ts +1 -0
- package/dist/ssr/SsrComponents.d.ts.map +1 -1
- package/dist/ssr/SsrComponents.js +1 -0
- package/package.json +6 -6
- package/src/Crelte.ts +124 -52
- package/src/CrelteRequest.ts +124 -0
- package/src/blocks/Blocks.svelte +35 -18
- package/src/blocks/Blocks.ts +38 -6
- package/src/blocks/index.ts +19 -10
- package/src/cookies/ServerCookies.ts +1 -1
- package/src/cookies/index.ts +7 -1
- package/src/graphql/GraphQl.ts +79 -27
- package/src/graphql/index.ts +7 -1
- package/src/index.ts +65 -29
- package/src/init/client.ts +55 -10
- package/src/init/server.ts +70 -10
- package/src/init/shared.ts +8 -7
- package/src/loadData/Globals.ts +43 -7
- package/src/loadData/index.ts +76 -13
- package/src/plugins/Events.ts +16 -5
- package/src/plugins/Plugins.ts +28 -2
- package/src/routing/History.ts +9 -0
- package/src/routing/InnerRouter.ts +47 -37
- package/src/routing/PageLoader.ts +10 -10
- package/src/routing/Request.ts +175 -0
- package/src/routing/Route.ts +74 -9
- package/src/routing/Router.ts +103 -163
- package/src/routing/Site.ts +2 -2
- package/src/routing/index.ts +12 -3
- package/src/routing/utils.ts +3 -0
- package/src/ssr/SsrCache.ts +17 -4
- package/src/ssr/SsrComponents.ts +1 -0
- package/dist/CrelteBase.d.ts +0 -16
- package/dist/CrelteBase.d.ts.map +0 -1
- package/dist/CrelteBase.js +0 -1
- package/dist/CrelteRouted.d.ts +0 -50
- package/dist/CrelteRouted.d.ts.map +0 -1
- package/dist/CrelteRouted.js +0 -88
- package/src/CrelteBase.ts +0 -24
- package/src/CrelteRouted.ts +0 -128
package/dist/routing/Router.js
CHANGED
|
@@ -2,14 +2,12 @@ import Route from './Route.js';
|
|
|
2
2
|
import InnerRouter from './InnerRouter.js';
|
|
3
3
|
import PageLoader from './PageLoader.js';
|
|
4
4
|
import { Writable } from 'crelte-std/stores';
|
|
5
|
-
import {
|
|
5
|
+
import { Listeners } from 'crelte-std/sync';
|
|
6
|
+
import Request from './Request.js';
|
|
6
7
|
const defaultRouterOpts = {
|
|
7
8
|
preloadOnMouseOver: false,
|
|
8
9
|
deubgTiming: false,
|
|
9
10
|
};
|
|
10
|
-
export function trimSlashEnd(str) {
|
|
11
|
-
return str.endsWith('/') ? str.substring(0, str.length - 1) : str;
|
|
12
|
-
}
|
|
13
11
|
// Make sure route and nextRoute are not the same object as _inner.route
|
|
14
12
|
export default class Router {
|
|
15
13
|
/**
|
|
@@ -20,14 +18,8 @@ export default class Router {
|
|
|
20
18
|
* The current site
|
|
21
19
|
*/
|
|
22
20
|
_site;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
_nextRoute;
|
|
27
|
-
/**
|
|
28
|
-
* The next site which is currently being loaded
|
|
29
|
-
*/
|
|
30
|
-
_nextSite;
|
|
21
|
+
// the next request, just here to destroy it
|
|
22
|
+
_request;
|
|
31
23
|
/**
|
|
32
24
|
* The loading flag, specifies if a page is currently
|
|
33
25
|
* getting loaded
|
|
@@ -38,9 +30,8 @@ export default class Router {
|
|
|
38
30
|
*/
|
|
39
31
|
_loadingProgress;
|
|
40
32
|
_onRouteEv;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// doc hidden
|
|
33
|
+
_onRequest;
|
|
34
|
+
/** @hidden */
|
|
44
35
|
_internal;
|
|
45
36
|
inner;
|
|
46
37
|
pageLoader;
|
|
@@ -55,52 +46,36 @@ export default class Router {
|
|
|
55
46
|
// in the first onRoute call we will update this value
|
|
56
47
|
this._route = new Writable(null);
|
|
57
48
|
this._site = new Writable(null);
|
|
58
|
-
this.
|
|
59
|
-
this._nextSite = new Writable(null);
|
|
49
|
+
this._request = null;
|
|
60
50
|
this._loading = new Writable(false);
|
|
61
51
|
this._loadingProgress = new Writable(0);
|
|
62
52
|
this._onRouteEv = new Listeners();
|
|
63
|
-
this.
|
|
64
|
-
this._renderBarrier = null;
|
|
53
|
+
this._onRequest = new Listeners();
|
|
65
54
|
this._internal = {
|
|
66
55
|
onLoaded: () => { },
|
|
67
56
|
onLoad: () => { },
|
|
68
|
-
domReady:
|
|
57
|
+
domReady: req => this.inner.domReady(req),
|
|
69
58
|
initClient: () => this._initClient(),
|
|
70
59
|
initServer: (url, acceptLang) => this._initServer(url, acceptLang),
|
|
71
60
|
};
|
|
72
61
|
this.inner.onRoute = (route, site, changeHistory) => this._onRoute(route, site, changeHistory);
|
|
73
62
|
this.inner.onPreload = (route, site) => this._onPreload(route, site);
|
|
74
|
-
this.pageLoader.onLoaded = (resp,
|
|
75
|
-
this.pageLoader.loadFn = (
|
|
63
|
+
this.pageLoader.onLoaded = (resp, req, site, more) => this._onLoaded(resp, req, site, more);
|
|
64
|
+
this.pageLoader.loadFn = (req, site, opts) => this._internal.onLoad(req, site, opts);
|
|
76
65
|
this.pageLoader.onProgress = (loading, progress) => this._onProgress(loading, progress);
|
|
77
66
|
}
|
|
78
67
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* this is a svelte store
|
|
68
|
+
* returns a store with the current route
|
|
82
69
|
*/
|
|
83
70
|
get route() {
|
|
84
71
|
return this._route.readclone();
|
|
85
72
|
}
|
|
86
73
|
/**
|
|
87
|
-
*
|
|
74
|
+
* returns a store with the current site
|
|
88
75
|
*/
|
|
89
76
|
get site() {
|
|
90
77
|
return this._site.readonly();
|
|
91
78
|
}
|
|
92
|
-
/**
|
|
93
|
-
* The next route which is currently being loaded
|
|
94
|
-
*/
|
|
95
|
-
get nextRoute() {
|
|
96
|
-
return this._nextRoute.readclone();
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* The next site which is currently being loaded
|
|
100
|
-
*/
|
|
101
|
-
get nextSite() {
|
|
102
|
-
return this._nextSite.readonly();
|
|
103
|
-
}
|
|
104
79
|
/**
|
|
105
80
|
* The sites which are available
|
|
106
81
|
*/
|
|
@@ -108,14 +83,13 @@ export default class Router {
|
|
|
108
83
|
return this.inner.sites;
|
|
109
84
|
}
|
|
110
85
|
/**
|
|
111
|
-
*
|
|
112
|
-
* getting loaded
|
|
86
|
+
* returns a store which indicates if the a page is loading
|
|
113
87
|
*/
|
|
114
88
|
get loading() {
|
|
115
89
|
return this._loading.readonly();
|
|
116
90
|
}
|
|
117
91
|
/**
|
|
118
|
-
*
|
|
92
|
+
* returns a store which indicates the loading progress between 0 and 1
|
|
119
93
|
*/
|
|
120
94
|
get loadingProgress() {
|
|
121
95
|
return this._loadingProgress.readonly();
|
|
@@ -126,6 +100,17 @@ export default class Router {
|
|
|
126
100
|
* @param target the target to open can be an url or a route
|
|
127
101
|
* the url needs to start with http or with a / which will be considered as
|
|
128
102
|
* the site baseUrl
|
|
103
|
+
*
|
|
104
|
+
* ## Example
|
|
105
|
+
* ```
|
|
106
|
+
* import { getRouter } from 'crelte';
|
|
107
|
+
*
|
|
108
|
+
* const router = getRouter();
|
|
109
|
+
* console.log(router.site.get().url.href); // 'https://example.com/de';
|
|
110
|
+
*
|
|
111
|
+
* router.open('/foo/bar');
|
|
112
|
+
* // the following page will be opened https://example.com/de/foo/bar
|
|
113
|
+
* ```
|
|
129
114
|
*/
|
|
130
115
|
open(target) {
|
|
131
116
|
this.inner.open(target);
|
|
@@ -136,7 +121,17 @@ export default class Router {
|
|
|
136
121
|
* You can use this when using pagination for example change the route object
|
|
137
122
|
* (search argument) and then call pushState
|
|
138
123
|
*
|
|
139
|
-
*
|
|
124
|
+
* ## Example
|
|
125
|
+
* ```
|
|
126
|
+
* import { getRouter } from 'crelte';
|
|
127
|
+
*
|
|
128
|
+
* const router = getRouter();
|
|
129
|
+
*
|
|
130
|
+
* const page = 1;
|
|
131
|
+
* const route = router.route.get();
|
|
132
|
+
* route.setSearchParam('page', page > 0 ? page : null);
|
|
133
|
+
* router.pushState(route);
|
|
134
|
+
* ```
|
|
140
135
|
*/
|
|
141
136
|
pushState(route) {
|
|
142
137
|
this.pageLoader.discard();
|
|
@@ -146,7 +141,19 @@ export default class Router {
|
|
|
146
141
|
/**
|
|
147
142
|
* This replaces the state of the route without triggering an event
|
|
148
143
|
*
|
|
149
|
-
*
|
|
144
|
+
* You can use this when using some filters for example a search filter
|
|
145
|
+
*
|
|
146
|
+
* ## Example
|
|
147
|
+
* ```
|
|
148
|
+
* import { getRouter } from 'crelte';
|
|
149
|
+
*
|
|
150
|
+
* const router = getRouter();
|
|
151
|
+
*
|
|
152
|
+
* const search = 'foo';
|
|
153
|
+
* const route = router.route.get();
|
|
154
|
+
* route.setSearchParam('search', search ? search : null);
|
|
155
|
+
* router.replaceState(route);
|
|
156
|
+
* ```
|
|
150
157
|
*/
|
|
151
158
|
replaceState(route) {
|
|
152
159
|
this.pageLoader.discard();
|
|
@@ -163,7 +170,7 @@ export default class Router {
|
|
|
163
170
|
* Go back in the history
|
|
164
171
|
*/
|
|
165
172
|
back() {
|
|
166
|
-
|
|
173
|
+
this.inner.history.back();
|
|
167
174
|
}
|
|
168
175
|
/**
|
|
169
176
|
* Preload a url
|
|
@@ -176,26 +183,30 @@ export default class Router {
|
|
|
176
183
|
*
|
|
177
184
|
* This differs from router.route.subscribe in the way that
|
|
178
185
|
* it will only trigger if a new render / load will occur
|
|
186
|
+
*
|
|
187
|
+
* @returns a function to remove the listener
|
|
179
188
|
*/
|
|
180
189
|
onRoute(fn) {
|
|
181
190
|
return this._onRouteEv.add(fn);
|
|
182
191
|
}
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Add a listener for the onRequest event
|
|
194
|
+
*
|
|
195
|
+
* This will trigger every time a new route is requested
|
|
196
|
+
*
|
|
197
|
+
* @returns a function to remove the listener
|
|
198
|
+
*/
|
|
199
|
+
onRequest(fn) {
|
|
200
|
+
return this._onRequest.add(fn);
|
|
185
201
|
}
|
|
186
202
|
setNewRoute(route) {
|
|
203
|
+
this.destroyRequest();
|
|
187
204
|
this._route.setSilent(route);
|
|
188
|
-
|
|
189
|
-
if (route.site) {
|
|
205
|
+
if (route.site)
|
|
190
206
|
this._site.setSilent(route.site);
|
|
191
|
-
this._nextSite.setSilent(route.site);
|
|
192
|
-
}
|
|
193
|
-
this._nextRoute.notify();
|
|
194
207
|
this._route.notify();
|
|
195
|
-
if (route.site)
|
|
196
|
-
this._nextSite.notify();
|
|
208
|
+
if (route.site)
|
|
197
209
|
this._site.notify();
|
|
198
|
-
}
|
|
199
210
|
}
|
|
200
211
|
async _initClient() {
|
|
201
212
|
this.inner.initClient();
|
|
@@ -203,19 +214,19 @@ export default class Router {
|
|
|
203
214
|
async _initServer(url, acceptLang) {
|
|
204
215
|
this.inner.initServer();
|
|
205
216
|
const prom = new Promise(resolve => {
|
|
206
|
-
this._internal.onLoaded = (success,
|
|
217
|
+
this._internal.onLoaded = (success, req, site, ready) => {
|
|
207
218
|
const props = ready();
|
|
208
219
|
this._internal.onLoaded = () => { };
|
|
209
220
|
resolve({
|
|
210
221
|
success,
|
|
211
222
|
redirect: false,
|
|
212
|
-
|
|
223
|
+
req,
|
|
213
224
|
site,
|
|
214
225
|
props,
|
|
215
226
|
});
|
|
216
227
|
};
|
|
217
228
|
});
|
|
218
|
-
const route = this.inner.
|
|
229
|
+
const route = this.inner.targetToRequest(url);
|
|
219
230
|
route.origin = 'init';
|
|
220
231
|
// let's see if the url matches any route and site
|
|
221
232
|
// if not let's redirect to the site which matches the acceptLang
|
|
@@ -224,7 +235,7 @@ export default class Router {
|
|
|
224
235
|
return {
|
|
225
236
|
success: true,
|
|
226
237
|
redirect: true,
|
|
227
|
-
|
|
238
|
+
req: new Request(site.url, site),
|
|
228
239
|
site,
|
|
229
240
|
props: {},
|
|
230
241
|
};
|
|
@@ -238,7 +249,7 @@ export default class Router {
|
|
|
238
249
|
return {
|
|
239
250
|
success: true,
|
|
240
251
|
redirect: true,
|
|
241
|
-
|
|
252
|
+
req: Request.fromRoute(nRoute),
|
|
242
253
|
site: route.site,
|
|
243
254
|
props: {},
|
|
244
255
|
};
|
|
@@ -246,43 +257,35 @@ export default class Router {
|
|
|
246
257
|
}
|
|
247
258
|
return resp;
|
|
248
259
|
}
|
|
249
|
-
_onRoute(
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this._nextSite.notify();
|
|
256
|
-
if (this._renderBarrier) {
|
|
257
|
-
const barr = this._renderBarrier;
|
|
258
|
-
this._renderBarrier = null;
|
|
259
|
-
// make sure nobody waits forevery
|
|
260
|
-
barr.cancel();
|
|
260
|
+
_onRoute(req, site, changeHistory) {
|
|
261
|
+
this.destroyRequest();
|
|
262
|
+
this._request = req;
|
|
263
|
+
const barrier = req._renderBarrier;
|
|
264
|
+
if (barrier.isOpen()) {
|
|
265
|
+
throw new Error('render barrier is already open');
|
|
261
266
|
}
|
|
262
|
-
|
|
263
|
-
this._renderBarrier = barrier;
|
|
264
|
-
this._onNextRoute.trigger(route.clone(), site, {
|
|
265
|
-
delayRender: () => barrier.add(),
|
|
266
|
-
});
|
|
267
|
+
this._onRequest.trigger(req, site);
|
|
267
268
|
// route prepared
|
|
268
|
-
this.pageLoader.load(
|
|
269
|
+
this.pageLoader.load(req, site, { changeHistory });
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
-
this.
|
|
271
|
+
destroyRequest() {
|
|
272
|
+
if (!this._request)
|
|
273
|
+
return;
|
|
274
|
+
this._request._renderBarrier.cancel();
|
|
275
|
+
this._request = null;
|
|
272
276
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
this._renderBarrier = null;
|
|
281
|
-
}
|
|
277
|
+
_onPreload(req, site) {
|
|
278
|
+
this.pageLoader.preload(req, site);
|
|
279
|
+
}
|
|
280
|
+
async _onLoaded(resp, req, site, more) {
|
|
281
|
+
// check if the render was cancelled
|
|
282
|
+
if (await req._renderBarrier.ready())
|
|
283
|
+
return;
|
|
282
284
|
// when the data is loaded let's update the route of the inner
|
|
283
285
|
// this is will only happen if no other route has been requested
|
|
284
286
|
// in the meantime
|
|
285
287
|
more.changeHistory();
|
|
288
|
+
const route = req.toRoute();
|
|
286
289
|
const updateRoute = () => {
|
|
287
290
|
this._route.setSilent(route);
|
|
288
291
|
const siteChanged = this.site.get()?.id !== site.id;
|
|
@@ -292,7 +295,7 @@ export default class Router {
|
|
|
292
295
|
this._site.notify();
|
|
293
296
|
this._onRouteEv.trigger(route.clone(), site);
|
|
294
297
|
};
|
|
295
|
-
this._internal.onLoaded(resp.success,
|
|
298
|
+
this._internal.onLoaded(resp.success, req, site, () => {
|
|
296
299
|
updateRoute();
|
|
297
300
|
return resp.data;
|
|
298
301
|
});
|
|
@@ -304,31 +307,3 @@ export default class Router {
|
|
|
304
307
|
this._loadingProgress.set(progress);
|
|
305
308
|
}
|
|
306
309
|
}
|
|
307
|
-
class RenderBarrier {
|
|
308
|
-
inner;
|
|
309
|
-
cancelled;
|
|
310
|
-
root;
|
|
311
|
-
constructor() {
|
|
312
|
-
this.inner = new Barrier();
|
|
313
|
-
this.cancelled = false;
|
|
314
|
-
this.root = this.add();
|
|
315
|
-
}
|
|
316
|
-
add() {
|
|
317
|
-
const action = this.inner.add();
|
|
318
|
-
return {
|
|
319
|
-
ready: async () => {
|
|
320
|
-
await action.ready(null);
|
|
321
|
-
return this.cancelled;
|
|
322
|
-
},
|
|
323
|
-
remove: () => action.remove(),
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
cancel() {
|
|
327
|
-
this.cancelled = true;
|
|
328
|
-
this.root.remove();
|
|
329
|
-
}
|
|
330
|
-
// returns if the render was cancelled
|
|
331
|
-
ready() {
|
|
332
|
-
return this.root.ready();
|
|
333
|
-
}
|
|
334
|
-
}
|
package/dist/routing/Site.d.ts
CHANGED
package/dist/routing/Site.js
CHANGED
package/dist/routing/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Router
|
|
2
|
-
import Route from './Route.js';
|
|
1
|
+
import Router from './Router.js';
|
|
2
|
+
import Route, { type RouteOptions } from './Route.js';
|
|
3
|
+
import Request, { type RequestOptions, type DelayRender } from './Request.js';
|
|
3
4
|
import Site from './Site.js';
|
|
4
|
-
export { Router, Route, Site,
|
|
5
|
+
export { Router, Route, RouteOptions, Site, Request, DelayRender, RequestOptions, };
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,KAAK,EAAE,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,OAAO,EAAE,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACN,MAAM,EACN,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,OAAO,EACP,WAAW,EACX,cAAc,GACd,CAAC"}
|
package/dist/routing/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/routing/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,UAEvC"}
|
package/dist/ssr/SsrCache.d.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
export declare function calcKey(data: any): Promise<string>;
|
|
2
|
+
/**
|
|
3
|
+
* A simple cache for server side rendering
|
|
4
|
+
*
|
|
5
|
+
* You can use this to store data to pass to the client or to cache data
|
|
6
|
+
* generally. Storing data and retrieving it will also work on the client.
|
|
7
|
+
*/
|
|
2
8
|
export default class SsrCache {
|
|
3
9
|
private store;
|
|
4
10
|
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* check if the value is in the cache else calls the fn
|
|
13
|
+
*/
|
|
5
14
|
load<T>(key: string, fn: () => Promise<T>): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Get a value from the cache
|
|
17
|
+
*/
|
|
6
18
|
get<T>(key: string): T | null;
|
|
19
|
+
/**
|
|
20
|
+
* Set a value in the cache
|
|
21
|
+
*/
|
|
7
22
|
set<T>(key: string, val: T): T;
|
|
23
|
+
/** @hidden */
|
|
8
24
|
clear(): void;
|
|
9
25
|
private exportAsJson;
|
|
26
|
+
/** @hidden */
|
|
10
27
|
_exportToHead(): string;
|
|
11
28
|
}
|
|
12
29
|
//# sourceMappingURL=SsrCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,mBAetC;AAED,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B,OAAO,CAAC,KAAK,CAAsB;;
|
|
1
|
+
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,mBAetC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B,OAAO,CAAC,KAAK,CAAsB;;IAYnC;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC;IAO/C;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAI7B;;OAEG;IACH,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAI9B,cAAc;IACd,KAAK;IAIL,OAAO,CAAC,YAAY;IAIpB,cAAc;IACd,aAAa,IAAI,MAAM;CAGvB"}
|
package/dist/ssr/SsrCache.js
CHANGED
|
@@ -11,6 +11,12 @@ export async function calcKey(data) {
|
|
|
11
11
|
.join(''); // Convert to hex string
|
|
12
12
|
return hashHex;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A simple cache for server side rendering
|
|
16
|
+
*
|
|
17
|
+
* You can use this to store data to pass to the client or to cache data
|
|
18
|
+
* generally. Storing data and retrieving it will also work on the client.
|
|
19
|
+
*/
|
|
14
20
|
export default class SsrCache {
|
|
15
21
|
store;
|
|
16
22
|
constructor() {
|
|
@@ -21,7 +27,9 @@ export default class SsrCache {
|
|
|
21
27
|
this.store = window.SSR_STORE;
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
|
-
|
|
30
|
+
/**
|
|
31
|
+
* check if the value is in the cache else calls the fn
|
|
32
|
+
*/
|
|
25
33
|
async load(key, fn) {
|
|
26
34
|
if (key in this.store)
|
|
27
35
|
return this.store[key];
|
|
@@ -29,21 +37,26 @@ export default class SsrCache {
|
|
|
29
37
|
this.set(key, v);
|
|
30
38
|
return v;
|
|
31
39
|
}
|
|
32
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Get a value from the cache
|
|
42
|
+
*/
|
|
33
43
|
get(key) {
|
|
34
44
|
return this.store[key] ?? null;
|
|
35
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Set a value in the cache
|
|
48
|
+
*/
|
|
36
49
|
set(key, val) {
|
|
37
50
|
return (this.store[key] = val);
|
|
38
51
|
}
|
|
52
|
+
/** @hidden */
|
|
39
53
|
clear() {
|
|
40
54
|
this.store = {};
|
|
41
55
|
}
|
|
42
|
-
// internal
|
|
43
56
|
exportAsJson() {
|
|
44
57
|
return JSON.stringify(this.store).replace(/</g, '\\u003c');
|
|
45
58
|
}
|
|
46
|
-
|
|
59
|
+
/** @hidden */
|
|
47
60
|
_exportToHead() {
|
|
48
61
|
return `\n\t\t<script>window.SSR_STORE = ${this.exportAsJson()};</script>`;
|
|
49
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SsrComponents.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrComponents.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,aAAa;IACjC,OAAO,CAAC,OAAO,CAAc;;IAO7B,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAOlC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAkB5C"}
|
|
1
|
+
{"version":3,"file":"SsrComponents.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrComponents.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,MAAM,CAAC,OAAO,OAAO,aAAa;IACjC,OAAO,CAAC,OAAO,CAAc;;IAO7B,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC;IAOlC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;CAkB5C"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"author": "Crelte <support@crelte.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"check": "
|
|
7
|
+
"check": "svelte-check",
|
|
8
|
+
"check-fmt": "prettier -c .",
|
|
9
|
+
"fmt": "prettier -w .",
|
|
8
10
|
"lint": "eslint ./src",
|
|
9
11
|
"test": "vitest",
|
|
10
12
|
"build": "svelte-package -i ./src",
|
|
@@ -70,10 +72,8 @@
|
|
|
70
72
|
"devDependencies": {
|
|
71
73
|
"@sveltejs/package": "^2.3.1",
|
|
72
74
|
"@sveltejs/vite-plugin-svelte": "^3.0.0",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"typescript": "^5.2.2",
|
|
76
|
-
"typescript-eslint": "^7.11.0",
|
|
75
|
+
"svelte-check": "^4.1.4",
|
|
76
|
+
"typescript-svelte-plugin": "^0.3.45",
|
|
77
77
|
"vitest": "^2.0.0"
|
|
78
78
|
}
|
|
79
79
|
}
|