@wordpress/list-reusable-blocks 5.32.0 → 5.32.1-next.b8c8708f3.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.
@@ -1,48 +1,60 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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.default = void 0;
8
- var _compose = require("@wordpress/compose");
9
- var _i18n = require("@wordpress/i18n");
10
- var _components = require("@wordpress/components");
11
- var _importForm = _interopRequireDefault(require("../import-form"));
12
- var _jsxRuntime = require("react/jsx-runtime");
13
- /**
14
- * WordPress dependencies
15
- */
16
-
17
- /**
18
- * Internal dependencies
19
- */
20
-
21
- function ImportDropdown({
22
- onUpload
23
- }) {
24
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Dropdown, {
25
- popoverProps: {
26
- placement: 'bottom-start'
27
- },
28
- contentClassName: "list-reusable-blocks-import-dropdown__content",
29
- renderToggle: ({
30
- isOpen,
31
- onToggle
32
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
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 _default = exports.default = ImportDropdown;
48
- //# sourceMappingURL=index.js.map
59
+ var import_dropdown_default = ImportDropdown;
60
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_compose","require","_i18n","_components","_importForm","_interopRequireDefault","_jsxRuntime","ImportDropdown","onUpload","jsx","Dropdown","popoverProps","placement","contentClassName","renderToggle","isOpen","onToggle","Button","size","className","onClick","variant","children","__","renderContent","onClose","default","pipe","_default","exports"],"sources":["@wordpress/list-reusable-blocks/src/components/import-dropdown/index.js"],"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"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAAwC,IAAAK,WAAA,GAAAL,OAAA;AAVxC;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASM,cAAcA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACvC,oBACC,IAAAF,WAAA,CAAAG,GAAA,EAACN,WAAA,CAAAO,QAAQ;IACRC,YAAY,EAAG;MAAEC,SAAS,EAAE;IAAe,CAAG;IAC9CC,gBAAgB,EAAC,+CAA+C;IAChEC,YAAY,EAAGA,CAAE;MAAEC,MAAM;MAAEC;IAAS,CAAC,kBACpC,IAAAV,WAAA,CAAAG,GAAA,EAACN,WAAA,CAAAc,MAAM;MACNC,IAAI,EAAC,SAAS;MACdC,SAAS,EAAC,8CAA8C;MACxD,iBAAgBJ,MAAQ;MACxBK,OAAO,EAAGJ,QAAU;MACpBK,OAAO,EAAC,SAAS;MAAAC,QAAA,EAEf,IAAAC,QAAE,EAAE,kBAAmB;IAAC,CACnB,CACN;IACHC,aAAa,EAAGA,CAAE;MAAEC;IAAQ,CAAC,kBAC5B,IAAAnB,WAAA,CAAAG,GAAA,EAACL,WAAA,CAAAsB,OAAU;MAAClB,QAAQ,EAAG,IAAAmB,aAAI,EAAEF,OAAO,EAAEjB,QAAS;IAAG,CAAE;EAClD,CACH,CAAC;AAEJ;AAAC,IAAAoB,QAAA,GAAAC,OAAA,CAAAH,OAAA,GAEcnB,cAAc","ignoreList":[]}
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
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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.default = void 0;
8
- var _element = require("@wordpress/element");
9
- var _compose = require("@wordpress/compose");
10
- var _i18n = require("@wordpress/i18n");
11
- var _components = require("@wordpress/components");
12
- var _import = _interopRequireDefault(require("../../utils/import"));
13
- var _jsxRuntime = require("react/jsx-runtime");
14
- /**
15
- * WordPress dependencies
16
- */
17
-
18
- /**
19
- * Internal dependencies
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
- isLoading: true
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 'Invalid JSON file':
56
- uiMessage = (0, _i18n.__)('Invalid JSON file');
67
+ case "Invalid JSON file":
68
+ uiMessage = (0, import_i18n.__)("Invalid JSON file");
57
69
  break;
58
- case 'Invalid pattern JSON file':
59
- uiMessage = (0, _i18n.__)('Invalid pattern JSON file');
70
+ case "Invalid pattern JSON file":
71
+ uiMessage = (0, import_i18n.__)("Invalid pattern JSON file");
60
72
  break;
61
73
  default:
62
- uiMessage = (0, _i18n.__)('Unknown error');
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 /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
72
- className: "list-reusable-blocks-import-form",
73
- onSubmit: onSubmit,
74
- ref: formRef,
75
- children: [error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Notice, {
76
- status: "error",
77
- onRemove: () => onDismissError(),
78
- children: error
79
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
80
- htmlFor: inputId,
81
- className: "list-reusable-blocks-import-form__label",
82
- children: (0, _i18n.__)('File')
83
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
84
- id: inputId,
85
- type: "file",
86
- onChange: onChangeFile
87
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
88
- __next40pxDefaultSize: true,
89
- type: "submit",
90
- isBusy: isLoading,
91
- accessibleWhenDisabled: true,
92
- disabled: !file || isLoading,
93
- variant: "secondary",
94
- className: "list-reusable-blocks-import-form__button",
95
- children: (0, _i18n._x)('Import', 'button label')
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 _default = exports.default = (0, _compose.withInstanceId)(ImportForm);
100
- //# sourceMappingURL=index.js.map
117
+ var import_form_default = (0, import_compose.withInstanceId)(ImportForm);
118
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_compose","_i18n","_components","_import","_interopRequireDefault","_jsxRuntime","ImportForm","instanceId","onUpload","inputId","formRef","useRef","isLoading","setIsLoading","useState","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","importReusableBlock","then","reusableBlock","catch","errors","uiMessage","message","__","onDismissError","jsxs","className","ref","children","jsx","Notice","status","onRemove","htmlFor","id","type","onChange","Button","__next40pxDefaultSize","isBusy","accessibleWhenDisabled","disabled","variant","_x","_default","exports","default","withInstanceId"],"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"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"],"mappings":"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","ignoreList":[]}
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
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _element = require("@wordpress/element");
5
- var _i18n = require("@wordpress/i18n");
6
- var _export = _interopRequireDefault(require("./utils/export"));
7
- var _importDropdown = _interopRequireDefault(require("./components/import-dropdown"));
8
- var _jsxRuntime = require("react/jsx-runtime");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
-
17
- // Setup Export Links.
18
- document.body.addEventListener('click', event => {
19
- if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
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, _export.default)(event.target.dataset.id);
33
+ (0, import_export.default)(event.target.dataset.id);
24
34
  });
25
-
26
- // Setup Import Form.
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('div');
34
- notice.className = 'notice notice-success is-dismissible';
35
- notice.innerHTML = `<p>${(0, _i18n.__)('Pattern imported successfully!')}</p>`;
36
- const headerEnd = document.querySelector('.wp-header-end');
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('div');
43
- container.className = 'list-reusable-blocks__container';
50
+ const container = document.createElement("div");
51
+ container.className = "list-reusable-blocks__container";
44
52
  button.parentNode.insertBefore(container, button);
45
- (0, _element.createRoot)(container).render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_element.StrictMode, {
46
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_importDropdown.default, {
47
- onUpload: showNotice
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
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_i18n","_export","_interopRequireDefault","_importDropdown","_jsxRuntime","document","body","addEventListener","event","target","classList","contains","preventDefault","exportReusableBlock","dataset","id","button","querySelector","showNotice","notice","createElement","className","innerHTML","__","headerEnd","parentNode","insertBefore","container","createRoot","render","jsx","StrictMode","children","default","onUpload"],"sources":["@wordpress/list-reusable-blocks/src/index.js"],"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"],"mappings":";;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAKA,IAAAE,OAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,eAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA0D,IAAAK,WAAA,GAAAL,OAAA;AAV1D;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACAM,QAAQ,CAACC,IAAI,CAACC,gBAAgB,CAAE,OAAO,EAAIC,KAAK,IAAM;EACrD,IACC,CAAEA,KAAK,CAACC,MAAM,CAACC,SAAS,CAACC,QAAQ,CAAE,iCAAkC,CAAC,EACrE;IACD;EACD;EACAH,KAAK,CAACI,cAAc,CAAC,CAAC;EACtB,IAAAC,eAAmB,EAAEL,KAAK,CAACC,MAAM,CAACK,OAAO,CAACC,EAAG,CAAC;AAC/C,CAAE,CAAC;;AAEH;AACAV,QAAQ,CAACE,gBAAgB,CAAE,kBAAkB,EAAE,MAAM;EACpD,MAAMS,MAAM,GAAGX,QAAQ,CAACY,aAAa,CAAE,oBAAqB,CAAC;EAC7D,IAAK,CAAED,MAAM,EAAG;IACf;EACD;EAEA,MAAME,UAAU,GAAGA,CAAA,KAAM;IACxB,MAAMC,MAAM,GAAGd,QAAQ,CAACe,aAAa,CAAE,KAAM,CAAC;IAC9CD,MAAM,CAACE,SAAS,GAAG,sCAAsC;IACzDF,MAAM,CAACG,SAAS,GAAG,MAAO,IAAAC,QAAE,EAAE,gCAAiC,CAAC,MAAO;IAEvE,MAAMC,SAAS,GAAGnB,QAAQ,CAACY,aAAa,CAAE,gBAAiB,CAAC;IAC5D,IAAK,CAAEO,SAAS,EAAG;MAClB;IACD;IACAA,SAAS,CAACC,UAAU,CAACC,YAAY,CAAEP,MAAM,EAAEK,SAAU,CAAC;EACvD,CAAC;EAED,MAAMG,SAAS,GAAGtB,QAAQ,CAACe,aAAa,CAAE,KAAM,CAAC;EACjDO,SAAS,CAACN,SAAS,GAAG,iCAAiC;EACvDL,MAAM,CAACS,UAAU,CAACC,YAAY,CAAEC,SAAS,EAAEX,MAAO,CAAC;EACnD,IAAAY,mBAAU,EAAED,SAAU,CAAC,CAACE,MAAM,cAC7B,IAAAzB,WAAA,CAAA0B,GAAA,EAAChC,QAAA,CAAAiC,UAAU;IAAAC,QAAA,eACV,IAAA5B,WAAA,CAAA0B,GAAA,EAAC3B,eAAA,CAAA8B,OAAc;MAACC,QAAQ,EAAGhB;IAAY,CAAE;EAAC,CAC/B,CACb,CAAC;AACF,CAAE,CAAC","ignoreList":[]}
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
+ }
@@ -1,48 +1,58 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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.default = void 0;
8
- var _changeCase = require("change-case");
9
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
10
- var _blob = require("@wordpress/blob");
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, _apiFetch.default)({
30
- path: `/wp/v2/types/wp_block`
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
- __file: 'wp_block',
40
- title,
41
- content,
42
- syncStatus
43
- }, null, 2);
44
- const fileName = (0, _changeCase.paramCase)(title) + '.json';
45
- (0, _blob.downloadBlob)(fileName, fileContent, 'application/json');
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 _default = exports.default = exportReusableBlock;
48
- //# sourceMappingURL=export.js.map
57
+ var export_default = exportReusableBlock;
58
+ //# sourceMappingURL=export.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_blob","exportReusableBlock","id","postType","apiFetch","path","post","rest_base","title","raw","content","syncStatus","wp_pattern_sync_status","fileContent","JSON","stringify","__file","fileName","kebabCase","downloadBlob","_default","exports","default"],"sources":["@wordpress/list-reusable-blocks/src/utils/export.js"],"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"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,eAAeI,mBAAmBA,CAAEC,EAAE,EAAG;EACxC,MAAMC,QAAQ,GAAG,MAAM,IAAAC,iBAAQ,EAAE;IAAEC,IAAI,EAAE;EAAwB,CAAE,CAAC;EACpE,MAAMC,IAAI,GAAG,MAAM,IAAAF,iBAAQ,EAAE;IAC5BC,IAAI,EAAE,UAAWF,QAAQ,CAACI,SAAS,IAAML,EAAE;EAC5C,CAAE,CAAC;EACH,MAAMM,KAAK,GAAGF,IAAI,CAACE,KAAK,CAACC,GAAG;EAC5B,MAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAO,CAACD,GAAG;EAChC,MAAME,UAAU,GAAGL,IAAI,CAACM,sBAAsB;EAC9C,MAAMC,WAAW,GAAGC,IAAI,CAACC,SAAS,CACjC;IACCC,MAAM,EAAE,UAAU;IAClBR,KAAK;IACLE,OAAO;IACPC;EACD,CAAC,EACD,IAAI,EACJ,CACD,CAAC;EACD,MAAMM,QAAQ,GAAG,IAAAC,qBAAS,EAAEV,KAAM,CAAC,GAAG,OAAO;EAE7C,IAAAW,kBAAY,EAAEF,QAAQ,EAAEJ,WAAW,EAAE,kBAAmB,CAAC;AAC1D;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcrB,mBAAmB","ignoreList":[]}
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
+ }
@@ -1,22 +1,36 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var file_exports = {};
19
+ __export(file_exports, {
20
+ readTextFile: () => readTextFile
5
21
  });
6
- exports.readTextFile = readTextFile;
7
- /**
8
- * Reads the textual content of the given file.
9
- *
10
- * @param {File} file File.
11
- * @return {Promise<string>} Content of the file.
12
- */
22
+ module.exports = __toCommonJS(file_exports);
13
23
  function readTextFile(file) {
14
24
  const reader = new window.FileReader();
15
- return new Promise(resolve => {
25
+ return new Promise((resolve) => {
16
26
  reader.onload = () => {
17
27
  resolve(reader.result);
18
28
  };
19
29
  reader.readAsText(file);
20
30
  });
21
31
  }
22
- //# sourceMappingURL=file.js.map
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ readTextFile
35
+ });
36
+ //# sourceMappingURL=file.js.map