import React$1, { CSSProperties } from 'react'; import * as _dnd_kit_core_dist_hooks_utilities from '@dnd-kit/core/dist/hooks/utilities'; import * as _dnd_kit_core from '@dnd-kit/core'; import { Patch } from 'immer'; import { Placement, OffsetOptions } from '@floating-ui/dom'; declare abstract class Step { meta: { changed: Block['id'] | null; changedParent?: Block['id']; }; protected inversePatches: Patch[]; abstract apply(blocks: Blocks): StepResult; abstract invert(blocks: Blocks): StepResult; protected produceWithPatches(blocks: Blocks, producer: (blocks: Blocks) => Blocks | void): Blocks; } declare class StepResult { readonly blocks: Blocks | null; readonly failed: string | null; constructor(blocks: Blocks | null, failed: string | null); static ok(blocks: Blocks): StepResult; static fail(message: string): StepResult; } declare class Transform { blocks: Blocks; lastModifiedBlock: Block['id'] | null; readonly steps: Step[]; constructor(blocks: Blocks, lastModifiedBlock: Block['id'] | null); insertContent(target: Block['id'], blocks: Array): this; remove(target: Block['id']): this; removeContent(target: Block['id'], blockIds?: Array): this; changeProperty(target: Block['id'], property: keyof Block['props'], value: any): this; changeStyle(target: Block['id'], layer: keyof Style, style: NonNullable): this; move(source: Block['id'], target: Block['id'], from: number, to: number): this; step(step: Step): this; private maybeStep; protected addStep(step: Step, blocks: Blocks): void; } declare class Transaction extends Transform { activeId: EditorState['activeId']; private meta; constructor(state: EditorState); get activeBlock(): Block | null; select(target?: Block['id'] | null): this; setMeta(key: string | Plugin, value: any): this; getMeta(key: string | Plugin): any; addStep(step: Step, blocks: Blocks): void; } type StateField = { init: (config: EditorStateConfig, instance: EditorState) => T; apply: (tr: Transaction, value: T, oldState: EditorState, newState: EditorState) => T; toJSON?: (value: T) => any; fromJSON?: (config: EditorStateConfig, value: any, state: EditorState) => T; }; type PluginCommonComponent = React.FunctionComponent<{ editor: Editor; }>; type PluginPropsComponent = React.FunctionComponent<{ editor: Editor; block: Block; }>; type PluginStyleComponent = React.FunctionComponent<{ editor: Editor; layer: keyof Style; styleSpec: React.CSSProperties; style: React.CSSProperties; block: Block; }>; type PluginCommonView = { name?: string; filter?: () => boolean; component: PluginCommonComponent; }; type PluginPropsView = { name?: string; filter: (block: Block) => boolean; component: PluginPropsComponent; }; type PluginStyleView = { name?: string; filter: (styleSpec: React.CSSProperties, block: Block, layer: keyof Style) => boolean; component: PluginStyleComponent; }; type PluginApplyMethods = { addCommands: (commands: Partial) => void; addProvider: (provider: Provider) => void; addBlock: (spec: { name: string; allowContent?: BlockSpec['allowContent']; withValue?: BlockSpec['withValue']; withChildren?: BlockSpec['withChildren']; rootable?: BlockSpec['rootable']; structural?: BlockSpec['structural']; props?: Properties; style?: BlockSpec['style']; components?: BlockViewRendererPack; }) => void; addView: (view: PluginCommonView) => void; addPropsView: (view: PluginPropsView) => void; addStyleView: (view: PluginStyleView) => void; getState: () => PluginState; setState: (state: PluginState | ((prevState: PluginState) => PluginState)) => void; usePluginState: () => [ PluginState, PluginApplyMethods['setState'] ]; }; type Plugin = { name: string; state?: StateField; init?: (editor: Editor) => Promise | void; apply?: (editor: Editor, methods: PluginApplyMethods) => void; filterTransaction?: (tr: Transaction, state: EditorState) => boolean; appendTransaction?: (transactions: readonly Transaction[], oldState: EditorState, newState: EditorState) => Transaction | null | undefined; }; type InferPluginState = T extends Plugin ? R : any; declare class FieldDesc { readonly name: string; init: StateField['init']; apply: StateField['apply']; constructor(name: string, desc: StateField, self?: any); } declare class Configuration { readonly schema: Schema; fields: FieldDesc[]; plugins: Plugin[]; pluginsByName: { [key: string]: Plugin; }; constructor(schema: Schema, plugins?: readonly Plugin[]); } type RawBlocks = Record; type Blocks = Record; type EditorStateConfig = { schema: Schema; blocks: RawBlocks; readonly plugins?: Plugin[]; }; declare class EditorState { blocks: Blocks; activeId: Block['id'] | null; lastModifiedBlock: Block['id'] | null; constructor(config: Configuration); get schema(): Schema; get plugins(): readonly Plugin[]; get activeBlock(): Block | null; get rootPage(): Block; getBlock(id: Block['id']): Block; apply(tr: Transaction): EditorState; get tr(): Transaction; static create(config: EditorStateConfig): EditorState; reconfigure(config: Pick): EditorState; fromJSON(json: any): { success: true; state: EditorState; } | { success: false; }; toJSON(): any; } type Props$1 = { readonly [prop: string]: any; }; interface PropertySpec { default?: any; } declare class Property$1 { hasDefault: boolean; default: any; constructor(options: PropertySpec); get isRequired(): boolean; } type Style = Partial<{ readonly root: Partial; readonly [element: string]: Partial; }>; type Elements = { readonly root: any; readonly [element: string]: any; }; interface BlockSpec { allowContent?: { name?: Array<'*' | Block['type']['name'] | `!${Block['type']['name']}`>; withValue?: boolean; withChildren?: boolean; rootable?: boolean; structural?: boolean; }; props?: { [name: string]: PropertySpec; }; style?: { [element in keyof Elements]: { [name in keyof CSSProperties]: CSSProperties[name]; }; }; withValue?: boolean; withChildren?: boolean; rootable?: boolean; structural?: boolean; } declare class BlockType { readonly name: string; readonly schema: Schema; readonly spec: BlockSpec; props: { [name: string]: Property$1; }; defaultProps: Props$1 | null; style: { [element in keyof Elements]: { [name in keyof CSSProperties]: CSSProperties[name]; }; }; constructor(name: string, schema: Schema, spec: BlockSpec); computeProps(props: Props$1 | null): Props$1; computeStyle(style: Style | null): {} | undefined; create(props?: Props$1 | null, style?: Style | null, content?: Fragment | Block | Block[] | null, id?: Block['id']): Block; isAllowedContent(block: Block): boolean; validContent(_content: Fragment): boolean; checkContent(content: Fragment): void; static compile(blocks: Map, schema: Schema): { readonly [name in Blocks]: BlockType; }; } interface SchemaSpec { rootBlockId?: string; blocks: { [name in Blocks]: BlockSpec; } | Map; } declare class Schema { spec: { rootBlockId: string; blocks: Map; }; blocks: { readonly [name in Blocks]: BlockType; } & { readonly [key: string]: BlockType; }; constructor(spec: SchemaSpec); block(type: BlockType | string, props?: Props$1 | null, style?: Style | null, content?: Fragment | Block | Block[], id?: Block['id']): Block; blockType(name: string): BlockType; getAllowContentAsChildren(block: Block): BlockType[]; getAllowContent(value: Block | BlockSpec['allowContent']): BlockType[]; blockFromJSON(json: any): Block; } declare class Fragment { readonly children: Block['id'][]; constructor(children: Block['id'][]); get isEmpty(): boolean; get isNotEmpty(): boolean; has(id: Block['id'] | Block): boolean; indexOf(id: Block['id'] | Block, fromIndex?: number): number; at(index: number): Block['id'] | undefined; slice(start?: number, end?: number): string[]; remove(ids: Array): Fragment; move(from: number, to: number): Fragment; swap(from: number, to: number): Fragment; insert(block: Block, index: number): Fragment; append(block: Block | Block[]): Fragment; static from(blocks?: Fragment | Block | Block[] | Block['id'][] | null): Fragment; static fromJSON(schema: Schema, value: any): Fragment; static empty: Fragment; toJSON(): any; } declare class Block { readonly type: BlockType; readonly props: Props$1; readonly children: Fragment; readonly id: string; private _style; constructor(type: BlockType, props: Props$1, style: Style, children: Fragment, id?: string); get style(): Style; hasNestedBlock(blockId: Block['id'], blocks: Blocks): boolean; getNestedBlocks(blocks: Blocks): Block[]; static fromJSON(schema: Schema, json: any): Block; toJSON(): any; } type StringKeyOf = Extract; type CallbackType, EventName extends StringKeyOf> = T[EventName] extends any[] ? T[EventName] : [T[EventName]]; type CallbackFunction, EventName extends StringKeyOf> = (...props: CallbackType) => any; declare class EventEmitter> { private callbacks; on>(event: EventName, fn: CallbackFunction): this; protected emit>(event: EventName, ...args: CallbackType): this; off>(event: EventName, fn?: CallbackFunction): this; protected removeAllListeners(): void; } declare class DragAndDropState extends EventEmitter<{ update: DragAndDropState; }> { constructor(); activeBlock: Block | null; isOverContainerId: Block['id'] | null; availableDropBlocks: Block['type']['name'][]; get isDragging(): boolean; changeOverContainerId(id: Block['id'] | null): void; changeAvailableDropBlocks(blockNames: Block['type']['name'][]): void; changeActiveBlock(block: Block): void; resetActiveBlock(): void; } type Selector = (state: DragAndDropState) => T; declare function useDragAndDropState(): DragAndDropState; declare function useDragAndDropState(selector: Selector): [T, DragAndDropState]; declare function useDragAndDropBlockState(block: Block): { isOver: boolean; isDragging: boolean; isAvailableDrop: boolean; }; type ActionPopoverProps = { referenceRef: React$1.RefObject; className?: string; placement?: Placement; offset?: OffsetOptions; children: React$1.ReactNode; } & { view: EditorView; }; declare function ActionPopover(props: ActionPopoverProps): React$1.ReactPortal; type Props = Omit[0], 'view'>; type EditorViewOptions = { state: EditorState; blockViews?: Record; dispatchTransaction?: (tr: Transaction) => void; propertyConfigurationRender?: React$1.FunctionComponent<{ view: EditorView; }>; styleConfigurationRender?: React$1.FunctionComponent<{ view: EditorView; }>; ui?: Partial; }; declare class EditorView { editor: Editor; options: EditorViewOptions; state: EditorState; pluginCommonViews: Array<{ id: string; view: PluginCommonView; }>; pluginPropsViews: Array<{ id: string; view: PluginPropsView; }>; pluginStyleViews: Array<{ id: string; view: PluginStyleView; }>; rawUI: { ActionPopover: typeof ActionPopover; }; ui: { [name in keyof EditorView['rawUI']]: React$1.FunctionComponent>; }; PluginProviders: Provider; dragAndDrop: { state: DragAndDropState; useState: typeof useDragAndDropState; useBlockState: typeof useDragAndDropBlockState; useDndConnector: () => { withActivator: false; block: Block; } | { withActivator: true; block: Block; ref: (element: HTMLElement | null) => void; attributes: _dnd_kit_core.DraggableAttributes; listeners?: _dnd_kit_core_dist_hooks_utilities.SyntheticListenerMap | undefined; }; }; Draggable: React$1.ForwardRefExoticComponent<{ id: string; withActivator?: boolean | undefined; children: React$1.ReactElement> | [React$1.ReactElement>, ...React$1.ReactNode[]] | ((connectorAttrs: { ref: React$1.Ref; attrs: Partial<_dnd_kit_core.DraggableAttributes> & { 'data-block-id': string; }; listeners?: _dnd_kit_core_dist_hooks_utilities.SyntheticListenerMap | undefined; style: { transform?: string | undefined; transition?: string | undefined; }; }) => React$1.ReactElement>); } & React$1.RefAttributes>; Dropzone: React$1.ForwardRefExoticComponent<{ block?: Block | undefined; children: React$1.ReactElement>; } & React$1.RefAttributes>; constructor(editor: Editor, options: EditorViewOptions); dispatch(tr: Transaction): void; updateState(state: EditorState): void; setOptions(options: Partial): void; setPluginViews(common: EditorView['pluginCommonViews'], props: EditorView['pluginPropsViews'], style: EditorView['pluginStyleViews']): void; setPluginProviders(pluginProviders?: Provider[]): void; getBlockViews(name: Block['type']['name']): BlockViewRendererPack; private injectViewToUI; } type Provider = React$1.FunctionComponent<{ Renderer: React$1.FunctionComponent<{ block: Block; }>; editor: Editor; children: React$1.ReactNode; }>; type EditorMode = 'view' | 'editor'; type EditorEvents = { ready: { editor: Editor; }; update: { editor: Editor; }; transaction: { editor: Editor; transaction: Transaction; }; mode: { editor: Editor; mode: EditorMode; }; }; type LogData = number | string | Record | any[]; interface Logger { log(data: LogData): void; info(data: LogData): void; warn(data: LogData): void; error(data: LogData): void; action(data: LogData): void; system(data: LogData): void; } type ValuesOf = T[keyof T]; type JSONContent = { id?: string; type: string; props?: Block['props']; style?: Block['style']; content?: JSONContent['id'][]; }; type Content = JSONContent | JSONContent[]; type Property = { default: any; isRequired?: boolean; }; type Properties = { [key: string]: Property; }; type BlockViewRendererProps = { editor: Editor; block: Block; children: React$1.ReactNode | React$1.ReactNode[]; }; type BlockViewRenderer = (props: BlockViewRendererProps) => React$1.ReactNode; type BlockViewRendererPack = { view: BlockViewRenderer; editor: BlockViewRenderer; palette: () => React$1.ReactNode; }; type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; type KeysWithTypeOf = { [P in keyof T]: T[P] extends Type ? P : never; }[keyof T]; type CommandProps = { editor: Editor; tr: Transaction; commands: SingleCommands; chain: ChainedCommands; state: EditorState; view: EditorView; }; type Command = (props: CommandProps) => void; type UnionCommands = UnionToIntersection, KeysWithTypeOf, object>>>>; type RawCommands = { [Item in keyof UnionCommands]: UnionCommands[Item]; }; type SingleCommands = { [Item in keyof UnionCommands]: UnionCommands[Item]; }; type ChainedCommands = { [Item in keyof UnionCommands]: UnionCommands[Item]; } & { run: () => void; }; declare class PluginManager extends EventEmitter<{ 'state-update': Plugin['name']; }> { editor: Editor; plugins: Plugin[]; schema: Schema; commands: RawCommands; pluginViews: { common: EditorView['pluginCommonViews']; props: EditorView['pluginPropsViews']; style: EditorView['pluginStyleViews']; }; blockViews: Record; providers: Provider[]; constructor(plugins: Plugin[], editor: Editor); pluginStateChanged(name: Plugin['name']): void; apply(): void; init(): Promise; } type EditorOptions = Pick & { blocks: RawBlocks; plugins: ReadonlyArray>; loggers?: Logger[]; }; declare class Editor extends EventEmitter { private commandManager; pluginManager: PluginManager; schema: Schema; view: EditorView; mode: EditorMode; options: EditorOptions; pluginViewTokens: { readonly configuration: "configuration"; readonly addBlockInline: "addBlockInline"; }; logger: Logger; private loggers; constructor(options?: Partial); private initPlugins; get state(): EditorState; get commands(): SingleCommands; get chain(): ChainedCommands; setOptions(options?: Partial): void; private createPluginManager; private createView; private createBlockViews; changeMode(mode: EditorMode): void; private dispatchTransaction; getPluginState(plugin: Plugin['name']): T; getPluginState(plugin: T): InferPluginState; setPluginState(plugin: Plugin['name'], state: S | ((prevState: S) => S)): void; setPluginState>(plugin: T, state: S | ((prevState: S) => S)): void; private getPluginName; } declare module '..' { interface Commands { command: { command: (fn: (props: Parameters[0]) => void) => ReturnType; }; } } declare const command: RawCommands['command']; declare module '..' { interface Commands { intention: { intention: (target: Block['id'], type: 'add-block' | 'change-properties', element?: HTMLElement) => ReturnType; }; } } declare const intention: RawCommands['intention']; declare module '..' { interface Commands { select: { select: () => ReturnType; }; } } declare const select: RawCommands['select']; declare module '..' { interface Commands { insertRootContent: { insertRootContent: (content: JSONContent & { id: string; }) => ReturnType; }; } } declare const insertRootContent: RawCommands['insertRootContent']; declare module '..' { interface Commands { insertContent: { insertContent: (target: Block['id'], content: Content) => ReturnType; }; } } declare const insertContent: RawCommands['insertContent']; declare module '..' { interface Commands { removeContent: { removeContent: (target: Block['id'], ids?: Array) => ReturnType; }; } } declare const removeContent: RawCommands['removeContent']; declare module '..' { interface Commands { remove: { remove: (target: Block['id']) => ReturnType; }; } } declare const remove: RawCommands['remove']; declare module '..' { interface Commands { appendBlocks: { appendBlocks: (target: Block['id'], blocks: Array) => ReturnType; }; } } declare const appendBlocks: RawCommands['appendBlocks']; declare module '..' { interface Commands { changeProperty: { changeProperty: (target: Block['id'], property: string, value: any) => ReturnType; }; } } declare const changeProperty: RawCommands['changeProperty']; declare module '..' { interface Commands { changeStyle: { changeStyle: (target: Block['id'], layer: keyof Style, style: NonNullable) => ReturnType; }; } } declare const changeStyle: RawCommands['changeStyle']; declare module '..' { interface Commands { changeTitle: { changeTitle: (target: Block['id'], title: string) => ReturnType; }; } } declare const changeTitle: RawCommands['changeTitle']; declare module '..' { interface Commands { changeValue: { changeValue: (target: Block['id'], value: string) => ReturnType; }; } } declare const changeValue: RawCommands['changeValue']; declare module '..' { interface Commands { move: { move: (source: Block['id'], target: Block['id'], from: number, to: number) => ReturnType; }; } } declare const move: RawCommands['move']; declare const index_appendBlocks: typeof appendBlocks; declare const index_changeProperty: typeof changeProperty; declare const index_changeStyle: typeof changeStyle; declare const index_changeTitle: typeof changeTitle; declare const index_changeValue: typeof changeValue; declare const index_command: typeof command; declare const index_insertContent: typeof insertContent; declare const index_insertRootContent: typeof insertRootContent; declare const index_intention: typeof intention; declare const index_move: typeof move; declare const index_remove: typeof remove; declare const index_removeContent: typeof removeContent; declare const index_select: typeof select; declare namespace index { export { index_appendBlocks as appendBlocks, index_changeProperty as changeProperty, index_changeStyle as changeStyle, index_changeTitle as changeTitle, index_changeValue as changeValue, index_command as command, index_insertContent as insertContent, index_insertRootContent as insertRootContent, index_intention as intention, index_move as move, index_remove as remove, index_removeContent as removeContent, index_select as select, }; } interface Commands { } export { Block, BlockViewRenderer, BlockViewRendererPack, Commands, Editor, EditorEvents, EditorMode, EditorState, EditorView, InferPluginState, JSONContent, Plugin, PluginApplyMethods, PluginCommonComponent, PluginCommonView, PluginPropsComponent, PluginPropsView, PluginStyleComponent, PluginStyleView, Provider, Transaction, index as commands };