@blinkk/selective-edit
Version:
Selective structured text editor.
123 lines (122 loc) • 4.34 kB
TypeScript
import { FieldComponent, FieldConfig, InternalFieldConfig } from './field';
import { GlobalConfig, SelectiveEditor } from './editor';
import { PreviewTypes } from '../utility/preview';
import { TemplateResult } from 'lit-html';
import { Base } from '../mixins';
import { DeepObject } from '../utility/deepObject';
import { Template } from './template';
import { Types } from './types';
export interface FieldsConfig {
fields?: Array<FieldConfig & InternalFieldConfig>;
isGuessed?: boolean;
parentKey: string;
previewField?: string;
previewFields?: Array<string>;
previewType?: PreviewTypes;
}
export interface FieldsComponent {
config: FieldsConfig;
addField(fieldConfig: FieldConfig & InternalFieldConfig): void;
allowSimple: boolean;
fields: Array<FieldComponent>;
isClean: boolean;
isSimple: boolean;
isValid: boolean;
guessDefaultValue(): string | Record<string, any>;
lock(): void;
reset(): void;
template: Template;
templatePreviewValue(editor: SelectiveEditor, data: DeepObject, index?: number): TemplateResult;
updateOriginal(editor: SelectiveEditor, data: DeepObject, deep?: boolean): void;
value: any;
unlock(): void;
}
export interface FieldsConstructor {
new (types: Types, config: FieldsConfig, globalConfig: GlobalConfig): FieldsComponent;
}
declare const Fields_base: {
new (...args: any[]): {
_uuid?: string | undefined;
readonly uuid: string;
readonly uid: string;
};
} & {
new (...args: any[]): {
_data?: DeepObject | undefined;
data: DeepObject | undefined;
};
} & typeof Base;
/**
* Fields control the display of a list of fields in the editor.
*/
export declare class Fields extends Fields_base implements FieldsComponent {
config: FieldsConfig;
globalConfig: GlobalConfig;
private currentValue?;
fields: Array<FieldComponent>;
private isLocked;
private originalValue?;
types: Types;
constructor(types: Types, config: FieldsConfig, globalConfig: GlobalConfig);
addField(fieldConfig: FieldConfig & InternalFieldConfig): void;
get allowSimple(): boolean;
/**
* When there is no value, guess based on the known information about
* the fields.
*/
guessDefaultValue(): string | Record<string, any>;
/**
* Checks if the value is clean (unchanged) from the original value.
*/
get isClean(): boolean;
/**
* Checks if the fields are simple and can be simplified in the display.
*/
get isSimple(): boolean;
/**
* Checks all the fields to find out if there are invalid fields.
*/
get isValid(): boolean;
/**
* Certain cases require the field to be locked while updating to prevent bad
* data mixing. This allows for manually locking the fields.
*/
lock(): void;
get previewFields(): Array<string>;
reset(): void;
/**
* Template for determining how to render the fields.
*
* @param editor Selective editor used to render the template.
* @param data Data provided to render the template.
*/
template(editor: SelectiveEditor, data: DeepObject): TemplateResult;
/**
* Template for how to render a preview.
*
* @param editor Selective editor used to render the template.
* @param data Data provided to render the template.
*/
templatePreviewValue(editor: SelectiveEditor, data: DeepObject, index?: number): TemplateResult;
/**
* Certain cases require the field to be locked while updating to prevent bad
* data mixing. This allows for manually unlocking the fields.
*/
unlock(): void;
/**
* The data is not known to the fields until the rendering is done.
*
* Updated the original value from the data provided during rendering.
* This gives a base set of values for clean checks and validation to use.
*
* @param editor Selective editor used to render the template.
* @param data Data provided to render the template.
* @param deep Update in fields as well, such as when the field is not visible.
*/
updateOriginal(editor: SelectiveEditor, data: DeepObject, deep?: boolean): void;
/**
* Returns the value from all of the fields in a single object.
*/
get value(): any;
}
export {};