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.73.2 #40322

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ Give quoted text visual emphasis. "In quoting others, we cite ourselves." — Ju

- **Name:** core/quote
- **Category:** text
- **Supports:** anchor, typography (fontSize, lineHeight)
- **Supports:** anchor, color (background, gradients, link, text), typography (fontSize, lineHeight)
- **Attributes:** align, citation, value

## Read More
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function BlockForType( {
onDeleteBlock,
onReplace,
parentWidth,
parentBlockAlignment,
wrapperProps,
blockWidth,
baseGlobalStyles,
Expand Down Expand Up @@ -95,6 +96,7 @@ function BlockForType( {
contentStyle={ contentStyle }
onDeleteBlock={ onDeleteBlock }
blockWidth={ blockWidth }
parentBlockAlignment={ parentBlockAlignment }
/>
<View onLayout={ getBlockWidth } />
</GlobalStylesContext.Provider>
Expand Down
14 changes: 12 additions & 2 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ const devOnly = ( block ) => ( !! __DEV__ ? block : null );
const iOSOnly = ( block ) =>
Platform.OS === 'ios' ? block : devOnly( block );

// To be removed once Quote V2 is released on the web editor.
function quoteCheck( quoteBlock, blocksFlags ) {
if ( blocksFlags?.__experimentalEnableQuoteBlockV2 ) {
quoteBlock.settings = quoteBlock?.settingsV2;
}
return quoteBlock;
}

// Hide the Classic block and SocialLink block
addFilter(
'blocks.registerBlockType',
Expand Down Expand Up @@ -230,8 +238,10 @@ addFilter(
*
* registerCoreBlocks();
* ```
* @param {Object} [blocksFlags] Experimental flags
*
*/
export const registerCoreBlocks = () => {
export const registerCoreBlocks = ( blocksFlags ) => {
// When adding new blocks to this list please also consider updating /src/block-support/supported-blocks.json in the Gutenberg-Mobile repo
[
paragraph,
Expand All @@ -244,7 +254,7 @@ export const registerCoreBlocks = () => {
nextpage,
separator,
list,
quote,
quoteCheck( quote, blocksFlags ),
mediaText,
preformatted,
gallery,
Expand Down
14 changes: 13 additions & 1 deletion packages/block-library/src/paragraph/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import { useSelect } from '@wordpress/data';

const name = 'core/paragraph';

const allowedParentBlockAlignments = [ 'left', 'center', 'right' ];

function ParagraphBlock( {
attributes,
mergeBlocks,
onReplace,
setAttributes,
style,
clientId,
parentBlockAlignment,
} ) {
const isRTL = useSelect( ( select ) => {
return !! select( blockEditorStore ).getSettings().isRTL;
Expand All @@ -40,6 +43,15 @@ function ParagraphBlock( {
const onAlignmentChange = useCallback( ( nextAlign ) => {
setAttributes( { align: nextAlign } );
}, [] );

const parentTextAlignment = allowedParentBlockAlignments.includes(
parentBlockAlignment
)
? parentBlockAlignment
: undefined;

const textAlignment = align || parentTextAlignment;

return (
<>
<BlockControls group="block">
Expand Down Expand Up @@ -82,7 +94,7 @@ function ParagraphBlock( {
onReplace={ onReplace }
onRemove={ onReplace ? () => onReplace( [] ) : undefined }
placeholder={ placeholder || __( 'Start writing…' ) }
textAlign={ align }
textAlign={ textAlignment }
__unstableEmbedURLOnPaste
/>
</>
Expand Down
8 changes: 8 additions & 0 deletions packages/block-library/src/quote/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"fontSize": true,
"fontAppearance": true
}
},
"color": {
"gradients": true,
"link": true,
"__experimentalDefaultControls": {
"background": true,
"text": true
}
}
},
"styles": [
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import settingsV2 from './v2';

const { name } = metadata;

export { metadata, name };
export { metadata, name, settingsV2 };

export const settingsV1 = {
icon,
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/quote/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.wp-block-quote {
box-sizing: border-box;
overflow-wrap: break-word; // Break long strings of text without spaces so they don't overflow the block.
// .is-style-large and .is-large are kept for backwards compatibility. The :not pseudo-class is used to enable switching styles. See PR #37580.
&.is-style-large:not(.is-style-plain),
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/quote/v2/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function QuoteEdit( {
insertBlocksAfter,
clientId,
className,
style,
} ) {
const { citation, align } = attributes;

Expand All @@ -88,6 +89,7 @@ export default function QuoteEdit( {
className: classNames( className, {
[ `has-text-align-${ align }` ]: align,
} ),
...( ! isWebPlatform && { style } ),
} );
const innerBlocksProps = useInnerBlocksProps( blockProps, {
template: TEMPLATE,
Expand Down Expand Up @@ -128,6 +130,7 @@ export default function QuoteEdit( {
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter( createBlock( 'core/paragraph' ) )
}
{ ...( ! isWebPlatform ? { textAlign: align } : {} ) }
/>
) }
</BlockQuotation>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/spacer/controls.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { MIN_SPACER_SIZE } from './edit';
import { MIN_SPACER_SIZE } from './edit.js';
import styles from './style.scss';

const DEFAULT_VALUES = { px: 100, em: 10, rem: 10, vw: 10, vh: 25 };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Spacer block decrements height 1`] = `
"<!-- wp:spacer {\\"height\\":\\"99px\\"} -->
<div style=\\"height:99px\\" aria-hidden=\\"true\\" class=\\"wp-block-spacer\\"></div>
<!-- /wp:spacer -->"
`;

exports[`Spacer block increments height 1`] = `
"<!-- wp:spacer {\\"height\\":\\"101px\\"} -->
<div style=\\"height:101px\\" aria-hidden=\\"true\\" class=\\"wp-block-spacer\\"></div>
<!-- /wp:spacer -->"
`;

exports[`Spacer block inserts block 1`] = `
"<!-- wp:spacer -->
<div style=\\"height:100px\\" aria-hidden=\\"true\\" class=\\"wp-block-spacer\\"></div>
<!-- /wp:spacer -->"
`;

exports[`Spacer block updates height to 25vh 1`] = `
"<!-- wp:spacer {\\"height\\":\\"25vh\\"} -->
<div style=\\"height:25vh\\" aria-hidden=\\"true\\" class=\\"wp-block-spacer\\"></div>
<!-- /wp:spacer -->"
`;

exports[`Spacer block updates height to 50px 1`] = `
"<!-- wp:spacer {\\"height\\":\\"50px\\"} -->
<div style=\\"height:50px\\" aria-hidden=\\"true\\" class=\\"wp-block-spacer\\"></div>
<!-- /wp:spacer -->"
`;
180 changes: 180 additions & 0 deletions packages/block-library/src/spacer/test/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/**
* External dependencies
*/
import {
fireEvent,
getEditorHtml,
initializeEditor,
waitFor,
} from 'test/helpers';

/**
* WordPress dependencies
*/
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';

beforeAll( () => {
// Register all core blocks
registerCoreBlocks();
} );

afterAll( () => {
// Clean up registered blocks
getBlockTypes().forEach( ( block ) => {
unregisterBlockType( block.name );
} );
} );

describe( 'Spacer block', () => {
it( 'inserts block', async () => {
const {
getByA11yLabel,
getByTestId,
getByText,
} = await initializeEditor();

fireEvent.press( getByA11yLabel( 'Add block' ) );

const blockList = getByTestId( 'InserterUI-Blocks' );
// onScroll event used to force the FlatList to render all items
fireEvent.scroll( blockList, {
nativeEvent: {
contentOffset: { y: 0, x: 0 },
contentSize: { width: 100, height: 100 },
layoutMeasurement: { width: 100, height: 100 },
},
} );

fireEvent.press( await waitFor( () => getByText( 'Spacer' ) ) );

expect( getByA11yLabel( /Spacer Block\. Row 1/ ) ).toBeVisible();
expect( getEditorHtml() ).toMatchSnapshot();
} );

it( 'updates height to 50px', async () => {
const initialHtml = `<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->`;
const {
getByA11yLabel,
getByDisplayValue,
getByTestId,
getByText,
} = await initializeEditor( {
initialHtml,
} );

// Select Spacer block
const spacerBlock = getByA11yLabel( /Spacer Block\. Row 1/ );
fireEvent.press( spacerBlock );

// Open block settings
fireEvent.press( getByA11yLabel( 'Open Settings' ) );
await waitFor(
() => getByTestId( 'block-settings-modal' ).props.isVisible
);

// Update height attribute
fireEvent.press( getByText( '100' ) );
const heightTextInput = getByDisplayValue( '100' );
fireEvent.changeText( heightTextInput, '50' );

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

it( 'updates height to 25vh', async () => {
const initialHtml = `<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->`;
const {
getByA11yLabel,
getByDisplayValue,
getByTestId,
getByText,
} = await initializeEditor( {
initialHtml,
} );

// Select Spacer block
const spacerBlock = getByA11yLabel( /Spacer Block\. Row 1/ );
fireEvent.press( spacerBlock );

// Open block settings
fireEvent.press( getByA11yLabel( 'Open Settings' ) );
await waitFor(
() => getByTestId( 'block-settings-modal' ).props.isVisible
);

// Set vh unit
fireEvent.press( getByText( 'px' ) );
fireEvent.press( getByText( 'Viewport height (vh)' ) );

// Update height attribute
fireEvent.press( getByText( '100' ) );
const heightTextInput = getByDisplayValue( '100' );
fireEvent.changeText( heightTextInput, '25' );

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

it( 'increments height', async () => {
const initialHtml = `<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->`;
const { getByA11yLabel, getByTestId } = await initializeEditor( {
initialHtml,
} );

// Select Spacer block
const spacerBlock = getByA11yLabel( /Spacer Block\. Row 1/ );
fireEvent.press( spacerBlock );

// Open block settings
fireEvent.press( getByA11yLabel( 'Open Settings' ) );
await waitFor(
() => getByTestId( 'block-settings-modal' ).props.isVisible
);

// Increment height
fireEvent(
getByA11yLabel( /Height\. Value is 100 Pixels \(px\)/ ),
'accessibilityAction',
{
nativeEvent: { actionName: 'increment' },
}
);

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

it( 'decrements height', async () => {
const initialHtml = `<!-- wp:spacer -->
<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>
<!-- /wp:spacer -->`;
const { getByA11yLabel, getByTestId } = await initializeEditor( {
initialHtml,
} );

// Select Spacer block
const spacerBlock = getByA11yLabel( /Spacer Block\. Row 1/ );
fireEvent.press( spacerBlock );

// Open block settings
fireEvent.press( getByA11yLabel( 'Open Settings' ) );
await waitFor(
() => getByTestId( 'block-settings-modal' ).props.isVisible
);

// Increment height
fireEvent(
getByA11yLabel( /Height\. Value is 100 Pixels \(px\)/ ),
'accessibilityAction',
{
nativeEvent: { actionName: 'decrement' },
}
);

expect( getEditorHtml() ).toMatchSnapshot();
} );
} );
4 changes: 3 additions & 1 deletion packages/edit-post/src/test/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const unsupportedBlock = `
jest.useFakeTimers( 'legacy' );

describe( 'Editor', () => {
beforeAll( registerCoreBlocks );
beforeAll( () => {
registerCoreBlocks();
} );

it( 'detects unsupported block and sends hasUnsupportedBlocks true to native', () => {
RNReactNativeGutenbergBridge.editorDidMount = jest.fn();
Expand Down
Loading