@wordpress/block-directory 3.0.1 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/plugins/get-install-missing/install-button.js +2 -2
- package/build/plugins/get-install-missing/install-button.js.map +1 -1
- package/build/store/actions.js +44 -37
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +3 -9
- package/build/store/index.js.map +1 -1
- package/build/store/{controls.js → load-assets.js} +25 -41
- package/build/store/load-assets.js.map +1 -0
- package/build/store/resolvers.js +19 -19
- package/build/store/resolvers.js.map +1 -1
- package/build/store/selectors.js +4 -8
- package/build/store/selectors.js.map +1 -1
- package/build-module/plugins/get-install-missing/install-button.js +2 -2
- package/build-module/plugins/get-install-missing/install-button.js.map +1 -1
- package/build-module/store/actions.js +39 -34
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +3 -7
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/{controls.js → load-assets.js} +23 -37
- package/build-module/store/load-assets.js.map +1 -0
- package/build-module/store/resolvers.js +14 -17
- package/build-module/store/resolvers.js.map +1 -1
- package/build-module/store/selectors.js +4 -8
- package/build-module/store/selectors.js.map +1 -1
- package/package.json +20 -21
- package/src/plugins/get-install-missing/install-button.js +4 -3
- package/src/store/actions.js +38 -46
- package/src/store/index.js +2 -4
- package/src/store/{controls.js → load-assets.js} +25 -42
- package/src/store/resolvers.js +17 -19
- package/src/store/selectors.js +2 -14
- package/src/store/test/actions.js +236 -267
- package/src/store/test/{controls.js → load-assets.js} +1 -1
- package/build/store/controls.js.map +0 -1
- package/build-module/store/controls.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Install the module
|
|
|
12
12
|
npm install @wordpress/block-directory --save
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for
|
|
15
|
+
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
18
18
|
|
|
@@ -31,7 +31,7 @@ function InstallButton({
|
|
|
31
31
|
block,
|
|
32
32
|
clientId
|
|
33
33
|
}) {
|
|
34
|
-
const isInstallingBlock = (0, _data.useSelect)(select => select(_store.store).isInstalling(block.id));
|
|
34
|
+
const isInstallingBlock = (0, _data.useSelect)(select => select(_store.store).isInstalling(block.id), [block.id]);
|
|
35
35
|
const {
|
|
36
36
|
installBlockType
|
|
37
37
|
} = (0, _data.useDispatch)(_store.store);
|
|
@@ -44,7 +44,7 @@ function InstallButton({
|
|
|
44
44
|
const blockType = (0, _blocks.getBlockType)(block.name);
|
|
45
45
|
const [originalBlock] = (0, _blocks.parse)(attributes.originalContent);
|
|
46
46
|
|
|
47
|
-
if (originalBlock) {
|
|
47
|
+
if (originalBlock && blockType) {
|
|
48
48
|
replaceBlock(clientId, (0, _blocks.createBlock)(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["InstallButton","attributes","block","clientId","isInstallingBlock","select","blockDirectoryStore","isInstalling","id","installBlockType","replaceBlock","blockEditorStore","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,aAAT,CAAwB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAxB,EAA0D;AACxE,QAAMC,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["InstallButton","attributes","block","clientId","isInstallingBlock","select","blockDirectoryStore","isInstalling","id","installBlockType","replaceBlock","blockEditorStore","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAZA;AACA;AACA;;AAOA;AACA;AACA;AAGe,SAASA,aAAT,CAAwB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAxB,EAA0D;AACxE,QAAMC,iBAAiB,GAAG,qBACvBC,MAAF,IAAcA,MAAM,CAAEC,YAAF,CAAN,CAA8BC,YAA9B,CAA4CL,KAAK,CAACM,EAAlD,CADW,EAEzB,CAAEN,KAAK,CAACM,EAAR,CAFyB,CAA1B;AAIA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uBAAaH,YAAb,CAA7B;AACA,QAAM;AAAEI,IAAAA;AAAF,MAAmB,uBAAaC,kBAAb,CAAzB;AAEA,SACC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAG,MACTF,gBAAgB,CAAEP,KAAF,CAAhB,CAA0BU,IAA1B,CAAkCC,OAAF,IAAe;AAC9C,UAAKA,OAAL,EAAe;AACd,cAAMC,SAAS,GAAG,0BAAcZ,KAAK,CAACa,IAApB,CAAlB;AACA,cAAM,CAAEC,aAAF,IAAoB,mBACzBf,UAAU,CAACgB,eADc,CAA1B;;AAGA,YAAKD,aAAa,IAAIF,SAAtB,EAAkC;AACjCJ,UAAAA,YAAY,CACXP,QADW,EAEX,yBACCW,SAAS,CAACC,IADX,EAECC,aAAa,CAACf,UAFf,EAGCe,aAAa,CAACE,WAHf,CAFW,CAAZ;AAQA;AACD;AACD,KAjBD,CAFF;AAqBC,IAAA,QAAQ,EAAGd,iBArBZ;AAsBC,IAAA,MAAM,EAAGA,iBAtBV;AAuBC,IAAA,OAAO,EAAC;AAvBT,KAyBG;AACD;AACA,gBAAI,YAAJ,CAFC,EAGDF,KAAK,CAACiB,KAHL,CAzBH,CADD;AAiCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock, getBlockType, parse } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as blockDirectoryStore } from '../../store';\n\nexport default function InstallButton( { attributes, block, clientId } ) {\n\tconst isInstallingBlock = useSelect(\n\t\t( select ) => select( blockDirectoryStore ).isInstalling( block.id ),\n\t\t[ block.id ]\n\t);\n\tconst { installBlockType } = useDispatch( blockDirectoryStore );\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\n\treturn (\n\t\t<Button\n\t\t\tonClick={ () =>\n\t\t\t\tinstallBlockType( block ).then( ( success ) => {\n\t\t\t\t\tif ( success ) {\n\t\t\t\t\t\tconst blockType = getBlockType( block.name );\n\t\t\t\t\t\tconst [ originalBlock ] = parse(\n\t\t\t\t\t\t\tattributes.originalContent\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( originalBlock && blockType ) {\n\t\t\t\t\t\t\treplaceBlock(\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\tblockType.name,\n\t\t\t\t\t\t\t\t\toriginalBlock.attributes,\n\t\t\t\t\t\t\t\t\toriginalBlock.innerBlocks\n\t\t\t\t\t\t\t\t)\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\t\t\t}\n\t\t\tdisabled={ isInstallingBlock }\n\t\t\tisBusy={ isInstallingBlock }\n\t\t\tvariant=\"primary\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %s: block name */\n\t\t\t\t__( 'Install %s' ),\n\t\t\t\tblock.title\n\t\t\t) }\n\t\t</Button>\n\t);\n}\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -7,25 +7,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.fetchDownloadableBlocks = fetchDownloadableBlocks;
|
|
9
9
|
exports.receiveDownloadableBlocks = receiveDownloadableBlocks;
|
|
10
|
-
exports.installBlockType = installBlockType;
|
|
11
|
-
exports.uninstallBlockType = uninstallBlockType;
|
|
12
10
|
exports.addInstalledBlockType = addInstalledBlockType;
|
|
13
11
|
exports.removeInstalledBlockType = removeInstalledBlockType;
|
|
14
12
|
exports.setIsInstalling = setIsInstalling;
|
|
15
13
|
exports.setErrorNotice = setErrorNotice;
|
|
16
14
|
exports.clearErrorNotice = clearErrorNotice;
|
|
15
|
+
exports.uninstallBlockType = exports.installBlockType = void 0;
|
|
17
16
|
|
|
18
17
|
var _blocks = require("@wordpress/blocks");
|
|
19
18
|
|
|
20
19
|
var _i18n = require("@wordpress/i18n");
|
|
21
20
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _dataControls = require("@wordpress/data-controls");
|
|
21
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
25
22
|
|
|
26
23
|
var _notices = require("@wordpress/notices");
|
|
27
24
|
|
|
28
|
-
var
|
|
25
|
+
var _loadAssets = require("./load-assets");
|
|
29
26
|
|
|
30
27
|
var _getPluginUrl = _interopRequireDefault(require("./utils/get-plugin-url"));
|
|
31
28
|
|
|
@@ -78,54 +75,56 @@ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
|
|
|
78
75
|
*/
|
|
79
76
|
|
|
80
77
|
|
|
81
|
-
|
|
78
|
+
const installBlockType = block => async ({
|
|
79
|
+
registry,
|
|
80
|
+
dispatch
|
|
81
|
+
}) => {
|
|
82
82
|
const {
|
|
83
|
-
id
|
|
84
|
-
assets
|
|
83
|
+
id
|
|
85
84
|
} = block;
|
|
86
85
|
let success = false;
|
|
87
|
-
|
|
86
|
+
dispatch.clearErrorNotice(id);
|
|
88
87
|
|
|
89
88
|
try {
|
|
90
|
-
|
|
89
|
+
dispatch.setIsInstalling(id, true); // If we have a wp:plugin link, the plugin is installed but inactive.
|
|
91
90
|
|
|
92
91
|
const url = (0, _getPluginUrl.default)(block);
|
|
93
92
|
let links = {};
|
|
94
93
|
|
|
95
94
|
if (url) {
|
|
96
|
-
|
|
95
|
+
await (0, _apiFetch.default)({
|
|
96
|
+
method: 'PUT',
|
|
97
97
|
url,
|
|
98
98
|
data: {
|
|
99
99
|
status: 'active'
|
|
100
|
-
}
|
|
101
|
-
method: 'PUT'
|
|
100
|
+
}
|
|
102
101
|
});
|
|
103
102
|
} else {
|
|
104
|
-
const response =
|
|
103
|
+
const response = await (0, _apiFetch.default)({
|
|
104
|
+
method: 'POST',
|
|
105
105
|
path: 'wp/v2/plugins',
|
|
106
106
|
data: {
|
|
107
|
-
slug:
|
|
107
|
+
slug: id,
|
|
108
108
|
status: 'active'
|
|
109
|
-
}
|
|
110
|
-
method: 'POST'
|
|
109
|
+
}
|
|
111
110
|
}); // Add the `self` link for newly-installed blocks.
|
|
112
111
|
|
|
113
112
|
links = response._links;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
|
|
115
|
+
dispatch.addInstalledBlockType({ ...block,
|
|
117
116
|
links: { ...block.links,
|
|
118
117
|
...links
|
|
119
118
|
}
|
|
120
119
|
});
|
|
121
|
-
|
|
122
|
-
const registeredBlocks =
|
|
120
|
+
await (0, _loadAssets.loadAssets)();
|
|
121
|
+
const registeredBlocks = registry.select(_blocks.store).getBlockTypes();
|
|
123
122
|
|
|
124
123
|
if (!registeredBlocks.some(i => i.name === block.name)) {
|
|
125
124
|
throw new Error((0, _i18n.__)('Error registering block. Try reloading the page.'));
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
|
|
127
|
+
registry.dispatch(_notices.store).createInfoNotice((0, _i18n.sprintf)( // translators: %s is the block title.
|
|
129
128
|
(0, _i18n.__)('Block %s installed and added.'), block.title), {
|
|
130
129
|
speak: true,
|
|
131
130
|
type: 'snackbar'
|
|
@@ -146,16 +145,16 @@ function* installBlockType(block) {
|
|
|
146
145
|
message = fatalAPIErrors[error.code];
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
dispatch.setErrorNotice(id, message, isFatal);
|
|
149
|
+
registry.dispatch(_notices.store).createErrorNotice(message, {
|
|
151
150
|
speak: true,
|
|
152
151
|
isDismissible: true
|
|
153
152
|
});
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
dispatch.setIsInstalling(id, false);
|
|
157
156
|
return success;
|
|
158
|
-
}
|
|
157
|
+
};
|
|
159
158
|
/**
|
|
160
159
|
* Action triggered to uninstall a block plugin.
|
|
161
160
|
*
|
|
@@ -163,24 +162,30 @@ function* installBlockType(block) {
|
|
|
163
162
|
*/
|
|
164
163
|
|
|
165
164
|
|
|
166
|
-
|
|
165
|
+
exports.installBlockType = installBlockType;
|
|
166
|
+
|
|
167
|
+
const uninstallBlockType = block => async ({
|
|
168
|
+
registry,
|
|
169
|
+
dispatch
|
|
170
|
+
}) => {
|
|
167
171
|
try {
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
const url = (0, _getPluginUrl.default)(block);
|
|
173
|
+
await (0, _apiFetch.default)({
|
|
174
|
+
method: 'PUT',
|
|
175
|
+
url,
|
|
170
176
|
data: {
|
|
171
177
|
status: 'inactive'
|
|
172
|
-
}
|
|
173
|
-
method: 'PUT'
|
|
178
|
+
}
|
|
174
179
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
180
|
+
await (0, _apiFetch.default)({
|
|
181
|
+
method: 'DELETE',
|
|
182
|
+
url
|
|
178
183
|
});
|
|
179
|
-
|
|
184
|
+
dispatch.removeInstalledBlockType(block);
|
|
180
185
|
} catch (error) {
|
|
181
|
-
|
|
186
|
+
registry.dispatch(_notices.store).createErrorNotice(error.message || (0, _i18n.__)('An error occurred.'));
|
|
182
187
|
}
|
|
183
|
-
}
|
|
188
|
+
};
|
|
184
189
|
/**
|
|
185
190
|
* Returns an action object used to add a block type to the "newly installed"
|
|
186
191
|
* tracking list.
|
|
@@ -191,6 +196,8 @@ function* uninstallBlockType(block) {
|
|
|
191
196
|
*/
|
|
192
197
|
|
|
193
198
|
|
|
199
|
+
exports.uninstallBlockType = uninstallBlockType;
|
|
200
|
+
|
|
194
201
|
function addInstalledBlockType(item) {
|
|
195
202
|
return {
|
|
196
203
|
type: 'ADD_INSTALLED_BLOCK_TYPE',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","id","assets","success","clearErrorNotice","setIsInstalling","url","links","data","status","method","response","path","slug","_links","addInstalledBlockType","registeredBlocks","controls","select","blocksStore","name","some","i","Error","dispatch","noticesStore","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAbA;AACA;AACA;;AAOA;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,UAAUI,gBAAV,CAA4BC,KAA5B,EAAoC;AAC1C,QAAM;AAAEC,IA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AE,oBADA;AAEN4C,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { controls } from '@wordpress/data';\nimport { apiFetch } from '@wordpress/data-controls';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './controls';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport function* installBlockType( block ) {\n\tconst { id, assets } = block;\n\tlet success = false;\n\tyield clearErrorNotice( id );\n\ttry {\n\t\tyield setIsInstalling( block.id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tyield apiFetch( {\n\t\t\t\turl,\n\t\t\t\tdata: {\n\t\t\t\t\tstatus: 'active',\n\t\t\t\t},\n\t\t\t\tmethod: 'PUT',\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = yield apiFetch( {\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: {\n\t\t\t\t\tslug: block.id,\n\t\t\t\t\tstatus: 'active',\n\t\t\t\t},\n\t\t\t\tmethod: 'POST',\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tyield addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\tyield loadAssets( assets );\n\t\tconst registeredBlocks = yield controls.select(\n\t\t\tblocksStore.name,\n\t\t\t'getBlockTypes'\n\t\t);\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === block.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createInfoNotice',\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tyield setErrorNotice( id, message, isFatal );\n\t\tyield controls.dispatch( noticesStore, 'createErrorNotice', message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tyield setIsInstalling( block.id, false );\n\treturn success;\n}\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport function* uninstallBlockType( block ) {\n\ttry {\n\t\tyield apiFetch( {\n\t\t\turl: getPluginUrl( block ),\n\t\t\tdata: {\n\t\t\t\tstatus: 'inactive',\n\t\t\t},\n\t\t\tmethod: 'PUT',\n\t\t} );\n\t\tyield apiFetch( {\n\t\t\turl: getPluginUrl( block ),\n\t\t\tmethod: 'DELETE',\n\t\t} );\n\t\tyield removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tyield controls.dispatch(\n\t\t\tnoticesStore,\n\t\t\t'createErrorNotice',\n\t\t\terror.message || __( 'An error occurred.' )\n\t\t);\n\t}\n}\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/actions.js"],"names":["fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","registeredBlocks","select","blocksStore","getBlockTypes","some","i","name","Error","noticesStore","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"mappings":";;;;;;;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAZA;AACA;AACA;;AAMA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,uBAAT,CAAkCC,WAAlC,EAAgD;AACtD,SAAO;AAAEC,IAAAA,IAAI,EAAE,2BAAR;AAAqCD,IAAAA;AAArC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,yBAAT,CAAoCC,kBAApC,EAAwDH,WAAxD,EAAsE;AAC5E,SAAO;AACNC,IAAAA,IAAI,EAAE,6BADA;AAENE,IAAAA,kBAFM;AAGNH,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMI,gBAAgB,GAAKC,KAAF,IAAa,OAAQ;AACpDC,EAAAA,QADoD;AAEpDC,EAAAA;AAFoD,CAAR,KAGtC;AACN,QAAM;AAAEC,IAAAA;AAAF,MAASH,KAAf;AACA,MAAII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SAAS1B,gBAAT,CAA2BqC,OAA3B,EAAqC;AAC3C,SAAO;AACN9C,IAAAA,IAAI,EAAE,oBADA;AAEN8C,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\tconst { id } = block;\n\tlet success = false;\n\tdispatch.clearErrorNotice( id );\n\ttry {\n\t\tdispatch.setIsInstalling( id, true );\n\n\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\tconst url = getPluginUrl( block );\n\t\tlet links = {};\n\t\tif ( url ) {\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'active' },\n\t\t\t} );\n\t\t} else {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t} );\n\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\tlinks = response._links;\n\t\t}\n\n\t\tdispatch.addInstalledBlockType( {\n\t\t\t...block,\n\t\t\tlinks: { ...block.links, ...links },\n\t\t} );\n\n\t\tawait loadAssets();\n\t\tconst registeredBlocks = registry.select( blocksStore ).getBlockTypes();\n\t\tif ( ! registeredBlocks.some( ( i ) => i.name === block.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t);\n\t\t}\n\n\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\tsprintf(\n\t\t\t\t// translators: %s is the block title.\n\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\tblock.title\n\t\t\t),\n\t\t\t{\n\t\t\t\tspeak: true,\n\t\t\t\ttype: 'snackbar',\n\t\t\t}\n\t\t);\n\t\tsuccess = true;\n\t} catch ( error ) {\n\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t// Errors we throw are fatal\n\t\tlet isFatal = error instanceof Error;\n\n\t\t// Specific API errors that are fatal\n\t\tconst fatalAPIErrors = {\n\t\t\tfolder_exists: __(\n\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t),\n\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t),\n\t\t};\n\n\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\tisFatal = true;\n\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t}\n\n\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\tspeak: true,\n\t\t\tisDismissible: true,\n\t\t} );\n\t}\n\tdispatch.setIsInstalling( id, false );\n\treturn success;\n};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType = ( block ) => async ( {\n\tregistry,\n\tdispatch,\n} ) => {\n\ttry {\n\t\tconst url = getPluginUrl( block );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'PUT',\n\t\t\turl,\n\t\t\tdata: { status: 'inactive' },\n\t\t} );\n\t\tawait apiFetch( {\n\t\t\tmethod: 'DELETE',\n\t\t\turl,\n\t\t} );\n\t\tdispatch.removeInstalledBlockType( block );\n\t} catch ( error ) {\n\t\tregistry\n\t\t\t.dispatch( noticesStore )\n\t\t\t.createErrorNotice( error.message || __( 'An error occurred.' ) );\n\t}\n};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -11,17 +11,13 @@ exports.store = exports.storeConfig = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _data = require("@wordpress/data");
|
|
13
13
|
|
|
14
|
-
var _dataControls = require("@wordpress/data-controls");
|
|
15
|
-
|
|
16
14
|
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
17
15
|
|
|
18
16
|
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
19
17
|
|
|
20
18
|
var actions = _interopRequireWildcard(require("./actions"));
|
|
21
19
|
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
var _controls = _interopRequireDefault(require("./controls"));
|
|
20
|
+
var resolvers = _interopRequireWildcard(require("./resolvers"));
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* WordPress dependencies
|
|
@@ -47,10 +43,8 @@ const storeConfig = {
|
|
|
47
43
|
reducer: _reducer.default,
|
|
48
44
|
selectors,
|
|
49
45
|
actions,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
resolvers: _resolvers.default
|
|
46
|
+
resolvers,
|
|
47
|
+
__experimentalUseThunks: true
|
|
54
48
|
};
|
|
55
49
|
/**
|
|
56
50
|
* Store definition for the block directory namespace.
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["STORE_NAME","storeConfig","reducer","selectors","actions","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/index.js"],"names":["STORE_NAME","storeConfig","reducer","selectors","actions","resolvers","__experimentalUseThunks","store"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AACA,MAAMA,UAAU,GAAG,sBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,WAAW,GAAG;AAC1BC,EAAAA,OAAO,EAAPA,gBAD0B;AAE1BC,EAAAA,SAF0B;AAG1BC,EAAAA,OAH0B;AAI1BC,EAAAA,SAJ0B;AAK1BC,EAAAA,uBAAuB,EAAE;AALC,CAApB;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,KAAK,GAAG,4BAAkBP,UAAlB,EAA8BC,WAA9B,CAAd;;AAEP,oBAAUM,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\n\n/**\n * Module Constants\n */\nconst STORE_NAME = 'core/block-directory';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore\n *\n * @type {Object}\n */\nexport const storeConfig = {\n\treducer,\n\tselectors,\n\tactions,\n\tresolvers,\n\t__experimentalUseThunks: true,\n};\n\n/**\n * Store definition for the block directory namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\n\nregister( store );\n"]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.loadAssets = loadAssets;
|
|
9
|
-
exports.
|
|
9
|
+
exports.loadAsset = void 0;
|
|
10
10
|
|
|
11
11
|
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
12
12
|
|
|
@@ -54,49 +54,33 @@ const loadAsset = el => {
|
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
56
|
* Load the asset files for a block
|
|
57
|
-
*
|
|
58
|
-
* @param {Array} assets A collection of URLs for the assets.
|
|
59
|
-
*
|
|
60
|
-
* @return {Object} Control descriptor.
|
|
61
57
|
*/
|
|
62
58
|
|
|
63
59
|
|
|
64
60
|
exports.loadAsset = loadAsset;
|
|
65
61
|
|
|
66
|
-
function loadAssets(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
89
|
-
/*
|
|
90
|
-
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
91
|
-
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
for (const newAsset of newAssets) {
|
|
95
|
-
await loadAsset(newAsset);
|
|
96
|
-
}
|
|
62
|
+
async function loadAssets() {
|
|
63
|
+
/*
|
|
64
|
+
* Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
|
|
65
|
+
* JavaScript and CSS assets loaded between the pages. This imports the required assets
|
|
66
|
+
* for the block into the current page while not requiring that we know them up-front.
|
|
67
|
+
* In the future this can be improved by reliance upon block.json and/or a script-loader
|
|
68
|
+
* dependency API.
|
|
69
|
+
*/
|
|
70
|
+
const response = await (0, _apiFetch.default)({
|
|
71
|
+
url: document.location.href,
|
|
72
|
+
parse: false
|
|
73
|
+
});
|
|
74
|
+
const data = await response.text();
|
|
75
|
+
const doc = new window.DOMParser().parseFromString(data, 'text/html');
|
|
76
|
+
const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
|
|
77
|
+
/*
|
|
78
|
+
* Load each asset in order, as they may depend upon an earlier loaded script.
|
|
79
|
+
* Stylesheets and Inline Scripts will resolve immediately upon insertion.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
for (const newAsset of newAssets) {
|
|
83
|
+
await loadAsset(newAsset);
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var _default = controls;
|
|
101
|
-
exports.default = _default;
|
|
102
|
-
//# sourceMappingURL=controls.js.map
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=load-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/load-assets.js"],"names":["loadAsset","el","Promise","resolve","reject","newNode","document","createElement","nodeName","forEach","attr","innerHTML","appendChild","createTextNode","onload","onerror","Error","body","toLowerCase","src","loadAssets","response","url","location","href","parse","data","text","doc","window","DOMParser","parseFromString","newAssets","Array","from","querySelectorAll","filter","asset","id","getElementById","newAsset"],"mappings":";;;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,SAAS,GAAKC,EAAF,IAAU;AAClC,SAAO,IAAIC,OAAJ,CAAa,CAAEC,OAAF,EAAWC,MAAX,KAAuB;AAC1C;AACF;AACA;AACA;AACE,UAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAwBN,EAAE,CAACO,QAA3B,CAAhB;AAEA,KAAE,IAAF,EAAQ,KAAR,EAAe,KAAf,EAAsB,MAAtB,EAA8B,MAA9B,EAAuCC,OAAvC,CAAkDC,IAAF,IAAY;AAC3D,UAAKT,EAAE,CAAES,IAAF,CAAP,EAAkB;AACjBL,QAAAA,OAAO,CAAEK,IAAF,CAAP,GAAkBT,EAAE,CAAES,IAAF,CAApB;AACA;AACD,KAJD,EAP0C,CAa1C;;AACA,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C,OAAM,MAAME,QAAZ,IAAwBR,SAAxB,EAAoC;AACnC,UAAMhC,SAAS,CAAEwC,QAAF,CAAf;AACA;AACD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Load an asset for a block.\n *\n * This function returns a Promise that will resolve once the asset is loaded,\n * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.\n *\n * @param {HTMLElement} el A HTML Element asset to inject.\n *\n * @return {Promise} Promise which will resolve when the asset is loaded.\n */\nexport const loadAsset = ( el ) => {\n\treturn new Promise( ( resolve, reject ) => {\n\t\t/*\n\t\t * Reconstruct the passed element, this is required as inserting the Node directly\n\t\t * won't always fire the required onload events, even if the asset wasn't already loaded.\n\t\t */\n\t\tconst newNode = document.createElement( el.nodeName );\n\n\t\t[ 'id', 'rel', 'src', 'href', 'type' ].forEach( ( attr ) => {\n\t\t\tif ( el[ attr ] ) {\n\t\t\t\tnewNode[ attr ] = el[ attr ];\n\t\t\t}\n\t\t} );\n\n\t\t// Append inline <script> contents.\n\t\tif ( el.innerHTML ) {\n\t\t\tnewNode.appendChild( document.createTextNode( el.innerHTML ) );\n\t\t}\n\n\t\tnewNode.onload = () => resolve( true );\n\t\tnewNode.onerror = () => reject( new Error( 'Error loading asset.' ) );\n\n\t\tdocument.body.appendChild( newNode );\n\n\t\t// Resolve Stylesheets and Inline JavaScript immediately.\n\t\tif (\n\t\t\t'link' === newNode.nodeName.toLowerCase() ||\n\t\t\t( 'script' === newNode.nodeName.toLowerCase() && ! newNode.src )\n\t\t) {\n\t\t\tresolve();\n\t\t}\n\t} );\n};\n\n/**\n * Load the asset files for a block\n */\nexport async function loadAssets() {\n\t/*\n\t * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the\n\t * JavaScript and CSS assets loaded between the pages. This imports the required assets\n\t * for the block into the current page while not requiring that we know them up-front.\n\t * In the future this can be improved by reliance upon block.json and/or a script-loader\n\t * dependency API.\n\t */\n\tconst response = await apiFetch( {\n\t\turl: document.location.href,\n\t\tparse: false,\n\t} );\n\n\tconst data = await response.text();\n\n\tconst doc = new window.DOMParser().parseFromString( data, 'text/html' );\n\n\tconst newAssets = Array.from(\n\t\tdoc.querySelectorAll( 'link[rel=\"stylesheet\"],script' )\n\t).filter( ( asset ) => asset.id && ! document.getElementById( asset.id ) );\n\n\t/*\n\t * Load each asset in order, as they may depend upon an earlier loaded script.\n\t * Stylesheets and Inline Scripts will resolve immediately upon insertion.\n\t */\n\tfor ( const newAsset of newAssets ) {\n\t\tawait loadAsset( newAsset );\n\t}\n}\n"]}
|
package/build/store/resolvers.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.
|
|
8
|
+
exports.getDownloadableBlocks = void 0;
|
|
7
9
|
|
|
8
10
|
var _lodash = require("lodash");
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
11
13
|
|
|
12
14
|
var _actions = require("./actions");
|
|
13
15
|
|
|
@@ -22,24 +24,22 @@ var _actions = require("./actions");
|
|
|
22
24
|
/**
|
|
23
25
|
* Internal dependencies
|
|
24
26
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
yield (0, _actions.fetchDownloadableBlocks)(filterValue);
|
|
33
|
-
const results = yield (0, _dataControls.apiFetch)({
|
|
34
|
-
path: `wp/v2/block-directory/search?term=${filterValue}`
|
|
35
|
-
});
|
|
36
|
-
const blocks = results.map(result => (0, _lodash.mapKeys)(result, (value, key) => {
|
|
37
|
-
return (0, _lodash.camelCase)(key);
|
|
38
|
-
}));
|
|
39
|
-
yield (0, _actions.receiveDownloadableBlocks)(blocks, filterValue);
|
|
40
|
-
} catch (error) {}
|
|
27
|
+
const getDownloadableBlocks = filterValue => async ({
|
|
28
|
+
dispatch
|
|
29
|
+
}) => {
|
|
30
|
+
if (!filterValue) {
|
|
31
|
+
return;
|
|
41
32
|
}
|
|
42
33
|
|
|
34
|
+
try {
|
|
35
|
+
dispatch((0, _actions.fetchDownloadableBlocks)(filterValue));
|
|
36
|
+
const results = await (0, _apiFetch.default)({
|
|
37
|
+
path: `wp/v2/block-directory/search?term=${filterValue}`
|
|
38
|
+
});
|
|
39
|
+
const blocks = results.map(result => (0, _lodash.mapKeys)(result, (value, key) => (0, _lodash.camelCase)(key)));
|
|
40
|
+
dispatch((0, _actions.receiveDownloadableBlocks)(blocks, filterValue));
|
|
41
|
+
} catch {}
|
|
43
42
|
};
|
|
44
|
-
|
|
43
|
+
|
|
44
|
+
exports.getDownloadableBlocks = getDownloadableBlocks;
|
|
45
45
|
//# sourceMappingURL=resolvers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","results","path","blocks","map","result","value","key"
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/resolvers.js"],"names":["getDownloadableBlocks","filterValue","dispatch","results","path","blocks","map","result","value","key"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AAGO,MAAMA,qBAAqB,GAAKC,WAAF,IAAmB,OAAQ;AAC/DC,EAAAA;AAD+D,CAAR,KAEjD;AACN,MAAK,CAAED,WAAP,EAAqB;AACpB;AACA;;AAED,MAAI;AACHC,IAAAA,QAAQ,CAAE,sCAAyBD,WAAzB,CAAF,CAAR;AACA,UAAME,OAAO,GAAG,MAAM,uBAAU;AAC/BC,MAAAA,IAAI,EAAG,qCAAqCH,WAAa;AAD1B,KAAV,CAAtB;AAGA,UAAMI,MAAM,GAAGF,OAAO,CAACG,GAAR,CAAeC,MAAF,IAC3B,qBAASA,MAAT,EAAiB,CAAEC,KAAF,EAASC,GAAT,KAAkB,uBAAWA,GAAX,CAAnC,CADc,CAAf;AAIAP,IAAAA,QAAQ,CAAE,wCAA2BG,MAA3B,EAAmCJ,WAAnC,CAAF,CAAR;AACA,GAVD,CAUE,MAAM,CAAE;AACV,CAlBM","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase, mapKeys } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { fetchDownloadableBlocks, receiveDownloadableBlocks } from './actions';\n\nexport const getDownloadableBlocks = ( filterValue ) => async ( {\n\tdispatch,\n} ) => {\n\tif ( ! filterValue ) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tdispatch( fetchDownloadableBlocks( filterValue ) );\n\t\tconst results = await apiFetch( {\n\t\t\tpath: `wp/v2/block-directory/search?term=${ filterValue }`,\n\t\t} );\n\t\tconst blocks = results.map( ( result ) =>\n\t\t\tmapKeys( result, ( value, key ) => camelCase( key ) )\n\t\t);\n\n\t\tdispatch( receiveDownloadableBlocks( blocks, filterValue ) );\n\t} catch {}\n};\n"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -36,11 +36,9 @@ var _hasBlockType = _interopRequireDefault(require("./utils/has-block-type"));
|
|
|
36
36
|
* @return {boolean} Whether a request is in progress for the blocks list.
|
|
37
37
|
*/
|
|
38
38
|
function isRequestingDownloadableBlocks(state, filterValue) {
|
|
39
|
-
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
39
|
+
var _state$downloadableBl, _state$downloadableBl2;
|
|
42
40
|
|
|
43
|
-
return state.downloadableBlocks[filterValue].isRequesting;
|
|
41
|
+
return (_state$downloadableBl = (_state$downloadableBl2 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl2 === void 0 ? void 0 : _state$downloadableBl2.isRequesting) !== null && _state$downloadableBl !== void 0 ? _state$downloadableBl : false;
|
|
44
42
|
}
|
|
45
43
|
/**
|
|
46
44
|
* Returns the available uninstalled blocks.
|
|
@@ -53,11 +51,9 @@ function isRequestingDownloadableBlocks(state, filterValue) {
|
|
|
53
51
|
|
|
54
52
|
|
|
55
53
|
function getDownloadableBlocks(state, filterValue) {
|
|
56
|
-
|
|
57
|
-
return [];
|
|
58
|
-
}
|
|
54
|
+
var _state$downloadableBl3, _state$downloadableBl4;
|
|
59
55
|
|
|
60
|
-
return state.downloadableBlocks[filterValue].results;
|
|
56
|
+
return (_state$downloadableBl3 = (_state$downloadableBl4 = state.downloadableBlocks[filterValue]) === null || _state$downloadableBl4 === void 0 ? void 0 : _state$downloadableBl4.results) !== null && _state$downloadableBl3 !== void 0 ? _state$downloadableBl3 : [];
|
|
61
57
|
}
|
|
62
58
|
/**
|
|
63
59
|
* Returns the block types that have been installed on the server in this
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","blockEditorStore","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AACpE,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/store/selectors.js"],"names":["isRequestingDownloadableBlocks","state","filterValue","downloadableBlocks","isRequesting","getDownloadableBlocks","results","getInstalledBlockTypes","blockManagement","installedBlockTypes","getNewBlockTypes","select","usedBlockTree","blockEditorStore","getBlocks","filter","blockType","getUnusedBlockTypes","isInstalling","blockId","getErrorNotices","errorNotices","getErrorNoticeForBlock"],"mappings":";;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,8BAAT,CAAyCC,KAAzC,EAAgDC,WAAhD,EAA8D;AAAA;;AACpE,4DAAOD,KAAK,CAACE,kBAAN,CAA0BD,WAA1B,CAAP,2DAAO,uBAAyCE,YAAhD,yEAAgE,KAAhE;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,qBAAT,CAAgCJ,KAAhC,EAAuCC,WAAvC,EAAqD;AAAA;;AAC3D,6DAAOD,KAAK,CAACE,kBAAN,CAA0BD,WAA1B,CAAP,2DAAO,uBAAyCI,OAAhD,2EAA2D,EAA3D;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,sBAAT,CAAiCN,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACO,eAAN,CAAsBC,mBAA7B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,gBAAgB,GAAG,kCAC7BC,MAAF,IAAgBV,KAAF,IAAa;AAC1B,QAAMW,aAAa,GAAGD,MAAM,CAAEE,kBAAF,CAAN,CAA2BC,SAA3B,EAAtB;AACA,QAAML,mBAAmB,GAAGF,sBAAsB,CAAEN,KAAF,CAAlD;AAEA,SAAOQ,mBAAmB,CAACM,MAApB,CAA8BC,SAAF,IAClC,2BAAcA,SAAd,EAAyBJ,aAAzB,CADM,CAAP;AAGA,CAR8B,CAAzB;AAWP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMK,mBAAmB,GAAG,kCAChCN,MAAF,IAAgBV,KAAF,IAAa;AAC1B,QAAMW,aAAa,GAAGD,MAAM,CAAEE,kBAAF,CAAN,CAA2BC,SAA3B,EAAtB;AACA,QAAML,mBAAmB,GAAGF,sBAAsB,CAAEN,KAAF,CAAlD;AAEA,SAAOQ,mBAAmB,CAACM,MAApB,CACJC,SAAF,IAAiB,CAAE,2BAAcA,SAAd,EAAyBJ,aAAzB,CADb,CAAP;AAGA,CARiC,CAA5B;AAWP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASM,YAAT,CAAuBjB,KAAvB,EAA8BkB,OAA9B,EAAwC;AAC9C,SAAOlB,KAAK,CAACO,eAAN,CAAsBU,YAAtB,CAAoCC,OAApC,KAAiD,KAAxD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,eAAT,CAA0BnB,KAA1B,EAAkC;AACxC,SAAOA,KAAK,CAACoB,YAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,sBAAT,CAAiCrB,KAAjC,EAAwCkB,OAAxC,EAAkD;AACxD,SAAOlB,KAAK,CAACoB,YAAN,CAAoBF,OAApB,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistrySelector } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport hasBlockType from './utils/has-block-type';\n\n/**\n * Returns true if application is requesting for downloadable blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {boolean} Whether a request is in progress for the blocks list.\n */\nexport function isRequestingDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.isRequesting ?? false;\n}\n\n/**\n * Returns the available uninstalled blocks.\n *\n * @param {Object} state Global application state.\n * @param {string} filterValue Search string.\n *\n * @return {Array} Downloadable blocks.\n */\nexport function getDownloadableBlocks( state, filterValue ) {\n\treturn state.downloadableBlocks[ filterValue ]?.results ?? [];\n}\n\n/**\n * Returns the block types that have been installed on the server in this\n * session.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items\n */\nexport function getInstalledBlockTypes( state ) {\n\treturn state.blockManagement.installedBlockTypes;\n}\n\n/**\n * Returns block types that have been installed on the server and used in the\n * current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getNewBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter( ( blockType ) =>\n\t\t\thasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns the block types that have been installed on the server but are not\n * used in the current post.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} Block type items.\n */\nexport const getUnusedBlockTypes = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst usedBlockTree = select( blockEditorStore ).getBlocks();\n\t\tconst installedBlockTypes = getInstalledBlockTypes( state );\n\n\t\treturn installedBlockTypes.filter(\n\t\t\t( blockType ) => ! hasBlockType( blockType, usedBlockTree )\n\t\t);\n\t}\n);\n\n/**\n * Returns true if a block plugin install is in progress.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId Id of the block.\n *\n * @return {boolean} Whether this block is currently being installed.\n */\nexport function isInstalling( state, blockId ) {\n\treturn state.blockManagement.isInstalling[ blockId ] || false;\n}\n\n/**\n * Returns all block error notices.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Object with error notices.\n */\nexport function getErrorNotices( state ) {\n\treturn state.errorNotices;\n}\n\n/**\n * Returns the error notice for a given block.\n *\n * @param {Object} state Global application state.\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {string|boolean} The error text, or false if no error.\n */\nexport function getErrorNoticeForBlock( state, blockId ) {\n\treturn state.errorNotices[ blockId ];\n}\n"]}
|
|
@@ -18,7 +18,7 @@ export default function InstallButton({
|
|
|
18
18
|
block,
|
|
19
19
|
clientId
|
|
20
20
|
}) {
|
|
21
|
-
const isInstallingBlock = useSelect(select => select(blockDirectoryStore).isInstalling(block.id));
|
|
21
|
+
const isInstallingBlock = useSelect(select => select(blockDirectoryStore).isInstalling(block.id), [block.id]);
|
|
22
22
|
const {
|
|
23
23
|
installBlockType
|
|
24
24
|
} = useDispatch(blockDirectoryStore);
|
|
@@ -31,7 +31,7 @@ export default function InstallButton({
|
|
|
31
31
|
const blockType = getBlockType(block.name);
|
|
32
32
|
const [originalBlock] = parse(attributes.originalContent);
|
|
33
33
|
|
|
34
|
-
if (originalBlock) {
|
|
34
|
+
if (originalBlock && blockType) {
|
|
35
35
|
replaceBlock(clientId, createBlock(blockType.name, originalBlock.attributes, originalBlock.innerBlocks));
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["__","sprintf","Button","createBlock","getBlockType","parse","useSelect","useDispatch","store","blockEditorStore","blockDirectoryStore","InstallButton","attributes","block","clientId","isInstallingBlock","select","isInstalling","id","installBlockType","replaceBlock","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,KAApC,QAAiD,mBAAjD;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,SAASD,KAAK,IAAIE,mBAAlB,QAA6C,aAA7C;AAEA,eAAe,SAASC,aAAT,CAAwB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAxB,EAA0D;AACxE,QAAMC,iBAAiB,GAAGT,SAAS,
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-directory/src/plugins/get-install-missing/install-button.js"],"names":["__","sprintf","Button","createBlock","getBlockType","parse","useSelect","useDispatch","store","blockEditorStore","blockDirectoryStore","InstallButton","attributes","block","clientId","isInstallingBlock","select","isInstalling","id","installBlockType","replaceBlock","then","success","blockType","name","originalBlock","originalContent","innerBlocks","title"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,KAApC,QAAiD,mBAAjD;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AAEA;AACA;AACA;;AACA,SAASD,KAAK,IAAIE,mBAAlB,QAA6C,aAA7C;AAEA,eAAe,SAASC,aAAT,CAAwB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA,KAAd;AAAqBC,EAAAA;AAArB,CAAxB,EAA0D;AACxE,QAAMC,iBAAiB,GAAGT,SAAS,CAChCU,MAAF,IAAcA,MAAM,CAAEN,mBAAF,CAAN,CAA8BO,YAA9B,CAA4CJ,KAAK,CAACK,EAAlD,CADoB,EAElC,CAAEL,KAAK,CAACK,EAAR,CAFkC,CAAnC;AAIA,QAAM;AAAEC,IAAAA;AAAF,MAAuBZ,WAAW,CAAEG,mBAAF,CAAxC;AACA,QAAM;AAAEU,IAAAA;AAAF,MAAmBb,WAAW,CAAEE,gBAAF,CAApC;AAEA,SACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAG,MACTU,gBAAgB,CAAEN,KAAF,CAAhB,CAA0BQ,IAA1B,CAAkCC,OAAF,IAAe;AAC9C,UAAKA,OAAL,EAAe;AACd,cAAMC,SAAS,GAAGnB,YAAY,CAAES,KAAK,CAACW,IAAR,CAA9B;AACA,cAAM,CAAEC,aAAF,IAAoBpB,KAAK,CAC9BO,UAAU,CAACc,eADmB,CAA/B;;AAGA,YAAKD,aAAa,IAAIF,SAAtB,EAAkC;AACjCH,UAAAA,YAAY,CACXN,QADW,EAEXX,WAAW,CACVoB,SAAS,CAACC,IADA,EAEVC,aAAa,CAACb,UAFJ,EAGVa,aAAa,CAACE,WAHJ,CAFA,CAAZ;AAQA;AACD;AACD,KAjBD,CAFF;AAqBC,IAAA,QAAQ,EAAGZ,iBArBZ;AAsBC,IAAA,MAAM,EAAGA,iBAtBV;AAuBC,IAAA,OAAO,EAAC;AAvBT,KAyBGd,OAAO;AACR;AACAD,EAAAA,EAAE,CAAE,YAAF,CAFM,EAGRa,KAAK,CAACe,KAHE,CAzBV,CADD;AAiCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { createBlock, getBlockType, parse } from '@wordpress/blocks';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { store as blockDirectoryStore } from '../../store';\n\nexport default function InstallButton( { attributes, block, clientId } ) {\n\tconst isInstallingBlock = useSelect(\n\t\t( select ) => select( blockDirectoryStore ).isInstalling( block.id ),\n\t\t[ block.id ]\n\t);\n\tconst { installBlockType } = useDispatch( blockDirectoryStore );\n\tconst { replaceBlock } = useDispatch( blockEditorStore );\n\n\treturn (\n\t\t<Button\n\t\t\tonClick={ () =>\n\t\t\t\tinstallBlockType( block ).then( ( success ) => {\n\t\t\t\t\tif ( success ) {\n\t\t\t\t\t\tconst blockType = getBlockType( block.name );\n\t\t\t\t\t\tconst [ originalBlock ] = parse(\n\t\t\t\t\t\t\tattributes.originalContent\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( originalBlock && blockType ) {\n\t\t\t\t\t\t\treplaceBlock(\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tcreateBlock(\n\t\t\t\t\t\t\t\t\tblockType.name,\n\t\t\t\t\t\t\t\t\toriginalBlock.attributes,\n\t\t\t\t\t\t\t\t\toriginalBlock.innerBlocks\n\t\t\t\t\t\t\t\t)\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\t\t\t}\n\t\t\tdisabled={ isInstallingBlock }\n\t\t\tisBusy={ isInstallingBlock }\n\t\t\tvariant=\"primary\"\n\t\t>\n\t\t\t{ sprintf(\n\t\t\t\t/* translators: %s: block name */\n\t\t\t\t__( 'Install %s' ),\n\t\t\t\tblock.title\n\t\t\t) }\n\t\t</Button>\n\t);\n}\n"]}
|