UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 4 kB
{ "version": 3, "sources": ["../../../src/components/post-trash/index.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { store as editorStore } from '../../store';\nimport PostTrashCheck from './check';\n\n/**\n * Displays the Post Trash Button and Confirm Dialog in the Editor.\n *\n * @param {?{onActionPerformed: Object}} An object containing the onActionPerformed function.\n * @return {React.ReactNode} The rendered PostTrash component.\n */\nexport default function PostTrash( { onActionPerformed } ) {\n\tconst registry = useRegistry();\n\tconst { isNew, isDeleting, postId, title } = useSelect( ( select ) => {\n\t\tconst store = select( editorStore );\n\t\treturn {\n\t\t\tisNew: store.isEditedPostNew(),\n\t\t\tisDeleting: store.isDeletingPost(),\n\t\t\tpostId: store.getCurrentPostId(),\n\t\t\ttitle: store.getCurrentPostAttribute( 'title' ),\n\t\t};\n\t}, [] );\n\tconst { trashPost } = useDispatch( editorStore );\n\tconst [ showConfirmDialog, setShowConfirmDialog ] = useState( false );\n\n\tif ( isNew || ! postId ) {\n\t\treturn null;\n\t}\n\n\tconst handleConfirm = async () => {\n\t\tsetShowConfirmDialog( false );\n\t\tawait trashPost();\n\t\tconst item = await registry\n\t\t\t.resolveSelect( editorStore )\n\t\t\t.getCurrentPost();\n\t\t// After the post is trashed, we want to trigger the onActionPerformed callback, so the user is redirect\n\t\t// to the post view depending on if the user is on post editor or site editor.\n\t\tonActionPerformed?.( 'move-to-trash', [ item ] );\n\t};\n\treturn (\n\t\t<PostTrashCheck>\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\tclassName=\"editor-post-trash\"\n\t\t\t\tisDestructive\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tisBusy={ isDeleting }\n\t\t\t\taria-disabled={ isDeleting }\n\t\t\t\tonClick={\n\t\t\t\t\tisDeleting ? undefined : () => setShowConfirmDialog( true )\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ __( 'Move to trash' ) }\n\t\t\t</Button>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ showConfirmDialog }\n\t\t\t\tonConfirm={ handleConfirm }\n\t\t\t\tonCancel={ () => setShowConfirmDialog( false ) }\n\t\t\t\tconfirmButtonText={ __( 'Move to trash' ) }\n\t\t\t\tsize=\"small\"\n\t\t\t>\n\t\t\t\t{ sprintf(\n\t\t\t\t\t// translators: %s: The item's title.\n\t\t\t\t\t__( 'Are you sure you want to move \"%s\" to the trash?' ),\n\t\t\t\t\ttitle\n\t\t\t\t) }\n\t\t\t</ConfirmDialog>\n\t\t</PostTrashCheck>\n\t);\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,wBAGO;AACP,kBAAoD;AACpD,qBAAyB;AAKzB,mBAAqC;AACrC,mBAA2B;AAqCzB;AA7Ba,SAAR,UAA4B,EAAE,kBAAkB,GAAI;AAC1D,QAAM,eAAW,yBAAY;AAC7B,QAAM,EAAE,OAAO,YAAY,QAAQ,MAAM,QAAI,uBAAW,CAAE,WAAY;AACrE,UAAM,QAAQ,OAAQ,aAAAA,KAAY;AAClC,WAAO;AAAA,MACN,OAAO,MAAM,gBAAgB;AAAA,MAC7B,YAAY,MAAM,eAAe;AAAA,MACjC,QAAQ,MAAM,iBAAiB;AAAA,MAC/B,OAAO,MAAM,wBAAyB,OAAQ;AAAA,IAC/C;AAAA,EACD,GAAG,CAAC,CAAE;AACN,QAAM,EAAE,UAAU,QAAI,yBAAa,aAAAA,KAAY;AAC/C,QAAM,CAAE,mBAAmB,oBAAqB,QAAI,yBAAU,KAAM;AAEpE,MAAK,SAAS,CAAE,QAAS;AACxB,WAAO;AAAA,E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