roosterjs 9.1.0 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 9.1.0)
1
+ // Type definitions for roosterjs (Version 9.3.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -1479,6 +1479,10 @@ export interface ContentModelEntity extends ContentModelBlockBase<'Entity', Cont
1479
1479
  * Content Model document entry point
1480
1480
  */
1481
1481
  export interface ContentModelDocument extends ContentModelBlockGroupBase<'Document'>, Partial<ContentModelWithFormat<ContentModelSegmentFormat>> {
1482
+ /**
1483
+ * Whether the selection in model (if any) is a revert selection (end is before start)
1484
+ */
1485
+ hasRevertedRangeSelection?: boolean;
1482
1486
  }
1483
1487
 
1484
1488
  /**
@@ -2706,19 +2710,20 @@ export type ColorTransformFunction = (lightColor: string, baseLValue?: number, c
2706
2710
  * An interface of Editor, built on top of Content Model
2707
2711
  */
2708
2712
  export interface IEditor {
2713
+ /**
2714
+ * @deprecated Use formatContentModel() instead
2715
+ */
2716
+ getContentModelCopy(mode: 'connected'): ContentModelDocument;
2709
2717
  /**
2710
2718
  * Create Content Model from DOM tree in this editor
2711
2719
  * @param mode What kind of Content Model we want. Currently we support the following values:
2712
- * - connected: Returns a connect Content Model object. "Connected" means if there is any entity inside editor, the returned Content Model will
2713
- * contain the same wrapper element for entity. This option should only be used in some special cases. In most cases we should use "disconnected"
2714
- * to get a fully disconnected Content Model so that any change to the model will not impact editor content.
2715
2720
  * - disconnected: Returns a disconnected clone of Content Model from editor which you can do any change on it and it won't impact the editor content.
2716
2721
  * If there is any entity in editor, the returned object will contain cloned copy of entity wrapper element.
2717
2722
  * If editor is in dark mode, the cloned entity will be converted back to light mode.
2718
2723
  * - clean: Similar with disconnected, this will return a disconnected model, the difference is "clean" mode will not include any selection info.
2719
2724
  * This is usually used for exporting content
2720
2725
  */
2721
- getContentModelCopy(mode: 'connected' | 'disconnected' | 'clean'): ContentModelDocument;
2726
+ getContentModelCopy(mode: 'disconnected' | 'clean'): ContentModelDocument;
2722
2727
  /**
2723
2728
  * Get current running environment, such as if editor is running on Mac
2724
2729
  */
@@ -2863,6 +2868,11 @@ export interface IEditor {
2863
2868
  * combined with root selector together to build a separate rule.
2864
2869
  */
2865
2870
  setEditorStyle(key: string, cssRule: string | null, subSelectors?: 'before' | 'after' | string[]): void;
2871
+ /**
2872
+ * Announce the given data
2873
+ * @param announceData Data to announce
2874
+ */
2875
+ announce(announceData: AnnounceData): void;
2866
2876
  }
2867
2877
 
2868
2878
  /**
@@ -2956,6 +2966,12 @@ export interface EditorOptions {
2956
2966
  * Default paste type. By default will use the normal (as-is) paste type.
2957
2967
  */
2958
2968
  defaultPasteType?: PasteType;
2969
+ /**
2970
+ * A callback to help get string template to announce, used for accessibility
2971
+ * @param key The key of known announce data
2972
+ * @returns A template string to announce, use placeholder such as "{0}" for variables if necessary
2973
+ */
2974
+ announcerStringGetter?: (key: KnownAnnounceStrings) => string;
2959
2975
  }
2960
2976
 
2961
2977
  /**
@@ -3122,6 +3138,12 @@ export interface CoreApiMap {
3122
3138
  * combined with root selector together to build a separate rule.
3123
3139
  */
3124
3140
  setEditorStyle: SetEditorStyle;
3141
+ /**
3142
+ * Announce the given data
3143
+ * @param core The EditorCore object
3144
+ * @param announceData Data to announce
3145
+ */
3146
+ announce: Announce;
3125
3147
  }
3126
3148
 
3127
3149
  /**
@@ -3240,6 +3262,13 @@ export type GetVisibleViewport = (core: EditorCore) => Rect | null;
3240
3262
  */
3241
3263
  export type SetEditorStyle = (core: EditorCore, key: string, cssRule: string | null, subSelectors?: 'before' | 'after' | string[], maxRuleLength?: number) => void;
3242
3264
 
3265
+ /**
3266
+ * Announce the given data
3267
+ * @param core The EditorCore object
3268
+ * @param announceData Data to announce
3269
+ */
3270
+ export type Announce = (core: EditorCore, announceData: AnnounceData) => void;
3271
+
3243
3272
  /**
3244
3273
  * Core plugins for editor
3245
3274
  */
@@ -3476,6 +3505,16 @@ export interface LifecyclePluginState {
3476
3505
  * Cached document fragment for original content
3477
3506
  */
3478
3507
  shadowEditFragment: DocumentFragment | null;
3508
+ /**
3509
+ * The HTML container for announced string
3510
+ */
3511
+ announceContainer?: HTMLElement;
3512
+ /**
3513
+ * A callback to help get string template to announce, used for accessibility
3514
+ * @param key The key of known announce data
3515
+ * @returns A template string to announce, use placeholder such as "{0}" for variables if necessary
3516
+ */
3517
+ readonly announcerStringGetter?: (key: KnownAnnounceStrings) => string;
3479
3518
  /**
3480
3519
  * Style elements used for adding CSS rules for editor
3481
3520
  */
@@ -3779,6 +3818,10 @@ export interface FormatContentModelContext {
3779
3818
  * @optional Set to true if this action can be undone when user press Backspace key (aka Auto Complete).
3780
3819
  */
3781
3820
  canUndoByBackspace?: boolean;
3821
+ /**
3822
+ * @optional Set this value to tell AnnouncePlugin to announce the given information
3823
+ */
3824
+ announceData?: AnnounceData | null;
3782
3825
  }
3783
3826
 
3784
3827
  /**
@@ -3811,6 +3854,10 @@ export interface FormatContentModelOptions {
3811
3854
  * When specified, use this selection range to override current selection inside editor
3812
3855
  */
3813
3856
  selectionOverride?: DOMSelection;
3857
+ /**
3858
+ * When pass to true, scroll the editing caret into view after write DOM tree if need
3859
+ */
3860
+ scrollCaretIntoView?: boolean;
3814
3861
  }
3815
3862
 
3816
3863
  /**
@@ -4474,6 +4521,14 @@ export interface DOMHelper {
4474
4521
  * @returns True if the editor has focus, otherwise false
4475
4522
  */
4476
4523
  hasFocus(): boolean;
4524
+ /**
4525
+ * Check if the root element is in RTL mode
4526
+ */
4527
+ isRightToLeft(): boolean;
4528
+ /**
4529
+ * Get the width of the editable area of the editor content div
4530
+ */
4531
+ getClientWidth(): number;
4477
4532
  }
4478
4533
 
4479
4534
  /**
@@ -4707,6 +4762,60 @@ export type ParsedTable = ParsedTableCell[][];
4707
4762
  */
4708
4763
  export type ParsedTableCell = HTMLTableCellElement | 'spanLeft' | 'spanTop' | 'spanBoth';
4709
4764
 
4765
+ /**
4766
+ * Callback function type for converting a given Content Model object to plain text
4767
+ * @param model The source model object to be converted to plain text
4768
+ */
4769
+ export type ModelToTextCallback<T> = (model: T) => string;
4770
+
4771
+ /**
4772
+ * Callbacks to customize the behavior of contentModelToText function
4773
+ */
4774
+ export interface ModelToTextCallbacks {
4775
+ /**
4776
+ * Customize the behavior of converting entity segment to plain text
4777
+ */
4778
+ onEntitySegment?: ModelToTextCallback<ContentModelEntity>;
4779
+ /**
4780
+ * Customize the behavior of converting entity block to plain text
4781
+ */
4782
+ onEntityBlock?: ModelToTextCallback<ContentModelEntity>;
4783
+ /**
4784
+ * Customize the behavior of converting general segment to plain text
4785
+ */
4786
+ onGeneralSegment?: ModelToTextCallback<ContentModelGeneralSegment>;
4787
+ /**
4788
+ * Customize the behavior of converting text model to plain text
4789
+ */
4790
+ onText?: ModelToTextCallback<ContentModelText>;
4791
+ /**
4792
+ * Customize the behavior of converting image model to plain text
4793
+ */
4794
+ onImage?: ModelToTextCallback<ContentModelImage>;
4795
+ /**
4796
+ * Customize the behavior of converting divider model to plain text
4797
+ */
4798
+ onDivider?: ModelToTextCallback<ContentModelDivider>;
4799
+ /**
4800
+ * Customize the check if we should convert a paragraph model to plain text
4801
+ */
4802
+ onParagraph?: ModelToTextChecker<ContentModelParagraph>;
4803
+ /**
4804
+ * Customize the check if we should convert a table model to plain text
4805
+ */
4806
+ onTable?: ModelToTextChecker<ContentModelTable>;
4807
+ /**
4808
+ * Customize the check if we should convert a block group model to plain text
4809
+ */
4810
+ onBlockGroup?: ModelToTextChecker<ContentModelBlockGroup>;
4811
+ }
4812
+
4813
+ /**
4814
+ * Callback function type for checking if we should convert to text for the given content model object
4815
+ * @param model The source model to check if we should convert it to plain text
4816
+ */
4817
+ export type ModelToTextChecker<T> = (model: T) => boolean;
4818
+
4710
4819
  /**
4711
4820
  * Editor plugin event interface
4712
4821
  */
@@ -4855,7 +4964,7 @@ export interface ContentChangedEvent extends BasePluginEvent<'contentChanged'> {
4855
4964
  */
4856
4965
  readonly formatApiName?: string;
4857
4966
  /**
4858
- * @optional Announce data from this content changed event.
4967
+ * @deprecated Call editor.announce(announceData) directly insteaad
4859
4968
  */
4860
4969
  readonly announceData?: AnnounceData;
4861
4970
  }
@@ -5254,8 +5363,9 @@ export function contentModelToDom(doc: Document, root: Node, model: ContentModel
5254
5363
  * Convert Content Model to plain text
5255
5364
  * @param model The source Content Model
5256
5365
  * @param [separator='\r\n'] The separator string used for connect lines
5366
+ * @param callbacks Callbacks to customize the behavior of contentModelToText function
5257
5367
  */
5258
- export function contentModelToText(model: ContentModelDocument, separator?: string): string;
5368
+ export function contentModelToText(model: ContentModelDocument, separator?: string, callbacks?: ModelToTextCallbacks): string;
5259
5369
 
5260
5370
  /**
5261
5371
  * Content Model Element Processor for child elements
@@ -5493,9 +5603,25 @@ export function addDelimiters(doc: Document, element: HTMLElement, format?: Cont
5493
5603
  /**
5494
5604
  * Checks whether the node provided is a Entity delimiter
5495
5605
  * @param node the node to check
5606
+ * @param isBefore True to match delimiter before entity only, false to match delimiter after entity, or undefined means match both
5496
5607
  * @return true if it is a delimiter
5497
5608
  */
5498
- export function isEntityDelimiter(element: HTMLElement): boolean;
5609
+ export function isEntityDelimiter(element: HTMLElement, isBefore?: boolean): boolean;
5610
+
5611
+ /**
5612
+ * Check if the given element is a container element of block entity
5613
+ * @param element The element to check
5614
+ * @returns True if the element is a block entity container, otherwise false
5615
+ */
5616
+ export function isBlockEntityContainer(element: HTMLElement): boolean;
5617
+
5618
+ /**
5619
+ * Find the closest block entity wrapper element from a given DOM node
5620
+ * @param node The node to start looking for entity container
5621
+ * @param domHelper The DOM helper
5622
+ * @returns
5623
+ */
5624
+ export function findClosestBlockEntityContainer(node: Node, domHelper: DOMHelper): HTMLElement | null;
5499
5625
 
5500
5626
  /**
5501
5627
  * When set a DOM tree into editor, reuse the existing element in editor and no need to change it
@@ -5726,6 +5852,29 @@ export function normalizeSingleSegment(segment: ContentModelSegment, ignoreTrail
5726
5852
  */
5727
5853
  export function setParagraphNotImplicit(block: ContentModelBlock): void;
5728
5854
 
5855
+ /**
5856
+ * Get the list number for a list item according to list style type and its index number
5857
+ * @param styleType The list style number, should be a value of NumberingListType type
5858
+ * @param listNumber List number, start from 1
5859
+ * @returns A string for this list item. For example, when pass in NumberingListType.LowerAlpha and 2, it returns "b"
5860
+ */
5861
+ export function getOrderedListNumberStr(styleType: number, listNumber: number): string;
5862
+
5863
+ /**
5864
+ * Get automatic list style of a list item according to its lis type and metadata.
5865
+ * @param listType The list type, either OL or UL
5866
+ * @param metadata Metadata of this list item from list item model
5867
+ * @param depth Depth of list level, start from 0
5868
+ * @param existingStyleType Existing list style type in format, if any
5869
+ * @returns A number to represent list style type.
5870
+ * This will be the value of either NumberingListType (when listType is OL) or BulletListType (when listType is UL).
5871
+ * When there is a specified list style in its metadata, return this value, otherwise
5872
+ * When specified "applyListStyleFromLevel" in metadata, calculate auto list type from its depth, otherwise
5873
+ * When there is already listStyleType in list level format, find a related style type index, otherwise
5874
+ * return undefined
5875
+ */
5876
+ export function getAutoListStyleType(listType: 'OL' | 'UL', metadata: ListMetadataFormat, depth: number, existingStyleType?: string): number | undefined;
5877
+
5729
5878
  /**
5730
5879
  * Parse unit value with its unit
5731
5880
  * @param value The source value to parse
@@ -5961,12 +6110,12 @@ export function getFirstSelectedTable(model: ContentModelDocument): [ContentMode
5961
6110
 
5962
6111
  /**
5963
6112
  * Get an array of block group - block pair that is of the expected block group type from selection
5964
- * @param model The Content Model to get selection from
6113
+ * @param group The root block group to search
5965
6114
  * @param blockGroupTypes The expected block group types
5966
6115
  * @param stopTypes Block group types that will stop searching when hit
5967
6116
  * @param deepFirst True means search in deep first, otherwise wide first
5968
6117
  */
5969
- export function getOperationalBlocks<T extends ContentModelBlockGroup>(model: ContentModelDocument, blockGroupTypes: TypeOfBlockGroup<T>[], stopTypes: ContentModelBlockGroupType[], deepFirst?: boolean): OperationalBlocks<T>[];
6118
+ export function getOperationalBlocks<T extends ContentModelBlockGroup>(group: ContentModelBlockGroup, blockGroupTypes: TypeOfBlockGroup<T>[], stopTypes: ContentModelBlockGroupType[], deepFirst?: boolean): OperationalBlocks<T>[];
5970
6119
 
5971
6120
  /**
5972
6121
  * Get any array of selected paragraphs from a content model
@@ -5986,7 +6135,7 @@ export function getSelectedSegments(model: ContentModelDocument, includingFormat
5986
6135
  * @param model The Content Model to get selection from
5987
6136
  * @param includingFormatHolder True means also include format holder as segment from list item, in that case paragraph will be null
5988
6137
  */
5989
- export function getSelectedSegmentsAndParagraphs(model: ContentModelDocument, includingFormatHolder: boolean): [ContentModelSegment, ContentModelParagraph | null][];
6138
+ export function getSelectedSegmentsAndParagraphs(model: ContentModelDocument, includingFormatHolder: boolean, includingEntity?: boolean): [ContentModelSegment, ContentModelParagraph | null, ContentModelBlockGroup[]][];
5990
6139
 
5991
6140
  /**
5992
6141
  * Get selection coordinates of a table. If there is no selection, return null
@@ -6156,7 +6305,7 @@ export function updateListMetadata(list: ContentModelWithDataset<ListMetadataFor
6156
6305
  /**
6157
6306
  * Metadata definition for List
6158
6307
  */
6159
- export const ListMetadataDefinition: import("roosterjs-content-model-types").ObjectDefinition<ListMetadataFormat>;
6308
+ export const ListMetadataDefinition: ObjectDefinition<ListMetadataFormat>;
6160
6309
 
6161
6310
  /**
6162
6311
  * Possible change sources. Here are the predefined sources.
@@ -6216,6 +6365,10 @@ export const ChangeSource: {
6216
6365
  * Data of this event will be the key code number
6217
6366
  */
6218
6367
  Keyboard: string;
6368
+ /**
6369
+ * Content changed by auto format
6370
+ */
6371
+ AutoFormat: string;
6219
6372
  };
6220
6373
 
6221
6374
  /**
@@ -6477,9 +6630,6 @@ export class Editor implements IEditor {
6477
6630
  /**
6478
6631
  * Create Content Model from DOM tree in this editor
6479
6632
  * @param mode What kind of Content Model we want. Currently we support the following values:
6480
- * - connected: Returns a connect Content Model object. "Connected" means if there is any entity inside editor, the returned Content Model will
6481
- * contain the same wrapper element for entity. This option should only be used in some special cases. In most cases we should use "disconnected"
6482
- * to get a fully disconnected Content Model so that any change to the model will not impact editor content.
6483
6633
  * - disconnected: Returns a disconnected clone of Content Model from editor which you can do any change on it and it won't impact the editor content.
6484
6634
  * If there is any entity in editor, the returned object will contain cloned copy of entity wrapper element.
6485
6635
  * If editor is in dark mode, the cloned entity will be converted back to light mode.
@@ -6619,6 +6769,11 @@ export class Editor implements IEditor {
6619
6769
  * combined with root selector together to build a separate rule.
6620
6770
  */
6621
6771
  setEditorStyle(key: string, cssRule: string | null, subSelectors?: 'before' | 'after' | string[]): void;
6772
+ /**
6773
+ * Announce the given data
6774
+ * @param announceData Data to announce
6775
+ */
6776
+ announce(announceData: AnnounceData): void;
6622
6777
  /**
6623
6778
  * @returns the current EditorCore object
6624
6779
  * @throws a standard Error if there's no core object
@@ -6637,15 +6792,28 @@ export class Editor implements IEditor {
6637
6792
  export function createModelFromHtml(html: string, options?: Partial<DomToModelOptionForSanitizing>, trustedHTMLHandler?: TrustedHTMLHandler, defaultSegmentFormat?: ContentModelSegmentFormat): ContentModelDocument;
6638
6793
 
6639
6794
  /**
6640
- * Export string content of editor
6795
+ * Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity
6796
+ * @param editor The editor to get content from
6797
+ * @param mode Specify HTML to get plain text result. This is the default option
6798
+ * @param options @optional Options for Model to DOM conversion
6799
+ */
6800
+ export function exportContent(editor: IEditor, mode?: 'HTML', options?: ModelToDomOption): string;
6801
+
6802
+ /**
6803
+ * Export plain text content
6804
+ * @param editor The editor to get content from
6805
+ * @param mode Specify PlainText to get plain text result
6806
+ * @param callbacks @optional Callbacks to customize conversion behavior
6807
+ */
6808
+ export function exportContent(editor: IEditor, mode: 'PlainText', callbacks?: ModelToTextCallbacks): string;
6809
+
6810
+ /**
6811
+ * Export plain text using editor's textContent property directly
6641
6812
  * @param editor The editor to get content from
6642
- * @param mode Mode of content to export. It supports:
6643
- * - HTML: Export HTML content. If there are entities, this will cause EntityOperation event with option = 'replaceTemporaryContent' to get a dehydrated entity
6644
- * - PlainText: Export plain text content
6645
- * - PlainTextFast: Export plain text using editor's textContent property directly
6813
+ * @param mode Specify PlainTextFast to get plain text result using textContent property
6646
6814
  * @param options @optional Options for Model to DOM conversion
6647
6815
  */
6648
- export function exportContent(editor: IEditor, mode?: ExportContentMode, options?: ModelToDomOption): string;
6816
+ export function exportContent(editor: IEditor, mode: 'PlainTextFast'): string;
6649
6817
 
6650
6818
  /**
6651
6819
  * Undo to last undo snapshot
@@ -7062,8 +7230,18 @@ export function formatSegmentWithContentModel(editor: IEditor, apiName: string,
7062
7230
  * Invoke a callback to format the text segment before the selection marker using Content Model
7063
7231
  * @param editor The editor object
7064
7232
  * @param callback The callback to format the text segment.
7233
+ * @returns True if the segment before cursor is found and callback is called, otherwise false
7065
7234
  */
7066
- export function formatTextSegmentBeforeSelectionMarker(editor: IEditor, callback: (model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext) => boolean): void;
7235
+ export function formatTextSegmentBeforeSelectionMarker(editor: IEditor, callback: (model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext) => boolean, options?: FormatContentModelOptions): boolean;
7236
+
7237
+ /**
7238
+ * Format content model at a given insert point with a callback function
7239
+ * @param editor The editor object
7240
+ * @param insertPoint The insert point to format
7241
+ * @param callback The callback function to format the content model
7242
+ * @param options Options to control the behavior of the formatting
7243
+ */
7244
+ export function formatInsertPointWithContentModel(editor: IEditor, insertPoint: DOMInsertPoint, callback: (model: ContentModelDocument, context: FormatContentModelContext, insertPoint?: InsertPoint) => void, options?: FormatContentModelOptions): void;
7067
7245
 
7068
7246
  /**
7069
7247
  * Set a list type to content model
@@ -7092,7 +7270,7 @@ export function setModelListStartNumber(model: ContentModelDocument, value: numb
7092
7270
  * @param currentItem The current list item
7093
7271
  * Search for all list items in the same thread as the current list item
7094
7272
  */
7095
- export function findListItemsInSameThread(model: ContentModelDocument, currentItem: ContentModelListItem): ContentModelListItem[];
7273
+ export function findListItemsInSameThread(group: ContentModelBlockGroup, currentItem: ContentModelListItem): ContentModelListItem[];
7096
7274
 
7097
7275
  /**
7098
7276
  * @param model The content model to set indentation
@@ -7100,7 +7278,7 @@ export function findListItemsInSameThread(model: ContentModelDocument, currentIt
7100
7278
  * @param length The length of indentation in pixel, default value is 40
7101
7279
  * Set indentation for selected list items or paragraphs
7102
7280
  */
7103
- export function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number): boolean;
7281
+ export function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number, context?: FormatContentModelContext): boolean;
7104
7282
 
7105
7283
  /**
7106
7284
  * Try to match a given string with link match rules, return matched link
@@ -7114,11 +7292,20 @@ export function setModelIndentation(model: ContentModelDocument, indentation: 'i
7114
7292
  */
7115
7293
  export function matchLink(url: string): LinkData | null;
7116
7294
 
7295
+ /**
7296
+ * Get announce data for list item
7297
+ * @param path Content model path that include the list item
7298
+ * @returns Announce data of current list item if any, or null
7299
+ */
7300
+ export function getListAnnounceData(path: ContentModelBlockGroup[]): AnnounceData | null;
7301
+
7117
7302
  /**
7118
7303
  * TableEdit plugin, provides the ability to resize a table by drag-and-drop
7119
7304
  */
7120
7305
  export class TableEditPlugin implements EditorPlugin {
7121
7306
  private anchorContainerSelector?;
7307
+ private onTableEditorCreated?;
7308
+ private disableFeatures?;
7122
7309
  private editor;
7123
7310
  private onMouseMoveDisposer;
7124
7311
  private tableRectMap;
@@ -7128,8 +7315,10 @@ export class TableEditPlugin implements EditorPlugin {
7128
7315
  * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.
7129
7316
  * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
7130
7317
  * If not specified, the plugin will be inserted in document.body
7318
+ * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.
7319
+ * @param disableFeatures An optional array of TableEditFeatures to disable
7131
7320
  */
7132
- constructor(anchorContainerSelector?: string | undefined);
7321
+ constructor(anchorContainerSelector?: string | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined, disableFeatures?: TableEditFeatureName[] | undefined);
7133
7322
  /**
7134
7323
  * Get a friendly name of this plugin
7135
7324
  */
@@ -7161,6 +7350,16 @@ export class TableEditPlugin implements EditorPlugin {
7161
7350
  private ensureTableRects;
7162
7351
  }
7163
7352
 
7353
+ /**
7354
+ * Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.
7355
+ */
7356
+ export type OnTableEditorCreatedCallback = (featureType: TableEditFeatureName, element: HTMLElement) => () => void;
7357
+
7358
+ /**
7359
+ * Names of table edit features
7360
+ */
7361
+ export type TableEditFeatureName = 'HorizontalTableInserter' | 'VerticalTableInserter' | 'TableMover' | 'TableResizer' | 'TableSelector' | 'CellResizer';
7362
+
7164
7363
  /**
7165
7364
  * Paste plugin, handles BeforePaste event and reformat some special content, including:
7166
7365
  * 1. Content copied from Word
@@ -7256,6 +7455,8 @@ export class AutoFormatPlugin implements EditorPlugin {
7256
7455
  * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
7257
7456
  * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
7258
7457
  * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
7458
+ * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
7459
+ * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
7259
7460
  */
7260
7461
  constructor(options?: AutoFormatOptions);
7261
7462
  /**
@@ -7294,23 +7495,31 @@ export type AutoFormatOptions = {
7294
7495
  /**
7295
7496
  * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true
7296
7497
  */
7297
- autoBullet: boolean;
7498
+ autoBullet?: boolean;
7298
7499
  /**
7299
7500
  * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true
7300
7501
  */
7301
- autoNumbering: boolean;
7502
+ autoNumbering?: boolean;
7302
7503
  /**
7303
7504
  * When press backspace before a link, remove the hyperlink
7304
7505
  */
7305
- autoUnlink: boolean;
7506
+ autoUnlink?: boolean;
7306
7507
  /**
7307
7508
  * When paste content, create hyperlink for the pasted link
7308
7509
  */
7309
- autoLink: boolean;
7510
+ autoLink?: boolean;
7310
7511
  /**
7311
7512
  * Transform -- into hyphen, if typed between two words
7312
7513
  */
7313
- autoHyphen: boolean;
7514
+ autoHyphen?: boolean;
7515
+ /**
7516
+ * Transform 1/2, 1/4, 3/4 into fraction character
7517
+ */
7518
+ autoFraction?: boolean;
7519
+ /**
7520
+ * Transform ordinal numbers into superscript
7521
+ */
7522
+ autoOrdinals?: boolean;
7314
7523
  };
7315
7524
 
7316
7525
  /**
@@ -7363,6 +7572,14 @@ export const ShortcutUndo2: ShortcutCommand;
7363
7572
  export const ShortcutRedo: ShortcutCommand;
7364
7573
 
7365
7574
  /**
7575
+ * Shortcut command for Redo 3
7576
+ * Windows: Ctrl + Shift + Z
7577
+ * MacOS: Meta + Shift + Z
7578
+ */
7579
+ export const ShortcutRedoAlt: ShortcutCommand;
7580
+
7581
+ /**
7582
+ * @deprecated
7366
7583
  * Shortcut command for Redo 2
7367
7584
  * Windows: N/A
7368
7585
  * MacOS: Meta + Shift + Z
@@ -7569,7 +7786,7 @@ export interface ContextMenuOptions<T> {
7569
7786
  * A watermark plugin to manage watermark string for roosterjs
7570
7787
  */
7571
7788
  export class WatermarkPlugin implements EditorPlugin {
7572
- private watermark;
7789
+ protected watermark: string;
7573
7790
  private editor;
7574
7791
  private format;
7575
7792
  private isShowing;
@@ -7726,6 +7943,261 @@ export class HyperlinkPlugin implements EditorPlugin {
7726
7943
  */
7727
7944
  export type HyperlinkToolTip = string | null | ((url: string, anchor: HTMLAnchorElement) => string);
7728
7945
 
7946
+ /**
7947
+ * PickerPlugin represents a plugin of editor which can handle picker related behaviors, including
7948
+ * - Show picker when special trigger key is pressed
7949
+ * - Hide picker
7950
+ * - Change selection in picker by Up/Down/Left/Right
7951
+ * - Apply selected item in picker
7952
+ *
7953
+ * PickerPlugin doesn't provide any UI, it just wraps related DOM events and invoke callback functions.
7954
+ */
7955
+ export class PickerPlugin implements EditorPlugin {
7956
+ private triggerCharacter;
7957
+ private readonly handler;
7958
+ private isMac;
7959
+ private lastQueryString;
7960
+ private helper;
7961
+ /**
7962
+ * Construct a new instance of PickerPlugin class
7963
+ * @param triggerCharacter The character to trigger a picker to be shown
7964
+ * @param handler Picker handler for receiving picker state change events
7965
+ */
7966
+ constructor(triggerCharacter: string, handler: PickerHandler);
7967
+ /**
7968
+ * Get a friendly name
7969
+ */
7970
+ getName(): string;
7971
+ /**
7972
+ * Initialize this plugin. This should only be called from Editor
7973
+ * @param editor Editor instance
7974
+ */
7975
+ initialize(editor: IEditor): void;
7976
+ /**
7977
+ * Dispose this plugin
7978
+ */
7979
+ dispose(): void;
7980
+ /**
7981
+ * Check if the plugin should handle the given event exclusively.
7982
+ * Handle an event exclusively means other plugin will not receive this event in
7983
+ * onPluginEvent method.
7984
+ * If two plugins will return true in willHandleEventExclusively() for the same event,
7985
+ * the final result depends on the order of the plugins are added into editor
7986
+ * @param event The event to check
7987
+ */
7988
+ willHandleEventExclusively(event: PluginEvent): boolean;
7989
+ /**
7990
+ * Handle events triggered from editor
7991
+ * @param event PluginEvent object
7992
+ */
7993
+ onPluginEvent(event: PluginEvent): void;
7994
+ private onSuggestingKeyDown;
7995
+ private onSuggestingInput;
7996
+ private onInput;
7997
+ }
7998
+
7999
+ /**
8000
+ * Represents the interface of picker plugin, provides necessary utility functions for pickers
8001
+ */
8002
+ export interface PickerHelper {
8003
+ /**
8004
+ * The editor instance
8005
+ */
8006
+ readonly editor: IEditor;
8007
+ /**
8008
+ * Replace the query string with a given Content Model.
8009
+ * This is used for commit a change from picker and insert the committed content into editor.
8010
+ * @param model The Content Model to insert
8011
+ * @param options Options for formatting content model
8012
+ * @param canUndoByBackspace Whether this change can be undone using Backspace key
8013
+ */
8014
+ replaceQueryString: (model: ContentModelDocument, options?: FormatContentModelOptions, canUndoByBackspace?: boolean) => void;
8015
+ /**
8016
+ * Notify Picker Plugin that picker is closed from the handler code, so picker plugin can quit the suggesting state
8017
+ */
8018
+ closePicker: () => void;
8019
+ }
8020
+
8021
+ /**
8022
+ * Change mode that PickerPlugin will pass to child class
8023
+ */
8024
+ export type PickerSelectionChangMode = /**
8025
+ * When user press Right ("horizontal" mode or "both" mode) (Left in RTL) or Down ("vertical" mode),
8026
+ * select the next option
8027
+ */
8028
+ 'next'
8029
+ /**
8030
+ * When user press Left ("horizontal" mode or "both" mode) (Right in RTL) or Up ("vertical" mode),
8031
+ * select the previous option
8032
+ */
8033
+ | 'previous'
8034
+ /**
8035
+ * When user press Down ("both" mode),
8036
+ * select the next row
8037
+ */
8038
+ | 'nextRow'
8039
+ /**
8040
+ * When user press Up ("both" mode),
8041
+ * select the previous row
8042
+ */
8043
+ | 'previousRow'
8044
+ /**
8045
+ * When user press PageDown,
8046
+ * switch to next page
8047
+ */
8048
+ | 'nextPage'
8049
+ /**
8050
+ * When user press PageUp,
8051
+ * switch to previous page
8052
+ */
8053
+ | 'previousPage'
8054
+ /**
8055
+ * When user press Home,
8056
+ * Select the first item in current row
8057
+ */
8058
+ | 'firstInRow'
8059
+ /**
8060
+ * When user press End,
8061
+ * Select the last item in current row
8062
+ */
8063
+ | 'lastInRow'
8064
+ /**
8065
+ * When user press CTRL (or META on Mac) + Home,
8066
+ * Select the very first item
8067
+ */
8068
+ | 'first'
8069
+ /**
8070
+ * When user press CTRL (or META on Mac) + End,
8071
+ * Select the very last item
8072
+ */
8073
+ | 'last';
8074
+
8075
+ /**
8076
+ * Direction option for picker
8077
+ */
8078
+ export type PickerDirection = /**
8079
+ * Show options horizontally
8080
+ */
8081
+ 'horizontal'
8082
+ /**
8083
+ * Show options vertically
8084
+ */
8085
+ | 'vertical'
8086
+ /**
8087
+ * Show options in both direction (2-D picker)
8088
+ */
8089
+ | 'both';
8090
+
8091
+ /**
8092
+ * Represents the interface a handler for picker plugin. Developer need to implement this interface to create a new type of picker
8093
+ */
8094
+ export interface PickerHandler {
8095
+ /**
8096
+ * Initialize the picker handler, pass in editor and PickerPlugin instance so that the handler can save them
8097
+ * @param editor The editor instance
8098
+ * @param pickerPlugin The PickerPlugin instance
8099
+ */
8100
+ onInitialize: (helper: PickerHelper) => void;
8101
+ /**
8102
+ * Dispose the picker handler
8103
+ */
8104
+ onDispose: () => void;
8105
+ /**
8106
+ * Notify the picker handler that user has typed trigger character so handler should show picker now
8107
+ * @param queryString Current query string
8108
+ * @param insertPoint Insert point where user is typing, can be used for calculating picker position
8109
+ * @returns A picker direction to let picker plugin know what kind of picker is opened. Picker plugin will use this value
8110
+ * to decide how to handle keyboard event to change selection. Return null means picker is not actually opened
8111
+ */
8112
+ onTrigger: (queryString: string, insertPoint: DOMInsertPoint) => PickerDirection | null;
8113
+ /**
8114
+ * Notify the picker handler that picker should be closed now
8115
+ */
8116
+ onClosePicker?(): void;
8117
+ /**
8118
+ * Notify the picker handler that user has changed current typed query string
8119
+ */
8120
+ onQueryStringChanged?(queryString: string): void;
8121
+ /**
8122
+ * Notify the picker handler that user has decide to select the current option in picker
8123
+ */
8124
+ onSelect?(): void;
8125
+ /**
8126
+ * Notify the picker handler that user is using keyboard to change current selection
8127
+ * @param mode The moving mode. Handler code can use this value to decide which item need to be selected
8128
+ */
8129
+ onSelectionChanged?(mode: PickerSelectionChangMode): void;
8130
+ }
8131
+
8132
+ /**
8133
+ * CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
8134
+ */
8135
+ export class CustomReplacePlugin implements EditorPlugin {
8136
+ private customReplacements;
8137
+ private editor;
8138
+ private triggerKeys;
8139
+ /**
8140
+ * @param customReplacements Custom replacement rules.
8141
+ * Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
8142
+ */
8143
+ constructor(customReplacements: CustomReplace[]);
8144
+ /**
8145
+ * Get name of this plugin
8146
+ */
8147
+ getName(): string;
8148
+ /**
8149
+ * The first method that editor will call to a plugin when editor is initializing.
8150
+ * It will pass in the editor instance, plugin should take this chance to save the
8151
+ * editor reference so that it can call to any editor method or format API later.
8152
+ * @param editor The editor object
8153
+ */
8154
+ initialize(editor: IEditor): void;
8155
+ /**
8156
+ * The last method that editor will call to a plugin before it is disposed.
8157
+ * Plugin can take this chance to clear the reference to editor. After this method is
8158
+ * called, plugin should not call to any editor method since it will result in error.
8159
+ */
8160
+ dispose(): void;
8161
+ /**
8162
+ * Core method for a plugin. Once an event happens in editor, editor will call this
8163
+ * method of each plugin to handle the event as long as the event is not handled
8164
+ * exclusively by another plugin.
8165
+ * @param event The event to handle:
8166
+ */
8167
+ onPluginEvent(event: PluginEvent): void;
8168
+ private handleEditorInputEvent;
8169
+ }
8170
+
8171
+ /**
8172
+ * The CustomReplace interface defines a custom replacement that can be used in CustomReplacePlugin.
8173
+ */
8174
+ export interface CustomReplace {
8175
+ /**
8176
+ * The string to replace in the editor.
8177
+ */
8178
+ stringToReplace: string;
8179
+ /**
8180
+ * The string to replace with.
8181
+ */
8182
+ replacementString: string;
8183
+ /**
8184
+ * The handler to replace the string.
8185
+ * @param previousSegment The text segment to replace.
8186
+ * @param stringToReplace The string to replace.
8187
+ * @param replacementString The string to replace with.
8188
+ * @param paragraph The paragraph that contains the text segment.
8189
+ * @returns True if the string is replaced successfully, otherwise false.
8190
+ */
8191
+ replacementHandler: (previousSegment: ContentModelText, stringToReplace: string, replacementString: string, paragraph?: ContentModelParagraph) => boolean;
8192
+ }
8193
+
8194
+ /**
8195
+ * Get bounding rect of the given DOM insert point
8196
+ * @param doc The document object
8197
+ * @param pos The input DOM insert point
8198
+ */
8199
+ export function getDOMInsertPointRect(doc: Document, pos: DOMInsertPoint): Rect | null;
8200
+
7729
8201
  /**
7730
8202
  * Get dark mode color for a given color
7731
8203
  * @param color The color to calculate from