Skip to content

Commit 6461ec7

Browse files
committed
fix(masonry): all linting errors and warnings across masonry module
1 parent 6ffaf38 commit 6461ec7

File tree

10 files changed

+223
-187
lines changed

10 files changed

+223
-187
lines changed

modules/masonry/src/brick/model/model.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,11 @@ export default class CompoundBrick extends BrickModel implements IBrickCompound
416416
// If there are nested children, calculate the total bounding box
417417
if (nestedChildren && nestedChildren.length > 0) {
418418
// Calculate the bounding box that fits all nested children
419-
let minX = 0, minY = 0, maxX = 0, maxY = 0;
420-
nestedChildren.forEach(child => {
419+
let _minX = 0,
420+
_minY = 0,
421+
maxX = 0,
422+
maxY = 0;
423+
nestedChildren.forEach((child) => {
421424
const bbox = child.boundingBox;
422425
// For simplicity, assume children are stacked vertically for now
423426
maxY += bbox.h;

modules/masonry/src/brick/utils/brickFactory.ts

Lines changed: 102 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,113 +5,129 @@ import type { TBrickType, TColor, TExtent } from '../@types/brick';
55

66
let idCounter = 0;
77
function generateUUID(prefix: string): string {
8-
return `${prefix}_${++idCounter}`;
8+
return `${prefix}_${++idCounter}`;
99
}
1010

1111
// Default colors
1212
const defaultColors = {
13-
simple: {
14-
colorBg: '#bbdefb' as TColor,
15-
colorFg: '#222' as TColor,
16-
strokeColor: '#1976d2' as TColor,
17-
},
18-
expression: {
19-
colorBg: '#b2fab4' as TColor,
20-
colorFg: '#222' as TColor,
21-
strokeColor: '#2e7d32' as TColor,
22-
},
23-
compound: {
24-
colorBg: '#b9f6ca' as TColor,
25-
colorFg: '#222' as TColor,
26-
strokeColor: '#43a047' as TColor,
27-
},
13+
simple: {
14+
colorBg: '#bbdefb' as TColor,
15+
colorFg: '#222' as TColor,
16+
strokeColor: '#1976d2' as TColor,
17+
},
18+
expression: {
19+
colorBg: '#b2fab4' as TColor,
20+
colorFg: '#222' as TColor,
21+
strokeColor: '#2e7d32' as TColor,
22+
},
23+
compound: {
24+
colorBg: '#b9f6ca' as TColor,
25+
colorFg: '#222' as TColor,
26+
strokeColor: '#43a047' as TColor,
27+
},
2828
};
2929

3030
const defaultLabelType = 'text' as const;
3131
const defaultScale = 1;
3232
const defaultBBoxArgs: TExtent[] = [{ w: 40, h: 20 }];
3333

34-
export function createSimpleBrick(overrides: Partial<ConstructorParameters<typeof SimpleBrick>[0]> = {}) {
35-
const idx = idCounter + 1;
36-
// By default, SimpleBrick has two argument slots (for arguments/inputs)
37-
return new SimpleBrick({
38-
uuid: generateUUID('simple'),
39-
name: overrides.name ?? `Simple${idx}`,
40-
label: overrides.label ?? `Simple${idx}`,
41-
labelType: overrides.labelType ?? defaultLabelType,
42-
colorBg: overrides.colorBg ?? defaultColors.simple.colorBg,
43-
colorFg: overrides.colorFg ?? defaultColors.simple.colorFg,
44-
strokeColor: overrides.strokeColor ?? defaultColors.simple.strokeColor,
45-
shadow: overrides.shadow ?? false,
46-
scale: overrides.scale ?? defaultScale,
47-
bboxArgs: overrides.bboxArgs ?? [{ w: 40, h: 20 }, { w: 40, h: 20 }],
48-
topNotch: overrides.topNotch ?? true,
49-
bottomNotch: overrides.bottomNotch ?? true,
50-
tooltip: overrides.tooltip,
51-
...overrides,
52-
});
34+
export function createSimpleBrick(
35+
overrides: Partial<ConstructorParameters<typeof SimpleBrick>[0]> = {},
36+
) {
37+
const idx = idCounter + 1;
38+
// By default, SimpleBrick has two argument slots (for arguments/inputs)
39+
return new SimpleBrick({
40+
uuid: generateUUID('simple'),
41+
name: overrides.name ?? `Simple${idx}`,
42+
label: overrides.label ?? `Simple${idx}`,
43+
labelType: overrides.labelType ?? defaultLabelType,
44+
colorBg: overrides.colorBg ?? defaultColors.simple.colorBg,
45+
colorFg: overrides.colorFg ?? defaultColors.simple.colorFg,
46+
strokeColor: overrides.strokeColor ?? defaultColors.simple.strokeColor,
47+
shadow: overrides.shadow ?? false,
48+
scale: overrides.scale ?? defaultScale,
49+
bboxArgs: overrides.bboxArgs ?? [
50+
{ w: 40, h: 20 },
51+
{ w: 40, h: 20 },
52+
],
53+
topNotch: overrides.topNotch ?? true,
54+
bottomNotch: overrides.bottomNotch ?? true,
55+
tooltip: overrides.tooltip,
56+
...overrides,
57+
});
5358
}
5459

5560
// ExpressionBrick is used as an argument value, not as an argument-receiving brick
56-
export function createExpressionBrick(overrides: Partial<ConstructorParameters<typeof ExpressionBrick>[0]> = {}) {
57-
const idx = idCounter + 1;
58-
return new ExpressionBrick({
59-
uuid: generateUUID('expr'),
60-
name: overrides.name ?? `Expr${idx}`,
61-
label: overrides.label ?? `Expr${idx}`,
62-
labelType: overrides.labelType ?? defaultLabelType,
63-
colorBg: overrides.colorBg ?? defaultColors.expression.colorBg,
64-
colorFg: overrides.colorFg ?? defaultColors.expression.colorFg,
65-
strokeColor: overrides.strokeColor ?? defaultColors.expression.strokeColor,
66-
shadow: overrides.shadow ?? false,
67-
scale: overrides.scale ?? defaultScale,
68-
bboxArgs: overrides.bboxArgs ?? [{ w: 40, h: 20 }],
69-
value: overrides.value,
70-
isValueSelectOpen: overrides.isValueSelectOpen ?? false,
71-
tooltip: overrides.tooltip,
72-
...overrides,
73-
});
61+
export function createExpressionBrick(
62+
overrides: Partial<ConstructorParameters<typeof ExpressionBrick>[0]> = {},
63+
) {
64+
const idx = idCounter + 1;
65+
return new ExpressionBrick({
66+
uuid: generateUUID('expr'),
67+
name: overrides.name ?? `Expr${idx}`,
68+
label: overrides.label ?? `Expr${idx}`,
69+
labelType: overrides.labelType ?? defaultLabelType,
70+
colorBg: overrides.colorBg ?? defaultColors.expression.colorBg,
71+
colorFg: overrides.colorFg ?? defaultColors.expression.colorFg,
72+
strokeColor: overrides.strokeColor ?? defaultColors.expression.strokeColor,
73+
shadow: overrides.shadow ?? false,
74+
scale: overrides.scale ?? defaultScale,
75+
bboxArgs: overrides.bboxArgs ?? [{ w: 40, h: 20 }],
76+
value: overrides.value,
77+
isValueSelectOpen: overrides.isValueSelectOpen ?? false,
78+
tooltip: overrides.tooltip,
79+
...overrides,
80+
});
7481
}
7582

76-
export function createCompoundBrick(overrides: Partial<ConstructorParameters<typeof CompoundBrick>[0]> = {}) {
77-
const idx = idCounter + 1;
78-
return new CompoundBrick({
79-
uuid: generateUUID('compound'),
80-
name: overrides.name ?? `Compound${idx}`,
81-
label: overrides.label ?? `Compound${idx}`,
82-
labelType: overrides.labelType ?? defaultLabelType,
83-
colorBg: overrides.colorBg ?? defaultColors.compound.colorBg,
84-
colorFg: overrides.colorFg ?? defaultColors.compound.colorFg,
85-
strokeColor: overrides.strokeColor ?? defaultColors.compound.strokeColor,
86-
shadow: overrides.shadow ?? false,
87-
scale: overrides.scale ?? defaultScale,
88-
bboxArgs: overrides.bboxArgs ?? defaultBBoxArgs,
89-
bboxNest: overrides.bboxNest ?? [],
90-
topNotch: overrides.topNotch ?? true,
91-
bottomNotch: overrides.bottomNotch ?? true,
92-
isFolded: overrides.isFolded ?? false,
93-
tooltip: overrides.tooltip,
94-
...overrides,
95-
});
83+
export function createCompoundBrick(
84+
overrides: Partial<ConstructorParameters<typeof CompoundBrick>[0]> = {},
85+
) {
86+
const idx = idCounter + 1;
87+
return new CompoundBrick({
88+
uuid: generateUUID('compound'),
89+
name: overrides.name ?? `Compound${idx}`,
90+
label: overrides.label ?? `Compound${idx}`,
91+
labelType: overrides.labelType ?? defaultLabelType,
92+
colorBg: overrides.colorBg ?? defaultColors.compound.colorBg,
93+
colorFg: overrides.colorFg ?? defaultColors.compound.colorFg,
94+
strokeColor: overrides.strokeColor ?? defaultColors.compound.strokeColor,
95+
shadow: overrides.shadow ?? false,
96+
scale: overrides.scale ?? defaultScale,
97+
bboxArgs: overrides.bboxArgs ?? defaultBBoxArgs,
98+
bboxNest: overrides.bboxNest ?? [],
99+
topNotch: overrides.topNotch ?? true,
100+
bottomNotch: overrides.bottomNotch ?? true,
101+
isFolded: overrides.isFolded ?? false,
102+
tooltip: overrides.tooltip,
103+
...overrides,
104+
});
96105
}
97106

98107
export function resetFactoryCounter() {
99-
idCounter = 0;
108+
idCounter = 0;
100109
}
101110

102111
export function getFactoryCounter() {
103-
return idCounter;
112+
return idCounter;
104113
}
105114

106-
export function createBrick(type: TBrickType, overrides: any = {}) {
107-
switch (type) {
108-
case 'Simple':
109-
return createSimpleBrick(overrides);
110-
case 'Expression':
111-
return createExpressionBrick(overrides);
112-
case 'Compound':
113-
return createCompoundBrick(overrides);
114-
default:
115-
throw new Error(`Unsupported brick type: ${type}`);
116-
}
115+
export function createBrick(
116+
type: TBrickType,
117+
overrides: Partial<
118+
| ConstructorParameters<typeof SimpleBrick>[0]
119+
| ConstructorParameters<typeof ExpressionBrick>[0]
120+
| ConstructorParameters<typeof CompoundBrick>[0]
121+
> = {},
122+
) {
123+
switch (type) {
124+
case 'Simple':
125+
return createSimpleBrick(overrides);
126+
case 'Expression':
127+
return createExpressionBrick(overrides);
128+
case 'Compound':
129+
return createCompoundBrick(overrides);
130+
default:
131+
throw new Error(`Unsupported brick type: ${type}`);
132+
}
117133
}

modules/masonry/src/brick/utils/path.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ function _generateRight(config: {
139139
if (hasArgs) {
140140
const requiredMinimum =
141141
strokeWidth / 2 + Math.max(MIN_LABEL_HEIGHT, bBoxLabel.h) + strokeWidth / 2;
142-
const argHeightsSum = bBoxArgs.length > 0 ? bBoxArgs.reduce((sum, arg) => sum + arg.h, 0) : 0;
142+
const argHeightsSum =
143+
bBoxArgs.length > 0 ? bBoxArgs.reduce((sum, arg) => sum + arg.h, 0) : 0;
143144
const extra = Math.max(0, requiredMinimum - argHeightsSum);
144145

145146
for (let i = 0; i < bBoxArgs.length; i++) {
@@ -263,7 +264,7 @@ function _generateNestedPath(config: {
263264
`a ${CORNER_RADIUS} ${CORNER_RADIUS} 90 0 1 ${CORNER_RADIUS} ${CORNER_RADIUS}`,
264265
...(hasSecondaryLabel ? [`v ${labelHeight}`] : ['v 4']),
265266
`a ${CORNER_RADIUS} ${CORNER_RADIUS} 90 0 1 -${CORNER_RADIUS} ${CORNER_RADIUS}`,
266-
`h -${variableOuterWidth - 2*strokeWidth}`,
267+
`h -${variableOuterWidth - 2 * strokeWidth}`,
267268
...(hasNotch ? _generateNotchBottom(strokeWidth) : [`h -${WIDTH_NOTCH_BOTTOM}`]),
268269
`h -${OFFSET_NOTCH_BOTTOM}`,
269270
];
@@ -443,7 +444,10 @@ function getBoundingBox(config: TInputUnion): TBBox {
443444

444445
// Reuse nested path logic
445446
const bBoxNesting3 = bBoxNesting || [];
446-
let nestingHeight = bBoxNesting3.length > 0 ? bBoxNesting3.reduce((sum: number, box: TBBox) => sum + box.h, 0) : 0;
447+
let nestingHeight =
448+
bBoxNesting3.length > 0
449+
? bBoxNesting3.reduce((sum: number, box: TBBox) => sum + box.h, 0)
450+
: 0;
447451
nestingHeight = Math.max(nestingHeight, MIN_NESTED_HEIGHT);
448452

449453
const labelHeight = Math.max(MIN_LABEL_HEIGHT, bBoxLabel.h);
@@ -617,25 +621,33 @@ export function generateBrickData(config: TInputType1 | TInputType2 | TInputType
617621
let args: { x: number; y: number }[] | undefined = undefined;
618622
if (connectionPoints.right && connectionPoints.right.length > 0) {
619623
args = connectionPoints.right.map((pt) => ({ x: pt.x, y: pt.y }));
620-
// Calculate origin for the argument brick based on the connection coordinates
624+
// Calculate origin for the argument brick based on the connection coordinates
621625
args.forEach((pt) => {
622-
pt.x = pt.x + OFFSET_NOTCH_RIGHT/2 + CORNER_RADIUS; // + strokewidth at the end
623-
pt.y = pt.y - CORNER_RADIUS - HEIGHT_NOTCH_RIGHT/2;
626+
pt.x = pt.x + OFFSET_NOTCH_RIGHT / 2 + CORNER_RADIUS; // + strokewidth at the end
627+
pt.y = pt.y - CORNER_RADIUS - HEIGHT_NOTCH_RIGHT / 2;
624628
});
625629
}
626630

627631
//nesting height to calculate the nested origin, either here or use it from the getBoundingBox function
628-
const bBoxNesting = (config as any).bBoxNesting || [];
629-
let nestingHeight = bBoxNesting.length > 0 ? bBoxNesting.reduce((sum: number, box: TBBox) => sum + box.h, 0) : 0;
632+
const bBoxNesting = 'bBoxNesting' in config ? config.bBoxNesting : [];
633+
let nestingHeight =
634+
bBoxNesting.length > 0
635+
? bBoxNesting.reduce((sum: number, box: TBBox) => sum + box.h, 0)
636+
: 0;
630637
nestingHeight = Math.max(nestingHeight, MIN_NESTED_HEIGHT);
631638

632639
// Nested region origin (for type3/compound)
633640
let nested: { x: number; y: number } | undefined = undefined;
634-
if ((config as any).type === 'type3' && connectionPoints.bottom) {
641+
if (config.type === 'type3' && connectionPoints.bottom) {
635642
nestingHeight += CORNER_RADIUS + 2;
636643
nested = {
637-
x: connectionPoints.bottom.x - WIDTH_NOTCH_BOTTOM / 2 - OFFSET_NOTCH_BOTTOM - CORNER_RADIUS - 2,//strokewidth,
638-
y: connectionPoints.bottom.y - CORNER_RADIUS*2 - 4 - nestingHeight,
644+
x:
645+
connectionPoints.bottom.x -
646+
WIDTH_NOTCH_BOTTOM / 2 -
647+
OFFSET_NOTCH_BOTTOM -
648+
CORNER_RADIUS -
649+
2, //strokewidth,
650+
y: connectionPoints.bottom.y - CORNER_RADIUS * 2 - 4 - nestingHeight,
639651
};
640652
}
641653

modules/masonry/src/brick/view/components/compound.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export const CompoundBrickView: React.FC<PropsWithMetrics> = (props) => {
124124
isFolded,
125125
bBoxLabel,
126126
bBoxNesting,
127+
RenderMetrics,
127128
]);
128129

129130
if (!isVisible) return null;

modules/masonry/src/brick/view/components/expression.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const ExpressionBrickView: React.FC<PropsWithMetrics> = (props) => {
9999
RenderMetrics(brickData.boundingBox, brickData.connectionPoints);
100100
}
101101
setShape({ path: brickData.path, w: brickData.boundingBox.w, h: brickData.boundingBox.h });
102-
}, [label, strokeWidth, scale, bboxArgs, bBoxLabel]);
102+
}, [label, strokeWidth, scale, bboxArgs, bBoxLabel, RenderMetrics]);
103103

104104
if (!isVisible) return null;
105105

modules/masonry/src/brick/view/components/simple.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export const SimpleBrickView: React.FC<PropsWithMetrics> = (props) => {
104104
RenderMetrics(brickData.boundingBox, brickData.connectionPoints);
105105
}
106106
setShape({ path: brickData.path, w: brickData.boundingBox.w, h: brickData.boundingBox.h });
107-
}, [label, strokeWidth, scale, bboxArgs, topNotch, bottomNotch, bBoxLabel]);
107+
}, [label, strokeWidth, scale, bboxArgs, topNotch, bottomNotch, bBoxLabel, RenderMetrics]);
108108

109109
if (!isVisible) return null;
110110

0 commit comments

Comments
 (0)