roosterjs 9.40.0 → 9.41.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.
package/dist/rooster.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 9.40.0)
1
+ // Type definitions for roosterjs (Version 9.41.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -2354,6 +2354,10 @@ interface TableSelection extends TableSelectionCoordinates, SelectionBase<'table
2354
2354
  * The table that this selection is representing
2355
2355
  */
2356
2356
  table: HTMLTableElement;
2357
+ /**
2358
+ * Table selection info
2359
+ */
2360
+ tableSelectionInfo?: TableSelectionInfo;
2357
2361
  }
2358
2362
 
2359
2363
  /**
@@ -5430,7 +5434,54 @@ type KnownAnnounceStrings = /**
5430
5434
  /**
5431
5435
  * String announced when cursor is moved to the last cell in a table
5432
5436
  */
5433
- | 'announceOnFocusLastCell';
5437
+ | 'announceOnFocusLastCell'
5438
+ /**
5439
+ * String announced when bold formatting is applied
5440
+ */
5441
+ | 'announceBoldOn'
5442
+ /**
5443
+ * String announced when bold formatting is removed
5444
+ */
5445
+ | 'announceBoldOff'
5446
+ /**
5447
+ * String announced when italic formatting is applied
5448
+ */
5449
+ | 'announceItalicOn'
5450
+ /**
5451
+ * String announced when italic formatting is removed
5452
+ */
5453
+ | 'announceItalicOff'
5454
+ /**
5455
+ * String announced when underline formatting is applied
5456
+ */
5457
+ | 'announceUnderlineOn'
5458
+ /**
5459
+ * String announced when underline formatting is removed
5460
+ */
5461
+ | 'announceUnderlineOff'
5462
+ /**
5463
+ * String announced when text is selected in the editor
5464
+ * @example
5465
+ * {0}, selected
5466
+ * Where {0} is the selected text content
5467
+ */
5468
+ | 'selected'
5469
+ /**
5470
+ * String announced when text is unselected in the editor.
5471
+ * @example
5472
+ * {0}, unselected
5473
+ */
5474
+ | 'unselected';
5475
+
5476
+ /**
5477
+ * Options for announcing format changes
5478
+ */
5479
+ interface AnnouncingOption {
5480
+ /**
5481
+ * Whether to announce the format change
5482
+ */
5483
+ announceFormatChange?: boolean;
5484
+ }
5434
5485
 
5435
5486
  /**
5436
5487
  * A handler type to convert HTML string to a trust HTML string or a DOM object
@@ -5555,6 +5606,12 @@ interface DOMHelper {
5555
5606
  * returns the given node
5556
5607
  */
5557
5608
  findClosestElementAncestor(node: Node, selector?: string): HTMLElement | null;
5609
+ /**
5610
+ * Find the closest block element ancestor from the given node within current editing scope
5611
+ * @param startFrom The node to start the search from
5612
+ * @returns The closest block element ancestor
5613
+ */
5614
+ findClosestBlockElement(startFrom: Node): HTMLElement;
5558
5615
  /**
5559
5616
  * Check if the editor has focus now
5560
5617
  * @returns True if the editor has focus, otherwise false
@@ -5578,6 +5635,15 @@ interface DOMHelper {
5578
5635
  * @param darkColorHandler Optional DarkColorHandler to retrieve dark mode colors
5579
5636
  */
5580
5637
  getContainerFormat(isInDarkMode?: boolean, darkColorHandler?: DarkColorHandler): ContentModelSegmentFormat;
5638
+ /**
5639
+ * Get text ranges by searching for a specific text, with options to match case and whole word.
5640
+ * This will only search within editable elements.
5641
+ * @param text The text to search for
5642
+ * @param matchCase Whether to match case
5643
+ * @param wholeWord Whether to match whole word
5644
+ * @returns An array of Ranges that match the search criteria
5645
+ */
5646
+ getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[];
5581
5647
  }
5582
5648
 
5583
5649
  /**
@@ -5947,6 +6013,20 @@ interface ParagraphIndexer {
5947
6013
  getParagraphFromMarker(paragraphWithMarker: ReadonlyContentModelParagraph): ReadonlyContentModelParagraph | null;
5948
6014
  }
5949
6015
 
6016
+ /**
6017
+ * The html and text content generated by the copy/cut action
6018
+ */
6019
+ interface TextAndHtmlContentForCopy {
6020
+ /**
6021
+ * The HTML Content modified by the beforeCutCopy event
6022
+ */
6023
+ htmlContent: HTMLDivElement;
6024
+ /**
6025
+ * The content model modified by the beforeCutCopy event in plain text
6026
+ */
6027
+ textContent: string;
6028
+ }
6029
+
5950
6030
  /**
5951
6031
  * Editor plugin event interface
5952
6032
  */
@@ -6365,7 +6445,7 @@ interface DoubleClickEvent extends BasePluginDomEvent<'doubleClick', MouseEvent>
6365
6445
  /**
6366
6446
  * Editor plugin event interface
6367
6447
  */
6368
- type PluginEvent = BeforeAddUndoSnapshotEvent | BeforeCutCopyEvent | BeforeDisposeEvent | BeforeKeyboardEditingEvent | BeforeLogicalRootChangeEvent | BeforePasteEvent | BeforeSetContentEvent | CompositionEndEvent | ContentChangedEvent | ContextMenuEvent | RewriteFromModelEvent | EditImageEvent | EditorReadyEvent | EnterShadowEditEvent | EntityOperationEvent | ExtractContentWithDomEvent | EditorInputEvent | KeyDownEvent | KeyPressEvent | KeyUpEvent | LeaveShadowEditEvent | LogicalRootChangedEvent | MouseDownEvent | MouseUpEvent | ScrollEvent | SelectionChangedEvent | ZoomChangedEvent | PointerDownEvent | PointerUpEvent | DoubleClickEvent;
6448
+ type PluginEvent = BeforeAddUndoSnapshotEvent | BeforeCutCopyEvent | BeforeDisposeEvent | BeforeKeyboardEditingEvent | BeforeLogicalRootChangeEvent | BeforePasteEvent | BeforeSetContentEvent | CompositionEndEvent | ContentChangedEvent | ContextMenuEvent | RewriteFromModelEvent | EditImageEvent | EditorReadyEvent | EnterShadowEditEvent | EntityOperationEvent | ExtractContentWithDomEvent | EditorInputEvent | KeyDownEvent | KeyPressEvent | KeyUpEvent | LeaveShadowEditEvent | LogicalRootChangedEvent | MouseDownEvent | MouseUpEvent | ScrollEvent | SelectionChangedEvent | ZoomChangedEvent | PointerDownEvent | PointerUpEvent | DoubleClickEvent | FindResultChangedEvent;
6369
6449
 
6370
6450
  /**
6371
6451
  * A type to extract data part of a plugin event type. Data part is the plugin event without eventType field.
@@ -6522,7 +6602,11 @@ type PluginEventType = /**
6522
6602
  /**
6523
6603
  * HTML double click event
6524
6604
  */
6525
- | 'doubleClick';
6605
+ | 'doubleClick'
6606
+ /**
6607
+ * Find result changed event
6608
+ */
6609
+ | 'findResultChanged';
6526
6610
 
6527
6611
  /**
6528
6612
  * This interface represents a PluginEvent wrapping native scroll event
@@ -6582,6 +6666,24 @@ interface PointerUpEvent extends BasePluginDomEvent<'pointerUp', PointerEvent> {
6582
6666
  originalEvent: MouseEvent | TouchEvent;
6583
6667
  }
6584
6668
 
6669
+ /**
6670
+ * Represents an event that occurs when the find result changes in the editor
6671
+ */
6672
+ interface FindResultChangedEvent extends BasePluginEvent<'findResultChanged'> {
6673
+ /**
6674
+ * The index of the currently marked find result
6675
+ */
6676
+ readonly markedIndex: number;
6677
+ /**
6678
+ * The array of ranges representing the current find results
6679
+ */
6680
+ readonly ranges: ReadonlyArray<Range>;
6681
+ /**
6682
+ * An alternative range to select when there is no marked result
6683
+ */
6684
+ readonly alternativeRange?: Range | null;
6685
+ }
6686
+
6585
6687
  /**
6586
6688
  * Create Content Model from DOM tree in this editor
6587
6689
  * @param root Root element of DOM tree to create Content Model from
@@ -6912,6 +7014,17 @@ function isWhiteSpacePreserved(whiteSpace: string | undefined): boolean;
6912
7014
  */
6913
7015
  function normalizeRect(clientRect: DOMRect): Rect | null;
6914
7016
 
7017
+ /**
7018
+ * Scroll a given rectangle into view within a scroll container
7019
+ * @param scrollContainer The container to scroll
7020
+ * @param visibleRect The currently visible rectangle within the scroll container
7021
+ * @param domHelper The DOM helper of the editor
7022
+ * @param targetRect The target rectangle to scroll into view
7023
+ * @param scrollMargin Optional margin to apply when scrolling
7024
+ * @param preferTop Optional flag to indicate whether to prefer aligning the top or bottom of the target rect when the target rect is higher than visible rect @default false
7025
+ */
7026
+ function scrollRectIntoView(scrollContainer: HTMLElement, visibleRect: Rect, domHelper: DOMHelper, targetRect: Rect, scrollMargin?: number, preferTop?: boolean): void;
7027
+
6915
7028
  /**
6916
7029
  * Set a hidden property on a link element to indicate whether it is undeletable or not.
6917
7030
  * This is used to prevent the link from being deleted when the user tries to delete it.
@@ -7490,6 +7603,17 @@ function setImageState(element: HTMLElement, marker: string): void;
7490
7603
  */
7491
7604
  function getImageState(element: HTMLElement): string | undefined;
7492
7605
 
7606
+ /**
7607
+ * Search text from the given root element and return all ranges that match the search criteria
7608
+ * @param root Root element to search from
7609
+ * @param text Text to search for
7610
+ * @param matchCase Whether to match case
7611
+ * @param wholeWord Whether to match whole words only
7612
+ * @param editableOnly Whether to search only in editable elements
7613
+ * @returns Array of matching ranges
7614
+ */
7615
+ function getRangesByText(root: HTMLElement, text: string, matchCase: boolean, wholeWord: boolean, editableOnly?: boolean): Range[];
7616
+
7493
7617
  /**
7494
7618
  * Check if the given content model block or block group is of the expected block group type
7495
7619
  * @param input The object to check
@@ -7929,6 +8053,10 @@ const ChangeSource: {
7929
8053
  * Content changed by auto format
7930
8054
  */
7931
8055
  AutoFormat: string;
8056
+ /**
8057
+ * Content changed by replace
8058
+ */
8059
+ Replace: string;
7932
8060
  };
7933
8061
 
7934
8062
  /**
@@ -8433,6 +8561,15 @@ function redo(editor: IEditor): void;
8433
8561
  */
8434
8562
  function paste(editor: IEditor, clipboardData: ClipboardData, pasteTypeOrGetter?: PasteTypeOrGetter): void;
8435
8563
 
8564
+ /**
8565
+ * Get the content for the copy event
8566
+ * @param editor The editor object
8567
+ * @param isCut if the event cut the content.
8568
+ * @param event the clipboard event that triggered the copy/cut
8569
+ * @returns
8570
+ */
8571
+ function getContentForCopy(editor: IEditor, isCut: boolean, event: ClipboardEvent): TextAndHtmlContentForCopy | null;
8572
+
8436
8573
  /**
8437
8574
  * Insert table into editor at current selection
8438
8575
  * @param editor The editor instance
@@ -8496,19 +8633,19 @@ function toggleNumbering(editor: IEditor, removeMargins?: boolean): void;
8496
8633
  * Toggle bold style
8497
8634
  * @param editor The editor to operate on
8498
8635
  */
8499
- function toggleBold(editor: IEditor): void;
8636
+ function toggleBold(editor: IEditor, options?: AnnouncingOption): void;
8500
8637
 
8501
8638
  /**
8502
8639
  * Toggle italic style
8503
8640
  * @param editor The editor to operate on
8504
8641
  */
8505
- function toggleItalic(editor: IEditor): void;
8642
+ function toggleItalic(editor: IEditor, options?: AnnouncingOption): void;
8506
8643
 
8507
8644
  /**
8508
8645
  * Toggle underline style
8509
8646
  * @param editor The editor to operate on
8510
8647
  */
8511
- function toggleUnderline(editor: IEditor): void;
8648
+ function toggleUnderline(editor: IEditor, options?: AnnouncingOption): void;
8512
8649
 
8513
8650
  /**
8514
8651
  * Toggle strikethrough style
@@ -8841,7 +8978,7 @@ function formatParagraphWithContentModel(editor: IEditor, apiName: string, setSt
8841
8978
  * @param includingFormatHolder True to also include format holder of list item when search selected segments
8842
8979
  * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree
8843
8980
  */
8844
- function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument) => void): void;
8981
+ function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument, isTurningOff: boolean, context: FormatContentModelContext) => void): void;
8845
8982
 
8846
8983
  /**
8847
8984
  * Invoke a callback to format the text segment before the selection marker using Content Model
@@ -10178,6 +10315,189 @@ class TouchPlugin implements EditorPlugin {
10178
10315
  onPluginEvent(event: PluginEvent): void;
10179
10316
  }
10180
10317
 
10318
+ /**
10319
+ * Plugin for finding and replacing text in the editor, maintain the highlights for found and replaced text
10320
+ */
10321
+ class FindReplacePlugin implements EditorPlugin {
10322
+ private context;
10323
+ private editor;
10324
+ private findHighlightStyle;
10325
+ private replaceHighlightStyle;
10326
+ /**
10327
+ * Creates a FindReplacePlugin instance
10328
+ * @param context FindReplaceContext to use. It will be disposed when plugin is being disposed.
10329
+ * @param options Options for highlighting styles
10330
+ */
10331
+ constructor(context: FindReplaceContext, options?: FindReplaceHighlightOptions);
10332
+ /**
10333
+ * Get name of this plugin
10334
+ */
10335
+ getName(): string;
10336
+ /**
10337
+ * The first method that editor will call to a plugin when editor is initializing.
10338
+ * It will pass in the editor instance, plugin should take this chance to save the
10339
+ * editor reference so that it can call to any editor method or format API later.
10340
+ * @param editor The editor object
10341
+ */
10342
+ initialize(editor: IEditor): void;
10343
+ /**
10344
+ * The last method that editor will call to a plugin before it is disposed.
10345
+ * Plugin can take this chance to clear the reference to editor. After this method is
10346
+ * called, plugin should not call to any editor method since it will result in error.
10347
+ */
10348
+ dispose(): void;
10349
+ /**
10350
+ * Core method for a plugin. Once an event happens in editor, editor will call this
10351
+ * method of each plugin to handle the event as long as the event is not handled
10352
+ * exclusively by another plugin.
10353
+ * @param event The event to handle:
10354
+ */
10355
+ onPluginEvent(event: PluginEvent): void;
10356
+ }
10357
+
10358
+ /**
10359
+ * Creates a FindReplaceContext object with default values
10360
+ * @param win The window object
10361
+ * @param scrollMargin Margin size (in pixels) when scrolling to a highlighted item
10362
+ * @returns
10363
+ */
10364
+ function createFindReplaceContext(scrollMargin?: number): FindReplaceContext;
10365
+
10366
+ /**
10367
+ * Start a find operation in the editor
10368
+ * @param editor The editor instance
10369
+ * @param context The FindReplaceContext to use
10370
+ * @param text The text to find
10371
+ * @param matchCase Whether to match case
10372
+ * @param wholeWord Whether to match whole words only
10373
+ */
10374
+ function find(editor: IEditor, context: FindReplaceContext, text: string | null, matchCase?: boolean, wholeWord?: boolean): void;
10375
+
10376
+ /**
10377
+ * Replace the currently found item or all found items in the editor
10378
+ * @param editor The editor instance
10379
+ * @param context The FindReplaceContext to use
10380
+ * @param replaceText The text to replace with
10381
+ * @param replaceAll Whether to replace all found items
10382
+ */
10383
+ function replace(editor: IEditor, context: FindReplaceContext, replaceText: string, replaceAll?: boolean): void;
10384
+
10385
+ /**
10386
+ * Move the highlight to next or previous match
10387
+ * @param editor The editor instance
10388
+ * @param context The FindReplaceContext to use
10389
+ * @param forward Whether to move forward or backward
10390
+ */
10391
+ function moveHighlight(editor: IEditor, context: FindReplaceContext, forward: boolean): void;
10392
+
10393
+ /**
10394
+ * Represents a context object used by all find/replace operations
10395
+ */
10396
+ interface FindReplaceContext {
10397
+ /**
10398
+ * Text to find (null means no find)
10399
+ */
10400
+ text: string | null;
10401
+ /**
10402
+ * Whether to match case when finding text
10403
+ */
10404
+ matchCase: boolean;
10405
+ /**
10406
+ * Whether to match whole word when finding text
10407
+ */
10408
+ wholeWord: boolean;
10409
+ /**
10410
+ * Ranges of found results
10411
+ */
10412
+ ranges: Range[];
10413
+ /**
10414
+ * Current marked index in the ranges array
10415
+ */
10416
+ markedIndex: number;
10417
+ /**
10418
+ * Margin size (in pixels) when scrolling to a highlighted item
10419
+ */
10420
+ readonly scrollMargin: number;
10421
+ /**
10422
+ * Highlight helper used to highlight found results
10423
+ */
10424
+ readonly findHighlight: HighlightHelper;
10425
+ /**
10426
+ * Highlight helper used to highlight the current marked result
10427
+ */
10428
+ readonly replaceHighlight: HighlightHelper;
10429
+ }
10430
+
10431
+ /**
10432
+ * Represents a helper that manages highlights in the editor
10433
+ */
10434
+ interface HighlightHelper {
10435
+ /**
10436
+ * Initialize the highlight helper
10437
+ * @param win The window object
10438
+ */
10439
+ initialize(win: Window): void;
10440
+ /**
10441
+ * Dispose the highlight helper and clear all highlights
10442
+ */
10443
+ dispose(): void;
10444
+ /**
10445
+ * Add ranges to be highlighted
10446
+ * @param ranges The ranges to be highlighted
10447
+ */
10448
+ addRanges(ranges: Range[]): void;
10449
+ /**
10450
+ * Clear all highlights
10451
+ */
10452
+ clear(): void;
10453
+ }
10454
+
10455
+ /**
10456
+ * Options for creating FindReplaceContext
10457
+ */
10458
+ interface FindReplaceHighlightOptions {
10459
+ /**
10460
+ * Style for highlighting found items
10461
+ */
10462
+ findHighlightStyle?: string;
10463
+ /**
10464
+ * Style for highlighting replacing items
10465
+ */
10466
+ replaceHighlightStyle?: string;
10467
+ }
10468
+
10469
+ /**
10470
+ * AnnouncePlugin helps editor announce table selection changes for accessibility
10471
+ */
10472
+ class AnnouncePlugin implements EditorPlugin {
10473
+ private editor;
10474
+ private previousSelection;
10475
+ /**
10476
+ * Get name of this plugin
10477
+ */
10478
+ getName(): string;
10479
+ /**
10480
+ * The first method that editor will call to a plugin when editor is initializing.
10481
+ * It will pass in the editor instance, plugin should take this chance to save the
10482
+ * editor reference so that it can call to any editor method or format API later.
10483
+ * @param editor The editor object
10484
+ */
10485
+ initialize(editor: IEditor): void;
10486
+ /**
10487
+ * The last method that editor will call to a plugin before it is disposed.
10488
+ * Plugin can take this chance to clear the reference to editor. After this method is
10489
+ * called, plugin should not call to any editor method since it will result in error.
10490
+ */
10491
+ dispose(): void;
10492
+ /**
10493
+ * Core method for a plugin. Once an event happens in editor, editor will call this
10494
+ * method of each plugin to handle the event as long as the event is not handled
10495
+ * exclusively by another plugin.
10496
+ * @param event The event to handle:
10497
+ */
10498
+ onPluginEvent(event: PluginEvent): void;
10499
+ }
10500
+
10181
10501
  /**
10182
10502
  * Get dark mode color for a given color
10183
10503
  * @param color The color to calculate from