filepond
Version:
FilePond, where files go to stretch their bits.
117 lines (116 loc) • 4.07 kB
TypeScript
import type { Locale, SpringOptions } from '../../types/index.js';
/**
* A collection of context information passed to this node
*/
export type NodeContext = {
[key: string]: any;
};
export type NodePropResourceMap = {
[componentProperty: string]: string;
};
export type NodeResources = {
locale: Locale;
assets: {
[key: string]: string;
};
};
export type NodeData = {
[key: string]: any;
};
export interface BaseNode {
/** Unique key for this node */
key?: string;
/** Select props from data and add to data for child nodes */
data?: false | ((currentData?: NodeData, currentContext?: NodeContext) => NodeData);
/** Routes to listen to */
routes?: {
[event: string]: string;
};
/** Apply transition `when` toggled */
transition?: {
fn: (node: HTMLElement, options?: {
duration?: number;
easing?: (t: number) => number;
}) => {
duration: number;
easing: (t: number) => number;
tick: (t: number) => void;
};
duration?: number;
easing?: (t: number) => number;
when: (currentData: NodeData) => boolean;
};
/**
* Automatically create springs for props, returned properties are added to context for this node
*/
spring?: (currentData: NodeData) => {
/** Property name to expose on context */
[propertyName: string]: NodeSpringProperty;
};
/** Children of this node. Falsy children are automatically filtered out */
children?: string | TemplateNode | (TemplateNode | undefined)[];
/** Single item node description to use for list based nodes */
item?: TemplateNode;
}
export interface NodeSpringProperty {
/** Value to set */
value: number | null | undefined;
/** Transform to apply to spring output */
transform?: (value: number) => number;
/** Spring configuration to use */
config?: SpringOptions;
/** Move to spring end state */
instant?: boolean;
}
export interface ElementNode extends BaseNode {
/** HTML tag, defaults to `'div'` */
tag?: string;
/** Attributes to add to the HTML element */
attrs?: {
[key: string]: any;
} | ((context: NodeContext) => {
[key: string]: any;
});
}
export interface TextNode extends BaseNode {
key: string;
children: string;
}
export interface ComponentNode extends BaseNode {
/** A Svelte component */
component: any;
/** Props to pass to the component */
props?: {
[key: string]: any;
} | ((context: NodeContext) => {
[key: string]: any;
});
}
export interface SwitchNode {
if: {
test: (currentData: NodeData, context: NodeContext) => boolean;
then: TemplateNode | TemplateNode[];
};
elseif?: {
test: (currentData: NodeData, context: NodeContext) => boolean;
then: TemplateNode | TemplateNode[];
};
else?: TemplateNode | TemplateNode[];
}
export type TemplateNode = ElementNode | ComponentNode | SwitchNode;
export interface NodeTree {
unwrap: () => void | TemplateNode | TemplateNode[];
find: (key: string) => NodeTree;
remove: (key: string) => NodeTree;
replace: (key: string, ...nodes: (NodeTree | TemplateNode)[]) => NodeTree;
update: (key: string, updater: (node: TemplateNode) => void) => NodeTree;
append: (...nodes: (NodeTree | TemplateNode | false)[]) => NodeTree;
prepend: (...nodes: (NodeTree | TemplateNode)[]) => NodeTree;
insert: (index: number, ...nodes: (NodeTree | TemplateNode)[]) => NodeTree;
}
export declare function withNodeTree(tree: void | TemplateNode | TemplateNode[]): NodeTree;
export declare function isSwitchNode(value: unknown): value is SwitchNode;
export declare function isTemplateNode(value: unknown): value is TemplateNode;
export declare function isComponentNode(value: unknown): value is ComponentNode;
export declare function isElementNode(value: unknown): value is ElementNode;
export declare function isTextNode(value: unknown): value is TextNode;