commit 451223816b04720691e52321d675a1ed4dad7d8b Author: pakintada@gmail.com Date: Tue Feb 17 14:30:02 2026 +0700 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4225035 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +node_modules + +# Output +.output +.vercel +.netlify +.wrangler +/.svelte-kit +/build + +# OS +.DS_Store +Thumbs.db + +# Env +.env +.env.* +!.env.example +!.env.test + +# Vite +vite.config.js.timestamp-* +vite.config.ts.timestamp-* + +*storybook.log +storybook-static diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..b6f27f1 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..7d74fe2 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,9 @@ +# Package Managers +package-lock.json +pnpm-lock.yaml +yarn.lock +bun.lock +bun.lockb + +# Miscellaneous +/static/ diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8103a0b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,16 @@ +{ + "useTabs": true, + "singleQuote": true, + "trailingComma": "none", + "printWidth": 100, + "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"], + "overrides": [ + { + "files": "*.svelte", + "options": { + "parser": "svelte" + } + } + ], + "tailwindStylesheet": "./src/app.css" +} diff --git a/.storybook/main.ts b/.storybook/main.ts new file mode 100644 index 0000000..a429e07 --- /dev/null +++ b/.storybook/main.ts @@ -0,0 +1,20 @@ +import type { StorybookConfig } from '@storybook/sveltekit'; + +const config: StorybookConfig = { + "stories": [ + "../src/**/*.mdx", + "../src/**/*.stories.@(js|ts|svelte)" + ], + "addons": [ + "@storybook/addon-svelte-csf", + "@chromatic-com/storybook", + "@storybook/addon-docs", + "@storybook/addon-a11y", + "@storybook/addon-vitest" + ], + "framework": { + "name": "@storybook/sveltekit", + "options": {} + } +}; +export default config; \ No newline at end of file diff --git a/.storybook/preview.ts b/.storybook/preview.ts new file mode 100644 index 0000000..20a11e0 --- /dev/null +++ b/.storybook/preview.ts @@ -0,0 +1,14 @@ +import type { Preview } from '@storybook/sveltekit' + +const preview: Preview = { + parameters: { + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview; \ No newline at end of file diff --git a/NOTE.txt b/NOTE.txt new file mode 100644 index 0000000..acf6dda --- /dev/null +++ b/NOTE.txt @@ -0,0 +1,3 @@ +install shadcn ui libs + +bunx --bun shadcn-svelte@latest \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..75842c4 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# sv + +Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli). + +## Creating a project + +If you're seeing this, you've probably already done this step. Congrats! + +```sh +# create a new project in the current directory +npx sv create + +# create a new project in my-app +npx sv create my-app +``` + +## Developing + +Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: + +```sh +npm run dev + +# or start the server and open the app in a new browser tab +npm run dev -- --open +``` + +## Building + +To create a production version of your app: + +```sh +npm run build +``` + +You can preview the production build with `npm run preview`. + +> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment. diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..0018d14 Binary files /dev/null and b/bun.lockb differ diff --git a/components.json b/components.json new file mode 100644 index 0000000..66f9d8c --- /dev/null +++ b/components.json @@ -0,0 +1,16 @@ +{ + "$schema": "https://shadcn-svelte.com/schema.json", + "tailwind": { + "css": "src/app.{p,post}css", + "baseColor": "stone" + }, + "aliases": { + "components": "$lib/components", + "utils": "$lib/utils", + "ui": "$lib/components/ui", + "hooks": "$lib/hooks", + "lib": "$lib" + }, + "typescript": true, + "registry": "https://shadcn-svelte.com/registry" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6e5a125 --- /dev/null +++ b/package.json @@ -0,0 +1,87 @@ +{ + "name": "supra-app", + "private": true, + "version": "0.0.1", + "type": "module", + "scripts": { + "dev": "vite dev", + "build": "vite build", + "preview": "vite preview", + "prepare": "svelte-kit sync || echo ''", + "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", + "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", + "format": "prettier --write .", + "lint": "prettier --check .", + "test:unit": "vitest", + "test": "npm run test:unit -- --run", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build" + }, + "devDependencies": { + "@chromatic-com/storybook": "^4.1.3", + "@internationalized/date": "^3.10.1", + "@lucide/svelte": "^0.561.0", + "@storybook/addon-a11y": "^10.2.0", + "@storybook/addon-docs": "^10.2.0", + "@storybook/addon-svelte-csf": "^5.0.10", + "@storybook/addon-vitest": "^10.2.0", + "@storybook/sveltekit": "^10.2.0", + "@sveltejs/adapter-auto": "^7.0.0", + "@sveltejs/kit": "^2.50.1", + "@sveltejs/vite-plugin-svelte": "^6.2.4", + "@tailwindcss/forms": "^0.5.11", + "@tailwindcss/typography": "^0.5.19", + "@tailwindcss/vite": "^4.1.18", + "@tanstack/table-core": "^8.21.3", + "@types/node": "^22.19.7", + "@vitest/browser": "^3.2.4", + "bits-ui": "^2.15.4", + "clsx": "^2.1.1", + "paneforge": "^1.0.0-next.6", + "playwright": "^1.57.0", + "prettier": "^3.8.1", + "prettier-plugin-svelte": "^3.4.1", + "prettier-plugin-tailwindcss": "^0.7.2", + "storybook": "^10.2.0", + "svelte": "^5.48.0", + "svelte-check": "^4.3.5", + "svelte-sonner": "^1.0.7", + "tailwind-merge": "^3.4.0", + "tailwind-variants": "^3.2.2", + "tailwindcss": "^4.1.18", + "tw-animate-css": "^1.4.0", + "typescript": "^5.9.3", + "vaul-svelte": "^1.0.0-next.7", + "vite": "^7.3.1", + "vite-plugin-devtools-json": "^1.0.0", + "vitest": "^4.0.18", + "vitest-browser-svelte": "^2.0.2" + }, + "dependencies": { + "@battlefieldduck/xterm-svelte": "^2.2.1", + "@dnd-kit-svelte/core": "^0.0.11", + "@dnd-kit-svelte/svelte": "0.1.3", + "@dnd-kit/abstract": "^0.2.4", + "@dnd-kit/geometry": "^0.2.4", + "@dnd-kit/helpers": "^0.2.3", + "@tanstack/match-sorter-utils": "^8.19.4", + "@xterm/xterm": "^5.5.0", + "@yume-chan/adb": "^2.5.1", + "@yume-chan/adb-credential-web": "^2.1.0", + "@yume-chan/adb-daemon-webusb": "^2.3.2", + "@yume-chan/adb-scrcpy": "^2.3.2", + "@yume-chan/scrcpy": "^2.3.0", + "@yume-chan/stream-extra": "^2.1.0", + "animejs": "^4.3.5", + "firebase": "^12.8.0", + "idb": "^8.0.3", + "mode-watcher": "^1.1.0", + "usb": "^2.17.0", + "uuid": "^13.0.0", + "xterm-addon-fit": "^0.8.0", + "zod": "^4.3.6" + }, + "resolutions": { + "@dnd-kit/geometry": "^0.2.4" + } +} diff --git a/src/app.css b/src/app.css new file mode 100644 index 0000000..719e82c --- /dev/null +++ b/src/app.css @@ -0,0 +1,114 @@ +@import "tailwindcss"; +@import "tw-animate-css"; + +@custom-variant dark (&:is(.dark *)); + +:root { + --background: hsl(0 0% 100%) /* <- Wrap in HSL */; + --foreground: hsl(240 10% 3.9%); + --muted: hsl(240 4.8% 95.9%); + --muted-foreground: hsl(240 3.8% 46.1%); + --popover: hsl(0 0% 100%); + --popover-foreground: hsl(240 10% 3.9%); + --card: hsl(0 0% 100%); + --card-foreground: hsl(240 10% 3.9%); + --border: hsl(240 5.9% 90%); + --input: hsl(240 5.9% 90%); + --primary: hsl(240 5.9% 10%); + --primary-foreground: hsl(0 0% 98%); + --secondary: hsl(240 4.8% 95.9%); + --secondary-foreground: hsl(240 5.9% 10%); + --accent: hsl(240 4.8% 95.9%); + --accent-foreground: hsl(240 5.9% 10%); + --destructive: hsl(0 72.2% 50.6%); + --destructive-foreground: hsl(0 0% 98%); + --ring: hsl(240 10% 3.9%); + --sidebar: hsl(0 0% 98%); + --sidebar-foreground: hsl(240 5.3% 26.1%); + --sidebar-primary: hsl(240 5.9% 10%); + --sidebar-primary-foreground: hsl(0 0% 98%); + --sidebar-accent: hsl(240 4.8% 95.9%); + --sidebar-accent-foreground: hsl(240 5.9% 10%); + --sidebar-border: hsl(220 13% 91%); + --sidebar-ring: hsl(217.2 91.2% 59.8%); + + --radius: 0.5rem; +} + +.dark { + --background: hsl(240 10% 3.9%); + --foreground: hsl(0 0% 98%); + --muted: hsl(240 3.7% 15.9%); + --muted-foreground: hsl(240 5% 64.9%); + --popover: hsl(240 10% 3.9%); + --popover-foreground: hsl(0 0% 98%); + --card: hsl(240 10% 3.9%); + --card-foreground: hsl(0 0% 98%); + --border: hsl(240 3.7% 15.9%); + --input: hsl(240 3.7% 15.9%); + --primary: hsl(0 0% 98%); + --primary-foreground: hsl(240 5.9% 10%); + --secondary: hsl(240 3.7% 15.9%); + --secondary-foreground: hsl(0 0% 98%); + --accent: hsl(240 3.7% 15.9%); + --accent-foreground: hsl(0 0% 98%); + --destructive: hsl(0 62.8% 30.6%); + --destructive-foreground: hsl(0 0% 98%); + --ring: hsl(240 4.9% 83.9%); + --sidebar: hsl(240 5.9% 10%); + --sidebar-foreground: hsl(240 4.8% 95.9%); + --sidebar-primary: hsl(224.3 76.3% 48%); + --sidebar-primary-foreground: hsl(0 0% 100%); + --sidebar-accent: hsl(240 3.7% 15.9%); + --sidebar-accent-foreground: hsl(240 4.8% 95.9%); + --sidebar-border: hsl(240 3.7% 15.9%); + --sidebar-ring: hsl(217.2 91.2% 59.8%); +} + +@theme inline { + /* Radius (for rounded-*) */ + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + + /* Colors */ + --color-background: var(--background); + --color-foreground: var(--foreground); + --color-muted: var(--muted); + --color-muted-foreground: var(--muted-foreground); + --color-popover: var(--popover); + --color-popover-foreground: var(--popover-foreground); + --color-card: var(--card); + --color-card-foreground: var(--card-foreground); + --color-border: var(--border); + --color-input: var(--input); + --color-primary: var(--primary); + --color-primary-foreground: var(--primary-foreground); + --color-secondary: var(--secondary); + --color-secondary-foreground: var(--secondary-foreground); + --color-accent: var(--accent); + --color-accent-foreground: var(--accent-foreground); + --color-destructive: var(--destructive); + --color-destructive-foreground: var(--destructive-foreground); + --color-ring: var(--ring); + --color-radius: var(--radius); + --color-sidebar: var(--sidebar); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-ring: var(--sidebar-ring); +} + +@layer base { + * { + @apply border-border; + } + + body { + @apply bg-background text-foreground; + } +} \ No newline at end of file diff --git a/src/app.d.ts b/src/app.d.ts new file mode 100644 index 0000000..da08e6d --- /dev/null +++ b/src/app.d.ts @@ -0,0 +1,13 @@ +// See https://svelte.dev/docs/kit/types#app.d.ts +// for information about these interfaces +declare global { + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } +} + +export {}; diff --git a/src/app.html b/src/app.html new file mode 100644 index 0000000..f273cc5 --- /dev/null +++ b/src/app.html @@ -0,0 +1,11 @@ + + + + + + %sveltekit.head% + + +
%sveltekit.body%
+ + diff --git a/src/demo.spec.ts b/src/demo.spec.ts new file mode 100644 index 0000000..e07cbbd --- /dev/null +++ b/src/demo.spec.ts @@ -0,0 +1,7 @@ +import { describe, it, expect } from 'vitest'; + +describe('sum test', () => { + it('adds 1 + 2 to equal 3', () => { + expect(1 + 2).toBe(3); + }); +}); diff --git a/src/lib/assets/bn_hot_america_no.png b/src/lib/assets/bn_hot_america_no.png new file mode 100644 index 0000000..36705c6 Binary files /dev/null and b/src/lib/assets/bn_hot_america_no.png differ diff --git a/src/lib/assets/departments/alpha-3.png b/src/lib/assets/departments/alpha-3.png new file mode 100644 index 0000000..b493c1c Binary files /dev/null and b/src/lib/assets/departments/alpha-3.png differ diff --git a/src/lib/assets/departments/aus_plate.png b/src/lib/assets/departments/aus_plate.png new file mode 100644 index 0000000..7d906ca Binary files /dev/null and b/src/lib/assets/departments/aus_plate.png differ diff --git a/src/lib/assets/departments/cocktail_tha.png b/src/lib/assets/departments/cocktail_tha.png new file mode 100644 index 0000000..35d8825 Binary files /dev/null and b/src/lib/assets/departments/cocktail_tha.png differ diff --git a/src/lib/assets/departments/counter01_plate.png b/src/lib/assets/departments/counter01_plate.png new file mode 100644 index 0000000..abcfcaf Binary files /dev/null and b/src/lib/assets/departments/counter01_plate.png differ diff --git a/src/lib/assets/departments/logo/alpha-3.png b/src/lib/assets/departments/logo/alpha-3.png new file mode 100644 index 0000000..1f7c6fe Binary files /dev/null and b/src/lib/assets/departments/logo/alpha-3.png differ diff --git a/src/lib/assets/departments/logo/aus_plate.png b/src/lib/assets/departments/logo/aus_plate.png new file mode 100644 index 0000000..507217f Binary files /dev/null and b/src/lib/assets/departments/logo/aus_plate.png differ diff --git a/src/lib/assets/departments/logo/cocktail_tha.png b/src/lib/assets/departments/logo/cocktail_tha.png new file mode 100644 index 0000000..35d8825 Binary files /dev/null and b/src/lib/assets/departments/logo/cocktail_tha.png differ diff --git a/src/lib/assets/departments/logo/counter01_plate.png b/src/lib/assets/departments/logo/counter01_plate.png new file mode 100644 index 0000000..abcfcaf Binary files /dev/null and b/src/lib/assets/departments/logo/counter01_plate.png differ diff --git a/src/lib/assets/departments/logo/mys_plate.png b/src/lib/assets/departments/logo/mys_plate.png new file mode 100644 index 0000000..7b7a8cc Binary files /dev/null and b/src/lib/assets/departments/logo/mys_plate.png differ diff --git a/src/lib/assets/departments/logo/sgp_plate.png b/src/lib/assets/departments/logo/sgp_plate.png new file mode 100644 index 0000000..1487af0 Binary files /dev/null and b/src/lib/assets/departments/logo/sgp_plate.png differ diff --git a/src/lib/assets/departments/logo/tha_plate.png b/src/lib/assets/departments/logo/tha_plate.png new file mode 100644 index 0000000..95540a8 Binary files /dev/null and b/src/lib/assets/departments/logo/tha_plate.png differ diff --git a/src/lib/assets/departments/mys_plate.png b/src/lib/assets/departments/mys_plate.png new file mode 100644 index 0000000..3bb130c Binary files /dev/null and b/src/lib/assets/departments/mys_plate.png differ diff --git a/src/lib/assets/departments/sgp_plate.png b/src/lib/assets/departments/sgp_plate.png new file mode 100644 index 0000000..1487af0 Binary files /dev/null and b/src/lib/assets/departments/sgp_plate.png differ diff --git a/src/lib/assets/departments/tha_plate.png b/src/lib/assets/departments/tha_plate.png new file mode 100644 index 0000000..ad42242 Binary files /dev/null and b/src/lib/assets/departments/tha_plate.png differ diff --git a/src/lib/assets/favicon.svg b/src/lib/assets/favicon.svg new file mode 100644 index 0000000..cc5dc66 --- /dev/null +++ b/src/lib/assets/favicon.svg @@ -0,0 +1 @@ +svelte-logo \ No newline at end of file diff --git a/src/lib/assets/google-color.svg b/src/lib/assets/google-color.svg new file mode 100644 index 0000000..b26d4a4 --- /dev/null +++ b/src/lib/assets/google-color.svg @@ -0,0 +1,28 @@ + + + + + Google-color + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/lib/assets/icons/export.svg b/src/lib/assets/icons/export.svg new file mode 100644 index 0000000..6cf1faf --- /dev/null +++ b/src/lib/assets/icons/export.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/assets/icons/logout.svg b/src/lib/assets/icons/logout.svg new file mode 100644 index 0000000..4881453 --- /dev/null +++ b/src/lib/assets/icons/logout.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/assets/icons/logs.svg b/src/lib/assets/icons/logs.svg new file mode 100644 index 0000000..1c52f1e --- /dev/null +++ b/src/lib/assets/icons/logs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/assets/icons/recipes.svg b/src/lib/assets/icons/recipes.svg new file mode 100644 index 0000000..d74d1cf --- /dev/null +++ b/src/lib/assets/icons/recipes.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/lib/assets/logo.png b/src/lib/assets/logo.png new file mode 100644 index 0000000..4bd4910 Binary files /dev/null and b/src/lib/assets/logo.png differ diff --git a/src/lib/assets/logo.svelte b/src/lib/assets/logo.svelte new file mode 100644 index 0000000..efdfc6f --- /dev/null +++ b/src/lib/assets/logo.svelte @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/lib/assets/modules/monitoring_btn.png b/src/lib/assets/modules/monitoring_btn.png new file mode 100644 index 0000000..0b13111 Binary files /dev/null and b/src/lib/assets/modules/monitoring_btn.png differ diff --git a/src/lib/assets/modules/recipe_btn.png b/src/lib/assets/modules/recipe_btn.png new file mode 100644 index 0000000..ad6f81d Binary files /dev/null and b/src/lib/assets/modules/recipe_btn.png differ diff --git a/src/lib/assets/status-health.svelte b/src/lib/assets/status-health.svelte new file mode 100644 index 0000000..cd93d3a --- /dev/null +++ b/src/lib/assets/status-health.svelte @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/lib/components/app-account-select.svelte b/src/lib/components/app-account-select.svelte new file mode 100644 index 0000000..f2c650a --- /dev/null +++ b/src/lib/components/app-account-select.svelte @@ -0,0 +1,109 @@ + + + + + + + {#snippet child({ props })} + +
+ + +
+
+ + {currentUser?.displayName} + + {currentUser?.email} +
+ +
+ {/snippet} +
+ + Account + + + +
+ +
+
+ +
+
+
+
+
+
diff --git a/src/lib/components/app-sidebar.svelte b/src/lib/components/app-sidebar.svelte new file mode 100644 index 0000000..e4d0917 --- /dev/null +++ b/src/lib/components/app-sidebar.svelte @@ -0,0 +1,130 @@ + + + + +
+ +
+
+ + {#each data.navMain as nav} + + {nav.title} + + + {#each nav.items as sub} + + + {#snippet child({ props })} + + {#if sub.icon} + + {/if} + {sub.title} + + {/snippet} + + + {/each} + + + + {/each} + + + + +
diff --git a/src/lib/components/content-form.svelte b/src/lib/components/content-form.svelte new file mode 100644 index 0000000..6a64ca1 --- /dev/null +++ b/src/lib/components/content-form.svelte @@ -0,0 +1,8 @@ + + + diff --git a/src/lib/components/dashboard-quick-adb.svelte b/src/lib/components/dashboard-quick-adb.svelte new file mode 100644 index 0000000..b4ba09d --- /dev/null +++ b/src/lib/components/dashboard-quick-adb.svelte @@ -0,0 +1,424 @@ + + +
+ + + Machine Shortcuts + Shortcuts for machine i.e. connect or hotfix + {#if enableComponent} + + + + {/if} + + + {#if enableComponent} + +
+ + +
+

+ Device: {connectDeviceOk ? 'Online' : 'Offline'} +

+ +
+
+ { + openAppBrewWhenConnected = !openAppBrewWhenConnected; + }} + /> +
+ +

+ Immediately try to open brew app when first connected +

+
+
+ + +
+ + + + + +
+
+ {:else} + +
+ This feature is not enabled +
+ {/if} +
+ + + {#if connectDeviceOk} + {#if showLoadProgress} + + {/if} +

{machineStatus}

+ {/if} +
+
+
diff --git a/src/lib/components/dashboard.svelte b/src/lib/components/dashboard.svelte new file mode 100644 index 0000000..4cd31e5 --- /dev/null +++ b/src/lib/components/dashboard.svelte @@ -0,0 +1,81 @@ + + +
+
+ + + Latest Activity + Real time activities. Click to view full activities. + + + + +
+ {#if activities.length > 0} + {#each activities as activity} +
+ {activity} +
+ + {/each} + {:else} +
No ongoing activity right now!
+ + {/if} +
+
+
+
+
+ + + + + + +
diff --git a/src/lib/components/error-layout.svelte b/src/lib/components/error-layout.svelte new file mode 100644 index 0000000..e7c4a45 --- /dev/null +++ b/src/lib/components/error-layout.svelte @@ -0,0 +1,11 @@ + + +
+ +
+ + \ No newline at end of file diff --git a/src/lib/components/machine-info.svelte b/src/lib/components/machine-info.svelte new file mode 100644 index 0000000..d4b16ea --- /dev/null +++ b/src/lib/components/machine-info.svelte @@ -0,0 +1,63 @@ + + +
+ + + Machine Infos + Informations of current connected machine + + + {#if currentMachineInfo && infoMap} +
+
+

Box ID:

+

{currentMachineInfo.boxId}

+
+ +

Versions:

+ {#each Object.keys(infoMap['versions']) as v} +
+

{v}

+ {#if infoMap['versions'][v] && infoMap['versions'][v] != ''} +

{infoMap['versions'][v]}

+ {:else} + + {/if} +
+ {/each} +
+ {:else} +
+ +
+ {/if} +
+
+
diff --git a/src/lib/components/recipe-details/columns.ts b/src/lib/components/recipe-details/columns.ts new file mode 100644 index 0000000..6198ac1 --- /dev/null +++ b/src/lib/components/recipe-details/columns.ts @@ -0,0 +1,114 @@ +// { +// "MixOrder": 0, +// "StringParam": "", +// "FeedParameter": 0, +// "FeedPattern": 0, +// "isUse": true, +// "materialPathId": 599501, +// "powderGram": 0, +// "powderTime": 0, +// "stirTime": 110, +// "syrupGram": 0, +// "syrupTime": 0, +// "waterCold": 0, +// "waterYield": 0 +// } + +import type { ColumnDef } from '@tanstack/table-core'; +import { renderComponent, renderSnippet } from '../ui/data-table'; +import RecipelistIsuse from './recipelist-isuse.svelte'; +import RecipelistValue from './recipelist-value.svelte'; +import { DragHandle } from './recipelist-table.svelte'; +import { createRawSnippet } from 'svelte'; +import RecipelistMatSelect from './recipelist-mat-select.svelte'; + +export type RecipelistMaterial = { + id: number; + material_id: string; + is_use: boolean; + values: { + string_param: string; + mix_order: number; + feed: { + pattern: number; + parameter: number; + }; + powder: { + gram: number; + time: number; + }; + syrup: { + gram: number; + time: number; + }; + water: { + cold: number; + yield: number; + }; + }; +}; + +export const columns: ColumnDef[] = [ + { + id: 'id', + accessorKey: 'id', + header: () => null, + cell: () => null, + enableSorting: true + }, + { + id: 'drag', + header: () => + renderSnippet( + createRawSnippet(() => ({ + render: () => '
' + })) + ), + cell: () => renderSnippet(DragHandle) + }, + { + accessorKey: 'is_use', + id: 'is_use', + header: ({ column }) => + renderSnippet( + createRawSnippet(() => ({ + render: () => '
Enable
' + })) + ), + cell: ({ row }) => { + return renderComponent(RecipelistIsuse, { + checked: row.original.is_use, + onCheckedChange: (value) => { + row.original.is_use = !!value; + row.toggleSelected(row.original.is_use); + } + }); + }, + enableSorting: false, + enableHiding: false + }, + { + id: 'material_id', + header: ({ column }) => 'Material', + cell: ({ row }) => { + return renderComponent(RecipelistMatSelect, { + currentMat: row.original.material_id, + onMatChange: (value: any) => { + row.original.material_id = value; + console.log('change mat', value); + row.toggleSelected(row.original.is_use); + } + }); + } + }, + { + accessorKey: 'values', + id: 'values', + header: ({ column }) => 'Values', + cell: ({ row }) => { + return renderComponent(RecipelistValue, { + ...row.original.values + }); + } + } +]; diff --git a/src/lib/components/recipe-details/recipe-detail.svelte b/src/lib/components/recipe-details/recipe-detail.svelte new file mode 100644 index 0000000..0e42f0c --- /dev/null +++ b/src/lib/components/recipe-details/recipe-detail.svelte @@ -0,0 +1,145 @@ + + + + + + +
+ + + Info + Details + + + + + + Info + Info about this menu + + + +
+ + + + +
+ +
+
+
+
+ + + + +
+
diff --git a/src/lib/components/recipe-details/recipelist-isuse.svelte b/src/lib/components/recipe-details/recipelist-isuse.svelte new file mode 100644 index 0000000..65bf6d3 --- /dev/null +++ b/src/lib/components/recipe-details/recipelist-isuse.svelte @@ -0,0 +1,14 @@ + + +
+ onCheckedChange(e)} {...restProps} /> +
diff --git a/src/lib/components/recipe-details/recipelist-mat-select.svelte b/src/lib/components/recipe-details/recipelist-mat-select.svelte new file mode 100644 index 0000000..3e5acf4 --- /dev/null +++ b/src/lib/components/recipe-details/recipelist-mat-select.svelte @@ -0,0 +1,76 @@ + + + + + + + +
+ + {}} + oninput={(e) => {}} + /> +
+ + + +
+ +

Create Material

+
+
+ + {#each allMatData as mat} + changeMat(`${mat.materialOtherName} (${mat.id})`)}> +
+ {#if mat.BeanChannel} + + {:else if mat.id > 8110 && mat.id < 8131} + + {/if} + +

{mat.materialOtherName} ({mat.id})

+
+
+ {:else} + +

No materials available

+
+ {/each} +
+
diff --git a/src/lib/components/recipe-details/recipelist-table.svelte b/src/lib/components/recipe-details/recipelist-table.svelte new file mode 100644 index 0000000..3d1ef58 --- /dev/null +++ b/src/lib/components/recipe-details/recipelist-table.svelte @@ -0,0 +1,196 @@ + + + + + + + + Recipe List + Material used in this menu's brewing process + + + + + { + // snap + data = move(data as any, e as any); + // + }} + > + + + + {#each table.getHeaderGroups() as headerGroup (headerGroup.id)} + + {#each headerGroup.headers as header (header.id)} + + {#if !header.isPlaceholder} + + {/if} + + {/each} + + {/each} + + + {#if table.getRowModel().rows?.length} + {#each table.getRowModel().rows as row, index (row.id)} + {@render DraggableRow({ row, index })} + {/each} + {:else} + + Empty recipe. + + {/if} + + + + + + + + +{#snippet DraggableRow({ row, index }: { row: Row; index: number })} + {@const { ref, isDragging, handleRef } = useSortable({ + id: row.original.id, + index: () => index + })} + + + {#each row.getVisibleCells() as cell (cell.id)} + + + + {/each} + +{/snippet} + +{#snippet DragHandle({ attach }: { attach: Attachment })} + +{/snippet} diff --git a/src/lib/components/recipe-details/recipelist-value.svelte b/src/lib/components/recipe-details/recipelist-value.svelte new file mode 100644 index 0000000..6957dd4 --- /dev/null +++ b/src/lib/components/recipe-details/recipelist-value.svelte @@ -0,0 +1,6 @@ + diff --git a/src/lib/components/recipe-editor-dialog.svelte b/src/lib/components/recipe-editor-dialog.svelte new file mode 100644 index 0000000..5d478e0 --- /dev/null +++ b/src/lib/components/recipe-editor-dialog.svelte @@ -0,0 +1,95 @@ + + +{#if isDesktop.current} + + e.preventDefault()}>View + + + Edit Recipe {productCode} + Make changes to selected menu here. Click "save" when done or "test" for testing with + connected machine + + + + + + + +{:else}{/if} diff --git a/src/lib/components/ui/alert/alert-description.svelte b/src/lib/components/ui/alert/alert-description.svelte new file mode 100644 index 0000000..8b56aed --- /dev/null +++ b/src/lib/components/ui/alert/alert-description.svelte @@ -0,0 +1,23 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/alert/alert-title.svelte b/src/lib/components/ui/alert/alert-title.svelte new file mode 100644 index 0000000..77e45ad --- /dev/null +++ b/src/lib/components/ui/alert/alert-title.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/alert/alert.svelte b/src/lib/components/ui/alert/alert.svelte new file mode 100644 index 0000000..2b2eff9 --- /dev/null +++ b/src/lib/components/ui/alert/alert.svelte @@ -0,0 +1,44 @@ + + + + + diff --git a/src/lib/components/ui/alert/index.ts b/src/lib/components/ui/alert/index.ts new file mode 100644 index 0000000..97e21b4 --- /dev/null +++ b/src/lib/components/ui/alert/index.ts @@ -0,0 +1,14 @@ +import Root from "./alert.svelte"; +import Description from "./alert-description.svelte"; +import Title from "./alert-title.svelte"; +export { alertVariants, type AlertVariant } from "./alert.svelte"; + +export { + Root, + Description, + Title, + // + Root as Alert, + Description as AlertDescription, + Title as AlertTitle, +}; diff --git a/src/lib/components/ui/badge/badge.svelte b/src/lib/components/ui/badge/badge.svelte new file mode 100644 index 0000000..e3164ba --- /dev/null +++ b/src/lib/components/ui/badge/badge.svelte @@ -0,0 +1,50 @@ + + + + + + {@render children?.()} + diff --git a/src/lib/components/ui/badge/index.ts b/src/lib/components/ui/badge/index.ts new file mode 100644 index 0000000..64e0aa9 --- /dev/null +++ b/src/lib/components/ui/badge/index.ts @@ -0,0 +1,2 @@ +export { default as Badge } from "./badge.svelte"; +export { badgeVariants, type BadgeVariant } from "./badge.svelte"; diff --git a/src/lib/components/ui/button/button.svelte b/src/lib/components/ui/button/button.svelte new file mode 100644 index 0000000..a8296ae --- /dev/null +++ b/src/lib/components/ui/button/button.svelte @@ -0,0 +1,82 @@ + + + + +{#if href} + + {@render children?.()} + +{:else} + +{/if} diff --git a/src/lib/components/ui/button/index.ts b/src/lib/components/ui/button/index.ts new file mode 100644 index 0000000..fb585d7 --- /dev/null +++ b/src/lib/components/ui/button/index.ts @@ -0,0 +1,17 @@ +import Root, { + type ButtonProps, + type ButtonSize, + type ButtonVariant, + buttonVariants, +} from "./button.svelte"; + +export { + Root, + type ButtonProps as Props, + // + Root as Button, + buttonVariants, + type ButtonProps, + type ButtonSize, + type ButtonVariant, +}; diff --git a/src/lib/components/ui/card/card-action.svelte b/src/lib/components/ui/card/card-action.svelte new file mode 100644 index 0000000..cc36c56 --- /dev/null +++ b/src/lib/components/ui/card/card-action.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/card-content.svelte b/src/lib/components/ui/card/card-content.svelte new file mode 100644 index 0000000..bc90b83 --- /dev/null +++ b/src/lib/components/ui/card/card-content.svelte @@ -0,0 +1,15 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/card-description.svelte b/src/lib/components/ui/card/card-description.svelte new file mode 100644 index 0000000..9b20ac7 --- /dev/null +++ b/src/lib/components/ui/card/card-description.svelte @@ -0,0 +1,20 @@ + + +

+ {@render children?.()} +

diff --git a/src/lib/components/ui/card/card-footer.svelte b/src/lib/components/ui/card/card-footer.svelte new file mode 100644 index 0000000..cf43353 --- /dev/null +++ b/src/lib/components/ui/card/card-footer.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/card-header.svelte b/src/lib/components/ui/card/card-header.svelte new file mode 100644 index 0000000..8a91abb --- /dev/null +++ b/src/lib/components/ui/card/card-header.svelte @@ -0,0 +1,23 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/card-title.svelte b/src/lib/components/ui/card/card-title.svelte new file mode 100644 index 0000000..22586e6 --- /dev/null +++ b/src/lib/components/ui/card/card-title.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/card.svelte b/src/lib/components/ui/card/card.svelte new file mode 100644 index 0000000..99448cc --- /dev/null +++ b/src/lib/components/ui/card/card.svelte @@ -0,0 +1,23 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/card/index.ts b/src/lib/components/ui/card/index.ts new file mode 100644 index 0000000..4d3fce4 --- /dev/null +++ b/src/lib/components/ui/card/index.ts @@ -0,0 +1,25 @@ +import Root from "./card.svelte"; +import Content from "./card-content.svelte"; +import Description from "./card-description.svelte"; +import Footer from "./card-footer.svelte"; +import Header from "./card-header.svelte"; +import Title from "./card-title.svelte"; +import Action from "./card-action.svelte"; + +export { + Root, + Content, + Description, + Footer, + Header, + Title, + Action, + // + Root as Card, + Content as CardContent, + Description as CardDescription, + Footer as CardFooter, + Header as CardHeader, + Title as CardTitle, + Action as CardAction, +}; diff --git a/src/lib/components/ui/checkbox/checkbox.svelte b/src/lib/components/ui/checkbox/checkbox.svelte new file mode 100644 index 0000000..1622e05 --- /dev/null +++ b/src/lib/components/ui/checkbox/checkbox.svelte @@ -0,0 +1,36 @@ + + + + {#snippet children({ checked, indeterminate })} +
+ {#if checked} + + {:else if indeterminate} + + {/if} +
+ {/snippet} +
diff --git a/src/lib/components/ui/checkbox/index.ts b/src/lib/components/ui/checkbox/index.ts new file mode 100644 index 0000000..6d92d94 --- /dev/null +++ b/src/lib/components/ui/checkbox/index.ts @@ -0,0 +1,6 @@ +import Root from "./checkbox.svelte"; +export { + Root, + // + Root as Checkbox, +}; diff --git a/src/lib/components/ui/command/command-dialog.svelte b/src/lib/components/ui/command/command-dialog.svelte new file mode 100644 index 0000000..5c9a82a --- /dev/null +++ b/src/lib/components/ui/command/command-dialog.svelte @@ -0,0 +1,40 @@ + + + + + {title} + {description} + + + + + diff --git a/src/lib/components/ui/command/command-empty.svelte b/src/lib/components/ui/command/command-empty.svelte new file mode 100644 index 0000000..6726cd8 --- /dev/null +++ b/src/lib/components/ui/command/command-empty.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/command/command-group.svelte b/src/lib/components/ui/command/command-group.svelte new file mode 100644 index 0000000..104f817 --- /dev/null +++ b/src/lib/components/ui/command/command-group.svelte @@ -0,0 +1,32 @@ + + + + {#if heading} + + {heading} + + {/if} + + diff --git a/src/lib/components/ui/command/command-input.svelte b/src/lib/components/ui/command/command-input.svelte new file mode 100644 index 0000000..e0dbd58 --- /dev/null +++ b/src/lib/components/ui/command/command-input.svelte @@ -0,0 +1,26 @@ + + +
+ + +
diff --git a/src/lib/components/ui/command/command-item.svelte b/src/lib/components/ui/command/command-item.svelte new file mode 100644 index 0000000..d94d07f --- /dev/null +++ b/src/lib/components/ui/command/command-item.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/command/command-link-item.svelte b/src/lib/components/ui/command/command-link-item.svelte new file mode 100644 index 0000000..944c22d --- /dev/null +++ b/src/lib/components/ui/command/command-link-item.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/command/command-list.svelte b/src/lib/components/ui/command/command-list.svelte new file mode 100644 index 0000000..569f595 --- /dev/null +++ b/src/lib/components/ui/command/command-list.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/command/command-loading.svelte b/src/lib/components/ui/command/command-loading.svelte new file mode 100644 index 0000000..19dd298 --- /dev/null +++ b/src/lib/components/ui/command/command-loading.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/command/command-separator.svelte b/src/lib/components/ui/command/command-separator.svelte new file mode 100644 index 0000000..35c4c95 --- /dev/null +++ b/src/lib/components/ui/command/command-separator.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/command/command-shortcut.svelte b/src/lib/components/ui/command/command-shortcut.svelte new file mode 100644 index 0000000..f3d6928 --- /dev/null +++ b/src/lib/components/ui/command/command-shortcut.svelte @@ -0,0 +1,20 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/command/command.svelte b/src/lib/components/ui/command/command.svelte new file mode 100644 index 0000000..a1581f1 --- /dev/null +++ b/src/lib/components/ui/command/command.svelte @@ -0,0 +1,28 @@ + + + diff --git a/src/lib/components/ui/command/index.ts b/src/lib/components/ui/command/index.ts new file mode 100644 index 0000000..5435fbe --- /dev/null +++ b/src/lib/components/ui/command/index.ts @@ -0,0 +1,37 @@ +import Root from "./command.svelte"; +import Loading from "./command-loading.svelte"; +import Dialog from "./command-dialog.svelte"; +import Empty from "./command-empty.svelte"; +import Group from "./command-group.svelte"; +import Item from "./command-item.svelte"; +import Input from "./command-input.svelte"; +import List from "./command-list.svelte"; +import Separator from "./command-separator.svelte"; +import Shortcut from "./command-shortcut.svelte"; +import LinkItem from "./command-link-item.svelte"; + +export { + Root, + Dialog, + Empty, + Group, + Item, + LinkItem, + Input, + List, + Separator, + Shortcut, + Loading, + // + Root as Command, + Dialog as CommandDialog, + Empty as CommandEmpty, + Group as CommandGroup, + Item as CommandItem, + LinkItem as CommandLinkItem, + Input as CommandInput, + List as CommandList, + Separator as CommandSeparator, + Shortcut as CommandShortcut, + Loading as CommandLoading, +}; diff --git a/src/lib/components/ui/data-table/data-table.svelte.ts b/src/lib/components/ui/data-table/data-table.svelte.ts new file mode 100644 index 0000000..5b7985e --- /dev/null +++ b/src/lib/components/ui/data-table/data-table.svelte.ts @@ -0,0 +1,142 @@ +import { + type RowData, + type TableOptions, + type TableOptionsResolved, + type TableState, + createTable, +} from "@tanstack/table-core"; + +/** + * Creates a reactive TanStack table object for Svelte. + * @param options Table options to create the table with. + * @returns A reactive table object. + * @example + * ```svelte + * + * + * + * + * {#each table.getHeaderGroups() as headerGroup} + * + * {#each headerGroup.headers as header} + * + * {/each} + * + * {/each} + * + * + *
+ * + *
+ * ``` + */ +export function createSvelteTable(options: TableOptions) { + const resolvedOptions: TableOptionsResolved = mergeObjects( + { + state: {}, + onStateChange() {}, + renderFallbackValue: null, + mergeOptions: ( + defaultOptions: TableOptions, + options: Partial> + ) => { + return mergeObjects(defaultOptions, options); + }, + }, + options + ); + + const table = createTable(resolvedOptions); + let state = $state>(table.initialState); + + function updateOptions() { + table.setOptions((prev) => { + return mergeObjects(prev, options, { + state: mergeObjects(state, options.state || {}), + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + onStateChange: (updater: any) => { + if (updater instanceof Function) state = updater(state); + else state = mergeObjects(state, updater); + + options.onStateChange?.(updater); + }, + }); + }); + } + + updateOptions(); + + $effect.pre(() => { + updateOptions(); + }); + + return table; +} + +type MaybeThunk = T | (() => T | null | undefined); +type Intersection = (T extends [infer H, ...infer R] + ? H & Intersection + : unknown) & {}; + +/** + * Lazily merges several objects (or thunks) while preserving + * getter semantics from every source. + * + * Proxy-based to avoid known WebKit recursion issue. + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function mergeObjects[]>( + ...sources: Sources +): Intersection<{ [K in keyof Sources]: Sources[K] }> { + const resolve = (src: MaybeThunk): T | undefined => + typeof src === "function" ? (src() ?? undefined) : src; + + const findSourceWithKey = (key: PropertyKey) => { + for (let i = sources.length - 1; i >= 0; i--) { + const obj = resolve(sources[i]); + if (obj && key in obj) return obj; + } + return undefined; + }; + + return new Proxy(Object.create(null), { + get(_, key) { + const src = findSourceWithKey(key); + + return src?.[key as never]; + }, + + has(_, key) { + return !!findSourceWithKey(key); + }, + + ownKeys(): (string | symbol)[] { + // eslint-disable-next-line svelte/prefer-svelte-reactivity + const all = new Set(); + for (const s of sources) { + const obj = resolve(s); + if (obj) { + for (const k of Reflect.ownKeys(obj) as (string | symbol)[]) { + all.add(k); + } + } + } + return [...all]; + }, + + getOwnPropertyDescriptor(_, key) { + const src = findSourceWithKey(key); + if (!src) return undefined; + return { + configurable: true, + enumerable: true, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + value: (src as any)[key], + writable: true, + }; + }, + }) as Intersection<{ [K in keyof Sources]: Sources[K] }>; +} diff --git a/src/lib/components/ui/data-table/flex-render.svelte b/src/lib/components/ui/data-table/flex-render.svelte new file mode 100644 index 0000000..ac82a58 --- /dev/null +++ b/src/lib/components/ui/data-table/flex-render.svelte @@ -0,0 +1,40 @@ + + +{#if typeof content === "string"} + {content} +{:else if content instanceof Function} + + + {@const result = content(context as any)} + {#if result instanceof RenderComponentConfig} + {@const { component: Component, props } = result} + + {:else if result instanceof RenderSnippetConfig} + {@const { snippet, params } = result} + {@render snippet({ ...params, attach })} + {:else} + {result} + {/if} +{/if} diff --git a/src/lib/components/ui/data-table/index.ts b/src/lib/components/ui/data-table/index.ts new file mode 100644 index 0000000..5f4e77e --- /dev/null +++ b/src/lib/components/ui/data-table/index.ts @@ -0,0 +1,3 @@ +export { default as FlexRender } from "./flex-render.svelte"; +export { renderComponent, renderSnippet } from "./render-helpers.js"; +export { createSvelteTable } from "./data-table.svelte.js"; diff --git a/src/lib/components/ui/data-table/render-helpers.ts b/src/lib/components/ui/data-table/render-helpers.ts new file mode 100644 index 0000000..fa036d6 --- /dev/null +++ b/src/lib/components/ui/data-table/render-helpers.ts @@ -0,0 +1,111 @@ +import type { Component, ComponentProps, Snippet } from "svelte"; + +/** + * A helper class to make it easy to identify Svelte components in + * `columnDef.cell` and `columnDef.header` properties. + * + * > NOTE: This class should only be used internally by the adapter. If you're + * reading this and you don't know what this is for, you probably don't need it. + * + * @example + * ```svelte + * {@const result = content(context as any)} + * {#if result instanceof RenderComponentConfig} + * {@const { component: Component, props } = result} + * + * {/if} + * ``` + */ +export class RenderComponentConfig { + component: TComponent; + props: ComponentProps | Record; + constructor( + component: TComponent, + props: ComponentProps | Record = {} + ) { + this.component = component; + this.props = props; + } +} + +/** + * A helper class to make it easy to identify Svelte Snippets in `columnDef.cell` and `columnDef.header` properties. + * + * > NOTE: This class should only be used internally by the adapter. If you're + * reading this and you don't know what this is for, you probably don't need it. + * + * @example + * ```svelte + * {@const result = content(context as any)} + * {#if result instanceof RenderSnippetConfig} + * {@const { snippet, params } = result} + * {@render snippet(params)} + * {/if} + * ``` + */ +export class RenderSnippetConfig { + snippet: Snippet<[TProps]>; + params: TProps; + constructor(snippet: Snippet<[TProps]>, params: TProps) { + this.snippet = snippet; + this.params = params; + } +} + +/** + * A helper function to help create cells from Svelte components through ColumnDef's `cell` and `header` properties. + * + * This is only to be used with Svelte Components - use `renderSnippet` for Svelte Snippets. + * + * @param component A Svelte component + * @param props The props to pass to `component` + * @returns A `RenderComponentConfig` object that helps svelte-table know how to render the header/cell component. + * @example + * ```ts + * // +page.svelte + * const defaultColumns = [ + * columnHelper.accessor('name', { + * header: header => renderComponent(SortHeader, { label: 'Name', header }), + * }), + * columnHelper.accessor('state', { + * header: header => renderComponent(SortHeader, { label: 'State', header }), + * }), + * ] + * ``` + * @see {@link https://tanstack.com/table/latest/docs/guide/column-defs} + */ +export function renderComponent< + // eslint-disable-next-line @typescript-eslint/no-explicit-any + T extends Component, + Props extends ComponentProps, +>(component: T, props: Props = {} as Props) { + return new RenderComponentConfig(component, props); +} + +/** + * A helper function to help create cells from Svelte Snippets through ColumnDef's `cell` and `header` properties. + * + * The snippet must only take one parameter. + * + * This is only to be used with Snippets - use `renderComponent` for Svelte Components. + * + * @param snippet + * @param params + * @returns - A `RenderSnippetConfig` object that helps svelte-table know how to render the header/cell snippet. + * @example + * ```ts + * // +page.svelte + * const defaultColumns = [ + * columnHelper.accessor('name', { + * cell: cell => renderSnippet(nameSnippet, { name: cell.row.name }), + * }), + * columnHelper.accessor('state', { + * cell: cell => renderSnippet(stateSnippet, { state: cell.row.state }), + * }), + * ] + * ``` + * @see {@link https://tanstack.com/table/latest/docs/guide/column-defs} + */ +export function renderSnippet(snippet: Snippet<[TProps]>, params: TProps = {} as TProps) { + return new RenderSnippetConfig(snippet, params); +} diff --git a/src/lib/components/ui/dialog/dialog-close.svelte b/src/lib/components/ui/dialog/dialog-close.svelte new file mode 100644 index 0000000..840b2f6 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-close.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog-content.svelte b/src/lib/components/ui/dialog/dialog-content.svelte new file mode 100644 index 0000000..31d629f --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-content.svelte @@ -0,0 +1,45 @@ + + + + + + {@render children?.()} + {#if showCloseButton} + + + Close + + {/if} + + diff --git a/src/lib/components/ui/dialog/dialog-description.svelte b/src/lib/components/ui/dialog/dialog-description.svelte new file mode 100644 index 0000000..3845023 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-description.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog-footer.svelte b/src/lib/components/ui/dialog/dialog-footer.svelte new file mode 100644 index 0000000..e7ff446 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-footer.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/dialog/dialog-header.svelte b/src/lib/components/ui/dialog/dialog-header.svelte new file mode 100644 index 0000000..4e5c447 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-header.svelte @@ -0,0 +1,20 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/dialog/dialog-overlay.svelte b/src/lib/components/ui/dialog/dialog-overlay.svelte new file mode 100644 index 0000000..f81ad83 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-overlay.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog-portal.svelte b/src/lib/components/ui/dialog/dialog-portal.svelte new file mode 100644 index 0000000..ccfa79c --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog-title.svelte b/src/lib/components/ui/dialog/dialog-title.svelte new file mode 100644 index 0000000..067e55e --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-title.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog-trigger.svelte b/src/lib/components/ui/dialog/dialog-trigger.svelte new file mode 100644 index 0000000..9d1e801 --- /dev/null +++ b/src/lib/components/ui/dialog/dialog-trigger.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dialog/dialog.svelte b/src/lib/components/ui/dialog/dialog.svelte new file mode 100644 index 0000000..211672c --- /dev/null +++ b/src/lib/components/ui/dialog/dialog.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dialog/index.ts b/src/lib/components/ui/dialog/index.ts new file mode 100644 index 0000000..076cef5 --- /dev/null +++ b/src/lib/components/ui/dialog/index.ts @@ -0,0 +1,34 @@ +import Root from "./dialog.svelte"; +import Portal from "./dialog-portal.svelte"; +import Title from "./dialog-title.svelte"; +import Footer from "./dialog-footer.svelte"; +import Header from "./dialog-header.svelte"; +import Overlay from "./dialog-overlay.svelte"; +import Content from "./dialog-content.svelte"; +import Description from "./dialog-description.svelte"; +import Trigger from "./dialog-trigger.svelte"; +import Close from "./dialog-close.svelte"; + +export { + Root, + Title, + Portal, + Footer, + Header, + Trigger, + Overlay, + Content, + Description, + Close, + // + Root as Dialog, + Title as DialogTitle, + Portal as DialogPortal, + Footer as DialogFooter, + Header as DialogHeader, + Trigger as DialogTrigger, + Overlay as DialogOverlay, + Content as DialogContent, + Description as DialogDescription, + Close as DialogClose, +}; diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-group.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-group.svelte new file mode 100644 index 0000000..e0e1971 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-group.svelte @@ -0,0 +1,16 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte new file mode 100644 index 0000000..6d9ef85 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte @@ -0,0 +1,43 @@ + + + + {#snippet children({ checked, indeterminate })} + + {#if indeterminate} + + {:else} + + {/if} + + {@render childrenProp?.()} + {/snippet} + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte new file mode 100644 index 0000000..1e96782 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-content.svelte @@ -0,0 +1,29 @@ + + + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte new file mode 100644 index 0000000..433540f --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-group-heading.svelte @@ -0,0 +1,22 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-group.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-group.svelte new file mode 100644 index 0000000..aca1f7b --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-group.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte new file mode 100644 index 0000000..04cd110 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-item.svelte @@ -0,0 +1,27 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte new file mode 100644 index 0000000..9681c2b --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-label.svelte @@ -0,0 +1,24 @@ + + +
+ {@render children?.()} +
diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-portal.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-portal.svelte new file mode 100644 index 0000000..274cfef --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-group.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-group.svelte new file mode 100644 index 0000000..189aef4 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-group.svelte @@ -0,0 +1,16 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte new file mode 100644 index 0000000..ce2ad09 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-radio-item.svelte @@ -0,0 +1,33 @@ + + + + {#snippet children({ checked })} + + {#if checked} + + {/if} + + {@render childrenProp?.({ checked })} + {/snippet} + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte new file mode 100644 index 0000000..90f1b6f --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-separator.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte new file mode 100644 index 0000000..7c6e9c6 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-shortcut.svelte @@ -0,0 +1,20 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte new file mode 100644 index 0000000..3f06dc4 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte new file mode 100644 index 0000000..5f49d01 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub-trigger.svelte @@ -0,0 +1,29 @@ + + + + {@render children?.()} + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-sub.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub.svelte new file mode 100644 index 0000000..f044581 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-sub.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu-trigger.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu-trigger.svelte new file mode 100644 index 0000000..cb05344 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu-trigger.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/dropdown-menu.svelte b/src/lib/components/ui/dropdown-menu/dropdown-menu.svelte new file mode 100644 index 0000000..cb4bc62 --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/dropdown-menu.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/dropdown-menu/index.ts b/src/lib/components/ui/dropdown-menu/index.ts new file mode 100644 index 0000000..7850c6a --- /dev/null +++ b/src/lib/components/ui/dropdown-menu/index.ts @@ -0,0 +1,54 @@ +import Root from "./dropdown-menu.svelte"; +import Sub from "./dropdown-menu-sub.svelte"; +import CheckboxGroup from "./dropdown-menu-checkbox-group.svelte"; +import CheckboxItem from "./dropdown-menu-checkbox-item.svelte"; +import Content from "./dropdown-menu-content.svelte"; +import Group from "./dropdown-menu-group.svelte"; +import Item from "./dropdown-menu-item.svelte"; +import Label from "./dropdown-menu-label.svelte"; +import RadioGroup from "./dropdown-menu-radio-group.svelte"; +import RadioItem from "./dropdown-menu-radio-item.svelte"; +import Separator from "./dropdown-menu-separator.svelte"; +import Shortcut from "./dropdown-menu-shortcut.svelte"; +import Trigger from "./dropdown-menu-trigger.svelte"; +import SubContent from "./dropdown-menu-sub-content.svelte"; +import SubTrigger from "./dropdown-menu-sub-trigger.svelte"; +import GroupHeading from "./dropdown-menu-group-heading.svelte"; +import Portal from "./dropdown-menu-portal.svelte"; + +export { + CheckboxGroup, + CheckboxItem, + Content, + Portal, + Root as DropdownMenu, + CheckboxGroup as DropdownMenuCheckboxGroup, + CheckboxItem as DropdownMenuCheckboxItem, + Content as DropdownMenuContent, + Portal as DropdownMenuPortal, + Group as DropdownMenuGroup, + Item as DropdownMenuItem, + Label as DropdownMenuLabel, + RadioGroup as DropdownMenuRadioGroup, + RadioItem as DropdownMenuRadioItem, + Separator as DropdownMenuSeparator, + Shortcut as DropdownMenuShortcut, + Sub as DropdownMenuSub, + SubContent as DropdownMenuSubContent, + SubTrigger as DropdownMenuSubTrigger, + Trigger as DropdownMenuTrigger, + GroupHeading as DropdownMenuGroupHeading, + Group, + GroupHeading, + Item, + Label, + RadioGroup, + RadioItem, + Root, + Separator, + Shortcut, + Sub, + SubContent, + SubTrigger, + Trigger, +}; diff --git a/src/lib/components/ui/input/index.ts b/src/lib/components/ui/input/index.ts new file mode 100644 index 0000000..f47b6d3 --- /dev/null +++ b/src/lib/components/ui/input/index.ts @@ -0,0 +1,7 @@ +import Root from "./input.svelte"; + +export { + Root, + // + Root as Input, +}; diff --git a/src/lib/components/ui/input/input.svelte b/src/lib/components/ui/input/input.svelte new file mode 100644 index 0000000..960167d --- /dev/null +++ b/src/lib/components/ui/input/input.svelte @@ -0,0 +1,52 @@ + + +{#if type === "file"} + +{:else} + +{/if} diff --git a/src/lib/components/ui/label/index.ts b/src/lib/components/ui/label/index.ts new file mode 100644 index 0000000..8bfca0b --- /dev/null +++ b/src/lib/components/ui/label/index.ts @@ -0,0 +1,7 @@ +import Root from "./label.svelte"; + +export { + Root, + // + Root as Label, +}; diff --git a/src/lib/components/ui/label/label.svelte b/src/lib/components/ui/label/label.svelte new file mode 100644 index 0000000..d0afda3 --- /dev/null +++ b/src/lib/components/ui/label/label.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/navigation-menu/index.ts b/src/lib/components/ui/navigation-menu/index.ts new file mode 100644 index 0000000..bbc250f --- /dev/null +++ b/src/lib/components/ui/navigation-menu/index.ts @@ -0,0 +1,28 @@ +import Root from "./navigation-menu.svelte"; +import Content from "./navigation-menu-content.svelte"; +import Indicator from "./navigation-menu-indicator.svelte"; +import Item from "./navigation-menu-item.svelte"; +import Link from "./navigation-menu-link.svelte"; +import List from "./navigation-menu-list.svelte"; +import Trigger from "./navigation-menu-trigger.svelte"; +import Viewport from "./navigation-menu-viewport.svelte"; + +export { + Root, + Content, + Indicator, + Item, + Link, + List, + Trigger, + Viewport, + // + Root as NavigationMenuRoot, + Content as NavigationMenuContent, + Indicator as NavigationMenuIndicator, + Item as NavigationMenuItem, + Link as NavigationMenuLink, + List as NavigationMenuList, + Trigger as NavigationMenuTrigger, + Viewport as NavigationMenuViewport, +}; diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-content.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-content.svelte new file mode 100644 index 0000000..9dbdb36 --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-content.svelte @@ -0,0 +1,21 @@ + + + diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-indicator.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-indicator.svelte new file mode 100644 index 0000000..6c9bdfd --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-indicator.svelte @@ -0,0 +1,22 @@ + + + +
+
diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-item.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-item.svelte new file mode 100644 index 0000000..b00b4b4 --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-item.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-link.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-link.svelte new file mode 100644 index 0000000..867851e --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-link.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-list.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-list.svelte new file mode 100644 index 0000000..c2c5880 --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-list.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-trigger.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-trigger.svelte new file mode 100644 index 0000000..aad82a2 --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-trigger.svelte @@ -0,0 +1,34 @@ + + + + + + {@render children?.()} + + diff --git a/src/lib/components/ui/navigation-menu/navigation-menu-viewport.svelte b/src/lib/components/ui/navigation-menu/navigation-menu-viewport.svelte new file mode 100644 index 0000000..655741d --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu-viewport.svelte @@ -0,0 +1,22 @@ + + +
+ +
diff --git a/src/lib/components/ui/navigation-menu/navigation-menu.svelte b/src/lib/components/ui/navigation-menu/navigation-menu.svelte new file mode 100644 index 0000000..69c3d13 --- /dev/null +++ b/src/lib/components/ui/navigation-menu/navigation-menu.svelte @@ -0,0 +1,32 @@ + + + + {@render children?.()} + + {#if viewport} + + {/if} + diff --git a/src/lib/components/ui/pagination/index.ts b/src/lib/components/ui/pagination/index.ts new file mode 100644 index 0000000..a769899 --- /dev/null +++ b/src/lib/components/ui/pagination/index.ts @@ -0,0 +1,31 @@ +import Root from "./pagination.svelte"; +import Content from "./pagination-content.svelte"; +import Item from "./pagination-item.svelte"; +import Link from "./pagination-link.svelte"; +import PrevButton from "./pagination-prev-button.svelte"; +import NextButton from "./pagination-next-button.svelte"; +import Ellipsis from "./pagination-ellipsis.svelte"; +import Previous from "./pagination-previous.svelte"; +import Next from "./pagination-next.svelte"; + +export { + Root, + Content, + Item, + Link, + PrevButton, //old + NextButton, //old + Ellipsis, + Previous, + Next, + // + Root as Pagination, + Content as PaginationContent, + Item as PaginationItem, + Link as PaginationLink, + PrevButton as PaginationPrevButton, //old + NextButton as PaginationNextButton, //old + Ellipsis as PaginationEllipsis, + Previous as PaginationPrevious, + Next as PaginationNext, +}; diff --git a/src/lib/components/ui/pagination/pagination-content.svelte b/src/lib/components/ui/pagination/pagination-content.svelte new file mode 100644 index 0000000..e1124fc --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-content.svelte @@ -0,0 +1,20 @@ + + +
    + {@render children?.()} +
diff --git a/src/lib/components/ui/pagination/pagination-ellipsis.svelte b/src/lib/components/ui/pagination/pagination-ellipsis.svelte new file mode 100644 index 0000000..3be94c9 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-ellipsis.svelte @@ -0,0 +1,22 @@ + + + diff --git a/src/lib/components/ui/pagination/pagination-item.svelte b/src/lib/components/ui/pagination/pagination-item.svelte new file mode 100644 index 0000000..fd7ffc3 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-item.svelte @@ -0,0 +1,14 @@ + + +
  • + {@render children?.()} +
  • diff --git a/src/lib/components/ui/pagination/pagination-link.svelte b/src/lib/components/ui/pagination/pagination-link.svelte new file mode 100644 index 0000000..58b1a5c --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-link.svelte @@ -0,0 +1,39 @@ + + +{#snippet Fallback()} + {page.value} +{/snippet} + + diff --git a/src/lib/components/ui/pagination/pagination-next-button.svelte b/src/lib/components/ui/pagination/pagination-next-button.svelte new file mode 100644 index 0000000..cc40ee3 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-next-button.svelte @@ -0,0 +1,33 @@ + + +{#snippet Fallback()} + Next + +{/snippet} + + diff --git a/src/lib/components/ui/pagination/pagination-next.svelte b/src/lib/components/ui/pagination/pagination-next.svelte new file mode 100644 index 0000000..5bb37f7 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-next.svelte @@ -0,0 +1,29 @@ + + + + + diff --git a/src/lib/components/ui/pagination/pagination-prev-button.svelte b/src/lib/components/ui/pagination/pagination-prev-button.svelte new file mode 100644 index 0000000..28caad5 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-prev-button.svelte @@ -0,0 +1,33 @@ + + +{#snippet Fallback()} + + Previous +{/snippet} + + diff --git a/src/lib/components/ui/pagination/pagination-previous.svelte b/src/lib/components/ui/pagination/pagination-previous.svelte new file mode 100644 index 0000000..cf7c460 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination-previous.svelte @@ -0,0 +1,29 @@ + + + + + diff --git a/src/lib/components/ui/pagination/pagination.svelte b/src/lib/components/ui/pagination/pagination.svelte new file mode 100644 index 0000000..60e3471 --- /dev/null +++ b/src/lib/components/ui/pagination/pagination.svelte @@ -0,0 +1,28 @@ + + + diff --git a/src/lib/components/ui/popover/index.ts b/src/lib/components/ui/popover/index.ts new file mode 100644 index 0000000..b79d12e --- /dev/null +++ b/src/lib/components/ui/popover/index.ts @@ -0,0 +1,19 @@ +import Root from "./popover.svelte"; +import Close from "./popover-close.svelte"; +import Content from "./popover-content.svelte"; +import Trigger from "./popover-trigger.svelte"; +import Portal from "./popover-portal.svelte"; + +export { + Root, + Content, + Trigger, + Close, + Portal, + // + Root as Popover, + Content as PopoverContent, + Trigger as PopoverTrigger, + Close as PopoverClose, + Portal as PopoverPortal, +}; diff --git a/src/lib/components/ui/popover/popover-close.svelte b/src/lib/components/ui/popover/popover-close.svelte new file mode 100644 index 0000000..c360925 --- /dev/null +++ b/src/lib/components/ui/popover/popover-close.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/popover/popover-content.svelte b/src/lib/components/ui/popover/popover-content.svelte new file mode 100644 index 0000000..66b5a30 --- /dev/null +++ b/src/lib/components/ui/popover/popover-content.svelte @@ -0,0 +1,31 @@ + + + + + diff --git a/src/lib/components/ui/popover/popover-portal.svelte b/src/lib/components/ui/popover/popover-portal.svelte new file mode 100644 index 0000000..dd8265f --- /dev/null +++ b/src/lib/components/ui/popover/popover-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/popover/popover-trigger.svelte b/src/lib/components/ui/popover/popover-trigger.svelte new file mode 100644 index 0000000..586323c --- /dev/null +++ b/src/lib/components/ui/popover/popover-trigger.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/popover/popover.svelte b/src/lib/components/ui/popover/popover.svelte new file mode 100644 index 0000000..6b1aa5f --- /dev/null +++ b/src/lib/components/ui/popover/popover.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/progress/index.ts b/src/lib/components/ui/progress/index.ts new file mode 100644 index 0000000..25eee61 --- /dev/null +++ b/src/lib/components/ui/progress/index.ts @@ -0,0 +1,7 @@ +import Root from "./progress.svelte"; + +export { + Root, + // + Root as Progress, +}; diff --git a/src/lib/components/ui/progress/progress.svelte b/src/lib/components/ui/progress/progress.svelte new file mode 100644 index 0000000..6833013 --- /dev/null +++ b/src/lib/components/ui/progress/progress.svelte @@ -0,0 +1,27 @@ + + + +
    +
    diff --git a/src/lib/components/ui/scroll-area/index.ts b/src/lib/components/ui/scroll-area/index.ts new file mode 100644 index 0000000..e86a25b --- /dev/null +++ b/src/lib/components/ui/scroll-area/index.ts @@ -0,0 +1,10 @@ +import Scrollbar from "./scroll-area-scrollbar.svelte"; +import Root from "./scroll-area.svelte"; + +export { + Root, + Scrollbar, + //, + Root as ScrollArea, + Scrollbar as ScrollAreaScrollbar, +}; diff --git a/src/lib/components/ui/scroll-area/scroll-area-scrollbar.svelte b/src/lib/components/ui/scroll-area/scroll-area-scrollbar.svelte new file mode 100644 index 0000000..8f5d960 --- /dev/null +++ b/src/lib/components/ui/scroll-area/scroll-area-scrollbar.svelte @@ -0,0 +1,31 @@ + + + + {@render children?.()} + + diff --git a/src/lib/components/ui/scroll-area/scroll-area.svelte b/src/lib/components/ui/scroll-area/scroll-area.svelte new file mode 100644 index 0000000..86ee032 --- /dev/null +++ b/src/lib/components/ui/scroll-area/scroll-area.svelte @@ -0,0 +1,43 @@ + + + + + {@render children?.()} + + {#if orientation === "vertical" || orientation === "both"} + + {/if} + {#if orientation === "horizontal" || orientation === "both"} + + {/if} + + diff --git a/src/lib/components/ui/separator/index.ts b/src/lib/components/ui/separator/index.ts new file mode 100644 index 0000000..82442d2 --- /dev/null +++ b/src/lib/components/ui/separator/index.ts @@ -0,0 +1,7 @@ +import Root from "./separator.svelte"; + +export { + Root, + // + Root as Separator, +}; diff --git a/src/lib/components/ui/separator/separator.svelte b/src/lib/components/ui/separator/separator.svelte new file mode 100644 index 0000000..89b2695 --- /dev/null +++ b/src/lib/components/ui/separator/separator.svelte @@ -0,0 +1,21 @@ + + + diff --git a/src/lib/components/ui/sheet/index.ts b/src/lib/components/ui/sheet/index.ts new file mode 100644 index 0000000..28d7da1 --- /dev/null +++ b/src/lib/components/ui/sheet/index.ts @@ -0,0 +1,34 @@ +import Root from "./sheet.svelte"; +import Portal from "./sheet-portal.svelte"; +import Trigger from "./sheet-trigger.svelte"; +import Close from "./sheet-close.svelte"; +import Overlay from "./sheet-overlay.svelte"; +import Content from "./sheet-content.svelte"; +import Header from "./sheet-header.svelte"; +import Footer from "./sheet-footer.svelte"; +import Title from "./sheet-title.svelte"; +import Description from "./sheet-description.svelte"; + +export { + Root, + Close, + Trigger, + Portal, + Overlay, + Content, + Header, + Footer, + Title, + Description, + // + Root as Sheet, + Close as SheetClose, + Trigger as SheetTrigger, + Portal as SheetPortal, + Overlay as SheetOverlay, + Content as SheetContent, + Header as SheetHeader, + Footer as SheetFooter, + Title as SheetTitle, + Description as SheetDescription, +}; diff --git a/src/lib/components/ui/sheet/sheet-close.svelte b/src/lib/components/ui/sheet/sheet-close.svelte new file mode 100644 index 0000000..ae382c1 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-close.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet-content.svelte b/src/lib/components/ui/sheet/sheet-content.svelte new file mode 100644 index 0000000..81ec122 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-content.svelte @@ -0,0 +1,60 @@ + + + + + + + + {@render children?.()} + + + Close + + + diff --git a/src/lib/components/ui/sheet/sheet-description.svelte b/src/lib/components/ui/sheet/sheet-description.svelte new file mode 100644 index 0000000..333b17a --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-description.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet-footer.svelte b/src/lib/components/ui/sheet/sheet-footer.svelte new file mode 100644 index 0000000..dd9ed84 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-footer.svelte @@ -0,0 +1,20 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sheet/sheet-header.svelte b/src/lib/components/ui/sheet/sheet-header.svelte new file mode 100644 index 0000000..757a6a5 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-header.svelte @@ -0,0 +1,20 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sheet/sheet-overlay.svelte b/src/lib/components/ui/sheet/sheet-overlay.svelte new file mode 100644 index 0000000..345e197 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-overlay.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet-portal.svelte b/src/lib/components/ui/sheet/sheet-portal.svelte new file mode 100644 index 0000000..f3085a3 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet-title.svelte b/src/lib/components/ui/sheet/sheet-title.svelte new file mode 100644 index 0000000..9fda327 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-title.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet-trigger.svelte b/src/lib/components/ui/sheet/sheet-trigger.svelte new file mode 100644 index 0000000..e266975 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet-trigger.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/sheet/sheet.svelte b/src/lib/components/ui/sheet/sheet.svelte new file mode 100644 index 0000000..5bf9783 --- /dev/null +++ b/src/lib/components/ui/sheet/sheet.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/sidebar/constants.ts b/src/lib/components/ui/sidebar/constants.ts new file mode 100644 index 0000000..4de4435 --- /dev/null +++ b/src/lib/components/ui/sidebar/constants.ts @@ -0,0 +1,6 @@ +export const SIDEBAR_COOKIE_NAME = "sidebar:state"; +export const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7; +export const SIDEBAR_WIDTH = "16rem"; +export const SIDEBAR_WIDTH_MOBILE = "18rem"; +export const SIDEBAR_WIDTH_ICON = "3rem"; +export const SIDEBAR_KEYBOARD_SHORTCUT = "b"; diff --git a/src/lib/components/ui/sidebar/context.svelte.ts b/src/lib/components/ui/sidebar/context.svelte.ts new file mode 100644 index 0000000..15248ad --- /dev/null +++ b/src/lib/components/ui/sidebar/context.svelte.ts @@ -0,0 +1,81 @@ +import { IsMobile } from "$lib/hooks/is-mobile.svelte.js"; +import { getContext, setContext } from "svelte"; +import { SIDEBAR_KEYBOARD_SHORTCUT } from "./constants.js"; + +type Getter = () => T; + +export type SidebarStateProps = { + /** + * A getter function that returns the current open state of the sidebar. + * We use a getter function here to support `bind:open` on the `Sidebar.Provider` + * component. + */ + open: Getter; + + /** + * A function that sets the open state of the sidebar. To support `bind:open`, we need + * a source of truth for changing the open state to ensure it will be synced throughout + * the sub-components and any `bind:` references. + */ + setOpen: (open: boolean) => void; +}; + +class SidebarState { + readonly props: SidebarStateProps; + open = $derived.by(() => this.props.open()); + openMobile = $state(false); + setOpen: SidebarStateProps["setOpen"]; + #isMobile: IsMobile; + state = $derived.by(() => (this.open ? "expanded" : "collapsed")); + + constructor(props: SidebarStateProps) { + this.setOpen = props.setOpen; + this.#isMobile = new IsMobile(); + this.props = props; + } + + // Convenience getter for checking if the sidebar is mobile + // without this, we would need to use `sidebar.isMobile.current` everywhere + get isMobile() { + return this.#isMobile.current; + } + + // Event handler to apply to the `` + handleShortcutKeydown = (e: KeyboardEvent) => { + if (e.key === SIDEBAR_KEYBOARD_SHORTCUT && (e.metaKey || e.ctrlKey)) { + e.preventDefault(); + this.toggle(); + } + }; + + setOpenMobile = (value: boolean) => { + this.openMobile = value; + }; + + toggle = () => { + return this.#isMobile.current + ? (this.openMobile = !this.openMobile) + : this.setOpen(!this.open); + }; +} + +const SYMBOL_KEY = "scn-sidebar"; + +/** + * Instantiates a new `SidebarState` instance and sets it in the context. + * + * @param props The constructor props for the `SidebarState` class. + * @returns The `SidebarState` instance. + */ +export function setSidebar(props: SidebarStateProps): SidebarState { + return setContext(Symbol.for(SYMBOL_KEY), new SidebarState(props)); +} + +/** + * Retrieves the `SidebarState` instance from the context. This is a class instance, + * so you cannot destructure it. + * @returns The `SidebarState` instance. + */ +export function useSidebar(): SidebarState { + return getContext(Symbol.for(SYMBOL_KEY)); +} diff --git a/src/lib/components/ui/sidebar/index.ts b/src/lib/components/ui/sidebar/index.ts new file mode 100644 index 0000000..318a341 --- /dev/null +++ b/src/lib/components/ui/sidebar/index.ts @@ -0,0 +1,75 @@ +import { useSidebar } from "./context.svelte.js"; +import Content from "./sidebar-content.svelte"; +import Footer from "./sidebar-footer.svelte"; +import GroupAction from "./sidebar-group-action.svelte"; +import GroupContent from "./sidebar-group-content.svelte"; +import GroupLabel from "./sidebar-group-label.svelte"; +import Group from "./sidebar-group.svelte"; +import Header from "./sidebar-header.svelte"; +import Input from "./sidebar-input.svelte"; +import Inset from "./sidebar-inset.svelte"; +import MenuAction from "./sidebar-menu-action.svelte"; +import MenuBadge from "./sidebar-menu-badge.svelte"; +import MenuButton from "./sidebar-menu-button.svelte"; +import MenuItem from "./sidebar-menu-item.svelte"; +import MenuSkeleton from "./sidebar-menu-skeleton.svelte"; +import MenuSubButton from "./sidebar-menu-sub-button.svelte"; +import MenuSubItem from "./sidebar-menu-sub-item.svelte"; +import MenuSub from "./sidebar-menu-sub.svelte"; +import Menu from "./sidebar-menu.svelte"; +import Provider from "./sidebar-provider.svelte"; +import Rail from "./sidebar-rail.svelte"; +import Separator from "./sidebar-separator.svelte"; +import Trigger from "./sidebar-trigger.svelte"; +import Root from "./sidebar.svelte"; + +export { + Content, + Footer, + Group, + GroupAction, + GroupContent, + GroupLabel, + Header, + Input, + Inset, + Menu, + MenuAction, + MenuBadge, + MenuButton, + MenuItem, + MenuSkeleton, + MenuSub, + MenuSubButton, + MenuSubItem, + Provider, + Rail, + Root, + Separator, + // + Root as Sidebar, + Content as SidebarContent, + Footer as SidebarFooter, + Group as SidebarGroup, + GroupAction as SidebarGroupAction, + GroupContent as SidebarGroupContent, + GroupLabel as SidebarGroupLabel, + Header as SidebarHeader, + Input as SidebarInput, + Inset as SidebarInset, + Menu as SidebarMenu, + MenuAction as SidebarMenuAction, + MenuBadge as SidebarMenuBadge, + MenuButton as SidebarMenuButton, + MenuItem as SidebarMenuItem, + MenuSkeleton as SidebarMenuSkeleton, + MenuSub as SidebarMenuSub, + MenuSubButton as SidebarMenuSubButton, + MenuSubItem as SidebarMenuSubItem, + Provider as SidebarProvider, + Rail as SidebarRail, + Separator as SidebarSeparator, + Trigger as SidebarTrigger, + Trigger, + useSidebar, +}; diff --git a/src/lib/components/ui/sidebar/sidebar-content.svelte b/src/lib/components/ui/sidebar/sidebar-content.svelte new file mode 100644 index 0000000..f121800 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-content.svelte @@ -0,0 +1,24 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-footer.svelte b/src/lib/components/ui/sidebar/sidebar-footer.svelte new file mode 100644 index 0000000..6259cb9 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-footer.svelte @@ -0,0 +1,21 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-group-action.svelte b/src/lib/components/ui/sidebar/sidebar-group-action.svelte new file mode 100644 index 0000000..241e971 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-group-action.svelte @@ -0,0 +1,36 @@ + + +{#if child} + {@render child({ props: mergedProps })} +{:else} + +{/if} diff --git a/src/lib/components/ui/sidebar/sidebar-group-content.svelte b/src/lib/components/ui/sidebar/sidebar-group-content.svelte new file mode 100644 index 0000000..415255f --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-group-content.svelte @@ -0,0 +1,21 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-group-label.svelte b/src/lib/components/ui/sidebar/sidebar-group-label.svelte new file mode 100644 index 0000000..e292945 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-group-label.svelte @@ -0,0 +1,34 @@ + + +{#if child} + {@render child({ props: mergedProps })} +{:else} +
    + {@render children?.()} +
    +{/if} diff --git a/src/lib/components/ui/sidebar/sidebar-group.svelte b/src/lib/components/ui/sidebar/sidebar-group.svelte new file mode 100644 index 0000000..ec18a69 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-group.svelte @@ -0,0 +1,21 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-header.svelte b/src/lib/components/ui/sidebar/sidebar-header.svelte new file mode 100644 index 0000000..a1b2db1 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-header.svelte @@ -0,0 +1,21 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-input.svelte b/src/lib/components/ui/sidebar/sidebar-input.svelte new file mode 100644 index 0000000..19b3666 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-input.svelte @@ -0,0 +1,21 @@ + + + diff --git a/src/lib/components/ui/sidebar/sidebar-inset.svelte b/src/lib/components/ui/sidebar/sidebar-inset.svelte new file mode 100644 index 0000000..4eac0f3 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-inset.svelte @@ -0,0 +1,24 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-menu-action.svelte b/src/lib/components/ui/sidebar/sidebar-menu-action.svelte new file mode 100644 index 0000000..98d5c4a --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-action.svelte @@ -0,0 +1,43 @@ + + +{#if child} + {@render child({ props: mergedProps })} +{:else} + +{/if} diff --git a/src/lib/components/ui/sidebar/sidebar-menu-badge.svelte b/src/lib/components/ui/sidebar/sidebar-menu-badge.svelte new file mode 100644 index 0000000..66edc8c --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-badge.svelte @@ -0,0 +1,29 @@ + + +
    + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-menu-button.svelte b/src/lib/components/ui/sidebar/sidebar-menu-button.svelte new file mode 100644 index 0000000..55ca616 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-button.svelte @@ -0,0 +1,103 @@ + + + + +{#snippet Button({ props }: { props?: Record })} + {@const mergedProps = mergeProps(buttonProps, props)} + {#if child} + {@render child({ props: mergedProps })} + {:else} + + {/if} +{/snippet} + +{#if !tooltipContent} + {@render Button({})} +{:else} + + + {#snippet child({ props })} + {@render Button({ props })} + {/snippet} + + + +{/if} diff --git a/src/lib/components/ui/sidebar/sidebar-menu-item.svelte b/src/lib/components/ui/sidebar/sidebar-menu-item.svelte new file mode 100644 index 0000000..4db4453 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-item.svelte @@ -0,0 +1,21 @@ + + +
  • + {@render children?.()} +
  • diff --git a/src/lib/components/ui/sidebar/sidebar-menu-skeleton.svelte b/src/lib/components/ui/sidebar/sidebar-menu-skeleton.svelte new file mode 100644 index 0000000..cc63b04 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-skeleton.svelte @@ -0,0 +1,36 @@ + + +
    + {#if showIcon} + + {/if} + + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-menu-sub-button.svelte b/src/lib/components/ui/sidebar/sidebar-menu-sub-button.svelte new file mode 100644 index 0000000..987f104 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-sub-button.svelte @@ -0,0 +1,43 @@ + + +{#if child} + {@render child({ props: mergedProps })} +{:else} + + {@render children?.()} + +{/if} diff --git a/src/lib/components/ui/sidebar/sidebar-menu-sub-item.svelte b/src/lib/components/ui/sidebar/sidebar-menu-sub-item.svelte new file mode 100644 index 0000000..681d0f1 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-sub-item.svelte @@ -0,0 +1,21 @@ + + +
  • + {@render children?.()} +
  • diff --git a/src/lib/components/ui/sidebar/sidebar-menu-sub.svelte b/src/lib/components/ui/sidebar/sidebar-menu-sub.svelte new file mode 100644 index 0000000..76bd1d9 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu-sub.svelte @@ -0,0 +1,25 @@ + + +
      + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-menu.svelte b/src/lib/components/ui/sidebar/sidebar-menu.svelte new file mode 100644 index 0000000..946ccce --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-menu.svelte @@ -0,0 +1,21 @@ + + +
      + {@render children?.()} +
    diff --git a/src/lib/components/ui/sidebar/sidebar-provider.svelte b/src/lib/components/ui/sidebar/sidebar-provider.svelte new file mode 100644 index 0000000..5b0d0aa --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-provider.svelte @@ -0,0 +1,53 @@ + + + + + +
    + {@render children?.()} +
    +
    diff --git a/src/lib/components/ui/sidebar/sidebar-rail.svelte b/src/lib/components/ui/sidebar/sidebar-rail.svelte new file mode 100644 index 0000000..1077527 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-rail.svelte @@ -0,0 +1,36 @@ + + + diff --git a/src/lib/components/ui/sidebar/sidebar-separator.svelte b/src/lib/components/ui/sidebar/sidebar-separator.svelte new file mode 100644 index 0000000..5a7deda --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-separator.svelte @@ -0,0 +1,19 @@ + + + diff --git a/src/lib/components/ui/sidebar/sidebar-trigger.svelte b/src/lib/components/ui/sidebar/sidebar-trigger.svelte new file mode 100644 index 0000000..1825182 --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar-trigger.svelte @@ -0,0 +1,35 @@ + + + diff --git a/src/lib/components/ui/sidebar/sidebar.svelte b/src/lib/components/ui/sidebar/sidebar.svelte new file mode 100644 index 0000000..6c0c0cb --- /dev/null +++ b/src/lib/components/ui/sidebar/sidebar.svelte @@ -0,0 +1,104 @@ + + +{#if collapsible === "none"} +
    + {@render children?.()} +
    +{:else if sidebar.isMobile} + sidebar.openMobile, (v) => sidebar.setOpenMobile(v)} + {...restProps} + > + + + Sidebar + Displays the mobile sidebar. + +
    + {@render children?.()} +
    +
    +
    +{:else} + +{/if} diff --git a/src/lib/components/ui/skeleton/index.ts b/src/lib/components/ui/skeleton/index.ts new file mode 100644 index 0000000..186db21 --- /dev/null +++ b/src/lib/components/ui/skeleton/index.ts @@ -0,0 +1,7 @@ +import Root from "./skeleton.svelte"; + +export { + Root, + // + Root as Skeleton, +}; diff --git a/src/lib/components/ui/skeleton/skeleton.svelte b/src/lib/components/ui/skeleton/skeleton.svelte new file mode 100644 index 0000000..c7e3d26 --- /dev/null +++ b/src/lib/components/ui/skeleton/skeleton.svelte @@ -0,0 +1,17 @@ + + +
    diff --git a/src/lib/components/ui/sonner/index.ts b/src/lib/components/ui/sonner/index.ts new file mode 100644 index 0000000..1ad9f4a --- /dev/null +++ b/src/lib/components/ui/sonner/index.ts @@ -0,0 +1 @@ +export { default as Toaster } from "./sonner.svelte"; diff --git a/src/lib/components/ui/sonner/sonner.svelte b/src/lib/components/ui/sonner/sonner.svelte new file mode 100644 index 0000000..08a1865 --- /dev/null +++ b/src/lib/components/ui/sonner/sonner.svelte @@ -0,0 +1,34 @@ + + +{#snippet loadingIcon()} + + {/snippet} + {#snippet successIcon()} + + {/snippet} + {#snippet errorIcon()} + + {/snippet} + {#snippet infoIcon()} + + {/snippet} + {#snippet warningIcon()} + + {/snippet} + diff --git a/src/lib/components/ui/spinner/index.ts b/src/lib/components/ui/spinner/index.ts new file mode 100644 index 0000000..f8b1ced --- /dev/null +++ b/src/lib/components/ui/spinner/index.ts @@ -0,0 +1 @@ +export { default as Spinner } from "./spinner.svelte"; diff --git a/src/lib/components/ui/spinner/spinner.svelte b/src/lib/components/ui/spinner/spinner.svelte new file mode 100644 index 0000000..9b12131 --- /dev/null +++ b/src/lib/components/ui/spinner/spinner.svelte @@ -0,0 +1,14 @@ + + + diff --git a/src/lib/components/ui/table/index.ts b/src/lib/components/ui/table/index.ts new file mode 100644 index 0000000..14695c8 --- /dev/null +++ b/src/lib/components/ui/table/index.ts @@ -0,0 +1,28 @@ +import Root from "./table.svelte"; +import Body from "./table-body.svelte"; +import Caption from "./table-caption.svelte"; +import Cell from "./table-cell.svelte"; +import Footer from "./table-footer.svelte"; +import Head from "./table-head.svelte"; +import Header from "./table-header.svelte"; +import Row from "./table-row.svelte"; + +export { + Root, + Body, + Caption, + Cell, + Footer, + Head, + Header, + Row, + // + Root as Table, + Body as TableBody, + Caption as TableCaption, + Cell as TableCell, + Footer as TableFooter, + Head as TableHead, + Header as TableHeader, + Row as TableRow, +}; diff --git a/src/lib/components/ui/table/table-body.svelte b/src/lib/components/ui/table/table-body.svelte new file mode 100644 index 0000000..29e9687 --- /dev/null +++ b/src/lib/components/ui/table/table-body.svelte @@ -0,0 +1,20 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-caption.svelte b/src/lib/components/ui/table/table-caption.svelte new file mode 100644 index 0000000..4696cff --- /dev/null +++ b/src/lib/components/ui/table/table-caption.svelte @@ -0,0 +1,20 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-cell.svelte b/src/lib/components/ui/table/table-cell.svelte new file mode 100644 index 0000000..2c0c26a --- /dev/null +++ b/src/lib/components/ui/table/table-cell.svelte @@ -0,0 +1,23 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-footer.svelte b/src/lib/components/ui/table/table-footer.svelte new file mode 100644 index 0000000..b9b14eb --- /dev/null +++ b/src/lib/components/ui/table/table-footer.svelte @@ -0,0 +1,20 @@ + + +tr]:last:border-b-0", className)} + {...restProps} +> + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-head.svelte b/src/lib/components/ui/table/table-head.svelte new file mode 100644 index 0000000..b67a6f9 --- /dev/null +++ b/src/lib/components/ui/table/table-head.svelte @@ -0,0 +1,23 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-header.svelte b/src/lib/components/ui/table/table-header.svelte new file mode 100644 index 0000000..f47d259 --- /dev/null +++ b/src/lib/components/ui/table/table-header.svelte @@ -0,0 +1,20 @@ + + + + {@render children?.()} + diff --git a/src/lib/components/ui/table/table-row.svelte b/src/lib/components/ui/table/table-row.svelte new file mode 100644 index 0000000..0df769e --- /dev/null +++ b/src/lib/components/ui/table/table-row.svelte @@ -0,0 +1,23 @@ + + +svelte-css-wrapper]:[&>th,td]:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", + className + )} + {...restProps} +> + {@render children?.()} + diff --git a/src/lib/components/ui/table/table.svelte b/src/lib/components/ui/table/table.svelte new file mode 100644 index 0000000..a334956 --- /dev/null +++ b/src/lib/components/ui/table/table.svelte @@ -0,0 +1,22 @@ + + +
    + + {@render children?.()} +
    +
    diff --git a/src/lib/components/ui/tabs/index.ts b/src/lib/components/ui/tabs/index.ts new file mode 100644 index 0000000..12d4327 --- /dev/null +++ b/src/lib/components/ui/tabs/index.ts @@ -0,0 +1,16 @@ +import Root from "./tabs.svelte"; +import Content from "./tabs-content.svelte"; +import List from "./tabs-list.svelte"; +import Trigger from "./tabs-trigger.svelte"; + +export { + Root, + Content, + List, + Trigger, + // + Root as Tabs, + Content as TabsContent, + List as TabsList, + Trigger as TabsTrigger, +}; diff --git a/src/lib/components/ui/tabs/tabs-content.svelte b/src/lib/components/ui/tabs/tabs-content.svelte new file mode 100644 index 0000000..340d65c --- /dev/null +++ b/src/lib/components/ui/tabs/tabs-content.svelte @@ -0,0 +1,17 @@ + + + diff --git a/src/lib/components/ui/tabs/tabs-list.svelte b/src/lib/components/ui/tabs/tabs-list.svelte new file mode 100644 index 0000000..08932b6 --- /dev/null +++ b/src/lib/components/ui/tabs/tabs-list.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/tabs/tabs-trigger.svelte b/src/lib/components/ui/tabs/tabs-trigger.svelte new file mode 100644 index 0000000..e623b36 --- /dev/null +++ b/src/lib/components/ui/tabs/tabs-trigger.svelte @@ -0,0 +1,20 @@ + + + diff --git a/src/lib/components/ui/tabs/tabs.svelte b/src/lib/components/ui/tabs/tabs.svelte new file mode 100644 index 0000000..ef6cada --- /dev/null +++ b/src/lib/components/ui/tabs/tabs.svelte @@ -0,0 +1,19 @@ + + + diff --git a/src/lib/components/ui/terminal/index.ts b/src/lib/components/ui/terminal/index.ts new file mode 100644 index 0000000..e274985 --- /dev/null +++ b/src/lib/components/ui/terminal/index.ts @@ -0,0 +1,4 @@ +import Terminal from './terminal.svelte'; +export { + Terminal as TerminalComponent +} \ No newline at end of file diff --git a/src/lib/components/ui/terminal/terminal.svelte b/src/lib/components/ui/terminal/terminal.svelte new file mode 100644 index 0000000..3569ba5 --- /dev/null +++ b/src/lib/components/ui/terminal/terminal.svelte @@ -0,0 +1,147 @@ + + +
    + +
    diff --git a/src/lib/components/ui/tooltip/index.ts b/src/lib/components/ui/tooltip/index.ts new file mode 100644 index 0000000..1718604 --- /dev/null +++ b/src/lib/components/ui/tooltip/index.ts @@ -0,0 +1,19 @@ +import Root from "./tooltip.svelte"; +import Trigger from "./tooltip-trigger.svelte"; +import Content from "./tooltip-content.svelte"; +import Provider from "./tooltip-provider.svelte"; +import Portal from "./tooltip-portal.svelte"; + +export { + Root, + Trigger, + Content, + Provider, + Portal, + // + Root as Tooltip, + Content as TooltipContent, + Trigger as TooltipTrigger, + Provider as TooltipProvider, + Portal as TooltipPortal, +}; diff --git a/src/lib/components/ui/tooltip/tooltip-content.svelte b/src/lib/components/ui/tooltip/tooltip-content.svelte new file mode 100644 index 0000000..5267aa5 --- /dev/null +++ b/src/lib/components/ui/tooltip/tooltip-content.svelte @@ -0,0 +1,52 @@ + + + + + {@render children?.()} + + {#snippet child({ props })} +
    + {/snippet} +
    +
    +
    diff --git a/src/lib/components/ui/tooltip/tooltip-portal.svelte b/src/lib/components/ui/tooltip/tooltip-portal.svelte new file mode 100644 index 0000000..d234f7d --- /dev/null +++ b/src/lib/components/ui/tooltip/tooltip-portal.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/tooltip/tooltip-provider.svelte b/src/lib/components/ui/tooltip/tooltip-provider.svelte new file mode 100644 index 0000000..8150bef --- /dev/null +++ b/src/lib/components/ui/tooltip/tooltip-provider.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/tooltip/tooltip-trigger.svelte b/src/lib/components/ui/tooltip/tooltip-trigger.svelte new file mode 100644 index 0000000..1acdaa4 --- /dev/null +++ b/src/lib/components/ui/tooltip/tooltip-trigger.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/components/ui/tooltip/tooltip.svelte b/src/lib/components/ui/tooltip/tooltip.svelte new file mode 100644 index 0000000..0b0f9ce --- /dev/null +++ b/src/lib/components/ui/tooltip/tooltip.svelte @@ -0,0 +1,7 @@ + + + diff --git a/src/lib/core/adb/adb.ts b/src/lib/core/adb/adb.ts new file mode 100644 index 0000000..91bd950 --- /dev/null +++ b/src/lib/core/adb/adb.ts @@ -0,0 +1,184 @@ +import { Adb, AdbDaemonTransport, encodeUtf8 } from '@yume-chan/adb'; +import AdbWebCredentialStore from '@yume-chan/adb-credential-web'; +import { + AdbDaemonWebUsbDeviceManager, + AdbDaemonWebUsbDeviceObserver, + type AdbDaemonWebUsbDevice +} from '@yume-chan/adb-daemon-webusb'; +import { AdbInstance } from '../../../routes/state.svelte'; +import { deviceCredentialManager } from './deviceCredManager'; +import { Consumable, MaybeConsumable, ReadableStream } from '@yume-chan/stream-extra'; +import { AdbScrcpyClient } from '@yume-chan/adb-scrcpy'; + +export async function connnectViaWebUSB() { + const device = await AdbDaemonWebUsbDeviceManager.BROWSER?.requestDevice(); + console.log('usb ok', globalThis.navigator.usb); + if (device) { + console.log('connect ', device.name); + + try { + const credentialStore = new AdbWebCredentialStore(); + const connection = await device.connect(); + + const transport = await AdbDaemonTransport.authenticate({ + connection: connection, + serial: device.serial, + credentialStore: credentialStore + }); + + const adb = new Adb(transport); + saveAdbInstance(adb); + + // save device info + await deviceCredentialManager.saveDeviceInfo(device); + } catch (e: any) { + console.error('error on connect', e); + throw new Error(e.toString()); + } + } +} + +export async function connectDeviceByCred( + device: AdbDaemonWebUsbDevice, + credStore: AdbWebCredentialStore +) { + try { + const connection = await device.connect(); + const transport = await AdbDaemonTransport.authenticate({ + connection: connection, + serial: device.serial, + credentialStore: credStore + }); + + const adb = new Adb(transport); + saveAdbInstance(adb); + + return true; + } catch (error) { + throw error; + } +} + +export function saveAdbInstance(adb: Adb | undefined) { + AdbInstance.instance = adb; +} + +export function getAdbInstance() { + return AdbInstance.instance; +} + +export async function executeCmd(command: string) { + let instance = getAdbInstance(); + + if (!instance) { + console.error('instance not found'); + return {}; + } + + try { + if (instance?.subprocess.shellProtocol?.isSupported) { + const result = await instance.subprocess.shellProtocol.spawnWaitText(command); + return { + output: result.stdout, + error: result.stderr, + exitCode: result.exitCode + }; + } else { + const process = await instance.subprocess.noneProtocol.spawn(command); + const reader = process.output.getReader(); + const chunks = []; + const decoder = new TextDecoder(); + + while (true) { + const { done, value } = await reader.read(); + if (done) break; + chunks.push(decoder.decode(value, { stream: true })); + } + + return { + output: chunks.join('') + }; + } + } catch (e: any) { + console.log(e.message); + //ExactReadable ended + if (e.message.includes('ExactReadable ended')) { + console.error('connection cut off'); + return { + error: 'ExactReadableEndedError' + }; + } + + console.error('error while execute command', e); + return {}; + } +} + +export async function disconnect() { + let instance = getAdbInstance(); + if (instance) { + await instance.close(); + console.log('close instance'); + saveAdbInstance(undefined); + } +} + +export async function pull(filename: string) { + let instance = getAdbInstance(); + if (instance) { + let chunkList: Uint8Array[] = []; + let sync = await instance.sync(); + const content = sync.read(filename); + let result = content.values(); + let res; + + let result_string = ''; + + while ((res = await result.next()) != null) { + // console.log(res.value); + if (res.value != undefined) { + result_string += new TextDecoder().decode(res.value); + } + if (res.done) { + break; + } + } + + return result_string; + } +} + +export async function push(path: string, obj: string) { + let instance = getAdbInstance(); + if (instance) { + let sync = await instance.sync(); + const encoder = new TextEncoder(); + + const file: ReadableStream> = new ReadableStream({ + start(controller) { + controller.enqueue(new Uint8Array(encoder.encode(obj))); + controller.close(); + } + }); + + try { + console.log('support push v2', sync.supportsSendReceiveV2); + + await sync.write({ + filename: path, + file + }); + } catch (error) { + console.log('error while trying to write to machine', error); + } finally { + await sync.dispose(); + } + } +} + +// logcat stream + +// TODO: screen mirror +export function getScrcpyBinaryFromSource() { + //https://github.com/Genymobile/scrcpy/releases +} diff --git a/src/lib/core/adb/deviceCredManager.ts b/src/lib/core/adb/deviceCredManager.ts new file mode 100644 index 0000000..39b39da --- /dev/null +++ b/src/lib/core/adb/deviceCredManager.ts @@ -0,0 +1,106 @@ +import AdbWebCredentialStore from '@yume-chan/adb-credential-web'; + +export class DeviceCredentialManager { + #credentialStore; + constructor() { + this.#credentialStore = new AdbWebCredentialStore(); + } + + async saveDeviceInfo(device: any) { + try { + const deviceInfo = { + name: device.name, + serial: device.serial, + vendorId: device.vendorId, + productId: device.productId, + lastConnected: new Date().toISOString() + }; + + const storedDevices = this.getStoredDeviceInfos(); + storedDevices[device.serial] = deviceInfo; + + localStorage.setItem('adb_device_infos', JSON.stringify(storedDevices)); + console.log('save device info', deviceInfo); + } catch (error) { + console.error('save device info error', error); + } + } + + getStoredDeviceInfos() { + try { + const stored = localStorage.getItem('adb_device_infos'); + return stored ? JSON.parse(stored) : {}; + } catch (error) { + console.error('unable to get stored device info', error); + return {}; + } + } + + async hasStoredKeys() { + try { + for await (const key of this.#credentialStore.iterateKeys()) { + return true; + } + return false; + } catch (error) { + console.error('check stored keys fail', error); + return false; + } + } + + async getStoredKeyCount() { + try { + let count = 0; + for await (const key of this.#credentialStore.iterateKeys()) { + count++; + } + + return count; + } catch (error) { + console.error('get key stored count error', error); + return 0; + } + } + + async clearAllCredentials() { + try { + let clearedCount = 0; + const keys = []; + for await (const key of this.#credentialStore.iterateKeys()) { + keys.push(key); + } + + for (const key of keys) { + try { + clearedCount++; + } catch (error) { + console.error('clear error', error); + } + } + + localStorage.removeItem('adb_device_infos'); + + try { + const dbName = 'webadb-credentials'; + const request = indexedDB.deleteDatabase(dbName); + + await new Promise((resolve, reject) => { + request.onsuccess = () => resolve(null); + request.onerror = () => reject(request.error); + request.onblocked = () => { + console.warn('request delete got blocked'); + resolve(null); + }; + }); + } catch (error) { + console.error(error); + } + return clearedCount; + } catch (error) { + console.error(error); + return 0; + } + } +} + +export const deviceCredentialManager = new DeviceCredentialManager(); diff --git a/src/lib/core/auth/domainBlocker.ts b/src/lib/core/auth/domainBlocker.ts new file mode 100644 index 0000000..fa55018 --- /dev/null +++ b/src/lib/core/auth/domainBlocker.ts @@ -0,0 +1,17 @@ +import { doc, getDoc } from "firebase/firestore"; +import { db } from "../client/firebase"; + + +export async function checkAllowAccess(userDomain: string): Promise { + + const docRef = doc(db, "whitelist", "allowedDomains"); + const snapshot = await getDoc(docRef); + + if(snapshot.exists()){ + let domains = snapshot.data(); + // console.log(`domains: ${JSON.stringify(domains)}`); + return domains["account_email"].includes(userDomain); + } + + return false; +}; \ No newline at end of file diff --git a/src/lib/core/auth/userPermissions.ts b/src/lib/core/auth/userPermissions.ts new file mode 100644 index 0000000..bad57c2 --- /dev/null +++ b/src/lib/core/auth/userPermissions.ts @@ -0,0 +1,90 @@ +import type { User } from "firebase/auth"; +import { addDoc, collection, doc, getDoc, setDoc, updateDoc } from "firebase/firestore"; +import { db } from "../client/firebase"; + +export enum UserPermissions { + NO_PERMISSION, + THAI_PERMISSION = 1 << 0, + MALAY_PERMISSION = 1 << 1, + AUS_PERMISSION = 1 << 2, + ALPHA3_PERMISSION = 1 << 3, + + VIEWER = 1 << 4, + EDITOR = 1 << 7, + + DUBAI_PERMISSION = 1 << 8, + COUNTER_PERMISSION = 1 << 9, + SINGAPORE_PERMISSION = 1 << 10, + COCKTAIL_PERMISSION = 1 << 11, + + // add new permission by shifting after 7. eg. 8,9,... + // also do add at server + + SUPER_ADMIN_PERMISSION = THAI_PERMISSION | + MALAY_PERMISSION | + AUS_PERMISSION | + ALPHA3_PERMISSION | + COUNTER_PERMISSION | + SINGAPORE_PERMISSION | + DUBAI_PERMISSION | + COCKTAIL_PERMISSION | + (EDITOR | VIEWER), +} + +export function getPermissions(perms: number): UserPermissions[] { + return Object.values(UserPermissions).filter( + (permission) => + typeof permission === "number" && (perms & permission) !== 0, + ) as UserPermissions[]; +} + +export function getDefaultPermission(): UserPermissions { + return UserPermissions.NO_PERMISSION; +} + +export async function getUserPermission(user: User | null): Promise { + if(user == null){ + return []; + } + let qid = user.uid; + let defaultPerms = ["no_permission"]; + // TODO: collect only important fields + const ignoredFields = [ + "apiKey", + ]; + const docRef = doc(db, "users", "data"); + + + const snapshot = await getDoc(docRef); + if(snapshot.exists()){ + let user_data = snapshot.data(); + if(Object.keys(user_data).includes(qid)){ + return user_data[qid]["permissions"]; + } else { + + let umap: any = user.toJSON(); + umap["permissions"] = defaultPerms; + umap["role"] = "guest"; + + for(let ignoredField of ignoredFields){ + umap[ignoredField] = undefined; + } + + let cleaned_umap: any = {}; + for(let k of Object.keys(umap)){ + if(umap[k] != undefined){ + cleaned_umap[k] = umap[k]; + } + } + + let fmap: any = {}; + fmap[qid] = cleaned_umap; + + await updateDoc(doc(db, "users", "data"), fmap); + + return defaultPerms; + } + } + + return []; +} \ No newline at end of file diff --git a/src/lib/core/client/server.ts b/src/lib/core/client/server.ts new file mode 100644 index 0000000..9833aee --- /dev/null +++ b/src/lib/core/client/server.ts @@ -0,0 +1,38 @@ +import { get } from 'svelte/store'; +import { departmentStore } from '../stores/departments'; +import { sendMessage } from '../handlers/ws_messageSender'; +import { auth } from '../stores/auth'; +import { extractCookieOnNonBrowser } from '$lib/helpers/cookie'; +import { browser } from '$app/environment'; + +export async function getRecipes() { + if (browser && !get(departmentStore)) { + console.log('cannot get dep', get(departmentStore)); + return []; + } + + let countryTarget = get(departmentStore); + let country = ''; + + // if (!countryTarget && !browser) { + // countryTarget = extractCookieOnNonBrowser()['department']; + // } + + // construct path. fetch (GET) {server}/recipe/{countryTarget}/{version} + let idToken = await get(auth)?.getIdToken(); + + console.log('country target get recipe', country); + + sendMessage({ + type: 'recipe', + payload: { + auth: idToken ?? '', + partial: false, + country: countryTarget ?? '', + version: -1, + parameters: '' + } + }); + + return []; +} diff --git a/src/lib/core/handlers/messageHandler.ts b/src/lib/core/handlers/messageHandler.ts new file mode 100644 index 0000000..3f399ff --- /dev/null +++ b/src/lib/core/handlers/messageHandler.ts @@ -0,0 +1,98 @@ +import { get, writable } from 'svelte/store'; +import { addNotification, notiStore } from '../stores/noti'; +import { + recipeData, + recipeDataError, + recipeLoading, + recipeOverviewData, + recipeStreamMeta +} from '../stores/recipeStore'; + +export const messages = writable([]); + +type WSMessage = { type: string; payload: any }; + +const handlers: Record void> = { + chat: (p) => messages.update((m) => [...m, p]), + ping: (p) => console.log('ping from server'), + recipeResponse: (p) => { + let recipe_result = p.result; + let recipe_request = p.request; + + if (recipe_result) { + addNotification('INFO:Start fetch recipe!'); + } + }, + stream_data_start: (p) => { + let stream_id = p.stream_id; + let total_size = p.total_size; + let chunk_size = p.chunk_size; + + if (stream_id) { + addNotification('INFO:Start streaming data'); + recipeLoading.set(true); + recipeStreamMeta.set({ + id: stream_id, + total_size: total_size, + chunk_size: chunk_size, + progress: 0 + }); + recipeData.set([]); + recipeOverviewData.set([]); + } + }, + stream_data_error: (p) => { + recipeLoading.set(false); + recipeDataError.set(p); + + setTimeout(() => { + addNotification(`ERROR:${p.error}`); + }, 2000); + }, + stream_data_chunk: (p) => { + let current_meta = get(recipeStreamMeta); + if (current_meta) { + let stream_id = current_meta.id; + + let progress_response_id = p.stream_id; + if (stream_id === progress_response_id) { + let current_response_end = p.start_idx + current_meta.chunk_size; + let percent = (current_response_end / current_meta.total_size) * 100; + if (percent > 100) { + percent = 100; + } + let data = p.data; + let currentData = get(recipeData); + for (let rp of data) { + currentData.push(rp); + } + recipeData.set(currentData); + recipeStreamMeta.set({ + ...current_meta, + progress: percent + }); + + // build overview + + if (percent == 100) { + addNotification(`INFO:Current progress ${percent}%`); + } + } + } + }, + stream_data_end: (p) => { + recipeLoading.set(false); + }, + stream_patch_update: (p) => {} +}; + +export function handleIncomingMessages(raw: string) { + const msg: WSMessage = JSON.parse(raw); + console.log(`${new Date().toLocaleTimeString()}:ws msg`, msg); + if (msg == null) { + // error response + addNotification('ERR:No response from server'); + return; + } + handlers[msg.type]?.(msg.payload); +} diff --git a/src/lib/core/handlers/permissionHandler.ts b/src/lib/core/handlers/permissionHandler.ts new file mode 100644 index 0000000..59306f1 --- /dev/null +++ b/src/lib/core/handlers/permissionHandler.ts @@ -0,0 +1,41 @@ +import { get } from "svelte/store"; +import { permission as currentPermissions } from "$lib/core/stores/permissions"; + + + +const splitPermCache = new Map(); +function splitPerm(p: string): string[]{ + if(!splitPermCache.has(p)){ + splitPermCache.set(p, p.split(".")); + } + return splitPermCache.get(p)!; +} + +/// Check if current user has exacted permissions +export function requirePermission(...permissions: string[]): boolean { + // let perms = get(currentPermissions); + // let countOk = 0; + // for(let perm of perms){ + // if(permissions.includes(perm)){ + // countOk += 1; + // } + // } + // return countOk > 0 && countOk == perms.length; + const userPerms = get(currentPermissions); + return permissions.every(req => { + return userPerms.includes(req); + }); +} + + +/// Check permission of user by +export function needPermission(...permissions: string[]): boolean { + const userPerms = get(currentPermissions).map(p => splitPerm(p)); + return permissions.every(req => { + const reqParts = splitPerm(req); + return userPerms.some(userParts => { + if(userParts.length !== reqParts.length) return false; + return reqParts.every((part, i) => part === "*" || part === userParts[i]); + }); + }); +} \ No newline at end of file diff --git a/src/lib/core/handlers/ws_messageSender.ts b/src/lib/core/handlers/ws_messageSender.ts new file mode 100644 index 0000000..ddc60b1 --- /dev/null +++ b/src/lib/core/handlers/ws_messageSender.ts @@ -0,0 +1,26 @@ +import { get, writable } from 'svelte/store'; +import type { OutMessage } from '../types/outMessage'; +import { socketStore } from '../stores/websocketStore'; +import { addNotification } from '../stores/noti'; + +export const queue = writable([]); + +export function sendMessage(msg: OutMessage): boolean { + const socket = get(socketStore); + const data = JSON.stringify(msg); + + if (!socket || socket.readyState !== WebSocket.OPEN) { + console.warn('WebSocket not connected, put to queue'); + + let currentQueue = get(queue); + currentQueue.push(data); + queue.set(currentQueue); + + addNotification('WARN:Queuing overview view request'); + + return false; + } + + socket.send(data); + return true; +} diff --git a/src/lib/core/stores/auth.ts b/src/lib/core/stores/auth.ts new file mode 100644 index 0000000..3f1c0ec --- /dev/null +++ b/src/lib/core/stores/auth.ts @@ -0,0 +1,9 @@ +import type { User } from "firebase/auth"; +import { writable } from "svelte/store"; + +// type User = { +// uid: string, +// email: string, +// }; + +export const auth = writable(null); \ No newline at end of file diff --git a/src/lib/core/stores/departments.ts b/src/lib/core/stores/departments.ts new file mode 100644 index 0000000..ec4b9b1 --- /dev/null +++ b/src/lib/core/stores/departments.ts @@ -0,0 +1,3 @@ +import { writable } from 'svelte/store'; + +export const departmentStore = writable(); diff --git a/src/lib/core/stores/machineFiles.ts b/src/lib/core/stores/machineFiles.ts new file mode 100644 index 0000000..f1f926e --- /dev/null +++ b/src/lib/core/stores/machineFiles.ts @@ -0,0 +1 @@ +/// save files' content diff --git a/src/lib/core/stores/machineInfoStore.ts b/src/lib/core/stores/machineInfoStore.ts new file mode 100644 index 0000000..644dc90 --- /dev/null +++ b/src/lib/core/stores/machineInfoStore.ts @@ -0,0 +1,4 @@ +import type { MachineInfo } from '$lib/models/machineInfo.model'; +import { writable } from 'svelte/store'; + +export const machineInfoStore = writable(); diff --git a/src/lib/core/stores/noti.ts b/src/lib/core/stores/noti.ts new file mode 100644 index 0000000..acdd5a3 --- /dev/null +++ b/src/lib/core/stores/noti.ts @@ -0,0 +1,41 @@ +import { toast } from 'svelte-sonner'; +import { get, writable } from 'svelte/store'; + +// save notifications to user +export const notiStore = writable([]); + +export function addNotification(msg: string) { + let current = get(notiStore); + current.push(msg); + notiStore.set(current); +} + +export function getNotification() { + let current = get(notiStore); + let first = current.shift(); + if (first) { + let msg_p = first.split(':'); + let msg_level_type = msg_p[0]; + let msg = msg_p[1]; + + switch (msg_level_type) { + case 'ERR': + toast.error('Error', { + description: msg + }); + break; + case 'WARN': + toast.warning('Warning', { + description: msg + }); + default: + toast(msg); + } + } + + notiStore.set(current); +} + +setInterval(() => { + getNotification(); +}, 100); diff --git a/src/lib/core/stores/permissions.ts b/src/lib/core/stores/permissions.ts new file mode 100644 index 0000000..3dc083b --- /dev/null +++ b/src/lib/core/stores/permissions.ts @@ -0,0 +1,4 @@ +import { writable } from "svelte/store"; + +// blocking views by permission of user +export const permission = writable([]); \ No newline at end of file diff --git a/src/lib/core/stores/recipeStore.ts b/src/lib/core/stores/recipeStore.ts new file mode 100644 index 0000000..b5ce0f4 --- /dev/null +++ b/src/lib/core/stores/recipeStore.ts @@ -0,0 +1,67 @@ +import { writable } from 'svelte/store'; +import type { RecipeOverview } from '../../../routes/(authed)/recipe/overview/columns'; +import type { Material } from '$lib/models/material.model'; + +export const recipeData = writable(null); +export const recipeLoading = writable(false); +export const recipeDataError = writable(null); +export const recipeStreamMeta = writable<{ + id: string; + total_size: number; + chunk_size: number; + progress: number; +} | null>(null); + +// from server +export const recipeOverviewData = writable(null); +export const materialData = writable(); + +// machine recipe +export const recipeFromMachine = writable(null); +export const recipeFromMachineLoading = writable(false); +export const recipeFromMachineError = writable(null); + +// NOTE: must not have any nested structures +// { recipe: {}, materials: {}, toppings: { groups: {}, lists: {} } } +export const recipeFromMachineQuery = writable({}); +export const materialFromMachineQuery = writable({}); + +export const referenceFromPage = writable(''); + +let worker: Worker | null = null; +let initialized = false; + +export function loadRecipe(url: string) { + if (initialized) return; + initialized = true; + + recipeLoading.set(true); + + worker = new Worker(new URL('../../workers/data.worker.ts', import.meta.url), { + type: 'module' + }); + + worker.onmessage = (e) => { + const { type, payload } = e.data; + if (type === 'data') { + recipeData.set(payload); + recipeLoading.set(false); + } + + if (type === 'error') { + recipeDataError.set(payload); + recipeLoading.set(false); + } + }; + + worker.postMessage({ url }); +} + +export function getWorker() { + if (!worker) { + worker = new Worker(new URL('../../workers/data.worker.ts', import.meta.url), { + type: 'module' + }); + } + return worker; +} diff --git a/src/lib/core/stores/sidebar.ts b/src/lib/core/stores/sidebar.ts new file mode 100644 index 0000000..2ed091d --- /dev/null +++ b/src/lib/core/stores/sidebar.ts @@ -0,0 +1,3 @@ +import { writable } from 'svelte/store'; + +export const sidebarStore = writable(true); diff --git a/src/lib/core/stores/websocketStore.ts b/src/lib/core/stores/websocketStore.ts new file mode 100644 index 0000000..ac7c243 --- /dev/null +++ b/src/lib/core/stores/websocketStore.ts @@ -0,0 +1,46 @@ +import { browser } from '$app/environment'; +import { env } from '$env/dynamic/public'; +import { get, writable } from 'svelte/store'; +import { handleIncomingMessages } from '../handlers/messageHandler'; +import { queue as msgQueue } from '../handlers/ws_messageSender'; + +export const socketStore = writable(null, (set) => { + if (browser) { + console.log('connecting to ', env.PUBLIC_WSS); + const socket = new WebSocket(`${env.PUBLIC_WSS}`); + + socket.addEventListener('open', () => { + set(socket); + + // recover messages on connect, flushing + while (get(msgQueue).length) { + let queue = get(msgQueue); + let current = queue.shift(); + if (current) { + socket.send(current); + // set next + msgQueue.set(queue); + } + } + }); + + socket.addEventListener('message', (event) => { + handleIncomingMessages(event.data); + }); + + socket.addEventListener('close', () => { + set(null); + }); + + socket.addEventListener('error', (e) => { + console.log('WebSocket error: ', e); + set(null); + }); + + return () => { + if (socket.readyState === WebSocket.OPEN) { + socket.close(); + } + }; + } +}); diff --git a/src/lib/core/types/menuStatus.ts b/src/lib/core/types/menuStatus.ts new file mode 100644 index 0000000..3485325 --- /dev/null +++ b/src/lib/core/types/menuStatus.ts @@ -0,0 +1,24 @@ +enum MenuStatus { + ready, + obsolete = 2, + pendingOnline = 11, + pendingOffline, + drafted = 99 +} + +function matchMenuStatus(status: number): MenuStatus { + switch (status) { + case 0: + return MenuStatus.ready; + case 2: + return MenuStatus.obsolete; + case 11: + return MenuStatus.pendingOnline; + case 12: + return MenuStatus.pendingOffline; + default: + return MenuStatus.drafted; + } +} + +export { MenuStatus, matchMenuStatus }; diff --git a/src/lib/core/types/outMessage.ts b/src/lib/core/types/outMessage.ts new file mode 100644 index 0000000..d41e0c0 --- /dev/null +++ b/src/lib/core/types/outMessage.ts @@ -0,0 +1,25 @@ +export type OutMessage = + | { type: 'chat'; payload: string } + | { type: 'ping' } + | { type: 'lock'; payload: { field: string } } + | { type: 'general'; payload: string } + | { + type: 'recipe'; + payload: { + auth: string; + partial: boolean; + country: string; + version: number; + parameters: string; + }; + } + | { + type: 'auth'; + payload: { + user: { + name: string; + email: string; + permissions: string; + }; + }; + }; diff --git a/src/lib/data/mockup.ts b/src/lib/data/mockup.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/data/recipeDef.ts b/src/lib/data/recipeDef.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/helpers/asyncStorage.ts b/src/lib/helpers/asyncStorage.ts new file mode 100644 index 0000000..f886ca9 --- /dev/null +++ b/src/lib/helpers/asyncStorage.ts @@ -0,0 +1,14 @@ +export class AsyncStorage { + static async getItem(key: string) { + return new Promise((resolve) => { + resolve(localStorage.getItem(key) as T) + }); + } + + static async setItem(key: string, value: string){ + return new Promise((resolve) => { + localStorage.setItem(key, value); + resolve(); + }); + } +} \ No newline at end of file diff --git a/src/lib/helpers/cookie.ts b/src/lib/helpers/cookie.ts new file mode 100644 index 0000000..e62b306 --- /dev/null +++ b/src/lib/helpers/cookie.ts @@ -0,0 +1,41 @@ +function extractCookieOnNonBrowser() { + let result: any = {}; + let cookie_ent = document.cookie.split(';'); + for (let i = 0; i < cookie_ent.length; i++) { + let c = cookie_ent[i].trim(); + if (c.indexOf('=') > -1) { + let key = c.split('=')[0]; + result[key] = c.split('=')[1]; + } + } + return result; +} + +function setCookieOnNonBrowser(name: string, value: string) { + let current = extractCookieOnNonBrowser(); + let result = ''; + + for (let key of Object.keys(current)) { + if (key == name) continue; + result += `${key}=${current[key]}; `; + } + + result += `${name}=${value};`; + + document.cookie = result; + console.log('last set cookie', result); +} + +function deleteCookiesOnNonBrowser(name: string) { + let current = extractCookieOnNonBrowser(); + let result = ''; + if (current[name]) { + for (let key of Object.keys(current)) { + if (key == name) continue; + result += `${key}=${current[key]}; `; + } + } + document.cookie = result; +} + +export { extractCookieOnNonBrowser, setCookieOnNonBrowser, deleteCookiesOnNonBrowser }; diff --git a/src/lib/helpers/icingGen.ts b/src/lib/helpers/icingGen.ts new file mode 100644 index 0000000..bcb3613 --- /dev/null +++ b/src/lib/helpers/icingGen.ts @@ -0,0 +1,49 @@ +class IcingGen { + private lastTimestamp = 0n; + private sequence = 0n; + private machineId: bigint; + + constructor(machineId: number) { + this.machineId = BigInt(machineId) & 0b11111n; + } + + private timestamp() { + return BigInt(new Date().getTime()); + } + + nextId() { + let now = this.timestamp(); + if (now === this.lastTimestamp) { + this.sequence = (this.sequence + 1n) & 0b111111111111n; + if (this.sequence === 0n) now++; + } else { + this.sequence = 0n; + } + + this.lastTimestamp = now; + + const id = ((now - 1700000000000n) << 17n) | (this.machineId << 12n) | this.sequence; + return id.toString(); + } +} + +function toBase62(num: bigint): string { + const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + let str = ''; + while (num > 0n) { + const rem = num % 62n; + str = chars[Number(rem)] + str; + num = num / 62n; + } + return str; +} + +export function generateIcing(machineId: number): string { + const icing = new IcingGen(machineId); + const nid = icing.nextId(); + + console.log('NEXT ID', nid); + + const id = toBase62(BigInt(nid)); + return id; +} diff --git a/src/lib/helpers/interfaceAccess.ts b/src/lib/helpers/interfaceAccess.ts new file mode 100644 index 0000000..a7a3e4d --- /dev/null +++ b/src/lib/helpers/interfaceAccess.ts @@ -0,0 +1,3 @@ +export function getProperty(obj: Type, key: Key) { + return obj[key]; +} diff --git a/src/lib/helpers/lang.ts b/src/lib/helpers/lang.ts new file mode 100644 index 0000000..c23351d --- /dev/null +++ b/src/lib/helpers/lang.ts @@ -0,0 +1,20 @@ +import { AsyncStorage } from "./asyncStorage"; + +export default class Lang { + static async initLanguageSwitcher(){ + let currentLanguage = await Lang.getCurrentLanguage(); + if(currentLanguage == null || currentLanguage == undefined){ + await AsyncStorage.setItem('currentLanguage', 'th'); + } + } + + static getCurrentLanguage(){ + return AsyncStorage.getItem('currentLanguage'); + } + + static async switchLanguage(){ + let currentLanguage = await Lang.getCurrentLanguage(); + let resultLang = currentLanguage == 'th' ? 'en' : 'th'; + await AsyncStorage.setItem('currentLanguage', resultLang); + } +} \ No newline at end of file diff --git a/src/lib/helpers/updater.ts b/src/lib/helpers/updater.ts new file mode 100644 index 0000000..5fc23c0 --- /dev/null +++ b/src/lib/helpers/updater.ts @@ -0,0 +1 @@ +export function update \ No newline at end of file diff --git a/src/lib/hooks/is-mobile.svelte.ts b/src/lib/hooks/is-mobile.svelte.ts new file mode 100644 index 0000000..4829c00 --- /dev/null +++ b/src/lib/hooks/is-mobile.svelte.ts @@ -0,0 +1,9 @@ +import { MediaQuery } from "svelte/reactivity"; + +const DEFAULT_MOBILE_BREAKPOINT = 768; + +export class IsMobile extends MediaQuery { + constructor(breakpoint: number = DEFAULT_MOBILE_BREAKPOINT) { + super(`max-width: ${breakpoint - 1}px`); + } +} diff --git a/src/lib/index.ts b/src/lib/index.ts new file mode 100644 index 0000000..856f2b6 --- /dev/null +++ b/src/lib/index.ts @@ -0,0 +1 @@ +// place files you want to import through the `$lib` alias in this folder. diff --git a/src/lib/models/machineInfo.model.ts b/src/lib/models/machineInfo.model.ts new file mode 100644 index 0000000..c08e69c --- /dev/null +++ b/src/lib/models/machineInfo.model.ts @@ -0,0 +1,23 @@ +/// Information about machine +export interface MachineInfo { + boxId: string | undefined; + versions: AppVersions; + devMode: boolean; + country: string; + status: string; + errors: MachineError[]; +} + +export interface AppVersions { + firmware: string; + brew: string; + xmlengine: string; + netcore: string; + devbox: string; +} + +export interface MachineError { + type: 'connection' | 'ui' | 'app' | string; + level: 'normal' | 'warning' | 'error'; + message: string; +} diff --git a/src/lib/models/material.model.ts b/src/lib/models/material.model.ts new file mode 100644 index 0000000..f0ca20f --- /dev/null +++ b/src/lib/models/material.model.ts @@ -0,0 +1,35 @@ +/// Material Values +export interface Material { + AlarmIDWhenOffline: number; + BeanChannel: boolean; + CanisterType: string; + DrainTimer: number; + IceScreamBingsuChannel: boolean; + IsEquipment: boolean; + LeavesChannel: boolean; + LowToOffline: number; + MaterialDescription: string; + MaterialStatus: number; + PowderChannel: boolean; + RefillUnitGram: boolean; + RefillUnitMilliliters: boolean; + RefillUnitPCS: boolean; + ScheduleDrainType: number; + SodaChannel: boolean; + StrTextShowError: string[]; + SyrupChannel: boolean; + id: number; + idAlternate: number; + isUse: true; + materialOtherName: string; + materialName: string; + pathOtherName: string; + pay_rettry_max_count: number; + RawMaterialUnit: string; + MaterialParameter: string; + FreshSyrupChannel: boolean; + MaterialDescrption: string; + FrozenFruitChannel: boolean; + // extra field + [key: string]: any; +} diff --git a/src/lib/models/user.model.ts b/src/lib/models/user.model.ts new file mode 100644 index 0000000..1ec562e --- /dev/null +++ b/src/lib/models/user.model.ts @@ -0,0 +1,8 @@ +import type { UserPermissions } from "$lib/core/auth/userPermissions"; + +export interface User { + email: string; + name: string; + picture: string; + permissions: UserPermissions[]; +} \ No newline at end of file diff --git a/src/lib/utils.ts b/src/lib/utils.ts new file mode 100644 index 0000000..280bda2 --- /dev/null +++ b/src/lib/utils.ts @@ -0,0 +1,15 @@ +import { type ClassValue, clsx } from 'clsx'; +import { twMerge } from 'tailwind-merge'; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type WithoutChild = T extends { child?: any } ? Omit : T; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type WithoutChildren = T extends { children?: any } ? Omit : T; +export type WithoutChildrenOrChild = WithoutChildren>; +export type WithElementRef = T & { + ref?: U | null; +}; diff --git a/src/lib/workers/data.worker.ts b/src/lib/workers/data.worker.ts new file mode 100644 index 0000000..d425e40 --- /dev/null +++ b/src/lib/workers/data.worker.ts @@ -0,0 +1,21 @@ +let cached: any | null = null; + +self.onmessage = async (e) => { + const { url } = e.data; + + if (cached) { + postMessage({ type: 'data', payload: cached }); + return; + } + + try { + const res = await fetch(url); + const data = await res.json(); + + cached = data; + + postMessage({ type: 'data', payload: data }); + } catch (err) { + postMessage({ type: 'error', payload: String(err) }); + } +}; diff --git a/src/routes/(authed)/+error.svelte b/src/routes/(authed)/+error.svelte new file mode 100644 index 0000000..78e40a8 --- /dev/null +++ b/src/routes/(authed)/+error.svelte @@ -0,0 +1,5 @@ + + +

    {page.status} {page.error?.message}

    \ No newline at end of file diff --git a/src/routes/(authed)/+layout.server.ts b/src/routes/(authed)/+layout.server.ts new file mode 100644 index 0000000..0e198e2 --- /dev/null +++ b/src/routes/(authed)/+layout.server.ts @@ -0,0 +1,14 @@ +import { auth } from '$lib/core/stores/auth.js'; +import { departmentStore } from '$lib/core/stores/departments.ts'; +import { redirect } from '@sveltejs/kit'; +import { get } from 'svelte/store'; + +export async function load({ cookies, url }) { + if (!cookies.get('logged_in')) { + redirect(303, `/login?redirectTo=${url.pathname}`); + } + + if (url.pathname.includes('recipe') && !cookies.get('department')) { + redirect(303, `/departments`); + } +} diff --git a/src/routes/(authed)/+layout.svelte b/src/routes/(authed)/+layout.svelte new file mode 100644 index 0000000..1c696d1 --- /dev/null +++ b/src/routes/(authed)/+layout.svelte @@ -0,0 +1,30 @@ + + + + + + + Taobin Management Tools + + + { + sidebarStore.set(open); + }} +> + +
    + + {@render children()} +
    +
    diff --git a/src/routes/(authed)/dashboard/+page.svelte b/src/routes/(authed)/dashboard/+page.svelte new file mode 100644 index 0000000..01a3b11 --- /dev/null +++ b/src/routes/(authed)/dashboard/+page.svelte @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/src/routes/(authed)/departments/+layout.svelte b/src/routes/(authed)/departments/+layout.svelte new file mode 100644 index 0000000..95eb23f --- /dev/null +++ b/src/routes/(authed)/departments/+layout.svelte @@ -0,0 +1,14 @@ + + + + + + Taobin Management Tools + + + +{@render children()} \ No newline at end of file diff --git a/src/routes/(authed)/departments/+page.svelte b/src/routes/(authed)/departments/+page.svelte new file mode 100644 index 0000000..dc1bd30 --- /dev/null +++ b/src/routes/(authed)/departments/+page.svelte @@ -0,0 +1,67 @@ + + +

    Country Selection

    +

    Select country to view/edit recipe

    + +{#if enabledAccessibleCountries.length == 0} +
    + +
    +{:else} +
    + {#each enabledAccessibleCountries as country} +
    + +
    + {/each} +
    +{/if} diff --git a/src/routes/(authed)/entry/+layout.svelte b/src/routes/(authed)/entry/+layout.svelte new file mode 100644 index 0000000..95eb23f --- /dev/null +++ b/src/routes/(authed)/entry/+layout.svelte @@ -0,0 +1,14 @@ + + + + + + Taobin Management Tools + + + +{@render children()} \ No newline at end of file diff --git a/src/routes/(authed)/entry/+page.svelte b/src/routes/(authed)/entry/+page.svelte new file mode 100644 index 0000000..cbc03f5 --- /dev/null +++ b/src/routes/(authed)/entry/+page.svelte @@ -0,0 +1,138 @@ + + + +
    +
    +

    Module Selection

    + + +
    + + {#if perms.filter((x) => x.startsWith("document.read") || x.startsWith("document.write")).length > 0} + + {/if} + + + {#if perms.filter((x) => x.startsWith("tools")).length > 0} + + {/if} +
    + + {#if perms.filter((x) => x.startsWith("document.read") || x.startsWith("document.write") || x.startsWith("tools")).length == 0} + +

    No modules are available. + Please check your account with admin.

    + + {/if} + +
    + + +
    + + + +
    +
    \ No newline at end of file diff --git a/src/routes/(authed)/recipe/material/+page.svelte b/src/routes/(authed)/recipe/material/+page.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/(authed)/recipe/overview/+page.server.ts b/src/routes/(authed)/recipe/overview/+page.server.ts new file mode 100644 index 0000000..229e7f6 --- /dev/null +++ b/src/routes/(authed)/recipe/overview/+page.server.ts @@ -0,0 +1,14 @@ +import { getRecipes } from '$lib/core/client/server'; +import { recipeData } from '$lib/core/stores/recipeStore'; +import { get } from 'svelte/store'; + +export async function load({ cookies, params }) { + let dep = cookies.get('department'); + console.log('load recipe ', dep); + let recipes = await getRecipes(); + recipes = get(recipeData); + + return { + recipes + }; +} diff --git a/src/routes/(authed)/recipe/overview/+page.svelte b/src/routes/(authed)/recipe/overview/+page.svelte new file mode 100644 index 0000000..354156c --- /dev/null +++ b/src/routes/(authed)/recipe/overview/+page.svelte @@ -0,0 +1,63 @@ + + +
    + +
    +
    +
    +

    Overview

    +

    + Display menus from the current selected country +

    +
    +
    + +
    +
    + + + + + + +
    + +
    +
    +
    diff --git a/src/routes/(authed)/recipe/overview/columns.ts b/src/routes/(authed)/recipe/overview/columns.ts new file mode 100644 index 0000000..bfe041d --- /dev/null +++ b/src/routes/(authed)/recipe/overview/columns.ts @@ -0,0 +1,92 @@ +import { renderComponent } from '$lib/components/ui/data-table'; +import type { ColumnDef } from '@tanstack/table-core'; +import DataTableTagsBadge from './data-table-tags-badge.svelte'; +import DataTableHeader from './data-table-header.svelte'; + +import type { FilterFn } from '@tanstack/table-core'; +import { rankItem } from '@tanstack/match-sorter-utils'; +import DataTableActions from './data-table-actions.svelte'; +import { get } from 'svelte/store'; +import { referenceFromPage } from '$lib/core/stores/recipeStore'; + +const fuzzyFilter: FilterFn = (row, columnId, value, addMeta) => { + const itemRank = rankItem(row.getValue(columnId), value); + addMeta({ itemRank }); + return itemRank.passed; +}; + +export type RecipeOverview = { + productCode: string; + name: string; + description: string; + tags: string; + status: 'ready' | 'obsolete' | 'drafted' | 'pending/online' | 'pending/offline'; +}; + +export const columns: ColumnDef[] = [ + { + accessorKey: 'productCode', + header: ({ column }) => + renderComponent(DataTableHeader, { + onclick: column.getToggleSortingHandler(), + data: 'Product Code' + }), + enableGlobalFilter: true, + filterFn: 'includesString' + }, + { + accessorKey: 'name', + header: ({ column }) => + renderComponent(DataTableHeader, { + onclick: column.getToggleSortingHandler(), + data: 'Name' + }), + enableGlobalFilter: true, + filterFn: 'includesString' + }, + { + accessorKey: 'description', + header: ({ column }) => + renderComponent(DataTableHeader, { + onclick: column.getToggleSortingHandler(), + data: 'Description' + }), + enableGlobalFilter: true, + filterFn: 'includesString' + }, + { + accessorKey: 'tags', + header: ({ column }) => + renderComponent(DataTableHeader, { + onclick: column.getToggleSortingHandler(), + data: 'Tags' + }), + cell: ({ row }) => { + return renderComponent(DataTableTagsBadge, { tags: row.original.tags }); + }, + enableGlobalFilter: true, + filterFn: 'includesString' + }, + { + accessorKey: 'status', + header: ({ column }) => + renderComponent(DataTableHeader, { + onclick: column.getToggleSortingHandler(), + data: 'Status' + }), + cell: ({ row }) => { + return renderComponent(DataTableTagsBadge, { tags: row.original.status }); + }, + enableGlobalFilter: true, + filterFn: 'includesString' + }, + { + id: 'actions', + cell: ({ row }) => { + return renderComponent(DataTableActions, { + refPage: get(referenceFromPage), + ...row.original + }); + } + } +]; diff --git a/src/routes/(authed)/recipe/overview/data-table-actions.svelte b/src/routes/(authed)/recipe/overview/data-table-actions.svelte new file mode 100644 index 0000000..edf38b5 --- /dev/null +++ b/src/routes/(authed)/recipe/overview/data-table-actions.svelte @@ -0,0 +1,57 @@ + + + + + {#snippet child({ props })} + + {/snippet} + + + + {#if refPage !== ''} + e.preventDefault()}> + + + {:else} + +

    Cannot Edit

    +
    + {/if} + + + + Actions + navigator.clipboard.writeText(dataForCopy)} + >Copy For Sheets + + navigator.clipboard.writeText(dataForCopy)} + >Export + +
    +
    diff --git a/src/routes/(authed)/recipe/overview/data-table-checkbox.svelte b/src/routes/(authed)/recipe/overview/data-table-checkbox.svelte new file mode 100644 index 0000000..4de6a8c --- /dev/null +++ b/src/routes/(authed)/recipe/overview/data-table-checkbox.svelte @@ -0,0 +1 @@ +// may not use diff --git a/src/routes/(authed)/recipe/overview/data-table-header.svelte b/src/routes/(authed)/recipe/overview/data-table-header.svelte new file mode 100644 index 0000000..fe7c0fc --- /dev/null +++ b/src/routes/(authed)/recipe/overview/data-table-header.svelte @@ -0,0 +1,16 @@ + + + diff --git a/src/routes/(authed)/recipe/overview/data-table-productcode.svelte b/src/routes/(authed)/recipe/overview/data-table-productcode.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/(authed)/recipe/overview/data-table-tags-badge.svelte b/src/routes/(authed)/recipe/overview/data-table-tags-badge.svelte new file mode 100644 index 0000000..de38f91 --- /dev/null +++ b/src/routes/(authed)/recipe/overview/data-table-tags-badge.svelte @@ -0,0 +1,75 @@ + + +
    + {#each tagList as tag} + + {#if tag === 'ready'} + + {/if} + {tag} + + {/each} + + + {#if extendTags.length > 0} + + + + + {extendTags.length}+ + + + + {extendTags.join(', ')} + + + + {/if} +
    diff --git a/src/routes/(authed)/recipe/overview/data-table.svelte b/src/routes/(authed)/recipe/overview/data-table.svelte new file mode 100644 index 0000000..2bf76a4 --- /dev/null +++ b/src/routes/(authed)/recipe/overview/data-table.svelte @@ -0,0 +1,159 @@ + + +
    +
    + + { + table.setGlobalFilter(e.currentTarget.value); + }} + oninput={(e) => { + table.setGlobalFilter(e.currentTarget.value); + }} + /> +
    + +
    + + + {#each table.getHeaderGroups() as headerGroup (headerGroup.id)} + + {#each headerGroup.headers as header (header.id)} + + {#if !header.isPlaceholder} + + {/if} + + {/each} + + {/each} + + + {#each table.getRowModel().rows as row (row.id)} + + {#each row.getVisibleCells() as cell (cell.id)} + + + + {/each} + + {:else} + + No results. + + {/each} + + +
    + + + +
    +
    +
    diff --git a/src/routes/(authed)/recipe/topping/+page.svelte b/src/routes/(authed)/recipe/topping/+page.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/(authed)/tools/brew/+page.svelte b/src/routes/(authed)/tools/brew/+page.svelte new file mode 100644 index 0000000..e083d11 --- /dev/null +++ b/src/routes/(authed)/tools/brew/+page.svelte @@ -0,0 +1,352 @@ + + +
    +
    +
    +
    +

    Brew

    +

    Brewing directly from web to machine

    +

    + Note: refreshing page may cut connection with machine +

    +
    +
    + {#if !adb.getAdbInstance()} + + {:else} + + {/if} +
    + + +
    + + + +
    + {#if $recipeFromMachineLoading} +
    +

    Please wait

    + +
    + {:else} + + {/if} +
    +
    +
    diff --git a/src/routes/(authed)/tools/debug/+page.svelte b/src/routes/(authed)/tools/debug/+page.svelte new file mode 100644 index 0000000..1424801 --- /dev/null +++ b/src/routes/(authed)/tools/debug/+page.svelte @@ -0,0 +1,17 @@ + + +
    +
    +
    +
    +

    Debug Toolkits

    +

    Tools for hotfix machine or viewing infos

    +
    +
    + +
    +
    +
    +
    diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte new file mode 100644 index 0000000..78e40a8 --- /dev/null +++ b/src/routes/+error.svelte @@ -0,0 +1,5 @@ + + +

    {page.status} {page.error?.message}

    \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte new file mode 100644 index 0000000..9fef3e7 --- /dev/null +++ b/src/routes/+layout.svelte @@ -0,0 +1,81 @@ + + + + + + + + Taobin Management Tools + + + + +{@render children()} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte new file mode 100644 index 0000000..12c1d86 --- /dev/null +++ b/src/routes/+page.svelte @@ -0,0 +1,93 @@ + + + diff --git a/src/routes/layout.css b/src/routes/layout.css new file mode 100644 index 0000000..cca3692 --- /dev/null +++ b/src/routes/layout.css @@ -0,0 +1,68 @@ +:root { + --radius: 0.625rem; + --background: oklch(1 0 0); + --foreground: oklch(0.147 0.004 49.25); + --card: oklch(1 0 0); + --card-foreground: oklch(0.147 0.004 49.25); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.147 0.004 49.25); + --primary: oklch(0.216 0.006 56.043); + --primary-foreground: oklch(0.985 0.001 106.423); + --secondary: oklch(0.97 0.001 106.424); + --secondary-foreground: oklch(0.216 0.006 56.043); + --muted: oklch(0.97 0.001 106.424); + --muted-foreground: oklch(0.553 0.013 58.071); + --accent: oklch(0.97 0.001 106.424); + --accent-foreground: oklch(0.216 0.006 56.043); + --destructive: oklch(0.577 0.245 27.325); + --border: oklch(0.923 0.003 48.717); + --input: oklch(0.923 0.003 48.717); + --ring: oklch(0.709 0.01 56.259); + --chart-1: oklch(0.646 0.222 41.116); + --chart-2: oklch(0.6 0.118 184.704); + --chart-3: oklch(0.398 0.07 227.392); + --chart-4: oklch(0.828 0.189 84.429); + --chart-5: oklch(0.769 0.188 70.08); + --sidebar: oklch(0.985 0.001 106.423); + --sidebar-foreground: oklch(0.147 0.004 49.25); + --sidebar-primary: oklch(0.216 0.006 56.043); + --sidebar-primary-foreground: oklch(0.985 0.001 106.423); + --sidebar-accent: oklch(0.97 0.001 106.424); + --sidebar-accent-foreground: oklch(0.216 0.006 56.043); + --sidebar-border: oklch(0.923 0.003 48.717); + --sidebar-ring: oklch(0.709 0.01 56.259); +} + +.dark { + --background: oklch(0.147 0.004 49.25); + --foreground: oklch(0.985 0.001 106.423); + --card: oklch(0.216 0.006 56.043); + --card-foreground: oklch(0.985 0.001 106.423); + --popover: oklch(0.216 0.006 56.043); + --popover-foreground: oklch(0.985 0.001 106.423); + --primary: oklch(0.923 0.003 48.717); + --primary-foreground: oklch(0.216 0.006 56.043); + --secondary: oklch(0.268 0.007 34.298); + --secondary-foreground: oklch(0.985 0.001 106.423); + --muted: oklch(0.268 0.007 34.298); + --muted-foreground: oklch(0.709 0.01 56.259); + --accent: oklch(0.268 0.007 34.298); + --accent-foreground: oklch(0.985 0.001 106.423); + --destructive: oklch(0.704 0.191 22.216); + --border: oklch(1 0 0 / 10%); + --input: oklch(1 0 0 / 15%); + --ring: oklch(0.553 0.013 58.071); + --chart-1: oklch(0.488 0.243 264.376); + --chart-2: oklch(0.696 0.17 162.48); + --chart-3: oklch(0.769 0.188 70.08); + --chart-4: oklch(0.627 0.265 303.9); + --chart-5: oklch(0.645 0.246 16.439); + --sidebar: oklch(0.216 0.006 56.043); + --sidebar-foreground: oklch(0.985 0.001 106.423); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0.001 106.423); + --sidebar-accent: oklch(0.268 0.007 34.298); + --sidebar-accent-foreground: oklch(0.985 0.001 106.423); + --sidebar-border: oklch(1 0 0 / 10%); + --sidebar-ring: oklch(0.553 0.013 58.071); +} diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte new file mode 100644 index 0000000..7024a53 --- /dev/null +++ b/src/routes/login/+page.svelte @@ -0,0 +1,115 @@ + + +
    + {#if loading} +
    + +
    + {:else} +
    +
    + Tao Bin | Forth Vanding Machine +

    + Sign in with your @Forth account +

    +
    + + +
    +
    +
    + {/if} +
    diff --git a/src/routes/page.svelte.spec.ts b/src/routes/page.svelte.spec.ts new file mode 100644 index 0000000..3c6adf3 --- /dev/null +++ b/src/routes/page.svelte.spec.ts @@ -0,0 +1,13 @@ +import { page } from '@vitest/browser/context'; +import { describe, expect, it } from 'vitest'; +import { render } from 'vitest-browser-svelte'; +import Page from './+page.svelte'; + +describe('/+page.svelte', () => { + it('should render h1', async () => { + render(Page); + + const heading = page.getByRole('heading', { level: 1 }); + await expect.element(heading).toBeInTheDocument(); + }); +}); diff --git a/src/routes/state.svelte.ts b/src/routes/state.svelte.ts new file mode 100644 index 0000000..59917d2 --- /dev/null +++ b/src/routes/state.svelte.ts @@ -0,0 +1,8 @@ + +import { Adb } from '@yume-chan/adb'; + +export interface AdbInstanceInterface { + instance?: Adb; +} + +export const AdbInstance: AdbInstanceInterface = $state({ instance: undefined }); diff --git a/src/routes/test_dev/scrap.txt b/src/routes/test_dev/scrap.txt new file mode 100644 index 0000000..b280c0a --- /dev/null +++ b/src/routes/test_dev/scrap.txt @@ -0,0 +1,78 @@ + +
    +
    + + + +
    + +

    Status:

    + {#if adb.getAdbInstance() != null} +

    Connected

    + {:else} +

    Disconnected

    + {/if} +
    +
    + + + +
    + + + + + + + + + + + + + + + + + +
    + + + + + + +
    + + + + + + +
    + + diff --git a/src/stories/Button.stories.svelte b/src/stories/Button.stories.svelte new file mode 100644 index 0000000..7187089 --- /dev/null +++ b/src/stories/Button.stories.svelte @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/src/stories/Button.svelte b/src/stories/Button.svelte new file mode 100644 index 0000000..c34befe --- /dev/null +++ b/src/stories/Button.svelte @@ -0,0 +1,30 @@ + + + diff --git a/src/stories/Configure.mdx b/src/stories/Configure.mdx new file mode 100644 index 0000000..4bbb649 --- /dev/null +++ b/src/stories/Configure.mdx @@ -0,0 +1,364 @@ +import { Meta } from "@storybook/addon-docs/blocks"; + +import Github from "./assets/github.svg"; +import Discord from "./assets/discord.svg"; +import Youtube from "./assets/youtube.svg"; +import Tutorials from "./assets/tutorials.svg"; +import Styling from "./assets/styling.png"; +import Context from "./assets/context.png"; +import Assets from "./assets/assets.png"; +import Docs from "./assets/docs.png"; +import Share from "./assets/share.png"; +import FigmaPlugin from "./assets/figma-plugin.png"; +import Testing from "./assets/testing.png"; +import Accessibility from "./assets/accessibility.png"; +import Theming from "./assets/theming.png"; +import AddonLibrary from "./assets/addon-library.png"; + +export const RightArrow = () => + + + + + +
    +
    + # Configure your project + + Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community. +
    +
    +
    + A wall of logos representing different styling technologies +

    Add styling and CSS

    +

    Like with web applications, there are many ways to include CSS within Storybook. Learn more about setting up styling within Storybook.

    + Learn more +
    +
    + An abstraction representing the composition of data for a component +

    Provide context and mocking

    +

    Often when a story doesn't render, it's because your component is expecting a specific environment or context (like a theme provider) to be available.

    + Learn more +
    +
    + A representation of typography and image assets +
    +

    Load assets and resources

    +

    To link static files (like fonts) to your projects and stories, use the + `staticDirs` configuration option to specify folders to load when + starting Storybook.

    + Learn more +
    +
    +
    +
    +
    +
    + # Do more with Storybook + + Now that you know the basics, let's explore other parts of Storybook that will improve your experience. This list is just to get you started. You can customise Storybook in many ways to fit your needs. +
    + +
    +
    +
    + A screenshot showing the autodocs tag being set, pointing a docs page being generated +

    Autodocs

    +

    Auto-generate living, + interactive reference documentation from your components and stories.

    + Learn more +
    +
    + A browser window showing a Storybook being published to a chromatic.com URL +

    Publish to Chromatic

    +

    Publish your Storybook to review and collaborate with your entire team.

    + Learn more +
    +
    + Windows showing the Storybook plugin in Figma +

    Figma Plugin

    +

    Embed your stories into Figma to cross-reference the design and live + implementation in one place.

    + Learn more +
    +
    + Screenshot of tests passing and failing +

    Testing

    +

    Use stories to test a component in all its variations, no matter how + complex.

    + Learn more +
    +
    + Screenshot of accessibility tests passing and failing +

    Accessibility

    +

    Automatically test your components for a11y issues as you develop.

    + Learn more +
    +
    + Screenshot of Storybook in light and dark mode +

    Theming

    +

    Theme Storybook's UI to personalize it to your project.

    + Learn more +
    +
    +
    +
    +
    +
    +

    Addons

    +

    Integrate your tools with Storybook to connect workflows.

    + Discover all addons +
    +
    + Integrate your tools with Storybook to connect workflows. +
    +
    + +
    +
    + Github logo + Join our contributors building the future of UI development. + + Star on GitHub +
    +
    + Discord logo +
    + Get support and chat with frontend developers. + + Join Discord server +
    +
    +
    + Youtube logo +
    + Watch tutorials, feature previews and interviews. + + Watch on YouTube +
    +
    +
    + A book +

    Follow guided walkthroughs on for key workflows.

    + + Discover tutorials +
    +
    + + diff --git a/src/stories/Header.stories.svelte b/src/stories/Header.stories.svelte new file mode 100644 index 0000000..23175a8 --- /dev/null +++ b/src/stories/Header.stories.svelte @@ -0,0 +1,26 @@ + + + + + diff --git a/src/stories/Header.svelte b/src/stories/Header.svelte new file mode 100644 index 0000000..d6b7b21 --- /dev/null +++ b/src/stories/Header.svelte @@ -0,0 +1,45 @@ + + +
    +
    +
    + + + + + + + +

    Acme

    +
    +
    + {#if user} + + Welcome, {user.name}! + +
    +
    +
    diff --git a/src/stories/Page.stories.svelte b/src/stories/Page.stories.svelte new file mode 100644 index 0000000..8f2ff22 --- /dev/null +++ b/src/stories/Page.stories.svelte @@ -0,0 +1,30 @@ + + + { + const canvas = within(canvasElement); + const loginButton = canvas.getByRole('button', { name: /Log in/i }); + await expect(loginButton).toBeInTheDocument(); + await userEvent.click(loginButton); + await waitFor(() => expect(loginButton).not.toBeInTheDocument()); + + const logoutButton = canvas.getByRole('button', { name: /Log out/i }); + await expect(logoutButton).toBeInTheDocument(); + }} +/> + + diff --git a/src/stories/Page.svelte b/src/stories/Page.svelte new file mode 100644 index 0000000..c4c069a --- /dev/null +++ b/src/stories/Page.svelte @@ -0,0 +1,70 @@ + + +
    +
    (user = { name: 'Jane Doe' })} + onLogout={() => (user = undefined)} + onCreateAccount={() => (user = { name: 'Jane Doe' })} + /> + +
    +

    Pages in Storybook

    +

    + We recommend building UIs with a + + component-driven + + process starting with atomic components and ending with pages. +

    +

    + Render pages with mock data. This makes it easy to build and review page states without + needing to navigate to them in your app. Here are some handy patterns for managing page data + in Storybook: +

    +
      +
    • + Use a higher-level connected component. Storybook helps you compose such data from the + "args" of child component stories +
    • +
    • + Assemble data in the page component from your services. You can mock these services out + using Storybook. +
    • +
    +

    + Get a guided tutorial on component-driven development at + + Storybook tutorials + + . Read more in the + docs + . +

    +
    + Tip + Adjust the width of the canvas with the + + + + + + Viewports addon in the toolbar +
    +
    +
    diff --git a/src/stories/assets/accessibility.png b/src/stories/assets/accessibility.png new file mode 100644 index 0000000..6ffe6fe Binary files /dev/null and b/src/stories/assets/accessibility.png differ diff --git a/src/stories/assets/accessibility.svg b/src/stories/assets/accessibility.svg new file mode 100644 index 0000000..107e93f --- /dev/null +++ b/src/stories/assets/accessibility.svg @@ -0,0 +1 @@ +Accessibility \ No newline at end of file diff --git a/src/stories/assets/addon-library.png b/src/stories/assets/addon-library.png new file mode 100644 index 0000000..95deb38 Binary files /dev/null and b/src/stories/assets/addon-library.png differ diff --git a/src/stories/assets/assets.png b/src/stories/assets/assets.png new file mode 100644 index 0000000..cfba681 Binary files /dev/null and b/src/stories/assets/assets.png differ diff --git a/src/stories/assets/avif-test-image.avif b/src/stories/assets/avif-test-image.avif new file mode 100644 index 0000000..530709b Binary files /dev/null and b/src/stories/assets/avif-test-image.avif differ diff --git a/src/stories/assets/context.png b/src/stories/assets/context.png new file mode 100644 index 0000000..e5cd249 Binary files /dev/null and b/src/stories/assets/context.png differ diff --git a/src/stories/assets/discord.svg b/src/stories/assets/discord.svg new file mode 100644 index 0000000..d638958 --- /dev/null +++ b/src/stories/assets/discord.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/stories/assets/docs.png b/src/stories/assets/docs.png new file mode 100644 index 0000000..a749629 Binary files /dev/null and b/src/stories/assets/docs.png differ diff --git a/src/stories/assets/figma-plugin.png b/src/stories/assets/figma-plugin.png new file mode 100644 index 0000000..8f79b08 Binary files /dev/null and b/src/stories/assets/figma-plugin.png differ diff --git a/src/stories/assets/github.svg b/src/stories/assets/github.svg new file mode 100644 index 0000000..dc51352 --- /dev/null +++ b/src/stories/assets/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/stories/assets/share.png b/src/stories/assets/share.png new file mode 100644 index 0000000..8097a37 Binary files /dev/null and b/src/stories/assets/share.png differ diff --git a/src/stories/assets/styling.png b/src/stories/assets/styling.png new file mode 100644 index 0000000..d341e82 Binary files /dev/null and b/src/stories/assets/styling.png differ diff --git a/src/stories/assets/testing.png b/src/stories/assets/testing.png new file mode 100644 index 0000000..d4ac39a Binary files /dev/null and b/src/stories/assets/testing.png differ diff --git a/src/stories/assets/theming.png b/src/stories/assets/theming.png new file mode 100644 index 0000000..1535eb9 Binary files /dev/null and b/src/stories/assets/theming.png differ diff --git a/src/stories/assets/tutorials.svg b/src/stories/assets/tutorials.svg new file mode 100644 index 0000000..b492a9c --- /dev/null +++ b/src/stories/assets/tutorials.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/stories/assets/youtube.svg b/src/stories/assets/youtube.svg new file mode 100644 index 0000000..a7515d7 --- /dev/null +++ b/src/stories/assets/youtube.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/stories/button.css b/src/stories/button.css new file mode 100644 index 0000000..4e3620b --- /dev/null +++ b/src/stories/button.css @@ -0,0 +1,30 @@ +.storybook-button { + display: inline-block; + cursor: pointer; + border: 0; + border-radius: 3em; + font-weight: 700; + line-height: 1; + font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; +} +.storybook-button--primary { + background-color: #555ab9; + color: white; +} +.storybook-button--secondary { + box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset; + background-color: transparent; + color: #333; +} +.storybook-button--small { + padding: 10px 16px; + font-size: 12px; +} +.storybook-button--medium { + padding: 11px 20px; + font-size: 14px; +} +.storybook-button--large { + padding: 12px 24px; + font-size: 16px; +} diff --git a/src/stories/header.css b/src/stories/header.css new file mode 100644 index 0000000..5efd46c --- /dev/null +++ b/src/stories/header.css @@ -0,0 +1,32 @@ +.storybook-header { + display: flex; + justify-content: space-between; + align-items: center; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); + padding: 15px 20px; + font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; +} + +.storybook-header svg { + display: inline-block; + vertical-align: top; +} + +.storybook-header h1 { + display: inline-block; + vertical-align: top; + margin: 6px 0 6px 10px; + font-weight: 700; + font-size: 20px; + line-height: 1; +} + +.storybook-header button + button { + margin-left: 10px; +} + +.storybook-header .welcome { + margin-right: 10px; + color: #333; + font-size: 14px; +} diff --git a/src/stories/page.css b/src/stories/page.css new file mode 100644 index 0000000..77c81d2 --- /dev/null +++ b/src/stories/page.css @@ -0,0 +1,68 @@ +.storybook-page { + margin: 0 auto; + padding: 48px 20px; + max-width: 600px; + color: #333; + font-size: 14px; + line-height: 24px; + font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; +} + +.storybook-page h2 { + display: inline-block; + vertical-align: top; + margin: 0 0 4px; + font-weight: 700; + font-size: 32px; + line-height: 1; +} + +.storybook-page p { + margin: 1em 0; +} + +.storybook-page a { + color: inherit; +} + +.storybook-page ul { + margin: 1em 0; + padding-left: 30px; +} + +.storybook-page li { + margin-bottom: 8px; +} + +.storybook-page .tip { + display: inline-block; + vertical-align: top; + margin-right: 10px; + border-radius: 1em; + background: #e7fdd8; + padding: 4px 12px; + color: #357a14; + font-weight: 700; + font-size: 11px; + line-height: 12px; +} + +.storybook-page .tip-wrapper { + margin-top: 40px; + margin-bottom: 40px; + font-size: 13px; + line-height: 20px; +} + +.storybook-page .tip-wrapper svg { + display: inline-block; + vertical-align: top; + margin-top: 3px; + margin-right: 4px; + width: 12px; + height: 12px; +} + +.storybook-page .tip-wrapper svg path { + fill: #1ea7fd; +} diff --git a/static/bn_hot_america_no.png b/static/bn_hot_america_no.png new file mode 100644 index 0000000..36705c6 Binary files /dev/null and b/static/bn_hot_america_no.png differ diff --git a/static/departments/alpha-3.png b/static/departments/alpha-3.png new file mode 100644 index 0000000..b493c1c Binary files /dev/null and b/static/departments/alpha-3.png differ diff --git a/static/departments/aus_plate.png b/static/departments/aus_plate.png new file mode 100644 index 0000000..7d906ca Binary files /dev/null and b/static/departments/aus_plate.png differ diff --git a/static/departments/cocktail_tha.png b/static/departments/cocktail_tha.png new file mode 100644 index 0000000..35d8825 Binary files /dev/null and b/static/departments/cocktail_tha.png differ diff --git a/static/departments/counter01_plate.png b/static/departments/counter01_plate.png new file mode 100644 index 0000000..abcfcaf Binary files /dev/null and b/static/departments/counter01_plate.png differ diff --git a/static/departments/logo/alpha-3.png b/static/departments/logo/alpha-3.png new file mode 100644 index 0000000..1f7c6fe Binary files /dev/null and b/static/departments/logo/alpha-3.png differ diff --git a/static/departments/logo/aus_plate.png b/static/departments/logo/aus_plate.png new file mode 100644 index 0000000..507217f Binary files /dev/null and b/static/departments/logo/aus_plate.png differ diff --git a/static/departments/logo/cocktail_tha.png b/static/departments/logo/cocktail_tha.png new file mode 100644 index 0000000..35d8825 Binary files /dev/null and b/static/departments/logo/cocktail_tha.png differ diff --git a/static/departments/logo/counter01_plate.png b/static/departments/logo/counter01_plate.png new file mode 100644 index 0000000..abcfcaf Binary files /dev/null and b/static/departments/logo/counter01_plate.png differ diff --git a/static/departments/logo/mys_plate.png b/static/departments/logo/mys_plate.png new file mode 100644 index 0000000..7b7a8cc Binary files /dev/null and b/static/departments/logo/mys_plate.png differ diff --git a/static/departments/logo/sgp_plate.png b/static/departments/logo/sgp_plate.png new file mode 100644 index 0000000..1487af0 Binary files /dev/null and b/static/departments/logo/sgp_plate.png differ diff --git a/static/departments/logo/tha_plate.png b/static/departments/logo/tha_plate.png new file mode 100644 index 0000000..95540a8 Binary files /dev/null and b/static/departments/logo/tha_plate.png differ diff --git a/static/departments/mys_plate.png b/static/departments/mys_plate.png new file mode 100644 index 0000000..3bb130c Binary files /dev/null and b/static/departments/mys_plate.png differ diff --git a/static/departments/sgp_plate.png b/static/departments/sgp_plate.png new file mode 100644 index 0000000..1487af0 Binary files /dev/null and b/static/departments/sgp_plate.png differ diff --git a/static/departments/tha_plate.png b/static/departments/tha_plate.png new file mode 100644 index 0000000..ad42242 Binary files /dev/null and b/static/departments/tha_plate.png differ diff --git a/static/favicon.svg b/static/favicon.svg new file mode 100644 index 0000000..cc5dc66 --- /dev/null +++ b/static/favicon.svg @@ -0,0 +1 @@ +svelte-logo \ No newline at end of file diff --git a/static/google-color.svg b/static/google-color.svg new file mode 100644 index 0000000..b26d4a4 --- /dev/null +++ b/static/google-color.svg @@ -0,0 +1,28 @@ + + + + + Google-color + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/static/icons/export.svg b/static/icons/export.svg new file mode 100644 index 0000000..6cf1faf --- /dev/null +++ b/static/icons/export.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/icons/logout.svg b/static/icons/logout.svg new file mode 100644 index 0000000..4881453 --- /dev/null +++ b/static/icons/logout.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/icons/logs.svg b/static/icons/logs.svg new file mode 100644 index 0000000..1c52f1e --- /dev/null +++ b/static/icons/logs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/icons/recipes.svg b/static/icons/recipes.svg new file mode 100644 index 0000000..d74d1cf --- /dev/null +++ b/static/icons/recipes.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/logo.png b/static/logo.png new file mode 100644 index 0000000..4bd4910 Binary files /dev/null and b/static/logo.png differ diff --git a/static/logo.svg b/static/logo.svg new file mode 100644 index 0000000..55f8f45 --- /dev/null +++ b/static/logo.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/robots.txt b/static/robots.txt new file mode 100644 index 0000000..b6dd667 --- /dev/null +++ b/static/robots.txt @@ -0,0 +1,3 @@ +# allow crawling everything by default +User-agent: * +Disallow: diff --git a/static/status-health.svelte b/static/status-health.svelte new file mode 100644 index 0000000..cd93d3a --- /dev/null +++ b/static/status-health.svelte @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/svelte.config.js b/svelte.config.js new file mode 100644 index 0000000..f18dfab --- /dev/null +++ b/svelte.config.js @@ -0,0 +1,17 @@ +import adapter from '@sveltejs/adapter-auto'; +import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; + +/** @type {import('@sveltejs/kit').Config} */ +const config = { + // Consult https://svelte.dev/docs/kit/integrations + // for more information about preprocessors + preprocess: vitePreprocess(), + kit: { + // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. + // If your environment is not supported, or you settled on a specific environment, switch out the adapter. + // See https://svelte.dev/docs/kit/adapters for more information about adapters. + adapter: adapter(), + }, +}; + +export default config; diff --git a/tailwind.config.ts b/tailwind.config.ts new file mode 100644 index 0000000..036abc0 --- /dev/null +++ b/tailwind.config.ts @@ -0,0 +1,126 @@ +import type { Config } from 'tailwindcss'; +import tailwindcssAnimate from 'tailwindcss-animate'; + +const config: Config = { + darkMode: 'class', + content: ['./src/**/*.{html,js,svelte,ts}'], + theme: { + extend: { + colors: { + primary: { + 50: '#f0f9ff', + 100: '#e0f2fe', + 200: '#bae6fd', + 300: '#7dd3fc', + 400: '#38bdf8', + 500: '#0ea5e9', + 600: '#0284c7', + 700: '#0369a1', + 800: '#075985', + 900: '#0c3d66' + }, + secondary: { + 50: '#faf5ff', + 100: '#f3e8ff', + 200: '#e9d5ff', + 300: '#d8b4fe', + 400: '#c084fc', + 500: '#a855f7', + 600: '#9333ea', + 700: '#7e22ce', + 800: '#6b21a8', + 900: '#581c87' + }, + accent: { + 50: '#fef3c7', + 100: '#fde68a', + 200: '#fcd34d', + 300: '#fbbf24', + 400: '#f59e0b', + 500: '#f97316', + 600: '#ea580c', + 700: '#c2410c', + 800: '#92400e', + 900: '#78350f' + }, + neutral: { + 50: '#fafafa', + 100: '#f5f5f5', + 200: '#e5e5e5', + 300: '#d4d4d4', + 400: '#a3a3a3', + 500: '#737373', + 600: '#525252', + 700: '#404040', + 800: '#262626', + 900: '#171717' + }, + sidebar: { + DEFAULT: 'hsl(var(--sidebar-background))', + foreground: 'hsl(var(--sidebar-foreground))', + primary: 'hsl(var(--sidebar-primary))', + 'primary-foreground': 'hsl(var(--sidebar-primary-foreground))', + accent: 'hsl(var(--sidebar-accent))', + 'accent-foreground': 'hsl(var(--sidebar-accent-foreground))', + border: 'hsl(var(--sidebar-border))', + ring: 'hsl(var(--sidebar-ring))' + } + }, + fontFamily: { + sans: [ + 'system-ui', + '-apple-system', + 'sans-serif', + '"Apple Color Emoji"', + '"Segoe UI Emoji"' + ] + }, + borderRadius: { + lg: '0.5rem', + md: '0.375rem', + sm: '0.25rem' + }, + boxShadow: { + sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)', + md: '0 4px 6px -1px rgba(0, 0, 0, 0.1)', + lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1)', + xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1)', + '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)', + none: 'none' + }, + spacing: { + 'safe-left': 'env(safe-area-inset-left)', + 'safe-right': 'env(safe-area-inset-right)', + 'safe-top': 'env(safe-area-inset-top)', + 'safe-bottom': 'env(safe-area-inset-bottom)' + }, + transitionDuration: { + 200: '200ms', + 300: '300ms', + 500: '500ms' + }, + keyframes: { + 'accordion-down': { + from: { height: '0' }, + to: { height: 'var(--bits-accordion-content-height)' } + }, + 'accordion-up': { + from: { height: 'var(--bits-accordion-content-height)' }, + to: { height: '0' } + }, + 'caret-blink': { + '0%,70%,100%': { opacity: '1' }, + '20%,50%': { opacity: '0' } + } + }, + animation: { + 'accordion-down': 'accordion-down 0.2s ease-out', + 'accordion-up': 'accordion-up 0.2s ease-out', + 'caret-blink': 'caret-blink 1.25s ease-out infinite' + } + } + }, + plugins: [tailwindcssAnimate] +}; + +export default config; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5f1994a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "allowImportingTsExtensions": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": true, + "moduleResolution": "bundler" + } + // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias + // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files + // + // To make changes to top-level options such as include and exclude, we recommend extending + // the generated config; see https://svelte.dev/docs/kit/configuration#typescript +} diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..6e62e08 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,43 @@ +import devtoolsJson from 'vite-plugin-devtools-json'; +import tailwindcss from '@tailwindcss/vite'; +import { defineConfig } from 'vitest/config'; +import { sveltekit } from '@sveltejs/kit/vite'; + +export default defineConfig({ + plugins: [tailwindcss(), sveltekit(), devtoolsJson()], + server: { + allowedHosts: ['pakins-macbook-pro.tail110d9.ts.net'] + }, + optimizeDeps: { + include: ['@xterm/xterm', '@xterm/addon-fit', '@xterm/addon-search'] + }, + test: { + expect: { requireAssertions: true }, + projects: [ + { + extends: './vite.config.ts', + test: { + name: 'client', + environment: 'browser', + browser: { + enabled: true, + provider: 'playwright', + instances: [{ browser: 'chromium' }] + }, + include: ['src/**/*.svelte.{test,spec}.{js,ts}'], + exclude: ['src/lib/server/**'], + setupFiles: ['./vitest-setup-client.ts'] + } + }, + { + extends: './vite.config.ts', + test: { + name: 'server', + environment: 'node', + include: ['src/**/*.{test,spec}.{js,ts}'], + exclude: ['src/**/*.svelte.{test,spec}.{js,ts}'] + } + } + ] + } +}); diff --git a/vitest-setup-client.ts b/vitest-setup-client.ts new file mode 100644 index 0000000..570b9f0 --- /dev/null +++ b/vitest-setup-client.ts @@ -0,0 +1,2 @@ +/// +///