MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / _keyEvent

Method _keyEvent

src/dd-draggable.ts:285–314  ·  view source on GitHub ↗

@internal call when keys are being pressed - use Esc to cancel, R to rotate

(e: KeyboardEvent)

Source from the content-addressed store, hash-verified

283
284 /** @internal call when keys are being pressed - use Esc to cancel, R to rotate */
285 protected _keyEvent(e: KeyboardEvent): void {
286 const n = this.el.gridstackNode as GridStackNodeRotate;
287 const grid = n?.grid || (DDManager.dropElement?.el as GridHTMLElement)?.gridstack;
288
289 if (e.key === 'Escape') {
290 if (n && n._origRotate) {
291 n._orig = n._origRotate;
292 delete n._origRotate;
293 }
294 grid?.cancelDrag();
295 this._mouseUp(this.mouseDownEvent);
296 } else if (n && grid && (e.key === 'r' || e.key === 'R')) {
297 if (!Utils.canBeRotated(n)) return;
298 n._origRotate = n._origRotate || { ...n._orig }; // store the real orig size in case we Esc after doing rotation
299 delete n._moving; // force rotate to happen (move waits for >50% coverage otherwise)
300 grid.setAnimation(false) // immediate rotate so _getDragOffset() gets the right dom size below
301 .rotate(n.el, {
302 top: -this.dragOffset.offsetTop,
303 left: -this.dragOffset.offsetX
304 })
305 .setAnimation();
306 n._moving = true;
307 this.dragOffset = this._getDragOffset(this.lastDrag, n.el, this.helperContainment);
308 this.helper.style.width = this.dragOffset.width + 'px';
309 this.helper.style.height = this.dragOffset.height + 'px';
310 Utils.swap(n._orig, 'w', 'h');
311 delete n._rect;
312 this._mouseMove(this.lastDrag);
313 }
314 }
315
316 /** @internal create a clone copy (or user defined method) of the original drag item if set */
317 protected _createHelper(): HTMLElement {

Callers

nothing calls this directly

Calls 8

_mouseUpMethod · 0.95
_getDragOffsetMethod · 0.95
_mouseMoveMethod · 0.95
cancelDragMethod · 0.80
canBeRotatedMethod · 0.80
setAnimationMethod · 0.80
rotateMethod · 0.80
swapMethod · 0.45

Tested by

no test coverage detected