test-keyboard
Advanced tools
Comparing version 0.7.4 to 0.7.5
# test-keyboard | ||
## 0.7.5 | ||
### Patch Changes | ||
- Updated dependencies [24f83413] | ||
- @remirror/core-types@0.8.0 | ||
- @remirror/core-helpers@0.7.5 | ||
## 0.7.4 | ||
@@ -4,0 +12,0 @@ |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck')); | ||
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass')); | ||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty')); | ||
@@ -17,3 +15,3 @@ var coreHelpers = require('@remirror/core-helpers'); | ||
var rawUSKeyboardLayout = { | ||
const rawUSKeyboardLayout = { | ||
'0': { | ||
@@ -337,3 +335,3 @@ keyCode: 48, | ||
code: 'NumpadDecimal', | ||
key: "\0", | ||
key: '\u0000', | ||
shiftKey: '.', | ||
@@ -897,5 +895,5 @@ location: 3 | ||
}, | ||
"\0": { | ||
'\u0000': { | ||
keyCode: 46, | ||
key: "\0", | ||
key: '\u0000', | ||
code: 'NumpadDecimal', | ||
@@ -1360,5 +1358,5 @@ location: 3 | ||
}; | ||
var noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
var noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
var usKeyboardLayout = rawUSKeyboardLayout; | ||
const noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
const noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
const usKeyboardLayout = rawUSKeyboardLayout; | ||
@@ -1370,5 +1368,3 @@ /** | ||
*/ | ||
var isUSKeyboardCharacter = function isUSKeyboardCharacter(char) { | ||
return coreHelpers.isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
}; | ||
const isUSKeyboardCharacter = char => coreHelpers.isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
@@ -1385,7 +1381,5 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var createKeyboardEvent = function createKeyboardEvent(type, options) { | ||
return new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
}; | ||
const createKeyboardEvent = (type, options) => new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
@@ -1399,7 +1393,7 @@ /** | ||
*/ | ||
var getModifierInformation = function getModifierInformation(_ref) { | ||
var modifiers = _ref.modifiers, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac; | ||
var info = { | ||
const getModifierInformation = ({ | ||
modifiers, | ||
isMac = false | ||
}) => { | ||
const info = { | ||
altKey: false, | ||
@@ -1410,41 +1404,21 @@ ctrlKey: false, | ||
}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = modifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var modifier = _step.value; | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
for (const modifier of modifiers) { | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
} else { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else { | ||
info.ctrlKey = true; | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -1460,5 +1434,3 @@ | ||
var cleanKey = function cleanKey(key) { | ||
return coreHelpers.omit(usKeyboardLayout[key], ['shiftKey']); | ||
}; | ||
const cleanKey = key => coreHelpers.omit(usKeyboardLayout[key], ['shiftKey']); | ||
@@ -1468,40 +1440,26 @@ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var Keyboard = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Keyboard, [{ | ||
key: "started", | ||
get: function get() { | ||
return this.status === 'started'; | ||
} | ||
}], [{ | ||
key: "create", | ||
value: function create(params) { | ||
return new Keyboard(params); | ||
} | ||
}, { | ||
key: "defaultOptions", | ||
get: function get() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
}]); | ||
class Keyboard { | ||
static create(params) { | ||
return new Keyboard(params); | ||
} | ||
function Keyboard(_ref) { | ||
var _this = this; | ||
static get defaultOptions() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
var target = _ref.target, | ||
_ref$defaultOptions = _ref.defaultOptions, | ||
defaultOptions = _ref$defaultOptions === void 0 ? Keyboard.defaultOptions : _ref$defaultOptions, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac, | ||
_ref$batch = _ref.batch, | ||
batch = _ref$batch === void 0 ? false : _ref$batch, | ||
onEventDispatch = _ref.onEventDispatch; | ||
get started() { | ||
return this.status === 'started'; | ||
} | ||
_classCallCheck(this, Keyboard); | ||
constructor({ | ||
target, | ||
defaultOptions = Keyboard.defaultOptions, | ||
isMac = false, | ||
batch = false, | ||
onEventDispatch | ||
}) { | ||
_defineProperty(this, "status", 'idle'); | ||
@@ -1511,15 +1469,18 @@ | ||
_defineProperty(this, "keyDown", function (_ref2) { | ||
var options = _ref2.options; | ||
return _this.dispatchEvent('keydown', options); | ||
_defineProperty(this, "keyDown", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keydown', options); | ||
}); | ||
_defineProperty(this, "keyPress", function (_ref3) { | ||
var options = _ref3.options; | ||
return _this.dispatchEvent('keypress', options); | ||
_defineProperty(this, "keyPress", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keypress', options); | ||
}); | ||
_defineProperty(this, "keyUp", function (_ref4) { | ||
var options = _ref4.options; | ||
return _this.dispatchEvent('keyup', options); | ||
_defineProperty(this, "keyUp", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keyup', options); | ||
}); | ||
@@ -1538,263 +1499,224 @@ | ||
_createClass(Keyboard, [{ | ||
key: "start", | ||
value: function start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
}, { | ||
key: "end", | ||
value: function end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
this.status = 'ended'; | ||
end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
}, { | ||
key: "forEach", | ||
value: function forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
}, { | ||
key: "runBatchedEvents", | ||
value: function runBatchedEvents() { | ||
this.actions.forEach(function (action) { | ||
action.dispatch(); | ||
}); | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "usChar", | ||
value: function usChar(_ref5) { | ||
var text = _ref5.text, | ||
_ref5$options = _ref5.options, | ||
options = _ref5$options === void 0 ? Object.create(null) : _ref5$options, | ||
_ref5$typing = _ref5.typing, | ||
typing = _ref5$typing === void 0 ? false : _ref5$typing; | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
if (!isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
return this.char({ | ||
text: text, | ||
options: options, | ||
typing: typing | ||
}); | ||
runBatchedEvents() { | ||
this.actions.forEach(action => { | ||
action.dispatch(); | ||
}); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
usChar({ | ||
text, | ||
options = Object.create(null), | ||
typing = false | ||
}) { | ||
if (!isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "char", | ||
value: function char(_ref6) { | ||
var text = _ref6.text, | ||
options = _ref6.options, | ||
typing = _ref6.typing; | ||
options = _objectSpread$1({}, options, {}, isUSKeyboardCharacter(text) ? cleanKey(text) : { | ||
key: text | ||
return this.char({ | ||
text, | ||
options, | ||
typing | ||
}); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
char({ | ||
text, | ||
options, | ||
typing | ||
}) { | ||
options = _objectSpread$1({}, options, {}, isUSKeyboardCharacter(text) ? cleanKey(text) : { | ||
key: text | ||
}); | ||
this.fireAllEvents({ | ||
options, | ||
typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
type({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
for (const char of text) { | ||
this.char({ | ||
text: char, | ||
options, | ||
typing: true | ||
}); | ||
this.fireAllEvents({ | ||
options: options, | ||
typing: typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
}, { | ||
key: "type", | ||
return this; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
value: function type(_ref7) { | ||
var text = _ref7.text, | ||
_ref7$options = _ref7.options, | ||
options = _ref7$options === void 0 ? Object.create(null) : _ref7$options; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = text[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var char = _step.value; | ||
this.char({ | ||
text: char, | ||
options: options, | ||
typing: true | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
mod({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
let modifiers = text.split(/-(?!$)/); | ||
let result = modifiers[modifiers.length - 1]; | ||
modifiers = coreHelpers.take(modifiers, modifiers.length - 1); | ||
return this; | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "mod", | ||
value: function mod(_ref8) { | ||
var text = _ref8.text, | ||
_ref8$options = _ref8.options, | ||
options = _ref8$options === void 0 ? Object.create(null) : _ref8$options; | ||
var modifiers = text.split(/-(?!$)/); | ||
var result = modifiers[modifiers.length - 1]; | ||
modifiers = coreHelpers.take(modifiers, modifiers.length - 1); | ||
const info = getModifierInformation({ | ||
modifiers, | ||
isMac: this.isMac | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread$1({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
var info = getModifierInformation({ | ||
modifiers: modifiers, | ||
isMac: this.isMac | ||
fireAllEvents({ | ||
options, | ||
typing = false | ||
}) { | ||
this.keyDown({ | ||
options | ||
}); | ||
if (!coreHelpers.includes(noKeyPress, options.key) || typing && isUSKeyboardCharacter(options.key) && usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread$1({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
}, { | ||
key: "fireAllEvents", | ||
value: function fireAllEvents(_ref9) { | ||
var options = _ref9.options, | ||
_ref9$typing = _ref9.typing, | ||
typing = _ref9$typing === void 0 ? false : _ref9$typing; | ||
this.keyDown({ | ||
options: options | ||
if (!coreHelpers.includes(noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options | ||
}); | ||
} | ||
if (!coreHelpers.includes(noKeyPress, options.key) || typing && isUSKeyboardCharacter(options.key) && usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
if (!coreHelpers.includes(noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
fireModifierEvents({ | ||
altKey, | ||
ctrlKey, | ||
metaKey, | ||
shiftKey | ||
}, type) { | ||
const event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Shift')) | ||
}); | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
}, { | ||
key: "fireModifierEvents", | ||
value: function fireModifierEvents(_ref10, type) { | ||
var altKey = _ref10.altKey, | ||
ctrlKey = _ref10.ctrlKey, | ||
metaKey = _ref10.metaKey, | ||
shiftKey = _ref10.shiftKey; | ||
var event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Shift')) | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Meta')) | ||
}); | ||
} | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Meta')) | ||
}); | ||
} else { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
}); | ||
} | ||
} | ||
if (ctrlKey) { | ||
} else { | ||
event({ | ||
@@ -1804,52 +1726,54 @@ options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
} | ||
} | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Alt')) | ||
}); | ||
} | ||
if (ctrlKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
}); | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
}, { | ||
key: "dispatchEvent", | ||
value: function dispatchEvent(type, options) { | ||
var _this2 = this; | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Alt')) | ||
}); | ||
} | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var event = createKeyboardEvent(type, _objectSpread$1({}, this.defaultOptions, {}, options)); | ||
dispatchEvent(type, options) { | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var dispatch = function dispatch() { | ||
_this2.target.dispatchEvent(event); | ||
const event = createKeyboardEvent(type, _objectSpread$1({}, this.defaultOptions, {}, options)); | ||
if (_this2.onEventDispatch) { | ||
_this2.onEventDispatch(event); | ||
} | ||
}; | ||
const dispatch = () => { | ||
this.target.dispatchEvent(event); | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch: dispatch, | ||
event: event, | ||
type: type | ||
}); | ||
} else { | ||
dispatch(); | ||
if (this.onEventDispatch) { | ||
this.onEventDispatch(event); | ||
} | ||
}; | ||
return this; | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch, | ||
event, | ||
type | ||
}); | ||
} else { | ||
dispatch(); | ||
} | ||
}]); | ||
return Keyboard; | ||
}(); | ||
return this; | ||
} | ||
} | ||
exports.Keyboard = Keyboard; | ||
@@ -1856,0 +1780,0 @@ exports.cleanKey = cleanKey; |
@@ -1,3 +0,1 @@ | ||
import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
import _createClass from '@babel/runtime/helpers/createClass'; | ||
import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
@@ -10,3 +8,3 @@ import { isString, omit, take, includes } from '@remirror/core-helpers'; | ||
var rawUSKeyboardLayout = { | ||
const rawUSKeyboardLayout = { | ||
'0': { | ||
@@ -330,3 +328,3 @@ keyCode: 48, | ||
code: 'NumpadDecimal', | ||
key: "\0", | ||
key: '\u0000', | ||
shiftKey: '.', | ||
@@ -890,5 +888,5 @@ location: 3 | ||
}, | ||
"\0": { | ||
'\u0000': { | ||
keyCode: 46, | ||
key: "\0", | ||
key: '\u0000', | ||
code: 'NumpadDecimal', | ||
@@ -1353,5 +1351,5 @@ location: 3 | ||
}; | ||
var noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
var noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
var usKeyboardLayout = rawUSKeyboardLayout; | ||
const noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
const noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
const usKeyboardLayout = rawUSKeyboardLayout; | ||
@@ -1363,5 +1361,3 @@ /** | ||
*/ | ||
var isUSKeyboardCharacter = function isUSKeyboardCharacter(char) { | ||
return isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
}; | ||
const isUSKeyboardCharacter = char => isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
@@ -1378,7 +1374,5 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
var createKeyboardEvent = function createKeyboardEvent(type, options) { | ||
return new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
}; | ||
const createKeyboardEvent = (type, options) => new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
@@ -1392,7 +1386,7 @@ /** | ||
*/ | ||
var getModifierInformation = function getModifierInformation(_ref) { | ||
var modifiers = _ref.modifiers, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac; | ||
var info = { | ||
const getModifierInformation = ({ | ||
modifiers, | ||
isMac = false | ||
}) => { | ||
const info = { | ||
altKey: false, | ||
@@ -1403,41 +1397,21 @@ ctrlKey: false, | ||
}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = modifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var modifier = _step.value; | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
for (const modifier of modifiers) { | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
} else { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else { | ||
info.ctrlKey = true; | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -1453,5 +1427,3 @@ | ||
var cleanKey = function cleanKey(key) { | ||
return omit(usKeyboardLayout[key], ['shiftKey']); | ||
}; | ||
const cleanKey = key => omit(usKeyboardLayout[key], ['shiftKey']); | ||
@@ -1461,40 +1433,26 @@ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var Keyboard = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Keyboard, [{ | ||
key: "started", | ||
get: function get() { | ||
return this.status === 'started'; | ||
} | ||
}], [{ | ||
key: "create", | ||
value: function create(params) { | ||
return new Keyboard(params); | ||
} | ||
}, { | ||
key: "defaultOptions", | ||
get: function get() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
}]); | ||
class Keyboard { | ||
static create(params) { | ||
return new Keyboard(params); | ||
} | ||
function Keyboard(_ref) { | ||
var _this = this; | ||
static get defaultOptions() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
var target = _ref.target, | ||
_ref$defaultOptions = _ref.defaultOptions, | ||
defaultOptions = _ref$defaultOptions === void 0 ? Keyboard.defaultOptions : _ref$defaultOptions, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac, | ||
_ref$batch = _ref.batch, | ||
batch = _ref$batch === void 0 ? false : _ref$batch, | ||
onEventDispatch = _ref.onEventDispatch; | ||
get started() { | ||
return this.status === 'started'; | ||
} | ||
_classCallCheck(this, Keyboard); | ||
constructor({ | ||
target, | ||
defaultOptions = Keyboard.defaultOptions, | ||
isMac = false, | ||
batch = false, | ||
onEventDispatch | ||
}) { | ||
_defineProperty(this, "status", 'idle'); | ||
@@ -1504,15 +1462,18 @@ | ||
_defineProperty(this, "keyDown", function (_ref2) { | ||
var options = _ref2.options; | ||
return _this.dispatchEvent('keydown', options); | ||
_defineProperty(this, "keyDown", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keydown', options); | ||
}); | ||
_defineProperty(this, "keyPress", function (_ref3) { | ||
var options = _ref3.options; | ||
return _this.dispatchEvent('keypress', options); | ||
_defineProperty(this, "keyPress", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keypress', options); | ||
}); | ||
_defineProperty(this, "keyUp", function (_ref4) { | ||
var options = _ref4.options; | ||
return _this.dispatchEvent('keyup', options); | ||
_defineProperty(this, "keyUp", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keyup', options); | ||
}); | ||
@@ -1531,263 +1492,224 @@ | ||
_createClass(Keyboard, [{ | ||
key: "start", | ||
value: function start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
}, { | ||
key: "end", | ||
value: function end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
this.status = 'ended'; | ||
end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
}, { | ||
key: "forEach", | ||
value: function forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
}, { | ||
key: "runBatchedEvents", | ||
value: function runBatchedEvents() { | ||
this.actions.forEach(function (action) { | ||
action.dispatch(); | ||
}); | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "usChar", | ||
value: function usChar(_ref5) { | ||
var text = _ref5.text, | ||
_ref5$options = _ref5.options, | ||
options = _ref5$options === void 0 ? Object.create(null) : _ref5$options, | ||
_ref5$typing = _ref5.typing, | ||
typing = _ref5$typing === void 0 ? false : _ref5$typing; | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
if (!isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
return this.char({ | ||
text: text, | ||
options: options, | ||
typing: typing | ||
}); | ||
runBatchedEvents() { | ||
this.actions.forEach(action => { | ||
action.dispatch(); | ||
}); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
usChar({ | ||
text, | ||
options = Object.create(null), | ||
typing = false | ||
}) { | ||
if (!isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "char", | ||
value: function char(_ref6) { | ||
var text = _ref6.text, | ||
options = _ref6.options, | ||
typing = _ref6.typing; | ||
options = _objectSpread$1({}, options, {}, isUSKeyboardCharacter(text) ? cleanKey(text) : { | ||
key: text | ||
return this.char({ | ||
text, | ||
options, | ||
typing | ||
}); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
char({ | ||
text, | ||
options, | ||
typing | ||
}) { | ||
options = _objectSpread$1({}, options, {}, isUSKeyboardCharacter(text) ? cleanKey(text) : { | ||
key: text | ||
}); | ||
this.fireAllEvents({ | ||
options, | ||
typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
type({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
for (const char of text) { | ||
this.char({ | ||
text: char, | ||
options, | ||
typing: true | ||
}); | ||
this.fireAllEvents({ | ||
options: options, | ||
typing: typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
}, { | ||
key: "type", | ||
return this; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
value: function type(_ref7) { | ||
var text = _ref7.text, | ||
_ref7$options = _ref7.options, | ||
options = _ref7$options === void 0 ? Object.create(null) : _ref7$options; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = text[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var char = _step.value; | ||
this.char({ | ||
text: char, | ||
options: options, | ||
typing: true | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
mod({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
let modifiers = text.split(/-(?!$)/); | ||
let result = modifiers[modifiers.length - 1]; | ||
modifiers = take(modifiers, modifiers.length - 1); | ||
return this; | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "mod", | ||
value: function mod(_ref8) { | ||
var text = _ref8.text, | ||
_ref8$options = _ref8.options, | ||
options = _ref8$options === void 0 ? Object.create(null) : _ref8$options; | ||
var modifiers = text.split(/-(?!$)/); | ||
var result = modifiers[modifiers.length - 1]; | ||
modifiers = take(modifiers, modifiers.length - 1); | ||
const info = getModifierInformation({ | ||
modifiers, | ||
isMac: this.isMac | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread$1({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
var info = getModifierInformation({ | ||
modifiers: modifiers, | ||
isMac: this.isMac | ||
fireAllEvents({ | ||
options, | ||
typing = false | ||
}) { | ||
this.keyDown({ | ||
options | ||
}); | ||
if (!includes(noKeyPress, options.key) || typing && isUSKeyboardCharacter(options.key) && usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread$1({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
}, { | ||
key: "fireAllEvents", | ||
value: function fireAllEvents(_ref9) { | ||
var options = _ref9.options, | ||
_ref9$typing = _ref9.typing, | ||
typing = _ref9$typing === void 0 ? false : _ref9$typing; | ||
this.keyDown({ | ||
options: options | ||
if (!includes(noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options | ||
}); | ||
} | ||
if (!includes(noKeyPress, options.key) || typing && isUSKeyboardCharacter(options.key) && usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
if (!includes(noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
fireModifierEvents({ | ||
altKey, | ||
ctrlKey, | ||
metaKey, | ||
shiftKey | ||
}, type) { | ||
const event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Shift')) | ||
}); | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
}, { | ||
key: "fireModifierEvents", | ||
value: function fireModifierEvents(_ref10, type) { | ||
var altKey = _ref10.altKey, | ||
ctrlKey = _ref10.ctrlKey, | ||
metaKey = _ref10.metaKey, | ||
shiftKey = _ref10.shiftKey; | ||
var event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Shift')) | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Meta')) | ||
}); | ||
} | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Meta')) | ||
}); | ||
} else { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
}); | ||
} | ||
} | ||
if (ctrlKey) { | ||
} else { | ||
event({ | ||
@@ -1797,53 +1719,55 @@ options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
} | ||
} | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Alt')) | ||
}); | ||
} | ||
if (ctrlKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Control')) | ||
}); | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
}, { | ||
key: "dispatchEvent", | ||
value: function dispatchEvent(type, options) { | ||
var _this2 = this; | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread$1({}, this.defaultOptions, {}, cleanKey('Alt')) | ||
}); | ||
} | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var event = createKeyboardEvent(type, _objectSpread$1({}, this.defaultOptions, {}, options)); | ||
dispatchEvent(type, options) { | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var dispatch = function dispatch() { | ||
_this2.target.dispatchEvent(event); | ||
const event = createKeyboardEvent(type, _objectSpread$1({}, this.defaultOptions, {}, options)); | ||
if (_this2.onEventDispatch) { | ||
_this2.onEventDispatch(event); | ||
} | ||
}; | ||
const dispatch = () => { | ||
this.target.dispatchEvent(event); | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch: dispatch, | ||
event: event, | ||
type: type | ||
}); | ||
} else { | ||
dispatch(); | ||
if (this.onEventDispatch) { | ||
this.onEventDispatch(event); | ||
} | ||
}; | ||
return this; | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch, | ||
event, | ||
type | ||
}); | ||
} else { | ||
dispatch(); | ||
} | ||
}]); | ||
return Keyboard; | ||
}(); | ||
return this; | ||
} | ||
} | ||
export { Keyboard, cleanKey, createKeyboardEvent, getModifierInformation, isUSKeyboardCharacter, noKeyPress, noKeyUp, usKeyboardLayout }; | ||
//# sourceMappingURL=test-keyboard.esm.js.map |
@@ -21,7 +21,5 @@ 'use strict'; | ||
var createKeyboardEvent = function createKeyboardEvent(type, options) { | ||
return new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
}; | ||
const createKeyboardEvent = (type, options) => new KeyboardEvent(type, _objectSpread({}, options, { | ||
bubbles: true | ||
})); | ||
@@ -35,7 +33,7 @@ /** | ||
*/ | ||
var getModifierInformation = function getModifierInformation(_ref) { | ||
var modifiers = _ref.modifiers, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac; | ||
var info = { | ||
const getModifierInformation = ({ | ||
modifiers, | ||
isMac = false | ||
}) => { | ||
const info = { | ||
altKey: false, | ||
@@ -46,41 +44,21 @@ ctrlKey: false, | ||
}; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = modifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var modifier = _step.value; | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
for (const modifier of modifiers) { | ||
if (/^(cmd|meta|m)$/i.test(modifier)) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else if (/^a(lt)?$/i.test(modifier)) { | ||
info.altKey = true; | ||
} else if (/^(c|ctrl|control)$/i.test(modifier)) { | ||
} else { | ||
info.ctrlKey = true; | ||
} else if (/^s(hift)?$/i.test(modifier)) { | ||
info.shiftKey = true; | ||
} else if (/^mod$/i.test(modifier)) { | ||
if (isMac) { | ||
info.metaKey = true; | ||
} else { | ||
info.ctrlKey = true; | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} else { | ||
throw new Error("Unrecognized modifier name: ".concat(modifier)); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -96,5 +74,3 @@ | ||
var cleanKey = function cleanKey(key) { | ||
return coreHelpers.omit(usKeyboardLayout.usKeyboardLayout[key], ['shiftKey']); | ||
}; | ||
const cleanKey = key => coreHelpers.omit(usKeyboardLayout.usKeyboardLayout[key], ['shiftKey']); | ||
@@ -101,0 +77,0 @@ exports.cleanKey = cleanKey; |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _classCallCheck = _interopDefault(require('@babel/runtime/helpers/classCallCheck')); | ||
var _createClass = _interopDefault(require('@babel/runtime/helpers/createClass')); | ||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty')); | ||
@@ -18,40 +16,26 @@ var coreHelpers = require('@remirror/core-helpers'); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var Keyboard = | ||
/*#__PURE__*/ | ||
function () { | ||
_createClass(Keyboard, [{ | ||
key: "started", | ||
get: function get() { | ||
return this.status === 'started'; | ||
} | ||
}], [{ | ||
key: "create", | ||
value: function create(params) { | ||
return new Keyboard(params); | ||
} | ||
}, { | ||
key: "defaultOptions", | ||
get: function get() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
}]); | ||
class Keyboard { | ||
static create(params) { | ||
return new Keyboard(params); | ||
} | ||
function Keyboard(_ref) { | ||
var _this = this; | ||
static get defaultOptions() { | ||
return { | ||
bubbles: true, | ||
cancelable: true, | ||
composed: true | ||
}; | ||
} | ||
var target = _ref.target, | ||
_ref$defaultOptions = _ref.defaultOptions, | ||
defaultOptions = _ref$defaultOptions === void 0 ? Keyboard.defaultOptions : _ref$defaultOptions, | ||
_ref$isMac = _ref.isMac, | ||
isMac = _ref$isMac === void 0 ? false : _ref$isMac, | ||
_ref$batch = _ref.batch, | ||
batch = _ref$batch === void 0 ? false : _ref$batch, | ||
onEventDispatch = _ref.onEventDispatch; | ||
get started() { | ||
return this.status === 'started'; | ||
} | ||
_classCallCheck(this, Keyboard); | ||
constructor({ | ||
target, | ||
defaultOptions = Keyboard.defaultOptions, | ||
isMac = false, | ||
batch = false, | ||
onEventDispatch | ||
}) { | ||
_defineProperty(this, "status", 'idle'); | ||
@@ -61,15 +45,18 @@ | ||
_defineProperty(this, "keyDown", function (_ref2) { | ||
var options = _ref2.options; | ||
return _this.dispatchEvent('keydown', options); | ||
_defineProperty(this, "keyDown", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keydown', options); | ||
}); | ||
_defineProperty(this, "keyPress", function (_ref3) { | ||
var options = _ref3.options; | ||
return _this.dispatchEvent('keypress', options); | ||
_defineProperty(this, "keyPress", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keypress', options); | ||
}); | ||
_defineProperty(this, "keyUp", function (_ref4) { | ||
var options = _ref4.options; | ||
return _this.dispatchEvent('keyup', options); | ||
_defineProperty(this, "keyUp", ({ | ||
options | ||
}) => { | ||
return this.dispatchEvent('keyup', options); | ||
}); | ||
@@ -88,263 +75,224 @@ | ||
_createClass(Keyboard, [{ | ||
key: "start", | ||
value: function start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
start() { | ||
if (this.started) { | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
}, { | ||
key: "end", | ||
value: function end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
this.status = 'started'; | ||
return this; | ||
} | ||
/** | ||
* Ends the fake timers and sets the keyboard status to 'ended' | ||
*/ | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
this.status = 'ended'; | ||
end() { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
}, { | ||
key: "forEach", | ||
value: function forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
if (this.batch) { | ||
this.runBatchedEvents(); | ||
this.actions = []; | ||
} | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* When batched is true the user can run through each event and fire as they please. | ||
*/ | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
forEach(fn) { | ||
if (!this.started) { | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
}, { | ||
key: "runBatchedEvents", | ||
value: function runBatchedEvents() { | ||
this.actions.forEach(function (action) { | ||
action.dispatch(); | ||
}); | ||
if (!this.batch) { | ||
throw new Error("'forEach' is only available when 'batched' is set to 'true'."); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "usChar", | ||
value: function usChar(_ref5) { | ||
var text = _ref5.text, | ||
_ref5$options = _ref5.options, | ||
options = _ref5$options === void 0 ? Object.create(null) : _ref5$options, | ||
_ref5$typing = _ref5.typing, | ||
typing = _ref5$typing === void 0 ? false : _ref5$typing; | ||
this.actions.forEach(fn); | ||
this.actions = []; | ||
this.status = 'ended'; | ||
return this; | ||
} | ||
/** | ||
* Runs all the batched events. | ||
*/ | ||
if (!usKeyboardLayout.isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
return this.char({ | ||
text: text, | ||
options: options, | ||
typing: typing | ||
}); | ||
runBatchedEvents() { | ||
this.actions.forEach(action => { | ||
action.dispatch(); | ||
}); | ||
} | ||
/** | ||
* Like `this.char` but only supports US Keyboard Characters. This is mainly | ||
* a utility for TypeScript and autocomplete support when typing characters. | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
usChar({ | ||
text, | ||
options = Object.create(null), | ||
typing = false | ||
}) { | ||
if (!usKeyboardLayout.isUSKeyboardCharacter(text)) { | ||
throw new Error('This is not a supported character. For generic characters use the `keyboard.char` method instead'); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "char", | ||
value: function char(_ref6) { | ||
var text = _ref6.text, | ||
options = _ref6.options, | ||
typing = _ref6.typing; | ||
options = _objectSpread({}, options, {}, usKeyboardLayout.isUSKeyboardCharacter(text) ? testKeyboardUtils.cleanKey(text) : { | ||
key: text | ||
return this.char({ | ||
text, | ||
options, | ||
typing | ||
}); | ||
} | ||
/** | ||
* Dispatches an event for a keyboard character | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
char({ | ||
text, | ||
options, | ||
typing | ||
}) { | ||
options = _objectSpread({}, options, {}, usKeyboardLayout.isUSKeyboardCharacter(text) ? testKeyboardUtils.cleanKey(text) : { | ||
key: text | ||
}); | ||
this.fireAllEvents({ | ||
options, | ||
typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
type({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
for (const char of text) { | ||
this.char({ | ||
text: char, | ||
options, | ||
typing: true | ||
}); | ||
this.fireAllEvents({ | ||
options: options, | ||
typing: typing | ||
}); | ||
return this; | ||
} | ||
/** | ||
* Triggers a keydown event with provided options | ||
* | ||
* @param params - see {@link OptionsParams} | ||
*/ | ||
}, { | ||
key: "type", | ||
return this; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
/** | ||
* Breaks a string into single characters and fires a keyboard into the target node | ||
* | ||
* @param params - see {@link TypingInputParams} | ||
*/ | ||
value: function type(_ref7) { | ||
var text = _ref7.text, | ||
_ref7$options = _ref7.options, | ||
options = _ref7$options === void 0 ? Object.create(null) : _ref7$options; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = text[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var char = _step.value; | ||
this.char({ | ||
text: char, | ||
options: options, | ||
typing: true | ||
}); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
mod({ | ||
text, | ||
options = Object.create(null) | ||
}) { | ||
let modifiers = text.split(/-(?!$)/); | ||
let result = modifiers[modifiers.length - 1]; | ||
modifiers = coreHelpers.take(modifiers, modifiers.length - 1); | ||
return this; | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
/** | ||
* Enables typing modifier commands | ||
* | ||
* ```ts | ||
* const editor = document.getElementById('editor'); | ||
* const keyboard = new Keyboard({ target: editor }); | ||
* keyboard | ||
* .mod({text: 'Shift-Meta-A'}) | ||
* .end(); | ||
* ``` | ||
* | ||
* @param params - see {@link TextInputParams} | ||
*/ | ||
}, { | ||
key: "mod", | ||
value: function mod(_ref8) { | ||
var text = _ref8.text, | ||
_ref8$options = _ref8.options, | ||
options = _ref8$options === void 0 ? Object.create(null) : _ref8$options; | ||
var modifiers = text.split(/-(?!$)/); | ||
var result = modifiers[modifiers.length - 1]; | ||
modifiers = coreHelpers.take(modifiers, modifiers.length - 1); | ||
const info = testKeyboardUtils.getModifierInformation({ | ||
modifiers, | ||
isMac: this.isMac | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
if (result === 'Space') { | ||
result = ' '; | ||
} | ||
var info = testKeyboardUtils.getModifierInformation({ | ||
modifiers: modifiers, | ||
isMac: this.isMac | ||
fireAllEvents({ | ||
options, | ||
typing = false | ||
}) { | ||
this.keyDown({ | ||
options | ||
}); | ||
if (!coreHelpers.includes(usKeyboardLayout.noKeyPress, options.key) || typing && usKeyboardLayout.isUSKeyboardCharacter(options.key) && usKeyboardLayout.usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options | ||
}); | ||
this.fireModifierEvents(info, 'keydown'); | ||
this.type({ | ||
text: result, | ||
options: _objectSpread({}, options, {}, info) | ||
}); | ||
this.fireModifierEvents(info, 'keyup'); | ||
return this; | ||
} | ||
/** | ||
* Fires events where valid. | ||
* | ||
* @param options - see {@link OptionsWithTypingParams} | ||
*/ | ||
}, { | ||
key: "fireAllEvents", | ||
value: function fireAllEvents(_ref9) { | ||
var options = _ref9.options, | ||
_ref9$typing = _ref9.typing, | ||
typing = _ref9$typing === void 0 ? false : _ref9$typing; | ||
this.keyDown({ | ||
options: options | ||
if (!coreHelpers.includes(usKeyboardLayout.noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options | ||
}); | ||
} | ||
if (!coreHelpers.includes(usKeyboardLayout.noKeyPress, options.key) || typing && usKeyboardLayout.isUSKeyboardCharacter(options.key) && usKeyboardLayout.usKeyboardLayout[options.key].text) { | ||
this.keyPress({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
if (!coreHelpers.includes(usKeyboardLayout.noKeyUp, options.key)) { | ||
this.keyUp({ | ||
options: options | ||
}); | ||
} | ||
return this; | ||
fireModifierEvents({ | ||
altKey, | ||
ctrlKey, | ||
metaKey, | ||
shiftKey | ||
}, type) { | ||
const event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Shift')) | ||
}); | ||
} | ||
/** | ||
* Fires all modifier events | ||
* | ||
* @param info - the modifier information for the keys see {@link ModifierInformation} | ||
* @param type - the keyboard event type | ||
* | ||
*/ | ||
}, { | ||
key: "fireModifierEvents", | ||
value: function fireModifierEvents(_ref10, type) { | ||
var altKey = _ref10.altKey, | ||
ctrlKey = _ref10.ctrlKey, | ||
metaKey = _ref10.metaKey, | ||
shiftKey = _ref10.shiftKey; | ||
var event = type === 'keydown' ? this.keyDown : this.keyUp; | ||
if (shiftKey) { | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Shift')) | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Meta')) | ||
}); | ||
} | ||
if (metaKey) { | ||
if (this.isMac) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Meta')) | ||
}); | ||
} else { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Control')) | ||
}); | ||
} | ||
} | ||
if (ctrlKey) { | ||
} else { | ||
event({ | ||
@@ -354,53 +302,55 @@ options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Control')) | ||
} | ||
} | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Alt')) | ||
}); | ||
} | ||
if (ctrlKey) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Control')) | ||
}); | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
}, { | ||
key: "dispatchEvent", | ||
value: function dispatchEvent(type, options) { | ||
var _this2 = this; | ||
if (altKey) { | ||
event({ | ||
options: _objectSpread({}, this.defaultOptions, {}, testKeyboardUtils.cleanKey('Alt')) | ||
}); | ||
} | ||
} | ||
/** | ||
* Dispatches the action or adds it to the queue when batching is enabled. | ||
* | ||
* @param type - the keyboard event name | ||
* @param options - options passed to the keyboard event. See {@link KeyboardEventInit} | ||
*/ | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var event = testKeyboardUtils.createKeyboardEvent(type, _objectSpread({}, this.defaultOptions, {}, options)); | ||
dispatchEvent(type, options) { | ||
if (!this.started) { | ||
this.start(); | ||
} | ||
var dispatch = function dispatch() { | ||
_this2.target.dispatchEvent(event); | ||
const event = testKeyboardUtils.createKeyboardEvent(type, _objectSpread({}, this.defaultOptions, {}, options)); | ||
if (_this2.onEventDispatch) { | ||
_this2.onEventDispatch(event); | ||
} | ||
}; | ||
const dispatch = () => { | ||
this.target.dispatchEvent(event); | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch: dispatch, | ||
event: event, | ||
type: type | ||
}); | ||
} else { | ||
dispatch(); | ||
if (this.onEventDispatch) { | ||
this.onEventDispatch(event); | ||
} | ||
}; | ||
return this; | ||
if (this.batch) { | ||
this.actions.push({ | ||
dispatch, | ||
event, | ||
type | ||
}); | ||
} else { | ||
dispatch(); | ||
} | ||
}]); | ||
return Keyboard; | ||
}(); | ||
return this; | ||
} | ||
} | ||
exports.Keyboard = Keyboard; | ||
//# sourceMappingURL=test-keyboard.js.map |
@@ -11,3 +11,3 @@ 'use strict'; | ||
var rawUSKeyboardLayout = { | ||
const rawUSKeyboardLayout = { | ||
'0': { | ||
@@ -331,3 +331,3 @@ keyCode: 48, | ||
code: 'NumpadDecimal', | ||
key: "\0", | ||
key: '\u0000', | ||
shiftKey: '.', | ||
@@ -891,5 +891,5 @@ location: 3 | ||
}, | ||
"\0": { | ||
'\u0000': { | ||
keyCode: 46, | ||
key: "\0", | ||
key: '\u0000', | ||
code: 'NumpadDecimal', | ||
@@ -1354,5 +1354,5 @@ location: 3 | ||
}; | ||
var noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
var noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
var usKeyboardLayout = rawUSKeyboardLayout; | ||
const noKeyPress = ['Power', 'Eject', 'Abort', 'Help', 'Backspace', 'Tab', 'Numpad5', 'NumpadEnter', 'Enter', 'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight', 'AltLeft', 'AltRight', 'Pause', 'CapsLock', 'Escape', 'Convert', 'NonConvert', 'Space', 'PageUp', 'PageDown', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'ArrowDown', 'Select', 'Open', 'PrintScreen', 'Delete', 'MetaLeft', 'MetaRight', 'ContextMenu', 'NumLock', 'ScrollLock', 'AudioVolumeMute', 'AudioVolumeDown', 'AudioVolumeUp', 'MediaTrackNext', 'MediaTrackPrevious', 'MediaStop', 'MediaPlayPause', 'AltGraph', 'Props', 'Cancel', 'Clear', 'Shift', 'Control', 'Alt', 'Accept', 'ModeChange', 'Print', 'Execute', 'Meta', 'Attn', 'CrSel', 'ExSel', 'EraseEof', 'Play', 'ZoomOut']; | ||
const noKeyUp = ['CapsLock', 'NumLock', 'ScrollLock']; | ||
const usKeyboardLayout = rawUSKeyboardLayout; | ||
@@ -1364,5 +1364,3 @@ /** | ||
*/ | ||
var isUSKeyboardCharacter = function isUSKeyboardCharacter(char) { | ||
return coreHelpers.isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
}; | ||
const isUSKeyboardCharacter = char => coreHelpers.isString(char) && Object.keys(rawUSKeyboardLayout).includes(char); | ||
@@ -1369,0 +1367,0 @@ exports.isUSKeyboardCharacter = isUSKeyboardCharacter; |
@@ -8,3 +8,3 @@ { | ||
"repository": "https://github.com/remirror/remirror/tree/master/packages/test-keyboard", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"main": "lib/index.js", | ||
@@ -21,4 +21,4 @@ "module": "lib/dist/test-keyboard.esm.js", | ||
"@babel/runtime": "^7", | ||
"@remirror/core-helpers": "^0.7.4", | ||
"@remirror/core-types": "^0.7.4" | ||
"@remirror/core-helpers": "^0.7.5", | ||
"@remirror/core-types": "^0.8.0" | ||
}, | ||
@@ -25,0 +25,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
381035
7685
+ Added@remirror/core-types@0.8.0(transitive)
+ Addedtype-fest@0.10.0(transitive)
- Removed@remirror/core-types@0.7.4(transitive)
Updated@remirror/core-types@^0.8.0