@wordpress/block-editor 12.3.13 → 12.3.15
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-controls/use-has-block-controls.js +52 -0
- package/build/components/block-controls/use-has-block-controls.js.map +1 -0
- package/build/components/block-tools/block-contextual-toolbar.js +50 -5
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +3 -2
- package/build/components/global-styles/typography-utils.js.map +1 -1
- package/build/components/link-control/index.js +47 -6
- package/build/components/link-control/index.js.map +1 -1
- package/build/components/rich-text/use-format-types.js +3 -2
- package/build/components/rich-text/use-format-types.js.map +1 -1
- package/build-module/components/block-controls/use-has-block-controls.js +38 -0
- package/build-module/components/block-controls/use-has-block-controls.js.map +1 -0
- package/build-module/components/block-tools/block-contextual-toolbar.js +49 -5
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +4 -3
- package/build-module/components/global-styles/typography-utils.js.map +1 -1
- package/build-module/components/link-control/index.js +45 -6
- package/build-module/components/link-control/index.js.map +1 -1
- package/build-module/components/rich-text/use-format-types.js +3 -2
- package/build-module/components/rich-text/use-format-types.js.map +1 -1
- package/build-style/content-rtl.css +5 -7
- package/build-style/content.css +5 -7
- package/build-style/style-rtl.css +28 -6
- package/build-style/style.css +28 -6
- package/package.json +31 -31
- package/src/components/block-controls/use-has-block-controls.js +35 -0
- package/src/components/block-list/content.scss +2 -3
- package/src/components/block-toolbar/style.scss +10 -0
- package/src/components/block-tools/block-contextual-toolbar.js +86 -7
- package/src/components/block-tools/style.scss +34 -10
- package/src/components/global-styles/test/typography-utils.js +10 -0
- package/src/components/global-styles/typography-utils.js +11 -3
- package/src/components/link-control/README.md +12 -3
- package/src/components/link-control/index.js +43 -6
- package/src/components/link-control/test/index.js +2 -1
- package/src/components/rich-text/use-format-types.js +3 -3
|
@@ -12,6 +12,8 @@ import { useRef, useState, useEffect } from '@wordpress/element';
|
|
|
12
12
|
import { focus } from '@wordpress/dom';
|
|
13
13
|
import { ENTER } from '@wordpress/keycodes';
|
|
14
14
|
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal';
|
|
15
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
16
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Internal dependencies
|
|
@@ -101,6 +103,9 @@ import { DEFAULT_LINK_SETTINGS } from './constants';
|
|
|
101
103
|
|
|
102
104
|
const noop = () => {};
|
|
103
105
|
|
|
106
|
+
const PREFERENCE_SCOPE = 'core/block-editor';
|
|
107
|
+
const PREFERENCE_KEY = 'linkControlSettingsDrawer';
|
|
108
|
+
|
|
104
109
|
/**
|
|
105
110
|
* Renders a link control. A link control is a controlled input which maintains
|
|
106
111
|
* a value associated with a link (HTML anchor element) and relevant settings
|
|
@@ -133,6 +138,41 @@ function LinkControl( {
|
|
|
133
138
|
withCreateSuggestion = true;
|
|
134
139
|
}
|
|
135
140
|
|
|
141
|
+
const [ settingsOpen, setSettingsOpen ] = useState( false );
|
|
142
|
+
|
|
143
|
+
const { advancedSettingsPreference } = useSelect( ( select ) => {
|
|
144
|
+
const prefsStore = select( preferencesStore );
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
advancedSettingsPreference:
|
|
148
|
+
prefsStore.get( PREFERENCE_SCOPE, PREFERENCE_KEY ) ?? false,
|
|
149
|
+
};
|
|
150
|
+
}, [] );
|
|
151
|
+
|
|
152
|
+
const { set: setPreference } = useDispatch( preferencesStore );
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Sets the open/closed state of the Advanced Settings Drawer,
|
|
156
|
+
* optionlly persisting the state to the user's preferences.
|
|
157
|
+
*
|
|
158
|
+
* Note that Block Editor components can be consumed by non-WordPress
|
|
159
|
+
* environments which may not have preferences setup.
|
|
160
|
+
* Therefore a local state is also used as a fallback.
|
|
161
|
+
*
|
|
162
|
+
* @param {boolean} prefVal the open/closed state of the Advanced Settings Drawer.
|
|
163
|
+
*/
|
|
164
|
+
const setSettingsOpenWithPreference = ( prefVal ) => {
|
|
165
|
+
if ( setPreference ) {
|
|
166
|
+
setPreference( PREFERENCE_SCOPE, PREFERENCE_KEY, prefVal );
|
|
167
|
+
}
|
|
168
|
+
setSettingsOpen( prefVal );
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// Block Editor components can be consumed by non-WordPress environments
|
|
172
|
+
// which may not have these preferences setup.
|
|
173
|
+
// Therefore a local state is used as a fallback.
|
|
174
|
+
const isSettingsOpen = advancedSettingsPreference || settingsOpen;
|
|
175
|
+
|
|
136
176
|
const isMounting = useRef( true );
|
|
137
177
|
const wrapperNode = useRef();
|
|
138
178
|
const textInputRef = useRef();
|
|
@@ -140,8 +180,6 @@ function LinkControl( {
|
|
|
140
180
|
|
|
141
181
|
const settingsKeys = settings.map( ( { id } ) => id );
|
|
142
182
|
|
|
143
|
-
const [ settingsOpen, setSettingsOpen ] = useState( false );
|
|
144
|
-
|
|
145
183
|
const [
|
|
146
184
|
internalControlValue,
|
|
147
185
|
setInternalControlValue,
|
|
@@ -207,7 +245,6 @@ function LinkControl( {
|
|
|
207
245
|
wrapperNode.current.ownerDocument.activeElement
|
|
208
246
|
);
|
|
209
247
|
|
|
210
|
-
setSettingsOpen( false );
|
|
211
248
|
setIsEditingLink( false );
|
|
212
249
|
};
|
|
213
250
|
|
|
@@ -292,7 +329,6 @@ function LinkControl( {
|
|
|
292
329
|
const shownUnlinkControl =
|
|
293
330
|
onRemove && value && ! isEditingLink && ! isCreatingPage;
|
|
294
331
|
|
|
295
|
-
const showSettings = !! settings?.length && isEditingLink && hasLinkValue;
|
|
296
332
|
const showActions = isEditingLink && hasLinkValue;
|
|
297
333
|
|
|
298
334
|
// Only show text control once a URL value has been committed
|
|
@@ -302,6 +338,7 @@ function LinkControl( {
|
|
|
302
338
|
|
|
303
339
|
const isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;
|
|
304
340
|
const isDisabled = ! valueHasChanges || currentInputIsEmpty;
|
|
341
|
+
const showSettings = !! settings?.length && isEditingLink && hasLinkValue;
|
|
305
342
|
|
|
306
343
|
return (
|
|
307
344
|
<div
|
|
@@ -382,8 +419,8 @@ function LinkControl( {
|
|
|
382
419
|
<div className="block-editor-link-control__tools">
|
|
383
420
|
{ ! currentInputIsEmpty && (
|
|
384
421
|
<LinkControlSettingsDrawer
|
|
385
|
-
settingsOpen={
|
|
386
|
-
setSettingsOpen={
|
|
422
|
+
settingsOpen={ isSettingsOpen }
|
|
423
|
+
setSettingsOpen={ setSettingsOpenWithPreference }
|
|
387
424
|
>
|
|
388
425
|
<LinkSettings
|
|
389
426
|
value={ internalControlValue }
|
|
@@ -1708,7 +1708,7 @@ describe( 'Selecting links', () => {
|
|
|
1708
1708
|
} );
|
|
1709
1709
|
|
|
1710
1710
|
describe( 'Addition Settings UI', () => {
|
|
1711
|
-
it( 'should
|
|
1711
|
+
it( 'should hide advanced link settings when not editing a link', async () => {
|
|
1712
1712
|
const selectedLink = fauxEntitySuggestions[ 0 ];
|
|
1713
1713
|
|
|
1714
1714
|
const LinkControlConsumer = () => {
|
|
@@ -1723,6 +1723,7 @@ describe( 'Addition Settings UI', () => {
|
|
|
1723
1723
|
|
|
1724
1724
|
expect( settingsToggle ).not.toBeInTheDocument();
|
|
1725
1725
|
} );
|
|
1726
|
+
|
|
1726
1727
|
it( 'should provides a means to toggle the link settings', async () => {
|
|
1727
1728
|
const selectedLink = fauxEntitySuggestions[ 0 ];
|
|
1728
1729
|
|
|
@@ -66,21 +66,21 @@ export function useFormatTypes( {
|
|
|
66
66
|
} ) {
|
|
67
67
|
const allFormatTypes = useSelect( formatTypesSelector, [] );
|
|
68
68
|
const formatTypes = useMemo( () => {
|
|
69
|
-
return allFormatTypes.filter( ( { name, tagName } ) => {
|
|
69
|
+
return allFormatTypes.filter( ( { name, interactive, tagName } ) => {
|
|
70
70
|
if ( allowedFormats && ! allowedFormats.includes( name ) ) {
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
if (
|
|
75
75
|
withoutInteractiveFormatting &&
|
|
76
|
-
interactiveContentTags.has( tagName )
|
|
76
|
+
( interactive || interactiveContentTags.has( tagName ) )
|
|
77
77
|
) {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return true;
|
|
82
82
|
} );
|
|
83
|
-
}, [ allFormatTypes, allowedFormats,
|
|
83
|
+
}, [ allFormatTypes, allowedFormats, withoutInteractiveFormatting ] );
|
|
84
84
|
const keyedSelected = useSelect(
|
|
85
85
|
( select ) =>
|
|
86
86
|
formatTypes.reduce( ( accumulator, type ) => {
|