@wordpress/block-editor 15.6.1-next.36001005c.0 → 15.7.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/build/components/block-list/block.js +3 -3
- package/build/components/block-list/block.js.map +2 -2
- package/build/components/block-list/index.js +2 -2
- package/build/components/block-list/index.js.map +1 -1
- package/build/components/block-toolbar/switch-section-style.js +2 -5
- package/build/components/block-toolbar/switch-section-style.js.map +2 -2
- package/build/components/global-styles/hooks.js +0 -107
- package/build/components/global-styles/hooks.js.map +3 -3
- package/build/components/global-styles/index.js +0 -15
- package/build/components/global-styles/index.js.map +2 -2
- package/build/components/global-styles/typography-panel.js +18 -1
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/global-styles/utils.js +0 -19
- package/build/components/global-styles/utils.js.map +3 -3
- package/build/components/inserter/media-tab/media-tab.js +33 -1
- package/build/components/inserter/media-tab/media-tab.js.map +3 -3
- package/build/components/inserter/tips.js +0 -2
- package/build/components/inserter/tips.js.map +2 -2
- package/build/components/media-placeholder/index.js +31 -1
- package/build/components/media-placeholder/index.js.map +3 -3
- package/build/components/media-replace-flow/index.js +29 -1
- package/build/components/media-replace-flow/index.js.map +3 -3
- package/build/components/{global-styles/context.js → media-upload-modal/index.js} +8 -23
- package/build/components/media-upload-modal/index.js.map +7 -0
- package/build/components/rich-text/index.js +8 -7
- package/build/components/rich-text/index.js.map +2 -2
- package/build/hooks/allowed-blocks.js +3 -8
- package/build/hooks/allowed-blocks.js.map +3 -3
- package/build/hooks/block-bindings.js +111 -170
- package/build/hooks/block-bindings.js.map +2 -2
- package/build/hooks/block-style-variation.js +4 -13
- package/build/hooks/block-style-variation.js.map +2 -2
- package/build/hooks/custom-class-name.js +1 -1
- package/build/hooks/custom-class-name.js.map +1 -1
- package/build/hooks/fit-text.js +33 -20
- package/build/hooks/fit-text.js.map +2 -2
- package/build/hooks/font-size.js +4 -3
- package/build/hooks/font-size.js.map +2 -2
- package/build/hooks/metadata.js +48 -2
- package/build/hooks/metadata.js.map +2 -2
- package/build/hooks/typography.js +11 -4
- package/build/hooks/typography.js.map +3 -3
- package/build/private-apis.js +3 -1
- package/build/private-apis.js.map +3 -3
- package/build/store/private-selectors.js +3 -3
- package/build/store/private-selectors.js.map +2 -2
- package/build/store/selectors.js +38 -13
- package/build/store/selectors.js.map +2 -2
- package/build/store/utils.js +2 -1
- package/build/store/utils.js.map +2 -2
- package/build/utils/fit-text-utils.js +4 -4
- package/build/utils/fit-text-utils.js.map +2 -2
- package/build-module/components/block-list/block.js +3 -3
- package/build-module/components/block-list/block.js.map +2 -2
- package/build-module/components/block-list/index.js +2 -2
- package/build-module/components/block-list/index.js.map +1 -1
- package/build-module/components/block-toolbar/switch-section-style.js +2 -5
- package/build-module/components/block-toolbar/switch-section-style.js.map +2 -2
- package/build-module/components/global-styles/hooks.js +1 -99
- package/build-module/components/global-styles/hooks.js.map +2 -2
- package/build-module/components/global-styles/index.js +1 -15
- package/build-module/components/global-styles/index.js.map +2 -2
- package/build-module/components/global-styles/typography-panel.js +18 -1
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- package/build-module/components/global-styles/utils.js +0 -8
- package/build-module/components/global-styles/utils.js.map +2 -2
- package/build-module/components/inserter/media-tab/media-tab.js +34 -2
- package/build-module/components/inserter/media-tab/media-tab.js.map +2 -2
- package/build-module/components/inserter/tips.js +0 -2
- package/build-module/components/inserter/tips.js.map +2 -2
- package/build-module/components/media-placeholder/index.js +31 -1
- package/build-module/components/media-placeholder/index.js.map +2 -2
- package/build-module/components/media-replace-flow/index.js +29 -1
- package/build-module/components/media-replace-flow/index.js.map +2 -2
- package/build-module/components/media-upload-modal/index.js +7 -0
- package/build-module/components/media-upload-modal/index.js.map +7 -0
- package/build-module/components/rich-text/index.js +8 -7
- package/build-module/components/rich-text/index.js.map +2 -2
- package/build-module/hooks/allowed-blocks.js +3 -8
- package/build-module/hooks/allowed-blocks.js.map +2 -2
- package/build-module/hooks/block-bindings.js +112 -172
- package/build-module/hooks/block-bindings.js.map +2 -2
- package/build-module/hooks/block-style-variation.js +5 -14
- package/build-module/hooks/block-style-variation.js.map +2 -2
- package/build-module/hooks/custom-class-name.js +1 -1
- package/build-module/hooks/custom-class-name.js.map +1 -1
- package/build-module/hooks/fit-text.js +34 -21
- package/build-module/hooks/fit-text.js.map +2 -2
- package/build-module/hooks/font-size.js +4 -3
- package/build-module/hooks/font-size.js.map +2 -2
- package/build-module/hooks/metadata.js +46 -1
- package/build-module/hooks/metadata.js.map +2 -2
- package/build-module/hooks/typography.js +11 -4
- package/build-module/hooks/typography.js.map +3 -3
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +2 -2
- package/build-module/store/private-selectors.js +2 -2
- package/build-module/store/private-selectors.js.map +2 -2
- package/build-module/store/selectors.js +39 -14
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/store/utils.js +3 -2
- package/build-module/store/utils.js.map +2 -2
- package/build-module/utils/fit-text-utils.js +4 -4
- package/build-module/utils/fit-text-utils.js.map +2 -2
- package/package.json +36 -36
- package/src/components/block-list/block.js +1 -1
- package/src/components/block-list/index.js +2 -2
- package/src/components/block-toolbar/switch-section-style.js +2 -5
- package/src/components/global-styles/hooks.js +1 -121
- package/src/components/global-styles/index.js +1 -9
- package/src/components/global-styles/typography-panel.js +26 -1
- package/src/components/global-styles/utils.js +0 -31
- package/src/components/inserter/media-tab/media-tab.js +44 -2
- package/src/components/inserter/tips.js +0 -2
- package/src/components/media-placeholder/index.js +41 -1
- package/src/components/media-replace-flow/index.js +39 -1
- package/src/components/media-upload-modal/index.js +18 -0
- package/src/components/rich-text/index.js +8 -14
- package/src/hooks/allowed-blocks.js +3 -11
- package/src/hooks/block-bindings.js +79 -153
- package/src/hooks/block-style-variation.js +5 -17
- package/src/hooks/custom-class-name.js +1 -1
- package/src/hooks/fit-text.js +39 -30
- package/src/hooks/font-size.js +7 -3
- package/src/hooks/metadata.js +89 -0
- package/src/hooks/test/metadata.js +316 -0
- package/src/hooks/typography.js +15 -4
- package/src/private-apis.js +2 -0
- package/src/store/private-selectors.js +2 -2
- package/src/store/selectors.js +59 -21
- package/src/store/test/selectors.js +1 -1
- package/src/store/utils.js +2 -1
- package/src/utils/fit-text-utils.js +4 -16
- package/tsconfig.json +1 -0
- package/build/components/global-styles/context.js.map +0 -7
- package/build/components/global-styles/get-global-styles-changes.js +0 -216
- package/build/components/global-styles/get-global-styles-changes.js.map +0 -7
- package/build-module/components/global-styles/context.js +0 -17
- package/build-module/components/global-styles/context.js.map +0 -7
- package/build-module/components/global-styles/get-global-styles-changes.js +0 -182
- package/build-module/components/global-styles/get-global-styles-changes.js.map +0 -7
- package/src/components/global-styles/README.md +0 -190
- package/src/components/global-styles/context.js +0 -16
- package/src/components/global-styles/get-global-styles-changes.js +0 -252
- package/src/components/global-styles/test/get-global-styles-changes.js +0 -290
- package/src/components/global-styles/test/utils.js +0 -58
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ToolbarButton,
|
|
13
13
|
} from '@wordpress/components';
|
|
14
14
|
import { useSelect, withDispatch } from '@wordpress/data';
|
|
15
|
+
import { useState } from '@wordpress/element';
|
|
15
16
|
import { DOWN } from '@wordpress/keycodes';
|
|
16
17
|
import {
|
|
17
18
|
postFeaturedImage,
|
|
@@ -26,6 +27,7 @@ import { store as noticesStore } from '@wordpress/notices';
|
|
|
26
27
|
* Internal dependencies
|
|
27
28
|
*/
|
|
28
29
|
import MediaUpload from '../media-upload';
|
|
30
|
+
import MediaUploadModal from '../media-upload-modal';
|
|
29
31
|
import MediaUploadCheck from '../media-upload/check';
|
|
30
32
|
import LinkControl from '../link-control';
|
|
31
33
|
import { store as blockEditorStore } from '../../store';
|
|
@@ -33,6 +35,42 @@ import { store as blockEditorStore } from '../../store';
|
|
|
33
35
|
const noop = () => {};
|
|
34
36
|
let uniqueId = 0;
|
|
35
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Conditional Media component that uses MediaUploadModal when experiment is enabled,
|
|
40
|
+
* otherwise falls back to MediaUpload.
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} root0 Component props.
|
|
43
|
+
* @param {Function} root0.render Render prop function that receives { open } object.
|
|
44
|
+
* @return {JSX.Element} The component.
|
|
45
|
+
*/
|
|
46
|
+
function ConditionalMediaUpload( { render, ...props } ) {
|
|
47
|
+
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
48
|
+
const { getSettings } = useSelect( blockEditorStore );
|
|
49
|
+
|
|
50
|
+
if ( window.__experimentalDataViewsMediaModal ) {
|
|
51
|
+
return (
|
|
52
|
+
<>
|
|
53
|
+
{ render && render( { open: () => setIsModalOpen( true ) } ) }
|
|
54
|
+
<MediaUploadModal
|
|
55
|
+
{ ...props }
|
|
56
|
+
isOpen={ isModalOpen }
|
|
57
|
+
onClose={ () => {
|
|
58
|
+
setIsModalOpen( false );
|
|
59
|
+
props.onClose?.();
|
|
60
|
+
} }
|
|
61
|
+
onSelect={ ( media ) => {
|
|
62
|
+
setIsModalOpen( false );
|
|
63
|
+
props.onSelect?.( media );
|
|
64
|
+
} }
|
|
65
|
+
onUpload={ getSettings().mediaUpload }
|
|
66
|
+
/>
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return <MediaUpload { ...props } render={ render } />;
|
|
72
|
+
}
|
|
73
|
+
|
|
36
74
|
const MediaReplaceFlow = ( {
|
|
37
75
|
mediaURL,
|
|
38
76
|
mediaId,
|
|
@@ -157,7 +195,7 @@ const MediaReplaceFlow = ( {
|
|
|
157
195
|
<>
|
|
158
196
|
<NavigableMenu className="block-editor-media-replace-flow__media-upload-menu">
|
|
159
197
|
<MediaUploadCheck>
|
|
160
|
-
<
|
|
198
|
+
<ConditionalMediaUpload
|
|
161
199
|
gallery={ gallery }
|
|
162
200
|
addToGallery={ addToGallery }
|
|
163
201
|
multiple={ multiple }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { withFilters } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is a placeholder for the media upload modal component necessary to make it possible to provide
|
|
8
|
+
* an integration with the core blocks that handle media files. By default it renders nothing but
|
|
9
|
+
* it provides a way to have it overridden with the `editor.MediaUploadModal` filter.
|
|
10
|
+
*
|
|
11
|
+
* @return {Component} The component to be rendered.
|
|
12
|
+
*/
|
|
13
|
+
const MediaUploadModal = () => null;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/media-upload-modal/README.md
|
|
17
|
+
*/
|
|
18
|
+
export default withFilters( 'editor.MediaUploadModal' )( MediaUploadModal );
|
|
@@ -41,6 +41,7 @@ import { getAllowedFormats } from './utils';
|
|
|
41
41
|
import { Content, valueToHTMLString } from './content';
|
|
42
42
|
import { withDeprecations } from './with-deprecations';
|
|
43
43
|
import BlockContext from '../block-context';
|
|
44
|
+
import { PrivateBlockContext } from '../block-list/private-block-context';
|
|
44
45
|
|
|
45
46
|
export const keyboardShortcutContext = createContext();
|
|
46
47
|
keyboardShortcutContext.displayName = 'keyboardShortcutContext';
|
|
@@ -124,9 +125,10 @@ export function RichTextWrapper(
|
|
|
124
125
|
const instanceId = useInstanceId( RichTextWrapper );
|
|
125
126
|
const anchorRef = useRef();
|
|
126
127
|
const context = useBlockEditContext();
|
|
127
|
-
const { clientId, isSelected: isBlockSelected
|
|
128
|
+
const { clientId, isSelected: isBlockSelected } = context;
|
|
128
129
|
const blockBindings = context[ blockBindingsKey ];
|
|
129
130
|
const blockContext = useContext( BlockContext );
|
|
131
|
+
const { bindableAttributes } = useContext( PrivateBlockContext );
|
|
130
132
|
const registry = useRegistry();
|
|
131
133
|
const selector = ( select ) => {
|
|
132
134
|
// Avoid subscribing to the block editor store if the block is not
|
|
@@ -171,15 +173,7 @@ export function RichTextWrapper(
|
|
|
171
173
|
|
|
172
174
|
const { disableBoundBlock, bindingsPlaceholder, bindingsLabel } = useSelect(
|
|
173
175
|
( select ) => {
|
|
174
|
-
|
|
175
|
-
select( blockEditorStore ).getSettings();
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
! blockBindings?.[ identifier ] ||
|
|
179
|
-
! (
|
|
180
|
-
blockName in __experimentalBlockBindingsSupportedAttributes
|
|
181
|
-
)
|
|
182
|
-
) {
|
|
176
|
+
if ( ! blockBindings?.[ identifier ] || ! bindableAttributes ) {
|
|
183
177
|
return {};
|
|
184
178
|
}
|
|
185
179
|
|
|
@@ -214,12 +208,12 @@ export function RichTextWrapper(
|
|
|
214
208
|
const { getBlockAttributes } = select( blockEditorStore );
|
|
215
209
|
const blockAttributes = getBlockAttributes( clientId );
|
|
216
210
|
let clientSideFieldLabel = null;
|
|
217
|
-
if ( blockBindingsSource?.
|
|
218
|
-
const
|
|
211
|
+
if ( blockBindingsSource?.getFieldsList ) {
|
|
212
|
+
const fieldsItems = blockBindingsSource.getFieldsList( {
|
|
219
213
|
select,
|
|
220
214
|
context: blockBindingsContext,
|
|
221
215
|
} );
|
|
222
|
-
clientSideFieldLabel =
|
|
216
|
+
clientSideFieldLabel = fieldsItems?.find( ( item ) =>
|
|
223
217
|
fastDeepEqual( item.args, relatedBinding?.args )
|
|
224
218
|
)?.label;
|
|
225
219
|
}
|
|
@@ -252,7 +246,7 @@ export function RichTextWrapper(
|
|
|
252
246
|
[
|
|
253
247
|
blockBindings,
|
|
254
248
|
identifier,
|
|
255
|
-
|
|
249
|
+
bindableAttributes,
|
|
256
250
|
adjustedValue,
|
|
257
251
|
clientId,
|
|
258
252
|
blockContext,
|
|
@@ -3,25 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { addFilter } from '@wordpress/hooks';
|
|
5
5
|
import { hasBlockSupport } from '@wordpress/blocks';
|
|
6
|
-
import { useSelect } from '@wordpress/data';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Internal dependencies
|
|
10
9
|
*/
|
|
11
|
-
import { store as blockEditorStore } from '../store';
|
|
12
10
|
import { PrivateInspectorControlsAllowedBlocks } from '../components/inspector-controls/groups';
|
|
13
11
|
import BlockAllowedBlocksControl from '../components/block-allowed-blocks/allowed-blocks-control';
|
|
12
|
+
import { useBlockEditingMode } from '../components/block-editing-mode';
|
|
14
13
|
|
|
15
14
|
function BlockEditAllowedBlocksControlPure( { clientId } ) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
select( blockEditorStore ).getBlockEditingMode( clientId ) ===
|
|
20
|
-
'contentOnly'
|
|
21
|
-
);
|
|
22
|
-
},
|
|
23
|
-
[ clientId ]
|
|
24
|
-
);
|
|
15
|
+
const blockEditingMode = useBlockEditingMode();
|
|
16
|
+
const isContentOnly = blockEditingMode === 'contentOnly';
|
|
25
17
|
|
|
26
18
|
if ( isContentOnly ) {
|
|
27
19
|
return null;
|
|
@@ -15,11 +15,10 @@ import {
|
|
|
15
15
|
__experimentalToolsPanel as ToolsPanel,
|
|
16
16
|
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
17
17
|
__experimentalVStack as VStack,
|
|
18
|
-
Modal,
|
|
19
18
|
privateApis as componentsPrivateApis,
|
|
20
19
|
} from '@wordpress/components';
|
|
21
20
|
import { useSelect } from '@wordpress/data';
|
|
22
|
-
import { useContext
|
|
21
|
+
import { useContext } from '@wordpress/element';
|
|
23
22
|
import { useViewportMatch } from '@wordpress/compose';
|
|
24
23
|
|
|
25
24
|
/**
|
|
@@ -63,12 +62,7 @@ const useToolsPanelDropdownMenuProps = () => {
|
|
|
63
62
|
: {};
|
|
64
63
|
};
|
|
65
64
|
|
|
66
|
-
function BlockBindingsPanelMenuContent( {
|
|
67
|
-
attribute,
|
|
68
|
-
binding,
|
|
69
|
-
sources,
|
|
70
|
-
onOpenModal,
|
|
71
|
-
} ) {
|
|
65
|
+
function BlockBindingsPanelMenuContent( { attribute, binding, sources } ) {
|
|
72
66
|
const { clientId } = useBlockEditContext();
|
|
73
67
|
const { updateBlockBindings } = useBlockBindingsUtils();
|
|
74
68
|
const isMobile = useViewportMatch( 'medium', '<' );
|
|
@@ -99,105 +93,85 @@ function BlockBindingsPanelMenuContent( {
|
|
|
99
93
|
return null;
|
|
100
94
|
}
|
|
101
95
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
>
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
item.args
|
|
137
|
-
) || item.key
|
|
138
|
-
}
|
|
139
|
-
onChange={ () => {
|
|
140
|
-
const isCurrentlySelected =
|
|
141
|
-
fastDeepEqual(
|
|
142
|
-
binding?.args,
|
|
143
|
-
item.args
|
|
144
|
-
) ??
|
|
145
|
-
// Deprecate key dependency in 7.0.
|
|
146
|
-
item.key ===
|
|
147
|
-
binding?.args?.key;
|
|
148
|
-
|
|
149
|
-
if ( isCurrentlySelected ) {
|
|
150
|
-
// Unset if the same item is selected again.
|
|
151
|
-
updateBlockBindings( {
|
|
152
|
-
[ attribute ]:
|
|
153
|
-
undefined,
|
|
154
|
-
} );
|
|
155
|
-
} else {
|
|
156
|
-
updateBlockBindings( {
|
|
157
|
-
[ attribute ]:
|
|
158
|
-
itemBindings,
|
|
159
|
-
} );
|
|
160
|
-
}
|
|
161
|
-
} }
|
|
162
|
-
name={ attribute + '-binding' }
|
|
163
|
-
value={ values[ attribute ] }
|
|
164
|
-
checked={
|
|
96
|
+
return (
|
|
97
|
+
<Menu
|
|
98
|
+
key={ sourceKey }
|
|
99
|
+
placement={ isMobile ? 'bottom-start' : 'left-start' }
|
|
100
|
+
>
|
|
101
|
+
<Menu.SubmenuTriggerItem>
|
|
102
|
+
<Menu.ItemLabel>{ source.label }</Menu.ItemLabel>
|
|
103
|
+
</Menu.SubmenuTriggerItem>
|
|
104
|
+
<Menu.Popover gutter={ 8 }>
|
|
105
|
+
<Menu.Group>
|
|
106
|
+
{ sourceDataItems.map( ( item ) => {
|
|
107
|
+
const itemBindings = {
|
|
108
|
+
source: sourceKey,
|
|
109
|
+
args: item?.args || {
|
|
110
|
+
key: item.key,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const values = source.getValues( {
|
|
114
|
+
select,
|
|
115
|
+
context: blockContext,
|
|
116
|
+
bindings: {
|
|
117
|
+
[ attribute ]: itemBindings,
|
|
118
|
+
},
|
|
119
|
+
} );
|
|
120
|
+
return (
|
|
121
|
+
<Menu.CheckboxItem
|
|
122
|
+
key={
|
|
123
|
+
sourceKey +
|
|
124
|
+
JSON.stringify(
|
|
125
|
+
item.args
|
|
126
|
+
) || item.key
|
|
127
|
+
}
|
|
128
|
+
onChange={ () => {
|
|
129
|
+
const isCurrentlySelected =
|
|
165
130
|
fastDeepEqual(
|
|
166
131
|
binding?.args,
|
|
167
132
|
item.args
|
|
168
133
|
) ??
|
|
169
134
|
// Deprecate key dependency in 7.0.
|
|
170
135
|
item.key ===
|
|
171
|
-
binding?.args?.key
|
|
136
|
+
binding?.args?.key;
|
|
137
|
+
|
|
138
|
+
if ( isCurrentlySelected ) {
|
|
139
|
+
// Unset if the same item is selected again.
|
|
140
|
+
updateBlockBindings( {
|
|
141
|
+
[ attribute ]:
|
|
142
|
+
undefined,
|
|
143
|
+
} );
|
|
144
|
+
} else {
|
|
145
|
+
updateBlockBindings( {
|
|
146
|
+
[ attribute ]:
|
|
147
|
+
itemBindings,
|
|
148
|
+
} );
|
|
172
149
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return null;
|
|
150
|
+
} }
|
|
151
|
+
name={ attribute + '-binding' }
|
|
152
|
+
value={ values[ attribute ] }
|
|
153
|
+
checked={
|
|
154
|
+
fastDeepEqual(
|
|
155
|
+
binding?.args,
|
|
156
|
+
item.args
|
|
157
|
+
) ??
|
|
158
|
+
// Deprecate key dependency in 7.0.
|
|
159
|
+
item.key === binding?.args?.key
|
|
160
|
+
}
|
|
161
|
+
>
|
|
162
|
+
<Menu.ItemLabel>
|
|
163
|
+
{ item?.label }
|
|
164
|
+
</Menu.ItemLabel>
|
|
165
|
+
<Menu.ItemHelpText>
|
|
166
|
+
{ values[ attribute ] }
|
|
167
|
+
</Menu.ItemHelpText>
|
|
168
|
+
</Menu.CheckboxItem>
|
|
169
|
+
);
|
|
170
|
+
} ) }
|
|
171
|
+
</Menu.Group>
|
|
172
|
+
</Menu.Popover>
|
|
173
|
+
</Menu>
|
|
174
|
+
);
|
|
201
175
|
} ) }
|
|
202
176
|
</Menu>
|
|
203
177
|
);
|
|
@@ -282,16 +256,11 @@ function EditableBlockBindingsPanelItem( {
|
|
|
282
256
|
attribute,
|
|
283
257
|
binding,
|
|
284
258
|
sources,
|
|
285
|
-
setModalState,
|
|
286
259
|
blockName,
|
|
287
260
|
} ) {
|
|
288
261
|
const { updateBlockBindings } = useBlockBindingsUtils();
|
|
289
262
|
const isMobile = useViewportMatch( 'medium', '<' );
|
|
290
263
|
|
|
291
|
-
const handleOpenModal = ( { sourceKey } ) => {
|
|
292
|
-
setModalState( { attribute, sourceKey } );
|
|
293
|
-
};
|
|
294
|
-
|
|
295
264
|
return (
|
|
296
265
|
<ToolsPanelItem
|
|
297
266
|
hasValue={ () => !! binding }
|
|
@@ -316,7 +285,6 @@ function EditableBlockBindingsPanelItem( {
|
|
|
316
285
|
attribute={ attribute }
|
|
317
286
|
binding={ binding }
|
|
318
287
|
sources={ sources }
|
|
319
|
-
onOpenModal={ handleOpenModal }
|
|
320
288
|
/>
|
|
321
289
|
</Menu.Popover>
|
|
322
290
|
</Menu>
|
|
@@ -328,11 +296,6 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
328
296
|
const blockContext = useContext( BlockContext );
|
|
329
297
|
const { removeAllBlockBindings } = useBlockBindingsUtils();
|
|
330
298
|
const dropdownMenuProps = useToolsPanelDropdownMenuProps();
|
|
331
|
-
const [ modalState, setModalState ] = useState( null );
|
|
332
|
-
|
|
333
|
-
const handleCloseModal = () => {
|
|
334
|
-
setModalState( null );
|
|
335
|
-
};
|
|
336
299
|
|
|
337
300
|
// Use useSelect to ensure sources are updated whenever there are updates in block context
|
|
338
301
|
// or when underlying data changes.
|
|
@@ -352,7 +315,7 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
352
315
|
Object.entries( registeredSources ).forEach(
|
|
353
316
|
( [
|
|
354
317
|
sourceName,
|
|
355
|
-
{
|
|
318
|
+
{ getFieldsList, usesContext, label, getValues },
|
|
356
319
|
] ) => {
|
|
357
320
|
// Populate context.
|
|
358
321
|
const context = {};
|
|
@@ -361,44 +324,19 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
361
324
|
context[ key ] = blockContext[ key ];
|
|
362
325
|
}
|
|
363
326
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const editorUIResult = editorUI( {
|
|
327
|
+
if ( getFieldsList ) {
|
|
328
|
+
const fieldsListResult = getFieldsList( {
|
|
367
329
|
select,
|
|
368
330
|
context,
|
|
369
331
|
} );
|
|
370
|
-
|
|
371
332
|
_sources[ sourceName ] = {
|
|
372
|
-
|
|
333
|
+
data: fieldsListResult || [],
|
|
373
334
|
label,
|
|
374
335
|
getValues,
|
|
375
336
|
};
|
|
376
|
-
} else if ( getFieldsList ) {
|
|
377
|
-
// Backward compatibility: Convert getFieldsList to editorUI format.
|
|
378
|
-
const fieldsListResult = getFieldsList( {
|
|
379
|
-
select,
|
|
380
|
-
context,
|
|
381
|
-
} );
|
|
382
|
-
|
|
383
|
-
if ( fieldsListResult ) {
|
|
384
|
-
const data = Object.entries( fieldsListResult ).map(
|
|
385
|
-
( [ key, field ] ) => ( {
|
|
386
|
-
label: field.label || key,
|
|
387
|
-
type: field.type || 'string',
|
|
388
|
-
args: { key },
|
|
389
|
-
} )
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
_sources[ sourceName ] = {
|
|
393
|
-
mode: 'dropdown', // Default mode for backward compatibility.
|
|
394
|
-
data,
|
|
395
|
-
label,
|
|
396
|
-
getValues,
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
337
|
} else {
|
|
400
338
|
/*
|
|
401
|
-
* Include sources without
|
|
339
|
+
* Include sources without getFieldsList if they are already used in a binding.
|
|
402
340
|
* This allows them to be displayed in read-only mode.
|
|
403
341
|
*/
|
|
404
342
|
_sources[ sourceName ] = {
|
|
@@ -438,9 +376,6 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
438
376
|
// Lock the UI when the user can't update bindings or there are no fields to connect to.
|
|
439
377
|
const readOnly = ! canUpdateBlockBindings || ! hasCompatibleData;
|
|
440
378
|
|
|
441
|
-
const RenderModalContent =
|
|
442
|
-
sources[ modalState?.sourceKey ]?.renderModalContent;
|
|
443
|
-
|
|
444
379
|
if ( bindings === undefined && ! hasCompatibleData ) {
|
|
445
380
|
return null;
|
|
446
381
|
}
|
|
@@ -490,7 +425,6 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
490
425
|
attribute={ attribute }
|
|
491
426
|
binding={ binding }
|
|
492
427
|
sources={ sources }
|
|
493
|
-
setModalState={ setModalState }
|
|
494
428
|
blockName={ blockName }
|
|
495
429
|
/>
|
|
496
430
|
);
|
|
@@ -508,14 +442,6 @@ export const BlockBindingsPanel = ( { name: blockName, metadata } ) => {
|
|
|
508
442
|
</p>
|
|
509
443
|
</Text>
|
|
510
444
|
</ToolsPanel>
|
|
511
|
-
{ RenderModalContent && (
|
|
512
|
-
<Modal onRequestClose={ handleCloseModal }>
|
|
513
|
-
<RenderModalContent
|
|
514
|
-
attribute={ modalState.attribute }
|
|
515
|
-
closeModal={ handleCloseModal }
|
|
516
|
-
/>
|
|
517
|
-
</Modal>
|
|
518
|
-
) }
|
|
519
445
|
</InspectorControls>
|
|
520
446
|
);
|
|
521
447
|
};
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { getBlockTypes, store as blocksStore } from '@wordpress/blocks';
|
|
5
5
|
import { useSelect } from '@wordpress/data';
|
|
6
|
-
import {
|
|
6
|
+
import { useMemo } from '@wordpress/element';
|
|
7
7
|
import { toStyles, getBlockSelectors } from '@wordpress/global-styles-engine';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
|
-
import { GlobalStylesContext } from '../components/global-styles';
|
|
13
12
|
import { usePrivateStyleOverride } from './utils';
|
|
14
13
|
import { getValueFromObjectPath } from '../utils/object';
|
|
15
14
|
import { store as blockEditorStore } from '../store';
|
|
@@ -249,10 +248,6 @@ export function getVariationStylesWithRefValues(
|
|
|
249
248
|
}
|
|
250
249
|
|
|
251
250
|
function useBlockStyleVariation( name, variation, clientId ) {
|
|
252
|
-
// Prefer global styles data in GlobalStylesContext, which are available
|
|
253
|
-
// if in the site editor. Otherwise fall back to whatever is in the
|
|
254
|
-
// editor settings and available in the post editor.
|
|
255
|
-
const { merged: mergedConfig } = useContext( GlobalStylesContext );
|
|
256
251
|
const { globalSettings, globalStyles } = useSelect( ( select ) => {
|
|
257
252
|
const settings = select( blockEditorStore ).getSettings();
|
|
258
253
|
return {
|
|
@@ -264,15 +259,15 @@ function useBlockStyleVariation( name, variation, clientId ) {
|
|
|
264
259
|
return useMemo( () => {
|
|
265
260
|
const variationStyles = getVariationStylesWithRefValues(
|
|
266
261
|
{
|
|
267
|
-
settings:
|
|
268
|
-
styles:
|
|
262
|
+
settings: globalSettings,
|
|
263
|
+
styles: globalStyles,
|
|
269
264
|
},
|
|
270
265
|
name,
|
|
271
266
|
variation
|
|
272
267
|
);
|
|
273
268
|
|
|
274
269
|
return {
|
|
275
|
-
settings:
|
|
270
|
+
settings: globalSettings,
|
|
276
271
|
// The variation style data is all that is needed to generate
|
|
277
272
|
// the styles for the current application to a block. The variation
|
|
278
273
|
// name is updated to match the instance specific class name.
|
|
@@ -286,14 +281,7 @@ function useBlockStyleVariation( name, variation, clientId ) {
|
|
|
286
281
|
},
|
|
287
282
|
},
|
|
288
283
|
};
|
|
289
|
-
}, [
|
|
290
|
-
mergedConfig,
|
|
291
|
-
globalSettings,
|
|
292
|
-
globalStyles,
|
|
293
|
-
variation,
|
|
294
|
-
clientId,
|
|
295
|
-
name,
|
|
296
|
-
] );
|
|
284
|
+
}, [ globalSettings, globalStyles, variation, clientId, name ] );
|
|
297
285
|
}
|
|
298
286
|
|
|
299
287
|
// Rather than leveraging `useInstanceId` here, the `clientId` is used.
|