diff --git a/README.md b/README.md index 796936a..e9d9e84 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,43 @@ If you want to list all the search matches of a single note, you can do so by us Also accessible through the Command Palette "**_Omnisearch: In-file search_**". This modal searches through the active note's content and lists the matching results. Just press enter to automatically scroll to the right place. +## Public API + +A simple API object is available to interact with Omnisearch. If you're using [this package](https://github.com/vanakat/plugin-api), it's accessible through `pluginApi('omnisearch')`. Otherwise, you can access it with `app.plugins.plugins.omnisearch.api`. + +At the time of writing, the API is a work-in-progress feature, but should be stable enough to use. + +**This API is an experimental feature, the ResultNote interface will likely change. The `search` function returns at most 50 results** + +```ts +{ + search: (query: string) => Promise +} + +type ResultNoteApi = { + score: number + path: string + basename: string + foundWords: string[] + matches: SearchMatch[] +} + +type SearchMatch = { + match: string + offset: number +} +``` + +DataviewJS example: + +~~~js +```dataviewjs +const results = await app.plugins.plugins.omnisearch.api.search('your query') +const arr = dv.array(results).sort(r => r.score, 'desc') +dv.table(['File', 'Score'], arr.map(o => [dv.fileLink(o.path), Math.round(o.score)])) +``` +~~~ + ## Customization There are several CSS classes you can use to customize the appearance of Omnisearch. diff --git a/package.json b/package.json index 54b2351..5dd5f1b 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "typescript": "^4.6.4" }, "dependencies": { + "@vanakat/plugin-api": "^0.1.0", "minisearch": "^5.0.0-beta1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e1e0110..99f5b0d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,6 +9,7 @@ specifiers: '@types/node': ^16.11.34 '@typescript-eslint/eslint-plugin': ^5.23.0 '@typescript-eslint/parser': ^5.23.0 + '@vanakat/plugin-api': ^0.1.0 babel-jest: ^27.5.1 builtin-modules: ^3.2.0 esbuild: 0.13.12 @@ -32,6 +33,7 @@ specifiers: typescript: ^4.6.4 dependencies: + '@vanakat/plugin-api': 0.1.0_eslint@7.12.1 minisearch: 5.0.0-beta1 devDependencies: @@ -55,7 +57,7 @@ devDependencies: eslint-plugin-promise: 5.0.0_eslint@7.12.1 eslint-plugin-svelte3: 3.4.1_eslint@7.12.1+svelte@3.48.0 jest: 27.5.1 - obsidian: 0.14.8 + obsidian: 0.15.2 prettier: 2.6.2 prettier-eslint: 13.0.0 svelte: 3.48.0 @@ -1311,19 +1313,21 @@ packages: /@codemirror/rangeset/0.19.9: resolution: {integrity: sha512-V8YUuOvK+ew87Xem+71nKcqu1SXd5QROMRLMS/ljT5/3MCxtgrRie1Cvild0G/Z2f1fpWxzX78V0U4jjXBorBQ==} + deprecated: As of 0.20.0, this package has been merged into @codemirror/state dependencies: '@codemirror/state': 0.19.9 - dev: true + dev: false /@codemirror/state/0.19.9: resolution: {integrity: sha512-psOzDolKTZkx4CgUqhBQ8T8gBc0xN5z4gzed109aF6x7D7umpDRoimacI/O6d9UGuyl4eYuDCZmDFr2Rq7aGOw==} dependencies: '@codemirror/text': 0.19.6 - dev: true + dev: false /@codemirror/text/0.19.6: resolution: {integrity: sha512-T9jnREMIygx+TPC1bOuepz18maGq/92q2a+n4qTqObKwvNMg+8cMTslb8yxeEDEq7S3kpgGWxgO1UWbQRij0dA==} - dev: true + deprecated: As of 0.20.0, this package has been merged into @codemirror/state + dev: false /@codemirror/view/0.19.48: resolution: {integrity: sha512-0eg7D2Nz4S8/caetCTz61rK0tkHI17V/d15Jy0kLOT8dTLGGNJUponDnW28h2B6bERmPlVHKh8MJIr5OCp1nGw==} @@ -1333,7 +1337,7 @@ packages: '@codemirror/text': 0.19.6 style-mod: 4.0.0 w3c-keyname: 2.2.4 - dev: true + dev: false /@eslint/eslintrc/0.2.2: resolution: {integrity: sha512-EfB5OHNYp1F4px/LI/FEnGylop7nOqkQ1LRzCM0KccA2U8tvV8w01KBv37LbO7nW4H+YhKyo2LcJhRwjjV17QQ==} @@ -1595,12 +1599,10 @@ packages: dependencies: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 - dev: true /@nodelib/fs.stat/2.0.5: resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} - dev: true /@nodelib/fs.walk/1.2.8: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} @@ -1608,7 +1610,6 @@ packages: dependencies: '@nodelib/fs.scandir': 2.1.5 fastq: 1.13.0 - dev: true /@sinonjs/commons/1.8.3: resolution: {integrity: sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==} @@ -1679,7 +1680,6 @@ packages: resolution: {integrity: sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw==} dependencies: '@types/tern': 0.23.4 - dev: true /@types/eslint-visitor-keys/1.0.0: resolution: {integrity: sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==} @@ -1687,7 +1687,6 @@ packages: /@types/estree/0.0.51: resolution: {integrity: sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==} - dev: true /@types/graceful-fs/4.1.5: resolution: {integrity: sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw==} @@ -1720,7 +1719,6 @@ packages: /@types/json-schema/7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} - dev: true /@types/json5/0.0.29: resolution: {integrity: sha1-7ihweulOEdK4J7y+UnC86n8+ce4=} @@ -1752,7 +1750,6 @@ packages: resolution: {integrity: sha512-JAUw1iXGO1qaWwEOzxTKJZ/5JxVeON9kvGZ/osgZaJImBnyjyn0cjovPsf6FNLmyGY8Vw9DoXZCMlfMkMwHRWg==} dependencies: '@types/estree': 0.0.51 - dev: true /@types/testing-library__jest-dom/5.14.3: resolution: {integrity: sha512-oKZe+Mf4ioWlMuzVBaXQ9WDnEm1+umLx0InILg+yvZVBBDmzV5KfZyLrCvadtWcx8+916jLmHafcmqqffl+iIw==} @@ -1797,6 +1794,33 @@ packages: - supports-color dev: true + /@typescript-eslint/eslint-plugin/5.23.0_dc6af012e2417e38d17415aa3d0b67db: + resolution: {integrity: sha512-hEcSmG4XodSLiAp1uxv/OQSGsDY6QN3TcRU32gANp+19wGE1QQZLRS8/GV58VRUoXhnkuJ3ZxNQ3T6Z6zM59DA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + '@typescript-eslint/parser': ^5.0.0 + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/parser': 5.23.0_eslint@7.12.1+typescript@4.4.4 + '@typescript-eslint/scope-manager': 5.23.0 + '@typescript-eslint/type-utils': 5.23.0_eslint@7.12.1+typescript@4.4.4 + '@typescript-eslint/utils': 5.23.0_eslint@7.12.1+typescript@4.4.4 + debug: 4.3.4 + eslint: 7.12.1 + functional-red-black-tree: 1.0.1 + ignore: 5.2.0 + regexpp: 3.2.0 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.4.4 + typescript: 4.4.4 + transitivePeerDependencies: + - supports-color + dev: false + /@typescript-eslint/experimental-utils/3.10.1_eslint@7.12.1+typescript@3.9.10: resolution: {integrity: sha512-DewqIgscDzmAfd5nOGe4zm6Bl7PKtMG2Ad0KG8CUZAHlXfAKTF9Ol5PXhiMh39yRL2ChRH1cuuUGOcVyyrhQIw==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1835,6 +1859,26 @@ packages: - supports-color dev: true + /@typescript-eslint/parser/5.23.0_eslint@7.12.1+typescript@4.4.4: + resolution: {integrity: sha512-V06cYUkqcGqpFjb8ttVgzNF53tgbB/KoQT/iB++DOIExKmzI9vBJKjZKt/6FuV9c+zrDsvJKbJ2DOCYwX91cbw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/scope-manager': 5.23.0 + '@typescript-eslint/types': 5.23.0 + '@typescript-eslint/typescript-estree': 5.23.0_typescript@4.4.4 + debug: 4.3.4 + eslint: 7.12.1 + typescript: 4.4.4 + transitivePeerDependencies: + - supports-color + dev: false + /@typescript-eslint/parser/5.23.0_eslint@7.12.1+typescript@4.6.4: resolution: {integrity: sha512-V06cYUkqcGqpFjb8ttVgzNF53tgbB/KoQT/iB++DOIExKmzI9vBJKjZKt/6FuV9c+zrDsvJKbJ2DOCYwX91cbw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1861,7 +1905,25 @@ packages: dependencies: '@typescript-eslint/types': 5.23.0 '@typescript-eslint/visitor-keys': 5.23.0 - dev: true + + /@typescript-eslint/type-utils/5.23.0_eslint@7.12.1+typescript@4.4.4: + resolution: {integrity: sha512-iuI05JsJl/SUnOTXA9f4oI+/4qS/Zcgk+s2ir+lRmXI+80D8GaGwoUqs4p+X+4AxDolPpEpVUdlEH4ADxFy4gw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: '*' + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/utils': 5.23.0_eslint@7.12.1+typescript@4.4.4 + debug: 4.3.4 + eslint: 7.12.1 + tsutils: 3.21.0_typescript@4.4.4 + typescript: 4.4.4 + transitivePeerDependencies: + - supports-color + dev: false /@typescript-eslint/type-utils/5.23.0_eslint@7.12.1+typescript@4.6.4: resolution: {integrity: sha512-iuI05JsJl/SUnOTXA9f4oI+/4qS/Zcgk+s2ir+lRmXI+80D8GaGwoUqs4p+X+4AxDolPpEpVUdlEH4ADxFy4gw==} @@ -1890,7 +1952,6 @@ packages: /@typescript-eslint/types/5.23.0: resolution: {integrity: sha512-NfBsV/h4dir/8mJwdZz7JFibaKC3E/QdeMEDJhiAE3/eMkoniZ7MjbEMCGXw6MZnZDMN3G9S0mH/6WUIj91dmw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - dev: true /@typescript-eslint/typescript-estree/3.10.1_typescript@3.9.10: resolution: {integrity: sha512-QbcXOuq6WYvnB3XPsZpIwztBoquEYLXh2MtwVU+kO8jgYCiv4G5xrSP/1wg4tkvrEE+esZVquIPX/dxPlePk1w==} @@ -1914,6 +1975,27 @@ packages: - supports-color dev: true + /@typescript-eslint/typescript-estree/5.23.0_typescript@4.4.4: + resolution: {integrity: sha512-xE9e0lrHhI647SlGMl+m+3E3CKPF1wzvvOEWnuE3CCjjT7UiRnDGJxmAcVKJIlFgK6DY9RB98eLr1OPigPEOGg==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 5.23.0 + '@typescript-eslint/visitor-keys': 5.23.0 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.3.7 + tsutils: 3.21.0_typescript@4.4.4 + typescript: 4.4.4 + transitivePeerDependencies: + - supports-color + dev: false + /@typescript-eslint/typescript-estree/5.23.0_typescript@4.6.4: resolution: {integrity: sha512-xE9e0lrHhI647SlGMl+m+3E3CKPF1wzvvOEWnuE3CCjjT7UiRnDGJxmAcVKJIlFgK6DY9RB98eLr1OPigPEOGg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1935,6 +2017,24 @@ packages: - supports-color dev: true + /@typescript-eslint/utils/5.23.0_eslint@7.12.1+typescript@4.4.4: + resolution: {integrity: sha512-dbgaKN21drqpkbbedGMNPCtRPZo1IOUr5EI9Jrrh99r5UW5Q0dz46RKXeSBoPV+56R6dFKpbrdhgUNSJsDDRZA==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + peerDependencies: + eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 + dependencies: + '@types/json-schema': 7.0.11 + '@typescript-eslint/scope-manager': 5.23.0 + '@typescript-eslint/types': 5.23.0 + '@typescript-eslint/typescript-estree': 5.23.0_typescript@4.4.4 + eslint: 7.12.1 + eslint-scope: 5.1.1 + eslint-utils: 3.0.0_eslint@7.12.1 + transitivePeerDependencies: + - supports-color + - typescript + dev: false + /@typescript-eslint/utils/5.23.0_eslint@7.12.1+typescript@4.6.4: resolution: {integrity: sha512-dbgaKN21drqpkbbedGMNPCtRPZo1IOUr5EI9Jrrh99r5UW5Q0dz46RKXeSBoPV+56R6dFKpbrdhgUNSJsDDRZA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1966,7 +2066,18 @@ packages: dependencies: '@typescript-eslint/types': 5.23.0 eslint-visitor-keys: 3.3.0 - dev: true + + /@vanakat/plugin-api/0.1.0_eslint@7.12.1: + resolution: {integrity: sha512-IxylWsxwkz1Knx/1/+8AkiKB7LWhGmiGX+j0rNiPMB5faw7AcSBBikxyq3gbOnbfwhaVPiQzJVIxKQcCPewMIw==} + dependencies: + '@typescript-eslint/eslint-plugin': 5.23.0_dc6af012e2417e38d17415aa3d0b67db + '@typescript-eslint/parser': 5.23.0_eslint@7.12.1+typescript@4.4.4 + obsidian: 0.14.8 + typescript: 4.4.4 + transitivePeerDependencies: + - eslint + - supports-color + dev: false /abab/2.0.6: resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==} @@ -2111,7 +2222,6 @@ packages: /array-union/2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} - dev: true /array.prototype.flat/1.3.0: resolution: {integrity: sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==} @@ -2313,7 +2423,6 @@ packages: engines: {node: '>=8'} dependencies: fill-range: 7.0.1 - dev: true /browser-process-hrtime/1.0.0: resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} @@ -2564,7 +2673,6 @@ packages: optional: true dependencies: ms: 2.1.2 - dev: true /decimal.js/10.3.1: resolution: {integrity: sha512-V0pfhfr8suzyPGOx3nmq4aHqabehUZn6Ch9kyFpV79TGDTWFmHqUqXdabR7QHqxzrYolF4+tVmJhUG4OURg5dQ==} @@ -2621,7 +2729,6 @@ packages: engines: {node: '>=8'} dependencies: path-type: 4.0.0 - dev: true /dlv/1.1.3: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} @@ -3044,7 +3151,6 @@ packages: dependencies: esrecurse: 4.3.0 estraverse: 4.3.0 - dev: true /eslint-utils/2.1.0: resolution: {integrity: sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==} @@ -3061,7 +3167,6 @@ packages: dependencies: eslint: 7.12.1 eslint-visitor-keys: 2.1.0 - dev: true /eslint-visitor-keys/1.3.0: resolution: {integrity: sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==} @@ -3071,12 +3176,10 @@ packages: /eslint-visitor-keys/2.1.0: resolution: {integrity: sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==} engines: {node: '>=10'} - dev: true /eslint-visitor-keys/3.3.0: resolution: {integrity: sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - dev: true /eslint/7.12.1: resolution: {integrity: sha512-HlMTEdr/LicJfN08LB3nM1rRYliDXOmfoO4vj39xN6BLpFzF00hbwBoqHk8UcJ2M/3nlARZWy/mslvGEuZFvsg==} @@ -3160,17 +3263,14 @@ packages: engines: {node: '>=4.0'} dependencies: estraverse: 5.3.0 - dev: true /estraverse/4.3.0: resolution: {integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==} engines: {node: '>=4.0'} - dev: true /estraverse/5.3.0: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} - dev: true /esutils/2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} @@ -3220,7 +3320,6 @@ packages: glob-parent: 5.1.2 merge2: 1.4.1 micromatch: 4.0.5 - dev: true /fast-json-stable-stringify/2.1.0: resolution: {integrity: sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==} @@ -3234,7 +3333,6 @@ packages: resolution: {integrity: sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==} dependencies: reusify: 1.0.4 - dev: true /fb-watchman/2.0.1: resolution: {integrity: sha512-DkPJKQeY6kKwmuMretBhr7G6Vodr7bFwDYTXIkfG1gjvNpaxBTQV3PbXg6bR1c1UP4jPOX0jHUbbHANL9vRjVg==} @@ -3254,7 +3352,6 @@ packages: engines: {node: '>=8'} dependencies: to-regex-range: 5.0.1 - dev: true /find-up/2.1.0: resolution: {integrity: sha1-RdG35QbHF93UgndaK3eSCjwMV6c=} @@ -3330,7 +3427,6 @@ packages: /functional-red-black-tree/1.0.1: resolution: {integrity: sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=} - dev: true /functions-have-names/1.2.3: resolution: {integrity: sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==} @@ -3377,7 +3473,6 @@ packages: engines: {node: '>= 6'} dependencies: is-glob: 4.0.3 - dev: true /glob/7.2.0: resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} @@ -3412,7 +3507,6 @@ packages: ignore: 5.2.0 merge2: 1.4.1 slash: 3.0.0 - dev: true /graceful-fs/4.2.10: resolution: {integrity: sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==} @@ -3520,7 +3614,6 @@ packages: /ignore/5.2.0: resolution: {integrity: sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==} engines: {node: '>= 4'} - dev: true /import-fresh/3.3.0: resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==} @@ -3608,7 +3701,6 @@ packages: /is-extglob/2.1.1: resolution: {integrity: sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=} engines: {node: '>=0.10.0'} - dev: true /is-fullwidth-code-point/2.0.0: resolution: {integrity: sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=} @@ -3630,7 +3722,6 @@ packages: engines: {node: '>=0.10.0'} dependencies: is-extglob: 2.1.1 - dev: true /is-negative-zero/2.0.2: resolution: {integrity: sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==} @@ -3647,7 +3738,6 @@ packages: /is-number/7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} - dev: true /is-potential-custom-element-name/1.0.1: resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} @@ -4398,7 +4488,6 @@ packages: engines: {node: '>=10'} dependencies: yallist: 4.0.0 - dev: true /magic-string/0.25.9: resolution: {integrity: sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==} @@ -4426,7 +4515,6 @@ packages: /merge2/1.4.1: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} - dev: true /micromatch/4.0.5: resolution: {integrity: sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==} @@ -4434,7 +4522,6 @@ packages: dependencies: braces: 3.0.2 picomatch: 2.3.1 - dev: true /mime-db/1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} @@ -4481,6 +4568,10 @@ packages: /moment/2.29.2: resolution: {integrity: sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==} + dev: false + + /moment/2.29.3: + resolution: {integrity: sha512-c6YRvhEo//6T2Jz/vVtYzqBzwvPT95JBQ+smCytzf7c50oMZRsR/a4w88aD34I+/QVSfnoAnSBFPJHItlOMJVw==} dev: true /ms/2.0.0: @@ -4489,7 +4580,6 @@ packages: /ms/2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} - dev: true /ms/2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -4567,6 +4657,16 @@ packages: '@codemirror/view': 0.19.48 '@types/codemirror': 0.0.108 moment: 2.29.2 + dev: false + + /obsidian/0.15.2: + resolution: {integrity: sha512-vN+MNwNmyXxyrIrQnc1tDquZYf1Z15Jl63pIBvHRMIDY8jIG4bSQxBVJSqH1vruKcqRd6TPnhpicrfj7yDKYGQ==} + peerDependencies: + '@codemirror/state': ^6.0.0 + '@codemirror/view': ^6.0.0 + dependencies: + '@types/codemirror': 0.0.108 + moment: 2.29.3 dev: true /once/1.4.0: @@ -4706,7 +4806,6 @@ packages: /path-type/4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} - dev: true /picocolors/1.0.0: resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==} @@ -4715,7 +4814,6 @@ packages: /picomatch/2.3.1: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} - dev: true /pify/2.3.0: resolution: {integrity: sha1-7RQaasBDqEnqWISY59yosVMw6Qw=} @@ -4810,7 +4908,6 @@ packages: /queue-microtask/1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} - dev: true /react-is/17.0.2: resolution: {integrity: sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==} @@ -4874,7 +4971,6 @@ packages: /regexpp/3.2.0: resolution: {integrity: sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==} engines: {node: '>=8'} - dev: true /regexpu-core/5.0.1: resolution: {integrity: sha512-CriEZlrKK9VJw/xQGJpQM5rY88BtuL8DM+AEwvcThHilbxiTAy8vq4iJnd2tqq8wLmjbGZzP7ZcKFjbGkmEFrw==} @@ -4942,7 +5038,6 @@ packages: /reusify/1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - dev: true /rimraf/2.6.3: resolution: {integrity: sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==} @@ -4969,7 +5064,6 @@ packages: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} dependencies: queue-microtask: 1.2.3 - dev: true /safe-buffer/5.1.2: resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==} @@ -5016,7 +5110,6 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 - dev: true /shebang-command/2.0.0: resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} @@ -5049,7 +5142,6 @@ packages: /slash/3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} - dev: true /slice-ansi/2.1.0: resolution: {integrity: sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==} @@ -5224,7 +5316,7 @@ packages: /style-mod/4.0.0: resolution: {integrity: sha512-OPhtyEjyyN9x3nhPsu76f52yUGXiZcgvsrFVtvTkyGRQJ0XK+GPc6ov1z+lRpbeabka+MYEQxOYRnt5nF30aMw==} - dev: true + dev: false /supports-color/2.0.0: resolution: {integrity: sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=} @@ -5385,7 +5477,6 @@ packages: engines: {node: '>=8.0'} dependencies: is-number: 7.0.0 - dev: true /tough-cookie/4.0.0: resolution: {integrity: sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==} @@ -5414,7 +5505,6 @@ packages: /tslib/1.14.1: resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==} - dev: true /tslib/2.3.1: resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==} @@ -5430,6 +5520,16 @@ packages: typescript: 3.9.10 dev: true + /tsutils/3.21.0_typescript@4.4.4: + resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} + engines: {node: '>= 6'} + peerDependencies: + typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' + dependencies: + tslib: 1.14.1 + typescript: 4.4.4 + dev: false + /tsutils/3.21.0_typescript@4.6.4: resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'} @@ -5481,6 +5581,12 @@ packages: hasBin: true dev: true + /typescript/4.4.4: + resolution: {integrity: sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: false + /typescript/4.6.4: resolution: {integrity: sha512-9ia/jWHIEbo49HfjrLGfKbZSuWo9iTMwXO+Ca3pRsSpbsMbc7/IU8NKdCZVRRBafVPGnoJeFL76ZOAA84I9fEg==} engines: {node: '>=4.2.0'} @@ -5580,7 +5686,7 @@ packages: /w3c-keyname/2.2.4: resolution: {integrity: sha512-tOhfEwEzFLJzf6d1ZPkYfGj+FWhIpBux9ppoP3rlclw3Z0BZv3N7b7030Z1kYth+6rDuAsXUFr+d0VE6Ed1ikw==} - dev: true + dev: false /w3c-xmlserializer/2.0.0: resolution: {integrity: sha512-4tzD0mF8iSiMiNs30BiLO3EpfGLZUT2MSX/G+o7ZywDzliWQ3OPtTZ0PTC3B3ca1UAf4cJMHB+2Bf56EriJuRA==} @@ -5704,7 +5810,6 @@ packages: /yallist/4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true /yargs-parser/20.2.9: resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==} diff --git a/src/api.ts b/src/api.ts new file mode 100644 index 0000000..7445958 --- /dev/null +++ b/src/api.ts @@ -0,0 +1,37 @@ +import type { ResultNote, SearchMatch } from './globals' +import { Query } from './query' +import { getSuggestions } from './search' + +type ResultNoteApi = { + score: number + path: string + basename: string + foundWords: string[] + matches: SearchMatch[] +} + +function mapResults(results: ResultNote[]): ResultNoteApi[] { + return results.map(result => { + const { score, path, basename, foundWords, matches } = result + return { + score, + path, + basename, + foundWords, + matches: matches.map(match => { + return { + match: match.match, + offset: match.offset, + } + }), + } + }) +} + +async function search(q: string): Promise { + const query = new Query(q) + const raw = await getSuggestions(query) + return mapResults(raw) +} + +export default { search } diff --git a/src/main.ts b/src/main.ts index acd3a2b..70e5f7b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,8 @@ import { import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' import { loadSettings, SettingsTab } from './settings' import { eventBus } from './globals' +import { registerAPI } from '@vanakat/plugin-api' +import api from './api' // let mainWindow: { on: any; off: any } | null = null // try { @@ -17,9 +19,20 @@ import { eventBus } from './globals' // console.log("Can't load electron, mobile platform") // } +function _registerAPI(plugin: OmnisearchPlugin): void { + registerAPI('omnisearch', api, plugin) + ;(app as any).plugins.plugins.omnisearch.api = api + plugin.register(() => { + delete (app as any).plugins.plugins.omnisearch.api + }) +} + export default class OmnisearchPlugin extends Plugin { async onload(): Promise { await loadSettings(this) + + _registerAPI(this) + this.addSettingTab(new SettingsTab(this)) eventBus.disable('vault') eventBus.disable('infile')