@wordpress/list-reusable-blocks 5.31.1-next.f56bd8138.0 → 5.32.1-next.47f435fc9.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/CHANGELOG.md +2 -0
- 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/CHANGELOG.md
CHANGED
|
@@ -1,48 +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_dropdown_exports = {};
|
|
29
|
+
__export(import_dropdown_exports, {
|
|
30
|
+
default: () => import_dropdown_default
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
size: "compact",
|
|
34
|
-
className: "list-reusable-blocks-import-dropdown__button",
|
|
35
|
-
"aria-expanded": isOpen,
|
|
36
|
-
onClick: onToggle,
|
|
37
|
-
variant: "primary",
|
|
38
|
-
children: (0, _i18n.__)('Import from JSON')
|
|
39
|
-
}),
|
|
40
|
-
renderContent: ({
|
|
41
|
-
onClose
|
|
42
|
-
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_importForm.default, {
|
|
43
|
-
onUpload: (0, _compose.pipe)(onClose, onUpload)
|
|
44
|
-
})
|
|
45
|
-
});
|
|
32
|
+
module.exports = __toCommonJS(import_dropdown_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_compose = require("@wordpress/compose");
|
|
35
|
+
var import_i18n = require("@wordpress/i18n");
|
|
36
|
+
var import_components = require("@wordpress/components");
|
|
37
|
+
var import_import_form = __toESM(require("../import-form"));
|
|
38
|
+
function ImportDropdown({ onUpload }) {
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
40
|
+
import_components.Dropdown,
|
|
41
|
+
{
|
|
42
|
+
popoverProps: { placement: "bottom-start" },
|
|
43
|
+
contentClassName: "list-reusable-blocks-import-dropdown__content",
|
|
44
|
+
renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
45
|
+
import_components.Button,
|
|
46
|
+
{
|
|
47
|
+
size: "compact",
|
|
48
|
+
className: "list-reusable-blocks-import-dropdown__button",
|
|
49
|
+
"aria-expanded": isOpen,
|
|
50
|
+
onClick: onToggle,
|
|
51
|
+
variant: "primary",
|
|
52
|
+
children: (0, import_i18n.__)("Import from JSON")
|
|
53
|
+
}
|
|
54
|
+
),
|
|
55
|
+
renderContent: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_import_form.default, { onUpload: (0, import_compose.pipe)(onClose, onUpload) })
|
|
56
|
+
}
|
|
57
|
+
);
|
|
46
58
|
}
|
|
47
|
-
var
|
|
48
|
-
//# sourceMappingURL=index.js.map
|
|
59
|
+
var import_dropdown_default = ImportDropdown;
|
|
60
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBI;AAfJ,qBAAqB;AACrB,kBAAmB;AACnB,wBAAiC;AAKjC,yBAAuB;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,8BAAI,kBAAmB;AAAA;AAAA,MAC1B;AAAA,MAED,eAAgB,CAAE,EAAE,QAAQ,MAC3B,4CAAC,mBAAAA,SAAA,EAAW,cAAW,qBAAM,SAAS,QAAS,GAAI;AAAA;AAAA,EAErD;AAEF;AAEA,IAAO,0BAAQ;",
|
|
6
|
+
"names": ["ImportForm"]
|
|
7
|
+
}
|
|
@@ -1,65 +1,77 @@
|
|
|
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_form_exports = {};
|
|
29
|
+
__export(import_form_exports, {
|
|
30
|
+
default: () => import_form_default
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function ImportForm({
|
|
23
|
-
instanceId,
|
|
24
|
-
onUpload
|
|
25
|
-
}) {
|
|
26
|
-
const inputId = 'list-reusable-blocks-import-form-' + instanceId;
|
|
27
|
-
const formRef = (0, _element.useRef)();
|
|
28
|
-
const [isLoading, setIsLoading] = (0, _element.useState)(false);
|
|
29
|
-
const [error, setError] = (0, _element.useState)(null);
|
|
30
|
-
const [file, setFile] = (0, _element.useState)(null);
|
|
31
|
-
const onChangeFile = event => {
|
|
32
|
+
module.exports = __toCommonJS(import_form_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_element = require("@wordpress/element");
|
|
35
|
+
var import_compose = require("@wordpress/compose");
|
|
36
|
+
var import_i18n = require("@wordpress/i18n");
|
|
37
|
+
var import_components = require("@wordpress/components");
|
|
38
|
+
var import_import = __toESM(require("../../utils/import"));
|
|
39
|
+
function ImportForm({ instanceId, onUpload }) {
|
|
40
|
+
const inputId = "list-reusable-blocks-import-form-" + instanceId;
|
|
41
|
+
const formRef = (0, import_element.useRef)();
|
|
42
|
+
const [isLoading, setIsLoading] = (0, import_element.useState)(false);
|
|
43
|
+
const [error, setError] = (0, import_element.useState)(null);
|
|
44
|
+
const [file, setFile] = (0, import_element.useState)(null);
|
|
45
|
+
const onChangeFile = (event) => {
|
|
32
46
|
setFile(event.target.files[0]);
|
|
33
47
|
setError(null);
|
|
34
48
|
};
|
|
35
|
-
const onSubmit = event => {
|
|
49
|
+
const onSubmit = (event) => {
|
|
36
50
|
event.preventDefault();
|
|
37
51
|
if (!file) {
|
|
38
52
|
return;
|
|
39
53
|
}
|
|
40
|
-
setIsLoading({
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
(0, _import.default)(file).then(reusableBlock => {
|
|
54
|
+
setIsLoading({ isLoading: true });
|
|
55
|
+
(0, import_import.default)(file).then((reusableBlock) => {
|
|
44
56
|
if (!formRef) {
|
|
45
57
|
return;
|
|
46
58
|
}
|
|
47
59
|
setIsLoading(false);
|
|
48
60
|
onUpload(reusableBlock);
|
|
49
|
-
}).catch(errors => {
|
|
61
|
+
}).catch((errors) => {
|
|
50
62
|
if (!formRef) {
|
|
51
63
|
return;
|
|
52
64
|
}
|
|
53
65
|
let uiMessage;
|
|
54
66
|
switch (errors.message) {
|
|
55
|
-
case
|
|
56
|
-
uiMessage = (0,
|
|
67
|
+
case "Invalid JSON file":
|
|
68
|
+
uiMessage = (0, import_i18n.__)("Invalid JSON file");
|
|
57
69
|
break;
|
|
58
|
-
case
|
|
59
|
-
uiMessage = (0,
|
|
70
|
+
case "Invalid pattern JSON file":
|
|
71
|
+
uiMessage = (0, import_i18n.__)("Invalid pattern JSON file");
|
|
60
72
|
break;
|
|
61
73
|
default:
|
|
62
|
-
uiMessage = (0,
|
|
74
|
+
uiMessage = (0, import_i18n.__)("Unknown error");
|
|
63
75
|
}
|
|
64
76
|
setIsLoading(false);
|
|
65
77
|
setError(uiMessage);
|
|
@@ -68,33 +80,39 @@ function ImportForm({
|
|
|
68
80
|
const onDismissError = () => {
|
|
69
81
|
setError(null);
|
|
70
82
|
};
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
84
|
+
"form",
|
|
85
|
+
{
|
|
86
|
+
className: "list-reusable-blocks-import-form",
|
|
87
|
+
onSubmit,
|
|
88
|
+
ref: formRef,
|
|
89
|
+
children: [
|
|
90
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Notice, { status: "error", onRemove: () => onDismissError(), children: error }),
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
92
|
+
"label",
|
|
93
|
+
{
|
|
94
|
+
htmlFor: inputId,
|
|
95
|
+
className: "list-reusable-blocks-import-form__label",
|
|
96
|
+
children: (0, import_i18n.__)("File")
|
|
97
|
+
}
|
|
98
|
+
),
|
|
99
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: inputId, type: "file", onChange: onChangeFile }),
|
|
100
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
101
|
+
import_components.Button,
|
|
102
|
+
{
|
|
103
|
+
__next40pxDefaultSize: true,
|
|
104
|
+
type: "submit",
|
|
105
|
+
isBusy: isLoading,
|
|
106
|
+
accessibleWhenDisabled: true,
|
|
107
|
+
disabled: !file || isLoading,
|
|
108
|
+
variant: "secondary",
|
|
109
|
+
className: "list-reusable-blocks-import-form__button",
|
|
110
|
+
children: (0, import_i18n._x)("Import", "button label")
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
);
|
|
98
116
|
}
|
|
99
|
-
var
|
|
100
|
-
//# sourceMappingURL=index.js.map
|
|
117
|
+
var import_form_default = (0, import_compose.withInstanceId)(ImportForm);
|
|
118
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoEE;AAjEF,qBAAiC;AACjC,qBAA+B;AAC/B,kBAAuB;AACvB,wBAA+B;AAK/B,oBAAgC;AAEhC,SAAS,WAAY,EAAE,YAAY,SAAS,GAAI;AAC/C,QAAM,UAAU,sCAAsC;AAEtD,QAAM,cAAU,uBAAO;AACvB,QAAM,CAAE,WAAW,YAAa,QAAI,yBAAU,KAAM;AACpD,QAAM,CAAE,OAAO,QAAS,QAAI,yBAAU,IAAK;AAC3C,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAU,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,sBAAAA,SAAqB,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,0BAAY,gBAAI,mBAAoB;AACpC;AAAA,QACD,KAAK;AACJ,0BAAY,gBAAI,2BAA4B;AAC5C;AAAA,QACD;AACC,0BAAY,gBAAI,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,4CAAC,4BAAO,QAAO,SAAQ,UAAW,MAAM,eAAe,GACpD,iBACH;AAAA,QAED;AAAA,UAAC;AAAA;AAAA,YACA,SAAU;AAAA,YACV,WAAU;AAAA,YAER,8BAAI,MAAO;AAAA;AAAA,QACd;AAAA,QACA,4CAAC,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,8BAAI,UAAU,cAAe;AAAA;AAAA,QAChC;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,0BAAQ,+BAAgB,UAAW;",
|
|
6
|
+
"names": ["importReusableBlock"]
|
|
7
|
+
}
|
package/build/index.js
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_element = require("@wordpress/element");
|
|
25
|
+
var import_i18n = require("@wordpress/i18n");
|
|
26
|
+
var import_export = __toESM(require("./utils/export"));
|
|
27
|
+
var import_import_dropdown = __toESM(require("./components/import-dropdown"));
|
|
28
|
+
document.body.addEventListener("click", (event) => {
|
|
29
|
+
if (!event.target.classList.contains("wp-list-reusable-blocks__export")) {
|
|
20
30
|
return;
|
|
21
31
|
}
|
|
22
32
|
event.preventDefault();
|
|
23
|
-
(0,
|
|
33
|
+
(0, import_export.default)(event.target.dataset.id);
|
|
24
34
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
28
|
-
const button = document.querySelector('.page-title-action');
|
|
35
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
36
|
+
const button = document.querySelector(".page-title-action");
|
|
29
37
|
if (!button) {
|
|
30
38
|
return;
|
|
31
39
|
}
|
|
32
40
|
const showNotice = () => {
|
|
33
|
-
const notice = document.createElement(
|
|
34
|
-
notice.className =
|
|
35
|
-
notice.innerHTML = `<p>${(0,
|
|
36
|
-
const headerEnd = document.querySelector(
|
|
41
|
+
const notice = document.createElement("div");
|
|
42
|
+
notice.className = "notice notice-success is-dismissible";
|
|
43
|
+
notice.innerHTML = `<p>${(0, import_i18n.__)("Pattern imported successfully!")}</p>`;
|
|
44
|
+
const headerEnd = document.querySelector(".wp-header-end");
|
|
37
45
|
if (!headerEnd) {
|
|
38
46
|
return;
|
|
39
47
|
}
|
|
40
48
|
headerEnd.parentNode.insertBefore(notice, headerEnd);
|
|
41
49
|
};
|
|
42
|
-
const container = document.createElement(
|
|
43
|
-
container.className =
|
|
50
|
+
const container = document.createElement("div");
|
|
51
|
+
container.className = "list-reusable-blocks__container";
|
|
44
52
|
button.parentNode.insertBefore(container, button);
|
|
45
|
-
(0,
|
|
46
|
-
children:
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
}));
|
|
53
|
+
(0, import_element.createRoot)(container).render(
|
|
54
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_import_dropdown.default, { onUpload: showNotice }) })
|
|
55
|
+
);
|
|
50
56
|
});
|
|
51
|
-
//# sourceMappingURL=index.js.map
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -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,qBAAuC;AACvC,kBAAmB;AAKnB,oBAAgC;AAChC,6BAA2B;AAG3B,SAAS,KAAK,iBAAkB,SAAS,CAAE,UAAW;AACrD,MACC,CAAE,MAAM,OAAO,UAAU,SAAU,iCAAkC,GACpE;AACD;AAAA,EACD;AACA,QAAM,eAAe;AACrB,oBAAAA,SAAqB,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,UAAO,gBAAI,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,iCAAY,SAAU,EAAE;AAAA,IACvB,4CAAC,6BACA,sDAAC,uBAAAC,SAAA,EAAe,UAAW,YAAa,GACzC;AAAA,EACD;AACD,CAAE;",
|
|
6
|
+
"names": ["exportReusableBlock", "ImportDropdown"]
|
|
7
|
+
}
|
package/build/utils/export.js
CHANGED
|
@@ -1,48 +1,58 @@
|
|
|
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 export_exports = {};
|
|
29
|
+
__export(export_exports, {
|
|
30
|
+
default: () => export_default
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
/**
|
|
12
|
-
* External dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* WordPress dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Export a reusable block as a JSON file.
|
|
25
|
-
*
|
|
26
|
-
* @param {number} id
|
|
27
|
-
*/
|
|
32
|
+
module.exports = __toCommonJS(export_exports);
|
|
33
|
+
var import_change_case = require("change-case");
|
|
34
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
35
|
+
var import_blob = require("@wordpress/blob");
|
|
28
36
|
async function exportReusableBlock(id) {
|
|
29
|
-
const postType = await (0,
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
const post = await (0, _apiFetch.default)({
|
|
37
|
+
const postType = await (0, import_api_fetch.default)({ path: `/wp/v2/types/wp_block` });
|
|
38
|
+
const post = await (0, import_api_fetch.default)({
|
|
33
39
|
path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
|
|
34
40
|
});
|
|
35
41
|
const title = post.title.raw;
|
|
36
42
|
const content = post.content.raw;
|
|
37
43
|
const syncStatus = post.wp_pattern_sync_status;
|
|
38
|
-
const fileContent = JSON.stringify(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const fileContent = JSON.stringify(
|
|
45
|
+
{
|
|
46
|
+
__file: "wp_block",
|
|
47
|
+
title,
|
|
48
|
+
content,
|
|
49
|
+
syncStatus
|
|
50
|
+
},
|
|
51
|
+
null,
|
|
52
|
+
2
|
|
53
|
+
);
|
|
54
|
+
const fileName = (0, import_change_case.paramCase)(title) + ".json";
|
|
55
|
+
(0, import_blob.downloadBlob)(fileName, fileContent, "application/json");
|
|
46
56
|
}
|
|
47
|
-
var
|
|
48
|
-
//# sourceMappingURL=export.js.map
|
|
57
|
+
var export_default = exportReusableBlock;
|
|
58
|
+
//# 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAKvC,uBAAqB;AAKrB,kBAA6B;AAO7B,eAAe,oBAAqB,IAAK;AACxC,QAAM,WAAW,UAAM,iBAAAA,SAAU,EAAE,MAAM,wBAAwB,CAAE;AACnE,QAAM,OAAO,UAAM,iBAAAA,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,eAAW,mBAAAC,WAAW,KAAM,IAAI;AAEtC,gCAAc,UAAU,aAAa,kBAAmB;AACzD;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": ["apiFetch", "kebabCase"]
|
|
7
|
+
}
|