roosterjs-content-model-api 0.28.0 → 9.0.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 (293) hide show
  1. package/README.md +47 -37
  2. package/lib/index.d.ts +2 -0
  3. package/lib/index.js +6 -2
  4. package/lib/index.js.map +1 -1
  5. package/lib/modelApi/block/setModelAlignment.js +2 -2
  6. package/lib/modelApi/block/setModelAlignment.js.map +1 -1
  7. package/lib/modelApi/block/setModelDirection.js +5 -5
  8. package/lib/modelApi/block/setModelDirection.js.map +1 -1
  9. package/lib/modelApi/block/setModelIndentation.js +6 -7
  10. package/lib/modelApi/block/setModelIndentation.js.map +1 -1
  11. package/lib/modelApi/block/toggleModelBlockQuote.js +3 -4
  12. package/lib/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  13. package/lib/modelApi/common/clearModelFormat.js +6 -7
  14. package/lib/modelApi/common/clearModelFormat.js.map +1 -1
  15. package/lib/modelApi/common/reducedModelChildProcessor.d.ts +20 -0
  16. package/lib/modelApi/common/reducedModelChildProcessor.js +64 -0
  17. package/lib/modelApi/common/reducedModelChildProcessor.js.map +1 -0
  18. package/lib/modelApi/entity/insertEntityModel.d.ts +2 -2
  19. package/lib/modelApi/entity/insertEntityModel.js +19 -10
  20. package/lib/modelApi/entity/insertEntityModel.js.map +1 -1
  21. package/lib/modelApi/image/applyImageBorderFormat.js +1 -2
  22. package/lib/modelApi/image/applyImageBorderFormat.js.map +1 -1
  23. package/lib/modelApi/list/setListType.js +3 -4
  24. package/lib/modelApi/list/setListType.js.map +1 -1
  25. package/lib/modelApi/list/setModelListStartNumber.d.ts +7 -0
  26. package/lib/modelApi/list/setModelListStartNumber.js +22 -0
  27. package/lib/modelApi/list/setModelListStartNumber.js.map +1 -0
  28. package/lib/modelApi/list/setModelListStyle.d.ts +7 -0
  29. package/lib/modelApi/list/setModelListStyle.js +26 -0
  30. package/lib/modelApi/list/setModelListStyle.js.map +1 -0
  31. package/lib/modelApi/selection/adjustSegmentSelection.js +3 -3
  32. package/lib/modelApi/selection/adjustSegmentSelection.js.map +1 -1
  33. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js +1 -2
  34. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -1
  35. package/lib/modelApi/selection/adjustWordSelection.js +3 -4
  36. package/lib/modelApi/selection/adjustWordSelection.js.map +1 -1
  37. package/lib/modelApi/table/alignTableCell.js +3 -3
  38. package/lib/modelApi/table/alignTableCell.js.map +1 -1
  39. package/lib/modelApi/table/clearSelectedCells.js +2 -2
  40. package/lib/modelApi/table/clearSelectedCells.js.map +1 -1
  41. package/lib/modelApi/table/deleteTableColumn.js +2 -2
  42. package/lib/modelApi/table/deleteTableColumn.js.map +1 -1
  43. package/lib/modelApi/table/deleteTableRow.js +2 -2
  44. package/lib/modelApi/table/deleteTableRow.js.map +1 -1
  45. package/lib/modelApi/table/insertTableColumn.js +1 -2
  46. package/lib/modelApi/table/insertTableColumn.js.map +1 -1
  47. package/lib/modelApi/table/insertTableRow.js +1 -2
  48. package/lib/modelApi/table/insertTableRow.js.map +1 -1
  49. package/lib/modelApi/table/mergeTableCells.js +2 -2
  50. package/lib/modelApi/table/mergeTableCells.js.map +1 -1
  51. package/lib/modelApi/table/mergeTableColumn.js +2 -2
  52. package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
  53. package/lib/modelApi/table/mergeTableRow.js +2 -2
  54. package/lib/modelApi/table/mergeTableRow.js.map +1 -1
  55. package/lib/modelApi/table/splitTableCellHorizontally.js +1 -2
  56. package/lib/modelApi/table/splitTableCellHorizontally.js.map +1 -1
  57. package/lib/modelApi/table/splitTableCellVertically.js +1 -2
  58. package/lib/modelApi/table/splitTableCellVertically.js.map +1 -1
  59. package/lib/publicApi/entity/insertEntity.d.ts +3 -3
  60. package/lib/publicApi/entity/insertEntity.js +17 -11
  61. package/lib/publicApi/entity/insertEntity.js.map +1 -1
  62. package/lib/publicApi/format/getFormatState.js +11 -3
  63. package/lib/publicApi/format/getFormatState.js.map +1 -1
  64. package/lib/publicApi/image/changeImage.js +3 -3
  65. package/lib/publicApi/image/changeImage.js.map +1 -1
  66. package/lib/publicApi/image/insertImage.js +2 -3
  67. package/lib/publicApi/image/insertImage.js.map +1 -1
  68. package/lib/publicApi/link/adjustLinkSelection.js +3 -3
  69. package/lib/publicApi/link/adjustLinkSelection.js.map +1 -1
  70. package/lib/publicApi/link/insertLink.js +3 -4
  71. package/lib/publicApi/link/insertLink.js.map +1 -1
  72. package/lib/publicApi/link/removeLink.js +2 -2
  73. package/lib/publicApi/link/removeLink.js.map +1 -1
  74. package/lib/publicApi/list/setListStartNumber.js +2 -10
  75. package/lib/publicApi/list/setListStartNumber.js.map +1 -1
  76. package/lib/publicApi/list/setListStyle.js +2 -17
  77. package/lib/publicApi/list/setListStyle.js.map +1 -1
  78. package/lib/publicApi/segment/setBackgroundColor.js +1 -2
  79. package/lib/publicApi/segment/setBackgroundColor.js.map +1 -1
  80. package/lib/publicApi/segment/toggleBold.js +2 -2
  81. package/lib/publicApi/segment/toggleBold.js.map +1 -1
  82. package/lib/publicApi/table/applyTableBorderFormat.js +4 -5
  83. package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
  84. package/lib/publicApi/table/formatTable.js +4 -4
  85. package/lib/publicApi/table/formatTable.js.map +1 -1
  86. package/lib/publicApi/table/insertTable.js +6 -7
  87. package/lib/publicApi/table/insertTable.js.map +1 -1
  88. package/lib/publicApi/table/setTableCellShade.js +5 -5
  89. package/lib/publicApi/table/setTableCellShade.js.map +1 -1
  90. package/lib/publicApi/utils/formatInsertPointWithContentModel.d.ts +5 -0
  91. package/lib/publicApi/utils/formatInsertPointWithContentModel.js +127 -0
  92. package/lib/publicApi/utils/formatInsertPointWithContentModel.js.map +1 -0
  93. package/lib/publicApi/utils/formatParagraphWithContentModel.js +2 -2
  94. package/lib/publicApi/utils/formatParagraphWithContentModel.js.map +1 -1
  95. package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -2
  96. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  97. package/lib/publicApi/utils/formatTableWithContentModel.js +5 -6
  98. package/lib/publicApi/utils/formatTableWithContentModel.js.map +1 -1
  99. package/lib-amd/index.d.ts +2 -0
  100. package/lib-amd/index.js +4 -2
  101. package/lib-amd/index.js.map +1 -1
  102. package/lib-amd/modelApi/block/setModelAlignment.js +2 -2
  103. package/lib-amd/modelApi/block/setModelAlignment.js.map +1 -1
  104. package/lib-amd/modelApi/block/setModelDirection.js +5 -5
  105. package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
  106. package/lib-amd/modelApi/block/setModelIndentation.js +6 -6
  107. package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
  108. package/lib-amd/modelApi/block/toggleModelBlockQuote.js +3 -3
  109. package/lib-amd/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  110. package/lib-amd/modelApi/common/clearModelFormat.js +7 -7
  111. package/lib-amd/modelApi/common/clearModelFormat.js.map +1 -1
  112. package/lib-amd/modelApi/common/reducedModelChildProcessor.d.ts +20 -0
  113. package/lib-amd/modelApi/common/reducedModelChildProcessor.js +64 -0
  114. package/lib-amd/modelApi/common/reducedModelChildProcessor.js.map +1 -0
  115. package/lib-amd/modelApi/entity/insertEntityModel.d.ts +2 -2
  116. package/lib-amd/modelApi/entity/insertEntityModel.js +20 -10
  117. package/lib-amd/modelApi/entity/insertEntityModel.js.map +1 -1
  118. package/lib-amd/modelApi/image/applyImageBorderFormat.js +2 -2
  119. package/lib-amd/modelApi/image/applyImageBorderFormat.js.map +1 -1
  120. package/lib-amd/modelApi/list/setListType.js +4 -4
  121. package/lib-amd/modelApi/list/setListType.js.map +1 -1
  122. package/lib-amd/modelApi/list/setModelListStartNumber.d.ts +7 -0
  123. package/lib-amd/modelApi/list/setModelListStartNumber.js +23 -0
  124. package/lib-amd/modelApi/list/setModelListStartNumber.js.map +1 -0
  125. package/lib-amd/modelApi/list/setModelListStyle.d.ts +7 -0
  126. package/lib-amd/modelApi/list/setModelListStyle.js +26 -0
  127. package/lib-amd/modelApi/list/setModelListStyle.js.map +1 -0
  128. package/lib-amd/modelApi/selection/adjustSegmentSelection.js +3 -3
  129. package/lib-amd/modelApi/selection/adjustSegmentSelection.js.map +1 -1
  130. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js +2 -2
  131. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -1
  132. package/lib-amd/modelApi/selection/adjustWordSelection.js +4 -4
  133. package/lib-amd/modelApi/selection/adjustWordSelection.js.map +1 -1
  134. package/lib-amd/modelApi/table/alignTableCell.js +3 -3
  135. package/lib-amd/modelApi/table/alignTableCell.js.map +1 -1
  136. package/lib-amd/modelApi/table/clearSelectedCells.js +2 -2
  137. package/lib-amd/modelApi/table/clearSelectedCells.js.map +1 -1
  138. package/lib-amd/modelApi/table/deleteTableColumn.js +2 -2
  139. package/lib-amd/modelApi/table/deleteTableColumn.js.map +1 -1
  140. package/lib-amd/modelApi/table/deleteTableRow.js +2 -2
  141. package/lib-amd/modelApi/table/deleteTableRow.js.map +1 -1
  142. package/lib-amd/modelApi/table/insertTableColumn.js +2 -2
  143. package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
  144. package/lib-amd/modelApi/table/insertTableRow.js +2 -2
  145. package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
  146. package/lib-amd/modelApi/table/mergeTableCells.js +2 -2
  147. package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
  148. package/lib-amd/modelApi/table/mergeTableColumn.js +2 -2
  149. package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
  150. package/lib-amd/modelApi/table/mergeTableRow.js +2 -2
  151. package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
  152. package/lib-amd/modelApi/table/splitTableCellHorizontally.js +2 -2
  153. package/lib-amd/modelApi/table/splitTableCellHorizontally.js.map +1 -1
  154. package/lib-amd/modelApi/table/splitTableCellVertically.js +2 -2
  155. package/lib-amd/modelApi/table/splitTableCellVertically.js.map +1 -1
  156. package/lib-amd/publicApi/entity/insertEntity.d.ts +3 -3
  157. package/lib-amd/publicApi/entity/insertEntity.js +17 -11
  158. package/lib-amd/publicApi/entity/insertEntity.js.map +1 -1
  159. package/lib-amd/publicApi/format/getFormatState.js +10 -3
  160. package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
  161. package/lib-amd/publicApi/image/changeImage.js +3 -3
  162. package/lib-amd/publicApi/image/changeImage.js.map +1 -1
  163. package/lib-amd/publicApi/image/insertImage.js +3 -3
  164. package/lib-amd/publicApi/image/insertImage.js.map +1 -1
  165. package/lib-amd/publicApi/link/adjustLinkSelection.js +3 -3
  166. package/lib-amd/publicApi/link/adjustLinkSelection.js.map +1 -1
  167. package/lib-amd/publicApi/link/insertLink.js +4 -4
  168. package/lib-amd/publicApi/link/insertLink.js.map +1 -1
  169. package/lib-amd/publicApi/link/removeLink.js +2 -2
  170. package/lib-amd/publicApi/link/removeLink.js.map +1 -1
  171. package/lib-amd/publicApi/list/setListStartNumber.js +2 -10
  172. package/lib-amd/publicApi/list/setListStartNumber.js.map +1 -1
  173. package/lib-amd/publicApi/list/setListStyle.js +2 -16
  174. package/lib-amd/publicApi/list/setListStyle.js.map +1 -1
  175. package/lib-amd/publicApi/segment/setBackgroundColor.js +2 -2
  176. package/lib-amd/publicApi/segment/setBackgroundColor.js.map +1 -1
  177. package/lib-amd/publicApi/segment/toggleBold.js +2 -2
  178. package/lib-amd/publicApi/segment/toggleBold.js.map +1 -1
  179. package/lib-amd/publicApi/table/applyTableBorderFormat.js +5 -5
  180. package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
  181. package/lib-amd/publicApi/table/formatTable.js +4 -4
  182. package/lib-amd/publicApi/table/formatTable.js.map +1 -1
  183. package/lib-amd/publicApi/table/insertTable.js +6 -6
  184. package/lib-amd/publicApi/table/insertTable.js.map +1 -1
  185. package/lib-amd/publicApi/table/setTableCellShade.js +5 -5
  186. package/lib-amd/publicApi/table/setTableCellShade.js.map +1 -1
  187. package/lib-amd/publicApi/utils/formatInsertPointWithContentModel.d.ts +5 -0
  188. package/lib-amd/publicApi/utils/formatInsertPointWithContentModel.js +127 -0
  189. package/lib-amd/publicApi/utils/formatInsertPointWithContentModel.js.map +1 -0
  190. package/lib-amd/publicApi/utils/formatParagraphWithContentModel.js +2 -2
  191. package/lib-amd/publicApi/utils/formatParagraphWithContentModel.js.map +1 -1
  192. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -2
  193. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  194. package/lib-amd/publicApi/utils/formatTableWithContentModel.js +6 -6
  195. package/lib-amd/publicApi/utils/formatTableWithContentModel.js.map +1 -1
  196. package/lib-mjs/index.d.ts +2 -0
  197. package/lib-mjs/index.js +2 -0
  198. package/lib-mjs/index.js.map +1 -1
  199. package/lib-mjs/modelApi/block/setModelAlignment.js +1 -1
  200. package/lib-mjs/modelApi/block/setModelAlignment.js.map +1 -1
  201. package/lib-mjs/modelApi/block/setModelDirection.js +1 -1
  202. package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
  203. package/lib-mjs/modelApi/block/setModelIndentation.js +1 -2
  204. package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
  205. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js +1 -2
  206. package/lib-mjs/modelApi/block/toggleModelBlockQuote.js.map +1 -1
  207. package/lib-mjs/modelApi/common/clearModelFormat.js +1 -2
  208. package/lib-mjs/modelApi/common/clearModelFormat.js.map +1 -1
  209. package/lib-mjs/modelApi/common/reducedModelChildProcessor.d.ts +20 -0
  210. package/lib-mjs/modelApi/common/reducedModelChildProcessor.js +60 -0
  211. package/lib-mjs/modelApi/common/reducedModelChildProcessor.js.map +1 -0
  212. package/lib-mjs/modelApi/entity/insertEntityModel.d.ts +2 -2
  213. package/lib-mjs/modelApi/entity/insertEntityModel.js +18 -9
  214. package/lib-mjs/modelApi/entity/insertEntityModel.js.map +1 -1
  215. package/lib-mjs/modelApi/image/applyImageBorderFormat.js +1 -2
  216. package/lib-mjs/modelApi/image/applyImageBorderFormat.js.map +1 -1
  217. package/lib-mjs/modelApi/list/setListType.js +1 -2
  218. package/lib-mjs/modelApi/list/setListType.js.map +1 -1
  219. package/lib-mjs/modelApi/list/setModelListStartNumber.d.ts +7 -0
  220. package/lib-mjs/modelApi/list/setModelListStartNumber.js +18 -0
  221. package/lib-mjs/modelApi/list/setModelListStartNumber.js.map +1 -0
  222. package/lib-mjs/modelApi/list/setModelListStyle.d.ts +7 -0
  223. package/lib-mjs/modelApi/list/setModelListStyle.js +22 -0
  224. package/lib-mjs/modelApi/list/setModelListStyle.js.map +1 -0
  225. package/lib-mjs/modelApi/selection/adjustSegmentSelection.js +1 -1
  226. package/lib-mjs/modelApi/selection/adjustSegmentSelection.js.map +1 -1
  227. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js +1 -2
  228. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -1
  229. package/lib-mjs/modelApi/selection/adjustWordSelection.js +1 -2
  230. package/lib-mjs/modelApi/selection/adjustWordSelection.js.map +1 -1
  231. package/lib-mjs/modelApi/table/alignTableCell.js +1 -1
  232. package/lib-mjs/modelApi/table/alignTableCell.js.map +1 -1
  233. package/lib-mjs/modelApi/table/clearSelectedCells.js +1 -1
  234. package/lib-mjs/modelApi/table/clearSelectedCells.js.map +1 -1
  235. package/lib-mjs/modelApi/table/deleteTableColumn.js +1 -1
  236. package/lib-mjs/modelApi/table/deleteTableColumn.js.map +1 -1
  237. package/lib-mjs/modelApi/table/deleteTableRow.js +1 -1
  238. package/lib-mjs/modelApi/table/deleteTableRow.js.map +1 -1
  239. package/lib-mjs/modelApi/table/insertTableColumn.js +1 -2
  240. package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
  241. package/lib-mjs/modelApi/table/insertTableRow.js +1 -2
  242. package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
  243. package/lib-mjs/modelApi/table/mergeTableCells.js +1 -1
  244. package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
  245. package/lib-mjs/modelApi/table/mergeTableColumn.js +1 -1
  246. package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
  247. package/lib-mjs/modelApi/table/mergeTableRow.js +1 -1
  248. package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
  249. package/lib-mjs/modelApi/table/splitTableCellHorizontally.js +1 -2
  250. package/lib-mjs/modelApi/table/splitTableCellHorizontally.js.map +1 -1
  251. package/lib-mjs/modelApi/table/splitTableCellVertically.js +1 -2
  252. package/lib-mjs/modelApi/table/splitTableCellVertically.js.map +1 -1
  253. package/lib-mjs/publicApi/entity/insertEntity.d.ts +3 -3
  254. package/lib-mjs/publicApi/entity/insertEntity.js +17 -11
  255. package/lib-mjs/publicApi/entity/insertEntity.js.map +1 -1
  256. package/lib-mjs/publicApi/format/getFormatState.js +11 -3
  257. package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
  258. package/lib-mjs/publicApi/image/changeImage.js +1 -1
  259. package/lib-mjs/publicApi/image/changeImage.js.map +1 -1
  260. package/lib-mjs/publicApi/image/insertImage.js +1 -2
  261. package/lib-mjs/publicApi/image/insertImage.js.map +1 -1
  262. package/lib-mjs/publicApi/link/adjustLinkSelection.js +1 -1
  263. package/lib-mjs/publicApi/link/adjustLinkSelection.js.map +1 -1
  264. package/lib-mjs/publicApi/link/insertLink.js +1 -2
  265. package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
  266. package/lib-mjs/publicApi/link/removeLink.js +1 -1
  267. package/lib-mjs/publicApi/link/removeLink.js.map +1 -1
  268. package/lib-mjs/publicApi/list/setListStartNumber.js +2 -10
  269. package/lib-mjs/publicApi/list/setListStartNumber.js.map +1 -1
  270. package/lib-mjs/publicApi/list/setListStyle.js +2 -17
  271. package/lib-mjs/publicApi/list/setListStyle.js.map +1 -1
  272. package/lib-mjs/publicApi/segment/setBackgroundColor.js +1 -2
  273. package/lib-mjs/publicApi/segment/setBackgroundColor.js.map +1 -1
  274. package/lib-mjs/publicApi/segment/toggleBold.js +1 -1
  275. package/lib-mjs/publicApi/segment/toggleBold.js.map +1 -1
  276. package/lib-mjs/publicApi/table/applyTableBorderFormat.js +1 -2
  277. package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
  278. package/lib-mjs/publicApi/table/formatTable.js +1 -1
  279. package/lib-mjs/publicApi/table/formatTable.js.map +1 -1
  280. package/lib-mjs/publicApi/table/insertTable.js +1 -2
  281. package/lib-mjs/publicApi/table/insertTable.js.map +1 -1
  282. package/lib-mjs/publicApi/table/setTableCellShade.js +1 -1
  283. package/lib-mjs/publicApi/table/setTableCellShade.js.map +1 -1
  284. package/lib-mjs/publicApi/utils/formatInsertPointWithContentModel.d.ts +5 -0
  285. package/lib-mjs/publicApi/utils/formatInsertPointWithContentModel.js +123 -0
  286. package/lib-mjs/publicApi/utils/formatInsertPointWithContentModel.js.map +1 -0
  287. package/lib-mjs/publicApi/utils/formatParagraphWithContentModel.js +1 -1
  288. package/lib-mjs/publicApi/utils/formatParagraphWithContentModel.js.map +1 -1
  289. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +1 -1
  290. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  291. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js +1 -2
  292. package/lib-mjs/publicApi/utils/formatTableWithContentModel.js.map +1 -1
  293. package/package.json +4 -5
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "roosterjs-content-model-dom", "../list/findListItemsInSameThread", "roosterjs-content-model-core"], function (require, exports, roosterjs_content_model_dom_1, findListItemsInSameThread_1, roosterjs_content_model_core_1) {
1
+ define(["require", "exports", "../list/findListItemsInSameThread", "roosterjs-content-model-dom"], function (require, exports, findListItemsInSameThread_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setModelIndentation = void 0;
@@ -11,12 +11,12 @@ define(["require", "exports", "roosterjs-content-model-dom", "../list/findListIt
11
11
  */
12
12
  function setModelIndentation(model, indentation, length) {
13
13
  if (length === void 0) { length = IndentStepInPixel; }
14
- var paragraphOrListItem = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
14
+ var paragraphOrListItem = (0, roosterjs_content_model_dom_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
15
15
  var isIndent = indentation == 'indent';
16
16
  var modifiedBlocks = [];
17
17
  paragraphOrListItem.forEach(function (_a) {
18
18
  var block = _a.block, parent = _a.parent, path = _a.path;
19
- if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
19
+ if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem')) {
20
20
  var thread = (0, findListItemsInSameThread_1.findListItemsInSameThread)(model, block);
21
21
  var firstItem = thread[0];
22
22
  //if the first item is selected and has only one level, we should add margin to the whole list
@@ -44,7 +44,7 @@ define(["require", "exports", "roosterjs-content-model-dom", "../list/findListIt
44
44
  if (isIndent) {
45
45
  var lastLevel = block.levels[block.levels.length - 1];
46
46
  var newLevel = (0, roosterjs_content_model_dom_1.createListLevel)((lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.listType) || 'UL', lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.format);
47
- (0, roosterjs_content_model_core_1.updateListMetadata)(newLevel, function (metadata) {
47
+ (0, roosterjs_content_model_dom_1.updateListMetadata)(newLevel, function (metadata) {
48
48
  metadata = metadata || {};
49
49
  metadata.applyListStyleFromLevel = true;
50
50
  return metadata;
@@ -105,13 +105,13 @@ define(["require", "exports", "roosterjs-content-model-dom", "../list/findListIt
105
105
  var listIndex = parent.blocks.indexOf(listItem);
106
106
  for (var i = listIndex - 1; i >= 0; i--) {
107
107
  var block = parent.blocks[i];
108
- if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem') &&
108
+ if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem') &&
109
109
  block.levels.length == 1 &&
110
110
  isSelected(block)) {
111
111
  var firstItem = (0, findListItemsInSameThread_1.findListItemsInSameThread)(model, block)[0];
112
112
  return isSelected(firstItem);
113
113
  }
114
- if (!(0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
114
+ if (!(0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem')) {
115
115
  return false;
116
116
  }
117
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAiBA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,WAAiC,EACjC,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAElC,IAAM,mBAAmB,GAAG,IAAA,mDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QACF,IAAM,QAAQ,GAAG,WAAW,IAAI,QAAQ,CAAC;QACzC,IAAM,cAAc,GAAwB,EAAE,CAAC;QAE/C,mBAAmB,CAAC,OAAO,CAAC,UAAC,EAAuB;gBAArB,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA;YAC9C,IAAI,IAAA,iDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,MAAM,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACvD,IAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC5B,8FAA8F;gBAC9F,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,C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AAC,EAAE;gBAC9D,OAAO,KAAK,CAAC;aAChB;SACJ;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,SAAS,oBAAoB,CACzB,MAA+B,EAC/B,QAAiB,EACjB,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAE1B,IAAA,UAAU,GAA6B,MAAM,WAAnC,EAAE,WAAW,GAAgB,MAAM,YAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;QACtD,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;QACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnE;QAED,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,oDAAoD;YACpD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { createListLevel, parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n getOperationalBlocks,\n isBlockGroupOfType,\n updateListMetadata,\n} from 'roosterjs-content-model-core';\n\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n }\n } else if (block) {\n let currentBlock: ContentModelBlock = block;\n let currentParent: ContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = currentBlock;\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n delete currentParent.cachedElement;\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ContentModelDocument,\n listItem: ContentModelListItem,\n parent: ContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: ContentModelBlockFormat,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
1
+ {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAiBA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,WAAiC,EACjC,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAElC,IAAM,mBAAmB,GAAG,IAAA,kDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QACF,IAAM,QAAQ,GAAG,WAAW,IAAI,QAAQ,CAAC;QACzC,IAAM,cAAc,GAAwB,EAAE,CAAC;QAE/C,mBAAmB,CAAC,OAAO,CAAC,UAAC,EAAuB;gBAArB,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA;YAC9C,IAAI,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,MAAM,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACvD,IAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC5B,8FAA8F;gBAC9F,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;oBACvD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBACtB,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;oBACjB,IAAA,UAAU,GAAkB,MAAM,WAAxB,EAAE,WAAW,GAAK,MAAM,YAAX,CAAY;oBAC3C,IAAM,QAAQ,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAChE,IAAM,KAAK,GAAG,MAAM,CAAC,SAAS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AAC;QACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnE;QAED,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,oDAAoD;YACpD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n }\n } else if (block) {\n let currentBlock: ContentModelBlock = block;\n let currentParent: ContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = currentBlock;\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n delete currentParent.cachedElement;\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ContentModelDocument,\n listItem: ContentModelListItem,\n parent: ContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: ContentModelBlockFormat,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-model-core", "../common/wrapBlock"], function (require, exports, roosterjs_content_model_dom_1, roosterjs_content_model_core_1, wrapBlock_1) {
1
+ define(["require", "exports", "../common/wrapBlock", "roosterjs-content-model-dom"], function (require, exports, wrapBlock_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.toggleModelBlockQuote = void 0;
@@ -6,7 +6,7 @@ define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-
6
6
  * @internal
7
7
  */
8
8
  function toggleModelBlockQuote(model, formatLtr, formatRtl) {
9
- var paragraphOfQuote = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);
9
+ var paragraphOfQuote = (0, roosterjs_content_model_dom_1.getOperationalBlocks)(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);
10
10
  if (areAllBlockQuotes(paragraphOfQuote)) {
11
11
  // All selections are already in quote, we need to unquote them
12
12
  paragraphOfQuote.forEach(function (_a) {
@@ -40,7 +40,7 @@ define(["require", "exports", "roosterjs-content-model-dom", "roosterjs-content-
40
40
  return isQuote(target) && (0, roosterjs_content_model_dom_1.areSameFormats)(format, target.format);
41
41
  }
42
42
  function isQuote(block) {
43
- return ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'FormatContainer') &&
43
+ return ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'FormatContainer') &&
44
44
  block.tagName == 'blockquote');
45
45
  }
46
46
  function areAllBlockQuotes(blockAndParents) {
@@ -1 +1 @@
1
- {"version":3,"file":"toggleModelBlockQuote.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/toggleModelBlockQuote.ts"],"names":[],"mappings":";;;;IAcA;;OAEG;IACH,SAAgB,qBAAqB,CACjC,KAA2B,EAC3B,SAA4C,EAC5C,SAA4C;QAE5C,IAAM,gBAAgB,GAAG,IAAA,mDAAoB,EAE3C,KAAK,EAAE,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7E,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,EAAE;YACrC,+DAA+D;YAC/D,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA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AC;YACzE,KAAK,CAAC,OAAO,IAAI,YAAY,CAChC,CAAC;IACN,CAAC;IAED,SAAS,iBAAiB,CACtB,eAAwF;QAMxF,OAAO,eAAe,CAAC,KAAK,CAAC,UAAA,cAAc,IAAI,OAAA,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAA7B,CAA6B,CAAC,CAAC;IAClF,CAAC","sourcesContent":["import { areSameFormats, createFormatContainer, unwrapBlock } from 'roosterjs-content-model-dom';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport { wrapBlockStep1, wrapBlockStep2 } from '../common/wrapBlock';\nimport type { OperationalBlocks } from 'roosterjs-content-model-core';\nimport type { WrapBlockStep1Result } from '../common/wrapBlock';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function toggleModelBlockQuote(\n model: ContentModelDocument,\n formatLtr: ContentModelFormatContainerFormat,\n formatRtl: ContentModelFormatContainerFormat\n): boolean {\n const paragraphOfQuote = getOperationalBlocks<\n ContentModelFormatContainer | ContentModelListItem\n >(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);\n\n if (areAllBlockQuotes(paragraphOfQuote)) {\n // All selections are already in quote, we need to unquote them\n paragraphOfQuote.forEach(({ block, parent }) => {\n unwrapBlock(parent, block);\n });\n } else {\n const step1Results: WrapBlockStep1Result<ContentModelFormatContainer>[] = [];\n const creator = (isRtl: boolean) =>\n createFormatContainer('blockquote', isRtl ? formatRtl : formatLtr);\n const canMerge = (\n isRtl: boolean,\n target: ContentModelBlock,\n current?: ContentModelFormatContainer\n ): target is ContentModelFormatContainer =>\n canMergeQuote(target, current?.format || (isRtl ? formatRtl : formatLtr));\n\n paragraphOfQuote.forEach(({ block, parent }) => {\n if (isQuote(block)) {\n // Already in quote, no op\n } else {\n wrapBlockStep1(step1Results, parent, block, creator, canMerge);\n }\n });\n\n wrapBlockStep2(step1Results, canMerge);\n }\n\n return paragraphOfQuote.length > 0;\n}\n\nfunction canMergeQuote(\n target: ContentModelBlock,\n format: ContentModelFormatContainerFormat\n): target is ContentModelFormatContainer {\n return isQuote(target) && areSameFormats(format, target.format);\n}\n\nfunction isQuote(block: ContentModelBlock): block is ContentModelFormatContainer {\n return (\n isBlockGroupOfType<ContentModelFormatContainer>(block, 'FormatContainer') &&\n block.tagName == 'blockquote'\n );\n}\n\nfunction areAllBlockQuotes(\n blockAndParents: OperationalBlocks<ContentModelFormatContainer | ContentModelListItem>[]\n): blockAndParents is {\n block: ContentModelFormatContainer;\n parent: ContentModelBlockGroup;\n path: ContentModelBlockGroup[];\n}[] {\n return blockAndParents.every(blockAndParent => isQuote(blockAndParent.block));\n}\n"]}
1
+ {"version":3,"file":"toggleModelBlockQuote.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/toggleModelBlockQuote.ts"],"names":[],"mappings":";;;;IAmBA;;OAEG;IACH,SAAgB,qBAAqB,CACjC,KAA2B,EAC3B,SAA4C,EAC5C,SAA4C;QAE5C,IAAM,gBAAgB,GAAG,IAAA,kDAAoB,EAE3C,KAAK,EAAE,CAAC,iBAAiB,EAAE,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAE7E,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,EAAE;YACrC,+DAA+D;YAC/D,gBAAgB,CAAC,OAAO,CAAC,UAAC,EAAiB;oBAAf,KAAK,WAAA,EAAE,MAAM,YAAA;gBACrC,IAAA,yCAAW,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;SACN;aAAM;YACH,IAAM,cAAY,GAAwD,EAAE,CAAC;YAC7E,IAAM,SAAO,GAAG,UAAC,KAAc;gBAC3B,OAAA,IAAA,mDAAqB,EAAC,YAAY,EAAE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sourcesContent":["import { wrapBlockStep1, wrapBlockStep2 } from '../common/wrapBlock';\nimport {\n getOperationalBlocks,\n isBlockGroupOfType,\n areSameFormats,\n createFormatContainer,\n unwrapBlock,\n} from 'roosterjs-content-model-dom';\nimport type { WrapBlockStep1Result } from '../common/wrapBlock';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelFormatContainerFormat,\n ContentModelListItem,\n OperationalBlocks,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function toggleModelBlockQuote(\n model: ContentModelDocument,\n formatLtr: ContentModelFormatContainerFormat,\n formatRtl: ContentModelFormatContainerFormat\n): boolean {\n const paragraphOfQuote = getOperationalBlocks<\n ContentModelFormatContainer | ContentModelListItem\n >(model, ['FormatContainer', 'ListItem'], ['TableCell'], true /*deepFirst*/);\n\n if (areAllBlockQuotes(paragraphOfQuote)) {\n // All selections are already in quote, we need to unquote them\n paragraphOfQuote.forEach(({ block, parent }) => {\n unwrapBlock(parent, block);\n });\n } else {\n const step1Results: WrapBlockStep1Result<ContentModelFormatContainer>[] = [];\n const creator = (isRtl: boolean) =>\n createFormatContainer('blockquote', isRtl ? formatRtl : formatLtr);\n const canMerge = (\n isRtl: boolean,\n target: ContentModelBlock,\n current?: ContentModelFormatContainer\n ): target is ContentModelFormatContainer =>\n canMergeQuote(target, current?.format || (isRtl ? formatRtl : formatLtr));\n\n paragraphOfQuote.forEach(({ block, parent }) => {\n if (isQuote(block)) {\n // Already in quote, no op\n } else {\n wrapBlockStep1(step1Results, parent, block, creator, canMerge);\n }\n });\n\n wrapBlockStep2(step1Results, canMerge);\n }\n\n return paragraphOfQuote.length > 0;\n}\n\nfunction canMergeQuote(\n target: ContentModelBlock,\n format: ContentModelFormatContainerFormat\n): target is ContentModelFormatContainer {\n return isQuote(target) && areSameFormats(format, target.format);\n}\n\nfunction isQuote(block: ContentModelBlock): block is ContentModelFormatContainer {\n return (\n isBlockGroupOfType<ContentModelFormatContainer>(block, 'FormatContainer') &&\n block.tagName == 'blockquote'\n );\n}\n\nfunction areAllBlockQuotes(\n blockAndParents: OperationalBlocks<ContentModelFormatContainer | ContentModelListItem>[]\n): blockAndParents is {\n block: ContentModelFormatContainer;\n parent: ContentModelBlockGroup;\n path: ContentModelBlockGroup[];\n}[] {\n return blockAndParents.every(blockAndParent => isQuote(blockAndParent.block));\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, tslib_1, adjustWordSelection_1, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
1
+ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roosterjs-content-model-dom"], function (require, exports, tslib_1, adjustWordSelection_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.clearModelFormat = void 0;
@@ -6,7 +6,7 @@ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roos
6
6
  * @internal
7
7
  */
8
8
  function clearModelFormat(model, blocksToClear, segmentsToClear, tablesToClear) {
9
- (0, roosterjs_content_model_core_1.iterateSelections)(model, function (path, tableContext, block, segments) {
9
+ (0, roosterjs_content_model_dom_1.iterateSelections)(model, function (path, tableContext, block, segments) {
10
10
  if (segments) {
11
11
  segmentsToClear.push.apply(segmentsToClear, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(segments), false));
12
12
  }
@@ -54,9 +54,9 @@ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roos
54
54
  useBorderBox: table.format.useBorderBox,
55
55
  borderCollapse: table.format.borderCollapse,
56
56
  };
57
- (0, roosterjs_content_model_core_1.updateTableMetadata)(table, function () { return null; });
57
+ (0, roosterjs_content_model_dom_1.updateTableMetadata)(table, function () { return null; });
58
58
  }
59
- (0, roosterjs_content_model_core_1.applyTableFormat)(table, undefined /*newFormat*/, true);
59
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, undefined /*newFormat*/, true);
60
60
  });
61
61
  }
62
62
  function clearSegmentsFormat(segmentsToClear, defaultSegmentFormat) {
@@ -73,7 +73,7 @@ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roos
73
73
  var table_1 = tableContext.table, colIndex = tableContext.colIndex, rowIndex = tableContext.rowIndex, isWholeTableSelected = tableContext.isWholeTableSelected;
74
74
  var cell = table_1.rows[rowIndex].cells[colIndex];
75
75
  if (cell.isSelected) {
76
- (0, roosterjs_content_model_core_1.updateTableCellMetadata)(cell, function () { return null; });
76
+ (0, roosterjs_content_model_dom_1.updateTableCellMetadata)(cell, function () { return null; });
77
77
  cell.isHeader = false;
78
78
  cell.format = {
79
79
  useBorderBox: cell.format.useBorderBox,
@@ -85,7 +85,7 @@ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roos
85
85
  }
86
86
  }
87
87
  function clearContainerFormat(path, block) {
88
- var containerPathIndex = (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['FormatContainer'], ['TableCell']);
88
+ var containerPathIndex = (0, roosterjs_content_model_dom_1.getClosestAncestorBlockGroupIndex)(path, ['FormatContainer'], ['TableCell']);
89
89
  if (containerPathIndex >= 0 && containerPathIndex < path.length - 1) {
90
90
  var container = path[containerPathIndex];
91
91
  var containerIndex = path[containerPathIndex + 1].blocks.indexOf(container);
@@ -99,7 +99,7 @@ define(["require", "exports", "tslib", "../selection/adjustWordSelection", "roos
99
99
  }
100
100
  }
101
101
  function clearListFormat(path) {
102
- var listItem = path[(0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], ['TableCell'])];
102
+ var listItem = path[(0, roosterjs_content_model_dom_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], ['TableCell'])];
103
103
  if (listItem) {
104
104
  listItem.levels = [];
105
105
  }
@@ -1 +1 @@
1
- {"version":3,"file":"clearModelFormat.js","sourceRoot":"","sources":["../../../../../packages/roos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;YAE5C,IAAI,KAAK,IAAI,CAAC,EAAE;gBACZ,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;aACnC;SACJ;aAAM,IAAI,KAAK,CAAC,SAAS,IAAI,WAAW,EAAE;YACvC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC,SAAS,CAAC;SAC1B;IACL,CAAC;IAED,SAAS,6BAA6B,CAAC,KAAwB;QAC3D,IAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,IAAI,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,EAAZ,CAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEhG,OAAO,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,CAAC;IAChF,CAAC;IAED,SAAS,oBAAoB,CAAC,KAAwB;QAClD,OAAO,CACF,KAAoB,CAAC,UAAU;YAChC,CAAC,KAAK,CAAC,SAAS,IAAI,WAAW,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,UAAU,EAAZ,CAAY,CAAC,CAAC,CAC9E,CAAC;IACN,CAAC","sourcesContent":["import { adjustWordSelection } from '../selection/adjustWordSelection';\nimport { createFormatContainer } from 'roosterjs-content-model-dom';\nimport {\n iterateSelections,\n applyTableFormat,\n getClosestAncestorBlockGroupIndex,\n updateTableCellMetadata,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelListItem,\n ContentModelSegment,\n ContentModelSegmentFormat,\n ContentModelTable,\n Selectable,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function clearModelFormat(\n model: ContentModelDocument,\n blocksToClear: [ContentModelBlockGroup[], ContentModelBlock][],\n segmentsToClear: ContentModelSegment[],\n tablesToClear: [ContentModelTable, boolean][]\n) {\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n if (segments) {\n segmentsToClear.push(...segments);\n }\n\n if (block) {\n blocksToClear.push([path, block]);\n } else if (tableContext) {\n clearTableCellFormat(tableContext, tablesToClear);\n }\n },\n {\n // When there is a default format to apply, we know how to handle segment format under list.\n // So no need to clear format of list number.\n // Otherwise, we will clear all format of selected text. And since they are under LI tag, we\n // also need to clear the format of LI (format holder) so that the format is really cleared\n includeListFormatHolder: model.format ? 'never' : 'anySegment',\n }\n );\n\n const marker = segmentsToClear[0];\n\n // 2. If selection is collapsed, add selection to whole word to clear if any\n if (\n blocksToClear.length == 1 &&\n isOnlySelectionMarkerSelected(blocksToClear[0][1]) &&\n blocksToClear.length == 1\n ) {\n segmentsToClear.splice(0, segmentsToClear.length, ...adjustWordSelection(model, marker));\n clearListFormat(blocksToClear[0][0]);\n } else if (blocksToClear.length > 1 || blocksToClear.some(x => isWholeBlockSelected(x[1]))) {\n // 2. If a full block or multiple blocks are selected, clear block format\n for (let i = blocksToClear.length - 1; i >= 0; i--) {\n const [path, block] = blocksToClear[i];\n\n clearBlockFormat(path, block);\n clearListFormat(path);\n clearContainerFormat(path, block);\n }\n }\n\n // 3. Finally clear format for segments\n clearSegmentsFormat(segmentsToClear, model.format);\n\n // 4. Clear format for table if any\n createTablesFormat(tablesToClear);\n}\n\nfunction createTablesFormat(tablesToClear: [ContentModelTable, boolean][]) {\n tablesToClear.forEach(x => {\n const [table, isWholeTableSelected] = x;\n if (isWholeTableSelected) {\n table.format = {\n useBorderBox: table.format.useBorderBox,\n borderCollapse: table.format.borderCollapse,\n };\n updateTableMetadata(table, () => null);\n }\n\n applyTableFormat(table, undefined /*newFormat*/, true);\n });\n}\n\nfunction clearSegmentsFormat(\n segmentsToClear: ContentModelSegment[],\n defaultSegmentFormat: ContentModelSegmentFormat | undefined\n) {\n segmentsToClear.forEach(x => {\n x.format = { ...(defaultSegmentFormat || {}) };\n\n if (x.link) {\n delete x.link.format.textColor;\n }\n\n delete x.code;\n });\n}\n\nfunction clearTableCellFormat(\n tableContext: TableSelectionContext | undefined,\n tablesToClear: [ContentModelTable, boolean][]\n) {\n if (tableContext) {\n const { table, colIndex, rowIndex, isWholeTableSelected } = tableContext;\n const cell = table.rows[rowIndex].cells[colIndex];\n\n if (cell.isSelected) {\n updateTableCellMetadata(cell, () => null);\n cell.isHeader = false;\n cell.format = {\n useBorderBox: cell.format.useBorderBox,\n };\n }\n\n if (!tablesToClear.find(x => x[0] == table)) {\n tablesToClear.push([table, isWholeTableSelected]);\n }\n }\n}\n\nfunction clearContainerFormat(path: ContentModelBlockGroup[], block: ContentModelBlock) {\n const containerPathIndex = getClosestAncestorBlockGroupIndex(\n path,\n ['FormatContainer'],\n ['TableCell']\n );\n\n if (containerPathIndex >= 0 && containerPathIndex < path.length - 1) {\n const container = path[containerPathIndex] as ContentModelFormatContainer;\n const containerIndex = path[containerPathIndex + 1].blocks.indexOf(container);\n const blockIndex = container.blocks.indexOf(block);\n\n if (blockIndex >= 0 && containerIndex >= 0) {\n const newContainer = createFormatContainer(container.tagName, container.format);\n\n container.blocks.splice(blockIndex, 1);\n newContainer.blocks = container.blocks.splice(blockIndex);\n\n path[containerPathIndex + 1].blocks.splice(containerIndex + 1, 0, block, newContainer);\n }\n }\n}\n\nfunction clearListFormat(path: ContentModelBlockGroup[]) {\n const listItem = path[getClosestAncestorBlockGroupIndex(path, ['ListItem'], ['TableCell'])] as\n | ContentModelListItem\n | undefined;\n\n if (listItem) {\n listItem.levels = [];\n }\n}\n\nfunction clearBlockFormat(path: ContentModelBlockGroup[], block: ContentModelBlock) {\n if (block.blockType == 'Divider') {\n const index = path[0].blocks.indexOf(block);\n\n if (index >= 0) {\n path[0].blocks.splice(index, 1);\n }\n } else if (block.blockType == 'Paragraph') {\n block.format = {};\n delete block.decorator;\n }\n}\n\nfunction isOnlySelectionMarkerSelected(block: ContentModelBlock) {\n const segments = block.blockType == 'Paragraph' ? block.segments.filter(x => x.isSelected) : [];\n\n return segments.length == 1 && segments[0].segmentType == 'SelectionMarker';\n}\n\nfunction isWholeBlockSelected(block: ContentModelBlock) {\n return (\n (block as Selectable).isSelected ||\n (block.blockType == 'Paragraph' && block.segments.every(x => x.isSelected))\n );\n}\n"]}
1
+ {"version":3,"file":"clearModelFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/clearModelFormat.ts"],"names":[],"mappings":";;;;IAsBA;;OAEG;IACH,SAAgB,gBAAgB,CAC5B,KAA2B,EAC3B,aAA8D,EAC9D,eAAsC,EACtC,aAA6C;QAE7C,IAAA,+CAAiB,EACb,KAAK,EACL,UAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ;YAChC,IAAI,QAAQ,EAAE;gBACV,eAAe,CAAC,IAAI,OAApB,eAAe,qDAAS,QAAQ,WAAE;aACrC;YAED,IAAI,KAAK,EAAE;gBACP,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aACrC;iBAAM,IAAI,YAAY,EAAE;gBACrB,oBAAoB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;aACrD;QACL,CAAC,EACD;YACI,4FAA4F;YAC5F,6CAA6C;YAC7C,4FAA4F;YAC5F,2FAA2F;YAC3F,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY;SACjE,CACJ,CAAC;QAEF,IAAM,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QAElC,4EAA4E;QAC5E,IACI,aAAa,CAAC,MAAM,IAAI,CAAC;YACzB,6BAA6B,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,aAAa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IACN,CAAC","sourcesContent":["import { adjustWordSelection } from '../selection/adjustWordSelection';\nimport {\n applyTableFormat,\n createFormatContainer,\n getClosestAncestorBlockGroupIndex,\n iterateSelections,\n updateTableCellMetadata,\n updateTableMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelListItem,\n ContentModelSegment,\n ContentModelSegmentFormat,\n ContentModelTable,\n Selectable,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function clearModelFormat(\n model: ContentModelDocument,\n blocksToClear: [ContentModelBlockGroup[], ContentModelBlock][],\n segmentsToClear: ContentModelSegment[],\n tablesToClear: [ContentModelTable, boolean][]\n) {\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n if (segments) {\n segmentsToClear.push(...segments);\n }\n\n if (block) {\n blocksToClear.push([path, block]);\n } else if (tableContext) {\n clearTableCellFormat(tableContext, tablesToClear);\n }\n },\n {\n // When there is a default format to apply, we know how to handle segment format under list.\n // So no need to clear format of list number.\n // Otherwise, we will clear all format of selected text. And since they are under LI tag, we\n // also need to clear the format of LI (format holder) so that the format is really cleared\n includeListFormatHolder: model.format ? 'never' : 'anySegment',\n }\n );\n\n const marker = segmentsToClear[0];\n\n // 2. If selection is collapsed, add selection to whole word to clear if any\n if (\n blocksToClear.length == 1 &&\n isOnlySelectionMarkerSelected(blocksToClear[0][1]) &&\n blocksToClear.length == 1\n ) {\n segmentsToClear.splice(0, segmentsToClear.length, ...adjustWordSelection(model, marker));\n clearListFormat(blocksToClear[0][0]);\n } else if (blocksToClear.length > 1 || blocksToClear.some(x => isWholeBlockSelected(x[1]))) {\n // 2. If a full block or multiple blocks are selected, clear block format\n for (let i = blocksToClear.length - 1; i >= 0; i--) {\n const [path, block] = blocksToClear[i];\n\n clearBlockFormat(path, block);\n clearListFormat(path);\n clearContainerFormat(path, block);\n }\n }\n\n // 3. Finally clear format for segments\n clearSegmentsFormat(segmentsToClear, model.format);\n\n // 4. Clear format for table if any\n createTablesFormat(tablesToClear);\n}\n\nfunction createTablesFormat(tablesToClear: [ContentModelTable, boolean][]) {\n tablesToClear.forEach(x => {\n const [table, isWholeTableSelected] = x;\n if (isWholeTableSelected) {\n table.format = {\n useBorderBox: table.format.useBorderBox,\n borderCollapse: table.format.borderCollapse,\n };\n updateTableMetadata(table, () => null);\n }\n\n applyTableFormat(table, undefined /*newFormat*/, true);\n });\n}\n\nfunction clearSegmentsFormat(\n segmentsToClear: ContentModelSegment[],\n defaultSegmentFormat: ContentModelSegmentFormat | undefined\n) {\n segmentsToClear.forEach(x => {\n x.format = { ...(defaultSegmentFormat || {}) };\n\n if (x.link) {\n delete x.link.format.textColor;\n }\n\n delete x.code;\n });\n}\n\nfunction clearTableCellFormat(\n tableContext: TableSelectionContext | undefined,\n tablesToClear: [ContentModelTable, boolean][]\n) {\n if (tableContext) {\n const { table, colIndex, rowIndex, isWholeTableSelected } = tableContext;\n const cell = table.rows[rowIndex].cells[colIndex];\n\n if (cell.isSelected) {\n updateTableCellMetadata(cell, () => null);\n cell.isHeader = false;\n cell.format = {\n useBorderBox: cell.format.useBorderBox,\n };\n }\n\n if (!tablesToClear.find(x => x[0] == table)) {\n tablesToClear.push([table, isWholeTableSelected]);\n }\n }\n}\n\nfunction clearContainerFormat(path: ContentModelBlockGroup[], block: ContentModelBlock) {\n const containerPathIndex = getClosestAncestorBlockGroupIndex(\n path,\n ['FormatContainer'],\n ['TableCell']\n );\n\n if (containerPathIndex >= 0 && containerPathIndex < path.length - 1) {\n const container = path[containerPathIndex] as ContentModelFormatContainer;\n const containerIndex = path[containerPathIndex + 1].blocks.indexOf(container);\n const blockIndex = container.blocks.indexOf(block);\n\n if (blockIndex >= 0 && containerIndex >= 0) {\n const newContainer = createFormatContainer(container.tagName, container.format);\n\n container.blocks.splice(blockIndex, 1);\n newContainer.blocks = container.blocks.splice(blockIndex);\n\n path[containerPathIndex + 1].blocks.splice(containerIndex + 1, 0, block, newContainer);\n }\n }\n}\n\nfunction clearListFormat(path: ContentModelBlockGroup[]) {\n const listItem = path[getClosestAncestorBlockGroupIndex(path, ['ListItem'], ['TableCell'])] as\n | ContentModelListItem\n | undefined;\n\n if (listItem) {\n listItem.levels = [];\n }\n}\n\nfunction clearBlockFormat(path: ContentModelBlockGroup[], block: ContentModelBlock) {\n if (block.blockType == 'Divider') {\n const index = path[0].blocks.indexOf(block);\n\n if (index >= 0) {\n path[0].blocks.splice(index, 1);\n }\n } else if (block.blockType == 'Paragraph') {\n block.format = {};\n delete block.decorator;\n }\n}\n\nfunction isOnlySelectionMarkerSelected(block: ContentModelBlock) {\n const segments = block.blockType == 'Paragraph' ? block.segments.filter(x => x.isSelected) : [];\n\n return segments.length == 1 && segments[0].segmentType == 'SelectionMarker';\n}\n\nfunction isWholeBlockSelected(block: ContentModelBlock) {\n return (\n (block as Selectable).isSelected ||\n (block.blockType == 'Paragraph' && block.segments.every(x => x.isSelected))\n );\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ interface FormatStateContext extends DomToModelContext {
6
+ /**
7
+ * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,
8
+ * but use the top element in this stack instead in childProcessor.
9
+ */
10
+ nodeStack?: Node[];
11
+ }
12
+ /**
13
+ * @internal
14
+ * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
15
+ * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
16
+ * This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
17
+ * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
18
+ */
19
+ export declare function reducedModelChildProcessor(group: ContentModelBlockGroup, parent: ParentNode, context: FormatStateContext): void;
20
+ export {};
@@ -0,0 +1,64 @@
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.reducedModelChildProcessor = void 0;
5
+ /**
6
+ * @internal
7
+ * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create
8
+ * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.
9
+ * This "reduced" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,
10
+ * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state
11
+ */
12
+ function reducedModelChildProcessor(group, parent, context) {
13
+ if (!context.nodeStack) {
14
+ var selectionRootNode = (0, roosterjs_content_model_dom_1.getSelectionRootNode)(context.selection);
15
+ context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];
16
+ }
17
+ var stackChild = context.nodeStack.pop();
18
+ if (stackChild) {
19
+ var _a = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getRegularSelectionOffsets)(context, parent), 2), nodeStartOffset = _a[0], nodeEndOffset = _a[1];
20
+ // If selection is not on this node, skip getting node index to save some time since we don't need it here
21
+ var index = nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;
22
+ if (index >= 0) {
23
+ (0, roosterjs_content_model_dom_1.handleRegularSelection)(index, context, group, nodeStartOffset, nodeEndOffset);
24
+ }
25
+ (0, roosterjs_content_model_dom_1.processChildNode)(group, stackChild, context);
26
+ if (index >= 0) {
27
+ (0, roosterjs_content_model_dom_1.handleRegularSelection)(index + 1, context, group, nodeStartOffset, nodeEndOffset);
28
+ }
29
+ }
30
+ else {
31
+ // No child node from node stack, that means we have reached the deepest node of selection.
32
+ // Now we can use default child processor to perform full sub tree scanning for content model,
33
+ // So that all selected node will be included.
34
+ context.defaultElementProcessors.child(group, parent, context);
35
+ }
36
+ }
37
+ exports.reducedModelChildProcessor = reducedModelChildProcessor;
38
+ function createNodeStack(root, startNode) {
39
+ var result = [];
40
+ var node = startNode;
41
+ while (node && root != node && root.contains(node)) {
42
+ if ((0, roosterjs_content_model_dom_1.isNodeOfType)(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {
43
+ // For table, we can't do a reduced model creation since we need to handle their cells and indexes,
44
+ // so clean up whatever we already have, and just put table into the stack
45
+ result.splice(0, result.length, node);
46
+ }
47
+ else {
48
+ result.push(node);
49
+ }
50
+ node = node.parentNode;
51
+ }
52
+ return result;
53
+ }
54
+ function getChildIndex(parent, stackChild) {
55
+ var index = 0;
56
+ var child = parent.firstChild;
57
+ while (child && child != stackChild) {
58
+ index++;
59
+ child = child.nextSibling;
60
+ }
61
+ return index;
62
+ }
63
+ });
64
+ //# sourceMappingURL=reducedModelChildProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducedModelChildProcessor.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/reducedModelChildProcessor.ts"],"names":[],"mappings":";;;;IAoBA;;;;;;OAMG;IACH,SAAgB,0BAA0B,CACtC,KAA6B,EAC7B,MAAkB,EAClB,OAA2B;QAE3B,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACpB,IAAM,iBAAiB,GAAG,IAAA,kDAAoB,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAClE,OAAO,CAAC,SAAS,GAAG,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3F;QAED,IAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;QAE3C,IAAI,UAAU,EAAE;YACN,IAAA,KAAA,oBAAmC,IAAA,wDAA0B,EAAC,OAAO,EAAE,MAAM,CAAC,IAAA,EAA7E,eAAe,QAAA,EAAE,aAAa,QAA+C,CAAC;YAErF,0GAA0G;YAC1G,IAAM,KAAK,GACP,eAAe,IAAI,CAAC,IAAI,aAAa,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,M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AC,CAAC;QACd,IAAI,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;QAE9B,OAAO,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;YACjC,KAAK,EAAE,CAAC;YACR,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;SAC7B;QACD,OAAO,KAAK,CAAC;IACjB,CAAC","sourcesContent":["import {\n getRegularSelectionOffsets,\n getSelectionRootNode,\n handleRegularSelection,\n isNodeOfType,\n processChildNode,\n} from 'roosterjs-content-model-dom';\nimport type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\ninterface FormatStateContext extends DomToModelContext {\n /**\n * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,\n * but use the top element in this stack instead in childProcessor.\n */\n nodeStack?: Node[];\n}\n\n/**\n * @internal\n * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create\n * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.\n * This \"reduced\" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,\n * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state\n */\nexport function reducedModelChildProcessor(\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: FormatStateContext\n) {\n if (!context.nodeStack) {\n const selectionRootNode = getSelectionRootNode(context.selection);\n context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];\n }\n\n const stackChild = context.nodeStack.pop();\n\n if (stackChild) {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n\n // If selection is not on this node, skip getting node index to save some time since we don't need it here\n const index =\n nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;\n\n if (index >= 0) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n }\n\n processChildNode(group, stackChild, context);\n\n if (index >= 0) {\n handleRegularSelection(index + 1, context, group, nodeStartOffset, nodeEndOffset);\n }\n } else {\n // No child node from node stack, that means we have reached the deepest node of selection.\n // Now we can use default child processor to perform full sub tree scanning for content model,\n // So that all selected node will be included.\n context.defaultElementProcessors.child(group, parent, context);\n }\n}\n\nfunction createNodeStack(root: Node, startNode: Node): Node[] {\n const result: Node[] = [];\n let node: Node | null = startNode;\n\n while (node && root != node && root.contains(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {\n // For table, we can't do a reduced model creation since we need to handle their cells and indexes,\n // so clean up whatever we already have, and just put table into the stack\n result.splice(0, result.length, node);\n } else {\n result.push(node);\n }\n\n node = node.parentNode;\n }\n\n return result;\n}\n\nfunction getChildIndex(parent: ParentNode, stackChild: Node) {\n let index = 0;\n let child = parent.firstChild;\n\n while (child && child != stackChild) {\n index++;\n child = child.nextSibling;\n }\n return index;\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { ContentModelDocument, ContentModelEntity, FormatContentModelContext, InsertEntityPosition } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, ContentModelEntity, FormatContentModelContext, InsertEntityPosition, InsertPoint } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function insertEntityModel(model: ContentModelDocument, entityModel: ContentModelEntity, position: InsertEntityPosition, isBlock: boolean, focusAfterEntity?: boolean, context?: FormatContentModelContext): void;
5
+ export declare function insertEntityModel(model: ContentModelDocument, entityModel: ContentModelEntity, position: InsertEntityPosition, isBlock: boolean, focusAfterEntity?: boolean, context?: FormatContentModelContext, insertPointOverride?: InsertPoint): void;
@@ -1,16 +1,16 @@
1
- define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_core_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertEntityModel = void 0;
5
5
  /**
6
6
  * @internal
7
7
  */
8
- function insertEntityModel(model, entityModel, position, isBlock, focusAfterEntity, context) {
8
+ function insertEntityModel(model, entityModel, position, isBlock, focusAfterEntity, context, insertPointOverride) {
9
9
  var _a;
10
10
  var _b;
11
11
  var blockParent;
12
12
  var blockIndex = -1;
13
- var deleteResult;
13
+ var insertPoint;
14
14
  if (position == 'begin' || position == 'end') {
15
15
  blockParent = model;
16
16
  blockIndex = position == 'begin' ? 0 : model.blocks.length;
@@ -18,11 +18,8 @@ define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterj
18
18
  Object.assign(entityModel.format, model.format);
19
19
  }
20
20
  }
21
- else if ((deleteResult = (0, roosterjs_content_model_core_1.deleteSelection)(model, [], context)).insertPoint) {
22
- var _c = deleteResult.insertPoint, marker = _c.marker, paragraph = _c.paragraph, path = _c.path;
23
- if (deleteResult.deleteResult == 'range') {
24
- (0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
25
- }
21
+ else if ((insertPoint = getInsertPoint(model, insertPointOverride, context))) {
22
+ var marker = insertPoint.marker, paragraph = insertPoint.paragraph, path = insertPoint.path;
26
23
  if (!isBlock) {
27
24
  var index = paragraph.segments.indexOf(marker);
28
25
  Object.assign(entityModel.format, marker.format);
@@ -32,7 +29,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterj
32
29
  }
33
30
  else {
34
31
  var pathIndex = position == 'root'
35
- ? (0, roosterjs_content_model_core_1.getClosestAncestorBlockGroupIndex)(path, ['TableCell', 'Document'])
32
+ ? (0, roosterjs_content_model_dom_1.getClosestAncestorBlockGroupIndex)(path, ['TableCell', 'Document'])
36
33
  : 0;
37
34
  blockParent = path[pathIndex];
38
35
  var child = path[pathIndex - 1];
@@ -70,10 +67,23 @@ define(["require", "exports", "tslib", "roosterjs-content-model-core", "roosterj
70
67
  var marker = (0, roosterjs_content_model_dom_1.createSelectionMarker)(((_b = nextParagraph.segments[0]) === null || _b === void 0 ? void 0 : _b.format) || model.format);
71
68
  var segments = nextParagraph.segments;
72
69
  isBlock ? segments.unshift(marker) : segments.push(marker);
73
- (0, roosterjs_content_model_core_1.setSelection)(model, marker, marker);
70
+ (0, roosterjs_content_model_dom_1.setSelection)(model, marker, marker);
74
71
  }
75
72
  }
76
73
  }
77
74
  exports.insertEntityModel = insertEntityModel;
75
+ function getInsertPoint(model, insertPointOverride, context) {
76
+ if (insertPointOverride) {
77
+ return insertPointOverride;
78
+ }
79
+ else {
80
+ var deleteResult = (0, roosterjs_content_model_dom_1.deleteSelection)(model, [], context);
81
+ var insertPoint = deleteResult.insertPoint;
82
+ if (deleteResult.deleteResult == 'range') {
83
+ (0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
84
+ }
85
+ return insertPoint;
86
+ }
87
+ }
78
88
  });
79
89
  //# sourceMappingURL=insertEntityModel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"insertEntityModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/entity/insertEntityModel.ts"],"names":[],"mappings":";;;;IAsBA;;OAEG;IACH,SAAgB,iBAAiB,CAC7B,KAA2B,EAC3B,WAA+B,EAC/B,QAA8B,EAC9B,OAAgB,EAChB,gBAA0B,EAC1B,OAAmC;;;QAEnC,IAAI,WAA+C,CAAC;QACpD,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;QACpB,IAAI,YAAmC,CAAC;QAExC,IAAI,QAAQ,IAAI,OAAO,IAAI,QAAQ,IAAI,KAAK,EAAE;YAC1C,WAAW,GAAG,KAAK,CAAC;YACpB,UAAU,GAAG,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;YAE3D,IAAI,CAAC,OAAO,EAAE;gBACV,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;aACnD;SACJ;aAAM,IAAI,CAAC,YAAY,GAAG,IAAA,8CAAe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,UAAU,EAAE,CAAC,uBAAK,cAAc,WAAE;YAE5D,IAAI,gBAAgB,IAAI,aAAa,EAAE;gBACnC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,CAAA,MAAA,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,KAAI,KAAK,CAAC,MAAM,CAAC,CAAC;gBACxF,IAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC;gBAExC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC3D,IAAA,2CAAY,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;aACvC;SACJ;IACL,CAAC;IAzFD,8CAyFC","sourcesContent":["import {\n deleteSelection,\n getClosestAncestorBlockGroupIndex,\n setSelection,\n} from 'roosterjs-content-model-core';\nimport {\n createBr,\n createParagraph,\n createSelectionMarker,\n normalizeContentModel,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n DeleteSelectionResult,\n FormatContentModelContext,\n InsertEntityPosition,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertEntityModel(\n model: ContentModelDocument,\n entityModel: ContentModelEntity,\n position: InsertEntityPosition,\n isBlock: boolean,\n focusAfterEntity?: boolean,\n context?: FormatContentModelContext\n) {\n let blockParent: ContentModelBlockGroup | undefined;\n let blockIndex = -1;\n let deleteResult: DeleteSelectionResult;\n\n if (position == 'begin' || position == 'end') {\n blockParent = model;\n blockIndex = position == 'begin' ? 0 : model.blocks.length;\n\n if (!isBlock) {\n Object.assign(entityModel.format, model.format);\n }\n } else if ((deleteResult = deleteSelection(model, [], context)).insertPoint) {\n const { marker, paragraph, path } = deleteResult.insertPoint;\n\n if (deleteResult.deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n if (!isBlock) {\n const index = paragraph.segments.indexOf(marker);\n\n Object.assign(entityModel.format, marker.format);\n\n if (index >= 0) {\n paragraph.segments.splice(focusAfterEntity ? index : index + 1, 0, entityModel);\n }\n } else {\n const pathIndex =\n position == 'root'\n ? getClosestAncestorBlockGroupIndex(path, ['TableCell', 'Document'])\n : 0;\n blockParent = path[pathIndex];\n const child = path[pathIndex - 1];\n const directChild: ContentModelBlock =\n child?.blockGroupType == 'FormatContainer' ||\n child?.blockGroupType == 'General' ||\n child?.blockGroupType == 'ListItem'\n ? child\n : paragraph;\n const childIndex = blockParent.blocks.indexOf(directChild);\n blockIndex = childIndex >= 0 ? childIndex + 1 : -1;\n }\n }\n\n if (blockIndex >= 0 && blockParent) {\n const blocksToInsert: ContentModelBlock[] = [];\n let nextParagraph: ContentModelParagraph | undefined;\n\n if (isBlock) {\n const nextBlock = blockParent.blocks[blockIndex];\n\n blocksToInsert.push(entityModel);\n\n if (nextBlock?.blockType == 'Paragraph') {\n nextParagraph = nextBlock;\n } else if (!nextBlock || nextBlock.blockType == 'Entity' || focusAfterEntity) {\n nextParagraph = createParagraph(false /*isImplicit*/, {}, model.format);\n nextParagraph.segments.push(createBr(model.format));\n blocksToInsert.push(nextParagraph);\n }\n } else {\n nextParagraph = createParagraph(\n false /*isImplicit*/,\n undefined /*format*/,\n model.format\n );\n\n nextParagraph.segments.push(entityModel);\n blocksToInsert.push(nextParagraph);\n }\n\n blockParent.blocks.splice(blockIndex, 0, ...blocksToInsert);\n\n if (focusAfterEntity && nextParagraph) {\n const marker = createSelectionMarker(nextParagraph.segments[0]?.format || model.format);\n const segments = nextParagraph.segments;\n\n isBlock ? segments.unshift(marker) : segments.push(marker);\n setSelection(model, marker, marker);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"insertEntityModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/entity/insertEntityModel.ts"],"names":[],"mappings":";;;;IAoBA;;OAEG;I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GAAG,YAAY,CAAC,WAAW,CAAC;YAE7C,IAAI,YAAY,CAAC,YAAY,IAAI,OAAO,EAAE;gBACtC,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;aAChC;YAED,OAAO,WAAW,CAAC;SACtB;IACL,CAAC","sourcesContent":["import {\n createBr,\n createParagraph,\n createSelectionMarker,\n normalizeContentModel,\n deleteSelection,\n getClosestAncestorBlockGroupIndex,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelEntity,\n ContentModelParagraph,\n FormatContentModelContext,\n InsertEntityPosition,\n InsertPoint,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function insertEntityModel(\n model: ContentModelDocument,\n entityModel: ContentModelEntity,\n position: InsertEntityPosition,\n isBlock: boolean,\n focusAfterEntity?: boolean,\n context?: FormatContentModelContext,\n insertPointOverride?: InsertPoint\n) {\n let blockParent: ContentModelBlockGroup | undefined;\n let blockIndex = -1;\n let insertPoint: InsertPoint | null;\n\n if (position == 'begin' || position == 'end') {\n blockParent = model;\n blockIndex = position == 'begin' ? 0 : model.blocks.length;\n\n if (!isBlock) {\n Object.assign(entityModel.format, model.format);\n }\n } else if ((insertPoint = getInsertPoint(model, insertPointOverride, context))) {\n const { marker, paragraph, path } = insertPoint;\n\n if (!isBlock) {\n const index = paragraph.segments.indexOf(marker);\n\n Object.assign(entityModel.format, marker.format);\n\n if (index >= 0) {\n paragraph.segments.splice(focusAfterEntity ? index : index + 1, 0, entityModel);\n }\n } else {\n const pathIndex =\n position == 'root'\n ? getClosestAncestorBlockGroupIndex(path, ['TableCell', 'Document'])\n : 0;\n blockParent = path[pathIndex];\n const child = path[pathIndex - 1];\n const directChild: ContentModelBlock =\n child?.blockGroupType == 'FormatContainer' ||\n child?.blockGroupType == 'General' ||\n child?.blockGroupType == 'ListItem'\n ? child\n : paragraph;\n const childIndex = blockParent.blocks.indexOf(directChild);\n blockIndex = childIndex >= 0 ? childIndex + 1 : -1;\n }\n }\n\n if (blockIndex >= 0 && blockParent) {\n const blocksToInsert: ContentModelBlock[] = [];\n let nextParagraph: ContentModelParagraph | undefined;\n\n if (isBlock) {\n const nextBlock = blockParent.blocks[blockIndex];\n\n blocksToInsert.push(entityModel);\n\n if (nextBlock?.blockType == 'Paragraph') {\n nextParagraph = nextBlock;\n } else if (!nextBlock || nextBlock.blockType == 'Entity' || focusAfterEntity) {\n nextParagraph = createParagraph(false /*isImplicit*/, {}, model.format);\n nextParagraph.segments.push(createBr(model.format));\n blocksToInsert.push(nextParagraph);\n }\n } else {\n nextParagraph = createParagraph(\n false /*isImplicit*/,\n undefined /*format*/,\n model.format\n );\n\n nextParagraph.segments.push(entityModel);\n blocksToInsert.push(nextParagraph);\n }\n\n blockParent.blocks.splice(blockIndex, 0, ...blocksToInsert);\n\n if (focusAfterEntity && nextParagraph) {\n const marker = createSelectionMarker(nextParagraph.segments[0]?.format || model.format);\n const segments = nextParagraph.segments;\n\n isBlock ? segments.unshift(marker) : segments.push(marker);\n setSelection(model, marker, marker);\n }\n }\n}\n\nfunction getInsertPoint(\n model: ContentModelDocument,\n insertPointOverride?: InsertPoint,\n context?: FormatContentModelContext\n): InsertPoint | null {\n if (insertPointOverride) {\n return insertPointOverride;\n } else {\n const deleteResult = deleteSelection(model, [], context);\n const insertPoint = deleteResult.insertPoint;\n\n if (deleteResult.deleteResult == 'range') {\n normalizeContentModel(model);\n }\n\n return insertPoint;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_core_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.applyImageBorderFormat = void 0;
@@ -10,7 +10,7 @@ define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content
10
10
  var format = image.format;
11
11
  var width = border.width, style = border.style, color = border.color;
12
12
  var borderKey = 'borderTop';
13
- var extractedBorder = (0, roosterjs_content_model_core_1.extractBorderValues)(format[borderKey]);
13
+ var extractedBorder = (0, roosterjs_content_model_dom_1.extractBorderValues)(format[borderKey]);
14
14
  var borderColor = extractedBorder.color;
15
15
  var borderWidth = extractedBorder.width;
16
16
  var borderStyle = extractedBorder.style;
@@ -1 +1 @@
1
- {"version":3,"file":"applyImageBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/image/applyImageBorderFormat.ts"],"names":[],"mappings":";;;;IAIA;;OAEG;IACH,SAAgB,sBAAsB,CAClC,KAAwB,EACxB,MAAqB,EACrB,YAAqB;QAErB,IAAI,MAAM,EAAE;YACR,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACpB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MAAM,MAAX,CAAY;YACvC,IAAM,SAAS,GAAG,WAAW,CAAC;YAC9B,IAAM,eAAe,GAAG,IAAA,kDAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAI,YAAY,GAAG,EAAE,CAAC;YAEtB,IAAI,KAAK,EAAE;gBACP,YAAY,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,GAAG,IAAI,CAAC;aACnD;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAG,WAAW,CAAC;aAC9B;iBAAM;gBACH,YAAY,GAAG,KAAK,CAAC;aACxB;YAED,IAAI,KAAK,EAAE;gBACP,YAAY,GAAM,YAAY,SAAI,KAAO,CAAC;aAC7C;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAM,YAAY,SAAI,WAAa,CAAC;aACnD;iBAAM;gBACH,YAAY,GAAM,YAAY,WAAQ,CAAC;aAC1C;YAED,IAAI,KAAK,EAAE;gBACP,YAAY,GAAM,YAAY,SAAI,KAAO,CAAC;aAC7C;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAM,YAAY,SAAI,WAAa,CAAC;aACnD;YACD,KAAK,CAAC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC;YACvC,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;YACzC,KAAK,CAAC,MAAM,CAAC,WAAW,GAAG,YAAY,CAAC;SAC3C;aAAM;YACH,OAAO,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;YAC/B,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;YAC9B,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC;YACjC,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC;SACnC;QAED,IAAI,YAAY,EAAE;YACd,KAAK,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;SAC5C;IACL,CAAC;IAlDD,wDAkDC","sourcesContent":["import { extractBorderValues } from 'roosterjs-content-model-core';\nimport { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport type { Border, ContentModelImage } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function applyImageBorderFormat(\n image: ContentModelImage,\n border: Border | null,\n borderRadius?: string\n) {\n if (border) {\n const format = image.format;\n const { width, style, color } = border;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n let borderFormat = '';\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n image.format.borderLeft = borderFormat;\n image.format.borderTop = borderFormat;\n image.format.borderBottom = borderFormat;\n image.format.borderRight = borderFormat;\n } else {\n delete image.format.borderLeft;\n delete image.format.borderTop;\n delete image.format.borderBottom;\n delete image.format.borderRight;\n }\n\n if (borderRadius) {\n image.format.borderRadius = borderRadius;\n }\n}\n"]}
1
+ {"version":3,"file":"applyImageBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/image/applyImageBorderFormat.ts"],"names":[],"mappings":";;;;IAGA;;OAEG;IACH,SAAgB,sBAAsB,CAClC,KAAwB,EACxB,MAAqB,EACrB,YAAqB;QAErB,IAAI,MAAM,EAAE;YACR,IAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACpB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MAAM,MAAX,CAAY;YACvC,IAAM,SAAS,GAAG,WAAW,CAAC;YAC9B,IAAM,eAAe,GAAG,IAAA,iDAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAI,YAAY,GAAG,EAAE,CAAC;YAEtB,IAAI,KAAK,EAAE;gBACP,YAAY,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,GAAG,IAAI,CAAC;aACnD;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAG,WAAW,CAAC;aAC9B;iBAAM;gBACH,YAAY,GAAG,KAAK,CAAC;aACxB;YAED,IAAI,KAAK,EAAE;gBACP,YAAY,GAAM,YAAY,SAAI,KAAO,CAAC;aAC7C;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAM,YAAY,SAAI,WAAa,CAAC;aACnD;iBAAM;gBACH,YAAY,GAAM,YAAY,WAAQ,CAAC;aAC1C;YAED,IAAI,KAAK,EAAE;gBACP,YAAY,GAAM,YAAY,SAAI,KAAO,CAAC;aAC7C;iBAAM,IAAI,WAAW,EAAE;gBACpB,YAAY,GAAM,YAAY,SAAI,WAAa,CAAC;aACnD;YACD,KAAK,CAAC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC;YACvC,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;YACtC,KAAK,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;YACzC,KAAK,CAAC,MAAM,CAAC,WAAW,GAAG,YAAY,CAAC;SAC3C;aAAM;YACH,OAAO,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;YAC/B,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;YAC9B,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC;YACjC,OAAO,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC;SACnC;QAED,IAAI,YAAY,EAAE;YACd,KAAK,CAAC,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;SAC5C;IACL,CAAC;IAlDD,wDAkDC","sourcesContent":["import { extractBorderValues, parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport type { Border, ContentModelImage } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function applyImageBorderFormat(\n image: ContentModelImage,\n border: Border | null,\n borderRadius?: string\n) {\n if (border) {\n const format = image.format;\n const { width, style, color } = border;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n let borderFormat = '';\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n image.format.borderLeft = borderFormat;\n image.format.borderTop = borderFormat;\n image.format.borderBottom = borderFormat;\n image.format.borderRight = borderFormat;\n } else {\n delete image.format.borderLeft;\n delete image.format.borderTop;\n delete image.format.borderBottom;\n delete image.format.borderRight;\n }\n\n if (borderRadius) {\n image.format.borderRadius = borderRadius;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_core_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setListType = void 0;
@@ -10,12 +10,12 @@ define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content
10
10
  */
11
11
  function setListType(model, listType, removeMargins) {
12
12
  if (removeMargins === void 0) { removeMargins = false; }
13
- var paragraphOrListItems = (0, roosterjs_content_model_core_1.getOperationalBlocks)(model, ['ListItem'], [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any
13
+ var paragraphOrListItems = (0, roosterjs_content_model_dom_1.getOperationalBlocks)(model, ['ListItem'], [] // Set stop types to be empty so we can find list items even cross the boundary of table, then we can always operation on the list item if any
14
14
  );
15
15
  var alreadyInExpectedType = paragraphOrListItems.every(function (_a) {
16
16
  var _b;
17
17
  var block = _a.block;
18
- return (0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')
18
+ return (0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem')
19
19
  ? ((_b = block.levels[block.levels.length - 1]) === null || _b === void 0 ? void 0 : _b.listType) == listType
20
20
  : shouldIgnoreBlock(block);
21
21
  });
@@ -23,7 +23,7 @@ define(["require", "exports", "roosterjs-content-model-core", "roosterjs-content
23
23
  paragraphOrListItems.forEach(function (_a, itemIndex) {
24
24
  var _b, _c;
25
25
  var block = _a.block, parent = _a.parent;
26
- if ((0, roosterjs_content_model_core_1.isBlockGroupOfType)(block, 'ListItem')) {
26
+ if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(block, 'ListItem')) {
27
27
  var level = block.levels.pop();
28
28
  if (!alreadyInExpectedType && level) {
29
29
  level.listType = listType;