@wordpress/block-editor 15.20.0 → 15.21.1

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 (430) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/components/block-compare/index.cjs +2 -2
  3. package/build/components/block-compare/index.cjs.map +2 -2
  4. package/build/components/block-list/use-block-props/index.cjs +1 -1
  5. package/build/components/block-list/use-block-props/index.cjs.map +2 -2
  6. package/build/components/block-patterns-list/index.cjs +1 -1
  7. package/build/components/block-patterns-list/index.cjs.map +2 -2
  8. package/build/components/block-switcher/block-transformations-menu.cjs +16 -15
  9. package/build/components/block-switcher/block-transformations-menu.cjs.map +2 -2
  10. package/build/components/block-switcher/index.cjs +4 -4
  11. package/build/components/block-switcher/index.cjs.map +2 -2
  12. package/build/components/child-layout-control/index.cjs +10 -5
  13. package/build/components/child-layout-control/index.cjs.map +2 -2
  14. package/build/components/global-styles/advanced-panel.cjs +23 -15
  15. package/build/components/global-styles/advanced-panel.cjs.map +2 -2
  16. package/build/components/global-styles/background-panel.cjs +2 -2
  17. package/build/components/global-styles/background-panel.cjs.map +2 -2
  18. package/build/components/global-styles/border-panel.cjs +2 -0
  19. package/build/components/global-styles/border-panel.cjs.map +2 -2
  20. package/build/components/global-styles/dimensions-panel.cjs +5 -4
  21. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  22. package/build/components/iframe/index.cjs +3 -0
  23. package/build/components/iframe/index.cjs.map +2 -2
  24. package/build/components/inner-blocks/use-inner-block-template-sync.cjs +3 -1
  25. package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +2 -2
  26. package/build/components/inserter/hooks/use-patterns-state.cjs +1 -1
  27. package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
  28. package/build/components/inserter/index.cjs +179 -220
  29. package/build/components/inserter/index.cjs.map +3 -3
  30. package/build/components/inserter/media-tab/utils.cjs +1 -1
  31. package/build/components/inserter/media-tab/utils.cjs.map +2 -2
  32. package/build/components/inserter/search-results.cjs +1 -1
  33. package/build/components/inserter/search-results.cjs.map +2 -2
  34. package/build/components/list-view/block-select-button.cjs +10 -12
  35. package/build/components/list-view/block-select-button.cjs.map +2 -2
  36. package/build/components/list-view/block.cjs +2 -1
  37. package/build/components/list-view/block.cjs.map +2 -2
  38. package/build/components/provider/use-block-sync.cjs +11 -2
  39. package/build/components/provider/use-block-sync.cjs.map +2 -2
  40. package/build/components/rich-text/event-listeners/before-input-rules.cjs +4 -4
  41. package/build/components/rich-text/event-listeners/before-input-rules.cjs.map +3 -3
  42. package/build/components/rich-text/event-listeners/delete.cjs +4 -4
  43. package/build/components/rich-text/event-listeners/delete.cjs.map +3 -3
  44. package/build/components/rich-text/event-listeners/enter.cjs +7 -2
  45. package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
  46. package/build/components/rich-text/event-listeners/input-events.cjs +4 -4
  47. package/build/components/rich-text/event-listeners/input-events.cjs.map +3 -3
  48. package/build/components/rich-text/event-listeners/input-rules.cjs +17 -4
  49. package/build/components/rich-text/event-listeners/input-rules.cjs.map +3 -3
  50. package/build/components/rich-text/event-listeners/insert-replacement-text.cjs +4 -4
  51. package/build/components/rich-text/event-listeners/insert-replacement-text.cjs.map +3 -3
  52. package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs +4 -4
  53. package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs.map +3 -3
  54. package/build/components/rich-text/event-listeners/shortcuts.cjs +4 -4
  55. package/build/components/rich-text/event-listeners/shortcuts.cjs.map +3 -3
  56. package/build/components/rich-text/event-listeners/undo-automatic-change.cjs +4 -4
  57. package/build/components/rich-text/event-listeners/undo-automatic-change.cjs.map +3 -3
  58. package/build/components/rich-text/index.cjs +1 -23
  59. package/build/components/rich-text/index.cjs.map +2 -2
  60. package/build/components/use-block-commands/index.cjs +5 -5
  61. package/build/components/use-block-commands/index.cjs.map +2 -2
  62. package/build/hooks/anchor.cjs +11 -15
  63. package/build/hooks/anchor.cjs.map +2 -2
  64. package/build/hooks/border.cjs +0 -3
  65. package/build/hooks/border.cjs.map +2 -2
  66. package/build/hooks/color.cjs +1 -4
  67. package/build/hooks/color.cjs.map +2 -2
  68. package/build/hooks/dimensions.cjs +0 -3
  69. package/build/hooks/dimensions.cjs.map +2 -2
  70. package/build/hooks/fit-text.cjs +11 -0
  71. package/build/hooks/fit-text.cjs.map +2 -2
  72. package/build/hooks/position.cjs +19 -22
  73. package/build/hooks/position.cjs.map +2 -2
  74. package/build/hooks/supports.cjs +0 -7
  75. package/build/hooks/supports.cjs.map +2 -2
  76. package/build/store/actions.cjs +7 -3
  77. package/build/store/actions.cjs.map +2 -2
  78. package/build/store/private-actions.cjs +1 -2
  79. package/build/store/private-actions.cjs.map +2 -2
  80. package/build/store/private-selectors.cjs +29 -0
  81. package/build/store/private-selectors.cjs.map +2 -2
  82. package/build/store/reducer.cjs +14 -6
  83. package/build/store/reducer.cjs.map +2 -2
  84. package/build/store/selectors.cjs +60 -41
  85. package/build/store/selectors.cjs.map +2 -2
  86. package/build-module/components/block-compare/index.mjs +1 -1
  87. package/build-module/components/block-compare/index.mjs.map +2 -2
  88. package/build-module/components/block-list/use-block-props/index.mjs +1 -1
  89. package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
  90. package/build-module/components/block-patterns-list/index.mjs +1 -1
  91. package/build-module/components/block-patterns-list/index.mjs.map +2 -2
  92. package/build-module/components/block-switcher/block-transformations-menu.mjs +16 -15
  93. package/build-module/components/block-switcher/block-transformations-menu.mjs.map +2 -2
  94. package/build-module/components/block-switcher/index.mjs +4 -4
  95. package/build-module/components/block-switcher/index.mjs.map +2 -2
  96. package/build-module/components/child-layout-control/index.mjs +10 -5
  97. package/build-module/components/child-layout-control/index.mjs.map +2 -2
  98. package/build-module/components/global-styles/advanced-panel.mjs +23 -15
  99. package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
  100. package/build-module/components/global-styles/background-panel.mjs +3 -3
  101. package/build-module/components/global-styles/background-panel.mjs.map +2 -2
  102. package/build-module/components/global-styles/border-panel.mjs +2 -0
  103. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  104. package/build-module/components/global-styles/dimensions-panel.mjs +9 -6
  105. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  106. package/build-module/components/iframe/index.mjs +3 -0
  107. package/build-module/components/iframe/index.mjs.map +2 -2
  108. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +3 -1
  109. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +2 -2
  110. package/build-module/components/inserter/hooks/use-patterns-state.mjs +1 -1
  111. package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
  112. package/build-module/components/inserter/index.mjs +185 -222
  113. package/build-module/components/inserter/index.mjs.map +3 -3
  114. package/build-module/components/inserter/media-tab/utils.mjs +1 -1
  115. package/build-module/components/inserter/media-tab/utils.mjs.map +2 -2
  116. package/build-module/components/inserter/search-results.mjs +1 -1
  117. package/build-module/components/inserter/search-results.mjs.map +2 -2
  118. package/build-module/components/list-view/block-select-button.mjs +10 -12
  119. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  120. package/build-module/components/list-view/block.mjs +2 -1
  121. package/build-module/components/list-view/block.mjs.map +2 -2
  122. package/build-module/components/provider/use-block-sync.mjs +11 -2
  123. package/build-module/components/provider/use-block-sync.mjs.map +2 -2
  124. package/build-module/components/rich-text/event-listeners/before-input-rules.mjs +4 -4
  125. package/build-module/components/rich-text/event-listeners/before-input-rules.mjs.map +2 -2
  126. package/build-module/components/rich-text/event-listeners/delete.mjs +4 -4
  127. package/build-module/components/rich-text/event-listeners/delete.mjs.map +2 -2
  128. package/build-module/components/rich-text/event-listeners/enter.mjs +7 -2
  129. package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
  130. package/build-module/components/rich-text/event-listeners/input-events.mjs +4 -4
  131. package/build-module/components/rich-text/event-listeners/input-events.mjs.map +2 -2
  132. package/build-module/components/rich-text/event-listeners/input-rules.mjs +17 -4
  133. package/build-module/components/rich-text/event-listeners/input-rules.mjs.map +2 -2
  134. package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs +4 -4
  135. package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs.map +2 -2
  136. package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs +4 -4
  137. package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs.map +2 -2
  138. package/build-module/components/rich-text/event-listeners/shortcuts.mjs +4 -4
  139. package/build-module/components/rich-text/event-listeners/shortcuts.mjs.map +2 -2
  140. package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs +4 -4
  141. package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs.map +2 -2
  142. package/build-module/components/rich-text/index.mjs +1 -23
  143. package/build-module/components/rich-text/index.mjs.map +2 -2
  144. package/build-module/components/use-block-commands/index.mjs +5 -5
  145. package/build-module/components/use-block-commands/index.mjs.map +2 -2
  146. package/build-module/hooks/anchor.mjs +11 -15
  147. package/build-module/hooks/anchor.mjs.map +2 -2
  148. package/build-module/hooks/border.mjs +1 -4
  149. package/build-module/hooks/border.mjs.map +2 -2
  150. package/build-module/hooks/color.mjs +2 -5
  151. package/build-module/hooks/color.mjs.map +2 -2
  152. package/build-module/hooks/dimensions.mjs +1 -4
  153. package/build-module/hooks/dimensions.mjs.map +2 -2
  154. package/build-module/hooks/fit-text.mjs +11 -0
  155. package/build-module/hooks/fit-text.mjs.map +2 -2
  156. package/build-module/hooks/position.mjs +20 -23
  157. package/build-module/hooks/position.mjs.map +2 -2
  158. package/build-module/hooks/supports.mjs +0 -7
  159. package/build-module/hooks/supports.mjs.map +2 -2
  160. package/build-module/store/actions.mjs +7 -3
  161. package/build-module/store/actions.mjs.map +2 -2
  162. package/build-module/store/private-actions.mjs +1 -2
  163. package/build-module/store/private-actions.mjs.map +2 -2
  164. package/build-module/store/private-selectors.mjs +26 -0
  165. package/build-module/store/private-selectors.mjs.map +2 -2
  166. package/build-module/store/reducer.mjs +14 -6
  167. package/build-module/store/reducer.mjs.map +2 -2
  168. package/build-module/store/selectors.mjs +62 -42
  169. package/build-module/store/selectors.mjs.map +2 -2
  170. package/build-style/content-rtl.css +12 -0
  171. package/build-style/content.css +12 -0
  172. package/build-style/style-rtl.css +26 -8
  173. package/build-style/style.css +26 -8
  174. package/package.json +51 -48
  175. package/src/components/block-breadcrumb/README.md +2 -2
  176. package/src/components/block-compare/README.md +6 -6
  177. package/src/components/block-compare/index.js +1 -3
  178. package/src/components/block-list/use-block-props/index.js +1 -1
  179. package/src/components/block-patterns-list/index.js +1 -1
  180. package/src/components/block-preview/README.md +1 -1
  181. package/src/components/block-switcher/block-transformations-menu.js +16 -18
  182. package/src/components/block-switcher/index.js +4 -4
  183. package/src/components/block-types-list/README.md +0 -19
  184. package/src/components/child-layout-control/index.js +15 -8
  185. package/src/components/child-layout-control/test/index.js +126 -0
  186. package/src/components/colors/test/with-colors.js +1 -1
  187. package/src/components/global-styles/advanced-panel.js +5 -1
  188. package/src/components/global-styles/background-panel.js +3 -3
  189. package/src/components/global-styles/border-panel.js +2 -0
  190. package/src/components/global-styles/dimensions-panel.js +23 -16
  191. package/src/components/iframe/index.js +3 -0
  192. package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -1
  193. package/src/components/inserter/hooks/use-patterns-state.js +1 -1
  194. package/src/components/inserter/index.js +257 -288
  195. package/src/components/inserter/media-tab/utils.js +1 -1
  196. package/src/components/inserter/search-results.js +1 -3
  197. package/src/components/justify-content-control/README.md +1 -1
  198. package/src/components/list-view/block-select-button.js +9 -13
  199. package/src/components/list-view/block.js +1 -0
  200. package/src/components/media-placeholder/README.md +1 -29
  201. package/src/components/media-upload/README.md +0 -19
  202. package/src/components/provider/test/use-block-sync.js +40 -0
  203. package/src/components/provider/use-block-sync.js +12 -2
  204. package/src/components/rich-text/event-listeners/before-input-rules.js +5 -4
  205. package/src/components/rich-text/event-listeners/delete.js +9 -4
  206. package/src/components/rich-text/event-listeners/enter.js +9 -2
  207. package/src/components/rich-text/event-listeners/input-events.js +13 -4
  208. package/src/components/rich-text/event-listeners/input-rules.js +20 -4
  209. package/src/components/rich-text/event-listeners/insert-replacement-text.js +9 -4
  210. package/src/components/rich-text/event-listeners/remove-browser-shortcuts.js +9 -4
  211. package/src/components/rich-text/event-listeners/shortcuts.js +13 -4
  212. package/src/components/rich-text/event-listeners/undo-automatic-change.js +5 -4
  213. package/src/components/rich-text/index.js +1 -33
  214. package/src/components/unit-control/README.md +1 -1
  215. package/src/components/url-popover/README.md +1 -1
  216. package/src/components/use-block-commands/index.js +5 -5
  217. package/src/hooks/anchor.js +9 -17
  218. package/src/hooks/border.js +1 -5
  219. package/src/hooks/color.js +1 -6
  220. package/src/hooks/dimensions.js +1 -5
  221. package/src/hooks/fit-text.js +16 -0
  222. package/src/hooks/position.js +23 -27
  223. package/src/hooks/supports.js +0 -9
  224. package/src/store/actions.js +13 -3
  225. package/src/store/private-actions.js +1 -4
  226. package/src/store/private-selectors.js +59 -0
  227. package/src/store/reducer.js +19 -7
  228. package/src/store/selectors.js +91 -53
  229. package/src/store/test/actions.js +21 -0
  230. package/src/store/test/private-selectors.js +53 -0
  231. package/src/store/test/reducer.js +46 -0
  232. package/src/store/test/selectors.js +77 -0
  233. package/build/components/media-upload-progress/constants.cjs +0 -46
  234. package/build/components/media-upload-progress/constants.cjs.map +0 -7
  235. package/build/components/rich-text/native/format-edit.cjs +0 -60
  236. package/build/components/rich-text/native/format-edit.cjs.map +0 -7
  237. package/build/components/rich-text/native/index.cjs +0 -28
  238. package/build/components/rich-text/native/index.cjs.map +0 -7
  239. package/build/components/rich-text/native/use-format-types.cjs +0 -139
  240. package/build/components/rich-text/native/use-format-types.cjs.map +0 -7
  241. package/build-module/components/media-upload-progress/constants.mjs +0 -16
  242. package/build-module/components/media-upload-progress/constants.mjs.map +0 -7
  243. package/build-module/components/rich-text/native/format-edit.mjs +0 -39
  244. package/build-module/components/rich-text/native/format-edit.mjs.map +0 -7
  245. package/build-module/components/rich-text/native/index.mjs +0 -7
  246. package/build-module/components/rich-text/native/index.mjs.map +0 -7
  247. package/build-module/components/rich-text/native/use-format-types.mjs +0 -114
  248. package/build-module/components/rich-text/native/use-format-types.mjs.map +0 -7
  249. package/src/components/audio-player/audio-url-parser.native.js +0 -20
  250. package/src/components/audio-player/index.native.js +0 -225
  251. package/src/components/audio-player/styles.native.scss +0 -114
  252. package/src/components/audio-player/test/audio-url-parser.native.js +0 -53
  253. package/src/components/block-alignment-control/test/index.native.js +0 -37
  254. package/src/components/block-alignment-control/ui.native.js +0 -86
  255. package/src/components/block-caption/README.md +0 -104
  256. package/src/components/block-caption/index.native.js +0 -89
  257. package/src/components/block-caption/styles.native.scss +0 -7
  258. package/src/components/block-controls/slot.native.js +0 -33
  259. package/src/components/block-draggable/draggable-chip.native.js +0 -49
  260. package/src/components/block-draggable/dropping-insertion-point.native.js +0 -181
  261. package/src/components/block-draggable/dropping-insertion-point.native.scss +0 -8
  262. package/src/components/block-draggable/index.native.js +0 -467
  263. package/src/components/block-draggable/style.native.scss +0 -19
  264. package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +0 -73
  265. package/src/components/block-draggable/test/helpers.native.js +0 -182
  266. package/src/components/block-draggable/test/index.native.js +0 -419
  267. package/src/components/block-draggable/use-scroll-when-dragging.native.js +0 -135
  268. package/src/components/block-edit/edit.native.js +0 -49
  269. package/src/components/block-edit/test/edit.native.js +0 -65
  270. package/src/components/block-heading-level-dropdown/index.native.js +0 -68
  271. package/src/components/block-icon/index.native.js +0 -47
  272. package/src/components/block-icon/style.native.scss +0 -7
  273. package/src/components/block-list/block-crash-boundary.native.js +0 -43
  274. package/src/components/block-list/block-crash-warning.native.js +0 -21
  275. package/src/components/block-list/block-invalid-warning.native.js +0 -70
  276. package/src/components/block-list/block-list-context.native.js +0 -172
  277. package/src/components/block-list/block-list-item-cell.native.js +0 -62
  278. package/src/components/block-list/block-list-item.native.js +0 -209
  279. package/src/components/block-list/block-list-item.native.scss +0 -16
  280. package/src/components/block-list/block-outline.native.js +0 -77
  281. package/src/components/block-list/block-selection-button.native.js +0 -100
  282. package/src/components/block-list/block-selection-button.native.scss +0 -34
  283. package/src/components/block-list/block.native.js +0 -716
  284. package/src/components/block-list/block.native.scss +0 -62
  285. package/src/components/block-list/grid-item.native.js +0 -58
  286. package/src/components/block-list/index.native.js +0 -437
  287. package/src/components/block-list/insertion-point.native.js +0 -36
  288. package/src/components/block-list/style.native.scss +0 -117
  289. package/src/components/block-list/test/block-invalid-warning.native.js +0 -62
  290. package/src/components/block-list/test/block-list-context.native.js +0 -243
  291. package/src/components/block-list/test/block-outline.native.js +0 -255
  292. package/src/components/block-list/test/fixtures/block-list-context.native.js +0 -79
  293. package/src/components/block-list/test/index.native.js +0 -205
  294. package/src/components/block-list/use-block-props/index.native.js +0 -10
  295. package/src/components/block-list/use-scroll-upon-insertion.native.js +0 -52
  296. package/src/components/block-list-appender/index.native.js +0 -70
  297. package/src/components/block-list-appender/style.native.scss +0 -8
  298. package/src/components/block-media-update-progress/README.md +0 -100
  299. package/src/components/block-media-update-progress/index.native.js +0 -299
  300. package/src/components/block-media-update-progress/styles.native.scss +0 -9
  301. package/src/components/block-media-update-progress/test/index.native.js +0 -543
  302. package/src/components/block-mover/index.native.js +0 -193
  303. package/src/components/block-mover/mover-description.native.js +0 -155
  304. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +0 -218
  305. package/src/components/block-mover/test/index.native.js +0 -186
  306. package/src/components/block-settings/button.native.js +0 -41
  307. package/src/components/block-settings/container.native.js +0 -91
  308. package/src/components/block-settings/container.native.scss +0 -4
  309. package/src/components/block-settings/index.native.js +0 -5
  310. package/src/components/block-styles/index.native.js +0 -94
  311. package/src/components/block-styles/preview.native.js +0 -109
  312. package/src/components/block-styles/style.native.scss +0 -64
  313. package/src/components/block-switcher/block-transformations-menu.native.js +0 -91
  314. package/src/components/block-toolbar/block-toolbar-menu.native.js +0 -477
  315. package/src/components/block-toolbar/index.native.js +0 -126
  316. package/src/components/block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap +0 -125
  317. package/src/components/block-toolbar/test/block-toolbar-menu.native.js +0 -405
  318. package/src/components/block-toolbar/test/index.native.js +0 -36
  319. package/src/components/block-types-list/index.native.js +0 -175
  320. package/src/components/block-types-list/style.native.scss +0 -25
  321. package/src/components/block-variation-picker/index.native.js +0 -107
  322. package/src/components/block-variation-picker/style.native.scss +0 -32
  323. package/src/components/button-block-appender/index.native.js +0 -92
  324. package/src/components/button-block-appender/styles.native.scss +0 -43
  325. package/src/components/caption/README.md +0 -44
  326. package/src/components/caption/index.native.js +0 -61
  327. package/src/components/colors-gradients/panel-color-gradient-settings.native.js +0 -59
  328. package/src/components/contrast-checker/index.native.js +0 -113
  329. package/src/components/contrast-checker/style.native.scss +0 -26
  330. package/src/components/convert-to-group-buttons/index.native.js +0 -79
  331. package/src/components/default-block-appender/index.native.js +0 -113
  332. package/src/components/default-block-appender/style.native.scss +0 -18
  333. package/src/components/floating-toolbar/floatingToolbar.android.scss +0 -4
  334. package/src/components/floating-toolbar/floatingToolbar.ios.scss +0 -3
  335. package/src/components/floating-toolbar/index.native.js +0 -141
  336. package/src/components/floating-toolbar/styles.native.scss +0 -43
  337. package/src/components/font-sizes/index.native.js +0 -7
  338. package/src/components/global-styles/color-panel.native.js +0 -207
  339. package/src/components/global-styles/test/use-global-styles-context.native.js +0 -435
  340. package/src/components/global-styles/use-global-styles-context.native.js +0 -592
  341. package/src/components/gradients/index.native.js +0 -2
  342. package/src/components/image-link-destinations/index.native.js +0 -152
  343. package/src/components/image-link-destinations/style.native.scss +0 -16
  344. package/src/components/index.native.js +0 -108
  345. package/src/components/inner-blocks/constants.native.js +0 -5
  346. package/src/components/inner-blocks/index.native.js +0 -221
  347. package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +0 -124
  348. package/src/components/inserter/block-types-tab.native.js +0 -76
  349. package/src/components/inserter/hooks/use-block-type-impressions.native.js +0 -47
  350. package/src/components/inserter/hooks/use-clipboard-block.native.js +0 -40
  351. package/src/components/inserter/index.native.js +0 -424
  352. package/src/components/inserter/menu.native.js +0 -237
  353. package/src/components/inserter/no-results.native.js +0 -49
  354. package/src/components/inserter/reusable-blocks-tab.native.js +0 -45
  355. package/src/components/inserter/search-results.native.js +0 -67
  356. package/src/components/inserter/style.native.scss +0 -83
  357. package/src/components/inserter/tabs.native.js +0 -152
  358. package/src/components/inserter/test/__snapshots__/index.native.js.snap +0 -117
  359. package/src/components/inserter/test/fixtures/index.native.js +0 -12
  360. package/src/components/inserter/test/index.native.js +0 -273
  361. package/src/components/inserter/test/reusable-blocks-tab.native.js +0 -62
  362. package/src/components/inserter/test/utils.native.js +0 -37
  363. package/src/components/inserter/utils.native.js +0 -46
  364. package/src/components/inserter-button/index.native.js +0 -108
  365. package/src/components/inserter-button/style.native.scss +0 -72
  366. package/src/components/inspector-controls/fill.native.js +0 -62
  367. package/src/components/inspector-controls/slot.native.js +0 -35
  368. package/src/components/inspector-controls-tabs/advanced-controls-panel.native.js +0 -31
  369. package/src/components/line-height-control/index.native.js +0 -28
  370. package/src/components/media-placeholder/index.native.js +0 -258
  371. package/src/components/media-placeholder/styles.native.scss +0 -108
  372. package/src/components/media-replace-flow/index.native.js +0 -12
  373. package/src/components/media-upload/constants.native.js +0 -14
  374. package/src/components/media-upload/index.native.js +0 -356
  375. package/src/components/media-upload/style.native.scss +0 -4
  376. package/src/components/media-upload/test/index.native.js +0 -172
  377. package/src/components/media-upload-progress/README.md +0 -100
  378. package/src/components/media-upload-progress/constants.js +0 -6
  379. package/src/components/media-upload-progress/index.native.js +0 -233
  380. package/src/components/media-upload-progress/styles.native.scss +0 -15
  381. package/src/components/media-upload-progress/test/index.native.js +0 -220
  382. package/src/components/plain-text/index.native.js +0 -164
  383. package/src/components/plain-text/style.native.scss +0 -10
  384. package/src/components/provider/index.native.js +0 -32
  385. package/src/components/rich-text/embed-handler-picker.native.js +0 -65
  386. package/src/components/rich-text/file-paste-handler.native.js +0 -3
  387. package/src/components/rich-text/format-toolbar/index.native.js +0 -21
  388. package/src/components/rich-text/format-toolbar-container.native.js +0 -16
  389. package/src/components/rich-text/index.native.js +0 -701
  390. package/src/components/rich-text/input-event.native.js +0 -10
  391. package/src/components/rich-text/native/format-edit.js +0 -44
  392. package/src/components/rich-text/native/get-format-colors.native.js +0 -47
  393. package/src/components/rich-text/native/index.js +0 -1
  394. package/src/components/rich-text/native/index.native.js +0 -1389
  395. package/src/components/rich-text/native/style.native.scss +0 -28
  396. package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +0 -79
  397. package/src/components/rich-text/native/test/index.native.js +0 -345
  398. package/src/components/rich-text/native/test/performance/rich-text.native.js +0 -44
  399. package/src/components/rich-text/native/toolbar-button-with-options.native.js +0 -61
  400. package/src/components/rich-text/native/use-format-types.js +0 -146
  401. package/src/components/rich-text/remove-browser-shortcuts.native.js +0 -1
  402. package/src/components/rich-text/shortcut.native.js +0 -10
  403. package/src/components/ungroup-button/README.md +0 -23
  404. package/src/components/ungroup-button/index.native.js +0 -77
  405. package/src/components/unsupported-block-details/index.native.js +0 -187
  406. package/src/components/unsupported-block-details/style.native.scss +0 -56
  407. package/src/components/url-input/index.native.js +0 -33
  408. package/src/components/use-block-drop-zone/index.native.js +0 -207
  409. package/src/components/use-on-block-drop/index.native.js +0 -115
  410. package/src/components/use-unsupported-block-editor/index.native.js +0 -59
  411. package/src/components/video-player/gridicon-play.native.js +0 -13
  412. package/src/components/video-player/index.native.js +0 -133
  413. package/src/components/video-player/styles.native.scss +0 -29
  414. package/src/components/warning/index.native.js +0 -64
  415. package/src/components/warning/style.native.scss +0 -47
  416. package/src/hooks/align.native.js +0 -49
  417. package/src/hooks/custom-class-name.native.js +0 -70
  418. package/src/hooks/index.native.js +0 -36
  419. package/src/hooks/layout.native.js +0 -23
  420. package/src/hooks/test/__snapshots__/align.native.js.snap +0 -73
  421. package/src/hooks/test/__snapshots__/anchor.native.js.snap +0 -7
  422. package/src/hooks/test/align.native.js +0 -134
  423. package/src/hooks/test/anchor.native.js +0 -32
  424. package/src/hooks/test/use-editor-wrapper-styles.native.js +0 -282
  425. package/src/hooks/typography.native.js +0 -60
  426. package/src/hooks/use-editor-wrapper-styles.native.js +0 -250
  427. package/src/hooks/use-editor-wrapper-styles.native.scss +0 -12
  428. package/src/index.native.js +0 -6
  429. package/src/private-apis.native.js +0 -21
  430. package/src/store/defaults.native.js +0 -23
@@ -1,1389 +0,0 @@
1
- /* eslint no-console: ["error", { allow: ["warn"] }] */
2
-
3
- /**
4
- * External dependencies
5
- */
6
- import { View, Platform, Dimensions } from 'react-native';
7
- import memize from 'memize';
8
- import { colord } from 'colord';
9
-
10
- /**
11
- * WordPress dependencies
12
- */
13
- import RCTAztecView from '@wordpress/react-native-aztec';
14
- import {
15
- showUserSuggestions,
16
- showXpostSuggestions,
17
- } from '@wordpress/react-native-bridge';
18
- import { getPxFromCssUnit } from '@wordpress/components';
19
- import { Component } from '@wordpress/element';
20
- import {
21
- compose,
22
- debounce,
23
- withPreferredColorScheme,
24
- } from '@wordpress/compose';
25
- import { withSelect } from '@wordpress/data';
26
- import { childrenBlock } from '@wordpress/blocks';
27
- import { decodeEntities } from '@wordpress/html-entities';
28
- import { BACKSPACE, DELETE, ENTER } from '@wordpress/keycodes';
29
- import { isURL } from '@wordpress/url';
30
- import { atSymbol, plus } from '@wordpress/icons';
31
- import { __ } from '@wordpress/i18n';
32
- import {
33
- applyFormat,
34
- getActiveFormat,
35
- getActiveFormats,
36
- insert,
37
- getTextContent,
38
- isEmpty,
39
- create,
40
- toHTMLString,
41
- isCollapsed,
42
- remove,
43
- } from '@wordpress/rich-text';
44
- import { BlockFormatControls } from '@wordpress/block-editor';
45
-
46
- /**
47
- * Internal dependencies
48
- */
49
- import { useFormatTypes } from './use-format-types';
50
- import FormatEdit from './format-edit';
51
- import { getFormatColors } from './get-format-colors';
52
- import styles from './style.scss';
53
- import ToolbarButtonWithOptions from './toolbar-button-with-options';
54
-
55
- // The flattened color palettes array is memoized to ensure that the same array instance is
56
- // returned for the colors palettes. This value might be used as a prop, so having the same
57
- // instance will prevent unnecessary re-renders of the RichText component.
58
- const flatColorPalettes = memize( ( colorsPalettes ) => [
59
- ...( colorsPalettes?.theme || [] ),
60
- ...( colorsPalettes?.custom || [] ),
61
- ...( colorsPalettes?.default || [] ),
62
- ] );
63
-
64
- const getSelectionColor = memize(
65
- (
66
- currentSelectionColor,
67
- defaultSelectionColor,
68
- baseGlobalStyles,
69
- isBlockBasedTheme
70
- ) => {
71
- let selectionColor = defaultSelectionColor;
72
- if ( currentSelectionColor ) {
73
- selectionColor = currentSelectionColor;
74
- }
75
-
76
- if ( isBlockBasedTheme ) {
77
- const colordTextColor = colord( selectionColor );
78
- const colordBackgroundColor = colord(
79
- baseGlobalStyles?.color?.background
80
- );
81
- const isColordTextReadable = colordTextColor.isReadable(
82
- colordBackgroundColor
83
- );
84
- if ( ! isColordTextReadable ) {
85
- selectionColor = baseGlobalStyles?.color?.text;
86
- }
87
- }
88
-
89
- return selectionColor;
90
- }
91
- );
92
-
93
- const gutenbergFormatNamesToAztec = {
94
- 'core/bold': 'bold',
95
- 'core/italic': 'italic',
96
- 'core/strikethrough': 'strikethrough',
97
- 'core/text-color': 'mark',
98
- };
99
-
100
- const EMPTY_PARAGRAPH_TAGS = '<p></p>';
101
- const DEFAULT_FONT_SIZE = 16;
102
- const MIN_LINE_HEIGHT = 1;
103
-
104
- export class RichText extends Component {
105
- constructor( { value, selectionStart, selectionEnd } ) {
106
- super( ...arguments );
107
-
108
- this.isIOS = Platform.OS === 'ios';
109
- this.createRecord = this.createRecord.bind( this );
110
- this.onChangeFromAztec = this.onChangeFromAztec.bind( this );
111
- this.onKeyDown = this.onKeyDown.bind( this );
112
- this.handleEnter = this.handleEnter.bind( this );
113
- this.handleDelete = this.handleDelete.bind( this );
114
- this.onPaste = this.onPaste.bind( this );
115
- this.onFocus = this.onFocus.bind( this );
116
- this.onBlur = this.onBlur.bind( this );
117
- this.onTextUpdate = this.onTextUpdate.bind( this );
118
- this.onContentSizeChange = this.onContentSizeChange.bind( this );
119
- this.onFormatChange = this.onFormatChange.bind( this );
120
- this.formatToValue = memize( this.formatToValue.bind( this ), {
121
- maxSize: 1,
122
- } );
123
- this.debounceCreateUndoLevel = debounce( this.onCreateUndoLevel, 1000 );
124
- // This prevents a bug in Aztec which triggers onSelectionChange twice on format change.
125
- this.onSelectionChange = this.onSelectionChange.bind( this );
126
- this.onSelectionChangeFromAztec =
127
- this.onSelectionChangeFromAztec.bind( this );
128
- this.valueToFormat = this.valueToFormat.bind( this );
129
- this.getHtmlToRender = this.getHtmlToRender.bind( this );
130
- this.handleSuggestionFunc = this.handleSuggestionFunc.bind( this );
131
- this.handleUserSuggestion = this.handleSuggestionFunc(
132
- showUserSuggestions,
133
- '@'
134
- ).bind( this );
135
- this.handleXpostSuggestion = this.handleSuggestionFunc(
136
- showXpostSuggestions,
137
- '+'
138
- ).bind( this );
139
- this.suggestionOptions = this.suggestionOptions.bind( this );
140
- this.insertString = this.insertString.bind( this );
141
- this.manipulateEventCounterToForceNativeToRefresh =
142
- this.manipulateEventCounterToForceNativeToRefresh.bind( this );
143
- this.shouldDropEventFromAztec =
144
- this.shouldDropEventFromAztec.bind( this );
145
- this.state = {
146
- activeFormats: [],
147
- selectedFormat: null,
148
- height: 0,
149
- currentFontSize: this.getFontSize( arguments[ 0 ] ),
150
- };
151
- this.needsSelectionUpdate = false;
152
- this.savedContent = '';
153
- this.isTouched = false;
154
- this.lastAztecEventType = null;
155
-
156
- this.lastHistoryValue = value;
157
-
158
- // Internal values that are update synchronously, unlike props.
159
- this.value = value;
160
- this.selectionStart = selectionStart;
161
- this.selectionEnd = selectionEnd;
162
- }
163
-
164
- /**
165
- * Get the current record (value and selection) from props and state.
166
- *
167
- * @return {Object} The current record (value and selection).
168
- */
169
- getRecord() {
170
- const {
171
- selectionStart: start,
172
- selectionEnd: end,
173
- colorPalette,
174
- } = this.props;
175
- const { value } = this.props;
176
- const currentValue = this.formatToValue( value );
177
-
178
- const { formats, replacements, text } = currentValue;
179
- const { activeFormats } = this.state;
180
- const newFormats = getFormatColors( formats, colorPalette );
181
-
182
- return {
183
- formats: newFormats,
184
- replacements,
185
- text,
186
- start,
187
- end,
188
- activeFormats,
189
- };
190
- }
191
-
192
- /**
193
- * Creates a RichText value "record" from the current content and selection
194
- * information
195
- *
196
- *
197
- * @return {Object} A RichText value with formats and selection.
198
- */
199
- createRecord() {
200
- const { preserveWhiteSpace } = this.props;
201
- const value = {
202
- start: this.selectionStart,
203
- end: this.selectionEnd,
204
- ...create( {
205
- html: this.value,
206
- range: null,
207
- preserveWhiteSpace,
208
- } ),
209
- };
210
- const start = Math.min( this.selectionStart, value.text.length );
211
- const end = Math.min( this.selectionEnd, value.text.length );
212
- return { ...value, start, end };
213
- }
214
-
215
- valueToFormat( value ) {
216
- // Remove the outer root tags.
217
- return this.removeRootTagsProducedByAztec( toHTMLString( { value } ) );
218
- }
219
-
220
- getActiveFormatNames( record ) {
221
- const { formatTypes } = this.props;
222
-
223
- return formatTypes
224
- .map( ( { name } ) => name )
225
- .filter( ( name ) => {
226
- return getActiveFormat( record, name ) !== undefined;
227
- } )
228
- .map( ( name ) => gutenbergFormatNamesToAztec[ name ] )
229
- .filter( Boolean );
230
- }
231
-
232
- onFormatChange( record ) {
233
- const { start = 0, end = 0, activeFormats = [] } = record;
234
- const changeHandlers = Object.fromEntries(
235
- Object.entries( this.props ).filter( ( [ key ] ) =>
236
- key.startsWith( 'format_on_change_functions_' )
237
- )
238
- );
239
-
240
- Object.values( changeHandlers ).forEach( ( changeHandler ) => {
241
- changeHandler( record.formats, record.text );
242
- } );
243
-
244
- this.value = this.valueToFormat( record );
245
- this.props.onChange( this.value );
246
- this.setState( { activeFormats } );
247
- this.props.onSelectionChange( start, end );
248
- this.selectionStart = start;
249
- this.selectionEnd = end;
250
-
251
- this.onCreateUndoLevel();
252
-
253
- this.lastAztecEventType = 'format change';
254
- }
255
-
256
- insertString( record, string ) {
257
- if ( record && string ) {
258
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
259
- const toInsert = insert( record, string );
260
- this.onFormatChange( toInsert );
261
- }
262
- }
263
-
264
- onCreateUndoLevel() {
265
- const { __unstableOnCreateUndoLevel: onCreateUndoLevel } = this.props;
266
- // If the content is the same, no level needs to be created.
267
- if ( this.lastHistoryValue?.toString() === this.value?.toString() ) {
268
- return;
269
- }
270
-
271
- onCreateUndoLevel();
272
- this.lastHistoryValue = this.value;
273
- }
274
-
275
- /*
276
- * Cleans up any root tags produced by aztec.
277
- * TODO: This should be removed on a later version when aztec doesn't return the top tag of the text being edited
278
- */
279
- removeRootTagsProducedByAztec( html ) {
280
- let result = this.removeRootTag( this.props.tagName, html );
281
-
282
- if ( this.props.tagsToEliminate ) {
283
- this.props.tagsToEliminate.forEach( ( element ) => {
284
- result = this.removeTag( element, result );
285
- } );
286
- }
287
-
288
- return result;
289
- }
290
-
291
- removeRootTag( tag, html ) {
292
- const openingTagRegexp = RegExp( '^<' + tag + '[^>]*>', 'gim' );
293
- const closingTagRegexp = RegExp( '</' + tag + '>$', 'gim' );
294
-
295
- return html
296
- .replace( openingTagRegexp, '' )
297
- .replace( closingTagRegexp, '' );
298
- }
299
-
300
- removeTag( tag, html ) {
301
- const openingTagRegexp = RegExp( '<' + tag + '>', 'gim' );
302
- const closingTagRegexp = RegExp( '</' + tag + '>', 'gim' );
303
- return html
304
- .replace( openingTagRegexp, '' )
305
- .replace( closingTagRegexp, '' );
306
- }
307
-
308
- /*
309
- * Handles any case where the content of the AztecRN instance has changed
310
- */
311
- onChangeFromAztec( event ) {
312
- if ( this.shouldDropEventFromAztec( event, 'onChange' ) ) {
313
- return;
314
- }
315
-
316
- const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
317
- event.nativeEvent.text
318
- );
319
-
320
- const { __unstableInputRule } = this.props;
321
- const currentValuePosition = {
322
- end: this.isIOS ? this.selectionEnd : this.selectionEnd + 1,
323
- start: this.isIOS ? this.selectionStart : this.selectionStart + 1,
324
- };
325
-
326
- if (
327
- __unstableInputRule &&
328
- __unstableInputRule( {
329
- ...currentValuePosition,
330
- ...this.formatToValue( contentWithoutRootTag ),
331
- } )
332
- ) {
333
- return;
334
- }
335
-
336
- // On iOS, onChange can be triggered after selection changes, even though there are no content changes.
337
- if ( contentWithoutRootTag === this.value?.toString() ) {
338
- return;
339
- }
340
- this.lastEventCount = event.nativeEvent.eventCount;
341
- this.comesFromAztec = true;
342
- this.firedAfterTextChanged = true; // The onChange event always fires after the fact.
343
- this.onTextUpdate( event );
344
- this.lastAztecEventType = 'input';
345
- }
346
-
347
- onTextUpdate( event ) {
348
- const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
349
- event.nativeEvent.text
350
- );
351
-
352
- this.debounceCreateUndoLevel();
353
- const refresh = this.value?.toString() !== contentWithoutRootTag;
354
- this.value = contentWithoutRootTag;
355
-
356
- // We don't want to refresh if our goal is just to create a record.
357
- if ( refresh ) {
358
- this.props.onChange( contentWithoutRootTag );
359
- }
360
- }
361
-
362
- /*
363
- * Handles any case where the content of the AztecRN instance has changed in size
364
- */
365
- onContentSizeChange( contentSize ) {
366
- this.setState( contentSize );
367
- this.lastAztecEventType = 'content size change';
368
- }
369
-
370
- onKeyDown( event ) {
371
- if ( event.defaultPrevented ) {
372
- return;
373
- }
374
-
375
- // Add stubs for conformance in downstream autocompleters logic.
376
- this.customEditableOnKeyDown?.( {
377
- preventDefault: () => undefined,
378
- ...event,
379
- key: RCTAztecView.KeyCodes[ event?.keyCode ],
380
- } );
381
-
382
- this.handleDelete( event );
383
- this.handleEnter( event );
384
- this.handleTriggerKeyCodes( event );
385
- }
386
-
387
- handleEnter( event ) {
388
- if ( event.keyCode !== ENTER ) {
389
- return;
390
- }
391
- const { onEnter } = this.props;
392
-
393
- if ( ! onEnter ) {
394
- return;
395
- }
396
-
397
- onEnter( {
398
- value: this.createRecord(),
399
- onChange: this.onFormatChange,
400
- shiftKey: event.shiftKey,
401
- } );
402
- this.lastAztecEventType = 'input';
403
- }
404
-
405
- handleDelete( event ) {
406
- if ( this.shouldDropEventFromAztec( event, 'handleDelete' ) ) {
407
- return;
408
- }
409
-
410
- const { keyCode } = event;
411
-
412
- if ( keyCode !== DELETE && keyCode !== BACKSPACE ) {
413
- return;
414
- }
415
- const isReverse = keyCode === BACKSPACE;
416
-
417
- const { onDelete } = this.props;
418
- this.lastEventCount = event.nativeEvent.eventCount;
419
- this.comesFromAztec = true;
420
- this.firedAfterTextChanged = event.nativeEvent.firedAfterTextChanged;
421
- const value = this.createRecord();
422
- const { start, end, text, activeFormats } = value;
423
- const hasActiveFormats = activeFormats && !! activeFormats.length;
424
- let newValue;
425
-
426
- // Always handle full content deletion ourselves.
427
- if ( start === 0 && end !== 0 && end >= text.length ) {
428
- newValue = remove( value );
429
- this.onFormatChange( newValue );
430
- event.preventDefault();
431
- return;
432
- }
433
-
434
- // Only process delete if the key press occurs at an uncollapsed edge.
435
- if (
436
- ! isCollapsed( value ) ||
437
- hasActiveFormats ||
438
- ( isReverse && start !== 0 ) ||
439
- ( ! isReverse && end !== text.length )
440
- ) {
441
- return;
442
- }
443
-
444
- if ( onDelete ) {
445
- onDelete( { isReverse, value } );
446
- }
447
-
448
- event.preventDefault();
449
- this.lastAztecEventType = 'input';
450
- }
451
-
452
- handleTriggerKeyCodes( event ) {
453
- const { keyCode } = event;
454
- const triggeredOption = this.suggestionOptions().find( ( option ) => {
455
- const triggeredKeyCode = option.triggerChar.charCodeAt( 0 );
456
- return triggeredKeyCode === keyCode;
457
- } );
458
-
459
- if ( triggeredOption ) {
460
- const record = this.getRecord();
461
- const text = getTextContent( record );
462
- // Only respond to the trigger if the selection is on the start of text or line
463
- // or if the character before is a space.
464
- const useTrigger =
465
- text.length === 0 ||
466
- record.start === 0 ||
467
- text.charAt( record.start - 1 ) === '\n' ||
468
- text.charAt( record.start - 1 ) === ' ';
469
-
470
- if ( useTrigger && triggeredOption.onClick ) {
471
- triggeredOption.onClick();
472
- } else {
473
- this.insertString( record, triggeredOption.triggerChar );
474
- }
475
- }
476
- }
477
-
478
- suggestionOptions() {
479
- const { areMentionsSupported, areXPostsSupported } = this.props;
480
- const allOptions = [
481
- {
482
- supported: areMentionsSupported,
483
- title: __( 'Insert mention' ),
484
- onClick: this.handleUserSuggestion,
485
- triggerChar: '@',
486
- value: 'mention',
487
- label: __( 'Mention' ),
488
- icon: atSymbol,
489
- },
490
- {
491
- supported: areXPostsSupported,
492
- title: __( 'Insert crosspost' ),
493
- onClick: this.handleXpostSuggestion,
494
- triggerChar: '+',
495
- value: 'crosspost',
496
- label: __( 'Crosspost' ),
497
- icon: plus,
498
- },
499
- ];
500
- return allOptions.filter( ( op ) => op.supported );
501
- }
502
-
503
- handleSuggestionFunc( suggestionFunction, prefix ) {
504
- return () => {
505
- const record = this.getRecord();
506
- suggestionFunction()
507
- .then( ( suggestion ) => {
508
- this.insertString( record, `${ prefix }${ suggestion } ` );
509
- } )
510
- .catch( () => {} );
511
- };
512
- }
513
-
514
- /**
515
- * Handles a paste event from the native Aztec Wrapper.
516
- *
517
- * @param {Object} event The paste event which wraps `nativeEvent`.
518
- */
519
- onPaste( event ) {
520
- const { onPaste, onChange } = this.props;
521
- const { activeFormats = [] } = this.state;
522
-
523
- const { pastedText, pastedHtml, files } = event.nativeEvent;
524
- const currentRecord = this.createRecord();
525
-
526
- event.preventDefault();
527
-
528
- // There is a selection, check if a URL is pasted.
529
- if ( ! isCollapsed( currentRecord ) ) {
530
- const trimmedText = ( pastedHtml || pastedText )
531
- .replace( /<[^>]+>/g, '' )
532
- .trim();
533
-
534
- // A URL was pasted, turn the selection into a link.
535
- if ( isURL( trimmedText ) ) {
536
- const linkedRecord = applyFormat( currentRecord, {
537
- type: 'a',
538
- attributes: {
539
- href: decodeEntities( trimmedText ),
540
- },
541
- } );
542
- this.value = this.valueToFormat( linkedRecord );
543
- onChange( this.value );
544
-
545
- // Allows us to ask for this information when we get a report.
546
- window.console.log( 'Created link:\n\n', trimmedText );
547
-
548
- return;
549
- }
550
- }
551
-
552
- if ( onPaste ) {
553
- onPaste( {
554
- value: currentRecord,
555
- onChange: this.onFormatChange,
556
- html: pastedHtml,
557
- plainText: pastedText,
558
- files,
559
- activeFormats,
560
- } );
561
- }
562
- }
563
-
564
- onFocus() {
565
- this.isTouched = true;
566
-
567
- const { unstableOnFocus, onSelectionChange } = this.props;
568
-
569
- if ( unstableOnFocus ) {
570
- unstableOnFocus();
571
- }
572
-
573
- // We know for certain that on focus, the old selection is invalid. It
574
- // will be recalculated on `selectionchange`.
575
-
576
- onSelectionChange( this.selectionStart, this.selectionEnd );
577
-
578
- this.lastAztecEventType = 'focus';
579
- }
580
-
581
- onBlur( event ) {
582
- this.isTouched = false;
583
-
584
- // Check if value is up to date with latest state of native AztecView.
585
- if (
586
- event.nativeEvent.text &&
587
- event.nativeEvent.text !== this.props.value?.toString()
588
- ) {
589
- this.onTextUpdate( event );
590
- }
591
-
592
- if ( this.props.onBlur ) {
593
- this.props.onBlur( event );
594
- }
595
-
596
- this.lastAztecEventType = 'blur';
597
- }
598
-
599
- onSelectionChange( start, end ) {
600
- const hasChanged =
601
- this.selectionStart !== start || this.selectionEnd !== end;
602
-
603
- this.selectionStart = start;
604
- this.selectionEnd = end;
605
-
606
- // This is a manual selection change event if onChange was not triggered just before
607
- // and we did not just trigger a text update
608
- // `onChange` could be the last event and could have been triggered a long time ago so
609
- // this approach is not perfectly reliable.
610
- const isManual =
611
- this.lastAztecEventType !== 'input' &&
612
- this.props.value?.toString() === this.value?.toString();
613
- if ( hasChanged && isManual ) {
614
- const value = this.createRecord();
615
- const activeFormats = getActiveFormats( value );
616
- this.setState( { activeFormats } );
617
- }
618
-
619
- this.props.onSelectionChange( start, end );
620
- }
621
-
622
- shouldDropEventFromAztec( event, logText ) {
623
- const shouldDrop =
624
- ! this.isIOS && event.nativeEvent.eventCount <= this.lastEventCount;
625
- if ( shouldDrop ) {
626
- window.console.log(
627
- `Dropping ${ logText } from Aztec as its event counter is older than latest sent to the native side. Got ${ event.nativeEvent.eventCount } but lastEventCount is ${ this.lastEventCount }.`
628
- );
629
- }
630
- return shouldDrop;
631
- }
632
-
633
- /**
634
- * Determines whether the text input should receive focus after an update.
635
- * For cases where a RichText with a value is merged with an empty one.
636
- *
637
- * @param {Object} prevProps - The previous props of the component.
638
- * @return {boolean} True if the text input should receive focus, false otherwise.
639
- */
640
- shouldFocusTextInputAfterMerge( prevProps ) {
641
- const {
642
- __unstableIsSelected: isSelected,
643
- blockIsSelected,
644
- selectionStart,
645
- selectionEnd,
646
- __unstableMobileNoFocusOnMount,
647
- } = this.props;
648
-
649
- const {
650
- __unstableIsSelected: prevIsSelected,
651
- blockIsSelected: prevBlockIsSelected,
652
- } = prevProps;
653
-
654
- const noSelectionValues =
655
- selectionStart === undefined && selectionEnd === undefined;
656
- const textInputWasNotFocused = ! prevIsSelected && ! isSelected;
657
-
658
- return (
659
- ! __unstableMobileNoFocusOnMount &&
660
- noSelectionValues &&
661
- textInputWasNotFocused &&
662
- ! prevBlockIsSelected &&
663
- blockIsSelected
664
- );
665
- }
666
-
667
- onSelectionChangeFromAztec( start, end, text, event ) {
668
- if ( this.shouldDropEventFromAztec( event, 'onSelectionChange' ) ) {
669
- return;
670
- }
671
-
672
- // `end` can be less than `start` on iOS
673
- // Let's fix that here so `rich-text/slice` can work properly.
674
- const realStart = Math.min( start, end );
675
- const realEnd = Math.max( start, end );
676
-
677
- // Check and dicsard stray event, where the text and selection is equal to the ones already cached.
678
- const contentWithoutRootTag = this.removeRootTagsProducedByAztec(
679
- event.nativeEvent.text
680
- );
681
- if (
682
- contentWithoutRootTag === this.value?.toString() &&
683
- realStart === this.selectionStart &&
684
- realEnd === this.selectionEnd
685
- ) {
686
- return;
687
- }
688
-
689
- this.comesFromAztec = true;
690
- this.firedAfterTextChanged = true; // Selection change event always fires after the fact.
691
-
692
- // Update text before updating selection
693
- // Make sure there are changes made to the content before upgrading it upward.
694
- this.onTextUpdate( event );
695
-
696
- // Aztec can send us selection change events after it has lost focus.
697
- // For instance the autocorrect feature will complete a partially written
698
- // word when resigning focus, causing a selection change event.
699
- // Forwarding this selection change could cause this RichText to regain
700
- // focus and start a focus loop.
701
- //
702
- // See https://github.com/wordpress-mobile/gutenberg-mobile/issues/1696
703
- if ( this.props.__unstableIsSelected ) {
704
- this.onSelectionChange( realStart, realEnd );
705
- }
706
- // Update lastEventCount to prevent Aztec from re-rendering the content it just sent.
707
- this.lastEventCount = event.nativeEvent.eventCount;
708
-
709
- this.lastAztecEventType = 'selection change';
710
- }
711
-
712
- isEmpty() {
713
- return isEmpty( this.formatToValue( this.props.value ) );
714
- }
715
-
716
- formatToValue( value ) {
717
- const { preserveWhiteSpace } = this.props;
718
- // Handle deprecated `children` and `node` sources.
719
- if ( Array.isArray( value ) ) {
720
- return create( {
721
- html: childrenBlock.toHTML( value ),
722
- preserveWhiteSpace,
723
- } );
724
- }
725
-
726
- if ( this.props.format === 'string' ) {
727
- return create( {
728
- html: value,
729
- preserveWhiteSpace,
730
- } );
731
- }
732
-
733
- // Guard for blocks passing `null` in onSplit callbacks. May be removed
734
- // if onSplit is revised to not pass a `null` value.
735
- if ( value === null ) {
736
- return create();
737
- }
738
-
739
- return value;
740
- }
741
-
742
- manipulateEventCounterToForceNativeToRefresh() {
743
- if ( this.isIOS ) {
744
- this.lastEventCount = undefined;
745
- return;
746
- }
747
-
748
- if ( typeof this.lastEventCount !== 'undefined' ) {
749
- this.lastEventCount += 100; // bump by a hundred, hopefully native hasn't bombarded the JS side in the meantime.
750
- } // no need to bump when 'undefined' as native side won't receive the key when the value is undefined, and that will cause force updating anyway,
751
- // see https://github.com/WordPress/gutenberg/blob/82e578dcc75e67891c750a41a04c1e31994192fc/packages/react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java#L213-L215
752
- }
753
-
754
- shouldComponentUpdate( nextProps, nextState ) {
755
- if (
756
- nextProps.tagName !== this.props.tagName ||
757
- nextProps.reversed !== this.props.reversed ||
758
- nextProps.start !== this.props.start
759
- ) {
760
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
761
- this.value = undefined;
762
- return true;
763
- }
764
-
765
- // TODO: Please re-introduce the check to avoid updating the content right after an `onChange` call.
766
- // It was removed in https://github.com/WordPress/gutenberg/pull/12417 to fix undo/redo problem.
767
-
768
- // If the component is changed React side (undo/redo/merging/splitting/custom text actions)
769
- // we need to make sure the native is updated as well.
770
-
771
- // Also, don't trust the "this.lastContent" as on Android, incomplete text events arrive
772
- // with only some of the text, while the virtual keyboard's suggestion system does its magic.
773
- // ** compare with this.lastContent for optimizing performance by not forcing Aztec with text it already has
774
- // , but compare with props.value to not lose "half word" text because of Android virtual keyb autosuggestion behavior
775
- if (
776
- typeof nextProps.value !== 'undefined' &&
777
- typeof this.props.value !== 'undefined' &&
778
- ( ! this.comesFromAztec || ! this.firedAfterTextChanged ) &&
779
- nextProps.value?.toString() !== this.props.value?.toString()
780
- ) {
781
- // Gutenberg seems to try to mirror the caret state even on events that only change the content so,
782
- // let's force caret update if state has selection set.
783
- if (
784
- typeof nextProps.selectionStart !== 'undefined' &&
785
- typeof nextProps.selectionEnd !== 'undefined'
786
- ) {
787
- this.needsSelectionUpdate = true;
788
- }
789
-
790
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
791
- }
792
-
793
- if ( ! this.comesFromAztec ) {
794
- if (
795
- typeof nextProps.selectionStart !== 'undefined' &&
796
- typeof nextProps.selectionEnd !== 'undefined' &&
797
- nextProps.selectionStart !== this.props.selectionStart &&
798
- nextProps.selectionStart !== this.selectionStart &&
799
- nextProps.__unstableIsSelected
800
- ) {
801
- this.needsSelectionUpdate = true;
802
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
803
- }
804
-
805
- // For font size changes from a prop value a force refresh
806
- // is needed without the selection update.
807
- if ( nextProps?.fontSize !== this.props?.fontSize ) {
808
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
809
- }
810
-
811
- if (
812
- ( nextProps?.style?.fontSize !== this.props?.style?.fontSize &&
813
- nextState.currentFontSize !==
814
- this.state.currentFontSize ) ||
815
- nextState.currentFontSize !== this.state.currentFontSize ||
816
- nextProps?.style?.lineHeight !== this.props?.style?.lineHeight
817
- ) {
818
- this.needsSelectionUpdate = true;
819
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
820
- }
821
- }
822
-
823
- return true;
824
- }
825
-
826
- componentDidMount() {
827
- // Request focus if wrapping block is selected and parent hasn't inhibited the focus request. This method of focusing
828
- // is trying to implement the web-side counterpart of BlockList's `focusTabbable` where the BlockList is focusing an
829
- // inputbox by searching the DOM. We don't have the DOM in RN so, using the combination of blockIsSelected and __unstableMobileNoFocusOnMount
830
- // to determine if we should focus the RichText.
831
- if (
832
- this.props.blockIsSelected &&
833
- ! this.props.__unstableMobileNoFocusOnMount
834
- ) {
835
- this._editor.focus();
836
- this.onSelectionChange(
837
- this.props.selectionStart || 0,
838
- this.props.selectionEnd || 0
839
- );
840
- }
841
- }
842
-
843
- componentDidUpdate( prevProps ) {
844
- const { style, tagName } = this.props;
845
- const { currentFontSize } = this.state;
846
-
847
- if ( this.props.value?.toString() !== this.value?.toString() ) {
848
- this.value = this.props.value;
849
- }
850
- const { __unstableIsSelected: prevIsSelected } = prevProps;
851
- const { __unstableIsSelected: isSelected } = this.props;
852
-
853
- if ( isSelected && ! prevIsSelected ) {
854
- this._editor.focus();
855
- // Update selection props explicitly when component is selected as Aztec won't call onSelectionChange
856
- // if its internal value hasn't change. When created, default value is 0, 0.
857
- this.onSelectionChange(
858
- this.props.selectionStart || 0,
859
- this.props.selectionEnd || 0
860
- );
861
- } else if ( this.shouldFocusTextInputAfterMerge( prevProps ) ) {
862
- // Since this is happening when merging blocks, the selection should be at the last character position.
863
- // As a fallback the internal selectionEnd value is used.
864
- const lastCharacterPosition =
865
- this.value?.toString().length ?? this.selectionEnd;
866
- this._editor.focus();
867
- this.props.onSelectionChange(
868
- lastCharacterPosition,
869
- lastCharacterPosition
870
- );
871
- } else if ( ! isSelected && prevIsSelected ) {
872
- this._editor.blur();
873
- }
874
-
875
- // For font size values changes from the font size picker
876
- // we compare previous values to refresh the selected font size,
877
- // this is also used when the tag name changes
878
- // e.g Heading block and a level change like h1->h2.
879
- const currentFontSizeStyle = this.getParsedFontSize( style?.fontSize );
880
- const prevFontSizeStyle = this.getParsedFontSize(
881
- prevProps?.style?.fontSize
882
- );
883
- const isDifferentTag = prevProps.tagName !== tagName;
884
- if (
885
- ( currentFontSize &&
886
- ( currentFontSizeStyle || prevFontSizeStyle ) &&
887
- currentFontSizeStyle !== currentFontSize ) ||
888
- isDifferentTag
889
- ) {
890
- this.setState( {
891
- currentFontSize: this.getFontSize( this.props ),
892
- } );
893
- }
894
- }
895
-
896
- componentWillUnmount() {
897
- const { clearCurrentSelectionOnUnmount } = this.props;
898
-
899
- // There are cases when the component is unmounted e.g. scrolling in a
900
- // long post due to virtualization, so the block selection needs to be cleared
901
- // so it doesn't auto-focus when it's added back.
902
- if ( this._editor?.isFocused() ) {
903
- clearCurrentSelectionOnUnmount?.();
904
- }
905
- }
906
-
907
- getHtmlToRender( record, tagName ) {
908
- // Save back to HTML from React tree.
909
- let value = this.valueToFormat( record );
910
-
911
- if ( value === undefined ) {
912
- this.manipulateEventCounterToForceNativeToRefresh(); // force a refresh on the native side
913
- value = '';
914
- }
915
- // On android if content is empty we need to send no content or else the placeholder will not show.
916
- if (
917
- ! this.isIOS &&
918
- ( value?.toString() === '' ||
919
- value?.toString() === EMPTY_PARAGRAPH_TAGS )
920
- ) {
921
- return '';
922
- }
923
-
924
- if ( tagName ) {
925
- let extraAttributes = ``;
926
- if ( tagName === `ol` ) {
927
- if ( this.props.reversed ) {
928
- extraAttributes += ` reversed`;
929
- }
930
- if ( this.props.start ) {
931
- extraAttributes += ` start=${ this.props.start }`;
932
- }
933
- }
934
- value = `<${ tagName }${ extraAttributes }>${ value }</${ tagName }>`;
935
- }
936
- return value;
937
- }
938
-
939
- getEditableProps() {
940
- return {
941
- // Overridable props.
942
- style: {},
943
- className: 'rich-text',
944
- onKeyDown: () => null,
945
- };
946
- }
947
-
948
- getParsedFontSize( fontSize ) {
949
- const { height, width } = Dimensions.get( 'window' );
950
- const cssUnitOptions = { height, width, fontSize: DEFAULT_FONT_SIZE };
951
-
952
- if ( ! fontSize ) {
953
- return fontSize;
954
- }
955
-
956
- const selectedPxValue =
957
- getPxFromCssUnit( fontSize, cssUnitOptions ) ?? DEFAULT_FONT_SIZE;
958
-
959
- return parseFloat( selectedPxValue );
960
- }
961
-
962
- getFontSize( props ) {
963
- const { baseGlobalStyles, tagName, fontSize, style } = props;
964
- const tagNameFontSize =
965
- baseGlobalStyles?.elements?.[ tagName ]?.typography?.fontSize;
966
-
967
- let newFontSize = DEFAULT_FONT_SIZE;
968
-
969
- // Disables line-height rendering for pre elements until we fix some issues with AztecAndroid.
970
- if ( tagName === 'pre' && ! this.isIOS ) {
971
- return undefined;
972
- }
973
-
974
- // For block-based themes, get the default editor font size.
975
- if ( baseGlobalStyles?.typography?.fontSize && tagName === 'p' ) {
976
- newFontSize = baseGlobalStyles?.typography?.fontSize;
977
- }
978
-
979
- // For block-based themes, get the default element font size
980
- // e.g h1, h2.
981
- if ( tagNameFontSize ) {
982
- newFontSize = tagNameFontSize;
983
- }
984
-
985
- // For font size values provided from the styles,
986
- // usually from values set from the font size picker.
987
- if ( style?.fontSize ) {
988
- newFontSize = style.fontSize;
989
- }
990
-
991
- // Fall-back to a font size provided from its props (if there's any)
992
- // and there are no other default values to use.
993
- if ( fontSize && ! tagNameFontSize && ! style?.fontSize ) {
994
- newFontSize = fontSize;
995
- }
996
-
997
- // We need to always convert to px units because the selected value
998
- // could be coming from the web where it could be stored as a different unit.
999
- const selectedPxValue = this.getParsedFontSize( newFontSize );
1000
-
1001
- return selectedPxValue;
1002
- }
1003
-
1004
- getLineHeight() {
1005
- const { baseGlobalStyles, tagName, lineHeight, style } = this.props;
1006
- const tagNameLineHeight =
1007
- baseGlobalStyles?.elements?.[ tagName ]?.typography?.lineHeight;
1008
- let newLineHeight;
1009
-
1010
- // Disables line-height rendering for pre elements until we fix some issues with AztecAndroid.
1011
- if ( tagName === 'pre' && ! this.isIOS ) {
1012
- return undefined;
1013
- }
1014
-
1015
- if ( ! this.getIsBlockBasedTheme() ) {
1016
- return;
1017
- }
1018
-
1019
- // For block-based themes, get the default editor line height.
1020
- if ( baseGlobalStyles?.typography?.lineHeight && tagName === 'p' ) {
1021
- newLineHeight = parseFloat(
1022
- baseGlobalStyles?.typography?.lineHeight
1023
- );
1024
- }
1025
-
1026
- // For block-based themes, get the default element line height
1027
- // e.g h1, h2.
1028
- if ( tagNameLineHeight ) {
1029
- newLineHeight = parseFloat( tagNameLineHeight );
1030
- }
1031
-
1032
- // For line height values provided from the styles,
1033
- // usually from values set from the line height picker.
1034
- if ( style?.lineHeight ) {
1035
- newLineHeight = parseFloat( style.lineHeight );
1036
- }
1037
-
1038
- // Fall-back to a line height provided from its props (if there's any)
1039
- // and there are no other default values to use.
1040
- if ( lineHeight && ! tagNameLineHeight && ! style?.lineHeight ) {
1041
- newLineHeight = lineHeight;
1042
- }
1043
-
1044
- // Check the final value is not over the minimum supported value.
1045
- if ( newLineHeight && newLineHeight < MIN_LINE_HEIGHT ) {
1046
- newLineHeight = MIN_LINE_HEIGHT;
1047
- }
1048
-
1049
- // Until we parse CSS values correctly, avoid passing NaN values to Aztec
1050
- if ( isNaN( newLineHeight ) ) {
1051
- return undefined;
1052
- }
1053
-
1054
- return newLineHeight;
1055
- }
1056
-
1057
- getIsBlockBasedTheme() {
1058
- const { baseGlobalStyles } = this.props;
1059
-
1060
- return (
1061
- baseGlobalStyles && Object.entries( baseGlobalStyles ).length !== 0
1062
- );
1063
- }
1064
-
1065
- getBlockUseDefaultFont() {
1066
- // For block-based themes it enables using the defaultFont
1067
- // in Aztec for iOS so it allows customizing the font size
1068
- // for the Preformatted/Code and Heading blocks.
1069
- if ( ! this.isIOS ) {
1070
- return;
1071
- }
1072
-
1073
- const { tagName } = this.props;
1074
- const isBlockBasedTheme = this.getIsBlockBasedTheme();
1075
- const tagsToMatch = /pre|h([1-6])$/gm;
1076
-
1077
- return isBlockBasedTheme && tagsToMatch.test( tagName );
1078
- }
1079
-
1080
- getLinkTextColor( defaultColor ) {
1081
- const { style } = this.props;
1082
- const customColor = style?.linkColor && colord( style.linkColor );
1083
-
1084
- return customColor && customColor.isValid()
1085
- ? customColor.toHex()
1086
- : defaultColor;
1087
- }
1088
-
1089
- getPlaceholderTextColor() {
1090
- const {
1091
- baseGlobalStyles,
1092
- getStylesFromColorScheme,
1093
- placeholderTextColor,
1094
- style,
1095
- } = this.props;
1096
-
1097
- // Default placeholder text color.
1098
- const placeholderStyle = getStylesFromColorScheme(
1099
- styles.richTextPlaceholder,
1100
- styles.richTextPlaceholderDark
1101
- );
1102
- const { color: defaultPlaceholderTextColor } = placeholderStyle;
1103
- // Custom 63% opacity for theme and inherited colors.
1104
- const placeholderOpacity = 'A1';
1105
-
1106
- // Determine inherited placeholder color if available.
1107
- const inheritPlaceholderColor = style?.placeholderColor
1108
- ? `${ style.placeholderColor }${ placeholderOpacity }`
1109
- : undefined;
1110
-
1111
- // If using block-based themes, derive the placeholder color from global styles.
1112
- const globalStylesPlaceholderColor = baseGlobalStyles?.color?.text
1113
- ? `${ baseGlobalStyles.color.text }${ placeholderOpacity }`
1114
- : undefined;
1115
-
1116
- return (
1117
- inheritPlaceholderColor ??
1118
- placeholderTextColor ??
1119
- globalStylesPlaceholderColor ??
1120
- defaultPlaceholderTextColor
1121
- );
1122
- }
1123
-
1124
- render() {
1125
- const {
1126
- tagName,
1127
- style,
1128
- __unstableIsSelected: isSelected,
1129
- children,
1130
- getStylesFromColorScheme,
1131
- minWidth,
1132
- maxWidth,
1133
- formatTypes,
1134
- parentBlockStyles,
1135
- accessibilityLabel,
1136
- disableEditingMenu = false,
1137
- baseGlobalStyles,
1138
- selectionStart,
1139
- selectionEnd,
1140
- disableSuggestions,
1141
- containerWidth,
1142
- } = this.props;
1143
- const { currentFontSize } = this.state;
1144
-
1145
- const record = this.getRecord();
1146
- const html = this.getHtmlToRender( record, tagName );
1147
- const editableProps = this.getEditableProps();
1148
- const blockUseDefaultFont = this.getBlockUseDefaultFont();
1149
-
1150
- const fontSize = currentFontSize;
1151
- const lineHeight = this.getLineHeight();
1152
-
1153
- const {
1154
- color: defaultColor,
1155
- textDecorationColor: defaultTextDecorationColor,
1156
- fontFamily: defaultFontFamily,
1157
- } = getStylesFromColorScheme( styles.richText, styles.richTextDark );
1158
- const linkTextColor = this.getLinkTextColor(
1159
- defaultTextDecorationColor
1160
- );
1161
-
1162
- const currentSelectionStart = selectionStart ?? 0;
1163
- const currentSelectionEnd = selectionEnd ?? 0;
1164
- let selection = null;
1165
- if ( this.needsSelectionUpdate ) {
1166
- this.needsSelectionUpdate = false;
1167
- selection = {
1168
- start: currentSelectionStart,
1169
- end: currentSelectionEnd,
1170
- };
1171
-
1172
- // On AztecAndroid, setting the caret to an out-of-bounds position will crash the editor so, let's check for some cases.
1173
- if ( ! this.isIOS ) {
1174
- // The following regular expression is used in Aztec here:
1175
- // https://github.com/wordpress-mobile/AztecEditor-Android/blob/b1fad439d56fa6d4aa0b78526fef355c59d00dd3/aztec/src/main/kotlin/org/wordpress/aztec/AztecParser.kt#L656
1176
- const brBeforeParaMatches = html.match( /(<br>)+<\/p>$/g );
1177
- if ( brBeforeParaMatches ) {
1178
- console.warn(
1179
- 'Oops, BR tag(s) at the end of content. Aztec will remove them, adapting the selection...'
1180
- );
1181
- const count = (
1182
- brBeforeParaMatches[ 0 ].match( /br/g ) || []
1183
- ).length;
1184
- if ( count > 0 ) {
1185
- let newSelectionStart = currentSelectionStart - count;
1186
- if ( newSelectionStart < 0 ) {
1187
- newSelectionStart = 0;
1188
- }
1189
- let newSelectionEnd = currentSelectionEnd - count;
1190
- if ( newSelectionEnd < 0 ) {
1191
- newSelectionEnd = 0;
1192
- }
1193
- selection = {
1194
- start: newSelectionStart,
1195
- end: newSelectionEnd,
1196
- };
1197
- }
1198
- }
1199
- }
1200
- }
1201
-
1202
- if ( this.comesFromAztec ) {
1203
- this.comesFromAztec = false;
1204
- this.firedAfterTextChanged = false;
1205
- }
1206
-
1207
- // Logic below assures that `RichText` width will always have equal value when container is almost fully filled.
1208
- const width =
1209
- maxWidth && this.state.width && maxWidth - this.state.width < 10
1210
- ? maxWidth
1211
- : this.state.width;
1212
- const containerStyles = [
1213
- style?.padding &&
1214
- style?.backgroundColor && {
1215
- padding: style.padding,
1216
- backgroundColor: style.backgroundColor,
1217
- },
1218
- containerWidth && {
1219
- width: containerWidth,
1220
- },
1221
- ];
1222
-
1223
- const defaultSelectionColor = getStylesFromColorScheme(
1224
- styles[ 'rich-text-selection' ],
1225
- styles[ 'rich-text-selection--dark' ]
1226
- ).color;
1227
- const selectionColor = getSelectionColor(
1228
- this.props.selectionColor,
1229
- defaultSelectionColor,
1230
- baseGlobalStyles,
1231
- this.getIsBlockBasedTheme()
1232
- );
1233
-
1234
- const EditableView = ( props ) => {
1235
- this.customEditableOnKeyDown = props?.onKeyDown;
1236
-
1237
- return <></>;
1238
- };
1239
-
1240
- return (
1241
- <View style={ containerStyles }>
1242
- { children &&
1243
- children( {
1244
- isSelected,
1245
- value: record,
1246
- onChange: this.onFormatChange,
1247
- onFocus: () => {},
1248
- editableProps,
1249
- editableTagName: EditableView,
1250
- } ) }
1251
- <RCTAztecView
1252
- accessibilityLabel={ accessibilityLabel }
1253
- ref={ ( ref ) => {
1254
- this._editor = ref;
1255
-
1256
- if ( this.props.nativeEditorRef ) {
1257
- this.props.nativeEditorRef( ref );
1258
- }
1259
- } }
1260
- style={ {
1261
- backgroundColor: styles.richText.backgroundColor,
1262
- ...style,
1263
- ...( this.isIOS && minWidth && maxWidth
1264
- ? { width }
1265
- : { maxWidth } ),
1266
- minHeight: this.state.height,
1267
- } }
1268
- blockUseDefaultFont={ blockUseDefaultFont }
1269
- text={ {
1270
- text: html,
1271
- eventCount: this.lastEventCount,
1272
- selection,
1273
- linkTextColor,
1274
- tag: tagName,
1275
- } }
1276
- placeholder={ this.props.placeholder }
1277
- placeholderTextColor={ this.getPlaceholderTextColor() }
1278
- deleteEnter={ this.props.deleteEnter }
1279
- onChange={ this.onChangeFromAztec }
1280
- onFocus={ this.onFocus }
1281
- onBlur={ this.onBlur }
1282
- onKeyDown={ this.onKeyDown }
1283
- triggerKeyCodes={
1284
- disableEditingMenu
1285
- ? []
1286
- : this.suggestionOptions().map(
1287
- ( op ) => op.triggerChar
1288
- )
1289
- }
1290
- onPaste={ this.onPaste }
1291
- activeFormats={ this.getActiveFormatNames( record ) }
1292
- onContentSizeChange={ this.onContentSizeChange }
1293
- onSelectionChange={ this.onSelectionChangeFromAztec }
1294
- blockType={ { tag: tagName } }
1295
- color={
1296
- ( style && style.color ) ||
1297
- ( parentBlockStyles && parentBlockStyles.color ) ||
1298
- ( baseGlobalStyles && baseGlobalStyles?.color?.text ) ||
1299
- defaultColor
1300
- }
1301
- maxImagesWidth={ 200 }
1302
- fontFamily={ this.props.fontFamily || defaultFontFamily }
1303
- fontSize={ fontSize }
1304
- lineHeight={ lineHeight }
1305
- fontWeight={ this.props.fontWeight }
1306
- fontStyle={ this.props.fontStyle }
1307
- disableEditingMenu={ disableEditingMenu }
1308
- isMultiline={ false }
1309
- textAlign={ this.props.textAlign }
1310
- { ...( this.isIOS ? { maxWidth } : {} ) }
1311
- minWidth={ minWidth }
1312
- id={ this.props.id }
1313
- selectionColor={ selectionColor }
1314
- disableAutocorrection={ this.props.disableAutocorrection }
1315
- />
1316
- { isSelected && (
1317
- <>
1318
- <FormatEdit
1319
- forwardedRef={ this._editor }
1320
- formatTypes={ formatTypes }
1321
- value={ record }
1322
- onChange={ this.onFormatChange }
1323
- onFocus={ () => {} }
1324
- />
1325
- { ! disableSuggestions && (
1326
- <BlockFormatControls>
1327
- <ToolbarButtonWithOptions
1328
- options={ this.suggestionOptions() }
1329
- />
1330
- </BlockFormatControls>
1331
- ) }
1332
- </>
1333
- ) }
1334
- </View>
1335
- );
1336
- }
1337
- }
1338
-
1339
- RichText.defaultProps = {
1340
- format: 'string',
1341
- value: '',
1342
- tagName: 'div',
1343
- };
1344
-
1345
- const withFormatTypes = ( WrappedComponent ) =>
1346
- function WithFormatTypes( props ) {
1347
- const {
1348
- clientId,
1349
- identifier,
1350
- withoutInteractiveFormatting,
1351
- allowedFormats,
1352
- } = props;
1353
- const { formatTypes } = useFormatTypes( {
1354
- clientId,
1355
- identifier,
1356
- withoutInteractiveFormatting,
1357
- allowedFormats,
1358
- } );
1359
-
1360
- return <WrappedComponent { ...props } formatTypes={ formatTypes } />;
1361
- };
1362
-
1363
- export default compose( [
1364
- withSelect( ( select, { clientId } ) => {
1365
- const { getBlockParents, getBlock, getSettings } =
1366
- select( 'core/block-editor' );
1367
- const parents = getBlockParents( clientId, true );
1368
- const parentBlock = parents ? getBlock( parents[ 0 ] ) : undefined;
1369
- const parentBlockStyles = parentBlock?.attributes?.childrenStyles;
1370
-
1371
- const settings = getSettings();
1372
- const baseGlobalStyles = settings?.__experimentalGlobalStylesBaseStyles;
1373
-
1374
- const colorPalettes = settings?.__experimentalFeatures?.color?.palette;
1375
- const colorPalette = colorPalettes
1376
- ? flatColorPalettes( colorPalettes )
1377
- : settings?.colors;
1378
-
1379
- return {
1380
- areMentionsSupported: settings?.capabilities?.mentions === true,
1381
- areXPostsSupported: settings?.capabilities?.xposts === true,
1382
- parentBlockStyles,
1383
- baseGlobalStyles,
1384
- colorPalette,
1385
- };
1386
- } ),
1387
- withPreferredColorScheme,
1388
- withFormatTypes,
1389
- ] )( RichText );