@wordpress/list-reusable-blocks 6.0.0 → 6.2.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.cjs +39 -51
- package/build/components/import-dropdown/index.cjs.map +1 -7
- package/build/components/import-form/index.cjs +96 -109
- package/build/components/import-form/index.cjs.map +1 -7
- package/build/index.cjs +46 -53
- package/build/index.cjs.map +1 -7
- package/build/utils/export.cjs +44 -52
- package/build/utils/export.cjs.map +1 -7
- package/build/utils/file.cjs +20 -35
- package/build/utils/file.cjs.map +1 -7
- package/build/utils/import.cjs +48 -53
- package/build/utils/import.cjs.map +1 -7
- package/build/utils/types.cjs +4 -18
- package/build-module/components/import-dropdown/index.mjs +17 -25
- package/build-module/components/import-dropdown/index.mjs.map +1 -7
- package/build-module/components/import-form/index.mjs +72 -81
- package/build-module/components/import-form/index.mjs.map +1 -7
- package/build-module/index.mjs +24 -35
- package/build-module/index.mjs.map +1 -7
- package/build-module/utils/export.mjs +23 -28
- package/build-module/utils/export.mjs.map +1 -7
- package/build-module/utils/file.mjs +16 -11
- package/build-module/utils/file.mjs.map +1 -7
- package/build-module/utils/import.mjs +29 -30
- package/build-module/utils/import.mjs.map +1 -7
- package/build-module/utils/types.mjs +0 -1
- package/package.json +10 -10
- package/build/utils/types.cjs.map +0 -7
- package/build-module/utils/types.mjs.map +0 -7
|
@@ -1,63 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_components = require("@wordpress/components");
|
|
28
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
29
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
30
|
+
let ___import_form_index_tsx = require("../import-form/index.cjs");
|
|
31
|
+
___import_form_index_tsx = __toESM(___import_form_index_tsx);
|
|
32
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
30
33
|
// packages/list-reusable-blocks/src/components/import-dropdown/index.tsx
|
|
31
|
-
var import_dropdown_exports = {};
|
|
32
|
-
__export(import_dropdown_exports, {
|
|
33
|
-
default: () => import_dropdown_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(import_dropdown_exports);
|
|
36
|
-
var import_components = require("@wordpress/components");
|
|
37
|
-
var import_compose = require("@wordpress/compose");
|
|
38
|
-
var import_i18n = require("@wordpress/i18n");
|
|
39
|
-
var import_import_form = __toESM(require("../import-form/index.cjs"));
|
|
40
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
34
|
function ImportDropdown({ onUpload }) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
children: (0, import_i18n.__)("Import from JSON")
|
|
56
|
-
}
|
|
57
|
-
),
|
|
58
|
-
renderContent: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_import_form.default, { onUpload: (0, import_compose.pipe)(onClose, onUpload) })
|
|
59
|
-
}
|
|
60
|
-
);
|
|
35
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Dropdown, {
|
|
36
|
+
popoverProps: { placement: "bottom-start" },
|
|
37
|
+
contentClassName: "list-reusable-blocks-import-dropdown__content",
|
|
38
|
+
renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
39
|
+
size: "compact",
|
|
40
|
+
className: "list-reusable-blocks-import-dropdown__button",
|
|
41
|
+
"aria-expanded": isOpen,
|
|
42
|
+
onClick: onToggle,
|
|
43
|
+
variant: "primary",
|
|
44
|
+
children: (0, _wordpress_i18n.__)("Import from JSON")
|
|
45
|
+
}),
|
|
46
|
+
renderContent: ({ onClose }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___import_form_index_tsx.default, { onUpload: (0, _wordpress_compose.pipe)(onClose, onUpload) })
|
|
47
|
+
});
|
|
61
48
|
}
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
exports.default = ImportDropdown;
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/import-dropdown/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Dropdown } from '@wordpress/components';\nimport { pipe } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport type { ImportDropdownProps } from '../../utils/types';\nimport ImportForm from '../import-form';\n\nfunction ImportDropdown( { onUpload }: ImportDropdownProps ) {\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;AAAA,wBAAiC;AACjC,qBAAqB;AACrB,kBAAmB;AAEnB,yBAAuB;AAQnB;AANJ,SAAS,eAAgB,EAAE,SAAS,GAAyB;AAC5D,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
|
+
{"version":3,"file":"index.cjs","names":["Dropdown","Button","__","ImportForm","pipe"],"sources":["../../../src/components/import-dropdown/index.tsx"],"sourcesContent":["import { Button, Dropdown } from '@wordpress/components';\nimport { pipe } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\nimport type { ImportDropdownProps } from '../../utils/types';\nimport ImportForm from '../import-form';\n\nfunction ImportDropdown( { onUpload }: ImportDropdownProps ) {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,eAAgB,EAAE,YAAkC;CAC5D,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACA,sBAAAA,UAAD;EACC,cAAe,EAAE,WAAW,eAAe;EAC3C,kBAAiB;EACjB,eAAiB,EAAE,QAAQ,eAC1B,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,QAAD;GACC,MAAK;GACL,WAAU;GACV,iBAAgB;GAChB,SAAU;GACV,SAAQ;GAENC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,kBAAmB;EAClB,CAAA;EAET,gBAAkB,EAAE,cACnB,iBAAA,GAAA,kBAAA,IAAA,CAACC,yBAAAA,SAAD,EAAY,WAAA,GAAWC,mBAAAA,KAAAA,CAAM,SAAS,QAAS,EAAK,CAAA;CAErD,CAAA;AAEH"}
|
|
@@ -1,121 +1,108 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_components = require("@wordpress/components");
|
|
28
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
29
|
+
let _wordpress_element = require("@wordpress/element");
|
|
30
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
31
|
+
let ______utils_import_ts = require("../../utils/import.cjs");
|
|
32
|
+
______utils_import_ts = __toESM(______utils_import_ts);
|
|
33
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
30
34
|
// packages/list-reusable-blocks/src/components/import-form/index.tsx
|
|
31
|
-
var import_form_exports = {};
|
|
32
|
-
__export(import_form_exports, {
|
|
33
|
-
default: () => import_form_default
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(import_form_exports);
|
|
36
|
-
var import_components = require("@wordpress/components");
|
|
37
|
-
var import_compose = require("@wordpress/compose");
|
|
38
|
-
var import_element = require("@wordpress/element");
|
|
39
|
-
var import_i18n = require("@wordpress/i18n");
|
|
40
|
-
var import_import = __toESM(require("../../utils/import.cjs"));
|
|
41
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
35
|
function ImportForm({ instanceId, onUpload }) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
variant: "secondary",
|
|
112
|
-
className: "list-reusable-blocks-import-form__button",
|
|
113
|
-
children: (0, import_i18n._x)("Import", "button label")
|
|
114
|
-
}
|
|
115
|
-
)
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
);
|
|
36
|
+
const inputId = "list-reusable-blocks-import-form-" + instanceId;
|
|
37
|
+
const formRef = (0, _wordpress_element.useRef)(null);
|
|
38
|
+
const [isLoading, setIsLoading] = (0, _wordpress_element.useState)(false);
|
|
39
|
+
const [error, setError] = (0, _wordpress_element.useState)(null);
|
|
40
|
+
const [file, setFile] = (0, _wordpress_element.useState)(null);
|
|
41
|
+
const onChangeFile = (event) => {
|
|
42
|
+
setFile(event.target.files?.[0] || null);
|
|
43
|
+
setError(null);
|
|
44
|
+
};
|
|
45
|
+
const onSubmit = (event) => {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
if (!file) return;
|
|
48
|
+
setIsLoading(true);
|
|
49
|
+
(0, ______utils_import_ts.default)(file).then((reusableBlock) => {
|
|
50
|
+
if (!formRef.current) return;
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
onUpload(reusableBlock);
|
|
53
|
+
}).catch((errors) => {
|
|
54
|
+
if (!formRef.current) return;
|
|
55
|
+
let uiMessage;
|
|
56
|
+
switch (errors.message) {
|
|
57
|
+
case "Invalid JSON file":
|
|
58
|
+
uiMessage = (0, _wordpress_i18n.__)("Invalid JSON file");
|
|
59
|
+
break;
|
|
60
|
+
case "Invalid pattern JSON file":
|
|
61
|
+
uiMessage = (0, _wordpress_i18n.__)("Invalid pattern JSON file");
|
|
62
|
+
break;
|
|
63
|
+
default: uiMessage = (0, _wordpress_i18n.__)("Unknown error");
|
|
64
|
+
}
|
|
65
|
+
setIsLoading(false);
|
|
66
|
+
setError(uiMessage);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const onDismissError = () => {
|
|
70
|
+
setError(null);
|
|
71
|
+
};
|
|
72
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
|
|
73
|
+
className: "list-reusable-blocks-import-form",
|
|
74
|
+
onSubmit,
|
|
75
|
+
ref: formRef,
|
|
76
|
+
children: [
|
|
77
|
+
error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Notice, {
|
|
78
|
+
status: "error",
|
|
79
|
+
onRemove: () => onDismissError(),
|
|
80
|
+
children: error
|
|
81
|
+
}),
|
|
82
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
83
|
+
htmlFor: inputId,
|
|
84
|
+
className: "list-reusable-blocks-import-form__label",
|
|
85
|
+
children: (0, _wordpress_i18n.__)("File")
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
88
|
+
id: inputId,
|
|
89
|
+
type: "file",
|
|
90
|
+
onChange: onChangeFile
|
|
91
|
+
}),
|
|
92
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
|
|
93
|
+
__next40pxDefaultSize: true,
|
|
94
|
+
type: "submit",
|
|
95
|
+
isBusy: isLoading,
|
|
96
|
+
accessibleWhenDisabled: true,
|
|
97
|
+
disabled: !file || isLoading,
|
|
98
|
+
variant: "secondary",
|
|
99
|
+
className: "list-reusable-blocks-import-form__button",
|
|
100
|
+
children: (0, _wordpress_i18n._x)("Import", "button label")
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
});
|
|
119
104
|
}
|
|
120
|
-
var import_form_default = (0,
|
|
121
|
-
|
|
105
|
+
var import_form_default = (0, _wordpress_compose.withInstanceId)(ImportForm);
|
|
106
|
+
exports.default = import_form_default;
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/import-form/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { Button, Notice } from '@wordpress/components';\nimport { withInstanceId } from '@wordpress/compose';\nimport { useRef, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport importReusableBlock from '../../utils/import';\nimport type { ImportFormProps, ReusableBlock } from '../../utils/types';\n\nfunction ImportForm( { instanceId, onUpload }: ImportFormProps ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef< HTMLFormElement >( null );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState< string | null >( null );\n\tconst [ file, setFile ] = useState< File | null >( null );\n\n\tconst onChangeFile = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetFile( event.target.files?.[ 0 ] || null );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event: React.FormEvent< HTMLFormElement > ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( true );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock: ReusableBlock ) => {\n\t\t\t\tif ( ! formRef.current ) {\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: Error ) => {\n\t\t\t\tif ( ! formRef.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage: string;\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;AAAA,wBAA+B;AAC/B,qBAA+B;AAC/B,qBAAiC;AACjC,kBAAuB;AACvB,oBAAgC;AA0D9B;AAvDF,SAAS,WAAY,EAAE,YAAY,SAAS,GAAqB;AAChE,QAAM,UAAU,sCAAsC;AAEtD,QAAM,cAAU,uBAA2B,IAAK;AAChD,QAAM,CAAE,WAAW,YAAa,QAAI,yBAAU,KAAM;AACpD,QAAM,CAAE,OAAO,QAAS,QAAI,yBAA2B,IAAK;AAC5D,QAAM,CAAE,MAAM,OAAQ,QAAI,yBAAyB,IAAK;AAExD,QAAM,eAAe,CAAE,UAAkD;AACxE,YAAS,MAAM,OAAO,QAAS,CAAE,KAAK,IAAK;AAC3C,aAAU,IAAK;AAAA,EAChB;AAEA,QAAM,WAAW,CAAE,UAA+C;AACjE,UAAM,eAAe;AACrB,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,iBAAc,IAAK;AACnB,sBAAAA,SAAqB,IAAK,EACxB,KAAM,CAAE,kBAAkC;AAC1C,UAAK,CAAE,QAAQ,SAAU;AACxB;AAAA,MACD;AAEA,mBAAc,KAAM;AACpB,eAAU,aAAc;AAAA,IACzB,CAAE,EACD,MAAO,CAAE,WAAmB;AAC5B,UAAK,CAAE,QAAQ,SAAU;AACxB;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
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useRef","useState","__","WCNotice","Button","_x","withInstanceId"],"sources":["../../../src/components/import-form/index.tsx"],"sourcesContent":["import { Button, Notice as WCNotice } from '@wordpress/components';\nimport { withInstanceId } from '@wordpress/compose';\nimport { useRef, useState } from '@wordpress/element';\nimport { __, _x } from '@wordpress/i18n';\nimport importReusableBlock from '../../utils/import';\nimport type { ImportFormProps, ReusableBlock } from '../../utils/types';\n\nfunction ImportForm( { instanceId, onUpload }: ImportFormProps ) {\n\tconst inputId = 'list-reusable-blocks-import-form-' + instanceId;\n\n\tconst formRef = useRef< HTMLFormElement >( null );\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ error, setError ] = useState< string | null >( null );\n\tconst [ file, setFile ] = useState< File | null >( null );\n\n\tconst onChangeFile = ( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\tsetFile( event.target.files?.[ 0 ] || null );\n\t\tsetError( null );\n\t};\n\n\tconst onSubmit = ( event: React.FormEvent< HTMLFormElement > ) => {\n\t\tevent.preventDefault();\n\t\tif ( ! file ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsLoading( true );\n\t\timportReusableBlock( file )\n\t\t\t.then( ( reusableBlock: ReusableBlock ) => {\n\t\t\t\tif ( ! formRef.current ) {\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: Error ) => {\n\t\t\t\tif ( ! formRef.current ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet uiMessage: string;\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<WCNotice status=\"error\" onRemove={ () => onDismissError() }>\n\t\t\t\t\t{ error }\n\t\t\t\t</WCNotice>\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,WAAY,EAAE,YAAY,YAA8B;CAChE,MAAM,UAAU,sCAAsC;CAEtD,MAAM,WAAA,GAAUA,mBAAAA,OAAAA,CAA2B,IAAK;CAChD,MAAM,CAAE,WAAW,iBAAA,GAAiBC,mBAAAA,SAAAA,CAAU,KAAM;CACpD,MAAM,CAAE,OAAO,aAAA,GAAaA,mBAAAA,SAAAA,CAA2B,IAAK;CAC5D,MAAM,CAAE,MAAM,YAAA,GAAYA,mBAAAA,SAAAA,CAAyB,IAAK;CAExD,MAAM,gBAAiB,UAAkD;EACxE,QAAS,MAAM,OAAO,QAAS,MAAO,IAAK;EAC3C,SAAU,IAAK;CAChB;CAEA,MAAM,YAAa,UAA+C;EACjE,MAAM,eAAe;EACrB,IAAK,CAAE,MACN;EAED,aAAc,IAAK;EACnB,CAAA,GAAA,sBAAA,QAAA,CAAqB,IAAK,CAAC,CACzB,MAAQ,kBAAkC;GAC1C,IAAK,CAAE,QAAQ,SACd;GAGD,aAAc,KAAM;GACpB,SAAU,aAAc;EACzB,CAAE,CAAC,CACF,OAAS,WAAmB;GAC5B,IAAK,CAAE,QAAQ,SACd;GAGD,IAAI;GACJ,QAAS,OAAO,SAAhB;IACC,KAAK;KACJ,aAAA,GAAYC,gBAAAA,GAAAA,CAAI,mBAAoB;KACpC;IACD,KAAK;KACJ,aAAA,GAAYA,gBAAAA,GAAAA,CAAI,2BAA4B;KAC5C;IACD,SACC,aAAA,GAAYA,gBAAAA,GAAAA,CAAI,eAAgB;GAClC;GAEA,aAAc,KAAM;GACpB,SAAU,SAAU;EACrB,CAAE;CACJ;CAEA,MAAM,uBAAuB;EAC5B,SAAU,IAAK;CAChB;CAEA,OACC,iBAAA,GAAA,kBAAA,KAAA,CAAC,QAAD;EACC,WAAU;EACC;EACX,KAAM;EAHP,UAAA;GAKG,SACD,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,QAAD;IAAU,QAAO;IAAQ,gBAAiB,eAAe;IACtD,UAAA;GACO,CAAA;GAEX,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;IACC,SAAU;IACV,WAAU;IAERD,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,MAAO;GACP,CAAA;GACP,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;IAAO,IAAK;IAAU,MAAK;IAAO,UAAW;GAAgB,CAAA;GAC7D,iBAAA,GAAA,kBAAA,IAAA,CAACE,sBAAAA,QAAD;IACC,uBAAA;IACA,MAAK;IACL,QAAS;IACT,wBAAA;IACA,UAAW,CAAE,QAAQ;IACrB,SAAQ;IACR,WAAU;IAERC,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,UAAU,cAAe;GACxB,CAAA;EACH;;AAER;AAEA,IAAA,uBAAA,GAAeC,mBAAAA,eAAAA,CAAgB,UAAW"}
|
package/build/index.cjs
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -6,62 +11,50 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
13
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
15
22
|
};
|
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_element = require("@wordpress/element");
|
|
28
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
29
|
+
let __components_import_dropdown_index_tsx = require("./components/import-dropdown/index.cjs");
|
|
30
|
+
__components_import_dropdown_index_tsx = __toESM(__components_import_dropdown_index_tsx);
|
|
31
|
+
let __utils_export_ts = require("./utils/export.cjs");
|
|
32
|
+
__utils_export_ts = __toESM(__utils_export_ts);
|
|
33
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
25
34
|
// packages/list-reusable-blocks/src/index.tsx
|
|
26
|
-
var import_element = require("@wordpress/element");
|
|
27
|
-
var import_i18n = require("@wordpress/i18n");
|
|
28
|
-
var import_import_dropdown = __toESM(require("./components/import-dropdown/index.cjs"));
|
|
29
|
-
var import_export = __toESM(require("./utils/export.cjs"));
|
|
30
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
35
|
document.body.addEventListener("click", (event) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const blockId = target.dataset.id;
|
|
38
|
-
if (blockId) {
|
|
39
|
-
(0, import_export.default)(Number(blockId));
|
|
40
|
-
}
|
|
36
|
+
const target = event.target;
|
|
37
|
+
if (!target.classList.contains("wp-list-reusable-blocks__export")) return;
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
const blockId = target.dataset.id;
|
|
40
|
+
if (blockId) (0, __utils_export_ts.default)(Number(blockId));
|
|
41
41
|
});
|
|
42
42
|
document.addEventListener("DOMContentLoaded", () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
container.className = "list-reusable-blocks__container";
|
|
59
|
-
if (!button.parentNode) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
button.parentNode.insertBefore(container, button);
|
|
63
|
-
(0, import_element.createRoot)(container).render(
|
|
64
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_element.StrictMode, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_import_dropdown.default, { onUpload: showNotice }) })
|
|
65
|
-
);
|
|
43
|
+
const button = document.querySelector(".page-title-action");
|
|
44
|
+
if (!button) return;
|
|
45
|
+
const showNotice = () => {
|
|
46
|
+
const notice = document.createElement("div");
|
|
47
|
+
notice.className = "notice notice-success is-dismissible";
|
|
48
|
+
notice.innerHTML = `<p>${(0, _wordpress_i18n.__)("Pattern imported successfully!")}</p>`;
|
|
49
|
+
const headerEnd = document.querySelector(".wp-header-end");
|
|
50
|
+
if (!headerEnd || !headerEnd.parentNode) return;
|
|
51
|
+
headerEnd.parentNode.insertBefore(notice, headerEnd);
|
|
52
|
+
};
|
|
53
|
+
const container = document.createElement("div");
|
|
54
|
+
container.className = "list-reusable-blocks__container";
|
|
55
|
+
if (!button.parentNode) return;
|
|
56
|
+
button.parentNode.insertBefore(container, button);
|
|
57
|
+
(0, _wordpress_element.createRoot)(container).render(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_element.StrictMode, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__components_import_dropdown_index_tsx.default, { onUpload: showNotice }) }));
|
|
66
58
|
});
|
|
67
|
-
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import { createRoot, StrictMode } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ImportDropdown from './components/import-dropdown';\nimport exportReusableBlock from './utils/export';\n\n// Setup Export Links.\ndocument.body.addEventListener( 'click', ( event: MouseEvent ) => {\n\tconst target = event.target as HTMLElement;\n\n\tif ( ! target.classList.contains( 'wp-list-reusable-blocks__export' ) ) {\n\t\treturn;\n\t}\n\n\tevent.preventDefault();\n\n\tconst blockId = target.dataset.id;\n\tif ( blockId ) {\n\t\texportReusableBlock( Number( blockId ) );\n\t}\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 || ! headerEnd.parentNode ) {\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\n\tif ( ! button.parentNode ) {\n\t\treturn;\n\t}\n\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": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qBAAuC;AACvC,kBAAmB;AACnB,6BAA2B;AAC3B,oBAAgC;AA+C7B;AA5CH,SAAS,KAAK,iBAAkB,SAAS,CAAE,UAAuB;AACjE,QAAM,SAAS,MAAM;AAErB,MAAK,CAAE,OAAO,UAAU,SAAU,iCAAkC,GAAI;AACvE;AAAA,EACD;AAEA,QAAM,eAAe;AAErB,QAAM,UAAU,OAAO,QAAQ;AAC/B,MAAK,SAAU;AACd,sBAAAA,SAAqB,OAAQ,OAAQ,CAAE;AAAA,EACxC;AACD,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,aAAa,CAAE,UAAU,YAAa;AAC5C;AAAA,IACD;AACA,cAAU,WAAW,aAAc,QAAQ,SAAU;AAAA,EACtD;AAEA,QAAM,YAAY,SAAS,cAAe,KAAM;AAChD,YAAU,YAAY;AAEtB,MAAK,CAAE,OAAO,YAAa;AAC1B;AAAA,EACD;AAEA,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
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["__","StrictMode","ImportDropdown"],"sources":["../src/index.tsx"],"sourcesContent":["import { createRoot, StrictMode } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport ImportDropdown from './components/import-dropdown';\nimport exportReusableBlock from './utils/export';\n\n// Setup Export Links.\ndocument.body.addEventListener( 'click', ( event: MouseEvent ) => {\n\tconst target = event.target as HTMLElement;\n\n\tif ( ! target.classList.contains( 'wp-list-reusable-blocks__export' ) ) {\n\t\treturn;\n\t}\n\n\tevent.preventDefault();\n\n\tconst blockId = target.dataset.id;\n\tif ( blockId ) {\n\t\texportReusableBlock( Number( blockId ) );\n\t}\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 || ! headerEnd.parentNode ) {\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\n\tif ( ! button.parentNode ) {\n\t\treturn;\n\t}\n\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAS,KAAK,iBAAkB,UAAW,UAAuB;CACjE,MAAM,SAAS,MAAM;CAErB,IAAK,CAAE,OAAO,UAAU,SAAU,iCAAkC,GACnE;CAGD,MAAM,eAAe;CAErB,MAAM,UAAU,OAAO,QAAQ;CAC/B,IAAK,SACJ,CAAA,GAAA,kBAAA,QAAA,CAAqB,OAAQ,OAAQ,CAAE;AAEzC,CAAE;AAGF,SAAS,iBAAkB,0BAA0B;CACpD,MAAM,SAAS,SAAS,cAAe,oBAAqB;CAC5D,IAAK,CAAE,QACN;CAGD,MAAM,mBAAmB;EACxB,MAAM,SAAS,SAAS,cAAe,KAAM;EAC7C,OAAO,YAAY;EACnB,OAAO,YAAY,OAAA,GAAOA,gBAAAA,GAAAA,CAAI,gCAAiC,EAAG;EAElE,MAAM,YAAY,SAAS,cAAe,gBAAiB;EAC3D,IAAK,CAAE,aAAa,CAAE,UAAU,YAC/B;EAED,UAAU,WAAW,aAAc,QAAQ,SAAU;CACtD;CAEA,MAAM,YAAY,SAAS,cAAe,KAAM;CAChD,UAAU,YAAY;CAEtB,IAAK,CAAE,OAAO,YACb;CAGD,OAAO,WAAW,aAAc,WAAW,MAAO;CAClD,CAAA,GAAA,mBAAA,WAAA,CAAY,SAAU,CAAC,CAAC,OACvB,iBAAA,GAAA,kBAAA,IAAA,CAACC,mBAAAA,YAAD,EAAA,UACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,uCAAAA,SAAD,EAAgB,UAAW,WAAc,CAAA,EAC9B,CAAA,CACb;AACD,CAAE"}
|
package/build/utils/export.cjs
CHANGED
|
@@ -1,64 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let change_case = require("change-case");
|
|
28
|
+
let remove_accents = require("remove-accents");
|
|
29
|
+
remove_accents = __toESM(remove_accents);
|
|
30
|
+
let _wordpress_api_fetch = require("@wordpress/api-fetch");
|
|
31
|
+
_wordpress_api_fetch = __toESM(_wordpress_api_fetch);
|
|
32
|
+
let _wordpress_blob = require("@wordpress/blob");
|
|
30
33
|
// packages/list-reusable-blocks/src/utils/export.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var import_change_case = require("change-case");
|
|
37
|
-
var import_remove_accents = __toESM(require("remove-accents"));
|
|
38
|
-
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
39
|
-
var import_blob = require("@wordpress/blob");
|
|
34
|
+
/**
|
|
35
|
+
* Export a reusable block as a JSON file.
|
|
36
|
+
*
|
|
37
|
+
* @param id - The ID of the reusable block to export
|
|
38
|
+
*/
|
|
40
39
|
async function exportReusableBlock(id) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
content,
|
|
55
|
-
syncStatus
|
|
56
|
-
},
|
|
57
|
-
null,
|
|
58
|
-
2
|
|
59
|
-
);
|
|
60
|
-
const fileName = (0, import_change_case.paramCase)((0, import_remove_accents.default)(title)) + ".json";
|
|
61
|
-
(0, import_blob.downloadBlob)(fileName, fileContent, "application/json");
|
|
40
|
+
const postType = await (0, _wordpress_api_fetch.default)({ path: `/wp/v2/types/wp_block` });
|
|
41
|
+
const post = await (0, _wordpress_api_fetch.default)({ path: `/wp/v2/${postType.rest_base}/${id}?context=edit` });
|
|
42
|
+
const title = post.title.raw;
|
|
43
|
+
const content = post.content.raw;
|
|
44
|
+
const syncStatus = post.wp_pattern_sync_status;
|
|
45
|
+
const fileContent = JSON.stringify({
|
|
46
|
+
__file: "wp_block",
|
|
47
|
+
title,
|
|
48
|
+
content,
|
|
49
|
+
syncStatus
|
|
50
|
+
}, null, 2);
|
|
51
|
+
const fileName = (0, change_case.paramCase)((0, remove_accents.default)(title)) + ".json";
|
|
52
|
+
(0, _wordpress_blob.downloadBlob)(fileName, fileContent, "application/json");
|
|
62
53
|
}
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
exports.default = exportReusableBlock;
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=export.cjs.map
|