@wordpress/list-reusable-blocks 4.19.1 → 4.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/import-form/index.js +2 -2
- package/build/components/import-form/index.js.map +1 -1
- package/build/utils/import.js +1 -1
- package/build/utils/import.js.map +1 -1
- package/build-module/components/import-form/index.js +2 -2
- package/build-module/components/import-form/index.js.map +1 -1
- package/build-module/utils/import.js +1 -1
- package/build-module/utils/import.js.map +1 -1
- package/package.json +7 -7
- package/src/components/import-form/index.js +2 -2
- package/src/utils/import.js +1 -1
|
@@ -54,8 +54,8 @@ function ImportForm({
|
|
|
54
54
|
case 'Invalid JSON file':
|
|
55
55
|
uiMessage = (0, _i18n.__)('Invalid JSON file');
|
|
56
56
|
break;
|
|
57
|
-
case 'Invalid
|
|
58
|
-
uiMessage = (0, _i18n.__)('Invalid
|
|
57
|
+
case 'Invalid pattern JSON file':
|
|
58
|
+
uiMessage = (0, _i18n.__)('Invalid pattern JSON file');
|
|
59
59
|
break;
|
|
60
60
|
default:
|
|
61
61
|
uiMessage = (0, _i18n.__)('Unknown error');
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;AACA;;AAMA;AACA;AACA;;AAGA,SAASM,UAAUA,CAAE;EAAEC,UAAU;EAAEC;AAAS,CAAC,EAAG;EAC/C,MAAMC,OAAO,GAAG,mCAAmC,GAAGF,UAAU;EAEhE,MAAMG,OAAO,GAAG,IAAAC,eAAM,EAAC,CAAC;EACxB,MAAM,CAAEC,SAAS,EAAEC,YAAY,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EACrD,MAAM,CAAEC,KAAK,EAAEC,QAAQ,CAAE,GAAG,IAAAF,iBAAQ,EAAE,IAAK,CAAC;EAC5C,MAAM,CAAEG,IAAI,EAAEC,OAAO,CAAE,GAAG,IAAAJ,iBAAQ,EAAE,IAAK,CAAC;EAE1C,MAAMK,YAAY,GAAKC,KAAK,IAAM;IACjCF,OAAO,CAAEE,KAAK,CAACC,MAAM,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MN,cAAc,CAAC;EAAG,GACvDlB,KACK,CACR,EACD,IAAAhB,QAAA,CAAAmC,aAAA;IACCM,OAAO,EAAG/B,OAAS;IACnB0B,SAAS,EAAC;EAAyC,GAEjD,IAAAH,QAAE,EAAE,MAAO,CACP,CAAC,EACR,IAAAjC,QAAA,CAAAmC,aAAA;IAAOO,EAAE,EAAGhC,OAAS;IAACiC,IAAI,EAAC,MAAM;IAACC,QAAQ,EAAGxB;EAAc,CAAE,CAAC,EAC9D,IAAApB,QAAA,CAAAmC,aAAA,EAAC/B,WAAA,CAAAyC,MAAM;IACNF,IAAI,EAAC,QAAQ;IACbG,MAAM,EAAGjC,SAAW;IACpBkC,QAAQ,EAAG,CAAE7B,IAAI,IAAIL,SAAW;IAChCmC,OAAO,EAAC,WAAW;IACnBZ,SAAS,EAAC;EAA0C,GAElD,IAAAa,QAAE,EAAE,QAAQ,EAAE,cAAe,CACxB,CACH,CAAC;AAET;AAAC,IAAAC,QAAA,GAEc,IAAAC,uBAAc,EAAE5C,UAAW,CAAC;AAAA6C,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
package/build/utils/import.js
CHANGED
|
@@ -30,7 +30,7 @@ async function importReusableBlock(file) {
|
|
|
30
30
|
throw new Error('Invalid JSON file');
|
|
31
31
|
}
|
|
32
32
|
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
|
|
33
|
-
throw new Error('Invalid
|
|
33
|
+
throw new Error('Invalid pattern JSON file');
|
|
34
34
|
}
|
|
35
35
|
const postType = await (0, _apiFetch.default)({
|
|
36
36
|
path: `/wp/v2/types/wp_block`
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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"}
|
|
@@ -47,8 +47,8 @@ function ImportForm({
|
|
|
47
47
|
case 'Invalid JSON file':
|
|
48
48
|
uiMessage = __('Invalid JSON file');
|
|
49
49
|
break;
|
|
50
|
-
case 'Invalid
|
|
51
|
-
uiMessage = __('Invalid
|
|
50
|
+
case 'Invalid pattern JSON file':
|
|
51
|
+
uiMessage = __('Invalid pattern JSON file');
|
|
52
52
|
break;
|
|
53
53
|
default:
|
|
54
54
|
uiMessage = __('Unknown error');
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,MAAM,CAAC,CAAC;EACxB,MAAM,CAAEY,SAAS,EAAEC,YAAY,CAAE,GAAGd,QAAQ,CAAE,KAAM,CAAC;EACrD,MAAM,CAAEe,KAAK,EAAEC,QAAQ,CAAE,GAAGhB,Q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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"}
|
|
@@ -23,7 +23,7 @@ async function importReusableBlock(file) {
|
|
|
23
23
|
throw new Error('Invalid JSON file');
|
|
24
24
|
}
|
|
25
25
|
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
|
|
26
|
-
throw new Error('Invalid
|
|
26
|
+
throw new Error('Invalid pattern JSON file');
|
|
27
27
|
}
|
|
28
28
|
const postType = await apiFetch({
|
|
29
29
|
path: `/wp/v2/types/wp_block`
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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.19.
|
|
3
|
+
"version": "4.19.2",
|
|
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.39.
|
|
30
|
-
"@wordpress/components": "^25.8.
|
|
31
|
-
"@wordpress/compose": "^6.19.
|
|
32
|
-
"@wordpress/element": "^5.19.
|
|
33
|
-
"@wordpress/i18n": "^4.42.
|
|
29
|
+
"@wordpress/api-fetch": "^6.39.2",
|
|
30
|
+
"@wordpress/components": "^25.8.2",
|
|
31
|
+
"@wordpress/compose": "^6.19.2",
|
|
32
|
+
"@wordpress/element": "^5.19.2",
|
|
33
|
+
"@wordpress/i18n": "^4.42.2",
|
|
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": "
|
|
43
|
+
"gitHead": "5d2e3d07cc97af8090fc32c1e5d5013a2967e752"
|
|
44
44
|
}
|
|
@@ -49,8 +49,8 @@ function ImportForm( { instanceId, onUpload } ) {
|
|
|
49
49
|
case 'Invalid JSON file':
|
|
50
50
|
uiMessage = __( 'Invalid JSON file' );
|
|
51
51
|
break;
|
|
52
|
-
case 'Invalid
|
|
53
|
-
uiMessage = __( 'Invalid
|
|
52
|
+
case 'Invalid pattern JSON file':
|
|
53
|
+
uiMessage = __( 'Invalid pattern JSON file' );
|
|
54
54
|
break;
|
|
55
55
|
default:
|
|
56
56
|
uiMessage = __( 'Unknown error' );
|
package/src/utils/import.js
CHANGED
|
@@ -31,7 +31,7 @@ async function importReusableBlock( file ) {
|
|
|
31
31
|
( parsedContent.syncStatus &&
|
|
32
32
|
typeof parsedContent.syncStatus !== 'string' )
|
|
33
33
|
) {
|
|
34
|
-
throw new Error( 'Invalid
|
|
34
|
+
throw new Error( 'Invalid pattern JSON file' );
|
|
35
35
|
}
|
|
36
36
|
const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );
|
|
37
37
|
const reusableBlock = await apiFetch( {
|