@wordpress/list-reusable-blocks 4.14.0 → 4.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/import-form/index.js +2 -2
- package/build/components/import-form/index.js.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/utils/export.js +3 -1
- package/build/utils/export.js.map +1 -1
- package/build/utils/import.js +6 -3
- 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/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/utils/export.js +3 -1
- package/build-module/utils/export.js.map +1 -1
- package/build-module/utils/import.js +6 -3
- 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/index.js +1 -3
- package/src/utils/export.js +2 -0
- package/src/utils/import.js +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -68,8 +68,8 @@ function ImportForm({
|
|
|
68
68
|
uiMessage = (0, _i18n.__)('Invalid JSON file');
|
|
69
69
|
break;
|
|
70
70
|
|
|
71
|
-
case 'Invalid
|
|
72
|
-
uiMessage = (0, _i18n.__)('Invalid
|
|
71
|
+
case 'Invalid Pattern JSON file':
|
|
72
|
+
uiMessage = (0, _i18n.__)('Invalid Pattern JSON file');
|
|
73
73
|
break;
|
|
74
74
|
|
|
75
75
|
default:
|
|
@@ -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,KAAF,EAASC,QAAT,IAAsB,uBAAU,IAAV,CAA5B;AACA,QAAM,CAAEC,IAAF,EAAQC,OAAR,IAAoB,uBAAU,IAAV,CAA1B;;AAEA,QAAMC,YAAY,GAAKC,KAAF,IAAa;AACjCF,IAAAA,OAAO,CAAEE,KAAK,CAACC,MAAN,CAAaC,KAAb,CAAoB,CAApB,CAAF,CAAP;AACAN,IAAAA,QAAQ,CAAE,IAAF,CAAR;AACA,GAHD;;AAKA,QAAMO,QAAQ,GAAKH,KAAF,IAAa;AAC7BA,IAAAA,KAAK,CAACI,cAAN;;AACA,QAAK,CAAEP,IAAP,EAAc;AACb;AACA;;AACDH,IAAAA,YAAY,CAAE;AAAED,MAAAA,SAAS,EAAE;AAAb,KAAF,CAAZ;AACA,yBAAqBI,IAArB,EACEQ,IADF,CACUC,aAAF,IAAqB;AAC3B,UAAK,CAAEd,OAAP,EAAiB;AAChB;AACA;;AAEDE,MAAAA,YAAY,CAAE,KAAF,CAAZ;AACAJ,MAAAA,QAAQ,CAAEgB,aAAF,CAAR;AACA,KARF,EASEC,KATF,CASWC,MAAF,IAAc;AACrB,UAAK,CAAEhB,OAAP,EAAiB;AAChB;AACA;;AAED,UAAIiB,SAAJ;;AACA,cAASD,MAAM,CAACE,OAAhB;AACC,aAAK,mBAAL;AACCD,UAAAA,SAAS,GAAG,cAAI,mBAAJ,CAAZ;AACA;;AACD,aAAK,
|
|
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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AACCA,UAAAA,SAAS,GAAG,cAAI,2BAAJ,CAAZ;AACA;;AACD;AACCA,UAAAA,SAAS,GAAG,cAAI,eAAJ,CAAZ;AARF;;AAWAf,MAAAA,YAAY,CAAE,KAAF,CAAZ;AACAE,MAAAA,QAAQ,CAAEa,SAAF,CAAR;AACA,KA5BF;AA6BA,GAnCD;;AAqCA,QAAME,cAAc,GAAG,MAAM;AAC5Bf,IAAAA,QAAQ,CAAE,IAAF,CAAR;AACA,GAFD;;AAIA,SACC;AACC,IAAA,SAAS,EAAC,kCADX;AAEC,IAAA,QAAQ,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"]}
|
package/build/index.js
CHANGED
|
@@ -37,7 +37,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
37
37
|
const showNotice = () => {
|
|
38
38
|
const notice = document.createElement('div');
|
|
39
39
|
notice.className = 'notice notice-success is-dismissible';
|
|
40
|
-
notice.innerHTML = `<p>${(0, _i18n.__)('
|
|
40
|
+
notice.innerHTML = `<p>${(0, _i18n.__)('Pattern imported successfully!')}</p>`;
|
|
41
41
|
const headerEnd = document.querySelector('.wp-header-end');
|
|
42
42
|
|
|
43
43
|
if (!headerEnd) {
|
package/build/index.js.map
CHANGED
|
@@ -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;AACA;AACA;AAIA;AACAA,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;AACA,uBAAqBJ,KAAK,CAACC,MAAN,CAAaI,OAAb,CAAqBC,EAA1C;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,MAAM,
|
|
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;AACA;AACA;AAIA;AACAA,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;AACA,uBAAqBJ,KAAK,CAACC,MAAN,CAAaI,OAAb,CAAqBC,EAA1C;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,MAAM,cAAI,gCAAJ,CAAwC,MAAlE;AAEA,UAAMC,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;AACA,2BAAYU,SAAZ,EAAwBC,MAAxB,CACC,4BAAC,uBAAD;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"]}
|
package/build/utils/export.js
CHANGED
|
@@ -39,10 +39,12 @@ async function exportReusableBlock(id) {
|
|
|
39
39
|
});
|
|
40
40
|
const title = post.title.raw;
|
|
41
41
|
const content = post.content.raw;
|
|
42
|
+
const syncStatus = post.wp_pattern_sync_status;
|
|
42
43
|
const fileContent = JSON.stringify({
|
|
43
44
|
__file: 'wp_block',
|
|
44
45
|
title,
|
|
45
|
-
content
|
|
46
|
+
content,
|
|
47
|
+
syncStatus
|
|
46
48
|
}, null, 2);
|
|
47
49
|
const fileName = (0, _changeCase.paramCase)(title) + '.json';
|
|
48
50
|
(0, _file.download)(fileName, fileContent, 'application/json');
|
|
@@ -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","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,WAAW,GAAGC,IAAI,CAACC,SAAL,CACnB;AACCC,IAAAA,MAAM,EAAE,UADT;
|
|
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"]}
|
package/build/utils/import.js
CHANGED
|
@@ -35,8 +35,8 @@ async function importReusableBlock(file) {
|
|
|
35
35
|
throw new Error('Invalid JSON file');
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string') {
|
|
39
|
-
throw new Error('Invalid
|
|
38
|
+
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
|
|
39
|
+
throw new Error('Invalid Pattern JSON file');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
const postType = await (0, _apiFetch.default)({
|
|
@@ -47,7 +47,10 @@ async function importReusableBlock(file) {
|
|
|
47
47
|
data: {
|
|
48
48
|
title: parsedContent.title,
|
|
49
49
|
content: parsedContent.content,
|
|
50
|
-
status: 'publish'
|
|
50
|
+
status: 'publish',
|
|
51
|
+
meta: parsedContent.syncStatus === 'unsynced' ? {
|
|
52
|
+
wp_pattern_sync_status: parsedContent.syncStatus
|
|
53
|
+
} : undefined
|
|
51
54
|
},
|
|
52
55
|
method: 'POST'
|
|
53
56
|
});
|
|
@@ -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","postType","path","reusableBlock","rest_base","data","status","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,
|
|
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"]}
|
|
@@ -57,8 +57,8 @@ function ImportForm({
|
|
|
57
57
|
uiMessage = __('Invalid JSON file');
|
|
58
58
|
break;
|
|
59
59
|
|
|
60
|
-
case 'Invalid
|
|
61
|
-
uiMessage = __('Invalid
|
|
60
|
+
case 'Invalid Pattern JSON file':
|
|
61
|
+
uiMessage = __('Invalid Pattern JSON file');
|
|
62
62
|
break;
|
|
63
63
|
|
|
64
64
|
default:
|
|
@@ -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,QA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,SAAJ;;AACA,cAASD,MAAM,CAACE,OAAhB;AACC,aAAK,mBAAL;AACCD,UAAAA,SAAS,GAAG1B,EAAE,CAAE,mBAAF,CAAd;AACA;;AACD,aAAK,
|
|
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,CAAoB,CAApB,CAAF,CAAP;AACAN,IAAAA,QAAQ,CAAE,IAAF,CAAR;AACA,GAHD;;AAKA,QAAMO,QAAQ,GAAKH,KAAF,IAAa;AAC7BA,IAAAA,KAAK,CAACI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Q,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"]}
|
package/build-module/index.js
CHANGED
|
@@ -31,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
31
31
|
const showNotice = () => {
|
|
32
32
|
const notice = document.createElement('div');
|
|
33
33
|
notice.className = 'notice notice-success is-dismissible';
|
|
34
|
-
notice.innerHTML = `<p>${__('
|
|
34
|
+
notice.innerHTML = `<p>${__('Pattern imported successfully!')}</p>`;
|
|
35
35
|
const headerEnd = document.querySelector('.wp-header-end');
|
|
36
36
|
|
|
37
37
|
if (!headerEnd) {
|
|
@@ -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,
|
|
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"]}
|
|
@@ -27,10 +27,12 @@ async function exportReusableBlock(id) {
|
|
|
27
27
|
});
|
|
28
28
|
const title = post.title.raw;
|
|
29
29
|
const content = post.content.raw;
|
|
30
|
+
const syncStatus = post.wp_pattern_sync_status;
|
|
30
31
|
const fileContent = JSON.stringify({
|
|
31
32
|
__file: 'wp_block',
|
|
32
33
|
title,
|
|
33
|
-
content
|
|
34
|
+
content,
|
|
35
|
+
syncStatus
|
|
34
36
|
}, null, 2);
|
|
35
37
|
const fileName = kebabCase(title) + '.json';
|
|
36
38
|
download(fileName, fileContent, 'application/json');
|
|
@@ -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","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,WAAW,GAAGC,IAAI,CAACC,SAAL,CACnB;AACCC,IAAAA,MAAM,EAAE,UADT;
|
|
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"]}
|
|
@@ -24,8 +24,8 @@ async function importReusableBlock(file) {
|
|
|
24
24
|
throw new Error('Invalid JSON file');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string') {
|
|
28
|
-
throw new Error('Invalid
|
|
27
|
+
if (parsedContent.__file !== 'wp_block' || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== 'string' || typeof parsedContent.content !== 'string' || parsedContent.syncStatus && typeof parsedContent.syncStatus !== 'string') {
|
|
28
|
+
throw new Error('Invalid Pattern JSON file');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const postType = await apiFetch({
|
|
@@ -36,7 +36,10 @@ async function importReusableBlock(file) {
|
|
|
36
36
|
data: {
|
|
37
37
|
title: parsedContent.title,
|
|
38
38
|
content: parsedContent.content,
|
|
39
|
-
status: 'publish'
|
|
39
|
+
status: 'publish',
|
|
40
|
+
meta: parsedContent.syncStatus === 'unsynced' ? {
|
|
41
|
+
wp_pattern_sync_status: parsedContent.syncStatus
|
|
42
|
+
} : undefined
|
|
40
43
|
},
|
|
41
44
|
method: 'POST'
|
|
42
45
|
});
|
|
@@ -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","postType","path","reusableBlock","rest_base","data","status","method"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,QAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeC,mBAAf,CAAoCC,IAApC,EAA2C;AAC1C,QAAMC,WAAW,GAAG,MAAMH,YAAY,CAAEE,IAAF,CAAtC;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,
|
|
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","reusableBlock","rest_base","data","status","meta","wp_pattern_sync_status","undefined","method"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,QAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeC,mBAAf,CAAoCC,IAApC,EAA2C;AAC1C,QAAMC,WAAW,GAAG,MAAMH,YAAY,CAAEE,IAAF,CAAtC;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,MAAMd,QAAQ,CAAE;AAAEe,IAAAA,IAAI,EAAG;AAAT,GAAF,CAA/B;AACA,QAAMC,aAAa,GAAG,MAAMhB,QAAQ,CAAE;AACrCe,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,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/list-reusable-blocks",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.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.
|
|
30
|
-
"@wordpress/components": "^25.
|
|
31
|
-
"@wordpress/compose": "^6.
|
|
32
|
-
"@wordpress/element": "^5.
|
|
33
|
-
"@wordpress/i18n": "^4.
|
|
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",
|
|
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": "6f14d11ed4cb59df110a28ebaa23ecba95eb673a"
|
|
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/index.js
CHANGED
|
@@ -31,9 +31,7 @@ document.addEventListener( 'DOMContentLoaded', () => {
|
|
|
31
31
|
const showNotice = () => {
|
|
32
32
|
const notice = document.createElement( 'div' );
|
|
33
33
|
notice.className = 'notice notice-success is-dismissible';
|
|
34
|
-
notice.innerHTML = `<p>${ __(
|
|
35
|
-
'Reusable block imported successfully!'
|
|
36
|
-
) }</p>`;
|
|
34
|
+
notice.innerHTML = `<p>${ __( 'Pattern imported successfully!' ) }</p>`;
|
|
37
35
|
|
|
38
36
|
const headerEnd = document.querySelector( '.wp-header-end' );
|
|
39
37
|
if ( ! headerEnd ) {
|
package/src/utils/export.js
CHANGED
|
@@ -25,11 +25,13 @@ async function exportReusableBlock( id ) {
|
|
|
25
25
|
} );
|
|
26
26
|
const title = post.title.raw;
|
|
27
27
|
const content = post.content.raw;
|
|
28
|
+
const syncStatus = post.wp_pattern_sync_status;
|
|
28
29
|
const fileContent = JSON.stringify(
|
|
29
30
|
{
|
|
30
31
|
__file: 'wp_block',
|
|
31
32
|
title,
|
|
32
33
|
content,
|
|
34
|
+
syncStatus,
|
|
33
35
|
},
|
|
34
36
|
null,
|
|
35
37
|
2
|
package/src/utils/import.js
CHANGED
|
@@ -27,9 +27,11 @@ async function importReusableBlock( file ) {
|
|
|
27
27
|
! parsedContent.title ||
|
|
28
28
|
! parsedContent.content ||
|
|
29
29
|
typeof parsedContent.title !== 'string' ||
|
|
30
|
-
typeof parsedContent.content !== 'string'
|
|
30
|
+
typeof parsedContent.content !== 'string' ||
|
|
31
|
+
( parsedContent.syncStatus &&
|
|
32
|
+
typeof parsedContent.syncStatus !== 'string' )
|
|
31
33
|
) {
|
|
32
|
-
throw new Error( 'Invalid
|
|
34
|
+
throw new Error( 'Invalid Pattern JSON file' );
|
|
33
35
|
}
|
|
34
36
|
const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } );
|
|
35
37
|
const reusableBlock = await apiFetch( {
|
|
@@ -38,6 +40,10 @@ async function importReusableBlock( file ) {
|
|
|
38
40
|
title: parsedContent.title,
|
|
39
41
|
content: parsedContent.content,
|
|
40
42
|
status: 'publish',
|
|
43
|
+
meta:
|
|
44
|
+
parsedContent.syncStatus === 'unsynced'
|
|
45
|
+
? { wp_pattern_sync_status: parsedContent.syncStatus }
|
|
46
|
+
: undefined,
|
|
41
47
|
},
|
|
42
48
|
method: 'POST',
|
|
43
49
|
} );
|