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

RichText state structure for value manipulation #7890

Merged
merged 44 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
aad05a6
[squashed] RichText structure:
ellatrix Sep 14, 2018
6de0653
Test deprecated node matcher
ellatrix Sep 14, 2018
0f64289
Fix equality check for deprecated node matcher value
ellatrix Sep 14, 2018
be8ddbd
Deprecate wp.blocks.node and wp.blocks.children
ellatrix Sep 14, 2018
6491282
Value manipulation: ensure passed value is not mutated
ellatrix Sep 17, 2018
d8cd31b
Fix initial selection RichText field
ellatrix Sep 17, 2018
b417549
Represent object format in text string
ellatrix Sep 17, 2018
89c9287
Reduce this.editor dependency
ellatrix Sep 17, 2018
d4295bb
Adjust e2e test expected output
ellatrix Sep 19, 2018
5bb7b12
More docs, rename things
ellatrix Sep 20, 2018
ec01348
Make mobile tests pass
ellatrix Sep 20, 2018
112f42b
Fix richTextValue dependency in test plugin
ellatrix Sep 20, 2018
3a879fd
Remove web logic from native format toolbar
ellatrix Sep 20, 2018
29cf891
Mobile: drop custom formatters as well
ellatrix Sep 20, 2018
aa82875
Mobile: absort formatting toolbar into RichText to reuse formatting m…
ellatrix Sep 20, 2018
209fd38
RN entrypoints for escape-html, rich-text-value packages
hypest Sep 20, 2018
817de47
Rewrite multiline splitting
ellatrix Sep 20, 2018
ce6d906
Rebase: correct new tests
ellatrix Sep 21, 2018
18c41bc
Bump deprecation version and add to deprecated.md
ellatrix Sep 21, 2018
e432f8b
Adjust wrong isEmpty check in cover image block
ellatrix Sep 21, 2018
fb33b33
Update package.json
gziolo Sep 24, 2018
ed4a9ec
Prepare packages for the intial release
gziolo Sep 24, 2018
3274ab5
Fix package-lock.json file for the new packages
gziolo Sep 24, 2018
228264b
Fix typo in pattern transform
ellatrix Sep 25, 2018
cd518dd
Rebase: fix new failing test #9454
ellatrix Sep 25, 2018
be16be0
Abstract tree creation
ellatrix Sep 25, 2018
0607230
Restore children and node sources
ellatrix Sep 25, 2018
2def469
Clean up
ellatrix Sep 25, 2018
c9369ff
Fix isEmptyLine
ellatrix Sep 25, 2018
5cdc4ee
Adjust merge functions
ellatrix Sep 25, 2018
3e4c01a
Clean up
ellatrix Sep 25, 2018
48b8963
Polish: make create() easier to read
ellatrix Sep 26, 2018
d8c35e9
Inline pasted text should be parsed as HTML
ellatrix Sep 26, 2018
e2a9fa2
Fix create() call after 9a754dc
ellatrix Sep 26, 2018
6e6e910
children and node sources should work without default set
ellatrix Sep 26, 2018
13ee0e3
Cast default values of children and node sources as array
ellatrix Sep 26, 2018
445ab90
Fix verse transform
ellatrix Sep 26, 2018
6596b4f
List merging: don't merge empty line
ellatrix Sep 26, 2018
e000668
Use line separator to separate multiline values, instead of double li…
ellatrix Sep 26, 2018
6855216
Change deprecation removal version
ellatrix Sep 26, 2018
a3b7745
Update quote to use line separators
ellatrix Sep 26, 2018
9bc2dd4
Guard against blocks passing null value to RichText
ellatrix Sep 27, 2018
b25545d
Ensure formats with different reference are reduced to different node…
ellatrix Sep 28, 2018
94352e7
rich-text-value => rich-text, better deprecation messages, cast strin…
ellatrix Oct 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
12 changes: 12 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/element/README.md",
"parent": "packages"
},
{
"title": "@wordpress/escape-html",
"slug": "packages-escape-html",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/escape-html/README.md",
"parent": "packages"
},
{
"title": "@wordpress/hooks",
"slug": "packages-hooks",
Expand Down Expand Up @@ -467,6 +473,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/redux-routine/README.md",
"parent": "packages"
},
{
"title": "@wordpress/rich-text",
"slug": "packages-rich-text",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/rich-text/README.md",
"parent": "packages"
},
{
"title": "@wordpress/scripts",
"slug": "packages-scripts",
Expand Down
11 changes: 11 additions & 0 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Gutenberg's deprecation policy is intended to support backwards-compatibility for two minor releases, when possible. The current deprecations are listed below and are grouped by _the version at which they will be removed completely_. If your plugin depends on these behaviors, you must update to the recommended alternative before the noted version.

## 4.4.0

- The block attribute sources `children` and `node` have been removed. Please use the `rich-text` source instead. See the core blocks for examples.
- `wp.blocks.node.matcher` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.node.toHTML` has been removed. Please use `wp.richTextValue.toHTMLString` instead.
- `wp.blocks.node.fromDOM` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.children.toHTML` has been removed. Please use `wp.richTextValue.toHTMLString` instead.
- `wp.blocks.children.fromDOM` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.children.concat` has been removed. Please use `wp.richTextValue.concat` instead.
- `wp.blocks.children.getChildrenArray` has been removed. Please use `wp.richTextValue.create` instead.

## 4.2.0

- Writing resolvers as async generators has been removed. Use the controls plugin instead.
Expand Down
20 changes: 19 additions & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,24 @@ function gutenberg_register_scripts_and_styles() {
wp_register_script(
'wp-element',
gutenberg_url( 'build/element/index.js' ),
array( 'wp-polyfill', 'react', 'react-dom', 'lodash' ),
array( 'wp-polyfill', 'react', 'react-dom', 'lodash', 'wp-escape-html' ),
filemtime( gutenberg_dir_path() . 'build/element/index.js' ),
true
);
wp_register_script(
'wp-escape-html',
gutenberg_url( 'build/escape-html/index.js' ),
array( 'wp-polyfill' ),
filemtime( gutenberg_dir_path() . 'build/element/index.js' ),
true
);
wp_register_script(
'wp-rich-text',
gutenberg_url( 'build/rich-text/index.js' ),
array( 'wp-polyfill', 'wp-escape-html', 'lodash' ),
filemtime( gutenberg_dir_path() . 'build/rich-text/index.js' ),
true
);
wp_register_script(
'wp-components',
gutenberg_url( 'build/components/index.js' ),
Expand All @@ -383,6 +397,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-keycodes',
'wp-polyfill',
'wp-url',
'wp-rich-text',
),
filemtime( gutenberg_dir_path() . 'build/components/index.js' ),
true
Expand All @@ -408,6 +423,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-polyfill',
'wp-shortcode',
'lodash',
'wp-rich-text',
),
filemtime( gutenberg_dir_path() . 'build/blocks/index.js' ),
true
Expand Down Expand Up @@ -442,6 +458,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-polyfill',
'wp-url',
'wp-viewport',
'wp-rich-text',
),
filemtime( gutenberg_dir_path() . 'build/block-library/index.js' ),
true
Expand Down Expand Up @@ -601,6 +618,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-url',
'wp-viewport',
'wp-wordcount',
'wp-rich-text',
),
filemtime( gutenberg_dir_path() . 'build/editor/index.js' )
);
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@wordpress/dom-ready": "file:packages/dom-ready",
"@wordpress/editor": "file:packages/editor",
"@wordpress/element": "file:packages/element",
"@wordpress/escape-html": "file:packages/escape-html",
"@wordpress/hooks": "file:packages/hooks",
"@wordpress/html-entities": "file:packages/html-entities",
"@wordpress/i18n": "file:packages/i18n",
Expand All @@ -41,6 +42,7 @@
"@wordpress/nux": "file:packages/nux",
"@wordpress/plugins": "file:packages/plugins",
"@wordpress/redux-routine": "file:packages/redux-routine",
"@wordpress/rich-text": "file:packages/rich-text",
"@wordpress/shortcode": "file:packages/shortcode",
"@wordpress/token-list": "file:packages/token-list",
"@wordpress/url": "file:packages/url",
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export const settings = {
attribute: 'src',
},
caption: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'figcaption',
},
id: {
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const blockAttributes = {
attribute: 'title',
},
text: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'a',
},
backgroundColor: {
Expand Down
9 changes: 3 additions & 6 deletions packages/block-library/src/cover-image/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import classnames from 'classnames';

/**
Expand All @@ -25,8 +24,7 @@ const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ];

const blockAttributes = {
title: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'p',
},
url: {
Expand Down Expand Up @@ -195,7 +193,7 @@ export const settings = {
);

if ( ! url ) {
const hasTitle = ! isEmpty( title );
const hasTitle = ! RichText.isEmpty( title );
const icon = hasTitle ? undefined : 'format-image';
const label = hasTitle ? (
<RichText
Expand Down Expand Up @@ -276,8 +274,7 @@ export const settings = {
attributes: {
...blockAttributes,
title: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'h2',
},
},
Expand Down
4 changes: 1 addition & 3 deletions packages/block-library/src/embed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,8 @@ const embedAttributes = {
type: 'string',
},
caption: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'figcaption',
default: [],
},
type: {
type: 'string',
Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const blockAttributes = {
attribute: 'data-id',
},
caption: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'figcaption',
},
},
Expand Down
10 changes: 3 additions & 7 deletions packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
getPhrasingContentSchema,
getBlockAttributes,
getBlockType,
children,
} from '@wordpress/blocks';
import { RichText } from '@wordpress/editor';
import { concat } from '@wordpress/rich-text';

/**
* Internal dependencies
Expand All @@ -39,8 +39,7 @@ const supports = {

const schema = {
content: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'h1,h2,h3,h4,h5,h6',
},
level: {
Expand Down Expand Up @@ -167,10 +166,7 @@ export const settings = {

merge( attributes, attributesToMerge ) {
return {
content: children.concat(
attributes.content,
attributesToMerge.content
),
content: concat( attributes.content, attributesToMerge.content ),
};
},

Expand Down
3 changes: 1 addition & 2 deletions packages/block-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const blockAttributes = {
default: '',
},
caption: {
type: 'array',
source: 'children',
source: 'rich-text',
selector: 'figcaption',
},
href: {
Expand Down
Loading