@wordpress/block-directory 3.0.7 → 3.0.11
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/build/components/block-ratings/index.js +10 -7
- package/build/components/block-ratings/index.js.map +1 -1
- package/build/components/block-ratings/stars.js +4 -3
- package/build/components/block-ratings/stars.js.map +1 -1
- package/build/components/compact-list/index.js +28 -23
- package/build/components/compact-list/index.js.map +1 -1
- package/build/components/downloadable-block-icon/index.js +4 -3
- package/build/components/downloadable-block-icon/index.js.map +1 -1
- package/build/components/downloadable-block-list-item/index.js +17 -14
- package/build/components/downloadable-block-list-item/index.js.map +1 -1
- package/build/components/downloadable-block-notice/index.js +4 -3
- package/build/components/downloadable-block-notice/index.js.map +1 -1
- package/build/components/downloadable-blocks-list/index.js +6 -5
- package/build/components/downloadable-blocks-list/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/index.js +16 -13
- package/build/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/inserter-panel.js +6 -5
- package/build/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build/plugins/get-install-missing/index.js +11 -7
- package/build/plugins/get-install-missing/index.js.map +1 -1
- package/build/plugins/get-install-missing/install-button.js +6 -5
- package/build/plugins/get-install-missing/install-button.js.map +1 -1
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js +9 -7
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build/store/actions.js +18 -13
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +5 -3
- package/build/store/index.js.map +1 -1
- package/build/store/load-assets.js +1 -1
- package/build/store/reducer.js +16 -7
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +5 -3
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +4 -4
- package/build/store/utils/has-block-type.js +9 -4
- package/build/store/utils/has-block-type.js.map +1 -1
- package/build-module/components/block-ratings/index.js +10 -7
- package/build-module/components/block-ratings/index.js.map +1 -1
- package/build-module/components/block-ratings/stars.js +4 -3
- package/build-module/components/block-ratings/stars.js.map +1 -1
- package/build-module/components/compact-list/index.js +28 -23
- package/build-module/components/compact-list/index.js.map +1 -1
- package/build-module/components/downloadable-block-icon/index.js +4 -3
- package/build-module/components/downloadable-block-icon/index.js.map +1 -1
- package/build-module/components/downloadable-block-list-item/index.js +17 -14
- package/build-module/components/downloadable-block-list-item/index.js.map +1 -1
- package/build-module/components/downloadable-block-notice/index.js +4 -3
- package/build-module/components/downloadable-block-notice/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-list/index.js +6 -5
- package/build-module/components/downloadable-blocks-list/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/index.js +16 -13
- package/build-module/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js +6 -5
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build-module/plugins/get-install-missing/index.js +11 -7
- package/build-module/plugins/get-install-missing/index.js.map +1 -1
- package/build-module/plugins/get-install-missing/install-button.js +6 -5
- package/build-module/plugins/get-install-missing/install-button.js.map +1 -1
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js +9 -7
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/store/actions.js +13 -9
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +15 -6
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +5 -3
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/utils/has-block-type.js +9 -4
- package/build-module/store/utils/has-block-type.js.map +1 -1
- package/package.json +21 -21
package/build/store/actions.js
CHANGED
|
@@ -5,14 +5,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.addInstalledBlockType = addInstalledBlockType;
|
|
9
|
+
exports.clearErrorNotice = clearErrorNotice;
|
|
8
10
|
exports.fetchDownloadableBlocks = fetchDownloadableBlocks;
|
|
11
|
+
exports.installBlockType = void 0;
|
|
9
12
|
exports.receiveDownloadableBlocks = receiveDownloadableBlocks;
|
|
10
|
-
exports.addInstalledBlockType = addInstalledBlockType;
|
|
11
13
|
exports.removeInstalledBlockType = removeInstalledBlockType;
|
|
12
|
-
exports.setIsInstalling = setIsInstalling;
|
|
13
14
|
exports.setErrorNotice = setErrorNotice;
|
|
14
|
-
exports.
|
|
15
|
-
exports.uninstallBlockType =
|
|
15
|
+
exports.setIsInstalling = setIsInstalling;
|
|
16
|
+
exports.uninstallBlockType = void 0;
|
|
16
17
|
|
|
17
18
|
var _blocks = require("@wordpress/blocks");
|
|
18
19
|
|
|
@@ -75,10 +76,11 @@ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
75
76
|
*/
|
|
76
77
|
|
|
77
78
|
|
|
78
|
-
const installBlockType = block => async
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const installBlockType = block => async _ref => {
|
|
80
|
+
let {
|
|
81
|
+
registry,
|
|
82
|
+
dispatch
|
|
83
|
+
} = _ref;
|
|
82
84
|
const {
|
|
83
85
|
id
|
|
84
86
|
} = block;
|
|
@@ -164,10 +166,12 @@ const installBlockType = block => async ({
|
|
|
164
166
|
|
|
165
167
|
exports.installBlockType = installBlockType;
|
|
166
168
|
|
|
167
|
-
const uninstallBlockType = block => async
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
const uninstallBlockType = block => async _ref2 => {
|
|
170
|
+
let {
|
|
171
|
+
registry,
|
|
172
|
+
dispatch
|
|
173
|
+
} = _ref2;
|
|
174
|
+
|
|
171
175
|
try {
|
|
172
176
|
const url = (0, _getPluginUrl.default)(block);
|
|
173
177
|
await (0, _apiFetch.default)({
|
|
@@ -248,7 +252,8 @@ function setIsInstalling(blockId, isInstalling) {
|
|
|
248
252
|
*/
|
|
249
253
|
|
|
250
254
|
|
|
251
|
-
function setErrorNotice(blockId, message
|
|
255
|
+
function setErrorNotice(blockId, message) {
|
|
256
|
+
let isFatal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
252
257
|
return {
|
|
253
258
|
type: 'SET_ERROR_NOTICE',
|
|
254
259
|
blockId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","registeredBlocks","select","blocksStore","getBlockTypes","some","i","name","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;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,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;;;AACO,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;;;AACO,MAAMI,gBAAgB,GAAKC,KAAF,IAAa,OAAQ;AACpDC,EAAAA,QADoD;AAEpDC,EAAAA;AAFoD,CAAR,KAGtC;AACN,QAAM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A;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAAS1B,gBAAT,CAA2BqC,OAA3B,EAAqC;AAC3C,SAAO;AACN9C,IAAAA,IAAI,EAAE,oBADA;AAEN8C,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\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 } = 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\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === block.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","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","registeredBlocks","select","blocksStore","getBlockTypes","some","i","name","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;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,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;;;AACO,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;;;AACO,MAAMI,gBAAgB,GAAKC,KAAF,IAAa,cAGtC;AAAA,MAH8C;AACpDC,IAAAA,QADoD;AAEpDC,IAAAA;AAFoD,GAG9C;AACN,QAAM;AAAEC,IAAAA;AAAF,MAASH,KAAf;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;AACA;AACA;AACA;AACA;;;AACO,SAAS1B,gBAAT,CAA2BqC,OAA3B,EAAqC;AAC3C,SAAO;AACN9C,IAAAA,IAAI,EAAE,oBADA;AAEN8C,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\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 } = 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\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === block.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/build/store/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
exports.
|
|
8
|
+
exports.storeConfig = exports.store = void 0;
|
|
11
9
|
|
|
12
10
|
var _data = require("@wordpress/data");
|
|
13
11
|
|
|
@@ -19,6 +17,10 @@ var actions = _interopRequireWildcard(require("./actions"));
|
|
|
19
17
|
|
|
20
18
|
var resolvers = _interopRequireWildcard(require("./resolvers"));
|
|
21
19
|
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* WordPress dependencies
|
|
24
26
|
*/
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["STORE_NAME","storeConfig","reducer","selectors","actions","resolvers","__experimentalUseThunks","store"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["STORE_NAME","storeConfig","reducer","selectors","actions","resolvers","__experimentalUseThunks","store"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;;;;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA,MAAMA,UAAU,GAAG,sBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,WAAW,GAAG;AAC1BC,EAAAA,OAAO,EAAPA,gBAD0B;AAE1BC,EAAAA,SAF0B;AAG1BC,EAAAA,OAH0B;AAI1BC,EAAAA,SAJ0B;AAK1BC,EAAAA,uBAAuB,EAAE;AALC,CAApB;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,KAAK,GAAG,4BAAkBP,UAAlB,EAA8BC,WAA9B,CAAd;;AAEP,oBAAUM,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\n\n/**\n * Module Constants\n */\nconst STORE_NAME = 'core/block-directory';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore\n *\n * @type {Object}\n */\nexport const storeConfig = {\n\treducer,\n\tselectors,\n\tactions,\n\tresolvers,\n\t__experimentalUseThunks: true,\n};\n\n/**\n * Store definition for the block directory namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\n\nregister( store );\n"]}
|
|
@@ -5,8 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.loadAssets = loadAssets;
|
|
9
8
|
exports.loadAsset = void 0;
|
|
9
|
+
exports.loadAssets = loadAssets;
|
|
10
10
|
|
|
11
11
|
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
12
12
|
|
package/build/store/reducer.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.errorNotices = exports.downloadableBlocks = exports.default = exports.blockManagement = void 0;
|
|
7
7
|
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
|
|
@@ -25,7 +25,10 @@ var _data = require("@wordpress/data");
|
|
|
25
25
|
*
|
|
26
26
|
* @return {Object} Updated state.
|
|
27
27
|
*/
|
|
28
|
-
const downloadableBlocks = (
|
|
28
|
+
const downloadableBlocks = function () {
|
|
29
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
31
|
+
|
|
29
32
|
switch (action.type) {
|
|
30
33
|
case 'FETCH_DOWNLOADABLE_BLOCKS':
|
|
31
34
|
return { ...state,
|
|
@@ -57,10 +60,13 @@ const downloadableBlocks = (state = {}, action) => {
|
|
|
57
60
|
|
|
58
61
|
exports.downloadableBlocks = downloadableBlocks;
|
|
59
62
|
|
|
60
|
-
const blockManagement = (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const blockManagement = function () {
|
|
64
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
65
|
+
installedBlockTypes: [],
|
|
66
|
+
isInstalling: {}
|
|
67
|
+
};
|
|
68
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
69
|
+
|
|
64
70
|
switch (action.type) {
|
|
65
71
|
case 'ADD_INSTALLED_BLOCK_TYPE':
|
|
66
72
|
return { ...state,
|
|
@@ -94,7 +100,10 @@ const blockManagement = (state = {
|
|
|
94
100
|
|
|
95
101
|
exports.blockManagement = blockManagement;
|
|
96
102
|
|
|
97
|
-
const errorNotices = (
|
|
103
|
+
const errorNotices = function () {
|
|
104
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
105
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
106
|
+
|
|
98
107
|
switch (action.type) {
|
|
99
108
|
case 'SET_ERROR_NOTICE':
|
|
100
109
|
return { ...state,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/reducer.js"],"names":["downloadableBlocks","state","action","type","filterValue","isRequesting","results","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal"],"mappings":";;;;;;;AAIA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/reducer.js"],"names":["downloadableBlocks","state","action","type","filterValue","isRequesting","results","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal"],"mappings":";;;;;;;AAIA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,k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,KAAP;AACA,CAjCM;AAmCP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMc,YAAY,GAAG,YAA0B;AAAA,MAAxBd,KAAwB,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;;AACrD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,kBAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACY,OAAT,GAAoB;AACnBE,UAAAA,OAAO,EAAEd,MAAM,CAACc,OADG;AAEnBC,UAAAA,OAAO,EAAEf,MAAM,CAACe;AAFG;AAFd,OAAP;;AAOD,SAAK,oBAAL;AACC,aAAO,kBAAMhB,KAAN,EAAaC,MAAM,CAACY,OAApB,CAAP;AAVF;;AAYA,SAAOb,KAAP;AACA,CAdM;;;;eAgBQ,2BAAiB;AAC/BD,EAAAA,kBAD+B;AAE/BO,EAAAA,eAF+B;AAG/BQ,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\n\nimport { omit } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning an array of downloadable blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const downloadableBlocks = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'FETCH_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tisRequesting: true,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'RECEIVE_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tresults: action.downloadableBlocks,\n\t\t\t\t\tisRequesting: false,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer managing the installation and deletion of blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const blockManagement = (\n\tstate = {\n\t\tinstalledBlockTypes: [],\n\t\tisInstalling: {},\n\t},\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: [\n\t\t\t\t\t...state.installedBlockTypes,\n\t\t\t\t\taction.item,\n\t\t\t\t],\n\t\t\t};\n\t\tcase 'REMOVE_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: state.installedBlockTypes.filter(\n\t\t\t\t\t( blockType ) => blockType.name !== action.item.name\n\t\t\t\t),\n\t\t\t};\n\t\tcase 'SET_INSTALLING_BLOCK':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisInstalling: {\n\t\t\t\t\t...state.isInstalling,\n\t\t\t\t\t[ action.blockId ]: action.isInstalling,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer returning an object of error notices.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const errorNotices = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'SET_ERROR_NOTICE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.blockId ]: {\n\t\t\t\t\tmessage: action.message,\n\t\t\t\t\tisFatal: action.isFatal,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'CLEAR_ERROR_NOTICE':\n\t\t\treturn omit( state, action.blockId );\n\t}\n\treturn state;\n};\n\nexport default combineReducers( {\n\tdownloadableBlocks,\n\tblockManagement,\n\terrorNotices,\n} );\n"]}
|
package/build/store/resolvers.js
CHANGED
|
@@ -24,9 +24,11 @@ var _actions = require("./actions");
|
|
|
24
24
|
/**
|
|
25
25
|
* Internal dependencies
|
|
26
26
|
*/
|
|
27
|
-
const getDownloadableBlocks = filterValue => async
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const getDownloadableBlocks = filterValue => async _ref => {
|
|
28
|
+
let {
|
|
29
|
+
dispatch
|
|
30
|
+
} = _ref;
|
|
31
|
+
|
|
30
32
|
if (!filterValue) {
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","value","key"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAKC,WAAF,IAAmB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","value","key"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAKC,WAAF,IAAmB,cAEjD;AAAA,MAFyD;AAC/DC,IAAAA;AAD+D,GAEzD;;AACN,MAAK,CAAED,WAAP,EAAqB;AACpB;AACA;;AAED,MAAI;AACHC,IAAAA,QAAQ,CAAE,sCAAyBD,WAAzB,CAAF,CAAR;AACA,UAAME,OAAO,GAAG,MAAM,uBAAU;AAC/BC,MAAAA,IAAI,EAAG,qCAAqCH,WAAa;AAD1B,KAAV,CAAtB;AAGA,UAAMI,MAAM,GAAGF,OAAO,CAACG,GAAR,CAAeC,MAAF,IAC3B,qBAASA,MAAT,EAAiB,CAAEC,KAAF,EAASC,GAAT,KAAkB,uBAAWA,GAAX,CAAnC,CADc,CAAf;AAIAP,IAAAA,QAAQ,CAAE,wCAA2BG,MAA3B,EAAmCJ,WAAnC,CAAF,CAAR;AACA,GAVD,CAUE,MAAM,CAAE;AACV,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase, mapKeys } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';\n\nexport const getDownloadableBlocks = ( filterValue ) => async ( {\n\tdispatch,\n} ) => {\n\tif ( ! filterValue ) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tdispatch( fetchDownloadableBlocks( filterValue ) );\n\t\tconst results = await apiFetch( {\n\t\t\tpath: `wp/v2/block-directory/search?term=${ filterValue }`,\n\t\t} );\n\t\tconst blocks = results.map( ( result ) =>\n\t\t\tmapKeys( result, ( value, key ) => camelCase( key ) )\n\t\t);\n\n\t\tdispatch( receiveDownloadableBlocks( blocks, filterValue ) );\n\t} catch {}\n};\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -5,13 +5,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.isRequestingDownloadableBlocks = isRequestingDownloadableBlocks;
|
|
9
8
|
exports.getDownloadableBlocks = getDownloadableBlocks;
|
|
10
|
-
exports.getInstalledBlockTypes = getInstalledBlockTypes;
|
|
11
|
-
exports.isInstalling = isInstalling;
|
|
12
|
-
exports.getErrorNotices = getErrorNotices;
|
|
13
9
|
exports.getErrorNoticeForBlock = getErrorNoticeForBlock;
|
|
10
|
+
exports.getErrorNotices = getErrorNotices;
|
|
11
|
+
exports.getInstalledBlockTypes = getInstalledBlockTypes;
|
|
14
12
|
exports.getUnusedBlockTypes = exports.getNewBlockTypes = void 0;
|
|
13
|
+
exports.isInstalling = isInstalling;
|
|
14
|
+
exports.isRequestingDownloadableBlocks = isRequestingDownloadableBlocks;
|
|
15
15
|
|
|
16
16
|
var _data = require("@wordpress/data");
|
|
17
17
|
|
|
@@ -14,14 +14,19 @@ exports.default = hasBlockType;
|
|
|
14
14
|
*
|
|
15
15
|
* @return {boolean} Whether the blockType is found.
|
|
16
16
|
*/
|
|
17
|
-
function hasBlockType(blockType
|
|
17
|
+
function hasBlockType(blockType) {
|
|
18
|
+
let blocks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
19
|
+
|
|
18
20
|
if (!blocks.length) {
|
|
19
21
|
return false;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
if (blocks.some(
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
if (blocks.some(_ref => {
|
|
25
|
+
let {
|
|
26
|
+
name
|
|
27
|
+
} = _ref;
|
|
28
|
+
return name === blockType.name;
|
|
29
|
+
})) {
|
|
25
30
|
return true;
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/utils/has-block-type.js"],"names":["hasBlockType","blockType","blocks","length","some","name","i","innerBlocks"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAuBC,SAAvB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/utils/has-block-type.js"],"names":["hasBlockType","blockType","blocks","length","some","name","i","innerBlocks"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,YAAT,CAAuBC,SAAvB,EAAgD;AAAA,MAAdC,MAAc,uEAAL,EAAK;;AAC9D,MAAK,CAAEA,MAAM,CAACC,MAAd,EAAuB;AACtB,WAAO,KAAP;AACA;;AACD,MAAKD,MAAM,CAACE,IAAP,CAAa;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WAAgBA,IAAI,KAAKJ,SAAS,CAACI,IAAnC;AAAA,GAAb,CAAL,EAA8D;AAC7D,WAAO,IAAP;AACA;;AACD,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGJ,MAAM,CAACC,MAA5B,EAAoCG,CAAC,EAArC,EAA0C;AACzC,QAAKN,YAAY,CAAEC,SAAF,EAAaC,MAAM,CAAEI,CAAF,CAAN,CAAYC,WAAzB,CAAjB,EAA0D;AACzD,aAAO,IAAP;AACA;AACD;;AAED,SAAO,KAAP;AACA","sourcesContent":["/**\n * Check if a block list contains a specific block type. Recursively searches\n * through `innerBlocks` if they exist.\n *\n * @param {Object} blockType A block object to search for.\n * @param {Object[]} blocks The list of blocks to look through.\n *\n * @return {boolean} Whether the blockType is found.\n */\nexport default function hasBlockType( blockType, blocks = [] ) {\n\tif ( ! blocks.length ) {\n\t\treturn false;\n\t}\n\tif ( blocks.some( ( { name } ) => name === blockType.name ) ) {\n\t\treturn true;\n\t}\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tif ( hasBlockType( blockType, blocks[ i ].innerBlocks ) ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
|
|
@@ -4,12 +4,15 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* Internal dependencies
|
|
5
5
|
*/
|
|
6
6
|
import Stars from './stars';
|
|
7
|
-
export const BlockRatings =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
7
|
+
export const BlockRatings = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
rating
|
|
10
|
+
} = _ref;
|
|
11
|
+
return createElement("span", {
|
|
12
|
+
className: "block-directory-block-ratings"
|
|
13
|
+
}, createElement(Stars, {
|
|
14
|
+
rating: rating
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
14
17
|
export default BlockRatings;
|
|
15
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/index.js"],"names":["Stars","BlockRatings","rating"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,SAAlB;AAEA,OAAO,MAAMC,YAAY,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/index.js"],"names":["Stars","BlockRatings","rating"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,SAAlB;AAEA,OAAO,MAAMC,YAAY,GAAG;AAAA,MAAE;AAAEC,IAAAA;AAAF,GAAF;AAAA,SAC3B;AAAM,IAAA,SAAS,EAAC;AAAhB,KACC,cAAC,KAAD;AAAO,IAAA,MAAM,EAAGA;AAAhB,IADD,CAD2B;AAAA,CAArB;AAMP,eAAeD,YAAf","sourcesContent":["/**\n * Internal dependencies\n */\nimport Stars from './stars';\n\nexport const BlockRatings = ( { rating } ) => (\n\t<span className=\"block-directory-block-ratings\">\n\t\t<Stars rating={ rating } />\n\t</span>\n);\n\nexport default BlockRatings;\n"]}
|
|
@@ -11,9 +11,10 @@ import { times } from 'lodash';
|
|
|
11
11
|
import { __, sprintf } from '@wordpress/i18n';
|
|
12
12
|
import { Icon, starEmpty, starFilled, starHalf } from '@wordpress/icons';
|
|
13
13
|
|
|
14
|
-
function Stars({
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
function Stars(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
rating
|
|
17
|
+
} = _ref;
|
|
17
18
|
const stars = Math.round(rating / 0.5) * 0.5;
|
|
18
19
|
const fullStarCount = Math.floor(rating);
|
|
19
20
|
const halfStarCount = Math.ceil(rating - fullStarCount);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/stars.js"],"names":["times","__","sprintf","Icon","starEmpty","starFilled","starHalf","Stars","rating","stars","Math","round","fullStarCount","floor","halfStarCount","ceil","emptyStarCount","i"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,QAAtB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,IAAT,EAAeC,SAAf,EAA0BC,UAA1B,EAAsCC,QAAtC,QAAsD,kBAAtD;;AAEA,SAASC,KAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/block-ratings/stars.js"],"names":["times","__","sprintf","Icon","starEmpty","starFilled","starHalf","Stars","rating","stars","Math","round","fullStarCount","floor","halfStarCount","ceil","emptyStarCount","i"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,QAAsB,QAAtB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,IAAT,EAAeC,SAAf,EAA0BC,UAA1B,EAAsCC,QAAtC,QAAsD,kBAAtD;;AAEA,SAASC,KAAT,OAA6B;AAAA,MAAb;AAAEC,IAAAA;AAAF,GAAa;AAC5B,QAAMC,KAAK,GAAGC,IAAI,CAACC,KAAL,CAAYH,MAAM,GAAG,GAArB,IAA6B,GAA3C;AAEA,QAAMI,aAAa,GAAGF,IAAI,CAACG,KAAL,CAAYL,MAAZ,CAAtB;AACA,QAAMM,aAAa,GAAGJ,IAAI,CAACK,IAAL,CAAWP,MAAM,GAAGI,aAApB,CAAtB;AACA,QAAMI,cAAc,GAAG,KAAMJ,aAAa,GAAGE,aAAtB,CAAvB;AAEA,SACC;AACC,kBAAaZ,OAAO;AACnB;AACAD,IAAAA,EAAE,CAAE,mBAAF,CAFiB,EAGnBQ,KAHmB;AADrB,KAOGT,KAAK,CAAEY,aAAF,EAAmBK,CAAF,IACvB,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,cAAcA,CAAG,EADzB;AAEC,IAAA,SAAS,EAAC,0CAFX;AAGC,IAAA,IAAI,EAAGZ,UAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADM,CAPR,EAeGL,KAAK,CAAEc,aAAF,EAAmBG,CAAF,IACvB,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,cAAcA,CAAG,EADzB;AAEC,IAAA,SAAS,EAAC,+CAFX;AAGC,IAAA,IAAI,EAAGX,QAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADM,CAfR,EAuBGN,KAAK,CAAEgB,cAAF,EAAoBC,CAAF,IACxB,cAAC,IAAD;AACC,IAAA,GAAG,EAAI,eAAeA,CAAG,EAD1B;AAEC,IAAA,SAAS,EAAC,2CAFX;AAGC,IAAA,IAAI,EAAGb,SAHR;AAIC,IAAA,IAAI,EAAG;AAJR,IADM,CAvBR,CADD;AAkCA;;AAED,eAAeG,KAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { times } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Icon, starEmpty, starFilled, starHalf } from '@wordpress/icons';\n\nfunction Stars( { rating } ) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tconst fullStarCount = Math.floor( rating );\n\tconst halfStarCount = Math.ceil( rating - fullStarCount );\n\tconst emptyStarCount = 5 - ( fullStarCount + halfStarCount );\n\n\treturn (\n\t\t<span\n\t\t\taria-label={ sprintf(\n\t\t\t\t/* translators: %s: number of stars. */\n\t\t\t\t__( '%s out of 5 stars' ),\n\t\t\t\tstars\n\t\t\t) }\n\t\t>\n\t\t\t{ times( fullStarCount, ( i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `full_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-full\"\n\t\t\t\t\ticon={ starFilled }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ times( halfStarCount, ( i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `half_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-half-full\"\n\t\t\t\t\ticon={ starHalf }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ times( emptyStarCount, ( i ) => (\n\t\t\t\t<Icon\n\t\t\t\t\tkey={ `empty_stars_${ i }` }\n\t\t\t\t\tclassName=\"block-directory-block-ratings__star-empty\"\n\t\t\t\t\ticon={ starEmpty }\n\t\t\t\t\tsize={ 16 }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</span>\n\t);\n}\n\nexport default Stars;\n"]}
|
|
@@ -9,34 +9,39 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import DownloadableBlockIcon from '../downloadable-block-icon';
|
|
12
|
-
export default function CompactList({
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export default function CompactList(_ref) {
|
|
13
|
+
let {
|
|
14
|
+
items
|
|
15
|
+
} = _ref;
|
|
16
|
+
|
|
15
17
|
if (!items.length) {
|
|
16
18
|
return null;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
return createElement("ul", {
|
|
20
22
|
className: "block-directory-compact-list"
|
|
21
|
-
}, items.map(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
}, items.map(_ref2 => {
|
|
24
|
+
let {
|
|
25
|
+
icon,
|
|
26
|
+
id,
|
|
27
|
+
title,
|
|
28
|
+
author
|
|
29
|
+
} = _ref2;
|
|
30
|
+
return createElement("li", {
|
|
31
|
+
key: id,
|
|
32
|
+
className: "block-directory-compact-list__item"
|
|
33
|
+
}, createElement(DownloadableBlockIcon, {
|
|
34
|
+
icon: icon,
|
|
35
|
+
title: title
|
|
36
|
+
}), createElement("div", {
|
|
37
|
+
className: "block-directory-compact-list__item-details"
|
|
38
|
+
}, createElement("div", {
|
|
39
|
+
className: "block-directory-compact-list__item-title"
|
|
40
|
+
}, title), createElement("div", {
|
|
41
|
+
className: "block-directory-compact-list__item-author"
|
|
42
|
+
}, sprintf(
|
|
43
|
+
/* translators: %s: Name of the block author. */
|
|
44
|
+
__('By %s'), author))));
|
|
45
|
+
}));
|
|
41
46
|
}
|
|
42
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/compact-list/index.js"],"names":["__","sprintf","DownloadableBlockIcon","CompactList","items","length","map","icon","id","title","author"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,eAAe,SAASC,WAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/compact-list/index.js"],"names":["__","sprintf","DownloadableBlockIcon","CompactList","items","length","map","icon","id","title","author"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AAEA,eAAe,SAASC,WAAT,OAAkC;AAAA,MAAZ;AAAEC,IAAAA;AAAF,GAAY;;AAChD,MAAK,CAAEA,KAAK,CAACC,MAAb,EAAsB;AACrB,WAAO,IAAP;AACA;;AAED,SACC;AAAI,IAAA,SAAS,EAAC;AAAd,KACGD,KAAK,CAACE,GAAN,CAAW;AAAA,QAAE;AAAEC,MAAAA,IAAF;AAAQC,MAAAA,EAAR;AAAYC,MAAAA,KAAZ;AAAmBC,MAAAA;AAAnB,KAAF;AAAA,WACZ;AAAI,MAAA,GAAG,EAAGF,EAAV;AAAe,MAAA,SAAS,EAAC;AAAzB,OACC,cAAC,qBAAD;AAAuB,MAAA,IAAI,EAAGD,IAA9B;AAAqC,MAAA,KAAK,EAAGE;AAA7C,MADD,EAGC;AAAK,MAAA,SAAS,EAAC;AAAf,OACC;AAAK,MAAA,SAAS,EAAC;AAAf,OACGA,KADH,CADD,EAIC;AAAK,MAAA,SAAS,EAAC;AAAf,OACGR,OAAO;AACR;AACAD,IAAAA,EAAE,CAAE,OAAF,CAFM,EAGRU,MAHQ,CADV,CAJD,CAHD,CADY;AAAA,GAAX,CADH,CADD;AAsBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport DownloadableBlockIcon from '../downloadable-block-icon';\n\nexport default function CompactList( { items } ) {\n\tif ( ! items.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<ul className=\"block-directory-compact-list\">\n\t\t\t{ items.map( ( { icon, id, title, author } ) => (\n\t\t\t\t<li key={ id } className=\"block-directory-compact-list__item\">\n\t\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\n\t\t\t\t\t<div className=\"block-directory-compact-list__item-details\">\n\t\t\t\t\t\t<div className=\"block-directory-compact-list__item-title\">\n\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div className=\"block-directory-compact-list__item-author\">\n\t\t\t\t\t\t\t{ sprintf(\n\t\t\t\t\t\t\t\t/* translators: %s: Name of the block author. */\n\t\t\t\t\t\t\t\t__( 'By %s' ),\n\t\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</li>\n\t\t\t) ) }\n\t\t</ul>\n\t);\n}\n"]}
|
|
@@ -5,9 +5,10 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import { BlockIcon } from '@wordpress/block-editor';
|
|
7
7
|
|
|
8
|
-
function DownloadableBlockIcon({
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
function DownloadableBlockIcon(_ref) {
|
|
9
|
+
let {
|
|
10
|
+
icon
|
|
11
|
+
} = _ref;
|
|
11
12
|
const className = 'block-directory-downloadable-block-icon';
|
|
12
13
|
return icon.match(/\.(jpeg|jpg|gif|png|svg)(?:\?.*)?$/) !== null ? createElement("img", {
|
|
13
14
|
className: className,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-icon/index.js"],"names":["BlockIcon","DownloadableBlockIcon","icon","className","match"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,yBAA1B;;AAEA,SAASC,qBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-icon/index.js"],"names":["BlockIcon","DownloadableBlockIcon","icon","className","match"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,yBAA1B;;AAEA,SAASC,qBAAT,OAA2C;AAAA,MAAX;AAAEC,IAAAA;AAAF,GAAW;AAC1C,QAAMC,SAAS,GAAG,yCAAlB;AACA,SAAOD,IAAI,CAACE,KAAL,CAAY,oCAAZ,MAAuD,IAAvD,GACN;AAAK,IAAA,SAAS,EAAGD,SAAjB;AAA6B,IAAA,GAAG,EAAGD,IAAnC;AAA0C,IAAA,GAAG,EAAC;AAA9C,IADM,GAGN,cAAC,SAAD;AAAW,IAAA,SAAS,EAAGC,SAAvB;AAAmC,IAAA,IAAI,EAAGD,IAA1C;AAAiD,IAAA,UAAU;AAA3D,IAHD;AAKA;;AAED,eAAeD,qBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { BlockIcon } from '@wordpress/block-editor';\n\nfunction DownloadableBlockIcon( { icon } ) {\n\tconst className = 'block-directory-downloadable-block-icon';\n\treturn icon.match( /\\.(jpeg|jpg|gif|png|svg)(?:\\?.*)?$/ ) !== null ? (\n\t\t<img className={ className } src={ icon } alt=\"\" />\n\t) : (\n\t\t<BlockIcon className={ className } icon={ icon } showColors />\n\t);\n}\n\nexport default DownloadableBlockIcon;\n"]}
|
|
@@ -19,15 +19,17 @@ import DownloadableBlockIcon from '../downloadable-block-icon';
|
|
|
19
19
|
import DownloadableBlockNotice from '../downloadable-block-notice';
|
|
20
20
|
import { store as blockDirectoryStore } from '../../store'; // Return the appropriate block item label, given the block data and status.
|
|
21
21
|
|
|
22
|
-
function getDownloadableBlockLabel({
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
function getDownloadableBlockLabel(_ref, _ref2) {
|
|
23
|
+
let {
|
|
24
|
+
title,
|
|
25
|
+
rating,
|
|
26
|
+
ratingCount
|
|
27
|
+
} = _ref;
|
|
28
|
+
let {
|
|
29
|
+
hasNotice,
|
|
30
|
+
isInstalled,
|
|
31
|
+
isInstalling
|
|
32
|
+
} = _ref2;
|
|
31
33
|
const stars = Math.round(rating / 0.5) * 0.5;
|
|
32
34
|
|
|
33
35
|
if (!isInstalled && hasNotice) {
|
|
@@ -56,11 +58,12 @@ function getDownloadableBlockLabel({
|
|
|
56
58
|
_n('Install %1$s. %2$s stars with %3$s review.', 'Install %1$s. %2$s stars with %3$s reviews.', ratingCount), decodeEntities(title), stars, ratingCount);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
function DownloadableBlockListItem({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
function DownloadableBlockListItem(_ref3) {
|
|
62
|
+
let {
|
|
63
|
+
composite,
|
|
64
|
+
item,
|
|
65
|
+
onClick
|
|
66
|
+
} = _ref3;
|
|
64
67
|
const {
|
|
65
68
|
author,
|
|
66
69
|
description,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-list-item/index.js"],"names":["__","_n","sprintf","Button","Spinner","VisuallyHidden","__unstableCompositeItem","CompositeItem","createInterpolateElement","decodeEntities","getBlockType","useSelect","BlockRatings","DownloadableBlockIcon","DownloadableBlockNotice","store","blockDirectoryStore","getDownloadableBlockLabel","title","rating","ratingCount","hasNotice","isInstalled","isInstalling","stars","Math","round","DownloadableBlockListItem","composite","item","onClick","author","description","icon","name","isInstallable","select","getErrorNoticeForBlock","isBlockInstalling","notice","id","hasFatal","isFatal","statusText","event","preventDefault","span"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SACCC,MADD,EAECC,OAFD,EAGCC,cAHD,EAICC,uBAAuB,IAAIC,aAJ5B,QAKO,uBALP;AAMA,SAASC,wBAAT,QAAyC,oBAAzC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,uBAAP,MAAoC,8BAApC;AACA,SAASC,KAAK,IAAIC,mBAAlB,QAA6C,aAA7C,C,CAEA;;AACA,SAASC,yBAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/components/downloadable-block-list-item/index.js"],"names":["__","_n","sprintf","Button","Spinner","VisuallyHidden","__unstableCompositeItem","CompositeItem","createInterpolateElement","decodeEntities","getBlockType","useSelect","BlockRatings","DownloadableBlockIcon","DownloadableBlockNotice","store","blockDirectoryStore","getDownloadableBlockLabel","title","rating","ratingCount","hasNotice","isInstalled","isInstalling","stars","Math","round","DownloadableBlockListItem","composite","item","onClick","author","description","icon","name","isInstallable","select","getErrorNoticeForBlock","isBlockInstalling","notice","id","hasFatal","isFatal","statusText","event","preventDefault","span"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,EAAb,EAAiBC,OAAjB,QAAgC,iBAAhC;AACA,SACCC,MADD,EAECC,OAFD,EAGCC,cAHD,EAICC,uBAAuB,IAAIC,aAJ5B,QAKO,uBALP;AAMA,SAASC,wBAAT,QAAyC,oBAAzC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,YAAT,QAA6B,mBAA7B;AACA,SAASC,SAAT,Q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tVisuallyHidden,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { createInterpolateElement } from '@wordpress/element';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { getBlockType } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport BlockRatings from '../block-ratings';\nimport DownloadableBlockIcon from '../downloadable-block-icon';\nimport DownloadableBlockNotice from '../downloadable-block-notice';\nimport { store as blockDirectoryStore } from '../../store';\n\n// Return the appropriate block item label, given the block data and status.\nfunction getDownloadableBlockLabel(\n\t{ title, rating, ratingCount },\n\t{ hasNotice, isInstalled, isInstalling }\n) {\n\tconst stars = Math.round( rating / 0.5 ) * 0.5;\n\n\tif ( ! isInstalled && hasNotice ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Retry installing %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalled ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Add %s.', decodeEntities( title ) );\n\t}\n\n\tif ( isInstalling ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Installing %s.', decodeEntities( title ) );\n\t}\n\n\t// No ratings yet, just use the title.\n\tif ( ratingCount < 1 ) {\n\t\t/* translators: %1$s: block title */\n\t\treturn sprintf( 'Install %s.', decodeEntities( title ) );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: %1$s: block title, %2$s: average rating, %3$s: total ratings count. */\n\t\t_n(\n\t\t\t'Install %1$s. %2$s stars with %3$s review.',\n\t\t\t'Install %1$s. %2$s stars with %3$s reviews.',\n\t\t\tratingCount\n\t\t),\n\t\tdecodeEntities( title ),\n\t\tstars,\n\t\tratingCount\n\t);\n}\n\nfunction DownloadableBlockListItem( { composite, item, onClick } ) {\n\tconst { author, description, icon, rating, title } = item;\n\t// getBlockType returns a block object if this block exists, or null if not.\n\tconst isInstalled = !! getBlockType( item.name );\n\n\tconst { hasNotice, isInstalling, isInstallable } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetErrorNoticeForBlock,\n\t\t\t\tisInstalling: isBlockInstalling,\n\t\t\t} = select( blockDirectoryStore );\n\t\t\tconst notice = getErrorNoticeForBlock( item.id );\n\t\t\tconst hasFatal = notice && notice.isFatal;\n\t\t\treturn {\n\t\t\t\thasNotice: !! notice,\n\t\t\t\tisInstalling: isBlockInstalling( item.id ),\n\t\t\t\tisInstallable: ! hasFatal,\n\t\t\t};\n\t\t},\n\t\t[ item ]\n\t);\n\n\tlet statusText = '';\n\tif ( isInstalled ) {\n\t\tstatusText = __( 'Installed!' );\n\t} else if ( isInstalling ) {\n\t\tstatusText = __( 'Installing…' );\n\t}\n\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName=\"block-directory-downloadable-block-list-item\"\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t\tisBusy={ isInstalling }\n\t\t\tdisabled={ isInstalling || ! isInstallable }\n\t\t\tlabel={ getDownloadableBlockLabel( item, {\n\t\t\t\thasNotice,\n\t\t\t\tisInstalled,\n\t\t\t\tisInstalling,\n\t\t\t} ) }\n\t\t\tshowTooltip={ true }\n\t\t\ttooltipPosition=\"top center\"\n\t\t>\n\t\t\t<div className=\"block-directory-downloadable-block-list-item__icon\">\n\t\t\t\t<DownloadableBlockIcon icon={ icon } title={ title } />\n\t\t\t\t{ isInstalling ? (\n\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__spinner\">\n\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t</span>\n\t\t\t\t) : (\n\t\t\t\t\t<BlockRatings rating={ rating } />\n\t\t\t\t) }\n\t\t\t</div>\n\t\t\t<span className=\"block-directory-downloadable-block-list-item__details\">\n\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__title\">\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t/* translators: %1$s: block title, %2$s: author name. */\n\t\t\t\t\t\t\t__( '%1$s <span>by %2$s</span>' ),\n\t\t\t\t\t\t\tdecodeEntities( title ),\n\t\t\t\t\t\t\tauthor\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tspan: (\n\t\t\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__author\" />\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t) }\n\t\t\t\t</span>\n\t\t\t\t{ hasNotice ? (\n\t\t\t\t\t<DownloadableBlockNotice block={ item } />\n\t\t\t\t) : (\n\t\t\t\t\t<>\n\t\t\t\t\t\t<span className=\"block-directory-downloadable-block-list-item__desc\">\n\t\t\t\t\t\t\t{ !! statusText\n\t\t\t\t\t\t\t\t? statusText\n\t\t\t\t\t\t\t\t: decodeEntities( description ) }\n\t\t\t\t\t\t</span>\n\t\t\t\t\t\t{ isInstallable &&\n\t\t\t\t\t\t\t! ( isInstalled || isInstalling ) && (\n\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t\t{ __( 'Install block' ) }\n\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t</>\n\t\t\t\t) }\n\t\t\t</span>\n\t\t</CompositeItem>\n\t);\n}\n\nexport default DownloadableBlockListItem;\n"]}
|
|
@@ -10,9 +10,10 @@ import { useSelect } from '@wordpress/data';
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { store as blockDirectoryStore } from '../../store';
|
|
13
|
-
export const DownloadableBlockNotice =
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
export const DownloadableBlockNotice = _ref => {
|
|
14
|
+
let {
|
|
15
|
+
block
|
|
16
|
+
} = _ref;
|
|
16
17
|
const errorNotice = useSelect(select => select(blockDirectoryStore).getErrorNoticeForBlock(block.id), [block]);
|
|
17
18
|
|
|
18
19
|
if (!errorNotice) {
|