crelte 0.2.2 → 0.3.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/dist/Crelte.d.ts +49 -9
- package/dist/Crelte.d.ts.map +1 -1
- package/dist/Crelte.js +30 -10
- package/dist/CrelteRequest.d.ts +3 -7
- package/dist/CrelteRequest.d.ts.map +1 -1
- package/dist/CrelteRequest.js +9 -15
- package/dist/graphql/GraphQl.d.ts +7 -0
- package/dist/graphql/GraphQl.d.ts.map +1 -1
- package/dist/graphql/GraphQl.js +16 -3
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/init/client.d.ts +0 -19
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +9 -12
- package/dist/init/server.d.ts +0 -4
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +2 -5
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +8 -8
- package/dist/loadData/Globals.d.ts +15 -31
- package/dist/loadData/Globals.d.ts.map +1 -1
- package/dist/loadData/Globals.js +65 -72
- package/dist/routing/InnerRouter.d.ts.map +1 -1
- package/dist/routing/InnerRouter.js +8 -2
- package/dist/routing/Router.d.ts +27 -2
- package/dist/routing/Router.d.ts.map +1 -1
- package/dist/routing/Router.js +31 -1
- package/dist/ssr/SsrCache.d.ts.map +1 -1
- package/dist/ssr/SsrCache.js +6 -1
- package/package.json +2 -2
- package/src/Crelte.ts +80 -13
- package/src/CrelteRequest.ts +14 -23
- package/src/graphql/GraphQl.ts +25 -6
- package/src/index.ts +30 -8
- package/src/init/client.ts +9 -40
- package/src/init/server.ts +2 -13
- package/src/init/shared.ts +8 -9
- package/src/loadData/Globals.ts +76 -93
- package/src/routing/InnerRouter.ts +9 -2
- package/src/routing/Router.ts +43 -9
- package/src/ssr/SsrCache.ts +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot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E;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,aAAa,GAAG,IAAI,CAE3D;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYvC;AAED,wBAAsB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACnC,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EACd,UAAU,EAAE,YAAY,EACxB,WAAW,CAAC,EAAE,YAAY,EAC1B,QAAQ,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,GAAG,CAAC,CAqGd"}
|
package/dist/init/shared.js
CHANGED
|
@@ -40,19 +40,21 @@ export async function loadFn(cr, app, entryQuery, globalQuery, loadOpts) {
|
|
|
40
40
|
dataProm = callLoadData(app.loadGlobalData, cr, null);
|
|
41
41
|
}
|
|
42
42
|
let globalProm = null;
|
|
43
|
-
if (globalQuery && !cr.globals._wasLoaded()) {
|
|
43
|
+
if (globalQuery && !cr.globals._wasLoaded(cr.site.id)) {
|
|
44
44
|
globalProm = (async () => {
|
|
45
|
-
const res = await cr.query(globalQuery
|
|
45
|
+
const res = await cr.query(globalQuery, {
|
|
46
|
+
siteId: cr.site.id,
|
|
47
|
+
});
|
|
46
48
|
// we need to do this sorcery here and can't wait until all
|
|
47
49
|
// globals functions are done, because some global function
|
|
48
50
|
// might want to use globals, and for that the function
|
|
49
|
-
//
|
|
51
|
+
// getAsync exists on Globals
|
|
50
52
|
cr.globals._setData(cr.site.id, res);
|
|
51
53
|
return res;
|
|
52
54
|
})();
|
|
53
55
|
}
|
|
54
56
|
let pageProm = null;
|
|
55
|
-
if (cr.req.
|
|
57
|
+
if (cr.req.siteMatches()) {
|
|
56
58
|
let uri = decodeURI(cr.req.uri);
|
|
57
59
|
if (uri.startsWith('/'))
|
|
58
60
|
uri = uri.substring(1);
|
|
@@ -60,7 +62,7 @@ export async function loadFn(cr, app, entryQuery, globalQuery, loadOpts) {
|
|
|
60
62
|
uri = '__home__';
|
|
61
63
|
pageProm = cr.query(entryQuery, {
|
|
62
64
|
uri,
|
|
63
|
-
siteId: cr.
|
|
65
|
+
siteId: cr.site.id,
|
|
64
66
|
});
|
|
65
67
|
}
|
|
66
68
|
const pluginsLoadGlobalData = cr.events.trigger('loadGlobalData', cr);
|
|
@@ -75,13 +77,11 @@ export async function loadFn(cr, app, entryQuery, globalQuery, loadOpts) {
|
|
|
75
77
|
if (global) {
|
|
76
78
|
cr.globals._setData(cr.site.id, global);
|
|
77
79
|
}
|
|
78
|
-
else if (!cr.globals._wasLoaded()) {
|
|
80
|
+
else if (!cr.globals._wasLoaded(cr.site.id)) {
|
|
79
81
|
// we need to set the global data to an empty object
|
|
80
82
|
// so any waiters get's triggered
|
|
81
83
|
cr.globals._setData(cr.site.id, {});
|
|
82
84
|
}
|
|
83
|
-
// allow cr to get the global data
|
|
84
|
-
cr._globalDataLoaded();
|
|
85
85
|
const entry = getEntry(page);
|
|
86
86
|
let template;
|
|
87
87
|
if (app.templates) {
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
export type GlobalWaiters = [(g:
|
|
1
|
+
export type GlobalWaiters<T> = [(g: T | null) => void];
|
|
2
2
|
export default class Globals {
|
|
3
3
|
private waiters;
|
|
4
|
-
private
|
|
5
|
-
private
|
|
6
|
-
private
|
|
4
|
+
private data;
|
|
5
|
+
private stores;
|
|
6
|
+
private currentSiteId;
|
|
7
7
|
constructor();
|
|
8
|
+
get<T = any>(name: string, siteId: number): T | null;
|
|
8
9
|
/**
|
|
9
10
|
* returns a store which contains a globalSet
|
|
10
11
|
*
|
|
11
12
|
* ## Note
|
|
12
13
|
* This only works in loadData, in loadGlobalData this will
|
|
13
14
|
* always return null. In that context you should use
|
|
14
|
-
* `.
|
|
15
|
+
* `.getAsync`
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
getStore<T = any>(name: string): Global<T> | null;
|
|
17
18
|
/**
|
|
18
19
|
* Get a store which contains a globalSet and wait until it is loaded
|
|
19
20
|
*
|
|
@@ -21,32 +22,21 @@ export default class Globals {
|
|
|
21
22
|
* This is only useful in loadGlobalData in all other cases
|
|
22
23
|
* you can use `.getGlobal` which does return a Promise
|
|
23
24
|
*/
|
|
24
|
-
getAsync<T
|
|
25
|
+
getAsync<T = any>(name: string, siteId: number): Promise<T | null>;
|
|
25
26
|
/** @hidden */
|
|
26
|
-
_wasLoaded(): boolean;
|
|
27
|
+
_wasLoaded(siteId: number): boolean;
|
|
27
28
|
/** @hidden */
|
|
28
29
|
_setData(siteId: number, data: any): void;
|
|
29
30
|
/** @hidden */
|
|
30
|
-
_globalsBySite(siteId: number): Map<string, any>;
|
|
31
|
-
/** @hidden */
|
|
32
31
|
_updateSiteId(siteId: number): void;
|
|
33
32
|
}
|
|
34
|
-
/**
|
|
35
|
-
* A globalSet Data
|
|
36
|
-
*
|
|
37
|
-
* Each global query should contain the siteId
|
|
38
|
-
*/
|
|
39
|
-
export interface GlobalData {
|
|
40
|
-
siteId?: number;
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
}
|
|
43
33
|
/**
|
|
44
34
|
* A globalSet store
|
|
45
35
|
*/
|
|
46
|
-
export declare class Global<T
|
|
36
|
+
export declare class Global<T = any> {
|
|
37
|
+
/** @hidden */
|
|
47
38
|
private inner;
|
|
48
|
-
|
|
49
|
-
constructor(name: string, data: T[] | T, siteId: number);
|
|
39
|
+
constructor(name: string, data: T);
|
|
50
40
|
/**
|
|
51
41
|
* The function get's called once with the current value and then when the
|
|
52
42
|
* values changes
|
|
@@ -58,15 +48,9 @@ export declare class Global<T extends GlobalData> {
|
|
|
58
48
|
* The current value
|
|
59
49
|
*/
|
|
60
50
|
get(): T;
|
|
61
|
-
/**
|
|
62
|
-
* Get the value based on the siteId
|
|
63
|
-
*
|
|
64
|
-
* ## Note
|
|
65
|
-
* If you pass a siteId which comes from craft
|
|
66
|
-
* you will never receive null
|
|
67
|
-
*/
|
|
68
|
-
bySiteId(siteId: number): T | null;
|
|
69
51
|
/** @hidden */
|
|
70
|
-
|
|
52
|
+
_setSilent(value: T): void;
|
|
53
|
+
/** @hidden */
|
|
54
|
+
_notify(): void;
|
|
71
55
|
}
|
|
72
56
|
//# sourceMappingURL=Globals.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Globals.d.ts","sourceRoot":"","sources":["../../../../src/loadData/Globals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Globals.d.ts","sourceRoot":"","sources":["../../../../src/loadData/Globals.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,OAAO;IAG3B,OAAO,CAAC,OAAO,CAA+C;IAC9D,OAAO,CAAC,IAAI,CAAgC;IAC5C,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,aAAa,CAAgB;;IASrC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAIpD;;;;;;;OAOG;IACH,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI;IAIjD;;;;;;OAMG;IACH,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAqBlE,cAAc;IACd,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAQnC,cAAc;IACd,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG;IAUlC,cAAc;IACd,aAAa,CAAC,MAAM,EAAE,MAAM;CAuB5B;AAED;;GAEG;AACH,qBAAa,MAAM,CAAC,CAAC,GAAG,GAAG;IAC1B,cAAc;IACd,OAAO,CAAC,KAAK,CAAc;gBAEf,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAiBjC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAI3C;;OAEG;IACH,GAAG,IAAI,CAAC;IAIR,cAAc;IACd,UAAU,CAAC,KAAK,EAAE,CAAC;IAInB,cAAc;IACd,OAAO;CAGP"}
|
package/dist/loadData/Globals.js
CHANGED
|
@@ -4,20 +4,24 @@ const emergency = getGlobal('emergency');
|
|
|
4
4
|
|
|
5
5
|
// returns the data based on the current site (no store)
|
|
6
6
|
cr.getGlobal('emergency')
|
|
7
|
+
|
|
7
8
|
*/
|
|
8
9
|
import { Writable } from 'crelte-std/stores';
|
|
9
10
|
export default class Globals {
|
|
10
11
|
// while the globals are not loaded if somebody calls
|
|
11
|
-
//
|
|
12
|
+
// getAsync then we need to store the waiters
|
|
12
13
|
waiters;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
data;
|
|
15
|
+
stores;
|
|
16
|
+
currentSiteId;
|
|
16
17
|
constructor() {
|
|
17
18
|
this.waiters = new Map();
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
19
|
+
this.data = new Map();
|
|
20
|
+
this.stores = new Map();
|
|
21
|
+
this.currentSiteId = null;
|
|
22
|
+
}
|
|
23
|
+
get(name, siteId) {
|
|
24
|
+
return this.data.get(siteId)?.get(name) ?? null;
|
|
21
25
|
}
|
|
22
26
|
/**
|
|
23
27
|
* returns a store which contains a globalSet
|
|
@@ -25,10 +29,10 @@ export default class Globals {
|
|
|
25
29
|
* ## Note
|
|
26
30
|
* This only works in loadData, in loadGlobalData this will
|
|
27
31
|
* always return null. In that context you should use
|
|
28
|
-
* `.
|
|
32
|
+
* `.getAsync`
|
|
29
33
|
*/
|
|
30
|
-
|
|
31
|
-
return this.
|
|
34
|
+
getStore(name) {
|
|
35
|
+
return this.stores.get(name) ?? null;
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* Get a store which contains a globalSet and wait until it is loaded
|
|
@@ -37,78 +41,78 @@ export default class Globals {
|
|
|
37
41
|
* This is only useful in loadGlobalData in all other cases
|
|
38
42
|
* you can use `.getGlobal` which does return a Promise
|
|
39
43
|
*/
|
|
40
|
-
getAsync(name) {
|
|
41
|
-
if (this.
|
|
42
|
-
return this.get(name);
|
|
43
|
-
let
|
|
44
|
+
getAsync(name, siteId) {
|
|
45
|
+
if (this._wasLoaded(siteId))
|
|
46
|
+
return Promise.resolve(this.get(name, siteId));
|
|
47
|
+
let listeners = this.waiters.get(siteId);
|
|
48
|
+
if (!listeners) {
|
|
49
|
+
listeners = new Map();
|
|
50
|
+
this.waiters.set(siteId, listeners);
|
|
51
|
+
}
|
|
52
|
+
let waiter = listeners.get(name);
|
|
44
53
|
if (!waiter) {
|
|
45
54
|
waiter = [];
|
|
46
|
-
|
|
55
|
+
listeners.set(name, waiter);
|
|
47
56
|
}
|
|
48
57
|
return new Promise(resolve => {
|
|
49
58
|
waiter.push(resolve);
|
|
50
59
|
});
|
|
51
60
|
}
|
|
52
61
|
/** @hidden */
|
|
53
|
-
_wasLoaded() {
|
|
54
|
-
return this.
|
|
62
|
+
_wasLoaded(siteId) {
|
|
63
|
+
return this.data.has(siteId);
|
|
55
64
|
}
|
|
56
65
|
// data is the data from the global graphql
|
|
57
66
|
// so it contains some keys and data which should be parsed
|
|
58
67
|
// and created a store for each key
|
|
68
|
+
// do not call this if _wasLoaded returns true with the same siteId
|
|
59
69
|
/** @hidden */
|
|
60
70
|
_setData(siteId, data) {
|
|
61
|
-
const
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.waiters.forEach((waiters, key) => {
|
|
68
|
-
waiters.forEach(waiter => waiter(this.get(key)));
|
|
69
|
-
});
|
|
70
|
-
this.waiters.clear();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** @hidden */
|
|
74
|
-
_globalsBySite(siteId) {
|
|
75
|
-
const map = new Map();
|
|
76
|
-
for (const [key, global] of this.entries) {
|
|
77
|
-
map.set(key, global.bySiteId(siteId));
|
|
78
|
-
}
|
|
79
|
-
return map;
|
|
71
|
+
const map = new Map(Object.entries(data));
|
|
72
|
+
this.data.set(siteId, map);
|
|
73
|
+
this.waiters.get(siteId)?.forEach((waiters, key) => {
|
|
74
|
+
waiters.forEach(waiter => waiter(map.get(key)));
|
|
75
|
+
});
|
|
76
|
+
this.waiters.delete(siteId);
|
|
80
77
|
}
|
|
81
78
|
/** @hidden */
|
|
82
79
|
_updateSiteId(siteId) {
|
|
83
|
-
|
|
84
|
-
if (this.prevSiteId === siteId)
|
|
80
|
+
if (this.currentSiteId === siteId)
|
|
85
81
|
return;
|
|
86
|
-
this.
|
|
82
|
+
const data = this.data.get(siteId) ?? new Map();
|
|
83
|
+
// we set all global data to null via setSilent
|
|
84
|
+
// then set them all with the new data
|
|
85
|
+
// and update all of them
|
|
86
|
+
this.stores.forEach(global => global._setSilent(null));
|
|
87
|
+
data.forEach((value, key) => {
|
|
88
|
+
let global = this.stores.get(key);
|
|
89
|
+
if (global) {
|
|
90
|
+
global._setSilent(value);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
global = new Global(key, value);
|
|
94
|
+
this.stores.set(key, global);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.stores.forEach(global => global._notify());
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
/**
|
|
90
101
|
* A globalSet store
|
|
91
102
|
*/
|
|
92
103
|
export class Global {
|
|
104
|
+
/** @hidden */
|
|
93
105
|
inner;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
this.languages = data;
|
|
103
|
-
inner = data.find(d => d.siteId === siteId);
|
|
104
|
-
if (!inner?.siteId) {
|
|
105
|
-
throw new Error(`The global query ${name} does not contain the required siteId property`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
inner = data;
|
|
106
|
+
constructor(name, data) {
|
|
107
|
+
// todo remove in v1.0
|
|
108
|
+
// In v0.2, we queried the global data for all sites.
|
|
109
|
+
// We now check if the siteId is present and notify the user to remove it.
|
|
110
|
+
if (typeof data.siteId === 'number' ||
|
|
111
|
+
(Array.isArray(data) && typeof data[0]?.siteId === 'number')) {
|
|
112
|
+
throw new Error(`The global query ${name} should not include the siteId` +
|
|
113
|
+
` property. Instead, use the siteId as a parameter.`);
|
|
110
114
|
}
|
|
111
|
-
this.inner = new Writable(
|
|
115
|
+
this.inner = new Writable(data);
|
|
112
116
|
}
|
|
113
117
|
/**
|
|
114
118
|
* The function get's called once with the current value and then when the
|
|
@@ -125,23 +129,12 @@ export class Global {
|
|
|
125
129
|
get() {
|
|
126
130
|
return this.inner.get();
|
|
127
131
|
}
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
* ## Note
|
|
132
|
-
* If you pass a siteId which comes from craft
|
|
133
|
-
* you will never receive null
|
|
134
|
-
*/
|
|
135
|
-
bySiteId(siteId) {
|
|
136
|
-
if (this.languages)
|
|
137
|
-
return this.languages.find(d => d.siteId === siteId) ?? null;
|
|
138
|
-
return this.inner.get();
|
|
132
|
+
/** @hidden */
|
|
133
|
+
_setSilent(value) {
|
|
134
|
+
this.inner.setSilent(value);
|
|
139
135
|
}
|
|
140
136
|
/** @hidden */
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return;
|
|
144
|
-
const inner = this.languages.find(d => d.siteId === siteId);
|
|
145
|
-
this.inner.set(inner);
|
|
137
|
+
_notify() {
|
|
138
|
+
this.inner.notify();
|
|
146
139
|
}
|
|
147
140
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InnerRouter.d.ts","sourceRoot":"","sources":["../../../../src/routing/InnerRouter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,OAAO,EAAE,EAAa,cAAc,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,MAAM,eAAe,GAAG;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC/B,KAAK,EAAE,IAAI,EAAE,CAAC;IACd;;;;;OAKG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAC7D,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAEpC,OAAO,CAAC,qBAAqB,CAAa;IAE1C;;;;;OAKG;gBACS,KAAK,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe;IAkB3D;;OAEG;IACH,UAAU;IAaV;;OAEG;IACH,UAAU;IAEV;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,GAAE,MAAM,GAAG,IAAW,GAAG,IAAI;IAsCxD;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"InnerRouter.d.ts","sourceRoot":"","sources":["../../../../src/routing/InnerRouter.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAE,eAAe,EAAE,MAAM,WAAW,C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C,GAAG,EAAE,OAAO,EAAE,cAAc,UAAQ;IAM7C;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,cAAc,UAAQ;IAsBzC;;;;;;;OAOG;IACH,OAAO,CAAC,GAAG,EAAE,OAAO;IAsBpB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO;IAW9C,QAAQ,CAAC,GAAG,EAAE,OAAO;CAsErB"}
|
|
@@ -110,6 +110,7 @@ export default class InnerRouter {
|
|
|
110
110
|
siteById(id) {
|
|
111
111
|
return this.sites.find(s => s.id === id) ?? null;
|
|
112
112
|
}
|
|
113
|
+
// keep this doc in sync with Router.targetToRequest
|
|
113
114
|
/**
|
|
114
115
|
* Resolve a url or Route and convert it to a Request
|
|
115
116
|
*
|
|
@@ -125,6 +126,9 @@ export default class InnerRouter {
|
|
|
125
126
|
const site = this.route?.site ?? this.defaultSite();
|
|
126
127
|
target = new URL(site.uri + target, site.url);
|
|
127
128
|
}
|
|
129
|
+
else if (!target) {
|
|
130
|
+
throw new Error('the url is not allowed to be empty');
|
|
131
|
+
}
|
|
128
132
|
else {
|
|
129
133
|
target = new URL(target);
|
|
130
134
|
}
|
|
@@ -205,7 +209,9 @@ export default class InnerRouter {
|
|
|
205
209
|
return;
|
|
206
210
|
if (link && link.target.toLowerCase() === '_blank')
|
|
207
211
|
return;
|
|
208
|
-
if (link &&
|
|
212
|
+
if (link &&
|
|
213
|
+
!link.hasAttribute('data-no-preload') &&
|
|
214
|
+
link.href) {
|
|
209
215
|
this.preload(link.href);
|
|
210
216
|
}
|
|
211
217
|
currentMouseOver = link;
|
|
@@ -243,7 +249,7 @@ export default class InnerRouter {
|
|
|
243
249
|
});
|
|
244
250
|
}
|
|
245
251
|
window.addEventListener('popstate', async (e) => {
|
|
246
|
-
if (!
|
|
252
|
+
if (!e.state?.route)
|
|
247
253
|
return;
|
|
248
254
|
const req = this.targetToRequest(window.location.href);
|
|
249
255
|
req._fillFromState(e.state);
|
package/dist/routing/Router.d.ts
CHANGED
|
@@ -27,10 +27,16 @@ type ServerInited = {
|
|
|
27
27
|
export default class Router {
|
|
28
28
|
/**
|
|
29
29
|
* The current route
|
|
30
|
+
*
|
|
31
|
+
* ## Note
|
|
32
|
+
* Will always contain a route expect in the first loadData call
|
|
30
33
|
*/
|
|
31
34
|
private _route;
|
|
32
35
|
/**
|
|
33
36
|
* The current site
|
|
37
|
+
*
|
|
38
|
+
* ## Note
|
|
39
|
+
* Will always contain a site expect in the first loadData call
|
|
34
40
|
*/
|
|
35
41
|
private _site;
|
|
36
42
|
private _request;
|
|
@@ -51,12 +57,22 @@ export default class Router {
|
|
|
51
57
|
constructor(sites: SiteFromGraphQl[], opts?: RouterOptions);
|
|
52
58
|
/**
|
|
53
59
|
* returns a store with the current route
|
|
60
|
+
*
|
|
61
|
+
* ## Note
|
|
62
|
+
* Will always contain a route expect in the first loadData call
|
|
63
|
+
*
|
|
64
|
+
* Consider to use CrelteRequest instead
|
|
54
65
|
*/
|
|
55
|
-
get route(): Readable<Route>;
|
|
66
|
+
get route(): Readable<Route | null>;
|
|
56
67
|
/**
|
|
57
68
|
* returns a store with the current site
|
|
69
|
+
*
|
|
70
|
+
* ## Note
|
|
71
|
+
* Will always contain a site expect in the first loadData call
|
|
72
|
+
*
|
|
73
|
+
* Consider to use CrelteRequest instead
|
|
58
74
|
*/
|
|
59
|
-
get site(): Readable<Site>;
|
|
75
|
+
get site(): Readable<Site | null>;
|
|
60
76
|
/**
|
|
61
77
|
* The sites which are available
|
|
62
78
|
*/
|
|
@@ -163,6 +179,7 @@ export default class Router {
|
|
|
163
179
|
*
|
|
164
180
|
* This will trigger every time a new route is set
|
|
165
181
|
* and is equivalent to router.route.subscribe(fn)
|
|
182
|
+
* expect that it will not trigger instantly
|
|
166
183
|
*
|
|
167
184
|
* @returns a function to remove the listener
|
|
168
185
|
*/
|
|
@@ -175,6 +192,14 @@ export default class Router {
|
|
|
175
192
|
* @returns a function to remove the listener
|
|
176
193
|
*/
|
|
177
194
|
onRequest(fn: (req: Request) => void): () => void;
|
|
195
|
+
/**
|
|
196
|
+
* Resolve a url or Route and convert it to a Request
|
|
197
|
+
*
|
|
198
|
+
* @param target
|
|
199
|
+
* @param opts, any option present will override the value in target
|
|
200
|
+
* @return Returns null if the url does not match our host (the protocol get's ignored)
|
|
201
|
+
*/
|
|
202
|
+
targetToRequest(target: string | URL | Route | Request, opts?: RequestOptions): Request;
|
|
178
203
|
private setNewRoute;
|
|
179
204
|
private _initClient;
|
|
180
205
|
private _initServer;
|
|
@@ -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,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;IACf,QAAQ,EAAE,CACT,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,OAAO,EAKZ,KAAK,EAAE,MAAM,GAAG,KACZ,IAAI,CAAC;IAIV,eAAe,EAAE,CAChB,GAAG,EAAE,OAAO,EAKZ,KAAK,EAAE,MAAM,IAAI,KACb,IAAI,CAAC;IAEV,MAAM,EAAE,MAAM,CAAC;IAEf,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAEjC,UAAU,EAAE,MAAM,IAAI,CAAC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AG,OAAO,EAAE,IAAI,GAAE,cAAmB;IActD;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAKhC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,EAAE,IAAI,GAAE,cAAmB;IAazD;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAKnC;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,IAAI;IAIJ;;OAEG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK;IAIpC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,MAAM,IAAI;IAK/C;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI;IAIjD;;;;;;OAMG;IACH,eAAe,CACd,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,GAAG,OAAO,EACtC,IAAI,GAAE,cAAmB,GACvB,OAAO;IAIV,OAAO,CAAC,WAAW;YAQL,WAAW;YAIX,WAAW;IA4DzB,OAAO,CAAC,QAAQ;IAoBhB,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,UAAU;YAIJ,SAAS;YAsBT,gBAAgB;IAkB9B,OAAO,CAAC,WAAW;CAKnB"}
|
package/dist/routing/Router.js
CHANGED
|
@@ -11,10 +11,16 @@ const defaultRouterOpts = {
|
|
|
11
11
|
export default class Router {
|
|
12
12
|
/**
|
|
13
13
|
* The current route
|
|
14
|
+
*
|
|
15
|
+
* ## Note
|
|
16
|
+
* Will always contain a route expect in the first loadData call
|
|
14
17
|
*/
|
|
15
18
|
_route;
|
|
16
19
|
/**
|
|
17
20
|
* The current site
|
|
21
|
+
*
|
|
22
|
+
* ## Note
|
|
23
|
+
* Will always contain a site expect in the first loadData call
|
|
18
24
|
*/
|
|
19
25
|
_site;
|
|
20
26
|
// the next request, just here to destroy it
|
|
@@ -64,12 +70,22 @@ export default class Router {
|
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* returns a store with the current route
|
|
73
|
+
*
|
|
74
|
+
* ## Note
|
|
75
|
+
* Will always contain a route expect in the first loadData call
|
|
76
|
+
*
|
|
77
|
+
* Consider to use CrelteRequest instead
|
|
67
78
|
*/
|
|
68
79
|
get route() {
|
|
69
80
|
return this._route.readclone();
|
|
70
81
|
}
|
|
71
82
|
/**
|
|
72
83
|
* returns a store with the current site
|
|
84
|
+
*
|
|
85
|
+
* ## Note
|
|
86
|
+
* Will always contain a site expect in the first loadData call
|
|
87
|
+
*
|
|
88
|
+
* Consider to use CrelteRequest instead
|
|
73
89
|
*/
|
|
74
90
|
get site() {
|
|
75
91
|
return this._site.readonly();
|
|
@@ -160,6 +176,7 @@ export default class Router {
|
|
|
160
176
|
* @deprecated use push instead
|
|
161
177
|
*/
|
|
162
178
|
pushState(route) {
|
|
179
|
+
console.warn('pushState is deprecated, use push instead');
|
|
163
180
|
this.push(route);
|
|
164
181
|
}
|
|
165
182
|
/**
|
|
@@ -200,6 +217,7 @@ export default class Router {
|
|
|
200
217
|
* @deprecated use replace instead
|
|
201
218
|
*/
|
|
202
219
|
replaceState(route) {
|
|
220
|
+
console.warn('replaceState is deprecated, use replace instead');
|
|
203
221
|
this.replace(route);
|
|
204
222
|
}
|
|
205
223
|
/**
|
|
@@ -225,11 +243,13 @@ export default class Router {
|
|
|
225
243
|
*
|
|
226
244
|
* This will trigger every time a new route is set
|
|
227
245
|
* and is equivalent to router.route.subscribe(fn)
|
|
246
|
+
* expect that it will not trigger instantly
|
|
228
247
|
*
|
|
229
248
|
* @returns a function to remove the listener
|
|
230
249
|
*/
|
|
231
250
|
onRoute(fn) {
|
|
232
|
-
|
|
251
|
+
let first = true;
|
|
252
|
+
return this.route.subscribe(r => (first ? (first = false) : fn(r)));
|
|
233
253
|
}
|
|
234
254
|
/**
|
|
235
255
|
* Add a listener for the onRequest event
|
|
@@ -241,6 +261,16 @@ export default class Router {
|
|
|
241
261
|
onRequest(fn) {
|
|
242
262
|
return this._onRequest.add(fn);
|
|
243
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Resolve a url or Route and convert it to a Request
|
|
266
|
+
*
|
|
267
|
+
* @param target
|
|
268
|
+
* @param opts, any option present will override the value in target
|
|
269
|
+
* @return Returns null if the url does not match our host (the protocol get's ignored)
|
|
270
|
+
*/
|
|
271
|
+
targetToRequest(target, opts = {}) {
|
|
272
|
+
return this.inner.targetToRequest(target, opts);
|
|
273
|
+
}
|
|
244
274
|
setNewRoute(route) {
|
|
245
275
|
this._route.setSilent(route);
|
|
246
276
|
const siteChanged = this.site.get()?.id !== route.site.id;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"SsrCache.d.ts","sourceRoot":"","sources":["../../../../src/ssr/SsrCache.ts"],"names":[],"mappings":"AAAA,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,mBAoBtC;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
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
export async function calcKey(data) {
|
|
2
|
+
const json = JSON.stringify(data);
|
|
3
|
+
// this should only happen in an unsecure context
|
|
4
|
+
// specifically in the craft preview locally
|
|
5
|
+
if (!crypto?.subtle)
|
|
6
|
+
return json;
|
|
2
7
|
// Convert the string data to an ArrayBuffer
|
|
3
8
|
const encoder = new TextEncoder();
|
|
4
|
-
const dataBuffer = encoder.encode(
|
|
9
|
+
const dataBuffer = encoder.encode(json);
|
|
5
10
|
// Use the Web Crypto API to hash the data with SHA-1
|
|
6
11
|
const hashBuffer = await crypto.subtle.digest('SHA-1', dataBuffer);
|
|
7
12
|
// Convert the ArrayBuffer to a hex string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "Crelte <support@crelte.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"crelte-std": "^0.1.
|
|
73
|
+
"crelte-std": "^0.1.1",
|
|
74
74
|
"svelte": "^4.2.12"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|