mirror of
https://github.com/google/blockly.git
synced 2026-01-09 10:00:09 +01:00
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:
committed by
GitHub
parent
af991f5e1b
commit
88ff901a72
@@ -21,7 +21,6 @@ import * as mathUtils from './utils/math.js';
|
||||
import type {WorkspaceCommentSvg} from './workspace_comment_svg.js';
|
||||
import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
|
||||
|
||||
/**
|
||||
* Bumps the given object that has passed out of bounds.
|
||||
*
|
||||
@@ -34,8 +33,10 @@ import type {WorkspaceSvg} from './workspace_svg.js';
|
||||
* @returns True if object was bumped.
|
||||
*/
|
||||
function bumpObjectIntoBounds(
|
||||
workspace: WorkspaceSvg, bounds: ContainerRegion,
|
||||
object: IBoundedElement): boolean {
|
||||
workspace: WorkspaceSvg,
|
||||
bounds: ContainerRegion,
|
||||
object: IBoundedElement
|
||||
): boolean {
|
||||
// Compute new top/left position for object.
|
||||
const objectMetrics = object.getBoundingRectangle();
|
||||
const height = objectMetrics.bottom - objectMetrics.top;
|
||||
@@ -46,8 +47,11 @@ function bumpObjectIntoBounds(
|
||||
const bottomClamp = boundsBottom - height;
|
||||
// If the object is taller than the workspace we want to
|
||||
// top-align the block
|
||||
const newYPosition =
|
||||
mathUtils.clamp(topClamp, objectMetrics.top, bottomClamp);
|
||||
const newYPosition = mathUtils.clamp(
|
||||
topClamp,
|
||||
objectMetrics.top,
|
||||
bottomClamp
|
||||
);
|
||||
const deltaY = newYPosition - objectMetrics.top;
|
||||
|
||||
// Note: Even in RTL mode the "anchor" of the object is the
|
||||
@@ -66,8 +70,11 @@ function bumpObjectIntoBounds(
|
||||
// the right clamp to match.
|
||||
rightClamp = Math.max(leftClamp, rightClamp);
|
||||
}
|
||||
const newXPosition =
|
||||
mathUtils.clamp(leftClamp, objectMetrics.left, rightClamp);
|
||||
const newXPosition = mathUtils.clamp(
|
||||
leftClamp,
|
||||
objectMetrics.left,
|
||||
rightClamp
|
||||
);
|
||||
const deltaX = newXPosition - objectMetrics.left;
|
||||
|
||||
if (deltaX || deltaY) {
|
||||
@@ -84,8 +91,9 @@ export const bumpIntoBounds = bumpObjectIntoBounds;
|
||||
* @param workspace The workspace to handle.
|
||||
* @returns The event handler.
|
||||
*/
|
||||
export function bumpIntoBoundsHandler(workspace: WorkspaceSvg):
|
||||
(p1: Abstract) => void {
|
||||
export function bumpIntoBoundsHandler(
|
||||
workspace: WorkspaceSvg
|
||||
): (p1: Abstract) => void {
|
||||
return (e) => {
|
||||
const metricsManager = workspace.getMetricsManager();
|
||||
if (!metricsManager.hasFixedEdges() || workspace.isDragging()) {
|
||||
@@ -96,8 +104,10 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg):
|
||||
const scrollMetricsInWsCoords = metricsManager.getScrollMetrics(true);
|
||||
|
||||
// Triggered by move/create event
|
||||
const object =
|
||||
extractObjectFromEvent(workspace, e as eventUtils.BumpEvent);
|
||||
const object = extractObjectFromEvent(
|
||||
workspace,
|
||||
e as eventUtils.BumpEvent
|
||||
);
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
@@ -106,18 +116,25 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg):
|
||||
eventUtils.setGroup(e.group);
|
||||
|
||||
const wasBumped = bumpObjectIntoBounds(
|
||||
workspace, scrollMetricsInWsCoords, (object as IBoundedElement));
|
||||
workspace,
|
||||
scrollMetricsInWsCoords,
|
||||
object as IBoundedElement
|
||||
);
|
||||
|
||||
if (wasBumped && !e.group) {
|
||||
console.warn(
|
||||
'Moved object in bounds but there was no' +
|
||||
' event group. This may break undo.');
|
||||
'Moved object in bounds but there was no' +
|
||||
' event group. This may break undo.'
|
||||
);
|
||||
}
|
||||
eventUtils.setGroup(existingGroup);
|
||||
} else if (e.type === eventUtils.VIEWPORT_CHANGE) {
|
||||
const viewportEvent = (e as ViewportChange);
|
||||
if (viewportEvent.scale && viewportEvent.oldScale &&
|
||||
viewportEvent.scale > viewportEvent.oldScale) {
|
||||
const viewportEvent = e as ViewportChange;
|
||||
if (
|
||||
viewportEvent.scale &&
|
||||
viewportEvent.oldScale &&
|
||||
viewportEvent.scale > viewportEvent.oldScale
|
||||
) {
|
||||
bumpTopObjectsIntoBounds(workspace);
|
||||
}
|
||||
}
|
||||
@@ -134,8 +151,9 @@ export function bumpIntoBoundsHandler(workspace: WorkspaceSvg):
|
||||
* object.
|
||||
*/
|
||||
function extractObjectFromEvent(
|
||||
workspace: WorkspaceSvg, e: eventUtils.BumpEvent): BlockSvg|null|
|
||||
WorkspaceCommentSvg {
|
||||
workspace: WorkspaceSvg,
|
||||
e: eventUtils.BumpEvent
|
||||
): BlockSvg | null | WorkspaceCommentSvg {
|
||||
let object = null;
|
||||
switch (e.type) {
|
||||
case eventUtils.BLOCK_CREATE:
|
||||
@@ -147,10 +165,9 @@ function extractObjectFromEvent(
|
||||
break;
|
||||
case eventUtils.COMMENT_CREATE:
|
||||
case eventUtils.COMMENT_MOVE:
|
||||
object =
|
||||
workspace.getCommentById((e as CommentCreate | CommentMove).commentId!
|
||||
) as WorkspaceCommentSvg |
|
||||
null;
|
||||
object = workspace.getCommentById(
|
||||
(e as CommentCreate | CommentMove).commentId!
|
||||
) as WorkspaceCommentSvg | null;
|
||||
break;
|
||||
}
|
||||
return object;
|
||||
@@ -169,7 +186,7 @@ export function bumpTopObjectsIntoBounds(workspace: WorkspaceSvg) {
|
||||
|
||||
const scrollMetricsInWsCoords = metricsManager.getScrollMetrics(true);
|
||||
const topBlocks = workspace.getTopBoundedElements();
|
||||
for (let i = 0, block; block = topBlocks[i]; i++) {
|
||||
for (let i = 0, block; (block = topBlocks[i]); i++) {
|
||||
bumpObjectIntoBounds(workspace, scrollMetricsInWsCoords, block);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user