pxt-core
Version:
Microsoft MakeCode provides Blocks / JavaScript / Python tools and editors
110 lines (109 loc) • 4.23 kB
TypeScript
import * as Blockly from "blockly";
/**
* An icon which allows the user to add comment text to a block.
*/
export declare class CommentIcon extends Blockly.icons.Icon implements Blockly.IHasBubble {
protected readonly sourceBlock: Blockly.Block;
/** The type string used to identify this icon. */
static readonly TYPE: Blockly.icons.IconType<import("blockly/core/interfaces/i_comment_icon").ICommentIcon>;
/**
* The weight this icon has relative to other icons. Icons with more positive
* weight values are rendered farther toward the end of the block.
*/
static readonly WEIGHT = 3;
/** The bubble used to show editable text to the user. */
private textInputBubble;
/** The text of this comment. */
private text;
/** The size of this comment (which is applied to the editable bubble). */
private bubbleSize;
/**
* The visibility of the bubble for this comment.
*
* This is used to track what the visibile state /should/ be, not necessarily
* what it currently /is/. E.g. sometimes this will be true, but the block
* hasn't been rendered yet, so the bubble will not currently be visible.
*/
private bubbleVisiblity;
constructor(sourceBlock: Blockly.Block);
getType(): Blockly.icons.IconType<CommentIcon>;
initView(pointerdownListener: (e: PointerEvent) => void): void;
dispose(): void;
getWeight(): number;
getSize(): Blockly.utils.Size;
applyColour(): void;
/**
* Updates the state of the bubble (editable / noneditable) to reflect the
* state of the bubble if the bubble is currently shown.
*/
updateEditable(): Promise<void>;
onLocationChange(blockOrigin: Blockly.utils.Coordinate): void;
/** Sets the text of this comment. Updates any bubbles if they are visible. */
setText(text: string): void;
/** Returns the text of this comment. */
getText(): string;
/**
* Sets the size of the editable bubble for this comment. Resizes the
* bubble if it is visible.
*/
setBubbleSize(size: Blockly.utils.Size): void;
/** @returns the size of the editable bubble for this comment. */
getBubbleSize(): Blockly.utils.Size;
/**
* @returns the state of the comment as a JSON serializable value if the
* comment has text. Otherwise returns null.
*/
saveState(): CommentState | null;
/** Applies the given state to this comment. */
loadState(state: CommentState): void;
setBubbleLocation(location: Blockly.utils.Coordinate): void;
getBubbleLocation(): Blockly.utils.Coordinate | undefined;
onClick(): void;
isClickableInFlyout(): boolean;
/**
* Updates the text of this comment in response to changes in the text of
* the input bubble.
*/
onTextChange(): void;
/**
* Updates the size of this icon in response to changes in the size of the
* input bubble.
*/
onSizeChange(): void;
onPositionChange(): void;
bubbleIsVisible(): boolean;
setBubbleVisible(visible: boolean): Promise<void>;
getBubble(): Blockly.IBubble | null;
/**
* Shows the editable text bubble for this comment, and adds change listeners
* to update the state of this icon in response to changes in the bubble.
*/
private showEditableBubble;
/** Shows the non editable text bubble for this comment. */
private showNonEditableBubble;
/** Hides any open bubbles owned by this comment. */
private hideBubble;
/**
* @returns the location the bubble should be anchored to.
* I.E. the middle of this icon.
*/
private getAnchorLocation;
/**
* @returns the rect the bubble should avoid overlapping.
* I.E. the block that owns this icon.
*/
private getBubbleOwnerRect;
private getSavedOffsetData;
private clearSavedOffsetData;
}
/** 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;
}