From 5dde8f80c7aa70724b62bd5064d4662263d1cd4b Mon Sep 17 00:00:00 2001 From: Ankit Kumar Shah Date: Wed, 25 Jun 2025 13:32:18 +0530 Subject: [PATCH 01/13] Migrate `list-reusable-blocks` package to ts --- .../import-dropdown/{index.js => index.tsx} | 8 ++- .../import-form/{index.js => index.tsx} | 35 ++++++----- .../src/{index.js => index.tsx} | 24 +++++--- .../src/utils/{export.js => export.ts} | 39 ++++++++++-- .../src/utils/{file.js => file.ts} | 8 +-- .../src/utils/{import.js => import.ts} | 60 ++++++++++++++++--- packages/list-reusable-blocks/tsconfig.json | 12 ++++ tsconfig.json | 1 + 8 files changed, 146 insertions(+), 41 deletions(-) rename packages/list-reusable-blocks/src/components/import-dropdown/{index.js => index.tsx} (80%) rename packages/list-reusable-blocks/src/components/import-form/{index.js => index.tsx} (69%) rename packages/list-reusable-blocks/src/{index.js => index.tsx} (75%) rename packages/list-reusable-blocks/src/utils/{export.js => export.ts} (56%) rename packages/list-reusable-blocks/src/utils/{file.js => file.ts} (51%) rename packages/list-reusable-blocks/src/utils/{import.js => import.ts} (50%) create mode 100644 packages/list-reusable-blocks/tsconfig.json diff --git a/packages/list-reusable-blocks/src/components/import-dropdown/index.js b/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx similarity index 80% rename from packages/list-reusable-blocks/src/components/import-dropdown/index.js rename to packages/list-reusable-blocks/src/components/import-dropdown/index.tsx index fdad08f80d213c..09ee50a31815ff 100644 --- a/packages/list-reusable-blocks/src/components/import-dropdown/index.js +++ b/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx @@ -1,16 +1,20 @@ /** * WordPress dependencies */ +import { Button, Dropdown } from '@wordpress/components'; import { pipe } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; -import { Dropdown, Button } from '@wordpress/components'; /** * Internal dependencies */ import ImportForm from '../import-form'; -function ImportDropdown( { onUpload } ) { +interface ImportDropdownProps { + onUpload: ( data: any ) => void; +} + +function ImportDropdown( { onUpload }: ImportDropdownProps ) { return ( void; +} + +function ImportForm( { instanceId, onUpload }: ImportFormProps ) { const inputId = 'list-reusable-blocks-import-form-' + instanceId; - const formRef = useRef(); + const formRef = useRef< HTMLFormElement >( null ); const [ isLoading, setIsLoading ] = useState( false ); - const [ error, setError ] = useState( null ); - const [ file, setFile ] = useState( null ); + const [ error, setError ] = useState< string | null >( null ); + const [ file, setFile ] = useState< File | null >( null ); - const onChangeFile = ( event ) => { - setFile( event.target.files[ 0 ] ); + const onChangeFile = ( event: React.ChangeEvent< HTMLInputElement > ) => { + setFile( event.target.files?.[ 0 ] || null ); setError( null ); }; - const onSubmit = ( event ) => { + const onSubmit = ( event: React.FormEvent< HTMLFormElement > ) => { event.preventDefault(); if ( ! file ) { return; } - setIsLoading( { isLoading: true } ); + setIsLoading( true ); importReusableBlock( file ) - .then( ( reusableBlock ) => { - if ( ! formRef ) { + .then( ( reusableBlock: any ) => { + if ( ! formRef.current ) { return; } setIsLoading( false ); onUpload( reusableBlock ); } ) - .catch( ( errors ) => { - if ( ! formRef ) { + .catch( ( errors: any ) => { + if ( ! formRef.current ) { return; } - let uiMessage; + let uiMessage: string; switch ( errors.message ) { case 'Invalid JSON file': uiMessage = __( 'Invalid JSON file' ); diff --git a/packages/list-reusable-blocks/src/index.js b/packages/list-reusable-blocks/src/index.tsx similarity index 75% rename from packages/list-reusable-blocks/src/index.js rename to packages/list-reusable-blocks/src/index.tsx index f5cb411726963c..398197a39f5ff1 100644 --- a/packages/list-reusable-blocks/src/index.js +++ b/packages/list-reusable-blocks/src/index.tsx @@ -7,18 +7,23 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import exportReusableBlock from './utils/export'; import ImportDropdown from './components/import-dropdown'; +import exportReusableBlock from './utils/export'; // Setup Export Links. -document.body.addEventListener( 'click', ( event ) => { - if ( - ! event.target.classList.contains( 'wp-list-reusable-blocks__export' ) - ) { +document.body.addEventListener( 'click', ( event: MouseEvent ) => { + const target = event.target as HTMLElement; + + if ( ! target.classList.contains( 'wp-list-reusable-blocks__export' ) ) { return; } + event.preventDefault(); - exportReusableBlock( event.target.dataset.id ); + + const blockId = target.dataset.id; + if ( blockId ) { + exportReusableBlock( Number( blockId ) ); + } } ); // Setup Import Form. @@ -34,7 +39,7 @@ document.addEventListener( 'DOMContentLoaded', () => { notice.innerHTML = `

${ __( 'Pattern imported successfully!' ) }

`; const headerEnd = document.querySelector( '.wp-header-end' ); - if ( ! headerEnd ) { + if ( ! headerEnd || ! headerEnd.parentNode ) { return; } headerEnd.parentNode.insertBefore( notice, headerEnd ); @@ -42,6 +47,11 @@ document.addEventListener( 'DOMContentLoaded', () => { const container = document.createElement( 'div' ); container.className = 'list-reusable-blocks__container'; + + if ( ! button.parentNode ) { + return; + } + button.parentNode.insertBefore( container, button ); createRoot( container ).render( diff --git a/packages/list-reusable-blocks/src/utils/export.js b/packages/list-reusable-blocks/src/utils/export.ts similarity index 56% rename from packages/list-reusable-blocks/src/utils/export.js rename to packages/list-reusable-blocks/src/utils/export.ts index 4d7e76afcaa8fd..7ed089d437bc8f 100644 --- a/packages/list-reusable-blocks/src/utils/export.js +++ b/packages/list-reusable-blocks/src/utils/export.ts @@ -13,29 +13,58 @@ import apiFetch from '@wordpress/api-fetch'; */ import { downloadBlob } from '@wordpress/blob'; +interface PostType { + rest_base: string; + [ key: string ]: any; +} + +interface Post { + title: { + raw: string; + }; + content: { + raw: string; + }; + wp_pattern_sync_status: string; + [ key: string ]: any; +} + +interface ExportedBlock { + __file: string; + title: string; + content: string; + syncStatus: string; +} + /** * Export a reusable block as a JSON file. * - * @param {number} id + * @param id - The ID of the reusable block to export */ -async function exportReusableBlock( id ) { - const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } ); - const post = await apiFetch( { +async function exportReusableBlock( id: number ): Promise< void > { + const postType = await apiFetch< PostType >( { + path: `/wp/v2/types/wp_block`, + } ); + + const post = await apiFetch< Post >( { path: `/wp/v2/${ postType.rest_base }/${ id }?context=edit`, } ); + const title = post.title.raw; const content = post.content.raw; const syncStatus = post.wp_pattern_sync_status; + const fileContent = JSON.stringify( { __file: 'wp_block', title, content, syncStatus, - }, + } as ExportedBlock, null, 2 ); + const fileName = kebabCase( title ) + '.json'; downloadBlob( fileName, fileContent, 'application/json' ); diff --git a/packages/list-reusable-blocks/src/utils/file.js b/packages/list-reusable-blocks/src/utils/file.ts similarity index 51% rename from packages/list-reusable-blocks/src/utils/file.js rename to packages/list-reusable-blocks/src/utils/file.ts index d31e54ae41896a..71d4a03e41c6f1 100644 --- a/packages/list-reusable-blocks/src/utils/file.js +++ b/packages/list-reusable-blocks/src/utils/file.ts @@ -1,14 +1,14 @@ /** * Reads the textual content of the given file. * - * @param {File} file File. - * @return {Promise} Content of the file. + * @param file - File to read + * @return Promise that resolves to the content of the file */ -export function readTextFile( file ) { +export function readTextFile( file: File ): Promise< string > { const reader = new window.FileReader(); return new Promise( ( resolve ) => { reader.onload = () => { - resolve( reader.result ); + resolve( reader.result as string ); }; reader.readAsText( file ); } ); diff --git a/packages/list-reusable-blocks/src/utils/import.js b/packages/list-reusable-blocks/src/utils/import.ts similarity index 50% rename from packages/list-reusable-blocks/src/utils/import.js rename to packages/list-reusable-blocks/src/utils/import.ts index 432948ce6d6dbc..f87926789f5acc 100644 --- a/packages/list-reusable-blocks/src/utils/import.js +++ b/packages/list-reusable-blocks/src/utils/import.ts @@ -8,20 +8,60 @@ import apiFetch from '@wordpress/api-fetch'; */ import { readTextFile } from './file'; +interface PostType { + rest_base: string; + [ key: string ]: any; +} + +interface ParsedContent { + __file: string; + title: string; + content: string; + syncStatus?: string; + [ key: string ]: any; +} + +interface ReusableBlockMeta { + wp_pattern_sync_status?: string; +} + +interface ReusableBlockData { + title: string; + content: string; + status: string; + meta?: ReusableBlockMeta; +} + +interface ReusableBlock { + id: number; + title: { + raw: string; + rendered: string; + }; + content: { + raw: string; + rendered: string; + }; + status: string; + [ key: string ]: any; +} + /** * Import a reusable block from a JSON file. * - * @param {File} file File. - * @return {Promise} Promise returning the imported reusable block. + * @param file - File to import + * @return Promise returning the imported reusable block */ -async function importReusableBlock( file ) { +async function importReusableBlock( file: File ): Promise< ReusableBlock > { const fileContent = await readTextFile( file ); - let parsedContent; + let parsedContent: ParsedContent; + try { - parsedContent = JSON.parse( fileContent ); + parsedContent = JSON.parse( fileContent ) as ParsedContent; } catch ( e ) { throw new Error( 'Invalid JSON file' ); } + if ( parsedContent.__file !== 'wp_block' || ! parsedContent.title || @@ -33,8 +73,12 @@ async function importReusableBlock( file ) { ) { throw new Error( 'Invalid pattern JSON file' ); } - const postType = await apiFetch( { path: `/wp/v2/types/wp_block` } ); - const reusableBlock = await apiFetch( { + + const postType = await apiFetch< PostType >( { + path: `/wp/v2/types/wp_block`, + } ); + + const reusableBlock = await apiFetch< ReusableBlock >( { path: `/wp/v2/${ postType.rest_base }`, data: { title: parsedContent.title, @@ -44,7 +88,7 @@ async function importReusableBlock( file ) { parsedContent.syncStatus === 'unsynced' ? { wp_pattern_sync_status: parsedContent.syncStatus } : undefined, - }, + } as ReusableBlockData, method: 'POST', } ); diff --git a/packages/list-reusable-blocks/tsconfig.json b/packages/list-reusable-blocks/tsconfig.json new file mode 100644 index 00000000000000..aaca5103e679aa --- /dev/null +++ b/packages/list-reusable-blocks/tsconfig.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig.json", + "extends": "../../tsconfig.base.json", + "references": [ + { "path": "../i18n" }, + { "path": "../compose" }, + { "path": "../components" }, + { "path": "../api-fetch" }, + { "path": "../blob" }, + { "path": "../element" } + ] +} diff --git a/tsconfig.json b/tsconfig.json index d6bbcb27f0adb6..f3a2a2a73928b5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,6 +38,7 @@ { "path": "packages/is-shallow-equal" }, { "path": "packages/keycodes" }, { "path": "packages/lazy-import" }, + { "path": "packages/list-reusable-blocks" }, { "path": "packages/media-utils" }, { "path": "packages/notices" }, { "path": "packages/plugins" }, From bf1a5752c0a22dc43b4388ded7701cd40d803171 Mon Sep 17 00:00:00 2001 From: Ankit Kumar Shah Date: Thu, 26 Jun 2025 19:47:23 +0530 Subject: [PATCH 02/13] TypeScript: Define and import types for ImportDropdown and ImportForm components --- .../src/components/import-dropdown/index.tsx | 5 +- .../src/components/import-form/index.tsx | 6 +- .../list-reusable-blocks/src/utils/export.ts | 24 +----- .../list-reusable-blocks/src/utils/import.ts | 44 ++--------- .../list-reusable-blocks/src/utils/types.ts | 76 +++++++++++++++++++ 5 files changed, 85 insertions(+), 70 deletions(-) create mode 100644 packages/list-reusable-blocks/src/utils/types.ts diff --git a/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx b/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx index 09ee50a31815ff..ea3759e0345992 100644 --- a/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx +++ b/packages/list-reusable-blocks/src/components/import-dropdown/index.tsx @@ -8,12 +8,9 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ +import type { ImportDropdownProps } from '../../utils/types'; import ImportForm from '../import-form'; -interface ImportDropdownProps { - onUpload: ( data: any ) => void; -} - function ImportDropdown( { onUpload }: ImportDropdownProps ) { return ( void; -} +import type { ImportFormProps } from '../../utils/types'; function ImportForm( { instanceId, onUpload }: ImportFormProps ) { const inputId = 'list-reusable-blocks-import-form-' + instanceId; diff --git a/packages/list-reusable-blocks/src/utils/export.ts b/packages/list-reusable-blocks/src/utils/export.ts index 7ed089d437bc8f..b4752e3eef7768 100644 --- a/packages/list-reusable-blocks/src/utils/export.ts +++ b/packages/list-reusable-blocks/src/utils/export.ts @@ -12,29 +12,7 @@ import apiFetch from '@wordpress/api-fetch'; * Internal dependencies */ import { downloadBlob } from '@wordpress/blob'; - -interface PostType { - rest_base: string; - [ key: string ]: any; -} - -interface Post { - title: { - raw: string; - }; - content: { - raw: string; - }; - wp_pattern_sync_status: string; - [ key: string ]: any; -} - -interface ExportedBlock { - __file: string; - title: string; - content: string; - syncStatus: string; -} +import type { ExportedBlock, Post, PostType } from './types'; /** * Export a reusable block as a JSON file. diff --git a/packages/list-reusable-blocks/src/utils/import.ts b/packages/list-reusable-blocks/src/utils/import.ts index f87926789f5acc..535da53f2f5481 100644 --- a/packages/list-reusable-blocks/src/utils/import.ts +++ b/packages/list-reusable-blocks/src/utils/import.ts @@ -7,44 +7,12 @@ import apiFetch from '@wordpress/api-fetch'; * Internal dependencies */ import { readTextFile } from './file'; - -interface PostType { - rest_base: string; - [ key: string ]: any; -} - -interface ParsedContent { - __file: string; - title: string; - content: string; - syncStatus?: string; - [ key: string ]: any; -} - -interface ReusableBlockMeta { - wp_pattern_sync_status?: string; -} - -interface ReusableBlockData { - title: string; - content: string; - status: string; - meta?: ReusableBlockMeta; -} - -interface ReusableBlock { - id: number; - title: { - raw: string; - rendered: string; - }; - content: { - raw: string; - rendered: string; - }; - status: string; - [ key: string ]: any; -} +import type { + ParsedContent, + PostType, + ReusableBlock, + ReusableBlockData, +} from './types'; /** * Import a reusable block from a JSON file. diff --git a/packages/list-reusable-blocks/src/utils/types.ts b/packages/list-reusable-blocks/src/utils/types.ts new file mode 100644 index 00000000000000..afae1f7ef93dcb --- /dev/null +++ b/packages/list-reusable-blocks/src/utils/types.ts @@ -0,0 +1,76 @@ +interface ImportDropdownProps { + onUpload: ( data: any ) => void; +} + +interface ImportFormProps { + instanceId: string | number; + onUpload: ( reusableBlock: any ) => void; +} + +interface PostType { + rest_base: string; + [ key: string ]: any; +} + +interface Post { + title: { + raw: string; + }; + content: { + raw: string; + }; + wp_pattern_sync_status: string; + [ key: string ]: any; +} + +interface ExportedBlock { + __file: string; + title: string; + content: string; + syncStatus: string; +} + +interface ParsedContent { + __file: string; + title: string; + content: string; + syncStatus?: string; + [ key: string ]: any; +} + +interface ReusableBlockMeta { + wp_pattern_sync_status?: string; +} + +interface ReusableBlockData { + title: string; + content: string; + status: string; + meta?: ReusableBlockMeta; +} + +interface ReusableBlock { + id: number; + title: { + raw: string; + rendered: string; + }; + content: { + raw: string; + rendered: string; + }; + status: string; + [ key: string ]: any; +} + +export type { + ExportedBlock, + ImportDropdownProps, + ImportFormProps, + ParsedContent, + Post, + PostType, + ReusableBlock, + ReusableBlockData, + ReusableBlockMeta, +}; From d88ee65707311d6e565c9135ed4484ec5eb3700a Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Fri, 3 Apr 2026 18:31:00 +0530 Subject: [PATCH 03/13] fix: Type in `list-reusable-blocks` --- packages/list-reusable-blocks/src/utils/import.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/list-reusable-blocks/src/utils/import.ts b/packages/list-reusable-blocks/src/utils/import.ts index 535da53f2f5481..f64349f9efa819 100644 --- a/packages/list-reusable-blocks/src/utils/import.ts +++ b/packages/list-reusable-blocks/src/utils/import.ts @@ -26,7 +26,7 @@ async function importReusableBlock( file: File ): Promise< ReusableBlock > { try { parsedContent = JSON.parse( fileContent ) as ParsedContent; - } catch ( e ) { + } catch { throw new Error( 'Invalid JSON file' ); } From 2f33a445f4da5271837db4f3f35c28743313b248 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Fri, 3 Apr 2026 18:38:51 +0530 Subject: [PATCH 04/13] fix: Type in list-reusable-blocks --- packages/list-reusable-blocks/src/utils/types.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/list-reusable-blocks/src/utils/types.ts b/packages/list-reusable-blocks/src/utils/types.ts index afae1f7ef93dcb..34934eb1cb5005 100644 --- a/packages/list-reusable-blocks/src/utils/types.ts +++ b/packages/list-reusable-blocks/src/utils/types.ts @@ -1,15 +1,15 @@ interface ImportDropdownProps { - onUpload: ( data: any ) => void; + onUpload: ( data: ReusableBlock ) => void; } interface ImportFormProps { instanceId: string | number; - onUpload: ( reusableBlock: any ) => void; + onUpload: ( reusableBlock: ReusableBlock ) => void; } interface PostType { rest_base: string; - [ key: string ]: any; + [ key: string ]: unknown; } interface Post { @@ -20,7 +20,7 @@ interface Post { raw: string; }; wp_pattern_sync_status: string; - [ key: string ]: any; + [ key: string ]: unknown; } interface ExportedBlock { @@ -35,7 +35,7 @@ interface ParsedContent { title: string; content: string; syncStatus?: string; - [ key: string ]: any; + [ key: string ]: unknown; } interface ReusableBlockMeta { @@ -60,7 +60,7 @@ interface ReusableBlock { rendered: string; }; status: string; - [ key: string ]: any; + [ key: string ]: unknown; } export type { From 0df42b38a67e854093787559581f87c77d45c794 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Mon, 6 Apr 2026 12:27:12 +0530 Subject: [PATCH 05/13] chore: Re run test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 01d5097b9f6ccd..6b5d9d34588508 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,4 @@ You can join us in the `#core-editor` channel in Slack, see the [WordPress Slack WordPress is free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See [LICENSE.md](LICENSE.md) for complete license.

Code is Poetry.

+t From 9d455410134852595dd8bcebe21eb4a327a3512d Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Mon, 6 Apr 2026 12:28:02 +0530 Subject: [PATCH 06/13] chore: Fix README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6b5d9d34588508..01d5097b9f6ccd 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,3 @@ You can join us in the `#core-editor` channel in Slack, see the [WordPress Slack WordPress is free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See [LICENSE.md](LICENSE.md) for complete license.

Code is Poetry.

-t From 3d32343397caf64ba45b115f2148ad27f70c4b98 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Tue, 7 Apr 2026 16:43:48 +0530 Subject: [PATCH 07/13] fix: Update types and add core-data import in list-reusable-blocks --- packages/list-reusable-blocks/package.json | 3 +++ .../list-reusable-blocks/src/utils/types.ts | 21 +++++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/list-reusable-blocks/package.json b/packages/list-reusable-blocks/package.json index b34b568e3b455e..4f291c8160530c 100644 --- a/packages/list-reusable-blocks/package.json +++ b/packages/list-reusable-blocks/package.json @@ -52,6 +52,9 @@ "@wordpress/i18n": "file:../i18n", "change-case": "^4.1.2" }, + "devDependencies": { + "@wordpress/core-data": "file:../core-data" + }, "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" diff --git a/packages/list-reusable-blocks/src/utils/types.ts b/packages/list-reusable-blocks/src/utils/types.ts index 34934eb1cb5005..43f79c2508da15 100644 --- a/packages/list-reusable-blocks/src/utils/types.ts +++ b/packages/list-reusable-blocks/src/utils/types.ts @@ -1,3 +1,8 @@ +/** + * WordPress dependencies + */ +import type { Post as CorePost, Type } from '@wordpress/core-data'; + interface ImportDropdownProps { onUpload: ( data: ReusableBlock ) => void; } @@ -7,21 +12,9 @@ interface ImportFormProps { onUpload: ( reusableBlock: ReusableBlock ) => void; } -interface PostType { - rest_base: string; - [ key: string ]: unknown; -} +type PostType = Type; -interface Post { - title: { - raw: string; - }; - content: { - raw: string; - }; - wp_pattern_sync_status: string; - [ key: string ]: unknown; -} +type Post = CorePost & { wp_pattern_sync_status?: string }; interface ExportedBlock { __file: string; From d29e1952acbbe0ce74e7203af8a1c715729c398e Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Tue, 7 Apr 2026 17:02:43 +0530 Subject: [PATCH 08/13] fix: Add @wordpress/core-data as a devDependency in package-lock.json --- package-lock.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package-lock.json b/package-lock.json index 8ab1e6e1c17f04..30c538ae525fa1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60783,6 +60783,9 @@ "@wordpress/i18n": "file:../i18n", "change-case": "^4.1.2" }, + "devDependencies": { + "@wordpress/core-data": "file:../core-data" + }, "engines": { "node": ">=18.12.0", "npm": ">=8.19.2" From e061f7cfe54fca620261c0fd286fbad061eb474b Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Tue, 7 Apr 2026 17:58:43 +0530 Subject: [PATCH 09/13] fix: Update types for reusableBlock and error in ImportForm component --- .../src/components/import-form/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/list-reusable-blocks/src/components/import-form/index.tsx b/packages/list-reusable-blocks/src/components/import-form/index.tsx index 54dbfa3f777003..ef4c4e9f6375e3 100644 --- a/packages/list-reusable-blocks/src/components/import-form/index.tsx +++ b/packages/list-reusable-blocks/src/components/import-form/index.tsx @@ -10,7 +10,7 @@ import { __, _x } from '@wordpress/i18n'; * Internal dependencies */ import importReusableBlock from '../../utils/import'; -import type { ImportFormProps } from '../../utils/types'; +import type { ImportFormProps, ReusableBlock } from '../../utils/types'; function ImportForm( { instanceId, onUpload }: ImportFormProps ) { const inputId = 'list-reusable-blocks-import-form-' + instanceId; @@ -32,7 +32,7 @@ function ImportForm( { instanceId, onUpload }: ImportFormProps ) { } setIsLoading( true ); importReusableBlock( file ) - .then( ( reusableBlock: any ) => { + .then( ( reusableBlock: ReusableBlock ) => { if ( ! formRef.current ) { return; } @@ -40,7 +40,7 @@ function ImportForm( { instanceId, onUpload }: ImportFormProps ) { setIsLoading( false ); onUpload( reusableBlock ); } ) - .catch( ( errors: any ) => { + .catch( ( errors: Error ) => { if ( ! formRef.current ) { return; } From a9ec59dd31431b3180e402ffb7ff95804b6469b1 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Wed, 8 Apr 2026 13:36:46 +0530 Subject: [PATCH 10/13] fix: Refactor types and imports in list-reusable-blocks package --- packages/list-reusable-blocks/package.json | 4 +-- .../list-reusable-blocks/src/utils/export.ts | 4 +-- .../list-reusable-blocks/src/utils/import.ts | 4 +-- .../list-reusable-blocks/src/utils/types.ts | 30 ++++++------------- packages/list-reusable-blocks/tsconfig.json | 9 +++--- tsconfig.json | 2 +- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/packages/list-reusable-blocks/package.json b/packages/list-reusable-blocks/package.json index 4f291c8160530c..59caab28b3d0e9 100644 --- a/packages/list-reusable-blocks/package.json +++ b/packages/list-reusable-blocks/package.json @@ -48,13 +48,11 @@ "@wordpress/blob": "file:../blob", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", + "@wordpress/core-data": "file:../core-data", "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", "change-case": "^4.1.2" }, - "devDependencies": { - "@wordpress/core-data": "file:../core-data" - }, "peerDependencies": { "react": "^18.0.0", "react-dom": "^18.0.0" diff --git a/packages/list-reusable-blocks/src/utils/export.ts b/packages/list-reusable-blocks/src/utils/export.ts index b4752e3eef7768..e58dea3d89605c 100644 --- a/packages/list-reusable-blocks/src/utils/export.ts +++ b/packages/list-reusable-blocks/src/utils/export.ts @@ -12,7 +12,7 @@ import apiFetch from '@wordpress/api-fetch'; * Internal dependencies */ import { downloadBlob } from '@wordpress/blob'; -import type { ExportedBlock, Post, PostType } from './types'; +import type { Post, PostType } from './types'; /** * Export a reusable block as a JSON file. @@ -38,7 +38,7 @@ async function exportReusableBlock( id: number ): Promise< void > { title, content, syncStatus, - } as ExportedBlock, + }, null, 2 ); diff --git a/packages/list-reusable-blocks/src/utils/import.ts b/packages/list-reusable-blocks/src/utils/import.ts index f64349f9efa819..c85f9aa5e4361a 100644 --- a/packages/list-reusable-blocks/src/utils/import.ts +++ b/packages/list-reusable-blocks/src/utils/import.ts @@ -25,7 +25,7 @@ async function importReusableBlock( file: File ): Promise< ReusableBlock > { let parsedContent: ParsedContent; try { - parsedContent = JSON.parse( fileContent ) as ParsedContent; + parsedContent = JSON.parse( fileContent ); } catch { throw new Error( 'Invalid JSON file' ); } @@ -56,7 +56,7 @@ async function importReusableBlock( file: File ): Promise< ReusableBlock > { parsedContent.syncStatus === 'unsynced' ? { wp_pattern_sync_status: parsedContent.syncStatus } : undefined, - } as ReusableBlockData, + } satisfies ReusableBlockData, method: 'POST', } ); diff --git a/packages/list-reusable-blocks/src/utils/types.ts b/packages/list-reusable-blocks/src/utils/types.ts index 43f79c2508da15..d794da685420ba 100644 --- a/packages/list-reusable-blocks/src/utils/types.ts +++ b/packages/list-reusable-blocks/src/utils/types.ts @@ -3,27 +3,27 @@ */ import type { Post as CorePost, Type } from '@wordpress/core-data'; -interface ImportDropdownProps { +export interface ImportDropdownProps { onUpload: ( data: ReusableBlock ) => void; } -interface ImportFormProps { +export interface ImportFormProps { instanceId: string | number; onUpload: ( reusableBlock: ReusableBlock ) => void; } -type PostType = Type; +export type PostType = Type; -type Post = CorePost & { wp_pattern_sync_status?: string }; +export type Post = CorePost & { wp_pattern_sync_status?: string }; -interface ExportedBlock { +export interface ExportedBlock { __file: string; title: string; content: string; syncStatus: string; } -interface ParsedContent { +export interface ParsedContent { __file: string; title: string; content: string; @@ -31,18 +31,18 @@ interface ParsedContent { [ key: string ]: unknown; } -interface ReusableBlockMeta { +export interface ReusableBlockMeta { wp_pattern_sync_status?: string; } -interface ReusableBlockData { +export interface ReusableBlockData { title: string; content: string; status: string; meta?: ReusableBlockMeta; } -interface ReusableBlock { +export interface ReusableBlock { id: number; title: { raw: string; @@ -55,15 +55,3 @@ interface ReusableBlock { status: string; [ key: string ]: unknown; } - -export type { - ExportedBlock, - ImportDropdownProps, - ImportFormProps, - ParsedContent, - Post, - PostType, - ReusableBlock, - ReusableBlockData, - ReusableBlockMeta, -}; diff --git a/packages/list-reusable-blocks/tsconfig.json b/packages/list-reusable-blocks/tsconfig.json index aaca5103e679aa..8f14eee8dfb48a 100644 --- a/packages/list-reusable-blocks/tsconfig.json +++ b/packages/list-reusable-blocks/tsconfig.json @@ -2,11 +2,12 @@ "$schema": "https://json.schemastore.org/tsconfig.json", "extends": "../../tsconfig.base.json", "references": [ - { "path": "../i18n" }, - { "path": "../compose" }, - { "path": "../components" }, { "path": "../api-fetch" }, { "path": "../blob" }, - { "path": "../element" } + { "path": "../compose" }, + { "path": "../components" }, + { "path": "../core-data" }, + { "path": "../element" }, + { "path": "../i18n" } ] } diff --git a/tsconfig.json b/tsconfig.json index 85660eb64eb63d..05569fea216f1c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -49,9 +49,9 @@ { "path": "packages/latex-to-mathml" }, { "path": "packages/lazy-editor" }, { "path": "packages/lazy-import" }, + { "path": "packages/list-reusable-blocks" }, { "path": "packages/media-editor" }, { "path": "packages/media-fields" }, - { "path": "packages/list-reusable-blocks" }, { "path": "packages/media-utils" }, { "path": "packages/notices" }, { "path": "packages/plugins" }, From 3f6a89e97224e84375c17d18dae5cac6916f73fe Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Wed, 8 Apr 2026 13:40:16 +0530 Subject: [PATCH 11/13] fix: Move @wordpress/core-data to dependencies in package-lock.json --- package-lock.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 30c538ae525fa1..3c859e5f04bc47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60779,13 +60779,11 @@ "@wordpress/blob": "file:../blob", "@wordpress/components": "file:../components", "@wordpress/compose": "file:../compose", + "@wordpress/core-data": "file:../core-data", "@wordpress/element": "file:../element", "@wordpress/i18n": "file:../i18n", "change-case": "^4.1.2" }, - "devDependencies": { - "@wordpress/core-data": "file:../core-data" - }, "engines": { "node": ">=18.12.0", "npm": ">=8.19.2" From ea3fe78582ef69a961af84e3f05af6fab7a33a86 Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Mon, 13 Apr 2026 16:09:18 +0530 Subject: [PATCH 12/13] fix: Add types export and make syncStatus optional in ExportedBlock interface --- packages/list-reusable-blocks/package.json | 2 ++ packages/list-reusable-blocks/src/utils/types.ts | 7 ------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/list-reusable-blocks/package.json b/packages/list-reusable-blocks/package.json index 59caab28b3d0e9..e250b5455dd087 100644 --- a/packages/list-reusable-blocks/package.json +++ b/packages/list-reusable-blocks/package.json @@ -33,8 +33,10 @@ ], "main": "build/index.cjs", "module": "build-module/index.mjs", + "types": "build-types", "exports": { ".": { + "types": "./build-types/index.d.ts", "import": "./build-module/index.mjs", "require": "./build/index.cjs" }, diff --git a/packages/list-reusable-blocks/src/utils/types.ts b/packages/list-reusable-blocks/src/utils/types.ts index d794da685420ba..b076191326944b 100644 --- a/packages/list-reusable-blocks/src/utils/types.ts +++ b/packages/list-reusable-blocks/src/utils/types.ts @@ -16,13 +16,6 @@ export type PostType = Type; export type Post = CorePost & { wp_pattern_sync_status?: string }; -export interface ExportedBlock { - __file: string; - title: string; - content: string; - syncStatus: string; -} - export interface ParsedContent { __file: string; title: string; From f8b19ee4dcdcaca6dc8cef2efb8ed9e999f4d09b Mon Sep 17 00:00:00 2001 From: Infinite-Null Date: Mon, 13 Apr 2026 16:16:17 +0530 Subject: [PATCH 13/13] fix: Re-add types field in package.json for list-reusable-blocks --- packages/list-reusable-blocks/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/list-reusable-blocks/package.json b/packages/list-reusable-blocks/package.json index e250b5455dd087..a2f41f10a039ef 100644 --- a/packages/list-reusable-blocks/package.json +++ b/packages/list-reusable-blocks/package.json @@ -33,7 +33,6 @@ ], "main": "build/index.cjs", "module": "build-module/index.mjs", - "types": "build-types", "exports": { ".": { "types": "./build-types/index.d.ts", @@ -44,6 +43,7 @@ "./build-style/": "./build-style/" }, "wpScript": true, + "types": "build-types", "dependencies": { "@wordpress/api-fetch": "file:../api-fetch", "@wordpress/base-styles": "file:../base-styles",