File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @license
3+ * Copyright 2025 Google LLC
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ import * as Blockly from 'blockly/core' ;
8+
9+ /**
10+ * Configuration options for toasts.
11+ */
12+ interface HtmlToastOptions extends Blockly . ToastOptions {
13+ element ?: HTMLElement ;
14+ }
15+
16+ /**
17+ * Custom toast implementation that supports HTML elements in toast messages.
18+ */
19+ class HtmlToast extends Blockly . Toast {
20+ /**
21+ * Creates the body of the toast for display.
22+ *
23+ * @param workspace The workspace the toast will be displayed on.
24+ * @param options Configuration options for toast appearance/behavior.
25+ * @returns The body for the toast.
26+ */
27+ protected static override createDom (
28+ workspace : Blockly . WorkspaceSvg ,
29+ options : Blockly . ToastOptions ,
30+ ) {
31+ const dom = super . createDom ( workspace , options ) ;
32+ const contents = dom . querySelector ( 'div' ) ;
33+ if (
34+ contents &&
35+ 'element' in options &&
36+ options . element instanceof HTMLElement
37+ ) {
38+ contents . innerHTML = '' ;
39+ contents . appendChild ( options . element ) ;
40+ }
41+ return dom ;
42+ }
43+ }
44+
45+ /**
46+ * Registers HtmlToast as the default toast implementation for Blockly. */
47+ export function registerHtmlToast ( ) {
48+ Blockly . dialog . setToast ( HtmlToast . show . bind ( HtmlToast ) ) ;
49+ }
Original file line number Diff line number Diff line change 77import * as Blockly from 'blockly/core' ;
88import { NavigationController } from './navigation_controller' ;
99import { enableBlocksOnDrag } from './disabled_blocks' ;
10+ import { registerHtmlToast } from './html_toast' ;
1011
1112/** Plugin for keyboard navigation. */
1213export class KeyboardNavigation {
@@ -82,6 +83,8 @@ export class KeyboardNavigation {
8283 } ) ;
8384 workspace . getSvgGroup ( ) . appendChild ( this . workspaceFocusRing ) ;
8485 this . resizeWorkspaceRings ( ) ;
86+
87+ registerHtmlToast ( ) ;
8588 }
8689
8790 private resizeWorkspaceRings ( ) {
You can’t perform that action at this time.
0 commit comments