dmeditor
Version:
dmeditor is a block-style visual editor. Data is in json format.
259 lines (258 loc) • 7.66 kB
TypeScript
import { ComponentType } from 'react';
import type { DME, DMEData } from '../types';
export type BrowseLinkCallbackParams = {
link: string;
openNew?: boolean;
};
export type BrowseImageCallbackParams = DME.ImageInfo[];
export interface SavedBlockData {
name: string;
image?: string;
savedData: {
id?: string;
type?: string;
style?: {
[style: string]: string;
};
data: DMEData.DefaultDataType;
children?: Array<DMEData.DefaultBlockType>;
};
}
export interface CallbackConfig {
browseImage?: ComponentType<{
value: BrowseImageCallbackParams;
onChange: (value: BrowseImageCallbackParams) => void;
multiple?: boolean;
}>;
browseLink?: ComponentType<{
value: BrowseLinkCallbackParams;
onChange: (value: BrowseLinkCallbackParams) => void;
}>;
canEditControl?: (block: DMEData.Block) => boolean;
getSavedBlocks?: (widget: string) => Array<SavedBlockData>;
}
export interface widgetConfig {
allowedTypes?: Array<string>;
[prop: string]: any;
}
export interface DataSourceConfigType {
edit: React.FC<{
widget: string;
data?: Record<string, string | number>;
isList?: boolean;
view?: string;
onChange: (v: Record<string, string | number>) => void;
}>;
fetchInServer?: (widget: string, data: DMEData.DataSourceData, vars: Record<string, any>) => Promise<any>;
fetchInClient?: (widget: string, data: DMEData.DataSourceData, values: {
dependencyValue?: any;
}) => Promise<any>;
}
export interface StyleSettingConfigType {
default: {
list: StyleSettingsType;
underList: StyleSettingsType;
};
block: Array<{
path?: string;
level?: number;
blockType?: string | string[];
rootType?: string;
rootStyle?: string;
config: StyleSettingsType;
}>;
}
export type AddingSettingsType = {
allowedTypes?: Array<string>;
defaultStyle?: {
[widget: string]: {
[styleKey: string]: string;
};
};
};
export type StyleSettingsType = {
styles?: Record<string, Array<string>>;
settings: Array<string>;
builtInSettings?: Array<string>;
};
export type ContextPathType = Array<{
pathKey: string | number;
block?: {
type: string;
styles: Array<string>;
};
}>;
export type ContextWithStyleType = {
root?: {
type: string;
styles: Array<string>;
};
path: ContextPathType;
};
export interface DMEConfigType {
general?: {
projectStyles?: {
default: string;
[prop: string]: string;
};
imagePath?: (path: string, size?: 'thumbnail' | string) => string;
deviceWidth?: {
mobile: number;
tablet: number;
pc: number;
};
};
editor: {
defaultTheme?: string;
favouriteWidgets?: Array<string>;
zIndex?: number;
colors?: {
text?: Array<DME.ColorConfig>;
border?: Array<DME.ColorConfig>;
background?: Array<DME.ColorConfig>;
[colorGroup: string]: Array<DME.ColorConfig> | undefined;
};
enableEditControl?: boolean;
disabledStyleSettings?: {
[widget: string]: Array<string>;
};
defaultStyle?: {
[widget: string]: {
[styleKey: string]: string;
};
};
categories?: Array<DME.WidgetCategory>;
ui: {
[variable: string]: string;
};
fontFamily?: Array<{
value: string;
label: string;
}>;
fontSize?: Array<{
value: string;
label: string;
}>;
heading?: Array<{
value: string;
label: string;
}>;
characters?: Array<string>;
settingPanelWidth?: number;
clipboardKey?: string;
getAddingSettings?: (context: ContextWithStyleType) => AddingSettingsType;
configStyleSettings?: ((current: {
pathKey: string | number;
block?: {
type: string;
styles: Array<string>;
};
}, context: ContextWithStyleType, parentIsList: boolean) => StyleSettingsType) | StyleSettingConfigType;
};
widgets?: {
[widget: string]: widgetConfig;
};
dataSource?: DataSourceConfigType;
plugins?: {
imageHandlers?: Array<React.ComponentType<{
image: DME.ImageInfo;
onChange: (imageInfo: DME.ImageInfo) => void;
}>>;
blockSettingActions?: Array<React.ComponentType<{
blockData: DMEData.Block;
}>>;
[plugin: string]: any;
};
}
declare const dmeConfig: {
general: {
projectStyles: {
default: string;
[prop: string]: string;
};
imagePath: (path: string, size?: 'thumbnail' | string) => string;
deviceWidth: {
mobile: number;
tablet: number;
pc: number;
};
themes: Array<DME.PageTheme>;
[prop: string]: string | number | boolean | Record<string, any>;
};
editor: {
defaultTheme: string;
favouriteWidgets: Array<string>;
colors: {
[colorGroup: string]: Array<DME.ColorConfig>;
};
defaultStyle: {
[widget: string]: {
[styleKey: string]: string;
};
};
enableEditControl: boolean;
disabledStyleSettings: {
[widget: string]: Array<string> | string;
};
categories: Array<DME.WidgetCategory>;
settingGroups: {
[key: string]: string;
};
fontFamily: Array<{
value: string;
label: string;
}>;
heading: Array<{
value: string;
label: string;
}>;
fontSize: Array<{
value: string;
label: string;
}>;
characters: Array<string>;
zIndex: number;
settingPanelWidth: number;
ui: {
[variable: string]: string;
};
getAddingSettings?: (context: ContextWithStyleType) => AddingSettingsType;
clipboardKey: string;
configStyleSettings?: ((current: {
pathKey: string | number;
block?: {
type: string;
styles: Array<string>;
};
}, context: ContextWithStyleType, parentIsList: boolean) => StyleSettingsType) | StyleSettingConfigType;
};
widgets: {
[widget: string]: widgetConfig;
};
plugins: {
imageHandlers: Array<React.ComponentType<{
image: DME.ImageInfo;
parameters?: {
[key: string]: unknown;
};
onChange: (imageInfo: DME.ImageInfo) => void;
}>>;
blockSettingActions?: Array<React.ComponentType<{
blockData: DMEData.Block;
}>>;
[plugin: string]: any;
};
dataSource: DataSourceConfigType;
callbacks: CallbackConfig;
};
declare const setDMEditorConfig: (config: DMEConfigType) => void;
declare const setDMEditorCallback: (config: CallbackConfig) => void;
declare const getStyleConfig: (current: {
pathKey: string | number;
block?: {
type: string;
styles: Array<string>;
};
}, context: ContextWithStyleType, parentIsList: boolean) => StyleSettingsType;
export * from './style';
export { dmeConfig, setDMEditorConfig, getStyleConfig, setDMEditorCallback };