@hadyfayed/filament-react-wrapper
Version:
Enterprise React integration for Laravel/Filament - Smart asset loading, 90%+ React-PHP function mapping, no-plugin Filament integration
101 lines • 3.76 kB
TypeScript
import { default as React, ReactNode } from 'react';
interface GlobalStateManagerInterface {
setState(path: string, value: unknown): void;
getState<T = unknown>(path: string): T | undefined;
subscribe(path: string, callback: (value: unknown) => void): () => void;
reset(): void;
}
declare global {
interface Window {
workflowDataSync?: (statePath: string, data: any) => void;
globalStateManager?: GlobalStateManagerInterface;
}
}
export interface StateManagerState {
[key: string]: unknown;
}
export interface StateAction {
type: "SET_STATE" | "UPDATE_STATE" | "RESET_STATE" | "BATCH_UPDATE";
payload: unknown;
path?: string;
}
export interface StateManagerContextType {
state: StateManagerState;
setState: (path: string, value: unknown) => void;
updateState: (path: string, updater: (current: unknown) => unknown) => void;
getState: (path: string) => unknown;
resetState: () => void;
batchUpdate: (updates: Array<{
path: string;
value: unknown;
}>) => void;
subscribe: (path: string, callback: (value: unknown) => void) => () => void;
}
export declare const StateManagerContext: React.Context<StateManagerContextType | null>;
export interface StateManagerProviderProps {
children: ReactNode;
initialState?: StateManagerState;
onStateChange?: (state: StateManagerState) => void;
syncPath?: string;
}
export declare const StateManagerProvider: React.FC<StateManagerProviderProps>;
export declare const useStateManager: () => StateManagerContextType;
export declare const useStatePath: <T = unknown>(path: string, defaultValue?: T) => [T, (value: T | ((prev: T) => T)) => void];
export declare function withStateManager<P extends object>(Component: React.ComponentType<P>, options?: {
initialState?: StateManagerState;
syncPath?: string;
onStateChange?: (state: StateManagerState) => void;
}): React.FC<P>;
export declare class GlobalStateManager implements GlobalStateManagerInterface {
private _state;
readonly subscribers: Map<string, Set<(value: unknown) => void>>;
private _notifyingPaths?;
get state(): StateManagerState;
/**
* Sets a value at the specified path in the state
* @param path Dot-notation path to set value at
* @param value Value to set
*/
setState(path: string, value: unknown): void;
/**
* Gets a value from the specified path in the state
* @param path Dot-notation path to get value from
* @returns The value at the specified path or undefined
*/
getState<T = unknown>(path: string): T | undefined;
/**
* Subscribes to changes at the specified path
* @param path Dot-notation path to subscribe to
* @param callback Function to call when value changes
* @returns Unsubscribe function
*/
subscribe(path: string, callback: (value: unknown) => void): () => void;
/**
* Notifies subscribers of changes at a specific path and its parent paths
* @param path Path that was changed
* @param value New value at the path
*/
notifySubscribers(path: string, value: unknown): void;
/**
* Update state with a function
*/
updateState(path: string, updater: (current: unknown) => unknown): void;
/**
* Reset state with optional new state
*/
resetState(newState?: StateManagerState): void;
/**
* Batch update multiple paths
*/
batchUpdate(updates: Array<{
path: string;
value: unknown;
}>): void;
/**
* Resets the state and clears all subscribers (legacy method)
*/
reset(): void;
}
export declare const globalStateManager: GlobalStateManager;
export {};
//# sourceMappingURL=StateManager.d.ts.map