@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.
- package/README.md +54 -54
- package/dist/mod.js +1 -0
- package/dist/src/build/integration-bundler-plugin.js +1 -0
- package/dist/src/build/integration-config.js +1 -0
- package/dist/src/build/integration-detection-plugin.js +1 -0
- package/dist/src/build/integration-resolver-plugin.js +1 -0
- package/dist/src/build/island-manifest.js +1 -0
- package/dist/src/build/island-types-generator.js +5 -0
- package/dist/src/build/mdx-island-transform.js +2 -0
- package/dist/src/build/mdx-plugin.js +1 -0
- package/dist/src/build/page-island-transform.js +3 -0
- package/dist/src/build/prop-extractors/index.js +1 -0
- package/dist/src/build/prop-extractors/lit.js +1 -0
- package/dist/src/build/prop-extractors/qwik.js +1 -0
- package/dist/src/build/prop-extractors/solid.js +1 -0
- package/dist/src/build/prop-extractors/svelte.js +1 -0
- package/dist/src/build/prop-extractors/vue.js +1 -0
- package/dist/src/build/sidecar-file-manager.js +1 -0
- package/dist/src/build/sidecar-renderer.js +6 -0
- package/dist/src/client/adapters/index.js +1 -0
- package/dist/src/client/components.js +1 -0
- package/dist/src/client/css-hmr-handler.js +1 -0
- package/dist/src/client/framework-adapter.js +13 -0
- package/dist/src/client/hmr-coordinator.js +1 -0
- package/dist/src/client/hmr-error-overlay.js +214 -0
- package/dist/src/client/main.js +39 -0
- package/{src → dist/src}/client/types/framework-runtime.d.ts +68 -68
- package/{src → dist/src}/client/types/vite-hmr.d.ts +46 -46
- package/dist/src/client/types/vite-virtual-modules.d.ts +70 -0
- package/dist/src/components/Image.js +1 -0
- package/dist/src/components/IslandErrorBoundary.js +1 -0
- package/dist/src/components/LayoutDataErrorBoundary.js +1 -0
- package/dist/src/components/LayoutErrorBoundary.js +1 -0
- package/dist/src/components/PersistentIsland.js +1 -0
- package/dist/src/components/StreamingErrorBoundary.js +1 -0
- package/dist/src/components/StreamingLayout.js +29 -0
- package/dist/src/core/components/component-analyzer.js +1 -0
- package/dist/src/core/components/component-detection.js +5 -0
- package/dist/src/core/components/enhanced-framework-detector.js +1 -0
- package/dist/src/core/components/framework-registry.js +1 -0
- package/dist/src/core/content/mdx-processor.js +1 -0
- package/dist/src/core/integrations/index.js +1 -0
- package/dist/src/core/integrations/loader.js +1 -0
- package/dist/src/core/integrations/registry.js +1 -0
- package/dist/src/core/islands/island-persistence.js +1 -0
- package/dist/src/core/islands/island-state-serializer.js +1 -0
- package/dist/src/core/islands/persistent-island-context.js +1 -0
- package/dist/src/core/islands/use-persistent-state.js +1 -0
- package/dist/src/core/layout/enhanced-layout-resolver.js +1 -0
- package/dist/src/core/layout/layout-cache-manager.js +1 -0
- package/dist/src/core/layout/layout-composer.js +1 -0
- package/dist/src/core/layout/layout-data-loader.js +1 -0
- package/dist/src/core/layout/layout-discovery.js +1 -0
- package/dist/src/core/layout/layout-matcher.js +1 -0
- package/dist/src/core/layout/layout-types.js +1 -0
- package/dist/src/core/modules/framework-module-resolver.js +1 -0
- package/dist/src/islands/component-analysis.js +1 -0
- package/dist/src/islands/css-utils.js +17 -0
- package/dist/src/islands/discovery/index.js +1 -0
- package/dist/src/islands/discovery/registry.js +1 -0
- package/dist/src/islands/discovery/resolver.js +2 -0
- package/dist/src/islands/discovery/scanner.js +1 -0
- package/dist/src/islands/discovery/types.js +1 -0
- package/dist/src/islands/discovery/validator.js +18 -0
- package/dist/src/islands/discovery/watcher.js +1 -0
- package/dist/src/islands/framework-detection.js +1 -0
- package/dist/src/islands/integration-loader.js +1 -0
- package/dist/src/islands/island.js +1 -0
- package/dist/src/islands/render-cache.js +1 -0
- package/dist/src/islands/types.js +1 -0
- package/dist/src/islands/universal-css-collector.js +5 -0
- package/dist/src/islands/universal-head-collector.js +2 -0
- package/{src → dist/src}/layout-system.d.ts +592 -592
- package/dist/src/layout-system.js +1 -0
- package/dist/src/middleware/discovery.js +1 -0
- package/dist/src/middleware/executor.js +1 -0
- package/dist/src/middleware/index.js +1 -0
- package/dist/src/middleware/types.js +1 -0
- package/dist/src/nitro/build-config.js +1 -0
- package/dist/src/nitro/config.js +1 -0
- package/dist/src/nitro/error-handler.js +198 -0
- package/dist/src/nitro/index.js +1 -0
- package/dist/src/nitro/island-manifest.js +2 -0
- package/dist/src/nitro/middleware-adapter.js +1 -0
- package/dist/src/nitro/renderer.js +183 -0
- package/dist/src/nitro/route-discovery.js +1 -0
- package/dist/src/nitro/types.js +1 -0
- package/dist/src/render/collect-css.js +3 -0
- package/{src/render/error-pages.ts → dist/src/render/error-pages.js} +7 -38
- package/dist/src/render/isolated-ssr-renderer.js +1 -0
- package/dist/src/render/ssr.js +90 -0
- package/dist/src/schemas/api.js +1 -0
- package/dist/src/schemas/core.js +1 -0
- package/dist/src/schemas/index.js +1 -0
- package/dist/src/schemas/layout.js +1 -0
- package/dist/src/schemas/routing/index.js +1 -0
- package/dist/src/schemas/routing.js +1 -0
- package/dist/src/types/as-island.js +1 -0
- package/{src → dist/src}/types/image.d.ts +106 -106
- package/{src → dist/src}/types/index.d.ts +22 -22
- package/{src → dist/src}/types/island-jsx.d.ts +33 -33
- package/{src → dist/src}/types/island-prop.d.ts +20 -20
- package/dist/src/types/layout.js +1 -0
- package/{src → dist/src}/types/mdx.d.ts +6 -6
- package/dist/src/types/routing.js +1 -0
- package/dist/src/types/types.js +1 -0
- package/{src → dist/src}/types/urlpattern.d.ts +49 -49
- package/{src → dist/src}/types/vite-env.d.ts +11 -11
- package/dist/src/utils/dev-logger.js +12 -0
- package/dist/src/utils/fs.js +1 -0
- package/dist/src/vite-plugin/auto-discover.js +1 -0
- package/dist/src/vite-plugin/config.js +1 -0
- package/dist/src/vite-plugin/errors.js +1 -0
- package/dist/src/vite-plugin/image-optimization.js +45 -0
- package/dist/src/vite-plugin/integration-activator.js +1 -0
- package/dist/src/vite-plugin/island-sidecar-plugin.js +1 -0
- package/dist/src/vite-plugin/module-discovery.js +1 -0
- package/dist/src/vite-plugin/nitro-integration.js +42 -0
- package/dist/src/vite-plugin/plugin.js +1 -0
- package/dist/src/vite-plugin/types.js +1 -0
- package/dist/src/vite-plugin/validation.js +2 -0
- package/package.json +57 -26
- package/mod.ts +0 -302
- package/src/build/integration-bundler-plugin.ts +0 -116
- package/src/build/integration-config.ts +0 -168
- package/src/build/integration-detection-plugin.ts +0 -117
- package/src/build/integration-resolver-plugin.ts +0 -90
- package/src/build/island-manifest.ts +0 -269
- package/src/build/island-types-generator.ts +0 -476
- package/src/build/mdx-island-transform.ts +0 -464
- package/src/build/mdx-plugin.ts +0 -98
- package/src/build/page-island-transform.ts +0 -598
- package/src/build/prop-extractors/index.ts +0 -21
- package/src/build/prop-extractors/lit.ts +0 -140
- package/src/build/prop-extractors/qwik.ts +0 -16
- package/src/build/prop-extractors/solid.ts +0 -125
- package/src/build/prop-extractors/svelte.ts +0 -194
- package/src/build/prop-extractors/vue.ts +0 -111
- package/src/build/sidecar-file-manager.ts +0 -104
- package/src/build/sidecar-renderer.ts +0 -30
- package/src/client/adapters/index.js +0 -12
- package/src/client/adapters/index.ts +0 -13
- package/src/client/adapters/lit-adapter.js +0 -467
- package/src/client/adapters/lit-adapter.ts +0 -654
- package/src/client/adapters/preact-adapter.js +0 -223
- package/src/client/adapters/preact-adapter.ts +0 -331
- package/src/client/adapters/qwik-adapter.js +0 -259
- package/src/client/adapters/qwik-adapter.ts +0 -345
- package/src/client/adapters/react-adapter.js +0 -220
- package/src/client/adapters/react-adapter.ts +0 -353
- package/src/client/adapters/solid-adapter.js +0 -295
- package/src/client/adapters/solid-adapter.ts +0 -451
- package/src/client/adapters/svelte-adapter.js +0 -368
- package/src/client/adapters/svelte-adapter.ts +0 -524
- package/src/client/adapters/vue-adapter.js +0 -278
- package/src/client/adapters/vue-adapter.ts +0 -467
- package/src/client/components.js +0 -23
- package/src/client/components.ts +0 -35
- package/src/client/css-hmr-handler.js +0 -263
- package/src/client/css-hmr-handler.ts +0 -344
- package/src/client/framework-adapter.js +0 -283
- package/src/client/framework-adapter.ts +0 -462
- package/src/client/hmr-coordinator.js +0 -274
- package/src/client/hmr-coordinator.ts +0 -396
- package/src/client/hmr-error-overlay.js +0 -533
- package/src/client/main.js +0 -816
- package/src/client/types/vite-virtual-modules.d.ts +0 -60
- package/src/components/Image.tsx +0 -123
- package/src/components/IslandErrorBoundary.tsx +0 -145
- package/src/components/LayoutDataErrorBoundary.tsx +0 -141
- package/src/components/LayoutErrorBoundary.tsx +0 -127
- package/src/components/PersistentIsland.tsx +0 -52
- package/src/components/StreamingErrorBoundary.tsx +0 -233
- package/src/components/StreamingLayout.tsx +0 -538
- package/src/core/components/component-analyzer.ts +0 -192
- package/src/core/components/component-detection.ts +0 -508
- package/src/core/components/enhanced-framework-detector.ts +0 -500
- package/src/core/components/framework-registry.ts +0 -563
- package/src/core/content/mdx-processor.ts +0 -46
- package/src/core/integrations/index.ts +0 -19
- package/src/core/integrations/loader.ts +0 -125
- package/src/core/integrations/registry.ts +0 -175
- package/src/core/islands/island-persistence.ts +0 -325
- package/src/core/islands/island-state-serializer.ts +0 -258
- package/src/core/islands/persistent-island-context.tsx +0 -80
- package/src/core/islands/use-persistent-state.ts +0 -68
- package/src/core/layout/enhanced-layout-resolver.ts +0 -322
- package/src/core/layout/layout-cache-manager.ts +0 -485
- package/src/core/layout/layout-composer.ts +0 -357
- package/src/core/layout/layout-data-loader.ts +0 -516
- package/src/core/layout/layout-discovery.ts +0 -243
- package/src/core/layout/layout-matcher.ts +0 -299
- package/src/core/layout/layout-types.ts +0 -110
- package/src/core/modules/framework-module-resolver.ts +0 -273
- package/src/islands/component-analysis.ts +0 -213
- package/src/islands/css-utils.ts +0 -565
- package/src/islands/discovery/index.ts +0 -80
- package/src/islands/discovery/registry.ts +0 -340
- package/src/islands/discovery/resolver.ts +0 -477
- package/src/islands/discovery/scanner.ts +0 -386
- package/src/islands/discovery/types.ts +0 -117
- package/src/islands/discovery/validator.ts +0 -544
- package/src/islands/discovery/watcher.ts +0 -368
- package/src/islands/framework-detection.ts +0 -428
- package/src/islands/integration-loader.ts +0 -490
- package/src/islands/island.tsx +0 -565
- package/src/islands/render-cache.ts +0 -550
- package/src/islands/types.ts +0 -80
- package/src/islands/universal-css-collector.ts +0 -157
- package/src/islands/universal-head-collector.ts +0 -137
- package/src/layout-system.ts +0 -218
- package/src/middleware/discovery.ts +0 -268
- package/src/middleware/executor.ts +0 -315
- package/src/middleware/index.ts +0 -76
- package/src/middleware/types.ts +0 -99
- package/src/nitro/build-config.ts +0 -576
- package/src/nitro/config.ts +0 -483
- package/src/nitro/error-handler.ts +0 -636
- package/src/nitro/index.ts +0 -173
- package/src/nitro/island-manifest.ts +0 -584
- package/src/nitro/middleware-adapter.ts +0 -260
- package/src/nitro/renderer.ts +0 -1471
- package/src/nitro/route-discovery.ts +0 -439
- package/src/nitro/types.ts +0 -321
- package/src/render/collect-css.ts +0 -198
- package/src/render/isolated-ssr-renderer.ts +0 -654
- package/src/render/ssr.ts +0 -1030
- package/src/schemas/api.ts +0 -30
- package/src/schemas/core.ts +0 -64
- package/src/schemas/index.ts +0 -212
- package/src/schemas/layout.ts +0 -279
- package/src/schemas/routing/index.ts +0 -38
- package/src/schemas/routing.ts +0 -376
- package/src/types/as-island.ts +0 -20
- package/src/types/layout.ts +0 -285
- package/src/types/routing.ts +0 -555
- package/src/types/types.ts +0 -5
- package/src/utils/dev-logger.ts +0 -299
- package/src/utils/fs.ts +0 -151
- package/src/vite-plugin/auto-discover.ts +0 -551
- package/src/vite-plugin/config.ts +0 -266
- package/src/vite-plugin/errors.ts +0 -127
- package/src/vite-plugin/image-optimization.ts +0 -156
- package/src/vite-plugin/integration-activator.ts +0 -126
- package/src/vite-plugin/island-sidecar-plugin.ts +0 -176
- package/src/vite-plugin/module-discovery.ts +0 -189
- package/src/vite-plugin/nitro-integration.ts +0 -1354
- package/src/vite-plugin/plugin.ts +0 -401
- package/src/vite-plugin/types.ts +0 -327
- 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
|
-
}
|
package/src/components/Image.tsx
DELETED
|
@@ -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;
|