Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile Release v1.109.3 #57060

Merged
merged 24 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a8fa1f7
Release script: Update react-native-editor version to 1.109.0
fluiddot Nov 23, 2023
a6f2d96
Release script: Update CHANGELOG for version 1.109.0
fluiddot Nov 23, 2023
15d16aa
Release script: Update podfile
fluiddot Nov 23, 2023
6f5b6ae
Update `react-native-editor` changelog
fluiddot Nov 23, 2023
134ce47
Update `react-native-editor` changelog
fluiddot Nov 24, 2023
e3560fb
Mobile - Fix issue when backspacing in an empty Paragraph block (#56496)
geriux Nov 28, 2023
290d21d
Release script: Update react-native-editor version to 1.109.1
geriux Nov 29, 2023
aaf04bb
Release script: Update CHANGELOG for version 1.109.1
geriux Nov 29, 2023
67f099e
Release script: Update podfile
geriux Nov 29, 2023
3d42ef9
[RNMobile] Fixes a crash on pasting MS Word list markup (#56653)
fluiddot Nov 30, 2023
99deadc
[RNMobile] Fix issue related to receiving undefined ref in text color…
fluiddot Dec 1, 2023
8c82075
[RNMobile] Fix HTML to blocks conversion when no transformations are …
fluiddot Dec 4, 2023
aad3fa4
RichText (native): remove HTML check in getFormatColors (#56684)
ellatrix Dec 1, 2023
9673464
Mobile - Global Styles - Fix issue with custom color variables not be…
geriux Dec 4, 2023
74e8f73
[RNMobile] Address `NullPointerException` crash in `AztecHeadingSpan`…
Dec 4, 2023
6734e00
Release script: Update react-native-editor version to 1.109.2
fluiddot Dec 5, 2023
9f24d7f
Release script: Update CHANGELOG for version 1.109.2
fluiddot Dec 5, 2023
b10351b
Release script: Update podfile
fluiddot Dec 5, 2023
ac76f57
Release script: Update react-native-editor version to 1.109.3
Dec 14, 2023
9de673f
Release script: Update CHANGELOG for version 1.109.3
Dec 14, 2023
c2852cf
Release script: Update podfile
Dec 14, 2023
0292f36
Mobile - Fix having the default font sizes when there are theme font …
geriux Dec 12, 2023
a66bdb0
Update CHANGELOG entry
Dec 14, 2023
8c6c3c7
Resolve merge conflicts.
Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps, registry ) => {
}

moveFirstItemUp( rootClientId );
} else {
removeBlock( clientId );
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function RichTextWrapper(
// an intentional user interaction distinguishing between Backspace and
// Delete to remove the empty field, but also to avoid merge & remove
// causing destruction of two fields (merge, then removed merged).
if ( onRemove && isEmpty( value ) && isReverse ) {
else if ( onRemove && isEmpty( value ) && isReverse ) {
onRemove( ! isReverse );
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,43 @@ import { getColorObjectByAttributeValues } from '../../../components/colors';

const FORMAT_TYPE = 'core/text-color';
const REGEX_TO_MATCH = /^has-(.*)-color$/;
const TAGS_TO_SEARCH = /\<mark/;

export function getFormatColors( value, formats, colors ) {
if ( value?.search( TAGS_TO_SEARCH ) !== -1 ) {
const newFormats = formats.slice();
export function getFormatColors( formats, colors ) {
const newFormats = formats.slice();

newFormats.forEach( ( format ) => {
format.forEach( ( currentFormat ) => {
if ( currentFormat?.type === FORMAT_TYPE ) {
const className = currentFormat?.attributes?.class;
currentFormat.attributes.style =
currentFormat.attributes.style.replace( / /g, '' );
// We are looping through a sparse array where empty indices will be
// skipped.
newFormats.forEach( ( format ) => {
format.forEach( ( currentFormat ) => {
if ( currentFormat?.type === FORMAT_TYPE ) {
const className = currentFormat?.attributes?.class;

className?.split( ' ' ).forEach( ( currentClass ) => {
const match = currentClass.match( REGEX_TO_MATCH );
if ( match ) {
const [ , colorSlug ] =
currentClass.match( REGEX_TO_MATCH );
const colorObject = getColorObjectByAttributeValues(
colors,
colorSlug
);
const currentStyles =
currentFormat?.attributes?.style;
if (
colorObject &&
( ! currentStyles ||
currentStyles?.indexOf(
colorObject.color
) === -1 )
) {
currentFormat.attributes.style = [
`color: ${ colorObject.color }`,
currentStyles,
].join( ';' );
}
className?.split( ' ' ).forEach( ( currentClass ) => {
const match = currentClass.match( REGEX_TO_MATCH );
if ( match ) {
const [ , colorSlug ] =
currentClass.match( REGEX_TO_MATCH );
const colorObject = getColorObjectByAttributeValues(
colors,
colorSlug
);
const currentStyles = currentFormat?.attributes?.style;
if (
colorObject &&
( ! currentStyles ||
currentStyles?.indexOf( colorObject.color ) ===
-1 )
) {
currentFormat.attributes.style = [
`color: ${ colorObject.color }`,
currentStyles,
].join( ';' );
}
} );
}
} );
}
} );
}
} );
} );

return newFormats;
}

return formats;
return newFormats;
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class RichText extends Component {

const { formats, replacements, text } = currentValue;
const { activeFormats } = this.state;
const newFormats = getFormatColors( value, formats, colorPalette );
const newFormats = getFormatColors( formats, colorPalette );

return {
formats: newFormats,
Expand Down Expand Up @@ -650,6 +650,40 @@ export class RichText extends Component {
return shouldDrop;
}

/**
* Determines whether the text input should receive focus after an update.
* For cases where a RichText with a value is merged with an empty one.
*
* @param {Object} prevProps - The previous props of the component.
* @return {boolean} True if the text input should receive focus, false otherwise.
*/
shouldFocusTextInputAfterMerge( prevProps ) {
const {
__unstableIsSelected: isSelected,
blockIsSelected,
selectionStart,
selectionEnd,
__unstableMobileNoFocusOnMount,
} = this.props;

const {
__unstableIsSelected: prevIsSelected,
blockIsSelected: prevBlockIsSelected,
} = prevProps;

const noSelectionValues =
selectionStart === undefined && selectionEnd === undefined;
const textInputWasNotFocused = ! prevIsSelected && ! isSelected;

return (
! __unstableMobileNoFocusOnMount &&
noSelectionValues &&
textInputWasNotFocused &&
! prevBlockIsSelected &&
blockIsSelected
);
}

onSelectionChangeFromAztec( start, end, text, event ) {
if ( this.shouldDropEventFromAztec( event, 'onSelectionChange' ) ) {
return;
Expand Down Expand Up @@ -843,9 +877,8 @@ export class RichText extends Component {
if ( this.props.value !== this.value ) {
this.value = this.props.value;
}
const { __unstableIsSelected: isSelected } = this.props;

const { __unstableIsSelected: prevIsSelected } = prevProps;
const { __unstableIsSelected: isSelected } = this.props;

if ( isSelected && ! prevIsSelected ) {
this._editor.focus();
Expand All @@ -855,6 +888,16 @@ export class RichText extends Component {
this.props.selectionStart || 0,
this.props.selectionEnd || 0
);
} else if ( this.shouldFocusTextInputAfterMerge( prevProps ) ) {
// Since this is happening when merging blocks, the selection should be at the last character position.
// As a fallback the internal selectionEnd value is used.
const lastCharacterPosition =
this.value?.length ?? this.selectionEnd;
this._editor.focus();
this.props.onSelectionChange(
lastCharacterPosition,
lastCharacterPosition
);
} else if ( ! isSelected && prevIsSelected ) {
this._editor.blur();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,3 @@ exports[`Buttons block when a button is shown removing button along with buttons
<p></p>
<!-- /wp:paragraph -->"
`;

exports[`Buttons block when a button is shown removing button along with buttons block removes the button and buttons block when deleting the block using the delete (backspace) key 1`] = `
"<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->"
`;
27 changes: 0 additions & 27 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
*/
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
import { BACKSPACE } from '@wordpress/keycodes';

const BUTTONS_HTML = `<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button /--></div>
Expand Down Expand Up @@ -238,32 +237,6 @@ describe( 'Buttons block', () => {

expect( getEditorHtml() ).toMatchSnapshot();
} );

it( 'removes the button and buttons block when deleting the block using the delete (backspace) key', async () => {
const screen = await initializeEditor( {
initialHtml: BUTTONS_HTML,
} );

// Get block
const buttonsBlock = await getBlock( screen, 'Buttons' );
triggerBlockListLayout( buttonsBlock );

// Get inner button block
const buttonBlock = await getBlock( screen, 'Button' );
fireEvent.press( buttonBlock );

const buttonInput =
within( buttonBlock ).getByLabelText( 'Text input. Empty' );

// Delete block
fireEvent( buttonInput, 'onKeyDown', {
nativeEvent: {},
preventDefault() {},
keyCode: BACKSPACE,
} );

expect( getEditorHtml() ).toMatchSnapshot();
} );
} );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ exports[`Heading block inserts block 1`] = `
<!-- /wp:heading -->"
`;

exports[`Heading block should merge with an empty Paragraph block and keep being the Heading block 1`] = `
"<!-- wp:heading -->
<h2 class="wp-block-heading">A quick brown fox jumps over the lazy dog.</h2>
<!-- /wp:heading -->"
`;

exports[`Heading block should set a background color 1`] = `
"<!-- wp:heading {"backgroundColor":"luminous-vivid-orange"} -->
<h2 class="wp-block-heading has-luminous-vivid-orange-background-color has-background">A quick brown fox jumps over the lazy dog.</h2>
Expand Down
40 changes: 40 additions & 0 deletions packages/block-library/src/heading/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
*/
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
import { BACKSPACE, ENTER } from '@wordpress/keycodes';

beforeAll( () => {
// Register all core blocks
Expand Down Expand Up @@ -134,4 +135,43 @@ describe( 'Heading block', () => {
)
).toBeVisible();
} );

it( 'should merge with an empty Paragraph block and keep being the Heading block', async () => {
// Arrange
const screen = await initializeEditor();
await addBlock( screen, 'Paragraph' );

// Act
const paragraphBlock = getBlock( screen, 'Paragraph' );
fireEvent.press( paragraphBlock );

const paragraphTextInput =
within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
fireEvent( paragraphTextInput, 'onKeyDown', {
nativeEvent: {},
preventDefault() {},
keyCode: ENTER,
} );

await addBlock( screen, 'Heading' );
const headingBlock = getBlock( screen, 'Heading', { rowIndex: 2 } );
fireEvent.press( headingBlock );

const headingTextInput =
within( headingBlock ).getByPlaceholderText( 'Heading' );
typeInRichText(
headingTextInput,
'A quick brown fox jumps over the lazy dog.',
{ finalSelectionStart: 0, finalSelectionEnd: 0 }
);

fireEvent( headingTextInput, 'onKeyDown', {
nativeEvent: {},
preventDefault() {},
keyCode: BACKSPACE,
} );

// Assert
expect( getEditorHtml() ).toMatchSnapshot();
} );
} );
38 changes: 37 additions & 1 deletion packages/block-library/src/paragraph/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import {
waitForElementToBeRemoved,
} from 'test/helpers';
import Clipboard from '@react-native-clipboard/clipboard';
import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';

/**
* WordPress dependencies
*/
import { ENTER } from '@wordpress/keycodes';
import { BACKSPACE, ENTER } from '@wordpress/keycodes';

/**
* Internal dependencies
Expand Down Expand Up @@ -685,4 +686,39 @@ describe( 'Paragraph block', () => {
<!-- /wp:paragraph -->"
` );
} );

it( 'should focus on the previous Paragraph block when backspacing in an empty Paragraph block', async () => {
// Arrange
const screen = await initializeEditor();
await addBlock( screen, 'Paragraph' );

// Act
const paragraphBlock = getBlock( screen, 'Paragraph' );
fireEvent.press( paragraphBlock );
const paragraphTextInput =
within( paragraphBlock ).getByPlaceholderText( 'Start writing…' );
typeInRichText( paragraphTextInput, 'A quick brown fox jumps' );

await addBlock( screen, 'Paragraph' );
const secondParagraphBlock = getBlock( screen, 'Paragraph', {
rowIndex: 2,
} );
fireEvent.press( secondParagraphBlock );

// Clear mock history
TextInputState.focusTextInput.mockClear();

const secondParagraphTextInput =
within( secondParagraphBlock ).getByPlaceholderText(
'Start writing…'
);
fireEvent( secondParagraphTextInput, 'onKeyDown', {
nativeEvent: {},
preventDefault() {},
keyCode: BACKSPACE,
} );

// Assert
expect( TextInputState.focusTextInput ).toHaveBeenCalled();
} );
} );
Loading
Loading