@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.
- package/CHANGELOG.md +2 -0
- package/README.md +4 -0
- package/build/components/block-list/index.js +2 -1
- package/build/components/block-list/index.js.map +2 -2
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build/components/block-lock/modal.js +5 -5
- package/build/components/block-lock/modal.js.map +2 -2
- package/build/components/block-lock/use-block-lock.js +10 -13
- package/build/components/block-lock/use-block-lock.js.map +2 -2
- package/build/components/block-settings-menu-controls/index.js +1 -1
- package/build/components/block-settings-menu-controls/index.js.map +2 -2
- package/build/components/block-tools/index.js +56 -45
- package/build/components/block-tools/index.js.map +3 -3
- package/build/components/block-visibility/toolbar.js +1 -1
- package/build/components/block-visibility/toolbar.js.map +1 -1
- package/build/components/content-only-controls/fields-dropdown-menu.js +66 -0
- package/build/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build/components/content-only-controls/index.js +225 -44
- package/build/components/content-only-controls/index.js.map +3 -3
- package/build/components/content-only-controls/link/index.js +92 -103
- package/build/components/content-only-controls/link/index.js.map +3 -3
- package/build/components/content-only-controls/media/index.js +134 -134
- package/build/components/content-only-controls/media/index.js.map +3 -3
- package/build/components/content-only-controls/rich-text/index.js +65 -74
- package/build/components/content-only-controls/rich-text/index.js.map +3 -3
- package/build/components/font-family/index.js +1 -15
- package/build/components/font-family/index.js.map +2 -2
- package/build/components/global-styles/dimensions-panel.js +35 -2
- package/build/components/global-styles/dimensions-panel.js.map +2 -2
- package/build/components/global-styles/hooks.js +1 -1
- package/build/components/global-styles/hooks.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +1 -2
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/index.js +3 -0
- package/build/components/index.js.map +2 -2
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build/components/link-control/index.js +15 -7
- package/build/components/link-control/index.js.map +2 -2
- package/build/components/list-view/block-select-button.js +3 -11
- package/build/components/list-view/block-select-button.js.map +2 -2
- package/build/components/list-view/block.js +9 -7
- package/build/components/list-view/block.js.map +2 -2
- package/build/components/media-placeholder/index.js +17 -4
- package/build/components/media-placeholder/index.js.map +2 -2
- package/build/components/media-placeholder/utils.js +60 -0
- package/build/components/media-placeholder/utils.js.map +7 -0
- package/build/components/media-replace-flow/index.js +20 -3
- package/build/components/media-replace-flow/index.js.map +2 -2
- package/build/components/tool-selector/index.js +46 -0
- package/build/components/tool-selector/index.js.map +7 -0
- package/build/components/use-block-commands/index.js +1 -1
- package/build/components/use-block-commands/index.js.map +2 -2
- package/build/components/use-block-drop-zone/index.js +1 -5
- package/build/components/use-block-drop-zone/index.js.map +2 -2
- package/build/hooks/dimensions.js +3 -3
- package/build/hooks/dimensions.js.map +2 -2
- package/build/hooks/metadata.js +1 -1
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/utils.js +5 -1
- package/build/hooks/utils.js.map +2 -2
- package/build/store/private-selectors.js +43 -3
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/reducer.js +2 -1
- package/build/store/reducer.js.map +2 -2
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -1
- package/build-module/components/block-list/index.js.map +2 -2
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js +27 -5
- package/build-module/components/block-list/use-block-props/use-selected-block-event-handlers.js.map +2 -2
- package/build-module/components/block-lock/modal.js +5 -5
- package/build-module/components/block-lock/modal.js.map +2 -2
- package/build-module/components/block-lock/use-block-lock.js +10 -13
- package/build-module/components/block-lock/use-block-lock.js.map +2 -2
- package/build-module/components/block-settings-menu-controls/index.js +1 -1
- package/build-module/components/block-settings-menu-controls/index.js.map +2 -2
- package/build-module/components/block-tools/index.js +56 -45
- package/build-module/components/block-tools/index.js.map +2 -2
- package/build-module/components/block-visibility/toolbar.js +1 -1
- package/build-module/components/block-visibility/toolbar.js.map +1 -1
- package/build-module/components/content-only-controls/fields-dropdown-menu.js +45 -0
- package/build-module/components/content-only-controls/fields-dropdown-menu.js.map +7 -0
- package/build-module/components/content-only-controls/index.js +229 -46
- package/build-module/components/content-only-controls/index.js.map +2 -2
- package/build-module/components/content-only-controls/link/index.js +92 -104
- package/build-module/components/content-only-controls/link/index.js.map +2 -2
- package/build-module/components/content-only-controls/media/index.js +134 -135
- package/build-module/components/content-only-controls/media/index.js.map +2 -2
- package/build-module/components/content-only-controls/rich-text/index.js +67 -81
- package/build-module/components/content-only-controls/rich-text/index.js.map +2 -2
- package/build-module/components/font-family/index.js +1 -15
- package/build-module/components/font-family/index.js.map +2 -2
- package/build-module/components/global-styles/dimensions-panel.js +35 -2
- package/build-module/components/global-styles/dimensions-panel.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -1
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +1 -2
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/index.js +2 -0
- package/build-module/components/index.js.map +2 -2
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -1
- package/build-module/components/inspector-controls-tabs/use-inspector-controls-tabs.js.map +2 -2
- package/build-module/components/link-control/index.js +16 -8
- package/build-module/components/link-control/index.js.map +2 -2
- package/build-module/components/list-view/block-select-button.js +3 -11
- package/build-module/components/list-view/block-select-button.js.map +2 -2
- package/build-module/components/list-view/block.js +9 -7
- package/build-module/components/list-view/block.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +18 -5
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-placeholder/utils.js +35 -0
- package/build-module/components/media-placeholder/utils.js.map +7 -0
- package/build-module/components/media-replace-flow/index.js +20 -3
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/tool-selector/index.js +15 -0
- package/build-module/components/tool-selector/index.js.map +7 -0
- package/build-module/components/use-block-commands/index.js +1 -1
- package/build-module/components/use-block-commands/index.js.map +2 -2
- package/build-module/components/use-block-drop-zone/index.js +1 -5
- package/build-module/components/use-block-drop-zone/index.js.map +2 -2
- package/build-module/hooks/dimensions.js +3 -3
- package/build-module/hooks/dimensions.js.map +2 -2
- package/build-module/hooks/metadata.js +1 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/utils.js +5 -1
- package/build-module/hooks/utils.js.map +2 -2
- package/build-module/store/private-selectors.js +39 -3
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/reducer.js +2 -1
- package/build-module/store/reducer.js.map +2 -2
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +2 -2
- package/build-style/content-rtl.css +3 -0
- package/build-style/content.css +3 -0
- package/build-style/style-rtl.css +14 -5
- package/build-style/style.css +14 -5
- package/package.json +38 -37
- package/src/components/block-list/content.scss +5 -0
- package/src/components/block-list/index.js +3 -1
- package/src/components/block-list/use-block-props/use-selected-block-event-handlers.js +34 -3
- package/src/components/block-lock/modal.js +6 -5
- package/src/components/block-lock/use-block-lock.js +10 -14
- package/src/components/block-patterns-list/stories/{index.story.js → index.story.jsx} +3 -1
- package/src/components/block-settings-menu-controls/index.js +1 -1
- package/src/components/block-tools/index.js +15 -2
- package/src/components/block-tools/style.scss +4 -0
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/content-only-controls/fields-dropdown-menu.js +53 -0
- package/src/components/content-only-controls/index.js +314 -50
- package/src/components/content-only-controls/link/index.js +62 -57
- package/src/components/content-only-controls/media/index.js +177 -156
- package/src/components/content-only-controls/rich-text/index.js +30 -44
- package/src/components/content-only-controls/styles.scss +10 -1
- package/src/components/font-family/README.md +0 -9
- package/src/components/font-family/index.js +1 -16
- package/src/components/font-family/stories/{index.story.js → index.story.jsx} +0 -1
- package/src/components/global-styles/dimensions-panel.js +36 -0
- package/src/components/global-styles/hooks.js +1 -1
- package/src/components/global-styles/typography-panel.js +0 -1
- package/src/components/index.js +4 -0
- package/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +1 -5
- package/src/components/link-control/index.js +36 -12
- package/src/components/list-view/block-select-button.js +22 -30
- package/src/components/list-view/block.js +9 -7
- package/src/components/media-placeholder/index.js +20 -5
- package/src/components/media-placeholder/test/get-computed-accept-attribute.js +164 -0
- package/src/components/media-placeholder/utils.js +65 -0
- package/src/components/media-replace-flow/index.js +22 -3
- package/src/components/tool-selector/index.js +19 -0
- package/src/components/use-block-commands/index.js +1 -1
- package/src/components/use-block-drop-zone/index.js +1 -5
- package/src/hooks/dimensions.js +8 -3
- package/src/hooks/metadata.js +1 -1
- package/src/hooks/test/metadata.js +1 -1
- package/src/hooks/utils.js +4 -0
- package/src/store/private-selectors.js +123 -6
- package/src/store/reducer.js +3 -0
- package/src/store/selectors.js +6 -4
- package/src/store/test/private-selectors.js +242 -0
- package/src/store/test/reducer.js +17 -7
- package/src/style.scss +0 -1
- package/tsconfig.json +1 -0
- package/build/components/content-only-controls/plain-text/index.js +0 -68
- package/build/components/content-only-controls/plain-text/index.js.map +0 -7
- package/build-module/components/content-only-controls/plain-text/index.js +0 -50
- package/build-module/components/content-only-controls/plain-text/index.js.map +0 -7
- package/src/components/content-only-controls/plain-text/index.js +0 -49
- package/src/components/font-family/style.scss +0 -7
- /package/src/components/alignment-control/stories/{aliginment-toolbar.story.js → aliginment-toolbar.story.jsx} +0 -0
- /package/src/components/alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-alignment-matrix-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-draggable/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-heading-level-dropdown/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-mover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/block-title/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/border-radius-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/date-format-picker/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{aspect-ratio-tool.story.js → aspect-ratio-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{scale-tool.story.js → scale-tool.story.jsx} +0 -0
- /package/src/components/dimensions-tool/stories/{width-height-tool.story.js → width-height-tool.story.jsx} +0 -0
- /package/src/components/height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/inserter/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/line-height-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/plain-text/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/resolution-tool/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/tabbed-sidebar/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-alignment-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-decoration-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/text-transform-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/unit-control/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/url-popover/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/warning/stories/{index.story.js → index.story.jsx} +0 -0
- /package/src/components/writing-mode-control/stories/{index.story.js → index.story.jsx} +0 -0
|
@@ -75,124 +75,113 @@ function getUpdatedLinkAttributes({
|
|
|
75
75
|
rel: updatedRel || void 0
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
function Link({
|
|
79
|
-
clientId,
|
|
80
|
-
control,
|
|
81
|
-
blockType,
|
|
82
|
-
attributeValues,
|
|
83
|
-
updateAttributes
|
|
84
|
-
}) {
|
|
78
|
+
function Link({ data, field, config = {} }) {
|
|
85
79
|
const [isLinkControlOpen, setIsLinkControlOpen] = (0, import_element.useState)(false);
|
|
86
80
|
const { popoverProps } = (0, import_use_inspector_popover_placement.useInspectorPopoverPlacement)({
|
|
87
81
|
isControl: true
|
|
88
82
|
});
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const relDefaultValue = blockType.attributes[rel]?.defaultValue ?? void 0;
|
|
99
|
-
const targetDefaultValue = blockType.attributes[target]?.defaultValue ?? void 0;
|
|
100
|
-
const destinationDefaultValue = blockType.attributes[destination]?.defaultValue ?? void 0;
|
|
83
|
+
const { clientId, updateBlockAttributes, fieldDef } = config;
|
|
84
|
+
const updateAttributes = (newValue) => {
|
|
85
|
+
const mappedChanges = field.setValue({ item: data, value: newValue });
|
|
86
|
+
updateBlockAttributes(clientId, mappedChanges);
|
|
87
|
+
};
|
|
88
|
+
const value = field.getValue({ item: data });
|
|
89
|
+
const url = value?.url;
|
|
90
|
+
const rel = value?.rel || "";
|
|
91
|
+
const target = value?.linkTarget;
|
|
101
92
|
const opensInNewTab = target === NEW_TAB_TARGET;
|
|
102
93
|
const nofollow = rel === NOFOLLOW_REL;
|
|
103
94
|
const linkValue = (0, import_element.useMemo)(
|
|
104
|
-
() => ({ url
|
|
105
|
-
[
|
|
95
|
+
() => ({ url, opensInNewTab, nofollow }),
|
|
96
|
+
[url, opensInNewTab, nofollow]
|
|
106
97
|
);
|
|
107
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
[destinationKey]: destinationDefaultValue
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
isShownByDefault: control.shownByDefault,
|
|
122
|
-
children: [
|
|
123
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
124
|
-
import_components.Button,
|
|
98
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
99
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
import_components.Button,
|
|
101
|
+
{
|
|
102
|
+
__next40pxDefaultSize: true,
|
|
103
|
+
className: "block-editor-content-only-controls__link",
|
|
104
|
+
onClick: () => {
|
|
105
|
+
setIsLinkControlOpen(true);
|
|
106
|
+
},
|
|
107
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
108
|
+
import_components.__experimentalGrid,
|
|
125
109
|
{
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
icon: import_icons.link,
|
|
148
|
-
size: 24,
|
|
149
|
-
style: { opacity: 0.3 }
|
|
150
|
-
}
|
|
151
|
-
),
|
|
152
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-content-only-controls__link-title", children: (0, import_i18n.__)("Link") })
|
|
153
|
-
] })
|
|
154
|
-
]
|
|
155
|
-
}
|
|
156
|
-
)
|
|
110
|
+
rowGap: 0,
|
|
111
|
+
columnGap: 8,
|
|
112
|
+
templateColumns: "24px 1fr",
|
|
113
|
+
className: "block-editor-content-only-controls__link-row",
|
|
114
|
+
children: [
|
|
115
|
+
url && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
116
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Icon, { icon: import_icons.link, size: 24 }),
|
|
117
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-content-only-controls__link-title", children: url })
|
|
118
|
+
] }),
|
|
119
|
+
!url && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
120
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
121
|
+
import_components.Icon,
|
|
122
|
+
{
|
|
123
|
+
icon: import_icons.link,
|
|
124
|
+
size: 24,
|
|
125
|
+
style: { opacity: 0.3 }
|
|
126
|
+
}
|
|
127
|
+
),
|
|
128
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-content-only-controls__link-title", children: (0, import_i18n.__)("Link") })
|
|
129
|
+
] })
|
|
130
|
+
]
|
|
157
131
|
}
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
isLinkControlOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
+
import_components.Popover,
|
|
137
|
+
{
|
|
138
|
+
onClose: () => {
|
|
139
|
+
setIsLinkControlOpen(false);
|
|
140
|
+
},
|
|
141
|
+
...popoverProps ?? {},
|
|
142
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
143
|
+
import_link_control.default,
|
|
161
144
|
{
|
|
162
|
-
|
|
163
|
-
|
|
145
|
+
value: linkValue,
|
|
146
|
+
onChange: (newValues) => {
|
|
147
|
+
const updatedAttrs = getUpdatedLinkAttributes({
|
|
148
|
+
rel,
|
|
149
|
+
...newValues
|
|
150
|
+
});
|
|
151
|
+
const updateValue = { ...value };
|
|
152
|
+
if (fieldDef?.mapping) {
|
|
153
|
+
Object.keys(fieldDef.mapping).forEach(
|
|
154
|
+
(key) => {
|
|
155
|
+
if (key === "href" || key === "url") {
|
|
156
|
+
updateValue[key] = updatedAttrs.url;
|
|
157
|
+
} else if (key === "rel") {
|
|
158
|
+
updateValue[key] = updatedAttrs.rel;
|
|
159
|
+
} else if (key === "target" || key === "linkTarget") {
|
|
160
|
+
updateValue[key] = updatedAttrs.linkTarget;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
updateAttributes(updateValue);
|
|
164
166
|
},
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
updateAttributes({
|
|
176
|
-
[hrefKey]: updatedAttrs.url,
|
|
177
|
-
[relKey]: updatedAttrs.rel,
|
|
178
|
-
[targetKey]: updatedAttrs.linkTarget
|
|
179
|
-
});
|
|
180
|
-
},
|
|
181
|
-
onRemove: () => {
|
|
182
|
-
updateAttributes({
|
|
183
|
-
[hrefKey]: hrefDefaultValue,
|
|
184
|
-
[relKey]: relDefaultValue,
|
|
185
|
-
[targetKey]: targetDefaultValue,
|
|
186
|
-
[destinationKey]: destinationDefaultValue
|
|
187
|
-
});
|
|
188
|
-
}
|
|
167
|
+
onRemove: () => {
|
|
168
|
+
const removeValue = {};
|
|
169
|
+
if (fieldDef?.mapping) {
|
|
170
|
+
Object.keys(fieldDef.mapping).forEach(
|
|
171
|
+
(key) => {
|
|
172
|
+
if (key === "href" || key === "url" || key === "rel" || key === "target" || key === "linkTarget") {
|
|
173
|
+
removeValue[key] = void 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
);
|
|
189
177
|
}
|
|
190
|
-
|
|
178
|
+
updateAttributes(removeValue);
|
|
179
|
+
}
|
|
191
180
|
}
|
|
192
181
|
)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
);
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
] });
|
|
196
185
|
}
|
|
197
186
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
187
|
0 && (module.exports = {
|
|
@@ -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\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["
|
|
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": "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",
|
|
6
|
+
"names": ["Grid", "LinkControl"]
|
|
7
7
|
}
|
|
@@ -35,7 +35,6 @@ __export(media_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(media_exports);
|
|
36
36
|
var import_components = require("@wordpress/components");
|
|
37
37
|
var import_data = require("@wordpress/data");
|
|
38
|
-
var import_element = require("@wordpress/element");
|
|
39
38
|
var import_i18n = require("@wordpress/i18n");
|
|
40
39
|
var import_icons = require("@wordpress/icons");
|
|
41
40
|
var import_media_replace_flow = __toESM(require("../../media-replace-flow"));
|
|
@@ -44,9 +43,9 @@ var import_use_inspector_popover_placement = require("../use-inspector-popover-p
|
|
|
44
43
|
var import_private_keys = require("../../../store/private-keys");
|
|
45
44
|
var import_store = require("../../../store");
|
|
46
45
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
47
|
-
function MediaThumbnail({
|
|
48
|
-
const
|
|
49
|
-
const
|
|
46
|
+
function MediaThumbnail({ data, field, attachment }) {
|
|
47
|
+
const config = field.config || {};
|
|
48
|
+
const { allowedTypes = [], multiple = false } = config;
|
|
50
49
|
if (multiple) {
|
|
51
50
|
return "todo multiple";
|
|
52
51
|
}
|
|
@@ -63,13 +62,9 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
|
|
|
63
62
|
);
|
|
64
63
|
}
|
|
65
64
|
if (allowedTypes.length === 1) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} else if (allowedTypes[0] === "video" && mapping.poster && attributeValues[mapping.poster]) {
|
|
70
|
-
src = attributeValues[mapping.poster];
|
|
71
|
-
}
|
|
72
|
-
if (src) {
|
|
65
|
+
const value = field.getValue({ item: data });
|
|
66
|
+
const url = value?.url;
|
|
67
|
+
if (url) {
|
|
73
68
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
74
69
|
"img",
|
|
75
70
|
{
|
|
@@ -77,7 +72,7 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
|
|
|
77
72
|
alt: "",
|
|
78
73
|
width: 24,
|
|
79
74
|
height: 24,
|
|
80
|
-
src
|
|
75
|
+
src: url
|
|
81
76
|
}
|
|
82
77
|
);
|
|
83
78
|
}
|
|
@@ -97,28 +92,23 @@ function MediaThumbnail({ control, attributeValues, attachment }) {
|
|
|
97
92
|
}
|
|
98
93
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Icon, { icon: import_icons.media, size: 24 });
|
|
99
94
|
}
|
|
100
|
-
function Media({
|
|
101
|
-
clientId,
|
|
102
|
-
control,
|
|
103
|
-
blockType,
|
|
104
|
-
attributeValues,
|
|
105
|
-
updateAttributes
|
|
106
|
-
}) {
|
|
95
|
+
function Media({ data, field, config = {} }) {
|
|
107
96
|
const { popoverProps } = (0, import_use_inspector_popover_placement.useInspectorPopoverPlacement)({
|
|
108
97
|
isControl: true
|
|
109
98
|
});
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
99
|
+
const value = field.getValue({ item: data });
|
|
100
|
+
const { allowedTypes = [], multiple = false } = field.config || {};
|
|
101
|
+
const { clientId, updateBlockAttributes, fieldDef } = config;
|
|
102
|
+
const updateAttributes = (newFieldValue) => {
|
|
103
|
+
const mappedChanges = field.setValue({
|
|
104
|
+
item: data,
|
|
105
|
+
value: newFieldValue
|
|
106
|
+
});
|
|
107
|
+
updateBlockAttributes(clientId, mappedChanges);
|
|
108
|
+
};
|
|
109
|
+
const hasFeaturedImageSupport = fieldDef?.mapping && "featuredImage" in fieldDef.mapping;
|
|
110
|
+
const id = value?.id;
|
|
111
|
+
const url = value?.url;
|
|
122
112
|
const attachment = (0, import_data.useSelect)(
|
|
123
113
|
(select) => {
|
|
124
114
|
if (!id) {
|
|
@@ -134,8 +124,8 @@ function Media({
|
|
|
134
124
|
[id]
|
|
135
125
|
);
|
|
136
126
|
let chooseItemLabel;
|
|
137
|
-
if (
|
|
138
|
-
const allowedType =
|
|
127
|
+
if (allowedTypes.length === 1) {
|
|
128
|
+
const allowedType = allowedTypes[0];
|
|
139
129
|
if (allowedType === "image") {
|
|
140
130
|
chooseItemLabel = (0, import_i18n.__)("Choose an image\u2026");
|
|
141
131
|
} else if (allowedType === "video") {
|
|
@@ -148,112 +138,122 @@ function Media({
|
|
|
148
138
|
} else {
|
|
149
139
|
chooseItemLabel = (0, import_i18n.__)("Choose a media item\u2026");
|
|
150
140
|
}
|
|
151
|
-
const defaultValues = (0, import_element.useMemo)(() => {
|
|
152
|
-
return Object.fromEntries(
|
|
153
|
-
Object.entries(control.mapping).map(([, attributeKey]) => {
|
|
154
|
-
return [
|
|
155
|
-
attributeKey,
|
|
156
|
-
blockType.attributes[attributeKey]?.defaultValue ?? void 0
|
|
157
|
-
];
|
|
158
|
-
})
|
|
159
|
-
);
|
|
160
|
-
}, [blockType.attributes, control.mapping]);
|
|
161
141
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_check.default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
162
|
-
|
|
142
|
+
import_media_replace_flow.default,
|
|
163
143
|
{
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
144
|
+
className: "block-editor-content-only-controls__media-replace-flow",
|
|
145
|
+
allowedTypes,
|
|
146
|
+
mediaId: id,
|
|
147
|
+
mediaURL: url,
|
|
148
|
+
multiple,
|
|
149
|
+
popoverProps,
|
|
150
|
+
onReset: () => {
|
|
151
|
+
const resetValue = {};
|
|
152
|
+
if (fieldDef?.mapping) {
|
|
153
|
+
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
154
|
+
if (key === "id" || key === "src" || key === "url") {
|
|
155
|
+
resetValue[key] = void 0;
|
|
156
|
+
} else if (key === "caption" || key === "alt") {
|
|
157
|
+
resetValue[key] = "";
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (hasFeaturedImageSupport) {
|
|
162
|
+
resetValue.featuredImage = false;
|
|
163
|
+
}
|
|
164
|
+
updateAttributes({ ...value, ...resetValue });
|
|
169
165
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
[featuredImageKey]: !useFeaturedImage
|
|
188
|
-
});
|
|
189
|
-
}),
|
|
190
|
-
onSelect: (selectedMedia) => {
|
|
191
|
-
if (selectedMedia.id && selectedMedia.url) {
|
|
192
|
-
const optionalAttributes = {};
|
|
193
|
-
if (typeKey && selectedMedia.type) {
|
|
194
|
-
optionalAttributes[typeKey] = selectedMedia.type;
|
|
195
|
-
}
|
|
196
|
-
if (captionKey && !caption && selectedMedia.caption) {
|
|
197
|
-
optionalAttributes[captionKey] = selectedMedia.caption;
|
|
198
|
-
}
|
|
199
|
-
if (altKey && !alt && selectedMedia.alt) {
|
|
200
|
-
optionalAttributes[altKey] = selectedMedia.alt;
|
|
201
|
-
}
|
|
202
|
-
if (posterKey && selectedMedia.poster) {
|
|
203
|
-
optionalAttributes[posterKey] = selectedMedia.poster;
|
|
204
|
-
}
|
|
205
|
-
updateAttributes({
|
|
206
|
-
[idKey]: selectedMedia.id,
|
|
207
|
-
[srcKey]: selectedMedia.url,
|
|
208
|
-
...optionalAttributes
|
|
209
|
-
});
|
|
166
|
+
...hasFeaturedImageSupport && {
|
|
167
|
+
useFeaturedImage: !!value?.featuredImage,
|
|
168
|
+
onToggleFeaturedImage: () => {
|
|
169
|
+
updateAttributes({
|
|
170
|
+
...value,
|
|
171
|
+
featuredImage: !value?.featuredImage
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
onSelect: (selectedMedia) => {
|
|
176
|
+
if (selectedMedia.id && selectedMedia.url) {
|
|
177
|
+
let mediaType = "image";
|
|
178
|
+
if (selectedMedia.mime_type) {
|
|
179
|
+
if (selectedMedia.mime_type.startsWith("video/")) {
|
|
180
|
+
mediaType = "video";
|
|
181
|
+
} else if (selectedMedia.mime_type.startsWith("audio/")) {
|
|
182
|
+
mediaType = "audio";
|
|
210
183
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
attachment,
|
|
231
|
-
control,
|
|
232
|
-
attributeValues
|
|
233
|
-
}
|
|
234
|
-
),
|
|
235
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
236
|
-
className: "block-editor-content-only-controls__media-title",
|
|
237
|
-
// TODO - truncate long titles or url smartly (e.g. show filename).
|
|
238
|
-
children: attachment?.title?.raw && attachment?.title?.raw !== "" ? attachment?.title?.raw : src
|
|
239
|
-
})
|
|
240
|
-
] }),
|
|
241
|
-
!src && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
242
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
243
|
-
"span",
|
|
244
|
-
{
|
|
245
|
-
className: "block-editor-content-only-controls__media-placeholder",
|
|
246
|
-
style: {
|
|
247
|
-
width: "24px",
|
|
248
|
-
height: "24px"
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
),
|
|
252
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-content-only-controls__media-title", children: chooseItemLabel })
|
|
253
|
-
] })
|
|
254
|
-
]
|
|
184
|
+
}
|
|
185
|
+
const newValue = {};
|
|
186
|
+
if (fieldDef?.mapping) {
|
|
187
|
+
Object.keys(fieldDef.mapping).forEach(
|
|
188
|
+
(key) => {
|
|
189
|
+
if (key === "id") {
|
|
190
|
+
newValue[key] = selectedMedia.id;
|
|
191
|
+
} else if (key === "src" || key === "url") {
|
|
192
|
+
newValue[key] = selectedMedia.url;
|
|
193
|
+
} else if (key === "type") {
|
|
194
|
+
newValue[key] = mediaType;
|
|
195
|
+
} else if (key === "link" && selectedMedia.link) {
|
|
196
|
+
newValue[key] = selectedMedia.link;
|
|
197
|
+
} else if (key === "caption" && !value?.caption && selectedMedia.caption) {
|
|
198
|
+
newValue[key] = selectedMedia.caption;
|
|
199
|
+
} else if (key === "alt" && !value?.alt && selectedMedia.alt) {
|
|
200
|
+
newValue[key] = selectedMedia.alt;
|
|
201
|
+
} else if (key === "poster" && selectedMedia.poster) {
|
|
202
|
+
newValue[key] = selectedMedia.poster;
|
|
255
203
|
}
|
|
256
|
-
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (hasFeaturedImageSupport) {
|
|
208
|
+
newValue.featuredImage = false;
|
|
209
|
+
}
|
|
210
|
+
const finalValue = { ...value, ...newValue };
|
|
211
|
+
updateAttributes(finalValue);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
renderToggle: (buttonProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
215
|
+
import_components.Button,
|
|
216
|
+
{
|
|
217
|
+
__next40pxDefaultSize: true,
|
|
218
|
+
className: "block-editor-content-only-controls__media",
|
|
219
|
+
...buttonProps,
|
|
220
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
221
|
+
import_components.__experimentalGrid,
|
|
222
|
+
{
|
|
223
|
+
rowGap: 0,
|
|
224
|
+
columnGap: 8,
|
|
225
|
+
templateColumns: "24px 1fr",
|
|
226
|
+
className: "block-editor-content-only-controls__media-row",
|
|
227
|
+
children: [
|
|
228
|
+
url && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
230
|
+
MediaThumbnail,
|
|
231
|
+
{
|
|
232
|
+
attachment,
|
|
233
|
+
field,
|
|
234
|
+
data
|
|
235
|
+
}
|
|
236
|
+
),
|
|
237
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
238
|
+
className: "block-editor-content-only-controls__media-title",
|
|
239
|
+
// TODO - truncate long titles or url smartly (e.g. show filename).
|
|
240
|
+
children: attachment?.title?.raw && attachment?.title?.raw !== "" ? attachment?.title?.raw : url
|
|
241
|
+
})
|
|
242
|
+
] }),
|
|
243
|
+
!url && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
244
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
245
|
+
"span",
|
|
246
|
+
{
|
|
247
|
+
className: "block-editor-content-only-controls__media-placeholder",
|
|
248
|
+
style: {
|
|
249
|
+
width: "24px",
|
|
250
|
+
height: "24px"
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
),
|
|
254
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block-editor-content-only-controls__media-title", children: chooseItemLabel })
|
|
255
|
+
] })
|
|
256
|
+
]
|
|
257
257
|
}
|
|
258
258
|
)
|
|
259
259
|
}
|