Skip to content

Commit 212f13a

Browse files
authored
feat: Add a method for creating flyout options (#8829)
1 parent ad6bbbc commit 212f13a

3 files changed

Lines changed: 19 additions & 35 deletions

File tree

core/toolbox/toolbox.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
// Unused import preserved for side-effects. Remove if unneeded.
1515
import {BlockSvg} from '../block_svg.js';
16-
import type {BlocklyOptions} from '../blockly_options.js';
1716
import * as browserEvents from '../browser_events.js';
1817
import * as common from '../common.js';
1918
import {ComponentManager} from '../component_manager.js';
@@ -33,7 +32,6 @@ import {isSelectableToolboxItem} from '../interfaces/i_selectable_toolbox_item.j
3332
import type {IStyleable} from '../interfaces/i_styleable.js';
3433
import type {IToolbox} from '../interfaces/i_toolbox.js';
3534
import type {IToolboxItem} from '../interfaces/i_toolbox_item.js';
36-
import {Options} from '../options.js';
3735
import * as registry from '../registry.js';
3836
import type {KeyboardShortcut} from '../shortcut_registry.js';
3937
import * as Touch from '../touch.js';
@@ -325,19 +323,7 @@ export class Toolbox
325323
*/
326324
protected createFlyout_(): IFlyout {
327325
const workspace = this.workspace_;
328-
// TODO (#4247): Look into adding a makeFlyout method to Blockly Options.
329-
const workspaceOptions = new Options({
330-
'parentWorkspace': workspace,
331-
'rtl': workspace.RTL,
332-
'oneBasedIndex': workspace.options.oneBasedIndex,
333-
'horizontalLayout': workspace.horizontalLayout,
334-
'renderer': workspace.options.renderer,
335-
'rendererOverrides': workspace.options.rendererOverrides,
336-
'modalInputs': workspace.options.modalInputs,
337-
'move': {
338-
'scrollbars': true,
339-
},
340-
} as BlocklyOptions);
326+
const workspaceOptions = workspace.copyOptionsForFlyout();
341327
// Options takes in either 'end' or 'start'. This has already been parsed to
342328
// be either 0 or 1, so set it after.
343329
workspaceOptions.toolboxPosition = workspace.options.toolboxPosition;

core/trashcan.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// Former goog.module ID: Blockly.Trashcan
1313

1414
// Unused import preserved for side-effects. Remove if unneeded.
15-
import type {BlocklyOptions} from './blockly_options.js';
1615
import * as browserEvents from './browser_events.js';
1716
import {ComponentManager} from './component_manager.js';
1817
import {DeleteArea} from './delete_area.js';
@@ -26,7 +25,6 @@ import type {IDraggable} from './interfaces/i_draggable.js';
2625
import type {IFlyout} from './interfaces/i_flyout.js';
2726
import type {IPositionable} from './interfaces/i_positionable.js';
2827
import type {UiMetrics} from './metrics_manager.js';
29-
import {Options} from './options.js';
3028
import * as uiPosition from './positionable_helpers.js';
3129
import * as registry from './registry.js';
3230
import type * as blocks from './serialization/blocks.js';
@@ -103,18 +101,7 @@ export class Trashcan
103101
}
104102

105103
// Create flyout options.
106-
const flyoutWorkspaceOptions = new Options({
107-
'scrollbars': true,
108-
'parentWorkspace': this.workspace,
109-
'rtl': this.workspace.RTL,
110-
'oneBasedIndex': this.workspace.options.oneBasedIndex,
111-
'renderer': this.workspace.options.renderer,
112-
'rendererOverrides': this.workspace.options.rendererOverrides,
113-
'modalInputs': this.workspace.options.modalInputs,
114-
'move': {
115-
'scrollbars': true,
116-
},
117-
} as BlocklyOptions);
104+
const flyoutWorkspaceOptions = this.workspace.copyOptionsForFlyout();
118105
// Create vertical or horizontal flyout.
119106
if (this.workspace.horizontalLayout) {
120107
flyoutWorkspaceOptions.toolboxPosition =

core/workspace_svg.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,25 +939,36 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg {
939939
}
940940

941941
/**
942-
* Add a flyout element in an element with the given tag name.
942+
* Creates a new set of options from this workspace's options with just the
943+
* values that are relevant to a flyout.
943944
*
944-
* @param tagName What type of tag the flyout belongs in.
945-
* @returns The element containing the flyout DOM.
946-
* @internal
945+
* @returns A subset of this workspace's options.
947946
*/
948-
addFlyout(tagName: string | Svg<SVGSVGElement> | Svg<SVGGElement>): Element {
949-
const workspaceOptions = new Options({
947+
copyOptionsForFlyout(): Options {
948+
return new Options({
950949
'parentWorkspace': this,
951950
'rtl': this.RTL,
952951
'oneBasedIndex': this.options.oneBasedIndex,
953952
'horizontalLayout': this.horizontalLayout,
954953
'renderer': this.options.renderer,
955954
'rendererOverrides': this.options.rendererOverrides,
955+
'plugins': this.options.plugins,
956956
'modalInputs': this.options.modalInputs,
957957
'move': {
958958
'scrollbars': true,
959959
},
960960
} as BlocklyOptions);
961+
}
962+
963+
/**
964+
* Add a flyout element in an element with the given tag name.
965+
*
966+
* @param tagName What type of tag the flyout belongs in.
967+
* @returns The element containing the flyout DOM.
968+
* @internal
969+
*/
970+
addFlyout(tagName: string | Svg<SVGSVGElement> | Svg<SVGGElement>): Element {
971+
const workspaceOptions = this.copyOptionsForFlyout();
961972
workspaceOptions.toolboxPosition = this.options.toolboxPosition;
962973
if (this.horizontalLayout) {
963974
const HorizontalFlyout = registry.getClassFromOptions(

0 commit comments

Comments
 (0)