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

feat: Add css classes from json block definitions #8377

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/block_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,4 +1720,20 @@ export class BlockSvg
traverseJson(json as unknown as {[key: string]: unknown});
return [json];
}

override jsonInit(json: AnyDuringMigration): void {
super.jsonInit(json);

if (json['classes']) {
let classesToAdd = '';

if (Array.isArray(json['classes'])) {
classesToAdd = json['classes'].join(' ');
} else {
classesToAdd = json['classes'];
}

this.addClass(classesToAdd);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can simplify this using a ternary operator.

Suggested change
let classesToAdd = '';
if (Array.isArray(json['classes'])) {
classesToAdd = json['classes'].join(' ');
} else {
classesToAdd = json['classes'];
}
this.addClass(classesToAdd);
this.addClass(Array.isArray(json['classes']) ? json['classes'].join(' ') : json['classes']);

You'll probably need to run npm run format in the root directory after applying this change to handle the line wrapping.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, thanks for pointing that out! Updated that and formatted using npm run format.

}
}
}
Loading