diagram-js
Advanced tools
Comparing version 8.7.1 to 8.8.0
@@ -9,2 +9,6 @@ # Changelog | ||
## 8.8.0 | ||
* `FEAT`: provide keyboard event testing utilities ([#664](https://github.com/bpmn-io/diagram-js/pull/664)) | ||
## 8.7.1 | ||
@@ -11,0 +15,0 @@ |
import { | ||
isCmd, | ||
isKey, | ||
isShift | ||
isCopy, | ||
isPaste, | ||
isUndo, | ||
isRedo | ||
} from './KeyboardUtil'; | ||
@@ -76,3 +79,3 @@ | ||
if (isCmd(event) && !isShift(event) && isKey(KEYS_UNDO, event)) { | ||
if (isUndo(event)) { | ||
editorActions.trigger('undo'); | ||
@@ -91,3 +94,3 @@ | ||
if (isCmd(event) && (isKey(KEYS_REDO, event) || (isKey(KEYS_UNDO, event) && isShift(event)))) { | ||
if (isRedo(event)) { | ||
editorActions.trigger('redo'); | ||
@@ -105,3 +108,3 @@ | ||
if (isCmd(event) && isKey(KEYS_COPY, event)) { | ||
if (isCopy(event)) { | ||
editorActions.trigger('copy'); | ||
@@ -119,3 +122,3 @@ | ||
if (isCmd(event) && isKey(KEYS_PASTE, event)) { | ||
if (isPaste(event)) { | ||
editorActions.trigger('paste'); | ||
@@ -122,0 +125,0 @@ |
import { isArray } from 'min-dash'; | ||
var KEYCODE_C = 67; | ||
var KEYCODE_V = 86; | ||
var KEYCODE_Y = 89; | ||
var KEYCODE_Z = 90; | ||
var KEYS_COPY = [ 'c', 'C', KEYCODE_C ]; | ||
var KEYS_PASTE = [ 'v', 'V', KEYCODE_V ]; | ||
var KEYS_REDO = [ 'y', 'Y', KEYCODE_Y ]; | ||
var KEYS_UNDO = [ 'z', 'Z', KEYCODE_Z ]; | ||
/** | ||
@@ -42,2 +52,22 @@ * Returns true if event was triggered with any modifier | ||
return event.shiftKey; | ||
} | ||
export function isCopy(event) { | ||
return isCmd(event) && isKey(KEYS_COPY, event); | ||
} | ||
export function isPaste(event) { | ||
return isCmd(event) && isKey(KEYS_PASTE, event); | ||
} | ||
export function isUndo(event) { | ||
return isCmd(event) && !isShift(event) && isKey(KEYS_UNDO, event); | ||
} | ||
export function isRedo(event) { | ||
return isCmd(event) && ( | ||
isKey(KEYS_REDO, event) || ( | ||
isKey(KEYS_UNDO, event) && isShift(event) | ||
) | ||
); | ||
} |
{ | ||
"name": "diagram-js", | ||
"version": "8.7.1", | ||
"version": "8.8.0", | ||
"description": "A toolbox for displaying and modifying diagrams on the web", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
683158
22316