From f11b3b7aaea5dc89485b07592bb0b63fd5fd53d3 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 2 Aug 2022 14:25:08 -0400 Subject: [PATCH 1/4] Add the types property to package.json. --- packages/blocks/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/blocks/package.json b/packages/blocks/package.json index b756451e81990..b1ae8e34068b7 100644 --- a/packages/blocks/package.json +++ b/packages/blocks/package.json @@ -24,6 +24,7 @@ "main": "build/index.js", "module": "build-module/index.js", "react-native": "src/index", + "types": "types", "sideEffects": [ "{src,build,build-module}/{index.js,store/index.js}" ], From 4ef74b9dad82acc6eb901411e731cc67879a7c0f Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 2 Aug 2022 14:25:46 -0400 Subject: [PATCH 2/4] types directory and add files to match structure of src. --- packages/blocks/types/api/categories.d.ts | 24 +++++++++++++++++++++++ packages/blocks/types/api/index.d.ts | 1 + packages/blocks/types/index.d.ts | 1 + 3 files changed, 26 insertions(+) create mode 100644 packages/blocks/types/api/categories.d.ts create mode 100644 packages/blocks/types/api/index.d.ts create mode 100644 packages/blocks/types/index.d.ts diff --git a/packages/blocks/types/api/categories.d.ts b/packages/blocks/types/api/categories.d.ts new file mode 100644 index 0000000000000..9d8dfa1712211 --- /dev/null +++ b/packages/blocks/types/api/categories.d.ts @@ -0,0 +1,24 @@ +import { Dashicon } from '@wordpress/components'; + +export interface WPBlockCategory { + slug: string; + title: string; + icon?: JSX.Element | Dashicon.Icon | null | undefined; +} +/** + * Returns all the block categories. + */ +export function getCategories(): WPBlockCategory[]; + +/** + * Sets the block categories. + */ +export function setCategories( categories: readonly WPBlockCategory[] ): void; + +/** + * Updates a category. + */ +export function updateCategory( + slug: string, + category: Partial< WPBlockCategory > +): void; diff --git a/packages/blocks/types/api/index.d.ts b/packages/blocks/types/api/index.d.ts new file mode 100644 index 0000000000000..a8c829f2b3f70 --- /dev/null +++ b/packages/blocks/types/api/index.d.ts @@ -0,0 +1 @@ +export * from './categories'; diff --git a/packages/blocks/types/index.d.ts b/packages/blocks/types/index.d.ts new file mode 100644 index 0000000000000..b1c13e734067a --- /dev/null +++ b/packages/blocks/types/index.d.ts @@ -0,0 +1 @@ +export * from './api'; From 76b9d51f3ede0d754f6d0df4348b1d1028dafd22 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 2 Aug 2022 14:26:17 -0400 Subject: [PATCH 3/4] Import WPBlockCategory type from types/api --- packages/blocks/src/api/categories.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blocks/src/api/categories.js b/packages/blocks/src/api/categories.js index 1a0f5a319b277..15a53e2b70b93 100644 --- a/packages/blocks/src/api/categories.js +++ b/packages/blocks/src/api/categories.js @@ -8,7 +8,7 @@ import { dispatch, select } from '@wordpress/data'; */ import { store as blocksStore } from '../store'; -/** @typedef {import('../store/reducer').WPBlockCategory} WPBlockCategory */ +/** @typedef {import('../../types/api/').WPBlockCategory} WPBlockCategory */ /** * Returns all the block categories. From 3cfaae0577af99be6a8e9ff40b66735b83688d56 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 30 Aug 2022 11:23:14 -0400 Subject: [PATCH 4/4] Remove types directory and move all types into categories.ts. --- package-lock.json | 5 ++-- packages/blocks/package.json | 2 +- .../src/api/{categories.js => categories.ts} | 16 +++++++++---- packages/blocks/types/api/categories.d.ts | 24 ------------------- packages/blocks/types/api/index.d.ts | 1 - packages/blocks/types/index.d.ts | 1 - 6 files changed, 16 insertions(+), 33 deletions(-) rename packages/blocks/src/api/{categories.js => categories.ts} (84%) delete mode 100644 packages/blocks/types/api/categories.d.ts delete mode 100644 packages/blocks/types/api/index.d.ts delete mode 100644 packages/blocks/types/index.d.ts diff --git a/package-lock.json b/package-lock.json index 77413a70d7913..090b671396589 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16644,6 +16644,7 @@ "@wordpress/autop": "file:packages/autop", "@wordpress/blob": "file:packages/blob", "@wordpress/block-serialization-default-parser": "file:packages/block-serialization-default-parser", + "@wordpress/components": "file:packages/components", "@wordpress/data": "file:packages/data", "@wordpress/deprecated": "file:packages/deprecated", "@wordpress/dom": "file:packages/dom", @@ -30558,7 +30559,7 @@ "css.escape": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz", - "integrity": "sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==", + "integrity": "sha1-QuJ9T6BK4y+TGktNQZH6nN3ul8s=", "dev": true }, "cssesc": { @@ -43407,7 +43408,7 @@ "lz-string": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz", - "integrity": "sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ==", + "integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=", "dev": true }, "macos-release": { diff --git a/packages/blocks/package.json b/packages/blocks/package.json index aef6d345c0de4..baf9702cf6a43 100644 --- a/packages/blocks/package.json +++ b/packages/blocks/package.json @@ -24,7 +24,6 @@ "main": "build/index.js", "module": "build-module/index.js", "react-native": "src/index", - "types": "types", "sideEffects": [ "{src,build,build-module}/{index.js,store/index.js}" ], @@ -33,6 +32,7 @@ "@wordpress/autop": "file:../autop", "@wordpress/blob": "file:../blob", "@wordpress/block-serialization-default-parser": "file:../block-serialization-default-parser", + "@wordpress/components": "file:../components", "@wordpress/data": "file:../data", "@wordpress/deprecated": "file:../deprecated", "@wordpress/dom": "file:../dom", diff --git a/packages/blocks/src/api/categories.js b/packages/blocks/src/api/categories.ts similarity index 84% rename from packages/blocks/src/api/categories.js rename to packages/blocks/src/api/categories.ts index c33e4ff922f9a..cf10847c47838 100644 --- a/packages/blocks/src/api/categories.js +++ b/packages/blocks/src/api/categories.ts @@ -2,13 +2,18 @@ * WordPress dependencies */ import { dispatch, select } from '@wordpress/data'; +import { Dashicon } from '@wordpress/components'; /** * Internal dependencies */ import { store as blocksStore } from '../store'; -/** @typedef {import('../../types/api/').WPBlockCategory} WPBlockCategory */ +export interface WPBlockCategory { + slug: string; + title: string; + icon?: JSX.Element | Dashicon.Icon | null | undefined; +} /** * Returns all the block categories. @@ -18,7 +23,7 @@ import { store as blocksStore } from '../store'; * * @return {WPBlockCategory[]} Block categories. */ -export function getCategories() { +export function getCategories(): WPBlockCategory[] { return select( blocksStore ).getCategories(); } @@ -57,7 +62,7 @@ export function getCategories() { * }; * ``` */ -export function setCategories( categories ) { +export function setCategories( categories: readonly WPBlockCategory[] ): void { dispatch( blocksStore ).setCategories( categories ); } @@ -87,6 +92,9 @@ export function setCategories( categories ) { * }; * ``` */ -export function updateCategory( slug, category ) { +export function updateCategory( + slug: string, + category: Partial< WPBlockCategory > +): void { dispatch( blocksStore ).updateCategory( slug, category ); } diff --git a/packages/blocks/types/api/categories.d.ts b/packages/blocks/types/api/categories.d.ts deleted file mode 100644 index 9d8dfa1712211..0000000000000 --- a/packages/blocks/types/api/categories.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Dashicon } from '@wordpress/components'; - -export interface WPBlockCategory { - slug: string; - title: string; - icon?: JSX.Element | Dashicon.Icon | null | undefined; -} -/** - * Returns all the block categories. - */ -export function getCategories(): WPBlockCategory[]; - -/** - * Sets the block categories. - */ -export function setCategories( categories: readonly WPBlockCategory[] ): void; - -/** - * Updates a category. - */ -export function updateCategory( - slug: string, - category: Partial< WPBlockCategory > -): void; diff --git a/packages/blocks/types/api/index.d.ts b/packages/blocks/types/api/index.d.ts deleted file mode 100644 index a8c829f2b3f70..0000000000000 --- a/packages/blocks/types/api/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './categories'; diff --git a/packages/blocks/types/index.d.ts b/packages/blocks/types/index.d.ts deleted file mode 100644 index b1c13e734067a..0000000000000 --- a/packages/blocks/types/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './api';