Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move Theme to use a Partial type for BlockStyle #6532

Merged
merged 4 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions core/field_angle.ts
Expand Up @@ -228,10 +228,6 @@ export class FieldAngle extends FieldTextInput {
dropDownDiv.getContentDiv().appendChild(this.editor_ as AnyDuringMigration);

if (this.sourceBlock_ instanceof BlockSvg) {
if (!this.sourceBlock_.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
dropDownDiv.setColour(
this.sourceBlock_.style.colourPrimary,
this.sourceBlock_.style.colourTertiary);
Expand Down
12 changes: 0 additions & 12 deletions core/field_dropdown.ts
Expand Up @@ -285,10 +285,6 @@ export class FieldDropdown extends Field {
const borderColour = this.getSourceBlock().isShadow() ?
(this.getSourceBlock().getParent() as BlockSvg).style.colourTertiary :
(this.sourceBlock_ as BlockSvg).style.colourTertiary;
if (!borderColour) {
throw new Error(
'The renderer did not properly initialize the block style');
}
dropDownDiv.setColour(primaryColour, borderColour);
}

Expand Down Expand Up @@ -503,14 +499,6 @@ export class FieldDropdown extends Field {
*/
override applyColour() {
const style = (this.sourceBlock_ as BlockSvg).style;
if (!style.colourSecondary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
if (!style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
if (this.borderRect_) {
this.borderRect_.setAttribute('stroke', style.colourTertiary);
if (this.menu_) {
Expand Down
4 changes: 0 additions & 4 deletions core/field_textinput.ts
Expand Up @@ -222,10 +222,6 @@ export class FieldTextInput extends Field {
const source = this.sourceBlock_ as BlockSvg;

if (this.borderRect_) {
if (!source.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
this.borderRect_.setAttribute('stroke', source.style.colourTertiary);
} else {
source.pathObject.svgPath.setAttribute(
Expand Down
7 changes: 1 addition & 6 deletions core/renderers/common/constants.ts
Expand Up @@ -658,12 +658,7 @@ export class ConstantProvider {
* @param blockStyle A full or partial block style object.
* @returns A full block style object, with all required properties populated.
*/
protected validatedBlockStyle_(blockStyle: {
colourPrimary: string,
colourSecondary?: string,
colourTertiary?: string,
hat?: string
}): BlockStyle {
protected validatedBlockStyle_(blockStyle: Partial<BlockStyle>): BlockStyle {
// Make a new object with all of the same properties.
const valid = {} as BlockStyle;
if (blockStyle) {
Expand Down
8 changes: 0 additions & 8 deletions core/renderers/common/path_object.ts
Expand Up @@ -137,10 +137,6 @@ export class PathObject implements IPathObject {
* @internal
*/
applyColour(block: BlockSvg) {
if (!this.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
this.svgPath.setAttribute('stroke', this.style.colourTertiary);
this.svgPath.setAttribute('fill', this.style.colourPrimary);

Expand Down Expand Up @@ -199,10 +195,6 @@ export class PathObject implements IPathObject {
*/
protected updateShadow_(shadow: boolean) {
if (shadow) {
if (!this.style.colourSecondary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
this.svgPath.setAttribute('stroke', 'none');
this.svgPath.setAttribute('fill', this.style.colourSecondary);
}
Expand Down
12 changes: 0 additions & 12 deletions core/renderers/zelos/path_object.ts
Expand Up @@ -77,19 +77,11 @@ export class PathObject extends BasePathObject {
// Set shadow stroke colour.
const parent = block.getParent();
if (block.isShadow() && parent) {
if (!parent.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
this.svgPath.setAttribute('stroke', parent.style.colourTertiary);
}

// Apply colour to outlines.
for (const outline of this.outlines.values()) {
if (!this.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
outline.setAttribute('fill', this.style.colourTertiary);
}
}
Expand Down Expand Up @@ -183,10 +175,6 @@ export class PathObject extends BasePathObject {
setOutlinePath(name: string, pathString: string) {
const outline = this.getOutlinePath_(name);
outline.setAttribute('d', pathString);
if (!this.style.colourTertiary) {
throw new Error(
'The renderer did not properly initialize the block style');
}
outline.setAttribute('fill', this.style.colourTertiary);
}

Expand Down
11 changes: 6 additions & 5 deletions core/theme.ts
Expand Up @@ -17,7 +17,7 @@ import * as object from './utils/object.js';


export interface ITheme {
blockStyles?: {[key: string]: BlockStyle};
blockStyles?: {[key: string]: Partial<BlockStyle>};
categoryStyles?: {[key: string]: CategoryStyle};
componentStyles?: ComponentStyle;
fontStyle?: FontStyle;
Expand Down Expand Up @@ -58,7 +58,8 @@ export class Theme implements ITheme {
* @param opt_componentStyles A map of Blockly component names to style value.
*/
constructor(
public name: string, opt_blockStyles?: {[key: string]: BlockStyle},
public name: string,
opt_blockStyles?: {[key: string]: Partial<BlockStyle>},
opt_categoryStyles?: {[key: string]: CategoryStyle},
opt_componentStyles?: ComponentStyle) {
/** The block styles map. */
Expand Down Expand Up @@ -187,9 +188,9 @@ export class Theme implements ITheme {
export namespace Theme {
export interface BlockStyle {
colourPrimary: string;
colourSecondary?: string;
colourTertiary?: string;
hat?: string;
colourSecondary: string;
colourTertiary: string;
hat: string;
}

export interface CategoryStyle {
Expand Down