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 @@
1
+ {"version":3,"file":"cloneModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/model/cloneModel.ts"],"names":[],"m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oB,CAAC,IAAI,EAAE,IAAI,CAAkB,CAAC;QAEjE,IAAI,CAAC,IAAI,IAAI,SAAS,IAAI,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE;YACpD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;SACxE;QAED,OAAO,MAAM,CAAC;KACjB;AACL,CAAC","sourcesContent":["import type {\n ContentModelBlock,\n ContentModelBlockBase,\n ContentModelBlockGroupBase,\n ContentModelBlockGroupType,\n ContentModelBlockType,\n ContentModelDivider,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelFormatBase,\n ContentModelFormatContainer,\n ContentModelGeneralBlock,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentBase,\n ContentModelSegmentType,\n ContentModelSelectionMarker,\n ContentModelTable,\n ContentModelTableCell,\n ContentModelWithDataset,\n ContentModelWithFormat,\n ContentModelGeneralSegment,\n ContentModelText,\n ContentModelTableRow,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\n/**\n * Function type used for cloneModel API to specify how to handle cached element when clone a model\n * @param node The cached node\n * @param type Type of the node, it can be\n * - general: DOM element of ContentModelGeneralSegment or ContentModelGeneralBlock\n * - entity: Wrapper element in ContentModelEntity\n * - cache: Cached node in other model element that supports cache\n */\nexport type CachedElementHandler = (\n node: HTMLElement,\n type: 'general' | 'entity' | 'cache'\n) => HTMLElement | undefined;\n\n/**\n *\n * Options for cloneModel API\n */\nexport interface CloneModelOptions {\n /**\n * Specify how to deal with cached element, including cached block element, element in General Model, and wrapper element in Entity\n * - True: Cloned model will have the same reference to the cached element\n * - False/Not passed: For cached block element, cached element will be undefined. For General Model and Entity, the element will have deep clone and assign to the cloned model\n * - A callback: invoke the callback with the source cached element and a string to specify model type, let the callback return the expected value of cached element.\n * For General Model and Entity, the callback must return a valid element, otherwise there will be exception thrown.\n */\n includeCachedElement?: boolean | CachedElementHandler;\n}\n\n/**\n * Clone a content model\n * @param model The content model to clone\n * @param options @optional Options to specify customize the clone behavior\n */\nexport function cloneModel(\n model: ContentModelDocument,\n options?: CloneModelOptions\n): ContentModelDocument {\n const newModel: ContentModelDocument = cloneBlockGroupBase(model, options || {});\n\n if (model.format) {\n newModel.format = Object.assign({}, model.format);\n }\n\n return newModel;\n}\n\nfunction cloneBlock(block: ContentModelBlock, options: CloneModelOptions): ContentModelBlock {\n switch (block.blockType) {\n case 'BlockGroup':\n switch (block.blockGroupType) {\n case 'FormatContainer':\n return cloneFormatContainer(block, options);\n case 'General':\n return cloneGeneralBlock(block, options);\n case 'ListItem':\n return cloneListItem(block, options);\n }\n break;\n case 'Divider':\n return cloneDivider(block, options);\n case 'Entity':\n return cloneEntity(block, options);\n case 'Paragraph':\n return cloneParagraph(block, options);\n case 'Table':\n return cloneTable(block, options);\n }\n}\n\nfunction cloneSegment(\n segment: ContentModelSegment,\n options: CloneModelOptions\n): ContentModelSegment {\n switch (segment.segmentType) {\n case 'Br':\n return cloneSegmentBase(segment);\n case 'Entity':\n return cloneEntity(segment, options);\n case 'General':\n return cloneGeneralSegment(segment, options);\n case 'Image':\n return cloneImage(segment);\n case 'SelectionMarker':\n return cloneSelectionMarker(segment);\n case 'Text':\n return cloneText(segment);\n }\n}\n\nfunction cloneModelWithFormat<T extends ContentModelFormatBase>(\n model: ContentModelWithFormat<T>\n): ContentModelWithFormat<T> {\n return {\n format: Object.assign({}, model.format),\n };\n}\n\nfunction cloneModelWithDataset<T>(model: ContentModelWithDataset<T>): ContentModelWithDataset<T> {\n return {\n dataset: Object.assign({}, model.dataset),\n };\n}\n\nfunction cloneBlockBase<T extends ContentModelBlockType>(\n block: ContentModelBlockBase<T>\n): ContentModelBlockBase<T> {\n const { blockType } = block;\n\n return Object.assign(\n {\n blockType,\n },\n cloneModelWithFormat(block)\n );\n}\n\nfunction cloneBlockGroupBase<T extends ContentModelBlockGroupType>(\n group: ContentModelBlockGroupBase<T>,\n options: CloneModelOptions\n): ContentModelBlockGroupBase<T> {\n const { blockGroupType, blocks } = group;\n\n return {\n blockGroupType: blockGroupType,\n blocks: blocks.map(block => cloneBlock(block, options)),\n };\n}\n\nfunction cloneSegmentBase<T extends ContentModelSegmentType>(\n segment: ContentModelSegmentBase<T>\n): ContentModelSegmentBase<T> {\n const { segmentType, isSelected, code, link } = segment;\n\n const newSegment: ContentModelSegmentBase<T> = Object.assign(\n {\n segmentType,\n isSelected,\n },\n cloneModelWithFormat(segment)\n );\n\n if (code) {\n newSegment.code = cloneModelWithFormat(code);\n }\n if (link) {\n newSegment.link = Object.assign(cloneModelWithFormat(link), cloneModelWithDataset(link));\n }\n\n return newSegment;\n}\n\nfunction cloneEntity(entity: ContentModelEntity, options: CloneModelOptions): ContentModelEntity {\n const { wrapper, entityFormat } = entity;\n\n return Object.assign(\n {\n wrapper: handleCachedElement(wrapper, 'entity', options),\n entityFormat: { ...entityFormat },\n },\n cloneBlockBase(entity),\n cloneSegmentBase(entity)\n );\n}\n\nfunction cloneParagraph(\n paragraph: ContentModelParagraph,\n options: CloneModelOptions\n): ContentModelParagraph {\n const { cachedElement, segments, isImplicit, decorator, segmentFormat } = paragraph;\n\n const newParagraph: ContentModelParagraph = Object.assign(\n {\n cachedElement: handleCachedElement(cachedElement, 'cache', options),\n isImplicit,\n segments: segments.map(segment => cloneSegment(segment, options)),\n segmentFormat: segmentFormat ? { ...segmentFormat } : undefined,\n },\n cloneBlockBase(paragraph),\n cloneModelWithFormat(paragraph)\n );\n\n if (decorator) {\n newParagraph.decorator = Object.assign(\n {\n tagName: decorator.tagName,\n },\n cloneModelWithFormat(decorator)\n );\n }\n\n return newParagraph;\n}\n\nfunction cloneTable(table: ContentModelTable, options: CloneModelOptions): ContentModelTable {\n const { cachedElement, widths, rows } = table;\n\n return Object.assign(\n {\n cachedElement: handleCachedElement(cachedElement, 'cache', options),\n widths: Array.from(widths),\n rows: rows.map(row => cloneTableRow(row, options)),\n },\n cloneBlockBase(table),\n cloneModelWithDataset(table)\n );\n}\n\nfunction cloneTableRow(\n row: ContentModelTableRow,\n options: CloneModelOptions\n): ContentModelTableRow {\n const { height, cells, cachedElement } = row;\n\n return Object.assign(\n {\n height,\n cachedElement: handleCachedElement(cachedElement, 'cache', options),\n cells: cells.map(cell => cloneTableCell(cell, options)),\n },\n cloneModelWithFormat(row)\n );\n}\n\nfunction cloneTableCell(\n cell: ContentModelTableCell,\n options: CloneModelOptions\n): ContentModelTableCell {\n const { cachedElement, isSelected, spanAbove, spanLeft, isHeader } = cell;\n\n return Object.assign(\n {\n cachedElement: handleCachedElement(cachedElement, 'cache', options),\n isSelected,\n spanAbove,\n spanLeft,\n isHeader,\n },\n cloneBlockGroupBase(cell, options),\n cloneModelWithFormat(cell),\n cloneModelWithDataset(cell)\n );\n}\n\nfunction cloneFormatContainer(\n container: ContentModelFormatContainer,\n options: CloneModelOptions\n): ContentModelFormatContainer {\n const { tagName, cachedElement } = container;\n const newContainer: ContentModelFormatContainer = Object.assign(\n { tagName, cachedElement: handleCachedElement(cachedElement, 'cache', options) },\n cloneBlockBase(container),\n cloneBlockGroupBase(container, options)\n );\n\n if (container.zeroFontSize) {\n newContainer.zeroFontSize = true;\n }\n\n return newContainer;\n}\n\nfunction cloneListItem(\n item: ContentModelListItem,\n options: CloneModelOptions\n): ContentModelListItem {\n const { formatHolder, levels } = item;\n\n return Object.assign(\n {\n formatHolder: cloneSelectionMarker(formatHolder),\n levels: levels.map(cloneListLevel),\n },\n cloneBlockBase(item),\n cloneBlockGroupBase(item, options)\n );\n}\n\nfunction cloneListLevel(level: ContentModelListLevel): ContentModelListLevel {\n const { listType } = level;\n\n return Object.assign({ listType }, cloneModelWithFormat(level), cloneModelWithDataset(level));\n}\nfunction cloneDivider(\n divider: ContentModelDivider,\n options: CloneModelOptions\n): ContentModelDivider {\n const { tagName, isSelected, cachedElement } = divider;\n\n return Object.assign(\n {\n isSelected,\n tagName,\n cachedElement: handleCachedElement(cachedElement, 'cache', options),\n },\n cloneBlockBase(divider)\n );\n}\n\nfunction cloneGeneralBlock(\n general: ContentModelGeneralBlock,\n options: CloneModelOptions\n): ContentModelGeneralBlock {\n const { element } = general;\n\n return Object.assign(\n {\n element: handleCachedElement(element, 'general', options),\n },\n cloneBlockBase(general),\n cloneBlockGroupBase(general, options)\n );\n}\n\nfunction cloneSelectionMarker(marker: ContentModelSelectionMarker): ContentModelSelectionMarker {\n return Object.assign({ isSelected: marker.isSelected }, cloneSegmentBase(marker));\n}\n\nfunction cloneImage(image: ContentModelImage): ContentModelImage {\n const { src, alt, title, isSelectedAsImageSelection } = image;\n\n return Object.assign(\n { src, alt, title, isSelectedAsImageSelection },\n cloneSegmentBase(image),\n cloneModelWithDataset(image)\n );\n}\n\nfunction cloneGeneralSegment(\n general: ContentModelGeneralSegment,\n options: CloneModelOptions\n): ContentModelGeneralSegment {\n return Object.assign(cloneGeneralBlock(general, options), cloneSegmentBase(general));\n}\n\nfunction cloneText(textSegment: ContentModelText): ContentModelText {\n const { text } = textSegment;\n return Object.assign({ text }, cloneSegmentBase(textSegment));\n}\n\nfunction handleCachedElement<T extends HTMLElement>(\n node: T,\n type: 'general' | 'entity',\n options: CloneModelOptions\n): T;\n\nfunction handleCachedElement<T extends HTMLElement>(\n node: T | undefined,\n type: 'cache',\n options: CloneModelOptions\n): T | undefined;\n\nfunction handleCachedElement<T extends HTMLElement>(\n node: T | undefined,\n type: 'general' | 'entity' | 'cache',\n options: CloneModelOptions\n): T | undefined {\n const { includeCachedElement } = options;\n\n if (!node) {\n return undefined;\n } else if (!includeCachedElement) {\n return type == 'cache' ? undefined : (node.cloneNode(true /*deep*/) as T);\n } else if (includeCachedElement === true) {\n return node;\n } else {\n const result = includeCachedElement(node, type) as T | undefined;\n\n if ((type == 'general' || type == 'entity') && !result) {\n throw new Error('Entity and General Model must has wrapper element');\n }\n\n return result;\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { ContentModelBlockGroup, ContentModelBlockGroupBase, ContentModelBlockGroupType } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Retrieve block group type string from a given block group
4
+ */
5
+ export declare type TypeOfBlockGroup<T extends ContentModelBlockGroup> = T extends ContentModelBlockGroupBase<infer U> ? U : never;
6
+ /**
7
+ * Get index of closest ancestor block group of the expected block group type. If not found, return -1
8
+ * @param path The block group path, from the closest one to root
9
+ * @param blockGroupTypes The expected block group types
10
+ * @param stopTypes @optional Block group types that will cause stop searching
11
+ */
12
+ export declare function getClosestAncestorBlockGroupIndex<T extends ContentModelBlockGroup>(path: ContentModelBlockGroup[], blockGroupTypes: TypeOfBlockGroup<T>[], stopTypes?: ContentModelBlockGroupType[]): number;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Get index of closest ancestor block group of the expected block group type. If not found, return -1
3
+ * @param path The block group path, from the closest one to root
4
+ * @param blockGroupTypes The expected block group types
5
+ * @param stopTypes @optional Block group types that will cause stop searching
6
+ */
7
+ export function getClosestAncestorBlockGroupIndex(path, blockGroupTypes, stopTypes) {
8
+ if (stopTypes === void 0) { stopTypes = []; }
9
+ for (var i = 0; i < path.length; i++) {
10
+ var group = path[i];
11
+ if (blockGroupTypes.indexOf(group.blockGroupType) >= 0) {
12
+ return i;
13
+ }
14
+ else if (stopTypes.indexOf(group.blockGroupType) >= 0) {
15
+ // Do not go across boundary specified by stopTypes.
16
+ // For example, in most case we will set table as the boundary,
17
+ // in order to allow modify list item under a table when the table itself is in another list item
18
+ // Although this is not very likely to happen in most case, but we still need to handle it
19
+ return -1;
20
+ }
21
+ }
22
+ return -1;
23
+ }
24
+ //# sourceMappingURL=getClosestAncestorBlockGroupIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getClosestAncestorBlockGroupIndex.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/model/getClosestAncestorBlockGroupIndex.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAC7C,IAA8B,EAC9B,eAAsC,EACtC,SAA4C;IAA5C,0BAAA,EAAA,cAA4C;IAE5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,IAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAK,eAA4B,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;YAClE,OAAO,CAAC,CAAC;SACZ;aAAM,IAAI,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;YACrD,oDAAoD;YACpD,+DAA+D;YAC/D,iGAAiG;YACjG,0FAA0F;YAC1F,OAAO,CAAC,CAAC,CAAC;SACb;KACJ;IAED,OAAO,CAAC,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type {\n ContentModelBlockGroup,\n ContentModelBlockGroupBase,\n ContentModelBlockGroupType,\n} from 'roosterjs-content-model-types';\n\n/**\n * Retrieve block group type string from a given block group\n */\nexport type TypeOfBlockGroup<\n T extends ContentModelBlockGroup\n> = T extends ContentModelBlockGroupBase<infer U> ? U : never;\n\n/**\n * Get index of closest ancestor block group of the expected block group type. If not found, return -1\n * @param path The block group path, from the closest one to root\n * @param blockGroupTypes The expected block group types\n * @param stopTypes @optional Block group types that will cause stop searching\n */\nexport function getClosestAncestorBlockGroupIndex<T extends ContentModelBlockGroup>(\n path: ContentModelBlockGroup[],\n blockGroupTypes: TypeOfBlockGroup<T>[],\n stopTypes: ContentModelBlockGroupType[] = []\n): number {\n for (let i = 0; i < path.length; i++) {\n const group = path[i];\n\n if ((blockGroupTypes as string[]).indexOf(group.blockGroupType) >= 0) {\n return i;\n } else if (stopTypes.indexOf(group.blockGroupType) >= 0) {\n // Do not go across boundary specified by stopTypes.\n // For example, in most case we will set table as the boundary,\n // in order to allow modify list item under a table when the table itself is in another list item\n // Although this is not very likely to happen in most case, but we still need to handle it\n return -1;\n }\n }\n\n return -1;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelBlock, ContentModelBlockGroup } from 'roosterjs-content-model-types';
2
+ import type { TypeOfBlockGroup } from './getClosestAncestorBlockGroupIndex';
3
+ /**
4
+ * Check if the given content model block or block group is of the expected block group type
5
+ * @param input The object to check
6
+ * @param type The expected type
7
+ */
8
+ export declare function isBlockGroupOfType<T extends ContentModelBlockGroup>(input: ContentModelBlock | ContentModelBlockGroup | null | undefined, type: TypeOfBlockGroup<T>): input is T;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Check if the given content model block or block group is of the expected block group type
3
+ * @param input The object to check
4
+ * @param type The expected type
5
+ */
6
+ export function isBlockGroupOfType(input, type) {
7
+ var item = input;
8
+ return (item === null || item === void 0 ? void 0 : item.blockGroupType) == type;
9
+ }
10
+ //# sourceMappingURL=isBlockGroupOfType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isBlockGroupOfType.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/model/isBlockGroupOfType.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAC9B,KAAoE,EACpE,IAAyB;IAEzB,IAAM,IAAI,GAAyB,KAAK,CAAC;IAEzC,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,cAAc,KAAI,IAAI,CAAC;AACxC,CAAC","sourcesContent":["import type { ContentModelBlock, ContentModelBlockGroup } from 'roosterjs-content-model-types';\nimport type { TypeOfBlockGroup } from './getClosestAncestorBlockGroupIndex';\n\n/**\n * Check if the given content model block or block group is of the expected block group type\n * @param input The object to check\n * @param type The expected type\n */\nexport function isBlockGroupOfType<T extends ContentModelBlockGroup>(\n input: ContentModelBlock | ContentModelBlockGroup | null | undefined,\n type: TypeOfBlockGroup<T>\n): input is T {\n const item = <T | null | undefined>input;\n\n return item?.blockGroupType == type;\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import type { ContentModelDocument, FormatWithContentModelContext, InsertPoint } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Options to specify how to merge models
4
+ */
5
+ export interface MergeModelOption {
6
+ /**
7
+ * When there is only a table to merge, whether merge this table into current table (if any), or just directly insert (nested table).
8
+ * This is usually used when paste table inside a table
9
+ * @default false
10
+ */
11
+ mergeTable?: boolean;
12
+ /**
13
+ * Use this insert position to merge instead of querying selection from target model
14
+ * @default undefined
15
+ */
16
+ insertPosition?: InsertPoint;
17
+ /**
18
+ * Use this to decide whether to change the source model format when doing the merge.
19
+ * 'mergeAll': segment format of the insert position will be merged into the content that is merged into current model.
20
+ * If the source model already has some format, it will not be overwritten.
21
+ * 'keepSourceEmphasisFormat': format of the insert position will be set into the content that is merged into current model.
22
+ * If the source model already has emphasis format, such as, fontWeight, Italic or underline different than the default style, it will not be overwritten.
23
+ * 'none' the source segment format will not be modified.
24
+ * @default undefined
25
+ */
26
+ mergeFormat?: 'mergeAll' | 'keepSourceEmphasisFormat' | 'none';
27
+ }
28
+ /**
29
+ * Merge source model into target mode
30
+ * @param target Target Content Model that will merge content into
31
+ * @param source Source Content Model will be merged to target model
32
+ * @param context Format context. When call this function inside formatContentModel, provide this context so that formatContentModel will do extra handling to the result
33
+ * @param options More options, see MergeModelOption
34
+ * @returns Insert point after merge, or null if there is no insert point
35
+ */
36
+ export declare function mergeModel(target: ContentModelDocument, source: ContentModelDocument, context?: FormatWithContentModelContext, options?: MergeModelOption): InsertPoint | null;
@@ -0,0 +1,258 @@
1
+ import { __assign } from "tslib";
2
+ import { applyTableFormat } from '../table/applyTableFormat';
3
+ import { deleteSelection } from '../../publicApi/selection/deleteSelection';
4
+ import { getClosestAncestorBlockGroupIndex } from './getClosestAncestorBlockGroupIndex';
5
+ import { normalizeTable } from '../table/normalizeTable';
6
+ import { addSegment, createListItem, createParagraph, createSelectionMarker, createTableCell, getObjectKeys, normalizeContentModel, } from 'roosterjs-content-model-dom';
7
+ var HeadingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
8
+ /**
9
+ * Merge source model into target mode
10
+ * @param target Target Content Model that will merge content into
11
+ * @param source Source Content Model will be merged to target model
12
+ * @param context Format context. When call this function inside formatContentModel, provide this context so that formatContentModel will do extra handling to the result
13
+ * @param options More options, see MergeModelOption
14
+ * @returns Insert point after merge, or null if there is no insert point
15
+ */
16
+ export function mergeModel(target, source, context, options) {
17
+ var _a;
18
+ var insertPosition = (_a = options === null || options === void 0 ? void 0 : options.insertPosition) !== null && _a !== void 0 ? _a : deleteSelection(target, [], context).insertPoint;
19
+ if (insertPosition) {
20
+ if ((options === null || options === void 0 ? void 0 : options.mergeFormat) && options.mergeFormat != 'none') {
21
+ var newFormat = __assign(__assign({}, (target.format || {})), insertPosition.marker.format);
22
+ applyDefaultFormat(source, newFormat, options === null || options === void 0 ? void 0 : options.mergeFormat);
23
+ }
24
+ for (var i = 0; i < source.blocks.length; i++) {
25
+ var block = source.blocks[i];
26
+ switch (block.blockType) {
27
+ case 'Paragraph':
28
+ mergeParagraph(insertPosition, block, i == 0, context, options);
29
+ break;
30
+ case 'Divider':
31
+ insertBlock(insertPosition, block);
32
+ break;
33
+ case 'Entity':
34
+ insertBlock(insertPosition, block);
35
+ context === null || context === void 0 ? void 0 : context.newEntities.push(block);
36
+ break;
37
+ case 'Table':
38
+ if (source.blocks.length == 1 && (options === null || options === void 0 ? void 0 : options.mergeTable)) {
39
+ mergeTable(insertPosition, block, source);
40
+ }
41
+ else {
42
+ insertBlock(insertPosition, block);
43
+ }
44
+ break;
45
+ case 'BlockGroup':
46
+ switch (block.blockGroupType) {
47
+ case 'General':
48
+ case 'FormatContainer':
49
+ insertBlock(insertPosition, block);
50
+ break;
51
+ case 'ListItem':
52
+ mergeList(insertPosition, block);
53
+ break;
54
+ }
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ normalizeContentModel(target);
60
+ return insertPosition;
61
+ }
62
+ function mergeParagraph(markerPosition, newPara, mergeToCurrentParagraph, context, option) {
63
+ var paragraph = markerPosition.paragraph, marker = markerPosition.marker;
64
+ var newParagraph = mergeToCurrentParagraph
65
+ ? paragraph
66
+ : splitParagraph(markerPosition, newPara.format);
67
+ var segmentIndex = newParagraph.segments.indexOf(marker);
68
+ if ((option === null || option === void 0 ? void 0 : option.mergeFormat) == 'none' && mergeToCurrentParagraph) {
69
+ newParagraph.segments.forEach(function (segment) {
70
+ segment.format = __assign(__assign({}, (newParagraph.segmentFormat || {})), segment.format);
71
+ });
72
+ delete newParagraph.segmentFormat;
73
+ }
74
+ if (segmentIndex >= 0) {
75
+ for (var i = 0; i < newPara.segments.length; i++) {
76
+ var segment = newPara.segments[i];
77
+ newParagraph.segments.splice(segmentIndex + i, 0, segment);
78
+ if (context) {
79
+ if (segment.segmentType == 'Entity') {
80
+ context.newEntities.push(segment);
81
+ }
82
+ if (segment.segmentType == 'Image') {
83
+ context.newImages.push(segment);
84
+ }
85
+ }
86
+ }
87
+ }
88
+ if (newPara.decorator) {
89
+ newParagraph.decorator = __assign({}, newPara.decorator);
90
+ if (HeadingTags.indexOf(newParagraph.decorator.tagName) > -1) {
91
+ var sourceKeys = getObjectKeys(newParagraph.decorator.format);
92
+ var segmentDecoratorKeys_1 = getObjectKeys(newParagraph.segmentFormat || {});
93
+ sourceKeys.forEach(function (key) {
94
+ var _a;
95
+ if (segmentDecoratorKeys_1.indexOf(key) > -1) {
96
+ (_a = newParagraph.segmentFormat) === null || _a === void 0 ? true : delete _a[key];
97
+ }
98
+ });
99
+ }
100
+ }
101
+ if (!mergeToCurrentParagraph) {
102
+ newParagraph.format = newPara.format;
103
+ }
104
+ }
105
+ function mergeTable(markerPosition, newTable, source) {
106
+ var _a, _b;
107
+ var tableContext = markerPosition.tableContext, marker = markerPosition.marker;
108
+ if (tableContext && source.blocks.length == 1 && source.blocks[0] == newTable) {
109
+ var table = tableContext.table, colIndex = tableContext.colIndex, rowIndex = tableContext.rowIndex;
110
+ for (var i = 0; i < newTable.rows.length; i++) {
111
+ for (var j = 0; j < newTable.rows[i].cells.length; j++) {
112
+ var newCell = newTable.rows[i].cells[j];
113
+ if (i == 0 && colIndex + j >= table.rows[0].cells.length) {
114
+ for (var k = 0; k < table.rows.length; k++) {
115
+ var leftCell = (_a = table.rows[k]) === null || _a === void 0 ? void 0 : _a.cells[colIndex + j - 1];
116
+ table.rows[k].cells[colIndex + j] = createTableCell(false /*spanLeft*/, false /*spanAbove*/, leftCell === null || leftCell === void 0 ? void 0 : leftCell.isHeader, leftCell === null || leftCell === void 0 ? void 0 : leftCell.format);
117
+ }
118
+ }
119
+ if (j == 0 && rowIndex + i >= table.rows.length) {
120
+ if (!table.rows[rowIndex + i]) {
121
+ table.rows[rowIndex + i] = {
122
+ cells: [],
123
+ format: {},
124
+ height: 0,
125
+ };
126
+ }
127
+ for (var k = 0; k < table.rows[rowIndex].cells.length; k++) {
128
+ var aboveCell = (_b = table.rows[rowIndex + i - 1]) === null || _b === void 0 ? void 0 : _b.cells[k];
129
+ table.rows[rowIndex + i].cells[k] = createTableCell(false /*spanLeft*/, false /*spanAbove*/, false /*isHeader*/, aboveCell === null || aboveCell === void 0 ? void 0 : aboveCell.format);
130
+ }
131
+ }
132
+ var oldCell = table.rows[rowIndex + i].cells[colIndex + j];
133
+ table.rows[rowIndex + i].cells[colIndex + j] = newCell;
134
+ if (i == 0 && j == 0) {
135
+ var newMarker = createSelectionMarker(marker.format);
136
+ var newPara = addSegment(newCell, newMarker);
137
+ if (markerPosition.path[0] == oldCell) {
138
+ // Update insert point to match the change result
139
+ markerPosition.path[0] = newCell;
140
+ markerPosition.marker = newMarker;
141
+ markerPosition.paragraph = newPara;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ normalizeTable(table, markerPosition.marker.format);
147
+ applyTableFormat(table, undefined /*newFormat*/, true /*keepCellShade*/);
148
+ }
149
+ else {
150
+ insertBlock(markerPosition, newTable);
151
+ }
152
+ }
153
+ function mergeList(markerPosition, newList) {
154
+ splitParagraph(markerPosition, newList.format);
155
+ var path = markerPosition.path, paragraph = markerPosition.paragraph;
156
+ var listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem']);
157
+ var listItem = path[listItemIndex];
158
+ var listParent = path[listItemIndex + 1]; // It is ok here when index is -1, that means there is no list and we just insert a new paragraph and use path[0] as its parent
159
+ var blockIndex = listParent.blocks.indexOf(listItem || paragraph);
160
+ if (blockIndex >= 0) {
161
+ listParent.blocks.splice(blockIndex, 0, newList);
162
+ }
163
+ if (listItem) {
164
+ listItem === null || listItem === void 0 ? void 0 : listItem.levels.forEach(function (level, i) {
165
+ newList.levels[i] = __assign({}, level);
166
+ });
167
+ }
168
+ }
169
+ function splitParagraph(markerPosition, newParaFormat) {
170
+ var paragraph = markerPosition.paragraph, marker = markerPosition.marker, path = markerPosition.path;
171
+ var segmentIndex = paragraph.segments.indexOf(marker);
172
+ var paraIndex = path[0].blocks.indexOf(paragraph);
173
+ var newParagraph = createParagraph(false /*isImplicit*/, __assign(__assign({}, paragraph.format), newParaFormat), paragraph.segmentFormat);
174
+ if (segmentIndex >= 0) {
175
+ newParagraph.segments = paragraph.segments.splice(segmentIndex);
176
+ }
177
+ if (paraIndex >= 0) {
178
+ path[0].blocks.splice(paraIndex + 1, 0, newParagraph);
179
+ }
180
+ var listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], ['FormatContainer', 'TableCell']);
181
+ var listItem = path[listItemIndex];
182
+ if (listItem) {
183
+ var listParent = listItemIndex >= 0 ? path[listItemIndex + 1] : null;
184
+ var blockIndex = listParent ? listParent.blocks.indexOf(listItem) : -1;
185
+ if (blockIndex >= 0 && listParent) {
186
+ var newListItem = createListItem(listItem.levels, listItem.formatHolder.format);
187
+ if (paraIndex >= 0) {
188
+ newListItem.blocks = listItem.blocks.splice(paraIndex + 1);
189
+ }
190
+ if (blockIndex >= 0) {
191
+ listParent.blocks.splice(blockIndex + 1, 0, newListItem);
192
+ }
193
+ path[listItemIndex] = newListItem;
194
+ }
195
+ }
196
+ markerPosition.paragraph = newParagraph;
197
+ return newParagraph;
198
+ }
199
+ function insertBlock(markerPosition, block) {
200
+ var path = markerPosition.path;
201
+ var newParaFormat = block.blockType !== 'Paragraph' ? {} : block.format;
202
+ var newPara = splitParagraph(markerPosition, newParaFormat);
203
+ var blockIndex = path[0].blocks.indexOf(newPara);
204
+ if (blockIndex >= 0) {
205
+ path[0].blocks.splice(blockIndex, 0, block);
206
+ }
207
+ }
208
+ function applyDefaultFormat(group, format, applyDefaultFormatOption) {
209
+ group.blocks.forEach(function (block) {
210
+ var _a;
211
+ switch (block.blockType) {
212
+ case 'BlockGroup':
213
+ if (block.blockGroupType == 'ListItem') {
214
+ block.formatHolder.format = mergeSegmentFormat(applyDefaultFormatOption, format, block.formatHolder.format);
215
+ }
216
+ applyDefaultFormat(block, format, applyDefaultFormatOption);
217
+ break;
218
+ case 'Table':
219
+ block.rows.forEach(function (row) {
220
+ return row.cells.forEach(function (cell) {
221
+ applyDefaultFormat(cell, format, applyDefaultFormatOption);
222
+ });
223
+ });
224
+ break;
225
+ case 'Paragraph':
226
+ var paragraphFormat_1 = ((_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format) || {};
227
+ block.segments.forEach(function (segment) {
228
+ if (segment.segmentType == 'General') {
229
+ applyDefaultFormat(segment, format, applyDefaultFormatOption);
230
+ }
231
+ segment.format = mergeSegmentFormat(applyDefaultFormatOption, format, __assign(__assign({}, paragraphFormat_1), segment.format));
232
+ });
233
+ if (applyDefaultFormatOption === 'keepSourceEmphasisFormat') {
234
+ delete block.decorator;
235
+ }
236
+ break;
237
+ }
238
+ });
239
+ }
240
+ function mergeSegmentFormat(applyDefaultFormatOption, targetformat, sourceFormat) {
241
+ return applyDefaultFormatOption == 'mergeAll'
242
+ ? __assign(__assign({}, targetformat), sourceFormat) : __assign(__assign({}, targetformat), getSemanticFormat(sourceFormat));
243
+ }
244
+ function getSemanticFormat(segmentFormat) {
245
+ var result = {};
246
+ var fontWeight = segmentFormat.fontWeight, italic = segmentFormat.italic, underline = segmentFormat.underline;
247
+ if (fontWeight && fontWeight != 'normal') {
248
+ result.fontWeight = fontWeight;
249
+ }
250
+ if (italic) {
251
+ result.italic = italic;
252
+ }
253
+ if (underline) {
254
+ result.underline = underline;
255
+ }
256
+ return result;
257
+ }
258
+ //# sourceMappingURL=mergeModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeModel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/publicApi/model/mergeModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,UAAU,EACV,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,aAAa,EACb,qBAAqB,GACxB,MAAM,6BAA6B,CAAC;AAcrC,IAAM,WAAW,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AA+BzD;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CACtB,MAA4B,EAC5B,MAA4B,EAC5B,OAAuC,EACvC,OAA0B;;IAE1B,IAAM,cAAc,GAChB,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,mCAAI,eAAe,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;IAEhF,IAAI,cAAc,EAAE;QAChB,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,OAAO,CAAC,WAAW,IAAI,MAAM,EAAE;YACvD,IAAM,SAAS,yBACR,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,GACrB,cAAc,CAAC,MAAM,CAAC,MAAM,CAClC,CAAC;YAEF,kBAAkB,CAA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AAwC;IAC/D,IAAM,MAAM,GAA8B,EAAE,CAAC;IAErC,IAAA,UAAU,GAAwB,aAAa,WAArC,EAAE,MAAM,GAAgB,aAAa,OAA7B,EAAE,SAAS,GAAK,aAAa,UAAlB,CAAmB;IAExD,IAAI,UAAU,IAAI,UAAU,IAAI,QAAQ,EAAE;QACtC,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC;KAClC;IACD,IAAI,MAAM,EAAE;QACR,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;KAC1B;IACD,IAAI,SAAS,EAAE;QACX,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;KAChC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { applyTableFormat } from '../table/applyTableFormat';\nimport { deleteSelection } from '../../publicApi/selection/deleteSelection';\nimport { getClosestAncestorBlockGroupIndex } from './getClosestAncestorBlockGroupIndex';\nimport { normalizeTable } from '../table/normalizeTable';\nimport {\n addSegment,\n createListItem,\n createParagraph,\n createSelectionMarker,\n createTableCell,\n getObjectKeys,\n normalizeContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n ContentModelTable,\n FormatWithContentModelContext,\n InsertPoint,\n} from 'roosterjs-content-model-types';\n\nconst HeadingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];\n\n/**\n * Options to specify how to merge models\n */\nexport interface MergeModelOption {\n /**\n * When there is only a table to merge, whether merge this table into current table (if any), or just directly insert (nested table).\n * This is usually used when paste table inside a table\n * @default false\n */\n mergeTable?: boolean;\n\n /**\n * Use this insert position to merge instead of querying selection from target model\n * @default undefined\n */\n insertPosition?: InsertPoint;\n\n /**\n * Use this to decide whether to change the source model format when doing the merge.\n * 'mergeAll': segment format of the insert position will be merged into the content that is merged into current model.\n * If the source model already has some format, it will not be overwritten.\n * 'keepSourceEmphasisFormat': format of the insert position will be set into the content that is merged into current model.\n * If the source model already has emphasis format, such as, fontWeight, Italic or underline different than the default style, it will not be overwritten.\n * 'none' the source segment format will not be modified.\n * @default undefined\n */\n mergeFormat?: 'mergeAll' | 'keepSourceEmphasisFormat' | 'none';\n}\n\n/**\n * Merge source model into target mode\n * @param target Target Content Model that will merge content into\n * @param source Source Content Model will be merged to target model\n * @param context Format context. When call this function inside formatContentModel, provide this context so that formatContentModel will do extra handling to the result\n * @param options More options, see MergeModelOption\n * @returns Insert point after merge, or null if there is no insert point\n */\nexport function mergeModel(\n target: ContentModelDocument,\n source: ContentModelDocument,\n context?: FormatWithContentModelContext,\n options?: MergeModelOption\n): InsertPoint | null {\n const insertPosition =\n options?.insertPosition ?? deleteSelection(target, [], context).insertPoint;\n\n if (insertPosition) {\n if (options?.mergeFormat && options.mergeFormat != 'none') {\n const newFormat: ContentModelSegmentFormat = {\n ...(target.format || {}),\n ...insertPosition.marker.format,\n };\n\n applyDefaultFormat(source, newFormat, options?.mergeFormat);\n }\n\n for (let i = 0; i < source.blocks.length; i++) {\n const block = source.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n mergeParagraph(insertPosition, block, i == 0, context, options);\n break;\n\n case 'Divider':\n insertBlock(insertPosition, block);\n break;\n\n case 'Entity':\n insertBlock(insertPosition, block);\n context?.newEntities.push(block);\n break;\n\n case 'Table':\n if (source.blocks.length == 1 && options?.mergeTable) {\n mergeTable(insertPosition, block, source);\n } else {\n insertBlock(insertPosition, block);\n }\n break;\n\n case 'BlockGroup':\n switch (block.blockGroupType) {\n case 'General':\n case 'FormatContainer':\n insertBlock(insertPosition, block);\n break;\n case 'ListItem':\n mergeList(insertPosition, block);\n break;\n }\n break;\n }\n }\n }\n\n normalizeContentModel(target);\n\n return insertPosition;\n}\n\nfunction mergeParagraph(\n markerPosition: InsertPoint,\n newPara: ContentModelParagraph,\n mergeToCurrentParagraph: boolean,\n context?: FormatWithContentModelContext,\n option?: MergeModelOption\n) {\n const { paragraph, marker } = markerPosition;\n const newParagraph = mergeToCurrentParagraph\n ? paragraph\n : splitParagraph(markerPosition, newPara.format);\n const segmentIndex = newParagraph.segments.indexOf(marker);\n\n if (option?.mergeFormat == 'none' && mergeToCurrentParagraph) {\n newParagraph.segments.forEach(segment => {\n segment.format = { ...(newParagraph.segmentFormat || {}), ...segment.format };\n });\n delete newParagraph.segmentFormat;\n }\n if (segmentIndex >= 0) {\n for (let i = 0; i < newPara.segments.length; i++) {\n const segment = newPara.segments[i];\n\n newParagraph.segments.splice(segmentIndex + i, 0, segment);\n\n if (context) {\n if (segment.segmentType == 'Entity') {\n context.newEntities.push(segment);\n }\n\n if (segment.segmentType == 'Image') {\n context.newImages.push(segment);\n }\n }\n }\n }\n\n if (newPara.decorator) {\n newParagraph.decorator = { ...newPara.decorator };\n if (HeadingTags.indexOf(newParagraph.decorator.tagName) > -1) {\n const sourceKeys: (keyof ContentModelSegmentFormat)[] = getObjectKeys(\n newParagraph.decorator.format\n );\n const segmentDecoratorKeys: (keyof ContentModelSegmentFormat)[] = getObjectKeys(\n newParagraph.segmentFormat || {}\n );\n\n sourceKeys.forEach(key => {\n if (segmentDecoratorKeys.indexOf(key) > -1) {\n delete newParagraph.segmentFormat?.[key];\n }\n });\n }\n }\n\n if (!mergeToCurrentParagraph) {\n newParagraph.format = newPara.format;\n }\n}\n\nfunction mergeTable(\n markerPosition: InsertPoint,\n newTable: ContentModelTable,\n source: ContentModelDocument\n) {\n const { tableContext, marker } = markerPosition;\n\n if (tableContext && source.blocks.length == 1 && source.blocks[0] == newTable) {\n const { table, colIndex, rowIndex } = tableContext;\n for (let i = 0; i < newTable.rows.length; i++) {\n for (let j = 0; j < newTable.rows[i].cells.length; j++) {\n const newCell = newTable.rows[i].cells[j];\n\n if (i == 0 && colIndex + j >= table.rows[0].cells.length) {\n for (let k = 0; k < table.rows.length; k++) {\n const leftCell = table.rows[k]?.cells[colIndex + j - 1];\n table.rows[k].cells[colIndex + j] = createTableCell(\n false /*spanLeft*/,\n false /*spanAbove*/,\n leftCell?.isHeader,\n leftCell?.format\n );\n }\n }\n\n if (j == 0 && rowIndex + i >= table.rows.length) {\n if (!table.rows[rowIndex + i]) {\n table.rows[rowIndex + i] = {\n cells: [],\n format: {},\n height: 0,\n };\n }\n\n for (let k = 0; k < table.rows[rowIndex].cells.length; k++) {\n const aboveCell = table.rows[rowIndex + i - 1]?.cells[k];\n table.rows[rowIndex + i].cells[k] = createTableCell(\n false /*spanLeft*/,\n false /*spanAbove*/,\n false /*isHeader*/,\n aboveCell?.format\n );\n }\n }\n\n const oldCell = table.rows[rowIndex + i].cells[colIndex + j];\n table.rows[rowIndex + i].cells[colIndex + j] = newCell;\n\n if (i == 0 && j == 0) {\n const newMarker = createSelectionMarker(marker.format);\n const newPara = addSegment(newCell, newMarker);\n\n if (markerPosition.path[0] == oldCell) {\n // Update insert point to match the change result\n markerPosition.path[0] = newCell;\n markerPosition.marker = newMarker;\n markerPosition.paragraph = newPara;\n }\n }\n }\n }\n\n normalizeTable(table, markerPosition.marker.format);\n applyTableFormat(table, undefined /*newFormat*/, true /*keepCellShade*/);\n } else {\n insertBlock(markerPosition, newTable);\n }\n}\n\nfunction mergeList(markerPosition: InsertPoint, newList: ContentModelListItem) {\n splitParagraph(markerPosition, newList.format);\n\n const { path, paragraph } = markerPosition;\n\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem']);\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listParent = path[listItemIndex + 1]; // It is ok here when index is -1, that means there is no list and we just insert a new paragraph and use path[0] as its parent\n const blockIndex = listParent.blocks.indexOf(listItem || paragraph);\n\n if (blockIndex >= 0) {\n listParent.blocks.splice(blockIndex, 0, newList);\n }\n\n if (listItem) {\n listItem?.levels.forEach((level, i) => {\n newList.levels[i] = { ...level };\n });\n }\n}\n\nfunction splitParagraph(markerPosition: InsertPoint, newParaFormat: ContentModelBlockFormat) {\n const { paragraph, marker, path } = markerPosition;\n const segmentIndex = paragraph.segments.indexOf(marker);\n const paraIndex = path[0].blocks.indexOf(paragraph);\n const newParagraph = createParagraph(\n false /*isImplicit*/,\n { ...paragraph.format, ...newParaFormat },\n paragraph.segmentFormat\n );\n\n if (segmentIndex >= 0) {\n newParagraph.segments = paragraph.segments.splice(segmentIndex);\n }\n\n if (paraIndex >= 0) {\n path[0].blocks.splice(paraIndex + 1, 0, newParagraph);\n }\n\n const listItemIndex = getClosestAncestorBlockGroupIndex(\n path,\n ['ListItem'],\n ['FormatContainer', 'TableCell']\n );\n const listItem = path[listItemIndex] as ContentModelListItem;\n\n if (listItem) {\n const listParent = listItemIndex >= 0 ? path[listItemIndex + 1] : null;\n const blockIndex = listParent ? listParent.blocks.indexOf(listItem) : -1;\n\n if (blockIndex >= 0 && listParent) {\n const newListItem = createListItem(listItem.levels, listItem.formatHolder.format);\n\n if (paraIndex >= 0) {\n newListItem.blocks = listItem.blocks.splice(paraIndex + 1);\n }\n\n if (blockIndex >= 0) {\n listParent.blocks.splice(blockIndex + 1, 0, newListItem);\n }\n\n path[listItemIndex] = newListItem;\n }\n }\n\n markerPosition.paragraph = newParagraph;\n\n return newParagraph;\n}\n\nfunction insertBlock(markerPosition: InsertPoint, block: ContentModelBlock) {\n const { path } = markerPosition;\n const newParaFormat = block.blockType !== 'Paragraph' ? {} : block.format;\n const newPara = splitParagraph(markerPosition, newParaFormat);\n const blockIndex = path[0].blocks.indexOf(newPara);\n\n if (blockIndex >= 0) {\n path[0].blocks.splice(blockIndex, 0, block);\n }\n}\n\nfunction applyDefaultFormat(\n group: ContentModelBlockGroup,\n format: ContentModelSegmentFormat,\n applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat'\n) {\n group.blocks.forEach(block => {\n switch (block.blockType) {\n case 'BlockGroup':\n if (block.blockGroupType == 'ListItem') {\n block.formatHolder.format = mergeSegmentFormat(\n applyDefaultFormatOption,\n format,\n block.formatHolder.format\n );\n }\n applyDefaultFormat(block, format, applyDefaultFormatOption);\n break;\n\n case 'Table':\n block.rows.forEach(row =>\n row.cells.forEach(cell => {\n applyDefaultFormat(cell, format, applyDefaultFormatOption);\n })\n );\n break;\n\n case 'Paragraph':\n const paragraphFormat = block.decorator?.format || {};\n block.segments.forEach(segment => {\n if (segment.segmentType == 'General') {\n applyDefaultFormat(segment, format, applyDefaultFormatOption);\n }\n\n segment.format = mergeSegmentFormat(applyDefaultFormatOption, format, {\n ...paragraphFormat,\n ...segment.format,\n });\n });\n\n if (applyDefaultFormatOption === 'keepSourceEmphasisFormat') {\n delete block.decorator;\n }\n break;\n }\n });\n}\n\nfunction mergeSegmentFormat(\n applyDefaultFormatOption: 'mergeAll' | 'keepSourceEmphasisFormat',\n targetformat: ContentModelSegmentFormat,\n sourceFormat: ContentModelSegmentFormat\n): ContentModelSegmentFormat {\n return applyDefaultFormatOption == 'mergeAll'\n ? { ...targetformat, ...sourceFormat }\n : {\n ...targetformat,\n ...getSemanticFormat(sourceFormat),\n };\n}\n\nfunction getSemanticFormat(segmentFormat: ContentModelSegmentFormat): ContentModelSegmentFormat {\n const result: ContentModelSegmentFormat = {};\n\n const { fontWeight, italic, underline } = segmentFormat;\n\n if (fontWeight && fontWeight != 'normal') {\n result.fontWeight = fontWeight;\n }\n if (italic) {\n result.italic = italic;\n }\n if (underline) {\n result.underline = underline;\n }\n\n return result;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { ContentModelDocument, FormatWithContentModelContext, InsertPoint, PasteType, IStandaloneEditor } from 'roosterjs-content-model-types';
2
+ import type { ClipboardData, IEditor } from 'roosterjs-editor-types';
3
+ /**
4
+ * Paste into editor using a clipboardData object
5
+ * @param editor The editor to paste content into
6
+ * @param clipboardData Clipboard data retrieved from clipboard
7
+ * @param pasteType Type of content to paste. @default normal
8
+ */
9
+ export declare function paste(editor: IStandaloneEditor & IEditor, clipboardData: ClipboardData, pasteType?: PasteType): void;
10
+ /**
11
+ * @internal
12
+ * Export only for unit test
13
+ */
14
+ export declare function mergePasteContent(model: ContentModelDocument, context: FormatWithContentModelContext, pasteModel: ContentModelDocument, applyCurrentFormat: boolean, customizedMerge: undefined | ((source: ContentModelDocument, target: ContentModelDocument) => InsertPoint | null)): InsertPoint | null;
@@ -0,0 +1,145 @@
1
+ import { __assign } from "tslib";
2
+ import { ChangeSource } from '../../constants/ChangeSource';
3
+ import { getSelectedSegments } from '../selection/collectSelections';
4
+ import { mergeModel } from './mergeModel';
5
+ import { applySegmentFormatToElement, createDomToModelContext, domToContentModel, moveChildNodes, } from 'roosterjs-content-model-dom';
6
+ import { createDefaultHtmlSanitizerOptions, handleImagePaste, handleTextPaste, retrieveMetadataFromClipboard, sanitizePasteContent, } from 'roosterjs-editor-dom';
7
+ // Map new PasteType to old PasteType
8
+ // TODO: We can remove this once we have standalone editor
9
+ var PasteTypeMap = {
10
+ asImage: 3 /* AsImage */,
11
+ asPlainText: 1 /* AsPlainText */,
12
+ mergeFormat: 2 /* MergeFormat */,
13
+ normal: 0 /* Normal */,
14
+ };
15
+ var EmptySegmentFormat = {
16
+ backgroundColor: '',
17
+ fontFamily: '',
18
+ fontSize: '',
19
+ fontWeight: '',
20
+ italic: false,
21
+ letterSpacing: '',
22
+ lineHeight: '',
23
+ strikethrough: false,
24
+ superOrSubScriptSequence: '',
25
+ textColor: '',
26
+ underline: false,
27
+ };
28
+ /**
29
+ * Paste into editor using a clipboardData object
30
+ * @param editor The editor to paste content into
31
+ * @param clipboardData Clipboard data retrieved from clipboard
32
+ * @param pasteType Type of content to paste. @default normal
33
+ */
34
+ export function paste(editor, clipboardData, pasteType) {
35
+ if (pasteType === void 0) { pasteType = 'normal'; }
36
+ if (clipboardData.snapshotBeforePaste) {
37
+ // Restore original content before paste a new one
38
+ editor.setContent(clipboardData.snapshotBeforePaste);
39
+ }
40
+ else {
41
+ clipboardData.snapshotBeforePaste = editor.getContent(2 /* RawHTMLWithSelection */);
42
+ }
43
+ editor.focus();
44
+ var originalFormat;
45
+ editor.formatContentModel(function (model, context) {
46
+ var _a;
47
+ var eventData = createBeforePasteEventData(editor, clipboardData, pasteType);
48
+ var currentSegment = getSelectedSegments(model, true /*includingFormatHolder*/)[0];
49
+ var _b = (_a = currentSegment === null || currentSegment === void 0 ? void 0 : currentSegment.format) !== null && _a !== void 0 ? _a : {}, fontFamily = _b.fontFamily, fontSize = _b.fontSize, textColor = _b.textColor, backgroundColor = _b.backgroundColor, letterSpacing = _b.letterSpacing, lineHeight = _b.lineHeight;
50
+ var _c = triggerPluginEventAndCreatePasteFragment(editor, clipboardData, pasteType, eventData, { fontFamily: fontFamily, fontSize: fontSize, textColor: textColor, backgroundColor: backgroundColor, letterSpacing: letterSpacing, lineHeight: lineHeight }), domToModelOption = _c.domToModelOption, fragment = _c.fragment, customizedMerge = _c.customizedMerge;
51
+ var pasteModel = domToContentModel(fragment, createDomToModelContext(undefined /*editorContext*/, domToModelOption));
52
+ var insertPoint = mergePasteContent(model, context, pasteModel, pasteType == 'mergeFormat', customizedMerge);
53
+ if (insertPoint) {
54
+ originalFormat = insertPoint.marker.format;
55
+ }
56
+ if (originalFormat) {
57
+ context.newPendingFormat = __assign(__assign({}, EmptySegmentFormat), originalFormat); // Use empty format as initial value to clear any other format inherits from pasted content
58
+ }
59
+ return true;
60
+ }, {
61
+ changeSource: ChangeSource.Paste,
62
+ getChangeData: function () { return clipboardData; },
63
+ apiName: 'paste',
64
+ });
65
+ }
66
+ /**
67
+ * @internal
68
+ * Export only for unit test
69
+ */
70
+ export function mergePasteContent(model, context, pasteModel, applyCurrentFormat, customizedMerge) {
71
+ return customizedMerge
72
+ ? customizedMerge(model, pasteModel)
73
+ : mergeModel(model, pasteModel, context, {
74
+ mergeFormat: applyCurrentFormat ? 'keepSourceEmphasisFormat' : 'none',
75
+ mergeTable: shouldMergeTable(pasteModel),
76
+ });
77
+ }
78
+ function shouldMergeTable(pasteModel) {
79
+ // If model contains a table and a paragraph element after the table with a single BR segment, remove the Paragraph after the table
80
+ if (pasteModel.blocks.length == 2 &&
81
+ pasteModel.blocks[0].blockType === 'Table' &&
82
+ pasteModel.blocks[1].blockType === 'Paragraph' &&
83
+ pasteModel.blocks[1].segments.length === 1 &&
84
+ pasteModel.blocks[1].segments[0].segmentType === 'Br') {
85
+ pasteModel.blocks.splice(1);
86
+ }
87
+ // Only merge table when the document contain a single table.
88
+ return pasteModel.blocks.length === 1 && pasteModel.blocks[0].blockType === 'Table';
89
+ }
90
+ function createBeforePasteEventData(editor, clipboardData, pasteType) {
91
+ var options = createDefaultHtmlSanitizerOptions();
92
+ // Remove "caret-color" style generated by Safari to make sure caret shows in right color after paste
93
+ options.cssStyleCallbacks['caret-color'] = function () { return false; };
94
+ return {
95
+ clipboardData: clipboardData,
96
+ fragment: editor.getDocument().createDocumentFragment(),
97
+ sanitizingOption: options,
98
+ htmlBefore: '',
99
+ htmlAfter: '',
100
+ htmlAttributes: {},
101
+ domToModelOption: {},
102
+ pasteType: PasteTypeMap[pasteType],
103
+ };
104
+ }
105
+ /**
106
+ * This function is used to create a BeforePasteEvent object after trigger the event, so other plugins can modify the event object
107
+ * This function will also create a DocumentFragment for paste.
108
+ */
109
+ function triggerPluginEventAndCreatePasteFragment(editor, clipboardData, pasteType, eventData, currentFormat) {
110
+ var event = __assign({ eventType: 10 /* BeforePaste */ }, eventData);
111
+ var fragment = event.fragment;
112
+ var rawHtml = clipboardData.rawHtml, text = clipboardData.text, imageDataUri = clipboardData.imageDataUri;
113
+ var trustedHTMLHandler = editor.getTrustedHTMLHandler();
114
+ var doc = rawHtml
115
+ ? new DOMParser().parseFromString(trustedHTMLHandler(rawHtml), 'text/html')
116
+ : undefined;
117
+ // Step 2: Retrieve Metadata from Html and the Html that was copied.
118
+ retrieveMetadataFromClipboard(doc, event, trustedHTMLHandler);
119
+ // Step 3: Fill the BeforePasteEvent object, especially the fragment for paste
120
+ if ((pasteType == 'asImage' && imageDataUri) ||
121
+ (pasteType != 'asPlainText' && !text && imageDataUri)) {
122
+ // Paste image
123
+ handleImagePaste(imageDataUri, fragment);
124
+ }
125
+ else if (pasteType != 'asPlainText' && rawHtml && doc ? doc.body : false) {
126
+ moveChildNodes(fragment, doc === null || doc === void 0 ? void 0 : doc.body);
127
+ }
128
+ else if (text) {
129
+ // Paste text
130
+ handleTextPaste(text, null /*position*/, fragment);
131
+ }
132
+ var formatContainer = fragment.ownerDocument.createElement('span');
133
+ moveChildNodes(formatContainer, fragment);
134
+ fragment.appendChild(formatContainer);
135
+ applySegmentFormatToElement(formatContainer, currentFormat);
136
+ var pluginEvent = event;
137
+ // Step 4: Trigger BeforePasteEvent so that plugins can do proper change before paste, when the type of paste is different than Plain Text
138
+ if (pasteType !== 'asPlainText') {
139
+ pluginEvent = editor.triggerPluginEvent(10 /* BeforePaste */, event, true /* broadcast */);
140
+ }
141
+ // Step 5. Sanitize the fragment before paste to make sure the content is safe
142
+ sanitizePasteContent(event, null /*position*/);
143
+ return pluginEvent;
144
+ }
145
+ //# sourceMappingURL=paste.js.map