80 /******/ // __webpack_public_path__ |
80 /******/ // __webpack_public_path__ |
81 /******/ __webpack_require__.p = ""; |
81 /******/ __webpack_require__.p = ""; |
82 /******/ |
82 /******/ |
83 /******/ |
83 /******/ |
84 /******/ // Load entry module and return exports |
84 /******/ // Load entry module and return exports |
85 /******/ return __webpack_require__(__webpack_require__.s = 457); |
85 /******/ return __webpack_require__(__webpack_require__.s = "SdGz"); |
86 /******/ }) |
86 /******/ }) |
87 /************************************************************************/ |
87 /************************************************************************/ |
88 /******/ ({ |
88 /******/ ({ |
89 |
89 |
90 /***/ 0: |
90 /***/ "GRId": |
91 /***/ (function(module, exports) { |
91 /***/ (function(module, exports) { |
92 |
92 |
93 (function() { module.exports = this["wp"]["element"]; }()); |
93 (function() { module.exports = window["wp"]["element"]; }()); |
94 |
94 |
95 /***/ }), |
95 /***/ }), |
96 |
96 |
97 /***/ 1: |
97 /***/ "K9lf": |
98 /***/ (function(module, exports) { |
98 /***/ (function(module, exports) { |
99 |
99 |
100 (function() { module.exports = this["wp"]["i18n"]; }()); |
100 (function() { module.exports = window["wp"]["compose"]; }()); |
101 |
101 |
102 /***/ }), |
102 /***/ }), |
103 |
103 |
104 /***/ 12: |
104 /***/ "SdGz": |
105 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
106 |
|
107 "use strict"; |
|
108 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _assertThisInitialized; }); |
|
109 function _assertThisInitialized(self) { |
|
110 if (self === void 0) { |
|
111 throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); |
|
112 } |
|
113 |
|
114 return self; |
|
115 } |
|
116 |
|
117 /***/ }), |
|
118 |
|
119 /***/ 16: |
|
120 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
121 |
|
122 "use strict"; |
|
123 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _getPrototypeOf; }); |
|
124 function _getPrototypeOf(o) { |
|
125 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { |
|
126 return o.__proto__ || Object.getPrototypeOf(o); |
|
127 }; |
|
128 return _getPrototypeOf(o); |
|
129 } |
|
130 |
|
131 /***/ }), |
|
132 |
|
133 /***/ 19: |
|
134 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
135 |
|
136 "use strict"; |
|
137 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; }); |
|
138 function _defineProperties(target, props) { |
|
139 for (var i = 0; i < props.length; i++) { |
|
140 var descriptor = props[i]; |
|
141 descriptor.enumerable = descriptor.enumerable || false; |
|
142 descriptor.configurable = true; |
|
143 if ("value" in descriptor) descriptor.writable = true; |
|
144 Object.defineProperty(target, descriptor.key, descriptor); |
|
145 } |
|
146 } |
|
147 |
|
148 function _createClass(Constructor, protoProps, staticProps) { |
|
149 if (protoProps) _defineProperties(Constructor.prototype, protoProps); |
|
150 if (staticProps) _defineProperties(Constructor, staticProps); |
|
151 return Constructor; |
|
152 } |
|
153 |
|
154 /***/ }), |
|
155 |
|
156 /***/ 2: |
|
157 /***/ (function(module, exports) { |
|
158 |
|
159 (function() { module.exports = this["lodash"]; }()); |
|
160 |
|
161 /***/ }), |
|
162 |
|
163 /***/ 20: |
|
164 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
165 |
|
166 "use strict"; |
|
167 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; }); |
|
168 function _classCallCheck(instance, Constructor) { |
|
169 if (!(instance instanceof Constructor)) { |
|
170 throw new TypeError("Cannot call a class as a function"); |
|
171 } |
|
172 } |
|
173 |
|
174 /***/ }), |
|
175 |
|
176 /***/ 22: |
|
177 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
178 |
|
179 "use strict"; |
|
180 |
|
181 // EXPORTS |
|
182 __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _inherits; }); |
|
183 |
|
184 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js |
|
185 function _setPrototypeOf(o, p) { |
|
186 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { |
|
187 o.__proto__ = p; |
|
188 return o; |
|
189 }; |
|
190 |
|
191 return _setPrototypeOf(o, p); |
|
192 } |
|
193 // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js |
|
194 |
|
195 function _inherits(subClass, superClass) { |
|
196 if (typeof superClass !== "function" && superClass !== null) { |
|
197 throw new TypeError("Super expression must either be null or a function"); |
|
198 } |
|
199 |
|
200 subClass.prototype = Object.create(superClass && superClass.prototype, { |
|
201 constructor: { |
|
202 value: subClass, |
|
203 writable: true, |
|
204 configurable: true |
|
205 } |
|
206 }); |
|
207 if (superClass) _setPrototypeOf(subClass, superClass); |
|
208 } |
|
209 |
|
210 /***/ }), |
|
211 |
|
212 /***/ 23: |
|
213 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
214 |
|
215 "use strict"; |
|
216 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _possibleConstructorReturn; }); |
|
217 /* harmony import */ var _helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(40); |
|
218 /* harmony import */ var _assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12); |
|
219 |
|
220 |
|
221 function _possibleConstructorReturn(self, call) { |
|
222 if (call && (Object(_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(call) === "object" || typeof call === "function")) { |
|
223 return call; |
|
224 } |
|
225 |
|
226 return Object(_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(self); |
|
227 } |
|
228 |
|
229 /***/ }), |
|
230 |
|
231 /***/ 24: |
|
232 /***/ (function(module, exports) { |
|
233 |
|
234 (function() { module.exports = this["regeneratorRuntime"]; }()); |
|
235 |
|
236 /***/ }), |
|
237 |
|
238 /***/ 3: |
|
239 /***/ (function(module, exports) { |
|
240 |
|
241 (function() { module.exports = this["wp"]["components"]; }()); |
|
242 |
|
243 /***/ }), |
|
244 |
|
245 /***/ 40: |
|
246 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
|
247 |
|
248 "use strict"; |
|
249 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _typeof; }); |
|
250 function _typeof(obj) { |
|
251 "@babel/helpers - typeof"; |
|
252 |
|
253 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
|
254 _typeof = function _typeof(obj) { |
|
255 return typeof obj; |
|
256 }; |
|
257 } else { |
|
258 _typeof = function _typeof(obj) { |
|
259 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; |
|
260 }; |
|
261 } |
|
262 |
|
263 return _typeof(obj); |
|
264 } |
|
265 |
|
266 /***/ }), |
|
267 |
|
268 /***/ 45: |
|
269 /***/ (function(module, exports) { |
|
270 |
|
271 (function() { module.exports = this["wp"]["apiFetch"]; }()); |
|
272 |
|
273 /***/ }), |
|
274 |
|
275 /***/ 457: |
|
276 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
105 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
277 |
106 |
278 "use strict"; |
107 "use strict"; |
279 // ESM COMPAT FLAG |
108 // ESM COMPAT FLAG |
280 __webpack_require__.r(__webpack_exports__); |
109 __webpack_require__.r(__webpack_exports__); |
281 |
110 |
282 // EXTERNAL MODULE: external {"this":["wp","element"]} |
111 // EXTERNAL MODULE: external ["wp","element"] |
283 var external_this_wp_element_ = __webpack_require__(0); |
112 var external_wp_element_ = __webpack_require__("GRId"); |
284 |
113 |
285 // EXTERNAL MODULE: external {"this":["wp","i18n"]} |
114 // EXTERNAL MODULE: external ["wp","i18n"] |
286 var external_this_wp_i18n_ = __webpack_require__(1); |
115 var external_wp_i18n_ = __webpack_require__("l3Sj"); |
287 |
116 |
288 // EXTERNAL MODULE: external {"this":"regeneratorRuntime"} |
117 // EXTERNAL MODULE: external "lodash" |
289 var external_this_regeneratorRuntime_ = __webpack_require__(24); |
118 var external_lodash_ = __webpack_require__("YLtl"); |
290 var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_); |
119 |
291 |
120 // EXTERNAL MODULE: external ["wp","apiFetch"] |
292 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js |
121 var external_wp_apiFetch_ = __webpack_require__("ywyh"); |
293 var asyncToGenerator = __webpack_require__(50); |
122 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_); |
294 |
|
295 // EXTERNAL MODULE: external {"this":"lodash"} |
|
296 var external_this_lodash_ = __webpack_require__(2); |
|
297 |
|
298 // EXTERNAL MODULE: external {"this":["wp","apiFetch"]} |
|
299 var external_this_wp_apiFetch_ = __webpack_require__(45); |
|
300 var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_); |
|
301 |
123 |
302 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js |
124 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js |
303 /** |
125 /** |
304 * Downloads a file. |
126 * Downloads a file. |
305 * |
127 * |
306 * @param {string} fileName File Name. |
128 * @param {string} fileName File Name. |
307 * @param {string} content File Content. |
129 * @param {string} content File Content. |
308 * @param {string} contentType File mime type. |
130 * @param {string} contentType File mime type. |
309 */ |
131 */ |
310 function download(fileName, content, contentType) { |
132 function download(fileName, content, contentType) { |
311 var file = new window.Blob([content], { |
133 const file = new window.Blob([content], { |
312 type: contentType |
134 type: contentType |
313 }); // IE11 can't use the click to download technique |
135 }); // IE11 can't use the click to download technique |
314 // we use a specific IE11 technique instead. |
136 // we use a specific IE11 technique instead. |
315 |
137 |
316 if (window.navigator.msSaveOrOpenBlob) { |
138 if (window.navigator.msSaveOrOpenBlob) { |
317 window.navigator.msSaveOrOpenBlob(file, fileName); |
139 window.navigator.msSaveOrOpenBlob(file, fileName); |
318 } else { |
140 } else { |
319 var a = document.createElement('a'); |
141 const a = document.createElement('a'); |
320 a.href = URL.createObjectURL(file); |
142 a.href = URL.createObjectURL(file); |
321 a.download = fileName; |
143 a.download = fileName; |
322 a.style.display = 'none'; |
144 a.style.display = 'none'; |
323 document.body.appendChild(a); |
145 document.body.appendChild(a); |
324 a.click(); |
146 a.click(); |
365 * Export a reusable block as a JSON file. |
184 * Export a reusable block as a JSON file. |
366 * |
185 * |
367 * @param {number} id |
186 * @param {number} id |
368 */ |
187 */ |
369 |
188 |
370 function exportReusableBlock(_x) { |
189 async function exportReusableBlock(id) { |
371 return _exportReusableBlock.apply(this, arguments); |
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'); |
372 } |
205 } |
373 |
206 |
374 function _exportReusableBlock() { |
|
375 _exportReusableBlock = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee(id) { |
|
376 var postType, post, title, content, fileContent, fileName; |
|
377 return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) { |
|
378 while (1) { |
|
379 switch (_context.prev = _context.next) { |
|
380 case 0: |
|
381 _context.next = 2; |
|
382 return external_this_wp_apiFetch_default()({ |
|
383 path: "/wp/v2/types/wp_block" |
|
384 }); |
|
385 |
|
386 case 2: |
|
387 postType = _context.sent; |
|
388 _context.next = 5; |
|
389 return external_this_wp_apiFetch_default()({ |
|
390 path: "/wp/v2/".concat(postType.rest_base, "/").concat(id, "?context=edit") |
|
391 }); |
|
392 |
|
393 case 5: |
|
394 post = _context.sent; |
|
395 title = post.title.raw; |
|
396 content = post.content.raw; |
|
397 fileContent = JSON.stringify({ |
|
398 __file: 'wp_block', |
|
399 title: title, |
|
400 content: content |
|
401 }, null, 2); |
|
402 fileName = Object(external_this_lodash_["kebabCase"])(title) + '.json'; |
|
403 download(fileName, fileContent, 'application/json'); |
|
404 |
|
405 case 11: |
|
406 case "end": |
|
407 return _context.stop(); |
|
408 } |
|
409 } |
|
410 }, _callee); |
|
411 })); |
|
412 return _exportReusableBlock.apply(this, arguments); |
|
413 } |
|
414 |
|
415 /* harmony default export */ var utils_export = (exportReusableBlock); |
207 /* harmony default export */ var utils_export = (exportReusableBlock); |
416 |
208 |
417 // EXTERNAL MODULE: external {"this":["wp","components"]} |
209 // EXTERNAL MODULE: external ["wp","components"] |
418 var external_this_wp_components_ = __webpack_require__(3); |
210 var external_wp_components_ = __webpack_require__("tI+e"); |
419 |
211 |
420 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js |
212 // EXTERNAL MODULE: external ["wp","compose"] |
421 var classCallCheck = __webpack_require__(20); |
213 var external_wp_compose_ = __webpack_require__("K9lf"); |
422 |
|
423 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/createClass.js |
|
424 var createClass = __webpack_require__(19); |
|
425 |
|
426 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js |
|
427 var assertThisInitialized = __webpack_require__(12); |
|
428 |
|
429 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js |
|
430 var possibleConstructorReturn = __webpack_require__(23); |
|
431 |
|
432 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js |
|
433 var getPrototypeOf = __webpack_require__(16); |
|
434 |
|
435 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js + 1 modules |
|
436 var inherits = __webpack_require__(22); |
|
437 |
|
438 // EXTERNAL MODULE: external {"this":["wp","compose"]} |
|
439 var external_this_wp_compose_ = __webpack_require__(9); |
|
440 |
214 |
441 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js |
215 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js |
442 |
|
443 |
|
444 |
|
445 /** |
216 /** |
446 * External dependencies |
217 * External dependencies |
447 */ |
218 */ |
448 |
219 |
449 /** |
220 /** |
461 * |
232 * |
462 * @param {File} file File. |
233 * @param {File} file File. |
463 * @return {Promise} Promise returning the imported reusable block. |
234 * @return {Promise} Promise returning the imported reusable block. |
464 */ |
235 */ |
465 |
236 |
466 function importReusableBlock(_x) { |
237 async function importReusableBlock(file) { |
467 return _importReusableBlock.apply(this, arguments); |
238 const fileContent = await readTextFile(file); |
|
239 let parsedContent; |
|
240 |
|
241 try { |
|
242 parsedContent = JSON.parse(fileContent); |
|
243 } catch (e) { |
|
244 throw new Error('Invalid JSON file'); |
|
245 } |
|
246 |
|
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 } |
|
250 |
|
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; |
468 } |
264 } |
469 |
265 |
470 function _importReusableBlock() { |
|
471 _importReusableBlock = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee(file) { |
|
472 var fileContent, parsedContent, postType, reusableBlock; |
|
473 return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) { |
|
474 while (1) { |
|
475 switch (_context.prev = _context.next) { |
|
476 case 0: |
|
477 _context.next = 2; |
|
478 return readTextFile(file); |
|
479 |
|
480 case 2: |
|
481 fileContent = _context.sent; |
|
482 _context.prev = 3; |
|
483 parsedContent = JSON.parse(fileContent); |
|
484 _context.next = 10; |
|
485 break; |
|
486 |
|
487 case 7: |
|
488 _context.prev = 7; |
|
489 _context.t0 = _context["catch"](3); |
|
490 throw new Error('Invalid JSON file'); |
|
491 |
|
492 case 10: |
|
493 if (!(parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !Object(external_this_lodash_["isString"])(parsedContent.title) || !Object(external_this_lodash_["isString"])(parsedContent.content))) { |
|
494 _context.next = 12; |
|
495 break; |
|
496 } |
|
497 |
|
498 throw new Error('Invalid Reusable Block JSON file'); |
|
499 |
|
500 case 12: |
|
501 _context.next = 14; |
|
502 return external_this_wp_apiFetch_default()({ |
|
503 path: "/wp/v2/types/wp_block" |
|
504 }); |
|
505 |
|
506 case 14: |
|
507 postType = _context.sent; |
|
508 _context.next = 17; |
|
509 return external_this_wp_apiFetch_default()({ |
|
510 path: "/wp/v2/".concat(postType.rest_base), |
|
511 data: { |
|
512 title: parsedContent.title, |
|
513 content: parsedContent.content, |
|
514 status: 'publish' |
|
515 }, |
|
516 method: 'POST' |
|
517 }); |
|
518 |
|
519 case 17: |
|
520 reusableBlock = _context.sent; |
|
521 return _context.abrupt("return", reusableBlock); |
|
522 |
|
523 case 19: |
|
524 case "end": |
|
525 return _context.stop(); |
|
526 } |
|
527 } |
|
528 }, _callee, null, [[3, 7]]); |
|
529 })); |
|
530 return _importReusableBlock.apply(this, arguments); |
|
531 } |
|
532 |
|
533 /* harmony default export */ var utils_import = (importReusableBlock); |
266 /* harmony default export */ var utils_import = (importReusableBlock); |
534 |
267 |
535 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js |
268 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js |
536 |
269 |
537 |
270 |
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 function _createSuper(Derived) { return function () { var Super = Object(getPrototypeOf["a" /* default */])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = Object(getPrototypeOf["a" /* default */])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return Object(possibleConstructorReturn["a" /* default */])(this, result); }; } |
|
545 |
|
546 function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } |
|
547 |
|
548 /** |
271 /** |
549 * WordPress dependencies |
272 * WordPress dependencies |
550 */ |
273 */ |
551 |
274 |
552 |
275 |
556 * Internal dependencies |
279 * Internal dependencies |
557 */ |
280 */ |
558 |
281 |
559 |
282 |
560 |
283 |
561 var import_form_ImportForm = /*#__PURE__*/function (_Component) { |
284 class import_form_ImportForm extends external_wp_element_["Component"] { |
562 Object(inherits["a" /* default */])(ImportForm, _Component); |
285 constructor() { |
563 |
286 super(...arguments); |
564 var _super = _createSuper(ImportForm); |
287 this.state = { |
565 |
|
566 function ImportForm() { |
|
567 var _this; |
|
568 |
|
569 Object(classCallCheck["a" /* default */])(this, ImportForm); |
|
570 |
|
571 _this = _super.apply(this, arguments); |
|
572 _this.state = { |
|
573 isLoading: false, |
288 isLoading: false, |
574 error: null, |
289 error: null, |
575 file: null |
290 file: null |
576 }; |
291 }; |
577 _this.isStillMounted = true; |
292 this.isStillMounted = true; |
578 _this.onChangeFile = _this.onChangeFile.bind(Object(assertThisInitialized["a" /* default */])(_this)); |
293 this.onChangeFile = this.onChangeFile.bind(this); |
579 _this.onSubmit = _this.onSubmit.bind(Object(assertThisInitialized["a" /* default */])(_this)); |
294 this.onSubmit = this.onSubmit.bind(this); |
580 return _this; |
295 } |
581 } |
296 |
582 |
297 componentWillUnmount() { |
583 Object(createClass["a" /* default */])(ImportForm, [{ |
298 this.isStillMounted = false; |
584 key: "componentWillUnmount", |
299 } |
585 value: function componentWillUnmount() { |
300 |
586 this.isStillMounted = false; |
301 onChangeFile(event) { |
|
302 this.setState({ |
|
303 file: event.target.files[0], |
|
304 error: null |
|
305 }); |
|
306 } |
|
307 |
|
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; |
587 } |
319 } |
588 }, { |
320 |
589 key: "onChangeFile", |
321 this.setState({ |
590 value: function onChangeFile(event) { |
322 isLoading: true |
591 this.setState({ |
323 }); |
592 file: event.target.files[0] |
324 utils_import(file).then(reusableBlock => { |
593 }); |
325 if (!this.isStillMounted) { |
594 } |
|
595 }, { |
|
596 key: "onSubmit", |
|
597 value: function onSubmit(event) { |
|
598 var _this2 = this; |
|
599 |
|
600 event.preventDefault(); |
|
601 var file = this.state.file; |
|
602 var onUpload = this.props.onUpload; |
|
603 |
|
604 if (!file) { |
|
605 return; |
326 return; |
606 } |
327 } |
607 |
328 |
608 this.setState({ |
329 this.setState({ |
609 isLoading: true |
330 isLoading: false |
610 }); |
331 }); |
611 utils_import(file).then(function (reusableBlock) { |
332 onUpload(reusableBlock); |
612 if (!_this2.isStillMounted) { |
333 }).catch(error => { |
613 return; |
334 if (!this.isStillMounted) { |
614 } |
335 return; |
615 |
336 } |
616 _this2.setState({ |
337 |
617 isLoading: false |
338 let uiMessage; |
618 }); |
339 |
619 |
340 switch (error.message) { |
620 onUpload(reusableBlock); |
341 case 'Invalid JSON file': |
621 }).catch(function (error) { |
342 uiMessage = Object(external_wp_i18n_["__"])('Invalid JSON file'); |
622 if (!_this2.isStillMounted) { |
343 break; |
623 return; |
344 |
624 } |
345 case 'Invalid Reusable block JSON file': |
625 |
346 uiMessage = Object(external_wp_i18n_["__"])('Invalid Reusable block JSON file'); |
626 var uiMessage; |
347 break; |
627 |
348 |
628 switch (error.message) { |
349 default: |
629 case 'Invalid JSON file': |
350 uiMessage = Object(external_wp_i18n_["__"])('Unknown error'); |
630 uiMessage = Object(external_this_wp_i18n_["__"])('Invalid JSON file'); |
351 } |
631 break; |
352 |
632 |
353 this.setState({ |
633 case 'Invalid Reusable Block JSON file': |
354 isLoading: false, |
634 uiMessage = Object(external_this_wp_i18n_["__"])('Invalid Reusable Block JSON file'); |
355 error: uiMessage |
635 break; |
|
636 |
|
637 default: |
|
638 uiMessage = Object(external_this_wp_i18n_["__"])('Unknown error'); |
|
639 } |
|
640 |
|
641 _this2.setState({ |
|
642 isLoading: false, |
|
643 error: uiMessage |
|
644 }); |
|
645 }); |
356 }); |
646 } |
357 }); |
647 }, { |
358 } |
648 key: "render", |
359 |
649 value: function render() { |
360 onDismissError() { |
650 var instanceId = this.props.instanceId; |
361 this.setState({ |
651 var _this$state = this.state, |
362 error: null |
652 file = _this$state.file, |
363 }); |
653 isLoading = _this$state.isLoading, |
364 } |
654 error = _this$state.error; |
365 |
655 var inputId = 'list-reusable-blocks-import-form-' + instanceId; |
366 render() { |
656 return Object(external_this_wp_element_["createElement"])("form", { |
367 const { |
657 className: "list-reusable-blocks-import-form", |
368 instanceId |
658 onSubmit: this.onSubmit |
369 } = this.props; |
659 }, error && Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Notice"], { |
370 const { |
660 status: "error" |
371 file, |
661 }, error), Object(external_this_wp_element_["createElement"])("label", { |
372 isLoading, |
662 htmlFor: inputId, |
373 error |
663 className: "list-reusable-blocks-import-form__label" |
374 } = this.state; |
664 }, Object(external_this_wp_i18n_["__"])('File')), Object(external_this_wp_element_["createElement"])("input", { |
375 const inputId = 'list-reusable-blocks-import-form-' + instanceId; |
665 id: inputId, |
376 return Object(external_wp_element_["createElement"])("form", { |
666 type: "file", |
377 className: "list-reusable-blocks-import-form", |
667 onChange: this.onChangeFile |
378 onSubmit: this.onSubmit |
668 }), Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Button"], { |
379 }, error && Object(external_wp_element_["createElement"])(external_wp_components_["Notice"], { |
669 type: "submit", |
380 status: "error", |
670 isBusy: isLoading, |
381 onRemove: () => this.onDismissError() |
671 disabled: !file || isLoading, |
382 }, error), Object(external_wp_element_["createElement"])("label", { |
672 isSecondary: true, |
383 htmlFor: inputId, |
673 className: "list-reusable-blocks-import-form__button" |
384 className: "list-reusable-blocks-import-form__label" |
674 }, Object(external_this_wp_i18n_["_x"])('Import', 'button label'))); |
385 }, Object(external_wp_i18n_["__"])('File')), Object(external_wp_element_["createElement"])("input", { |
675 } |
386 id: inputId, |
676 }]); |
387 type: "file", |
677 |
388 onChange: this.onChangeFile |
678 return ImportForm; |
389 }), Object(external_wp_element_["createElement"])(external_wp_components_["Button"], { |
679 }(external_this_wp_element_["Component"]); |
390 type: "submit", |
680 |
391 isBusy: isLoading, |
681 /* harmony default export */ var import_form = (Object(external_this_wp_compose_["withInstanceId"])(import_form_ImportForm)); |
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 } |
|
397 |
|
398 } |
|
399 |
|
400 /* harmony default export */ var import_form = (Object(external_wp_compose_["withInstanceId"])(import_form_ImportForm)); |
682 |
401 |
683 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js |
402 // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js |
684 |
403 |
685 |
404 |
686 /** |
405 /** |
697 * Internal dependencies |
416 * Internal dependencies |
698 */ |
417 */ |
699 |
418 |
700 |
419 |
701 |
420 |
702 function ImportDropdown(_ref) { |
421 function ImportDropdown({ |
703 var onUpload = _ref.onUpload; |
422 onUpload |
704 return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Dropdown"], { |
423 }) { |
|
424 return Object(external_wp_element_["createElement"])(external_wp_components_["Dropdown"], { |
705 position: "bottom right", |
425 position: "bottom right", |
706 contentClassName: "list-reusable-blocks-import-dropdown__content", |
426 contentClassName: "list-reusable-blocks-import-dropdown__content", |
707 renderToggle: function renderToggle(_ref2) { |
427 renderToggle: ({ |
708 var isOpen = _ref2.isOpen, |
428 isOpen, |
709 onToggle = _ref2.onToggle; |
429 onToggle |
710 return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Button"], { |
430 }) => Object(external_wp_element_["createElement"])(external_wp_components_["Button"], { |
711 "aria-expanded": isOpen, |
431 "aria-expanded": isOpen, |
712 onClick: onToggle, |
432 onClick: onToggle, |
713 isPrimary: true |
433 isPrimary: true |
714 }, Object(external_this_wp_i18n_["__"])('Import from JSON')); |
434 }, Object(external_wp_i18n_["__"])('Import from JSON')), |
715 }, |
435 renderContent: ({ |
716 renderContent: function renderContent(_ref3) { |
436 onClose |
717 var onClose = _ref3.onClose; |
437 }) => Object(external_wp_element_["createElement"])(import_form, { |
718 return Object(external_this_wp_element_["createElement"])(import_form, { |
438 onUpload: Object(external_lodash_["flow"])(onClose, onUpload) |
719 onUpload: Object(external_this_lodash_["flow"])(onClose, onUpload) |
439 }) |
720 }); |
|
721 } |
|
722 }); |
440 }); |
723 } |
441 } |
724 |
442 |
725 /* harmony default export */ var import_dropdown = (ImportDropdown); |
443 /* harmony default export */ var import_dropdown = (ImportDropdown); |
726 |
444 |
737 */ |
455 */ |
738 |
456 |
739 |
457 |
740 // Setup Export Links |
458 // Setup Export Links |
741 |
459 |
742 document.body.addEventListener('click', function (event) { |
460 document.body.addEventListener('click', event => { |
743 if (!event.target.classList.contains('wp-list-reusable-blocks__export')) { |
461 if (!event.target.classList.contains('wp-list-reusable-blocks__export')) { |
744 return; |
462 return; |
745 } |
463 } |
746 |
464 |
747 event.preventDefault(); |
465 event.preventDefault(); |
748 utils_export(event.target.dataset.id); |
466 utils_export(event.target.dataset.id); |
749 }); // Setup Import Form |
467 }); // Setup Import Form |
750 |
468 |
751 document.addEventListener('DOMContentLoaded', function () { |
469 document.addEventListener('DOMContentLoaded', () => { |
752 var button = document.querySelector('.page-title-action'); |
470 const button = document.querySelector('.page-title-action'); |
753 |
471 |
754 if (!button) { |
472 if (!button) { |
755 return; |
473 return; |
756 } |
474 } |
757 |
475 |
758 var showNotice = function showNotice() { |
476 const showNotice = () => { |
759 var notice = document.createElement('div'); |
477 const notice = document.createElement('div'); |
760 notice.className = 'notice notice-success is-dismissible'; |
478 notice.className = 'notice notice-success is-dismissible'; |
761 notice.innerHTML = "<p>".concat(Object(external_this_wp_i18n_["__"])('Reusable block imported successfully!'), "</p>"); |
479 notice.innerHTML = `<p>${Object(external_wp_i18n_["__"])('Reusable block imported successfully!')}</p>`; |
762 var headerEnd = document.querySelector('.wp-header-end'); |
480 const headerEnd = document.querySelector('.wp-header-end'); |
763 |
481 |
764 if (!headerEnd) { |
482 if (!headerEnd) { |
765 return; |
483 return; |
766 } |
484 } |
767 |
485 |
768 headerEnd.parentNode.insertBefore(notice, headerEnd); |
486 headerEnd.parentNode.insertBefore(notice, headerEnd); |
769 }; |
487 }; |
770 |
488 |
771 var container = document.createElement('div'); |
489 const container = document.createElement('div'); |
772 container.className = 'list-reusable-blocks__container'; |
490 container.className = 'list-reusable-blocks__container'; |
773 button.parentNode.insertBefore(container, button); |
491 button.parentNode.insertBefore(container, button); |
774 Object(external_this_wp_element_["render"])(Object(external_this_wp_element_["createElement"])(import_dropdown, { |
492 Object(external_wp_element_["render"])(Object(external_wp_element_["createElement"])(import_dropdown, { |
775 onUpload: showNotice |
493 onUpload: showNotice |
776 }), container); |
494 }), container); |
777 }); |
495 }); |
778 |
496 |
779 |
497 |
780 /***/ }), |
498 /***/ }), |
781 |
499 |
782 /***/ 50: |
500 /***/ "YLtl": |
783 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
501 /***/ (function(module, exports) { |
784 |
502 |
785 "use strict"; |
503 (function() { module.exports = window["lodash"]; }()); |
786 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; }); |
|
787 function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { |
|
788 try { |
|
789 var info = gen[key](arg); |
|
790 var value = info.value; |
|
791 } catch (error) { |
|
792 reject(error); |
|
793 return; |
|
794 } |
|
795 |
|
796 if (info.done) { |
|
797 resolve(value); |
|
798 } else { |
|
799 Promise.resolve(value).then(_next, _throw); |
|
800 } |
|
801 } |
|
802 |
|
803 function _asyncToGenerator(fn) { |
|
804 return function () { |
|
805 var self = this, |
|
806 args = arguments; |
|
807 return new Promise(function (resolve, reject) { |
|
808 var gen = fn.apply(self, args); |
|
809 |
|
810 function _next(value) { |
|
811 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); |
|
812 } |
|
813 |
|
814 function _throw(err) { |
|
815 asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); |
|
816 } |
|
817 |
|
818 _next(undefined); |
|
819 }); |
|
820 }; |
|
821 } |
|
822 |
504 |
823 /***/ }), |
505 /***/ }), |
824 |
506 |
825 /***/ 9: |
507 /***/ "l3Sj": |
826 /***/ (function(module, exports) { |
508 /***/ (function(module, exports) { |
827 |
509 |
828 (function() { module.exports = this["wp"]["compose"]; }()); |
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"]; }()); |
829 |
525 |
830 /***/ }) |
526 /***/ }) |
831 |
527 |
832 /******/ }); |
528 /******/ }); |