@knotpad/app 0.1.5 → 0.1.6
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 +224 -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 +49 -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-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +4 -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,305 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Member, NoteRef, TaskRef, SlashCommandId, PriorityLevel } from "./note-types";
|
|
3
|
+
import { SLASH_COMMANDS, PRIORITY_LEVELS } from "./note-types";
|
|
4
|
+
|
|
5
|
+
export interface KeyboardHandlerDeps {
|
|
6
|
+
content: string;
|
|
7
|
+
title: string;
|
|
8
|
+
textareaRef: React.RefObject<HTMLTextAreaElement | null>;
|
|
9
|
+
savedCursor: React.MutableRefObject<{ start: number; end: number } | null>;
|
|
10
|
+
// Undo
|
|
11
|
+
historyTimer: React.MutableRefObject<ReturnType<typeof setTimeout> | null>;
|
|
12
|
+
historyPos: React.MutableRefObject<number>;
|
|
13
|
+
historyStack: React.MutableRefObject<string[]>;
|
|
14
|
+
pushHistoryImmediate: (v: string) => void;
|
|
15
|
+
// Save
|
|
16
|
+
scheduleSave: (t: string, c: string) => void;
|
|
17
|
+
setContent: (v: string | ((prev: string) => string)) => void;
|
|
18
|
+
// Slash
|
|
19
|
+
slashQuery: string | null;
|
|
20
|
+
setSlashQuery: (v: string | null) => void;
|
|
21
|
+
slashIndex: number;
|
|
22
|
+
setSlashIndex: (v: number | ((prev: number) => number)) => void;
|
|
23
|
+
slashSuggestions: typeof SLASH_COMMANDS;
|
|
24
|
+
executeSlashCommand: (id: SlashCommandId) => void;
|
|
25
|
+
setDropdownPos: (v: { top: number; left: number } | null) => void;
|
|
26
|
+
// Mention
|
|
27
|
+
mentionQuery: string | null;
|
|
28
|
+
setMentionQuery: (v: string | null) => void;
|
|
29
|
+
mentionIndex: number;
|
|
30
|
+
setMentionIndex: (v: number | ((prev: number) => number)) => void;
|
|
31
|
+
mentionSuggestions: Member[];
|
|
32
|
+
insertMention: (h: string) => void;
|
|
33
|
+
// Task
|
|
34
|
+
taskQuery: string | null;
|
|
35
|
+
setTaskQuery: (v: string | null) => void;
|
|
36
|
+
taskIndex: number;
|
|
37
|
+
setTaskIndex: (v: number | ((prev: number) => number)) => void;
|
|
38
|
+
taskSuggestions: TaskRef[];
|
|
39
|
+
insertTaskRef: (t: TaskRef) => void;
|
|
40
|
+
// Priority
|
|
41
|
+
priorityQuery: string | null;
|
|
42
|
+
setPriorityQuery: (v: string | null) => void;
|
|
43
|
+
priorityIndex: number;
|
|
44
|
+
setPriorityIndex: (v: number | ((prev: number) => number)) => void;
|
|
45
|
+
prioritySuggestions: typeof PRIORITY_LEVELS;
|
|
46
|
+
insertPriority: (level: PriorityLevel) => void;
|
|
47
|
+
// Plus
|
|
48
|
+
plusOpen: boolean;
|
|
49
|
+
setPlusOpen: (v: boolean) => void;
|
|
50
|
+
triggerPlusOption: (o: "note" | "task" | "person" | "date" | "priority") => void;
|
|
51
|
+
// Template
|
|
52
|
+
templateOpen: boolean;
|
|
53
|
+
setTemplateOpen: (v: boolean) => void;
|
|
54
|
+
// Context menu
|
|
55
|
+
contextMenu: { top: number; left: number; selStart: number; selEnd: number } | null;
|
|
56
|
+
setContextMenu: (v: { top: number; left: number; selStart: number; selEnd: number } | null) => void;
|
|
57
|
+
// Note
|
|
58
|
+
noteQuery: string | null;
|
|
59
|
+
setNoteQuery: (v: string | null) => void;
|
|
60
|
+
noteIndex: number;
|
|
61
|
+
setNoteIndex: (v: number | ((prev: number) => number)) => void;
|
|
62
|
+
noteSuggestions: NoteRef[];
|
|
63
|
+
insertNoteLink: (n: NoteRef) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function useNoteEditorKeyboard(d: KeyboardHandlerDeps) {
|
|
67
|
+
function handleKeyDown(e: React.KeyboardEvent<HTMLTextAreaElement>) {
|
|
68
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
69
|
+
|
|
70
|
+
// ── Undo Ctrl/Cmd+Z ────────────────────────────────────────────────────
|
|
71
|
+
if (mod && e.key === "z" && !e.shiftKey) {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
if (d.historyTimer.current) { clearTimeout(d.historyTimer.current); d.historyTimer.current = null; }
|
|
74
|
+
if (d.historyPos.current > 0) {
|
|
75
|
+
const curCursor = d.textareaRef.current?.selectionStart ?? 0;
|
|
76
|
+
d.historyPos.current--;
|
|
77
|
+
const prev = d.historyStack.current[d.historyPos.current];
|
|
78
|
+
const restored = Math.min(curCursor, prev.length);
|
|
79
|
+
d.savedCursor.current = { start: restored, end: restored };
|
|
80
|
+
d.setContent(prev);
|
|
81
|
+
d.scheduleSave(d.title, prev);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// ── Redo Ctrl/Cmd+Y or Ctrl/Cmd+Shift+Z ──────────────────────────────
|
|
86
|
+
if (mod && (e.key === "y" || (e.key === "z" && e.shiftKey))) {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
if (d.historyTimer.current) { clearTimeout(d.historyTimer.current); d.historyTimer.current = null; }
|
|
89
|
+
if (d.historyPos.current < d.historyStack.current.length - 1) {
|
|
90
|
+
const curCursor = d.textareaRef.current?.selectionStart ?? 0;
|
|
91
|
+
d.historyPos.current++;
|
|
92
|
+
const next = d.historyStack.current[d.historyPos.current];
|
|
93
|
+
const restored = Math.min(curCursor, next.length);
|
|
94
|
+
d.savedCursor.current = { start: restored, end: restored };
|
|
95
|
+
d.setContent(next);
|
|
96
|
+
d.scheduleSave(d.title, next);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// / command palette takes priority
|
|
102
|
+
if (d.slashQuery !== null && d.slashSuggestions.length > 0) {
|
|
103
|
+
if (e.key === "ArrowDown") {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
d.setSlashIndex((i) => Math.min(i + 1, d.slashSuggestions.length - 1));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (e.key === "ArrowUp") {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
d.setSlashIndex((i) => Math.max(i - 1, 0));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (e.key === "Enter" || e.key === "Tab") {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
d.executeSlashCommand(d.slashSuggestions[d.slashIndex].id);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (e.key === "Escape") {
|
|
119
|
+
d.setSlashQuery(null);
|
|
120
|
+
d.setDropdownPos(null);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Auto-continue task list on Enter — only when NO picker is active
|
|
126
|
+
if (
|
|
127
|
+
e.key === "Enter" &&
|
|
128
|
+
d.mentionQuery === null &&
|
|
129
|
+
d.slashQuery === null &&
|
|
130
|
+
d.noteQuery === null &&
|
|
131
|
+
d.taskQuery === null &&
|
|
132
|
+
d.priorityQuery === null &&
|
|
133
|
+
!d.plusOpen
|
|
134
|
+
) {
|
|
135
|
+
const ta = d.textareaRef.current;
|
|
136
|
+
if (ta) {
|
|
137
|
+
const pos = ta.selectionStart;
|
|
138
|
+
const lineStart = d.content.lastIndexOf("\n", pos - 1) + 1;
|
|
139
|
+
const currentLine = d.content.slice(lineStart, pos);
|
|
140
|
+
// Empty task line + Enter → terminate the list
|
|
141
|
+
if (/^\s*-\s+\[[ x]\]\s*$/.test(currentLine)) {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
d.pushHistoryImmediate(d.content);
|
|
144
|
+
const before = d.content.slice(0, lineStart);
|
|
145
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
146
|
+
const newContent = before + after;
|
|
147
|
+
d.savedCursor.current = { start: lineStart, end: lineStart };
|
|
148
|
+
d.setContent(newContent);
|
|
149
|
+
d.scheduleSave(d.title, newContent);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (/^\s*-\s+\[[ x]\]\s/.test(currentLine)) {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
const prefix = "- [ ] ";
|
|
155
|
+
const before = d.content.slice(0, pos);
|
|
156
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
157
|
+
const newContent = before + "\n" + prefix + after;
|
|
158
|
+
d.pushHistoryImmediate(d.content);
|
|
159
|
+
d.savedCursor.current = { start: pos + 1 + prefix.length, end: pos + 1 + prefix.length };
|
|
160
|
+
d.setContent(newContent);
|
|
161
|
+
d.scheduleSave(d.title, newContent);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Empty numbered list line → terminate
|
|
165
|
+
if (/^\s*\d+\.\s*$/.test(currentLine)) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
d.pushHistoryImmediate(d.content);
|
|
168
|
+
const before = d.content.slice(0, lineStart);
|
|
169
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
170
|
+
d.savedCursor.current = { start: lineStart, end: lineStart };
|
|
171
|
+
d.setContent(before + after);
|
|
172
|
+
d.scheduleSave(d.title, before + after);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// Numbered list continuation (auto-increment)
|
|
176
|
+
const numberedMatch = /^(\s*)(\d+)\.\s/.exec(currentLine);
|
|
177
|
+
if (numberedMatch) {
|
|
178
|
+
e.preventDefault();
|
|
179
|
+
const indent = numberedMatch[1];
|
|
180
|
+
const nextNum = parseInt(numberedMatch[2], 10) + 1;
|
|
181
|
+
const prefix = `${indent}${nextNum}. `;
|
|
182
|
+
const before = d.content.slice(0, pos);
|
|
183
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
184
|
+
const afterLines = after.split("\n");
|
|
185
|
+
for (let j = 1; j < afterLines.length; j++) {
|
|
186
|
+
const mm = /^(\s*)(\d+)(\.\s)/.exec(afterLines[j]);
|
|
187
|
+
if (mm && mm[1] === indent) {
|
|
188
|
+
afterLines[j] = `${mm[1]}${parseInt(mm[2], 10) + 1}${mm[3]}` + afterLines[j].slice(mm[0].length);
|
|
189
|
+
} else {
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const newContent = before + "\n" + prefix + afterLines.join("\n");
|
|
194
|
+
d.pushHistoryImmediate(d.content);
|
|
195
|
+
d.savedCursor.current = { start: pos + 1 + prefix.length, end: pos + 1 + prefix.length };
|
|
196
|
+
d.setContent(newContent);
|
|
197
|
+
d.scheduleSave(d.title, newContent);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
// Empty bullet list line → terminate
|
|
201
|
+
if (/^\s*-\s*$/.test(currentLine)) {
|
|
202
|
+
e.preventDefault();
|
|
203
|
+
d.pushHistoryImmediate(d.content);
|
|
204
|
+
const before = d.content.slice(0, lineStart);
|
|
205
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
206
|
+
d.savedCursor.current = { start: lineStart, end: lineStart };
|
|
207
|
+
d.setContent(before + after);
|
|
208
|
+
d.scheduleSave(d.title, before + after);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
// Bullet list continuation
|
|
212
|
+
const bulletMatch = /^(\s*)-\s/.exec(currentLine);
|
|
213
|
+
if (bulletMatch) {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
const indent = bulletMatch[1];
|
|
216
|
+
const prefix = `${indent}- `;
|
|
217
|
+
const before = d.content.slice(0, pos);
|
|
218
|
+
const after = d.content.slice(ta.selectionEnd);
|
|
219
|
+
const newContent = before + "\n" + prefix + after;
|
|
220
|
+
d.pushHistoryImmediate(d.content);
|
|
221
|
+
d.savedCursor.current = { start: pos + 1 + prefix.length, end: pos + 1 + prefix.length };
|
|
222
|
+
d.setContent(newContent);
|
|
223
|
+
d.scheduleSave(d.title, newContent);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Regular Enter is also a good undo checkpoint
|
|
228
|
+
d.pushHistoryImmediate(d.content);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// @mention navigation
|
|
232
|
+
if (d.mentionQuery !== null && d.mentionSuggestions.length > 0) {
|
|
233
|
+
if (e.key === "ArrowDown") {
|
|
234
|
+
e.preventDefault();
|
|
235
|
+
d.setMentionIndex((i) => Math.min(i + 1, d.mentionSuggestions.length - 1));
|
|
236
|
+
} else if (e.key === "ArrowUp") {
|
|
237
|
+
e.preventDefault();
|
|
238
|
+
d.setMentionIndex((i) => Math.max(i - 1, 0));
|
|
239
|
+
} else if (e.key === "Enter" || e.key === "Tab") {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
d.insertMention(d.mentionSuggestions[d.mentionIndex].handle);
|
|
242
|
+
} else if (e.key === "Escape") {
|
|
243
|
+
d.setMentionQuery(null);
|
|
244
|
+
d.setDropdownPos(null);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ((task)) picker navigation
|
|
249
|
+
if (d.taskQuery !== null && d.taskSuggestions.length > 0) {
|
|
250
|
+
if (e.key === "ArrowDown") { e.preventDefault(); d.setTaskIndex((i) => Math.min(i + 1, d.taskSuggestions.length - 1)); }
|
|
251
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); d.setTaskIndex((i) => Math.max(i - 1, 0)); }
|
|
252
|
+
else if (e.key === "Enter" || e.key === "Tab") { e.preventDefault(); d.insertTaskRef(d.taskSuggestions[d.taskIndex]); }
|
|
253
|
+
else if (e.key === "Escape") { d.setTaskQuery(null); d.setDropdownPos(null); }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// !priority picker navigation
|
|
257
|
+
if (d.priorityQuery !== null && d.prioritySuggestions.length > 0) {
|
|
258
|
+
if (e.key === "ArrowDown") { e.preventDefault(); d.setPriorityIndex((i) => Math.min(i + 1, d.prioritySuggestions.length - 1)); }
|
|
259
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); d.setPriorityIndex((i) => Math.max(i - 1, 0)); }
|
|
260
|
+
else if (e.key === "Enter" || e.key === "Tab") { e.preventDefault(); d.insertPriority(d.prioritySuggestions[d.priorityIndex].id); }
|
|
261
|
+
else if (e.key === "Escape") { d.setPriorityQuery(null); d.setDropdownPos(null); }
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// + quick-pick navigation
|
|
265
|
+
if (d.plusOpen) {
|
|
266
|
+
if (e.key === "Escape") { d.setPlusOpen(false); d.setDropdownPos(null); }
|
|
267
|
+
if (e.key === "1") { e.preventDefault(); d.triggerPlusOption("note"); }
|
|
268
|
+
if (e.key === "2") { e.preventDefault(); d.triggerPlusOption("task"); }
|
|
269
|
+
if (e.key === "3") { e.preventDefault(); d.triggerPlusOption("person"); }
|
|
270
|
+
if (e.key === "4") { e.preventDefault(); d.triggerPlusOption("date"); }
|
|
271
|
+
if (e.key === "5") { e.preventDefault(); d.triggerPlusOption("priority"); }
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Template sub-picker — Escape to dismiss
|
|
275
|
+
if (d.templateOpen && e.key === "Escape") {
|
|
276
|
+
d.setTemplateOpen(false);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Context menu — Escape to dismiss
|
|
281
|
+
if (d.contextMenu && e.key === "Escape") {
|
|
282
|
+
d.setContextMenu(null);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// [[note]] picker navigation
|
|
287
|
+
if (d.noteQuery !== null && d.noteSuggestions.length > 0) {
|
|
288
|
+
if (e.key === "ArrowDown") {
|
|
289
|
+
e.preventDefault();
|
|
290
|
+
d.setNoteIndex((i) => Math.min(i + 1, d.noteSuggestions.length - 1));
|
|
291
|
+
} else if (e.key === "ArrowUp") {
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
d.setNoteIndex((i) => Math.max(i - 1, 0));
|
|
294
|
+
} else if (e.key === "Enter" || e.key === "Tab") {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
d.insertNoteLink(d.noteSuggestions[d.noteIndex]);
|
|
297
|
+
} else if (e.key === "Escape") {
|
|
298
|
+
d.setNoteQuery(null);
|
|
299
|
+
d.setDropdownPos(null);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return { handleKeyDown };
|
|
305
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React from "react";
|
|
4
|
+
import type { Task } from "./note-types";
|
|
5
|
+
import { extractTaskTitleFromLine, formatDateChip, formatDateRangeChip } from "./note-types";
|
|
6
|
+
|
|
7
|
+
/** Escape HTML entities and apply inline syntax colouring. */
|
|
8
|
+
export function highlightLine(raw: string): string {
|
|
9
|
+
const esc = raw
|
|
10
|
+
.replace(/&/g, "&")
|
|
11
|
+
.replace(/</g, "<")
|
|
12
|
+
.replace(/>/g, ">");
|
|
13
|
+
|
|
14
|
+
function colorize(s: string): string {
|
|
15
|
+
return s
|
|
16
|
+
.replace(/@[\w-]+/g, (m) => `<span class="text-blue-400 font-medium">${m}</span>`)
|
|
17
|
+
.replace(/<[^&]+>/g, (m) => `<span class="text-emerald-400 font-medium">${m}</span>`)
|
|
18
|
+
.replace(/\[\[([^\]]+)\]\]/g, (_, t) => `<span class="text-violet-400 underline decoration-dotted">[[${t}]]</span>`)
|
|
19
|
+
.replace(/\(\(([^)]+)\)\)/g, (_, t) => `<span class="text-amber-400 underline decoration-dotted">((${t}))</span>`)
|
|
20
|
+
.replace(/~~([^~]+)~~/g, (_, t) => `<s class="text-zinc-500">~~${t}~~</s>`)
|
|
21
|
+
.replace(/!(low|medium|high|critical)\b/gi, (m, level) => {
|
|
22
|
+
const colors: Record<string, string> = {
|
|
23
|
+
critical: "text-red-500 bg-red-950/50 border-red-800/40",
|
|
24
|
+
high: "text-red-400 bg-red-950/30 border-red-800/30",
|
|
25
|
+
medium: "text-yellow-400 bg-yellow-950/30 border-yellow-800/30",
|
|
26
|
+
low: "text-green-400 bg-green-950/30 border-green-800/30",
|
|
27
|
+
};
|
|
28
|
+
return `<span class="${colors[level.toLowerCase()]} text-[11px] font-mono border rounded px-1">${m}</span>`;
|
|
29
|
+
})
|
|
30
|
+
// Inserted dates stay stored as ISO (so badge/title-stripping regexes keep
|
|
31
|
+
// working — see EDITOR_DATE_REGEX), but we show the human-readable
|
|
32
|
+
// form on hover via title= since rewriting the visible text here would
|
|
33
|
+
// shift it out of alignment with the textarea underneath (breaks caret
|
|
34
|
+
// hit-testing).
|
|
35
|
+
.replace(/\d{4}-\d{2}-\d{2}(?:\.\.\d{4}-\d{2}-\d{2})?/g, (m) => {
|
|
36
|
+
const chip = m.includes("..")
|
|
37
|
+
? formatDateRangeChip(m.split("..")[0], m.split("..")[1])
|
|
38
|
+
: formatDateChip(m);
|
|
39
|
+
return (
|
|
40
|
+
`<span class="relative">` +
|
|
41
|
+
`<span class="invisible">${m}</span>` +
|
|
42
|
+
`<span class="absolute inset-0 flex items-center pointer-events-none overflow-hidden">` +
|
|
43
|
+
`<span class="text-green-400 text-[11px] font-mono bg-green-950/50 border border-green-800/40 rounded px-1 leading-4 whitespace-nowrap">${chip}</span>` +
|
|
44
|
+
`</span>` +
|
|
45
|
+
`</span>`
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Checked task line → dim the whole line + strikethrough the text
|
|
51
|
+
const checkedMatch = /^(\s*-\s+\[x\]\s*)(.+)$/.exec(esc);
|
|
52
|
+
if (checkedMatch) {
|
|
53
|
+
return (
|
|
54
|
+
`<span class="text-zinc-600">${checkedMatch[1]}` +
|
|
55
|
+
`<s>${colorize(checkedMatch[2])}</s></span>`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return colorize(esc);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Render the overlay as pure inline content — no block elements at all. */
|
|
63
|
+
export function EditorOverlay({ content }: { content: string }) {
|
|
64
|
+
const lines = content.split("\n");
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{lines.map((line, i) => (
|
|
68
|
+
<span key={i}>
|
|
69
|
+
<span dangerouslySetInnerHTML={{ __html: highlightLine(line) || " " }} />
|
|
70
|
+
{i < lines.length - 1 ? "\n" : null}
|
|
71
|
+
</span>
|
|
72
|
+
))}
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Collect badge positions: one entry per task line (line index → task). */
|
|
78
|
+
export function getTaskBadgeRows(
|
|
79
|
+
content: string,
|
|
80
|
+
tasks: Task[],
|
|
81
|
+
): { lineIndex: number; task: Task }[] {
|
|
82
|
+
return content.split("\n").flatMap((line, i) => {
|
|
83
|
+
const taskTitle = extractTaskTitleFromLine(line);
|
|
84
|
+
const task = taskTitle ? tasks.find((t) => t.title === taskTitle) : null;
|
|
85
|
+
return task ? [{ lineIndex: i, task }] : [];
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Gutter width in pixels for the task-badge column. */
|
|
90
|
+
export const GUTTER_PX = 20;
|