@wordpress/format-library 5.47.0 → 5.48.1
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 +4 -0
- package/build/image/index.cjs +5 -3
- package/build/image/index.cjs.map +3 -3
- package/build/language/index.cjs +6 -4
- package/build/language/index.cjs.map +3 -3
- package/build/link/css-classes-setting.cjs +1 -1
- package/build/link/css-classes-setting.cjs.map +3 -3
- package/build/math/index.cjs +2 -1
- package/build/math/index.cjs.map +3 -3
- package/build/text-color/inline.cjs +6 -7
- package/build/text-color/inline.cjs.map +3 -3
- package/build-module/image/index.mjs +5 -6
- package/build-module/image/index.mjs.map +2 -2
- package/build-module/language/index.mjs +7 -7
- package/build-module/language/index.mjs.map +2 -2
- package/build-module/link/css-classes-setting.mjs +3 -4
- package/build-module/link/css-classes-setting.mjs.map +2 -2
- package/build-module/math/index.mjs +2 -2
- package/build-module/math/index.mjs.map +2 -2
- package/build-module/text-color/inline.mjs +7 -11
- package/build-module/text-color/inline.mjs.map +2 -2
- package/package.json +24 -20
- package/src/image/index.js +8 -9
- package/src/language/index.js +8 -8
- package/src/link/css-classes-setting.js +3 -4
- package/src/math/index.js +3 -3
- package/src/text-color/inline.js +11 -16
- package/src/default-formats.native.js +0 -10
- package/src/link/index.native.js +0 -176
- package/src/link/modal-screens/link-picker-screen.native.js +0 -61
- package/src/link/modal-screens/link-settings-screen.native.js +0 -229
- package/src/link/modal-screens/screens.native.js +0 -4
- package/src/link/modal.native.js +0 -44
- package/src/link/modal.native.scss +0 -16
- package/src/link/test/__snapshots__/modal.native.js.snap +0 -553
- package/src/link/test/index.native.js +0 -145
- package/src/link/test/modal.native.js +0 -18
- package/src/text-color/index.native.js +0 -172
- package/src/text-color/inline.native.js +0 -169
- package/src/text-color/style.native.scss +0 -22
- package/src/text-color/test/__snapshots__/index.native.js.snap +0 -23
- package/src/text-color/test/index.native.js +0 -192
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import ModalLinkUI from '../modal';
|
|
5
|
-
/**
|
|
6
|
-
* External dependencies
|
|
7
|
-
*/
|
|
8
|
-
import { render } from 'test/helpers';
|
|
9
|
-
|
|
10
|
-
describe( 'LinksUI', () => {
|
|
11
|
-
it( 'LinksUI renders', () => {
|
|
12
|
-
const value = { text: '' }; // empty `RichTextValue`
|
|
13
|
-
const screen = render(
|
|
14
|
-
<ModalLinkUI isVisible value={ value } activeAttributes={ {} } />
|
|
15
|
-
);
|
|
16
|
-
expect( screen.toJSON() ).toMatchSnapshot();
|
|
17
|
-
} );
|
|
18
|
-
} );
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { StyleSheet, View } from 'react-native';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { __ } from '@wordpress/i18n';
|
|
10
|
-
import { useMemo, useState } from '@wordpress/element';
|
|
11
|
-
import {
|
|
12
|
-
BlockControls,
|
|
13
|
-
useSettings,
|
|
14
|
-
useMobileGlobalStylesColors,
|
|
15
|
-
} from '@wordpress/block-editor';
|
|
16
|
-
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
|
|
17
|
-
import {
|
|
18
|
-
Icon,
|
|
19
|
-
color as colorIcon,
|
|
20
|
-
textColor as textColorIcon,
|
|
21
|
-
} from '@wordpress/icons';
|
|
22
|
-
import { removeFormat } from '@wordpress/rich-text';
|
|
23
|
-
import { usePreferredColorSchemeStyle } from '@wordpress/compose';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Internal dependencies
|
|
27
|
-
*/
|
|
28
|
-
import { getActiveColors } from './inline.native.js';
|
|
29
|
-
import { default as InlineColorUI } from './inline';
|
|
30
|
-
import styles from './style.scss';
|
|
31
|
-
|
|
32
|
-
const name = 'core/text-color';
|
|
33
|
-
const title = __( 'Text color' );
|
|
34
|
-
|
|
35
|
-
function getComputedStyleProperty( element, property ) {
|
|
36
|
-
const style = element?.props?.style ?? {};
|
|
37
|
-
|
|
38
|
-
if ( property === 'background-color' ) {
|
|
39
|
-
const { backgroundColor, baseColors } = style;
|
|
40
|
-
|
|
41
|
-
if ( backgroundColor !== 'transparent' ) {
|
|
42
|
-
return backgroundColor;
|
|
43
|
-
} else if ( baseColors && baseColors?.color?.background ) {
|
|
44
|
-
return baseColors?.color?.background;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return 'transparent';
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function fillComputedColors( element, { color, backgroundColor } ) {
|
|
52
|
-
if ( ! color && ! backgroundColor ) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
color: color || getComputedStyleProperty( element, 'color' ),
|
|
58
|
-
backgroundColor: getComputedStyleProperty(
|
|
59
|
-
element,
|
|
60
|
-
'background-color'
|
|
61
|
-
),
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function TextColorEdit( {
|
|
66
|
-
value,
|
|
67
|
-
onChange,
|
|
68
|
-
isActive,
|
|
69
|
-
activeAttributes,
|
|
70
|
-
contentRef,
|
|
71
|
-
} ) {
|
|
72
|
-
const [ allowCustomControl ] = useSettings( 'color.custom' );
|
|
73
|
-
const colors = useMobileGlobalStylesColors();
|
|
74
|
-
const [ isAddingColor, setIsAddingColor ] = useState( false );
|
|
75
|
-
const colorIndicatorStyle = useMemo(
|
|
76
|
-
() =>
|
|
77
|
-
fillComputedColors(
|
|
78
|
-
contentRef,
|
|
79
|
-
getActiveColors( value, name, colors )
|
|
80
|
-
),
|
|
81
|
-
[ contentRef, value, colors ]
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const hasColorsToChoose = colors.length || ! allowCustomControl;
|
|
85
|
-
|
|
86
|
-
const outlineStyle = [
|
|
87
|
-
usePreferredColorSchemeStyle(
|
|
88
|
-
styles[ 'components-inline-color__outline' ],
|
|
89
|
-
styles[ 'components-inline-color__outline--dark' ]
|
|
90
|
-
),
|
|
91
|
-
{ borderWidth: StyleSheet.hairlineWidth },
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
if ( ! hasColorsToChoose && ! isActive ) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const isActiveStyle = {
|
|
99
|
-
...colorIndicatorStyle,
|
|
100
|
-
...( ! colorIndicatorStyle?.backgroundColor
|
|
101
|
-
? { backgroundColor: 'transparent' }
|
|
102
|
-
: {} ),
|
|
103
|
-
...styles[ 'components-inline-color--is-active' ],
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const customContainerStyles =
|
|
107
|
-
styles[ 'components-inline-color__button-container' ];
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<>
|
|
111
|
-
<BlockControls>
|
|
112
|
-
<ToolbarGroup>
|
|
113
|
-
{ isActive && (
|
|
114
|
-
<View style={ outlineStyle } pointerEvents="none" />
|
|
115
|
-
) }
|
|
116
|
-
|
|
117
|
-
<ToolbarButton
|
|
118
|
-
name="text-color"
|
|
119
|
-
isActive={ isActive }
|
|
120
|
-
icon={
|
|
121
|
-
<Icon
|
|
122
|
-
icon={
|
|
123
|
-
Object.keys( activeAttributes ).length
|
|
124
|
-
? textColorIcon
|
|
125
|
-
: colorIcon
|
|
126
|
-
}
|
|
127
|
-
style={
|
|
128
|
-
colorIndicatorStyle?.color && {
|
|
129
|
-
color: colorIndicatorStyle.color,
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/>
|
|
133
|
-
}
|
|
134
|
-
title={ title }
|
|
135
|
-
extraProps={ {
|
|
136
|
-
isActiveStyle,
|
|
137
|
-
customContainerStyles,
|
|
138
|
-
} }
|
|
139
|
-
// If has no colors to choose but a color is active remove the color onClick
|
|
140
|
-
onClick={
|
|
141
|
-
hasColorsToChoose
|
|
142
|
-
? () => setIsAddingColor( true )
|
|
143
|
-
: () => onChange( removeFormat( value, name ) )
|
|
144
|
-
}
|
|
145
|
-
/>
|
|
146
|
-
</ToolbarGroup>
|
|
147
|
-
</BlockControls>
|
|
148
|
-
{ isAddingColor && (
|
|
149
|
-
<InlineColorUI
|
|
150
|
-
name={ name }
|
|
151
|
-
onClose={ () => setIsAddingColor( false ) }
|
|
152
|
-
activeAttributes={ activeAttributes }
|
|
153
|
-
value={ value }
|
|
154
|
-
onChange={ onChange }
|
|
155
|
-
contentRef={ contentRef }
|
|
156
|
-
/>
|
|
157
|
-
) }
|
|
158
|
-
</>
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export const textColor = {
|
|
163
|
-
name,
|
|
164
|
-
title,
|
|
165
|
-
tagName: 'mark',
|
|
166
|
-
className: 'has-inline-color',
|
|
167
|
-
attributes: {
|
|
168
|
-
style: 'style',
|
|
169
|
-
class: 'class',
|
|
170
|
-
},
|
|
171
|
-
edit: TextColorEdit,
|
|
172
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useCallback, useMemo } from '@wordpress/element';
|
|
5
|
-
import {
|
|
6
|
-
applyFormat,
|
|
7
|
-
removeFormat,
|
|
8
|
-
getActiveFormat,
|
|
9
|
-
} from '@wordpress/rich-text';
|
|
10
|
-
import {
|
|
11
|
-
getColorClassName,
|
|
12
|
-
getColorObjectByColorValue,
|
|
13
|
-
useMultipleOriginColorsAndGradients,
|
|
14
|
-
useMobileGlobalStylesColors,
|
|
15
|
-
} from '@wordpress/block-editor';
|
|
16
|
-
import { BottomSheet, ColorSettings } from '@wordpress/components';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
import { transparentValue } from './index.js';
|
|
22
|
-
import { parseClassName } from './inline.js';
|
|
23
|
-
|
|
24
|
-
function parseCSS( css = '' ) {
|
|
25
|
-
return css.split( ';' ).reduce( ( accumulator, rule ) => {
|
|
26
|
-
if ( rule ) {
|
|
27
|
-
const [ property, value ] = rule.replace( / /g, '' ).split( ':' );
|
|
28
|
-
if ( property === 'color' ) {
|
|
29
|
-
accumulator.color = value;
|
|
30
|
-
}
|
|
31
|
-
if (
|
|
32
|
-
property === 'background-color' &&
|
|
33
|
-
value !== transparentValue
|
|
34
|
-
) {
|
|
35
|
-
accumulator.backgroundColor = value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return accumulator;
|
|
39
|
-
}, {} );
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function getActiveColors( value, name, colorSettings ) {
|
|
43
|
-
const activeColorFormat = getActiveFormat( value, name );
|
|
44
|
-
|
|
45
|
-
if ( ! activeColorFormat ) {
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
...parseCSS( activeColorFormat.attributes.style ),
|
|
51
|
-
...parseClassName( activeColorFormat.attributes.class, colorSettings ),
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function setColors( value, name, colorSettings, colors, contentRef ) {
|
|
56
|
-
const { color, backgroundColor } = {
|
|
57
|
-
...getActiveColors( value, name, colorSettings ),
|
|
58
|
-
...colors,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
if ( ! color ) {
|
|
62
|
-
contentRef?.onRemoveMarkFormatting();
|
|
63
|
-
return removeFormat( value, name );
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const styles = [];
|
|
67
|
-
const classNames = [];
|
|
68
|
-
const attributes = {};
|
|
69
|
-
|
|
70
|
-
if ( backgroundColor ) {
|
|
71
|
-
styles.push( [ 'background-color', backgroundColor ].join( ':' ) );
|
|
72
|
-
} else {
|
|
73
|
-
// Override default browser color for mark element.
|
|
74
|
-
styles.push( [ 'background-color', transparentValue ].join( ':' ) );
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if ( color ) {
|
|
78
|
-
const colorObject = getColorObjectByColorValue( colorSettings, color );
|
|
79
|
-
|
|
80
|
-
if ( colorObject ) {
|
|
81
|
-
classNames.push( getColorClassName( 'color', colorObject.slug ) );
|
|
82
|
-
styles.push( [ 'color', colorObject.color ].join( ':' ) );
|
|
83
|
-
} else {
|
|
84
|
-
styles.push( [ 'color', color ].join( ':' ) );
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if ( styles.length ) {
|
|
89
|
-
attributes.style = styles.join( ';' );
|
|
90
|
-
}
|
|
91
|
-
if ( classNames.length ) {
|
|
92
|
-
attributes.class = classNames.join( ' ' );
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const format = { type: name, attributes };
|
|
96
|
-
const hasNoSelection = value.start === value.end;
|
|
97
|
-
|
|
98
|
-
if ( hasNoSelection ) {
|
|
99
|
-
contentRef?.onMarkFormatting( color );
|
|
100
|
-
}
|
|
101
|
-
return applyFormat( value, format );
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function ColorPicker( { name, value, onChange, contentRef } ) {
|
|
105
|
-
const property = 'color';
|
|
106
|
-
const colors = useMobileGlobalStylesColors();
|
|
107
|
-
const colorSettings = useMultipleOriginColorsAndGradients();
|
|
108
|
-
colorSettings.allAvailableColors = colors;
|
|
109
|
-
|
|
110
|
-
const onColorChange = useCallback(
|
|
111
|
-
( color ) => {
|
|
112
|
-
onChange(
|
|
113
|
-
setColors(
|
|
114
|
-
value,
|
|
115
|
-
name,
|
|
116
|
-
colors,
|
|
117
|
-
{ [ property ]: color },
|
|
118
|
-
contentRef
|
|
119
|
-
)
|
|
120
|
-
);
|
|
121
|
-
},
|
|
122
|
-
[ colors, contentRef, name, onChange, value ]
|
|
123
|
-
);
|
|
124
|
-
const activeColors = useMemo(
|
|
125
|
-
() => getActiveColors( value, name, colors ),
|
|
126
|
-
[ name, value, colors ]
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
return (
|
|
130
|
-
<ColorSettings
|
|
131
|
-
colorValue={ activeColors[ property ] }
|
|
132
|
-
onColorChange={ onColorChange }
|
|
133
|
-
onColorCleared={ onColorChange }
|
|
134
|
-
defaultSettings={ colorSettings }
|
|
135
|
-
hideNavigation
|
|
136
|
-
/>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default function InlineColorUI( {
|
|
141
|
-
name,
|
|
142
|
-
value,
|
|
143
|
-
onChange,
|
|
144
|
-
onClose,
|
|
145
|
-
contentRef,
|
|
146
|
-
} ) {
|
|
147
|
-
return (
|
|
148
|
-
<BottomSheet
|
|
149
|
-
isVisible
|
|
150
|
-
onClose={ onClose }
|
|
151
|
-
hideHeader
|
|
152
|
-
contentStyle={ { paddingLeft: 0, paddingRight: 0 } }
|
|
153
|
-
hasNavigation
|
|
154
|
-
leftButton={ null }
|
|
155
|
-
testID="inline-text-color-modal"
|
|
156
|
-
>
|
|
157
|
-
<BottomSheet.NavigationContainer animate main>
|
|
158
|
-
<BottomSheet.NavigationScreen name="text-color">
|
|
159
|
-
<ColorPicker
|
|
160
|
-
name={ name }
|
|
161
|
-
value={ value }
|
|
162
|
-
onChange={ onChange }
|
|
163
|
-
contentRef={ contentRef }
|
|
164
|
-
/>
|
|
165
|
-
</BottomSheet.NavigationScreen>
|
|
166
|
-
</BottomSheet.NavigationContainer>
|
|
167
|
-
</BottomSheet>
|
|
168
|
-
);
|
|
169
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
.components-inline-color--is-active {
|
|
2
|
-
border-radius: 18px;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.components-inline-color__outline {
|
|
6
|
-
border-color: $light-quaternary;
|
|
7
|
-
top: 6px;
|
|
8
|
-
bottom: 6px;
|
|
9
|
-
left: 11px;
|
|
10
|
-
right: 11px;
|
|
11
|
-
border-radius: 24px;
|
|
12
|
-
position: absolute;
|
|
13
|
-
z-index: 2;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.components-inline-color__outline--dark {
|
|
17
|
-
border-color: $dark-quaternary;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.components-inline-color__button-container {
|
|
21
|
-
padding: 6px;
|
|
22
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Text color allows toggling the highlight color feature to selected text 1`] = `
|
|
4
|
-
"<!-- wp:paragraph -->
|
|
5
|
-
<p><mark style="background-color:rgba(0, 0, 0, 0);color:#f78da7" class="has-inline-color has-pale-pink-color">Hello this is a test</mark></p>
|
|
6
|
-
<!-- /wp:paragraph -->"
|
|
7
|
-
`;
|
|
8
|
-
|
|
9
|
-
exports[`Text color creates a paragraph block with the text color format 1`] = `
|
|
10
|
-
"<!-- wp:paragraph -->
|
|
11
|
-
<p>Hello <mark style="background-color:rgba(0,0,0,0);color:#cf2e2e" class="has-inline-color has-vivid-red-color">this is a test</mark></p>
|
|
12
|
-
<!-- /wp:paragraph -->"
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
|
-
exports[`Text color supports old text color format using "span" tag 1`] = `
|
|
16
|
-
"<!-- wp:paragraph -->
|
|
17
|
-
<p>this <span class="has-inline-color has-green-color">is</span> <span class="has-inline-color has-red-color">test</span></p>
|
|
18
|
-
<!-- /wp:paragraph -->
|
|
19
|
-
|
|
20
|
-
<!-- wp:paragraph -->
|
|
21
|
-
<p><span style="color:#08a5e9" class="has-inline-color">this is a test</span></p>
|
|
22
|
-
<!-- /wp:paragraph -->"
|
|
23
|
-
`;
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import {
|
|
5
|
-
fireEvent,
|
|
6
|
-
getEditorHtml,
|
|
7
|
-
initializeEditor,
|
|
8
|
-
render,
|
|
9
|
-
waitFor,
|
|
10
|
-
} from 'test/helpers';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/
|
|
15
|
-
import {
|
|
16
|
-
registerBlockType,
|
|
17
|
-
setDefaultBlockName,
|
|
18
|
-
unregisterBlockType,
|
|
19
|
-
} from '@wordpress/blocks';
|
|
20
|
-
import { coreBlocks } from '@wordpress/block-library';
|
|
21
|
-
import { BlockControls, BlockEdit } from '@wordpress/block-editor';
|
|
22
|
-
import { SlotFillProvider } from '@wordpress/components';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
import { textColor } from '..';
|
|
28
|
-
|
|
29
|
-
const COLOR_PINK = '#f78da7';
|
|
30
|
-
const paragraph = coreBlocks[ 'core/paragraph' ];
|
|
31
|
-
|
|
32
|
-
const TEXT_WITH_COLOR = `<!-- wp:paragraph -->
|
|
33
|
-
<p>Hello <mark style="background-color:rgba(0,0,0,0);color:#cf2e2e" class="has-inline-color has-vivid-red-color">this is a test</mark></p>
|
|
34
|
-
<!-- /wp:paragraph -->`;
|
|
35
|
-
|
|
36
|
-
beforeAll( () => {
|
|
37
|
-
paragraph.init();
|
|
38
|
-
setDefaultBlockName( paragraph.name );
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
afterAll( () => {
|
|
42
|
-
unregisterBlockType( paragraph.name );
|
|
43
|
-
} );
|
|
44
|
-
|
|
45
|
-
describe( 'Text color', () => {
|
|
46
|
-
it( 'shows the text color formatting button in the toolbar', async () => {
|
|
47
|
-
const screen = await initializeEditor();
|
|
48
|
-
|
|
49
|
-
// Wait for the editor placeholder
|
|
50
|
-
const paragraphPlaceholder = await screen.findByLabelText(
|
|
51
|
-
'Add paragraph block'
|
|
52
|
-
);
|
|
53
|
-
expect( paragraphPlaceholder ).toBeDefined();
|
|
54
|
-
fireEvent.press( paragraphPlaceholder );
|
|
55
|
-
|
|
56
|
-
// Wait for the block to be created
|
|
57
|
-
const [ paragraphBlock ] = await screen.findAllByLabelText(
|
|
58
|
-
/Paragraph Block\. Row 1/
|
|
59
|
-
);
|
|
60
|
-
expect( paragraphBlock ).toBeDefined();
|
|
61
|
-
|
|
62
|
-
// Look for the highlight text color button
|
|
63
|
-
const textColorButton = await screen.findByLabelText( 'Text color' );
|
|
64
|
-
expect( textColorButton ).toBeDefined();
|
|
65
|
-
} );
|
|
66
|
-
|
|
67
|
-
it( 'allows toggling the highlight color feature to selected text', async () => {
|
|
68
|
-
const screen = await initializeEditor();
|
|
69
|
-
const text = 'Hello this is a test';
|
|
70
|
-
|
|
71
|
-
// Wait for the editor placeholder
|
|
72
|
-
const paragraphPlaceholder = await screen.findByLabelText(
|
|
73
|
-
'Add paragraph block'
|
|
74
|
-
);
|
|
75
|
-
expect( paragraphPlaceholder ).toBeDefined();
|
|
76
|
-
fireEvent.press( paragraphPlaceholder );
|
|
77
|
-
|
|
78
|
-
// Wait for the block to be created
|
|
79
|
-
const [ paragraphBlock ] = await screen.findAllByLabelText(
|
|
80
|
-
/Paragraph Block\. Row 1/
|
|
81
|
-
);
|
|
82
|
-
expect( paragraphBlock ).toBeDefined();
|
|
83
|
-
|
|
84
|
-
// Update TextInput value
|
|
85
|
-
const paragraphText = screen.getByPlaceholderText( 'Start writing…' );
|
|
86
|
-
fireEvent( paragraphText, 'onSelectionChange', 0, text.length, text, {
|
|
87
|
-
nativeEvent: {
|
|
88
|
-
eventCount: 1,
|
|
89
|
-
target: undefined,
|
|
90
|
-
text,
|
|
91
|
-
},
|
|
92
|
-
} );
|
|
93
|
-
|
|
94
|
-
// Look for the highlight text color button
|
|
95
|
-
const textColorButton = await screen.findByLabelText( 'Text color' );
|
|
96
|
-
expect( textColorButton ).toBeDefined();
|
|
97
|
-
fireEvent.press( textColorButton );
|
|
98
|
-
|
|
99
|
-
// Wait for Inline color modal to be visible
|
|
100
|
-
const inlineTextColorModal = screen.getByTestId(
|
|
101
|
-
'inline-text-color-modal'
|
|
102
|
-
);
|
|
103
|
-
await waitFor( () => inlineTextColorModal.props.isVisible );
|
|
104
|
-
|
|
105
|
-
// Look for the pink color button
|
|
106
|
-
const pinkColorButton = await screen.findByA11yHint( COLOR_PINK );
|
|
107
|
-
expect( pinkColorButton ).toBeDefined();
|
|
108
|
-
fireEvent.press( pinkColorButton );
|
|
109
|
-
// TODO(jest-console): Fix the warning and remove the expect below.
|
|
110
|
-
expect( console ).toHaveWarnedWith(
|
|
111
|
-
`Non-serializable values were found in the navigation state. Check:\n\ntext-color > Palette > params.onColorChange (Function)\n\nThis can break usage such as persisting and restoring state. This might happen if you passed non-serializable values such as function, class instances etc. in params. If you need to use components with callbacks in your options, you can use 'navigation.setOptions' instead. See https://reactnavigation.org/docs/troubleshooting#i-get-the-warning-non-serializable-values-were-found-in-the-navigation-state for more details.`
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
expect( getEditorHtml() ).toMatchSnapshot();
|
|
115
|
-
} );
|
|
116
|
-
|
|
117
|
-
it( 'creates a paragraph block with the text color format', async () => {
|
|
118
|
-
const screen = await initializeEditor( {
|
|
119
|
-
initialHtml: TEXT_WITH_COLOR,
|
|
120
|
-
} );
|
|
121
|
-
|
|
122
|
-
// Wait for the block to be created
|
|
123
|
-
const [ paragraphBlock ] = await screen.findAllByLabelText(
|
|
124
|
-
/Paragraph Block\. Row 1/
|
|
125
|
-
);
|
|
126
|
-
expect( paragraphBlock ).toBeDefined();
|
|
127
|
-
|
|
128
|
-
expect( getEditorHtml() ).toMatchSnapshot();
|
|
129
|
-
} );
|
|
130
|
-
|
|
131
|
-
it( 'supports old text color format using "span" tag', async () => {
|
|
132
|
-
await initializeEditor( {
|
|
133
|
-
initialHtml: `<!-- wp:paragraph -->
|
|
134
|
-
<p>this <span class="has-inline-color has-green-color">is</span> <span class="has-inline-color has-red-color">test</span></p>
|
|
135
|
-
<!-- /wp:paragraph -->
|
|
136
|
-
|
|
137
|
-
<!-- wp:paragraph -->
|
|
138
|
-
<p><span style="color:#08a5e9" class="has-inline-color">this is a test</span></p>
|
|
139
|
-
<!-- /wp:paragraph -->`,
|
|
140
|
-
} );
|
|
141
|
-
|
|
142
|
-
expect( getEditorHtml() ).toMatchSnapshot();
|
|
143
|
-
} );
|
|
144
|
-
|
|
145
|
-
it( 'renders when "contentRef" is undefined', () => {
|
|
146
|
-
registerBlockType( 'core/test-block', {
|
|
147
|
-
save: () => {},
|
|
148
|
-
category: 'text',
|
|
149
|
-
title: 'block title',
|
|
150
|
-
edit: ( { children } ) => <>{ children }</>,
|
|
151
|
-
} );
|
|
152
|
-
const TextColorEdit = textColor.edit;
|
|
153
|
-
// Empty text with black color set as the text color
|
|
154
|
-
const textValue = {
|
|
155
|
-
formats: [],
|
|
156
|
-
replacements: [],
|
|
157
|
-
text: '',
|
|
158
|
-
start: 0,
|
|
159
|
-
end: 0,
|
|
160
|
-
activeFormats: [
|
|
161
|
-
{
|
|
162
|
-
type: 'core/text-color',
|
|
163
|
-
attributes: {
|
|
164
|
-
style: 'background-color:rgba(0, 0, 0, 0);color:#111111',
|
|
165
|
-
class: 'has-contrast-color',
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const { getByLabelText } = render(
|
|
172
|
-
<SlotFillProvider>
|
|
173
|
-
<BlockEdit name="core/test-block" isSelected mayDisplayControls>
|
|
174
|
-
<TextColorEdit
|
|
175
|
-
isActive
|
|
176
|
-
activeAttributes={ {} }
|
|
177
|
-
value={ textValue }
|
|
178
|
-
onChange={ jest.fn() }
|
|
179
|
-
// This ref is usually defined by the `RichText` component.
|
|
180
|
-
// However, there are rare cases (probably related to slow performance
|
|
181
|
-
// in low-end devices) where it's undefined upon mounting.
|
|
182
|
-
contentRef={ undefined }
|
|
183
|
-
/>
|
|
184
|
-
</BlockEdit>
|
|
185
|
-
<BlockControls.Slot />
|
|
186
|
-
</SlotFillProvider>
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
const textColorButton = getByLabelText( 'Text color' );
|
|
190
|
-
expect( textColorButton ).toBeDefined();
|
|
191
|
-
} );
|
|
192
|
-
} );
|