@wordpress/format-library 4.32.0 → 4.33.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/bold/index.js.map +1 -1
- package/build/code/index.js.map +1 -1
- package/build/default-formats.js.map +1 -1
- package/build/default-formats.native.js.map +1 -1
- package/build/image/index.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/italic/index.js.map +1 -1
- package/build/keyboard/index.js.map +1 -1
- package/build/language/index.js.map +1 -1
- package/build/link/index.js +23 -42
- package/build/link/index.js.map +1 -1
- package/build/link/index.native.js.map +1 -1
- package/build/link/inline.js +2 -1
- package/build/link/inline.js.map +1 -1
- package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build/link/modal-screens/screens.native.js.map +1 -1
- package/build/link/modal.native.js.map +1 -1
- package/build/link/use-link-instance-key.js.map +1 -1
- package/build/link/utils.js.map +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/non-breaking-space/index.js.map +1 -1
- package/build/strikethrough/index.js.map +1 -1
- package/build/subscript/index.js.map +1 -1
- package/build/superscript/index.js.map +1 -1
- package/build/text-color/index.js +1 -1
- package/build/text-color/index.js.map +1 -1
- package/build/text-color/index.native.js.map +1 -1
- package/build/text-color/inline.js.map +1 -1
- package/build/text-color/inline.native.js.map +1 -1
- package/build/underline/index.js.map +1 -1
- package/build/unknown/index.js.map +1 -1
- package/build-module/bold/index.js.map +1 -1
- package/build-module/code/index.js.map +1 -1
- package/build-module/default-formats.js.map +1 -1
- package/build-module/default-formats.native.js.map +1 -1
- package/build-module/image/index.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/italic/index.js.map +1 -1
- package/build-module/keyboard/index.js.map +1 -1
- package/build-module/language/index.js.map +1 -1
- package/build-module/link/index.js +23 -42
- package/build-module/link/index.js.map +1 -1
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/inline.js +2 -1
- package/build-module/link/inline.js.map +1 -1
- package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
- package/build-module/link/modal-screens/screens.native.js.map +1 -1
- package/build-module/link/modal.native.js.map +1 -1
- package/build-module/link/use-link-instance-key.js.map +1 -1
- package/build-module/link/utils.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/non-breaking-space/index.js.map +1 -1
- package/build-module/strikethrough/index.js.map +1 -1
- package/build-module/subscript/index.js.map +1 -1
- package/build-module/superscript/index.js.map +1 -1
- package/build-module/text-color/index.js.map +1 -1
- package/build-module/text-color/index.native.js.map +1 -1
- package/build-module/text-color/inline.js.map +1 -1
- package/build-module/text-color/inline.native.js.map +1 -1
- package/build-module/underline/index.js.map +1 -1
- package/build-module/unknown/index.js.map +1 -1
- package/build-style/style-rtl.css +1 -1
- package/build-style/style.css +1 -1
- package/package.json +14 -14
- package/src/link/index.js +25 -41
- package/src/link/inline.js +2 -1
package/src/link/index.js
CHANGED
|
@@ -38,36 +38,17 @@ function Edit( {
|
|
|
38
38
|
onFocus,
|
|
39
39
|
contentRef,
|
|
40
40
|
} ) {
|
|
41
|
-
const [
|
|
42
|
-
const [ creatingLink, setCreatingLink ] = useState( false );
|
|
41
|
+
const [ addingLink, setAddingLink ] = useState( false );
|
|
43
42
|
|
|
44
43
|
// We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.
|
|
45
44
|
const [ openedBy, setOpenedBy ] = useState( null );
|
|
46
45
|
|
|
47
|
-
// Manages whether the Link UI popover should autofocus when shown.
|
|
48
|
-
const [ shouldAutoFocus, setShouldAutoFocus ] = useState( true );
|
|
49
|
-
|
|
50
|
-
function setIsEditingLink( isEditing, { autoFocus = true } = {} ) {
|
|
51
|
-
setEditingLink( isEditing );
|
|
52
|
-
setShouldAutoFocus( autoFocus );
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setIsCreatingLink( isCreating ) {
|
|
56
|
-
// Don't add a new link if there is already an active link.
|
|
57
|
-
// The two states are mutually exclusive.
|
|
58
|
-
if ( isCreating === true && isActive ) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
setCreatingLink( isCreating );
|
|
62
|
-
}
|
|
63
|
-
|
|
64
46
|
useEffect( () => {
|
|
65
47
|
// When the link becomes inactive (i.e. isActive is false), reset the editingLink state
|
|
66
48
|
// and the creatingLink state. This means that if the Link UI is displayed and the link
|
|
67
49
|
// becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.
|
|
68
50
|
if ( ! isActive ) {
|
|
69
|
-
|
|
70
|
-
setCreatingLink( false );
|
|
51
|
+
setAddingLink( false );
|
|
71
52
|
}
|
|
72
53
|
}, [ isActive ] );
|
|
73
54
|
|
|
@@ -84,15 +65,19 @@ function Edit( {
|
|
|
84
65
|
// This causes the `editingLink` state to be set to `true` and the link UI
|
|
85
66
|
// to be rendered in "creating" mode. We need to check isActive to see if
|
|
86
67
|
// we have an active link format.
|
|
68
|
+
const link = event.target.closest( '[contenteditable] a' );
|
|
87
69
|
if (
|
|
88
|
-
!
|
|
70
|
+
! link || // other formats (e.g. bold) may be nested within the link.
|
|
89
71
|
! isActive
|
|
90
72
|
) {
|
|
91
|
-
setIsEditingLink( false );
|
|
92
73
|
return;
|
|
93
74
|
}
|
|
94
75
|
|
|
95
|
-
|
|
76
|
+
setAddingLink( true );
|
|
77
|
+
setOpenedBy( {
|
|
78
|
+
el: link,
|
|
79
|
+
action: 'click',
|
|
80
|
+
} );
|
|
96
81
|
}
|
|
97
82
|
|
|
98
83
|
editableContentElement.addEventListener( 'click', handleClick );
|
|
@@ -103,7 +88,6 @@ function Edit( {
|
|
|
103
88
|
}, [ contentRef, isActive ] );
|
|
104
89
|
|
|
105
90
|
function addLink( target ) {
|
|
106
|
-
setShouldAutoFocus( true );
|
|
107
91
|
const text = getTextContent( slice( value ) );
|
|
108
92
|
|
|
109
93
|
if ( ! isActive && text && isURL( text ) && isValidHref( text ) ) {
|
|
@@ -122,13 +106,12 @@ function Edit( {
|
|
|
122
106
|
);
|
|
123
107
|
} else {
|
|
124
108
|
if ( target ) {
|
|
125
|
-
setOpenedBy(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} else {
|
|
130
|
-
setIsEditingLink( true );
|
|
109
|
+
setOpenedBy( {
|
|
110
|
+
el: target,
|
|
111
|
+
action: null, // We don't need to distinguish between click or keyboard here
|
|
112
|
+
} );
|
|
131
113
|
}
|
|
114
|
+
setAddingLink( true );
|
|
132
115
|
}
|
|
133
116
|
}
|
|
134
117
|
|
|
@@ -147,12 +130,11 @@ function Edit( {
|
|
|
147
130
|
// Otherwise, we rely on the passed in onFocus to return focus to the rich text field.
|
|
148
131
|
|
|
149
132
|
// Close the popover
|
|
150
|
-
|
|
151
|
-
setIsCreatingLink( false );
|
|
133
|
+
setAddingLink( false );
|
|
152
134
|
|
|
153
135
|
// Return focus to the toolbar button or the rich text field
|
|
154
|
-
if ( openedBy?.tagName === 'BUTTON' ) {
|
|
155
|
-
openedBy.focus();
|
|
136
|
+
if ( openedBy?.el?.tagName === 'BUTTON' ) {
|
|
137
|
+
openedBy.el.focus();
|
|
156
138
|
} else {
|
|
157
139
|
onFocus();
|
|
158
140
|
}
|
|
@@ -167,8 +149,7 @@ function Edit( {
|
|
|
167
149
|
// 4. Press Escape
|
|
168
150
|
// 5. Focus should be on the Options button
|
|
169
151
|
function onFocusOutside() {
|
|
170
|
-
|
|
171
|
-
setIsCreatingLink( false );
|
|
152
|
+
setAddingLink( false );
|
|
172
153
|
setOpenedBy( null );
|
|
173
154
|
}
|
|
174
155
|
|
|
@@ -177,7 +158,10 @@ function Edit( {
|
|
|
177
158
|
speak( __( 'Link removed.' ), 'assertive' );
|
|
178
159
|
}
|
|
179
160
|
|
|
180
|
-
|
|
161
|
+
// Only autofocus if we have clicked a link within the editor
|
|
162
|
+
const shouldAutoFocus = ! (
|
|
163
|
+
openedBy?.el?.tagName === 'A' && openedBy?.action === 'click'
|
|
164
|
+
);
|
|
181
165
|
|
|
182
166
|
return (
|
|
183
167
|
<>
|
|
@@ -194,13 +178,13 @@ function Edit( {
|
|
|
194
178
|
onClick={ ( event ) => {
|
|
195
179
|
addLink( event.currentTarget );
|
|
196
180
|
} }
|
|
197
|
-
isActive={ isActive ||
|
|
181
|
+
isActive={ isActive || addingLink }
|
|
198
182
|
shortcutType="primary"
|
|
199
183
|
shortcutCharacter="k"
|
|
200
184
|
aria-haspopup="true"
|
|
201
|
-
aria-expanded={
|
|
185
|
+
aria-expanded={ addingLink }
|
|
202
186
|
/>
|
|
203
|
-
{
|
|
187
|
+
{ addingLink && (
|
|
204
188
|
<InlineLinkUI
|
|
205
189
|
stopAddingLink={ stopAddingLink }
|
|
206
190
|
onFocusOutside={ onFocusOutside }
|
package/src/link/inline.js
CHANGED
|
@@ -252,10 +252,11 @@ function InlineLinkUI( {
|
|
|
252
252
|
return (
|
|
253
253
|
<Popover
|
|
254
254
|
anchor={ popoverAnchor }
|
|
255
|
+
animate={ false }
|
|
255
256
|
onClose={ stopAddingLink }
|
|
256
257
|
onFocusOutside={ onFocusOutside }
|
|
257
258
|
placement="bottom"
|
|
258
|
-
offset={
|
|
259
|
+
offset={ 8 }
|
|
259
260
|
shift
|
|
260
261
|
focusOnMount={ focusOnMount }
|
|
261
262
|
constrainTabbing
|