@wordpress/format-library 4.32.0 → 4.34.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/bold/index.js.map +1 -1
  3. package/build/code/index.js.map +1 -1
  4. package/build/default-formats.js.map +1 -1
  5. package/build/default-formats.native.js.map +1 -1
  6. package/build/image/index.js.map +1 -1
  7. package/build/index.js.map +1 -1
  8. package/build/italic/index.js.map +1 -1
  9. package/build/keyboard/index.js.map +1 -1
  10. package/build/language/index.js.map +1 -1
  11. package/build/link/index.js +23 -42
  12. package/build/link/index.js.map +1 -1
  13. package/build/link/index.native.js.map +1 -1
  14. package/build/link/inline.js +2 -1
  15. package/build/link/inline.js.map +1 -1
  16. package/build/link/modal-screens/link-picker-screen.native.js.map +1 -1
  17. package/build/link/modal-screens/link-settings-screen.native.js.map +1 -1
  18. package/build/link/modal-screens/screens.native.js.map +1 -1
  19. package/build/link/modal.native.js.map +1 -1
  20. package/build/link/use-link-instance-key.js.map +1 -1
  21. package/build/link/utils.js +6 -2
  22. package/build/link/utils.js.map +1 -1
  23. package/build/lock-unlock.js.map +1 -1
  24. package/build/non-breaking-space/index.js.map +1 -1
  25. package/build/strikethrough/index.js.map +1 -1
  26. package/build/subscript/index.js.map +1 -1
  27. package/build/superscript/index.js.map +1 -1
  28. package/build/text-color/index.js +1 -1
  29. package/build/text-color/index.js.map +1 -1
  30. package/build/text-color/index.native.js.map +1 -1
  31. package/build/text-color/inline.js +12 -4
  32. package/build/text-color/inline.js.map +1 -1
  33. package/build/text-color/inline.native.js +12 -4
  34. package/build/text-color/inline.native.js.map +1 -1
  35. package/build/underline/index.js.map +1 -1
  36. package/build/unknown/index.js.map +1 -1
  37. package/build-module/bold/index.js.map +1 -1
  38. package/build-module/code/index.js.map +1 -1
  39. package/build-module/default-formats.js.map +1 -1
  40. package/build-module/default-formats.native.js.map +1 -1
  41. package/build-module/image/index.js.map +1 -1
  42. package/build-module/index.js.map +1 -1
  43. package/build-module/italic/index.js.map +1 -1
  44. package/build-module/keyboard/index.js.map +1 -1
  45. package/build-module/language/index.js.map +1 -1
  46. package/build-module/link/index.js +23 -42
  47. package/build-module/link/index.js.map +1 -1
  48. package/build-module/link/index.native.js.map +1 -1
  49. package/build-module/link/inline.js +2 -1
  50. package/build-module/link/inline.js.map +1 -1
  51. package/build-module/link/modal-screens/link-picker-screen.native.js.map +1 -1
  52. package/build-module/link/modal-screens/link-settings-screen.native.js.map +1 -1
  53. package/build-module/link/modal-screens/screens.native.js.map +1 -1
  54. package/build-module/link/modal.native.js.map +1 -1
  55. package/build-module/link/use-link-instance-key.js.map +1 -1
  56. package/build-module/link/utils.js +6 -2
  57. package/build-module/link/utils.js.map +1 -1
  58. package/build-module/lock-unlock.js.map +1 -1
  59. package/build-module/non-breaking-space/index.js.map +1 -1
  60. package/build-module/strikethrough/index.js.map +1 -1
  61. package/build-module/subscript/index.js.map +1 -1
  62. package/build-module/superscript/index.js.map +1 -1
  63. package/build-module/text-color/index.js.map +1 -1
  64. package/build-module/text-color/index.native.js.map +1 -1
  65. package/build-module/text-color/inline.js +12 -4
  66. package/build-module/text-color/inline.js.map +1 -1
  67. package/build-module/text-color/inline.native.js +12 -4
  68. package/build-module/text-color/inline.native.js.map +1 -1
  69. package/build-module/underline/index.js.map +1 -1
  70. package/build-module/unknown/index.js.map +1 -1
  71. package/build-style/style-rtl.css +1 -1
  72. package/build-style/style.css +1 -1
  73. package/package.json +14 -14
  74. package/src/link/index.js +25 -41
  75. package/src/link/inline.js +2 -1
  76. package/src/link/utils.js +6 -2
  77. package/src/text-color/inline.js +14 -4
  78. package/src/text-color/inline.native.js +14 -4
@@ -96,7 +96,7 @@
96
96
  --wp-admin-border-width-focus: 2px;
97
97
  --wp-block-synced-color: #7a00df;
98
98
  --wp-block-synced-color--rgb: 122, 0, 223;
99
- --wp-bound-block-color: #9747ff;
99
+ --wp-bound-block-color: var(--wp-block-synced-color);
100
100
  }
101
101
  @media (min-resolution: 192dpi) {
102
102
  :root {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/format-library",
3
- "version": "4.32.0",
3
+ "version": "4.34.0",
4
4
  "description": "Format library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,18 +26,18 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.55.0",
30
- "@wordpress/block-editor": "^12.23.0",
31
- "@wordpress/components": "^27.3.0",
32
- "@wordpress/compose": "^6.32.0",
33
- "@wordpress/data": "^9.25.0",
34
- "@wordpress/element": "^5.32.0",
35
- "@wordpress/html-entities": "^3.55.0",
36
- "@wordpress/i18n": "^4.55.0",
37
- "@wordpress/icons": "^9.46.0",
38
- "@wordpress/private-apis": "^0.37.0",
39
- "@wordpress/rich-text": "^6.32.0",
40
- "@wordpress/url": "^3.56.0"
29
+ "@wordpress/a11y": "^3.57.0",
30
+ "@wordpress/block-editor": "^12.25.0",
31
+ "@wordpress/components": "^27.5.0",
32
+ "@wordpress/compose": "^6.34.0",
33
+ "@wordpress/data": "^9.27.0",
34
+ "@wordpress/element": "^5.34.0",
35
+ "@wordpress/html-entities": "^3.57.0",
36
+ "@wordpress/i18n": "^4.57.0",
37
+ "@wordpress/icons": "^9.48.0",
38
+ "@wordpress/private-apis": "^0.39.0",
39
+ "@wordpress/rich-text": "^6.34.0",
40
+ "@wordpress/url": "^3.58.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": "^18.0.0",
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "ac2b13783c28f959770cf029a797a712f59e1958"
49
+ "gitHead": "581d8a5580dba8f600b7268d51eb554771ae482c"
50
50
  }
package/src/link/index.js CHANGED
@@ -38,36 +38,17 @@ function Edit( {
38
38
  onFocus,
39
39
  contentRef,
40
40
  } ) {
41
- const [ editingLink, setEditingLink ] = useState( false );
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
- setEditingLink( false );
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
- ! event.target.closest( '[contenteditable] a' ) || // other formats (e.g. bold) may be nested within the link.
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
- setIsEditingLink( true, { autoFocus: false } );
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( target );
126
- }
127
- if ( ! isActive ) {
128
- setIsCreatingLink( true );
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
- setIsEditingLink( false );
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
- setIsEditingLink( false );
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
- const isEditingActiveLink = editingLink && isActive;
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 || editingLink }
181
+ isActive={ isActive || addingLink }
198
182
  shortcutType="primary"
199
183
  shortcutCharacter="k"
200
184
  aria-haspopup="true"
201
- aria-expanded={ editingLink }
185
+ aria-expanded={ addingLink }
202
186
  />
203
- { ( isEditingActiveLink || creatingLink ) && (
187
+ { addingLink && (
204
188
  <InlineLinkUI
205
189
  stopAddingLink={ stopAddingLink }
206
190
  onFocusOutside={ onFocusOutside }
@@ -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={ 10 }
259
+ offset={ 8 }
259
260
  shift
260
261
  focusOnMount={ focusOnMount }
261
262
  constrainTabbing
package/src/link/utils.js CHANGED
@@ -102,8 +102,12 @@ export function createLinkFormat( {
102
102
  },
103
103
  };
104
104
 
105
- if ( type ) format.attributes.type = type;
106
- if ( id ) format.attributes.id = id;
105
+ if ( type ) {
106
+ format.attributes.type = type;
107
+ }
108
+ if ( id ) {
109
+ format.attributes.id = id;
110
+ }
107
111
 
108
112
  if ( opensInNewWindow ) {
109
113
  format.attributes.target = '_blank';
@@ -39,9 +39,15 @@ function parseCSS( css = '' ) {
39
39
  return css.split( ';' ).reduce( ( accumulator, rule ) => {
40
40
  if ( rule ) {
41
41
  const [ property, value ] = rule.split( ':' );
42
- if ( property === 'color' ) accumulator.color = value;
43
- if ( property === 'background-color' && value !== transparentValue )
42
+ if ( property === 'color' ) {
43
+ accumulator.color = value;
44
+ }
45
+ if (
46
+ property === 'background-color' &&
47
+ value !== transparentValue
48
+ ) {
44
49
  accumulator.backgroundColor = value;
50
+ }
45
51
  }
46
52
  return accumulator;
47
53
  }, {} );
@@ -108,8 +114,12 @@ function setColors( value, name, colorSettings, colors ) {
108
114
  }
109
115
  }
110
116
 
111
- if ( styles.length ) attributes.style = styles.join( ';' );
112
- if ( classNames.length ) attributes.class = classNames.join( ' ' );
117
+ if ( styles.length ) {
118
+ attributes.style = styles.join( ';' );
119
+ }
120
+ if ( classNames.length ) {
121
+ attributes.class = classNames.join( ' ' );
122
+ }
113
123
 
114
124
  return applyFormat( value, { type: name, attributes } );
115
125
  }
@@ -28,9 +28,15 @@ function parseCSS( css = '' ) {
28
28
  return css.split( ';' ).reduce( ( accumulator, rule ) => {
29
29
  if ( rule ) {
30
30
  const [ property, value ] = rule.replace( / /g, '' ).split( ':' );
31
- if ( property === 'color' ) accumulator.color = value;
32
- if ( property === 'background-color' && value !== transparentValue )
31
+ if ( property === 'color' ) {
32
+ accumulator.color = value;
33
+ }
34
+ if (
35
+ property === 'background-color' &&
36
+ value !== transparentValue
37
+ ) {
33
38
  accumulator.backgroundColor = value;
39
+ }
34
40
  }
35
41
  return accumulator;
36
42
  }, {} );
@@ -82,8 +88,12 @@ function setColors( value, name, colorSettings, colors, contentRef ) {
82
88
  }
83
89
  }
84
90
 
85
- if ( styles.length ) attributes.style = styles.join( ';' );
86
- if ( classNames.length ) attributes.class = classNames.join( ' ' );
91
+ if ( styles.length ) {
92
+ attributes.style = styles.join( ';' );
93
+ }
94
+ if ( classNames.length ) {
95
+ attributes.class = classNames.join( ' ' );
96
+ }
87
97
 
88
98
  const format = { type: name, attributes };
89
99
  const hasNoSelection = value.start === value.end;