@wordpress/block-directory 3.1.4 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.2.0 (2022-03-11)
6
+
5
7
  ## 3.1.1 (2022-02-10)
6
8
 
7
9
  ### Bug Fix
@@ -158,9 +158,9 @@ const installBlockType = block => async _ref => {
158
158
  });
159
159
  success = true;
160
160
  } catch (error) {
161
- let message = error.message || (0, _i18n.__)('An error occurred.'); // Errors we throw are fatal
161
+ let message = error.message || (0, _i18n.__)('An error occurred.'); // Errors we throw are fatal.
162
162
 
163
- let isFatal = error instanceof Error; // Specific API errors that are fatal
163
+ let isFatal = error instanceof Error; // Specific API errors that are fatal.
164
164
 
165
165
  const fatalAPIErrors = {
166
166
  folder_exists: (0, _i18n.__)('This block is already installed. Try reloading the page.'),
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAKA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI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AAA;AAFe,KAAV,CAAN;AAIAN,IAAAA,QAAQ,CAAC0C,wBAAT,CAAmC5C,KAAnC;AACA,GAZD,CAYE,OAAQiC,KAAR,EAAgB;AACjBhC,IAAAA,QAAQ,CACNC,QADF,CACY2B,cADZ,EAEEY,iBAFF,CAEqBR,KAAK,CAACC,OAAN,IAAiB,cAAI,oBAAJ,CAFtC;AAGA;AACD,CArBM;AAuBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASjB,qBAAT,CAAgC4B,IAAhC,EAAuC;AAC7C,SAAO;AACNjD,IAAAA,IAAI,EAAE,0BADA;AAENiD,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACNjD,IAAAA,IAAI,EAAE,6BADA;AAENiD,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAStC,eAAT,CAA0BuC,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNnD,IAAAA,IAAI,EAAE,sBADA;AAENkD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACNvC,IAAAA,IAAI,EAAE,kBADA;AAENkD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS7B,gBAAT,CAA2BwC,OAA3B,EAAqC;AAC3C,SAAO;AACNlD,IAAAA,IAAI,EAAE,oBADA;AAENkD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\tconst { id, name } = block;\n\tlet success = false;\n\tdispatch.clearErrorNotice( id );\n\ttry {\n\t\tdispatch.setIsInstalling( id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'active' },\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tdispatch.addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\tconst metadataFields = [\n\t\t\t'api_version',\n\t\t\t'title',\n\t\t\t'category',\n\t\t\t'parent',\n\t\t\t'icon',\n\t\t\t'description',\n\t\t\t'keywords',\n\t\t\t'attributes',\n\t\t\t'provides_context',\n\t\t\t'uses_context',\n\t\t\t'supports',\n\t\t\t'styles',\n\t\t\t'example',\n\t\t\t'variations',\n\t\t];\n\t\tawait apiFetch( {\n\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t_fields: metadataFields,\n\t\t\t} ),\n\t\t} )\n\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t.catch( () => {} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif ( ! response ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t} );\n\t\t\t} );\n\n\t\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tdispatch.setIsInstalling( id, false );\n\treturn success;\n};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\ttry {\n\t\tconst url = getPluginUrl( block );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'PUT',\n\t\t\turl,\n\t\t\tdata: { status: 'inactive' },\n\t\t} );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'DELETE',\n\t\t\turl,\n\t\t} );\n\t\tdispatch.removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( error.message || __( 'An error occurred.' ) );\n\t}\n};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAKA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AArBA;AACA;AACA;;AAGA;AACA;AACA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EAAqC;AAC3C,SAAO;AACNlD,IAAAA,IAAI,EAAE,oBADA;AAENkD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\tconst { id, name } = block;\n\tlet success = false;\n\tdispatch.clearErrorNotice( id );\n\ttry {\n\t\tdispatch.setIsInstalling( id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'active' },\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tdispatch.addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\tconst metadataFields = [\n\t\t\t'api_version',\n\t\t\t'title',\n\t\t\t'category',\n\t\t\t'parent',\n\t\t\t'icon',\n\t\t\t'description',\n\t\t\t'keywords',\n\t\t\t'attributes',\n\t\t\t'provides_context',\n\t\t\t'uses_context',\n\t\t\t'supports',\n\t\t\t'styles',\n\t\t\t'example',\n\t\t\t'variations',\n\t\t];\n\t\tawait apiFetch( {\n\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t_fields: metadataFields,\n\t\t\t} ),\n\t\t} )\n\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t.catch( () => {} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif ( ! response ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t} );\n\t\t\t} );\n\n\t\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal.\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal.\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tdispatch.setIsInstalling( id, false );\n\treturn success;\n};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\ttry {\n\t\tconst url = getPluginUrl( block );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'PUT',\n\t\t\turl,\n\t\t\tdata: { status: 'inactive' },\n\t\t} );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'DELETE',\n\t\t\turl,\n\t\t} );\n\t\tdispatch.removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( error.message || __( 'An error occurred.' ) );\n\t}\n};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
@@ -132,10 +132,10 @@ export const installBlockType = block => async _ref => {
132
132
  });
133
133
  success = true;
134
134
  } catch (error) {
135
- let message = error.message || __('An error occurred.'); // Errors we throw are fatal
135
+ let message = error.message || __('An error occurred.'); // Errors we throw are fatal.
136
136
 
137
137
 
138
- let isFatal = error instanceof Error; // Specific API errors that are fatal
138
+ let isFatal = error instanceof Error; // Specific API errors that are fatal.
139
139
 
140
140
  const fatalAPIErrors = {
141
141
  folder_exists: __('This block is already installed. Try reloading the page.'),
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["pick","store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SACCC,KAAK,IAAIC,WADV,EAECC,6CAFD,CAEgD;AAFhD,OAGO,mBAHP;AAIA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASL,KAAK,IAAIM,YAAlB,QAAsC,oBAAtC;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,gBAAgB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AAA,QAAQ,CACNC,QADF,CACYZ,YADZ,EAEEiD,iBAFF,CAEqBR,KAAK,CAACC,OAAN,IAAiB7C,EAAE,CAAE,oBAAF,CAFxC;AAGA;AACD,CArBM;AAuBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS8B,qBAAT,CAAgC0B,IAAhC,EAAuC;AAC7C,SAAO;AACN/C,IAAAA,IAAI,EAAE,0BADA;AAEN+C,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACN/C,IAAAA,IAAI,EAAE,6BADA;AAEN+C,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASpC,eAAT,CAA0BqC,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNjD,IAAAA,IAAI,EAAE,sBADA;AAENgD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACNrC,IAAAA,IAAI,EAAE,kBADA;AAENgD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS3B,gBAAT,CAA2BsC,OAA3B,EAAqC;AAC3C,SAAO;AACNhD,IAAAA,IAAI,EAAE,oBADA;AAENgD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\tconst { id, name } = block;\n\tlet success = false;\n\tdispatch.clearErrorNotice( id );\n\ttry {\n\t\tdispatch.setIsInstalling( id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'active' },\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tdispatch.addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\tconst metadataFields = [\n\t\t\t'api_version',\n\t\t\t'title',\n\t\t\t'category',\n\t\t\t'parent',\n\t\t\t'icon',\n\t\t\t'description',\n\t\t\t'keywords',\n\t\t\t'attributes',\n\t\t\t'provides_context',\n\t\t\t'uses_context',\n\t\t\t'supports',\n\t\t\t'styles',\n\t\t\t'example',\n\t\t\t'variations',\n\t\t];\n\t\tawait apiFetch( {\n\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t_fields: metadataFields,\n\t\t\t} ),\n\t\t} )\n\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t.catch( () => {} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif ( ! response ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t} );\n\t\t\t} );\n\n\t\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tdispatch.setIsInstalling( id, false );\n\treturn success;\n};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\ttry {\n\t\tconst url = getPluginUrl( block );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'PUT',\n\t\t\turl,\n\t\t\tdata: { status: 'inactive' },\n\t\t} );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'DELETE',\n\t\t\turl,\n\t\t} );\n\t\tdispatch.removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( error.message || __( 'An error occurred.' ) );\n\t}\n};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["pick","store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,QAArB;AAEA;AACA;AACA;;AACA,SACCC,KAAK,IAAIC,WADV,EAECC,6CAFD,CAEgD;AAFhD,OA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AAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNjD,IAAAA,IAAI,EAAE,sBADA;AAENgD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA6D;AAAA,MAAlBC,OAAkB,uEAAR,KAAQ;AACnE,SAAO;AACNrC,IAAAA,IAAI,EAAE,kBADA;AAENgD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS3B,gBAAT,CAA2BsC,OAA3B,EAAqC;AAC3C,SAAO;AACNhD,IAAAA,IAAI,EAAE,oBADA;AAENgD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { pick } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\tconst { id, name } = block;\n\tlet success = false;\n\tdispatch.clearErrorNotice( id );\n\ttry {\n\t\tdispatch.setIsInstalling( id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'active' },\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tdispatch.addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\tconst metadataFields = [\n\t\t\t'api_version',\n\t\t\t'title',\n\t\t\t'category',\n\t\t\t'parent',\n\t\t\t'icon',\n\t\t\t'description',\n\t\t\t'keywords',\n\t\t\t'attributes',\n\t\t\t'provides_context',\n\t\t\t'uses_context',\n\t\t\t'supports',\n\t\t\t'styles',\n\t\t\t'example',\n\t\t\t'variations',\n\t\t];\n\t\tawait apiFetch( {\n\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t_fields: metadataFields,\n\t\t\t} ),\n\t\t} )\n\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t.catch( () => {} )\n\t\t\t.then( ( response ) => {\n\t\t\t\tif ( ! response ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t[ name ]: pick( response, metadataFields ),\n\t\t\t\t} );\n\t\t\t} );\n\n\t\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal.\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal.\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tdispatch.setIsInstalling( id, false );\n\treturn success;\n};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\ttry {\n\t\tconst url = getPluginUrl( block );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'PUT',\n\t\t\turl,\n\t\t\tdata: { status: 'inactive' },\n\t\t} );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'DELETE',\n\t\t\turl,\n\t\t} );\n\t\tdispatch.removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( error.message || __( 'An error occurred.' ) );\n\t}\n};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-directory",
3
- "version": "3.1.4",
3
+ "version": "3.2.0",
4
4
  "description": "Extend editor with block directory features to search, download and install blocks.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,28 +26,32 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/a11y": "^3.3.1",
30
- "@wordpress/api-fetch": "^6.0.1",
31
- "@wordpress/block-editor": "^8.2.0",
32
- "@wordpress/blocks": "^11.2.2",
33
- "@wordpress/components": "^19.5.0",
34
- "@wordpress/compose": "^5.1.2",
35
- "@wordpress/core-data": "^4.1.2",
36
- "@wordpress/data": "^6.3.0",
37
- "@wordpress/edit-post": "^6.0.2",
38
- "@wordpress/editor": "^12.2.2",
39
- "@wordpress/element": "^4.1.1",
40
- "@wordpress/hooks": "^3.3.1",
41
- "@wordpress/html-entities": "^3.3.1",
42
- "@wordpress/i18n": "^4.3.1",
43
- "@wordpress/icons": "^7.0.1",
44
- "@wordpress/notices": "^3.3.2",
45
- "@wordpress/plugins": "^4.1.3",
46
- "@wordpress/url": "^3.4.1",
29
+ "@wordpress/a11y": "^3.4.0",
30
+ "@wordpress/api-fetch": "^6.1.0",
31
+ "@wordpress/block-editor": "^8.3.0",
32
+ "@wordpress/blocks": "^11.3.0",
33
+ "@wordpress/components": "^19.6.0",
34
+ "@wordpress/compose": "^5.2.0",
35
+ "@wordpress/core-data": "^4.2.0",
36
+ "@wordpress/data": "^6.4.0",
37
+ "@wordpress/edit-post": "^6.1.0",
38
+ "@wordpress/editor": "^12.3.0",
39
+ "@wordpress/element": "^4.2.0",
40
+ "@wordpress/hooks": "^3.4.0",
41
+ "@wordpress/html-entities": "^3.4.0",
42
+ "@wordpress/i18n": "^4.4.0",
43
+ "@wordpress/icons": "^8.0.0",
44
+ "@wordpress/notices": "^3.4.0",
45
+ "@wordpress/plugins": "^4.2.0",
46
+ "@wordpress/url": "^3.5.0",
47
47
  "lodash": "^4.17.21"
48
48
  },
49
+ "peerDependencies": {
50
+ "react": "^17.0.0",
51
+ "react-dom": "^17.0.0"
52
+ },
49
53
  "publishConfig": {
50
54
  "access": "public"
51
55
  },
52
- "gitHead": "4566ac290359553d04de4eb574545309343f790b"
56
+ "gitHead": "c37fd7edbc3e379540d7b24fce75a6f640a434ae"
53
57
  }
@@ -15,7 +15,7 @@ import DownloadableBlockListItem from '../';
15
15
  import { plugin } from '../../test/fixtures';
16
16
 
17
17
  jest.mock( '@wordpress/data/src/components/use-select', () => {
18
- // This allows us to tweak the returned value on each test
18
+ // This allows us to tweak the returned value on each test.
19
19
  const mock = jest.fn();
20
20
  return mock;
21
21
  } );
@@ -15,7 +15,7 @@ import DownloadableBlocksList from '../';
15
15
  import { items } from '../../test/fixtures';
16
16
 
17
17
  jest.mock( '@wordpress/data/src/components/use-select', () => {
18
- // This allows us to tweak the returned value on each test
18
+ // This allows us to tweak the returned value on each test.
19
19
  const mock = jest.fn();
20
20
  return mock;
21
21
  } );
@@ -147,10 +147,10 @@ export const installBlockType = ( block ) => async ( {
147
147
  } catch ( error ) {
148
148
  let message = error.message || __( 'An error occurred.' );
149
149
 
150
- // Errors we throw are fatal
150
+ // Errors we throw are fatal.
151
151
  let isFatal = error instanceof Error;
152
152
 
153
- // Specific API errors that are fatal
153
+ // Specific API errors that are fatal.
154
154
  const fatalAPIErrors = {
155
155
  folder_exists: __(
156
156
  'This block is already installed. Try reloading the page.'
@@ -22,7 +22,7 @@ jest.mock( '../load-assets', () => ( {
22
22
  } ) );
23
23
 
24
24
  function createRegistryWithStores() {
25
- // create a registry and register stores
25
+ // Create a registry and register stores.
26
26
  const registry = createRegistry();
27
27
 
28
28
  registry.register( blockDirectoryStore );
@@ -32,7 +32,7 @@ function createRegistryWithStores() {
32
32
  return registry;
33
33
  }
34
34
 
35
- // mock the `loadAssets` function. The real function would load the installed
35
+ // Mock the `loadAssets` function. The real function would load the installed
36
36
  // block's script assets, which in turn register the block. That registration
37
37
  // call is the only thing we need to mock.
38
38
  function loadAssetsMock( registry ) {
@@ -85,7 +85,7 @@ describe( 'actions', () => {
85
85
  it( 'should install a block successfully', async () => {
86
86
  const registry = createRegistryWithStores();
87
87
 
88
- // mock the api-fetch and load-assets modules
88
+ // Mock the api-fetch and load-assets modules.
89
89
  apiFetch.mockImplementation( async ( { path } ) => {
90
90
  switch ( path ) {
91
91
  case 'wp/v2/plugins':
@@ -99,18 +99,18 @@ describe( 'actions', () => {
99
99
 
100
100
  loadAssets.mockImplementation( loadAssetsMock( registry ) );
101
101
 
102
- // install the block
102
+ // Install the block.
103
103
  await registry
104
104
  .dispatch( blockDirectoryStore )
105
105
  .installBlockType( block );
106
106
 
107
- // check that blocks store contains the new block
107
+ // Check that blocks store contains the new block.
108
108
  const registeredBlock = registry
109
109
  .select( blocksStore )
110
110
  .getBlockType( 'block/block' );
111
111
  expect( registeredBlock ).toBeTruthy();
112
112
 
113
- // check that the block-directory store contains the new block, too
113
+ // Check that the block-directory store contains the new block, too.
114
114
  const installedBlockTypes = registry
115
115
  .select( blockDirectoryStore )
116
116
  .getInstalledBlockTypes();
@@ -118,7 +118,7 @@ describe( 'actions', () => {
118
118
  { name: 'block/block' },
119
119
  ] );
120
120
 
121
- // check that notice was displayed
121
+ // Check that notice was displayed.
122
122
  const notices = registry.select( noticesStore ).getNotices();
123
123
  expect( notices ).toMatchObject( [
124
124
  { content: 'Block Test Block installed and added.' },
@@ -128,7 +128,7 @@ describe( 'actions', () => {
128
128
  it( 'should activate an inactive block plugin successfully', async () => {
129
129
  const registry = createRegistryWithStores();
130
130
 
131
- // mock the api-fetch and load-assets modules
131
+ // Mock the api-fetch and load-assets modules.
132
132
  apiFetch.mockImplementation( async ( { path, url } ) => {
133
133
  if ( path === blockTypePath ) {
134
134
  return blockTypeResponse;
@@ -141,20 +141,20 @@ describe( 'actions', () => {
141
141
 
142
142
  loadAssets.mockImplementation( loadAssetsMock( registry ) );
143
143
 
144
- // install the block
144
+ // Install the block.
145
145
  await registry.dispatch( blockDirectoryStore ).installBlockType(
146
146
  blockWithLinks( block, {
147
147
  'wp:plugin': [ { href: pluginEndpoint } ],
148
148
  } )
149
149
  );
150
150
 
151
- // check that blocks store contains the new block
151
+ // Check that blocks store contains the new block.
152
152
  const registeredBlock = registry
153
153
  .select( blocksStore )
154
154
  .getBlockType( 'block/block' );
155
155
  expect( registeredBlock ).toBeTruthy();
156
156
 
157
- // check that notice was displayed
157
+ // Check that notice was displayed.
158
158
  const notices = registry.select( noticesStore ).getNotices();
159
159
  expect( notices ).toMatchObject( [
160
160
  { content: 'Block Test Block installed and added.' },
@@ -164,7 +164,7 @@ describe( 'actions', () => {
164
164
  it( "should set an error if the plugin can't install", async () => {
165
165
  const registry = createRegistryWithStores();
166
166
 
167
- // mock the api-fetch and load-assets modules
167
+ // Mock the api-fetch and load-assets modules.
168
168
  apiFetch.mockImplementation( async ( { path } ) => {
169
169
  switch ( path ) {
170
170
  case 'wp/v2/plugins':
@@ -180,18 +180,18 @@ describe( 'actions', () => {
180
180
 
181
181
  loadAssets.mockImplementation( loadAssetsMock( registry ) );
182
182
 
183
- // install the block
183
+ // Install the block.
184
184
  await registry
185
185
  .dispatch( blockDirectoryStore )
186
186
  .installBlockType( block );
187
187
 
188
- // check that blocks store doesn't contain the new block
188
+ // Check that blocks store doesn't contain the new block.
189
189
  const registeredBlock = registry
190
190
  .select( blocksStore )
191
191
  .getBlockType( 'block/block' );
192
192
  expect( registeredBlock ).toBeUndefined();
193
193
 
194
- // check that error notice was displayed
194
+ // Check that error notice was displayed.
195
195
  const notices = registry.select( noticesStore ).getNotices();
196
196
  expect( notices ).toMatchObject( [
197
197
  { content: 'Plugin not found.' },
@@ -224,21 +224,21 @@ describe( 'actions', () => {
224
224
  }
225
225
  } );
226
226
 
227
- // add installed block type that we're going to uninstall
227
+ // Add installed block type that we're going to uninstall.
228
228
  registry
229
229
  .dispatch( blockDirectoryStore )
230
230
  .addInstalledBlockType( installedBlock );
231
231
 
232
- // uninstall the block
232
+ // Uninstall the block.
233
233
  await registry
234
234
  .dispatch( blockDirectoryStore )
235
235
  .uninstallBlockType( installedBlock );
236
236
 
237
- // check that no error notice was displayed
237
+ // Check that no error notice was displayed.
238
238
  const notices = registry.select( noticesStore ).getNotices();
239
239
  expect( notices ).toEqual( [] );
240
240
 
241
- // verify that the block was uninstalled
241
+ // Verify that the block was uninstalled.
242
242
  const installedBlockTypes = registry
243
243
  .select( blockDirectoryStore )
244
244
  .getInstalledBlockTypes();
@@ -271,12 +271,12 @@ describe( 'actions', () => {
271
271
  }
272
272
  } );
273
273
 
274
- // uninstall the block
274
+ // Uninstall the block.
275
275
  await registry
276
276
  .dispatch( blockDirectoryStore )
277
277
  .uninstallBlockType( installedBlock );
278
278
 
279
- // check that error notice was displayed
279
+ // Check that error notice was displayed.
280
280
  const notices = registry.select( noticesStore ).getNotices();
281
281
  expect( notices ).toMatchObject( [
282
282
  {