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":"formatContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/formatContentModel.ts"],"names":[],"mapp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C,CAAC,CAAC,CAAC;SACN;KACJ;AACL,CAAC;AAED,SAAS,mBAAmB,CACxB,IAA0B,EAC1B,OAAsC,EACtC,SAA+B;;IAE/B,IAAM,aAAa,GACf,OAAO,CAAC,gBAAgB,IAAI,UAAU;QAClC,CAAC,CAAC,MAAA,IAAI,CAAC,MAAM,CAAC,aAAa,0CAAE,MAAM;QACnC,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC;IAEnC,IAAI,aAAa,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE;QAC1E,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG;YACxB,MAAM,4BAAO,aAAa,CAAE;YAC5B,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc;YAC5C,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW;SACzC,CAAC;KACL;AACL,CAAC","sourcesContent":["import { ChangeSource } from '../constants/ChangeSource';\nimport { ColorTransformDirection, EntityOperation, PluginEventType } from 'roosterjs-editor-types';\nimport type { EditorCore, Entity } from 'roosterjs-editor-types';\nimport type {\n ContentModelContentChangedEvent,\n DOMSelection,\n EntityRemovalOperation,\n FormatContentModel,\n FormatWithContentModelContext,\n StandaloneEditorCore,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * The general API to do format change with Content Model\n * It will grab a Content Model for current editor content, and invoke a callback function\n * to do format change. Then according to the return value, write back the modified content model into editor.\n * If there is cached model, it will be used and updated.\n * @param core The StandaloneEditorCore object\n * @param formatter Formatter function, see ContentModelFormatter\n * @param options More options, see FormatWithContentModelOptions\n */\nexport const formatContentModel: FormatContentModel = (core, formatter, options) => {\n const { apiName, onNodeCreated, getChangeData, changeSource, rawEvent, selectionOverride } =\n options || {};\n\n const model = core.api.createContentModel(core, undefined /*option*/, selectionOverride);\n const context: FormatWithContentModelContext = {\n newEntities: [],\n deletedEntities: [],\n rawEvent,\n newImages: [],\n };\n let selection: DOMSelection | undefined;\n\n if (formatter(model, context)) {\n const writeBack = () => {\n handleNewEntities(core, context);\n handleDeletedEntities(core, context);\n handleImages(core, context);\n\n selection =\n core.api.setContentModel(core, model, undefined /*options*/, onNodeCreated) ||\n undefined;\n\n handlePendingFormat(core, context, selection);\n };\n\n if (context.skipUndoSnapshot) {\n writeBack();\n } else {\n core.api.addUndoSnapshot(\n core,\n writeBack,\n null /*changeSource, passing undefined here to avoid triggering ContentChangedEvent. We will trigger it using it with Content Model below */,\n false /*canUndoByBackspace*/,\n {\n formatApiName: apiName,\n }\n );\n }\n\n const eventData: ContentModelContentChangedEvent = {\n eventType: PluginEventType.ContentChanged,\n contentModel: context.clearModelCache ? undefined : model,\n selection: context.clearModelCache ? undefined : selection,\n source: changeSource || ChangeSource.Format,\n data: getChangeData?.(),\n additionalData: {\n formatApiName: apiName,\n },\n };\n core.api.triggerEvent(core, eventData, true /*broadcast*/);\n } else {\n if (context.clearModelCache) {\n core.cache.cachedModel = undefined;\n core.cache.cachedSelection = undefined;\n }\n\n handlePendingFormat(core, context, core.api.getDOMSelection(core));\n }\n};\n\nfunction handleNewEntities(core: EditorCore, context: FormatWithContentModelContext) {\n // TODO: Ideally we can trigger NewEntity event here. But to be compatible with original editor code, we don't do it here for now.\n // Once Content Model Editor can be standalone, we can change this behavior to move triggering NewEntity event code\n // from EntityPlugin to here\n\n if (core.lifecycle.isDarkMode) {\n context.newEntities.forEach(entity => {\n core.api.transformColor(\n core,\n entity.wrapper,\n true /*includeSelf*/,\n null /*callback*/,\n ColorTransformDirection.LightToDark\n );\n });\n }\n}\n\n// This is only used for compatibility with old editor\n// TODO: Remove this map once we have standalone editor\nconst EntityOperationMap: Record<EntityRemovalOperation, EntityOperation> = {\n overwrite: EntityOperation.Overwrite,\n removeFromEnd: EntityOperation.RemoveFromEnd,\n removeFromStart: EntityOperation.RemoveFromStart,\n};\n\nfunction handleDeletedEntities(core: EditorCore, context: FormatWithContentModelContext) {\n context.deletedEntities.forEach(\n ({\n entity: {\n wrapper,\n entityFormat: { id, entityType, isReadonly },\n },\n operation,\n }) => {\n if (id && entityType) {\n // TODO: Revisit this entity parameter for standalone editor, we may just directly pass ContentModelEntity object instead\n const entity: Entity = {\n id,\n type: entityType,\n isReadonly: !!isReadonly,\n wrapper,\n };\n core.api.triggerEvent(\n core,\n {\n eventType: PluginEventType.EntityOperation,\n entity,\n operation: EntityOperationMap[operation],\n rawEvent: context.rawEvent,\n },\n false /*broadcast*/\n );\n }\n }\n );\n}\n\nfunction handleImages(core: EditorCore, context: FormatWithContentModelContext) {\n if (context.newImages.length > 0) {\n const viewport = core.getVisibleViewport();\n\n if (viewport) {\n const { left, right } = viewport;\n const minMaxImageSize = 10;\n const maxWidth = Math.max(right - left, minMaxImageSize);\n context.newImages.forEach(image => {\n image.format.maxWidth = `${maxWidth}px`;\n });\n }\n }\n}\n\nfunction handlePendingFormat(\n core: StandaloneEditorCore,\n context: FormatWithContentModelContext,\n selection?: DOMSelection | null\n) {\n const pendingFormat =\n context.newPendingFormat == 'preserve'\n ? core.format.pendingFormat?.format\n : context.newPendingFormat;\n\n if (pendingFormat && selection?.type == 'range' && selection.range.collapsed) {\n core.format.pendingFormat = {\n format: { ...pendingFormat },\n posContainer: selection.range.startContainer,\n posOffset: selection.range.startOffset,\n };\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { GetDOMSelection } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const getDOMSelection: GetDOMSelection;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDOMSelection = void 0;
4
+ /**
5
+ * @internal
6
+ */
7
+ var getDOMSelection = function (core) {
8
+ var _a;
9
+ return (_a = core.cache.cachedSelection) !== null && _a !== void 0 ? _a : getNewSelection(core);
10
+ };
11
+ exports.getDOMSelection = getDOMSelection;
12
+ function getNewSelection(core) {
13
+ // TODO: Get rid of getSelectionRangeEx when we have standalone editor
14
+ var rangeEx = core.api.getSelectionRangeEx(core);
15
+ if (rangeEx.type == 0 /* Normal */ && rangeEx.ranges[0]) {
16
+ return {
17
+ type: 'range',
18
+ range: rangeEx.ranges[0],
19
+ };
20
+ }
21
+ else if (rangeEx.type == 1 /* TableSelection */ && rangeEx.coordinates) {
22
+ return {
23
+ type: 'table',
24
+ table: rangeEx.table,
25
+ firstColumn: rangeEx.coordinates.firstCell.x,
26
+ lastColumn: rangeEx.coordinates.lastCell.x,
27
+ firstRow: rangeEx.coordinates.firstCell.y,
28
+ lastRow: rangeEx.coordinates.lastCell.y,
29
+ };
30
+ }
31
+ else if (rangeEx.type == 2 /* ImageSelection */) {
32
+ return {
33
+ type: 'image',
34
+ image: rangeEx.image,
35
+ };
36
+ }
37
+ else {
38
+ return null;
39
+ }
40
+ }
41
+ //# sourceMappingURL=getDOMSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDOMSelection.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/getDOMSelection.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACI,IAAM,eAAe,GAAoB,UAAA,IAAI;;IAChD,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,eAAe,mCAAI,eAAe,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEF,SAAS,eAAe,CAAC,IAAgB;IACrC,sEAAsE;IACtE,IAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAEnD,IAAI,OAAO,CAAC,IAAI,kBAA8B,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QACjE,OAAO;YACH,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;SAC3B,CAAC;KACL;SAAM,IAAI,OAAO,CAAC,IAAI,0BAAsC,IAAI,OAAO,CAAC,WAAW,EAAE;QAClF,OAAO;YACH,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YAC5C,UAAU,EAAE,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAC1C,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;YACzC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;SAC1C,CAAC;KACL;SAAM,IAAI,OAAO,CAAC,IAAI,0BAAsC,EAAE;QAC3D,OAAO;YACH,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,OAAO,CAAC,KAAK;SACvB,CAAC;KACL;SAAM;QACH,OAAO,IAAI,CAAC;KACf;AACL,CAAC","sourcesContent":["import { SelectionRangeTypes } from 'roosterjs-editor-types';\nimport type { EditorCore } from 'roosterjs-editor-types';\nimport type { DOMSelection, GetDOMSelection } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const getDOMSelection: GetDOMSelection = core => {\n return core.cache.cachedSelection ?? getNewSelection(core);\n};\n\nfunction getNewSelection(core: EditorCore): DOMSelection | null {\n // TODO: Get rid of getSelectionRangeEx when we have standalone editor\n const rangeEx = core.api.getSelectionRangeEx(core);\n\n if (rangeEx.type == SelectionRangeTypes.Normal && rangeEx.ranges[0]) {\n return {\n type: 'range',\n range: rangeEx.ranges[0],\n };\n } else if (rangeEx.type == SelectionRangeTypes.TableSelection && rangeEx.coordinates) {\n return {\n type: 'table',\n table: rangeEx.table,\n firstColumn: rangeEx.coordinates.firstCell.x,\n lastColumn: rangeEx.coordinates.lastCell.x,\n firstRow: rangeEx.coordinates.firstCell.y,\n lastRow: rangeEx.coordinates.lastCell.y,\n };\n } else if (rangeEx.type == SelectionRangeTypes.ImageSelection) {\n return {\n type: 'image',\n image: rangeEx.image,\n };\n } else {\n return null;\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { SetContentModel } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ * Set content with content model
5
+ * @param core The editor core object
6
+ * @param model The content model to set
7
+ * @param option Additional options to customize the behavior of Content Model to DOM conversion
8
+ */
9
+ export declare const setContentModel: SetContentModel;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setContentModel = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
+ /**
7
+ * @internal
8
+ * Set content with content model
9
+ * @param core The editor core object
10
+ * @param model The content model to set
11
+ * @param option Additional options to customize the behavior of Content Model to DOM conversion
12
+ */
13
+ var setContentModel = function (core, model, option, onNodeCreated) {
14
+ var editorContext = core.api.createEditorContext(core);
15
+ var modelToDomContext = option
16
+ ? roosterjs_content_model_dom_1.createModelToDomContext.apply(void 0, (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([editorContext], (0, tslib_1.__read)((core.defaultModelToDomOptions || [])), false), [option], false)) : (0, roosterjs_content_model_dom_1.createModelToDomContextWithConfig)(core.defaultModelToDomConfig, editorContext);
17
+ var selection = (0, roosterjs_content_model_dom_1.contentModelToDom)(core.contentDiv.ownerDocument, core.contentDiv, model, modelToDomContext, onNodeCreated);
18
+ if (!core.lifecycle.shadowEditFragment) {
19
+ core.cache.cachedSelection = selection || undefined;
20
+ if (selection) {
21
+ if (!(option === null || option === void 0 ? void 0 : option.ignoreSelection)) {
22
+ core.api.setDOMSelection(core, selection);
23
+ }
24
+ else if (selection.type == 'range') {
25
+ core.domEvent.selectionRange = selection.range;
26
+ }
27
+ }
28
+ core.cache.cachedModel = model;
29
+ }
30
+ return selection;
31
+ };
32
+ exports.setContentModel = setContentModel;
33
+ //# sourceMappingURL=setContentModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setContentModel.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/setContentModel.ts"],"names":[],"mappings":";;;;AAAA,2EAIqC;AAGrC;;;;;;GAMG;AACI,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa;IAC/E,IAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACzD,IAAM,iBAAiB,GAAG,MAAM;QAC5B,CAAC,CAAC,qDAAuB,sEAAC,aAAa,uBAAK,CAAC,IAAI,CAAC,wBAAwB,IAAI,EAAE,CAAC,YAAE,MAAM,WACzF,CAAC,CAAC,IAAA,+DAAiC,EAAC,IAAI,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;IAErF,IAAM,SAAS,GAAG,IAAA,+CAAiB,EAC/B,IAAI,CAAC,UAAU,CAAC,aAAa,EAC7B,IAAI,CAAC,UAAU,EACf,KAAK,EACL,iBAAiB,EACjB,aAAa,CAChB,CAAC;IAEF,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE;QACpC,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,SAAS,IAAI,SAAS,CAAC;QAEpD,IAAI,SAAS,EAAE;YACX,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,eAAe,CAAA,EAAE;gBAC1B,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAC7C;iBAAM,IAAI,SAAS,CAAC,IAAI,IAAI,OAAO,EAAE;gBAClC,IAAI,CAAC,QAAQ,CAAC,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC;aAClD;SACJ;QAED,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;KAClC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AA7BW,QAAA,eAAe,mBA6B1B","sourcesContent":["import {\n contentModelToDom,\n createModelToDomContext,\n createModelToDomContextWithConfig,\n} from 'roosterjs-content-model-dom';\nimport type { SetContentModel } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Set content with content model\n * @param core The editor core object\n * @param model The content model to set\n * @param option Additional options to customize the behavior of Content Model to DOM conversion\n */\nexport const setContentModel: SetContentModel = (core, model, option, onNodeCreated) => {\n const editorContext = core.api.createEditorContext(core);\n const modelToDomContext = option\n ? createModelToDomContext(editorContext, ...(core.defaultModelToDomOptions || []), option)\n : createModelToDomContextWithConfig(core.defaultModelToDomConfig, editorContext);\n\n const selection = contentModelToDom(\n core.contentDiv.ownerDocument,\n core.contentDiv,\n model,\n modelToDomContext,\n onNodeCreated\n );\n\n if (!core.lifecycle.shadowEditFragment) {\n core.cache.cachedSelection = selection || undefined;\n\n if (selection) {\n if (!option?.ignoreSelection) {\n core.api.setDOMSelection(core, selection);\n } else if (selection.type == 'range') {\n core.domEvent.selectionRange = selection.range;\n }\n }\n\n core.cache.cachedModel = model;\n }\n\n return selection;\n};\n"]}
@@ -0,0 +1,5 @@
1
+ import type { SetDOMSelection } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const setDOMSelection: SetDOMSelection;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDOMSelection = void 0;
4
+ /**
5
+ * @internal
6
+ */
7
+ var setDOMSelection = function (core, selection) {
8
+ // TODO: Get rid of SelectionRangeEx in standalone editor
9
+ var rangeEx = selection.type == 'range'
10
+ ? {
11
+ type: 0 /* Normal */,
12
+ ranges: [selection.range],
13
+ areAllCollapsed: selection.range.collapsed,
14
+ }
15
+ : selection.type == 'image'
16
+ ? {
17
+ type: 2 /* ImageSelection */,
18
+ ranges: [],
19
+ areAllCollapsed: false,
20
+ image: selection.image,
21
+ }
22
+ : {
23
+ type: 1 /* TableSelection */,
24
+ ranges: [],
25
+ areAllCollapsed: false,
26
+ table: selection.table,
27
+ coordinates: {
28
+ firstCell: {
29
+ x: selection.firstColumn,
30
+ y: selection.firstRow,
31
+ },
32
+ lastCell: {
33
+ x: selection.lastColumn,
34
+ y: selection.lastRow,
35
+ },
36
+ },
37
+ };
38
+ core.api.select(core, rangeEx);
39
+ };
40
+ exports.setDOMSelection = setDOMSelection;
41
+ //# sourceMappingURL=setDOMSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setDOMSelection.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/setDOMSelection.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACI,IAAM,eAAe,GAAoB,UAAC,IAAI,EAAE,SAAS;IAC5D,yDAAyD;IACzD,IAAM,OAAO,GACT,SAAS,CAAC,IAAI,IAAI,OAAO;QACrB,CAAC,CAAC;YACI,IAAI,gBAA4B;YAChC,MAAM,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;YACzB,eAAe,EAAE,SAAS,CAAC,KAAK,CAAC,SAAS;SAC7C;QACH,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,OAAO;YAC3B,CAAC,CAAC;gBACI,IAAI,wBAAoC;gBACxC,MAAM,EAAE,EAAE;gBACV,eAAe,EAAE,KAAK;gBACtB,KAAK,EAAE,SAAS,CAAC,KAAK;aACzB;YACH,CAAC,CAAC;gBACI,IAAI,wBAAoC;gBACxC,MAAM,EAAE,EAAE;gBACV,eAAe,EAAE,KAAK;gBACtB,KAAK,EAAE,SAAS,CAAC,KAAK;gBACtB,WAAW,EAAE;oBACT,SAAS,EAAE;wBACP,CAAC,EAAE,SAAS,CAAC,WAAW;wBACxB,CAAC,EAAE,SAAS,CAAC,QAAQ;qBACxB;oBACD,QAAQ,EAAE;wBACN,CAAC,EAAE,SAAS,CAAC,UAAU;wBACvB,CAAC,EAAE,SAAS,CAAC,OAAO;qBACvB;iBACJ;aACJ,CAAC;IAEZ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC,CAAC;AAlCW,QAAA,eAAe,mBAkC1B","sourcesContent":["import { SelectionRangeTypes } from 'roosterjs-editor-types';\nimport type { SelectionRangeEx } from 'roosterjs-editor-types';\nimport type { SetDOMSelection } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const setDOMSelection: SetDOMSelection = (core, selection) => {\n // TODO: Get rid of SelectionRangeEx in standalone editor\n const rangeEx: SelectionRangeEx =\n selection.type == 'range'\n ? {\n type: SelectionRangeTypes.Normal,\n ranges: [selection.range],\n areAllCollapsed: selection.range.collapsed,\n }\n : selection.type == 'image'\n ? {\n type: SelectionRangeTypes.ImageSelection,\n ranges: [],\n areAllCollapsed: false,\n image: selection.image,\n }\n : {\n type: SelectionRangeTypes.TableSelection,\n ranges: [],\n areAllCollapsed: false,\n table: selection.table,\n coordinates: {\n firstCell: {\n x: selection.firstColumn,\n y: selection.firstRow,\n },\n lastCell: {\n x: selection.lastColumn,\n y: selection.lastRow,\n },\n },\n };\n\n core.api.select(core, rangeEx);\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import type { SwitchShadowEdit } from 'roosterjs-editor-types';
2
+ /**
3
+ * @internal
4
+ * Switch the Shadow Edit mode of editor On/Off
5
+ * @param editorCore The EditorCore object
6
+ * @param isOn True to switch On, False to switch Off
7
+ */
8
+ export declare const switchShadowEdit: SwitchShadowEdit;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.switchShadowEdit = void 0;
4
+ var iterateSelections_1 = require("../publicApi/selection/iterateSelections");
5
+ /**
6
+ * @internal
7
+ * Switch the Shadow Edit mode of editor On/Off
8
+ * @param editorCore The EditorCore object
9
+ * @param isOn True to switch On, False to switch Off
10
+ */
11
+ var switchShadowEdit = function (editorCore, isOn) {
12
+ // TODO: Use strong-typed editor core object
13
+ var core = editorCore;
14
+ if (isOn != !!core.lifecycle.shadowEditFragment) {
15
+ if (isOn) {
16
+ var model = !core.cache.cachedModel ? core.api.createContentModel(core) : null;
17
+ // Fake object, not used in Content Model Editor, just to satisfy original editor code
18
+ // TODO: we can remove them once we have standalone Content Model Editor
19
+ var fragment = core.contentDiv.ownerDocument.createDocumentFragment();
20
+ var selectionPath = {
21
+ start: [],
22
+ end: [],
23
+ };
24
+ core.api.triggerEvent(core, {
25
+ eventType: 17 /* EnteredShadowEdit */,
26
+ fragment: fragment,
27
+ selectionPath: selectionPath,
28
+ }, false /*broadcast*/);
29
+ // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event
30
+ // if current selection is table selection or image selection
31
+ if (!core.cache.cachedModel && model) {
32
+ core.cache.cachedModel = model;
33
+ }
34
+ core.lifecycle.shadowEditSelectionPath = selectionPath;
35
+ core.lifecycle.shadowEditFragment = fragment;
36
+ }
37
+ else {
38
+ core.lifecycle.shadowEditFragment = null;
39
+ core.lifecycle.shadowEditSelectionPath = null;
40
+ core.api.triggerEvent(core, {
41
+ eventType: 18 /* LeavingShadowEdit */,
42
+ }, false /*broadcast*/);
43
+ if (core.cache.cachedModel) {
44
+ // Force clear cached element from selected block
45
+ (0, iterateSelections_1.iterateSelections)(core.cache.cachedModel, function () { });
46
+ core.api.setContentModel(core, core.cache.cachedModel, {
47
+ ignoreSelection: true, // Do not set focus and selection when quit shadow edit, focus may remain in UI control (picker, ...)
48
+ });
49
+ }
50
+ }
51
+ }
52
+ };
53
+ exports.switchShadowEdit = switchShadowEdit;
54
+ //# sourceMappingURL=switchShadowEdit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchShadowEdit.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/coreApi/switchShadowEdit.ts"],"names":[],"mappings":";;;AAAA,8EAA6E;AAK7E;;;;;GAKG;AACI,IAAM,gBAAgB,GAAqB,UAAC,UAAU,EAAE,IAAI;IAC/D,4CAA4C;IAC5C,IAAM,IAAI,GAAG,UAA+C,CAAC;IAE7D,IAAI,IAAI,IAAI,CAAC,CAAC,IAA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C;gBAEpD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE;oBACnD,eAAe,EAAE,IAAI,EAAE,qGAAqG;iBAC/H,CAAC,CAAC;aACN;SACJ;KACJ;AACL,CAAC,CAAC;AAxDW,QAAA,gBAAgB,oBAwD3B","sourcesContent":["import { iterateSelections } from '../publicApi/selection/iterateSelections';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type { StandaloneEditorCore } from 'roosterjs-content-model-types';\nimport type { EditorCore, SelectionPath, SwitchShadowEdit } from 'roosterjs-editor-types';\n\n/**\n * @internal\n * Switch the Shadow Edit mode of editor On/Off\n * @param editorCore The EditorCore object\n * @param isOn True to switch On, False to switch Off\n */\nexport const switchShadowEdit: SwitchShadowEdit = (editorCore, isOn): void => {\n // TODO: Use strong-typed editor core object\n const core = editorCore as StandaloneEditorCore & EditorCore;\n\n if (isOn != !!core.lifecycle.shadowEditFragment) {\n if (isOn) {\n const model = !core.cache.cachedModel ? core.api.createContentModel(core) : null;\n\n // Fake object, not used in Content Model Editor, just to satisfy original editor code\n // TODO: we can remove them once we have standalone Content Model Editor\n const fragment = core.contentDiv.ownerDocument.createDocumentFragment();\n const selectionPath: SelectionPath = {\n start: [],\n end: [],\n };\n\n core.api.triggerEvent(\n core,\n {\n eventType: PluginEventType.EnteredShadowEdit,\n fragment,\n selectionPath,\n },\n false /*broadcast*/\n );\n\n // This need to be done after EnteredShadowEdit event is triggered since EnteredShadowEdit event will cause a SelectionChanged event\n // if current selection is table selection or image selection\n if (!core.cache.cachedModel && model) {\n core.cache.cachedModel = model;\n }\n\n core.lifecycle.shadowEditSelectionPath = selectionPath;\n core.lifecycle.shadowEditFragment = fragment;\n } else {\n core.lifecycle.shadowEditFragment = null;\n core.lifecycle.shadowEditSelectionPath = null;\n\n core.api.triggerEvent(\n core,\n {\n eventType: PluginEventType.LeavingShadowEdit,\n },\n false /*broadcast*/\n );\n\n if (core.cache.cachedModel) {\n // Force clear cached element from selected block\n iterateSelections(core.cache.cachedModel, () => {});\n\n core.api.setContentModel(core, core.cache.cachedModel, {\n ignoreSelection: true, // Do not set focus and selection when quit shadow edit, focus may remain in UI control (picker, ...)\n });\n }\n }\n }\n};\n"]}
@@ -0,0 +1,53 @@
1
+ import type { ContentModelCachePluginState } from 'roosterjs-content-model-types';
2
+ import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
3
+ /**
4
+ * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
5
+ */
6
+ export declare class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {
7
+ private state;
8
+ private editor;
9
+ /**
10
+ * Construct a new instance of ContentModelEditPlugin class
11
+ * @param state State of this plugin
12
+ */
13
+ constructor(state: ContentModelCachePluginState);
14
+ /**
15
+ * Get name of this plugin
16
+ */
17
+ getName(): string;
18
+ /**
19
+ * The first method that editor will call to a plugin when editor is initializing.
20
+ * It will pass in the editor instance, plugin should take this chance to save the
21
+ * editor reference so that it can call to any editor method or format API later.
22
+ * @param editor The editor object
23
+ */
24
+ initialize(editor: IEditor): void;
25
+ /**
26
+ * The last method that editor will call to a plugin before it is disposed.
27
+ * Plugin can take this chance to clear the reference to editor. After this method is
28
+ * called, plugin should not call to any editor method since it will result in error.
29
+ */
30
+ dispose(): void;
31
+ /**
32
+ * Get plugin state object
33
+ */
34
+ getState(): ContentModelCachePluginState;
35
+ /**
36
+ * Core method for a plugin. Once an event happens in editor, editor will call this
37
+ * method of each plugin to handle the event as long as the event is not handled
38
+ * exclusively by another plugin.
39
+ * @param event The event to handle:
40
+ */
41
+ onPluginEvent(event: PluginEvent): void;
42
+ private onNativeSelectionChange;
43
+ private invalidateCache;
44
+ private updateCachedModel;
45
+ private shouldClearCache;
46
+ }
47
+ /**
48
+ * @internal
49
+ * Create a new instance of ContentModelCachePlugin class.
50
+ * This is mostly for unit test
51
+ * @param state State of this plugin
52
+ */
53
+ export declare function createContentModelCachePlugin(state: ContentModelCachePluginState): ContentModelCachePlugin;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createContentModelCachePlugin = exports.ContentModelCachePlugin = void 0;
4
+ var areSameSelection_1 = require("./utils/areSameSelection");
5
+ var eventUtils_1 = require("../publicApi/domUtils/eventUtils");
6
+ /**
7
+ * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary
8
+ */
9
+ var ContentModelCachePlugin = /** @class */ (function () {
10
+ /**
11
+ * Construct a new instance of ContentModelEditPlugin class
12
+ * @param state State of this plugin
13
+ */
14
+ function ContentModelCachePlugin(state) {
15
+ var _this = this;
16
+ this.state = state;
17
+ this.editor = null;
18
+ this.onNativeSelectionChange = function () {
19
+ var _a;
20
+ if ((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) {
21
+ _this.updateCachedModel(_this.editor);
22
+ }
23
+ };
24
+ // TODO: Remove tempState parameter once we have standalone Content Model editor
25
+ }
26
+ /**
27
+ * Get name of this plugin
28
+ */
29
+ ContentModelCachePlugin.prototype.getName = function () {
30
+ return 'ContentModelCache';
31
+ };
32
+ /**
33
+ * The first method that editor will call to a plugin when editor is initializing.
34
+ * It will pass in the editor instance, plugin should take this chance to save the
35
+ * editor reference so that it can call to any editor method or format API later.
36
+ * @param editor The editor object
37
+ */
38
+ ContentModelCachePlugin.prototype.initialize = function (editor) {
39
+ // TODO: Later we may need a different interface for Content Model editor plugin
40
+ this.editor = editor;
41
+ this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);
42
+ };
43
+ /**
44
+ * The last method that editor will call to a plugin before it is disposed.
45
+ * Plugin can take this chance to clear the reference to editor. After this method is
46
+ * called, plugin should not call to any editor method since it will result in error.
47
+ */
48
+ ContentModelCachePlugin.prototype.dispose = function () {
49
+ if (this.editor) {
50
+ this.editor
51
+ .getDocument()
52
+ .removeEventListener('selectionchange', this.onNativeSelectionChange);
53
+ this.editor = null;
54
+ }
55
+ };
56
+ /**
57
+ * Get plugin state object
58
+ */
59
+ ContentModelCachePlugin.prototype.getState = function () {
60
+ return this.state;
61
+ };
62
+ /**
63
+ * Core method for a plugin. Once an event happens in editor, editor will call this
64
+ * method of each plugin to handle the event as long as the event is not handled
65
+ * exclusively by another plugin.
66
+ * @param event The event to handle:
67
+ */
68
+ ContentModelCachePlugin.prototype.onPluginEvent = function (event) {
69
+ if (!this.editor) {
70
+ return;
71
+ }
72
+ switch (event.eventType) {
73
+ case 0 /* KeyDown */:
74
+ if (this.shouldClearCache(event)) {
75
+ this.invalidateCache();
76
+ }
77
+ break;
78
+ case 3 /* Input */:
79
+ {
80
+ this.updateCachedModel(this.editor, true /*forceUpdate*/);
81
+ }
82
+ break;
83
+ case 22 /* SelectionChanged */:
84
+ this.updateCachedModel(this.editor);
85
+ break;
86
+ case 7 /* ContentChanged */:
87
+ {
88
+ var _a = event, contentModel = _a.contentModel, selection = _a.selection;
89
+ if (contentModel && this.state.domIndexer) {
90
+ this.state.cachedModel = contentModel;
91
+ this.state.cachedSelection = selection;
92
+ }
93
+ else {
94
+ this.invalidateCache();
95
+ }
96
+ }
97
+ break;
98
+ }
99
+ };
100
+ ContentModelCachePlugin.prototype.invalidateCache = function () {
101
+ var _a;
102
+ if (!((_a = this.editor) === null || _a === void 0 ? void 0 : _a.isInShadowEdit())) {
103
+ this.state.cachedModel = undefined;
104
+ this.state.cachedSelection = undefined;
105
+ }
106
+ };
107
+ ContentModelCachePlugin.prototype.updateCachedModel = function (editor, forceUpdate) {
108
+ var _a;
109
+ var cachedSelection = this.state.cachedSelection;
110
+ this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range
111
+ var newRangeEx = editor.getDOMSelection() || undefined;
112
+ var model = this.state.cachedModel;
113
+ var isSelectionChanged = forceUpdate ||
114
+ !cachedSelection ||
115
+ !newRangeEx ||
116
+ !(0, areSameSelection_1.areSameSelection)(newRangeEx, cachedSelection);
117
+ if (isSelectionChanged) {
118
+ if (!model ||
119
+ !newRangeEx ||
120
+ !((_a = this.state.domIndexer) === null || _a === void 0 ? void 0 : _a.reconcileSelection(model, newRangeEx, cachedSelection))) {
121
+ this.invalidateCache();
122
+ }
123
+ else {
124
+ this.state.cachedSelection = newRangeEx;
125
+ }
126
+ }
127
+ else {
128
+ this.state.cachedSelection = cachedSelection;
129
+ }
130
+ };
131
+ ContentModelCachePlugin.prototype.shouldClearCache = function (event) {
132
+ var _a;
133
+ var rawEvent = event.rawEvent, handledByEditFeature = event.handledByEditFeature;
134
+ // In these cases we can't update the model, so clear cache:
135
+ // 1. It is already handled by Content Edit Features
136
+ if (handledByEditFeature) {
137
+ return true;
138
+ }
139
+ // 2. Default behavior is prevented, which means other plugins has handled the event
140
+ if (rawEvent.defaultPrevented) {
141
+ return true;
142
+ }
143
+ // 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change
144
+ // TODO: Handle ENTER key to better reuse content model
145
+ if (rawEvent.key == 'Enter') {
146
+ return true;
147
+ }
148
+ // 4. Current selection is image or table or expanded range selection, and is inputting some text
149
+ if ((((_a = this.state.cachedSelection) === null || _a === void 0 ? void 0 : _a.type) != 'range' ||
150
+ !this.state.cachedSelection.range.collapsed) &&
151
+ (0, eventUtils_1.isCharacterValue)(rawEvent)) {
152
+ return true;
153
+ }
154
+ return false;
155
+ };
156
+ return ContentModelCachePlugin;
157
+ }());
158
+ exports.ContentModelCachePlugin = ContentModelCachePlugin;
159
+ /**
160
+ * @internal
161
+ * Create a new instance of ContentModelCachePlugin class.
162
+ * This is mostly for unit test
163
+ * @param state State of this plugin
164
+ */
165
+ function createContentModelCachePlugin(state) {
166
+ return new ContentModelCachePlugin(state);
167
+ }
168
+ exports.createContentModelCachePlugin = createContentModelCachePlugin;
169
+ //# sourceMappingURL=ContentModelCachePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentModelCachePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/Cont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AAC;AAC9C,CAAC;AAFD,sEAEC","sourcesContent":["import { areSameSelection } from './utils/areSameSelection';\nimport { isCharacterValue } from '../publicApi/domUtils/eventUtils';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type {\n ContentModelCachePluginState,\n ContentModelContentChangedEvent,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\nimport type {\n IEditor,\n PluginEvent,\n PluginKeyDownEvent,\n PluginWithState,\n} from 'roosterjs-editor-types';\n\n/**\n * ContentModel cache plugin manages cached Content Model, and refresh the cache when necessary\n */\nexport class ContentModelCachePlugin implements PluginWithState<ContentModelCachePluginState> {\n private editor: (IEditor & IStandaloneEditor) | null = null;\n\n /**\n * Construct a new instance of ContentModelEditPlugin class\n * @param state State of this plugin\n */\n constructor(private state: ContentModelCachePluginState) {\n // TODO: Remove tempState parameter once we have standalone Content Model editor\n }\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelCache';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IEditor & IStandaloneEditor;\n this.editor.getDocument().addEventListener('selectionchange', this.onNativeSelectionChange);\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n if (this.editor) {\n this.editor\n .getDocument()\n .removeEventListener('selectionchange', this.onNativeSelectionChange);\n this.editor = null;\n }\n }\n\n /**\n * Get plugin state object\n */\n getState(): ContentModelCachePluginState {\n return this.state;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor) {\n return;\n }\n\n switch (event.eventType) {\n case PluginEventType.KeyDown:\n if (this.shouldClearCache(event)) {\n this.invalidateCache();\n }\n break;\n\n case PluginEventType.Input:\n {\n this.updateCachedModel(this.editor, true /*forceUpdate*/);\n }\n break;\n\n case PluginEventType.SelectionChanged:\n this.updateCachedModel(this.editor);\n break;\n\n case PluginEventType.ContentChanged:\n {\n const { contentModel, selection } = event as ContentModelContentChangedEvent;\n\n if (contentModel && this.state.domIndexer) {\n this.state.cachedModel = contentModel;\n this.state.cachedSelection = selection;\n } else {\n this.invalidateCache();\n }\n }\n\n break;\n }\n }\n\n private onNativeSelectionChange = () => {\n if (this.editor?.hasFocus()) {\n this.updateCachedModel(this.editor);\n }\n };\n\n private invalidateCache() {\n if (!this.editor?.isInShadowEdit()) {\n this.state.cachedModel = undefined;\n this.state.cachedSelection = undefined;\n }\n }\n\n private updateCachedModel(editor: IStandaloneEditor, forceUpdate?: boolean) {\n const cachedSelection = this.state.cachedSelection;\n this.state.cachedSelection = undefined; // Clear it to force getDOMSelection() retrieve the latest selection range\n\n const newRangeEx = editor.getDOMSelection() || undefined;\n const model = this.state.cachedModel;\n const isSelectionChanged =\n forceUpdate ||\n !cachedSelection ||\n !newRangeEx ||\n !areSameSelection(newRangeEx, cachedSelection);\n\n if (isSelectionChanged) {\n if (\n !model ||\n !newRangeEx ||\n !this.state.domIndexer?.reconcileSelection(model, newRangeEx, cachedSelection)\n ) {\n this.invalidateCache();\n } else {\n this.state.cachedSelection = newRangeEx;\n }\n } else {\n this.state.cachedSelection = cachedSelection;\n }\n }\n\n private shouldClearCache(event: PluginKeyDownEvent) {\n const { rawEvent, handledByEditFeature } = event;\n\n // In these cases we can't update the model, so clear cache:\n // 1. It is already handled by Content Edit Features\n if (handledByEditFeature) {\n return true;\n }\n\n // 2. Default behavior is prevented, which means other plugins has handled the event\n if (rawEvent.defaultPrevented) {\n return true;\n }\n\n // 3. ENTER key is pressed. ENTER key will create new paragraph, so need to update cache to reflect this change\n // TODO: Handle ENTER key to better reuse content model\n\n if (rawEvent.key == 'Enter') {\n return true;\n }\n\n // 4. Current selection is image or table or expanded range selection, and is inputting some text\n if (\n (this.state.cachedSelection?.type != 'range' ||\n !this.state.cachedSelection.range.collapsed) &&\n isCharacterValue(rawEvent)\n ) {\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * @internal\n * Create a new instance of ContentModelCachePlugin class.\n * This is mostly for unit test\n * @param state State of this plugin\n */\nexport function createContentModelCachePlugin(state: ContentModelCachePluginState) {\n return new ContentModelCachePlugin(state);\n}\n"]}
@@ -0,0 +1,46 @@
1
+ import type { OnNodeCreated } from 'roosterjs-content-model-types';
2
+ import type { CopyPastePluginState, IEditor, PluginWithState } from 'roosterjs-editor-types';
3
+ /**
4
+ * Copy and paste plugin for handling onCopy and onPaste event
5
+ */
6
+ export declare class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {
7
+ private state;
8
+ private editor;
9
+ private disposer;
10
+ /**
11
+ * Construct a new instance of CopyPastePlugin
12
+ * @param options The editor options
13
+ */
14
+ constructor(state: CopyPastePluginState);
15
+ /**
16
+ * Get a friendly name of this plugin
17
+ */
18
+ getName(): string;
19
+ /**
20
+ * Initialize this plugin. This should only be called from Editor
21
+ * @param editor Editor instance
22
+ */
23
+ initialize(editor: IEditor): void;
24
+ /**
25
+ * Dispose this plugin
26
+ */
27
+ dispose(): void;
28
+ /**
29
+ * Get plugin state object
30
+ */
31
+ getState(): CopyPastePluginState;
32
+ private onCutCopy;
33
+ private onPaste;
34
+ private getTempDiv;
35
+ }
36
+ /**
37
+ * @internal
38
+ * Exported only for unit testing
39
+ */
40
+ export declare const onNodeCreated: OnNodeCreated;
41
+ /**
42
+ * @internal
43
+ * Create a new instance of ContentModelCopyPastePlugin
44
+ * @param state The plugin state object
45
+ */
46
+ export declare function createContentModelCopyPastePlugin(state: CopyPastePluginState): ContentModelCopyPastePlugin;