Skip to content

Commit f6ff0a1

Browse files
committed
Rename 'page content lock' to 'page content focus'
1 parent 80678f9 commit f6ff0a1

File tree

19 files changed

+126
-128
lines changed

19 files changed

+126
-128
lines changed

docs/reference-guides/data/data-core-edit-site.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ _Returns_
131131

132132
- `Object`: Settings.
133133

134-
### hasPageContentLock
134+
### hasPageContentFocus
135135

136-
Whether or not the editor is locked so that only page content can be edited.
136+
Whether or not the editor allows only page content to be edited.
137137

138138
_Parameters_
139139

140140
- _state_ `Object`: Global application state.
141141

142142
_Returns_
143143

144-
- `boolean`: Whether or not the editor is locked.
144+
- `boolean`: Whether or not focus is on editing page content.
145145

146146
### isFeatureActive
147147

@@ -280,13 +280,13 @@ _Returns_
280280

281281
- `number`: The resolved template ID for the page route.
282282

283-
### setHasPageContentLock
283+
### setHasPageContentFocus
284284

285-
Sets whether or not the editor is locked so that only page content can be edited.
285+
Sets whether or not the editor allows only page content to be edited.
286286

287287
_Parameters_
288288

289-
- _hasPageContentLock_ `boolean`: True to enable lock, false to disable.
289+
- _hasPageContentFocus_ `boolean`: True to allow only page content to be edited, false to allow template to be edited.
290290

291291
### setHomeTemplateId
292292

packages/edit-site/src/components/block-editor/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import EditorCanvas from './editor-canvas';
3939
import { unlock } from '../../private-apis';
4040
import EditorCanvasContainer from '../editor-canvas-container';
4141
import {
42-
PageContentLock,
43-
usePageContentLockNotifications,
44-
} from '../page-content-lock';
42+
DisableNonPageContentBlocks,
43+
usePageContentFocusNotifications,
44+
} from '../page-content-focus';
4545

4646
const { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );
4747

@@ -53,21 +53,21 @@ const LAYOUT = {
5353

5454
export default function BlockEditor() {
5555
const { setIsInserterOpened } = useDispatch( editSiteStore );
56-
const { storedSettings, templateType, canvasMode, hasPageContentLock } =
56+
const { storedSettings, templateType, canvasMode, hasPageContentFocus } =
5757
useSelect(
5858
( select ) => {
5959
const {
6060
getSettings,
6161
getEditedPostType,
6262
getCanvasMode,
63-
hasPageContentLock: _hasPageContentLock,
63+
hasPageContentFocus: _hasPageContentFocus,
6464
} = unlock( select( editSiteStore ) );
6565

6666
return {
6767
storedSettings: getSettings( setIsInserterOpened ),
6868
templateType: getEditedPostType(),
6969
canvasMode: getCanvasMode(),
70-
hasPageContentLock: _hasPageContentLock(),
70+
hasPageContentFocus: _hasPageContentFocus(),
7171
};
7272
},
7373
[ setIsInserterOpened ]
@@ -146,7 +146,7 @@ export default function BlockEditor() {
146146
contentRef,
147147
useClipboardHandler(),
148148
useTypingObserver(),
149-
usePageContentLockNotifications(),
149+
usePageContentFocusNotifications(),
150150
] );
151151
const isMobileViewport = useViewportMatch( 'small', '<' );
152152
const { clearSelectedBlock } = useDispatch( blockEditorStore );
@@ -172,7 +172,7 @@ export default function BlockEditor() {
172172
onChange={ onChange }
173173
useSubRegistry={ false }
174174
>
175-
{ hasPageContentLock && <PageContentLock /> }
175+
{ hasPageContentFocus && <DisableNonPageContentBlocks /> }
176176
<TemplatePartConverter />
177177
<SidebarInspectorFill>
178178
<BlockInspector />

packages/edit-site/src/components/editor/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ export default function Editor( { isLoading } ) {
7373
isListViewOpen,
7474
showIconLabels,
7575
showBlockBreadcrumbs,
76-
hasPageContentLock,
76+
hasPageContentFocus,
7777
} = useSelect( ( select ) => {
7878
const {
7979
getEditedPostContext,
8080
getEditorMode,
8181
getCanvasMode,
8282
isInserterOpened,
8383
isListViewOpened,
84-
hasPageContentLock: _hasPageContentLock,
84+
hasPageContentFocus: _hasPageContentFocus,
8585
} = unlock( select( editSiteStore ) );
8686
const { __unstableGetEditorMode } = select( blockEditorStore );
8787
const { getActiveComplementaryArea } = select( interfaceStore );
@@ -106,7 +106,7 @@ export default function Editor( { isLoading } ) {
106106
'core/edit-site',
107107
'showBlockBreadcrumbs'
108108
),
109-
hasPageContentLock: _hasPageContentLock(),
109+
hasPageContentFocus: _hasPageContentFocus(),
110110
};
111111
}, [] );
112112
const { setEditedPostContext } = useDispatch( editSiteStore );
@@ -127,7 +127,7 @@ export default function Editor( { isLoading } ) {
127127
const blockContext = useMemo( () => {
128128
const { postType, postId, ...nonPostFields } = context ?? {};
129129
return {
130-
...( hasPageContentLock ? context : nonPostFields ),
130+
...( hasPageContentFocus ? context : nonPostFields ),
131131
queryContext: [
132132
context?.queryContext || { page: 1 },
133133
( newQueryContext ) =>
@@ -140,7 +140,7 @@ export default function Editor( { isLoading } ) {
140140
} ),
141141
],
142142
};
143-
}, [ hasPageContentLock, context, setEditedPostContext ] );
143+
}, [ hasPageContentFocus, context, setEditedPostContext ] );
144144

145145
let title;
146146
if ( hasLoadedPost ) {
@@ -230,7 +230,7 @@ export default function Editor( { isLoading } ) {
230230
shouldShowBlockBreakcrumbs && (
231231
<BlockBreadcrumb
232232
rootLabelText={
233-
hasPageContentLock
233+
hasPageContentFocus
234234
? __( 'Page' )
235235
: __( 'Template' )
236236
}

packages/edit-site/src/components/header-edit-mode/document-actions/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export default function DocumentActions() {
3636
}
3737

3838
function PageDocumentActions() {
39-
const { hasPageContentLock, context } = useSelect(
39+
const { hasPageContentFocus, context } = useSelect(
4040
( select ) => ( {
41-
hasPageContentLock: select( editSiteStore ).hasPageContentLock(),
41+
hasPageContentFocus: select( editSiteStore ).hasPageContentFocus(),
4242
context: select( editSiteStore ).getEditedPostContext(),
4343
} ),
4444
[]
@@ -50,16 +50,16 @@ function PageDocumentActions() {
5050
context.postId
5151
);
5252

53-
const { setHasPageContentLock } = useDispatch( editSiteStore );
53+
const { setHasPageContentFocus } = useDispatch( editSiteStore );
5454

5555
const [ hasEditedTemplate, setHasEditedTemplate ] = useState( false );
56-
const prevHasPageContentLock = useRef( false );
56+
const prevHasPageContentFocus = useRef( false );
5757
useEffect( () => {
58-
if ( prevHasPageContentLock.current && ! hasPageContentLock ) {
58+
if ( prevHasPageContentFocus.current && ! hasPageContentFocus ) {
5959
setHasEditedTemplate( true );
6060
}
61-
prevHasPageContentLock.current = hasPageContentLock;
62-
}, [ hasPageContentLock ] );
61+
prevHasPageContentFocus.current = hasPageContentFocus;
62+
}, [ hasPageContentFocus ] );
6363

6464
if ( ! hasResolved ) {
6565
return null;
@@ -73,7 +73,7 @@ function PageDocumentActions() {
7373
);
7474
}
7575

76-
return hasPageContentLock ? (
76+
return hasPageContentFocus ? (
7777
<BaseDocumentActions
7878
className={ classnames( 'is-page', {
7979
'is-animated': hasEditedTemplate,
@@ -85,7 +85,7 @@ function PageDocumentActions() {
8585
) : (
8686
<TemplateDocumentActions
8787
className="is-animated"
88-
onBack={ () => setHasPageContentLock( true ) }
88+
onBack={ () => setHasPageContentFocus( true ) }
8989
/>
9090
);
9191
}

packages/edit-site/src/components/page-content-lock/constants.js packages/edit-site/src/components/page-content-focus/constants.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const CONTENT_BLOCK_TYPES = [
1+
export const PAGE_CONTENT_BLOCK_TYPES = [
22
'core/post-title',
33
'core/post-featured-image',
44
'core/post-content',

packages/edit-site/src/components/page-content-lock/use-disable-non-content-blocks.js packages/edit-site/src/components/page-content-focus/disable-non-page-content-blocks.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@ import { useEffect } from '@wordpress/element';
1010
* Internal dependencies
1111
*/
1212
import { unlock } from '../../private-apis';
13-
import { CONTENT_BLOCK_TYPES } from './constants';
13+
import { PAGE_CONTENT_BLOCK_TYPES } from './constants';
1414

1515
const { useBlockEditingMode } = unlock( blockEditorPrivateApis );
1616

17+
/**
18+
* Component that when rendered, makes it so that the site editor allows only
19+
* page content to be edited.
20+
*/
21+
export function DisableNonPageContentBlocks() {
22+
useDisableNonPageContentBlocks();
23+
}
24+
1725
/**
1826
* Disables non-content blocks using the `useBlockEditingMode` hook.
1927
*/
20-
export function useDisableNonContentBlocks() {
28+
export function useDisableNonPageContentBlocks() {
2129
useBlockEditingMode( 'disabled' );
2230
useEffect( () => {
2331
addFilter(
2432
'editor.BlockEdit',
2533
'core/edit-site/disable-non-content-blocks',
26-
withDisableNonContentBlocks
34+
withDisableNonPageContentBlocks
2735
);
2836
return () =>
2937
removeFilter(
@@ -33,12 +41,12 @@ export function useDisableNonContentBlocks() {
3341
}, [] );
3442
}
3543

36-
const withDisableNonContentBlocks = createHigherOrderComponent(
44+
const withDisableNonPageContentBlocks = createHigherOrderComponent(
3745
( BlockEdit ) => ( props ) => {
38-
const isContent = CONTENT_BLOCK_TYPES.includes( props.name );
46+
const isContent = PAGE_CONTENT_BLOCK_TYPES.includes( props.name );
3947
const mode = isContent ? 'contentOnly' : undefined;
4048
useBlockEditingMode( mode );
4149
return <BlockEdit { ...props } />;
4250
},
43-
'withBlockEditingMode'
51+
'withDisableNonPageContentBlocks'
4452
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './disable-non-page-content-blocks';
2+
export { usePageContentFocusNotifications } from './use-page-content-focus-notifications';

packages/edit-site/src/components/page-content-lock/use-page-content-lock-notifications.js packages/edit-site/src/components/page-content-focus/use-page-content-focus-notifications.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,38 @@ import { store as editSiteStore } from '../../store';
2020
* (using useMergeRefs()) to
2121
* the editor iframe canvas.
2222
*/
23-
export function usePageContentLockNotifications() {
23+
export function usePageContentFocusNotifications() {
2424
const ref = useEditTemplateNotification();
2525
useBackToPageNotification();
2626
return ref;
2727
}
2828

2929
/**
3030
* Hook that displays a 'Edit your template to edit this block' notification
31-
* when the user is focusing on editing page content and clicks on a locked
31+
* when the user is focusing on editing page content and clicks on a disabled
3232
* template block.
3333
*
3434
* @return {import('react').RefObject<HTMLElement>} Ref which should be passed
3535
* (using useMergeRefs()) to
3636
* the editor iframe canvas.
3737
*/
3838
function useEditTemplateNotification() {
39-
const hasPageContentLock = useSelect(
40-
( select ) => select( editSiteStore ).hasPageContentLock(),
39+
const hasPageContentFocus = useSelect(
40+
( select ) => select( editSiteStore ).hasPageContentFocus(),
4141
[]
4242
);
4343

4444
const alreadySeen = useRef( false );
4545

4646
const { createInfoNotice } = useDispatch( noticesStore );
47-
const { setHasPageContentLock } = useDispatch( editSiteStore );
47+
const { setHasPageContentFocus } = useDispatch( editSiteStore );
4848

4949
return useRefEffect(
5050
( node ) => {
5151
const handleClick = ( event ) => {
5252
if (
5353
! alreadySeen.current &&
54-
hasPageContentLock &&
54+
hasPageContentFocus &&
5555
event.target.classList.contains( 'is-root-container' )
5656
) {
5757
createInfoNotice(
@@ -63,7 +63,7 @@ function useEditTemplateNotification() {
6363
{
6464
label: __( 'Edit template' ),
6565
onClick: () =>
66-
setHasPageContentLock( false ),
66+
setHasPageContentFocus( false ),
6767
},
6868
],
6969
}
@@ -75,10 +75,10 @@ function useEditTemplateNotification() {
7575
return () => node.removeEventListener( 'click', handleClick );
7676
},
7777
[
78-
hasPageContentLock,
78+
hasPageContentFocus,
7979
alreadySeen,
8080
createInfoNotice,
81-
setHasPageContentLock,
81+
setHasPageContentFocus,
8282
]
8383
);
8484
}
@@ -88,41 +88,41 @@ function useEditTemplateNotification() {
8888
* switches from focusing on editing page content to editing a template.
8989
*/
9090
function useBackToPageNotification() {
91-
const hasPageContentLock = useSelect(
92-
( select ) => select( editSiteStore ).hasPageContentLock(),
91+
const hasPageContentFocus = useSelect(
92+
( select ) => select( editSiteStore ).hasPageContentFocus(),
9393
[]
9494
);
9595

9696
const alreadySeen = useRef( false );
97-
const prevHasPageContentLock = useRef( false );
97+
const prevHasPageContentFocus = useRef( false );
9898

9999
const { createInfoNotice } = useDispatch( noticesStore );
100-
const { setHasPageContentLock } = useDispatch( editSiteStore );
100+
const { setHasPageContentFocus } = useDispatch( editSiteStore );
101101

102102
useEffect( () => {
103103
if (
104104
! alreadySeen.current &&
105-
prevHasPageContentLock.current &&
106-
! hasPageContentLock
105+
prevHasPageContentFocus.current &&
106+
! hasPageContentFocus
107107
) {
108108
createInfoNotice( __( 'You are editing a template' ), {
109109
isDismissible: true,
110110
type: 'snackbar',
111111
actions: [
112112
{
113113
label: __( 'Back to page' ),
114-
onClick: () => setHasPageContentLock( true ),
114+
onClick: () => setHasPageContentFocus( true ),
115115
},
116116
],
117117
} );
118118
alreadySeen.current = true;
119119
}
120-
prevHasPageContentLock.current = hasPageContentLock;
120+
prevHasPageContentFocus.current = hasPageContentFocus;
121121
}, [
122122
alreadySeen,
123-
prevHasPageContentLock,
124-
hasPageContentLock,
123+
prevHasPageContentFocus,
124+
hasPageContentFocus,
125125
createInfoNotice,
126-
setHasPageContentLock,
126+
setHasPageContentFocus,
127127
] );
128128
}

packages/edit-site/src/components/page-content-lock/index.js

-14
This file was deleted.

0 commit comments

Comments
 (0)