chore: use prettier instead of clang-format (#7014)

* chore: add and configure prettier

* chore: remove clang-format

* chore: remove clang-format config

* chore: lint additional ts files

* chore: fix lint errors in blocks

* chore: add prettier-ignore where needed

* chore: ignore js blocks when formatting

* chore: fix playground html syntax

* chore: fix yaml spacing from merge

* chore: convert text blocks to use arrow functions

* chore: format everything with prettier

* chore: fix lint unused imports in blocks
This commit is contained in:
Maribeth Bottorff
2023-05-10 16:01:39 -07:00
committed by GitHub
parent af991f5e1b
commit 88ff901a72
425 changed files with 29170 additions and 21169 deletions

View File

@@ -24,7 +24,6 @@ import {Rect} from './utils/rect.js';
import * as toolbox from './utils/toolbox.js';
import * as WidgetDiv from './widgetdiv.js';
/**
* Class for a flyout.
*/
@@ -43,7 +42,7 @@ export class VerticalFlyout extends Flyout {
* @param xyRatio Contains a y property which is a float between 0 and 1
* specifying the degree of scrolling and a similar x property.
*/
protected override setMetrics_(xyRatio: {x: number, y: number}) {
protected override setMetrics_(xyRatio: {x: number; y: number}) {
if (!this.isVisible()) {
return;
}
@@ -53,13 +52,15 @@ export class VerticalFlyout extends Flyout {
const absoluteMetrics = metricsManager.getAbsoluteMetrics();
if (typeof xyRatio.y === 'number') {
this.workspace_.scrollY =
-(scrollMetrics.top +
(scrollMetrics.height - viewMetrics.height) * xyRatio.y);
this.workspace_.scrollY = -(
scrollMetrics.top +
(scrollMetrics.height - viewMetrics.height) * xyRatio.y
);
}
this.workspace_.translate(
this.workspace_.scrollX + absoluteMetrics.left,
this.workspace_.scrollY + absoluteMetrics.top);
this.workspace_.scrollX + absoluteMetrics.left,
this.workspace_.scrollY + absoluteMetrics.top
);
}
/**
@@ -132,7 +133,7 @@ export class VerticalFlyout extends Flyout {
const edgeWidth = this.width_ - this.CORNER_RADIUS;
const edgeHeight =
targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS;
targetWorkspaceViewMetrics.height - 2 * this.CORNER_RADIUS;
this.setBackgroundPath(edgeWidth, edgeHeight);
const x = this.getX();
@@ -152,22 +153,37 @@ export class VerticalFlyout extends Flyout {
const totalWidth = width + this.CORNER_RADIUS;
// Decide whether to start on the left or right.
const path: Array<string|number> =
['M ' + (atRight ? totalWidth : 0) + ',0'];
const path: Array<string | number> = [
'M ' + (atRight ? totalWidth : 0) + ',0',
];
// Top.
path.push('h', (atRight ? -width : width));
path.push('h', atRight ? -width : width);
// Rounded corner.
path.push(
'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1,
atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS, this.CORNER_RADIUS);
'a',
this.CORNER_RADIUS,
this.CORNER_RADIUS,
0,
0,
atRight ? 0 : 1,
atRight ? -this.CORNER_RADIUS : this.CORNER_RADIUS,
this.CORNER_RADIUS
);
// Side closest to workspace.
path.push('v', Math.max(0, height));
// Rounded corner.
path.push(
'a', this.CORNER_RADIUS, this.CORNER_RADIUS, 0, 0, atRight ? 0 : 1,
atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS, this.CORNER_RADIUS);
'a',
this.CORNER_RADIUS,
this.CORNER_RADIUS,
0,
0,
atRight ? 0 : 1,
atRight ? this.CORNER_RADIUS : -this.CORNER_RADIUS,
this.CORNER_RADIUS
);
// Bottom.
path.push('h', (atRight ? width : -width));
path.push('h', atRight ? width : -width);
path.push('z');
this.svgBackground_!.setAttribute('d', path.join(' '));
}
@@ -215,11 +231,11 @@ export class VerticalFlyout extends Flyout {
const cursorX = this.RTL ? margin : margin + this.tabWidth_;
let cursorY = margin;
for (let i = 0, item; item = contents[i]; i++) {
for (let i = 0, item; (item = contents[i]); i++) {
if (item.type === 'block') {
const block = item.block;
const allBlocks = block!.getDescendants(false);
for (let j = 0, child; child = allBlocks[j]; j++) {
for (let j = 0, child; (child = allBlocks[j]); j++) {
// Mark blocks as being inside a flyout. This is used to detect and
// prevent the closure of the flyout if the user right-clicks on such
// a block.
@@ -227,13 +243,18 @@ export class VerticalFlyout extends Flyout {
}
const root = block!.getSvgRoot();
const blockHW = block!.getHeightWidth();
const moveX =
block!.outputConnection ? cursorX - this.tabWidth_ : cursorX;
const moveX = block!.outputConnection
? cursorX - this.tabWidth_
: cursorX;
block!.moveBy(moveX, cursorY);
const rect = this.createRect_(
block!, this.RTL ? moveX - blockHW.width : moveX, cursorY, blockHW,
i);
block!,
this.RTL ? moveX - blockHW.width : moveX,
cursorY,
blockHW,
i
);
this.addBlockListeners_(root, block!, rect);
@@ -260,12 +281,15 @@ export class VerticalFlyout extends Flyout {
const dx = currentDragDeltaXY.x;
const dy = currentDragDeltaXY.y;
// Direction goes from -180 to 180, with 0 toward the right and 90 on top.
const dragDirection = Math.atan2(dy, dx) / Math.PI * 180;
const dragDirection = (Math.atan2(dy, dx) / Math.PI) * 180;
const range = this.dragAngleRange_;
// Check for left or right dragging.
if (dragDirection < range && dragDirection > -range ||
(dragDirection < -180 + range || dragDirection > 180 - range)) {
if (
(dragDirection < range && dragDirection > -range) ||
dragDirection < -180 + range ||
dragDirection > 180 - range
) {
return true;
}
return false;
@@ -278,7 +302,7 @@ export class VerticalFlyout extends Flyout {
* @returns The component's bounding box. Null if drag target area should be
* ignored.
*/
override getClientRect(): Rect|null {
override getClientRect(): Rect | null {
if (!this.svgGroup_ || this.autoClose || !this.isVisible()) {
// The bounding rectangle won't compute correctly if the flyout is closed
// and auto-close flyouts aren't valid drag targets (or delete areas).
@@ -296,7 +320,8 @@ export class VerticalFlyout extends Flyout {
if (this.toolboxPosition_ === toolbox.Position.LEFT) {
const width = flyoutRect.width;
return new Rect(-BIG_NUM, BIG_NUM, -BIG_NUM, left + width);
} else { // Right
} else {
// Right
return new Rect(-BIG_NUM, BIG_NUM, left, BIG_NUM);
}
}
@@ -309,14 +334,14 @@ export class VerticalFlyout extends Flyout {
this.workspace_.scale = this.getFlyoutScale();
let flyoutWidth = 0;
const blocks = this.workspace_.getTopBlocks(false);
for (let i = 0, block; block = blocks[i]; i++) {
for (let i = 0, block; (block = blocks[i]); i++) {
let width = block.getHeightWidth().width;
if (block.outputConnection) {
width -= this.tabWidth_;
}
flyoutWidth = Math.max(flyoutWidth, width);
}
for (let i = 0, button; button = this.buttons_[i]; i++) {
for (let i = 0, button; (button = this.buttons_[i]); i++) {
flyoutWidth = Math.max(flyoutWidth, button.width);
}
flyoutWidth += this.MARGIN * 1.5 + this.tabWidth_;
@@ -324,7 +349,7 @@ export class VerticalFlyout extends Flyout {
flyoutWidth += Scrollbar.scrollbarThickness;
if (this.width_ !== flyoutWidth) {
for (let i = 0, block; block = blocks[i]; i++) {
for (let i = 0, block; (block = blocks[i]); i++) {
if (this.RTL) {
// With the flyoutWidth known, right-align the blocks.
const oldX = block.getRelativeToSurfaceXY().x;
@@ -340,23 +365,29 @@ export class VerticalFlyout extends Flyout {
}
if (this.RTL) {
// With the flyoutWidth known, right-align the buttons.
for (let i = 0, button; button = this.buttons_[i]; i++) {
for (let i = 0, button; (button = this.buttons_[i]); i++) {
const y = button.getPosition().y;
const x = flyoutWidth / this.workspace_.scale - button.width -
this.MARGIN - this.tabWidth_;
const x =
flyoutWidth / this.workspace_.scale -
button.width -
this.MARGIN -
this.tabWidth_;
button.moveTo(x, y);
}
}
if (this.targetWorkspace!.toolboxPosition === this.toolboxPosition_ &&
this.toolboxPosition_ === toolbox.Position.LEFT &&
!this.targetWorkspace!.getToolbox()) {
if (
this.targetWorkspace!.toolboxPosition === this.toolboxPosition_ &&
this.toolboxPosition_ === toolbox.Position.LEFT &&
!this.targetWorkspace!.getToolbox()
) {
// This flyout is a simple toolbox. Reposition the workspace so that
// (0,0) is in the correct position relative to the new absolute edge
// (ie toolbox edge).
this.targetWorkspace!.translate(
this.targetWorkspace!.scrollX + flyoutWidth,
this.targetWorkspace!.scrollY);
this.targetWorkspace!.scrollX + flyoutWidth,
this.targetWorkspace!.scrollY
);
}
this.width_ = flyoutWidth;
this.position();
@@ -366,4 +397,7 @@ export class VerticalFlyout extends Flyout {
}
registry.register(
registry.Type.FLYOUTS_VERTICAL_TOOLBOX, registry.DEFAULT, VerticalFlyout);
registry.Type.FLYOUTS_VERTICAL_TOOLBOX,
registry.DEFAULT,
VerticalFlyout
);