PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
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
gutenberg / build / scripts / list-reusable-blocks / index.js

index.js in Gutenberg 24.1.0, at build/scripts/list-reusable-blocks/index.js

856 lines 24.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 "use strict";
3 var wp;
4 (wp ||= {}).listReusableBlocks = (() => {
5 var __create = Object.create;
6 var __defProp = Object.defineProperty;
7 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8 var __getOwnPropNames = Object.getOwnPropertyNames;
9 var __getProtoOf = Object.getPrototypeOf;
10 var __hasOwnProp = Object.prototype.hasOwnProperty;
11 var __commonJS = (cb, mod) => function __require() {
12 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13 };
14 var __copyProps = (to, from, except, desc) => {
15 if (from && typeof from === "object" || typeof from === "function") {
16 for (let key of __getOwnPropNames(from))
17 if (!__hasOwnProp.call(to, key) && key !== except)
18 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19 }
20 return to;
21 };
22 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23 // If the importer is in node compatibility mode or this is not an ESM
24 // file that has been converted to a CommonJS file using a Babel-
25 // compatible transform (i.e. "__esModule" has not been set), then set
26 // "default" to the CommonJS "module.exports" for node compatibility.
27 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28 mod
29 ));
30
31 // package-external:@wordpress/element
32 var require_element = __commonJS({
33 "package-external:@wordpress/element"(exports, module) {
34 module.exports = window.wp.element;
35 }
36 });
37
38 // package-external:@wordpress/i18n
39 var require_i18n = __commonJS({
40 "package-external:@wordpress/i18n"(exports, module) {
41 module.exports = window.wp.i18n;
42 }
43 });
44
45 // package-external:@wordpress/components
46 var require_components = __commonJS({
47 "package-external:@wordpress/components"(exports, module) {
48 module.exports = window.wp.components;
49 }
50 });
51
52 // package-external:@wordpress/compose
53 var require_compose = __commonJS({
54 "package-external:@wordpress/compose"(exports, module) {
55 module.exports = window.wp.compose;
56 }
57 });
58
59 // package-external:@wordpress/api-fetch
60 var require_api_fetch = __commonJS({
61 "package-external:@wordpress/api-fetch"(exports, module) {
62 module.exports = window.wp.apiFetch;
63 }
64 });
65
66 // vendor-external:react/jsx-runtime
67 var require_jsx_runtime = __commonJS({
68 "vendor-external:react/jsx-runtime"(exports, module) {
69 module.exports = window.ReactJSXRuntime;
70 }
71 });
72
73 // node_modules/remove-accents/index.js
74 var require_remove_accents = __commonJS({
75 "node_modules/remove-accents/index.js"(exports, module) {
76 var characterMap = {
77 "\xC0": "A",
78 "\xC1": "A",
79 "\xC2": "A",
80 "\xC3": "A",
81 "\xC4": "A",
82 "\xC5": "A",
83 "\u1EA4": "A",
84 "\u1EAE": "A",
85 "\u1EB2": "A",
86 "\u1EB4": "A",
87 "\u1EB6": "A",
88 "\xC6": "AE",
89 "\u1EA6": "A",
90 "\u1EB0": "A",
91 "\u0202": "A",
92 "\u1EA2": "A",
93 "\u1EA0": "A",
94 "\u1EA8": "A",
95 "\u1EAA": "A",
96 "\u1EAC": "A",
97 "\xC7": "C",
98 "\u1E08": "C",
99 "\xC8": "E",
100 "\xC9": "E",
101 "\xCA": "E",
102 "\xCB": "E",
103 "\u1EBE": "E",
104 "\u1E16": "E",
105 "\u1EC0": "E",
106 "\u1E14": "E",
107 "\u1E1C": "E",
108 "\u0206": "E",
109 "\u1EBA": "E",
110 "\u1EBC": "E",
111 "\u1EB8": "E",
112 "\u1EC2": "E",
113 "\u1EC4": "E",
114 "\u1EC6": "E",
115 "\xCC": "I",
116 "\xCD": "I",
117 "\xCE": "I",
118 "\xCF": "I",
119 "\u1E2E": "I",
120 "\u020A": "I",
121 "\u1EC8": "I",
122 "\u1ECA": "I",
123 "\xD0": "D",
124 "\xD1": "N",
125 "\xD2": "O",
126 "\xD3": "O",
127 "\xD4": "O",
128 "\xD5": "O",
129 "\xD6": "O",
130 "\xD8": "O",
131 "\u1ED0": "O",
132 "\u1E4C": "O",
133 "\u1E52": "O",
134 "\u020E": "O",
135 "\u1ECE": "O",
136 "\u1ECC": "O",
137 "\u1ED4": "O",
138 "\u1ED6": "O",
139 "\u1ED8": "O",
140 "\u1EDC": "O",
141 "\u1EDE": "O",
142 "\u1EE0": "O",
143 "\u1EDA": "O",
144 "\u1EE2": "O",
145 "\xD9": "U",
146 "\xDA": "U",
147 "\xDB": "U",
148 "\xDC": "U",
149 "\u1EE6": "U",
150 "\u1EE4": "U",
151 "\u1EEC": "U",
152 "\u1EEE": "U",
153 "\u1EF0": "U",
154 "\xDD": "Y",
155 "\xE0": "a",
156 "\xE1": "a",
157 "\xE2": "a",
158 "\xE3": "a",
159 "\xE4": "a",
160 "\xE5": "a",
161 "\u1EA5": "a",
162 "\u1EAF": "a",
163 "\u1EB3": "a",
164 "\u1EB5": "a",
165 "\u1EB7": "a",
166 "\xE6": "ae",
167 "\u1EA7": "a",
168 "\u1EB1": "a",
169 "\u0203": "a",
170 "\u1EA3": "a",
171 "\u1EA1": "a",
172 "\u1EA9": "a",
173 "\u1EAB": "a",
174 "\u1EAD": "a",
175 "\xE7": "c",
176 "\u1E09": "c",
177 "\xE8": "e",
178 "\xE9": "e",
179 "\xEA": "e",
180 "\xEB": "e",
181 "\u1EBF": "e",
182 "\u1E17": "e",
183 "\u1EC1": "e",
184 "\u1E15": "e",
185 "\u1E1D": "e",
186 "\u0207": "e",
187 "\u1EBB": "e",
188 "\u1EBD": "e",
189 "\u1EB9": "e",
190 "\u1EC3": "e",
191 "\u1EC5": "e",
192 "\u1EC7": "e",
193 "\xEC": "i",
194 "\xED": "i",
195 "\xEE": "i",
196 "\xEF": "i",
197 "\u1E2F": "i",
198 "\u020B": "i",
199 "\u1EC9": "i",
200 "\u1ECB": "i",
201 "\xF0": "d",
202 "\xF1": "n",
203 "\xF2": "o",
204 "\xF3": "o",
205 "\xF4": "o",
206 "\xF5": "o",
207 "\xF6": "o",
208 "\xF8": "o",
209 "\u1ED1": "o",
210 "\u1E4D": "o",
211 "\u1E53": "o",
212 "\u020F": "o",
213 "\u1ECF": "o",
214 "\u1ECD": "o",
215 "\u1ED5": "o",
216 "\u1ED7": "o",
217 "\u1ED9": "o",
218 "\u1EDD": "o",
219 "\u1EDF": "o",
220 "\u1EE1": "o",
221 "\u1EDB": "o",
222 "\u1EE3": "o",
223 "\xF9": "u",
224 "\xFA": "u",
225 "\xFB": "u",
226 "\xFC": "u",
227 "\u1EE7": "u",
228 "\u1EE5": "u",
229 "\u1EED": "u",
230 "\u1EEF": "u",
231 "\u1EF1": "u",
232 "\xFD": "y",
233 "\xFF": "y",
234 "\u0100": "A",
235 "\u0101": "a",
236 "\u0102": "A",
237 "\u0103": "a",
238 "\u0104": "A",
239 "\u0105": "a",
240 "\u0106": "C",
241 "\u0107": "c",
242 "\u0108": "C",
243 "\u0109": "c",
244 "\u010A": "C",
245 "\u010B": "c",
246 "\u010C": "C",
247 "\u010D": "c",
248 "C\u0306": "C",
249 "c\u0306": "c",
250 "\u010E": "D",
251 "\u010F": "d",
252 "\u0110": "D",
253 "\u0111": "d",
254 "\u0112": "E",
255 "\u0113": "e",
256 "\u0114": "E",
257 "\u0115": "e",
258 "\u0116": "E",
259 "\u0117": "e",
260 "\u0118": "E",
261 "\u0119": "e",
262 "\u011A": "E",
263 "\u011B": "e",
264 "\u011C": "G",
265 "\u01F4": "G",
266 "\u011D": "g",
267 "\u01F5": "g",
268 "\u011E": "G",
269 "\u011F": "g",
270 "\u0120": "G",
271 "\u0121": "g",
272 "\u0122": "G",
273 "\u0123": "g",
274 "\u0124": "H",
275 "\u0125": "h",
276 "\u0126": "H",
277 "\u0127": "h",
278 "\u1E2A": "H",
279 "\u1E2B": "h",
280 "\u0128": "I",
281 "\u0129": "i",
282 "\u012A": "I",
283 "\u012B": "i",
284 "\u012C": "I",
285 "\u012D": "i",
286 "\u012E": "I",
287 "\u012F": "i",
288 "\u0130": "I",
289 "\u0131": "i",
290 "\u0132": "IJ",
291 "\u0133": "ij",
292 "\u0134": "J",
293 "\u0135": "j",
294 "\u0136": "K",
295 "\u0137": "k",
296 "\u1E30": "K",
297 "\u1E31": "k",
298 "K\u0306": "K",
299 "k\u0306": "k",
300 "\u0139": "L",
301 "\u013A": "l",
302 "\u013B": "L",
303 "\u013C": "l",
304 "\u013D": "L",
305 "\u013E": "l",
306 "\u013F": "L",
307 "\u0140": "l",
308 "\u0141": "l",
309 "\u0142": "l",
310 "\u1E3E": "M",
311 "\u1E3F": "m",
312 "M\u0306": "M",
313 "m\u0306": "m",
314 "\u0143": "N",
315 "\u0144": "n",
316 "\u0145": "N",
317 "\u0146": "n",
318 "\u0147": "N",
319 "\u0148": "n",
320 "\u0149": "n",
321 "N\u0306": "N",
322 "n\u0306": "n",
323 "\u014C": "O",
324 "\u014D": "o",
325 "\u014E": "O",
326 "\u014F": "o",
327 "\u0150": "O",
328 "\u0151": "o",
329 "\u0152": "OE",
330 "\u0153": "oe",
331 "P\u0306": "P",
332 "p\u0306": "p",
333 "\u0154": "R",
334 "\u0155": "r",
335 "\u0156": "R",
336 "\u0157": "r",
337 "\u0158": "R",
338 "\u0159": "r",
339 "R\u0306": "R",
340 "r\u0306": "r",
341 "\u0212": "R",
342 "\u0213": "r",
343 "\u015A": "S",
344 "\u015B": "s",
345 "\u015C": "S",
346 "\u015D": "s",
347 "\u015E": "S",
348 "\u0218": "S",
349 "\u0219": "s",
350 "\u015F": "s",
351 "\u0160": "S",
352 "\u0161": "s",
353 "\u0162": "T",
354 "\u0163": "t",
355 "\u021B": "t",
356 "\u021A": "T",
357 "\u0164": "T",
358 "\u0165": "t",
359 "\u0166": "T",
360 "\u0167": "t",
361 "T\u0306": "T",
362 "t\u0306": "t",
363 "\u0168": "U",
364 "\u0169": "u",
365 "\u016A": "U",
366 "\u016B": "u",
367 "\u016C": "U",
368 "\u016D": "u",
369 "\u016E": "U",
370 "\u016F": "u",
371 "\u0170": "U",
372 "\u0171": "u",
373 "\u0172": "U",
374 "\u0173": "u",
375 "\u0216": "U",
376 "\u0217": "u",
377 "V\u0306": "V",
378 "v\u0306": "v",
379 "\u0174": "W",
380 "\u0175": "w",
381 "\u1E82": "W",
382 "\u1E83": "w",
383 "X\u0306": "X",
384 "x\u0306": "x",
385 "\u0176": "Y",
386 "\u0177": "y",
387 "\u0178": "Y",
388 "Y\u0306": "Y",
389 "y\u0306": "y",
390 "\u0179": "Z",
391 "\u017A": "z",
392 "\u017B": "Z",
393 "\u017C": "z",
394 "\u017D": "Z",
395 "\u017E": "z",
396 "\u017F": "s",
397 "\u0192": "f",
398 "\u01A0": "O",
399 "\u01A1": "o",
400 "\u01AF": "U",
401 "\u01B0": "u",
402 "\u01CD": "A",
403 "\u01CE": "a",
404 "\u01CF": "I",
405 "\u01D0": "i",
406 "\u01D1": "O",
407 "\u01D2": "o",
408 "\u01D3": "U",
409 "\u01D4": "u",
410 "\u01D5": "U",
411 "\u01D6": "u",
412 "\u01D7": "U",
413 "\u01D8": "u",
414 "\u01D9": "U",
415 "\u01DA": "u",
416 "\u01DB": "U",
417 "\u01DC": "u",
418 "\u1EE8": "U",
419 "\u1EE9": "u",
420 "\u1E78": "U",
421 "\u1E79": "u",
422 "\u01FA": "A",
423 "\u01FB": "a",
424 "\u01FC": "AE",
425 "\u01FD": "ae",
426 "\u01FE": "O",
427 "\u01FF": "o",
428 "\xDE": "TH",
429 "\xFE": "th",
430 "\u1E54": "P",
431 "\u1E55": "p",
432 "\u1E64": "S",
433 "\u1E65": "s",
434 "X\u0301": "X",
435 "x\u0301": "x",
436 "\u0403": "\u0413",
437 "\u0453": "\u0433",
438 "\u040C": "\u041A",
439 "\u045C": "\u043A",
440 "A\u030B": "A",
441 "a\u030B": "a",
442 "E\u030B": "E",
443 "e\u030B": "e",
444 "I\u030B": "I",
445 "i\u030B": "i",
446 "\u01F8": "N",
447 "\u01F9": "n",
448 "\u1ED2": "O",
449 "\u1ED3": "o",
450 "\u1E50": "O",
451 "\u1E51": "o",
452 "\u1EEA": "U",
453 "\u1EEB": "u",
454 "\u1E80": "W",
455 "\u1E81": "w",
456 "\u1EF2": "Y",
457 "\u1EF3": "y",
458 "\u0200": "A",
459 "\u0201": "a",
460 "\u0204": "E",
461 "\u0205": "e",
462 "\u0208": "I",
463 "\u0209": "i",
464 "\u020C": "O",
465 "\u020D": "o",
466 "\u0210": "R",
467 "\u0211": "r",
468 "\u0214": "U",
469 "\u0215": "u",
470 "B\u030C": "B",
471 "b\u030C": "b",
472 "\u010C\u0323": "C",
473 "\u010D\u0323": "c",
474 "\xCA\u030C": "E",
475 "\xEA\u030C": "e",
476 "F\u030C": "F",
477 "f\u030C": "f",
478 "\u01E6": "G",
479 "\u01E7": "g",
480 "\u021E": "H",
481 "\u021F": "h",
482 "J\u030C": "J",
483 "\u01F0": "j",
484 "\u01E8": "K",
485 "\u01E9": "k",
486 "M\u030C": "M",
487 "m\u030C": "m",
488 "P\u030C": "P",
489 "p\u030C": "p",
490 "Q\u030C": "Q",
491 "q\u030C": "q",
492 "\u0158\u0329": "R",
493 "\u0159\u0329": "r",
494 "\u1E66": "S",
495 "\u1E67": "s",
496 "V\u030C": "V",
497 "v\u030C": "v",
498 "W\u030C": "W",
499 "w\u030C": "w",
500 "X\u030C": "X",
501 "x\u030C": "x",
502 "Y\u030C": "Y",
503 "y\u030C": "y",
504 "A\u0327": "A",
505 "a\u0327": "a",
506 "B\u0327": "B",
507 "b\u0327": "b",
508 "\u1E10": "D",
509 "\u1E11": "d",
510 "\u0228": "E",
511 "\u0229": "e",
512 "\u0190\u0327": "E",
513 "\u025B\u0327": "e",
514 "\u1E28": "H",
515 "\u1E29": "h",
516 "I\u0327": "I",
517 "i\u0327": "i",
518 "\u0197\u0327": "I",
519 "\u0268\u0327": "i",
520 "M\u0327": "M",
521 "m\u0327": "m",
522 "O\u0327": "O",
523 "o\u0327": "o",
524 "Q\u0327": "Q",
525 "q\u0327": "q",
526 "U\u0327": "U",
527 "u\u0327": "u",
528 "X\u0327": "X",
529 "x\u0327": "x",
530 "Z\u0327": "Z",
531 "z\u0327": "z",
532 "\u0439": "\u0438",
533 "\u0419": "\u0418",
534 "\u0451": "\u0435",
535 "\u0401": "\u0415"
536 };
537 var chars = Object.keys(characterMap).join("|");
538 var allAccents = new RegExp(chars, "g");
539 var firstAccent = new RegExp(chars, "");
540 function matcher(match) {
541 return characterMap[match];
542 }
543 var removeAccents2 = function(string) {
544 return string.replace(allAccents, matcher);
545 };
546 var hasAccents = function(string) {
547 return !!string.match(firstAccent);
548 };
549 module.exports = removeAccents2;
550 module.exports.has = hasAccents;
551 module.exports.remove = removeAccents2;
552 }
553 });
554
555 // package-external:@wordpress/blob
556 var require_blob = __commonJS({
557 "package-external:@wordpress/blob"(exports, module) {
558 module.exports = window.wp.blob;
559 }
560 });
561
562 // packages/list-reusable-blocks/build-module/index.mjs
563 var import_element2 = __toESM(require_element(), 1);
564 var import_i18n3 = __toESM(require_i18n(), 1);
565
566 // packages/list-reusable-blocks/build-module/components/import-dropdown/index.mjs
567 var import_components2 = __toESM(require_components(), 1);
568 var import_compose2 = __toESM(require_compose(), 1);
569 var import_i18n2 = __toESM(require_i18n(), 1);
570
571 // packages/list-reusable-blocks/build-module/components/import-form/index.mjs
572 var import_components = __toESM(require_components(), 1);
573 var import_compose = __toESM(require_compose(), 1);
574 var import_element = __toESM(require_element(), 1);
575 var import_i18n = __toESM(require_i18n(), 1);
576
577 // packages/list-reusable-blocks/build-module/utils/import.mjs
578 var import_api_fetch = __toESM(require_api_fetch(), 1);
579
580 // packages/list-reusable-blocks/build-module/utils/file.mjs
581 function readTextFile(file) {
582 const reader = new window.FileReader();
583 return new Promise((resolve) => {
584 reader.onload = () => {
585 resolve(reader.result);
586 };
587 reader.readAsText(file);
588 });
589 }
590
591 // packages/list-reusable-blocks/build-module/utils/import.mjs
592 async function importReusableBlock(file) {
593 const fileContent = await readTextFile(file);
594 let parsedContent;
595 try {
596 parsedContent = JSON.parse(fileContent);
597 } catch {
598 throw new Error("Invalid JSON file");
599 }
600 if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") {
601 throw new Error("Invalid pattern JSON file");
602 }
603 const postType = await (0, import_api_fetch.default)({
604 path: `/wp/v2/types/wp_block`
605 });
606 const reusableBlock = await (0, import_api_fetch.default)({
607 path: `/wp/v2/${postType.rest_base}`,
608 data: {
609 title: parsedContent.title,
610 content: parsedContent.content,
611 status: "publish",
612 meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
613 },
614 method: "POST"
615 });
616 return reusableBlock;
617 }
618 var import_default = importReusableBlock;
619
620 // packages/list-reusable-blocks/build-module/components/import-form/index.mjs
621 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
622 function ImportForm({ instanceId, onUpload }) {
623 const inputId = "list-reusable-blocks-import-form-" + instanceId;
624 const formRef = (0, import_element.useRef)(null);
625 const [isLoading, setIsLoading] = (0, import_element.useState)(false);
626 const [error, setError] = (0, import_element.useState)(null);
627 const [file, setFile] = (0, import_element.useState)(null);
628 const onChangeFile = (event) => {
629 setFile(event.target.files?.[0] || null);
630 setError(null);
631 };
632 const onSubmit = (event) => {
633 event.preventDefault();
634 if (!file) {
635 return;
636 }
637 setIsLoading(true);
638 import_default(file).then((reusableBlock) => {
639 if (!formRef.current) {
640 return;
641 }
642 setIsLoading(false);
643 onUpload(reusableBlock);
644 }).catch((errors) => {
645 if (!formRef.current) {
646 return;
647 }
648 let uiMessage;
649 switch (errors.message) {
650 case "Invalid JSON file":
651 uiMessage = (0, import_i18n.__)("Invalid JSON file");
652 break;
653 case "Invalid pattern JSON file":
654 uiMessage = (0, import_i18n.__)("Invalid pattern JSON file");
655 break;
656 default:
657 uiMessage = (0, import_i18n.__)("Unknown error");
658 }
659 setIsLoading(false);
660 setError(uiMessage);
661 });
662 };
663 const onDismissError = () => {
664 setError(null);
665 };
666 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
667 "form",
668 {
669 className: "list-reusable-blocks-import-form",
670 onSubmit,
671 ref: formRef,
672 children: [
673 error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Notice, { status: "error", onRemove: () => onDismissError(), children: error }),
674 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
675 "label",
676 {
677 htmlFor: inputId,
678 className: "list-reusable-blocks-import-form__label",
679 children: (0, import_i18n.__)("File")
680 }
681 ),
682 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: inputId, type: "file", onChange: onChangeFile }),
683 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
684 import_components.Button,
685 {
686 __next40pxDefaultSize: true,
687 type: "submit",
688 isBusy: isLoading,
689 accessibleWhenDisabled: true,
690 disabled: !file || isLoading,
691 variant: "secondary",
692 className: "list-reusable-blocks-import-form__button",
693 children: (0, import_i18n._x)("Import", "button label")
694 }
695 )
696 ]
697 }
698 );
699 }
700 var import_form_default = (0, import_compose.withInstanceId)(ImportForm);
701
702 // packages/list-reusable-blocks/build-module/components/import-dropdown/index.mjs
703 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
704 function ImportDropdown({ onUpload }) {
705 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
706 import_components2.Dropdown,
707 {
708 popoverProps: { placement: "bottom-start" },
709 contentClassName: "list-reusable-blocks-import-dropdown__content",
710 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
711 import_components2.Button,
712 {
713 size: "compact",
714 className: "list-reusable-blocks-import-dropdown__button",
715 "aria-expanded": isOpen,
716 onClick: onToggle,
717 variant: "primary",
718 children: (0, import_i18n2.__)("Import from JSON")
719 }
720 ),
721 renderContent: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_form_default, { onUpload: (0, import_compose2.pipe)(onClose, onUpload) })
722 }
723 );
724 }
725 var import_dropdown_default = ImportDropdown;
726
727 // node_modules/tslib/tslib.es6.mjs
728 var __assign = function() {
729 __assign = Object.assign || function __assign2(t) {
730 for (var s, i = 1, n = arguments.length; i < n; i++) {
731 s = arguments[i];
732 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
733 }
734 return t;
735 };
736 return __assign.apply(this, arguments);
737 };
738
739 // node_modules/lower-case/dist.es2015/index.js
740 function lowerCase(str) {
741 return str.toLowerCase();
742 }
743
744 // node_modules/no-case/dist.es2015/index.js
745 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
746 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
747 function noCase(input, options) {
748 if (options === void 0) {
749 options = {};
750 }
751 var _a = options.splitRegexp, splitRegexp = _a === void 0 ? DEFAULT_SPLIT_REGEXP : _a, _b = options.stripRegexp, stripRegexp = _b === void 0 ? DEFAULT_STRIP_REGEXP : _b, _c = options.transform, transform = _c === void 0 ? lowerCase : _c, _d = options.delimiter, delimiter = _d === void 0 ? " " : _d;
752 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
753 var start = 0;
754 var end = result.length;
755 while (result.charAt(start) === "\0")
756 start++;
757 while (result.charAt(end - 1) === "\0")
758 end--;
759 return result.slice(start, end).split("\0").map(transform).join(delimiter);
760 }
761 function replace(input, re, value) {
762 if (re instanceof RegExp)
763 return input.replace(re, value);
764 return re.reduce(function(input2, re2) {
765 return input2.replace(re2, value);
766 }, input);
767 }
768
769 // node_modules/dot-case/dist.es2015/index.js
770 function dotCase(input, options) {
771 if (options === void 0) {
772 options = {};
773 }
774 return noCase(input, __assign({ delimiter: "." }, options));
775 }
776
777 // node_modules/param-case/dist.es2015/index.js
778 function paramCase(input, options) {
779 if (options === void 0) {
780 options = {};
781 }
782 return dotCase(input, __assign({ delimiter: "-" }, options));
783 }
784
785 // packages/list-reusable-blocks/build-module/utils/export.mjs
786 var import_remove_accents = __toESM(require_remove_accents(), 1);
787 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
788 var import_blob = __toESM(require_blob(), 1);
789 async function exportReusableBlock(id) {
790 const postType = await (0, import_api_fetch2.default)({
791 path: `/wp/v2/types/wp_block`
792 });
793 const post = await (0, import_api_fetch2.default)({
794 path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
795 });
796 const title = post.title.raw;
797 const content = post.content.raw;
798 const syncStatus = post.wp_pattern_sync_status;
799 const fileContent = JSON.stringify(
800 {
801 __file: "wp_block",
802 title,
803 content,
804 syncStatus
805 },
806 null,
807 2
808 );
809 const fileName = paramCase((0, import_remove_accents.default)(title)) + ".json";
810 (0, import_blob.downloadBlob)(fileName, fileContent, "application/json");
811 }
812 var export_default = exportReusableBlock;
813
814 // packages/list-reusable-blocks/build-module/index.mjs
815 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
816 document.body.addEventListener("click", (event) => {
817 const target = event.target;
818 if (!target.classList.contains("wp-list-reusable-blocks__export")) {
819 return;
820 }
821 event.preventDefault();
822 const blockId = target.dataset.id;
823 if (blockId) {
824 export_default(Number(blockId));
825 }
826 });
827 document.addEventListener("DOMContentLoaded", () => {
828 const button = document.querySelector(".page-title-action");
829 if (!button) {
830 return;
831 }
832 const showNotice = () => {
833 const notice = document.createElement("div");
834 notice.className = "notice notice-success is-dismissible";
835 notice.innerHTML = `<p>${(0, import_i18n3.__)("Pattern imported successfully!")}</p>`;
836 const headerEnd = document.querySelector(".wp-header-end");
837 if (!headerEnd || !headerEnd.parentNode) {
838 return;
839 }
840 headerEnd.parentNode.insertBefore(notice, headerEnd);
841 };
842 const container = document.createElement("div");
843 container.className = "list-reusable-blocks__container";
844 if (!button.parentNode) {
845 return;
846 }
847 button.parentNode.insertBefore(container, button);
848 (0, import_element2.createRoot)(container).render(
849 /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_element2.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dropdown_default, { onUpload: showNotice }) })
850 );
851 });
852 })();
853 (window.wp ||= {}).listReusableBlocks = wp.listReusableBlocks;
854 })();
855 //# sourceMappingURL=index.js.map
856