Skip to content

Commit 2968668

Browse files
Suggestions: Render block-insert-after pending state in canvas and sidebar
Brings the visual treatment for block-insert-after suggestions: - style.scss adds the pending-insert treatment: 70% opacity plus a dashed green outline. The dashed style distinguishes it from the solid bracket used by pending attribute edits — both treatments can apply to the same block when a user inserts and then immediately edits its attributes. - suggestion-summary.js adds an "Insert block: <name>" line via the same friendlyBlockName helper that handles block-remove. Falls back to "block" when the op carries no name. - suggestion-diff.js adds BlockInsertDiff, which renders the captured block snapshot's text via collectBlockText with <ins> styling. When the inserted block has no text yet (an empty paragraph), falls back to a "New block: <name>" label so the sidebar isn't blank. Refs #77434.
1 parent f083328 commit 2968668

4 files changed

Lines changed: 70 additions & 0 deletions

File tree

packages/editor/src/components/suggestion-mode/style.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ $suggestion-color: #007017;
5757
}
5858
}
5959

60+
// Pending-insert: the block was inserted in Suggest mode but isn't yet
61+
// "real" — the marker indicates it's proposed but not committed. A
62+
// dashed green outline distinguishes it from the solid bracket used by
63+
// pending attribute edits, and reduced opacity de-emphasizes the
64+
// content without hiding it. Apply clears the marker; Reject runs
65+
// removeBlock to undo the insert.
66+
.block-editor-block-list__block.is-suggestion-pending-insert {
67+
position: relative;
68+
opacity: 0.7;
69+
outline: 2px dashed $suggestion-color;
70+
outline-offset: 2px;
71+
border-radius: $radius-small;
72+
}
73+
6074
.editor-collab-sidebar-panel__suggestion-summary {
6175
em {
6276
font-style: italic;

packages/editor/src/components/suggestion-mode/suggestion-diff.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ function DiffForOperation( { operation } ) {
166166
if ( operation.type === 'block-remove' ) {
167167
return <BlockRemoveDiff operation={ operation } />;
168168
}
169+
if ( operation.type === 'block-insert-after' ) {
170+
return <BlockInsertDiff operation={ operation } />;
171+
}
169172
if (
170173
operation.type === 'attribute-set' &&
171174
isTextValue( operation.before ) &&
@@ -262,6 +265,37 @@ function BlockRemoveDiff( { operation } ) {
262265
);
263266
}
264267

268+
/**
269+
* Render a `block-insert-after` op as an underlined inserted-block preview.
270+
* The captured snapshot (`op.block`) carries the proposed block as it was
271+
* at insertion time; `collectBlockText` walks its content and innerBlocks
272+
* to produce a textual preview.
273+
*
274+
* Falls back to "Insert block: <name>" when the op carries no usable text
275+
* (an inserted block with no content yet, e.g. an empty paragraph).
276+
*
277+
* @param {{ operation: { blockName?: string, block?: Object } }} props
278+
*/
279+
function BlockInsertDiff( { operation } ) {
280+
const blockName = operation.blockName ?? operation.block?.name ?? '';
281+
const innerText = collectBlockText( operation.block );
282+
const fallbackLabel = blockName
283+
? // translators: %s: block name (e.g. "core/paragraph").
284+
__( 'New block: %s' ).replace( '%s', blockName )
285+
: __( 'New block proposed.' );
286+
return (
287+
<WCText
288+
size="13px"
289+
className="editor-collab-sidebar-panel__suggestion-text-diff"
290+
>
291+
<ins>
292+
<VisuallyHidden>{ __( 'Inserted:' ) }</VisuallyHidden>
293+
{ innerText || fallbackLabel }
294+
</ins>
295+
</WCText>
296+
);
297+
}
298+
265299
/**
266300
* Concatenate the text content of a serialized block snapshot for use in
267301
* the sidebar diff preview. Walks `attributes.content` (RichText-backed

packages/editor/src/components/suggestion-mode/suggestion-summary.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ export function summarizeOperations( operations ) {
250250
} );
251251
continue;
252252
}
253+
if ( op.type === 'block-insert-after' ) {
254+
lines.push( {
255+
label: __( 'Insert block:' ),
256+
value: friendlyBlockName( op.blockName ),
257+
} );
258+
continue;
259+
}
253260
if ( op.type !== 'attribute-set' ) {
254261
attributeLabels.push( op.attribute );
255262
continue;

packages/editor/src/components/suggestion-mode/test/suggestion-summary.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,19 @@ describe( 'summarizeOperations', () => {
234234
{ label: 'Remove block:', value: 'custom-block' },
235235
] );
236236
} );
237+
238+
it( 'summarizes a block-insert-after op as "Insert block: <name>"', () => {
239+
const lines = summarizeOperations( [
240+
{
241+
type: 'block-insert-after',
242+
clientId: 'abc',
243+
blockName: 'core/paragraph',
244+
anchorClientId: null,
245+
parentClientId: null,
246+
},
247+
] );
248+
expect( lines ).toEqual( [
249+
{ label: 'Insert block:', value: 'paragraph' },
250+
] );
251+
} );
237252
} );

0 commit comments

Comments
 (0)