@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
package/build/store/actions.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -14,21 +13,13 @@ exports.removeInstalledBlockType = removeInstalledBlockType;
|
|
|
14
13
|
exports.setErrorNotice = setErrorNotice;
|
|
15
14
|
exports.setIsInstalling = setIsInstalling;
|
|
16
15
|
exports.uninstallBlockType = void 0;
|
|
17
|
-
|
|
18
16
|
var _blocks = require("@wordpress/blocks");
|
|
19
|
-
|
|
20
17
|
var _i18n = require("@wordpress/i18n");
|
|
21
|
-
|
|
22
18
|
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
23
|
-
|
|
24
19
|
var _notices = require("@wordpress/notices");
|
|
25
|
-
|
|
26
20
|
var _url = require("@wordpress/url");
|
|
27
|
-
|
|
28
21
|
var _loadAssets = require("./load-assets");
|
|
29
|
-
|
|
30
22
|
var _getPluginUrl = _interopRequireDefault(require("./utils/get-plugin-url"));
|
|
31
|
-
|
|
32
23
|
/**
|
|
33
24
|
* WordPress dependencies
|
|
34
25
|
*/
|
|
@@ -51,6 +42,7 @@ function fetchDownloadableBlocks(filterValue) {
|
|
|
51
42
|
filterValue
|
|
52
43
|
};
|
|
53
44
|
}
|
|
45
|
+
|
|
54
46
|
/**
|
|
55
47
|
* Returns an action object used in signalling that the downloadable blocks
|
|
56
48
|
* have been updated.
|
|
@@ -60,8 +52,6 @@ function fetchDownloadableBlocks(filterValue) {
|
|
|
60
52
|
*
|
|
61
53
|
* @return {Object} Action object.
|
|
62
54
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
55
|
function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
66
56
|
return {
|
|
67
57
|
type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
|
|
@@ -69,6 +59,7 @@ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
69
59
|
filterValue
|
|
70
60
|
};
|
|
71
61
|
}
|
|
62
|
+
|
|
72
63
|
/**
|
|
73
64
|
* Action triggered to install a block plugin.
|
|
74
65
|
*
|
|
@@ -76,8 +67,6 @@ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
76
67
|
*
|
|
77
68
|
* @return {boolean} Whether the block was successfully installed & loaded.
|
|
78
69
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
70
|
const installBlockType = block => async ({
|
|
82
71
|
registry,
|
|
83
72
|
dispatch
|
|
@@ -88,13 +77,12 @@ const installBlockType = block => async ({
|
|
|
88
77
|
} = block;
|
|
89
78
|
let success = false;
|
|
90
79
|
dispatch.clearErrorNotice(id);
|
|
91
|
-
|
|
92
80
|
try {
|
|
93
|
-
dispatch.setIsInstalling(id, true);
|
|
81
|
+
dispatch.setIsInstalling(id, true);
|
|
94
82
|
|
|
83
|
+
// If we have a wp:plugin link, the plugin is installed but inactive.
|
|
95
84
|
const url = (0, _getPluginUrl.default)(block);
|
|
96
85
|
let links = {};
|
|
97
|
-
|
|
98
86
|
if (url) {
|
|
99
87
|
await (0, _apiFetch.default)({
|
|
100
88
|
method: 'PUT',
|
|
@@ -111,79 +99,77 @@ const installBlockType = block => async ({
|
|
|
111
99
|
slug: id,
|
|
112
100
|
status: 'active'
|
|
113
101
|
}
|
|
114
|
-
});
|
|
115
|
-
|
|
102
|
+
});
|
|
103
|
+
// Add the `self` link for newly-installed blocks.
|
|
116
104
|
links = response._links;
|
|
117
105
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
links: {
|
|
106
|
+
dispatch.addInstalledBlockType({
|
|
107
|
+
...block,
|
|
108
|
+
links: {
|
|
109
|
+
...block.links,
|
|
121
110
|
...links
|
|
122
111
|
}
|
|
123
|
-
});
|
|
112
|
+
});
|
|
124
113
|
|
|
114
|
+
// Ensures that the block metadata is propagated to the editor when registered on the server.
|
|
125
115
|
const metadataFields = ['api_version', 'title', 'category', 'parent', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'supports', 'styles', 'example', 'variations'];
|
|
126
116
|
await (0, _apiFetch.default)({
|
|
127
117
|
path: (0, _url.addQueryArgs)(`/wp/v2/block-types/${name}`, {
|
|
128
118
|
_fields: metadataFields
|
|
129
119
|
})
|
|
130
|
-
})
|
|
120
|
+
})
|
|
121
|
+
// Ignore when the block is not registered on the server.
|
|
131
122
|
.catch(() => {}).then(response => {
|
|
132
123
|
if (!response) {
|
|
133
124
|
return;
|
|
134
125
|
}
|
|
135
|
-
|
|
136
126
|
(0, _blocks.unstable__bootstrapServerSideBlockDefinitions)({
|
|
137
127
|
[name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key)))
|
|
138
128
|
});
|
|
139
129
|
});
|
|
140
130
|
await (0, _loadAssets.loadAssets)();
|
|
141
131
|
const registeredBlocks = registry.select(_blocks.store).getBlockTypes();
|
|
142
|
-
|
|
143
132
|
if (!registeredBlocks.some(i => i.name === name)) {
|
|
144
133
|
throw new Error((0, _i18n.__)('Error registering block. Try reloading the page.'));
|
|
145
134
|
}
|
|
146
|
-
|
|
147
|
-
|
|
135
|
+
registry.dispatch(_notices.store).createInfoNotice((0, _i18n.sprintf)(
|
|
136
|
+
// translators: %s is the block title.
|
|
148
137
|
(0, _i18n.__)('Block %s installed and added.'), block.title), {
|
|
149
138
|
speak: true,
|
|
150
139
|
type: 'snackbar'
|
|
151
140
|
});
|
|
152
141
|
success = true;
|
|
153
142
|
} catch (error) {
|
|
154
|
-
let message = error.message || (0, _i18n.__)('An error occurred.');
|
|
143
|
+
let message = error.message || (0, _i18n.__)('An error occurred.');
|
|
155
144
|
|
|
156
|
-
|
|
145
|
+
// Errors we throw are fatal.
|
|
146
|
+
let isFatal = error instanceof Error;
|
|
157
147
|
|
|
148
|
+
// Specific API errors that are fatal.
|
|
158
149
|
const fatalAPIErrors = {
|
|
159
150
|
folder_exists: (0, _i18n.__)('This block is already installed. Try reloading the page.'),
|
|
160
151
|
unable_to_connect_to_filesystem: (0, _i18n.__)('Error installing block. You can reload the page and try again.')
|
|
161
152
|
};
|
|
162
|
-
|
|
163
153
|
if (fatalAPIErrors[error.code]) {
|
|
164
154
|
isFatal = true;
|
|
165
155
|
message = fatalAPIErrors[error.code];
|
|
166
156
|
}
|
|
167
|
-
|
|
168
157
|
dispatch.setErrorNotice(id, message, isFatal);
|
|
169
158
|
registry.dispatch(_notices.store).createErrorNotice(message, {
|
|
170
159
|
speak: true,
|
|
171
160
|
isDismissible: true
|
|
172
161
|
});
|
|
173
162
|
}
|
|
174
|
-
|
|
175
163
|
dispatch.setIsInstalling(id, false);
|
|
176
164
|
return success;
|
|
177
165
|
};
|
|
166
|
+
|
|
178
167
|
/**
|
|
179
168
|
* Action triggered to uninstall a block plugin.
|
|
180
169
|
*
|
|
181
170
|
* @param {Object} block The blockType object.
|
|
182
171
|
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
172
|
exports.installBlockType = installBlockType;
|
|
186
|
-
|
|
187
173
|
const uninstallBlockType = block => async ({
|
|
188
174
|
registry,
|
|
189
175
|
dispatch
|
|
@@ -206,6 +192,7 @@ const uninstallBlockType = block => async ({
|
|
|
206
192
|
registry.dispatch(_notices.store).createErrorNotice(error.message || (0, _i18n.__)('An error occurred.'));
|
|
207
193
|
}
|
|
208
194
|
};
|
|
195
|
+
|
|
209
196
|
/**
|
|
210
197
|
* Returns an action object used to add a block type to the "newly installed"
|
|
211
198
|
* tracking list.
|
|
@@ -214,16 +201,14 @@ const uninstallBlockType = block => async ({
|
|
|
214
201
|
*
|
|
215
202
|
* @return {Object} Action object.
|
|
216
203
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
204
|
exports.uninstallBlockType = uninstallBlockType;
|
|
220
|
-
|
|
221
205
|
function addInstalledBlockType(item) {
|
|
222
206
|
return {
|
|
223
207
|
type: 'ADD_INSTALLED_BLOCK_TYPE',
|
|
224
208
|
item
|
|
225
209
|
};
|
|
226
210
|
}
|
|
211
|
+
|
|
227
212
|
/**
|
|
228
213
|
* Returns an action object used to remove a block type from the "newly installed"
|
|
229
214
|
* tracking list.
|
|
@@ -232,14 +217,13 @@ function addInstalledBlockType(item) {
|
|
|
232
217
|
*
|
|
233
218
|
* @return {Object} Action object.
|
|
234
219
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
220
|
function removeInstalledBlockType(item) {
|
|
238
221
|
return {
|
|
239
222
|
type: 'REMOVE_INSTALLED_BLOCK_TYPE',
|
|
240
223
|
item
|
|
241
224
|
};
|
|
242
225
|
}
|
|
226
|
+
|
|
243
227
|
/**
|
|
244
228
|
* Returns an action object used to indicate install in progress.
|
|
245
229
|
*
|
|
@@ -248,8 +232,6 @@ function removeInstalledBlockType(item) {
|
|
|
248
232
|
*
|
|
249
233
|
* @return {Object} Action object.
|
|
250
234
|
*/
|
|
251
|
-
|
|
252
|
-
|
|
253
235
|
function setIsInstalling(blockId, isInstalling) {
|
|
254
236
|
return {
|
|
255
237
|
type: 'SET_INSTALLING_BLOCK',
|
|
@@ -257,6 +239,7 @@ function setIsInstalling(blockId, isInstalling) {
|
|
|
257
239
|
isInstalling
|
|
258
240
|
};
|
|
259
241
|
}
|
|
242
|
+
|
|
260
243
|
/**
|
|
261
244
|
* Sets an error notice to be displayed to the user for a given block.
|
|
262
245
|
*
|
|
@@ -266,8 +249,6 @@ function setIsInstalling(blockId, isInstalling) {
|
|
|
266
249
|
*
|
|
267
250
|
* @return {Object} Action object.
|
|
268
251
|
*/
|
|
269
|
-
|
|
270
|
-
|
|
271
252
|
function setErrorNotice(blockId, message, isFatal = false) {
|
|
272
253
|
return {
|
|
273
254
|
type: 'SET_ERROR_NOTICE',
|
|
@@ -276,6 +257,7 @@ function setErrorNotice(blockId, message, isFatal = false) {
|
|
|
276
257
|
isFatal
|
|
277
258
|
};
|
|
278
259
|
}
|
|
260
|
+
|
|
279
261
|
/**
|
|
280
262
|
* Sets the error notice to empty for specific block.
|
|
281
263
|
*
|
|
@@ -283,8 +265,6 @@ function setErrorNotice(blockId, message, isFatal = false) {
|
|
|
283
265
|
*
|
|
284
266
|
* @return {Object} Action object.
|
|
285
267
|
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
268
|
function clearErrorNotice(blockId) {
|
|
289
269
|
return {
|
|
290
270
|
type: 'CLEAR_ERROR_NOTICE',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAhBA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMI,gBAAgB,GAC1BC,KAAF,IACA,OAAQ;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAR,KAAoC;AACnC,QAAM;AAAEC,IAAAA,EAAF;AAAMC,IAAAA;AAAN,MAAeJ,KAArB;AACA,MAAIK,OAAO,GAAG,KAAd;AACAH,EAAAA,QAAQ,CAACI,gBAAT,CAA2BH,EAA3B;;AACA,MAAI;AACHD,IAAAA,QAAQ,CAACK,eAAT,CAA0BJ,EAA1B,EAA8B,IAA9B,EADG,CAGH;;AACA,UAAMK,GAAG,GAAG,2BAAcR,KAAd,CAAZ;AACA,QAAIS,KAAK,GAAG,EAAZ;;AACA,QAAKD,GAAL,EA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;AACA;;;AACO,SAAS5C,eAAT,CAA0B6C,OAA1B,EAAmCC,YAAnC,EAAkD;AACxD,SAAO;AACNzD,IAAAA,IAAI,EAAE,sBADA;AAENwD,IAAAA,OAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASP,cAAT,CAAyBM,OAAzB,EAAkCZ,OAAlC,EAA2CC,OAAO,GAAG,KAArD,EAA6D;AACnE,SAAO;AACN7C,IAAAA,IAAI,EAAE,kBADA;AAENwD,IAAAA,OAFM;AAGNZ,IAAAA,OAHM;AAINC,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASnC,gBAAT,CAA2B8C,OAA3B,EAAqC;AAC3C,SAAO;AACNxD,IAAAA,IAAI,EAAE,oBADA;AAENwD,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":["_blocks","require","_i18n","_apiFetch","_interopRequireDefault","_notices","_url","_loadAssets","_getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","getPluginUrl","links","apiFetch","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","addQueryArgs","_fields","catch","then","unstable__bootstrapServerSideBlockDefinitions","Object","fromEntries","entries","filter","key","includes","loadAssets","registeredBlocks","select","blocksStore","getBlockTypes","some","i","Error","__","noticesStore","createInfoNotice","sprintf","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","exports","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":";;;;;;;;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAC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C;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS1C,gBAAgBA,CAAEsD,OAAO,EAAG;EAC3C,OAAO;IACNhE,IAAI,EAAE,oBAAoB;IAC1BgE;EACD,CAAC;AACF"}
|
package/build/store/index.js
CHANGED
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.storeConfig = exports.store = void 0;
|
|
9
|
-
|
|
10
8
|
var _data = require("@wordpress/data");
|
|
11
|
-
|
|
12
9
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
13
|
-
|
|
14
10
|
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
15
|
-
|
|
16
11
|
var actions = _interopRequireWildcard(require("./actions"));
|
|
17
|
-
|
|
18
12
|
var resolvers = _interopRequireWildcard(require("./resolvers"));
|
|
19
|
-
|
|
20
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
15
|
/**
|
|
25
16
|
* WordPress dependencies
|
|
26
17
|
*/
|
|
@@ -33,6 +24,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
33
24
|
* Module Constants
|
|
34
25
|
*/
|
|
35
26
|
const STORE_NAME = 'core/block-directory';
|
|
27
|
+
|
|
36
28
|
/**
|
|
37
29
|
* Block editor data store configuration.
|
|
38
30
|
*
|
|
@@ -40,13 +32,13 @@ const STORE_NAME = 'core/block-directory';
|
|
|
40
32
|
*
|
|
41
33
|
* @type {Object}
|
|
42
34
|
*/
|
|
43
|
-
|
|
44
35
|
const storeConfig = {
|
|
45
36
|
reducer: _reducer.default,
|
|
46
37
|
selectors,
|
|
47
38
|
actions,
|
|
48
39
|
resolvers
|
|
49
40
|
};
|
|
41
|
+
|
|
50
42
|
/**
|
|
51
43
|
* Store definition for the block directory namespace.
|
|
52
44
|
*
|
|
@@ -54,7 +46,6 @@ const storeConfig = {
|
|
|
54
46
|
*
|
|
55
47
|
* @type {Object}
|
|
56
48
|
*/
|
|
57
|
-
|
|
58
49
|
exports.storeConfig = storeConfig;
|
|
59
50
|
const store = (0, _data.createReduxStore)(STORE_NAME, storeConfig);
|
|
60
51
|
exports.store = store;
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","_reducer","_interopRequireDefault","selectors","_interopRequireWildcard","actions","resolvers","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","STORE_NAME","storeConfig","reducer","exports","store","createReduxStore","register"],"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":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAD,uBAAA,CAAAJ,OAAA;AACA,IAAAM,SAAA,GAAAF,uBAAA,CAAAJ,OAAA;AAAyC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAXzC;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA,MAAMW,UAAU,GAAG,sBAAsB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,GAAG;EAC1BC,OAAO,EAAPA,gBAAO;EACP5B,SAAS;EACTE,OAAO;EACPC;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANA0B,OAAA,CAAAF,WAAA,GAAAA,WAAA;AAOO,MAAMG,KAAK,GAAG,IAAAC,sBAAgB,EAAEL,UAAU,EAAEC,WAAY,CAAC;AAACE,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAEjE,IAAAE,cAAQ,EAAEF,KAAM,CAAC"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.loadAsset = void 0;
|
|
9
8
|
exports.loadAssets = loadAssets;
|
|
10
|
-
|
|
11
9
|
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* WordPress dependencies
|
|
15
12
|
*/
|
|
@@ -35,30 +32,27 @@ const loadAsset = el => {
|
|
|
35
32
|
if (el[attr]) {
|
|
36
33
|
newNode[attr] = el[attr];
|
|
37
34
|
}
|
|
38
|
-
});
|
|
35
|
+
});
|
|
39
36
|
|
|
37
|
+
// Append inline <script> contents.
|
|
40
38
|
if (el.innerHTML) {
|
|
41
39
|
newNode.appendChild(document.createTextNode(el.innerHTML));
|
|
42
40
|
}
|
|
43
|
-
|
|
44
41
|
newNode.onload = () => resolve(true);
|
|
45
|
-
|
|
46
42
|
newNode.onerror = () => reject(new Error('Error loading asset.'));
|
|
43
|
+
document.body.appendChild(newNode);
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// Resolve Stylesheets and Inline JavaScript immediately.
|
|
50
46
|
if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
|
|
51
47
|
resolve();
|
|
52
48
|
}
|
|
53
49
|
});
|
|
54
50
|
};
|
|
51
|
+
|
|
55
52
|
/**
|
|
56
53
|
* Load the asset files for a block
|
|
57
54
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
55
|
exports.loadAsset = loadAsset;
|
|
61
|
-
|
|
62
56
|
async function loadAssets() {
|
|
63
57
|
/*
|
|
64
58
|
* Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
|
|
@@ -74,11 +68,11 @@ async function loadAssets() {
|
|
|
74
68
|
const data = await response.text();
|
|
75
69
|
const doc = new window.DOMParser().parseFromString(data, 'text/html');
|
|
76
70
|
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
71
|
+
|
|
77
72
|
/*
|
|
78
73
|
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
79
74
|
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
80
75
|
*/
|
|
81
|
-
|
|
82
76
|
for (const newAsset of newAssets) {
|
|
83
77
|
await loadAsset(newAsset);
|
|
84
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_apiFetch","_interopRequireDefault","require","loadAsset","el","Promise","resolve","reject","newNode","document","createElement","nodeName","forEach","attr","innerHTML","appendChild","createTextNode","onload","onerror","Error","body","toLowerCase","src","exports","loadAssets","response","apiFetch","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":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,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,EAA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ACvD,CAAC,CAACC,MAAM,CAAIC,KAAK,IAAMA,KAAK,CAACC,EAAE,IAAI,CAAElC,QAAQ,CAACmC,cAAc,CAAEF,KAAK,CAACC,EAAG,CAAE,CAAC;;EAE1E;AACD;AACA;AACA;EACC,KAAM,MAAME,QAAQ,IAAIR,SAAS,EAAG;IACnC,MAAMlC,SAAS,CAAE0C,QAAS,CAAC;EAC5B;AACD"}
|
package/build/store/reducer.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.errorNotices = exports.downloadableBlocks = exports.default = exports.blockManagement = void 0;
|
|
7
|
-
|
|
8
7
|
var _data = require("@wordpress/data");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* WordPress dependencies
|
|
12
10
|
*/
|
|
@@ -22,23 +20,24 @@ var _data = require("@wordpress/data");
|
|
|
22
20
|
const downloadableBlocks = (state = {}, action) => {
|
|
23
21
|
switch (action.type) {
|
|
24
22
|
case 'FETCH_DOWNLOADABLE_BLOCKS':
|
|
25
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
...state,
|
|
26
25
|
[action.filterValue]: {
|
|
27
26
|
isRequesting: true
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
|
-
|
|
31
29
|
case 'RECEIVE_DOWNLOADABLE_BLOCKS':
|
|
32
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
33
32
|
[action.filterValue]: {
|
|
34
33
|
results: action.downloadableBlocks,
|
|
35
34
|
isRequesting: false
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
return state;
|
|
41
39
|
};
|
|
40
|
+
|
|
42
41
|
/**
|
|
43
42
|
* Reducer managing the installation and deletion of blocks.
|
|
44
43
|
*
|
|
@@ -47,35 +46,34 @@ const downloadableBlocks = (state = {}, action) => {
|
|
|
47
46
|
*
|
|
48
47
|
* @return {Object} Updated state.
|
|
49
48
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
49
|
exports.downloadableBlocks = downloadableBlocks;
|
|
53
|
-
|
|
54
50
|
const blockManagement = (state = {
|
|
55
51
|
installedBlockTypes: [],
|
|
56
52
|
isInstalling: {}
|
|
57
53
|
}, action) => {
|
|
58
54
|
switch (action.type) {
|
|
59
55
|
case 'ADD_INSTALLED_BLOCK_TYPE':
|
|
60
|
-
return {
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
61
58
|
installedBlockTypes: [...state.installedBlockTypes, action.item]
|
|
62
59
|
};
|
|
63
|
-
|
|
64
60
|
case 'REMOVE_INSTALLED_BLOCK_TYPE':
|
|
65
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
66
63
|
installedBlockTypes: state.installedBlockTypes.filter(blockType => blockType.name !== action.item.name)
|
|
67
64
|
};
|
|
68
|
-
|
|
69
65
|
case 'SET_INSTALLING_BLOCK':
|
|
70
|
-
return {
|
|
71
|
-
|
|
66
|
+
return {
|
|
67
|
+
...state,
|
|
68
|
+
isInstalling: {
|
|
69
|
+
...state.isInstalling,
|
|
72
70
|
[action.blockId]: action.isInstalling
|
|
73
71
|
}
|
|
74
72
|
};
|
|
75
73
|
}
|
|
76
|
-
|
|
77
74
|
return state;
|
|
78
75
|
};
|
|
76
|
+
|
|
79
77
|
/**
|
|
80
78
|
* Reducer returning an object of error notices.
|
|
81
79
|
*
|
|
@@ -84,20 +82,17 @@ const blockManagement = (state = {
|
|
|
84
82
|
*
|
|
85
83
|
* @return {Object} Updated state.
|
|
86
84
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
85
|
exports.blockManagement = blockManagement;
|
|
90
|
-
|
|
91
86
|
const errorNotices = (state = {}, action) => {
|
|
92
87
|
switch (action.type) {
|
|
93
88
|
case 'SET_ERROR_NOTICE':
|
|
94
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
...state,
|
|
95
91
|
[action.blockId]: {
|
|
96
92
|
message: action.message,
|
|
97
93
|
isFatal: action.isFatal
|
|
98
94
|
}
|
|
99
95
|
};
|
|
100
|
-
|
|
101
96
|
case 'CLEAR_ERROR_NOTICE':
|
|
102
97
|
const {
|
|
103
98
|
[action.blockId]: blockId,
|
|
@@ -105,17 +100,13 @@ const errorNotices = (state = {}, action) => {
|
|
|
105
100
|
} = state;
|
|
106
101
|
return restState;
|
|
107
102
|
}
|
|
108
|
-
|
|
109
103
|
return state;
|
|
110
104
|
};
|
|
111
|
-
|
|
112
105
|
exports.errorNotices = errorNotices;
|
|
113
|
-
|
|
114
106
|
var _default = (0, _data.combineReducers)({
|
|
115
107
|
downloadableBlocks,
|
|
116
108
|
blockManagement,
|
|
117
109
|
errorNotices
|
|
118
110
|
});
|
|
119
|
-
|
|
120
111
|
exports.default = _default;
|
|
121
112
|
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","downloadableBlocks","state","action","type","filterValue","isRequesting","results","exports","blockManagement","installedBlockTypes","isInstalling","item","filter","blockType","name","blockId","errorNotices","message","isFatal","restState","_default","combineReducers","default"],"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\t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