@wordpress/block-editor 15.21.0 → 15.22.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 (836) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/README.md +2 -2
  3. package/build/components/block-card/index.cjs +4 -5
  4. package/build/components/block-card/index.cjs.map +2 -2
  5. package/build/components/block-compare/index.cjs +2 -2
  6. package/build/components/block-compare/index.cjs.map +2 -2
  7. package/build/components/block-editing-mode/index.cjs +13 -7
  8. package/build/components/block-editing-mode/index.cjs.map +2 -2
  9. package/build/components/block-inspector/index.cjs +35 -20
  10. package/build/components/block-inspector/index.cjs.map +2 -2
  11. package/build/components/block-mover/mover-description.cjs +6 -6
  12. package/build/components/block-mover/mover-description.cjs.map +1 -1
  13. package/build/components/block-patterns-list/index.cjs +1 -1
  14. package/build/components/block-patterns-list/index.cjs.map +2 -2
  15. package/build/components/block-patterns-paging/index.cjs +4 -4
  16. package/build/components/block-patterns-paging/index.cjs.map +2 -2
  17. package/build/components/block-popover/use-popover-scroll.cjs.map +1 -1
  18. package/build/components/block-quick-navigation/index.cjs +7 -5
  19. package/build/components/block-quick-navigation/index.cjs.map +2 -2
  20. package/build/components/block-rename/modal.cjs +0 -1
  21. package/build/components/block-rename/modal.cjs.map +2 -2
  22. package/build/components/block-switcher/block-transformations-menu.cjs +16 -15
  23. package/build/components/block-switcher/block-transformations-menu.cjs.map +2 -2
  24. package/build/components/block-switcher/index.cjs +4 -4
  25. package/build/components/block-switcher/index.cjs.map +2 -2
  26. package/build/components/block-toolbar/block-toolbar-icon.cjs +14 -6
  27. package/build/components/block-toolbar/block-toolbar-icon.cjs.map +2 -2
  28. package/build/components/block-toolbar/edit-section-button.cjs.map +1 -1
  29. package/build/components/block-tools/use-block-toolbar-popover-props.cjs +10 -4
  30. package/build/components/block-tools/use-block-toolbar-popover-props.cjs.map +2 -2
  31. package/build/components/child-layout-control/index.cjs +51 -19
  32. package/build/components/child-layout-control/index.cjs.map +2 -2
  33. package/build/components/colors-gradients/control.cjs +25 -14
  34. package/build/components/colors-gradients/control.cjs.map +2 -2
  35. package/build/components/colors-gradients/dropdown.cjs +4 -1
  36. package/build/components/colors-gradients/dropdown.cjs.map +3 -3
  37. package/build/components/contrast-checker/index.cjs +22 -4
  38. package/build/components/contrast-checker/index.cjs.map +2 -2
  39. package/build/components/date-format-picker/index.cjs +0 -1
  40. package/build/components/date-format-picker/index.cjs.map +2 -2
  41. package/build/components/dimensions-tool/index.cjs +4 -5
  42. package/build/components/dimensions-tool/index.cjs.map +2 -2
  43. package/build/components/dimensions-tool/scale-tool.cjs +1 -1
  44. package/build/components/dimensions-tool/scale-tool.cjs.map +2 -2
  45. package/build/components/global-styles/advanced-panel.cjs +23 -15
  46. package/build/components/global-styles/advanced-panel.cjs.map +2 -2
  47. package/build/components/global-styles/background-panel.cjs +154 -26
  48. package/build/components/global-styles/background-panel.cjs.map +3 -3
  49. package/build/components/global-styles/border-panel.cjs +2 -0
  50. package/build/components/global-styles/border-panel.cjs.map +2 -2
  51. package/build/components/global-styles/color-gradient-dropdown-item.cjs +227 -0
  52. package/build/components/global-styles/color-gradient-dropdown-item.cjs.map +7 -0
  53. package/build/components/global-styles/color-panel.cjs +98 -375
  54. package/build/components/global-styles/color-panel.cjs.map +3 -3
  55. package/build/components/global-styles/dimensions-panel.cjs +2 -5
  56. package/build/components/global-styles/dimensions-panel.cjs.map +2 -2
  57. package/build/components/global-styles/hooks.cjs +34 -0
  58. package/build/components/global-styles/hooks.cjs.map +2 -2
  59. package/build/components/global-styles/shadow-panel-components.cjs.map +2 -2
  60. package/build/components/global-styles/typography-panel.cjs +82 -10
  61. package/build/components/global-styles/typography-panel.cjs.map +3 -3
  62. package/build/components/grid/grid-item-resizer.cjs.map +1 -1
  63. package/build/components/grid/grid-visualizer.cjs.map +1 -1
  64. package/build/components/iframe/index.cjs +6 -3
  65. package/build/components/iframe/index.cjs.map +3 -3
  66. package/build/components/image-editor/use-transform-image.cjs.map +1 -1
  67. package/build/components/inner-blocks/use-inner-block-template-sync.cjs +3 -1
  68. package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +2 -2
  69. package/build/components/inserter/get-appender-label.cjs.map +1 -1
  70. package/build/components/inserter/hooks/use-patterns-state.cjs +1 -1
  71. package/build/components/inserter/hooks/use-patterns-state.cjs.map +2 -2
  72. package/build/components/inserter/index.cjs +179 -220
  73. package/build/components/inserter/index.cjs.map +3 -3
  74. package/build/components/inserter/media-tab/media-preview.cjs.map +2 -2
  75. package/build/components/inserter/search-items.cjs.map +1 -1
  76. package/build/components/inserter/search-results.cjs +1 -1
  77. package/build/components/inserter/search-results.cjs.map +2 -2
  78. package/build/components/inspector-controls/fill.cjs +1 -3
  79. package/build/components/inspector-controls/fill.cjs.map +2 -2
  80. package/build/components/inspector-controls/groups.cjs +2 -0
  81. package/build/components/inspector-controls/groups.cjs.map +2 -2
  82. package/build/components/inspector-controls-tabs/index.cjs.map +2 -2
  83. package/build/components/inspector-controls-tabs/styles-tab.cjs +76 -32
  84. package/build/components/inspector-controls-tabs/styles-tab.cjs.map +2 -2
  85. package/build/components/keyboard-shortcuts/index.cjs.map +1 -1
  86. package/build/components/line-height-control/index.cjs.map +1 -1
  87. package/build/components/link-control/index.cjs +2 -3
  88. package/build/components/link-control/index.cjs.map +2 -2
  89. package/build/components/link-control/normalize-url.cjs.map +1 -1
  90. package/build/components/list-view/block-select-button.cjs +9 -20
  91. package/build/components/list-view/block-select-button.cjs.map +3 -3
  92. package/build/components/list-view/block.cjs +2 -1
  93. package/build/components/list-view/block.cjs.map +2 -2
  94. package/build/components/list-view/utils.cjs.map +1 -1
  95. package/build/components/preset-input-control/custom-value-controls.cjs.map +2 -2
  96. package/build/components/provider/index.cjs.map +1 -1
  97. package/build/components/provider/use-block-sync.cjs +14 -3
  98. package/build/components/provider/use-block-sync.cjs.map +2 -2
  99. package/build/components/rich-text/event-listeners/before-input-rules.cjs +5 -5
  100. package/build/components/rich-text/event-listeners/before-input-rules.cjs.map +3 -3
  101. package/build/components/rich-text/event-listeners/delete.cjs +4 -4
  102. package/build/components/rich-text/event-listeners/delete.cjs.map +3 -3
  103. package/build/components/rich-text/event-listeners/enter.cjs +7 -2
  104. package/build/components/rich-text/event-listeners/enter.cjs.map +2 -2
  105. package/build/components/rich-text/event-listeners/input-events.cjs +4 -4
  106. package/build/components/rich-text/event-listeners/input-events.cjs.map +3 -3
  107. package/build/components/rich-text/event-listeners/input-rules.cjs +17 -4
  108. package/build/components/rich-text/event-listeners/input-rules.cjs.map +3 -3
  109. package/build/components/rich-text/event-listeners/insert-replacement-text.cjs +4 -4
  110. package/build/components/rich-text/event-listeners/insert-replacement-text.cjs.map +3 -3
  111. package/build/components/rich-text/event-listeners/paste-handler.cjs.map +1 -1
  112. package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs +4 -4
  113. package/build/components/rich-text/event-listeners/remove-browser-shortcuts.cjs.map +3 -3
  114. package/build/components/rich-text/event-listeners/shortcuts.cjs +4 -4
  115. package/build/components/rich-text/event-listeners/shortcuts.cjs.map +3 -3
  116. package/build/components/rich-text/event-listeners/undo-automatic-change.cjs +4 -4
  117. package/build/components/rich-text/event-listeners/undo-automatic-change.cjs.map +3 -3
  118. package/build/components/rich-text/index.cjs +1 -23
  119. package/build/components/rich-text/index.cjs.map +2 -2
  120. package/build/components/rich-text/prevent-event-discovery.cjs +1 -1
  121. package/build/components/rich-text/prevent-event-discovery.cjs.map +1 -1
  122. package/build/components/url-popover/image-url-input-ui.cjs +0 -2
  123. package/build/components/url-popover/image-url-input-ui.cjs.map +2 -2
  124. package/build/components/use-block-commands/index.cjs +5 -5
  125. package/build/components/use-block-commands/index.cjs.map +2 -2
  126. package/build/components/use-block-display-information/index.cjs +10 -3
  127. package/build/components/use-block-display-information/index.cjs.map +2 -2
  128. package/build/components/writing-flow/use-tab-nav.cjs.map +1 -1
  129. package/build/hooks/anchor.cjs +12 -17
  130. package/build/hooks/anchor.cjs.map +2 -2
  131. package/build/hooks/background.cjs +124 -75
  132. package/build/hooks/background.cjs.map +3 -3
  133. package/build/hooks/block-fields/index.cjs +13 -2
  134. package/build/hooks/block-fields/index.cjs.map +2 -2
  135. package/build/hooks/border.cjs +0 -3
  136. package/build/hooks/border.cjs.map +2 -2
  137. package/build/hooks/color.cjs +0 -165
  138. package/build/hooks/color.cjs.map +3 -3
  139. package/build/hooks/contrast-checker.cjs +31 -28
  140. package/build/hooks/contrast-checker.cjs.map +3 -3
  141. package/build/hooks/custom-class-name.cjs +0 -1
  142. package/build/hooks/custom-class-name.cjs.map +2 -2
  143. package/build/hooks/dimensions.cjs +13 -5
  144. package/build/hooks/dimensions.cjs.map +2 -2
  145. package/build/hooks/elements.cjs +142 -0
  146. package/build/hooks/elements.cjs.map +7 -0
  147. package/build/hooks/fit-text.cjs +11 -0
  148. package/build/hooks/fit-text.cjs.map +2 -2
  149. package/build/hooks/grid-visualizer.cjs +21 -11
  150. package/build/hooks/grid-visualizer.cjs.map +2 -2
  151. package/build/hooks/layout-child.cjs +65 -10
  152. package/build/hooks/layout-child.cjs.map +2 -2
  153. package/build/hooks/layout.cjs +6 -3
  154. package/build/hooks/layout.cjs.map +2 -2
  155. package/build/hooks/list-view.cjs +10 -7
  156. package/build/hooks/list-view.cjs.map +2 -2
  157. package/build/hooks/position.cjs +19 -22
  158. package/build/hooks/position.cjs.map +2 -2
  159. package/build/hooks/spacing-visualizer.cjs.map +1 -1
  160. package/build/hooks/state-utils.cjs.map +1 -1
  161. package/build/hooks/states.cjs +2 -2
  162. package/build/hooks/states.cjs.map +2 -2
  163. package/build/hooks/style.cjs +50 -6
  164. package/build/hooks/style.cjs.map +2 -2
  165. package/build/hooks/supports.cjs +0 -7
  166. package/build/hooks/supports.cjs.map +2 -2
  167. package/build/hooks/typography.cjs +62 -10
  168. package/build/hooks/typography.cjs.map +3 -3
  169. package/build/layouts/flex.cjs +99 -6
  170. package/build/layouts/flex.cjs.map +2 -2
  171. package/build/private-apis.cjs +4 -0
  172. package/build/private-apis.cjs.map +2 -2
  173. package/build/store/actions.cjs +7 -3
  174. package/build/store/actions.cjs.map +2 -2
  175. package/build/store/private-actions.cjs +1 -2
  176. package/build/store/private-actions.cjs.map +2 -2
  177. package/build/store/private-selectors.cjs +42 -2
  178. package/build/store/private-selectors.cjs.map +2 -2
  179. package/build/store/reducer.cjs +14 -6
  180. package/build/store/reducer.cjs.map +2 -2
  181. package/build/store/selectors.cjs +60 -41
  182. package/build/store/selectors.cjs.map +2 -2
  183. package/build/utils/block-bindings.cjs +9 -9
  184. package/build/utils/block-bindings.cjs.map +3 -3
  185. package/build/utils/color-values.cjs +10 -1
  186. package/build/utils/color-values.cjs.map +3 -3
  187. package/build/utils/dom.cjs +2 -5
  188. package/build/utils/dom.cjs.map +3 -3
  189. package/build/utils/fit-text-frontend.cjs +6 -2
  190. package/build/utils/fit-text-frontend.cjs.map +3 -3
  191. package/build/utils/fit-text-utils.cjs +1 -1
  192. package/build/utils/fit-text-utils.cjs.map +3 -3
  193. package/build/utils/format-font-style.cjs +1 -1
  194. package/build/utils/format-font-style.cjs.map +3 -3
  195. package/build/utils/format-font-weight.cjs +1 -1
  196. package/build/utils/format-font-weight.cjs.map +3 -3
  197. package/build/utils/get-editor-region.cjs +4 -2
  198. package/build/utils/get-editor-region.cjs.map +3 -3
  199. package/build/utils/get-font-styles-and-weights.cjs +8 -12
  200. package/build/utils/get-font-styles-and-weights.cjs.map +3 -3
  201. package/build/utils/get-px-from-css-unit.cjs +1 -1
  202. package/build/utils/get-px-from-css-unit.cjs.map +1 -1
  203. package/build/utils/index.cjs +1 -1
  204. package/build/utils/index.cjs.map +1 -1
  205. package/build/utils/math.cjs +1 -1
  206. package/build/utils/math.cjs.map +3 -3
  207. package/build/utils/object.cjs +8 -8
  208. package/build/utils/object.cjs.map +3 -3
  209. package/build/utils/order-inserter-block-items.cjs +1 -1
  210. package/build/utils/order-inserter-block-items.cjs.map +3 -3
  211. package/build/utils/pasting.cjs +4 -2
  212. package/build/utils/pasting.cjs.map +3 -3
  213. package/build/utils/selection.cjs +3 -2
  214. package/build/utils/selection.cjs.map +3 -3
  215. package/build/utils/sorting.cjs +9 -3
  216. package/build/utils/sorting.cjs.map +3 -3
  217. package/build/utils/transform-styles/index.cjs +3 -2
  218. package/build/utils/transform-styles/index.cjs.map +3 -3
  219. package/build/utils/transform-styles/postcss-urlrebase.d.cjs +2 -0
  220. package/build/utils/transform-styles/postcss-urlrebase.d.cjs.map +7 -0
  221. package/build/{components/rich-text/native/index.cjs → utils/transform-styles/types.cjs} +4 -13
  222. package/build/utils/transform-styles/types.cjs.map +7 -0
  223. package/build/utils/types.cjs +19 -0
  224. package/build/utils/types.cjs.map +7 -0
  225. package/build-module/components/block-card/index.mjs +5 -6
  226. package/build-module/components/block-card/index.mjs.map +2 -2
  227. package/build-module/components/block-compare/index.mjs +1 -1
  228. package/build-module/components/block-compare/index.mjs.map +2 -2
  229. package/build-module/components/block-editing-mode/index.mjs +14 -8
  230. package/build-module/components/block-editing-mode/index.mjs.map +2 -2
  231. package/build-module/components/block-inspector/index.mjs +35 -21
  232. package/build-module/components/block-inspector/index.mjs.map +2 -2
  233. package/build-module/components/block-mover/mover-description.mjs +6 -6
  234. package/build-module/components/block-mover/mover-description.mjs.map +1 -1
  235. package/build-module/components/block-patterns-list/index.mjs +1 -1
  236. package/build-module/components/block-patterns-list/index.mjs.map +2 -2
  237. package/build-module/components/block-patterns-paging/index.mjs +4 -4
  238. package/build-module/components/block-patterns-paging/index.mjs.map +2 -2
  239. package/build-module/components/block-popover/use-popover-scroll.mjs.map +1 -1
  240. package/build-module/components/block-quick-navigation/index.mjs +8 -6
  241. package/build-module/components/block-quick-navigation/index.mjs.map +2 -2
  242. package/build-module/components/block-rename/modal.mjs +0 -1
  243. package/build-module/components/block-rename/modal.mjs.map +2 -2
  244. package/build-module/components/block-switcher/block-transformations-menu.mjs +16 -15
  245. package/build-module/components/block-switcher/block-transformations-menu.mjs.map +2 -2
  246. package/build-module/components/block-switcher/index.mjs +4 -4
  247. package/build-module/components/block-switcher/index.mjs.map +2 -2
  248. package/build-module/components/block-toolbar/block-toolbar-icon.mjs +14 -6
  249. package/build-module/components/block-toolbar/block-toolbar-icon.mjs.map +2 -2
  250. package/build-module/components/block-toolbar/edit-section-button.mjs.map +1 -1
  251. package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs +10 -4
  252. package/build-module/components/block-tools/use-block-toolbar-popover-props.mjs.map +2 -2
  253. package/build-module/components/child-layout-control/index.mjs +51 -19
  254. package/build-module/components/child-layout-control/index.mjs.map +2 -2
  255. package/build-module/components/colors-gradients/control.mjs +27 -15
  256. package/build-module/components/colors-gradients/control.mjs.map +2 -2
  257. package/build-module/components/colors-gradients/dropdown.mjs +4 -1
  258. package/build-module/components/colors-gradients/dropdown.mjs.map +2 -2
  259. package/build-module/components/contrast-checker/index.mjs +18 -4
  260. package/build-module/components/contrast-checker/index.mjs.map +2 -2
  261. package/build-module/components/date-format-picker/index.mjs +0 -1
  262. package/build-module/components/date-format-picker/index.mjs.map +2 -2
  263. package/build-module/components/dimensions-tool/index.mjs +4 -5
  264. package/build-module/components/dimensions-tool/index.mjs.map +2 -2
  265. package/build-module/components/dimensions-tool/scale-tool.mjs +1 -1
  266. package/build-module/components/dimensions-tool/scale-tool.mjs.map +2 -2
  267. package/build-module/components/global-styles/advanced-panel.mjs +23 -15
  268. package/build-module/components/global-styles/advanced-panel.mjs.map +2 -2
  269. package/build-module/components/global-styles/background-panel.mjs +157 -29
  270. package/build-module/components/global-styles/background-panel.mjs.map +2 -2
  271. package/build-module/components/global-styles/border-panel.mjs +2 -0
  272. package/build-module/components/global-styles/border-panel.mjs.map +2 -2
  273. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs +207 -0
  274. package/build-module/components/global-styles/color-gradient-dropdown-item.mjs.map +7 -0
  275. package/build-module/components/global-styles/color-panel.mjs +106 -387
  276. package/build-module/components/global-styles/color-panel.mjs.map +3 -3
  277. package/build-module/components/global-styles/dimensions-panel.mjs +3 -7
  278. package/build-module/components/global-styles/dimensions-panel.mjs.map +2 -2
  279. package/build-module/components/global-styles/hooks.mjs +33 -0
  280. package/build-module/components/global-styles/hooks.mjs.map +2 -2
  281. package/build-module/components/global-styles/shadow-panel-components.mjs.map +2 -2
  282. package/build-module/components/global-styles/typography-panel.mjs +84 -10
  283. package/build-module/components/global-styles/typography-panel.mjs.map +2 -2
  284. package/build-module/components/grid/grid-item-resizer.mjs.map +1 -1
  285. package/build-module/components/grid/grid-visualizer.mjs.map +1 -1
  286. package/build-module/components/iframe/index.mjs +6 -3
  287. package/build-module/components/iframe/index.mjs.map +2 -2
  288. package/build-module/components/image-editor/use-transform-image.mjs.map +1 -1
  289. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +3 -1
  290. package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +2 -2
  291. package/build-module/components/inserter/get-appender-label.mjs.map +1 -1
  292. package/build-module/components/inserter/hooks/use-patterns-state.mjs +1 -1
  293. package/build-module/components/inserter/hooks/use-patterns-state.mjs.map +2 -2
  294. package/build-module/components/inserter/index.mjs +185 -222
  295. package/build-module/components/inserter/index.mjs.map +3 -3
  296. package/build-module/components/inserter/media-tab/media-preview.mjs.map +2 -2
  297. package/build-module/components/inserter/search-items.mjs.map +1 -1
  298. package/build-module/components/inserter/search-results.mjs +1 -1
  299. package/build-module/components/inserter/search-results.mjs.map +2 -2
  300. package/build-module/components/inspector-controls/fill.mjs +1 -3
  301. package/build-module/components/inspector-controls/fill.mjs.map +2 -2
  302. package/build-module/components/inspector-controls/groups.mjs +2 -0
  303. package/build-module/components/inspector-controls/groups.mjs.map +2 -2
  304. package/build-module/components/inspector-controls-tabs/index.mjs.map +2 -2
  305. package/build-module/components/inspector-controls-tabs/styles-tab.mjs +76 -32
  306. package/build-module/components/inspector-controls-tabs/styles-tab.mjs.map +2 -2
  307. package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -1
  308. package/build-module/components/line-height-control/index.mjs.map +1 -1
  309. package/build-module/components/link-control/index.mjs +2 -3
  310. package/build-module/components/link-control/index.mjs.map +2 -2
  311. package/build-module/components/link-control/normalize-url.mjs.map +1 -1
  312. package/build-module/components/list-view/block-select-button.mjs +10 -27
  313. package/build-module/components/list-view/block-select-button.mjs.map +2 -2
  314. package/build-module/components/list-view/block.mjs +2 -1
  315. package/build-module/components/list-view/block.mjs.map +2 -2
  316. package/build-module/components/list-view/utils.mjs.map +1 -1
  317. package/build-module/components/preset-input-control/custom-value-controls.mjs.map +2 -2
  318. package/build-module/components/provider/index.mjs.map +1 -1
  319. package/build-module/components/provider/use-block-sync.mjs +14 -3
  320. package/build-module/components/provider/use-block-sync.mjs.map +2 -2
  321. package/build-module/components/rich-text/event-listeners/before-input-rules.mjs +5 -5
  322. package/build-module/components/rich-text/event-listeners/before-input-rules.mjs.map +2 -2
  323. package/build-module/components/rich-text/event-listeners/delete.mjs +4 -4
  324. package/build-module/components/rich-text/event-listeners/delete.mjs.map +2 -2
  325. package/build-module/components/rich-text/event-listeners/enter.mjs +7 -2
  326. package/build-module/components/rich-text/event-listeners/enter.mjs.map +2 -2
  327. package/build-module/components/rich-text/event-listeners/input-events.mjs +4 -4
  328. package/build-module/components/rich-text/event-listeners/input-events.mjs.map +2 -2
  329. package/build-module/components/rich-text/event-listeners/input-rules.mjs +17 -4
  330. package/build-module/components/rich-text/event-listeners/input-rules.mjs.map +2 -2
  331. package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs +4 -4
  332. package/build-module/components/rich-text/event-listeners/insert-replacement-text.mjs.map +2 -2
  333. package/build-module/components/rich-text/event-listeners/paste-handler.mjs.map +1 -1
  334. package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs +4 -4
  335. package/build-module/components/rich-text/event-listeners/remove-browser-shortcuts.mjs.map +2 -2
  336. package/build-module/components/rich-text/event-listeners/shortcuts.mjs +4 -4
  337. package/build-module/components/rich-text/event-listeners/shortcuts.mjs.map +2 -2
  338. package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs +4 -4
  339. package/build-module/components/rich-text/event-listeners/undo-automatic-change.mjs.map +2 -2
  340. package/build-module/components/rich-text/index.mjs +1 -23
  341. package/build-module/components/rich-text/index.mjs.map +2 -2
  342. package/build-module/components/rich-text/prevent-event-discovery.mjs +1 -1
  343. package/build-module/components/rich-text/prevent-event-discovery.mjs.map +1 -1
  344. package/build-module/components/url-popover/image-url-input-ui.mjs +0 -2
  345. package/build-module/components/url-popover/image-url-input-ui.mjs.map +2 -2
  346. package/build-module/components/use-block-commands/index.mjs +5 -5
  347. package/build-module/components/use-block-commands/index.mjs.map +2 -2
  348. package/build-module/components/use-block-display-information/index.mjs +10 -3
  349. package/build-module/components/use-block-display-information/index.mjs.map +2 -2
  350. package/build-module/components/writing-flow/use-tab-nav.mjs.map +1 -1
  351. package/build-module/hooks/anchor.mjs +12 -17
  352. package/build-module/hooks/anchor.mjs.map +2 -2
  353. package/build-module/hooks/background.mjs +123 -75
  354. package/build-module/hooks/background.mjs.map +2 -2
  355. package/build-module/hooks/block-fields/index.mjs +13 -2
  356. package/build-module/hooks/block-fields/index.mjs.map +2 -2
  357. package/build-module/hooks/border.mjs +1 -4
  358. package/build-module/hooks/border.mjs.map +2 -2
  359. package/build-module/hooks/color.mjs +2 -178
  360. package/build-module/hooks/color.mjs.map +2 -2
  361. package/build-module/hooks/contrast-checker.mjs +32 -19
  362. package/build-module/hooks/contrast-checker.mjs.map +2 -2
  363. package/build-module/hooks/custom-class-name.mjs +0 -1
  364. package/build-module/hooks/custom-class-name.mjs.map +2 -2
  365. package/build-module/hooks/dimensions.mjs +13 -6
  366. package/build-module/hooks/dimensions.mjs.map +2 -2
  367. package/build-module/hooks/elements.mjs +115 -0
  368. package/build-module/hooks/elements.mjs.map +7 -0
  369. package/build-module/hooks/fit-text.mjs +11 -0
  370. package/build-module/hooks/fit-text.mjs.map +2 -2
  371. package/build-module/hooks/grid-visualizer.mjs +21 -11
  372. package/build-module/hooks/grid-visualizer.mjs.map +2 -2
  373. package/build-module/hooks/layout-child.mjs +68 -10
  374. package/build-module/hooks/layout-child.mjs.map +2 -2
  375. package/build-module/hooks/layout.mjs +6 -3
  376. package/build-module/hooks/layout.mjs.map +2 -2
  377. package/build-module/hooks/list-view.mjs +10 -7
  378. package/build-module/hooks/list-view.mjs.map +2 -2
  379. package/build-module/hooks/position.mjs +20 -23
  380. package/build-module/hooks/position.mjs.map +2 -2
  381. package/build-module/hooks/spacing-visualizer.mjs.map +1 -1
  382. package/build-module/hooks/state-utils.mjs.map +1 -1
  383. package/build-module/hooks/states.mjs +2 -2
  384. package/build-module/hooks/states.mjs.map +2 -2
  385. package/build-module/hooks/style.mjs +53 -8
  386. package/build-module/hooks/style.mjs.map +2 -2
  387. package/build-module/hooks/supports.mjs +0 -7
  388. package/build-module/hooks/supports.mjs.map +2 -2
  389. package/build-module/hooks/typography.mjs +62 -10
  390. package/build-module/hooks/typography.mjs.map +2 -2
  391. package/build-module/layouts/flex.mjs +105 -7
  392. package/build-module/layouts/flex.mjs.map +2 -2
  393. package/build-module/private-apis.mjs +8 -0
  394. package/build-module/private-apis.mjs.map +2 -2
  395. package/build-module/store/actions.mjs +7 -3
  396. package/build-module/store/actions.mjs.map +2 -2
  397. package/build-module/store/private-actions.mjs +1 -2
  398. package/build-module/store/private-actions.mjs.map +2 -2
  399. package/build-module/store/private-selectors.mjs +39 -1
  400. package/build-module/store/private-selectors.mjs.map +2 -2
  401. package/build-module/store/reducer.mjs +14 -6
  402. package/build-module/store/reducer.mjs.map +2 -2
  403. package/build-module/store/selectors.mjs +62 -42
  404. package/build-module/store/selectors.mjs.map +2 -2
  405. package/build-module/utils/block-bindings.mjs +9 -9
  406. package/build-module/utils/block-bindings.mjs.map +3 -3
  407. package/build-module/utils/color-values.mjs +9 -1
  408. package/build-module/utils/color-values.mjs.map +3 -3
  409. package/build-module/utils/dom.mjs +2 -5
  410. package/build-module/utils/dom.mjs.map +3 -3
  411. package/build-module/utils/fit-text-frontend.mjs +6 -2
  412. package/build-module/utils/fit-text-frontend.mjs.map +3 -3
  413. package/build-module/utils/fit-text-utils.mjs +1 -1
  414. package/build-module/utils/fit-text-utils.mjs.map +3 -3
  415. package/build-module/utils/format-font-style.mjs +1 -1
  416. package/build-module/utils/format-font-style.mjs.map +3 -3
  417. package/build-module/utils/format-font-weight.mjs +1 -1
  418. package/build-module/utils/format-font-weight.mjs.map +3 -3
  419. package/build-module/utils/get-editor-region.mjs +4 -2
  420. package/build-module/utils/get-editor-region.mjs.map +3 -3
  421. package/build-module/utils/get-font-styles-and-weights.mjs +8 -12
  422. package/build-module/utils/get-font-styles-and-weights.mjs.map +3 -3
  423. package/build-module/utils/get-px-from-css-unit.mjs +1 -1
  424. package/build-module/utils/get-px-from-css-unit.mjs.map +1 -1
  425. package/build-module/utils/index.mjs +1 -1
  426. package/build-module/utils/index.mjs.map +1 -1
  427. package/build-module/utils/math.mjs +1 -1
  428. package/build-module/utils/math.mjs.map +3 -3
  429. package/build-module/utils/object.mjs +8 -8
  430. package/build-module/utils/object.mjs.map +3 -3
  431. package/build-module/utils/order-inserter-block-items.mjs +1 -1
  432. package/build-module/utils/order-inserter-block-items.mjs.map +3 -3
  433. package/build-module/utils/pasting.mjs +4 -2
  434. package/build-module/utils/pasting.mjs.map +3 -3
  435. package/build-module/utils/selection.mjs +3 -2
  436. package/build-module/utils/selection.mjs.map +3 -3
  437. package/build-module/utils/sorting.mjs +9 -3
  438. package/build-module/utils/sorting.mjs.map +3 -3
  439. package/build-module/utils/transform-styles/index.mjs +3 -2
  440. package/build-module/utils/transform-styles/index.mjs.map +3 -3
  441. package/build-module/utils/transform-styles/postcss-urlrebase.d.mjs +1 -0
  442. package/build-module/utils/transform-styles/postcss-urlrebase.d.mjs.map +7 -0
  443. package/build-module/utils/transform-styles/types.mjs +1 -0
  444. package/build-module/utils/transform-styles/types.mjs.map +7 -0
  445. package/build-module/utils/types.mjs +1 -0
  446. package/build-module/utils/types.mjs.map +7 -0
  447. package/build-style/content-rtl.css +14 -0
  448. package/build-style/content.css +14 -0
  449. package/build-style/style-rtl.css +60 -49
  450. package/build-style/style.css +60 -49
  451. package/build-types/utils/block-bindings.d.ts +27 -0
  452. package/build-types/utils/block-bindings.d.ts.map +1 -0
  453. package/build-types/utils/color-values.d.ts +40 -0
  454. package/build-types/utils/color-values.d.ts.map +1 -0
  455. package/build-types/utils/dom.d.ts +19 -19
  456. package/build-types/utils/dom.d.ts.map +1 -1
  457. package/build-types/utils/fit-text-frontend.d.ts +7 -0
  458. package/build-types/utils/fit-text-frontend.d.ts.map +1 -0
  459. package/build-types/utils/fit-text-utils.d.ts +15 -0
  460. package/build-types/utils/fit-text-utils.d.ts.map +1 -0
  461. package/build-types/utils/format-font-style.d.ts +12 -0
  462. package/build-types/utils/format-font-style.d.ts.map +1 -0
  463. package/build-types/utils/format-font-weight.d.ts +12 -0
  464. package/build-types/utils/format-font-weight.d.ts.map +1 -0
  465. package/build-types/utils/get-editor-region.d.ts +9 -0
  466. package/build-types/utils/get-editor-region.d.ts.map +1 -0
  467. package/build-types/utils/get-font-styles-and-weights.d.ts +16 -0
  468. package/build-types/utils/get-font-styles-and-weights.d.ts.map +1 -0
  469. package/build-types/utils/get-px-from-css-unit.d.ts +10 -0
  470. package/build-types/utils/get-px-from-css-unit.d.ts.map +1 -0
  471. package/build-types/utils/index.d.ts +3 -0
  472. package/build-types/utils/index.d.ts.map +1 -0
  473. package/build-types/utils/math.d.ts +61 -0
  474. package/build-types/utils/math.d.ts.map +1 -0
  475. package/build-types/utils/object.d.ts +39 -0
  476. package/build-types/utils/object.d.ts.map +1 -0
  477. package/build-types/utils/order-inserter-block-items.d.ts +13 -0
  478. package/build-types/utils/order-inserter-block-items.d.ts.map +1 -0
  479. package/build-types/utils/pasting.d.ts +28 -0
  480. package/build-types/utils/pasting.d.ts.map +1 -0
  481. package/build-types/utils/selection.d.ts +21 -0
  482. package/build-types/utils/selection.d.ts.map +1 -0
  483. package/build-types/utils/sorting.d.ts +17 -0
  484. package/build-types/utils/sorting.d.ts.map +1 -0
  485. package/build-types/utils/transform-styles/index.d.ts +15 -0
  486. package/build-types/utils/transform-styles/index.d.ts.map +1 -0
  487. package/build-types/utils/transform-styles/types.d.ts +13 -0
  488. package/build-types/utils/transform-styles/types.d.ts.map +1 -0
  489. package/build-types/utils/types.d.ts +28 -0
  490. package/build-types/utils/types.d.ts.map +1 -0
  491. package/package.json +55 -46
  492. package/src/components/alignment-control/test/__snapshots__/index.js.snap +6 -0
  493. package/src/components/block-alignment-control/test/__snapshots__/index.js.snap +5 -0
  494. package/src/components/block-breadcrumb/README.md +2 -2
  495. package/src/components/block-card/index.js +7 -13
  496. package/src/components/block-compare/README.md +6 -6
  497. package/src/components/block-compare/index.js +1 -3
  498. package/src/components/block-editing-mode/index.js +17 -9
  499. package/src/components/block-icon/test/__snapshots__/index.js.snap +1 -0
  500. package/src/components/block-inspector/index.js +22 -20
  501. package/src/components/block-patterns-list/index.js +1 -2
  502. package/src/components/block-preview/README.md +1 -1
  503. package/src/components/block-quick-navigation/index.js +7 -7
  504. package/src/components/block-rename/modal.js +0 -1
  505. package/src/components/block-switcher/block-transformations-menu.js +16 -18
  506. package/src/components/block-switcher/index.js +4 -4
  507. package/src/components/block-toolbar/block-toolbar-icon.js +22 -6
  508. package/src/components/block-toolbar/test/block-toolbar-icon.js +99 -0
  509. package/src/components/block-tools/use-block-toolbar-popover-props.js +10 -4
  510. package/src/components/block-types-list/README.md +0 -19
  511. package/src/components/block-vertical-alignment-control/test/__snapshots__/index.js.snap +4 -0
  512. package/src/components/child-layout-control/index.js +65 -20
  513. package/src/components/child-layout-control/test/index.js +64 -0
  514. package/src/components/colors-gradients/control.js +29 -12
  515. package/src/components/colors-gradients/dropdown.js +4 -1
  516. package/src/components/colors-gradients/style.scss +39 -2
  517. package/src/components/contrast-checker/README.md +9 -0
  518. package/src/components/contrast-checker/index.js +42 -3
  519. package/src/components/date-format-picker/index.js +0 -1
  520. package/src/components/default-block-appender/content.scss +3 -0
  521. package/src/components/dimensions-tool/index.js +4 -9
  522. package/src/components/dimensions-tool/scale-tool.js +1 -2
  523. package/src/components/dimensions-tool/test/index.js +89 -11
  524. package/src/components/global-styles/advanced-panel.js +5 -1
  525. package/src/components/global-styles/background-panel.js +203 -36
  526. package/src/components/global-styles/border-panel.js +2 -0
  527. package/src/components/global-styles/color-gradient-dropdown-item.js +258 -0
  528. package/src/components/global-styles/color-panel.js +125 -487
  529. package/src/components/global-styles/dimensions-panel.js +13 -18
  530. package/src/components/global-styles/hooks.js +45 -0
  531. package/src/components/global-styles/shadow-panel-components.js +0 -1
  532. package/src/components/global-styles/test/background-panel.js +56 -0
  533. package/src/components/global-styles/test/color-panel.js +172 -118
  534. package/src/components/global-styles/test/typography-panel.js +167 -0
  535. package/src/components/global-styles/typography-panel.js +100 -11
  536. package/src/components/iframe/index.js +8 -3
  537. package/src/components/inner-blocks/use-inner-block-template-sync.js +3 -1
  538. package/src/components/inserter/hooks/use-patterns-state.js +1 -1
  539. package/src/components/inserter/index.js +257 -288
  540. package/src/components/inserter/media-tab/media-preview.js +0 -1
  541. package/src/components/inserter/search-results.js +1 -3
  542. package/src/components/inspector-controls/README.md +0 -2
  543. package/src/components/inspector-controls/fill.js +6 -8
  544. package/src/components/inspector-controls/groups.js +2 -0
  545. package/src/components/inspector-controls-tabs/index.js +0 -1
  546. package/src/components/inspector-controls-tabs/styles-tab.js +78 -28
  547. package/src/components/justify-content-control/README.md +1 -1
  548. package/src/components/link-control/index.js +0 -1
  549. package/src/components/link-control/test/index.js +2 -3
  550. package/src/components/list-view/block-select-button.js +9 -29
  551. package/src/components/list-view/block.js +1 -0
  552. package/src/components/media-placeholder/README.md +1 -29
  553. package/src/components/media-upload/README.md +0 -19
  554. package/src/components/preset-input-control/custom-value-controls.js +0 -1
  555. package/src/components/provider/test/use-block-sync.js +40 -0
  556. package/src/components/provider/use-block-sync.js +15 -3
  557. package/src/components/rich-text/content.scss +2 -0
  558. package/src/components/rich-text/event-listeners/before-input-rules.js +5 -4
  559. package/src/components/rich-text/event-listeners/delete.js +9 -4
  560. package/src/components/rich-text/event-listeners/enter.js +9 -2
  561. package/src/components/rich-text/event-listeners/input-events.js +13 -4
  562. package/src/components/rich-text/event-listeners/input-rules.js +20 -4
  563. package/src/components/rich-text/event-listeners/insert-replacement-text.js +9 -4
  564. package/src/components/rich-text/event-listeners/remove-browser-shortcuts.js +9 -4
  565. package/src/components/rich-text/event-listeners/shortcuts.js +13 -4
  566. package/src/components/rich-text/event-listeners/undo-automatic-change.js +5 -4
  567. package/src/components/rich-text/index.js +1 -33
  568. package/src/components/unit-control/README.md +1 -1
  569. package/src/components/url-popover/README.md +1 -1
  570. package/src/components/url-popover/image-url-input-ui.js +0 -2
  571. package/src/components/use-block-commands/index.js +5 -5
  572. package/src/components/use-block-display-information/index.js +15 -2
  573. package/src/components/use-block-display-information/test/index.js +140 -0
  574. package/src/hooks/anchor.js +9 -18
  575. package/src/hooks/background.js +210 -133
  576. package/src/hooks/background.scss +0 -35
  577. package/src/hooks/block-fields/index.js +27 -2
  578. package/src/hooks/border.js +1 -5
  579. package/src/hooks/color.js +2 -210
  580. package/src/hooks/color.scss +3 -9
  581. package/src/hooks/contrast-checker.js +60 -17
  582. package/src/hooks/custom-class-name.js +0 -1
  583. package/src/hooks/dimensions.js +15 -8
  584. package/src/hooks/elements.js +140 -0
  585. package/src/hooks/elements.scss +8 -0
  586. package/src/hooks/fit-text.js +16 -0
  587. package/src/hooks/grid-visualizer.js +59 -45
  588. package/src/hooks/layout-child.js +92 -14
  589. package/src/hooks/layout.js +6 -3
  590. package/src/hooks/list-view.js +10 -11
  591. package/src/hooks/position.js +23 -27
  592. package/src/hooks/states.js +2 -2
  593. package/src/hooks/style.js +91 -9
  594. package/src/hooks/supports.js +0 -9
  595. package/src/hooks/test/background.js +59 -0
  596. package/src/hooks/test/block-style-state.js +14 -14
  597. package/src/hooks/test/dimensions.js +71 -0
  598. package/src/hooks/test/layout-child.js +165 -0
  599. package/src/hooks/test/layout.js +6 -6
  600. package/src/hooks/test/style.js +133 -11
  601. package/src/hooks/typography.js +70 -6
  602. package/src/layouts/flex.js +118 -15
  603. package/src/private-apis.js +8 -0
  604. package/src/store/actions.js +13 -3
  605. package/src/store/private-actions.js +1 -4
  606. package/src/store/private-selectors.js +89 -0
  607. package/src/store/reducer.js +19 -7
  608. package/src/store/selectors.js +91 -53
  609. package/src/store/test/actions.js +21 -0
  610. package/src/store/test/private-selectors.js +166 -7
  611. package/src/store/test/reducer.js +107 -10
  612. package/src/store/test/selectors.js +77 -0
  613. package/src/style.scss +1 -0
  614. package/src/utils/block-bindings.ts +51 -0
  615. package/src/utils/color-values.ts +63 -0
  616. package/src/utils/{dom.js → dom.ts} +27 -27
  617. package/src/utils/{fit-text-frontend.js → fit-text-frontend.ts} +12 -4
  618. package/src/utils/{fit-text-utils.js → fit-text-utils.ts} +15 -7
  619. package/src/utils/{format-font-style.js → format-font-style.ts} +10 -3
  620. package/src/utils/{format-font-weight.js → format-font-weight.ts} +10 -3
  621. package/src/utils/{get-editor-region.js → get-editor-region.ts} +10 -6
  622. package/src/utils/{get-font-styles-and-weights.js → get-font-styles-and-weights.ts} +21 -17
  623. package/src/utils/{math.js → math.ts} +37 -30
  624. package/src/utils/object.ts +89 -0
  625. package/src/utils/{order-inserter-block-items.js → order-inserter-block-items.ts} +8 -5
  626. package/src/utils/{pasting.js → pasting.ts} +18 -11
  627. package/src/utils/{selection.js → selection.ts} +11 -4
  628. package/src/utils/sorting.ts +81 -0
  629. package/src/utils/test/color-values.js +44 -1
  630. package/src/utils/transform-styles/{index.js → index.ts} +25 -25
  631. package/src/utils/transform-styles/postcss-urlrebase.d.ts +15 -0
  632. package/src/utils/transform-styles/types.ts +13 -0
  633. package/src/utils/types.ts +29 -0
  634. package/build/components/media-upload-progress/constants.cjs +0 -46
  635. package/build/components/media-upload-progress/constants.cjs.map +0 -7
  636. package/build/components/rich-text/native/format-edit.cjs +0 -60
  637. package/build/components/rich-text/native/format-edit.cjs.map +0 -7
  638. package/build/components/rich-text/native/index.cjs.map +0 -7
  639. package/build/components/rich-text/native/use-format-types.cjs +0 -139
  640. package/build/components/rich-text/native/use-format-types.cjs.map +0 -7
  641. package/build-module/components/media-upload-progress/constants.mjs +0 -16
  642. package/build-module/components/media-upload-progress/constants.mjs.map +0 -7
  643. package/build-module/components/rich-text/native/format-edit.mjs +0 -39
  644. package/build-module/components/rich-text/native/format-edit.mjs.map +0 -7
  645. package/build-module/components/rich-text/native/index.mjs +0 -7
  646. package/build-module/components/rich-text/native/index.mjs.map +0 -7
  647. package/build-module/components/rich-text/native/use-format-types.mjs +0 -114
  648. package/build-module/components/rich-text/native/use-format-types.mjs.map +0 -7
  649. package/src/components/audio-player/audio-url-parser.native.js +0 -20
  650. package/src/components/audio-player/index.native.js +0 -225
  651. package/src/components/audio-player/styles.native.scss +0 -114
  652. package/src/components/audio-player/test/audio-url-parser.native.js +0 -53
  653. package/src/components/block-alignment-control/test/index.native.js +0 -37
  654. package/src/components/block-alignment-control/ui.native.js +0 -86
  655. package/src/components/block-caption/README.md +0 -104
  656. package/src/components/block-caption/index.native.js +0 -89
  657. package/src/components/block-caption/styles.native.scss +0 -7
  658. package/src/components/block-controls/slot.native.js +0 -33
  659. package/src/components/block-draggable/draggable-chip.native.js +0 -49
  660. package/src/components/block-draggable/dropping-insertion-point.native.js +0 -181
  661. package/src/components/block-draggable/dropping-insertion-point.native.scss +0 -8
  662. package/src/components/block-draggable/index.native.js +0 -467
  663. package/src/components/block-draggable/style.native.scss +0 -19
  664. package/src/components/block-draggable/test/__snapshots__/index.native.js.snap +0 -73
  665. package/src/components/block-draggable/test/helpers.native.js +0 -182
  666. package/src/components/block-draggable/test/index.native.js +0 -419
  667. package/src/components/block-draggable/use-scroll-when-dragging.native.js +0 -135
  668. package/src/components/block-edit/edit.native.js +0 -49
  669. package/src/components/block-edit/test/edit.native.js +0 -65
  670. package/src/components/block-heading-level-dropdown/index.native.js +0 -68
  671. package/src/components/block-icon/index.native.js +0 -47
  672. package/src/components/block-icon/style.native.scss +0 -7
  673. package/src/components/block-list/block-crash-boundary.native.js +0 -43
  674. package/src/components/block-list/block-crash-warning.native.js +0 -21
  675. package/src/components/block-list/block-invalid-warning.native.js +0 -70
  676. package/src/components/block-list/block-list-context.native.js +0 -172
  677. package/src/components/block-list/block-list-item-cell.native.js +0 -62
  678. package/src/components/block-list/block-list-item.native.js +0 -209
  679. package/src/components/block-list/block-list-item.native.scss +0 -16
  680. package/src/components/block-list/block-outline.native.js +0 -77
  681. package/src/components/block-list/block-selection-button.native.js +0 -100
  682. package/src/components/block-list/block-selection-button.native.scss +0 -34
  683. package/src/components/block-list/block.native.js +0 -716
  684. package/src/components/block-list/block.native.scss +0 -62
  685. package/src/components/block-list/grid-item.native.js +0 -58
  686. package/src/components/block-list/index.native.js +0 -437
  687. package/src/components/block-list/insertion-point.native.js +0 -36
  688. package/src/components/block-list/style.native.scss +0 -117
  689. package/src/components/block-list/test/block-invalid-warning.native.js +0 -62
  690. package/src/components/block-list/test/block-list-context.native.js +0 -243
  691. package/src/components/block-list/test/block-outline.native.js +0 -255
  692. package/src/components/block-list/test/fixtures/block-list-context.native.js +0 -79
  693. package/src/components/block-list/test/index.native.js +0 -205
  694. package/src/components/block-list/use-block-props/index.native.js +0 -10
  695. package/src/components/block-list/use-scroll-upon-insertion.native.js +0 -52
  696. package/src/components/block-list-appender/index.native.js +0 -70
  697. package/src/components/block-list-appender/style.native.scss +0 -8
  698. package/src/components/block-media-update-progress/README.md +0 -100
  699. package/src/components/block-media-update-progress/index.native.js +0 -299
  700. package/src/components/block-media-update-progress/styles.native.scss +0 -9
  701. package/src/components/block-media-update-progress/test/index.native.js +0 -543
  702. package/src/components/block-mover/index.native.js +0 -193
  703. package/src/components/block-mover/mover-description.native.js +0 -155
  704. package/src/components/block-mover/test/__snapshots__/index.native.js.snap +0 -218
  705. package/src/components/block-mover/test/index.native.js +0 -186
  706. package/src/components/block-settings/button.native.js +0 -41
  707. package/src/components/block-settings/container.native.js +0 -91
  708. package/src/components/block-settings/container.native.scss +0 -4
  709. package/src/components/block-settings/index.native.js +0 -5
  710. package/src/components/block-styles/index.native.js +0 -94
  711. package/src/components/block-styles/preview.native.js +0 -109
  712. package/src/components/block-styles/style.native.scss +0 -64
  713. package/src/components/block-switcher/block-transformations-menu.native.js +0 -91
  714. package/src/components/block-toolbar/block-toolbar-menu.native.js +0 -477
  715. package/src/components/block-toolbar/index.native.js +0 -126
  716. package/src/components/block-toolbar/test/__snapshots__/block-toolbar-menu.native.js.snap +0 -125
  717. package/src/components/block-toolbar/test/block-toolbar-menu.native.js +0 -405
  718. package/src/components/block-toolbar/test/index.native.js +0 -36
  719. package/src/components/block-types-list/index.native.js +0 -175
  720. package/src/components/block-types-list/style.native.scss +0 -25
  721. package/src/components/block-variation-picker/index.native.js +0 -107
  722. package/src/components/block-variation-picker/style.native.scss +0 -32
  723. package/src/components/button-block-appender/index.native.js +0 -92
  724. package/src/components/button-block-appender/styles.native.scss +0 -43
  725. package/src/components/caption/README.md +0 -44
  726. package/src/components/caption/index.native.js +0 -61
  727. package/src/components/colors-gradients/panel-color-gradient-settings.native.js +0 -59
  728. package/src/components/contrast-checker/index.native.js +0 -113
  729. package/src/components/contrast-checker/style.native.scss +0 -26
  730. package/src/components/convert-to-group-buttons/index.native.js +0 -79
  731. package/src/components/default-block-appender/index.native.js +0 -113
  732. package/src/components/default-block-appender/style.native.scss +0 -18
  733. package/src/components/floating-toolbar/floatingToolbar.android.scss +0 -4
  734. package/src/components/floating-toolbar/floatingToolbar.ios.scss +0 -3
  735. package/src/components/floating-toolbar/index.native.js +0 -141
  736. package/src/components/floating-toolbar/styles.native.scss +0 -43
  737. package/src/components/font-sizes/index.native.js +0 -7
  738. package/src/components/global-styles/color-panel.native.js +0 -207
  739. package/src/components/global-styles/test/use-global-styles-context.native.js +0 -435
  740. package/src/components/global-styles/use-global-styles-context.native.js +0 -592
  741. package/src/components/gradients/index.native.js +0 -2
  742. package/src/components/image-link-destinations/index.native.js +0 -152
  743. package/src/components/image-link-destinations/style.native.scss +0 -16
  744. package/src/components/index.native.js +0 -108
  745. package/src/components/inner-blocks/constants.native.js +0 -5
  746. package/src/components/inner-blocks/index.native.js +0 -221
  747. package/src/components/inner-blocks/warning-max-depth-exceeded.native.js +0 -124
  748. package/src/components/inserter/block-types-tab.native.js +0 -76
  749. package/src/components/inserter/hooks/use-block-type-impressions.native.js +0 -47
  750. package/src/components/inserter/hooks/use-clipboard-block.native.js +0 -40
  751. package/src/components/inserter/index.native.js +0 -424
  752. package/src/components/inserter/menu.native.js +0 -237
  753. package/src/components/inserter/no-results.native.js +0 -49
  754. package/src/components/inserter/reusable-blocks-tab.native.js +0 -45
  755. package/src/components/inserter/search-results.native.js +0 -67
  756. package/src/components/inserter/style.native.scss +0 -83
  757. package/src/components/inserter/tabs.native.js +0 -152
  758. package/src/components/inserter/test/__snapshots__/index.native.js.snap +0 -117
  759. package/src/components/inserter/test/fixtures/index.native.js +0 -12
  760. package/src/components/inserter/test/index.native.js +0 -273
  761. package/src/components/inserter/test/reusable-blocks-tab.native.js +0 -62
  762. package/src/components/inserter/test/utils.native.js +0 -37
  763. package/src/components/inserter/utils.native.js +0 -46
  764. package/src/components/inserter-button/index.native.js +0 -108
  765. package/src/components/inserter-button/style.native.scss +0 -72
  766. package/src/components/inspector-controls/fill.native.js +0 -62
  767. package/src/components/inspector-controls/slot.native.js +0 -35
  768. package/src/components/inspector-controls-tabs/advanced-controls-panel.native.js +0 -31
  769. package/src/components/line-height-control/index.native.js +0 -28
  770. package/src/components/media-placeholder/index.native.js +0 -258
  771. package/src/components/media-placeholder/styles.native.scss +0 -108
  772. package/src/components/media-replace-flow/index.native.js +0 -12
  773. package/src/components/media-upload/constants.native.js +0 -14
  774. package/src/components/media-upload/index.native.js +0 -356
  775. package/src/components/media-upload/style.native.scss +0 -4
  776. package/src/components/media-upload/test/index.native.js +0 -172
  777. package/src/components/media-upload-progress/README.md +0 -100
  778. package/src/components/media-upload-progress/constants.js +0 -6
  779. package/src/components/media-upload-progress/index.native.js +0 -233
  780. package/src/components/media-upload-progress/styles.native.scss +0 -15
  781. package/src/components/media-upload-progress/test/index.native.js +0 -220
  782. package/src/components/plain-text/index.native.js +0 -164
  783. package/src/components/plain-text/style.native.scss +0 -10
  784. package/src/components/provider/index.native.js +0 -32
  785. package/src/components/rich-text/embed-handler-picker.native.js +0 -65
  786. package/src/components/rich-text/file-paste-handler.native.js +0 -3
  787. package/src/components/rich-text/format-toolbar/index.native.js +0 -21
  788. package/src/components/rich-text/format-toolbar-container.native.js +0 -16
  789. package/src/components/rich-text/index.native.js +0 -701
  790. package/src/components/rich-text/input-event.native.js +0 -10
  791. package/src/components/rich-text/native/format-edit.js +0 -44
  792. package/src/components/rich-text/native/get-format-colors.native.js +0 -47
  793. package/src/components/rich-text/native/index.js +0 -1
  794. package/src/components/rich-text/native/index.native.js +0 -1389
  795. package/src/components/rich-text/native/style.native.scss +0 -28
  796. package/src/components/rich-text/native/test/__snapshots__/index.native.js.snap +0 -79
  797. package/src/components/rich-text/native/test/index.native.js +0 -345
  798. package/src/components/rich-text/native/test/performance/rich-text.native.js +0 -44
  799. package/src/components/rich-text/native/toolbar-button-with-options.native.js +0 -61
  800. package/src/components/rich-text/native/use-format-types.js +0 -146
  801. package/src/components/rich-text/remove-browser-shortcuts.native.js +0 -1
  802. package/src/components/rich-text/shortcut.native.js +0 -10
  803. package/src/components/ungroup-button/README.md +0 -23
  804. package/src/components/ungroup-button/index.native.js +0 -77
  805. package/src/components/unsupported-block-details/index.native.js +0 -187
  806. package/src/components/unsupported-block-details/style.native.scss +0 -56
  807. package/src/components/url-input/index.native.js +0 -33
  808. package/src/components/use-block-drop-zone/index.native.js +0 -207
  809. package/src/components/use-on-block-drop/index.native.js +0 -115
  810. package/src/components/use-unsupported-block-editor/index.native.js +0 -59
  811. package/src/components/video-player/gridicon-play.native.js +0 -13
  812. package/src/components/video-player/index.native.js +0 -133
  813. package/src/components/video-player/styles.native.scss +0 -29
  814. package/src/components/warning/index.native.js +0 -64
  815. package/src/components/warning/style.native.scss +0 -47
  816. package/src/hooks/align.native.js +0 -49
  817. package/src/hooks/custom-class-name.native.js +0 -70
  818. package/src/hooks/index.native.js +0 -36
  819. package/src/hooks/layout.native.js +0 -23
  820. package/src/hooks/test/__snapshots__/align.native.js.snap +0 -73
  821. package/src/hooks/test/__snapshots__/anchor.native.js.snap +0 -7
  822. package/src/hooks/test/align.native.js +0 -134
  823. package/src/hooks/test/anchor.native.js +0 -32
  824. package/src/hooks/test/use-editor-wrapper-styles.native.js +0 -282
  825. package/src/hooks/typography.native.js +0 -60
  826. package/src/hooks/use-editor-wrapper-styles.native.js +0 -250
  827. package/src/hooks/use-editor-wrapper-styles.native.scss +0 -12
  828. package/src/index.native.js +0 -6
  829. package/src/private-apis.native.js +0 -21
  830. package/src/store/defaults.native.js +0 -23
  831. package/src/utils/block-bindings.js +0 -46
  832. package/src/utils/color-values.js +0 -28
  833. package/src/utils/object.js +0 -67
  834. package/src/utils/sorting.js +0 -54
  835. /package/src/utils/{get-px-from-css-unit.js → get-px-from-css-unit.ts} +0 -0
  836. /package/src/utils/{index.js → index.ts} +0 -0
@@ -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 );