roosterjs
Version:
A simple facade for all roosterjs code
1,719 lines (1,648 loc) • 188 kB
TypeScript
// Type definitions for roosterjs (Version 7.13.0)
// Generated by dts tool from roosterjs
// Project: https://github.com/Microsoft/roosterjs
/**
* Create an editor instance with most common options
* @param contentDiv The html div element needed for creating the editor
* @param additionalPlugins The additional user defined plugins. Currently the default plugins that are already included are
* DefalutShortcut, HyperLink, Paste, and ContentEdit, user don't need to add those.
* @param initialContent The initial content to show in editor. It can't be removed by undo, user need to manually remove it if needed.
* @returns The editor instance
*/
export function createEditor(contentDiv: HTMLDivElement, additionalPlugins?: EditorPlugin[], initialContent?: string): Editor;
/**
* Information of current OS and web browser
*/
export interface BrowserInfo {
/**
* Wether current OS is Mac
*/
readonly isMac?: boolean;
/**
* Whether current OS is Windows
*/
readonly isWin?: boolean;
/**
* Whether current browser is using webkit kernal
*/
readonly isWebKit?: boolean;
/**
* Whether current browser is Internet Explorer
*/
readonly isIE?: boolean;
/**
* Whether current browser is IE10 or IE11
*/
readonly isIE11OrGreater?: boolean;
/**
* Whether current browser is Safari
*/
readonly isSafari?: boolean;
/**
* Whether current browser is Chrome
*/
readonly isChrome?: boolean;
/**
* Whether current browser is Firfox
*/
readonly isFirefox?: boolean;
/**
* Whether current browser is Edge
*/
readonly isEdge?: boolean;
/**
* Whether current browser is IE/Edge
*/
readonly isIEOrEdge?: boolean;
}
/**
* Command strings for Document.execCommand() API
* https: */
export const enum DocumentCommand {
/**
* Changes the browser auto-link behavior (Internet Explorer only)
*/
AutoUrlDetect = "AutoUrlDetect",
/**
* Changes the document background color. In styleWithCss mode, it affects the background color of the containing block instead.
* This requires a <color> value string to be passed in as a value argument. Note that Internet Explorer uses this to set the
* text background color.
*/
BackColor = "backColor",
/**
* Toggles bold on/off for the selection or at the insertion point. Internet Explorer uses the <strong> tag instead of <b>.
*/
Bold = "bold",
/**
* Clears all authentication credentials from the cache.
*/
ClearAuthenticationCache = "ClearAuthenticationCache",
/**
* Makes the content document either read-only or editable. This requires a boolean true/false as the value argument.
* (Not supported by Internet Explorer.)
*/
ContentReadOnly = "contentReadOnly",
/**
* Copies the current selection to the clipboard. Conditions of having this behavior enabled vary from one browser to another,
* and have evolved over time. Check the compatibility table to determine if you can use it in your case.
*/
Copy = "copy",
/**
* Creates an hyperlink from the selection, but only if there is a selection. Requires a URI string as a value argument for the
* hyperlink's href. The URI must contain at least a single character, which may be whitespace.
* (Internet Explorer will create a link with a null value.)
*/
CreateLink = "createLink",
/**
* Removes the current selection and copies it to the clipboard. When this behavior is enabled varies between browsers,
* and its conditions have evolved over time. Check the compatibility table for usage details.
*/
Cut = "cut",
/**
* Adds a <small> tag around the selection or at the insertion point. (Not supported by Internet Explorer.)
*/
DecreaseFontSize = "decreaseFontSize",
/**
* Changes the paragraph separator used when new paragraphs are created in editable text regions. See Differences in markup
* generation for more details.
*/
DefaultParagraphSeparator = "defaultParagraphSeparator",
/**
* Deletes the current selection.
*/
Delete = "delete",
/**
* Enables or disables the table row/column insertion and deletion controls. (Not supported by Internet Explorer.)
*/
EnableInlineTableEditing = "enableInlineTableEditing",
/**
* Enables or disables the resize handles on images and other resizable objects. (Not supported by Internet Explorer.)
*/
EnableObjectResizing = "enableObjectResizing",
/**
* Changes the font name for the selection or at the insertion point. This requires a font name string (like "Arial")
* as a value argument.
*/
FontName = "fontName",
/**
* Changes the font size for the selection or at the insertion point. This requires an integer from 1-7 as a value argument.
*/
FontSize = "fontSize",
/**
* Changes a font color for the selection or at the insertion point. This requires a hexidecimal color value string
* as a value argument.
*/
ForeColor = "foreColor",
/**
* Adds an HTML block-level element around the line containing the current selection, replacing the block element containing
* the line if one exists (in Firefox, <blockquote> is the exception — it will wrap any containing block element).
* Requires a tag-name string as a value argument. Virtually all block-level elements can be used.
* (Internet Explorer supports only heading tags H1–H6, ADDRESS, and PRE, which must be wrapped in angle brackets, such as "<H1>".)
*/
FormatBlock = "formatBlock",
/**
* Deletes the character ahead of the cursor's position, identical to hitting the Delete key on a Windows keyboard.
*/
ForwardDelete = "forwardDelete",
/**
* Adds a heading element around a selection or insertion point line. Requires the tag-name stringas a value argument (i.e. "H1", "H6").
* (Not supported by Internet Explorer and Safari.)
*/
Heading = "heading",
/**
* Changes the background color for the selection or at the insertion point. Requires a color value string as a value argument.
* useCSS must be true for this to function. (Not supported by Internet Explorer.)
*/
HiliteColor = "hiliteColor",
/**
* Adds a <big> tag around the selection or at the insertion point. (Not supported by Internet Explorer.)
*/
IncreaseFontSize = "increaseFontSize",
/**
* Indents the line containing the selection or insertion point. In Firefox, if the selection spans multiple lines at different
* levels of indentation, only the least indented lines in the selection will be indented.
*/
Indent = "indent",
/**
* Controls whether the Enter key inserts a <br> element, or splits the current block element into two.
* (Not supported by Internet Explorer.)
*/
InsertBrOnReturn = "insertBrOnReturn",
/**
* Inserts a <hr> element at the insertion point, or replaces the selection with it.
*/
InsertHorizontalRule = "insertHorizontalRule",
/**
* Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string as a value argument.
* (Not supported by Internet Explorer.)
*/
InsertHTML = "insertHTML",
/**
* Inserts an image at the insertion point (deletes selection). Requires a URL string for the image's src as a value argument.
* The requirements for this string are the same as createLink.
*/
InsertImage = "insertImage",
/**
* Creates a numbered ordered list for the selection or at the insertion point.
*/
InsertOrderedList = "insertOrderedList",
/**
* Creates a bulleted unordered list for the selection or at the insertion point.
*/
InsertUnorderedList = "insertUnorderedList",
/**
* Inserts a paragraph around the selection or the current line.
* (Internet Explorer inserts a paragraph at the insertion point and deletes the selection.)
*/
InsertParagraph = "insertParagraph",
/**
* Inserts the given plain text at the insertion point (deletes selection).
*/
InsertText = "insertText",
/**
* Toggles italics on/off for the selection or at the insertion point.
* (Internet Explorer uses the <em> element instead of <i>.)
*/
Italic = "italic",
/**
* Centers the selection or insertion point.
*/
JustifyCenter = "justifyCenter",
/**
* Justifies the selection or insertion point.
*/
JustifyFull = "justifyFull",
/**
* Justifies the selection or insertion point to the left.
*/
JustifyLeft = "justifyLeft",
/**
* Right-justifies the selection or the insertion point.
*/
JustifyRight = "justifyRight",
/**
* Outdents the line containing the selection or insertion point.
*/
Outdent = "outdent",
/**
* Pastes the clipboard contents at the insertion point (replaces current selection). Disabled for web content. See [1].
*/
Paste = "paste",
/**
* Redoes the previous undo command.
*/
Redo = "redo",
/**
* Removes all formatting from the current selection.
*/
RemoveFormat = "removeFormat",
/**
* Selects all of the content of the editable region.
*/
SelectAll = "selectAll",
/**
* Toggles strikethrough on/off for the selection or at the insertion point.
*/
StrikeThrough = "strikeThrough",
/**
* Toggles subscript on/off for the selection or at the insertion point.
*/
Subscript = "subscript",
/**
* Toggles superscript on/off for the selection or at the insertion point.
*/
Superscript = "superscript",
/**
* Toggles underline on/off for the selection or at the insertion point.
*/
Underline = "underline",
/**
* Undoes the last executed command.
*/
Undo = "undo",
/**
* Removes the anchor element from a selected hyperlink.
*/
Unlink = "unlink",
/**
* Replaces the useCSS command. true modifies/generates style attributes in markup, false generates presentational elements.
*/
StyleWithCSS = "styleWithCSS"
}
/**
* The is essentially an enum representing result from browser compareDocumentPosition API
* https: */
export const enum DocumentPosition {
/**
* Same node
*/
Same = 0,
/**
* Node is disconnected from document
*/
Disconnected = 1,
/**
* Node is preceding the comparing node
*/
Preceding = 2,
/**
* Node is following the comparing node
*/
Following = 4,
/**
* Node contains the comparing node
*/
Contains = 8,
/**
* Node is contained by the comparing node
*/
ContainedBy = 16
}
/**
* The is essentially an enum represents the type of the node
* https: * Values not listed here are deprecated.
*/
export const enum NodeType {
/**
* An Element node such as <p> or <div>.
*/
Element = 1,
/**
* The actual Text of Element or Attr.
*/
Text = 3,
/**
* A ProcessingInstruction of an XML document such as <?xml-stylesheet ... ?> declaration.
*/
ProcessingInstruction = 7,
/**
* A Comment node.
*/
Comment = 8,
/**
* A Document node.
*/
Document = 9,
/**
* A DocumentType node e.g. <!DOCTYPE html> for HTML5 documents.
*/
DocumentType = 10,
/**
* A DocumentFragment node.
*/
DocumentFragment = 11
}
/**
* enum for setting block alignment, used by setAlignment API
*/
export const enum Alignment {
/**
* Align left
*/
Left = 0,
/**
* Align center
*/
Center = 1,
/**
* Align right
*/
Right = 2
}
/**
* Possible change sources. Here are the predefined sources.
* It can also be other string if the change source can't fall into these sources.
*/
export const enum ChangeSource {
/**
* Content changed by auto link
*/
AutoLink = "AutoLink",
/**
* Content changed by create link
*/
CreateLink = "CreateLink",
/**
* Content changed by format
*/
Format = "Format",
/**
* Content changed by image resize
*/
ImageResize = "ImageResize",
/**
* Content changed by paste
*/
Paste = "Paste",
/**
* Content changed by setContent API
*/
SetContent = "SetContent",
/**
* Content changed by cut operation
*/
Cut = "Cut",
/**
* Content changed by drag & drop operation
*/
Drop = "Drop",
/**
* Insert a new entity into editor
*/
InsertEntity = "InsertEntity"
}
/**
* The position. Mostly used for content insertion and traversing
* On insertion, we will need to specify where we want the content to be placed (begin, end, selection or outside)
* On content traversing, we will need to specify the start position of traversing
*/
export const enum ContentPosition {
/**
* Begin of the container
*/
Begin = 0,
/**
* End of the container
*/
End = 1,
/**
* End of the content div domain.
*/
DomEnd = 2,
/**
* Selection start
*/
SelectionStart = 3,
/**
* Outside of editor
*/
Outside = 4,
/**
* Manually defined range
*/
Range = 5
}
/**
* enum for setting block direction, used by setDirection API
*/
export const enum Direction {
/**
* Left to right
*/
LeftToRight = 0,
/**
* Right to left
*/
RightToLeft = 1
}
/**
* Define possible operations to an entity
*/
export const enum EntityOperation {
/**
* Notify plugins that there is a new plugin was added into editor.
* Plugin can handle this event to entity hydration.
* This event will be only fired once for each entity DOM node.
* After undo, or copy/paste, since new DOM nodes were added, this event will be fired
* for those entites represented by newly added nodes.
*/
NewEntity = 0,
/**
* Notify plugins that user is clicking target to an entity
*/
Click = 1,
/**
* Notify plugins that user is triggering context menu to an entity
*/
ContextMenu = 2,
/**
* Notify plugins that user is escaping from an entity by pressing ESC key
*/
Escape = 3,
/**
* Notify plugins that user is removing an entity from its start position using DELETE key
*/
RemoveFromStart = 4,
/**
* Notify plugins that user is remove an entity from its end position using BACKSPACE key
*/
RemoveFromEnd = 5,
/**
* Notify plugins that an entity is being overwritten.
* This can be causes by key in, cut, paste, delete, backspace ... on a selection
* which contains some entites.
*/
Overwrite = 6,
/**
* Notify plugins that an entity is being partially overwritten.
* This happens when user selected part of the entity then do key press, or cut, paste, delete, backspace, ...
*/
PartialOverwrite = 7,
/**
* Notify plugins that editor is generating HTML content for save.
* Plugin should use this event to remove any temporary content, and only leave DOM nodes that
* should be saved as HTML string.
* This event will provide a cloned DOM tree for each entity, do NOT compare the DOM nodes with cached nodes
* because it will always return false.
*/
ReplaceTemporaryContent = 8
}
/**
* The enum used for increase or decrease font size
* Used by setFontSize API
*/
export const enum FontSizeChange {
/**
* Increase font size
*/
Increase = 0,
/**
* Decrease font size
*/
Decrease = 1
}
/**
* The enum used for increase or decrease indentation of a block
* Used by setIndentation API
*/
export const enum Indentation {
/**
* Increase indentation
*/
Increase = 0,
/**
* Decrease indentation
*/
Decrease = 1
}
/**
* Type of list (numbering or bullet)
*/
export const enum ListType {
/**
* None list type
* It means this is not a list
*/
None = 0,
/**
* Ordered List type (numbering list)
* Represented by "OL" tag
*/
Ordered = 1,
/**
* Unordered List type (bullet list)
* Represented by "UL" tag
*/
Unordered = 2
}
/**
* Paste option
*/
export const enum PasteOption {
/**
* Paste html with content type "text/html"
*/
PasteHtml = 0,
/**
* Paste plain text with content type "text/plain"
*/
PasteText = 1,
/**
* Paste image from clipboard with content type "image/*"
*/
PasteImage = 2
}
/**
* Represent the type of a position
*/
export const enum PositionType {
/**
* At the begninning of a node
*/
Begin = 0,
/**
* At the endo of a node
*/
End = -1,
/**
* Before a node
*/
Before = -2,
/**
* After a node
*/
After = -3
}
/**
* Query scope for queryElements() API
*/
export const enum QueryScope {
/**
* Query from the whole body of root node. This is default value.
*/
Body = 0,
/**
* Query elements on a given selction (intersect)
* The result element can contain the selection, contain part of selection, or inside selection
*/
OnSelection = 1,
/**
* Query elements inside a given selection only
*/
InSelection = 2
}
/**
* Type of all possible regions. Currently we only support region of Table
*/
export const enum RegionType {
/**
* Region splitted by Table
*/
Table = 0
}
/**
* Operations used by editTable() API
*/
export const enum TableOperation {
/**
* Insert a row above current row
*/
InsertAbove = 0,
/**
* Insert a row below current row
*/
InsertBelow = 1,
/**
* Insert a column on the left of current column
*/
InsertLeft = 2,
/**
* Insert a column on the right of current column
*/
InsertRight = 3,
/**
* Delete the whole table
*/
DeleteTable = 4,
/**
* Delete current column
*/
DeleteColumn = 5,
/**
* Delete current row
*/
DeleteRow = 6,
/**
* Merge current row with the row above
*/
MergeAbove = 7,
/**
* Merge current row with the row below
*/
MergeBelow = 8,
/**
* Merge current column with the column on the left
*/
MergeLeft = 9,
/**
* Merge current column with the column on the right
*/
MergeRight = 10,
/**
* Split current table cell horizontally
*/
SplitHorizontally = 11,
/**
* Split current table cell vertically
*/
SplitVertically = 12
}
/**
* Editor plugin event interface
*/
export interface BasePluginEvent<T extends PluginEventType> {
/**
* Type of this event
*/
eventType: T;
/**
* An optional event cache.
* This will be consumed by event cache API to store some expensive calculation result.
* So that for the same event across plugins, the result doesn't need to be calculated again
*/
eventDataCache?: {
[key: string]: any;
};
}
/**
* Provides a chance for plugin to change the content before it is pasted into editor.
*/
export interface BeforeDisposeEvent extends BasePluginEvent<PluginEventType.BeforeDispose> {
}
/**
* Provides a chance for plugin to change the content before it is pasted into editor.
*/
export interface BeforePasteEvent extends BasePluginEvent<PluginEventType.BeforePaste> {
/**
* An object contains all related data for pasting
*/
clipboardData: ClipboardData;
/**
* HTML Document Fragment which will be inserted into content if pasteOption is set to PasteHtml
*/
fragment: DocumentFragment;
/**
* Paste option: html, text or image
*/
pasteOption: PasteOption;
}
/**
* Represents a change to the editor made by another plugin
*/
export interface ContentChangedEvent extends BasePluginEvent<PluginEventType.ContentChanged> {
/**
* Source of the change
*/
source: ChangeSource | string;
/**
* Optional related data
*/
data?: any;
}
/**
* Provides a chance for plugin to change the content before it is pasted into editor.
*/
export interface EditorReadyEvent extends BasePluginEvent<PluginEventType.EditorReady> {
}
/**
* Provide a chance for plugins to handle entity related events.
* See enum EntityOperation for more details about each operation
*/
export interface EntityOperationEvent extends BasePluginEvent<PluginEventType.EntityOperation> {
/**
* Operation to this entity
*/
operation: EntityOperation;
/**
* The entity that editor is operating on
*/
entity: Entity;
/**
* Optional raw UI event. Need to do null check before use its value
*/
rawEvent?: UIEvent;
}
/**
* @deprecated Use ExtractContentWithDomEvent instead
* Represents a custom BasePluginEvent for extracting content
*/
export interface ExtractContentEvent extends BasePluginEvent<PluginEventType.ExtractContent> {
/**
* Current content string
* Plugin can change this string to clean up the markups it added before
*/
content: string;
}
/**
* Extract Content with a DOM tree event
* This event is triggered when getContent() is called with triggerExtractContentEvent = true
* Plugin can handle this event to remove the UI only markups to return clean HTML
* by operating on a cloned DOM tree
*/
export interface ExtractContentWithDomEvent extends BasePluginEvent<PluginEventType.ExtractContentWithDom> {
/**
* Cloned root element of editor
* Plugin can change this DOM tree to clean up the markups it added before
*/
clonedRoot: HTMLElement;
}
/**
* An event fired when pending format state (bold, italic, underline, ... with collapsed selection) is changed
*/
export interface PendingFormatStateChangedEvent extends BasePluginEvent<PluginEventType.PendingFormatStateChanged> {
formatState: PendableFormatState;
}
/**
* This represents a PluginEvent wrapping native browser event
*/
export type PluginDomEvent = PluginCompositionEvent | PluginMouseEvent | PluginKeyboardEvent | PluginInputEvent | PluginScrollEvent;
/**
* This represents a PluginEvent wrapping native CompositionEnd event
*/
export interface PluginCompositionEvent extends BasePluginEvent<PluginEventType.CompositionEnd> {
rawEvent: CompositionEvent;
}
/**
* The represents a PluginEvent wrapping native Keyboard event
*/
export type PluginKeyboardEvent = PluginKeyDownEvent | PluginKeyPressEvent | PluginKeyUpEvent;
/**
* This represents a PluginEvent wrapping native KeyDown event
*/
export interface PluginKeyDownEvent extends BasePluginEvent<PluginEventType.KeyDown> {
rawEvent: KeyboardEvent;
}
/**
* This represents a PluginEvent wrapping native KeyPress event
*/
export interface PluginKeyPressEvent extends BasePluginEvent<PluginEventType.KeyPress> {
rawEvent: KeyboardEvent;
}
/**
* This represents a PluginEvent wrapping native KeyUp event
*/
export interface PluginKeyUpEvent extends BasePluginEvent<PluginEventType.KeyUp> {
rawEvent: KeyboardEvent;
}
/**
* This represents a PluginEvent wrapping native Mouse event
*/
export type PluginMouseEvent = PluginMouseDownEvent | PluginMouseUpEvent;
/**
* This represents a PluginEvent wrapping native MouseDown event
*/
export interface PluginMouseDownEvent extends BasePluginEvent<PluginEventType.MouseDown> {
rawEvent: MouseEvent;
}
/**
* This represents a PluginEvent wrapping native MouseUp event
*/
export interface PluginMouseUpEvent extends BasePluginEvent<PluginEventType.MouseUp> {
rawEvent: MouseEvent;
}
/**
* This represents a PluginEvent wrapping native input / textinput event
*/
export interface PluginInputEvent extends BasePluginEvent<PluginEventType.Input> {
rawEvent: InputEvent;
}
export interface PluginScrollEvent extends BasePluginEvent<PluginEventType.Scroll> {
rawEvent: UIEvent;
scrollContainer: HTMLElement;
}
/**
* Editor plugin event interface
*/
export type PluginEvent = BeforePasteEvent | ContentChangedEvent | EntityOperationEvent | ExtractContentEvent | ExtractContentWithDomEvent | PluginDomEvent | EditorReadyEvent | BeforeDisposeEvent | PendingFormatStateChangedEvent | DarkModeChangedEvent;
/**
* Editor plugin event type
*/
export const enum PluginEventType {
/**
* HTML KeyDown event
*/
KeyDown = 0,
/**
* HTML KeyPress event
*/
KeyPress = 1,
/**
* HTML KeyUp event
*/
KeyUp = 2,
/**
* HTML CompositionEnd event
*/
CompositionEnd = 3,
/**
* HTML MouseDown event
*/
MouseDown = 4,
/**
* HTML MouseUp event
*/
MouseUp = 5,
/**
* Content changed event
*/
ContentChanged = 6,
/**
* @deprecated Use ExtractContentWithDom instead.
* Extract Content event
* This event is triggered when getContent() is called with triggerExtractContentEvent = true
* Plugin can handle this event to remove the UI only markups to return clean HTML
*/
ExtractContent = 7,
/**
* Extract Content with a DOM tree event
* This event is triggered when getContent() is called with triggerExtractContentEvent = true
* Plugin can handle this event to remove the UI only markups to return clean HTML
* by operating on a cloned DOM tree
*/
ExtractContentWithDom = 8,
/**
* Before Paste event, provide a chance to change paste content
*/
BeforePaste = 9,
/**
* Let plugin know editor is ready now
*/
EditorReady = 10,
/**
* Let plugin know editor is about to dispose
*/
BeforeDispose = 11,
/**
* HTML Input / TextInput event
*/
Input = 12,
/**
* Pending format state (bold, italic, underline, ... with collapsed selection) is changed
*/
PendingFormatStateChanged = 13,
/**
* Dark mode state is changed
*/
DarkModeChanged = 14,
/**
* Scroll event triggered by scroll container
*/
Scroll = 15,
/**
* Operating on an entity. See enum EntityOperation for more details about each operation
*/
EntityOperation = 16
}
/**
* A type to extract data part of a plugin event type. Data part is the plugin event without eventType field.
*/
export type PluginEventData<T extends PluginEventType> = PluginEventDataGeneric<PluginEvent, T>;
/**
* A type to extract data part of a plugin event type. Data part is the plugin event without eventType field.
* This type is a middle result and only used by PluginEventData type
*/
export type PluginEventDataGeneric<E extends PluginEvent, T extends PluginEventType> = E extends BasePluginEvent<T> ? Pick<E, Exclude<keyof E, 'eventType'>> : never;
/**
* A type to get specify plugin event type from eventType parameter.
*/
export type PluginEventFromType<T extends PluginEventType> = PluginEventFromTypeGeneric<PluginEvent, T>;
/**
* A type to get specify plugin event type from eventType parameter.
* This type is a middle result and only used by PluginEventFromType type
*/
export type PluginEventFromTypeGeneric<E extends PluginEvent, T extends PluginEventType> = E extends BasePluginEvent<T> ? E : never;
export interface DarkModeChangedEvent extends BasePluginEvent<PluginEventType.DarkModeChanged> {
changedToDarkMode: boolean;
}
/**
* This refers to a "content block" in editor that serves as a content parsing boundary
* It is most those html block like tags, i.e. <p>, <div>, <li>, <td> etc.
* but can also be just a text node, followed by a <br>, i.e.
* for html fragment <div>abc<br>123</div>, abc<br> is a block, 123 is another block
*/
export interface BlockElement {
/**
* Collapse this block element to a single DOM element.
*/
collapseToSingleElement(): HTMLElement;
/**
* Get start node of this block element
*/
getStartNode(): Node;
/**
* Get end node of this block element
*/
getEndNode(): Node;
/**
* Check whether this block element equals to the given block element
*/
equals(blockElement: BlockElement): boolean;
/**
* Checks if this block element is after another block element
*/
isAfter(blockElement: BlockElement): boolean;
/**
* Check if the given node is within this block element
*/
contains(node: Node): boolean;
/**
* Get the text content of this block element
*/
getTextContent(): string;
}
/**
* An object contains all related data for pasting
*/
export interface ClipboardData {
/**
* An editor content snapshot before pasting happens. This is used for changing paste format
*/
snapshotBeforePaste: string;
/**
* The format state at cursor before pasting. This is used for changing paste format
*/
originalFormat: DefaultFormat;
/**
* Types of content included by the original onpaste event
*/
types: string[];
/**
* If the copied data contains image format, this will be the image blob. Otherwise it is null.
*/
image: File;
/**
* If the copied data contains plain text format, this will be the plain text string. Otherwise it is null.
*/
text: string;
/**
* If the copied data contains HTML format, this will be the sanitized html string. Otherwise it is null.
*/
html: string;
/**
* If the copied data contains HTML format, this will be the original html string without any processing. Otherwise it is null.
*/
rawHtml: string;
}
/**
* Represents items retrieved from clipboard event
*/
export interface ClipboardItems {
/**
* Available types from clipboard event
*/
types: string[];
/**
* Plain text from clipboard event
*/
text: string;
/**
* HTML string from clipboard event.
* When set to null, it means there's no HTML from clipboard event.
* When set to undefined, it means there may be HTML in clipboard event, but fail to retrieve
*/
html: string;
/**
* Image file from clipboard event
*/
image: File;
}
/**
* The options to specify dark mode editor behavior
*/
export interface DarkModeOptions {
/** Transform on insert controls if, when the editor is initialized, content should be transformed for dark mode.
* Set this to true to run the content being set to the editor through an initial transform into dark mode.
* Set this to false if you are setting dark mode compliant content initialy.
*/
transformOnInitialize?: boolean;
/**
* RoosterJS provides an experemental "external content handler" that transforms text
* This is used when content is pasted or inserted via a method we can hook into.
* This transform is currently "lossy" and will eliminate color information.
* If you want change this behavior, you may define a different function here.
* It takes in the impacted HTMLElement
*/
onExternalContentTransform?: (htmlIn: HTMLElement) => void;
}
/**
* Default format settings
*/
export interface DefaultFormat {
/**
* Font family
*/
fontFamily?: string;
/**
* Font size
*/
fontSize?: string;
/**
* Single text color (for non dark mode/single mode editor)
*/
textColor?: string;
/**
* Text color light/dark mode pair
*/
textColors?: ModeIndependentColor;
/**
* Single background color (for non dark mode/single mode editor)
*/
backgroundColor?: string;
/**
* Background color light/dark mode pair
*/
backgroundColors?: ModeIndependentColor;
/**
* Whether is bold
*/
bold?: boolean;
/**
* Whether is italic
*/
italic?: boolean;
/**
* Whether has underline
*/
underline?: boolean;
}
/**
* Represents an entity in editor.
* An entity is an HTML element with special CSS classes and will be treated as an atom from the editor.
* Editor provides basic operations and will trigger related events to let plugins know that there is
* operation target to an entity.
* Plugin can insert/remove an entity, handle entity events, query entities within the editor.
* Plugin can also set an entity to be readonly so that user can't modify content within an entity.
*/
export interface Entity {
/**
* Type of this entity. Specified when insert an entity, can be an valid CSS class-like string.
*/
type: string;
/**
* Id of this entity, generated by editor code and will be unique within an editor
*/
id: string;
/**
* The root DOM node of this entity
*/
contentNode: HTMLElement;
/**
* Whether this is a readonly entity
*/
isReadonly: boolean;
}
/**
* The format state
*/
export interface FormatState extends PendableFormatState, ElementBasedFormatState, StyleBasedFormatState {
/**
* @deprecated Use editor.canUndo() instead
* Whether the content can be undone
*/
canUndo?: boolean;
/**
* @deprecated Use editor.canRedo() instead
* Whether the content ca nbe redone
*/
canRedo?: boolean;
}
/**
* Format states that can have pending state.
*
* e.g., When using execCommand('bold') target to a collapsed selection, browser will enter bold state,
* but there isn't a <B> tag until user type something, or the state will be rollback if selection
* is changed.
*/
export interface PendableFormatState {
/**
* Whether the text is bolded
*/
isBold?: boolean;
/**
* Whether the text is italic
*/
isItalic?: boolean;
/**
* Whether the text has underline
*/
isUnderline?: boolean;
/**
* Whether the text has strike through line
*/
isStrikeThrough?: boolean;
/**
* Whether the text is in subscript mode
*/
isSubscript?: boolean;
/**
* Whether the text is in superscript mode
*/
isSuperscript?: boolean;
}
/**
* Format state represented by DOM element
*/
export interface ElementBasedFormatState {
/**
* Whether the text is in bullet mode
*/
isBullet?: boolean;
/**
* Whether the text is in numbering mode
*/
isNumbering?: boolean;
/**
* Whether the text is in block quote
*/
isBlockQuote?: boolean;
/**
* Whether unlink command can be called to the text
*/
canUnlink?: boolean;
/**
* Whether add image alt text command can be called to the text
*/
canAddImageAltText?: boolean;
/**
* Header level (0-6, 0 means no header)
*/
headerLevel?: number;
}
/**
* Format states represented by CSS style
*/
export interface StyleBasedFormatState {
/**
* Font name
*/
fontName?: string;
/**
* Font size
*/
fontSize?: string;
/**
* Background color
*/
backgroundColor?: string;
/**
* Text color
*/
textColor?: string;
}
/**
* This refers to an inline element (as opposed to block) in editor
* Inline and block makes the "type" system in editor.
* An inline element is a maximum resolvable "entity" within the boundary of a block
* At minimum and also most commonly, it represents a text node.
* It can represent broader "content" depending on the resolvers that are available, i.e.
* it can be anchor link, image, emoji, ...
* Two rules:
* 1) every inline element must have a container node (text or span, a etc.)
* 2) inline element cannot be nested
*/
export interface InlineElement {
/**
* Get the text content of this inline element
*/
getTextContent(): string;
/**
* Get the container node of this inline element
*/
getContainerNode(): Node;
/**
* Get the parent block element of this inline element
*/
getParentBlock(): BlockElement;
/**
* Get the start position of this inline element
*/
getStartPosition(): NodePosition;
/**
* Get the end position of this inline element
*/
getEndPosition(): NodePosition;
/**
* Checks if the given inline element is after this inline element
*/
isAfter(inlineElement: InlineElement): boolean;
/**
* Checks if this inline element is a textual inline element
*/
isTextualInlineElement(): boolean;
/**
* Checks if the given editor position is contained in this inline element
*/
contains(position: NodePosition): boolean;
/**
* Apply inline style to a region of an inline element
*/
applyStyle(styler: (element: HTMLElement, isInnerNode?: boolean) => any): void;
}
/**
* Type definition for the InsertOption, used in the insertNode API.
* The position parameter defines how the node will be inserted.
* In a future revision, this will become strongly typed
* Only parameters applicable to the given position will be accepted.
*/
export type InsertOption = InsertOptionRange | InsertOptionBasic;
/**
* Shared options for insertNode related APIs
*/
export interface InsertOptionBase {
/**
* Whether need to update cursor.
*/
updateCursor?: boolean;
/**
* Boolean flag for inserting the content onto a new line.
* No-op for ContentPosition.Outside
*/
insertOnNewLine?: boolean;
/**
* Boolean flag for inserting the content onto a new line.
* No-op for ContentPosition.Begin, End, and Outside
*/
replaceSelection?: boolean;
}
/**
* The "basic" insertNode related ContentPositions that require no additional parameters to use.
*/
export interface InsertOptionBasic extends InsertOptionBase {
position: ContentPosition.Begin | ContentPosition.End | ContentPosition.DomEnd | ContentPosition.Outside | ContentPosition.SelectionStart;
}
/**
* The Range varient where insertNode will opperate on a range disjointed from the current selection state.
*/
export interface InsertOptionRange extends InsertOptionBase {
position: ContentPosition.Range;
/**
* The range to be targeted when insertion happens.
*/
range: Range;
}
/**
* LinkData represents a link match result
*/
export interface LinkData {
/**
* Schema of a hyperlink
*/
scheme: string;
/**
* Original url of a hyperlink
*/
originalUrl: string;
/**
* Normalized url of a hyperlink
*/
normalizedUrl: string;
}
export interface ModeIndependentColor {
/**
* The color to be used in dark mode, if enabled.
*/
darkModeColor: string;
/**
* The color to be used in light mode, or stored as the original color in dark mode.
*/
lightModeColor: string;
}
/**
* Represent a position in DOM tree by the node and its offset index
*/
export interface NodePosition {
readonly node: Node;
readonly element: HTMLElement;
readonly offset: number;
readonly isAtEnd: boolean;
/**
* Normalize this position to the leaf node, return the normalize result.
* If current position is already using leaf node, return this position object itself
*/
normalize(): NodePosition;
/**
* Check if this position is equal to the given position
* @param position The position to check
*/
equalTo(position: NodePosition): boolean;
/**
* Checks if this position is after the given position
* @param position The position to check
*/
isAfter(position: NodePosition): boolean;
/**
* Move this position with offset, returns a new position with a valid offset in the same node
* @param offset Offset to move with
*/
move(offset: number): NodePosition;
}
/**
* This represents a rect inside editor
*/
export interface Rect {
/**
* Top
*/
top: number;
/**
* Bottom
*/
bottom: number;
/**
* Left
*/
left: number;
/**
* Right
*/
right: number;
}
/**
* Represents a DOM region.
* A region is a range under a given node, and possibly after one child and before another child
* e.g.
* ```html
* <div>
* <table>...</table>
* <span>...</span>
* <span>...</span>
* <table>...</table>
* <div>
* ```
* We can define a region under DIV before the second TABLE and after the first TABLE
*
* This is used when user's selection go across different TD elements or start from TD and end after
* that TD (or inverse way). Some block operation should not ruin the TABLE structure, so we need to
* split the selection into several regions.
*/
export interface Region {
/**
* Root node of this region
*/
rootNode: HTMLElement;
/**
* A node to define the beginning boundary of this region.
* All nodes after this node before nodeAfter and contaiend by rootNode will be treated contained by this region.
*/
nodeBefore: Node;
/**
* A node to define the ending boundary of this region.
* All nodes before this node after nodeBefore and contaiend by rootNode will be treated contained by this region.
*/
nodeAfter: Node;
/**
* Tags that child elements will be skipped
*/
skipTags: string[];
/**
* Start position of full selection. It is possible to be out of this region.
* We use this position and fullSelectionEnd to calculate the selected range inside this region.
*/
fullSelectionStart: NodePosition;
/**
* End position of full selection. It is possible to be out of this region.
* We use this position and fullSelectionStart to calculate the selected range inside this region.
*/
fullSelectionEnd: NodePosition;
}
/**
* A start and end pair of selection path
*/
export interface SelectionPath {
/**
* Start path of selection
*/
start: number[];
/**
* End path of selection
*/
end: number[];
}
/**
* Represents a data structure of snapshots, this is usually used for undo snapshots
*/
export interface Snapshots {
/**
* The snapshot array
*/
snapshots: string[];
/**
* Size of all snapshots
*/
totalSize: number;
/**
* Current index
*/
currentIndex: number;
/**
* Max size of all snapshots
*/
readonly maxSize: number;
}
/**
* Table format
*/
export interface TableFormat {
/**
* Background color for even rows
*/
bgColorEven: string;
/**
* Background color for odd rows
*/
bgColorOdd: string;
/**
* Top border color for each row
*/
topBorderColor: string;
/**
* Bottom border color for each row
*/
bottomBorderColor: string;
/**
* Vertical border color for each row
*/
verticalBorderColor: string;
}
/**
* Options for HtmlSanitizer
*/
export interface HtmlSanitizerOptions {
/**
* Callbacks for HTML elements
*/
elementCallbacks?: ElementCallbackMap;
/**
* Callbacks for HTML attributes
*/
attributeCallbacks?: AttributeCallbackMap;
/**
* Callbacks for CSS styles
*/
styleCallbacks?: StyleCallbackMap;
/**
* Allowed HTML tags in addition to default tags, in upper case
*/
additionalAllowedTags?: string[];
/**
* Allowed HTML attributes in addition to default attributes, in lower case
* TODO: rename to "additionalAllowedAttributes" in next major release
*/
additionalAllowAttributes?: string[];
/**
* Allowed CSS Class names
*/
additionalAllowedCssClasses?: string[];
/**
* CSS style default values in addition to the default value map, style name should be in lower case
*/
additionalDefaultStyleValues?: StringMap;
/**
* Additional global CSS style nodes
*/
additionalGlobalStyleNodes?: HTMLStyleElement[];
/**
* Whether allow CSS white-space in result
*/
allowPreserveWhiteSpace?: boolean;
}
/**
* Options for sanitizeHtml function
*/
export interface SanitizeHtmlOptions extends HtmlSanitizerOptions {
/**
* Current HTML element, styles of this element will be used as current style values.
* Or a string map represents current styles
*/
currentElementOrStyle?: HTMLElement | StringMap;
/**
* When set to true, will only do inline CSS conversion and skip the sanitizing pass
*/
convertCssOnly?: boolean;
/**
* When set to true, only content inside Fragment markup (if any) will be preserved
*/
preserveFragmentOnly?: boolean;
}
/**
* Define DOM types of window, used by safeInstanceOf() to check if a given object is of the specified type of its own window
*
* !!!Note: This file is generated from /tools/generateTargetWindow.js. Do NOT modify this file directly!!!
*/
export interface TargetWindow {
Range: Range;
Node: Node;
Element: Element;
SVGElement: SVGElement;
SVGViewElement: SVGViewElement;
SVGTitleElement: SVGTitleElement;
SVGSymbolElement: SVGSymbolElement;
SVGStyleElement: SVGStyleElement;
SVGStopElement: SVGStopElement;
SVGScriptElement: SVGScriptElement;
SVGPatternElement: SVGPatternElement;
SVGMetadataElement: SVGMetadataElement;
SVGMaskElement: SVGMaskElement;
SVGMarkerElement: SVGMarkerElement;
SVGGraphicsElement: SVGGraphicsElement;
SVGUseElement: SVGUseElement;
SVGTextContentElement: SVGTextContentElement;
SVGTextPositioningElement: SVGTextPositioningElement;
SVGTextElement: SVGTextElement;
SVGTSpanElement: SVGTSpanElement;
SVGTextPathElement: SVGTextPathElement;
SVGSwitchElement: SVGSwitchElement;
SVGSVGElement: SVGSVGElement;
SVGPathElement: SVGPathElement;
SVGImageElement: SVGImageElement;
SVGGeometryElement: SVGGeometryElement;
SVGRectElement: SVGRectElement;
SVGPolylineElement: SVGPolylineElement;
SVGPolygonElement: SVGPolygonElement;
SVGLineElement: SVGLineElement;
SVGEllipseElement: SVGEllipseElement;
SVGCircleElement: SVGCircleElement;
SVGGElement: SVGGElement;
SVGForeignObjectElement: SVGForeignObjectElement;
SVGDefsElement: SVGDefsElement;
SVGAElement: SVGAElement;
SVGGradientElement: SVGGradientElement;
SVGRadialGradientElement: SVGRadialGradientElement;
SVGLinearGradientElement: SVGLinearGradientElement;
SVGFilterElement: SVGFilterElement;
SVGFETurbulenceElement: SVGFETurbulenceElement;
SVGFETileElement: SVGFETileElement;
SVGFESpotLightElement: SVGFESpotLightElement;
SVGFESpecularLightingElement: SVGFESpecularLightingElement;
SVGFEPointLightElement: SVGFEPointLightElement;
SVGFEOffsetElement: SVGFEOffsetElement;
SVGFEMorphologyElement: SVGFEMorphologyElement;
SVGFEMergeNodeElement: SVGFEMergeNodeElement;
SVGFEMergeElement: SVGFEMergeElement;
SVGFEImageElement: SVGFEImageElement;
SVGFEGaussianBlurElement: SVGFEGaussianBlurElement;
SVGFEFloodElement: SVGFEFloodElement;
SVGFEDropShadowElement: SVGFEDropShadowElement;
SVGFEDistantLightElement: SVGFEDistantLightElement;
SVGFEDisplacementMapElement: SVGFEDisplacementMapElement;
SVGFEDiffuseLightingElement: SVGFEDiffuseLightingElement;
SVGFEConvolveMatrixElement: SVGFEConvolveMatrixElement;
SVGFECompositeElement: SVGFECompositeElement;
SVGFEComponentTransferElement: SVGFEComponentTransferElement;
SVGFEColorMatrixElement: SVGFEColorMatrixElement;
SVGFEBlendElement: SVGFEBlendElement;
SVGDescElement: SVGDescElement;
SVGCursorElement: SVGCursorElement;
SVGComponentTransferFunctionElement: SVGComponentTransferFunctionElement;
SVGFEFuncRElement: SVGFEFuncRElement;
SVGFEFuncGElement: SVGFEFuncGElement;
SVGFEFuncBElement: SVGFEFuncBElement;
SVGFEFuncAElement: SVGFEFuncAElement;
SVGClipPathElement: SVGClipPathElement;
SVGAnimationElement: SVGAnimationElement;
SVGAnimateTransformElement: SVGAnimateTransformElement;
SVGAnimateMotionElement: SVGAnimateMotionElement;
SVGAnimateElement: SVGAnimateElement;
HTMLElement: HTMLElement;
HTMLUnknownElement: HTMLUnknownElement;
HTMLUListElement: HTMLUListElement;
HTMLTrackElement: HTMLTrackElement;
HTMLTitleElement: HTMLTitleElement;
HTMLTimeElement: HTMLTimeElement;
HTMLTextAreaElement: HTMLTextAreaElement;
HTMLTemplateElement: HTMLTemplateElement;
HTMLTableSectionElement: HTMLTableSectionElement;
HTMLTableRowElement: HTMLTableRowElement;
HTMLTableElement: HTMLTableElement;
HTMLTableColElement: HTMLTableColElement;
HTMLTableCellElement: HTMLTableCellElement;
HTMLTableHeaderCellElement: HTMLTableHeaderCellElement;
HTMLTableDataCellElement: HTMLTableDataCellElement;
HTMLTableCaptionElement: HTMLTableCaptionElement;
HTMLStyleElement: HTMLStyleElement;
HTMLSpanElement: HTMLSpanElement;
HTMLSourceElement: HTMLSourceElement;
HTMLSlotElement: HTMLSlotElement;
HTMLSelectElement: HTMLSelectElement;
HTMLScriptElement: HTMLScriptElement;
HTMLQuoteElement: HTMLQuoteElement;
HTMLProgressElement: HTMLProgressElement;
HTMLPreElement: HTMLPreElement;
HTMLPictureElement: HTMLPictureElement;
HTMLParamElement: HTMLParamElement;
HTMLParagraphElement: HTMLParagraphElement;
HTMLOutputElement: HTMLOutputElement;
HTMLOptionElement: HTMLOptionElement;
HTMLOptGroupElement: HTMLOptGroupElement;
HTMLObjectElement: HTMLObjectElement;
HTMLOListEl