import { TemplateResult } from 'lit'; import { Direction } from '../arenaEvents'; import { ArenaSelection, NodeRegistry } from '../helpers'; import { AnyArena, AnyArenaNode, ArenaCursorAncestor, ArenaCursorText, ArenaFormating, ArenaFormatings, ArenaInlineInterface, ArenaInterval, ArenaMediatorInterface, ArenaNodeInline, ArenaNodeMediator, ArenaNodeRoot, ArenaNodeText, ArenaOptionsChild, ArenaRootInterface, ArenaTextInterface, ChildArena, ChildArenaNode, ParentArenaNode, TagAndAttributes } from '../interfaces'; import { ArenaServiceManager } from './ArenaServiceManager'; export declare type ArenaMark = { attributes: string[]; excludeAttributes?: string[]; arena: AnyArena; }; export declare type FormatingMark = { attributes: string[]; excludeAttributes?: string[]; formating: ArenaFormating; }; export declare class ArenaModel { protected asm: ArenaServiceManager; readonly rootArenaName = "__ROOT__"; constructor(asm: ArenaServiceManager); get model(): ArenaNodeRoot; getRegistry(): NodeRegistry; setRegistry(registry: NodeRegistry): void; setRoot(root: ArenaNodeRoot): void; setDefaultTextArena(arena: ArenaMediatorInterface | ArenaTextInterface): void; createNewRoot(): void; registerArena(arenaOptions: ArenaOptionsChild, markers?: TagAndAttributes[], parentArenas?: string[]): ChildArena | ArenaInlineInterface; registerFormating(formating: ArenaFormating, markers: TagAndAttributes[]): ArenaFormating; getArena(name: string): AnyArena | undefined; getArenas(): AnyArena[]; getFormatings(): ArenaFormatings; getArenaMarks(tagName: string): ArenaMark[] | undefined; getFormatingMarks(tagName: string): FormatingMark[] | undefined; /** Data for storing */ getDataHtml(): string; /** Tempate for rendering in the editor */ getTemplate(): TemplateResult | string; /** Output string for external */ getOutput(type: string): string; getPlainTextOfSelection(selection: ArenaSelection): string; getDataHtmlOfSelection(selection: ArenaSelection): string; getJson(): string; /** */ createChildNode(arena: ChildArena, isNew?: boolean): ChildArenaNode; /** */ createInlineNode(arena: ArenaInlineInterface): ArenaNodeInline; /** */ getTextCursor(node: AnyArenaNode, offset: number): ArenaCursorText; /** * TODO split in two methods: with creating and without * Find or create text node in children or ancestors. * @param node AnyArenaNode * @param offset number * @param onlyChild boolean * @param forceCreate boolean * @returns ArenaCursorText | undefined */ getOrCreateNodeForText(node: AnyArenaNode, offset?: number, onlyChild?: boolean, forceCreate?: boolean): ArenaCursorText | undefined; /** * Try to create new node described by arena in given parent and offset. * @param arena ChildArena * @param parent ParentArenaNode * @param offset number * @param before boolean * @param onlyChild boolean * @param isNew boolean * @param replace boolean * @returns ChildArenaNode | undefined */ createAndInsertNode(arena: ChildArena, parent: AnyArenaNode, offset: number, before?: boolean, onlyChild?: boolean, isNew?: boolean, replace?: boolean): ChildArenaNode | undefined; /** * Find in model tree the text node with global id equal given id parameter. * @param id: string * @returns ArenaNodeText | undefined */ getTextNodeById(id: string): ArenaNodeText | undefined; /** * Find in model tree the node with global id equal given id parameter. * @param id: string * @returns AnyArenaNode | undefined */ getNodeById(id: string): AnyArenaNode | undefined; insertHtmlToModel(selection: ArenaSelection, html: string): ArenaSelection; insertTextToModel(selection: ArenaSelection, text: string, typing?: boolean): ArenaSelection; removeNodeById(id: string): ArenaCursorAncestor | undefined; /** * Remove selected text and all nodes between selections ends * @param selection * @param direction * @returns */ removeSelection(selection: ArenaSelection, direction: Direction): ArenaSelection; /** * Remove selected nodes and split selected node in two nodes. * If current node is empty, try split uprotected parent in two * or get out of protected node, if cursor in the end of parent. * @param selection * @returns */ breakSelection(selection: ArenaSelection): ArenaSelection; /** * Breaks the text node into two. Returns the parent of both and the offset between them * @param param0 ArenaCursorText * @returns ArenaCursorAncestor */ splitTextNode({ node, offset }: ArenaCursorText): ArenaCursorAncestor; /** */ moveChild(selection: ArenaSelection, direction: 'up' | 'down'): ArenaSelection; protected moveNode(node: AnyArenaNode, direction: 'up' | 'down'): void; /** */ insertBeforeSelected(selection: ArenaSelection, arena: ChildArena, replace?: boolean): [ArenaSelection, AnyArenaNode | undefined]; /** * * @param selection * @param arena * @returns */ applyArenaToSelection(selection: ArenaSelection, arena: ArenaMediatorInterface | ArenaTextInterface): ArenaSelection; /** * Apply given formation to all selected nodes, including child nodes. * @param selection ArenaSelection * @param formating ArenaFormating * @returns ArenaSelection */ applyFormationToSelection(selection: ArenaSelection, formating: ArenaFormating): ArenaSelection; clearFormationInSelection(selection: ArenaSelection): ArenaSelection; getInlineInterval(selection: ArenaSelection): ArenaInterval | undefined; addInlineNode(selection: ArenaSelection, arena: ArenaInlineInterface): ArenaNodeInline | undefined; getInlineNode(selection: ArenaSelection, arena: ArenaInlineInterface): [ArenaNodeText, ArenaNodeInline] | undefined; removeInlineNode(selection: ArenaSelection, node: ArenaNodeInline): void; updateInlineNode(selection: ArenaSelection, node: ArenaNodeInline): void; isAllowedNode(node: AnyArenaNode, arena: ChildArena): boolean; protected registry: NodeRegistry; protected arenas: AnyArena[]; protected arenasByName: { [name: string]: AnyArena; }; protected formatings: ArenaFormating[]; protected formatingsByName: ArenaFormatings; protected arenaMarks: { [tag: string]: ArenaMark[]; }; protected formatingMarks: { [tag: string]: FormatingMark[]; }; protected rootArena: ArenaRootInterface | undefined; protected rootNode: ArenaNodeRoot | undefined; /** Split non protected node into two. * If offset in start or end of the givven node splitting is not necessary. */ protected splitMediatorNode(node: ArenaNodeMediator, offset: number): undefined | ArenaNodeMediator; /** */ getOutFromMediator(node: ArenaNodeText, onlyGroup?: boolean): ArenaNodeText | undefined; protected applyTextArenaToSelection(selection: ArenaSelection, arena: ArenaTextInterface): ArenaSelection; protected transformNode(node: AnyArenaNode, arena: ArenaTextInterface): ArenaNodeText | undefined; protected getParentWhoCanCreateNode(node: AnyArenaNode, arena: ArenaTextInterface, after?: boolean): ArenaCursorAncestor | undefined; protected toggleGroupArenaForSelection(selection: ArenaSelection, arena: ArenaMediatorInterface): ArenaSelection; /** * Wrap selected nodes by protected Node described by given Arena. * All selected children will be took of and inserted in new Node, if it allow Arena. * Rest children will be back in them ancestor after new Node. * @param selection ArenaSelection * @param arena ArenaAncestor * @returns ArenaSelection */ protected applyProtectedArenaToSelection(selection: ArenaSelection, arena: ArenaMediatorInterface): ArenaSelection; protected toggleSimpleMediatorArenaForSelection(selection: ArenaSelection, arena: ArenaMediatorInterface): ArenaSelection; protected tryToFindAncestor(node: AnyArenaNode, arena: ArenaMediatorInterface): ArenaNodeMediator | undefined; protected tryToFindAncestor2(node: ParentArenaNode, arena: ArenaMediatorInterface): ArenaNodeMediator | undefined; protected unwrapNode(node: ArenaNodeMediator): void; }