roosterjs 9.52.0 → 9.54.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.52.0)
1
+ // Type definitions for roosterjs (Version 9.54.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -1511,7 +1511,11 @@ export type PasteType = /**
1511
1511
  /**
1512
1512
  * If there is a image uri in the clipboard, paste the content as image element
1513
1513
  */
1514
- | 'asImage';
1514
+ | 'asImage'
1515
+ /**
1516
+ * If the editor includes a markdown plugin @see MarkdownPastePlugin, and there is markdown content in the clipboard, paste it as markdown
1517
+ */
1518
+ | 'asMarkdown';
1515
1519
 
1516
1520
  /**
1517
1521
  * All Border operations
@@ -2883,6 +2887,13 @@ export interface DomToModelSettings {
2883
2887
  * If true elements that has display:none style will be processed
2884
2888
  */
2885
2889
  processNonVisibleElements?: boolean;
2890
+ /**
2891
+ * When set to true, if a container element could be represented by a FormatContainer, always keep the
2892
+ * FormatContainer and never fall back to a paragraph, even when it only has a single child.
2893
+ * Set this when the intermediate FormatContainer is persisted during DOM to Content Model conversion
2894
+ * and is later used during formatting.
2895
+ */
2896
+ skipFormatContainerFallbackCheck?: boolean;
2886
2897
  }
2887
2898
 
2888
2899
  /**
@@ -3303,6 +3314,13 @@ export interface DomToModelOptionForCreateModel extends DomToModelOption {
3303
3314
  * When this option is passed, "tryGetFromCache" will be ignored.
3304
3315
  */
3305
3316
  recalculateTableSize?: boolean | 'all' | 'selected' | 'none';
3317
+ /**
3318
+ * When set to true, if a container element could be represented by a FormatContainer, always keep the
3319
+ * FormatContainer and never fall back to a paragraph, even when it only has a single child.
3320
+ * Set this when the intermediate FormatContainer is persisted during DOM to Content Model conversion
3321
+ * and is later used during formatting.
3322
+ */
3323
+ skipFormatContainerFallbackCheck?: boolean;
3306
3324
  }
3307
3325
 
3308
3326
  /**
@@ -3412,6 +3430,14 @@ export interface DomIndexer {
3412
3430
  * @returns True if successfully updated, otherwise false
3413
3431
  */
3414
3432
  reconcileElementId: (element: HTMLElement) => boolean;
3433
+ /**
3434
+ * When src or a data-* attribute is changed on an indexed IMG element, update the related
3435
+ * ContentModelImage (src property or dataset) so the cached model stays valid.
3436
+ * @param element The element that has an attribute changed
3437
+ * @param attributeName The name of the changed attribute
3438
+ * @returns True if successfully updated, otherwise false
3439
+ */
3440
+ reconcileImageAttribute: (element: HTMLElement, attributeName: string) => boolean;
3415
3441
  /**
3416
3442
  * When child list of editor content is changed, we can use this method to do sync the change from editor into content model.
3417
3443
  * This is mostly used when user start to type in an empty line. In that case browser will remove the existing BR node in the empty line if any,
@@ -3827,7 +3853,19 @@ export type ExperimentalFeature = GraduatedExperimentalFeature
3827
3853
  /**
3828
3854
  * Transform the table border colors when switching from light to dark mode
3829
3855
  */
3830
- | 'TransformTableBorderColors';
3856
+ | 'TransformTableBorderColors'
3857
+ /**
3858
+ * When the editor content div is inside a Shadow DOM, enable shadow root detection
3859
+ * in DOMHelper so that selection, focus, and element appending work correctly within
3860
+ * the shadow boundary.
3861
+ */
3862
+ | 'ShadowDom'
3863
+ /**
3864
+ * Strip invisible unicode characters (U+E0000 to U+EFFFF) from text segments during DOM to Model conversion.
3865
+ * These characters can be used to hide text in HTML and may cause unexpected behavior.
3866
+ * @see https://embracethered.com/blog/posts/2024/hiding-and-finding-text-with-unicode-tags/
3867
+ */
3868
+ | 'FilterInvisibleUnicode';
3831
3869
 
3832
3870
  /**
3833
3871
  * Predefined experiment features (Graduated, only keep them for backward compatibility)
@@ -5804,6 +5842,22 @@ export interface DOMHelper {
5804
5842
  * @returns An array of Ranges that match the search criteria
5805
5843
  */
5806
5844
  getRangesByText(text: string, matchCase: boolean, wholeWord: boolean): Range[];
5845
+ /**
5846
+ * Get the current selection range, handling shadow DOM StaticRange conversion.
5847
+ * Returns a live Range in all browsers.
5848
+ */
5849
+ getSelectionRange(): Range | null;
5850
+ /**
5851
+ * Set the selection to the given range, handling browser differences for shadow DOM.
5852
+ * @param range The range to set
5853
+ * @param isReverted Whether the selection is reverted (focus before anchor)
5854
+ */
5855
+ setSelectionRange(range: Range, isReverted?: boolean): void;
5856
+ /**
5857
+ * Append an element to the correct root container (shadow root or document.body)
5858
+ * @param element The element to append
5859
+ */
5860
+ appendToRoot(element: HTMLElement): void;
5807
5861
  }
5808
5862
 
5809
5863
  /**
@@ -6307,7 +6361,7 @@ export interface BeforePasteEvent extends BasePluginEvent<'beforePaste'> {
6307
6361
  */
6308
6362
  readonly htmlAttributes: Record<string, string>;
6309
6363
  /**
6310
- * Paste type option (as plain text, merge format, normal, as image)
6364
+ * Paste type option (as plain text, merge format, normal, as image, asMarkdown (@see MarkdownPastePlugin ))
6311
6365
  */
6312
6366
  readonly pasteType: PasteType;
6313
6367
  /**
@@ -7639,7 +7693,7 @@ export function createDomToModelContext(editorContext?: EditorContext, ...option
7639
7693
  * @param config A full config object to define how to convert DOM tree to Content Model
7640
7694
  * @param editorContext Context of editor
7641
7695
  */
7642
- export function createDomToModelContextWithConfig(config: DomToModelSettings, editorContext?: EditorContext): any;
7696
+ export function createDomToModelContextWithConfig(config: DomToModelSettings, editorContext?: EditorContext): DomToModelContext;
7643
7697
 
7644
7698
  /**
7645
7699
  * Create Dom to Content Model Config object
@@ -10890,6 +10944,23 @@ export function convertMarkdownToContentModel(text: string, options?: MarkdownTo
10890
10944
  */
10891
10945
  export function convertContentModelToMarkdown(model: ContentModelDocument, newLine?: MarkdownLineBreaks): string;
10892
10946
 
10947
+ /**
10948
+ * Detect whether the given plain text contains any markdown markup.
10949
+ * Recognizes block-level patterns (headings, blockquotes, lists, horizontal rules, tables)
10950
+ * and inline patterns (bold, italic, strikethrough, links, images).
10951
+ * @param text The plain text to check.
10952
+ * @returns True if the text contains any markdown markup, false otherwise.
10953
+ */
10954
+ export function isContentMarkdown(text: string): boolean;
10955
+
10956
+ /**
10957
+ * Detect whether the given clipboard content can be interpreted as markdown.
10958
+ * @param editor The editor instance.
10959
+ * @param clipboardData The clipboard data to check.
10960
+ * @returns True if the content can be interpreted as markdown, false otherwise.
10961
+ */
10962
+ export function isPastedContentMarkdown(editor: IEditor, clipboardData: ClipboardData): boolean;
10963
+
10893
10964
  /**
10894
10965
  * The characters to add line breaks and new lines
10895
10966
  */
@@ -10921,3 +10992,55 @@ export interface MarkdownToModelOptions {
10921
10992
  direction?: 'ltr' | 'rtl' | undefined;
10922
10993
  }
10923
10994
 
10995
+ /**
10996
+ * Markdown paste plugin. Handles the BeforePaste event and, when the pasted content
10997
+ * can be interpreted as markdown, converts the plain text into a Content Model and
10998
+ * pastes it as rich markdown content instead of the original clipboard HTML.
10999
+ */
11000
+ export class MarkdownPastePlugin implements EditorPlugin {
11001
+ private editor;
11002
+ private options;
11003
+ /**
11004
+ * Construct a new instance of MarkdownPastePlugin
11005
+ * @param options Options to control the markdown paste behavior
11006
+ */
11007
+ constructor(options?: MarkdownPasteOptions);
11008
+ /**
11009
+ * Get name of this plugin
11010
+ */
11011
+ getName(): string;
11012
+ /**
11013
+ * The first method that editor will call to a plugin when editor is initializing.
11014
+ * It will pass in the editor instance, plugin should take this chance to save the
11015
+ * editor reference so that it can call to any editor method or format API later.
11016
+ * @param editor The editor object
11017
+ */
11018
+ initialize(editor: IEditor): void;
11019
+ /**
11020
+ * The last method that editor will call to a plugin before it is disposed.
11021
+ * Plugin can take this chance to clear the reference to editor. After this method is
11022
+ * called, plugin should not call to any editor method since it will result in error.
11023
+ */
11024
+ dispose(): void;
11025
+ /**
11026
+ * Core method for a plugin. Once an event happens in editor, editor will call this
11027
+ * method of each plugin to handle the event as long as the event is not handled
11028
+ * exclusively by another plugin.
11029
+ * @param event The event to handle:
11030
+ */
11031
+ onPluginEvent(event: PluginEvent): void;
11032
+ }
11033
+
11034
+ /**
11035
+ * Options for MarkdownPastePlugin
11036
+ */
11037
+ export interface MarkdownPasteOptions {
11038
+ /**
11039
+ * When true, content that can be interpreted as markdown is automatically converted
11040
+ * into rich content on every paste, without requiring an explicit "Paste as Markdown"
11041
+ * command.
11042
+ * @default false
11043
+ */
11044
+ autoConversion: boolean;
11045
+ }
11046
+