From 2c503a6bcefa0bbca5bb3ad0749940508ae8ec0e Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Fri, 16 Aug 2019 14:29:41 -0400 Subject: [PATCH 1/3] [RNMobile] update mobile to not use ListEdit This update is in response to changes made on the web side in #15113 that were causing a crash on mobile. --- .../src/components/rich-text/index.native.js | 12 +- .../block-library/src/list/edit.native.js | 139 ++++++++++++++++++ 2 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 packages/block-library/src/list/edit.native.js diff --git a/packages/block-editor/src/components/rich-text/index.native.js b/packages/block-editor/src/components/rich-text/index.native.js index ccb5e0d15bf7e..30e882ed49d80 100644 --- a/packages/block-editor/src/components/rich-text/index.native.js +++ b/packages/block-editor/src/components/rich-text/index.native.js @@ -20,12 +20,12 @@ import Autocomplete from '../autocomplete'; import BlockFormatControls from '../block-format-controls'; import FormatToolbar from './format-toolbar'; import { withBlockEditContext } from '../block-edit/context'; -import { ListEdit } from './list-edit'; const wrapperClasses = 'editor-rich-text block-editor-rich-text'; const classes = 'editor-rich-text__editable block-editor-rich-text__editable'; function RichTextWraper( { + children, tagName, value: originalValue, onChange: originalOnChange, @@ -33,7 +33,6 @@ function RichTextWraper( { selectionEnd, onSelectionChange, multiline, - onTagNameChange, inlineToolbar, wrapperClassName, className, @@ -86,14 +85,7 @@ function RichTextWraper( { > { ( { isSelected, value, onChange } ) => - { isSelected && multiline === 'li' && ( - - ) } + { children && children( { value, onChange } ) } { isSelected && ! inlineToolbar && ( diff --git a/packages/block-library/src/list/edit.native.js b/packages/block-library/src/list/edit.native.js new file mode 100644 index 0000000000000..f8497648e06df --- /dev/null +++ b/packages/block-library/src/list/edit.native.js @@ -0,0 +1,139 @@ +/** + * WordPress dependencies + */ +import { __, _x } from '@wordpress/i18n'; +import { createBlock } from '@wordpress/blocks'; +import { + RichText, + BlockControls, + RichTextShortcut, +} from '@wordpress/block-editor'; +import { + Toolbar, +} from '@wordpress/components'; +import { + __unstableIndentListItems as indentListItems, + __unstableOutdentListItems as outdentListItems, + __unstableChangeListType as changeListType, + __unstableIsListRootSelected as isListRootSelected, + __unstableIsActiveListType as isActiveListType, +} from '@wordpress/rich-text'; + +/** + * Internal dependencies + */ +import { name } from './'; + +export default function ListEdit( { + attributes, + setAttributes, + mergeBlocks, + onReplace, + className, +} ) { + const { ordered, values } = attributes; + const tagName = ordered ? 'ol' : 'ul'; + + const controls = ( { value, onChange } ) => { + if ( value.start === undefined ) { + return; + } + + return <> + { + onChange( outdentListItems( value ) ); + } } + /> + { + onChange( indentListItems( value, { type: tagName } ) ); + } } + /> + { + onChange( indentListItems( value, { type: tagName } ) ); + } } + /> + { + onChange( outdentListItems( value ) ); + } } + /> + + + + ; + }; + + return ( + setAttributes( { values: nextValues } ) } + value={ values } + wrapperClassName="block-library-list" + className={ className } + placeholder={ __( 'Write list…' ) } + onMerge={ mergeBlocks } + onSplit={ ( value ) => createBlock( name, { ordered, values: value } ) } + __unstableOnSplitMiddle={ () => createBlock( 'core/paragraph' ) } + onReplace={ onReplace } + onRemove={ () => onReplace( [] ) } + > + { controls } + + ); +} From d4b828afb93c2f96b1d78d6d905cbb536273bda6 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Sun, 18 Aug 2019 07:42:51 -0400 Subject: [PATCH 2/3] Extract list block logic not shared with mobile to separate component --- .../src/list/additional-settings.js | 44 ++++++ .../src/list/additional-settings.native.js | 3 + packages/block-library/src/list/edit.js | 42 +----- .../block-library/src/list/edit.native.js | 139 ------------------ 4 files changed, 54 insertions(+), 174 deletions(-) create mode 100644 packages/block-library/src/list/additional-settings.js create mode 100644 packages/block-library/src/list/additional-settings.native.js delete mode 100644 packages/block-library/src/list/edit.native.js diff --git a/packages/block-library/src/list/additional-settings.js b/packages/block-library/src/list/additional-settings.js new file mode 100644 index 0000000000000..9d12ae443b556 --- /dev/null +++ b/packages/block-library/src/list/additional-settings.js @@ -0,0 +1,44 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { InspectorControls } from '@wordpress/block-editor'; +import { + TextControl, + PanelBody, + ToggleControl, +} from '@wordpress/components'; + +const AdditionalSettings = ( { setAttributes, ordered, reversed, start } ) => + ordered && ( + + + { + const int = parseInt( value, 10 ); + + setAttributes( { + // It should be possible to unset the value, + // e.g. with an empty string. + start: isNaN( int ) ? undefined : int, + } ); + } } + value={ Number.isInteger( start ) ? start.toString( 10 ) : '' } + step="1" + /> + { + setAttributes( { + // Unset the attribute if not reversed. + reversed: value || undefined, + } ); + } } + /> + + ); + +export default AdditionalSettings; diff --git a/packages/block-library/src/list/additional-settings.native.js b/packages/block-library/src/list/additional-settings.native.js new file mode 100644 index 0000000000000..43bab31a4330e --- /dev/null +++ b/packages/block-library/src/list/additional-settings.native.js @@ -0,0 +1,3 @@ +// Mobile has no additional list settings at this time, so render nothing +const AdditionalSettings = () => null; +export default AdditionalSettings; diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index efc38c50a63e2..4c928d9a8d5dd 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -7,13 +7,9 @@ import { RichText, BlockControls, RichTextShortcut, - InspectorControls, } from '@wordpress/block-editor'; import { Toolbar, - TextControl, - PanelBody, - ToggleControl, } from '@wordpress/components'; import { __unstableIndentListItems as indentListItems, @@ -27,6 +23,7 @@ import { * Internal dependencies */ import { name } from './'; +import AdditionalSettings from './additional-settings'; export default function ListEdit( { attributes, @@ -141,36 +138,11 @@ export default function ListEdit( { > { controls } - { ordered && - - - { - const int = parseInt( value, 10 ); - - setAttributes( { - // It should be possible to unset the value, - // e.g. with an empty string. - start: isNaN( int ) ? undefined : int, - } ); - } } - value={ Number.isInteger( start ) ? start.toString( 10 ) : '' } - step="1" - /> - { - setAttributes( { - // Unset the attribute if not reversed. - reversed: value || undefined, - } ); - } } - /> - - - } + ; } diff --git a/packages/block-library/src/list/edit.native.js b/packages/block-library/src/list/edit.native.js deleted file mode 100644 index f8497648e06df..0000000000000 --- a/packages/block-library/src/list/edit.native.js +++ /dev/null @@ -1,139 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, _x } from '@wordpress/i18n'; -import { createBlock } from '@wordpress/blocks'; -import { - RichText, - BlockControls, - RichTextShortcut, -} from '@wordpress/block-editor'; -import { - Toolbar, -} from '@wordpress/components'; -import { - __unstableIndentListItems as indentListItems, - __unstableOutdentListItems as outdentListItems, - __unstableChangeListType as changeListType, - __unstableIsListRootSelected as isListRootSelected, - __unstableIsActiveListType as isActiveListType, -} from '@wordpress/rich-text'; - -/** - * Internal dependencies - */ -import { name } from './'; - -export default function ListEdit( { - attributes, - setAttributes, - mergeBlocks, - onReplace, - className, -} ) { - const { ordered, values } = attributes; - const tagName = ordered ? 'ol' : 'ul'; - - const controls = ( { value, onChange } ) => { - if ( value.start === undefined ) { - return; - } - - return <> - { - onChange( outdentListItems( value ) ); - } } - /> - { - onChange( indentListItems( value, { type: tagName } ) ); - } } - /> - { - onChange( indentListItems( value, { type: tagName } ) ); - } } - /> - { - onChange( outdentListItems( value ) ); - } } - /> - - - - ; - }; - - return ( - setAttributes( { values: nextValues } ) } - value={ values } - wrapperClassName="block-library-list" - className={ className } - placeholder={ __( 'Write list…' ) } - onMerge={ mergeBlocks } - onSplit={ ( value ) => createBlock( name, { ordered, values: value } ) } - __unstableOnSplitMiddle={ () => createBlock( 'core/paragraph' ) } - onReplace={ onReplace } - onRemove={ () => onReplace( [] ) } - > - { controls } - - ); -} From 0f74d0af2fa589b709b105e12e0c24c606857096 Mon Sep 17 00:00:00 2001 From: Matt Chowning Date: Mon, 19 Aug 2019 16:33:59 -0400 Subject: [PATCH 3/3] Improve name of AdditionalSettings component --- .../src/list/additional-settings.js | 44 ------------------- packages/block-library/src/list/edit.js | 15 ++++--- .../src/list/ordered-list-settings.js | 43 ++++++++++++++++++ ...ive.js => ordered-list-settings.native.js} | 0 4 files changed, 51 insertions(+), 51 deletions(-) delete mode 100644 packages/block-library/src/list/additional-settings.js create mode 100644 packages/block-library/src/list/ordered-list-settings.js rename packages/block-library/src/list/{additional-settings.native.js => ordered-list-settings.native.js} (100%) diff --git a/packages/block-library/src/list/additional-settings.js b/packages/block-library/src/list/additional-settings.js deleted file mode 100644 index 9d12ae443b556..0000000000000 --- a/packages/block-library/src/list/additional-settings.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { InspectorControls } from '@wordpress/block-editor'; -import { - TextControl, - PanelBody, - ToggleControl, -} from '@wordpress/components'; - -const AdditionalSettings = ( { setAttributes, ordered, reversed, start } ) => - ordered && ( - - - { - const int = parseInt( value, 10 ); - - setAttributes( { - // It should be possible to unset the value, - // e.g. with an empty string. - start: isNaN( int ) ? undefined : int, - } ); - } } - value={ Number.isInteger( start ) ? start.toString( 10 ) : '' } - step="1" - /> - { - setAttributes( { - // Unset the attribute if not reversed. - reversed: value || undefined, - } ); - } } - /> - - ); - -export default AdditionalSettings; diff --git a/packages/block-library/src/list/edit.js b/packages/block-library/src/list/edit.js index 4c928d9a8d5dd..53e0edda0ebf8 100644 --- a/packages/block-library/src/list/edit.js +++ b/packages/block-library/src/list/edit.js @@ -23,7 +23,7 @@ import { * Internal dependencies */ import { name } from './'; -import AdditionalSettings from './additional-settings'; +import OrderedListSettings from './ordered-list-settings'; export default function ListEdit( { attributes, @@ -138,11 +138,12 @@ export default function ListEdit( { > { controls } - + { ordered && ( + ) } ; } diff --git a/packages/block-library/src/list/ordered-list-settings.js b/packages/block-library/src/list/ordered-list-settings.js new file mode 100644 index 0000000000000..4cb845f423d65 --- /dev/null +++ b/packages/block-library/src/list/ordered-list-settings.js @@ -0,0 +1,43 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { InspectorControls } from '@wordpress/block-editor'; +import { + TextControl, + PanelBody, + ToggleControl, +} from '@wordpress/components'; + +const OrderedListSettings = ( { setAttributes, reversed, start } ) => ( + + + { + const int = parseInt( value, 10 ); + + setAttributes( { + // It should be possible to unset the value, + // e.g. with an empty string. + start: isNaN( int ) ? undefined : int, + } ); + } } + value={ Number.isInteger( start ) ? start.toString( 10 ) : '' } + step="1" + /> + { + setAttributes( { + // Unset the attribute if not reversed. + reversed: value || undefined, + } ); + } } + /> + + ); + +export default OrderedListSettings; diff --git a/packages/block-library/src/list/additional-settings.native.js b/packages/block-library/src/list/ordered-list-settings.native.js similarity index 100% rename from packages/block-library/src/list/additional-settings.native.js rename to packages/block-library/src/list/ordered-list-settings.native.js