From 1e7fb6fc4d7cb66252139235b75031b11c2e16e1 Mon Sep 17 00:00:00 2001 From: Shreyans Pathak Date: Tue, 16 Jul 2024 06:39:26 -0400 Subject: [PATCH 1/3] fix: override `jsonInit` method to add css classes --- core/block_svg.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/block_svg.ts b/core/block_svg.ts index adef213d5fc..3f4ad91f201 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -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); + } + } } From 6905d528ee5703110331daab125ed588029205e2 Mon Sep 17 00:00:00 2001 From: Shreyans Pathak Date: Tue, 16 Jul 2024 06:40:30 -0400 Subject: [PATCH 2/3] fix: lint --- core/block_svg.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/block_svg.ts b/core/block_svg.ts index 3f4ad91f201..f40f6737096 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -1721,7 +1721,7 @@ export class BlockSvg return [json]; } - override jsonInit(json: AnyDuringMigration): void { + override jsonInit(json: AnyDuringMigration): void { super.jsonInit(json); if (json['classes']) { From b834c1ab51ef2e9656993e95353d718f9e830f03 Mon Sep 17 00:00:00 2001 From: Shreyans Pathak Date: Tue, 16 Jul 2024 18:03:04 +0000 Subject: [PATCH 3/3] refactor: simplify logic --- core/block_svg.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/block_svg.ts b/core/block_svg.ts index f40f6737096..a5b7f8d1049 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -1723,17 +1723,13 @@ export class BlockSvg 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); + if (json['classes']) { + this.addClass( + Array.isArray(json['classes']) + ? json['classes'].join(' ') + : json['classes'], + ); } } }