feat: Add a method for creating flyout options (#8829)

This commit is contained in:
RoboErikG
2025-03-28 14:02:28 -07:00
committed by GitHub
parent ad6bbbc740
commit 212f13af08
3 changed files with 25 additions and 41 deletions

View File

@@ -13,7 +13,6 @@
// Unused import preserved for side-effects. Remove if unneeded.
import {BlockSvg} from '../block_svg.js';
import type {BlocklyOptions} from '../blockly_options.js';
import * as browserEvents from '../browser_events.js';
import * as common from '../common.js';
import {ComponentManager} from '../component_manager.js';
@@ -33,7 +32,6 @@ import {isSelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.j
import type {IStyleable} from '../interfaces/i_styleable.js';
import type {IToolbox} from '../interfaces/i_toolbox.js';
import type {IToolboxItem} from '../interfaces/i_toolbox_item.js';
import {Options} from '../options.js';
import * as registry from '../registry.js';
import type {KeyboardShortcut} from '../shortcut_registry.js';
import * as Touch from '../touch.js';
@@ -325,19 +323,7 @@ export class Toolbox
*/
protected createFlyout_(): IFlyout {
const workspace = this.workspace_;
// TODO (#4247): Look into adding a makeFlyout method to Blockly Options.
const workspaceOptions = new Options({
'parentWorkspace': workspace,
'rtl': workspace.RTL,
'oneBasedIndex': workspace.options.oneBasedIndex,
'horizontalLayout': workspace.horizontalLayout,
'renderer': workspace.options.renderer,
'rendererOverrides': workspace.options.rendererOverrides,
'modalInputs': workspace.options.modalInputs,
'move': {
'scrollbars': true,
},
} as BlocklyOptions);
const workspaceOptions = workspace.copyOptionsForFlyout();
// Options takes in either 'end' or 'start'. This has already been parsed to
// be either 0 or 1, so set it after.
workspaceOptions.toolboxPosition = workspace.options.toolboxPosition;

View File

@@ -12,7 +12,6 @@
// Former goog.module ID: Blockly.Trashcan
// Unused import preserved for side-effects. Remove if unneeded.
import type {BlocklyOptions} from './blockly_options.js';
import * as browserEvents from './browser_events.js';
import {ComponentManager} from './component_manager.js';
import {DeleteArea} from './delete_area.js';
@@ -26,7 +25,6 @@ import type {IDraggable} from './interfaces/i_draggable.js';
import type {IFlyout} from './interfaces/i_flyout.js';
import type {IPositionable} from './interfaces/i_positionable.js';
import type {UiMetrics} from './metrics_manager.js';
import {Options} from './options.js';
import * as uiPosition from './positionable_helpers.js';
import * as registry from './registry.js';
import type * as blocks from './serialization/blocks.js';
@@ -103,18 +101,7 @@ export class Trashcan
}
// Create flyout options.
const flyoutWorkspaceOptions = new Options({
'scrollbars': true,
'parentWorkspace': this.workspace,
'rtl': this.workspace.RTL,
'oneBasedIndex': this.workspace.options.oneBasedIndex,
'renderer': this.workspace.options.renderer,
'rendererOverrides': this.workspace.options.rendererOverrides,
'modalInputs': this.workspace.options.modalInputs,
'move': {
'scrollbars': true,
},
} as BlocklyOptions);
const flyoutWorkspaceOptions = this.workspace.copyOptionsForFlyout();
// Create vertical or horizontal flyout.
if (this.workspace.horizontalLayout) {
flyoutWorkspaceOptions.toolboxPosition =

View File

@@ -938,6 +938,28 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
this.svgGroup_.appendChild(svgZoomControls);
}
/**
* Creates a new set of options from this workspace's options with just the
* values that are relevant to a flyout.
*
* @returns A subset of this workspace's options.
*/
copyOptionsForFlyout(): Options {
return new Options({
'parentWorkspace': this,
'rtl': this.RTL,
'oneBasedIndex': this.options.oneBasedIndex,
'horizontalLayout': this.horizontalLayout,
'renderer': this.options.renderer,
'rendererOverrides': this.options.rendererOverrides,
'plugins': this.options.plugins,
'modalInputs': this.options.modalInputs,
'move': {
'scrollbars': true,
},
} as BlocklyOptions);
}
/**
* Add a flyout element in an element with the given tag name.
*
@@ -946,18 +968,7 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
* @internal
*/
addFlyout(tagName: string | Svg<SVGSVGElement> | Svg<SVGGElement>): Element {
const workspaceOptions = new Options({
'parentWorkspace': this,
'rtl': this.RTL,
'oneBasedIndex': this.options.oneBasedIndex,
'horizontalLayout': this.horizontalLayout,
'renderer': this.options.renderer,
'rendererOverrides': this.options.rendererOverrides,
'modalInputs': this.options.modalInputs,
'move': {
'scrollbars': true,
},
} as BlocklyOptions);
const workspaceOptions = this.copyOptionsForFlyout();
workspaceOptions.toolboxPosition = this.options.toolboxPosition;
if (this.horizontalLayout) {
const HorizontalFlyout = registry.getClassFromOptions(