roosterjs-content-model-core 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 (417) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +262 -0
  3. package/lib/constants/ChangeSource.d.ts +59 -0
  4. package/lib/constants/ChangeSource.js +63 -0
  5. package/lib/constants/ChangeSource.js.map +1 -0
  6. package/lib/coreApi/createContentModel.d.ts +9 -0
  7. package/lib/coreApi/createContentModel.js +40 -0
  8. package/lib/coreApi/createContentModel.js.map +1 -0
  9. package/lib/coreApi/createEditorContext.d.ts +6 -0
  10. package/lib/coreApi/createEditorContext.js +38 -0
  11. package/lib/coreApi/createEditorContext.js.map +1 -0
  12. package/lib/coreApi/formatContentModel.d.ts +12 -0
  13. package/lib/coreApi/formatContentModel.js +128 -0
  14. package/lib/coreApi/formatContentModel.js.map +1 -0
  15. package/lib/coreApi/getDOMSelection.d.ts +5 -0
  16. package/lib/coreApi/getDOMSelection.js +41 -0
  17. package/lib/coreApi/getDOMSelection.js.map +1 -0
  18. package/lib/coreApi/setContentModel.d.ts +9 -0
  19. package/lib/coreApi/setContentModel.js +33 -0
  20. package/lib/coreApi/setContentModel.js.map +1 -0
  21. package/lib/coreApi/setDOMSelection.d.ts +5 -0
  22. package/lib/coreApi/setDOMSelection.js +41 -0
  23. package/lib/coreApi/setDOMSelection.js.map +1 -0
  24. package/lib/coreApi/switchShadowEdit.d.ts +8 -0
  25. package/lib/coreApi/switchShadowEdit.js +54 -0
  26. package/lib/coreApi/switchShadowEdit.js.map +1 -0
  27. package/lib/corePlugin/ContentModelCachePlugin.d.ts +53 -0
  28. package/lib/corePlugin/ContentModelCachePlugin.js +169 -0
  29. package/lib/corePlugin/ContentModelCachePlugin.js.map +1 -0
  30. package/lib/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
  31. package/lib/corePlugin/ContentModelCopyPastePlugin.js +233 -0
  32. package/lib/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
  33. package/lib/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
  34. package/lib/corePlugin/ContentModelFormatPlugin.js +147 -0
  35. package/lib/corePlugin/ContentModelFormatPlugin.js.map +1 -0
  36. package/lib/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
  37. package/lib/corePlugin/ContentModelTypeInContainerPlugin.js +32 -0
  38. package/lib/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
  39. package/lib/corePlugin/utils/addRangeToSelection.d.ts +4 -0
  40. package/lib/corePlugin/utils/addRangeToSelection.js +16 -0
  41. package/lib/corePlugin/utils/addRangeToSelection.js.map +1 -0
  42. package/lib/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
  43. package/lib/corePlugin/utils/applyDefaultFormat.js +79 -0
  44. package/lib/corePlugin/utils/applyDefaultFormat.js.map +1 -0
  45. package/lib/corePlugin/utils/applyPendingFormat.d.ts +8 -0
  46. package/lib/corePlugin/utils/applyPendingFormat.js +51 -0
  47. package/lib/corePlugin/utils/applyPendingFormat.js.map +1 -0
  48. package/lib/corePlugin/utils/areSameSelection.d.ts +6 -0
  49. package/lib/corePlugin/utils/areSameSelection.js +36 -0
  50. package/lib/corePlugin/utils/areSameSelection.js.map +1 -0
  51. package/lib/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
  52. package/lib/corePlugin/utils/contentModelDomIndexer.js +190 -0
  53. package/lib/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
  54. package/lib/editor/createContentModelEditorCore.d.ts +6 -0
  55. package/lib/editor/createContentModelEditorCore.js +50 -0
  56. package/lib/editor/createContentModelEditorCore.js.map +1 -0
  57. package/lib/editor/promoteToContentModelEditorCore.d.ts +8 -0
  58. package/lib/editor/promoteToContentModelEditorCore.js +72 -0
  59. package/lib/editor/promoteToContentModelEditorCore.js.map +1 -0
  60. package/lib/index.d.ts +29 -0
  61. package/lib/index.js +71 -0
  62. package/lib/index.js.map +1 -0
  63. package/lib/metadata/definitionCreators.d.ts +48 -0
  64. package/lib/metadata/definitionCreators.js +95 -0
  65. package/lib/metadata/definitionCreators.js.map +1 -0
  66. package/lib/metadata/updateImageMetadata.d.ts +7 -0
  67. package/lib/metadata/updateImageMetadata.js +28 -0
  68. package/lib/metadata/updateImageMetadata.js.map +1 -0
  69. package/lib/metadata/updateListMetadata.d.ts +15 -0
  70. package/lib/metadata/updateListMetadata.js +181 -0
  71. package/lib/metadata/updateListMetadata.js.map +1 -0
  72. package/lib/metadata/updateTableCellMetadata.d.ts +7 -0
  73. package/lib/metadata/updateTableCellMetadata.js +20 -0
  74. package/lib/metadata/updateTableCellMetadata.js.map +1 -0
  75. package/lib/metadata/updateTableMetadata.d.ts +7 -0
  76. package/lib/metadata/updateTableMetadata.js +32 -0
  77. package/lib/metadata/updateTableMetadata.js.map +1 -0
  78. package/lib/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
  79. package/lib/modelApi/edit/deleteExpandedSelection.js +99 -0
  80. package/lib/modelApi/edit/deleteExpandedSelection.js.map +1 -0
  81. package/lib/modelApi/edit/deleteSingleChar.d.ts +4 -0
  82. package/lib/modelApi/edit/deleteSingleChar.js +36 -0
  83. package/lib/modelApi/edit/deleteSingleChar.js.map +1 -0
  84. package/lib/override/tablePreProcessor.d.ts +5 -0
  85. package/lib/override/tablePreProcessor.js +25 -0
  86. package/lib/override/tablePreProcessor.js.map +1 -0
  87. package/lib/publicApi/domUtils/borderValues.d.ts +13 -0
  88. package/lib/publicApi/domUtils/borderValues.js +48 -0
  89. package/lib/publicApi/domUtils/borderValues.js.map +1 -0
  90. package/lib/publicApi/domUtils/eventUtils.d.ts +13 -0
  91. package/lib/publicApi/domUtils/eventUtils.js +29 -0
  92. package/lib/publicApi/domUtils/eventUtils.js.map +1 -0
  93. package/lib/publicApi/domUtils/stringUtil.d.ts +18 -0
  94. package/lib/publicApi/domUtils/stringUtil.js +35 -0
  95. package/lib/publicApi/domUtils/stringUtil.js.map +1 -0
  96. package/lib/publicApi/model/cloneModel.d.ts +30 -0
  97. package/lib/publicApi/model/cloneModel.js +207 -0
  98. package/lib/publicApi/model/cloneModel.js.map +1 -0
  99. package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
  100. package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.js +28 -0
  101. package/lib/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
  102. package/lib/publicApi/model/isBlockGroupOfType.d.ts +8 -0
  103. package/lib/publicApi/model/isBlockGroupOfType.js +14 -0
  104. package/lib/publicApi/model/isBlockGroupOfType.js.map +1 -0
  105. package/lib/publicApi/model/mergeModel.d.ts +36 -0
  106. package/lib/publicApi/model/mergeModel.js +262 -0
  107. package/lib/publicApi/model/mergeModel.js.map +1 -0
  108. package/lib/publicApi/model/paste.d.ts +14 -0
  109. package/lib/publicApi/model/paste.js +150 -0
  110. package/lib/publicApi/model/paste.js.map +1 -0
  111. package/lib/publicApi/selection/collectSelections.d.ts +50 -0
  112. package/lib/publicApi/selection/collectSelections.js +182 -0
  113. package/lib/publicApi/selection/collectSelections.js.map +1 -0
  114. package/lib/publicApi/selection/deleteBlock.d.ts +11 -0
  115. package/lib/publicApi/selection/deleteBlock.js +56 -0
  116. package/lib/publicApi/selection/deleteBlock.js.map +1 -0
  117. package/lib/publicApi/selection/deleteSegment.d.ts +10 -0
  118. package/lib/publicApi/selection/deleteSegment.js +88 -0
  119. package/lib/publicApi/selection/deleteSegment.js.map +1 -0
  120. package/lib/publicApi/selection/deleteSelection.d.ts +9 -0
  121. package/lib/publicApi/selection/deleteSelection.js +44 -0
  122. package/lib/publicApi/selection/deleteSelection.js.map +1 -0
  123. package/lib/publicApi/selection/getSelectionRootNode.d.ts +9 -0
  124. package/lib/publicApi/selection/getSelectionRootNode.js +23 -0
  125. package/lib/publicApi/selection/getSelectionRootNode.js.map +1 -0
  126. package/lib/publicApi/selection/iterateSelections.d.ts +48 -0
  127. package/lib/publicApi/selection/iterateSelections.js +147 -0
  128. package/lib/publicApi/selection/iterateSelections.js.map +1 -0
  129. package/lib/publicApi/selection/setSelection.d.ts +8 -0
  130. package/lib/publicApi/selection/setSelection.js +131 -0
  131. package/lib/publicApi/selection/setSelection.js.map +1 -0
  132. package/lib/publicApi/table/applyTableFormat.d.ts +8 -0
  133. package/lib/publicApi/table/applyTableFormat.js +241 -0
  134. package/lib/publicApi/table/applyTableFormat.js.map +1 -0
  135. package/lib/publicApi/table/normalizeTable.d.ts +13 -0
  136. package/lib/publicApi/table/normalizeTable.js +121 -0
  137. package/lib/publicApi/table/normalizeTable.js.map +1 -0
  138. package/lib/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
  139. package/lib/publicApi/table/setTableCellBackgroundColor.js +105 -0
  140. package/lib/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
  141. package/lib-amd/constants/ChangeSource.d.ts +59 -0
  142. package/lib-amd/constants/ChangeSource.js +65 -0
  143. package/lib-amd/constants/ChangeSource.js.map +1 -0
  144. package/lib-amd/coreApi/createContentModel.d.ts +9 -0
  145. package/lib-amd/coreApi/createContentModel.js +39 -0
  146. package/lib-amd/coreApi/createContentModel.js.map +1 -0
  147. package/lib-amd/coreApi/createEditorContext.d.ts +6 -0
  148. package/lib-amd/coreApi/createEditorContext.js +40 -0
  149. package/lib-amd/coreApi/createEditorContext.js.map +1 -0
  150. package/lib-amd/coreApi/formatContentModel.d.ts +12 -0
  151. package/lib-amd/coreApi/formatContentModel.js +128 -0
  152. package/lib-amd/coreApi/formatContentModel.js.map +1 -0
  153. package/lib-amd/coreApi/getDOMSelection.d.ts +5 -0
  154. package/lib-amd/coreApi/getDOMSelection.js +43 -0
  155. package/lib-amd/coreApi/getDOMSelection.js.map +1 -0
  156. package/lib-amd/coreApi/setContentModel.d.ts +9 -0
  157. package/lib-amd/coreApi/setContentModel.js +33 -0
  158. package/lib-amd/coreApi/setContentModel.js.map +1 -0
  159. package/lib-amd/coreApi/setDOMSelection.d.ts +5 -0
  160. package/lib-amd/coreApi/setDOMSelection.js +43 -0
  161. package/lib-amd/coreApi/setDOMSelection.js.map +1 -0
  162. package/lib-amd/coreApi/switchShadowEdit.d.ts +8 -0
  163. package/lib-amd/coreApi/switchShadowEdit.js +55 -0
  164. package/lib-amd/coreApi/switchShadowEdit.js.map +1 -0
  165. package/lib-amd/corePlugin/ContentModelCachePlugin.d.ts +53 -0
  166. package/lib-amd/corePlugin/ContentModelCachePlugin.js +169 -0
  167. package/lib-amd/corePlugin/ContentModelCachePlugin.js.map +1 -0
  168. package/lib-amd/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
  169. package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js +226 -0
  170. package/lib-amd/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
  171. package/lib-amd/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
  172. package/lib-amd/corePlugin/ContentModelFormatPlugin.js +145 -0
  173. package/lib-amd/corePlugin/ContentModelFormatPlugin.js.map +1 -0
  174. package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
  175. package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.js +34 -0
  176. package/lib-amd/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
  177. package/lib-amd/corePlugin/utils/addRangeToSelection.d.ts +4 -0
  178. package/lib-amd/corePlugin/utils/addRangeToSelection.js +18 -0
  179. package/lib-amd/corePlugin/utils/addRangeToSelection.js.map +1 -0
  180. package/lib-amd/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
  181. package/lib-amd/corePlugin/utils/applyDefaultFormat.js +78 -0
  182. package/lib-amd/corePlugin/utils/applyDefaultFormat.js.map +1 -0
  183. package/lib-amd/corePlugin/utils/applyPendingFormat.d.ts +8 -0
  184. package/lib-amd/corePlugin/utils/applyPendingFormat.js +50 -0
  185. package/lib-amd/corePlugin/utils/applyPendingFormat.js.map +1 -0
  186. package/lib-amd/corePlugin/utils/areSameSelection.d.ts +6 -0
  187. package/lib-amd/corePlugin/utils/areSameSelection.js +38 -0
  188. package/lib-amd/corePlugin/utils/areSameSelection.js.map +1 -0
  189. package/lib-amd/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
  190. package/lib-amd/corePlugin/utils/contentModelDomIndexer.js +189 -0
  191. package/lib-amd/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
  192. package/lib-amd/editor/createContentModelEditorCore.d.ts +6 -0
  193. package/lib-amd/editor/createContentModelEditorCore.js +44 -0
  194. package/lib-amd/editor/createContentModelEditorCore.js.map +1 -0
  195. package/lib-amd/editor/promoteToContentModelEditorCore.d.ts +8 -0
  196. package/lib-amd/editor/promoteToContentModelEditorCore.js +64 -0
  197. package/lib-amd/editor/promoteToContentModelEditorCore.js.map +1 -0
  198. package/lib-amd/index.d.ts +29 -0
  199. package/lib-amd/index.js +44 -0
  200. package/lib-amd/index.js.map +1 -0
  201. package/lib-amd/metadata/definitionCreators.d.ts +48 -0
  202. package/lib-amd/metadata/definitionCreators.js +97 -0
  203. package/lib-amd/metadata/definitionCreators.js.map +1 -0
  204. package/lib-amd/metadata/updateImageMetadata.d.ts +7 -0
  205. package/lib-amd/metadata/updateImageMetadata.js +28 -0
  206. package/lib-amd/metadata/updateImageMetadata.js.map +1 -0
  207. package/lib-amd/metadata/updateListMetadata.d.ts +15 -0
  208. package/lib-amd/metadata/updateListMetadata.js +179 -0
  209. package/lib-amd/metadata/updateListMetadata.js.map +1 -0
  210. package/lib-amd/metadata/updateTableCellMetadata.d.ts +7 -0
  211. package/lib-amd/metadata/updateTableCellMetadata.js +20 -0
  212. package/lib-amd/metadata/updateTableCellMetadata.js.map +1 -0
  213. package/lib-amd/metadata/updateTableMetadata.d.ts +7 -0
  214. package/lib-amd/metadata/updateTableMetadata.js +31 -0
  215. package/lib-amd/metadata/updateTableMetadata.js.map +1 -0
  216. package/lib-amd/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
  217. package/lib-amd/modelApi/edit/deleteExpandedSelection.js +96 -0
  218. package/lib-amd/modelApi/edit/deleteExpandedSelection.js.map +1 -0
  219. package/lib-amd/modelApi/edit/deleteSingleChar.d.ts +4 -0
  220. package/lib-amd/modelApi/edit/deleteSingleChar.js +37 -0
  221. package/lib-amd/modelApi/edit/deleteSingleChar.js.map +1 -0
  222. package/lib-amd/override/tablePreProcessor.d.ts +5 -0
  223. package/lib-amd/override/tablePreProcessor.js +25 -0
  224. package/lib-amd/override/tablePreProcessor.js.map +1 -0
  225. package/lib-amd/publicApi/domUtils/borderValues.d.ts +13 -0
  226. package/lib-amd/publicApi/domUtils/borderValues.js +50 -0
  227. package/lib-amd/publicApi/domUtils/borderValues.js.map +1 -0
  228. package/lib-amd/publicApi/domUtils/eventUtils.d.ts +13 -0
  229. package/lib-amd/publicApi/domUtils/eventUtils.js +31 -0
  230. package/lib-amd/publicApi/domUtils/eventUtils.js.map +1 -0
  231. package/lib-amd/publicApi/domUtils/stringUtil.d.ts +18 -0
  232. package/lib-amd/publicApi/domUtils/stringUtil.js +37 -0
  233. package/lib-amd/publicApi/domUtils/stringUtil.js.map +1 -0
  234. package/lib-amd/publicApi/model/cloneModel.d.ts +30 -0
  235. package/lib-amd/publicApi/model/cloneModel.js +208 -0
  236. package/lib-amd/publicApi/model/cloneModel.js.map +1 -0
  237. package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
  238. package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.js +30 -0
  239. package/lib-amd/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
  240. package/lib-amd/publicApi/model/isBlockGroupOfType.d.ts +8 -0
  241. package/lib-amd/publicApi/model/isBlockGroupOfType.js +16 -0
  242. package/lib-amd/publicApi/model/isBlockGroupOfType.js.map +1 -0
  243. package/lib-amd/publicApi/model/mergeModel.d.ts +36 -0
  244. package/lib-amd/publicApi/model/mergeModel.js +258 -0
  245. package/lib-amd/publicApi/model/mergeModel.js.map +1 -0
  246. package/lib-amd/publicApi/model/paste.d.ts +14 -0
  247. package/lib-amd/publicApi/model/paste.js +146 -0
  248. package/lib-amd/publicApi/model/paste.js.map +1 -0
  249. package/lib-amd/publicApi/selection/collectSelections.d.ts +50 -0
  250. package/lib-amd/publicApi/selection/collectSelections.js +180 -0
  251. package/lib-amd/publicApi/selection/collectSelections.js.map +1 -0
  252. package/lib-amd/publicApi/selection/deleteBlock.d.ts +11 -0
  253. package/lib-amd/publicApi/selection/deleteBlock.js +58 -0
  254. package/lib-amd/publicApi/selection/deleteBlock.js.map +1 -0
  255. package/lib-amd/publicApi/selection/deleteSegment.d.ts +10 -0
  256. package/lib-amd/publicApi/selection/deleteSegment.js +87 -0
  257. package/lib-amd/publicApi/selection/deleteSegment.js.map +1 -0
  258. package/lib-amd/publicApi/selection/deleteSelection.d.ts +9 -0
  259. package/lib-amd/publicApi/selection/deleteSelection.js +44 -0
  260. package/lib-amd/publicApi/selection/deleteSelection.js.map +1 -0
  261. package/lib-amd/publicApi/selection/getSelectionRootNode.d.ts +9 -0
  262. package/lib-amd/publicApi/selection/getSelectionRootNode.js +25 -0
  263. package/lib-amd/publicApi/selection/getSelectionRootNode.js.map +1 -0
  264. package/lib-amd/publicApi/selection/iterateSelections.d.ts +48 -0
  265. package/lib-amd/publicApi/selection/iterateSelections.js +148 -0
  266. package/lib-amd/publicApi/selection/iterateSelections.js.map +1 -0
  267. package/lib-amd/publicApi/selection/setSelection.d.ts +8 -0
  268. package/lib-amd/publicApi/selection/setSelection.js +132 -0
  269. package/lib-amd/publicApi/selection/setSelection.js.map +1 -0
  270. package/lib-amd/publicApi/table/applyTableFormat.d.ts +8 -0
  271. package/lib-amd/publicApi/table/applyTableFormat.js +236 -0
  272. package/lib-amd/publicApi/table/applyTableFormat.js.map +1 -0
  273. package/lib-amd/publicApi/table/normalizeTable.d.ts +13 -0
  274. package/lib-amd/publicApi/table/normalizeTable.js +121 -0
  275. package/lib-amd/publicApi/table/normalizeTable.js.map +1 -0
  276. package/lib-amd/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
  277. package/lib-amd/publicApi/table/setTableCellBackgroundColor.js +105 -0
  278. package/lib-amd/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
  279. package/lib-mjs/constants/ChangeSource.d.ts +59 -0
  280. package/lib-mjs/constants/ChangeSource.js +60 -0
  281. package/lib-mjs/constants/ChangeSource.js.map +1 -0
  282. package/lib-mjs/coreApi/createContentModel.d.ts +9 -0
  283. package/lib-mjs/coreApi/createContentModel.js +36 -0
  284. package/lib-mjs/coreApi/createContentModel.js.map +1 -0
  285. package/lib-mjs/coreApi/createEditorContext.d.ts +6 -0
  286. package/lib-mjs/coreApi/createEditorContext.js +34 -0
  287. package/lib-mjs/coreApi/createEditorContext.js.map +1 -0
  288. package/lib-mjs/coreApi/formatContentModel.d.ts +12 -0
  289. package/lib-mjs/coreApi/formatContentModel.js +124 -0
  290. package/lib-mjs/coreApi/formatContentModel.js.map +1 -0
  291. package/lib-mjs/coreApi/getDOMSelection.d.ts +5 -0
  292. package/lib-mjs/coreApi/getDOMSelection.js +37 -0
  293. package/lib-mjs/coreApi/getDOMSelection.js.map +1 -0
  294. package/lib-mjs/coreApi/setContentModel.d.ts +9 -0
  295. package/lib-mjs/coreApi/setContentModel.js +29 -0
  296. package/lib-mjs/coreApi/setContentModel.js.map +1 -0
  297. package/lib-mjs/coreApi/setDOMSelection.d.ts +5 -0
  298. package/lib-mjs/coreApi/setDOMSelection.js +37 -0
  299. package/lib-mjs/coreApi/setDOMSelection.js.map +1 -0
  300. package/lib-mjs/coreApi/switchShadowEdit.d.ts +8 -0
  301. package/lib-mjs/coreApi/switchShadowEdit.js +50 -0
  302. package/lib-mjs/coreApi/switchShadowEdit.js.map +1 -0
  303. package/lib-mjs/corePlugin/ContentModelCachePlugin.d.ts +53 -0
  304. package/lib-mjs/corePlugin/ContentModelCachePlugin.js +165 -0
  305. package/lib-mjs/corePlugin/ContentModelCachePlugin.js.map +1 -0
  306. package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.d.ts +46 -0
  307. package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js +228 -0
  308. package/lib-mjs/corePlugin/ContentModelCopyPastePlugin.js.map +1 -0
  309. package/lib-mjs/corePlugin/ContentModelFormatPlugin.d.ts +59 -0
  310. package/lib-mjs/corePlugin/ContentModelFormatPlugin.js +143 -0
  311. package/lib-mjs/corePlugin/ContentModelFormatPlugin.js.map +1 -0
  312. package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.d.ts +23 -0
  313. package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.js +29 -0
  314. package/lib-mjs/corePlugin/ContentModelTypeInContainerPlugin.js.map +1 -0
  315. package/lib-mjs/corePlugin/utils/addRangeToSelection.d.ts +4 -0
  316. package/lib-mjs/corePlugin/utils/addRangeToSelection.js +12 -0
  317. package/lib-mjs/corePlugin/utils/addRangeToSelection.js.map +1 -0
  318. package/lib-mjs/corePlugin/utils/applyDefaultFormat.d.ts +9 -0
  319. package/lib-mjs/corePlugin/utils/applyDefaultFormat.js +75 -0
  320. package/lib-mjs/corePlugin/utils/applyDefaultFormat.js.map +1 -0
  321. package/lib-mjs/corePlugin/utils/applyPendingFormat.d.ts +8 -0
  322. package/lib-mjs/corePlugin/utils/applyPendingFormat.js +47 -0
  323. package/lib-mjs/corePlugin/utils/applyPendingFormat.js.map +1 -0
  324. package/lib-mjs/corePlugin/utils/areSameSelection.d.ts +6 -0
  325. package/lib-mjs/corePlugin/utils/areSameSelection.js +32 -0
  326. package/lib-mjs/corePlugin/utils/areSameSelection.js.map +1 -0
  327. package/lib-mjs/corePlugin/utils/contentModelDomIndexer.d.ts +6 -0
  328. package/lib-mjs/corePlugin/utils/contentModelDomIndexer.js +187 -0
  329. package/lib-mjs/corePlugin/utils/contentModelDomIndexer.js.map +1 -0
  330. package/lib-mjs/editor/createContentModelEditorCore.d.ts +6 -0
  331. package/lib-mjs/editor/createContentModelEditorCore.js +46 -0
  332. package/lib-mjs/editor/createContentModelEditorCore.js.map +1 -0
  333. package/lib-mjs/editor/promoteToContentModelEditorCore.d.ts +8 -0
  334. package/lib-mjs/editor/promoteToContentModelEditorCore.js +68 -0
  335. package/lib-mjs/editor/promoteToContentModelEditorCore.js.map +1 -0
  336. package/lib-mjs/index.d.ts +29 -0
  337. package/lib-mjs/index.js +30 -0
  338. package/lib-mjs/index.js.map +1 -0
  339. package/lib-mjs/metadata/definitionCreators.d.ts +48 -0
  340. package/lib-mjs/metadata/definitionCreators.js +87 -0
  341. package/lib-mjs/metadata/definitionCreators.js.map +1 -0
  342. package/lib-mjs/metadata/updateImageMetadata.d.ts +7 -0
  343. package/lib-mjs/metadata/updateImageMetadata.js +24 -0
  344. package/lib-mjs/metadata/updateImageMetadata.js.map +1 -0
  345. package/lib-mjs/metadata/updateListMetadata.d.ts +15 -0
  346. package/lib-mjs/metadata/updateListMetadata.js +177 -0
  347. package/lib-mjs/metadata/updateListMetadata.js.map +1 -0
  348. package/lib-mjs/metadata/updateTableCellMetadata.d.ts +7 -0
  349. package/lib-mjs/metadata/updateTableCellMetadata.js +16 -0
  350. package/lib-mjs/metadata/updateTableCellMetadata.js.map +1 -0
  351. package/lib-mjs/metadata/updateTableMetadata.d.ts +7 -0
  352. package/lib-mjs/metadata/updateTableMetadata.js +28 -0
  353. package/lib-mjs/metadata/updateTableMetadata.js.map +1 -0
  354. package/lib-mjs/modelApi/edit/deleteExpandedSelection.d.ts +7 -0
  355. package/lib-mjs/modelApi/edit/deleteExpandedSelection.js +95 -0
  356. package/lib-mjs/modelApi/edit/deleteExpandedSelection.js.map +1 -0
  357. package/lib-mjs/modelApi/edit/deleteSingleChar.d.ts +4 -0
  358. package/lib-mjs/modelApi/edit/deleteSingleChar.js +32 -0
  359. package/lib-mjs/modelApi/edit/deleteSingleChar.js.map +1 -0
  360. package/lib-mjs/override/tablePreProcessor.d.ts +5 -0
  361. package/lib-mjs/override/tablePreProcessor.js +21 -0
  362. package/lib-mjs/override/tablePreProcessor.js.map +1 -0
  363. package/lib-mjs/publicApi/domUtils/borderValues.d.ts +13 -0
  364. package/lib-mjs/publicApi/domUtils/borderValues.js +43 -0
  365. package/lib-mjs/publicApi/domUtils/borderValues.js.map +1 -0
  366. package/lib-mjs/publicApi/domUtils/eventUtils.d.ts +13 -0
  367. package/lib-mjs/publicApi/domUtils/eventUtils.js +24 -0
  368. package/lib-mjs/publicApi/domUtils/eventUtils.js.map +1 -0
  369. package/lib-mjs/publicApi/domUtils/stringUtil.d.ts +18 -0
  370. package/lib-mjs/publicApi/domUtils/stringUtil.js +29 -0
  371. package/lib-mjs/publicApi/domUtils/stringUtil.js.map +1 -0
  372. package/lib-mjs/publicApi/model/cloneModel.d.ts +30 -0
  373. package/lib-mjs/publicApi/model/cloneModel.js +203 -0
  374. package/lib-mjs/publicApi/model/cloneModel.js.map +1 -0
  375. package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.d.ts +12 -0
  376. package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.js +24 -0
  377. package/lib-mjs/publicApi/model/getClosestAncestorBlockGroupIndex.js.map +1 -0
  378. package/lib-mjs/publicApi/model/isBlockGroupOfType.d.ts +8 -0
  379. package/lib-mjs/publicApi/model/isBlockGroupOfType.js +10 -0
  380. package/lib-mjs/publicApi/model/isBlockGroupOfType.js.map +1 -0
  381. package/lib-mjs/publicApi/model/mergeModel.d.ts +36 -0
  382. package/lib-mjs/publicApi/model/mergeModel.js +258 -0
  383. package/lib-mjs/publicApi/model/mergeModel.js.map +1 -0
  384. package/lib-mjs/publicApi/model/paste.d.ts +14 -0
  385. package/lib-mjs/publicApi/model/paste.js +145 -0
  386. package/lib-mjs/publicApi/model/paste.js.map +1 -0
  387. package/lib-mjs/publicApi/selection/collectSelections.d.ts +50 -0
  388. package/lib-mjs/publicApi/selection/collectSelections.js +173 -0
  389. package/lib-mjs/publicApi/selection/collectSelections.js.map +1 -0
  390. package/lib-mjs/publicApi/selection/deleteBlock.d.ts +11 -0
  391. package/lib-mjs/publicApi/selection/deleteBlock.js +52 -0
  392. package/lib-mjs/publicApi/selection/deleteBlock.js.map +1 -0
  393. package/lib-mjs/publicApi/selection/deleteSegment.d.ts +10 -0
  394. package/lib-mjs/publicApi/selection/deleteSegment.js +84 -0
  395. package/lib-mjs/publicApi/selection/deleteSegment.js.map +1 -0
  396. package/lib-mjs/publicApi/selection/deleteSelection.d.ts +9 -0
  397. package/lib-mjs/publicApi/selection/deleteSelection.js +40 -0
  398. package/lib-mjs/publicApi/selection/deleteSelection.js.map +1 -0
  399. package/lib-mjs/publicApi/selection/getSelectionRootNode.d.ts +9 -0
  400. package/lib-mjs/publicApi/selection/getSelectionRootNode.js +19 -0
  401. package/lib-mjs/publicApi/selection/getSelectionRootNode.js.map +1 -0
  402. package/lib-mjs/publicApi/selection/iterateSelections.d.ts +48 -0
  403. package/lib-mjs/publicApi/selection/iterateSelections.js +143 -0
  404. package/lib-mjs/publicApi/selection/iterateSelections.js.map +1 -0
  405. package/lib-mjs/publicApi/selection/setSelection.d.ts +8 -0
  406. package/lib-mjs/publicApi/selection/setSelection.js +127 -0
  407. package/lib-mjs/publicApi/selection/setSelection.js.map +1 -0
  408. package/lib-mjs/publicApi/table/applyTableFormat.d.ts +8 -0
  409. package/lib-mjs/publicApi/table/applyTableFormat.js +237 -0
  410. package/lib-mjs/publicApi/table/applyTableFormat.js.map +1 -0
  411. package/lib-mjs/publicApi/table/normalizeTable.d.ts +13 -0
  412. package/lib-mjs/publicApi/table/normalizeTable.js +117 -0
  413. package/lib-mjs/publicApi/table/normalizeTable.js.map +1 -0
  414. package/lib-mjs/publicApi/table/setTableCellBackgroundColor.d.ts +15 -0
  415. package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js +100 -0
  416. package/lib-mjs/publicApi/table/setTableCellBackgroundColor.js.map +1 -0
  417. package/package.json +21 -0
@@ -0,0 +1,180 @@
1
+ define(["require", "exports", "tslib", "../model/getClosestAncestorBlockGroupIndex", "../model/isBlockGroupOfType", "./iterateSelections"], function (require, exports, tslib_1, getClosestAncestorBlockGroupIndex_1, isBlockGroupOfType_1, iterateSelections_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getFirstSelectedListItem = exports.getFirstSelectedTable = exports.getOperationalBlocks = exports.getSelectedParagraphs = exports.getSelectedSegments = exports.getSelectedSegmentsAndParagraphs = void 0;
5
+ /**
6
+ * Get an array of selected parent paragraph and child segment pair
7
+ * @param model The Content Model to get selection from
8
+ * @param includingFormatHolder True means also include format holder as segment from list item, in that case paragraph will be null
9
+ */
10
+ function getSelectedSegmentsAndParagraphs(model, includingFormatHolder) {
11
+ var selections = collectSelections(model, {
12
+ includeListFormatHolder: includingFormatHolder ? 'allSegments' : 'never',
13
+ });
14
+ var result = [];
15
+ selections.forEach(function (_a) {
16
+ var segments = _a.segments, block = _a.block;
17
+ if (segments && ((includingFormatHolder && !block) || (block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph')) {
18
+ segments.forEach(function (segment) {
19
+ if (segment.segmentType != 'Entity' || !segment.entityFormat.isReadonly) {
20
+ result.push([segment, (block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph' ? block : null]);
21
+ }
22
+ });
23
+ }
24
+ });
25
+ return result;
26
+ }
27
+ exports.getSelectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs;
28
+ /**
29
+ * Get an array of selected segments from a content model
30
+ * @param model The Content Model to get selection from
31
+ * @param includingFormatHolder True means also include format holder as segment from list item
32
+ */
33
+ function getSelectedSegments(model, includingFormatHolder) {
34
+ return getSelectedSegmentsAndParagraphs(model, includingFormatHolder).map(function (x) { return x[0]; });
35
+ }
36
+ exports.getSelectedSegments = getSelectedSegments;
37
+ /**
38
+ * Get any array of selected paragraphs from a content model
39
+ * @param model The Content Model to get selection from
40
+ */
41
+ function getSelectedParagraphs(model) {
42
+ var selections = collectSelections(model, { includeListFormatHolder: 'never' });
43
+ var result = [];
44
+ removeUnmeaningfulSelections(selections);
45
+ selections.forEach(function (_a) {
46
+ var block = _a.block;
47
+ if ((block === null || block === void 0 ? void 0 : block.blockType) == 'Paragraph') {
48
+ result.push(block);
49
+ }
50
+ });
51
+ return result;
52
+ }
53
+ exports.getSelectedParagraphs = getSelectedParagraphs;
54
+ /**
55
+ * Get an array of block group - block pair that is of the expected block group type from selection
56
+ * @param model The Content Model to get selection from
57
+ * @param blockGroupTypes The expected block group types
58
+ * @param stopTypes Block group types that will stop searching when hit
59
+ * @param deepFirst True means search in deep first, otherwise wide first
60
+ */
61
+ function getOperationalBlocks(model, blockGroupTypes, stopTypes, deepFirst) {
62
+ var result = [];
63
+ var findSequence = deepFirst ? blockGroupTypes.map(function (type) { return [type]; }) : [blockGroupTypes];
64
+ var selections = collectSelections(model, {
65
+ includeListFormatHolder: 'never',
66
+ contentUnderSelectedTableCell: 'ignoreForTable', // When whole table is selected, we treat the table as a single block
67
+ });
68
+ removeUnmeaningfulSelections(selections);
69
+ selections.forEach(function (_a) {
70
+ var path = _a.path, block = _a.block;
71
+ var _loop_1 = function (i) {
72
+ var groupIndex = (0, getClosestAncestorBlockGroupIndex_1.getClosestAncestorBlockGroupIndex)(path, findSequence[i], stopTypes);
73
+ if (groupIndex >= 0) {
74
+ if (result.filter(function (x) { return x.block == path[groupIndex]; }).length <= 0) {
75
+ result.push({
76
+ parent: path[groupIndex + 1],
77
+ block: path[groupIndex],
78
+ });
79
+ }
80
+ return "break";
81
+ }
82
+ else if (i == findSequence.length - 1 && block) {
83
+ result.push({
84
+ parent: path[0],
85
+ block: block,
86
+ });
87
+ return "break";
88
+ }
89
+ };
90
+ for (var i = 0; i < findSequence.length; i++) {
91
+ var state_1 = _loop_1(i);
92
+ if (state_1 === "break")
93
+ break;
94
+ }
95
+ });
96
+ return result;
97
+ }
98
+ exports.getOperationalBlocks = getOperationalBlocks;
99
+ /**
100
+ * Get the first selected table from content model
101
+ * @param model The Content Model to get selection from
102
+ */
103
+ function getFirstSelectedTable(model) {
104
+ var selections = collectSelections(model, { includeListFormatHolder: 'never' });
105
+ var table;
106
+ var resultPath = [];
107
+ removeUnmeaningfulSelections(selections);
108
+ selections.forEach(function (_a) {
109
+ var block = _a.block, tableContext = _a.tableContext, path = _a.path;
110
+ if (!table) {
111
+ if ((block === null || block === void 0 ? void 0 : block.blockType) == 'Table') {
112
+ table = block;
113
+ resultPath = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(path), false);
114
+ }
115
+ else if (tableContext === null || tableContext === void 0 ? void 0 : tableContext.table) {
116
+ table = tableContext.table;
117
+ var parent_1 = path.filter(function (group) { return group.blocks.indexOf(tableContext.table) >= 0; })[0];
118
+ var index = path.indexOf(parent_1);
119
+ resultPath = index >= 0 ? path.slice(index) : [];
120
+ }
121
+ }
122
+ });
123
+ return [table, resultPath];
124
+ }
125
+ exports.getFirstSelectedTable = getFirstSelectedTable;
126
+ /**
127
+ * Get the first selected list item from content model
128
+ * @param model The Content Model to get selection from
129
+ */
130
+ function getFirstSelectedListItem(model) {
131
+ var listItem;
132
+ getOperationalBlocks(model, ['ListItem'], ['TableCell']).forEach(function (r) {
133
+ if (!listItem && (0, isBlockGroupOfType_1.isBlockGroupOfType)(r.block, 'ListItem')) {
134
+ listItem = r.block;
135
+ }
136
+ });
137
+ return listItem;
138
+ }
139
+ exports.getFirstSelectedListItem = getFirstSelectedListItem;
140
+ function collectSelections(model, option) {
141
+ var selections = [];
142
+ (0, iterateSelections_1.iterateSelections)(model, function (path, tableContext, block, segments) {
143
+ selections.push({
144
+ path: path,
145
+ tableContext: tableContext,
146
+ block: block,
147
+ segments: segments,
148
+ });
149
+ }, option);
150
+ return selections;
151
+ }
152
+ function removeUnmeaningfulSelections(selections) {
153
+ if (selections.length > 1 &&
154
+ isOnlySelectionMarkerSelected(selections, false /*checkFirstParagraph*/)) {
155
+ selections.pop();
156
+ }
157
+ // Remove head paragraph if first selection marker is the only selection
158
+ if (selections.length > 1 &&
159
+ isOnlySelectionMarkerSelected(selections, true /*checkFirstParagraph*/)) {
160
+ selections.shift();
161
+ }
162
+ }
163
+ function isOnlySelectionMarkerSelected(selections, checkFirstParagraph) {
164
+ var _a;
165
+ var selection = selections[checkFirstParagraph ? 0 : selections.length - 1];
166
+ if (((_a = selection.block) === null || _a === void 0 ? void 0 : _a.blockType) == 'Paragraph' &&
167
+ selection.segments &&
168
+ selection.segments.length > 0) {
169
+ var allSegments = selection.block.segments;
170
+ var segment = selection.segments[0];
171
+ return (selection.segments.length == 1 &&
172
+ segment.segmentType == 'SelectionMarker' &&
173
+ segment == allSegments[checkFirstParagraph ? allSegments.length - 1 : 0]);
174
+ }
175
+ else {
176
+ return false;
177
+ }
178
+ }
179
+ });
180
+ //# sourceMappingURL=collectSelections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectSelections.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/selection/collectSelections.ts"],"names":[],"mappings":";;;;IAgCA;;;;OAIG;IACH,SAAgB,gCAAgC,CAC5C,KAA2B,EAC3B,qBAA8B;QAE9B,IAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,EAAE;YACxC,uBAAuB,EAAE,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO;SAC3E,CAAC,CAAC;QACH,IAAM,MAAM,GAA0D,EAAE,CAAC;QAEzE,UAAU,CAAC,OAAO,CAAC,UAAC,EAAmB;gBAAjB,QAAQ,cAAA,EAAE,KAAK,WAAA;YACjC,IAAI,QAAQ,IAAI,CAAC,CAAC,qBAAqB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,CAAC,EAAE;gBACpF,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;oBACpB,IAAI,OAAO,CAAC,WAAW,IAAI,QAAQ,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE;wBACrE,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAA,KAAK,aAAL,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AAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAC/B;YACE,IAAM,WAAW,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;YAC7C,IAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAEtC,OAAO,CACH,SAAS,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC;gBAC9B,OAAO,CAAC,WAAW,IAAI,iBAAiB;gBACxC,OAAO,IAAI,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3E,CAAC;SACL;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC","sourcesContent":["import { getClosestAncestorBlockGroupIndex } from '../model/getClosestAncestorBlockGroupIndex';\nimport { isBlockGroupOfType } from '../model/isBlockGroupOfType';\nimport { iterateSelections } from './iterateSelections';\nimport type { IterateSelectionsOption } from './iterateSelections';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelBlockGroupType,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelTable,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\nimport type { TypeOfBlockGroup } from '../model/getClosestAncestorBlockGroupIndex';\n\n/**\n * Represent a pair of parent block group and child block\n */\nexport type OperationalBlocks<T extends ContentModelBlockGroup> = {\n /**\n * The parent block group\n */\n parent: ContentModelBlockGroup;\n\n /**\n * The child block\n */\n block: ContentModelBlock | T;\n};\n\n/**\n * Get an array of selected parent paragraph and child segment pair\n * @param model The Content Model to get selection from\n * @param includingFormatHolder True means also include format holder as segment from list item, in that case paragraph will be null\n */\nexport function getSelectedSegmentsAndParagraphs(\n model: ContentModelDocument,\n includingFormatHolder: boolean\n): [ContentModelSegment, ContentModelParagraph | null][] {\n const selections = collectSelections(model, {\n includeListFormatHolder: includingFormatHolder ? 'allSegments' : 'never',\n });\n const result: [ContentModelSegment, ContentModelParagraph | null][] = [];\n\n selections.forEach(({ segments, block }) => {\n if (segments && ((includingFormatHolder && !block) || block?.blockType == 'Paragraph')) {\n segments.forEach(segment => {\n if (segment.segmentType != 'Entity' || !segment.entityFormat.isReadonly) {\n result.push([segment, block?.blockType == 'Paragraph' ? block : null]);\n }\n });\n }\n });\n\n return result;\n}\n\n/**\n * Get an array of selected segments from a content model\n * @param model The Content Model to get selection from\n * @param includingFormatHolder True means also include format holder as segment from list item\n */\nexport function getSelectedSegments(\n model: ContentModelDocument,\n includingFormatHolder: boolean\n): ContentModelSegment[] {\n return getSelectedSegmentsAndParagraphs(model, includingFormatHolder).map(x => x[0]);\n}\n\n/**\n * Get any array of selected paragraphs from a content model\n * @param model The Content Model to get selection from\n */\nexport function getSelectedParagraphs(model: ContentModelDocument): ContentModelParagraph[] {\n const selections = collectSelections(model, { includeListFormatHolder: 'never' });\n const result: ContentModelParagraph[] = [];\n\n removeUnmeaningfulSelections(selections);\n\n selections.forEach(({ block }) => {\n if (block?.blockType == 'Paragraph') {\n result.push(block);\n }\n });\n\n return result;\n}\n\n/**\n * Get an array of block group - block pair that is of the expected block group type from selection\n * @param model The Content Model to get selection from\n * @param blockGroupTypes The expected block group types\n * @param stopTypes Block group types that will stop searching when hit\n * @param deepFirst True means search in deep first, otherwise wide first\n */\nexport function getOperationalBlocks<T extends ContentModelBlockGroup>(\n model: ContentModelDocument,\n blockGroupTypes: TypeOfBlockGroup<T>[],\n stopTypes: ContentModelBlockGroupType[],\n deepFirst?: boolean\n): OperationalBlocks<T>[] {\n const result: OperationalBlocks<T>[] = [];\n const findSequence = deepFirst ? blockGroupTypes.map(type => [type]) : [blockGroupTypes];\n const selections = collectSelections(model, {\n includeListFormatHolder: 'never',\n contentUnderSelectedTableCell: 'ignoreForTable', // When whole table is selected, we treat the table as a single block\n });\n\n removeUnmeaningfulSelections(selections);\n\n selections.forEach(({ path, block }) => {\n for (let i = 0; i < findSequence.length; i++) {\n const groupIndex = getClosestAncestorBlockGroupIndex(path, findSequence[i], stopTypes);\n\n if (groupIndex >= 0) {\n if (result.filter(x => x.block == path[groupIndex]).length <= 0) {\n result.push({\n parent: path[groupIndex + 1],\n block: path[groupIndex] as T,\n });\n }\n break;\n } else if (i == findSequence.length - 1 && block) {\n result.push({\n parent: path[0],\n block: block,\n });\n break;\n }\n }\n });\n\n return result;\n}\n\n/**\n * Get the first selected table from content model\n * @param model The Content Model to get selection from\n */\nexport function getFirstSelectedTable(\n model: ContentModelDocument\n): [ContentModelTable | undefined, ContentModelBlockGroup[]] {\n const selections = collectSelections(model, { includeListFormatHolder: 'never' });\n let table: ContentModelTable | undefined;\n let resultPath: ContentModelBlockGroup[] = [];\n\n removeUnmeaningfulSelections(selections);\n\n selections.forEach(({ block, tableContext, path }) => {\n if (!table) {\n if (block?.blockType == 'Table') {\n table = block;\n resultPath = [...path];\n } else if (tableContext?.table) {\n table = tableContext.table;\n\n const parent = path.filter(\n group => group.blocks.indexOf(tableContext.table) >= 0\n )[0];\n const index = path.indexOf(parent);\n resultPath = index >= 0 ? path.slice(index) : [];\n }\n }\n });\n\n return [table, resultPath];\n}\n\n/**\n * Get the first selected list item from content model\n * @param model The Content Model to get selection from\n */\nexport function getFirstSelectedListItem(\n model: ContentModelDocument\n): ContentModelListItem | undefined {\n let listItem: ContentModelListItem | undefined;\n\n getOperationalBlocks(model, ['ListItem'], ['TableCell']).forEach(r => {\n if (!listItem && isBlockGroupOfType<ContentModelListItem>(r.block, 'ListItem')) {\n listItem = r.block;\n }\n });\n\n return listItem;\n}\n\ninterface SelectionInfo {\n path: ContentModelBlockGroup[];\n segments?: ContentModelSegment[];\n block?: ContentModelBlock;\n tableContext?: TableSelectionContext;\n}\n\nfunction collectSelections(\n model: ContentModelDocument,\n option?: IterateSelectionsOption\n): SelectionInfo[] {\n const selections: SelectionInfo[] = [];\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n selections.push({\n path,\n tableContext,\n block,\n segments,\n });\n },\n option\n );\n\n return selections;\n}\n\nfunction removeUnmeaningfulSelections(selections: SelectionInfo[]) {\n if (\n selections.length > 1 &&\n isOnlySelectionMarkerSelected(selections, false /*checkFirstParagraph*/)\n ) {\n selections.pop();\n }\n\n // Remove head paragraph if first selection marker is the only selection\n if (\n selections.length > 1 &&\n isOnlySelectionMarkerSelected(selections, true /*checkFirstParagraph*/)\n ) {\n selections.shift();\n }\n}\n\nfunction isOnlySelectionMarkerSelected(\n selections: SelectionInfo[],\n checkFirstParagraph: boolean\n): boolean {\n const selection = selections[checkFirstParagraph ? 0 : selections.length - 1];\n\n if (\n selection.block?.blockType == 'Paragraph' &&\n selection.segments &&\n selection.segments.length > 0\n ) {\n const allSegments = selection.block.segments;\n const segment = selection.segments[0];\n\n return (\n selection.segments.length == 1 &&\n segment.segmentType == 'SelectionMarker' &&\n segment == allSegments[checkFirstParagraph ? allSegments.length - 1 : 0]\n );\n } else {\n return false;\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { ContentModelBlock, FormatWithContentModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Delete a content model block from current selection
4
+ * @param blocks Array of the block to delete
5
+ * @param blockToDelete The block to delete
6
+ * @param replacement @optional If specified, use this block to replace the deleted block
7
+ * @param context @optional Context object provided by formatContentModel API
8
+ * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.
9
+ * If not specified, only selected entity will be deleted
10
+ */
11
+ export declare function deleteBlock(blocks: ContentModelBlock[], blockToDelete: ContentModelBlock, replacement?: ContentModelBlock, context?: FormatWithContentModelContext, direction?: 'forward' | 'backward'): boolean;
@@ -0,0 +1,58 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deleteBlock = void 0;
5
+ /**
6
+ * Delete a content model block from current selection
7
+ * @param blocks Array of the block to delete
8
+ * @param blockToDelete The block to delete
9
+ * @param replacement @optional If specified, use this block to replace the deleted block
10
+ * @param context @optional Context object provided by formatContentModel API
11
+ * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.
12
+ * If not specified, only selected entity will be deleted
13
+ */
14
+ function deleteBlock(blocks, blockToDelete, replacement, context, direction) {
15
+ var index = blocks.indexOf(blockToDelete);
16
+ switch (blockToDelete.blockType) {
17
+ case 'Table':
18
+ case 'Divider':
19
+ replacement ? blocks.splice(index, 1, replacement) : blocks.splice(index, 1);
20
+ return true;
21
+ case 'Entity':
22
+ var operation = blockToDelete.isSelected
23
+ ? 'overwrite'
24
+ : direction == 'forward'
25
+ ? 'removeFromStart'
26
+ : direction == 'backward'
27
+ ? 'removeFromEnd'
28
+ : undefined;
29
+ if (operation !== undefined) {
30
+ replacement ? blocks.splice(index, 1, replacement) : blocks.splice(index, 1);
31
+ context === null || context === void 0 ? void 0 : context.deletedEntities.push({
32
+ entity: blockToDelete,
33
+ operation: operation,
34
+ });
35
+ }
36
+ return true;
37
+ case 'BlockGroup':
38
+ switch (blockToDelete.blockGroupType) {
39
+ case 'General':
40
+ if (replacement) {
41
+ blocks.splice(index, 1, replacement);
42
+ return true;
43
+ }
44
+ else {
45
+ // no op, let browser handle it
46
+ return false;
47
+ }
48
+ case 'ListItem':
49
+ case 'FormatContainer':
50
+ blocks.splice(index, 1);
51
+ return true;
52
+ }
53
+ }
54
+ return false;
55
+ }
56
+ exports.deleteBlock = deleteBlock;
57
+ });
58
+ //# sourceMappingURL=deleteBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteBlock.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/selection/deleteBlock.ts"],"names":[],"mappings":";;;;IAMA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAA2B,EAC3B,aAAgC,EAChC,WAA+B,EAC/B,OAAuC,EACvC,SAAkC;QAElC,IAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAE5C,QAAQ,aAAa,CAAC,SAAS,EAAE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,CAAC;iBACnB;SACR;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IArDD,kCAqDC","sourcesContent":["import type {\n ContentModelBlock,\n EntityRemovalOperation,\n FormatWithContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Delete a content model block from current selection\n * @param blocks Array of the block to delete\n * @param blockToDelete The block to delete\n * @param replacement @optional If specified, use this block to replace the deleted block\n * @param context @optional Context object provided by formatContentModel API\n * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.\n * If not specified, only selected entity will be deleted\n */\nexport function deleteBlock(\n blocks: ContentModelBlock[],\n blockToDelete: ContentModelBlock,\n replacement?: ContentModelBlock,\n context?: FormatWithContentModelContext,\n direction?: 'forward' | 'backward'\n): boolean {\n const index = blocks.indexOf(blockToDelete);\n\n switch (blockToDelete.blockType) {\n case 'Table':\n case 'Divider':\n replacement ? blocks.splice(index, 1, replacement) : blocks.splice(index, 1);\n return true;\n\n case 'Entity':\n const operation: EntityRemovalOperation | undefined = blockToDelete.isSelected\n ? 'overwrite'\n : direction == 'forward'\n ? 'removeFromStart'\n : direction == 'backward'\n ? 'removeFromEnd'\n : undefined;\n\n if (operation !== undefined) {\n replacement ? blocks.splice(index, 1, replacement) : blocks.splice(index, 1);\n context?.deletedEntities.push({\n entity: blockToDelete,\n operation,\n });\n }\n\n return true;\n\n case 'BlockGroup':\n switch (blockToDelete.blockGroupType) {\n case 'General':\n if (replacement) {\n blocks.splice(index, 1, replacement);\n return true;\n } else {\n // no op, let browser handle it\n return false;\n }\n\n case 'ListItem':\n case 'FormatContainer':\n blocks.splice(index, 1);\n return true;\n }\n }\n\n return false;\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ContentModelParagraph, ContentModelSegment, FormatWithContentModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Delete a content model segment from current selection
4
+ * @param paragraph Parent paragraph of the segment to delete
5
+ * @param segmentToDelete The segment to delete
6
+ * @param context @optional Context object provided by formatContentModel API
7
+ * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.
8
+ * If not specified, only selected entity will be deleted
9
+ */
10
+ export declare function deleteSegment(paragraph: ContentModelParagraph, segmentToDelete: ContentModelSegment, context?: FormatWithContentModelContext, direction?: 'forward' | 'backward'): boolean;
@@ -0,0 +1,87 @@
1
+ define(["require", "exports", "../../modelApi/edit/deleteSingleChar", "roosterjs-content-model-dom", "../domUtils/stringUtil"], function (require, exports, deleteSingleChar_1, roosterjs_content_model_dom_1, stringUtil_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deleteSegment = void 0;
5
+ /**
6
+ * Delete a content model segment from current selection
7
+ * @param paragraph Parent paragraph of the segment to delete
8
+ * @param segmentToDelete The segment to delete
9
+ * @param context @optional Context object provided by formatContentModel API
10
+ * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.
11
+ * If not specified, only selected entity will be deleted
12
+ */
13
+ function deleteSegment(paragraph, segmentToDelete, context, direction) {
14
+ var segments = paragraph.segments;
15
+ var index = segments.indexOf(segmentToDelete);
16
+ var preserveWhiteSpace = (0, roosterjs_content_model_dom_1.isWhiteSpacePreserved)(paragraph);
17
+ var isForward = direction == 'forward';
18
+ var isBackward = direction == 'backward';
19
+ if (!preserveWhiteSpace) {
20
+ normalizePreviousSegment(segments, index);
21
+ }
22
+ switch (segmentToDelete.segmentType) {
23
+ case 'Br':
24
+ case 'Image':
25
+ case 'SelectionMarker':
26
+ segments.splice(index, 1);
27
+ return true;
28
+ case 'Entity':
29
+ var operation = segmentToDelete.isSelected
30
+ ? 'overwrite'
31
+ : isForward
32
+ ? 'removeFromStart'
33
+ : isBackward
34
+ ? 'removeFromEnd'
35
+ : undefined;
36
+ if (operation !== undefined) {
37
+ segments.splice(index, 1);
38
+ context === null || context === void 0 ? void 0 : context.deletedEntities.push({
39
+ entity: segmentToDelete,
40
+ operation: operation,
41
+ });
42
+ }
43
+ return true;
44
+ case 'Text':
45
+ var text = segmentToDelete.text;
46
+ if (text.length == 0 || segmentToDelete.isSelected) {
47
+ segments.splice(index, 1);
48
+ }
49
+ else if (direction) {
50
+ text = (0, deleteSingleChar_1.deleteSingleChar)(text, isForward); // isForward ? text.substring(1) : text.substring(0, text.length - 1);
51
+ if (!preserveWhiteSpace) {
52
+ text = (0, stringUtil_1.normalizeText)(text, isForward);
53
+ }
54
+ if (text == '') {
55
+ segments.splice(index, 1);
56
+ }
57
+ else {
58
+ segmentToDelete.text = text;
59
+ }
60
+ }
61
+ return true;
62
+ case 'General':
63
+ if (segmentToDelete.isSelected) {
64
+ segments.splice(index, 1);
65
+ return true;
66
+ }
67
+ else {
68
+ // No op if a general segment is not selected, let browser handle general segment
69
+ // TODO: Need to revisit this
70
+ return false;
71
+ }
72
+ }
73
+ }
74
+ exports.deleteSegment = deleteSegment;
75
+ function normalizePreviousSegment(segments, currentIndex) {
76
+ var _a;
77
+ var index = currentIndex - 1;
78
+ while (((_a = segments[index]) === null || _a === void 0 ? void 0 : _a.segmentType) == 'SelectionMarker') {
79
+ index--;
80
+ }
81
+ var segment = segments[index];
82
+ if (segment) {
83
+ (0, roosterjs_content_model_dom_1.normalizeSingleSegment)(segment);
84
+ }
85
+ }
86
+ });
87
+ //# sourceMappingURL=deleteSegment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteSegment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/selection/deleteSegment.ts"],"names":[],"mappings":";;;;IAUA;;;;;;;OAOG;IACH,SAAgB,aAAa,CACzB,SAAgC,EAChC,eAAoC,EACpC,OAAuC,EACvC,SAAkC;QAElC,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QACpC,IAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;QAChD,IAAM,kBAAkB,GAAG,IAAA,mDAAqB,EAAC,SAAS,CAAC,CAAC;QAC5D,IAAM,SAAS,GAAG,SAAS,IAAI,SAAS,C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SAAS,CAAC,CAAC;qBACzC;oBAED,IAAI,IAAI,IAAI,EAAE,EAAE;wBACZ,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;qBAC7B;yBAAM;wBACH,eAAe,CAAC,IAAI,GAAG,IAAI,CAAC;qBAC/B;iBACJ;gBAED,OAAO,IAAI,CAAC;YAEhB,KAAK,SAAS;gBACV,IAAI,eAAe,CAAC,UAAU,EAAE;oBAC5B,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBAC1B,OAAO,IAAI,CAAC;iBACf;qBAAM;oBACH,iFAAiF;oBACjF,6BAA6B;oBAC7B,OAAO,KAAK,CAAC;iBAChB;SACR;IACL,CAAC;IAxED,sCAwEC;IAED,SAAS,wBAAwB,CAAC,QAA+B,EAAE,YAAoB;;QACnF,IAAI,KAAK,GAAG,YAAY,GAAG,CAAC,CAAC;QAE7B,OAAO,CAAA,MAAA,QAAQ,CAAC,KAAK,CAAC,0CAAE,WAAW,KAAI,iBAAiB,EAAE;YACtD,KAAK,EAAE,CAAC;SACX;QAED,IAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEhC,IAAI,OAAO,EAAE;YACT,IAAA,oDAAsB,EAAC,OAAO,CAAC,CAAC;SACnC;IACL,CAAC","sourcesContent":["import { deleteSingleChar } from '../../modelApi/edit/deleteSingleChar';\nimport { isWhiteSpacePreserved, normalizeSingleSegment } from 'roosterjs-content-model-dom';\nimport { normalizeText } from '../domUtils/stringUtil';\nimport type {\n ContentModelParagraph,\n ContentModelSegment,\n EntityRemovalOperation,\n FormatWithContentModelContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Delete a content model segment from current selection\n * @param paragraph Parent paragraph of the segment to delete\n * @param segmentToDelete The segment to delete\n * @param context @optional Context object provided by formatContentModel API\n * @param direction @optional Whether this is deleting forward or backward. This is only used for deleting entity.\n * If not specified, only selected entity will be deleted\n */\nexport function deleteSegment(\n paragraph: ContentModelParagraph,\n segmentToDelete: ContentModelSegment,\n context?: FormatWithContentModelContext,\n direction?: 'forward' | 'backward'\n): boolean {\n const segments = paragraph.segments;\n const index = segments.indexOf(segmentToDelete);\n const preserveWhiteSpace = isWhiteSpacePreserved(paragraph);\n const isForward = direction == 'forward';\n const isBackward = direction == 'backward';\n\n if (!preserveWhiteSpace) {\n normalizePreviousSegment(segments, index);\n }\n\n switch (segmentToDelete.segmentType) {\n case 'Br':\n case 'Image':\n case 'SelectionMarker':\n segments.splice(index, 1);\n return true;\n\n case 'Entity':\n const operation: EntityRemovalOperation | undefined = segmentToDelete.isSelected\n ? 'overwrite'\n : isForward\n ? 'removeFromStart'\n : isBackward\n ? 'removeFromEnd'\n : undefined;\n if (operation !== undefined) {\n segments.splice(index, 1);\n context?.deletedEntities.push({\n entity: segmentToDelete,\n operation,\n });\n }\n\n return true;\n\n case 'Text':\n let text = segmentToDelete.text;\n\n if (text.length == 0 || segmentToDelete.isSelected) {\n segments.splice(index, 1);\n } else if (direction) {\n text = deleteSingleChar(text, isForward); // isForward ? text.substring(1) : text.substring(0, text.length - 1);\n\n if (!preserveWhiteSpace) {\n text = normalizeText(text, isForward);\n }\n\n if (text == '') {\n segments.splice(index, 1);\n } else {\n segmentToDelete.text = text;\n }\n }\n\n return true;\n\n case 'General':\n if (segmentToDelete.isSelected) {\n segments.splice(index, 1);\n return true;\n } else {\n // No op if a general segment is not selected, let browser handle general segment\n // TODO: Need to revisit this\n return false;\n }\n }\n}\n\nfunction normalizePreviousSegment(segments: ContentModelSegment[], currentIndex: number) {\n let index = currentIndex - 1;\n\n while (segments[index]?.segmentType == 'SelectionMarker') {\n index--;\n }\n\n const segment = segments[index];\n\n if (segment) {\n normalizeSingleSegment(segment);\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { ContentModelDocument, DeleteSelectionResult, DeleteSelectionStep, FormatWithContentModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Delete selected content from Content Model
4
+ * @param model The model to delete selected content from
5
+ * @param additionalSteps @optional Addition delete steps
6
+ * @param formatContext @optional A context object provided by formatContentModel API
7
+ * @returns A DeleteSelectionResult object to specify the deletion result
8
+ */
9
+ export declare function deleteSelection(model: ContentModelDocument, additionalSteps?: (DeleteSelectionStep | null)[], formatContext?: FormatWithContentModelContext): DeleteSelectionResult;
@@ -0,0 +1,44 @@
1
+ define(["require", "exports", "tslib", "../../modelApi/edit/deleteExpandedSelection"], function (require, exports, tslib_1, deleteExpandedSelection_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deleteSelection = void 0;
5
+ /**
6
+ * Delete selected content from Content Model
7
+ * @param model The model to delete selected content from
8
+ * @param additionalSteps @optional Addition delete steps
9
+ * @param formatContext @optional A context object provided by formatContentModel API
10
+ * @returns A DeleteSelectionResult object to specify the deletion result
11
+ */
12
+ function deleteSelection(model, additionalSteps, formatContext) {
13
+ if (additionalSteps === void 0) { additionalSteps = []; }
14
+ var context = (0, deleteExpandedSelection_1.deleteExpandedSelection)(model, formatContext);
15
+ additionalSteps.forEach(function (step) {
16
+ if (step &&
17
+ isValidDeleteSelectionContext(context) &&
18
+ context.deleteResult == 'notDeleted') {
19
+ step(context);
20
+ }
21
+ });
22
+ mergeParagraphAfterDelete(context);
23
+ return context;
24
+ }
25
+ exports.deleteSelection = deleteSelection;
26
+ function isValidDeleteSelectionContext(context) {
27
+ return !!context.insertPoint;
28
+ }
29
+ // If we end up with multiple paragraphs impacted, we need to merge them
30
+ function mergeParagraphAfterDelete(context) {
31
+ var _a;
32
+ var insertPoint = context.insertPoint, deleteResult = context.deleteResult, lastParagraph = context.lastParagraph, lastTableContext = context.lastTableContext;
33
+ if (insertPoint &&
34
+ deleteResult != 'notDeleted' &&
35
+ deleteResult != 'nothingToDelete' &&
36
+ lastParagraph &&
37
+ lastParagraph != insertPoint.paragraph &&
38
+ lastTableContext == insertPoint.tableContext) {
39
+ (_a = insertPoint.paragraph.segments).push.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(lastParagraph.segments), false));
40
+ lastParagraph.segments = [];
41
+ }
42
+ }
43
+ });
44
+ //# sourceMappingURL=deleteSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/selection/deleteSelection.ts"],"names":[],"mappings":";;;;IAUA;;;;;;OAMG;IACH,SAAgB,eAAe,CAC3B,KAA2B,EAC3B,eAAoD,EACpD,aAA6C;QAD7C,gCAAA,EAAA,oBAAoD;QAGpD,IAAM,OAAO,GAAG,IAAA,iDAAuB,EAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QAE9D,eAAe,CAAC,OAAO,CAAC,UAAA,IAAI;YACxB,IACI,IAAI;gBACJ,6BAA6B,CAAC,OAAO,CAAC;gBACtC,OAAO,CAAC,YAAY,IAAI,YAAY,EACtC;gBACE,IAAI,CAAC,OAAO,CAAC,CAAC;aACjB;QACL,CAAC,CAAC,CAAC;QAEH,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAEnC,OAAO,OAAO,CAAC;IACnB,CAAC;IApBD,0CAoBC;IAED,SAAS,6BAA6B,CAClC,OAA+B;QAE/B,OAAO,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;IACjC,CAAC;IAED,wEAAwE;IACxE,SAAS,yBAAyB,CAAC,OAA+B;;QACtD,IAAA,WAAW,GAAoD,OAAO,YAA3D,EAAE,YAAY,GAAsC,OAAO,aAA7C,EAAE,aAAa,GAAuB,OAAO,cAA9B,EAAE,gBAAgB,GAAK,OAAO,iBAAZ,CAAa;QAE/E,IACI,WAAW;YACX,YAAY,IAAI,YAAY;YAC5B,YAAY,IAAI,iBAAiB;YACjC,aAAa;YACb,aAAa,IAAI,WAAW,CAAC,SAAS;YACtC,gBAAgB,IAAI,WAAW,CAAC,YAAY,EAC9C;YACE,CAAA,KAAA,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAA,CAAC,IAAI,8DAAI,aAAa,CAAC,QAAQ,WAAE;YAC/D,aAAa,CAAC,QAAQ,GAAG,EAAE,CAAC;SAC/B;IACL,CAAC","sourcesContent":["import { deleteExpandedSelection } from '../../modelApi/edit/deleteExpandedSelection';\nimport type {\n ContentModelDocument,\n DeleteSelectionContext,\n DeleteSelectionResult,\n DeleteSelectionStep,\n FormatWithContentModelContext,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * Delete selected content from Content Model\n * @param model The model to delete selected content from\n * @param additionalSteps @optional Addition delete steps\n * @param formatContext @optional A context object provided by formatContentModel API\n * @returns A DeleteSelectionResult object to specify the deletion result\n */\nexport function deleteSelection(\n model: ContentModelDocument,\n additionalSteps: (DeleteSelectionStep | null)[] = [],\n formatContext?: FormatWithContentModelContext\n): DeleteSelectionResult {\n const context = deleteExpandedSelection(model, formatContext);\n\n additionalSteps.forEach(step => {\n if (\n step &&\n isValidDeleteSelectionContext(context) &&\n context.deleteResult == 'notDeleted'\n ) {\n step(context);\n }\n });\n\n mergeParagraphAfterDelete(context);\n\n return context;\n}\n\nfunction isValidDeleteSelectionContext(\n context: DeleteSelectionContext\n): context is ValidDeleteSelectionContext {\n return !!context.insertPoint;\n}\n\n// If we end up with multiple paragraphs impacted, we need to merge them\nfunction mergeParagraphAfterDelete(context: DeleteSelectionContext) {\n const { insertPoint, deleteResult, lastParagraph, lastTableContext } = context;\n\n if (\n insertPoint &&\n deleteResult != 'notDeleted' &&\n deleteResult != 'nothingToDelete' &&\n lastParagraph &&\n lastParagraph != insertPoint.paragraph &&\n lastTableContext == insertPoint.tableContext\n ) {\n insertPoint.paragraph.segments.push(...lastParagraph.segments);\n lastParagraph.segments = [];\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { DOMSelection } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Get root node of a given DOM selection
4
+ * For table selection, root node is the selected table
5
+ * For image selection, root node is the selected image
6
+ * For range selection, root node is the common ancestor container node of the selection range
7
+ * @param selection The selection to get root node from
8
+ */
9
+ export declare function getSelectionRootNode(selection: DOMSelection | undefined): Node | undefined;
@@ -0,0 +1,25 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getSelectionRootNode = void 0;
5
+ /**
6
+ * Get root node of a given DOM selection
7
+ * For table selection, root node is the selected table
8
+ * For image selection, root node is the selected image
9
+ * For range selection, root node is the common ancestor container node of the selection range
10
+ * @param selection The selection to get root node from
11
+ */
12
+ function getSelectionRootNode(selection) {
13
+ return !selection
14
+ ? undefined
15
+ : selection.type == 'range'
16
+ ? selection.range.commonAncestorContainer
17
+ : selection.type == 'table'
18
+ ? selection.table
19
+ : selection.type == 'image'
20
+ ? selection.image
21
+ : undefined;
22
+ }
23
+ exports.getSelectionRootNode = getSelectionRootNode;
24
+ });
25
+ //# sourceMappingURL=getSelectionRootNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSelectionRootNode.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/selection/getSelectionRootNode.ts"],"names":[],"mappings":";;;;IAEA;;;;;;OAMG;IACH,SAAgB,oBAAoB,CAAC,SAAmC;QACpE,OAAO,CAAC,SAAS;YACb,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,OAAO;gBAC3B,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,uBAAuB;gBACzC,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,OAAO;oBAC3B,CAAC,CAAC,SAAS,CAAC,KAAK;oBACjB,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,OAAO;wBAC3B,CAAC,CAAC,SAAS,CAAC,KAAK;wBACjB,CAAC,CAAC,SAAS,CAAC;IACpB,CAAC;IAVD,oDAUC","sourcesContent":["import type { DOMSelection } from 'roosterjs-content-model-types';\n\n/**\n * Get root node of a given DOM selection\n * For table selection, root node is the selected table\n * For image selection, root node is the selected image\n * For range selection, root node is the common ancestor container node of the selection range\n * @param selection The selection to get root node from\n */\nexport function getSelectionRootNode(selection: DOMSelection | undefined): Node | undefined {\n return !selection\n ? undefined\n : selection.type == 'range'\n ? selection.range.commonAncestorContainer\n : selection.type == 'table'\n ? selection.table\n : selection.type == 'image'\n ? selection.image\n : undefined;\n}\n"]}
@@ -0,0 +1,48 @@
1
+ import type { ContentModelBlock, ContentModelBlockGroup, ContentModelSegment, TableSelectionContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Options for iterateSelections API
4
+ */
5
+ export interface IterateSelectionsOption {
6
+ /**
7
+ * For selected table cell, this property determines how do we handle its content.
8
+ * include: No matter if table cell is selected, always invoke callback function for selected content (default value)
9
+ * ignoreForTable: When the whole table is selected we invoke callback for the table (using block parameter) but skip
10
+ * all its cells and content, otherwise keep invoking callback for table cell and content
11
+ * ignoreForTableOrCell: If whole table is selected, same with ignoreForTable, or if a table cell is selected, only
12
+ * invoke callback for the table cell itself but not for its content, otherwise keep invoking callback for content.
13
+ * @default include
14
+ */
15
+ contentUnderSelectedTableCell?: 'include' | 'ignoreForTable' | 'ignoreForTableOrCell';
16
+ /**
17
+ * For a selected general element, this property determines how do we handle its content.
18
+ * contentOnly: (Default) When the whole general element is selected, we only invoke callback for its selected content
19
+ * generalElementOnly: When the whole general element is selected, we only invoke callback for the general element (using block or
20
+ * segment parameter depends on if it is a block or segment), but skip all its content.
21
+ * both: When general element is selected, we invoke callback first for its content, then for general element itself
22
+ */
23
+ contentUnderSelectedGeneralElement?: 'contentOnly' | 'generalElementOnly' | 'both';
24
+ /**
25
+ * Whether call the callback for the list item format holder segment
26
+ * anySegment: call the callback if any segment is selected under a list item
27
+ * allSegments: call the callback only when all segments under the list item are selected
28
+ * never: never call the callback for list item format holder
29
+ * @default allSegments
30
+ */
31
+ includeListFormatHolder?: 'anySegment' | 'allSegments' | 'never';
32
+ }
33
+ /**
34
+ * The callback function type for iterateSelections
35
+ * @param path The block group path of current selection
36
+ * @param tableContext Table context of current selection
37
+ * @param block Block of current selection
38
+ * @param segments Segments of current selection
39
+ * @returns True to stop iterating, otherwise keep going
40
+ */
41
+ export declare type IterateSelectionsCallback = (path: ContentModelBlockGroup[], tableContext?: TableSelectionContext, block?: ContentModelBlock, segments?: ContentModelSegment[]) => void | boolean;
42
+ /**
43
+ * Iterate all selected elements in a given model
44
+ * @param group The given Content Model to iterate selection from
45
+ * @param callback The callback function to access the selected element
46
+ * @param option Option to determine how to iterate
47
+ */
48
+ export declare function iterateSelections(group: ContentModelBlockGroup, callback: IterateSelectionsCallback, option?: IterateSelectionsOption): void;