From 29974643b6880744d3318395a580c29944d4cf0e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:25:28 +0900 Subject: [PATCH 01/24] Install TypeScript --- package-lock.json | 43 +++++++++++++++++++++++++++++++++++++------ package.json | 2 ++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index cbc8dae..15fd9a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -395,6 +395,15 @@ "@babel/helper-plugin-utils": "^7.0.0" } }, + "@babel/plugin-syntax-typescript": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.3.3.tgz", + "integrity": "sha512-dGwbSMA1YhVS8+31CnPR7LB4pcbrzcV99wQzby4uAfrkZPYZlQ7ImwdpzLqi6Z6IL02b8IAL379CaMwo0x5Lag==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0" + } + }, "@babel/plugin-transform-react-display-name": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.2.0.tgz", @@ -435,6 +444,16 @@ "@babel/plugin-syntax-jsx": "^7.2.0" } }, + "@babel/plugin-transform-typescript": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.4.4.tgz", + "integrity": "sha512-rwDvjaMTx09WC0rXGBRlYSSkEHOKRrecY6hEr3SVIPKII8DVWXtapNAfAyMC0dovuO+zYArcAuKeu3q9DNRfzA==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-syntax-typescript": "^7.2.0" + } + }, "@babel/preset-react": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/preset-react/-/preset-react-7.0.0.tgz", @@ -448,6 +467,16 @@ "@babel/plugin-transform-react-jsx-source": "^7.0.0" } }, + "@babel/preset-typescript": { + "version": "7.3.3", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.3.3.tgz", + "integrity": "sha512-mzMVuIP4lqtn4du2ynEfdO0+RYcslwrZiJHXu4MGaC1ctJiW2fyaeDrtjJGs7R/KebZ1sgowcIoWf4uRpEfKEg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/plugin-transform-typescript": "^7.3.2" + } + }, "@babel/runtime": { "version": "7.4.4", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.4.4.tgz", @@ -3948,14 +3977,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3975,8 +4002,7 @@ "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", @@ -4124,7 +4150,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -10378,6 +10403,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", + "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==", + "dev": true + }, "uglify-js": { "version": "3.3.25", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.25.tgz", diff --git a/package.json b/package.json index 98cdc60..9db3296 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@babel/cli": "^7.4.4", "@babel/core": "^7.4.4", "@babel/preset-react": "^7.0.0", + "@babel/preset-typescript": "^7.3.3", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", "chai": "^4.2.0", @@ -51,6 +52,7 @@ "sass-loader": "^7.1.0", "sinon-chrome": "^3.0.1", "style-loader": "^0.23.1", + "typescript": "^3.4.5", "webextensions-api-fake": "^0.7.4", "webpack": "^4.30.0", "webpack-cli": "^3.3.1" From 074b34decaa890812fbf8c06f49016de877fc2e9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:35:13 +0900 Subject: [PATCH 02/24] Configure Webpack for TypeScript --- tsconfig.json | 31 +++++++++++++++++++++++++++++++ webpack.config.js | 14 +++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..bf03cd2 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "target": "es2017", + "module": "commonjs", + "allowJs": true, + "checkJs": true, + "jsx": "react", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "./build", + "removeComments": true, + "importHelpers": true, + + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "alwaysStrict": true, + + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + + "moduleResolution": "node", + "esModuleInterop": true + } +} diff --git a/webpack.config.js b/webpack.config.js index d9c60cc..a845375 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -20,12 +20,16 @@ config = { module: { rules: [ { - test: [ /\.js$/, /\.jsx$/ ], + test: [ /\.js$/, /\.jsx$/, /\.ts$/, /\.tsx$/], exclude: /node_modules/, loader: 'babel-loader', - query: { - presets: ['@babel/react'] - } + options: { + presets: [ + { plugins: ['@babel/plugin-proposal-class-properties'] }, + '@babel/react', + '@babel/preset-typescript' + ] + }, }, { test: /\.css$/, @@ -39,7 +43,7 @@ config = { }, resolve: { - extensions: [ '.js', '.jsx' ], + extensions: [ '.js', '.jsx', '.ts', '.tsx' ], modules: [path.join(__dirname, 'src'), 'node_modules'] }, From b1df2b141b37f9390e87207554f5722f0cb37da9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:44:48 +0900 Subject: [PATCH 03/24] Install web-ext-types --- package-lock.json | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index 15fd9a9..5df214a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11131,6 +11131,12 @@ } } }, + "web-ext-types": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/web-ext-types/-/web-ext-types-3.1.0.tgz", + "integrity": "sha512-HKVibk040vuhpbOljcIYYYC8GP9w9REbHpquI3im/aoZqoDIRq9DnsHl4Zsg+4Fg3SBnWsnvlIr1rnspV4TdXQ==", + "dev": true + }, "webextensions-api-fake": { "version": "0.7.4", "resolved": "https://registry.npmjs.org/webextensions-api-fake/-/webextensions-api-fake-0.7.4.tgz", diff --git a/package.json b/package.json index 9db3296..09354f2 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "sinon-chrome": "^3.0.1", "style-loader": "^0.23.1", "typescript": "^3.4.5", + "web-ext-types": "^3.1.0", "webextensions-api-fake": "^0.7.4", "webpack": "^4.30.0", "webpack-cli": "^3.3.1" From cc6092bbcd58e80a24c5cff10cae240a2701313b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:45:28 +0900 Subject: [PATCH 04/24] Configure web-ext-types --- tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index bf03cd2..575601b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,6 +26,8 @@ "noImplicitReturns": true, "moduleResolution": "node", - "esModuleInterop": true + "esModuleInterop": true, + + "typeRoots": ["node_modules/@types", "node_modules/web-ext-types"] } } From 4bc07b6f53654f7c23e393d2c7d79cd30d831aa3 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:55:30 +0900 Subject: [PATCH 05/24] Install @typescript-eslint/eslint-plugin --- package-lock.json | 76 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 77 insertions(+) diff --git a/package-lock.json b/package-lock.json index 5df214a..4e2179c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -608,6 +608,61 @@ "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", "dev": true }, + "@typescript-eslint/eslint-plugin": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.7.0.tgz", + "integrity": "sha512-NUSz1aTlIzzTjFFVFyzrbo8oFjHg3K/M9MzYByqbMCxeFdErhLAcGITVfXzSz+Yvp5OOpMu3HkIttB0NyKl54Q==", + "dev": true, + "requires": { + "@typescript-eslint/parser": "1.7.0", + "@typescript-eslint/typescript-estree": "1.7.0", + "eslint-utils": "^1.3.1", + "regexpp": "^2.0.1", + "requireindex": "^1.2.0", + "tsutils": "^3.7.0" + } + }, + "@typescript-eslint/parser": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.7.0.tgz", + "integrity": "sha512-1QFKxs2V940372srm12ovSE683afqc1jB6zF/f8iKhgLz1yoSjYeGHipasao33VXKI+0a/ob9okeogGdKGvvlg==", + "dev": true, + "requires": { + "@typescript-eslint/typescript-estree": "1.7.0", + "eslint-scope": "^4.0.0", + "eslint-visitor-keys": "^1.0.0" + }, + "dependencies": { + "eslint-scope": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", + "integrity": "sha512-p7VutNr1O/QrxysMo3E45FjYDTeXBy0iTltPFNSqKAIfjDSXC+4dj+qfyuD8bfAXrW/y6lW3O76VaYNPKfpKrg==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + } + } + }, + "@typescript-eslint/typescript-estree": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.7.0.tgz", + "integrity": "sha512-K5uedUxVmlYrVkFbyV3htDipvLqTE3QMOUQEHYJaKtgzxj6r7c5Ca/DG1tGgFxX+fsbi9nDIrf4arq7Ib7H/Yw==", + "dev": true, + "requires": { + "lodash.unescape": "4.0.1", + "semver": "5.5.0" + }, + "dependencies": { + "semver": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", + "dev": true + } + } + }, "@webassemblyjs/ast": { "version": "1.8.5", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.8.5.tgz", @@ -6439,6 +6494,12 @@ "integrity": "sha1-0jM6NtnncXyK0vfKyv7HwytERmQ=", "dev": true }, + "lodash.unescape": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.unescape/-/lodash.unescape-4.0.1.tgz", + "integrity": "sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=", + "dev": true + }, "log-symbols": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", @@ -8926,6 +8987,12 @@ "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=", "dev": true }, + "requireindex": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", + "dev": true + }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", @@ -10351,6 +10418,15 @@ "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", "dev": true }, + "tsutils": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.10.0.tgz", + "integrity": "sha512-q20XSMq7jutbGB8luhKKsQldRKWvyBO2BGqni3p4yq8Ys9bEP/xQw3KepKmMRt9gJ4lvQSScrihJrcKdKoSU7Q==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", diff --git a/package.json b/package.json index 09354f2..4169b90 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@babel/core": "^7.4.4", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.3.3", + "@typescript-eslint/eslint-plugin": "^1.7.0", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", "chai": "^4.2.0", From 08a318874e979ca115bfcb0a88f4678469332088 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:05:19 +0900 Subject: [PATCH 06/24] Install types --- package-lock.json | 43 +++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ 2 files changed, 46 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4e2179c..3e15f83 100644 --- a/package-lock.json +++ b/package-lock.json @@ -608,6 +608,43 @@ "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", "dev": true }, + "@types/hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==", + "dev": true, + "requires": { + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0" + } + }, + "@types/prop-types": { + "version": "15.7.1", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.1.tgz", + "integrity": "sha512-CFzn9idOEpHrgdw8JsoTkaDDyRWk1jrzIV8djzcgpq0y9tG4B4lFT+Nxh52DVpDXV+n4+NPNv7M1Dj5uMp6XFg==", + "dev": true + }, + "@types/react": { + "version": "16.8.15", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.15.tgz", + "integrity": "sha512-dMhzw1rWK+wwJWvPp5Pk12ksSrm/z/C/+lOQbMZ7YfDQYnJ02bc0wtg4EJD9qrFhuxFrf/ywNgwTboucobJqQg==", + "dev": true, + "requires": { + "@types/prop-types": "*", + "csstype": "^2.2.0" + } + }, + "@types/react-redux": { + "version": "7.0.8", + "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.0.8.tgz", + "integrity": "sha512-vIBC15E84ehN6RzdGwRVa41whp9e4CkfPm+WfD0r6y6vqBf4tQPKZeKEBfLLM8k79uSwQC7rh3rH/MFaN1IESQ==", + "dev": true, + "requires": { + "@types/hoist-non-react-statics": "^3.3.0", + "@types/react": "*", + "redux": "^4.0.0" + } + }, "@typescript-eslint/eslint-plugin": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.7.0.tgz", @@ -2339,6 +2376,12 @@ "integrity": "sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==", "dev": true }, + "csstype": { + "version": "2.6.4", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-2.6.4.tgz", + "integrity": "sha512-lAJUJP3M6HxFXbqtGRc0iZrdyeN+WzOWeY0q/VnFzI+kqVrYIzC7bWlKqCW7oCIdzoPkvfp82EVvrTlQ8zsWQg==", + "dev": true + }, "currently-unhandled": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz", diff --git a/package.json b/package.json index 4169b90..f617c14 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "@babel/core": "^7.4.4", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.3.3", + "@types/prop-types": "^15.7.1", + "@types/react": "^16.8.15", + "@types/react-redux": "^7.0.8", "@typescript-eslint/eslint-plugin": "^1.7.0", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", From 257162e5b6b4993e1dff0d705ffa6f0d809033eb Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 13:59:51 +0900 Subject: [PATCH 07/24] Configure eslint for TypeScript --- .eslintrc | 16 +++++++++++----- package.json | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0f41e10..fb60bc2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,12 +5,17 @@ "browser" : true, "webextensions": true }, - "plugins": ["react"], - "parser": "babel-eslint", + "plugins": [ + "react", + "@typescript-eslint" + ], + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaFeatures": { "jsx": true - } + }, + "sourceType": "module", + "project": "./tsconfig.json" }, "extends": [ "eslint:all", "plugin:react/recommended" ], "rules": { @@ -48,7 +53,7 @@ "no-ternary": "off", "no-undefined": "off", "no-undef-init": "off", - "no-unused-vars": ["error", { "varsIgnorePattern": "h" }], + "no-unused-vars": "off", "no-use-before-define": "off", "no-warning-comments": "off", "object-curly-newline": ["error", { "consistent": true }], @@ -71,6 +76,7 @@ "react/jsx-indent": ["error", 2], "react/prop-types": "off", - "react/react-in-jsx-scope": "off" + "react/react-in-jsx-scope": "off", + "@typescript-eslint/no-unused-vars": "error" } } diff --git a/package.json b/package.json index f617c14..590504b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "start": "webpack --mode development -w --debug --devtool inline-source-map", "build": "NODE_ENV=production webpack --mode production --progress --display-error-details", "package": "npm run build && script/package", - "lint": "eslint --ext .jsx,.js src", + "lint": "eslint --ext .js,.jsx,.ts,.tsx src", "test": "karma start", "test:e2e": "mocha --timeout 8000 e2e" }, From c60d0e7392fc708e961614d6b756a045de74f458 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 14:00:07 +0900 Subject: [PATCH 08/24] Rename .js/.jsx to .ts/.tsx --- .../{AddonEnabledController.js => AddonEnabledController.ts} | 0 .../controllers/{CommandController.js => CommandController.ts} | 0 .../controllers/{FindController.js => FindController.ts} | 0 .../controllers/{LinkController.js => LinkController.ts} | 0 .../controllers/{MarkController.js => MarkController.ts} | 0 .../{OperationController.js => OperationController.ts} | 0 .../controllers/{SettingController.js => SettingController.ts} | 0 .../controllers/{VersionController.js => VersionController.ts} | 0 src/background/controllers/{version.js => version.ts} | 0 src/background/domains/{CommandDocs.js => CommandDocs.ts} | 0 src/background/domains/{CompletionGroup.js => CompletionGroup.ts} | 0 src/background/domains/{CompletionItem.js => CompletionItem.ts} | 0 src/background/domains/{Completions.js => Completions.ts} | 0 src/background/domains/{GlobalMark.js => GlobalMark.ts} | 0 src/background/domains/{Setting.js => Setting.ts} | 0 src/background/{index.js => index.ts} | 0 .../infrastructures/{ConsoleClient.js => ConsoleClient.ts} | 0 .../{ContentMessageClient.js => ContentMessageClient.ts} | 0 .../{ContentMessageListener.js => ContentMessageListener.ts} | 0 .../infrastructures/{MemoryStorage.js => MemoryStorage.ts} | 0 .../presenters/{IndicatorPresenter.js => IndicatorPresenter.ts} | 0 .../presenters/{NotifyPresenter.js => NotifyPresenter.ts} | 0 src/background/presenters/{TabPresenter.js => TabPresenter.ts} | 0 .../presenters/{WindowPresenter.js => WindowPresenter.ts} | 0 .../repositories/{BookmarkRepository.js => BookmarkRepository.ts} | 0 .../{BrowserSettingRepository.js => BrowserSettingRepository.ts} | 0 .../{CompletionsRepository.js => CompletionsRepository.ts} | 0 .../repositories/{FindRepository.js => FindRepository.ts} | 0 .../repositories/{MarkRepository.js => MarkRepository.ts} | 0 ...sistentSettingRepository.js => PersistentSettingRepository.ts} | 0 .../repositories/{SettingRepository.js => SettingRepository.ts} | 0 .../repositories/{VersionRepository.js => VersionRepository.ts} | 0 .../usecases/{AddonEnabledUseCase.js => AddonEnabledUseCase.ts} | 0 src/background/usecases/{CommandUseCase.js => CommandUseCase.ts} | 0 .../usecases/{CompletionsUseCase.js => CompletionsUseCase.ts} | 0 src/background/usecases/{ConsoleUseCase.js => ConsoleUseCase.ts} | 0 src/background/usecases/{FindUseCase.js => FindUseCase.ts} | 0 src/background/usecases/{LinkUseCase.js => LinkUseCase.ts} | 0 src/background/usecases/{MarkUseCase.js => MarkUseCase.ts} | 0 src/background/usecases/{SettingUseCase.js => SettingUseCase.ts} | 0 .../usecases/{TabSelectUseCase.js => TabSelectUseCase.ts} | 0 src/background/usecases/{TabUseCase.js => TabUseCase.ts} | 0 src/background/usecases/{VersionUseCase.js => VersionUseCase.ts} | 0 src/background/usecases/{ZoomUseCase.js => ZoomUseCase.ts} | 0 src/background/usecases/{filters.js => filters.ts} | 0 src/background/usecases/{parsers.js => parsers.ts} | 0 src/console/actions/{console.js => console.ts} | 0 src/console/actions/{index.js => index.ts} | 0 src/console/components/{Console.jsx => Console.tsx} | 0 src/console/components/console/{Completion.jsx => Completion.tsx} | 0 .../components/console/{CompletionItem.jsx => CompletionItem.tsx} | 0 .../console/{CompletionTitle.jsx => CompletionTitle.tsx} | 0 src/console/components/console/{Input.jsx => Input.tsx} | 0 src/console/components/console/{Message.jsx => Message.tsx} | 0 src/console/{index.jsx => index.tsx} | 0 src/console/reducers/{index.js => index.ts} | 0 src/content/actions/{addon.js => addon.ts} | 0 src/content/actions/{find.js => find.ts} | 0 .../actions/{follow-controller.js => follow-controller.ts} | 0 src/content/actions/{index.js => index.ts} | 0 src/content/actions/{input.js => input.ts} | 0 src/content/actions/{mark.js => mark.ts} | 0 src/content/actions/{operation.js => operation.ts} | 0 src/content/actions/{setting.js => setting.ts} | 0 src/content/components/common/{follow.js => follow.ts} | 0 src/content/components/common/{hint.js => hint.ts} | 0 src/content/components/common/{index.js => index.ts} | 0 src/content/components/common/{input.js => input.ts} | 0 src/content/components/common/{keymapper.js => keymapper.ts} | 0 src/content/components/common/{mark.js => mark.ts} | 0 src/content/components/{frame-content.js => frame-content.ts} | 0 src/content/components/top-content/{find.js => find.ts} | 0 .../top-content/{follow-controller.js => follow-controller.ts} | 0 src/content/components/top-content/{index.js => index.ts} | 0 src/content/{console-frames.js => console-frames.ts} | 0 src/content/{focuses.js => focuses.ts} | 0 src/content/{hint-key-producer.js => hint-key-producer.ts} | 0 src/content/{index.js => index.ts} | 0 src/content/{navigates.js => navigates.ts} | 0 src/content/reducers/{addon.js => addon.ts} | 0 src/content/reducers/{find.js => find.ts} | 0 .../reducers/{follow-controller.js => follow-controller.ts} | 0 src/content/reducers/{index.js => index.ts} | 0 src/content/reducers/{input.js => input.ts} | 0 src/content/reducers/{mark.js => mark.ts} | 0 src/content/reducers/{setting.js => setting.ts} | 0 src/content/{scrolls.js => scrolls.ts} | 0 src/content/{site-style.js => site-style.ts} | 0 src/content/{urls.js => urls.ts} | 0 src/settings/actions/{index.js => index.ts} | 0 src/settings/actions/{setting.js => setting.ts} | 0 .../components/form/{BlacklistForm.jsx => BlacklistForm.tsx} | 0 src/settings/components/form/{KeymapsForm.jsx => KeymapsForm.tsx} | 0 .../components/form/{PropertiesForm.jsx => PropertiesForm.tsx} | 0 src/settings/components/form/{SearchForm.jsx => SearchForm.tsx} | 0 src/settings/components/{index.jsx => index.tsx} | 0 src/settings/components/ui/{AddButton.jsx => AddButton.tsx} | 0 src/settings/components/ui/{DeleteButton.jsx => DeleteButton.tsx} | 0 src/settings/components/ui/{Input.jsx => Input.tsx} | 0 src/settings/{index.jsx => index.tsx} | 0 src/settings/{keymaps.js => keymaps.ts} | 0 src/settings/reducers/{setting.js => setting.ts} | 0 src/shared/{blacklists.js => blacklists.ts} | 0 src/shared/{messages.js => messages.ts} | 0 src/shared/{operations.js => operations.ts} | 0 src/shared/settings/{default.js => default.ts} | 0 src/shared/settings/{properties.js => properties.ts} | 0 src/shared/settings/{storage.js => storage.ts} | 0 src/shared/settings/{validator.js => validator.ts} | 0 src/shared/settings/{values.js => values.ts} | 0 src/shared/{urls.js => urls.ts} | 0 src/shared/utils/{dom.js => dom.ts} | 0 src/shared/utils/{keys.js => keys.ts} | 0 src/shared/utils/{re.js => re.ts} | 0 .../background/domains/{GlobalMark.test.js => GlobalMark.test.ts} | 0 .../{MemoryStorage.test.js => MemoryStorage.test.ts} | 0 test/background/repositories/{Mark.test.js => Mark.test.ts} | 0 test/background/repositories/{Version.js => Version.ts} | 0 test/background/usecases/{filters.test.js => filters.test.ts} | 0 test/background/usecases/{parsers.test.js => parsers.test.ts} | 0 test/console/actions/{console.test.js => console.test.ts} | 0 .../console/{Completion.test.jsx => Completion.test.tsx} | 0 test/console/reducers/{console.test.js => console.test.ts} | 0 .../{follow-controller.test.js => follow-controller.test.ts} | 0 test/content/actions/{input.test.js => input.test.ts} | 0 test/content/actions/{mark.test.js => mark.test.ts} | 0 test/content/actions/{setting.test.js => setting.test.ts} | 0 test/content/components/common/{follow.test.js => follow.test.ts} | 0 test/content/components/common/{hint.test.js => hint.test.ts} | 0 test/content/components/common/{input.test.js => input.test.ts} | 0 .../{hint-key-producer.test.js => hint-key-producer.test.ts} | 0 test/content/{navigates.test.js => navigates.test.ts} | 0 test/content/reducers/{addon.test.js => addon.test.ts} | 0 test/content/reducers/{find.test.js => find.test.ts} | 0 .../{follow-controller.test.js => follow-controller.test.ts} | 0 test/content/reducers/{input.test.js => input.test.ts} | 0 test/content/reducers/{mark.test.js => mark.test.ts} | 0 test/content/reducers/{setting.test.js => setting.test.ts} | 0 test/{main.js => main.ts} | 0 .../form/{BlacklistForm.test.jsx => BlacklistForm.test.tsx} | 0 .../form/{KeymapsForm.test.jsx => KeymapsForm.test.tsx} | 0 .../form/{PropertiesForm.test.jsx => PropertiesForm.test.tsx} | 0 .../form/{SearchEngineForm.test.jsx => SearchEngineForm.test.tsx} | 0 test/settings/components/ui/{input.test.jsx => input.test.tsx} | 0 test/settings/reducers/{setting.test.js => setting.test.ts} | 0 test/shared/{blacklists.test.js => blacklists.test.ts} | 0 test/shared/settings/{validator.test.js => validator.test.ts} | 0 test/shared/settings/{values.test.js => values.test.ts} | 0 test/shared/{urls.test.js => urls.test.ts} | 0 test/shared/utils/{keys.test.js => keys.test.ts} | 0 test/shared/utils/{re.test.js => re.test.ts} | 0 151 files changed, 0 insertions(+), 0 deletions(-) rename src/background/controllers/{AddonEnabledController.js => AddonEnabledController.ts} (100%) rename src/background/controllers/{CommandController.js => CommandController.ts} (100%) rename src/background/controllers/{FindController.js => FindController.ts} (100%) rename src/background/controllers/{LinkController.js => LinkController.ts} (100%) rename src/background/controllers/{MarkController.js => MarkController.ts} (100%) rename src/background/controllers/{OperationController.js => OperationController.ts} (100%) rename src/background/controllers/{SettingController.js => SettingController.ts} (100%) rename src/background/controllers/{VersionController.js => VersionController.ts} (100%) rename src/background/controllers/{version.js => version.ts} (100%) rename src/background/domains/{CommandDocs.js => CommandDocs.ts} (100%) rename src/background/domains/{CompletionGroup.js => CompletionGroup.ts} (100%) rename src/background/domains/{CompletionItem.js => CompletionItem.ts} (100%) rename src/background/domains/{Completions.js => Completions.ts} (100%) rename src/background/domains/{GlobalMark.js => GlobalMark.ts} (100%) rename src/background/domains/{Setting.js => Setting.ts} (100%) rename src/background/{index.js => index.ts} (100%) rename src/background/infrastructures/{ConsoleClient.js => ConsoleClient.ts} (100%) rename src/background/infrastructures/{ContentMessageClient.js => ContentMessageClient.ts} (100%) rename src/background/infrastructures/{ContentMessageListener.js => ContentMessageListener.ts} (100%) rename src/background/infrastructures/{MemoryStorage.js => MemoryStorage.ts} (100%) rename src/background/presenters/{IndicatorPresenter.js => IndicatorPresenter.ts} (100%) rename src/background/presenters/{NotifyPresenter.js => NotifyPresenter.ts} (100%) rename src/background/presenters/{TabPresenter.js => TabPresenter.ts} (100%) rename src/background/presenters/{WindowPresenter.js => WindowPresenter.ts} (100%) rename src/background/repositories/{BookmarkRepository.js => BookmarkRepository.ts} (100%) rename src/background/repositories/{BrowserSettingRepository.js => BrowserSettingRepository.ts} (100%) rename src/background/repositories/{CompletionsRepository.js => CompletionsRepository.ts} (100%) rename src/background/repositories/{FindRepository.js => FindRepository.ts} (100%) rename src/background/repositories/{MarkRepository.js => MarkRepository.ts} (100%) rename src/background/repositories/{PersistentSettingRepository.js => PersistentSettingRepository.ts} (100%) rename src/background/repositories/{SettingRepository.js => SettingRepository.ts} (100%) rename src/background/repositories/{VersionRepository.js => VersionRepository.ts} (100%) rename src/background/usecases/{AddonEnabledUseCase.js => AddonEnabledUseCase.ts} (100%) rename src/background/usecases/{CommandUseCase.js => CommandUseCase.ts} (100%) rename src/background/usecases/{CompletionsUseCase.js => CompletionsUseCase.ts} (100%) rename src/background/usecases/{ConsoleUseCase.js => ConsoleUseCase.ts} (100%) rename src/background/usecases/{FindUseCase.js => FindUseCase.ts} (100%) rename src/background/usecases/{LinkUseCase.js => LinkUseCase.ts} (100%) rename src/background/usecases/{MarkUseCase.js => MarkUseCase.ts} (100%) rename src/background/usecases/{SettingUseCase.js => SettingUseCase.ts} (100%) rename src/background/usecases/{TabSelectUseCase.js => TabSelectUseCase.ts} (100%) rename src/background/usecases/{TabUseCase.js => TabUseCase.ts} (100%) rename src/background/usecases/{VersionUseCase.js => VersionUseCase.ts} (100%) rename src/background/usecases/{ZoomUseCase.js => ZoomUseCase.ts} (100%) rename src/background/usecases/{filters.js => filters.ts} (100%) rename src/background/usecases/{parsers.js => parsers.ts} (100%) rename src/console/actions/{console.js => console.ts} (100%) rename src/console/actions/{index.js => index.ts} (100%) rename src/console/components/{Console.jsx => Console.tsx} (100%) rename src/console/components/console/{Completion.jsx => Completion.tsx} (100%) rename src/console/components/console/{CompletionItem.jsx => CompletionItem.tsx} (100%) rename src/console/components/console/{CompletionTitle.jsx => CompletionTitle.tsx} (100%) rename src/console/components/console/{Input.jsx => Input.tsx} (100%) rename src/console/components/console/{Message.jsx => Message.tsx} (100%) rename src/console/{index.jsx => index.tsx} (100%) rename src/console/reducers/{index.js => index.ts} (100%) rename src/content/actions/{addon.js => addon.ts} (100%) rename src/content/actions/{find.js => find.ts} (100%) rename src/content/actions/{follow-controller.js => follow-controller.ts} (100%) rename src/content/actions/{index.js => index.ts} (100%) rename src/content/actions/{input.js => input.ts} (100%) rename src/content/actions/{mark.js => mark.ts} (100%) rename src/content/actions/{operation.js => operation.ts} (100%) rename src/content/actions/{setting.js => setting.ts} (100%) rename src/content/components/common/{follow.js => follow.ts} (100%) rename src/content/components/common/{hint.js => hint.ts} (100%) rename src/content/components/common/{index.js => index.ts} (100%) rename src/content/components/common/{input.js => input.ts} (100%) rename src/content/components/common/{keymapper.js => keymapper.ts} (100%) rename src/content/components/common/{mark.js => mark.ts} (100%) rename src/content/components/{frame-content.js => frame-content.ts} (100%) rename src/content/components/top-content/{find.js => find.ts} (100%) rename src/content/components/top-content/{follow-controller.js => follow-controller.ts} (100%) rename src/content/components/top-content/{index.js => index.ts} (100%) rename src/content/{console-frames.js => console-frames.ts} (100%) rename src/content/{focuses.js => focuses.ts} (100%) rename src/content/{hint-key-producer.js => hint-key-producer.ts} (100%) rename src/content/{index.js => index.ts} (100%) rename src/content/{navigates.js => navigates.ts} (100%) rename src/content/reducers/{addon.js => addon.ts} (100%) rename src/content/reducers/{find.js => find.ts} (100%) rename src/content/reducers/{follow-controller.js => follow-controller.ts} (100%) rename src/content/reducers/{index.js => index.ts} (100%) rename src/content/reducers/{input.js => input.ts} (100%) rename src/content/reducers/{mark.js => mark.ts} (100%) rename src/content/reducers/{setting.js => setting.ts} (100%) rename src/content/{scrolls.js => scrolls.ts} (100%) rename src/content/{site-style.js => site-style.ts} (100%) rename src/content/{urls.js => urls.ts} (100%) rename src/settings/actions/{index.js => index.ts} (100%) rename src/settings/actions/{setting.js => setting.ts} (100%) rename src/settings/components/form/{BlacklistForm.jsx => BlacklistForm.tsx} (100%) rename src/settings/components/form/{KeymapsForm.jsx => KeymapsForm.tsx} (100%) rename src/settings/components/form/{PropertiesForm.jsx => PropertiesForm.tsx} (100%) rename src/settings/components/form/{SearchForm.jsx => SearchForm.tsx} (100%) rename src/settings/components/{index.jsx => index.tsx} (100%) rename src/settings/components/ui/{AddButton.jsx => AddButton.tsx} (100%) rename src/settings/components/ui/{DeleteButton.jsx => DeleteButton.tsx} (100%) rename src/settings/components/ui/{Input.jsx => Input.tsx} (100%) rename src/settings/{index.jsx => index.tsx} (100%) rename src/settings/{keymaps.js => keymaps.ts} (100%) rename src/settings/reducers/{setting.js => setting.ts} (100%) rename src/shared/{blacklists.js => blacklists.ts} (100%) rename src/shared/{messages.js => messages.ts} (100%) rename src/shared/{operations.js => operations.ts} (100%) rename src/shared/settings/{default.js => default.ts} (100%) rename src/shared/settings/{properties.js => properties.ts} (100%) rename src/shared/settings/{storage.js => storage.ts} (100%) rename src/shared/settings/{validator.js => validator.ts} (100%) rename src/shared/settings/{values.js => values.ts} (100%) rename src/shared/{urls.js => urls.ts} (100%) rename src/shared/utils/{dom.js => dom.ts} (100%) rename src/shared/utils/{keys.js => keys.ts} (100%) rename src/shared/utils/{re.js => re.ts} (100%) rename test/background/domains/{GlobalMark.test.js => GlobalMark.test.ts} (100%) rename test/background/infrastructures/{MemoryStorage.test.js => MemoryStorage.test.ts} (100%) rename test/background/repositories/{Mark.test.js => Mark.test.ts} (100%) rename test/background/repositories/{Version.js => Version.ts} (100%) rename test/background/usecases/{filters.test.js => filters.test.ts} (100%) rename test/background/usecases/{parsers.test.js => parsers.test.ts} (100%) rename test/console/actions/{console.test.js => console.test.ts} (100%) rename test/console/components/console/{Completion.test.jsx => Completion.test.tsx} (100%) rename test/console/reducers/{console.test.js => console.test.ts} (100%) rename test/content/actions/{follow-controller.test.js => follow-controller.test.ts} (100%) rename test/content/actions/{input.test.js => input.test.ts} (100%) rename test/content/actions/{mark.test.js => mark.test.ts} (100%) rename test/content/actions/{setting.test.js => setting.test.ts} (100%) rename test/content/components/common/{follow.test.js => follow.test.ts} (100%) rename test/content/components/common/{hint.test.js => hint.test.ts} (100%) rename test/content/components/common/{input.test.js => input.test.ts} (100%) rename test/content/{hint-key-producer.test.js => hint-key-producer.test.ts} (100%) rename test/content/{navigates.test.js => navigates.test.ts} (100%) rename test/content/reducers/{addon.test.js => addon.test.ts} (100%) rename test/content/reducers/{find.test.js => find.test.ts} (100%) rename test/content/reducers/{follow-controller.test.js => follow-controller.test.ts} (100%) rename test/content/reducers/{input.test.js => input.test.ts} (100%) rename test/content/reducers/{mark.test.js => mark.test.ts} (100%) rename test/content/reducers/{setting.test.js => setting.test.ts} (100%) rename test/{main.js => main.ts} (100%) rename test/settings/components/form/{BlacklistForm.test.jsx => BlacklistForm.test.tsx} (100%) rename test/settings/components/form/{KeymapsForm.test.jsx => KeymapsForm.test.tsx} (100%) rename test/settings/components/form/{PropertiesForm.test.jsx => PropertiesForm.test.tsx} (100%) rename test/settings/components/form/{SearchEngineForm.test.jsx => SearchEngineForm.test.tsx} (100%) rename test/settings/components/ui/{input.test.jsx => input.test.tsx} (100%) rename test/settings/reducers/{setting.test.js => setting.test.ts} (100%) rename test/shared/{blacklists.test.js => blacklists.test.ts} (100%) rename test/shared/settings/{validator.test.js => validator.test.ts} (100%) rename test/shared/settings/{values.test.js => values.test.ts} (100%) rename test/shared/{urls.test.js => urls.test.ts} (100%) rename test/shared/utils/{keys.test.js => keys.test.ts} (100%) rename test/shared/utils/{re.test.js => re.test.ts} (100%) diff --git a/src/background/controllers/AddonEnabledController.js b/src/background/controllers/AddonEnabledController.ts similarity index 100% rename from src/background/controllers/AddonEnabledController.js rename to src/background/controllers/AddonEnabledController.ts diff --git a/src/background/controllers/CommandController.js b/src/background/controllers/CommandController.ts similarity index 100% rename from src/background/controllers/CommandController.js rename to src/background/controllers/CommandController.ts diff --git a/src/background/controllers/FindController.js b/src/background/controllers/FindController.ts similarity index 100% rename from src/background/controllers/FindController.js rename to src/background/controllers/FindController.ts diff --git a/src/background/controllers/LinkController.js b/src/background/controllers/LinkController.ts similarity index 100% rename from src/background/controllers/LinkController.js rename to src/background/controllers/LinkController.ts diff --git a/src/background/controllers/MarkController.js b/src/background/controllers/MarkController.ts similarity index 100% rename from src/background/controllers/MarkController.js rename to src/background/controllers/MarkController.ts diff --git a/src/background/controllers/OperationController.js b/src/background/controllers/OperationController.ts similarity index 100% rename from src/background/controllers/OperationController.js rename to src/background/controllers/OperationController.ts diff --git a/src/background/controllers/SettingController.js b/src/background/controllers/SettingController.ts similarity index 100% rename from src/background/controllers/SettingController.js rename to src/background/controllers/SettingController.ts diff --git a/src/background/controllers/VersionController.js b/src/background/controllers/VersionController.ts similarity index 100% rename from src/background/controllers/VersionController.js rename to src/background/controllers/VersionController.ts diff --git a/src/background/controllers/version.js b/src/background/controllers/version.ts similarity index 100% rename from src/background/controllers/version.js rename to src/background/controllers/version.ts diff --git a/src/background/domains/CommandDocs.js b/src/background/domains/CommandDocs.ts similarity index 100% rename from src/background/domains/CommandDocs.js rename to src/background/domains/CommandDocs.ts diff --git a/src/background/domains/CompletionGroup.js b/src/background/domains/CompletionGroup.ts similarity index 100% rename from src/background/domains/CompletionGroup.js rename to src/background/domains/CompletionGroup.ts diff --git a/src/background/domains/CompletionItem.js b/src/background/domains/CompletionItem.ts similarity index 100% rename from src/background/domains/CompletionItem.js rename to src/background/domains/CompletionItem.ts diff --git a/src/background/domains/Completions.js b/src/background/domains/Completions.ts similarity index 100% rename from src/background/domains/Completions.js rename to src/background/domains/Completions.ts diff --git a/src/background/domains/GlobalMark.js b/src/background/domains/GlobalMark.ts similarity index 100% rename from src/background/domains/GlobalMark.js rename to src/background/domains/GlobalMark.ts diff --git a/src/background/domains/Setting.js b/src/background/domains/Setting.ts similarity index 100% rename from src/background/domains/Setting.js rename to src/background/domains/Setting.ts diff --git a/src/background/index.js b/src/background/index.ts similarity index 100% rename from src/background/index.js rename to src/background/index.ts diff --git a/src/background/infrastructures/ConsoleClient.js b/src/background/infrastructures/ConsoleClient.ts similarity index 100% rename from src/background/infrastructures/ConsoleClient.js rename to src/background/infrastructures/ConsoleClient.ts diff --git a/src/background/infrastructures/ContentMessageClient.js b/src/background/infrastructures/ContentMessageClient.ts similarity index 100% rename from src/background/infrastructures/ContentMessageClient.js rename to src/background/infrastructures/ContentMessageClient.ts diff --git a/src/background/infrastructures/ContentMessageListener.js b/src/background/infrastructures/ContentMessageListener.ts similarity index 100% rename from src/background/infrastructures/ContentMessageListener.js rename to src/background/infrastructures/ContentMessageListener.ts diff --git a/src/background/infrastructures/MemoryStorage.js b/src/background/infrastructures/MemoryStorage.ts similarity index 100% rename from src/background/infrastructures/MemoryStorage.js rename to src/background/infrastructures/MemoryStorage.ts diff --git a/src/background/presenters/IndicatorPresenter.js b/src/background/presenters/IndicatorPresenter.ts similarity index 100% rename from src/background/presenters/IndicatorPresenter.js rename to src/background/presenters/IndicatorPresenter.ts diff --git a/src/background/presenters/NotifyPresenter.js b/src/background/presenters/NotifyPresenter.ts similarity index 100% rename from src/background/presenters/NotifyPresenter.js rename to src/background/presenters/NotifyPresenter.ts diff --git a/src/background/presenters/TabPresenter.js b/src/background/presenters/TabPresenter.ts similarity index 100% rename from src/background/presenters/TabPresenter.js rename to src/background/presenters/TabPresenter.ts diff --git a/src/background/presenters/WindowPresenter.js b/src/background/presenters/WindowPresenter.ts similarity index 100% rename from src/background/presenters/WindowPresenter.js rename to src/background/presenters/WindowPresenter.ts diff --git a/src/background/repositories/BookmarkRepository.js b/src/background/repositories/BookmarkRepository.ts similarity index 100% rename from src/background/repositories/BookmarkRepository.js rename to src/background/repositories/BookmarkRepository.ts diff --git a/src/background/repositories/BrowserSettingRepository.js b/src/background/repositories/BrowserSettingRepository.ts similarity index 100% rename from src/background/repositories/BrowserSettingRepository.js rename to src/background/repositories/BrowserSettingRepository.ts diff --git a/src/background/repositories/CompletionsRepository.js b/src/background/repositories/CompletionsRepository.ts similarity index 100% rename from src/background/repositories/CompletionsRepository.js rename to src/background/repositories/CompletionsRepository.ts diff --git a/src/background/repositories/FindRepository.js b/src/background/repositories/FindRepository.ts similarity index 100% rename from src/background/repositories/FindRepository.js rename to src/background/repositories/FindRepository.ts diff --git a/src/background/repositories/MarkRepository.js b/src/background/repositories/MarkRepository.ts similarity index 100% rename from src/background/repositories/MarkRepository.js rename to src/background/repositories/MarkRepository.ts diff --git a/src/background/repositories/PersistentSettingRepository.js b/src/background/repositories/PersistentSettingRepository.ts similarity index 100% rename from src/background/repositories/PersistentSettingRepository.js rename to src/background/repositories/PersistentSettingRepository.ts diff --git a/src/background/repositories/SettingRepository.js b/src/background/repositories/SettingRepository.ts similarity index 100% rename from src/background/repositories/SettingRepository.js rename to src/background/repositories/SettingRepository.ts diff --git a/src/background/repositories/VersionRepository.js b/src/background/repositories/VersionRepository.ts similarity index 100% rename from src/background/repositories/VersionRepository.js rename to src/background/repositories/VersionRepository.ts diff --git a/src/background/usecases/AddonEnabledUseCase.js b/src/background/usecases/AddonEnabledUseCase.ts similarity index 100% rename from src/background/usecases/AddonEnabledUseCase.js rename to src/background/usecases/AddonEnabledUseCase.ts diff --git a/src/background/usecases/CommandUseCase.js b/src/background/usecases/CommandUseCase.ts similarity index 100% rename from src/background/usecases/CommandUseCase.js rename to src/background/usecases/CommandUseCase.ts diff --git a/src/background/usecases/CompletionsUseCase.js b/src/background/usecases/CompletionsUseCase.ts similarity index 100% rename from src/background/usecases/CompletionsUseCase.js rename to src/background/usecases/CompletionsUseCase.ts diff --git a/src/background/usecases/ConsoleUseCase.js b/src/background/usecases/ConsoleUseCase.ts similarity index 100% rename from src/background/usecases/ConsoleUseCase.js rename to src/background/usecases/ConsoleUseCase.ts diff --git a/src/background/usecases/FindUseCase.js b/src/background/usecases/FindUseCase.ts similarity index 100% rename from src/background/usecases/FindUseCase.js rename to src/background/usecases/FindUseCase.ts diff --git a/src/background/usecases/LinkUseCase.js b/src/background/usecases/LinkUseCase.ts similarity index 100% rename from src/background/usecases/LinkUseCase.js rename to src/background/usecases/LinkUseCase.ts diff --git a/src/background/usecases/MarkUseCase.js b/src/background/usecases/MarkUseCase.ts similarity index 100% rename from src/background/usecases/MarkUseCase.js rename to src/background/usecases/MarkUseCase.ts diff --git a/src/background/usecases/SettingUseCase.js b/src/background/usecases/SettingUseCase.ts similarity index 100% rename from src/background/usecases/SettingUseCase.js rename to src/background/usecases/SettingUseCase.ts diff --git a/src/background/usecases/TabSelectUseCase.js b/src/background/usecases/TabSelectUseCase.ts similarity index 100% rename from src/background/usecases/TabSelectUseCase.js rename to src/background/usecases/TabSelectUseCase.ts diff --git a/src/background/usecases/TabUseCase.js b/src/background/usecases/TabUseCase.ts similarity index 100% rename from src/background/usecases/TabUseCase.js rename to src/background/usecases/TabUseCase.ts diff --git a/src/background/usecases/VersionUseCase.js b/src/background/usecases/VersionUseCase.ts similarity index 100% rename from src/background/usecases/VersionUseCase.js rename to src/background/usecases/VersionUseCase.ts diff --git a/src/background/usecases/ZoomUseCase.js b/src/background/usecases/ZoomUseCase.ts similarity index 100% rename from src/background/usecases/ZoomUseCase.js rename to src/background/usecases/ZoomUseCase.ts diff --git a/src/background/usecases/filters.js b/src/background/usecases/filters.ts similarity index 100% rename from src/background/usecases/filters.js rename to src/background/usecases/filters.ts diff --git a/src/background/usecases/parsers.js b/src/background/usecases/parsers.ts similarity index 100% rename from src/background/usecases/parsers.js rename to src/background/usecases/parsers.ts diff --git a/src/console/actions/console.js b/src/console/actions/console.ts similarity index 100% rename from src/console/actions/console.js rename to src/console/actions/console.ts diff --git a/src/console/actions/index.js b/src/console/actions/index.ts similarity index 100% rename from src/console/actions/index.js rename to src/console/actions/index.ts diff --git a/src/console/components/Console.jsx b/src/console/components/Console.tsx similarity index 100% rename from src/console/components/Console.jsx rename to src/console/components/Console.tsx diff --git a/src/console/components/console/Completion.jsx b/src/console/components/console/Completion.tsx similarity index 100% rename from src/console/components/console/Completion.jsx rename to src/console/components/console/Completion.tsx diff --git a/src/console/components/console/CompletionItem.jsx b/src/console/components/console/CompletionItem.tsx similarity index 100% rename from src/console/components/console/CompletionItem.jsx rename to src/console/components/console/CompletionItem.tsx diff --git a/src/console/components/console/CompletionTitle.jsx b/src/console/components/console/CompletionTitle.tsx similarity index 100% rename from src/console/components/console/CompletionTitle.jsx rename to src/console/components/console/CompletionTitle.tsx diff --git a/src/console/components/console/Input.jsx b/src/console/components/console/Input.tsx similarity index 100% rename from src/console/components/console/Input.jsx rename to src/console/components/console/Input.tsx diff --git a/src/console/components/console/Message.jsx b/src/console/components/console/Message.tsx similarity index 100% rename from src/console/components/console/Message.jsx rename to src/console/components/console/Message.tsx diff --git a/src/console/index.jsx b/src/console/index.tsx similarity index 100% rename from src/console/index.jsx rename to src/console/index.tsx diff --git a/src/console/reducers/index.js b/src/console/reducers/index.ts similarity index 100% rename from src/console/reducers/index.js rename to src/console/reducers/index.ts diff --git a/src/content/actions/addon.js b/src/content/actions/addon.ts similarity index 100% rename from src/content/actions/addon.js rename to src/content/actions/addon.ts diff --git a/src/content/actions/find.js b/src/content/actions/find.ts similarity index 100% rename from src/content/actions/find.js rename to src/content/actions/find.ts diff --git a/src/content/actions/follow-controller.js b/src/content/actions/follow-controller.ts similarity index 100% rename from src/content/actions/follow-controller.js rename to src/content/actions/follow-controller.ts diff --git a/src/content/actions/index.js b/src/content/actions/index.ts similarity index 100% rename from src/content/actions/index.js rename to src/content/actions/index.ts diff --git a/src/content/actions/input.js b/src/content/actions/input.ts similarity index 100% rename from src/content/actions/input.js rename to src/content/actions/input.ts diff --git a/src/content/actions/mark.js b/src/content/actions/mark.ts similarity index 100% rename from src/content/actions/mark.js rename to src/content/actions/mark.ts diff --git a/src/content/actions/operation.js b/src/content/actions/operation.ts similarity index 100% rename from src/content/actions/operation.js rename to src/content/actions/operation.ts diff --git a/src/content/actions/setting.js b/src/content/actions/setting.ts similarity index 100% rename from src/content/actions/setting.js rename to src/content/actions/setting.ts diff --git a/src/content/components/common/follow.js b/src/content/components/common/follow.ts similarity index 100% rename from src/content/components/common/follow.js rename to src/content/components/common/follow.ts diff --git a/src/content/components/common/hint.js b/src/content/components/common/hint.ts similarity index 100% rename from src/content/components/common/hint.js rename to src/content/components/common/hint.ts diff --git a/src/content/components/common/index.js b/src/content/components/common/index.ts similarity index 100% rename from src/content/components/common/index.js rename to src/content/components/common/index.ts diff --git a/src/content/components/common/input.js b/src/content/components/common/input.ts similarity index 100% rename from src/content/components/common/input.js rename to src/content/components/common/input.ts diff --git a/src/content/components/common/keymapper.js b/src/content/components/common/keymapper.ts similarity index 100% rename from src/content/components/common/keymapper.js rename to src/content/components/common/keymapper.ts diff --git a/src/content/components/common/mark.js b/src/content/components/common/mark.ts similarity index 100% rename from src/content/components/common/mark.js rename to src/content/components/common/mark.ts diff --git a/src/content/components/frame-content.js b/src/content/components/frame-content.ts similarity index 100% rename from src/content/components/frame-content.js rename to src/content/components/frame-content.ts diff --git a/src/content/components/top-content/find.js b/src/content/components/top-content/find.ts similarity index 100% rename from src/content/components/top-content/find.js rename to src/content/components/top-content/find.ts diff --git a/src/content/components/top-content/follow-controller.js b/src/content/components/top-content/follow-controller.ts similarity index 100% rename from src/content/components/top-content/follow-controller.js rename to src/content/components/top-content/follow-controller.ts diff --git a/src/content/components/top-content/index.js b/src/content/components/top-content/index.ts similarity index 100% rename from src/content/components/top-content/index.js rename to src/content/components/top-content/index.ts diff --git a/src/content/console-frames.js b/src/content/console-frames.ts similarity index 100% rename from src/content/console-frames.js rename to src/content/console-frames.ts diff --git a/src/content/focuses.js b/src/content/focuses.ts similarity index 100% rename from src/content/focuses.js rename to src/content/focuses.ts diff --git a/src/content/hint-key-producer.js b/src/content/hint-key-producer.ts similarity index 100% rename from src/content/hint-key-producer.js rename to src/content/hint-key-producer.ts diff --git a/src/content/index.js b/src/content/index.ts similarity index 100% rename from src/content/index.js rename to src/content/index.ts diff --git a/src/content/navigates.js b/src/content/navigates.ts similarity index 100% rename from src/content/navigates.js rename to src/content/navigates.ts diff --git a/src/content/reducers/addon.js b/src/content/reducers/addon.ts similarity index 100% rename from src/content/reducers/addon.js rename to src/content/reducers/addon.ts diff --git a/src/content/reducers/find.js b/src/content/reducers/find.ts similarity index 100% rename from src/content/reducers/find.js rename to src/content/reducers/find.ts diff --git a/src/content/reducers/follow-controller.js b/src/content/reducers/follow-controller.ts similarity index 100% rename from src/content/reducers/follow-controller.js rename to src/content/reducers/follow-controller.ts diff --git a/src/content/reducers/index.js b/src/content/reducers/index.ts similarity index 100% rename from src/content/reducers/index.js rename to src/content/reducers/index.ts diff --git a/src/content/reducers/input.js b/src/content/reducers/input.ts similarity index 100% rename from src/content/reducers/input.js rename to src/content/reducers/input.ts diff --git a/src/content/reducers/mark.js b/src/content/reducers/mark.ts similarity index 100% rename from src/content/reducers/mark.js rename to src/content/reducers/mark.ts diff --git a/src/content/reducers/setting.js b/src/content/reducers/setting.ts similarity index 100% rename from src/content/reducers/setting.js rename to src/content/reducers/setting.ts diff --git a/src/content/scrolls.js b/src/content/scrolls.ts similarity index 100% rename from src/content/scrolls.js rename to src/content/scrolls.ts diff --git a/src/content/site-style.js b/src/content/site-style.ts similarity index 100% rename from src/content/site-style.js rename to src/content/site-style.ts diff --git a/src/content/urls.js b/src/content/urls.ts similarity index 100% rename from src/content/urls.js rename to src/content/urls.ts diff --git a/src/settings/actions/index.js b/src/settings/actions/index.ts similarity index 100% rename from src/settings/actions/index.js rename to src/settings/actions/index.ts diff --git a/src/settings/actions/setting.js b/src/settings/actions/setting.ts similarity index 100% rename from src/settings/actions/setting.js rename to src/settings/actions/setting.ts diff --git a/src/settings/components/form/BlacklistForm.jsx b/src/settings/components/form/BlacklistForm.tsx similarity index 100% rename from src/settings/components/form/BlacklistForm.jsx rename to src/settings/components/form/BlacklistForm.tsx diff --git a/src/settings/components/form/KeymapsForm.jsx b/src/settings/components/form/KeymapsForm.tsx similarity index 100% rename from src/settings/components/form/KeymapsForm.jsx rename to src/settings/components/form/KeymapsForm.tsx diff --git a/src/settings/components/form/PropertiesForm.jsx b/src/settings/components/form/PropertiesForm.tsx similarity index 100% rename from src/settings/components/form/PropertiesForm.jsx rename to src/settings/components/form/PropertiesForm.tsx diff --git a/src/settings/components/form/SearchForm.jsx b/src/settings/components/form/SearchForm.tsx similarity index 100% rename from src/settings/components/form/SearchForm.jsx rename to src/settings/components/form/SearchForm.tsx diff --git a/src/settings/components/index.jsx b/src/settings/components/index.tsx similarity index 100% rename from src/settings/components/index.jsx rename to src/settings/components/index.tsx diff --git a/src/settings/components/ui/AddButton.jsx b/src/settings/components/ui/AddButton.tsx similarity index 100% rename from src/settings/components/ui/AddButton.jsx rename to src/settings/components/ui/AddButton.tsx diff --git a/src/settings/components/ui/DeleteButton.jsx b/src/settings/components/ui/DeleteButton.tsx similarity index 100% rename from src/settings/components/ui/DeleteButton.jsx rename to src/settings/components/ui/DeleteButton.tsx diff --git a/src/settings/components/ui/Input.jsx b/src/settings/components/ui/Input.tsx similarity index 100% rename from src/settings/components/ui/Input.jsx rename to src/settings/components/ui/Input.tsx diff --git a/src/settings/index.jsx b/src/settings/index.tsx similarity index 100% rename from src/settings/index.jsx rename to src/settings/index.tsx diff --git a/src/settings/keymaps.js b/src/settings/keymaps.ts similarity index 100% rename from src/settings/keymaps.js rename to src/settings/keymaps.ts diff --git a/src/settings/reducers/setting.js b/src/settings/reducers/setting.ts similarity index 100% rename from src/settings/reducers/setting.js rename to src/settings/reducers/setting.ts diff --git a/src/shared/blacklists.js b/src/shared/blacklists.ts similarity index 100% rename from src/shared/blacklists.js rename to src/shared/blacklists.ts diff --git a/src/shared/messages.js b/src/shared/messages.ts similarity index 100% rename from src/shared/messages.js rename to src/shared/messages.ts diff --git a/src/shared/operations.js b/src/shared/operations.ts similarity index 100% rename from src/shared/operations.js rename to src/shared/operations.ts diff --git a/src/shared/settings/default.js b/src/shared/settings/default.ts similarity index 100% rename from src/shared/settings/default.js rename to src/shared/settings/default.ts diff --git a/src/shared/settings/properties.js b/src/shared/settings/properties.ts similarity index 100% rename from src/shared/settings/properties.js rename to src/shared/settings/properties.ts diff --git a/src/shared/settings/storage.js b/src/shared/settings/storage.ts similarity index 100% rename from src/shared/settings/storage.js rename to src/shared/settings/storage.ts diff --git a/src/shared/settings/validator.js b/src/shared/settings/validator.ts similarity index 100% rename from src/shared/settings/validator.js rename to src/shared/settings/validator.ts diff --git a/src/shared/settings/values.js b/src/shared/settings/values.ts similarity index 100% rename from src/shared/settings/values.js rename to src/shared/settings/values.ts diff --git a/src/shared/urls.js b/src/shared/urls.ts similarity index 100% rename from src/shared/urls.js rename to src/shared/urls.ts diff --git a/src/shared/utils/dom.js b/src/shared/utils/dom.ts similarity index 100% rename from src/shared/utils/dom.js rename to src/shared/utils/dom.ts diff --git a/src/shared/utils/keys.js b/src/shared/utils/keys.ts similarity index 100% rename from src/shared/utils/keys.js rename to src/shared/utils/keys.ts diff --git a/src/shared/utils/re.js b/src/shared/utils/re.ts similarity index 100% rename from src/shared/utils/re.js rename to src/shared/utils/re.ts diff --git a/test/background/domains/GlobalMark.test.js b/test/background/domains/GlobalMark.test.ts similarity index 100% rename from test/background/domains/GlobalMark.test.js rename to test/background/domains/GlobalMark.test.ts diff --git a/test/background/infrastructures/MemoryStorage.test.js b/test/background/infrastructures/MemoryStorage.test.ts similarity index 100% rename from test/background/infrastructures/MemoryStorage.test.js rename to test/background/infrastructures/MemoryStorage.test.ts diff --git a/test/background/repositories/Mark.test.js b/test/background/repositories/Mark.test.ts similarity index 100% rename from test/background/repositories/Mark.test.js rename to test/background/repositories/Mark.test.ts diff --git a/test/background/repositories/Version.js b/test/background/repositories/Version.ts similarity index 100% rename from test/background/repositories/Version.js rename to test/background/repositories/Version.ts diff --git a/test/background/usecases/filters.test.js b/test/background/usecases/filters.test.ts similarity index 100% rename from test/background/usecases/filters.test.js rename to test/background/usecases/filters.test.ts diff --git a/test/background/usecases/parsers.test.js b/test/background/usecases/parsers.test.ts similarity index 100% rename from test/background/usecases/parsers.test.js rename to test/background/usecases/parsers.test.ts diff --git a/test/console/actions/console.test.js b/test/console/actions/console.test.ts similarity index 100% rename from test/console/actions/console.test.js rename to test/console/actions/console.test.ts diff --git a/test/console/components/console/Completion.test.jsx b/test/console/components/console/Completion.test.tsx similarity index 100% rename from test/console/components/console/Completion.test.jsx rename to test/console/components/console/Completion.test.tsx diff --git a/test/console/reducers/console.test.js b/test/console/reducers/console.test.ts similarity index 100% rename from test/console/reducers/console.test.js rename to test/console/reducers/console.test.ts diff --git a/test/content/actions/follow-controller.test.js b/test/content/actions/follow-controller.test.ts similarity index 100% rename from test/content/actions/follow-controller.test.js rename to test/content/actions/follow-controller.test.ts diff --git a/test/content/actions/input.test.js b/test/content/actions/input.test.ts similarity index 100% rename from test/content/actions/input.test.js rename to test/content/actions/input.test.ts diff --git a/test/content/actions/mark.test.js b/test/content/actions/mark.test.ts similarity index 100% rename from test/content/actions/mark.test.js rename to test/content/actions/mark.test.ts diff --git a/test/content/actions/setting.test.js b/test/content/actions/setting.test.ts similarity index 100% rename from test/content/actions/setting.test.js rename to test/content/actions/setting.test.ts diff --git a/test/content/components/common/follow.test.js b/test/content/components/common/follow.test.ts similarity index 100% rename from test/content/components/common/follow.test.js rename to test/content/components/common/follow.test.ts diff --git a/test/content/components/common/hint.test.js b/test/content/components/common/hint.test.ts similarity index 100% rename from test/content/components/common/hint.test.js rename to test/content/components/common/hint.test.ts diff --git a/test/content/components/common/input.test.js b/test/content/components/common/input.test.ts similarity index 100% rename from test/content/components/common/input.test.js rename to test/content/components/common/input.test.ts diff --git a/test/content/hint-key-producer.test.js b/test/content/hint-key-producer.test.ts similarity index 100% rename from test/content/hint-key-producer.test.js rename to test/content/hint-key-producer.test.ts diff --git a/test/content/navigates.test.js b/test/content/navigates.test.ts similarity index 100% rename from test/content/navigates.test.js rename to test/content/navigates.test.ts diff --git a/test/content/reducers/addon.test.js b/test/content/reducers/addon.test.ts similarity index 100% rename from test/content/reducers/addon.test.js rename to test/content/reducers/addon.test.ts diff --git a/test/content/reducers/find.test.js b/test/content/reducers/find.test.ts similarity index 100% rename from test/content/reducers/find.test.js rename to test/content/reducers/find.test.ts diff --git a/test/content/reducers/follow-controller.test.js b/test/content/reducers/follow-controller.test.ts similarity index 100% rename from test/content/reducers/follow-controller.test.js rename to test/content/reducers/follow-controller.test.ts diff --git a/test/content/reducers/input.test.js b/test/content/reducers/input.test.ts similarity index 100% rename from test/content/reducers/input.test.js rename to test/content/reducers/input.test.ts diff --git a/test/content/reducers/mark.test.js b/test/content/reducers/mark.test.ts similarity index 100% rename from test/content/reducers/mark.test.js rename to test/content/reducers/mark.test.ts diff --git a/test/content/reducers/setting.test.js b/test/content/reducers/setting.test.ts similarity index 100% rename from test/content/reducers/setting.test.js rename to test/content/reducers/setting.test.ts diff --git a/test/main.js b/test/main.ts similarity index 100% rename from test/main.js rename to test/main.ts diff --git a/test/settings/components/form/BlacklistForm.test.jsx b/test/settings/components/form/BlacklistForm.test.tsx similarity index 100% rename from test/settings/components/form/BlacklistForm.test.jsx rename to test/settings/components/form/BlacklistForm.test.tsx diff --git a/test/settings/components/form/KeymapsForm.test.jsx b/test/settings/components/form/KeymapsForm.test.tsx similarity index 100% rename from test/settings/components/form/KeymapsForm.test.jsx rename to test/settings/components/form/KeymapsForm.test.tsx diff --git a/test/settings/components/form/PropertiesForm.test.jsx b/test/settings/components/form/PropertiesForm.test.tsx similarity index 100% rename from test/settings/components/form/PropertiesForm.test.jsx rename to test/settings/components/form/PropertiesForm.test.tsx diff --git a/test/settings/components/form/SearchEngineForm.test.jsx b/test/settings/components/form/SearchEngineForm.test.tsx similarity index 100% rename from test/settings/components/form/SearchEngineForm.test.jsx rename to test/settings/components/form/SearchEngineForm.test.tsx diff --git a/test/settings/components/ui/input.test.jsx b/test/settings/components/ui/input.test.tsx similarity index 100% rename from test/settings/components/ui/input.test.jsx rename to test/settings/components/ui/input.test.tsx diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.ts similarity index 100% rename from test/settings/reducers/setting.test.js rename to test/settings/reducers/setting.test.ts diff --git a/test/shared/blacklists.test.js b/test/shared/blacklists.test.ts similarity index 100% rename from test/shared/blacklists.test.js rename to test/shared/blacklists.test.ts diff --git a/test/shared/settings/validator.test.js b/test/shared/settings/validator.test.ts similarity index 100% rename from test/shared/settings/validator.test.js rename to test/shared/settings/validator.test.ts diff --git a/test/shared/settings/values.test.js b/test/shared/settings/values.test.ts similarity index 100% rename from test/shared/settings/values.test.js rename to test/shared/settings/values.test.ts diff --git a/test/shared/urls.test.js b/test/shared/urls.test.ts similarity index 100% rename from test/shared/urls.test.js rename to test/shared/urls.test.ts diff --git a/test/shared/utils/keys.test.js b/test/shared/utils/keys.test.ts similarity index 100% rename from test/shared/utils/keys.test.js rename to test/shared/utils/keys.test.ts diff --git a/test/shared/utils/re.test.js b/test/shared/utils/re.test.ts similarity index 100% rename from test/shared/utils/re.test.js rename to test/shared/utils/re.test.ts From 194edb1f731b17fb823449d0c401d6a056771ab7 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 21:44:09 +0900 Subject: [PATCH 09/24] Install karma-babel-preprocessor --- package-lock.json | 6 ++++++ package.json | 1 + 2 files changed, 7 insertions(+) diff --git a/package-lock.json b/package-lock.json index 3e15f83..376b476 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6200,6 +6200,12 @@ } } }, + "karma-babel-preprocessor": { + "version": "8.0.0-beta.0", + "resolved": "https://registry.npmjs.org/karma-babel-preprocessor/-/karma-babel-preprocessor-8.0.0-beta.0.tgz", + "integrity": "sha512-nv3GbDAKdonWuTJc+Kg4jEdRXzoP7uKKQ6HfTJb5PNTY+OJYKzrtUBUSez/wrutUFtztVT+MQxJHamd7MNCmBQ==", + "dev": true + }, "karma-firefox-launcher": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/karma-firefox-launcher/-/karma-firefox-launcher-1.1.0.tgz", diff --git a/package.json b/package.json index 590504b..9adf163 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "html-webpack-plugin": "^3.2.0", "jszip": "^3.2.1", "karma": "^4.1.0", + "karma-babel-preprocessor": "^8.0.0-beta.0", "karma-firefox-launcher": "^1.1.0", "karma-html2js-preprocessor": "^1.1.0", "karma-mocha": "^1.3.0", From 2b8c37e57f1b55dcb562ccf9141ae29bac0e370a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 21:50:32 +0900 Subject: [PATCH 10/24] Configure karma.conf --- karma.conf.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 32da469..b422605 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,16 +6,16 @@ module.exports = function (config) { basePath: '', frameworks: ['mocha', 'sinon'], files: [ - 'test/main.js', - 'test/**/*.test.js', - 'test/**/*.test.jsx', + 'test/main.ts', + 'test/**/*.test.ts', + 'test/**/*.test.tsx', 'test/**/*.html' ], preprocessors: { - 'test/main.js': [ 'webpack', 'sourcemap' ], - 'test/**/*.test.js': [ 'webpack', 'sourcemap' ], - 'test/**/*.test.jsx': [ 'webpack', 'sourcemap' ], + 'test/main.ts': [ 'webpack', 'sourcemap' ], + 'test/**/*.test.ts': [ 'webpack', 'sourcemap' ], + 'test/**/*.test.tsx': [ 'webpack', 'sourcemap' ], 'test/**/*.html': ['html2js'] }, From 0cffb09e249832291be73be039dc1b9bb38115f9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Tue, 30 Apr 2019 21:50:46 +0900 Subject: [PATCH 11/24] Types on src/share --- src/shared/blacklists.ts | 4 +-- src/shared/messages.ts | 15 ++++++++--- src/shared/operations.ts | 4 ++- src/shared/settings/properties.ts | 6 ++--- src/shared/settings/storage.ts | 6 ++--- src/shared/settings/validator.ts | 12 ++++----- src/shared/settings/values.ts | 24 +++++++++--------- src/shared/urls.ts | 6 ++--- src/shared/utils/dom.ts | 41 +++++++++++++++++++++---------- src/shared/utils/keys.ts | 22 ++++++++++++----- src/shared/utils/re.ts | 2 +- 11 files changed, 88 insertions(+), 54 deletions(-) diff --git a/src/shared/blacklists.ts b/src/shared/blacklists.ts index 61720c3..61ee4de 100644 --- a/src/shared/blacklists.ts +++ b/src/shared/blacklists.ts @@ -1,6 +1,6 @@ -import * as re from 'shared/utils/re'; +import * as re from './utils/re'; -const includes = (blacklist, url) => { +const includes = (blacklist: string[], url: string): boolean => { let u = new URL(url); return blacklist.some((item) => { if (!item.includes('/')) { diff --git a/src/shared/messages.ts b/src/shared/messages.ts index ddf3368..2bc12d8 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -1,5 +1,8 @@ -const onWebMessage = (listener) => { - window.addEventListener('message', (event) => { +type WebMessageSender = Window | MessagePort | ServiceWorker | null; +type WebMessageListener = (msg: any, sender: WebMessageSender | null) => void; + +const onWebMessage = (listener: WebMessageListener) => { + window.addEventListener('message', (event: MessageEvent) => { let sender = event.source; let message = null; try { @@ -12,11 +15,15 @@ const onWebMessage = (listener) => { }); }; -const onBackgroundMessage = (listener) => { +const onBackgroundMessage = ( + listener: (msg: any, sender: browser.runtime.MessageSender, +) => void) => { browser.runtime.onMessage.addListener(listener); }; -const onMessage = (listener) => { +const onMessage = ( + listener: (msg: any, sender: WebMessageSender | browser.runtime.MessageSender, +) => void) => { onWebMessage(listener); onBackgroundMessage(listener); }; diff --git a/src/shared/operations.ts b/src/shared/operations.ts index 8674f4d..d59723e 100644 --- a/src/shared/operations.ts +++ b/src/shared/operations.ts @@ -1,4 +1,4 @@ -export default { +const operations: { [key: string]: string } = { // Hide console, or cancel some user actions CANCEL: 'cancel', @@ -76,3 +76,5 @@ export default { MARK_SET_PREFIX: 'mark.set.prefix', MARK_JUMP_PREFIX: 'mark.jump.prefix', }; + +export default operations; diff --git a/src/shared/settings/properties.ts b/src/shared/settings/properties.ts index f8e61a0..7d037df 100644 --- a/src/shared/settings/properties.ts +++ b/src/shared/settings/properties.ts @@ -2,20 +2,20 @@ // mystr: 'string', // mynum: 'number', // mybool: 'boolean', -const types = { +const types: { [key: string]: string } = { hintchars: 'string', smoothscroll: 'boolean', complete: 'string', }; // describe default values of a property -const defaults = { +const defaults: { [key: string]: string | number | boolean } = { hintchars: 'abcdefghijklmnopqrstuvwxyz', smoothscroll: false, complete: 'sbh', }; -const docs = { +const docs: { [key: string]: string } = { hintchars: 'hint characters on follow mode', smoothscroll: 'smooth scroll', complete: 'which are completed at the open page', diff --git a/src/shared/settings/storage.ts b/src/shared/settings/storage.ts index 5dce3b0..90a3a66 100644 --- a/src/shared/settings/storage.ts +++ b/src/shared/settings/storage.ts @@ -1,12 +1,12 @@ import DefaultSettings from './default'; import * as settingsValues from './values'; -const loadRaw = async() => { +const loadRaw = async(): Promise => { let { settings } = await browser.storage.local.get('settings'); if (!settings) { return DefaultSettings; } - return { ...DefaultSettings, ...settings }; + return { ...DefaultSettings, ...settings as object }; }; const loadValue = async() => { @@ -23,7 +23,7 @@ const loadValue = async() => { return { ...settingsValues.valueFromJson(DefaultSettings.json), ...value }; }; -const save = (settings) => { +const save = (settings: any): Promise => { return browser.storage.local.set({ settings, }); diff --git a/src/shared/settings/validator.ts b/src/shared/settings/validator.ts index a800a52..0483931 100644 --- a/src/shared/settings/validator.ts +++ b/src/shared/settings/validator.ts @@ -1,4 +1,4 @@ -import operations from 'shared/operations'; +import operations from '../operations'; import * as properties from './properties'; const VALID_TOP_KEYS = ['keymaps', 'search', 'blacklist', 'properties']; @@ -6,7 +6,7 @@ const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => { return operations[key]; }); -const validateInvalidTopKeys = (settings) => { +const validateInvalidTopKeys = (settings: any): void => { let invalidKey = Object.keys(settings).find((key) => { return !VALID_TOP_KEYS.includes(key); }); @@ -15,7 +15,7 @@ const validateInvalidTopKeys = (settings) => { } }; -const validateKeymaps = (keymaps) => { +const validateKeymaps = (keymaps: any): void => { for (let key of Object.keys(keymaps)) { let value = keymaps[key]; if (!VALID_OPERATION_VALUES.includes(value.type)) { @@ -24,7 +24,7 @@ const validateKeymaps = (keymaps) => { } }; -const validateSearch = (search) => { +const validateSearch = (search: any): void => { let engines = search.engines; for (let key of Object.keys(engines)) { if ((/\s/).test(key)) { @@ -49,7 +49,7 @@ const validateSearch = (search) => { } }; -const validateProperties = (props) => { +const validateProperties = (props: any): void => { for (let name of Object.keys(props)) { if (!properties.types[name]) { throw new Error(`Unknown property name: "${name}"`); @@ -60,7 +60,7 @@ const validateProperties = (props) => { } }; -const validate = (settings) => { +const validate = (settings: any): void => { validateInvalidTopKeys(settings); if (settings.keymaps) { validateKeymaps(settings.keymaps); diff --git a/src/shared/settings/values.ts b/src/shared/settings/values.ts index 9828af6..cb6a668 100644 --- a/src/shared/settings/values.ts +++ b/src/shared/settings/values.ts @@ -1,6 +1,6 @@ import * as properties from './properties'; -const operationFromFormName = (name) => { +const operationFromFormName = (name: string): any => { let [type, argStr] = name.split('?'); let args = {}; if (argStr) { @@ -9,7 +9,7 @@ const operationFromFormName = (name) => { return { type, ...args }; }; -const operationToFormName = (op) => { +const operationToFormName = (op: any): string => { let type = op.type; let args = { ...op }; delete args.type; @@ -20,12 +20,12 @@ const operationToFormName = (op) => { return op.type + '?' + JSON.stringify(args); }; -const valueFromJson = (json) => { +const valueFromJson = (json: string): object => { return JSON.parse(json); }; -const valueFromForm = (form) => { - let keymaps = undefined; +const valueFromForm = (form: any): object => { + let keymaps: any = undefined; if (form.keymaps) { keymaps = {}; for (let name of Object.keys(form.keymaps)) { @@ -34,7 +34,7 @@ const valueFromForm = (form) => { } } - let search = undefined; + let search: any = undefined; if (form.search) { search = { default: form.search.default }; @@ -54,12 +54,12 @@ const valueFromForm = (form) => { }; }; -const jsonFromValue = (value) => { +const jsonFromValue = (value: any): string => { return JSON.stringify(value, undefined, 2); }; -const formFromValue = (value, allowedOps) => { - let keymaps = undefined; +const formFromValue = (value: any, allowedOps: any[]): any => { + let keymaps: any = undefined; if (value.keymaps) { let allowedSet = new Set(allowedOps); @@ -73,7 +73,7 @@ const formFromValue = (value, allowedOps) => { } } - let search = undefined; + let search: any = undefined; if (value.search) { search = { default: value.search.default }; if (value.search.engines) { @@ -93,11 +93,11 @@ const formFromValue = (value, allowedOps) => { }; }; -const jsonFromForm = (form) => { +const jsonFromForm = (form: any): string => { return jsonFromValue(valueFromForm(form)); }; -const formFromJson = (json, allowedOps) => { +const formFromJson = (json: string, allowedOps: any[]): any => { let value = valueFromJson(json); return formFromValue(value, allowedOps); }; diff --git a/src/shared/urls.ts b/src/shared/urls.ts index 94b1220..18349c8 100644 --- a/src/shared/urls.ts +++ b/src/shared/urls.ts @@ -1,11 +1,11 @@ -const trimStart = (str) => { +const trimStart = (str: string): string => { // NOTE String.trimStart is available on Firefox 61 return str.replace(/^\s+/, ''); }; const SUPPORTED_PROTOCOLS = ['http:', 'https:', 'ftp:', 'mailto:', 'about:']; -const searchUrl = (keywords, searchSettings) => { +const searchUrl = (keywords: string, searchSettings: any): string => { try { let u = new URL(keywords); if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { @@ -28,7 +28,7 @@ const searchUrl = (keywords, searchSettings) => { return template.replace('{}', encodeURIComponent(query)); }; -const normalizeUrl = (url) => { +const normalizeUrl = (url: string): string => { try { let u = new URL(url); if (SUPPORTED_PROTOCOLS.includes(u.protocol.toLowerCase())) { diff --git a/src/shared/utils/dom.ts b/src/shared/utils/dom.ts index 974d534..c1f2190 100644 --- a/src/shared/utils/dom.ts +++ b/src/shared/utils/dom.ts @@ -1,16 +1,24 @@ -const isContentEditable = (element) => { - return element.hasAttribute('contenteditable') && ( - element.getAttribute('contenteditable').toLowerCase() === 'true' || - element.getAttribute('contenteditable').toLowerCase() === '' - ); +const isContentEditable = (element: Element): boolean => { + let value = element.getAttribute('contenteditable'); + if (value === null) { + return false; + } + return value.toLowerCase() === 'true' || value.toLowerCase() === ''; }; -const rectangleCoordsRect = (coords) => { +interface Rect { + left: number; + top: number; + right: number; + bottom: number; +} + +const rectangleCoordsRect = (coords: string): Rect => { let [left, top, right, bottom] = coords.split(',').map(n => Number(n)); return { left, top, right, bottom }; }; -const circleCoordsRect = (coords) => { +const circleCoordsRect = (coords: string): Rect => { let [x, y, r] = coords.split(',').map(n => Number(n)); return { left: x - r, @@ -20,7 +28,7 @@ const circleCoordsRect = (coords) => { }; }; -const polygonCoordsRect = (coords) => { +const polygonCoordsRect = (coords: string): Rect => { let params = coords.split(','); let minx = Number(params[0]), maxx = Number(params[0]), @@ -46,18 +54,24 @@ const polygonCoordsRect = (coords) => { return { left: minx, top: miny, right: maxx, bottom: maxy }; }; -const viewportRect = (e) => { +const viewportRect = (e: Element): Rect => { if (e.tagName !== 'AREA') { return e.getBoundingClientRect(); } - let mapElement = e.parentNode; - let imgElement = document.querySelector(`img[usemap="#${mapElement.name}"]`); + let mapElement = e.parentNode as HTMLMapElement; + let imgElement = document.querySelector( + `img[usemap="#${mapElement.name}"]` + ) as HTMLImageElement; let { left: mapLeft, top: mapTop } = imgElement.getBoundingClientRect(); let coords = e.getAttribute('coords'); + if (!coords) { + return e.getBoundingClientRect(); + } + let rect = { left: 0, top: 0, right: 0, bottom: 0 }; switch (e.getAttribute('shape')) { case 'rect': @@ -81,7 +95,7 @@ const viewportRect = (e) => { }; }; -const isVisible = (element) => { +const isVisible = (element: Element): boolean => { let rect = element.getBoundingClientRect(); let style = window.getComputedStyle(element); @@ -94,7 +108,8 @@ const isVisible = (element) => { if (window.innerWidth < rect.left && window.innerHeight < rect.top) { return false; } - if (element.nodeName === 'INPUT' && element.type.toLowerCase() === 'hidden') { + if (element instanceof HTMLInputElement && + element.type.toLowerCase() === 'hidden') { return false; } diff --git a/src/shared/utils/keys.ts b/src/shared/utils/keys.ts index f024069..d9abef7 100644 --- a/src/shared/utils/keys.ts +++ b/src/shared/utils/keys.ts @@ -1,4 +1,12 @@ -const modifiedKeyName = (name) => { +interface Key { + key: string; + shiftKey: boolean | undefined; + ctrlKey: boolean | undefined; + altKey: boolean | undefined; + metaKey: boolean | undefined; +} + +const modifiedKeyName = (name: string): string => { if (name === ' ') { return 'Space'; } @@ -10,7 +18,7 @@ const modifiedKeyName = (name) => { return name; }; -const fromKeyboardEvent = (e) => { +const fromKeyboardEvent = (e: KeyboardEvent): Key => { let key = modifiedKeyName(e.key); let shift = e.shiftKey; if (key.length === 1 && key.toUpperCase() === key.toLowerCase()) { @@ -28,7 +36,7 @@ const fromKeyboardEvent = (e) => { }; }; -const fromMapKey = (key) => { +const fromMapKey = (key: string): Key => { if (key.startsWith('<') && key.endsWith('>')) { let inner = key.slice(1, -1); let shift = inner.includes('S-'); @@ -55,8 +63,10 @@ const fromMapKey = (key) => { }; }; -const fromMapKeys = (keys) => { - const fromMapKeysRecursive = (remainings, mappedKeys) => { +const fromMapKeys = (keys: string): Key[] => { + const fromMapKeysRecursive = ( + remainings: string, mappedKeys: Key[], + ): Key[] => { if (remainings.length === 0) { return mappedKeys; } @@ -78,7 +88,7 @@ const fromMapKeys = (keys) => { return fromMapKeysRecursive(keys, []); }; -const equals = (e1, e2) => { +const equals = (e1: Key, e2: Key): boolean => { return e1.key === e2.key && e1.ctrlKey === e2.ctrlKey && e1.metaKey === e2.metaKey && diff --git a/src/shared/utils/re.ts b/src/shared/utils/re.ts index 7db9091..34f4fa6 100644 --- a/src/shared/utils/re.ts +++ b/src/shared/utils/re.ts @@ -1,4 +1,4 @@ -const fromWildcard = (pattern) => { +const fromWildcard = (pattern: string): RegExp => { let regexStr = '^' + pattern.replace(/\*/g, '.*') + '$'; return new RegExp(regexStr); }; From 678020a3a27713e77ec8d74483122b4258fbc829 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 1 May 2019 11:04:24 +0900 Subject: [PATCH 12/24] Types on src/background --- .../controllers/AddonEnabledController.ts | 4 +- .../controllers/CommandController.ts | 14 ++- src/background/controllers/FindController.ts | 6 +- src/background/controllers/LinkController.ts | 12 +- src/background/controllers/MarkController.ts | 10 +- .../controllers/OperationController.ts | 13 ++- .../controllers/SettingController.ts | 8 +- .../controllers/VersionController.ts | 6 +- src/background/controllers/version.ts | 13 --- src/background/domains/CommandDocs.ts | 3 +- src/background/domains/CompletionGroup.ts | 17 +-- src/background/domains/CompletionItem.ts | 29 +---- src/background/domains/Completions.ts | 27 ----- src/background/domains/GlobalMark.ts | 28 +---- .../infrastructures/ConsoleClient.ts | 10 +- .../infrastructures/ContentMessageClient.ts | 12 +- .../infrastructures/ContentMessageListener.ts | 78 +++++++++---- .../infrastructures/MemoryStorage.ts | 6 +- .../presenters/IndicatorPresenter.ts | 4 +- src/background/presenters/NotifyPresenter.ts | 8 +- src/background/presenters/TabPresenter.ts | 44 +++---- src/background/presenters/WindowPresenter.ts | 2 +- .../repositories/BookmarkRepository.ts | 4 +- .../repositories/BrowserSettingRepository.ts | 2 +- .../repositories/CompletionsRepository.ts | 14 ++- src/background/repositories/FindRepository.ts | 6 +- src/background/repositories/MarkRepository.ts | 8 +- .../PersistentSettingRepository.ts | 2 +- .../repositories/SettingRepository.ts | 8 +- .../repositories/VersionRepository.ts | 10 -- .../usecases/AddonEnabledUseCase.ts | 18 ++- src/background/usecases/CommandUseCase.ts | 52 +++++---- src/background/usecases/CompletionsUseCase.ts | 107 ++++++++++-------- src/background/usecases/ConsoleUseCase.ts | 40 ++++--- src/background/usecases/FindUseCase.ts | 14 ++- src/background/usecases/LinkUseCase.ts | 8 +- src/background/usecases/MarkUseCase.ts | 20 +++- src/background/usecases/SettingUseCase.ts | 8 +- src/background/usecases/TabSelectUseCase.ts | 24 ++-- src/background/usecases/TabUseCase.ts | 36 +++--- src/background/usecases/VersionUseCase.ts | 10 +- src/background/usecases/ZoomUseCase.ts | 26 +++-- src/background/usecases/filters.ts | 38 ++++--- src/background/usecases/parsers.ts | 10 +- src/content/scrolls.ts | 10 -- test/background/domains/GlobalMark.test.ts | 11 -- test/background/repositories/Mark.test.ts | 3 +- test/background/repositories/Version.ts | 34 ------ 48 files changed, 446 insertions(+), 431 deletions(-) delete mode 100644 src/background/controllers/version.ts delete mode 100644 src/background/domains/Completions.ts delete mode 100644 src/background/repositories/VersionRepository.ts delete mode 100644 test/background/domains/GlobalMark.test.ts delete mode 100644 test/background/repositories/Version.ts diff --git a/src/background/controllers/AddonEnabledController.ts b/src/background/controllers/AddonEnabledController.ts index 9a3a521..251af25 100644 --- a/src/background/controllers/AddonEnabledController.ts +++ b/src/background/controllers/AddonEnabledController.ts @@ -1,11 +1,13 @@ import AddonEnabledUseCase from '../usecases/AddonEnabledUseCase'; export default class AddonEnabledController { + private addonEnabledUseCase: AddonEnabledUseCase; + constructor() { this.addonEnabledUseCase = new AddonEnabledUseCase(); } - indicate(enabled) { + indicate(enabled: boolean): Promise { return this.addonEnabledUseCase.indicate(enabled); } } diff --git a/src/background/controllers/CommandController.ts b/src/background/controllers/CommandController.ts index b113709..f3a6b7f 100644 --- a/src/background/controllers/CommandController.ts +++ b/src/background/controllers/CommandController.ts @@ -1,19 +1,23 @@ import CompletionsUseCase from '../usecases/CompletionsUseCase'; import CommandUseCase from '../usecases/CommandUseCase'; -import Completions from '../domains/Completions'; +import CompletionGroup from '../domains/CompletionGroup'; -const trimStart = (str) => { +const trimStart = (str: string): string => { // NOTE String.trimStart is available on Firefox 61 return str.replace(/^\s+/, ''); }; export default class CommandController { + private completionsUseCase: CompletionsUseCase; + + private commandIndicator: CommandUseCase; + constructor() { this.completionsUseCase = new CompletionsUseCase(); this.commandIndicator = new CommandUseCase(); } - getCompletions(line) { + getCompletions(line: string): Promise { let trimmed = trimStart(line); let words = trimmed.split(/ +/); let name = words[0]; @@ -45,11 +49,11 @@ export default class CommandController { case 'set': return this.completionsUseCase.querySet(name, keywords); } - return Promise.resolve(Completions.empty()); + return Promise.resolve([]); } // eslint-disable-next-line complexity - exec(line) { + exec(line: string): Promise { let trimmed = trimStart(line); let words = trimmed.split(/ +/); let name = words[0]; diff --git a/src/background/controllers/FindController.ts b/src/background/controllers/FindController.ts index caeff98..28959e2 100644 --- a/src/background/controllers/FindController.ts +++ b/src/background/controllers/FindController.ts @@ -1,15 +1,17 @@ import FindUseCase from '../usecases/FindUseCase'; export default class FindController { + private findUseCase: FindUseCase; + constructor() { this.findUseCase = new FindUseCase(); } - getKeyword() { + getKeyword(): Promise { return this.findUseCase.getKeyword(); } - setKeyword(keyword) { + setKeyword(keyword: string): Promise { return this.findUseCase.setKeyword(keyword); } } diff --git a/src/background/controllers/LinkController.ts b/src/background/controllers/LinkController.ts index 7e395b1..707b28a 100644 --- a/src/background/controllers/LinkController.ts +++ b/src/background/controllers/LinkController.ts @@ -1,15 +1,19 @@ import LinkUseCase from '../usecases/LinkUseCase'; export default class LinkController { + private linkUseCase: LinkUseCase; + constructor() { this.linkUseCase = new LinkUseCase(); } - openToTab(url, tabId) { - this.linkUseCase.openToTab(url, tabId); + openToTab(url: string, tabId: number): Promise { + return this.linkUseCase.openToTab(url, tabId); } - openNewTab(url, openerId, background) { - this.linkUseCase.openNewTab(url, openerId, background); + openNewTab( + url: string, openerId: number, background: boolean, + ): Promise { + return this.linkUseCase.openNewTab(url, openerId, background); } } diff --git a/src/background/controllers/MarkController.ts b/src/background/controllers/MarkController.ts index 0478369..419a08b 100644 --- a/src/background/controllers/MarkController.ts +++ b/src/background/controllers/MarkController.ts @@ -1,15 +1,17 @@ import MarkUseCase from '../usecases/MarkUseCase'; export default class MarkController { + private markUseCase: MarkUseCase; + constructor() { this.markUseCase = new MarkUseCase(); } - setGlobal(key, x, y) { - this.markUseCase.setGlobal(key, x, y); + setGlobal(key: string, x: number, y: number): Promise { + return this.markUseCase.setGlobal(key, x, y); } - jumpGlobal(key) { - this.markUseCase.jumpGlobal(key); + jumpGlobal(key: string): Promise { + return this.markUseCase.jumpGlobal(key); } } diff --git a/src/background/controllers/OperationController.ts b/src/background/controllers/OperationController.ts index 416aa9c..4e9c106 100644 --- a/src/background/controllers/OperationController.ts +++ b/src/background/controllers/OperationController.ts @@ -6,6 +6,16 @@ import TabSelectUseCase from '../usecases/TabSelectUseCase'; import ZoomUseCase from '../usecases/ZoomUseCase'; export default class OperationController { + private findUseCase: FindUseCase; + + private consoleUseCase: ConsoleUseCase; + + private tabUseCase: TabUseCase; + + private tabSelectUseCase: TabSelectUseCase; + + private zoomUseCase: ZoomUseCase; + constructor() { this.findUseCase = new FindUseCase(); this.consoleUseCase = new ConsoleUseCase(); @@ -15,7 +25,7 @@ export default class OperationController { } // eslint-disable-next-line complexity, max-lines-per-function - exec(operation) { + exec(operation: any): Promise { switch (operation.type) { case operations.TAB_CLOSE: return this.tabUseCase.close(false); @@ -72,6 +82,7 @@ export default class OperationController { case operations.CANCEL: return this.consoleUseCase.hideConsole(); } + throw new Error('unknown operation: ' + operation.type); } } diff --git a/src/background/controllers/SettingController.ts b/src/background/controllers/SettingController.ts index e895d72..f8b7302 100644 --- a/src/background/controllers/SettingController.ts +++ b/src/background/controllers/SettingController.ts @@ -2,16 +2,20 @@ import SettingUseCase from '../usecases/SettingUseCase'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; export default class SettingController { + private settingUseCase: SettingUseCase; + + private contentMessageClient: ContentMessageClient; + constructor() { this.settingUseCase = new SettingUseCase(); this.contentMessageClient = new ContentMessageClient(); } - getSetting() { + getSetting(): any { return this.settingUseCase.get(); } - async reload() { + async reload(): Promise { await this.settingUseCase.reload(); this.contentMessageClient.broadcastSettingsChanged(); } diff --git a/src/background/controllers/VersionController.ts b/src/background/controllers/VersionController.ts index c596f9b..f402ed0 100644 --- a/src/background/controllers/VersionController.ts +++ b/src/background/controllers/VersionController.ts @@ -1,11 +1,13 @@ import VersionUseCase from '../usecases/VersionUseCase'; export default class VersionController { + private versionUseCase: VersionUseCase; + constructor() { this.versionUseCase = new VersionUseCase(); } - notify() { - this.versionUseCase.notify(); + notify(): void { + return this.versionUseCase.notify(); } } diff --git a/src/background/controllers/version.ts b/src/background/controllers/version.ts deleted file mode 100644 index ec0f634..0000000 --- a/src/background/controllers/version.ts +++ /dev/null @@ -1,13 +0,0 @@ -import VersionInteractor from '../usecases/version'; - -export default class VersionController { - constructor() { - this.versionInteractor = new VersionInteractor(); - } - - notifyIfUpdated() { - browser.runtime.onInstalled.addListener(() => { - return this.versionInteractor.notify(); - }); - } -} diff --git a/src/background/domains/CommandDocs.ts b/src/background/domains/CommandDocs.ts index 734c68e..25ea62a 100644 --- a/src/background/domains/CommandDocs.ts +++ b/src/background/domains/CommandDocs.ts @@ -8,5 +8,4 @@ export default { bdeletes: 'Close all tabs matched by keywords', quit: 'Close the current tab', quitall: 'Close all tabs', -}; - +} as {[key: string]: string}; diff --git a/src/background/domains/CompletionGroup.ts b/src/background/domains/CompletionGroup.ts index 1749d72..1eea7d8 100644 --- a/src/background/domains/CompletionGroup.ts +++ b/src/background/domains/CompletionGroup.ts @@ -1,14 +1,7 @@ -export default class CompletionGroup { - constructor(name, items) { - this.name0 = name; - this.items0 = items; - } +import CompletionItem from './CompletionItem'; - get name() { - return this.name0; - } - - get items() { - return this.items0; - } +export default interface CompletionGroup { + name: string; + items: CompletionItem[]; + // eslint-disable-next-line semi } diff --git a/src/background/domains/CompletionItem.ts b/src/background/domains/CompletionItem.ts index c7ad8a1..657efaa 100644 --- a/src/background/domains/CompletionItem.ts +++ b/src/background/domains/CompletionItem.ts @@ -1,24 +1,7 @@ -export default class CompletionItem { - constructor({ caption, content, url, icon }) { - this.caption0 = caption; - this.content0 = content; - this.url0 = url; - this.icon0 = icon; - } - - get caption() { - return this.caption0; - } - - get content() { - return this.content0; - } - - get url() { - return this.url0; - } - - get icon() { - return this.icon0; - } +export default interface CompletionItem { + readonly caption?: string; + readonly content?: string; + readonly url?: string; + readonly icon?: string; + // eslint-disable-next-line semi } diff --git a/src/background/domains/Completions.ts b/src/background/domains/Completions.ts deleted file mode 100644 index f399743..0000000 --- a/src/background/domains/Completions.ts +++ /dev/null @@ -1,27 +0,0 @@ -export default class Completions { - constructor(groups) { - this.g = groups; - } - - get groups() { - return this.g; - } - - serialize() { - return this.groups.map(group => ({ - name: group.name, - items: group.items.map(item => ({ - caption: item.caption, - content: item.content, - url: item.url, - icon: item.icon, - })), - })); - } - - static empty() { - return EMPTY_COMPLETIONS; - } -} - -let EMPTY_COMPLETIONS = new Completions([]); diff --git a/src/background/domains/GlobalMark.ts b/src/background/domains/GlobalMark.ts index f0586f1..0964373 100644 --- a/src/background/domains/GlobalMark.ts +++ b/src/background/domains/GlobalMark.ts @@ -1,24 +1,6 @@ -export default class GlobalMark { - constructor(tabId, url, x, y) { - this.tabId0 = tabId; - this.url0 = url; - this.x0 = x; - this.y0 = y; - } - - get tabId() { - return this.tabId0; - } - - get url() { - return this.url0; - } - - get x() { - return this.x0; - } - - get y() { - return this.y0; - } +export interface GlobalMark { + readonly tabId: number; + readonly url: string; + readonly x: number; + readonly y: number; } diff --git a/src/background/infrastructures/ConsoleClient.ts b/src/background/infrastructures/ConsoleClient.ts index f691515..7ad5d24 100644 --- a/src/background/infrastructures/ConsoleClient.ts +++ b/src/background/infrastructures/ConsoleClient.ts @@ -1,34 +1,34 @@ import messages from '../../shared/messages'; export default class ConsoleClient { - showCommand(tabId, command) { + showCommand(tabId: number, command: string): Promise { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_COMMAND, command, }); } - showFind(tabId) { + showFind(tabId: number): Promise { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_FIND }); } - showInfo(tabId, message) { + showInfo(tabId: number, message: string): Promise { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_INFO, text: message, }); } - showError(tabId, message) { + showError(tabId: number, message: string): Promise { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_SHOW_ERROR, text: message, }); } - hide(tabId) { + hide(tabId: number): Promise { return browser.tabs.sendMessage(tabId, { type: messages.CONSOLE_HIDE, }); diff --git a/src/background/infrastructures/ContentMessageClient.ts b/src/background/infrastructures/ContentMessageClient.ts index 0fab5a3..20057c7 100644 --- a/src/background/infrastructures/ContentMessageClient.ts +++ b/src/background/infrastructures/ContentMessageClient.ts @@ -1,10 +1,10 @@ import messages from '../../shared/messages'; export default class ContentMessageClient { - async broadcastSettingsChanged() { + async broadcastSettingsChanged(): Promise { let tabs = await browser.tabs.query({}); for (let tab of tabs) { - if (tab.url.startsWith('about:')) { + if (!tab.id || tab.url && tab.url.startsWith('about:')) { continue; } browser.tabs.sendMessage(tab.id, { @@ -13,20 +13,20 @@ export default class ContentMessageClient { } } - async getAddonEnabled(tabId) { + async getAddonEnabled(tabId: number): Promise { let { enabled } = await browser.tabs.sendMessage(tabId, { type: messages.ADDON_ENABLED_QUERY, - }); + }) as { enabled: boolean }; return enabled; } - toggleAddonEnabled(tabId) { + toggleAddonEnabled(tabId: number): Promise { return browser.tabs.sendMessage(tabId, { type: messages.ADDON_TOGGLE_ENABLED, }); } - scrollTo(tabId, x, y) { + scrollTo(tabId: number, x: number, y: number): Promise { return browser.tabs.sendMessage(tabId, { type: messages.TAB_SCROLL_TO, x, diff --git a/src/background/infrastructures/ContentMessageListener.ts b/src/background/infrastructures/ContentMessageListener.ts index 5b0f62e..81d3232 100644 --- a/src/background/infrastructures/ContentMessageListener.ts +++ b/src/background/infrastructures/ContentMessageListener.ts @@ -1,4 +1,5 @@ import messages from '../../shared/messages'; +import CompletionGroup from '../domains/CompletionGroup'; import CommandController from '../controllers/CommandController'; import SettingController from '../controllers/SettingController'; import FindController from '../controllers/FindController'; @@ -8,6 +9,22 @@ import OperationController from '../controllers/OperationController'; import MarkController from '../controllers/MarkController'; export default class ContentMessageListener { + private settingController: SettingController; + + private commandController: CommandController; + + private findController: FindController; + + private addonEnabledController: AddonEnabledController; + + private linkController: LinkController; + + private backgroundOperationController: OperationController; + + private markController: MarkController; + + private consolePorts: {[tabId: number]: browser.runtime.Port}; + constructor() { this.settingController = new SettingController(); this.commandController = new CommandController(); @@ -20,20 +37,28 @@ export default class ContentMessageListener { this.consolePorts = {}; } - run() { - browser.runtime.onMessage.addListener((message, sender) => { + run(): void { + browser.runtime.onMessage.addListener(( + message: any, sender: browser.runtime.MessageSender, + ) => { try { - let ret = this.onMessage(message, sender); + let ret = this.onMessage(message, sender.tab as browser.tabs.Tab); if (!(ret instanceof Promise)) { return {}; } return ret.catch((e) => { + if (!sender.tab || !sender.tab.id) { + return; + } return browser.tabs.sendMessage(sender.tab.id, { type: messages.CONSOLE_SHOW_ERROR, text: e.message, }); }); } catch (e) { + if (!sender.tab || !sender.tab.id) { + return; + } return browser.tabs.sendMessage(sender.tab.id, { type: messages.CONSOLE_SHOW_ERROR, text: e.message, @@ -43,7 +68,7 @@ export default class ContentMessageListener { browser.runtime.onConnect.addListener(this.onConnected.bind(this)); } - onMessage(message, sender) { + onMessage(message: any, senderTab: browser.tabs.Tab): Promise | any { switch (message.type) { case messages.CONSOLE_QUERY_COMPLETIONS: return this.onConsoleQueryCompletions(message.text); @@ -59,7 +84,10 @@ export default class ContentMessageListener { return this.onAddonEnabledResponse(message.enabled); case messages.OPEN_URL: return this.onOpenUrl( - message.newTab, message.url, sender.tab.id, message.background); + message.newTab, + message.url, + senderTab.id as number, + message.background); case messages.BACKGROUND_OPERATION: return this.onBackgroundOperation(message.operation); case messages.MARK_SET_GLOBAL: @@ -67,56 +95,60 @@ export default class ContentMessageListener { case messages.MARK_JUMP_GLOBAL: return this.onMarkJumpGlobal(message.key); case messages.CONSOLE_FRAME_MESSAGE: - return this.onConsoleFrameMessage(sender.tab.id, message.message); + return this.onConsoleFrameMessage( + senderTab.id as number, message.message, + ); } + throw new Error('unsupported message: ' + message.type); } - async onConsoleQueryCompletions(line) { + async onConsoleQueryCompletions(line: string): Promise { let completions = await this.commandController.getCompletions(line); - return Promise.resolve(completions.serialize()); + return Promise.resolve(completions); } - onConsoleEnterCommand(text) { + onConsoleEnterCommand(text: string): Promise { return this.commandController.exec(text); } - - onSettingsQuery() { + onSettingsQuery(): Promise { return this.settingController.getSetting(); } - onFindGetKeyword() { + onFindGetKeyword(): Promise { return this.findController.getKeyword(); } - onFindSetKeyword(keyword) { + onFindSetKeyword(keyword: string): Promise { return this.findController.setKeyword(keyword); } - onAddonEnabledResponse(enabled) { + onAddonEnabledResponse(enabled: boolean): Promise { return this.addonEnabledController.indicate(enabled); } - onOpenUrl(newTab, url, openerId, background) { + onOpenUrl( + newTab: boolean, url: string, openerId: number, background: boolean, + ): Promise { if (newTab) { return this.linkController.openNewTab(url, openerId, background); } return this.linkController.openToTab(url, openerId); } - onBackgroundOperation(operation) { + onBackgroundOperation(operation: any): Promise { return this.backgroundOperationController.exec(operation); } - onMarkSetGlobal(key, x, y) { + onMarkSetGlobal(key: string, x: number, y: number): Promise { return this.markController.setGlobal(key, x, y); } - onMarkJumpGlobal(key) { + onMarkJumpGlobal(key: string): Promise { return this.markController.jumpGlobal(key); } - onConsoleFrameMessage(tabId, message) { + onConsoleFrameMessage(tabId: number, message: any): void { let port = this.consolePorts[tabId]; if (!port) { return; @@ -124,12 +156,14 @@ export default class ContentMessageListener { port.postMessage(message); } - onConnected(port) { + onConnected(port: browser.runtime.Port): void { if (port.name !== 'vimvixen-console') { return; } - let id = port.sender.tab.id; - this.consolePorts[id] = port; + if (port.sender && port.sender.tab && port.sender.tab.id) { + let id = port.sender.tab.id; + this.consolePorts[id] = port; + } } } diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/infrastructures/MemoryStorage.ts index 3a7e4f2..baf9ffa 100644 --- a/src/background/infrastructures/MemoryStorage.ts +++ b/src/background/infrastructures/MemoryStorage.ts @@ -1,7 +1,7 @@ -const db = {}; +const db: {[key: string]: any} = {}; export default class MemoryStorage { - set(name, value) { + set(name: string, value: any): void { let data = JSON.stringify(value); if (typeof data === 'undefined') { throw new Error('value is not serializable'); @@ -9,7 +9,7 @@ export default class MemoryStorage { db[name] = data; } - get(name) { + get(name: string): any { let data = db[name]; if (!data) { return undefined; diff --git a/src/background/presenters/IndicatorPresenter.ts b/src/background/presenters/IndicatorPresenter.ts index 5737519..d9a615a 100644 --- a/src/background/presenters/IndicatorPresenter.ts +++ b/src/background/presenters/IndicatorPresenter.ts @@ -1,12 +1,12 @@ export default class IndicatorPresenter { - indicate(enabled) { + indicate(enabled: boolean): Promise { let path = enabled ? 'resources/enabled_32x32.png' : 'resources/disabled_32x32.png'; return browser.browserAction.setIcon({ path }); } - onClick(listener) { + onClick(listener: (arg: browser.tabs.Tab) => void): void { browser.browserAction.onClicked.addListener(listener); } } diff --git a/src/background/presenters/NotifyPresenter.ts b/src/background/presenters/NotifyPresenter.ts index a81f227..c83c205 100644 --- a/src/background/presenters/NotifyPresenter.ts +++ b/src/background/presenters/NotifyPresenter.ts @@ -1,8 +1,12 @@ const NOTIFICATION_ID = 'vimvixen-update'; export default class NotifyPresenter { - notify(title, message, onclick) { - const listener = (id) => { + notify( + title: string, + message: string, + onclick: () => void, + ): Promise { + const listener = (id: string) => { if (id !== NOTIFICATION_ID) { return; } diff --git a/src/background/presenters/TabPresenter.ts b/src/background/presenters/TabPresenter.ts index 744be39..33c6513 100644 --- a/src/background/presenters/TabPresenter.ts +++ b/src/background/presenters/TabPresenter.ts @@ -3,27 +3,29 @@ import MemoryStorage from '../infrastructures/MemoryStorage'; const CURRENT_SELECTED_KEY = 'tabs.current.selected'; const LAST_SELECTED_KEY = 'tabs.last.selected'; +type Tab = browser.tabs.Tab; + export default class TabPresenter { - open(url, tabId) { + open(url: string, tabId?: number): Promise { return browser.tabs.update(tabId, { url }); } - create(url, opts) { + create(url: string, opts?: object): Promise { return browser.tabs.create({ url, ...opts }); } - async getCurrent() { + async getCurrent(): Promise { let tabs = await browser.tabs.query({ active: true, currentWindow: true }); return tabs[0]; } - getAll() { + getAll(): Promise { return browser.tabs.query({ currentWindow: true }); } - async getLastSelectedId() { + async getLastSelectedId(): Promise { let cache = new MemoryStorage(); let tabId = await cache.get(LAST_SELECTED_KEY); if (tabId === null || typeof tabId === 'undefined') { @@ -32,25 +34,25 @@ export default class TabPresenter { return tabId; } - async getByKeyword(keyword, excludePinned = false) { + async getByKeyword(keyword: string, excludePinned = false): Promise { let tabs = await browser.tabs.query({ currentWindow: true }); return tabs.filter((t) => { - return t.url.toLowerCase().includes(keyword.toLowerCase()) || + return t.url && t.url.toLowerCase().includes(keyword.toLowerCase()) || t.title && t.title.toLowerCase().includes(keyword.toLowerCase()); }).filter((t) => { return !(excludePinned && t.pinned); }); } - select(tabId) { + select(tabId: number): Promise { return browser.tabs.update(tabId, { active: true }); } - remove(ids) { + remove(ids: number[]): Promise { return browser.tabs.remove(ids); } - async reopen() { + async reopen(): Promise { let window = await browser.windows.getCurrent(); let sessions = await browser.sessions.getRecentlyClosed(); let session = sessions.find((s) => { @@ -59,39 +61,43 @@ export default class TabPresenter { if (!session) { return; } - if (session.tab) { + if (session.tab && session.tab.sessionId) { return browser.sessions.restore(session.tab.sessionId); } - return browser.sessions.restore(session.window.sessionId); + if (session.window && session.window.sessionId) { + return browser.sessions.restore(session.window.sessionId); + } } - reload(tabId, cache) { + reload(tabId: number, cache: boolean): Promise { return browser.tabs.reload(tabId, { bypassCache: cache }); } - setPinned(tabId, pinned) { + setPinned(tabId: number, pinned: boolean): Promise { return browser.tabs.update(tabId, { pinned }); } - duplicate(id) { + duplicate(id: number): Promise { return browser.tabs.duplicate(id); } - getZoom(tabId) { + getZoom(tabId: number): Promise { return browser.tabs.getZoom(tabId); } - setZoom(tabId, factor) { + setZoom(tabId: number, factor: number): Promise { return browser.tabs.setZoom(tabId, factor); } - onSelected(listener) { + onSelected( + listener: (arg: { tabId: number, windowId: number}) => void, + ): void { browser.tabs.onActivated.addListener(listener); } } let tabPresenter = new TabPresenter(); -tabPresenter.onSelected((tab) => { +tabPresenter.onSelected((tab: any) => { let cache = new MemoryStorage(); let lastId = cache.get(CURRENT_SELECTED_KEY); diff --git a/src/background/presenters/WindowPresenter.ts b/src/background/presenters/WindowPresenter.ts index a82c4a2..e04f258 100644 --- a/src/background/presenters/WindowPresenter.ts +++ b/src/background/presenters/WindowPresenter.ts @@ -1,5 +1,5 @@ export default class WindowPresenter { - create(url) { + create(url: string): Promise { return browser.windows.create({ url }); } } diff --git a/src/background/repositories/BookmarkRepository.ts b/src/background/repositories/BookmarkRepository.ts index 99f7ec4..b4da509 100644 --- a/src/background/repositories/BookmarkRepository.ts +++ b/src/background/repositories/BookmarkRepository.ts @@ -1,5 +1,7 @@ export default class BookmarkRepository { - async create(title, url) { + async create( + title: string, url: string + ): Promise { let item = await browser.bookmarks.create({ type: 'bookmark', title, diff --git a/src/background/repositories/BrowserSettingRepository.ts b/src/background/repositories/BrowserSettingRepository.ts index a9d2c06..48c72a5 100644 --- a/src/background/repositories/BrowserSettingRepository.ts +++ b/src/background/repositories/BrowserSettingRepository.ts @@ -1,7 +1,7 @@ import * as urls from '../../shared/urls'; export default class BrowserSettingRepository { - async getHomepageUrls() { + async getHomepageUrls(): Promise { let { value } = await browser.browserSettings.homepageOverride.get({}); return value.split('|').map(urls.normalizeUrl); } diff --git a/src/background/repositories/CompletionsRepository.ts b/src/background/repositories/CompletionsRepository.ts index 1318d36..18af587 100644 --- a/src/background/repositories/CompletionsRepository.ts +++ b/src/background/repositories/CompletionsRepository.ts @@ -1,7 +1,13 @@ +type Tab = browser.tabs.Tab; +type BookmarkTreeNode = browser.bookmarks.BookmarkTreeNode; + export default class CompletionsRepository { - async queryBookmarks(keywords) { + async queryBookmarks(keywords: string): Promise { let items = await browser.bookmarks.search({ query: keywords }); return items.filter((item) => { + if (!item.url) { + return false; + } let url = undefined; try { url = new URL(item.url); @@ -12,17 +18,17 @@ export default class CompletionsRepository { }); } - queryHistories(keywords) { + queryHistories(keywords: string): Promise { return browser.history.search({ text: keywords, startTime: 0, }); } - async queryTabs(keywords, excludePinned) { + async queryTabs(keywords: string, excludePinned: boolean): Promise { let tabs = await browser.tabs.query({ currentWindow: true }); return tabs.filter((t) => { - return t.url.toLowerCase().includes(keywords.toLowerCase()) || + return t.url && t.url.toLowerCase().includes(keywords.toLowerCase()) || t.title && t.title.toLowerCase().includes(keywords.toLowerCase()); }).filter((t) => { return !(excludePinned && t.pinned); diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts index 74ec914..bf286e6 100644 --- a/src/background/repositories/FindRepository.ts +++ b/src/background/repositories/FindRepository.ts @@ -3,15 +3,17 @@ import MemoryStorage from '../infrastructures/MemoryStorage'; const FIND_KEYWORD_KEY = 'find-keyword'; export default class FindRepository { + private cache: MemoryStorage; + constructor() { this.cache = new MemoryStorage(); } - getKeyword() { + getKeyword(): Promise { return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY)); } - setKeyword(keyword) { + setKeyword(keyword: string): Promise { this.cache.set(FIND_KEYWORD_KEY, keyword); return Promise.resolve(); } diff --git a/src/background/repositories/MarkRepository.ts b/src/background/repositories/MarkRepository.ts index 282c712..69c85f6 100644 --- a/src/background/repositories/MarkRepository.ts +++ b/src/background/repositories/MarkRepository.ts @@ -4,21 +4,23 @@ import GlobalMark from '../domains/GlobalMark'; const MARK_KEY = 'mark'; export default class MarkRepository { + private cache: MemoryStorage; + constructor() { this.cache = new MemoryStorage(); } - getMark(key) { + getMark(key: string): Promise { let marks = this.getOrEmptyMarks(); let data = marks[key]; if (!data) { return Promise.resolve(undefined); } - let mark = new GlobalMark(data.tabId, data.url, data.x, data.y); + let mark = { tabId: data.tabId, url: data.url, x: data.x, y: data.y }; return Promise.resolve(mark); } - setMark(key, mark) { + setMark(key: string, mark: GlobalMark): Promise { let marks = this.getOrEmptyMarks(); marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y }; this.cache.set(MARK_KEY, marks); diff --git a/src/background/repositories/PersistentSettingRepository.ts b/src/background/repositories/PersistentSettingRepository.ts index 4cab107..3f2f4a1 100644 --- a/src/background/repositories/PersistentSettingRepository.ts +++ b/src/background/repositories/PersistentSettingRepository.ts @@ -1,7 +1,7 @@ import Setting from '../domains/Setting'; export default class SettingRepository { - async load() { + async load(): Promise { let { settings } = await browser.storage.local.get('settings'); if (!settings) { return null; diff --git a/src/background/repositories/SettingRepository.ts b/src/background/repositories/SettingRepository.ts index c4667a9..15355ba 100644 --- a/src/background/repositories/SettingRepository.ts +++ b/src/background/repositories/SettingRepository.ts @@ -3,19 +3,21 @@ import MemoryStorage from '../infrastructures/MemoryStorage'; const CACHED_SETTING_KEY = 'setting'; export default class SettingRepository { + private cache: MemoryStorage; + constructor() { this.cache = new MemoryStorage(); } - get() { + get(): Promise { return Promise.resolve(this.cache.get(CACHED_SETTING_KEY)); } - update(value) { + update(value: any): any { return this.cache.set(CACHED_SETTING_KEY, value); } - async setProperty(name, value) { + async setProperty(name: string, value: string): Promise { let current = await this.get(); current.properties[name] = value; return this.update(current); diff --git a/src/background/repositories/VersionRepository.ts b/src/background/repositories/VersionRepository.ts deleted file mode 100644 index 4c71d05..0000000 --- a/src/background/repositories/VersionRepository.ts +++ /dev/null @@ -1,10 +0,0 @@ -export default class VersionRepository { - async get() { - let { version } = await browser.storage.local.get('version'); - return version; - } - - update(version) { - return browser.storage.local.set({ version }); - } -} diff --git a/src/background/usecases/AddonEnabledUseCase.ts b/src/background/usecases/AddonEnabledUseCase.ts index bb2c347..0a6fb03 100644 --- a/src/background/usecases/AddonEnabledUseCase.ts +++ b/src/background/usecases/AddonEnabledUseCase.ts @@ -3,10 +3,20 @@ import TabPresenter from '../presenters/TabPresenter'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; export default class AddonEnabledUseCase { + private indicatorPresentor: IndicatorPresenter; + + private tabPresenter: TabPresenter; + + private contentMessageClient: ContentMessageClient; + constructor() { this.indicatorPresentor = new IndicatorPresenter(); - this.indicatorPresentor.onClick(tab => this.onIndicatorClick(tab.id)); + this.indicatorPresentor.onClick((tab) => { + if (tab.id) { + this.onIndicatorClick(tab.id); + } + }); this.tabPresenter = new TabPresenter(); this.tabPresenter.onSelected(info => this.onTabSelected(info.tabId)); @@ -14,15 +24,15 @@ export default class AddonEnabledUseCase { this.contentMessageClient = new ContentMessageClient(); } - indicate(enabled) { + indicate(enabled: boolean): Promise { return this.indicatorPresentor.indicate(enabled); } - onIndicatorClick(tabId) { + onIndicatorClick(tabId: number): Promise { return this.contentMessageClient.toggleAddonEnabled(tabId); } - async onTabSelected(tabId) { + async onTabSelected(tabId: number): Promise { let enabled = await this.contentMessageClient.getAddonEnabled(tabId); return this.indicatorPresentor.indicate(enabled); } diff --git a/src/background/usecases/CommandUseCase.ts b/src/background/usecases/CommandUseCase.ts index 9ec46fe..e0e3ada 100644 --- a/src/background/usecases/CommandUseCase.ts +++ b/src/background/usecases/CommandUseCase.ts @@ -6,9 +6,21 @@ import SettingRepository from '../repositories/SettingRepository'; import BookmarkRepository from '../repositories/BookmarkRepository'; import ConsoleClient from '../infrastructures/ConsoleClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; -import * as properties from 'shared/settings/properties'; +import * as properties from '../../shared/settings/properties'; export default class CommandIndicator { + private tabPresenter: TabPresenter; + + private windowPresenter: WindowPresenter; + + private settingRepository: SettingRepository; + + private bookmarkRepository: BookmarkRepository; + + private consoleClient: ConsoleClient; + + private contentMessageClient: ContentMessageClient; + constructor() { this.tabPresenter = new TabPresenter(); this.windowPresenter = new WindowPresenter(); @@ -19,34 +31,34 @@ export default class CommandIndicator { this.contentMessageClient = new ContentMessageClient(); } - async open(keywords) { + async open(keywords: string): Promise { let url = await this.urlOrSearch(keywords); return this.tabPresenter.open(url); } - async tabopen(keywords) { + async tabopen(keywords: string): Promise { let url = await this.urlOrSearch(keywords); return this.tabPresenter.create(url); } - async winopen(keywords) { + async winopen(keywords: string): Promise { let url = await this.urlOrSearch(keywords); return this.windowPresenter.create(url); } // eslint-disable-next-line max-statements - async buffer(keywords) { + async buffer(keywords: string): Promise { if (keywords.length === 0) { return; } - if (!isNaN(keywords)) { + if (!isNaN(Number(keywords))) { let tabs = await this.tabPresenter.getAll(); let index = parseInt(keywords, 10) - 1; if (index < 0 || tabs.length <= index) { throw new RangeError(`tab ${index + 1} does not exist`); } - return this.tabPresenter.select(tabs[index].id); + return this.tabPresenter.select(tabs[index].id as number); } else if (keywords.trim() === '%') { // Select current window return; @@ -66,13 +78,13 @@ export default class CommandIndicator { } for (let tab of tabs) { if (tab.index > current.index) { - return this.tabPresenter.select(tab.id); + return this.tabPresenter.select(tab.id as number); } } - return this.tabPresenter.select(tabs[0].id); + return this.tabPresenter.select(tabs[0].id as number); } - async bdelete(force, keywords) { + async bdelete(force: boolean, keywords: string): Promise { let excludePinned = !force; let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); if (tabs.length === 0) { @@ -80,35 +92,35 @@ export default class CommandIndicator { } else if (tabs.length > 1) { throw new Error('More than one match for ' + keywords); } - return this.tabPresenter.remove([tabs[0].id]); + return this.tabPresenter.remove([tabs[0].id as number]); } - async bdeletes(force, keywords) { + async bdeletes(force: boolean, keywords: string): Promise { let excludePinned = !force; let tabs = await this.tabPresenter.getByKeyword(keywords, excludePinned); - let ids = tabs.map(tab => tab.id); + let ids = tabs.map(tab => tab.id as number); return this.tabPresenter.remove(ids); } - async quit() { + async quit(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.remove([tab.id]); + return this.tabPresenter.remove([tab.id as number]); } - async quitAll() { + async quitAll(): Promise { let tabs = await this.tabPresenter.getAll(); - let ids = tabs.map(tab => tab.id); + let ids = tabs.map(tab => tab.id as number); this.tabPresenter.remove(ids); } - async addbookmark(title) { + async addbookmark(title: string): Promise { let tab = await this.tabPresenter.getCurrent(); let item = await this.bookmarkRepository.create(title, tab.url); let message = 'Saved current page: ' + item.url; return this.consoleClient.showInfo(tab.id, message); } - async set(keywords) { + async set(keywords: string): Promise { if (keywords.length === 0) { return; } @@ -118,7 +130,7 @@ export default class CommandIndicator { return this.contentMessageClient.broadcastSettingsChanged(); } - async urlOrSearch(keywords) { + async urlOrSearch(keywords: string): Promise { let settings = await this.settingRepository.get(); return urls.searchUrl(keywords, settings.search); } diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts index 7dc30ac..037d6eb 100644 --- a/src/background/usecases/CompletionsUseCase.ts +++ b/src/background/usecases/CompletionsUseCase.ts @@ -1,6 +1,5 @@ -import CompletionItem from '../domains/CompletionItem'; -import CompletionGroup from '../domains/CompletionGroup'; import Completions from '../domains/Completions'; +import CompletionGroup from '../domains/CompletionGroup'; import CommandDocs from '../domains/CommandDocs'; import CompletionsRepository from '../repositories/CompletionsRepository'; import * as filters from './filters'; @@ -10,14 +9,23 @@ import * as properties from '../../shared/settings/properties'; const COMPLETION_ITEM_LIMIT = 10; +type Tab = browser.tabs.Tab; +type HistoryItem = browser.history.HistoryItem; + export default class CompletionsUseCase { + private tabPresenter: TabPresenter; + + private completionsRepository: CompletionsRepository; + + private settingRepository: SettingRepository; + constructor() { this.tabPresenter = new TabPresenter(); this.completionsRepository = new CompletionsRepository(); this.settingRepository = new SettingRepository(); } - queryConsoleCommand(prefix) { + queryConsoleCommand(prefix: string): Promise { let keys = Object.keys(CommandDocs); let items = keys .filter(name => name.startsWith(prefix)) @@ -28,16 +36,14 @@ export default class CompletionsUseCase { })); if (items.length === 0) { - return Promise.resolve(Completions.empty()); + return Promise.resolve([]); } - return Promise.resolve( - new Completions([new CompletionGroup('Console Command', items)]) - ); + return Promise.resolve([{ name: 'Console CompletionGroup', items }]); } - async queryOpen(name, keywords) { + async queryOpen(name: string, keywords: string): Promise { let settings = await this.settingRepository.get(); - let groups = []; + let groups: CompletionGroup[] = []; let complete = settings.properties.complete || properties.defaults.complete; for (let c of complete) { @@ -45,31 +51,31 @@ export default class CompletionsUseCase { // eslint-disable-next-line no-await-in-loop let engines = await this.querySearchEngineItems(name, keywords); if (engines.length > 0) { - groups.push(new CompletionGroup('Search Engines', engines)); + groups.push({ name: 'Search Engines', items: engines }); } } else if (c === 'h') { // eslint-disable-next-line no-await-in-loop let histories = await this.queryHistoryItems(name, keywords); if (histories.length > 0) { - groups.push(new CompletionGroup('History', histories)); + groups.push({ name: 'History', items: histories }); } } else if (c === 'b') { // eslint-disable-next-line no-await-in-loop let bookmarks = await this.queryBookmarkItems(name, keywords); if (bookmarks.length > 0) { - groups.push(new CompletionGroup('Bookmarks', bookmarks)); + groups.push({ name: 'Bookmarks', items: bookmarks }); } } } - return new Completions(groups); + return groups; } // eslint-disable-next-line max-statements - async queryBuffer(name, keywords) { + async queryBuffer(name: string, keywords: string): Promise { let lastId = await this.tabPresenter.getLastSelectedId(); let trimmed = keywords.trim(); - let tabs = []; - if (trimmed.length > 0 && !isNaN(trimmed)) { + let tabs: Tab[] = []; + if (trimmed.length > 0 && !isNaN(Number(trimmed))) { let all = await this.tabPresenter.getAll(); let index = parseInt(trimmed, 10) - 1; if (index >= 0 && index < all.length) { @@ -77,18 +83,18 @@ export default class CompletionsUseCase { } } else if (trimmed === '%') { let all = await this.tabPresenter.getAll(); - let tab = all.find(t => t.active); + let tab = all.find(t => t.active) as Tab; tabs = [tab]; } else if (trimmed === '#') { if (typeof lastId !== 'undefined' && lastId !== null) { let all = await this.tabPresenter.getAll(); - let tab = all.find(t => t.id === lastId); + let tab = all.find(t => t.id === lastId) as Tab; tabs = [tab]; } } else { tabs = await this.completionsRepository.queryTabs(keywords, false); } - const flag = (tab) => { + const flag = (tab: Tab) => { if (tab.active) { return '%'; } else if (tab.id === lastId) { @@ -96,87 +102,90 @@ export default class CompletionsUseCase { } return ' '; }; - let items = tabs.map(tab => new CompletionItem({ + let items = tabs.map(tab => ({ caption: tab.index + 1 + ': ' + flag(tab) + ' ' + tab.title, content: name + ' ' + tab.title, url: tab.url, - icon: tab.favIconUrl + icon: tab.favIconUrl, })); if (items.length === 0) { - return Promise.resolve(Completions.empty()); + return Promise.resolve([]); } - return new Completions([new CompletionGroup('Buffers', items)]); + return [{ name: 'Buffers', items }]; } - queryBdelete(name, keywords) { + queryBdelete(name: string, keywords: string): Promise { return this.queryTabs(name, true, keywords); } - queryBdeleteForce(name, keywords) { + queryBdeleteForce( + name: string, keywords: string, + ): Promise { return this.queryTabs(name, false, keywords); } - querySet(name, keywords) { + querySet(name: string, keywords: string): Promise { let items = Object.keys(properties.docs).map((key) => { if (properties.types[key] === 'boolean') { return [ - new CompletionItem({ + { caption: key, content: name + ' ' + key, url: 'Enable ' + properties.docs[key], - }), - new CompletionItem({ + }, { caption: 'no' + key, content: name + ' no' + key, url: 'Disable ' + properties.docs[key], - }), + } ]; } return [ - new CompletionItem({ + { caption: key, content: name + ' ' + key, url: 'Set ' + properties.docs[key], - }) + } ]; }); - items = items.reduce((acc, val) => acc.concat(val), []); - items = items.filter((item) => { + let flatten = items.reduce((acc, val) => acc.concat(val), []); + flatten = flatten.filter((item) => { return item.caption.startsWith(keywords); }); - if (items.length === 0) { - return Promise.resolve(Completions.empty()); + if (flatten.length === 0) { + return Promise.resolve([]); } return Promise.resolve( - new Completions([new CompletionGroup('Properties', items)]) + [{ name: 'Properties', items: flatten }], ); } - async queryTabs(name, excludePinned, args) { + async queryTabs( + name: string, excludePinned: boolean, args: string, + ): Promise { let tabs = await this.completionsRepository.queryTabs(args, excludePinned); - let items = tabs.map(tab => new CompletionItem({ + let items = tabs.map(tab => ({ caption: tab.title, content: name + ' ' + tab.title, url: tab.url, icon: tab.favIconUrl })); if (items.length === 0) { - return Promise.resolve(Completions.empty()); + return Promise.resolve([]); } - return new Completions([new CompletionGroup('Buffers', items)]); + return [{ name: 'Buffers', items }]; } - async querySearchEngineItems(name, keywords) { + async querySearchEngineItems(name: string, keywords: string) { let settings = await this.settingRepository.get(); let engines = Object.keys(settings.search.engines) .filter(key => key.startsWith(keywords)); - return engines.map(key => new CompletionItem({ + return engines.map(key => ({ caption: key, content: name + ' ' + key, })); } - async queryHistoryItems(name, keywords) { + async queryHistoryItems(name: string, keywords: string) { let histories = await this.completionsRepository.queryHistories(keywords); histories = [histories] .map(filters.filterBlankTitle) @@ -184,19 +193,21 @@ export default class CompletionsUseCase { .map(filters.filterByTailingSlash) .map(pages => filters.filterByPathname(pages, COMPLETION_ITEM_LIMIT)) .map(pages => filters.filterByOrigin(pages, COMPLETION_ITEM_LIMIT))[0] - .sort((x, y) => x.visitCount < y.visitCount) + .sort((x: HistoryItem, y: HistoryItem) => { + return Number(x.visitCount) < Number(y.visitCount); + }) .slice(0, COMPLETION_ITEM_LIMIT); - return histories.map(page => new CompletionItem({ + return histories.map(page => ({ caption: page.title, content: name + ' ' + page.url, url: page.url })); } - async queryBookmarkItems(name, keywords) { + async queryBookmarkItems(name: string, keywords: string) { let bookmarks = await this.completionsRepository.queryBookmarks(keywords); return bookmarks.slice(0, COMPLETION_ITEM_LIMIT) - .map(page => new CompletionItem({ + .map(page => ({ caption: page.title, content: name + ' ' + page.url, url: page.url diff --git a/src/background/usecases/ConsoleUseCase.ts b/src/background/usecases/ConsoleUseCase.ts index e8e5d4a..60c0439 100644 --- a/src/background/usecases/ConsoleUseCase.ts +++ b/src/background/usecases/ConsoleUseCase.ts @@ -2,60 +2,64 @@ import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; export default class ConsoleUseCase { + private tabPresenter: TabPresenter; + + private consoleClient: ConsoleClient; + constructor() { this.tabPresenter = new TabPresenter(); this.consoleClient = new ConsoleClient(); } - async showCommand() { + async showCommand(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showCommand(tab.id, ''); + return this.consoleClient.showCommand(tab.id as number, ''); } - async showOpenCommand(alter) { + async showOpenCommand(alter: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); let command = 'open '; if (alter) { - command += tab.url; + command += tab.url || ''; } - return this.consoleClient.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id as number, command); } - async showTabopenCommand(alter) { + async showTabopenCommand(alter: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); let command = 'tabopen '; if (alter) { - command += tab.url; + command += tab.url || ''; } - return this.consoleClient.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id as number, command); } - async showWinopenCommand(alter) { + async showWinopenCommand(alter: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); let command = 'winopen '; if (alter) { - command += tab.url; + command += tab.url || ''; } - return this.consoleClient.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id as number, command); } - async showBufferCommand() { + async showBufferCommand(): Promise { let tab = await this.tabPresenter.getCurrent(); let command = 'buffer '; - return this.consoleClient.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id as number, command); } - async showAddbookmarkCommand(alter) { + async showAddbookmarkCommand(alter: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); let command = 'addbookmark '; if (alter) { - command += tab.title; + command += tab.title || ''; } - return this.consoleClient.showCommand(tab.id, command); + return this.consoleClient.showCommand(tab.id as number, command); } - async hideConsole() { + async hideConsole(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.hide(tab.id); + return this.consoleClient.hide(tab.id as number); } } diff --git a/src/background/usecases/FindUseCase.ts b/src/background/usecases/FindUseCase.ts index 224e4a9..d567800 100644 --- a/src/background/usecases/FindUseCase.ts +++ b/src/background/usecases/FindUseCase.ts @@ -3,22 +3,28 @@ import TabPresenter from '../presenters/TabPresenter'; import ConsoleClient from '../infrastructures/ConsoleClient'; export default class FindUseCase { + private tabPresenter: TabPresenter; + + private findRepository: FindRepository; + + private consoleClient: ConsoleClient; + constructor() { this.tabPresenter = new TabPresenter(); this.findRepository = new FindRepository(); this.consoleClient = new ConsoleClient(); } - getKeyword() { + getKeyword(): Promise { return this.findRepository.getKeyword(); } - setKeyword(keyword) { + setKeyword(keyword: string): Promise { return this.findRepository.setKeyword(keyword); } - async findStart() { + async findStart(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.consoleClient.showFind(tab.id); + return this.consoleClient.showFind(tab.id as number); } } diff --git a/src/background/usecases/LinkUseCase.ts b/src/background/usecases/LinkUseCase.ts index 89412c5..2f4df7b 100644 --- a/src/background/usecases/LinkUseCase.ts +++ b/src/background/usecases/LinkUseCase.ts @@ -1,17 +1,17 @@ -import SettingRepository from '../repositories/SettingRepository'; import TabPresenter from '../presenters/TabPresenter'; export default class LinkUseCase { + private tabPresenter: TabPresenter; + constructor() { - this.settingRepository = new SettingRepository(); this.tabPresenter = new TabPresenter(); } - openToTab(url, tabId) { + openToTab(url: string, tabId: number): Promise { return this.tabPresenter.open(url, tabId); } - openNewTab(url, openerId, background) { + openNewTab(url: string, openerId: number, background: boolean): Promise { return this.tabPresenter.create(url, { openerTabId: openerId, active: !background }); diff --git a/src/background/usecases/MarkUseCase.ts b/src/background/usecases/MarkUseCase.ts index 39c796b..8b544aa 100644 --- a/src/background/usecases/MarkUseCase.ts +++ b/src/background/usecases/MarkUseCase.ts @@ -1,10 +1,17 @@ -import GlobalMark from '../domains/GlobalMark'; import TabPresenter from '../presenters/TabPresenter'; import MarkRepository from '../repositories/MarkRepository'; import ConsoleClient from '../infrastructures/ConsoleClient'; import ContentMessageClient from '../infrastructures/ContentMessageClient'; export default class MarkUseCase { + private tabPresenter: TabPresenter; + + private markRepository: MarkRepository; + + private consoleClient: ConsoleClient; + + private contentMessageClient: ContentMessageClient; + constructor() { this.tabPresenter = new TabPresenter(); this.markRepository = new MarkRepository(); @@ -12,18 +19,19 @@ export default class MarkUseCase { this.contentMessageClient = new ContentMessageClient(); } - async setGlobal(key, x, y) { + async setGlobal(key: string, x: number, y: number): Promise { let tab = await this.tabPresenter.getCurrent(); - let mark = new GlobalMark(tab.id, tab.url, x, y); + let mark = { tabId: tab.id, url: tab.url, x, y }; return this.markRepository.setMark(key, mark); } - async jumpGlobal(key) { + async jumpGlobal(key: string): Promise { let current = await this.tabPresenter.getCurrent(); let mark = await this.markRepository.getMark(key); if (!mark) { - return this.consoleClient.showError(current.id, 'Mark is not set'); + return this.consoleClient.showError( + current.id as number, 'Mark is not set'); } return this.contentMessageClient.scrollTo( @@ -32,7 +40,7 @@ export default class MarkUseCase { return this.tabPresenter.select(mark.tabId); }).catch(async() => { let tab = await this.tabPresenter.create(mark.url); - let mark2 = new GlobalMark(tab.id, mark.url, mark.x, mark.y); + let mark2 = { tabId: tab.id, url: mark.url, x: mark.x, y: mark.y }; return this.markRepository.setMark(key, mark2); }); } diff --git a/src/background/usecases/SettingUseCase.ts b/src/background/usecases/SettingUseCase.ts index 9e17408..b66ce02 100644 --- a/src/background/usecases/SettingUseCase.ts +++ b/src/background/usecases/SettingUseCase.ts @@ -4,16 +4,20 @@ import PersistentSettingRepository from '../repositories/PersistentSettingReposi import SettingRepository from '../repositories/SettingRepository'; export default class SettingUseCase { + private persistentSettingRepository: PersistentSettingRepository; + + private settingRepository: SettingRepository; + constructor() { this.persistentSettingRepository = new PersistentSettingRepository(); this.settingRepository = new SettingRepository(); } - get() { + get(): Promise { return this.settingRepository.get(); } - async reload() { + async reload(): Promise { let settings = await this.persistentSettingRepository.load(); if (!settings) { settings = Setting.defaultSettings(); diff --git a/src/background/usecases/TabSelectUseCase.ts b/src/background/usecases/TabSelectUseCase.ts index 16b3e14..a0b52f0 100644 --- a/src/background/usecases/TabSelectUseCase.ts +++ b/src/background/usecases/TabSelectUseCase.ts @@ -1,11 +1,13 @@ import TabPresenter from '../presenters/TabPresenter'; export default class TabSelectUseCase { + private tabPresenter: TabPresenter; + constructor() { this.tabPresenter = new TabPresenter(); } - async selectPrev(count) { + async selectPrev(count: number): Promise { let tabs = await this.tabPresenter.getAll(); if (tabs.length < 2) { return; @@ -15,10 +17,10 @@ export default class TabSelectUseCase { return; } let select = (tab.index - count + tabs.length) % tabs.length; - return this.tabPresenter.select(tabs[select].id); + return this.tabPresenter.select(tabs[select].id as number); } - async selectNext(count) { + async selectNext(count: number): Promise { let tabs = await this.tabPresenter.getAll(); if (tabs.length < 2) { return; @@ -28,24 +30,24 @@ export default class TabSelectUseCase { return; } let select = (tab.index + count) % tabs.length; - return this.tabPresenter.select(tabs[select].id); + return this.tabPresenter.select(tabs[select].id as number); } - async selectFirst() { + async selectFirst(): Promise { let tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[0].id); + return this.tabPresenter.select(tabs[0].id as number); } - async selectLast() { + async selectLast(): Promise { let tabs = await this.tabPresenter.getAll(); - return this.tabPresenter.select(tabs[tabs.length - 1].id); + return this.tabPresenter.select(tabs[tabs.length - 1].id as number); } - async selectPrevSelected() { + async selectPrevSelected(): Promise { let tabId = await this.tabPresenter.getLastSelectedId(); if (tabId === null || typeof tabId === 'undefined') { - return; + return Promise.resolve(); } - this.tabPresenter.select(tabId); + return this.tabPresenter.select(tabId); } } diff --git a/src/background/usecases/TabUseCase.ts b/src/background/usecases/TabUseCase.ts index d930842..1615333 100644 --- a/src/background/usecases/TabUseCase.ts +++ b/src/background/usecases/TabUseCase.ts @@ -2,20 +2,24 @@ import TabPresenter from '../presenters/TabPresenter'; import BrowserSettingRepository from '../repositories/BrowserSettingRepository'; export default class TabUseCase { + private tabPresenter: TabPresenter; + + private browserSettingRepository: BrowserSettingRepository; + constructor() { this.tabPresenter = new TabPresenter(); this.browserSettingRepository = new BrowserSettingRepository(); } - async close(force) { + async close(force: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); if (!force && tab.pinned) { - return; + return Promise.resolve(); } - return this.tabPresenter.remove([tab.id]); + return this.tabPresenter.remove([tab.id as number]); } - async closeRight() { + async closeRight(): Promise { let tabs = await this.tabPresenter.getAll(); tabs.sort((t1, t2) => t1.index - t2.index); let index = tabs.findIndex(t => t.active); @@ -25,42 +29,42 @@ export default class TabUseCase { for (let i = index + 1; i < tabs.length; ++i) { let tab = tabs[i]; if (!tab.pinned) { - this.tabPresenter.remove(tab.id); + this.tabPresenter.remove([tab.id as number]); } } } - reopen() { + reopen(): Promise { return this.tabPresenter.reopen(); } - async reload(cache) { + async reload(cache: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.reload(tab.id, cache); + return this.tabPresenter.reload(tab.id as number, cache); } - async setPinned(pinned) { + async setPinned(pinned: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id, pinned); + return this.tabPresenter.setPinned(tab.id as number, pinned); } - async togglePinned() { + async togglePinned(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.setPinned(tab.id, !tab.pinned); + return this.tabPresenter.setPinned(tab.id as number, !tab.pinned); } - async duplicate() { + async duplicate(): Promise { let tab = await this.tabPresenter.getCurrent(); - return this.tabPresenter.duplicate(tab.id); + return this.tabPresenter.duplicate(tab.id as number); } - async openPageSource() { + async openPageSource(): Promise { let tab = await this.tabPresenter.getCurrent(); let url = 'view-source:' + tab.url; return this.tabPresenter.create(url); } - async openHome(newTab) { + async openHome(newTab: boolean): Promise { let tab = await this.tabPresenter.getCurrent(); let urls = await this.browserSettingRepository.getHomepageUrls(); if (urls.length === 1 && urls[0] === 'about:home') { diff --git a/src/background/usecases/VersionUseCase.ts b/src/background/usecases/VersionUseCase.ts index ed5112b..207f9e2 100644 --- a/src/background/usecases/VersionUseCase.ts +++ b/src/background/usecases/VersionUseCase.ts @@ -3,21 +3,25 @@ import TabPresenter from '../presenters/TabPresenter'; import NotifyPresenter from '../presenters/NotifyPresenter'; export default class VersionUseCase { + private tabPresenter: TabPresenter; + + private notifyPresenter: NotifyPresenter; + constructor() { this.tabPresenter = new TabPresenter(); this.notifyPresenter = new NotifyPresenter(); } - notify() { + notify(): Promise { let title = `Vim Vixen ${manifest.version} has been installed`; let message = 'Click here to see release notes'; let url = this.releaseNoteUrl(manifest.version); - this.notifyPresenter.notify(title, message, () => { + return this.notifyPresenter.notify(title, message, () => { this.tabPresenter.create(url); }); } - releaseNoteUrl(version) { + releaseNoteUrl(version?: string): string { if (version) { return `https://github.com/ueokande/vim-vixen/releases/tag/${version}`; } diff --git a/src/background/usecases/ZoomUseCase.ts b/src/background/usecases/ZoomUseCase.ts index 692d6d9..661c3cd 100644 --- a/src/background/usecases/ZoomUseCase.ts +++ b/src/background/usecases/ZoomUseCase.ts @@ -1,35 +1,39 @@ import TabPresenter from '../presenters/TabPresenter'; -const ZOOM_SETTINGS = [ +const ZOOM_SETTINGS: number[] = [ 0.33, 0.50, 0.66, 0.75, 0.80, 0.90, 1.00, 1.10, 1.25, 1.50, 1.75, 2.00, 2.50, 3.00 ]; export default class ZoomUseCase { + private tabPresenter: TabPresenter; + constructor() { this.tabPresenter = new TabPresenter(); } - async zoomIn(tabId) { + async zoomIn(): Promise { let tab = await this.tabPresenter.getCurrent(); - let current = await this.tabPresenter.getZoom(tab.id); + let tabId = tab.id as number; + let current = await this.tabPresenter.getZoom(tabId); let factor = ZOOM_SETTINGS.find(f => f > current); if (factor) { - return this.tabPresenter.setZoom(tabId, factor); + return this.tabPresenter.setZoom(tabId as number, factor); } } - async zoomOut(tabId) { + async zoomOut(): Promise { let tab = await this.tabPresenter.getCurrent(); - let current = await this.tabPresenter.getZoom(tab.id); - let factor = [].concat(ZOOM_SETTINGS).reverse().find(f => f < current); + let tabId = tab.id as number; + let current = await this.tabPresenter.getZoom(tabId); + let factor = ZOOM_SETTINGS.slice(0).reverse().find(f => f < current); if (factor) { - return this.tabPresenter.setZoom(tabId, factor); + return this.tabPresenter.setZoom(tabId as number, factor); } } - zoomNutoral(tabId) { - return this.tabPresenter.setZoom(tabId, 1); + async zoomNutoral(): Promise { + let tab = await this.tabPresenter.getCurrent(); + return this.tabPresenter.setZoom(tab.id as number, 1); } - } diff --git a/src/background/usecases/filters.ts b/src/background/usecases/filters.ts index d057dca..44eb56f 100644 --- a/src/background/usecases/filters.ts +++ b/src/background/usecases/filters.ts @@ -1,40 +1,42 @@ -const filterHttp = (items) => { - let httpsHosts = items.map(x => new URL(x.url)) +type Item = browser.history.HistoryItem; + +const filterHttp = (items: Item[]): Item[] => { + let httpsHosts = items.map(x => new URL(x.url as string)) .filter(x => x.protocol === 'https:') .map(x => x.host); - httpsHosts = new Set(httpsHosts); + let hostsSet = new Set(httpsHosts); - return items.filter((item) => { - let url = new URL(item.url); - return url.protocol === 'https:' || !httpsHosts.has(url.host); + return items.filter((item: Item) => { + let url = new URL(item.url as string); + return url.protocol === 'https:' || !hostsSet.has(url.host); }); }; -const filterBlankTitle = (items) => { +const filterBlankTitle = (items: Item[]): Item[] => { return items.filter(item => item.title && item.title !== ''); }; -const filterByTailingSlash = (items) => { - let urls = items.map(item => new URL(item.url)); +const filterByTailingSlash = (items: Item[]): Item[] => { + let urls = items.map(item => new URL(item.url as string)); let simplePaths = urls .filter(url => url.hash === '' && url.search === '') .map(url => url.origin + url.pathname); - simplePaths = new Set(simplePaths); + let pathsSet = new Set(simplePaths); return items.filter((item) => { - let url = new URL(item.url); + let url = new URL(item.url as string); if (url.hash !== '' || url.search !== '' || url.pathname.slice(-1) !== '/') { return true; } - return !simplePaths.has(url.origin + url.pathname.slice(0, -1)); + return !pathsSet.has(url.origin + url.pathname.slice(0, -1)); }); }; -const filterByPathname = (items, min) => { - let hash = {}; +const filterByPathname = (items: Item[], min: number): Item[] => { + let hash: {[key: string]: Item} = {}; for (let item of items) { - let url = new URL(item.url); + let url = new URL(item.url as string); let pathname = url.origin + url.pathname; if (!hash[pathname]) { hash[pathname] = item; @@ -49,10 +51,10 @@ const filterByPathname = (items, min) => { return filtered; }; -const filterByOrigin = (items, min) => { - let hash = {}; +const filterByOrigin = (items: Item[], min: number): Item[] => { + let hash: {[key: string]: Item} = {}; for (let item of items) { - let origin = new URL(item.url).origin; + let origin = new URL(item.url as string).origin; if (!hash[origin]) { hash[origin] = item; } else if (hash[origin].url.length > item.url.length) { diff --git a/src/background/usecases/parsers.ts b/src/background/usecases/parsers.ts index 43c8177..3616ac3 100644 --- a/src/background/usecases/parsers.ts +++ b/src/background/usecases/parsers.ts @@ -1,4 +1,4 @@ -const mustNumber = (v) => { +const mustNumber = (v: any): number => { let num = Number(v); if (isNaN(num)) { throw new Error('Not number: ' + v); @@ -6,8 +6,11 @@ const mustNumber = (v) => { return num; }; -const parseSetOption = (word, types) => { - let [key, value] = word.split('='); +const parseSetOption = ( + word: string, + types: { [key: string]: string }, +): any[] => { + let [key, value]: any[] = word.split('='); if (value === undefined) { value = !key.startsWith('no'); key = value ? key : key.slice(2); @@ -26,6 +29,7 @@ const parseSetOption = (word, types) => { case 'number': return [key, mustNumber(value)]; case 'boolean': return [key, value]; } + throw new Error('Unknown property type: ' + type); }; export { parseSetOption }; diff --git a/src/content/scrolls.ts b/src/content/scrolls.ts index f3124a1..bbf2491 100644 --- a/src/content/scrolls.ts +++ b/src/content/scrolls.ts @@ -90,16 +90,6 @@ class Scroller { } } -class RoughtScroller { - constructor(element) { - this.element = element; - } - - scroll(x, y) { - this.element.scrollTo(x, y); - } -} - const getScroll = () => { let target = scrollTarget(); return { x: target.scrollLeft, y: target.scrollTop }; diff --git a/test/background/domains/GlobalMark.test.ts b/test/background/domains/GlobalMark.test.ts deleted file mode 100644 index ed636e9..0000000 --- a/test/background/domains/GlobalMark.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import GlobalMark from 'background/domains/GlobalMark'; - -describe('background/domains/global-mark', () => { - describe('constructor and getter', () => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); - expect(mark.tabId).to.equal(1); - expect(mark.url).to.equal('http://example.com'); - expect(mark.x).to.equal(10); - expect(mark.y).to.equal(30); - }); -}); diff --git a/test/background/repositories/Mark.test.ts b/test/background/repositories/Mark.test.ts index 2a5b099..167e512 100644 --- a/test/background/repositories/Mark.test.ts +++ b/test/background/repositories/Mark.test.ts @@ -9,12 +9,11 @@ describe('background/repositories/mark', () => { }); it('get and set', async() => { - let mark = new GlobalMark(1, 'http://example.com', 10, 30); + let mark = { tabId: 1, url: 'http://example.com', x: 10, y: 30 }; repository.setMark('A', mark); let got = await repository.getMark('A'); - expect(got).to.be.a('object'); expect(got.tabId).to.equal(1); expect(got.url).to.equal('http://example.com'); expect(got.x).to.equal(10); diff --git a/test/background/repositories/Version.ts b/test/background/repositories/Version.ts deleted file mode 100644 index c7fa88b..0000000 --- a/test/background/repositories/Version.ts +++ /dev/null @@ -1,34 +0,0 @@ -import VersionRepository from 'background/repositories/Version'; - -describe("background/repositories/version", () => { - let versionRepository; - - beforeEach(() => { - versionRepository = new VersionRepository; - }); - - describe('#get', () => { - beforeEach(() => { - return browser.storage.local.remove('version'); - }); - - it('loads saved version', async() => { - await browser.storage.local.set({ version: '1.2.3' }); - let version = await this.versionRepository.get(); - expect(version).to.equal('1.2.3'); - }); - - it('returns undefined if no versions in storage', async() => { - let version = await storage.load(); - expect(version).to.be.a('undefined'); - }); - }); - - describe('#update', () => { - it('saves version string', async() => { - await versionRepository.update('2.3.4'); - let { version } = await browser.storage.local.get('version'); - expect(version).to.equal('2.3.4'); - }); - }); -}); From b89787974381410fbefd4f067a21d295422745bc Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 1 May 2019 22:03:48 +0900 Subject: [PATCH 13/24] Install @types/react-dom --- package-lock.json | 9 +++++++++ package.json | 1 + 2 files changed, 10 insertions(+) diff --git a/package-lock.json b/package-lock.json index 376b476..4032195 100644 --- a/package-lock.json +++ b/package-lock.json @@ -634,6 +634,15 @@ "csstype": "^2.2.0" } }, + "@types/react-dom": { + "version": "16.8.4", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-16.8.4.tgz", + "integrity": "sha512-eIRpEW73DCzPIMaNBDP5pPIpK1KXyZwNgfxiVagb5iGiz6da+9A5hslSX6GAQKdO7SayVCS/Fr2kjqprgAvkfA==", + "dev": true, + "requires": { + "@types/react": "*" + } + }, "@types/react-redux": { "version": "7.0.8", "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.0.8.tgz", diff --git a/package.json b/package.json index 9adf163..d000390 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@babel/preset-typescript": "^7.3.3", "@types/prop-types": "^15.7.1", "@types/react": "^16.8.15", + "@types/react-dom": "^16.8.4", "@types/react-redux": "^7.0.8", "@typescript-eslint/eslint-plugin": "^1.7.0", "babel-eslint": "^10.0.1", From 8cf8a0e62549a8c56ef821e207dbf2bca6d182f0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 1 May 2019 23:02:13 +0900 Subject: [PATCH 14/24] Install @types/redux-promise --- package-lock.json | 29 +++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 30 insertions(+) diff --git a/package-lock.json b/package-lock.json index 4032195..731b471 100644 --- a/package-lock.json +++ b/package-lock.json @@ -654,6 +654,29 @@ "redux": "^4.0.0" } }, + "@types/redux-promise": { + "version": "0.5.28", + "resolved": "https://registry.npmjs.org/@types/redux-promise/-/redux-promise-0.5.28.tgz", + "integrity": "sha512-HNWAIjTeMcdAgl4wI2XQdlrJeJMS/TyohD8Yzf3Ebp0fPR4M9wg4/+EBrbbLAsBrGxmSkXdvy1H2ty21dhlS7A==", + "dev": true, + "requires": { + "redux": "^3.6.0" + }, + "dependencies": { + "redux": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/redux/-/redux-3.7.2.tgz", + "integrity": "sha512-pNqnf9q1hI5HHZRBkj3bAngGZW/JMCmexDlOxw4XagXY2o1327nHH54LoTjiPJ0gizoqPDRqWyX/00g0hD6w+A==", + "dev": true, + "requires": { + "lodash": "^4.2.1", + "lodash-es": "^4.2.1", + "loose-envify": "^1.1.0", + "symbol-observable": "^1.0.3" + } + } + } + }, "@typescript-eslint/eslint-plugin": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.7.0.tgz", @@ -6546,6 +6569,12 @@ "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", "dev": true }, + "lodash-es": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.11.tgz", + "integrity": "sha512-DHb1ub+rMjjrxqlB3H56/6MXtm1lSksDp2rA2cNWjG8mlDUYFhUj3Di2Zn5IwSU87xLv8tNIQ7sSwE/YOX/D/Q==", + "dev": true + }, "lodash.tail": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.tail/-/lodash.tail-4.1.1.tgz", diff --git a/package.json b/package.json index d000390..64b81a9 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@types/react": "^16.8.15", "@types/react-dom": "^16.8.4", "@types/react-redux": "^7.0.8", + "@types/redux-promise": "^0.5.28", "@typescript-eslint/eslint-plugin": "^1.7.0", "babel-eslint": "^10.0.1", "babel-loader": "^8.0.5", From 0452370df43cc4263f268e7064f824d7e6e489b3 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 1 May 2019 23:10:37 +0900 Subject: [PATCH 15/24] Types on src/console --- src/background/usecases/CompletionsUseCase.ts | 12 +-- src/console/actions/console.ts | 34 +++++---- src/console/actions/index.ts | 76 +++++++++++++++---- src/console/components/Console.tsx | 43 ++++++----- src/console/components/console/Completion.tsx | 45 ++++++----- .../components/console/CompletionItem.tsx | 9 ++- .../components/console/CompletionTitle.tsx | 11 ++- src/console/components/console/Input.tsx | 31 +++++--- src/console/components/console/Message.tsx | 13 ++-- src/console/index.tsx | 10 +-- src/console/reducers/index.ts | 23 ++++-- test/console/actions/console.test.ts | 2 +- test/console/reducers/console.test.ts | 2 +- 13 files changed, 206 insertions(+), 105 deletions(-) diff --git a/src/background/usecases/CompletionsUseCase.ts b/src/background/usecases/CompletionsUseCase.ts index 037d6eb..f3a808b 100644 --- a/src/background/usecases/CompletionsUseCase.ts +++ b/src/background/usecases/CompletionsUseCase.ts @@ -1,4 +1,3 @@ -import Completions from '../domains/Completions'; import CompletionGroup from '../domains/CompletionGroup'; import CommandDocs from '../domains/CommandDocs'; import CompletionsRepository from '../repositories/CompletionsRepository'; @@ -25,7 +24,7 @@ export default class CompletionsUseCase { this.settingRepository = new SettingRepository(); } - queryConsoleCommand(prefix: string): Promise { + queryConsoleCommand(prefix: string): Promise { let keys = Object.keys(CommandDocs); let items = keys .filter(name => name.startsWith(prefix)) @@ -38,10 +37,10 @@ export default class CompletionsUseCase { if (items.length === 0) { return Promise.resolve([]); } - return Promise.resolve([{ name: 'Console CompletionGroup', items }]); + return Promise.resolve([{ name: 'Console Command', items }]); } - async queryOpen(name: string, keywords: string): Promise { + async queryOpen(name: string, keywords: string): Promise { let settings = await this.settingRepository.get(); let groups: CompletionGroup[] = []; @@ -71,7 +70,10 @@ export default class CompletionsUseCase { } // eslint-disable-next-line max-statements - async queryBuffer(name: string, keywords: string): Promise { + async queryBuffer( + name: string, + keywords: string, + ): Promise { let lastId = await this.tabPresenter.getLastSelectedId(); let trimmed = keywords.trim(); let tabs: Tab[] = []; diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts index 3713a76..ceb419c 100644 --- a/src/console/actions/console.ts +++ b/src/console/actions/console.ts @@ -1,40 +1,40 @@ -import messages from 'shared/messages'; -import actions from 'console/actions'; +import messages from '../../shared/messages'; +import * as actions from './index'; -const hide = () => { +const hide = (): actions.ConsoleAction => { return { type: actions.CONSOLE_HIDE, }; }; -const showCommand = (text) => { +const showCommand = (text: string): actions.ConsoleAction => { return { type: actions.CONSOLE_SHOW_COMMAND, text: text }; }; -const showFind = () => { +const showFind = (): actions.ConsoleAction => { return { type: actions.CONSOLE_SHOW_FIND, }; }; -const showError = (text) => { +const showError = (text: string): actions.ConsoleAction => { return { type: actions.CONSOLE_SHOW_ERROR, text: text }; }; -const showInfo = (text) => { +const showInfo = (text: string): actions.ConsoleAction => { return { type: actions.CONSOLE_SHOW_INFO, text: text }; }; -const hideCommand = () => { +const hideCommand = (): actions.ConsoleAction => { window.top.postMessage(JSON.stringify({ type: messages.CONSOLE_UNFOCUS, }), '*'); @@ -43,15 +43,17 @@ const hideCommand = () => { }; }; -const enterCommand = async(text) => { +const enterCommand = async( + text: string, +): Promise => { await browser.runtime.sendMessage({ type: messages.CONSOLE_ENTER_COMMAND, text, }); - return hideCommand(text); + return hideCommand(); }; -const enterFind = (text) => { +const enterFind = (text: string): actions.ConsoleAction => { window.top.postMessage(JSON.stringify({ type: messages.CONSOLE_ENTER_FIND, text, @@ -59,14 +61,14 @@ const enterFind = (text) => { return hideCommand(); }; -const setConsoleText = (consoleText) => { +const setConsoleText = (consoleText: string): actions.ConsoleAction => { return { type: actions.CONSOLE_SET_CONSOLE_TEXT, consoleText, }; }; -const getCompletions = async(text) => { +const getCompletions = async(text: string): Promise => { let completions = await browser.runtime.sendMessage({ type: messages.CONSOLE_QUERY_COMPLETIONS, text, @@ -78,13 +80,13 @@ const getCompletions = async(text) => { }; }; -const completionNext = () => { +const completionNext = (): actions.ConsoleAction => { return { type: actions.CONSOLE_COMPLETION_NEXT, }; }; -const completionPrev = () => { +const completionPrev = (): actions.ConsoleAction => { return { type: actions.CONSOLE_COMPLETION_PREV, }; @@ -92,5 +94,5 @@ const completionPrev = () => { export { hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, - enterCommand, enterFind, getCompletions, completionNext, completionPrev + enterCommand, enterFind, getCompletions, completionNext, completionPrev, }; diff --git a/src/console/actions/index.ts b/src/console/actions/index.ts index b394179..3770496 100644 --- a/src/console/actions/index.ts +++ b/src/console/actions/index.ts @@ -1,13 +1,63 @@ -export default { - // console commands - CONSOLE_HIDE: 'console.hide', - CONSOLE_SHOW_COMMAND: 'console.show.command', - CONSOLE_SHOW_ERROR: 'console.show.error', - CONSOLE_SHOW_INFO: 'console.show.info', - CONSOLE_HIDE_COMMAND: 'console.hide.command', - CONSOLE_SET_CONSOLE_TEXT: 'console.set.command', - CONSOLE_SET_COMPLETIONS: 'console.set.completions', - CONSOLE_COMPLETION_NEXT: 'console.completion.next', - CONSOLE_COMPLETION_PREV: 'console.completion.prev', - CONSOLE_SHOW_FIND: 'console.show.find', -}; +// console commands +export const CONSOLE_HIDE = 'console.hide'; +export const CONSOLE_SHOW_COMMAND = 'console.show.command'; +export const CONSOLE_SHOW_ERROR = 'console.show.error'; +export const CONSOLE_SHOW_INFO = 'console.show.info'; +export const CONSOLE_HIDE_COMMAND = 'console.hide.command'; +export const CONSOLE_SET_CONSOLE_TEXT = 'console.set.command'; +export const CONSOLE_SET_COMPLETIONS = 'console.set.completions'; +export const CONSOLE_COMPLETION_NEXT = 'console.completion.next'; +export const CONSOLE_COMPLETION_PREV = 'console.completion.prev'; +export const CONSOLE_SHOW_FIND = 'console.show.find'; + +interface HideAction { + type: typeof CONSOLE_HIDE; +} + +interface ShowCommand { + type: typeof CONSOLE_SHOW_COMMAND; + text: string; +} + +interface ShowFindAction { + type: typeof CONSOLE_SHOW_FIND; +} + +interface ShowErrorAction { + type: typeof CONSOLE_SHOW_ERROR; + text: string; +} + +interface ShowInfoAction { + type: typeof CONSOLE_SHOW_INFO; + text: string; +} + +interface HideCommandAction { + type: typeof CONSOLE_HIDE_COMMAND; +} + +interface SetConsoleTextAction { + type: typeof CONSOLE_SET_CONSOLE_TEXT; + consoleText: string; +} + +interface SetCompletionsAction { + type: typeof CONSOLE_SET_COMPLETIONS; + completions: any[]; + completionSource: string; +} + +interface CompletionNextAction { + type: typeof CONSOLE_COMPLETION_NEXT; +} + +interface CompletionPrevAction { + type: typeof CONSOLE_COMPLETION_PREV; +} + +export type ConsoleAction = + HideAction | ShowCommand | ShowFindAction | ShowErrorAction | + ShowInfoAction | HideCommandAction | SetConsoleTextAction | + SetCompletionsAction | CompletionNextAction | CompletionPrevAction; + diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx index 5427e43..09c0f50 100644 --- a/src/console/components/Console.tsx +++ b/src/console/components/Console.tsx @@ -1,7 +1,6 @@ import './console.scss'; import { connect } from 'react-redux'; import React from 'react'; -import PropTypes from 'prop-types'; import Input from './console/Input'; import Completion from './console/Completion'; import Message from './console/Message'; @@ -9,14 +8,29 @@ import * as consoleActions from '../../console/actions/console'; const COMPLETION_MAX_ITEMS = 33; -class Console extends React.Component { +interface Props { + mode?: string; + consoleText?: string; + messageText?: string; + children?: string; +} + +class Console extends React.Component { + private input: HTMLInputElement | null; + + constructor(props: Props) { + super(props); + + this.input = null; + } + onBlur() { if (this.props.mode === 'command' || this.props.mode === 'find') { return this.props.dispatch(consoleActions.hideCommand()); } } - doEnter(e) { + doEnter(e: React.KeyboardEvent) { e.stopPropagation(); e.preventDefault(); @@ -28,19 +42,19 @@ class Console extends React.Component { } } - selectNext(e) { + selectNext(e: React.KeyboardEvent) { this.props.dispatch(consoleActions.completionNext()); e.stopPropagation(); e.preventDefault(); } - selectPrev(e) { + selectPrev(e: React.KeyboardEvent) { this.props.dispatch(consoleActions.completionPrev()); e.stopPropagation(); e.preventDefault(); } - onKeyDown(e) { + onKeyDown(e: React.KeyboardEvent) { if (e.keyCode === KeyboardEvent.DOM_VK_ESCAPE && e.ctrlKey) { this.props.dispatch(consoleActions.hideCommand()); } @@ -81,7 +95,7 @@ class Console extends React.Component { } } - onChange(e) { + onChange(e: React.ChangeEvent) { let text = e.target.value; this.props.dispatch(consoleActions.setConsoleText(text)); if (this.props.mode === 'command') { @@ -90,7 +104,7 @@ class Console extends React.Component { } - componentDidUpdate(prevProps) { + componentDidUpdate(prevProps: Props) { if (!this.input) { return; } @@ -134,16 +148,11 @@ class Console extends React.Component { focus() { window.focus(); - this.input.focus(); + if (this.input) { + this.input.focus(); + } } } -Console.propTypes = { - mode: PropTypes.string, - consoleText: PropTypes.string, - messageText: PropTypes.string, - children: PropTypes.string, -}; - -const mapStateToProps = state => state; +const mapStateToProps = (state: any) => state; export default connect(mapStateToProps)(Console); diff --git a/src/console/components/console/Completion.tsx b/src/console/components/console/Completion.tsx index 5477cb6..169a39c 100644 --- a/src/console/components/console/Completion.tsx +++ b/src/console/components/console/Completion.tsx @@ -1,15 +1,36 @@ import React from 'react'; -import PropTypes from 'prop-types'; import CompletionItem from './CompletionItem'; import CompletionTitle from './CompletionTitle'; -class Completion extends React.Component { - constructor() { - super(); +interface Item { + icon?: string; + caption?: string; + url?: string; +} + +interface Group { + name: string; + items: Item[]; +} + +interface Props { + select: number; + size: number; + completions: Group[]; +} + +interface State { + viewOffset: number; + select: number; +} + +class Completion extends React.Component { + constructor(props: Props) { + super(props); this.state = { viewOffset: 0, select: -1 }; } - static getDerivedStateFromProps(nextProps, prevState) { + static getDerivedStateFromProps(nextProps: Props, prevState: State) { if (prevState.select === nextProps.select) { return null; } @@ -24,6 +45,7 @@ class Completion extends React.Component { } index += g.items.length; } + return -1; })(); let viewOffset = 0; @@ -70,17 +92,4 @@ class Completion extends React.Component { } } -Completion.propTypes = { - select: PropTypes.number, - size: PropTypes.number, - completions: PropTypes.arrayOf(PropTypes.shape({ - name: PropTypes.string, - items: PropTypes.arrayOf(PropTypes.shape({ - icon: PropTypes.string, - caption: PropTypes.string, - url: PropTypes.string, - })), - })), -}; - export default Completion; diff --git a/src/console/components/console/CompletionItem.tsx b/src/console/components/console/CompletionItem.tsx index 3dc552b..1cbf3de 100644 --- a/src/console/components/console/CompletionItem.tsx +++ b/src/console/components/console/CompletionItem.tsx @@ -1,7 +1,14 @@ import React from 'react'; import PropTypes from 'prop-types'; -const CompletionItem = (props) => { +interface Props { + highlight: boolean; + caption?: string; + url?: string; + icon?: string; +} + +const CompletionItem = (props: Props) => { let className = 'vimvixen-console-completion-item'; if (props.highlight) { className += ' vimvixen-completion-selected'; diff --git a/src/console/components/console/CompletionTitle.tsx b/src/console/components/console/CompletionTitle.tsx index 4fcba3f..2543619 100644 --- a/src/console/components/console/CompletionTitle.tsx +++ b/src/console/components/console/CompletionTitle.tsx @@ -1,14 +1,13 @@ import React from 'react'; -import PropTypes from 'prop-types'; -const CompletionTitle = (props) => { +interface Props { + title: string; +} + +const CompletionTitle = (props: Props) => { return
  • {props.title}
  • ; }; -CompletionTitle.propTypes = { - title: PropTypes.string, -}; - export default CompletionTitle; diff --git a/src/console/components/console/Input.tsx b/src/console/components/console/Input.tsx index cbd3348..d0348bd 100644 --- a/src/console/components/console/Input.tsx +++ b/src/console/components/console/Input.tsx @@ -1,9 +1,26 @@ import React from 'react'; -import PropTypes from 'prop-types'; -class Input extends React.Component { +interface Props { + mode: string; + value: string; + onBlur: (e: React.FocusEvent) => void; + onKeyDown: (e: React.KeyboardEvent) => void; + onChange: (e: React.ChangeEvent) => void; +} + +class Input extends React.Component { + private input: HTMLInputElement | null; + + constructor(props: Props) { + super(props); + + this.input = null; + } + focus() { - this.input.focus(); + if (this.input) { + this.input.focus(); + } } render() { @@ -32,12 +49,4 @@ class Input extends React.Component { } } -Input.propTypes = { - mode: PropTypes.string, - value: PropTypes.string, - onBlur: PropTypes.func, - onKeyDown: PropTypes.func, - onChange: PropTypes.func, -}; - export default Input; diff --git a/src/console/components/console/Message.tsx b/src/console/components/console/Message.tsx index dd96248..07a929e 100644 --- a/src/console/components/console/Message.tsx +++ b/src/console/components/console/Message.tsx @@ -1,7 +1,11 @@ import React from 'react'; -import PropTypes from 'prop-types'; -const Message = (props) => { +interface Props { + mode: string; + children: string[]; +} + +const Message = (props: Props) => { switch (props.mode) { case 'error': return ( @@ -16,10 +20,7 @@ const Message = (props) => {

    ); } -}; - -Message.propTypes = { - children: PropTypes.string, + return null; }; export default Message; diff --git a/src/console/index.tsx b/src/console/index.tsx index 3190a9a..ee3a8ee 100644 --- a/src/console/index.tsx +++ b/src/console/index.tsx @@ -1,8 +1,8 @@ -import messages from 'shared/messages'; -import reducers from 'console/reducers'; +import messages from '../shared/messages'; +import reducers from './reducers'; import { createStore, applyMiddleware } from 'redux'; import promise from 'redux-promise'; -import * as consoleActions from 'console/actions/console'; +import * as consoleActions from './actions/console'; import { Provider } from 'react-redux'; import Console from './components/Console'; import React from 'react'; @@ -22,7 +22,7 @@ window.addEventListener('load', () => { wrapper); }); -const onMessage = (message) => { +const onMessage = (message: any): any => { switch (message.type) { case messages.CONSOLE_SHOW_COMMAND: return store.dispatch(consoleActions.showCommand(message.command)); @@ -38,5 +38,5 @@ const onMessage = (message) => { }; browser.runtime.onMessage.addListener(onMessage); -let port = browser.runtime.connect({ name: 'vimvixen-console' }); +let port = browser.runtime.connect(undefined, { name: 'vimvixen-console' }); port.onMessage.addListener(onMessage); diff --git a/src/console/reducers/index.ts b/src/console/reducers/index.ts index 614a72f..37ed715 100644 --- a/src/console/reducers/index.ts +++ b/src/console/reducers/index.ts @@ -1,4 +1,14 @@ -import actions from 'console/actions'; +import * as actions from '../actions'; + +interface State { + mode: string; + messageText: string; + consoleText: string; + completionSource: string; + completions: any[], + select: number; + viewIndex: number; +} const defaultState = { mode: '', @@ -10,7 +20,7 @@ const defaultState = { viewIndex: 0, }; -const nextSelection = (state) => { +const nextSelection = (state: State): number => { if (state.completions.length === 0) { return -1; } @@ -27,7 +37,7 @@ const nextSelection = (state) => { return -1; }; -const prevSelection = (state) => { +const prevSelection = (state: State): number => { let length = state.completions .map(g => g.items.length) .reduce((x, y) => x + y); @@ -37,7 +47,7 @@ const prevSelection = (state) => { return state.select - 1; }; -const nextConsoleText = (completions, select, defaults) => { +const nextConsoleText = (completions: any[], select: number, defaults: any) => { if (select < 0) { return defaults; } @@ -46,7 +56,10 @@ const nextConsoleText = (completions, select, defaults) => { }; // eslint-disable-next-line max-lines-per-function -export default function reducer(state = defaultState, action = {}) { +export default function reducer( + state: State = defaultState, + action: actions.ConsoleAction, +): State { switch (action.type) { case actions.CONSOLE_HIDE: return { ...state, diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts index 10cd9fe..e45d008 100644 --- a/test/console/actions/console.test.ts +++ b/test/console/actions/console.test.ts @@ -1,4 +1,4 @@ -import actions from 'console/actions'; +import * as actions from 'console/actions'; import * as consoleActions from 'console/actions/console'; describe("console actions", () => { diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts index d5a38cf..47e7daf 100644 --- a/test/console/reducers/console.test.ts +++ b/test/console/reducers/console.test.ts @@ -1,4 +1,4 @@ -import actions from 'console/actions'; +import * as actions from 'console/actions'; import reducer from 'console/reducers'; describe("console reducer", () => { From c059bf8be3b302173f2cab0d22a434aea4a6e0bd Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 2 May 2019 10:40:29 +0900 Subject: [PATCH 16/24] Install @babel/plugin-proposal-class-properties --- package-lock.json | 149 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 150 insertions(+) diff --git a/package-lock.json b/package-lock.json index 731b471..a13a3b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -196,6 +196,42 @@ "esutils": "^2.0.0" } }, + "@babel/helper-create-class-features-plugin": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.4.4.tgz", + "integrity": "sha512-UbBHIa2qeAGgyiNR9RszVF7bUHEdgS4JAUNT8SiqrAN6YJVxlOxeLr5pBzb5kan302dejJ9nla4RyKcR1XT6XA==", + "dev": true, + "requires": { + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-member-expression-to-functions": "^7.0.0", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/helper-replace-supers": "^7.4.4", + "@babel/helper-split-export-declaration": "^7.4.4" + }, + "dependencies": { + "@babel/helper-split-export-declaration": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", + "integrity": "sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4" + } + }, + "@babel/types": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.4.tgz", + "integrity": "sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + } + } + }, "@babel/helper-function-name": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.1.0.tgz", @@ -216,12 +252,115 @@ "@babel/types": "^7.0.0" } }, + "@babel/helper-member-expression-to-functions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.0.0.tgz", + "integrity": "sha512-avo+lm/QmZlv27Zsi0xEor2fKcqWG56D5ae9dzklpIaY7cQMK5N8VSpaNVPPagiqmy7LrEjK1IWdGMOqPu5csg==", + "dev": true, + "requires": { + "@babel/types": "^7.0.0" + } + }, + "@babel/helper-optimise-call-expression": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.0.0.tgz", + "integrity": "sha512-u8nd9NQePYNQV8iPWu/pLLYBqZBa4ZaY1YWRFMuxrid94wKI1QNt67NEZ7GAe5Kc/0LLScbim05xZFWkAdrj9g==", + "dev": true, + "requires": { + "@babel/types": "^7.0.0" + } + }, "@babel/helper-plugin-utils": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz", "integrity": "sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==", "dev": true }, + "@babel/helper-replace-supers": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.4.4.tgz", + "integrity": "sha512-04xGEnd+s01nY1l15EuMS1rfKktNF+1CkKmHoErDppjAAZL+IUBZpzT748x262HF7fibaQPhbvWUl5HeSt1EXg==", + "dev": true, + "requires": { + "@babel/helper-member-expression-to-functions": "^7.0.0", + "@babel/helper-optimise-call-expression": "^7.0.0", + "@babel/traverse": "^7.4.4", + "@babel/types": "^7.4.4" + }, + "dependencies": { + "@babel/generator": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.4.4.tgz", + "integrity": "sha512-53UOLK6TVNqKxf7RUh8NE851EHRxOOeVXKbK2bivdb+iziMyk03Sr4eaE9OELCbyZAAafAKPDwF2TPUES5QbxQ==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4", + "jsesc": "^2.5.1", + "lodash": "^4.17.11", + "source-map": "^0.5.0", + "trim-right": "^1.0.1" + } + }, + "@babel/helper-split-export-declaration": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz", + "integrity": "sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q==", + "dev": true, + "requires": { + "@babel/types": "^7.4.4" + } + }, + "@babel/parser": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.4.tgz", + "integrity": "sha512-5pCS4mOsL+ANsFZGdvNLybx4wtqAZJ0MJjMHxvzI3bvIsz6sQvzW8XX92EYIkiPtIvcfG3Aj+Ir5VNyjnZhP7w==", + "dev": true + }, + "@babel/traverse": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.4.4.tgz", + "integrity": "sha512-Gw6qqkw/e6AGzlyj9KnkabJX7VcubqPtkUQVAwkc0wUMldr3A/hezNB3Rc5eIvId95iSGkGIOe5hh1kMKf951A==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.0.0", + "@babel/generator": "^7.4.4", + "@babel/helper-function-name": "^7.1.0", + "@babel/helper-split-export-declaration": "^7.4.4", + "@babel/parser": "^7.4.4", + "@babel/types": "^7.4.4", + "debug": "^4.1.0", + "globals": "^11.1.0", + "lodash": "^4.17.11" + } + }, + "@babel/types": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.4.4.tgz", + "integrity": "sha512-dOllgYdnEFOebhkKCjzSVFqw/PmmB8pH6RGOWkY4GsboQNd47b1fBThBSwlHAq9alF9vc1M3+6oqR47R50L0tQ==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.11", + "to-fast-properties": "^2.0.0" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true + } + } + }, "@babel/helper-split-export-declaration": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz", @@ -386,6 +525,16 @@ "integrity": "sha512-ATz6yX/L8LEnC3dtLQnIx4ydcPxhLcoy9Vl6re00zb2w5lG6itY6Vhnr1KFRPq/FHNsgl/gh2mjNN20f9iJTTA==", "dev": true }, + "@babel/plugin-proposal-class-properties": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.4.4.tgz", + "integrity": "sha512-WjKTI8g8d5w1Bc9zgwSz2nfrsNQsXcCf9J9cdCvrJV6RF56yztwm4TmJC0MgJ9tvwO9gUA/mcYe89bLdGfiXFg==", + "dev": true, + "requires": { + "@babel/helper-create-class-features-plugin": "^7.4.4", + "@babel/helper-plugin-utils": "^7.0.0" + } + }, "@babel/plugin-syntax-jsx": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.2.0.tgz", diff --git a/package.json b/package.json index 64b81a9..00fa97d 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "devDependencies": { "@babel/cli": "^7.4.4", "@babel/core": "^7.4.4", + "@babel/plugin-proposal-class-properties": "^7.4.4", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.3.3", "@types/prop-types": "^15.7.1", From e69497fab457df486b2a7068bdd0283505461f8b Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 2 May 2019 11:12:28 +0900 Subject: [PATCH 17/24] Types src/settings --- src/settings/actions/index.ts | 39 +++++++++++--- src/settings/actions/setting.ts | 18 +++---- .../components/form/BlacklistForm.tsx | 28 +++++----- src/settings/components/form/KeymapsForm.tsx | 32 ++++++------ .../components/form/PropertiesForm.tsx | 32 +++++++----- src/settings/components/form/SearchForm.tsx | 38 +++++++------- src/settings/components/index.tsx | 44 +++++++++------- src/settings/components/ui/AddButton.tsx | 5 +- src/settings/components/ui/DeleteButton.tsx | 5 +- src/settings/components/ui/Input.tsx | 52 +++++++++++++------ src/settings/reducers/setting.ts | 16 ++++-- test/settings/reducers/setting.test.ts | 2 +- 12 files changed, 194 insertions(+), 117 deletions(-) diff --git a/src/settings/actions/index.ts b/src/settings/actions/index.ts index 016f2a5..75c6bb5 100644 --- a/src/settings/actions/index.ts +++ b/src/settings/actions/index.ts @@ -1,7 +1,32 @@ -export default { - // Settings - SETTING_SET_SETTINGS: 'setting.set.settings', - SETTING_SHOW_ERROR: 'setting.show.error', - SETTING_SWITCH_TO_FORM: 'setting.switch.to.form', - SETTING_SWITCH_TO_JSON: 'setting.switch.to.json', -}; +// Settings +export const SETTING_SET_SETTINGS = 'setting.set.settings'; +export const SETTING_SHOW_ERROR = 'setting.show.error'; +export const SETTING_SWITCH_TO_FORM = 'setting.switch.to.form'; +export const SETTING_SWITCH_TO_JSON = 'setting.switch.to.json'; + +interface SettingSetSettingsAcion { + type: typeof SETTING_SET_SETTINGS; + source: string; + json: string; + form: any; +} + +interface SettingShowErrorAction { + type: typeof SETTING_SHOW_ERROR; + error: string; + json: string; +} + +interface SettingSwitchToFormAction { + type: typeof SETTING_SWITCH_TO_FORM; + form: any; +} + +interface SettingSwitchToJsonAction { + type: typeof SETTING_SWITCH_TO_JSON; + json: string; +} + +export type SettingAction = + SettingSetSettingsAcion | SettingShowErrorAction | + SettingSwitchToFormAction | SettingSwitchToJsonAction; diff --git a/src/settings/actions/setting.ts b/src/settings/actions/setting.ts index db63a45..b03cd80 100644 --- a/src/settings/actions/setting.ts +++ b/src/settings/actions/setting.ts @@ -1,15 +1,15 @@ -import actions from 'settings/actions'; -import * as validator from 'shared/settings/validator'; -import * as settingsValues from 'shared/settings/values'; -import * as settingsStorage from 'shared/settings/storage'; +import * as actions from './index'; +import * as validator from '../../shared/settings/validator'; +import * as settingsValues from '../../shared/settings/values'; +import * as settingsStorage from '../../shared/settings/storage'; import keymaps from '../keymaps'; -const load = async() => { +const load = async(): Promise => { let settings = await settingsStorage.loadRaw(); return set(settings); }; -const save = async(settings) => { +const save = async(settings: any): Promise => { try { if (settings.source === 'json') { let value = JSON.parse(settings.json); @@ -26,7 +26,7 @@ const save = async(settings) => { return set(settings); }; -const switchToForm = (json) => { +const switchToForm = (json: string): actions.SettingAction => { try { validator.validate(JSON.parse(json)); let form = settingsValues.formFromJson(json, keymaps.allowedOps); @@ -43,7 +43,7 @@ const switchToForm = (json) => { } }; -const switchToJson = (form) => { +const switchToJson = (form: any): actions.SettingAction => { let json = settingsValues.jsonFromForm(form); return { type: actions.SETTING_SWITCH_TO_JSON, @@ -51,7 +51,7 @@ const switchToJson = (form) => { }; }; -const set = (settings) => { +const set = (settings: any): actions.SettingAction => { return { type: actions.SETTING_SET_SETTINGS, source: settings.source, diff --git a/src/settings/components/form/BlacklistForm.tsx b/src/settings/components/form/BlacklistForm.tsx index c470758..637bc1e 100644 --- a/src/settings/components/form/BlacklistForm.tsx +++ b/src/settings/components/form/BlacklistForm.tsx @@ -2,9 +2,19 @@ import './BlacklistForm.scss'; import AddButton from '../ui/AddButton'; import DeleteButton from '../ui/DeleteButton'; import React from 'react'; -import PropTypes from 'prop-types'; -class BlacklistForm extends React.Component { +interface Props { + value: string[]; + onChange: (value: string[]) => void; + onBlur: () => void; +} + +class BlacklistForm extends React.Component { + public static defaultProps: Props = { + value: [], + onChange: () => {}, + onBlur: () => {}, + }; render() { return
    @@ -28,7 +38,7 @@ class BlacklistForm extends React.Component {
    ; } - bindValue(e) { + bindValue(e: any) { let name = e.target.name; let index = e.target.getAttribute('data-index'); let next = this.props.value ? this.props.value.slice() : []; @@ -48,16 +58,4 @@ class BlacklistForm extends React.Component { } } -BlacklistForm.propTypes = { - value: PropTypes.arrayOf(PropTypes.string), - onChange: PropTypes.func, - onBlur: PropTypes.func, -}; - -BlacklistForm.defaultProps = { - value: [], - onChange: () => {}, - onBlur: () => {}, -}; - export default BlacklistForm; diff --git a/src/settings/components/form/KeymapsForm.tsx b/src/settings/components/form/KeymapsForm.tsx index 01acf61..ab44464 100644 --- a/src/settings/components/form/KeymapsForm.tsx +++ b/src/settings/components/form/KeymapsForm.tsx @@ -1,10 +1,22 @@ import './KeymapsForm.scss'; import React from 'react'; -import PropTypes from 'prop-types'; import Input from '../ui/Input'; import keymaps from '../../keymaps'; -class KeymapsForm extends React.Component { +type Value = {[key: string]: string}; + +interface Props{ + value: Value; + onChange: (e: Value) => void; + onBlur: () => void; +} + +class KeymapsForm extends React.Component { + public static defaultProps: Props = { + value: {}, + onChange: () => {}, + onBlur: () => {}, + } render() { return
    @@ -19,7 +31,7 @@ class KeymapsForm extends React.Component { return ; }) @@ -30,22 +42,12 @@ class KeymapsForm extends React.Component {
    ; } - bindValue(e) { + bindValue(name: string, value: string) { let next = { ...this.props.value }; - next[e.target.name] = e.target.value; + next[name] = value; this.props.onChange(next); } } -KeymapsForm.propTypes = { - value: PropTypes.objectOf(PropTypes.string), - onChange: PropTypes.func, -}; - -KeymapsForm.defaultProps = { - value: {}, - onChange: () => {}, -}; - export default KeymapsForm; diff --git a/src/settings/components/form/PropertiesForm.tsx b/src/settings/components/form/PropertiesForm.tsx index 979fdd8..0be5f5c 100644 --- a/src/settings/components/form/PropertiesForm.tsx +++ b/src/settings/components/form/PropertiesForm.tsx @@ -1,8 +1,20 @@ import './PropertiesForm.scss'; import React from 'react'; -import PropTypes from 'prop-types'; -class PropertiesForm extends React.Component { +interface Props { + types: {[key: string]: string}; + value: {[key: string]: any}; + onChange: (value: any) => void; + onBlur: () => void; +} + +class PropertiesForm extends React.Component { + public static defaultProps: Props = { + types: {}, + value: {}, + onChange: () => {}, + onBlur: () => {}, + }; render() { let types = this.props.types; @@ -12,13 +24,15 @@ class PropertiesForm extends React.Component { { Object.keys(types).map((name) => { let type = types[name]; - let inputType = null; + let inputType = ''; if (type === 'string') { inputType = 'text'; } else if (type === 'number') { inputType = 'number'; } else if (type === 'boolean') { inputType = 'checkbox'; + } else { + return null; } return
    ; } - bindValue(e) { + bindValue(e: React.ChangeEvent) { let name = e.target.name; let next = { ...this.props.value }; if (e.target.type.toLowerCase() === 'checkbox') { @@ -52,14 +66,4 @@ class PropertiesForm extends React.Component { } } -PropertiesForm.propTypes = { - value: PropTypes.objectOf(PropTypes.any), - onChange: PropTypes.func, -}; - -PropertiesForm.defaultProps = { - value: {}, - onChange: () => {}, -}; - export default PropertiesForm; diff --git a/src/settings/components/form/SearchForm.tsx b/src/settings/components/form/SearchForm.tsx index 6b0bd01..737e291 100644 --- a/src/settings/components/form/SearchForm.tsx +++ b/src/settings/components/form/SearchForm.tsx @@ -1,10 +1,25 @@ import './SearchForm.scss'; import React from 'react'; -import PropTypes from 'prop-types'; import AddButton from '../ui/AddButton'; import DeleteButton from '../ui/DeleteButton'; -class SearchForm extends React.Component { +interface Value { + default: string; + engines: string[][]; +} + +interface Props { + value: Value; + onChange: (value: Value) => void; + onBlur: () => void; +} + +class SearchForm extends React.Component { + public static defaultProps: Props = { + value: { default: '', engines: []}, + onChange: () => {}, + onBlur: () => {}, + } render() { let value = this.props.value; @@ -47,11 +62,11 @@ class SearchForm extends React.Component { ; } - bindValue(e) { + bindValue(e: any) { let value = this.props.value; let name = e.target.name; - let index = e.target.getAttribute('data-index'); - let next = { + let index = Number(e.target.getAttribute('data-index')); + let next: Value = { default: value.default, engines: value.engines ? value.engines.slice() : [], }; @@ -76,17 +91,4 @@ class SearchForm extends React.Component { } } -SearchForm.propTypes = { - value: PropTypes.shape({ - default: PropTypes.string, - engines: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.string)), - }), - onChange: PropTypes.func, -}; - -SearchForm.defaultProps = { - value: { default: '', engines: []}, - onChange: () => {}, -}; - export default SearchForm; diff --git a/src/settings/components/index.tsx b/src/settings/components/index.tsx index 4ef59d7..f56e93f 100644 --- a/src/settings/components/index.tsx +++ b/src/settings/components/index.tsx @@ -6,19 +6,29 @@ import SearchForm from './form/SearchForm'; import KeymapsForm from './form/KeymapsForm'; import BlacklistForm from './form/BlacklistForm'; import PropertiesForm from './form/PropertiesForm'; -import * as properties from 'shared/settings/properties'; -import * as settingActions from 'settings/actions/setting'; +import * as properties from '../../shared/settings/properties'; +import * as settingActions from '../../settings/actions/setting'; const DO_YOU_WANT_TO_CONTINUE = 'Some settings in JSON can be lost when migrating. ' + 'Do you want to continue?'; -class SettingsComponent extends React.Component { +interface Props { + source: string; + json: string; + form: any; + error: string; + + // FIXME + store: any; +} + +class SettingsComponent extends React.Component { componentDidMount() { this.props.dispatch(settingActions.load()); } - renderFormFields(form) { + renderFormFields(form: any) { return
    Keybindings @@ -56,15 +66,15 @@ class SettingsComponent extends React.Component {
    ; } - renderJsonFields(json, error) { + renderJsonFields(json: string, error: string) { return
    @@ -90,7 +100,7 @@ class SettingsComponent extends React.Component { label='Use form' checked={this.props.source === 'form'} value='form' - onChange={this.bindSource.bind(this)} + onValueChange={this.bindSource.bind(this)} disabled={disabled} /> { fields } @@ -107,7 +117,7 @@ class SettingsComponent extends React.Component { ); } - bindForm(name, value) { + bindForm(name: string, value: any) { let settings = { source: this.props.source, json: this.props.json, @@ -117,22 +127,20 @@ class SettingsComponent extends React.Component { this.props.dispatch(settingActions.set(settings)); } - bindJson(e) { + bindJson(_name: string, value: string) { let settings = { source: this.props.source, - json: e.target.value, + json: value, form: this.props.form, }; this.props.dispatch(settingActions.set(settings)); } - bindSource(e) { + bindSource(_name: string, value: string) { let from = this.props.source; - let to = e.target.value; - - if (from === 'form' && to === 'json') { + if (from === 'form' && value === 'json') { this.props.dispatch(settingActions.switchToJson(this.props.form)); - } else if (from === 'json' && to === 'form') { + } else if (from === 'json' && value === 'form') { let b = window.confirm(DO_YOU_WANT_TO_CONTINUE); if (!b) { this.forceUpdate(); @@ -148,6 +156,6 @@ class SettingsComponent extends React.Component { } } -const mapStateToProps = state => state; +const mapStateToProps = (state: any) => state; export default connect(mapStateToProps)(SettingsComponent); diff --git a/src/settings/components/ui/AddButton.tsx b/src/settings/components/ui/AddButton.tsx index 185a03b..0577068 100644 --- a/src/settings/components/ui/AddButton.tsx +++ b/src/settings/components/ui/AddButton.tsx @@ -1,7 +1,10 @@ import './AddButton.scss'; import React from 'react'; -class AddButton extends React.Component { +interface Props extends React.AllHTMLAttributes { +} + +class AddButton extends React.Component { render() { return { +} + +class DeleteButton extends React.Component { render() { return { + name: string; + type: string; + error?: string; + label: string; + value: string; + onValueChange?: (name: string, value: string) => void; + onBlur?: (e: React.FocusEvent) => void; +} - renderText(props) { +class Input extends React.Component { + renderText(props: Props) { let inputClassName = props.error ? 'input-error' : ''; + let pp = { ...props }; + delete pp.onValueChange; return
    - +
    ; } - renderRadio(props) { + renderRadio(props: Props) { let inputClassName = props.error ? 'input-error' : ''; + let pp = { ...props }; + delete pp.onValueChange; return
    ; } - renderTextArea(props) { + renderTextArea(props: Props) { let inputClassName = props.error ? 'input-error' : ''; + let pp = { ...props }; + delete pp.onValueChange; return
    -