@wordpress/block-editor 15.10.1-next.79a2f3cdd.0 → 15.10.1-next.v.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/build/components/block-bindings/attribute-control.cjs +1 -1
- package/build/components/block-bindings/attribute-control.cjs.map +1 -1
- package/build/components/block-bindings/source-fields-list.cjs +1 -1
- package/build/components/block-bindings/source-fields-list.cjs.map +1 -1
- package/build/components/block-edit/context.cjs +5 -5
- package/build/components/block-edit/context.cjs.map +1 -1
- package/build/components/block-list/block.cjs +24 -12
- package/build/components/block-list/block.cjs.map +3 -3
- package/build/components/block-list/use-block-props/index.cjs +8 -2
- package/build/components/block-list/use-block-props/index.cjs.map +2 -2
- package/build/components/block-tools/index.cjs +82 -70
- package/build/components/block-tools/index.cjs.map +2 -2
- package/build/components/block-visibility/block-visibility-info.cjs +0 -59
- package/build/components/block-visibility/block-visibility-info.cjs.map +3 -3
- package/build/components/block-visibility/constants.cjs +54 -0
- package/build/components/block-visibility/constants.cjs.map +7 -0
- package/build/components/block-visibility/index.cjs +15 -4
- package/build/components/block-visibility/index.cjs.map +3 -3
- package/build/components/block-visibility/modal.cjs +397 -0
- package/build/components/block-visibility/modal.cjs.map +7 -0
- package/build/components/block-visibility/toolbar.cjs +1 -1
- package/build/components/block-visibility/toolbar.cjs.map +2 -2
- package/build/components/block-visibility/use-block-visibility.cjs +65 -0
- package/build/components/block-visibility/use-block-visibility.cjs.map +7 -0
- package/build/components/block-visibility/utils.cjs +81 -0
- package/build/components/block-visibility/utils.cjs.map +7 -0
- package/build/components/block-visibility/viewport-menu-item.cjs +61 -0
- package/build/components/block-visibility/viewport-menu-item.cjs.map +7 -0
- package/build/components/block-visibility/viewport-toolbar.cjs +89 -0
- package/build/components/block-visibility/viewport-toolbar.cjs.map +7 -0
- package/build/components/collab/block-comment-icon-slot.cjs +1 -1
- package/build/components/collab/block-comment-icon-slot.cjs.map +1 -1
- package/build/components/collab/block-comment-icon-toolbar-slot.cjs +1 -1
- package/build/components/collab/block-comment-icon-toolbar-slot.cjs.map +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs +1 -1
- package/build/components/inner-blocks/use-inner-block-template-sync.cjs.map +1 -1
- package/build/components/inserter/menu.cjs +6 -2
- package/build/components/inserter/menu.cjs.map +2 -2
- package/build/components/inspector-controls/groups.cjs +1 -1
- package/build/components/inspector-controls/groups.cjs.map +1 -1
- package/build/components/inspector-controls-tabs/content-tab.cjs +1 -1
- package/build/components/inspector-controls-tabs/content-tab.cjs.map +2 -2
- package/build/components/list-view/block-select-button.cjs +2 -2
- package/build/components/list-view/block-select-button.cjs.map +2 -2
- package/build/components/list-view/block.cjs +39 -22
- package/build/components/list-view/block.cjs.map +2 -2
- package/build/components/list-view/index.cjs +11 -6
- package/build/components/list-view/index.cjs.map +2 -2
- package/build/components/list-view/utils.cjs +24 -17
- package/build/components/list-view/utils.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/input-rules.cjs +13 -1
- package/build/components/rich-text/event-listeners/input-rules.cjs.map +2 -2
- package/build/components/rich-text/format-edit.cjs +1 -1
- package/build/components/rich-text/format-edit.cjs.map +1 -1
- package/build/components/rich-text/index.cjs +2 -2
- package/build/components/rich-text/index.cjs.map +2 -2
- package/build/components/url-input/index.cjs +2 -0
- package/build/components/url-input/index.cjs.map +2 -2
- package/build/components/use-block-commands/index.cjs +1 -1
- package/build/components/use-block-commands/index.cjs.map +2 -2
- package/build/components/writing-flow/utils.cjs +1 -1
- package/build/components/writing-flow/utils.cjs.map +1 -1
- package/build/hooks/block-fields/index.cjs +76 -167
- package/build/hooks/block-fields/index.cjs.map +2 -2
- package/build/hooks/block-fields/link/index.cjs +13 -23
- package/build/hooks/block-fields/link/index.cjs.map +2 -2
- package/build/hooks/block-fields/media/index.cjs +32 -58
- package/build/hooks/block-fields/media/index.cjs.map +2 -2
- package/build/hooks/block-fields/rich-text/index.cjs +1 -5
- package/build/hooks/block-fields/rich-text/index.cjs.map +2 -2
- package/build/hooks/cross-origin-isolation.cjs +102 -0
- package/build/hooks/cross-origin-isolation.cjs.map +7 -0
- package/build/hooks/fit-text.cjs +1 -1
- package/build/hooks/fit-text.cjs.map +1 -1
- package/build/hooks/index.cjs +1 -0
- package/build/hooks/index.cjs.map +2 -2
- package/build/layouts/flex.cjs +6 -2
- package/build/layouts/flex.cjs.map +2 -2
- package/build/store/private-keys.cjs +10 -10
- package/build/store/private-keys.cjs.map +1 -1
- package/build/store/private-selectors.cjs +33 -1
- package/build/store/private-selectors.cjs.map +3 -3
- package/build/store/reducer.cjs +1 -1
- package/build/store/reducer.cjs.map +1 -1
- package/build/store/selectors.cjs +7 -8
- package/build/store/selectors.cjs.map +2 -2
- package/build/store/utils.cjs +1 -1
- package/build/store/utils.cjs.map +1 -1
- package/build-module/components/block-bindings/attribute-control.mjs +1 -1
- package/build-module/components/block-bindings/attribute-control.mjs.map +1 -1
- package/build-module/components/block-bindings/source-fields-list.mjs +1 -1
- package/build-module/components/block-bindings/source-fields-list.mjs.map +1 -1
- package/build-module/components/block-edit/context.mjs +5 -5
- package/build-module/components/block-edit/context.mjs.map +1 -1
- package/build-module/components/block-list/block.mjs +24 -12
- package/build-module/components/block-list/block.mjs.map +3 -3
- package/build-module/components/block-list/use-block-props/index.mjs +8 -2
- package/build-module/components/block-list/use-block-props/index.mjs.map +2 -2
- package/build-module/components/block-tools/index.mjs +85 -73
- package/build-module/components/block-tools/index.mjs.map +2 -2
- package/build-module/components/block-visibility/block-visibility-info.mjs +0 -59
- package/build-module/components/block-visibility/block-visibility-info.mjs.map +3 -3
- package/build-module/components/block-visibility/constants.mjs +28 -0
- package/build-module/components/block-visibility/constants.mjs.map +7 -0
- package/build-module/components/block-visibility/index.mjs +13 -4
- package/build-module/components/block-visibility/index.mjs.map +2 -2
- package/build-module/components/block-visibility/modal.mjs +384 -0
- package/build-module/components/block-visibility/modal.mjs.map +7 -0
- package/build-module/components/block-visibility/toolbar.mjs +1 -1
- package/build-module/components/block-visibility/toolbar.mjs.map +2 -2
- package/build-module/components/block-visibility/use-block-visibility.mjs +44 -0
- package/build-module/components/block-visibility/use-block-visibility.mjs.map +7 -0
- package/build-module/components/block-visibility/utils.mjs +55 -0
- package/build-module/components/block-visibility/utils.mjs.map +7 -0
- package/build-module/components/block-visibility/viewport-menu-item.mjs +40 -0
- package/build-module/components/block-visibility/viewport-menu-item.mjs.map +7 -0
- package/build-module/components/block-visibility/viewport-toolbar.mjs +68 -0
- package/build-module/components/block-visibility/viewport-toolbar.mjs.map +7 -0
- package/build-module/components/collab/block-comment-icon-slot.mjs +1 -1
- package/build-module/components/collab/block-comment-icon-slot.mjs.map +1 -1
- package/build-module/components/collab/block-comment-icon-toolbar-slot.mjs +1 -1
- package/build-module/components/collab/block-comment-icon-toolbar-slot.mjs.map +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs +1 -1
- package/build-module/components/inner-blocks/use-inner-block-template-sync.mjs.map +1 -1
- package/build-module/components/inserter/menu.mjs +6 -2
- package/build-module/components/inserter/menu.mjs.map +2 -2
- package/build-module/components/inspector-controls/groups.mjs +1 -1
- package/build-module/components/inspector-controls/groups.mjs.map +1 -1
- package/build-module/components/inspector-controls-tabs/content-tab.mjs +1 -1
- package/build-module/components/inspector-controls-tabs/content-tab.mjs.map +2 -2
- package/build-module/components/list-view/block-select-button.mjs +2 -2
- package/build-module/components/list-view/block-select-button.mjs.map +2 -2
- package/build-module/components/list-view/block.mjs +39 -22
- package/build-module/components/list-view/block.mjs.map +2 -2
- package/build-module/components/list-view/index.mjs +11 -7
- package/build-module/components/list-view/index.mjs.map +2 -2
- package/build-module/components/list-view/utils.mjs +24 -17
- package/build-module/components/list-view/utils.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/input-rules.mjs +13 -1
- package/build-module/components/rich-text/event-listeners/input-rules.mjs.map +2 -2
- package/build-module/components/rich-text/format-edit.mjs +1 -1
- package/build-module/components/rich-text/format-edit.mjs.map +1 -1
- package/build-module/components/rich-text/index.mjs +2 -2
- package/build-module/components/rich-text/index.mjs.map +2 -2
- package/build-module/components/url-input/index.mjs +2 -0
- package/build-module/components/url-input/index.mjs.map +2 -2
- package/build-module/components/use-block-commands/index.mjs +1 -1
- package/build-module/components/use-block-commands/index.mjs.map +2 -2
- package/build-module/components/writing-flow/utils.mjs +1 -1
- package/build-module/components/writing-flow/utils.mjs.map +1 -1
- package/build-module/hooks/block-fields/index.mjs +76 -167
- package/build-module/hooks/block-fields/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/link/index.mjs +13 -23
- package/build-module/hooks/block-fields/link/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/media/index.mjs +32 -58
- package/build-module/hooks/block-fields/media/index.mjs.map +2 -2
- package/build-module/hooks/block-fields/rich-text/index.mjs +1 -5
- package/build-module/hooks/block-fields/rich-text/index.mjs.map +2 -2
- package/build-module/hooks/cross-origin-isolation.mjs +100 -0
- package/build-module/hooks/cross-origin-isolation.mjs.map +7 -0
- package/build-module/hooks/fit-text.mjs +1 -1
- package/build-module/hooks/fit-text.mjs.map +1 -1
- package/build-module/hooks/index.mjs +1 -0
- package/build-module/hooks/index.mjs.map +2 -2
- package/build-module/layouts/flex.mjs +6 -2
- package/build-module/layouts/flex.mjs.map +2 -2
- package/build-module/store/private-keys.mjs +10 -10
- package/build-module/store/private-keys.mjs.map +1 -1
- package/build-module/store/private-selectors.mjs +34 -1
- package/build-module/store/private-selectors.mjs.map +2 -2
- package/build-module/store/reducer.mjs +1 -1
- package/build-module/store/reducer.mjs.map +1 -1
- package/build-module/store/selectors.mjs +7 -8
- package/build-module/store/selectors.mjs.map +2 -2
- package/build-module/store/utils.mjs +1 -1
- package/build-module/store/utils.mjs.map +1 -1
- package/build-style/content-rtl.css +4 -1
- package/build-style/content.css +4 -1
- package/build-style/style-rtl.css +54 -1
- package/build-style/style.css +54 -1
- package/package.json +39 -39
- package/src/components/block-bindings/attribute-control.js +1 -1
- package/src/components/block-bindings/source-fields-list.js +1 -1
- package/src/components/block-list/block.js +23 -9
- package/src/components/block-list/content.scss +4 -1
- package/src/components/block-list/use-block-props/index.js +10 -2
- package/src/components/block-toolbar/style.scss +0 -1
- package/src/components/block-tools/index.js +45 -33
- package/src/components/block-tools/style.scss +10 -0
- package/src/components/block-visibility/block-visibility-info.js +0 -1
- package/src/components/block-visibility/constants.js +33 -0
- package/src/components/block-visibility/index.js +21 -2
- package/src/components/block-visibility/modal.js +358 -0
- package/src/components/block-visibility/style.scss +58 -0
- package/src/components/block-visibility/test/use-block-visibility.js +316 -0
- package/src/components/block-visibility/test/utils.js +266 -0
- package/src/components/block-visibility/toolbar.js +1 -1
- package/src/components/block-visibility/use-block-visibility.js +70 -0
- package/src/components/block-visibility/utils.js +95 -0
- package/src/components/block-visibility/viewport-menu-item.js +42 -0
- package/src/components/block-visibility/viewport-toolbar.js +88 -0
- package/src/components/inner-blocks/use-inner-block-template-sync.js +1 -1
- package/src/components/inserter/menu.js +6 -2
- package/src/components/inspector-controls-tabs/content-tab.js +0 -1
- package/src/components/list-view/block-select-button.js +2 -2
- package/src/components/list-view/block.js +47 -25
- package/src/components/list-view/index.js +15 -11
- package/src/components/list-view/utils.js +31 -23
- package/src/components/rich-text/event-listeners/input-rules.js +17 -0
- package/src/components/rich-text/index.js +1 -1
- package/src/components/url-input/index.js +2 -0
- package/src/components/use-block-commands/index.js +4 -3
- package/src/hooks/block-fields/index.js +104 -225
- package/src/hooks/block-fields/link/index.js +13 -39
- package/src/hooks/block-fields/media/index.js +31 -90
- package/src/hooks/block-fields/rich-text/index.js +1 -5
- package/src/hooks/block-fields/styles.scss +2 -0
- package/src/hooks/cross-origin-isolation.js +143 -0
- package/src/hooks/fit-text.js +1 -1
- package/src/hooks/index.js +1 -0
- package/src/layouts/flex.js +8 -3
- package/src/layouts/test/flex.js +53 -0
- package/src/store/private-selectors.js +64 -1
- package/src/store/reducer.js +1 -1
- package/src/store/selectors.js +7 -9
- package/src/store/test/private-selectors.js +80 -0
- package/src/style.scss +1 -0
- package/src/components/block-visibility/styles.scss +0 -10
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
9
9
|
import { DataForm } from "@wordpress/dataviews";
|
|
10
10
|
import { useContext, useState, useMemo } from "@wordpress/element";
|
|
11
|
+
import { __ } from "@wordpress/i18n";
|
|
11
12
|
import { unlock } from "../../lock-unlock.mjs";
|
|
12
13
|
import BlockIcon from "../../components/block-icon/index.mjs";
|
|
13
14
|
import useBlockDisplayTitle from "../../components/block-title/use-block-display-title.mjs";
|
|
@@ -25,171 +26,85 @@ var CONTROLS = {
|
|
|
25
26
|
media: Media,
|
|
26
27
|
link: Link
|
|
27
28
|
};
|
|
28
|
-
function createConfiguredControl(config) {
|
|
29
|
-
const { control, ...controlConfig } = config;
|
|
30
|
-
const ControlComponent = CONTROLS[control];
|
|
29
|
+
function createConfiguredControl(ControlComponent, type, config) {
|
|
31
30
|
if (!ControlComponent) {
|
|
32
|
-
throw new Error(`Control type "${
|
|
31
|
+
throw new Error(`Control type "${type}" not found`);
|
|
33
32
|
}
|
|
34
33
|
return function ConfiguredControl(props) {
|
|
35
|
-
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config
|
|
34
|
+
return /* @__PURE__ */ jsx(ControlComponent, { ...props, config });
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
poster: "",
|
|
46
|
-
featuredImage: false,
|
|
47
|
-
link: ""
|
|
48
|
-
};
|
|
49
|
-
const result = {};
|
|
50
|
-
if (fieldDef?.mapping) {
|
|
51
|
-
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
52
|
-
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
53
|
-
});
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
Object.keys(defaults).forEach((key) => {
|
|
57
|
-
result[key] = value?.[key] ?? defaults[key];
|
|
58
|
-
});
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
function denormalizeMediaValue(value, fieldDef) {
|
|
62
|
-
if (!fieldDef.mapping) {
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
const result = {};
|
|
66
|
-
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
67
|
-
if (key in value) {
|
|
68
|
-
result[key] = value[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
function normalizeLinkValue(value, fieldDef) {
|
|
74
|
-
const defaults = {
|
|
75
|
-
url: "",
|
|
76
|
-
rel: "",
|
|
77
|
-
linkTarget: "",
|
|
78
|
-
destination: ""
|
|
79
|
-
};
|
|
80
|
-
const result = {};
|
|
81
|
-
if (fieldDef?.mapping) {
|
|
82
|
-
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
83
|
-
result[key] = value?.[key] ?? defaults[key] ?? "";
|
|
84
|
-
});
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
Object.keys(defaults).forEach((key) => {
|
|
88
|
-
result[key] = value?.[key] ?? defaults[key];
|
|
89
|
-
});
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
function denormalizeLinkValue(value, fieldDef) {
|
|
93
|
-
if (!fieldDef.mapping) {
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
const result = {};
|
|
97
|
-
Object.entries(fieldDef.mapping).forEach(([key]) => {
|
|
98
|
-
if (key in value) {
|
|
99
|
-
result[key] = value[key];
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
function BlockFields({ clientId, blockType, attributes, setAttributes }) {
|
|
37
|
+
function BlockFields({
|
|
38
|
+
clientId,
|
|
39
|
+
blockType,
|
|
40
|
+
attributes,
|
|
41
|
+
setAttributes,
|
|
42
|
+
isCollapsed = false
|
|
43
|
+
}) {
|
|
105
44
|
const blockTitle = useBlockDisplayTitle({
|
|
106
45
|
clientId,
|
|
107
46
|
context: "list-view"
|
|
108
47
|
});
|
|
109
48
|
const blockInformation = useBlockDisplayInformation(clientId);
|
|
110
49
|
const blockTypeFields = blockType?.[fieldsKey];
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
50
|
+
const computedForm = useMemo(() => {
|
|
51
|
+
if (!isCollapsed) {
|
|
52
|
+
return blockType?.[formKey];
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...blockType?.[formKey],
|
|
56
|
+
fields: [blockType?.[formKey]?.fields?.[0]]
|
|
57
|
+
};
|
|
58
|
+
}, [blockType, isCollapsed]);
|
|
59
|
+
const [form, setForm] = useState(computedForm);
|
|
114
60
|
const dataFormFields = useMemo(() => {
|
|
115
61
|
if (!blockTypeFields?.length) {
|
|
116
62
|
return [];
|
|
117
63
|
}
|
|
118
64
|
return blockTypeFields.map((fieldDef) => {
|
|
119
|
-
const ControlComponent = CONTROLS[fieldDef.type];
|
|
120
|
-
const defaultValues = {};
|
|
121
|
-
if (fieldDef.mapping && blockType?.attributes) {
|
|
122
|
-
Object.entries(fieldDef.mapping).forEach(
|
|
123
|
-
([key, attrKey]) => {
|
|
124
|
-
defaultValues[key] = blockType.attributes[attrKey]?.defaultValue ?? void 0;
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
65
|
const field = {
|
|
129
66
|
id: fieldDef.id,
|
|
130
67
|
label: fieldDef.label,
|
|
131
|
-
type: fieldDef.type
|
|
68
|
+
type: fieldDef.type
|
|
132
69
|
// Use the field's type; DataForm will use built-in or custom Edit
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
([key, attrKey]) => {
|
|
141
|
-
mappedValue[key] = item[attrKey];
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
if (fieldDef.type === "media") {
|
|
145
|
-
return normalizeMediaValue(mappedValue, fieldDef);
|
|
146
|
-
}
|
|
147
|
-
if (fieldDef.type === "link") {
|
|
148
|
-
return normalizeLinkValue(mappedValue, fieldDef);
|
|
70
|
+
};
|
|
71
|
+
if (fieldDef.mapping) {
|
|
72
|
+
field.getValue = ({ item }) => {
|
|
73
|
+
const mappedValue = {};
|
|
74
|
+
Object.entries(fieldDef.mapping).forEach(
|
|
75
|
+
([key, attrKey]) => {
|
|
76
|
+
mappedValue[key] = item[attrKey];
|
|
149
77
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
denormalizedValue = denormalizeMediaValue(
|
|
159
|
-
value,
|
|
160
|
-
fieldDef
|
|
161
|
-
);
|
|
162
|
-
} else if (fieldDef.type === "link") {
|
|
163
|
-
denormalizedValue = denormalizeLinkValue(
|
|
164
|
-
value,
|
|
165
|
-
fieldDef
|
|
166
|
-
);
|
|
78
|
+
);
|
|
79
|
+
return mappedValue;
|
|
80
|
+
};
|
|
81
|
+
field.setValue = ({ value }) => {
|
|
82
|
+
const attributeUpdates = {};
|
|
83
|
+
Object.entries(fieldDef.mapping).forEach(
|
|
84
|
+
([key, attrKey]) => {
|
|
85
|
+
attributeUpdates[attrKey] = value[key];
|
|
167
86
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
} else {
|
|
174
|
-
updates[attrKey] = item[attrKey];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
return updates;
|
|
179
|
-
}
|
|
180
|
-
return { [fieldDef.id]: value };
|
|
181
|
-
}
|
|
182
|
-
};
|
|
87
|
+
);
|
|
88
|
+
return attributeUpdates;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const ControlComponent = CONTROLS[fieldDef.type];
|
|
183
92
|
if (ControlComponent) {
|
|
184
|
-
field.Edit = createConfiguredControl(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
93
|
+
field.Edit = createConfiguredControl(
|
|
94
|
+
ControlComponent,
|
|
95
|
+
fieldDef.type,
|
|
96
|
+
{
|
|
97
|
+
clientId,
|
|
98
|
+
fieldDef
|
|
99
|
+
}
|
|
100
|
+
);
|
|
189
101
|
}
|
|
190
102
|
return field;
|
|
191
103
|
});
|
|
192
|
-
}, [blockTypeFields,
|
|
104
|
+
}, [blockTypeFields, clientId]);
|
|
105
|
+
if (!blockTypeFields?.length) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
193
108
|
const handleToggleField = (fieldId) => {
|
|
194
109
|
setForm((prev) => {
|
|
195
110
|
if (prev.fields?.includes(fieldId)) {
|
|
@@ -204,34 +119,27 @@ function BlockFields({ clientId, blockType, attributes, setAttributes }) {
|
|
|
204
119
|
};
|
|
205
120
|
});
|
|
206
121
|
};
|
|
207
|
-
if (!blockTypeFields?.length) {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
122
|
return /* @__PURE__ */ jsxs("div", { className: "block-editor-block-fields__container", children: [
|
|
211
123
|
/* @__PURE__ */ jsx("div", { className: "block-editor-block-fields__header", children: /* @__PURE__ */ jsxs(HStack, { spacing: 1, children: [
|
|
212
|
-
/* @__PURE__ */
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
Truncate,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
visibleFields: form.fields,
|
|
232
|
-
onToggleField: handleToggleField
|
|
233
|
-
}
|
|
234
|
-
)
|
|
124
|
+
isCollapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
125
|
+
/* @__PURE__ */ jsx(
|
|
126
|
+
BlockIcon,
|
|
127
|
+
{
|
|
128
|
+
className: "block-editor-block-fields__header-icon",
|
|
129
|
+
icon: blockInformation?.icon
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
/* @__PURE__ */ jsx("h2", { className: "block-editor-block-fields__header-title", children: /* @__PURE__ */ jsx(Truncate, { numberOfLines: 1, children: blockTitle }) }),
|
|
133
|
+
/* @__PURE__ */ jsx(
|
|
134
|
+
FieldsDropdownMenu,
|
|
135
|
+
{
|
|
136
|
+
fields: dataFormFields,
|
|
137
|
+
visibleFields: form.fields,
|
|
138
|
+
onToggleField: handleToggleField
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
] }),
|
|
142
|
+
!isCollapsed && /* @__PURE__ */ jsx("h2", { className: "block-editor-block-fields__header-title", children: __("Content") })
|
|
235
143
|
] }) }),
|
|
236
144
|
/* @__PURE__ */ jsx(
|
|
237
145
|
DataForm,
|
|
@@ -253,7 +161,7 @@ var withBlockFields = createHigherOrderComponent(
|
|
|
253
161
|
blockEditingMode,
|
|
254
162
|
isSelected
|
|
255
163
|
} = useContext(PrivateBlockContext);
|
|
256
|
-
const shouldShowBlockFields = window?.
|
|
164
|
+
const shouldShowBlockFields = window?.__experimentalContentOnlyInspectorFields;
|
|
257
165
|
const blockTypeFields = blockType?.[fieldsKey];
|
|
258
166
|
if (!shouldShowBlockFields || !blockTypeFields?.length) {
|
|
259
167
|
return /* @__PURE__ */ jsx(BlockEdit, { ...props }, "edit");
|
|
@@ -270,7 +178,8 @@ var withBlockFields = createHigherOrderComponent(
|
|
|
270
178
|
BlockFields,
|
|
271
179
|
{
|
|
272
180
|
...props,
|
|
273
|
-
blockType
|
|
181
|
+
blockType,
|
|
182
|
+
isCollapsed: true
|
|
274
183
|
}
|
|
275
184
|
)
|
|
276
185
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/block-fields/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport { PrivateInspectorControlsFill } from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\nconst CONTROLS = {\n\trichtext: RichText,\n\tmedia: Media,\n\tlink: Link,\n};\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Object} config - The control configuration\n * @param {string} config.control - The control type (key in CONTROLS map)\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( config ) {\n\tconst { control, ...controlConfig } = config;\n\tconst ControlComponent = CONTROLS[ control ];\n\n\tif ( ! ControlComponent ) {\n\t\tthrow new Error( `Control type \"${ control }\" not found` );\n\t}\n\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ controlConfig } />;\n\t};\n}\n\n/**\n * Normalize a media value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized media value with canonical properties\n */\nfunction normalizeMediaValue( value, fieldDef ) {\n\tconst defaults = {\n\t\tid: null,\n\t\turl: '',\n\t\tcaption: '',\n\t\talt: '',\n\t\ttype: 'image',\n\t\tposter: '',\n\t\tfeaturedImage: false,\n\t\tlink: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a media value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized media value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeMediaValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\n/**\n * Normalize a link value to a canonical structure.\n * Only includes properties that are present in the field's mapping (if provided).\n *\n * @param {Object} value - The mapped value from the block attributes (with canonical keys)\n * @param {Object} fieldDef - Optional field definition containing the mapping\n * @return {Object} Normalized link value with canonical properties\n */\nfunction normalizeLinkValue( value, fieldDef ) {\n\tconst defaults = {\n\t\turl: '',\n\t\trel: '',\n\t\tlinkTarget: '',\n\t\tdestination: '',\n\t};\n\n\tconst result = {};\n\n\t// If there's a mapping, only include properties that are in it\n\tif ( fieldDef?.mapping ) {\n\t\tObject.keys( fieldDef.mapping ).forEach( ( key ) => {\n\t\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ] ?? '';\n\t\t} );\n\t\treturn result;\n\t}\n\n\t// Without mapping, include all default properties\n\tObject.keys( defaults ).forEach( ( key ) => {\n\t\tresult[ key ] = value?.[ key ] ?? defaults[ key ];\n\t} );\n\treturn result;\n}\n\n/**\n * Denormalize a link value from canonical structure back to mapped keys.\n * Only includes properties that are present in the field's mapping.\n *\n * @param {Object} value - The normalized link value\n * @param {Object} fieldDef - The field definition containing the mapping\n * @return {Object} Value with only mapped properties\n */\nfunction denormalizeLinkValue( value, fieldDef ) {\n\tif ( ! fieldDef.mapping ) {\n\t\treturn value;\n\t}\n\n\tconst result = {};\n\tObject.entries( fieldDef.mapping ).forEach( ( [ key ] ) => {\n\t\tif ( key in value ) {\n\t\t\tresult[ key ] = value[ key ];\n\t\t}\n\t} );\n\treturn result;\n}\n\nfunction BlockFields( { clientId, blockType, attributes, setAttributes } ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst [ form, setForm ] = useState( () => {\n\t\treturn blockType?.[ formKey ];\n\t} );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst ControlComponent = CONTROLS[ fieldDef.type ];\n\n\t\t\tconst defaultValues = {};\n\t\t\tif ( fieldDef.mapping && blockType?.attributes ) {\n\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\tdefaultValues[ key ] =\n\t\t\t\t\t\t\tblockType.attributes[ attrKey ]?.defaultValue ??\n\t\t\t\t\t\t\tundefined;\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst field = {\n\t\t\t\tid: fieldDef.id,\n\t\t\t\tlabel: fieldDef.label,\n\t\t\t\ttype: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit\n\t\t\t\tconfig: { ...fieldDef.args, defaultValues },\n\t\t\t\thideLabelFromVision: fieldDef.id === 'content',\n\t\t\t\t// getValue and setValue handle the mapping to block attributes\n\t\t\t\tgetValue: ( { item } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Extract mapped properties from the block attributes\n\t\t\t\t\t\tconst mappedValue = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\tmappedValue[ key ] = item[ attrKey ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Normalize to canonical structure based on field type\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\treturn normalizeMediaValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\treturn normalizeLinkValue( mappedValue, fieldDef );\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// For other types, return as-is\n\t\t\t\t\t\treturn mappedValue;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn item[ fieldDef.id ];\n\t\t\t\t},\n\t\t\t\tsetValue: ( { item, value } ) => {\n\t\t\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\t\t\t// Denormalize from canonical structure back to mapped keys\n\t\t\t\t\t\tlet denormalizedValue = value;\n\t\t\t\t\t\tif ( fieldDef.type === 'media' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeMediaValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( fieldDef.type === 'link' ) {\n\t\t\t\t\t\t\tdenormalizedValue = denormalizeLinkValue(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tfieldDef\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Build an object with all mapped attributes\n\t\t\t\t\t\tconst updates = {};\n\t\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\t\t// If key is explicitly in value, use it (even if undefined to allow clearing)\n\t\t\t\t\t\t\t\t// Otherwise, preserve the old value\n\t\t\t\t\t\t\t\tif ( key in denormalizedValue ) {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] =\n\t\t\t\t\t\t\t\t\t\tdenormalizedValue[ key ];\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tupdates[ attrKey ] = item[ attrKey ];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn updates;\n\t\t\t\t\t}\n\t\t\t\t\t// For simple id-based fields, use the id as the attribute key\n\t\t\t\t\treturn { [ fieldDef.id ]: value };\n\t\t\t\t},\n\t\t\t};\n\n\t\t\t// Only add custom Edit component if one exists for this type\n\t\t\tif ( ControlComponent ) {\n\t\t\t\t// Use EditConfig pattern: Edit is an object with control type and config props\n\t\t\t\tfield.Edit = createConfiguredControl( {\n\t\t\t\t\tcontrol: fieldDef.type,\n\t\t\t\t\tclientId,\n\t\t\t\t\tfieldDef,\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, blockType?.attributes, clientId ] );\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t/>\n\t\t\t\t\t<Truncate\n\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-title\"\n\t\t\t\t\t\tnumberOfLines={ 1 }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t</Truncate>\n\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\tonToggleField={ handleToggleField }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nconst withBlockFields = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst {\n\t\t\tblockType,\n\t\t\tisSelectionWithinCurrentSection,\n\t\t\tisSectionBlock,\n\t\t\tblockEditingMode,\n\t\t\tisSelected,\n\t\t} = useContext( PrivateBlockContext );\n\n\t\tconst shouldShowBlockFields =\n\t\t\twindow?.__experimentalContentOnlyPatternInsertion &&\n\t\t\twindow?.__experimentalContentOnlyInspectorFields;\n\t\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\t\tif ( ! shouldShowBlockFields || ! blockTypeFields?.length ) {\n\t\t\treturn <BlockEdit key=\"edit\" { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{\n\t\t\t\t\t// Display the controls of all inner blocks for section/pattern editing.\n\t\t\t\t\tisSelectionWithinCurrentSection &&\n\t\t\t\t\t\t( isSectionBlock ||\n\t\t\t\t\t\t\tblockEditingMode === 'contentOnly' ) && (\n\t\t\t\t\t\t\t<PrivateInspectorControlsFill\n\t\t\t\t\t\t\t\tgroup=\"content\"\n\t\t\t\t\t\t\t\tforceDisplayControls\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BlockFields\n\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\tblockType={ blockType }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\t{ ! isSelectionWithinCurrentSection && isSelected && (\n\t\t\t\t\t<PrivateInspectorControlsFill group=\"content\">\n\t\t\t\t\t\t<BlockFields { ...props } blockType={ blockType } />\n\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/content-only-controls/block-fields',\n\twithBlockFields\n);\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,iBAAiB;AAC1B,SAAS,eAAe,yBAAyB;AACjD;AAAA,EACC,wBAAwB;AAAA,EACxB,0BAA0B;AAAA,OACpB;AACP,SAAS,kCAAkC;AAC3C,SAAS,gBAAgB;AACzB,SAAS,YAAY,UAAU,eAAe;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addFilter } from '@wordpress/hooks';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\nimport {\n\t__experimentalHStack as HStack,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { DataForm } from '@wordpress/dataviews';\nimport { useContext, useState, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport BlockIcon from '../../components/block-icon';\nimport useBlockDisplayTitle from '../../components/block-title/use-block-display-title';\nimport useBlockDisplayInformation from '../../components/use-block-display-information';\nconst { fieldsKey, formKey } = unlock( blocksPrivateApis );\nimport FieldsDropdownMenu from './fields-dropdown-menu';\nimport { PrivateBlockContext } from '../../components/block-list/private-block-context';\nimport { PrivateInspectorControlsFill } from '../../components/inspector-controls/fill';\n\n// controls\nimport RichText from './rich-text';\nimport Media from './media';\nimport Link from './link';\n\nconst CONTROLS = {\n\trichtext: RichText,\n\tmedia: Media,\n\tlink: Link,\n};\n\n/**\n * Creates a configured control component that wraps a custom control\n * and passes configuration as props.\n *\n * @param {Component} ControlComponent The React component for the control.\n * @param {string} type The type of control.\n * @param {Object} config The control configuration passed as a prop.\n *\n * @return {Function} A wrapped control component\n */\nfunction createConfiguredControl( ControlComponent, type, config ) {\n\tif ( ! ControlComponent ) {\n\t\tthrow new Error( `Control type \"${ type }\" not found` );\n\t}\n\n\treturn function ConfiguredControl( props ) {\n\t\treturn <ControlComponent { ...props } config={ config } />;\n\t};\n}\n\n/**\n * Component that renders a DataForm for a single block's attributes\n * @param {Object} props\n * @param {string} props.clientId The clientId of the block.\n * @param {Object} props.blockType The blockType definition.\n * @param {Object} props.attributes The block's attribute values.\n * @param {Function} props.setAttributes Action to set the block's attributes.\n * @param {boolean} props.isCollapsed Whether the DataForm is rendered as 'collapsed' with only the first field\n * displayed by default. When collapsed a dropdown is displayed to allow\n * displaying additional fields. The block's title is displayed as the title.\n * The collapsed mode is often used when multiple BlockForms are shown together.\n */\nfunction BlockFields( {\n\tclientId,\n\tblockType,\n\tattributes,\n\tsetAttributes,\n\tisCollapsed = false,\n} ) {\n\tconst blockTitle = useBlockDisplayTitle( {\n\t\tclientId,\n\t\tcontext: 'list-view',\n\t} );\n\tconst blockInformation = useBlockDisplayInformation( clientId );\n\n\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\tconst computedForm = useMemo( () => {\n\t\tif ( ! isCollapsed ) {\n\t\t\treturn blockType?.[ formKey ];\n\t\t}\n\n\t\t// For a collapsed form only show the first field by default.\n\t\treturn {\n\t\t\t...blockType?.[ formKey ],\n\t\t\tfields: [ blockType?.[ formKey ]?.fields?.[ 0 ] ],\n\t\t};\n\t}, [ blockType, isCollapsed ] );\n\n\tconst [ form, setForm ] = useState( computedForm );\n\n\t// Build DataForm fields with proper structure\n\tconst dataFormFields = useMemo( () => {\n\t\tif ( ! blockTypeFields?.length ) {\n\t\t\treturn [];\n\t\t}\n\n\t\treturn blockTypeFields.map( ( fieldDef ) => {\n\t\t\tconst field = {\n\t\t\t\tid: fieldDef.id,\n\t\t\t\tlabel: fieldDef.label,\n\t\t\t\ttype: fieldDef.type, // Use the field's type; DataForm will use built-in or custom Edit\n\t\t\t};\n\n\t\t\t// If the field defines a `mapping`, then custom `getValue` and `setValue`\n\t\t\t// implementations are provided.\n\t\t\t// These functions map from the inconsistent attribute keys found on blocks\n\t\t\t// to consistent keys that the field can use internally (and back again).\n\t\t\t// When `mapping` isn't provided, we can use the field API's default\n\t\t\t// implementation of these functions.\n\t\t\tif ( fieldDef.mapping ) {\n\t\t\t\tfield.getValue = ( { item } ) => {\n\t\t\t\t\t// Extract mapped properties from the block attributes\n\t\t\t\t\tconst mappedValue = {};\n\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\tmappedValue[ key ] = item[ attrKey ];\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\treturn mappedValue;\n\t\t\t\t};\n\t\t\t\tfield.setValue = ( { value } ) => {\n\t\t\t\t\tconst attributeUpdates = {};\n\t\t\t\t\tObject.entries( fieldDef.mapping ).forEach(\n\t\t\t\t\t\t( [ key, attrKey ] ) => {\n\t\t\t\t\t\t\tattributeUpdates[ attrKey ] = value[ key ];\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\treturn attributeUpdates;\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Only add custom Edit component if one exists for this type\n\t\t\tconst ControlComponent = CONTROLS[ fieldDef.type ];\n\t\t\tif ( ControlComponent ) {\n\t\t\t\t// Use EditConfig pattern: Edit is an object with control type and config props\n\t\t\t\tfield.Edit = createConfiguredControl(\n\t\t\t\t\tControlComponent,\n\t\t\t\t\tfieldDef.type,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\tfieldDef,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn field;\n\t\t} );\n\t}, [ blockTypeFields, clientId ] );\n\n\tif ( ! blockTypeFields?.length ) {\n\t\t// TODO - we might still want to show a placeholder for blocks with no fields.\n\t\t// for example, a way to select the block.\n\t\treturn null;\n\t}\n\n\tconst handleToggleField = ( fieldId ) => {\n\t\tsetForm( ( prev ) => {\n\t\t\tif ( prev.fields?.includes( fieldId ) ) {\n\t\t\t\treturn {\n\t\t\t\t\t...prev,\n\t\t\t\t\tfields: prev.fields.filter( ( id ) => id !== fieldId ),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...prev,\n\t\t\t\tfields: [ ...( prev.fields || [] ), fieldId ],\n\t\t\t};\n\t\t} );\n\t};\n\n\treturn (\n\t\t<div className=\"block-editor-block-fields__container\">\n\t\t\t<div className=\"block-editor-block-fields__header\">\n\t\t\t\t<HStack spacing={ 1 }>\n\t\t\t\t\t{ isCollapsed && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<BlockIcon\n\t\t\t\t\t\t\t\tclassName=\"block-editor-block-fields__header-icon\"\n\t\t\t\t\t\t\t\ticon={ blockInformation?.icon }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t\t<Truncate numberOfLines={ 1 }>\n\t\t\t\t\t\t\t\t\t{ blockTitle }\n\t\t\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t\t\t</h2>\n\t\t\t\t\t\t\t<FieldsDropdownMenu\n\t\t\t\t\t\t\t\tfields={ dataFormFields }\n\t\t\t\t\t\t\t\tvisibleFields={ form.fields }\n\t\t\t\t\t\t\t\tonToggleField={ handleToggleField }\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\t{ ! isCollapsed && (\n\t\t\t\t\t\t<h2 className=\"block-editor-block-fields__header-title\">\n\t\t\t\t\t\t\t{ __( 'Content' ) }\n\t\t\t\t\t\t</h2>\n\t\t\t\t\t) }\n\t\t\t\t</HStack>\n\t\t\t</div>\n\t\t\t<DataForm\n\t\t\t\tdata={ attributes }\n\t\t\t\tfields={ dataFormFields }\n\t\t\t\tform={ form }\n\t\t\t\tonChange={ setAttributes }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nconst withBlockFields = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst {\n\t\t\tblockType,\n\t\t\tisSelectionWithinCurrentSection,\n\t\t\tisSectionBlock,\n\t\t\tblockEditingMode,\n\t\t\tisSelected,\n\t\t} = useContext( PrivateBlockContext );\n\n\t\tconst shouldShowBlockFields =\n\t\t\twindow?.__experimentalContentOnlyInspectorFields;\n\t\tconst blockTypeFields = blockType?.[ fieldsKey ];\n\n\t\tif ( ! shouldShowBlockFields || ! blockTypeFields?.length ) {\n\t\t\treturn <BlockEdit key=\"edit\" { ...props } />;\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{\n\t\t\t\t\t// Display the controls of all inner blocks for section/pattern editing.\n\t\t\t\t\tisSelectionWithinCurrentSection &&\n\t\t\t\t\t\t( isSectionBlock ||\n\t\t\t\t\t\t\tblockEditingMode === 'contentOnly' ) && (\n\t\t\t\t\t\t\t<PrivateInspectorControlsFill\n\t\t\t\t\t\t\t\tgroup=\"content\"\n\t\t\t\t\t\t\t\tforceDisplayControls\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<BlockFields\n\t\t\t\t\t\t\t\t\t{ ...props }\n\t\t\t\t\t\t\t\t\tblockType={ blockType }\n\t\t\t\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\t{ ! isSelectionWithinCurrentSection && isSelected && (\n\t\t\t\t\t<PrivateInspectorControlsFill group=\"content\">\n\t\t\t\t\t\t<BlockFields { ...props } blockType={ blockType } />\n\t\t\t\t\t</PrivateInspectorControlsFill>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t}\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/content-only-controls/block-fields',\n\twithBlockFields\n);\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -48,10 +48,6 @@ function Link({ data, field, onChange, config = {} }) {
|
|
|
48
48
|
isControl: true
|
|
49
49
|
});
|
|
50
50
|
const { fieldDef } = config;
|
|
51
|
-
const updateAttributes = (newValue) => {
|
|
52
|
-
const mappedChanges = field.setValue({ item: data, value: newValue });
|
|
53
|
-
onChange(mappedChanges);
|
|
54
|
-
};
|
|
55
51
|
const value = field.getValue({ item: data });
|
|
56
52
|
const url = value?.url;
|
|
57
53
|
const rel = value?.rel || "";
|
|
@@ -115,34 +111,28 @@ function Link({ data, field, onChange, config = {} }) {
|
|
|
115
111
|
rel,
|
|
116
112
|
...newValues
|
|
117
113
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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);
|
|
114
|
+
onChange(
|
|
115
|
+
field.setValue({
|
|
116
|
+
item: data,
|
|
117
|
+
value: updatedAttrs
|
|
118
|
+
})
|
|
119
|
+
);
|
|
133
120
|
},
|
|
134
121
|
onRemove: () => {
|
|
135
122
|
const removeValue = {};
|
|
136
123
|
if (fieldDef?.mapping) {
|
|
137
124
|
Object.keys(fieldDef.mapping).forEach(
|
|
138
125
|
(key) => {
|
|
139
|
-
|
|
140
|
-
removeValue[key] = void 0;
|
|
141
|
-
}
|
|
126
|
+
removeValue[key] = void 0;
|
|
142
127
|
}
|
|
143
128
|
);
|
|
144
129
|
}
|
|
145
|
-
|
|
130
|
+
onChange(
|
|
131
|
+
field.setValue({
|
|
132
|
+
item: data,
|
|
133
|
+
value: removeValue
|
|
134
|
+
})
|
|
135
|
+
);
|
|
146
136
|
}
|
|
147
137
|
}
|
|
148
138
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/hooks/block-fields/link/index.js"],
|
|
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 '../../../components/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, onChange, config = {} } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst { fieldDef } = config;\n\tconst
|
|
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;
|
|
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 '../../../components/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, onChange, config = {} } ) {\n\tconst [ isLinkControlOpen, setIsLinkControlOpen ] = useState( false );\n\tconst { popoverProps } = useInspectorPopoverPlacement( {\n\t\tisControl: true,\n\t} );\n\tconst { fieldDef } = config;\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\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: updatedAttrs,\n\t\t\t\t\t\t\t\t} )\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\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\tremoveValue[ key ] = undefined;\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\tonChange(\n\t\t\t\t\t\t\t\tfield.setValue( {\n\t\t\t\t\t\t\t\t\titem: data,\n\t\t\t\t\t\t\t\t\tvalue: removeValue,\n\t\t\t\t\t\t\t\t} )\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</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,9 +18,9 @@ import { useInspectorPopoverPlacement } from "../use-inspector-popover-placement
|
|
|
18
18
|
import { getMediaSelectKey } from "../../../store/private-keys.mjs";
|
|
19
19
|
import { store as blockEditorStore } from "../../../store/index.mjs";
|
|
20
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
-
function MediaThumbnail({ data, field, attachment }) {
|
|
22
|
-
const
|
|
23
|
-
const { allowedTypes = [], multiple = false } =
|
|
21
|
+
function MediaThumbnail({ data, field, attachment, config }) {
|
|
22
|
+
const { fieldDef } = config;
|
|
23
|
+
const { allowedTypes = [], multiple = false } = fieldDef.args || {};
|
|
24
24
|
if (multiple) {
|
|
25
25
|
return "todo multiple";
|
|
26
26
|
}
|
|
@@ -38,7 +38,7 @@ function MediaThumbnail({ data, field, attachment }) {
|
|
|
38
38
|
if (allowedTypes.length === 1) {
|
|
39
39
|
const value = field.getValue({ item: data });
|
|
40
40
|
const url = value?.url;
|
|
41
|
-
if (url) {
|
|
41
|
+
if (allowedTypes[0] === "image" && url) {
|
|
42
42
|
return /* @__PURE__ */ jsx("div", { className: "block-editor-content-only-controls__media-thumbnail", children: /* @__PURE__ */ jsx("img", { alt: "", width: 24, height: 24, src: url }) });
|
|
43
43
|
}
|
|
44
44
|
let icon;
|
|
@@ -62,15 +62,8 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
62
62
|
isControl: true
|
|
63
63
|
});
|
|
64
64
|
const value = field.getValue({ item: data });
|
|
65
|
-
const { allowedTypes = [], multiple = false } = field.config || {};
|
|
66
65
|
const { fieldDef } = config;
|
|
67
|
-
const
|
|
68
|
-
const mappedChanges = field.setValue({
|
|
69
|
-
item: data,
|
|
70
|
-
value: newFieldValue
|
|
71
|
-
});
|
|
72
|
-
onChange(mappedChanges);
|
|
73
|
-
};
|
|
66
|
+
const { allowedTypes = [], multiple = false } = fieldDef.args || {};
|
|
74
67
|
const hasFeaturedImageSupport = fieldDef?.mapping && "featuredImage" in fieldDef.mapping;
|
|
75
68
|
const id = value?.id;
|
|
76
69
|
const url = value?.url;
|
|
@@ -116,64 +109,44 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
116
109
|
const resetValue = {};
|
|
117
110
|
if (fieldDef?.mapping) {
|
|
118
111
|
Object.keys(fieldDef.mapping).forEach((key) => {
|
|
119
|
-
|
|
120
|
-
resetValue[key] = void 0;
|
|
121
|
-
} else if (key === "caption" || key === "alt") {
|
|
122
|
-
resetValue[key] = "";
|
|
123
|
-
}
|
|
112
|
+
resetValue[key] = void 0;
|
|
124
113
|
});
|
|
125
114
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
115
|
+
onChange(
|
|
116
|
+
field.setValue({
|
|
117
|
+
item: data,
|
|
118
|
+
value: resetValue
|
|
119
|
+
})
|
|
120
|
+
);
|
|
130
121
|
},
|
|
131
122
|
...hasFeaturedImageSupport && {
|
|
132
123
|
useFeaturedImage: !!value?.featuredImage,
|
|
133
124
|
onToggleFeaturedImage: () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
onChange(
|
|
126
|
+
field.setValue({
|
|
127
|
+
item: data,
|
|
128
|
+
value: {
|
|
129
|
+
featuredImage: !value?.featuredImage
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
);
|
|
138
133
|
}
|
|
139
134
|
},
|
|
140
135
|
onSelect: (selectedMedia) => {
|
|
141
136
|
if (selectedMedia.id && selectedMedia.url) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} else if (selectedMedia.mime_type.startsWith("audio/")) {
|
|
147
|
-
mediaType = "audio";
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const newValue = {};
|
|
151
|
-
if (fieldDef?.mapping) {
|
|
152
|
-
Object.keys(fieldDef.mapping).forEach(
|
|
153
|
-
(key) => {
|
|
154
|
-
if (key === "id") {
|
|
155
|
-
newValue[key] = selectedMedia.id;
|
|
156
|
-
} else if (key === "src" || key === "url") {
|
|
157
|
-
newValue[key] = selectedMedia.url;
|
|
158
|
-
} else if (key === "type") {
|
|
159
|
-
newValue[key] = mediaType;
|
|
160
|
-
} else if (key === "link" && selectedMedia.link) {
|
|
161
|
-
newValue[key] = selectedMedia.link;
|
|
162
|
-
} else if (key === "caption" && !value?.caption && selectedMedia.caption) {
|
|
163
|
-
newValue[key] = selectedMedia.caption;
|
|
164
|
-
} else if (key === "alt" && !value?.alt && selectedMedia.alt) {
|
|
165
|
-
newValue[key] = selectedMedia.alt;
|
|
166
|
-
} else if (key === "poster" && selectedMedia.poster) {
|
|
167
|
-
newValue[key] = selectedMedia.poster;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
}
|
|
137
|
+
const newValue = {
|
|
138
|
+
...selectedMedia,
|
|
139
|
+
mediaType: selectedMedia.media_type
|
|
140
|
+
};
|
|
172
141
|
if (hasFeaturedImageSupport) {
|
|
173
142
|
newValue.featuredImage = false;
|
|
174
143
|
}
|
|
175
|
-
|
|
176
|
-
|
|
144
|
+
onChange(
|
|
145
|
+
field.setValue({
|
|
146
|
+
item: data,
|
|
147
|
+
value: newValue
|
|
148
|
+
})
|
|
149
|
+
);
|
|
177
150
|
}
|
|
178
151
|
},
|
|
179
152
|
renderToggle: (buttonProps) => /* @__PURE__ */ jsx(
|
|
@@ -196,7 +169,8 @@ function Media({ data, field, onChange, config = {} }) {
|
|
|
196
169
|
{
|
|
197
170
|
attachment,
|
|
198
171
|
field,
|
|
199
|
-
data
|
|
172
|
+
data,
|
|
173
|
+
config
|
|
200
174
|
}
|
|
201
175
|
),
|
|
202
176
|
/* @__PURE__ */ jsx("span", {
|