roosterjs 8.31.0 → 8.32.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.31.0)
1
+ // Type definitions for roosterjs (Version 8.32.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -716,6 +716,33 @@ const KnownCreateElementData: Record<KnownCreateElementDataIndex, CreateElementD
716
716
  */
717
717
  function moveChildNodes(target: Node, source?: Node, keepExistingChildren?: boolean): void;
718
718
 
719
+ /**
720
+ * Get the intersected Rect of elements provided
721
+ *
722
+ * @example
723
+ * The result of the following Elements Rects would be:
724
+ {
725
+ top: Element2.top,
726
+ bottom: Element1.bottom,
727
+ left: Element2.left,
728
+ right: Element2.right
729
+ }
730
+ +-------------------------+
731
+ | Element 1 |
732
+ | +-----------------+ |
733
+ | | Element2 | |
734
+ | | | |
735
+ | | | |
736
+ +-------------------------+
737
+ | |
738
+ +-----------------+
739
+
740
+ * @param elements Elements to use.
741
+ * @param additionalRects additional rects to use
742
+ * @returns If the Rect is valid return the rect, if not, return null.
743
+ */
744
+ function getIntersectedRect(elements: HTMLElement[], additionalRects?: Rect[]): Rect | null;
745
+
719
746
  /**
720
747
  * A virtual table class, represent an HTML table, by expand all merged cells to each separated cells
721
748
  */
@@ -912,8 +939,10 @@ class VList {
912
939
  /**
913
940
  * Write the result back into DOM tree
914
941
  * After that, this VList becomes unavailable because we set this.rootList to null
942
+ *
943
+ * @param shouldReuseAllAncestorListElements Optional - defaults to false.
915
944
  */
916
- writeBack(): void;
945
+ writeBack(shouldReuseAllAncestorListElements?: boolean): void;
917
946
  /**
918
947
  * Sets the New List Start Property, that is going to be used to create a new List in the WriteBack function
919
948
  * @param separator The HTML element that indicates when to split the VList
@@ -1109,8 +1138,10 @@ class VListItem {
1109
1138
  * Write the change result back into DOM
1110
1139
  * @param listStack current stack of list elements
1111
1140
  * @param originalRoot Original list root element. It will be reused when write back if possible
1141
+ * @param shouldReuseAllAncestorListElements Optional - defaults to false. If true, only make
1142
+ * sure the direct parent of this list matches the list types when writing back.
1112
1143
  */
1113
- writeBack(listStack: Node[], originalRoot?: HTMLOListElement | HTMLUListElement): void;
1144
+ writeBack(listStack: Node[], originalRoot?: HTMLOListElement | HTMLUListElement, shouldReuseAllAncestorListElements?: boolean): void;
1114
1145
  /**
1115
1146
  * Get the index of how deep is the current node parent list inside of the original root list.
1116
1147
  * @example In the following structure this function would return 2
@@ -1172,7 +1203,7 @@ class VListChain {
1172
1203
  * After change the lists, commit the change to all lists in this chain to update the list number,
1173
1204
  * and clear the temporary dataset values added to list node
1174
1205
  */
1175
- commit(): void;
1206
+ commit(shouldReuseAllAncestorListElements?: boolean): void;
1176
1207
  /**
1177
1208
  * Construct a new instance of VListChain class
1178
1209
  * @param editor Editor object
@@ -1208,6 +1239,13 @@ function setListItemStyle(element: HTMLLIElement, styles: string[]): void;
1208
1239
  */
1209
1240
  function getTableFormatInfo(table: HTMLTableElement): Required<TableFormat> | null;
1210
1241
 
1242
+ /**
1243
+ * Add metadata to a cell
1244
+ * @param cell The table cell to add the metadata
1245
+ * @param format The format of the table
1246
+ */
1247
+ function saveTableCellMetadata(cell: HTMLTableCellElement, format: TableCellMetadataFormat): void;
1248
+
1211
1249
  /**
1212
1250
  * Get regions impacted by the given range under the root node
1213
1251
  * @param root Root node to get regions from
@@ -1950,7 +1988,7 @@ class Editor implements IEditor {
1950
1988
  * Focus to this editor, the selection was restored to where it was before, no unexpected scroll.
1951
1989
  */
1952
1990
  focus(): void;
1953
- select(arg1: Range | NodePosition | Node | SelectionPath | HTMLTableElement | null, arg2?: NodePosition | number | PositionType | TableSelection, arg3?: Node, arg4?: number | PositionType): boolean;
1991
+ select(arg1: Range | NodePosition | Node | SelectionPath | HTMLTableElement | HTMLImageElement | null, arg2?: NodePosition | number | PositionType | TableSelection, arg3?: Node, arg4?: number | PositionType): boolean;
1954
1992
  /**
1955
1993
  * Get current focused position. Return null if editor doesn't have focus at this time.
1956
1994
  */
@@ -2088,6 +2126,8 @@ class Editor implements IEditor {
2088
2126
  */
2089
2127
  getEditorDomAttribute(name: string): string | null;
2090
2128
  /**
2129
+ * @deprecated Use getVisibleViewport() instead.
2130
+ *
2091
2131
  * Get current relative distance from top-left corner of the given element to top-left corner of editor content DIV.
2092
2132
  * @param element The element to calculate from. If the given element is not in editor, return value will be null
2093
2133
  * @param addScroll When pass true, The return value will also add scrollLeft and scrollTop if any. So the value
@@ -2178,6 +2218,10 @@ class Editor implements IEditor {
2178
2218
  * @param scale The new scale number to set. It should be positive number and no greater than 10, otherwise it will be ignored.
2179
2219
  */
2180
2220
  setZoomScale(scale: number): void;
2221
+ /**
2222
+ * Retrieves the rect of the visible viewport of the editor.
2223
+ */
2224
+ getVisibleViewport(): Rect | null;
2181
2225
  /**
2182
2226
  * @returns the current EditorCore object
2183
2227
  * @throws a standard Error if there's no core object
@@ -2714,6 +2758,10 @@ interface DOMEventPluginState {
2714
2758
  * Context menu providers, that can provide context menu items
2715
2759
  */
2716
2760
  contextMenuProviders: ContextMenuProvider<any>[];
2761
+ /**
2762
+ * Image selection range
2763
+ */
2764
+ imageSelectionRange: ImageSelectionRange | null;
2717
2765
  }
2718
2766
 
2719
2767
  /**
@@ -2790,6 +2838,10 @@ interface LifecyclePluginState {
2790
2838
  * Cached table selection path for original content
2791
2839
  */
2792
2840
  shadowEditTableSelectionPath: SelectionPath[] | null;
2841
+ /**
2842
+ * Cached image selection path for original content
2843
+ */
2844
+ shadowEditImageSelectionPath: SelectionPath[] | null;
2793
2845
  }
2794
2846
 
2795
2847
  /**
@@ -3537,7 +3589,18 @@ const enum ExperimentalFeatures {
3537
3589
  * Normalize list to make sure it can be displayed correctly in other client
3538
3590
  * e.g. We will move list items with "display: block" into previous list item and change tag to be DIV
3539
3591
  */
3540
- NormalizeList = "NormalizeList"
3592
+ NormalizeList = "NormalizeList",
3593
+ /**
3594
+ * When a html image is selected, the selected image data will be stored by editor core.
3595
+ */
3596
+ ImageSelection = "ImageSelection",
3597
+ /**
3598
+ * With this feature enabled, when writing back a list item we will re-use all
3599
+ * ancestor list elements, even if they don't match the types currently in the
3600
+ * listTypes array for that item. The only list that we will ensure is correct
3601
+ * is the one closest to the item.
3602
+ */
3603
+ ReuseAllAncestorListElements = "ReuseAllAncestorListElements"
3541
3604
  }
3542
3605
 
3543
3606
  /**
@@ -4090,7 +4153,11 @@ const enum SelectionRangeTypes {
4090
4153
  /**
4091
4154
  * Selection made inside of a single table.
4092
4155
  */
4093
- TableSelection = 1
4156
+ TableSelection = 1,
4157
+ /**
4158
+ * Selection made in a image.
4159
+ */
4160
+ ImageSelection = 2
4094
4161
  }
4095
4162
 
4096
4163
  /**
@@ -4227,10 +4294,14 @@ const enum BulletListType {
4227
4294
  * Bullet triggered by -->
4228
4295
  */
4229
4296
  DoubleLongArrow = 8,
4297
+ /**
4298
+ * Bullet type circle
4299
+ */
4300
+ Circle = 9,
4230
4301
  /**
4231
4302
  * Maximum value of the enum
4232
4303
  */
4233
- Max = 8
4304
+ Max = 9
4234
4305
  }
4235
4306
 
4236
4307
  /**
@@ -5673,6 +5744,16 @@ interface TableFormat {
5673
5744
  keepCellShade?: boolean;
5674
5745
  }
5675
5746
 
5747
+ /**
5748
+ * Format of table cell that stored as metadata
5749
+ */
5750
+ interface TableCellMetadataFormat {
5751
+ /**
5752
+ * Override default background color
5753
+ */
5754
+ bgColorOverride?: boolean;
5755
+ }
5756
+
5676
5757
  /**
5677
5758
  * Represents a selection made inside of a table
5678
5759
  */
@@ -6264,6 +6345,8 @@ interface IEditor {
6264
6345
  */
6265
6346
  getEditorDomAttribute(name: string): string | null;
6266
6347
  /**
6348
+ * @deprecated Use getVisibleViewport() instead
6349
+ *
6267
6350
  * Get current relative distance from top-left corner of the given element to top-left corner of editor content DIV.
6268
6351
  * @param element The element to calculate from. If the given element is not in editor, return value will be null
6269
6352
  * @param addScroll When pass true, The return value will also add scrollLeft and scrollTop if any. So the value
@@ -6353,6 +6436,10 @@ interface IEditor {
6353
6436
  * @deprecated Use getZoomScale() instead
6354
6437
  */
6355
6438
  getSizeTransformer(): SizeTransformer;
6439
+ /**
6440
+ * Retrieves the rect of the visible viewport of the editor.
6441
+ */
6442
+ getVisibleViewport(): Rect | null;
6356
6443
  }
6357
6444
 
6358
6445
  /**
@@ -6566,6 +6653,14 @@ interface EditorCore extends PluginState {
6566
6653
  * @deprecated Use zoomScale instead
6567
6654
  */
6568
6655
  sizeTransformer: SizeTransformer;
6656
+ /**
6657
+ * Retrieves the Visible Viewport of the editor.
6658
+ */
6659
+ getVisibleViewport: () => Rect | null;
6660
+ /**
6661
+ * Color of the border of a selectedImage. Default color: '#DB626C'
6662
+ */
6663
+ imageSelectionBorderColor?: string;
6569
6664
  }
6570
6665
 
6571
6666
  /**
@@ -6733,6 +6828,14 @@ interface CoreApiMap {
6733
6828
  * @returns true if successful
6734
6829
  */
6735
6830
  selectTable: SelectTable;
6831
+ /**
6832
+ * Select a image and save data of the selected range
6833
+ * @param core The EditorCore object
6834
+ * @param image image to select
6835
+ * @param imageId the id of the image element
6836
+ * @returns true if successful
6837
+ */
6838
+ selectImage: SelectImage;
6736
6839
  }
6737
6840
 
6738
6841
  /**
@@ -6875,6 +6978,14 @@ type TriggerEvent = (core: EditorCore, pluginEvent: PluginEvent, broadcast: bool
6875
6978
  */
6876
6979
  type SelectTable = (core: EditorCore, table: HTMLTableElement | null, coordinates?: TableSelection) => TableSelectionRange | null;
6877
6980
 
6981
+ /**
6982
+ * Select a table and save data of the selected range
6983
+ * @param core The EditorCore object
6984
+ * @param image image to select
6985
+ * @returns true if successful
6986
+ */
6987
+ type SelectImage = (core: EditorCore, image: HTMLImageElement | null) => ImageSelectionRange | null;
6988
+
6878
6989
  /**
6879
6990
  * The options to specify parameters customizing an editor, used by ctor of Editor class
6880
6991
  */
@@ -6976,6 +7087,14 @@ interface EditorOptions {
6976
7087
  * @deprecated Use zoomScale instead
6977
7088
  */
6978
7089
  sizeTransformer?: SizeTransformer;
7090
+ /**
7091
+ * Retrieves the visible viewport of the Editor. The default viewport is the Rect of the scrollContainer.
7092
+ */
7093
+ getVisibleViewport?: () => Rect | null;
7094
+ /**
7095
+ * Color of the border of a selectedImage. Default color: '#DB626C'
7096
+ */
7097
+ imageSelectionBorderColor?: string;
6979
7098
  }
6980
7099
 
6981
7100
  /**
@@ -7530,10 +7649,20 @@ interface TableSelectionRange extends SelectionRangeExBase<SelectionRangeTypes.T
7530
7649
  coordinates: TableSelection | undefined;
7531
7650
  }
7532
7651
 
7652
+ /**
7653
+ * Represents a selected image.
7654
+ */
7655
+ interface ImageSelectionRange extends SelectionRangeExBase<SelectionRangeTypes.ImageSelection | CompatibleSelectionRangeTypes.ImageSelection> {
7656
+ /**
7657
+ * Selected Image
7658
+ */
7659
+ image: HTMLImageElement;
7660
+ }
7661
+
7533
7662
  /**
7534
7663
  * Types of ranges used in editor api getSelectionRangeEx
7535
7664
  */
7536
- type SelectionRangeEx = NormalSelectionRange | TableSelectionRange;
7665
+ type SelectionRangeEx = NormalSelectionRange | TableSelectionRange | ImageSelectionRange;
7537
7666
 
7538
7667
  /**
7539
7668
  * Attribute callback, will be called when HtmlSanitizer process an attribute with given name
@@ -7824,7 +7953,18 @@ enum CompatibleExperimentalFeatures {
7824
7953
  * Normalize list to make sure it can be displayed correctly in other client
7825
7954
  * e.g. We will move list items with "display: block" into previous list item and change tag to be DIV
7826
7955
  */
7827
- NormalizeList = "NormalizeList"
7956
+ NormalizeList = "NormalizeList",
7957
+ /**
7958
+ * When a html image is selected, the selected image data will be stored by editor core.
7959
+ */
7960
+ ImageSelection = "ImageSelection",
7961
+ /**
7962
+ * With this feature enabled, when writing back a list item we will re-use all
7963
+ * ancestor list elements, even if they don't match the types currently in the
7964
+ * listTypes array for that item. The only list that we will ensure is correct
7965
+ * is the one closest to the item.
7966
+ */
7967
+ ReuseAllAncestorListElements = "ReuseAllAncestorListElements"
7828
7968
  }
7829
7969
 
7830
7970
  /**
@@ -8236,7 +8376,11 @@ enum CompatibleSelectionRangeTypes {
8236
8376
  /**
8237
8377
  * Selection made inside of a single table.
8238
8378
  */
8239
- TableSelection = 1
8379
+ TableSelection = 1,
8380
+ /**
8381
+ * Selection made in a image.
8382
+ */
8383
+ ImageSelection = 2
8240
8384
  }
8241
8385
 
8242
8386
  /**
@@ -8327,10 +8471,14 @@ enum CompatibleBulletListType {
8327
8471
  * Bullet triggered by -->
8328
8472
  */
8329
8473
  DoubleLongArrow = 8,
8474
+ /**
8475
+ * Bullet type circle
8476
+ */
8477
+ Circle = 9,
8330
8478
  /**
8331
8479
  * Maximum value of the enum
8332
8480
  */
8333
- Max = 8
8481
+ Max = 9
8334
8482
  }
8335
8483
 
8336
8484
  /**
@@ -9839,4 +9987,27 @@ class AutoFormat implements EditorPlugin {
9839
9987
  onPluginEvent(event: PluginEvent): void;
9840
9988
  }
9841
9989
 
9990
+ /**
9991
+ * Detect image selection and help highlight the image
9992
+ */
9993
+ class ImageSelection implements EditorPlugin {
9994
+ private editor;
9995
+ private imageId;
9996
+ constructor();
9997
+ /**
9998
+ * Get a friendly name of this plugin
9999
+ */
10000
+ getName(): string;
10001
+ /**
10002
+ * Initialize this plugin. This should only be called from Editor
10003
+ * @param editor Editor instance
10004
+ */
10005
+ initialize(editor: IEditor): void;
10006
+ /**
10007
+ * Dispose this plugin
10008
+ */
10009
+ dispose(): void;
10010
+ onPluginEvent(event: PluginEvent): void;
10011
+ }
10012
+
9842
10013
  }