@knotpad/app 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/(app)/calendar/page.tsx +57 -0
- package/app/(app)/error.tsx +35 -0
- package/app/(app)/graph/page.tsx +32 -0
- package/app/(app)/guide/page.tsx +21 -0
- package/app/(app)/kanban/loading.tsx +24 -0
- package/app/(app)/kanban/page.tsx +59 -0
- package/app/(app)/layout.tsx +122 -0
- package/app/(app)/list/loading.tsx +21 -0
- package/app/(app)/list/page.tsx +137 -0
- package/app/(app)/loading.tsx +18 -0
- package/app/(app)/notes/[noteId]/page.tsx +84 -0
- package/app/(app)/notes/layout.tsx +30 -0
- package/app/(app)/notes/page.tsx +39 -0
- package/app/(app)/page.tsx +5 -0
- package/app/(app)/settings/agent-token/page.tsx +59 -0
- package/app/(app)/settings/backup/page.tsx +49 -0
- package/app/(app)/settings/billing/page.tsx +53 -0
- package/app/(app)/settings/calendar/page.tsx +41 -0
- package/app/(app)/settings/layout.test.tsx +39 -0
- package/app/(app)/settings/layout.tsx +71 -0
- package/app/(app)/settings/page.tsx +4 -0
- package/app/(app)/settings/security/page.tsx +43 -0
- package/app/(app)/settings/team/page.tsx +74 -0
- package/app/(app)/settings/workspace/page.tsx +27 -0
- package/app/(app)/tasks/[taskId]/page.tsx +79 -0
- package/app/(auth)/forgot-password/page.tsx +106 -0
- package/app/(auth)/guest/page.tsx +56 -0
- package/app/(auth)/layout.tsx +13 -0
- package/app/(auth)/login/page.tsx +14 -0
- package/app/(auth)/register/page.tsx +193 -0
- package/app/(auth)/reset-password/page.tsx +138 -0
- package/app/api/account/claim/route.tsx +135 -0
- package/app/api/admin/backfill-encryption/route.tsx +43 -0
- package/app/api/admin/license/route.tsx +42 -0
- package/app/api/auth/2fa/route.tsx +148 -0
- package/app/api/auth/[...nextauth]/route.tsx +3 -0
- package/app/api/auth/change-password/route.tsx +61 -0
- package/app/api/auth/check-2fa/route.tsx +19 -0
- package/app/api/auth/forgot-password/route.tsx +65 -0
- package/app/api/auth/reset-password/route.tsx +52 -0
- package/app/api/auth/verify-2fa/route.tsx +88 -0
- package/app/api/backup/download/db/route.ts +29 -0
- package/app/api/backup/download/notes/route.ts +25 -0
- package/app/api/backup/settings/route.ts +92 -0
- package/app/api/billing/checkout/route.tsx +81 -0
- package/app/api/billing/migrate/route.tsx +163 -0
- package/app/api/billing/portal/route.tsx +24 -0
- package/app/api/billing/setup-intent/route.tsx +55 -0
- package/app/api/billing/status/route.tsx +36 -0
- package/app/api/billing/subscribe/route.tsx +85 -0
- package/app/api/billing/webhook/route.tsx +199 -0
- package/app/api/calendar-feeds/[feedId]/route.tsx +67 -0
- package/app/api/calendar-feeds/[feedId]/sync/route.tsx +37 -0
- package/app/api/calendar-feeds/events/route.tsx +82 -0
- package/app/api/calendar-feeds/route.tsx +52 -0
- package/app/api/calendar-feeds/sync-all/route.tsx +34 -0
- package/app/api/cron/calendar-feeds/route.tsx +31 -0
- package/app/api/cron/stale-tasks/route.tsx +51 -0
- package/app/api/cron/sync/route.tsx +34 -0
- package/app/api/devices/[deviceId]/route.tsx +25 -0
- package/app/api/devices/route.tsx +41 -0
- package/app/api/export/route.tsx +40 -0
- package/app/api/feedback/route.tsx +54 -0
- package/app/api/folders/[folderId]/route.tsx +51 -0
- package/app/api/folders/route.tsx +37 -0
- package/app/api/graph/route.tsx +242 -0
- package/app/api/guest/route.tsx +58 -0
- package/app/api/health/route.tsx +10 -0
- package/app/api/holidays/countries/route.tsx +14 -0
- package/app/api/holidays/route.tsx +49 -0
- package/app/api/holidays/states/route.tsx +21 -0
- package/app/api/invites/[token]/route.tsx +131 -0
- package/app/api/invites/route.tsx +74 -0
- package/app/api/mcp/generate-token/route.tsx +55 -0
- package/app/api/mcp/revoke-token/[tokenId]/route.tsx +30 -0
- package/app/api/mcp/update-alias/[tokenId]/route.tsx +22 -0
- package/app/api/notes/[noteId]/export/route.tsx +45 -0
- package/app/api/notes/[noteId]/route.tsx +360 -0
- package/app/api/notes/route.tsx +112 -0
- package/app/api/notifications/route.tsx +44 -0
- package/app/api/register/route.tsx +67 -0
- package/app/api/restore/route.tsx +148 -0
- package/app/api/sync/conflicts/[conflictId]/route.tsx +134 -0
- package/app/api/sync/conflicts/route.tsx +48 -0
- package/app/api/sync/status/route.tsx +49 -0
- package/app/api/sync/trigger/route.tsx +15 -0
- package/app/api/tasks/[taskId]/detail/route.tsx +68 -0
- package/app/api/tasks/[taskId]/route.tsx +259 -0
- package/app/api/tasks/bulk/route.tsx +133 -0
- package/app/api/tasks/route.tsx +36 -0
- package/app/api/workspace/active/route.tsx +39 -0
- package/app/api/workspace/create-team/route.tsx +42 -0
- package/app/api/workspace/kanban-statuses/route.tsx +71 -0
- package/app/api/workspace/members/[memberId]/route.tsx +69 -0
- package/app/api/workspace/route.tsx +24 -0
- package/app/download/page.tsx +170 -0
- package/app/favicon.ico +0 -0
- package/app/generated/prisma/client.d.ts +1 -0
- package/app/generated/prisma/client.js +5 -0
- package/app/generated/prisma/default.d.ts +1 -0
- package/app/generated/prisma/default.js +5 -0
- package/app/generated/prisma/edge.d.ts +1 -0
- package/app/generated/prisma/edge.js +497 -0
- package/app/generated/prisma/index-browser.js +523 -0
- package/app/generated/prisma/index.d.ts +46376 -0
- package/app/generated/prisma/index.js +497 -0
- package/app/generated/prisma/package.json +144 -0
- package/app/generated/prisma/query_compiler_fast_bg.js +2 -0
- package/app/generated/prisma/query_compiler_fast_bg.wasm +0 -0
- package/app/generated/prisma/query_compiler_fast_bg.wasm-base64.js +2 -0
- package/app/generated/prisma/runtime/client.d.ts +3386 -0
- package/app/generated/prisma/runtime/client.js +86 -0
- package/app/generated/prisma/runtime/index-browser.d.ts +90 -0
- package/app/generated/prisma/runtime/index-browser.js +6 -0
- package/app/generated/prisma/runtime/wasm-compiler-edge.js +76 -0
- package/app/generated/prisma/schema.prisma +456 -0
- package/app/generated/prisma/wasm-edge-light-loader.mjs +5 -0
- package/app/generated/prisma/wasm-worker-loader.mjs +5 -0
- package/app/globals.css +54 -0
- package/app/invite/[token]/page.tsx +52 -0
- package/app/layout.tsx +90 -0
- package/app/mcp/route.tsx +430 -0
- package/app/opengraph-image.tsx +120 -0
- package/app/page.tsx +398 -0
- package/app/privacy/page.tsx +69 -0
- package/app/robots.tsx +25 -0
- package/app/sitemap.tsx +36 -0
- package/app/terms/page.tsx +69 -0
- package/app/upgrade/page.tsx +75 -0
- package/auth.config.ts +33 -0
- package/auth.ts +79 -0
- package/bin/brief.js +229 -0
- package/components/auth/login-form.tsx +302 -0
- package/components/auth/password-checklist.tsx +31 -0
- package/components/auth/password-input.tsx +36 -0
- package/components/auth/switch-account-button.test.tsx +22 -0
- package/components/auth/switch-account-button.tsx +19 -0
- package/components/auth/two-factor-input.tsx +116 -0
- package/components/billing/billing-dashboard.tsx +265 -0
- package/components/billing/card-form.tsx +210 -0
- package/components/billing/claim-account-form.tsx +99 -0
- package/components/branding/app-logo.test.tsx +20 -0
- package/components/branding/app-logo.tsx +25 -0
- package/components/calendar/calendar-agenda.tsx +150 -0
- package/components/calendar/calendar-drag.test.tsx +177 -0
- package/components/calendar/calendar-grid.tsx +357 -0
- package/components/calendar/calendar-hooks.test.tsx +27 -0
- package/components/calendar/calendar-hooks.ts +351 -0
- package/components/calendar/calendar-toolbar.test.tsx +68 -0
- package/components/calendar/calendar-toolbar.tsx +291 -0
- package/components/calendar/calendar-types.ts +148 -0
- package/components/calendar/calendar-view.test.tsx +295 -0
- package/components/calendar/calendar-view.tsx +307 -0
- package/components/calendar/day-detail-popover.tsx +174 -0
- package/components/calendar/task-chip.tsx +86 -0
- package/components/command/command-palette.test.tsx +33 -0
- package/components/command/command-palette.tsx +310 -0
- package/components/download-cta.tsx +87 -0
- package/components/feedback/feedback-popup.tsx +207 -0
- package/components/graph/graph-draw.ts +337 -0
- package/components/graph/graph-overlays.tsx +160 -0
- package/components/graph/graph-page.test.tsx +131 -0
- package/components/graph/graph-page.tsx +263 -0
- package/components/graph/graph-types.ts +47 -0
- package/components/graph/graph-view.tsx +322 -0
- package/components/guide/guide-view.tsx +522 -0
- package/components/kanban/kanban-board.test.tsx +128 -0
- package/components/kanban/kanban-board.tsx +361 -0
- package/components/kanban/kanban-card-menu.tsx +102 -0
- package/components/kanban/kanban-card.tsx +227 -0
- package/components/kanban/kanban-column.tsx +49 -0
- package/components/kanban/kanban-status-context.tsx +28 -0
- package/components/landing/calendar-sandbox.test.tsx +15 -0
- package/components/landing/calendar-sandbox.tsx +107 -0
- package/components/landing/graph-sandbox.test.tsx +27 -0
- package/components/landing/graph-sandbox.tsx +80 -0
- package/components/landing/kanban-sandbox.test.tsx +24 -0
- package/components/landing/kanban-sandbox.tsx +101 -0
- package/components/landing/landing-showcase.test.tsx +21 -0
- package/components/landing/landing-showcase.tsx +54 -0
- package/components/landing/list-sandbox.tsx +86 -0
- package/components/landing/mock-workspace.ts +168 -0
- package/components/landing/notes-sandbox.test.tsx +14 -0
- package/components/landing/notes-sandbox.tsx +88 -0
- package/components/layout/app-shell.tsx +83 -0
- package/components/layout/backup-scheduler.tsx +122 -0
- package/components/layout/bottom-nav.tsx +43 -0
- package/components/layout/icon-bar.test.tsx +29 -0
- package/components/layout/icon-bar.tsx +118 -0
- package/components/layout/mobile-top-bar.tsx +68 -0
- package/components/layout/notes-panel-folder.tsx +127 -0
- package/components/layout/notes-panel-note-item.tsx +140 -0
- package/components/layout/notes-panel-task-tab.tsx +63 -0
- package/components/layout/notes-panel-types.ts +44 -0
- package/components/layout/notes-panel.tsx +476 -0
- package/components/layout/notification-bell.tsx +251 -0
- package/components/layout/paywall-screen.tsx +41 -0
- package/components/layout/pro-banner.tsx +76 -0
- package/components/layout/sw-register.tsx +27 -0
- package/components/layout/workspace-switcher.tsx +90 -0
- package/components/notes/mobile-bottom-sheet.tsx +99 -0
- package/components/notes/note-editor-context-menu.tsx +47 -0
- package/components/notes/note-editor-dom.ts +33 -0
- package/components/notes/note-editor-dropdowns.tsx +484 -0
- package/components/notes/note-editor-hooks.ts +692 -0
- package/components/notes/note-editor-keyboard.ts +305 -0
- package/components/notes/note-editor-overlay.tsx +90 -0
- package/components/notes/note-editor.test.tsx +372 -0
- package/components/notes/note-editor.tsx +662 -0
- package/components/notes/note-preview-pane.tsx +156 -0
- package/components/notes/note-tabs.tsx +120 -0
- package/components/notes/note-types.tsx +157 -0
- package/components/settings/accept-invite.tsx +108 -0
- package/components/settings/agent-token-settings.tsx +369 -0
- package/components/settings/backup-restore-settings.test.tsx +25 -0
- package/components/settings/backup-restore-settings.tsx +327 -0
- package/components/settings/calendar-feeds-settings.tsx +489 -0
- package/components/settings/calendar-general-settings.tsx +174 -0
- package/components/settings/confirm-danger-action.test.tsx +215 -0
- package/components/settings/confirm-danger-action.tsx +65 -0
- package/components/settings/security-settings.tsx +252 -0
- package/components/settings/settings-guidance.test.tsx +98 -0
- package/components/settings/team-settings.tsx +319 -0
- package/components/settings/two-factor-auth.tsx +296 -0
- package/components/settings/workspace-settings-client.tsx +363 -0
- package/components/settings/workspace-settings-form.tsx +73 -0
- package/components/sync/conflict-viewer.tsx +247 -0
- package/components/sync/sync-indicator.tsx +171 -0
- package/components/tasks/snippet-thread.tsx +119 -0
- package/components/tasks/status-dot.tsx +47 -0
- package/components/tasks/task-badge.tsx +43 -0
- package/components/tasks/task-detail.test.tsx +187 -0
- package/components/tasks/task-detail.tsx +458 -0
- package/components/tasks/task-list-filters.test.tsx +75 -0
- package/components/tasks/task-list-filters.tsx +163 -0
- package/components/tasks/task-list-types.ts +20 -0
- package/components/tasks/task-list.test.tsx +175 -0
- package/components/tasks/task-list.tsx +481 -0
- package/components/tasks/task-row.tsx +85 -0
- package/components/tasks/task-table-row.tsx +259 -0
- package/components/ui/skeleton.tsx +3 -0
- package/components/ui/toast.test.tsx +42 -0
- package/components/ui/toast.tsx +70 -0
- package/instrumentation.tsx +23 -0
- package/lib/api-error.ts +50 -0
- package/lib/backup/backup-runner.test.ts +32 -0
- package/lib/backup/backup-runner.ts +19 -0
- package/lib/backup/backup-schedule.test.ts +23 -0
- package/lib/backup/backup-schedule.ts +55 -0
- package/lib/backup/backup-settings.test.ts +30 -0
- package/lib/backup/backup-settings.ts +27 -0
- package/lib/backup/export-notes-zip.test.ts +26 -0
- package/lib/backup/export-notes-zip.ts +82 -0
- package/lib/backup/export-workspace-backup.test.ts +17 -0
- package/lib/backup/export-workspace-backup.ts +77 -0
- package/lib/backup/restore-workspace-from-export.test.ts +18 -0
- package/lib/backup/restore-workspace-from-export.ts +183 -0
- package/lib/backup/types.ts +14 -0
- package/lib/brand-icons.ts +1 -0
- package/lib/calendar-feed-crypto.ts +38 -0
- package/lib/calendar-feed.ts +239 -0
- package/lib/client/online-status.ts +47 -0
- package/lib/conflict-resolver.test.ts +57 -0
- package/lib/conflict-resolver.ts +240 -0
- package/lib/db-init.ts +79 -0
- package/lib/email.ts +159 -0
- package/lib/encryption.test.ts +41 -0
- package/lib/encryption.ts +98 -0
- package/lib/extract-snippet.test.ts +123 -0
- package/lib/extract-snippet.ts +69 -0
- package/lib/kanban-status.ts +55 -0
- package/lib/license.ts +21 -0
- package/lib/limits.ts +31 -0
- package/lib/mcp-auth.test.ts +58 -0
- package/lib/mcp-auth.ts +65 -0
- package/lib/mcp-contract.test.ts +25 -0
- package/lib/mcp-contract.ts +210 -0
- package/lib/mcp-handler.ts +31 -0
- package/lib/mcp-url.test.ts +12 -0
- package/lib/mcp-url.ts +7 -0
- package/lib/mentions.test.ts +45 -0
- package/lib/mentions.ts +73 -0
- package/lib/note-crypto.ts +108 -0
- package/lib/note-sync.ts +201 -0
- package/lib/note-title.ts +93 -0
- package/lib/prisma.ts +193 -0
- package/lib/pro-flush.ts +292 -0
- package/lib/rate-limit.ts +57 -0
- package/lib/stripe.ts +38 -0
- package/lib/sync-worker.ts +388 -0
- package/lib/task-parser.test.ts +91 -0
- package/lib/task-parser.ts +81 -0
- package/lib/task-utils.ts +52 -0
- package/lib/use-is-electron.ts +19 -0
- package/lib/use-is-mobile.ts +22 -0
- package/lib/validation/calendar-feed.ts +31 -0
- package/lib/validation/note.ts +27 -0
- package/lib/validation/task.ts +26 -0
- package/lib/view-preferences.test.ts +54 -0
- package/lib/view-preferences.ts +28 -0
- package/lib/workspace.ts +66 -0
- package/next.config.ts +21 -0
- package/package.json +54 -3
- package/postcss.config.mjs +7 -0
- package/prisma/migrations/20260519021916_init/migration.sql +388 -0
- package/prisma/migrations/20260519061113_drop_sync_password/migration.sql +8 -0
- package/prisma/migrations/20260520065016_add_task_start_date/migration.sql +2 -0
- package/prisma/migrations/20260529010600_remove_encryption_fields/migration.sql +12 -0
- package/prisma/migrations/20260529020000_restore_encryption_salt/migration.sql +3 -0
- package/prisma/migrations/20260529030000_add_folders/migration.sql +17 -0
- package/prisma/migrations/20260605000000_deferred_fixes/migration.sql +31 -0
- package/prisma/migrations/20260605020806_add_pending_sync_to_note_and_task/migration.sql +5 -0
- package/prisma/migrations/20260605063634_add_stripe_webhook_event_sync_lock/migration.sql +14 -0
- package/prisma/migrations/20260605100000_add_prod_indexes/migration.sql +26 -0
- package/prisma/migrations/20260608081404_add_kanban_statuses/migration.sql +23 -0
- package/prisma/migrations/20260611032723_add_calendar_feeds/migration.sql +43 -0
- package/prisma/migrations/20260611040000_add_calendar_feed_color/migration.sql +2 -0
- package/prisma/migrations/20260611050000_add_task_priority/migration.sql +14 -0
- package/prisma/migrations/20260612060000_add_critical_priority/migration.sql +2 -0
- package/prisma/migrations/20260613090000_add_backup_settings/migration.sql +25 -0
- package/prisma/migrations/20260614160000_add_feedback/migration.sql +20 -0
- package/prisma/migrations/20260614210000_add_2fa/migration.sql +4 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +457 -0
- package/public/Logo_icon.svg +1 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/icon_dark.svg +1 -0
- package/public/knotpad_icon.svg +1 -0
- package/public/knotpad_logo_full.svg +1 -0
- package/public/manifest.json +14 -0
- package/public/next.svg +1 -0
- package/public/sw.js +137 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/tsconfig.json +35 -0
- package/brief.js +0 -311
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import Link from "next/link";
|
|
6
|
+
import { useKanbanStatuses } from "@/components/kanban/kanban-status-context";
|
|
7
|
+
import type { CalTask, BusyBlockEntry, HolidayEntry } from "./calendar-types";
|
|
8
|
+
import { getStatusDot, feedBg, feedText, countryFlag } from "./calendar-types";
|
|
9
|
+
import { MobileBottomSheet } from "@/components/notes/mobile-bottom-sheet";
|
|
10
|
+
|
|
11
|
+
const POPOVER_WIDTH = 256;
|
|
12
|
+
|
|
13
|
+
function formatDate(dateKey: string): string {
|
|
14
|
+
const d = new Date(dateKey + "T00:00:00");
|
|
15
|
+
return d.toLocaleDateString(undefined, { weekday: "short", month: "short", day: "numeric" });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function formatTime(iso: string): string {
|
|
19
|
+
return new Date(iso).toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Props = {
|
|
23
|
+
open: boolean;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
dateKey: string | null;
|
|
26
|
+
kind: "busy" | "tasks" | "holidays";
|
|
27
|
+
busyBlocks: BusyBlockEntry[];
|
|
28
|
+
tasks: CalTask[];
|
|
29
|
+
holidays?: HolidayEntry[];
|
|
30
|
+
holidayCountry?: string;
|
|
31
|
+
taskHref: (taskId: string) => string;
|
|
32
|
+
isOverdue: (task: CalTask) => boolean;
|
|
33
|
+
anchorRect: DOMRect | null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function DayDetailPopover({
|
|
37
|
+
open,
|
|
38
|
+
onClose,
|
|
39
|
+
dateKey,
|
|
40
|
+
kind,
|
|
41
|
+
busyBlocks,
|
|
42
|
+
tasks,
|
|
43
|
+
holidays = [],
|
|
44
|
+
holidayCountry = "MY",
|
|
45
|
+
taskHref,
|
|
46
|
+
isOverdue,
|
|
47
|
+
anchorRect,
|
|
48
|
+
}: Props) {
|
|
49
|
+
const kanbanStatuses = useKanbanStatuses();
|
|
50
|
+
const popoverRef = useRef<HTMLDivElement>(null);
|
|
51
|
+
const [pos, setPos] = useState<{ top: number; left: number }>({ top: 0, left: 0 });
|
|
52
|
+
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
if (!open || !anchorRect) return;
|
|
55
|
+
const popoverHeight = popoverRef.current?.offsetHeight ?? 320;
|
|
56
|
+
let top = anchorRect.bottom + 4;
|
|
57
|
+
let left = anchorRect.left;
|
|
58
|
+
if (top + popoverHeight > window.innerHeight) {
|
|
59
|
+
top = Math.max(4, anchorRect.top - popoverHeight - 4);
|
|
60
|
+
}
|
|
61
|
+
if (left + POPOVER_WIDTH > window.innerWidth) {
|
|
62
|
+
left = Math.max(8, window.innerWidth - POPOVER_WIDTH - 8);
|
|
63
|
+
}
|
|
64
|
+
if (left < 0) left = 8;
|
|
65
|
+
setPos({ top, left });
|
|
66
|
+
}, [open, anchorRect]);
|
|
67
|
+
|
|
68
|
+
// Escape key dismissal
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!open) return;
|
|
71
|
+
function onKey(e: KeyboardEvent) {
|
|
72
|
+
if (e.key === "Escape") onClose();
|
|
73
|
+
}
|
|
74
|
+
document.addEventListener("keydown", onKey);
|
|
75
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
76
|
+
}, [open, onClose]);
|
|
77
|
+
|
|
78
|
+
// Close on scroll/resize (desktop popover only)
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!open || !anchorRect) return;
|
|
81
|
+
function handle() {
|
|
82
|
+
onClose();
|
|
83
|
+
}
|
|
84
|
+
window.addEventListener("scroll", handle, true);
|
|
85
|
+
window.addEventListener("resize", handle);
|
|
86
|
+
return () => {
|
|
87
|
+
window.removeEventListener("scroll", handle, true);
|
|
88
|
+
window.removeEventListener("resize", handle);
|
|
89
|
+
};
|
|
90
|
+
}, [open, anchorRect, onClose]);
|
|
91
|
+
|
|
92
|
+
if (!open || !dateKey) return null;
|
|
93
|
+
|
|
94
|
+
const count = kind === "busy" ? busyBlocks.length : kind === "holidays" ? holidays.length : tasks.length;
|
|
95
|
+
|
|
96
|
+
const content = (
|
|
97
|
+
<>
|
|
98
|
+
<div className="flex items-center justify-between border-b border-zinc-800 px-3 py-2">
|
|
99
|
+
<span className="text-sm font-medium text-zinc-200">{formatDate(dateKey)}</span>
|
|
100
|
+
<span className="rounded-full bg-zinc-800 px-2 py-0.5 text-[10px] text-zinc-400">
|
|
101
|
+
{count} {kind === "busy" ? "busy" : kind === "holidays" ? "holiday" + (count === 1 ? "" : "s") : "task" + (count === 1 ? "" : "s")}
|
|
102
|
+
</span>
|
|
103
|
+
</div>
|
|
104
|
+
<div className="max-h-[50vh] overflow-y-auto p-2">
|
|
105
|
+
{kind === "busy"
|
|
106
|
+
? busyBlocks.map((b, i) => (
|
|
107
|
+
<div
|
|
108
|
+
key={`${b.title}-${i}`}
|
|
109
|
+
className={`mb-1 rounded border px-2 py-1.5 text-xs ${feedBg(b.feedColor)} ${feedText(b.feedColor)}`}
|
|
110
|
+
>
|
|
111
|
+
<div className="truncate">
|
|
112
|
+
{b.allDay ? b.title : `${formatTime(b.start)} ${b.title}`}
|
|
113
|
+
</div>
|
|
114
|
+
<div className="truncate text-[10px] opacity-60">{b.feedLabel}</div>
|
|
115
|
+
</div>
|
|
116
|
+
))
|
|
117
|
+
: kind === "holidays"
|
|
118
|
+
? holidays.map((h) => (
|
|
119
|
+
<div
|
|
120
|
+
key={h.name}
|
|
121
|
+
className="mb-1 rounded border border-amber-800/40 bg-amber-950/50 px-2 py-1.5 text-xs text-amber-300"
|
|
122
|
+
>
|
|
123
|
+
<div className="flex items-center gap-1.5 truncate">
|
|
124
|
+
<span className="shrink-0 text-[10px]">{countryFlag(holidayCountry)}</span>
|
|
125
|
+
<span className="truncate">{h.name}{h.is_subject_to_change ? " *" : ""}</span>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
))
|
|
129
|
+
: tasks.map((task) => {
|
|
130
|
+
const overdue = isOverdue(task);
|
|
131
|
+
return (
|
|
132
|
+
<Link
|
|
133
|
+
key={task.id}
|
|
134
|
+
href={taskHref(task.id)}
|
|
135
|
+
onClick={onClose}
|
|
136
|
+
className="flex items-center gap-2 rounded px-2 py-1.5 text-sm transition-colors hover:bg-zinc-800"
|
|
137
|
+
>
|
|
138
|
+
<span
|
|
139
|
+
className={`h-2 w-2 shrink-0 rounded-full ${overdue ? "bg-red-400" : getStatusDot(kanbanStatuses, task.status)}`}
|
|
140
|
+
/>
|
|
141
|
+
<span className={`flex-1 truncate ${overdue ? "text-red-300" : "text-zinc-200"}`}>
|
|
142
|
+
{task.title}
|
|
143
|
+
</span>
|
|
144
|
+
<span className="shrink-0 truncate text-xs text-zinc-600 max-w-[80px]">{task.noteTitle}</span>
|
|
145
|
+
</Link>
|
|
146
|
+
);
|
|
147
|
+
})}
|
|
148
|
+
</div>
|
|
149
|
+
</>
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<>
|
|
154
|
+
{anchorRect &&
|
|
155
|
+
createPortal(
|
|
156
|
+
<>
|
|
157
|
+
<div className="fixed inset-0 z-40 hidden md:block" onClick={onClose} aria-hidden />
|
|
158
|
+
<div
|
|
159
|
+
ref={popoverRef}
|
|
160
|
+
className="fixed z-50 hidden w-64 rounded-lg border border-zinc-700 bg-zinc-900 shadow-xl shadow-black/40 md:block"
|
|
161
|
+
style={{ top: pos.top, left: pos.left }}
|
|
162
|
+
>
|
|
163
|
+
{content}
|
|
164
|
+
</div>
|
|
165
|
+
</>,
|
|
166
|
+
document.body,
|
|
167
|
+
)}
|
|
168
|
+
|
|
169
|
+
<MobileBottomSheet open={open} onClose={onClose}>
|
|
170
|
+
<div className="px-1">{content}</div>
|
|
171
|
+
</MobileBottomSheet>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import { useKanbanStatuses } from "@/components/kanban/kanban-status-context";
|
|
5
|
+
import type { CalTask } from "./calendar-types";
|
|
6
|
+
import { getStatusDot } from "./calendar-types";
|
|
7
|
+
|
|
8
|
+
export function TaskChip({
|
|
9
|
+
task,
|
|
10
|
+
href,
|
|
11
|
+
isSaving,
|
|
12
|
+
isOverdue,
|
|
13
|
+
onDragStart,
|
|
14
|
+
onDragEnd,
|
|
15
|
+
onEdgeDragStart,
|
|
16
|
+
resizable = false,
|
|
17
|
+
compact = false,
|
|
18
|
+
}: {
|
|
19
|
+
task: CalTask;
|
|
20
|
+
href: string;
|
|
21
|
+
isSaving: boolean;
|
|
22
|
+
isOverdue: boolean;
|
|
23
|
+
onDragStart: (e: React.DragEvent) => void;
|
|
24
|
+
onDragEnd: () => void;
|
|
25
|
+
onEdgeDragStart?: (e: React.DragEvent, edge: "start" | "end") => void;
|
|
26
|
+
resizable?: boolean;
|
|
27
|
+
compact?: boolean;
|
|
28
|
+
}) {
|
|
29
|
+
const kanbanStatuses = useKanbanStatuses();
|
|
30
|
+
const showHandles = resizable && !!onEdgeDragStart;
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
className={`flex items-center overflow-hidden rounded border text-[11px] leading-tight transition ${
|
|
34
|
+
isSaving ? "opacity-50" : ""
|
|
35
|
+
} ${
|
|
36
|
+
isOverdue
|
|
37
|
+
? "border-red-800/50 bg-red-900/60"
|
|
38
|
+
: compact
|
|
39
|
+
? "border-zinc-800 bg-zinc-900"
|
|
40
|
+
: "border-zinc-700/50 bg-zinc-800/70"
|
|
41
|
+
}`}
|
|
42
|
+
title={`${task.title} · ${task.noteTitle}${isOverdue ? " · Overdue" : ""}`}
|
|
43
|
+
>
|
|
44
|
+
{showHandles && (
|
|
45
|
+
<span
|
|
46
|
+
draggable
|
|
47
|
+
onDragStart={(e) => { e.stopPropagation(); onEdgeDragStart!(e, "start"); }}
|
|
48
|
+
onDragEnd={(e) => { e.stopPropagation(); onDragEnd(); }}
|
|
49
|
+
aria-label={`Resize start for ${task.title}`}
|
|
50
|
+
title="Drag to set start date"
|
|
51
|
+
className="flex w-3.5 shrink-0 cursor-ew-resize items-center justify-center self-stretch border-r border-white/10 bg-black/25 text-[9px] leading-none text-white/60 hover:bg-black/45 hover:text-white/90"
|
|
52
|
+
>
|
|
53
|
+
<
|
|
54
|
+
</span>
|
|
55
|
+
)}
|
|
56
|
+
<div
|
|
57
|
+
draggable
|
|
58
|
+
onDragStart={(e) => { e.stopPropagation(); onDragStart(e); }}
|
|
59
|
+
onDragEnd={(e) => { e.stopPropagation(); onDragEnd(); }}
|
|
60
|
+
className="flex min-w-0 flex-1 cursor-grab items-center gap-1 px-1 py-0.5 transition hover:opacity-90 active:cursor-grabbing"
|
|
61
|
+
>
|
|
62
|
+
<Link
|
|
63
|
+
href={href}
|
|
64
|
+
draggable={false}
|
|
65
|
+
onClick={(e) => e.stopPropagation()}
|
|
66
|
+
className="flex min-w-0 flex-1 items-center gap-1 overflow-hidden"
|
|
67
|
+
>
|
|
68
|
+
<span className={`shrink-0 h-1.5 w-1.5 rounded-full ${isOverdue ? "bg-red-400" : getStatusDot(kanbanStatuses, task.status)}`} />
|
|
69
|
+
<span className={`truncate max-w-[100px] ${isOverdue ? "text-red-300" : "text-zinc-300"}`}>{task.title}</span>
|
|
70
|
+
</Link>
|
|
71
|
+
</div>
|
|
72
|
+
{showHandles && (
|
|
73
|
+
<span
|
|
74
|
+
draggable
|
|
75
|
+
onDragStart={(e) => { e.stopPropagation(); onEdgeDragStart!(e, "end"); }}
|
|
76
|
+
onDragEnd={(e) => { e.stopPropagation(); onDragEnd(); }}
|
|
77
|
+
aria-label={`Resize end for ${task.title}`}
|
|
78
|
+
title="Drag to set end date"
|
|
79
|
+
className="flex w-3.5 shrink-0 cursor-ew-resize items-center justify-center self-stretch border-l border-white/10 bg-black/25 text-[9px] leading-none text-white/60 hover:bg-black/45 hover:text-white/90"
|
|
80
|
+
>
|
|
81
|
+
>
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { CommandPaletteProvider } from "@/components/command/command-palette";
|
|
6
|
+
|
|
7
|
+
vi.mock("next/navigation", () => ({
|
|
8
|
+
useRouter: () => ({ push: vi.fn() }),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
window.HTMLElement.prototype.scrollIntoView = vi.fn();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe("CommandPalette", () => {
|
|
16
|
+
it("shows an empty state with recovery hints when no results match", async () => {
|
|
17
|
+
const user = userEvent.setup();
|
|
18
|
+
|
|
19
|
+
render(
|
|
20
|
+
<CommandPaletteProvider data={{ notes: [], tasks: [], folders: [], notesHref: "/notes" }}>
|
|
21
|
+
<button>Child</button>
|
|
22
|
+
</CommandPaletteProvider>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
await user.keyboard("{Meta>}k{/Meta}");
|
|
26
|
+
await user.type(screen.getByRole("textbox"), "zzzz");
|
|
27
|
+
|
|
28
|
+
expect(screen.getByText('No results for "zzzz"')).toBeInTheDocument();
|
|
29
|
+
expect(
|
|
30
|
+
screen.getByText(/try a note title, a task name, or a command like "calendar" or "settings"\./i)
|
|
31
|
+
).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { useRouter } from "next/navigation";
|
|
12
|
+
import {
|
|
13
|
+
Search,
|
|
14
|
+
FileText,
|
|
15
|
+
Folder,
|
|
16
|
+
Plus,
|
|
17
|
+
Kanban,
|
|
18
|
+
List as ListIcon,
|
|
19
|
+
Calendar,
|
|
20
|
+
Share2,
|
|
21
|
+
Settings,
|
|
22
|
+
CheckSquare,
|
|
23
|
+
CornerDownLeft,
|
|
24
|
+
} from "lucide-react";
|
|
25
|
+
|
|
26
|
+
export type CommandData = {
|
|
27
|
+
notes: { id: string; title: string }[];
|
|
28
|
+
tasks: { id: string; title: string; note: { id: string; title: string } | null }[];
|
|
29
|
+
folders: { id: string; name: string }[];
|
|
30
|
+
notesHref: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type Item = {
|
|
34
|
+
key: string;
|
|
35
|
+
section: string;
|
|
36
|
+
icon: React.ComponentType<{ size?: number; className?: string }>;
|
|
37
|
+
label: string;
|
|
38
|
+
sublabel?: string;
|
|
39
|
+
run: () => void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Lightweight relevance score. Returns -1 for no match; higher is better.
|
|
44
|
+
* exact > prefix > substring > subsequence. No external dependency.
|
|
45
|
+
*/
|
|
46
|
+
function score(textRaw: string, qRaw: string): number {
|
|
47
|
+
const text = textRaw.toLowerCase();
|
|
48
|
+
const q = qRaw.toLowerCase();
|
|
49
|
+
if (!q) return 0;
|
|
50
|
+
if (text === q) return 1000;
|
|
51
|
+
if (text.startsWith(q)) return 600 - text.length;
|
|
52
|
+
const idx = text.indexOf(q);
|
|
53
|
+
if (idx >= 0) return 300 - idx;
|
|
54
|
+
// subsequence fallback (fuzzy)
|
|
55
|
+
let ti = 0;
|
|
56
|
+
for (const ch of q) {
|
|
57
|
+
ti = text.indexOf(ch, ti);
|
|
58
|
+
if (ti === -1) return -1;
|
|
59
|
+
ti++;
|
|
60
|
+
}
|
|
61
|
+
return 50;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const Ctx = createContext<{ open: () => void }>({ open: () => {} });
|
|
65
|
+
export function useCommandPalette() {
|
|
66
|
+
return useContext(Ctx);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function CommandPaletteProvider({
|
|
70
|
+
data,
|
|
71
|
+
children,
|
|
72
|
+
}: {
|
|
73
|
+
data: CommandData;
|
|
74
|
+
children: React.ReactNode;
|
|
75
|
+
}) {
|
|
76
|
+
const [open, setOpen] = useState(false);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
function onKey(e: KeyboardEvent) {
|
|
80
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
setOpen((o) => !o);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
document.addEventListener("keydown", onKey);
|
|
86
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Ctx.Provider value={{ open: () => setOpen(true) }}>
|
|
91
|
+
{children}
|
|
92
|
+
{open && <CommandPalette data={data} onClose={() => setOpen(false)} />}
|
|
93
|
+
</Ctx.Provider>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function CommandPalette({ data, onClose }: { data: CommandData; onClose: () => void }) {
|
|
98
|
+
const router = useRouter();
|
|
99
|
+
const [query, setQuery] = useState("");
|
|
100
|
+
const [active, setActive] = useState(0);
|
|
101
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
102
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
inputRef.current?.focus();
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
const go = (href: string) => {
|
|
109
|
+
onClose();
|
|
110
|
+
router.push(href);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
async function createNote() {
|
|
114
|
+
onClose();
|
|
115
|
+
try {
|
|
116
|
+
const res = await fetch("/api/notes", {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({ title: "Untitled", content: "" }),
|
|
120
|
+
});
|
|
121
|
+
if (res.ok) {
|
|
122
|
+
const note = await res.json();
|
|
123
|
+
router.push(`/notes/${note.id}`);
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
/* ignore */
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const items = useMemo<Item[]>(() => {
|
|
131
|
+
const q = query.trim();
|
|
132
|
+
const out: Item[] = [];
|
|
133
|
+
|
|
134
|
+
const navCmds: Omit<Item, "section" | "key">[] = [
|
|
135
|
+
{ label: "Go to Notes", icon: FileText, run: () => go(data.notesHref) },
|
|
136
|
+
{ label: "Go to List", icon: ListIcon, run: () => go("/list") },
|
|
137
|
+
{ label: "Go to Kanban", icon: Kanban, run: () => go("/kanban") },
|
|
138
|
+
{ label: "Go to Calendar", icon: Calendar, run: () => go("/calendar") },
|
|
139
|
+
{ label: "Go to Graph", icon: Share2, run: () => go("/graph") },
|
|
140
|
+
{ label: "Go to Settings", icon: Settings, run: () => go("/settings") },
|
|
141
|
+
{ label: "Create new note", icon: Plus, run: createNote },
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
if (!q) {
|
|
145
|
+
navCmds.forEach((c, i) => out.push({ key: `cmd-${i}`, section: "Jump to", ...c }));
|
|
146
|
+
data.notes.slice(0, 5).forEach((n) =>
|
|
147
|
+
out.push({
|
|
148
|
+
key: `recent-${n.id}`,
|
|
149
|
+
section: "Recent notes",
|
|
150
|
+
icon: FileText,
|
|
151
|
+
label: n.title || "Untitled",
|
|
152
|
+
run: () => go(`/notes/${n.id}`),
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const ranked = <T,>(arr: T[], text: (t: T) => string, limit: number) =>
|
|
159
|
+
arr
|
|
160
|
+
.map((t) => ({ t, s: score(text(t), q) }))
|
|
161
|
+
.filter((x) => x.s >= 0)
|
|
162
|
+
.sort((a, b) => b.s - a.s)
|
|
163
|
+
.slice(0, limit)
|
|
164
|
+
.map((x) => x.t);
|
|
165
|
+
|
|
166
|
+
ranked(data.notes, (n) => n.title || "Untitled", 6).forEach((n) =>
|
|
167
|
+
out.push({
|
|
168
|
+
key: `note-${n.id}`,
|
|
169
|
+
section: "Notes",
|
|
170
|
+
icon: FileText,
|
|
171
|
+
label: n.title || "Untitled",
|
|
172
|
+
run: () => go(`/notes/${n.id}`),
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
ranked(data.tasks, (t) => t.title, 6).forEach((t) =>
|
|
177
|
+
out.push({
|
|
178
|
+
key: `task-${t.id}`,
|
|
179
|
+
section: "Tasks",
|
|
180
|
+
icon: CheckSquare,
|
|
181
|
+
label: t.title,
|
|
182
|
+
sublabel: t.note?.title,
|
|
183
|
+
run: () => go(`/tasks/${t.id}`),
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
ranked(data.folders, (f) => f.name, 4).forEach((f) =>
|
|
188
|
+
out.push({
|
|
189
|
+
key: `folder-${f.id}`,
|
|
190
|
+
section: "Folders",
|
|
191
|
+
icon: Folder,
|
|
192
|
+
label: f.name,
|
|
193
|
+
run: () => go(`/list?folder=${f.id}`),
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
navCmds
|
|
198
|
+
.filter((c) => score(c.label, q) >= 0)
|
|
199
|
+
.forEach((c, i) => out.push({ key: `cmd-${i}`, section: "Commands", ...c }));
|
|
200
|
+
|
|
201
|
+
return out;
|
|
202
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
203
|
+
}, [query, data]);
|
|
204
|
+
|
|
205
|
+
// Clamp during render (no effect) so the active row is always in range even
|
|
206
|
+
// as results shrink/grow.
|
|
207
|
+
const activeIdx = items.length === 0 ? -1 : Math.min(active, items.length - 1);
|
|
208
|
+
|
|
209
|
+
function onKeyDown(e: React.KeyboardEvent) {
|
|
210
|
+
if (e.key === "ArrowDown") {
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
setActive(Math.min(activeIdx + 1, items.length - 1));
|
|
213
|
+
} else if (e.key === "ArrowUp") {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
setActive(Math.max(activeIdx - 1, 0));
|
|
216
|
+
} else if (e.key === "Enter") {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
items[activeIdx]?.run();
|
|
219
|
+
} else if (e.key === "Escape") {
|
|
220
|
+
e.preventDefault();
|
|
221
|
+
onClose();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Scroll the active row into view.
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
const el = listRef.current?.querySelector<HTMLElement>(`[data-idx="${activeIdx}"]`);
|
|
228
|
+
el?.scrollIntoView({ block: "nearest" });
|
|
229
|
+
}, [activeIdx]);
|
|
230
|
+
|
|
231
|
+
let lastSection = "";
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<div
|
|
235
|
+
className="fixed inset-0 z-[100] flex items-start justify-center bg-black/60 px-4 pt-[12vh]"
|
|
236
|
+
onMouseDown={onClose}
|
|
237
|
+
>
|
|
238
|
+
<div
|
|
239
|
+
className="w-full max-w-lg overflow-hidden rounded-xl border border-zinc-700 bg-zinc-900 shadow-2xl"
|
|
240
|
+
onMouseDown={(e) => e.stopPropagation()}
|
|
241
|
+
role="dialog"
|
|
242
|
+
aria-label="Command palette"
|
|
243
|
+
>
|
|
244
|
+
<div className="flex items-center gap-2 border-b border-zinc-800 px-3">
|
|
245
|
+
<Search size={16} className="shrink-0 text-zinc-500" />
|
|
246
|
+
<input
|
|
247
|
+
ref={inputRef}
|
|
248
|
+
value={query}
|
|
249
|
+
onChange={(e) => {
|
|
250
|
+
setQuery(e.target.value);
|
|
251
|
+
setActive(0);
|
|
252
|
+
}}
|
|
253
|
+
onKeyDown={onKeyDown}
|
|
254
|
+
placeholder="Search notes, tasks, or jump to…"
|
|
255
|
+
aria-label="Search notes, tasks, or jump to a view"
|
|
256
|
+
className="w-full bg-transparent py-3 text-sm text-zinc-100 placeholder:text-zinc-600 outline-none"
|
|
257
|
+
/>
|
|
258
|
+
<kbd className="hidden shrink-0 rounded border border-zinc-700 px-1.5 py-0.5 text-[10px] text-zinc-500 sm:block">
|
|
259
|
+
Esc
|
|
260
|
+
</kbd>
|
|
261
|
+
</div>
|
|
262
|
+
|
|
263
|
+
<div ref={listRef} className="max-h-[55vh] overflow-y-auto py-1">
|
|
264
|
+
{items.length === 0 && (
|
|
265
|
+
<div className="border-t border-zinc-800 px-4 py-6 text-sm text-zinc-500">
|
|
266
|
+
<p className="font-medium text-zinc-300">No results for "{query.trim()}"</p>
|
|
267
|
+
<p className="mt-1">
|
|
268
|
+
Try a note title, a task name, or a command like "calendar" or
|
|
269
|
+
"settings".
|
|
270
|
+
</p>
|
|
271
|
+
</div>
|
|
272
|
+
)}
|
|
273
|
+
{items.map((item, i) => {
|
|
274
|
+
const header = item.section !== lastSection ? item.section : null;
|
|
275
|
+
lastSection = item.section;
|
|
276
|
+
const Icon = item.icon;
|
|
277
|
+
return (
|
|
278
|
+
<div key={item.key}>
|
|
279
|
+
{header && (
|
|
280
|
+
<p className="px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-zinc-600">
|
|
281
|
+
{header}
|
|
282
|
+
</p>
|
|
283
|
+
)}
|
|
284
|
+
<button
|
|
285
|
+
data-idx={i}
|
|
286
|
+
onMouseMove={() => setActive(i)}
|
|
287
|
+
onClick={() => item.run()}
|
|
288
|
+
className={`flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm transition-colors ${
|
|
289
|
+
activeIdx === i ? "bg-zinc-800 text-zinc-100" : "text-zinc-300"
|
|
290
|
+
}`}
|
|
291
|
+
>
|
|
292
|
+
<Icon size={15} className="shrink-0 text-zinc-500" />
|
|
293
|
+
<span className="flex-1 truncate">{item.label}</span>
|
|
294
|
+
{item.sublabel && (
|
|
295
|
+
<span className="shrink-0 max-w-[40%] truncate text-xs text-zinc-600">
|
|
296
|
+
{item.sublabel}
|
|
297
|
+
</span>
|
|
298
|
+
)}
|
|
299
|
+
{activeIdx === i && (
|
|
300
|
+
<CornerDownLeft size={13} className="shrink-0 text-zinc-600" />
|
|
301
|
+
)}
|
|
302
|
+
</button>
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
})}
|
|
306
|
+
</div>
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
);
|
|
310
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
|
|
6
|
+
type Platform = "windows" | "macos" | "linux" | "unknown";
|
|
7
|
+
|
|
8
|
+
function detectPlatform(): Platform {
|
|
9
|
+
if (typeof navigator === "undefined") return "unknown";
|
|
10
|
+
const ua = navigator.userAgent.toLowerCase();
|
|
11
|
+
if (ua.includes("win")) return "windows";
|
|
12
|
+
if (ua.includes("mac") || ua.includes("darwin")) return "macos";
|
|
13
|
+
if (ua.includes("linux")) return "linux";
|
|
14
|
+
return "unknown";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export default function DownloadCTA() {
|
|
19
|
+
const [platform, setPlatform] = useState<Platform>("unknown");
|
|
20
|
+
const [isMounted, setIsMounted] = useState(false);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setPlatform(detectPlatform());
|
|
24
|
+
setIsMounted(true);
|
|
25
|
+
}, []);
|
|
26
|
+
|
|
27
|
+
// Don't flash wrong content during SSR — render minimal state
|
|
28
|
+
if (!isMounted) {
|
|
29
|
+
return (
|
|
30
|
+
<div className="flex flex-col gap-4 sm:flex-row sm:items-center">
|
|
31
|
+
<div className="inline-flex items-center justify-center rounded-lg bg-zinc-100 px-6 py-3 text-sm font-semibold text-zinc-900 animate-pulse">
|
|
32
|
+
Loading…
|
|
33
|
+
</div>
|
|
34
|
+
<div className="flex flex-col gap-0.5 rounded-lg border border-zinc-800 bg-zinc-900 px-4 py-3">
|
|
35
|
+
<code className="text-sm font-mono text-zinc-300">npx @knotpad/app</code>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const isMac = platform === "macos";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className="flex flex-col gap-4">
|
|
45
|
+
{/* Primary CTA */}
|
|
46
|
+
<div className="flex flex-col gap-4 sm:flex-row sm:items-center">
|
|
47
|
+
{isMac ? (
|
|
48
|
+
<div className="flex flex-col gap-2">
|
|
49
|
+
<div className="inline-flex items-center gap-2 rounded-full border border-amber-800/40 bg-amber-950/30 px-3 py-1 w-fit">
|
|
50
|
+
<span className="h-1.5 w-1.5 rounded-full bg-amber-400 animate-pulse" />
|
|
51
|
+
<span className="text-xs text-amber-300">macOS coming soon</span>
|
|
52
|
+
</div>
|
|
53
|
+
<Link
|
|
54
|
+
href="/register"
|
|
55
|
+
className="inline-flex items-center justify-center rounded-lg bg-zinc-100 px-6 py-3 text-sm font-semibold text-zinc-900 hover:bg-white transition-colors"
|
|
56
|
+
>
|
|
57
|
+
Get started free →
|
|
58
|
+
</Link>
|
|
59
|
+
</div>
|
|
60
|
+
) : (
|
|
61
|
+
<Link
|
|
62
|
+
href="/download"
|
|
63
|
+
className="inline-flex items-center justify-center rounded-lg bg-zinc-100 px-6 py-3 text-sm font-semibold text-zinc-900 hover:bg-white transition-colors"
|
|
64
|
+
>
|
|
65
|
+
Download ↓
|
|
66
|
+
</Link>
|
|
67
|
+
)}
|
|
68
|
+
|
|
69
|
+
<div className="flex flex-col gap-0.5 rounded-lg border border-zinc-800 bg-zinc-900 px-4 py-3">
|
|
70
|
+
<code className="text-sm font-mono text-zinc-300">npx @knotpad/app</code>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
|
|
74
|
+
{/* All platforms fallback (for unknown / mobile) */}
|
|
75
|
+
{platform === "unknown" && (
|
|
76
|
+
<div className="flex flex-wrap gap-3 pt-1">
|
|
77
|
+
<Link
|
|
78
|
+
href="/download"
|
|
79
|
+
className="inline-flex items-center gap-2 rounded-md border border-zinc-800 bg-zinc-900 px-3 py-1.5 text-xs text-zinc-400 hover:text-zinc-200 hover:border-zinc-700 transition-colors"
|
|
80
|
+
>
|
|
81
|
+
View all downloads
|
|
82
|
+
</Link>
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|