@wordpress/block-directory 4.16.0 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/auto-block-uninstaller/index.js +1 -6
- package/build/components/auto-block-uninstaller/index.js.map +1 -1
- package/build/components/block-ratings/index.js +1 -5
- package/build/components/block-ratings/index.js.map +1 -1
- package/build/components/block-ratings/stars.js +2 -7
- package/build/components/block-ratings/stars.js.map +1 -1
- package/build/components/compact-list/index.js +2 -8
- package/build/components/compact-list/index.js.map +1 -1
- package/build/components/downloadable-block-icon/index.js +1 -4
- package/build/components/downloadable-block-icon/index.js.map +1 -1
- package/build/components/downloadable-block-list-item/index.js +7 -28
- package/build/components/downloadable-block-list-item/index.js.map +1 -1
- package/build/components/downloadable-block-notice/index.js +1 -8
- package/build/components/downloadable-block-notice/index.js.map +1 -1
- package/build/components/downloadable-blocks-list/index.js +3 -15
- package/build/components/downloadable-blocks-list/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/index.js +1 -25
- package/build/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build/components/downloadable-blocks-panel/inserter-panel.js +2 -7
- package/build/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build/components/downloadable-blocks-panel/no-results.js +1 -6
- package/build/components/downloadable-blocks-panel/no-results.js.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/plugins/get-install-missing/index.js +13 -28
- package/build/plugins/get-install-missing/index.js.map +1 -1
- package/build/plugins/get-install-missing/install-button.js +2 -11
- package/build/plugins/get-install-missing/install-button.js.map +1 -1
- package/build/plugins/index.js +1 -10
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js +1 -9
- package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build/plugins/installed-blocks-pre-publish-panel/index.js +2 -13
- package/build/plugins/installed-blocks-pre-publish-panel/index.js.map +1 -1
- package/build/store/actions.js +26 -46
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -11
- package/build/store/index.js.map +1 -1
- package/build/store/load-assets.js +6 -12
- package/build/store/load-assets.js.map +1 -1
- package/build/store/reducer.js +16 -25
- package/build/store/reducer.js.map +1 -1
- package/build/store/resolvers.js +1 -7
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +7 -20
- package/build/store/selectors.js.map +1 -1
- package/build/store/utils/get-plugin-url.js +0 -4
- package/build/store/utils/get-plugin-url.js.map +1 -1
- package/build/store/utils/has-block-type.js +0 -4
- package/build/store/utils/has-block-type.js.map +1 -1
- package/build-module/components/auto-block-uninstaller/index.js +1 -1
- package/build-module/components/auto-block-uninstaller/index.js.map +1 -1
- package/build-module/components/block-ratings/index.js +0 -1
- package/build-module/components/block-ratings/index.js.map +1 -1
- package/build-module/components/block-ratings/stars.js +1 -5
- package/build-module/components/block-ratings/stars.js.map +1 -1
- package/build-module/components/compact-list/index.js +2 -5
- package/build-module/components/compact-list/index.js.map +1 -1
- package/build-module/components/downloadable-block-icon/index.js +0 -3
- package/build-module/components/downloadable-block-icon/index.js.map +1 -1
- package/build-module/components/downloadable-block-list-item/index.js +9 -19
- package/build-module/components/downloadable-block-list-item/index.js.map +1 -1
- package/build-module/components/downloadable-block-notice/index.js +1 -4
- package/build-module/components/downloadable-block-notice/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-list/index.js +3 -9
- package/build-module/components/downloadable-blocks-list/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/index.js +1 -13
- package/build-module/components/downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js +1 -5
- package/build-module/components/downloadable-blocks-panel/inserter-panel.js.map +1 -1
- package/build-module/components/downloadable-blocks-panel/no-results.js +0 -3
- package/build-module/components/downloadable-blocks-panel/no-results.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/get-install-missing/index.js +13 -20
- package/build-module/plugins/get-install-missing/index.js.map +1 -1
- package/build-module/plugins/get-install-missing/install-button.js +2 -5
- package/build-module/plugins/get-install-missing/install-button.js.map +1 -1
- package/build-module/plugins/index.js +1 -4
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js +1 -6
- package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +1 -1
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.js +6 -8
- package/build-module/plugins/installed-blocks-pre-publish-panel/index.js.map +1 -1
- package/build-module/store/actions.js +28 -30
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +4 -4
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/load-assets.js +7 -8
- package/build-module/store/load-assets.js.map +1 -1
- package/build-module/store/reducer.js +17 -17
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/resolvers.js +2 -3
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +9 -11
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/store/utils/get-plugin-url.js +0 -3
- package/build-module/store/utils/get-plugin-url.js.map +1 -1
- package/build-module/store/utils/has-block-type.js +0 -3
- package/build-module/store/utils/has-block-type.js.map +1 -1
- package/package.json +20 -20
- package/src/components/downloadable-block-list-item/test/index.js +1 -1
|
@@ -7,12 +7,13 @@ import { __, sprintf } from '@wordpress/i18n';
|
|
|
7
7
|
import apiFetch from '@wordpress/api-fetch';
|
|
8
8
|
import { store as noticesStore } from '@wordpress/notices';
|
|
9
9
|
import { addQueryArgs } from '@wordpress/url';
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Internal dependencies
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
import { loadAssets } from './load-assets';
|
|
15
15
|
import getPluginUrl from './utils/get-plugin-url';
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* Returns an action object used in signalling that the downloadable blocks
|
|
18
19
|
* have been requested and are loading.
|
|
@@ -21,13 +22,13 @@ import getPluginUrl from './utils/get-plugin-url';
|
|
|
21
22
|
*
|
|
22
23
|
* @return {Object} Action object.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
25
|
export function fetchDownloadableBlocks(filterValue) {
|
|
26
26
|
return {
|
|
27
27
|
type: 'FETCH_DOWNLOADABLE_BLOCKS',
|
|
28
28
|
filterValue
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
|
|
31
32
|
/**
|
|
32
33
|
* Returns an action object used in signalling that the downloadable blocks
|
|
33
34
|
* have been updated.
|
|
@@ -37,7 +38,6 @@ export function fetchDownloadableBlocks(filterValue) {
|
|
|
37
38
|
*
|
|
38
39
|
* @return {Object} Action object.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
41
|
export function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
42
42
|
return {
|
|
43
43
|
type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
|
|
@@ -45,6 +45,7 @@ export function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
45
45
|
filterValue
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
|
|
48
49
|
/**
|
|
49
50
|
* Action triggered to install a block plugin.
|
|
50
51
|
*
|
|
@@ -52,7 +53,6 @@ export function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
52
53
|
*
|
|
53
54
|
* @return {boolean} Whether the block was successfully installed & loaded.
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
56
|
export const installBlockType = block => async ({
|
|
57
57
|
registry,
|
|
58
58
|
dispatch
|
|
@@ -63,13 +63,12 @@ export const installBlockType = block => async ({
|
|
|
63
63
|
} = block;
|
|
64
64
|
let success = false;
|
|
65
65
|
dispatch.clearErrorNotice(id);
|
|
66
|
-
|
|
67
66
|
try {
|
|
68
|
-
dispatch.setIsInstalling(id, true);
|
|
67
|
+
dispatch.setIsInstalling(id, true);
|
|
69
68
|
|
|
69
|
+
// If we have a wp:plugin link, the plugin is installed but inactive.
|
|
70
70
|
const url = getPluginUrl(block);
|
|
71
71
|
let links = {};
|
|
72
|
-
|
|
73
72
|
if (url) {
|
|
74
73
|
await apiFetch({
|
|
75
74
|
method: 'PUT',
|
|
@@ -86,77 +85,76 @@ export const installBlockType = block => async ({
|
|
|
86
85
|
slug: id,
|
|
87
86
|
status: 'active'
|
|
88
87
|
}
|
|
89
|
-
});
|
|
90
|
-
|
|
88
|
+
});
|
|
89
|
+
// Add the `self` link for newly-installed blocks.
|
|
91
90
|
links = response._links;
|
|
92
91
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
links: {
|
|
92
|
+
dispatch.addInstalledBlockType({
|
|
93
|
+
...block,
|
|
94
|
+
links: {
|
|
95
|
+
...block.links,
|
|
96
96
|
...links
|
|
97
97
|
}
|
|
98
|
-
});
|
|
98
|
+
});
|
|
99
99
|
|
|
100
|
+
// Ensures that the block metadata is propagated to the editor when registered on the server.
|
|
100
101
|
const metadataFields = ['api_version', 'title', 'category', 'parent', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'supports', 'styles', 'example', 'variations'];
|
|
101
102
|
await apiFetch({
|
|
102
103
|
path: addQueryArgs(`/wp/v2/block-types/${name}`, {
|
|
103
104
|
_fields: metadataFields
|
|
104
105
|
})
|
|
105
|
-
})
|
|
106
|
+
})
|
|
107
|
+
// Ignore when the block is not registered on the server.
|
|
106
108
|
.catch(() => {}).then(response => {
|
|
107
109
|
if (!response) {
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
|
-
|
|
111
112
|
unstable__bootstrapServerSideBlockDefinitions({
|
|
112
113
|
[name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key)))
|
|
113
114
|
});
|
|
114
115
|
});
|
|
115
116
|
await loadAssets();
|
|
116
117
|
const registeredBlocks = registry.select(blocksStore).getBlockTypes();
|
|
117
|
-
|
|
118
118
|
if (!registeredBlocks.some(i => i.name === name)) {
|
|
119
119
|
throw new Error(__('Error registering block. Try reloading the page.'));
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
registry.dispatch(noticesStore).createInfoNotice(sprintf(
|
|
122
|
+
// translators: %s is the block title.
|
|
123
123
|
__('Block %s installed and added.'), block.title), {
|
|
124
124
|
speak: true,
|
|
125
125
|
type: 'snackbar'
|
|
126
126
|
});
|
|
127
127
|
success = true;
|
|
128
128
|
} catch (error) {
|
|
129
|
-
let message = error.message || __('An error occurred.');
|
|
129
|
+
let message = error.message || __('An error occurred.');
|
|
130
130
|
|
|
131
|
+
// Errors we throw are fatal.
|
|
132
|
+
let isFatal = error instanceof Error;
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
// Specific API errors that are fatal.
|
|
134
135
|
const fatalAPIErrors = {
|
|
135
136
|
folder_exists: __('This block is already installed. Try reloading the page.'),
|
|
136
137
|
unable_to_connect_to_filesystem: __('Error installing block. You can reload the page and try again.')
|
|
137
138
|
};
|
|
138
|
-
|
|
139
139
|
if (fatalAPIErrors[error.code]) {
|
|
140
140
|
isFatal = true;
|
|
141
141
|
message = fatalAPIErrors[error.code];
|
|
142
142
|
}
|
|
143
|
-
|
|
144
143
|
dispatch.setErrorNotice(id, message, isFatal);
|
|
145
144
|
registry.dispatch(noticesStore).createErrorNotice(message, {
|
|
146
145
|
speak: true,
|
|
147
146
|
isDismissible: true
|
|
148
147
|
});
|
|
149
148
|
}
|
|
150
|
-
|
|
151
149
|
dispatch.setIsInstalling(id, false);
|
|
152
150
|
return success;
|
|
153
151
|
};
|
|
152
|
+
|
|
154
153
|
/**
|
|
155
154
|
* Action triggered to uninstall a block plugin.
|
|
156
155
|
*
|
|
157
156
|
* @param {Object} block The blockType object.
|
|
158
157
|
*/
|
|
159
|
-
|
|
160
158
|
export const uninstallBlockType = block => async ({
|
|
161
159
|
registry,
|
|
162
160
|
dispatch
|
|
@@ -179,6 +177,7 @@ export const uninstallBlockType = block => async ({
|
|
|
179
177
|
registry.dispatch(noticesStore).createErrorNotice(error.message || __('An error occurred.'));
|
|
180
178
|
}
|
|
181
179
|
};
|
|
180
|
+
|
|
182
181
|
/**
|
|
183
182
|
* Returns an action object used to add a block type to the "newly installed"
|
|
184
183
|
* tracking list.
|
|
@@ -187,13 +186,13 @@ export const uninstallBlockType = block => async ({
|
|
|
187
186
|
*
|
|
188
187
|
* @return {Object} Action object.
|
|
189
188
|
*/
|
|
190
|
-
|
|
191
189
|
export function addInstalledBlockType(item) {
|
|
192
190
|
return {
|
|
193
191
|
type: 'ADD_INSTALLED_BLOCK_TYPE',
|
|
194
192
|
item
|
|
195
193
|
};
|
|
196
194
|
}
|
|
195
|
+
|
|
197
196
|
/**
|
|
198
197
|
* Returns an action object used to remove a block type from the "newly installed"
|
|
199
198
|
* tracking list.
|
|
@@ -202,13 +201,13 @@ export function addInstalledBlockType(item) {
|
|
|
202
201
|
*
|
|
203
202
|
* @return {Object} Action object.
|
|
204
203
|
*/
|
|
205
|
-
|
|
206
204
|
export function removeInstalledBlockType(item) {
|
|
207
205
|
return {
|
|
208
206
|
type: 'REMOVE_INSTALLED_BLOCK_TYPE',
|
|
209
207
|
item
|
|
210
208
|
};
|
|
211
209
|
}
|
|
210
|
+
|
|
212
211
|
/**
|
|
213
212
|
* Returns an action object used to indicate install in progress.
|
|
214
213
|
*
|
|
@@ -217,7 +216,6 @@ export function removeInstalledBlockType(item) {
|
|
|
217
216
|
*
|
|
218
217
|
* @return {Object} Action object.
|
|
219
218
|
*/
|
|
220
|
-
|
|
221
219
|
export function setIsInstalling(blockId, isInstalling) {
|
|
222
220
|
return {
|
|
223
221
|
type: 'SET_INSTALLING_BLOCK',
|
|
@@ -225,6 +223,7 @@ export function setIsInstalling(blockId, isInstalling) {
|
|
|
225
223
|
isInstalling
|
|
226
224
|
};
|
|
227
225
|
}
|
|
226
|
+
|
|
228
227
|
/**
|
|
229
228
|
* Sets an error notice to be displayed to the user for a given block.
|
|
230
229
|
*
|
|
@@ -234,7 +233,6 @@ export function setIsInstalling(blockId, isInstalling) {
|
|
|
234
233
|
*
|
|
235
234
|
* @return {Object} Action object.
|
|
236
235
|
*/
|
|
237
|
-
|
|
238
236
|
export function setErrorNotice(blockId, message, isFatal = false) {
|
|
239
237
|
return {
|
|
240
238
|
type: 'SET_ERROR_NOTICE',
|
|
@@ -243,6 +241,7 @@ export function setErrorNotice(blockId, message, isFatal = false) {
|
|
|
243
241
|
isFatal
|
|
244
242
|
};
|
|
245
243
|
}
|
|
244
|
+
|
|
246
245
|
/**
|
|
247
246
|
* Sets the error notice to empty for specific block.
|
|
248
247
|
*
|
|
@@ -250,7 +249,6 @@ export function setErrorNotice(blockId, message, isFatal = false) {
|
|
|
250
249
|
*
|
|
251
250
|
* @return {Object} Action object.
|
|
252
251
|
*/
|
|
253
|
-
|
|
254
252
|
export function clearErrorNotice(blockId) {
|
|
255
253
|
return {
|
|
256
254
|
type: 'CLEAR_ERROR_NOTICE',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,WADV,EAECC,6CAFD,CAEgD;AAFhD,OAGO,mBAHP;AAIA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,OAAOC,QA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AAS1C,eAAT,CAA0B2C,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNvD,IAAAA,IAAI,EAAE,sBADA;AAENsD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA2CC,OAAO,GAAG,KAArD,EAA6D;AACnE,SAAO;AACN3C,IAAAA,IAAI,EAAE,kBADA;AAENsD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASjC,gBAAT,CAA2B4C,OAA3B,EAAqC;AAC3C,SAAO;AACNtD,IAAAA,IAAI,EAAE,oBADA;AAENsD,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\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'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'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\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"]}
|
|
1
|
+
{"version":3,"names":["store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"sources":["@wordpress/block-directory/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\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'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'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\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":"AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,WAAW,EACpBC,6CAA6C,CAAE;AAAA,OACzC,mBAAmB;AAC1B,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;AAC1D,SAAS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|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import reducer from './reducer';
|
|
10
10
|
import * as selectors from './selectors';
|
|
11
11
|
import * as actions from './actions';
|
|
12
12
|
import * as resolvers from './resolvers';
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Module Constants
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
const STORE_NAME = 'core/block-directory';
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* Block editor data store configuration.
|
|
20
21
|
*
|
|
@@ -22,13 +23,13 @@ const STORE_NAME = 'core/block-directory';
|
|
|
22
23
|
*
|
|
23
24
|
* @type {Object}
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
26
|
export const storeConfig = {
|
|
27
27
|
reducer,
|
|
28
28
|
selectors,
|
|
29
29
|
actions,
|
|
30
30
|
resolvers
|
|
31
31
|
};
|
|
32
|
+
|
|
32
33
|
/**
|
|
33
34
|
* Store definition for the block directory namespace.
|
|
34
35
|
*
|
|
@@ -36,7 +37,6 @@ export const storeConfig = {
|
|
|
36
37
|
*
|
|
37
38
|
* @type {Object}
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
40
|
export const store = createReduxStore(STORE_NAME, storeConfig);
|
|
41
41
|
register(store);
|
|
42
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createReduxStore","register","reducer","selectors","actions","resolvers","STORE_NAME","storeConfig","store"],"sources":["@wordpress/block-directory/src/store/index.js"],"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};\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":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aAAa;;AAExC;AACA;AACA;AACA,MAAMC,UAAU,GAAG,sBAAsB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG;EAC1BL,OAAO;EACPC,SAAS;EACTC,OAAO;EACPC;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,KAAK,GAAGR,gBAAgB,CAAEM,UAAU,EAAEC,WAAY,CAAC;AAEhEN,QAAQ,CAAEO,KAAM,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Load an asset for a block.
|
|
7
8
|
*
|
|
@@ -12,7 +13,6 @@ import apiFetch from '@wordpress/api-fetch';
|
|
|
12
13
|
*
|
|
13
14
|
* @return {Promise} Promise which will resolve when the asset is loaded.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
export const loadAsset = el => {
|
|
17
17
|
return new Promise((resolve, reject) => {
|
|
18
18
|
/*
|
|
@@ -24,27 +24,26 @@ export const loadAsset = el => {
|
|
|
24
24
|
if (el[attr]) {
|
|
25
25
|
newNode[attr] = el[attr];
|
|
26
26
|
}
|
|
27
|
-
});
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
+
// Append inline <script> contents.
|
|
29
30
|
if (el.innerHTML) {
|
|
30
31
|
newNode.appendChild(document.createTextNode(el.innerHTML));
|
|
31
32
|
}
|
|
32
|
-
|
|
33
33
|
newNode.onload = () => resolve(true);
|
|
34
|
-
|
|
35
34
|
newNode.onerror = () => reject(new Error('Error loading asset.'));
|
|
35
|
+
document.body.appendChild(newNode);
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// Resolve Stylesheets and Inline JavaScript immediately.
|
|
39
38
|
if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
|
|
40
39
|
resolve();
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
};
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Load the asset files for a block
|
|
46
46
|
*/
|
|
47
|
-
|
|
48
47
|
export async function loadAssets() {
|
|
49
48
|
/*
|
|
50
49
|
* Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
|
|
@@ -60,11 +59,11 @@ export async function loadAssets() {
|
|
|
60
59
|
const data = await response.text();
|
|
61
60
|
const doc = new window.DOMParser().parseFromString(data, 'text/html');
|
|
62
61
|
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
62
|
+
|
|
63
63
|
/*
|
|
64
64
|
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
65
65
|
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
67
|
for (const newAsset of newAssets) {
|
|
69
68
|
await loadAsset(newAsset);
|
|
70
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"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"],"sources":["@wordpress/block-directory/src/store/load-assets.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAKC,EAAE,IAAM;EAClC,OAAO,IAAIC,OAAO,CAAE,CAAEC,OAAO,EAAEC,MAAM,KAAM;IAC1C;AACF;AACA;AACA;IACE,MAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAAEN,EAAE,CAACO,QAAS,CAAC;IAErD,CAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAE,CAACC,OAAO,CAAIC,IAAI,IAAM;MAC3D,IAAKT,EAAE,CAAES,IAAI,CAAE,EAAG;QACjBL,OAAO,CAAEK,IAAI,CAAE,GAAGT,EAAE,CAAES,IAAI,CAAE;MAC7B;IACD,CAAE,CAAC;;IAEH;IACA,IAAKT,EAAE,CAACU,SAAS,EAAG;MACnBN,OAAO,CAACO,WAAW,CAAEN,QAAQ,C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;EAC5B;AACD"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { combineReducers } from '@wordpress/data';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Reducer returning an array of downloadable blocks.
|
|
7
8
|
*
|
|
@@ -10,27 +11,27 @@ import { combineReducers } from '@wordpress/data';
|
|
|
10
11
|
*
|
|
11
12
|
* @return {Object} Updated state.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
export const downloadableBlocks = (state = {}, action) => {
|
|
15
15
|
switch (action.type) {
|
|
16
16
|
case 'FETCH_DOWNLOADABLE_BLOCKS':
|
|
17
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
...state,
|
|
18
19
|
[action.filterValue]: {
|
|
19
20
|
isRequesting: true
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
|
-
|
|
23
23
|
case 'RECEIVE_DOWNLOADABLE_BLOCKS':
|
|
24
|
-
return {
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
25
26
|
[action.filterValue]: {
|
|
26
27
|
results: action.downloadableBlocks,
|
|
27
28
|
isRequesting: false
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
|
-
|
|
32
32
|
return state;
|
|
33
33
|
};
|
|
34
|
+
|
|
34
35
|
/**
|
|
35
36
|
* Reducer managing the installation and deletion of blocks.
|
|
36
37
|
*
|
|
@@ -39,32 +40,33 @@ export const downloadableBlocks = (state = {}, action) => {
|
|
|
39
40
|
*
|
|
40
41
|
* @return {Object} Updated state.
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
43
|
export const blockManagement = (state = {
|
|
44
44
|
installedBlockTypes: [],
|
|
45
45
|
isInstalling: {}
|
|
46
46
|
}, action) => {
|
|
47
47
|
switch (action.type) {
|
|
48
48
|
case 'ADD_INSTALLED_BLOCK_TYPE':
|
|
49
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
50
51
|
installedBlockTypes: [...state.installedBlockTypes, action.item]
|
|
51
52
|
};
|
|
52
|
-
|
|
53
53
|
case 'REMOVE_INSTALLED_BLOCK_TYPE':
|
|
54
|
-
return {
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
55
56
|
installedBlockTypes: state.installedBlockTypes.filter(blockType => blockType.name !== action.item.name)
|
|
56
57
|
};
|
|
57
|
-
|
|
58
58
|
case 'SET_INSTALLING_BLOCK':
|
|
59
|
-
return {
|
|
60
|
-
|
|
59
|
+
return {
|
|
60
|
+
...state,
|
|
61
|
+
isInstalling: {
|
|
62
|
+
...state.isInstalling,
|
|
61
63
|
[action.blockId]: action.isInstalling
|
|
62
64
|
}
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
|
-
|
|
66
67
|
return state;
|
|
67
68
|
};
|
|
69
|
+
|
|
68
70
|
/**
|
|
69
71
|
* Reducer returning an object of error notices.
|
|
70
72
|
*
|
|
@@ -73,17 +75,16 @@ export const blockManagement = (state = {
|
|
|
73
75
|
*
|
|
74
76
|
* @return {Object} Updated state.
|
|
75
77
|
*/
|
|
76
|
-
|
|
77
78
|
export const errorNotices = (state = {}, action) => {
|
|
78
79
|
switch (action.type) {
|
|
79
80
|
case 'SET_ERROR_NOTICE':
|
|
80
|
-
return {
|
|
81
|
+
return {
|
|
82
|
+
...state,
|
|
81
83
|
[action.blockId]: {
|
|
82
84
|
message: action.message,
|
|
83
85
|
isFatal: action.isFatal
|
|
84
86
|
}
|
|
85
87
|
};
|
|
86
|
-
|
|
87
88
|
case 'CLEAR_ERROR_NOTICE':
|
|
88
89
|
const {
|
|
89
90
|
[action.blockId]: blockId,
|
|
@@ -91,7 +92,6 @@ export const errorNotices = (state = {}, action) => {
|
|
|
91
92
|
} = state;
|
|
92
93
|
return restState;
|
|
93
94
|
}
|
|
94
|
-
|
|
95
95
|
return state;
|
|
96
96
|
};
|
|
97
97
|
export default combineReducers({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["combineReducers","downloadableBlocks","state","action","type","filterValue","isRequesting","results","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal","restState"],"sources":["@wordpress/block-directory/src/store/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning an array of downloadable blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const downloadableBlocks = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'FETCH_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tisRequesting: true,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'RECEIVE_DOWNLOADABLE_BLOCKS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.filterValue ]: {\n\t\t\t\t\tresults: action.downloadableBlocks,\n\t\t\t\t\tisRequesting: false,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer managing the installation and deletion of blocks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const blockManagement = (\n\tstate = {\n\t\tinstalledBlockTypes: [],\n\t\tisInstalling: {},\n\t},\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: [\n\t\t\t\t\t...state.installedBlockTypes,\n\t\t\t\t\taction.item,\n\t\t\t\t],\n\t\t\t};\n\t\tcase 'REMOVE_INSTALLED_BLOCK_TYPE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tinstalledBlockTypes: state.installedBlockTypes.filter(\n\t\t\t\t\t( blockType ) => blockType.name !== action.item.name\n\t\t\t\t),\n\t\t\t};\n\t\tcase 'SET_INSTALLING_BLOCK':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tisInstalling: {\n\t\t\t\t\t...state.isInstalling,\n\t\t\t\t\t[ action.blockId ]: action.isInstalling,\n\t\t\t\t},\n\t\t\t};\n\t}\n\treturn state;\n};\n\n/**\n * Reducer returning an object of error notices.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const errorNotices = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'SET_ERROR_NOTICE':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.blockId ]: {\n\t\t\t\t\tmessage: action.message,\n\t\t\t\t\tisFatal: action.isFatal,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'CLEAR_ERROR_NOTICE':\n\t\t\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":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,iBAAiB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAAEC,KAAK,GAAG,CAAC,CAAC,EAAEC,MAAM,KAAM;EAC3D,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,2BAA2B;MAC/B,OAAO;QACN,GAAGF,KAAK;QACR,CAAEC,MAAM,CAACE,WAAW,GAAI;UACvBC,YAAY,EAAE;QACf;MACD,CAAC;IACF,KAAK,6BAA6B;MACjC,OAAO;QACN,GAAGJ,KAAK;QACR,CAAEC,MAAM,CAACE,WAAW,GAAI;UACvBE,OAAO,EAAEJ,MAAM,CAACF,kBAAkB;UAClCK,YAAY,EAAE;QACf;MACD,CAAC;EACH;EACA,OAAOJ,KAAK;AACb,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;A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EAC/BC,kBAAkB;EAClBO,eAAe;EACfQ;AACD,CAAE,CAAC"}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { camelCase } from 'change-case';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* WordPress dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import apiFetch from '@wordpress/api-fetch';
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Internal dependencies
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
import { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';
|
|
15
15
|
export const getDownloadableBlocks = filterValue => async ({
|
|
16
16
|
dispatch
|
|
@@ -18,7 +18,6 @@ export const getDownloadableBlocks = filterValue => async ({
|
|
|
18
18
|
if (!filterValue) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
try {
|
|
23
22
|
dispatch(fetchDownloadableBlocks(filterValue));
|
|
24
23
|
const results = await apiFetch({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["camelCase","apiFetch","fetchDownloadableBlocks","receiveDownloadableBlocks","getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","Object","fromEntries","entries","key","value"],"sources":["@wordpress/block-directory/src/store/resolvers.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\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 =\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};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,aAAa;;AAEvC;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA,SAASC,uBAAuB,EAAEC,yBAAyB,QAAQ,WAAW;AAE9E,OAAO,MAAMC,qBAAqB,GAC/BC,WAAW,IACb,OAAQ;EAAEC;AAAS,CAAC,KAAM;EACzB,IAAK,CAAED,WAAW,EAAG;IACpB;EACD;EAEA,IAAI;IACHC,QAAQ,CAAEJ,uBAAuB,CAAEG,WAAY,CAAE,CAAC;IAClD,MAAME,OAAO,GAAG,MAAMN,QAAQ,CAAE;MAC/BO,IAAI,EAAG,qCAAqCH,WAAa;IAC1D,CAAE,CAAC;IACH,MAAMI,MAAM,GAAGF,OAAO,CAACG,GAAG,CAAIC,MAAM,IACnCC,MAAM,CAACC,WAAW,CACjBD,MAAM,CAACE,OAAO,CAAEH,MAAO,CAAC,CAACD,GAAG,CAAE,CAAE,CAAEK,GAAG,EAAEC,KAAK,CAAE,KAAM,CACnDhB,SAAS,CAAEe,GAAI,CAAC,EAChBC,KAAK,CACJ,CACH,CACD,CAAC;IAEDV,QAAQ,CAAEH,yBAAyB,CAAEM,MAAM,EAAEJ,WAAY,CAAE,CAAC;EAC7D,CAAC,CAAC,MAAM,CAAC;AACV,CAAC"}
|