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: comment icon interface re serialization #7964

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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