roosterjs 8.47.0 → 8.49.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 8.47.0)
1
+ // Type definitions for roosterjs (Version 8.49.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -414,6 +414,45 @@ export function extractClipboardItemsForIE(dataTransfer: DataTransfer, callback:
414
414
  */
415
415
  export function createFragmentFromClipboardData(core: EditorCore, clipboardData: ClipboardData, position: NodePosition | null, pasteAsText: boolean, applyCurrentStyle: boolean, pasteAsImage: boolean, event: BeforePasteEvent): DocumentFragment;
416
416
 
417
+ /**
418
+ * Handles the content when using the Image Paste Option
419
+ * @param imageDataUri the image uri to use for the image
420
+ * @param fragment fragment that will contain the content to paste.
421
+ */
422
+ export function handleImagePaste(imageDataUri: string, fragment: DocumentFragment): void;
423
+
424
+ /**
425
+ * handle the content when using the text only option
426
+ * @param text Text from clipboard
427
+ * @param position current position of the clipboard
428
+ * @param fragment fragment that contains the paste content.
429
+ */
430
+ export function handleTextPaste(text: string, position: NodePosition | null, fragment: DocumentFragment): void;
431
+
432
+ /**
433
+ * Retrieves the metadata from the content inside of the clipboard
434
+ * @param doc Document parsed from the clipboard
435
+ * @param event Before Paste event
436
+ * @param trustedHTMLHandler the trusted html handler to sanitize the content.
437
+ */
438
+ export function retrieveMetadataFromClipboard(doc: Document | undefined, event: BeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler): void;
439
+
440
+ /**
441
+ * Sanitize the content from the pasted content
442
+ * @param event The before paste event
443
+ * @param position the position of the cursor
444
+ */
445
+ export function sanitizePasteContent(event: BeforePasteEvent, position: NodePosition | null): void;
446
+
447
+ /**
448
+ * Get the paste type that will be used corresponding to the configuration
449
+ * @param pasteAsText Whether to paste as Text
450
+ * @param applyCurrentStyle Whether to apply the current format to the content
451
+ * @param pasteAsImage Whether to only paste the image
452
+ * @returns
453
+ */
454
+ export function getPasteType(pasteAsText: boolean, applyCurrentStyle: boolean, pasteAsImage: boolean): PasteType;
455
+
417
456
  /**
418
457
  * Browser object contains browser and operating system information of current environment
419
458
  */
@@ -1315,8 +1354,9 @@ export function getRegionsFromRange(root: HTMLElement, range: Range, type: Regio
1315
1354
  * @param regionBase The region to get block elements from
1316
1355
  * @param createBlockIfEmpty When set to true, a new empty block element will be created if there is not
1317
1356
  * any blocks in the region. Default value is false
1357
+ * @param deprecated Deprecated parameter, not used
1318
1358
  */
1319
- export function getSelectedBlockElementsInRegion(regionBase: RegionBase, createBlockIfEmpty?: boolean, shouldApplyFormatToSpan?: boolean): BlockElement[];
1359
+ export function getSelectedBlockElementsInRegion(regionBase: RegionBase, createBlockIfEmpty?: boolean, deprecated?: boolean): BlockElement[];
1320
1360
 
1321
1361
  /**
1322
1362
  * Collapse nodes within this region to their common ancestor node under this region
@@ -1507,6 +1547,13 @@ export function setHtmlWithSelectionPath(rootNode: HTMLElement, html: string, tr
1507
1547
  */
1508
1548
  export function setHtmlWithMetadata(rootNode: HTMLElement, html: string, trustedHTMLHandler?: TrustedHTMLHandler): ContentMetadata | undefined;
1509
1549
 
1550
+ /**
1551
+ * Extract content metadata from DOM tree
1552
+ * @param rootNode Root of the DOM tree
1553
+ * @returns If there is a valid content metadata node in the give DOM tree, return this metadata object, otherwise undefined
1554
+ */
1555
+ export function extractContentMetadata(rootNode: HTMLElement): ContentMetadata | undefined;
1556
+
1510
1557
  /**
1511
1558
  * Add the given range into selection of the given document
1512
1559
  * @param range The range to select
@@ -1705,6 +1752,7 @@ export function getEntityFromElement(element: HTMLElement): Entity | null;
1705
1752
  export function getEntitySelector(type?: string, id?: string): string;
1706
1753
 
1707
1754
  /**
1755
+ * @deprecated
1708
1756
  * Create a placeholder comment node for entity
1709
1757
  * @param entity The entity to create placeholder from
1710
1758
  * @returns A placeholder comment node as
@@ -1731,7 +1779,7 @@ export function moveContentWithEntityPlaceholders(root: HTMLDivElement, entities
1731
1779
  * @param entities A map from entity id to entity wrapper, used for reusing existing DOM structure for entity
1732
1780
  * @param insertClonedNode When pass true, merge with a cloned copy of the nodes from source fragment rather than the nodes themselves @default false
1733
1781
  */
1734
- export function restoreContentWithEntityPlaceholder(source: DocumentFragment, target: HTMLElement, entities: Record<string, HTMLElement> | null, insertClonedNode?: boolean): void;
1782
+ export function restoreContentWithEntityPlaceholder(source: ParentNode, target: HTMLElement, entities: Record<string, HTMLElement | KnownEntityItem> | null, insertClonedNode?: boolean): void;
1735
1783
 
1736
1784
  /**
1737
1785
  * Gets the cached event data by cache key from event object if there is already one.
@@ -2934,15 +2982,18 @@ export interface EntityPluginState {
2934
2982
  pageY: number;
2935
2983
  };
2936
2984
  /**
2985
+ * @deprecated
2937
2986
  * All known entity elements
2938
2987
  */
2939
- knownEntityElements: HTMLElement[];
2988
+ knownEntityElements?: HTMLElement[];
2989
+ /**
2990
+ * @deprecated
2991
+ */
2992
+ shadowEntityCache?: Record<string, HTMLElement>;
2940
2993
  /**
2941
- * Cache for the hydrated content of shadow DOM entity.
2942
- * When set content to replace the whole editor, we will cache the hydrated content
2943
- * before it is gone, then after that we can use the cached content to rehydrate entity
2994
+ * Entities cached for undo snapshot
2944
2995
  */
2945
- shadowEntityCache: Record<string, HTMLElement>;
2996
+ entityMap: Record<string, KnownEntityItem>;
2946
2997
  }
2947
2998
 
2948
2999
  /**
@@ -3667,15 +3718,18 @@ export const enum EntityOperation {
3667
3718
  */
3668
3719
  ReplaceTemporaryContent = 8,
3669
3720
  /**
3670
- * Notify plugins that editor has attached shadow root for an entity.
3671
- * Plugins can handle this event to do extra operations to the shadow root
3721
+ * @deprecated
3672
3722
  */
3673
3723
  AddShadowRoot = 9,
3674
3724
  /**
3675
- * Notify plugins that editor has removed the shadow root of an entity
3676
- * Plugins can handle this event to do any necessary clean up for shadow root
3725
+ * @deprecated
3726
+ */
3727
+ RemoveShadowRoot = 10,
3728
+ /**
3729
+ * Notify plugins that a new entity state need to be updated to an entity.
3730
+ * This is normally happened when user undo/redo the content with an entity snapshot added by a plugin that handles entity
3677
3731
  */
3678
- RemoveShadowRoot = 10
3732
+ UpdateEntityState = 11
3679
3733
  }
3680
3734
 
3681
3735
  /**
@@ -3773,6 +3827,14 @@ export const enum ExperimentalFeatures {
3773
3827
  * Align list elements elements to left, center and right using setAlignment API
3774
3828
  */
3775
3829
  ListItemAlignment = "ListItemAlignment",
3830
+ /**
3831
+ * @deprecated
3832
+ */
3833
+ DefaultFormatInSpan = "DefaultFormatInSpan",
3834
+ /**
3835
+ * @deprecated
3836
+ */
3837
+ DefaultFormatOnContainer = "DefaultFormatOnContainer",
3776
3838
  /**
3777
3839
  * Provide additional Tab Key Features. Requires Text Features Content Editable Features
3778
3840
  */
@@ -3788,11 +3850,6 @@ export const enum ExperimentalFeatures {
3788
3850
  * is the one closest to the item.
3789
3851
  */
3790
3852
  ReuseAllAncestorListElements = "ReuseAllAncestorListElements",
3791
- /**
3792
- * When apply default format when initialize or user type, apply the format on a SPAN element rather than
3793
- * the block element (In most case, the DIV element) so keep the block element clean.
3794
- */
3795
- DefaultFormatInSpan = "DefaultFormatInSpan",
3796
3853
  /**
3797
3854
  * Reuse existing DOM structure if possible when convert Content Model back to DOM tree
3798
3855
  */
@@ -3801,10 +3858,6 @@ export const enum ExperimentalFeatures {
3801
3858
  * Handle keyboard editing event with Content Model
3802
3859
  */
3803
3860
  EditWithContentModel = "EditWithContentModel",
3804
- /**
3805
- * Apply default format on editor container
3806
- */
3807
- DefaultFormatOnContainer = "DefaultFormatOnContainer",
3808
3861
  /**
3809
3862
  * Delete table with Backspace key with the whole was selected with table selector
3810
3863
  */
@@ -4185,7 +4238,7 @@ export const enum KnownCreateElementDataIndex {
4185
4238
  */
4186
4239
  TableSelector = 11,
4187
4240
  /**
4188
- * An empty line without format with span inside of it.
4241
+ * @deprecated
4189
4242
  */
4190
4243
  EmptyLineFormatInSpan = 12
4191
4244
  }
@@ -4836,15 +4889,18 @@ export interface EntityOperationEventData {
4836
4889
  */
4837
4890
  rawEvent?: Event;
4838
4891
  /**
4839
- * A document fragment for entity based on Shadow DOM. This property is only available for NewEntity operation.
4840
- * Putting DOM nodes under this fragment will cause a shadow root to be attached to the entity wrapper
4841
- * with these DOM nodes under it.
4842
- *
4843
- * If there is already cached DOM nodes, they will also be put under this fragment.
4844
- * Plugin need to decide:
4845
- * 1. Apply the cache: do nothing and the DOM nodes will be appended as shadow DOM entity content
4846
- * 2. Discard the cache and use new content instead: clear the fragment and append new DOM nodes, then new DOM nodes will be used
4847
- * 3. Dehydrate this entity: clear the fragment, and leave it empty
4892
+ * For EntityOperation.UpdateEntityState, we use this object to pass the new entity state to plugin.
4893
+ * For other operation types, it is not used.
4894
+ */
4895
+ state?: string;
4896
+ /**
4897
+ * For EntityOperation.NewEntity, plugin can set this property to true then the entity will be persisted.
4898
+ * A persisted entity won't be touched during undo/redo, unless it does not exist after undo/redo.
4899
+ * For other operation types, this value will be ignored.
4900
+ */
4901
+ shouldPersist?: boolean;
4902
+ /**
4903
+ * @deprecated
4848
4904
  */
4849
4905
  contentForShadowEntity?: DocumentFragment;
4850
4906
  }
@@ -5349,6 +5405,12 @@ export interface ContentChangedData {
5349
5405
  * Optional property to store the format api name when using ChangeSource.Format
5350
5406
  */
5351
5407
  formatApiName?: string;
5408
+ /**
5409
+ * @optional Get entity states related to the snapshot. If it returns entity states, each state will cause
5410
+ * an EntityOperation event with operation = EntityOperation.UpdateEntityState when undo/redo to this snapshot
5411
+ * @returns Related entity state array
5412
+ */
5413
+ getEntityState?: () => EntityState[];
5352
5414
  }
5353
5415
 
5354
5416
  /**
@@ -6058,6 +6120,31 @@ export interface Snapshot {
6058
6120
  * Known colors for dark mode
6059
6121
  */
6060
6122
  knownColors: Readonly<ModeIndependentColor>[];
6123
+ /**
6124
+ * Entity states related to this undo snapshots. When undo/redo to this snapshot, each entity state will trigger
6125
+ * an EntityOperation event with operation = EntityOperation.UpdateEntityState
6126
+ */
6127
+ entityStates?: EntityState[];
6128
+ }
6129
+
6130
+ /**
6131
+ * State for an entity. This is used for storing entity undo snapshot
6132
+ */
6133
+ export interface EntityState {
6134
+ /**
6135
+ * Type of the entity
6136
+ */
6137
+ type: string;
6138
+ /**
6139
+ * Id of the entity
6140
+ */
6141
+ id: string;
6142
+ /**
6143
+ * The state of this entity to store into undo snapshot.
6144
+ * The state can be any string, or a serialized JSON object.
6145
+ * We are using string here instead of a JSON object to make sure the whole state is serializable.
6146
+ */
6147
+ state: string;
6061
6148
  }
6062
6149
 
6063
6150
  /**
@@ -6701,7 +6788,7 @@ export interface IEditor {
6701
6788
  * If it is not cached before, query from DOM and cache the result into the event object
6702
6789
  * @returns A content traverser, or null if editor never got focus before
6703
6790
  */
6704
- getContentSearcherOfCursor(event?: PluginEvent): IPositionContentSearcher | null;
6791
+ getContentSearcherOfCursor(event?: PluginEvent | null): IPositionContentSearcher | null;
6705
6792
  /**
6706
6793
  * Run a callback function asynchronously
6707
6794
  * @param callback The callback function to run
@@ -7164,8 +7251,7 @@ export interface CoreApiMap {
7164
7251
  * @param core The EditorCore object.
7165
7252
  * @param position The position that user is about to type to
7166
7253
  * @param keyboardEvent Optional keyboard event object
7167
- * @param applyFormatToSpan Optional When set to true, default format (if any) will be applied to
7168
- * a SPAN element inside the block element instead of the block element itself.
7254
+ * @param deprecated Deprecated parameter, not used
7169
7255
  */
7170
7256
  ensureTypeInContainer: EnsureTypeInContainer;
7171
7257
  /**
@@ -7313,10 +7399,9 @@ export type CreatePasteFragment = (core: EditorCore, clipboardData: ClipboardDat
7313
7399
  * @param core The EditorCore object.
7314
7400
  * @param position The position that user is about to type to
7315
7401
  * @param keyboardEvent Optional keyboard event object
7316
- * @param applyFormatToSpan Optional When set to true, default format (if any) will be applied to
7317
- * a SPAN element inside the block element instead of the block element itself.
7402
+ * @param deprecated Deprecated parameter, not used
7318
7403
  */
7319
- export type EnsureTypeInContainer = (core: EditorCore, position: NodePosition, keyboardEvent?: KeyboardEvent, applyFormatToSpan?: boolean) => void;
7404
+ export type EnsureTypeInContainer = (core: EditorCore, position: NodePosition, keyboardEvent?: KeyboardEvent, deprecated?: boolean) => void;
7320
7405
 
7321
7406
  /**
7322
7407
  * Focus to editor. If there is a cached selection range, use it as current selection
@@ -8186,6 +8271,24 @@ export interface ImageSelectionRange extends SelectionRangeExBase<SelectionRange
8186
8271
  */
8187
8272
  export type SelectionRangeEx = NormalSelectionRange | TableSelectionRange | ImageSelectionRange;
8188
8273
 
8274
+ /**
8275
+ * Represents all info of a known entity, including its DOM element, whether it is deleted and if it can be persisted
8276
+ */
8277
+ export interface KnownEntityItem {
8278
+ /**
8279
+ * The HTML element of entity wrapper
8280
+ */
8281
+ element: HTMLElement;
8282
+ /**
8283
+ * Whether this entity is deleted.
8284
+ */
8285
+ isDeleted?: boolean;
8286
+ /**
8287
+ * Whether we want to persist this entity element during undo/redo
8288
+ */
8289
+ canPersist?: boolean;
8290
+ }
8291
+
8189
8292
  /**
8190
8293
  * Attribute callback, will be called when HtmlSanitizer process an attribute with given name
8191
8294
  * @param value Value of the attribute
@@ -8493,6 +8596,14 @@ export enum CompatibleExperimentalFeatures {
8493
8596
  * Align list elements elements to left, center and right using setAlignment API
8494
8597
  */
8495
8598
  ListItemAlignment = "ListItemAlignment",
8599
+ /**
8600
+ * @deprecated
8601
+ */
8602
+ DefaultFormatInSpan = "DefaultFormatInSpan",
8603
+ /**
8604
+ * @deprecated
8605
+ */
8606
+ DefaultFormatOnContainer = "DefaultFormatOnContainer",
8496
8607
  /**
8497
8608
  * Provide additional Tab Key Features. Requires Text Features Content Editable Features
8498
8609
  */
@@ -8508,11 +8619,6 @@ export enum CompatibleExperimentalFeatures {
8508
8619
  * is the one closest to the item.
8509
8620
  */
8510
8621
  ReuseAllAncestorListElements = "ReuseAllAncestorListElements",
8511
- /**
8512
- * When apply default format when initialize or user type, apply the format on a SPAN element rather than
8513
- * the block element (In most case, the DIV element) so keep the block element clean.
8514
- */
8515
- DefaultFormatInSpan = "DefaultFormatInSpan",
8516
8622
  /**
8517
8623
  * Reuse existing DOM structure if possible when convert Content Model back to DOM tree
8518
8624
  */
@@ -8521,10 +8627,6 @@ export enum CompatibleExperimentalFeatures {
8521
8627
  * Handle keyboard editing event with Content Model
8522
8628
  */
8523
8629
  EditWithContentModel = "EditWithContentModel",
8524
- /**
8525
- * Apply default format on editor container
8526
- */
8527
- DefaultFormatOnContainer = "DefaultFormatOnContainer",
8528
8630
  /**
8529
8631
  * Delete table with Backspace key with the whole was selected with table selector
8530
8632
  */
@@ -8782,15 +8884,18 @@ export enum CompatibleEntityOperation {
8782
8884
  */
8783
8885
  ReplaceTemporaryContent = 8,
8784
8886
  /**
8785
- * Notify plugins that editor has attached shadow root for an entity.
8786
- * Plugins can handle this event to do extra operations to the shadow root
8887
+ * @deprecated
8787
8888
  */
8788
8889
  AddShadowRoot = 9,
8789
8890
  /**
8790
- * Notify plugins that editor has removed the shadow root of an entity
8791
- * Plugins can handle this event to do any necessary clean up for shadow root
8891
+ * @deprecated
8792
8892
  */
8793
- RemoveShadowRoot = 10
8893
+ RemoveShadowRoot = 10,
8894
+ /**
8895
+ * Notify plugins that a new entity state need to be updated to an entity.
8896
+ * This is normally happened when user undo/redo the content with an entity snapshot added by a plugin that handles entity
8897
+ */
8898
+ UpdateEntityState = 11
8794
8899
  }
8795
8900
 
8796
8901
  /**
@@ -9654,7 +9759,7 @@ export enum CompatibleKnownCreateElementDataIndex {
9654
9759
  */
9655
9760
  TableSelector = 11,
9656
9761
  /**
9657
- * An empty line without format with span inside of it.
9762
+ * @deprecated
9658
9763
  */
9659
9764
  EmptyLineFormatInSpan = 12
9660
9765
  }