import { DependencyList } from 'react'; import { DialSchema } from '@vuer-ai/vuer-uikit'; import { DialControlSchema, OnChangeCallback } from './dialControlsStore'; /** * Options for customizing dial control behavior */ export interface CustomDialControlOptions { /** If false, automatically cleanup on unmount (default: true) */ persist?: boolean; /** Category tag for filtering controls (default: 'global') */ category?: string; /** If false, controls will not be registered/displayed (default: true) */ enabled?: boolean; /** * If true, component re-renders when values change (default: true) * Set to false for performance optimization when only using get/set */ reactive?: boolean; /** * Tags for panel filtering (replaces displayKey-based filtering) * Panels can filter by tags to show only matching controls * When not provided, defaults to [key] for convenient filtering */ tags?: string[]; /** * Callback when values change (from panel interaction or set() calls) * Receives full context including source and schema ownership info */ onChange?: OnChangeCallback; } /** * Return type for dial control hooks */ export interface DialControlResult { /** Current values for all controls */ values: Record; /** Get a specific value by name */ get: (name: string) => T; /** Set a specific value by name (also triggers onChange) */ set: (name: string, value: any) => void; /** The registration ID for this hook instance */ registrationId: string | null; } /** * Low-level hook to register and manage dial controls with full customization * * This is the base API that allows full control over all options including category. * For most use cases, consider using `useDialControls` or `useGlobalDialControls` instead. * * @param key - Display key for this control set (used for data grouping and value sharing) * @param schemaConfig - Schema configuration with schemas and optional groups * @param options - Optional configuration options * @param deps - Dependency list to control when schemas are re-registered (default: []) * Similar to useEffect's dependency array. Only re-register when these deps change. * @returns Object containing { values, get, set, registrationId } * * @remarks * Multiple components can use the same key - each gets its own registration. * When a component unmounts, only its registration is removed. * Values are shared across all components using the same key. * * The `deps` parameter controls when the schemas are re-registered: * - `[]` (default): Register only once on mount * - `[value1, value2]`: Re-register when any of these values change * - Use this when your schema contains dynamic values or functions * * The `enabled` option allows you to conditionally show/hide controls: * - When set to `false`, the controls are removed from the store * - When set to `true` (default), the controls are registered and visible * * The `reactive` option controls re-render behavior: * - When set to `true` (default), component re-renders when values change * - When set to `false`, no re-renders on value changes (use get/set only) * * The `tags` option is used for panel filtering: * - When not provided, defaults to [key] for convenient filtering * - Panels can filter by tags to show controls matching specific tags * - This decouples display filtering from data grouping (displayKey) * * The `onChange` callback is called when values change: * - From panel interaction (source: 'panel') * - From set() calls (source: 'set') * - Provides meta info including isSchemaOwner to filter by ownership * * @example * ```tsx * // Basic usage with destructuring * const { values, get, set } = useCustomDialControls('lighting-controls', { * schemas: [ * { name: 'intensity', dtype: 'number', value: 1.0 }, * ], * }, { category: 'lighting' }); * * // With tags for panel filtering * const { values } = useCustomDialControls('joint-controls', { * schemas: jointSchemas, * }, { * category: 'default', * tags: [nodeKey], // Panel filters by this tag * }); * * // With onChange callback for external updates (e.g., to sceneStore) * const { values } = useCustomDialControls('robot-controls', { * schemas: jointSchemas, * }, { * tags: [controlKey], * reactive: false, // No re-renders needed * onChange: (name, value, values, meta) => { * if (!meta.isSchemaOwner) return; // Only handle own schemas * // Update external store * ops.update({ ... }); * }, * }); * * // Performance optimization: non-reactive mode (no re-renders) * const { get, set } = useCustomDialControls('perf-controls', { * schemas: [{ name: 'value', dtype: 'number', value: 0 }], * }, { reactive: false }); * * // Multiple components using same key (schemas are merged) * // ComponentA: * const { values: valuesA } = useDialControls('robot', [{ name: 'speed', ... }]); * // ComponentB: * const { values: valuesB } = useDialControls('robot', [{ name: 'power', ... }]); * // Panel shows both 'speed' and 'power', values are shared * ``` */ export declare function useCustomDialControls(key: string, schemaConfig: DialControlSchema | DialSchema[], options?: CustomDialControlOptions, deps?: DependencyList): DialControlResult; /** * Hook to manually trigger cleanup of dial control values * * Note: In the new registration-based architecture, unregistering happens * automatically when components unmount. This hook is for manually clearing * the persisted values for a displayKey. * * @example * ```tsx * const clearMyValues = useDialControlsCleanup('my-controls'); * * // Call when you want to clear the values * const handleReset = () => { * clearMyValues(); * }; * ``` */ export declare function useDialControlsCleanup(key: string): () => void; export type { DialControlSchema, OnChangeCallback, OnChangeMeta } from './dialControlsStore';