diff --git a/.eslintrc.js b/.eslintrc.js index 84e6f57..707cca1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,4 @@ -const defaultConfig = require("@bigbinary/neeto-commons-frontend/configs/eslint/index.js"); +const defaultConfig = require("@bigbinary/neeto-commons-frontend/configs/nanos/eslint/index.js"); const { mergeDeepLeft } = require("ramda"); @@ -6,8 +6,6 @@ module.exports = mergeDeepLeft( { rules: { "@bigbinary/neeto/no-missing-localization": "off", - "@bigbinary/neeto/webpack-aliases-and-jsconfig-paths-should-be-in-sync": - "off", }, }, defaultConfig diff --git a/.gitignore b/.gitignore index b78b78c..de53132 100644 --- a/.gitignore +++ b/.gitignore @@ -117,7 +117,6 @@ yalc.lock /index.cjs.js.map /index.mjs /index.mjs.map -/index.d.ts # Ignore bundler config /.bundle @@ -232,9 +231,3 @@ dump.rdb # Ignore yalc generated files yalc.lock /.yalc - -/index.cjs.js -/index.cjs.js.map -/index.mjs -/index.mjs.map -/index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..452a856 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,11 @@ +type ConfigType = { + mode?: "default" | "global" | "scoped"; + unbindOnUnmount?: boolean; + enabled?: boolean; +}; + +export default function useHotkeys( + hotkey: string | string[], + handler: (event: React.KeyboardEvent) => void, + config?: ConfigType +): React.MutableRefObject | null; diff --git a/package.json b/package.json index 35c391f..e6eb22e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "prepare": "husky install", "build": "NODE_ENV=production rollup -c" }, + "types": "index.d.ts", "engines": { "node": ">=18.12", "npm": ">=9", diff --git a/rollup.config.js b/rollup.config.js index 05f60da..9db03ad 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -17,6 +17,8 @@ const globals = Object.fromEntries( keys(packageJSON.peerDependencies).map(lib => [lib, lib]) ); +const buildFilesMatchPattern = 'index.{cjs.js,cjs.js.map,mjs,mjs.map}'; + export default { input: "./src/index.js", output: [ @@ -39,7 +41,7 @@ export default { ], plugins: [ // To delete previously existing bundle. - cleaner({ targets: globSync(path.resolve(__dirname, `index.*`)) }), + cleaner({ targets: globSync(path.resolve(__dirname, buildFilesMatchPattern)) }), // To automatically externalize peerDependencies in a rollup bundle. peerDepsExternal(), // To use third party modules from node_modules diff --git a/src/constants.js b/src/constants.js index b6ecab9..18688e8 100644 --- a/src/constants.js +++ b/src/constants.js @@ -17,12 +17,7 @@ export const MAC_TO_WINDOWS_KEYS_MAP = { delete: "backspace", }; -export const OS = { - mac: "OS X", - windows: "Windows", -}; +// eslint-disable-next-line @bigbinary/neeto/hard-coded-strings-should-be-localized +export const OS = { mac: "OS X", windows: "Windows" }; -export const KEY_NAMES = { - delete: "delete", - backspace: "backspace", -}; +export const KEY_NAMES = { delete: "delete", backspace: "backspace" }; diff --git a/src/index.js b/src/index.js index f346318..5a45ea5 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import { useEffect, useRef } from "react"; import { mergeLeft } from "ramda"; + import { DEFAULT_CONFIG, MODES } from "src/constants"; import { bindHotKey,