diff --git a/package.json b/package.json index f174b2f..16fdc88 100644 --- a/package.json +++ b/package.json @@ -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 ", - "license": "Apache 2.0", + "license": "Apache-2.0", "engines": { "node": ">=6.0.0" }, @@ -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", diff --git a/src/index.ts b/src/index.ts index 2de74ab..5915979 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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 + 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 public options: Options public eventProcessor: EventProcessor @@ -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' diff --git a/src/key-container.ts b/src/key-container.ts index dbeda20..7d6e1ec 100644 --- a/src/key-container.ts +++ b/src/key-container.ts @@ -24,7 +24,7 @@ export interface ISkipKey { * * @class KeyContainer */ -class KeyContainer { +export class KeyContainer { /** * Map of allowed keys */ diff --git a/src/utils.ts b/src/utils.ts index 7923111..0b38ca2 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -interface Logger extends Console { +export interface Logger extends Console { group(title: string, options?: string) groupCollapsed(title: string, options?: string) } diff --git a/tsconfig.json b/tsconfig.json index 41a3e71..77dd1ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,8 @@ "noImplicitAny": false, "sourceMap": false, "moduleResolution": "node", + "declaration": true, + "outDir": "types", "typeRoots": [ "node_modules/@types" ] diff --git a/tsconfig.prod.json b/tsconfig.prod.json index bf72901..94e5bd6 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -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" ] } \ No newline at end of file