@wordpress/block-directory 3.0.1 → 3.0.5
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/README.md +1 -1
- package/build/plugins/get-install-missing/install-button.js +2 -2
- package/build/plugins/get-install-missing/install-button.js.map +1 -1
- package/build/store/actions.js +44 -37
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +3 -9
- package/build/store/index.js.map +1 -1
- package/build/store/{controls.js → load-assets.js} +25 -41
- package/build/store/load-assets.js.map +1 -0
- package/build/store/resolvers.js +19 -19
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +4 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/plugins/get-install-missing/install-button.js +2 -2
- package/build-module/plugins/get-install-missing/install-button.js.map +1 -1
- package/build-module/store/actions.js +39 -34
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +3 -7
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/{controls.js → load-assets.js} +23 -37
- package/build-module/store/load-assets.js.map +1 -0
- package/build-module/store/resolvers.js +14 -17
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +4 -8
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +20 -21
- package/src/plugins/get-install-missing/install-button.js +4 -3
- package/src/store/actions.js +38 -46
- package/src/store/index.js +2 -4
- package/src/store/{controls.js → load-assets.js} +25 -42
- package/src/store/resolvers.js +17 -19
- package/src/store/selectors.js +2 -14
- package/src/store/test/actions.js +236 -267
- package/src/store/test/{controls.js → load-assets.js} +1 -1
- package/build/store/controls.js.map +0 -1
- package/build-module/store/controls.js.map +0 -1
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { store as blocksStore } from '@wordpress/blocks';
|
|
5
5
|
import { __, sprintf } from '@wordpress/i18n';
|
|
6
|
-
import
|
|
7
|
-
import { apiFetch } from '@wordpress/data-controls';
|
|
6
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
8
7
|
import { store as noticesStore } from '@wordpress/notices';
|
|
9
8
|
/**
|
|
10
9
|
* Internal dependencies
|
|
11
10
|
*/
|
|
12
11
|
|
|
13
|
-
import { loadAssets } from './
|
|
12
|
+
import { loadAssets } from './load-assets';
|
|
14
13
|
import getPluginUrl from './utils/get-plugin-url';
|
|
15
14
|
/**
|
|
16
15
|
* Returns an action object used in signalling that the downloadable blocks
|
|
@@ -52,54 +51,56 @@ export function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
52
51
|
* @return {boolean} Whether the block was successfully installed & loaded.
|
|
53
52
|
*/
|
|
54
53
|
|
|
55
|
-
export
|
|
54
|
+
export const installBlockType = block => async ({
|
|
55
|
+
registry,
|
|
56
|
+
dispatch
|
|
57
|
+
}) => {
|
|
56
58
|
const {
|
|
57
|
-
id
|
|
58
|
-
assets
|
|
59
|
+
id
|
|
59
60
|
} = block;
|
|
60
61
|
let success = false;
|
|
61
|
-
|
|
62
|
+
dispatch.clearErrorNotice(id);
|
|
62
63
|
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
dispatch.setIsInstalling(id, true); // If we have a wp:plugin link, the plugin is installed but inactive.
|
|
65
66
|
|
|
66
67
|
const url = getPluginUrl(block);
|
|
67
68
|
let links = {};
|
|
68
69
|
|
|
69
70
|
if (url) {
|
|
70
|
-
|
|
71
|
+
await apiFetch({
|
|
72
|
+
method: 'PUT',
|
|
71
73
|
url,
|
|
72
74
|
data: {
|
|
73
75
|
status: 'active'
|
|
74
|
-
}
|
|
75
|
-
method: 'PUT'
|
|
76
|
+
}
|
|
76
77
|
});
|
|
77
78
|
} else {
|
|
78
|
-
const response =
|
|
79
|
+
const response = await apiFetch({
|
|
80
|
+
method: 'POST',
|
|
79
81
|
path: 'wp/v2/plugins',
|
|
80
82
|
data: {
|
|
81
|
-
slug:
|
|
83
|
+
slug: id,
|
|
82
84
|
status: 'active'
|
|
83
|
-
}
|
|
84
|
-
method: 'POST'
|
|
85
|
+
}
|
|
85
86
|
}); // Add the `self` link for newly-installed blocks.
|
|
86
87
|
|
|
87
88
|
links = response._links;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
dispatch.addInstalledBlockType({ ...block,
|
|
91
92
|
links: { ...block.links,
|
|
92
93
|
...links
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
|
-
|
|
96
|
-
const registeredBlocks =
|
|
96
|
+
await loadAssets();
|
|
97
|
+
const registeredBlocks = registry.select(blocksStore).getBlockTypes();
|
|
97
98
|
|
|
98
99
|
if (!registeredBlocks.some(i => i.name === block.name)) {
|
|
99
100
|
throw new Error(__('Error registering block. Try reloading the page.'));
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
registry.dispatch(noticesStore).createInfoNotice(sprintf( // translators: %s is the block title.
|
|
103
104
|
__('Block %s installed and added.'), block.title), {
|
|
104
105
|
speak: true,
|
|
105
106
|
type: 'snackbar'
|
|
@@ -121,40 +122,44 @@ export function* installBlockType(block) {
|
|
|
121
122
|
message = fatalAPIErrors[error.code];
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
dispatch.setErrorNotice(id, message, isFatal);
|
|
126
|
+
registry.dispatch(noticesStore).createErrorNotice(message, {
|
|
126
127
|
speak: true,
|
|
127
128
|
isDismissible: true
|
|
128
129
|
});
|
|
129
130
|
}
|
|
130
131
|
|
|
131
|
-
|
|
132
|
+
dispatch.setIsInstalling(id, false);
|
|
132
133
|
return success;
|
|
133
|
-
}
|
|
134
|
+
};
|
|
134
135
|
/**
|
|
135
136
|
* Action triggered to uninstall a block plugin.
|
|
136
137
|
*
|
|
137
138
|
* @param {Object} block The blockType object.
|
|
138
139
|
*/
|
|
139
140
|
|
|
140
|
-
export
|
|
141
|
+
export const uninstallBlockType = block => async ({
|
|
142
|
+
registry,
|
|
143
|
+
dispatch
|
|
144
|
+
}) => {
|
|
141
145
|
try {
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
const url = getPluginUrl(block);
|
|
147
|
+
await apiFetch({
|
|
148
|
+
method: 'PUT',
|
|
149
|
+
url,
|
|
144
150
|
data: {
|
|
145
151
|
status: 'inactive'
|
|
146
|
-
}
|
|
147
|
-
method: 'PUT'
|
|
152
|
+
}
|
|
148
153
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
await apiFetch({
|
|
155
|
+
method: 'DELETE',
|
|
156
|
+
url
|
|
152
157
|
});
|
|
153
|
-
|
|
158
|
+
dispatch.removeInstalledBlockType(block);
|
|
154
159
|
} catch (error) {
|
|
155
|
-
|
|
160
|
+
registry.dispatch(noticesStore).createErrorNotice(error.message || __('An error occurred.'));
|
|
156
161
|
}
|
|
157
|
-
}
|
|
162
|
+
};
|
|
158
163
|
/**
|
|
159
164
|
* Returns an action object used to add a block type to the "newly installed"
|
|
160
165
|
* tracking list.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["store","blocksStore","__","sprintf","controls","apiFetch","noticesStore","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","id","assets","success","clearErrorNotice","setIsInstalling","url","links","data","status","method","response","path","slug","_links","addInstalledBlockType","registeredBlocks","select","name","some","i","Error","dispatch","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,QAAT,QAAyB,iBAAzB;AACA,SAASC,QAAT,QAAyB,0BAAzB;AACA,SAASL,KAAK,IAAIM,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,YA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AACA;AACA;AACA;;AACA,OAAO,SAASD,wBAAT,CAAmCC,IAAnC,EAA0C;AAChD,SAAO;AACNxC,IAAAA,IAAI,EAAE,6BADA;AAENwC,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAAS/B,eAAT,CAA0BgC,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACN1C,IAAAA,IAAI,EAAE,sBADA;AAENyC,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASN,cAAT,CAAyBK,OAAzB,EAAkCX,OAAlC,EAA2CC,OAAO,GAAG,KAArD,EAA6D;AACnE,SAAO;AACN/B,IAAAA,IAAI,EAAE,kBADA;AAENyC,IAAAA,OAFM;AAGNX,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASvB,gBAAT,CAA2BiC,OAA3B,EAAqC;AAC3C,SAAO;AACNzC,IAAAA,IAAI,EAAE,oBADA;AAENyC,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { controls } from '@wordpress/data';\nimport { apiFetch } from '@wordpress/data-controls';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './controls';\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 function* installBlockType( block ) {\n\tconst { id, assets } = block;\n\tlet success = false;\n\tyield clearErrorNotice( id );\n\ttry {\n\t\tyield setIsInstalling( block.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\tyield apiFetch( {\n\t\t\t\turl,\n\t\t\t\tdata: {\n\t\t\t\t\tstatus: 'active',\n\t\t\t\t},\n\t\t\t\tmethod: 'PUT',\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = yield apiFetch( {\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: {\n\t\t\t\t\tslug: block.id,\n\t\t\t\t\tstatus: 'active',\n\t\t\t\t},\n\t\t\t\tmethod: 'POST',\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\tyield addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\tyield loadAssets( assets );\n\t\tconst registeredBlocks = yield controls.select(\n\t\t\tblocksStore.name,\n\t\t\t'getBlockTypes'\n\t\t);\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\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'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\tyield setErrorNotice( id, message, isFatal );\n\t\tyield controls.dispatch( noticesStore, 'createErrorNotice', message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tyield setIsInstalling( block.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 function* uninstallBlockType( block ) {\n\ttry {\n\t\tyield apiFetch( {\n\t\t\turl: getPluginUrl( block ),\n\t\t\tdata: {\n\t\t\t\tstatus: 'inactive',\n\t\t\t},\n\t\t\tmethod: 'PUT',\n\t\t} );\n\t\tyield apiFetch( {\n\t\t\turl: getPluginUrl( block ),\n\t\t\tmethod: 'DELETE',\n\t\t} );\n\t\tyield removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createErrorNotice',\n\t\t\terror.message || __( 'An error occurred.' )\n\t\t);\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":["store","blocksStore","__","sprintf","apiFetch","noticesStore","loadAssets","getPluginUrl","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","getBlockTypes","some","i","name","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASJ,KAAK,IAAIK,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,eAA3B;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMI,gBAAgB,GAAKC,KAAF,IAAa,OAAQ;AACpDC,EAAAA,QADoD;AAEpDC,EAAAA;AAFoD,CAAR,KAGtC;AACN,QAAM;AAAEC,IAAAA;AAAF,MAASH,KAAf;AACA,MAAII,OAAO,GAAG,KAAd;AACAF,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,EAA3B;;AACA,MAAI;AACHD,IAAAA,QAAQ,CAACI,eAAT,CAA0BH,EAA1B,EAA8B,IAA9B,EADG,CAGH;;AACA,UAAMI,GAAG,GAAGd,YAAY,CAAEO,KAAF,CAAxB;AACA,QAAIQ,KAAK,GAAG,EAAZ;;AACA,QAAKD,GAAL,EAAW;AACV,YAAMjB,QAAQ,CAAE;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ies\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"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
-
import { controls as dataControls } from '@wordpress/data-controls';
|
|
6
5
|
/**
|
|
7
6
|
* Internal dependencies
|
|
8
7
|
*/
|
|
@@ -10,8 +9,7 @@ import { controls as dataControls } from '@wordpress/data-controls';
|
|
|
10
9
|
import reducer from './reducer';
|
|
11
10
|
import * as selectors from './selectors';
|
|
12
11
|
import * as actions from './actions';
|
|
13
|
-
import resolvers from './resolvers';
|
|
14
|
-
import controls from './controls';
|
|
12
|
+
import * as resolvers from './resolvers';
|
|
15
13
|
/**
|
|
16
14
|
* Module Constants
|
|
17
15
|
*/
|
|
@@ -29,10 +27,8 @@ export const storeConfig = {
|
|
|
29
27
|
reducer,
|
|
30
28
|
selectors,
|
|
31
29
|
actions,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
resolvers
|
|
30
|
+
resolvers,
|
|
31
|
+
__experimentalUseThunks: true
|
|
36
32
|
};
|
|
37
33
|
/**
|
|
38
34
|
* Store definition for the block directory namespace.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["createReduxStore","register","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","STORE_NAME","storeConfig","__experimentalUseThunks","store"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AAEA;AACA;AACA;;AACA,MAAMC,UAAU,GAAG,sBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAG;AAC1BL,EAAAA,OAD0B;AAE1BC,EAAAA,SAF0B;AAG1BC,EAAAA,OAH0B;AAI1BC,EAAAA,SAJ0B;AAK1BG,EAAAA,uBAAuB,EAAE;AALC,CAApB;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGT,gBAAgB,CAAEM,UAAF,EAAcC,WAAd,CAA9B;AAEPN,QAAQ,CAAEQ,KAAF,CAAR","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"]}
|
|
@@ -43,44 +43,30 @@ export const loadAsset = el => {
|
|
|
43
43
|
};
|
|
44
44
|
/**
|
|
45
45
|
* Load the asset files for a block
|
|
46
|
-
*
|
|
47
|
-
* @param {Array} assets A collection of URLs for the assets.
|
|
48
|
-
*
|
|
49
|
-
* @return {Object} Control descriptor.
|
|
50
46
|
*/
|
|
51
47
|
|
|
52
|
-
export function loadAssets(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const data = await response.text();
|
|
72
|
-
const doc = new window.DOMParser().parseFromString(data, 'text/html');
|
|
73
|
-
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
74
|
-
/*
|
|
75
|
-
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
76
|
-
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
77
|
-
*/
|
|
48
|
+
export async function loadAssets() {
|
|
49
|
+
/*
|
|
50
|
+
* Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
|
|
51
|
+
* JavaScript and CSS assets loaded between the pages. This imports the required assets
|
|
52
|
+
* for the block into the current page while not requiring that we know them up-front.
|
|
53
|
+
* In the future this can be improved by reliance upon block.json and/or a script-loader
|
|
54
|
+
* dependency API.
|
|
55
|
+
*/
|
|
56
|
+
const response = await apiFetch({
|
|
57
|
+
url: document.location.href,
|
|
58
|
+
parse: false
|
|
59
|
+
});
|
|
60
|
+
const data = await response.text();
|
|
61
|
+
const doc = new window.DOMParser().parseFromString(data, 'text/html');
|
|
62
|
+
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
63
|
+
/*
|
|
64
|
+
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
65
|
+
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
66
|
+
*/
|
|
78
67
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
68
|
+
for (const newAsset of newAssets) {
|
|
69
|
+
await loadAsset(newAsset);
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export default controls;
|
|
86
|
-
//# sourceMappingURL=controls.js.map
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=load-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/load-assets.js"],"names":["apiFetch","loadAsset","el","Promise","resolve","reject","newNode","document","createElement","nodeName","forEach","attr","innerHTML","appendChild","createTextNode","onload","onerror","Error","body","toLowerCase","src","loadAssets","response","url","location","href","parse","data","text","doc","window","DOMParser","parseFromString","newAssets","Array","from","querySelectorAll","filter","asset","id","getElementById","newAsset"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,SAAS,GAAKC,EAAF,IAAU;AAClC,SAAO,IAAIC,OAAJ,CAAa,CAAEC,OAAF,EAAWC,MAAX,KAAuB;AAC1C;AACF;AACA;AACA;AACE,UAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAwBN,EAAE,CAACO,QAA3B,CAAhB;AAEA,KAAE,IAAF,EAAQ,KAAR,EAAe,KAAf,EAAsB,MAAtB,EAA8B,MAA9B,EAAuCC,OAAvC,CAAkDC,IAAF,IAAY;AAC3D,UAAKT,EAAE,CAAES,IAAF,CAAP,EAAkB;AACjBL,QAAAA,OAAO,CAAEK,IAAF,CAAP,GAAkBT,EAAE,CAAES,IAAF,CAApB;AACA;AACD,KAJD,EAP0C,CAa1C;;AACA,QAAKT,EAAE,CAACU,SAAR,EAAoB;AACnBN,MAAAA,OAAO,CAACO,WAAR,CAAqBN,QAAQ,CAACO,cAAT,CAAyBZ,EAAE,CAACU,SAA5B,CAArB;AACA;;AAEDN,IAAAA,OAAO,CAACS,MAAR,GAAiB,MAAMX,OAAO,CAAE,IAAF,CAA9B;;AACAE,IAAAA,OAAO,CAACU,OAAR,GAAkB,MAAMX,MAAM,CAAE,IAAIY,KAAJ,CAAW,sBAAX,CAAF,CAA9B;;AAEAV,IAAAA,QAAQ,CAACW,IAAT,CAAcL,WAAd,CAA2BP,OAA3B,EArB0C,CAuB1C;;AACA,QACC,WAAWA,OAAO,CAACG,QAAR,CAAiBU,WAAjB,EAAX,IACE,aAAab,OAAO,CAACG,QAAR,CAAiBU,WAAjB,EAAb,IAA+C,CAAEb,OAAO,CAACc,GAF5D,EAGE;AACDhB,MAAAA,OAAO;AACP;AACD,GA9BM,CAAP;AA+BA,CAhCM;AAkCP;AACA;AACA;;AACA,OAAO,eAAeiB,UAAf,GAA4B;AAClC;AACD;AACA;AACA;AACA;AACA;AACA;AACC,QAAMC,QAAQ,GAAG,MAAMtB,QAAQ,CAAE;AAChCuB,IAAAA,GAAG,EAAEhB,QAAQ,CAACiB,QAAT,CAAkBC,IADS;AAEhCC,IAAAA,KAAK,EAAE;AAFyB,GAAF,CAA/B;AAKA,QAAMC,IAAI,GAAG,MAAML,QAAQ,CAACM,IAAT,EAAnB;AAEA,QAAMC,GAAG,GAAG,IAAIC,MAAM,CAACC,SAAX,GAAuBC,eAAvB,CAAwCL,IAAxC,EAA8C,WAA9C,CAAZ;AAEA,QAAMM,SAAS,GAAGC,KAAK,CAACC,IAAN,CACjBN,GAAG,CAACO,gBAAJ,CAAsB,+BAAtB,CADiB,EAEhBC,MAFgB,CAENC,KAAF,IAAaA,KAAK,CAACC,EAAN,IAAY,CAAEhC,QAAQ,CAACiC,cAAT,CAAyBF,KAAK,CAACC,EAA/B,CAFnB,CAAlB;AAIA;AACD;AACA;AACA;;AACC,OAAM,MAAME,QAAZ,IAAwBR,SAAxB,EAAoC;AACnC,UAAMhC,SAAS,CAAEwC,QAAF,CAAf;AACA;AACD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport 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\t}\n}\n"]}
|
|
@@ -6,29 +6,26 @@ import { camelCase, mapKeys } from 'lodash';
|
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
10
10
|
/**
|
|
11
11
|
* Internal dependencies
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
yield fetchDownloadableBlocks(filterValue);
|
|
23
|
-
const results = yield apiFetch({
|
|
24
|
-
path: `wp/v2/block-directory/search?term=${filterValue}`
|
|
25
|
-
});
|
|
26
|
-
const blocks = results.map(result => mapKeys(result, (value, key) => {
|
|
27
|
-
return camelCase(key);
|
|
28
|
-
}));
|
|
29
|
-
yield receiveDownloadableBlocks(blocks, filterValue);
|
|
30
|
-
} catch (error) {}
|
|
15
|
+
export const getDownloadableBlocks = filterValue => async ({
|
|
16
|
+
dispatch
|
|
17
|
+
}) => {
|
|
18
|
+
if (!filterValue) {
|
|
19
|
+
return;
|
|
31
20
|
}
|
|
32
21
|
|
|
22
|
+
try {
|
|
23
|
+
dispatch(fetchDownloadableBlocks(filterValue));
|
|
24
|
+
const results = await apiFetch({
|
|
25
|
+
path: `wp/v2/block-directory/search?term=${filterValue}`
|
|
26
|
+
});
|
|
27
|
+
const blocks = results.map(result => mapKeys(result, (value, key) => camelCase(key)));
|
|
28
|
+
dispatch(receiveDownloadableBlocks(blocks, filterValue));
|
|
29
|
+
} catch {}
|
|
33
30
|
};
|
|
34
31
|
//# sourceMappingURL=resolvers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["camelCase","mapKeys","apiFetch","fetchDownloadableBlocks","receiveDownloadableBlocks","getDownloadableBlocks","filterValue","results","path","blocks","map","result","value","key"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["camelCase","mapKeys","apiFetch","fetchDownloadableBlocks","receiveDownloadableBlocks","getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","value","key"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,OAApB,QAAmC,QAAnC;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,uBAAT,EAAkCC,yBAAlC,QAAmE,WAAnE;AAEA,OAAO,MAAMC,qBAAqB,GAAKC,WAAF,IAAmB,OAAQ;AAC/DC,EAAAA;AAD+D,CAAR,KAEjD;AACN,MAAK,CAAED,WAAP,EAAqB;AACpB;AACA;;AAED,MAAI;AACHC,IAAAA,QAAQ,CAAEJ,uBAAuB,CAAEG,WAAF,CAAzB,CAAR;AACA,UAAME,OAAO,GAAG,MAAMN,QAAQ,CAAE;AAC/BO,MAAAA,IAAI,EAAG,qCAAqCH,WAAa;AAD1B,KAAF,CAA9B;AAGA,UAAMI,MAAM,GAAGF,OAAO,CAACG,GAAR,CAAeC,MAAF,IAC3BX,OAAO,CAAEW,MAAF,EAAU,CAAEC,KAAF,EAASC,GAAT,KAAkBd,SAAS,CAAEc,GAAF,CAArC,CADO,CAAf;AAIAP,IAAAA,QAAQ,CAAEH,yBAAyB,CAAEM,MAAF,EAAUJ,WAAV,CAA3B,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"]}
|
|
@@ -18,11 +18,9 @@ import hasBlockType from './utils/has-block-type';
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
export function isRequestingDownloadableBlocks(state, filterValue) {
|
|
21
|
-
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
21
|
+
var _state$downloadableBl, _state$downloadableBl2;
|
|
24
22
|
|
|
25
|
-
return state.downloadableBlocks[filterValue].isRequesting;
|
|
23
|
+
return (_state$downloadableBl = (_state$downloadableBl2 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl2 === void 0 ? void 0 : _state$downloadableBl2.isRequesting) !== null && _state$downloadableBl !== void 0 ? _state$downloadableBl : false;
|
|
26
24
|
}
|
|
27
25
|
/**
|
|
28
26
|
* Returns the available uninstalled blocks.
|
|
@@ -34,11 +32,9 @@ export function isRequestingDownloadableBlocks(state, filterValue) {
|
|
|
34
32
|
*/
|
|
35
33
|
|
|
36
34
|
export function getDownloadableBlocks(state, filterValue) {
|
|
37
|
-
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
35
|
+
var _state$downloadableBl3, _state$downloadableBl4;
|
|
40
36
|
|
|
41
|
-
return state.downloadableBlocks[filterValue].results;
|
|
37
|
+
return (_state$downloadableBl3 = (_state$downloadableBl4 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl4 === void 0 ? void 0 : _state$downloadableBl4.results) !== null && _state$downloadableBl3 !== void 0 ? _state$downloadableBl3 : [];
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
44
40
|
* Returns the block types that have been installed on the server in this
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["createRegistrySelector","store","blockEditorStore","hasBlockType","isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAT,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AACpE,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["createRegistrySelector","store","blockEditorStore","hasBlockType","isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,sBAAT,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AAAA;;AACpE,4DAAOD,KAAK,CAACE,kBAAN,CAA0BD,WAA1B,CAAP,2DAAO,uBAAyCE,YAAhD,yEAAgE,KAAhE;AACA;AAED;AACA;AACA;AACA;AACA;AACA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AoCC,OAApC,KAAiD,KAAxD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BlB,KAA1B,EAAkC;AACxC,SAAOA,KAAK,CAACmB,YAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,sBAAT,CAAiCpB,KAAjC,EAAwCiB,OAAxC,EAAkD;AACxD,SAAOjB,KAAK,CAACmB,YAAN,CAAoBF,OAApB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport hasBlockType from './utils/has-block-type';\n\n/**\n * Returns true if application is requesting for downloadable blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {boolean} Whether a request is in progress for the blocks list.\n */\nexport function isRequestingDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.isRequesting ?? false;\n}\n\n/**\n * Returns the available uninstalled blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {Array} Downloadable blocks.\n */\nexport function getDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.results ?? [];\n}\n\n/**\n * Returns the block types that have been installed on the server in this\n * session.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items\n */\nexport function getInstalledBlockTypes( state ) {\n\treturn state.blockManagement.installedBlockTypes;\n}\n\n/**\n * Returns block types that have been installed on the server and used in the\n * current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getNewBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter( ( blockType ) =>\n\t\t\thasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns the block types that have been installed on the server but are not\n * used in the current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getUnusedBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter(\n\t\t\t( blockType ) => ! hasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns true if a block plugin install is in progress.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId Id of the block.\n *\n * @return {boolean} Whether this block is currently being installed.\n */\nexport function isInstalling( state, blockId ) {\n\treturn state.blockManagement.isInstalling[ blockId ] || false;\n}\n\n/**\n * Returns all block error notices.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Object with error notices.\n */\nexport function getErrorNotices( state ) {\n\treturn state.errorNotices;\n}\n\n/**\n * Returns the error notice for a given block.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {string|boolean} The error text, or false if no error.\n */\nexport function getErrorNoticeForBlock( state, blockId ) {\n\treturn state.errorNotices[ blockId ];\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-directory",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Extend editor with block directory features to search, download and install blocks.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -26,29 +26,28 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@babel/runtime": "^7.13.10",
|
|
29
|
-
"@wordpress/a11y": "^3.2.
|
|
30
|
-
"@wordpress/api-fetch": "^5.2.
|
|
31
|
-
"@wordpress/block-editor": "^
|
|
32
|
-
"@wordpress/blocks": "^11.
|
|
33
|
-
"@wordpress/components": "^
|
|
34
|
-
"@wordpress/compose": "^5.0.
|
|
35
|
-
"@wordpress/core-data": "^4.0.
|
|
36
|
-
"@wordpress/data": "^6.
|
|
37
|
-
"@wordpress/
|
|
38
|
-
"@wordpress/
|
|
39
|
-
"@wordpress/
|
|
40
|
-
"@wordpress/
|
|
41
|
-
"@wordpress/
|
|
42
|
-
"@wordpress/
|
|
43
|
-
"@wordpress/
|
|
44
|
-
"@wordpress/
|
|
45
|
-
"@wordpress/
|
|
46
|
-
"@wordpress/
|
|
47
|
-
"@wordpress/url": "^3.2.1",
|
|
29
|
+
"@wordpress/a11y": "^3.2.3",
|
|
30
|
+
"@wordpress/api-fetch": "^5.2.5",
|
|
31
|
+
"@wordpress/block-editor": "^8.0.0",
|
|
32
|
+
"@wordpress/blocks": "^11.1.3",
|
|
33
|
+
"@wordpress/components": "^19.0.1",
|
|
34
|
+
"@wordpress/compose": "^5.0.5",
|
|
35
|
+
"@wordpress/core-data": "^4.0.5",
|
|
36
|
+
"@wordpress/data": "^6.1.3",
|
|
37
|
+
"@wordpress/edit-post": "^5.0.5",
|
|
38
|
+
"@wordpress/editor": "^12.0.2",
|
|
39
|
+
"@wordpress/element": "^4.0.3",
|
|
40
|
+
"@wordpress/hooks": "^3.2.1",
|
|
41
|
+
"@wordpress/html-entities": "^3.2.2",
|
|
42
|
+
"@wordpress/i18n": "^4.2.3",
|
|
43
|
+
"@wordpress/icons": "^6.1.0",
|
|
44
|
+
"@wordpress/notices": "^3.2.6",
|
|
45
|
+
"@wordpress/plugins": "^4.0.5",
|
|
46
|
+
"@wordpress/url": "^3.3.0",
|
|
48
47
|
"lodash": "^4.17.21"
|
|
49
48
|
},
|
|
50
49
|
"publishConfig": {
|
|
51
50
|
"access": "public"
|
|
52
51
|
},
|
|
53
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "393c2b5533837fd637e998d23f0124c081a10df0"
|
|
54
53
|
}
|
|
@@ -13,8 +13,9 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
|
13
13
|
import { store as blockDirectoryStore } from '../../store';
|
|
14
14
|
|
|
15
15
|
export default function InstallButton( { attributes, block, clientId } ) {
|
|
16
|
-
const isInstallingBlock = useSelect(
|
|
17
|
-
select( blockDirectoryStore ).isInstalling( block.id )
|
|
16
|
+
const isInstallingBlock = useSelect(
|
|
17
|
+
( select ) => select( blockDirectoryStore ).isInstalling( block.id ),
|
|
18
|
+
[ block.id ]
|
|
18
19
|
);
|
|
19
20
|
const { installBlockType } = useDispatch( blockDirectoryStore );
|
|
20
21
|
const { replaceBlock } = useDispatch( blockEditorStore );
|
|
@@ -28,7 +29,7 @@ export default function InstallButton( { attributes, block, clientId } ) {
|
|
|
28
29
|
const [ originalBlock ] = parse(
|
|
29
30
|
attributes.originalContent
|
|
30
31
|
);
|
|
31
|
-
if ( originalBlock ) {
|
|
32
|
+
if ( originalBlock && blockType ) {
|
|
32
33
|
replaceBlock(
|
|
33
34
|
clientId,
|
|
34
35
|
createBlock(
|