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,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;
@@ -0,0 +1,228 @@
1
+ import { __assign } from "tslib";
2
+ import { addRangeToSelection } from './utils/addRangeToSelection';
3
+ import { ChangeSource } from '../constants/ChangeSource';
4
+ import { cloneModel } from '../publicApi/model/cloneModel';
5
+ import { deleteSelection } from '../publicApi/selection/deleteSelection';
6
+ import { extractClipboardItems } from 'roosterjs-editor-dom';
7
+ import { iterateSelections } from '../publicApi/selection/iterateSelections';
8
+ import { paste } from '../publicApi/model/paste';
9
+ import { contentModelToDom, createModelToDomContext, isElementOfType, isNodeOfType, moveChildNodes, normalizeContentModel, toArray, wrap, } from 'roosterjs-content-model-dom';
10
+ /**
11
+ * Copy and paste plugin for handling onCopy and onPaste event
12
+ */
13
+ var ContentModelCopyPastePlugin = /** @class */ (function () {
14
+ /**
15
+ * Construct a new instance of CopyPastePlugin
16
+ * @param options The editor options
17
+ */
18
+ function ContentModelCopyPastePlugin(state) {
19
+ var _this = this;
20
+ this.state = state;
21
+ this.editor = null;
22
+ this.disposer = null;
23
+ this.onPaste = function (event) {
24
+ if (_this.editor && isClipboardEvent(event)) {
25
+ var editor_1 = _this.editor;
26
+ var dataTransfer = event.clipboardData;
27
+ if (dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.items) {
28
+ event.preventDefault();
29
+ extractClipboardItems(toArray(dataTransfer.items), {
30
+ allowedCustomPasteType: _this.state.allowedCustomPasteType,
31
+ }, true /*pasteNativeEvent*/).then(function (clipboardData) {
32
+ if (!editor_1.isDisposed()) {
33
+ paste(editor_1, clipboardData);
34
+ }
35
+ });
36
+ }
37
+ }
38
+ };
39
+ }
40
+ /**
41
+ * Get a friendly name of this plugin
42
+ */
43
+ ContentModelCopyPastePlugin.prototype.getName = function () {
44
+ return 'ContentModelCopyPaste';
45
+ };
46
+ /**
47
+ * Initialize this plugin. This should only be called from Editor
48
+ * @param editor Editor instance
49
+ */
50
+ ContentModelCopyPastePlugin.prototype.initialize = function (editor) {
51
+ var _this = this;
52
+ this.editor = editor;
53
+ this.disposer = this.editor.addDomEventHandler({
54
+ paste: function (e) { return _this.onPaste(e); },
55
+ copy: function (e) { return _this.onCutCopy(e, false /*isCut*/); },
56
+ cut: function (e) { return _this.onCutCopy(e, true /*isCut*/); },
57
+ });
58
+ };
59
+ /**
60
+ * Dispose this plugin
61
+ */
62
+ ContentModelCopyPastePlugin.prototype.dispose = function () {
63
+ if (this.disposer) {
64
+ this.disposer();
65
+ }
66
+ this.disposer = null;
67
+ this.editor = null;
68
+ };
69
+ /**
70
+ * Get plugin state object
71
+ */
72
+ ContentModelCopyPastePlugin.prototype.getState = function () {
73
+ return this.state;
74
+ };
75
+ ContentModelCopyPastePlugin.prototype.onCutCopy = function (event, isCut) {
76
+ var _this = this;
77
+ if (!this.editor) {
78
+ return;
79
+ }
80
+ var doc = this.editor.getDocument();
81
+ var selection = this.editor.getDOMSelection();
82
+ if (selection && (selection.type != 'range' || !selection.range.collapsed)) {
83
+ var model = this.editor.createContentModel();
84
+ var pasteModel = cloneModel(model, {
85
+ includeCachedElement: this.editor.isDarkMode()
86
+ ? function (node, type) {
87
+ var _a;
88
+ if (type == 'cache') {
89
+ return undefined;
90
+ }
91
+ else {
92
+ var result = node.cloneNode(true /*deep*/);
93
+ (_a = _this.editor) === null || _a === void 0 ? void 0 : _a.transformToDarkColor(result, 1 /* DarkToLight */);
94
+ result.style.color = result.style.color || 'inherit';
95
+ result.style.backgroundColor =
96
+ result.style.backgroundColor || 'inherit';
97
+ return result;
98
+ }
99
+ }
100
+ : false,
101
+ });
102
+ if (selection.type === 'table') {
103
+ iterateSelections(pasteModel, function (_, tableContext) {
104
+ if (tableContext === null || tableContext === void 0 ? void 0 : tableContext.table) {
105
+ var table = tableContext === null || tableContext === void 0 ? void 0 : tableContext.table;
106
+ table.rows = table.rows
107
+ .map(function (row) {
108
+ return __assign(__assign({}, row), { cells: row.cells.filter(function (cell) { return cell.isSelected; }) });
109
+ })
110
+ .filter(function (row) { return row.cells.length > 0; });
111
+ return true;
112
+ }
113
+ return false;
114
+ });
115
+ }
116
+ var tempDiv_1 = this.getTempDiv(this.editor);
117
+ var selectionForCopy = contentModelToDom(tempDiv_1.ownerDocument, tempDiv_1, pasteModel, createModelToDomContext(), onNodeCreated);
118
+ var newRange = selectionForCopy
119
+ ? domSelectionToRange(doc, selectionForCopy, tempDiv_1)
120
+ : null;
121
+ if (newRange) {
122
+ newRange = this.editor.triggerPluginEvent(9 /* BeforeCutCopy */, {
123
+ clonedRoot: tempDiv_1,
124
+ range: newRange,
125
+ rawEvent: event,
126
+ isCut: isCut,
127
+ }).range;
128
+ if (newRange) {
129
+ addRangeToSelection(doc, newRange);
130
+ }
131
+ this.editor.runAsync(function (e) {
132
+ var editor = e;
133
+ cleanUpAndRestoreSelection(tempDiv_1);
134
+ editor.focus();
135
+ editor.setDOMSelection(selection);
136
+ if (isCut) {
137
+ editor.formatContentModel(function (model, context) {
138
+ if (deleteSelection(model, [], context).deleteResult == 'range') {
139
+ normalizeContentModel(model);
140
+ }
141
+ return true;
142
+ }, {
143
+ apiName: 'cut',
144
+ changeSource: ChangeSource.Cut,
145
+ });
146
+ }
147
+ });
148
+ }
149
+ else {
150
+ cleanUpAndRestoreSelection(tempDiv_1);
151
+ }
152
+ }
153
+ };
154
+ ContentModelCopyPastePlugin.prototype.getTempDiv = function (editor) {
155
+ var div = editor.getCustomData('CopyPasteTempDiv', function () {
156
+ var tempDiv = editor.getDocument().createElement('div');
157
+ tempDiv.style.width = '600px';
158
+ tempDiv.style.height = '1px';
159
+ tempDiv.style.overflow = 'hidden';
160
+ tempDiv.style.position = 'fixed';
161
+ tempDiv.style.top = '0';
162
+ tempDiv.style.left = '0';
163
+ tempDiv.style.userSelect = 'text';
164
+ tempDiv.contentEditable = 'true';
165
+ editor.getDocument().body.appendChild(tempDiv);
166
+ return tempDiv;
167
+ }, function (tempDiv) { var _a; return (_a = tempDiv.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(tempDiv); });
168
+ div.style.backgroundColor = 'white';
169
+ div.style.color = 'black';
170
+ div.childNodes.forEach(function (node) { return div.removeChild(node); });
171
+ div.style.display = '';
172
+ div.focus();
173
+ return div;
174
+ };
175
+ return ContentModelCopyPastePlugin;
176
+ }());
177
+ export { ContentModelCopyPastePlugin };
178
+ function cleanUpAndRestoreSelection(tempDiv) {
179
+ tempDiv.style.backgroundColor = '';
180
+ tempDiv.style.color = '';
181
+ tempDiv.style.display = 'none';
182
+ moveChildNodes(tempDiv);
183
+ }
184
+ function isClipboardEvent(event) {
185
+ return !!event.clipboardData;
186
+ }
187
+ function domSelectionToRange(doc, selection, tempDiv) {
188
+ var _a;
189
+ var newRange = null;
190
+ if (selection.type === 'table') {
191
+ var table = tempDiv.querySelector("#" + selection.table.id);
192
+ var elementToSelect = ((_a = table.parentElement) === null || _a === void 0 ? void 0 : _a.childElementCount) == 1 ? table.parentElement : table;
193
+ newRange = doc.createRange();
194
+ newRange.selectNode(elementToSelect);
195
+ }
196
+ else if (selection.type === 'image') {
197
+ var image = tempDiv.querySelector('#' + selection.image.id);
198
+ if (image) {
199
+ newRange = doc.createRange();
200
+ newRange.selectNode(image);
201
+ }
202
+ }
203
+ else {
204
+ newRange = selection.range;
205
+ }
206
+ return newRange;
207
+ }
208
+ /**
209
+ * @internal
210
+ * Exported only for unit testing
211
+ */
212
+ export var onNodeCreated = function (_, node) {
213
+ if (isNodeOfType(node, 'ELEMENT_NODE') && isElementOfType(node, 'table')) {
214
+ wrap(node.ownerDocument, node, 'div');
215
+ }
216
+ if (isNodeOfType(node, 'ELEMENT_NODE') && !node.isContentEditable) {
217
+ node.removeAttribute('contenteditable');
218
+ }
219
+ };
220
+ /**
221
+ * @internal
222
+ * Create a new instance of ContentModelCopyPastePlugin
223
+ * @param state The plugin state object
224
+ */
225
+ export function createContentModelCopyPastePlugin(state) {
226
+ return new ContentModelCopyPastePlugin(state);
227
+ }
228
+ //# sourceMappingURL=ContentModelCopyPastePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentModelCopyPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelCopyPastePlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACjD,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,YAA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ChD,IAAI,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE;QACtE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;KACzC;IACD,IAAI,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;QAC/D,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;KAC3C;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,CAAC,KAA2B;IACzE,OAAO,IAAI,2BAA2B,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { addRangeToSelection } from './utils/addRangeToSelection';\nimport { ChangeSource } from '../constants/ChangeSource';\nimport { cloneModel } from '../publicApi/model/cloneModel';\nimport { ColorTransformDirection, PluginEventType } from 'roosterjs-editor-types';\nimport { deleteSelection } from '../publicApi/selection/deleteSelection';\nimport { extractClipboardItems } from 'roosterjs-editor-dom';\nimport { iterateSelections } from '../publicApi/selection/iterateSelections';\nimport { paste } from '../publicApi/model/paste';\nimport {\n contentModelToDom,\n createModelToDomContext,\n isElementOfType,\n isNodeOfType,\n moveChildNodes,\n normalizeContentModel,\n toArray,\n wrap,\n} from 'roosterjs-content-model-dom';\nimport type { DOMSelection, IStandaloneEditor, OnNodeCreated } from 'roosterjs-content-model-types';\nimport type {\n CopyPastePluginState,\n IEditor,\n PluginWithState,\n ClipboardData,\n} from 'roosterjs-editor-types';\n\n/**\n * Copy and paste plugin for handling onCopy and onPaste event\n */\nexport class ContentModelCopyPastePlugin implements PluginWithState<CopyPastePluginState> {\n private editor: (IStandaloneEditor & IEditor) | null = null;\n private disposer: (() => void) | null = null;\n\n /**\n * Construct a new instance of CopyPastePlugin\n * @param options The editor options\n */\n constructor(private state: CopyPastePluginState) {}\n\n /**\n * Get a friendly name of this plugin\n */\n getName() {\n return 'ContentModelCopyPaste';\n }\n\n /**\n * Initialize this plugin. This should only be called from Editor\n * @param editor Editor instance\n */\n initialize(editor: IEditor) {\n this.editor = editor as IStandaloneEditor & IEditor;\n this.disposer = this.editor.addDomEventHandler({\n paste: e => this.onPaste(e),\n copy: e => this.onCutCopy(e, false /*isCut*/),\n cut: e => this.onCutCopy(e, true /*isCut*/),\n });\n }\n\n /**\n * Dispose this plugin\n */\n dispose() {\n if (this.disposer) {\n this.disposer();\n }\n this.disposer = null;\n this.editor = null;\n }\n\n /**\n * Get plugin state object\n */\n getState() {\n return this.state;\n }\n\n private onCutCopy(event: Event, isCut: boolean) {\n if (!this.editor) {\n return;\n }\n\n const doc = this.editor.getDocument();\n const selection = this.editor.getDOMSelection();\n\n if (selection && (selection.type != 'range' || !selection.range.collapsed)) {\n const model = this.editor.createContentModel();\n\n const pasteModel = cloneModel(model, {\n includeCachedElement: this.editor.isDarkMode()\n ? (node, type) => {\n if (type == 'cache') {\n return undefined;\n } else {\n const result = node.cloneNode(true /*deep*/) as HTMLElement;\n\n this.editor?.transformToDarkColor(\n result,\n ColorTransformDirection.DarkToLight\n );\n\n result.style.color = result.style.color || 'inherit';\n result.style.backgroundColor =\n result.style.backgroundColor || 'inherit';\n\n return result;\n }\n }\n : false,\n });\n if (selection.type === 'table') {\n iterateSelections(pasteModel, (_, tableContext) => {\n if (tableContext?.table) {\n const table = tableContext?.table;\n table.rows = table.rows\n .map(row => {\n return {\n ...row,\n cells: row.cells.filter(cell => cell.isSelected),\n };\n })\n .filter(row => row.cells.length > 0);\n return true;\n }\n return false;\n });\n }\n const tempDiv = this.getTempDiv(this.editor);\n const selectionForCopy = contentModelToDom(\n tempDiv.ownerDocument,\n tempDiv,\n pasteModel,\n createModelToDomContext(),\n onNodeCreated\n );\n\n let newRange: Range | null = selectionForCopy\n ? domSelectionToRange(doc, selectionForCopy, tempDiv)\n : null;\n if (newRange) {\n newRange = this.editor.triggerPluginEvent(PluginEventType.BeforeCutCopy, {\n clonedRoot: tempDiv,\n range: newRange,\n rawEvent: event as ClipboardEvent,\n isCut,\n }).range;\n\n if (newRange) {\n addRangeToSelection(doc, newRange);\n }\n\n this.editor.runAsync(e => {\n const editor = e as IStandaloneEditor & IEditor;\n\n cleanUpAndRestoreSelection(tempDiv);\n editor.focus();\n editor.setDOMSelection(selection);\n\n if (isCut) {\n editor.formatContentModel(\n (model, context) => {\n if (deleteSelection(model, [], context).deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n return true;\n },\n {\n apiName: 'cut',\n changeSource: ChangeSource.Cut,\n }\n );\n }\n });\n } else {\n cleanUpAndRestoreSelection(tempDiv);\n }\n }\n }\n\n private onPaste = (event: Event) => {\n if (this.editor && isClipboardEvent(event)) {\n const editor = this.editor;\n\n const dataTransfer = event.clipboardData;\n\n if (dataTransfer?.items) {\n event.preventDefault();\n extractClipboardItems(\n toArray(dataTransfer.items),\n {\n allowedCustomPasteType: this.state.allowedCustomPasteType,\n },\n true /*pasteNativeEvent*/\n ).then((clipboardData: ClipboardData) => {\n if (!editor.isDisposed()) {\n paste(editor, clipboardData);\n }\n });\n }\n }\n };\n\n private getTempDiv(editor: IEditor) {\n const div = editor.getCustomData(\n 'CopyPasteTempDiv',\n () => {\n const tempDiv = editor.getDocument().createElement('div');\n\n tempDiv.style.width = '600px';\n tempDiv.style.height = '1px';\n tempDiv.style.overflow = 'hidden';\n tempDiv.style.position = 'fixed';\n tempDiv.style.top = '0';\n tempDiv.style.left = '0';\n tempDiv.style.userSelect = 'text';\n tempDiv.contentEditable = 'true';\n\n editor.getDocument().body.appendChild(tempDiv);\n\n return tempDiv;\n },\n tempDiv => tempDiv.parentNode?.removeChild(tempDiv)\n );\n\n div.style.backgroundColor = 'white';\n div.style.color = 'black';\n div.childNodes.forEach(node => div.removeChild(node));\n\n div.style.display = '';\n div.focus();\n\n return div;\n }\n}\n\nfunction cleanUpAndRestoreSelection(tempDiv: HTMLDivElement) {\n tempDiv.style.backgroundColor = '';\n tempDiv.style.color = '';\n tempDiv.style.display = 'none';\n moveChildNodes(tempDiv);\n}\n\nfunction isClipboardEvent(event: Event): event is ClipboardEvent {\n return !!(event as ClipboardEvent).clipboardData;\n}\n\nfunction domSelectionToRange(\n doc: Document,\n selection: DOMSelection,\n tempDiv: HTMLDivElement\n): Range | null {\n let newRange: Range | null = null;\n\n if (selection.type === 'table') {\n const table = tempDiv.querySelector(`#${selection.table.id}`) as HTMLTableElement;\n const elementToSelect =\n table.parentElement?.childElementCount == 1 ? table.parentElement : table;\n\n newRange = doc.createRange();\n newRange.selectNode(elementToSelect);\n } else if (selection.type === 'image') {\n const image = tempDiv.querySelector('#' + selection.image.id);\n\n if (image) {\n newRange = doc.createRange();\n newRange.selectNode(image);\n }\n } else {\n newRange = selection.range;\n }\n\n return newRange;\n}\n\n/**\n * @internal\n * Exported only for unit testing\n */\nexport const onNodeCreated: OnNodeCreated = (_, node): void => {\n if (isNodeOfType(node, 'ELEMENT_NODE') && isElementOfType(node, 'table')) {\n wrap(node.ownerDocument, node, 'div');\n }\n if (isNodeOfType(node, 'ELEMENT_NODE') && !node.isContentEditable) {\n node.removeAttribute('contenteditable');\n }\n};\n\n/**\n * @internal\n * Create a new instance of ContentModelCopyPastePlugin\n * @param state The plugin state object\n */\nexport function createContentModelCopyPastePlugin(state: CopyPastePluginState) {\n return new ContentModelCopyPastePlugin(state);\n}\n"]}
@@ -0,0 +1,59 @@
1
+ import type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';
2
+ import type { ContentModelFormatPluginState } from 'roosterjs-content-model-types';
3
+ /**
4
+ * ContentModelFormat plugins helps editor to do formatting on top of content model.
5
+ * This includes:
6
+ * 1. Handle pending format changes when selection is collapsed
7
+ */
8
+ export declare class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {
9
+ private state;
10
+ private editor;
11
+ private hasDefaultFormat;
12
+ /**
13
+ * Construct a new instance of ContentModelEditPlugin class
14
+ * @param state State of this plugin
15
+ */
16
+ constructor(state: ContentModelFormatPluginState);
17
+ /**
18
+ * Get name of this plugin
19
+ */
20
+ getName(): string;
21
+ /**
22
+ * The first method that editor will call to a plugin when editor is initializing.
23
+ * It will pass in the editor instance, plugin should take this chance to save the
24
+ * editor reference so that it can call to any editor method or format API later.
25
+ * @param editor The editor object
26
+ */
27
+ initialize(editor: IEditor): void;
28
+ /**
29
+ * The last method that editor will call to a plugin before it is disposed.
30
+ * Plugin can take this chance to clear the reference to editor. After this method is
31
+ * called, plugin should not call to any editor method since it will result in error.
32
+ */
33
+ dispose(): void;
34
+ /**
35
+ * Get plugin state object
36
+ */
37
+ getState(): ContentModelFormatPluginState;
38
+ /**
39
+ * Core method for a plugin. Once an event happens in editor, editor will call this
40
+ * method of each plugin to handle the event as long as the event is not handled
41
+ * exclusively by another plugin.
42
+ * @param event The event to handle:
43
+ */
44
+ onPluginEvent(event: PluginEvent): void;
45
+ private checkAndApplyPendingFormat;
46
+ private clearPendingFormat;
47
+ /**
48
+ * @internal
49
+ * Check if this editor can apply pending format
50
+ * @param editor The editor to get format from
51
+ */
52
+ private canApplyPendingFormat;
53
+ }
54
+ /**
55
+ * @internal
56
+ * Create a new instance of ContentModelFormatPlugin.
57
+ * This is mostly for unit test
58
+ */
59
+ export declare function createContentModelFormatPlugin(state: ContentModelFormatPluginState): ContentModelFormatPlugin;
@@ -0,0 +1,143 @@
1
+ import { applyDefaultFormat } from './utils/applyDefaultFormat';
2
+ import { applyPendingFormat } from './utils/applyPendingFormat';
3
+ import { getObjectKeys } from 'roosterjs-content-model-dom';
4
+ import { isCharacterValue } from '../publicApi/domUtils/eventUtils';
5
+ // During IME input, KeyDown event will have "Process" as key
6
+ var ProcessKey = 'Process';
7
+ var CursorMovingKeys = new Set([
8
+ 'ArrowUp',
9
+ 'ArrowDown',
10
+ 'ArrowLeft',
11
+ 'ArrowRight',
12
+ 'Home',
13
+ 'End',
14
+ 'PageUp',
15
+ 'PageDown',
16
+ ]);
17
+ /**
18
+ * ContentModelFormat plugins helps editor to do formatting on top of content model.
19
+ * This includes:
20
+ * 1. Handle pending format changes when selection is collapsed
21
+ */
22
+ var ContentModelFormatPlugin = /** @class */ (function () {
23
+ /**
24
+ * Construct a new instance of ContentModelEditPlugin class
25
+ * @param state State of this plugin
26
+ */
27
+ function ContentModelFormatPlugin(state) {
28
+ this.state = state;
29
+ this.editor = null;
30
+ this.hasDefaultFormat = false;
31
+ // TODO: Remove tempState parameter once we have standalone Content Model editor
32
+ }
33
+ /**
34
+ * Get name of this plugin
35
+ */
36
+ ContentModelFormatPlugin.prototype.getName = function () {
37
+ return 'ContentModelFormat';
38
+ };
39
+ /**
40
+ * The first method that editor will call to a plugin when editor is initializing.
41
+ * It will pass in the editor instance, plugin should take this chance to save the
42
+ * editor reference so that it can call to any editor method or format API later.
43
+ * @param editor The editor object
44
+ */
45
+ ContentModelFormatPlugin.prototype.initialize = function (editor) {
46
+ var _this = this;
47
+ // TODO: Later we may need a different interface for Content Model editor plugin
48
+ this.editor = editor;
49
+ this.hasDefaultFormat =
50
+ getObjectKeys(this.state.defaultFormat).filter(function (x) { return typeof _this.state.defaultFormat[x] !== 'undefined'; }).length > 0;
51
+ };
52
+ /**
53
+ * The last method that editor will call to a plugin before it is disposed.
54
+ * Plugin can take this chance to clear the reference to editor. After this method is
55
+ * called, plugin should not call to any editor method since it will result in error.
56
+ */
57
+ ContentModelFormatPlugin.prototype.dispose = function () {
58
+ this.editor = null;
59
+ };
60
+ /**
61
+ * Get plugin state object
62
+ */
63
+ ContentModelFormatPlugin.prototype.getState = function () {
64
+ return this.state;
65
+ };
66
+ /**
67
+ * Core method for a plugin. Once an event happens in editor, editor will call this
68
+ * method of each plugin to handle the event as long as the event is not handled
69
+ * exclusively by another plugin.
70
+ * @param event The event to handle:
71
+ */
72
+ ContentModelFormatPlugin.prototype.onPluginEvent = function (event) {
73
+ if (!this.editor) {
74
+ return;
75
+ }
76
+ switch (event.eventType) {
77
+ case 3 /* Input */:
78
+ var env = this.editor.getEnvironment();
79
+ // In Safari, isComposing will be undefined but isInIME() works
80
+ // For Android, we can skip checking isComposing since this property is not always reliable in all IME,
81
+ // and we have tested without this check it can still work correctly
82
+ if (env.isAndroid || (!event.rawEvent.isComposing && !this.editor.isInIME())) {
83
+ this.checkAndApplyPendingFormat(event.rawEvent.data);
84
+ }
85
+ break;
86
+ case 4 /* CompositionEnd */:
87
+ this.checkAndApplyPendingFormat(event.rawEvent.data);
88
+ break;
89
+ case 0 /* KeyDown */:
90
+ if (CursorMovingKeys.has(event.rawEvent.key)) {
91
+ this.clearPendingFormat();
92
+ }
93
+ else if (this.hasDefaultFormat &&
94
+ (isCharacterValue(event.rawEvent) || event.rawEvent.key == ProcessKey)) {
95
+ applyDefaultFormat(this.editor, this.state.defaultFormat);
96
+ }
97
+ break;
98
+ case 6 /* MouseUp */:
99
+ case 7 /* ContentChanged */:
100
+ if (!this.canApplyPendingFormat()) {
101
+ this.clearPendingFormat();
102
+ }
103
+ break;
104
+ }
105
+ };
106
+ ContentModelFormatPlugin.prototype.checkAndApplyPendingFormat = function (data) {
107
+ if (this.editor && data && this.state.pendingFormat) {
108
+ applyPendingFormat(this.editor, data, this.state.pendingFormat.format);
109
+ this.clearPendingFormat();
110
+ }
111
+ };
112
+ ContentModelFormatPlugin.prototype.clearPendingFormat = function () {
113
+ this.state.pendingFormat = null;
114
+ };
115
+ /**
116
+ * @internal
117
+ * Check if this editor can apply pending format
118
+ * @param editor The editor to get format from
119
+ */
120
+ ContentModelFormatPlugin.prototype.canApplyPendingFormat = function () {
121
+ var result = false;
122
+ if (this.state.pendingFormat && this.editor) {
123
+ var selection = this.editor.getDOMSelection();
124
+ var range = (selection === null || selection === void 0 ? void 0 : selection.type) == 'range' && selection.range.collapsed ? selection.range : null;
125
+ var _a = this.state.pendingFormat, posContainer = _a.posContainer, posOffset = _a.posOffset;
126
+ if (range && range.startContainer == posContainer && range.startOffset == posOffset) {
127
+ result = true;
128
+ }
129
+ }
130
+ return result;
131
+ };
132
+ return ContentModelFormatPlugin;
133
+ }());
134
+ export { ContentModelFormatPlugin };
135
+ /**
136
+ * @internal
137
+ * Create a new instance of ContentModelFormatPlugin.
138
+ * This is mostly for unit test
139
+ */
140
+ export function createContentModelFormatPlugin(state) {
141
+ return new ContentModelFormatPlugin(state);
142
+ }
143
+ //# sourceMappingURL=ContentModelFormatPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentModelFormatPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelFormatPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAQpE,6DAA6D;AAC7D,IAAM,UAAU,GAAG,SAAS,CAAC;AAC7B,IAAM,gBAAgB,GAAG,IAAI,GAAG,CAAS;IACrC,SAAS;IACT,WAAW;IACX,WAAW;IACX,YAAY;IACZ,MAAM;IACN,KAAK;IACL,QAAQ;IACR,UAAU;CACb,CAAC,CAAC;AAEH;;;;GAIG;AACH;IAII;;;OAGG;IACH,kCAAoB,KAAoC;QAApC,UAAK,GAAL,KAAK,CAA+B;QAPhD,WAAM,GAAyC,IAAI,CAAC;QACpD,qBAAgB,GAAG,KAAK,CAAC;QAO7B,gFAAgF;IACpF,CAAC;IAED;;OAEG;IACH,0CAAO,GAAP;QACI,OAAO,oBAAoB,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,6CAAU,GAAV,UAAW,MAAe;QAA1B,iBAOC;QANG,gFAAgF;QAChF,IAAI,CAAC,MAAM,GAAG,MAAqC,CAAC;QACpD,IAAI,CAAC,gBAAgB;YACjB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,MAAM,CAC1C,UAAA,CA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AAM,CAAC;IAClB,CAAC;IACL,+BAAC;AAAD,CAAC,AAnID,IAmIC;;AAED;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,KAAoC;IAC/E,OAAO,IAAI,wBAAwB,CAAC,KAAK,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { applyDefaultFormat } from './utils/applyDefaultFormat';\nimport { applyPendingFormat } from './utils/applyPendingFormat';\nimport { getObjectKeys } from 'roosterjs-content-model-dom';\nimport { isCharacterValue } from '../publicApi/domUtils/eventUtils';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport type { IEditor, PluginEvent, PluginWithState } from 'roosterjs-editor-types';\nimport type {\n ContentModelFormatPluginState,\n IStandaloneEditor,\n} from 'roosterjs-content-model-types';\n\n// During IME input, KeyDown event will have \"Process\" as key\nconst ProcessKey = 'Process';\nconst CursorMovingKeys = new Set<string>([\n 'ArrowUp',\n 'ArrowDown',\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n]);\n\n/**\n * ContentModelFormat plugins helps editor to do formatting on top of content model.\n * This includes:\n * 1. Handle pending format changes when selection is collapsed\n */\nexport class ContentModelFormatPlugin implements PluginWithState<ContentModelFormatPluginState> {\n private editor: (IStandaloneEditor & IEditor) | null = null;\n private hasDefaultFormat = false;\n\n /**\n * Construct a new instance of ContentModelEditPlugin class\n * @param state State of this plugin\n */\n constructor(private state: ContentModelFormatPluginState) {\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 'ContentModelFormat';\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 IStandaloneEditor & IEditor;\n this.hasDefaultFormat =\n getObjectKeys(this.state.defaultFormat).filter(\n x => typeof this.state.defaultFormat[x] !== 'undefined'\n ).length > 0;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Get plugin state object\n */\n getState(): ContentModelFormatPluginState {\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.Input:\n const env = this.editor.getEnvironment();\n\n // In Safari, isComposing will be undefined but isInIME() works\n // For Android, we can skip checking isComposing since this property is not always reliable in all IME,\n // and we have tested without this check it can still work correctly\n if (env.isAndroid || (!event.rawEvent.isComposing && !this.editor.isInIME())) {\n this.checkAndApplyPendingFormat(event.rawEvent.data);\n }\n\n break;\n\n case PluginEventType.CompositionEnd:\n this.checkAndApplyPendingFormat(event.rawEvent.data);\n break;\n\n case PluginEventType.KeyDown:\n if (CursorMovingKeys.has(event.rawEvent.key)) {\n this.clearPendingFormat();\n } else if (\n this.hasDefaultFormat &&\n (isCharacterValue(event.rawEvent) || event.rawEvent.key == ProcessKey)\n ) {\n applyDefaultFormat(this.editor, this.state.defaultFormat);\n }\n\n break;\n\n case PluginEventType.MouseUp:\n case PluginEventType.ContentChanged:\n if (!this.canApplyPendingFormat()) {\n this.clearPendingFormat();\n }\n break;\n }\n }\n\n private checkAndApplyPendingFormat(data: string | null) {\n if (this.editor && data && this.state.pendingFormat) {\n applyPendingFormat(this.editor, data, this.state.pendingFormat.format);\n this.clearPendingFormat();\n }\n }\n\n private clearPendingFormat() {\n this.state.pendingFormat = null;\n }\n\n /**\n * @internal\n * Check if this editor can apply pending format\n * @param editor The editor to get format from\n */\n private canApplyPendingFormat(): boolean {\n let result = false;\n\n if (this.state.pendingFormat && this.editor) {\n const selection = this.editor.getDOMSelection();\n const range =\n selection?.type == 'range' && selection.range.collapsed ? selection.range : null;\n const { posContainer, posOffset } = this.state.pendingFormat;\n\n if (range && range.startContainer == posContainer && range.startOffset == posOffset) {\n result = true;\n }\n }\n\n return result;\n }\n}\n\n/**\n * @internal\n * Create a new instance of ContentModelFormatPlugin.\n * This is mostly for unit test\n */\nexport function createContentModelFormatPlugin(state: ContentModelFormatPluginState) {\n return new ContentModelFormatPlugin(state);\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import type { EditorPlugin } from 'roosterjs-editor-types';
2
+ /**
3
+ * Dummy plugin, just to skip original TypeInContainerPlugin's behavior
4
+ */
5
+ export declare class ContentModelTypeInContainerPlugin implements EditorPlugin {
6
+ /**
7
+ * Get name of this plugin
8
+ */
9
+ getName(): string;
10
+ /**
11
+ * The first method that editor will call to a plugin when editor is initializing.
12
+ * It will pass in the editor instance, plugin should take this chance to save the
13
+ * editor reference so that it can call to any editor method or format API later.
14
+ * @param editor The editor object
15
+ */
16
+ initialize(): void;
17
+ /**
18
+ * The last method that editor will call to a plugin before it is disposed.
19
+ * Plugin can take this chance to clear the reference to editor. After this method is
20
+ * called, plugin should not call to any editor method since it will result in error.
21
+ */
22
+ dispose(): void;
23
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Dummy plugin, just to skip original TypeInContainerPlugin's behavior
3
+ */
4
+ var ContentModelTypeInContainerPlugin = /** @class */ (function () {
5
+ function ContentModelTypeInContainerPlugin() {
6
+ }
7
+ /**
8
+ * Get name of this plugin
9
+ */
10
+ ContentModelTypeInContainerPlugin.prototype.getName = function () {
11
+ return 'ContentModelTypeInContainer';
12
+ };
13
+ /**
14
+ * The first method that editor will call to a plugin when editor is initializing.
15
+ * It will pass in the editor instance, plugin should take this chance to save the
16
+ * editor reference so that it can call to any editor method or format API later.
17
+ * @param editor The editor object
18
+ */
19
+ ContentModelTypeInContainerPlugin.prototype.initialize = function () { };
20
+ /**
21
+ * The last method that editor will call to a plugin before it is disposed.
22
+ * Plugin can take this chance to clear the reference to editor. After this method is
23
+ * called, plugin should not call to any editor method since it will result in error.
24
+ */
25
+ ContentModelTypeInContainerPlugin.prototype.dispose = function () { };
26
+ return ContentModelTypeInContainerPlugin;
27
+ }());
28
+ export { ContentModelTypeInContainerPlugin };
29
+ //# sourceMappingURL=ContentModelTypeInContainerPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentModelTypeInContainerPlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/ContentModelTypeInContainerPlugin.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH;IAAA;IAsBA,CAAC;IArBG;;OAEG;IACH,mDAAO,GAAP;QACI,OAAO,6BAA6B,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,sDAAU,GAAV,cAAc,CAAC;IAEf;;;;OAIG;IACH,mDAAO,GAAP,cAAW,CAAC;IAChB,wCAAC;AAAD,CAAC,AAtBD,IAsBC","sourcesContent":["import type { EditorPlugin } from 'roosterjs-editor-types';\n\n/**\n * Dummy plugin, just to skip original TypeInContainerPlugin's behavior\n */\nexport class ContentModelTypeInContainerPlugin implements EditorPlugin {\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelTypeInContainer';\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() {}\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}\n"]}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare function addRangeToSelection(doc: Document, range: Range): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export function addRangeToSelection(doc, range) {
5
+ var _a;
6
+ var selection = (_a = doc.defaultView) === null || _a === void 0 ? void 0 : _a.getSelection();
7
+ if (selection) {
8
+ selection.removeAllRanges();
9
+ selection.addRange(range);
10
+ }
11
+ }
12
+ //# sourceMappingURL=addRangeToSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addRangeToSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-core/lib/corePlugin/utils/addRangeToSelection.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAa,EAAE,KAAY;;IAC3D,IAAM,SAAS,GAAG,MAAA,GAAG,CAAC,WAAW,0CAAE,YAAY,EAAE,CAAC;IAElD,IAAI,SAAS,EAAE;QACX,SAAS,CAAC,eAAe,EAAE,CAAC;QAC5B,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;KAC7B;AACL,CAAC","sourcesContent":["/**\n * @internal\n */\nexport function addRangeToSelection(doc: Document, range: Range) {\n const selection = doc.defaultView?.getSelection();\n\n if (selection) {\n selection.removeAllRanges();\n selection.addRange(range);\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { IEditor } from 'roosterjs-editor-types';
2
+ import type { ContentModelSegmentFormat, IStandaloneEditor } from 'roosterjs-content-model-types';
3
+ /**
4
+ * @internal
5
+ * When necessary, set default format as current pending format so it will be applied when Input event is fired
6
+ * @param editor The Content Model Editor
7
+ * @param defaultFormat The default segment format to apply
8
+ */
9
+ export declare function applyDefaultFormat(editor: IStandaloneEditor & IEditor, defaultFormat: ContentModelSegmentFormat): void;