@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,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adapter registry for managing framework-specific HMR adapters
|
|
3
|
-
*/
|
|
4
|
-
export class AdapterRegistry {
|
|
5
|
-
adapters = new Map();
|
|
6
|
-
/**
|
|
7
|
-
* Register a framework-specific HMR adapter
|
|
8
|
-
*
|
|
9
|
-
* @param framework - Framework name (case-insensitive)
|
|
10
|
-
* @param adapter - The adapter implementation
|
|
11
|
-
* @throws Error if adapter is invalid or already registered
|
|
12
|
-
*
|
|
13
|
-
* Requirements: 2.1-2.7
|
|
14
|
-
*/
|
|
15
|
-
register(framework, adapter) {
|
|
16
|
-
const normalizedName = framework.toLowerCase();
|
|
17
|
-
// Validate adapter
|
|
18
|
-
if (!adapter) {
|
|
19
|
-
throw new Error(`Cannot register null/undefined adapter for framework: ${framework}`);
|
|
20
|
-
}
|
|
21
|
-
if (!adapter.name) {
|
|
22
|
-
throw new Error(`Adapter for framework ${framework} must have a name property`);
|
|
23
|
-
}
|
|
24
|
-
if (typeof adapter.canHandle !== "function") {
|
|
25
|
-
throw new Error(`Adapter for framework ${framework} must implement canHandle method`);
|
|
26
|
-
}
|
|
27
|
-
if (typeof adapter.preserveState !== "function") {
|
|
28
|
-
throw new Error(`Adapter for framework ${framework} must implement preserveState method`);
|
|
29
|
-
}
|
|
30
|
-
if (typeof adapter.update !== "function") {
|
|
31
|
-
throw new Error(`Adapter for framework ${framework} must implement update method`);
|
|
32
|
-
}
|
|
33
|
-
if (typeof adapter.restoreState !== "function") {
|
|
34
|
-
throw new Error(`Adapter for framework ${framework} must implement restoreState method`);
|
|
35
|
-
}
|
|
36
|
-
if (typeof adapter.handleError !== "function") {
|
|
37
|
-
throw new Error(`Adapter for framework ${framework} must implement handleError method`);
|
|
38
|
-
}
|
|
39
|
-
// Check if already registered
|
|
40
|
-
if (this.adapters.has(normalizedName)) {
|
|
41
|
-
console.warn(`Overwriting existing HMR adapter for framework: ${framework}`);
|
|
42
|
-
}
|
|
43
|
-
this.adapters.set(normalizedName, adapter);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get an adapter for a specific framework
|
|
47
|
-
*
|
|
48
|
-
* @param framework - Framework name (case-insensitive)
|
|
49
|
-
* @returns The adapter or undefined if not found
|
|
50
|
-
*/
|
|
51
|
-
get(framework) {
|
|
52
|
-
return this.adapters.get(framework.toLowerCase());
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Check if an adapter is registered for a framework
|
|
56
|
-
*
|
|
57
|
-
* @param framework - Framework name (case-insensitive)
|
|
58
|
-
* @returns true if adapter is registered
|
|
59
|
-
*/
|
|
60
|
-
has(framework) {
|
|
61
|
-
return this.adapters.has(framework.toLowerCase());
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get all registered framework names
|
|
65
|
-
*
|
|
66
|
-
* @returns Array of registered framework names
|
|
67
|
-
*/
|
|
68
|
-
getRegisteredFrameworks() {
|
|
69
|
-
return Array.from(this.adapters.keys());
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Find an adapter that can handle a specific component
|
|
73
|
-
*
|
|
74
|
-
* Iterates through all registered adapters and returns the first one
|
|
75
|
-
* that can handle the component.
|
|
76
|
-
*
|
|
77
|
-
* @param component - The component to check
|
|
78
|
-
* @returns The adapter that can handle the component, or undefined
|
|
79
|
-
*/
|
|
80
|
-
findAdapter(component) {
|
|
81
|
-
for (const adapter of this.adapters.values()) {
|
|
82
|
-
if (adapter.canHandle(component)) {
|
|
83
|
-
return adapter;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Unregister an adapter
|
|
90
|
-
*
|
|
91
|
-
* @param framework - Framework name (case-insensitive)
|
|
92
|
-
* @returns true if adapter was removed, false if not found
|
|
93
|
-
*/
|
|
94
|
-
unregister(framework) {
|
|
95
|
-
const normalizedName = framework.toLowerCase();
|
|
96
|
-
const removed = this.adapters.delete(normalizedName);
|
|
97
|
-
return removed;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Clear all registered adapters
|
|
101
|
-
*/
|
|
102
|
-
clear() {
|
|
103
|
-
this.adapters.clear();
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Get the number of registered adapters
|
|
107
|
-
*/
|
|
108
|
-
get size() {
|
|
109
|
-
return this.adapters.size;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Base adapter class with common functionality
|
|
114
|
-
*
|
|
115
|
-
* Framework-specific adapters can extend this class to inherit common behavior
|
|
116
|
-
* and only override framework-specific methods.
|
|
117
|
-
*/
|
|
118
|
-
export class BaseFrameworkAdapter {
|
|
119
|
-
/**
|
|
120
|
-
* Default state preservation implementation
|
|
121
|
-
* Captures DOM state (scroll, focus, form values)
|
|
122
|
-
*
|
|
123
|
-
* Subclasses should override to add framework-specific state
|
|
124
|
-
*/
|
|
125
|
-
preserveState(island) {
|
|
126
|
-
try {
|
|
127
|
-
const snapshot = {
|
|
128
|
-
framework: this.name,
|
|
129
|
-
timestamp: Date.now(),
|
|
130
|
-
data: {},
|
|
131
|
-
dom: this.captureDOMState(island)
|
|
132
|
-
};
|
|
133
|
-
return snapshot;
|
|
134
|
-
} catch (error) {
|
|
135
|
-
console.warn(`Failed to preserve state for ${this.name}:`, error);
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Default state restoration implementation
|
|
141
|
-
* Restores DOM state (scroll, focus, form values)
|
|
142
|
-
*
|
|
143
|
-
* Subclasses should override to add framework-specific state restoration
|
|
144
|
-
*/
|
|
145
|
-
restoreState(island, state) {
|
|
146
|
-
try {
|
|
147
|
-
if (state.dom) {
|
|
148
|
-
this.restoreDOMState(island, state.dom);
|
|
149
|
-
}
|
|
150
|
-
} catch (error) {
|
|
151
|
-
console.warn(`Failed to restore state for ${this.name}:`, error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Default error handling implementation
|
|
156
|
-
* Shows error indicator and preserves SSR HTML
|
|
157
|
-
*/
|
|
158
|
-
handleError(island, error) {
|
|
159
|
-
console.error(`HMR error in ${this.name} island:`, error);
|
|
160
|
-
// Add error indicator
|
|
161
|
-
const errorIndicator = document.createElement("div");
|
|
162
|
-
errorIndicator.className = "hmr-error-indicator";
|
|
163
|
-
errorIndicator.style.cssText = `
|
|
164
|
-
position: absolute;
|
|
165
|
-
top: 0;
|
|
166
|
-
left: 0;
|
|
167
|
-
right: 0;
|
|
168
|
-
background: #ff4444;
|
|
169
|
-
color: white;
|
|
170
|
-
padding: 8px;
|
|
171
|
-
font-size: 12px;
|
|
172
|
-
font-family: monospace;
|
|
173
|
-
z-index: 10000;
|
|
174
|
-
border-bottom: 2px solid #cc0000;
|
|
175
|
-
`;
|
|
176
|
-
errorIndicator.textContent = `HMR Error: ${error.message}`;
|
|
177
|
-
// Remove existing error indicators
|
|
178
|
-
const existing = island.querySelector(".hmr-error-indicator");
|
|
179
|
-
if (existing) {
|
|
180
|
-
existing.remove();
|
|
181
|
-
}
|
|
182
|
-
island.style.position = "relative";
|
|
183
|
-
island.insertBefore(errorIndicator, island.firstChild);
|
|
184
|
-
// Mark island as having error
|
|
185
|
-
island.setAttribute("data-hmr-error", "true");
|
|
186
|
-
island.setAttribute("data-hmr-error-message", error.message);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Capture DOM state (scroll, focus, form values)
|
|
190
|
-
*/
|
|
191
|
-
captureDOMState(island) {
|
|
192
|
-
const dom = {};
|
|
193
|
-
// Capture scroll position
|
|
194
|
-
const scrollableElements = island.querySelectorAll("[data-preserve-scroll]");
|
|
195
|
-
if (scrollableElements.length > 0 || island.scrollTop > 0 || island.scrollLeft > 0) {
|
|
196
|
-
dom.scrollPosition = {
|
|
197
|
-
x: island.scrollLeft,
|
|
198
|
-
y: island.scrollTop
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
// Capture focused element
|
|
202
|
-
const activeElement = document.activeElement;
|
|
203
|
-
if (activeElement && island.contains(activeElement)) {
|
|
204
|
-
const selector = this.getElementSelector(activeElement);
|
|
205
|
-
if (selector) {
|
|
206
|
-
dom.focusedElement = selector;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
// Capture form values
|
|
210
|
-
const formElements = island.querySelectorAll("input, textarea, select");
|
|
211
|
-
if (formElements.length > 0) {
|
|
212
|
-
dom.formValues = {};
|
|
213
|
-
formElements.forEach((element, index) => {
|
|
214
|
-
const input = element;
|
|
215
|
-
const name = input.name || input.id || `element-${index}`;
|
|
216
|
-
if (input.type === "checkbox" || input.type === "radio") {
|
|
217
|
-
dom.formValues[name] = input.checked;
|
|
218
|
-
} else {
|
|
219
|
-
dom.formValues[name] = input.value;
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
return dom;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Restore DOM state (scroll, focus, form values)
|
|
227
|
-
*/
|
|
228
|
-
restoreDOMState(island, dom) {
|
|
229
|
-
if (!dom) return;
|
|
230
|
-
// Restore scroll position
|
|
231
|
-
if (dom.scrollPosition) {
|
|
232
|
-
island.scrollLeft = dom.scrollPosition.x;
|
|
233
|
-
island.scrollTop = dom.scrollPosition.y;
|
|
234
|
-
}
|
|
235
|
-
// Restore focused element
|
|
236
|
-
if (dom.focusedElement) {
|
|
237
|
-
try {
|
|
238
|
-
const element = island.querySelector(dom.focusedElement);
|
|
239
|
-
if (element && typeof element.focus === "function") {
|
|
240
|
-
element.focus();
|
|
241
|
-
}
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.warn("Failed to restore focus:", error);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
// Restore form values
|
|
247
|
-
if (dom.formValues) {
|
|
248
|
-
const formElements = island.querySelectorAll("input, textarea, select");
|
|
249
|
-
formElements.forEach((element, index) => {
|
|
250
|
-
const input = element;
|
|
251
|
-
const name = input.name || input.id || `element-${index}`;
|
|
252
|
-
const value = dom.formValues[name];
|
|
253
|
-
if (value !== undefined) {
|
|
254
|
-
if (input.type === "checkbox" || input.type === "radio") {
|
|
255
|
-
input.checked = value;
|
|
256
|
-
} else {
|
|
257
|
-
input.value = value;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Get a CSS selector for an element
|
|
265
|
-
*/
|
|
266
|
-
getElementSelector(element) {
|
|
267
|
-
if (element.id) {
|
|
268
|
-
return `#${element.id}`;
|
|
269
|
-
}
|
|
270
|
-
// Check if element has name attribute (for form elements)
|
|
271
|
-
const nameAttr = element.getAttribute("name");
|
|
272
|
-
if (nameAttr) {
|
|
273
|
-
return `[name="${nameAttr}"]`;
|
|
274
|
-
}
|
|
275
|
-
// Fallback to nth-child selector
|
|
276
|
-
const parent = element.parentElement;
|
|
277
|
-
if (parent) {
|
|
278
|
-
const index = Array.from(parent.children).indexOf(element);
|
|
279
|
-
return `${element.tagName.toLowerCase()}:nth-child(${index + 1})`;
|
|
280
|
-
}
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
}
|