UNPKG

4.9 kBSource Map (JSON)View Raw
1{"version":3,"sources":["@wordpress/edit-post/src/components/browser-url/index.js"],"names":["Component","withSelect","addQueryArgs","getPostEditURL","postId","post","action","getPostTrashedURL","postType","trashed","post_type","ids","BrowserURL","arguments","state","historyId","prevProps","props","postStatus","setTrashURL","setBrowserURL","window","location","href","history","replaceState","id","setState","select","getCurrentPost","status","type"],"mappings":";;;;;;AAAA;;;AAGA,SAASA,SAAT,QAA0B,oBAA1B;AACA,SAASC,UAAT,QAA2B,iBAA3B;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA;;;;;;;;AAOA,OAAO,SAASC,cAAT,CAAyBC,MAAzB,EAAkC;AACxC,SAAOF,YAAY,CAAE,UAAF,EAAc;AAAEG,IAAAA,IAAI,EAAED,MAAR;AAAgBE,IAAAA,MAAM,EAAE;AAAxB,GAAd,CAAnB;AACA;AAED;;;;;;;;;AAQA,OAAO,SAASC,iBAAT,CAA4BH,MAA5B,EAAoCI,QAApC,EAA+C;AACrD,SAAON,YAAY,CAAE,UAAF,EAAc;AAChCO,IAAAA,OAAO,EAAE,CADuB;AAEhCC,IAAAA,SAAS,EAAEF,QAFqB;AAGhCG,IAAAA,GAAG,EAAEP;AAH2B,GAAd,CAAnB;AAKA;AAED,WAAaQ,UAAb;AAAA;AAAA;AAAA;;AACC,wBAAc;AAAA;;AAAA;;AACb,qFAAUC,SAAV;AAEA,UAAKC,KAAL,GAAa;AACZC,MAAAA,SAAS,EAAE;AADC,KAAb;AAHa;AAMb;;AAPF;AAAA;AAAA,uCASqBC,SATrB,EASiC;AAAA,wBACU,KAAKC,KADf;AAAA,UACvBb,MADuB,eACvBA,MADuB;AAAA,UACfc,UADe,eACfA,UADe;AAAA,UACHV,QADG,eACHA,QADG;AAAA,UAEvBO,SAFuB,GAET,KAAKD,KAFI,CAEvBC,SAFuB;;AAI/B,UAAKG,UAAU,KAAK,OAApB,EAA8B;AAC7B,aAAKC,WAAL,CAAkBf,MAAlB,EAA0BI,Q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} from '@wordpress/data';\nimport { addQueryArgs } from '@wordpress/url';\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\n/**\n * Returns the Post's Trashed URL.\n *\n * @param {number} postId Post ID.\n * @param {string} postType Post Type.\n *\n * @return {string} Post trashed URL.\n */\nexport function getPostTrashedURL( postId, postType ) {\n\treturn addQueryArgs( 'edit.php', {\n\t\ttrashed: 1,\n\t\tpost_type: postType,\n\t\tids: postId,\n\t} );\n}\n\nexport class BrowserURL extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\thistoryId: null,\n\t\t};\n\t}\n\n\tcomponentDidUpdate( prevProps ) {\n\t\tconst { postId, postStatus, postType } = this.props;\n\t\tconst { historyId } = this.state;\n\n\t\tif ( postStatus === 'trash' ) {\n\t\t\tthis.setTrashURL( postId, postType );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( ( postId !== prevProps.postId || postId !== historyId ) && postStatus !== 'auto-draft' ) {\n\t\t\tthis.setBrowserURL( postId );\n\t\t}\n\t}\n\n\t/**\n\t * Navigates the browser to the post trashed URL to show a notice about the trashed post.\n\t *\n\t * @param {number} postId Post ID.\n\t * @param {string} postType Post Type.\n\t */\n\tsetTrashURL( postId, postType ) {\n\t\twindow.location.href = getPostTrashedURL( postId, postType );\n\t}\n\n\t/**\n\t * Replaces the browser URL with a post editor link for the given post ID.\n\t *\n\t * Note it is important that, since this function may be called when the\n\t * editor first loads, the result generated `getPostEditURL` matches that\n\t * produced by the server. Otherwise, the URL will change unexpectedly.\n\t *\n\t * @param {number} postId Post ID for which to generate post editor URL.\n\t */\n\tsetBrowserURL( postId ) {\n\t\twindow.history.replaceState(\n\t\t\t{ id: postId },\n\t\t\t'Post ' + postId,\n\t\t\tgetPostEditURL( postId )\n\t\t);\n\n\t\tthis.setState( () => ( {\n\t\t\thistoryId: postId,\n\t\t} ) );\n\t}\n\n\trender() {\n\t\treturn null;\n\t}\n}\n\nexport default withSelect( ( select ) => {\n\tconst { getCurrentPost } = select( 'core/editor' );\n\tconst { id, status, type } = getCurrentPost();\n\n\treturn {\n\t\tpostId: id,\n\t\tpostStatus: status,\n\t\tpostType: type,\n\t};\n} )( BrowserURL );\n"]}
\No newline at end of file