Files
blockly/core/toolbox/separator.ts
Christopher Allen b0a7c004a9 refactor(build): Delete Closure Library (#7415)
* fix(build): Restore erroneously-deleted filter function

  This was deleted in PR #7406 as it was mainly being used to
  filter core/ vs. test/mocha/ deps into separate deps files -
  but it turns out also to be used for filtering error
  messages too.  Oops.

* refactor(tests): Migrate advanced compilation test to ES Modules

* refactor(build): Migrate main.js to TypeScript

  This turns out to be pretty straight forward, even if it would
  cause crashing if one actually tried to import this module
  instead of just feeding it to Closure Compiler.

* chore(build): Remove goog.declareModuleId calls

  Replace goog.declareModuleId calls with a comment recording the
  former module ID for posterity (or at least until we decide
  how to reformat the renamings file.

* chore(tests): Delete closure/goog/*

  For the moment we still need something to serve as base.js for
  the benefit of closure-make-deps, so we keep a vestigial
  base.js around, containing only the @provideGoog declaration.

* refactor(build): Remove vestigial base.js

  By changing slightly the command line arguments to
  closure-make-deps and closure-calculate-chunks the need to have
  any base.js is eliminated.

* chore: Typo fix for PR #7415
2023-08-31 00:24:47 +01:00

106 lines
2.5 KiB
TypeScript

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* A separator used for separating toolbox categories.
*
* @class
*/
// Former goog.module ID: Blockly.ToolboxSeparator
import * as Css from '../css.js';
import type {IToolbox} from '../interfaces/i_toolbox.js';
import * as registry from '../registry.js';
import * as dom from '../utils/dom.js';
import type * as toolbox from '../utils/toolbox.js';
import {ToolboxItem} from './toolbox_item.js';
/**
* Class for a toolbox separator. This is the thin visual line that appears on
* the toolbox. This item is not interactable.
*/
export class ToolboxSeparator extends ToolboxItem {
/** Name used for registering a toolbox separator. */
static registrationName = 'sep';
/** All the CSS class names that are used to create a separator. */
protected cssConfig_: CssConfig = {'container': 'blocklyTreeSeparator'};
private htmlDiv_: HTMLDivElement | null = null;
/**
* @param separatorDef The information needed to create a separator.
* @param toolbox The parent toolbox for the separator.
*/
constructor(separatorDef: toolbox.SeparatorInfo, toolbox: IToolbox) {
super(separatorDef, toolbox);
const cssConfig =
separatorDef['cssconfig'] || (separatorDef as any)['cssConfig'];
Object.assign(this.cssConfig_, cssConfig);
}
override init() {
this.createDom_();
}
/**
* Creates the DOM for a separator.
*
* @returns The parent element for the separator.
*/
protected createDom_(): HTMLDivElement {
const container = document.createElement('div');
const className = this.cssConfig_['container'];
if (className) {
dom.addClass(container, className);
}
this.htmlDiv_ = container;
return container;
}
override getDiv() {
return this.htmlDiv_ as HTMLDivElement;
}
override dispose() {
dom.removeNode(this.htmlDiv_ as HTMLDivElement);
}
}
export namespace ToolboxSeparator {
export interface CssConfig {
container: string | undefined;
}
}
export type CssConfig = ToolboxSeparator.CssConfig;
/** CSS for Toolbox. See css.js for use. */
Css.register(`
.blocklyTreeSeparator {
border-bottom: solid #e5e5e5 1px;
height: 0;
margin: 5px 0;
}
.blocklyToolboxDiv[layout="h"] .blocklyTreeSeparator {
border-right: solid #e5e5e5 1px;
border-bottom: none;
height: auto;
margin: 0 5px 0 5px;
padding: 5px 0;
width: 0;
}
`);
registry.register(
registry.Type.TOOLBOX_ITEM,
ToolboxSeparator.registrationName,
ToolboxSeparator,
);