@@ -16,7 +16,6 @@ import { SectionBlock } from '../blocks/layout/SectionBlock';
16
16
import { Markdown } from '../blocks/text/Markdown' ;
17
17
import { PlainText } from '../blocks/text/PlainText' ;
18
18
import { isNotNull } from '../isNotNull' ;
19
- import { Permutation } from '../utils/Permutation' ;
20
19
import { BlockContext } from './BlockContext' ;
21
20
import { BlockRenderers } from './BlockRenderers' ;
22
21
import { Conditions } from './Conditions' ;
@@ -30,12 +29,14 @@ export abstract class SurfaceRenderer<
30
29
B extends RenderableLayoutBlock = RenderableLayoutBlock
31
30
> implements BlockRenderers < T >
32
31
{
33
- public constructor (
34
- protected readonly allowedLayoutBlockTypes : Permutation < B [ 'type' ] >
35
- ) { }
32
+ protected readonly allowedLayoutBlockTypes : Set < B [ 'type' ] > ;
33
+
34
+ public constructor ( allowedLayoutBlockTypes : B [ 'type' ] [ ] ) {
35
+ this . allowedLayoutBlockTypes = new Set ( allowedLayoutBlockTypes ) ;
36
+ }
36
37
37
38
private isAllowedLayoutBlock = ( block : Block ) : block is B =>
38
- ( this . allowedLayoutBlockTypes as string [ ] ) ?. includes ( block . type ) ?? true ;
39
+ this . allowedLayoutBlockTypes . has ( block . type as B [ 'type' ] ) ;
39
40
40
41
public render ( blocks : readonly Block [ ] , conditions ?: Conditions ) : T [ ] {
41
42
if ( ! Array . isArray ( blocks ) ) {
@@ -62,9 +63,7 @@ export abstract class SurfaceRenderer<
62
63
index : number
63
64
) : T | null {
64
65
if (
65
- ( this . allowedLayoutBlockTypes as string [ ] ) ?. includes (
66
- LayoutBlockType . ACTIONS
67
- ) === false &&
66
+ this . allowedLayoutBlockTypes . has ( LayoutBlockType . ACTIONS ) === false &&
68
67
! isActionsBlockElement ( block )
69
68
) {
70
69
return null ;
@@ -88,9 +87,7 @@ export abstract class SurfaceRenderer<
88
87
index : number
89
88
) : T | null {
90
89
if (
91
- ( this . allowedLayoutBlockTypes as string [ ] ) ?. includes (
92
- LayoutBlockType . CONTEXT
93
- ) === false &&
90
+ this . allowedLayoutBlockTypes . has ( LayoutBlockType . CONTEXT ) === false &&
94
91
! isContextBlockElement ( block )
95
92
) {
96
93
return null ;
@@ -115,9 +112,7 @@ export abstract class SurfaceRenderer<
115
112
116
113
public renderInputBlockElement ( block : BlockElement , index : number ) : T | null {
117
114
if (
118
- ( this . allowedLayoutBlockTypes as string [ ] ) ?. includes (
119
- LayoutBlockType . INPUT
120
- ) === false &&
115
+ this . allowedLayoutBlockTypes . has ( LayoutBlockType . INPUT ) === false &&
121
116
! isInputBlockElement ( block )
122
117
) {
123
118
return null ;
@@ -141,9 +136,7 @@ export abstract class SurfaceRenderer<
141
136
index : number
142
137
) : T | null {
143
138
if (
144
- ( this . allowedLayoutBlockTypes as string [ ] ) ?. includes (
145
- LayoutBlockType . SECTION
146
- ) === false &&
139
+ this . allowedLayoutBlockTypes . has ( LayoutBlockType . SECTION ) === false &&
147
140
! isSectionBlockAccessoryElement ( block )
148
141
) {
149
142
return null ;
@@ -201,6 +194,3 @@ export abstract class SurfaceRenderer<
201
194
index : number
202
195
) : T | null ;
203
196
}
204
-
205
- export type SurfaceRendererPayload < S extends BlockRenderers < any > > =
206
- S extends SurfaceRenderer < any , infer T > ? T [ ] : never ;
0 commit comments