crelte 0.5.11 → 0.5.13
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/blocks/Blocks.d.ts +1 -1
- package/dist/blocks/Blocks.d.ts.map +1 -1
- package/dist/bodyClass/BodyClass.d.ts +56 -0
- package/dist/bodyClass/BodyClass.d.ts.map +1 -0
- package/dist/bodyClass/BodyClass.js +70 -0
- package/dist/bodyClass/ClientBodyClass.d.ts +17 -0
- package/dist/bodyClass/ClientBodyClass.d.ts.map +1 -0
- package/dist/bodyClass/ClientBodyClass.js +71 -0
- package/dist/bodyClass/ServerBodyClass.d.ts +18 -0
- package/dist/bodyClass/ServerBodyClass.d.ts.map +1 -0
- package/dist/bodyClass/ServerBodyClass.js +61 -0
- package/dist/bodyClass/index.d.ts +2 -0
- package/dist/bodyClass/index.d.ts.map +1 -0
- package/dist/bodyClass/index.js +1 -0
- package/dist/bodyClass/utils.d.ts +39 -0
- package/dist/bodyClass/utils.d.ts.map +1 -0
- package/dist/bodyClass/utils.js +84 -0
- package/dist/cookies/ClientCookies.d.ts +8 -3
- package/dist/cookies/ClientCookies.d.ts.map +1 -1
- package/dist/cookies/ClientCookies.js +31 -7
- package/dist/cookies/Cookies.d.ts +42 -0
- package/dist/cookies/Cookies.d.ts.map +1 -0
- package/dist/cookies/Cookies.js +44 -0
- package/dist/cookies/ServerCookies.d.ts +3 -2
- package/dist/cookies/ServerCookies.d.ts.map +1 -1
- package/dist/cookies/ServerCookies.js +6 -4
- package/dist/cookies/index.d.ts +1 -25
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/cookies/index.js +1 -1
- package/dist/crelte.d.ts +7 -1
- package/dist/crelte.d.ts.map +1 -1
- package/dist/crelte.js +4 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +23 -14
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +12 -3
- package/dist/init/shared.d.ts +1 -0
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +19 -5
- package/dist/loadData/Globals.d.ts.map +1 -1
- package/dist/loadData/entry.d.ts +11 -2
- package/dist/loadData/entry.d.ts.map +1 -1
- package/dist/loadData/entry.js +11 -2
- package/dist/node/index.js +1 -1
- package/dist/plugins/Events.d.ts +6 -1
- package/dist/plugins/Events.d.ts.map +1 -1
- package/dist/plugins/Plugins.d.ts +36 -1
- package/dist/plugins/Plugins.d.ts.map +1 -1
- package/dist/plugins/Plugins.js +32 -0
- package/dist/queries/index.d.ts +1 -1
- package/dist/queries/index.d.ts.map +1 -1
- package/dist/routing/route/Request.d.ts +1 -1
- package/dist/routing/route/Request.d.ts.map +1 -1
- package/dist/routing/route/Request.js +7 -3
- package/dist/routing/router/ClientRouter.d.ts.map +1 -1
- package/dist/routing/router/ClientRouter.js +18 -11
- package/dist/routing/router/Router.d.ts.map +1 -1
- package/dist/routing/router/Router.js +8 -12
- package/dist/server/CrelteServer.d.ts +1 -0
- package/dist/server/CrelteServer.d.ts.map +1 -1
- package/dist/server/CrelteServer.js +5 -2
- package/dist/server/queries/QueryGqlRoute.d.ts.map +1 -1
- package/dist/server/queries/QueryGqlRoute.js +3 -3
- package/dist/server/queries/routes.d.ts +1 -1
- package/dist/server/queries/routes.d.ts.map +1 -1
- package/dist/std/stores/StagedWritable.d.ts +48 -0
- package/dist/std/stores/StagedWritable.d.ts.map +1 -0
- package/dist/std/stores/StagedWritable.js +84 -0
- package/dist/std/stores/index.d.ts +2 -1
- package/dist/std/stores/index.d.ts.map +1 -1
- package/dist/std/stores/index.js +2 -1
- package/dist/std/sync/Barrier.js +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -0
- package/package.json +5 -1
- package/src/blocks/Blocks.ts +1 -1
- package/src/bodyClass/BodyClass.ts +94 -0
- package/src/bodyClass/ClientBodyClass.ts +79 -0
- package/src/bodyClass/ServerBodyClass.ts +86 -0
- package/src/bodyClass/index.ts +1 -0
- package/src/bodyClass/utils.ts +118 -0
- package/src/cookies/ClientCookies.ts +41 -10
- package/src/cookies/Cookies.ts +70 -0
- package/src/cookies/ServerCookies.ts +9 -6
- package/src/cookies/index.ts +5 -29
- package/src/crelte.ts +12 -0
- package/src/index.ts +15 -1
- package/src/init/client.ts +26 -14
- package/src/init/server.ts +12 -3
- package/src/init/shared.ts +21 -6
- package/src/loadData/Globals.ts +1 -1
- package/src/loadData/entry.ts +12 -2
- package/src/node/index.ts +1 -1
- package/src/plugins/Events.ts +12 -1
- package/src/plugins/Plugins.ts +66 -1
- package/src/queries/index.ts +5 -1
- package/src/routing/route/Request.ts +11 -4
- package/src/routing/router/ClientRouter.ts +23 -14
- package/src/routing/router/Router.ts +8 -10
- package/src/server/CrelteServer.ts +4 -2
- package/src/server/queries/QueryGqlRoute.ts +3 -2
- package/src/server/queries/routes.ts +1 -0
- package/src/std/stores/StagedWritable.ts +96 -0
- package/src/std/stores/index.ts +2 -1
- package/src/std/sync/Barrier.ts +1 -1
- package/src/utils.ts +15 -0
package/dist/blocks/Blocks.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare class BlockModules {
|
|
|
58
58
|
* );
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export declare function blockModules(modules: Record<string,
|
|
61
|
+
export declare function blockModules(modules: Record<string, (() => Promise<any>) | Module>, opts?: BlockModulesOptions): BlockModules;
|
|
62
62
|
/**
|
|
63
63
|
* Load blocks data
|
|
64
64
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Blocks.d.ts","sourceRoot":"","sources":["../../src/blocks/Blocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,WAAW,MAAM;IACtB,uBAAuB;IACvB,OAAO,EAAE,GAAG,CAAC;IAEb,kEAAkE;IAClE,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AC5B,YAAY,CAEd;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CACnC,EAAE,EAAE,aAAa,EACjB,MAAM,EAAE,GAAG,EAAE,EACb,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC,cAAc,CAAC,CAMzB;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC9B,MAAM,EAAE,GAAG,EAAE,EACb,OAAO,EAAE,YAAY,GACnB,OAAO,CAAC,cAAc,CAAC,CAazB;AAED,MAAM,CAAC,OAAO,OAAO,cAAc;IAClC,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAEjB,MAAM,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAMjD,QAAQ,CAAC,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBhD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,IAAI;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EAAE;CAclC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import StagedWritable from '../std/stores/StagedWritable.js';
|
|
2
|
+
export default class BodyClass {
|
|
3
|
+
private inner;
|
|
4
|
+
private store;
|
|
5
|
+
constructor(inner: PlatformBodyClass, store?: StagedWritable<void>);
|
|
6
|
+
subscribe(fn: (val: BodyClass) => void, invalidate?: () => void): () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the body contains the given class
|
|
9
|
+
*/
|
|
10
|
+
contains(cls: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Adds the given classes to the body
|
|
13
|
+
*/
|
|
14
|
+
add(...classes: string[]): void;
|
|
15
|
+
/**
|
|
16
|
+
* Toggles the given class on the body
|
|
17
|
+
*
|
|
18
|
+
* ## Warning
|
|
19
|
+
* toggle without `force` should almost never be used
|
|
20
|
+
* on the server. If you call this for example in loadData
|
|
21
|
+
* the server will add the class and the client will the remove
|
|
22
|
+
* it.
|
|
23
|
+
*/
|
|
24
|
+
toggle(cls: string, force?: boolean): void;
|
|
25
|
+
/**
|
|
26
|
+
* Removes the given classes from the body
|
|
27
|
+
*/
|
|
28
|
+
remove(...classes: string[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the class for the given variant removing the old class for that
|
|
31
|
+
* variant, if cls is null it will remove the variant class
|
|
32
|
+
*
|
|
33
|
+
* If you just have like a dark or light mode and only for the dark mode a
|
|
34
|
+
* class, **prefer** `toggle('dark', isDarkMode)` over
|
|
35
|
+
* `setVariant('mode', isDarkMode ? 'dark' : null)`
|
|
36
|
+
*
|
|
37
|
+
* ## Note
|
|
38
|
+
* The variant name is only used for the internal state management
|
|
39
|
+
* and has no inpact on the actual class name
|
|
40
|
+
*/
|
|
41
|
+
setVariant(variant: string, cls: string | null): void;
|
|
42
|
+
/** @hidden */
|
|
43
|
+
z_toRequest(): BodyClass;
|
|
44
|
+
/** @hidden */
|
|
45
|
+
z_render(): void;
|
|
46
|
+
}
|
|
47
|
+
export interface PlatformBodyClass {
|
|
48
|
+
contains(cls: string): boolean;
|
|
49
|
+
add(...classes: string[]): void;
|
|
50
|
+
toggle(cls: string, force?: boolean): boolean;
|
|
51
|
+
remove(...classes: string[]): void;
|
|
52
|
+
setVariant(variant: string, cls: string | null): boolean;
|
|
53
|
+
toRequest(): PlatformBodyClass;
|
|
54
|
+
render?: () => void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=BodyClass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BodyClass.d.ts","sourceRoot":"","sources":["../../src/bodyClass/BodyClass.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAE7D,MAAM,CAAC,OAAO,OAAO,SAAS;IAC7B,O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 -0,0 +1,70 @@
|
|
|
1
|
+
import StagedWritable from '../std/stores/StagedWritable.js';
|
|
2
|
+
export default class BodyClass {
|
|
3
|
+
inner;
|
|
4
|
+
store;
|
|
5
|
+
constructor(inner, store) {
|
|
6
|
+
this.inner = inner;
|
|
7
|
+
this.store = store ?? new StagedWritable(void 0);
|
|
8
|
+
}
|
|
9
|
+
subscribe(fn, invalidate) {
|
|
10
|
+
return this.store.subscribe(() => fn(this), invalidate);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the body contains the given class
|
|
14
|
+
*/
|
|
15
|
+
contains(cls) {
|
|
16
|
+
return this.inner.contains(cls);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Adds the given classes to the body
|
|
20
|
+
*/
|
|
21
|
+
add(...classes) {
|
|
22
|
+
this.inner.add(...classes);
|
|
23
|
+
this.store.set();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Toggles the given class on the body
|
|
27
|
+
*
|
|
28
|
+
* ## Warning
|
|
29
|
+
* toggle without `force` should almost never be used
|
|
30
|
+
* on the server. If you call this for example in loadData
|
|
31
|
+
* the server will add the class and the client will the remove
|
|
32
|
+
* it.
|
|
33
|
+
*/
|
|
34
|
+
toggle(cls, force) {
|
|
35
|
+
if (this.inner.toggle(cls, force))
|
|
36
|
+
this.store.set();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Removes the given classes from the body
|
|
40
|
+
*/
|
|
41
|
+
remove(...classes) {
|
|
42
|
+
this.inner.remove(...classes);
|
|
43
|
+
this.store.set();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sets the class for the given variant removing the old class for that
|
|
47
|
+
* variant, if cls is null it will remove the variant class
|
|
48
|
+
*
|
|
49
|
+
* If you just have like a dark or light mode and only for the dark mode a
|
|
50
|
+
* class, **prefer** `toggle('dark', isDarkMode)` over
|
|
51
|
+
* `setVariant('mode', isDarkMode ? 'dark' : null)`
|
|
52
|
+
*
|
|
53
|
+
* ## Note
|
|
54
|
+
* The variant name is only used for the internal state management
|
|
55
|
+
* and has no inpact on the actual class name
|
|
56
|
+
*/
|
|
57
|
+
setVariant(variant, cls) {
|
|
58
|
+
if (this.inner.setVariant(variant, cls))
|
|
59
|
+
this.store.set();
|
|
60
|
+
}
|
|
61
|
+
/** @hidden */
|
|
62
|
+
z_toRequest() {
|
|
63
|
+
return new BodyClass(this.inner.toRequest(), this.store.stage());
|
|
64
|
+
}
|
|
65
|
+
/** @hidden */
|
|
66
|
+
z_render() {
|
|
67
|
+
this.inner.render?.();
|
|
68
|
+
this.store.commit();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import SsrCache from '../ssr/SsrCache.js';
|
|
2
|
+
import { PlatformBodyClass } from './BodyClass.js';
|
|
3
|
+
import { ClassSet, Variants } from './utils.js';
|
|
4
|
+
export default class ClientBodyClass implements PlatformBodyClass {
|
|
5
|
+
private variants;
|
|
6
|
+
private inner;
|
|
7
|
+
constructor(variants: Variants, inner?: ClassSet);
|
|
8
|
+
static fromSsrCache(ssrCache: SsrCache): ClientBodyClass;
|
|
9
|
+
contains(cls: string): boolean;
|
|
10
|
+
add(...classes: string[]): void;
|
|
11
|
+
toggle(cls: string, force?: boolean): boolean;
|
|
12
|
+
remove(...classes: string[]): void;
|
|
13
|
+
setVariant(variant: string, cls: string | null): boolean;
|
|
14
|
+
toRequest(): ClientBodyClass;
|
|
15
|
+
render(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=ClientBodyClass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientBodyClass.d.ts","sourceRoot":"","sources":["../../src/bodyClass/ClientBodyClass.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAsB,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEpE,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,iBAAiB;IAChE,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,KAAK,CAAkB;gBAEnB,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,QAAQ;IAKhD,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,eAAe;IAKxD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAK9B,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAM/B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO;IAe7C,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAKlC,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAWxD,SAAS,IAAI,eAAe;IAK5B,MAAM,IAAI,IAAI;CAQd"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ClassSet, ssrCacheToVariants } from './utils.js';
|
|
2
|
+
export default class ClientBodyClass {
|
|
3
|
+
variants;
|
|
4
|
+
// during the request store the classes here
|
|
5
|
+
inner;
|
|
6
|
+
constructor(variants, inner) {
|
|
7
|
+
this.variants = variants;
|
|
8
|
+
this.inner = inner ?? null;
|
|
9
|
+
}
|
|
10
|
+
static fromSsrCache(ssrCache) {
|
|
11
|
+
const variants = ssrCacheToVariants(ssrCache);
|
|
12
|
+
return new ClientBodyClass(variants);
|
|
13
|
+
}
|
|
14
|
+
contains(cls) {
|
|
15
|
+
if (this.inner)
|
|
16
|
+
return this.inner.has(cls);
|
|
17
|
+
return cl().contains(cls);
|
|
18
|
+
}
|
|
19
|
+
add(...classes) {
|
|
20
|
+
if (this.inner)
|
|
21
|
+
classes.forEach(cls => this.inner.add(cls));
|
|
22
|
+
else
|
|
23
|
+
cl().add(...classes);
|
|
24
|
+
}
|
|
25
|
+
// returns true if the value was changed
|
|
26
|
+
toggle(cls, force) {
|
|
27
|
+
const exists = this.contains(cls);
|
|
28
|
+
const shouldExist = typeof force === 'boolean' ? force : !exists;
|
|
29
|
+
const changed = shouldExist !== exists;
|
|
30
|
+
if (this.inner) {
|
|
31
|
+
if (shouldExist)
|
|
32
|
+
this.inner.add(cls);
|
|
33
|
+
else
|
|
34
|
+
this.inner.delete(cls);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
cl().toggle(cls, force);
|
|
38
|
+
}
|
|
39
|
+
return changed;
|
|
40
|
+
}
|
|
41
|
+
remove(...classes) {
|
|
42
|
+
if (this.inner)
|
|
43
|
+
classes.forEach(cls => this.inner.delete(cls));
|
|
44
|
+
else
|
|
45
|
+
cl().remove(...classes);
|
|
46
|
+
}
|
|
47
|
+
setVariant(variant, cls) {
|
|
48
|
+
if (this.inner)
|
|
49
|
+
return this.inner.setVariant(variant, cls);
|
|
50
|
+
const { remove, add } = this.variants.set(variant, cls);
|
|
51
|
+
if (remove)
|
|
52
|
+
cl().remove(remove);
|
|
53
|
+
if (add)
|
|
54
|
+
cl().add(add);
|
|
55
|
+
return !!remove || !!add;
|
|
56
|
+
}
|
|
57
|
+
toRequest() {
|
|
58
|
+
const inner = new ClassSet(cl(), this.variants.entries(), true);
|
|
59
|
+
return new ClientBodyClass(this.variants, inner);
|
|
60
|
+
}
|
|
61
|
+
render() {
|
|
62
|
+
if (!this.inner)
|
|
63
|
+
throw new Error('call toRequest first');
|
|
64
|
+
const inner = this.inner;
|
|
65
|
+
this.inner = null;
|
|
66
|
+
inner.applyHistory(this);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function cl() {
|
|
70
|
+
return document.body.classList;
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import SsrCache from '../ssr/SsrCache.js';
|
|
2
|
+
import { PlatformBodyClass } from './BodyClass.js';
|
|
3
|
+
export default class ServerBodyClass implements PlatformBodyClass {
|
|
4
|
+
private inner;
|
|
5
|
+
constructor();
|
|
6
|
+
contains(cls: string): boolean;
|
|
7
|
+
add(...classes: string[]): void;
|
|
8
|
+
toggle(cls: string, force?: boolean): boolean;
|
|
9
|
+
remove(...classes: string[]): void;
|
|
10
|
+
/**
|
|
11
|
+
* @returns Returns true if the value was changed
|
|
12
|
+
*/
|
|
13
|
+
setVariant(variant: string, cls: string | null): boolean;
|
|
14
|
+
toRequest(): ServerBodyClass;
|
|
15
|
+
z_populateSsrCache(ssrCache: SsrCache): void;
|
|
16
|
+
z_processHtmlTemplate(html: string): string;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ServerBodyClass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServerBodyClass.d.ts","sourceRoot":"","sources":["../../src/bodyClass/ServerBodyClass.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,MAAM,CAAC,OAAO,OAAO,eAAgB,YAAW,iBAAiB;IAChE,OAAO,CAAC,KAAK,CAAW;;IAMxB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAI9B,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAK/B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO;IAqB7C,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAKlC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAIxD,SAAS,IAAI,eAAe;IAK5B,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI5C,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAa3C"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ClassSet, variantsToSsrCache } from './utils.js';
|
|
2
|
+
export default class ServerBodyClass {
|
|
3
|
+
inner;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.inner = new ClassSet();
|
|
6
|
+
}
|
|
7
|
+
contains(cls) {
|
|
8
|
+
return this.inner.has(cls);
|
|
9
|
+
}
|
|
10
|
+
add(...classes) {
|
|
11
|
+
validate(classes);
|
|
12
|
+
classes.forEach(cls => this.inner.add(cls));
|
|
13
|
+
}
|
|
14
|
+
toggle(cls, force) {
|
|
15
|
+
validate([cls]);
|
|
16
|
+
if (import.meta.env.DEV && typeof force !== 'boolean') {
|
|
17
|
+
console.warn('Using toggle without force on the server can lead ' +
|
|
18
|
+
'to unexpected results. Because in a loadData the server will add it ' +
|
|
19
|
+
'and the client will afterwards remove it.');
|
|
20
|
+
}
|
|
21
|
+
const exists = this.inner.has(cls);
|
|
22
|
+
const shouldExist = typeof force === 'boolean' ? force : !exists;
|
|
23
|
+
const changed = shouldExist !== exists;
|
|
24
|
+
if (shouldExist)
|
|
25
|
+
this.inner.add(cls);
|
|
26
|
+
else
|
|
27
|
+
this.inner.delete(cls);
|
|
28
|
+
return changed;
|
|
29
|
+
}
|
|
30
|
+
remove(...classes) {
|
|
31
|
+
validate(classes);
|
|
32
|
+
classes.forEach(cls => this.inner.delete(cls));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @returns Returns true if the value was changed
|
|
36
|
+
*/
|
|
37
|
+
setVariant(variant, cls) {
|
|
38
|
+
return this.inner.setVariant(variant, cls);
|
|
39
|
+
}
|
|
40
|
+
toRequest() {
|
|
41
|
+
// no second request should ever start on the server
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
z_populateSsrCache(ssrCache) {
|
|
45
|
+
variantsToSsrCache(this.inner.z_variants, ssrCache);
|
|
46
|
+
}
|
|
47
|
+
z_processHtmlTemplate(html) {
|
|
48
|
+
const SEARCH_STR = '<!--body-class-->';
|
|
49
|
+
if (this.inner.length && !html.includes(SEARCH_STR)) {
|
|
50
|
+
throw new Error('index.html needs to contain `class="<!--body-class-->"`');
|
|
51
|
+
}
|
|
52
|
+
return html.replace(SEARCH_STR, Array.from(this.inner.classes()).join(' '));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function validate(classes) {
|
|
56
|
+
for (const cls of classes) {
|
|
57
|
+
if (cls.includes(' ')) {
|
|
58
|
+
throw new Error(`Invalid class name "${cls}". Class names must not contain spaces.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bodyClass/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BodyClass } from './BodyClass.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import SsrCache from '../ssr/SsrCache.js';
|
|
2
|
+
export type HistoryClassSet = {
|
|
3
|
+
add(cls: string): void;
|
|
4
|
+
remove(cls: string): void;
|
|
5
|
+
setVariant(variant: string, cls: string | null): void;
|
|
6
|
+
};
|
|
7
|
+
export declare class ClassSet {
|
|
8
|
+
private _classes;
|
|
9
|
+
/** @hidden */
|
|
10
|
+
z_variants: Variants;
|
|
11
|
+
private history;
|
|
12
|
+
constructor(classes?: Iterable<string>, variants?: Iterable<[string, string]>, history?: boolean);
|
|
13
|
+
classes(): Iterable<string>;
|
|
14
|
+
get length(): number;
|
|
15
|
+
has(cls: string): boolean;
|
|
16
|
+
add(cls: string): void;
|
|
17
|
+
delete(cls: string): void;
|
|
18
|
+
/**
|
|
19
|
+
* @returns Returns true if the value was changed
|
|
20
|
+
*/
|
|
21
|
+
setVariant(variant: string, cls: string | null): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Fails if no history is active.
|
|
24
|
+
*/
|
|
25
|
+
applyHistory(cl: HistoryClassSet): void;
|
|
26
|
+
}
|
|
27
|
+
export type VariantSetReturn = {
|
|
28
|
+
remove?: string;
|
|
29
|
+
add?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare class Variants {
|
|
32
|
+
private inner;
|
|
33
|
+
constructor(entries?: Iterable<[string, string]>);
|
|
34
|
+
set(variant: string, cls: string | null): VariantSetReturn;
|
|
35
|
+
entries(): Iterable<[string, string]>;
|
|
36
|
+
}
|
|
37
|
+
export declare function ssrCacheToVariants(ssrCache: SsrCache): Variants;
|
|
38
|
+
export declare function variantsToSsrCache(variants: Variants, ssrCache: SsrCache): void;
|
|
39
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/bodyClass/utils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,oBAAoB,CAAC;AAE1C,MAAM,MAAM,eAAe,GAAG;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACtD,CAAC;AAEF,qBAAa,QAAQ;IACpB,OAAO,CAAC,QAAQ,CAAc;IAC9B,cAAc;IACd,UAAU,EAAE,QAAQ,CAAC;IACrB,OAAO,CAAC,OAAO,CAA2C;gBAGzD,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACrC,OAAO,GAAE,OAAe;IAOzB,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC;IAI3B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKtB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAKzB;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAaxD;;OAEG;IACH,YAAY,CAAC,EAAE,EAAE,eAAe,GAAG,IAAI;CAGvC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,qBAAa,QAAQ;IAEpB,OAAO,CAAC,KAAK,CAAsB;gBAEvB,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAIhD,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB;IAkB1D,OAAO,IAAI,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAGrC;AAGD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAE/D;AAGD,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,GAChB,IAAI,CAEN"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export class ClassSet {
|
|
2
|
+
_classes;
|
|
3
|
+
/** @hidden */
|
|
4
|
+
z_variants;
|
|
5
|
+
history;
|
|
6
|
+
constructor(classes, variants, history = false) {
|
|
7
|
+
this._classes = new Set(classes);
|
|
8
|
+
this.z_variants = new Variants();
|
|
9
|
+
this.history = history ? [] : null;
|
|
10
|
+
}
|
|
11
|
+
classes() {
|
|
12
|
+
return this._classes;
|
|
13
|
+
}
|
|
14
|
+
get length() {
|
|
15
|
+
return this._classes.size;
|
|
16
|
+
}
|
|
17
|
+
has(cls) {
|
|
18
|
+
return this._classes.has(cls);
|
|
19
|
+
}
|
|
20
|
+
add(cls) {
|
|
21
|
+
this._classes.add(cls);
|
|
22
|
+
if (this.history)
|
|
23
|
+
this.history.push(c => c.add(cls));
|
|
24
|
+
}
|
|
25
|
+
delete(cls) {
|
|
26
|
+
this._classes.delete(cls);
|
|
27
|
+
if (this.history)
|
|
28
|
+
this.history.push(c => c.remove(cls));
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @returns Returns true if the value was changed
|
|
32
|
+
*/
|
|
33
|
+
setVariant(variant, cls) {
|
|
34
|
+
const { remove, add } = this.z_variants.set(variant, cls);
|
|
35
|
+
if (remove)
|
|
36
|
+
this.delete(remove);
|
|
37
|
+
if (add)
|
|
38
|
+
this.add(add);
|
|
39
|
+
const changed = !!remove || !!add;
|
|
40
|
+
if (this.history)
|
|
41
|
+
this.history.push(c => c.setVariant(variant, cls));
|
|
42
|
+
return changed;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Fails if no history is active.
|
|
46
|
+
*/
|
|
47
|
+
applyHistory(cl) {
|
|
48
|
+
this.history.forEach(fn => fn(cl));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class Variants {
|
|
52
|
+
// list of active variant classes
|
|
53
|
+
inner;
|
|
54
|
+
constructor(entries) {
|
|
55
|
+
this.inner = new Map(entries);
|
|
56
|
+
}
|
|
57
|
+
set(variant, cls) {
|
|
58
|
+
const current = this.inner.get(variant) ?? null;
|
|
59
|
+
if (current === cls)
|
|
60
|
+
return {};
|
|
61
|
+
const obj = {};
|
|
62
|
+
if (current)
|
|
63
|
+
obj.remove = current;
|
|
64
|
+
if (cls) {
|
|
65
|
+
obj.add = cls;
|
|
66
|
+
this.inner.set(variant, cls);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.inner.delete(variant);
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
}
|
|
73
|
+
entries() {
|
|
74
|
+
return this.inner.entries();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// separate function for tree shaking
|
|
78
|
+
export function ssrCacheToVariants(ssrCache) {
|
|
79
|
+
return new Variants(ssrCache.get('BODY_CLASS_VAR'));
|
|
80
|
+
}
|
|
81
|
+
// separate function for tree shaking
|
|
82
|
+
export function variantsToSsrCache(variants, ssrCache) {
|
|
83
|
+
ssrCache.set('BODY_CLASS_VAR', Array.from(variants.entries()));
|
|
84
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { PlatformCookies, RemoveOptions, SetOptions } from './Cookies.js';
|
|
2
|
+
import { SetCookie } from './utils.js';
|
|
3
|
+
export default class ClientCookies implements PlatformCookies {
|
|
4
|
+
private inner;
|
|
5
|
+
private setCookies;
|
|
6
|
+
constructor(inner?: Map<string, string>, setCookies?: Map<string, SetCookie>);
|
|
4
7
|
get(name: string): string | null;
|
|
5
8
|
set(name: string, value: string, opts?: SetOptions): void;
|
|
6
9
|
remove(name: string, opts?: RemoveOptions): void;
|
|
10
|
+
toRequest(): ClientCookies;
|
|
11
|
+
render(): void;
|
|
7
12
|
}
|
|
8
13
|
//# sourceMappingURL=ClientCookies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientCookies.d.ts","sourceRoot":"","sources":["../../src/cookies/ClientCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ClientCookies.d.ts","sourceRoot":"","sources":["../../src/cookies/ClientCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAgB,SAAS,EAAqB,MAAM,YAAY,CAAC;AAExE,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,eAAe;IAC5D,OAAO,CAAC,KAAK,CAA6B;IAC1C,OAAO,CAAC,UAAU,CAAgC;gBAGjD,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC;IAMpC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAchC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI;IAOzD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,IAAI;IAIhD,SAAS,IAAI,aAAa;IAI1B,MAAM,IAAI,IAAI;CAUd"}
|
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import { parseCookies, setCookieToString } from './utils.js';
|
|
2
|
-
// the philosophy here is that document.cookie is the source of truth
|
|
3
|
-
// so we don't cache cookies here
|
|
4
|
-
// if this changes, modify init/client.ts
|
|
5
2
|
export default class ClientCookies {
|
|
6
|
-
|
|
3
|
+
inner;
|
|
4
|
+
setCookies;
|
|
5
|
+
constructor(inner, setCookies) {
|
|
6
|
+
this.inner = inner ?? null;
|
|
7
|
+
this.setCookies = setCookies ?? null;
|
|
8
|
+
}
|
|
7
9
|
get(name) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
if (!this.inner || !this.setCookies) {
|
|
11
|
+
const cookies = getCookies();
|
|
12
|
+
return cookies.get(name) ?? null;
|
|
13
|
+
}
|
|
14
|
+
const setCookie = this.setCookies.get(name);
|
|
15
|
+
if (setCookie) {
|
|
16
|
+
return (setCookie.maxAge ?? 1) > 0 ? setCookie.value : null;
|
|
17
|
+
}
|
|
18
|
+
return this.inner.get(name) ?? null;
|
|
10
19
|
}
|
|
11
20
|
set(name, value, opts) {
|
|
12
21
|
const setCookie = { name, value, path: '/', ...opts };
|
|
13
|
-
|
|
22
|
+
if (this.setCookies)
|
|
23
|
+
this.setCookies.set(name, setCookie);
|
|
24
|
+
else
|
|
25
|
+
document.cookie = setCookieToString(setCookie);
|
|
14
26
|
}
|
|
15
27
|
remove(name, opts) {
|
|
16
28
|
this.set(name, '', { ...opts, maxAge: 0 });
|
|
17
29
|
}
|
|
30
|
+
toRequest() {
|
|
31
|
+
return new ClientCookies(getCookies(), new Map());
|
|
32
|
+
}
|
|
33
|
+
render() {
|
|
34
|
+
if (!this.setCookies)
|
|
35
|
+
throw new Error('call toRequest first');
|
|
36
|
+
for (const setCookie of this.setCookies.values()) {
|
|
37
|
+
document.cookie = setCookieToString(setCookie);
|
|
38
|
+
}
|
|
39
|
+
this.inner = null;
|
|
40
|
+
this.setCookies = null;
|
|
41
|
+
}
|
|
18
42
|
}
|
|
19
43
|
function getCookies() {
|
|
20
44
|
return parseCookies(document.cookie);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import StagedWritable from '../std/stores/StagedWritable.js';
|
|
2
|
+
export type SetOptions = {
|
|
3
|
+
maxAge?: number;
|
|
4
|
+
path?: string;
|
|
5
|
+
domain?: string;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
httpOnly?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type RemoveOptions = Omit<SetOptions, 'maxAge'>;
|
|
10
|
+
export default class Cookies {
|
|
11
|
+
private inner;
|
|
12
|
+
private store;
|
|
13
|
+
constructor(inner: PlatformCookies, store?: StagedWritable<void>);
|
|
14
|
+
subscribe(fn: (val: Cookies) => void, invalidate?: () => void): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* returns the value of the cookie
|
|
17
|
+
*/
|
|
18
|
+
get(name: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* sets the value of the cookie
|
|
21
|
+
*
|
|
22
|
+
* #### Note
|
|
23
|
+
* path defaults to '/'
|
|
24
|
+
*/
|
|
25
|
+
set(name: string, value: string, opts?: SetOptions): void;
|
|
26
|
+
/**
|
|
27
|
+
* removes the cookie
|
|
28
|
+
*/
|
|
29
|
+
remove(name: string, opts?: RemoveOptions): void;
|
|
30
|
+
/** @hidden */
|
|
31
|
+
z_toRequest(): Cookies;
|
|
32
|
+
/** @hidden */
|
|
33
|
+
z_render(): void;
|
|
34
|
+
}
|
|
35
|
+
export interface PlatformCookies {
|
|
36
|
+
get(name: string): string | null;
|
|
37
|
+
set(name: string, value: string, opts?: SetOptions): void;
|
|
38
|
+
remove(name: string, opts?: RemoveOptions): void;
|
|
39
|
+
toRequest(): PlatformCookies;
|
|
40
|
+
render?: () => void;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=Cookies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cookies.d.ts","sourceRoot":"","sources":["../../src/cookies/Cookies.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iCAAiC,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAEvD,MAAM,CAAC,OAAO,OAAO,OAAO;IAC3B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,KAAK,CAAuB;gBAExB,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC;IAKhE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAI1E;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIhC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI;IAKzD;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,IAAI;IAKhD,cAAc;IACd,WAAW,IAAI,OAAO;IAItB,cAAc;IACd,QAAQ,IAAI,IAAI;CAIhB;AAED,MAAM,WAAW,eAAe;IAC/B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACjC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1D,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IACjD,SAAS,IAAI,eAAe,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import StagedWritable from '../std/stores/StagedWritable.js';
|
|
2
|
+
export default class Cookies {
|
|
3
|
+
inner;
|
|
4
|
+
store;
|
|
5
|
+
constructor(inner, store) {
|
|
6
|
+
this.inner = inner;
|
|
7
|
+
this.store = store ?? new StagedWritable(void 0);
|
|
8
|
+
}
|
|
9
|
+
subscribe(fn, invalidate) {
|
|
10
|
+
return this.store.subscribe(() => fn(this), invalidate);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* returns the value of the cookie
|
|
14
|
+
*/
|
|
15
|
+
get(name) {
|
|
16
|
+
return this.inner.get(name);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* sets the value of the cookie
|
|
20
|
+
*
|
|
21
|
+
* #### Note
|
|
22
|
+
* path defaults to '/'
|
|
23
|
+
*/
|
|
24
|
+
set(name, value, opts) {
|
|
25
|
+
this.inner.set(name, value, opts);
|
|
26
|
+
this.store.set();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* removes the cookie
|
|
30
|
+
*/
|
|
31
|
+
remove(name, opts) {
|
|
32
|
+
this.inner.remove(name, opts);
|
|
33
|
+
this.store.set();
|
|
34
|
+
}
|
|
35
|
+
/** @hidden */
|
|
36
|
+
z_toRequest() {
|
|
37
|
+
return new Cookies(this.inner.toRequest(), this.store.stage());
|
|
38
|
+
}
|
|
39
|
+
/** @hidden */
|
|
40
|
+
z_render() {
|
|
41
|
+
this.inner.render?.();
|
|
42
|
+
this.store.commit();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PlatformCookies, RemoveOptions, SetOptions } from './Cookies.js';
|
|
2
2
|
import { type SetCookie } from './utils.js';
|
|
3
3
|
/**
|
|
4
4
|
* #### Warning
|
|
5
5
|
* This is not stable and should only be used internally by crelte
|
|
6
6
|
*/
|
|
7
|
-
export default class ServerCookies implements
|
|
7
|
+
export default class ServerCookies implements PlatformCookies {
|
|
8
8
|
requestCookies: Map<string, string>;
|
|
9
9
|
setCookies: Map<string, SetCookie>;
|
|
10
10
|
constructor(headers: Headers);
|
|
11
11
|
get(name: string): string | null;
|
|
12
12
|
set(name: string, value: string, opts?: SetOptions): void;
|
|
13
13
|
remove(name: string, opts?: RemoveOptions): void;
|
|
14
|
+
toRequest(): ServerCookies;
|
|
14
15
|
_populateHeaders(headers: Headers): void;
|
|
15
16
|
}
|
|
16
17
|
//# sourceMappingURL=ServerCookies.d.ts.map
|