PluginProbe
Gutenberg / 12.6.0
Gutenberg v12.6.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / reusable-blocks / index.js

index.js in Gutenberg 12.6.0, at build/reusable-blocks/index.js

487 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (function() { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ !function() {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = function(exports, definition) {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ }();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ !function() {
21 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
22 /******/ }();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ !function() {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = function(exports) {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ }();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 "ReusableBlocksMenuItems": function() { return /* reexport */ reusable_blocks_menu_items; },
43 "store": function() { return /* reexport */ store; }
44 });
45
46 // NAMESPACE OBJECT: ./packages/reusable-blocks/build-module/store/actions.js
47 var actions_namespaceObject = {};
48 __webpack_require__.r(actions_namespaceObject);
49 __webpack_require__.d(actions_namespaceObject, {
50 "__experimentalConvertBlockToStatic": function() { return __experimentalConvertBlockToStatic; },
51 "__experimentalConvertBlocksToReusable": function() { return __experimentalConvertBlocksToReusable; },
52 "__experimentalDeleteReusableBlock": function() { return __experimentalDeleteReusableBlock; },
53 "__experimentalSetEditingReusableBlock": function() { return __experimentalSetEditingReusableBlock; }
54 });
55
56 // NAMESPACE OBJECT: ./packages/reusable-blocks/build-module/store/selectors.js
57 var selectors_namespaceObject = {};
58 __webpack_require__.r(selectors_namespaceObject);
59 __webpack_require__.d(selectors_namespaceObject, {
60 "__experimentalIsEditingReusableBlock": function() { return __experimentalIsEditingReusableBlock; }
61 });
62
63 ;// CONCATENATED MODULE: external ["wp","data"]
64 var external_wp_data_namespaceObject = window["wp"]["data"];
65 ;// CONCATENATED MODULE: external "lodash"
66 var external_lodash_namespaceObject = window["lodash"];
67 ;// CONCATENATED MODULE: external ["wp","blockEditor"]
68 var external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
69 ;// CONCATENATED MODULE: external ["wp","blocks"]
70 var external_wp_blocks_namespaceObject = window["wp"]["blocks"];
71 ;// CONCATENATED MODULE: external ["wp","i18n"]
72 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
73 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/store/actions.js
74 /**
75 * External dependencies
76 */
77
78 /**
79 * WordPress dependencies
80 */
81
82
83
84
85 /**
86 * Returns a generator converting a reusable block into a static block.
87 *
88 * @param {string} clientId The client ID of the block to attach.
89 */
90
91 const __experimentalConvertBlockToStatic = clientId => _ref => {
92 let {
93 registry
94 } = _ref;
95 const oldBlock = registry.select(external_wp_blockEditor_namespaceObject.store).getBlock(clientId);
96 const reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', oldBlock.attributes.ref);
97 const newBlocks = (0,external_wp_blocks_namespaceObject.parse)((0,external_lodash_namespaceObject.isFunction)(reusableBlock.content) ? reusableBlock.content(reusableBlock) : reusableBlock.content);
98 registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(oldBlock.clientId, newBlocks);
99 };
100 /**
101 * Returns a generator converting one or more static blocks into a reusable block.
102 *
103 * @param {string[]} clientIds The client IDs of the block to detach.
104 * @param {string} title Reusable block title.
105 */
106
107 const __experimentalConvertBlocksToReusable = (clientIds, title) => async _ref2 => {
108 let {
109 registry,
110 dispatch
111 } = _ref2;
112 const reusableBlock = {
113 title: title || (0,external_wp_i18n_namespaceObject.__)('Untitled Reusable block'),
114 content: (0,external_wp_blocks_namespaceObject.serialize)(registry.select(external_wp_blockEditor_namespaceObject.store).getBlocksByClientId(clientIds)),
115 status: 'publish'
116 };
117 const updatedRecord = await registry.dispatch('core').saveEntityRecord('postType', 'wp_block', reusableBlock);
118 const newBlock = (0,external_wp_blocks_namespaceObject.createBlock)('core/block', {
119 ref: updatedRecord.id
120 });
121 registry.dispatch(external_wp_blockEditor_namespaceObject.store).replaceBlocks(clientIds, newBlock);
122
123 dispatch.__experimentalSetEditingReusableBlock(newBlock.clientId, true);
124 };
125 /**
126 * Returns a generator deleting a reusable block.
127 *
128 * @param {string} id The ID of the reusable block to delete.
129 */
130
131 const __experimentalDeleteReusableBlock = id => async _ref3 => {
132 let {
133 registry
134 } = _ref3;
135 const reusableBlock = registry.select('core').getEditedEntityRecord('postType', 'wp_block', id); // Don't allow a reusable block with a temporary ID to be deleted
136
137 if (!reusableBlock) {
138 return;
139 } // Remove any other blocks that reference this reusable block
140
141
142 const allBlocks = registry.select(external_wp_blockEditor_namespaceObject.store).getBlocks();
143 const associatedBlocks = allBlocks.filter(block => (0,external_wp_blocks_namespaceObject.isReusableBlock)(block) && block.attributes.ref === id);
144 const associatedBlockClientIds = associatedBlocks.map(block => block.clientId); // Remove the parsed block.
145
146 if (associatedBlockClientIds.length) {
147 registry.dispatch(external_wp_blockEditor_namespaceObject.store).removeBlocks(associatedBlockClientIds);
148 }
149
150 await registry.dispatch('core').deleteEntityRecord('postType', 'wp_block', id);
151 };
152 /**
153 * Returns an action descriptor for SET_EDITING_REUSABLE_BLOCK action.
154 *
155 * @param {string} clientId The clientID of the reusable block to target.
156 * @param {boolean} isEditing Whether the block should be in editing state.
157 * @return {Object} Action descriptor.
158 */
159
160 function __experimentalSetEditingReusableBlock(clientId, isEditing) {
161 return {
162 type: 'SET_EDITING_REUSABLE_BLOCK',
163 clientId,
164 isEditing
165 };
166 }
167 //# sourceMappingURL=actions.js.map
168 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/store/reducer.js
169 /**
170 * WordPress dependencies
171 */
172
173 function isEditingReusableBlock() {
174 let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
175 let action = arguments.length > 1 ? arguments[1] : undefined;
176
177 if ((action === null || action === void 0 ? void 0 : action.type) === 'SET_EDITING_REUSABLE_BLOCK') {
178 return { ...state,
179 [action.clientId]: action.isEditing
180 };
181 }
182
183 return state;
184 }
185 /* harmony default export */ var reducer = ((0,external_wp_data_namespaceObject.combineReducers)({
186 isEditingReusableBlock
187 }));
188 //# sourceMappingURL=reducer.js.map
189 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/store/selectors.js
190 /**
191 * Returns true if reusable block is in the editing state.
192 *
193 * @param {Object} state Global application state.
194 * @param {number} clientId the clientID of the block.
195 * @return {boolean} Whether the reusable block is in the editing state.
196 */
197 function __experimentalIsEditingReusableBlock(state, clientId) {
198 return state.isEditingReusableBlock[clientId];
199 }
200 //# sourceMappingURL=selectors.js.map
201 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/store/index.js
202 /**
203 * WordPress dependencies
204 */
205
206 /**
207 * Internal dependencies
208 */
209
210
211
212
213 const STORE_NAME = 'core/reusable-blocks';
214 /**
215 * Store definition for the reusable blocks namespace.
216 *
217 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
218 *
219 * @type {Object}
220 */
221
222 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
223 actions: actions_namespaceObject,
224 reducer: reducer,
225 selectors: selectors_namespaceObject,
226 __experimentalUseThunks: true
227 });
228 (0,external_wp_data_namespaceObject.register)(store);
229 //# sourceMappingURL=index.js.map
230 ;// CONCATENATED MODULE: external ["wp","element"]
231 var external_wp_element_namespaceObject = window["wp"]["element"];
232 ;// CONCATENATED MODULE: external ["wp","components"]
233 var external_wp_components_namespaceObject = window["wp"]["components"];
234 ;// CONCATENATED MODULE: external ["wp","primitives"]
235 var external_wp_primitives_namespaceObject = window["wp"]["primitives"];
236 ;// CONCATENATED MODULE: ./packages/icons/build-module/library/reusable-block.js
237
238
239 /**
240 * WordPress dependencies
241 */
242
243 const reusableBlock = (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.SVG, {
244 xmlns: "http://www.w3.org/2000/svg",
245 viewBox: "0 0 24 24"
246 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_primitives_namespaceObject.Path, {
247 d: "M7 7.2h8.2L13.5 9l1.1 1.1 3.6-3.6-3.5-4-1.1 1 1.9 2.3H7c-.9 0-1.7.3-2.3.9-1.4 1.5-1.4 4.2-1.4 5.6v.2h1.5v-.3c0-1.1 0-3.5 1-4.5.3-.3.7-.5 1.2-.5zm13.8 4V11h-1.5v.3c0 1.1 0 3.5-1 4.5-.3.3-.7.5-1.3.5H8.8l1.7-1.7-1.1-1.1L5.9 17l3.5 4 1.1-1-1.9-2.3H17c.9 0 1.7-.3 2.3-.9 1.5-1.4 1.5-4.2 1.5-5.6z"
248 }));
249 /* harmony default export */ var reusable_block = (reusableBlock);
250 //# sourceMappingURL=reusable-block.js.map
251 ;// CONCATENATED MODULE: external ["wp","notices"]
252 var external_wp_notices_namespaceObject = window["wp"]["notices"];
253 ;// CONCATENATED MODULE: external ["wp","coreData"]
254 var external_wp_coreData_namespaceObject = window["wp"]["coreData"];
255 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.js
256
257
258 /**
259 * WordPress dependencies
260 */
261
262
263
264
265
266
267
268
269
270 /**
271 * Internal dependencies
272 */
273
274
275 /**
276 * Menu control to convert block(s) to reusable block.
277 *
278 * @param {Object} props Component props.
279 * @param {string[]} props.clientIds Client ids of selected blocks.
280 * @param {string} props.rootClientId ID of the currently selected top-level block.
281 * @return {import('@wordpress/element').WPComponent} The menu control or null.
282 */
283
284 function ReusableBlockConvertButton(_ref) {
285 let {
286 clientIds,
287 rootClientId
288 } = _ref;
289 const [isModalOpen, setIsModalOpen] = (0,external_wp_element_namespaceObject.useState)(false);
290 const [title, setTitle] = (0,external_wp_element_namespaceObject.useState)('');
291 const canConvert = (0,external_wp_data_namespaceObject.useSelect)(select => {
292 var _getBlocksByClientId;
293
294 const {
295 canUser
296 } = select(external_wp_coreData_namespaceObject.store);
297 const {
298 getBlocksByClientId,
299 canInsertBlockType
300 } = select(external_wp_blockEditor_namespaceObject.store);
301 const blocks = (_getBlocksByClientId = getBlocksByClientId(clientIds)) !== null && _getBlocksByClientId !== void 0 ? _getBlocksByClientId : [];
302 const isReusable = blocks.length === 1 && blocks[0] && (0,external_wp_blocks_namespaceObject.isReusableBlock)(blocks[0]) && !!select(external_wp_coreData_namespaceObject.store).getEntityRecord('postType', 'wp_block', blocks[0].attributes.ref);
303
304 const _canConvert = // Hide when this is already a reusable block.
305 !isReusable && // Hide when reusable blocks are disabled.
306 canInsertBlockType('core/block', rootClientId) && blocks.every(block => // Guard against the case where a regular block has *just* been converted.
307 !!block && // Hide on invalid blocks.
308 block.isValid && // Hide when block doesn't support being made reusable.
309 (0,external_wp_blocks_namespaceObject.hasBlockSupport)(block.name, 'reusable', true)) && // Hide when current doesn't have permission to do that.
310 !!canUser('create', 'blocks');
311
312 return _canConvert;
313 }, [clientIds]);
314 const {
315 __experimentalConvertBlocksToReusable: convertBlocksToReusable
316 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
317 const {
318 createSuccessNotice,
319 createErrorNotice
320 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_notices_namespaceObject.store);
321 const onConvert = (0,external_wp_element_namespaceObject.useCallback)(async function (reusableBlockTitle) {
322 try {
323 await convertBlocksToReusable(clientIds, reusableBlockTitle);
324 createSuccessNotice((0,external_wp_i18n_namespaceObject.__)('Reusable block created.'), {
325 type: 'snackbar'
326 });
327 } catch (error) {
328 createErrorNotice(error.message, {
329 type: 'snackbar'
330 });
331 }
332 }, [clientIds]);
333
334 if (!canConvert) {
335 return null;
336 }
337
338 return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockSettingsMenuControls, null, _ref2 => {
339 let {
340 onClose
341 } = _ref2;
342 return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
343 icon: reusable_block,
344 onClick: () => {
345 setIsModalOpen(true);
346 }
347 }, (0,external_wp_i18n_namespaceObject.__)('Add to Reusable blocks')), isModalOpen && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Modal, {
348 title: (0,external_wp_i18n_namespaceObject.__)('Create Reusable block'),
349 closeLabel: (0,external_wp_i18n_namespaceObject.__)('Close'),
350 onRequestClose: () => {
351 setIsModalOpen(false);
352 setTitle('');
353 },
354 overlayClassName: "reusable-blocks-menu-items__convert-modal"
355 }, (0,external_wp_element_namespaceObject.createElement)("form", {
356 onSubmit: event => {
357 event.preventDefault();
358 onConvert(title);
359 setIsModalOpen(false);
360 setTitle('');
361 onClose();
362 }
363 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.TextControl, {
364 label: (0,external_wp_i18n_namespaceObject.__)('Name'),
365 value: title,
366 onChange: setTitle
367 }), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Flex, {
368 className: "reusable-blocks-menu-items__convert-modal-actions",
369 justify: "flex-end"
370 }, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.FlexItem, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
371 variant: "secondary",
372 onClick: () => {
373 setIsModalOpen(false);
374 setTitle('');
375 }
376 }, (0,external_wp_i18n_namespaceObject.__)('Cancel'))), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.FlexItem, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
377 variant: "primary",
378 type: "submit"
379 }, (0,external_wp_i18n_namespaceObject.__)('Save')))))));
380 });
381 }
382 //# sourceMappingURL=reusable-block-convert-button.js.map
383 ;// CONCATENATED MODULE: external ["wp","url"]
384 var external_wp_url_namespaceObject = window["wp"]["url"];
385 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js
386
387
388 /**
389 * WordPress dependencies
390 */
391
392
393
394
395
396
397
398 /**
399 * Internal dependencies
400 */
401
402
403
404 function ReusableBlocksManageButton(_ref) {
405 let {
406 clientId
407 } = _ref;
408 const {
409 isVisible
410 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
411 const {
412 getBlock
413 } = select(external_wp_blockEditor_namespaceObject.store);
414 const {
415 canUser
416 } = select(external_wp_coreData_namespaceObject.store);
417 const reusableBlock = getBlock(clientId);
418 return {
419 isVisible: !!reusableBlock && (0,external_wp_blocks_namespaceObject.isReusableBlock)(reusableBlock) && !!canUser('update', 'blocks', reusableBlock.attributes.ref)
420 };
421 }, [clientId]);
422 const {
423 __experimentalConvertBlockToStatic: convertBlockToStatic
424 } = (0,external_wp_data_namespaceObject.useDispatch)(store);
425
426 if (!isVisible) {
427 return null;
428 }
429
430 return (0,external_wp_element_namespaceObject.createElement)(external_wp_blockEditor_namespaceObject.BlockSettingsMenuControls, null, (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
431 href: (0,external_wp_url_namespaceObject.addQueryArgs)('edit.php', {
432 post_type: 'wp_block'
433 })
434 }, (0,external_wp_i18n_namespaceObject.__)('Manage Reusable blocks')), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.MenuItem, {
435 onClick: () => convertBlockToStatic(clientId)
436 }, (0,external_wp_i18n_namespaceObject.__)('Convert to regular blocks')));
437 }
438
439 /* harmony default export */ var reusable_blocks_manage_button = (ReusableBlocksManageButton);
440 //# sourceMappingURL=reusable-blocks-manage-button.js.map
441 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.js
442
443
444 /**
445 * WordPress dependencies
446 */
447
448
449 /**
450 * Internal dependencies
451 */
452
453
454
455
456 function ReusableBlocksMenuItems(_ref) {
457 let {
458 clientIds,
459 rootClientId
460 } = _ref;
461 return (0,external_wp_element_namespaceObject.createElement)(external_wp_element_namespaceObject.Fragment, null, (0,external_wp_element_namespaceObject.createElement)(ReusableBlockConvertButton, {
462 clientIds: clientIds,
463 rootClientId: rootClientId
464 }), clientIds.length === 1 && (0,external_wp_element_namespaceObject.createElement)(reusable_blocks_manage_button, {
465 clientId: clientIds[0]
466 }));
467 }
468
469 /* harmony default export */ var reusable_blocks_menu_items = ((0,external_wp_data_namespaceObject.withSelect)(select => {
470 const {
471 getSelectedBlockClientIds
472 } = select(external_wp_blockEditor_namespaceObject.store);
473 return {
474 clientIds: getSelectedBlockClientIds()
475 };
476 })(ReusableBlocksMenuItems));
477 //# sourceMappingURL=index.js.map
478 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/components/index.js
479
480 //# sourceMappingURL=index.js.map
481 ;// CONCATENATED MODULE: ./packages/reusable-blocks/build-module/index.js
482
483
484 //# sourceMappingURL=index.js.map
485 (window.wp = window.wp || {}).reusableBlocks = __webpack_exports__;
486 /******/ })()
487 ;