@workspace-fs/react
Version:
React hooks for Workspace-FS - Multi-project file system management
101 lines (90 loc) • 4.12 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import React from 'react';
import * as _workspace_fs_core from '@workspace-fs/core';
import { WorkspaceFileSystem, SourceProvider, ProjectConfig, Project, DeleteProjectOptions, ExportOptions, IReactiveFileSystem, WorkspaceEventPayloads } from '@workspace-fs/core';
export { DeleteProjectOptions, ExportOptions, FSEvent, FileEntry, FileStat, IReactiveFileSystem, Project, ProjectConfig, ProjectMetadata, ProjectSource, ProjectState, SourceProvider, SyncOptions, WorkspaceEventPayloads } from '@workspace-fs/core';
interface WorkspaceContextValue {
workspace: WorkspaceFileSystem;
}
interface WorkspaceProviderProps {
children: React.ReactNode;
workspace: WorkspaceFileSystem;
}
declare function WorkspaceProvider({ children, workspace, }: WorkspaceProviderProps): react_jsx_runtime.JSX.Element;
declare function useWorkspaceContext(): WorkspaceContextValue;
/**
* Get or create the singleton workspace instance
*/
declare function getWorkspace(): WorkspaceFileSystem;
/**
* Initialize workspace with providers
*/
declare function initializeWorkspace(providers?: SourceProvider[]): Promise<WorkspaceFileSystem>;
/**
* Reset workspace instance (mainly for testing)
*/
declare function resetWorkspace(): void;
/**
* Main hook to access and manage the workspace
*/
declare function useWorkspace(): {
workspace: _workspace_fs_core.WorkspaceFileSystem;
loadProject: (config: ProjectConfig) => Promise<Project>;
unloadProject: (projectId: string) => Promise<void>;
setActiveProject: (projectId: string) => Promise<void>;
deleteProject: (projectId: string, options?: DeleteProjectOptions) => Promise<void>;
enableProject: (projectId: string) => Promise<void>;
disableProject: (projectId: string) => Promise<void>;
importFromUrl: (url: string) => Promise<void>;
exportWorkspace: (options?: ExportOptions) => Promise<any>;
registerProvider: (provider: SourceProvider) => void;
};
/**
* Hook to get reactive list of all projects
*/
declare function useProjects(): {
projects: Project[];
activeProject: Project | null;
activeProjectId: string | null;
projectCount: number;
getProjectsByType: (type: string) => Project[];
searchProjects: (query: string) => Project[];
};
/**
* Hook to get a specific project by ID
* Re-renders when the project state changes
*/
declare function useProject(projectId: string | null | undefined): Project | null;
/**
* Hook to get the active project and its filesystem
* Re-renders when active project changes
*/
declare function useActiveProject(): {
project: Project | null;
fs: IReactiveFileSystem | undefined;
projectId: string | undefined;
projectName: string | undefined;
projectType: "memory" | "indexeddb" | "s3" | "json-url" | "api" | "github" | "git" | undefined;
isLoaded: boolean;
};
/**
* Hook to listen to specific workspace events
* Automatically handles subscription and cleanup
*/
declare function useWorkspaceEvents<K extends keyof WorkspaceEventPayloads>(eventName: K, callback: (payload: WorkspaceEventPayloads[K]) => void): void;
/**
* Hook to select specific data from a project with fine-grained updates
* Only re-renders when the selected value changes
*/
declare function useProjectSelector<T>(projectId: string | null | undefined, selector: (project: Project | null) => T): T;
/**
* Hook to select specific data from all projects with fine-grained updates
* Only re-renders when the selected value changes
*/
declare function useProjectsSelector<T>(selector: (projects: Project[]) => T): T;
/**
* Hook to select the active project with a selector
* Only re-renders when the selected value from active project changes
*/
declare function useActiveProjectSelector<T>(selector: (project: Project | null) => T): T;
export { WorkspaceProvider, type WorkspaceProviderProps, getWorkspace, initializeWorkspace, resetWorkspace, useActiveProject, useActiveProjectSelector, useProject, useProjectSelector, useProjects, useProjectsSelector, useWorkspace, useWorkspaceContext, useWorkspaceEvents };