UNPKG

@glyphtek/unspecd

Version:

A declarative UI framework for building internal tools and dashboards with TypeScript. Create interactive tables, forms, and dashboards using simple specifications.

176 lines 5.73 kB
/** * Main entry point for the Unspec'd Framework * * This file exports the UnspecdUI class, which serves as the primary interface * for developers to initialize and manage their declarative UI tools. * * The UnspecdUI class handles tool registration, normalization, and provides * a high-level API for rendering tools within applications. */ import type { ToolSpec } from './dsl-schema.js'; export type { ToolSpec }; /** * Configuration object for tool registration in UnspecdUI. * Tools can be provided either as raw ToolSpec objects or with custom descriptions. */ export interface ToolConfig { /** The display description for navigation (overrides spec.title) */ description: string; /** The tool specification defining the behavior and content */ spec: ToolSpec; /** Optional file path for copy command functionality */ filePath?: string; } /** * Configuration object for the UnspecdUI constructor. */ export interface UnspecdUIConfig { /** Array of tool specifications or tool configurations to register */ tools: Array<ToolSpec | ToolConfig>; /** Enable focus mode to hide sidebar and show single tool directly */ focusMode?: boolean; /** Application title displayed in the UI */ title?: string; /** Default server port (can be overridden in startServer) */ port?: number; } /** * Normalized internal representation of a registered tool. * All tools are converted to this consistent format internally. */ interface NormalizedTool { /** Unique identifier for the tool (from ToolSpec.id) */ id: string; /** Display title for navigation and UI */ title: string; /** The complete tool specification */ spec: ToolSpec; /** Optional file path for copy command functionality */ filePath?: string; } /** * Main class for the Unspec'd Framework providing high-level developer experience. * * The UnspecdUI class serves as the primary entry point for developers who want to * create declarative UI applications. It handles tool registration, normalization, * and provides methods for rendering and managing tools. * * @example * ```typescript * import { UnspecdUI } from '@unspecd/core'; * import { myToolSpec } from './my-tool'; * * const ui = new UnspecdUI({ * tools: [ * myToolSpec, * { * description: 'Custom Tool Name', * spec: anotherToolSpec * } * ] * }); * * ui.init(document.getElementById('app')); * ``` */ export declare class UnspecdUI { #private; /** * Creates a new UnspecdUI instance with the provided tool specifications. * * The constructor processes the incoming tools array and normalizes all entries * into a consistent internal format. This allows developers to provide tools * either as raw ToolSpec objects or with custom navigation descriptions. * * @param config - Configuration object containing the tools to register * @param config.tools - Array of ToolSpec objects or ToolConfig objects * * @example * ```typescript * // Using raw ToolSpec objects * const ui = new UnspecdUI({ * tools: [toolSpec1, toolSpec2] * }); * * // Using custom descriptions * const ui = new UnspecdUI({ * tools: [ * { description: 'User Management', spec: userToolSpec }, * { description: 'System Settings', spec: settingsToolSpec } * ] * }); * * // Mixed approach * const ui = new UnspecdUI({ * tools: [ * rawToolSpec, * { description: 'Custom Name', spec: anotherToolSpec } * ] * }); * ``` */ constructor(config: UnspecdUIConfig); /** * Initializes the UnspecdUI instance and renders it to the target element. * * This method handles the complete initialization process, including container * setup, layout rendering, and basic structure creation. If no target element * is provided, it looks for #root in the document or creates a default container. * * @param targetElement - Optional DOM element to render the UI into. * If not provided, uses #root or creates a default container. * * @example * ```typescript * const ui = new UnspecdUI({ tools: [myToolSpec] }); * * // Initialize with specific target element * ui.init(document.getElementById('app')); * * // Initialize with automatic container detection (#root or create new) * ui.init(); * ``` */ init(targetElement?: HTMLElement): void; /** * Public API: Get the number of registered tools. * * @returns The number of tools currently registered */ get toolCount(): number; /** * Public API: Get a summary of all registered tools. * * @returns Array of tool summaries with id and title */ get toolSummary(): Array<{ id: string; title: string; }>; /** * Public API: Get all registered tools with full specifications. * Returns the complete normalized tool objects for library mode entry generation. * * @returns Array of normalized tool objects */ get tools(): NormalizedTool[]; /** * Public API: Get the focus mode state. * * @returns Whether this instance is in focus mode */ get focusMode(): boolean; /** * Public API: Get the application title. * * @returns The application title if set */ get title(): string | undefined; /** * Public API: Get the default server port. * * @returns The default server port if set */ get port(): number | undefined; } //# sourceMappingURL=index.d.ts.map