@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/CHANGELOG.md +6 -0
- package/build/code/index.js +6 -2
- package/build/code/index.js.map +1 -1
- package/build/link/index.native.js.map +1 -1
- package/build/link/utils.js +35 -16
- package/build/link/utils.js.map +1 -1
- package/build/strikethrough/index.js +6 -2
- package/build/strikethrough/index.js.map +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.native.js +10 -13
- package/build/text-color/inline.native.js.map +1 -1
- package/build-module/code/index.js +8 -4
- package/build-module/code/index.js.map +1 -1
- package/build-module/link/index.native.js.map +1 -1
- package/build-module/link/utils.js +33 -13
- package/build-module/link/utils.js.map +1 -1
- package/build-module/strikethrough/index.js +8 -4
- package/build-module/strikethrough/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.native.js +10 -12
- package/build-module/text-color/inline.native.js.map +1 -1
- package/package.json +13 -13
- package/src/code/index.js +18 -8
- package/src/link/index.native.js +2 -3
- package/src/link/utils.js +16 -16
- package/src/strikethrough/index.js +18 -8
- package/src/text-color/index.js +8 -6
- package/src/text-color/index.native.js +8 -6
- package/src/text-color/inline.native.js +3 -7
- package/src/text-color/test/index.native.js +2 -5
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(
|
|
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(
|
|
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 =
|
|
150
|
-
type
|
|
151
|
-
|
|
144
|
+
const formatAtStart = newFormats[ startIndex ]?.find(
|
|
145
|
+
( { type } ) => type === format.type
|
|
146
|
+
);
|
|
152
147
|
|
|
153
|
-
const formatAtEnd =
|
|
154
|
-
type
|
|
155
|
-
|
|
148
|
+
const formatAtEnd = newFormats[ endIndex ]?.find(
|
|
149
|
+
( { type } ) => type === format.type
|
|
150
|
+
);
|
|
156
151
|
|
|
157
|
-
const formatAtEndMinusOne =
|
|
158
|
-
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 {
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
};
|
package/src/text-color/index.js
CHANGED
|
@@ -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(
|
|
69
|
-
setIsAddingColor,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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(
|
|
76
|
-
setIsAddingColor,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
...
|
|
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
|
-
|
|
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( () =>
|