Skip to content

Commit

Permalink
feat(masonry): Implement final classes for BrickExpression and BrickS…
Browse files Browse the repository at this point in the history
…tatement
  • Loading branch information
Karan-Palan committed Sep 4, 2024
1 parent a385c3a commit f52f067
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 10 deletions.
55 changes: 50 additions & 5 deletions modules/masonry/src/brick/design0/BrickExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { generatePath } from '../utils/path';
*/
export default class BrickExpression extends BrickModelExpression {
readonly _pathResults: ReturnType<typeof generatePath>;
readonly id: string;

constructor(params: {
// intrinsic
id: string;
uuid: string;
name: string;
label: string;
glyph: string;
Expand All @@ -27,14 +25,14 @@ export default class BrickExpression extends BrickModelExpression {
meta: unknown;
}
>;
// style
colorBg: TBrickColor;
colorFg: TBrickColor;
colorBgHighlight: TBrickColor;
colorFgHighlight: TBrickColor;
outline: TBrickColor;
scale: number;
}) {
super(params);
this.id = params.id;
const argsKeys = Object.keys(this._args);
this._pathResults = generatePath({
hasNest: false,
Expand All @@ -47,10 +45,12 @@ export default class BrickExpression extends BrickModelExpression {
});
}

// Getter for SVG path
public get SVGpath(): string {
return this._pathResults.path;
}

// Getter for bounding box of the brick
public get bBoxBrick(): { extent: TBrickExtent; coords: TBrickCoords } {
return {
extent: {
Expand All @@ -64,6 +64,7 @@ export default class BrickExpression extends BrickModelExpression {
};
}

// Getter for bounding boxes of the arguments
public get bBoxArgs(): Record<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};
Expand All @@ -84,6 +85,7 @@ export default class BrickExpression extends BrickModelExpression {
return result;
}

// Getter for bounding box of the argument notch
public get bBoxNotchArg(): { extent: TBrickExtent; coords: TBrickCoords } {
return {
extent: {
Expand All @@ -96,4 +98,47 @@ export default class BrickExpression extends BrickModelExpression {
},
};
}

// Method to return React props for the BrickExpression component
public getReactProps(): Record<string, unknown> {
return {
uuid: this.uuid,
name: this.name,
label: this.label,
glyph: this.glyph,
dataType: this.dataType,
args: this.args,
colorBg: this.colorBg,
colorFg: this.colorFg,
colorBgHighlight: this.colorBgHighlight,
colorFgHighlight: this.colorFgHighlight,
outline: this.outline,
scale: this.scale,
highlighted: this.highlighted,
};
}

// Setters for properties that can change at runtime
public setArgs(
args: Record<string, { label: string; dataType: TBrickArgDataType; meta: unknown }>,
): void {
this._args = args;
this.updateConnectionPoints();
}

public setHighlighted(highlighted: boolean): void {
this.highlighted = highlighted;
}

// Method to update connection points based on current state
protected updateConnectionPoints(): void {
this._connectionPoints.ArgsIncoming = Object.keys(this._args).map((_, index) => ({
x: 0,
y: index * 20,
}));
this._connectionPoints.ArgsOutgoing = Object.keys(this._args).map((_, index) => ({
x: 0,
y: index * 20,
}));
}
}
60 changes: 55 additions & 5 deletions modules/masonry/src/brick/design0/BrickStatement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { generatePath } from '../utils/path';
*/
export default class BrickStatement extends BrickModelStatement {
readonly _pathResults: ReturnType<typeof generatePath>;
readonly id: string;

constructor(params: {
// intrinsic
id: string;
uuid: string;
name: string;
label: string;
glyph: string;
Expand All @@ -26,16 +24,16 @@ export default class BrickStatement extends BrickModelStatement {
meta: unknown;
}
>;
// style
colorBg: TBrickColor;
colorFg: TBrickColor;
colorBgHighlight: TBrickColor;
colorFgHighlight: TBrickColor;
outline: TBrickColor;
scale: number;
connectAbove: boolean;
connectBelow: boolean;
}) {
super(params);
this.id = params.id;
const argsKeys = Object.keys(this._args);
this._pathResults = generatePath({
hasNest: false,
Expand All @@ -48,10 +46,12 @@ export default class BrickStatement extends BrickModelStatement {
});
}

// Getter for SVG path
public get SVGpath(): string {
return this._pathResults.path;
}

// Getter for bounding box of the brick
public get bBoxBrick(): { extent: TBrickExtent; coords: TBrickCoords } {
return {
extent: {
Expand All @@ -65,6 +65,7 @@ export default class BrickStatement extends BrickModelStatement {
};
}

// Getter for bounding boxes of the arguments
public get bBoxArgs(): Record<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};
Expand All @@ -85,6 +86,7 @@ export default class BrickStatement extends BrickModelStatement {
return result;
}

// Getter for bounding box of the top insertion notch
public get bBoxNotchInsTop(): { extent: TBrickExtent; coords: TBrickCoords } {
return {
extent: {
Expand All @@ -98,6 +100,7 @@ export default class BrickStatement extends BrickModelStatement {
};
}

// Getter for bounding box of the bottom insertion notch
public get bBoxNotchInsBot(): { extent: TBrickExtent; coords: TBrickCoords } {
return {
extent: {
Expand All @@ -110,4 +113,51 @@ export default class BrickStatement extends BrickModelStatement {
},
};
}

// Method to return React props for the BrickStatement component
public getReactProps(): Record<string, unknown> {
return {
uuid: this.uuid,
name: this.name,
label: this.label,
glyph: this.glyph,
args: this.args,
colorBg: this.colorBg,
colorFg: this.colorFg,
colorBgHighlight: this.colorBgHighlight,
colorFgHighlight: this.colorFgHighlight,
outline: this.outline,
scale: this.scale,
connectAbove: this.connectAbove,
connectBelow: this.connectBelow,
highlighted: this.highlighted,
};
}

// Setters for properties that can change at runtime
public setArgs(
args: Record<string, { label: string; dataType: TBrickArgDataType; meta: unknown }>,
): void {
this._args = args;
this.updateConnectionPoints();
}

public setConnectAbove(connectAbove: boolean): void {
this._connectAbove = connectAbove;
}

public setConnectBelow(connectBelow: boolean): void {
this._connectBelow = connectBelow;
}

public setHighlighted(highlighted: boolean): void {
this.highlighted = highlighted;
}

// Method to update connection points based on current state
protected updateConnectionPoints(): void {
// Update the connection points for the top and bottom of the brick
this._connectionPoints.ArgsIncoming = this.connectAbove ? [{ x: 0, y: 0 }] : [];
this._connectionPoints.ArgsOutgoing = this.connectBelow ? [{ x: 0, y: 0 }] : [];
}
}

0 comments on commit f52f067

Please sign in to comment.