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

Introduces RichText component for mobile and ports Para block for mobile #8231

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3318475
Introduce RichText component for mobile, and port the Paragraph block…
daniloercoli Jul 26, 2018
1ffdf7c
Fix lint
daniloercoli Jul 26, 2018
73d1a38
Use an edit file to share more common code with the main Paragraph we…
SergioEstevao Jul 26, 2018
1669996
Fix lint
daniloercoli Jul 27, 2018
ec0f897
Remove log calls
daniloercoli Jul 27, 2018
20d7082
Revert renaming of custom-class-name.native.js → custom-class-name-na…
daniloercoli Jul 27, 2018
b918423
Cleaning the code / Refactoring by "nativizing" `utils.js` (& `index.…
daniloercoli Jul 27, 2018
3348926
Remove any extra P.
SergioEstevao Jul 27, 2018
804b52a
Replace <p> by <br>
SergioEstevao Jul 27, 2018
8e75df3
Merge branch 'master' into rnmobile/port-para-block-use-latest-gb-mas…
SergioEstevao Jul 30, 2018
bed493b
The RichText mobile component now returns plain HTML, and the transfo…
daniloercoli Jul 30, 2018
c9373d2
Merge remote-tracking branch 'origin/master' into rnmobile/port-para-…
gziolo Aug 1, 2018
f0e83ec
Update code to work with the lastest master changes
gziolo Aug 1, 2018
b275731
Correctly check if minHeight is undefined when setting the style of m…
daniloercoli Aug 1, 2018
f214c76
Blocks: Extract phrasing content to its own file to allow reuse with …
gziolo Aug 1, 2018
762b582
Merge branch 'rnmobile/port-para-block-use-latest-gb-master-july' of …
gziolo Aug 1, 2018
9651c70
Remove method `setForceUpdate` that is not used. Also remove the conv…
daniloercoli Aug 1, 2018
248a2c8
Remove `aria-label` that is not used in RichText mobile
daniloercoli Aug 1, 2018
b34049a
Convert private instance variable `lastContentSizeHeight`, to local m…
daniloercoli Aug 1, 2018
131e3e7
Use built-in `forceUpdate` method call, instead of using a private bo…
daniloercoli Aug 1, 2018
3351260
Add comment for P replacement for BR
SergioEstevao Aug 1, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { has } from 'lodash';
/**
* Internal dependencies
*/
import { isPhrasingContent } from './utils';
import { isPhrasingContent } from './phrasing-content';

/**
* Whether or not the given node is figure content.
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import figureContentReducer from './figure-content-reducer';
import shortcodeConverter from './shortcode-converter';
import markdownConverter from './markdown-converter';
import iframeRemover from './iframe-remover';
import { getPhrasingContentSchema } from './phrasing-content';
import {
deepFilterHTML,
isPlain,
removeInvalidHTML,
getPhrasingContentSchema,
getBlockContentSchema,
} from './utils';

Expand Down
6 changes: 1 addition & 5 deletions packages/blocks/src/api/raw-handling/index.native.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import {
getPhrasingContentSchema,
} from './utils';

export { getPhrasingContentSchema };
export { getPhrasingContentSchema } from './phrasing-content';
2 changes: 1 addition & 1 deletion packages/blocks/src/api/raw-handling/is-inline-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { difference } from 'lodash';
/**
* Internal dependencies
*/
import { isPhrasingContent } from './utils';
import { isPhrasingContent } from './phrasing-content';

/**
* Checks if the given node should be considered inline content, optionally
Expand Down
3 changes: 2 additions & 1 deletion packages/blocks/src/api/raw-handling/normalise-blocks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Internal dependencies
*/
import { isPhrasingContent, isEmpty } from './utils';
import { isEmpty } from './utils';
import { isPhrasingContent } from './phrasing-content';

/**
* Browser dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unwrap, replaceTag } from '@wordpress/dom';
/**
* Internal dependencies
*/
import { isPhrasingContent } from './utils';
import { isPhrasingContent } from './phrasing-content';

function isBlockContent( node, schema = {} ) {
return schema.hasOwnProperty( node.nodeName.toLowerCase() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const phrasingContentSchema = {
em: {},
del: {},
ins: {},
a: { attributes: [ 'href' ] },
a: { attributes: [ 'href', 'target', 'rel' ] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this already get out of sync so I moved it to its own file.

code: {},
abbr: { attributes: [ 'title' ] },
sub: {},
Expand All @@ -34,3 +34,17 @@ const phrasingContentSchema = {
export function getPhrasingContentSchema() {
return phrasingContentSchema;
}

/**
* Find out whether or not the given node is phrasing content.
*
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
*
* @param {Element} node The node to test.
*
* @return {boolean} True if phrasing content, false if not.
*/
export function isPhrasingContent( node ) {
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';
}
3 changes: 2 additions & 1 deletion packages/blocks/src/api/raw-handling/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Internal dependencies
*/
import { isEmpty, isPlain, removeInvalidHTML, getPhrasingContentSchema } from '../utils';
import { getPhrasingContentSchema } from '../phrasing-content';
import { isEmpty, isPlain, removeInvalidHTML } from '../utils';

describe( 'isEmpty', () => {
function isEmptyHTML( HTML ) {
Expand Down
51 changes: 5 additions & 46 deletions packages/blocks/src/api/raw-handling/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { omit, mergeWith, includes, noop } from 'lodash';
import { mergeWith, includes, noop } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -10,55 +10,14 @@ import { unwrap, insertAfter, remove } from '@wordpress/dom';
import { hasBlockSupport } from '..';

/**
* Browser dependencies
* Internal dependencies
*/
const { ELEMENT_NODE, TEXT_NODE } = window.Node;

const phrasingContentSchema = {
strong: {},
em: {},
del: {},
ins: {},
a: { attributes: [ 'href', 'target', 'rel' ] },
code: {},
abbr: { attributes: [ 'title' ] },
sub: {},
sup: {},
br: {},
'#text': {},
};

// Recursion is needed.
// Possible: strong > em > strong.
// Impossible: strong > strong.
[ 'strong', 'em', 'del', 'ins', 'a', 'code', 'abbr', 'sub', 'sup' ].forEach( ( tag ) => {
phrasingContentSchema[ tag ].children = omit( phrasingContentSchema, tag );
} );
import { isPhrasingContent } from './phrasing-content';

/**
* Get schema of possible paths for phrasing content.
*
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
*
* @return {Object} Schema.
*/
export function getPhrasingContentSchema() {
return phrasingContentSchema;
}

/**
* Find out whether or not the given node is phrasing content.
*
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
*
* @param {Element} node The node to test.
*
* @return {boolean} True if phrasing content, false if not.
* Browser dependencies
*/
export function isPhrasingContent( node ) {
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';
}
const { ELEMENT_NODE, TEXT_NODE } = window.Node;

/**
* Given raw transforms from blocks, merges all schemas into one.
Expand Down