h5p-utils
Version:
A set of utility classes and functions to be used when creating H5P widgets and content types.
56 lines (50 loc) • 3.2 kB
text/typescript
import * as h5p_types from 'h5p-types';
import { IH5PResumableType, H5PExtras, H5PField, ParamTypeInferredFromFieldType, IH5PWidget, H5PForm, H5PSetValue, H5PObject, H5PEditorObject, IH5PContentType } from 'h5p-types';
type ExtrasWithState<TState> = H5PExtras & {
previousState?: TState;
};
declare abstract class H5PResumableContentType<TParams = unknown, TState = unknown> extends H5PContentType<TParams> implements IH5PResumableType<TState> {
protected extras: ExtrasWithState<TState> | undefined;
protected state: TState | undefined;
constructor(params: TParams, contentId: string, extras?: ExtrasWithState<TState>);
abstract getCurrentState(): TState | undefined;
}
declare abstract class H5PWidget<TField extends H5PField = H5PField, TParams = ParamTypeInferredFromFieldType<TField>> extends H5P.EventDispatcher implements IH5PWidget {
protected parent: H5PForm<TParams>;
field: TField;
protected params: TParams | undefined;
protected setValue: H5PSetValue<TParams>;
protected wrapper: HTMLElement;
constructor(parent: H5PForm<TParams>, field: TField, params: TParams | undefined, setValue: H5PSetValue<TParams>);
abstract appendTo($container: JQuery<HTMLElement>): void;
abstract validate(): boolean;
abstract remove(): void;
}
declare const H5P: H5PObject;
declare const H5PEditor: H5PEditorObject;
/**
* Get absolute path to image from relative parameters path
*
* @param path Relative path as found in content parameters
* @returns Absolute path to image
*/
declare const getAbsoluteUrlFromRelativePath: (path: string) => string;
declare const getImageUrl: (imagePath: string | undefined) => string | null;
declare const registerContentType: <TParams = unknown, TState = unknown>(name: string, contentType: (abstract new (params: TParams, contentId: string, extras?: h5p_types.H5PExtras | undefined) => H5PContentType<TParams>) | (abstract new (params: TParams, contentId: string, extras?: (h5p_types.H5PExtras & {
previousState?: TState;
}) | undefined) => H5PResumableContentType<TParams, TState>)) => void;
/**
* @param h5pName The widget's logical name, usually in PascalCase
* @param widgetName The name that's used when using the widget in semantics.json (e. g. `html`, `showWhen`)
* @param widget
*/
declare const registerWidget: <TField extends H5PField = H5PField, TParams = unknown>(h5pName: string, widgetName: string, widget: abstract new (parent: h5p_types.H5PForm<TParams>, field: TField, params: TParams | undefined, setValue: h5p_types.H5PSetValue<TParams>) => H5PWidget<TField, TParams>) => void;
declare abstract class H5PContentType<TParams extends Record<string, unknown> | unknown = unknown> extends H5P.EventDispatcher implements IH5PContentType {
params: TParams;
protected contentId: string;
protected extras?: H5PExtras | undefined;
protected wrapper: HTMLElement;
constructor(params: TParams, contentId: string, extras?: H5PExtras | undefined);
abstract attach($wrapper: JQuery<HTMLElement>): void;
}
export { H5P, H5PContentType, H5PEditor, H5PResumableContentType, H5PWidget, getAbsoluteUrlFromRelativePath, getImageUrl, registerContentType, registerWidget };