@wordpress/block-editor 15.8.1-next.dc3f6d3c1.0 → 15.9.1-next.8b30e05b0.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 (216) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +4 -0
  3. package/build/components/block-list/index.js +2 -1
  4. package/build/components/block-list/index.js.map +2 -2
  5. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  6. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  7. package/build/components/block-lock/modal.js +5 -5
  8. package/build/components/block-lock/modal.js.map +2 -2
  9. package/build/components/block-lock/use-block-lock.js +10 -13
  10. package/build/components/block-lock/use-block-lock.js.map +2 -2
  11. package/build/components/block-settings-menu-controls/index.js +1 -1
  12. package/build/components/block-settings-menu-controls/index.js.map +2 -2
  13. package/build/components/block-tools/index.js +56 -45
  14. package/build/components/block-tools/index.js.map +3 -3
  15. package/build/components/block-visibility/toolbar.js +1 -1
  16. package/build/components/block-visibility/toolbar.js.map +1 -1
  17. package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
  18. package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  19. package/build/components/content-only-controls/index.js +225 -44
  20. package/build/components/content-only-controls/index.js.map +3 -3
  21. package/build/components/content-only-controls/link/index.js +92 -103
  22. package/build/components/content-only-controls/link/index.js.map +3 -3
  23. package/build/components/content-only-controls/media/index.js +134 -134
  24. package/build/components/content-only-controls/media/index.js.map +3 -3
  25. package/build/components/content-only-controls/rich-text/index.js +65 -74
  26. package/build/components/content-only-controls/rich-text/index.js.map +3 -3
  27. package/build/components/font-family/index.js +1 -15
  28. package/build/components/font-family/index.js.map +2 -2
  29. package/build/components/global-styles/dimensions-panel.js +35 -2
  30. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  31. package/build/components/global-styles/hooks.js +1 -1
  32. package/build/components/global-styles/hooks.js.map +2 -2
  33. package/build/components/global-styles/typography-panel.js +1 -2
  34. package/build/components/global-styles/typography-panel.js.map +2 -2
  35. package/build/components/index.js +3 -0
  36. package/build/components/index.js.map +2 -2
  37. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  38. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  39. package/build/components/link-control/index.js +15 -7
  40. package/build/components/link-control/index.js.map +2 -2
  41. package/build/components/list-view/block-select-button.js +3 -11
  42. package/build/components/list-view/block-select-button.js.map +2 -2
  43. package/build/components/list-view/block.js +9 -7
  44. package/build/components/list-view/block.js.map +2 -2
  45. package/build/components/media-placeholder/index.js +17 -4
  46. package/build/components/media-placeholder/index.js.map +2 -2
  47. package/build/components/media-placeholder/utils.js +60 -0
  48. package/build/components/media-placeholder/utils.js.map +7 -0
  49. package/build/components/media-replace-flow/index.js +20 -3
  50. package/build/components/media-replace-flow/index.js.map +2 -2
  51. package/build/components/tool-selector/index.js +46 -0
  52. package/build/components/tool-selector/index.js.map +7 -0
  53. package/build/components/use-block-commands/index.js +1 -1
  54. package/build/components/use-block-commands/index.js.map +2 -2
  55. package/build/components/use-block-drop-zone/index.js +1 -5
  56. package/build/components/use-block-drop-zone/index.js.map +2 -2
  57. package/build/hooks/dimensions.js +3 -3
  58. package/build/hooks/dimensions.js.map +2 -2
  59. package/build/hooks/metadata.js +1 -1
  60. package/build/hooks/metadata.js.map +2 -2
  61. package/build/hooks/utils.js +5 -1
  62. package/build/hooks/utils.js.map +2 -2
  63. package/build/store/private-selectors.js +43 -3
  64. package/build/store/private-selectors.js.map +2 -2
  65. package/build/store/reducer.js +2 -1
  66. package/build/store/reducer.js.map +2 -2
  67. package/build/store/selectors.js +6 -4
  68. package/build/store/selectors.js.map +2 -2
  69. package/build-module/components/block-list/index.js +2 -1
  70. package/build-module/components/block-list/index.js.map +2 -2
  71. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  72. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  73. package/build-module/components/block-lock/modal.js +5 -5
  74. package/build-module/components/block-lock/modal.js.map +2 -2
  75. package/build-module/components/block-lock/use-block-lock.js +10 -13
  76. package/build-module/components/block-lock/use-block-lock.js.map +2 -2
  77. package/build-module/components/block-settings-menu-controls/index.js +1 -1
  78. package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
  79. package/build-module/components/block-tools/index.js +56 -45
  80. package/build-module/components/block-tools/index.js.map +2 -2
  81. package/build-module/components/block-visibility/toolbar.js +1 -1
  82. package/build-module/components/block-visibility/toolbar.js.map +1 -1
  83. package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
  84. package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  85. package/build-module/components/content-only-controls/index.js +229 -46
  86. package/build-module/components/content-only-controls/index.js.map +2 -2
  87. package/build-module/components/content-only-controls/link/index.js +92 -104
  88. package/build-module/components/content-only-controls/link/index.js.map +2 -2
  89. package/build-module/components/content-only-controls/media/index.js +134 -135
  90. package/build-module/components/content-only-controls/media/index.js.map +2 -2
  91. package/build-module/components/content-only-controls/rich-text/index.js +67 -81
  92. package/build-module/components/content-only-controls/rich-text/index.js.map +2 -2
  93. package/build-module/components/font-family/index.js +1 -15
  94. package/build-module/components/font-family/index.js.map +2 -2
  95. package/build-module/components/global-styles/dimensions-panel.js +35 -2
  96. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  97. package/build-module/components/global-styles/hooks.js +1 -1
  98. package/build-module/components/global-styles/hooks.js.map +2 -2
  99. package/build-module/components/global-styles/typography-panel.js +1 -2
  100. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  101. package/build-module/components/index.js +2 -0
  102. package/build-module/components/index.js.map +2 -2
  103. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  104. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  105. package/build-module/components/link-control/index.js +16 -8
  106. package/build-module/components/link-control/index.js.map +2 -2
  107. package/build-module/components/list-view/block-select-button.js +3 -11
  108. package/build-module/components/list-view/block-select-button.js.map +2 -2
  109. package/build-module/components/list-view/block.js +9 -7
  110. package/build-module/components/list-view/block.js.map +2 -2
  111. package/build-module/components/media-placeholder/index.js +18 -5
  112. package/build-module/components/media-placeholder/index.js.map +2 -2
  113. package/build-module/components/media-placeholder/utils.js +35 -0
  114. package/build-module/components/media-placeholder/utils.js.map +7 -0
  115. package/build-module/components/media-replace-flow/index.js +20 -3
  116. package/build-module/components/media-replace-flow/index.js.map +2 -2
  117. package/build-module/components/tool-selector/index.js +15 -0
  118. package/build-module/components/tool-selector/index.js.map +7 -0
  119. package/build-module/components/use-block-commands/index.js +1 -1
  120. package/build-module/components/use-block-commands/index.js.map +2 -2
  121. package/build-module/components/use-block-drop-zone/index.js +1 -5
  122. package/build-module/components/use-block-drop-zone/index.js.map +2 -2
  123. package/build-module/hooks/dimensions.js +3 -3
  124. package/build-module/hooks/dimensions.js.map +2 -2
  125. package/build-module/hooks/metadata.js +1 -1
  126. package/build-module/hooks/metadata.js.map +2 -2
  127. package/build-module/hooks/utils.js +5 -1
  128. package/build-module/hooks/utils.js.map +2 -2
  129. package/build-module/store/private-selectors.js +39 -3
  130. package/build-module/store/private-selectors.js.map +2 -2
  131. package/build-module/store/reducer.js +2 -1
  132. package/build-module/store/reducer.js.map +2 -2
  133. package/build-module/store/selectors.js +6 -4
  134. package/build-module/store/selectors.js.map +2 -2
  135. package/build-style/content-rtl.css +3 -0
  136. package/build-style/content.css +3 -0
  137. package/build-style/style-rtl.css +14 -5
  138. package/build-style/style.css +14 -5
  139. package/package.json +38 -37
  140. package/src/components/block-list/content.scss +5 -0
  141. package/src/components/block-list/index.js +3 -1
  142. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
  143. package/src/components/block-lock/modal.js +6 -5
  144. package/src/components/block-lock/use-block-lock.js +10 -14
  145. package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
  146. package/src/components/block-settings-menu-controls/index.js +1 -1
  147. package/src/components/block-tools/index.js +15 -2
  148. package/src/components/block-tools/style.scss +4 -0
  149. package/src/components/block-visibility/toolbar.js +1 -1
  150. package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
  151. package/src/components/content-only-controls/index.js +314 -50
  152. package/src/components/content-only-controls/link/index.js +62 -57
  153. package/src/components/content-only-controls/media/index.js +177 -156
  154. package/src/components/content-only-controls/rich-text/index.js +30 -44
  155. package/src/components/content-only-controls/styles.scss +10 -1
  156. package/src/components/font-family/README.md +0 -9
  157. package/src/components/font-family/index.js +1 -16
  158. package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
  159. package/src/components/global-styles/dimensions-panel.js +36 -0
  160. package/src/components/global-styles/hooks.js +1 -1
  161. package/src/components/global-styles/typography-panel.js +0 -1
  162. package/src/components/index.js +4 -0
  163. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
  164. package/src/components/link-control/index.js +36 -12
  165. package/src/components/list-view/block-select-button.js +22 -30
  166. package/src/components/list-view/block.js +9 -7
  167. package/src/components/media-placeholder/index.js +20 -5
  168. package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
  169. package/src/components/media-placeholder/utils.js +65 -0
  170. package/src/components/media-replace-flow/index.js +22 -3
  171. package/src/components/tool-selector/index.js +19 -0
  172. package/src/components/use-block-commands/index.js +1 -1
  173. package/src/components/use-block-drop-zone/index.js +1 -5
  174. package/src/hooks/dimensions.js +8 -3
  175. package/src/hooks/metadata.js +1 -1
  176. package/src/hooks/test/metadata.js +1 -1
  177. package/src/hooks/utils.js +4 -0
  178. package/src/store/private-selectors.js +123 -6
  179. package/src/store/reducer.js +3 -0
  180. package/src/store/selectors.js +6 -4
  181. package/src/store/test/private-selectors.js +242 -0
  182. package/src/store/test/reducer.js +17 -7
  183. package/src/style.scss +0 -1
  184. package/tsconfig.json +1 -0
  185. package/build/components/content-only-controls/plain-text/index.js +0 -68
  186. package/build/components/content-only-controls/plain-text/index.js.map +0 -7
  187. package/build-module/components/content-only-controls/plain-text/index.js +0 -50
  188. package/build-module/components/content-only-controls/plain-text/index.js.map +0 -7
  189. package/src/components/content-only-controls/plain-text/index.js +0 -49
  190. package/src/components/font-family/style.scss +0 -7
  191. /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
  192. /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  193. /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
  194. /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
  195. /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
  196. /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
  197. /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
  198. /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
  199. /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
  200. /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
  201. /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
  202. /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
  203. /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
  204. /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
  205. /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
  206. /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
  207. /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
  208. /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
  209. /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
  210. /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  211. /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
  212. /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
  213. /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
  214. /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
  215. /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
  216. /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
@@ -1,9 +1,11 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store as blocksStore } from '@wordpress/blocks';
5
4
  import {
6
- __experimentalToolsPanel as ToolsPanel,
5
+ store as blocksStore,
6
+ privateApis as blocksPrivateApis,
7
+ } from '@wordpress/blocks';
8
+ import {
7
9
  __experimentalHStack as HStack,
8
10
  Icon,
9
11
  Navigator,
@@ -11,6 +13,8 @@ import {
11
13
  import { useDispatch, useSelect } from '@wordpress/data';
12
14
  import { __ } from '@wordpress/i18n';
13
15
  import { arrowLeft, arrowRight } from '@wordpress/icons';
16
+ import { DataForm } from '@wordpress/dataviews';
17
+ import { useState, useMemo } from '@wordpress/element';
14
18
 
15
19
  /**
16
20
  * Internal dependencies
@@ -20,45 +24,153 @@ import { store as blockEditorStore } from '../../store';
20
24
  import BlockIcon from '../block-icon';
21
25
  import useBlockDisplayTitle from '../block-title/use-block-display-title';
22
26
  import useBlockDisplayInformation from '../use-block-display-information';
23
- import { useInspectorPopoverPlacement } from './use-inspector-popover-placement';
27
+ const { fieldsKey, formKey } = unlock( blocksPrivateApis );
28
+ import FieldsDropdownMenu from './fields-dropdown-menu';
24
29
 
25
30
  // controls
26
- import PlainText from './plain-text';
27
31
  import RichText from './rich-text';
28
32
  import Media from './media';
29
33
  import Link from './link';
30
34
 
31
- const controls = {
32
- PlainText,
33
- RichText,
34
- Media,
35
- Link,
35
+ const CONTROLS = {
36
+ richtext: RichText,
37
+ media: Media,
38
+ link: Link,
36
39
  };
37
40
 
38
- function BlockAttributeToolsPanelItem( {
39
- clientId,
40
- control,
41
- blockType,
42
- attributeValues,
43
- } ) {
44
- const { updateBlockAttributes } = useDispatch( blockEditorStore );
45
- const ControlComponent = controls[ control.type ];
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 ];
46
52
 
47
53
  if ( ! ControlComponent ) {
48
- return null;
54
+ throw new Error( `Control type "${ control }" not found` );
49
55
  }
50
56
 
51
- return (
52
- <ControlComponent
53
- clientId={ clientId }
54
- control={ control }
55
- blockType={ blockType }
56
- attributeValues={ attributeValues }
57
- updateAttributes={ ( attributes ) =>
58
- updateBlockAttributes( clientId, attributes )
59
- }
60
- />
61
- );
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;
62
174
  }
63
175
 
64
176
  function BlockFields( { clientId } ) {
@@ -76,40 +188,192 @@ function BlockFields( { clientId } ) {
76
188
  [ clientId ]
77
189
  );
78
190
 
191
+ const { updateBlockAttributes } = useDispatch( blockEditorStore );
79
192
  const blockTitle = useBlockDisplayTitle( {
80
193
  clientId,
81
194
  context: 'list-view',
82
195
  } );
83
196
  const blockInformation = useBlockDisplayInformation( clientId );
84
- const popoverPlacementProps = useInspectorPopoverPlacement();
85
197
 
86
- if ( ! blockType?.fields?.length ) {
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 ) {
87
329
  // TODO - we might still want to show a placeholder for blocks with no fields.
88
330
  // for example, a way to select the block.
89
331
  return null;
90
332
  }
91
333
 
92
334
  return (
93
- <ToolsPanel
94
- label={
95
- <HStack spacing={ 1 }>
96
- <BlockIcon icon={ blockInformation?.icon } />
97
- <div>{ blockTitle }</div>
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
+ />
98
347
  </HStack>
99
- }
100
- panelId={ clientId }
101
- dropdownMenuProps={ popoverPlacementProps }
102
- >
103
- { blockType?.fields?.map( ( field, index ) => (
104
- <BlockAttributeToolsPanelItem
105
- key={ `${ clientId }/${ index }` }
106
- clientId={ clientId }
107
- control={ field }
108
- blockType={ blockType }
109
- attributeValues={ attributes }
110
- />
111
- ) ) }
112
- </ToolsPanel>
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>
113
377
  );
114
378
  }
115
379
 
@@ -4,7 +4,6 @@
4
4
  import {
5
5
  Button,
6
6
  Icon,
7
- __experimentalToolsPanelItem as ToolsPanelItem,
8
7
  __experimentalGrid as Grid,
9
8
  Popover,
10
9
  } from '@wordpress/components';
@@ -68,35 +67,21 @@ export function getUpdatedLinkAttributes( {
68
67
  };
69
68
  }
70
69
 
71
- export default function Link( {
72
- clientId,
73
- control,
74
- blockType,
75
- attributeValues,
76
- updateAttributes,
77
- } ) {
70
+ export default function Link( { data, field, config = {} } ) {
78
71
  const [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );
79
72
  const { popoverProps } = useInspectorPopoverPlacement( {
80
73
  isControl: true,
81
74
  } );
82
- const hrefKey = control.mapping.href;
83
- const relKey = control.mapping.rel;
84
- const targetKey = control.mapping.target;
85
- const destinationKey = control.mapping.destination;
86
-
87
- const href = attributeValues[ hrefKey ];
88
- const rel = attributeValues[ relKey ];
89
- const target = attributeValues[ targetKey ];
90
- const destination = attributeValues[ destinationKey ];
91
-
92
- const hrefDefaultValue =
93
- blockType.attributes[ href ]?.defaultValue ?? undefined;
94
- const relDefaultValue =
95
- blockType.attributes[ rel ]?.defaultValue ?? undefined;
96
- const targetDefaultValue =
97
- blockType.attributes[ target ]?.defaultValue ?? undefined;
98
- const destinationDefaultValue =
99
- blockType.attributes[ destination ]?.defaultValue ?? undefined;
75
+ const { clientId, updateBlockAttributes, fieldDef } = config;
76
+ const updateAttributes = ( newValue ) => {
77
+ const mappedChanges = field.setValue( { item: data, value: newValue } );
78
+ updateBlockAttributes( clientId, mappedChanges );
79
+ };
80
+
81
+ const value = field.getValue( { item: data } );
82
+ const url = value?.url;
83
+ const rel = value?.rel || '';
84
+ const target = value?.linkTarget;
100
85
 
101
86
  const opensInNewTab = target === NEW_TAB_TARGET;
102
87
  const nofollow = rel === NOFOLLOW_REL;
@@ -104,25 +89,12 @@ export default function Link( {
104
89
  // Memoize link value to avoid overriding the LinkControl's internal state.
105
90
  // This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/51256.
106
91
  const linkValue = useMemo(
107
- () => ( { url: href, opensInNewTab, nofollow } ),
108
- [ href, opensInNewTab, nofollow ]
92
+ () => ( { url, opensInNewTab, nofollow } ),
93
+ [ url, opensInNewTab, nofollow ]
109
94
  );
110
95
 
111
96
  return (
112
- <ToolsPanelItem
113
- panelId={ clientId }
114
- label={ control.label }
115
- hasValue={ () => !! href }
116
- onDeselect={ () => {
117
- updateAttributes( {
118
- [ hrefKey ]: hrefDefaultValue,
119
- [ relKey ]: relDefaultValue,
120
- [ targetKey ]: targetDefaultValue,
121
- [ destinationKey ]: destinationDefaultValue,
122
- } );
123
- } }
124
- isShownByDefault={ control.shownByDefault }
125
- >
97
+ <>
126
98
  <Button
127
99
  __next40pxDefaultSize
128
100
  className="block-editor-content-only-controls__link"
@@ -136,15 +108,15 @@ export default function Link( {
136
108
  templateColumns="24px 1fr"
137
109
  className="block-editor-content-only-controls__link-row"
138
110
  >
139
- { href && (
111
+ { url && (
140
112
  <>
141
113
  <Icon icon={ link } size={ 24 } />
142
114
  <span className="block-editor-content-only-controls__link-title">
143
- { href }
115
+ { url }
144
116
  </span>
145
117
  </>
146
118
  ) }
147
- { ! href && (
119
+ { ! url && (
148
120
  <>
149
121
  <Icon
150
122
  icon={ link }
@@ -173,23 +145,56 @@ export default function Link( {
173
145
  ...newValues,
174
146
  } );
175
147
 
176
- updateAttributes( {
177
- [ hrefKey ]: updatedAttrs.url,
178
- [ relKey ]: updatedAttrs.rel,
179
- [ targetKey ]: updatedAttrs.linkTarget,
180
- } );
148
+ // Build update object dynamically based on what's in the mapping
149
+ const updateValue = { ...value };
150
+
151
+ if ( fieldDef?.mapping ) {
152
+ Object.keys( fieldDef.mapping ).forEach(
153
+ ( key ) => {
154
+ if ( key === 'href' || key === 'url' ) {
155
+ updateValue[ key ] =
156
+ updatedAttrs.url;
157
+ } else if ( key === 'rel' ) {
158
+ updateValue[ key ] =
159
+ updatedAttrs.rel;
160
+ } else if (
161
+ key === 'target' ||
162
+ key === 'linkTarget'
163
+ ) {
164
+ updateValue[ key ] =
165
+ updatedAttrs.linkTarget;
166
+ }
167
+ }
168
+ );
169
+ }
170
+
171
+ updateAttributes( updateValue );
181
172
  } }
182
173
  onRemove={ () => {
183
- updateAttributes( {
184
- [ hrefKey ]: hrefDefaultValue,
185
- [ relKey ]: relDefaultValue,
186
- [ targetKey ]: targetDefaultValue,
187
- [ destinationKey ]: destinationDefaultValue,
188
- } );
174
+ // Remove all link-related properties based on what's in the mapping
175
+ const removeValue = {};
176
+
177
+ if ( fieldDef?.mapping ) {
178
+ Object.keys( fieldDef.mapping ).forEach(
179
+ ( key ) => {
180
+ if (
181
+ key === 'href' ||
182
+ key === 'url' ||
183
+ key === 'rel' ||
184
+ key === 'target' ||
185
+ key === 'linkTarget'
186
+ ) {
187
+ removeValue[ key ] = undefined;
188
+ }
189
+ }
190
+ );
191
+ }
192
+
193
+ updateAttributes( removeValue );
189
194
  } }
190
195
  />
191
196
  </Popover>
192
197
  ) }
193
- </ToolsPanelItem>
198
+ </>
194
199
  );
195
200
  }