Skip to content

Commit

Permalink
๐Ÿ› fix: ๋ธ”๋ก ์ƒ์„ฑ ์œ„์น˜ ์ˆ˜์ • (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujaa authored Nov 25, 2024
1 parent 60da41a commit 15ea820
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/client/src/core/fixedFlyout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import TabbedToolbox from './tabbedToolbox';
* Flyout์˜ ์œ„์น˜๊ฐ€ ๋™์ ์œผ๋กœ ๊ณ„์‚ฐ๋ฉ๋‹ˆ๋‹ค. ์ด ํด๋ž˜์Šค๋Š” position ํ•จ์ˆ˜๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œํ•˜์—ฌ Flyout์˜ ์œ„์น˜๋ฅผ
* ๊ณ ์ •๋œ ์œ„์น˜์— ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.
*/

// @ts-expect-error Private field inheritance
export default class FixedFlyout extends Blockly.VerticalFlyout {
static registryName = 'FixedFlyout';

Expand Down Expand Up @@ -47,6 +49,39 @@ export default class FixedFlyout extends Blockly.VerticalFlyout {
this.positionAt_(metrics.width, metrics.height - toolbox.getContentHeight(), x, y);
}

/**
* ์ƒˆ๋กœ์šด ๋ธ”๋ก์ด ์ถ”๊ฐ€๋  ๋•Œ ์œ„์น˜๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
*
* @description
* ์ด ๋ฉ”์„œ๋“œ๋Š” ์›๋ž˜ private์ด๋ผ ์ ‘๊ทผํ•˜๋ฉด ์•ˆ ๋˜์ง€๋งŒ flyout์„ contentArea ๋‚ด๋ถ€๋กœ ์ด๋™ํ•˜๋ฉฐ ์ฒ˜์Œ ๋ธ”๋ก์„ ์ƒ์„ฑํ•  ๋•Œ ์ •ํ™•ํ•œ ์œ„์น˜์— ์ƒ์„ฑํ•˜์ง€ ์•Š๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด ์ˆ˜์ •ํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
* workspace์˜
*
* @throws {Error} ์›Œํฌ์ŠคํŽ˜์ด์Šค๊ฐ€ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ๋ณด์ด์ง€ ์•Š๋Š” ๊ฒฝ์šฐ
* @throws {Error} Toolbox๊ฐ€ ์—†๊ฑฐ๋‚˜ ์ดˆ๊ธฐํ™”๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ
* @override
*/
override positionNewBlock(oldBlock: Blockly.BlockSvg, block: Blockly.BlockSvg) {
const targetWorkspace = this.targetWorkspace;

const mainOffsetPixels = targetWorkspace.getOriginOffsetInPixels();

const toolboxClientRec = document.querySelector('.blocklyFlyout')?.getBoundingClientRect();
const workspace = document.querySelector('.blocklyMainBackground')?.getBoundingClientRect();

const flyoutOffsetPixels = this.workspace_.getOriginOffsetInPixels();
flyoutOffsetPixels.x = toolboxClientRec!.x - workspace!.x;
flyoutOffsetPixels.y = toolboxClientRec!.y - workspace!.y;

const oldBlockPos = oldBlock.getRelativeToSurfaceXY();
oldBlockPos.scale(this.workspace_.scale);

const oldBlockOffsetPixels = Blockly.utils.Coordinate.sum(flyoutOffsetPixels, oldBlockPos);
const finalOffset = Blockly.utils.Coordinate.difference(oldBlockOffsetPixels, mainOffsetPixels);
finalOffset.scale(1 / targetWorkspace.scale);

block.moveTo(new Blockly.utils.Coordinate(finalOffset.x, finalOffset.y));
}

/**
* Flyout์„ ์ˆจ๊ธฐ๋Š” ๊ธฐ๋Šฅ์„ ๋น„ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค.
*
Expand Down

0 comments on commit 15ea820

Please sign in to comment.