1import { createEffect, createMemo, createSignal, For, onCleanup, Show } from "solid-js";2import type { VaultEntry } from "../../shared/types";3import { isPasskeyOnly } from "../../shared/types";4import { detectBrowser } from "../../shared/browser";5import { getDisplayDomain } from "../../shared/domain";6import { faviconUrl } from "../../shared/favicon";7import { generateTOTP, parseOtpauthURI } from "../../crypto/totp";8import { sendMessage, triggerPipPulse, triggerRing } from "../App";9import { popupCopy } from "../copy";10import { GeneratorDrawer } from "../components/GeneratorDrawer";11import { NoteEditorInline, Toolbar } from "./NoteEditor";1213type EditableField = "title" | "url" | "username" | "password" | "notes" | "totp" | null;1415interface EntryProps {16 entry: VaultEntry | null;17 1819202122 currentTabUrl?: string;23 onDelete: () => void;24 25 onFieldSaved: () => void | Promise<void>;26 onEscape?: () => void;27}2829export function EntryView(props: EntryProps) {30 const [editingField, setEditingField] = createSignal<EditableField>(null);31 const [draft, setDraft] = createSignal("");32 const [saving, setSaving] = createSignal(false);33 const [showPassword, setShowPassword] = createSignal(false);34 const [showGenerator, setShowGenerator] = createSignal(false);35 const [copied, setCopied] = createSignal<string | null>(null);36 37 38 const [additionalUrlsDraft, setAdditionalUrlsDraft] = createSignal<string[]>([]);39 const [editingTags, setEditingTags] = createSignal(false);40 const [tagsDraft, setTagsDraft] = createSignal<string[]>([]);41 const [tagInput, setTagInput] = createSignal("");42 const [showCardNumber, setShowCardNumber] = createSignal(false);43 const [showCardCvc, setShowCardCvc] = createSignal(false);44 const [totpTick, setTotpTick] = createSignal(0);45 const [confirmDelete, setConfirmDelete] = createSignal(false);46 const [totpHot, setTotpHot] = createSignal(false);47 const [faviconSrc, setFaviconSrc] = createSignal<string | null>(null);48 const [noteEditorEl, setNoteEditorEl] = createSignal<HTMLDivElement | null>(null);49 50 const [showAdvanced, setShowAdvanced] = createSignal(false);51 let lastSavedNote: string | null = null;5253 function noteExec(cmd: string, val?: string) {54 document.execCommand(cmd, false, val);55 noteEditorEl()?.focus();56 }5758 async function saveNoteInline(html: string) {59 const entry = props.entry;60 if (!entry) return;61 const currentStored = entry.notes ?? "";62 if (html === currentStored) return;63 if (lastSavedNote !== null && html === lastSavedNote) return;64 lastSavedNote = html;65 setSaving(true);66 try {67 await sendMessage({68 type: "UPDATE_ENTRY",69 payload: { id: entry.id, patch: { notes: html } },70 });71 triggerRing();72 await props.onFieldSaved();73 } catch {74 lastSavedNote = null;75 } finally {76 setSaving(false);77 }78 }7980 const interval = window.setInterval(() => setTotpTick((n) => n + 1), 1000);81 onCleanup(() => window.clearInterval(interval));8283 const displayDomain = createMemo(() =>84 props.entry?.url ? getDisplayDomain(props.entry.url) : ""85 );8687 createEffect(() => {88 const domain = displayDomain();89 setFaviconSrc(domain ? faviconUrl(domain) : null);90 });9192 93 94 createEffect(() => {95 void props.entry?.id;96 setConfirmDelete(false);97 setEditingField(null);98 setEditingTags(false);99 setShowAdvanced(false);100 });101102 const totpState = createMemo(() => {103 void totpTick();104 if (!props.entry?.totp) return null;105 return generateTOTP(props.entry.totp);106 });107108 let prevTotpCode: string | undefined;109 createEffect(() => {110 const state = totpState();111 if (!state) { prevTotpCode = undefined; return; }112 if (prevTotpCode !== undefined && state.code !== prevTotpCode) {113 setTotpHot(true);114 window.setTimeout(() => setTotpHot(false), 3000);115 }116 prevTotpCode = state.code;117 });118119 const totpProgress = createMemo(() => {120 const state = totpState();121 if (!state) return 0;122 return ((state.remaining - 1) / 29) * 100;123 });124125 createEffect(() => {126 const shell = document.getElementById("hd-shell");127 if (!shell) return;128129 const state = totpState();130 if (!state) {131 delete shell.dataset.totpActive;132 shell.style.removeProperty("--peach-totp-progress");133 return;134 }135136 shell.dataset.totpActive = "true";137 shell.style.setProperty(138 "--peach-totp-progress",139 `${Math.max(0, totpProgress())}%`140 );141142 onCleanup(() => {143 delete shell.dataset.totpActive;144 shell.style.removeProperty("--peach-totp-progress");145 });146 });147148 const titleSizeClass = createMemo(() => {149 const length = props.entry?.title.length ?? 0;150 if (length >= 28) return "peach-entry-name--xxl";151 if (length >= 20) return "peach-entry-name--xl";152 if (length >= 14) return "peach-entry-name--lg";153 return "";154 });155 const useAnimatedTitle = createMemo(() => (props.entry?.title.length ?? 0) <= 13);156157 158159 function startEdit(field: EditableField, value: string) {160 setEditingField(field);161 setDraft(value);162 setShowGenerator(false);163 setConfirmDelete(false);164 if (field === "url") {165 setAdditionalUrlsDraft([...(props.entry?.additionalUrls ?? [])]);166 }167 }168169 170 171 172 function urlMatchesAny(candidate: string, primary: string, others: string[]): boolean {173 const c = candidate.trim();174 if (!c) return true;175 if (primary.trim() === c) return true;176 return others.some((u) => u.trim() === c);177 }178179 function addCurrentSite(url: string) {180 if (!url) return;181 if (!draft().trim()) {182 setDraft(url);183 return;184 }185 if (urlMatchesAny(url, draft(), additionalUrlsDraft())) return;186 setAdditionalUrlsDraft((arr) => [...arr, url]);187 }188189 async function saveField() {190 const field = editingField();191 const entry = props.entry;192 if (!field || !entry) return;193 194 let value = field === "password" ? draft() : draft().trim();195 if (field === "totp" && value.startsWith("otpauth://")) {196 const parsed = parseOtpauthURI(value);197 value = parsed?.secret ?? value;198 }199 if (field === "password" && entry.type !== "note" && !value) {200 return;201 }202 setSaving(true);203 try {204 const patch: Partial<VaultEntry> = { [field]: value };205 if (field === "url") {206 207 patch.additionalUrls = additionalUrlsDraft();208 }209 await sendMessage({210 type: "UPDATE_ENTRY",211 payload: { id: entry.id, patch },212 });213 triggerRing();214 setEditingField(null);215 setShowGenerator(false);216 await props.onFieldSaved();217 } catch {218 219 } finally {220 setSaving(false);221 }222 }223224 function startEditTags() {225 setTagsDraft([...(props.entry?.tags ?? [])]);226 setTagInput("");227 setEditingTags(true);228 }229230 function addTag(value: string) {231 const n = value.toLowerCase().trim();232 if (!n || n.length > 32 || tagsDraft().includes(n) || tagsDraft().length >= 10) return;233 setTagsDraft([...tagsDraft(), n]);234 setTagInput("");235 }236237 async function saveTags() {238 if (tagInput()) addTag(tagInput());239 const entry = props.entry;240 if (!entry) return;241 const next = tagsDraft().length > 0 ? tagsDraft() : undefined;242 setEditingTags(false);243 setSaving(true);244 try {245 await sendMessage({246 type: "UPDATE_ENTRY",247 payload: { id: entry.id, patch: { tags: next } },248 });249 triggerRing();250 await props.onFieldSaved();251 } catch {252 253 } finally {254 setSaving(false);255 }256 }257258 function cancelEdit() {259 setEditingField(null);260 setDraft("");261 setShowGenerator(false);262 }263264 function fieldValue(entry: VaultEntry, field: Exclude<EditableField, null>): string {265 switch (field) {266 case "title":267 return entry.title;268 case "url":269 return entry.url ?? "";270 case "username":271 return entry.username ?? "";272 case "password":273 return entry.password ?? "";274 case "notes":275 return entry.notes ?? "";276 case "totp":277 return entry.totp ?? "";278 }279 }280281 function handleEditorFocusOut(282 field: Exclude<EditableField, null>,283 event: FocusEvent & { currentTarget: HTMLElement; relatedTarget: EventTarget | null }284 ) {285 const nextTarget = event.relatedTarget;286 if (nextTarget instanceof Node && event.currentTarget.contains(nextTarget)) return;287288 const entry = props.entry;289 if (!entry) return;290291 const currentValue = fieldValue(entry, field);292 const nextValue = field === "password" ? draft() : draft().trim();293 if (nextValue === currentValue) {294 cancelEdit();295 }296 }297298 async function savePassword(password: string) {299 const entry = props.entry;300 if (!entry) return;301 setSaving(true);302 try {303 await sendMessage({304 type: "UPDATE_ENTRY",305 payload: { id: entry.id, patch: { password } },306 });307 triggerRing();308 setShowGenerator(false);309 await props.onFieldSaved();310 } catch {311 312 } finally {313 setSaving(false);314 }315 }316317 318319 async function copyField(text: string, label: string, button?: HTMLButtonElement) {320 const ok = await popupCopy(text, label);321 if (ok) {322 const entry = props.entry;323 if (entry?.canary?.webhookUrl) {324 const trigger =325 label === "password"326 ? "password_copied"327 : label === "username"328 ? "username_copied"329 : undefined;330 if (trigger) {331 void sendMessage({332 type: "FIRE_CANARY_PING",333 payload: { webhookUrl: entry.canary.webhookUrl, entryTitle: entry.title, trigger },334 });335 }336 }337 triggerRing();338 triggerPipPulse();339 setCopied(null);340 requestAnimationFrame(() => setCopied(label));341 if (button) {342 button.classList.remove("is-copied", "is-retreat");343 void button.offsetWidth;344 const drain = document.createElement("span");345 drain.className = "peach-copy-drain";346 const bar = document.createElement("span"); bar.className = "peach-copy-drain-bar";347 drain.appendChild(bar);348 button.appendChild(drain);349 window.setTimeout(() => {350 button.classList.remove("is-copied");351 button.classList.add("is-retreat");352 drain.remove();353 window.setTimeout(() => button.classList.remove("is-retreat"), 160);354 }, 1800);355 }356 window.setTimeout(() => setCopied(null), 1800);357 }358 }359360 361362 createEffect(() => {363 if (!props.entry) return;364 const handler = (e: KeyboardEvent) => {365 const inInput = e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement || (e.target as HTMLElement).isContentEditable;366 if (inInput) return;367 switch (e.key) {368 case "c": e.preventDefault();369 if (props.entry?.password) void copyField(props.entry.password, "password"); break;370 case "u": e.preventDefault();371 if (props.entry?.username) void copyField(props.entry.username, "username"); break;372 case "Escape": e.preventDefault(); props.onEscape?.(); break;373 }374 };375 window.addEventListener("keydown", handler);376 onCleanup(() => window.removeEventListener("keydown", handler));377 });378379 380381 function autoFocus(el: HTMLInputElement | HTMLTextAreaElement) {382 requestAnimationFrame(() => { el.focus(); el.select?.(); });383 }384385 function onEditKeyDown(e: KeyboardEvent) {386 if (e.key === "Enter" && !(e.target instanceof HTMLTextAreaElement)) {387 e.preventDefault();388 void saveField();389 }390 if (e.key === "Escape") { e.preventDefault(); cancelEdit(); }391 }392393 return (394 <>395 <div396 class="peach-ghost"397 aria-hidden="true"398 style="position:absolute;top:30px;left:12px;right:0;font-family:'Cormorant Garamond',Georgia,serif;font-size:150px;font-style:italic;font-weight:400;color:var(--t0);opacity:0.03;pointer-events:none;line-height:1;overflow:hidden;white-space:nowrap;z-index:0;"399 >400 {props.entry?.title || "empty"}401 </div>402403 <div class="peach-stage" style="position:relative;">404 <Show when={props.entry} fallback={<EmptyVaultState />}>405 {(entry) => (406 <>407 {}408 <Show when={entry().type !== "note" && entry().type !== "card" && (entry().breach ?? 0) > 0}>409 <div class="peach-breach-badge">410 <svg width="10" height="10" viewBox="0 0 12 12" fill="none" stroke="var(--breach)" stroke-width="1.5" stroke-linecap="round">411 <path d="M6 1L11 10H1L6 1z" />412 <line x1="6" y1="5" x2="6" y2="7.5" />413 <circle cx="6" cy="9" r="0.5" fill="var(--breach)" stroke="none" />414 </svg>415 <span style="flex:1">found in a known data breach</span>416 <button417 class="peach-btn peach-btn--sm peach-btn--accent peach-breach-action"418 onClick={() => { startEdit("password", entry().password ?? ""); setShowGenerator(true); }}419 >420 Change password421 </button>422 </div>423 </Show>424425 {}426 <div class="peach-entry-header">427 <div class="peach-entry-header-name">428 <Show429 when={editingField() === "title"}430 fallback={431 <button432 class="peach-entry-name-button"433 title="Click to edit title"434 onClick={() => startEdit("title", entry().title)}435 >436 <h1 class={`peach-entry-name ${titleSizeClass()}`} aria-label={entry().title}>437 <span class="peach-entry-name-text">438 <Show439 when={useAnimatedTitle()}440 fallback={entry().title}441 >442 <For each={entry().title.split("")}>443 {(ch, i) => (444 <span class="peach-entry-name-char" style={`--char-index:${i()}`}>445 {ch === " " ? "\u00A0" : ch}446 </span>447 )}448 </For>449 </Show>450 </span>451 </h1>452 </button>453 }454 >455 <div456 class="peach-inline-title-wrap"457 onFocusOut={(event) => handleEditorFocusOut("title", event)}458 >459 <input460 class="peach-inline-title-input"461 value={draft()}462 onInput={(e) => setDraft(e.currentTarget.value)}463 onKeyDown={onEditKeyDown}464 ref={autoFocus}465 disabled={saving()}466 />467 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />468 </div>469 </Show>470 </div>471472 {}473 <Show when={editingField() !== "title"}>474 <Show475 when={confirmDelete()}476 fallback={477 <button478 class="peach-entry-trash-btn"479 onClick={() => setConfirmDelete(true)}480 aria-label="Move to trash"481 title="Delete entry"482 >483 <svg width="12" height="13" viewBox="0 0 12 13" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">484 <path d="M1 3h10M4 3V2h4v1M2 3l.7 8.5a1 1 0 0 0 1 .9h4.6a1 1 0 0 0 1-.9L10 3" />485 <path d="M4.5 6l.3 3.5M7.5 6l-.3 3.5" />486 </svg>487 </button>488 }489 >490 <div class="peach-entry-trash-confirm">491 <span class="peach-entry-trash-confirm-label">trash?</span>492 <button493 class="peach-btn peach-btn--sm peach-btn--danger"494 style="font-size:10px;padding:2px 8px;min-height:22px;"495 onClick={() => { setConfirmDelete(false); props.onDelete(); }}496 >497 yes498 </button>499 <button500 class="peach-btn peach-btn--ghost peach-btn--sm"501 style="font-size:10px;padding:2px 8px;min-height:22px;"502 onClick={() => setConfirmDelete(false)}503 >504 no505 </button>506 </div>507 </Show>508 </Show>509 </div>510511 {}512 <Show when={entry().type !== "note" && entry().type !== "card"}>513 <div class="peach-domain" style="position:relative;z-index:1;">514 <Show515 when={editingField() === "url"}516 fallback={517 <div518 class="peach-domain-row peach-inline-clickable"519 title="Click to edit URL"520 onClick={() => startEdit("url", entry().url ?? "")}521 >522 <Show when={faviconSrc()}>523 <img524 src={faviconSrc()!}525 width="16"526 height="16"527 alt=""528 style="border-radius:3px;margin-right:5px;flex-shrink:0;"529 onError={(e) => { (e.currentTarget as HTMLImageElement).style.display = "none"; }}530 />531 </Show>532 <span class="peach-domain-value">533 {displayDomain() || (entry().url ? entry().url : "add a website url")}534 </span>535 <span class="peach-inline-edit-hint">edit</span>536 </div>537 }538 >539 <div540 class="peach-inline-field-wrap peach-inline-field-wrap--url"541 onFocusOut={(event) => handleEditorFocusOut("url", event)}542 >543 <div class="peach-inline-field-row">544 <input545 class="peach-inline-input"546 type="url"547 placeholder="https://"548 value={draft()}549 onInput={(e) => setDraft(e.currentTarget.value)}550 onKeyDown={onEditKeyDown}551 ref={autoFocus}552 disabled={saving()}553 />554 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />555 </div>556 <div class="peach-additional-urls">557 <Show when={additionalUrlsDraft().length > 0}>558 <span class="peach-label peach-additional-urls-label">also matches</span>559 </Show>560 <For each={additionalUrlsDraft()}>561 {(value, i) => (562 <div class="peach-additional-url-row">563 <input564 class="peach-inline-input"565 type="url"566 placeholder="https://"567 value={value}568 onInput={(e) => setAdditionalUrlsDraft((arr) => {569 const next = [...arr];570 next[i()] = e.currentTarget.value;571 return next;572 })}573 disabled={saving()}574 />575 <button576 class="peach-additional-url-remove"577 type="button"578 aria-label="Remove URL"579 onMouseDown={(e) => e.preventDefault()}580 onClick={() => setAdditionalUrlsDraft((arr) => arr.filter((_, idx) => idx !== i()))}581 disabled={saving()}582 >×</button>583 </div>584 )}585 </For>586 <button587 class="peach-add-field-link peach-additional-urls-add"588 type="button"589 onMouseDown={(e) => e.preventDefault()}590 onClick={() => setAdditionalUrlsDraft((arr) => [...arr, ""])}591 disabled={saving()}592 >593 + add another url594 </button>595 <Show when={props.currentTabUrl && !urlMatchesAny(props.currentTabUrl!, draft(), additionalUrlsDraft())}>596 <button597 class="peach-add-field-link peach-additional-urls-add peach-additional-urls-add-current"598 type="button"599 title={props.currentTabUrl}600 onMouseDown={(e) => e.preventDefault()}601 onClick={() => addCurrentSite(props.currentTabUrl!)}602 disabled={saving()}603 >604 + add current site605 </button>606 </Show>607 </div>608 </div>609 </Show>610 </div>611 </Show>612613 {}614 <Show when={!editingTags() && entry().tags && entry().tags!.length > 0}>615 <div616 style="display:flex;flex-wrap:wrap;gap:5px;margin:2px 0;position:relative;z-index:1;cursor:pointer;"617 onClick={startEditTags}618 title="Click to edit tags"619 >620 <For each={entry().tags!}>621 {(tag) => <span class="peach-tag-chip" style="font-size:10px;padding:2px 8px;">{tag}</span>}622 </For>623 </div>624 </Show>625626 {}627 <Show when={entry().type === "note"}>628 <div class="peach-entry-note-toolbar-row">629 <Toolbar exec={noteExec} class="peach-note-toolbar-inline" />630 </div>631 <section class="peach-fields peach-note-body" style="position:relative;z-index:1;">632 <NoteEditorInline633 entryKey={entry().id}634 initialContent={entry().notes ?? ""}635 onReady={(el) => { setNoteEditorEl(el); lastSavedNote = null; }}636 onBlur={saveNoteInline}637 autoFocus={false}638 />639 </section>640 </Show>641642 {}643 <Show when={entry().type === "card"}>644 <section class="peach-fields" style="position:relative;z-index:1;">645 {}646 <Show when={entry().last4}>647 <div class="peach-field-card" style="padding-bottom:4px;">648 <span class="peach-label">649 <Show when={entry().network && entry().network !== "unknown"}>650 <span class="peach-card-network-badge" style="margin-left:0;margin-right:6px;">{entry().network}</span>651 </Show>652 {entry().cardNickname || `•••• ${entry().last4}`}653 </span>654 </div>655 </Show>656657 {}658 <div class="peach-field-card">659 <span class="peach-label">cardholder name</span>660 <div class="peach-field-value-row">661 <span class="peach-field-value">{entry().cardholderName || "—"}</span>662 <Show when={entry().cardholderName}>663 <button664 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "cardholderName" ? "is-copied" : ""}`}665 onClick={(e) => void copyField(entry().cardholderName!, "cardholderName", e.currentTarget as HTMLButtonElement)}666 aria-label="Copy cardholder name"667 >668 <CopyGlyph /><span class="peach-copy-sheen" />669 </button>670 </Show>671 </div>672 </div>673674 {}675 <div class="peach-field-card">676 <span class="peach-label">card number</span>677 <div class="peach-field-value-row">678 <span class={`peach-field-value peach-card-number`}>679 <Show when={showCardNumber()} fallback={680 <span>{`•••• •••• •••• ${entry().last4 ?? "••••"}`}</span>681 }>682 <span>{entry().cardNumber ?? ""}</span>683 </Show>684 </span>685 <div class="peach-field-actions">686 <button687 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"688 onClick={() => setShowCardNumber(!showCardNumber())}689 aria-label={showCardNumber() ? "Hide card number" : "Reveal card number"}690 >691 <Show when={showCardNumber()} fallback={<EyeOpenGlyph />}>692 <EyeClosedGlyph />693 </Show>694 </button>695 <Show when={entry().cardNumber}>696 <button697 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "cardNumber" ? "is-copied" : ""}`}698 onClick={(e) => {699 const cardNum = entry().cardNumber!;700 if (entry().canary?.webhookUrl) {701 void sendMessage({702 type: "FIRE_CANARY_PING",703 payload: { webhookUrl: entry().canary!.webhookUrl, entryTitle: entry().title, trigger: "password_copied" },704 });705 }706 void copyField(cardNum, "cardNumber", e.currentTarget as HTMLButtonElement);707 }}708 aria-label="Copy card number"709 >710 <CopyGlyph /><span class="peach-copy-sheen" />711 </button>712 </Show>713 </div>714 </div>715 </div>716717 {}718 <Show when={entry().expMonth || entry().expYear}>719 <div class="peach-field-card">720 <span class="peach-label">expiry</span>721 <div class="peach-field-value-row">722 <span class="peach-field-value">{entry().expMonth} / {entry().expYear}</span>723 <button724 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "expiry" ? "is-copied" : ""}`}725 onClick={(e) => void copyField(`${entry().expMonth}/${entry().expYear}`, "expiry", e.currentTarget as HTMLButtonElement)}726 aria-label="Copy expiry"727 >728 <CopyGlyph /><span class="peach-copy-sheen" />729 </button>730 </div>731 </div>732 </Show>733734 {}735 <Show when={entry().cvc}>736 <div class="peach-field-card">737 <span class="peach-label">CVC</span>738 <div class="peach-field-value-row">739 <span class="peach-field-value">740 <Show when={showCardCvc()} fallback={<span class="peach-password-mask">•••</span>}>741 <span>{entry().cvc}</span>742 </Show>743 </span>744 <div class="peach-field-actions">745 <button746 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"747 onClick={() => setShowCardCvc(!showCardCvc())}748 aria-label={showCardCvc() ? "Hide CVC" : "Show CVC"}749 >750 <Show when={showCardCvc()} fallback={<EyeOpenGlyph />}>751 <EyeClosedGlyph />752 </Show>753 </button>754 <button755 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "cvc" ? "is-copied" : ""}`}756 onClick={(e) => void copyField(entry().cvc!, "cvc", e.currentTarget as HTMLButtonElement)}757 aria-label="Copy CVC"758 >759 <CopyGlyph /><span class="peach-copy-sheen" />760 </button>761 </div>762 </div>763 </div>764 </Show>765 </section>766 </Show>767768 {}769 <Show when={entry().type !== "note" && entry().type !== "card" && !isPasskeyOnly(entry())}>770 <section class="peach-fields" style="position:relative;z-index:1;">771772 {}773 <div class="peach-field-card" classList={{ "is-editing": editingField() === "username" }}>774 <span class="peach-label">username</span>775 <Show776 when={editingField() === "username"}777 fallback={778 <div class="peach-field-value-row">779 <span780 class="peach-field-value peach-inline-clickable"781 title="Click to edit"782 onClick={() => startEdit("username", entry().username ?? "")}783 >784 {entry().username || <span style="color:var(--t2);font-style:italic;">click to add username</span>}785 </span>786 <Show when={entry().username}>787 <button788 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "username" ? "is-copied" : ""}`}789 onClick={(e) => void copyField(entry().username!, "username", e.currentTarget as HTMLButtonElement)}790 aria-label="Copy username"791 >792 <CopyGlyph /><span class="peach-copy-sheen" />793 </button>794 </Show>795 </div>796 }797 >798 <div799 class="peach-inline-field-wrap"800 onFocusOut={(event) => handleEditorFocusOut("username", event)}801 >802 <input803 class="peach-inline-input"804 value={draft()}805 onInput={(e) => setDraft(e.currentTarget.value)}806 onKeyDown={onEditKeyDown}807 ref={autoFocus}808 disabled={saving()}809 autocomplete="off"810 />811 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />812 </div>813 </Show>814 </div>815816 {}817 <div class="peach-field-card" classList={{ "is-editing": editingField() === "password" }}>818 <span class="peach-label">password</span>819 <Show820 when={editingField() === "password"}821 fallback={822 <div class="peach-field-value-row">823 <span824 class="peach-password-value"825 classList={{ "is-revealed": showPassword(), "is-breached": (entry().breach ?? 0) > 0 }}826 style="cursor:pointer;"827 title="Click to edit password"828 onClick={() => startEdit("password", entry().password ?? "")}829 >830 <Show831 when={showPassword()}832 fallback={<span class="peach-password-mask" aria-label="password hidden">••••••••••••••</span>}833 >834 <span class="peach-password-text">{entry().password ?? ""}</span>835 </Show>836 </span>837 <div class="peach-field-actions">838 <button839 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"840 onClick={() => setShowPassword(!showPassword())}841 aria-label="Reveal password"842 >843 <Show when={showPassword()} fallback={<EyeOpenGlyph />}>844 <EyeClosedGlyph />845 </Show>846 </button>847 <button848 class={`peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-copy-btn ${copied() === "password" ? "is-copied" : ""}`}849 onClick={(e) => { if (entry().password) void copyField(entry().password!, "password", e.currentTarget as HTMLButtonElement); }}850 aria-label="Copy password"851 >852 <CopyGlyph /><span class="peach-copy-sheen" />853 </button>854 </div>855 </div>856 }857 >858 {}859 <div860 class="peach-inline-field-wrap"861 onFocusOut={(event) => handleEditorFocusOut("password", event)}862 >863 <div class="peach-password-edit-row">864 <input865 class="peach-inline-input"866 type={showPassword() ? "text" : "password"}867 placeholder="paste or type a password"868 value={draft()}869 onInput={(e) => setDraft(e.currentTarget.value)}870 onKeyDown={(e) => {871 if (e.key === "Enter") { e.preventDefault(); void saveField(); }872 if (e.key === "Escape") { e.preventDefault(); cancelEdit(); }873 }}874 ref={autoFocus}875 disabled={saving()}876 autocomplete="new-password"877 />878 <button879 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"880 type="button"881 onClick={() => setShowPassword(!showPassword())}882 aria-label={showPassword() ? "Hide" : "Show"}883 >884 <Show when={showPassword()} fallback={<EyeOpenGlyph />}>885 <EyeClosedGlyph />886 </Show>887 </button>888 </div>889 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />890 <button891 class="peach-generate-toggle-link"892 type="button"893 onClick={() => setShowGenerator(!showGenerator())}894 >895 <svg width="10" height="10" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round">896 <path d="M11 2.5A5.5 5.5 0 1 0 12.5 7" />897 <path d="M9.5 2.5H11V1" />898 </svg>899 {showGenerator() ? "hide generator" : "generate"}900 </button>901 <Show when={showGenerator()}>902 <GeneratorDrawer903 open={true}904 compact={true}905 onUse={(pw) => { setDraft(pw); setShowGenerator(false); }}906 />907 </Show>908 </div>909 </Show>910 </div>911912 </section>913 </Show>914915 {}916 <Show when={entry().type !== "note" && entry().type !== "card"}>917 <Show918 when={entry().notes || editingField() === "notes"}919 fallback={920 <button921 class="peach-add-field-link peach-entry-add-link"922 onClick={() => startEdit("notes", "")}923 >924 + notes925 </button>926 }927 >928 <div style="position:relative;z-index:1;margin-top:6px;">929 <span class="peach-label" style="display:block;margin-bottom:4px;">notes</span>930 <Show931 when={editingField() === "notes"}932 fallback={933 <div934 class="peach-note-content peach-inline-clickable"935 style="cursor:text;white-space:pre-wrap;"936 onClick={() => startEdit("notes", entry().notes ?? "")}937 >938 {entry().notes}939 </div>940 }941 >942 <div943 class="peach-inline-field-wrap"944 onFocusOut={(event) => handleEditorFocusOut("notes", event)}945 >946 <textarea947 class="peach-inline-textarea"948 value={draft()}949 onInput={(e) => setDraft(e.currentTarget.value)}950 onKeyDown={(e) => { if (e.key === "Escape") { e.preventDefault(); cancelEdit(); } }}951 ref={(el) => requestAnimationFrame(() => el?.focus())}952 rows={4}953 disabled={saving()}954 />955 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />956 </div>957 </Show>958 </div>959 </Show>960 </Show>961962 {}963 <Show964 when={editingTags()}965 fallback={966 <Show when={!entry().tags || entry().tags!.length === 0}>967 <button968 class="peach-add-field-link peach-entry-add-link"969 onClick={startEditTags}970 >971 + tags972 </button>973 </Show>974 }975 >976 <div977 class="peach-inline-tag-editor"978 onFocusOut={(e) => {979 const next = e.relatedTarget;980 if (next instanceof Node && e.currentTarget.contains(next)) return;981 void saveTags();982 }}983 >984 <span class="peach-label">tags</span>985 <div class="peach-tag-input-wrap">986 <For each={tagsDraft()}>987 {(tag) => (988 <span class="peach-tag-chip">989 {tag}990 <button991 class="peach-tag-chip-remove"992 onMouseDown={(e) => e.preventDefault()}993 onClick={() => setTagsDraft(tagsDraft().filter(t => t !== tag))}994 aria-label={`Remove ${tag}`}995 >×</button>996 </span>997 )}998 </For>999 <input1000 class="peach-tag-input"1001 placeholder={tagsDraft().length === 0 ? "type and press Enter…" : ""}1002 value={tagInput()}1003 onInput={(e) => setTagInput(e.currentTarget.value)}1004 onKeyDown={(e) => {1005 if (e.key === "Enter" || e.key === ",") {1006 e.preventDefault();1007 addTag(tagInput());1008 } else if (e.key === "Backspace" && !tagInput() && tagsDraft().length > 0) {1009 setTagsDraft(tagsDraft().slice(0, -1));1010 } else if (e.key === "Escape") {1011 e.preventDefault();1012 setEditingTags(false);1013 setTagInput("");1014 }1015 }}1016 ref={(el) => requestAnimationFrame(() => el?.focus())}1017 style="flex:1;min-width:80px;background:transparent;border:none;outline:none;color:var(--t1);font-size:12px;padding:2px;"1018 />1019 </div>1020 </div>1021 </Show>10221023 {}1024 <Show when={entry().type === "login" && !isPasskeyOnly(entry())}>1025 <Show1026 when={totpState() || editingField() === "totp"}1027 fallback={1028 <button1029 class="peach-add-field-link peach-entry-add-link"1030 onClick={() => startEdit("totp", "")}1031 >1032 + 2FA1033 </button>1034 }1035 >1036 <section class="peach-totp-band">1037 <Show1038 when={editingField() === "totp"}1039 fallback={1040 <Show when={totpState()}>1041 {(state) => (1042 <>1043 <div1044 class="peach-totp-main"1045 onClick={() => void copyField(state().code.replace(" ", ""), "totp")}1046 onDblClick={() => startEdit("totp", entry().totp ?? "")}1047 title="Click to copy · double-click to edit"1048 >1049 <span class="peach-label">2-factor</span>1050 <div class="peach-totp-code-row">1051 <p class={`peach-totp-code${totpHot() ? " is-hot" : ""}${copied() === "totp" ? " is-copied" : ""}`}>1052 <span class="peach-totp-code-text">1053 {state().code.slice(0, 3)} {state().code.slice(3)}1054 </span>1055 </p>1056 </div>1057 </div>1058 <div class="peach-totp-meta">1059 <span class="peach-label">expires</span>1060 <div class="peach-totp-countdown">{state().remaining}s</div>1061 <svg class="peach-totp-ring" width="44" height="44" viewBox="0 0 44 44">1062 <circle cx="22" cy="22" r="17" class="peach-totp-ring-track" />1063 <circle cx="22" cy="22" r="17" class="peach-totp-ring-progress"1064 stroke-dasharray="106.8"1065 stroke-dashoffset={(1 - state().remaining / 30) * 106.8}1066 />1067 </svg>1068 </div>1069 </>1070 )}1071 </Show>1072 }1073 >1074 <div1075 class="peach-inline-field-wrap peach-inline-field-wrap--totp"1076 onFocusOut={(event) => handleEditorFocusOut("totp", event)}1077 >1078 <span class="peach-label">2-factor</span>1079 <input1080 class="peach-inline-input"1081 value={draft()}1082 onInput={(e) => setDraft(e.currentTarget.value)}1083 onKeyDown={onEditKeyDown}1084 ref={autoFocus}1085 disabled={saving()}1086 placeholder="otpauth://... or base32 secret"1087 autocomplete="off"1088 />1089 <InlineSaveCancelRow onSave={saveField} onCancel={cancelEdit} saving={saving()} />1090 </div>1091 </Show>1092 </section>1093 </Show>1094 </Show>10951096 {}1097 <Show when={entry().type === "login"}>1098 <Show1099 when={showAdvanced()}1100 fallback={1101 <button1102 class="peach-add-field-link peach-entry-add-link"1103 onClick={() => setShowAdvanced(true)}1104 >1105 + Advanced1106 </button>1107 }1108 >1109 <Show when={!isPasskeyOnly(entry())}>1110 <CanarySection entry={entry()} onSaved={props.onFieldSaved} />1111 </Show>11121113 <Show when={entry().passkey}>1114 {(passkey) => {1115 const currentBrowser = detectBrowser();1116 const crossBrowser =1117 passkey().browser &&1118 currentBrowser !== "unknown" &&1119 passkey().browser !== currentBrowser;1120 const algorithmLabel =1121 passkey().algorithm === -8 ? "EdDSA (Ed25519)" : "ES256 (P-256)";1122 const formatDate = (ts?: number) =>1123 ts ? new Date(ts).toLocaleDateString() : "Never";1124 return (1125 <section1126 class="peach-fields peach-passkey-section"1127 style="position:relative;z-index:1;margin-top:6px;"1128 >1129 <div class="peach-field-card">1130 <span class="peach-label">passkey · {passkey().rpId}</span>1131 <div class="peach-field-value-row">1132 <span class="peach-field-value">{passkey().userName}</span>1133 <span class="peach-passkey-badge">passkey</span>1134 </div>1135 </div>11361137 <div class="peach-field-card">1138 <span class="peach-label">algorithm</span>1139 <div class="peach-field-value-row">1140 <span class="peach-field-value">{algorithmLabel}</span>1141 </div>1142 </div>11431144 <div class="peach-field-card">1145 <span class="peach-label">activity</span>1146 <div class="peach-field-value-row peach-passkey-activity">1147 <span class="peach-field-value">1148 used {passkey().signCount} time{passkey().signCount === 1 ? "" : "s"}1149 </span>1150 <span class="peach-passkey-meta">1151 created {formatDate(passkey().createdAt)}1152 </span>1153 <span class="peach-passkey-meta">1154 last used {formatDate(passkey().lastUsedAt)}1155 </span>1156 </div>1157 </div>11581159 <Show when={crossBrowser}>1160 <div class="peach-info-notice peach-info-notice--warn">1161 {`This passkey was created on ${1162 passkey().browser === "chrome" ? "Chrome" : "Firefox"1163 }. To use it on ${1164 currentBrowser === "chrome" ? "Chrome" : "Firefox"1165 }, re-register it on this device.`}1166 </div>1167 </Show>11681169 <div class="peach-info-notice">1170 {passkey().browser === "firefox"1171 ? "This passkey is held by your platform authenticator. Peach stores only the metadata."1172 : "The private key is stored encrypted in your Peach vault and is never shown in the UI."}1173 </div>11741175 <button1176 class="peach-add-field-link peach-entry-add-link"1177 style="color:rgba(220,38,38,0.7);"1178 onClick={async () => {1179 const id = entry().id;1180 await sendMessage({1181 type: "UPDATE_ENTRY",1182 payload: { id, patch: { passkey: undefined } },1183 });1184 await props.onFieldSaved();1185 }}1186 >1187 − remove passkey1188 </button>1189 </section>1190 );1191 }}1192 </Show>1193 </Show>1194 </Show>11951196 {}1197 <div style="height:4px;" />1198 </>1199 )}1200 </Show>1201 </div>12021203 </>1204 );1205}1206120712081209function InlineSaveCancelRow(props: { onSave: () => void; onCancel: () => void; saving: boolean }) {1210 return (1211 <div class="peach-inline-actions">1212 <button1213 class="peach-inline-save-btn"1214 onClick={props.onSave}1215 disabled={props.saving}1216 aria-label="Save"1217 title="Save (Enter)"1218 >1219 <svg width="11" height="9" viewBox="0 0 11 9" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">1220 <path d="M1 4.5L4 7.5L10 1.5" />1221 </svg>1222 </button>1223 <button1224 class="peach-inline-cancel-btn"1225 onClick={props.onCancel}1226 disabled={props.saving}1227 aria-label="Cancel"1228 title="Cancel (Esc)"1229 >1230 <svg width="9" height="9" viewBox="0 0 9 9" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round">1231 <path d="M1 1L8 8M8 1L1 8" />1232 </svg>1233 </button>1234 </div>1235 );1236}12371238function EmptyVaultState() {1239 return (1240 <>1241 <div class="peach-entry-name-wrap" style="position:relative;z-index:1;">1242 <div class="peach-entry-name">1243 <span class="peach-entry-name-text">1244 <span class="peach-entry-name-char" style="--char-index:0">e</span>1245 <span class="peach-entry-name-char" style="--char-index:1">m</span>1246 <span class="peach-entry-name-char" style="--char-index:2">p</span>1247 <span class="peach-entry-name-char" style="--char-index:3">t</span>1248 <span class="peach-entry-name-char" style="--char-index:4">y</span>1249 </span>1250 </div>1251 </div>1252 <div class="peach-empty-copy">1253 <span class="peach-label">vault</span>1254 <p>Your vault is ready for its first entry.</p>1255 </div>1256 </>1257 );1258}12591260function CopyGlyph() {1261 return (1262 <span class="peach-copy-icon">1263 <svg class="peach-copy-icon-svg" width="12" height="12" viewBox="0 0 14 14" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">1264 <rect x="4" y="4" width="8" height="9" rx="1.5" />1265 <path d="M10 4V2.5A1.5 1.5 0 0 0 8.5 1h-6A1.5 1.5 0 0 0 1 2.5v7A1.5 1.5 0 0 0 2.5 11H4" />1266 </svg>1267 </span>1268 );1269}12701271function EyeClosedGlyph() {1272 return (1273 <svg width="14" height="10" viewBox="0 0 14 10" fill="none" stroke="currentColor" stroke-width="0.9" stroke-linecap="round">1274 <path d="M1 2C3 4.5 5 6 7 6C9 6 11 4.5 13 2" />1275 <path d="M3.5 5.5L2.5 7.5" />1276 <path d="M7 6.5V8.5" />1277 <path d="M10.5 5.5L11.5 7.5" />1278 </svg>1279 );1280}12811282function EyeOpenGlyph() {1283 return (1284 <svg width="14" height="10" viewBox="0 0 14 10" fill="none" stroke="currentColor" stroke-width="0.9" stroke-linecap="round">1285 <path d="M1 5C1 5 2.8 1 7 1C11.2 1 13 5 13 5C13 5 11.2 9 7 9C2.8 9 1 5 1 5Z" />1286 <circle cx="7" cy="5" r="1.75" />1287 </svg>1288 );1289}12901291function ChevronGlyph(props: { open: boolean }) {1292 return (1293 <svg1294 width="8"1295 height="8"1296 viewBox="0 0 8 8"1297 fill="none"1298 stroke="currentColor"1299 stroke-width="1.3"1300 stroke-linecap="round"1301 stroke-linejoin="round"1302 style={`transform: rotate(${props.open ? 90 : 0}deg); transition: transform 160ms ease;`}1303 >1304 <path d="M2 1L6 4L2 7" />1305 </svg>1306 );1307}13081309function CanarySection(props: { entry: VaultEntry; onSaved: () => void | Promise<void> }) {1310 const [enabled, setEnabled] = createSignal(Boolean(props.entry.canary));1311 const [webhookUrl, setWebhookUrl] = createSignal(props.entry.canary?.webhookUrl ?? "");1312 const [label, setLabel] = createSignal(props.entry.canary?.label ?? "");1313 const [testResult, setTestResult] = createSignal<string | null>(null);1314 const [testing, setTesting] = createSignal(false);13151316 async function save() {1317 const url = webhookUrl().trim();1318 const nextLabel = label().trim() || undefined;1319 const canary = enabled() && url1320 ? {1321 webhookUrl: url,1322 label: nextLabel,1323 lastPinged: props.entry.canary?.lastPinged,1324 pingCount: props.entry.canary?.pingCount,1325 }1326 : undefined;1327 await sendMessage({1328 type: "UPDATE_ENTRY",1329 payload: { id: props.entry.id, patch: { canary } },1330 });1331 await props.onSaved();1332 }13331334 async function testPing() {1335 const url = webhookUrl().trim();1336 if (!url) return;1337 setTesting(true);1338 setTestResult(null);1339 const res = await sendMessage({1340 type: "FIRE_CANARY_PING",1341 payload: { webhookUrl: url, entryTitle: props.entry.title, trigger: "test" },1342 }) as { ok: boolean; error?: string };1343 setTestResult(res.ok ? "sent ✓" : `failed — ${res.error ?? "check URL"}`);1344 setTesting(false);1345 }13461347 return (1348 <div class="peach-canary-section">1349 <div class="peach-field-value-row">1350 <span class="peach-field-value" style="font-size:12px;">canary alert</span>1351 <button1352 class={`peach-toggle ${enabled() ? "is-on" : ""}`}1353 onClick={() => { setEnabled(!enabled()); void save(); }}1354 aria-label="Toggle canary"1355 >1356 <span class="peach-toggle-knob" />1357 </button>1358 </div>1359 <p style="font-size:10px;color:var(--peach-t2);margin:4px 0 0;line-height:1.5;">1360 Fires a silent webhook when this entry's password or username is copied. Great for honeypot credentials.1361 </p>1362 <Show when={enabled()}>1363 <div class="peach-inline-field-wrap" style="margin-top:8px;">1364 <input1365 class="peach-inline-input"1366 placeholder="https://hooks.zapier.com/..."1367 value={webhookUrl()}1368 onInput={(e) => setWebhookUrl(e.currentTarget.value)}1369 onBlur={() => void save()}1370 />1371 <input1372 class="peach-inline-input"1373 placeholder="label (optional, e.g. AWS decoy)"1374 value={label()}1375 onInput={(e) => setLabel(e.currentTarget.value)}1376 onBlur={() => void save()}1377 />1378 <div style="display:flex;align-items:center;gap:8px;margin-top:4px;">1379 <button1380 class="peach-btn peach-btn--ghost peach-btn--sm"1381 onClick={() => void testPing()}1382 disabled={testing() || !webhookUrl().trim()}1383 >1384 {testing() ? "sending..." : "test ping"}1385 </button>1386 <Show when={testResult()}>1387 <span style="font-size:10px;color:var(--peach-t2);font-family:var(--font-mono);">{testResult()}</span>1388 </Show>1389 </div>1390 <Show when={props.entry.canary?.lastPinged}>1391 <p style="font-size:10px;color:var(--peach-t2);margin-top:4px;">1392 Last triggered: {new Date(props.entry.canary!.lastPinged!).toLocaleDateString()}1393 {" · "}{props.entry.canary?.pingCount ?? 0} total alerts1394 </p>1395 </Show>1396 </div>1397 </Show>1398 </div>1399 );1400}