Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patterns: create patterns package and share the create pattern modal between post editor and site editor #53161

Merged
merged 31 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e067abd
Share the pattern creation modal between block editor and site editor
glendaviesnz Jul 31, 2023
9e33835
Use sync statuses
glendaviesnz Jul 31, 2023
891d6b4
Move the modal to the editor package
glendaviesnz Jul 31, 2023
856bd5c
Remove unused exports
glendaviesnz Jul 31, 2023
c889ada
Update references to reusable blocks
glendaviesnz Jul 31, 2023
d925d88
Some additional tweeks
glendaviesnz Jul 31, 2023
e7a44cf
Some more naming fixes
glendaviesnz Jul 31, 2023
701d922
Fix detach menu
glendaviesnz Jul 31, 2023
7d3fc91
Fix broken import
glendaviesnz Jul 31, 2023
4a8f503
Fix e2e tests
glendaviesnz Jul 31, 2023
3221566
More e2e test fixes
glendaviesnz Jul 31, 2023
1d976e5
create package
glendaviesnz Aug 14, 2023
6f012da
Add docs manifest
glendaviesnz Aug 1, 2023
971e0d5
Keep store private
glendaviesnz Aug 1, 2023
88218f4
Get the styles from the new edit-patterns package enqueued
glendaviesnz Aug 1, 2023
dae2675
add patterns package
glendaviesnz Aug 9, 2023
680af16
Add an optional classname prop
glendaviesnz Aug 3, 2023
411c525
add package
glendaviesnz Aug 14, 2023
378df19
Fix linting issue
glendaviesnz Aug 8, 2023
4a4ea00
update readme to specify block editor dependency
glendaviesnz Aug 9, 2023
76a2040
Reformat readme to highlight internal nature of package at top
glendaviesnz Aug 9, 2023
93c35b5
recreate package-lock.json
glendaviesnz Aug 14, 2023
9cc173d
update package-lock.json
glendaviesnz Aug 14, 2023
5632554
update package-lock.json again
glendaviesnz Aug 14, 2023
4fb9440
Update packages/patterns/package.json
glendaviesnz Aug 14, 2023
feff32a
rebuild package-lock.json again
glendaviesnz Aug 14, 2023
24e7481
rebuild package-lock.json yet again
glendaviesnz Aug 14, 2023
81bce86
rebuild package-lock.json yet again again again
glendaviesnz Aug 14, 2023
e2fc32a
Update the changlog
glendaviesnz Aug 14, 2023
05734f6
Update node engine requirements
glendaviesnz Aug 14, 2023
2313ff8
update package-lock.json again
glendaviesnz Aug 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,12 @@
"markdown_source": "../packages/nux/README.md",
"parent": "packages"
},
{
"title": "@wordpress/patterns",
"slug": "packages-patterns",
"markdown_source": "../packages/patterns/README.md",
"parent": "packages"
},
{
"title": "@wordpress/plugins",
"slug": "packages-plugins",
Expand Down
14 changes: 12 additions & 2 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function gutenberg_register_packages_styles( $styles ) {
$styles,
'wp-editor',
gutenberg_url( 'build/editor/style.css' ),
array( 'wp-components', 'wp-block-editor', 'wp-reusable-blocks' ),
array( 'wp-components', 'wp-block-editor', 'wp-patterns', 'wp-reusable-blocks' ),
$version
);
$styles->add_data( 'wp-editor', 'rtl', 'replace' );
Expand Down Expand Up @@ -324,6 +324,7 @@ function gutenberg_register_packages_styles( $styles ) {
// The block library styles override the "reset" styles.
'wp-reset-editor-styles',
'wp-block-library',
'wp-patterns',
'wp-reusable-blocks',
// Until #37466, we can't specifically add them as editor styles yet,
// so we must hard-code it here as a dependency.
Expand Down Expand Up @@ -417,7 +418,7 @@ function gutenberg_register_packages_styles( $styles ) {
$styles,
'wp-edit-widgets',
gutenberg_url( 'build/edit-widgets/style.css' ),
array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-reusable-blocks', 'wp-widgets' ),
array( 'wp-components', 'wp-block-editor', 'wp-editor', 'wp-edit-blocks', 'wp-patterns', 'wp-reusable-blocks', 'wp-widgets' ),
$version
);
$styles->add_data( 'wp-edit-widgets', 'rtl', 'replace' );
Expand All @@ -440,6 +441,15 @@ function gutenberg_register_packages_styles( $styles ) {
);
$styles->add_data( 'wp-customize-widgets', 'rtl', 'replace' );

gutenberg_override_style(
$styles,
'wp-patterns',
gutenberg_url( 'build/patterns/style.css' ),
array( 'wp-components' ),
$version
);
$styles->add_data( 'wp-patterns', 'rtl', 'replace' );

gutenberg_override_style(
$styles,
'wp-reusable-blocks',
Expand Down
54 changes: 54 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@wordpress/media-utils": "file:packages/media-utils",
"@wordpress/notices": "file:packages/notices",
"@wordpress/nux": "file:packages/nux",
"@wordpress/patterns": "file:packages/patterns",
"@wordpress/plugins": "file:packages/plugins",
"@wordpress/preferences": "file:packages/preferences",
"@wordpress/preferences-persistence": "file:packages/preferences-persistence",
Expand Down
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ $z-layers: (

// Should be above the popover (dropdown)
".reusable-blocks-menu-items__convert-modal": 1000001,
".patterns-menu-items__convert-modal": 1000001,
".edit-site-create-template-part-modal": 1000001,
".block-editor-block-lock-modal": 1000001,
".block-editor-template-part__selection-modal": 1000001,
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-test-utils/src/create-reusable-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { canvas } from './canvas';
*/
export const createReusableBlock = async ( content, title ) => {
const reusableBlockNameInputSelector =
'.reusable-blocks-menu-items__convert-modal .components-text-control__input';
'.patterns-menu-items__convert-modal .components-text-control__input';
const syncToggleSelectorChecked =
'.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked';
'.patterns-menu-items__convert-modal .components-form-toggle.is-checked';
// Insert a paragraph block
await insertBlock( 'Paragraph' );
await page.keyboard.type( content );

await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Create pattern/reusable block' );
await clickMenuItem( 'Create pattern' );
const nameInput = await page.waitForSelector(
reusableBlockNameInputSelector
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ describe( 'block editor keyboard shortcuts', () => {
} );
it( 'should prevent deleting multiple selected blocks from inputs', async () => {
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Create pattern/reusable block' );
await clickMenuItem( 'Create pattern' );
const reusableBlockNameInputSelector =
'.reusable-blocks-menu-items__convert-modal .components-text-control__input';
'.patterns-menu-items__convert-modal .components-text-control__input';
const nameInput = await page.waitForSelector(
reusableBlockNameInputSelector
);
Expand All @@ -102,7 +102,7 @@ describe( 'block editor keyboard shortcuts', () => {
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'Delete' );
await clickOnCloseModalButton(
'.reusable-blocks-menu-items__convert-modal'
'.patterns-menu-items__convert-modal'
);
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {
} from '@wordpress/e2e-test-utils';

const reusableBlockNameInputSelector =
'.reusable-blocks-menu-items__convert-modal .components-text-control__input';
'.patterns-menu-items__convert-modal .components-text-control__input';
const reusableBlockInspectorNameInputSelector =
'.block-editor-block-inspector .components-text-control__input';
const syncToggleSelectorChecked =
'.reusable-blocks-menu-items__convert-modal .components-form-toggle.is-checked';
'.patterns-menu-items__convert-modal .components-form-toggle.is-checked';

const saveAll = async () => {
const publishButtonSelector =
Expand Down Expand Up @@ -196,7 +196,7 @@ describe( 'Reusable blocks', () => {

// Convert block to a reusable block.
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Create pattern/reusable block' );
await clickMenuItem( 'Create pattern' );

// Set title.
const nameInput = await page.waitForSelector(
Expand Down Expand Up @@ -382,7 +382,7 @@ describe( 'Reusable blocks', () => {

// Convert to reusable.
await clickBlockToolbarButton( 'Options' );
await clickMenuItem( 'Create pattern/reusable block' );
await clickMenuItem( 'Create pattern' );
const nameInput = await page.waitForSelector(
reusableBlockNameInputSelector
);
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/patterns": "file:../patterns",
"@wordpress/plugins": "file:../plugins",
"@wordpress/preferences": "file:../preferences",
"@wordpress/primitives": "file:../primitives",
Expand Down
7 changes: 4 additions & 3 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import { __ } from '@wordpress/i18n';
import { plus, symbol, symbolFilled } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';

/**
* Internal dependencies
*/
import CreatePatternModal from '../create-pattern-modal';
import CreateTemplatePartModal from '../create-template-part-modal';
import SidebarButton from '../sidebar-button';
import { unlock } from '../../lock-unlock';
import { store as editSiteStore } from '../../store';

const { useHistory } = unlock( routerPrivateApis );
const { CreatePatternModal } = unlock( editPatternsPrivateApis );

export default function AddNewPattern() {
const history = useHistory();
Expand Down Expand Up @@ -87,8 +88,8 @@ export default function AddNewPattern() {
/>
{ showPatternModal && (
<CreatePatternModal
closeModal={ () => setShowPatternModal( false ) }
onCreate={ handleCreatePattern }
onClose={ () => setShowPatternModal( false ) }
onSuccess={ handleCreatePattern }
onError={ handleError }
/>
) }
Expand Down
7 changes: 4 additions & 3 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*/
import { useSelect } from '@wordpress/data';
import { BlockInspector } from '@wordpress/block-editor';

import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
import { privateApis as editPatternsPrivateApis } from '@wordpress/patterns';

/**
* Internal dependencies
Expand All @@ -15,6 +14,8 @@ import { store as editSiteStore } from '../../store';
import SiteEditorCanvas from './site-editor-canvas';
import getBlockEditorProvider from './get-block-editor-provider';

import { unlock } from '../../lock-unlock';
const { PatternsMenuItems } = unlock( editPatternsPrivateApis );
export default function BlockEditor() {
const entityType = useSelect(
( select ) => select( editSiteStore ).getEditedPostType(),
Expand All @@ -34,7 +35,7 @@ export default function BlockEditor() {

<SiteEditorCanvas />

<ReusableBlocksMenuItems />
<PatternsMenuItems />
</BlockEditorProvider>
);
}
Loading