@wordpress/format-library 3.8.0 → 3.11.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/src/link/utils.js CHANGED
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { startsWith, find, partialRight } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -47,7 +42,7 @@ export function isValidHref( href ) {
47
42
  // Add some extra checks for http(s) URIs, since these are the most common use-case.
48
43
  // This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
49
44
  if (
50
- startsWith( protocol, 'http' ) &&
45
+ protocol.startsWith( 'http' ) &&
51
46
  ! /^https?:\/\/[^\/\s]/i.test( trimmedHref )
52
47
  ) {
53
48
  return false;
@@ -75,7 +70,7 @@ export function isValidHref( href ) {
75
70
  }
76
71
 
77
72
  // Validate anchor links.
78
- if ( startsWith( trimmedHref, '#' ) && ! isValidFragment( trimmedHref ) ) {
73
+ if ( trimmedHref.startsWith( '#' ) && ! isValidFragment( trimmedHref ) ) {
79
74
  return false;
80
75
  }
81
76
 
@@ -146,17 +141,17 @@ export function getFormatBoundary(
146
141
  // Clone formats to avoid modifying source formats.
147
142
  const newFormats = formats.slice();
148
143
 
149
- const formatAtStart = find( newFormats[ startIndex ], {
150
- type: format.type,
151
- } );
144
+ const formatAtStart = newFormats[ startIndex ]?.find(
145
+ ( { type } ) => type === format.type
146
+ );
152
147
 
153
- const formatAtEnd = find( newFormats[ endIndex ], {
154
- type: format.type,
155
- } );
148
+ const formatAtEnd = newFormats[ endIndex ]?.find(
149
+ ( { type } ) => type === format.type
150
+ );
156
151
 
157
- const formatAtEndMinusOne = find( newFormats[ endIndex - 1 ], {
158
- type: format.type,
159
- } );
152
+ const formatAtEndMinusOne = newFormats[ endIndex - 1 ]?.find(
153
+ ( { type } ) => type === format.type
154
+ );
160
155
 
161
156
  if ( !! formatAtStart ) {
162
157
  // Set values to conform to "start"
@@ -239,6 +234,11 @@ function walkToBoundary(
239
234
  return index;
240
235
  }
241
236
 
237
+ const partialRight =
238
+ ( fn, ...partialArgs ) =>
239
+ ( ...args ) =>
240
+ fn( ...args, ...partialArgs );
241
+
242
242
  const walkToStart = partialRight( walkToBoundary, 'backwards' );
243
243
 
244
244
  const walkToEnd = partialRight( walkToBoundary, 'forwards' );
@@ -3,7 +3,10 @@
3
3
  */
4
4
  import { __ } from '@wordpress/i18n';
5
5
  import { toggleFormat } from '@wordpress/rich-text';
6
- import { RichTextToolbarButton } from '@wordpress/block-editor';
6
+ import {
7
+ RichTextToolbarButton,
8
+ RichTextShortcut,
9
+ } from '@wordpress/block-editor';
7
10
  import { formatStrikethrough } from '@wordpress/icons';
8
11
 
9
12
  const name = 'core/strikethrough';
@@ -21,13 +24,20 @@ export const strikethrough = {
21
24
  }
22
25
 
23
26
  return (
24
- <RichTextToolbarButton
25
- icon={ formatStrikethrough }
26
- title={ title }
27
- onClick={ onClick }
28
- isActive={ isActive }
29
- role="menuitemcheckbox"
30
- />
27
+ <>
28
+ <RichTextShortcut
29
+ type="access"
30
+ character="d"
31
+ onUse={ onClick }
32
+ />
33
+ <RichTextToolbarButton
34
+ icon={ formatStrikethrough }
35
+ title={ title }
36
+ onClick={ onClick }
37
+ isActive={ isActive }
38
+ role="menuitemcheckbox"
39
+ />
40
+ </>
31
41
  );
32
42
  },
33
43
  };
@@ -65,12 +65,14 @@ function TextColorEdit( {
65
65
  const allowCustomControl = useSetting( 'color.custom' );
66
66
  const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
67
67
  const [ isAddingColor, setIsAddingColor ] = useState( false );
68
- const enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [
69
- setIsAddingColor,
70
- ] );
71
- const disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [
72
- setIsAddingColor,
73
- ] );
68
+ const enableIsAddingColor = useCallback(
69
+ () => setIsAddingColor( true ),
70
+ [ setIsAddingColor ]
71
+ );
72
+ const disableIsAddingColor = useCallback(
73
+ () => setIsAddingColor( false ),
74
+ [ setIsAddingColor ]
75
+ );
74
76
  const colorIndicatorStyle = useMemo(
75
77
  () =>
76
78
  fillComputedColors(
@@ -72,12 +72,14 @@ function TextColorEdit( {
72
72
  const allowCustomControl = useSetting( 'color.custom' );
73
73
  const colors = useMobileGlobalStylesColors();
74
74
  const [ isAddingColor, setIsAddingColor ] = useState( false );
75
- const enableIsAddingColor = useCallback( () => setIsAddingColor( true ), [
76
- setIsAddingColor,
77
- ] );
78
- const disableIsAddingColor = useCallback( () => setIsAddingColor( false ), [
79
- setIsAddingColor,
80
- ] );
75
+ const enableIsAddingColor = useCallback(
76
+ () => setIsAddingColor( true ),
77
+ [ setIsAddingColor ]
78
+ );
79
+ const disableIsAddingColor = useCallback(
80
+ () => setIsAddingColor( false ),
81
+ [ setIsAddingColor ]
82
+ );
81
83
  const colorIndicatorStyle = useMemo(
82
84
  () =>
83
85
  fillComputedColors(
@@ -1,9 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- import { reject } from 'lodash';
6
-
7
1
  /**
8
2
  * WordPress dependencies
9
3
  */
@@ -110,7 +104,9 @@ function setColors( value, name, colorSettings, colors ) {
110
104
  const newFormat = applyFormat( value, format );
111
105
  const { activeFormats } = newFormat;
112
106
  newFormat.formats[ value.start ] = [
113
- ...reject( activeFormats, { type: format.type } ),
107
+ ...( activeFormats?.filter(
108
+ ( { type } ) => type !== format.type
109
+ ) || [] ),
114
110
  format,
115
111
  ];
116
112
  return newFormat;
@@ -55,11 +55,8 @@ describe( 'Text color', () => {
55
55
  } );
56
56
 
57
57
  it( 'allows toggling the highlight color feature to type new text', async () => {
58
- const {
59
- getByA11yLabel,
60
- getByTestId,
61
- getByA11yHint,
62
- } = await initializeEditor();
58
+ const { getByA11yLabel, getByTestId, getByA11yHint } =
59
+ await initializeEditor();
63
60
 
64
61
  // Wait for the editor placeholder
65
62
  const paragraphPlaceholder = await waitFor( () =>