Skip to content

Commit

Permalink
feat(typescript): Support typescript
Browse files Browse the repository at this point in the history
Generate declarations for support typescript intellisense

Closes #10
  • Loading branch information
alexjoverm committed Feb 5, 2017
1 parent 4dc4afa commit fd48b2b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 28 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
"typescript"
],
"main": "dist/shortcut.js",
"typings": "dist/types/index.d.ts",
"files": [
"dist"
],
"repository": "https://github.com/coosto/ShortcutJS",
"author": "Alex Jover Morales <alexjovermorales@gmail.com>",
"license": "Apache 2.0",
"license": "Apache-2.0",
"engines": {
"node": ">=6.0.0"
},
Expand All @@ -29,10 +33,6 @@
"build:dev": "webpack",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"files": [
"dist",
"readme.md"
],
"config": {
"ghooks": {
"pre-commit": "npm run test:prod && npm run build",
Expand Down
43 changes: 23 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2017 Alex Jover Morales (alexjovermorales@gmail.com)
Licensed under the Apache License, Version 2.0 (the "License");
Licensed under the Apache License, Version 2.0 (the "License")
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -22,22 +22,21 @@ import { KeyCombo } from './key-combo'

import { keyContainer } from './key-container'

/**
* First Version of a ShortcutJS.
*
* Ideally, ShortcutJS could hold the keydown and keyup events, and execute the actions according
* to the key combos.
*
* WARNING: careful when adding combos with CTRL key on it. If you happen to trigger a by-default
* browser shortcut (like CTRL-T) the keyup event will not be performed
*
* @todo Improvements:
* - Avoid repetition of mouseDownEvents if the last key is the same
* - Performance of processActionCombos
*
* @class ShortcutJS
*/
export class ShortcutJS {
export interface ShortcutJS {
actions: Map<string, Action>
options: Options
eventProcessor: EventProcessor
init(options?: IOptions): void
reset(): void
loadFromJson(json: any, options?: IOptions): void
addAction(action: Action): void
subscribe(actionName: string, cb: Function): void
unsubscribe(actionName: string, cb?: Function): void
processEvent(ev: KeyboardEvent): void
cleanCombo(): void
}

class Shortcut implements ShortcutJS {
public actions: Map<string, Action>
public options: Options
public eventProcessor: EventProcessor
Expand Down Expand Up @@ -109,6 +108,10 @@ export class ShortcutJS {
}
}

export const shortcutJS = new ShortcutJS() // Enforce singleton
export { KeyCombo } from './key-combo'
export { Action } from './action'
export const shortcutJS: ShortcutJS = new Shortcut() // Enforce singleton
export * from './action'
export * from './event-processor'
export * from './json-parser'
export * from './key-combo'
export * from './key-container'
export * from './options'
2 changes: 1 addition & 1 deletion src/key-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ISkipKey {
*
* @class KeyContainer
*/
class KeyContainer {
export class KeyContainer {
/**
* Map of allowed keys
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface Logger extends Console {
export interface Logger extends Console {
group(title: string, options?: string)
groupCollapsed(title: string, options?: string)
}
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"noImplicitAny": false,
"sourceMap": false,
"moduleResolution": "node",
"declaration": true,
"outDir": "types",
"typeRoots": [
"node_modules/@types"
]
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
"noImplicitAny": false,
"sourceMap": false,
"moduleResolution": "node",
"declaration": true,
"outDir": "types",
"typeRoots": [
"node_modules/@types"
]
},
"files": ["src/index.ts"],
"exclude": [
"test",
"node_modules"
"node_modules",
"webpack.config.ts"
]
}

0 comments on commit fd48b2b

Please sign in to comment.