Skip to content

Commit

Permalink
pass explicit prop to disable rich text editing
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Feb 12, 2024
1 parent 94ad853 commit 7f33f24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
12 changes: 8 additions & 4 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function RichTextWrapper(
__unstableDisableFormats: disableFormats,
disableLineBreaks,
__unstableAllowPrefixTransformations,
disableEditing,
...props
},
forwardedRef
Expand Down Expand Up @@ -147,7 +148,7 @@ export function RichTextWrapper(
}

// Disable Rich Text editing if block bindings specify that.
let shouldDisableEditing = false;
let disableBoundBlocks = false;
if ( blockBindings && blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS ) {
const blockTypeAttributes = getBlockType( blockName ).attributes;
const { getBlockBindingsSource } = unlock(
Expand All @@ -163,7 +164,7 @@ export function RichTextWrapper(
'rich-text' &&
getBlockBindingsSource( args.source )?.lockAttributesEditing
) {
shouldDisableEditing = true;
disableBoundBlocks = true;
break;
}
}
Expand All @@ -173,16 +174,19 @@ export function RichTextWrapper(
selectionStart: isSelected ? selectionStart.offset : undefined,
selectionEnd: isSelected ? selectionEnd.offset : undefined,
isSelected,
shouldDisableEditing,
disableBoundBlocks,
};
};
const { selectionStart, selectionEnd, isSelected, shouldDisableEditing } =
const { selectionStart, selectionEnd, isSelected, disableBoundBlocks } =
useSelect( selector, [
clientId,
identifier,
originalIsSelected,
isBlockSelected,
] );

const shouldDisableEditing = disableEditing || disableBoundBlocks;

const { getSelectionStart, getSelectionEnd, getBlockRootClientId } =
useSelect( blockEditorStore );
const { selectionChange } = useDispatch( blockEditorStore );
Expand Down
25 changes: 9 additions & 16 deletions packages/block-library/src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,15 @@ export default function Image( {
{ ! temporaryURL && controls }
{ img }

{ lockCaption && (
<figcaption>{ attributes.caption?.toHTMLString() }</figcaption>
) }

{ ! lockCaption && (
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={
isSingleSelected && hasNonContentControls
}
/>
) }
<Caption
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSingleSelected }
insertBlocksAfter={ insertBlocksAfter }
label={ __( 'Image caption text' ) }
showToolbarButton={ isSingleSelected && hasNonContentControls }
disableEditing={ lockCaption }
/>
</>
);
}
2 changes: 2 additions & 0 deletions packages/block-library/src/utils/caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function Caption( {
label = __( 'Caption text' ),
showToolbarButton = true,
className,
disableEditing,
} ) {
const caption = attributes[ key ];
const prevCaption = usePrevious( caption );
Expand Down Expand Up @@ -101,6 +102,7 @@ export function Caption( {
createBlock( getDefaultBlockName() )
)
}
disableEditing={ disableEditing }
/>
) }
</>
Expand Down

0 comments on commit 7f33f24

Please sign in to comment.