@fastkit/keybord
Advanced tools
Comparing version 0.6.10 to 0.6.11
@@ -5,2 +5,4 @@ 'use strict'; | ||
var helpers = require('@fastkit/helpers'); | ||
function Special(key) { | ||
@@ -54,3 +56,36 @@ return key; | ||
function createSetting(rawKBSettings) { | ||
const _settings = Array.isArray(rawKBSettings) | ||
? rawKBSettings | ||
: [rawKBSettings]; | ||
const computedSettings = []; | ||
if (!helpers.IN_WINDOW) | ||
return computedSettings; | ||
_settings.forEach((_setting) => { | ||
const { target = document, event = 'keydown', capture = false } = _setting; | ||
const setting = { | ||
..._setting, | ||
target, | ||
event, | ||
capture, | ||
}; | ||
let bucket = computedSettings.find((b) => b.target === target && b.event === event && b.capture === capture); | ||
if (!bucket) { | ||
bucket = { | ||
target, | ||
event, | ||
capture, | ||
settings: [], | ||
handler: (ev) => { | ||
bucket && | ||
bucket.settings.forEach(({ key, handler }) => { | ||
if (!key || Key.is(ev.key, key)) { | ||
handler(ev); | ||
} | ||
}); | ||
}, | ||
}; | ||
computedSettings.push(bucket); | ||
} | ||
bucket.settings.push(setting); | ||
}); | ||
return computedSettings; | ||
@@ -65,3 +100,3 @@ } | ||
constructor(settings) { | ||
this.settings = createSetting(); | ||
this.settings = createSetting(settings); | ||
} | ||
@@ -68,0 +103,0 @@ run() { |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var helpers = require('@fastkit/helpers'); | ||
function Special(key) { | ||
@@ -54,3 +56,36 @@ return key; | ||
function createSetting(rawKBSettings) { | ||
const _settings = Array.isArray(rawKBSettings) | ||
? rawKBSettings | ||
: [rawKBSettings]; | ||
const computedSettings = []; | ||
if (!helpers.IN_WINDOW) | ||
return computedSettings; | ||
_settings.forEach((_setting) => { | ||
const { target = document, event = 'keydown', capture = false } = _setting; | ||
const setting = { | ||
..._setting, | ||
target, | ||
event, | ||
capture, | ||
}; | ||
let bucket = computedSettings.find((b) => b.target === target && b.event === event && b.capture === capture); | ||
if (!bucket) { | ||
bucket = { | ||
target, | ||
event, | ||
capture, | ||
settings: [], | ||
handler: (ev) => { | ||
bucket && | ||
bucket.settings.forEach(({ key, handler }) => { | ||
if (!key || Key.is(ev.key, key)) { | ||
handler(ev); | ||
} | ||
}); | ||
}, | ||
}; | ||
computedSettings.push(bucket); | ||
} | ||
bucket.settings.push(setting); | ||
}); | ||
return computedSettings; | ||
@@ -65,3 +100,3 @@ } | ||
constructor(settings) { | ||
this.settings = createSetting(); | ||
this.settings = createSetting(settings); | ||
} | ||
@@ -68,0 +103,0 @@ run() { |
@@ -0,1 +1,3 @@ | ||
import { IN_WINDOW } from '@fastkit/helpers'; | ||
function Special(key) { | ||
@@ -53,3 +55,3 @@ return key; | ||
const computedSettings = []; | ||
if (!(typeof document !== 'undefined')) | ||
if (!IN_WINDOW) | ||
return computedSettings; | ||
@@ -56,0 +58,0 @@ _settings.forEach((_setting) => { |
{ | ||
"name": "@fastkit/keybord", | ||
"version": "0.6.10", | ||
"version": "0.6.11", | ||
"description": "@fastkit/keybord", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
15018
447