@@ -128,4 +128,137 @@ export class KeyboardNavigation {
128128 toggleShortcutDialog ( ) : void {
129129 this . navigationController . shortcutDialog . toggle ( this . workspace ) ;
130130 }
131+
132+ /**
133+ * Register CSS used by the plugin.
134+ * This is broken up into sections by purpose, with some notes about
135+ * where it should eventually live.
136+ * Must be called before `Blockly.inject`.
137+ */
138+ static registerKeyboardNavigationStyles ( ) {
139+ // Enable the delete icon for comments.
140+ //
141+ // This should remain in the plugin for the time being because we do
142+ // not want to display the delete icon by default.
143+ Blockly . Css . register ( `
144+ .blocklyDeleteIcon {
145+ display: block;
146+ }
147+ ` ) ;
148+
149+ // Set variables that will be used to control the appearance of the
150+ // focus indicators. Attach them to the injectionDiv since they will
151+ // apply to things contained therein.
152+ //
153+ // This should be moved to core, either to core/css.ts
154+ // or to core/renderers/.
155+ Blockly . Css . register ( `
156+ .injectionDiv {
157+ --blockly-active-node-color: #fff200;
158+ --blockly-active-tree-color: #60a5fa;
159+ --blockly-selection-width: 3px;
160+ }
161+ ` ) ;
162+
163+ // Styling focusing blocks, connections and fields.
164+ //
165+ // This should be moved to core, being integrated into the
166+ // existing styling of renderers in core/renderers/*/constants.ts.
167+ Blockly . Css . register ( `
168+ /* Blocks, connections and fields. */
169+ .blocklyKeyboardNavigation
170+ .blocklyActiveFocus:is(.blocklyPath, .blocklyHighlightedConnectionPath),
171+ .blocklyKeyboardNavigation
172+ .blocklyActiveFocus.blocklyField
173+ > .blocklyFieldRect,
174+ .blocklyKeyboardNavigation
175+ .blocklyActiveFocus.blocklyIconGroup
176+ > .blocklyIconShape:first-child {
177+ stroke: var(--blockly-active-node-color);
178+ stroke-width: var(--blockly-selection-width);
179+ }
180+ .blocklyKeyboardNavigation
181+ .blocklyPassiveFocus:is(
182+ .blocklyPath:not(.blocklyFlyout .blocklyPath),
183+ .blocklyHighlightedConnectionPath
184+ ),
185+ .blocklyKeyboardNavigation
186+ .blocklyPassiveFocus.blocklyField
187+ > .blocklyFieldRect,
188+ .blocklyKeyboardNavigation
189+ .blocklyPassiveFocus.blocklyIconGroup
190+ > .blocklyIconShape:first-child {
191+ stroke: var(--blockly-active-node-color);
192+ stroke-dasharray: 5px 3px;
193+ stroke-width: var(--blockly-selection-width);
194+ }
195+ .blocklyKeyboardNavigation
196+ .blocklyPassiveFocus.blocklyHighlightedConnectionPath {
197+ /* The connection path is being unexpectedly hidden in core */
198+ display: unset !important;
199+ }
200+ ` ) ;
201+
202+ // Styling for focusing the toolbox and flyout.
203+ //
204+ // This should be moved to core, to core/css.ts if not to somewhere
205+ // more specific in core/toolbox/.
206+ Blockly . Css . register ( `
207+ .blocklyKeyboardNavigation .blocklyFlyout:has(.blocklyActiveFocus),
208+ .blocklyKeyboardNavigation .blocklyToolbox:has(.blocklyActiveFocus),
209+ .blocklyKeyboardNavigation
210+ .blocklyActiveFocus:is(.blocklyFlyout, .blocklyToolbox) {
211+ outline-offset: calc(var(--blockly-selection-width) * -1);
212+ outline: var(--blockly-selection-width) solid
213+ var(--blockly-active-tree-color);
214+ }
215+ .blocklyKeyboardNavigation
216+ .blocklyToolboxCategoryContainer:focus-visible {
217+ outline: none;
218+ }
219+ ` ) ;
220+
221+ // Styling for focusing the Workspace.
222+ //
223+ // This should be move to core, probably to core/css.ts.
224+ Blockly . Css . register ( `
225+ .blocklyKeyboardNavigation
226+ .blocklyWorkspace:has(.blocklyActiveFocus)
227+ .blocklyWorkspaceFocusRing,
228+ .blocklyKeyboardNavigation
229+ .blocklySvg:has(~ .blocklyBlockDragSurface .blocklyActiveFocus)
230+ .blocklyWorkspaceFocusRing,
231+ .blocklyKeyboardNavigation
232+ .blocklyWorkspace.blocklyActiveFocus
233+ .blocklyWorkspaceFocusRing {
234+ stroke: var(--blockly-active-tree-color);
235+ stroke-width: calc(var(--blockly-selection-width) * 2);
236+ }
237+ .blocklyKeyboardNavigation
238+ .blocklyWorkspace.blocklyActiveFocus
239+ .blocklyWorkspaceSelectionRing {
240+ stroke: var(--blockly-active-node-color);
241+ stroke-width: var(--blockly-selection-width);
242+ }
243+ ` ) ;
244+
245+ // Keyboard-nav-specific styling for the context menu.
246+ //
247+ // This should remain in the plugin for the time being because the
248+ // classes selected are currently only defined in the plugin.
249+ Blockly . Css . register ( `
250+ .blocklyRTL .blocklyMenuItemContent .blocklyShortcutContainer {
251+ flex-direction: row-reverse;
252+ }
253+ .blocklyMenuItemContent .blocklyShortcutContainer {
254+ width: 100%;
255+ display: flex;
256+ justify-content: space-between;
257+ gap: 16px;
258+ }
259+ .blocklyMenuItemContent .blocklyShortcutContainer .blocklyShortcut {
260+ color: #ccc;
261+ }
262+ ` ) ;
263+ }
131264}
0 commit comments