{
  "version": 3,
  "sources": ["../../../src/components/browser-url/use-classic-revision-redirect.js"],
  "sourcesContent": ["import { useRegistry, useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { useEffect } from '@wordpress/element';\nimport { addQueryArgs } from '@wordpress/url';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Redirects an editor URL that already contains a revision ID to the classic\n * screen when visual revisions are disabled. Revision buttons already link\n * there, but the URL can load before the editor finishes checking for meta boxes.\n */\nexport default function useClassicRevisionRedirect() {\n\tconst registry = useRegistry();\n\tconst { disableVisualRevisions, currentRevisionId, postType, postId } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst editor = select( editorStore );\n\t\t\treturn {\n\t\t\t\tdisableVisualRevisions:\n\t\t\t\t\t!! editor.getEditorSettings().disableVisualRevisions,\n\t\t\t\tcurrentRevisionId: unlock( editor ).getCurrentRevisionId(),\n\t\t\t\tpostType: editor.getCurrentPostType(),\n\t\t\t\tpostId: editor.getCurrentPostId(),\n\t\t\t};\n\t\t}, [] );\n\tconst hasClassicRevisionScreen = ! [\n\t\t'wp_template',\n\t\t'wp_template_part',\n\t].includes( postType );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\t! disableVisualRevisions ||\n\t\t\t! hasClassicRevisionScreen ||\n\t\t\t! currentRevisionId ||\n\t\t\t! postType ||\n\t\t\t! postId\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet cancelled = false;\n\t\t// Invalid IDs trigger `wp_die()` before JavaScript loads. Check that the\n\t\t// revision belongs to this post before redirecting.\n\t\tregistry\n\t\t\t.resolveSelect( coreStore )\n\t\t\t.getRevision( 'postType', postType, postId, currentRevisionId, {\n\t\t\t\tcontext: 'edit',\n\t\t\t\t_fields: 'id',\n\t\t\t} )\n\t\t\t.then( ( revision ) => {\n\t\t\t\tif ( cancelled || ! revision ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst editor = registry.select( editorStore );\n\t\t\t\tconst isStillSelected =\n\t\t\t\t\t!! editor.getEditorSettings().disableVisualRevisions &&\n\t\t\t\t\teditor.getCurrentPostType() === postType &&\n\t\t\t\t\tString( editor.getCurrentPostId() ) === String( postId ) &&\n\t\t\t\t\tunlock( editor ).getCurrentRevisionId() ===\n\t\t\t\t\t\tcurrentRevisionId;\n\t\t\t\tif ( ! isStillSelected ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Replace the editor URL so Back does not reopen it and trigger\n\t\t\t\t// the redirect again.\n\t\t\t\twindow.location.replace(\n\t\t\t\t\taddQueryArgs( 'revision.php', {\n\t\t\t\t\t\trevision: currentRevisionId,\n\t\t\t\t\t} )\n\t\t\t\t);\n\t\t\t} );\n\n\t\treturn () => {\n\t\t\tcancelled = true;\n\t\t};\n\t}, [\n\t\tdisableVisualRevisions,\n\t\thasClassicRevisionScreen,\n\t\tcurrentRevisionId,\n\t\tpostType,\n\t\tpostId,\n\t\tregistry,\n\t] );\n}\n"],
  "mappings": ";AAAA,SAAS,aAAa,iBAAiB;AACvC,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,mBAAmB;AACrC,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AAOR,SAAR,6BAA8C;AACpD,QAAM,WAAW,YAAY;AAC7B,QAAM,EAAE,wBAAwB,mBAAmB,UAAU,OAAO,IACnE,UAAW,CAAE,WAAY;AACxB,UAAM,SAAS,OAAQ,WAAY;AACnC,WAAO;AAAA,MACN,wBACC,CAAC,CAAE,OAAO,kBAAkB,EAAE;AAAA,MAC/B,mBAAmB,OAAQ,MAAO,EAAE,qBAAqB;AAAA,MACzD,UAAU,OAAO,mBAAmB;AAAA,MACpC,QAAQ,OAAO,iBAAiB;AAAA,IACjC;AAAA,EACD,GAAG,CAAC,CAAE;AACP,QAAM,2BAA2B,CAAE;AAAA,IAClC;AAAA,IACA;AAAA,EACD,EAAE,SAAU,Q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