fix: patch flexsearch type definitions

[deploy]
This commit is contained in:
2023-07-28 19:56:00 +02:00
parent e508d1312e
commit 73c71836dc
6 changed files with 33 additions and 15 deletions

1
package-lock.json generated
View File

@@ -7,6 +7,7 @@
"": {
"name": "amacc1ng",
"version": "0.3.0",
"hasInstallScript": true,
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@fontsource-variable/material-symbols-rounded": "^5.0.4",

View File

@@ -9,6 +9,7 @@
"build": "typesafe-i18n --no-watch && vite build",
"test": "vitest run --coverage",
"preview": "vite preview",
"postinstall": "patch-package",
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch",
"minify-icons": "ts-node-esm src/tools/minify-icon-font.ts",

View File

@@ -1,13 +1,21 @@
diff --git a/node_modules/@types/flexsearch/index.d.ts b/node_modules/@types/flexsearch/index.d.ts
index ecde8e7..4173464 100755
index ecde8e7..64a5f1e 100755
--- a/node_modules/@types/flexsearch/index.d.ts
+++ b/node_modules/@types/flexsearch/index.d.ts
@@ -165,7 +165,7 @@ export type IndexSearchResult = Id[];
@@ -6,7 +6,6 @@
/************************************/
/* Utils */
/************************************/
-export type Id = number | string;
export type Limit = number;
export type ExportHandler<T> = (id: string | number, value: T) => void;
export type AsyncCallback<T = undefined> = T extends undefined ? () => void : (result: T) => void;
@@ -165,7 +164,7 @@ export type IndexSearchResult = Id[];
* * Usage: https://github.com/nextapps-de/flexsearch#usage
*/
-export class Index {
+export default class Index {
+export default class Index<ID extends number | string = number> {
constructor(x?: Preset | IndexOptions<string>);
add(id: Id, item: string): this;
append(id: Id, item: string): this;

View File

@@ -1,7 +1,7 @@
/**
* Compress JSON.stringify with gzip
*/
export async function stringifyCompressed(chords: any): Promise<Blob> {
export async function stringifyCompressed<T>(chords: T): Promise<Blob> {
const stream = new Blob([JSON.stringify(chords)]).stream().pipeThrough(new CompressionStream("gzip"))
return await new Response(stream).blob()
}

View File

@@ -1,10 +1,18 @@
<script lang="ts">
import {getSharableUrl, parseCompressed, stringifyCompressed} from "$lib/serial/serialization"
import {chords, layout} from "$lib/serial/connection"
import type {Chord} from "$lib/serial/chord"
import type {CharaLayout} from "$lib/serialization/layout"
interface CharaBackup {
isCharaBackup: "v1.0"
chords: Chord[]
layout: CharaLayout
}
async function downloadBackup() {
const downloadUrl = URL.createObjectURL(
await stringifyCompressed({
await stringifyCompressed<CharaBackup>({
isCharaBackup: "v1.0",
chords: $chords,
layout: $layout,
@@ -18,10 +26,10 @@
URL.revokeObjectURL(downloadUrl)
}
async function restoreBackup(event: InputEvent) {
async function restoreBackup(event: Event) {
const input = (event.target as HTMLInputElement).files![0]
if (!input) return
const backup = await parseCompressed(input)
const backup = await parseCompressed<CharaBackup>(input)
if (backup.isCharaBackup !== "v1.0") throw new Error("Invalid Backup")
if (backup.chords) {
$chords = backup.chords
@@ -91,10 +99,10 @@
border-radius: 32px;
transition: all 250ms ease;
}
&.primary {
color: var(--md-sys-color-on-primary);
background: var(--md-sys-color-primary);
}
button.primary {
color: var(--md-sys-color-on-primary);
background: var(--md-sys-color-primary);
}
</style>

View File

@@ -21,16 +21,16 @@
let searchFilter: number[] | undefined
function search(event) {
function search(event: Event) {
document.startViewTransition(async () => {
const query = event.target.value
const query = (event.target as HTMLInputElement).value
searchFilter = query && searchIndex ? searchIndex.search(query) : undefined
await tick()
})
}
const sort: MouseEventHandler<HTMLButtonElement> = function (event) {
tippy(event.target, {})
function sort(event: Event) {
tippy(event.target as HTMLInputElement, {})
}
$: items = searchFilter?.map(it => [$chords[it], it] as const) ?? $chords.map((it, i) => [it, i] as const)