From 2a019350115fdabe272fa717fef777bdce1d07d9 Mon Sep 17 00:00:00 2001 From: Botvid Johansson Date: Thu, 6 Feb 2025 14:35:32 +0100 Subject: [PATCH] =?UTF-8?q?en=20knapp=20f=C3=B6r=20att=20ta=20bort=20stand?= =?UTF-8?q?ardlistan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 135 ++++++++++++++++++++- package.json | 1 + src/db/import.ts | 20 +++ src/db/main.ts | 11 +- src/db/shortforms.se.json | 4 +- src/lib/components/ui/button/button.svelte | 25 ++++ src/lib/components/ui/button/index.ts | 50 ++++++++ src/routes/+page.svelte | 16 ++- src/routes/dashboard.svelte | 1 + src/routes/textarea.svelte | 3 + 10 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 src/db/import.ts create mode 100644 src/lib/components/ui/button/button.svelte create mode 100644 src/lib/components/ui/button/index.ts create mode 100644 src/routes/dashboard.svelte diff --git a/package-lock.json b/package-lock.json index 8ad5aa8..6c06186 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "@sveltejs/vite-plugin-svelte": "^5.0.0", "@tauri-apps/cli": "^2.2.7", "autoprefixer": "^10.4.20", + "bits-ui": "^0.22.0", "clsx": "^2.1.1", "drizzle-kit": "^0.30.2", "eslint": "^9.18.0", @@ -1128,6 +1129,34 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@floating-ui/core": { + "version": "1.6.9", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.6.9.tgz", + "integrity": "sha512-uMXCuQ3BItDUbAMhIXw7UPXRfAlOAvZzdK9BWpE60MCn+Svt3aLn9jsPTi/WNGlRUu2uI0v5S7JiIUsbsvh3fw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@floating-ui/utils": "^0.2.9" + } + }, + "node_modules/@floating-ui/dom": { + "version": "1.6.13", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.6.13.tgz", + "integrity": "sha512-umqzocjDgNRGTuO7Q8CU32dkHkECqI8ZdMZ5Swb6QAM0t5rnlrN3lGo1hdpscRd3WS8T6DKYK4ephgIH9iRh3w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@floating-ui/core": "^1.6.0", + "@floating-ui/utils": "^0.2.9" + } + }, + "node_modules/@floating-ui/utils": { + "version": "0.2.9", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.9.tgz", + "integrity": "sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg==", + "dev": true, + "license": "MIT" + }, "node_modules/@humanfs/core": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", @@ -1498,6 +1527,16 @@ "@inlang/language-tag": "1.5.1" } }, + "node_modules/@internationalized/date": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/@internationalized/date/-/date-3.7.0.tgz", + "integrity": "sha512-VJ5WS3fcVx0bejE/YHfbDKR/yawZgKqn/if+oEeLqNwBtPzVB06olkfcnojTmEMX+gTpH+FlQ69SHNitJ8/erQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@swc/helpers": "^0.5.0" + } + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -2969,6 +3008,16 @@ "vite": "^6.0.0" } }, + "node_modules/@swc/helpers": { + "version": "0.5.15", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.15.tgz", + "integrity": "sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "tslib": "^2.8.0" + } + }, "node_modules/@tauri-apps/api": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@tauri-apps/api/-/api-2.2.0.tgz", @@ -3830,6 +3879,61 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bits-ui": { + "version": "0.22.0", + "resolved": "https://registry.npmjs.org/bits-ui/-/bits-ui-0.22.0.tgz", + "integrity": "sha512-r7Fw1HNgA4YxZBRcozl7oP0bheQ8EHh+kfMBZJgyFISix8t4p/nqDcHLmBgIiJ3T5XjYnJRorYDjIWaCfhb5fw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@internationalized/date": "^3.5.1", + "@melt-ui/svelte": "0.76.2", + "nanoid": "^5.0.5" + }, + "funding": { + "url": "https://github.com/sponsors/huntabyte" + }, + "peerDependencies": { + "svelte": "^4.0.0 || ^5.0.0" + } + }, + "node_modules/bits-ui/node_modules/@melt-ui/svelte": { + "version": "0.76.2", + "resolved": "https://registry.npmjs.org/@melt-ui/svelte/-/svelte-0.76.2.tgz", + "integrity": "sha512-7SbOa11tXUS95T3fReL+dwDs5FyJtCEqrqG3inRziDws346SYLsxOQ6HmX+4BkIsQh1R8U3XNa+EMmdMt38lMA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@floating-ui/core": "^1.3.1", + "@floating-ui/dom": "^1.4.5", + "@internationalized/date": "^3.5.0", + "dequal": "^2.0.3", + "focus-trap": "^7.5.2", + "nanoid": "^5.0.4" + }, + "peerDependencies": { + "svelte": ">=3 <5" + } + }, + "node_modules/bits-ui/node_modules/nanoid": { + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.9.tgz", + "integrity": "sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.js" + }, + "engines": { + "node": "^18 || >=20" + } + }, "node_modules/bottleneck": { "version": "2.19.5", "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", @@ -4271,6 +4375,16 @@ "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", "license": "ISC" }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/detect-libc": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", @@ -4988,6 +5102,16 @@ "dev": true, "license": "ISC" }, + "node_modules/focus-trap": { + "version": "7.6.4", + "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.6.4.tgz", + "integrity": "sha512-xx560wGBk7seZ6y933idtjJQc1l+ck+pI3sKvhKozdBV1dRZoKhkW5xoCaFv9tQiX5RH1xfSxjuNu6g+lmN/gw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tabbable": "^6.2.0" + } + }, "node_modules/follow-redirects": { "version": "1.15.9", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", @@ -7158,6 +7282,13 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/tabbable": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.2.0.tgz", + "integrity": "sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==", + "dev": true, + "license": "MIT" + }, "node_modules/tailwind-merge": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.0.1.tgz", @@ -7470,8 +7601,8 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "optional": true + "devOptional": true, + "license": "0BSD" }, "node_modules/type-check": { "version": "0.4.0", diff --git a/package.json b/package.json index c5b4972..5a5c32d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@sveltejs/vite-plugin-svelte": "^5.0.0", "@tauri-apps/cli": "^2.2.7", "autoprefixer": "^10.4.20", + "bits-ui": "^0.22.0", "clsx": "^2.1.1", "drizzle-kit": "^0.30.2", "eslint": "^9.18.0", diff --git a/src/db/import.ts b/src/db/import.ts new file mode 100644 index 0000000..0fe7e1d --- /dev/null +++ b/src/db/import.ts @@ -0,0 +1,20 @@ +import default_shortforms from "./shortforms.se.json"; +import { db, type Shortform, type List } from "./main" + +export const importShortforms = (shortforms: Array) => { + /* + shortforms.map((sf: Shortform) => { + db.shortforms.add({ shortform: sf.sf, phrase: sf.p }) + }) + */ +} + +export const importDefaultShortforms = () => { + const shortforms = default_shortforms.shortforms + const list: List = { id: default_shortforms.listid, type: default_shortforms.type, name: default_shortforms.name, updated: new Date(default_shortforms.updated) } + db.lists.add(list) + shortforms.map((sf: Shortform) => { + db.shortforms.add({ shortform: sf.sf, phrase: sf.p, listid: list.id }) + }) + +} diff --git a/src/db/main.ts b/src/db/main.ts index 7cce5b0..0f7f472 100644 --- a/src/db/main.ts +++ b/src/db/main.ts @@ -1,4 +1,5 @@ import Dexie, { type Table } from "dexie"; +import { importDefaultShortforms } from "./import"; export interface SyncInfo { @@ -9,7 +10,7 @@ export interface SyncInfo { export interface List { id?: number; name: string; - type: boolean; + type: number; updated: Date; } @@ -44,10 +45,16 @@ export class SkrivertDB extends Dexie { if (localListsCount === 0) { // No local data - perform full download + importDefaultShortforms() console.log('No local data found. Prompt user to import data or use standard list...'); } }) - } + }; } +export async function deleteShortformList(id: number) { + await db.shortforms.where("listid").equals(id).delete() + await db.lists.where("id").equals(id).delete() + +} export const db = new SkrivertDB(); diff --git a/src/db/shortforms.se.json b/src/db/shortforms.se.json index 1af2945..b7ee15b 100644 --- a/src/db/shortforms.se.json +++ b/src/db/shortforms.se.json @@ -1,6 +1,8 @@ { + "listid": 890324, + "name": "Svenska", + "type": 0, "updated": "2025-02-05T15:37:46.696Z", - "listid": 0, "shortforms": [ { "sf": "10e", "p": "10:e", "u": null }, diff --git a/src/lib/components/ui/button/button.svelte b/src/lib/components/ui/button/button.svelte new file mode 100644 index 0000000..86827f3 --- /dev/null +++ b/src/lib/components/ui/button/button.svelte @@ -0,0 +1,25 @@ + + + + + diff --git a/src/lib/components/ui/button/index.ts b/src/lib/components/ui/button/index.ts new file mode 100644 index 0000000..f0f4612 --- /dev/null +++ b/src/lib/components/ui/button/index.ts @@ -0,0 +1,50 @@ +import type { Button as ButtonPrimitive } from "bits-ui"; +import { type VariantProps, tv } from "tailwind-variants"; +import Root from "./button.svelte"; + +const buttonVariants = tv({ + base: "focus-visible:ring-ring inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 disabled:pointer-events-none disabled:opacity-50", + variants: { + variant: { + default: "bg-primary text-primary-foreground hover:bg-primary/90 shadow", + destructive: + "bg-destructive text-destructive-foreground hover:bg-destructive/90 shadow-sm", + outline: + "border-input bg-background hover:bg-accent hover:text-accent-foreground border shadow-sm", + secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 shadow-sm", + ghost: "hover:bg-accent hover:text-accent-foreground", + link: "text-primary underline-offset-4 hover:underline", + }, + size: { + default: "h-9 px-4 py-2", + sm: "h-8 rounded-md px-3 text-xs", + lg: "h-10 rounded-md px-8", + icon: "h-9 w-9", + }, + }, + defaultVariants: { + variant: "default", + size: "default", + }, +}); + +type Variant = VariantProps["variant"]; +type Size = VariantProps["size"]; + +type Props = ButtonPrimitive.Props & { + variant?: Variant; + size?: Size; +}; + +type Events = ButtonPrimitive.Events; + +export { + Root, + type Props, + type Events, + // + Root as Button, + type Props as ButtonProps, + type Events as ButtonEvents, + buttonVariants, +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 290e526..f876b0e 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,6 +1,10 @@
-