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
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace", "roosterjs-content-model-api", "./list/keyboardListTrigger", "./hyphen/transformHyphen", "./link/unlink"], function (require, exports, createLink_1, createLinkAfterSpace_1, roosterjs_content_model_api_1, keyboardListTrigger_1, transformHyphen_1, unlink_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom", "./link/createLink", "./link/createLinkAfterSpace", "roosterjs-content-model-api", "./list/keyboardListTrigger", "./numbers/transformFraction", "./hyphen/transformHyphen", "./numbers/transformOrdinals", "./link/unlink"], function (require, exports, roosterjs_content_model_dom_1, createLink_1, createLinkAfterSpace_1, roosterjs_content_model_api_1, keyboardListTrigger_1, transformFraction_1, transformHyphen_1, transformOrdinals_1, unlink_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.AutoFormatPlugin = void 0;
@@ -11,6 +11,8 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
11
11
  autoUnlink: false,
12
12
  autoLink: false,
13
13
  autoHyphen: false,
14
+ autoFraction: false,
15
+ autoOrdinals: false,
14
16
  };
15
17
  /**
16
18
  * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.
@@ -24,6 +26,8 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
24
26
  * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.
25
27
  * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.
26
28
  * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.
29
+ * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.
30
+ * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.
27
31
  */
28
32
  function AutoFormatPlugin(options) {
29
33
  if (options === void 0) { options = DefaultOptions; }
@@ -84,20 +88,40 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
84
88
  selection.range.collapsed) {
85
89
  switch (rawEvent.data) {
86
90
  case ' ':
91
+ var formatOptions_1 = {
92
+ changeSource: '',
93
+ apiName: '',
94
+ };
87
95
  (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, paragraph, _markerFormat, context) {
88
- var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen;
96
+ var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering, autoLink = _a.autoLink, autoHyphen = _a.autoHyphen, autoFraction = _a.autoFraction, autoOrdinals = _a.autoOrdinals;
89
97
  var shouldHyphen = false;
90
98
  var shouldLink = false;
99
+ var shouldList = false;
100
+ var shouldFraction = false;
101
+ var shouldOrdinals = false;
102
+ if (autoBullet || autoNumbering) {
103
+ shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
104
+ }
91
105
  if (autoLink) {
92
106
  shouldLink = (0, createLinkAfterSpace_1.createLinkAfterSpace)(previousSegment, paragraph, context);
93
107
  }
94
108
  if (autoHyphen) {
95
109
  shouldHyphen = (0, transformHyphen_1.transformHyphen)(previousSegment, paragraph, context);
96
110
  }
97
- return ((0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering) ||
111
+ if (autoFraction) {
112
+ shouldFraction = (0, transformFraction_1.transformFraction)(previousSegment, paragraph, context);
113
+ }
114
+ if (autoOrdinals) {
115
+ shouldOrdinals = (0, transformOrdinals_1.transformOrdinals)(previousSegment, paragraph, context);
116
+ }
117
+ formatOptions_1.apiName = getApiName(shouldList, shouldHyphen);
118
+ formatOptions_1.changeSource = getChangeSource(shouldList, shouldHyphen, shouldLink);
119
+ return (shouldList ||
98
120
  shouldHyphen ||
99
- shouldLink);
100
- });
121
+ shouldLink ||
122
+ shouldFraction ||
123
+ shouldOrdinals);
124
+ }, formatOptions_1);
101
125
  break;
102
126
  }
103
127
  }
@@ -123,5 +147,15 @@ define(["require", "exports", "./link/createLink", "./link/createLinkAfterSpace"
123
147
  return AutoFormatPlugin;
124
148
  }());
125
149
  exports.AutoFormatPlugin = AutoFormatPlugin;
150
+ var getApiName = function (shouldList, shouldHyphen) {
151
+ return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';
152
+ };
153
+ var getChangeSource = function (shouldList, shouldHyphen, shouldLink) {
154
+ return shouldList || shouldHyphen
155
+ ? roosterjs_content_model_dom_1.ChangeSource.AutoFormat
156
+ : shouldLink
157
+ ? roosterjs_content_model_dom_1.ChangeSource.AutoLink
158
+ : '';
159
+ };
126
160
  });
127
161
  //# sourceMappingURL=AutoFormatPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;IA6CA;;OAEG;IACH,IAAM,cAAc,GAAgC;QAChD,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;KACpB,CAAC;IAEF;;;OAGG;IACH;QAEI;;;;;;;WAOG;QACH,0BAAoB,OAA2C;YAA3C,wBAAA,EAAA,wBAA2C;YAA3C,YAAO,GAAP,OAAO,CAAoC;YATvD,WAAM,GAAmB,IAAI,CAAC;QAS4B,CAAC;QAEnE;;WAEG;QACH,kCAAO,GAAP;YACI,OAAO,YAAY,CAAC;QACxB,CAAC;QAED;;;;;WAKG;QACH,qCAAU,GAAV,UAAW,MAAe;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;QAED;;;;WAIG;QACH,kCAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,wCAAa,GAAb,UAAc,KAAkB;YAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,KAAK,CAAC,SAAS,EAAE;oBACrB,KAAK,OAAO;wBACR,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBAChD,MAAM;oBACV,KAAK,SAAS;wBACV,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBAC5C,MAAM;oBACV,KAAK,gBAAgB;wBACjB,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;wBACnD,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,iDAAsB,GAA9B,UAA+B,MAAe,EAAE,KAAuB;YAAvE,iBAmDC;YAlDG,IAAM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Z,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;4BACzB,IAAA,eAAM,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;yBAC5B;wBACD,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,oDAAyB,GAAjC,UAAkC,MAAe,EAAE,KAA0B;YACjE,IAAA,QAAQ,GAAK,IAAI,CAAC,OAAO,SAAjB,CAAkB;YAClC,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,QAAQ,EAAE;gBACrC,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAC;aACtB;QACL,CAAC;QACL,uBAAC;IAAD,CAAC,AApID,IAoIC;IApIY,4CAAgB","sourcesContent":["import { createLink } from './link/createLink';\nimport { createLinkAfterSpace } from './link/createLinkAfterSpace';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { unlink } from './link/unlink';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport type AutoFormatOptions = {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true\n */\n autoBullet: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true\n */\n autoNumbering: boolean;\n\n /**\n * When press backspace before a link, remove the hyperlink\n */\n autoUnlink: boolean;\n\n /**\n * When paste content, create hyperlink for the pasted link\n */\n autoLink: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen: boolean;\n};\n\n/**\n * @internal\n */\nconst DefaultOptions: Required<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 * 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) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n\n if (autoLink) {\n shouldLink = createLinkAfterSpace(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n return (\n keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n ) ||\n shouldHyphen ||\n shouldLink\n );\n }\n );\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink } = this.options;\n if (event.source == 'Paste' && autoLink) {\n createLink(editor);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;IA2DA;;OAEG;IACH,IAAM,cAAc,GAA+B;QAC/C,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;KACtB,CAAC;IAEF;;;OAGG;IACH;QAEI;;;;;;;;;WASG;QACH,0BAAoB,OAA2C;YAA3C,wBAAA,EAAA,wBAA2C;YAA3C,YAAO,GAAP,OAAO,CAAoC;YAXvD,WAAM,GAAmB,IAAI,CAAC;QAW4B,CAAC;QAEnE;;WAEG;QACH,kCAAO,GAAP;YACI,OAAO,YAAY,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QAEO,6CAAkB,GAA1B,UAA2B,MAAe,EAAE,KAAmB;YAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAChC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE;gBAC3D,QAAQ,QAAQ,CAAC,GAAG,EAAE;oBAClB,KAAK,WAAW;wBACZ,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;4BACzB,IAAA,eAAM,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;yBAC5B;wBACD,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,oDAAyB,GAAjC,UAAkC,MAAe,EAAE,KAA0B;YACjE,IAAA,QAAQ,GAAK,IAAI,CAAC,OAAO,SAAjB,CAAkB;YAClC,IAAI,KAAK,CAAC,MAAM,IAAI,OAAO,IAAI,QAAQ,EAAE;gBACrC,IAAA,uBAAU,EAAC,MAAM,CAAC,CAAC;aACtB;QACL,CAAC;QACL,uBAAC;IAAD,CAAC,AA9KD,IA8KC;IA9KY,4CAAgB;IAgL7B,IAAM,UAAU,GAAG,UAAC,UAAmB,EAAE,YAAqB;QAC1D,OAAO,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,CAAC,CAAC;IAEF,IAAM,eAAe,GAAG,UAAC,UAAmB,EAAE,YAAqB,EAAE,UAAmB;QACpF,OAAO,UAAU,IAAI,YAAY;YAC7B,CAAC,CAAC,0CAAY,CAAC,UAAU;YACzB,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,0CAAY,CAAC,QAAQ;gBACvB,CAAC,CAAC,EAAE,CAAC;IACb,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { createLink } from './link/createLink';\nimport { createLinkAfterSpace } from './link/createLinkAfterSpace';\nimport { formatTextSegmentBeforeSelectionMarker } from 'roosterjs-content-model-api';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport type {\n ContentChangedEvent,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Options to customize the Content Model Auto Format Plugin\n */\nexport type AutoFormatOptions = {\n /**\n * When true, after type *, ->, -, --, => , —, > and space key a type of bullet list will be triggered. @default true\n */\n autoBullet?: boolean;\n\n /**\n * When true, after type 1, A, a, i, I followed by ., ), - or between () and space key a type of numbering list will be triggered. @default true\n */\n autoNumbering?: boolean;\n\n /**\n * When press backspace before a link, remove the hyperlink\n */\n autoUnlink?: boolean;\n\n /**\n * When paste content, create hyperlink for the pasted link\n */\n autoLink?: boolean;\n\n /**\n * Transform -- into hyphen, if typed between two words\n */\n autoHyphen?: boolean;\n\n /**\n * Transform 1/2, 1/4, 3/4 into fraction character\n */\n autoFraction?: boolean;\n\n /**\n * Transform ordinal numbers into superscript\n */\n autoOrdinals?: boolean;\n};\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\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 }\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 * 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) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n };\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n const {\n autoBullet,\n autoNumbering,\n autoLink,\n autoHyphen,\n autoFraction,\n autoOrdinals,\n } = this.options;\n let shouldHyphen = false;\n let shouldLink = false;\n let shouldList = false;\n let shouldFraction = false;\n let shouldOrdinals = false;\n\n if (autoBullet || autoNumbering) {\n shouldList = keyboardListTrigger(\n model,\n paragraph,\n context,\n autoBullet,\n autoNumbering\n );\n }\n\n if (autoLink) {\n shouldLink = createLinkAfterSpace(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoHyphen) {\n shouldHyphen = transformHyphen(previousSegment, paragraph, context);\n }\n\n if (autoFraction) {\n shouldFraction = transformFraction(\n previousSegment,\n paragraph,\n context\n );\n }\n\n if (autoOrdinals) {\n shouldOrdinals = transformOrdinals(\n previousSegment,\n paragraph,\n context\n );\n }\n\n formatOptions.apiName = getApiName(shouldList, shouldHyphen);\n formatOptions.changeSource = getChangeSource(\n shouldList,\n shouldHyphen,\n shouldLink\n );\n\n return (\n shouldList ||\n shouldHyphen ||\n shouldLink ||\n shouldFraction ||\n shouldOrdinals\n );\n },\n formatOptions\n );\n\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink } = this.options;\n if (event.source == 'Paste' && autoLink) {\n createLink(editor);\n }\n }\n}\n\nconst getApiName = (shouldList: boolean, shouldHyphen: boolean) => {\n return shouldList ? 'autoToggleList' : shouldHyphen ? 'autoHyphen' : '';\n};\n\nconst getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink: boolean) => {\n return shouldList || shouldHyphen\n ? ChangeSource.AutoFormat\n : shouldLink\n ? ChangeSource.AutoLink\n : '';\n};\n"]}
@@ -19,6 +19,8 @@ define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-
19
19
  return true;
20
20
  }
21
21
  return false;
22
+ }, {
23
+ changeSource: roosterjs_content_model_dom_1.ChangeSource.AutoLink,
22
24
  });
23
25
  }
24
26
  exports.createLink = createLink;
@@ -1 +1 @@
1
- {"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;;IAIA;;OAEG;IACH,SAAgB,UAAU,CAAC,MAAe;QACtC,IAAA,oEAAsC,EAAC,MAAM,EAAE,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;YAC3E,IAAI,QAAQ,GAAoB,IAAI,CAAC;YACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;gBAC/D,IAAA,qCAAO,EAAC,WAAW,EAAE;oBACjB,MAAM,EAAE;wBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;wBAC5B,SAAS,EAAE,IAAI;qBAClB;oBACD,OAAO,EAAE,EAAE;iBACd,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;aACf;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;IACP,CAAC;IAfD,gCAeC","sourcesContent":["import { addLink } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';\nimport type { IEditor, LinkData } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLink(editor: IEditor) {\n formatTextSegmentBeforeSelectionMarker(editor, (_model, linkSegment, _paragraph) => {\n let linkData: LinkData | null = null;\n if (!linkSegment.link && (linkData = matchLink(linkSegment.text))) {\n addLink(linkSegment, {\n format: {\n href: linkData.normalizedUrl,\n underline: true,\n },\n dataset: {},\n });\n return true;\n }\n return false;\n });\n}\n"]}
1
+ {"version":3,"file":"createLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts"],"names":[],"mappings":";;;;IAIA;;OAEG;IACH,SAAgB,UAAU,CAAC,MAAe;QACtC,IAAA,oEAAsC,EAClC,MAAM,EACN,UAAC,MAAM,EAAE,WAAW,EAAE,UAAU;YAC5B,IAAI,QAAQ,GAAoB,IAAI,CAAC;YACrC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,GAAG,IAAA,uCAAS,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE;gBAC/D,IAAA,qCAAO,EAAC,WAAW,EAAE;oBACjB,MAAM,EAAE;wBACJ,IAAI,EAAE,QAAQ,CAAC,aAAa;wBAC5B,SAAS,EAAE,IAAI;qBAClB;oBACD,OAAO,EAAE,EAAE;iBACd,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;aACf;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,EACD;YACI,YAAY,EAAE,0CAAY,CAAC,QAAQ;SACtC,CACJ,CAAC;IACN,CAAC;IArBD,gCAqBC","sourcesContent":["import { addLink, ChangeSource } from 'roosterjs-content-model-dom';\nimport { formatTextSegmentBeforeSelectionMarker, matchLink } from 'roosterjs-content-model-api';\nimport type { IEditor, LinkData } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function createLink(editor: IEditor) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, linkSegment, _paragraph) => {\n let linkData: LinkData | null = null;\n if (!linkSegment.link && (linkData = matchLink(linkSegment.text))) {\n addLink(linkSegment, {\n format: {\n href: linkData.normalizedUrl,\n underline: true,\n },\n dataset: {},\n });\n return true;\n }\n return false;\n },\n {\n changeSource: ChangeSource.AutoLink,\n }\n );\n}\n"]}
@@ -8,15 +8,13 @@ define(["require", "exports", "./getListTypeStyle", "roosterjs-content-model-api
8
8
  function keyboardListTrigger(model, paragraph, context, shouldSearchForBullet, shouldSearchForNumbering) {
9
9
  if (shouldSearchForBullet === void 0) { shouldSearchForBullet = true; }
10
10
  if (shouldSearchForNumbering === void 0) { shouldSearchForNumbering = true; }
11
- if (shouldSearchForBullet || shouldSearchForNumbering) {
12
- var listStyleType = (0, getListTypeStyle_1.getListTypeStyle)(model, shouldSearchForBullet, shouldSearchForNumbering);
13
- if (listStyleType) {
14
- paragraph.segments.splice(0, 1);
15
- var listType = listStyleType.listType, styleType = listStyleType.styleType, index = listStyleType.index;
16
- triggerList(model, listType, styleType, index);
17
- context.canUndoByBackspace = true;
18
- return true;
19
- }
11
+ var listStyleType = (0, getListTypeStyle_1.getListTypeStyle)(model, shouldSearchForBullet, shouldSearchForNumbering);
12
+ if (listStyleType) {
13
+ paragraph.segments.splice(0, 1);
14
+ var listType = listStyleType.listType, styleType = listStyleType.styleType, index = listStyleType.index;
15
+ triggerList(model, listType, styleType, index);
16
+ context.canUndoByBackspace = true;
17
+ return true;
20
18
  }
21
19
  return false;
22
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":";;;;IAYA;;OAEG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,SAAgC,EAChC,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;QADxC,sCAAA,EAAA,4BAAqC;QACrC,yCAAA,EAAA,+BAAwC;QAExC,IAAI,qBAAqB,IAAI,wBAAwB,EAAE;YACnD,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAClC,KAAK,EACL,qBAAqB,EACrB,wBAAwB,CAC3B,CAAC;YACF,IAAI,aAAa,EAAE;gBACf,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBACxB,IAAA,QAAQ,GAAuB,aAAa,SAApC,EAAE,SAAS,GAAY,aAAa,UAAzB,EAAE,KAAK,GAAK,aAAa,MAAlB,CAAmB;gBACrD,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBAC/C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;gBAElC,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAvBD,kDAuBC;IAED,IAAM,WAAW,GAAG,UAChB,KAA2B,EAC3B,QAAqB,EACrB,SAAiB,EACjB,KAAc;QAEd,IAAA,yCAAW,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC7B,IAAM,aAAa,GAAG,QAAQ,IAAI,IAAI,CAAC;QACvC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE;YACrC,IAAA,qDAAuB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;SACzC;QACD,IAAA,+CAAiB,EACb,KAAK,EACL,aAAa;YACT,CAAC,CAAC;gBACI,gBAAgB,EAAE,SAAS;aAC9B;YACH,CAAC,CAAC;gBACI,kBAAkB,EAAE,SAAS;aAChC,CACV,CAAC;IACN,CAAC,CAAC","sourcesContent":["import { getListTypeStyle } from './getListTypeStyle';\nimport {\n setListType,\n setModelListStartNumber,\n setModelListStyle,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n model: ContentModelDocument,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true\n) {\n if (shouldSearchForBullet || shouldSearchForNumbering) {\n const listStyleType = getListTypeStyle(\n model,\n shouldSearchForBullet,\n shouldSearchForNumbering\n );\n if (listStyleType) {\n paragraph.segments.splice(0, 1);\n const { listType, styleType, index } = listStyleType;\n triggerList(model, listType, styleType, index);\n context.canUndoByBackspace = true;\n\n return true;\n }\n }\n return false;\n}\n\nconst triggerList = (\n model: ContentModelDocument,\n listType: 'OL' | 'UL',\n styleType: number,\n index?: number\n) => {\n setListType(model, listType);\n const isOrderedList = listType == 'OL';\n if (index && index > 1 && isOrderedList) {\n setModelListStartNumber(model, index);\n }\n setModelListStyle(\n model,\n isOrderedList\n ? {\n orderedStyleType: styleType,\n }\n : {\n unorderedStyleType: styleType,\n }\n );\n};\n"]}
1
+ {"version":3,"file":"keyboardListTrigger.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts"],"names":[],"mappings":";;;;IAYA;;OAEG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,SAAgC,EAChC,OAAkC,EAClC,qBAAqC,EACrC,wBAAwC;QADxC,sCAAA,EAAA,4BAAqC;QACrC,yCAAA,EAAA,+BAAwC;QAExC,IAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,KAAK,EAAE,qBAAqB,EAAE,wBAAwB,CAAC,CAAC;QAC/F,IAAI,aAAa,EAAE;YACf,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACxB,IAAA,QAAQ,GAAuB,aAAa,SAApC,EAAE,SAAS,GAAY,aAAa,UAAzB,EAAE,KAAK,GAAK,aAAa,MAAlB,CAAmB;YACrD,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YAC/C,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAElC,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAjBD,kDAiBC;IAED,IAAM,WAAW,GAAG,UAChB,KAA2B,EAC3B,QAAqB,EACrB,SAAiB,EACjB,KAAc;QAEd,IAAA,yCAAW,EAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC7B,IAAM,aAAa,GAAG,QAAQ,IAAI,IAAI,CAAC;QACvC,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE;YACrC,IAAA,qDAAuB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;SACzC;QACD,IAAA,+CAAiB,EACb,KAAK,EACL,aAAa;YACT,CAAC,CAAC;gBACI,gBAAgB,EAAE,SAAS;aAC9B;YACH,CAAC,CAAC;gBACI,kBAAkB,EAAE,SAAS;aAChC,CACV,CAAC;IACN,CAAC,CAAC","sourcesContent":["import { getListTypeStyle } from './getListTypeStyle';\nimport {\n setListType,\n setModelListStartNumber,\n setModelListStyle,\n} from 'roosterjs-content-model-api';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardListTrigger(\n model: ContentModelDocument,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext,\n shouldSearchForBullet: boolean = true,\n shouldSearchForNumbering: boolean = true\n) {\n const listStyleType = getListTypeStyle(model, shouldSearchForBullet, shouldSearchForNumbering);\n if (listStyleType) {\n paragraph.segments.splice(0, 1);\n const { listType, styleType, index } = listStyleType;\n triggerList(model, listType, styleType, index);\n context.canUndoByBackspace = true;\n\n return true;\n }\n return false;\n}\n\nconst triggerList = (\n model: ContentModelDocument,\n listType: 'OL' | 'UL',\n styleType: number,\n index?: number\n) => {\n setListType(model, listType);\n const isOrderedList = listType == 'OL';\n if (index && index > 1 && isOrderedList) {\n setModelListStartNumber(model, index);\n }\n setModelListStyle(\n model,\n isOrderedList\n ? {\n orderedStyleType: styleType,\n }\n : {\n unorderedStyleType: styleType,\n }\n );\n};\n"]}
@@ -0,0 +1,5 @@
1
+ import type { ContentModelParagraph, ContentModelText, FormatContentModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function transformFraction(previousSegment: ContentModelText, paragraph: ContentModelParagraph, context: FormatContentModelContext): boolean;
@@ -0,0 +1,28 @@
1
+ define(["require", "exports", "../../pluginUtils/splitTextSegment"], function (require, exports, splitTextSegment_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.transformFraction = void 0;
5
+ var FRACTIONS = {
6
+ '1/2': '½',
7
+ '1/4': '¼',
8
+ '3/4': '¾',
9
+ };
10
+ /**
11
+ * @internal
12
+ */
13
+ function transformFraction(previousSegment, paragraph, context) {
14
+ var _a;
15
+ var fraction = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
16
+ if (fraction && FRACTIONS[fraction]) {
17
+ var textLength = previousSegment.text.length - 1;
18
+ var textIndex = textLength - fraction.length;
19
+ var textSegment = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, textIndex, textLength);
20
+ textSegment.text = FRACTIONS[fraction];
21
+ context.canUndoByBackspace = true;
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ exports.transformFraction = transformFraction;
27
+ });
28
+ //# sourceMappingURL=transformFraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformFraction.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformFraction.ts"],"names":[],"mappings":";;;;IAOA,IAAM,SAAS,GAA2B;QACtC,KAAK,EAAE,GAAG;QACV,KAAK,EAAE,GAAG;QACV,KAAK,EAAE,GAAG;KACb,CAAC;IAEF;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,eAAiC,EACjC,SAAgC,EAChC,OAAkC;;QAElC,IAAM,QAAQ,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;QAC/D,IAAI,QAAQ,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE;YACjC,IAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;YACnD,IAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC;YAC/C,IAAM,WAAW,GAAG,IAAA,mCAAgB,EAAC,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;YACxF,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;YAEvC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;YAClC,OAAO,IAAI,CAAC;SACf;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAjBD,8CAiBC","sourcesContent":["import { splitTextSegment } from '../../pluginUtils/splitTextSegment';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\nconst FRACTIONS: Record<string, string> = {\n '1/2': '½',\n '1/4': '¼',\n '3/4': '¾',\n};\n\n/**\n * @internal\n */\nexport function transformFraction(\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const fraction = previousSegment.text.split(' ').pop()?.trim();\n if (fraction && FRACTIONS[fraction]) {\n const textLength = previousSegment.text.length - 1;\n const textIndex = textLength - fraction.length;\n const textSegment = splitTextSegment(previousSegment, paragraph, textIndex, textLength);\n textSegment.text = FRACTIONS[fraction];\n\n context.canUndoByBackspace = true;\n return true;\n }\n\n return false;\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { ContentModelParagraph, ContentModelText, FormatContentModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function transformOrdinals(previousSegment: ContentModelText, paragraph: ContentModelParagraph, context: FormatContentModelContext): boolean;
@@ -0,0 +1,33 @@
1
+ define(["require", "exports", "../../pluginUtils/splitTextSegment"], function (require, exports, splitTextSegment_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.transformOrdinals = void 0;
5
+ var getOrdinal = function (value) {
6
+ var ORDINALS = {
7
+ 1: 'st',
8
+ 2: 'nd',
9
+ 3: 'rd',
10
+ };
11
+ return ORDINALS[value] || 'th';
12
+ };
13
+ /**
14
+ * @internal
15
+ */
16
+ function transformOrdinals(previousSegment, paragraph, context) {
17
+ var _a;
18
+ var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
19
+ if (value) {
20
+ var ordinal = value.substring(value.length - 2);
21
+ var ordinalValue = parseInt(value);
22
+ if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {
23
+ var ordinalSegment = (0, splitTextSegment_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
24
+ ordinalSegment.format.superOrSubScriptSequence = 'super';
25
+ context.canUndoByBackspace = true;
26
+ return true;
27
+ }
28
+ }
29
+ return false;
30
+ }
31
+ exports.transformOrdinals = transformOrdinals;
32
+ });
33
+ //# sourceMappingURL=transformOrdinals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformOrdinals.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformOrdinals.ts"],"names":[],"mappings":";;;;IAOA,IAAM,UAAU,GAAG,UAAC,KAAa;QAC7B,IAAM,QAAQ,GAA2B;YACrC,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;YACP,CAAC,EAAE,IAAI;SACV,CAAC;QACF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC;IACnC,CAAC,CAAC;IAEF;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,eAAiC,EACjC,SAAgC,EAChC,OAAkC;;QAElC,IAAM,KAAK,GAAG,MAAA,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,0CAAE,IAAI,EAAE,CAAC;QAC5D,IAAI,KAAK,EAAE;YACP,IAAM,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAClD,IAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,YAAY,IAAI,UAAU,CAAC,YAAY,CAAC,KAAK,OAAO,EAAE;gBACtD,IAAM,cAAc,GAAG,IAAA,mCAAgB,EACnC,eAAe,EACf,SAAS,EACT,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAC/B,eAAe,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAClC,CAAC;gBAEF,cAAc,CAAC,MAAM,CAAC,wBAAwB,GAAG,OAAO,CAAC;gBACzD,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;gBAClC,OAAO,IAAI,CAAC;aACf;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAvBD,8CAuBC","sourcesContent":["import { splitTextSegment } from '../../pluginUtils/splitTextSegment';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\nconst getOrdinal = (value: number) => {\n const ORDINALS: Record<number, string> = {\n 1: 'st',\n 2: 'nd',\n 3: 'rd',\n };\n return ORDINALS[value] || 'th';\n};\n\n/**\n * @internal\n */\nexport function transformOrdinals(\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\n context: FormatContentModelContext\n): boolean {\n const value = previousSegment.text.split(' ').pop()?.trim();\n if (value) {\n const ordinal = value.substring(value.length - 2);\n const ordinalValue = parseInt(value);\n if (ordinalValue && getOrdinal(ordinalValue) === ordinal) {\n const ordinalSegment = splitTextSegment(\n previousSegment,\n paragraph,\n previousSegment.text.length - 3,\n previousSegment.text.length - 1\n );\n\n ordinalSegment.format.superOrSubScriptSequence = 'super';\n context.canUndoByBackspace = true;\n return true;\n }\n }\n return false;\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import type { ContentModelParagraph, ContentModelText, EditorPlugin, IEditor, PluginEvent } from 'roosterjs-content-model-types';
2
+ /**
3
+ * The CustomReplace interface defines a custom replacement that can be used in CustomReplacePlugin.
4
+ */
5
+ export interface CustomReplace {
6
+ /**
7
+ * The string to replace in the editor.
8
+ */
9
+ stringToReplace: string;
10
+ /**
11
+ * The string to replace with.
12
+ */
13
+ replacementString: string;
14
+ /**
15
+ * The handler to replace the string.
16
+ * @param previousSegment The text segment to replace.
17
+ * @param stringToReplace The string to replace.
18
+ * @param replacementString The string to replace with.
19
+ * @param paragraph The paragraph that contains the text segment.
20
+ * @returns True if the string is replaced successfully, otherwise false.
21
+ */
22
+ replacementHandler: (previousSegment: ContentModelText, stringToReplace: string, replacementString: string, paragraph?: ContentModelParagraph) => boolean;
23
+ }
24
+ /**
25
+ * CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
26
+ */
27
+ export declare class CustomReplacePlugin implements EditorPlugin {
28
+ private customReplacements;
29
+ private editor;
30
+ private triggerKeys;
31
+ /**
32
+ * @param customReplacements Custom replacement rules.
33
+ * Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
34
+ */
35
+ constructor(customReplacements: CustomReplace[]);
36
+ /**
37
+ * Get name of this plugin
38
+ */
39
+ getName(): string;
40
+ /**
41
+ * The first method that editor will call to a plugin when editor is initializing.
42
+ * It will pass in the editor instance, plugin should take this chance to save the
43
+ * editor reference so that it can call to any editor method or format API later.
44
+ * @param editor The editor object
45
+ */
46
+ initialize(editor: IEditor): void;
47
+ /**
48
+ * The last method that editor will call to a plugin before it is disposed.
49
+ * Plugin can take this chance to clear the reference to editor. After this method is
50
+ * called, plugin should not call to any editor method since it will result in error.
51
+ */
52
+ dispose(): void;
53
+ /**
54
+ * Core method for a plugin. Once an event happens in editor, editor will call this
55
+ * method of each plugin to handle the event as long as the event is not handled
56
+ * exclusively by another plugin.
57
+ * @param event The event to handle:
58
+ */
59
+ onPluginEvent(event: PluginEvent): void;
60
+ private handleEditorInputEvent;
61
+ }
@@ -0,0 +1,88 @@
1
+ define(["require", "exports", "roosterjs-content-model-api"], function (require, exports, roosterjs_content_model_api_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.CustomReplacePlugin = void 0;
5
+ /**
6
+ * CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.
7
+ */
8
+ var CustomReplacePlugin = /** @class */ (function () {
9
+ /**
10
+ * @param customReplacements Custom replacement rules.
11
+ * Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]
12
+ */
13
+ function CustomReplacePlugin(customReplacements) {
14
+ this.customReplacements = customReplacements;
15
+ this.editor = null;
16
+ this.triggerKeys = [];
17
+ }
18
+ /**
19
+ * Get name of this plugin
20
+ */
21
+ CustomReplacePlugin.prototype.getName = function () {
22
+ return 'CustomReplace';
23
+ };
24
+ /**
25
+ * The first method that editor will call to a plugin when editor is initializing.
26
+ * It will pass in the editor instance, plugin should take this chance to save the
27
+ * editor reference so that it can call to any editor method or format API later.
28
+ * @param editor The editor object
29
+ */
30
+ CustomReplacePlugin.prototype.initialize = function (editor) {
31
+ this.editor = editor;
32
+ this.triggerKeys = this.customReplacements.map(function (replacement) {
33
+ return replacement.stringToReplace.slice(-1);
34
+ });
35
+ };
36
+ /**
37
+ * The last method that editor will call to a plugin before it is disposed.
38
+ * Plugin can take this chance to clear the reference to editor. After this method is
39
+ * called, plugin should not call to any editor method since it will result in error.
40
+ */
41
+ CustomReplacePlugin.prototype.dispose = function () {
42
+ this.editor = null;
43
+ };
44
+ /**
45
+ * Core method for a plugin. Once an event happens in editor, editor will call this
46
+ * method of each plugin to handle the event as long as the event is not handled
47
+ * exclusively by another plugin.
48
+ * @param event The event to handle:
49
+ */
50
+ CustomReplacePlugin.prototype.onPluginEvent = function (event) {
51
+ if (this.editor) {
52
+ switch (event.eventType) {
53
+ case 'input':
54
+ this.handleEditorInputEvent(this.editor, event);
55
+ break;
56
+ }
57
+ }
58
+ };
59
+ CustomReplacePlugin.prototype.handleEditorInputEvent = function (editor, event) {
60
+ var _this = this;
61
+ var rawEvent = event.rawEvent;
62
+ var selection = editor.getDOMSelection();
63
+ var key = rawEvent.data;
64
+ if (this.customReplacements.length > 0 &&
65
+ rawEvent.inputType === 'insertText' &&
66
+ selection &&
67
+ selection.type === 'range' &&
68
+ selection.range.collapsed &&
69
+ key &&
70
+ this.triggerKeys.indexOf(key) > -1) {
71
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, previousSegment, paragraph, _markerFormat, context) {
72
+ var replaced = _this.customReplacements.some(function (_a) {
73
+ var stringToReplace = _a.stringToReplace, replacementString = _a.replacementString, replacementHandler = _a.replacementHandler;
74
+ return replacementHandler(previousSegment, stringToReplace, replacementString, paragraph);
75
+ });
76
+ if (replaced) {
77
+ context.canUndoByBackspace = true;
78
+ return true;
79
+ }
80
+ return false;
81
+ });
82
+ }
83
+ };
84
+ return CustomReplacePlugin;
85
+ }());
86
+ exports.CustomReplacePlugin = CustomReplacePlugin;
87
+ });
88
+ //# sourceMappingURL=CustomReplacePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomReplacePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/customReplace/CustomReplacePlugin.ts"],"names":[],"mappings":";;;;IAwCA;;OAEG;IACH;QAII;;;WAGG;QACH,6BAAoB,kBAAmC;YAAnC,uBAAkB,GAAlB,kBAAkB,CAAiB;YAP/C,WAAM,GAAmB,IAAI,CAAC;YAC9B,gBAAW,GAAa,EAAE,CAAC;QAMuB,CAAC;QAE3D;;WAEG;QACH,qCAAO,GAAP;YACI,OAAO,eAAe,CAAC;QAC3B,CAAC;QAED;;;;;WAKG;QACH,wCAAU,GAAV,UAAW,MAAe;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAA,WAAW;gBACtD,OAAA,WAAW,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAArC,CAAqC,CACxC,CAAC;QACN,CAAC;QAED;;;;WAIG;QACH,qCAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,2CAAa,GAAb,UAAc,KAAkB;YAC5B,IAAI,IAAI,CAAC,MAAM,EAAE;gBACb,QAAQ,KAAK,C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foreSelectionMarker } from 'roosterjs-content-model-api';\nimport type {\n ContentModelParagraph,\n ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * The CustomReplace interface defines a custom replacement that can be used in CustomReplacePlugin.\n */\nexport interface CustomReplace {\n /**\n * The string to replace in the editor.\n */\n stringToReplace: string;\n\n /**\n * The string to replace with.\n */\n replacementString: string;\n\n /**\n * The handler to replace the string.\n * @param previousSegment The text segment to replace.\n * @param stringToReplace The string to replace.\n * @param replacementString The string to replace with.\n * @param paragraph The paragraph that contains the text segment.\n * @returns True if the string is replaced successfully, otherwise false.\n */\n replacementHandler: (\n previousSegment: ContentModelText,\n stringToReplace: string,\n replacementString: string,\n paragraph?: ContentModelParagraph\n ) => boolean;\n}\n\n/**\n * CustomReplacePlugin is a plugin that allows you to replace a string with another string in the editor.\n */\nexport class CustomReplacePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private triggerKeys: string[] = [];\n\n /**\n * @param customReplacements Custom replacement rules.\n * Ex: [{ stringToReplace: ':)', replacementString: '🙂', replacementHandler: replaceEmojis }]\n */\n constructor(private customReplacements: CustomReplace[]) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'CustomReplace';\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.triggerKeys = this.customReplacements.map(replacement =>\n replacement.stringToReplace.slice(-1)\n );\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 * 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) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n const key = rawEvent.data;\n if (\n this.customReplacements.length > 0 &&\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n key &&\n this.triggerKeys.indexOf(key) > -1\n ) {\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (_model, previousSegment, paragraph, _markerFormat, context) => {\n const replaced = this.customReplacements.some(\n ({ stringToReplace, replacementString, replacementHandler }) => {\n return replacementHandler(\n previousSegment,\n stringToReplace,\n replacementString,\n paragraph\n );\n }\n );\n if (replaced) {\n context.canUndoByBackspace = true;\n return true;\n }\n return false;\n }\n );\n }\n }\n}\n"]}
@@ -71,11 +71,18 @@ define(["require", "exports", "./keyboardDelete", "./keyboardInput", "./keyboard
71
71
  if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
72
72
  switch (rawEvent.key) {
73
73
  case 'Backspace':
74
- case 'Delete':
75
74
  // Use our API to handle BACKSPACE/DELETE key.
76
75
  // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache
77
76
  (0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
78
77
  break;
78
+ case 'Delete':
79
+ // Use our API to handle BACKSPACE/DELETE key.
80
+ // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache
81
+ // And leave it to browser when shift key is pressed so that browser will trigger cut event
82
+ if (!event.rawEvent.shiftKey) {
83
+ (0, keyboardDelete_1.keyboardDelete)(editor, rawEvent);
84
+ }
85
+ break;
79
86
  case 'Tab':
80
87
  (0, keyboardTab_1.keyboardTab)(editor, rawEvent);
81
88
  break;
@@ -92,6 +99,8 @@ define(["require", "exports", "./keyboardDelete", "./keyboardInput", "./keyboard
92
99
  }
93
100
  };
94
101
  EditPlugin.prototype.handleBeforeInputEvent = function (editor, rawEvent) {
102
+ var _this = this;
103
+ var _a, _b;
95
104
  // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key
96
105
  // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic
97
106
  if (!this.shouldHandleNextInputEvent ||
@@ -119,6 +128,15 @@ define(["require", "exports", "./keyboardDelete", "./keyboardInput", "./keyboard
119
128
  }
120
129
  if (handled) {
121
130
  rawEvent.preventDefault();
131
+ // Restore the selection to avoid the cursor jump issue
132
+ // See: https://issues.chromium.org/issues/330596261
133
+ var selection_1 = editor.getDOMSelection();
134
+ var doc = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.getDocument();
135
+ (_b = doc === null || doc === void 0 ? void 0 : doc.defaultView) === null || _b === void 0 ? void 0 : _b.requestAnimationFrame(function () {
136
+ if (_this.editor) {
137
+ _this.editor.setDOMSelection(selection_1);
138
+ }
139
+ });
122
140
  }
123
141
  };
124
142
  return EditPlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;;IAUA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IAEtB;;;;;;OAMG;IACH;QAAA;YACY,WAAM,GAAmB,IAAI,CAAC;YAC9B,aAAQ,GAAwB,IAAI,CAAC;YACrC,+BAA0B,GAAG,KAAK,CAAC;QA0H/C,CAAC;QAxHG;;WAEG;QACH,4BAAO,GAAP;YACI,OAAO,MAAM,CAAC;QAClB,CAAC;QAED;;;;;WAKG;QACH,+BAAU,GAAV,UAAW,MAAe;YAA1B,iBASC;YARG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE;gBACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cA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O,CAAC;oBACb;wBACI,IAAA,6BAAa,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;wBAChC,MAAM;iBACb;aACJ;QACL,CAAC;QAEO,2CAAsB,GAA9B,UAA+B,MAAe,EAAE,QAAe;YAC3D,gFAAgF;YAChF,uGAAuG;YACvG,IACI,CAAC,IAAI,CAAC,0BAA0B;gBAChC,CAAC,CAAC,QAAQ,YAAY,UAAU,CAAC;gBACjC,QAAQ,CAAC,gBAAgB,EAC3B;gBACE,OAAO;aACV;YACD,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;YAExC,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,QAAQ,QAAQ,CAAC,SAAS,EAAE;gBACxB,KAAK,uBAAuB;oBACxB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;wBACzB,GAAG,EAAE,WAAW;wBAChB,OAAO,EAAE,aAAa;wBACtB,KAAK,EAAE,aAAa;qBACvB,CAAC,CACL,CAAC;oBACF,MAAM;gBACV,KAAK,sBAAsB;oBACvB,OAAO,GAAG,IAAA,+BAAc,EACpB,MAAM,EACN,IAAI,aAAa,CAAC,SAAS,EAAE;wBACzB,GAAG,EAAE,QAAQ;wBACb,OAAO,EAAE,UAAU;wBACnB,KAAK,EAAE,UAAU;qBACpB,CAAC,CACL,CAAC;oBACF,MAAM;aACb;YAED,IAAI,OAAO,EAAE;gBACT,QAAQ,CAAC,cAAc,EAAE,CAAC;aAC7B;QACL,CAAC;QACL,iBAAC;IAAD,CAAC,AA7HD,IA6HC;IA7HY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\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 if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\n }\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 this.disposer?.();\n this.disposer = null;\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) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n case 'Delete':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n keyboardDelete(editor, rawEvent);\n break;\n\n case 'Tab':\n keyboardTab(editor, rawEvent);\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"EditPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/edit/EditPlugin.ts"],"names":[],"mappings":";;;;IAUA,IAAM,aAAa,GAAG,CAAC,CAAC;IACxB,IAAM,UAAU,GAAG,EAAE,CAAC;IAEtB;;;;;;OAMG;IACH;QAAA;YACY,WAAM,GAAmB,IAAI,CAAC;YAC9B,aAAQ,GAAwB,IAAI,CAAC;YACrC,+BAA0B,GAAG,KAAK,CAAC;QA4I/C,CAAC;QA1IG;;WAEG;QACH,4BAAO,GAAP;YACI,OAAO,MAAM,CAAC;QAClB,CAAC;QAED;;;;;WAKG;QACH,+BAAU,GAAV,UAAW,MAAe;YAA1B,iBASC;YARG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;YACrB,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,SAAS,EAAE;gBACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC;oBACvC,WAAW,EAAE;wBACT,cAAc,EAAE,UAAA,CAAC,IAAI,OAAA,KAAI,CAAC,sBAAs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AH,GAAG,CAAE,WAAW,0CAAE,qBAAqB,CAAC;oBACpC,IAAI,KAAI,CAAC,MAAM,EAAE;wBACb,KAAI,CAAC,MAAM,CAAC,eAAe,CAAC,WAAS,CAAC,CAAC;qBAC1C;gBACL,CAAC,CAAC,CAAC;aACN;QACL,CAAC;QACL,iBAAC;IAAD,CAAC,AA/ID,IA+IC;IA/IY,gCAAU","sourcesContent":["import { keyboardDelete } from './keyboardDelete';\nimport { keyboardInput } from './keyboardInput';\nimport { keyboardTab } from './keyboardTab';\nimport type {\n EditorPlugin,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\nconst BACKSPACE_KEY = 8;\nconst DELETE_KEY = 46;\n\n/**\n * Edit plugins helps editor to do editing operation on top of content model.\n * This includes:\n * 1. Delete Key\n * 2. Backspace Key\n * 3. Tab Key\n */\nexport class EditPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n private disposer: (() => void) | null = null;\n private shouldHandleNextInputEvent = false;\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Edit';\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 if (editor.getEnvironment().isAndroid) {\n this.disposer = this.editor.attachDomEvent({\n beforeinput: {\n beforeDispatch: e => this.handleBeforeInputEvent(editor, e),\n },\n });\n }\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 this.disposer?.();\n this.disposer = null;\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) {\n switch (event.eventType) {\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n keyboardDelete(editor, rawEvent);\n break;\n\n case 'Delete':\n // Use our API to handle BACKSPACE/DELETE key.\n // No need to clear cache here since if we rely on browser's behavior, there will be Input event and its handler will reconcile cache\n // And leave it to browser when shift key is pressed so that browser will trigger cut event\n if (!event.rawEvent.shiftKey) {\n keyboardDelete(editor, rawEvent);\n }\n break;\n\n case 'Tab':\n keyboardTab(editor, rawEvent);\n break;\n case 'Unidentified':\n if (editor.getEnvironment().isAndroid) {\n this.shouldHandleNextInputEvent = true;\n }\n break;\n\n case 'Enter':\n default:\n keyboardInput(editor, rawEvent);\n break;\n }\n }\n }\n\n private handleBeforeInputEvent(editor: IEditor, rawEvent: Event) {\n // Some Android IMEs doesn't fire correct keydown event for BACKSPACE/DELETE key\n // Here we translate input event to BACKSPACE/DELETE keydown event to be compatible with existing logic\n if (\n !this.shouldHandleNextInputEvent ||\n !(rawEvent instanceof InputEvent) ||\n rawEvent.defaultPrevented\n ) {\n return;\n }\n this.shouldHandleNextInputEvent = false;\n\n let handled = false;\n switch (rawEvent.inputType) {\n case 'deleteContentBackward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Backspace',\n keyCode: BACKSPACE_KEY,\n which: BACKSPACE_KEY,\n })\n );\n break;\n case 'deleteContentForward':\n handled = keyboardDelete(\n editor,\n new KeyboardEvent('keydown', {\n key: 'Delete',\n keyCode: DELETE_KEY,\n which: DELETE_KEY,\n })\n );\n break;\n }\n\n if (handled) {\n rawEvent.preventDefault();\n\n // Restore the selection to avoid the cursor jump issue\n // See: https://issues.chromium.org/issues/330596261\n const selection = editor.getDOMSelection();\n const doc = this.editor?.getDocument();\n doc?.defaultView?.requestAnimationFrame(() => {\n if (this.editor) {\n this.editor.setDOMSelection(selection);\n }\n });\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-api", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_api_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.handleEnterOnList = void 0;
@@ -47,7 +47,12 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
47
47
  listItem_1.levels.pop();
48
48
  }
49
49
  else {
50
- createNewListItem(context, listItem_1, listParent);
50
+ var newListItem = createNewListItem(context, listItem_1, listParent);
51
+ if (context.formatContext) {
52
+ context.formatContext.announceData = (0, roosterjs_content_model_api_1.getListAnnounceData)((0, tslib_1.__spreadArray)([
53
+ newListItem
54
+ ], (0, tslib_1.__read)(path.slice(index + 1)), false));
55
+ }
51
56
  }
52
57
  }
53
58
  rawEvent === null || rawEvent === void 0 ? void 0 : rawEvent.preventDefault();
@@ -73,6 +78,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
73
78
  insertPoint.paragraph = newParagraph;
74
79
  context.lastParagraph = newParagraph;
75
80
  listParent.blocks.splice(listIndex + 1, 0, newListItem);
81
+ return newListItem;
76
82
  };
77
83
  var createNewListLevel = function (listItem) {
78
84
  return listItem.levels.map(function (level) {