@blinkk/selective-edit
Version:
Selective structured text editor.
82 lines (81 loc) • 2.82 kB
TypeScript
import { FieldConfig, FieldConstructor } from './field';
import { FieldsComponent } from './fields';
import { RuleConstructor } from './validationRules';
import { TemplateResult } from 'lit-html';
import { Base } from '../mixins';
import { DeepObject } from '../utility/deepObject';
import { Types } from './types';
/**
* Globally accessible configuration. Allow for passing arbitrary
* information to fields.
*/
export interface GlobalConfig {
}
export interface EditorConfig {
/**
* Optionally provide the field types that the editor understands.
*/
fieldTypes?: Record<string, FieldConstructor>;
/**
* Optionally provide the validation rules that the fields can use.
*/
ruleTypes?: Record<string, RuleConstructor>;
/**
* Optionally define an initial set of field configurations.
*/
fields?: Array<FieldConfig>;
/**
* Global configuration for all of the fields.
*
* This allows for passing things that fields will need access to
* such as an api or additional global meta information.
*/
global?: GlobalConfig;
/**
* Delay the validation until marked for validation.
*
* The default for the editor is to show validation messages after
* the user has left the fields. This provides a better user
* experience for longer forms but can be disruptive on smaller forms.
*
* By delaying the validation the editor will not run the field
* validation until the `markValidation` is set to `true` and
* the editor is re-rendered.
*/
delayValidation?: boolean;
}
declare const SelectiveEditor_base: {
new (...args: any[]): {
_data?: DeepObject | undefined;
data: DeepObject | undefined;
};
} & typeof Base;
export declare class SelectiveEditor extends SelectiveEditor_base {
config: EditorConfig;
container?: HTMLElement;
fields: FieldsComponent;
/**
* Controls when the validation should be checked across all the
* fields in the editor.
*
* **Note:** Render cycle needs to complete before the validation can
* be trusted.
*/
markValidation?: boolean;
isPendingRender: boolean;
isRendering: boolean;
types: Types;
constructor(config: EditorConfig, container?: HTMLElement);
addFieldType(key: string, FieldCls: FieldConstructor): void;
addFieldTypes(fieldTypes: Record<string, FieldConstructor>): void;
addRuleType(key: string, RuleCls: RuleConstructor): void;
addRuleTypes(ruleTypes: Record<string, RuleConstructor>): void;
guessFields(): Array<FieldConfig>;
get isClean(): boolean;
get isValid(): boolean;
template(editor: SelectiveEditor, data: DeepObject): TemplateResult;
render(): void;
resetFields(): void;
get value(): any;
}
export {};