@useavalon/avalon 0.1.47 → 0.1.49

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 (58) hide show
  1. package/dist/mod.d.ts +48 -49
  2. package/dist/mod.js +1 -1
  3. package/dist/src/client/components.d.ts +10 -18
  4. package/dist/src/client/components.js +1 -1
  5. package/dist/src/client/custom-directives.d.ts +25 -0
  6. package/dist/src/client/custom-directives.js +1 -0
  7. package/dist/src/client/main.js +3 -3
  8. package/dist/src/components/IslandErrorBoundary.d.ts +48 -9
  9. package/dist/src/components/IslandErrorBoundary.js +1 -1
  10. package/dist/src/components/LayoutErrorBoundary.d.ts +75 -10
  11. package/dist/src/components/LayoutErrorBoundary.js +1 -1
  12. package/dist/src/islands/builtin-directives.d.ts +15 -0
  13. package/dist/src/islands/builtin-directives.js +1 -0
  14. package/dist/src/islands/hydration-directives.d.ts +89 -0
  15. package/dist/src/islands/hydration-directives.js +1 -0
  16. package/dist/src/islands/integration-loader.d.ts +2 -2
  17. package/dist/src/islands/island.d.ts +11 -9
  18. package/dist/src/islands/island.js +1 -1
  19. package/dist/src/islands/types.d.ts +4 -2
  20. package/dist/src/layout-system.d.ts +14 -30
  21. package/dist/src/layout-system.js +1 -1
  22. package/dist/src/nitro/config.d.ts +3 -3
  23. package/dist/src/nitro/renderer.d.ts +18 -5
  24. package/dist/src/nitro/renderer.js +11 -11
  25. package/dist/src/persistence/island-state-serializer.d.ts +9 -0
  26. package/dist/src/persistence/island-state-serializer.js +1 -0
  27. package/dist/src/persistence/use-persistent-state.d.ts +31 -0
  28. package/dist/src/persistence/use-persistent-state.js +1 -0
  29. package/dist/src/prerender/index.d.ts +1 -1
  30. package/dist/src/prerender/prerender.d.ts +1 -1
  31. package/dist/src/prerender/prerender.js +1 -1
  32. package/dist/src/schemas/core.d.ts +2 -2
  33. package/dist/src/schemas/layout.d.ts +5 -5
  34. package/dist/src/schemas/layout.js +1 -1
  35. package/dist/src/schemas/routing/index.d.ts +2 -2
  36. package/dist/src/schemas/routing.d.ts +4 -4
  37. package/dist/src/types/island-prop.d.ts +14 -6
  38. package/dist/src/types/layout.d.ts +11 -19
  39. package/dist/src/types/layout.js +1 -1
  40. package/dist/src/vite-plugin/nitro-integration.d.ts +3 -3
  41. package/dist/src/vite-plugin/nitro-integration.js +14 -14
  42. package/package.json +2 -2
  43. package/dist/src/components/LayoutDataErrorBoundary.d.ts +0 -34
  44. package/dist/src/components/LayoutDataErrorBoundary.js +0 -1
  45. package/dist/src/components/PersistentIsland.d.ts +0 -36
  46. package/dist/src/components/PersistentIsland.js +0 -1
  47. package/dist/src/components/StreamingErrorBoundary.d.ts +0 -42
  48. package/dist/src/components/StreamingErrorBoundary.js +0 -1
  49. package/dist/src/components/StreamingLayout.d.ts +0 -83
  50. package/dist/src/components/StreamingLayout.js +0 -29
  51. package/dist/src/core/islands/island-persistence.d.ts +0 -74
  52. package/dist/src/core/islands/island-persistence.js +0 -1
  53. package/dist/src/core/islands/island-state-serializer.d.ts +0 -53
  54. package/dist/src/core/islands/island-state-serializer.js +0 -1
  55. package/dist/src/core/islands/persistent-island-context.d.ts +0 -36
  56. package/dist/src/core/islands/persistent-island-context.js +0 -1
  57. package/dist/src/core/islands/use-persistent-state.d.ts +0 -17
  58. package/dist/src/core/islands/use-persistent-state.js +0 -1
@@ -1,74 +0,0 @@
1
- import type { IslandState } from '../../schemas/layout.ts';
2
- import type { IIslandPersistence } from '../../types/layout.ts';
3
- /**
4
- * IslandPersistence class for state management across navigation
5
- *
6
- * Handles saving, loading, and clearing island state using browser storage
7
- * with support for both sessionStorage and localStorage persistence strategies.
8
- */
9
- export declare class IslandPersistence implements IIslandPersistence {
10
- private storageType;
11
- private keyPrefix;
12
- private storage;
13
- constructor(options?: {
14
- storageType?: 'session' | 'local';
15
- keyPrefix?: string;
16
- });
17
- /**
18
- * Save island state to browser storage
19
- */
20
- saveState(id: string, state: IslandState): void;
21
- /**
22
- * Load island state from browser storage
23
- */
24
- loadState(id: string): IslandState | null;
25
- /**
26
- * Clear island state from browser storage
27
- */
28
- clearState(id: string): void;
29
- /**
30
- * Check if state exists for an island
31
- */
32
- hasState(id: string): boolean;
33
- /**
34
- * Get all stored island IDs
35
- */
36
- getStoredIds(): string[];
37
- /**
38
- * Clear all stored states
39
- */
40
- clearAllStates(): void;
41
- /**
42
- * Get the storage key for an island ID
43
- */
44
- private getStorageKey;
45
- /**
46
- * Get current storage configuration
47
- */
48
- getConfig(): {
49
- storageType: string;
50
- keyPrefix: string;
51
- available: boolean;
52
- };
53
- /**
54
- * Get storage usage statistics
55
- */
56
- getStorageStats(): {
57
- totalKeys: number;
58
- islandKeys: number;
59
- estimatedSize: number;
60
- };
61
- /**
62
- * JSON.stringify replacer function to handle special types
63
- */
64
- private replacer;
65
- /**
66
- * JSON.parse reviver function to restore special types
67
- */
68
- private reviver;
69
- }
70
- /**
71
- * Default island persistence instance
72
- * Uses sessionStorage by default for better privacy and performance
73
- */
74
- export declare const defaultIslandPersistence: IslandPersistence;
@@ -1 +0,0 @@
1
- import{IslandStateSerializer as e}from"./island-state-serializer.js";export class IslandPersistence{storageType;keyPrefix;storage=null;constructor(e={}){this.storageType=e.storageType||`session`,this.keyPrefix=e.keyPrefix||`island-state`,typeof window<`u`&&(this.storage=this.storageType===`session`?sessionStorage:localStorage)}saveState(t,n){if(!this.storage){console.warn(`Island persistence: Storage not available (server-side or unsupported browser)`);return}try{let r=this.getStorageKey(t),i=e.serialize({state:n,timestamp:Date.now(),version:`1.0`});this.storage.setItem(r,i),console.log(`Island state saved for ${t}`)}catch(e){console.error(`Failed to save island state for ${t}:`,e)}}loadState(t){if(!this.storage)return console.warn(`Island persistence: Storage not available (server-side or unsupported browser)`),null;try{let n=this.getStorageKey(t),r=this.storage.getItem(n);if(!r)return null;let i=e.deserialize(r);return!i.state||!i.timestamp||!i.version?(console.warn(`Invalid island state format for ${t}, clearing...`),this.clearState(t),null):(console.log(`Island state loaded for ${t}`),i.state)}catch(e){return console.error(`Failed to load island state for ${t}:`,e),this.clearState(t),null}}clearState(e){if(this.storage)try{let t=this.getStorageKey(e);this.storage.removeItem(t),console.log(`Island state cleared for ${e}`)}catch(t){console.error(`Failed to clear island state for ${e}:`,t)}}hasState(e){if(!this.storage)return!1;try{let t=this.getStorageKey(e);return this.storage.getItem(t)!==null}catch(t){return console.error(`Failed to check island state for ${e}:`,t),!1}}getStoredIds(){if(!this.storage)return[];try{let e=[],t=this.keyPrefix.length+1;for(let n=0;n<this.storage.length;n++){let r=this.storage.key(n);r&&r.startsWith(this.keyPrefix+`:`)&&e.push(r.substring(t))}return e}catch(e){return console.error(`Failed to get stored island IDs:`,e),[]}}clearAllStates(){if(this.storage)try{let e=[];for(let t=0;t<this.storage.length;t++){let n=this.storage.key(t);n&&n.startsWith(this.keyPrefix+`:`)&&e.push(n)}e.forEach(e=>this.storage.removeItem(e)),console.log(`Cleared ${e.length} island states`)}catch(e){console.error(`Failed to clear all island states:`,e)}}getStorageKey(e){return`${this.keyPrefix}:${e}`}getConfig(){return{storageType:this.storageType,keyPrefix:this.keyPrefix,available:this.storage!==null}}getStorageStats(){if(!this.storage)return{totalKeys:0,islandKeys:0,estimatedSize:0};try{let e=0,t=0;for(let n=0;n<this.storage.length;n++){let r=this.storage.key(n);if(r&&r.startsWith(this.keyPrefix+`:`)){e++;let n=this.storage.getItem(r);n&&(t+=r.length+n.length)}}return{totalKeys:this.storage.length,islandKeys:e,estimatedSize:t}}catch(e){return console.error(`Failed to get storage stats:`,e),{totalKeys:0,islandKeys:0,estimatedSize:0}}}replacer(e,t){return t instanceof Date?{__type:`Date`,__value:t.toISOString()}:t instanceof RegExp?{__type:`RegExp`,__value:{source:t.source,flags:t.flags}}:t instanceof Map?{__type:`Map`,__value:Array.from(t.entries())}:t instanceof Set?{__type:`Set`,__value:Array.from(t.values())}:typeof t==`function`?(console.warn(`Function found in island state at key "${e}", converting to null`),null):t===void 0?null:t}reviver(e,t){if(t&&typeof t==`object`){let e=t;if(e.__type&&e.__value!==void 0)switch(e.__type){case`Date`:return new Date(e.__value);case`RegExp`:{let t=e.__value;return new RegExp(t.source,t.flags)}case`Map`:return new Map(e.__value);case`Set`:return new Set(e.__value);default:return console.warn(`Unknown special type "${e.__type}" in serialized state`),e.__value}}return t}}export const defaultIslandPersistence=new IslandPersistence({storageType:`session`,keyPrefix:`island-state`});
@@ -1,53 +0,0 @@
1
- import type { IslandState } from '../../schemas/layout.ts';
2
- /**
3
- * Island State Serializer
4
- *
5
- * Handles serialization and deserialization of island state for browser storage.
6
- * Supports complex data types including Dates, RegExp, and circular references.
7
- */
8
- export declare class IslandStateSerializer {
9
- /**
10
- * Serialize island state to JSON string
11
- */
12
- static serialize(state: IslandState): string;
13
- /**
14
- * Deserialize JSON string to island state
15
- */
16
- static deserialize(serializedState: string): IslandState;
17
- /**
18
- * Transform state for serialization, handling special types
19
- */
20
- private static transformForSerialization;
21
- /**
22
- * JSON.parse reviver function to restore special types
23
- */
24
- private static reviver;
25
- /**
26
- * Validate that state can be safely serialized
27
- */
28
- static validate(state: IslandState): {
29
- valid: boolean;
30
- errors: string[];
31
- };
32
- /**
33
- * Get size information for serialized state
34
- */
35
- static getSize(state: IslandState): {
36
- bytes: number;
37
- kilobytes: number;
38
- megabytes: number;
39
- readable: string;
40
- };
41
- /**
42
- * Deep clone state object (useful for preventing mutations)
43
- */
44
- static clone(state: IslandState): IslandState;
45
- /**
46
- * Compare two states for equality
47
- */
48
- static equals(state1: IslandState, state2: IslandState): boolean;
49
- /**
50
- * Sanitize state by removing non-serializable values
51
- */
52
- static sanitize(state: IslandState): IslandState;
53
- }
@@ -1 +0,0 @@
1
- export class IslandStateSerializer{static serialize(t){try{let n=IslandStateSerializer.transformForSerialization(t);return JSON.stringify(n)}catch(e){throw console.error(`Failed to serialize island state:`,e),Error(`State serialization failed: ${e instanceof Error?e.message:String(e)}`)}}static deserialize(t){try{return JSON.parse(t,IslandStateSerializer.reviver)}catch(e){throw console.error(`Failed to deserialize island state:`,e),Error(`State deserialization failed: ${e instanceof Error?e.message:String(e)}`)}}static transformForSerialization(t){if(t===null)return t;if(t===void 0)return null;if(t instanceof Date)return{__type:`Date`,__value:t.toISOString()};if(t instanceof RegExp)return{__type:`RegExp`,__value:{source:t.source,flags:t.flags}};if(t instanceof Map)return{__type:`Map`,__value:Array.from(t.entries()).map(([t,n])=>[IslandStateSerializer.transformForSerialization(t),IslandStateSerializer.transformForSerialization(n)])};if(t instanceof Set)return{__type:`Set`,__value:Array.from(t.values()).map(t=>IslandStateSerializer.transformForSerialization(t))};if(typeof t==`function`)return console.warn(`Function found in island state, converting to null`),null;if(Array.isArray(t))return t.map(t=>IslandStateSerializer.transformForSerialization(t));if(typeof t==`object`){let n={},r=t;for(let t in r)Object.hasOwn(r,t)&&(n[t]=IslandStateSerializer.transformForSerialization(r[t]));return n}return t}static reviver(e,t){if(t&&typeof t==`object`){let e=t;if(e.__type&&e.__value!==void 0)switch(e.__type){case`Date`:return new Date(e.__value);case`RegExp`:{let t=e.__value;return new RegExp(t.source,t.flags)}case`Map`:return new Map(e.__value);case`Set`:return new Set(e.__value);case`undefined`:return null;default:return console.warn(`Unknown special type "${typeof e.__type==`string`?e.__type:`non-string`}" in serialized state`),e.__value}}return t}static validate(e){let t=[];try{let n=this.serialize(e),r=new Blob([n]).size,i=5*1024*1024;r>i&&t.push(`Serialized state size (${Math.round(r/1024)}KB) exceeds recommended limit (${Math.round(i/1024)}KB)`),this.deserialize(n)}catch(e){t.push(e instanceof Error?e.message:String(e))}return{valid:t.length===0,errors:t}}static getSize(e){try{let t=this.serialize(e),n=new Blob([t]).size,r=n/1024,i=r/1024,a;return a=i>=1?`${i.toFixed(2)} MB`:r>=1?`${r.toFixed(2)} KB`:`${n} bytes`,{bytes:n,kilobytes:r,megabytes:i,readable:a}}catch(e){return console.error(`Failed to calculate state size:`,e),{bytes:0,kilobytes:0,megabytes:0,readable:`0 bytes`}}}static clone(e){try{let t=this.serialize(e);return this.deserialize(t)}catch(t){return console.error(`Failed to clone island state:`,t),{...e}}}static equals(e,t){try{return this.serialize(e)===this.serialize(t)}catch(e){return console.error(`Failed to compare island states:`,e),!1}}static sanitize(e){try{let t=this.serialize(e);return this.deserialize(t)}catch(e){return console.error(`Failed to sanitize island state:`,e),{}}}}
@@ -1,36 +0,0 @@
1
- import type { ComponentChildren } from 'preact';
2
- import type { IslandState } from '../../schemas/layout.ts';
3
- import { defaultIslandPersistence } from './island-persistence.ts';
4
- /**
5
- * Explicit interface for persistent island context
6
- * (Zod z.any() inference for function types is unreliable)
7
- */
8
- export interface PersistentIslandContextType {
9
- saveState: (state: IslandState) => void;
10
- loadState: () => IslandState | null;
11
- clearState: () => void;
12
- }
13
- /**
14
- * Context for persistent island state operations
15
- *
16
- * Provides save, load, and clear operations for island state management
17
- * across navigation and browser sessions.
18
- */
19
- export declare const PersistentIslandContextProvider: import("preact").Context<PersistentIslandContextType>;
20
- /**
21
- * Create a persistent island context for a specific island ID
22
- */
23
- export declare function createPersistentIslandContext(persistentId: string, persistence?: import("./island-persistence.ts").IslandPersistence): PersistentIslandContextType;
24
- /**
25
- * Hook to use persistent island context
26
- * Must be used within a PersistentIsland component
27
- */
28
- export declare function usePersistentIslandContext(): PersistentIslandContextType;
29
- /**
30
- * Provider component for persistent island context
31
- */
32
- export declare function PersistentIslandProvider({ persistentId, children, persistence, }: Readonly<{
33
- persistentId: string;
34
- children: ComponentChildren;
35
- persistence?: typeof defaultIslandPersistence;
36
- }>): import("preact").JSX.Element;
@@ -1 +0,0 @@
1
- import{createContext as e}from"preact";import{useContext as t}from"preact/hooks";import{defaultIslandPersistence as n}from"./island-persistence.js";import{jsx as r}from"preact/jsx-runtime";export const PersistentIslandContextProvider=e(null);export function createPersistentIslandContext(e,t=n){return{saveState:n=>{t.saveState(e,n)},loadState:()=>t.loadState(e),clearState:()=>{t.clearState(e)}}}export function usePersistentIslandContext(){let e=t(PersistentIslandContextProvider);if(!e)throw Error(`usePersistentIslandContext must be used within a PersistentIsland component`);return e}export function PersistentIslandProvider({persistentId:e,children:t,persistence:i=n}){let a=createPersistentIslandContext(e,i);return r(PersistentIslandContextProvider.Provider,{value:a,children:t})}
@@ -1,17 +0,0 @@
1
- /**
2
- * Hook for persistent island state — like useState but survives navigations.
3
- *
4
- * State is serialized to sessionStorage (supports Date, Map, Set, RegExp).
5
- * On the server or when storage is unavailable, falls back to in-memory state.
6
- *
7
- * ```tsx
8
- * const [count, setCount, clearCount] = usePersistentState('my-counter', 0);
9
- * ```
10
- *
11
- * @param id - Unique storage key for this piece of state
12
- * @param initialValue - Default value when no persisted state exists
13
- * @param options - Optional: `storage` ('session' | 'local'), defaults to 'session'
14
- */
15
- export declare function usePersistentState<T>(id: string, initialValue: T, options?: {
16
- storage?: 'session' | 'local';
17
- }): [T, (value: T | ((prev: T) => T)) => void, () => void];
@@ -1 +0,0 @@
1
- import{useState as e,useEffect as t,useCallback as n}from"preact/hooks";import{IslandStateSerializer as r}from"./island-state-serializer.js";export function usePersistentState(i,a,o){let s=o?.storage??`session`,c=`avalon-island:${i}`,[l,u]=e(()=>{if(typeof window>`u`)return a;try{let e=(s===`local`?localStorage:sessionStorage).getItem(c);return e===null?a:r.deserialize(e).v??a}catch{return a}});return t(()=>{if(!(typeof window>`u`))try{(s===`local`?localStorage:sessionStorage).setItem(c,r.serialize({v:l}))}catch{}},[l,c,s]),[l,n(e=>{u(t=>typeof e==`function`?e(t):e)},[]),n(()=>{if(u(a),!(typeof window>`u`))try{(s===`local`?localStorage:sessionStorage).removeItem(c)}catch{}},[a,c,s])]}