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

Extract @wordpress/reusable-blocks from @wordpress/editor #25859

Merged
merged 44 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f59687d
Move reusable blocks logic to separate package
adamziel Oct 6, 2020
61abe81
Add reusable-blocks as a dependency to edit-post package
adamziel Oct 6, 2020
1dc20cb
Import reusable-blocks in edit-post/index.native.js
adamziel Oct 6, 2020
7c84d52
WIP: Use Core Data in Reusable Blocks
noisysocks Oct 7, 2020
f7acff7
Move ReusableBlocksButtons to reusable-blocks package
adamziel Oct 8, 2020
1faf278
Use core data instead of reusable-blocks selectors in the editor package
adamziel Oct 8, 2020
44dbb38
Replace reusable-blocks selectors with core data selectors
adamziel Oct 8, 2020
940ae4e
Remove commented out chunk of code
adamziel Oct 8, 2020
c920ce8
Remove selectors that are no longer used
adamziel Oct 8, 2020
6435783
Reusable blocks based on controls
adamziel Oct 8, 2020
6b70d3b
Simplify store
adamziel Oct 8, 2020
7512896
Remove the concept of fetchReusableBlocks
adamziel Oct 8, 2020
35e788b
Rename convertBlockToReusable to convertBlocksToReusable and update t…
adamziel Oct 8, 2020
50d168f
Add unit tests
adamziel Oct 8, 2020
f480d39
Clean up imports
adamziel Oct 9, 2020
bdb9dc0
Clean up store export
adamziel Oct 9, 2020
84c6849
Update package version
adamziel Oct 9, 2020
cd98331
Clean up imports
adamziel Oct 9, 2020
2aa3085
Update docs
adamziel Oct 9, 2020
ce35f7f
Deduplicate logic from block/edit.js
adamziel Oct 9, 2020
3dae629
Update README
adamziel Oct 9, 2020
1d3ddec
Export storeConfig
adamziel Oct 9, 2020
fd1ecac
Add deleteReusableBlock action
adamziel Oct 9, 2020
b458e98
Update readme
adamziel Oct 9, 2020
9c759b2
Refactor ReusableBlockDeleteButton to use useSelect and useDispatch i…
adamziel Oct 9, 2020
5efbb95
Remove @TODO
adamziel Oct 9, 2020
ecc095b
Use notices as before the refactor
adamziel Oct 9, 2020
1202251
Show notices when reusable block is updated
adamziel Oct 9, 2020
4333419
Remove REUSABLE_BLOCK_NOTICE_ID notice id
adamziel Oct 9, 2020
bc06f59
Update package-lock.json
adamziel Oct 9, 2020
8bf36e2
Embrace entity data format instead of augmenting reusable blocks to l…
adamziel Oct 9, 2020
9d9032e
Don't export storeConfig
adamziel Oct 9, 2020
c2bdc50
Fix mobile unit tests
adamziel Oct 9, 2020
186071c
Fix alphabetical ordering
adamziel Oct 9, 2020
764a59e
Update docstring
adamziel Oct 9, 2020
694a241
Adjust tests to the new data shape
adamziel Oct 9, 2020
7bfce26
Initialize newly created reusable blocks as in editing state
adamziel Oct 9, 2020
c7fff76
Remove outdated test
adamziel Oct 9, 2020
eebe625
Adjust e2e tests
adamziel Oct 12, 2020
96a33f3
Remove obsolete isTemporary
adamziel Oct 13, 2020
f255483
Don't export ReusableBlockDeleteButton twice
adamziel Oct 13, 2020
d5ac446
Don't export ReusableBlockDeleteButton twice
adamziel Oct 13, 2020
acf1fb7
Merge branch 'master' into update/reusable-blocks-package
adamziel Oct 14, 2020
6d2243c
Prettier
adamziel Oct 14, 2020
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/redux-routine/README.md",
"parent": "packages"
},
{
"title": "@wordpress/reusable-blocks",
"slug": "packages-reusable-blocks",
"markdown_source": "../packages/reusable-blocks/README.md",
"parent": "packages"
},
{
"title": "@wordpress/rich-text",
"slug": "packages-rich-text",
Expand Down
34 changes: 34 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 @@ -69,6 +69,7 @@
"@wordpress/react-native-bridge": "file:packages/react-native-bridge",
"@wordpress/react-native-editor": "file:packages/react-native-editor",
"@wordpress/redux-routine": "file:packages/redux-routine",
"@wordpress/reusable-blocks": "file:packages/reusable-blocks",
"@wordpress/rich-text": "file:packages/rich-text",
"@wordpress/server-side-render": "file:packages/server-side-render",
"@wordpress/shortcode": "file:packages/shortcode",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { useEffect } from '@wordpress/element';
import {
createBlock,
createBlocksFromInnerBlocksTemplate,
Expand All @@ -16,31 +15,20 @@ import { useSelect } from '@wordpress/data';
* @return {Array} Returns the block types state. (block types, categories, collections, onSelect handler)
*/
const useBlockTypesState = ( rootClientId, onInsert ) => {
const { categories, collections, items, fetchReusableBlocks } = useSelect(
const { categories, collections, items } = useSelect(
( select ) => {
const { getInserterItems, getSettings } = select(
'core/block-editor'
);
const { getInserterItems } = select( 'core/block-editor' );
const { getCategories, getCollections } = select( 'core/blocks' );
const { __experimentalFetchReusableBlocks } = getSettings();

return {
categories: getCategories(),
collections: getCollections(),
items: getInserterItems( rootClientId ),
fetchReusableBlocks: __experimentalFetchReusableBlocks,
};
},
[ rootClientId ]
);

// Fetch resuable blocks on mount
useEffect( () => {
if ( fetchReusableBlocks ) {
fetchReusableBlocks();
}
}, [] );

const onSelectItem = ( { name, initialAttributes, innerBlocks } ) => {
const insertedBlock = createBlock(
name,
Expand Down
6 changes: 4 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ export const getInserterItems = createSelector(
id,
name: 'core/block',
initialAttributes: { ref: reusableBlock.id },
title: reusableBlock.title,
title: reusableBlock.title.raw,
icon: referencedBlockType
? referencedBlockType.icon
: templateIcon,
Expand Down Expand Up @@ -1695,7 +1695,9 @@ export const __experimentalGetParsedReusableBlock = createSelector(
return null;
}

return parse( reusableBlock.content );
// Only reusableBlock.content.raw should be used here, `reusableBlock.content` is a
// workaround until #22127 is fixed.
return parse( reusableBlock.content.raw || reusableBlock.content );
},
( state ) => [ getReusableBlocks( state ) ]
);
Expand Down
12 changes: 6 additions & 6 deletions packages/block-editor/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2476,8 +2476,8 @@ describe( 'selectors', () => {
id: 1,
isTemporary: false,
clientId: 'block1',
title: 'Reusable Block 1',
content: '<!-- /wp:test-block-a -->',
title: { raw: 'Reusable Block 1' },
content: { raw: '<!-- /wp:test-block-a -->' },
},
],
},
Expand Down Expand Up @@ -2556,15 +2556,15 @@ describe( 'selectors', () => {
id: 1,
isTemporary: false,
clientId: 'block1',
title: 'Reusable Block 1',
content: '<!-- /wp:test-block-a -->',
title: { raw: 'Reusable Block 1' },
content: { raw: '<!-- /wp:test-block-a -->' },
},
{
id: 2,
isTemporary: false,
clientId: 'block2',
title: 'Reusable Block 2',
content: '<!-- /wp:test-block-b -->',
title: { raw: 'Reusable Block 2' },
content: { raw: '<!-- /wp:test-block-b -->' },
},
],
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/notices": "file:../notices",
"@wordpress/primitives": "file:../primitives",
"@wordpress/reusable-blocks": "file:../reusable-blocks",
"@wordpress/rich-text": "file:../rich-text",
"@wordpress/server-side-render": "file:../server-side-render",
"@wordpress/url": "file:../url",
Expand Down
10 changes: 0 additions & 10 deletions packages/block-library/src/block/edit-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Button } from '@wordpress/components';
import { useInstanceId, usePrevious } from '@wordpress/compose';
import { useEffect, useRef } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { ESCAPE } from '@wordpress/keycodes';

/** @typedef {import('@wordpress/element').WPComponent} WPComponent */

Expand Down Expand Up @@ -44,7 +43,6 @@ export default function ReusableBlockEditPanel( {
isEditDisabled,
isEditing,
isSaving,
onCancel,
onChangeTitle,
onEdit,
onSave,
Expand Down Expand Up @@ -79,13 +77,6 @@ export default function ReusableBlockEditPanel( {
onChangeTitle( event.target.value );
}

function handleTitleKeyDown( event ) {
if ( event.keyCode === ESCAPE ) {
event.stopPropagation();
onCancel();
}
}

return (
<>
{ ! isEditing && ! isSaving && (
Expand Down Expand Up @@ -120,7 +111,6 @@ export default function ReusableBlockEditPanel( {
className="reusable-block-edit-panel__title"
value={ title }
onChange={ handleTitleChange }
onKeyDown={ handleTitleKeyDown }
id={ `reusable-block-edit-panel__title-${ instanceId }` }
/>
<Button
Expand Down
Loading