UNPKG

roosterjs

Version:

A simple facade for all roosterjs code

1,931 lines (1,793 loc) 341 kB
// Type definitions for roosterjs (Version 9.31.0) // Generated by dts tool from roosterjs // Project: https://github.com/Microsoft/roosterjs declare namespace roosterjs { /** * Create a new Editor instance using the given 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 * PastePlugin, EditPlugin, user don't need to add those. * @param initialModel The initial content model to show in editor. It can't be removed by undo, user need to manually remove it if needed. * @returns The Editor instance */ function createEditor(contentDiv: HTMLDivElement, additionalPlugins?: EditorPlugin[], initialModel?: ContentModelDocument): IEditor; /** * The format object for a segment in Content Model */ type ContentModelSegmentFormat = TextColorFormat & BackgroundColorFormat & LetterSpacingFormat & FontSizeFormat & FontFamilyFormat & BoldFormat & ItalicFormat & UnderlineFormat & StrikeFormat & SuperOrSubScriptFormat & LineHeightFormat; /** * Represent a content model with format */ interface ContentModelWithFormat<T extends ContentModelFormatBase> { /** * Format of this model */ format: T; } /** * Represent a content model with format (Readonly) */ interface ReadonlyContentModelWithFormat<T extends ContentModelFormatBase> { /** * Format of this model */ readonly format: Readonly<T>; } /** * Format of Table */ type ContentModelTableFormat = ContentModelBlockFormat & IdFormat & AriaFormat & BorderFormat & BorderBoxFormat & SpacingFormat & MarginFormat & DisplayFormat & TableLayoutFormat & SizeFormat; /** * Represents base format of an element that supports dataset and/or metadata */ type ContentModelWithDataset<T> = MutableMark & { /** * dataset of this element */ dataset: DatasetFormat; }; /** * Represents base format of an element that supports dataset and/or metadata (Readonly) */ type ReadonlyContentModelWithDataset<T> = ReadonlyMark & { /** * dataset of this element */ readonly dataset: ReadonlyDatasetFormat; }; /** * Represents base format of an element that supports dataset and/or metadata (Readonly) */ type ShallowMutableContentModelWithDataset<T> = ShallowMutableMark & { /** * dataset of this element */ dataset: DatasetFormat; }; /** * The format object for a paragraph in Content Model */ type ContentModelBlockFormat = BackgroundColorFormat & DirectionFormat & TextAlignFormat & HtmlAlignFormat & MarginFormat & PaddingFormat & LineHeightFormat & WhiteSpaceFormat & BorderFormat & TextIndentFormat & IdFormat; /** * Format of table cell */ type ContentModelTableCellFormat = ContentModelBlockFormat & BorderBoxFormat & VerticalAlignFormat & WordBreakFormat & TextColorFormat & SizeFormat & BoldFormat; /** * The format object for a list item in Content Model */ type ContentModelListItemFormat = DirectionFormat & LineHeightFormat & MarginFormat & PaddingFormat & TextAlignFormat & ListStyleFormat & TextIndentFormat & BackgroundColorFormat; /** * The format object for a list level in Content Model */ type ContentModelListItemLevelFormat = ListThreadFormat & DirectionFormat & TextAlignFormat & MarginFormat & PaddingFormat & ListStyleFormat; /** * The format object for a hyperlink in Content Model */ type ContentModelHyperLinkFormat = LinkFormat & TextColorFormat & BackgroundColorFormat & UnderlineFormat & DisplayFormat & MarginFormat & PaddingFormat & BorderFormat & SizeFormat & TextAlignFormat & UndeletableFormat; /** * The format object for a code element in Content Model */ type ContentModelCodeFormat = FontFamilyFormat & DisplayFormat; /** * Type for FormatContainer */ type ContentModelFormatContainerFormat = ContentModelBlockFormat & ContentModelSegmentFormat & SizeFormat & DisplayFormat; /** * The format object for a divider in Content Model */ type ContentModelDividerFormat = ContentModelBlockFormat & DisplayFormat & SizeFormat; /** * Base type of content model format. * All content model format should only have simple value type (string, number, boolean). * So that we can use a single level copy ({...object}) to easily clone a format object */ type ContentModelFormatBase<V extends string | number | boolean | undefined | null = string | number | boolean | undefined | null> = { [key: string]: V; }; /** * A map from Content Model format name to its combined format type */ interface ContentModelFormatMap { /** * Format type for block */ block: ContentModelBlockFormat; /** * Format type for style based segment format */ styleBasedSegment: ContentModelSegmentFormat; /** * Format type for element based segment format */ elementBasedSegment: ContentModelSegmentFormat; /** * Format type for segment */ segment: ContentModelSegmentFormat; /** * Format type for segment on block. * Block can have format that can impact segment, such as font and color. * But some segment format should not be read from block, like background color. */ segmentOnBlock: ContentModelSegmentFormat; /** * Format type for segment on table cell. * This is very similar with segmentOnBlock, without 'textColor'. Because we will keep * text color style on table cell to indicate auto calculated segment color when set table cell shade. * Segments can set its own text color to override this value */ segmentOnTableCell: ContentModelSegmentFormat; /** * Format type for table, except alignment related styles */ table: ContentModelTableFormat; /** * Format type for tableCell */ tableCell: ContentModelTableCellFormat; /** * Format type for tableRow */ tableRow: ContentModelBlockFormat; /** * Format type for tableColumn */ tableColumn: SizeFormat; /** * Format type for table border */ tableBorder: ContentModelTableFormat; /** * Format type for tableCell border */ tableCellBorder: ContentModelTableCellFormat; /** * Format type for li element */ listItemElement: ContentModelListItemFormat; /** * Format type for listItem */ listItemThread: ContentModelListItemLevelFormat; /** * Format type for listLevel */ listLevel: ContentModelListItemLevelFormat; /** * Format type for listLevel */ listLevelThread: ContentModelListItemLevelFormat; /** * Format type for image */ image: ContentModelImageFormat; /** * Format type for link */ link: ContentModelHyperLinkFormat; /** * Format type for segment inside link */ segmentUnderLink: ContentModelHyperLinkFormat; /** * Format type for code */ code: FontFamilyFormat; /** * Format type for dataset */ dataset: DatasetFormat; /** * Format type for divider */ divider: ContentModelDividerFormat; /** * Format type for format container */ container: ContentModelFormatContainerFormat; /** * Format type for entity */ entity: ContentModelEntityFormat; /** * Format type for general model */ general: ContentModelSegmentFormat; } /** * The format object for an image in Content Model */ type ContentModelImageFormat = ContentModelSegmentFormat & IdFormat & SizeFormat & MarginFormat & PaddingFormat & BorderFormat & BoxShadowFormat & DisplayFormat & FloatFormat & VerticalAlignFormat & ImageStateFormat; /** * The format object for an entity in Content Model */ type ContentModelEntityFormat = EntityInfoFormat & IdFormat; /** * Represents a record of all format handlers */ interface FormatHandlerTypeMap { /** * Format for AriaFormat */ aria: AriaFormat; /** * Format for BackgroundColorFormat */ backgroundColor: BackgroundColorFormat; /** * Format for BoldFormat */ bold: BoldFormat; /** * Format for BorderFormat */ border: BorderFormat; /** * Format for BorderBoxFormat */ borderBox: BorderBoxFormat; /** * Format for BoxShadowFormat */ boxShadow: BoxShadowFormat; /** * Format for DatasetFormat */ dataset: DatasetFormat; /** * Format for DirectionFormat */ direction: DirectionFormat; /** * Format for DisplayFormat */ display: DisplayFormat; /** * Format for EntityInfoFormat and IdFormat */ entity: EntityInfoFormat & IdFormat; /** * Format for FloatFormat */ float: FloatFormat; /** * Format for FontFamilyFormat */ fontFamily: FontFamilyFormat; /** * Format for FontSizeFormat */ fontSize: FontSizeFormat; /** * Format for HtmlAlignFormat */ htmlAlign: HtmlAlignFormat; /** * Format for IdFormat */ id: IdFormat; /** * Format of ImageStateFormat */ imageState: ImageStateFormat; /** * Format for ItalicFormat */ italic: ItalicFormat; /** * Format for LetterSpacingFormat */ letterSpacing: LetterSpacingFormat; /** * Format for LineHeightFormat */ lineHeight: LineHeightFormat; /** * Format for LinkFormat */ link: LinkFormat; /** * Format for ListThreadFormat (used by list item) */ listItemThread: ListThreadFormat; /** * Format for ListThreadFormat (used by list level) */ listLevelThread: ListThreadFormat; /** * Format for ListStyleFormat */ listStyle: ListStyleFormat; /** * Format for MarginFormat */ margin: MarginFormat; /** * Format for PaddingFormat */ padding: PaddingFormat; /** * Format for SizeFormat */ size: SizeFormat; /** * Format for StrikeFormat */ strike: StrikeFormat; /** * Format for SuperOrSubScriptFormat */ superOrSubScript: SuperOrSubScriptFormat; /** * Format for TableLayout */ tableLayout: TableLayoutFormat; /** * Format for SpacingFormat */ tableSpacing: SpacingFormat; /** * Format for TextAlignFormat */ textAlign: TextAlignFormat; /** * Format for TextColorFormat */ textColor: TextColorFormat; /** * Format for TextColorFormat, for Table Cell only */ textColorOnTableCell: TextColorFormat; /** * Format for TextIndentFormat */ textIndent: TextIndentFormat; /** * Format for Undeletable link */ undeletableLink: UndeletableFormat; /** * Format for UnderlineFormat */ underline: UnderlineFormat; /** * Format for VerticalAlignFormat */ verticalAlign: VerticalAlignFormat; /** * Format for WhiteSpaceFormat */ whiteSpace: WhiteSpaceFormat; /** * Format for WordBreakFormat */ wordBreak: WordBreakFormat; } /** * Key of all format handler */ type FormatKey = keyof FormatHandlerTypeMap; /** * Format of background color */ type AriaFormat = { /** * Aria-describedby attribute */ ariaDescribedBy?: string; /** * Title attribute */ title?: string; }; /** * Format of background color */ type BackgroundColorFormat = { /** * Background color */ backgroundColor?: string; }; /** * Format of bold */ type BoldFormat = { /** * Font weight of the element */ fontWeight?: string; }; /** * Format of font family */ type FontFamilyFormat = { /** * Font family */ fontFamily?: string; }; /** * Format of font size */ type FontSizeFormat = { /** * Font size */ fontSize?: string; }; /** * Format of italic */ type ItalicFormat = { /** * Whether it is in italic */ italic?: boolean; }; /** * Format of letter spacing */ type LetterSpacingFormat = { /** * letter-spacing style */ letterSpacing?: string; }; /** * Format of line height */ type LineHeightFormat = { /** * Line height of this block */ lineHeight?: string; }; /** * Format of strikethrough */ type StrikeFormat = { /** * Whether it has strike through */ strikethrough?: boolean; }; /** * Format of superscript/subscript */ type SuperOrSubScriptFormat = { /** * Sequence of superscript/subscript * e.g. sub super sub */ superOrSubScriptSequence?: string; }; /** * Format of text color */ type TextColorFormat = { /** * Text color */ textColor?: string; }; /** * Format of underline */ type UnderlineFormat = { /** * Whether it has underline */ underline?: boolean; }; /** * Format of border box */ type BorderBoxFormat = { /** * Whether use border-box for this element */ useBorderBox?: boolean; }; /** * Format of vertical alignment */ type VerticalAlignFormat = { /** * Vertical alignment */ verticalAlign?: 'top' | 'middle' | 'bottom'; }; /** * Format of word break */ type WordBreakFormat = { /** * Word break CSS value */ wordBreak?: string; }; /** * Format of border */ type BorderFormat = { /** * Top border in format 'width style color' */ borderTop?: string; /** * Right border in format 'width style color' */ borderRight?: string; /** * Bottom border in format 'width style color' */ borderBottom?: string; /** * Left border in format 'width style color' */ borderLeft?: string; /** * Radius to be applied in all borders corners */ borderRadius?: string; /** * Radius to be applied in top left corner */ borderTopLeftRadius?: string; /** * Radius to be applied in top right corner */ borderTopRightRadius?: string; /** * Radius to be applied in bottom left corner */ borderBottomLeftRadius?: string; /** * Radius to be applied in bottom right corner */ borderBottomRightRadius?: string; }; /** * Format of direction */ type DirectionFormat = { /** * Text direction */ direction?: 'ltr' | 'rtl'; }; /** * Format of HTML align attribute */ type HtmlAlignFormat = { /** * Horizontal alignment, from HTML attribute "align" */ htmlAlign?: 'start' | 'center' | 'end' | 'justify' | 'initial'; }; /** * Format of margin */ type MarginFormat = { /** * Margin top value */ marginTop?: string; /** * Margin right value */ marginRight?: string; /** * Margin bottom value */ marginBottom?: string; /** * Margin left value */ marginLeft?: string; }; /** * Format of padding */ type PaddingFormat = { /** * Padding top value */ paddingTop?: string; /** * Padding right value */ paddingRight?: string; /** * Padding bottom value */ paddingBottom?: string; /** * Padding left value */ paddingLeft?: string; }; /** * Format of text-align */ type TextAlignFormat = { /** * Horizontal alignment, from CSS "text-align" */ textAlign?: 'start' | 'center' | 'end' | 'justify' | 'initial'; }; /** * Format of text-indent */ type TextIndentFormat = { /** * Text indent of a paragraph */ textIndent?: string; /** * Due to the special behavior of text-indent style, we need to know if this text-indent style is already applied to any child block. * Then after that, we can ignore it for the block at the same level. */ isTextIndentApplied?: boolean; }; /** * Format of white space */ type WhiteSpaceFormat = { /** * White space */ whiteSpace?: string; }; /** * Format of display */ type DisplayFormat = { /** * Display of this element */ display?: string; }; /** * Format for element with Id */ type IdFormat = { /** * Id of the element */ id?: string; }; /** * Format of spacing */ type SpacingFormat = { /** * Whether borders of cells are collapsed together */ borderCollapse?: boolean; /** * Whether borders of cells are separated */ borderSeparate?: boolean; }; /** * Format of Table Layout */ type TableLayoutFormat = { /** * Whether borders of cells are collapsed together */ tableLayout?: string; }; /** * Format of hyper link */ type LinkFormat = { /** * Name of this link */ name?: string; /** * Href of the hyper link */ href?: string; /** * Target of the hyper link */ target?: string; /** * Id of anchor element */ anchorId?: string; /** * Class attribute of anchor element */ anchorClass?: string; /** * Title attribute of anchor element */ anchorTitle?: string; /** * Rel attribute of anchor element */ relationship?: string; }; /** * Format of element size */ type SizeFormat = { /** * Width of the element */ width?: string; /** * Height of the element */ height?: string; /** * Maximum width of the element */ maxWidth?: string; /** * Maximum height of the element */ maxHeight?: string; /** * Minimum width of the element */ minWidth?: string; /** * Minimum height of the element */ minHeight?: string; }; /** * Format of box shadow */ type BoxShadowFormat = { /** * Box shadow in format "offset-x offset-y blur-radius spread-radius color" */ boxShadow?: string; }; /** * Format of list thread id */ type ListThreadFormat = { /** * When restart a new list thread, set this value to be the restart number. * Otherwise, leave it undefined to continue last list */ startNumberOverride?: number; /** * For a list item, it should have "list-item" (default value) for display style. In those case, * we will leave displayForDummyItem as undefined. * But if there is other value than "list-item" in display style, we store it here and treat this item * as a dummy item. Dummy item won't have list bullet or number, and we won't add 1 for list number for such items */ displayForDummyItem?: string; }; /** * Format of list-style */ type ListStyleFormat = { /** * list-style-position */ listStylePosition?: string; /** * list-style-type */ listStyleType?: string; }; /** * Format of float */ type FloatFormat = { /** * Float style */ float?: string; }; /** * Format of entity type */ type EntityInfoFormat = { /** * For a readonly DOM element, we also treat it as entity, with isFakeEntity set to true */ isFakeEntity?: boolean; /** * Whether the entity is readonly */ isReadonly?: boolean; /** * Type of this entity */ entityType?: string; }; /** * Format of undeletable segments */ type UndeletableFormat = { /** * When set to true, this link is not allowed to be deleted by deleteSelection API. * This is used to protect links that are not allowed to be deleted by user action. */ undeletable?: boolean; }; /** * The hidden property of an image */ type ImageStateFormat = { /** * A hidden marker for the image state */ imageState?: string; }; /** * Represents dataset format of Content Model */ type DatasetFormat = Record<string, string>; /** * Represents dataset format of Content Model (Readonly) */ type ReadonlyDatasetFormat = Readonly<Record<string, string>>; /** * Format of table that stored as metadata */ type TableMetadataFormat = { /** * Top border color for each row */ topBorderColor?: string | null; /** * Bottom border color for each row */ bottomBorderColor?: string | null; /** * Vertical border color for each row */ verticalBorderColor?: string | null; /** * Set header row */ hasHeaderRow?: boolean; /** * Header row background color for even cells */ headerRowColor?: string | null; /** * Set first column */ hasFirstColumn?: boolean; /** * Set banded columns */ hasBandedColumns?: boolean; /** * Set banded rows */ hasBandedRows?: boolean; /** * Background color for even row or even columns */ bgColorEven?: string | null; /** * Background color for odd row or odd columns */ bgColorOdd?: string | null; /** * Table Borders Type. Use value of constant TableBorderFormat as value */ tableBorderFormat?: number; /** * Vertical alignment for each row */ verticalAlign?: 'top' | 'middle' | 'bottom' | null; }; /** * Format of list / list item that stored as metadata */ type ListMetadataFormat = { /** * Style type for Ordered list. Use value of constant NumberingListType as value. */ orderedStyleType?: number; /** * Style type for Unordered list. Use value of constant BulletListType as value. */ unorderedStyleType?: number; /** * When set to true, if there is no orderedStyleType (for OL) or unorderedStyleType (for UL) specified, use the list from its level * For ordered list, the default list styles from levels are: 'decimal', 'lower-alpha', 'lower-roman', then loop * For unordered list, the default list styles from levels are: 'disc', 'circle', 'square', then loop */ applyListStyleFromLevel?: boolean; }; /** * Metadata for inline image resize */ type ImageResizeMetadataFormat = { /** * Width after resize, in px. * If image is cropped, this is the width of visible part * If image is rotated, this is the width before rotation * @default clientWidth of the image */ widthPx?: number; /** * Height after resize, in px. * If image is cropped, this is the height of visible part * If image is rotated, this is the height before rotation * @default clientHeight of the image */ heightPx?: number; }; /** * Metadata for inline image crop */ type ImageCropMetadataFormat = { /** * Left cropped percentage. Rotation or resizing won't impact this percentage value * @default 0 */ leftPercent?: number; /** * Right cropped percentage. Rotation or resizing won't impact this percentage value * @default 0 */ rightPercent?: number; /** * Top cropped percentage. Rotation or resizing won't impact this percentage value * @default 0 */ topPercent?: number; /** * Bottom cropped percentage. Rotation or resizing won't impact this percentage value * @default 0 */ bottomPercent?: number; }; /** * Metadata for inline image */ type ImageMetadataFormat = ImageResizeMetadataFormat & ImageCropMetadataFormat & ImageRotateMetadataFormat & ImageFlipMetadataFormat & { /** * Original src of the image. This value will not be changed when edit image. We can always use it * to get the original image so that all editing operation will be on top of the original image. */ readonly src?: string; /** * Natural width of the original image (specified by the src field, may not be the current edited image) */ readonly naturalWidth?: number; /** * Natural height of the original image (specified by the src field, may not be the current edited image) */ readonly naturalHeight?: number; }; /** * Metadata for inline image rotate */ type ImageRotateMetadataFormat = { /** * Rotated angle of inline image, in radian. Cropping or resizing won't impact this percentage value * @default 0 */ angleRad?: number; }; /** * Metadata for inline image flip */ interface ImageFlipMetadataFormat { /** * If true, the image was flipped. */ flippedVertical?: boolean; /** * If true, the image was flipped. */ flippedHorizontal?: boolean; } /** * Format of table cell that stored as metadata */ type TableCellMetadataFormat = { /** * Override default background color */ bgColorOverride?: boolean; /** * Override default vertical align value */ vAlignOverride?: boolean; /** * Override default border value */ borderOverride?: boolean; }; /** * Type of Block Group in Content Model */ type ContentModelBlockGroupType = /** * Represents the document entry of Content Model */ 'Document' /** * Represents a FormatContainer */ | 'FormatContainer' /** * Represents a list item (LI) element */ | 'ListItem' /** * Represents a table cell (TD, TH) element */ | 'TableCell' /** * Represents a general HTML element that doesn't have a special type */ | 'General'; /** * Type of Block in Content Model */ type ContentModelBlockType = /** * Represent a Block Group */ 'BlockGroup' /** * Represent a Table */ | 'Table' /** * Represent a general paragraph (DIV, P, ...) */ | 'Paragraph' /** * Represent a block entity */ | 'Entity' /** * Represents a horizontal divider element */ | 'Divider'; /** * Type of Segment in Content Model */ type ContentModelSegmentType = /** * Represents a text node */ 'Text' /** * Represents a BR element */ | 'Br' /** * Represents an IMG element */ | 'Image' /** * Represents a selection marker. A selection marker is an empty segment that mark the start/end of selection */ | 'SelectionMarker' /** * Represents a general segment that doesn't have a special type */ | 'General' /** * Represents an inline entity */ | 'Entity'; /** * Define entity lifecycle related operations */ type EntityLifecycleOperation = /** * 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 entities represented by newly added nodes. */ 'newEntity' /** * 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' /** * This event is triggered when an undo snapshot is taken while a custom logical root is used * Plugins can handle this event to include entity state to include in the snapshot */ | 'snapshotEntityState' /** * Notify plugins that a new entity state need to be updated to an entity. * This is normally happened when user undo/redo the content with an entity snapshot added by a plugin that handles entity */ | 'updateEntityState' /** * Notify plugins that user is clicking target to an entity */ | 'click'; /** * Define possible operations to an entity */ type EntityOperation = EntityLifecycleOperation | EntityRemovalOperation | EntityFormatOperation; /** * Define entity removal related operations */ type EntityRemovalOperation = /** * Notify plugins that user is removing an entity from its start position using DELETE key */ 'removeFromStart' /** * Notify plugins that user is remove an entity from its end position using BACKSPACE key */ | 'removeFromEnd' /** * Notify plugins that an entity is being overwritten. * This can be caused by key in, cut, paste, delete, backspace ... on a selection * which contains some entities. */ | 'overwrite'; /** * DEfine entity format related operations */ type EntityFormatOperation = /** * Tell plugins we are doing format change and an entity is inside the selection. * Plugin can handle this event and put root level node (must be under the entity wrapper) into * event.formattableRoots so editor will create content models for each root and do format to their contents */ 'beforeFormat'; /** * Operations used by editTable() API */ type TableOperation = TableVerticalInsertOperation | TableHorizontalInsertOperation | TableDeleteOperation | TableVerticalMergeOperation | TableHorizontalMergeOperation | TableCellMergeOperation | TableSplitOperation | TableAlignOperation | TableCellHorizontalAlignOperation | TableCellVerticalAlignOperation; /** * Operations used by editTable() API for insert table cell vertically */ type TableVerticalInsertOperation = /** * Insert a row above current row */ 'insertAbove' /** * Insert a row below current row */ | 'insertBelow'; /** * Operations used by editTable() API for insert table cell horizontally */ type TableHorizontalInsertOperation = /** * Insert a column on the left of current column */ 'insertLeft' /** * Insert a column on the right of current column */ | 'insertRight'; /** * Operations used by editTable() API for delete table cells */ type TableDeleteOperation = /** * Delete the whole table */ 'deleteTable' /** * Delete current column */ | 'deleteColumn' /** * Delete current row */ | 'deleteRow'; /** * Operations used by editTable() API for merge table cells vertically */ type TableVerticalMergeOperation = /** * Merge current row with the row above */ 'mergeAbove' /** * Merge current row with the row below */ | 'mergeBelow'; /** * Operations used by editTable() API for merge table cells horizontally */ type TableHorizontalMergeOperation = /** * Merge current column with the column on the left */ 'mergeLeft' /** * Merge current column with the column on the right */ | 'mergeRight'; /** * Operations used by editTable() API for merge selected table cells */ type TableCellMergeOperation = /** * Merge all selected cells */ 'mergeCells'; /** * Operations used by editTable() API for split table cells */ type TableSplitOperation = /** * Split current table cell horizontally */ 'splitHorizontally' /** * Split current table cell vertically */ | 'splitVertically'; /** * Operations used by editTable() API for align table */ type TableAlignOperation = /** * Align current table at the center */ 'alignCenter' /** * Align current table at the left */ | 'alignLeft' /** * Align current table at the right */ | 'alignRight'; /** * Operations used by editTable() API for align table cell horizontally */ type TableCellHorizontalAlignOperation = /** * Align current content table cell at the left */ 'alignCellLeft' /** * Align current content table cell at the center */ | 'alignCellCenter' /** * Align current content table cell at the right */ | 'alignCellRight'; /** * Operations used by editTable() API for align table cell vertically */ type TableCellVerticalAlignOperation = /** * Align current content table cell at the top */ 'alignCellTop' /** * Align current table cell at the middle */ | 'alignCellMiddle' /** * Align current table cell at the bottom */ | 'alignCellBottom'; /** * Specify what type of content to paste */ type PasteType = /** * Default paste behavior */ 'normal' /** * Paste only the plain text */ | 'asPlainText' /** * Apply the current style to pasted content */ | 'mergeFormat' /** * If there is a image uri in the clipboard, paste the content as image element */ | 'asImage'; /** * All Border operations */ type BorderOperations = /** * Apply border format to all borders */ 'allBorders' /** * Remove al borders */ | 'noBorders' /** * Apply border format to left borders */ | 'leftBorders' /** * Apply border format to right borders */ | 'rightBorders' /** * Apply border format to top borders */ | 'topBorders' /** * Apply border format to bottom borders */ | 'bottomBorders' /** * Apply border format to inside borders */ | 'insideBorders' /** * Apply border format to outside borders */ | 'outsideBorders'; /** * Delete selection result */ type DeleteResult = /** * Content Model could not finish deletion, need to let browser handle it */ 'notDeleted' /** * Deleted a single char, no need to let browser keep handling */ | 'singleChar' /** * Deleted a range, no need to let browser keep handling */ | 'range' /** * There is nothing to delete, no need to let browser keep handling */ | 'nothingToDelete'; /** * Define the position of the entity to insert. It can be: * "focus": insert at current focus. If insert a block entity, it will be inserted under the paragraph where focus is * "begin": insert at beginning of content. When insert an inline entity, it will be wrapped with a paragraph. * "end": insert at end of content. When insert an inline entity, it will be wrapped with a paragraph. * "root": insert at the root level of current region */ type InsertEntityPosition = 'focus' | 'begin' | 'end' | 'root'; /** * The mode parameter type for exportContent API */ type ExportContentMode = /** * Export to clean HTML in light color mode with dehydrated entities */ 'HTML' /** * Export to plain text */ | 'PlainText' /** * Export to plain text via browser's textContent property */ | 'PlainTextFast'; /** * A union type of Content Model Block */ type ContentModelBlock = ContentModelFormatContainer | ContentModelListItem | ContentModelGeneralBlock | ContentModelTable | ContentModelParagraph | ContentModelEntity | ContentModelDivider; /** * A union type of Content Model Block (Readonly) */ type ReadonlyContentModelBlock = ReadonlyContentModelFormatContainer | ReadonlyContentModelListItem | ReadonlyContentModelGeneralBlock | ReadonlyContentModelTable | ReadonlyContentModelParagraph | ContentModelEntity | ReadonlyContentModelDivider; /** * A union type of Content Model Block (Shallow mutable) */ type ShallowMutableContentModelBlock = ShallowMutableContentModelFormatContainer | ShallowMutableContentModelListItem | ShallowMutableContentModelGeneralBlock | ShallowMutableContentModelTable | ShallowMutableContentModelParagraph | ContentModelEntity | ContentModelDivider; /** * Content Model of Paragraph */ interface ContentModelParagraph extends ContentModelParagraphCommon, ContentModelBlockBase<'Paragraph'> { /** * Segments within this paragraph */ segments: ContentModelSegment[]; /** * Segment format on this paragraph. This is mostly used for default format */ segmentFormat?: ContentModelSegmentFormat; /** * Decorator info for this paragraph, used by heading and P tags */ decorator?: ContentModelParagraphDecorator; } /** * Common part of Content Model of Paragraph */ interface ContentModelParagraphCommon { /** * Whether this block was created from a block HTML element or just some simple segment between other block elements. * True means it doesn't have a related block element, false means it was from a block element */ isImplicit?: boolean; } /** * Content Model of Paragraph (Readonly) */ interface ReadonlyContentModelParagraph extends ReadonlyContentModelBlockBase<'Paragraph'>, Readonly<ContentModelParagraphCommon> { /** * Segments within this paragraph */ readonly segments: ReadonlyArray<ReadonlyContentModelSegment>; /** * Segment format on this paragraph. This is mostly used for default format */ readonly segmentFormat?: Readonly<ContentModelSegmentFormat>; /** * Decorator info for this paragraph, used by heading and P tags */ readonly decorator?: ReadonlyContentModelParagraphDecorator; } /** * Content Model of Paragraph (Shallow mutable) */ interface ShallowMutableContentModelParagraph extends ContentModelParagraphCommon, ContentModelBlockBase<'Paragraph'> { /** * Segments within this paragraph */ segments: ShallowMutableContentModelSegment[]; /** * Segment format on this paragraph. This is mostly used for default format */ segmentFormat?: ContentModelSegmentFormat; /** * Decorator info for this paragraph, used by heading and P tags */ decorator?: ContentModelParagraphDecorator; } /** * Content Model of Table */ interface ContentModelTable extends ContentModelBlockBase<'Table', ContentModelTableFormat, HTMLTableElement>, ContentModelWithDataset<TableMetadataFormat> { /** * Widths of each column */ widths: number[]; /** * Cells of this table */ rows: ContentModelTableRow[]; } /** * Content Model of Table (Readonly) */ interface ReadonlyContentModelTable extends ReadonlyContentModelBlockBase<'Table', ContentModelTableFormat, HTMLTableElement>, ReadonlyContentModelWithDataset<TableMetadataFormat> { /** * Widths of each column */ readonly widths: ReadonlyArray<number>; /** * Cells of this table */ readonly rows: ReadonlyArray<ReadonlyContentModelTableRow>; } /** * Content Model of Table (Shallow mutable) */ interface ShallowMutableContentModelTable extends ShallowMutableContentModelBlockBase<'Table', ContentModelTableFormat, HTMLTableElement>, ShallowMutableContentModelWithDataset<TableMetadataFormat> { /** * Widths of each column */ widths: number[]; /** * Cells of this table */ rows: ShallowMutableContentModelTableRow[]; } /** * Content Model of horizontal divider */ interface ContentModelDivider extends Selectable, ContentModelDividerCommon, ContentModelBlockBase<'Divider', ContentModelDividerFormat> { } /** * Common part of Content Model of horizontal divider */ interface ContentModelDividerCommon { /** * Tag name of this element, either HR or DIV */ tagName: 'hr' | 'div'; /** * Size property for HR */ size?: string; } /** * Content Model of horizontal divider (Readonly) */ interface ReadonlyContentModelDivider extends ReadonlySelectable, ReadonlyContentModelBlockBase<'Divider', ContentModelDividerFormat>, Readonly<ContentModelDividerCommon> { } /** * Base type of a block */ interface ContentModelBlockBase<T extends ContentModelBlockType, TFormat extends ContentModelBlockFormat = ContentModelBlockFormat, TCacheElement extends HTMLElement = HTMLElement> extends MutableMark, ContentModelBlockBaseCommon<T>, ContentModelWithFormat<TFormat>, ContentModelBlockWithCache<TCacheElement> { } /** * Common part of base type of a block */ interface ContentModelBlockBaseCommon<T extends ContentModelBlockType> { /** * Type of this block */ readonly blockType: T; } /** * Base type of a block (Readonly) */ interface ReadonlyContentModelBlockBase<T extends ContentModelBlockType, TFormat extends ContentModelBlockFormat = ContentModelBlockFormat, TCacheElement extends HTMLElement = HTMLElement> extends ReadonlyMark, ContentModelBlockBaseCommon<T>, ReadonlyContentModelWithFormat<TFormat>, ContentModelBlockWithCache<TCacheElement> { } /** * Base type of a block (Shallow mutable) */ interface ShallowMutableContentModelBlockBase<T extends ContentModelBlockType, TFormat extends ContentModelBlockFormat = ContentModelBlockFormat, TCacheElement extends HTMLElement = HTMLElement> extends ShallowMutableMark, ContentModelBlockBaseCommon<T>, ContentModelWithFormat<TFormat>, ContentModelBlockWithCache<TCacheElement> { } /** * Represent a Content Model block with cached element */ interface ContentModelBlockWithCache<TElement extends HTMLElement = HTMLElement> { /** * Cached element for reuse */ cachedElement?: TElement; } /** * Content Model of Table */ interface ContentModelTableRow extends MutableMark, ContentModelTableRowCommon, ContentModelBlockWithCache<HTMLTableRowElement>, ContentModelWithFormat<ContentModelBlockFormat> { /** * Cells of this table */ cells: ContentModelTableCell[]; } /** * Common part of Content Model of Table */ interface ContentModelTableRowCommon { /** * Heights of each row */ height: number; } /** * Content Model of Table (Readonly) */ interface ReadonlyContentModelTableRow extends ReadonlyMark, Readonly<ContentModelTableRowCommon>, ContentModelBlockWithCache<HTMLTableRowElement>, ReadonlyContentModelWithFormat<ContentModelBlockFormat> { /** * Cells of this table */ readonly cells: ReadonlyArray<ReadonlyContentModelTableCell>; } /** * Content Model of Table (Readonly) */ interface ShallowMutableContentModelTableRow extends ShallowMutableMark, ContentModelTableRowCommon, ContentModelBlockWithCache<HTMLTableRowElement>, ContentModelWithFormat<ContentModelBlockFormat> { /** * Cells of this table */ cells: ReadonlyContentModelTableCell[]; } /** * Content Model of Entity */ interface ContentModelEntity extends ContentModelBlockBase<'Entity', ContentModelBlockFormat & ContentModelSegmentFormat>, ContentModelSegmentBase<'Entity', ContentModelBlockFormat & ContentModelSegmentFormat> { /** * The wrapper DOM node of this entity which holds the info CSS classes of this entity */ wrapper: HTMLElement; /** * Format of this entity */ entityFormat: ContentModelEntityFormat; } /** * Content Model document entry point */ interface ContentModelDocument extends ContentModelDocumentCommon, ContentModelBlockGroupBase<'Document'>, Partial<ContentModelWithFormat<ContentModelSegmentFormat>> { } /** * Common part of Content Model document entry point */ interface ContentModelDocumentCommon { /** * Whether the selection in model (if any) is a revert selection (end is before start) */ hasRevertedRangeSelection?: boolean; } /** * Content Model document entry point (Readonly) */ interface ReadonlyContentModelDocument extends Readonly<ContentModelDocumentCommon>, ReadonlyContentModelBlockGroupBase<'Document'>, Partial<ReadonlyContentModelWithFormat<ContentModelSegmentFormat>> { } /** * Content Model document entry point (Shallow mutable) */ interface ShallowMutableContentModelDocument extends ContentModelDocumentCommon, ShallowMutableContentModelBlockGroupBase<'Document'>, Partial<ContentModelWithFormat<ContentModelSegmentFormat>> { } /** * Base type of Content Model Block Group */ interface ContentModelBlockGroupBase<T extends ContentModelBlockGroupType, TElement extends HTMLElement = HTMLElement> extends MutableMark, ContentModelBlockGroupBaseCommon<T, TElement> { /** * Blocks under this group */ blocks: ContentModelBlock[]; } /** * Common part of base type of Content Model Block Group */ interface ContentModelBlockGroupBaseCommon<T extends ContentModelBlockGroupType, TElement extends HTMLElement = HTMLElement> extends ContentModelBlockWithCache<TElement> { /** * Type of this block group */ readonly blockGroupType: T; } /** * Base type of Content Model Block Group (Readonly) */ interface ReadonlyContentModelBlockGroupBase<T extends ContentModelBlockGroupType, TElement extends HTMLElement = HTMLElement> extends ReadonlyMark, ContentModelBlockGroupBaseCommon<T, TElement> { /** * Blocks under this group */ readonly blocks: ReadonlyArray<ReadonlyContentModelBlock>; } /** * Base type of Content Model Block Group (Shallow mutable) */ interface ShallowMutableContentModelBlockGroupBase<T extends ContentModelBlockGroupType, TElement extends HTMLElement = HTMLElement> extends ShallowMutableMark, ContentModelBlockGroupBaseCommon<T, TElement> { /** * Blocks under this group */ blocks: ReadonlyContentModelBlock[]; } /** * Content Model of Format Container */ interface ContentModelFormatContainer extends ContentModelFormatContainerCommon, ContentModelBlockGroupBase<'FormatContainer'>, ContentModelBlockBase<'BlockGroup', ContentModelFormatContainerFormat, HTMLElement> { } /** * Common part of Content Model of Format Container */ interface ContentModelFormatContainerCommon { /** * Tag name of this container */ tagName: Lowercase<string>; /** * Whether we can apply "font-size: 0" to this paragraph. When set to true, we will check if there is no text segment inside, * and apply "font-size: 0" to the container element */ zeroFontSize?: boolean; } /** * Content Model of Format Container (Readonly) */ interface ReadonlyContentModelFormatContainer extends Readonly<ContentModelFormatContainerCommon>, ReadonlyContentModelBlockGroupBase<'FormatContainer'>, ReadonlyContentModelBlockBase<'BlockGroup', ContentModelFormatContainerFormat, HTMLElement> { } /** * Content Model of Format Container (Shallow mutable) */ interface ShallowMutableContentModelFormatContainer extends ContentModelFormatContainerCommon, ShallowMutableContentModelBlockGroupBase<'FormatContainer'>, ShallowMutableContentModelBlockBase<'BlockGroup', ContentModelFormatContainerFormat, HTMLElement> { } /** * Content Model for general Block element */ interface ContentModelGeneralBlock extends Selectable, ContentModelGeneralBlockCommon, ContentModelBlockGroupBase<'General'>, ContentModelBlockBase<'BlockGroup', ContentModelBlockFormat & ContentModelSegmentFormat> { } /** * Common part of Content Model for general Block element */ interface ContentModelGeneralBlockCommon { /** * A reference to original HTML node that this model was created from */ element: HTMLElement; } /** * Content Model for general Block element (Readonly) */ interface ReadonlyContentModelGeneralBlock extends ReadonlySelectable, Readonly<ContentModelGeneralBlockCommon>, ReadonlyContentModelBlockGroupBase<'General'>, ReadonlyContentModelBlockBase<'BlockGroup', ContentModelBlockFormat & ContentModelSegmentFormat> { } /** * Content Model for general Block element (Shallow mutable) */ interface ShallowMutableContentModelGeneralBlock extends ShallowMutableSelectable, ContentModelGeneralBlockCommon, ShallowMutableContentModelBlockGroupBase<'General'>, ShallowMutableContentModelBlockBase<'BlockGroup', ContentModelBlockFormat & ContentModelSegmentFormat> { } /** * Content Model of List Item */ interface ContentModelListItem extends ContentModelBlockGroupBase<'ListItem', HTMLLIElement>, ContentModelBlockBase<'BlockGroup', ContentModelListItemFormat, HTMLLIElement> { /** * Type of this list, either ordered or unordered */ levels: ContentModelListLevel[]; /** * A dummy segment to hold format of this list item */ formatHolder: ContentModelSelectionMarker; } /** * Content Model of List Item (Readonly) */ interface ReadonlyContentModelListItem extends ReadonlyContentModelBlockGroupBase<'ListItem', HTMLLIElement>, ReadonlyContentModelBlockBase<'BlockGroup', ContentModelListItemFormat, HTMLLIElement> { /** * Type of this list, either ordered or unordered */ readonly levels: ReadonlyArray<ReadonlyContentModelListLevel>; /** * A dummy segment to hold format of this list item */ readonly formatHolder: ReadonlyContentModelSelectionMarker; } /** * Content Model of List Item (Shallow mutable) */ interface ShallowMutableContentModelListItem extends ShallowMutableContentModelBlockGroupBase<'ListItem', HTMLLIElement>, ShallowMutableContentModelBlockBase<'BlockGroup', ContentModelListItemFormat, HTMLLIElement> { /** * Type of this list, either ordered or unordered */ levels: ContentModelListLevel[]; /** * A dummy segment to hold format of this list item */ formatHolder: ContentModelSelectionMarker; } /** * Content Model of Table Cell */ interface ContentModelTableCell extends Selectable, ContentModelTableCellCommon, ContentModelBlockGroupBase<'TableCell', HTMLTableCellElement>, ContentModelWithFormat<ContentModelTableCellFormat>, ContentModelWithDataset<TableCellMetadataFormat> { } /** * Common part of Content Model of Table Cell */ interface ContentModelTableCellCommon { /** * Whether this cell is spanned from left cell */ spanLeft: boolean; /** * Whether this cell is spanned from above cell */ spanAbove: boolean; /** * Whether this cell is a table header (TH) element */ isHeader?: boolean; } /** * Content Model of Table Cell (Readonly) */ interface ReadonlyContentModelTableCell extends ReadonlySelectable, Readonly<ContentModelTableCellCommon>, ReadonlyContentModelBlockGroupBase<'TableCell', HTMLTableCellElement>, ReadonlyContentModelWithFormat<ContentModelTableCellFormat>, ReadonlyContentModelWithDataset<TableCellMetadataFormat> { } /** * Content Model of Table Cell (Shallow mutable) */ interface ShallowMutableContentModelTableCell extends ShallowMutableSelectable, ContentModelTableCellCommon, ShallowMutableContentModelBlockGroupBase<'TableCell', HTMLTableCellElement>, ContentModelWithFormat<ContentModelTableCellFormat>, ShallowMutableContentModelWithDataset<TableCellMetadataFormat> { } /** * The union type of Content Model Block Group */ type ContentModelBlockGroup = Conten