Skip to content

Commit f47cc5d

Browse files
authored
Merge pull request #81 from wordpress-mobile/feature/introduce-para-block
Introduce paragraph block and RichText component for mobile
2 parents ebd0ca3 + 0e38e2b commit f47cc5d

File tree

8 files changed

+52
-78
lines changed

8 files changed

+52
-78
lines changed

.babelrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
"module-resolver",
99
{
1010
"cwd": "babelrc",
11-
"alias": {
12-
"react-native-aztec": "./react-native-aztec",
13-
"@wordpress/editor": "./editor",
11+
"alias": {
1412
"@gutenberg": "./gutenberg"
1513
},
1614
"extensions": [

gutenberg

Submodule gutenberg updated 504 files

jest.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ module.exports = {
3030
'node',
3131
],
3232
moduleNameMapper: {
33-
'@wordpress\\/(editor)$': '<rootDir>/gutenberg/$1',
34-
'@wordpress\\/(blocks|data|element|deprecated)$': '<rootDir>/gutenberg/packages/$1/src/index',
33+
'@wordpress\\/(blocks|data|element|deprecated|editor)$': '<rootDir>/gutenberg/packages/$1/src/index',
3534
'@gutenberg': '<rootDir>/gutenberg',
3635

3736
// Mock the CSS modules. See https://facebook.github.io/jest/docs/en/webpack.html#handling-static-assets

react-native-aztec

src/block-management/block-holder.js

+2-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import React from 'react';
77
import { View, Text, TouchableWithoutFeedback } from 'react-native';
8-
import RCTAztecView from 'react-native-aztec';
98
import Toolbar from './toolbar';
109

1110
import type { BlockType } from '../store/';
@@ -23,19 +22,14 @@ type PropsType = BlockType & {
2322
type StateType = {
2423
selected: boolean,
2524
focused: boolean,
26-
aztecHeight: number,
27-
eventCount?: number,
2825
};
2926

30-
const _minHeight = 50;
31-
3227
export default class BlockHolder extends React.Component<PropsType, StateType> {
3328
constructor( props: PropsType ) {
3429
super( props );
3530
this.state = {
3631
selected: false,
3732
focused: false,
38-
aztecHeight: _minHeight,
3933
};
4034
}
4135

@@ -58,6 +52,8 @@ export default class BlockHolder extends React.Component<PropsType, StateType> {
5852
let style;
5953
if ( blockType.name === 'core/code' ) {
6054
style = styles.block_code;
55+
} else if ( blockType.name === 'core/paragraph' ) {
56+
style = styles[ 'aztec_editor' ];
6157
}
6258

6359
// TODO: setAttributes needs to change the state/attributes
@@ -70,30 +66,6 @@ export default class BlockHolder extends React.Component<PropsType, StateType> {
7066
style={ style }
7167
/>
7268
);
73-
} else if ( this.props.name === 'aztec' ) {
74-
return (
75-
<RCTAztecView
76-
accessibilityLabel="aztec-view"
77-
style={ [
78-
styles[ 'aztec-editor' ],
79-
{ minHeight: Math.max( _minHeight, this.state.aztecHeight ) },
80-
] }
81-
text={ { text: this.props.attributes.content, eventCount: this.state.eventCount } }
82-
onContentSizeChange={ ( event ) => {
83-
this.setState( { ...this.state, aztecHeight: event.nativeEvent.contentSize.height } );
84-
} }
85-
onChange={ ( event ) => {
86-
this.setState( { ...this.state, eventCount: event.nativeEvent.eventCount } );
87-
88-
this.props.onChange( this.props.uid, {
89-
...this.props.attributes,
90-
content: event.nativeEvent.text,
91-
} );
92-
} }
93-
color={ 'black' }
94-
maxImagesWidth={ 200 }
95-
/>
96-
);
9769
}
9870

9971
// Default block placeholder
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/** @format */
2+
3+
import '../globals';
4+
5+
import { registerCoreBlocks } from '@gutenberg/core-blocks';
6+
import { parse } from '@wordpress/blocks';
7+
8+
registerCoreBlocks();
9+
10+
describe( 'Parser', () => {
11+
const innerContent = `
12+
if name == "World":
13+
return "Hello World"
14+
else:
15+
return "Hello Pony"`;
16+
17+
const originalBlockHtml = `<p>${ innerContent }</p>`;
18+
19+
const gbBlockHtml = `
20+
<!-- wp:paragraph -->
21+
${ originalBlockHtml }
22+
<!-- /wp:code -->`;
23+
24+
it( 'parses the paragraph block ok', () => {
25+
const blockInstance = parse( gbBlockHtml )[ 0 ];
26+
expect( blockInstance ).toBeTruthy();
27+
} );
28+
29+
it( 'parses the paragraph block content ok', () => {
30+
const blockInstance = parse( gbBlockHtml )[ 0 ];
31+
32+
expect( blockInstance.isValid ).toEqual( true );
33+
expect( blockInstance.name ).toEqual( 'core/paragraph' );
34+
expect( blockInstance.innerBlocks ).toHaveLength( 0 );
35+
expect( blockInstance.originalContent ).toEqual( originalBlockHtml );
36+
} );
37+
} );

src/store/index.js

+9-32
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,20 @@ const initialMoreBlockHtml = `
4141
<!-- /wp:more -->
4242
`;
4343

44+
const initialParagraphBlockHtml = '<!-- wp:paragraph --><p><b>Hello</b> World!</p><!-- /wp:paragraph -->';
45+
const initialParagraphBlockHtml2 = `<!-- wp:paragraph {"dropCap":true,"backgroundColor":"vivid-red","fontSize":"large","className":"custom-class-1 custom-class-2"} -->
46+
<p class="has-background has-drop-cap is-large-text has-vivid-red-background-color custom-class-1 custom-class-2">
47+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempor tincidunt sapien, quis dictum orci sollicitudin quis. Proin sed elit id est pulvinar feugiat vitae eget dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p><!-- /wp:paragraph -->`;
48+
4449
const codeBlockInstance = parse( initialCodeBlockHtml )[ 0 ];
4550
const moreBlockInstance = parse( initialMoreBlockHtml )[ 0 ];
51+
const paragraphBlockInstance = parse( initialParagraphBlockHtml )[ 0 ];
52+
const paragraphBlockInstance2 = parse( initialParagraphBlockHtml2 )[ 0 ];
4653

4754
const initialState: StateType = {
4855
// TODO: get blocks list block state should be externalized (shared with Gutenberg at some point?).
4956
// If not it should be created from a string parsing (commented HTML to json).
5057
blocks: [
51-
{
52-
uid: '0',
53-
name: 'aztec',
54-
isValid: true,
55-
attributes: {
56-
content: 'This is text rendered <b>in Aztec!</b>',
57-
},
58-
innerBlocks: [],
59-
focused: false,
60-
},
6158
{
6259
uid: '1',
6360
name: 'title',
@@ -68,28 +65,8 @@ const initialState: StateType = {
6865
innerBlocks: [],
6966
focused: false,
7067
},
71-
{
72-
uid: '2',
73-
name: 'paragraph',
74-
isValid: true,
75-
attributes: {
76-
content:
77-
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tempor tincidunt sapien, quis dictum orci sollicitudin quis. Proin sed elit id est pulvinar feugiat vitae eget dolor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
78-
},
79-
innerBlocks: [],
80-
focused: false,
81-
},
82-
{
83-
uid: '3',
84-
name: 'paragraph',
85-
isValid: true,
86-
attributes: {
87-
content:
88-
'書籍やウェブページや広告などのデザインのプロトタイプを制作したり顧客にプレゼンテーションしたりする際に、まだ正式な文章の出来上がっていないテキスト部分の書体(フォント)、タイポグラフィ、レイアウトなどといった視覚的なデザインを調整したりわかりやすく見せるために用いられる。',
89-
},
90-
innerBlocks: [],
91-
focused: false,
92-
},
68+
{ ...paragraphBlockInstance, focused: false },
69+
{ ...paragraphBlockInstance2, focused: false },
9370
{ ...codeBlockInstance, focused: false },
9471
{ ...moreBlockInstance, focused: false },
9572
{

wordpress/hooks.js

-9
This file was deleted.

0 commit comments

Comments
 (0)