1
1
import type { TBrickArgDataType , TBrickColor , TBrickCoords , TBrickExtent } from '@/@types/brick' ;
2
-
3
2
import { BrickModelBlock } from '../model' ;
4
3
import { generatePath } from '../utils/path' ;
5
4
6
- // -------------------------------------------------------------------------------------------------
7
-
8
5
/**
9
- * @class
10
- * Final class that defines a block brick.
6
+ * Defines a block brick, extending `BrickModelBlock`.
11
7
*/
12
8
export default class BrickBlock extends BrickModelBlock {
13
9
readonly _pathResults : ReturnType < typeof generatePath > ;
14
10
readonly id : string ;
11
+ readonly colorBgHighlight : TBrickColor ;
12
+ readonly colorFgHighlight : TBrickColor ;
13
+ public highlighted : boolean ;
14
+ private _argExtents : Record < string , { argLengthX ?: number ; argLengthY : number } > = { } ;
15
+ private _folded : boolean ;
15
16
16
17
constructor ( params : {
17
- // intrinsic
18
18
id : string ;
19
19
name : string ;
20
20
label : string ;
21
21
glyph : string ;
22
22
args : Record <
23
23
string ,
24
24
{
25
- label : string ;
26
- dataType : TBrickArgDataType ;
27
- meta : unknown ;
25
+ argId : string ;
26
+ argLabel : string ;
27
+ argTypeIncoming : TBrickArgDataType ;
28
28
}
29
29
> ;
30
30
colorBg : TBrickColor ;
31
31
colorFg : TBrickColor ;
32
32
outline : TBrickColor ;
33
+ colorBgHighlight : TBrickColor ;
34
+ colorFgHighlight : TBrickColor ;
33
35
scale : number ;
34
36
connectAbove : boolean ;
35
37
connectBelow : boolean ;
36
38
nestLengthY : number ;
39
+ folded ?: boolean ;
40
+ highlighted ?: boolean ;
37
41
} ) {
38
- super ( params ) ;
42
+ super ( {
43
+ name : params . name ,
44
+ label : params . label ,
45
+ glyph : params . glyph ,
46
+ args : Object . fromEntries (
47
+ Object . entries ( params . args ) . map ( ( [ key , value ] ) => [
48
+ key ,
49
+ {
50
+ label : value . argLabel ,
51
+ dataType : value . argTypeIncoming ,
52
+ meta : { } ,
53
+ } ,
54
+ ] ) ,
55
+ ) ,
56
+ colorBg : params . colorBg ,
57
+ colorFg : params . colorFg ,
58
+ outline : params . outline ,
59
+ scale : params . scale ,
60
+ connectAbove : params . connectAbove ,
61
+ connectBelow : params . connectBelow ,
62
+ } ) ;
63
+
39
64
this . id = params . id ;
40
- const argsKeys = Object . keys ( this . _args ) ;
65
+ this . colorBgHighlight = params . colorBgHighlight ;
66
+ this . colorFgHighlight = params . colorFgHighlight ;
67
+ this . highlighted = params . highlighted ?? false ;
68
+ this . _folded = params . folded ?? false ;
69
+
41
70
this . _pathResults = generatePath ( {
42
71
hasNest : true ,
43
72
hasNotchArg : false ,
44
- hasNotchInsTop : this . _connectAbove ,
45
- hasNotchInsBot : this . _connectBelow ,
46
- scale : this . _scale ,
73
+ hasNotchInsTop : params . connectAbove ,
74
+ hasNotchInsBot : params . connectBelow ,
75
+ scale : params . scale ,
47
76
nestLengthY : params . nestLengthY ,
48
77
innerLengthX : 100 ,
49
- argHeights : Array . from ( { length : argsKeys . length } , ( ) => 17 ) ,
78
+ argHeights : Array ( Object . keys ( params . args ) . length ) . fill ( 17 ) ,
50
79
} ) ;
51
80
}
52
81
@@ -68,10 +97,8 @@ export default class BrickBlock extends BrickModelBlock {
68
97
}
69
98
70
99
public get bBoxArgs ( ) : Record < string , { extent : TBrickExtent ; coords : TBrickCoords } > {
71
- const argsKeys = Object . keys ( this . _args ) ;
72
100
const result : Record < string , { extent : TBrickExtent ; coords : TBrickCoords } > = { } ;
73
-
74
- argsKeys . forEach ( ( key , index ) => {
101
+ Object . keys ( this . _args ) . forEach ( ( key , index ) => {
75
102
result [ key ] = {
76
103
extent : {
77
104
width : this . _pathResults . bBoxArgs . extent . width * this . _scale ,
@@ -83,7 +110,6 @@ export default class BrickBlock extends BrickModelBlock {
83
110
} ,
84
111
} ;
85
112
} ) ;
86
-
87
113
return result ;
88
114
}
89
115
@@ -138,4 +164,78 @@ export default class BrickBlock extends BrickModelBlock {
138
164
} ,
139
165
} ;
140
166
}
167
+
168
+ public get instantiationProperties ( ) : {
169
+ id : string ;
170
+ name : string ;
171
+ label : string ;
172
+ glyph : string ;
173
+ args : Record <
174
+ string ,
175
+ {
176
+ argId : string ;
177
+ argLabel : string ;
178
+ argTypeIncoming : TBrickArgDataType ;
179
+ }
180
+ > ;
181
+ colorBg : TBrickColor ;
182
+ colorFg : TBrickColor ;
183
+ colorBgHighlight : TBrickColor ;
184
+ colorFgHighlight : TBrickColor ;
185
+ outline : TBrickColor ;
186
+ scale : number ;
187
+ connectAbove : boolean ;
188
+ connectBelow : boolean ;
189
+ highlighted : boolean ;
190
+ argExtents : Record < string , { argLengthX ?: number ; argLengthY : number } > ;
191
+ folded : boolean ;
192
+ } {
193
+ return {
194
+ id : this . id ,
195
+ name : this . name ,
196
+ label : this . label ,
197
+ glyph : this . glyph ,
198
+ args : Object . fromEntries (
199
+ Object . entries ( this . _args ) . map ( ( [ key , value ] ) => [
200
+ key ,
201
+ {
202
+ argId : value . label ,
203
+ argLabel : value . label ,
204
+ argTypeIncoming : value . dataType ,
205
+ } ,
206
+ ] ) ,
207
+ ) ,
208
+ colorBg : this . colorBg ,
209
+ colorFg : this . colorFg ,
210
+ colorBgHighlight : this . colorBgHighlight ,
211
+ colorFgHighlight : this . colorFgHighlight ,
212
+ outline : this . outline ,
213
+ scale : this . _scale ,
214
+ connectAbove : this . connectAbove ,
215
+ connectBelow : this . connectBelow ,
216
+ highlighted : this . highlighted ,
217
+ argExtents : this . _argExtents ,
218
+ folded : this . _folded ,
219
+ } ;
220
+ }
221
+
222
+ public get renderProperties ( ) : {
223
+ boundingBox : { extent : TBrickExtent ; coords : TBrickCoords } ;
224
+ connectionPoints : {
225
+ Top : { extent : TBrickExtent ; coords : TBrickCoords } | null ;
226
+ Bottom : { extent : TBrickExtent ; coords : TBrickCoords } | null ;
227
+ TopInner : { extent : TBrickExtent ; coords : TBrickCoords } | null ;
228
+ ArgsIncoming : { extent : TBrickExtent ; coords : TBrickCoords } | null ;
229
+ } ;
230
+ } {
231
+ return {
232
+ boundingBox : this . bBoxBrick ,
233
+ connectionPoints : {
234
+ Top : this . bBoxNotchInsTop ,
235
+ Bottom : this . bBoxNotchInsBot ,
236
+ TopInner : this . bBoxNotchInsNestTop ,
237
+ ArgsIncoming : this . bBoxNotchArg ,
238
+ } ,
239
+ } ;
240
+ }
141
241
}
0 commit comments