Skip to content

Commit

Permalink
refactor!: Improve ability to use CSS to style Blockly. (#8647)
Browse files Browse the repository at this point in the history
* refactor!: Rename blocklyTreeIconClosed to blocklyToolboxCategoryIconClosed.

* refactor!: Rename blocklyTreeLabel to blocklyToolboxCategoryLabel

* refactor!: Rename blocklyToolboxDiv to blocklyToolbox.

* refactor: remove unreferenced CSS classes.

* refactor!: Remove the blocklyArrowTop and blocklyArrowBottom classes.

* feat: Add a blocklyTextInputField class to text fields.
  • Loading branch information
gonfunko authored Nov 7, 2024
1 parent 2523093 commit d804c1a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 42 deletions.
14 changes: 0 additions & 14 deletions core/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,12 @@ let content = `
z-index: -1;
background-color: inherit;
border-color: inherit;
}
.blocklyArrowTop {
border-top: 1px solid;
border-left: 1px solid;
border-top-left-radius: 4px;
border-color: inherit;
}
.blocklyArrowBottom {
border-bottom: 1px solid;
border-right: 1px solid;
border-bottom-right-radius: 4px;
border-color: inherit;
}
.blocklyHighlightedConnectionPath {
fill: none;
stroke: #fc3;
Expand Down Expand Up @@ -243,10 +233,6 @@ let content = `
cursor: inherit;
}
.blocklyFieldDropdown:not(.blocklyHidden) {
display: block;
}
.blocklyIconGroup {
cursor: default;
}
Expand Down
17 changes: 5 additions & 12 deletions core/dropdowndiv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,19 +697,12 @@ function positionInternal(

// Update arrow CSS.
if (metrics.arrowVisible) {
const x = metrics.arrowX;
const y = metrics.arrowY;
const rotation = metrics.arrowAtTop ? 45 : 225;
arrow.style.display = '';
arrow.style.transform =
'translate(' +
metrics.arrowX +
'px,' +
metrics.arrowY +
'px) rotate(45deg)';
arrow.setAttribute(
'class',
metrics.arrowAtTop
? 'blocklyDropDownArrow blocklyArrowTop'
: 'blocklyDropDownArrow blocklyArrowBottom',
);
arrow.style.transform = `translate(${x}px, ${y}px) rotate(${rotation}deg)`;
arrow.setAttribute('class', 'blocklyDropDownArrow');
} else {
arrow.style.display = 'none';
}
Expand Down
8 changes: 8 additions & 0 deletions core/field_textinput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from './field_input.js';
import * as fieldRegistry from './field_registry.js';
import * as parsing from './utils/parsing.js';
import * as dom from './utils/dom.js';

/**
* Class for an editable text field.
Expand Down Expand Up @@ -49,6 +50,13 @@ export class FieldTextInput extends FieldInput<string> {
super(value, validator, config);
}

override initView() {
super.initView();
if (this.fieldGroup_) {
dom.addClass(this.fieldGroup_, 'blocklyTextInputField');
}
}

/**
* Ensure that the input value casts to a valid string.
*
Expand Down
24 changes: 12 additions & 12 deletions core/toolbox/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ export class ToolboxCategory
'row': 'blocklyToolboxCategory',
'rowcontentcontainer': 'blocklyTreeRowContentContainer',
'icon': 'blocklyToolboxCategoryIcon',
'label': 'blocklyTreeLabel',
'label': 'blocklyToolboxCategoryLabel',
'contents': 'blocklyToolboxCategoryGroup',
'selected': 'blocklyToolboxSelected',
'openicon': 'blocklyToolboxCategoryIconOpen',
'closedicon': 'blocklyTreeIconClosed',
'closedicon': 'blocklyToolboxCategoryIconClosed',
};
}

Expand Down Expand Up @@ -663,11 +663,11 @@ Css.register(`
background-color: rgba(255, 255, 255, .2);
}
.blocklyToolboxDiv[layout="h"] .blocklyToolboxCategoryContainer {
.blocklyToolbox[layout="h"] .blocklyToolboxCategoryContainer {
margin: 1px 5px 1px 0;
}
.blocklyToolboxDiv[dir="RTL"][layout="h"] .blocklyToolboxCategoryContainer {
.blocklyToolbox[dir="RTL"][layout="h"] .blocklyToolboxCategoryContainer {
margin: 1px 0 1px 5px;
}
Expand All @@ -679,7 +679,7 @@ Css.register(`
white-space: nowrap;
}
.blocklyToolboxDiv[dir="RTL"] .blocklyToolboxCategory {
.blocklyToolbox[dir="RTL"] .blocklyToolboxCategory {
margin-left: 8px;
padding-right: 0;
}
Expand All @@ -692,19 +692,19 @@ Css.register(`
width: 16px;
}
.blocklyTreeIconClosed {
.blocklyToolboxCategoryIconClosed {
background-position: -32px -1px;
}
.blocklyToolboxDiv[dir="RTL"] .blocklyTreeIconClosed {
.blocklyToolbox[dir="RTL"] .blocklyToolboxCategoryIconClosed {
background-position: 0 -1px;
}
.blocklyToolboxSelected>.blocklyTreeIconClosed {
.blocklyToolboxSelected>.blocklyToolboxCategoryIconClosed {
background-position: -32px -17px;
}
.blocklyToolboxDiv[dir="RTL"] .blocklyToolboxSelected>.blocklyTreeIconClosed {
.blocklyToolbox[dir="RTL"] .blocklyToolboxSelected>.blocklyToolboxCategoryIconClosed {
background-position: 0 -17px;
}
Expand All @@ -716,18 +716,18 @@ Css.register(`
background-position: -16px -17px;
}
.blocklyTreeLabel {
.blocklyToolboxCategoryLabel {
cursor: default;
font: 16px sans-serif;
padding: 0 3px;
vertical-align: middle;
}
.blocklyToolboxDelete .blocklyTreeLabel {
.blocklyToolboxDelete .blocklyToolboxCategoryLabel {
cursor: url("<<<PATH>>>/handdelete.cur"), auto;
}
.blocklyToolboxSelected .blocklyTreeLabel {
.blocklyToolboxSelected .blocklyToolboxCategoryLabel {
color: #fff;
}
`);
Expand Down
2 changes: 1 addition & 1 deletion core/toolbox/separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Css.register(`
margin: 5px 0;
}
.blocklyToolboxDiv[layout="h"] .blocklyTreeSeparator {
.blocklyToolbox[layout="h"] .blocklyTreeSeparator {
border-right: solid #e5e5e5 1px;
border-bottom: none;
height: auto;
Expand Down
4 changes: 2 additions & 2 deletions core/toolbox/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class Toolbox
protected createContainer_(): HTMLDivElement {
const toolboxContainer = document.createElement('div');
toolboxContainer.setAttribute('layout', this.isHorizontal() ? 'h' : 'v');
dom.addClass(toolboxContainer, 'blocklyToolboxDiv');
dom.addClass(toolboxContainer, 'blocklyToolbox');
toolboxContainer.setAttribute('dir', this.RTL ? 'RTL' : 'LTR');
return toolboxContainer;
}
Expand Down Expand Up @@ -1107,7 +1107,7 @@ Css.register(`
}
/* Category tree in Toolbox. */
.blocklyToolboxDiv {
.blocklyToolbox {
user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/toolbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ suite('Toolbox', function () {
test('Init called -> HtmlDiv is inserted before parent node', function () {
const toolboxDiv = Blockly.common.getMainWorkspace().getInjectionDiv()
.childNodes[0];
assert.equal(toolboxDiv.className, 'blocklyToolboxDiv');
assert.equal(toolboxDiv.className, 'blocklyToolbox');
});
test('Init called -> Toolbox is subscribed to background and foreground colour', function () {
const themeManager = this.toolbox.workspace_.getThemeManager();
Expand Down

0 comments on commit d804c1a

Please sign in to comment.