From bb2aba987294cd593a28d32bf6f3c745cca68bab Mon Sep 17 00:00:00 2001 From: hirohe Date: Tue, 22 Nov 2022 11:40:36 +0800 Subject: [PATCH 1/6] build: add typescript and eslint related deps --- package.json | 4 ++ yarn.lock | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 166 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bde7b051..1a0e0682 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "@babel/core": "^7.19.6", "@babel/preset-env": "^7.19.4", "@babel/register": "^7.18.9", + "@typescript-eslint/eslint-plugin": "^5.44.0", + "@typescript-eslint/parser": "^5.44.0", "autoprefixer": "^9.8.8", "babel-eslint": "^10.1.0", "babel-jest": "^27.0.2", @@ -47,6 +49,7 @@ "eslint": "^7.21.0", "eslint-config-algolia": "^16.0.0", "eslint-config-prettier": "^8.1.0", + "eslint-config-typescript": "^3.0.0", "eslint-plugin-cypress": "^2.12.1", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.22.0", @@ -59,6 +62,7 @@ "pretty-bytes-cli": "^2.0.0", "sass": "^1.55.0", "sinon": "^14.0.1", + "typescript": "^4.9.3", "uglify-js": "^3.17.4", "webpack": "^5.74.0", "webpack-cli": "^4.10.0" diff --git a/yarn.lock b/yarn.lock index 59da0e32..b9059534 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1529,6 +1529,11 @@ resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== +"@types/json-schema@^7.0.9": + version "7.0.11" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" + integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz" @@ -1559,6 +1564,11 @@ resolved "https://registry.npmjs.org/@types/q/-/q-1.5.4.tgz" integrity sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug== +"@types/semver@^7.3.12": + version "7.3.13" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" + integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== + "@types/sinonjs__fake-timers@^6.0.2": version "6.0.4" resolved "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.4.tgz" @@ -1600,6 +1610,21 @@ dependencies: "@types/node" "*" +"@typescript-eslint/eslint-plugin@^5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.44.0.tgz#105788f299050c917eb85c4d9fd04b089e3740de" + integrity sha512-j5ULd7FmmekcyWeArx+i8x7sdRHzAtXTkmDPthE4amxZOWKFK7bomoJ4r7PJ8K7PoMzD16U8MmuZFAonr1ERvw== + dependencies: + "@typescript-eslint/scope-manager" "5.44.0" + "@typescript-eslint/type-utils" "5.44.0" + "@typescript-eslint/utils" "5.44.0" + debug "^4.3.4" + ignore "^5.2.0" + natural-compare-lite "^1.4.0" + regexpp "^3.2.0" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/experimental-utils@^4.0.1": version "4.26.1" resolved "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.26.1.tgz" @@ -1612,6 +1637,16 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" +"@typescript-eslint/parser@^5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.44.0.tgz#99e2c710a2252191e7a79113264f438338b846ad" + integrity sha512-H7LCqbZnKqkkgQHaKLGC6KUjt3pjJDx8ETDqmwncyb6PuoigYajyAwBGz08VU/l86dZWZgI4zm5k2VaKqayYyA== + dependencies: + "@typescript-eslint/scope-manager" "5.44.0" + "@typescript-eslint/types" "5.44.0" + "@typescript-eslint/typescript-estree" "5.44.0" + debug "^4.3.4" + "@typescript-eslint/scope-manager@4.26.1": version "4.26.1" resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.26.1.tgz" @@ -1620,11 +1655,34 @@ "@typescript-eslint/types" "4.26.1" "@typescript-eslint/visitor-keys" "4.26.1" +"@typescript-eslint/scope-manager@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.44.0.tgz#988c3f34b45b3474eb9ff0674c18309dedfc3e04" + integrity sha512-2pKml57KusI0LAhgLKae9kwWeITZ7IsZs77YxyNyIVOwQ1kToyXRaJLl+uDEXzMN5hnobKUOo2gKntK9H1YL8g== + dependencies: + "@typescript-eslint/types" "5.44.0" + "@typescript-eslint/visitor-keys" "5.44.0" + +"@typescript-eslint/type-utils@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.44.0.tgz#bc5a6e8a0269850714a870c9268c038150dfb3c7" + integrity sha512-A1u0Yo5wZxkXPQ7/noGkRhV4J9opcymcr31XQtOzcc5nO/IHN2E2TPMECKWYpM3e6olWEM63fq/BaL1wEYnt/w== + dependencies: + "@typescript-eslint/typescript-estree" "5.44.0" + "@typescript-eslint/utils" "5.44.0" + debug "^4.3.4" + tsutils "^3.21.0" + "@typescript-eslint/types@4.26.1": version "4.26.1" resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.26.1.tgz" integrity sha512-STyMPxR3cS+LaNvS8yK15rb8Y0iL0tFXq0uyl6gY45glyI7w0CsyqyEXl/Fa0JlQy+pVANeK3sbwPneCbWE7yg== +"@typescript-eslint/types@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.44.0.tgz#f3f0b89aaff78f097a2927fe5688c07e786a0241" + integrity sha512-Tp+zDnHmGk4qKR1l+Y1rBvpjpm5tGXX339eAlRBDg+kgZkz9Bw+pqi4dyseOZMsGuSH69fYfPJCBKBrbPCxYFQ== + "@typescript-eslint/typescript-estree@4.26.1": version "4.26.1" resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.26.1.tgz" @@ -1638,6 +1696,33 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.44.0.tgz#0461b386203e8d383bb1268b1ed1da9bc905b045" + integrity sha512-M6Jr+RM7M5zeRj2maSfsZK2660HKAJawv4Ud0xT+yauyvgrsHu276VtXlKDFnEmhG+nVEd0fYZNXGoAgxwDWJw== + dependencies: + "@typescript-eslint/types" "5.44.0" + "@typescript-eslint/visitor-keys" "5.44.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + +"@typescript-eslint/utils@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.44.0.tgz#d733da4d79d6c30f1a68b531cdda1e0c1f00d52d" + integrity sha512-fMzA8LLQ189gaBjS0MZszw5HBdZgVwxVFShCO3QN+ws3GlPkcy9YuS3U4wkT6su0w+Byjq3mS3uamy9HE4Yfjw== + dependencies: + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.44.0" + "@typescript-eslint/types" "5.44.0" + "@typescript-eslint/typescript-estree" "5.44.0" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + semver "^7.3.7" + "@typescript-eslint/visitor-keys@4.26.1": version "4.26.1" resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.26.1.tgz" @@ -1646,6 +1731,14 @@ "@typescript-eslint/types" "4.26.1" eslint-visitor-keys "^2.0.0" +"@typescript-eslint/visitor-keys@5.44.0": + version "5.44.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.44.0.tgz#10740dc28902bb903d12ee3a005cc3a70207d433" + integrity sha512-a48tLG8/4m62gPFbJ27FxwCOqPKxsb8KC3HkmYoq2As/4YyjQl1jDbRr1s63+g4FS/iIehjmN3L5UjmKva1HzQ== + dependencies: + "@typescript-eslint/types" "5.44.0" + eslint-visitor-keys "^3.3.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz" @@ -3052,6 +3145,13 @@ debug@^3.1.0, debug@^3.2.7: dependencies: ms "^2.1.1" +debug@^4.3.4: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + decamelize@^1.1.2, decamelize@^1.2.0: version "1.2.0" resolved "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz" @@ -3354,6 +3454,11 @@ eslint-config-prettier@^8.1.0: resolved "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz" integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew== +eslint-config-typescript@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-typescript/-/eslint-config-typescript-3.0.0.tgz#13e0627f8c5aa8d58b5a01eeddd0a726a259c4b5" + integrity sha512-CwC2cQ29OLE1OUw0k+Twpc6wpCdenG8rrErl89sWrzmMpWfkulyeQS1HJhhjU0B3Tb4k41zdei4LtX26x5m60Q== + eslint-import-resolver-node@^0.3.4: version "0.3.4" resolved "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz" @@ -3452,6 +3557,11 @@ eslint-visitor-keys@^2.0.0: resolved "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz" integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw== +eslint-visitor-keys@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826" + integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA== + eslint@^7.21.0: version "7.28.0" resolved "https://registry.npmjs.org/eslint/-/eslint-7.28.0.tgz" @@ -3697,6 +3807,17 @@ fast-glob@^3.1.1: micromatch "^4.0.2" picomatch "^2.2.1" +fast-glob@^3.2.9: + version "3.2.12" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.12.tgz#7f39ec99c2e6ab030337142da9e0c18f37afae80" + integrity sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w== + dependencies: + "@nodelib/fs.stat" "^2.0.2" + "@nodelib/fs.walk" "^1.2.3" + glob-parent "^5.1.2" + merge2 "^1.3.0" + micromatch "^4.0.4" + fast-json-stable-stringify@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz" @@ -4031,6 +4152,18 @@ globby@^11.0.0, globby@^11.0.3: merge2 "^1.3.0" slash "^3.0.0" +globby@^11.1.0: + version "11.1.0" + resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" + integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== + dependencies: + array-union "^2.1.0" + dir-glob "^3.0.1" + fast-glob "^3.2.9" + ignore "^5.2.0" + merge2 "^1.4.1" + slash "^3.0.0" + graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.4, graceful-fs@^4.2.9: version "4.2.9" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" @@ -4215,6 +4348,11 @@ ignore@^5.0.5, ignore@^5.1.4: resolved "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz" integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw== +ignore@^5.2.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a" + integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== + immediate@^3.2.3: version "3.3.0" resolved "https://registry.npmjs.org/immediate/-/immediate-3.3.0.tgz" @@ -4492,7 +4630,7 @@ is-glob@^4.0.0: dependencies: is-extglob "^2.1.1" -is-glob@^4.0.1, is-glob@~4.0.1: +is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1: version "4.0.3" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg== @@ -5570,7 +5708,7 @@ merge-stream@^2.0.0: resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz" integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== -merge2@^1.3.0: +merge2@^1.3.0, merge2@^1.4.1: version "1.4.1" resolved "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== @@ -5680,6 +5818,11 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" +natural-compare-lite@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" + integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz" @@ -6756,6 +6899,11 @@ regexpp@^3.1.0: resolved "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz" integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q== +regexpp@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2" + integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg== + regexpu-core@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-5.1.0.tgz#2f8504c3fd0ebe11215783a41541e21c79942c6d" @@ -7018,6 +7166,13 @@ semver@^7.2.1, semver@^7.3.2, semver@^7.3.5: dependencies: lru-cache "^6.0.0" +semver@^7.3.7: + version "7.3.8" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798" + integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A== + dependencies: + lru-cache "^6.0.0" + serialize-javascript@^6.0.0: version "6.0.0" resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz" @@ -7695,6 +7850,11 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typescript@^4.9.3: + version "4.9.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db" + integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA== + uglify-js@^3.17.4: version "3.17.4" resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.17.4.tgz#61678cf5fa3f5b7eb789bb345df29afb8257c22c" From 80c2ea9cb052f74e822fee01042b0170b4dd7ac8 Mon Sep 17 00:00:00 2001 From: hirohe Date: Tue, 22 Nov 2022 11:42:22 +0800 Subject: [PATCH 2/6] chore: typescript related eslint config --- .eslintrc.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b2741674..1b89cb94 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,16 +1,18 @@ /* Using eslint-config-algolia */ /* eslint-disable import/no-commonjs */ module.exports = { + parser: '@typescript-eslint/parser', extends: [ 'algolia', 'algolia/jest', 'plugin:prettier/recommended', 'plugin:cypress/recommended', + 'plugin:@typescript-eslint/recommended', ], - plugins: ['prettier', 'cypress'], + plugins: ['prettier', 'cypress', '@typescript-eslint'], rules: { 'no-console': 0, - 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], 'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], 'prettier/prettier': [ 'error', From 6f7f44bfbfe1915784c10847f5a6154df29dfbf2 Mon Sep 17 00:00:00 2001 From: hirohe Date: Tue, 22 Nov 2022 11:43:24 +0800 Subject: [PATCH 3/6] feat: add index.d.ts --- index.d.ts | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 40 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 00000000..078357ad --- /dev/null +++ b/index.d.ts @@ -0,0 +1,39 @@ +import { SearchResponse, SearchParams, Hits, Config } from 'meilisearch' + +interface Options { + hostUrl: string + apiKey: string + indexUid: string + inputSelector?: string + inputElement?: Element + debug?: boolean + meilisearchOptions?: SearchParams + queryDataCallback?: (data?: SearchResponse) => void + autocompleteOptions?: { + ariaLabel?: string + cssClasses?: { + prefix?: string + root?: string + } + keyboardShortcuts?: (string | number)[] + } + transformData?: (hits: Hits) => Hits + queryHook?: (query: unknown) => unknown + handleSelected?: (input, event, suggestion, datasetNumber, context) => void + enhancedSearchInput?: boolean + layout?: 'column' | 'simple' + enableDarkMode?: boolean | 'auto' + clientAgents?: Config['clientAgents'] +} + +declare class DocsSearchBar { + constructor(options: Options) +} + +declare global { + interface Window { + docsSearchBar: (options: Options) => void + } +} + +export default DocsSearchBar diff --git a/package.json b/package.json index 1a0e0682..8bc3b195 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "search-as-you-type" ], "main": "dist/npm/index.js", + "typings": "./index.d.ts", "scripts": { "build": "./scripts/build", "build:css": "./scripts/build-css", From 9e252803ee7ef46bd8af1bd7be9ec36adb421b9b Mon Sep 17 00:00:00 2001 From: hirohe Date: Tue, 22 Nov 2022 12:33:18 +0800 Subject: [PATCH 4/6] refactor: change export default of index.d.ts --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 078357ad..9aa7d2ad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,4 +36,4 @@ declare global { } } -export default DocsSearchBar +export default function docsSearchBar(options: Options): DocsSearchBar From 38ba3f8da91fb615107dbaff2688c241fd01881f Mon Sep 17 00:00:00 2001 From: hirohe Date: Wed, 23 Nov 2022 10:43:41 +0800 Subject: [PATCH 5/6] feat: more definitions --- index.d.ts | 68 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 9aa7d2ad..da590953 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,6 +1,46 @@ +/* eslint camelcase: ["off"] */ + import { SearchResponse, SearchParams, Hits, Config } from 'meilisearch' -interface Options { +interface HitResponse { + anchor: string + content: string + hierarchy_lvl0: string | null + hierarchy_lvl1: string | null + hierarchy_lvl2: string | null + hierarchy_lvl3: string | null + hierarchy_lvl4: string | null + hierarchy_lvl5: string | null + hierarchy_lvl6: string | null + objectID: string + url: string + [key: string]: unknown +} + +interface DefaultFormattedHit { + isLvl0: boolean + isLvl1: boolean + isLbl2: boolean + isLvl1EmptyOrDuplicate: boolean + isCategoryHeader: boolean + isSubCategoryHeader: boolean + isTextOrSubcategoryNonEmpty: boolean + subcategory: string | null + text: string | null + title: string | null + url: string | null +} + +interface AutoCompleteInput { + open: () => void + close: () => void + destroy: () => void + getWrapper: () => Element + getVal: () => string + setVal: (val: string) => void +} + +interface Options { hostUrl: string apiKey: string indexUid: string @@ -17,23 +57,35 @@ interface Options { } keyboardShortcuts?: (string | number)[] } - transformData?: (hits: Hits) => Hits - queryHook?: (query: unknown) => unknown - handleSelected?: (input, event, suggestion, datasetNumber, context) => void + transformData?: (hits: Hits) => Hits + queryHook?: (query: string) => string + handleSelected?: ( + input: AutoCompleteInput, + event: Event, + suggestion: FormattedHit, + datasetNumber: number, + context: { + selectionMethod: 'click' | 'blur' | 'enterKey' | 'tabKey' | string + }, + ) => void enhancedSearchInput?: boolean layout?: 'column' | 'simple' enableDarkMode?: boolean | 'auto' clientAgents?: Config['clientAgents'] } -declare class DocsSearchBar { - constructor(options: Options) +declare class DocsSearchBar { + constructor(options: Options) } declare global { interface Window { - docsSearchBar: (options: Options) => void + docsSearchBar: ( + options: Options, + ) => void } } -export default function docsSearchBar(options: Options): DocsSearchBar +export default function docsSearchBar( + options: Options, +): DocsSearchBar From dfd8feba31c0940c94682d289fb7800adc812d2c Mon Sep 17 00:00:00 2001 From: hirohe Date: Fri, 3 Mar 2023 19:13:44 +0800 Subject: [PATCH 6/6] refactor: add overrides in eslint for typescript rules only --- .eslintrc.js | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1b89cb94..50af792a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,18 +1,15 @@ /* Using eslint-config-algolia */ /* eslint-disable import/no-commonjs */ module.exports = { - parser: '@typescript-eslint/parser', extends: [ 'algolia', 'algolia/jest', 'plugin:prettier/recommended', 'plugin:cypress/recommended', - 'plugin:@typescript-eslint/recommended', ], - plugins: ['prettier', 'cypress', '@typescript-eslint'], + plugins: ['prettier', 'cypress'], rules: { 'no-console': 0, - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], 'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], 'prettier/prettier': [ 'error', @@ -21,4 +18,34 @@ module.exports = { }, ], }, + overrides: [ + { + files: ['**/*.ts'], + extends: [ + 'algolia', + 'algolia/jest', + 'plugin:prettier/recommended', + 'plugin:cypress/recommended', + 'plugin:@typescript-eslint/recommended', + ], + plugins: ['prettier', 'cypress', '@typescript-eslint'], + rules: { + 'no-console': 0, + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_' }, + ], + 'eslint-comments/disable-enable-pair': [ + 'error', + { allowWholeFile: true }, + ], + 'prettier/prettier': [ + 'error', + { + trailingComma: 'all', + }, + ], + }, + }, + ], }