@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
|
@@ -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
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
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
|
|
73
|
-
[
|
|
62
|
+
() => ({ url, opensInNewTab, nofollow }),
|
|
63
|
+
[url, opensInNewTab, nofollow]
|
|
74
64
|
);
|
|
75
|
-
return /* @__PURE__ */ jsxs(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
131
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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\
|
|
5
|
-
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA,
|
|
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
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({
|
|
24
|
-
const
|
|
25
|
-
const
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
const
|
|
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 (
|
|
114
|
-
const allowedType =
|
|
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
|
-
|
|
117
|
+
MediaReplaceFlow,
|
|
139
118
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
{
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
}
|