@wordpress/block-editor 15.6.0 → 15.6.1
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-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/global-styles/typography-panel.js +18 -1
- package/build/components/global-styles/typography-panel.js.map +2 -2
- package/build/components/rich-text/index.js +8 -7
- package/build/components/rich-text/index.js.map +2 -2
- package/build/hooks/block-bindings.js +111 -170
- package/build/hooks/block-bindings.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 +31 -18
- 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/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/global-styles/typography-panel.js +18 -1
- package/build-module/components/global-styles/typography-panel.js.map +2 -2
- 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/block-bindings.js +112 -172
- package/build-module/hooks/block-bindings.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 +32 -19
- 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/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 +35 -35
- package/src/components/block-list/block.js +1 -1
- package/src/components/block-list/index.js +2 -2
- package/src/components/global-styles/typography-panel.js +26 -1
- package/src/components/rich-text/index.js +8 -14
- package/src/hooks/block-bindings.js +79 -153
- package/src/hooks/custom-class-name.js +1 -1
- package/src/hooks/fit-text.js +37 -28
- 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/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
|
@@ -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
|
};
|
package/src/hooks/fit-text.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { addFilter } from '@wordpress/hooks';
|
|
5
5
|
import { hasBlockSupport } from '@wordpress/blocks';
|
|
6
|
-
import { useEffect, useCallback
|
|
6
|
+
import { useEffect, useCallback } from '@wordpress/element';
|
|
7
7
|
import { useSelect } from '@wordpress/data';
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
9
|
import {
|
|
@@ -62,28 +62,18 @@ function useFitText( { fitText, name, clientId } ) {
|
|
|
62
62
|
const hasFitTextSupport = hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY );
|
|
63
63
|
const blockElement = useBlockElement( clientId );
|
|
64
64
|
|
|
65
|
-
// Monitor block attribute changes
|
|
65
|
+
// Monitor block attribute changes
|
|
66
66
|
// Any attribute may change the available space.
|
|
67
|
-
const
|
|
67
|
+
const blockAttributes = useSelect(
|
|
68
68
|
( select ) => {
|
|
69
69
|
if ( ! clientId ) {
|
|
70
|
-
return
|
|
70
|
+
return;
|
|
71
71
|
}
|
|
72
|
-
return
|
|
73
|
-
blockAttributes:
|
|
74
|
-
select( blockEditorStore ).getBlockAttributes( clientId ),
|
|
75
|
-
isSelected:
|
|
76
|
-
select( blockEditorStore ).isBlockSelected( clientId ),
|
|
77
|
-
};
|
|
72
|
+
return select( blockEditorStore ).getBlockAttributes( clientId );
|
|
78
73
|
},
|
|
79
74
|
[ clientId ]
|
|
80
75
|
);
|
|
81
76
|
|
|
82
|
-
const isSelectedRef = useRef();
|
|
83
|
-
useEffect( () => {
|
|
84
|
-
isSelectedRef.current = isSelected;
|
|
85
|
-
}, [ isSelected ] );
|
|
86
|
-
|
|
87
77
|
const applyFitText = useCallback( () => {
|
|
88
78
|
if ( ! blockElement || ! hasFitTextSupport || ! fitText ) {
|
|
89
79
|
return;
|
|
@@ -104,13 +94,8 @@ function useFitText( { fitText, name, clientId } ) {
|
|
|
104
94
|
styleElement.textContent = css;
|
|
105
95
|
};
|
|
106
96
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// effect of the first few keypresses.
|
|
110
|
-
const maxSize = isSelectedRef.current ? 200 : undefined;
|
|
111
|
-
|
|
112
|
-
optimizeFitText( blockElement, blockSelector, applyStylesFn, maxSize );
|
|
113
|
-
}, [ blockElement, clientId, hasFitTextSupport, fitText, isSelectedRef ] );
|
|
97
|
+
optimizeFitText( blockElement, blockSelector, applyStylesFn );
|
|
98
|
+
}, [ blockElement, clientId, hasFitTextSupport, fitText ] );
|
|
114
99
|
|
|
115
100
|
useEffect( () => {
|
|
116
101
|
if (
|
|
@@ -164,7 +149,6 @@ function useFitText( { fitText, name, clientId } ) {
|
|
|
164
149
|
}
|
|
165
150
|
}, [
|
|
166
151
|
blockAttributes,
|
|
167
|
-
isSelected,
|
|
168
152
|
fitText,
|
|
169
153
|
applyFitText,
|
|
170
154
|
blockElement,
|
|
@@ -180,12 +164,16 @@ function useFitText( { fitText, name, clientId } ) {
|
|
|
180
164
|
* @param {Function} props.setAttributes Function to set block attributes.
|
|
181
165
|
* @param {string} props.name Block name.
|
|
182
166
|
* @param {boolean} props.fitText Whether fit text is enabled.
|
|
167
|
+
* @param {string} props.fontSize Font size slug.
|
|
168
|
+
* @param {Object} props.style Block style object.
|
|
183
169
|
*/
|
|
184
170
|
export function FitTextControl( {
|
|
185
171
|
clientId,
|
|
186
172
|
fitText = false,
|
|
187
173
|
setAttributes,
|
|
188
174
|
name,
|
|
175
|
+
fontSize,
|
|
176
|
+
style,
|
|
189
177
|
} ) {
|
|
190
178
|
if ( ! hasBlockSupport( name, FIT_TEXT_SUPPORT_KEY ) ) {
|
|
191
179
|
return null;
|
|
@@ -203,13 +191,34 @@ export function FitTextControl( {
|
|
|
203
191
|
__nextHasNoMarginBottom
|
|
204
192
|
label={ __( 'Fit text' ) }
|
|
205
193
|
checked={ fitText }
|
|
206
|
-
onChange={ () =>
|
|
207
|
-
|
|
208
|
-
|
|
194
|
+
onChange={ () => {
|
|
195
|
+
const newFitText = ! fitText || undefined;
|
|
196
|
+
const updates = { fitText: newFitText };
|
|
197
|
+
|
|
198
|
+
// When enabling fit text, clear font size if it has a value
|
|
199
|
+
if ( newFitText ) {
|
|
200
|
+
if ( fontSize ) {
|
|
201
|
+
updates.fontSize = undefined;
|
|
202
|
+
}
|
|
203
|
+
if ( style?.typography?.fontSize ) {
|
|
204
|
+
updates.style = {
|
|
205
|
+
...style,
|
|
206
|
+
typography: {
|
|
207
|
+
...style?.typography,
|
|
208
|
+
fontSize: undefined,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
setAttributes( updates );
|
|
215
|
+
} }
|
|
209
216
|
help={
|
|
210
217
|
fitText
|
|
211
218
|
? __( 'Text will resize to fit its container.' )
|
|
212
|
-
: __(
|
|
219
|
+
: __(
|
|
220
|
+
'The text will resize to fit its container, resetting other font size settings.'
|
|
221
|
+
)
|
|
213
222
|
}
|
|
214
223
|
/>
|
|
215
224
|
</ToolsPanelItem>
|
|
@@ -278,7 +287,7 @@ const hasFitTextSupport = ( blockNameOrType ) => {
|
|
|
278
287
|
export default {
|
|
279
288
|
useBlockProps,
|
|
280
289
|
addSaveProps,
|
|
281
|
-
attributeKeys: [ 'fitText' ],
|
|
290
|
+
attributeKeys: [ 'fitText', 'fontSize', 'style' ],
|
|
282
291
|
hasSupport: hasFitTextSupport,
|
|
283
292
|
edit: FitTextControl,
|
|
284
293
|
};
|
package/src/hooks/font-size.js
CHANGED
|
@@ -97,8 +97,11 @@ export function FontSizeEdit( props ) {
|
|
|
97
97
|
} = props;
|
|
98
98
|
const [ fontSizes ] = useSettings( 'typography.fontSizes' );
|
|
99
99
|
|
|
100
|
-
const onChange = ( value ) => {
|
|
101
|
-
|
|
100
|
+
const onChange = ( value, selectedItem ) => {
|
|
101
|
+
// Use the selectedItem's slug if available, otherwise fall back to finding by value
|
|
102
|
+
const fontSizeSlug =
|
|
103
|
+
selectedItem?.slug ||
|
|
104
|
+
getFontSizeObjectByValue( fontSizes, value ).slug;
|
|
102
105
|
|
|
103
106
|
setAttributes( {
|
|
104
107
|
style: cleanEmptyObject( {
|
|
@@ -124,7 +127,8 @@ export function FontSizeEdit( props ) {
|
|
|
124
127
|
return (
|
|
125
128
|
<FontSizePicker
|
|
126
129
|
onChange={ onChange }
|
|
127
|
-
value={ fontSizeValue }
|
|
130
|
+
value={ fontSize || fontSizeValue }
|
|
131
|
+
valueMode={ fontSize ? 'slug' : 'literal' }
|
|
128
132
|
withReset={ false }
|
|
129
133
|
withSlider
|
|
130
134
|
size="__unstable-large"
|
package/src/hooks/metadata.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { addFilter } from '@wordpress/hooks';
|
|
5
|
+
import { hasBlockSupport } from '@wordpress/blocks';
|
|
6
|
+
|
|
5
7
|
const META_ATTRIBUTE_NAME = 'metadata';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -28,8 +30,95 @@ export function addMetaAttribute( blockTypeSettings ) {
|
|
|
28
30
|
return blockTypeSettings;
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Add metadata transforms.
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} result The transformed block.
|
|
37
|
+
* @param {Array} source Original blocks transformed.
|
|
38
|
+
* @param {number} index Index of the transformed block.
|
|
39
|
+
* @param {Array} results All blocks that resulted from the transformation.
|
|
40
|
+
* @return {Object} Modified transformed block.
|
|
41
|
+
*/
|
|
42
|
+
export function addTransforms( result, source, index, results ) {
|
|
43
|
+
// If the condition verifies we are probably in the presence of a wrapping transform
|
|
44
|
+
// e.g: nesting paragraphs in a group or columns and in that case the metadata should not be kept.
|
|
45
|
+
if ( results.length === 1 && result.innerBlocks.length === source.length ) {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If we are transforming one block to multiple blocks or multiple blocks to one block,
|
|
50
|
+
// we ignore the metadata during the transform.
|
|
51
|
+
if (
|
|
52
|
+
( results.length === 1 && source.length > 1 ) ||
|
|
53
|
+
( results.length > 1 && source.length === 1 )
|
|
54
|
+
) {
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// If we are transforming multiple blocks to multiple blocks with different counts,
|
|
59
|
+
// we ignore the metadata during the transform.
|
|
60
|
+
if (
|
|
61
|
+
results.length > 1 &&
|
|
62
|
+
source.length > 1 &&
|
|
63
|
+
results.length !== source.length
|
|
64
|
+
) {
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const sourceMetadata = source[ index ]?.attributes?.metadata;
|
|
69
|
+
|
|
70
|
+
if ( ! sourceMetadata ) {
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const preservedMetadata = {};
|
|
75
|
+
|
|
76
|
+
// Notes
|
|
77
|
+
if ( sourceMetadata.noteId && ! result.attributes?.metadata?.noteId ) {
|
|
78
|
+
preservedMetadata.noteId = sourceMetadata.noteId;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Custom name
|
|
82
|
+
if (
|
|
83
|
+
sourceMetadata.name &&
|
|
84
|
+
! result.attributes?.metadata?.name &&
|
|
85
|
+
hasBlockSupport( result.name, 'renaming', true )
|
|
86
|
+
) {
|
|
87
|
+
preservedMetadata.name = sourceMetadata.name;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Block visibility
|
|
91
|
+
if (
|
|
92
|
+
sourceMetadata.blockVisibility !== undefined &&
|
|
93
|
+
! result.attributes?.metadata?.blockVisibility &&
|
|
94
|
+
hasBlockSupport( result.name, 'blockVisibility', true )
|
|
95
|
+
) {
|
|
96
|
+
preservedMetadata.blockVisibility = sourceMetadata.blockVisibility;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ( Object.keys( preservedMetadata ).length > 0 ) {
|
|
100
|
+
return {
|
|
101
|
+
...result,
|
|
102
|
+
attributes: {
|
|
103
|
+
...result.attributes,
|
|
104
|
+
metadata: {
|
|
105
|
+
...result.attributes.metadata,
|
|
106
|
+
...preservedMetadata,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
|
|
31
114
|
addFilter(
|
|
32
115
|
'blocks.registerBlockType',
|
|
33
116
|
'core/metadata/addMetaAttribute',
|
|
34
117
|
addMetaAttribute
|
|
35
118
|
);
|
|
119
|
+
|
|
120
|
+
addFilter(
|
|
121
|
+
'blocks.switchToBlockType.transformedBlock',
|
|
122
|
+
'core/metadata/addTransforms',
|
|
123
|
+
addTransforms
|
|
124
|
+
);
|