2022-04-11 14:04:30 +02:00
|
|
|
/******/ (function() { // webpackBootstrap
|
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/compat get default export */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
|
|
/******/ __webpack_require__.n = function(module) {
|
|
|
|
/******/ var getter = module && module.__esModule ?
|
|
|
|
/******/ function() { return module['default']; } :
|
|
|
|
/******/ function() { return module; };
|
|
|
|
/******/ __webpack_require__.d(getter, { a: getter });
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
|
|
|
/******/ }();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ // define getter functions for harmony exports
|
|
|
|
/******/ __webpack_require__.d = function(exports, definition) {
|
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
2018-12-14 05:41:57 +01:00
|
|
|
/******/ };
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ }();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
|
|
/******/ }();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ // 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 });
|
|
|
|
/******/ };
|
|
|
|
/******/ }();
|
|
|
|
/******/
|
2018-12-14 05:41:57 +01:00
|
|
|
/************************************************************************/
|
2022-04-11 14:04:30 +02:00
|
|
|
var __webpack_exports__ = {};
|
2020-06-29 13:50:29 +02:00
|
|
|
// ESM COMPAT FLAG
|
2018-12-14 05:41:57 +01:00
|
|
|
__webpack_require__.r(__webpack_exports__);
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","element"]
|
|
|
|
var external_wp_element_namespaceObject = window["wp"]["element"];
|
|
|
|
;// CONCATENATED MODULE: external ["wp","i18n"]
|
|
|
|
var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
|
|
|
|
;// CONCATENATED MODULE: external "lodash"
|
|
|
|
var external_lodash_namespaceObject = window["lodash"];
|
|
|
|
;// CONCATENATED MODULE: external ["wp","apiFetch"]
|
|
|
|
var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
|
|
|
|
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/file.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Downloads a file.
|
|
|
|
*
|
|
|
|
* @param {string} fileName File Name.
|
|
|
|
* @param {string} content File Content.
|
|
|
|
* @param {string} contentType File mime type.
|
|
|
|
*/
|
|
|
|
function download(fileName, content, contentType) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const file = new window.Blob([content], {
|
2018-12-18 04:14:52 +01:00
|
|
|
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 {
|
2021-05-19 17:09:27 +02:00
|
|
|
const a = document.createElement('a');
|
2018-12-18 04:14:52 +01:00
|
|
|
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.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {File} file File.
|
2018-12-18 04:14:52 +01:00
|
|
|
* @return {Promise<string>} Content of the file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function readTextFile(file) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const reader = new window.FileReader();
|
|
|
|
return new Promise(resolve => {
|
|
|
|
reader.onload = () => {
|
2018-12-18 04:14:52 +01:00
|
|
|
resolve(reader.result);
|
|
|
|
};
|
|
|
|
|
|
|
|
reader.readAsText(file);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/export.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Export a reusable block as a JSON file.
|
|
|
|
*
|
|
|
|
* @param {number} id
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
async function exportReusableBlock(id) {
|
|
|
|
const postType = await external_wp_apiFetch_default()({
|
|
|
|
path: `/wp/v2/types/wp_block`
|
|
|
|
});
|
|
|
|
const post = await external_wp_apiFetch_default()({
|
|
|
|
path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
|
|
|
|
});
|
|
|
|
const title = post.title.raw;
|
|
|
|
const content = post.content.raw;
|
|
|
|
const fileContent = JSON.stringify({
|
|
|
|
__file: 'wp_block',
|
|
|
|
title,
|
|
|
|
content
|
|
|
|
}, null, 2);
|
2022-04-11 14:04:30 +02:00
|
|
|
const fileName = (0,external_lodash_namespaceObject.kebabCase)(title) + '.json';
|
2021-05-19 17:09:27 +02:00
|
|
|
download(fileName, fileContent, 'application/json');
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/* harmony default export */ var utils_export = (exportReusableBlock);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","components"]
|
|
|
|
var external_wp_components_namespaceObject = window["wp"]["components"];
|
|
|
|
;// CONCATENATED MODULE: external ["wp","compose"]
|
|
|
|
var external_wp_compose_namespaceObject = window["wp"]["compose"];
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/utils/import.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2018-12-18 04:14:52 +01:00
|
|
|
* External dependencies
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Import a reusable block from a JSON file.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {File} file File.
|
2018-12-18 04:14:52 +01:00
|
|
|
* @return {Promise} Promise returning the imported reusable block.
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
async function importReusableBlock(file) {
|
|
|
|
const fileContent = await readTextFile(file);
|
|
|
|
let parsedContent;
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
try {
|
|
|
|
parsedContent = JSON.parse(fileContent);
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error('Invalid JSON file');
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || !(0,external_lodash_namespaceObject.isString)(parsedContent.title) || !(0,external_lodash_namespaceObject.isString)(parsedContent.content)) {
|
2021-05-19 17:09:27 +02:00
|
|
|
throw new Error('Invalid Reusable block JSON file');
|
|
|
|
}
|
|
|
|
|
|
|
|
const postType = await external_wp_apiFetch_default()({
|
|
|
|
path: `/wp/v2/types/wp_block`
|
|
|
|
});
|
|
|
|
const reusableBlock = await external_wp_apiFetch_default()({
|
|
|
|
path: `/wp/v2/${postType.rest_base}`,
|
|
|
|
data: {
|
|
|
|
title: parsedContent.title,
|
|
|
|
content: parsedContent.content,
|
|
|
|
status: 'publish'
|
|
|
|
},
|
|
|
|
method: 'POST'
|
|
|
|
});
|
|
|
|
return reusableBlock;
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* harmony default export */ var utils_import = (importReusableBlock);
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-form/index.js
|
2018-12-18 04:14:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
function ImportForm(_ref) {
|
|
|
|
let {
|
|
|
|
instanceId,
|
|
|
|
onUpload
|
|
|
|
} = _ref;
|
|
|
|
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
|
|
const formRef = (0,external_wp_element_namespaceObject.useRef)();
|
|
|
|
const [isLoading, setIsLoading] = (0,external_wp_element_namespaceObject.useState)(false);
|
|
|
|
const [error, setError] = (0,external_wp_element_namespaceObject.useState)(null);
|
|
|
|
const [file, setFile] = (0,external_wp_element_namespaceObject.useState)(null);
|
|
|
|
|
|
|
|
const onChangeFile = event => {
|
|
|
|
setFile(event.target.files[0]);
|
|
|
|
setError(null);
|
|
|
|
};
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
const onSubmit = event => {
|
2021-05-19 17:09:27 +02:00
|
|
|
event.preventDefault();
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
setIsLoading({
|
2021-05-19 17:09:27 +02:00
|
|
|
isLoading: true
|
|
|
|
});
|
|
|
|
utils_import(file).then(reusableBlock => {
|
2022-04-12 17:12:47 +02:00
|
|
|
if (!formRef) {
|
2018-12-14 05:41:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
setIsLoading(false);
|
2021-05-19 17:09:27 +02:00
|
|
|
onUpload(reusableBlock);
|
2022-04-12 17:12:47 +02:00
|
|
|
}).catch(errors => {
|
|
|
|
if (!formRef) {
|
2021-05-19 17:09:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let uiMessage;
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
switch (errors.message) {
|
2021-05-19 17:09:27 +02:00
|
|
|
case 'Invalid JSON file':
|
2022-04-11 14:04:30 +02:00
|
|
|
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Invalid JSON file');
|
2021-05-19 17:09:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Invalid Reusable block JSON file':
|
2022-04-11 14:04:30 +02:00
|
|
|
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Invalid Reusable block JSON file');
|
2021-05-19 17:09:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-04-11 14:04:30 +02:00
|
|
|
uiMessage = (0,external_wp_i18n_namespaceObject.__)('Unknown error');
|
2021-05-19 17:09:27 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
setIsLoading(false);
|
|
|
|
setError(uiMessage);
|
2021-05-19 17:09:27 +02:00
|
|
|
});
|
2022-04-12 17:12:47 +02:00
|
|
|
};
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
const onDismissError = () => {
|
|
|
|
setError(null);
|
|
|
|
};
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
return (0,external_wp_element_namespaceObject.createElement)("form", {
|
|
|
|
className: "list-reusable-blocks-import-form",
|
|
|
|
onSubmit: onSubmit,
|
|
|
|
ref: formRef
|
|
|
|
}, error && (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Notice, {
|
|
|
|
status: "error",
|
|
|
|
onRemove: () => onDismissError()
|
|
|
|
}, error), (0,external_wp_element_namespaceObject.createElement)("label", {
|
|
|
|
htmlFor: inputId,
|
|
|
|
className: "list-reusable-blocks-import-form__label"
|
|
|
|
}, (0,external_wp_i18n_namespaceObject.__)('File')), (0,external_wp_element_namespaceObject.createElement)("input", {
|
|
|
|
id: inputId,
|
|
|
|
type: "file",
|
|
|
|
onChange: onChangeFile
|
|
|
|
}), (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
|
|
|
|
type: "submit",
|
|
|
|
isBusy: isLoading,
|
|
|
|
disabled: !file || isLoading,
|
|
|
|
variant: "secondary",
|
|
|
|
className: "list-reusable-blocks-import-form__button"
|
|
|
|
}, (0,external_wp_i18n_namespaceObject._x)('Import', 'button label')));
|
2021-05-19 17:09:27 +02:00
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
/* harmony default export */ var import_form = ((0,external_wp_compose_namespaceObject.withInstanceId)(ImportForm));
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/components/import-dropdown/index.js
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-15 13:50:17 +01:00
|
|
|
function ImportDropdown(_ref) {
|
|
|
|
let {
|
|
|
|
onUpload
|
|
|
|
} = _ref;
|
2022-04-11 14:04:30 +02:00
|
|
|
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Dropdown, {
|
2018-12-18 04:14:52 +01:00
|
|
|
position: "bottom right",
|
|
|
|
contentClassName: "list-reusable-blocks-import-dropdown__content",
|
2021-11-15 13:50:17 +01:00
|
|
|
renderToggle: _ref2 => {
|
|
|
|
let {
|
|
|
|
isOpen,
|
|
|
|
onToggle
|
|
|
|
} = _ref2;
|
2022-04-11 14:04:30 +02:00
|
|
|
return (0,external_wp_element_namespaceObject.createElement)(external_wp_components_namespaceObject.Button, {
|
2021-11-15 13:50:17 +01:00
|
|
|
"aria-expanded": isOpen,
|
|
|
|
onClick: onToggle,
|
|
|
|
variant: "primary"
|
2022-04-11 14:04:30 +02:00
|
|
|
}, (0,external_wp_i18n_namespaceObject.__)('Import from JSON'));
|
2021-11-15 13:50:17 +01:00
|
|
|
},
|
|
|
|
renderContent: _ref3 => {
|
|
|
|
let {
|
|
|
|
onClose
|
|
|
|
} = _ref3;
|
2022-04-11 14:04:30 +02:00
|
|
|
return (0,external_wp_element_namespaceObject.createElement)(import_form, {
|
|
|
|
onUpload: (0,external_lodash_namespaceObject.flow)(onClose, onUpload)
|
2021-11-15 13:50:17 +01:00
|
|
|
});
|
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* harmony default export */ var import_dropdown = (ImportDropdown);
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/list-reusable-blocks/build-module/index.js
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
// Setup Export Links.
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
document.body.addEventListener('click', event => {
|
2018-12-14 05:41:57 +01:00
|
|
|
if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
2018-12-18 04:14:52 +01:00
|
|
|
utils_export(event.target.dataset.id);
|
2022-04-12 17:12:47 +02:00
|
|
|
}); // Setup Import Form.
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
const button = document.querySelector('.page-title-action');
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
if (!button) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const showNotice = () => {
|
|
|
|
const notice = document.createElement('div');
|
2018-12-14 05:41:57 +01:00
|
|
|
notice.className = 'notice notice-success is-dismissible';
|
2022-04-11 14:04:30 +02:00
|
|
|
notice.innerHTML = `<p>${(0,external_wp_i18n_namespaceObject.__)('Reusable block imported successfully!')}</p>`;
|
2021-05-19 17:09:27 +02:00
|
|
|
const headerEnd = document.querySelector('.wp-header-end');
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
if (!headerEnd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
headerEnd.parentNode.insertBefore(notice, headerEnd);
|
|
|
|
};
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const container = document.createElement('div');
|
2018-12-14 05:41:57 +01:00
|
|
|
container.className = 'list-reusable-blocks__container';
|
|
|
|
button.parentNode.insertBefore(container, button);
|
2022-04-11 14:04:30 +02:00
|
|
|
(0,external_wp_element_namespaceObject.render)((0,external_wp_element_namespaceObject.createElement)(import_dropdown, {
|
2018-12-14 05:41:57 +01:00
|
|
|
onUpload: showNotice
|
|
|
|
}), container);
|
|
|
|
});
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
(window.wp = window.wp || {}).listReusableBlocks = __webpack_exports__;
|
|
|
|
/******/ })()
|
|
|
|
;
|