Skip to content

Commit

Permalink
fix: comment icon interface re serialization (#7964)
Browse files Browse the repository at this point in the history
* fix: comment icon interface re serialization

* chore: fix test
  • Loading branch information
BeksOmega authored Apr 1, 2024
1 parent 63eb4ec commit 2fa6f5b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/icons/comment_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions core/interfaces/i_comment_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
* 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;

setBubbleSize(size: Size): void;

getBubbleSize(): Size;

saveState(): CommentState;

loadState(state: CommentState): void;
}

/** Checks whether the given object is an ICommentIcon. */
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 &&
Expand Down
6 changes: 6 additions & 0 deletions tests/mocha/block_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,12 @@ suite('Blocks', function () {
}

setBubbleVisible() {}

saveState() {
return {};
}

loadState() {}
}

setup(function () {
Expand Down

0 comments on commit 2fa6f5b

Please sign in to comment.