roosterjs 8.48.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.
package/dist/rooster.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 8.48.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
 
@@ -415,6 +415,45 @@ function extractClipboardItemsForIE(dataTransfer: DataTransfer, callback: (data:
415
415
  */
416
416
  function createFragmentFromClipboardData(core: EditorCore, clipboardData: ClipboardData, position: NodePosition | null, pasteAsText: boolean, applyCurrentStyle: boolean, pasteAsImage: boolean, event: BeforePasteEvent): DocumentFragment;
417
417
 
418
+ /**
419
+ * Handles the content when using the Image Paste Option
420
+ * @param imageDataUri the image uri to use for the image
421
+ * @param fragment fragment that will contain the content to paste.
422
+ */
423
+ function handleImagePaste(imageDataUri: string, fragment: DocumentFragment): void;
424
+
425
+ /**
426
+ * handle the content when using the text only option
427
+ * @param text Text from clipboard
428
+ * @param position current position of the clipboard
429
+ * @param fragment fragment that contains the paste content.
430
+ */
431
+ function handleTextPaste(text: string, position: NodePosition | null, fragment: DocumentFragment): void;
432
+
433
+ /**
434
+ * Retrieves the metadata from the content inside of the clipboard
435
+ * @param doc Document parsed from the clipboard
436
+ * @param event Before Paste event
437
+ * @param trustedHTMLHandler the trusted html handler to sanitize the content.
438
+ */
439
+ function retrieveMetadataFromClipboard(doc: Document | undefined, event: BeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler): void;
440
+
441
+ /**
442
+ * Sanitize the content from the pasted content
443
+ * @param event The before paste event
444
+ * @param position the position of the cursor
445
+ */
446
+ function sanitizePasteContent(event: BeforePasteEvent, position: NodePosition | null): void;
447
+
448
+ /**
449
+ * Get the paste type that will be used corresponding to the configuration
450
+ * @param pasteAsText Whether to paste as Text
451
+ * @param applyCurrentStyle Whether to apply the current format to the content
452
+ * @param pasteAsImage Whether to only paste the image
453
+ * @returns
454
+ */
455
+ function getPasteType(pasteAsText: boolean, applyCurrentStyle: boolean, pasteAsImage: boolean): PasteType;
456
+
418
457
  /**
419
458
  * Browser object contains browser and operating system information of current environment
420
459
  */
@@ -1509,6 +1548,13 @@ function setHtmlWithSelectionPath(rootNode: HTMLElement, html: string, trustedHT
1509
1548
  */
1510
1549
  function setHtmlWithMetadata(rootNode: HTMLElement, html: string, trustedHTMLHandler?: TrustedHTMLHandler): ContentMetadata | undefined;
1511
1550
 
1551
+ /**
1552
+ * Extract content metadata from DOM tree
1553
+ * @param rootNode Root of the DOM tree
1554
+ * @returns If there is a valid content metadata node in the give DOM tree, return this metadata object, otherwise undefined
1555
+ */
1556
+ function extractContentMetadata(rootNode: HTMLElement): ContentMetadata | undefined;
1557
+
1512
1558
  /**
1513
1559
  * Add the given range into selection of the given document
1514
1560
  * @param range The range to select
@@ -1707,6 +1753,7 @@ function getEntityFromElement(element: HTMLElement): Entity | null;
1707
1753
  function getEntitySelector(type?: string, id?: string): string;
1708
1754
 
1709
1755
  /**
1756
+ * @deprecated
1710
1757
  * Create a placeholder comment node for entity
1711
1758
  * @param entity The entity to create placeholder from
1712
1759
  * @returns A placeholder comment node as
@@ -1733,7 +1780,7 @@ function moveContentWithEntityPlaceholders(root: HTMLDivElement, entities: Recor
1733
1780
  * @param entities A map from entity id to entity wrapper, used for reusing existing DOM structure for entity
1734
1781
  * @param insertClonedNode When pass true, merge with a cloned copy of the nodes from source fragment rather than the nodes themselves @default false
1735
1782
  */
1736
- function restoreContentWithEntityPlaceholder(source: DocumentFragment, target: HTMLElement, entities: Record<string, HTMLElement> | null, insertClonedNode?: boolean): void;
1783
+ function restoreContentWithEntityPlaceholder(source: ParentNode, target: HTMLElement, entities: Record<string, HTMLElement | KnownEntityItem> | null, insertClonedNode?: boolean): void;
1737
1784
 
1738
1785
  /**
1739
1786
  * Gets the cached event data by cache key from event object if there is already one.
@@ -2936,15 +2983,18 @@ interface EntityPluginState {
2936
2983
  pageY: number;
2937
2984
  };
2938
2985
  /**
2986
+ * @deprecated
2939
2987
  * All known entity elements
2940
2988
  */
2941
- knownEntityElements: HTMLElement[];
2989
+ knownEntityElements?: HTMLElement[];
2990
+ /**
2991
+ * @deprecated
2992
+ */
2993
+ shadowEntityCache?: Record<string, HTMLElement>;
2942
2994
  /**
2943
- * Cache for the hydrated content of shadow DOM entity.
2944
- * When set content to replace the whole editor, we will cache the hydrated content
2945
- * before it is gone, then after that we can use the cached content to rehydrate entity
2995
+ * Entities cached for undo snapshot
2946
2996
  */
2947
- shadowEntityCache: Record<string, HTMLElement>;
2997
+ entityMap: Record<string, KnownEntityItem>;
2948
2998
  }
2949
2999
 
2950
3000
  /**
@@ -3669,15 +3719,18 @@ const enum EntityOperation {
3669
3719
  */
3670
3720
  ReplaceTemporaryContent = 8,
3671
3721
  /**
3672
- * Notify plugins that editor has attached shadow root for an entity.
3673
- * Plugins can handle this event to do extra operations to the shadow root
3722
+ * @deprecated
3674
3723
  */
3675
3724
  AddShadowRoot = 9,
3676
3725
  /**
3677
- * Notify plugins that editor has removed the shadow root of an entity
3678
- * Plugins can handle this event to do any necessary clean up for shadow root
3726
+ * @deprecated
3727
+ */
3728
+ RemoveShadowRoot = 10,
3729
+ /**
3730
+ * Notify plugins that a new entity state need to be updated to an entity.
3731
+ * This is normally happened when user undo/redo the content with an entity snapshot added by a plugin that handles entity
3679
3732
  */
3680
- RemoveShadowRoot = 10
3733
+ UpdateEntityState = 11
3681
3734
  }
3682
3735
 
3683
3736
  /**
@@ -4837,15 +4890,18 @@ interface EntityOperationEventData {
4837
4890
  */
4838
4891
  rawEvent?: Event;
4839
4892
  /**
4840
- * A document fragment for entity based on Shadow DOM. This property is only available for NewEntity operation.
4841
- * Putting DOM nodes under this fragment will cause a shadow root to be attached to the entity wrapper
4842
- * with these DOM nodes under it.
4843
- *
4844
- * If there is already cached DOM nodes, they will also be put under this fragment.
4845
- * Plugin need to decide:
4846
- * 1. Apply the cache: do nothing and the DOM nodes will be appended as shadow DOM entity content
4847
- * 2. Discard the cache and use new content instead: clear the fragment and append new DOM nodes, then new DOM nodes will be used
4848
- * 3. Dehydrate this entity: clear the fragment, and leave it empty
4893
+ * For EntityOperation.UpdateEntityState, we use this object to pass the new entity state to plugin.
4894
+ * For other operation types, it is not used.
4895
+ */
4896
+ state?: string;
4897
+ /**
4898
+ * For EntityOperation.NewEntity, plugin can set this property to true then the entity will be persisted.
4899
+ * A persisted entity won't be touched during undo/redo, unless it does not exist after undo/redo.
4900
+ * For other operation types, this value will be ignored.
4901
+ */
4902
+ shouldPersist?: boolean;
4903
+ /**
4904
+ * @deprecated
4849
4905
  */
4850
4906
  contentForShadowEntity?: DocumentFragment;
4851
4907
  }
@@ -5350,6 +5406,12 @@ interface ContentChangedData {
5350
5406
  * Optional property to store the format api name when using ChangeSource.Format
5351
5407
  */
5352
5408
  formatApiName?: string;
5409
+ /**
5410
+ * @optional Get entity states related to the snapshot. If it returns entity states, each state will cause
5411
+ * an EntityOperation event with operation = EntityOperation.UpdateEntityState when undo/redo to this snapshot
5412
+ * @returns Related entity state array
5413
+ */
5414
+ getEntityState?: () => EntityState[];
5353
5415
  }
5354
5416
 
5355
5417
  /**
@@ -6059,6 +6121,31 @@ interface Snapshot {
6059
6121
  * Known colors for dark mode
6060
6122
  */
6061
6123
  knownColors: Readonly<ModeIndependentColor>[];
6124
+ /**
6125
+ * Entity states related to this undo snapshots. When undo/redo to this snapshot, each entity state will trigger
6126
+ * an EntityOperation event with operation = EntityOperation.UpdateEntityState
6127
+ */
6128
+ entityStates?: EntityState[];
6129
+ }
6130
+
6131
+ /**
6132
+ * State for an entity. This is used for storing entity undo snapshot
6133
+ */
6134
+ interface EntityState {
6135
+ /**
6136
+ * Type of the entity
6137
+ */
6138
+ type: string;
6139
+ /**
6140
+ * Id of the entity
6141
+ */
6142
+ id: string;
6143
+ /**
6144
+ * The state of this entity to store into undo snapshot.
6145
+ * The state can be any string, or a serialized JSON object.
6146
+ * We are using string here instead of a JSON object to make sure the whole state is serializable.
6147
+ */
6148
+ state: string;
6062
6149
  }
6063
6150
 
6064
6151
  /**
@@ -8185,6 +8272,24 @@ interface ImageSelectionRange extends SelectionRangeExBase<SelectionRangeTypes.I
8185
8272
  */
8186
8273
  type SelectionRangeEx = NormalSelectionRange | TableSelectionRange | ImageSelectionRange;
8187
8274
 
8275
+ /**
8276
+ * Represents all info of a known entity, including its DOM element, whether it is deleted and if it can be persisted
8277
+ */
8278
+ interface KnownEntityItem {
8279
+ /**
8280
+ * The HTML element of entity wrapper
8281
+ */
8282
+ element: HTMLElement;
8283
+ /**
8284
+ * Whether this entity is deleted.
8285
+ */
8286
+ isDeleted?: boolean;
8287
+ /**
8288
+ * Whether we want to persist this entity element during undo/redo
8289
+ */
8290
+ canPersist?: boolean;
8291
+ }
8292
+
8188
8293
  /**
8189
8294
  * Attribute callback, will be called when HtmlSanitizer process an attribute with given name
8190
8295
  * @param value Value of the attribute
@@ -8780,15 +8885,18 @@ enum CompatibleEntityOperation {
8780
8885
  */
8781
8886
  ReplaceTemporaryContent = 8,
8782
8887
  /**
8783
- * Notify plugins that editor has attached shadow root for an entity.
8784
- * Plugins can handle this event to do extra operations to the shadow root
8888
+ * @deprecated
8785
8889
  */
8786
8890
  AddShadowRoot = 9,
8787
8891
  /**
8788
- * Notify plugins that editor has removed the shadow root of an entity
8789
- * Plugins can handle this event to do any necessary clean up for shadow root
8892
+ * @deprecated
8893
+ */
8894
+ RemoveShadowRoot = 10,
8895
+ /**
8896
+ * Notify plugins that a new entity state need to be updated to an entity.
8897
+ * This is normally happened when user undo/redo the content with an entity snapshot added by a plugin that handles entity
8790
8898
  */
8791
- RemoveShadowRoot = 10
8899
+ UpdateEntityState = 11
8792
8900
  }
8793
8901
 
8794
8902
  /**