@wordpress/list-reusable-blocks 5.32.0 → 5.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/import-dropdown/index.js +58 -46
- package/build/components/import-dropdown/index.js.map +7 -1
- package/build/components/import-form/index.js +88 -70
- package/build/components/import-form/index.js.map +7 -1
- package/build/index.js +42 -36
- package/build/index.js.map +7 -1
- package/build/utils/export.js +50 -40
- package/build/utils/export.js.map +7 -1
- package/build/utils/file.js +27 -13
- package/build/utils/file.js.map +7 -1
- package/build/utils/import.js +44 -37
- package/build/utils/import.js.map +7 -1
- package/build-module/components/import-dropdown/index.js +30 -39
- package/build-module/components/import-dropdown/index.js.map +7 -1
- package/build-module/components/import-form/index.js +56 -59
- package/build-module/components/import-form/index.js.map +7 -1
- package/build-module/index.js +19 -32
- package/build-module/index.js.map +7 -1
- package/build-module/utils/export.js +21 -33
- package/build-module/utils/export.js.map +7 -1
- package/build-module/utils/file.js +6 -9
- package/build-module/utils/file.js.map +7 -1
- package/build-module/utils/import.js +14 -29
- package/build-module/utils/import.js.map +7 -1
- package/build-style/style-rtl.css +32 -186
- package/build-style/style.css +32 -186
- package/package.json +17 -9
- package/src/style.scss +3 -2
package/build/utils/file.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/file.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,SAAS,aAAc,MAAO;AACpC,QAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAO,IAAI,QAAS,CAAE,YAAa;AAClC,WAAO,SAAS,MAAM;AACrB,cAAS,OAAO,MAAO;AAAA,IACxB;AACA,WAAO,WAAY,IAAK;AAAA,EACzB,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/utils/import.js
CHANGED
|
@@ -1,53 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var import_exports = {};
|
|
29
|
+
__export(import_exports, {
|
|
30
|
+
default: () => import_default
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Import a reusable block from a JSON file.
|
|
20
|
-
*
|
|
21
|
-
* @param {File} file File.
|
|
22
|
-
* @return {Promise} Promise returning the imported reusable block.
|
|
23
|
-
*/
|
|
32
|
+
module.exports = __toCommonJS(import_exports);
|
|
33
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
34
|
+
var import_file = require("./file");
|
|
24
35
|
async function importReusableBlock(file) {
|
|
25
|
-
const fileContent = await (0,
|
|
36
|
+
const fileContent = await (0, import_file.readTextFile)(file);
|
|
26
37
|
let parsedContent;
|
|
27
38
|
try {
|
|
28
39
|
parsedContent = JSON.parse(fileContent);
|
|
29
40
|
} catch (e) {
|
|
30
|
-
throw new Error(
|
|
41
|
+
throw new Error("Invalid JSON file");
|
|
31
42
|
}
|
|
32
|
-
if (parsedContent.__file !==
|
|
33
|
-
throw new Error(
|
|
43
|
+
if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") {
|
|
44
|
+
throw new Error("Invalid pattern JSON file");
|
|
34
45
|
}
|
|
35
|
-
const postType = await (0,
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
const reusableBlock = await (0, _apiFetch.default)({
|
|
46
|
+
const postType = await (0, import_api_fetch.default)({ path: `/wp/v2/types/wp_block` });
|
|
47
|
+
const reusableBlock = await (0, import_api_fetch.default)({
|
|
39
48
|
path: `/wp/v2/${postType.rest_base}`,
|
|
40
49
|
data: {
|
|
41
50
|
title: parsedContent.title,
|
|
42
51
|
content: parsedContent.content,
|
|
43
|
-
status:
|
|
44
|
-
meta: parsedContent.syncStatus ===
|
|
45
|
-
wp_pattern_sync_status: parsedContent.syncStatus
|
|
46
|
-
} : undefined
|
|
52
|
+
status: "publish",
|
|
53
|
+
meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
|
|
47
54
|
},
|
|
48
|
-
method:
|
|
55
|
+
method: "POST"
|
|
49
56
|
});
|
|
50
57
|
return reusableBlock;
|
|
51
58
|
}
|
|
52
|
-
var
|
|
53
|
-
//# sourceMappingURL=import.js.map
|
|
59
|
+
var import_default = importReusableBlock;
|
|
60
|
+
//# sourceMappingURL=import.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/import.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { readTextFile } from './file';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param {File} file File.\n * @return {Promise} Promise returning the imported reusable block.\n */\nasync function importReusableBlock( file ) {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent;\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch ( e ) {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid pattern JSON file' );\n\t}\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst reusableBlock = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t},\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,kBAA6B;AAQ7B,eAAe,oBAAqB,MAAO;AAC1C,QAAM,cAAc,UAAM,0BAAc,IAAK;AAC7C,MAAI;AACJ,MAAI;AACH,oBAAgB,KAAK,MAAO,WAAY;AAAA,EACzC,SAAU,GAAI;AACb,UAAM,IAAI,MAAO,mBAAoB;AAAA,EACtC;AACA,MACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UACpC;AACD,UAAM,IAAI,MAAO,2BAA4B;AAAA,EAC9C;AACA,QAAM,WAAW,UAAM,iBAAAA,SAAU,EAAE,MAAM,wBAAwB,CAAE;AACnE,QAAM,gBAAgB,UAAM,iBAAAA,SAAU;AAAA,IACrC,MAAM,UAAW,SAAS,SAAU;AAAA,IACpC,MAAM;AAAA,MACL,OAAO,cAAc;AAAA,MACrB,SAAS,cAAc;AAAA,MACvB,QAAQ;AAAA,MACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACT,CAAE;AAEF,SAAO;AACR;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": ["apiFetch"]
|
|
7
|
+
}
|
|
@@ -1,40 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
className: "list-reusable-blocks-import-dropdown__button",
|
|
27
|
-
"aria-expanded": isOpen,
|
|
28
|
-
onClick: onToggle,
|
|
29
|
-
variant: "primary",
|
|
30
|
-
children: __('Import from JSON')
|
|
31
|
-
}),
|
|
32
|
-
renderContent: ({
|
|
33
|
-
onClose
|
|
34
|
-
}) => /*#__PURE__*/_jsx(ImportForm, {
|
|
35
|
-
onUpload: pipe(onClose, onUpload)
|
|
36
|
-
})
|
|
37
|
-
});
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { pipe } from "@wordpress/compose";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import { Dropdown, Button } from "@wordpress/components";
|
|
5
|
+
import ImportForm from "../import-form";
|
|
6
|
+
function ImportDropdown({ onUpload }) {
|
|
7
|
+
return /* @__PURE__ */ jsx(
|
|
8
|
+
Dropdown,
|
|
9
|
+
{
|
|
10
|
+
popoverProps: { placement: "bottom-start" },
|
|
11
|
+
contentClassName: "list-reusable-blocks-import-dropdown__content",
|
|
12
|
+
renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ jsx(
|
|
13
|
+
Button,
|
|
14
|
+
{
|
|
15
|
+
size: "compact",
|
|
16
|
+
className: "list-reusable-blocks-import-dropdown__button",
|
|
17
|
+
"aria-expanded": isOpen,
|
|
18
|
+
onClick: onToggle,
|
|
19
|
+
variant: "primary",
|
|
20
|
+
children: __("Import from JSON")
|
|
21
|
+
}
|
|
22
|
+
),
|
|
23
|
+
renderContent: ({ onClose }) => /* @__PURE__ */ jsx(ImportForm, { onUpload: pipe(onClose, onUpload) })
|
|
24
|
+
}
|
|
25
|
+
);
|
|
38
26
|
}
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
var import_dropdown_default = ImportDropdown;
|
|
28
|
+
export {
|
|
29
|
+
import_dropdown_default as default
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/import-dropdown/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { pipe } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport { Dropdown, Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport ImportForm from '../import-form';\n\nfunction ImportDropdown( { onUpload } ) {\n\treturn (\n\t\t<Dropdown\n\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\tcontentClassName=\"list-reusable-blocks-import-dropdown__content\"\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<Button\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"list-reusable-blocks-import-dropdown__button\"\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Import from JSON' ) }\n\t\t\t\t</Button>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<ImportForm onUpload={ pipe( onClose, onUpload ) } />\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default ImportDropdown;\n"],
|
|
5
|
+
"mappings": "AAkBI;AAfJ,SAAS,YAAY;AACrB,SAAS,UAAU;AACnB,SAAS,UAAU,cAAc;AAKjC,OAAO,gBAAgB;AAEvB,SAAS,eAAgB,EAAE,SAAS,GAAI;AACvC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,cAAe,EAAE,WAAW,eAAe;AAAA,MAC3C,kBAAiB;AAAA,MACjB,cAAe,CAAE,EAAE,QAAQ,SAAS,MACnC;AAAA,QAAC;AAAA;AAAA,UACA,MAAK;AAAA,UACL,WAAU;AAAA,UACV,iBAAgB;AAAA,UAChB,SAAU;AAAA,UACV,SAAQ;AAAA,UAEN,aAAI,kBAAmB;AAAA;AAAA,MAC1B;AAAA,MAED,eAAgB,CAAE,EAAE,QAAQ,MAC3B,oBAAC,cAAW,UAAW,KAAM,SAAS,QAAS,GAAI;AAAA;AAAA,EAErD;AAEF;AAEA,IAAO,0BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,57 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Internal dependencies
|
|
11
|
-
*/
|
|
12
|
-
import importReusableBlock from '../../utils/import';
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
function ImportForm({
|
|
15
|
-
instanceId,
|
|
16
|
-
onUpload
|
|
17
|
-
}) {
|
|
18
|
-
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef } from "@wordpress/element";
|
|
3
|
+
import { withInstanceId } from "@wordpress/compose";
|
|
4
|
+
import { __, _x } from "@wordpress/i18n";
|
|
5
|
+
import { Button, Notice } from "@wordpress/components";
|
|
6
|
+
import importReusableBlock from "../../utils/import";
|
|
7
|
+
function ImportForm({ instanceId, onUpload }) {
|
|
8
|
+
const inputId = "list-reusable-blocks-import-form-" + instanceId;
|
|
19
9
|
const formRef = useRef();
|
|
20
10
|
const [isLoading, setIsLoading] = useState(false);
|
|
21
11
|
const [error, setError] = useState(null);
|
|
22
12
|
const [file, setFile] = useState(null);
|
|
23
|
-
const onChangeFile = event => {
|
|
13
|
+
const onChangeFile = (event) => {
|
|
24
14
|
setFile(event.target.files[0]);
|
|
25
15
|
setError(null);
|
|
26
16
|
};
|
|
27
|
-
const onSubmit = event => {
|
|
17
|
+
const onSubmit = (event) => {
|
|
28
18
|
event.preventDefault();
|
|
29
19
|
if (!file) {
|
|
30
20
|
return;
|
|
31
21
|
}
|
|
32
|
-
setIsLoading({
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
importReusableBlock(file).then(reusableBlock => {
|
|
22
|
+
setIsLoading({ isLoading: true });
|
|
23
|
+
importReusableBlock(file).then((reusableBlock) => {
|
|
36
24
|
if (!formRef) {
|
|
37
25
|
return;
|
|
38
26
|
}
|
|
39
27
|
setIsLoading(false);
|
|
40
28
|
onUpload(reusableBlock);
|
|
41
|
-
}).catch(errors => {
|
|
29
|
+
}).catch((errors) => {
|
|
42
30
|
if (!formRef) {
|
|
43
31
|
return;
|
|
44
32
|
}
|
|
45
33
|
let uiMessage;
|
|
46
34
|
switch (errors.message) {
|
|
47
|
-
case
|
|
48
|
-
uiMessage = __(
|
|
35
|
+
case "Invalid JSON file":
|
|
36
|
+
uiMessage = __("Invalid JSON file");
|
|
49
37
|
break;
|
|
50
|
-
case
|
|
51
|
-
uiMessage = __(
|
|
38
|
+
case "Invalid pattern JSON file":
|
|
39
|
+
uiMessage = __("Invalid pattern JSON file");
|
|
52
40
|
break;
|
|
53
41
|
default:
|
|
54
|
-
uiMessage = __(
|
|
42
|
+
uiMessage = __("Unknown error");
|
|
55
43
|
}
|
|
56
44
|
setIsLoading(false);
|
|
57
45
|
setError(uiMessage);
|
|
@@ -60,33 +48,42 @@ function ImportForm({
|
|
|
60
48
|
const onDismissError = () => {
|
|
61
49
|
setError(null);
|
|
62
50
|
};
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
51
|
+
return /* @__PURE__ */ jsxs(
|
|
52
|
+
"form",
|
|
53
|
+
{
|
|
54
|
+
className: "list-reusable-blocks-import-form",
|
|
55
|
+
onSubmit,
|
|
56
|
+
ref: formRef,
|
|
57
|
+
children: [
|
|
58
|
+
error && /* @__PURE__ */ jsx(Notice, { status: "error", onRemove: () => onDismissError(), children: error }),
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
"label",
|
|
61
|
+
{
|
|
62
|
+
htmlFor: inputId,
|
|
63
|
+
className: "list-reusable-blocks-import-form__label",
|
|
64
|
+
children: __("File")
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsx("input", { id: inputId, type: "file", onChange: onChangeFile }),
|
|
68
|
+
/* @__PURE__ */ jsx(
|
|
69
|
+
Button,
|
|
70
|
+
{
|
|
71
|
+
__next40pxDefaultSize: true,
|
|
72
|
+
type: "submit",
|
|
73
|
+
isBusy: isLoading,
|
|
74
|
+
accessibleWhenDisabled: true,
|
|
75
|
+
disabled: !file || isLoading,
|
|
76
|
+
variant: "secondary",
|
|
77
|
+
className: "list-reusable-blocks-import-form__button",
|
|
78
|
+
children: _x("Import", "button label")
|
|
79
|
+
}
|
|
80
|
+
)
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
);
|
|
90
84
|
}
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
var import_form_default = withInstanceId(ImportForm);
|
|
86
|
+
export {
|
|
87
|
+
import_form_default as default
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/import-form/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useRef } from '@wordpress/element';\nimport { withInstanceId } from '@wordpress/compose';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, Notice } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport importReusableBlock from '../../utils/import';\n\nfunction ImportForm( { instanceId, onUpload } ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef();\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState( null );\n\tconst [ file, setFile ] = useState( null );\n\n\tconst onChangeFile = ( event ) => {\n\t\tsetFile( event.target.files[ 0 ] );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( { isLoading: true } );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tonUpload( reusableBlock );\n\t\t\t} )\n\t\t\t.catch( ( errors ) => {\n\t\t\t\tif ( ! formRef ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage;\n\t\t\t\tswitch ( errors.message ) {\n\t\t\t\t\tcase 'Invalid JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'Invalid pattern JSON file':\n\t\t\t\t\t\tuiMessage = __( 'Invalid pattern JSON file' );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tuiMessage = __( 'Unknown error' );\n\t\t\t\t}\n\n\t\t\t\tsetIsLoading( false );\n\t\t\t\tsetError( uiMessage );\n\t\t\t} );\n\t};\n\n\tconst onDismissError = () => {\n\t\tsetError( null );\n\t};\n\n\treturn (\n\t\t<form\n\t\t\tclassName=\"list-reusable-blocks-import-form\"\n\t\t\tonSubmit={ onSubmit }\n\t\t\tref={ formRef }\n\t\t>\n\t\t\t{ error && (\n\t\t\t\t<Notice status=\"error\" onRemove={ () => onDismissError() }>\n\t\t\t\t\t{ error }\n\t\t\t\t</Notice>\n\t\t\t) }\n\t\t\t<label\n\t\t\t\thtmlFor={ inputId }\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__label\"\n\t\t\t>\n\t\t\t\t{ __( 'File' ) }\n\t\t\t</label>\n\t\t\t<input id={ inputId } type=\"file\" onChange={ onChangeFile } />\n\t\t\t<Button\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\n\t\t\t\taccessibleWhenDisabled\n\t\t\t\tdisabled={ ! file || isLoading }\n\t\t\t\tvariant=\"secondary\"\n\t\t\t\tclassName=\"list-reusable-blocks-import-form__button\"\n\t\t\t>\n\t\t\t\t{ _x( 'Import', 'button label' ) }\n\t\t\t</Button>\n\t\t</form>\n\t);\n}\n\nexport default withInstanceId( ImportForm );\n"],
|
|
5
|
+
"mappings": "AAoEE,SAME,KANF;AAjEF,SAAS,UAAU,cAAc;AACjC,SAAS,sBAAsB;AAC/B,SAAS,IAAI,UAAU;AACvB,SAAS,QAAQ,cAAc;AAK/B,OAAO,yBAAyB;AAEhC,SAAS,WAAY,EAAE,YAAY,SAAS,GAAI;AAC/C,QAAM,UAAU,sCAAsC;AAEtD,QAAM,UAAU,OAAO;AACvB,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AACpD,QAAM,CAAE,OAAO,QAAS,IAAI,SAAU,IAAK;AAC3C,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,IAAK;AAEzC,QAAM,eAAe,CAAE,UAAW;AACjC,YAAS,MAAM,OAAO,MAAO,CAAE,CAAE;AACjC,aAAU,IAAK;AAAA,EAChB;AAEA,QAAM,WAAW,CAAE,UAAW;AAC7B,UAAM,eAAe;AACrB,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,iBAAc,EAAE,WAAW,KAAK,CAAE;AAClC,wBAAqB,IAAK,EACxB,KAAM,CAAE,kBAAmB;AAC3B,UAAK,CAAE,SAAU;AAChB;AAAA,MACD;AAEA,mBAAc,KAAM;AACpB,eAAU,aAAc;AAAA,IACzB,CAAE,EACD,MAAO,CAAE,WAAY;AACrB,UAAK,CAAE,SAAU;AAChB;AAAA,MACD;AAEA,UAAI;AACJ,cAAS,OAAO,SAAU;AAAA,QACzB,KAAK;AACJ,sBAAY,GAAI,mBAAoB;AACpC;AAAA,QACD,KAAK;AACJ,sBAAY,GAAI,2BAA4B;AAC5C;AAAA,QACD;AACC,sBAAY,GAAI,eAAgB;AAAA,MAClC;AAEA,mBAAc,KAAM;AACpB,eAAU,SAAU;AAAA,IACrB,CAAE;AAAA,EACJ;AAEA,QAAM,iBAAiB,MAAM;AAC5B,aAAU,IAAK;AAAA,EAChB;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV;AAAA,MACA,KAAM;AAAA,MAEJ;AAAA,iBACD,oBAAC,UAAO,QAAO,SAAQ,UAAW,MAAM,eAAe,GACpD,iBACH;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA,SAAU;AAAA,YACV,WAAU;AAAA,YAER,aAAI,MAAO;AAAA;AAAA,QACd;AAAA,QACA,oBAAC,WAAM,IAAK,SAAU,MAAK,QAAO,UAAW,cAAe;AAAA,QAC5D;AAAA,UAAC;AAAA;AAAA,YACA,uBAAqB;AAAA,YACrB,MAAK;AAAA,YACL,QAAS;AAAA,YACT,wBAAsB;AAAA,YACtB,UAAW,CAAE,QAAQ;AAAA,YACrB,SAAQ;AAAA,YACR,WAAU;AAAA,YAER,aAAI,UAAU,cAAe;AAAA;AAAA,QAChC;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,sBAAQ,eAAgB,UAAW;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import exportReusableBlock from './utils/export';
|
|
11
|
-
import ImportDropdown from './components/import-dropdown';
|
|
12
|
-
|
|
13
|
-
// Setup Export Links.
|
|
14
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
-
document.body.addEventListener('click', event => {
|
|
16
|
-
if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createRoot, StrictMode } from "@wordpress/element";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import exportReusableBlock from "./utils/export";
|
|
5
|
+
import ImportDropdown from "./components/import-dropdown";
|
|
6
|
+
document.body.addEventListener("click", (event) => {
|
|
7
|
+
if (!event.target.classList.contains("wp-list-reusable-blocks__export")) {
|
|
17
8
|
return;
|
|
18
9
|
}
|
|
19
10
|
event.preventDefault();
|
|
20
11
|
exportReusableBlock(event.target.dataset.id);
|
|
21
12
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
25
|
-
const button = document.querySelector('.page-title-action');
|
|
13
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
14
|
+
const button = document.querySelector(".page-title-action");
|
|
26
15
|
if (!button) {
|
|
27
16
|
return;
|
|
28
17
|
}
|
|
29
18
|
const showNotice = () => {
|
|
30
|
-
const notice = document.createElement(
|
|
31
|
-
notice.className =
|
|
32
|
-
notice.innerHTML = `<p>${__(
|
|
33
|
-
const headerEnd = document.querySelector(
|
|
19
|
+
const notice = document.createElement("div");
|
|
20
|
+
notice.className = "notice notice-success is-dismissible";
|
|
21
|
+
notice.innerHTML = `<p>${__("Pattern imported successfully!")}</p>`;
|
|
22
|
+
const headerEnd = document.querySelector(".wp-header-end");
|
|
34
23
|
if (!headerEnd) {
|
|
35
24
|
return;
|
|
36
25
|
}
|
|
37
26
|
headerEnd.parentNode.insertBefore(notice, headerEnd);
|
|
38
27
|
};
|
|
39
|
-
const container = document.createElement(
|
|
40
|
-
container.className =
|
|
28
|
+
const container = document.createElement("div");
|
|
29
|
+
container.className = "list-reusable-blocks__container";
|
|
41
30
|
button.parentNode.insertBefore(container, button);
|
|
42
|
-
createRoot(container).render(
|
|
43
|
-
children:
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
}));
|
|
31
|
+
createRoot(container).render(
|
|
32
|
+
/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(ImportDropdown, { onUpload: showNotice }) })
|
|
33
|
+
);
|
|
47
34
|
});
|
|
48
|
-
//# sourceMappingURL=index.js.map
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport exportReusableBlock from './utils/export';\nimport ImportDropdown from './components/import-dropdown';\n\n// Setup Export Links.\ndocument.body.addEventListener( 'click', ( event ) => {\n\tif (\n\t\t! event.target.classList.contains( 'wp-list-reusable-blocks__export' )\n\t) {\n\t\treturn;\n\t}\n\tevent.preventDefault();\n\texportReusableBlock( event.target.dataset.id );\n} );\n\n// Setup Import Form.\ndocument.addEventListener( 'DOMContentLoaded', () => {\n\tconst button = document.querySelector( '.page-title-action' );\n\tif ( ! button ) {\n\t\treturn;\n\t}\n\n\tconst showNotice = () => {\n\t\tconst notice = document.createElement( 'div' );\n\t\tnotice.className = 'notice notice-success is-dismissible';\n\t\tnotice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;\n\n\t\tconst headerEnd = document.querySelector( '.wp-header-end' );\n\t\tif ( ! headerEnd ) {\n\t\t\treturn;\n\t\t}\n\t\theaderEnd.parentNode.insertBefore( notice, headerEnd );\n\t};\n\n\tconst container = document.createElement( 'div' );\n\tcontainer.className = 'list-reusable-blocks__container';\n\tbutton.parentNode.insertBefore( container, button );\n\tcreateRoot( container ).render(\n\t\t<StrictMode>\n\t\t\t<ImportDropdown onUpload={ showNotice } />\n\t\t</StrictMode>\n\t);\n} );\n"],
|
|
5
|
+
"mappings": "AA+CG;AA5CH,SAAS,YAAY,kBAAkB;AACvC,SAAS,UAAU;AAKnB,OAAO,yBAAyB;AAChC,OAAO,oBAAoB;AAG3B,SAAS,KAAK,iBAAkB,SAAS,CAAE,UAAW;AACrD,MACC,CAAE,MAAM,OAAO,UAAU,SAAU,iCAAkC,GACpE;AACD;AAAA,EACD;AACA,QAAM,eAAe;AACrB,sBAAqB,MAAM,OAAO,QAAQ,EAAG;AAC9C,CAAE;AAGF,SAAS,iBAAkB,oBAAoB,MAAM;AACpD,QAAM,SAAS,SAAS,cAAe,oBAAqB;AAC5D,MAAK,CAAE,QAAS;AACf;AAAA,EACD;AAEA,QAAM,aAAa,MAAM;AACxB,UAAM,SAAS,SAAS,cAAe,KAAM;AAC7C,WAAO,YAAY;AACnB,WAAO,YAAY,MAAO,GAAI,gCAAiC,CAAE;AAEjE,UAAM,YAAY,SAAS,cAAe,gBAAiB;AAC3D,QAAK,CAAE,WAAY;AAClB;AAAA,IACD;AACA,cAAU,WAAW,aAAc,QAAQ,SAAU;AAAA,EACtD;AAEA,QAAM,YAAY,SAAS,cAAe,KAAM;AAChD,YAAU,YAAY;AACtB,SAAO,WAAW,aAAc,WAAW,MAAO;AAClD,aAAY,SAAU,EAAE;AAAA,IACvB,oBAAC,cACA,8BAAC,kBAAe,UAAW,YAAa,GACzC;AAAA,EACD;AACD,CAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,41 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { paramCase as kebabCase } from 'change-case';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { downloadBlob } from '@wordpress/blob';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Export a reusable block as a JSON file.
|
|
18
|
-
*
|
|
19
|
-
* @param {number} id
|
|
20
|
-
*/
|
|
1
|
+
import { paramCase as kebabCase } from "change-case";
|
|
2
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
3
|
+
import { downloadBlob } from "@wordpress/blob";
|
|
21
4
|
async function exportReusableBlock(id) {
|
|
22
|
-
const postType = await apiFetch({
|
|
23
|
-
path: `/wp/v2/types/wp_block`
|
|
24
|
-
});
|
|
5
|
+
const postType = await apiFetch({ path: `/wp/v2/types/wp_block` });
|
|
25
6
|
const post = await apiFetch({
|
|
26
7
|
path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
|
|
27
8
|
});
|
|
28
9
|
const title = post.title.raw;
|
|
29
10
|
const content = post.content.raw;
|
|
30
11
|
const syncStatus = post.wp_pattern_sync_status;
|
|
31
|
-
const fileContent = JSON.stringify(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
12
|
+
const fileContent = JSON.stringify(
|
|
13
|
+
{
|
|
14
|
+
__file: "wp_block",
|
|
15
|
+
title,
|
|
16
|
+
content,
|
|
17
|
+
syncStatus
|
|
18
|
+
},
|
|
19
|
+
null,
|
|
20
|
+
2
|
|
21
|
+
);
|
|
22
|
+
const fileName = kebabCase(title) + ".json";
|
|
23
|
+
downloadBlob(fileName, fileContent, "application/json");
|
|
39
24
|
}
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
var export_default = exportReusableBlock;
|
|
26
|
+
export {
|
|
27
|
+
export_default as default
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/export.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { downloadBlob } from '@wordpress/blob';\n\n/**\n * Export a reusable block as a JSON file.\n *\n * @param {number} id\n */\nasync function exportReusableBlock( id ) {\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst post = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`,\n\t} );\n\tconst title = post.title.raw;\n\tconst content = post.content.raw;\n\tconst syncStatus = post.wp_pattern_sync_status;\n\tconst fileContent = JSON.stringify(\n\t\t{\n\t\t\t__file: 'wp_block',\n\t\t\ttitle,\n\t\t\tcontent,\n\t\t\tsyncStatus,\n\t\t},\n\t\tnull,\n\t\t2\n\t);\n\tconst fileName = kebabCase( title ) + '.json';\n\n\tdownloadBlob( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,aAAa,iBAAiB;AAKvC,OAAO,cAAc;AAKrB,SAAS,oBAAoB;AAO7B,eAAe,oBAAqB,IAAK;AACxC,QAAM,WAAW,MAAM,SAAU,EAAE,MAAM,wBAAwB,CAAE;AACnE,QAAM,OAAO,MAAM,SAAU;AAAA,IAC5B,MAAM,UAAW,SAAS,SAAU,IAAK,EAAG;AAAA,EAC7C,CAAE;AACF,QAAM,QAAQ,KAAK,MAAM;AACzB,QAAM,UAAU,KAAK,QAAQ;AAC7B,QAAM,aAAa,KAAK;AACxB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACA,QAAM,WAAW,UAAW,KAAM,IAAI;AAEtC,eAAc,UAAU,aAAa,kBAAmB;AACzD;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
* Reads the textual content of the given file.
|
|
3
|
-
*
|
|
4
|
-
* @param {File} file File.
|
|
5
|
-
* @return {Promise<string>} Content of the file.
|
|
6
|
-
*/
|
|
7
|
-
export function readTextFile(file) {
|
|
1
|
+
function readTextFile(file) {
|
|
8
2
|
const reader = new window.FileReader();
|
|
9
|
-
return new Promise(resolve => {
|
|
3
|
+
return new Promise((resolve) => {
|
|
10
4
|
reader.onload = () => {
|
|
11
5
|
resolve(reader.result);
|
|
12
6
|
};
|
|
13
7
|
reader.readAsText(file);
|
|
14
8
|
});
|
|
15
9
|
}
|
|
16
|
-
|
|
10
|
+
export {
|
|
11
|
+
readTextFile
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/file.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],
|
|
5
|
+
"mappings": "AAMO,SAAS,aAAc,MAAO;AACpC,QAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAO,IAAI,QAAS,CAAE,YAAa;AAClC,WAAO,SAAS,MAAM;AACrB,cAAS,OAAO,MAAO;AAAA,IACxB;AACA,WAAO,WAAY,IAAK;AAAA,EACzB,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|