{
  "version": 3,
  "sources": ["../../../src/components/site-export/index.js"],
  "sourcesContent": ["import { __, _x } from '@wordpress/i18n';\nimport { MenuItem } from '@wordpress/components';\nimport apiFetch from '@wordpress/api-fetch';\nimport { download } from '@wordpress/icons';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { downloadBlob } from '@wordpress/blob';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as editorStore } from '../../store';\nimport {\n\tTEMPLATE_POST_TYPE,\n\tTEMPLATE_PART_POST_TYPE,\n} from '../../store/constants';\n\n/**\n * Menu item offering to download the active theme, with the user's template\n * and style changes, as a zip.\n *\n * Offered only while editing one of the entities the exported theme is made\n * of — a template or a template part — and only to users the export endpoint\n * accepts. The host places it in a menu group.\n *\n * @return {React.ReactNode} The menu item, or nothing where export does not\n *                           apply.\n */\nexport default function SiteExport() {\n\tconst canExport = useSelect( ( select ) => {\n\t\tconst postType = select( editorStore ).getCurrentPostType();\n\t\tif (\n\t\t\tpostType !== TEMPLATE_POST_TYPE &&\n\t\t\tpostType !== TEMPLATE_PART_POST_TYPE\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst targetHints =\n\t\t\tselect( coreStore ).getCurrentTheme()?._links?.[\n\t\t\t\t'wp:export-theme'\n\t\t\t]?.[ 0 ]?.targetHints ?? {};\n\n\t\treturn !! targetHints.allow?.includes( 'GET' );\n\t}, [] );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tif ( ! canExport ) {\n\t\treturn null;\n\t}\n\n\tasync function handleExport() {\n\t\ttry {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tpath: '/wp-block-editor/v1/export',\n\t\t\t\tparse: false,\n\t\t\t\theaders: {\n\t\t\t\t\tAccept: 'application/zip',\n\t\t\t\t},\n\t\t\t} );\n\t\t\tconst blob = await response.blob();\n\t\t\tconst contentDisposition = response.headers.get(\n\t\t\t\t'content-disposition'\n\t\t\t);\n\t\t\tconst contentDispositionMatches =\n\t\t\t\tcontentDisposition.match( /=(.+)\\.zip/ );\n\t\t\tconst fileName = contentDispositionMatches[ 1 ]\n\t\t\t\t? contentDispositionMatches[ 1 ]\n\t\t\t\t: 'edit-site-export';\n\n\t\t\tdownloadBlob( fileName + '.zip', blob, 'application/zip' );\n\t\t} catch ( errorResponse ) {\n\t\t\tlet error = {};\n\t\t\ttry {\n\t\t\t\terror = await errorResponse.json();\n\t\t\t} catch {}\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the site export.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\trole=\"menuitem\"\n\t\t\ticon={ download }\n\t\t\tonClick={ handleExport }\n\t\t\tinfo={ __(\n\t\t\t\t'Download your theme with updated templates and styles.'\n\t\t\t) }\n\t\t>\n\t\t\t{ _x( 'Export', 'site exporter menu item' ) }\n\t\t</MenuItem>\n\t);\n}\n"],
  "mappings": ";AAAA,SAAS,IAAI,UAAU;AACvB,SAAS,gBAAgB;AACzB,OAAO,cAAc;AACrB,SAAS,gBAAgB;AACzB,SAAS,aAAa,iBAAiB;AACvC,SAAS,oBAAoB;AAC7B,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,oBAAoB;AACtC,SAAS,SAAS,mBAAmB;AACrC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAuEL;AA1Da,SAAR,aAA8B;AACpC,QAAM,YAAY,UAAW,CAAE,WAAY;AAC1C,UAAM,WAAW,OAAQ,WAAY,EAAE,mBAAmB;AAC1D,QACC,aAAa,sBACb,aAAa,yBACZ;AACD,aAAO;AAAA,IACR;AAEA,UAAM,cACL,OAAQ,SAAU,EAAE,gBAAgB,GAAG,SACtC,iBACD,IAAK,CAAE,GAAG,eAAe,CAAC;AAE3B,WAAO,CAAC,CAAE,YAAY,OAA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