Skip to content

Commit 2341905

Browse files
authored
Apply content only mode (#207)
* Add content only mode * Add e2e test * Fix lint * Fix e2e test
1 parent b58a4ee commit 2341905

File tree

5 files changed

+89
-29
lines changed

5 files changed

+89
-29
lines changed

src/block.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"caption": {
4343
"type": "string",
4444
"source": "html",
45-
"selector": "figcaption"
45+
"selector": "figcaption",
46+
"__experimentalRole": "content"
4647
},
4748
"captionStyles": {
4849
"type": "string",
@@ -64,7 +65,8 @@
6465
"query": {
6566
"content": {
6667
"type": "string",
67-
"source": "html"
68+
"source": "html",
69+
"__experimentalRole": "content"
6870
},
6971
"styles": {
7072
"type": "string",
@@ -124,7 +126,8 @@
124126
"query": {
125127
"content": {
126128
"type": "string",
127-
"source": "html"
129+
"source": "html",
130+
"__experimentalRole": "content"
128131
},
129132
"styles": {
130133
"type": "string",
@@ -184,7 +187,8 @@
184187
"query": {
185188
"content": {
186189
"type": "string",
187-
"source": "html"
190+
"source": "html",
191+
"__experimentalRole": "content"
188192
},
189193
"styles": {
190194
"type": "string",

src/edit.tsx

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import type { Properties } from 'csstype';
1010
import { __ } from '@wordpress/i18n';
1111
import { useEffect, useState } from '@wordpress/element';
1212
import { useSelect, useDispatch } from '@wordpress/data';
13-
import { InspectorControls, BlockControls, useBlockProps } from '@wordpress/block-editor';
13+
import {
14+
InspectorControls,
15+
BlockControls,
16+
useBlockProps,
17+
// @ts-ignore: has no exported member
18+
useBlockEditingMode,
19+
} from '@wordpress/block-editor';
1420
import {
1521
// @ts-ignore: has no exported member
1622
ToolbarDropdownMenu,
@@ -79,6 +85,8 @@ function TableEdit( props: BlockEditProps< BlockAttributes > ) {
7985
[]
8086
);
8187
const { createWarningNotice } = useDispatch( noticesStore );
88+
const blockEditingMode = useBlockEditingMode();
89+
const isContentOnlyMode = blockEditingMode === 'contentOnly';
8290

8391
// Release cell selection.
8492
useEffect( () => {
@@ -256,6 +264,7 @@ function TableEdit( props: BlockEditProps< BlockAttributes > ) {
256264
[ `is-content-justification-${ contentJustification }` ]: contentJustification,
257265
'show-dot-on-th': options.show_dot_on_th,
258266
'show-control-button': options.show_control_button,
267+
'is-content-only': isContentOnlyMode,
259268
} ),
260269
} );
261270

@@ -270,6 +279,7 @@ function TableEdit( props: BlockEditProps< BlockAttributes > ) {
270279
setSelectedCells,
271280
selectedLine,
272281
setSelectedLine,
282+
isContentOnlyMode,
273283
};
274284

275285
const tableSettingsProps = {
@@ -316,28 +326,33 @@ function TableEdit( props: BlockEditProps< BlockAttributes > ) {
316326
) }
317327
{ ! isEmpty && (
318328
<figure { ...tableFigureProps }>
319-
<BlockControls
320-
// @ts-ignore: `group` prop is not exist at @types
321-
group="block"
322-
>
323-
<ToolbarDropdownMenu
324-
label={ __( 'Change table justification', 'flexible-table-block' ) }
325-
icon={
326-
( contentJustification &&
327-
TableJustifyControls.find( ( control ) => control.value === contentJustification )
328-
?.icon ) ||
329-
justifyLeft
330-
}
331-
controls={ TableJustifyControls }
332-
hasArrowIndicator
333-
/>
334-
<ToolbarDropdownMenu
335-
label={ __( 'Edit table', 'flexible-table-block' ) }
336-
icon={ blockTable }
337-
controls={ TableEditControls }
338-
hasArrowIndicator
339-
/>
340-
</BlockControls>
329+
{ ! isContentOnlyMode && (
330+
<>
331+
<BlockControls
332+
// @ts-ignore: `group` prop is not exist at @types
333+
group="block"
334+
>
335+
<ToolbarDropdownMenu
336+
label={ __( 'Change table justification', 'flexible-table-block' ) }
337+
icon={
338+
( contentJustification &&
339+
TableJustifyControls.find(
340+
( control ) => control.value === contentJustification
341+
)?.icon ) ||
342+
justifyLeft
343+
}
344+
controls={ TableJustifyControls }
345+
hasArrowIndicator
346+
/>
347+
<ToolbarDropdownMenu
348+
label={ __( 'Edit table', 'flexible-table-block' ) }
349+
icon={ blockTable }
350+
controls={ TableEditControls }
351+
hasArrowIndicator
352+
/>
353+
</BlockControls>
354+
</>
355+
) }
341356
<InspectorControls>
342357
<PanelBody
343358
title={ __( 'Table settings', 'flexible-table-block' ) }

src/editor.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
border-radius: 50%;
6868
}
6969

70-
&.show-control-button {
70+
&.show-control-button:not(.is-content-only) {
7171
padding-left: 40px;
7272

7373
&.is-caption-side-bottom {

src/elements/table.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type Props = {
6767
setSelectedCells: Dispatch< SetStateAction< VSelectedCells > >;
6868
selectedLine: VSelectedLine;
6969
setSelectedLine: Dispatch< SetStateAction< VSelectedLine > >;
70+
isContentOnlyMode: boolean;
7071
};
7172

7273
export default function Table( {
@@ -80,6 +81,7 @@ export default function Table( {
8081
setSelectedCells,
8182
selectedLine,
8283
setSelectedLine,
84+
isContentOnlyMode,
8385
}: Props ) {
8486
const { hasFixedLayout, isStackedOnMobile, sticky } = attributes;
8587

@@ -465,6 +467,7 @@ export default function Table( {
465467
onClick={ ( event: MouseEvent ) => onClickCell( event, cell ) }
466468
>
467469
{ isSelected &&
470+
! isContentOnlyMode &&
468471
options.show_label_on_section &&
469472
rowIndex === 0 &&
470473
vColIndex === 0 && (
@@ -480,7 +483,7 @@ export default function Table( {
480483
{ `t${ sectionName }` }
481484
</Button>
482485
) }
483-
{ isSelected && options.show_control_button && (
486+
{ isSelected && ! isContentOnlyMode && options.show_control_button && (
484487
<>
485488
{ rowIndex === 0 && vColIndex === 0 && (
486489
<Button
@@ -613,6 +616,7 @@ export default function Table( {
613616
aria-label={ CELL_ARIA_LABEL[ sectionName as SectionName ] }
614617
/>
615618
{ isSelected &&
619+
! isContentOnlyMode &&
616620
options.show_control_button &&
617621
sectionIndex === 0 &&
618622
rowIndex === 0 && (

test/e2e/specs/various.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
5+
6+
/**
7+
* Internal dependencies
8+
*/
9+
import FlexibleTableBlockUtils from '../util';
10+
11+
test.use( {
12+
fsbUtils: async ( { page, editor }, use ) => {
13+
await use( new FlexibleTableBlockUtils( { page, editor } ) );
14+
},
15+
} );
16+
17+
test.describe( 'Various', () => {
18+
test.beforeEach( async ( { admin } ) => {
19+
await admin.createNewPost();
20+
} );
21+
22+
test( 'contentOnly mode should be enabled', async ( { editor, page } ) => {
23+
await editor.insertBlock( {
24+
name: 'core/group',
25+
attributes: {
26+
templateLock: 'contentOnly',
27+
},
28+
innerBlocks: [ { name: 'flexible-table-block/table' } ],
29+
} );
30+
await editor.canvas.getByRole( 'button', { name: 'Create Table' } ).click();
31+
await expect(
32+
page
33+
.getByRole( 'region', { name: 'Editor settings' } )
34+
.getByRole( 'button', { name: 'Flexible Table' } )
35+
).toBeVisible();
36+
} );
37+
} );

0 commit comments

Comments
 (0)