Skip to content

Commit b8ea87d

Browse files
blocks: Convert blocks package to TypeScript (#76312)
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org> Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
1 parent c05ddf2 commit b8ea87d

103 files changed

Lines changed: 3807 additions & 2025 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/reference-guides/data/data-core-blocks.md‎

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Namespace: `core/blocks`.
44

55
## Selectors
66

7-
<!-- START TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.js) -->
7+
<!-- START TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.ts) -->
88

99
### getActiveBlockVariation
1010

@@ -45,14 +45,14 @@ const ExampleComponent = () => {
4545

4646
_Parameters_
4747

48-
- _state_ `Object`: Data state.
49-
- _blockName_ `string`: Name of block (example: “core/columns”).
50-
- _attributes_ `Object`: Block attributes used to determine active variation.
51-
- _scope_ `[WPBlockVariationScope]`: Block variation scope name.
48+
- _state_ `BlockStoreState`: Data state.
49+
- _blockName_ `string`: Name of block (example: "core/columns").
50+
- _attributes_ `Record< string, unknown >`: Block attributes used to determine active variation.
51+
- _scope_ `BlockVariationScope`: Block variation scope name.
5252

5353
_Returns_
5454

55-
- `(WPBlockVariation|undefined)`: Active block variation.
55+
- `BlockVariation | undefined`: Active block variation.
5656

5757
### getBlockStyles
5858

@@ -83,12 +83,12 @@ const ExampleComponent = () => {
8383

8484
_Parameters_
8585

86-
- _state_ `Object`: Data state.
86+
- _state_ `BlockStoreState`: Data state.
8787
- _name_ `string`: Block type name.
8888

8989
_Returns_
9090

91-
- `Array?`: Block Styles.
91+
- `BlockStyle[]`: Block Styles.
9292

9393
### getBlockSupport
9494

@@ -121,14 +121,14 @@ const ExampleComponent = () => {
121121

122122
_Parameters_
123123

124-
- _state_ `Object`: Data state.
125-
- _nameOrType_ `(string|Object)`: Block name or type object
126-
- _feature_ `Array|string`: Feature to retrieve
127-
- _defaultSupports_ `*`: Default value to return if not explicitly defined
124+
- _state_ `BlockStoreState`: Data state.
125+
- _nameOrType_ `string | BlockType`: Block name or type object
126+
- _feature_ `string | string[]`: Feature to retrieve
127+
- _defaultSupports_ `unknown`: Default value to return if not explicitly defined
128128

129129
_Returns_
130130

131-
- `?*`: Block support value
131+
- `unknown`: Block support value
132132

133133
### getBlockType
134134

@@ -167,12 +167,12 @@ const ExampleComponent = () => {
167167

168168
_Parameters_
169169

170-
- _state_ `Object`: Data state.
170+
- _state_ `BlockStoreState`: Data state.
171171
- _name_ `string`: Block type name.
172172

173173
_Returns_
174174

175-
- `?Object`: Block Type.
175+
- `BlockType | undefined`: Block Type.
176176

177177
### getBlockTypes
178178

@@ -202,11 +202,11 @@ const ExampleComponent = () => {
202202

203203
_Parameters_
204204

205-
- _state_ `Object`: Data state.
205+
- _state_ `BlockStoreState`: Data state.
206206

207207
_Returns_
208208

209-
- `Array`: Block Types.
209+
- `BlockType[]`: Block Types.
210210

211211
### getBlockVariations
212212

@@ -238,13 +238,13 @@ const ExampleComponent = () => {
238238

239239
_Parameters_
240240

241-
- _state_ `Object`: Data state.
241+
- _state_ `BlockStoreState`: Data state.
242242
- _blockName_ `string`: Block type name.
243-
- _scope_ `[WPBlockVariationScope]`: Block variation scope name.
243+
- _scope_ `BlockVariationScope`: Block variation scope name.
244244

245245
_Returns_
246246

247-
- `(WPBlockVariation[]|void)`: Block variations.
247+
- `BlockVariation[] | undefined`: Block variations.
248248

249249
### getCategories
250250

@@ -274,11 +274,11 @@ const ExampleComponent = () => {
274274

275275
_Parameters_
276276

277-
- _state_ `Object`: Data state.
277+
- _state_ `BlockStoreState`: Data state.
278278

279279
_Returns_
280280

281-
- `WPBlockCategory[]`: Categories list.
281+
- `BlockCategory[]`: Categories list.
282282

283283
### getChildBlockNames
284284

@@ -310,12 +310,12 @@ const ExampleComponent = () => {
310310

311311
_Parameters_
312312

313-
- _state_ `Object`: Data state.
313+
- _state_ `BlockStoreState`: Data state.
314314
- _blockName_ `string`: Block type name.
315315

316316
_Returns_
317317

318-
- `Array`: Array of child block names.
318+
- `string[]`: Array of child block names.
319319

320320
### getCollections
321321

@@ -346,11 +346,11 @@ const ExampleComponent = () => {
346346

347347
_Parameters_
348348

349-
- _state_ `Object`: Data state.
349+
- _state_ `BlockStoreState`: Data state.
350350

351351
_Returns_
352352

353-
- `Object`: Collections list.
353+
- `Record< string, BlockCollection >`: Collections list.
354354

355355
### getDefaultBlockName
356356

@@ -381,11 +381,11 @@ const ExampleComponent = () => {
381381

382382
_Parameters_
383383

384-
- _state_ `Object`: Data state.
384+
- _state_ `BlockStoreState`: Data state.
385385

386386
_Returns_
387387

388-
- `?string`: Default block name.
388+
- `string | null`: Default block name.
389389

390390
### getDefaultBlockVariation
391391

@@ -420,13 +420,13 @@ const ExampleComponent = () => {
420420

421421
_Parameters_
422422

423-
- _state_ `Object`: Data state.
423+
- _state_ `BlockStoreState`: Data state.
424424
- _blockName_ `string`: Block type name.
425-
- _scope_ `[WPBlockVariationScope]`: Block variation scope name.
425+
- _scope_ `BlockVariationScope`: Block variation scope name.
426426

427427
_Returns_
428428

429-
- `?WPBlockVariation`: The default block variation.
429+
- `BlockVariation | undefined`: The default block variation.
430430

431431
### getFreeformFallbackBlockName
432432

@@ -460,11 +460,11 @@ const ExampleComponent = () => {
460460

461461
_Parameters_
462462

463-
- _state_ `Object`: Data state.
463+
- _state_ `BlockStoreState`: Data state.
464464

465465
_Returns_
466466

467-
- `?string`: Name of the block for handling non-block content.
467+
- `string | null`: Name of the block for handling non-block content.
468468

469469
### getGroupingBlockName
470470

@@ -498,11 +498,11 @@ const ExampleComponent = () => {
498498

499499
_Parameters_
500500

501-
- _state_ `Object`: Data state.
501+
- _state_ `BlockStoreState`: Data state.
502502

503503
_Returns_
504504

505-
- `?string`: Name of the block for handling the grouping of blocks.
505+
- `string | null`: Name of the block for handling the grouping of blocks.
506506

507507
### getUnregisteredFallbackBlockName
508508

@@ -536,11 +536,11 @@ const ExampleComponent = () => {
536536

537537
_Parameters_
538538

539-
- _state_ `Object`: Data state.
539+
- _state_ `BlockStoreState`: Data state.
540540

541541
_Returns_
542542

543-
- `?string`: Name of the block for handling unregistered blocks.
543+
- `string | null`: Name of the block for handling unregistered blocks.
544544

545545
### hasBlockSupport
546546

@@ -572,10 +572,10 @@ const ExampleComponent = () => {
572572

573573
_Parameters_
574574

575-
- _state_ `Object`: Data state.
576-
- _nameOrType_ `(string|Object)`: Block name or type object.
577-
- _feature_ `string`: Feature to test.
578-
- _defaultSupports_ `boolean`: Whether feature is supported by default if not explicitly defined.
575+
- _state_ `BlockStoreState`: Data state.
576+
- _nameOrType_ `string | BlockType`: Block name or type object.
577+
- _feature_ `string | string[]`: Feature to test.
578+
- _defaultSupports_ `unknown`: Whether feature is supported by default if not explicitly defined.
579579

580580
_Returns_
581581

@@ -611,7 +611,7 @@ const ExampleComponent = () => {
611611

612612
_Parameters_
613613

614-
- _state_ `Object`: Data state.
614+
- _state_ `BlockStoreState`: Data state.
615615
- _blockName_ `string`: Block type name.
616616

617617
_Returns_
@@ -653,7 +653,7 @@ const ExampleComponent = () => {
653653

654654
_Parameters_
655655

656-
- _state_ `Object`: Data state.
656+
- _state_ `BlockStoreState`: Data state.
657657
- _blockName_ `string`: Block type name.
658658

659659
_Returns_
@@ -696,26 +696,26 @@ const ExampleComponent = () => {
696696

697697
_Parameters_
698698

699-
- _state_ `Object`: Blocks state.
700-
- _nameOrType_ `(string|Object)`: Block name or type object.
699+
- _state_ `BlockStoreState`: Blocks state.
700+
- _nameOrType_ `string | BlockType`: Block name or type object.
701701
- _searchTerm_ `string`: Search term by which to filter.
702702

703703
_Returns_
704704

705-
- `Object[]`: Whether block type matches search term.
705+
- `boolean`: Whether block type matches search term.
706706

707-
<!-- END TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.js) -->
707+
<!-- END TOKEN(Autogenerated selectors|../../../packages/blocks/src/store/selectors.ts) -->
708708

709709
## Actions
710710

711711
The actions in this package shouldn't be used directly. Instead, use the functions listed in the public API [here](/packages/blocks/README.md)
712712

713-
<!-- START TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) -->
713+
<!-- START TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.ts) -->
714714

715715
### reapplyBlockTypeFilters
716716

717717
Signals that all block types should be computed again. It uses stored unprocessed block types and all the most recent list of registered filters.
718718

719719
It addresses the issue where third party block filters get registered after third party blocks. A sample sequence: 1. Filter A. 2. Block B. 3. Block C. 4. Filter D. 5. Filter E. 6. Block F. 7. Filter G. In this scenario some filters would not get applied for all blocks because they are registered too late.
720720

721-
<!-- END TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) -->
721+
<!-- END TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.ts) -->

‎packages/block-editor/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{ "path": "../a11y" },
66
{ "path": "../block-serialization-default-parser" },
77
{ "path": "../blob" },
8+
{ "path": "../blocks" },
89
{ "path": "../components" },
910
{ "path": "../compose" },
1011
{ "path": "../data" },

‎packages/block-library/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
{ "path": "../autop" },
1212
{ "path": "../blob" },
1313
{ "path": "../block-editor" },
14+
{ "path": "../blocks" },
1415
{ "path": "../components" },
1516
{ "path": "../compose" },
1617
{ "path": "../core-data" },

0 commit comments

Comments
 (0)