UNPKG

@wordpress/edit-post

Version:
8 lines (7 loc) 2.24 kB
{ "version": 3, "sources": ["../../../src/components/browser-url/index.js"], "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { addQueryArgs } from '@wordpress/url';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Returns the Post's Edit URL.\n *\n * @param {number} postId Post ID.\n *\n * @return {string} Post edit URL.\n */\nexport function getPostEditURL( postId ) {\n\treturn addQueryArgs( 'post.php', { post: postId, action: 'edit' } );\n}\n\nexport default function BrowserURL() {\n\tconst [ historyId, setHistoryId ] = useState( null );\n\tconst { postId, postStatus } = useSelect( ( select ) => {\n\t\tconst { getCurrentPost } = select( editorStore );\n\t\tconst post = getCurrentPost();\n\t\tlet { id, status, type } = post;\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\ttype\n\t\t);\n\t\tif ( isTemplate ) {\n\t\t\tid = post.wp_id;\n\t\t}\n\n\t\treturn {\n\t\t\tpostId: id,\n\t\t\tpostStatus: status,\n\t\t};\n\t}, [] );\n\n\tuseEffect( () => {\n\t\tif ( postId && postId !== historyId && postStatus !== 'auto-draft' ) {\n\t\t\twindow.history.replaceState(\n\t\t\t\t{ id: postId },\n\t\t\t\t'Post ' + postId,\n\t\t\t\tgetPostEditURL( postId )\n\t\t\t);\n\t\t\tsetHistoryId( postId );\n\t\t}\n\t}, [ postId, postStatus, historyId ] );\n\n\treturn null;\n}\n"], "mappings": ";AAGA,SAAS,WAAW,gBAAgB;AACpC,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,SAAS,mBAAmB;AAS9B,SAAS,eAAgB,QAAS;AACxC,SAAO,aAAc,YAAY,EAAE,MAAM,QAAQ,QAAQ,OAAO,CAAE;AACnE;AAEe,SAAR,aAA8B;AACpC,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,IAAK;AACnD,QAAM,EAAE,QAAQ,WAAW,IAAI,UAAW,CAAE,WAAY;AACvD,UAAM,EAAE,eAAe,IAAI,OAAQ,WAAY;AAC/C,UAAM,OAAO,eAAe;AAC5B,QAAI,EAAE,IAAI,QAAQ,KAAK,IAAI;AAC3B,UAAM,aAAa,CAAE,eAAe,kBAAmB,EAAE;AAAA,MACxD;AAAA,IACD;AACA,QAAK,YAAa;AACjB,WAAK,KAAK;AAAA,IACX;AAEA,WAAO;AAAA,MACN,QAAQ;AAAA,MACR,YAAY;AAAA,IACb;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,YAAW,MAAM;AAChB,QAAK,UAAU,WAAW,aAAa,eAAe,cAAe;AACpE,aAAO,QAAQ;AAAA,QACd,EAAE,IAAI,OAAO;AAAA,QACb,UAAU;AAAA,QACV,eAAgB,MAAO;AAAA,MACxB;AACA,mBAAc,MAAO;AAAA,IACtB;AAAA,EACD,GAAG,CAAE,QAAQ,YAAY,SAAU,CAAE;AAErC,SAAO;AACR;", "names": [] }