From 2fa6f5b95427cf54d0069bc837a9318738154b93 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Mon, 1 Apr 2024 21:34:48 +0000 Subject: [PATCH] fix: comment icon interface re serialization (#7964) * fix: comment icon interface re serialization * chore: fix test --- core/icons/comment_icon.ts | 8 ++++++++ core/interfaces/i_comment_icon.ts | 11 +++++++++-- tests/mocha/block_test.js | 6 ++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/icons/comment_icon.ts b/core/icons/comment_icon.ts index 6042b44e2..591fe9727 100644 --- a/core/icons/comment_icon.ts +++ b/core/icons/comment_icon.ts @@ -349,10 +349,18 @@ export class CommentIcon extends Icon implements IHasBubble, ISerializable { } } +/** The save state format for a comment icon. */ export interface CommentState { + /** The text of the comment. */ text?: string; + + /** True if the comment is open, false otherwise. */ pinned?: boolean; + + /** The height of the comment bubble. */ height?: number; + + /** The width of the comment bubble. */ width?: number; } diff --git a/core/interfaces/i_comment_icon.ts b/core/interfaces/i_comment_icon.ts index d1e18534f..09b071110 100644 --- a/core/interfaces/i_comment_icon.ts +++ b/core/interfaces/i_comment_icon.ts @@ -4,12 +4,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -import {IconType} from '../icons.js'; +import {IconType} from '../icons/icon_types.js'; +import {CommentState} from '../icons/comment_icon.js'; import {IIcon, isIcon} from './i_icon.js'; import {Size} from '../utils/size.js'; import {IHasBubble, hasBubble} from './i_has_bubble.js'; +import {ISerializable, isSerializable} from './i_serializable.js'; -export interface ICommentIcon extends IIcon, IHasBubble { +export interface ICommentIcon extends IIcon, IHasBubble, ISerializable { setText(text: string): void; getText(): string; @@ -17,6 +19,10 @@ export interface ICommentIcon extends IIcon, IHasBubble { setBubbleSize(size: Size): void; getBubbleSize(): Size; + + saveState(): CommentState; + + loadState(state: CommentState): void; } /** Checks whether the given object is an ICommentIcon. */ @@ -24,6 +30,7 @@ export function isCommentIcon(obj: Object): obj is ICommentIcon { return ( isIcon(obj) && hasBubble(obj) && + isSerializable(obj) && (obj as any)['setText'] !== undefined && (obj as any)['getText'] !== undefined && (obj as any)['setBubbleSize'] !== undefined && diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 3184d409d..13514ef74 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1392,6 +1392,12 @@ suite('Blocks', function () { } setBubbleVisible() {} + + saveState() { + return {}; + } + + loadState() {} } setup(function () {