19
|
1 |
/******/ (function() { // webpackBootstrap |
|
2 |
/******/ "use strict"; |
|
3 |
/******/ // The require scope |
|
4 |
/******/ var __webpack_require__ = {}; |
|
5 |
/******/ |
|
6 |
/************************************************************************/ |
|
7 |
/******/ /* webpack/runtime/compat get default export */ |
|
8 |
/******/ !function() { |
|
9 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
|
10 |
/******/ __webpack_require__.n = function(module) { |
|
11 |
/******/ var getter = module && module.__esModule ? |
|
12 |
/******/ function() { return module['default']; } : |
|
13 |
/******/ function() { return module; }; |
|
14 |
/******/ __webpack_require__.d(getter, { a: getter }); |
|
15 |
/******/ return getter; |
9
|
16 |
/******/ }; |
19
|
17 |
/******/ }(); |
|
18 |
/******/ |
|
19 |
/******/ /* webpack/runtime/define property getters */ |
|
20 |
/******/ !function() { |
|
21 |
/******/ // define getter functions for harmony exports |
|
22 |
/******/ __webpack_require__.d = function(exports, definition) { |
|
23 |
/******/ for(var key in definition) { |
|
24 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
|
25 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
|
26 |
/******/ } |
|
27 |
/******/ } |
|
28 |
/******/ }; |
|
29 |
/******/ }(); |
|
30 |
/******/ |
|
31 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
|
32 |
/******/ !function() { |
|
33 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } |
|
34 |
/******/ }(); |
|
35 |
/******/ |
|
36 |
/******/ /* webpack/runtime/make namespace object */ |
|
37 |
/******/ !function() { |
|
38 |
/******/ // define __esModule on exports |
|
39 |
/******/ __webpack_require__.r = function(exports) { |
|
40 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
|
41 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
|
42 |
/******/ } |
|
43 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
|
44 |
/******/ }; |
|
45 |
/******/ }(); |
|
46 |
/******/ |
9
|
47 |
/************************************************************************/ |
19
|
48 |
var __webpack_exports__ = {}; |
16
|
49 |
// ESM COMPAT FLAG |
9
|
50 |
__webpack_require__.r(__webpack_exports__); |
|
51 |
|
19
|
52 |
;// CONCATENATED MODULE: external ["wp","element"] |
|
53 |
var external_wp_element_namespaceObject = window["wp"]["element"]; |
|
54 |
;// CONCATENATED MODULE: external ["wp","i18n"] |
|
55 |
var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
|
56 |
;// CONCATENATED MODULE: external "lodash" |
|
57 |
var external_lodash_namespaceObject = window["lodash"]; |
|
58 |
;// CONCATENATED MODULE: external ["wp","apiFetch"] |
|
59 |
var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"]; |
|
60 |
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject); |
|
61 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js |
9
|
62 |
/** |
|
63 |
* Downloads a file. |
|
64 |
* |
|
65 |
* @param {string} fileName File Name. |
|
66 |
* @param {string} content File Content. |
|
67 |
* @param {string} contentType File mime type. |
|
68 |
*/ |
|
69 |
function download(fileName, content, contentType) { |
18
|
70 |
const file = new window.Blob([content], { |
9
|
71 |
type: contentType |
|
72 |
}); // IE11 can't use the click to download technique |
|
73 |
// we use a specific IE11 technique instead. |
|
74 |
|
|
75 |
if (window.navigator.msSaveOrOpenBlob) { |
|
76 |
window.navigator.msSaveOrOpenBlob(file, fileName); |
|
77 |
} else { |
18
|
78 |
const a = document.createElement('a'); |
9
|
79 |
a.href = URL.createObjectURL(file); |
|
80 |
a.download = fileName; |
|
81 |
a.style.display = 'none'; |
|
82 |
document.body.appendChild(a); |
|
83 |
a.click(); |
|
84 |
document.body.removeChild(a); |
|
85 |
} |
|
86 |
} |
|
87 |
/** |
|
88 |
* Reads the textual content of the given file. |
|
89 |
* |
19
|
90 |
* @param {File} file File. |
9
|
91 |
* @return {Promise<string>} Content of the file. |
|
92 |
*/ |
|
93 |
|
|
94 |
function readTextFile(file) { |
18
|
95 |
const reader = new window.FileReader(); |
|
96 |
return new Promise(resolve => { |
|
97 |
reader.onload = () => { |
9
|
98 |
resolve(reader.result); |
|
99 |
}; |
|
100 |
|
|
101 |
reader.readAsText(file); |
|
102 |
}); |
|
103 |
} |
|
104 |
|
19
|
105 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js |
9
|
106 |
/** |
|
107 |
* External dependencies |
|
108 |
*/ |
|
109 |
|
|
110 |
/** |
|
111 |
* WordPress dependencies |
|
112 |
*/ |
|
113 |
|
|
114 |
|
|
115 |
/** |
|
116 |
* Internal dependencies |
|
117 |
*/ |
|
118 |
|
|
119 |
|
|
120 |
/** |
|
121 |
* Export a reusable block as a JSON file. |
|
122 |
* |
|
123 |
* @param {number} id |
|
124 |
*/ |
|
125 |
|
18
|
126 |
async function exportReusableBlock(id) { |
|
127 |
const postType = await external_wp_apiFetch_default()({ |
|
128 |
path: `/wp/v2/types/wp_block` |
|
129 |
}); |
|
130 |
const post = await external_wp_apiFetch_default()({ |
|
131 |
path: `/wp/v2/${postType.rest_base}/${id}?context=edit` |
|
132 |
}); |
|
133 |
const title = post.title.raw; |
|
134 |
const content = post.content.raw; |
|
135 |
const fileContent = JSON.stringify({ |
|
136 |
__file: 'wp_block', |
|
137 |
title, |
|
138 |
content |
|
139 |
}, null, 2); |
19
|
140 |
const fileName = (0,external_lodash_namespaceObject.kebabCase)(title) + '.json'; |
18
|
141 |
download(fileName, fileContent, 'application/json'); |
9
|
142 |
} |
|
143 |
|
|
144 |
/* harmony default export */ var utils_export = (exportReusableBlock); |
|
145 |
|
19
|
146 |
;// CONCATENATED MODULE: external ["wp","components"] |
|
147 |
var external_wp_components_namespaceObject = window["wp"]["components"]; |
|
148 |
;// CONCATENATED MODULE: external ["wp","compose"] |
|
149 |
var external_wp_compose_namespaceObject = window["wp"]["compose"]; |
|
150 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js |
9
|
151 |
/** |
|
152 |
* External dependencies |
|
153 |
*/ |
|
154 |
|
|
155 |
/** |
|
156 |
* WordPress dependencies |
|
157 |
*/ |
|
158 |
|
|
159 |
|
|
160 |
/** |
|
161 |
* Internal dependencies |
|
162 |
*/ |
|
163 |
|
|
164 |
|
|
165 |
/** |
|
166 |
* Import a reusable block from a JSON file. |
|
167 |
* |
19
|
168 |
* @param {File} file File. |
9
|
169 |
* @return {Promise} Promise returning the imported reusable block. |
|
170 |
*/ |
|
171 |
|
18
|
172 |
async function importReusableBlock(file) { |
|
173 |
const fileContent = await readTextFile(file); |
|
174 |
let parsedContent; |
9
|
175 |
|
18
|
176 |
try { |
|
177 |
parsedContent = JSON.parse(fileContent); |
|
178 |
} catch (e) { |
|
179 |
throw new Error('Invalid JSON file'); |
|
180 |
} |
9
|
181 |
|
19
|
182 |
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !(0,external_lodash_namespaceObject.isString)(parsedContent.title) || !(0,external_lodash_namespaceObject.isString)(parsedContent.content)) { |
18
|
183 |
throw new Error('Invalid Reusable block JSON file'); |
|
184 |
} |
9
|
185 |
|
18
|
186 |
const postType = await external_wp_apiFetch_default()({ |
|
187 |
path: `/wp/v2/types/wp_block` |
|
188 |
}); |
|
189 |
const reusableBlock = await external_wp_apiFetch_default()({ |
|
190 |
path: `/wp/v2/${postType.rest_base}`, |
|
191 |
data: { |
|
192 |
title: parsedContent.title, |
|
193 |
content: parsedContent.content, |
|
194 |
status: 'publish' |
|
195 |
}, |
|
196 |
method: 'POST' |
|
197 |
}); |
|
198 |
return reusableBlock; |
9
|
199 |
} |
|
200 |
|
|
201 |
/* harmony default export */ var utils_import = (importReusableBlock); |
|
202 |
|
19
|
203 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js |
9
|
204 |
|
|
205 |
|
|
206 |
/** |
|
207 |
* WordPress dependencies |
|
208 |
*/ |
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
/** |
|
214 |
* Internal dependencies |
|
215 |
*/ |
|
216 |
|
|
217 |
|
|
218 |
|
19
|
219 |
function ImportForm(_ref) { |
|
220 |
let { |
|
221 |
instanceId, |
|
222 |
onUpload |
|
223 |
} = _ref; |
|
224 |
const inputId = 'list-reusable-blocks-import-form-' + instanceId; |
|
225 |
const formRef = (0,external_wp_element_namespaceObject.useRef)(); |
|
226 |
const [isLoading, setIsLoading] = (0,external_wp_element_namespaceObject.useState)(false); |
|
227 |
const [error, setError] = (0,external_wp_element_namespaceObject.useState)(null); |
|
228 |
const [file, setFile] = (0,external_wp_element_namespaceObject.useState)(null); |
18
|
229 |
|
19
|
230 |
const onChangeFile = event => { |
|
231 |
setFile(event.target.files[0]); |
|
232 |
setError(null); |
|
233 |
}; |
18
|
234 |
|
19
|
235 |
const onSubmit = event => { |
18
|
236 |
event.preventDefault(); |
|
237 |
|
|
238 |
if (!file) { |
|
239 |
return; |
9
|
240 |
} |
|
241 |
|
19
|
242 |
setIsLoading({ |
18
|
243 |
isLoading: true |
|
244 |
}); |
|
245 |
utils_import(file).then(reusableBlock => { |
19
|
246 |
if (!formRef) { |
9
|
247 |
return; |
|
248 |
} |
|
249 |
|
19
|
250 |
setIsLoading(false); |
18
|
251 |
onUpload(reusableBlock); |
19
|
252 |
}).catch(errors => { |
|
253 |
if (!formRef) { |
18
|
254 |
return; |
|
255 |
} |
9
|
256 |
|
18
|
257 |
let uiMessage; |
9
|
258 |
|
19
|
259 |
switch (errors.message) { |
18
|
260 |
case 'Invalid JSON file': |
19
|
261 |
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Invalid JSON file'); |
18
|
262 |
break; |
9
|
263 |
|
18
|
264 |
case 'Invalid Reusable block JSON file': |
19
|
265 |
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Invalid Reusable block JSON file'); |
18
|
266 |
break; |
9
|
267 |
|
18
|
268 |
default: |
19
|
269 |
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Unknown error'); |
18
|
270 |
} |
9
|
271 |
|
19
|
272 |
setIsLoading(false); |
|
273 |
setError(uiMessage); |
18
|
274 |
}); |
19
|
275 |
}; |
18
|
276 |
|
19
|
277 |
const onDismissError = () => { |
|
278 |
setError(null); |
|
279 |
}; |
9
|
280 |
|
19
|
281 |
return (0,external_wp_element_namespaceObject.createElement)("form", { |
|
282 |
className: "list-reusable-blocks-import-form", |
|
283 |
onSubmit: onSubmit, |
|
284 |
ref: formRef |
|
285 |
}, error && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Notice, { |
|
286 |
status: "error", |
|
287 |
onRemove: () => onDismissError() |
|
288 |
}, error), (0,external_wp_element_namespaceObject.createElement)("label", { |
|
289 |
htmlFor: inputId, |
|
290 |
className: "list-reusable-blocks-import-form__label" |
|
291 |
}, (0,external_wp_i18n_namespaceObject.__)('File')), (0,external_wp_element_namespaceObject.createElement)("input", { |
|
292 |
id: inputId, |
|
293 |
type: "file", |
|
294 |
onChange: onChangeFile |
|
295 |
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { |
|
296 |
type: "submit", |
|
297 |
isBusy: isLoading, |
|
298 |
disabled: !file || isLoading, |
|
299 |
variant: "secondary", |
|
300 |
className: "list-reusable-blocks-import-form__button" |
|
301 |
}, (0,external_wp_i18n_namespaceObject._x)('Import', 'button label'))); |
18
|
302 |
} |
|
303 |
|
19
|
304 |
/* harmony default export */ var import_form = ((0,external_wp_compose_namespaceObject.withInstanceId)(ImportForm)); |
9
|
305 |
|
19
|
306 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js |
9
|
307 |
|
|
308 |
|
|
309 |
/** |
|
310 |
* External dependencies |
|
311 |
*/ |
|
312 |
|
|
313 |
/** |
|
314 |
* WordPress dependencies |
|
315 |
*/ |
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
/** |
|
320 |
* Internal dependencies |
|
321 |
*/ |
|
322 |
|
|
323 |
|
|
324 |
|
19
|
325 |
function ImportDropdown(_ref) { |
|
326 |
let { |
|
327 |
onUpload |
|
328 |
} = _ref; |
|
329 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Dropdown, { |
9
|
330 |
position: "bottom right", |
|
331 |
contentClassName: "list-reusable-blocks-import-dropdown__content", |
19
|
332 |
renderToggle: _ref2 => { |
|
333 |
let { |
|
334 |
isOpen, |
|
335 |
onToggle |
|
336 |
} = _ref2; |
|
337 |
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, { |
|
338 |
"aria-expanded": isOpen, |
|
339 |
onClick: onToggle, |
|
340 |
variant: "primary" |
|
341 |
}, (0,external_wp_i18n_namespaceObject.__)('Import from JSON')); |
|
342 |
}, |
|
343 |
renderContent: _ref3 => { |
|
344 |
let { |
|
345 |
onClose |
|
346 |
} = _ref3; |
|
347 |
return (0,external_wp_element_namespaceObject.createElement)(import_form, { |
|
348 |
onUpload: (0,external_lodash_namespaceObject.flow)(onClose, onUpload) |
|
349 |
}); |
|
350 |
} |
9
|
351 |
}); |
|
352 |
} |
|
353 |
|
|
354 |
/* harmony default export */ var import_dropdown = (ImportDropdown); |
|
355 |
|
19
|
356 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/index.js |
9
|
357 |
|
|
358 |
|
|
359 |
/** |
|
360 |
* WordPress dependencies |
|
361 |
*/ |
|
362 |
|
|
363 |
|
|
364 |
/** |
|
365 |
* Internal dependencies |
|
366 |
*/ |
|
367 |
|
|
368 |
|
19
|
369 |
// Setup Export Links. |
9
|
370 |
|
18
|
371 |
document.body.addEventListener('click', event => { |
9
|
372 |
if (!event.target.classList.contains('wp-list-reusable-blocks__export')) { |
|
373 |
return; |
|
374 |
} |
|
375 |
|
|
376 |
event.preventDefault(); |
|
377 |
utils_export(event.target.dataset.id); |
19
|
378 |
}); // Setup Import Form. |
9
|
379 |
|
18
|
380 |
document.addEventListener('DOMContentLoaded', () => { |
|
381 |
const button = document.querySelector('.page-title-action'); |
9
|
382 |
|
|
383 |
if (!button) { |
|
384 |
return; |
|
385 |
} |
|
386 |
|
18
|
387 |
const showNotice = () => { |
|
388 |
const notice = document.createElement('div'); |
9
|
389 |
notice.className = 'notice notice-success is-dismissible'; |
19
|
390 |
notice.innerHTML = `<p>${(0,external_wp_i18n_namespaceObject.__)('Reusable block imported successfully!')}</p>`; |
18
|
391 |
const headerEnd = document.querySelector('.wp-header-end'); |
9
|
392 |
|
|
393 |
if (!headerEnd) { |
|
394 |
return; |
|
395 |
} |
|
396 |
|
|
397 |
headerEnd.parentNode.insertBefore(notice, headerEnd); |
|
398 |
}; |
|
399 |
|
18
|
400 |
const container = document.createElement('div'); |
9
|
401 |
container.className = 'list-reusable-blocks__container'; |
|
402 |
button.parentNode.insertBefore(container, button); |
19
|
403 |
(0,external_wp_element_namespaceObject.render)((0,external_wp_element_namespaceObject.createElement)(import_dropdown, { |
9
|
404 |
onUpload: showNotice |
|
405 |
}), container); |
|
406 |
}); |
|
407 |
|
19
|
408 |
(window.wp = window.wp || {}).listReusableBlocks = __webpack_exports__; |
|
409 |
/******/ })() |
|
410 |
; |