Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slate-hotkeys

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slate-hotkeys - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

8

Changelog.md

@@ -7,4 +7,12 @@ # Changelog

### `0.2.0` — August 7, 2018
###### BREAKING
**Some hotkey checkers have changed or been removed.** Please check the source to see the changes, sorry for the hassle. This was needed to cleanup the behavior and get this package to not be leaky in terms of what checkers it exposed.
---
### `0.1.0` — April 5, 2018
:tada:

229

dist/slate-hotkeys.js

@@ -108,7 +108,15 @@ (function (global, factory) {

var object = parseHotkey(hotkey, options);
var ret = event == null ? function (e) {
return compareHotkey(object, e);
} : compareHotkey(object, event);
if (!Array.isArray(hotkey)) {
hotkey = [hotkey];
}
var array = hotkey.map(function (string) {
return parseHotkey(string, options);
});
var check = function check(e) {
return array.some(function (object) {
return compareHotkey(object, e);
});
};
var ret = event == null ? check : check(event);
return ret;

@@ -152,2 +160,8 @@ }

var optional = value.endsWith('?');
if (optional) {
value = value.slice(0, -1);
}
var name = toKeyName(value);

@@ -165,3 +179,3 @@ var modifier = MODIFIERS[name];

if (modifier) {
ret[modifier] = true;
ret[modifier] = optional ? null : true;
}

@@ -202,5 +216,7 @@

if (expected == null) continue;
if (expected == null) {
continue;
}
if (key == 'key') {
if (key === 'key') {
actual = event.key.toLowerCase();

@@ -213,3 +229,9 @@ } else if (key == 'which') {

if (actual != expected) return false;
if (actual == null && expected === false) {
continue;
}
if (actual !== expected) {
return false;
}
}

@@ -441,154 +463,77 @@

/**
* Is Apple?
* Hotkey mappings for each platform.
*
* @type {Boolean}
* @type {Object}
*/
var IS_APPLE = IS_IOS || IS_MAC;
/**
* Hotkeys.
*
* @type {Function}
*/
var isBold = lib_3('mod+b');
var isItalic = lib_3('mod+i');
var isEnter = lib_3('enter');
var isShiftEnter = lib_3('shift+enter');
var isSplitBlock = function isSplitBlock(e) {
return isEnter(e) || isShiftEnter(e);
var HOTKEYS = {
bold: 'mod+b',
compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
moveBackward: 'mod?+ctrl?+alt?+left',
moveForward: 'mod?+ctrl?+alt?+right',
deleteBackward: 'shift?+backspace',
deleteForward: 'shift?+delete',
extendBackward: 'shift+left',
extendForward: 'shift+right',
italic: 'mod+i',
splitBlock: 'shift?+enter',
undo: 'mod+z'
};
var isBackspace = lib_3('backspace');
var isShiftBackspace = lib_3('shift+backspace');
var isDelete = lib_3('delete');
var isShiftDelete = lib_3('shift+delete');
var isDeleteBackward = function isDeleteBackward(e) {
return isBackspace(e) || isShiftBackspace(e);
var APPLE_HOTKEYS = {
moveLineBackward: 'opt+up',
moveLineForward: 'opt+down',
deleteBackward: ['ctrl+backspace', 'ctrl+h'],
deleteForward: ['ctrl+delete', 'ctrl+d'],
deleteLineBackward: 'cmd+shift?+backspace',
deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
deleteWordBackward: 'opt+shift?+backspace',
deleteWordForward: 'opt+shift?+delete',
extendLineBackward: 'opt+shift+up',
extendLineForward: 'opt+shift+down',
redo: 'cmd+shift+z',
transposeCharacter: 'ctrl+t'
};
var isDeleteForward = function isDeleteForward(e) {
return isDelete(e) || isShiftDelete(e);
};
var isDeleteCharBackwardMac = lib_3('ctrl+h');
var isDeleteCharForwardMac = lib_3('ctrl+d');
var isDeleteCharBackward = function isDeleteCharBackward(e) {
return isDeleteBackward(e) || IS_APPLE && isDeleteCharBackwardMac(e);
};
var isDeleteCharForward = function isDeleteCharForward(e) {
return isDeleteForward(e) || IS_APPLE && isDeleteCharForwardMac(e);
};
var WINDOWS_HOTKEYS = {
deleteWordBackward: 'ctrl+shift?+backspace',
deleteWordForward: 'ctrl+shift?+delete',
redo: 'ctrl+y'
var isDeleteLineBackwardMac = function isDeleteLineBackwardMac(e) {
return lib_3('cmd+shift+backspace', e) || lib_3('cmd+backspace', e);
};
var isDeleteLineForwardMac = lib_3('ctrl+k');
var isDeleteLineBackward = function isDeleteLineBackward(e) {
return IS_APPLE && isDeleteLineBackwardMac(e);
};
var isDeleteLineForward = function isDeleteLineForward(e) {
return IS_APPLE && isDeleteLineForwardMac(e);
};
/**
* Hotkeys.
*
* @type {Object}
*/
var isDeleteWordBackwardMac = function isDeleteWordBackwardMac(e) {
return lib_3('shift+option+backspace', e) || lib_3('option+backspace', e);
};
var isDeleteWordBackwardPC = lib_3('ctrl+backspace');
var isDeleteWordForwardMac = function isDeleteWordForwardMac(e) {
return lib_3('shift+option+delete', e) || lib_3('option+delete', e);
};
var isDeleteWordForwardPC = lib_3('ctrl+delete');
var isDeleteWordBackward = function isDeleteWordBackward(e) {
return IS_APPLE ? isDeleteWordBackwardMac(e) : isDeleteWordBackwardPC(e);
};
var isDeleteWordForward = function isDeleteWordForward(e) {
return IS_APPLE ? isDeleteWordForwardMac(e) : isDeleteWordForwardPC(e);
};
};var Hotkeys = {};
var isExtendCharForward = lib_3('shift+right');
var isExtendCharBackward = lib_3('shift+left');
var IS_APPLE = IS_IOS || IS_MAC;
var IS_WINDOWS$1 = !IS_APPLE;
var KEYS = [].concat(Object.keys(HOTKEYS)).concat(Object.keys(APPLE_HOTKEYS)).concat(Object.keys(WINDOWS_HOTKEYS));
var isRightArrow = lib_3('right');
var isLeftArrow = lib_3('left');
var isCollapseCharForward = function isCollapseCharForward(e) {
return isRightArrow(e) && !isExtendCharForward(e);
};
var isCollapseCharBackward = function isCollapseCharBackward(e) {
return isLeftArrow(e) && !isExtendCharBackward(e);
};
KEYS.forEach(function (key) {
var method = 'is' + key[0].toUpperCase() + key.slice(1);
if (Hotkeys[method]) return;
var isCollapseLineBackwardMac = lib_3('option+up');
var isCollapseLineForwardMac = lib_3('option+down');
var isCollapseLineBackward = function isCollapseLineBackward(e) {
return IS_APPLE && isCollapseLineBackwardMac(e);
};
var isCollapseLineForward = function isCollapseLineForward(e) {
return IS_APPLE && isCollapseLineForwardMac(e);
};
var generic = HOTKEYS[key];
var apple = APPLE_HOTKEYS[key];
var windows = WINDOWS_HOTKEYS[key];
var isExtendLineBackwardMac = lib_3('option+shift+up');
var isExtendLineForwardMac = lib_3('option+shift+down');
var isExtendLineBackward = function isExtendLineBackward(e) {
return IS_APPLE && isExtendLineBackwardMac(e);
};
var isExtendLineForward = function isExtendLineForward(e) {
return IS_APPLE && isExtendLineForwardMac(e);
};
var isGeneric = generic && lib_3(generic);
var isApple = apple && lib_3(apple);
var isWindows = windows && lib_3(windows);
var isUndo = lib_3('mod+z');
var isRedoMac = lib_3('mod+shift+z');
var isRedoPC = lib_3('mod+y');
var isRedo = function isRedo(e) {
return IS_APPLE ? isRedoMac(e) : isRedoPC(e);
};
Hotkeys[method] = function (event) {
if (isGeneric && isGeneric(event)) return true;
if (IS_APPLE && isApple && isApple(event)) return true;
if (IS_WINDOWS$1 && isWindows && isWindows(event)) return true;
return false;
};
});
var isTransposeCharacterMac = lib_3('ctrl+t');
var isTransposeCharacter = function isTransposeCharacter(e) {
return IS_APPLE && isTransposeCharacterMac(e);
};
exports.default = Hotkeys;
var isContentEditable = function isContentEditable(e) {
return isBold(e) || isDeleteCharBackward(e) || isDeleteCharForward(e) || isDeleteLineBackward(e) || isDeleteLineForward(e) || isDeleteWordBackward(e) || isDeleteWordForward(e) || isItalic(e) || isRedo(e) || isSplitBlock(e) || isTransposeCharacter(e) || isUndo(e);
};
var isComposing = function isComposing(e) {
return e.key == 'ArrowDown' || e.key == 'ArrowLeft' || e.key == 'ArrowRight' || e.key == 'ArrowUp' || e.key == 'Backspace' || e.key == 'Enter';
};
/**
* Export.
*
* @type {Object}
*/
var index$1 = {
isBold: isBold,
isCollapseCharBackward: isCollapseCharBackward,
isCollapseCharForward: isCollapseCharForward,
isCollapseLineBackward: isCollapseLineBackward,
isCollapseLineForward: isCollapseLineForward,
isComposing: isComposing,
isContentEditable: isContentEditable,
isDeleteCharBackward: isDeleteCharBackward,
isDeleteCharForward: isDeleteCharForward,
isDeleteLineBackward: isDeleteLineBackward,
isDeleteLineForward: isDeleteLineForward,
isDeleteWordBackward: isDeleteWordBackward,
isDeleteWordForward: isDeleteWordForward,
isExtendCharBackward: isExtendCharBackward,
isExtendCharForward: isExtendCharForward,
isExtendLineBackward: isExtendLineBackward,
isExtendLineForward: isExtendLineForward,
isItalic: isItalic,
isRedo: isRedo,
isSplitBlock: isSplitBlock,
isUndo: isUndo
};
exports.default = index$1;
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.SlateHotkeys={})}(this,function(e){"use strict";var t,r,o=(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});for(var r={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},o={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:"undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform)?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},i=1;i<20;i++)n["f"+i]=111+i;function a(e,t,r){!t||"byKey"in t||(r=t,t=null);var o=c(e,t);return null==r?function(e){return u(o,e)}:u(o,r)}function c(e,t){var o=t&&t.byKey,n={},i=(e=e.replace("++","+add")).split("+"),a=i.length;for(var c in r)n[r[c]]=!1;var u=!0,l=!1,s=void 0;try{for(var y,p=i[Symbol.iterator]();!(u=(y=p.next()).done);u=!0){var w=y.value,h=f(w),m=r[h];1!=a&&m||(o?n.key=h:n.which=d(w)),m&&(n[m]=!0),1==a&&!m&&o&&(n.shiftKey=null)}}catch(e){l=!0,s=e}finally{try{!u&&p.return&&p.return()}finally{if(l)throw s}}return n}function u(e,t){for(var r in e){var o=e[r];if(null!=o&&("key"==r?t.key.toLowerCase():"which"==r?91==o&&93==t.which?91:t.which:t[r])!=o)return!1}return!0}function d(e){return e=f(e),n[e]||e.toUpperCase().charCodeAt(0)}function f(e){return e=e.toLowerCase(),e=o[e]||e}t.default=a,t.isHotkey=a,t.isCodeHotkey=function(e,t){return a(e,t)},t.isKeyHotkey=function(e,t){return a(e,{byKey:!0},t)},t.parseHotkey=c,t.compareHotkey=u,t.toKeyCode=d,t.toKeyName=f}(t={exports:{}},t.exports),t.exports);(r=o)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")&&r.default;o.isHotkey,o.isCodeHotkey;var n=o.isKeyHotkey,i=(o.parseHotkey,o.compareHotkey,o.toKeyCode,o.toKeyName,"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e}),a="object"===("undefined"==typeof window?"undefined":i(window))&&"object"===("undefined"==typeof document?"undefined":i(document))&&9===document.nodeType,c=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,i=void 0;try{for(var a,c=e[Symbol.iterator]();!(o=(a=c.next()).done)&&(r.push(a.value),!t||r.length!==t);o=!0);}catch(e){n=!0,i=e}finally{try{!o&&c.return&&c.return()}finally{if(n)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),u={},d=void 0;if(a){var f=window.navigator.userAgent,l=!0,s=!1,y=void 0;try{for(var p,w=[["edge",/Edge\/([0-9\._]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["android",/Android\s([0-9\.]+)/],["safari",/Version\/([0-9\._]+).*Safari/]][Symbol.iterator]();!(l=(p=w.next()).done);l=!0){var h=c(p.value,2);h[0];if(h[1].test(f))break}}catch(e){s=!0,y=e}finally{try{!l&&w.return&&w.return()}finally{if(s)throw y}}var m=!0,k=!1,b=void 0;try{for(var v,C=[["ios",/os ([\.\_\d]+) like mac os/i],["macos",/mac os x/i],["android",/android/i],["firefoxos",/mozilla\/[a-z\.\_\d]+ \((?:mobile)|(?:tablet)/i],["windows",/windows\s*(?:nt)?\s*([\.\_\d]+)/i]][Symbol.iterator]();!(m=(v=C.next()).done);m=!0){var x=c(v.value,2),g=x[0];if(x[1].test(f)){d=g;break}}}catch(e){k=!0,b=e}finally{try{!m&&C.return&&C.return()}finally{if(k)throw b}}var S=window.document.createElement("div");S.contentEditable=!0;var K=!0,E=!1,H=void 0;try{for(var _,B=[["beforeinput",function(e){return"onbeforeinput"in e}]][Symbol.iterator]();!(K=(_=B.next()).done);K=!0){var A=c(_.value,2),L=A[0],F=A[1];u[L]=F(S)}}catch(e){E=!0,H=e}finally{try{!K&&B.return&&B.return()}finally{if(E)throw H}}}var O="ios"===d||"macos"===d,P=n("mod+b"),j=n("mod+i"),D=n("enter"),M=n("shift+enter"),$=function(e){return D(e)||M(e)},z=n("backspace"),I=n("shift+backspace"),R=n("delete"),T=n("shift+delete"),U=n("ctrl+h"),N=n("ctrl+d"),W=function(e){return function(e){return z(e)||I(e)}(e)||O&&U(e)},G=function(e){return function(e){return R(e)||T(e)}(e)||O&&N(e)},V=n("ctrl+k"),q=function(e){return O&&function(e){return n("cmd+shift+backspace",e)||n("cmd+backspace",e)}(e)},J=function(e){return O&&V(e)},Q=n("ctrl+backspace"),X=n("ctrl+delete"),Y=function(e){return O?function(e){return n("shift+option+backspace",e)||n("option+backspace",e)}(e):Q(e)},Z=function(e){return O?function(e){return n("shift+option+delete",e)||n("option+delete",e)}(e):X(e)},ee=n("shift+right"),te=n("shift+left"),re=n("right"),oe=n("left"),ne=n("option+up"),ie=n("option+down"),ae=n("option+shift+up"),ce=n("option+shift+down"),ue=n("mod+z"),de=n("mod+shift+z"),fe=n("mod+y"),le=function(e){return O?de(e):fe(e)},se=n("ctrl+t"),ye={isBold:P,isCollapseCharBackward:function(e){return oe(e)&&!te(e)},isCollapseCharForward:function(e){return re(e)&&!ee(e)},isCollapseLineBackward:function(e){return O&&ne(e)},isCollapseLineForward:function(e){return O&&ie(e)},isComposing:function(e){return"ArrowDown"==e.key||"ArrowLeft"==e.key||"ArrowRight"==e.key||"ArrowUp"==e.key||"Backspace"==e.key||"Enter"==e.key},isContentEditable:function(e){return P(e)||W(e)||G(e)||q(e)||J(e)||Y(e)||Z(e)||j(e)||le(e)||$(e)||function(e){return O&&se(e)}(e)||ue(e)},isDeleteCharBackward:W,isDeleteCharForward:G,isDeleteLineBackward:q,isDeleteLineForward:J,isDeleteWordBackward:Y,isDeleteWordForward:Z,isExtendCharBackward:te,isExtendCharForward:ee,isExtendLineBackward:function(e){return O&&ae(e)},isExtendLineForward:function(e){return O&&ce(e)},isItalic:j,isRedo:le,isSplitBlock:$,isUndo:ue};e.default=ye,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.SlateHotkeys={})}(this,function(e){"use strict";var t,r,o=(function(e,t){Object.defineProperty(t,"__esModule",{value:!0});for(var r={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},o={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:"undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform)?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},a=1;a<20;a++)n["f"+a]=111+a;function i(e,t,r){!t||"byKey"in t||(r=t,t=null),Array.isArray(e)||(e=[e]);var o=e.map(function(e){return d(e,t)}),n=function(e){return o.some(function(t){return c(t,e)})};return null==r?n:n(r)}function d(e,t){var o=t&&t.byKey,n={},a=(e=e.replace("++","+add")).split("+"),i=a.length;for(var d in r)n[r[d]]=!1;var c=!0,s=!1,u=void 0;try{for(var y,p=a[Symbol.iterator]();!(c=(y=p.next()).done);c=!0){var w=y.value,m=w.endsWith("?");m&&(w=w.slice(0,-1));var h=f(w),v=r[h];1!=i&&v||(o?n.key=h:n.which=l(w)),v&&(n[v]=!m||null),1==i&&!v&&o&&(n.shiftKey=null)}}catch(e){s=!0,u=e}finally{try{!c&&p.return&&p.return()}finally{if(s)throw u}}return n}function c(e,t){for(var r in e){var o=e[r],n=void 0;if(null!=o&&((null!=(n="key"===r?t.key.toLowerCase():"which"==r?91==o&&93==t.which?91:t.which:t[r])||!1!==o)&&n!==o))return!1}return!0}function l(e){return e=f(e),n[e]||e.toUpperCase().charCodeAt(0)}function f(e){return e=e.toLowerCase(),e=o[e]||e}t.default=i,t.isHotkey=i,t.isCodeHotkey=function(e,t){return i(e,t)},t.isKeyHotkey=function(e,t){return i(e,{byKey:!0},t)},t.parseHotkey=d,t.compareHotkey=c,t.toKeyCode=l,t.toKeyName=f}(t={exports:{}},t.exports),t.exports);(r=o)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")&&r.default;o.isHotkey,o.isCodeHotkey;var n=o.isKeyHotkey,a=(o.parseHotkey,o.compareHotkey,o.toKeyCode,o.toKeyName,"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e}),i="object"===("undefined"==typeof window?"undefined":a(window))&&"object"===("undefined"==typeof document?"undefined":a(document))&&9===document.nodeType,d=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,n=!1,a=void 0;try{for(var i,d=e[Symbol.iterator]();!(o=(i=d.next()).done)&&(r.push(i.value),!t||r.length!==t);o=!0);}catch(e){n=!0,a=e}finally{try{!o&&d.return&&d.return()}finally{if(n)throw a}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),c={},l=void 0;if(i){var f=window.navigator.userAgent,s=!0,u=!1,y=void 0;try{for(var p,w=[["edge",/Edge\/([0-9\._]+)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)$/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+)\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["android",/Android\s([0-9\.]+)/],["safari",/Version\/([0-9\._]+).*Safari/]][Symbol.iterator]();!(s=(p=w.next()).done);s=!0){var m=d(p.value,2);m[0];if(m[1].test(f))break}}catch(e){u=!0,y=e}finally{try{!s&&w.return&&w.return()}finally{if(u)throw y}}var h=!0,v=!1,b=void 0;try{for(var k,x=[["ios",/os ([\.\_\d]+) like mac os/i],["macos",/mac os x/i],["android",/android/i],["firefoxos",/mozilla\/[a-z\.\_\d]+ \((?:mobile)|(?:tablet)/i],["windows",/windows\s*(?:nt)?\s*([\.\_\d]+)/i]][Symbol.iterator]();!(h=(k=x.next()).done);h=!0){var g=d(k.value,2),S=g[0];if(g[1].test(f)){l=S;break}}}catch(e){v=!0,b=e}finally{try{!h&&x.return&&x.return()}finally{if(v)throw b}}var K=window.document.createElement("div");K.contentEditable=!0;var C=!0,H=!1,O=void 0;try{for(var _,j=[["beforeinput",function(e){return"onbeforeinput"in e}]][Symbol.iterator]();!(C=(_=j.next()).done);C=!0){var B=d(_.value,2),F=B[0],L=B[1];c[F]=L(K)}}catch(e){H=!0,O=e}finally{try{!C&&j.return&&j.return()}finally{if(H)throw O}}}var P={bold:"mod+b",compose:["down","left","right","up","backspace","enter"],moveBackward:"mod?+ctrl?+alt?+left",moveForward:"mod?+ctrl?+alt?+right",deleteBackward:"shift?+backspace",deleteForward:"shift?+delete",extendBackward:"shift+left",extendForward:"shift+right",italic:"mod+i",splitBlock:"shift?+enter",undo:"mod+z"},A={moveLineBackward:"opt+up",moveLineForward:"opt+down",deleteBackward:["ctrl+backspace","ctrl+h"],deleteForward:["ctrl+delete","ctrl+d"],deleteLineBackward:"cmd+shift?+backspace",deleteLineForward:["cmd+shift?+delete","ctrl+k"],deleteWordBackward:"opt+shift?+backspace",deleteWordForward:"opt+shift?+delete",extendLineBackward:"opt+shift+up",extendLineForward:"opt+shift+down",redo:"cmd+shift+z",transposeCharacter:"ctrl+t"},E={deleteWordBackward:"ctrl+shift?+backspace",deleteWordForward:"ctrl+shift?+delete",redo:"ctrl+y"},M={},$="ios"===l||"macos"===l,W=!$;[].concat(Object.keys(P)).concat(Object.keys(A)).concat(Object.keys(E)).forEach(function(e){var t="is"+e[0].toUpperCase()+e.slice(1);if(!M[t]){var r=P[e],o=A[e],a=E[e],i=r&&n(r),d=o&&n(o),c=a&&n(a);M[t]=function(e){return!(!i||!i(e))||(!!($&&d&&d(e))||!!(W&&c&&c(e)))}}}),e.default=M,Object.defineProperty(e,"__esModule",{value:!0})});

@@ -5,151 +5,74 @@ import { isKeyHotkey } from 'is-hotkey';

/**
* Is Apple?
* Hotkey mappings for each platform.
*
* @type {Boolean}
* @type {Object}
*/
var IS_APPLE = IS_IOS || IS_MAC;
/**
* Hotkeys.
*
* @type {Function}
*/
var isBold = isKeyHotkey('mod+b');
var isItalic = isKeyHotkey('mod+i');
var isEnter = isKeyHotkey('enter');
var isShiftEnter = isKeyHotkey('shift+enter');
var isSplitBlock = function isSplitBlock(e) {
return isEnter(e) || isShiftEnter(e);
var HOTKEYS = {
bold: 'mod+b',
compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
moveBackward: 'mod?+ctrl?+alt?+left',
moveForward: 'mod?+ctrl?+alt?+right',
deleteBackward: 'shift?+backspace',
deleteForward: 'shift?+delete',
extendBackward: 'shift+left',
extendForward: 'shift+right',
italic: 'mod+i',
splitBlock: 'shift?+enter',
undo: 'mod+z'
};
var isBackspace = isKeyHotkey('backspace');
var isShiftBackspace = isKeyHotkey('shift+backspace');
var isDelete = isKeyHotkey('delete');
var isShiftDelete = isKeyHotkey('shift+delete');
var isDeleteBackward = function isDeleteBackward(e) {
return isBackspace(e) || isShiftBackspace(e);
var APPLE_HOTKEYS = {
moveLineBackward: 'opt+up',
moveLineForward: 'opt+down',
deleteBackward: ['ctrl+backspace', 'ctrl+h'],
deleteForward: ['ctrl+delete', 'ctrl+d'],
deleteLineBackward: 'cmd+shift?+backspace',
deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
deleteWordBackward: 'opt+shift?+backspace',
deleteWordForward: 'opt+shift?+delete',
extendLineBackward: 'opt+shift+up',
extendLineForward: 'opt+shift+down',
redo: 'cmd+shift+z',
transposeCharacter: 'ctrl+t'
};
var isDeleteForward = function isDeleteForward(e) {
return isDelete(e) || isShiftDelete(e);
};
var isDeleteCharBackwardMac = isKeyHotkey('ctrl+h');
var isDeleteCharForwardMac = isKeyHotkey('ctrl+d');
var isDeleteCharBackward = function isDeleteCharBackward(e) {
return isDeleteBackward(e) || IS_APPLE && isDeleteCharBackwardMac(e);
};
var isDeleteCharForward = function isDeleteCharForward(e) {
return isDeleteForward(e) || IS_APPLE && isDeleteCharForwardMac(e);
};
var WINDOWS_HOTKEYS = {
deleteWordBackward: 'ctrl+shift?+backspace',
deleteWordForward: 'ctrl+shift?+delete',
redo: 'ctrl+y'
var isDeleteLineBackwardMac = function isDeleteLineBackwardMac(e) {
return isKeyHotkey('cmd+shift+backspace', e) || isKeyHotkey('cmd+backspace', e);
};
var isDeleteLineForwardMac = isKeyHotkey('ctrl+k');
var isDeleteLineBackward = function isDeleteLineBackward(e) {
return IS_APPLE && isDeleteLineBackwardMac(e);
};
var isDeleteLineForward = function isDeleteLineForward(e) {
return IS_APPLE && isDeleteLineForwardMac(e);
};
/**
* Hotkeys.
*
* @type {Object}
*/
var isDeleteWordBackwardMac = function isDeleteWordBackwardMac(e) {
return isKeyHotkey('shift+option+backspace', e) || isKeyHotkey('option+backspace', e);
};
var isDeleteWordBackwardPC = isKeyHotkey('ctrl+backspace');
var isDeleteWordForwardMac = function isDeleteWordForwardMac(e) {
return isKeyHotkey('shift+option+delete', e) || isKeyHotkey('option+delete', e);
};
var isDeleteWordForwardPC = isKeyHotkey('ctrl+delete');
var isDeleteWordBackward = function isDeleteWordBackward(e) {
return IS_APPLE ? isDeleteWordBackwardMac(e) : isDeleteWordBackwardPC(e);
};
var isDeleteWordForward = function isDeleteWordForward(e) {
return IS_APPLE ? isDeleteWordForwardMac(e) : isDeleteWordForwardPC(e);
};
};var Hotkeys = {};
var isExtendCharForward = isKeyHotkey('shift+right');
var isExtendCharBackward = isKeyHotkey('shift+left');
var IS_APPLE = IS_IOS || IS_MAC;
var IS_WINDOWS = !IS_APPLE;
var KEYS = [].concat(Object.keys(HOTKEYS)).concat(Object.keys(APPLE_HOTKEYS)).concat(Object.keys(WINDOWS_HOTKEYS));
var isRightArrow = isKeyHotkey('right');
var isLeftArrow = isKeyHotkey('left');
var isCollapseCharForward = function isCollapseCharForward(e) {
return isRightArrow(e) && !isExtendCharForward(e);
};
var isCollapseCharBackward = function isCollapseCharBackward(e) {
return isLeftArrow(e) && !isExtendCharBackward(e);
};
KEYS.forEach(function (key) {
var method = 'is' + key[0].toUpperCase() + key.slice(1);
if (Hotkeys[method]) return;
var isCollapseLineBackwardMac = isKeyHotkey('option+up');
var isCollapseLineForwardMac = isKeyHotkey('option+down');
var isCollapseLineBackward = function isCollapseLineBackward(e) {
return IS_APPLE && isCollapseLineBackwardMac(e);
};
var isCollapseLineForward = function isCollapseLineForward(e) {
return IS_APPLE && isCollapseLineForwardMac(e);
};
var generic = HOTKEYS[key];
var apple = APPLE_HOTKEYS[key];
var windows = WINDOWS_HOTKEYS[key];
var isExtendLineBackwardMac = isKeyHotkey('option+shift+up');
var isExtendLineForwardMac = isKeyHotkey('option+shift+down');
var isExtendLineBackward = function isExtendLineBackward(e) {
return IS_APPLE && isExtendLineBackwardMac(e);
};
var isExtendLineForward = function isExtendLineForward(e) {
return IS_APPLE && isExtendLineForwardMac(e);
};
var isGeneric = generic && isKeyHotkey(generic);
var isApple = apple && isKeyHotkey(apple);
var isWindows = windows && isKeyHotkey(windows);
var isUndo = isKeyHotkey('mod+z');
var isRedoMac = isKeyHotkey('mod+shift+z');
var isRedoPC = isKeyHotkey('mod+y');
var isRedo = function isRedo(e) {
return IS_APPLE ? isRedoMac(e) : isRedoPC(e);
};
Hotkeys[method] = function (event) {
if (isGeneric && isGeneric(event)) return true;
if (IS_APPLE && isApple && isApple(event)) return true;
if (IS_WINDOWS && isWindows && isWindows(event)) return true;
return false;
};
});
var isTransposeCharacterMac = isKeyHotkey('ctrl+t');
var isTransposeCharacter = function isTransposeCharacter(e) {
return IS_APPLE && isTransposeCharacterMac(e);
};
var isContentEditable = function isContentEditable(e) {
return isBold(e) || isDeleteCharBackward(e) || isDeleteCharForward(e) || isDeleteLineBackward(e) || isDeleteLineForward(e) || isDeleteWordBackward(e) || isDeleteWordForward(e) || isItalic(e) || isRedo(e) || isSplitBlock(e) || isTransposeCharacter(e) || isUndo(e);
};
var isComposing = function isComposing(e) {
return e.key == 'ArrowDown' || e.key == 'ArrowLeft' || e.key == 'ArrowRight' || e.key == 'ArrowUp' || e.key == 'Backspace' || e.key == 'Enter';
};
/**
* Export.
*
* @type {Object}
*/
var index = {
isBold: isBold,
isCollapseCharBackward: isCollapseCharBackward,
isCollapseCharForward: isCollapseCharForward,
isCollapseLineBackward: isCollapseLineBackward,
isCollapseLineForward: isCollapseLineForward,
isComposing: isComposing,
isContentEditable: isContentEditable,
isDeleteCharBackward: isDeleteCharBackward,
isDeleteCharForward: isDeleteCharForward,
isDeleteLineBackward: isDeleteLineBackward,
isDeleteLineForward: isDeleteLineForward,
isDeleteWordBackward: isDeleteWordBackward,
isDeleteWordForward: isDeleteWordForward,
isExtendCharBackward: isExtendCharBackward,
isExtendCharForward: isExtendCharForward,
isExtendLineBackward: isExtendLineBackward,
isExtendLineForward: isExtendLineForward,
isItalic: isItalic,
isRedo: isRedo,
isSplitBlock: isSplitBlock,
isUndo: isUndo
};
export default index;
export default Hotkeys;
//# sourceMappingURL=slate-hotkeys.es.js.map

@@ -9,151 +9,74 @@ 'use strict';

/**
* Is Apple?
* Hotkey mappings for each platform.
*
* @type {Boolean}
* @type {Object}
*/
var IS_APPLE = slateDevEnvironment.IS_IOS || slateDevEnvironment.IS_MAC;
/**
* Hotkeys.
*
* @type {Function}
*/
var isBold = isHotkey.isKeyHotkey('mod+b');
var isItalic = isHotkey.isKeyHotkey('mod+i');
var isEnter = isHotkey.isKeyHotkey('enter');
var isShiftEnter = isHotkey.isKeyHotkey('shift+enter');
var isSplitBlock = function isSplitBlock(e) {
return isEnter(e) || isShiftEnter(e);
var HOTKEYS = {
bold: 'mod+b',
compose: ['down', 'left', 'right', 'up', 'backspace', 'enter'],
moveBackward: 'mod?+ctrl?+alt?+left',
moveForward: 'mod?+ctrl?+alt?+right',
deleteBackward: 'shift?+backspace',
deleteForward: 'shift?+delete',
extendBackward: 'shift+left',
extendForward: 'shift+right',
italic: 'mod+i',
splitBlock: 'shift?+enter',
undo: 'mod+z'
};
var isBackspace = isHotkey.isKeyHotkey('backspace');
var isShiftBackspace = isHotkey.isKeyHotkey('shift+backspace');
var isDelete = isHotkey.isKeyHotkey('delete');
var isShiftDelete = isHotkey.isKeyHotkey('shift+delete');
var isDeleteBackward = function isDeleteBackward(e) {
return isBackspace(e) || isShiftBackspace(e);
var APPLE_HOTKEYS = {
moveLineBackward: 'opt+up',
moveLineForward: 'opt+down',
deleteBackward: ['ctrl+backspace', 'ctrl+h'],
deleteForward: ['ctrl+delete', 'ctrl+d'],
deleteLineBackward: 'cmd+shift?+backspace',
deleteLineForward: ['cmd+shift?+delete', 'ctrl+k'],
deleteWordBackward: 'opt+shift?+backspace',
deleteWordForward: 'opt+shift?+delete',
extendLineBackward: 'opt+shift+up',
extendLineForward: 'opt+shift+down',
redo: 'cmd+shift+z',
transposeCharacter: 'ctrl+t'
};
var isDeleteForward = function isDeleteForward(e) {
return isDelete(e) || isShiftDelete(e);
};
var isDeleteCharBackwardMac = isHotkey.isKeyHotkey('ctrl+h');
var isDeleteCharForwardMac = isHotkey.isKeyHotkey('ctrl+d');
var isDeleteCharBackward = function isDeleteCharBackward(e) {
return isDeleteBackward(e) || IS_APPLE && isDeleteCharBackwardMac(e);
};
var isDeleteCharForward = function isDeleteCharForward(e) {
return isDeleteForward(e) || IS_APPLE && isDeleteCharForwardMac(e);
};
var WINDOWS_HOTKEYS = {
deleteWordBackward: 'ctrl+shift?+backspace',
deleteWordForward: 'ctrl+shift?+delete',
redo: 'ctrl+y'
var isDeleteLineBackwardMac = function isDeleteLineBackwardMac(e) {
return isHotkey.isKeyHotkey('cmd+shift+backspace', e) || isHotkey.isKeyHotkey('cmd+backspace', e);
};
var isDeleteLineForwardMac = isHotkey.isKeyHotkey('ctrl+k');
var isDeleteLineBackward = function isDeleteLineBackward(e) {
return IS_APPLE && isDeleteLineBackwardMac(e);
};
var isDeleteLineForward = function isDeleteLineForward(e) {
return IS_APPLE && isDeleteLineForwardMac(e);
};
/**
* Hotkeys.
*
* @type {Object}
*/
var isDeleteWordBackwardMac = function isDeleteWordBackwardMac(e) {
return isHotkey.isKeyHotkey('shift+option+backspace', e) || isHotkey.isKeyHotkey('option+backspace', e);
};
var isDeleteWordBackwardPC = isHotkey.isKeyHotkey('ctrl+backspace');
var isDeleteWordForwardMac = function isDeleteWordForwardMac(e) {
return isHotkey.isKeyHotkey('shift+option+delete', e) || isHotkey.isKeyHotkey('option+delete', e);
};
var isDeleteWordForwardPC = isHotkey.isKeyHotkey('ctrl+delete');
var isDeleteWordBackward = function isDeleteWordBackward(e) {
return IS_APPLE ? isDeleteWordBackwardMac(e) : isDeleteWordBackwardPC(e);
};
var isDeleteWordForward = function isDeleteWordForward(e) {
return IS_APPLE ? isDeleteWordForwardMac(e) : isDeleteWordForwardPC(e);
};
};var Hotkeys = {};
var isExtendCharForward = isHotkey.isKeyHotkey('shift+right');
var isExtendCharBackward = isHotkey.isKeyHotkey('shift+left');
var IS_APPLE = slateDevEnvironment.IS_IOS || slateDevEnvironment.IS_MAC;
var IS_WINDOWS = !IS_APPLE;
var KEYS = [].concat(Object.keys(HOTKEYS)).concat(Object.keys(APPLE_HOTKEYS)).concat(Object.keys(WINDOWS_HOTKEYS));
var isRightArrow = isHotkey.isKeyHotkey('right');
var isLeftArrow = isHotkey.isKeyHotkey('left');
var isCollapseCharForward = function isCollapseCharForward(e) {
return isRightArrow(e) && !isExtendCharForward(e);
};
var isCollapseCharBackward = function isCollapseCharBackward(e) {
return isLeftArrow(e) && !isExtendCharBackward(e);
};
KEYS.forEach(function (key) {
var method = 'is' + key[0].toUpperCase() + key.slice(1);
if (Hotkeys[method]) return;
var isCollapseLineBackwardMac = isHotkey.isKeyHotkey('option+up');
var isCollapseLineForwardMac = isHotkey.isKeyHotkey('option+down');
var isCollapseLineBackward = function isCollapseLineBackward(e) {
return IS_APPLE && isCollapseLineBackwardMac(e);
};
var isCollapseLineForward = function isCollapseLineForward(e) {
return IS_APPLE && isCollapseLineForwardMac(e);
};
var generic = HOTKEYS[key];
var apple = APPLE_HOTKEYS[key];
var windows = WINDOWS_HOTKEYS[key];
var isExtendLineBackwardMac = isHotkey.isKeyHotkey('option+shift+up');
var isExtendLineForwardMac = isHotkey.isKeyHotkey('option+shift+down');
var isExtendLineBackward = function isExtendLineBackward(e) {
return IS_APPLE && isExtendLineBackwardMac(e);
};
var isExtendLineForward = function isExtendLineForward(e) {
return IS_APPLE && isExtendLineForwardMac(e);
};
var isGeneric = generic && isHotkey.isKeyHotkey(generic);
var isApple = apple && isHotkey.isKeyHotkey(apple);
var isWindows = windows && isHotkey.isKeyHotkey(windows);
var isUndo = isHotkey.isKeyHotkey('mod+z');
var isRedoMac = isHotkey.isKeyHotkey('mod+shift+z');
var isRedoPC = isHotkey.isKeyHotkey('mod+y');
var isRedo = function isRedo(e) {
return IS_APPLE ? isRedoMac(e) : isRedoPC(e);
};
Hotkeys[method] = function (event) {
if (isGeneric && isGeneric(event)) return true;
if (IS_APPLE && isApple && isApple(event)) return true;
if (IS_WINDOWS && isWindows && isWindows(event)) return true;
return false;
};
});
var isTransposeCharacterMac = isHotkey.isKeyHotkey('ctrl+t');
var isTransposeCharacter = function isTransposeCharacter(e) {
return IS_APPLE && isTransposeCharacterMac(e);
};
var isContentEditable = function isContentEditable(e) {
return isBold(e) || isDeleteCharBackward(e) || isDeleteCharForward(e) || isDeleteLineBackward(e) || isDeleteLineForward(e) || isDeleteWordBackward(e) || isDeleteWordForward(e) || isItalic(e) || isRedo(e) || isSplitBlock(e) || isTransposeCharacter(e) || isUndo(e);
};
var isComposing = function isComposing(e) {
return e.key == 'ArrowDown' || e.key == 'ArrowLeft' || e.key == 'ArrowRight' || e.key == 'ArrowUp' || e.key == 'Backspace' || e.key == 'Enter';
};
/**
* Export.
*
* @type {Object}
*/
var index = {
isBold: isBold,
isCollapseCharBackward: isCollapseCharBackward,
isCollapseCharForward: isCollapseCharForward,
isCollapseLineBackward: isCollapseLineBackward,
isCollapseLineForward: isCollapseLineForward,
isComposing: isComposing,
isContentEditable: isContentEditable,
isDeleteCharBackward: isDeleteCharBackward,
isDeleteCharForward: isDeleteCharForward,
isDeleteLineBackward: isDeleteLineBackward,
isDeleteLineForward: isDeleteLineForward,
isDeleteWordBackward: isDeleteWordBackward,
isDeleteWordForward: isDeleteWordForward,
isExtendCharBackward: isExtendCharBackward,
isExtendCharForward: isExtendCharForward,
isExtendLineBackward: isExtendLineBackward,
isExtendLineForward: isExtendLineForward,
isItalic: isItalic,
isRedo: isRedo,
isSplitBlock: isSplitBlock,
isUndo: isUndo
};
exports.default = index;
exports.default = Hotkeys;
//# sourceMappingURL=slate-hotkeys.js.map
{
"name": "slate-hotkeys",
"description": "A set of function to detect common keypresses in a platform-agnostic way",
"version": "0.1.4",
"version": "0.2.0",
"license": "MIT",

@@ -16,3 +16,3 @@ "repository": "git://github.com/ianstormtaylor/slate.git",

"dependencies": {
"is-hotkey": "^0.1.1",
"is-hotkey": "^0.1.3",
"slate-dev-environment": "^0.1.4"

@@ -19,0 +19,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc