Skip to content

Commit

Permalink
Remove @wordpress/editor as a dependency from @wordpress/block-librar…
Browse files Browse the repository at this point in the history
…y when GUTENBERG_PHASE is 1 (#32801)
  • Loading branch information
noisysocks authored and youknowriad committed Jun 21, 2021
1 parent f55eb92 commit b4dddc2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion packages/block-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@wordpress/date": "file:../date",
"@wordpress/deprecated": "file:../deprecated",
"@wordpress/dom": "file:../dom",
"@wordpress/editor": "file:../editor",
"@wordpress/element": "file:../element",
"@wordpress/escape-html": "file:../escape-html",
"@wordpress/hooks": "file:../hooks",
Expand Down
24 changes: 15 additions & 9 deletions packages/block-library/src/calendar/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Disabled } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import ServerSideRender from '@wordpress/server-side-render';
import { useBlockProps } from '@wordpress/block-editor';
import { store as editorStore } from '@wordpress/editor';

const getYearMonth = memoize( ( date ) => {
if ( ! date ) {
Expand All @@ -26,15 +25,22 @@ const getYearMonth = memoize( ( date ) => {

export default function CalendarEdit( { attributes } ) {
const date = useSelect( ( select ) => {
const { getEditedPostAttribute } = select( editorStore );
// FIXME: @wordpress/block-library should not depend on @wordpress/editor.
// Blocks can be loaded into a *non-post* block editor.
// eslint-disable-next-line @wordpress/data-no-store-string-literals
const editorSelectors = select( 'core/editor' );
let _date;
if ( editorSelectors ) {
const postType = editorSelectors.getEditedPostAttribute( 'type' );
// Dates are used to overwrite year and month used on the calendar.
// This overwrite should only happen for 'post' post types.
// For other post types the calendar always displays the current month.
if ( postType === 'post' ) {
_date = editorSelectors.getEditedPostAttribute( 'date' );
}
}

const postType = getEditedPostAttribute( 'type' );
// Dates are used to overwrite year and month used on the calendar.
// This overwrite should only happen for 'post' post types.
// For other post types the calendar always displays the current month.
return postType === 'post'
? getEditedPostAttribute( 'date' )
: undefined;
return _date;
}, [] );

return (
Expand Down

0 comments on commit b4dddc2

Please sign in to comment.