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