Skip to content

Commit 8ec99df

Browse files
authored
build: Format with wp-prettier (#101)
* build: Replace prettier with wp-prettier * build: Format code with wp-prettier Adhere to Gutenberg project practices. * fix: Escape script path backslash characters Improve robustness of regular expression logic modifying remote script paths. * fix: Repair editor load notice elevation Ensure notice sits atop editor UI.
1 parent 74a8859 commit 8ec99df

29 files changed

+469
-457
lines changed

Diff for: .eslintrc.cjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module.exports = {
22
root: true,
3-
extends: ['plugin:@wordpress/eslint-plugin/recommended'],
3+
extends: [ 'plugin:@wordpress/eslint-plugin/recommended' ],
44
env: {
55
browser: true,
66
es2020: true,
77
},
8-
ignorePatterns: ['android', 'dist', 'ios'],
8+
ignorePatterns: [ 'android', 'dist', 'ios' ],
99
parserOptions: {
1010
ecmaVersion: 'latest',
1111
sourceType: 'module',
1212
},
13-
plugins: ['react-refresh'],
13+
plugins: [ 'react-refresh' ],
1414
rules: {
1515
'react-refresh/only-export-components': [
1616
'warn',

Diff for: .prettierrc.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('@wordpress/prettier-config');
1+
module.exports = require( '@wordpress/prettier-config' );

Diff for: package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"eslint-plugin-react-refresh": "^0.4.18",
4747
"magic-string": "^0.30.17",
4848
"patch-package": "^8.0.0",
49-
"prettier": "^3.4.2",
49+
"prettier": "npm:wp-prettier@^3.0.3",
5050
"sass-embedded": "^1.83.4",
5151
"vite": "^6.0.11"
5252
},

Diff for: src/components/default-block-appender/index.jsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ import './style.scss';
1818
* @return {JSX.Element} The rendered button element.
1919
*/
2020
export default function DefaultBlockAppender() {
21-
const { insertBlock } = useDispatch(blockEditorStore);
22-
const { blockCount } = useSelect((select) => {
23-
const { getBlockCount } = select(blockEditorStore);
21+
const { insertBlock } = useDispatch( blockEditorStore );
22+
const { blockCount } = useSelect( ( select ) => {
23+
const { getBlockCount } = select( blockEditorStore );
2424
return {
2525
blockCount: getBlockCount(),
2626
};
27-
});
27+
} );
2828

2929
const onAddParagraphBlock = () => {
30-
const paragraphBlock = createBlock('core/paragraph');
31-
insertBlock(paragraphBlock, blockCount);
30+
const paragraphBlock = createBlock( 'core/paragraph' );
31+
insertBlock( paragraphBlock, blockCount );
3232
};
3333

3434
return (
3535
<button
36-
aria-label={__('Add paragraph block')}
37-
onClick={onAddParagraphBlock}
36+
aria-label={ __( 'Add paragraph block' ) }
37+
onClick={ onAddParagraphBlock }
3838
className="gutenberg-kit-default-block-appender"
3939
></button>
4040
);

Diff for: src/components/editor-load-notice.jsx

+25-21
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import { useState, useEffect } from '@wordpress/element';
1313
*
1414
* @return {?JSX.Element} The rendered component or null if no notice is present.
1515
*/
16-
export default function EditorLoadNotice({ className }) {
16+
export default function EditorLoadNotice( { className } ) {
1717
const { notice, clearNotice } = useEditorLoadNotice();
1818

1919
const actions = [
2020
{
2121
label: 'Retry',
22-
onClick: () => (window.location.href = 'remote.html'),
22+
onClick: () => ( window.location.href = 'remote.html' ),
2323
variant: 'primary',
2424
},
2525
{
@@ -29,14 +29,18 @@ export default function EditorLoadNotice({ className }) {
2929
},
3030
];
3131

32-
if (!notice) {
32+
if ( ! notice ) {
3333
return null;
3434
}
3535

3636
return (
37-
<div className={className}>
38-
<Notice actions={actions} status="warning" isDismissible={false}>
39-
{notice}
37+
<div className={ className }>
38+
<Notice
39+
actions={ actions }
40+
status="warning"
41+
isDismissible={ false }
42+
>
43+
{ notice }
4044
</Notice>
4145
</div>
4246
);
@@ -48,14 +52,14 @@ export default function EditorLoadNotice({ className }) {
4852
* @return {{notice:string, clearNotice:()=>void}} The notice message and a function to clear it.
4953
*/
5054
function useEditorLoadNotice() {
51-
const [notice, setNotice] = useState(null);
55+
const [ notice, setNotice ] = useState( null );
5256

53-
useEffect(() => {
54-
const url = new URL(window.location.href);
55-
const error = url.searchParams.get('error');
57+
useEffect( () => {
58+
const url = new URL( window.location.href );
59+
const error = url.searchParams.get( 'error' );
5660

5761
let message = null;
58-
switch (error) {
62+
switch ( error ) {
5963
case REMOTE_EDITOR_LOAD_ERROR:
6064
message = __(
6165
"Oops! We couldn't load your site's editor and plugins. Don't worry, you can use the default editor for now."
@@ -65,19 +69,19 @@ function useEditorLoadNotice() {
6569
message = null;
6670
}
6771

68-
setNotice(message);
69-
}, []);
72+
setNotice( message );
73+
}, [] );
7074

71-
useEffect(() => {
72-
if (notice) {
73-
const timeout = setTimeout(() => {
74-
setNotice(null);
75-
}, 20000);
76-
return () => clearTimeout(timeout);
75+
useEffect( () => {
76+
if ( notice ) {
77+
const timeout = setTimeout( () => {
78+
setNotice( null );
79+
}, 20000 );
80+
return () => clearTimeout( timeout );
7781
}
78-
}, [notice]);
82+
}, [ notice ] );
7983

80-
return { notice, clearNotice: () => setNotice(null) };
84+
return { notice, clearNotice: () => setNotice( null ) };
8185
}
8286

8387
const REMOTE_EDITOR_LOAD_ERROR = 'remote_editor_load_error';

Diff for: src/components/editor-toolbar/index.jsx

+24-24
Original file line numberDiff line numberDiff line change
@@ -33,60 +33,60 @@ import './style.scss';
3333
* @param {string} props.className Component classes.
3434
* @return {JSX.Element} The rendered editor toolbar component.
3535
*/
36-
const EditorToolbar = ({ className }) => {
37-
const [isBlockInspectorShown, setBlockInspectorShown] = useState(false);
38-
const { isSelected } = useSelect((select) => {
39-
const { getSelectedBlockClientId } = select(blockEditorStore);
36+
const EditorToolbar = ( { className } ) => {
37+
const [ isBlockInspectorShown, setBlockInspectorShown ] = useState( false );
38+
const { isSelected } = useSelect( ( select ) => {
39+
const { getSelectedBlockClientId } = select( blockEditorStore );
4040
const selectedBlockClientId = getSelectedBlockClientId();
4141
return {
4242
isSelected: selectedBlockClientId !== null,
4343
};
44-
});
45-
const { isInserterOpened } = useSelect((select) => {
44+
} );
45+
const { isInserterOpened } = useSelect( ( select ) => {
4646
return {
47-
isInserterOpened: select(editorStore).isInserterOpened(),
47+
isInserterOpened: select( editorStore ).isInserterOpened(),
4848
};
49-
}, []);
50-
const { setIsInserterOpened } = useDispatch(editorStore);
49+
}, [] );
50+
const { setIsInserterOpened } = useDispatch( editorStore );
5151

5252
function openSettings() {
53-
setBlockInspectorShown(true);
53+
setBlockInspectorShown( true );
5454
}
5555

5656
function onCloseSettings() {
57-
setBlockInspectorShown(false);
57+
setBlockInspectorShown( false );
5858
}
5959

60-
const classes = clsx('gutenberg-kit-editor-toolbar', className);
60+
const classes = clsx( 'gutenberg-kit-editor-toolbar', className );
6161

6262
return (
6363
<>
6464
<Toolbar
65-
className={classes}
65+
className={ classes }
6666
label="Editor toolbar"
6767
variant="unstyled"
6868
>
6969
<ToolbarGroup>
7070
<Inserter
71-
open={isInserterOpened}
72-
onToggle={setIsInserterOpened}
71+
open={ isInserterOpened }
72+
onToggle={ setIsInserterOpened }
7373
/>
7474
</ToolbarGroup>
7575

76-
{isSelected && (
76+
{ isSelected && (
7777
<ToolbarGroup>
7878
<ToolbarButton
79-
title={__('Open Settings')}
80-
icon={cog}
81-
onClick={openSettings}
79+
title={ __( 'Open Settings' ) }
80+
icon={ cog }
81+
onClick={ openSettings }
8282
/>
8383
</ToolbarGroup>
84-
)}
84+
) }
8585

8686
<BlockToolbar hideDragHandle />
8787
</Toolbar>
8888

89-
{isBlockInspectorShown && (
89+
{ isBlockInspectorShown && (
9090
<Popover
9191
className="block-settings-menu"
9292
variant="unstyled"
@@ -96,14 +96,14 @@ const EditorToolbar = ({ className }) => {
9696
<div className="block-settings-menu__header">
9797
<Button
9898
className="block-settings-menu__close"
99-
icon={close}
100-
onClick={onCloseSettings}
99+
icon={ close }
100+
onClick={ onCloseSettings }
101101
/>
102102
</div>
103103
<BlockInspector />
104104
</>
105105
</Popover>
106-
)}
106+
) }
107107
</>
108108
);
109109
};

Diff for: src/components/editor/index.jsx

+24-24
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ const { ExperimentalBlockEditorProvider: BlockEditorProvider } = unlock(
3939
*
4040
* @return {JSX.Element} The rendered App component.
4141
*/
42-
export default function Editor({ post, children, hideTitle }) {
43-
const editorRef = useRef(null);
44-
useHostBridge(post, editorRef);
42+
export default function Editor( { post, children, hideTitle } ) {
43+
const editorRef = useRef( null );
44+
useHostBridge( post, editorRef );
4545
useSyncHistoryControls();
4646
useHostExceptionLogging();
47-
useEditorSetup(post);
47+
useEditorSetup( post );
4848
useMediaUpload();
4949

50-
const [postBlocks, onInput, onChange] = useEntityBlockEditor(
50+
const [ postBlocks, onInput, onChange ] = useEntityBlockEditor(
5151
'postType',
5252
post.type,
5353
{ id: post.id }
5454
);
5555

56-
const settings = useGBKitSettings(post);
56+
const settings = useGBKitSettings( post );
5757

58-
const { isReady, mode, isRichEditingEnabled } = useSelect((select) => {
58+
const { isReady, mode, isRichEditingEnabled } = useSelect( ( select ) => {
5959
const { __unstableIsEditorReady, getEditorSettings, getEditorMode } =
60-
select(editorStore);
60+
select( editorStore );
6161
const editorSettings = getEditorSettings();
6262

6363
return {
@@ -71,35 +71,35 @@ export default function Editor({ post, children, hideTitle }) {
7171
mode: getEditorMode(),
7272
isRichEditingEnabled: editorSettings.richEditingEnabled,
7373
};
74-
}, []);
74+
}, [] );
7575

76-
if (!isReady) {
76+
if ( ! isReady ) {
7777
return null;
7878
}
7979

8080
return (
81-
<div className="gutenberg-kit-editor" ref={editorRef}>
81+
<div className="gutenberg-kit-editor" ref={ editorRef }>
8282
<BlockEditorProvider
83-
value={postBlocks}
84-
onInput={onInput}
85-
onChange={onChange}
86-
settings={settings}
87-
useSubRegistry={false}
83+
value={ postBlocks }
84+
onInput={ onInput }
85+
onChange={ onChange }
86+
settings={ settings }
87+
useSubRegistry={ false }
8888
>
89-
{mode === 'visual' && isRichEditingEnabled && (
90-
<VisualEditor hideTitle={hideTitle} />
91-
)}
89+
{ mode === 'visual' && isRichEditingEnabled && (
90+
<VisualEditor hideTitle={ hideTitle } />
91+
) }
9292

93-
{(mode === 'text' || !isRichEditingEnabled) && (
93+
{ ( mode === 'text' || ! isRichEditingEnabled ) && (
9494
<TextEditor
9595
// We should auto-focus the canvas (title) on load.
9696
// eslint-disable-next-line jsx-a11y/no-autofocus
97-
autoFocus={true}
98-
hideTitle={hideTitle}
97+
autoFocus={ true }
98+
hideTitle={ hideTitle }
9999
/>
100-
)}
100+
) }
101101

102-
{children}
102+
{ children }
103103
</BlockEditorProvider>
104104
</div>
105105
);

Diff for: src/components/editor/style.scss

-7
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ $min-menu-item-touch-target-size: 42px;
1111
box-sizing: border-box;
1212
}
1313

14-
.gutenberg-kit-editor__load-notice {
15-
bottom: 62px;
16-
left: 16px;
17-
position: fixed;
18-
right: 16px;
19-
}
20-
2114
.gutenberg-kit-editor .components-button {
2215
font-size: $baseline-interactive-font-size;
2316
}

0 commit comments

Comments
 (0)