@wordpress/list-reusable-blocks 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,28 @@
1
- // packages/list-reusable-blocks/src/utils/export.ts
2
- import { paramCase as kebabCase } from "change-case";
1
+ import { paramCase } from "change-case";
3
2
  import removeAccents from "remove-accents";
4
3
  import apiFetch from "@wordpress/api-fetch";
5
4
  import { downloadBlob } from "@wordpress/blob";
5
+ // packages/list-reusable-blocks/src/utils/export.ts
6
+ /**
7
+ * Export a reusable block as a JSON file.
8
+ *
9
+ * @param id - The ID of the reusable block to export
10
+ */
6
11
  async function exportReusableBlock(id) {
7
- const postType = await apiFetch({
8
- path: `/wp/v2/types/wp_block`
9
- });
10
- const post = await apiFetch({
11
- path: `/wp/v2/${postType.rest_base}/${id}?context=edit`
12
- });
13
- const title = post.title.raw;
14
- const content = post.content.raw;
15
- const syncStatus = post.wp_pattern_sync_status;
16
- const fileContent = JSON.stringify(
17
- {
18
- __file: "wp_block",
19
- title,
20
- content,
21
- syncStatus
22
- },
23
- null,
24
- 2
25
- );
26
- const fileName = kebabCase(removeAccents(title)) + ".json";
27
- downloadBlob(fileName, fileContent, "application/json");
12
+ const postType = await apiFetch({ path: `/wp/v2/types/wp_block` });
13
+ const post = await apiFetch({ path: `/wp/v2/${postType.rest_base}/${id}?context=edit` });
14
+ const title = post.title.raw;
15
+ const content = post.content.raw;
16
+ const syncStatus = post.wp_pattern_sync_status;
17
+ const fileContent = JSON.stringify({
18
+ __file: "wp_block",
19
+ title,
20
+ content,
21
+ syncStatus
22
+ }, null, 2);
23
+ const fileName = paramCase(removeAccents(title)) + ".json";
24
+ downloadBlob(fileName, fileContent, "application/json");
28
25
  }
29
- var export_default = exportReusableBlock;
30
- export {
31
- export_default as default
32
- };
33
- //# sourceMappingURL=export.mjs.map
26
+ export { exportReusableBlock as default };
27
+
28
+ //# sourceMappingURL=export.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/export.ts"],
4
- "sourcesContent": ["import { paramCase as kebabCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport apiFetch from '@wordpress/api-fetch';\nimport { downloadBlob } from '@wordpress/blob';\nimport type { Post, PostType } from './types';\n\n/**\n * Export a reusable block as a JSON file.\n *\n * @param id - The ID of the reusable block to export\n */\nasync function exportReusableBlock( id: number ): Promise< void > {\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst post = await apiFetch< Post >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`,\n\t} );\n\n\tconst title = post.title.raw;\n\tconst content = post.content.raw;\n\tconst syncStatus = post.wp_pattern_sync_status;\n\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\n\tconst fileName = kebabCase( removeAccents( title ) ) + '.json';\n\n\tdownloadBlob( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],
5
- "mappings": ";AAAA,SAAS,aAAa,iBAAiB;AACvC,OAAO,mBAAmB;AAC1B,OAAO,cAAc;AACrB,SAAS,oBAAoB;AAQ7B,eAAe,oBAAqB,IAA8B;AACjE,QAAM,WAAW,MAAM,SAAsB;AAAA,IAC5C,MAAM;AAAA,EACP,CAAE;AAEF,QAAM,OAAO,MAAM,SAAkB;AAAA,IACpC,MAAM,UAAW,SAAS,SAAU,IAAK,EAAG;AAAA,EAC7C,CAAE;AAEF,QAAM,QAAQ,KAAK,MAAM;AACzB,QAAM,UAAU,KAAK,QAAQ;AAC7B,QAAM,aAAa,KAAK;AAExB,QAAM,cAAc,KAAK;AAAA,IACxB;AAAA,MACC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,QAAM,WAAW,UAAW,cAAe,KAAM,CAAE,IAAI;AAEvD,eAAc,UAAU,aAAa,kBAAmB;AACzD;AAEA,IAAO,iBAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"export.mjs","names":["kebabCase"],"sources":["../../src/utils/export.ts"],"sourcesContent":["import { paramCase as kebabCase } from 'change-case';\nimport removeAccents from 'remove-accents';\nimport apiFetch from '@wordpress/api-fetch';\nimport { downloadBlob } from '@wordpress/blob';\nimport type { Post, PostType } from './types';\n\n/**\n * Export a reusable block as a JSON file.\n *\n * @param id - The ID of the reusable block to export\n */\nasync function exportReusableBlock( id: number ): Promise< void > {\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst post = await apiFetch< Post >( {\n\t\tpath: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`,\n\t} );\n\n\tconst title = post.title.raw;\n\tconst content = post.content.raw;\n\tconst syncStatus = post.wp_pattern_sync_status;\n\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\n\tconst fileName = kebabCase( removeAccents( title ) ) + '.json';\n\n\tdownloadBlob( fileName, fileContent, 'application/json' );\n}\n\nexport default exportReusableBlock;\n"],"mappings":";;;;;;;;;;AAWA,eAAe,oBAAqB,IAA8B;CACjE,MAAM,WAAW,MAAM,SAAsB,EAC5C,MAAM,wBACP,CAAE;CAEF,MAAM,OAAO,MAAM,SAAkB,EACpC,MAAM,UAAW,SAAS,UAAW,GAAI,GAAI,eAC9C,CAAE;CAEF,MAAM,QAAQ,KAAK,MAAM;CACzB,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,aAAa,KAAK;CAExB,MAAM,cAAc,KAAK,UACxB;EACC,QAAQ;EACR;EACA;EACA;CACD,GACA,MACA,CACD;CAEA,MAAM,WAAWA,UAAW,cAAe,KAAM,CAAE,IAAI;CAEvD,aAAc,UAAU,aAAa,kBAAmB;AACzD"}
@@ -1,14 +1,19 @@
1
1
  // packages/list-reusable-blocks/src/utils/file.ts
2
+ /**
3
+ * Reads the textual content of the given file.
4
+ *
5
+ * @param file - File to read
6
+ * @return Promise that resolves to the content of the file
7
+ */
2
8
  function readTextFile(file) {
3
- const reader = new window.FileReader();
4
- return new Promise((resolve) => {
5
- reader.onload = () => {
6
- resolve(reader.result);
7
- };
8
- reader.readAsText(file);
9
- });
9
+ const reader = new window.FileReader();
10
+ return new Promise((resolve) => {
11
+ reader.onload = () => {
12
+ resolve(reader.result);
13
+ };
14
+ reader.readAsText(file);
15
+ });
10
16
  }
11
- export {
12
- readTextFile
13
- };
14
- //# sourceMappingURL=file.mjs.map
17
+ export { readTextFile };
18
+
19
+ //# sourceMappingURL=file.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/file.ts"],
4
- "sourcesContent": ["/**\n * Reads the textual content of the given file.\n *\n * @param file - File to read\n * @return Promise that resolves to the content of the file\n */\nexport function readTextFile( file: File ): Promise< string > {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result as string );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],
5
- "mappings": ";AAMO,SAAS,aAAc,MAAgC;AAC7D,QAAM,SAAS,IAAI,OAAO,WAAW;AACrC,SAAO,IAAI,QAAS,CAAE,YAAa;AAClC,WAAO,SAAS,MAAM;AACrB,cAAS,OAAO,MAAiB;AAAA,IAClC;AACA,WAAO,WAAY,IAAK;AAAA,EACzB,CAAE;AACH;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"file.mjs","names":[],"sources":["../../src/utils/file.ts"],"sourcesContent":["/**\n * Reads the textual content of the given file.\n *\n * @param file - File to read\n * @return Promise that resolves to the content of the file\n */\nexport function readTextFile( file: File ): Promise< string > {\n\tconst reader = new window.FileReader();\n\treturn new Promise( ( resolve ) => {\n\t\treader.onload = () => {\n\t\t\tresolve( reader.result as string );\n\t\t};\n\t\treader.readAsText( file );\n\t} );\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,aAAc,MAAgC;CAC7D,MAAM,SAAS,IAAI,OAAO,WAAW;CACrC,OAAO,IAAI,SAAW,YAAa;EAClC,OAAO,eAAe;GACrB,QAAS,OAAO,MAAiB;EAClC;EACA,OAAO,WAAY,IAAK;CACzB,CAAE;AACH"}
@@ -1,34 +1,33 @@
1
- // packages/list-reusable-blocks/src/utils/import.ts
2
1
  import apiFetch from "@wordpress/api-fetch";
3
2
  import { readTextFile } from "./file.mjs";
3
+ // packages/list-reusable-blocks/src/utils/import.ts
4
+ /**
5
+ * Import a reusable block from a JSON file.
6
+ *
7
+ * @param file - File to import
8
+ * @return Promise returning the imported reusable block
9
+ */
4
10
  async function importReusableBlock(file) {
5
- const fileContent = await readTextFile(file);
6
- let parsedContent;
7
- try {
8
- parsedContent = JSON.parse(fileContent);
9
- } catch {
10
- throw new Error("Invalid JSON file");
11
- }
12
- if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") {
13
- throw new Error("Invalid pattern JSON file");
14
- }
15
- const postType = await apiFetch({
16
- path: `/wp/v2/types/wp_block`
17
- });
18
- const reusableBlock = await apiFetch({
19
- path: `/wp/v2/${postType.rest_base}`,
20
- data: {
21
- title: parsedContent.title,
22
- content: parsedContent.content,
23
- status: "publish",
24
- meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
25
- },
26
- method: "POST"
27
- });
28
- return reusableBlock;
11
+ const fileContent = await readTextFile(file);
12
+ let parsedContent;
13
+ try {
14
+ parsedContent = JSON.parse(fileContent);
15
+ } catch {
16
+ throw new Error("Invalid JSON file");
17
+ }
18
+ if (parsedContent.__file !== "wp_block" || !parsedContent.title || !parsedContent.content || typeof parsedContent.title !== "string" || typeof parsedContent.content !== "string" || parsedContent.syncStatus && typeof parsedContent.syncStatus !== "string") throw new Error("Invalid pattern JSON file");
19
+ const postType = await apiFetch({ path: `/wp/v2/types/wp_block` });
20
+ return await apiFetch({
21
+ path: `/wp/v2/${postType.rest_base}`,
22
+ data: {
23
+ title: parsedContent.title,
24
+ content: parsedContent.content,
25
+ status: "publish",
26
+ meta: parsedContent.syncStatus === "unsynced" ? { wp_pattern_sync_status: parsedContent.syncStatus } : void 0
27
+ },
28
+ method: "POST"
29
+ });
29
30
  }
30
- var import_default = importReusableBlock;
31
- export {
32
- import_default as default
33
- };
34
- //# sourceMappingURL=import.mjs.map
31
+ export { importReusableBlock as default };
32
+
33
+ //# sourceMappingURL=import.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/import.ts"],
4
- "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\nimport { readTextFile } from './file';\nimport type {\n\tParsedContent,\n\tPostType,\n\tReusableBlock,\n\tReusableBlockData,\n} from './types';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param file - File to import\n * @return Promise returning the imported reusable block\n */\nasync function importReusableBlock( file: File ): Promise< ReusableBlock > {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent: ParsedContent;\n\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\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\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst reusableBlock = await apiFetch< ReusableBlock >( {\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} satisfies ReusableBlockData,\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],
5
- "mappings": ";AAAA,OAAO,cAAc;AACrB,SAAS,oBAAoB;AAc7B,eAAe,oBAAqB,MAAuC;AAC1E,QAAM,cAAc,MAAM,aAAc,IAAK;AAC7C,MAAI;AAEJ,MAAI;AACH,oBAAgB,KAAK,MAAO,WAAY;AAAA,EACzC,QAAQ;AACP,UAAM,IAAI,MAAO,mBAAoB;AAAA,EACtC;AAEA,MACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UACpC;AACD,UAAM,IAAI,MAAO,2BAA4B;AAAA,EAC9C;AAEA,QAAM,WAAW,MAAM,SAAsB;AAAA,IAC5C,MAAM;AAAA,EACP,CAAE;AAEF,QAAM,gBAAgB,MAAM,SAA2B;AAAA,IACtD,MAAM,UAAW,SAAS,SAAU;AAAA,IACpC,MAAM;AAAA,MACL,OAAO,cAAc;AAAA,MACrB,SAAS,cAAc;AAAA,MACvB,QAAQ;AAAA,MACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,EACT,CAAE;AAEF,SAAO;AACR;AAEA,IAAO,iBAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"import.mjs","names":[],"sources":["../../src/utils/import.ts"],"sourcesContent":["import apiFetch from '@wordpress/api-fetch';\nimport { readTextFile } from './file';\nimport type {\n\tParsedContent,\n\tPostType,\n\tReusableBlock,\n\tReusableBlockData,\n} from './types';\n\n/**\n * Import a reusable block from a JSON file.\n *\n * @param file - File to import\n * @return Promise returning the imported reusable block\n */\nasync function importReusableBlock( file: File ): Promise< ReusableBlock > {\n\tconst fileContent = await readTextFile( file );\n\tlet parsedContent: ParsedContent;\n\n\ttry {\n\t\tparsedContent = JSON.parse( fileContent );\n\t} catch {\n\t\tthrow new Error( 'Invalid JSON file' );\n\t}\n\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\n\tconst postType = await apiFetch< PostType >( {\n\t\tpath: `/wp/v2/types/wp_block`,\n\t} );\n\n\tconst reusableBlock = await apiFetch< ReusableBlock >( {\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} satisfies ReusableBlockData,\n\t\tmethod: 'POST',\n\t} );\n\n\treturn reusableBlock;\n}\n\nexport default importReusableBlock;\n"],"mappings":";;;;;;;;;AAeA,eAAe,oBAAqB,MAAuC;CAC1E,MAAM,cAAc,MAAM,aAAc,IAAK;CAC7C,IAAI;CAEJ,IAAI;EACH,gBAAgB,KAAK,MAAO,WAAY;CACzC,QAAQ;EACP,MAAM,IAAI,MAAO,mBAAoB;CACtC;CAEA,IACC,cAAc,WAAW,cACzB,CAAE,cAAc,SAChB,CAAE,cAAc,WAChB,OAAO,cAAc,UAAU,YAC/B,OAAO,cAAc,YAAY,YAC/B,cAAc,cACf,OAAO,cAAc,eAAe,UAErC,MAAM,IAAI,MAAO,2BAA4B;CAG9C,MAAM,WAAW,MAAM,SAAsB,EAC5C,MAAM,wBACP,CAAE;CAgBF,OAAO,MAdqB,SAA2B;EACtD,MAAM,UAAW,SAAS;EAC1B,MAAM;GACL,OAAO,cAAc;GACrB,SAAS,cAAc;GACvB,QAAQ;GACR,MACC,cAAc,eAAe,aAC1B,EAAE,wBAAwB,cAAc,WAAW,IACnD,KAAA;EACL;EACA,QAAQ;CACT,CAAE;AAGH"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/list-reusable-blocks",
3
- "version": "6.0.0",
3
+ "version": "6.1.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",
@@ -42,14 +42,14 @@
42
42
  "wpScript": true,
43
43
  "types": "build-types",
44
44
  "dependencies": {
45
- "@wordpress/api-fetch": "^8.0.0",
46
- "@wordpress/base-styles": "^14.0.0",
47
- "@wordpress/blob": "^5.0.0",
48
- "@wordpress/components": "^43.0.0",
49
- "@wordpress/compose": "^9.0.0",
50
- "@wordpress/core-data": "^9.0.0",
51
- "@wordpress/element": "^10.0.0",
52
- "@wordpress/i18n": "^7.0.0",
45
+ "@wordpress/api-fetch": "^8.1.0",
46
+ "@wordpress/base-styles": "^15.0.0",
47
+ "@wordpress/blob": "^5.1.0",
48
+ "@wordpress/components": "^44.0.0",
49
+ "@wordpress/compose": "^9.1.0",
50
+ "@wordpress/core-data": "^9.1.0",
51
+ "@wordpress/element": "^10.1.0",
52
+ "@wordpress/i18n": "^7.1.0",
53
53
  "change-case": "^4.1.2",
54
54
  "remove-accents": "^0.5.0"
55
55
  },
@@ -66,5 +66,5 @@
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  },
69
- "gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
69
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
70
70
  }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/types.ts"],
4
- "sourcesContent": ["import type { Post as CorePost, Type } from '@wordpress/core-data';\n\nexport interface ImportDropdownProps {\n\tonUpload: ( data: ReusableBlock ) => void;\n}\n\nexport interface ImportFormProps {\n\tinstanceId: string | number;\n\tonUpload: ( reusableBlock: ReusableBlock ) => void;\n}\n\nexport type PostType = Type;\n\nexport type Post = CorePost & { wp_pattern_sync_status?: string };\n\nexport interface ParsedContent {\n\t__file: string;\n\ttitle: string;\n\tcontent: string;\n\tsyncStatus?: string;\n\t[ key: string ]: unknown;\n}\n\nexport interface ReusableBlockMeta {\n\twp_pattern_sync_status?: string;\n}\n\nexport interface ReusableBlockData {\n\ttitle: string;\n\tcontent: string;\n\tstatus: string;\n\tmeta?: ReusableBlockMeta;\n}\n\nexport interface ReusableBlock {\n\tid: number;\n\ttitle: {\n\t\traw: string;\n\t\trendered: string;\n\t};\n\tcontent: {\n\t\traw: string;\n\t\trendered: string;\n\t};\n\tstatus: string;\n\t[ key: string ]: unknown;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
7
- }