@humanspeak/svelte-render
Version:
Manage complex Svelte behaviors outside of templates with full type safety
93 lines (92 loc) • 3.52 kB
TypeScript
import type { Component, ComponentProps } from 'svelte';
import type { Readable } from 'svelte/store';
/**
* Configuration type for rendering Svelte components or primitive values
* @template TComponent - The Svelte component type
*/
export type RenderConfig<TComponent extends Component = Component<any>> = ComponentRenderConfig<TComponent> | string | number | Readable<string | number>;
/**
* Configuration class for rendering Svelte components with props and slots
* @template TComponent - The Svelte component type
*/
export declare class ComponentRenderConfig<TComponent extends Component = Component<any>> {
/**
* The Svelte component to render
*/
component: TComponent;
/**
* Optional props to pass to the component
*/
props?: Record<string, unknown> | undefined;
/**
* Creates a new component render configuration
* @param component - The Svelte component to render
* @param props - Optional props to pass to the component
*/
constructor(
/**
* The Svelte component to render
*/
component: TComponent,
/**
* Optional props to pass to the component
*/
props?: Record<string, unknown> | undefined);
/**
* @deprecated This method will be removed in the next major release. Please use svelte-5 event syntax instead.
* List of event handlers to attach to the component
*/
eventHandlers: [string, (ev: any) => void][];
/**
* @deprecated This method will be removed in the next major release. Please use svelte-5 event syntax instead.
*
* Attaches an event handler to the component
* @param type - The event type to listen for
* @param handler - The event handler function
* @returns this - For method chaining
*/
on<TEventType extends string, TEvent = any>(type: TEventType, handler: (ev: TEvent) => void): this;
/**
* List of child components to render in the default slot
*/
children: RenderConfig[];
/**
* Sets the children to render in the default slot
* @param children - The child components to render
* @returns this - For method chaining
*/
slot(...children: RenderConfig[]): this;
}
/**
* Creates a render configuration for a Svelte component without props
* @template TComponent - The Svelte component type
* @param component - The component to render
* @returns A new ComponentRenderConfig instance
* @example
* ```svelte
* <script>
* import { createRender } from 'svelte-render'
* import MyComponent from './MyComponent.svelte'
*
* const config = createRender(MyComponent)
* </script>
* ```
*/
export declare function createRender<TComponent extends Component<any>>(component: TComponent): ComponentRenderConfig<TComponent>;
/**
* Creates a render configuration for a Svelte component with props
* @template TComponent - The Svelte component type
* @param component - The component to render
* @param props - The props to pass to the component, can be static or reactive
* @returns A new ComponentRenderConfig instance
* @example
* ```svelte
* <script>
* import { createRender } from 'svelte-render'
* import MyComponent from './MyComponent.svelte'
*
* const config = createRender(MyComponent, { name: 'World' })
* </script>
* ```
*/
export declare function createRender<TComponent extends Component<any>>(component: TComponent, props: Partial<ComponentProps<TComponent>> | Readable<ComponentProps<TComponent>>): ComponentRenderConfig<TComponent>;