@wordpress/block-editor 15.8.1-next.dc3f6d3c1.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 (205) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/block-list/index.js +2 -1
  3. package/build/components/block-list/index.js.map +2 -2
  4. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  5. package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  6. package/build/components/block-lock/modal.js +5 -5
  7. package/build/components/block-lock/modal.js.map +2 -2
  8. package/build/components/block-lock/use-block-lock.js +10 -13
  9. package/build/components/block-lock/use-block-lock.js.map +2 -2
  10. package/build/components/block-settings-menu-controls/index.js +1 -1
  11. package/build/components/block-settings-menu-controls/index.js.map +2 -2
  12. package/build/components/block-tools/index.js +56 -45
  13. package/build/components/block-tools/index.js.map +3 -3
  14. package/build/components/block-visibility/toolbar.js +1 -1
  15. package/build/components/block-visibility/toolbar.js.map +1 -1
  16. package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
  17. package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  18. package/build/components/content-only-controls/index.js +225 -44
  19. package/build/components/content-only-controls/index.js.map +3 -3
  20. package/build/components/content-only-controls/link/index.js +92 -103
  21. package/build/components/content-only-controls/link/index.js.map +3 -3
  22. package/build/components/content-only-controls/media/index.js +134 -134
  23. package/build/components/content-only-controls/media/index.js.map +3 -3
  24. package/build/components/content-only-controls/rich-text/index.js +65 -74
  25. package/build/components/content-only-controls/rich-text/index.js.map +3 -3
  26. package/build/components/font-family/index.js +1 -15
  27. package/build/components/font-family/index.js.map +2 -2
  28. package/build/components/global-styles/dimensions-panel.js +35 -2
  29. package/build/components/global-styles/dimensions-panel.js.map +2 -2
  30. package/build/components/global-styles/hooks.js +1 -1
  31. package/build/components/global-styles/hooks.js.map +2 -2
  32. package/build/components/global-styles/typography-panel.js +1 -2
  33. package/build/components/global-styles/typography-panel.js.map +2 -2
  34. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  35. package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  36. package/build/components/link-control/index.js +15 -7
  37. package/build/components/link-control/index.js.map +2 -2
  38. package/build/components/list-view/block-select-button.js +3 -11
  39. package/build/components/list-view/block-select-button.js.map +2 -2
  40. package/build/components/list-view/block.js +9 -7
  41. package/build/components/list-view/block.js.map +2 -2
  42. package/build/components/media-placeholder/index.js +17 -4
  43. package/build/components/media-placeholder/index.js.map +2 -2
  44. package/build/components/media-placeholder/utils.js +60 -0
  45. package/build/components/media-placeholder/utils.js.map +7 -0
  46. package/build/components/media-replace-flow/index.js +20 -3
  47. package/build/components/media-replace-flow/index.js.map +2 -2
  48. package/build/components/use-block-commands/index.js +1 -1
  49. package/build/components/use-block-commands/index.js.map +2 -2
  50. package/build/components/use-block-drop-zone/index.js +1 -5
  51. package/build/components/use-block-drop-zone/index.js.map +2 -2
  52. package/build/hooks/dimensions.js +3 -3
  53. package/build/hooks/dimensions.js.map +2 -2
  54. package/build/hooks/metadata.js +1 -1
  55. package/build/hooks/metadata.js.map +2 -2
  56. package/build/hooks/utils.js +5 -1
  57. package/build/hooks/utils.js.map +2 -2
  58. package/build/store/private-selectors.js +43 -3
  59. package/build/store/private-selectors.js.map +2 -2
  60. package/build/store/reducer.js +2 -1
  61. package/build/store/reducer.js.map +2 -2
  62. package/build/store/selectors.js +6 -4
  63. package/build/store/selectors.js.map +2 -2
  64. package/build-module/components/block-list/index.js +2 -1
  65. package/build-module/components/block-list/index.js.map +2 -2
  66. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
  67. package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
  68. package/build-module/components/block-lock/modal.js +5 -5
  69. package/build-module/components/block-lock/modal.js.map +2 -2
  70. package/build-module/components/block-lock/use-block-lock.js +10 -13
  71. package/build-module/components/block-lock/use-block-lock.js.map +2 -2
  72. package/build-module/components/block-settings-menu-controls/index.js +1 -1
  73. package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
  74. package/build-module/components/block-tools/index.js +56 -45
  75. package/build-module/components/block-tools/index.js.map +2 -2
  76. package/build-module/components/block-visibility/toolbar.js +1 -1
  77. package/build-module/components/block-visibility/toolbar.js.map +1 -1
  78. package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
  79. package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
  80. package/build-module/components/content-only-controls/index.js +229 -46
  81. package/build-module/components/content-only-controls/index.js.map +2 -2
  82. package/build-module/components/content-only-controls/link/index.js +92 -104
  83. package/build-module/components/content-only-controls/link/index.js.map +2 -2
  84. package/build-module/components/content-only-controls/media/index.js +134 -135
  85. package/build-module/components/content-only-controls/media/index.js.map +2 -2
  86. package/build-module/components/content-only-controls/rich-text/index.js +67 -81
  87. package/build-module/components/content-only-controls/rich-text/index.js.map +2 -2
  88. package/build-module/components/font-family/index.js +1 -15
  89. package/build-module/components/font-family/index.js.map +2 -2
  90. package/build-module/components/global-styles/dimensions-panel.js +35 -2
  91. package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
  92. package/build-module/components/global-styles/hooks.js +1 -1
  93. package/build-module/components/global-styles/hooks.js.map +2 -2
  94. package/build-module/components/global-styles/typography-panel.js +1 -2
  95. package/build-module/components/global-styles/typography-panel.js.map +2 -2
  96. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
  97. package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
  98. package/build-module/components/link-control/index.js +16 -8
  99. package/build-module/components/link-control/index.js.map +2 -2
  100. package/build-module/components/list-view/block-select-button.js +3 -11
  101. package/build-module/components/list-view/block-select-button.js.map +2 -2
  102. package/build-module/components/list-view/block.js +9 -7
  103. package/build-module/components/list-view/block.js.map +2 -2
  104. package/build-module/components/media-placeholder/index.js +18 -5
  105. package/build-module/components/media-placeholder/index.js.map +2 -2
  106. package/build-module/components/media-placeholder/utils.js +35 -0
  107. package/build-module/components/media-placeholder/utils.js.map +7 -0
  108. package/build-module/components/media-replace-flow/index.js +20 -3
  109. package/build-module/components/media-replace-flow/index.js.map +2 -2
  110. package/build-module/components/use-block-commands/index.js +1 -1
  111. package/build-module/components/use-block-commands/index.js.map +2 -2
  112. package/build-module/components/use-block-drop-zone/index.js +1 -5
  113. package/build-module/components/use-block-drop-zone/index.js.map +2 -2
  114. package/build-module/hooks/dimensions.js +3 -3
  115. package/build-module/hooks/dimensions.js.map +2 -2
  116. package/build-module/hooks/metadata.js +1 -1
  117. package/build-module/hooks/metadata.js.map +2 -2
  118. package/build-module/hooks/utils.js +5 -1
  119. package/build-module/hooks/utils.js.map +2 -2
  120. package/build-module/store/private-selectors.js +39 -3
  121. package/build-module/store/private-selectors.js.map +2 -2
  122. package/build-module/store/reducer.js +2 -1
  123. package/build-module/store/reducer.js.map +2 -2
  124. package/build-module/store/selectors.js +6 -4
  125. package/build-module/store/selectors.js.map +2 -2
  126. package/build-style/content-rtl.css +3 -0
  127. package/build-style/content.css +3 -0
  128. package/build-style/style-rtl.css +14 -5
  129. package/build-style/style.css +14 -5
  130. package/package.json +38 -37
  131. package/src/components/block-list/content.scss +5 -0
  132. package/src/components/block-list/index.js +3 -1
  133. package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
  134. package/src/components/block-lock/modal.js +6 -5
  135. package/src/components/block-lock/use-block-lock.js +10 -14
  136. package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
  137. package/src/components/block-settings-menu-controls/index.js +1 -1
  138. package/src/components/block-tools/index.js +15 -2
  139. package/src/components/block-tools/style.scss +4 -0
  140. package/src/components/block-visibility/toolbar.js +1 -1
  141. package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
  142. package/src/components/content-only-controls/index.js +314 -50
  143. package/src/components/content-only-controls/link/index.js +62 -57
  144. package/src/components/content-only-controls/media/index.js +177 -156
  145. package/src/components/content-only-controls/rich-text/index.js +30 -44
  146. package/src/components/content-only-controls/styles.scss +10 -1
  147. package/src/components/font-family/README.md +0 -9
  148. package/src/components/font-family/index.js +1 -16
  149. package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
  150. package/src/components/global-styles/dimensions-panel.js +36 -0
  151. package/src/components/global-styles/hooks.js +1 -1
  152. package/src/components/global-styles/typography-panel.js +0 -1
  153. package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
  154. package/src/components/link-control/index.js +36 -12
  155. package/src/components/list-view/block-select-button.js +22 -30
  156. package/src/components/list-view/block.js +9 -7
  157. package/src/components/media-placeholder/index.js +20 -5
  158. package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
  159. package/src/components/media-placeholder/utils.js +65 -0
  160. package/src/components/media-replace-flow/index.js +22 -3
  161. package/src/components/use-block-commands/index.js +1 -1
  162. package/src/components/use-block-drop-zone/index.js +1 -5
  163. package/src/hooks/dimensions.js +8 -3
  164. package/src/hooks/metadata.js +1 -1
  165. package/src/hooks/test/metadata.js +1 -1
  166. package/src/hooks/utils.js +4 -0
  167. package/src/store/private-selectors.js +123 -6
  168. package/src/store/reducer.js +3 -0
  169. package/src/store/selectors.js +6 -4
  170. package/src/store/test/private-selectors.js +242 -0
  171. package/src/store/test/reducer.js +17 -7
  172. package/src/style.scss +0 -1
  173. package/tsconfig.json +1 -0
  174. package/build/components/content-only-controls/plain-text/index.js +0 -68
  175. package/build/components/content-only-controls/plain-text/index.js.map +0 -7
  176. package/build-module/components/content-only-controls/plain-text/index.js +0 -50
  177. package/build-module/components/content-only-controls/plain-text/index.js.map +0 -7
  178. package/src/components/content-only-controls/plain-text/index.js +0 -49
  179. package/src/components/font-family/style.scss +0 -7
  180. /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
  181. /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  182. /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
  183. /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
  184. /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
  185. /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
  186. /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
  187. /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
  188. /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
  189. /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
  190. /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
  191. /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
  192. /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
  193. /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
  194. /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
  195. /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
  196. /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
  197. /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
  198. /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
  199. /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
  200. /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
  201. /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
  202. /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
  203. /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
  204. /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
  205. /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
@@ -2,7 +2,6 @@
2
2
  import {
3
3
  Button,
4
4
  Icon,
5
- __experimentalToolsPanelItem as ToolsPanelItem,
6
5
  __experimentalGrid as Grid,
7
6
  Popover
8
7
  } from "@wordpress/components";
@@ -43,124 +42,113 @@ function getUpdatedLinkAttributes({
43
42
  rel: updatedRel || void 0
44
43
  };
45
44
  }
46
- function Link({
47
- clientId,
48
- control,
49
- blockType,
50
- attributeValues,
51
- updateAttributes
52
- }) {
45
+ function Link({ data, field, config = {} }) {
53
46
  const [isLinkControlOpen, setIsLinkControlOpen] = useState(false);
54
47
  const { popoverProps } = useInspectorPopoverPlacement({
55
48
  isControl: true
56
49
  });
57
- const hrefKey = control.mapping.href;
58
- const relKey = control.mapping.rel;
59
- const targetKey = control.mapping.target;
60
- const destinationKey = control.mapping.destination;
61
- const href = attributeValues[hrefKey];
62
- const rel = attributeValues[relKey];
63
- const target = attributeValues[targetKey];
64
- const destination = attributeValues[destinationKey];
65
- const hrefDefaultValue = blockType.attributes[href]?.defaultValue ?? void 0;
66
- const relDefaultValue = blockType.attributes[rel]?.defaultValue ?? void 0;
67
- const targetDefaultValue = blockType.attributes[target]?.defaultValue ?? void 0;
68
- const destinationDefaultValue = blockType.attributes[destination]?.defaultValue ?? void 0;
50
+ const { clientId, updateBlockAttributes, fieldDef } = config;
51
+ const updateAttributes = (newValue) => {
52
+ const mappedChanges = field.setValue({ item: data, value: newValue });
53
+ updateBlockAttributes(clientId, mappedChanges);
54
+ };
55
+ const value = field.getValue({ item: data });
56
+ const url = value?.url;
57
+ const rel = value?.rel || "";
58
+ const target = value?.linkTarget;
69
59
  const opensInNewTab = target === NEW_TAB_TARGET;
70
60
  const nofollow = rel === NOFOLLOW_REL;
71
61
  const linkValue = useMemo(
72
- () => ({ url: href, opensInNewTab, nofollow }),
73
- [href, opensInNewTab, nofollow]
62
+ () => ({ url, opensInNewTab, nofollow }),
63
+ [url, opensInNewTab, nofollow]
74
64
  );
75
- return /* @__PURE__ */ jsxs(
76
- ToolsPanelItem,
77
- {
78
- panelId: clientId,
79
- label: control.label,
80
- hasValue: () => !!href,
81
- onDeselect: () => {
82
- updateAttributes({
83
- [hrefKey]: hrefDefaultValue,
84
- [relKey]: relDefaultValue,
85
- [targetKey]: targetDefaultValue,
86
- [destinationKey]: destinationDefaultValue
87
- });
88
- },
89
- isShownByDefault: control.shownByDefault,
90
- children: [
91
- /* @__PURE__ */ jsx(
92
- Button,
65
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
66
+ /* @__PURE__ */ jsx(
67
+ Button,
68
+ {
69
+ __next40pxDefaultSize: true,
70
+ className: "block-editor-content-only-controls__link",
71
+ onClick: () => {
72
+ setIsLinkControlOpen(true);
73
+ },
74
+ children: /* @__PURE__ */ jsxs(
75
+ Grid,
93
76
  {
94
- __next40pxDefaultSize: true,
95
- className: "block-editor-content-only-controls__link",
96
- onClick: () => {
97
- setIsLinkControlOpen(true);
98
- },
99
- children: /* @__PURE__ */ jsxs(
100
- Grid,
101
- {
102
- rowGap: 0,
103
- columnGap: 8,
104
- templateColumns: "24px 1fr",
105
- className: "block-editor-content-only-controls__link-row",
106
- children: [
107
- href && /* @__PURE__ */ jsxs(Fragment, { children: [
108
- /* @__PURE__ */ jsx(Icon, { icon: link, size: 24 }),
109
- /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: href })
110
- ] }),
111
- !href && /* @__PURE__ */ jsxs(Fragment, { children: [
112
- /* @__PURE__ */ jsx(
113
- Icon,
114
- {
115
- icon: link,
116
- size: 24,
117
- style: { opacity: 0.3 }
118
- }
119
- ),
120
- /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: __("Link") })
121
- ] })
122
- ]
123
- }
124
- )
77
+ rowGap: 0,
78
+ columnGap: 8,
79
+ templateColumns: "24px 1fr",
80
+ className: "block-editor-content-only-controls__link-row",
81
+ children: [
82
+ url && /* @__PURE__ */ jsxs(Fragment, { children: [
83
+ /* @__PURE__ */ jsx(Icon, { icon: link, size: 24 }),
84
+ /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: url })
85
+ ] }),
86
+ !url && /* @__PURE__ */ jsxs(Fragment, { children: [
87
+ /* @__PURE__ */ jsx(
88
+ Icon,
89
+ {
90
+ icon: link,
91
+ size: 24,
92
+ style: { opacity: 0.3 }
93
+ }
94
+ ),
95
+ /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__link-title", children: __("Link") })
96
+ ] })
97
+ ]
125
98
  }
126
- ),
127
- isLinkControlOpen && /* @__PURE__ */ jsx(
128
- Popover,
99
+ )
100
+ }
101
+ ),
102
+ isLinkControlOpen && /* @__PURE__ */ jsx(
103
+ Popover,
104
+ {
105
+ onClose: () => {
106
+ setIsLinkControlOpen(false);
107
+ },
108
+ ...popoverProps ?? {},
109
+ children: /* @__PURE__ */ jsx(
110
+ LinkControl,
129
111
  {
130
- onClose: () => {
131
- setIsLinkControlOpen(false);
112
+ value: linkValue,
113
+ onChange: (newValues) => {
114
+ const updatedAttrs = getUpdatedLinkAttributes({
115
+ rel,
116
+ ...newValues
117
+ });
118
+ const updateValue = { ...value };
119
+ if (fieldDef?.mapping) {
120
+ Object.keys(fieldDef.mapping).forEach(
121
+ (key) => {
122
+ if (key === "href" || key === "url") {
123
+ updateValue[key] = updatedAttrs.url;
124
+ } else if (key === "rel") {
125
+ updateValue[key] = updatedAttrs.rel;
126
+ } else if (key === "target" || key === "linkTarget") {
127
+ updateValue[key] = updatedAttrs.linkTarget;
128
+ }
129
+ }
130
+ );
131
+ }
132
+ updateAttributes(updateValue);
132
133
  },
133
- ...popoverProps ?? {},
134
- children: /* @__PURE__ */ jsx(
135
- LinkControl,
136
- {
137
- value: linkValue,
138
- onChange: (newValues) => {
139
- const updatedAttrs = getUpdatedLinkAttributes({
140
- rel,
141
- ...newValues
142
- });
143
- updateAttributes({
144
- [hrefKey]: updatedAttrs.url,
145
- [relKey]: updatedAttrs.rel,
146
- [targetKey]: updatedAttrs.linkTarget
147
- });
148
- },
149
- onRemove: () => {
150
- updateAttributes({
151
- [hrefKey]: hrefDefaultValue,
152
- [relKey]: relDefaultValue,
153
- [targetKey]: targetDefaultValue,
154
- [destinationKey]: destinationDefaultValue
155
- });
156
- }
134
+ onRemove: () => {
135
+ const removeValue = {};
136
+ if (fieldDef?.mapping) {
137
+ Object.keys(fieldDef.mapping).forEach(
138
+ (key) => {
139
+ if (key === "href" || key === "url" || key === "rel" || key === "target" || key === "linkTarget") {
140
+ removeValue[key] = void 0;
141
+ }
142
+ }
143
+ );
157
144
  }
158
- )
145
+ updateAttributes(removeValue);
146
+ }
159
147
  }
160
148
  )
161
- ]
162
- }
163
- );
149
+ }
150
+ )
151
+ ] });
164
152
  }
165
153
  export {
166
154
  NEW_TAB_REL,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/content-only-controls/link/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n\t__experimentalGrid as Grid,\n\tPopover,\n} from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { link } from '@wordpress/icons';\nimport { prependHTTP } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport LinkControl from '../../link-control';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\n\nexport const NEW_TAB_REL = 'noreferrer noopener';\nexport const NEW_TAB_TARGET = '_blank';\nexport const NOFOLLOW_REL = 'nofollow';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object} attributes The current block attributes.\n * @param {string} attributes.rel The current link rel attribute.\n * @param {string} attributes.url The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t\tupdatedRel = updatedRel?.includes( NEW_TAB_REL )\n\t\t\t? updatedRel\n\t\t\t: updatedRel + ` ${ NEW_TAB_REL }`;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTP( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n\nexport default function Link( {\n\tclientId,\n\tcontrol,\n\tblockType,\n\tattributeValues,\n\tupdateAttributes,\n} ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst hrefKey = control.mapping.href;\n\tconst relKey = control.mapping.rel;\n\tconst targetKey = control.mapping.target;\n\tconst destinationKey = control.mapping.destination;\n\n\tconst href = attributeValues[ hrefKey ];\n\tconst rel = attributeValues[ relKey ];\n\tconst target = attributeValues[ targetKey ];\n\tconst destination = attributeValues[ destinationKey ];\n\n\tconst hrefDefaultValue =\n\t\tblockType.attributes[ href ]?.defaultValue ?? undefined;\n\tconst relDefaultValue =\n\t\tblockType.attributes[ rel ]?.defaultValue ?? undefined;\n\tconst targetDefaultValue =\n\t\tblockType.attributes[ target ]?.defaultValue ?? undefined;\n\tconst destinationDefaultValue =\n\t\tblockType.attributes[ destination ]?.defaultValue ?? undefined;\n\n\tconst opensInNewTab = target === NEW_TAB_TARGET;\n\tconst nofollow = rel === NOFOLLOW_REL;\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/51256.\n\tconst linkValue = useMemo(\n\t\t() => ( { url: href, opensInNewTab, nofollow } ),\n\t\t[ href, opensInNewTab, nofollow ]\n\t);\n\n\treturn (\n\t\t<ToolsPanelItem\n\t\t\tpanelId={ clientId }\n\t\t\tlabel={ control.label }\n\t\t\thasValue={ () => !! href }\n\t\t\tonDeselect={ () => {\n\t\t\t\tupdateAttributes( {\n\t\t\t\t\t[ hrefKey ]: hrefDefaultValue,\n\t\t\t\t\t[ relKey ]: relDefaultValue,\n\t\t\t\t\t[ targetKey ]: targetDefaultValue,\n\t\t\t\t\t[ destinationKey ]: destinationDefaultValue,\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tisShownByDefault={ control.shownByDefault }\n\t\t>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"block-editor-content-only-controls__link\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsLinkControlOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Grid\n\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__link-row\"\n\t\t\t\t>\n\t\t\t\t\t{ href && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon icon={ link } size={ 24 } />\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ href }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! href && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\t\t\tsize={ 24 }\n\t\t\t\t\t\t\t\tstyle={ { opacity: 0.3 } }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ __( 'Link' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Grid>\n\t\t\t</Button>\n\t\t\t{ isLinkControlOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsLinkControlOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...( popoverProps ?? {} ) }\n\t\t\t\t>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\tvalue={ linkValue }\n\t\t\t\t\t\tonChange={ ( newValues ) => {\n\t\t\t\t\t\t\tconst updatedAttrs = getUpdatedLinkAttributes( {\n\t\t\t\t\t\t\t\trel,\n\t\t\t\t\t\t\t\t...newValues,\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\tupdateAttributes( {\n\t\t\t\t\t\t\t\t[ hrefKey ]: updatedAttrs.url,\n\t\t\t\t\t\t\t\t[ relKey ]: updatedAttrs.rel,\n\t\t\t\t\t\t\t\t[ targetKey ]: updatedAttrs.linkTarget,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\tupdateAttributes( {\n\t\t\t\t\t\t\t\t[ hrefKey ]: hrefDefaultValue,\n\t\t\t\t\t\t\t\t[ relKey ]: relDefaultValue,\n\t\t\t\t\t\t\t\t[ targetKey ]: targetDefaultValue,\n\t\t\t\t\t\t\t\t[ destinationKey ]: destinationDefaultValue,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</ToolsPanelItem>\n\t);\n}\n"],
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AK;AAAA,oBAChC,oBAAC,UAAK,WAAU,kDACb,gBACH;AAAA,qBACD;AAAA,kBAEC,CAAE,QACH,iCACC;AAAA;AAAA,sBAAC;AAAA;AAAA,wBACA,MAAO;AAAA,wBACP,MAAO;AAAA,wBACP,OAAQ,EAAE,SAAS,IAAI;AAAA;AAAA,oBACxB;AAAA,oBACA,oBAAC,UAAK,WAAU,kDACb,aAAI,MAAO,GACd;AAAA,qBACD;AAAA;AAAA;AAAA,YAEF;AAAA;AAAA,QACD;AAAA,QACE,qBACD;AAAA,UAAC;AAAA;AAAA,YACA,SAAU,MAAM;AACf,mCAAsB,KAAM;AAAA,YAC7B;AAAA,YACE,GAAK,gBAAgB,CAAC;AAAA,YAExB;AAAA,cAAC;AAAA;AAAA,gBACA,OAAQ;AAAA,gBACR,UAAW,CAAE,cAAe;AAC3B,wBAAM,eAAe,yBAA0B;AAAA,oBAC9C;AAAA,oBACA,GAAG;AAAA,kBACJ,CAAE;AAEF,mCAAkB;AAAA,oBACjB,CAAE,OAAQ,GAAG,aAAa;AAAA,oBAC1B,CAAE,MAAO,GAAG,aAAa;AAAA,oBACzB,CAAE,SAAU,GAAG,aAAa;AAAA,kBAC7B,CAAE;AAAA,gBACH;AAAA,gBACA,UAAW,MAAM;AAChB,mCAAkB;AAAA,oBACjB,CAAE,OAAQ,GAAG;AAAA,oBACb,CAAE,MAAO,GAAG;AAAA,oBACZ,CAAE,SAAU,GAAG;AAAA,oBACf,CAAE,cAAe,GAAG;AAAA,kBACrB,CAAE;AAAA,gBACH;AAAA;AAAA,YACD;AAAA;AAAA,QACD;AAAA;AAAA;AAAA,EAEF;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tIcon,\n\t__experimentalGrid as Grid,\n\tPopover,\n} from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { link } from '@wordpress/icons';\nimport { prependHTTP } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport LinkControl from '../../link-control';\nimport { useInspectorPopoverPlacement } from '../use-inspector-popover-placement';\n\nexport const NEW_TAB_REL = 'noreferrer noopener';\nexport const NEW_TAB_TARGET = '_blank';\nexport const NOFOLLOW_REL = 'nofollow';\n\n/**\n * Updates the link attributes.\n *\n * @param {Object} attributes The current block attributes.\n * @param {string} attributes.rel The current link rel attribute.\n * @param {string} attributes.url The current link url.\n * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window.\n * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow.\n */\nexport function getUpdatedLinkAttributes( {\n\trel = '',\n\turl = '',\n\topensInNewTab,\n\tnofollow,\n} ) {\n\tlet newLinkTarget;\n\t// Since `rel` is editable attribute, we need to check for existing values and proceed accordingly.\n\tlet updatedRel = rel;\n\n\tif ( opensInNewTab ) {\n\t\tnewLinkTarget = NEW_TAB_TARGET;\n\t\tupdatedRel = updatedRel?.includes( NEW_TAB_REL )\n\t\t\t? updatedRel\n\t\t\t: updatedRel + ` ${ NEW_TAB_REL }`;\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NEW_TAB_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\tif ( nofollow ) {\n\t\tupdatedRel = updatedRel?.includes( NOFOLLOW_REL )\n\t\t\t? updatedRel\n\t\t\t: ( updatedRel + ` ${ NOFOLLOW_REL }` ).trim();\n\t} else {\n\t\tconst relRegex = new RegExp( `\\\\b${ NOFOLLOW_REL }\\\\s*`, 'g' );\n\t\tupdatedRel = updatedRel?.replace( relRegex, '' ).trim();\n\t}\n\n\treturn {\n\t\turl: prependHTTP( url ),\n\t\tlinkTarget: newLinkTarget,\n\t\trel: updatedRel || undefined,\n\t};\n}\n\nexport default function Link( { data, field, config = {} } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst { clientId, updateBlockAttributes, fieldDef } = config;\n\tconst updateAttributes = ( newValue ) => {\n\t\tconst mappedChanges = field.setValue( { item: data, value: newValue } );\n\t\tupdateBlockAttributes( clientId, mappedChanges );\n\t};\n\n\tconst value = field.getValue( { item: data } );\n\tconst url = value?.url;\n\tconst rel = value?.rel || '';\n\tconst target = value?.linkTarget;\n\n\tconst opensInNewTab = target === NEW_TAB_TARGET;\n\tconst nofollow = rel === NOFOLLOW_REL;\n\n\t// Memoize link value to avoid overriding the LinkControl's internal state.\n\t// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/51256.\n\tconst linkValue = useMemo(\n\t\t() => ( { url, opensInNewTab, nofollow } ),\n\t\t[ url, opensInNewTab, nofollow ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"block-editor-content-only-controls__link\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsLinkControlOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<Grid\n\t\t\t\t\trowGap={ 0 }\n\t\t\t\t\tcolumnGap={ 8 }\n\t\t\t\t\ttemplateColumns=\"24px 1fr\"\n\t\t\t\t\tclassName=\"block-editor-content-only-controls__link-row\"\n\t\t\t\t>\n\t\t\t\t\t{ url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon icon={ link } size={ 24 } />\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ url }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! url && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\ticon={ link }\n\t\t\t\t\t\t\t\tsize={ 24 }\n\t\t\t\t\t\t\t\tstyle={ { opacity: 0.3 } }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<span className=\"block-editor-content-only-controls__link-title\">\n\t\t\t\t\t\t\t\t{ __( 'Link' ) }\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</Grid>\n\t\t\t</Button>\n\t\t\t{ isLinkControlOpen && (\n\t\t\t\t<Popover\n\t\t\t\t\tonClose={ () => {\n\t\t\t\t\t\tsetIsLinkControlOpen( false );\n\t\t\t\t\t} }\n\t\t\t\t\t{ ...( popoverProps ?? {} ) }\n\t\t\t\t>\n\t\t\t\t\t<LinkControl\n\t\t\t\t\t\tvalue={ linkValue }\n\t\t\t\t\t\tonChange={ ( newValues ) => {\n\t\t\t\t\t\t\tconst updatedAttrs = getUpdatedLinkAttributes( {\n\t\t\t\t\t\t\t\trel,\n\t\t\t\t\t\t\t\t...newValues,\n\t\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t\t// Build update object dynamically based on what's in the mapping\n\t\t\t\t\t\t\tconst updateValue = { ...value };\n\n\t\t\t\t\t\t\tif ( fieldDef?.mapping ) {\n\t\t\t\t\t\t\t\tObject.keys( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t\t\t( key ) => {\n\t\t\t\t\t\t\t\t\t\tif ( key === 'href' || key === 'url' ) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.url;\n\t\t\t\t\t\t\t\t\t\t} else if ( key === 'rel' ) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.rel;\n\t\t\t\t\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t\t\t\t\tkey === 'target' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'linkTarget'\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tupdateValue[ key ] =\n\t\t\t\t\t\t\t\t\t\t\t\tupdatedAttrs.linkTarget;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tupdateAttributes( updateValue );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonRemove={ () => {\n\t\t\t\t\t\t\t// Remove all link-related properties based on what's in the mapping\n\t\t\t\t\t\t\tconst removeValue = {};\n\n\t\t\t\t\t\t\tif ( fieldDef?.mapping ) {\n\t\t\t\t\t\t\t\tObject.keys( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t\t\t( key ) => {\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\tkey === 'href' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'url' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'rel' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'target' ||\n\t\t\t\t\t\t\t\t\t\t\tkey === 'linkTarget'\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\tremoveValue[ key ] = undefined;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tupdateAttributes( removeValue );\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</Popover>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],
5
+ "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,EACtB;AAAA,OACM;AACP,SAAS,SAAS,gBAAgB;AAClC,SAAS,UAAU;AACnB,SAAS,YAAY;AACrB,SAAS,mBAAmB;AAK5B,OAAO,iBAAiB;AACxB,SAAS,oCAAoC;AA6FvC,mBACC,KADD;AA3FC,IAAM,cAAc;AACpB,IAAM,iBAAiB;AACvB,IAAM,eAAe;AAWrB,SAAS,yBAA0B;AAAA,EACzC,MAAM;AAAA,EACN,MA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oBACf,WACC,QAAQ,YACR,QAAQ,cACP;AACD,kCAAa,GAAI,IAChB,aAAa;AAAA,oBACf;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAEA,+BAAkB,WAAY;AAAA,YAC/B;AAAA,YACA,UAAW,MAAM;AAEhB,oBAAM,cAAc,CAAC;AAErB,kBAAK,UAAU,SAAU;AACxB,uBAAO,KAAM,SAAS,OAAQ,EAAE;AAAA,kBAC/B,CAAE,QAAS;AACV,wBACC,QAAQ,UACR,QAAQ,SACR,QAAQ,SACR,QAAQ,YACR,QAAQ,cACP;AACD,kCAAa,GAAI,IAAI;AAAA,oBACtB;AAAA,kBACD;AAAA,gBACD;AAAA,cACD;AAEA,+BAAkB,WAAY;AAAA,YAC/B;AAAA;AAAA,QACD;AAAA;AAAA,IACD;AAAA,KAEF;AAEF;",
6
6
  "names": []
7
7
  }
@@ -2,11 +2,9 @@
2
2
  import {
3
3
  Button,
4
4
  Icon,
5
- __experimentalToolsPanelItem as ToolsPanelItem,
6
5
  __experimentalGrid as Grid
7
6
  } from "@wordpress/components";
8
7
  import { useSelect } from "@wordpress/data";
9
- import { useMemo } from "@wordpress/element";
10
8
  import { __ } from "@wordpress/i18n";
11
9
  import {
12
10
  audio as audioIcon,
@@ -20,9 +18,9 @@ import { useInspectorPopoverPlacement } from "../use-inspector-popover-placement
20
18
  import { getMediaSelectKey } from "../../../store/private-keys";
21
19
  import { store as blockEditorStore } from "../../../store";
22
20
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
23
- function MediaThumbnail({ control, attributeValues, attachment }) {
24
- const { allowedTypes, multiple } = control.args;
25
- const mapping = control.mapping;
21
+ function MediaThumbnail({ data, field, attachment }) {
22
+ const config = field.config || {};
23
+ const { allowedTypes = [], multiple = false } = config;
26
24
  if (multiple) {
27
25
  return "todo multiple";
28
26
  }
@@ -39,13 +37,9 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
39
37
  );
40
38
  }
41
39
  if (allowedTypes.length === 1) {
42
- let src;
43
- if (allowedTypes[0] === "image" && mapping.src && attributeValues[mapping.src]) {
44
- src = attributeValues[mapping.src];
45
- } else if (allowedTypes[0] === "video" && mapping.poster && attributeValues[mapping.poster]) {
46
- src = attributeValues[mapping.poster];
47
- }
48
- if (src) {
40
+ const value = field.getValue({ item: data });
41
+ const url = value?.url;
42
+ if (url) {
49
43
  return /* @__PURE__ */ jsx(
50
44
  "img",
51
45
  {
@@ -53,7 +47,7 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
53
47
  alt: "",
54
48
  width: 24,
55
49
  height: 24,
56
- src
50
+ src: url
57
51
  }
58
52
  );
59
53
  }
@@ -73,28 +67,23 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
73
67
  }
74
68
  return /* @__PURE__ */ jsx(Icon, { icon: mediaIcon, size: 24 });
75
69
  }
76
- function Media({
77
- clientId,
78
- control,
79
- blockType,
80
- attributeValues,
81
- updateAttributes
82
- }) {
70
+ function Media({ data, field, config = {} }) {
83
71
  const { popoverProps } = useInspectorPopoverPlacement({
84
72
  isControl: true
85
73
  });
86
- const typeKey = control.mapping.type;
87
- const idKey = control.mapping.id;
88
- const srcKey = control.mapping.src;
89
- const captionKey = control.mapping.caption;
90
- const altKey = control.mapping.alt;
91
- const posterKey = control.mapping.poster;
92
- const featuredImageKey = control.mapping.featuredImage;
93
- const id = attributeValues[idKey];
94
- const src = attributeValues[srcKey];
95
- const caption = attributeValues[captionKey];
96
- const alt = attributeValues[altKey];
97
- const useFeaturedImage = attributeValues[featuredImageKey];
74
+ const value = field.getValue({ item: data });
75
+ const { allowedTypes = [], multiple = false } = field.config || {};
76
+ const { clientId, updateBlockAttributes, fieldDef } = config;
77
+ const updateAttributes = (newFieldValue) => {
78
+ const mappedChanges = field.setValue({
79
+ item: data,
80
+ value: newFieldValue
81
+ });
82
+ updateBlockAttributes(clientId, mappedChanges);
83
+ };
84
+ const hasFeaturedImageSupport = fieldDef?.mapping && "featuredImage" in fieldDef.mapping;
85
+ const id = value?.id;
86
+ const url = value?.url;
98
87
  const attachment = useSelect(
99
88
  (select) => {
100
89
  if (!id) {
@@ -110,8 +99,8 @@ function Media({
110
99
  [id]
111
100
  );
112
101
  let chooseItemLabel;
113
- if (control.args.allowedTypes.length === 1) {
114
- const allowedType = control.args.allowedTypes[0];
102
+ if (allowedTypes.length === 1) {
103
+ const allowedType = allowedTypes[0];
115
104
  if (allowedType === "image") {
116
105
  chooseItemLabel = __("Choose an image\u2026");
117
106
  } else if (allowedType === "video") {
@@ -124,112 +113,122 @@ function Media({
124
113
  } else {
125
114
  chooseItemLabel = __("Choose a media item\u2026");
126
115
  }
127
- const defaultValues = useMemo(() => {
128
- return Object.fromEntries(
129
- Object.entries(control.mapping).map(([, attributeKey]) => {
130
- return [
131
- attributeKey,
132
- blockType.attributes[attributeKey]?.defaultValue ?? void 0
133
- ];
134
- })
135
- );
136
- }, [blockType.attributes, control.mapping]);
137
116
  return /* @__PURE__ */ jsx(MediaUploadCheck, { children: /* @__PURE__ */ jsx(
138
- ToolsPanelItem,
117
+ MediaReplaceFlow,
139
118
  {
140
- panelId: clientId,
141
- label: control.label,
142
- hasValue: () => !!src,
143
- onDeselect: () => {
144
- updateAttributes(defaultValues);
119
+ className: "block-editor-content-only-controls__media-replace-flow",
120
+ allowedTypes,
121
+ mediaId: id,
122
+ mediaURL: url,
123
+ multiple,
124
+ popoverProps,
125
+ onReset: () => {
126
+ const resetValue = {};
127
+ if (fieldDef?.mapping) {
128
+ Object.keys(fieldDef.mapping).forEach((key) => {
129
+ if (key === "id" || key === "src" || key === "url") {
130
+ resetValue[key] = void 0;
131
+ } else if (key === "caption" || key === "alt") {
132
+ resetValue[key] = "";
133
+ }
134
+ });
135
+ }
136
+ if (hasFeaturedImageSupport) {
137
+ resetValue.featuredImage = false;
138
+ }
139
+ updateAttributes({ ...value, ...resetValue });
145
140
  },
146
- isShownByDefault: control.shownByDefault,
147
- children: /* @__PURE__ */ jsx(
148
- MediaReplaceFlow,
149
- {
150
- className: "block-editor-content-only-controls__media-replace-flow",
151
- allowedTypes: control.args.allowedTypes,
152
- mediaId: id,
153
- mediaURL: src,
154
- multiple: control.args.multiple,
155
- popoverProps,
156
- onReset: () => {
157
- updateAttributes(defaultValues);
158
- },
159
- useFeaturedImage: !!useFeaturedImage,
160
- onToggleFeaturedImage: !!featuredImageKey && (() => {
161
- updateAttributes({
162
- ...defaultValues,
163
- [featuredImageKey]: !useFeaturedImage
164
- });
165
- }),
166
- onSelect: (selectedMedia) => {
167
- if (selectedMedia.id && selectedMedia.url) {
168
- const optionalAttributes = {};
169
- if (typeKey && selectedMedia.type) {
170
- optionalAttributes[typeKey] = selectedMedia.type;
171
- }
172
- if (captionKey && !caption && selectedMedia.caption) {
173
- optionalAttributes[captionKey] = selectedMedia.caption;
174
- }
175
- if (altKey && !alt && selectedMedia.alt) {
176
- optionalAttributes[altKey] = selectedMedia.alt;
177
- }
178
- if (posterKey && selectedMedia.poster) {
179
- optionalAttributes[posterKey] = selectedMedia.poster;
180
- }
181
- updateAttributes({
182
- [idKey]: selectedMedia.id,
183
- [srcKey]: selectedMedia.url,
184
- ...optionalAttributes
185
- });
141
+ ...hasFeaturedImageSupport && {
142
+ useFeaturedImage: !!value?.featuredImage,
143
+ onToggleFeaturedImage: () => {
144
+ updateAttributes({
145
+ ...value,
146
+ featuredImage: !value?.featuredImage
147
+ });
148
+ }
149
+ },
150
+ onSelect: (selectedMedia) => {
151
+ if (selectedMedia.id && selectedMedia.url) {
152
+ let mediaType = "image";
153
+ if (selectedMedia.mime_type) {
154
+ if (selectedMedia.mime_type.startsWith("video/")) {
155
+ mediaType = "video";
156
+ } else if (selectedMedia.mime_type.startsWith("audio/")) {
157
+ mediaType = "audio";
186
158
  }
187
- },
188
- renderToggle: (buttonProps) => /* @__PURE__ */ jsx(
189
- Button,
190
- {
191
- __next40pxDefaultSize: true,
192
- className: "block-editor-content-only-controls__media",
193
- ...buttonProps,
194
- children: /* @__PURE__ */ jsxs(
195
- Grid,
196
- {
197
- rowGap: 0,
198
- columnGap: 8,
199
- templateColumns: "24px 1fr",
200
- className: "block-editor-content-only-controls__media-row",
201
- children: [
202
- src && /* @__PURE__ */ jsxs(Fragment, { children: [
203
- /* @__PURE__ */ jsx(
204
- MediaThumbnail,
205
- {
206
- attachment,
207
- control,
208
- attributeValues
209
- }
210
- ),
211
- /* @__PURE__ */ jsx("span", {
212
- className: "block-editor-content-only-controls__media-title",
213
- // TODO - truncate long titles or url smartly (e.g. show filename).
214
- children: attachment?.title?.raw && attachment?.title?.raw !== "" ? attachment?.title?.raw : src
215
- })
216
- ] }),
217
- !src && /* @__PURE__ */ jsxs(Fragment, { children: [
218
- /* @__PURE__ */ jsx(
219
- "span",
220
- {
221
- className: "block-editor-content-only-controls__media-placeholder",
222
- style: {
223
- width: "24px",
224
- height: "24px"
225
- }
226
- }
227
- ),
228
- /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__media-title", children: chooseItemLabel })
229
- ] })
230
- ]
159
+ }
160
+ const newValue = {};
161
+ if (fieldDef?.mapping) {
162
+ Object.keys(fieldDef.mapping).forEach(
163
+ (key) => {
164
+ if (key === "id") {
165
+ newValue[key] = selectedMedia.id;
166
+ } else if (key === "src" || key === "url") {
167
+ newValue[key] = selectedMedia.url;
168
+ } else if (key === "type") {
169
+ newValue[key] = mediaType;
170
+ } else if (key === "link" && selectedMedia.link) {
171
+ newValue[key] = selectedMedia.link;
172
+ } else if (key === "caption" && !value?.caption && selectedMedia.caption) {
173
+ newValue[key] = selectedMedia.caption;
174
+ } else if (key === "alt" && !value?.alt && selectedMedia.alt) {
175
+ newValue[key] = selectedMedia.alt;
176
+ } else if (key === "poster" && selectedMedia.poster) {
177
+ newValue[key] = selectedMedia.poster;
231
178
  }
232
- )
179
+ }
180
+ );
181
+ }
182
+ if (hasFeaturedImageSupport) {
183
+ newValue.featuredImage = false;
184
+ }
185
+ const finalValue = { ...value, ...newValue };
186
+ updateAttributes(finalValue);
187
+ }
188
+ },
189
+ renderToggle: (buttonProps) => /* @__PURE__ */ jsx(
190
+ Button,
191
+ {
192
+ __next40pxDefaultSize: true,
193
+ className: "block-editor-content-only-controls__media",
194
+ ...buttonProps,
195
+ children: /* @__PURE__ */ jsxs(
196
+ Grid,
197
+ {
198
+ rowGap: 0,
199
+ columnGap: 8,
200
+ templateColumns: "24px 1fr",
201
+ className: "block-editor-content-only-controls__media-row",
202
+ children: [
203
+ url && /* @__PURE__ */ jsxs(Fragment, { children: [
204
+ /* @__PURE__ */ jsx(
205
+ MediaThumbnail,
206
+ {
207
+ attachment,
208
+ field,
209
+ data
210
+ }
211
+ ),
212
+ /* @__PURE__ */ jsx("span", {
213
+ className: "block-editor-content-only-controls__media-title",
214
+ // TODO - truncate long titles or url smartly (e.g. show filename).
215
+ children: attachment?.title?.raw && attachment?.title?.raw !== "" ? attachment?.title?.raw : url
216
+ })
217
+ ] }),
218
+ !url && /* @__PURE__ */ jsxs(Fragment, { children: [
219
+ /* @__PURE__ */ jsx(
220
+ "span",
221
+ {
222
+ className: "block-editor-content-only-controls__media-placeholder",
223
+ style: {
224
+ width: "24px",
225
+ height: "24px"
226
+ }
227
+ }
228
+ ),
229
+ /* @__PURE__ */ jsx("span", { className: "block-editor-content-only-controls__media-title", children: chooseItemLabel })
230
+ ] })
231
+ ]
233
232
  }
234
233
  )
235
234
  }