-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cef5825
commit eea24a5
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/edit-site/src/components/header/more-menu/copy-content-menu-item.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { MenuItem } from '@wordpress/components'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useCopyToClipboard } from '@wordpress/compose'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { __unstableSerializeAndClean } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { store as editSiteStore } from '../../../store'; | ||
|
||
export default function CopyContentMenuItem() { | ||
const { createNotice } = useDispatch( noticesStore ); | ||
const getText = useSelect( ( select ) => { | ||
return () => { | ||
const { getEditedPostId, getEditedPostType } = select( | ||
editSiteStore | ||
); | ||
const { getEditedEntityRecord } = select( coreStore ); | ||
const record = getEditedEntityRecord( | ||
'postType', | ||
getEditedPostType(), | ||
getEditedPostId() | ||
); | ||
if ( record ) { | ||
if ( typeof record.content === 'function' ) { | ||
return record.content( record ); | ||
} else if ( record.blocks ) { | ||
return __unstableSerializeAndClean( record.blocks ); | ||
} else if ( record.content ) { | ||
return record.content; | ||
} | ||
} | ||
return ''; | ||
}; | ||
}, [] ); | ||
|
||
function onSuccess() { | ||
createNotice( 'info', __( 'All content copied.' ), { | ||
isDismissible: true, | ||
type: 'snackbar', | ||
} ); | ||
} | ||
|
||
const ref = useCopyToClipboard( getText, onSuccess ); | ||
|
||
return <MenuItem ref={ ref }>{ __( 'Copy all content' ) }</MenuItem>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters