list-reusable-blocks.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  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
  85. /******/ return __webpack_require__(__webpack_require__.s = 358);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, exports) {
  91. (function() { module.exports = this["wp"]["element"]; }());
  92. /***/ }),
  93. /***/ 1:
  94. /***/ (function(module, exports) {
  95. (function() { module.exports = this["wp"]["i18n"]; }());
  96. /***/ }),
  97. /***/ 11:
  98. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99. "use strict";
  100. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; });
  101. function _defineProperties(target, props) {
  102. for (var i = 0; i < props.length; i++) {
  103. var descriptor = props[i];
  104. descriptor.enumerable = descriptor.enumerable || false;
  105. descriptor.configurable = true;
  106. if ("value" in descriptor) descriptor.writable = true;
  107. Object.defineProperty(target, descriptor.key, descriptor);
  108. }
  109. }
  110. function _createClass(Constructor, protoProps, staticProps) {
  111. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  112. if (staticProps) _defineProperties(Constructor, staticProps);
  113. return Constructor;
  114. }
  115. /***/ }),
  116. /***/ 12:
  117. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  118. "use strict";
  119. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; });
  120. function _classCallCheck(instance, Constructor) {
  121. if (!(instance instanceof Constructor)) {
  122. throw new TypeError("Cannot call a class as a function");
  123. }
  124. }
  125. /***/ }),
  126. /***/ 13:
  127. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  128. "use strict";
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _possibleConstructorReturn; });
  130. /* harmony import */ var _helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(31);
  131. /* harmony import */ var _assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
  132. function _possibleConstructorReturn(self, call) {
  133. if (call && (Object(_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(call) === "object" || typeof call === "function")) {
  134. return call;
  135. }
  136. return Object(_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(self);
  137. }
  138. /***/ }),
  139. /***/ 14:
  140. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  141. "use strict";
  142. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _getPrototypeOf; });
  143. function _getPrototypeOf(o) {
  144. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  145. return o.__proto__ || Object.getPrototypeOf(o);
  146. };
  147. return _getPrototypeOf(o);
  148. }
  149. /***/ }),
  150. /***/ 15:
  151. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  152. "use strict";
  153. // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
  154. function _setPrototypeOf(o, p) {
  155. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  156. o.__proto__ = p;
  157. return o;
  158. };
  159. return _setPrototypeOf(o, p);
  160. }
  161. // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js
  162. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _inherits; });
  163. function _inherits(subClass, superClass) {
  164. if (typeof superClass !== "function" && superClass !== null) {
  165. throw new TypeError("Super expression must either be null or a function");
  166. }
  167. subClass.prototype = Object.create(superClass && superClass.prototype, {
  168. constructor: {
  169. value: subClass,
  170. writable: true,
  171. configurable: true
  172. }
  173. });
  174. if (superClass) _setPrototypeOf(subClass, superClass);
  175. }
  176. /***/ }),
  177. /***/ 2:
  178. /***/ (function(module, exports) {
  179. (function() { module.exports = this["lodash"]; }());
  180. /***/ }),
  181. /***/ 20:
  182. /***/ (function(module, exports, __webpack_require__) {
  183. module.exports = __webpack_require__(47);
  184. /***/ }),
  185. /***/ 3:
  186. /***/ (function(module, exports) {
  187. (function() { module.exports = this["wp"]["components"]; }());
  188. /***/ }),
  189. /***/ 31:
  190. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  191. "use strict";
  192. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _typeof; });
  193. function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
  194. function _typeof(obj) {
  195. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  196. _typeof = function _typeof(obj) {
  197. return _typeof2(obj);
  198. };
  199. } else {
  200. _typeof = function _typeof(obj) {
  201. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  202. };
  203. }
  204. return _typeof(obj);
  205. }
  206. /***/ }),
  207. /***/ 34:
  208. /***/ (function(module, exports) {
  209. (function() { module.exports = this["wp"]["apiFetch"]; }());
  210. /***/ }),
  211. /***/ 358:
  212. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  213. "use strict";
  214. __webpack_require__.r(__webpack_exports__);
  215. // EXTERNAL MODULE: external {"this":["wp","element"]}
  216. var external_this_wp_element_ = __webpack_require__(0);
  217. // EXTERNAL MODULE: external {"this":["wp","i18n"]}
  218. var external_this_wp_i18n_ = __webpack_require__(1);
  219. // EXTERNAL MODULE: ./node_modules/@babel/runtime/regenerator/index.js
  220. var regenerator = __webpack_require__(20);
  221. var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);
  222. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
  223. var asyncToGenerator = __webpack_require__(43);
  224. // EXTERNAL MODULE: external "lodash"
  225. var external_lodash_ = __webpack_require__(2);
  226. // EXTERNAL MODULE: external {"this":["wp","apiFetch"]}
  227. var external_this_wp_apiFetch_ = __webpack_require__(34);
  228. var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_);
  229. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js
  230. /**
  231. * Downloads a file.
  232. *
  233. * @param {string} fileName File Name.
  234. * @param {string} content File Content.
  235. * @param {string} contentType File mime type.
  236. */
  237. function download(fileName, content, contentType) {
  238. var file = new window.Blob([content], {
  239. type: contentType
  240. }); // IE11 can't use the click to download technique
  241. // we use a specific IE11 technique instead.
  242. if (window.navigator.msSaveOrOpenBlob) {
  243. window.navigator.msSaveOrOpenBlob(file, fileName);
  244. } else {
  245. var a = document.createElement('a');
  246. a.href = URL.createObjectURL(file);
  247. a.download = fileName;
  248. a.style.display = 'none';
  249. document.body.appendChild(a);
  250. a.click();
  251. document.body.removeChild(a);
  252. }
  253. }
  254. /**
  255. * Reads the textual content of the given file.
  256. *
  257. * @param {File} file File.
  258. * @return {Promise<string>} Content of the file.
  259. */
  260. function readTextFile(file) {
  261. var reader = new window.FileReader();
  262. return new Promise(function (resolve) {
  263. reader.onload = function () {
  264. resolve(reader.result);
  265. };
  266. reader.readAsText(file);
  267. });
  268. }
  269. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js
  270. /**
  271. * External dependencies
  272. */
  273. /**
  274. * WordPress dependencies
  275. */
  276. /**
  277. * Internal dependencies
  278. */
  279. /**
  280. * Export a reusable block as a JSON file.
  281. *
  282. * @param {number} id
  283. */
  284. function exportReusableBlock(_x) {
  285. return _exportReusableBlock.apply(this, arguments);
  286. }
  287. function _exportReusableBlock() {
  288. _exportReusableBlock = Object(asyncToGenerator["a" /* default */])(
  289. /*#__PURE__*/
  290. regenerator_default.a.mark(function _callee(id) {
  291. var postType, post, title, content, fileContent, fileName;
  292. return regenerator_default.a.wrap(function _callee$(_context) {
  293. while (1) {
  294. switch (_context.prev = _context.next) {
  295. case 0:
  296. _context.next = 2;
  297. return external_this_wp_apiFetch_default()({
  298. path: "/wp/v2/types/wp_block"
  299. });
  300. case 2:
  301. postType = _context.sent;
  302. _context.next = 5;
  303. return external_this_wp_apiFetch_default()({
  304. path: "/wp/v2/".concat(postType.rest_base, "/").concat(id, "?context=edit")
  305. });
  306. case 5:
  307. post = _context.sent;
  308. title = post.title.raw;
  309. content = post.content.raw;
  310. fileContent = JSON.stringify({
  311. __file: 'wp_block',
  312. title: title,
  313. content: content
  314. }, null, 2);
  315. fileName = Object(external_lodash_["kebabCase"])(title) + '.json';
  316. download(fileName, fileContent, 'application/json');
  317. case 11:
  318. case "end":
  319. return _context.stop();
  320. }
  321. }
  322. }, _callee);
  323. }));
  324. return _exportReusableBlock.apply(this, arguments);
  325. }
  326. /* harmony default export */ var utils_export = (exportReusableBlock);
  327. // EXTERNAL MODULE: external {"this":["wp","components"]}
  328. var external_this_wp_components_ = __webpack_require__(3);
  329. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js
  330. var classCallCheck = __webpack_require__(12);
  331. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/createClass.js
  332. var createClass = __webpack_require__(11);
  333. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js
  334. var possibleConstructorReturn = __webpack_require__(13);
  335. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js
  336. var getPrototypeOf = __webpack_require__(14);
  337. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js
  338. var assertThisInitialized = __webpack_require__(5);
  339. // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js + 1 modules
  340. var inherits = __webpack_require__(15);
  341. // EXTERNAL MODULE: external {"this":["wp","compose"]}
  342. var external_this_wp_compose_ = __webpack_require__(8);
  343. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js
  344. /**
  345. * External dependencies
  346. */
  347. /**
  348. * WordPress dependencies
  349. */
  350. /**
  351. * Internal dependencies
  352. */
  353. /**
  354. * Import a reusable block from a JSON file.
  355. *
  356. * @param {File} file File.
  357. * @return {Promise} Promise returning the imported reusable block.
  358. */
  359. function importReusableBlock(_x) {
  360. return _importReusableBlock.apply(this, arguments);
  361. }
  362. function _importReusableBlock() {
  363. _importReusableBlock = Object(asyncToGenerator["a" /* default */])(
  364. /*#__PURE__*/
  365. regenerator_default.a.mark(function _callee(file) {
  366. var fileContent, parsedContent, postType, reusableBlock;
  367. return regenerator_default.a.wrap(function _callee$(_context) {
  368. while (1) {
  369. switch (_context.prev = _context.next) {
  370. case 0:
  371. _context.next = 2;
  372. return readTextFile(file);
  373. case 2:
  374. fileContent = _context.sent;
  375. _context.prev = 3;
  376. parsedContent = JSON.parse(fileContent);
  377. _context.next = 10;
  378. break;
  379. case 7:
  380. _context.prev = 7;
  381. _context.t0 = _context["catch"](3);
  382. throw new Error('Invalid JSON file');
  383. case 10:
  384. if (!(parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !Object(external_lodash_["isString"])(parsedContent.title) || !Object(external_lodash_["isString"])(parsedContent.content))) {
  385. _context.next = 12;
  386. break;
  387. }
  388. throw new Error('Invalid Reusable Block JSON file');
  389. case 12:
  390. _context.next = 14;
  391. return external_this_wp_apiFetch_default()({
  392. path: "/wp/v2/types/wp_block"
  393. });
  394. case 14:
  395. postType = _context.sent;
  396. _context.next = 17;
  397. return external_this_wp_apiFetch_default()({
  398. path: "/wp/v2/".concat(postType.rest_base),
  399. data: {
  400. title: parsedContent.title,
  401. content: parsedContent.content,
  402. status: 'publish'
  403. },
  404. method: 'POST'
  405. });
  406. case 17:
  407. reusableBlock = _context.sent;
  408. return _context.abrupt("return", reusableBlock);
  409. case 19:
  410. case "end":
  411. return _context.stop();
  412. }
  413. }
  414. }, _callee, null, [[3, 7]]);
  415. }));
  416. return _importReusableBlock.apply(this, arguments);
  417. }
  418. /* harmony default export */ var utils_import = (importReusableBlock);
  419. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js
  420. /**
  421. * WordPress dependencies
  422. */
  423. /**
  424. * Internal dependencies
  425. */
  426. var import_form_ImportForm =
  427. /*#__PURE__*/
  428. function (_Component) {
  429. Object(inherits["a" /* default */])(ImportForm, _Component);
  430. function ImportForm() {
  431. var _this;
  432. Object(classCallCheck["a" /* default */])(this, ImportForm);
  433. _this = Object(possibleConstructorReturn["a" /* default */])(this, Object(getPrototypeOf["a" /* default */])(ImportForm).apply(this, arguments));
  434. _this.state = {
  435. isLoading: false,
  436. error: null,
  437. file: null
  438. };
  439. _this.isStillMounted = true;
  440. _this.onChangeFile = _this.onChangeFile.bind(Object(assertThisInitialized["a" /* default */])(_this));
  441. _this.onSubmit = _this.onSubmit.bind(Object(assertThisInitialized["a" /* default */])(_this));
  442. return _this;
  443. }
  444. Object(createClass["a" /* default */])(ImportForm, [{
  445. key: "componentWillUnmount",
  446. value: function componentWillUnmount() {
  447. this.isStillMounted = false;
  448. }
  449. }, {
  450. key: "onChangeFile",
  451. value: function onChangeFile(event) {
  452. this.setState({
  453. file: event.target.files[0]
  454. });
  455. }
  456. }, {
  457. key: "onSubmit",
  458. value: function onSubmit(event) {
  459. var _this2 = this;
  460. event.preventDefault();
  461. var file = this.state.file;
  462. var onUpload = this.props.onUpload;
  463. if (!file) {
  464. return;
  465. }
  466. this.setState({
  467. isLoading: true
  468. });
  469. utils_import(file).then(function (reusableBlock) {
  470. if (!_this2.isStillMounted) {
  471. return;
  472. }
  473. _this2.setState({
  474. isLoading: false
  475. });
  476. onUpload(reusableBlock);
  477. }).catch(function (error) {
  478. if (!_this2.isStillMounted) {
  479. return;
  480. }
  481. var uiMessage;
  482. switch (error.message) {
  483. case 'Invalid JSON file':
  484. uiMessage = Object(external_this_wp_i18n_["__"])('Invalid JSON file');
  485. break;
  486. case 'Invalid Reusable Block JSON file':
  487. uiMessage = Object(external_this_wp_i18n_["__"])('Invalid Reusable Block JSON file');
  488. break;
  489. default:
  490. uiMessage = Object(external_this_wp_i18n_["__"])('Unknown error');
  491. }
  492. _this2.setState({
  493. isLoading: false,
  494. error: uiMessage
  495. });
  496. });
  497. }
  498. }, {
  499. key: "render",
  500. value: function render() {
  501. var instanceId = this.props.instanceId;
  502. var _this$state = this.state,
  503. file = _this$state.file,
  504. isLoading = _this$state.isLoading,
  505. error = _this$state.error;
  506. var inputId = 'list-reusable-blocks-import-form-' + instanceId;
  507. return Object(external_this_wp_element_["createElement"])("form", {
  508. className: "list-reusable-blocks-import-form",
  509. onSubmit: this.onSubmit
  510. }, error && Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Notice"], {
  511. status: "error"
  512. }, error), Object(external_this_wp_element_["createElement"])("label", {
  513. htmlFor: inputId,
  514. className: "list-reusable-blocks-import-form__label"
  515. }, Object(external_this_wp_i18n_["__"])('File')), Object(external_this_wp_element_["createElement"])("input", {
  516. id: inputId,
  517. type: "file",
  518. onChange: this.onChangeFile
  519. }), Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Button"], {
  520. type: "submit",
  521. isBusy: isLoading,
  522. disabled: !file || isLoading,
  523. isDefault: true,
  524. className: "list-reusable-blocks-import-form__button"
  525. }, Object(external_this_wp_i18n_["_x"])('Import', 'button label')));
  526. }
  527. }]);
  528. return ImportForm;
  529. }(external_this_wp_element_["Component"]);
  530. /* harmony default export */ var import_form = (Object(external_this_wp_compose_["withInstanceId"])(import_form_ImportForm));
  531. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js
  532. /**
  533. * External dependencies
  534. */
  535. /**
  536. * WordPress dependencies
  537. */
  538. /**
  539. * Internal dependencies
  540. */
  541. function ImportDropdown(_ref) {
  542. var onUpload = _ref.onUpload;
  543. return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Dropdown"], {
  544. position: "bottom right",
  545. contentClassName: "list-reusable-blocks-import-dropdown__content",
  546. renderToggle: function renderToggle(_ref2) {
  547. var isOpen = _ref2.isOpen,
  548. onToggle = _ref2.onToggle;
  549. return Object(external_this_wp_element_["createElement"])(external_this_wp_components_["Button"], {
  550. type: "button",
  551. "aria-expanded": isOpen,
  552. onClick: onToggle,
  553. isPrimary: true
  554. }, Object(external_this_wp_i18n_["__"])('Import from JSON'));
  555. },
  556. renderContent: function renderContent(_ref3) {
  557. var onClose = _ref3.onClose;
  558. return Object(external_this_wp_element_["createElement"])(import_form, {
  559. onUpload: Object(external_lodash_["flow"])(onClose, onUpload)
  560. });
  561. }
  562. });
  563. }
  564. /* harmony default export */ var import_dropdown = (ImportDropdown);
  565. // CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/index.js
  566. /**
  567. * WordPress dependencies
  568. */
  569. /**
  570. * Internal dependencies
  571. */
  572. // Setup Export Links
  573. document.body.addEventListener('click', function (event) {
  574. if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
  575. return;
  576. }
  577. event.preventDefault();
  578. utils_export(event.target.dataset.id);
  579. }); // Setup Import Form
  580. document.addEventListener('DOMContentLoaded', function () {
  581. var button = document.querySelector('.page-title-action');
  582. if (!button) {
  583. return;
  584. }
  585. var showNotice = function showNotice() {
  586. var notice = document.createElement('div');
  587. notice.className = 'notice notice-success is-dismissible';
  588. notice.innerHTML = "<p>".concat(Object(external_this_wp_i18n_["__"])('Reusable block imported successfully!'), "</p>");
  589. var headerEnd = document.querySelector('.wp-header-end');
  590. if (!headerEnd) {
  591. return;
  592. }
  593. headerEnd.parentNode.insertBefore(notice, headerEnd);
  594. };
  595. var container = document.createElement('div');
  596. container.className = 'list-reusable-blocks__container';
  597. button.parentNode.insertBefore(container, button);
  598. Object(external_this_wp_element_["render"])(Object(external_this_wp_element_["createElement"])(import_dropdown, {
  599. onUpload: showNotice
  600. }), container);
  601. });
  602. /***/ }),
  603. /***/ 43:
  604. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  605. "use strict";
  606. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
  607. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  608. try {
  609. var info = gen[key](arg);
  610. var value = info.value;
  611. } catch (error) {
  612. reject(error);
  613. return;
  614. }
  615. if (info.done) {
  616. resolve(value);
  617. } else {
  618. Promise.resolve(value).then(_next, _throw);
  619. }
  620. }
  621. function _asyncToGenerator(fn) {
  622. return function () {
  623. var self = this,
  624. args = arguments;
  625. return new Promise(function (resolve, reject) {
  626. var gen = fn.apply(self, args);
  627. function _next(value) {
  628. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  629. }
  630. function _throw(err) {
  631. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  632. }
  633. _next(undefined);
  634. });
  635. };
  636. }
  637. /***/ }),
  638. /***/ 47:
  639. /***/ (function(module, exports, __webpack_require__) {
  640. /**
  641. * Copyright (c) 2014-present, Facebook, Inc.
  642. *
  643. * This source code is licensed under the MIT license found in the
  644. * LICENSE file in the root directory of this source tree.
  645. */
  646. var runtime = (function (exports) {
  647. "use strict";
  648. var Op = Object.prototype;
  649. var hasOwn = Op.hasOwnProperty;
  650. var undefined; // More compressible than void 0.
  651. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  652. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  653. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  654. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  655. function wrap(innerFn, outerFn, self, tryLocsList) {
  656. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  657. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  658. var generator = Object.create(protoGenerator.prototype);
  659. var context = new Context(tryLocsList || []);
  660. // The ._invoke method unifies the implementations of the .next,
  661. // .throw, and .return methods.
  662. generator._invoke = makeInvokeMethod(innerFn, self, context);
  663. return generator;
  664. }
  665. exports.wrap = wrap;
  666. // Try/catch helper to minimize deoptimizations. Returns a completion
  667. // record like context.tryEntries[i].completion. This interface could
  668. // have been (and was previously) designed to take a closure to be
  669. // invoked without arguments, but in all the cases we care about we
  670. // already have an existing method we want to call, so there's no need
  671. // to create a new function object. We can even get away with assuming
  672. // the method takes exactly one argument, since that happens to be true
  673. // in every case, so we don't have to touch the arguments object. The
  674. // only additional allocation required is the completion record, which
  675. // has a stable shape and so hopefully should be cheap to allocate.
  676. function tryCatch(fn, obj, arg) {
  677. try {
  678. return { type: "normal", arg: fn.call(obj, arg) };
  679. } catch (err) {
  680. return { type: "throw", arg: err };
  681. }
  682. }
  683. var GenStateSuspendedStart = "suspendedStart";
  684. var GenStateSuspendedYield = "suspendedYield";
  685. var GenStateExecuting = "executing";
  686. var GenStateCompleted = "completed";
  687. // Returning this object from the innerFn has the same effect as
  688. // breaking out of the dispatch switch statement.
  689. var ContinueSentinel = {};
  690. // Dummy constructor functions that we use as the .constructor and
  691. // .constructor.prototype properties for functions that return Generator
  692. // objects. For full spec compliance, you may wish to configure your
  693. // minifier not to mangle the names of these two functions.
  694. function Generator() {}
  695. function GeneratorFunction() {}
  696. function GeneratorFunctionPrototype() {}
  697. // This is a polyfill for %IteratorPrototype% for environments that
  698. // don't natively support it.
  699. var IteratorPrototype = {};
  700. IteratorPrototype[iteratorSymbol] = function () {
  701. return this;
  702. };
  703. var getProto = Object.getPrototypeOf;
  704. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  705. if (NativeIteratorPrototype &&
  706. NativeIteratorPrototype !== Op &&
  707. hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  708. // This environment has a native %IteratorPrototype%; use it instead
  709. // of the polyfill.
  710. IteratorPrototype = NativeIteratorPrototype;
  711. }
  712. var Gp = GeneratorFunctionPrototype.prototype =
  713. Generator.prototype = Object.create(IteratorPrototype);
  714. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  715. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  716. GeneratorFunctionPrototype[toStringTagSymbol] =
  717. GeneratorFunction.displayName = "GeneratorFunction";
  718. // Helper for defining the .next, .throw, and .return methods of the
  719. // Iterator interface in terms of a single ._invoke method.
  720. function defineIteratorMethods(prototype) {
  721. ["next", "throw", "return"].forEach(function(method) {
  722. prototype[method] = function(arg) {
  723. return this._invoke(method, arg);
  724. };
  725. });
  726. }
  727. exports.isGeneratorFunction = function(genFun) {
  728. var ctor = typeof genFun === "function" && genFun.constructor;
  729. return ctor
  730. ? ctor === GeneratorFunction ||
  731. // For the native GeneratorFunction constructor, the best we can
  732. // do is to check its .name property.
  733. (ctor.displayName || ctor.name) === "GeneratorFunction"
  734. : false;
  735. };
  736. exports.mark = function(genFun) {
  737. if (Object.setPrototypeOf) {
  738. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  739. } else {
  740. genFun.__proto__ = GeneratorFunctionPrototype;
  741. if (!(toStringTagSymbol in genFun)) {
  742. genFun[toStringTagSymbol] = "GeneratorFunction";
  743. }
  744. }
  745. genFun.prototype = Object.create(Gp);
  746. return genFun;
  747. };
  748. // Within the body of any async function, `await x` is transformed to
  749. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  750. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  751. // meant to be awaited.
  752. exports.awrap = function(arg) {
  753. return { __await: arg };
  754. };
  755. function AsyncIterator(generator) {
  756. function invoke(method, arg, resolve, reject) {
  757. var record = tryCatch(generator[method], generator, arg);
  758. if (record.type === "throw") {
  759. reject(record.arg);
  760. } else {
  761. var result = record.arg;
  762. var value = result.value;
  763. if (value &&
  764. typeof value === "object" &&
  765. hasOwn.call(value, "__await")) {
  766. return Promise.resolve(value.__await).then(function(value) {
  767. invoke("next", value, resolve, reject);
  768. }, function(err) {
  769. invoke("throw", err, resolve, reject);
  770. });
  771. }
  772. return Promise.resolve(value).then(function(unwrapped) {
  773. // When a yielded Promise is resolved, its final value becomes
  774. // the .value of the Promise<{value,done}> result for the
  775. // current iteration.
  776. result.value = unwrapped;
  777. resolve(result);
  778. }, function(error) {
  779. // If a rejected Promise was yielded, throw the rejection back
  780. // into the async generator function so it can be handled there.
  781. return invoke("throw", error, resolve, reject);
  782. });
  783. }
  784. }
  785. var previousPromise;
  786. function enqueue(method, arg) {
  787. function callInvokeWithMethodAndArg() {
  788. return new Promise(function(resolve, reject) {
  789. invoke(method, arg, resolve, reject);
  790. });
  791. }
  792. return previousPromise =
  793. // If enqueue has been called before, then we want to wait until
  794. // all previous Promises have been resolved before calling invoke,
  795. // so that results are always delivered in the correct order. If
  796. // enqueue has not been called before, then it is important to
  797. // call invoke immediately, without waiting on a callback to fire,
  798. // so that the async generator function has the opportunity to do
  799. // any necessary setup in a predictable way. This predictability
  800. // is why the Promise constructor synchronously invokes its
  801. // executor callback, and why async functions synchronously
  802. // execute code before the first await. Since we implement simple
  803. // async functions in terms of async generators, it is especially
  804. // important to get this right, even though it requires care.
  805. previousPromise ? previousPromise.then(
  806. callInvokeWithMethodAndArg,
  807. // Avoid propagating failures to Promises returned by later
  808. // invocations of the iterator.
  809. callInvokeWithMethodAndArg
  810. ) : callInvokeWithMethodAndArg();
  811. }
  812. // Define the unified helper method that is used to implement .next,
  813. // .throw, and .return (see defineIteratorMethods).
  814. this._invoke = enqueue;
  815. }
  816. defineIteratorMethods(AsyncIterator.prototype);
  817. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  818. return this;
  819. };
  820. exports.AsyncIterator = AsyncIterator;
  821. // Note that simple async functions are implemented on top of
  822. // AsyncIterator objects; they just return a Promise for the value of
  823. // the final result produced by the iterator.
  824. exports.async = function(innerFn, outerFn, self, tryLocsList) {
  825. var iter = new AsyncIterator(
  826. wrap(innerFn, outerFn, self, tryLocsList)
  827. );
  828. return exports.isGeneratorFunction(outerFn)
  829. ? iter // If outerFn is a generator, return the full iterator.
  830. : iter.next().then(function(result) {
  831. return result.done ? result.value : iter.next();
  832. });
  833. };
  834. function makeInvokeMethod(innerFn, self, context) {
  835. var state = GenStateSuspendedStart;
  836. return function invoke(method, arg) {
  837. if (state === GenStateExecuting) {
  838. throw new Error("Generator is already running");
  839. }
  840. if (state === GenStateCompleted) {
  841. if (method === "throw") {
  842. throw arg;
  843. }
  844. // Be forgiving, per 25.3.3.3.3 of the spec:
  845. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  846. return doneResult();
  847. }
  848. context.method = method;
  849. context.arg = arg;
  850. while (true) {
  851. var delegate = context.delegate;
  852. if (delegate) {
  853. var delegateResult = maybeInvokeDelegate(delegate, context);
  854. if (delegateResult) {
  855. if (delegateResult === ContinueSentinel) continue;
  856. return delegateResult;
  857. }
  858. }
  859. if (context.method === "next") {
  860. // Setting context._sent for legacy support of Babel's
  861. // function.sent implementation.
  862. context.sent = context._sent = context.arg;
  863. } else if (context.method === "throw") {
  864. if (state === GenStateSuspendedStart) {
  865. state = GenStateCompleted;
  866. throw context.arg;
  867. }
  868. context.dispatchException(context.arg);
  869. } else if (context.method === "return") {
  870. context.abrupt("return", context.arg);
  871. }
  872. state = GenStateExecuting;
  873. var record = tryCatch(innerFn, self, context);
  874. if (record.type === "normal") {
  875. // If an exception is thrown from innerFn, we leave state ===
  876. // GenStateExecuting and loop back for another invocation.
  877. state = context.done
  878. ? GenStateCompleted
  879. : GenStateSuspendedYield;
  880. if (record.arg === ContinueSentinel) {
  881. continue;
  882. }
  883. return {
  884. value: record.arg,
  885. done: context.done
  886. };
  887. } else if (record.type === "throw") {
  888. state = GenStateCompleted;
  889. // Dispatch the exception by looping back around to the
  890. // context.dispatchException(context.arg) call above.
  891. context.method = "throw";
  892. context.arg = record.arg;
  893. }
  894. }
  895. };
  896. }
  897. // Call delegate.iterator[context.method](context.arg) and handle the
  898. // result, either by returning a { value, done } result from the
  899. // delegate iterator, or by modifying context.method and context.arg,
  900. // setting context.delegate to null, and returning the ContinueSentinel.
  901. function maybeInvokeDelegate(delegate, context) {
  902. var method = delegate.iterator[context.method];
  903. if (method === undefined) {
  904. // A .throw or .return when the delegate iterator has no .throw
  905. // method always terminates the yield* loop.
  906. context.delegate = null;
  907. if (context.method === "throw") {
  908. // Note: ["return"] must be used for ES3 parsing compatibility.
  909. if (delegate.iterator["return"]) {
  910. // If the delegate iterator has a return method, give it a
  911. // chance to clean up.
  912. context.method = "return";
  913. context.arg = undefined;
  914. maybeInvokeDelegate(delegate, context);
  915. if (context.method === "throw") {
  916. // If maybeInvokeDelegate(context) changed context.method from
  917. // "return" to "throw", let that override the TypeError below.
  918. return ContinueSentinel;
  919. }
  920. }
  921. context.method = "throw";
  922. context.arg = new TypeError(
  923. "The iterator does not provide a 'throw' method");
  924. }
  925. return ContinueSentinel;
  926. }
  927. var record = tryCatch(method, delegate.iterator, context.arg);
  928. if (record.type === "throw") {
  929. context.method = "throw";
  930. context.arg = record.arg;
  931. context.delegate = null;
  932. return ContinueSentinel;
  933. }
  934. var info = record.arg;
  935. if (! info) {
  936. context.method = "throw";
  937. context.arg = new TypeError("iterator result is not an object");
  938. context.delegate = null;
  939. return ContinueSentinel;
  940. }
  941. if (info.done) {
  942. // Assign the result of the finished delegate to the temporary
  943. // variable specified by delegate.resultName (see delegateYield).
  944. context[delegate.resultName] = info.value;
  945. // Resume execution at the desired location (see delegateYield).
  946. context.next = delegate.nextLoc;
  947. // If context.method was "throw" but the delegate handled the
  948. // exception, let the outer generator proceed normally. If
  949. // context.method was "next", forget context.arg since it has been
  950. // "consumed" by the delegate iterator. If context.method was
  951. // "return", allow the original .return call to continue in the
  952. // outer generator.
  953. if (context.method !== "return") {
  954. context.method = "next";
  955. context.arg = undefined;
  956. }
  957. } else {
  958. // Re-yield the result returned by the delegate method.
  959. return info;
  960. }
  961. // The delegate iterator is finished, so forget it and continue with
  962. // the outer generator.
  963. context.delegate = null;
  964. return ContinueSentinel;
  965. }
  966. // Define Generator.prototype.{next,throw,return} in terms of the
  967. // unified ._invoke helper method.
  968. defineIteratorMethods(Gp);
  969. Gp[toStringTagSymbol] = "Generator";
  970. // A Generator should always return itself as the iterator object when the
  971. // @@iterator function is called on it. Some browsers' implementations of the
  972. // iterator prototype chain incorrectly implement this, causing the Generator
  973. // object to not be returned from this call. This ensures that doesn't happen.
  974. // See https://github.com/facebook/regenerator/issues/274 for more details.
  975. Gp[iteratorSymbol] = function() {
  976. return this;
  977. };
  978. Gp.toString = function() {
  979. return "[object Generator]";
  980. };
  981. function pushTryEntry(locs) {
  982. var entry = { tryLoc: locs[0] };
  983. if (1 in locs) {
  984. entry.catchLoc = locs[1];
  985. }
  986. if (2 in locs) {
  987. entry.finallyLoc = locs[2];
  988. entry.afterLoc = locs[3];
  989. }
  990. this.tryEntries.push(entry);
  991. }
  992. function resetTryEntry(entry) {
  993. var record = entry.completion || {};
  994. record.type = "normal";
  995. delete record.arg;
  996. entry.completion = record;
  997. }
  998. function Context(tryLocsList) {
  999. // The root entry object (effectively a try statement without a catch
  1000. // or a finally block) gives us a place to store values thrown from
  1001. // locations where there is no enclosing try statement.
  1002. this.tryEntries = [{ tryLoc: "root" }];
  1003. tryLocsList.forEach(pushTryEntry, this);
  1004. this.reset(true);
  1005. }
  1006. exports.keys = function(object) {
  1007. var keys = [];
  1008. for (var key in object) {
  1009. keys.push(key);
  1010. }
  1011. keys.reverse();
  1012. // Rather than returning an object with a next method, we keep
  1013. // things simple and return the next function itself.
  1014. return function next() {
  1015. while (keys.length) {
  1016. var key = keys.pop();
  1017. if (key in object) {
  1018. next.value = key;
  1019. next.done = false;
  1020. return next;
  1021. }
  1022. }
  1023. // To avoid creating an additional object, we just hang the .value
  1024. // and .done properties off the next function object itself. This
  1025. // also ensures that the minifier will not anonymize the function.
  1026. next.done = true;
  1027. return next;
  1028. };
  1029. };
  1030. function values(iterable) {
  1031. if (iterable) {
  1032. var iteratorMethod = iterable[iteratorSymbol];
  1033. if (iteratorMethod) {
  1034. return iteratorMethod.call(iterable);
  1035. }
  1036. if (typeof iterable.next === "function") {
  1037. return iterable;
  1038. }
  1039. if (!isNaN(iterable.length)) {
  1040. var i = -1, next = function next() {
  1041. while (++i < iterable.length) {
  1042. if (hasOwn.call(iterable, i)) {
  1043. next.value = iterable[i];
  1044. next.done = false;
  1045. return next;
  1046. }
  1047. }
  1048. next.value = undefined;
  1049. next.done = true;
  1050. return next;
  1051. };
  1052. return next.next = next;
  1053. }
  1054. }
  1055. // Return an iterator with no values.
  1056. return { next: doneResult };
  1057. }
  1058. exports.values = values;
  1059. function doneResult() {
  1060. return { value: undefined, done: true };
  1061. }
  1062. Context.prototype = {
  1063. constructor: Context,
  1064. reset: function(skipTempReset) {
  1065. this.prev = 0;
  1066. this.next = 0;
  1067. // Resetting context._sent for legacy support of Babel's
  1068. // function.sent implementation.
  1069. this.sent = this._sent = undefined;
  1070. this.done = false;
  1071. this.delegate = null;
  1072. this.method = "next";
  1073. this.arg = undefined;
  1074. this.tryEntries.forEach(resetTryEntry);
  1075. if (!skipTempReset) {
  1076. for (var name in this) {
  1077. // Not sure about the optimal order of these conditions:
  1078. if (name.charAt(0) === "t" &&
  1079. hasOwn.call(this, name) &&
  1080. !isNaN(+name.slice(1))) {
  1081. this[name] = undefined;
  1082. }
  1083. }
  1084. }
  1085. },
  1086. stop: function() {
  1087. this.done = true;
  1088. var rootEntry = this.tryEntries[0];
  1089. var rootRecord = rootEntry.completion;
  1090. if (rootRecord.type === "throw") {
  1091. throw rootRecord.arg;
  1092. }
  1093. return this.rval;
  1094. },
  1095. dispatchException: function(exception) {
  1096. if (this.done) {
  1097. throw exception;
  1098. }
  1099. var context = this;
  1100. function handle(loc, caught) {
  1101. record.type = "throw";
  1102. record.arg = exception;
  1103. context.next = loc;
  1104. if (caught) {
  1105. // If the dispatched exception was caught by a catch block,
  1106. // then let that catch block handle the exception normally.
  1107. context.method = "next";
  1108. context.arg = undefined;
  1109. }
  1110. return !! caught;
  1111. }
  1112. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1113. var entry = this.tryEntries[i];
  1114. var record = entry.completion;
  1115. if (entry.tryLoc === "root") {
  1116. // Exception thrown outside of any try block that could handle
  1117. // it, so set the completion value of the entire function to
  1118. // throw the exception.
  1119. return handle("end");
  1120. }
  1121. if (entry.tryLoc <= this.prev) {
  1122. var hasCatch = hasOwn.call(entry, "catchLoc");
  1123. var hasFinally = hasOwn.call(entry, "finallyLoc");
  1124. if (hasCatch && hasFinally) {
  1125. if (this.prev < entry.catchLoc) {
  1126. return handle(entry.catchLoc, true);
  1127. } else if (this.prev < entry.finallyLoc) {
  1128. return handle(entry.finallyLoc);
  1129. }
  1130. } else if (hasCatch) {
  1131. if (this.prev < entry.catchLoc) {
  1132. return handle(entry.catchLoc, true);
  1133. }
  1134. } else if (hasFinally) {
  1135. if (this.prev < entry.finallyLoc) {
  1136. return handle(entry.finallyLoc);
  1137. }
  1138. } else {
  1139. throw new Error("try statement without catch or finally");
  1140. }
  1141. }
  1142. }
  1143. },
  1144. abrupt: function(type, arg) {
  1145. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1146. var entry = this.tryEntries[i];
  1147. if (entry.tryLoc <= this.prev &&
  1148. hasOwn.call(entry, "finallyLoc") &&
  1149. this.prev < entry.finallyLoc) {
  1150. var finallyEntry = entry;
  1151. break;
  1152. }
  1153. }
  1154. if (finallyEntry &&
  1155. (type === "break" ||
  1156. type === "continue") &&
  1157. finallyEntry.tryLoc <= arg &&
  1158. arg <= finallyEntry.finallyLoc) {
  1159. // Ignore the finally entry if control is not jumping to a
  1160. // location outside the try/catch block.
  1161. finallyEntry = null;
  1162. }
  1163. var record = finallyEntry ? finallyEntry.completion : {};
  1164. record.type = type;
  1165. record.arg = arg;
  1166. if (finallyEntry) {
  1167. this.method = "next";
  1168. this.next = finallyEntry.finallyLoc;
  1169. return ContinueSentinel;
  1170. }
  1171. return this.complete(record);
  1172. },
  1173. complete: function(record, afterLoc) {
  1174. if (record.type === "throw") {
  1175. throw record.arg;
  1176. }
  1177. if (record.type === "break" ||
  1178. record.type === "continue") {
  1179. this.next = record.arg;
  1180. } else if (record.type === "return") {
  1181. this.rval = this.arg = record.arg;
  1182. this.method = "return";
  1183. this.next = "end";
  1184. } else if (record.type === "normal" && afterLoc) {
  1185. this.next = afterLoc;
  1186. }
  1187. return ContinueSentinel;
  1188. },
  1189. finish: function(finallyLoc) {
  1190. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1191. var entry = this.tryEntries[i];
  1192. if (entry.finallyLoc === finallyLoc) {
  1193. this.complete(entry.completion, entry.afterLoc);
  1194. resetTryEntry(entry);
  1195. return ContinueSentinel;
  1196. }
  1197. }
  1198. },
  1199. "catch": function(tryLoc) {
  1200. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  1201. var entry = this.tryEntries[i];
  1202. if (entry.tryLoc === tryLoc) {
  1203. var record = entry.completion;
  1204. if (record.type === "throw") {
  1205. var thrown = record.arg;
  1206. resetTryEntry(entry);
  1207. }
  1208. return thrown;
  1209. }
  1210. }
  1211. // The context.catch method must only be called with a location
  1212. // argument that corresponds to a known catch block.
  1213. throw new Error("illegal catch attempt");
  1214. },
  1215. delegateYield: function(iterable, resultName, nextLoc) {
  1216. this.delegate = {
  1217. iterator: values(iterable),
  1218. resultName: resultName,
  1219. nextLoc: nextLoc
  1220. };
  1221. if (this.method === "next") {
  1222. // Deliberately forget the last sent value so that we don't
  1223. // accidentally pass it on to the delegate.
  1224. this.arg = undefined;
  1225. }
  1226. return ContinueSentinel;
  1227. }
  1228. };
  1229. // Regardless of whether this script is executing as a CommonJS module
  1230. // or not, return the runtime object so that we can declare the variable
  1231. // regeneratorRuntime in the outer scope, which allows this module to be
  1232. // injected easily by `bin/regenerator --include-runtime script.js`.
  1233. return exports;
  1234. }(
  1235. // If this script is executing as a CommonJS module, use module.exports
  1236. // as the regeneratorRuntime namespace. Otherwise create a new empty
  1237. // object. Either way, the resulting object will be used to initialize
  1238. // the regeneratorRuntime variable at the top of this file.
  1239. true ? module.exports : undefined
  1240. ));
  1241. try {
  1242. regeneratorRuntime = runtime;
  1243. } catch (accidentalStrictMode) {
  1244. // This module should not be running in strict mode, so the above
  1245. // assignment should always work unless something is misconfigured. Just
  1246. // in case runtime.js accidentally runs in strict mode, we can escape
  1247. // strict mode using a global Function call. This could conceivably fail
  1248. // if a Content Security Policy forbids using Function, but in that case
  1249. // the proper solution is to fix the accidental strict mode problem. If
  1250. // you've misconfigured your bundler to force strict mode and applied a
  1251. // CSP to forbid Function, and you're not willing to fix either of those
  1252. // problems, please detail your unique predicament in a GitHub issue.
  1253. Function("r", "regeneratorRuntime = r")(runtime);
  1254. }
  1255. /***/ }),
  1256. /***/ 5:
  1257. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  1258. "use strict";
  1259. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _assertThisInitialized; });
  1260. function _assertThisInitialized(self) {
  1261. if (self === void 0) {
  1262. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1263. }
  1264. return self;
  1265. }
  1266. /***/ }),
  1267. /***/ 8:
  1268. /***/ (function(module, exports) {
  1269. (function() { module.exports = this["wp"]["compose"]; }());
  1270. /***/ })
  1271. /******/ });