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

Support passing a context variable to the custom format prepareEditTreeValue #11630

Merged
merged 1 commit into from
Nov 9, 2018
Merged
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
1 change: 1 addition & 0 deletions packages/block-library/src/heading/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function HeadingEdit( {
</PanelBody>
</InspectorControls>
<RichText
identifier="content"
wrapperClassName="wp-block-heading"
tagName={ tagName }
value={ content }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const settings = {
] }
/>
<RichText
identifier="values"
multiline="li"
tagName={ tagName }
unstableGetSettings={ this.getEditorSettings }
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class ParagraphBlock extends Component {
</PanelColorSettings>
</InspectorControls>
<RichText
identifier="content"
tagName="p"
className={ classnames( 'wp-block-paragraph', className, {
'has-text-color': textColor.color,
Expand Down
9 changes: 7 additions & 2 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ import {
import { join, split, create, toHTMLString } from '@wordpress/rich-text';
import { G, Path, SVG } from '@wordpress/components';

const ATTRIBUTE_QUOTE = 'value';
const ATTRIBUTE_CITATION = 'citation';

const blockAttributes = {
value: {
[ ATTRIBUTE_QUOTE ]: {
type: 'string',
source: 'html',
selector: 'blockquote',
multiline: 'p',
default: '',
},
citation: {
[ ATTRIBUTE_CITATION ]: {
type: 'string',
source: 'html',
selector: 'cite',
Expand Down Expand Up @@ -201,6 +204,7 @@ export const settings = {
</BlockControls>
<blockquote className={ className } style={ { textAlign: align } }>
<RichText
identifier={ ATTRIBUTE_QUOTE }
multiline
value={ value }
onChange={
Expand All @@ -222,6 +226,7 @@ export const settings = {
/>
{ ( ! RichText.isEmpty( citation ) || isSelected ) && (
<RichText
identifier={ ATTRIBUTE_CITATION }
value={ citation }
onChange={
( nextCitation ) => setAttributes( {
Expand Down
6 changes: 5 additions & 1 deletion packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,19 +957,23 @@ const RichTextContainer = compose( [
withBlockEditContext( ( context, ownProps ) => {
// When explicitly set as not selected, do nothing.
if ( ownProps.isSelected === false ) {
return {};
return {
clientId: context.clientId,
};
}
// When explicitly set as selected, use the value stored in the context instead.
if ( ownProps.isSelected === true ) {
return {
isSelected: context.isSelected,
clientId: context.clientId,
};
}

// Ensures that only one RichText component can be focused.
return {
isSelected: context.isSelected && context.focusedElement === ownProps.instanceId,
setFocusedElement: context.setFocusedElement,
clientId: context.clientId,
};
} ),
withSelect( ( select ) => {
Expand Down
15 changes: 12 additions & 3 deletions packages/rich-text/src/register-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,23 @@ export function registerFormatType( name, settings ) {
settings.__experimentalGetPropsForEditableTreePreparation
) {
addFilter( 'experimentalRichText', name, ( OriginalComponent ) => {
return withSelect( ( sel ) => ( {
[ `format_${ name }` ]: settings.__experimentalGetPropsForEditableTreePreparation( sel ),
return withSelect( ( sel, { clientId, identifier } ) => ( {
[ `format_${ name }` ]: settings.__experimentalGetPropsForEditableTreePreparation(
sel,
{
richTextIdentifier: identifier,
blockClientId: clientId,
}
),
} ) )( ( props ) => (
<OriginalComponent
{ ...props }
prepareEditableTree={ [
...( props.prepareEditableTree || [] ),
settings.__experimentalCreatePrepareEditableTree( props[ `format_${ name }` ] ),
settings.__experimentalCreatePrepareEditableTree( props[ `format_${ name }` ], {
richTextIdentifier: props.identifier,
blockClientId: props.clientId,
} ),
] }
/>
) );
Expand Down