Skip to content

Commit b2624f2

Browse files
authored
Merge pull request #441 from sugarlabs/gsoc-dmp-2025/week-2/justin
GSoC/DMP 2025 Week 2: feat(Masonry): Add Model and View for Brick
2 parents b305224 + 0941466 commit b2624f2

File tree

8 files changed

+1052
-0
lines changed

8 files changed

+1052
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* @type
3+
* Type (Simple Statement, Expression, Compound Statement) of a brick
4+
*/
5+
6+
export type TBrickType = 'Simple' | 'Expression' | 'Compound';
7+
8+
/**
9+
* @type
10+
* Bounding box dimensions of a brick.
11+
*/
12+
export type TExtent = {
13+
w: number;
14+
h: number;
15+
};
16+
17+
/**
18+
* @type
19+
* Defines color property of a brick. Supported types are RGB, HSL, and hexadecimal.
20+
*/
21+
export type TColor = ['rgb' | 'hsl', number, number, number] | string;
22+
23+
// -------------------------------------------------------------------------------------------------
24+
25+
export type TVisualState =
26+
| 'default'
27+
| 'selected'
28+
| 'hovered'
29+
| 'executing'
30+
| 'unconnected'
31+
| 'dragged';
32+
33+
type TBrickRenderProps = {
34+
path: string;
35+
label: string;
36+
labelType: 'text' | 'glyph' | 'icon' | 'thumbnail';
37+
colorBg: TColor;
38+
colorFg: TColor;
39+
strokeColor: TColor;
40+
strokeWidth: number; //remove
41+
scale: number;
42+
shadow: boolean;
43+
tooltip?: string;
44+
bboxArgs: TExtent[];
45+
46+
visualState: TVisualState;
47+
isActionMenuOpen: boolean;
48+
isVisible: boolean;
49+
};
50+
51+
export type TBrickRenderPropsExpression = TBrickRenderProps & {
52+
value: undefined | boolean | number | string;
53+
isValueSelectOpen: boolean;
54+
};
55+
56+
export type TBrickRenderPropsSimple = TBrickRenderProps & {
57+
topNotch: boolean;
58+
bottomNotch: boolean;
59+
};
60+
61+
export type TBrickRenderPropsCompound = TBrickRenderProps & {
62+
topNotch: boolean;
63+
bottomNotch: boolean;
64+
bboxNest: TExtent[];
65+
isFolded: boolean;
66+
};
67+
68+
/**
69+
* @interface
70+
* Type definition of a brick (any type).
71+
*/
72+
export interface IBrick {
73+
get uuid(): string;
74+
get name(): string;
75+
get type(): TBrickType;
76+
set scale(value: number);
77+
get boundingBox(): TExtent;
78+
79+
get visualState(): TVisualState;
80+
set visualState(value: TVisualState);
81+
82+
get isActionMenuOpen(): boolean;
83+
set isActionMenuOpen(value: boolean);
84+
85+
get isVisible(): boolean;
86+
set isVisible(value: boolean);
87+
}
88+
89+
/**
90+
* @interface
91+
* Type definition of a Simple Statement brick.
92+
*/
93+
export interface IBrickExpression extends IBrick {
94+
get isValueSelectOpen(): boolean;
95+
get value(): undefined | boolean | number | string;
96+
97+
get renderProps(): TBrickRenderPropsExpression;
98+
}
99+
100+
/**
101+
* @interface
102+
* Type definition of a Expression brick.
103+
*/
104+
export interface IBrickSimple extends IBrick {
105+
get topNotch(): boolean;
106+
get bottomNotch(): boolean;
107+
108+
get renderProps(): TBrickRenderPropsSimple;
109+
}
110+
111+
export interface IBrickCompound extends IBrick {
112+
get topNotch(): boolean;
113+
get bottomNotch(): boolean;
114+
get bboxNest(): TExtent[];
115+
116+
get isFolded(): boolean;
117+
set isFolded(value: boolean);
118+
119+
get renderProps(): TBrickRenderPropsCompound;
120+
121+
/**
122+
* Sets the bounding box extents for the nested area
123+
* @param extent width and height values of the nest area
124+
*/
125+
setBoundingBoxNest(extent: TExtent[]): void;
126+
}

0 commit comments

Comments
 (0)