@wordpress/block-directory 5.32.0 → 5.32.1-next.b8c8708f3.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.
Files changed (110) hide show
  1. package/build/components/auto-block-uninstaller/index.js +37 -31
  2. package/build/components/auto-block-uninstaller/index.js.map +7 -1
  3. package/build/components/block-ratings/index.js +40 -22
  4. package/build/components/block-ratings/index.js.map +7 -1
  5. package/build/components/block-ratings/stars.js +66 -40
  6. package/build/components/block-ratings/stars.js.map +7 -1
  7. package/build/components/compact-list/index.js +47 -46
  8. package/build/components/compact-list/index.js.map +7 -1
  9. package/build/components/downloadable-block-icon/index.js +28 -26
  10. package/build/components/downloadable-block-icon/index.js.map +7 -1
  11. package/build/components/downloadable-block-list-item/index.js +113 -127
  12. package/build/components/downloadable-block-list-item/index.js.map +7 -1
  13. package/build/components/downloadable-block-notice/index.js +41 -31
  14. package/build/components/downloadable-block-notice/index.js.map +7 -1
  15. package/build/components/downloadable-blocks-list/index.js +72 -56
  16. package/build/components/downloadable-blocks-list/index.js.map +7 -1
  17. package/build/components/downloadable-blocks-panel/index.js +108 -95
  18. package/build/components/downloadable-blocks-panel/index.js.map +7 -1
  19. package/build/components/downloadable-blocks-panel/inserter-panel.js +52 -38
  20. package/build/components/downloadable-blocks-panel/inserter-panel.js.map +7 -1
  21. package/build/components/downloadable-blocks-panel/no-results.js +37 -30
  22. package/build/components/downloadable-blocks-panel/no-results.js.map +7 -1
  23. package/build/index.js +27 -12
  24. package/build/index.js.map +7 -1
  25. package/build/lock-unlock.js +31 -15
  26. package/build/lock-unlock.js.map +7 -1
  27. package/build/plugins/get-install-missing/index.js +123 -102
  28. package/build/plugins/get-install-missing/index.js.map +7 -1
  29. package/build/plugins/get-install-missing/install-button.js +68 -50
  30. package/build/plugins/get-install-missing/install-button.js.map +7 -1
  31. package/build/plugins/index.js +46 -29
  32. package/build/plugins/index.js.map +7 -1
  33. package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js +55 -42
  34. package/build/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +7 -1
  35. package/build/plugins/installed-blocks-pre-publish-panel/index.js +65 -34
  36. package/build/plugins/installed-blocks-pre-publish-panel/index.js.map +7 -1
  37. package/build/store/actions.js +142 -188
  38. package/build/store/actions.js.map +7 -1
  39. package/build/store/index.js +48 -46
  40. package/build/store/index.js.map +7 -1
  41. package/build/store/load-assets.js +48 -55
  42. package/build/store/load-assets.js.map +7 -1
  43. package/build/store/reducer.js +48 -54
  44. package/build/store/reducer.js.map +7 -1
  45. package/build/store/resolvers.js +52 -31
  46. package/build/store/resolvers.js.map +7 -1
  47. package/build/store/selectors.js +100 -127
  48. package/build/store/selectors.js.map +7 -1
  49. package/build/store/utils/get-plugin-url.js +23 -14
  50. package/build/store/utils/get-plugin-url.js.map +7 -1
  51. package/build-module/components/auto-block-uninstaller/index.js +18 -24
  52. package/build-module/components/auto-block-uninstaller/index.js.map +7 -1
  53. package/build-module/components/block-ratings/index.js +9 -15
  54. package/build-module/components/block-ratings/index.js.map +7 -1
  55. package/build-module/components/block-ratings/stars.js +48 -34
  56. package/build-module/components/block-ratings/stars.js.map +7 -1
  57. package/build-module/components/compact-list/index.js +19 -39
  58. package/build-module/components/compact-list/index.js.map +7 -1
  59. package/build-module/components/downloadable-block-icon/index.js +10 -20
  60. package/build-module/components/downloadable-block-icon/index.js.map +7 -1
  61. package/build-module/components/downloadable-block-list-item/index.js +89 -120
  62. package/build-module/components/downloadable-block-list-item/index.js.map +7 -1
  63. package/build-module/components/downloadable-block-notice/index.js +19 -24
  64. package/build-module/components/downloadable-block-notice/index.js.map +7 -1
  65. package/build-module/components/downloadable-blocks-list/index.js +44 -49
  66. package/build-module/components/downloadable-blocks-list/index.js.map +7 -1
  67. package/build-module/components/downloadable-blocks-panel/index.js +81 -89
  68. package/build-module/components/downloadable-blocks-panel/index.js.map +7 -1
  69. package/build-module/components/downloadable-blocks-panel/inserter-panel.js +33 -31
  70. package/build-module/components/downloadable-blocks-panel/inserter-panel.js.map +7 -1
  71. package/build-module/components/downloadable-blocks-panel/no-results.js +19 -24
  72. package/build-module/components/downloadable-blocks-panel/no-results.js.map +7 -1
  73. package/build-module/index.js +6 -6
  74. package/build-module/index.js.map +7 -1
  75. package/build-module/lock-unlock.js +8 -7
  76. package/build-module/lock-unlock.js.map +7 -1
  77. package/build-module/plugins/get-install-missing/index.js +99 -95
  78. package/build-module/plugins/get-install-missing/index.js.map +7 -1
  79. package/build-module/plugins/get-install-missing/install-button.js +50 -44
  80. package/build-module/plugins/get-install-missing/install-button.js.map +7 -1
  81. package/build-module/plugins/index.js +24 -25
  82. package/build-module/plugins/index.js.map +7 -1
  83. package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js +26 -34
  84. package/build-module/plugins/inserter-menu-downloadable-blocks-panel/index.js.map +7 -1
  85. package/build-module/plugins/installed-blocks-pre-publish-panel/index.js +38 -28
  86. package/build-module/plugins/installed-blocks-pre-publish-panel/index.js.map +7 -1
  87. package/build-module/store/actions.js +100 -168
  88. package/build-module/store/actions.js.map +7 -1
  89. package/build-module/store/index.js +13 -36
  90. package/build-module/store/index.js.map +7 -1
  91. package/build-module/store/load-assets.js +15 -47
  92. package/build-module/store/load-assets.js.map +7 -1
  93. package/build-module/store/reducer.js +27 -49
  94. package/build-module/store/reducer.js.map +7 -1
  95. package/build-module/store/resolvers.js +16 -19
  96. package/build-module/store/resolvers.js.map +7 -1
  97. package/build-module/store/selectors.js +77 -121
  98. package/build-module/store/selectors.js.map +7 -1
  99. package/build-module/store/utils/get-plugin-url.js +6 -10
  100. package/build-module/store/utils/get-plugin-url.js.map +7 -1
  101. package/build-style/style-rtl.css +9 -142
  102. package/build-style/style.css +9 -142
  103. package/package.json +28 -21
  104. package/src/components/block-ratings/style.scss +2 -0
  105. package/src/components/compact-list/style.scss +3 -0
  106. package/src/components/downloadable-block-icon/style.scss +3 -0
  107. package/src/components/downloadable-block-list-item/style.scss +4 -0
  108. package/src/components/downloadable-block-notice/style.scss +3 -0
  109. package/src/components/downloadable-blocks-panel/style.scss +3 -1
  110. package/src/style.scss +8 -7
@@ -1,140 +1,115 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { store as blocksStore, unstable__bootstrapServerSideBlockDefinitions // eslint-disable-line camelcase
5
- } from '@wordpress/blocks';
6
- import { __, sprintf } from '@wordpress/i18n';
7
- import apiFetch from '@wordpress/api-fetch';
8
- import { store as noticesStore } from '@wordpress/notices';
9
- import { addQueryArgs } from '@wordpress/url';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import { loadAssets } from './load-assets';
15
- import getPluginUrl from './utils/get-plugin-url';
16
-
17
- /**
18
- * Returns an action object used in signalling that the downloadable blocks
19
- * have been requested and are loading.
20
- *
21
- * @param {string} filterValue Search string.
22
- *
23
- * @return {Object} Action object.
24
- */
25
- export function fetchDownloadableBlocks(filterValue) {
26
- return {
27
- type: 'FETCH_DOWNLOADABLE_BLOCKS',
28
- filterValue
29
- };
1
+ import {
2
+ store as blocksStore,
3
+ unstable__bootstrapServerSideBlockDefinitions
4
+ } from "@wordpress/blocks";
5
+ import { __, sprintf } from "@wordpress/i18n";
6
+ import apiFetch from "@wordpress/api-fetch";
7
+ import { store as noticesStore } from "@wordpress/notices";
8
+ import { addQueryArgs } from "@wordpress/url";
9
+ import { loadAssets } from "./load-assets";
10
+ import getPluginUrl from "./utils/get-plugin-url";
11
+ function fetchDownloadableBlocks(filterValue) {
12
+ return { type: "FETCH_DOWNLOADABLE_BLOCKS", filterValue };
30
13
  }
31
-
32
- /**
33
- * Returns an action object used in signalling that the downloadable blocks
34
- * have been updated.
35
- *
36
- * @param {Array} downloadableBlocks Downloadable blocks.
37
- * @param {string} filterValue Search string.
38
- *
39
- * @return {Object} Action object.
40
- */
41
- export function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
14
+ function receiveDownloadableBlocks(downloadableBlocks, filterValue) {
42
15
  return {
43
- type: 'RECEIVE_DOWNLOADABLE_BLOCKS',
16
+ type: "RECEIVE_DOWNLOADABLE_BLOCKS",
44
17
  downloadableBlocks,
45
18
  filterValue
46
19
  };
47
20
  }
48
-
49
- /**
50
- * Action triggered to install a block plugin.
51
- *
52
- * @param {Object} block The block item returned by search.
53
- *
54
- * @return {boolean} Whether the block was successfully installed & loaded.
55
- */
56
- export const installBlockType = block => async ({
57
- registry,
58
- dispatch
59
- }) => {
60
- const {
61
- id,
62
- name
63
- } = block;
21
+ const installBlockType = (block) => async ({ registry, dispatch }) => {
22
+ const { id, name } = block;
64
23
  let success = false;
65
24
  dispatch.clearErrorNotice(id);
66
25
  try {
67
26
  dispatch.setIsInstalling(id, true);
68
-
69
- // If we have a wp:plugin link, the plugin is installed but inactive.
70
27
  const url = getPluginUrl(block);
71
28
  let links = {};
72
29
  if (url) {
73
30
  await apiFetch({
74
- method: 'PUT',
31
+ method: "PUT",
75
32
  url,
76
- data: {
77
- status: 'active'
78
- }
33
+ data: { status: "active" }
79
34
  });
80
35
  } else {
81
36
  const response = await apiFetch({
82
- method: 'POST',
83
- path: 'wp/v2/plugins',
84
- data: {
85
- slug: id,
86
- status: 'active'
87
- }
37
+ method: "POST",
38
+ path: "wp/v2/plugins",
39
+ data: { slug: id, status: "active" }
88
40
  });
89
- // Add the `self` link for newly-installed blocks.
90
41
  links = response._links;
91
42
  }
92
43
  dispatch.addInstalledBlockType({
93
44
  ...block,
94
- links: {
95
- ...block.links,
96
- ...links
97
- }
45
+ links: { ...block.links, ...links }
98
46
  });
99
-
100
- // Ensures that the block metadata is propagated to the editor when registered on the server.
101
- const metadataFields = ['api_version', 'title', 'category', 'parent', 'ancestor', 'icon', 'description', 'keywords', 'attributes', 'provides_context', 'uses_context', 'selectors', 'supports', 'styles', 'example', 'variations', 'allowed_blocks', 'block_hooks'];
47
+ const metadataFields = [
48
+ "api_version",
49
+ "title",
50
+ "category",
51
+ "parent",
52
+ "ancestor",
53
+ "icon",
54
+ "description",
55
+ "keywords",
56
+ "attributes",
57
+ "provides_context",
58
+ "uses_context",
59
+ "selectors",
60
+ "supports",
61
+ "styles",
62
+ "example",
63
+ "variations",
64
+ "allowed_blocks",
65
+ "block_hooks"
66
+ ];
102
67
  await apiFetch({
103
68
  path: addQueryArgs(`/wp/v2/block-types/${name}`, {
104
69
  _fields: metadataFields
105
70
  })
106
- })
107
- // Ignore when the block is not registered on the server.
108
- .catch(() => {}).then(response => {
71
+ }).catch(() => {
72
+ }).then((response) => {
109
73
  if (!response) {
110
74
  return;
111
75
  }
112
76
  unstable__bootstrapServerSideBlockDefinitions({
113
- [name]: Object.fromEntries(Object.entries(response).filter(([key]) => metadataFields.includes(key)))
77
+ [name]: Object.fromEntries(
78
+ Object.entries(response).filter(
79
+ ([key]) => metadataFields.includes(key)
80
+ )
81
+ )
114
82
  });
115
83
  });
116
84
  await loadAssets();
117
85
  const registeredBlocks = registry.select(blocksStore).getBlockTypes();
118
- if (!registeredBlocks.some(i => i.name === name)) {
119
- throw new Error(__('Error registering block. Try reloading the page.'));
86
+ if (!registeredBlocks.some((i) => i.name === name)) {
87
+ throw new Error(
88
+ __("Error registering block. Try reloading the page.")
89
+ );
120
90
  }
121
- registry.dispatch(noticesStore).createInfoNotice(sprintf(
122
- // translators: %s is the block title.
123
- __('Block %s installed and added.'), block.title), {
124
- speak: true,
125
- type: 'snackbar'
126
- });
91
+ registry.dispatch(noticesStore).createInfoNotice(
92
+ sprintf(
93
+ // translators: %s is the block title.
94
+ __("Block %s installed and added."),
95
+ block.title
96
+ ),
97
+ {
98
+ speak: true,
99
+ type: "snackbar"
100
+ }
101
+ );
127
102
  success = true;
128
103
  } catch (error) {
129
- let message = error.message || __('An error occurred.');
130
-
131
- // Errors we throw are fatal.
104
+ let message = error.message || __("An error occurred.");
132
105
  let isFatal = error instanceof Error;
133
-
134
- // Specific API errors that are fatal.
135
106
  const fatalAPIErrors = {
136
- folder_exists: __('This block is already installed. Try reloading the page.'),
137
- unable_to_connect_to_filesystem: __('Error installing block. You can reload the page and try again.')
107
+ folder_exists: __(
108
+ "This block is already installed. Try reloading the page."
109
+ ),
110
+ unable_to_connect_to_filesystem: __(
111
+ "Error installing block. You can reload the page and try again."
112
+ )
138
113
  };
139
114
  if (fatalAPIErrors[error.code]) {
140
115
  isFatal = true;
@@ -149,110 +124,67 @@ export const installBlockType = block => async ({
149
124
  dispatch.setIsInstalling(id, false);
150
125
  return success;
151
126
  };
152
-
153
- /**
154
- * Action triggered to uninstall a block plugin.
155
- *
156
- * @param {Object} block The blockType object.
157
- */
158
- export const uninstallBlockType = block => async ({
159
- registry,
160
- dispatch
161
- }) => {
127
+ const uninstallBlockType = (block) => async ({ registry, dispatch }) => {
162
128
  try {
163
129
  const url = getPluginUrl(block);
164
130
  await apiFetch({
165
- method: 'PUT',
131
+ method: "PUT",
166
132
  url,
167
- data: {
168
- status: 'inactive'
169
- }
133
+ data: { status: "inactive" }
170
134
  });
171
135
  await apiFetch({
172
- method: 'DELETE',
136
+ method: "DELETE",
173
137
  url
174
138
  });
175
139
  dispatch.removeInstalledBlockType(block);
176
140
  } catch (error) {
177
- registry.dispatch(noticesStore).createErrorNotice(error.message || __('An error occurred.'));
141
+ registry.dispatch(noticesStore).createErrorNotice(
142
+ error.message || __("An error occurred.")
143
+ );
178
144
  }
179
145
  };
180
-
181
- /**
182
- * Returns an action object used to add a block type to the "newly installed"
183
- * tracking list.
184
- *
185
- * @param {Object} item The block item with the block id and name.
186
- *
187
- * @return {Object} Action object.
188
- */
189
- export function addInstalledBlockType(item) {
146
+ function addInstalledBlockType(item) {
190
147
  return {
191
- type: 'ADD_INSTALLED_BLOCK_TYPE',
148
+ type: "ADD_INSTALLED_BLOCK_TYPE",
192
149
  item
193
150
  };
194
151
  }
195
-
196
- /**
197
- * Returns an action object used to remove a block type from the "newly installed"
198
- * tracking list.
199
- *
200
- * @param {string} item The block item with the block id and name.
201
- *
202
- * @return {Object} Action object.
203
- */
204
- export function removeInstalledBlockType(item) {
152
+ function removeInstalledBlockType(item) {
205
153
  return {
206
- type: 'REMOVE_INSTALLED_BLOCK_TYPE',
154
+ type: "REMOVE_INSTALLED_BLOCK_TYPE",
207
155
  item
208
156
  };
209
157
  }
210
-
211
- /**
212
- * Returns an action object used to indicate install in progress.
213
- *
214
- * @param {string} blockId
215
- * @param {boolean} isInstalling
216
- *
217
- * @return {Object} Action object.
218
- */
219
- export function setIsInstalling(blockId, isInstalling) {
158
+ function setIsInstalling(blockId, isInstalling) {
220
159
  return {
221
- type: 'SET_INSTALLING_BLOCK',
160
+ type: "SET_INSTALLING_BLOCK",
222
161
  blockId,
223
162
  isInstalling
224
163
  };
225
164
  }
226
-
227
- /**
228
- * Sets an error notice to be displayed to the user for a given block.
229
- *
230
- * @param {string} blockId The ID of the block plugin. eg: my-block
231
- * @param {string} message The message shown in the notice.
232
- * @param {boolean} isFatal Whether the user can recover from the error.
233
- *
234
- * @return {Object} Action object.
235
- */
236
- export function setErrorNotice(blockId, message, isFatal = false) {
165
+ function setErrorNotice(blockId, message, isFatal = false) {
237
166
  return {
238
- type: 'SET_ERROR_NOTICE',
167
+ type: "SET_ERROR_NOTICE",
239
168
  blockId,
240
169
  message,
241
170
  isFatal
242
171
  };
243
172
  }
244
-
245
- /**
246
- * Sets the error notice to empty for specific block.
247
- *
248
- * @param {string} blockId The ID of the block plugin. eg: my-block
249
- *
250
- * @return {Object} Action object.
251
- */
252
- export function clearErrorNotice(blockId) {
173
+ function clearErrorNotice(blockId) {
253
174
  return {
254
- type: 'CLEAR_ERROR_NOTICE',
175
+ type: "CLEAR_ERROR_NOTICE",
255
176
  blockId
256
177
  };
257
178
  }
258
- //# sourceMappingURL=actions.js.map
179
+ export {
180
+ addInstalledBlockType,
181
+ clearErrorNotice,
182
+ fetchDownloadableBlocks,
183
+ installBlockType,
184
+ receiveDownloadableBlocks,
185
+ removeInstalledBlockType,
186
+ setErrorNotice,
187
+ setIsInstalling,
188
+ uninstallBlockType
189
+ };
190
+ //# sourceMappingURL=actions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["store","blocksStore","unstable__bootstrapServerSideBlockDefinitions","__","sprintf","apiFetch","noticesStore","addQueryArgs","loadAssets","getPluginUrl","fetchDownloadableBlocks","filterValue","type","receiveDownloadableBlocks","downloadableBlocks","installBlockType","block","registry","dispatch","id","name","success","clearErrorNotice","setIsInstalling","url","links","method","data","status","response","path","slug","_links","addInstalledBlockType","metadataFields","_fields","catch","then","Object","fromEntries","entries","filter","key","includes","registeredBlocks","select","getBlockTypes","some","i","Error","createInfoNotice","title","speak","error","message","isFatal","fatalAPIErrors","folder_exists","unable_to_connect_to_filesystem","code","setErrorNotice","createErrorNotice","isDismissible","uninstallBlockType","removeInstalledBlockType","item","blockId","isInstalling"],"sources":["@wordpress/block-directory/src/store/actions.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tstore as blocksStore,\n\tunstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase\n} from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { loadAssets } from './load-assets';\nimport getPluginUrl from './utils/get-plugin-url';\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been requested and are loading.\n *\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function fetchDownloadableBlocks( filterValue ) {\n\treturn { type: 'FETCH_DOWNLOADABLE_BLOCKS', filterValue };\n}\n\n/**\n * Returns an action object used in signalling that the downloadable blocks\n * have been updated.\n *\n * @param {Array} downloadableBlocks Downloadable blocks.\n * @param {string} filterValue Search string.\n *\n * @return {Object} Action object.\n */\nexport function receiveDownloadableBlocks( downloadableBlocks, filterValue ) {\n\treturn {\n\t\ttype: 'RECEIVE_DOWNLOADABLE_BLOCKS',\n\t\tdownloadableBlocks,\n\t\tfilterValue,\n\t};\n}\n\n/**\n * Action triggered to install a block plugin.\n *\n * @param {Object} block The block item returned by search.\n *\n * @return {boolean} Whether the block was successfully installed & loaded.\n */\nexport const installBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\tconst { id, name } = block;\n\t\tlet success = false;\n\t\tdispatch.clearErrorNotice( id );\n\t\ttry {\n\t\t\tdispatch.setIsInstalling( id, true );\n\n\t\t\t// If we have a wp:plugin link, the plugin is installed but inactive.\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tlet links = {};\n\t\t\tif ( url ) {\n\t\t\t\tawait apiFetch( {\n\t\t\t\t\tmethod: 'PUT',\n\t\t\t\t\turl,\n\t\t\t\t\tdata: { status: 'active' },\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tpath: 'wp/v2/plugins',\n\t\t\t\t\tdata: { slug: id, status: 'active' },\n\t\t\t\t} );\n\t\t\t\t// Add the `self` link for newly-installed blocks.\n\t\t\t\tlinks = response._links;\n\t\t\t}\n\n\t\t\tdispatch.addInstalledBlockType( {\n\t\t\t\t...block,\n\t\t\t\tlinks: { ...block.links, ...links },\n\t\t\t} );\n\n\t\t\t// Ensures that the block metadata is propagated to the editor when registered on the server.\n\t\t\tconst metadataFields = [\n\t\t\t\t'api_version',\n\t\t\t\t'title',\n\t\t\t\t'category',\n\t\t\t\t'parent',\n\t\t\t\t'ancestor',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'selectors',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t\t'allowed_blocks',\n\t\t\t\t'block_hooks',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,KAAK,IAAIC,WAAW,EACpBC,6CAA6C,CAAE;AAAA,OACzC,mBAAmB;AAC1B,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,YAAY,QAAQ,gBAAgB;;AAE7C;AACA;AACA;AACA,SAASC,UAAU,QAAQ,eAAe;AAC1C,OAAOC,YAAY,MAAM,wBAAwB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAAEC,WAAW,EAAG;EACtD,OAAO;IAAEC,IAAI,EAAE,2BAA2B;IAAED;EAAY,CAAC;AAC1D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,yBAAyBA,CAAEC,kBAAkB,EAAEH,WAAW,EAAG;EAC5E,OAAO;IACNC,IAAI,EAAE,6BAA6B;IACnCE,kBAAkB;IAClBH;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA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S8B,qBAAqBA,CAAEgC,IAAI,EAAG;EAC7C,OAAO;IACNrD,IAAI,EAAE,0BAA0B;IAChCqD;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASD,wBAAwBA,CAAEC,IAAI,EAAG;EAChD,OAAO;IACNrD,IAAI,EAAE,6BAA6B;IACnCqD;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS1C,eAAeA,CAAE2C,OAAO,EAAEC,YAAY,EAAG;EACxD,OAAO;IACNvD,IAAI,EAAE,sBAAsB;IAC5BsD,OAAO;IACPC;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASP,cAAcA,CAAEM,OAAO,EAAEZ,OAAO,EAAEC,OAAO,GAAG,KAAK,EAAG;EACnE,OAAO;IACN3C,IAAI,EAAE,kBAAkB;IACxBsD,OAAO;IACPZ,OAAO;IACPC;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASjC,gBAAgBA,CAAE4C,OAAO,EAAG;EAC3C,OAAO;IACNtD,IAAI,EAAE,oBAAoB;IAC1BsD;EACD,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/actions.js"],
4
+ "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'ancestor',\n\t\t\t\t'icon',\n\t\t\t\t'description',\n\t\t\t\t'keywords',\n\t\t\t\t'attributes',\n\t\t\t\t'provides_context',\n\t\t\t\t'uses_context',\n\t\t\t\t'selectors',\n\t\t\t\t'supports',\n\t\t\t\t'styles',\n\t\t\t\t'example',\n\t\t\t\t'variations',\n\t\t\t\t'allowed_blocks',\n\t\t\t\t'block_hooks',\n\t\t\t];\n\t\t\tawait apiFetch( {\n\t\t\t\tpath: addQueryArgs( `/wp/v2/block-types/${ name }`, {\n\t\t\t\t\t_fields: metadataFields,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t// Ignore when the block is not registered on the server.\n\t\t\t\t.catch( () => {} )\n\t\t\t\t.then( ( response ) => {\n\t\t\t\t\tif ( ! response ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tunstable__bootstrapServerSideBlockDefinitions( {\n\t\t\t\t\t\t[ name ]: Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries( response ).filter( ( [ key ] ) =>\n\t\t\t\t\t\t\t\tmetadataFields.includes( key )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\tawait loadAssets();\n\t\t\tconst registeredBlocks = registry\n\t\t\t\t.select( blocksStore )\n\t\t\t\t.getBlockTypes();\n\t\t\tif ( ! registeredBlocks.some( ( i ) => i.name === name ) ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t__( 'Error registering block. Try reloading the page.' )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tregistry.dispatch( noticesStore ).createInfoNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s is the block title.\n\t\t\t\t\t__( 'Block %s installed and added.' ),\n\t\t\t\t\tblock.title\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\tspeak: true,\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t\tsuccess = true;\n\t\t} catch ( error ) {\n\t\t\tlet message = error.message || __( 'An error occurred.' );\n\n\t\t\t// Errors we throw are fatal.\n\t\t\tlet isFatal = error instanceof Error;\n\n\t\t\t// Specific API errors that are fatal.\n\t\t\tconst fatalAPIErrors = {\n\t\t\t\tfolder_exists: __(\n\t\t\t\t\t'This block is already installed. Try reloading the page.'\n\t\t\t\t),\n\t\t\t\tunable_to_connect_to_filesystem: __(\n\t\t\t\t\t'Error installing block. You can reload the page and try again.'\n\t\t\t\t),\n\t\t\t};\n\n\t\t\tif ( fatalAPIErrors[ error.code ] ) {\n\t\t\t\tisFatal = true;\n\t\t\t\tmessage = fatalAPIErrors[ error.code ];\n\t\t\t}\n\n\t\t\tdispatch.setErrorNotice( id, message, isFatal );\n\t\t\tregistry.dispatch( noticesStore ).createErrorNotice( message, {\n\t\t\t\tspeak: true,\n\t\t\t\tisDismissible: true,\n\t\t\t} );\n\t\t}\n\t\tdispatch.setIsInstalling( id, false );\n\t\treturn success;\n\t};\n\n/**\n * Action triggered to uninstall a block plugin.\n *\n * @param {Object} block The blockType object.\n */\nexport const uninstallBlockType =\n\t( block ) =>\n\tasync ( { registry, dispatch } ) => {\n\t\ttry {\n\t\t\tconst url = getPluginUrl( block );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'PUT',\n\t\t\t\turl,\n\t\t\t\tdata: { status: 'inactive' },\n\t\t\t} );\n\t\t\tawait apiFetch( {\n\t\t\t\tmethod: 'DELETE',\n\t\t\t\turl,\n\t\t\t} );\n\t\t\tdispatch.removeInstalledBlockType( block );\n\t\t} catch ( error ) {\n\t\t\tregistry\n\t\t\t\t.dispatch( noticesStore )\n\t\t\t\t.createErrorNotice(\n\t\t\t\t\terror.message || __( 'An error occurred.' )\n\t\t\t\t);\n\t\t}\n\t};\n\n/**\n * Returns an action object used to add a block type to the \"newly installed\"\n * tracking list.\n *\n * @param {Object} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function addInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'ADD_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to remove a block type from the \"newly installed\"\n * tracking list.\n *\n * @param {string} item The block item with the block id and name.\n *\n * @return {Object} Action object.\n */\nexport function removeInstalledBlockType( item ) {\n\treturn {\n\t\ttype: 'REMOVE_INSTALLED_BLOCK_TYPE',\n\t\titem,\n\t};\n}\n\n/**\n * Returns an action object used to indicate install in progress.\n *\n * @param {string} blockId\n * @param {boolean} isInstalling\n *\n * @return {Object} Action object.\n */\nexport function setIsInstalling( blockId, isInstalling ) {\n\treturn {\n\t\ttype: 'SET_INSTALLING_BLOCK',\n\t\tblockId,\n\t\tisInstalling,\n\t};\n}\n\n/**\n * Sets an error notice to be displayed to the user for a given block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n * @param {string} message The message shown in the notice.\n * @param {boolean} isFatal Whether the user can recover from the error.\n *\n * @return {Object} Action object.\n */\nexport function setErrorNotice( blockId, message, isFatal = false ) {\n\treturn {\n\t\ttype: 'SET_ERROR_NOTICE',\n\t\tblockId,\n\t\tmessage,\n\t\tisFatal,\n\t};\n}\n\n/**\n * Sets the error notice to empty for specific block.\n *\n * @param {string} blockId The ID of the block plugin. eg: my-block\n *\n * @return {Object} Action object.\n */\nexport function clearErrorNotice( blockId ) {\n\treturn {\n\t\ttype: 'CLEAR_ERROR_NOTICE',\n\t\tblockId,\n\t};\n}\n"],
5
+ "mappings": "AAGA;AAAA,EACC,SAAS;AAAA,EACT;AAAA,OACM;AACP,SAAS,IAAI,eAAe;AAC5B,OAAO,cAAc;AACrB,SAAS,SAAS,oBAAoB;AACtC,SAAS,oBAAoB;AAK7B,SAAS,kBAAkB;AAC3B,OAAO,kBAAkB;AAUlB,SAAS,wBAAyB,aAAc;AACtD,SAAO,EAAE,MAAM,6BAA6B,YAAY;AACzD;AAWO,SAAS,0BAA2B,oBAAoB,aAAc;AAC5E,SAAO;AAA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Q;AAAA,MACR;AAAA,IACD,CAAE;AACF,aAAS,yBAA0B,KAAM;AAAA,EAC1C,SAAU,OAAQ;AACjB,aACE,SAAU,YAAa,EACvB;AAAA,MACA,MAAM,WAAW,GAAI,oBAAqB;AAAA,IAC3C;AAAA,EACF;AACD;AAUM,SAAS,sBAAuB,MAAO;AAC7C,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,yBAA0B,MAAO;AAChD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;AAUO,SAAS,gBAAiB,SAAS,cAAe;AACxD,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAWO,SAAS,eAAgB,SAAS,SAAS,UAAU,OAAQ;AACnE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AASO,SAAS,iBAAkB,SAAU;AAC3C,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1,42 +1,19 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createReduxStore, register } from '@wordpress/data';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import reducer from './reducer';
10
- import * as selectors from './selectors';
11
- import * as actions from './actions';
12
- import * as resolvers from './resolvers';
13
-
14
- /**
15
- * Module Constants
16
- */
17
- const STORE_NAME = 'core/block-directory';
18
-
19
- /**
20
- * Block editor data store configuration.
21
- *
22
- * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore
23
- *
24
- * @type {Object}
25
- */
26
- export const storeConfig = {
1
+ import { createReduxStore, register } from "@wordpress/data";
2
+ import reducer from "./reducer";
3
+ import * as selectors from "./selectors";
4
+ import * as actions from "./actions";
5
+ import * as resolvers from "./resolvers";
6
+ const STORE_NAME = "core/block-directory";
7
+ const storeConfig = {
27
8
  reducer,
28
9
  selectors,
29
10
  actions,
30
11
  resolvers
31
12
  };
32
-
33
- /**
34
- * Store definition for the block directory namespace.
35
- *
36
- * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
37
- *
38
- * @type {Object}
39
- */
40
- export const store = createReduxStore(STORE_NAME, storeConfig);
13
+ const store = createReduxStore(STORE_NAME, storeConfig);
41
14
  register(store);
42
- //# sourceMappingURL=index.js.map
15
+ export {
16
+ store,
17
+ storeConfig
18
+ };
19
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createReduxStore","register","reducer","selectors","actions","resolvers","STORE_NAME","storeConfig","store"],"sources":["@wordpress/block-directory/src/store/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\n\n/**\n * Module Constants\n */\nconst STORE_NAME = 'core/block-directory';\n\n/**\n * Block editor data store configuration.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#registerStore\n *\n * @type {Object}\n */\nexport const storeConfig = {\n\treducer,\n\tselectors,\n\tactions,\n\tresolvers,\n};\n\n/**\n * Store definition for the block directory namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig );\n\nregister( store );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aAAa;;AAExC;AACA;AACA;AACA,MAAMC,UAAU,GAAG,sBAAsB;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAG;EAC1BL,OAAO;EACPC,SAAS;EACTC,OAAO;EACPC;AACD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,KAAK,GAAGR,gBAAgB,CAAEM,UAAU,EAAEC,WAAY,CAAC;AAEhEN,QAAQ,CAAEO,KAAM,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/index.js"],
4
+ "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"],
5
+ "mappings": "AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,aAAa;AACzB,YAAY,eAAe;AAK3B,MAAM,aAAa;AASZ,MAAM,cAAc;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AASO,MAAM,QAAQ,iBAAkB,YAAY,WAAY;AAE/D,SAAU,KAAM;",
6
+ "names": []
7
+ }
@@ -1,71 +1,39 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import apiFetch from '@wordpress/api-fetch';
5
-
6
- /**
7
- * Load an asset for a block.
8
- *
9
- * This function returns a Promise that will resolve once the asset is loaded,
10
- * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.
11
- *
12
- * @param {HTMLElement} el A HTML Element asset to inject.
13
- *
14
- * @return {Promise} Promise which will resolve when the asset is loaded.
15
- */
16
- export const loadAsset = el => {
1
+ import apiFetch from "@wordpress/api-fetch";
2
+ const loadAsset = (el) => {
17
3
  return new Promise((resolve, reject) => {
18
- /*
19
- * Reconstruct the passed element, this is required as inserting the Node directly
20
- * won't always fire the required onload events, even if the asset wasn't already loaded.
21
- */
22
4
  const newNode = document.createElement(el.nodeName);
23
- ['id', 'rel', 'src', 'href', 'type'].forEach(attr => {
5
+ ["id", "rel", "src", "href", "type"].forEach((attr) => {
24
6
  if (el[attr]) {
25
7
  newNode[attr] = el[attr];
26
8
  }
27
9
  });
28
-
29
- // Append inline <script> contents.
30
10
  if (el.innerHTML) {
31
11
  newNode.appendChild(document.createTextNode(el.innerHTML));
32
12
  }
33
13
  newNode.onload = () => resolve(true);
34
- newNode.onerror = () => reject(new Error('Error loading asset.'));
14
+ newNode.onerror = () => reject(new Error("Error loading asset."));
35
15
  document.body.appendChild(newNode);
36
-
37
- // Resolve Stylesheets and Inline JavaScript immediately.
38
- if ('link' === newNode.nodeName.toLowerCase() || 'script' === newNode.nodeName.toLowerCase() && !newNode.src) {
16
+ if ("link" === newNode.nodeName.toLowerCase() || "script" === newNode.nodeName.toLowerCase() && !newNode.src) {
39
17
  resolve();
40
18
  }
41
19
  });
42
20
  };
43
-
44
- /**
45
- * Load the asset files for a block
46
- */
47
- export async function loadAssets() {
48
- /*
49
- * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the
50
- * JavaScript and CSS assets loaded between the pages. This imports the required assets
51
- * for the block into the current page while not requiring that we know them up-front.
52
- * In the future this can be improved by reliance upon block.json and/or a script-loader
53
- * dependency API.
54
- */
21
+ async function loadAssets() {
55
22
  const response = await apiFetch({
56
23
  url: document.location.href,
57
24
  parse: false
58
25
  });
59
26
  const data = await response.text();
60
- const doc = new window.DOMParser().parseFromString(data, 'text/html');
61
- const newAssets = Array.from(doc.querySelectorAll('link[rel="stylesheet"],script')).filter(asset => asset.id && !document.getElementById(asset.id));
62
-
63
- /*
64
- * Load each asset in order, as they may depend upon an earlier loaded script.
65
- * Stylesheets and Inline Scripts will resolve immediately upon insertion.
66
- */
27
+ const doc = new window.DOMParser().parseFromString(data, "text/html");
28
+ const newAssets = Array.from(
29
+ doc.querySelectorAll('link[rel="stylesheet"],script')
30
+ ).filter((asset) => asset.id && !document.getElementById(asset.id));
67
31
  for (const newAsset of newAssets) {
68
32
  await loadAsset(newAsset);
69
33
  }
70
34
  }
71
- //# sourceMappingURL=load-assets.js.map
35
+ export {
36
+ loadAsset,
37
+ loadAssets
38
+ };
39
+ //# sourceMappingURL=load-assets.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["apiFetch","loadAsset","el","Promise","resolve","reject","newNode","document","createElement","nodeName","forEach","attr","innerHTML","appendChild","createTextNode","onload","onerror","Error","body","toLowerCase","src","loadAssets","response","url","location","href","parse","data","text","doc","window","DOMParser","parseFromString","newAssets","Array","from","querySelectorAll","filter","asset","id","getElementById","newAsset"],"sources":["@wordpress/block-directory/src/store/load-assets.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Load an asset for a block.\n *\n * This function returns a Promise that will resolve once the asset is loaded,\n * or in the case of Stylesheets and Inline JavaScript, will resolve immediately.\n *\n * @param {HTMLElement} el A HTML Element asset to inject.\n *\n * @return {Promise} Promise which will resolve when the asset is loaded.\n */\nexport const loadAsset = ( el ) => {\n\treturn new Promise( ( resolve, reject ) => {\n\t\t/*\n\t\t * Reconstruct the passed element, this is required as inserting the Node directly\n\t\t * won't always fire the required onload events, even if the asset wasn't already loaded.\n\t\t */\n\t\tconst newNode = document.createElement( el.nodeName );\n\n\t\t[ 'id', 'rel', 'src', 'href', 'type' ].forEach( ( attr ) => {\n\t\t\tif ( el[ attr ] ) {\n\t\t\t\tnewNode[ attr ] = el[ attr ];\n\t\t\t}\n\t\t} );\n\n\t\t// Append inline <script> contents.\n\t\tif ( el.innerHTML ) {\n\t\t\tnewNode.appendChild( document.createTextNode( el.innerHTML ) );\n\t\t}\n\n\t\tnewNode.onload = () => resolve( true );\n\t\tnewNode.onerror = () => reject( new Error( 'Error loading asset.' ) );\n\n\t\tdocument.body.appendChild( newNode );\n\n\t\t// Resolve Stylesheets and Inline JavaScript immediately.\n\t\tif (\n\t\t\t'link' === newNode.nodeName.toLowerCase() ||\n\t\t\t( 'script' === newNode.nodeName.toLowerCase() && ! newNode.src )\n\t\t) {\n\t\t\tresolve();\n\t\t}\n\t} );\n};\n\n/**\n * Load the asset files for a block\n */\nexport async function loadAssets() {\n\t/*\n\t * Fetch the current URL (post-new.php, or post.php?post=1&action=edit) and compare the\n\t * JavaScript and CSS assets loaded between the pages. This imports the required assets\n\t * for the block into the current page while not requiring that we know them up-front.\n\t * In the future this can be improved by reliance upon block.json and/or a script-loader\n\t * dependency API.\n\t */\n\tconst response = await apiFetch( {\n\t\turl: document.location.href,\n\t\tparse: false,\n\t} );\n\n\tconst data = await response.text();\n\n\tconst doc = new window.DOMParser().parseFromString( data, 'text/html' );\n\n\tconst newAssets = Array.from(\n\t\tdoc.querySelectorAll( 'link[rel=\"stylesheet\"],script' )\n\t).filter( ( asset ) => asset.id && ! document.getElementById( asset.id ) );\n\n\t/*\n\t * Load each asset in order, as they may depend upon an earlier loaded script.\n\t * Stylesheets and Inline Scripts will resolve immediately upon insertion.\n\t */\n\tfor ( const newAsset of newAssets ) {\n\t\tawait loadAsset( newAsset );\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAKC,EAAE,IAAM;EAClC,OAAO,IAAIC,OAAO,CAAE,CAAEC,OAAO,EAAEC,MAAM,KAAM;IAC1C;AACF;AACA;A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M,CAACC,SAAS,CAAC,CAAC,CAACC,eAAe,CAAEL,IAAI,EAAE,WAAY,CAAC;EAEvE,MAAMM,SAAS,GAAGC,KAAK,CAACC,IAAI,CAC3BN,GAAG,CAACO,gBAAgB,CAAE,+BAAgC,CACvD,CAAC,CAACC,MAAM,CAAIC,KAAK,IAAMA,KAAK,CAACC,EAAE,IAAI,CAAEhC,QAAQ,CAACiC,cAAc,CAAEF,KAAK,CAACC,EAAG,CAAE,CAAC;;EAE1E;AACD;AACA;AACA;EACC,KAAM,MAAME,QAAQ,IAAIR,SAAS,EAAG;IACnC,MAAMhC,SAAS,CAAEwC,QAAS,CAAC;EAC5B;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/store/load-assets.js"],
4
+ "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"],
5
+ "mappings": "AAGA,OAAO,cAAc;AAYd,MAAM,YAAY,CAAE,OAAQ;AAClC,SAAO,IAAI,QAAS,CAAE,SAAS,WAAY;AAK1C,UAAM,UAAU,SAAS,cAAe,GAAG,QAAS;AAEpD,KAAE,MAAM,OAAO,OAAO,QAAQ,MAAO,EAAE,QAAS,CAAE,SAAU;AAC3D,UAAK,GAAI,IAAK,GAAI;AACjB,gBAAS,IAAK,IAAI,GAAI,IAAK;AAAA,MAC5B;AAAA,IACD,CAAE;AAGF,QAAK,GAAG,WAAY;AACnB,cAAQ,YAAa,SAAS,eAAgB,GAAG,SAAU,CAAE;AAAA,IAC9D;AAEA,YAAQ,SAAS,MAAM,QAAS,IAAK;AACrC,YAAQ,UAAU,MAAM,OAAQ,IAAI,MAAO,sBAAuB,CAAE;AAEpE,aAAS,KAAK,YAAa,OAAQ;AAGnC,QACC,WAAW,QAAQ,SAAS,YAAY,KACtC,aAAa,QAAQ,SAAS,YAAY,KAAK,CAAE,QAAQ,KAC1D;AACD,cAAQ;AAAA,IACT;AAAA,EACD,CAAE;AACH;AAKA,eAAsB,aAAa;AAQlC,QAAM,WAAW,MAAM,SAAU;AAAA,IAChC,KAAK,SAAS,SAAS;AAAA,IACvB,OAAO;AAAA,EACR,CAAE;AAEF,QAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,QAAM,MAAM,IAAI,OAAO,UAAU,EAAE,gBAAiB,MAAM,WAAY;AAEtE,QAAM,YAAY,MAAM;AAAA,IACvB,IAAI,iBAAkB,+BAAgC;AAAA,EACvD,EAAE,OAAQ,CAAE,UAAW,MAAM,MAAM,CAAE,SAAS,eAAgB,MAAM,EAAG,CAAE;AAMzE,aAAY,YAAY,WAAY;AACnC,UAAM,UAAW,QAAS;AAAA,EAC3B;AACD;",
6
+ "names": []
7
+ }