Skip to content

Commit

Permalink
feat(masonry): Add missing methods to BrickBlock.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan-Palan committed Sep 3, 2024
1 parent 4fba69d commit dc63072
Showing 1 changed file with 119 additions and 19 deletions.
138 changes: 119 additions & 19 deletions modules/masonry/src/brick/design0/BrickBlock.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,81 @@
import type { TBrickArgDataType, TBrickColor, TBrickCoords, TBrickExtent } from '@/@types/brick';

import { BrickModelBlock } from '../model';
import { generatePath } from '../utils/path';

// -------------------------------------------------------------------------------------------------

/**
* @class
* Final class that defines a block brick.
* Defines a block brick, extending `BrickModelBlock`.
*/
export default class BrickBlock extends BrickModelBlock {
readonly _pathResults: ReturnType<typeof generatePath>;
readonly id: string;
readonly colorBgHighlight: TBrickColor;
readonly colorFgHighlight: TBrickColor;
public highlighted: boolean;
private _argExtents: Record<string, { argLengthX?: number; argLengthY: number }> = {};
private _folded: boolean;

constructor(params: {
// intrinsic
id: string;
name: string;
label: string;
glyph: string;
args: Record<

This comment has been minimized.

Copy link
@meganindya

meganindya Sep 3, 2024

Member

array not object

string,
{
label: string;
dataType: TBrickArgDataType;
meta: unknown;
argId: string;
argLabel: string;
argTypeIncoming: TBrickArgDataType;
}
>;
colorBg: TBrickColor;
colorFg: TBrickColor;
outline: TBrickColor;
colorBgHighlight: TBrickColor;
colorFgHighlight: TBrickColor;
scale: number;

This comment has been minimized.

Copy link
@meganindya

meganindya Sep 3, 2024

Member

check constructor params list

connectAbove: boolean;
connectBelow: boolean;
nestLengthY: number;
folded?: boolean;
highlighted?: boolean;
}) {
super(params);
super({
name: params.name,

This comment has been minimized.

Copy link
@meganindya

meganindya Sep 3, 2024

Member

params not matching list

label: params.label,
glyph: params.glyph,
args: Object.fromEntries(
Object.entries(params.args).map(([key, value]) => [
key,
{
label: value.argLabel,
dataType: value.argTypeIncoming,
meta: {},
},
]),
),
colorBg: params.colorBg,
colorFg: params.colorFg,
outline: params.outline,
scale: params.scale,
connectAbove: params.connectAbove,
connectBelow: params.connectBelow,
});

this.id = params.id;
const argsKeys = Object.keys(this._args);
this.colorBgHighlight = params.colorBgHighlight;
this.colorFgHighlight = params.colorFgHighlight;
this.highlighted = params.highlighted ?? false;
this._folded = params.folded ?? false;

this._pathResults = generatePath({
hasNest: true,
hasNotchArg: false,
hasNotchInsTop: this._connectAbove,
hasNotchInsBot: this._connectBelow,
scale: this._scale,
hasNotchInsTop: params.connectAbove,
hasNotchInsBot: params.connectBelow,
scale: params.scale,
nestLengthY: params.nestLengthY,
innerLengthX: 100,
argHeights: Array.from({ length: argsKeys.length }, () => 17),
argHeights: Array(Object.keys(params.args).length).fill(17),
});
}

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

public get bBoxArgs(): Record<string, { extent: TBrickExtent; coords: TBrickCoords }> {
const argsKeys = Object.keys(this._args);
const result: Record<string, { extent: TBrickExtent; coords: TBrickCoords }> = {};

argsKeys.forEach((key, index) => {
Object.keys(this._args).forEach((key, index) => {
result[key] = {
extent: {
width: this._pathResults.bBoxArgs.extent.width * this._scale,
Expand All @@ -83,7 +110,6 @@ export default class BrickBlock extends BrickModelBlock {
},
};
});

return result;
}

Expand Down Expand Up @@ -138,4 +164,78 @@ export default class BrickBlock extends BrickModelBlock {
},
};
}

public get instantiationProperties(): {

This comment has been minimized.

Copy link
@meganindya

meganindya Sep 3, 2024

Member

why do you need this?

id: string;
name: string;
label: string;
glyph: string;
args: Record<
string,
{
argId: string;
argLabel: string;
argTypeIncoming: TBrickArgDataType;
}
>;
colorBg: TBrickColor;
colorFg: TBrickColor;
colorBgHighlight: TBrickColor;
colorFgHighlight: TBrickColor;
outline: TBrickColor;
scale: number;
connectAbove: boolean;
connectBelow: boolean;
highlighted: boolean;
argExtents: Record<string, { argLengthX?: number; argLengthY: number }>;
folded: boolean;
} {
return {
id: this.id,
name: this.name,
label: this.label,
glyph: this.glyph,
args: Object.fromEntries(
Object.entries(this._args).map(([key, value]) => [
key,
{
argId: value.label,
argLabel: value.label,
argTypeIncoming: value.dataType,
},
]),
),
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,
argExtents: this._argExtents,
folded: this._folded,
};
}

public get renderProperties(): {

This comment has been minimized.

Copy link
@meganindya

meganindya Sep 3, 2024

Member

use different name ... these are calculated properties

boundingBox: { extent: TBrickExtent; coords: TBrickCoords };
connectionPoints: {
Top: { extent: TBrickExtent; coords: TBrickCoords } | null;
Bottom: { extent: TBrickExtent; coords: TBrickCoords } | null;
TopInner: { extent: TBrickExtent; coords: TBrickCoords } | null;
ArgsIncoming: { extent: TBrickExtent; coords: TBrickCoords } | null;
};
} {
return {
boundingBox: this.bBoxBrick,
connectionPoints: {
Top: this.bBoxNotchInsTop,
Bottom: this.bBoxNotchInsBot,
TopInner: this.bBoxNotchInsNestTop,
ArgsIncoming: this.bBoxNotchArg,
},
};
}
}

1 comment on commit dc63072

@meganindya
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add method to return all state properties in current state which will be props to the React component
move common attributes to parent class
add methods to get/set dynamic state params

Please sign in to comment.