@wordpress/block-editor 15.8.1-next.16d95556a.0 → 15.9.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 (302) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-inspector/edit-contents.js +19 -23
  3. package/build/components/block-inspector/edit-contents.js.map +3 -3
  4. package/build/components/block-inspector/index.js +7 -1
  5. package/build/components/block-inspector/index.js.map +2 -2
  6. package/build/components/block-list/block.js +4 -0
  7. package/build/components/block-list/block.js.map +2 -2
  8. package/build/components/block-list/index.js +2 -1
  9. package/build/components/block-list/index.js.map +2 -2
  10. package/build/components/block-list/use-block-props/index.js +3 -1
  11. package/build/components/block-list/use-block-props/index.js.map +2 -2
  12. package/build/components/block-list/use-block-props/use-is-hovered.js +16 -10
  13. package/build/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
  14. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  15. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  16. package/build/components/block-lock/modal.js +5 -5
  17. package/build/components/block-lock/modal.js.map +2 -2
  18. package/build/components/block-lock/use-block-lock.js +10 -13
  19. package/build/components/block-lock/use-block-lock.js.map +2 -2
  20. package/build/components/block-settings-menu-controls/edit-section-menu-item.js +64 -0
  21. package/build/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
  22. package/build/components/block-settings-menu-controls/index.js +9 -1
  23. package/build/components/block-settings-menu-controls/index.js.map +2 -2
  24. package/build/components/block-toolbar/block-toolbar-icon.js +9 -9
  25. package/build/components/block-toolbar/block-toolbar-icon.js.map +2 -2
  26. package/build/components/block-tools/index.js +56 -45
  27. package/build/components/block-tools/index.js.map +3 -3
  28. package/build/components/block-variation-transforms/index.js +32 -5
  29. package/build/components/block-variation-transforms/index.js.map +2 -2
  30. package/build/components/block-visibility/toolbar.js +1 -1
  31. package/build/components/block-visibility/toolbar.js.map +1 -1
  32. package/build/components/border-radius-control/single-input-control.js +1 -0
  33. package/build/components/border-radius-control/single-input-control.js.map +2 -2
  34. package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
  35. package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  36. package/build/components/content-only-controls/index.js +444 -0
  37. package/build/components/content-only-controls/index.js.map +7 -0
  38. package/build/components/content-only-controls/link/index.js +193 -0
  39. package/build/components/content-only-controls/link/index.js.map +7 -0
  40. package/build/components/content-only-controls/media/index.js +264 -0
  41. package/build/components/content-only-controls/media/index.js.map +7 -0
  42. package/build/components/content-only-controls/rich-text/index.js +188 -0
  43. package/build/components/content-only-controls/rich-text/index.js.map +7 -0
  44. package/build/components/content-only-controls/use-inspector-popover-placement.js +41 -0
  45. package/build/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
  46. package/build/components/font-family/index.js +1 -15
  47. package/build/components/font-family/index.js.map +2 -2
  48. package/build/components/global-styles/dimensions-panel.js +35 -2
  49. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  50. package/build/components/global-styles/hooks.js +1 -1
  51. package/build/components/global-styles/hooks.js.map +2 -2
  52. package/build/components/global-styles/typography-panel.js +1 -2
  53. package/build/components/global-styles/typography-panel.js.map +2 -2
  54. package/build/components/inserter/media-tab/media-tab.js +1 -33
  55. package/build/components/inserter/media-tab/media-tab.js.map +3 -3
  56. package/build/components/inspector-controls-tabs/content-tab.js +6 -2
  57. package/build/components/inspector-controls-tabs/content-tab.js.map +3 -3
  58. package/build/components/inspector-controls-tabs/index.js +7 -1
  59. package/build/components/inspector-controls-tabs/index.js.map +2 -2
  60. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  61. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  62. package/build/components/link-control/index.js +15 -7
  63. package/build/components/link-control/index.js.map +2 -2
  64. package/build/components/list-view/block-select-button.js +7 -8
  65. package/build/components/list-view/block-select-button.js.map +2 -2
  66. package/build/components/list-view/block.js +9 -7
  67. package/build/components/list-view/block.js.map +2 -2
  68. package/build/components/media-placeholder/index.js +18 -35
  69. package/build/components/media-placeholder/index.js.map +3 -3
  70. package/build/components/media-placeholder/utils.js +60 -0
  71. package/build/components/media-placeholder/utils.js.map +7 -0
  72. package/build/components/media-replace-flow/index.js +24 -33
  73. package/build/components/media-replace-flow/index.js.map +3 -3
  74. package/build/components/use-block-commands/index.js +1 -1
  75. package/build/components/use-block-commands/index.js.map +2 -2
  76. package/build/components/use-block-display-information/index.js +21 -1
  77. package/build/components/use-block-display-information/index.js.map +3 -3
  78. package/build/components/use-block-drop-zone/index.js +1 -5
  79. package/build/components/use-block-drop-zone/index.js.map +2 -2
  80. package/build/hooks/block-bindings.js +52 -61
  81. package/build/hooks/block-bindings.js.map +3 -3
  82. package/build/hooks/dimensions.js +3 -3
  83. package/build/hooks/dimensions.js.map +2 -2
  84. package/build/hooks/metadata.js +1 -1
  85. package/build/hooks/metadata.js.map +2 -2
  86. package/build/hooks/use-content-only-section-edit.js +67 -0
  87. package/build/hooks/use-content-only-section-edit.js.map +7 -0
  88. package/build/hooks/utils.js +5 -1
  89. package/build/hooks/utils.js.map +2 -2
  90. package/build/layouts/constrained.js +2 -2
  91. package/build/layouts/constrained.js.map +2 -2
  92. package/build/private-apis.js +2 -3
  93. package/build/private-apis.js.map +3 -3
  94. package/build/store/private-keys.js +3 -0
  95. package/build/store/private-keys.js.map +2 -2
  96. package/build/store/private-selectors.js +41 -2
  97. package/build/store/private-selectors.js.map +2 -2
  98. package/build/store/selectors.js +6 -4
  99. package/build/store/selectors.js.map +2 -2
  100. package/build/utils/fit-text-utils.js +9 -1
  101. package/build/utils/fit-text-utils.js.map +2 -2
  102. package/build-module/components/block-inspector/edit-contents.js +9 -23
  103. package/build-module/components/block-inspector/edit-contents.js.map +2 -2
  104. package/build-module/components/block-inspector/index.js +7 -1
  105. package/build-module/components/block-inspector/index.js.map +2 -2
  106. package/build-module/components/block-list/block.js +4 -0
  107. package/build-module/components/block-list/block.js.map +2 -2
  108. package/build-module/components/block-list/index.js +2 -1
  109. package/build-module/components/block-list/index.js.map +2 -2
  110. package/build-module/components/block-list/use-block-props/index.js +3 -1
  111. package/build-module/components/block-list/use-block-props/index.js.map +2 -2
  112. package/build-module/components/block-list/use-block-props/use-is-hovered.js +16 -10
  113. package/build-module/components/block-list/use-block-props/use-is-hovered.js.map +2 -2
  114. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  115. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  116. package/build-module/components/block-lock/modal.js +5 -5
  117. package/build-module/components/block-lock/modal.js.map +2 -2
  118. package/build-module/components/block-lock/use-block-lock.js +10 -13
  119. package/build-module/components/block-lock/use-block-lock.js.map +2 -2
  120. package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js +29 -0
  121. package/build-module/components/block-settings-menu-controls/edit-section-menu-item.js.map +7 -0
  122. package/build-module/components/block-settings-menu-controls/index.js +9 -1
  123. package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
  124. package/build-module/components/block-toolbar/block-toolbar-icon.js +10 -10
  125. package/build-module/components/block-toolbar/block-toolbar-icon.js.map +2 -2
  126. package/build-module/components/block-tools/index.js +56 -45
  127. package/build-module/components/block-tools/index.js.map +2 -2
  128. package/build-module/components/block-variation-transforms/index.js +32 -5
  129. package/build-module/components/block-variation-transforms/index.js.map +2 -2
  130. package/build-module/components/block-visibility/toolbar.js +1 -1
  131. package/build-module/components/block-visibility/toolbar.js.map +1 -1
  132. package/build-module/components/border-radius-control/single-input-control.js +1 -0
  133. package/build-module/components/border-radius-control/single-input-control.js.map +2 -2
  134. package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
  135. package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  136. package/build-module/components/content-only-controls/index.js +420 -0
  137. package/build-module/components/content-only-controls/index.js.map +7 -0
  138. package/build-module/components/content-only-controls/link/index.js +160 -0
  139. package/build-module/components/content-only-controls/link/index.js.map +7 -0
  140. package/build-module/components/content-only-controls/media/index.js +242 -0
  141. package/build-module/components/content-only-controls/media/index.js.map +7 -0
  142. package/build-module/components/content-only-controls/rich-text/index.js +160 -0
  143. package/build-module/components/content-only-controls/rich-text/index.js.map +7 -0
  144. package/build-module/components/content-only-controls/use-inspector-popover-placement.js +16 -0
  145. package/build-module/components/content-only-controls/use-inspector-popover-placement.js.map +7 -0
  146. package/build-module/components/font-family/index.js +1 -15
  147. package/build-module/components/font-family/index.js.map +2 -2
  148. package/build-module/components/global-styles/dimensions-panel.js +35 -2
  149. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  150. package/build-module/components/global-styles/hooks.js +1 -1
  151. package/build-module/components/global-styles/hooks.js.map +2 -2
  152. package/build-module/components/global-styles/typography-panel.js +1 -2
  153. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  154. package/build-module/components/inserter/media-tab/media-tab.js +2 -34
  155. package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
  156. package/build-module/components/inspector-controls-tabs/content-tab.js +7 -3
  157. package/build-module/components/inspector-controls-tabs/content-tab.js.map +2 -2
  158. package/build-module/components/inspector-controls-tabs/index.js +7 -1
  159. package/build-module/components/inspector-controls-tabs/index.js.map +2 -2
  160. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  161. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  162. package/build-module/components/link-control/index.js +16 -8
  163. package/build-module/components/link-control/index.js.map +2 -2
  164. package/build-module/components/list-view/block-select-button.js +14 -9
  165. package/build-module/components/list-view/block-select-button.js.map +2 -2
  166. package/build-module/components/list-view/block.js +9 -7
  167. package/build-module/components/list-view/block.js.map +2 -2
  168. package/build-module/components/media-placeholder/index.js +19 -36
  169. package/build-module/components/media-placeholder/index.js.map +2 -2
  170. package/build-module/components/media-placeholder/utils.js +35 -0
  171. package/build-module/components/media-placeholder/utils.js.map +7 -0
  172. package/build-module/components/media-replace-flow/index.js +24 -33
  173. package/build-module/components/media-replace-flow/index.js.map +2 -2
  174. package/build-module/components/use-block-commands/index.js +1 -1
  175. package/build-module/components/use-block-commands/index.js.map +2 -2
  176. package/build-module/components/use-block-display-information/index.js +21 -1
  177. package/build-module/components/use-block-display-information/index.js.map +3 -3
  178. package/build-module/components/use-block-drop-zone/index.js +1 -5
  179. package/build-module/components/use-block-drop-zone/index.js.map +2 -2
  180. package/build-module/hooks/block-bindings.js +57 -62
  181. package/build-module/hooks/block-bindings.js.map +2 -2
  182. package/build-module/hooks/dimensions.js +3 -3
  183. package/build-module/hooks/dimensions.js.map +2 -2
  184. package/build-module/hooks/metadata.js +1 -1
  185. package/build-module/hooks/metadata.js.map +2 -2
  186. package/build-module/hooks/use-content-only-section-edit.js +46 -0
  187. package/build-module/hooks/use-content-only-section-edit.js.map +7 -0
  188. package/build-module/hooks/utils.js +5 -1
  189. package/build-module/hooks/utils.js.map +2 -2
  190. package/build-module/layouts/constrained.js +2 -2
  191. package/build-module/layouts/constrained.js.map +2 -2
  192. package/build-module/private-apis.js +3 -3
  193. package/build-module/private-apis.js.map +2 -2
  194. package/build-module/store/private-keys.js +2 -0
  195. package/build-module/store/private-keys.js.map +2 -2
  196. package/build-module/store/private-selectors.js +37 -2
  197. package/build-module/store/private-selectors.js.map +2 -2
  198. package/build-module/store/selectors.js +6 -4
  199. package/build-module/store/selectors.js.map +2 -2
  200. package/build-module/utils/fit-text-utils.js +9 -1
  201. package/build-module/utils/fit-text-utils.js.map +2 -2
  202. package/build-style/content-rtl.css +3 -0
  203. package/build-style/content.css +3 -0
  204. package/build-style/style-rtl.css +145 -4
  205. package/build-style/style.css +145 -4
  206. package/package.json +38 -37
  207. package/src/components/block-inspector/edit-contents.js +10 -29
  208. package/src/components/block-inspector/index.js +4 -2
  209. package/src/components/block-list/block.js +6 -0
  210. package/src/components/block-list/content.scss +5 -0
  211. package/src/components/block-list/index.js +3 -1
  212. package/src/components/block-list/use-block-props/index.js +3 -1
  213. package/src/components/block-list/use-block-props/use-is-hovered.js +24 -12
  214. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
  215. package/src/components/block-lock/modal.js +6 -5
  216. package/src/components/block-lock/use-block-lock.js +10 -14
  217. package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
  218. package/src/components/block-settings-menu-controls/edit-section-menu-item.js +39 -0
  219. package/src/components/block-settings-menu-controls/index.js +8 -1
  220. package/src/components/block-toolbar/block-toolbar-icon.js +14 -10
  221. package/src/components/block-tools/index.js +15 -2
  222. package/src/components/block-tools/style.scss +4 -0
  223. package/src/components/block-variation-transforms/index.js +96 -35
  224. package/src/components/block-visibility/toolbar.js +1 -1
  225. package/src/components/border-radius-control/single-input-control.js +1 -0
  226. package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
  227. package/src/components/content-only-controls/index.js +560 -0
  228. package/src/components/content-only-controls/link/index.js +200 -0
  229. package/src/components/content-only-controls/link/styles.scss +23 -0
  230. package/src/components/content-only-controls/media/index.js +306 -0
  231. package/src/components/content-only-controls/media/styles.scss +47 -0
  232. package/src/components/content-only-controls/rich-text/index.js +179 -0
  233. package/src/components/content-only-controls/rich-text/styles.scss +24 -0
  234. package/src/components/content-only-controls/styles.scss +44 -0
  235. package/src/components/content-only-controls/use-inspector-popover-placement.js +19 -0
  236. package/src/components/font-family/README.md +0 -9
  237. package/src/components/font-family/index.js +1 -16
  238. package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
  239. package/src/components/global-styles/dimensions-panel.js +36 -0
  240. package/src/components/global-styles/hooks.js +1 -1
  241. package/src/components/global-styles/typography-panel.js +0 -1
  242. package/src/components/inserter/media-tab/media-tab.js +2 -44
  243. package/src/components/inspector-controls-tabs/content-tab.js +12 -4
  244. package/src/components/inspector-controls-tabs/index.js +4 -1
  245. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
  246. package/src/components/link-control/index.js +36 -12
  247. package/src/components/list-view/block-select-button.js +15 -10
  248. package/src/components/list-view/block.js +9 -7
  249. package/src/components/media-placeholder/index.js +21 -46
  250. package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
  251. package/src/components/media-placeholder/utils.js +65 -0
  252. package/src/components/media-replace-flow/index.js +25 -42
  253. package/src/components/use-block-commands/index.js +1 -1
  254. package/src/components/use-block-display-information/index.js +30 -2
  255. package/src/components/use-block-drop-zone/index.js +1 -5
  256. package/src/hooks/block-bindings.js +71 -82
  257. package/src/hooks/dimensions.js +8 -3
  258. package/src/hooks/metadata.js +1 -1
  259. package/src/hooks/test/metadata.js +1 -1
  260. package/src/hooks/use-content-only-section-edit.js +63 -0
  261. package/src/hooks/utils.js +4 -0
  262. package/src/layouts/constrained.js +8 -2
  263. package/src/private-apis.js +2 -2
  264. package/src/store/private-keys.js +1 -0
  265. package/src/store/private-selectors.js +121 -5
  266. package/src/store/selectors.js +6 -4
  267. package/src/store/test/private-selectors.js +242 -0
  268. package/src/style.scss +1 -1
  269. package/src/utils/fit-text-utils.js +19 -1
  270. package/tsconfig.json +1 -0
  271. package/build/components/media-upload-modal/index.js +0 -29
  272. package/build/components/media-upload-modal/index.js.map +0 -7
  273. package/build-module/components/media-upload-modal/index.js +0 -8
  274. package/build-module/components/media-upload-modal/index.js.map +0 -7
  275. package/src/components/font-family/style.scss +0 -7
  276. package/src/components/media-upload-modal/index.js +0 -18
  277. /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
  278. /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  279. /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
  280. /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
  281. /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
  282. /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
  283. /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
  284. /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
  285. /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
  286. /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
  287. /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
  288. /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
  289. /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
  290. /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
  291. /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
  292. /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
  293. /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
  294. /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
  295. /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
  296. /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  297. /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
  298. /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
  299. /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
  300. /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
  301. /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
  302. /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
@@ -0,0 +1,560 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ store as blocksStore,
6
+ privateApis as blocksPrivateApis,
7
+ } from '@wordpress/blocks';
8
+ import {
9
+ __experimentalHStack as HStack,
10
+ Icon,
11
+ Navigator,
12
+ } from '@wordpress/components';
13
+ import { useDispatch, useSelect } from '@wordpress/data';
14
+ import { __ } from '@wordpress/i18n';
15
+ import { arrowLeft, arrowRight } from '@wordpress/icons';
16
+ import { DataForm } from '@wordpress/dataviews';
17
+ import { useState, useMemo } from '@wordpress/element';
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+ import { unlock } from '../../lock-unlock';
23
+ import { store as blockEditorStore } from '../../store';
24
+ import BlockIcon from '../block-icon';
25
+ import useBlockDisplayTitle from '../block-title/use-block-display-title';
26
+ import useBlockDisplayInformation from '../use-block-display-information';
27
+ const { fieldsKey, formKey } = unlock( blocksPrivateApis );
28
+ import FieldsDropdownMenu from './fields-dropdown-menu';
29
+
30
+ // controls
31
+ import RichText from './rich-text';
32
+ import Media from './media';
33
+ import Link from './link';
34
+
35
+ const CONTROLS = {
36
+ richtext: RichText,
37
+ media: Media,
38
+ link: Link,
39
+ };
40
+
41
+ /**
42
+ * Creates a configured control component that wraps a custom control
43
+ * and passes configuration as props.
44
+ *
45
+ * @param {Object} config - The control configuration
46
+ * @param {string} config.control - The control type (key in CONTROLS map)
47
+ * @return {Function} A wrapped control component
48
+ */
49
+ function createConfiguredControl( config ) {
50
+ const { control, ...controlConfig } = config;
51
+ const ControlComponent = CONTROLS[ control ];
52
+
53
+ if ( ! ControlComponent ) {
54
+ throw new Error( `Control type "${ control }" not found` );
55
+ }
56
+
57
+ return function ConfiguredControl( props ) {
58
+ return <ControlComponent { ...props } config={ controlConfig } />;
59
+ };
60
+ }
61
+
62
+ /**
63
+ * Normalize a media value to a canonical structure.
64
+ * Only includes properties that are present in the field's mapping (if provided).
65
+ *
66
+ * @param {Object} value - The mapped value from the block attributes (with canonical keys)
67
+ * @param {Object} fieldDef - Optional field definition containing the mapping
68
+ * @return {Object} Normalized media value with canonical properties
69
+ */
70
+ function normalizeMediaValue( value, fieldDef ) {
71
+ const defaults = {
72
+ id: null,
73
+ url: '',
74
+ caption: '',
75
+ alt: '',
76
+ type: 'image',
77
+ poster: '',
78
+ featuredImage: false,
79
+ link: '',
80
+ };
81
+
82
+ const result = {};
83
+
84
+ // If there's a mapping, only include properties that are in it
85
+ if ( fieldDef?.mapping ) {
86
+ Object.keys( fieldDef.mapping ).forEach( ( key ) => {
87
+ result[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';
88
+ } );
89
+ return result;
90
+ }
91
+
92
+ // Without mapping, include all default properties
93
+ Object.keys( defaults ).forEach( ( key ) => {
94
+ result[ key ] = value?.[ key ] ?? defaults[ key ];
95
+ } );
96
+ return result;
97
+ }
98
+
99
+ /**
100
+ * Denormalize a media value from canonical structure back to mapped keys.
101
+ * Only includes properties that are present in the field's mapping.
102
+ *
103
+ * @param {Object} value - The normalized media value
104
+ * @param {Object} fieldDef - The field definition containing the mapping
105
+ * @return {Object} Value with only mapped properties
106
+ */
107
+ function denormalizeMediaValue( value, fieldDef ) {
108
+ if ( ! fieldDef.mapping ) {
109
+ return value;
110
+ }
111
+
112
+ const result = {};
113
+ Object.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {
114
+ if ( key in value ) {
115
+ result[ key ] = value[ key ];
116
+ }
117
+ } );
118
+ return result;
119
+ }
120
+
121
+ /**
122
+ * Normalize a link value to a canonical structure.
123
+ * Only includes properties that are present in the field's mapping (if provided).
124
+ *
125
+ * @param {Object} value - The mapped value from the block attributes (with canonical keys)
126
+ * @param {Object} fieldDef - Optional field definition containing the mapping
127
+ * @return {Object} Normalized link value with canonical properties
128
+ */
129
+ function normalizeLinkValue( value, fieldDef ) {
130
+ const defaults = {
131
+ url: '',
132
+ rel: '',
133
+ linkTarget: '',
134
+ destination: '',
135
+ };
136
+
137
+ const result = {};
138
+
139
+ // If there's a mapping, only include properties that are in it
140
+ if ( fieldDef?.mapping ) {
141
+ Object.keys( fieldDef.mapping ).forEach( ( key ) => {
142
+ result[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';
143
+ } );
144
+ return result;
145
+ }
146
+
147
+ // Without mapping, include all default properties
148
+ Object.keys( defaults ).forEach( ( key ) => {
149
+ result[ key ] = value?.[ key ] ?? defaults[ key ];
150
+ } );
151
+ return result;
152
+ }
153
+
154
+ /**
155
+ * Denormalize a link value from canonical structure back to mapped keys.
156
+ * Only includes properties that are present in the field's mapping.
157
+ *
158
+ * @param {Object} value - The normalized link value
159
+ * @param {Object} fieldDef - The field definition containing the mapping
160
+ * @return {Object} Value with only mapped properties
161
+ */
162
+ function denormalizeLinkValue( value, fieldDef ) {
163
+ if ( ! fieldDef.mapping ) {
164
+ return value;
165
+ }
166
+
167
+ const result = {};
168
+ Object.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {
169
+ if ( key in value ) {
170
+ result[ key ] = value[ key ];
171
+ }
172
+ } );
173
+ return result;
174
+ }
175
+
176
+ function BlockFields( { clientId } ) {
177
+ const { attributes, blockType } = useSelect(
178
+ ( select ) => {
179
+ const { getBlockAttributes, getBlockName } =
180
+ select( blockEditorStore );
181
+ const { getBlockType } = select( blocksStore );
182
+ const blockName = getBlockName( clientId );
183
+ return {
184
+ attributes: getBlockAttributes( clientId ),
185
+ blockType: getBlockType( blockName ),
186
+ };
187
+ },
188
+ [ clientId ]
189
+ );
190
+
191
+ const { updateBlockAttributes } = useDispatch( blockEditorStore );
192
+ const blockTitle = useBlockDisplayTitle( {
193
+ clientId,
194
+ context: 'list-view',
195
+ } );
196
+ const blockInformation = useBlockDisplayInformation( clientId );
197
+
198
+ const blockTypeFields = blockType?.[ fieldsKey ];
199
+
200
+ const [ form, setForm ] = useState( () => {
201
+ return blockType?.[ formKey ];
202
+ } );
203
+
204
+ // Build DataForm fields with proper structure
205
+ const dataFormFields = useMemo( () => {
206
+ if ( ! blockTypeFields?.length ) {
207
+ return [];
208
+ }
209
+
210
+ return blockTypeFields.map( ( fieldDef ) => {
211
+ const ControlComponent = CONTROLS[ fieldDef.type ];
212
+
213
+ const defaultValues = {};
214
+ if ( fieldDef.mapping && blockType?.attributes ) {
215
+ Object.entries( fieldDef.mapping ).forEach(
216
+ ( [ key, attrKey ] ) => {
217
+ defaultValues[ key ] =
218
+ blockType.attributes[ attrKey ]?.defaultValue ??
219
+ undefined;
220
+ }
221
+ );
222
+ }
223
+
224
+ const field = {
225
+ id: fieldDef.id,
226
+ label: fieldDef.label,
227
+ type: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit
228
+ config: { ...fieldDef.args, defaultValues },
229
+ hideLabelFromVision: fieldDef.id === 'content',
230
+ // getValue and setValue handle the mapping to block attributes
231
+ getValue: ( { item } ) => {
232
+ if ( fieldDef.mapping ) {
233
+ // Extract mapped properties from the block attributes
234
+ const mappedValue = {};
235
+ Object.entries( fieldDef.mapping ).forEach(
236
+ ( [ key, attrKey ] ) => {
237
+ mappedValue[ key ] = item[ attrKey ];
238
+ }
239
+ );
240
+
241
+ // Normalize to canonical structure based on field type
242
+ if ( fieldDef.type === 'media' ) {
243
+ return normalizeMediaValue( mappedValue, fieldDef );
244
+ }
245
+ if ( fieldDef.type === 'link' ) {
246
+ return normalizeLinkValue( mappedValue, fieldDef );
247
+ }
248
+
249
+ // For other types, return as-is
250
+ return mappedValue;
251
+ }
252
+ // For simple id-based fields, use the id as the attribute key
253
+ return item[ fieldDef.id ];
254
+ },
255
+ setValue: ( { item, value } ) => {
256
+ if ( fieldDef.mapping ) {
257
+ // Denormalize from canonical structure back to mapped keys
258
+ let denormalizedValue = value;
259
+ if ( fieldDef.type === 'media' ) {
260
+ denormalizedValue = denormalizeMediaValue(
261
+ value,
262
+ fieldDef
263
+ );
264
+ } else if ( fieldDef.type === 'link' ) {
265
+ denormalizedValue = denormalizeLinkValue(
266
+ value,
267
+ fieldDef
268
+ );
269
+ }
270
+
271
+ // Build an object with all mapped attributes
272
+ const updates = {};
273
+ Object.entries( fieldDef.mapping ).forEach(
274
+ ( [ key, attrKey ] ) => {
275
+ // If key is explicitly in value, use it (even if undefined to allow clearing)
276
+ // Otherwise, preserve the old value
277
+ if ( key in denormalizedValue ) {
278
+ updates[ attrKey ] =
279
+ denormalizedValue[ key ];
280
+ } else {
281
+ updates[ attrKey ] = item[ attrKey ];
282
+ }
283
+ }
284
+ );
285
+ return updates;
286
+ }
287
+ // For simple id-based fields, use the id as the attribute key
288
+ return { [ fieldDef.id ]: value };
289
+ },
290
+ };
291
+
292
+ // Only add custom Edit component if one exists for this type
293
+ if ( ControlComponent ) {
294
+ // Use EditConfig pattern: Edit is an object with control type and config props
295
+ field.Edit = createConfiguredControl( {
296
+ control: fieldDef.type,
297
+ clientId,
298
+ updateBlockAttributes,
299
+ fieldDef,
300
+ } );
301
+ }
302
+
303
+ return field;
304
+ } );
305
+ }, [
306
+ blockTypeFields,
307
+ blockType?.attributes,
308
+ clientId,
309
+ updateBlockAttributes,
310
+ ] );
311
+
312
+ const handleToggleField = ( fieldId ) => {
313
+ setForm( ( prev ) => {
314
+ if ( prev.fields?.includes( fieldId ) ) {
315
+ return {
316
+ ...prev,
317
+ fields: prev.fields.filter( ( id ) => id !== fieldId ),
318
+ };
319
+ }
320
+
321
+ return {
322
+ ...prev,
323
+ fields: [ ...( prev.fields || [] ), fieldId ],
324
+ };
325
+ } );
326
+ };
327
+
328
+ if ( ! blockTypeFields?.length ) {
329
+ // TODO - we might still want to show a placeholder for blocks with no fields.
330
+ // for example, a way to select the block.
331
+ return null;
332
+ }
333
+
334
+ return (
335
+ <div className="block-editor-content-only-controls__fields-container">
336
+ <div className="block-editor-content-only-controls__fields-header">
337
+ <HStack spacing={ 1 } justify="space-between" expanded>
338
+ <HStack spacing={ 1 } justify="flex-start">
339
+ <BlockIcon icon={ blockInformation?.icon } />
340
+ <div>{ blockTitle }</div>
341
+ </HStack>
342
+ <FieldsDropdownMenu
343
+ fields={ dataFormFields }
344
+ visibleFields={ form.fields }
345
+ onToggleField={ handleToggleField }
346
+ />
347
+ </HStack>
348
+ </div>
349
+ <DataForm
350
+ data={ attributes }
351
+ fields={ dataFormFields }
352
+ form={ form }
353
+ onChange={ ( changes ) => {
354
+ // Map field values to block attributes using field.setValue
355
+ const mappedChanges = {};
356
+ Object.entries( changes ).forEach(
357
+ ( [ fieldId, fieldValue ] ) => {
358
+ const field = dataFormFields.find(
359
+ ( f ) => f.id === fieldId
360
+ );
361
+ if ( field && field.setValue ) {
362
+ const updates = field.setValue( {
363
+ item: attributes,
364
+ value: fieldValue,
365
+ } );
366
+ Object.assign( mappedChanges, updates );
367
+ } else {
368
+ // For fields without setValue, use the value directly
369
+ mappedChanges[ fieldId ] = fieldValue;
370
+ }
371
+ }
372
+ );
373
+ updateBlockAttributes( clientId, mappedChanges );
374
+ } }
375
+ />
376
+ </div>
377
+ );
378
+ }
379
+
380
+ function DrillDownButton( { clientId } ) {
381
+ const blockTitle = useBlockDisplayTitle( {
382
+ clientId,
383
+ context: 'list-view',
384
+ } );
385
+ const blockInformation = useBlockDisplayInformation( clientId );
386
+ return (
387
+ <div className="block-editor-content-only-controls__button-panel">
388
+ <Navigator.Button
389
+ path={ `/${ clientId }` }
390
+ className="block-editor-content-only-controls__drill-down-button"
391
+ >
392
+ <HStack expanded justify="space-between">
393
+ <HStack justify="flex-start" spacing={ 1 }>
394
+ <BlockIcon icon={ blockInformation?.icon } />
395
+ <div>{ blockTitle }</div>
396
+ </HStack>
397
+ <Icon icon={ arrowRight } />
398
+ </HStack>
399
+ </Navigator.Button>
400
+ </div>
401
+ );
402
+ }
403
+
404
+ function ContentOnlyControlsScreen( {
405
+ rootClientId,
406
+ contentClientIds,
407
+ parentClientIds,
408
+ isNested,
409
+ } ) {
410
+ const isRootContentBlock = useSelect(
411
+ ( select ) => {
412
+ const { getBlockName } = select( blockEditorStore );
413
+ const blockName = getBlockName( rootClientId );
414
+ const { hasContentRoleAttribute } = unlock( select( blocksStore ) );
415
+ return hasContentRoleAttribute( blockName );
416
+ },
417
+ [ rootClientId ]
418
+ );
419
+
420
+ if ( ! isRootContentBlock && ! contentClientIds.length ) {
421
+ return null;
422
+ }
423
+
424
+ return (
425
+ <>
426
+ { isNested && (
427
+ <div className="block-editor-content-only-controls__button-panel">
428
+ <Navigator.BackButton className="block-editor-content-only-controls__back-button">
429
+ <HStack expanded spacing={ 1 } justify="flex-start">
430
+ <Icon icon={ arrowLeft } />
431
+ <div>{ __( 'Back' ) }</div>
432
+ </HStack>
433
+ </Navigator.BackButton>
434
+ </div>
435
+ ) }
436
+ { isRootContentBlock && <BlockFields clientId={ rootClientId } /> }
437
+ { contentClientIds.map( ( clientId ) => {
438
+ if ( parentClientIds?.[ clientId ] ) {
439
+ return (
440
+ <DrillDownButton
441
+ key={ clientId }
442
+ clientId={ clientId }
443
+ />
444
+ );
445
+ }
446
+
447
+ return <BlockFields key={ clientId } clientId={ clientId } />;
448
+ } ) }
449
+ </>
450
+ );
451
+ }
452
+
453
+ export default function ContentOnlyControls( { rootClientId } ) {
454
+ const { updatedRootClientId, nestedContentClientIds, contentClientIds } =
455
+ useSelect(
456
+ ( select ) => {
457
+ const { getClientIdsOfDescendants, getBlockEditingMode } =
458
+ select( blockEditorStore );
459
+
460
+ // _nestedContentClientIds is for content blocks within 'drilldowns'.
461
+ // It's an object where the key is the parent clientId, and the element is
462
+ // an array of child clientIds whose controls are shown within the drilldown.
463
+ const _nestedContentClientIds = {};
464
+
465
+ // _contentClientIds is the list of contentClientIds for blocks being
466
+ // shown at the root level. Includes parent blocks that might have a drilldown,
467
+ // but not the children of those blocks.
468
+ const _contentClientIds = [];
469
+
470
+ // An array of all nested client ids. Used for ensuring blocks within drilldowns
471
+ // don't appear at the root level.
472
+ let allNestedClientIds = [];
473
+
474
+ // A flattened list of all content clientIds to arrange into the
475
+ // groups above.
476
+ const allContentClientIds = getClientIdsOfDescendants(
477
+ rootClientId
478
+ ).filter(
479
+ ( clientId ) =>
480
+ getBlockEditingMode( clientId ) === 'contentOnly'
481
+ );
482
+
483
+ for ( const clientId of allContentClientIds ) {
484
+ const childClientIds = getClientIdsOfDescendants(
485
+ clientId
486
+ ).filter(
487
+ ( childClientId ) =>
488
+ getBlockEditingMode( childClientId ) ===
489
+ 'contentOnly'
490
+ );
491
+
492
+ // If there's more than one child block, use a drilldown.
493
+ if (
494
+ childClientIds.length > 1 &&
495
+ ! allNestedClientIds.includes( clientId )
496
+ ) {
497
+ _nestedContentClientIds[ clientId ] = childClientIds;
498
+ allNestedClientIds = [
499
+ allNestedClientIds,
500
+ ...childClientIds,
501
+ ];
502
+ }
503
+
504
+ if ( ! allNestedClientIds.includes( clientId ) ) {
505
+ _contentClientIds.push( clientId );
506
+ }
507
+ }
508
+
509
+ // Avoid showing only one drilldown block at the root.
510
+ if (
511
+ _contentClientIds.length === 1 &&
512
+ Object.keys( _nestedContentClientIds ).length === 1
513
+ ) {
514
+ const onlyParentClientId = Object.keys(
515
+ _nestedContentClientIds
516
+ )[ 0 ];
517
+ return {
518
+ updatedRootClientId: onlyParentClientId,
519
+ contentClientIds:
520
+ _nestedContentClientIds[ onlyParentClientId ],
521
+ nestedContentClientIds: {},
522
+ };
523
+ }
524
+
525
+ return {
526
+ nestedContentClientIds: _nestedContentClientIds,
527
+ contentClientIds: _contentClientIds,
528
+ };
529
+ },
530
+ [ rootClientId ]
531
+ );
532
+
533
+ return (
534
+ <Navigator initialPath="/">
535
+ <Navigator.Screen
536
+ path="/"
537
+ className="block-editor-content-only-controls__screen"
538
+ >
539
+ <ContentOnlyControlsScreen
540
+ rootClientId={ updatedRootClientId ?? rootClientId }
541
+ contentClientIds={ contentClientIds }
542
+ parentClientIds={ nestedContentClientIds }
543
+ />
544
+ </Navigator.Screen>
545
+ { Object.keys( nestedContentClientIds ).map( ( clientId ) => (
546
+ <Navigator.Screen
547
+ key={ clientId }
548
+ path={ `/${ clientId }` }
549
+ className="block-editor-content-only-controls__screen"
550
+ >
551
+ <ContentOnlyControlsScreen
552
+ isNested
553
+ rootClientId={ clientId }
554
+ contentClientIds={ nestedContentClientIds[ clientId ] }
555
+ />
556
+ </Navigator.Screen>
557
+ ) ) }
558
+ </Navigator>
559
+ );
560
+ }