Skip to content

Commit dc63072

Browse files
committed
feat(masonry): Add missing methods to BrickBlock.ts
1 parent 4fba69d commit dc63072

File tree

1 file changed

+119
-19
lines changed

1 file changed

+119
-19
lines changed

modules/masonry/src/brick/design0/BrickBlock.ts

+119-19
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,81 @@
11
import type { TBrickArgDataType, TBrickColor, TBrickCoords, TBrickExtent } from '@/@types/brick';
2-
32
import { BrickModelBlock } from '../model';
43
import { generatePath } from '../utils/path';
54

6-
// -------------------------------------------------------------------------------------------------
7-
85
/**
9-
* @class
10-
* Final class that defines a block brick.
6+
* Defines a block brick, extending `BrickModelBlock`.
117
*/
128
export default class BrickBlock extends BrickModelBlock {
139
readonly _pathResults: ReturnType<typeof generatePath>;
1410
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;
1516

1617
constructor(params: {
17-
// intrinsic
1818
id: string;
1919
name: string;
2020
label: string;
2121
glyph: string;
2222
args: Record<
2323
string,
2424
{
25-
label: string;
26-
dataType: TBrickArgDataType;
27-
meta: unknown;
25+
argId: string;
26+
argLabel: string;
27+
argTypeIncoming: TBrickArgDataType;
2828
}
2929
>;
3030
colorBg: TBrickColor;
3131
colorFg: TBrickColor;
3232
outline: TBrickColor;
33+
colorBgHighlight: TBrickColor;
34+
colorFgHighlight: TBrickColor;
3335
scale: number;
3436
connectAbove: boolean;
3537
connectBelow: boolean;
3638
nestLengthY: number;
39+
folded?: boolean;
40+
highlighted?: boolean;
3741
}) {
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+
3964
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+
4170
this._pathResults = generatePath({
4271
hasNest: true,
4372
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,
4776
nestLengthY: params.nestLengthY,
4877
innerLengthX: 100,
49-
argHeights: Array.from({ length: argsKeys.length }, () => 17),
78+
argHeights: Array(Object.keys(params.args).length).fill(17),
5079
});
5180
}
5281

@@ -68,10 +97,8 @@ export default class BrickBlock extends BrickModelBlock {
6897
}
6998

7099
public get bBoxArgs(): Record<string, { extent: TBrickExtent; coords: TBrickCoords }> {
71-
const argsKeys = Object.keys(this._args);
72100
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};
73-
74-
argsKeys.forEach((key, index) => {
101+
Object.keys(this._args).forEach((key, index) => {
75102
result[key] = {
76103
extent: {
77104
width: this._pathResults.bBoxArgs.extent.width * this._scale,
@@ -83,7 +110,6 @@ export default class BrickBlock extends BrickModelBlock {
83110
},
84111
};
85112
});
86-
87113
return result;
88114
}
89115

@@ -138,4 +164,78 @@ export default class BrickBlock extends BrickModelBlock {
138164
},
139165
};
140166
}
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+
}
141241
}

0 commit comments

Comments
 (0)