@gen-epix/ui-core 3.5.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
+ declare const MODIFIER_KEYS: readonly ["Accel", "Alt", "AltGraph", "CapsLock", "Control", "Fn", "FnLock", "Hyper", "Meta", "NumLock", "OS", "ScrollLock", "Shift", "Super", "Symbol", "SymbolLock"];
2
+ type KeyboardModifier = typeof MODIFIER_KEYS[number];
1
3
  type KeyboardShortcutConfig = {
2
4
  callback: (event: KeyboardEvent) => void;
3
5
  code?: string;
4
6
  key?: string;
5
- modifier?: string;
7
+ modifier?: KeyboardModifier[];
6
8
  };
7
9
  export declare class KeyboardShortcutService {
8
10
  private static __instance;
@@ -13,14 +13,31 @@ var t = [
13
13
  "output",
14
14
  "option",
15
15
  "optgroup"
16
- ], n = class n {
16
+ ], n = [
17
+ "Accel",
18
+ "Alt",
19
+ "AltGraph",
20
+ "CapsLock",
21
+ "Control",
22
+ "Fn",
23
+ "FnLock",
24
+ "Hyper",
25
+ "Meta",
26
+ "NumLock",
27
+ "OS",
28
+ "ScrollLock",
29
+ "Shift",
30
+ "Super",
31
+ "Symbol",
32
+ "SymbolLock"
33
+ ], r = class r {
17
34
  static __instance;
18
35
  configs = [];
19
36
  constructor() {
20
37
  window.addEventListener("keydown", this.handleKeyDown.bind(this));
21
38
  }
22
39
  static getInstance() {
23
- return n.__instance = e.getHmrSingleton("keyboardShortcutService", n.__instance, () => new n()), n.__instance;
40
+ return r.__instance = e.getHmrSingleton("keyboardShortcutService", r.__instance, () => new r()), r.__instance;
24
41
  }
25
42
  static shouldIgnoreShortcut() {
26
43
  let e = document.activeElement;
@@ -43,16 +60,16 @@ var t = [
43
60
  }
44
61
  handleKeyDown(e) {
45
62
  for (let t of this.configs) {
46
- let { callback: r, code: i, key: a, modifier: o } = t;
47
- if (!(a && e.key !== a || i && e.code !== i)) {
48
- if (o && !e.getModifierState(o) || !o && (e.getModifierState("Control") || e.getModifierState("Alt") || e.getModifierState("Meta")) || n.shouldIgnoreShortcut()) return;
49
- r(e);
63
+ let { callback: i, code: a, key: o, modifier: s } = t;
64
+ if (!(o && e.key !== o || a && e.code !== a) && (!s?.length || s.some((t) => e.getModifierState(t))) && (s?.length || !n.some((t) => e.getModifierState(t)))) {
65
+ if (r.shouldIgnoreShortcut()) return;
66
+ i(e);
50
67
  return;
51
68
  }
52
69
  }
53
70
  }
54
71
  };
55
72
  //#endregion
56
- export { n as KeyboardShortcutService };
73
+ export { r as KeyboardShortcutService };
57
74
 
58
75
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/classes/services/KeyboardShortcutService/KeyboardShortcutService.ts"],"sourcesContent":["import { HmrUtil } from '../../../utils/HmrUtil';\n\nconst FORM_ELEMENT_TAG_NAMES = [\n 'form',\n 'input',\n 'label',\n 'select',\n 'textarea',\n 'button',\n 'fieldset',\n 'legend',\n 'datalist',\n 'output',\n 'option',\n 'optgroup',\n];\n\ntype KeyboardShortcutConfig = {\n callback: (event: KeyboardEvent) => void;\n code?: string;\n key?: string;\n modifier?: string;\n};\n\nexport class KeyboardShortcutService {\n private static __instance: KeyboardShortcutService;\n\n private readonly configs: KeyboardShortcutConfig[] = [];\n\n private constructor() {\n window.addEventListener('keydown', this.handleKeyDown.bind(this));\n }\n\n public static getInstance(): KeyboardShortcutService {\n KeyboardShortcutService.__instance = HmrUtil.getHmrSingleton('keyboardShortcutService', KeyboardShortcutService.__instance, () => new KeyboardShortcutService());\n return KeyboardShortcutService.__instance;\n }\n\n private static shouldIgnoreShortcut(): boolean {\n let activeElement = document.activeElement as HTMLElement;\n while (activeElement) {\n if (FORM_ELEMENT_TAG_NAMES.includes(activeElement.tagName.toLowerCase())) {\n return true; // ignore all shortcuts when typing in form elements\n }\n activeElement = activeElement.parentElement;\n }\n return false;\n }\n\n public registerShortcut({ callback, code, key, modifier }: KeyboardShortcutConfig): () => void {\n const config: KeyboardShortcutConfig = { callback, code, key, modifier };\n this.configs.push(config);\n\n return () => {\n this.configs.splice(this.configs.indexOf(config), 1);\n };\n }\n\n private handleKeyDown(event: KeyboardEvent): void {\n for (const config of this.configs) {\n const { callback, code, key, modifier } = config;\n if ((key && event.key !== key) || (code && event.code !== code)) {\n continue;\n }\n if (modifier && !event.getModifierState(modifier)) {\n return;\n }\n if (!modifier && (event.getModifierState('Control') || event.getModifierState('Alt') || event.getModifierState('Meta'))) {\n return;\n }\n\n if (KeyboardShortcutService.shouldIgnoreShortcut()) {\n return;\n }\n callback(event);\n return; // only one callback per shortcut\n }\n }\n}\n"],"mappings":";;AAEA,IAAM,IAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GASa,IAAb,MAAa,EAAwB;CACnC,OAAe;CAEf,UAAqD,CAAC;CAEtD,cAAsB;EACpB,OAAO,iBAAiB,WAAW,KAAK,cAAc,KAAK,IAAI,CAAC;CAClE;CAEA,OAAc,cAAuC;EAEnD,OADA,EAAwB,aAAa,EAAQ,gBAAgB,2BAA2B,EAAwB,kBAAkB,IAAI,EAAwB,CAAC,GACxJ,EAAwB;CACjC;CAEA,OAAe,uBAAgC;EAC7C,IAAI,IAAgB,SAAS;EAC7B,OAAO,IAAe;GACpB,IAAI,EAAuB,SAAS,EAAc,QAAQ,YAAY,CAAC,GACrE,OAAO;GAET,IAAgB,EAAc;EAChC;EACA,OAAO;CACT;CAEA,iBAAwB,EAAE,aAAU,SAAM,QAAK,eAAgD;EAC7F,IAAM,IAAiC;GAAE;GAAU;GAAM;GAAK;EAAS;EAGvE,OAFA,KAAK,QAAQ,KAAK,CAAM,SAEX;GACX,KAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ,CAAM,GAAG,CAAC;EACrD;CACF;CAEA,cAAsB,GAA4B;EAChD,KAAK,IAAM,KAAU,KAAK,SAAS;GACjC,IAAM,EAAE,aAAU,SAAM,QAAK,gBAAa;GACrC,WAAO,EAAM,QAAQ,KAAS,KAAQ,EAAM,SAAS,IAU1D;QAPI,KAAY,CAAC,EAAM,iBAAiB,CAAQ,KAG5C,CAAC,MAAa,EAAM,iBAAiB,SAAS,KAAK,EAAM,iBAAiB,KAAK,KAAK,EAAM,iBAAiB,MAAM,MAIjH,EAAwB,qBAAqB,GAC/C;IAEF,EAAS,CAAK;IACd;GAHE;EAIJ;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/classes/services/KeyboardShortcutService/KeyboardShortcutService.ts"],"sourcesContent":["import { HmrUtil } from '../../../utils/HmrUtil';\n\nconst FORM_ELEMENT_TAG_NAMES = [\n 'form',\n 'input',\n 'label',\n 'select',\n 'textarea',\n 'button',\n 'fieldset',\n 'legend',\n 'datalist',\n 'output',\n 'option',\n 'optgroup',\n];\n\nconst MODIFIER_KEYS = [\n 'Accel',\n 'Alt',\n 'AltGraph',\n 'CapsLock',\n 'Control',\n 'Fn',\n 'FnLock',\n 'Hyper',\n 'Meta',\n 'NumLock',\n 'OS',\n 'ScrollLock',\n 'Shift',\n 'Super',\n 'Symbol',\n 'SymbolLock',\n] as const;\n\ntype KeyboardModifier = typeof MODIFIER_KEYS[number];\n\ntype KeyboardShortcutConfig = {\n callback: (event: KeyboardEvent) => void;\n code?: string;\n key?: string;\n modifier?: KeyboardModifier[];\n};\n\nexport class KeyboardShortcutService {\n private static __instance: KeyboardShortcutService;\n\n private readonly configs: KeyboardShortcutConfig[] = [];\n\n private constructor() {\n window.addEventListener('keydown', this.handleKeyDown.bind(this));\n }\n\n public static getInstance(): KeyboardShortcutService {\n KeyboardShortcutService.__instance = HmrUtil.getHmrSingleton('keyboardShortcutService', KeyboardShortcutService.__instance, () => new KeyboardShortcutService());\n return KeyboardShortcutService.__instance;\n }\n\n private static shouldIgnoreShortcut(): boolean {\n let activeElement = document.activeElement as HTMLElement;\n while (activeElement) {\n if (FORM_ELEMENT_TAG_NAMES.includes(activeElement.tagName.toLowerCase())) {\n return true; // ignore all shortcuts when typing in form elements\n }\n activeElement = activeElement.parentElement;\n }\n return false;\n }\n\n public registerShortcut({ callback, code, key, modifier }: KeyboardShortcutConfig): () => void {\n const config: KeyboardShortcutConfig = { callback, code, key, modifier };\n this.configs.push(config);\n\n return () => {\n this.configs.splice(this.configs.indexOf(config), 1);\n };\n }\n\n private handleKeyDown(event: KeyboardEvent): void {\n for (const config of this.configs) {\n const { callback, code, key, modifier } = config;\n if ((key && event.key !== key) || (code && event.code !== code)) {\n continue;\n }\n if (modifier?.length && !modifier.some((modifierKey) => event.getModifierState(modifierKey))) {\n continue;\n }\n if (!modifier?.length && MODIFIER_KEYS.some((modifierKey) => event.getModifierState(modifierKey))) {\n continue;\n }\n\n if (KeyboardShortcutService.shouldIgnoreShortcut()) {\n return;\n }\n callback(event);\n return; // only one callback per shortcut\n }\n }\n}\n"],"mappings":";;AAEA,IAAM,IAAyB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAWa,IAAb,MAAa,EAAwB;CACnC,OAAe;CAEf,UAAqD,CAAC;CAEtD,cAAsB;EACpB,OAAO,iBAAiB,WAAW,KAAK,cAAc,KAAK,IAAI,CAAC;CAClE;CAEA,OAAc,cAAuC;EAEnD,OADA,EAAwB,aAAa,EAAQ,gBAAgB,2BAA2B,EAAwB,kBAAkB,IAAI,EAAwB,CAAC,GACxJ,EAAwB;CACjC;CAEA,OAAe,uBAAgC;EAC7C,IAAI,IAAgB,SAAS;EAC7B,OAAO,IAAe;GACpB,IAAI,EAAuB,SAAS,EAAc,QAAQ,YAAY,CAAC,GACrE,OAAO;GAET,IAAgB,EAAc;EAChC;EACA,OAAO;CACT;CAEA,iBAAwB,EAAE,aAAU,SAAM,QAAK,eAAgD;EAC7F,IAAM,IAAiC;GAAE;GAAU;GAAM;GAAK;EAAS;EAGvE,OAFA,KAAK,QAAQ,KAAK,CAAM,SAEX;GACX,KAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ,CAAM,GAAG,CAAC;EACrD;CACF;CAEA,cAAsB,GAA4B;EAChD,KAAK,IAAM,KAAU,KAAK,SAAS;GACjC,IAAM,EAAE,aAAU,SAAM,QAAK,gBAAa;GACrC,WAAO,EAAM,QAAQ,KAAS,KAAQ,EAAM,SAAS,OAGtD,IAAU,UAAW,EAAS,MAAM,MAAgB,EAAM,iBAAiB,CAAW,CAAC,OAGtF,GAAU,UAAU,GAAc,MAAM,MAAgB,EAAM,iBAAiB,CAAW,CAAC,IAIhG;QAAI,EAAwB,qBAAqB,GAC/C;IAEF,EAAS,CAAK;IACd;GAHE;EAIJ;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gen-epix/ui-core",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "homepage": "https://github.com/RIVM-bioinformatics/gen-epix",
5
5
  "repository": {
6
6
  "type": "git",