@divkitframework/visual-editor
Version:
Visual editor for DivKit
157 lines (151 loc) • 4.71 kB
TypeScript
interface Loc {
line: number;
column: number;
offset: number;
}
interface Range {
start: Loc;
end: Loc;
}
interface TypedRange {
range: Range;
type: 'highlight' | 'select';
}
declare function convertDictToPalette(json: any): any;
declare function convertPaletteToDict(json: any): any;
declare function addTemplatesSuffix(card: any, suffix: string): any;
declare function removeTemplatesSuffix(card: any, clearSuffix: (str: string) => string | undefined): any;
type Theme = 'light' | 'dark';
type LayoutItem = 'new-component' | 'component-tree' | 'palette' | 'preview' | 'component-props' | 'code' | 'component-props:code' | 'tanker-overview' | 'sources-overview' | 'custom-variables' | 'timers';
type LayoutColumn = {
items: LayoutItem[];
minWidth?: number;
weight?: number;
};
type Layout = LayoutColumn[];
type Locale = 'ru' | 'en';
interface ActionArgBase {
type: string;
name: string;
text: Record<string, string>;
}
interface ActionArgString extends ActionArgBase {
type: 'string';
}
type ActionArg = ActionArgString;
interface ActionDesc {
baseUrl: string;
text: Record<string, string>;
args?: ActionArg[];
}
interface FontFaceDesc {
value: string;
text: Record<string, string>;
cssValue: string;
}
type TankerMeta = Record<string, Record<string, string>>;
interface Meta {
tanker?: TankerMeta;
}
interface Card {
json: string;
meta?: Meta;
}
interface CardLocale {
id: string;
text: Record<string, string>;
}
interface EditorOptions {
node: HTMLElement;
shadowRoot?: ShadowRoot;
value: string;
theme: 'light' | 'dark';
readOnly?: boolean;
onChange(value: string): void;
onOver(offset: number | null): void;
onClick(offset: number): void;
}
interface EditorInstance {
setValue(value: string): void;
setTheme(theme: 'light' | 'dark'): void;
setReadOnly(readOnly: boolean): void;
revealLoc(loc: Loc): void;
decorateRanges(typedRanges: TypedRange[]): void;
isFocused(): boolean;
destroy(): void;
}
interface TranslationVariant {
key: string;
text?: string;
}
type GetTranslationSuggest = (query: string, locale: string) => Promise<TranslationVariant[]>;
type GetTranslationKey = (key: string) => Promise<Record<string, string> | undefined>;
interface DivProEditorApi {
uploadFile?(file: File): Promise<string>;
editorFabric?(opts: EditorOptions): EditorInstance;
onChange?(): void;
getTranslationSuggest?: GetTranslationSuggest;
getTranslationKey?: GetTranslationKey;
}
interface Source {
key: string;
url: string;
example: object;
}
interface FileLimit {
warn?: number;
error?: number;
}
interface FileLimits {
preview?: FileLimit;
image?: FileLimit;
lottie?: FileLimit;
video?: FileLimit;
upload?: FileLimit;
}
interface DivProEditorOptions {
renderTo: HTMLElement;
shadowRoot?: ShadowRoot;
value?: string;
card?: Card;
theme?: Theme;
layout?: Layout;
locale?: Locale;
api?: DivProEditorApi;
actionLogUrlVariable?: string;
readOnly?: boolean;
customActions?: ActionDesc[];
paletteEnabled?: boolean;
cardLocales?: CardLocale[];
sources?: Source[];
previewWarnFileLimit?: number;
previewErrorFileLimit?: number;
warnFileLimit?: number;
errorFileLimit?: number;
fileLimits?: FileLimits;
rootConfigurable?: boolean;
customFontFaces?: FontFaceDesc[];
directionSelector?: boolean;
direction?: 'ltr' | 'rtl';
perThemeProps?: boolean;
}
interface EditorError {
message: string;
level: 'error' | 'warn';
}
interface DivProEditorInstance {
getValue(): string;
getCard(): Card;
getErrors(): EditorError[];
setTheme(theme: Theme): void;
setLayout(layout: Layout): void;
setLocale(locale: Locale): void;
setReadOnly(readOnly: boolean): void;
setCustomActions(customActions: ActionDesc[]): void;
setPaletteEnabled(toggle: boolean): void;
destroy(): void;
}
declare const DivProEditor: {
init(opts: DivProEditorOptions): DivProEditorInstance;
};
export { type ActionArg, type ActionArgBase, type ActionArgString, type ActionDesc, type Card, type CardLocale, DivProEditor, type DivProEditorApi, type DivProEditorInstance, type DivProEditorOptions, type EditorError, type EditorInstance, type EditorOptions, type FileLimit, type FileLimits, type FontFaceDesc, type GetTranslationKey, type GetTranslationSuggest, type Layout, type LayoutColumn, type LayoutItem, type Locale, type Meta, type Source, type TankerMeta, type Theme, type TranslationVariant, addTemplatesSuffix, convertDictToPalette, convertPaletteToDict, removeTemplatesSuffix };