PluginProbe
Gutenberg / trunk
Gutenberg vtrunk
24.1.0 24.0.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 All 404 releases
← All changes | build/scripts/reusable-blocks/index.js +15 -414 23.9.0 → trunk View file →
@@ -38,29 +38,8 @@
38 38 module.exports = window.wp.data;
39 39 }
40 40 });
41 41
42 - // package-external:@wordpress/block-editor
43 - var require_block_editor = __commonJS({
44 - "package-external:@wordpress/block-editor"(exports, module) {
45 - module.exports = window.wp.blockEditor;
46 - }
47 - });
48 -
49 - // package-external:@wordpress/blocks
50 - var require_blocks = __commonJS({
51 - "package-external:@wordpress/blocks"(exports, module) {
52 - module.exports = window.wp.blocks;
53 - }
54 - });
55 -
56 - // package-external:@wordpress/i18n
57 - var require_i18n = __commonJS({
58 - "package-external:@wordpress/i18n"(exports, module) {
59 - module.exports = window.wp.i18n;
60 - }
61 - });
62 -
63 42 // package-external:@wordpress/deprecated
64 43 var require_deprecated = __commonJS({
65 44 "package-external:@wordpress/deprecated"(exports, module) {
66 45 module.exports = window.wp.deprecated;
@@ -66,57 +45,8 @@
66 45 module.exports = window.wp.deprecated;
67 46 }
68 47 });
69 48
70 - // package-external:@wordpress/element
71 - var require_element = __commonJS({
72 - "package-external:@wordpress/element"(exports, module) {
73 - module.exports = window.wp.element;
74 - }
75 - });
76 -
77 - // package-external:@wordpress/components
78 - var require_components = __commonJS({
79 - "package-external:@wordpress/components"(exports, module) {
80 - module.exports = window.wp.components;
81 - }
82 - });
83 -
84 - // package-external:@wordpress/primitives
85 - var require_primitives = __commonJS({
86 - "package-external:@wordpress/primitives"(exports, module) {
87 - module.exports = window.wp.primitives;
88 - }
89 - });
90 -
91 - // vendor-external:react/jsx-runtime
92 - var require_jsx_runtime = __commonJS({
93 - "vendor-external:react/jsx-runtime"(exports, module) {
94 - module.exports = window.ReactJSXRuntime;
95 - }
96 - });
97 -
98 - // package-external:@wordpress/notices
99 - var require_notices = __commonJS({
100 - "package-external:@wordpress/notices"(exports, module) {
101 - module.exports = window.wp.notices;
102 - }
103 - });
104 -
105 - // package-external:@wordpress/core-data
106 - var require_core_data = __commonJS({
107 - "package-external:@wordpress/core-data"(exports, module) {
108 - module.exports = window.wp.coreData;
109 - }
110 - });
111 -
112 - // package-external:@wordpress/url
113 - var require_url = __commonJS({
114 - "package-external:@wordpress/url"(exports, module) {
115 - module.exports = window.wp.url;
116 - }
117 - });
118 -
119 49 // packages/reusable-blocks/build-module/index.mjs
120 50 var index_exports = {};
121 51 __export(index_exports, {
122 52 ReusableBlocksMenuItems: () => ReusableBlocksMenuItems,
@@ -123,9 +53,9 @@
123 53 store: () => store
124 54 });
125 55
126 56 // packages/reusable-blocks/build-module/store/index.mjs
127 - var import_data2 = __toESM(require_data(), 1);
57 + var import_data = __toESM(require_data(), 1);
128 58
129 59 // packages/reusable-blocks/build-module/store/actions.mjs
130 60 var actions_exports = {};
131 61 __export(actions_exports, {
@@ -133,13 +63,10 @@
133 63 __experimentalConvertBlocksToReusable: () => __experimentalConvertBlocksToReusable,
134 64 __experimentalDeleteReusableBlock: () => __experimentalDeleteReusableBlock,
135 65 __experimentalSetEditingReusableBlock: () => __experimentalSetEditingReusableBlock
136 66 });
137 - var import_block_editor = __toESM(require_block_editor(), 1);
138 - var import_blocks = __toESM(require_blocks(), 1);
139 - var import_i18n = __toESM(require_i18n(), 1);
140 67 var import_deprecated = __toESM(require_deprecated(), 1);
141 - var __experimentalConvertBlockToStatic = (clientId) => ({ registry }) => {
68 + var __experimentalConvertBlockToStatic = () => () => {
142 69 (0, import_deprecated.default)(
143 70 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlockToStatic",
144 71 {
145 72 since: "7.1"
@@ -144,20 +71,10 @@
144 71 {
145 72 since: "7.1"
146 73 }
147 74 );
148 - const oldBlock = registry.select(import_block_editor.store).getBlock(clientId);
149 - const reusableBlock = registry.select("core").getEditedEntityRecord(
150 - "postType",
151 - "wp_block",
152 - oldBlock.attributes.ref
153 - );
154 - const newBlocks = (0, import_blocks.parse)(
155 - typeof reusableBlock.content === "function" ? reusableBlock.content(reusableBlock) : reusableBlock.content
156 - );
157 - registry.dispatch(import_block_editor.store).replaceBlocks(oldBlock.clientId, newBlocks);
158 75 };
159 - var __experimentalConvertBlocksToReusable = (clientIds, title, syncType) => async ({ registry, dispatch }) => {
76 + var __experimentalConvertBlocksToReusable = () => async () => {
160 77 (0, import_deprecated.default)(
161 78 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalConvertBlocksToReusable",
162 79 {
163 80 since: "7.1"
@@ -162,33 +79,10 @@
162 79 {
163 80 since: "7.1"
164 81 }
165 82 );
166 - const meta = syncType === "unsynced" ? {
167 - wp_pattern_sync_status: syncType
168 - } : void 0;
169 - const reusableBlock = {
170 - title: title || (0, import_i18n.__)("Untitled pattern block"),
171 - content: (0, import_blocks.serialize)(
172 - registry.select(import_block_editor.store).getBlocksByClientId(clientIds)
173 - ),
174 - status: "publish",
175 - meta
176 - };
177 - const updatedRecord = await registry.dispatch("core").saveEntityRecord("postType", "wp_block", reusableBlock);
178 - if (syncType === "unsynced") {
179 - return;
180 - }
181 - const newBlock = (0, import_blocks.createBlock)("core/block", {
182 - ref: updatedRecord.id
183 - });
184 - registry.dispatch(import_block_editor.store).replaceBlocks(clientIds, newBlock);
185 - dispatch.__experimentalSetEditingReusableBlock(
186 - newBlock.clientId,
187 - true
188 - );
189 83 };
190 - var __experimentalDeleteReusableBlock = (id) => async ({ registry }) => {
84 + var __experimentalDeleteReusableBlock = () => async () => {
191 85 (0, import_deprecated.default)(
192 86 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalDeleteReusableBlock",
193 87 {
194 88 since: "7.1"
@@ -193,23 +87,8 @@
193 87 {
194 88 since: "7.1"
195 89 }
196 90 );
197 - const reusableBlock = registry.select("core").getEditedEntityRecord("postType", "wp_block", id);
198 - if (!reusableBlock) {
199 - return;
200 - }
201 - const allBlocks = registry.select(import_block_editor.store).getBlocks();
202 - const associatedBlocks = allBlocks.filter(
203 - (block) => (0, import_blocks.isReusableBlock)(block) && block.attributes.ref === id
204 - );
205 - const associatedBlockClientIds = associatedBlocks.map(
206 - (block) => block.clientId
207 - );
208 - if (associatedBlockClientIds.length) {
209 - registry.dispatch(import_block_editor.store).removeBlocks(associatedBlockClientIds);
210 - }
211 - await registry.dispatch("core").deleteEntityRecord("postType", "wp_block", id);
212 91 };
213 92 function __experimentalSetEditingReusableBlock(clientId, isEditing) {
214 93 (0, import_deprecated.default)(
215 94 "wp.data.dispatch( 'core/reusable-blocks' ).__experimentalSetEditingReusableBlock",
@@ -224,21 +103,14 @@
224 103 };
225 104 }
226 105
227 106 // packages/reusable-blocks/build-module/store/reducer.mjs
228 - var import_data = __toESM(require_data(), 1);
229 - function isEditingReusableBlock(state = {}, action) {
230 - if (action?.type === "SET_EDITING_REUSABLE_BLOCK") {
231 - return {
232 - ...state,
233 - [action.clientId]: action.isEditing
234 - };
235 - }
107 + var DEFAULT_STATE = {
108 + isEditingReusableBlock: {}
109 + };
110 + function reducer(state = DEFAULT_STATE) {
236 111 return state;
237 112 }
238 - var reducer_default = (0, import_data.combineReducers)({
239 - isEditingReusableBlock
240 - });
241 113
242 114 // packages/reusable-blocks/build-module/store/selectors.mjs
243 115 var selectors_exports = {};
244 116 __export(selectors_exports, {
@@ -244,9 +116,9 @@
244 116 __export(selectors_exports, {
245 117 __experimentalIsEditingReusableBlock: () => __experimentalIsEditingReusableBlock
246 118 });
247 119 var import_deprecated2 = __toESM(require_deprecated(), 1);
248 - function __experimentalIsEditingReusableBlock(state, clientId) {
120 + function __experimentalIsEditingReusableBlock() {
249 121 (0, import_deprecated2.default)(
250 122 "wp.data.select( 'core/reusable-blocks' ).__experimentalIsEditingReusableBlock",
251 123 {
252 124 since: "7.1"
@@ -251,298 +123,27 @@
251 123 {
252 124 since: "7.1"
253 125 }
254 126 );
255 - return state.isEditingReusableBlock[clientId];
127 + return false;
256 128 }
257 129
258 130 // packages/reusable-blocks/build-module/store/index.mjs
259 131 var STORE_NAME = "core/reusable-blocks";
260 - var store = (0, import_data2.createReduxStore)(STORE_NAME, {
132 + var store = (0, import_data.createReduxStore)(STORE_NAME, {
261 133 actions: actions_exports,
262 - reducer: reducer_default,
134 + reducer,
263 135 selectors: selectors_exports
264 136 });
265 - (0, import_data2.register)(store);
137 + (0, import_data.register)(store);
266 138
267 139 // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.mjs
268 - var import_block_editor4 = __toESM(require_block_editor(), 1);
269 140 var import_deprecated3 = __toESM(require_deprecated(), 1);
270 -
271 - // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.mjs
272 - var import_blocks2 = __toESM(require_blocks(), 1);
273 - var import_block_editor2 = __toESM(require_block_editor(), 1);
274 - var import_element = __toESM(require_element(), 1);
275 - var import_components = __toESM(require_components(), 1);
276 -
277 - // packages/icons/build-module/library/symbol.mjs
278 - var import_primitives = __toESM(require_primitives(), 1);
279 - var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
280 - var symbol_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z" }) });
281 -
282 - // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-block-convert-button.mjs
283 - var import_data3 = __toESM(require_data(), 1);
284 - var import_i18n2 = __toESM(require_i18n(), 1);
285 - var import_notices = __toESM(require_notices(), 1);
286 - var import_core_data = __toESM(require_core_data(), 1);
287 - var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
288 - function ReusableBlockConvertButton({
289 - clientIds,
290 - rootClientId,
291 - onClose
292 - }) {
293 - const [syncType, setSyncType] = (0, import_element.useState)(void 0);
294 - const [isModalOpen, setIsModalOpen] = (0, import_element.useState)(false);
295 - const [title, setTitle] = (0, import_element.useState)("");
296 - const canConvert = (0, import_data3.useSelect)(
297 - (select) => {
298 - const { canUser } = select(import_core_data.store);
299 - const {
300 - getBlocksByClientId,
301 - canInsertBlockType,
302 - getBlockRootClientId
303 - } = select(import_block_editor2.store);
304 - const rootId = rootClientId || (clientIds.length > 0 ? getBlockRootClientId(clientIds[0]) : void 0);
305 - const blocks = getBlocksByClientId(clientIds) ?? [];
306 - const isReusable = blocks.length === 1 && blocks[0] && (0, import_blocks2.isReusableBlock)(blocks[0]) && !!select(import_core_data.store).getEntityRecord(
307 - "postType",
308 - "wp_block",
309 - blocks[0].attributes.ref
310 - );
311 - const _canConvert = (
312 - // Hide when this is already a reusable block.
313 - !isReusable && // Hide when reusable blocks are disabled.
314 - canInsertBlockType("core/block", rootId) && blocks.every(
315 - (block) => (
316 - // Guard against the case where a regular block has *just* been converted.
317 - !!block && // Hide on invalid blocks.
318 - block.isValid && // Hide when block doesn't support being made reusable.
319 - (0, import_blocks2.hasBlockSupport)(block.name, "reusable", true)
320 - )
321 - ) && // Hide when current doesn't have permission to do that.
322 - // Blocks refers to the wp_block post type, this checks the ability to create a post of that type.
323 - !!canUser("create", {
324 - kind: "postType",
325 - name: "wp_block"
326 - })
327 - );
328 - return _canConvert;
329 - },
330 - [clientIds, rootClientId]
331 - );
332 - const { __experimentalConvertBlocksToReusable: convertBlocksToReusable } = (0, import_data3.useDispatch)(store);
333 - const { createSuccessNotice, createErrorNotice } = (0, import_data3.useDispatch)(import_notices.store);
334 - const onConvert = (0, import_element.useCallback)(
335 - async function(reusableBlockTitle) {
336 - try {
337 - await convertBlocksToReusable(
338 - clientIds,
339 - reusableBlockTitle,
340 - syncType
341 - );
342 - createSuccessNotice(
343 - !syncType ? (0, import_i18n2.sprintf)(
344 - // translators: %s: the name the user has given to the pattern.
345 - (0, import_i18n2.__)("Synced pattern created: %s"),
346 - reusableBlockTitle
347 - ) : (0, import_i18n2.sprintf)(
348 - // translators: %s: the name the user has given to the pattern.
349 - (0, import_i18n2.__)("Unsynced pattern created: %s"),
350 - reusableBlockTitle
351 - ),
352 - {
353 - type: "snackbar",
354 - id: "convert-to-reusable-block-success"
355 - }
356 - );
357 - } catch (error) {
358 - createErrorNotice(error.message, {
359 - type: "snackbar",
360 - id: "convert-to-reusable-block-error"
361 - });
362 - }
363 - },
364 - [
365 - convertBlocksToReusable,
366 - clientIds,
367 - syncType,
368 - createSuccessNotice,
369 - createErrorNotice
370 - ]
371 - );
372 - if (!canConvert) {
373 - return null;
374 - }
375 - return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
376 - /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_components.MenuItem, { icon: symbol_default, onClick: () => setIsModalOpen(true), children: (0, import_i18n2.__)("Create pattern") }),
377 - isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
378 - import_components.Modal,
379 - {
380 - title: (0, import_i18n2.__)("Create pattern"),
381 - onRequestClose: () => {
382 - setIsModalOpen(false);
383 - setTitle("");
384 - },
385 - overlayClassName: "reusable-blocks-menu-items__convert-modal",
386 - children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
387 - "form",
388 - {
389 - onSubmit: (event) => {
390 - event.preventDefault();
391 - onConvert(title);
392 - setIsModalOpen(false);
393 - setTitle("");
394 - onClose();
395 - },
396 - children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_components.__experimentalVStack, { spacing: "5", children: [
397 - /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
398 - import_components.TextControl,
399 - {
400 - label: (0, import_i18n2.__)("Name"),
401 - value: title,
402 - onChange: setTitle,
403 - placeholder: (0, import_i18n2.__)("My pattern")
404 - }
405 - ),
406 - /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
407 - import_components.ToggleControl,
408 - {
409 - label: (0, import_i18n2._x)("Synced", "pattern (singular)"),
410 - help: (0, import_i18n2.__)(
411 - "Sync this pattern across multiple locations."
412 - ),
413 - checked: !syncType,
414 - onChange: () => {
415 - setSyncType(
416 - !syncType ? "unsynced" : void 0
417 - );
418 - }
419 - }
420 - ),
421 - /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
422 - /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
423 - import_components.Button,
424 - {
425 - __next40pxDefaultSize: true,
426 - variant: "tertiary",
427 - onClick: () => {
428 - setIsModalOpen(false);
429 - setTitle("");
430 - },
431 - children: (0, import_i18n2.__)("Cancel")
432 - }
433 - ),
434 - /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
435 - import_components.Button,
436 - {
437 - __next40pxDefaultSize: true,
438 - variant: "primary",
439 - type: "submit",
440 - children: (0, import_i18n2.__)("Create")
441 - }
442 - )
443 - ] })
444 - ] })
445 - }
446 - )
447 - }
448 - )
449 - ] });
450 - }
451 -
452 - // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/reusable-blocks-manage-button.mjs
453 - var import_components2 = __toESM(require_components(), 1);
454 - var import_i18n3 = __toESM(require_i18n(), 1);
455 - var import_blocks3 = __toESM(require_blocks(), 1);
456 - var import_data4 = __toESM(require_data(), 1);
457 - var import_element2 = __toESM(require_element(), 1);
458 - var import_block_editor3 = __toESM(require_block_editor(), 1);
459 - var import_url = __toESM(require_url(), 1);
460 - var import_core_data2 = __toESM(require_core_data(), 1);
461 - var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
462 - function ReusableBlocksManageButton({ clientId }) {
463 - const [showConfirmDialog, setShowConfirmDialog] = (0, import_element2.useState)(false);
464 - const { canRemove, isVisible, managePatternsUrl } = (0, import_data4.useSelect)(
465 - (select) => {
466 - const { getBlock, canRemoveBlock } = select(import_block_editor3.store);
467 - const { canUser } = select(import_core_data2.store);
468 - const reusableBlock = getBlock(clientId);
469 - return {
470 - canRemove: canRemoveBlock(clientId),
471 - isVisible: !!reusableBlock && (0, import_blocks3.isReusableBlock)(reusableBlock) && !!canUser("update", {
472 - kind: "postType",
473 - name: "wp_block",
474 - id: reusableBlock.attributes.ref
475 - }),
476 - // The site editor and templates both check whether the user
477 - // has edit_theme_options capabilities. We can leverage that here
478 - // and omit the manage patterns link if the user can't access it.
479 - managePatternsUrl: canUser("create", {
480 - kind: "postType",
481 - name: "wp_template"
482 - }) ? (0, import_url.addQueryArgs)("site-editor.php", {
483 - p: "/pattern"
484 - }) : (0, import_url.addQueryArgs)("edit.php", {
485 - post_type: "wp_block"
486 - })
487 - };
488 - },
489 - [clientId]
490 - );
491 - const { __experimentalConvertBlockToStatic: convertBlockToStatic } = (0, import_data4.useDispatch)(store);
492 - if (!isVisible) {
493 - return null;
494 - }
495 - const handleDetach = () => {
496 - convertBlockToStatic(clientId);
497 - setShowConfirmDialog(false);
498 - };
499 - return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
500 - /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_components2.MenuItem, { href: managePatternsUrl, children: (0, import_i18n3.__)("Manage patterns") }),
501 - canRemove && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
502 - /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_components2.MenuItem, { onClick: () => setShowConfirmDialog(true), children: (0, import_i18n3.__)("Disconnect pattern") }),
503 - /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
504 - import_components2.__experimentalConfirmDialog,
505 - {
506 - isOpen: showConfirmDialog,
507 - onConfirm: handleDetach,
508 - onCancel: () => setShowConfirmDialog(false),
509 - confirmButtonText: (0, import_i18n3.__)("Disconnect"),
510 - size: "medium",
511 - title: (0, import_i18n3.__)("Disconnect pattern?"),
512 - __experimentalHideHeader: false,
513 - children: (0, import_i18n3.__)(
514 - "Blocks will be separated from the original pattern and will be fully editable. Future changes to the pattern will not apply here."
515 - )
516 - }
517 - )
518 - ] })
519 - ] });
520 - }
521 - var reusable_blocks_manage_button_default = ReusableBlocksManageButton;
522 -
523 - // packages/reusable-blocks/build-module/components/reusable-blocks-menu-items/index.mjs
524 - var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
525 - function ReusableBlocksMenuItems({ rootClientId }) {
141 + function ReusableBlocksMenuItems() {
526 142 (0, import_deprecated3.default)("wp.reusableBlocks.ReusableBlocksMenuItems", {
527 143 since: "7.1"
528 144 });
529 - return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_block_editor4.BlockSettingsMenuControls, { children: ({ onClose, selectedClientIds }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
530 - /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
531 - ReusableBlockConvertButton,
532 - {
533 - clientIds: selectedClientIds,
534 - rootClientId,
535 - onClose
536 - }
537 - ),
538 - selectedClientIds.length === 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
539 - reusable_blocks_manage_button_default,
540 - {
541 - clientId: selectedClientIds[0]
542 - }
543 - )
544 - ] }) });
145 + return null;
545 146 }
546 147 return __toCommonJS(index_exports);
547 148 })();
548 149 (window.wp ||= {}).reusableBlocks = wp.reusableBlocks;