mirror of
https://github.com/google/blockly.git
synced 2026-01-06 08:30:13 +01:00
fix!: refactor comment icon (#7128)
* fix: add basic comment icon * fix: add using comment icon * chore: delete old comment icon * chore: add docs to the comment icon * chore: move Comment to icons.CommentIcon * chore: mode properties to module level * chore: properly override and call super * chore: remove .comment and .commentIcon_ * chore: cleanup test * chore: deprecate getCommentIcon and getCommentText * chore: change imports to import type * chore: refactor code for paren peace * chore: fix lint and make it error * chore: remove change to block JS file * chore: fix css * chore: add renamings * chore: format
This commit is contained in:
22
core/xml.ts
22
core/xml.ts
@@ -12,6 +12,8 @@ import type {BlockSvg} from './block_svg.js';
|
||||
import type {Connection} from './connection.js';
|
||||
import * as eventUtils from './events/utils.js';
|
||||
import type {Field} from './field.js';
|
||||
import type {CommentIcon} from './icons/comment_icon.js';
|
||||
import {COMMENT_TYPE} from './icons/icon_types.js';
|
||||
import {inputTypes} from './inputs/input_types.js';
|
||||
import * as dom from './utils/dom.js';
|
||||
import {Size} from './utils/size.js';
|
||||
@@ -188,8 +190,9 @@ export function blockToDom(
|
||||
|
||||
const commentText = block.getCommentText();
|
||||
if (commentText) {
|
||||
const size = block.commentModel.size;
|
||||
const pinned = block.commentModel.pinned;
|
||||
const comment = block.getIcon(COMMENT_TYPE) as CommentIcon;
|
||||
const size = comment.getBubbleSize();
|
||||
const pinned = comment.bubbleIsVisible();
|
||||
|
||||
const commentElement = utilsXml.createElement('comment');
|
||||
commentElement.appendChild(utilsXml.createTextNode(commentText));
|
||||
@@ -720,17 +723,14 @@ function applyCommentTagNodes(xmlChildren: Element[], block: Block) {
|
||||
const height = parseInt(xmlChild.getAttribute('h') ?? '50', 10);
|
||||
|
||||
block.setCommentText(text);
|
||||
block.commentModel.pinned = pinned;
|
||||
const comment = block.getIcon(COMMENT_TYPE) as CommentIcon;
|
||||
if (!isNaN(width) && !isNaN(height)) {
|
||||
block.commentModel.size = new Size(width, height);
|
||||
}
|
||||
|
||||
if (pinned && (block as BlockSvg).getCommentIcon && !block.isInFlyout) {
|
||||
const blockSvg = block as BlockSvg;
|
||||
setTimeout(function () {
|
||||
blockSvg.getCommentIcon()!.setVisible(true);
|
||||
}, 1);
|
||||
comment.setBubbleSize(new Size(width, height));
|
||||
}
|
||||
// Set the pinned state of the bubble.
|
||||
comment.setBubbleVisible(pinned);
|
||||
// Actually show the bubble after the block has been rendered.
|
||||
setTimeout(() => comment.setBubbleVisible(pinned), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user