roosterjs-content-model-plugins 9.1.0 → 9.3.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.
Files changed (289) hide show
  1. package/lib/autoFormat/AutoFormatPlugin.d.ts +15 -5
  2. package/lib/autoFormat/AutoFormatPlugin.js +41 -4
  3. package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
  4. package/lib/autoFormat/link/createLink.js +2 -0
  5. package/lib/autoFormat/link/createLink.js.map +1 -1
  6. package/lib/autoFormat/list/keyboardListTrigger.js +7 -9
  7. package/lib/autoFormat/list/keyboardListTrigger.js.map +1 -1
  8. package/lib/autoFormat/numbers/transformFraction.d.ts +5 -0
  9. package/lib/autoFormat/numbers/transformFraction.js +27 -0
  10. package/lib/autoFormat/numbers/transformFraction.js.map +1 -0
  11. package/lib/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  12. package/lib/autoFormat/numbers/transformOrdinals.js +32 -0
  13. package/lib/autoFormat/numbers/transformOrdinals.js.map +1 -0
  14. package/lib/customReplace/CustomReplacePlugin.d.ts +61 -0
  15. package/lib/customReplace/CustomReplacePlugin.js +87 -0
  16. package/lib/customReplace/CustomReplacePlugin.js.map +1 -0
  17. package/lib/edit/EditPlugin.js +19 -1
  18. package/lib/edit/EditPlugin.js.map +1 -1
  19. package/lib/edit/inputSteps/handleEnterOnList.js +8 -1
  20. package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
  21. package/lib/edit/keyboardDelete.js +1 -0
  22. package/lib/edit/keyboardDelete.js.map +1 -1
  23. package/lib/edit/keyboardInput.js +1 -0
  24. package/lib/edit/keyboardInput.js.map +1 -1
  25. package/lib/edit/keyboardTab.js +5 -5
  26. package/lib/edit/keyboardTab.js.map +1 -1
  27. package/lib/edit/tabUtils/handleTabOnList.d.ts +2 -2
  28. package/lib/edit/tabUtils/handleTabOnList.js +3 -3
  29. package/lib/edit/tabUtils/handleTabOnList.js.map +1 -1
  30. package/lib/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  31. package/lib/edit/tabUtils/handleTabOnParagraph.js +2 -2
  32. package/lib/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  33. package/lib/hyperlink/HyperlinkPlugin.js +4 -1
  34. package/lib/hyperlink/HyperlinkPlugin.js.map +1 -1
  35. package/lib/index.d.ts +8 -1
  36. package/lib/index.js +8 -1
  37. package/lib/index.js.map +1 -1
  38. package/lib/markdown/utils/setFormat.js +11 -9
  39. package/lib/markdown/utils/setFormat.js.map +1 -1
  40. package/lib/picker/PickerHandler.d.ts +112 -0
  41. package/lib/picker/PickerHandler.js +3 -0
  42. package/lib/picker/PickerHandler.js.map +1 -0
  43. package/lib/picker/PickerHelper.d.ts +22 -0
  44. package/lib/picker/PickerHelper.js +3 -0
  45. package/lib/picker/PickerHelper.js.map +1 -0
  46. package/lib/picker/PickerHelperImpl.d.ts +25 -0
  47. package/lib/picker/PickerHelperImpl.js +54 -0
  48. package/lib/picker/PickerHelperImpl.js.map +1 -0
  49. package/lib/picker/PickerPlugin.d.ts +54 -0
  50. package/lib/picker/PickerPlugin.js +217 -0
  51. package/lib/picker/PickerPlugin.js.map +1 -0
  52. package/lib/picker/getQueryString.d.ts +5 -0
  53. package/lib/picker/getQueryString.js +36 -0
  54. package/lib/picker/getQueryString.js.map +1 -0
  55. package/lib/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  56. package/lib/pluginUtils/Rect/getDOMInsertPointRect.js +57 -0
  57. package/lib/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  58. package/lib/shortcut/ShortcutPlugin.js +1 -0
  59. package/lib/shortcut/ShortcutPlugin.js.map +1 -1
  60. package/lib/shortcut/shortcuts.d.ts +7 -0
  61. package/lib/shortcut/shortcuts.js +15 -1
  62. package/lib/shortcut/shortcuts.js.map +1 -1
  63. package/lib/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  64. package/lib/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  65. package/lib/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
  66. package/lib/tableEdit/OnTableEditorCreatedCallback.js +3 -0
  67. package/lib/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  68. package/lib/tableEdit/TableEditPlugin.d.ts +7 -1
  69. package/lib/tableEdit/TableEditPlugin.js +7 -2
  70. package/lib/tableEdit/TableEditPlugin.js.map +1 -1
  71. package/lib/tableEdit/editors/TableEditor.d.ts +9 -1
  72. package/lib/tableEdit/editors/TableEditor.js +51 -15
  73. package/lib/tableEdit/editors/TableEditor.js.map +1 -1
  74. package/lib/tableEdit/editors/features/CellResizer.d.ts +9 -1
  75. package/lib/tableEdit/editors/features/CellResizer.js +11 -3
  76. package/lib/tableEdit/editors/features/CellResizer.js.map +1 -1
  77. package/lib/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
  78. package/lib/tableEdit/editors/features/TableEditFeature.js +6 -6
  79. package/lib/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  80. package/lib/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
  81. package/lib/tableEdit/editors/features/TableEditFeatureName.js +3 -0
  82. package/lib/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
  83. package/lib/tableEdit/editors/features/TableInserter.d.ts +10 -1
  84. package/lib/tableEdit/editors/features/TableInserter.js +18 -12
  85. package/lib/tableEdit/editors/features/TableInserter.js.map +1 -1
  86. package/lib/tableEdit/editors/features/TableMover.d.ts +48 -3
  87. package/lib/tableEdit/editors/features/TableMover.js +212 -24
  88. package/lib/tableEdit/editors/features/TableMover.js.map +1 -1
  89. package/lib/tableEdit/editors/features/TableResizer.d.ts +7 -2
  90. package/lib/tableEdit/editors/features/TableResizer.js +25 -6
  91. package/lib/tableEdit/editors/features/TableResizer.js.map +1 -1
  92. package/lib/watermark/WatermarkPlugin.d.ts +1 -1
  93. package/lib/watermark/WatermarkPlugin.js +2 -1
  94. package/lib/watermark/WatermarkPlugin.js.map +1 -1
  95. package/lib/watermark/isModelEmptyFast.js +4 -0
  96. package/lib/watermark/isModelEmptyFast.js.map +1 -1
  97. package/lib-amd/autoFormat/AutoFormatPlugin.d.ts +15 -5
  98. package/lib-amd/autoFormat/AutoFormatPlugin.js +39 -5
  99. package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
  100. package/lib-amd/autoFormat/link/createLink.js +2 -0
  101. package/lib-amd/autoFormat/link/createLink.js.map +1 -1
  102. package/lib-amd/autoFormat/list/keyboardListTrigger.js +7 -9
  103. package/lib-amd/autoFormat/list/keyboardListTrigger.js.map +1 -1
  104. package/lib-amd/autoFormat/numbers/transformFraction.d.ts +5 -0
  105. package/lib-amd/autoFormat/numbers/transformFraction.js +28 -0
  106. package/lib-amd/autoFormat/numbers/transformFraction.js.map +1 -0
  107. package/lib-amd/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  108. package/lib-amd/autoFormat/numbers/transformOrdinals.js +33 -0
  109. package/lib-amd/autoFormat/numbers/transformOrdinals.js.map +1 -0
  110. package/lib-amd/customReplace/CustomReplacePlugin.d.ts +61 -0
  111. package/lib-amd/customReplace/CustomReplacePlugin.js +88 -0
  112. package/lib-amd/customReplace/CustomReplacePlugin.js.map +1 -0
  113. package/lib-amd/edit/EditPlugin.js +19 -1
  114. package/lib-amd/edit/EditPlugin.js.map +1 -1
  115. package/lib-amd/edit/inputSteps/handleEnterOnList.js +8 -2
  116. package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
  117. package/lib-amd/edit/keyboardDelete.js +1 -0
  118. package/lib-amd/edit/keyboardDelete.js.map +1 -1
  119. package/lib-amd/edit/keyboardInput.js +1 -0
  120. package/lib-amd/edit/keyboardInput.js.map +1 -1
  121. package/lib-amd/edit/keyboardTab.js +5 -5
  122. package/lib-amd/edit/keyboardTab.js.map +1 -1
  123. package/lib-amd/edit/tabUtils/handleTabOnList.d.ts +2 -2
  124. package/lib-amd/edit/tabUtils/handleTabOnList.js +3 -3
  125. package/lib-amd/edit/tabUtils/handleTabOnList.js.map +1 -1
  126. package/lib-amd/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  127. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js +2 -2
  128. package/lib-amd/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  129. package/lib-amd/hyperlink/HyperlinkPlugin.js +4 -1
  130. package/lib-amd/hyperlink/HyperlinkPlugin.js.map +1 -1
  131. package/lib-amd/index.d.ts +8 -1
  132. package/lib-amd/index.js +6 -2
  133. package/lib-amd/index.js.map +1 -1
  134. package/lib-amd/markdown/utils/setFormat.js +11 -9
  135. package/lib-amd/markdown/utils/setFormat.js.map +1 -1
  136. package/lib-amd/picker/PickerHandler.d.ts +112 -0
  137. package/lib-amd/picker/PickerHandler.js +5 -0
  138. package/lib-amd/picker/PickerHandler.js.map +1 -0
  139. package/lib-amd/picker/PickerHelper.d.ts +22 -0
  140. package/lib-amd/picker/PickerHelper.js +5 -0
  141. package/lib-amd/picker/PickerHelper.js.map +1 -0
  142. package/lib-amd/picker/PickerHelperImpl.d.ts +25 -0
  143. package/lib-amd/picker/PickerHelperImpl.js +53 -0
  144. package/lib-amd/picker/PickerHelperImpl.js.map +1 -0
  145. package/lib-amd/picker/PickerPlugin.d.ts +54 -0
  146. package/lib-amd/picker/PickerPlugin.js +215 -0
  147. package/lib-amd/picker/PickerPlugin.js.map +1 -0
  148. package/lib-amd/picker/getQueryString.d.ts +5 -0
  149. package/lib-amd/picker/getQueryString.js +37 -0
  150. package/lib-amd/picker/getQueryString.js.map +1 -0
  151. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  152. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js +58 -0
  153. package/lib-amd/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  154. package/lib-amd/shortcut/ShortcutPlugin.js +1 -0
  155. package/lib-amd/shortcut/ShortcutPlugin.js.map +1 -1
  156. package/lib-amd/shortcut/shortcuts.d.ts +7 -0
  157. package/lib-amd/shortcut/shortcuts.js +15 -1
  158. package/lib-amd/shortcut/shortcuts.js.map +1 -1
  159. package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  160. package/lib-amd/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  161. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
  162. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js +5 -0
  163. package/lib-amd/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  164. package/lib-amd/tableEdit/TableEditPlugin.d.ts +7 -1
  165. package/lib-amd/tableEdit/TableEditPlugin.js +7 -2
  166. package/lib-amd/tableEdit/TableEditPlugin.js.map +1 -1
  167. package/lib-amd/tableEdit/editors/TableEditor.d.ts +9 -1
  168. package/lib-amd/tableEdit/editors/TableEditor.js +51 -15
  169. package/lib-amd/tableEdit/editors/TableEditor.js.map +1 -1
  170. package/lib-amd/tableEdit/editors/features/CellResizer.d.ts +9 -1
  171. package/lib-amd/tableEdit/editors/features/CellResizer.js +11 -3
  172. package/lib-amd/tableEdit/editors/features/CellResizer.js.map +1 -1
  173. package/lib-amd/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
  174. package/lib-amd/tableEdit/editors/features/TableEditFeature.js +6 -6
  175. package/lib-amd/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  176. package/lib-amd/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
  177. package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js +5 -0
  178. package/lib-amd/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
  179. package/lib-amd/tableEdit/editors/features/TableInserter.d.ts +10 -1
  180. package/lib-amd/tableEdit/editors/features/TableInserter.js +18 -12
  181. package/lib-amd/tableEdit/editors/features/TableInserter.js.map +1 -1
  182. package/lib-amd/tableEdit/editors/features/TableMover.d.ts +48 -3
  183. package/lib-amd/tableEdit/editors/features/TableMover.js +212 -25
  184. package/lib-amd/tableEdit/editors/features/TableMover.js.map +1 -1
  185. package/lib-amd/tableEdit/editors/features/TableResizer.d.ts +7 -2
  186. package/lib-amd/tableEdit/editors/features/TableResizer.js +25 -7
  187. package/lib-amd/tableEdit/editors/features/TableResizer.js.map +1 -1
  188. package/lib-amd/watermark/WatermarkPlugin.d.ts +1 -1
  189. package/lib-amd/watermark/WatermarkPlugin.js +2 -1
  190. package/lib-amd/watermark/WatermarkPlugin.js.map +1 -1
  191. package/lib-amd/watermark/isModelEmptyFast.js +4 -0
  192. package/lib-amd/watermark/isModelEmptyFast.js.map +1 -1
  193. package/lib-mjs/autoFormat/AutoFormatPlugin.d.ts +15 -5
  194. package/lib-mjs/autoFormat/AutoFormatPlugin.js +41 -4
  195. package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
  196. package/lib-mjs/autoFormat/link/createLink.js +3 -1
  197. package/lib-mjs/autoFormat/link/createLink.js.map +1 -1
  198. package/lib-mjs/autoFormat/list/keyboardListTrigger.js +7 -9
  199. package/lib-mjs/autoFormat/list/keyboardListTrigger.js.map +1 -1
  200. package/lib-mjs/autoFormat/numbers/transformFraction.d.ts +5 -0
  201. package/lib-mjs/autoFormat/numbers/transformFraction.js +23 -0
  202. package/lib-mjs/autoFormat/numbers/transformFraction.js.map +1 -0
  203. package/lib-mjs/autoFormat/numbers/transformOrdinals.d.ts +5 -0
  204. package/lib-mjs/autoFormat/numbers/transformOrdinals.js +28 -0
  205. package/lib-mjs/autoFormat/numbers/transformOrdinals.js.map +1 -0
  206. package/lib-mjs/customReplace/CustomReplacePlugin.d.ts +61 -0
  207. package/lib-mjs/customReplace/CustomReplacePlugin.js +84 -0
  208. package/lib-mjs/customReplace/CustomReplacePlugin.js.map +1 -0
  209. package/lib-mjs/edit/EditPlugin.js +19 -1
  210. package/lib-mjs/edit/EditPlugin.js.map +1 -1
  211. package/lib-mjs/edit/inputSteps/handleEnterOnList.js +8 -1
  212. package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
  213. package/lib-mjs/edit/keyboardDelete.js +1 -0
  214. package/lib-mjs/edit/keyboardDelete.js.map +1 -1
  215. package/lib-mjs/edit/keyboardInput.js +1 -0
  216. package/lib-mjs/edit/keyboardInput.js.map +1 -1
  217. package/lib-mjs/edit/keyboardTab.js +5 -5
  218. package/lib-mjs/edit/keyboardTab.js.map +1 -1
  219. package/lib-mjs/edit/tabUtils/handleTabOnList.d.ts +2 -2
  220. package/lib-mjs/edit/tabUtils/handleTabOnList.js +3 -3
  221. package/lib-mjs/edit/tabUtils/handleTabOnList.js.map +1 -1
  222. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.d.ts +2 -2
  223. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js +2 -2
  224. package/lib-mjs/edit/tabUtils/handleTabOnParagraph.js.map +1 -1
  225. package/lib-mjs/hyperlink/HyperlinkPlugin.js +4 -1
  226. package/lib-mjs/hyperlink/HyperlinkPlugin.js.map +1 -1
  227. package/lib-mjs/index.d.ts +8 -1
  228. package/lib-mjs/index.js +4 -1
  229. package/lib-mjs/index.js.map +1 -1
  230. package/lib-mjs/markdown/utils/setFormat.js +11 -9
  231. package/lib-mjs/markdown/utils/setFormat.js.map +1 -1
  232. package/lib-mjs/picker/PickerHandler.d.ts +112 -0
  233. package/lib-mjs/picker/PickerHandler.js +2 -0
  234. package/lib-mjs/picker/PickerHandler.js.map +1 -0
  235. package/lib-mjs/picker/PickerHelper.d.ts +22 -0
  236. package/lib-mjs/picker/PickerHelper.js +2 -0
  237. package/lib-mjs/picker/PickerHelper.js.map +1 -0
  238. package/lib-mjs/picker/PickerHelperImpl.d.ts +25 -0
  239. package/lib-mjs/picker/PickerHelperImpl.js +51 -0
  240. package/lib-mjs/picker/PickerHelperImpl.js.map +1 -0
  241. package/lib-mjs/picker/PickerPlugin.d.ts +54 -0
  242. package/lib-mjs/picker/PickerPlugin.js +214 -0
  243. package/lib-mjs/picker/PickerPlugin.js.map +1 -0
  244. package/lib-mjs/picker/getQueryString.d.ts +5 -0
  245. package/lib-mjs/picker/getQueryString.js +32 -0
  246. package/lib-mjs/picker/getQueryString.js.map +1 -0
  247. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.d.ts +7 -0
  248. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js +53 -0
  249. package/lib-mjs/pluginUtils/Rect/getDOMInsertPointRect.js.map +1 -0
  250. package/lib-mjs/shortcut/ShortcutPlugin.js +2 -1
  251. package/lib-mjs/shortcut/ShortcutPlugin.js.map +1 -1
  252. package/lib-mjs/shortcut/shortcuts.d.ts +7 -0
  253. package/lib-mjs/shortcut/shortcuts.js +14 -0
  254. package/lib-mjs/shortcut/shortcuts.js.map +1 -1
  255. package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js +2 -2
  256. package/lib-mjs/shortcut/utils/setShortcutIndentationCommand.js.map +1 -1
  257. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.d.ts +5 -0
  258. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js +2 -0
  259. package/lib-mjs/tableEdit/OnTableEditorCreatedCallback.js.map +1 -0
  260. package/lib-mjs/tableEdit/TableEditPlugin.d.ts +7 -1
  261. package/lib-mjs/tableEdit/TableEditPlugin.js +7 -2
  262. package/lib-mjs/tableEdit/TableEditPlugin.js.map +1 -1
  263. package/lib-mjs/tableEdit/editors/TableEditor.d.ts +9 -1
  264. package/lib-mjs/tableEdit/editors/TableEditor.js +52 -16
  265. package/lib-mjs/tableEdit/editors/TableEditor.js.map +1 -1
  266. package/lib-mjs/tableEdit/editors/features/CellResizer.d.ts +9 -1
  267. package/lib-mjs/tableEdit/editors/features/CellResizer.js +10 -2
  268. package/lib-mjs/tableEdit/editors/features/CellResizer.js.map +1 -1
  269. package/lib-mjs/tableEdit/editors/features/TableEditFeature.d.ts +1 -1
  270. package/lib-mjs/tableEdit/editors/features/TableEditFeature.js +6 -6
  271. package/lib-mjs/tableEdit/editors/features/TableEditFeature.js.map +1 -1
  272. package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.d.ts +4 -0
  273. package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js +2 -0
  274. package/lib-mjs/tableEdit/editors/features/TableEditFeatureName.js.map +1 -0
  275. package/lib-mjs/tableEdit/editors/features/TableInserter.d.ts +10 -1
  276. package/lib-mjs/tableEdit/editors/features/TableInserter.js +17 -11
  277. package/lib-mjs/tableEdit/editors/features/TableInserter.js.map +1 -1
  278. package/lib-mjs/tableEdit/editors/features/TableMover.d.ts +48 -3
  279. package/lib-mjs/tableEdit/editors/features/TableMover.js +209 -24
  280. package/lib-mjs/tableEdit/editors/features/TableMover.js.map +1 -1
  281. package/lib-mjs/tableEdit/editors/features/TableResizer.d.ts +7 -2
  282. package/lib-mjs/tableEdit/editors/features/TableResizer.js +23 -4
  283. package/lib-mjs/tableEdit/editors/features/TableResizer.js.map +1 -1
  284. package/lib-mjs/watermark/WatermarkPlugin.d.ts +1 -1
  285. package/lib-mjs/watermark/WatermarkPlugin.js +2 -1
  286. package/lib-mjs/watermark/WatermarkPlugin.js.map +1 -1
  287. package/lib-mjs/watermark/isModelEmptyFast.js +4 -0
  288. package/lib-mjs/watermark/isModelEmptyFast.js.map +1 -1
  289. package/package.json +5 -5
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDOMInsertPointRect = void 0;
4
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
5
+ /**
6
+ * Get bounding rect of the given DOM insert point
7
+ * @param doc The document object
8
+ * @param pos The input DOM insert point
9
+ */
10
+ function getDOMInsertPointRect(doc, pos) {
11
+ var _a;
12
+ var node = pos.node, offset = pos.offset;
13
+ var range = doc.createRange();
14
+ range.setStart(node, offset);
15
+ // 1) try to get rect using range.getBoundingClientRect()
16
+ var rect = (0, roosterjs_content_model_dom_1.normalizeRect)(range.getBoundingClientRect());
17
+ if (rect) {
18
+ return rect;
19
+ }
20
+ // 2) try to get rect using range.getClientRects
21
+ while (node.lastChild) {
22
+ if (offset == node.childNodes.length) {
23
+ node = node.lastChild;
24
+ offset = node.childNodes.length;
25
+ }
26
+ else {
27
+ node = node.childNodes[offset];
28
+ offset = 0;
29
+ }
30
+ }
31
+ var rects = range.getClientRects && range.getClientRects();
32
+ rect = rects && rects.length == 1 ? (0, roosterjs_content_model_dom_1.normalizeRect)(rects[0]) : null;
33
+ if (rect) {
34
+ return rect;
35
+ }
36
+ // 3) if node is text node, try inserting a SPAN and get the rect of SPAN for others
37
+ if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'TEXT_NODE')) {
38
+ var span = node.ownerDocument.createElement('span');
39
+ span.textContent = '\u200b';
40
+ range.insertNode(span);
41
+ rect = (0, roosterjs_content_model_dom_1.normalizeRect)(span.getBoundingClientRect());
42
+ (_a = span.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(span);
43
+ if (rect) {
44
+ return rect;
45
+ }
46
+ }
47
+ // 4) try getBoundingClientRect on element
48
+ if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && node.getBoundingClientRect) {
49
+ rect = (0, roosterjs_content_model_dom_1.normalizeRect)(node.getBoundingClientRect());
50
+ if (rect) {
51
+ return rect;
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ exports.getDOMInsertPointRect = getDOMInsertPointRect;
57
+ //# sourceMappingURL=getDOMInsertPointRect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDOMInsertPointRect.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/pluginUtils/Rect/getDOMInsertPointRect.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAG1E;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,GAAa,EAAE,GAAmB;;IAC9D,IAAA,IAAI,GAAa,GAAG,KAAhB,EAAE,MAAM,GAAK,GAAG,OAAR,CAAS;IAC3B,IAAM,KAAK,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;IAEhC,KAAK,CAAC,Q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AC;SACf;KACJ;IAED,0CAA0C;IAC1C,IAAI,IAAA,0CAAY,EAAC,IAAI,EAAE,cAAc,CAAC,IAAI,IAAI,CAAC,qBAAqB,EAAE;QAClE,IAAI,GAAG,IAAA,2CAAa,EAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC,CAAC;QAEnD,IAAI,IAAI,EAAE;YACN,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAtDD,sDAsDC","sourcesContent":["import { isNodeOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport type { DOMInsertPoint, Rect } from 'roosterjs-content-model-types';\n\n/**\n * Get bounding rect of the given DOM insert point\n * @param doc The document object\n * @param pos The input DOM insert point\n */\nexport function getDOMInsertPointRect(doc: Document, pos: DOMInsertPoint): Rect | null {\n let { node, offset } = pos;\n const range = doc.createRange();\n\n range.setStart(node, offset);\n\n // 1) try to get rect using range.getBoundingClientRect()\n let rect = normalizeRect(range.getBoundingClientRect());\n\n if (rect) {\n return rect;\n }\n\n // 2) try to get rect using range.getClientRects\n while (node.lastChild) {\n if (offset == node.childNodes.length) {\n node = node.lastChild;\n offset = node.childNodes.length;\n } else {\n node = node.childNodes[offset];\n offset = 0;\n }\n }\n\n const rects = range.getClientRects && range.getClientRects();\n rect = rects && rects.length == 1 ? normalizeRect(rects[0]) : null;\n if (rect) {\n return rect;\n }\n\n // 3) if node is text node, try inserting a SPAN and get the rect of SPAN for others\n if (isNodeOfType(node, 'TEXT_NODE')) {\n const span = node.ownerDocument.createElement('span');\n\n span.textContent = '\\u200b';\n range.insertNode(span);\n rect = normalizeRect(span.getBoundingClientRect());\n span.parentNode?.removeChild(span);\n\n if (rect) {\n return rect;\n }\n }\n\n // 4) try getBoundingClientRect on element\n if (isNodeOfType(node, 'ELEMENT_NODE') && node.getBoundingClientRect) {\n rect = normalizeRect(node.getBoundingClientRect());\n\n if (rect) {\n return rect;\n }\n }\n\n return null;\n}\n"]}
@@ -11,6 +11,7 @@ var defaultShortcuts = [
11
11
  shortcuts_1.ShortcutUndo,
12
12
  shortcuts_1.ShortcutUndo2,
13
13
  shortcuts_1.ShortcutRedo,
14
+ shortcuts_1.ShortcutRedoAlt,
14
15
  shortcuts_1.ShortcutRedoMacOS,
15
16
  shortcuts_1.ShortcutBullet,
16
17
  shortcuts_1.ShortcutNumbering,
@@ -1 +1 @@
1
- {"version":3,"file":"ShortcutPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAAgE;AAEhE,yCAeqB;AAQrB,IAAM,gBAAgB,GAAsB;IACxC,wBAAY;IACZ,0BAAc;IACd,6BAAiB;IACjB,+BAAmB;IACnB,wBAAY;IACZ,yBAAa;IACb,wBAAY;IACZ,6BAAiB;IACjB,0BAAc;IACd,6BAAiB;IACjB,gCAAoB;IACpB,gCAAoB;IACpB,8BAAkB;IAClB,+BAAmB;CACtB,CAAC;AACF,IAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD;;GAEG;AACH;IAII;;;OAGG;IACH,wBAAoB,SAA+C;QAA/C,0BAAA,EAAA,4BAA+C;QAA/C,cAAS,GAAT,SAAS,CAAsC;QAP3D,WAAM,GAAmB,IAAI,CAAC;QAC9B,UAAK,GAAG,KAAK,CAAC;IAMgD,CAAC;IAEvE;;OAEG;IACH,gCAAO,GAAP;QACI,OAAO,UAAU,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACH,mCAAU,GAAV,UAAW,MAAe;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,gCAAO,GAAP;QACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACH,mDAA0B,GAA1B,UAA2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,CAAC,KAAK,CAAC;YAEvB;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC;IAEO,sCAAa,GAArB,UAAsB,WAAkC,EAAE,KAAoB;QAClE,IAAA,OAAO,GAAuC,KAAK,QAA5C,EAAE,MAAM,GAA+B,KAAK,OAApC,EAAE,QAAQ,GAAqB,KAAK,SAA1B,EAAE,KAAK,GAAc,KAAK,MAAnB,EAAE,OAAO,GAAK,KAAK,QAAV,CAAW;QAC5D,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAClD,IAAM,aAAa,GACf,CAAC,WAAW,CAAC,WAAW,IAAI,MAAM,IAAI,UAAU,IAAI,CAAC,MAAM,CAAC;YAC5D,CAAC,WAAW,CAAC,WAAW,IAAI,KAAK,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;QAEhE,OAAO,aAAa,IAAI,QAAQ,IAAI,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,IAAI,KAAK,CAAC;IAC3F,CAAC;IACL,qBAAC;AAAD,CAAC,AA3GD,IA2GC;AA3GY,wCAAc","sourcesContent":["import { cacheGetEventData } from 'roosterjs-content-model-dom';\nimport type { ShortcutCommand, ShortcutKeyDefinition } from './ShortcutCommand';\nimport {\n ShortcutBold,\n ShortcutBullet,\n ShortcutClearFormat,\n ShortcutDecreaseFont,\n ShortcutIncreaseFont,\n ShortcutIndentList,\n ShortcutItalic,\n ShortcutNumbering,\n ShortcutOutdentList,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutUnderline,\n ShortcutUndo,\n ShortcutUndo2,\n} from './shortcuts';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst defaultShortcuts: ShortcutCommand[] = [\n ShortcutBold,\n ShortcutItalic,\n ShortcutUnderline,\n ShortcutClearFormat,\n ShortcutUndo,\n ShortcutUndo2,\n ShortcutRedo,\n ShortcutRedoMacOS,\n ShortcutBullet,\n ShortcutNumbering,\n ShortcutIncreaseFont,\n ShortcutDecreaseFont,\n ShortcutIndentList,\n ShortcutOutdentList,\n];\nconst CommandCacheKey = '__ShortcutCommandCache';\n\n/**\n * Shortcut plugin hook on the specified shortcut keys and trigger related format API\n */\nexport class ShortcutPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private isMac = false;\n\n /**\n * Create a new instance of ShortcutPlugin\n * @param [shortcuts=defaultShortcuts] Allowed commands\n */\n constructor(private shortcuts: ShortcutCommand[] = defaultShortcuts) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Shortcut';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.isMac = !!this.editor.getEnvironment().isMac;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n return (\n event.eventType == 'keyDown' &&\n (event.rawEvent.ctrlKey || event.rawEvent.altKey || event.rawEvent.metaKey) &&\n !!this.cacheGetCommand(event)\n );\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor && event.eventType == 'keyDown') {\n const command = this.cacheGetCommand(event);\n\n if (command) {\n command.onClick(this.editor);\n event.rawEvent.preventDefault();\n }\n }\n }\n\n private cacheGetCommand(event: KeyDownEvent) {\n return cacheGetEventData(event, CommandCacheKey, event => {\n const editor = this.editor;\n\n return (\n editor &&\n this.shortcuts.filter(\n command =>\n this.matchOS(command.environment) &&\n this.matchShortcut(command.shortcutKey, event.rawEvent)\n )[0]\n );\n });\n }\n\n private matchOS(environment?: 'all' | 'mac' | 'nonMac') {\n switch (environment) {\n case 'mac':\n return this.isMac;\n\n case 'nonMac':\n return !this.isMac;\n\n default:\n return true;\n }\n }\n\n private matchShortcut(shortcutKey: ShortcutKeyDefinition, event: KeyboardEvent) {\n const { ctrlKey, altKey, shiftKey, which, metaKey } = event;\n const ctrlOrMeta = this.isMac ? metaKey : ctrlKey;\n const matchModifier =\n (shortcutKey.modifierKey == 'ctrl' && ctrlOrMeta && !altKey) ||\n (shortcutKey.modifierKey == 'alt' && altKey && !ctrlOrMeta);\n\n return matchModifier && shiftKey == shortcutKey.shiftKey && shortcutKey.which == which;\n }\n}\n"]}
1
+ {"version":3,"file":"ShortcutPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/ShortcutPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAAgE;AAEhE,yCAgBqB;AAQrB,IAAM,gBAAgB,GAAsB;IACxC,wBAAY;IACZ,0BAAc;IACd,6BAAiB;IACjB,+BAAmB;IACnB,wBAAY;IACZ,yBAAa;IACb,wBAAY;IACZ,2BAAe;IACf,6BAAiB;IACjB,0BAAc;IACd,6BAAiB;IACjB,gCAAoB;IACpB,gCAAoB;IACpB,8BAAkB;IAClB,+BAAmB;CACtB,CAAC;AACF,IAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD;;GAEG;AACH;IAII;;;OAGG;IACH,wBAAoB,SAA+C;QAA/C,0BAAA,EAAA,4BAA+C;QAA/C,cAAS,GAAT,SAAS,CAAsC;QAP3D,WAAM,GAAmB,IAAI,CAAC;QAC9B,UAAK,GAAG,KAAK,CAAC;IAMgD,CAAC;IAEvE;;OAE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oBACH,OAAA,KAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;wBACjC,KAAI,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC;gBADvD,CACuD,CAC9D,CAAC,CAAC,CAAC,CACP,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,gCAAO,GAAf,UAAgB,WAAsC;QAClD,QAAQ,WAAW,EAAE;YACjB,KAAK,KAAK;gBACN,OAAO,IAAI,CAAC,KAAK,CAAC;YAEtB,KAAK,QAAQ;gBACT,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;YAEvB;gBACI,OAAO,IAAI,CAAC;SACnB;IACL,CAAC;IAEO,sCAAa,GAArB,UAAsB,WAAkC,EAAE,KAAoB;QAClE,IAAA,OAAO,GAAuC,KAAK,QAA5C,EAAE,MAAM,GAA+B,KAAK,OAApC,EAAE,QAAQ,GAAqB,KAAK,SAA1B,EAAE,KAAK,GAAc,KAAK,MAAnB,EAAE,OAAO,GAAK,KAAK,QAAV,CAAW;QAC5D,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;QAClD,IAAM,aAAa,GACf,CAAC,WAAW,CAAC,WAAW,IAAI,MAAM,IAAI,UAAU,IAAI,CAAC,MAAM,CAAC;YAC5D,CAAC,WAAW,CAAC,WAAW,IAAI,KAAK,IAAI,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC;QAEhE,OAAO,aAAa,IAAI,QAAQ,IAAI,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,KAAK,IAAI,KAAK,CAAC;IAC3F,CAAC;IACL,qBAAC;AAAD,CAAC,AA3GD,IA2GC;AA3GY,wCAAc","sourcesContent":["import { cacheGetEventData } from 'roosterjs-content-model-dom';\nimport type { ShortcutCommand, ShortcutKeyDefinition } from './ShortcutCommand';\nimport {\n ShortcutBold,\n ShortcutBullet,\n ShortcutClearFormat,\n ShortcutDecreaseFont,\n ShortcutIncreaseFont,\n ShortcutIndentList,\n ShortcutItalic,\n ShortcutNumbering,\n ShortcutOutdentList,\n ShortcutRedo,\n ShortcutRedoAlt,\n ShortcutRedoMacOS,\n ShortcutUnderline,\n ShortcutUndo,\n ShortcutUndo2,\n} from './shortcuts';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst defaultShortcuts: ShortcutCommand[] = [\n ShortcutBold,\n ShortcutItalic,\n ShortcutUnderline,\n ShortcutClearFormat,\n ShortcutUndo,\n ShortcutUndo2,\n ShortcutRedo,\n ShortcutRedoAlt,\n ShortcutRedoMacOS,\n ShortcutBullet,\n ShortcutNumbering,\n ShortcutIncreaseFont,\n ShortcutDecreaseFont,\n ShortcutIndentList,\n ShortcutOutdentList,\n];\nconst CommandCacheKey = '__ShortcutCommandCache';\n\n/**\n * Shortcut plugin hook on the specified shortcut keys and trigger related format API\n */\nexport class ShortcutPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private isMac = false;\n\n /**\n * Create a new instance of ShortcutPlugin\n * @param [shortcuts=defaultShortcuts] Allowed commands\n */\n constructor(private shortcuts: ShortcutCommand[] = defaultShortcuts) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Shortcut';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.isMac = !!this.editor.getEnvironment().isMac;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Check if the plugin should handle the given event exclusively.\n * Handle an event exclusively means other plugin will not receive this event in\n * onPluginEvent method.\n * If two plugins will return true in willHandleEventExclusively() for the same event,\n * the final result depends on the order of the plugins are added into editor\n * @param event The event to check:\n */\n willHandleEventExclusively(event: PluginEvent) {\n return (\n event.eventType == 'keyDown' &&\n (event.rawEvent.ctrlKey || event.rawEvent.altKey || event.rawEvent.metaKey) &&\n !!this.cacheGetCommand(event)\n );\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor && event.eventType == 'keyDown') {\n const command = this.cacheGetCommand(event);\n\n if (command) {\n command.onClick(this.editor);\n event.rawEvent.preventDefault();\n }\n }\n }\n\n private cacheGetCommand(event: KeyDownEvent) {\n return cacheGetEventData(event, CommandCacheKey, event => {\n const editor = this.editor;\n\n return (\n editor &&\n this.shortcuts.filter(\n command =>\n this.matchOS(command.environment) &&\n this.matchShortcut(command.shortcutKey, event.rawEvent)\n )[0]\n );\n });\n }\n\n private matchOS(environment?: 'all' | 'mac' | 'nonMac') {\n switch (environment) {\n case 'mac':\n return this.isMac;\n\n case 'nonMac':\n return !this.isMac;\n\n default:\n return true;\n }\n }\n\n private matchShortcut(shortcutKey: ShortcutKeyDefinition, event: KeyboardEvent) {\n const { ctrlKey, altKey, shiftKey, which, metaKey } = event;\n const ctrlOrMeta = this.isMac ? metaKey : ctrlKey;\n const matchModifier =\n (shortcutKey.modifierKey == 'ctrl' && ctrlOrMeta && !altKey) ||\n (shortcutKey.modifierKey == 'alt' && altKey && !ctrlOrMeta);\n\n return matchModifier && shiftKey == shortcutKey.shiftKey && shortcutKey.which == which;\n }\n}\n"]}
@@ -42,11 +42,18 @@ export declare const ShortcutUndo2: ShortcutCommand;
42
42
  */
43
43
  export declare const ShortcutRedo: ShortcutCommand;
44
44
  /**
45
+ * @deprecated
45
46
  * Shortcut command for Redo 2
46
47
  * Windows: N/A
47
48
  * MacOS: Meta + Shift + Z
48
49
  */
49
50
  export declare const ShortcutRedoMacOS: ShortcutCommand;
51
+ /**
52
+ * Shortcut command for Redo 3
53
+ * Windows: Ctrl + Shift + Z
54
+ * MacOS: Meta + Shift + Z
55
+ */
56
+ export declare const ShortcutRedoAlt: ShortcutCommand;
50
57
  /**
51
58
  * Shortcut command for Bullet List
52
59
  * Windows: Ctrl + . (Period)
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ShortcutOutdentList = exports.ShortcutIndentList = exports.ShortcutDecreaseFont = exports.ShortcutIncreaseFont = exports.ShortcutNumbering = exports.ShortcutBullet = exports.ShortcutRedoMacOS = exports.ShortcutRedo = exports.ShortcutUndo2 = exports.ShortcutUndo = exports.ShortcutClearFormat = exports.ShortcutUnderline = exports.ShortcutItalic = exports.ShortcutBold = void 0;
3
+ exports.ShortcutOutdentList = exports.ShortcutIndentList = exports.ShortcutDecreaseFont = exports.ShortcutIncreaseFont = exports.ShortcutNumbering = exports.ShortcutBullet = exports.ShortcutRedoAlt = exports.ShortcutRedoMacOS = exports.ShortcutRedo = exports.ShortcutUndo2 = exports.ShortcutUndo = exports.ShortcutClearFormat = exports.ShortcutUnderline = exports.ShortcutItalic = exports.ShortcutBold = void 0;
4
4
  var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
5
  var setShortcutIndentationCommand_1 = require("./utils/setShortcutIndentationCommand");
6
6
  var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
@@ -114,6 +114,7 @@ exports.ShortcutRedo = {
114
114
  environment: 'nonMac',
115
115
  };
116
116
  /**
117
+ * @deprecated
117
118
  * Shortcut command for Redo 2
118
119
  * Windows: N/A
119
120
  * MacOS: Meta + Shift + Z
@@ -127,6 +128,19 @@ exports.ShortcutRedoMacOS = {
127
128
  onClick: function (editor) { return (0, roosterjs_content_model_core_1.redo)(editor); },
128
129
  environment: 'mac',
129
130
  };
131
+ /**
132
+ * Shortcut command for Redo 3
133
+ * Windows: Ctrl + Shift + Z
134
+ * MacOS: Meta + Shift + Z
135
+ */
136
+ exports.ShortcutRedoAlt = {
137
+ shortcutKey: {
138
+ modifierKey: 'ctrl',
139
+ shiftKey: true,
140
+ which: 90 /* Z */,
141
+ },
142
+ onClick: function (editor) { return (0, roosterjs_content_model_core_1.redo)(editor); },
143
+ };
130
144
  /**
131
145
  * Shortcut command for Bullet List
132
146
  * Windows: Ctrl + . (Period)
@@ -1 +1 @@
1
- {"version":3,"file":"shortcuts.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts"],"names":[],"mappings":";;;AAAA,6EAA0D;AAC1D,uFAAsF;AACtF,2EAQqC;AAGrC,IAAW,IAaV;AAbD,WAAW,IAAI;IACX,yCAAa,CAAA;IACb,kCAAU,CAAA;IACV,0BAAM,CAAA;IACN,0BAAM,CAAA;IACN,0BAAM,CAAA;IACN,0BAAM,CAAA;IACN,0BAAM,CAAA;IACN,mCAAW,CAAA;IACX,qCAAY,CAAA;IACZ,mDAAmB,CAAA;IACnB,4CAAe,CAAA;IACf,0CAAc,CAAA;AAClB,CAAC,EAbU,IAAI,KAAJ,IAAI,QAad;AAED;;;;GAIG;AACU,QAAA,YAAY,GAAoB;IACzC,WAAW,EAAE;QACT,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,KAAK;QACf,KAAK,YAAQ;KAChB;IACD,OAAO,EAAE,UAAA,MAAM,IAAI,OAAA,IAAA,wCAAU,EAAC,MAAM,CAAC,EAAlB,CAAkB;CACxC,CAAC;AAEF;;;;GAIG;AACU,QAAA,cAAc,GAAoB;IAC3C,WAAW,EAAE;QACT,WAAW,EAAE,MAAM;QACnB,QAAQ,EAAE,KAAK;QACf,KAAK,YAAQ;KAChB;IACD,OAAO,EAAE,UAAA,MAAM,IAAI,OAAA,IAAA,0CAAY,EAAC,MAAM,CAAC,EAApB,CAAoB;CAC1C,CAAC;AAEF;;;;GAIG;AACU,QAAA,iBAAiB,GAAoB;IAC9C,WAAW,EAAE;QACT,WAAW,EAAE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AI;QACd,KAAK,qBAAiB;KACzB;IACD,OAAO,EAAE,UAAA,MAAM;QACX,IAAA,6DAA6B,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IACD,WAAW,EAAE,QAAQ;CACxB,CAAC;AAEF;;;;GAIG;AACU,QAAA,mBAAmB,GAAoB;IAChD,WAAW,EAAE;QACT,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,IAAI;QACd,KAAK,oBAAgB;KACxB;IACD,OAAO,EAAE,UAAA,MAAM;QACX,IAAA,6DAA6B,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;IACD,WAAW,EAAE,QAAQ;CACxB,CAAC","sourcesContent":["import { redo, undo } from 'roosterjs-content-model-core';\nimport { setShortcutIndentationCommand } from './utils/setShortcutIndentationCommand';\nimport {\n changeFontSize,\n clearFormat,\n toggleBold,\n toggleBullet,\n toggleItalic,\n toggleNumbering,\n toggleUnderline,\n} from 'roosterjs-content-model-api';\nimport type { ShortcutCommand } from './ShortcutCommand';\n\nconst enum Keys {\n BACKSPACE = 8,\n SPACE = 32,\n B = 66,\n I = 73,\n U = 85,\n Y = 89,\n Z = 90,\n COMMA = 188,\n PERIOD = 190,\n FORWARD_SLASH = 191,\n ArrowRight = 39,\n ArrowLeft = 37,\n}\n\n/**\n * Shortcut command for Bold\n * Windows: Ctrl + B\n * MacOS: Meta + B\n */\nexport const ShortcutBold: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.B,\n },\n onClick: editor => toggleBold(editor),\n};\n\n/**\n * Shortcut command for Italic\n * Windows: Ctrl + I\n * MacOS: Meta + I\n */\nexport const ShortcutItalic: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.I,\n },\n onClick: editor => toggleItalic(editor),\n};\n\n/**\n * Shortcut command for Underline\n * Windows: Ctrl + U\n * MacOS: Meta + U\n */\nexport const ShortcutUnderline: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.U,\n },\n onClick: editor => toggleUnderline(editor),\n};\n\n/**\n * Shortcut command for Clear Format\n * Windows: Ctrl + Space\n * MacOS: N/A\n */\nexport const ShortcutClearFormat: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.SPACE,\n },\n onClick: editor => clearFormat(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Undo 1\n * Windows: Ctrl + Z\n * MacOS: Meta + Z\n */\nexport const ShortcutUndo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Z,\n },\n onClick: editor => undo(editor),\n};\n\n/**\n * Shortcut command for Undo 2\n * Windows: Alt + Backspace\n * MacOS: N/A\n */\nexport const ShortcutUndo2: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: false,\n which: Keys.BACKSPACE,\n },\n onClick: editor => undo(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Redo 1\n * Windows: Ctrl + Y\n * MacOS: N/A\n */\nexport const ShortcutRedo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Y,\n },\n onClick: editor => redo(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Redo 2\n * Windows: N/A\n * MacOS: Meta + Shift + Z\n */\nexport const ShortcutRedoMacOS: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.Z,\n },\n onClick: editor => redo(editor),\n environment: 'mac',\n};\n\n/**\n * Shortcut command for Bullet List\n * Windows: Ctrl + . (Period)\n * MacOS: Meta + . (Period)\n */\nexport const ShortcutBullet: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.PERIOD,\n },\n onClick: editor => toggleBullet(editor),\n};\n\n/**\n * Shortcut command for Numbering List\n * Windows: Ctrl + / (Forward slash)\n * MacOS: Meta + / (Forward slash)\n */\nexport const ShortcutNumbering: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.FORWARD_SLASH,\n },\n onClick: editor => toggleNumbering(editor),\n};\n\n/**\n * Shortcut command for Increase Font\n * Windows: Ctrl + Shift + . (Period)\n * MacOS: Meta + Shift + . (Period)\n */\nexport const ShortcutIncreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.PERIOD,\n },\n onClick: editor => changeFontSize(editor, 'increase'),\n};\n\n/**\n * Shortcut command for Decrease Font\n * Windows: Ctrl + Shift + , (Comma)\n * MacOS: Meta + Shift + , (Comma)\n */\nexport const ShortcutDecreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.COMMA,\n },\n onClick: editor => changeFontSize(editor, 'decrease'),\n};\n\n/**\n * Shortcut command for Intent list\n * Windows: Alt + Shift + Arrow Right\n * MacOS: N/A\n */\nexport const ShortcutIndentList: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: true,\n which: Keys.ArrowRight,\n },\n onClick: editor => {\n setShortcutIndentationCommand(editor, 'indent');\n },\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Outdent list\n * Windows: Alt + Shift + Arrow Left\n * MacOS: N/A\n */\nexport const ShortcutOutdentList: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: true,\n which: Keys.ArrowLeft,\n },\n onClick: editor => {\n setShortcutIndentationCommand(editor, 'outdent');\n },\n environment: 'nonMac',\n};\n"]}
1
+ {"version":3,"file":"shortcuts.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/shortcut/shortcuts.ts"],"names":[],"mappings":";;;AAAA,6EAA0D;AAC1D,uFAAsF;AACtF,2EAQqC;AAGrC,IAAW,IAaV;AAbD,W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B,GAAoB;IAChD,WAAW,EAAE;QACT,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,IAAI;QACd,KAAK,oBAAgB;KACxB;IACD,OAAO,EAAE,UAAA,MAAM;QACX,IAAA,6DAA6B,EAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;IACD,WAAW,EAAE,QAAQ;CACxB,CAAC","sourcesContent":["import { redo, undo } from 'roosterjs-content-model-core';\nimport { setShortcutIndentationCommand } from './utils/setShortcutIndentationCommand';\nimport {\n changeFontSize,\n clearFormat,\n toggleBold,\n toggleBullet,\n toggleItalic,\n toggleNumbering,\n toggleUnderline,\n} from 'roosterjs-content-model-api';\nimport type { ShortcutCommand } from './ShortcutCommand';\n\nconst enum Keys {\n BACKSPACE = 8,\n SPACE = 32,\n B = 66,\n I = 73,\n U = 85,\n Y = 89,\n Z = 90,\n COMMA = 188,\n PERIOD = 190,\n FORWARD_SLASH = 191,\n ArrowRight = 39,\n ArrowLeft = 37,\n}\n\n/**\n * Shortcut command for Bold\n * Windows: Ctrl + B\n * MacOS: Meta + B\n */\nexport const ShortcutBold: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.B,\n },\n onClick: editor => toggleBold(editor),\n};\n\n/**\n * Shortcut command for Italic\n * Windows: Ctrl + I\n * MacOS: Meta + I\n */\nexport const ShortcutItalic: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.I,\n },\n onClick: editor => toggleItalic(editor),\n};\n\n/**\n * Shortcut command for Underline\n * Windows: Ctrl + U\n * MacOS: Meta + U\n */\nexport const ShortcutUnderline: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.U,\n },\n onClick: editor => toggleUnderline(editor),\n};\n\n/**\n * Shortcut command for Clear Format\n * Windows: Ctrl + Space\n * MacOS: N/A\n */\nexport const ShortcutClearFormat: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.SPACE,\n },\n onClick: editor => clearFormat(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Undo 1\n * Windows: Ctrl + Z\n * MacOS: Meta + Z\n */\nexport const ShortcutUndo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Z,\n },\n onClick: editor => undo(editor),\n};\n\n/**\n * Shortcut command for Undo 2\n * Windows: Alt + Backspace\n * MacOS: N/A\n */\nexport const ShortcutUndo2: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: false,\n which: Keys.BACKSPACE,\n },\n onClick: editor => undo(editor),\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Redo 1\n * Windows: Ctrl + Y\n * MacOS: N/A\n */\nexport const ShortcutRedo: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.Y,\n },\n onClick: editor => redo(editor),\n environment: 'nonMac',\n};\n\n/**\n * @deprecated\n * Shortcut command for Redo 2\n * Windows: N/A\n * MacOS: Meta + Shift + Z\n */\nexport const ShortcutRedoMacOS: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.Z,\n },\n onClick: editor => redo(editor),\n environment: 'mac',\n};\n\n/**\n * Shortcut command for Redo 3\n * Windows: Ctrl + Shift + Z\n * MacOS: Meta + Shift + Z\n */\nexport const ShortcutRedoAlt: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.Z,\n },\n onClick: editor => redo(editor),\n};\n\n/**\n * Shortcut command for Bullet List\n * Windows: Ctrl + . (Period)\n * MacOS: Meta + . (Period)\n */\nexport const ShortcutBullet: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.PERIOD,\n },\n onClick: editor => toggleBullet(editor),\n};\n\n/**\n * Shortcut command for Numbering List\n * Windows: Ctrl + / (Forward slash)\n * MacOS: Meta + / (Forward slash)\n */\nexport const ShortcutNumbering: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: false,\n which: Keys.FORWARD_SLASH,\n },\n onClick: editor => toggleNumbering(editor),\n};\n\n/**\n * Shortcut command for Increase Font\n * Windows: Ctrl + Shift + . (Period)\n * MacOS: Meta + Shift + . (Period)\n */\nexport const ShortcutIncreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.PERIOD,\n },\n onClick: editor => changeFontSize(editor, 'increase'),\n};\n\n/**\n * Shortcut command for Decrease Font\n * Windows: Ctrl + Shift + , (Comma)\n * MacOS: Meta + Shift + , (Comma)\n */\nexport const ShortcutDecreaseFont: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'ctrl',\n shiftKey: true,\n which: Keys.COMMA,\n },\n onClick: editor => changeFontSize(editor, 'decrease'),\n};\n\n/**\n * Shortcut command for Intent list\n * Windows: Alt + Shift + Arrow Right\n * MacOS: N/A\n */\nexport const ShortcutIndentList: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: true,\n which: Keys.ArrowRight,\n },\n onClick: editor => {\n setShortcutIndentationCommand(editor, 'indent');\n },\n environment: 'nonMac',\n};\n\n/**\n * Shortcut command for Outdent list\n * Windows: Alt + Shift + Arrow Left\n * MacOS: N/A\n */\nexport const ShortcutOutdentList: ShortcutCommand = {\n shortcutKey: {\n modifierKey: 'alt',\n shiftKey: true,\n which: Keys.ArrowLeft,\n },\n onClick: editor => {\n setShortcutIndentationCommand(editor, 'outdent');\n },\n environment: 'nonMac',\n};\n"]}
@@ -7,12 +7,12 @@ var roosterjs_content_model_api_1 = require("roosterjs-content-model-api");
7
7
  * @internal
8
8
  */
9
9
  function setShortcutIndentationCommand(editor, operation) {
10
- editor.formatContentModel(function (model) {
10
+ editor.formatContentModel(function (model, context) {
11
11
  var listItem = (0, roosterjs_content_model_dom_1.getFirstSelectedListItem)(model);
12
12
  if (listItem &&
13
13
  listItem.blocks[0].blockType == 'Paragraph' &&
14
14
  listItem.blocks[0].segments[0].segmentType == 'SelectionMarker') {
15
- (0, roosterjs_content_model_api_1.setModelIndentation)(model, operation);
15
+ (0, roosterjs_content_model_api_1.setModelIndentation)(model, operation, undefined /*length*/, context);
16
16
  return true;
17
17
  }
18
18
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"setShortcutIndentationCommand.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/shortcut/utils/setShortcutIndentationCommand.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,2EAAkE;AAGlE;;GAEG;AACH,SAAgB,6BAA6B,CAAC,MAAe,EAAE,SAA+B;IAC1F,MAAM,CAAC,kBAAkB,CAAC,UAAA,KAAK;QAC3B,IAAM,QAAQ,GAAG,IAAA,sDAAwB,EAAC,KAAK,CAAC,CAAC;QAEjD,IACI,QAAQ;YACR,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,WAAW;YAC3C,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EACjE;YACE,IAAA,iDAAmB,EAAC,KAAK,EAAE,SAAS,CAAC,CAAC;YACtC,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,sEAcC","sourcesContent":["import { getFirstSelectedListItem } from 'roosterjs-content-model-dom';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setShortcutIndentationCommand(editor: IEditor, operation: 'indent' | 'outdent') {\n editor.formatContentModel(model => {\n const listItem = getFirstSelectedListItem(model);\n\n if (\n listItem &&\n listItem.blocks[0].blockType == 'Paragraph' &&\n listItem.blocks[0].segments[0].segmentType == 'SelectionMarker'\n ) {\n setModelIndentation(model, operation);\n return true;\n }\n return false;\n });\n}\n"]}
1
+ {"version":3,"file":"setShortcutIndentationCommand.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/shortcut/utils/setShortcutIndentationCommand.ts"],"names":[],"mappings":";;;AAAA,2EAAuE;AACvE,2EAAkE;AAGlE;;GAEG;AACH,SAAgB,6BAA6B,CAAC,MAAe,EAAE,SAA+B;IAC1F,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;QACrC,IAAM,QAAQ,GAAG,IAAA,sDAAwB,EAAC,KAAK,CAAC,CAAC;QAEjD,IACI,QAAQ;YACR,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,WAAW;YAC3C,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EACjE;YACE,IAAA,iDAAmB,EAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YACrE,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,sEAcC","sourcesContent":["import { getFirstSelectedListItem } from 'roosterjs-content-model-dom';\nimport { setModelIndentation } from 'roosterjs-content-model-api';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setShortcutIndentationCommand(editor: IEditor, operation: 'indent' | 'outdent') {\n editor.formatContentModel((model, context) => {\n const listItem = getFirstSelectedListItem(model);\n\n if (\n listItem &&\n listItem.blocks[0].blockType == 'Paragraph' &&\n listItem.blocks[0].segments[0].segmentType == 'SelectionMarker'\n ) {\n setModelIndentation(model, operation, undefined /*length*/, context);\n return true;\n }\n return false;\n });\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';
2
+ /**
3
+ * Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.
4
+ */
5
+ export declare type OnTableEditorCreatedCallback = (featureType: TableEditFeatureName, element: HTMLElement) => () => void;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=OnTableEditorCreatedCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OnTableEditorCreatedCallback.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/OnTableEditorCreatedCallback.ts"],"names":[],"mappings":"","sourcesContent":["import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';\n\n/**\n * Optional callback when creating a TableEditPlugin, allows to customize the Selectors element as required.\n */\nexport type OnTableEditorCreatedCallback = (\n featureType: TableEditFeatureName,\n element: HTMLElement\n) => () => void;\n"]}
@@ -1,9 +1,13 @@
1
+ import type { TableEditFeatureName } from './editors/features/TableEditFeatureName';
2
+ import type { OnTableEditorCreatedCallback } from './OnTableEditorCreatedCallback';
1
3
  import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
2
4
  /**
3
5
  * TableEdit plugin, provides the ability to resize a table by drag-and-drop
4
6
  */
5
7
  export declare class TableEditPlugin implements EditorPlugin {
6
8
  private anchorContainerSelector?;
9
+ private onTableEditorCreated?;
10
+ private disableFeatures?;
7
11
  private editor;
8
12
  private onMouseMoveDisposer;
9
13
  private tableRectMap;
@@ -13,8 +17,10 @@ export declare class TableEditPlugin implements EditorPlugin {
13
17
  * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.
14
18
  * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
15
19
  * If not specified, the plugin will be inserted in document.body
20
+ * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.
21
+ * @param disableFeatures An optional array of TableEditFeatures to disable
16
22
  */
17
- constructor(anchorContainerSelector?: string | undefined);
23
+ constructor(anchorContainerSelector?: string | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined, disableFeatures?: TableEditFeatureName[] | undefined);
18
24
  /**
19
25
  * Get a friendly name of this plugin
20
26
  */
@@ -13,10 +13,14 @@ var TableEditPlugin = /** @class */ (function () {
13
13
  * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.
14
14
  * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.
15
15
  * If not specified, the plugin will be inserted in document.body
16
+ * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.
17
+ * @param disableFeatures An optional array of TableEditFeatures to disable
16
18
  */
17
- function TableEditPlugin(anchorContainerSelector) {
19
+ function TableEditPlugin(anchorContainerSelector, onTableEditorCreated, disableFeatures) {
18
20
  var _this = this;
19
21
  this.anchorContainerSelector = anchorContainerSelector;
22
+ this.onTableEditorCreated = onTableEditorCreated;
23
+ this.disableFeatures = disableFeatures;
20
24
  this.editor = null;
21
25
  this.onMouseMoveDisposer = null;
22
26
  this.tableRectMap = null;
@@ -94,6 +98,7 @@ var TableEditPlugin = /** @class */ (function () {
94
98
  this.disposeTableEditor();
95
99
  this.editor = null;
96
100
  this.onMouseMoveDisposer = null;
101
+ this.onTableEditorCreated = undefined;
97
102
  };
98
103
  /**
99
104
  * Handle events triggered from editor
@@ -124,7 +129,7 @@ var TableEditPlugin = /** @class */ (function () {
124
129
  var container = this.anchorContainerSelector
125
130
  ? this.editor.getDocument().querySelector(this.anchorContainerSelector)
126
131
  : undefined;
127
- this.tableEditor = new TableEditor_1.TableEditor(this.editor, table, this.invalidateTableRects, (0, roosterjs_content_model_dom_1.isNodeOfType)(container, 'ELEMENT_NODE') ? container : undefined, event === null || event === void 0 ? void 0 : event.currentTarget);
132
+ this.tableEditor = new TableEditor_1.TableEditor(this.editor, table, this.invalidateTableRects, (0, roosterjs_content_model_dom_1.isNodeOfType)(container, 'ELEMENT_NODE') ? container : undefined, event === null || event === void 0 ? void 0 : event.currentTarget, this.onTableEditorCreated, this.disableFeatures);
128
133
  }
129
134
  };
130
135
  TableEditPlugin.prototype.disposeTableEditor = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"TableEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/TableEditPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAC1E,qDAAoD;AAGpD,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;GAEG;AACH;IAMI;;;;;OAKG;IACH,yBAAoB,uBAAgC;QAApD,iBAAwD;QAApC,4BAAuB,GAAvB,uBAAuB,CAAS;QAX5C,WAAM,GAAmB,IAAI,CAAC;QAC9B,wBAAmB,GAAwB,IAAI,CAAC;QAChD,iBAAY,GAAqD,IAAI,CAAC;QACtE,gBAAW,GAAuB,IAAI,CAAC;QA8BvC,eAAU,GAAG,UAAC,EAA4C;gBAA1C,aAAa,mBAAA,EAAE,aAAa,mBAAA;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IACI,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,KAAI,CAAC,WAAW;gBAChB,CAAC,KAAI,CAAC,WAAW,CAAC,cAAc,CAAC,iBAAiB,CAAC;gBACnD,CAAC,iBAAiB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAChD;gBACE,KAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aAC7B;QACL,CAAC,CAAC;QA+BM,gBAAW,GAAG,UAAC,KAAY;;YAC/B,IAAM,CAAC,GAAG,KAAmB,CAAC;YAE9B,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,KAAI,CAAC,MAAM,EAAE;gBAC/B,OAAO;aACV;YAED,KAAI,CAAC,gBAAgB,EAAE,CAAC;YAExB,IAAM,YAAY,GAAG,KAAI,CAAC,MAAM,CAAC,WAAW,E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4BACnB,KAAK,OAAA;4BACL,IAAI,MAAA;yBACP,CAAC,CAAC;qBACN;iBACJ;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AArKD,IAqKC;AArKY,0CAAe","sourcesContent":["import { isNodeOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport { TableEditor } from './editors/TableEditor';\nimport type { EditorPlugin, IEditor, PluginEvent, Rect } from 'roosterjs-content-model-types';\n\nconst TABLE_RESIZER_LENGTH = 12;\n\n/**\n * TableEdit plugin, provides the ability to resize a table by drag-and-drop\n */\nexport class TableEditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private onMouseMoveDisposer: (() => void) | null = null;\n private tableRectMap: { table: HTMLTableElement; rect: Rect }[] | null = null;\n private tableEditor: TableEditor | null = null;\n\n /**\n * Construct a new instance of TableResize plugin\n * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.\n * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.\n * If not specified, the plugin will be inserted in document.body\n */\n constructor(private anchorContainerSelector?: string) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'TableEdit';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.onMouseMoveDisposer = this.editor.attachDomEvent({\n mousemove: { beforeDispatch: this.onMouseMove },\n });\n const scrollContainer = this.editor.getScrollContainer();\n scrollContainer.addEventListener('mouseout', this.onMouseOut);\n }\n\n private onMouseOut = ({ relatedTarget, currentTarget }: MouseEvent) => {\n const relatedTargetNode = relatedTarget as Node;\n const currentTargetNode = currentTarget as Node;\n if (\n isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&\n isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&\n this.tableEditor &&\n !this.tableEditor.isOwnedElement(relatedTargetNode) &&\n !currentTargetNode.contains(relatedTargetNode)\n ) {\n this.setTableEditor(null);\n }\n };\n\n /**\n * Dispose this plugin\n */\n dispose() {\n const scrollContainer = this.editor?.getScrollContainer();\n scrollContainer?.removeEventListener('mouseout', this.onMouseOut);\n this.onMouseMoveDisposer?.();\n this.invalidateTableRects();\n this.disposeTableEditor();\n this.editor = null;\n this.onMouseMoveDisposer = null;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(e: PluginEvent) {\n switch (e.eventType) {\n case 'input':\n case 'contentChanged':\n case 'scroll':\n case 'zoomChanged':\n this.setTableEditor(null);\n this.invalidateTableRects();\n break;\n }\n }\n\n private onMouseMove = (event: Event) => {\n const e = event as MouseEvent;\n\n if (e.buttons > 0 || !this.editor) {\n return;\n }\n\n this.ensureTableRects();\n\n const editorWindow = this.editor.getDocument().defaultView || window;\n const x = e.pageX - editorWindow.scrollX;\n const y = e.pageY - editorWindow.scrollY;\n let currentTable: HTMLTableElement | null = null;\n\n //Find table in range of mouse\n if (this.tableRectMap) {\n for (let i = this.tableRectMap.length - 1; i >= 0; i--) {\n const { table, rect } = this.tableRectMap[i];\n\n if (\n x >= rect.left - TABLE_RESIZER_LENGTH &&\n x <= rect.right + TABLE_RESIZER_LENGTH &&\n y >= rect.top - TABLE_RESIZER_LENGTH &&\n y <= rect.bottom + TABLE_RESIZER_LENGTH\n ) {\n currentTable = table;\n break;\n }\n }\n }\n\n this.setTableEditor(currentTable, e);\n this.tableEditor?.onMouseMove(x, y);\n };\n\n /**\n * @internal Public only for unit test\n * @param table Table to use when setting the Editors\n * @param event (Optional) Mouse event\n */\n public setTableEditor(table: HTMLTableElement | null, event?: MouseEvent) {\n if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {\n this.disposeTableEditor();\n }\n\n if (!this.tableEditor && table && this.editor && table.rows.length > 0) {\n // anchorContainerSelector is used to specify the container to host the plugin, which can be outside of the editor's div\n const container = this.anchorContainerSelector\n ? this.editor.getDocument().querySelector(this.anchorContainerSelector)\n : undefined;\n\n this.tableEditor = new TableEditor(\n this.editor,\n table,\n this.invalidateTableRects,\n isNodeOfType(container, 'ELEMENT_NODE') ? container : undefined,\n event?.currentTarget\n );\n }\n }\n\n private invalidateTableRects = () => {\n this.tableRectMap = null;\n };\n\n private disposeTableEditor() {\n this.tableEditor?.dispose();\n this.tableEditor = null;\n }\n\n private ensureTableRects() {\n if (!this.tableRectMap && this.editor) {\n this.tableRectMap = [];\n\n const tables = this.editor.getDOMHelper().queryElements('table');\n tables.forEach(table => {\n if (table.isContentEditable) {\n const rect = normalizeRect(table.getBoundingClientRect());\n if (rect && this.tableRectMap) {\n this.tableRectMap.push({\n table,\n rect,\n });\n }\n }\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"TableEditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/tableEdit/TableEditPlugin.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAC1E,qDAAoD;AAKpD,IAAM,oBAAoB,GAAG,EAAE,CAAC;AAEhC;;GAEG;AACH;IAMI;;;;;;;OAOG;IACH,yBACY,uBAAgC,EAChC,oBAAmD,EACnD,eAAwC;QAHpD,iBAII;QAHQ,4BAAuB,GAAvB,uBAAuB,CAAS;QAChC,yBAAoB,GAApB,oBAAoB,CAA+B;QACnD,oBAAe,GAAf,eAAe,CAAyB;QAhB5C,WAAM,GAAmB,IAAI,CAAC;QAC9B,wBAAmB,GAAwB,IAAI,CAAC;QAChD,iBAAY,GAAqD,IAAI,CAAC;QACtE,gBAAW,GAAuB,IAAI,CAAC;QAoCvC,eAAU,GAAG,UAAC,EAA4C;gBAA1C,aAAa,mBAAA,EAAE,aAAa,mBAAA;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IAAM,iBAAiB,GAAG,aAAqB,CAAC;YAChD,IACI,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,IAAA,0CAAY,EAAC,iBAAiB,EAAE,cAAc,CAAC;gBAC/C,KAAI,CAAC,WAAW;gBAChB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AAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAEO,0CAAgB,GAAxB;QAAA,iBAiBC;QAhBG,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,EAAE;YACnC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;YAEvB,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YACjE,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;gBAChB,IAAI,KAAK,CAAC,iBAAiB,EAAE;oBACzB,IAAM,IAAI,GAAG,IAAA,2CAAa,EAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC,CAAC;oBAC1D,IAAI,IAAI,IAAI,KAAI,CAAC,YAAY,EAAE;wBAC3B,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC;4BACnB,KAAK,OAAA;4BACL,IAAI,MAAA;yBACP,CAAC,CAAC;qBACN;iBACJ;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,sBAAC;AAAD,CAAC,AA9KD,IA8KC;AA9KY,0CAAe","sourcesContent":["import { isNodeOfType, normalizeRect } from 'roosterjs-content-model-dom';\nimport { TableEditor } from './editors/TableEditor';\nimport type { TableEditFeatureName } from './editors/features/TableEditFeatureName';\nimport type { OnTableEditorCreatedCallback } from './OnTableEditorCreatedCallback';\nimport type { EditorPlugin, IEditor, PluginEvent, Rect } from 'roosterjs-content-model-types';\n\nconst TABLE_RESIZER_LENGTH = 12;\n\n/**\n * TableEdit plugin, provides the ability to resize a table by drag-and-drop\n */\nexport class TableEditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private onMouseMoveDisposer: (() => void) | null = null;\n private tableRectMap: { table: HTMLTableElement; rect: Rect }[] | null = null;\n private tableEditor: TableEditor | null = null;\n\n /**\n * Construct a new instance of TableResize plugin\n * @param anchorContainerSelector An optional selector string to specify the container to host the plugin.\n * The container must not be affected by transform: scale(), otherwise the position calculation will be wrong.\n * If not specified, the plugin will be inserted in document.body\n * @param onTableEditorCreated An optional callback to customize the Table Editors elements when created.\n * @param disableFeatures An optional array of TableEditFeatures to disable\n */\n constructor(\n private anchorContainerSelector?: string,\n private onTableEditorCreated?: OnTableEditorCreatedCallback,\n private disableFeatures?: TableEditFeatureName[]\n ) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'TableEdit';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n this.onMouseMoveDisposer = this.editor.attachDomEvent({\n mousemove: { beforeDispatch: this.onMouseMove },\n });\n const scrollContainer = this.editor.getScrollContainer();\n scrollContainer.addEventListener('mouseout', this.onMouseOut);\n }\n\n private onMouseOut = ({ relatedTarget, currentTarget }: MouseEvent) => {\n const relatedTargetNode = relatedTarget as Node;\n const currentTargetNode = currentTarget as Node;\n if (\n isNodeOfType(relatedTargetNode, 'ELEMENT_NODE') &&\n isNodeOfType(currentTargetNode, 'ELEMENT_NODE') &&\n this.tableEditor &&\n !this.tableEditor.isOwnedElement(relatedTargetNode) &&\n !currentTargetNode.contains(relatedTargetNode)\n ) {\n this.setTableEditor(null);\n }\n };\n\n /**\n * Dispose this plugin\n */\n dispose() {\n const scrollContainer = this.editor?.getScrollContainer();\n scrollContainer?.removeEventListener('mouseout', this.onMouseOut);\n this.onMouseMoveDisposer?.();\n this.invalidateTableRects();\n this.disposeTableEditor();\n this.editor = null;\n this.onMouseMoveDisposer = null;\n this.onTableEditorCreated = undefined;\n }\n\n /**\n * Handle events triggered from editor\n * @param event PluginEvent object\n */\n onPluginEvent(e: PluginEvent) {\n switch (e.eventType) {\n case 'input':\n case 'contentChanged':\n case 'scroll':\n case 'zoomChanged':\n this.setTableEditor(null);\n this.invalidateTableRects();\n break;\n }\n }\n\n private onMouseMove = (event: Event) => {\n const e = event as MouseEvent;\n\n if (e.buttons > 0 || !this.editor) {\n return;\n }\n\n this.ensureTableRects();\n\n const editorWindow = this.editor.getDocument().defaultView || window;\n const x = e.pageX - editorWindow.scrollX;\n const y = e.pageY - editorWindow.scrollY;\n let currentTable: HTMLTableElement | null = null;\n\n //Find table in range of mouse\n if (this.tableRectMap) {\n for (let i = this.tableRectMap.length - 1; i >= 0; i--) {\n const { table, rect } = this.tableRectMap[i];\n\n if (\n x >= rect.left - TABLE_RESIZER_LENGTH &&\n x <= rect.right + TABLE_RESIZER_LENGTH &&\n y >= rect.top - TABLE_RESIZER_LENGTH &&\n y <= rect.bottom + TABLE_RESIZER_LENGTH\n ) {\n currentTable = table;\n break;\n }\n }\n }\n\n this.setTableEditor(currentTable, e);\n this.tableEditor?.onMouseMove(x, y);\n };\n\n /**\n * @internal Public only for unit test\n * @param table Table to use when setting the Editors\n * @param event (Optional) Mouse event\n */\n public setTableEditor(table: HTMLTableElement | null, event?: MouseEvent) {\n if (this.tableEditor && !this.tableEditor.isEditing() && table != this.tableEditor.table) {\n this.disposeTableEditor();\n }\n\n if (!this.tableEditor && table && this.editor && table.rows.length > 0) {\n // anchorContainerSelector is used to specify the container to host the plugin, which can be outside of the editor's div\n const container = this.anchorContainerSelector\n ? this.editor.getDocument().querySelector(this.anchorContainerSelector)\n : undefined;\n\n this.tableEditor = new TableEditor(\n this.editor,\n table,\n this.invalidateTableRects,\n isNodeOfType(container, 'ELEMENT_NODE') ? container : undefined,\n event?.currentTarget,\n this.onTableEditorCreated,\n this.disableFeatures\n );\n }\n }\n\n private invalidateTableRects = () => {\n this.tableRectMap = null;\n };\n\n private disposeTableEditor() {\n this.tableEditor?.dispose();\n this.tableEditor = null;\n }\n\n private ensureTableRects() {\n if (!this.tableRectMap && this.editor) {\n this.tableRectMap = [];\n\n const tables = this.editor.getDOMHelper().queryElements('table');\n tables.forEach(table => {\n if (table.isContentEditable) {\n const rect = normalizeRect(table.getBoundingClientRect());\n if (rect && this.tableRectMap) {\n this.tableRectMap.push({\n table,\n rect,\n });\n }\n }\n });\n }\n }\n}\n"]}
@@ -1,4 +1,6 @@
1
+ import type { OnTableEditorCreatedCallback } from '../OnTableEditorCreatedCallback';
1
2
  import type { IEditor } from 'roosterjs-content-model-types';
3
+ import type { TableEditFeatureName } from './features/TableEditFeatureName';
2
4
  /**
3
5
  * @internal
4
6
  *
@@ -34,6 +36,8 @@ export declare class TableEditor {
34
36
  private onChanged;
35
37
  private anchorContainer?;
36
38
  private contentDiv?;
39
+ private onTableEditorCreated?;
40
+ private disableFeatures?;
37
41
  private horizontalInserter;
38
42
  private verticalInserter;
39
43
  private horizontalResizer;
@@ -43,12 +47,13 @@ export declare class TableEditor {
43
47
  private isRTL;
44
48
  private range;
45
49
  private isCurrentlyEditing;
46
- constructor(editor: IEditor, table: HTMLTableElement, onChanged: () => void, anchorContainer?: HTMLElement | undefined, contentDiv?: EventTarget | null | undefined);
50
+ constructor(editor: IEditor, table: HTMLTableElement, onChanged: () => void, anchorContainer?: HTMLElement | undefined, contentDiv?: EventTarget | null | undefined, onTableEditorCreated?: OnTableEditorCreatedCallback | undefined, disableFeatures?: TableEditFeatureName[] | undefined);
47
51
  dispose(): void;
48
52
  isEditing(): boolean;
49
53
  isOwnedElement(node: Node): boolean;
50
54
  onMouseMove(x: number, y: number): void;
51
55
  private setEditorFeatures;
56
+ private onEditorCreated;
52
57
  private setResizingTd;
53
58
  /**
54
59
  * create or remove TableInserter
@@ -62,7 +67,9 @@ export declare class TableEditor {
62
67
  private onFinishEditing;
63
68
  private onStartTableResize;
64
69
  private onStartCellResize;
70
+ private onStartTableMove;
65
71
  private onStartResize;
72
+ private onEndTableMove;
66
73
  private onInserted;
67
74
  /**
68
75
  * Public only for testing purposes
@@ -70,4 +77,5 @@ export declare class TableEditor {
70
77
  */
71
78
  onSelect: (table: HTMLTableElement) => void;
72
79
  private getOnMouseOut;
80
+ private isFeatureDisabled;
73
81
  }
@@ -43,7 +43,7 @@ var TOP_OR_SIDE;
43
43
  * When set a different current table or change current TD, we need to update these areas
44
44
  */
45
45
  var TableEditor = /** @class */ (function () {
46
- function TableEditor(editor, table, onChanged, anchorContainer, contentDiv) {
46
+ function TableEditor(editor, table, onChanged, anchorContainer, contentDiv, onTableEditorCreated, disableFeatures) {
47
47
  var _this = this;
48
48
  var _a;
49
49
  this.editor = editor;
@@ -51,6 +51,8 @@ var TableEditor = /** @class */ (function () {
51
51
  this.onChanged = onChanged;
52
52
  this.anchorContainer = anchorContainer;
53
53
  this.contentDiv = contentDiv;
54
+ this.onTableEditorCreated = onTableEditorCreated;
55
+ this.disableFeatures = disableFeatures;
54
56
  // 1, 2 - Insert a column or a row
55
57
  this.horizontalInserter = null;
56
58
  this.verticalInserter = null;
@@ -62,6 +64,20 @@ var TableEditor = /** @class */ (function () {
62
64
  // 6 - Move as well as select whole table
63
65
  this.tableMover = null;
64
66
  this.range = null;
67
+ this.onEditorCreated = function (featureType, element) {
68
+ var _a;
69
+ var disposer = (_a = _this.onTableEditorCreated) === null || _a === void 0 ? void 0 : _a.call(_this, featureType, element);
70
+ var onMouseOut = element && _this.getOnMouseOut(element);
71
+ if (onMouseOut) {
72
+ element.addEventListener('mouseout', onMouseOut);
73
+ }
74
+ return function () {
75
+ disposer === null || disposer === void 0 ? void 0 : disposer();
76
+ if (onMouseOut) {
77
+ element.removeEventListener('mouseout', onMouseOut);
78
+ }
79
+ };
80
+ };
65
81
  this.onFinishEditing = function () {
66
82
  _this.editor.focus();
67
83
  if (_this.range) {
@@ -81,6 +97,16 @@ var TableEditor = /** @class */ (function () {
81
97
  _this.disposeTableResizer();
82
98
  _this.onStartResize();
83
99
  };
100
+ this.onStartTableMove = function () {
101
+ _this.isCurrentlyEditing = true;
102
+ _this.disposeTableResizer();
103
+ _this.disposeTableInserter();
104
+ _this.disposeCellResizers();
105
+ };
106
+ this.onEndTableMove = function () {
107
+ _this.disposeTableMover();
108
+ return _this.onFinishEditing();
109
+ };
84
110
  this.onInserted = function () {
85
111
  _this.disposeTableResizer();
86
112
  _this.onFinishEditing();
@@ -90,14 +116,16 @@ var TableEditor = /** @class */ (function () {
90
116
  * @param table the table to select
91
117
  */
92
118
  this.onSelect = function (table) {
119
+ var _a, _b;
93
120
  _this.editor.focus();
94
121
  if (table) {
122
+ var parsedTable = (0, roosterjs_content_model_dom_1.parseTableCells)(table);
95
123
  var selection = {
96
124
  table: table,
97
125
  firstRow: 0,
98
126
  firstColumn: 0,
99
- lastRow: table.rows.length - 1,
100
- lastColumn: table.rows[table.rows.length - 1].cells.length - 1,
127
+ lastRow: parsedTable.length - 1,
128
+ lastColumn: ((_b = (_a = parsedTable[0]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1,
101
129
  type: 'table',
102
130
  };
103
131
  _this.editor.setDOMSelection(selection);
@@ -109,7 +137,8 @@ var TableEditor = /** @class */ (function () {
109
137
  ev.relatedTarget != feature &&
110
138
  (0, roosterjs_content_model_dom_1.isNodeOfType)(_this.contentDiv, 'ELEMENT_NODE') &&
111
139
  (0, roosterjs_content_model_dom_1.isNodeOfType)(ev.relatedTarget, 'ELEMENT_NODE') &&
112
- !(_this.contentDiv == ev.relatedTarget)) {
140
+ !(_this.contentDiv == ev.relatedTarget) &&
141
+ !_this.isEditing()) {
113
142
  _this.dispose();
114
143
  }
115
144
  };
@@ -143,7 +172,6 @@ var TableEditor = /** @class */ (function () {
143
172
  var _a;
144
173
  // Get whole table rect
145
174
  var tableRect = (0, roosterjs_content_model_dom_1.normalizeRect)(this.table.getBoundingClientRect());
146
- //console.log('>>>tableRect', tableRect);
147
175
  if (!tableRect) {
148
176
  return;
149
177
  }
@@ -181,7 +209,8 @@ var TableEditor = /** @class */ (function () {
181
209
  if (i === 0 && topOrSide == 0 /* top */) {
182
210
  var center = (tdRect.left + tdRect.right) / 2;
183
211
  var isOnRightHalf = this.isRTL ? x < center : x > center;
184
- this.setInserterTd(isOnRightHalf ? td : tr.cells[j - 1], false /*isHorizontal*/);
212
+ !this.isFeatureDisabled('VerticalTableInserter') &&
213
+ this.setInserterTd(isOnRightHalf ? td : tr.cells[j - 1], false /*isHorizontal*/);
185
214
  }
186
215
  else if (j === 0 && topOrSide == 1 /* side */) {
187
216
  var tdAbove = (_a = this.table.rows[i - 1]) === null || _a === void 0 ? void 0 : _a.cells[0];
@@ -193,14 +222,15 @@ var TableEditor = /** @class */ (function () {
193
222
  : this.isRTL
194
223
  ? tdAboveRect.right === tdRect.right
195
224
  : tdAboveRect.left === tdRect.left;
196
- this.setInserterTd(y < (tdRect.top + tdRect.bottom) / 2 && isTdNotAboveMerged
197
- ? tdAbove
198
- : td, true /*isHorizontal*/);
225
+ !this.isFeatureDisabled('HorizontalTableInserter') &&
226
+ this.setInserterTd(y < (tdRect.top + tdRect.bottom) / 2 && isTdNotAboveMerged
227
+ ? tdAbove
228
+ : td, true /*isHorizontal*/);
199
229
  }
200
230
  else {
201
231
  this.setInserterTd(null);
202
232
  }
203
- this.setResizingTd(td);
233
+ !this.isFeatureDisabled('CellResizer') && this.setResizingTd(td);
204
234
  //Cell found
205
235
  break;
206
236
  }
@@ -213,11 +243,13 @@ var TableEditor = /** @class */ (function () {
213
243
  this.setEditorFeatures();
214
244
  };
215
245
  TableEditor.prototype.setEditorFeatures = function () {
216
- if (!this.tableMover) {
217
- this.tableMover = (0, TableMover_1.createTableMover)(this.table, this.editor, this.isRTL, this.onSelect, this.getOnMouseOut, this.contentDiv, this.anchorContainer);
246
+ var disableSelector = this.isFeatureDisabled('TableSelector');
247
+ var disableMovement = this.isFeatureDisabled('TableMover');
248
+ if (!this.tableMover && !(disableSelector && disableMovement)) {
249
+ this.tableMover = (0, TableMover_1.createTableMover)(this.table, this.editor, this.isRTL, disableSelector ? function () { } : this.onSelect, this.onStartTableMove, this.onEndTableMove, this.contentDiv, this.anchorContainer, this.onEditorCreated, disableMovement);
218
250
  }
219
- if (!this.tableResizer) {
220
- this.tableResizer = (0, TableResizer_1.createTableResizer)(this.table, this.editor, this.isRTL, this.onStartTableResize, this.onFinishEditing, this.contentDiv, this.anchorContainer);
251
+ if (!this.tableResizer && !this.isFeatureDisabled('TableResizer')) {
252
+ this.tableResizer = (0, TableResizer_1.createTableResizer)(this.table, this.editor, this.isRTL, this.onStartTableResize, this.onFinishEditing, this.contentDiv, this.anchorContainer, this.onTableEditorCreated);
221
253
  }
222
254
  };
223
255
  TableEditor.prototype.setResizingTd = function (td) {
@@ -239,7 +271,7 @@ var TableEditor = /** @class */ (function () {
239
271
  this.disposeTableInserter();
240
272
  }
241
273
  if (!this.horizontalInserter && !this.verticalInserter && td) {
242
- var newInserter = (0, TableInserter_1.createTableInserter)(this.editor, td, this.table, this.isRTL, !!isHorizontal, this.onInserted, this.getOnMouseOut, this.anchorContainer);
274
+ var newInserter = (0, TableInserter_1.createTableInserter)(this.editor, td, this.table, this.isRTL, !!isHorizontal, this.onInserted, this.anchorContainer, this.onEditorCreated);
243
275
  if (isHorizontal) {
244
276
  this.horizontalInserter = newInserter;
245
277
  }
@@ -288,6 +320,10 @@ var TableEditor = /** @class */ (function () {
288
320
  }
289
321
  this.editor.takeSnapshot();
290
322
  };
323
+ TableEditor.prototype.isFeatureDisabled = function (feature) {
324
+ var _a;
325
+ return (_a = this.disableFeatures) === null || _a === void 0 ? void 0 : _a.includes(feature);
326
+ };
291
327
  return TableEditor;
292
328
  }());
293
329
  exports.TableEditor = TableEditor;