[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> list-reusable-blocks.js (source)

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


Generated: Thu Dec 3 01:00:04 2020 Cross-referenced by PHPXref 0.7.1