9
|
1 |
this["wp"] = this["wp"] || {}; this["wp"]["listReusableBlocks"] = |
|
2 |
/******/ (function(modules) { // webpackBootstrap |
|
3 |
/******/ // The module cache |
|
4 |
/******/ var installedModules = {}; |
|
5 |
/******/ |
|
6 |
/******/ // The require function |
|
7 |
/******/ function __webpack_require__(moduleId) { |
|
8 |
/******/ |
|
9 |
/******/ // Check if module is in cache |
|
10 |
/******/ if(installedModules[moduleId]) { |
|
11 |
/******/ return installedModules[moduleId].exports; |
|
12 |
/******/ } |
|
13 |
/******/ // Create a new module (and put it into the cache) |
|
14 |
/******/ var module = installedModules[moduleId] = { |
|
15 |
/******/ i: moduleId, |
|
16 |
/******/ l: false, |
|
17 |
/******/ exports: {} |
|
18 |
/******/ }; |
|
19 |
/******/ |
|
20 |
/******/ // Execute the module function |
|
21 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
|
22 |
/******/ |
|
23 |
/******/ // Flag the module as loaded |
|
24 |
/******/ module.l = true; |
|
25 |
/******/ |
|
26 |
/******/ // Return the exports of the module |
|
27 |
/******/ return module.exports; |
|
28 |
/******/ } |
|
29 |
/******/ |
|
30 |
/******/ |
|
31 |
/******/ // expose the modules object (__webpack_modules__) |
|
32 |
/******/ __webpack_require__.m = modules; |
|
33 |
/******/ |
|
34 |
/******/ // expose the module cache |
|
35 |
/******/ __webpack_require__.c = installedModules; |
|
36 |
/******/ |
|
37 |
/******/ // define getter function for harmony exports |
|
38 |
/******/ __webpack_require__.d = function(exports, name, getter) { |
|
39 |
/******/ if(!__webpack_require__.o(exports, name)) { |
|
40 |
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); |
|
41 |
/******/ } |
|
42 |
/******/ }; |
|
43 |
/******/ |
|
44 |
/******/ // define __esModule on exports |
|
45 |
/******/ __webpack_require__.r = function(exports) { |
|
46 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
47 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
48 |
/******/ } |
|
49 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
50 |
/******/ }; |
|
51 |
/******/ |
|
52 |
/******/ // create a fake namespace object |
|
53 |
/******/ // mode & 1: value is a module id, require it |
|
54 |
/******/ // mode & 2: merge all properties of value into the ns |
|
55 |
/******/ // mode & 4: return value when already ns object |
|
56 |
/******/ // mode & 8|1: behave like require |
|
57 |
/******/ __webpack_require__.t = function(value, mode) { |
|
58 |
/******/ if(mode & 1) value = __webpack_require__(value); |
|
59 |
/******/ if(mode & 8) return value; |
|
60 |
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; |
|
61 |
/******/ var ns = Object.create(null); |
|
62 |
/******/ __webpack_require__.r(ns); |
|
63 |
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); |
|
64 |
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); |
|
65 |
/******/ return ns; |
|
66 |
/******/ }; |
|
67 |
/******/ |
|
68 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
|
69 |
/******/ __webpack_require__.n = function(module) { |
|
70 |
/******/ var getter = module && module.__esModule ? |
|
71 |
/******/ function getDefault() { return module['default']; } : |
|
72 |
/******/ function getModuleExports() { return module; }; |
|
73 |
/******/ __webpack_require__.d(getter, 'a', getter); |
|
74 |
/******/ return getter; |
|
75 |
/******/ }; |
|
76 |
/******/ |
|
77 |
/******/ // Object.prototype.hasOwnProperty.call |
|
78 |
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; |
|
79 |
/******/ |
|
80 |
/******/ // __webpack_public_path__ |
|
81 |
/******/ __webpack_require__.p = ""; |
|
82 |
/******/ |
|
83 |
/******/ |
|
84 |
/******/ // Load entry module and return exports |
18
|
85 |
/******/ return __webpack_require__(__webpack_require__.s = "SdGz"); |
9
|
86 |
/******/ }) |
|
87 |
/************************************************************************/ |
|
88 |
/******/ ({ |
|
89 |
|
18
|
90 |
/***/ "GRId": |
9
|
91 |
/***/ (function(module, exports) { |
|
92 |
|
18
|
93 |
(function() { module.exports = window["wp"]["element"]; }()); |
16
|
94 |
|
|
95 |
/***/ }), |
|
96 |
|
18
|
97 |
/***/ "K9lf": |
|
98 |
/***/ (function(module, exports) { |
9
|
99 |
|
18
|
100 |
(function() { module.exports = window["wp"]["compose"]; }()); |
9
|
101 |
|
|
102 |
/***/ }), |
|
103 |
|
18
|
104 |
/***/ "SdGz": |
9
|
105 |
/***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
106 |
|
|
107 |
"use strict"; |
16
|
108 |
// ESM COMPAT FLAG |
9
|
109 |
__webpack_require__.r(__webpack_exports__); |
|
110 |
|
18
|
111 |
// EXTERNAL MODULE: external ["wp","element"] |
|
112 |
var external_wp_element_ = __webpack_require__("GRId"); |
9
|
113 |
|
18
|
114 |
// EXTERNAL MODULE: external ["wp","i18n"] |
|
115 |
var external_wp_i18n_ = __webpack_require__("l3Sj"); |
9
|
116 |
|
18
|
117 |
// EXTERNAL MODULE: external "lodash" |
|
118 |
var external_lodash_ = __webpack_require__("YLtl"); |
9
|
119 |
|
18
|
120 |
// EXTERNAL MODULE: external ["wp","apiFetch"] |
|
121 |
var external_wp_apiFetch_ = __webpack_require__("ywyh"); |
|
122 |
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_); |
9
|
123 |
|
|
124 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js |
|
125 |
/** |
|
126 |
* Downloads a file. |
|
127 |
* |
|
128 |
* @param {string} fileName File Name. |
|
129 |
* @param {string} content File Content. |
|
130 |
* @param {string} contentType File mime type. |
|
131 |
*/ |
|
132 |
function download(fileName, content, contentType) { |
18
|
133 |
const file = new window.Blob([content], { |
9
|
134 |
type: contentType |
|
135 |
}); // IE11 can't use the click to download technique |
|
136 |
// we use a specific IE11 technique instead. |
|
137 |
|
|
138 |
if (window.navigator.msSaveOrOpenBlob) { |
|
139 |
window.navigator.msSaveOrOpenBlob(file, fileName); |
|
140 |
} else { |
18
|
141 |
const a = document.createElement('a'); |
9
|
142 |
a.href = URL.createObjectURL(file); |
|
143 |
a.download = fileName; |
|
144 |
a.style.display = 'none'; |
|
145 |
document.body.appendChild(a); |
|
146 |
a.click(); |
|
147 |
document.body.removeChild(a); |
|
148 |
} |
|
149 |
} |
|
150 |
/** |
|
151 |
* Reads the textual content of the given file. |
|
152 |
* |
|
153 |
* @param {File} file File. |
|
154 |
* @return {Promise<string>} Content of the file. |
|
155 |
*/ |
|
156 |
|
|
157 |
function readTextFile(file) { |
18
|
158 |
const reader = new window.FileReader(); |
|
159 |
return new Promise(resolve => { |
|
160 |
reader.onload = () => { |
9
|
161 |
resolve(reader.result); |
|
162 |
}; |
|
163 |
|
|
164 |
reader.readAsText(file); |
|
165 |
}); |
|
166 |
} |
|
167 |
|
|
168 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js |
|
169 |
/** |
|
170 |
* External dependencies |
|
171 |
*/ |
|
172 |
|
|
173 |
/** |
|
174 |
* WordPress dependencies |
|
175 |
*/ |
|
176 |
|
|
177 |
|
|
178 |
/** |
|
179 |
* Internal dependencies |
|
180 |
*/ |
|
181 |
|
|
182 |
|
|
183 |
/** |
|
184 |
* Export a reusable block as a JSON file. |
|
185 |
* |
|
186 |
* @param {number} id |
|
187 |
*/ |
|
188 |
|
18
|
189 |
async function exportReusableBlock(id) { |
|
190 |
const postType = await external_wp_apiFetch_default()({ |
|
191 |
path: `/wp/v2/types/wp_block` |
|
192 |
}); |
|
193 |
const post = await external_wp_apiFetch_default()({ |
|
194 |
path: `/wp/v2/${postType.rest_base}/${id}?context=edit` |
|
195 |
}); |
|
196 |
const title = post.title.raw; |
|
197 |
const content = post.content.raw; |
|
198 |
const fileContent = JSON.stringify({ |
|
199 |
__file: 'wp_block', |
|
200 |
title, |
|
201 |
content |
|
202 |
}, null, 2); |
|
203 |
const fileName = Object(external_lodash_["kebabCase"])(title) + '.json'; |
|
204 |
download(fileName, fileContent, 'application/json'); |
9
|
205 |
} |
|
206 |
|
|
207 |
/* harmony default export */ var utils_export = (exportReusableBlock); |
|
208 |
|
18
|
209 |
// EXTERNAL MODULE: external ["wp","components"] |
|
210 |
var external_wp_components_ = __webpack_require__("tI+e"); |
9
|
211 |
|
18
|
212 |
// EXTERNAL MODULE: external ["wp","compose"] |
|
213 |
var external_wp_compose_ = __webpack_require__("K9lf"); |
9
|
214 |
|
|
215 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js |
|
216 |
/** |
|
217 |
* External dependencies |
|
218 |
*/ |
|
219 |
|
|
220 |
/** |
|
221 |
* WordPress dependencies |
|
222 |
*/ |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
226 |
* Internal dependencies |
|
227 |
*/ |
|
228 |
|
|
229 |
|
|
230 |
/** |
|
231 |
* Import a reusable block from a JSON file. |
|
232 |
* |
|
233 |
* @param {File} file File. |
|
234 |
* @return {Promise} Promise returning the imported reusable block. |
|
235 |
*/ |
|
236 |
|
18
|
237 |
async function importReusableBlock(file) { |
|
238 |
const fileContent = await readTextFile(file); |
|
239 |
let parsedContent; |
9
|
240 |
|
18
|
241 |
try { |
|
242 |
parsedContent = JSON.parse(fileContent); |
|
243 |
} catch (e) { |
|
244 |
throw new Error('Invalid JSON file'); |
|
245 |
} |
9
|
246 |
|
18
|
247 |
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !Object(external_lodash_["isString"])(parsedContent.title) || !Object(external_lodash_["isString"])(parsedContent.content)) { |
|
248 |
throw new Error('Invalid Reusable block JSON file'); |
|
249 |
} |
9
|
250 |
|
18
|
251 |
const postType = await external_wp_apiFetch_default()({ |
|
252 |
path: `/wp/v2/types/wp_block` |
|
253 |
}); |
|
254 |
const reusableBlock = await external_wp_apiFetch_default()({ |
|
255 |
path: `/wp/v2/${postType.rest_base}`, |
|
256 |
data: { |
|
257 |
title: parsedContent.title, |
|
258 |
content: parsedContent.content, |
|
259 |
status: 'publish' |
|
260 |
}, |
|
261 |
method: 'POST' |
|
262 |
}); |
|
263 |
return reusableBlock; |
9
|
264 |
} |
|
265 |
|
|
266 |
/* harmony default export */ var utils_import = (importReusableBlock); |
|
267 |
|
|
268 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js |
|
269 |
|
|
270 |
|
|
271 |
/** |
|
272 |
* WordPress dependencies |
|
273 |
*/ |
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
/** |
|
279 |
* Internal dependencies |
|
280 |
*/ |
|
281 |
|
|
282 |
|
|
283 |
|
18
|
284 |
class import_form_ImportForm extends external_wp_element_["Component"] { |
|
285 |
constructor() { |
|
286 |
super(...arguments); |
|
287 |
this.state = { |
9
|
288 |
isLoading: false, |
|
289 |
error: null, |
|
290 |
file: null |
|
291 |
}; |
18
|
292 |
this.isStillMounted = true; |
|
293 |
this.onChangeFile = this.onChangeFile.bind(this); |
|
294 |
this.onSubmit = this.onSubmit.bind(this); |
|
295 |
} |
|
296 |
|
|
297 |
componentWillUnmount() { |
|
298 |
this.isStillMounted = false; |
|
299 |
} |
|
300 |
|
|
301 |
onChangeFile(event) { |
|
302 |
this.setState({ |
|
303 |
file: event.target.files[0], |
|
304 |
error: null |
|
305 |
}); |
9
|
306 |
} |
|
307 |
|
18
|
308 |
onSubmit(event) { |
|
309 |
event.preventDefault(); |
|
310 |
const { |
|
311 |
file |
|
312 |
} = this.state; |
|
313 |
const { |
|
314 |
onUpload |
|
315 |
} = this.props; |
|
316 |
|
|
317 |
if (!file) { |
|
318 |
return; |
9
|
319 |
} |
|
320 |
|
18
|
321 |
this.setState({ |
|
322 |
isLoading: true |
|
323 |
}); |
|
324 |
utils_import(file).then(reusableBlock => { |
|
325 |
if (!this.isStillMounted) { |
9
|
326 |
return; |
|
327 |
} |
|
328 |
|
|
329 |
this.setState({ |
18
|
330 |
isLoading: false |
9
|
331 |
}); |
18
|
332 |
onUpload(reusableBlock); |
|
333 |
}).catch(error => { |
|
334 |
if (!this.isStillMounted) { |
|
335 |
return; |
|
336 |
} |
9
|
337 |
|
18
|
338 |
let uiMessage; |
9
|
339 |
|
18
|
340 |
switch (error.message) { |
|
341 |
case 'Invalid JSON file': |
|
342 |
uiMessage = Object(external_wp_i18n_["__"])('Invalid JSON file'); |
|
343 |
break; |
9
|
344 |
|
18
|
345 |
case 'Invalid Reusable block JSON file': |
|
346 |
uiMessage = Object(external_wp_i18n_["__"])('Invalid Reusable block JSON file'); |
|
347 |
break; |
9
|
348 |
|
18
|
349 |
default: |
|
350 |
uiMessage = Object(external_wp_i18n_["__"])('Unknown error'); |
|
351 |
} |
9
|
352 |
|
18
|
353 |
this.setState({ |
|
354 |
isLoading: false, |
|
355 |
error: uiMessage |
9
|
356 |
}); |
18
|
357 |
}); |
|
358 |
} |
|
359 |
|
|
360 |
onDismissError() { |
|
361 |
this.setState({ |
|
362 |
error: null |
|
363 |
}); |
|
364 |
} |
9
|
365 |
|
18
|
366 |
render() { |
|
367 |
const { |
|
368 |
instanceId |
|
369 |
} = this.props; |
|
370 |
const { |
|
371 |
file, |
|
372 |
isLoading, |
|
373 |
error |
|
374 |
} = this.state; |
|
375 |
const inputId = 'list-reusable-blocks-import-form-' + instanceId; |
|
376 |
return Object(external_wp_element_["createElement"])("form", { |
|
377 |
className: "list-reusable-blocks-import-form", |
|
378 |
onSubmit: this.onSubmit |
|
379 |
}, error && Object(external_wp_element_["createElement"])(external_wp_components_["Notice"], { |
|
380 |
status: "error", |
|
381 |
onRemove: () => this.onDismissError() |
|
382 |
}, error), Object(external_wp_element_["createElement"])("label", { |
|
383 |
htmlFor: inputId, |
|
384 |
className: "list-reusable-blocks-import-form__label" |
|
385 |
}, Object(external_wp_i18n_["__"])('File')), Object(external_wp_element_["createElement"])("input", { |
|
386 |
id: inputId, |
|
387 |
type: "file", |
|
388 |
onChange: this.onChangeFile |
|
389 |
}), Object(external_wp_element_["createElement"])(external_wp_components_["Button"], { |
|
390 |
type: "submit", |
|
391 |
isBusy: isLoading, |
|
392 |
disabled: !file || isLoading, |
|
393 |
isSecondary: true, |
|
394 |
className: "list-reusable-blocks-import-form__button" |
|
395 |
}, Object(external_wp_i18n_["_x"])('Import', 'button label'))); |
|
396 |
} |
9
|
397 |
|
18
|
398 |
} |
|
399 |
|
|
400 |
/* harmony default export */ var import_form = (Object(external_wp_compose_["withInstanceId"])(import_form_ImportForm)); |
9
|
401 |
|
|
402 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js |
|
403 |
|
|
404 |
|
|
405 |
/** |
|
406 |
* External dependencies |
|
407 |
*/ |
|
408 |
|
|
409 |
/** |
|
410 |
* WordPress dependencies |
|
411 |
*/ |
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
/** |
|
416 |
* Internal dependencies |
|
417 |
*/ |
|
418 |
|
|
419 |
|
|
420 |
|
18
|
421 |
function ImportDropdown({ |
|
422 |
onUpload |
|
423 |
}) { |
|
424 |
return Object(external_wp_element_["createElement"])(external_wp_components_["Dropdown"], { |
9
|
425 |
position: "bottom right", |
|
426 |
contentClassName: "list-reusable-blocks-import-dropdown__content", |
18
|
427 |
renderToggle: ({ |
|
428 |
isOpen, |
|
429 |
onToggle |
|
430 |
}) => Object(external_wp_element_["createElement"])(external_wp_components_["Button"], { |
|
431 |
"aria-expanded": isOpen, |
|
432 |
onClick: onToggle, |
|
433 |
isPrimary: true |
|
434 |
}, Object(external_wp_i18n_["__"])('Import from JSON')), |
|
435 |
renderContent: ({ |
|
436 |
onClose |
|
437 |
}) => Object(external_wp_element_["createElement"])(import_form, { |
|
438 |
onUpload: Object(external_lodash_["flow"])(onClose, onUpload) |
|
439 |
}) |
9
|
440 |
}); |
|
441 |
} |
|
442 |
|
|
443 |
/* harmony default export */ var import_dropdown = (ImportDropdown); |
|
444 |
|
|
445 |
// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/index.js |
|
446 |
|
|
447 |
|
|
448 |
/** |
|
449 |
* WordPress dependencies |
|
450 |
*/ |
|
451 |
|
|
452 |
|
|
453 |
/** |
|
454 |
* Internal dependencies |
|
455 |
*/ |
|
456 |
|
|
457 |
|
|
458 |
// Setup Export Links |
|
459 |
|
18
|
460 |
document.body.addEventListener('click', event => { |
9
|
461 |
if (!event.target.classList.contains('wp-list-reusable-blocks__export')) { |
|
462 |
return; |
|
463 |
} |
|
464 |
|
|
465 |
event.preventDefault(); |
|
466 |
utils_export(event.target.dataset.id); |
|
467 |
}); // Setup Import Form |
|
468 |
|
18
|
469 |
document.addEventListener('DOMContentLoaded', () => { |
|
470 |
const button = document.querySelector('.page-title-action'); |
9
|
471 |
|
|
472 |
if (!button) { |
|
473 |
return; |
|
474 |
} |
|
475 |
|
18
|
476 |
const showNotice = () => { |
|
477 |
const notice = document.createElement('div'); |
9
|
478 |
notice.className = 'notice notice-success is-dismissible'; |
18
|
479 |
notice.innerHTML = `<p>${Object(external_wp_i18n_["__"])('Reusable block imported successfully!')}</p>`; |
|
480 |
const headerEnd = document.querySelector('.wp-header-end'); |
9
|
481 |
|
|
482 |
if (!headerEnd) { |
|
483 |
return; |
|
484 |
} |
|
485 |
|
|
486 |
headerEnd.parentNode.insertBefore(notice, headerEnd); |
|
487 |
}; |
|
488 |
|
18
|
489 |
const container = document.createElement('div'); |
9
|
490 |
container.className = 'list-reusable-blocks__container'; |
|
491 |
button.parentNode.insertBefore(container, button); |
18
|
492 |
Object(external_wp_element_["render"])(Object(external_wp_element_["createElement"])(import_dropdown, { |
9
|
493 |
onUpload: showNotice |
|
494 |
}), container); |
|
495 |
}); |
|
496 |
|
|
497 |
|
|
498 |
/***/ }), |
|
499 |
|
18
|
500 |
/***/ "YLtl": |
|
501 |
/***/ (function(module, exports) { |
9
|
502 |
|
18
|
503 |
(function() { module.exports = window["lodash"]; }()); |
9
|
504 |
|
|
505 |
/***/ }), |
|
506 |
|
18
|
507 |
/***/ "l3Sj": |
9
|
508 |
/***/ (function(module, exports) { |
|
509 |
|
18
|
510 |
(function() { module.exports = window["wp"]["i18n"]; }()); |
|
511 |
|
|
512 |
/***/ }), |
|
513 |
|
|
514 |
/***/ "tI+e": |
|
515 |
/***/ (function(module, exports) { |
|
516 |
|
|
517 |
(function() { module.exports = window["wp"]["components"]; }()); |
|
518 |
|
|
519 |
/***/ }), |
|
520 |
|
|
521 |
/***/ "ywyh": |
|
522 |
/***/ (function(module, exports) { |
|
523 |
|
|
524 |
(function() { module.exports = window["wp"]["apiFetch"]; }()); |
9
|
525 |
|
|
526 |
/***/ }) |
|
527 |
|
|
528 |
/******/ }); |