@wordpress/list-reusable-blocks 4.15.0 → 4.17.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 CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.17.0 (2023-08-16)
6
+
7
+ ## 4.16.0 (2023-08-10)
8
+
5
9
  ## 4.15.0 (2023-07-20)
6
10
 
7
11
  ## 4.14.0 (2023-07-05)
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _compose = require("@wordpress/compose");
13
-
14
10
  var _i18n = require("@wordpress/i18n");
15
-
16
11
  var _components = require("@wordpress/components");
17
-
18
12
  var _importForm = _interopRequireDefault(require("../import-form"));
19
-
20
13
  /**
21
14
  * WordPress dependencies
22
15
  */
@@ -24,6 +17,7 @@ var _importForm = _interopRequireDefault(require("../import-form"));
24
17
  /**
25
18
  * Internal dependencies
26
19
  */
20
+
27
21
  function ImportDropdown({
28
22
  onUpload
29
23
  }) {
@@ -47,7 +41,6 @@ function ImportDropdown({
47
41
  })
48
42
  });
49
43
  }
50
-
51
44
  var _default = ImportDropdown;
52
45
  exports.default = _default;
53
46
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-dropdown/index.js"],"names":["ImportDropdown","onUpload","placement","isOpen","onToggle","onClose"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGA,SAASA,cAAT,CAAyB;AAAEC,EAAAA;AAAF,CAAzB,EAAwC;AACvC,SACC,4BAAC,oBAAD;AACC,IAAA,YAAY,EAAG;AAAEC,MAAAA,SAAS,EAAE;AAAb,KADhB;AAEC,IAAA,gBAAgB,EAAC,+CAFlB;AAGC,IAAA,YAAY,EAAG,CAAE;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAF,KACd,4BAAC,kBAAD;AACC,uBAAgBD,MADjB;AAEC,MAAA,OAAO,EAAGC,QAFX;AAGC,MAAA,OAAO,EAAC;AAHT,OAKG,cAAI,kBAAJ,CALH,CAJF;AAYC,IAAA,aAAa,EAAG,CAAE;AAAEC,MAAAA;AAAF,KAAF,KACf,4BAAC,mBAAD;AAAY,MAAA,QAAQ,EAAG,mBAAMA,OAAN,EAAeJ,QAAf;AAAvB;AAbF,IADD;AAkBA;;eAEcD,c","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\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"]}
1
+ {"version":3,"names":["_compose","require","_i18n","_components","_importForm","_interopRequireDefault","ImportDropdown","onUpload","_element","createElement","Dropdown","popoverProps","placement","contentClassName","renderToggle","isOpen","onToggle","Button","onClick","variant","__","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\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;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAGA,SAASK,cAAcA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACvC,OACC,IAAAC,QAAA,CAAAC,aAAA,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,KACpC,IAAAR,QAAA,CAAAC,aAAA,EAACN,WAAA,CAAAc,MAAM;MACN,iBAAgBF,MAAQ;MACxBG,OAAO,EAAGF,QAAU;MACpBG,OAAO,EAAC;IAAS,GAEf,IAAAC,QAAE,EAAE,kBAAmB,CAClB,CACN;IACHC,aAAa,EAAGA,CAAE;MAAEC;IAAQ,CAAC,KAC5B,IAAAd,QAAA,CAAAC,aAAA,EAACL,WAAA,CAAAmB,OAAU;MAAChB,QAAQ,EAAG,IAAAiB,aAAI,EAAEF,OAAO,EAAEf,QAAS;IAAG,CAAE;EAClD,CACH,CAAC;AAEJ;AAAC,IAAAkB,QAAA,GAEcnB,cAAc;AAAAoB,OAAA,CAAAH,OAAA,GAAAE,QAAA"}
@@ -1,22 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _compose = require("@wordpress/compose");
13
-
14
10
  var _i18n = require("@wordpress/i18n");
15
-
16
11
  var _components = require("@wordpress/components");
17
-
18
12
  var _import = _interopRequireDefault(require("../../utils/import"));
19
-
20
13
  /**
21
14
  * WordPress dependencies
22
15
  */
@@ -24,6 +17,7 @@ var _import = _interopRequireDefault(require("../../utils/import"));
24
17
  /**
25
18
  * Internal dependencies
26
19
  */
20
+
27
21
  function ImportForm({
28
22
  instanceId,
29
23
  onUpload
@@ -33,19 +27,15 @@ function ImportForm({
33
27
  const [isLoading, setIsLoading] = (0, _element.useState)(false);
34
28
  const [error, setError] = (0, _element.useState)(null);
35
29
  const [file, setFile] = (0, _element.useState)(null);
36
-
37
30
  const onChangeFile = event => {
38
31
  setFile(event.target.files[0]);
39
32
  setError(null);
40
33
  };
41
-
42
34
  const onSubmit = event => {
43
35
  event.preventDefault();
44
-
45
36
  if (!file) {
46
37
  return;
47
38
  }
48
-
49
39
  setIsLoading({
50
40
  isLoading: true
51
41
  });
@@ -53,38 +43,30 @@ function ImportForm({
53
43
  if (!formRef) {
54
44
  return;
55
45
  }
56
-
57
46
  setIsLoading(false);
58
47
  onUpload(reusableBlock);
59
48
  }).catch(errors => {
60
49
  if (!formRef) {
61
50
  return;
62
51
  }
63
-
64
52
  let uiMessage;
65
-
66
53
  switch (errors.message) {
67
54
  case 'Invalid JSON file':
68
55
  uiMessage = (0, _i18n.__)('Invalid JSON file');
69
56
  break;
70
-
71
57
  case 'Invalid Pattern JSON file':
72
58
  uiMessage = (0, _i18n.__)('Invalid Pattern JSON file');
73
59
  break;
74
-
75
60
  default:
76
61
  uiMessage = (0, _i18n.__)('Unknown error');
77
62
  }
78
-
79
63
  setIsLoading(false);
80
64
  setError(uiMessage);
81
65
  });
82
66
  };
83
-
84
67
  const onDismissError = () => {
85
68
  setError(null);
86
69
  };
87
-
88
70
  return (0, _element.createElement)("form", {
89
71
  className: "list-reusable-blocks-import-form",
90
72
  onSubmit: onSubmit,
@@ -107,8 +89,6 @@ function ImportForm({
107
89
  className: "list-reusable-blocks-import-form__button"
108
90
  }, (0, _i18n._x)('Import', 'button label')));
109
91
  }
110
-
111
92
  var _default = (0, _compose.withInstanceId)(ImportForm);
112
-
113
93
  exports.default = _default;
114
94
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["ImportForm","instanceId","onUpload","inputId","formRef","isLoading","setIsLoading","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","then","reusableBlock","catch","errors","uiMessage","message","onDismissError"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAXA;AACA;AACA;;AAMA;AACA;AACA;AAGA,SAASA,UAAT,CAAqB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,CAArB,EAAgD;AAC/C,QAAMC,OAAO,GAAG,sCAAsCF,UAAtD;AAEA,QAAMG,OAAO,GAAG,sBAAhB;AACA,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,uBAAU,KAAV,CAApC;AACA,QAAM,CAAEC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AQ,EAAGO,QAFZ;AAGC,IAAA,GAAG,EAAGX;AAHP,KAKGG,KAAK,IACN,4BAAC,kBAAD;AAAQ,IAAA,MAAM,EAAC,OAAf;AAAuB,IAAA,QAAQ,EAAG,MAAMgB,cAAc;AAAtD,KACGhB,KADH,CANF,EAUC;AACC,IAAA,OAAO,EAAGJ,OADX;AAEC,IAAA,SAAS,EAAC;AAFX,KAIG,cAAI,MAAJ,CAJH,CAVD,EAgBC;AAAO,IAAA,EAAE,EAAGA,OAAZ;AAAsB,IAAA,IAAI,EAAC,MAA3B;AAAkC,IAAA,QAAQ,EAAGQ;AAA7C,IAhBD,EAiBC,4BAAC,kBAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,MAAM,EAAGN,SAFV;AAGC,IAAA,QAAQ,EAAG,CAAEI,IAAF,IAAUJ,SAHtB;AAIC,IAAA,OAAO,EAAC,WAJT;AAKC,IAAA,SAAS,EAAC;AALX,KAOG,cAAI,QAAJ,EAAc,cAAd,CAPH,CAjBD,CADD;AA6BA;;eAEc,6BAAgBL,UAAhB,C","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\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\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"]}
1
+ {"version":3,"names":["_element","require","_compose","_i18n","_components","_import","_interopRequireDefault","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","createElement","className","ref","Notice","status","onRemove","htmlFor","id","type","onChange","Button","isBusy","disabled","variant","_x","_default","withInstanceId","exports","default"],"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\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AAKA,IAAAI,OAAA,GAAAC,sBAAA,CAAAL,OAAA;AAXA;AACA;AAC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,10 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _element = require("@wordpress/element");
6
-
7
5
  var _i18n = require("@wordpress/i18n");
8
-
9
6
  var _export = _interopRequireDefault(require("./utils/export"));
10
-
11
7
  var _importDropdown = _interopRequireDefault(require("./components/import-dropdown"));
12
-
13
8
  /**
14
9
  * WordPress dependencies
15
10
  */
@@ -17,36 +12,32 @@ var _importDropdown = _interopRequireDefault(require("./components/import-dropdo
17
12
  /**
18
13
  * Internal dependencies
19
14
  */
15
+
20
16
  // Setup Export Links.
21
17
  document.body.addEventListener('click', event => {
22
18
  if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
23
19
  return;
24
20
  }
25
-
26
21
  event.preventDefault();
27
22
  (0, _export.default)(event.target.dataset.id);
28
- }); // Setup Import Form.
23
+ });
29
24
 
25
+ // Setup Import Form.
30
26
  document.addEventListener('DOMContentLoaded', () => {
31
27
  const button = document.querySelector('.page-title-action');
32
-
33
28
  if (!button) {
34
29
  return;
35
30
  }
36
-
37
31
  const showNotice = () => {
38
32
  const notice = document.createElement('div');
39
33
  notice.className = 'notice notice-success is-dismissible';
40
34
  notice.innerHTML = `<p>${(0, _i18n.__)('Pattern imported successfully!')}</p>`;
41
35
  const headerEnd = document.querySelector('.wp-header-end');
42
-
43
36
  if (!headerEnd) {
44
37
  return;
45
38
  }
46
-
47
39
  headerEnd.parentNode.insertBefore(notice, headerEnd);
48
40
  };
49
-
50
41
  const container = document.createElement('div');
51
42
  container.className = 'list-reusable-blocks__container';
52
43
  button.parentNode.insertBefore(container, button);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/index.js"],"names":["document","body","addEventListener","event","target","classList","contains","preventDefault","dataset","id","button","querySelector","showNotice","notice","createElement","className","innerHTML","headerEnd","parentNode","insertBefore","container","render"],"mappings":";;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;A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} 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<ImportDropdown onUpload={ showNotice } />\n\t);\n} );\n"]}
1
+ {"version":3,"names":["_element","require","_i18n","_export","_interopRequireDefault","_importDropdown","document","body","addEventListener","event","target","classList","contains","preventDefault","exportReusableBlock","dataset","id","button","querySelector","showNotice","notice","createElement","className","innerHTML","__","headerEnd","parentNode","insertBefore","container","createRoot","render","default","onUpload"],"sources":["@wordpress/list-reusable-blocks/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot } 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<ImportDropdown onUpload={ showNotice } />\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;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACAK,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,GAAI,MAAM,IAAAC,QAAE,EAAE,gCAAiC,CAAG,MAAK;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,IAAA9B,QAAA,CAAAqB,aAAA,EAAChB,eAAA,CAAA0B,OAAc;IAACC,QAAQ,EAAGb;EAAY,CAAE,CAC1C,CAAC;AACF,CAAE,CAAC"}
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _changeCase = require("change-case");
11
-
12
9
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
13
-
14
10
  var _file = require("./file");
15
-
16
11
  /**
17
12
  * External dependencies
18
13
  */
@@ -49,7 +44,6 @@ async function exportReusableBlock(id) {
49
44
  const fileName = (0, _changeCase.paramCase)(title) + '.json';
50
45
  (0, _file.download)(fileName, fileContent, 'application/json');
51
46
  }
52
-
53
47
  var _default = exportReusableBlock;
54
48
  exports.default = _default;
55
49
  //# sourceMappingURL=export.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/export.js"],"names":["exportReusableBlock","id","postType","path","post","rest_base","title","raw","content","syncStatus","wp_pattern_sync_status","fileContent","JSON","stringify","__file","fileName"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,eAAeA,mBAAf,CAAoCC,EAApC,EAAyC;AACxC,QAAMC,QAAQ,GAAG,MAAM,uBAAU;AAAEC,IAAAA,IAAI,EAAG;AAAT,GAAV,CAAvB;AACA,QAAMC,IAAI,GAAG,MAAM,uBAAU;AAC5BD,IAAAA,IAAI,EAAG,UAAUD,QAAQ,CAACG,SAAW,IAAIJ,EAAI;AADjB,GAAV,CAAnB;AAGA,QAAMK,KAAK,GAAGF,IAAI,CAACE,KAAL,CAAWC,GAAzB;AACA,QAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAL,CAAaD,GAA7B;AACA,QAAME,UAAU,GAAGL,IAAI,CAACM,sBAAxB;AACA,QAAMC,WAAW,GAAGC,IAAI,CAACC,SAAL,CACnB;AACCC,IAAAA,MAAM,EAAE,UADT;AAECR,IAAAA,KAFD;AAGCE,IAAAA,OAHD;AAICC,IAAAA;AAJD,GADmB,EAOnB,IAPmB,EAQnB,CARmB,CAApB;AAUA,QAAMM,QAAQ,GAAG,2BAAWT,KAAX,IAAqB,OAAtC;AAEA,sBAAUS,QAAV,EAAoBJ,WAApB,EAAiC,kBAAjC;AACA;;eAEcX,mB","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 { download } from './file';\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\tdownload( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"]}
1
+ {"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_file","exportReusableBlock","id","postType","apiFetch","path","post","rest_base","title","raw","content","syncStatus","wp_pattern_sync_status","fileContent","JSON","stringify","__file","fileName","kebabCase","download","_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 { download } from './file';\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\tdownload( 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,EAAG;EAAuB,CAAE,CAAC;EACpE,MAAMC,IAAI,GAAG,MAAM,IAAAF,iBAAQ,EAAE;IAC5BC,IAAI,EAAG,UAAUF,QAAQ,CAACI,SAAW,IAAIL,EAAI;EAC9C,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,cAAQ,EAAEF,QAAQ,EAAEJ,WAAW,EAAE,kBAAmB,CAAC;AACtD;AAAC,IAAAO,QAAA,GAEcnB,mBAAmB;AAAAoB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.download = download;
7
7
  exports.readTextFile = readTextFile;
8
-
9
8
  /**
10
9
  * Downloads a file.
11
10
  *
@@ -16,9 +15,10 @@ exports.readTextFile = readTextFile;
16
15
  function download(fileName, content, contentType) {
17
16
  const file = new window.Blob([content], {
18
17
  type: contentType
19
- }); // IE11 can't use the click to download technique
20
- // we use a specific IE11 technique instead.
18
+ });
21
19
 
20
+ // IE11 can't use the click to download technique
21
+ // we use a specific IE11 technique instead.
22
22
  if (window.navigator.msSaveOrOpenBlob) {
23
23
  window.navigator.msSaveOrOpenBlob(file, fileName);
24
24
  } else {
@@ -31,21 +31,19 @@ function download(fileName, content, contentType) {
31
31
  document.body.removeChild(a);
32
32
  }
33
33
  }
34
+
34
35
  /**
35
36
  * Reads the textual content of the given file.
36
37
  *
37
38
  * @param {File} file File.
38
39
  * @return {Promise<string>} Content of the file.
39
40
  */
40
-
41
-
42
41
  function readTextFile(file) {
43
42
  const reader = new window.FileReader();
44
43
  return new Promise(resolve => {
45
44
  reader.onload = () => {
46
45
  resolve(reader.result);
47
46
  };
48
-
49
47
  reader.readAsText(file);
50
48
  });
51
49
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/file.js"],"names":["download","fileName","content","contentType","file","window","Blob","type","navigator","msSaveOrOpenBlob","a","document","createElement","href","URL","createObjectURL","style","display","body","appendChild","click","removeChild","readTextFile","reader","FileReader","Promise","resolve","onload","result","readAsText"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAT,CAAmBC,QAAnB,EAA6BC,OAA7B,EAAsCC,WAAtC,EAAoD;AAC1D,QAAMC,IAAI,GAAG,IAAIC,MAAM,CAACC,IAAX,CAAiB,CAAEJ,OAAF,CAAjB,EAA8B;AAAEK,IAAAA,IAAI,EAAEJ;AAAR,GAA9B,CAAb,CAD0D,CAG1D;AACA;;AACA,MAAKE,MAAM,CAACG,SAAP,CAAiBC,gBAAtB,EAAyC;AACxCJ,IAAAA,MAAM,CAACG,SAAP,CAAiBC,gBAAjB,CAAmCL,IAAnC,EAAyCH,QAAzC;AACA,GAFD,MAEO;AACN,UAAMS,CAAC,GAAGC,QAAQ,CAACC,aAAT,CAAwB,GAAxB,CAAV;AACAF,IAAAA,CAAC,CAACG,IAAF,GAASC,GAAG,CAACC,eAAJ,CAAqBX,IAArB,CAAT;AACAM,IAAAA,CAAC,CAACV,QAAF,GAAaC,QAAb;AAEAS,IAAAA,CAAC,CAACM,KAAF,CAAQC,OAAR,GAAkB,MAAlB;AACAN,IAAAA,QAAQ,CAACO,IAAT,CAAcC,WAAd,CAA2BT,CAA3B;AACAA,IAAAA,CAAC,CAACU,KAAF;AACAT,IAAAA,QAAQ,CAACO,IAAT,CAAcG,WAAd,CAA2BX,CAA3B;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASY,YAAT,CAAuBlB,IAAvB,EAA8B;AACpC,QAAMmB,MAAM,GAAG,IAAIlB,MAAM,CAACmB,UAAX,EAAf;AACA,SAAO,IAAIC,OAAJ,CAAeC,OAAF,IAAe;AAClCH,IAAAA,MAAM,CAACI,MAAP,GAAgB,MAAM;AACrBD,MAAAA,OAAO,CAAEH,MAAM,CAACK,MAAT,CAAP;AACA,KAFD;;AAGAL,IAAAA,MAAM,CAACM,UAAP,CAAmBzB,IAAnB;AACA,GALM,CAAP;AAMA","sourcesContent":["/**\n * Downloads a file.\n *\n * @param {string} fileName File Name.\n * @param {string} content File Content.\n * @param {string} contentType File mime type.\n */\nexport function download( fileName, content, contentType ) {\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\n\t// IE11 can't use the click to download technique\n\t// we use a specific IE11 technique instead.\n\tif ( window.navigator.msSaveOrOpenBlob ) {\n\t\twindow.navigator.msSaveOrOpenBlob( file, fileName );\n\t} else {\n\t\tconst a = document.createElement( 'a' );\n\t\ta.href = URL.createObjectURL( file );\n\t\ta.download = fileName;\n\n\t\ta.style.display = 'none';\n\t\tdocument.body.appendChild( a );\n\t\ta.click();\n\t\tdocument.body.removeChild( a );\n\t}\n}\n\n/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"]}
1
+ {"version":3,"names":["download","fileName","content","contentType","file","window","Blob","type","navigator","msSaveOrOpenBlob","a","document","createElement","href","URL","createObjectURL","style","display","body","appendChild","click","removeChild","readTextFile","reader","FileReader","Promise","resolve","onload","result","readAsText"],"sources":["@wordpress/list-reusable-blocks/src/utils/file.js"],"sourcesContent":["/**\n * Downloads a file.\n *\n * @param {string} fileName File Name.\n * @param {string} content File Content.\n * @param {string} contentType File mime type.\n */\nexport function download( fileName, content, contentType ) {\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\n\t// IE11 can't use the click to download technique\n\t// we use a specific IE11 technique instead.\n\tif ( window.navigator.msSaveOrOpenBlob ) {\n\t\twindow.navigator.msSaveOrOpenBlob( file, fileName );\n\t} else {\n\t\tconst a = document.createElement( 'a' );\n\t\ta.href = URL.createObjectURL( file );\n\t\ta.download = fileName;\n\n\t\ta.style.display = 'none';\n\t\tdocument.body.appendChild( a );\n\t\ta.click();\n\t\tdocument.body.removeChild( a );\n\t}\n}\n\n/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,QAAQA,CAAEC,QAAQ,EAAEC,OAAO,EAAEC,WAAW,EAAG;EAC1D,MAAMC,IAAI,GAAG,IAAIC,MAAM,CAACC,IAAI,CAAE,CAAEJ,OAAO,CAAE,EAAE;IAAEK,IAAI,EAAEJ;EAAY,CAAE,CAAC;;EAElE;EACA;EACA,IAAKE,MAAM,CAACG,SAAS,CAACC,gBAAgB,EAAG;IACxCJ,MAAM,CAACG,SAAS,CAACC,gBAAgB,CAAEL,IAAI,EAAEH,QAAS,CAAC;EACpD,CAAC,MAAM;IACN,MAAMS,CAAC,GAAGC,QAAQ,CAACC,aAAa,CAAE,GAAI,CAAC;IACvCF,CAAC,CAACG,IAAI,GAAGC,GAAG,CAACC,eAAe,CAAEX,IAAK,CAAC;IACpCM,CAAC,CAACV,QAAQ,GAAGC,QAAQ;IAErBS,CAAC,CAACM,KAAK,CAACC,OAAO,GAAG,MAAM;IACxBN,QAAQ,CAACO,IAAI,CAACC,WAAW,CAAET,CAAE,CAAC;IAC9BA,CAAC,CAACU,KAAK,CAAC,CAAC;IACTT,QAAQ,CAACO,IAAI,CAACG,WAAW,CAAEX,CAAE,CAAC;EAC/B;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASY,YAAYA,CAAElB,IAAI,EAAG;EACpC,MAAMmB,MAAM,GAAG,IAAIlB,MAAM,CAACmB,UAAU,CAAC,CAAC;EACtC,OAAO,IAAIC,OAAO,CAAIC,OAAO,IAAM;IAClCH,MAAM,CAACI,MAAM,GAAG,MAAM;MACrBD,OAAO,CAAEH,MAAM,CAACK,MAAO,CAAC;IACzB,CAAC;IACDL,MAAM,CAACM,UAAU,CAAEzB,IAAK,CAAC;EAC1B,CAAE,CAAC;AACJ"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
11
-
12
9
  var _file = require("./file");
13
-
14
10
  /**
15
11
  * WordPress dependencies
16
12
  */
@@ -28,17 +24,14 @@ var _file = require("./file");
28
24
  async function importReusableBlock(file) {
29
25
  const fileContent = await (0, _file.readTextFile)(file);
30
26
  let parsedContent;
31
-
32
27
  try {
33
28
  parsedContent = JSON.parse(fileContent);
34
29
  } catch (e) {
35
30
  throw new Error('Invalid JSON file');
36
31
  }
37
-
38
32
  if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
39
33
  throw new Error('Invalid Pattern JSON file');
40
34
  }
41
-
42
35
  const postType = await (0, _apiFetch.default)({
43
36
  path: `/wp/v2/types/wp_block`
44
37
  });
@@ -56,7 +49,6 @@ async function importReusableBlock(file) {
56
49
  });
57
50
  return reusableBlock;
58
51
  }
59
-
60
52
  var _default = importReusableBlock;
61
53
  exports.default = _default;
62
54
  //# sourceMappingURL=import.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/import.js"],"names":["importReusableBlock","file","fileContent","parsedContent","JSON","parse","e","Error","__file","title","content","syncStatus","postType","path","reusableBlock","rest_base","data","status","meta","wp_pattern_sync_status","undefined","method"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeA,mBAAf,CAAoCC,IAApC,EAA2C;AAC1C,QAAMC,WAAW,GAAG,MAAM,wBAAcD,IAAd,CAA1B;AACA,MAAIE,aAAJ;;AACA,MAAI;AACHA,IAAAA,aAAa,GAAGC,IAAI,CAACC,KAAL,CAAYH,WAAZ,CAAhB;AACA,GAFD,CAEE,OAAQI,CAAR,EAAY;AACb,UAAM,IAAIC,KAAJ,CAAW,mBAAX,CAAN;AACA;;AACD,MACCJ,aAAa,CAACK,MAAd,KAAyB,UAAzB,IACA,CAAEL,aAAa,CAACM,KADhB,IAEA,CAAEN,aAAa,CAACO,OAFhB,IAGA,OAAOP,aAAa,CAACM,KAArB,KAA+B,QAH/B,IAIA,OAAON,aAAa,CAACO,OAArB,KAAiC,QAJjC,IAKEP,aAAa,CAACQ,UAAd,IACD,OAAOR,aAAa,CAACQ,UAArB,KAAoC,QAPtC,EAQE;AACD,UAAM,IAAIJ,KAAJ,CAAW,2BAAX,CAAN;AACA;;AACD,QAAMK,QAAQ,GAAG,MAAM,uBAAU;AAAEC,IAAAA,IAAI,EAAG;AAAT,GAAV,CAAvB;AACA,QAAMC,aAAa,GAAG,MAAM,uBAAU;AACrCD,IAAAA,IAAI,EAAG,UAAUD,QAAQ,CAACG,SAAW,EADA;AAErCC,IAAAA,IAAI,EAAE;AACLP,MAAAA,KAAK,EAAEN,aAAa,CAACM,KADhB;AAELC,MAAAA,OAAO,EAAEP,aAAa,CAACO,OAFlB;AAGLO,MAAAA,MAAM,EAAE,SAHH;AAILC,MAAAA,IAAI,EACHf,aAAa,CAACQ,UAAd,KAA6B,UAA7B,GACG;AAAEQ,QAAAA,sBAAsB,EAAEhB,aAAa,CAACQ;AAAxC,OADH,GAEGS;AAPC,KAF+B;AAWrCC,IAAAA,MAAM,EAAE;AAX6B,GAAV,CAA5B;AAcA,SAAOP,aAAP;AACA;;eAEcd,mB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { readTextFile } from './file';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param {File} file File.\n * @return {Promise} Promise returning the imported reusable block.\n */\nasync function importReusableBlock( file ) {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent;\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch ( e ) {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid Pattern JSON file' );\n\t}\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst reusableBlock = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t},\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"]}
1
+ {"version":3,"names":["_apiFetch","_interopRequireDefault","require","_file","importReusableBlock","file","fileContent","readTextFile","parsedContent","JSON","parse","e","Error","__file","title","content","syncStatus","postType","apiFetch","path","reusableBlock","rest_base","data","status","meta","wp_pattern_sync_status","undefined","method","_default","exports","default"],"sources":["@wordpress/list-reusable-blocks/src/utils/import.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { readTextFile } from './file';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param {File} file File.\n * @return {Promise} Promise returning the imported reusable block.\n */\nasync function importReusableBlock( file ) {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent;\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch ( e ) {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid Pattern JSON file' );\n\t}\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst reusableBlock = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t},\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeE,mBAAmBA,CAAEC,IAAI,EAAG;EAC1C,MAAMC,WAAW,GAAG,MAAM,IAAAC,kBAAY,EAAEF,IAAK,CAAC;EAC9C,IAAIG,aAAa;EACjB,IAAI;IACHA,aAAa,GAAGC,IAAI,CAACC,KAAK,CAAEJ,WAAY,CAAC;EAC1C,CAAC,CAAC,OAAQK,CAAC,EAAG;IACb,MAAM,IAAIC,KAAK,CAAE,mBAAoB,CAAC;EACvC;EACA,IACCJ,aAAa,CAACK,MAAM,KAAK,UAAU,IACnC,CAAEL,aAAa,CAACM,KAAK,IACrB,CAAEN,aAAa,CAACO,OAAO,IACvB,OAAOP,aAAa,CAACM,KAAK,KAAK,QAAQ,IACvC,OAAON,aAAa,CAACO,OAAO,KAAK,QAAQ,IACvCP,aAAa,CAACQ,UAAU,IACzB,OAAOR,aAAa,CAACQ,UAAU,KAAK,QAAU,EAC9C;IACD,MAAM,IAAIJ,KAAK,CAAE,2BAA4B,CAAC;EAC/C;EACA,MAAMK,QAAQ,GAAG,MAAM,IAAAC,iBAAQ,EAAE;IAAEC,IAAI,EAAG;EAAuB,CAAE,CAAC;EACpE,MAAMC,aAAa,GAAG,MAAM,IAAAF,iBAAQ,EAAE;IACrCC,IAAI,EAAG,UAAUF,QAAQ,CAACI,SAAW,EAAC;IACtCC,IAAI,EAAE;MACLR,KAAK,EAAEN,aAAa,CAACM,KAAK;MAC1BC,OAAO,EAAEP,aAAa,CAACO,OAAO;MAC9BQ,MAAM,EAAE,SAAS;MACjBC,IAAI,EACHhB,aAAa,CAACQ,UAAU,KAAK,UAAU,GACpC;QAAES,sBAAsB,EAAEjB,aAAa,CAACQ;MAAW,CAAC,GACpDU;IACL,CAAC;IACDC,MAAM,EAAE;EACT,CAAE,CAAC;EAEH,OAAOP,aAAa;AACrB;AAAC,IAAAQ,QAAA,GAEcxB,mBAAmB;AAAAyB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -1,17 +1,15 @@
1
1
  import { createElement } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * WordPress dependencies
5
4
  */
6
5
  import { pipe } from '@wordpress/compose';
7
6
  import { __ } from '@wordpress/i18n';
8
7
  import { Dropdown, Button } from '@wordpress/components';
8
+
9
9
  /**
10
10
  * Internal dependencies
11
11
  */
12
-
13
12
  import ImportForm from '../import-form';
14
-
15
13
  function ImportDropdown({
16
14
  onUpload
17
15
  }) {
@@ -35,6 +33,5 @@ function ImportDropdown({
35
33
  })
36
34
  });
37
35
  }
38
-
39
36
  export default ImportDropdown;
40
37
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-dropdown/index.js"],"names":["pipe","__","Dropdown","Button","ImportForm","ImportDropdown","onUpload","placement","isOpen","onToggle","onClose"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,IAAT,QAAqB,oBAArB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,EAAmBC,MAAnB,QAAiC,uBAAjC;AAEA;AACA;AACA;;AACA,OAAOC,UAAP,MAAuB,gBAAvB;;AAEA,SAASC,cAAT,CAAyB;AAAEC,EAAAA;AAAF,CAAzB,EAAwC;AACvC,SACC,cAAC,QAAD;AACC,IAAA,YAAY,EAAG;AAAEC,MAAAA,SAAS,EAAE;AAAb,KADhB;AAEC,IAAA,gBAAgB,EAAC,+CAFlB;AAGC,IAAA,YAAY,EAAG,CAAE;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,KAAF,KACd,cAAC,MAAD;AACC,uBAAgBD,MADjB;AAEC,MAAA,OAAO,EAAGC,QAFX;AAGC,MAAA,OAAO,EAAC;AAHT,OAKGR,EAAE,CAAE,kBAAF,CALL,CAJF;AAYC,IAAA,aAAa,EAAG,CAAE;AAAES,MAAAA;AAAF,KAAF,KACf,cAAC,UAAD;AAAY,MAAA,QAAQ,EAAGV,IAAI,CAAEU,OAAF,EAAWJ,QAAX;AAA3B;AAbF,IADD;AAkBA;;AAED,eAAeD,cAAf","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\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"]}
1
+ {"version":3,"names":["pipe","__","Dropdown","Button","ImportForm","ImportDropdown","onUpload","createElement","popoverProps","placement","contentClassName","renderToggle","isOpen","onToggle","onClick","variant","renderContent","onClose"],"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\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":";AAAA;AACA;AACA;AACA,SAASA,IAAI,QAAQ,oBAAoB;AACzC,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,EAAEC,MAAM,QAAQ,uBAAuB;;AAExD;AACA;AACA;AACA,OAAOC,UAAU,MAAM,gBAAgB;AAEvC,SAASC,cAAcA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACvC,OACCC,aAAA,CAACL,QAAQ;IACRM,YAAY,EAAG;MAAEC,SAAS,EAAE;IAAe,CAAG;IAC9CC,gBAAgB,EAAC,+CAA+C;IAChEC,YAAY,EAAGA,CAAE;MAAEC,MAAM;MAAEC;IAAS,CAAC,KACpCN,aAAA,CAACJ,MAAM;MACN,iBAAgBS,MAAQ;MACxBE,OAAO,EAAGD,QAAU;MACpBE,OAAO,EAAC;IAAS,GAEfd,EAAE,CAAE,kBAAmB,CAClB,CACN;IACHe,aAAa,EAAGA,CAAE;MAAEC;IAAQ,CAAC,KAC5BV,aAAA,CAACH,UAAU;MAACE,QAAQ,EAAGN,IAAI,CAAEiB,OAAO,EAAEX,QAAS;IAAG,CAAE;EAClD,CACH,CAAC;AAEJ;AAEA,eAAeD,cAAc"}
@@ -1,5 +1,4 @@
1
1
  import { createElement } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * WordPress dependencies
5
4
  */
@@ -7,12 +6,11 @@ import { useState, useRef } from '@wordpress/element';
7
6
  import { withInstanceId } from '@wordpress/compose';
8
7
  import { __, _x } from '@wordpress/i18n';
9
8
  import { Button, Notice } from '@wordpress/components';
9
+
10
10
  /**
11
11
  * Internal dependencies
12
12
  */
13
-
14
13
  import importReusableBlock from '../../utils/import';
15
-
16
14
  function ImportForm({
17
15
  instanceId,
18
16
  onUpload
@@ -22,19 +20,15 @@ function ImportForm({
22
20
  const [isLoading, setIsLoading] = useState(false);
23
21
  const [error, setError] = useState(null);
24
22
  const [file, setFile] = useState(null);
25
-
26
23
  const onChangeFile = event => {
27
24
  setFile(event.target.files[0]);
28
25
  setError(null);
29
26
  };
30
-
31
27
  const onSubmit = event => {
32
28
  event.preventDefault();
33
-
34
29
  if (!file) {
35
30
  return;
36
31
  }
37
-
38
32
  setIsLoading({
39
33
  isLoading: true
40
34
  });
@@ -42,38 +36,30 @@ function ImportForm({
42
36
  if (!formRef) {
43
37
  return;
44
38
  }
45
-
46
39
  setIsLoading(false);
47
40
  onUpload(reusableBlock);
48
41
  }).catch(errors => {
49
42
  if (!formRef) {
50
43
  return;
51
44
  }
52
-
53
45
  let uiMessage;
54
-
55
46
  switch (errors.message) {
56
47
  case 'Invalid JSON file':
57
48
  uiMessage = __('Invalid JSON file');
58
49
  break;
59
-
60
50
  case 'Invalid Pattern JSON file':
61
51
  uiMessage = __('Invalid Pattern JSON file');
62
52
  break;
63
-
64
53
  default:
65
54
  uiMessage = __('Unknown error');
66
55
  }
67
-
68
56
  setIsLoading(false);
69
57
  setError(uiMessage);
70
58
  });
71
59
  };
72
-
73
60
  const onDismissError = () => {
74
61
  setError(null);
75
62
  };
76
-
77
63
  return createElement("form", {
78
64
  className: "list-reusable-blocks-import-form",
79
65
  onSubmit: onSubmit,
@@ -96,6 +82,5 @@ function ImportForm({
96
82
  className: "list-reusable-blocks-import-form__button"
97
83
  }, _x('Import', 'button label')));
98
84
  }
99
-
100
85
  export default withInstanceId(ImportForm);
101
86
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/components/import-form/index.js"],"names":["useState","useRef","withInstanceId","__","_x","Button","Notice","importReusableBlock","ImportForm","instanceId","onUpload","inputId","formRef","isLoading","setIsLoading","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","then","reusableBlock","catch","errors","uiMessage","message","onDismissError"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,QAAT,EAAmBC,MAAnB,QAAiC,oBAAjC;AACA,SAASC,cAAT,QAA+B,oBAA/B;AACA,SAASC,EAAT,EAAaC,EAAb,QAAuB,iBAAvB;AACA,SAASC,MAAT,EAAiBC,MAAjB,QAA+B,uBAA/B;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,oBAAhC;;AAEA,SAASC,UAAT,CAAqB;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,CAArB,EAAgD;AAC/C,QAAMC,OAAO,GAAG,sCAAsCF,UAAtD;AAEA,QAAMG,OAAO,GAAGX,MAAM,EAAtB;AACA,QAAM,CAAEY,SAAF,EAAaC,YAAb,IAA8Bd,QAAQ,CAAE,KAAF,CAA5C;AACA,QAAM,CAAEe,KAAF,EAASC,QAAT,IAAsBhB,QAAQ,CAAE,IAAF,CAApC;AACA,QAAM,CAAEiB,IAAF,EAAQC,OAAR,IAAoBlB,QAAQ,CAAE,IAAF,CAAlC;;AAEA,QAAMmB,YAAY,GAAKC,KAAF,IAAa;AACjCF,IAAAA,OAAO,CAAEE,KAAK,CAACC,MAAN,CAAaC,KAAb,CA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,CANF,EAUC;AACC,IAAA,OAAO,EAAGJ,OADX;AAEC,IAAA,SAAS,EAAC;AAFX,KAIGR,EAAE,CAAE,MAAF,CAJL,CAVD,EAgBC;AAAO,IAAA,EAAE,EAAGQ,OAAZ;AAAsB,IAAA,IAAI,EAAC,MAA3B;AAAkC,IAAA,QAAQ,EAAGQ;AAA7C,IAhBD,EAiBC,cAAC,MAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,MAAM,EAAGN,SAFV;AAGC,IAAA,QAAQ,EAAG,CAAEI,IAAF,IAAUJ,SAHtB;AAIC,IAAA,OAAO,EAAC,WAJT;AAKC,IAAA,SAAS,EAAC;AALX,KAOGT,EAAE,CAAE,QAAF,EAAY,cAAZ,CAPL,CAjBD,CADD;AA6BA;;AAED,eAAeF,cAAc,CAAEM,UAAF,CAA7B","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\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\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"]}
1
+ {"version":3,"names":["useState","useRef","withInstanceId","__","_x","Button","Notice","importReusableBlock","ImportForm","instanceId","onUpload","inputId","formRef","isLoading","setIsLoading","error","setError","file","setFile","onChangeFile","event","target","files","onSubmit","preventDefault","then","reusableBlock","catch","errors","uiMessage","message","onDismissError","createElement","className","ref","status","onRemove","htmlFor","id","type","onChange","isBusy","disabled","variant"],"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\ttype=\"submit\"\n\t\t\t\tisBusy={ isLoading }\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":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,MAAM,QAAQ,oBAAoB;AACrD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,EAAE,EAAEC,EAAE,QAAQ,iBAAiB;AACxC,SAASC,MAAM,EAAEC,MAAM,QAAQ,uBAAuB;;AAEtD;AACA;AACA;AACA,OAAOC,mBAAmB,MAAM,oBAAoB;AAEpD,SAASC,UAAUA,CAAE;EAAEC,UAAU;EAAEC;AAAS,CAAC,EAAG;EAC/C,MAAMC,OAAO,GAAG,mCAAmC,GAAGF,UAAU;EAEhE,MAAMG,OAAO,GAAGX,MAA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,CAAA,KAAM;IAC5Bf,QAAQ,CAAE,IAAK,CAAC;EACjB,CAAC;EAED,OACCgB,aAAA;IACCC,SAAS,EAAC,kCAAkC;IAC5CV,QAAQ,EAAGA,QAAU;IACrBW,GAAG,EAAGtB;EAAS,GAEbG,KAAK,IACNiB,aAAA,CAAC1B,MAAM;IAAC6B,MAAM,EAAC,OAAO;IAACC,QAAQ,EAAGA,CAAA,KAAML,cAAc,CAAC;EAAG,GACvDhB,KACK,CACR,EACDiB,aAAA;IACCK,OAAO,EAAG1B,OAAS;IACnBsB,SAAS,EAAC;EAAyC,GAEjD9B,EAAE,CAAE,MAAO,CACP,CAAC,EACR6B,aAAA;IAAOM,EAAE,EAAG3B,OAAS;IAAC4B,IAAI,EAAC,MAAM;IAACC,QAAQ,EAAGrB;EAAc,CAAE,CAAC,EAC9Da,aAAA,CAAC3B,MAAM;IACNkC,IAAI,EAAC,QAAQ;IACbE,MAAM,EAAG5B,SAAW;IACpB6B,QAAQ,EAAG,CAAEzB,IAAI,IAAIJ,SAAW;IAChC8B,OAAO,EAAC,WAAW;IACnBV,SAAS,EAAC;EAA0C,GAElD7B,EAAE,CAAE,QAAQ,EAAE,cAAe,CACxB,CACH,CAAC;AAET;AAEA,eAAeF,cAAc,CAAEM,UAAW,CAAC"}
@@ -1,46 +1,41 @@
1
1
  import { createElement } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * WordPress dependencies
5
4
  */
6
5
  import { createRoot } from '@wordpress/element';
7
6
  import { __ } from '@wordpress/i18n';
7
+
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
-
12
11
  import exportReusableBlock from './utils/export';
13
- import ImportDropdown from './components/import-dropdown'; // Setup Export Links.
12
+ import ImportDropdown from './components/import-dropdown';
14
13
 
14
+ // Setup Export Links.
15
15
  document.body.addEventListener('click', event => {
16
16
  if (!event.target.classList.contains('wp-list-reusable-blocks__export')) {
17
17
  return;
18
18
  }
19
-
20
19
  event.preventDefault();
21
20
  exportReusableBlock(event.target.dataset.id);
22
- }); // Setup Import Form.
21
+ });
23
22
 
23
+ // Setup Import Form.
24
24
  document.addEventListener('DOMContentLoaded', () => {
25
25
  const button = document.querySelector('.page-title-action');
26
-
27
26
  if (!button) {
28
27
  return;
29
28
  }
30
-
31
29
  const showNotice = () => {
32
30
  const notice = document.createElement('div');
33
31
  notice.className = 'notice notice-success is-dismissible';
34
32
  notice.innerHTML = `<p>${__('Pattern imported successfully!')}</p>`;
35
33
  const headerEnd = document.querySelector('.wp-header-end');
36
-
37
34
  if (!headerEnd) {
38
35
  return;
39
36
  }
40
-
41
37
  headerEnd.parentNode.insertBefore(notice, headerEnd);
42
38
  };
43
-
44
39
  const container = document.createElement('div');
45
40
  container.className = 'list-reusable-blocks__container';
46
41
  button.parentNode.insertBefore(container, button);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/index.js"],"names":["createRoot","__","exportReusableBlock","ImportDropdown","document","body","addEventListener","event","target","classList","contains","preventDefault","dataset","id","button","querySelector","showNotice","notice","createElement","className","innerHTML","headerEnd","parentNode","insertBefore","container","render"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,oBAA3B;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,OAAOC,mBAAP,MAAgC,gBAAhC;AACA,OAAOC,cAAP,MAA2B,8BAA3B,C,CAEA;;AACAC,QAAQ,CAACC,IAAT,CAAcC,gBAAd,CAAgC,OAAhC,EAA2CC,KAAF,IAAa;AACrD,MACC,CAAEA,KAAK,CAACC,MAAN,CAAaC,SAAb,CAAuBC,QAAvB,CAAiC,iCAAjC,CADH,EAEE;AACD;AACA;;AACDH,EAAAA,KAAK,CAACI,cAAN;AACAT,EAAAA,mBAAmB,CAAEK,KAAK,CAACC,MAAN,CAAaI,OAAb,CAAqBC,EAAvB,CAAnB;AACA,CARD,E,CAUA;;AACAT,QAAQ,CAACE,gBAAT,CAA2B,kBAA3B,EAA+C,MAAM;AACpD,QAAMQ,MAAM,GAAGV,QAAQ,CAACW,aAAT,CAAwB,oBAAxB,CAAf;;AACA,MAAK,CAAED,MAAP,EAAgB;AACf;AACA;;AAED,QAAME,UAAU,GAAG,MAAM;AACxB,UAAMC,MAAM,GAAGb,QAAQ,CAACc,aAAT,CAAwB,KAAxB,CAAf;AACAD,IAAAA,MAAM,CAACE,SAAP,GAAmB,sCAAnB;AACAF,IAAAA,MAAM,CAACG,SAAP,GAAoB,MAAMnB,EAAE,CAAE,gCAAF,CAAsC,MAAlE;AAEA,UAAMoB,SAAS,GAAGjB,QAAQ,CAACW,aAAT,CAAwB,gBAAxB,CAAlB;;AACA,QAAK,CAAEM,SAAP,EAAmB;AAClB;AACA;;AACDA,IAAAA,SAAS,CAACC,UAAV,CAAqBC,YAArB,CAAmCN,MAAnC,EAA2CI,SAA3C;AACA,GAVD;;AAYA,QAAMG,SAAS,GAAGpB,QAAQ,CAACc,aAAT,CAAwB,KAAxB,CAAlB;AACAM,EAAAA,SAAS,CAACL,SAAV,GAAsB,iCAAtB;AACAL,EAAAA,MAAM,CAACQ,UAAP,CAAkBC,YAAlB,CAAgCC,SAAhC,EAA2CV,MAA3C;AACAd,EAAAA,UAAU,CAAEwB,SAAF,CAAV,CAAwBC,MAAxB,CACC,cAAC,cAAD;AAAgB,IAAA,QAAQ,EAAGT;AAA3B,IADD;AAGA,CAxBD","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot } 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<ImportDropdown onUpload={ showNotice } />\n\t);\n} );\n"]}
1
+ {"version":3,"names":["createRoot","__","exportReusableBlock","ImportDropdown","document","body","addEventListener","event","target","classList","contains","preventDefault","dataset","id","button","querySelector","showNotice","notice","createElement","className","innerHTML","headerEnd","parentNode","insertBefore","container","render","onUpload"],"sources":["@wordpress/list-reusable-blocks/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot } 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<ImportDropdown onUpload={ showNotice } />\n\t);\n} );\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,OAAOC,mBAAmB,MAAM,gBAAgB;AAChD,OAAOC,cAAc,MAAM,8BAA8B;;AAEzD;AACAC,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;EACtBT,mBAAmB,CAAEK,KAAK,CAACC,MAAM,CAACI,OAAO,CAACC,EAAG,CAAC;AAC/C,CAAE,CAAC;;AAEH;AACAT,QAAQ,CAACE,gBAAgB,CAAE,kBAAkB,EAAE,MAAM;EACpD,MAAMQ,MAAM,GAAGV,QAAQ,CAACW,aAAa,CAAE,oBAAqB,CAAC;EAC7D,IAAK,CAAED,MAAM,EAAG;IACf;EACD;EAEA,MAAME,UAAU,GAAGA,CAAA,KAAM;IACxB,MAAMC,MAAM,GAAGb,QAAQ,CAACc,aAAa,CAAE,KAAM,CAAC;IAC9CD,MAAM,CAACE,SAAS,GAAG,sCAAsC;IACzDF,MAAM,CAACG,SAAS,GAAI,MAAMnB,EAAE,CAAE,gCAAiC,CAAG,MAAK;IAEvE,MAAMoB,SAAS,GAAGjB,QAAQ,CAACW,aAAa,CAAE,gBAAiB,CAAC;IAC5D,IAAK,CAAEM,SAAS,EAAG;MAClB;IACD;IACAA,SAAS,CAACC,UAAU,CAACC,YAAY,CAAEN,MAAM,EAAEI,SAAU,CAAC;EACvD,CAAC;EAED,MAAMG,SAAS,GAAGpB,QAAQ,CAACc,aAAa,CAAE,KAAM,CAAC;EACjDM,SAAS,CAACL,SAAS,GAAG,iCAAiC;EACvDL,MAAM,CAACQ,UAAU,CAACC,YAAY,CAAEC,SAAS,EAAEV,MAAO,CAAC;EACnDd,UAAU,CAAEwB,SAAU,CAAC,CAACC,MAAM,CAC7BP,aAAA,CAACf,cAAc;IAACuB,QAAQ,EAAGV;EAAY,CAAE,CAC1C,CAAC;AACF,CAAE,CAAC"}
@@ -2,22 +2,22 @@
2
2
  * External dependencies
3
3
  */
4
4
  import { paramCase as kebabCase } from 'change-case';
5
+
5
6
  /**
6
7
  * WordPress dependencies
7
8
  */
8
-
9
9
  import apiFetch from '@wordpress/api-fetch';
10
+
10
11
  /**
11
12
  * Internal dependencies
12
13
  */
13
-
14
14
  import { download } from './file';
15
+
15
16
  /**
16
17
  * Export a reusable block as a JSON file.
17
18
  *
18
19
  * @param {number} id
19
20
  */
20
-
21
21
  async function exportReusableBlock(id) {
22
22
  const postType = await apiFetch({
23
23
  path: `/wp/v2/types/wp_block`
@@ -37,6 +37,5 @@ async function exportReusableBlock(id) {
37
37
  const fileName = kebabCase(title) + '.json';
38
38
  download(fileName, fileContent, 'application/json');
39
39
  }
40
-
41
40
  export default exportReusableBlock;
42
41
  //# sourceMappingURL=export.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/export.js"],"names":["paramCase","kebabCase","apiFetch","download","exportReusableBlock","id","postType","path","post","rest_base","title","raw","content","syncStatus","wp_pattern_sync_status","fileContent","JSON","stringify","__file","fileName"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,IAAIC,SAAtB,QAAuC,aAAvC;AAEA;AACA;AACA;;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,QAAzB;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAeC,mBAAf,CAAoCC,EAApC,EAAyC;AACxC,QAAMC,QAAQ,GAAG,MAAMJ,QAAQ,CAAE;AAAEK,IAAAA,IAAI,EAAG;AAAT,GAAF,CAA/B;AACA,QAAMC,IAAI,GAAG,MAAMN,QAAQ,CAAE;AAC5BK,IAAAA,IAAI,EAAG,UAAUD,QAAQ,CAACG,SAAW,IAAIJ,EAAI;AADjB,GAAF,CAA3B;AAGA,QAAMK,KAAK,GAAGF,IAAI,CAACE,KAAL,CAAWC,GAAzB;AACA,QAAMC,OAAO,GAAGJ,IAAI,CAACI,OAAL,CAAaD,GAA7B;AACA,QAAME,UAAU,GAAGL,IAAI,CAACM,sBAAxB;AACA,QAAMC,WAAW,GAAGC,IAAI,CAACC,SAAL,CACnB;AACCC,IAAAA,MAAM,EAAE,UADT;AAECR,IAAAA,KAFD;AAGCE,IAAAA,OAHD;AAICC,IAAAA;AAJD,GADmB,EAOnB,IAPmB,EAQnB,CARmB,CAApB;AAUA,QAAMM,QAAQ,GAAGlB,SAAS,CAAES,KAAF,CAAT,GAAqB,OAAtC;AAEAP,EAAAA,QAAQ,CAAEgB,QAAF,EAAYJ,WAAZ,EAAyB,kBAAzB,CAAR;AACA;;AAED,eAAeX,mBAAf","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 { download } from './file';\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\tdownload( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"]}
1
+ {"version":3,"names":["paramCase","kebabCase","apiFetch","download","exportReusableBlock","id","postType","path","post","rest_base","title","raw","content","syncStatus","wp_pattern_sync_status","fileContent","JSON","stringify","__file","fileName"],"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 { download } from './file';\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\tdownload( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,IAAIC,SAAS,QAAQ,aAAa;;AAEpD;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,QAAQ;;AAEjC;AACA;AACA;AACA;AACA;AACA,eAAeC,mBAAmBA,CAAEC,EAAE,EAAG;EACxC,MAAMC,QAAQ,GAAG,MAAMJ,QAAQ,CAAE;IAAEK,IAAI,EAAG;EAAuB,CAAE,CAAC;EACpE,MAAMC,IAAI,GAAG,MAAMN,QAAQ,CAAE;IAC5BK,IAAI,EAAG,UAAUD,QAAQ,CAACG,SAAW,IAAIJ,EAAI;EAC9C,CAAE,CAAC;EACH,MAAMK,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,GAAGlB,SAAS,CAAES,KAAM,CAAC,GAAG,OAAO;EAE7CP,QAAQ,CAAEgB,QAAQ,EAAEJ,WAAW,EAAE,kBAAmB,CAAC;AACtD;AAEA,eAAeX,mBAAmB"}
@@ -8,9 +8,10 @@
8
8
  export function download(fileName, content, contentType) {
9
9
  const file = new window.Blob([content], {
10
10
  type: contentType
11
- }); // IE11 can't use the click to download technique
12
- // we use a specific IE11 technique instead.
11
+ });
13
12
 
13
+ // IE11 can't use the click to download technique
14
+ // we use a specific IE11 technique instead.
14
15
  if (window.navigator.msSaveOrOpenBlob) {
15
16
  window.navigator.msSaveOrOpenBlob(file, fileName);
16
17
  } else {
@@ -23,20 +24,19 @@ export function download(fileName, content, contentType) {
23
24
  document.body.removeChild(a);
24
25
  }
25
26
  }
27
+
26
28
  /**
27
29
  * Reads the textual content of the given file.
28
30
  *
29
31
  * @param {File} file File.
30
32
  * @return {Promise<string>} Content of the file.
31
33
  */
32
-
33
34
  export function readTextFile(file) {
34
35
  const reader = new window.FileReader();
35
36
  return new Promise(resolve => {
36
37
  reader.onload = () => {
37
38
  resolve(reader.result);
38
39
  };
39
-
40
40
  reader.readAsText(file);
41
41
  });
42
42
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/file.js"],"names":["download","fileName","content","contentType","file","window","Blob","type","navigator","msSaveOrOpenBlob","a","document","createElement","href","URL","createObjectURL","style","display","body","appendChild","click","removeChild","readTextFile","reader","FileReader","Promise","resolve","onload","result","readAsText"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,QAAT,CAAmBC,QAAnB,EAA6BC,OAA7B,EAAsCC,WAAtC,EAAoD;AAC1D,QAAMC,IAAI,GAAG,IAAIC,MAAM,CAACC,IAAX,CAAiB,CAAEJ,OAAF,CAAjB,EAA8B;AAAEK,IAAAA,IAAI,EAAEJ;AAAR,GAA9B,CAAb,CAD0D,CAG1D;AACA;;AACA,MAAKE,MAAM,CAACG,SAAP,CAAiBC,gBAAtB,EAAyC;AACxCJ,IAAAA,MAAM,CAACG,SAAP,CAAiBC,gBAAjB,CAAmCL,IAAnC,EAAyCH,QAAzC;AACA,GAFD,MAEO;AACN,UAAMS,CAAC,GAAGC,QAAQ,CAACC,aAAT,CAAwB,GAAxB,CAAV;AACAF,IAAAA,CAAC,CAACG,IAAF,GAASC,GAAG,CAACC,eAAJ,CAAqBX,IAArB,CAAT;AACAM,IAAAA,CAAC,CAACV,QAAF,GAAaC,QAAb;AAEAS,IAAAA,CAAC,CAACM,KAAF,CAAQC,OAAR,GAAkB,MAAlB;AACAN,IAAAA,QAAQ,CAACO,IAAT,CAAcC,WAAd,CAA2BT,CAA3B;AACAA,IAAAA,CAAC,CAACU,KAAF;AACAT,IAAAA,QAAQ,CAACO,IAAT,CAAcG,WAAd,CAA2BX,CAA3B;AACA;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASY,YAAT,CAAuBlB,IAAvB,EAA8B;AACpC,QAAMmB,MAAM,GAAG,IAAIlB,MAAM,CAACmB,UAAX,EAAf;AACA,SAAO,IAAIC,OAAJ,CAAeC,OAAF,IAAe;AAClCH,IAAAA,MAAM,CAACI,MAAP,GAAgB,MAAM;AACrBD,MAAAA,OAAO,CAAEH,MAAM,CAACK,MAAT,CAAP;AACA,KAFD;;AAGAL,IAAAA,MAAM,CAACM,UAAP,CAAmBzB,IAAnB;AACA,GALM,CAAP;AAMA","sourcesContent":["/**\n * Downloads a file.\n *\n * @param {string} fileName File Name.\n * @param {string} content File Content.\n * @param {string} contentType File mime type.\n */\nexport function download( fileName, content, contentType ) {\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\n\t// IE11 can't use the click to download technique\n\t// we use a specific IE11 technique instead.\n\tif ( window.navigator.msSaveOrOpenBlob ) {\n\t\twindow.navigator.msSaveOrOpenBlob( file, fileName );\n\t} else {\n\t\tconst a = document.createElement( 'a' );\n\t\ta.href = URL.createObjectURL( file );\n\t\ta.download = fileName;\n\n\t\ta.style.display = 'none';\n\t\tdocument.body.appendChild( a );\n\t\ta.click();\n\t\tdocument.body.removeChild( a );\n\t}\n}\n\n/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"]}
1
+ {"version":3,"names":["download","fileName","content","contentType","file","window","Blob","type","navigator","msSaveOrOpenBlob","a","document","createElement","href","URL","createObjectURL","style","display","body","appendChild","click","removeChild","readTextFile","reader","FileReader","Promise","resolve","onload","result","readAsText"],"sources":["@wordpress/list-reusable-blocks/src/utils/file.js"],"sourcesContent":["/**\n * Downloads a file.\n *\n * @param {string} fileName File Name.\n * @param {string} content File Content.\n * @param {string} contentType File mime type.\n */\nexport function download( fileName, content, contentType ) {\n\tconst file = new window.Blob( [ content ], { type: contentType } );\n\n\t// IE11 can't use the click to download technique\n\t// we use a specific IE11 technique instead.\n\tif ( window.navigator.msSaveOrOpenBlob ) {\n\t\twindow.navigator.msSaveOrOpenBlob( file, fileName );\n\t} else {\n\t\tconst a = document.createElement( 'a' );\n\t\ta.href = URL.createObjectURL( file );\n\t\ta.download = fileName;\n\n\t\ta.style.display = 'none';\n\t\tdocument.body.appendChild( a );\n\t\ta.click();\n\t\tdocument.body.removeChild( a );\n\t}\n}\n\n/**\n * Reads the textual content of the given file.\n *\n * @param {File} file File.\n * @return {Promise<string>} Content of the file.\n */\nexport function readTextFile( file ) {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,QAAQA,CAAEC,QAAQ,EAAEC,OAAO,EAAEC,WAAW,EAAG;EAC1D,MAAMC,IAAI,GAAG,IAAIC,MAAM,CAACC,IAAI,CAAE,CAAEJ,OAAO,CAAE,EAAE;IAAEK,IAAI,EAAEJ;EAAY,CAAE,CAAC;;EAElE;EACA;EACA,IAAKE,MAAM,CAACG,SAAS,CAACC,gBAAgB,EAAG;IACxCJ,MAAM,CAACG,SAAS,CAACC,gBAAgB,CAAEL,IAAI,EAAEH,QAAS,CAAC;EACpD,CAAC,MAAM;IACN,MAAMS,CAAC,GAAGC,QAAQ,CAACC,aAAa,CAAE,GAAI,CAAC;IACvCF,CAAC,CAACG,IAAI,GAAGC,GAAG,CAACC,eAAe,CAAEX,IAAK,CAAC;IACpCM,CAAC,CAACV,QAAQ,GAAGC,QAAQ;IAErBS,CAAC,CAACM,KAAK,CAACC,OAAO,GAAG,MAAM;IACxBN,QAAQ,CAACO,IAAI,CAACC,WAAW,CAAET,CAAE,CAAC;IAC9BA,CAAC,CAACU,KAAK,CAAC,CAAC;IACTT,QAAQ,CAACO,IAAI,CAACG,WAAW,CAAEX,CAAE,CAAC;EAC/B;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASY,YAAYA,CAAElB,IAAI,EAAG;EACpC,MAAMmB,MAAM,GAAG,IAAIlB,MAAM,CAACmB,UAAU,CAAC,CAAC;EACtC,OAAO,IAAIC,OAAO,CAAIC,OAAO,IAAM;IAClCH,MAAM,CAACI,MAAM,GAAG,MAAM;MACrBD,OAAO,CAAEH,MAAM,CAACK,MAAO,CAAC;IACzB,CAAC;IACDL,MAAM,CAACM,UAAU,CAAEzB,IAAK,CAAC;EAC1B,CAAE,CAAC;AACJ"}
@@ -2,32 +2,29 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import apiFetch from '@wordpress/api-fetch';
5
+
5
6
  /**
6
7
  * Internal dependencies
7
8
  */
8
-
9
9
  import { readTextFile } from './file';
10
+
10
11
  /**
11
12
  * Import a reusable block from a JSON file.
12
13
  *
13
14
  * @param {File} file File.
14
15
  * @return {Promise} Promise returning the imported reusable block.
15
16
  */
16
-
17
17
  async function importReusableBlock(file) {
18
18
  const fileContent = await readTextFile(file);
19
19
  let parsedContent;
20
-
21
20
  try {
22
21
  parsedContent = JSON.parse(fileContent);
23
22
  } catch (e) {
24
23
  throw new Error('Invalid JSON file');
25
24
  }
26
-
27
25
  if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
28
26
  throw new Error('Invalid Pattern JSON file');
29
27
  }
30
-
31
28
  const postType = await apiFetch({
32
29
  path: `/wp/v2/types/wp_block`
33
30
  });
@@ -45,6 +42,5 @@ async function importReusableBlock(file) {
45
42
  });
46
43
  return reusableBlock;
47
44
  }
48
-
49
45
  export default importReusableBlock;
50
46
  //# sourceMappingURL=import.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/list-reusable-blocks/src/utils/import.js"],"names":["apiFetch","readTextFile","importReusableBlock","file","fileContent","parsedContent","JSON","parse","e","Error","__file","title","content","syncStatus","postType","path","reusableBl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,CAACQ;AAAxC,OADH,GAEGS;AAPC,KAF+B;AAWrCC,IAAAA,MAAM,EAAE;AAX6B,GAAF,CAApC;AAcA,SAAOP,aAAP;AACA;;AAED,eAAed,mBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { readTextFile } from './file';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param {File} file File.\n * @return {Promise} Promise returning the imported reusable block.\n */\nasync function importReusableBlock( file ) {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent;\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch ( e ) {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid Pattern JSON file' );\n\t}\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst reusableBlock = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t},\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"]}
1
+ {"version":3,"names":["apiFetch","readTextFile","importReusableBlock","file","fileContent","parsedContent","JSON","parse","e","Error","__file","title","content","syncStatus","postType","path","reusableBlock","rest_base","data","status","meta","wp_pattern_sync_status","undefined","method"],"sources":["@wordpress/list-reusable-blocks/src/utils/import.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { readTextFile } from './file';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param {File} file File.\n * @return {Promise} Promise returning the imported reusable block.\n */\nasync function importReusableBlock( file ) {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent;\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch ( e ) {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\tif (\n\t\tparsedContent.__file !== 'wp_block' ||\n\t\t! parsedContent.title ||\n\t\t! parsedContent.content ||\n\t\ttypeof parsedContent.title !== 'string' ||\n\t\ttypeof parsedContent.content !== 'string' ||\n\t\t( parsedContent.syncStatus &&\n\t\t\ttypeof parsedContent.syncStatus !== 'string' )\n\t) {\n\t\tthrow new Error( 'Invalid Pattern JSON file' );\n\t}\n\tconst postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );\n\tconst reusableBlock = await apiFetch( {\n\t\tpath: `/wp/v2/${ postType.rest_base }`,\n\t\tdata: {\n\t\t\ttitle: parsedContent.title,\n\t\t\tcontent: parsedContent.content,\n\t\t\tstatus: 'publish',\n\t\t\tmeta:\n\t\t\t\tparsedContent.syncStatus === 'unsynced'\n\t\t\t\t\t? { wp_pattern_sync_status: parsedContent.syncStatus }\n\t\t\t\t\t: undefined,\n\t\t},\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;;AAE3C;AACA;AACA;AACA,SAASC,YAAY,QAAQ,QAAQ;;AAErC;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,mBAAmBA,CAAEC,IAAI,EAAG;EAC1C,MAAMC,WAAW,GAAG,MAAMH,YAAY,CAAEE,IAAK,CAAC;EAC9C,IAAIE,aAAa;EACjB,IAAI;IACHA,aAAa,GAAGC,IAAI,CAACC,KAAK,CAAEH,WAAY,CAAC;EAC1C,CAAC,CAAC,OAAQI,CAAC,EAAG;IACb,MAAM,IAAIC,KAAK,CAAE,mBAAoB,CAAC;EACvC;EACA,IACCJ,aAAa,CAACK,MAAM,KAAK,UAAU,IACnC,CAAEL,aAAa,CAACM,KAAK,IACrB,CAAEN,aAAa,CAACO,OAAO,IACvB,OAAOP,aAAa,CAACM,KAAK,KAAK,QAAQ,IACvC,OAAON,aAAa,CAACO,OAAO,KAAK,QAAQ,IACvCP,aAAa,CAACQ,UAAU,IACzB,OAAOR,aAAa,CAACQ,UAAU,KAAK,QAAU,EAC9C;IACD,MAAM,IAAIJ,KAAK,CAAE,2BAA4B,CAAC;EAC/C;EACA,MAAMK,QAAQ,GAAG,MAAMd,QAAQ,CAAE;IAAEe,IAAI,EAAG;EAAuB,CAAE,CAAC;EACpE,MAAMC,aAAa,GAAG,MAAMhB,QAAQ,CAAE;IACrCe,IAAI,EAAG,UAAUD,QAAQ,CAACG,SAAW,EAAC;IACtCC,IAAI,EAAE;MACLP,KAAK,EAAEN,aAAa,CAACM,KAAK;MAC1BC,OAAO,EAAEP,aAAa,CAACO,OAAO;MAC9BO,MAAM,EAAE,SAAS;MACjBC,IAAI,EACHf,aAAa,CAACQ,UAAU,KAAK,UAAU,GACpC;QAAEQ,sBAAsB,EAAEhB,aAAa,CAACQ;MAAW,CAAC,GACpDS;IACL,CAAC;IACDC,MAAM,EAAE;EACT,CAAE,CAAC;EAEH,OAAOP,aAAa;AACrB;AAEA,eAAed,mBAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/list-reusable-blocks",
3
- "version": "4.15.0",
3
+ "version": "4.17.0",
4
4
  "description": "Adding Export/Import support to the reusable blocks listing.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,11 +26,11 @@
26
26
  "module": "build-module/index.js",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/api-fetch": "^6.35.0",
30
- "@wordpress/components": "^25.4.0",
31
- "@wordpress/compose": "^6.15.0",
32
- "@wordpress/element": "^5.15.0",
33
- "@wordpress/i18n": "^4.38.0",
29
+ "@wordpress/api-fetch": "^6.37.0",
30
+ "@wordpress/components": "^25.6.0",
31
+ "@wordpress/compose": "^6.17.0",
32
+ "@wordpress/element": "^5.17.0",
33
+ "@wordpress/i18n": "^4.40.0",
34
34
  "change-case": "^4.1.2"
35
35
  },
36
36
  "peerDependencies": {
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "6f14d11ed4cb59df110a28ebaa23ecba95eb673a"
43
+ "gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
44
44
  }