roosterjs-content-model-plugins 0.20.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 (264) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +262 -0
  3. package/lib/edit/ContentModelEditPlugin.d.ts +35 -0
  4. package/lib/edit/ContentModelEditPlugin.js +71 -0
  5. package/lib/edit/ContentModelEditPlugin.js.map +1 -0
  6. package/lib/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -0
  7. package/lib/edit/deleteSteps/deleteAllSegmentBefore.js +20 -0
  8. package/lib/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -0
  9. package/lib/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -0
  10. package/lib/edit/deleteSteps/deleteCollapsedSelection.js +91 -0
  11. package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -0
  12. package/lib/edit/deleteSteps/deleteWordSelection.d.ts +9 -0
  13. package/lib/edit/deleteSteps/deleteWordSelection.js +171 -0
  14. package/lib/edit/deleteSteps/deleteWordSelection.js.map +1 -0
  15. package/lib/edit/handleKeyboardEventCommon.d.ts +15 -0
  16. package/lib/edit/handleKeyboardEventCommon.js +55 -0
  17. package/lib/edit/handleKeyboardEventCommon.js.map +1 -0
  18. package/lib/edit/keyboardDelete.d.ts +9 -0
  19. package/lib/edit/keyboardDelete.js +64 -0
  20. package/lib/edit/keyboardDelete.js.map +1 -0
  21. package/lib/edit/utils/getLeafSiblingBlock.d.ts +23 -0
  22. package/lib/edit/utils/getLeafSiblingBlock.js +76 -0
  23. package/lib/edit/utils/getLeafSiblingBlock.js.map +1 -0
  24. package/lib/index.d.ts +2 -0
  25. package/lib/index.js +8 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/paste/ContentModelPastePlugin.d.ts +42 -0
  28. package/lib/paste/ContentModelPastePlugin.js +149 -0
  29. package/lib/paste/ContentModelPastePlugin.js.map +1 -0
  30. package/lib/paste/Excel/processPastedContentFromExcel.d.ts +13 -0
  31. package/lib/paste/Excel/processPastedContentFromExcel.js +83 -0
  32. package/lib/paste/Excel/processPastedContentFromExcel.js.map +1 -0
  33. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -0
  34. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js +20 -0
  35. package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -0
  36. package/lib/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -0
  37. package/lib/paste/WacComponents/processPastedContentWacComponents.js +208 -0
  38. package/lib/paste/WacComponents/processPastedContentWacComponents.js.map +1 -0
  39. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -0
  40. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +70 -0
  41. package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -0
  42. package/lib/paste/WordDesktop/processWordComments.d.ts +7 -0
  43. package/lib/paste/WordDesktop/processWordComments.js +22 -0
  44. package/lib/paste/WordDesktop/processWordComments.js.map +1 -0
  45. package/lib/paste/WordDesktop/processWordLists.d.ts +10 -0
  46. package/lib/paste/WordDesktop/processWordLists.js +155 -0
  47. package/lib/paste/WordDesktop/processWordLists.js.map +1 -0
  48. package/lib/paste/pasteSourceValidations/constants.d.ts +17 -0
  49. package/lib/paste/pasteSourceValidations/constants.js +22 -0
  50. package/lib/paste/pasteSourceValidations/constants.js.map +1 -0
  51. package/lib/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -0
  52. package/lib/paste/pasteSourceValidations/documentContainWacElements.js +25 -0
  53. package/lib/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -0
  54. package/lib/paste/pasteSourceValidations/getPasteSource.d.ts +27 -0
  55. package/lib/paste/pasteSourceValidations/getPasteSource.js +44 -0
  56. package/lib/paste/pasteSourceValidations/getPasteSource.js.map +1 -0
  57. package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -0
  58. package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js +17 -0
  59. package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -0
  60. package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -0
  61. package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js +19 -0
  62. package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -0
  63. package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -0
  64. package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js +15 -0
  65. package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -0
  66. package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -0
  67. package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +15 -0
  68. package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -0
  69. package/lib/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -0
  70. package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js +19 -0
  71. package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -0
  72. package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -0
  73. package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.js +19 -0
  74. package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -0
  75. package/lib/paste/utils/addParser.d.ts +5 -0
  76. package/lib/paste/utils/addParser.js +17 -0
  77. package/lib/paste/utils/addParser.js.map +1 -0
  78. package/lib/paste/utils/deprecatedColorParser.d.ts +5 -0
  79. package/lib/paste/utils/deprecatedColorParser.js +20 -0
  80. package/lib/paste/utils/deprecatedColorParser.js.map +1 -0
  81. package/lib/paste/utils/getStyles.d.ts +6 -0
  82. package/lib/paste/utils/getStyles.js +23 -0
  83. package/lib/paste/utils/getStyles.js.map +1 -0
  84. package/lib/paste/utils/linkParser.d.ts +5 -0
  85. package/lib/paste/utils/linkParser.js +28 -0
  86. package/lib/paste/utils/linkParser.js.map +1 -0
  87. package/lib/paste/utils/setProcessor.d.ts +5 -0
  88. package/lib/paste/utils/setProcessor.js +14 -0
  89. package/lib/paste/utils/setProcessor.js.map +1 -0
  90. package/lib-amd/edit/ContentModelEditPlugin.d.ts +35 -0
  91. package/lib-amd/edit/ContentModelEditPlugin.js +72 -0
  92. package/lib-amd/edit/ContentModelEditPlugin.js.map +1 -0
  93. package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -0
  94. package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js +21 -0
  95. package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -0
  96. package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -0
  97. package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +90 -0
  98. package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -0
  99. package/lib-amd/edit/deleteSteps/deleteWordSelection.d.ts +9 -0
  100. package/lib-amd/edit/deleteSteps/deleteWordSelection.js +170 -0
  101. package/lib-amd/edit/deleteSteps/deleteWordSelection.js.map +1 -0
  102. package/lib-amd/edit/handleKeyboardEventCommon.d.ts +15 -0
  103. package/lib-amd/edit/handleKeyboardEventCommon.js +56 -0
  104. package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -0
  105. package/lib-amd/edit/keyboardDelete.d.ts +9 -0
  106. package/lib-amd/edit/keyboardDelete.js +60 -0
  107. package/lib-amd/edit/keyboardDelete.js.map +1 -0
  108. package/lib-amd/edit/utils/getLeafSiblingBlock.d.ts +23 -0
  109. package/lib-amd/edit/utils/getLeafSiblingBlock.js +76 -0
  110. package/lib-amd/edit/utils/getLeafSiblingBlock.js.map +1 -0
  111. package/lib-amd/index.d.ts +2 -0
  112. package/lib-amd/index.js +8 -0
  113. package/lib-amd/index.js.map +1 -0
  114. package/lib-amd/paste/ContentModelPastePlugin.d.ts +42 -0
  115. package/lib-amd/paste/ContentModelPastePlugin.js +141 -0
  116. package/lib-amd/paste/ContentModelPastePlugin.js.map +1 -0
  117. package/lib-amd/paste/Excel/processPastedContentFromExcel.d.ts +13 -0
  118. package/lib-amd/paste/Excel/processPastedContentFromExcel.js +81 -0
  119. package/lib-amd/paste/Excel/processPastedContentFromExcel.js.map +1 -0
  120. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -0
  121. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js +21 -0
  122. package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -0
  123. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -0
  124. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js +207 -0
  125. package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js.map +1 -0
  126. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -0
  127. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +65 -0
  128. package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -0
  129. package/lib-amd/paste/WordDesktop/processWordComments.d.ts +7 -0
  130. package/lib-amd/paste/WordDesktop/processWordComments.js +23 -0
  131. package/lib-amd/paste/WordDesktop/processWordComments.js.map +1 -0
  132. package/lib-amd/paste/WordDesktop/processWordLists.d.ts +10 -0
  133. package/lib-amd/paste/WordDesktop/processWordLists.js +154 -0
  134. package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -0
  135. package/lib-amd/paste/pasteSourceValidations/constants.d.ts +17 -0
  136. package/lib-amd/paste/pasteSourceValidations/constants.js +24 -0
  137. package/lib-amd/paste/pasteSourceValidations/constants.js.map +1 -0
  138. package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -0
  139. package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js +27 -0
  140. package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -0
  141. package/lib-amd/paste/pasteSourceValidations/getPasteSource.d.ts +27 -0
  142. package/lib-amd/paste/pasteSourceValidations/getPasteSource.js +39 -0
  143. package/lib-amd/paste/pasteSourceValidations/getPasteSource.js.map +1 -0
  144. package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -0
  145. package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js +19 -0
  146. package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -0
  147. package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -0
  148. package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js +21 -0
  149. package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -0
  150. package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -0
  151. package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js +17 -0
  152. package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -0
  153. package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -0
  154. package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +17 -0
  155. package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -0
  156. package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -0
  157. package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js +21 -0
  158. package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -0
  159. package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -0
  160. package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.js +21 -0
  161. package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -0
  162. package/lib-amd/paste/utils/addParser.d.ts +5 -0
  163. package/lib-amd/paste/utils/addParser.js +19 -0
  164. package/lib-amd/paste/utils/addParser.js.map +1 -0
  165. package/lib-amd/paste/utils/deprecatedColorParser.d.ts +5 -0
  166. package/lib-amd/paste/utils/deprecatedColorParser.js +21 -0
  167. package/lib-amd/paste/utils/deprecatedColorParser.js.map +1 -0
  168. package/lib-amd/paste/utils/getStyles.d.ts +6 -0
  169. package/lib-amd/paste/utils/getStyles.js +25 -0
  170. package/lib-amd/paste/utils/getStyles.js.map +1 -0
  171. package/lib-amd/paste/utils/linkParser.d.ts +5 -0
  172. package/lib-amd/paste/utils/linkParser.js +29 -0
  173. package/lib-amd/paste/utils/linkParser.js.map +1 -0
  174. package/lib-amd/paste/utils/setProcessor.d.ts +5 -0
  175. package/lib-amd/paste/utils/setProcessor.js +16 -0
  176. package/lib-amd/paste/utils/setProcessor.js.map +1 -0
  177. package/lib-mjs/edit/ContentModelEditPlugin.d.ts +35 -0
  178. package/lib-mjs/edit/ContentModelEditPlugin.js +68 -0
  179. package/lib-mjs/edit/ContentModelEditPlugin.js.map +1 -0
  180. package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -0
  181. package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js +16 -0
  182. package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -0
  183. package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -0
  184. package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +88 -0
  185. package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -0
  186. package/lib-mjs/edit/deleteSteps/deleteWordSelection.d.ts +9 -0
  187. package/lib-mjs/edit/deleteSteps/deleteWordSelection.js +168 -0
  188. package/lib-mjs/edit/deleteSteps/deleteWordSelection.js.map +1 -0
  189. package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +15 -0
  190. package/lib-mjs/edit/handleKeyboardEventCommon.js +49 -0
  191. package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -0
  192. package/lib-mjs/edit/keyboardDelete.d.ts +9 -0
  193. package/lib-mjs/edit/keyboardDelete.js +60 -0
  194. package/lib-mjs/edit/keyboardDelete.js.map +1 -0
  195. package/lib-mjs/edit/utils/getLeafSiblingBlock.d.ts +23 -0
  196. package/lib-mjs/edit/utils/getLeafSiblingBlock.js +72 -0
  197. package/lib-mjs/edit/utils/getLeafSiblingBlock.js.map +1 -0
  198. package/lib-mjs/index.d.ts +2 -0
  199. package/lib-mjs/index.js +3 -0
  200. package/lib-mjs/index.js.map +1 -0
  201. package/lib-mjs/paste/ContentModelPastePlugin.d.ts +42 -0
  202. package/lib-mjs/paste/ContentModelPastePlugin.js +146 -0
  203. package/lib-mjs/paste/ContentModelPastePlugin.js.map +1 -0
  204. package/lib-mjs/paste/Excel/processPastedContentFromExcel.d.ts +13 -0
  205. package/lib-mjs/paste/Excel/processPastedContentFromExcel.js +78 -0
  206. package/lib-mjs/paste/Excel/processPastedContentFromExcel.js.map +1 -0
  207. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -0
  208. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js +16 -0
  209. package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -0
  210. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -0
  211. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js +204 -0
  212. package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js.map +1 -0
  213. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -0
  214. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +65 -0
  215. package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -0
  216. package/lib-mjs/paste/WordDesktop/processWordComments.d.ts +7 -0
  217. package/lib-mjs/paste/WordDesktop/processWordComments.js +18 -0
  218. package/lib-mjs/paste/WordDesktop/processWordComments.js.map +1 -0
  219. package/lib-mjs/paste/WordDesktop/processWordLists.d.ts +10 -0
  220. package/lib-mjs/paste/WordDesktop/processWordLists.js +151 -0
  221. package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -0
  222. package/lib-mjs/paste/pasteSourceValidations/constants.d.ts +17 -0
  223. package/lib-mjs/paste/pasteSourceValidations/constants.js +19 -0
  224. package/lib-mjs/paste/pasteSourceValidations/constants.js.map +1 -0
  225. package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -0
  226. package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js +21 -0
  227. package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -0
  228. package/lib-mjs/paste/pasteSourceValidations/getPasteSource.d.ts +27 -0
  229. package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js +40 -0
  230. package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js.map +1 -0
  231. package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -0
  232. package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js +13 -0
  233. package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -0
  234. package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -0
  235. package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js +15 -0
  236. package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -0
  237. package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -0
  238. package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js +11 -0
  239. package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -0
  240. package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -0
  241. package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +11 -0
  242. package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -0
  243. package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -0
  244. package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js +15 -0
  245. package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -0
  246. package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -0
  247. package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.js +15 -0
  248. package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -0
  249. package/lib-mjs/paste/utils/addParser.d.ts +5 -0
  250. package/lib-mjs/paste/utils/addParser.js +14 -0
  251. package/lib-mjs/paste/utils/addParser.js.map +1 -0
  252. package/lib-mjs/paste/utils/deprecatedColorParser.d.ts +5 -0
  253. package/lib-mjs/paste/utils/deprecatedColorParser.js +16 -0
  254. package/lib-mjs/paste/utils/deprecatedColorParser.js.map +1 -0
  255. package/lib-mjs/paste/utils/getStyles.d.ts +6 -0
  256. package/lib-mjs/paste/utils/getStyles.js +19 -0
  257. package/lib-mjs/paste/utils/getStyles.js.map +1 -0
  258. package/lib-mjs/paste/utils/linkParser.d.ts +5 -0
  259. package/lib-mjs/paste/utils/linkParser.js +24 -0
  260. package/lib-mjs/paste/utils/linkParser.js.map +1 -0
  261. package/lib-mjs/paste/utils/setProcessor.d.ts +5 -0
  262. package/lib-mjs/paste/utils/setProcessor.js +10 -0
  263. package/lib-mjs/paste/utils/setProcessor.js.map +1 -0
  264. package/package.json +22 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.backwardDeleteWordSelection = exports.forwardDeleteWordSelection = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
6
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
+ var DeleteWordState;
8
+ (function (DeleteWordState) {
9
+ DeleteWordState[DeleteWordState["Start"] = 0] = "Start";
10
+ DeleteWordState[DeleteWordState["Punctuation"] = 1] = "Punctuation";
11
+ DeleteWordState[DeleteWordState["Text"] = 2] = "Text";
12
+ DeleteWordState[DeleteWordState["NonText"] = 3] = "NonText";
13
+ DeleteWordState[DeleteWordState["Space"] = 4] = "Space";
14
+ DeleteWordState[DeleteWordState["End"] = 5] = "End";
15
+ })(DeleteWordState || (DeleteWordState = {}));
16
+ function getDeleteWordSelection(direction) {
17
+ return function (context) {
18
+ var _a = context.insertPoint, marker = _a.marker, paragraph = _a.paragraph;
19
+ var startIndex = paragraph.segments.indexOf(marker);
20
+ var deleteNext = direction == 'forward';
21
+ var iterator = iterateSegments(paragraph, startIndex, deleteNext, context);
22
+ var curr = iterator.next();
23
+ for (var state = 0 /* Start */; state != 5 /* End */ && !curr.done;) {
24
+ var _b = curr.value, punctuation = _b.punctuation, space = _b.space, text = _b.text;
25
+ // This is a state machine of how to delete a whole word together with space and punctuations.
26
+ // For a full state machine chart, see
27
+ // Forward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/ForwardDeleteWord.png
28
+ // Backward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/BackwardDeleteWord.png
29
+ switch (state) {
30
+ case 0 /* Start */:
31
+ state = space
32
+ ? 4 /* Space */
33
+ : punctuation
34
+ ? 1 /* Punctuation */
35
+ : 2 /* Text */;
36
+ curr = iterator.next(true /*delete*/);
37
+ break;
38
+ case 1 /* Punctuation */:
39
+ if (deleteNext && space) {
40
+ state = 3 /* NonText */;
41
+ curr = iterator.next(true /*delete*/);
42
+ }
43
+ else if (punctuation) {
44
+ curr = iterator.next(true /*delete*/);
45
+ }
46
+ else {
47
+ state = 5 /* End */;
48
+ }
49
+ break;
50
+ case 2 /* Text */:
51
+ if (deleteNext && space) {
52
+ state = 3 /* NonText */;
53
+ curr = iterator.next(true /*delete*/);
54
+ }
55
+ else if (text) {
56
+ curr = iterator.next(true /*delete*/);
57
+ }
58
+ else {
59
+ state = 5 /* End */;
60
+ }
61
+ break;
62
+ case 3 /* NonText */:
63
+ if (punctuation || !space) {
64
+ state = 5 /* End */;
65
+ }
66
+ else {
67
+ curr = iterator.next(true /*delete*/);
68
+ }
69
+ break;
70
+ case 4 /* Space */:
71
+ if (space) {
72
+ curr = iterator.next(true /*delete*/);
73
+ }
74
+ else if (punctuation) {
75
+ state = deleteNext ? 3 /* NonText */ : 1 /* Punctuation */;
76
+ curr = iterator.next(true /*delete*/);
77
+ }
78
+ else {
79
+ state = deleteNext ? 5 /* End */ : 2 /* Text */;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+ };
85
+ }
86
+ function iterateSegments(paragraph, markerIndex, forward, context) {
87
+ var step, segments, preserveWhiteSpace, i, segment, _a, j, c, punctuation, space, text, newText;
88
+ return (0, tslib_1.__generator)(this, function (_b) {
89
+ switch (_b.label) {
90
+ case 0:
91
+ step = forward ? 1 : -1;
92
+ segments = paragraph.segments;
93
+ preserveWhiteSpace = (0, roosterjs_content_model_dom_1.isWhiteSpacePreserved)(paragraph);
94
+ i = markerIndex + step;
95
+ _b.label = 1;
96
+ case 1:
97
+ if (!(i >= 0 && i < segments.length)) return [3 /*break*/, 12];
98
+ segment = segments[i];
99
+ _a = segment.segmentType;
100
+ switch (_a) {
101
+ case 'Text': return [3 /*break*/, 2];
102
+ case 'Image': return [3 /*break*/, 7];
103
+ case 'SelectionMarker': return [3 /*break*/, 9];
104
+ }
105
+ return [3 /*break*/, 10];
106
+ case 2:
107
+ j = forward ? 0 : segment.text.length - 1;
108
+ _b.label = 3;
109
+ case 3:
110
+ if (!(j >= 0 && j < segment.text.length)) return [3 /*break*/, 6];
111
+ c = segment.text[j];
112
+ punctuation = (0, roosterjs_content_model_core_1.isPunctuation)(c);
113
+ space = (0, roosterjs_content_model_core_1.isSpace)(c);
114
+ text = !punctuation && !space;
115
+ return [4 /*yield*/, { punctuation: punctuation, space: space, text: text }];
116
+ case 4:
117
+ if (_b.sent()) {
118
+ newText = segment.text;
119
+ newText = newText.substring(0, j) + newText.substring(j + 1);
120
+ if (!preserveWhiteSpace) {
121
+ newText = (0, roosterjs_content_model_core_1.normalizeText)(newText, forward);
122
+ }
123
+ context.deleteResult = 'range';
124
+ if (newText) {
125
+ segment.text = newText;
126
+ if (step > 0) {
127
+ j -= step;
128
+ }
129
+ }
130
+ else {
131
+ segments.splice(i, 1);
132
+ if (step > 0) {
133
+ i -= step;
134
+ }
135
+ return [3 /*break*/, 6];
136
+ }
137
+ }
138
+ _b.label = 5;
139
+ case 5:
140
+ j += step;
141
+ return [3 /*break*/, 3];
142
+ case 6: return [3 /*break*/, 11];
143
+ case 7: return [4 /*yield*/, { punctuation: true, space: false, text: false }]; // Treat image as punctuation since they have the same behavior.
144
+ case 8:
145
+ if (_b.sent() // Treat image as punctuation since they have the same behavior.
146
+ ) {
147
+ segments.splice(i, 1);
148
+ if (step > 0) {
149
+ i -= step;
150
+ }
151
+ context.deleteResult = 'range';
152
+ }
153
+ return [3 /*break*/, 11];
154
+ case 9: return [3 /*break*/, 11];
155
+ case 10: return [2 /*return*/, null];
156
+ case 11:
157
+ i += step;
158
+ return [3 /*break*/, 1];
159
+ case 12: return [2 /*return*/, null];
160
+ }
161
+ });
162
+ }
163
+ /**
164
+ * @internal
165
+ */
166
+ exports.forwardDeleteWordSelection = getDeleteWordSelection('forward');
167
+ /**
168
+ * @internal
169
+ */
170
+ exports.backwardDeleteWordSelection = getDeleteWordSelection('backward');
171
+ //# sourceMappingURL=deleteWordSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteWordSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteWordSelection.ts"],"names":[],"mappings":";;;;AAAA,6EAAqF;AACrF,2EAAoE;AAOpE,IAAW,eAOV;AAPD,WAAW,eAAe;IACtB,uDAAK,CAAA;IACL,mEAAW,CAAA;IACX,qDAAI,CAAA;IACJ,2DAAO,CAAA;IACP,uDAAK,CAAA;IACL,mDAAG,CAAA;AACP,CAAC,EAPU,eAAe,KAAf,eAAe,QAOzB;AAQD,SAAS,sBAAsB,CAAC,SAAiC;IAC7D,OAAO,UAAA,OAAO;QACJ,I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,CAAC,CAAC;wBAEtB,IAAI,IAAI,GAAG,CAAC,EAAE;4BACV,CAAC,IAAI,IAAI,CAAC;yBACb;wBAED,wBAAM;qBACT;iBACJ;;;gBAjCD,CAAC,IAAI,IAAI,CAAA;;oBAmCb,yBAAM;oBAIF,qBAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAA,CAAC,gEAAgE;;gBAD3H,IACI,SAAsD,CAAC,gEAAgE;kBACzH;oBACE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAEtB,IAAI,IAAI,GAAG,CAAC,EAAE;wBACV,CAAC,IAAI,IAAI,CAAC;qBACb;oBAED,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;iBAClC;gBACD,yBAAM;oBAGN,yBAAM;qBAGN,sBAAO,IAAI,EAAC;;gBA/DwC,CAAC,IAAI,IAAI,CAAA;;qBAmEzE,sBAAO,IAAI,EAAC;;;CACf;AAED;;GAEG;AACU,QAAA,0BAA0B,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACU,QAAA,2BAA2B,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { isPunctuation, isSpace, normalizeText } from 'roosterjs-content-model-core';\nimport { isWhiteSpacePreserved } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelParagraph,\n DeleteSelectionContext,\n DeleteSelectionStep,\n} from 'roosterjs-content-model-types';\n\nconst enum DeleteWordState {\n Start,\n Punctuation,\n Text,\n NonText,\n Space,\n End,\n}\n\ninterface CharInfo {\n text: boolean;\n space: boolean;\n punctuation: boolean;\n}\n\nfunction getDeleteWordSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n const { marker, paragraph } = context.insertPoint;\n const startIndex = paragraph.segments.indexOf(marker);\n const deleteNext = direction == 'forward';\n\n const iterator = iterateSegments(paragraph, startIndex, deleteNext, context);\n let curr = iterator.next();\n\n for (let state = DeleteWordState.Start; state != DeleteWordState.End && !curr.done; ) {\n const { punctuation, space, text } = curr.value;\n\n // This is a state machine of how to delete a whole word together with space and punctuations.\n // For a full state machine chart, see\n // Forward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/ForwardDeleteWord.png\n // Backward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/BackwardDeleteWord.png\n switch (state) {\n case DeleteWordState.Start:\n state = space\n ? DeleteWordState.Space\n : punctuation\n ? DeleteWordState.Punctuation\n : DeleteWordState.Text;\n curr = iterator.next(true /*delete*/);\n break;\n\n case DeleteWordState.Punctuation:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.Text:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (text) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.NonText:\n if (punctuation || !space) {\n state = DeleteWordState.End;\n } else {\n curr = iterator.next(true /*delete*/);\n }\n break;\n\n case DeleteWordState.Space:\n if (space) {\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n state = deleteNext ? DeleteWordState.NonText : DeleteWordState.Punctuation;\n curr = iterator.next(true /*delete*/);\n } else {\n state = deleteNext ? DeleteWordState.End : DeleteWordState.Text;\n }\n break;\n }\n }\n };\n}\n\nfunction* iterateSegments(\n paragraph: ContentModelParagraph,\n markerIndex: number,\n forward: boolean,\n context: DeleteSelectionContext\n): Generator<CharInfo, null, boolean> {\n const step = forward ? 1 : -1;\n const segments = paragraph.segments;\n const preserveWhiteSpace = isWhiteSpacePreserved(paragraph);\n\n for (let i = markerIndex + step; i >= 0 && i < segments.length; i += step) {\n const segment = segments[i];\n\n switch (segment.segmentType) {\n case 'Text':\n for (\n let j = forward ? 0 : segment.text.length - 1;\n j >= 0 && j < segment.text.length;\n j += step\n ) {\n const c = segment.text[j];\n const punctuation = isPunctuation(c);\n const space = isSpace(c);\n const text = !punctuation && !space;\n\n if (yield { punctuation, space, text }) {\n let newText = segment.text;\n\n newText = newText.substring(0, j) + newText.substring(j + 1);\n\n if (!preserveWhiteSpace) {\n newText = normalizeText(newText, forward);\n }\n\n context.deleteResult = 'range';\n\n if (newText) {\n segment.text = newText;\n\n if (step > 0) {\n j -= step;\n }\n } else {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n break;\n }\n }\n }\n break;\n\n case 'Image':\n if (\n yield { punctuation: true, space: false, text: false } // Treat image as punctuation since they have the same behavior.\n ) {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n context.deleteResult = 'range';\n }\n break;\n\n case 'SelectionMarker':\n break;\n\n default:\n return null;\n }\n }\n\n return null;\n}\n\n/**\n * @internal\n */\nexport const forwardDeleteWordSelection = getDeleteWordSelection('forward');\n\n/**\n * @internal\n */\nexport const backwardDeleteWordSelection = getDeleteWordSelection('backward');\n"]}
@@ -0,0 +1,15 @@
1
+ import type { IContentModelEditor } from 'roosterjs-content-model-editor';
2
+ import type { ContentModelDocument, DeleteResult, FormatWithContentModelContext } from 'roosterjs-content-model-types';
3
+ /**
4
+ * @internal
5
+ * @return True means content is changed, so need to rewrite content model to editor. Otherwise false
6
+ */
7
+ export declare function handleKeyboardEventResult(editor: IContentModelEditor, model: ContentModelDocument, rawEvent: KeyboardEvent, result: DeleteResult, context: FormatWithContentModelContext): boolean;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare function shouldDeleteWord(rawEvent: KeyboardEvent, isMac: boolean): boolean;
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare function shouldDeleteAllSegmentsBefore(rawEvent: KeyboardEvent): boolean;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldDeleteAllSegmentsBefore = exports.shouldDeleteWord = exports.handleKeyboardEventResult = void 0;
4
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
5
+ /**
6
+ * @internal
7
+ * @return True means content is changed, so need to rewrite content model to editor. Otherwise false
8
+ */
9
+ function handleKeyboardEventResult(editor, model, rawEvent, result, context) {
10
+ context.skipUndoSnapshot = true;
11
+ context.clearModelCache = false;
12
+ switch (result) {
13
+ case 'notDeleted':
14
+ // We have not delete anything, we will let browser handle this event, so that current cached model may be invalid
15
+ context.clearModelCache = true;
16
+ // Return false here since we didn't do any change to Content Model, so no need to rewrite with Content Model
17
+ return false;
18
+ case 'nothingToDelete':
19
+ // We known there is nothing to delete, no need to let browser keep handling the event
20
+ rawEvent.preventDefault();
21
+ return false;
22
+ case 'range':
23
+ case 'singleChar':
24
+ // We have deleted what we need from content model, no need to let browser keep handling the event
25
+ rawEvent.preventDefault();
26
+ (0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
27
+ if (result == 'range') {
28
+ // A range is about to be deleted, so add an undo snapshot immediately
29
+ context.skipUndoSnapshot = false;
30
+ }
31
+ // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.
32
+ // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.
33
+ editor.triggerPluginEvent(23 /* BeforeKeyboardEditing */, {
34
+ rawEvent: rawEvent,
35
+ });
36
+ return true;
37
+ }
38
+ }
39
+ exports.handleKeyboardEventResult = handleKeyboardEventResult;
40
+ /**
41
+ * @internal
42
+ */
43
+ function shouldDeleteWord(rawEvent, isMac) {
44
+ return ((isMac && rawEvent.altKey && !rawEvent.metaKey) ||
45
+ (!isMac && rawEvent.ctrlKey && !rawEvent.altKey));
46
+ }
47
+ exports.shouldDeleteWord = shouldDeleteWord;
48
+ /**
49
+ * @internal
50
+ */
51
+ function shouldDeleteAllSegmentsBefore(rawEvent) {
52
+ return rawEvent.metaKey && !rawEvent.altKey;
53
+ }
54
+ exports.shouldDeleteAllSegmentsBefore = shouldDeleteAllSegmentsBefore;
55
+ //# sourceMappingURL=handleKeyboardEventCommon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleKeyboardEventCommon.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/handleKeyboardEventCommon.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AASpE;;;GAGG;AACH,SAAgB,yBAAyB,CACrC,MAA2B,EAC3B,KAA2B,EAC3B,QAAuB,EACvB,MAAoB,EACpB,OAAsC;IAEtC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAChC,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC;IAEhC,QAAQ,MAAM,EAAE;QACZ,KAAK,YAAY;YACb,kHAAkH;YAClH,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,6GAA6G;YAC7G,OAAO,KAAK,CAAC;QAEjB,KAAK,iBAAiB;YAClB,sFAAsF;YACtF,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QAEjB,KAAK,OAAO,CAAC;QACb,KAAK,YAAY;YACb,kGAAkG;YAClG,QAAQ,CAAC,cAAc,EAAE,CAAC;YAC1B,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;YAE7B,IAAI,MAAM,IAAI,OAAO,EAAE;gBACnB,sEAAsE;gBACtE,OAAO,CAAC,gBAAgB,GAAG,KAAK,CAAC;aACpC;YAED,6GAA6G;YAC7G,oHAAoH;YACpH,MAAM,CAAC,kBAAkB,iCAAwC;gBAC7D,QAAQ,UAAA;aACX,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;KACnB;AACL,CAAC;AA1CD,8DA0CC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAuB,EAAE,KAAc;IACpE,OAAO,CACH,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAC/C,CAAC,CAAC,KAAK,IAAI,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CACnD,CAAC;AACN,CAAC;AALD,4CAKC;AAED;;GAEG;AACH,SAAgB,6BAA6B,CAAC,QAAuB;IACjE,OAAO,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AAChD,CAAC;AAFD,sEAEC","sourcesContent":["import { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n ContentModelDocument,\n DeleteResult,\n FormatWithContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * @return True means content is changed, so need to rewrite content model to editor. Otherwise false\n */\nexport function handleKeyboardEventResult(\n editor: IContentModelEditor,\n model: ContentModelDocument,\n rawEvent: KeyboardEvent,\n result: DeleteResult,\n context: FormatWithContentModelContext\n): boolean {\n context.skipUndoSnapshot = true;\n context.clearModelCache = false;\n\n switch (result) {\n case 'notDeleted':\n // We have not delete anything, we will let browser handle this event, so that current cached model may be invalid\n context.clearModelCache = true;\n\n // Return false here since we didn't do any change to Content Model, so no need to rewrite with Content Model\n return false;\n\n case 'nothingToDelete':\n // We known there is nothing to delete, no need to let browser keep handling the event\n rawEvent.preventDefault();\n return false;\n\n case 'range':\n case 'singleChar':\n // We have deleted what we need from content model, no need to let browser keep handling the event\n rawEvent.preventDefault();\n normalizeContentModel(model);\n\n if (result == 'range') {\n // A range is about to be deleted, so add an undo snapshot immediately\n context.skipUndoSnapshot = false;\n }\n\n // Trigger an event to let plugins know the content is about to be changed by Content Model keyboard editing.\n // So plugins can do proper handling. e.g. UndoPlugin can decide whether take a snapshot before this change happens.\n editor.triggerPluginEvent(PluginEventType.BeforeKeyboardEditing, {\n rawEvent,\n });\n\n return true;\n }\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteWord(rawEvent: KeyboardEvent, isMac: boolean) {\n return (\n (isMac && rawEvent.altKey && !rawEvent.metaKey) ||\n (!isMac && rawEvent.ctrlKey && !rawEvent.altKey)\n );\n}\n\n/**\n * @internal\n */\nexport function shouldDeleteAllSegmentsBefore(rawEvent: KeyboardEvent) {\n return rawEvent.metaKey && !rawEvent.altKey;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { IContentModelEditor } from 'roosterjs-content-model-editor';
2
+ /**
3
+ * @internal
4
+ * Do keyboard event handling for DELETE/BACKSPACE key
5
+ * @param editor The Content Model Editor
6
+ * @param rawEvent DOM keyboard event
7
+ * @returns True if the event is handled with this function, otherwise false
8
+ */
9
+ export declare function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): boolean;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keyboardDelete = void 0;
4
+ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
5
+ var deleteAllSegmentBefore_1 = require("./deleteSteps/deleteAllSegmentBefore");
6
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
+ var handleKeyboardEventCommon_1 = require("./handleKeyboardEventCommon");
8
+ var deleteWordSelection_1 = require("./deleteSteps/deleteWordSelection");
9
+ var deleteCollapsedSelection_1 = require("./deleteSteps/deleteCollapsedSelection");
10
+ /**
11
+ * @internal
12
+ * Do keyboard event handling for DELETE/BACKSPACE key
13
+ * @param editor The Content Model Editor
14
+ * @param rawEvent DOM keyboard event
15
+ * @returns True if the event is handled with this function, otherwise false
16
+ */
17
+ function keyboardDelete(editor, rawEvent) {
18
+ var selection = editor.getDOMSelection();
19
+ var range = (selection === null || selection === void 0 ? void 0 : selection.type) == 'range' ? selection.range : null;
20
+ var isDeleted = false;
21
+ if (shouldDeleteWithContentModel(range, rawEvent)) {
22
+ editor.formatContentModel(function (model, context) {
23
+ var result = (0, roosterjs_content_model_core_1.deleteSelection)(model, getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac), context).deleteResult;
24
+ isDeleted = result != 'notDeleted';
25
+ return (0, handleKeyboardEventCommon_1.handleKeyboardEventResult)(editor, model, rawEvent, result, context);
26
+ }, {
27
+ rawEvent: rawEvent,
28
+ changeSource: roosterjs_content_model_core_1.ChangeSource.Keyboard,
29
+ getChangeData: function () { return rawEvent.which; },
30
+ apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',
31
+ });
32
+ return true;
33
+ }
34
+ return isDeleted;
35
+ }
36
+ exports.keyboardDelete = keyboardDelete;
37
+ function getDeleteSteps(rawEvent, isMac) {
38
+ var isForward = rawEvent.key == 'Delete';
39
+ var deleteAllSegmentBeforeStep = (0, handleKeyboardEventCommon_1.shouldDeleteAllSegmentsBefore)(rawEvent) && !isForward ? deleteAllSegmentBefore_1.deleteAllSegmentBefore : null;
40
+ var deleteWordSelection = (0, handleKeyboardEventCommon_1.shouldDeleteWord)(rawEvent, isMac)
41
+ ? isForward
42
+ ? deleteWordSelection_1.forwardDeleteWordSelection
43
+ : deleteWordSelection_1.backwardDeleteWordSelection
44
+ : null;
45
+ var deleteCollapsedSelection = isForward
46
+ ? deleteCollapsedSelection_1.forwardDeleteCollapsedSelection
47
+ : deleteCollapsedSelection_1.backwardDeleteCollapsedSelection;
48
+ return [deleteAllSegmentBeforeStep, deleteWordSelection, deleteCollapsedSelection];
49
+ }
50
+ function shouldDeleteWithContentModel(range, rawEvent) {
51
+ return !((range === null || range === void 0 ? void 0 : range.collapsed) &&
52
+ (0, roosterjs_content_model_dom_1.isNodeOfType)(range.startContainer, 'TEXT_NODE') &&
53
+ !(0, roosterjs_content_model_core_1.isModifierKey)(rawEvent) &&
54
+ (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range)));
55
+ }
56
+ function canDeleteBefore(rawEvent, range) {
57
+ return rawEvent.key == 'Backspace' && range.startOffset > 1;
58
+ }
59
+ function canDeleteAfter(rawEvent, range) {
60
+ var _a, _b;
61
+ return (rawEvent.key == 'Delete' &&
62
+ range.startOffset < ((_b = (_a = range.startContainer.nodeValue) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1);
63
+ }
64
+ //# sourceMappingURL=keyboardDelete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboardDelete.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardDelete.ts"],"names":[],"mappings":";;;AAAA,6EAA4F;AAC5F,+EAA8E;AAC9E,2EAA2D;AAC3D,yEAIqC;AACrC,yEAG2C;AAC3C,mFAGgD;AAIhD;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAA2B,EAAE,QAAuB;IAC/E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC3C,IAAM,KAAK,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAClE,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,IAAI,4BAA4B,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE;QAC/C,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAC1B,KAAK,EACL,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,EACzD,OAAO,CACV,CAAC,YAAY,CAAC;YAEf,SAAS,GAAG,MAAM,IAAI,YAAY,CAAC;YAEnC,OAAO,IAAA,qDAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/E,CAAC,EACD;YACI,QAAQ,UAAA;YACR,YAAY,EAAE,2CAAY,CAAC,QAAQ;YACnC,aAAa,EAAE,cAAM,OAAA,QAAQ,CAAC,KAAK,EAAd,CAAc;YACnC,OAAO,EAA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,WAAW,GAAG,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,QAAuB,EAAE,KAAY;;IACzD,OAAO,CACH,QAAQ,CAAC,GAAG,IAAI,QAAQ;QACxB,KAAK,CAAC,WAAW,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,cAAc,CAAC,SAAS,0CAAE,MAAM,mCAAI,CAAC,CAAC,GAAG,CAAC,CACxE,CAAC;AACN,CAAC","sourcesContent":["import { ChangeSource, deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { deleteAllSegmentBefore } from './deleteSteps/deleteAllSegmentBefore';\nimport { isNodeOfType } from 'roosterjs-content-model-dom';\nimport {\n handleKeyboardEventResult,\n shouldDeleteAllSegmentsBefore,\n shouldDeleteWord,\n} from './handleKeyboardEventCommon';\nimport {\n backwardDeleteWordSelection,\n forwardDeleteWordSelection,\n} from './deleteSteps/deleteWordSelection';\nimport {\n backwardDeleteCollapsedSelection,\n forwardDeleteCollapsedSelection,\n} from './deleteSteps/deleteCollapsedSelection';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type { DeleteSelectionStep } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Do keyboard event handling for DELETE/BACKSPACE key\n * @param editor The Content Model Editor\n * @param rawEvent DOM keyboard event\n * @returns True if the event is handled with this function, otherwise false\n */\nexport function keyboardDelete(editor: IContentModelEditor, rawEvent: KeyboardEvent): boolean {\n const selection = editor.getDOMSelection();\n const range = selection?.type == 'range' ? selection.range : null;\n let isDeleted = false;\n\n if (shouldDeleteWithContentModel(range, rawEvent)) {\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(\n model,\n getDeleteSteps(rawEvent, !!editor.getEnvironment().isMac),\n context\n ).deleteResult;\n\n isDeleted = result != 'notDeleted';\n\n return handleKeyboardEventResult(editor, model, rawEvent, result, context);\n },\n {\n rawEvent,\n changeSource: ChangeSource.Keyboard,\n getChangeData: () => rawEvent.which,\n apiName: rawEvent.key == 'Delete' ? 'handleDeleteKey' : 'handleBackspaceKey',\n }\n );\n\n return true;\n }\n\n return isDeleted;\n}\n\nfunction getDeleteSteps(rawEvent: KeyboardEvent, isMac: boolean): (DeleteSelectionStep | null)[] {\n const isForward = rawEvent.key == 'Delete';\n const deleteAllSegmentBeforeStep =\n shouldDeleteAllSegmentsBefore(rawEvent) && !isForward ? deleteAllSegmentBefore : null;\n const deleteWordSelection = shouldDeleteWord(rawEvent, isMac)\n ? isForward\n ? forwardDeleteWordSelection\n : backwardDeleteWordSelection\n : null;\n const deleteCollapsedSelection = isForward\n ? forwardDeleteCollapsedSelection\n : backwardDeleteCollapsedSelection;\n return [deleteAllSegmentBeforeStep, deleteWordSelection, deleteCollapsedSelection];\n}\n\nfunction shouldDeleteWithContentModel(range: Range | null, rawEvent: KeyboardEvent) {\n return !(\n range?.collapsed &&\n isNodeOfType(range.startContainer, 'TEXT_NODE') &&\n !isModifierKey(rawEvent) &&\n (canDeleteBefore(rawEvent, range) || canDeleteAfter(rawEvent, range))\n );\n}\n\nfunction canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {\n return rawEvent.key == 'Backspace' && range.startOffset > 1;\n}\n\nfunction canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {\n return (\n rawEvent.key == 'Delete' &&\n range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1\n );\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { ContentModelBlock, ContentModelBlockGroup, ContentModelSegment } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare type BlockAndPath = {
6
+ /**
7
+ * The sibling block
8
+ */
9
+ block: ContentModelBlock;
10
+ /**
11
+ * Path of this sibling block
12
+ */
13
+ path: ContentModelBlockGroup[];
14
+ /**
15
+ * If the input block is under a general segment, it is possible there are sibling segments under the same paragraph.
16
+ * Use this property to return the sibling sibling under the same paragraph
17
+ */
18
+ siblingSegment?: ContentModelSegment;
19
+ };
20
+ /**
21
+ * @internal
22
+ */
23
+ export declare function getLeafSiblingBlock(path: ContentModelBlockGroup[], block: ContentModelBlock, isNext: boolean): BlockAndPath | null;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLeafSiblingBlock = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
+ /**
7
+ * @internal
8
+ */
9
+ function getLeafSiblingBlock(path, block, isNext) {
10
+ var _a;
11
+ var newPath = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(path), false);
12
+ var _loop_1 = function () {
13
+ var group = newPath[0];
14
+ var index = group.blocks.indexOf(block);
15
+ if (index < 0) {
16
+ return "break";
17
+ }
18
+ var nextBlock = group.blocks[index + (isNext ? 1 : -1)];
19
+ if (nextBlock) {
20
+ while (nextBlock.blockType == 'BlockGroup') {
21
+ var child = nextBlock.blocks[isNext ? 0 : nextBlock.blocks.length - 1];
22
+ if (!child) {
23
+ return { value: { block: nextBlock, path: newPath } };
24
+ }
25
+ else if (child.blockType != 'BlockGroup') {
26
+ newPath.unshift(nextBlock);
27
+ return { value: { block: child, path: newPath } };
28
+ }
29
+ else {
30
+ newPath.unshift(nextBlock);
31
+ nextBlock = child;
32
+ }
33
+ }
34
+ return { value: { block: nextBlock, path: newPath } };
35
+ }
36
+ else if ((0, roosterjs_content_model_dom_1.isGeneralSegment)(group)) {
37
+ // For general segment, we need to check if there is sibling segment under the same paragraph
38
+ // First let's find the parent paragraph of this segment
39
+ newPath.shift();
40
+ var segmentIndex_1 = -1;
41
+ var segment_1 = group;
42
+ var para = (_a = newPath[0]) === null || _a === void 0 ? void 0 : _a.blocks.find(function (x) { return x.blockType == 'Paragraph' && (segmentIndex_1 = x.segments.indexOf(segment_1)) >= 0; });
43
+ if (para) {
44
+ // Now we have found the parent paragraph, so let's check if it has a sibling segment
45
+ var siblingSegment = para.segments[segmentIndex_1 + (isNext ? 1 : -1)];
46
+ if (siblingSegment) {
47
+ return { value: { block: para, path: newPath, siblingSegment: siblingSegment } };
48
+ }
49
+ else {
50
+ // No sibling segment, let's keep go upper level
51
+ block = para;
52
+ }
53
+ }
54
+ else {
55
+ return "break";
56
+ }
57
+ }
58
+ else if (group.blockGroupType != 'Document' && group.blockGroupType != 'TableCell') {
59
+ newPath.shift();
60
+ block = group;
61
+ }
62
+ else {
63
+ return "break";
64
+ }
65
+ };
66
+ while (newPath.length > 0) {
67
+ var state_1 = _loop_1();
68
+ if (typeof state_1 === "object")
69
+ return state_1.value;
70
+ if (state_1 === "break")
71
+ break;
72
+ }
73
+ return null;
74
+ }
75
+ exports.getLeafSiblingBlock = getLeafSiblingBlock;
76
+ //# sourceMappingURL=getLeafSiblingBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLeafSiblingBlock.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/utils/getLeafSiblingBlock.ts"],"names":[],"mappings":";;;;AAAA,2EAA+D;AA6B/D;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,IAA8B,EAC9B,KAAwB,EACxB,MAAe;;IAEf,IAAM,OAAO,sDAAO,IAAI,SAAC,CAAC;;QAGtB,IAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAE1C,IAAI,KAAK,GAAG,CAAC,EAAE;;SAEd;QAED,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAExD,IAAI,SAAS,EAAE;YACX,OAAO,SAAS,CAAC,SAAS,IAAI,YAAY,EAAE;gBACxC,IAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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A,EAAE;iBACxD;qBAAM;oBACH,gDAAgD;oBAChD,KAAK,GAAG,IAAI,CAAC;iBAChB;aACJ;iBAAM;;aAGN;SACJ;aAAM,IAAI,KAAK,CAAC,cAAc,IAAI,UAAU,IAAI,KAAK,CAAC,cAAc,IAAI,WAAW,EAAE;YAClF,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,KAAK,GAAG,KAAK,CAAC;SACjB;aAAM;;SAEN;;IAzDL,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC;;;;;;KA0DxB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AApED,kDAoEC","sourcesContent":["import { isGeneralSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelParagraph,\n ContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport type BlockAndPath = {\n /**\n * The sibling block\n */\n block: ContentModelBlock;\n\n /**\n * Path of this sibling block\n */\n path: ContentModelBlockGroup[];\n\n /**\n * If the input block is under a general segment, it is possible there are sibling segments under the same paragraph.\n * Use this property to return the sibling sibling under the same paragraph\n */\n siblingSegment?: ContentModelSegment;\n};\n\n/**\n * @internal\n */\nexport function getLeafSiblingBlock(\n path: ContentModelBlockGroup[],\n block: ContentModelBlock,\n isNext: boolean\n): BlockAndPath | null {\n const newPath = [...path];\n\n while (newPath.length > 0) {\n const group = newPath[0];\n const index = group.blocks.indexOf(block);\n\n if (index < 0) {\n break;\n }\n\n let nextBlock = group.blocks[index + (isNext ? 1 : -1)];\n\n if (nextBlock) {\n while (nextBlock.blockType == 'BlockGroup') {\n const child = nextBlock.blocks[isNext ? 0 : nextBlock.blocks.length - 1];\n\n if (!child) {\n return { block: nextBlock, path: newPath };\n } else if (child.blockType != 'BlockGroup') {\n newPath.unshift(nextBlock);\n return { block: child, path: newPath };\n } else {\n newPath.unshift(nextBlock);\n nextBlock = child;\n }\n }\n\n return { block: nextBlock, path: newPath };\n } else if (isGeneralSegment(group)) {\n // For general segment, we need to check if there is sibling segment under the same paragraph\n // First let's find the parent paragraph of this segment\n newPath.shift();\n\n let segmentIndex = -1;\n const segment = group;\n const para = newPath[0]?.blocks.find(\n x => x.blockType == 'Paragraph' && (segmentIndex = x.segments.indexOf(segment)) >= 0\n ) as ContentModelParagraph;\n\n if (para) {\n // Now we have found the parent paragraph, so let's check if it has a sibling segment\n const siblingSegment = para.segments[segmentIndex + (isNext ? 1 : -1)];\n\n if (siblingSegment) {\n // Return this block, path and segment since we have found it\n return { block: para, path: newPath, siblingSegment };\n } else {\n // No sibling segment, let's keep go upper level\n block = para;\n }\n } else {\n // Parent sibling is not found (in theory this should never happen), just return null\n break;\n }\n } else if (group.blockGroupType != 'Document' && group.blockGroupType != 'TableCell') {\n newPath.shift();\n block = group;\n } else {\n break;\n }\n }\n\n return null;\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';
2
+ export { ContentModelEditPlugin } from './edit/ContentModelEditPlugin';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentModelEditPlugin = exports.ContentModelPastePlugin = void 0;
4
+ var ContentModelPastePlugin_1 = require("./paste/ContentModelPastePlugin");
5
+ Object.defineProperty(exports, "ContentModelPastePlugin", { enumerable: true, get: function () { return ContentModelPastePlugin_1.ContentModelPastePlugin; } });
6
+ var ContentModelEditPlugin_1 = require("./edit/ContentModelEditPlugin");
7
+ Object.defineProperty(exports, "ContentModelEditPlugin", { enumerable: true, get: function () { return ContentModelEditPlugin_1.ContentModelEditPlugin; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-plugins/lib/index.ts"],"names":[],"mappings":";;;AAAA,2EAA0E;AAAjE,kIAAA,uBAAuB,OAAA;AAChC,wEAAuE;AAA9D,gIAAA,sBAAsB,OAAA","sourcesContent":["export { ContentModelPastePlugin } from './paste/ContentModelPastePlugin';\nexport { ContentModelEditPlugin } from './edit/ContentModelEditPlugin';\n"]}
@@ -0,0 +1,42 @@
1
+ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types';
2
+ /**
3
+ * Paste plugin, handles BeforePaste event and reformat some special content, including:
4
+ * 1. Content copied from Word
5
+ * 2. Content copied from Excel
6
+ * 3. Content copied from Word Online or OneNote Online
7
+ * 4. Content copied from Power Point
8
+ * (This class is still under development, and may still be changed in the future with some breaking changes)
9
+ */
10
+ export declare class ContentModelPastePlugin implements EditorPlugin {
11
+ private unknownTagReplacement;
12
+ private editor;
13
+ /**
14
+ * Construct a new instance of Paste class
15
+ * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN
16
+ */
17
+ constructor(unknownTagReplacement?: string);
18
+ /**
19
+ * Get name of this plugin
20
+ */
21
+ getName(): string;
22
+ /**
23
+ * The first method that editor will call to a plugin when editor is initializing.
24
+ * It will pass in the editor instance, plugin should take this chance to save the
25
+ * editor reference so that it can call to any editor method or format API later.
26
+ * @param editor The editor object
27
+ */
28
+ initialize(editor: IEditor): void;
29
+ /**
30
+ * The last method that editor will call to a plugin before it is disposed.
31
+ * Plugin can take this chance to clear the reference to editor. After this method is
32
+ * called, plugin should not call to any editor method since it will result in error.
33
+ */
34
+ dispose(): void;
35
+ /**
36
+ * Core method for a plugin. Once an event happens in editor, editor will call this
37
+ * method of each plugin to handle the event as long as the event is not handled
38
+ * exclusively by another plugin.
39
+ * @param event The event to handle:
40
+ */
41
+ onPluginEvent(event: PluginEvent): void;
42
+ }