Skip to content

Commit

Permalink
feat: increased the capture area for dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
egordidenko committed Sep 23, 2024
1 parent c915f71 commit a9b8574
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
76 changes: 42 additions & 34 deletions blocks/CloudImageEditor/src/CropFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ export class CropFrame extends Block {

if (isCenter) {
const moveThumbRect = {
x: x + width / 3,
y: y + height / 3,
width: width / 3,
height: height / 3,
x,
y,
width,
height,
};
setSvgNodeAttrs(interactionNode, moveThumbRect);
} else {
Expand Down Expand Up @@ -202,47 +202,55 @@ export class CropFrame extends Block {
});
}

/**
* @param {import('./types.js').FrameThumbs} frameThumbs
* @param {import('./types.js').Direction} direction
*/
_createThumb(frameThumbs, direction) {
let groupNode = createSvgNode('g');
groupNode.classList.add('uc-thumb');
groupNode.setAttribute('with-effects', '');
let interactionNode = createSvgNode('rect', {
fill: 'transparent',
});
let pathNode = createSvgNode('path', {
stroke: 'currentColor',
fill: 'none',
'stroke-width': THUMB_STROKE_WIDTH,
});
groupNode.appendChild(pathNode);
groupNode.appendChild(interactionNode);
frameThumbs[direction] = {
direction,
pathNode,
interactionNode,
groupNode,
};

if (direction === '') {
groupNode.style.cursor = 'move';
}

interactionNode.addEventListener('pointerdown', this._handlePointerDown.bind(this, direction));
}

/** @private */
_createThumbs() {
/**
* @type {Partial<{
* [K in import('./types.js').Direction]: {
* direction: import('./types.js').Direction;
* pathNode: SVGElement;
* interactionNode: SVGElement;
* groupNode: SVGElement;
* };
* }>}
*/
/** @type {import('./types.js').FrameThumbs} */
const frameThumbs = {};

for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
let direction = /** @type {import('./types.js').Direction} */ (`${['n', '', 's'][i]}${['w', '', 'e'][j]}`);
let groupNode = createSvgNode('g');
groupNode.classList.add('uc-thumb');
groupNode.setAttribute('with-effects', '');
let interactionNode = createSvgNode('rect', {
fill: 'transparent',
});
let pathNode = createSvgNode('path', {
stroke: 'currentColor',
fill: 'none',
'stroke-width': THUMB_STROKE_WIDTH,
});
groupNode.appendChild(pathNode);
groupNode.appendChild(interactionNode);
frameThumbs[direction] = {
direction,
pathNode,
interactionNode,
groupNode,
};
if (direction === '') {
continue;
}

interactionNode.addEventListener('pointerdown', this._handlePointerDown.bind(this, direction));
this._createThumb(frameThumbs, direction);
}
}

this._createThumb(frameThumbs, '');
return frameThumbs;
}

Expand Down
11 changes: 11 additions & 0 deletions blocks/CloudImageEditor/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@

/** @typedef {CropAspectRatio[]} CropPresetList */

/**
* @typedef {Partial<{
* [K in Direction]: {
* direction: Direction;
* pathNode: SVGElement;
* interactionNode: SVGElement;
* groupNode: SVGElement;
* };
* }>} FrameThumbs
*/

/** @typedef {'' | 'n' | 's' | 'e' | 'w' | 'ne' | 'nw' | 'se' | 'sw'} Direction */

export {};

0 comments on commit a9b8574

Please sign in to comment.