@wordpress/block-directory 6.0.0 → 6.1.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/build/components/auto-block-uninstaller/index.cjs +26 -47
- package/build/components/auto-block-uninstaller/index.cjs.map +1 -7
- package/build/components/block-ratings/index.cjs +28 -34
- package/build/components/block-ratings/index.cjs.map +1 -7
- package/build/components/block-ratings/stars.cjs +35 -71
- package/build/components/block-ratings/stars.cjs.map +1 -7
- package/build/components/compact-list/index.cjs +45 -43
- package/build/components/compact-list/index.cjs.map +1 -7
- package/build/components/downloadable-block-icon/index.cjs +20 -29
- package/build/components/downloadable-block-icon/index.cjs.map +1 -7
- package/build/components/downloadable-block-list-item/index.cjs +95 -161
- package/build/components/downloadable-block-list-item/index.cjs.map +1 -7
- package/build/components/downloadable-block-notice/index.cjs +23 -46
- package/build/components/downloadable-block-notice/index.cjs.map +1 -7
- package/build/components/downloadable-blocks-list/index.cjs +50 -70
- package/build/components/downloadable-blocks-list/index.cjs.map +1 -7
- package/build/components/downloadable-blocks-panel/index.cjs +79 -119
- package/build/components/downloadable-blocks-panel/index.cjs.map +1 -7
- package/build/components/downloadable-blocks-panel/inserter-panel.cjs +37 -61
- package/build/components/downloadable-blocks-panel/inserter-panel.cjs.map +1 -7
- package/build/components/downloadable-blocks-panel/no-results.cjs +27 -46
- package/build/components/downloadable-blocks-panel/no-results.cjs.map +1 -7
- package/build/index.cjs +11 -29
- package/build/plugins/get-install-missing/index.cjs +80 -122
- package/build/plugins/get-install-missing/index.cjs.map +1 -7
- package/build/plugins/get-install-missing/install-button.cjs +33 -70
- package/build/plugins/get-install-missing/install-button.cjs.map +1 -7
- package/build/plugins/index.cjs +45 -45
- package/build/plugins/index.cjs.map +1 -7
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.cjs +40 -52
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.cjs.map +1 -7
- package/build/plugins/installed-blocks-pre-publish-panel/index.cjs +38 -62
- package/build/plugins/installed-blocks-pre-publish-panel/index.cjs.map +1 -7
- package/build/store/actions.cjs +233 -205
- package/build/store/actions.cjs.map +1 -7
- package/build/store/index.cjs +56 -45
- package/build/store/index.cjs.map +1 -7
- package/build/store/load-assets.cjs +62 -63
- package/build/store/load-assets.cjs.map +1 -7
- package/build/store/reducer.cjs +90 -101
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/resolvers.cjs +34 -54
- package/build/store/resolvers.cjs.map +1 -7
- package/build/store/selectors.cjs +111 -107
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/utils/get-plugin-url.cjs +19 -32
- package/build/store/utils/get-plugin-url.cjs.map +1 -7
- package/build-module/components/auto-block-uninstaller/index.mjs +19 -25
- package/build-module/components/auto-block-uninstaller/index.mjs.map +1 -7
- package/build-module/components/block-ratings/index.mjs +8 -8
- package/build-module/components/block-ratings/index.mjs.map +1 -7
- package/build-module/components/block-ratings/stars.mjs +28 -49
- package/build-module/components/block-ratings/stars.mjs.map +1 -7
- package/build-module/components/compact-list/index.mjs +24 -19
- package/build-module/components/compact-list/index.mjs.map +1 -7
- package/build-module/components/downloadable-block-icon/index.mjs +14 -8
- package/build-module/components/downloadable-block-icon/index.mjs.map +1 -7
- package/build-module/components/downloadable-block-list-item/index.mjs +64 -130
- package/build-module/components/downloadable-block-list-item/index.mjs.map +1 -7
- package/build-module/components/downloadable-block-notice/index.mjs +15 -20
- package/build-module/components/downloadable-block-notice/index.mjs.map +1 -7
- package/build-module/components/downloadable-blocks-list/index.mjs +26 -43
- package/build-module/components/downloadable-blocks-list/index.mjs.map +1 -7
- package/build-module/components/downloadable-blocks-panel/index.mjs +52 -91
- package/build-module/components/downloadable-blocks-panel/index.mjs.map +1 -7
- package/build-module/components/downloadable-blocks-panel/inserter-panel.mjs +29 -38
- package/build-module/components/downloadable-blocks-panel/inserter-panel.mjs.map +1 -7
- package/build-module/components/downloadable-blocks-panel/no-results.mjs +19 -23
- package/build-module/components/downloadable-blocks-panel/no-results.mjs.map +1 -7
- package/build-module/index.mjs +1 -6
- package/build-module/plugins/get-install-missing/index.mjs +55 -98
- package/build-module/plugins/get-install-missing/index.mjs.map +1 -7
- package/build-module/plugins/get-install-missing/install-button.mjs +25 -47
- package/build-module/plugins/get-install-missing/install-button.mjs.map +1 -7
- package/build-module/plugins/index.mjs +16 -23
- package/build-module/plugins/index.mjs.map +1 -7
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs +17 -26
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.mjs.map +1 -7
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs +15 -36
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.mjs.map +1 -7
- package/build-module/store/actions.mjs +201 -170
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/index.mjs +28 -13
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/load-assets.mjs +42 -36
- package/build-module/store/load-assets.mjs.map +1 -7
- package/build-module/store/reducer.mjs +81 -74
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/resolvers.mjs +13 -26
- package/build-module/store/resolvers.mjs.map +1 -7
- package/build-module/store/selectors.mjs +99 -76
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/utils/get-plugin-url.mjs +14 -12
- package/build-module/store/utils/get-plugin-url.mjs.map +1 -7
- package/build-style/style-rtl.css +6 -12
- package/build-style/style.css +6 -12
- package/package.json +22 -23
- package/src/components/downloadable-block-list-item/style.scss +6 -6
- package/build/index.cjs.map +0 -7
- package/build/lock-unlock.cjs +0 -36
- package/build/lock-unlock.cjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/lock-unlock.mjs +0 -11
- package/build-module/lock-unlock.mjs.map +0 -7
- package/src/lock-unlock.js +0 -7
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/actions.js"],
|
|
4
|
-
"sourcesContent": ["import {\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';\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 =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'ancestor',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'selectors',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t\t'allowed_blocks',\n\t\t\t\t'block_hooks',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\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} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\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"],
|
|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AAe;AAAA,IAChB,CAAE;AAAA,EACH;AACA,WAAS,gBAAiB,IAAI,KAAM;AACpC,SAAO;AACR;AAOM,IAAM,qBACZ,CAAE,UACF,OAAQ,EAAE,UAAU,SAAS,MAAO;AACnC,MAAI;AACH,UAAM,MAAM,aAAc,KAAM;AAChC,UAAM,SAAU;AAAA,MACf,QAAQ;AAAA,MACR;AAAA,MACA,MAAM,EAAE,QAAQ,WAAW;AAAA,IAC5B,CAAE;AACF,UAAM,SAAU;AAAA,MACf,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AACF,aAAS,yBAA0B,KAAM;AAAA,EAC1C,SAAU,OAAQ;AACjB,aACE,SAAU,YAAa,EACvB;AAAA,MACA,MAAM,WAAW,GAAI,oBAAqB;AAAA,IAC3C;AAAA,EACF;AACD;AAUM,SAAS,sBAAuB,MAAO;AAC7C,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,yBAA0B,MAAO;AAChD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,gBAAiB,SAAS,cAAe;AACxD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAWO,SAAS,eAAgB,SAAS,SAAS,UAAU,OAAQ;AACnE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,iBAAkB,SAAU;AAC3C,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"actions.mjs","names":["blocksStore","noticesStore"],"sources":["../../src/store/actions.js"],"sourcesContent":["import {\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';\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 =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'ancestor',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'selectors',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t\t'allowed_blocks',\n\t\t\t\t'block_hooks',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\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} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\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"],"mappings":";;;;;;;;;;;;;;;;AAmBA,SAAgB,wBAAyB,aAAc;CACtD,OAAO;EAAE,MAAM;EAA6B;CAAY;AACzD;;;;;;;;;;AAWA,SAAgB,0BAA2B,oBAAoB,aAAc;CAC5E,O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+1,35 @@
|
|
|
1
|
-
// packages/block-directory/src/store/index.js
|
|
2
1
|
import { createReduxStore, register } from "@wordpress/data";
|
|
3
2
|
import reducer from "./reducer.mjs";
|
|
4
3
|
import * as selectors from "./selectors.mjs";
|
|
5
4
|
import * as actions from "./actions.mjs";
|
|
6
5
|
import * as resolvers from "./resolvers.mjs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
// packages/block-directory/src/store/index.js
|
|
7
|
+
/**
|
|
8
|
+
* Module Constants
|
|
9
|
+
*/
|
|
10
|
+
const STORE_NAME = "core/block-directory";
|
|
11
|
+
/**
|
|
12
|
+
* Block editor data store configuration.
|
|
13
|
+
*
|
|
14
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
|
|
15
|
+
*
|
|
16
|
+
* @type {Object}
|
|
17
|
+
*/
|
|
18
|
+
const storeConfig = {
|
|
19
|
+
reducer,
|
|
20
|
+
selectors,
|
|
21
|
+
actions,
|
|
22
|
+
resolvers
|
|
13
23
|
};
|
|
14
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Store definition for the block directory namespace.
|
|
26
|
+
*
|
|
27
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
28
|
+
*
|
|
29
|
+
* @type {Object}
|
|
30
|
+
*/
|
|
31
|
+
const store = createReduxStore(STORE_NAME, storeConfig);
|
|
15
32
|
register(store);
|
|
16
|
-
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=index.mjs.map
|
|
33
|
+
export { store, storeConfig };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/index.js"],
|
|
4
|
-
"sourcesContent": ["import { createReduxStore, register } from '@wordpress/data';\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};\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
|
-
"mappings": ";AAAA,SAAS,kBAAkB,gBAAgB;AAC3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,aAAa;AACzB,YAAY,eAAe;AAK3B,IAAM,aAAa;AASZ,IAAM,cAAc;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AASO,IAAM,QAAQ,iBAAkB,YAAY,WAAY;AAE/D,SAAU,KAAM;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/store/index.js"],"sourcesContent":["import { createReduxStore, register } from '@wordpress/data';\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};\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"],"mappings":";;;;;;;;;AASA,MAAM,aAAa;;;;;;;;AASnB,MAAa,cAAc;CAC1B;CACA;CACA;CACA;AACD;;;;;;;;AASA,MAAa,QAAQ,iBAAkB,YAAY,WAAY;AAE/D,SAAU,KAAM"}
|
|
@@ -1,40 +1,46 @@
|
|
|
1
|
-
// packages/block-directory/src/store/load-assets.js
|
|
2
1
|
import apiFetch from "@wordpress/api-fetch";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
// packages/block-directory/src/store/load-assets.js
|
|
3
|
+
/**
|
|
4
|
+
* Load an asset for a block.
|
|
5
|
+
*
|
|
6
|
+
* This function returns a Promise that will resolve once the asset is loaded,
|
|
7
|
+
* or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
|
|
8
|
+
*
|
|
9
|
+
* @param {HTMLElement} el A HTML Element asset to inject.
|
|
10
|
+
*
|
|
11
|
+
* @return {Promise} Promise which will resolve when the asset is loaded.
|
|
12
|
+
*/
|
|
13
|
+
const loadAsset = (el) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const newNode = document.createElement(el.nodeName);
|
|
16
|
+
[
|
|
17
|
+
"id",
|
|
18
|
+
"rel",
|
|
19
|
+
"src",
|
|
20
|
+
"href",
|
|
21
|
+
"type"
|
|
22
|
+
].forEach((attr) => {
|
|
23
|
+
if (el[attr]) newNode[attr] = el[attr];
|
|
24
|
+
});
|
|
25
|
+
if (el.innerHTML) newNode.appendChild(document.createTextNode(el.innerHTML));
|
|
26
|
+
newNode.onload = () => resolve(true);
|
|
27
|
+
newNode.onerror = () => reject(/* @__PURE__ */ new Error("Error loading asset."));
|
|
28
|
+
document.body.appendChild(newNode);
|
|
29
|
+
if ("link" === newNode.nodeName.toLowerCase() || "script" === newNode.nodeName.toLowerCase() && !newNode.src) resolve();
|
|
30
|
+
});
|
|
21
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Load the asset files for a block
|
|
34
|
+
*/
|
|
22
35
|
async function loadAssets() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
doc.querySelectorAll('link[rel="stylesheet"],script')
|
|
31
|
-
).filter((asset) => asset.id && !document.getElementById(asset.id));
|
|
32
|
-
for (const newAsset of newAssets) {
|
|
33
|
-
await loadAsset(newAsset);
|
|
34
|
-
}
|
|
36
|
+
const data = await (await apiFetch({
|
|
37
|
+
url: document.location.href,
|
|
38
|
+
parse: false
|
|
39
|
+
})).text();
|
|
40
|
+
const doc = new window.DOMParser().parseFromString(data, "text/html");
|
|
41
|
+
const newAssets = Array.from(doc.querySelectorAll("link[rel=\"stylesheet\"],script")).filter((asset) => asset.id && !document.getElementById(asset.id));
|
|
42
|
+
for (const newAsset of newAssets) await loadAsset(newAsset);
|
|
35
43
|
}
|
|
36
|
-
export {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=load-assets.mjs.map
|
|
44
|
+
export { loadAsset, loadAssets };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=load-assets.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/load-assets.js"],
|
|
4
|
-
"sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\n\n/**\n * Load an asset for a block.\n *\n * This function returns a Promise that will resolve once the asset is loaded,\n * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.\n *\n * @param {HTMLElement} el A HTML Element asset to inject.\n *\n * @return {Promise} Promise which will resolve when the asset is loaded.\n */\nexport const loadAsset = ( el ) => {\n\treturn new Promise( ( resolve, reject ) => {\n\t\t/*\n\t\t * Reconstruct the passed element, this is required as inserting the Node directly\n\t\t * won't always fire the required onload events, even if the asset wasn't already loaded.\n\t\t */\n\t\tconst newNode = document.createElement( el.nodeName );\n\n\t\t[ 'id', 'rel', 'src', 'href', 'type' ].forEach( ( attr ) => {\n\t\t\tif ( el[ attr ] ) {\n\t\t\t\tnewNode[ attr ] = el[ attr ];\n\t\t\t}\n\t\t} );\n\n\t\t// Append inline <script> contents.\n\t\tif ( el.innerHTML ) {\n\t\t\tnewNode.appendChild( document.createTextNode( el.innerHTML ) );\n\t\t}\n\n\t\tnewNode.onload = () => resolve( true );\n\t\tnewNode.onerror = () => reject( new Error( 'Error loading asset.' ) );\n\n\t\tdocument.body.appendChild( newNode );\n\n\t\t// Resolve Stylesheets and Inline JavaScript immediately.\n\t\tif (\n\t\t\t'link' === newNode.nodeName.toLowerCase() ||\n\t\t\t( 'script' === newNode.nodeName.toLowerCase() && ! newNode.src )\n\t\t) {\n\t\t\tresolve();\n\t\t}\n\t} );\n};\n\n/**\n * Load the asset files for a block\n */\nexport async function loadAssets() {\n\t/*\n\t * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the\n\t * JavaScript and CSS assets loaded between the pages. This imports the required assets\n\t * for the block into the current page while not requiring that we know them up-front.\n\t * In the future this can be improved by reliance upon block.json and/or a script-loader\n\t * dependency API.\n\t */\n\tconst response = await apiFetch( {\n\t\turl: document.location.href,\n\t\tparse: false,\n\t} );\n\n\tconst data = await response.text();\n\n\tconst doc = new window.DOMParser().parseFromString( data, 'text/html' );\n\n\tconst newAssets = Array.from(\n\t\tdoc.querySelectorAll( 'link[rel=\"stylesheet\"],script' )\n\t).filter( ( asset ) => asset.id && ! document.getElementById( asset.id ) );\n\n\t/*\n\t * Load each asset in order, as they may depend upon an earlier loaded script.\n\t * Stylesheets and Inline Scripts will resolve immediately upon insertion.\n\t */\n\tfor ( const newAsset of newAssets ) {\n\t\tawait loadAsset( newAsset );\n\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Fetch from '@wordpress/api-fetch';\n\n/**\n * Load an asset for a block.\n *\n * This function returns a Promise that will resolve once the asset is loaded,\n * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.\n *\n * @param {HTMLElement} el A HTML Element asset to inject.\n *\n * @return {Promise} Promise which will resolve when the asset is loaded.\n */\nexport const loadAsset = ( el ) => {\n\treturn new Promise( ( resolve, reject ) => {\n\t\t/*\n\t\t * Reconstruct the passed element, this is required as inserting the Node directly\n\t\t * won't always fire the required onload events, even if the asset wasn't already loaded.\n\t\t */\n\t\tconst newNode = document.createElement( el.nodeName );\n\n\t\t[ 'id', 'rel', 'src', 'href', 'type' ].forEach( ( attr ) => {\n\t\t\tif ( el[ attr ] ) {\n\t\t\t\tnewNode[ attr ] = el[ attr ];\n\t\t\t}\n\t\t} );\n\n\t\t// Append inline <script> contents.\n\t\tif ( el.innerHTML ) {\n\t\t\tnewNode.appendChild( document.createTextNode( el.innerHTML ) );\n\t\t}\n\n\t\tnewNode.onload = () => resolve( true );\n\t\tnewNode.onerror = () => reject( new Error( 'Error loading asset.' ) );\n\n\t\tdocument.body.appendChild( newNode );\n\n\t\t// Resolve Stylesheets and Inline JavaScript immediately.\n\t\tif (\n\t\t\t'link' === newNode.nodeName.toLowerCase() ||\n\t\t\t( 'script' === newNode.nodeName.toLowerCase() && ! newNode.src )\n\t\t) {\n\t\t\tresolve();\n\t\t}\n\t} );\n};\n\n/**\n * Load the asset files for a block\n */\nexport async function loadAssets() {\n\t/*\n\t * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the\n\t * JavaScript and CSS assets loaded between the pages. This imports the required assets\n\t * for the block into the current page while not requiring that we know them up-front.\n\t * In the future this can be improved by reliance upon block.json and/or a script-loader\n\t * dependency API.\n\t */\n\tconst response = await apiFetch( {\n\t\turl: document.location.href,\n\t\tparse: false,\n\t} );\n\n\tconst data = await response.text();\n\n\tconst doc = new window.DOMParser().parseFromString( data, 'text/html' );\n\n\tconst newAssets = Array.from(\n\t\tdoc.querySelectorAll( 'link[rel=\"stylesheet\"],script' )\n\t).filter( ( asset ) => asset.id && ! document.getElementById( asset.id ) );\n\n\t/*\n\t * Load each asset in order, as they may depend upon an earlier loaded script.\n\t * Stylesheets and Inline Scripts will resolve immediately upon insertion.\n\t */\n\tfor ( const newAsset of newAssets ) {\n\t\tawait loadAsset( newAsset );\n\t}\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,aAAc,OAAQ;CAClC,OAAO,IAAI,SAAW,SAAS,WAAY;EAK1C,MAAM,UAAU,SAAS,cAAe,GAAG,QAAS;EAEpD;GAAE;GAAM;GAAO;GAAO;GAAQ;EAAO,CAAC,CAAC,SAAW,SAAU;GAC3D,IAAK,GAAI,OACR,QAAS,QAAS,GAAI;EAExB,CAAE;EAGF,IAAK,GAAG,WACP,QAAQ,YAAa,SAAS,eAAgB,GAAG,SAAU,CAAE;EAG9D,QAAQ,eAAe,QAAS,IAAK;EACrC,QAAQ,gBAAgB,uBAAQ,IAAI,MAAO,sBAAuB,CAAE;EAEpE,SAAS,KAAK,YAAa,OAAQ;EAGnC,IACC,WAAW,QAAQ,SAAS,YAAY,KACtC,aAAa,QAAQ,SAAS,YAAY,KAAK,CAAE,QAAQ,KAE3D,QAAQ;CAEV,CAAE;AACH;;;;AAKA,eAAsB,aAAa;CAalC,MAAM,OAAO,OAAM,MALI,SAAU;EAChC,KAAK,SAAS,SAAS;EACvB,OAAO;CACR,CAAE,EAAA,CAE0B,KAAK;CAEjC,MAAM,MAAM,IAAI,OAAO,UAAU,CAAC,CAAC,gBAAiB,MAAM,WAAY;CAEtE,MAAM,YAAY,MAAM,KACvB,IAAI,iBAAkB,iCAAgC,CACvD,CAAC,CAAC,QAAU,UAAW,MAAM,MAAM,CAAE,SAAS,eAAgB,MAAM,EAAG,CAAE;CAMzE,KAAM,MAAM,YAAY,WACvB,MAAM,UAAW,QAAS;AAE5B"}
|
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
// packages/block-directory/src/store/reducer.js
|
|
2
1
|
import { combineReducers } from "@wordpress/data";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
// packages/block-directory/src/store/reducer.js
|
|
3
|
+
/**
|
|
4
|
+
* Reducer returning an array of downloadable blocks.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} state Current state.
|
|
7
|
+
* @param {Object} action Dispatched action.
|
|
8
|
+
*
|
|
9
|
+
* @return {Object} Updated state.
|
|
10
|
+
*/
|
|
11
|
+
const downloadableBlocks = (state = {}, action) => {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case "FETCH_DOWNLOADABLE_BLOCKS": return {
|
|
14
|
+
...state,
|
|
15
|
+
[action.filterValue]: { isRequesting: true }
|
|
16
|
+
};
|
|
17
|
+
case "RECEIVE_DOWNLOADABLE_BLOCKS": return {
|
|
18
|
+
...state,
|
|
19
|
+
[action.filterValue]: {
|
|
20
|
+
results: action.downloadableBlocks,
|
|
21
|
+
isRequesting: false
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return state;
|
|
22
26
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Reducer managing the installation and deletion of blocks.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} state Current state.
|
|
31
|
+
* @param {Object} action Dispatched action.
|
|
32
|
+
*
|
|
33
|
+
* @return {Object} Updated state.
|
|
34
|
+
*/
|
|
35
|
+
const blockManagement = (state = {
|
|
36
|
+
installedBlockTypes: [],
|
|
37
|
+
isInstalling: {}
|
|
26
38
|
}, action) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
...state,
|
|
46
|
-
isInstalling: {
|
|
47
|
-
...state.isInstalling,
|
|
48
|
-
[action.blockId]: action.isInstalling
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return state;
|
|
39
|
+
switch (action.type) {
|
|
40
|
+
case "ADD_INSTALLED_BLOCK_TYPE": return {
|
|
41
|
+
...state,
|
|
42
|
+
installedBlockTypes: [...state.installedBlockTypes, action.item]
|
|
43
|
+
};
|
|
44
|
+
case "REMOVE_INSTALLED_BLOCK_TYPE": return {
|
|
45
|
+
...state,
|
|
46
|
+
installedBlockTypes: state.installedBlockTypes.filter((blockType) => blockType.name !== action.item.name)
|
|
47
|
+
};
|
|
48
|
+
case "SET_INSTALLING_BLOCK": return {
|
|
49
|
+
...state,
|
|
50
|
+
isInstalling: {
|
|
51
|
+
...state.isInstalling,
|
|
52
|
+
[action.blockId]: action.isInstalling
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return state;
|
|
53
57
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Reducer returning an object of error notices.
|
|
60
|
+
*
|
|
61
|
+
* @param {Object} state Current state.
|
|
62
|
+
* @param {Object} action Dispatched action.
|
|
63
|
+
*
|
|
64
|
+
* @return {Object} Updated state.
|
|
65
|
+
*/
|
|
66
|
+
const errorNotices = (state = {}, action) => {
|
|
67
|
+
switch (action.type) {
|
|
68
|
+
case "SET_ERROR_NOTICE": return {
|
|
69
|
+
...state,
|
|
70
|
+
[action.blockId]: {
|
|
71
|
+
message: action.message,
|
|
72
|
+
isFatal: action.isFatal
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
case "CLEAR_ERROR_NOTICE":
|
|
76
|
+
const { [action.blockId]: blockId, ...restState } = state;
|
|
77
|
+
return restState;
|
|
78
|
+
}
|
|
79
|
+
return state;
|
|
69
80
|
};
|
|
70
81
|
var reducer_default = combineReducers({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
downloadableBlocks,
|
|
83
|
+
blockManagement,
|
|
84
|
+
errorNotices
|
|
74
85
|
});
|
|
75
|
-
export {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
downloadableBlocks,
|
|
79
|
-
errorNotices
|
|
80
|
-
};
|
|
81
|
-
//# sourceMappingURL=reducer.mjs.map
|
|
86
|
+
export { blockManagement, reducer_default as default, downloadableBlocks, errorNotices };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=reducer.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/reducer.js"],
|
|
4
|
-
"sourcesContent": ["import { 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\tconst { [ action.blockId ]: blockId, ...restState } = state;\n\t\t\treturn restState;\n\t}\n\treturn state;\n};\n\nexport default combineReducers( {\n\tdownloadableBlocks,\n\tblockManagement,\n\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AA,MACD;AAAA,IACD,KAAK;AACJ,YAAM,EAAE,CAAE,OAAO,OAAQ,GAAG,SAAS,GAAG,UAAU,IAAI;AACtD,aAAO;AAAA,EACT;AACA,SAAO;AACR;AAEA,IAAO,kBAAQ,gBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"reducer.mjs","names":[],"sources":["../../src/store/reducer.js"],"sourcesContent":["import { 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\tconst { [ action.blockId ]: blockId, ...restState } = state;\n\t\t\treturn restState;\n\t}\n\treturn state;\n};\n\nexport default combineReducers( {\n\tdownloadableBlocks,\n\tblockManagement,\n\terrorNotices,\n} );\n"],"mappings":";;;;;;;;;;AAUA,MAAa,sBAAuB,QAAQ,CAAC,GAAG,WAAY;CAC3D,QAAS,OAAO,MAAhB;EACC,KAAK,6BACJ,OAAO;GACN,GAAG;IACD,OAAO,cAAe,EACvB,cAAc,KACf;EACD;EACD,KAAK,+BACJ,OAAO;GACN,GAAG;IACD,OAAO,cAAe;IACvB,SAAS,OAAO;IAChB,cAAc;GACf;EACD;CACF;CACA,OAAO;AACR;;;;;;;;;AAUA,MAAa,mBACZ,QAAQ;CACP,qBAAqB,CAAC;CACtB,cAAc,CAAC;AAChB,GACA,WACI;CACJ,QAAS,OAAO,MAAhB;EACC,KAAK,4BACJ,OAAO;GACN,GAAG;GACH,qBAAqB,CACpB,GAAG,MAAM,qBACT,OAAO,IACR;EACD;EACD,KAAK,+BACJ,OAAO;GACN,GAAG;GACH,qBAAqB,MAAM,oBAAoB,QAC5C,cAAe,UAAU,SAAS,OAAO,KAAK,IACjD;EACD;EACD,KAAK,wBACJ,OAAO;GACN,GAAG;GACH,cAAc;IACb,GAAG,MAAM;KACP,OAAO,UAAW,OAAO;GAC5B;EACD;CACF;CACA,OAAO;AACR;;;;;;;;;AAUA,MAAa,gBAAiB,QAAQ,CAAC,GAAG,WAAY;CACrD,QAAS,OAAO,MAAhB;EACC,KAAK,oBACJ,OAAO;GACN,GAAG;IACD,OAAO,UAAW;IACnB,SAAS,OAAO;IAChB,SAAS,OAAO;GACjB;EACD;EACD,KAAK;GACJ,MAAM,GAAI,OAAO,UAAW,SAAS,GAAG,cAAc;GACtD,OAAO;CACT;CACA,OAAO;AACR;AAEA,IAAA,kBAAe,gBAAiB;CAC/B;CACA;CACA;AACD,CAAE"}
|
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
// packages/block-directory/src/store/resolvers.js
|
|
2
1
|
import { camelCase } from "change-case";
|
|
3
2
|
import apiFetch from "@wordpress/api-fetch";
|
|
4
3
|
import { fetchDownloadableBlocks, receiveDownloadableBlocks } from "./actions.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
(result) => Object.fromEntries(
|
|
16
|
-
Object.entries(result).map(([key, value]) => [
|
|
17
|
-
camelCase(key),
|
|
18
|
-
value
|
|
19
|
-
])
|
|
20
|
-
)
|
|
21
|
-
);
|
|
22
|
-
dispatch(receiveDownloadableBlocks(blocks, filterValue));
|
|
23
|
-
} catch {
|
|
24
|
-
dispatch(receiveDownloadableBlocks([], filterValue));
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
export {
|
|
28
|
-
getDownloadableBlocks
|
|
4
|
+
// packages/block-directory/src/store/resolvers.js
|
|
5
|
+
const getDownloadableBlocks = (filterValue) => async ({ dispatch }) => {
|
|
6
|
+
if (!filterValue) return;
|
|
7
|
+
try {
|
|
8
|
+
dispatch(fetchDownloadableBlocks(filterValue));
|
|
9
|
+
const blocks = (await apiFetch({ path: `wp/v2/block-directory/search?term=${filterValue}` })).map((result) => Object.fromEntries(Object.entries(result).map(([key, value]) => [camelCase(key), value])));
|
|
10
|
+
dispatch(receiveDownloadableBlocks(blocks, filterValue));
|
|
11
|
+
} catch {
|
|
12
|
+
dispatch(receiveDownloadableBlocks([], filterValue));
|
|
13
|
+
}
|
|
29
14
|
};
|
|
30
|
-
|
|
15
|
+
export { getDownloadableBlocks };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=resolvers.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/resolvers.js"],
|
|
4
|
-
"sourcesContent": ["import { camelCase } from 'change-case';\nimport apiFetch from '@wordpress/api-fetch';\nimport { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';\n\nexport const getDownloadableBlocks =\n\t( filterValue ) =>\n\tasync ( { dispatch } ) => {\n\t\tif ( ! filterValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tdispatch( fetchDownloadableBlocks( filterValue ) );\n\t\t\tconst results = await apiFetch( {\n\t\t\t\tpath: `wp/v2/block-directory/search?term=${ filterValue }`,\n\t\t\t} );\n\t\t\tconst blocks = results.map( ( result ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( result ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tdispatch( receiveDownloadableBlocks( blocks, filterValue ) );\n\t\t} catch {\n\t\t\tdispatch( receiveDownloadableBlocks( [], filterValue ) );\n\t\t}\n\t};\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,OAAO,cAAc;AACrB,SAAS,yBAAyB,iCAAiC;AAE5D,IAAM,wBACZ,CAAE,gBACF,OAAQ,EAAE,SAAS,MAAO;AACzB,MAAK,CAAE,aAAc;AACpB;AAAA,EACD;AAEA,MAAI;AACH,aAAU,wBAAyB,WAAY,CAAE;AACjD,UAAM,UAAU,MAAM,SAAU;AAAA,MAC/B,MAAM,qCAAsC,WAAY;AAAA,IACzD,CAAE;AACF,UAAM,SAAS,QAAQ;AAAA,MAAK,CAAE,WAC7B,OAAO;AAAA,QACN,OAAO,QAAS,MAAO,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO;AAAA,UACnD,UAAW,GAAI;AAAA,UACf;AAAA,QACD,CAAE;AAAA,MACH;AAAA,IACD;AAEA,aAAU,0BAA2B,QAAQ,WAAY,CAAE;AAAA,EAC5D,QAAQ;AACP,aAAU,0BAA2B,CAAC,GAAG,WAAY,CAAE;AAAA,EACxD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"resolvers.mjs","names":[],"sources":["../../src/store/resolvers.js"],"sourcesContent":["import { camelCase } from 'change-case';\nimport apiFetch from '@wordpress/api-fetch';\nimport { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';\n\nexport const getDownloadableBlocks =\n\t( filterValue ) =>\n\tasync ( { dispatch } ) => {\n\t\tif ( ! filterValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tdispatch( fetchDownloadableBlocks( filterValue ) );\n\t\t\tconst results = await apiFetch( {\n\t\t\t\tpath: `wp/v2/block-directory/search?term=${ filterValue }`,\n\t\t\t} );\n\t\t\tconst blocks = results.map( ( result ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( result ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tdispatch( receiveDownloadableBlocks( blocks, filterValue ) );\n\t\t} catch {\n\t\t\tdispatch( receiveDownloadableBlocks( [], filterValue ) );\n\t\t}\n\t};\n"],"mappings":";;;;AAIA,MAAa,yBACV,gBACF,OAAQ,EAAE,eAAgB;CACzB,IAAK,CAAE,aACN;CAGD,IAAI;EACH,SAAU,wBAAyB,WAAY,CAAE;EAIjD,MAAM,UAAS,MAHO,SAAU,EAC/B,MAAM,qCAAsC,cAC7C,CAAE,EAAA,CACqB,KAAO,WAC7B,OAAO,YACN,OAAO,QAAS,MAAO,CAAC,CAAC,KAAO,CAAE,KAAK,WAAa,CACnD,UAAW,GAAI,GACf,KACD,CAAE,CACH,CACD;EAEA,SAAU,0BAA2B,QAAQ,WAAY,CAAE;CAC5D,QAAQ;EACP,SAAU,0BAA2B,CAAC,GAAG,WAAY,CAAE;CACxD;AACD"}
|