From 9dd7da49787d8ddb2a6d21ebe61eb22069e0337a Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Wed, 10 Apr 2024 18:24:10 +0000 Subject: [PATCH] fix: naming and logs --- plugins/scroll-options/src/AutoScroll.js | 4 +- ...ScrollDragger.js => ScrollBlockDragger.js} | 50 +++++++++---------- plugins/scroll-options/src/index.js | 14 +++--- plugins/scroll-options/test/index.js | 8 ++- 4 files changed, 39 insertions(+), 37 deletions(-) rename plugins/scroll-options/src/{ScrollDragger.js => ScrollBlockDragger.js} (91%) diff --git a/plugins/scroll-options/src/AutoScroll.js b/plugins/scroll-options/src/AutoScroll.js index 762b7d58b7..9dba42d0dc 100644 --- a/plugins/scroll-options/src/AutoScroll.js +++ b/plugins/scroll-options/src/AutoScroll.js @@ -7,7 +7,7 @@ import * as Blockly from 'blockly/core'; import {ScrollMetricsManager} from './ScrollMetricsManager'; import {getTranslation} from './utils'; -import {ScrollDragger} from './ScrollDragger'; +import {ScrollBlockDragger} from './ScrollBlockDragger'; /** * AutoScroll is used to scroll/pan the workspace automatically. For example, @@ -24,7 +24,7 @@ export class AutoScroll { /** * Creates an AutoScroll instance for a specified workspace. * @param {!Blockly.WorkspaceSvg} workspace Workspace to scroll. - * @param {!ScrollDragger} dragger The dragger that's currently dragging. + * @param {!ScrollBlockDragger} dragger The dragger that's currently dragging. * @constructor */ constructor(workspace, dragger) { diff --git a/plugins/scroll-options/src/ScrollDragger.js b/plugins/scroll-options/src/ScrollBlockDragger.js similarity index 91% rename from plugins/scroll-options/src/ScrollDragger.js rename to plugins/scroll-options/src/ScrollBlockDragger.js index 3e1bd36b5a..f6530af6be 100644 --- a/plugins/scroll-options/src/ScrollDragger.js +++ b/plugins/scroll-options/src/ScrollBlockDragger.js @@ -68,7 +68,7 @@ const defaultOptions = { * A block dragger that adds the functionality for a block to be moved while * someone is dragging it. */ -export class ScrollDragger extends Blockly.Dragger { +export class ScrollBlockDragger extends Blockly.Dragger { /** @override */ constructor(draggable, workspace) { super(draggable, workspace); @@ -131,8 +131,7 @@ export class ScrollDragger extends Blockly.Dragger { super.onDrag(e, totalDelta); this.dragDelta_ = dragDelta; - console.log('here', ScrollDragger.edgeScrollEnabled); - if (ScrollDragger.edgeScrollEnabled) { + if (ScrollBlockDragger.edgeScrollEnabled) { this.scrollWorkspaceWhileDragging_(e); } } @@ -215,7 +214,6 @@ export class ScrollDragger extends Blockly.Dragger { // Update the autoscroll or start a new one. this.activeAutoScroll_ = this.activeAutoScroll_ || new AutoScroll(this.workspace, this); - console.log('autoscoll'); this.activeAutoScroll_.updateProperties(overallScrollVector); } @@ -276,11 +274,11 @@ export class ScrollDragger extends Blockly.Dragger { const blockOverflows = this.getBlockBoundsOverflows_(viewMetrics, mouse); for (const direction of this.scrollDirections_) { const overflow = blockOverflows[direction]; - if (overflow > ScrollDragger.options.slowBlockStartDistance) { + if (overflow > ScrollBlockDragger.options.slowBlockStartDistance) { const speed = - overflow > ScrollDragger.options.fastBlockStartDistance - ? ScrollDragger.options.fastBlockSpeed - : ScrollDragger.options.slowBlockSpeed; + overflow > ScrollBlockDragger.options.fastBlockStartDistance + ? ScrollBlockDragger.options.fastBlockSpeed + : ScrollBlockDragger.options.slowBlockSpeed; const scrollVector = this.SCROLL_DIRECTION_VECTORS_[direction] .clone() .scale(speed); @@ -307,11 +305,11 @@ export class ScrollDragger extends Blockly.Dragger { const mouseOverflows = this.getMouseOverflows_(viewMetrics, mouse); for (const direction of this.scrollDirections_) { const overflow = mouseOverflows[direction]; - if (overflow > ScrollDragger.options.slowMouseStartDistance) { + if (overflow > ScrollBlockDragger.options.slowMouseStartDistance) { const speed = - overflow > ScrollDragger.options.fastMouseStartDistance - ? ScrollDragger.options.fastMouseSpeed - : ScrollDragger.options.slowMouseSpeed; + overflow > ScrollBlockDragger.options.fastMouseStartDistance + ? ScrollBlockDragger.options.fastMouseSpeed + : ScrollBlockDragger.options.slowMouseSpeed; const scrollVector = this.SCROLL_DIRECTION_VECTORS_[direction] .clone() .scale(speed); @@ -349,15 +347,15 @@ export class ScrollDragger extends Blockly.Dragger { const blockHeight = blockBounds.bottom - blockBounds.top; if ( blockHeight > - viewMetrics.height * ScrollDragger.options.oversizeBlockThreshold + viewMetrics.height * ScrollBlockDragger.options.oversizeBlockThreshold ) { blockBounds.top = Math.max( blockBounds.top, - mouse.y - ScrollDragger.options.oversizeBlockMargin, + mouse.y - ScrollBlockDragger.options.oversizeBlockMargin, ); blockBounds.bottom = Math.min( blockBounds.bottom, - mouse.y + ScrollDragger.options.oversizeBlockMargin, + mouse.y + ScrollBlockDragger.options.oversizeBlockMargin, ); } @@ -365,15 +363,15 @@ export class ScrollDragger extends Blockly.Dragger { const blockWidth = blockBounds.right - blockBounds.left; if ( blockWidth > - viewMetrics.width * ScrollDragger.options.oversizeBlockThreshold + viewMetrics.width * ScrollBlockDragger.options.oversizeBlockThreshold ) { blockBounds.left = Math.max( blockBounds.left, - mouse.x - ScrollDragger.options.oversizeBlockMargin, + mouse.x - ScrollBlockDragger.options.oversizeBlockMargin, ); blockBounds.right = Math.min( blockBounds.right, - mouse.x + ScrollDragger.options.oversizeBlockMargin, + mouse.x + ScrollBlockDragger.options.oversizeBlockMargin, ); } @@ -433,13 +431,13 @@ export class ScrollDragger extends Blockly.Dragger { * the edge is enabled. * @type {boolean} */ -ScrollDragger.edgeScrollEnabled = true; +ScrollBlockDragger.edgeScrollEnabled = true; /** * Configuration options for the scroll-options settings. * @type {!EdgeScrollOptions} */ -ScrollDragger.options = defaultOptions; +ScrollBlockDragger.options = defaultOptions; /** * Update the scroll options. Only the properties actually included in the @@ -462,19 +460,19 @@ ScrollDragger.options = defaultOptions; * the available options. Any properties not present will use the existing * value. */ -ScrollDragger.updateOptions = function (options) { - ScrollDragger.options = {...ScrollDragger.options, ...options}; +ScrollBlockDragger.updateOptions = function (options) { + ScrollBlockDragger.options = {...ScrollBlockDragger.options, ...options}; }; /** * Resets the options object to the default options. */ -ScrollDragger.resetOptions = function () { - ScrollDragger.options = defaultOptions; +ScrollBlockDragger.resetOptions = function () { + ScrollBlockDragger.options = defaultOptions; }; Blockly.registry.register( - Blockly.registry.Type.DRAGGER, + Blockly.registry.Type.BLOCK_DRAGGER, 'ScrollDragger', - ScrollDragger, + ScrollBlockDragger, ); diff --git a/plugins/scroll-options/src/index.js b/plugins/scroll-options/src/index.js index dba1f6adc5..c39cd23b68 100644 --- a/plugins/scroll-options/src/index.js +++ b/plugins/scroll-options/src/index.js @@ -5,7 +5,7 @@ */ import Blockly from 'blockly/core'; -import {EdgeScrollOptions, ScrollDragger} from './ScrollDragger'; +import {EdgeScrollOptions, ScrollBlockDragger} from './ScrollBlockDragger'; import {getTranslation} from './utils'; /** @@ -63,10 +63,10 @@ export class ScrollOptions { this.disableWheelScroll(); } - ScrollDragger.edgeScrollEnabled = enableEdgeScroll; + ScrollBlockDragger.edgeScrollEnabled = enableEdgeScroll; if (edgeScrollOptions) { - ScrollDragger.updateOptions(edgeScrollOptions); + ScrollBlockDragger.updateOptions(edgeScrollOptions); } } @@ -104,14 +104,14 @@ export class ScrollOptions { * Enables scrolling when block is dragged near edge. */ enableEdgeScroll() { - ScrollDragger.edgeScrollEnabled = true; + ScrollBlockDragger.edgeScrollEnabled = true; } /** * Disables scrolling when block is dragged near edge. */ disableEdgeScroll() { - ScrollDragger.edgeScrollEnabled = false; + ScrollBlockDragger.edgeScrollEnabled = false; } /** @@ -121,7 +121,7 @@ export class ScrollOptions { * @param {!EdgeScrollOptions} options Edge scroll options. */ updateEdgeScrollOptions(options) { - ScrollDragger.updateOptions(options); + ScrollBlockDragger.updateOptions(options); } /** @@ -177,5 +177,5 @@ export class ScrollOptions { } } -export * from './ScrollDragger'; +export * from './ScrollBlockDragger'; export * from './ScrollMetricsManager'; diff --git a/plugins/scroll-options/test/index.js b/plugins/scroll-options/test/index.js index 65c3ece121..b560c8419f 100644 --- a/plugins/scroll-options/test/index.js +++ b/plugins/scroll-options/test/index.js @@ -11,7 +11,11 @@ import {createPlayground, toolboxCategories} from '@blockly/dev-tools'; import * as Blockly from 'blockly'; -import {ScrollDragger, ScrollMetricsManager, ScrollOptions} from '../src/index'; +import { + ScrollBlockDragger, + ScrollMetricsManager, + ScrollOptions, +} from '../src/index'; /** * Create a workspace. @@ -35,7 +39,7 @@ document.addEventListener('DOMContentLoaded', function () { toolbox: toolboxCategories, plugins: { // These are both required, even if you turn off edge scrolling. - dragger: ScrollDragger, + blockDragger: ScrollBlockDragger, metricsManager: ScrollMetricsManager, }, move: {