filepond
Version:
FilePond, where files go to stretch their bits.
69 lines (68 loc) • 3.29 kB
TypeScript
import type { EntryTreeOn } from '../../core/entryTree.js';
import type { ExtensionManagerOn } from '../../core/extensionManager.js';
import type { EntrySource, ExtensionContext, ExtensionOptions, Locale, TemplateNode } from '../../types/index.js';
import { type Extension } from './createExtension.js';
interface SourceExtensionEvents {
dialogOpen: HTMLElement;
dialogClosed: HTMLElement;
}
export type SourceExtensionOn = <EventName extends keyof SourceExtensionEvents>(event: EventName, callback: (detail: SourceExtensionEvents[EventName]) => void) => () => void;
type SourceExtensionResolvedOptions = SourceExtensionOptions & {
/** Name to use for getting input element value */
inputAttributes: {
name: string;
};
};
type SourceExtensionResolvedProps<Props extends object = SourceExtensionOptions> = SourceExtensionResolvedOptions & Required<Props>;
interface SourceExtensionState<Props extends object = SourceExtensionOptions> extends Omit<ExtensionOptions, 'props' | 'didSetProps'> {
props: SourceExtensionResolvedProps<Props>;
didSetProps: (cb: (props: SourceExtensionResolvedProps<Props>) => void) => void;
}
type SourceFactory<Props extends object = SourceExtensionOptions> = (instance: SourceExtensionState<Props>, api: ExtensionContext & {
setExtensionSourceState: (newSourceState: {
[key: string]: any;
}) => void;
on: EntryTreeOn & ExtensionManagerOn & SourceExtensionOn;
}) => SourceExtensionFunctions;
export type SourceExtensionCreateSourceTemplateFunction = (inputAttributes: {
[key: string]: string | boolean | number;
}) => TemplateNode[];
export type SourceExtensionDestroyFunction = () => void;
interface SourceExtensionFunctions {
createSourceTemplate: SourceExtensionCreateSourceTemplateFunction;
destroy?: SourceExtensionDestroyFunction;
}
export interface SourceExtensionOptions {
/** Locale to use */
locale?: Locale;
/** Is this source disabled */
disabled?: boolean;
/** Where to add new files, defaults to index `0` */
insertIndex?: number;
/** Label to use for source button, defaults to `undefined` */
sourceLabel?: string;
/** Icon to use for source button, defaults to `undefined` */
sourceIcon?: string;
/** Icon to use for source button when source in error state, defaults to `undefined` */
sourceIconError?: string;
/** The type of source */
sourceType?: string;
/** The element to add */
sourceElement?: HTMLElement;
/** Name to use for getting input element value */
inputAttributes?: {
[key: string]: string | boolean | number;
};
/** Hook into submit */
beforeInsertSource?: (src: EntrySource, props: any) => EntrySource | false | undefined | null;
}
export interface CreateSourceExtensionOptions<Props extends object = SourceExtensionOptions> {
/** The name of the extension */
name: string;
/** The default properties available to this extension */
props: Props & Partial<SourceExtensionOptions>;
/** The factory function that runs when the extension is created */
factory: SourceFactory<Props>;
}
export declare function createSourceExtension<Props extends object = SourceExtensionOptions>(options: CreateSourceExtensionOptions<Props>): Extension;
export {};