@useavalon/avalon 0.1.10 → 0.1.12

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 (250) hide show
  1. package/README.md +54 -54
  2. package/dist/mod.js +1 -0
  3. package/dist/src/build/integration-bundler-plugin.js +1 -0
  4. package/dist/src/build/integration-config.js +1 -0
  5. package/dist/src/build/integration-detection-plugin.js +1 -0
  6. package/dist/src/build/integration-resolver-plugin.js +1 -0
  7. package/dist/src/build/island-manifest.js +1 -0
  8. package/dist/src/build/island-types-generator.js +5 -0
  9. package/dist/src/build/mdx-island-transform.js +2 -0
  10. package/dist/src/build/mdx-plugin.js +1 -0
  11. package/dist/src/build/page-island-transform.js +3 -0
  12. package/dist/src/build/prop-extractors/index.js +1 -0
  13. package/dist/src/build/prop-extractors/lit.js +1 -0
  14. package/dist/src/build/prop-extractors/qwik.js +1 -0
  15. package/dist/src/build/prop-extractors/solid.js +1 -0
  16. package/dist/src/build/prop-extractors/svelte.js +1 -0
  17. package/dist/src/build/prop-extractors/vue.js +1 -0
  18. package/dist/src/build/sidecar-file-manager.js +1 -0
  19. package/dist/src/build/sidecar-renderer.js +6 -0
  20. package/dist/src/client/adapters/index.js +1 -0
  21. package/dist/src/client/components.js +1 -0
  22. package/dist/src/client/css-hmr-handler.js +1 -0
  23. package/dist/src/client/framework-adapter.js +13 -0
  24. package/dist/src/client/hmr-coordinator.js +1 -0
  25. package/dist/src/client/hmr-error-overlay.js +214 -0
  26. package/dist/src/client/main.js +39 -0
  27. package/{src → dist/src}/client/types/framework-runtime.d.ts +68 -68
  28. package/{src → dist/src}/client/types/vite-hmr.d.ts +46 -46
  29. package/dist/src/client/types/vite-virtual-modules.d.ts +70 -0
  30. package/dist/src/components/Image.js +1 -0
  31. package/dist/src/components/IslandErrorBoundary.js +1 -0
  32. package/dist/src/components/LayoutDataErrorBoundary.js +1 -0
  33. package/dist/src/components/LayoutErrorBoundary.js +1 -0
  34. package/dist/src/components/PersistentIsland.js +1 -0
  35. package/dist/src/components/StreamingErrorBoundary.js +1 -0
  36. package/dist/src/components/StreamingLayout.js +29 -0
  37. package/dist/src/core/components/component-analyzer.js +1 -0
  38. package/dist/src/core/components/component-detection.js +5 -0
  39. package/dist/src/core/components/enhanced-framework-detector.js +1 -0
  40. package/dist/src/core/components/framework-registry.js +1 -0
  41. package/dist/src/core/content/mdx-processor.js +1 -0
  42. package/dist/src/core/integrations/index.js +1 -0
  43. package/dist/src/core/integrations/loader.js +1 -0
  44. package/dist/src/core/integrations/registry.js +1 -0
  45. package/dist/src/core/islands/island-persistence.js +1 -0
  46. package/dist/src/core/islands/island-state-serializer.js +1 -0
  47. package/dist/src/core/islands/persistent-island-context.js +1 -0
  48. package/dist/src/core/islands/use-persistent-state.js +1 -0
  49. package/dist/src/core/layout/enhanced-layout-resolver.js +1 -0
  50. package/dist/src/core/layout/layout-cache-manager.js +1 -0
  51. package/dist/src/core/layout/layout-composer.js +1 -0
  52. package/dist/src/core/layout/layout-data-loader.js +1 -0
  53. package/dist/src/core/layout/layout-discovery.js +1 -0
  54. package/dist/src/core/layout/layout-matcher.js +1 -0
  55. package/dist/src/core/layout/layout-types.js +1 -0
  56. package/dist/src/core/modules/framework-module-resolver.js +1 -0
  57. package/dist/src/islands/component-analysis.js +1 -0
  58. package/dist/src/islands/css-utils.js +17 -0
  59. package/dist/src/islands/discovery/index.js +1 -0
  60. package/dist/src/islands/discovery/registry.js +1 -0
  61. package/dist/src/islands/discovery/resolver.js +2 -0
  62. package/dist/src/islands/discovery/scanner.js +1 -0
  63. package/dist/src/islands/discovery/types.js +1 -0
  64. package/dist/src/islands/discovery/validator.js +18 -0
  65. package/dist/src/islands/discovery/watcher.js +1 -0
  66. package/dist/src/islands/framework-detection.js +1 -0
  67. package/dist/src/islands/integration-loader.js +1 -0
  68. package/dist/src/islands/island.js +1 -0
  69. package/dist/src/islands/render-cache.js +1 -0
  70. package/dist/src/islands/types.js +1 -0
  71. package/dist/src/islands/universal-css-collector.js +5 -0
  72. package/dist/src/islands/universal-head-collector.js +2 -0
  73. package/{src → dist/src}/layout-system.d.ts +592 -592
  74. package/dist/src/layout-system.js +1 -0
  75. package/dist/src/middleware/discovery.js +1 -0
  76. package/dist/src/middleware/executor.js +1 -0
  77. package/dist/src/middleware/index.js +1 -0
  78. package/dist/src/middleware/types.js +1 -0
  79. package/dist/src/nitro/build-config.js +1 -0
  80. package/dist/src/nitro/config.js +1 -0
  81. package/dist/src/nitro/error-handler.js +198 -0
  82. package/dist/src/nitro/index.js +1 -0
  83. package/dist/src/nitro/island-manifest.js +2 -0
  84. package/dist/src/nitro/middleware-adapter.js +1 -0
  85. package/dist/src/nitro/renderer.js +183 -0
  86. package/dist/src/nitro/route-discovery.js +1 -0
  87. package/dist/src/nitro/types.js +1 -0
  88. package/dist/src/render/collect-css.js +3 -0
  89. package/{src/render/error-pages.ts → dist/src/render/error-pages.js} +7 -38
  90. package/dist/src/render/isolated-ssr-renderer.js +1 -0
  91. package/dist/src/render/ssr.js +90 -0
  92. package/dist/src/schemas/api.js +1 -0
  93. package/dist/src/schemas/core.js +1 -0
  94. package/dist/src/schemas/index.js +1 -0
  95. package/dist/src/schemas/layout.js +1 -0
  96. package/dist/src/schemas/routing/index.js +1 -0
  97. package/dist/src/schemas/routing.js +1 -0
  98. package/dist/src/types/as-island.js +1 -0
  99. package/{src → dist/src}/types/image.d.ts +106 -106
  100. package/{src → dist/src}/types/index.d.ts +22 -22
  101. package/{src → dist/src}/types/island-jsx.d.ts +33 -33
  102. package/{src → dist/src}/types/island-prop.d.ts +20 -20
  103. package/dist/src/types/layout.js +1 -0
  104. package/{src → dist/src}/types/mdx.d.ts +6 -6
  105. package/dist/src/types/routing.js +1 -0
  106. package/dist/src/types/types.js +1 -0
  107. package/{src → dist/src}/types/urlpattern.d.ts +49 -49
  108. package/{src → dist/src}/types/vite-env.d.ts +11 -11
  109. package/dist/src/utils/dev-logger.js +12 -0
  110. package/dist/src/utils/fs.js +1 -0
  111. package/dist/src/vite-plugin/auto-discover.js +1 -0
  112. package/dist/src/vite-plugin/config.js +1 -0
  113. package/dist/src/vite-plugin/errors.js +1 -0
  114. package/dist/src/vite-plugin/image-optimization.js +45 -0
  115. package/dist/src/vite-plugin/integration-activator.js +1 -0
  116. package/dist/src/vite-plugin/island-sidecar-plugin.js +1 -0
  117. package/dist/src/vite-plugin/module-discovery.js +1 -0
  118. package/dist/src/vite-plugin/nitro-integration.js +42 -0
  119. package/dist/src/vite-plugin/plugin.js +1 -0
  120. package/dist/src/vite-plugin/types.js +1 -0
  121. package/dist/src/vite-plugin/validation.js +2 -0
  122. package/package.json +57 -26
  123. package/mod.ts +0 -302
  124. package/src/build/integration-bundler-plugin.ts +0 -116
  125. package/src/build/integration-config.ts +0 -168
  126. package/src/build/integration-detection-plugin.ts +0 -117
  127. package/src/build/integration-resolver-plugin.ts +0 -90
  128. package/src/build/island-manifest.ts +0 -269
  129. package/src/build/island-types-generator.ts +0 -476
  130. package/src/build/mdx-island-transform.ts +0 -464
  131. package/src/build/mdx-plugin.ts +0 -98
  132. package/src/build/page-island-transform.ts +0 -598
  133. package/src/build/prop-extractors/index.ts +0 -21
  134. package/src/build/prop-extractors/lit.ts +0 -140
  135. package/src/build/prop-extractors/qwik.ts +0 -16
  136. package/src/build/prop-extractors/solid.ts +0 -125
  137. package/src/build/prop-extractors/svelte.ts +0 -194
  138. package/src/build/prop-extractors/vue.ts +0 -111
  139. package/src/build/sidecar-file-manager.ts +0 -104
  140. package/src/build/sidecar-renderer.ts +0 -30
  141. package/src/client/adapters/index.js +0 -12
  142. package/src/client/adapters/index.ts +0 -13
  143. package/src/client/adapters/lit-adapter.js +0 -467
  144. package/src/client/adapters/lit-adapter.ts +0 -654
  145. package/src/client/adapters/preact-adapter.js +0 -223
  146. package/src/client/adapters/preact-adapter.ts +0 -331
  147. package/src/client/adapters/qwik-adapter.js +0 -259
  148. package/src/client/adapters/qwik-adapter.ts +0 -345
  149. package/src/client/adapters/react-adapter.js +0 -220
  150. package/src/client/adapters/react-adapter.ts +0 -353
  151. package/src/client/adapters/solid-adapter.js +0 -295
  152. package/src/client/adapters/solid-adapter.ts +0 -451
  153. package/src/client/adapters/svelte-adapter.js +0 -368
  154. package/src/client/adapters/svelte-adapter.ts +0 -524
  155. package/src/client/adapters/vue-adapter.js +0 -278
  156. package/src/client/adapters/vue-adapter.ts +0 -467
  157. package/src/client/components.js +0 -23
  158. package/src/client/components.ts +0 -35
  159. package/src/client/css-hmr-handler.js +0 -263
  160. package/src/client/css-hmr-handler.ts +0 -344
  161. package/src/client/framework-adapter.js +0 -283
  162. package/src/client/framework-adapter.ts +0 -462
  163. package/src/client/hmr-coordinator.js +0 -274
  164. package/src/client/hmr-coordinator.ts +0 -396
  165. package/src/client/hmr-error-overlay.js +0 -533
  166. package/src/client/main.js +0 -816
  167. package/src/client/types/vite-virtual-modules.d.ts +0 -60
  168. package/src/components/Image.tsx +0 -123
  169. package/src/components/IslandErrorBoundary.tsx +0 -145
  170. package/src/components/LayoutDataErrorBoundary.tsx +0 -141
  171. package/src/components/LayoutErrorBoundary.tsx +0 -127
  172. package/src/components/PersistentIsland.tsx +0 -52
  173. package/src/components/StreamingErrorBoundary.tsx +0 -233
  174. package/src/components/StreamingLayout.tsx +0 -538
  175. package/src/core/components/component-analyzer.ts +0 -192
  176. package/src/core/components/component-detection.ts +0 -508
  177. package/src/core/components/enhanced-framework-detector.ts +0 -500
  178. package/src/core/components/framework-registry.ts +0 -563
  179. package/src/core/content/mdx-processor.ts +0 -46
  180. package/src/core/integrations/index.ts +0 -19
  181. package/src/core/integrations/loader.ts +0 -125
  182. package/src/core/integrations/registry.ts +0 -175
  183. package/src/core/islands/island-persistence.ts +0 -325
  184. package/src/core/islands/island-state-serializer.ts +0 -258
  185. package/src/core/islands/persistent-island-context.tsx +0 -80
  186. package/src/core/islands/use-persistent-state.ts +0 -68
  187. package/src/core/layout/enhanced-layout-resolver.ts +0 -322
  188. package/src/core/layout/layout-cache-manager.ts +0 -485
  189. package/src/core/layout/layout-composer.ts +0 -357
  190. package/src/core/layout/layout-data-loader.ts +0 -516
  191. package/src/core/layout/layout-discovery.ts +0 -243
  192. package/src/core/layout/layout-matcher.ts +0 -299
  193. package/src/core/layout/layout-types.ts +0 -110
  194. package/src/core/modules/framework-module-resolver.ts +0 -273
  195. package/src/islands/component-analysis.ts +0 -213
  196. package/src/islands/css-utils.ts +0 -565
  197. package/src/islands/discovery/index.ts +0 -80
  198. package/src/islands/discovery/registry.ts +0 -340
  199. package/src/islands/discovery/resolver.ts +0 -477
  200. package/src/islands/discovery/scanner.ts +0 -386
  201. package/src/islands/discovery/types.ts +0 -117
  202. package/src/islands/discovery/validator.ts +0 -544
  203. package/src/islands/discovery/watcher.ts +0 -368
  204. package/src/islands/framework-detection.ts +0 -428
  205. package/src/islands/integration-loader.ts +0 -490
  206. package/src/islands/island.tsx +0 -565
  207. package/src/islands/render-cache.ts +0 -550
  208. package/src/islands/types.ts +0 -80
  209. package/src/islands/universal-css-collector.ts +0 -157
  210. package/src/islands/universal-head-collector.ts +0 -137
  211. package/src/layout-system.ts +0 -218
  212. package/src/middleware/discovery.ts +0 -268
  213. package/src/middleware/executor.ts +0 -315
  214. package/src/middleware/index.ts +0 -76
  215. package/src/middleware/types.ts +0 -99
  216. package/src/nitro/build-config.ts +0 -576
  217. package/src/nitro/config.ts +0 -483
  218. package/src/nitro/error-handler.ts +0 -636
  219. package/src/nitro/index.ts +0 -173
  220. package/src/nitro/island-manifest.ts +0 -584
  221. package/src/nitro/middleware-adapter.ts +0 -260
  222. package/src/nitro/renderer.ts +0 -1471
  223. package/src/nitro/route-discovery.ts +0 -439
  224. package/src/nitro/types.ts +0 -321
  225. package/src/render/collect-css.ts +0 -198
  226. package/src/render/isolated-ssr-renderer.ts +0 -654
  227. package/src/render/ssr.ts +0 -1030
  228. package/src/schemas/api.ts +0 -30
  229. package/src/schemas/core.ts +0 -64
  230. package/src/schemas/index.ts +0 -212
  231. package/src/schemas/layout.ts +0 -279
  232. package/src/schemas/routing/index.ts +0 -38
  233. package/src/schemas/routing.ts +0 -376
  234. package/src/types/as-island.ts +0 -20
  235. package/src/types/layout.ts +0 -285
  236. package/src/types/routing.ts +0 -555
  237. package/src/types/types.ts +0 -5
  238. package/src/utils/dev-logger.ts +0 -299
  239. package/src/utils/fs.ts +0 -151
  240. package/src/vite-plugin/auto-discover.ts +0 -551
  241. package/src/vite-plugin/config.ts +0 -266
  242. package/src/vite-plugin/errors.ts +0 -127
  243. package/src/vite-plugin/image-optimization.ts +0 -156
  244. package/src/vite-plugin/integration-activator.ts +0 -126
  245. package/src/vite-plugin/island-sidecar-plugin.ts +0 -176
  246. package/src/vite-plugin/module-discovery.ts +0 -189
  247. package/src/vite-plugin/nitro-integration.ts +0 -1354
  248. package/src/vite-plugin/plugin.ts +0 -401
  249. package/src/vite-plugin/types.ts +0 -327
  250. package/src/vite-plugin/validation.ts +0 -228
@@ -1,60 +0,0 @@
1
- /**
2
- * Type declarations for Vite virtual modules
3
- *
4
- * These modules are resolved by Vite at runtime in the browser.
5
- * They don't exist as actual files but are provided by Vite's plugin system.
6
- */
7
-
8
- declare module '/@useavalon/preact/client' {
9
- export function hydrate(
10
- container: Element,
11
- component: unknown,
12
- props?: Record<string, unknown>
13
- ): void;
14
- export function getHydrationScript(): string;
15
- }
16
-
17
- declare module '/@useavalon/react/client' {
18
- export function hydrate(
19
- container: Element,
20
- component: unknown,
21
- props?: Record<string, unknown>
22
- ): void;
23
- export function getHydrationScript(): string;
24
- }
25
-
26
- declare module '/@useavalon/vue/client' {
27
- export function hydrate(
28
- container: Element,
29
- component: unknown,
30
- props?: Record<string, unknown>
31
- ): void;
32
- export function getHydrationScript(): string;
33
- }
34
-
35
- declare module '/@useavalon/svelte/client' {
36
- export function hydrate(
37
- container: Element,
38
- component: unknown,
39
- props?: Record<string, unknown>
40
- ): void;
41
- export function getHydrationScript(): string;
42
- }
43
-
44
- declare module '/@useavalon/solid/client' {
45
- export function hydrate(
46
- container: Element,
47
- component: unknown,
48
- props?: Record<string, unknown>
49
- ): void;
50
- export function getHydrationScript(): string;
51
- }
52
-
53
- declare module '/@useavalon/lit/client' {
54
- export function hydrate(
55
- container: Element,
56
- component: unknown,
57
- props?: Record<string, unknown>
58
- ): void;
59
- export function getHydrationScript(): string;
60
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * Image Component for Avalon
3
- *
4
- * A responsive image component that works with vite-imagetools to provide
5
- * optimized images with automatic srcset generation.
6
- *
7
- * Usage:
8
- * ```tsx
9
- * import { Image } from '@useavalon/avalon/client';
10
- * import heroSrc from './hero.jpg?w=400;800;1200&format=webp&as=srcset';
11
- *
12
- * <Image
13
- * src={heroSrc}
14
- * alt="Hero image"
15
- * sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px"
16
- * />
17
- * ```
18
- *
19
- * Or with the simpler single-image approach:
20
- * ```tsx
21
- * import heroSrc from './hero.jpg?w=800&format=webp';
22
- *
23
- * <Image src={heroSrc} alt="Hero image" width={800} height={600} />
24
- * ```
25
- */
26
-
27
- import type { JSX } from "preact";
28
-
29
- export interface ImageProps {
30
- /**
31
- * Image source - can be:
32
- * - A string URL (single image)
33
- * - A srcset string from ?as=srcset (contains " Xw" width descriptors)
34
- * - An object with src/srcset/width/height from vite-imagetools
35
- */
36
- src: string | { src: string; srcset?: string; width?: number; height?: number };
37
-
38
- /** Alt text for accessibility (required) */
39
- alt: string;
40
-
41
- /** Sizes attribute for responsive images (required when using srcset) */
42
- sizes?: string;
43
-
44
- /** Loading strategy */
45
- loading?: "lazy" | "eager";
46
-
47
- /** Decoding hint */
48
- decoding?: "async" | "sync" | "auto";
49
-
50
- /** Optional width (auto-detected from srcset if available) */
51
- width?: number | string;
52
-
53
- /** Optional height (auto-detected from srcset if available) */
54
- height?: number | string;
55
-
56
- /** CSS class name */
57
- className?: string;
58
-
59
- /** Inline styles */
60
- style?: string | Record<string, string | number>;
61
- }
62
-
63
- /**
64
- * Check if a string looks like a srcset (contains width descriptors like "400w")
65
- */
66
- function isSrcsetString(value: string): boolean {
67
- return /\s\d+w/.test(value);
68
- }
69
-
70
- /**
71
- * Responsive image component with built-in optimization support
72
- */
73
- export function Image({
74
- src,
75
- alt,
76
- sizes,
77
- loading = "lazy",
78
- decoding = "async",
79
- width,
80
- height,
81
- className,
82
- style,
83
- }: Readonly<ImageProps>): JSX.Element {
84
- let imgSrc: string | undefined;
85
- let srcSet: string | undefined;
86
- let autoWidth: number | undefined;
87
- let autoHeight: number | undefined;
88
-
89
- if (typeof src === "object" && src !== null) {
90
- // Object from vite-imagetools (e.g., ?as=metadata or custom output)
91
- imgSrc = src.src;
92
- srcSet = src.srcset;
93
- autoWidth = src.width;
94
- autoHeight = src.height;
95
- } else if (typeof src === "string") {
96
- if (isSrcsetString(src)) {
97
- // srcset string from ?as=srcset - use first URL as fallback src
98
- srcSet = src;
99
- const firstUrl = src.split(",")[0]?.trim().split(" ")[0];
100
- imgSrc = firstUrl;
101
- } else {
102
- // Regular URL string
103
- imgSrc = src;
104
- }
105
- }
106
-
107
- return (
108
- <img
109
- src={imgSrc}
110
- srcSet={srcSet}
111
- sizes={sizes}
112
- alt={alt}
113
- loading={loading}
114
- decoding={decoding}
115
- width={width ?? autoWidth}
116
- height={height ?? autoHeight}
117
- className={className}
118
- style={style}
119
- />
120
- );
121
- }
122
-
123
- export default Image;
@@ -1,145 +0,0 @@
1
- import { Component, ComponentChildren, ComponentType } from 'preact';
2
- import type { LayoutErrorInfo } from '../types/layout.ts';
3
-
4
- export interface IslandErrorBoundaryProps {
5
- children: ComponentChildren;
6
- islandId: string;
7
- onError?: (error: Error, errorInfo: LayoutErrorInfo) => void;
8
- fallback?: (error: Error, islandId: string) => ComponentChildren;
9
- isolateError?: boolean;
10
- }
11
-
12
- export interface IslandErrorBoundaryState {
13
- hasError: boolean;
14
- error: Error | null;
15
- errorInfo: LayoutErrorInfo | null;
16
- }
17
-
18
- /**
19
- * Specialized error boundary for island components
20
- * Provides error isolation to prevent island errors from affecting the main layout
21
- */
22
- export class IslandErrorBoundary extends Component<IslandErrorBoundaryProps, IslandErrorBoundaryState> {
23
- constructor(props: IslandErrorBoundaryProps) {
24
- super(props);
25
- this.state = { hasError: false, error: null, errorInfo: null };
26
- }
27
-
28
- static override getDerivedStateFromError(error: Error): Partial<IslandErrorBoundaryState> {
29
- return { hasError: true, error };
30
- }
31
-
32
- override componentDidCatch(error: Error, errorInfo: { componentStack?: string }): void {
33
- const layoutErrorInfo: LayoutErrorInfo = {
34
- layoutPath: `island:${this.props.islandId}`,
35
- errorType: 'island',
36
- timestamp: Date.now(),
37
- componentStack: errorInfo.componentStack,
38
- errorBoundary: 'IslandErrorBoundary',
39
- };
40
-
41
- this.setState({ errorInfo: layoutErrorInfo });
42
-
43
- if (this.props.onError) {
44
- this.props.onError(error, layoutErrorInfo);
45
- }
46
-
47
- const isDevelopment = typeof Deno !== 'undefined' && Deno.env.get('NODE_ENV') === 'development';
48
- if (isDevelopment) {
49
- console.error(`Island Error [${this.props.islandId}]:`, error);
50
- }
51
-
52
- if (!this.props.isolateError) {
53
- throw error;
54
- }
55
- }
56
-
57
- private handleRemoveIsland = (): void => {
58
- const islandElement = document.querySelector(`[data-island-id="${this.props.islandId}"]`);
59
- if (islandElement) {
60
- islandElement.remove();
61
- }
62
- };
63
-
64
- private handleReloadIsland = (): void => {
65
- this.setState({ hasError: false, error: null, errorInfo: null });
66
- };
67
-
68
- private renderFallback(): ComponentChildren {
69
- const { error } = this.state;
70
- const { fallback, islandId } = this.props;
71
-
72
- if (fallback && error) {
73
- return fallback(error, islandId);
74
- }
75
-
76
- const isDevelopment = typeof Deno !== 'undefined' && Deno.env.get('NODE_ENV') === 'development';
77
-
78
- return (
79
- <div class="island-error-boundary" data-island-error={islandId}>
80
- <div class="island-error-container">
81
- <div class="island-error-header">
82
- <span class="island-error-icon">⚠️</span>
83
- <span class="island-error-title">Island Error</span>
84
- </div>
85
-
86
- <p class="island-error-message">
87
- An error occurred in island "{islandId}". The rest of the page should work normally.
88
- </p>
89
-
90
- <div class="island-error-actions">
91
- <button onClick={this.handleReloadIsland} class="island-reload-button">
92
- Reload Island
93
- </button>
94
- <button onClick={this.handleRemoveIsland} class="island-remove-button">
95
- Remove Island
96
- </button>
97
- </div>
98
-
99
- {isDevelopment && error && (
100
- <details class="island-error-details">
101
- <summary>Error Details (Development)</summary>
102
- <div class="island-error-info">
103
- <p><strong>Island ID:</strong> {islandId}</p>
104
- <p><strong>Error:</strong> {error.message}</p>
105
- </div>
106
- <pre class="island-error-stack">{error.stack}</pre>
107
- </details>
108
- )}
109
- </div>
110
- </div>
111
- );
112
- }
113
-
114
- render() {
115
- if (this.state.hasError) {
116
- return this.renderFallback();
117
- }
118
- return this.props.children;
119
- }
120
- }
121
-
122
- /**
123
- * Higher-order component to wrap islands with error boundaries
124
- */
125
- export function withIslandErrorBoundary<P extends object>(
126
- WrappedComponent: ComponentType<P>,
127
- islandId: string,
128
- options?: {
129
- fallback?: (error: Error, islandId: string) => ComponentChildren;
130
- isolateError?: boolean;
131
- onError?: (error: Error, errorInfo: LayoutErrorInfo) => void;
132
- }
133
- ) {
134
- return function IslandWithErrorBoundary(props: P) {
135
- return (
136
- <IslandErrorBoundary
137
- islandId={islandId}
138
- fallback={options?.fallback}
139
- isolateError={options?.isolateError ?? true}
140
- onError={options?.onError}>
141
- <WrappedComponent {...props} />
142
- </IslandErrorBoundary>
143
- );
144
- };
145
- }
@@ -1,141 +0,0 @@
1
- import { Component, ComponentChildren } from 'preact';
2
- import type { LayoutErrorInfo, LayoutContext, LayoutData } from '../types/layout.ts';
3
-
4
- export interface LayoutDataErrorBoundaryProps {
5
- children: ComponentChildren;
6
- layoutPath: string;
7
- context: LayoutContext;
8
- onError?: (error: Error, errorInfo: LayoutErrorInfo) => void;
9
- fallbackData?: LayoutData;
10
- retryLoader?: () => Promise<LayoutData>;
11
- }
12
-
13
- export interface LayoutDataErrorBoundaryState {
14
- hasError: boolean;
15
- error: Error | null;
16
- errorInfo: LayoutErrorInfo | null;
17
- retryCount: number;
18
- isRetrying: boolean;
19
- fallbackData: LayoutData | null;
20
- }
21
-
22
- /**
23
- * Specialized error boundary for layout data loading errors
24
- * Provides specific handling for data loader failures with retry and fallback mechanisms
25
- */
26
- export class LayoutDataErrorBoundary extends Component<LayoutDataErrorBoundaryProps, LayoutDataErrorBoundaryState> {
27
- private maxRetries = 3;
28
-
29
- constructor(props: LayoutDataErrorBoundaryProps) {
30
- super(props);
31
- this.state = {
32
- hasError: false,
33
- error: null,
34
- errorInfo: null,
35
- retryCount: 0,
36
- isRetrying: false,
37
- fallbackData: props.fallbackData || null,
38
- };
39
- }
40
-
41
- static override getDerivedStateFromError(error: Error): Partial<LayoutDataErrorBoundaryState> {
42
- return { hasError: true, error };
43
- }
44
-
45
- override componentDidCatch(error: Error, errorInfo: { componentStack?: string }): void {
46
- const layoutErrorInfo: LayoutErrorInfo = {
47
- layoutPath: this.props.layoutPath,
48
- errorType: 'loader',
49
- timestamp: Date.now(),
50
- componentStack: errorInfo.componentStack,
51
- errorBoundary: 'LayoutDataErrorBoundary',
52
- };
53
-
54
- this.setState({ errorInfo: layoutErrorInfo });
55
-
56
- if (this.props.onError) {
57
- this.props.onError(error, layoutErrorInfo);
58
- }
59
- }
60
-
61
- private handleRetry = async (): Promise<void> => {
62
- if (this.state.retryCount >= this.maxRetries || !this.props.retryLoader) {
63
- return;
64
- }
65
-
66
- this.setState({ isRetrying: true });
67
-
68
- try {
69
- const data = await this.props.retryLoader();
70
- this.setState({
71
- hasError: false,
72
- error: null,
73
- errorInfo: null,
74
- retryCount: this.state.retryCount + 1,
75
- isRetrying: false,
76
- fallbackData: data,
77
- });
78
- } catch (retryError) {
79
- this.setState({
80
- retryCount: this.state.retryCount + 1,
81
- isRetrying: false,
82
- error: retryError instanceof Error ? retryError : new Error(String(retryError)),
83
- });
84
- }
85
- };
86
-
87
- private handleUseFallback = (): void => {
88
- if (this.state.fallbackData) {
89
- this.setState({ hasError: false, error: null, errorInfo: null });
90
- }
91
- };
92
-
93
- private renderErrorUI(): ComponentChildren {
94
- const { error, retryCount, isRetrying, fallbackData } = this.state;
95
- const canRetry = retryCount < this.maxRetries && this.props.retryLoader;
96
- const hasFallback = fallbackData !== null;
97
- const isDevelopment = typeof Deno !== 'undefined' && Deno.env.get('NODE_ENV') === 'development';
98
-
99
- return (
100
- <div class="layout-data-error-boundary">
101
- <div class="error-container">
102
- <h3>Data Loading Error</h3>
103
- <p>Failed to load data for layout: {this.props.layoutPath}</p>
104
-
105
- <div class="error-actions">
106
- {canRetry && (
107
- <button onClick={this.handleRetry} disabled={isRetrying} class="retry-button">
108
- {isRetrying ? 'Retrying...' : `Retry (${this.maxRetries - retryCount} left)`}
109
- </button>
110
- )}
111
-
112
- {hasFallback && (
113
- <button onClick={this.handleUseFallback} class="fallback-button">
114
- Use Cached Data
115
- </button>
116
- )}
117
- </div>
118
-
119
- {isDevelopment && error && (
120
- <details class="error-details">
121
- <summary>Error Details (Development)</summary>
122
- <div class="error-info">
123
- <p><strong>Error:</strong> {error.message}</p>
124
- <p><strong>Layout:</strong> {this.props.layoutPath}</p>
125
- <p><strong>Retry Count:</strong> {retryCount}</p>
126
- </div>
127
- <pre class="error-stack">{error.stack}</pre>
128
- </details>
129
- )}
130
- </div>
131
- </div>
132
- );
133
- }
134
-
135
- render() {
136
- if (this.state.hasError) {
137
- return this.renderErrorUI();
138
- }
139
- return this.props.children;
140
- }
141
- }
@@ -1,127 +0,0 @@
1
- import { Component, ComponentChildren } from 'preact';
2
- import type { LayoutErrorInfo, ErrorRecoveryStrategy } from '../types/layout.ts';
3
-
4
- export interface LayoutErrorBoundaryProps {
5
- children: ComponentChildren;
6
- fallback?: (error: Error, retry: () => void) => ComponentChildren;
7
- onError?: (error: Error, errorInfo: LayoutErrorInfo) => void;
8
- recoveryStrategy?: ErrorRecoveryStrategy;
9
- layoutPath?: string;
10
- errorType?: 'component' | 'loader' | 'rendering' | 'island';
11
- }
12
-
13
- export interface LayoutErrorBoundaryState {
14
- hasError: boolean;
15
- error: Error | null;
16
- errorInfo: LayoutErrorInfo | null;
17
- retryCount: number;
18
- }
19
-
20
- export class LayoutErrorBoundary extends Component<LayoutErrorBoundaryProps, LayoutErrorBoundaryState> {
21
- private maxRetries = 3;
22
-
23
- constructor(props: LayoutErrorBoundaryProps) {
24
- super(props);
25
- this.state = {
26
- hasError: false,
27
- error: null,
28
- errorInfo: null,
29
- retryCount: 0,
30
- };
31
- }
32
-
33
- static override getDerivedStateFromError(error: Error): Partial<LayoutErrorBoundaryState> {
34
- return {
35
- hasError: true,
36
- error,
37
- };
38
- }
39
-
40
- override componentDidCatch(error: Error, errorInfo: any): void {
41
- const layoutErrorInfo: LayoutErrorInfo = {
42
- layoutPath: this.props.layoutPath || 'unknown',
43
- errorType: this.props.errorType || 'component',
44
- timestamp: Date.now(),
45
- componentStack: errorInfo.componentStack,
46
- errorBoundary: this.constructor.name,
47
- };
48
-
49
- this.setState({
50
- errorInfo: layoutErrorInfo,
51
- });
52
-
53
- // Call onError callback if provided
54
- if (this.props.onError) {
55
- this.props.onError(error, layoutErrorInfo);
56
- }
57
-
58
- // Log error in development mode
59
- if (typeof Deno !== 'undefined' && Deno.env.get('NODE_ENV') === 'development') {
60
- console.error('Layout Error Boundary caught an error:', error);
61
- console.error('Error Info:', layoutErrorInfo);
62
- console.error('Component Stack:', errorInfo.componentStack);
63
- }
64
- }
65
-
66
- private handleRetry = (): void => {
67
- if (this.state.retryCount < this.maxRetries) {
68
- this.setState({
69
- hasError: false,
70
- error: null,
71
- errorInfo: null,
72
- retryCount: this.state.retryCount + 1,
73
- });
74
- }
75
- };
76
-
77
- private renderFallback(): ComponentChildren {
78
- const { error } = this.state;
79
- const { fallback } = this.props;
80
-
81
- if (fallback && error) {
82
- return fallback(error, this.handleRetry);
83
- }
84
-
85
- // Default fallback UI
86
- return (
87
- <div class="layout-error-boundary">
88
- <div class="error-container">
89
- <h2>Something went wrong</h2>
90
- <p>An error occurred while rendering this layout.</p>
91
- {this.state.retryCount < this.maxRetries && (
92
- <button onClick={this.handleRetry} class="retry-button">
93
- Try Again ({this.maxRetries - this.state.retryCount} attempts left)
94
- </button>
95
- )}
96
- {typeof Deno !== 'undefined' && Deno.env.get('NODE_ENV') === 'development' && (
97
- <details class="error-details">
98
- <summary>Error Details (Development)</summary>
99
- <pre>{error?.stack}</pre>
100
- {this.state.errorInfo && (
101
- <div>
102
- <p>
103
- <strong>Layout Path:</strong> {this.state.errorInfo.layoutPath}
104
- </p>
105
- <p>
106
- <strong>Error Type:</strong> {this.state.errorInfo.errorType}
107
- </p>
108
- <p>
109
- <strong>Timestamp:</strong> {new Date(this.state.errorInfo.timestamp).toISOString()}
110
- </p>
111
- </div>
112
- )}
113
- </details>
114
- )}
115
- </div>
116
- </div>
117
- );
118
- }
119
-
120
- render() {
121
- if (this.state.hasError) {
122
- return this.renderFallback();
123
- }
124
-
125
- return this.props.children;
126
- }
127
- }
@@ -1,52 +0,0 @@
1
- /** @jsxImportSource preact */
2
- import type { ComponentChildren } from 'preact';
3
- import { PersistentIslandProvider } from '../core/islands/persistent-island-context.tsx';
4
- import { defaultIslandPersistence, type IslandPersistence } from '../core/islands/island-persistence.ts';
5
-
6
- interface PersistentIslandProps {
7
- /** Unique ID used as the storage key for this island's state */
8
- persistentId: string;
9
- /** The island component(s) to wrap with persistence context */
10
- children: ComponentChildren;
11
- /** Custom persistence instance (defaults to sessionStorage-backed) */
12
- persistence?: IslandPersistence;
13
- }
14
-
15
- /**
16
- * PersistentIsland — provides automatic state persistence context to child islands.
17
- *
18
- * Wrap any island with this component and use `usePersistentIslandContext()` inside
19
- * the island to get `saveState`, `loadState`, and `clearState` functions.
20
- *
21
- * Usage in a page:
22
- * ```tsx
23
- * <PersistentIsland persistentId="my-counter" island={{ condition: 'on:client' }}>
24
- * <MyCounter />
25
- * </PersistentIsland>
26
- * ```
27
- *
28
- * Usage inside the island:
29
- * ```tsx
30
- * import { usePersistentIslandContext } from '@useavalon/avalon';
31
- *
32
- * function MyCounter() {
33
- * const { saveState, loadState, clearState } = usePersistentIslandContext();
34
- * // ...
35
- * }
36
- * ```
37
- */
38
- export function PersistentIsland({
39
- persistentId,
40
- children,
41
- persistence = defaultIslandPersistence,
42
- }: Readonly<PersistentIslandProps>) {
43
- return (
44
- <PersistentIslandProvider persistentId={persistentId} persistence={persistence}>
45
- <div data-persistent-id={persistentId}>
46
- {children}
47
- </div>
48
- </PersistentIslandProvider>
49
- );
50
- }
51
-
52
- export default PersistentIsland;