WordPress/js/dist/list-reusable-blocks.js

1011 lines
40 KiB
JavaScript

this["wp"] = this["wp"] || {}; this["wp"]["listReusableBlocks"] =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./node_modules/@wordpress/list-reusable-blocks/build-module/index.js");
/******/ })
/************************************************************************/
/******/ ({
/***/ "./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js":
/*!**************************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js ***!
\**************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _assertThisInitialized; });
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js":
/*!*********************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js ***!
\*********************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _asyncToGenerator; });
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/classCallCheck.js":
/*!*******************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _classCallCheck; });
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/createClass.js":
/*!****************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/createClass.js ***!
\****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _createClass; });
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js":
/*!*******************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/defineProperty.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _defineProperty; });
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js":
/*!*******************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _getPrototypeOf; });
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/inherits.js":
/*!*************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/inherits.js ***!
\*************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _inherits; });
/* harmony import */ var _setPrototypeOf__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./setPrototypeOf */ "./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js");
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) Object(_setPrototypeOf__WEBPACK_IMPORTED_MODULE_0__["default"])(subClass, superClass);
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/objectSpread.js":
/*!*****************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/objectSpread.js ***!
\*****************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _objectSpread; });
/* harmony import */ var _defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./defineProperty */ "./node_modules/@babel/runtime/helpers/esm/defineProperty.js");
function _objectSpread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function (key) {
Object(_defineProperty__WEBPACK_IMPORTED_MODULE_0__["default"])(target, key, source[key]);
});
}
return target;
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js":
/*!******************************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js ***!
\******************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _possibleConstructorReturn; });
/* harmony import */ var _helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../helpers/esm/typeof */ "./node_modules/@babel/runtime/helpers/esm/typeof.js");
/* harmony import */ var _assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./assertThisInitialized */ "./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js");
function _possibleConstructorReturn(self, call) {
if (call && (Object(_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__["default"])(call) === "object" || typeof call === "function")) {
return call;
}
return Object(_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__["default"])(self);
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js":
/*!*******************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js ***!
\*******************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _setPrototypeOf; });
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
/***/ }),
/***/ "./node_modules/@babel/runtime/helpers/esm/typeof.js":
/*!***********************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/esm/typeof.js ***!
\***********************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _typeof; });
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); }
function _typeof(obj) {
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
_typeof = function _typeof(obj) {
return _typeof2(obj);
};
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
};
}
return _typeof(obj);
}
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js":
/*!*******************************************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js ***!
\*******************************************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _import_form__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../import-form */ "./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function ImportDropdown(_ref) {
var onUpload = _ref.onUpload;
return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__["Dropdown"], {
position: "bottom right",
contentClassName: "list-reusable-blocks-import-dropdown__content",
renderToggle: function renderToggle(_ref2) {
var isOpen = _ref2.isOpen,
onToggle = _ref2.onToggle;
return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_3__["Button"], {
type: "button",
"aria-expanded": isOpen,
onClick: onToggle,
isPrimary: true
}, Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__["__"])('Import from JSON'));
},
renderContent: function renderContent(_ref3) {
var onClose = _ref3.onClose;
return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])(_import_form__WEBPACK_IMPORTED_MODULE_4__["default"], {
onUpload: Object(lodash__WEBPACK_IMPORTED_MODULE_1__["flow"])(onClose, onUpload)
});
}
});
}
/* harmony default export */ __webpack_exports__["default"] = (ImportDropdown);
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js":
/*!***************************************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js ***!
\***************************************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/classCallCheck */ "./node_modules/@babel/runtime/helpers/esm/classCallCheck.js");
/* harmony import */ var _babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/esm/createClass */ "./node_modules/@babel/runtime/helpers/esm/createClass.js");
/* harmony import */ var _babel_runtime_helpers_esm_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @babel/runtime/helpers/esm/possibleConstructorReturn */ "./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js");
/* harmony import */ var _babel_runtime_helpers_esm_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @babel/runtime/helpers/esm/getPrototypeOf */ "./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js");
/* harmony import */ var _babel_runtime_helpers_esm_inherits__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @babel/runtime/helpers/esm/inherits */ "./node_modules/@babel/runtime/helpers/esm/inherits.js");
/* harmony import */ var _babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @babel/runtime/helpers/esm/assertThisInitialized */ "./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose");
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @wordpress/components */ "@wordpress/components");
/* harmony import */ var _wordpress_components__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_wordpress_components__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _utils_import__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../utils/import */ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
var ImportForm =
/*#__PURE__*/
function (_Component) {
Object(_babel_runtime_helpers_esm_inherits__WEBPACK_IMPORTED_MODULE_4__["default"])(ImportForm, _Component);
function ImportForm() {
var _this;
Object(_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_0__["default"])(this, ImportForm);
_this = Object(_babel_runtime_helpers_esm_possibleConstructorReturn__WEBPACK_IMPORTED_MODULE_2__["default"])(this, Object(_babel_runtime_helpers_esm_getPrototypeOf__WEBPACK_IMPORTED_MODULE_3__["default"])(ImportForm).apply(this, arguments));
_this.state = {
isLoading: false,
error: null,
file: null
};
_this.isStillMounted = true;
_this.onChangeFile = _this.onChangeFile.bind(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__["default"])(_this)));
_this.onSubmit = _this.onSubmit.bind(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__["default"])(Object(_babel_runtime_helpers_esm_assertThisInitialized__WEBPACK_IMPORTED_MODULE_5__["default"])(_this)));
return _this;
}
Object(_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_1__["default"])(ImportForm, [{
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.isStillMounted = false;
}
}, {
key: "onChangeFile",
value: function onChangeFile(event) {
this.setState({
file: event.target.files[0]
});
}
}, {
key: "onSubmit",
value: function onSubmit(event) {
var _this2 = this;
event.preventDefault();
var file = this.state.file;
var onUpload = this.props.onUpload;
if (!file) {
return;
}
this.setState({
isLoading: true
});
Object(_utils_import__WEBPACK_IMPORTED_MODULE_10__["default"])(file).then(function (reusableBlock) {
if (!_this2.isStillMounted) {
return;
}
_this2.setState({
isLoading: false
});
onUpload(reusableBlock);
}).catch(function (error) {
if (!_this2.isStillMounted) {
return;
}
var uiMessage;
switch (error.message) {
case 'Invalid JSON file':
uiMessage = Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__["__"])('Invalid JSON file');
break;
case 'Invalid Reusable Block JSON file':
uiMessage = Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__["__"])('Invalid Reusable Block JSON file');
break;
default:
uiMessage = Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__["__"])('Unknown error');
}
_this2.setState({
isLoading: false,
error: uiMessage
});
});
}
}, {
key: "render",
value: function render() {
var instanceId = this.props.instanceId;
var _this$state = this.state,
file = _this$state.file,
isLoading = _this$state.isLoading,
error = _this$state.error;
var inputId = 'list-reusable-blocks-import-form-' + instanceId;
return Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["createElement"])("form", {
className: "list-reusable-blocks-import-form",
onSubmit: this.onSubmit
}, error && Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_9__["Notice"], {
status: "error"
}, error), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["createElement"])("label", {
htmlFor: inputId,
className: "list-reusable-blocks-import-form__label"
}, Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__["__"])('File')), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["createElement"])("input", {
id: inputId,
type: "file",
onChange: this.onChangeFile
}), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_9__["Button"], {
type: "submit",
isBusy: isLoading,
disabled: !file || isLoading,
isDefault: true,
className: "list-reusable-blocks-import-form__button"
}, Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_8__["__"])('Import')));
}
}]);
return ImportForm;
}(_wordpress_element__WEBPACK_IMPORTED_MODULE_6__["Component"]);
/* harmony default export */ __webpack_exports__["default"] = (Object(_wordpress_compose__WEBPACK_IMPORTED_MODULE_7__["withInstanceId"])(ImportForm));
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/index.js":
/*!****************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/index.js ***!
\****************************************************************************/
/*! no exports provided */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element");
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n");
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _utils_export__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils/export */ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js");
/* harmony import */ var _components_import_dropdown__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./components/import-dropdown */ "./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
// Setup Export Links
document.body.addEventListener('click', function (event) {
if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
return;
}
event.preventDefault();
Object(_utils_export__WEBPACK_IMPORTED_MODULE_2__["default"])(event.target.dataset.id);
}); // Setup Import Form
document.addEventListener('DOMContentLoaded', function () {
var button = document.querySelector('.page-title-action');
if (!button) {
return;
}
var showNotice = function showNotice() {
var notice = document.createElement('div');
notice.className = 'notice notice-success is-dismissible';
notice.innerHTML = "<p>".concat(Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_1__["__"])('Reusable block imported successfully!'), "</p>");
var headerEnd = document.querySelector('.wp-header-end');
if (!headerEnd) {
return;
}
headerEnd.parentNode.insertBefore(notice, headerEnd);
};
var container = document.createElement('div');
container.className = 'list-reusable-blocks__container';
button.parentNode.insertBefore(container, button);
Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["render"])(Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__["createElement"])(_components_import_dropdown__WEBPACK_IMPORTED_MODULE_3__["default"], {
onUpload: showNotice
}), container);
});
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js":
/*!***********************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js ***!
\***********************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_helpers_esm_objectSpread__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/objectSpread */ "./node_modules/@babel/runtime/helpers/esm/objectSpread.js");
/* harmony import */ var _babel_runtime_helpers_esm_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @babel/runtime/helpers/esm/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch");
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _file__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./file */ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Export a reusable block as a JSON file.
*
* @param {number} id
*/
function exportReusableBlock(_x) {
return _exportReusableBlock.apply(this, arguments);
}
function _exportReusableBlock() {
_exportReusableBlock = Object(_babel_runtime_helpers_esm_asyncToGenerator__WEBPACK_IMPORTED_MODULE_1__["default"])(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(id) {
var postType, reusableBlock, fileContent, fileName;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({
path: "/wp/v2/types/wp_block"
});
case 2:
postType = _context.sent;
_context.next = 5;
return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_3___default()({
path: "/wp/v2/".concat(postType.rest_base, "/").concat(id)
});
case 5:
reusableBlock = _context.sent;
fileContent = JSON.stringify(Object(_babel_runtime_helpers_esm_objectSpread__WEBPACK_IMPORTED_MODULE_0__["default"])({
__file: 'wp_block'
}, Object(lodash__WEBPACK_IMPORTED_MODULE_2__["pick"])(reusableBlock, ['title', 'content'])), null, 2);
fileName = Object(lodash__WEBPACK_IMPORTED_MODULE_2__["kebabCase"])(reusableBlock.title) + '.json';
Object(_file__WEBPACK_IMPORTED_MODULE_4__["download"])(fileName, fileContent, 'application/json');
case 9:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
return _exportReusableBlock.apply(this, arguments);
}
/* harmony default export */ __webpack_exports__["default"] = (exportReusableBlock);
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js":
/*!*********************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js ***!
\*********************************************************************************/
/*! exports provided: download, readTextFile */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "download", function() { return download; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "readTextFile", function() { return readTextFile; });
/**
* Downloads a file.
*
* @param {string} fileName File Name.
* @param {string} content File Content.
* @param {string} contentType File mime type.
*/
function download(fileName, content, contentType) {
var file = new window.Blob([content], {
type: contentType
}); // IE11 can't use the click to download technique
// we use a specific IE11 technique instead.
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(file, fileName);
} else {
var a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
}
/**
* Reads the textual content of the given file.
*
* @param {File} file File.
* @return {Promise<string>} Content of the file.
*/
function readTextFile(file) {
var reader = new window.FileReader();
return new Promise(function (resolve) {
reader.onload = function () {
resolve(reader.result);
};
reader.readAsText(file);
});
}
/***/ }),
/***/ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js":
/*!***********************************************************************************!*\
!*** ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js ***!
\***********************************************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _babel_runtime_helpers_esm_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/api-fetch */ "@wordpress/api-fetch");
/* harmony import */ var _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _file__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./file */ "./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
/**
* Import a reusable block from a JSON file.
*
* @param {File} file File.
* @return {Promise} Promise returning the imported reusable block.
*/
function importReusableBlock(_x) {
return _importReusableBlock.apply(this, arguments);
}
function _importReusableBlock() {
_importReusableBlock = Object(_babel_runtime_helpers_esm_asyncToGenerator__WEBPACK_IMPORTED_MODULE_0__["default"])(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(file) {
var fileContent, parsedContent, postType, reusableBlock;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return Object(_file__WEBPACK_IMPORTED_MODULE_3__["readTextFile"])(file);
case 2:
fileContent = _context.sent;
_context.prev = 3;
parsedContent = JSON.parse(fileContent);
_context.next = 10;
break;
case 7:
_context.prev = 7;
_context.t0 = _context["catch"](3);
throw new Error('Invalid JSON file');
case 10:
if (!(parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !Object(lodash__WEBPACK_IMPORTED_MODULE_1__["isString"])(parsedContent.title) || !Object(lodash__WEBPACK_IMPORTED_MODULE_1__["isString"])(parsedContent.content))) {
_context.next = 12;
break;
}
throw new Error('Invalid Reusable Block JSON file');
case 12:
_context.next = 14;
return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_2___default()({
path: "/wp/v2/types/wp_block"
});
case 14:
postType = _context.sent;
_context.next = 17;
return _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_2___default()({
path: "/wp/v2/".concat(postType.rest_base),
data: {
title: parsedContent.title,
content: parsedContent.content
},
method: 'POST'
});
case 17:
reusableBlock = _context.sent;
return _context.abrupt("return", reusableBlock);
case 19:
case "end":
return _context.stop();
}
}
}, _callee, this, [[3, 7]]);
}));
return _importReusableBlock.apply(this, arguments);
}
/* harmony default export */ __webpack_exports__["default"] = (importReusableBlock);
/***/ }),
/***/ "@wordpress/api-fetch":
/*!*******************************************!*\
!*** external {"this":["wp","apiFetch"]} ***!
\*******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["apiFetch"]; }());
/***/ }),
/***/ "@wordpress/components":
/*!*********************************************!*\
!*** external {"this":["wp","components"]} ***!
\*********************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["components"]; }());
/***/ }),
/***/ "@wordpress/compose":
/*!******************************************!*\
!*** external {"this":["wp","compose"]} ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["compose"]; }());
/***/ }),
/***/ "@wordpress/element":
/*!******************************************!*\
!*** external {"this":["wp","element"]} ***!
\******************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["element"]; }());
/***/ }),
/***/ "@wordpress/i18n":
/*!***************************************!*\
!*** external {"this":["wp","i18n"]} ***!
\***************************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["wp"]["i18n"]; }());
/***/ }),
/***/ "lodash":
/*!*************************!*\
!*** external "lodash" ***!
\*************************/
/*! no static exports found */
/***/ (function(module, exports) {
(function() { module.exports = this["lodash"]; }());
/***/ })
/******/ });
//# sourceMappingURL=list-reusable-blocks.js.map