Skip to content

Commit

Permalink
chore: Merge branch 'master' of github.com:google/blockly-samples int…
Browse files Browse the repository at this point in the history
…o fix-pl
  • Loading branch information
maribethb committed Jul 14, 2023
2 parents faf84bb + af842ed commit d78bc3b
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 18 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/dependabot_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This workflow runs `lerna bootstrap` after dependabot updates a package-lock file.
# Without it, package-locks become cluttered with incorrect dependencies that
# normally would be removed by lerna. It wouldn't be necessary if we weren't using
# lerna bootstrap.

name: Clean up after dependabot

# Triggered when a PR is (re)opened or synchronized
on: pull_request

permissions:
pull-requests: write # This action adds commits to PRs

jobs:
update:
runs-on: ubuntu-latest
# Only run on dependabot PRs
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

# Check out the dependabot PR so commits are added there
- name: Checkout PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.pull_request.number }}

# This uses a reverse-engineered email for the github actions bot. See
# https://github.com/actions/checkout/issues/13#issuecomment-724415212
- name: Git identity
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '<41898282+github-actions[bot]@users.noreply.github.com'
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20

- name: Lerna bootstrap
run: |
npm run boot
cd examples && npm run boot
# If any package-locks were updated by lerna bootstrap, commit them
# Using `[dependabot skip]` in the commit message allows dependabot
# to continue making changes to this PR after it is updated
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/managing-pull-requests-for-dependency-updates#allowing-dependabot-to-rebase-and-force-push-over-extra-commits
- name: Commit changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ $(git status | grep '.package-lock.json') ]]; then
git commit -am "chore: update package-locks [dependabot skip]"
git push
else
echo "No changes detected"
fi
85 changes: 85 additions & 0 deletions plugins/workspace-minimap/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion plugins/workspace-minimap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"blockly": "^10.0.0",
"@blockly/dev-scripts": "^2.0.0",
"@blockly/dev-tools": "^7.0.0",
"typescript": "^5.1.3"
"typescript": "^5.1.3",
"chai": "^4.2.0"
},
"peerDependencies": {
"blockly": "^10.0.0"
Expand Down
39 changes: 22 additions & 17 deletions plugins/workspace-minimap/src/minimap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,34 @@ export class Minimap {
}

/**
* Converts a mouse event on the minimap into scroll coordinates for
* the primary viewport.
* Converts the coorindates from a mouse event on the minimap
* into scroll coordinates for the primary viewport.
* @param primaryMetrics The metrics from the primary workspace.
* @param minimapMetrics The metrics from the minimap workspace.
* @param offsetX The x offset of the mouse event.
* @param offsetY The y offset of the mouse event.
* @returns (x, y) primary workspace scroll coordinates.
*/
private minimapToPrimaryCoords(
offsetX: number, offsetY: number): [number, number] {
// Get the metrics from the workspaces
const primaryMetrics = this.primaryWorkspace.getMetrics();
const minimapMetrics = this.minimapWorkspace.getMetrics();

// Calculates the location of the click relative to the
// top left of the minimap content.
static minimapToPrimaryCoords(
primaryMetrics: Blockly.utils.Metrics,
minimapMetrics: Blockly.utils.Metrics,
offsetX: number,
offsetY: number): [number, number] {
// Gets the coordinate relative to the top left of the minimap content.
offsetX -= (minimapMetrics.svgWidth - minimapMetrics.contentWidth) / 2;
offsetY -= (minimapMetrics.svgHeight - minimapMetrics.contentHeight) / 2;

// Calculates the scale between the minimap and primary workspace
// and applies it to the offset.
const scale = primaryMetrics.contentWidth / minimapMetrics.contentWidth;
// Scales the coordinate to the primary workspace.
const scale =
primaryMetrics.contentWidth / minimapMetrics.contentWidth;
offsetX *= scale;
offsetY *= scale;

// Calculates the location of the click relative to the
// top left of the primary workspace content.
// Gets the coordinate relative to the top left of the primary content.
let x = -primaryMetrics.contentLeft - offsetX;
let y = -primaryMetrics.contentTop - offsetY;

// Centers the click in the primary viewport.
// Centers the coordinate in the primary viewport.
x += primaryMetrics.viewWidth / 2;
y += primaryMetrics.viewHeight / 2;

Expand All @@ -129,7 +128,11 @@ export class Minimap {
* @param event The minimap browser event.
*/
private primaryScroll(event: PointerEvent): void {
const [x, y] = this.minimapToPrimaryCoords(event.offsetX, event.offsetY);
const [x, y] = Minimap.minimapToPrimaryCoords(
this.primaryWorkspace.getMetrics(),
this.minimapWorkspace.getMetrics(),
event.offsetX,
event.offsetY);
this.primaryWorkspace.scroll(x, y);
}

Expand All @@ -147,6 +150,8 @@ export class Minimap {
* Unbinds the minimap mousemove when the mouse is not clicked.
*/
private onClickUp(): void {
// TODO: If you start the click in the minimap and end it in the primary
// the then this function is never unbinded
Blockly.browserEvents.unbind(this.onMouseMoveWrapper);
}

Expand Down
Loading

0 comments on commit d78bc3b

Please sign in to comment.