From 2865901b4d32062ab470cadc38337a6537a98159 Mon Sep 17 00:00:00 2001 From: Chris Zarate Date: Wed, 4 Dec 2024 13:36:24 -0500 Subject: [PATCH] Update @wordpress/blocks types and remove expected error (#230) --- package-lock.json | 7 ++-- package.json | 1 + src/blocks/remote-data-container/index.ts | 3 +- .../registerBlockBindingsSource.ts | 36 ------------------- types/wordpress__blocks/index.d.ts | 32 ++++++++++++++++- 5 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 src/types/expected-errors/registerBlockBindingsSource.ts diff --git a/package-lock.json b/package-lock.json index 83da7213..595ac0ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@testing-library/jest-dom": "6.6.3", "@testing-library/react": "16.0.1", "@types/wordpress__block-editor": "11.5.15", + "@types/wordpress__blocks": "12.5.15", "@types/wordpress__editor": "14.3.1", "@vitest/coverage-v8": "2.1.2", "@wordpress/api-fetch": "7.10.0", @@ -5857,9 +5858,9 @@ } }, "node_modules/@types/wordpress__blocks": { - "version": "12.5.14", - "resolved": "https://registry.npmjs.org/@types/wordpress__blocks/-/wordpress__blocks-12.5.14.tgz", - "integrity": "sha512-eXEnCRKYu+39KEJ/OYpoYxWTATxI+eJHd+meMGZ14hYydFtxA0Y8M7zJT8D8f4klBo8wINLvP7zrO8vYrjWjPQ==", + "version": "12.5.15", + "resolved": "https://registry.npmjs.org/@types/wordpress__blocks/-/wordpress__blocks-12.5.15.tgz", + "integrity": "sha512-kJ8kviVTXOld7gjmiY1JnzBQfwtKaRCxifnJ6z7lkcacjtY0H57IiIGTTu/XfhGCzbXXssimpAZyAK3xsLYNnA==", "dev": true, "dependencies": { "@types/react": "*", diff --git a/package.json b/package.json index 2d3747f4..454555cf 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "@testing-library/jest-dom": "6.6.3", "@testing-library/react": "16.0.1", "@types/wordpress__block-editor": "11.5.15", + "@types/wordpress__blocks": "12.5.15", "@types/wordpress__editor": "14.3.1", "@vitest/coverage-v8": "2.1.2", "@wordpress/api-fetch": "7.10.0", diff --git a/src/blocks/remote-data-container/index.ts b/src/blocks/remote-data-container/index.ts index 2deb752c..b0b5a4fc 100644 --- a/src/blocks/remote-data-container/index.ts +++ b/src/blocks/remote-data-container/index.ts @@ -1,4 +1,4 @@ -import { registerBlockType } from '@wordpress/blocks'; +import { registerBlockBindingsSource, registerBlockType } from '@wordpress/blocks'; import { addFilter } from '@wordpress/hooks'; import { registerFormatType } from '@wordpress/rich-text'; @@ -8,7 +8,6 @@ import { Edit } from '@/blocks/remote-data-container/edit'; import { addUsesContext } from '@/blocks/remote-data-container/filters/addUsesContext'; import { withBlockBindingShim } from '@/blocks/remote-data-container/filters/withBlockBinding'; import { Save } from '@/blocks/remote-data-container/save'; -import { registerBlockBindingsSource } from '@/types/expected-errors/registerBlockBindingsSource'; import { getBlocksConfig } from '@/utils/localized-block-data'; import './style.scss'; diff --git a/src/types/expected-errors/registerBlockBindingsSource.ts b/src/types/expected-errors/registerBlockBindingsSource.ts deleted file mode 100644 index 692d1bec..00000000 --- a/src/types/expected-errors/registerBlockBindingsSource.ts +++ /dev/null @@ -1,36 +0,0 @@ -// @ts-expect-error Temporary registerBlockBindingsSource type error workaround for WordPress 6.7 -import { registerBlockBindingsSource as originalRegisterBlockBindingsSource } from '@wordpress/blocks'; - -import type { - BlockEditorStoreActions, - BlockEditorStoreSelectors, - BlockEditorStoreDescriptor, -} from '@wordpress/block-editor'; - -interface GetValuesPayload< Context, Values > { - bindings: Values; - clientId: string; - context: Context; - select: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreSelectors; -} - -interface SetValuesPayload< Context, Values > extends GetValuesPayload< Context, Values > { - dispatch: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreActions; - values: Values; -} - -export interface BlockBindingsSource< Context = Record< string, unknown >, Values = unknown > { - canUserEditValue?: ( payload: GetValuesPayload< Context, Values > ) => boolean; - getValues?: ( payload: GetValuesPayload< Context, Values > ) => Values; - label?: string; - name: string; - setValues?: ( payload: SetValuesPayload< Context, Values > ) => void; - usesContext?: string[]; -} - -export function registerBlockBindingsSource< Context, Values >( - source: BlockBindingsSource< Context, Values > -): void { - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - originalRegisterBlockBindingsSource( source ); -} diff --git a/types/wordpress__blocks/index.d.ts b/types/wordpress__blocks/index.d.ts index 412006c6..64d479d0 100644 --- a/types/wordpress__blocks/index.d.ts +++ b/types/wordpress__blocks/index.d.ts @@ -1,11 +1,41 @@ -import { BlockEditProps as BlockEditPropsOriginal } from '@wordpress/blocks'; +import type { BlockEditProps as BlockEditPropsOriginal } from '@wordpress/blocks'; +import type { + BlockEditorStoreActions, + BlockEditorStoreSelectors, + BlockEditorStoreDescriptor, +} from '@wordpress/block-editor'; /** * The types provided by @wordpress/blocks are incomplete. */ +interface GetValuesPayload< Context, Values > { + bindings: Values; + clientId: string; + context: Context; + select: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreSelectors; +} + +interface SetValuesPayload< Context, Values > extends GetValuesPayload< Context, Values > { + dispatch: ( store: BlockEditorStoreDescriptor ) => BlockEditorStoreActions; + values: Values; +} + declare module '@wordpress/blocks' { interface BlockEditProps< T extends Record< string, any > > extends BlockEditPropsOriginal< T > { name: string; } + + interface BlockBindingsSource< Context = Record< string, unknown >, Values = unknown > { + canUserEditValue?: ( payload: GetValuesPayload< Context, Values > ) => boolean; + getValues?: ( payload: GetValuesPayload< Context, Values > ) => Values; + label?: string; + name: string; + setValues?: ( payload: SetValuesPayload< Context, Values > ) => void; + usesContext?: string[]; + } + + function registerBlockBindingsSource< Context, Values >( + source: BlockBindingsSource< Context, Values > + ): void; }