kiru 0.51.0-preview.1 → 0.51.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.
Files changed (62) hide show
  1. package/dist/constants.d.ts.map +1 -1
  2. package/dist/constants.js +1 -0
  3. package/dist/constants.js.map +1 -1
  4. package/dist/router/cache.d.ts +71 -0
  5. package/dist/router/cache.d.ts.map +1 -0
  6. package/dist/router/cache.js +325 -0
  7. package/dist/router/cache.js.map +1 -0
  8. package/dist/router/client/index.d.ts.map +1 -1
  9. package/dist/router/client/index.js +62 -1
  10. package/dist/router/client/index.js.map +1 -1
  11. package/dist/router/context.d.ts +8 -0
  12. package/dist/router/context.d.ts.map +1 -1
  13. package/dist/router/context.js.map +1 -1
  14. package/dist/router/fileRouterController.d.ts +1 -0
  15. package/dist/router/fileRouterController.d.ts.map +1 -1
  16. package/dist/router/fileRouterController.js +124 -36
  17. package/dist/router/fileRouterController.js.map +1 -1
  18. package/dist/router/globals.d.ts +4 -0
  19. package/dist/router/globals.d.ts.map +1 -1
  20. package/dist/router/globals.js +3 -0
  21. package/dist/router/globals.js.map +1 -1
  22. package/dist/router/head.d.ts +4 -36
  23. package/dist/router/head.d.ts.map +1 -1
  24. package/dist/router/head.js +33 -53
  25. package/dist/router/head.js.map +1 -1
  26. package/dist/router/index.d.ts +57 -3
  27. package/dist/router/index.d.ts.map +1 -1
  28. package/dist/router/index.js +67 -3
  29. package/dist/router/index.js.map +1 -1
  30. package/dist/router/server/index.d.ts +1 -3
  31. package/dist/router/server/index.d.ts.map +1 -1
  32. package/dist/router/server/index.js +23 -20
  33. package/dist/router/server/index.js.map +1 -1
  34. package/dist/router/types.d.ts +31 -3
  35. package/dist/router/types.d.ts.map +1 -1
  36. package/dist/router/types.internal.d.ts +9 -8
  37. package/dist/router/types.internal.d.ts.map +1 -1
  38. package/dist/router/utils/index.d.ts +1 -6
  39. package/dist/router/utils/index.d.ts.map +1 -1
  40. package/dist/router/utils/index.js +1 -1
  41. package/dist/router/utils/index.js.map +1 -1
  42. package/dist/types.dom.d.ts +2 -1
  43. package/dist/types.dom.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/src/constants.ts +1 -0
  46. package/src/router/cache.ts +385 -0
  47. package/src/router/client/index.ts +81 -1
  48. package/src/router/context.ts +8 -0
  49. package/src/router/fileRouterController.ts +140 -47
  50. package/src/router/globals.ts +5 -0
  51. package/src/router/head.ts +44 -54
  52. package/src/router/index.ts +70 -3
  53. package/src/router/server/index.ts +33 -24
  54. package/src/router/types.internal.ts +10 -8
  55. package/src/router/types.ts +43 -13
  56. package/src/router/utils/index.ts +1 -1
  57. package/src/types.dom.ts +5 -1
  58. package/dist/router/dev/index.d.ts +0 -2
  59. package/dist/router/dev/index.d.ts.map +0 -1
  60. package/dist/router/dev/index.js +0 -46
  61. package/dist/router/dev/index.js.map +0 -1
  62. package/src/router/dev/index.ts +0 -63
@@ -15,6 +15,7 @@ export interface FileRouterPreloadConfig {
15
15
  params: RouteParams
16
16
  query: RouteQuery
17
17
  route: string
18
+ cacheData: null | { value: unknown }
18
19
  }
19
20
 
20
21
  export interface FileRouterConfig {
@@ -91,25 +92,54 @@ export interface RouterState {
91
92
 
92
93
  type PageDataLoaderContext = RouterState & {}
93
94
 
95
+ export interface PageDataLoaderCacheConfig {
96
+ type: "memory" | "localStorage" | "sessionStorage"
97
+ ttl: number
98
+ }
99
+
94
100
  export type PageDataLoaderConfig<T = unknown> = {
95
101
  /**
96
102
  * The function to load the page data
97
103
  */
98
104
  load: (context: PageDataLoaderContext) => Promise<T>
105
+ } & (
106
+ | {
107
+ /**
108
+ * The mode to use for the page data loader
109
+ * @default "client"
110
+ * @description
111
+ * - **static**: The page data is loaded at build time and never updated
112
+ * - **client**: The page data is loaded upon navigation and updated on subsequent navigations
113
+ */
114
+ mode?: "client"
115
+ /**
116
+ * Enable transitions when swapping between "load", "error" and "data" states
117
+ */
118
+ transition?: boolean
99
119
 
100
- /**
101
- * The mode to use for the page data loader
102
- * @default "client"
103
- * @description
104
- * - **static**: The page data is loaded at build time and never updated
105
- * - **client**: The page data is loaded upon navigation and updated on subsequent navigations
106
- */
107
- mode?: "static" | "client"
108
- /**
109
- * Enable transitions when swapping between "load", "error" and "data" states (only when mode is "client")
110
- */
111
- transition?: boolean
112
- }
120
+ /**
121
+ * Configure caching for this loader
122
+ * @example
123
+ * ```ts
124
+ * cache: {
125
+ * type: "memory", // or "localStorage" / "sessionStorage"
126
+ * ttl: 1000 * 60 * 5, // 5 minutes
127
+ }
128
+ * ```
129
+ */
130
+ cache?: PageDataLoaderCacheConfig
131
+ }
132
+ | {
133
+ /**
134
+ * The mode to use for the page data loader
135
+ * @default "client"
136
+ * @description
137
+ * - **static**: The page data is loaded at build time and never updated
138
+ * - **client**: The page data is loaded upon navigation and updated on subsequent navigations
139
+ */
140
+ mode: "static"
141
+ }
142
+ )
113
143
 
114
144
  export interface PageConfig<T = unknown> {
115
145
  /**
@@ -65,7 +65,7 @@ function formatViteImportMap(
65
65
  load: map[key],
66
66
  specificity,
67
67
  segments,
68
- filePath: key,
68
+ absolutePath: key,
69
69
  }
70
70
 
71
71
  return {
package/src/types.dom.ts CHANGED
@@ -365,7 +365,7 @@ declare global {
365
365
  bivarianceHack(event: E): void
366
366
  }["bivarianceHack"]
367
367
 
368
- interface BaseEventHandler<T extends Element = Element>
368
+ interface BaseEvent<T extends Element = Element>
369
369
  extends DOMEvent<Event, T> {}
370
370
 
371
371
  interface AnimationEvent<T extends Element = Element>
@@ -413,6 +413,10 @@ declare global {
413
413
  interface WheelEvent<T extends Element = Element>
414
414
  extends DOMEvent<NativeWheelEvent, T> {}
415
415
 
416
+ type BaseEventHandler<T extends Element = Element> = EventHandler<
417
+ BaseEvent<T>
418
+ >
419
+
416
420
  type ClipboardEventHandler<T extends Element = Element> = EventHandler<
417
421
  ClipboardEvent<T>
418
422
  >
@@ -1,2 +0,0 @@
1
- export declare function onLoadedDev(): void;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/router/dev/index.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,SAO1B"}
@@ -1,46 +0,0 @@
1
- import { __DEV__ } from "../../env.js";
2
- export function onLoadedDev() {
3
- if (!__DEV__) {
4
- throw new Error("onLoadedDev should not have been included in production build.");
5
- }
6
- clean();
7
- }
8
- function clean() {
9
- let isCleaned = true;
10
- const VITE_ID = "data-vite-dev-id";
11
- const injectedByVite = [
12
- ...document.querySelectorAll(`style[${VITE_ID}]`),
13
- ].map((style) => style.getAttribute(VITE_ID));
14
- const suffix = "?temp";
15
- const injectedByKiru = [
16
- ...document.querySelectorAll(`link[rel="stylesheet"][type="text/css"][href$="${suffix}"]`),
17
- ];
18
- injectedByKiru.forEach((linkKiru) => {
19
- const href = linkKiru.getAttribute("href");
20
- let filePathAbsoluteUserRootDir = href.slice(0, -suffix.length);
21
- const prefix = "/@fs/";
22
- if (filePathAbsoluteUserRootDir.startsWith(prefix))
23
- filePathAbsoluteUserRootDir = filePathAbsoluteUserRootDir.slice(prefix.length);
24
- if (injectedByVite.some((filePathAbsoluteFilesystem) => filePathAbsoluteFilesystem.endsWith(filePathAbsoluteUserRootDir))) {
25
- linkKiru.remove();
26
- }
27
- else {
28
- isCleaned = false;
29
- }
30
- });
31
- return isCleaned;
32
- }
33
- function removeInjectedStyles() {
34
- let sleep = 2;
35
- function runClean() {
36
- if (clean())
37
- return;
38
- if (sleep < 1000) {
39
- sleep *= 2;
40
- }
41
- setTimeout(runClean, sleep);
42
- }
43
- setTimeout(runClean, sleep);
44
- }
45
- removeInjectedStyles();
46
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/router/dev/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC,OAAO,EA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K,GAAG,CAAC,CAAA;IAEb,SAAS,QAAQ;QACf,IAAI,KAAK,EAAE;YAAE,OAAM;QAEnB,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;YACjB,KAAK,IAAI,CAAC,CAAA;QACZ,CAAC;QACD,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC7B,CAAC;IAED,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC;AAED,oBAAoB,EAAE,CAAA"}
@@ -1,63 +0,0 @@
1
- import { __DEV__ } from "../../env.js"
2
-
3
- export function onLoadedDev() {
4
- if (!__DEV__) {
5
- throw new Error(
6
- "onLoadedDev should not have been included in production build."
7
- )
8
- }
9
- clean()
10
- }
11
-
12
- function clean() {
13
- let isCleaned = true
14
- const VITE_ID = "data-vite-dev-id"
15
- const injectedByVite = [
16
- ...document.querySelectorAll(`style[${VITE_ID}]`),
17
- ].map((style) => style.getAttribute(VITE_ID))
18
-
19
- const suffix = "?temp"
20
- const injectedByKiru = [
21
- ...document.querySelectorAll(
22
- `link[rel="stylesheet"][type="text/css"][href$="${suffix}"]`
23
- ),
24
- ]
25
-
26
- injectedByKiru.forEach((linkKiru) => {
27
- const href = linkKiru.getAttribute("href")!
28
- let filePathAbsoluteUserRootDir = href.slice(0, -suffix.length)
29
- const prefix = "/@fs/"
30
- if (filePathAbsoluteUserRootDir.startsWith(prefix))
31
- filePathAbsoluteUserRootDir = filePathAbsoluteUserRootDir.slice(
32
- prefix.length
33
- )
34
-
35
- if (
36
- injectedByVite.some((filePathAbsoluteFilesystem) =>
37
- filePathAbsoluteFilesystem!.endsWith(filePathAbsoluteUserRootDir)
38
- )
39
- ) {
40
- linkKiru.remove()
41
- } else {
42
- isCleaned = false
43
- }
44
- })
45
- return isCleaned
46
- }
47
-
48
- function removeInjectedStyles() {
49
- let sleep = 2
50
-
51
- function runClean() {
52
- if (clean()) return
53
-
54
- if (sleep < 1000) {
55
- sleep *= 2
56
- }
57
- setTimeout(runClean, sleep)
58
- }
59
-
60
- setTimeout(runClean, sleep)
61
- }
62
-
63
- removeInjectedStyles()