@ngrdt/shortcuts 0.1.1 → 0.1.3
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 +1 @@
|
|
|
1
|
-
import{RdtStringUtils as t}from"@ngrdt/utils";import*as e from"@angular/core";import{Injectable as n,EventEmitter as r,HostListener as s,Output as o,Directive as a}from"@angular/core";import c from"hotkeys-js";import{Subject as i,Observable as l,filter as m}from"rxjs";const d=":",h=["WakeUp"];var p;!function(t){t.INPUT="input",t.OTHER="other"}(p||(p={}));const u={preventDefault:!0,element:void 0},f=[["command","n"],["command","shift","n"],["command","t"],["command","shift","t"],["command","option","right"],["ctrl","tab"],["command","option","left"],["ctrl","shift","tab"],...[...Array(9).keys()].map(t=>["command",String(t+1)]),["command","shift","["],["command","shift","]"],["command","m"],["command","h"],["command","q"],["command","w"],["command","shift","w"],["command","["],["command","]"],["command","shift","b"],["command","option","b"],["command",","],["command","y"],["command","shift","j"],["command","option","l"],["command","shift","del"],["command","f"],["command","g"],["command","shift","g"],["command","e"],["command","option","f"],["command","l"],["command","option","i"],["command","option","j"],["f12"],["command","u"],["command","shift","m"],["command","p"],["command","s"],["command","r"],["command","shift","r"],["esc"],["command","="],["command","-"],["command","0"],["command","ctrl","f"],["space"],["shift","space"],["command","up"],["command","down"],["command","left"],["command","right"],["tab"],["shift","tab"],["command","o"],["command","d"],["command","shift","d"],["command","k"]],y=[["ctrl","n"],["ctrl","shift","n"],["ctrl","t"],["ctrl","shift","t"],["ctrl","tab"],["ctrl","pagedown"],["ctrl","shift","tab"],["ctrl","pageup"],...[...Array(9).keys()].map(t=>["ctrl",String(t+1)]),["alt","home"],["alt","left"],["alt","right"],["ctrl","w"],["ctrl","f4"],["ctrl","shift","w"],["alt","f4"],["alt","space","n"],["alt","space","x"],["alt","f","x"],["ctrl","shift","pageup"],["ctrl","shift","pagedown"],["alt","f"],["alt","e"],["ctrl","shift","b"],["ctrl","shift","o"],["ctrl","h"],["ctrl","j"],["shift","esc"],["shift","alt","t"],["f10"],["f6"],["ctrl","f"],["f3"],["ctrl","g"],["ctrl","shift","g"],["ctrl","shift","j"],["f12"],["ctrl","shift","del"],["f1"],["ctrl","shift","m"],["alt","shift","i"],["f7"],["ctrl","f6"],["alt","shift","a"],["ctrl","l"],["alt","d"],["f6"],["ctrl","k"],["ctrl","e"],["ctrl","p"],["ctrl","s"],["f5"],["ctrl","r"],["shift","f5"],["ctrl","shift","r"],["esc"],["tab"],["shift","tab"],["ctrl","o"],["ctrl","u"],["ctrl","d"],["ctrl","shift","d"],["f11"],["ctrl","+"],["ctrl","-"],["ctrl","0"],["space"],["pagedown"],["shift","space"],["pageup"],["home"],["end"],["ctrl","left"],["ctrl","right"],["ctrl","backspace"],["alt","home"]];function b(t){return[...t].sort(),t.join(d)}const g=function(t){const e=new Set;return t.forEach(t=>e.add(b(t))),e}("undefined"!=typeof navigator&&/Mac/i.test(navigator.platform)?f:y);class k{hotkeysValue;keys;label;get lastKey(){return this.keys[this.keys.length-1]}constructor(t){this.keys=t,this.hotkeysValue=k.joinKeys(t),this.label=k.makeLabel(t)}static joinKeys(t){return t.join(d)}static makeLabel(e){return e.map(t.capitalize).join("+")}static create(...t){if(function(t){const e=b(t);return g.has(e)}(t))throw new Error(`Shortcut ${k.joinKeys(t)} is a browser shortcut!`);return new k(t)}static createUnsafe(...t){return new k(t)}}class w{bound=new Map;subject$=new i;observable$=this.subject$.asObservable();constructor(){c.filter=function(t){if(h.includes(t.code))return!1;const e=t.target.tagName,n=/^(INPUT|TEXTAREA|SELECT)$/.test(e)?p.INPUT:p.OTHER;return c.setScope(n),!0}}listen(t,e){const n={...u,...e};return Array.isArray(t)?this.listenArray(t,n):this.listenSingle(t,n)}listenArray(t,e){return new l(n=>{const r=new Set(t);try{t.forEach(t=>this.bind(t,e))}catch(t){n.error(t)}const s=this.observable$.pipe(m(t=>r.has(t.shortcut))).subscribe(n);return()=>{s.unsubscribe(),t.forEach(t=>this.unbind(t,e))}})}listenSingle(t,e){return new l(n=>{try{this.bind(t,e)}catch(t){n.error(t)}const r=this.observable$.pipe(m(e=>e.shortcut===t)).subscribe(n);return()=>{r.unsubscribe(),this.unbind(t,e)}})}bind(t,e){const n={element:e.element,splitKey:d};if(this.bound.get(e.element)?.[t.hotkeysValue])throw new Error(`Shortcut ${t} is already binded!`);if(this.bound.has(e.element))this.bound.get(e.element)[t.hotkeysValue]=t;else{const n={[t.hotkeysValue]:t};this.bound.set(e.element,n)}c(t.hotkeysValue,n,this.keyHandlerFactory(e))}unbind(t,e){const n=this.bound.get(e.element);n?.[t.hotkeysValue]&&(n[t.hotkeysValue]=void 0,Object.keys(n).every(t=>void 0===n[t])&&this.bound.delete(e.element),c.unbind(t.hotkeysValue))}keyHandlerFactory(t){return(e,n)=>{t.preventDefault&&e.preventDefault();const r={shortcut:this.bound.get(t.element)[n.shortcut],src:n.scope,originalEvent:e};return this.subject$.next(r),!t.preventDefault}}static"ɵfac"=e.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.
|
|
1
|
+
import{RdtStringUtils as t}from"@ngrdt/utils";import*as e from"@angular/core";import{Injectable as n,EventEmitter as r,HostListener as s,Output as o,Directive as a}from"@angular/core";import c from"hotkeys-js";import{Subject as i,Observable as l,filter as m}from"rxjs";const d=":",h=["WakeUp"];var p;!function(t){t.INPUT="input",t.OTHER="other"}(p||(p={}));const u={preventDefault:!0,element:void 0},f=[["command","n"],["command","shift","n"],["command","t"],["command","shift","t"],["command","option","right"],["ctrl","tab"],["command","option","left"],["ctrl","shift","tab"],...[...Array(9).keys()].map(t=>["command",String(t+1)]),["command","shift","["],["command","shift","]"],["command","m"],["command","h"],["command","q"],["command","w"],["command","shift","w"],["command","["],["command","]"],["command","shift","b"],["command","option","b"],["command",","],["command","y"],["command","shift","j"],["command","option","l"],["command","shift","del"],["command","f"],["command","g"],["command","shift","g"],["command","e"],["command","option","f"],["command","l"],["command","option","i"],["command","option","j"],["f12"],["command","u"],["command","shift","m"],["command","p"],["command","s"],["command","r"],["command","shift","r"],["esc"],["command","="],["command","-"],["command","0"],["command","ctrl","f"],["space"],["shift","space"],["command","up"],["command","down"],["command","left"],["command","right"],["tab"],["shift","tab"],["command","o"],["command","d"],["command","shift","d"],["command","k"]],y=[["ctrl","n"],["ctrl","shift","n"],["ctrl","t"],["ctrl","shift","t"],["ctrl","tab"],["ctrl","pagedown"],["ctrl","shift","tab"],["ctrl","pageup"],...[...Array(9).keys()].map(t=>["ctrl",String(t+1)]),["alt","home"],["alt","left"],["alt","right"],["ctrl","w"],["ctrl","f4"],["ctrl","shift","w"],["alt","f4"],["alt","space","n"],["alt","space","x"],["alt","f","x"],["ctrl","shift","pageup"],["ctrl","shift","pagedown"],["alt","f"],["alt","e"],["ctrl","shift","b"],["ctrl","shift","o"],["ctrl","h"],["ctrl","j"],["shift","esc"],["shift","alt","t"],["f10"],["f6"],["ctrl","f"],["f3"],["ctrl","g"],["ctrl","shift","g"],["ctrl","shift","j"],["f12"],["ctrl","shift","del"],["f1"],["ctrl","shift","m"],["alt","shift","i"],["f7"],["ctrl","f6"],["alt","shift","a"],["ctrl","l"],["alt","d"],["f6"],["ctrl","k"],["ctrl","e"],["ctrl","p"],["ctrl","s"],["f5"],["ctrl","r"],["shift","f5"],["ctrl","shift","r"],["esc"],["tab"],["shift","tab"],["ctrl","o"],["ctrl","u"],["ctrl","d"],["ctrl","shift","d"],["f11"],["ctrl","+"],["ctrl","-"],["ctrl","0"],["space"],["pagedown"],["shift","space"],["pageup"],["home"],["end"],["ctrl","left"],["ctrl","right"],["ctrl","backspace"],["alt","home"]];function b(t){return[...t].sort(),t.join(d)}const g=function(t){const e=new Set;return t.forEach(t=>e.add(b(t))),e}("undefined"!=typeof navigator&&/Mac/i.test(navigator.platform)?f:y);class k{hotkeysValue;keys;label;get lastKey(){return this.keys[this.keys.length-1]}constructor(t){this.keys=t,this.hotkeysValue=k.joinKeys(t),this.label=k.makeLabel(t)}static joinKeys(t){return t.join(d)}static makeLabel(e){return e.map(t.capitalize).join("+")}static create(...t){if(function(t){const e=b(t);return g.has(e)}(t))throw new Error(`Shortcut ${k.joinKeys(t)} is a browser shortcut!`);return new k(t)}static createUnsafe(...t){return new k(t)}}class w{bound=new Map;subject$=new i;observable$=this.subject$.asObservable();constructor(){c.filter=function(t){if(h.includes(t.code))return!1;const e=t.target.tagName,n=/^(INPUT|TEXTAREA|SELECT)$/.test(e)?p.INPUT:p.OTHER;return c.setScope(n),!0}}listen(t,e){const n={...u,...e};return Array.isArray(t)?this.listenArray(t,n):this.listenSingle(t,n)}listenArray(t,e){return new l(n=>{const r=new Set(t);try{t.forEach(t=>this.bind(t,e))}catch(t){n.error(t)}const s=this.observable$.pipe(m(t=>r.has(t.shortcut))).subscribe(n);return()=>{s.unsubscribe(),t.forEach(t=>this.unbind(t,e))}})}listenSingle(t,e){return new l(n=>{try{this.bind(t,e)}catch(t){n.error(t)}const r=this.observable$.pipe(m(e=>e.shortcut===t)).subscribe(n);return()=>{r.unsubscribe(),this.unbind(t,e)}})}bind(t,e){const n={element:e.element,splitKey:d};if(this.bound.get(e.element)?.[t.hotkeysValue])throw new Error(`Shortcut ${t} is already binded!`);if(this.bound.has(e.element))this.bound.get(e.element)[t.hotkeysValue]=t;else{const n={[t.hotkeysValue]:t};this.bound.set(e.element,n)}c(t.hotkeysValue,n,this.keyHandlerFactory(e))}unbind(t,e){const n=this.bound.get(e.element);n?.[t.hotkeysValue]&&(n[t.hotkeysValue]=void 0,Object.keys(n).every(t=>void 0===n[t])&&this.bound.delete(e.element),c.unbind(t.hotkeysValue))}keyHandlerFactory(t){return(e,n)=>{t.preventDefault&&e.preventDefault();const r={shortcut:this.bound.get(t.element)[n.shortcut],src:n.scope,originalEvent:e};return this.subject$.next(r),!t.preventDefault}}static"ɵfac"=e.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:e,type:w,deps:[],target:e.ɵɵFactoryTarget.Injectable});static"ɵprov"=e.ɵɵngDeclareInjectable({minVersion:"12.0.0",version:"21.2.15",ngImport:e,type:w,providedIn:"root"})}e.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:e,type:w,decorators:[{type:n,args:[{providedIn:"root"}]}],ctorParameters:()=>[]});class v{keysPressed=new Set;pressedAtOnce=new Set;output=new r;onKeyDown(t){this.pressedAtOnce.has(t.key)||(this.keysPressed.add(t.key),this.pressedAtOnce.add(t.key),1===this.pressedAtOnce.size&&this.output.emit(t))}onKeyUp(t){this.keysPressed.delete(t.key),this.pressedAtOnce.delete(t.key),0===this.keysPressed.size&&this.pressedAtOnce.clear()}onWindowFocus(){this.pressedAtOnce.clear(),this.keysPressed.clear()}static"ɵfac"=e.ɵɵngDeclareFactory({minVersion:"12.0.0",version:"21.2.15",ngImport:e,type:v,deps:[],target:e.ɵɵFactoryTarget.Directive});static"ɵdir"=e.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"21.2.15",type:v,isStandalone:!0,selector:"[rdtKeyListener]",outputs:{output:"rdtKeyListener"},host:{listeners:{keydown:"onKeyDown($event)","window:keyup":"onKeyUp($event)",keyup:"onKeyUp($event)","window:focus":"onWindowFocus()"}},ngImport:e})}e.ɵɵngDeclareClassMetadata({minVersion:"12.0.0",version:"21.2.15",ngImport:e,type:v,decorators:[{type:a,args:[{selector:"[rdtKeyListener]",standalone:!0}]}],propDecorators:{output:[{type:o,args:["rdtKeyListener"]}],onKeyDown:[{type:s,args:["keydown",["$event"]]}],onKeyUp:[{type:s,args:["window:keyup",["$event"]]},{type:s,args:["keyup",["$event"]]}],onWindowFocus:[{type:s,args:["window:focus"]}]}});export{u as DEFAULT_SHORTCUT_CONFIG,h as IGNORED_KEYCODES,v as RdtKeyListenerDirective,k as RdtShortcut,w as RdtShortcutService,d as SHORTCUT_SPLIT_KEY,p as ShortcutSrcElement};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrdt/shortcuts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/core": ">=21.0.0",
|
|
6
6
|
"rxjs": ">=7.0.0",
|
|
7
7
|
"hotkeys-js": ">=3.10.0",
|
|
8
|
-
"@ngrdt/utils": "^0.1.
|
|
8
|
+
"@ngrdt/utils": "^0.1.3"
|
|
9
9
|
},
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"module": "fesm2022/ngrdt-shortcuts.mjs",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"default": "./fesm2022/ngrdt-shortcuts.mjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
|
+
"type": "module",
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"tslib": "^2.3.0"
|
|
24
25
|
}
|