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