Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(popup): refine UI layout, animated controls, and form ergonomics (#4541)

Shahzeb Parkarad3db4e8c56b
diff --git a/packages/chrome-plugin/app.css b/packages/chrome-plugin/app.css
index ff98f77b3..06087e5cc 100644
--- a/packages/chrome-plugin/app.css
+++ b/packages/chrome-plugin/app.css
@@ -77,7 +77,7 @@ a {
}
#app {
- @apply min-h-screen bg-white text-black dark:bg-black dark:text-white transition-colors duration-150;
+ @apply bg-white text-black dark:bg-black dark:text-white transition-colors duration-150;
font-family:
Atkinson Hyperlegible,
diff --git a/packages/chrome-plugin/src/options/Options.svelte b/packages/chrome-plugin/src/options/Options.svelte
index 8cd5dbc42..a42af64e7 100644
--- a/packages/chrome-plugin/src/options/Options.svelte
+++ b/packages/chrome-plugin/src/options/Options.svelte
@@ -6,12 +6,15 @@ import {
type StructuredLintConfig,
type StructuredLintSetting,
} from 'harper.js';
+import { tick } from 'svelte';
import logo from '/logo.png';
import ProtocolClient from '../ProtocolClient';
import type { Hotkey, Modifier, WeirpackMeta } from '../protocol';
import { ActivationKey } from '../protocol';
import StructuredRuleSettings from './StructuredRuleSettings.svelte';
+let loaded = $state(false);
+
let lintConfig: LintConfig = $state({});
let structuredLintConfig: StructuredLintConfig = $state({ settings: [] });
let lintDescriptions: Record<string, string> = $state({});
@@ -25,85 +28,97 @@ let delayLoaded = $state(false);
let defaultEnabled = $state(false);
let activationKey: ActivationKey = $state(ActivationKey.Off);
let userDict = $state('');
-let modifyHotkeyButton: Button;
-let hotkey: Hotkey = $state({ modifiers: ['Ctrl'], key: 'e' });
+let hotkey: Hotkey = $state({ modifiers: ['Ctrl'], key: 'E' });
+let buttonText = $state('');
let anyRulesEnabled = $derived(Object.values(lintConfig ?? {}).some((value) => value !== false));
+let totalRules = $derived(Object.keys(lintConfig ?? {}).length);
+let customizedRules = $derived(
+ Object.values(lintConfig ?? {}).filter((value) => value !== null && value !== undefined).length,
+);
let weirpacks: WeirpackMeta[] = $state([]);
let weirpackBusy = $state(false);
let weirpackError = $state('');
+let fileInputRef: HTMLInputElement | undefined = $state();
+/** Announced to screen readers through a polite live region. */
+let statusMessage = $state('');
$effect(() => {
+ if (!loaded) return;
ProtocolClient.setLintConfig($state.snapshot(lintConfig));
});
$effect(() => {
+ if (!loaded) return;
ProtocolClient.setDialect(dialect);
});
$effect(() => {
- if (delayLoaded) {
- ProtocolClient.setDelay(delay);
- }
+ if (!loaded || !delayLoaded) return;
+ ProtocolClient.setDelay(delay);
});
$effect(() => {
+ if (!loaded) return;
ProtocolClient.setDefaultEnabled(defaultEnabled);
});
$effect(() => {
+ if (!loaded) return;
ProtocolClient.setActivationKey(activationKey);
});
$effect(() => {
+ if (!loaded) return;
ProtocolClient.setUserDictionary(stringToDict(userDict));
});
+// Load all initial state before displaying settings to prevent flash of defaults
Promise.all([
ProtocolClient.getLintConfig(),
ProtocolClient.getStructuredLintConfig(),
ProtocolClient.getLintDescriptions(),
-]).then(([nextLintConfig, nextStructuredConfig, nextLintDescriptions]) => {
- lintConfig = nextLintConfig;
- structuredLintConfig = nextStructuredConfig;
- lintDescriptions = nextLintDescriptions;
-});
-
-ProtocolClient.getDialect().then((d) => {
- dialect = d;
-});
-
-ProtocolClient.getIsolateEnglish().then((value) => {
- isolateEnglish = value;
-});
-
-ProtocolClient.getDelay().then((value) => {
- delay = value;
- delayLoaded = true;
-});
-
-ProtocolClient.getDefaultEnabled().then((d) => {
- defaultEnabled = d;
-});
-
-ProtocolClient.getActivationKey().then((d) => {
- activationKey = d;
-});
-
-ProtocolClient.getHotkey().then((d) => {
- hotkey = {
- modifiers: [...d.modifiers],
- key: d.key,
- };
- buttonText = `Hotkey: ${d.modifiers.join('+')}+${d.key}`;
-});
-
-ProtocolClient.getUserDictionary().then((d) => {
- userDict = dictToString(d.toSorted());
-});
-
-ProtocolClient.getWeirpacks().then((stored) => {
- weirpacks = stored.toSorted((a, b) => b.installedAt.localeCompare(a.installedAt));
-});
+ ProtocolClient.getDialect(),
+ ProtocolClient.getIsolateEnglish(),
+ ProtocolClient.getDelay(),
+ ProtocolClient.getDefaultEnabled(),
+ ProtocolClient.getActivationKey(),
+ ProtocolClient.getHotkey(),
+ ProtocolClient.getUserDictionary(),
+ ProtocolClient.getWeirpacks(),
+]).then(
+ ([
+ nextLintConfig,
+ nextStructuredConfig,
+ nextLintDescriptions,
+ nextDialect,
+ nextIsolateEnglish,
+ nextDelay,
+ nextDefaultEnabled,
+ nextActivationKey,
+ nextHotkey,
+ nextUserDict,
+ nextWeirpacks,
+ ]) => {
+ lintConfig = nextLintConfig;
+ structuredLintConfig = nextStructuredConfig;
+ lintDescriptions = nextLintDescriptions;
+ dialect = nextDialect;
+ isolateEnglish = nextIsolateEnglish;
+ delay = nextDelay;
+ delayLoaded = true;
+ defaultEnabled = nextDefaultEnabled;
+ activationKey = nextActivationKey;
+ hotkey = {
+ modifiers: [...nextHotkey.modifiers],
+ key: nextHotkey.key,
+ };
+ buttonText = `${nextHotkey.modifiers.join('+')} + ${nextHotkey.key.toUpperCase()}`;
+ userDict = dictToString(nextUserDict.toSorted());
+ weirpacks = nextWeirpacks.toSorted((a, b) => b.installedAt.localeCompare(a.installedAt));
+
+ loaded = true;
+ },
+);
/** Converts the content of a text area to viable dictionary values. */
export function stringToDict(s: string): string[] {
@@ -143,7 +158,9 @@ function updateAllRules(enabled: boolean): void {
}
function toggleAllRules(): void {
- updateAllRules(!anyRulesEnabled);
+ const enable = !anyRulesEnabled;
+ updateAllRules(enable);
+ statusMessage = enable ? 'All rules enabled.' : 'All rules disabled.';
}
function collectStructuredRuleNames(settings: StructuredLintSetting[]): string[] {
@@ -212,15 +229,23 @@ function updateLintConfig(nextConfig: LintConfig) {
lintConfig = nextConfig;
}
-function setIsolateEnglishFromCheckbox(event: Event): void {
- const input = event.currentTarget;
- if (!(input instanceof HTMLInputElement)) {
- console.warn('Could not update isolate English setting: missing checkbox input.');
- return;
- }
+function setIsolateEnglish(value: boolean): void {
+ if (isolateEnglish === value) return;
+ isolateEnglish = value;
+ ProtocolClient.setIsolateEnglish(isolateEnglish);
+}
- isolateEnglish = input.checked;
- ProtocolClient.setIsolateEnglish(input.checked);
+/** Arrow-key support for the On/Off radio groups (On is the first option). */
+async function handleRadioKeydown(event: KeyboardEvent, set: (value: boolean) => void) {
+ const previous = ['ArrowLeft', 'ArrowUp'];
+ const next = ['ArrowRight', 'ArrowDown'];
+ if (!previous.includes(event.key) && !next.includes(event.key)) return;
+
+ event.preventDefault();
+ const group = event.currentTarget as HTMLElement;
+ set(previous.includes(event.key));
+ await tick();
+ group.querySelector<HTMLElement>('[aria-checked="true"]')?.focus();
}
function toggleGroup(groupKey: string) {
@@ -249,12 +274,39 @@ async function exportEnabledDomainsCSV() {
}
}
-let buttonText = $state('Set Hotkey');
-let isBlue = $state(false); // modify color of hotkey button once it is pressed
-function startHotkeyCapture(_modifyHotkeyButton: Button) {
- buttonText = 'Press desired hotkey combination now.';
+let isCapturingHotkey = $state(false);
+let stopHotkeyCapture: (() => void) | null = null;
+
+function formatHotkey(value: Hotkey): string {
+ const key = value.key.length === 1 ? value.key.toUpperCase() : value.key;
+ return `${value.modifiers.join('+')} + ${key}`;
+}
+
+function cancelHotkeyCapture() {
+ stopHotkeyCapture?.();
+ stopHotkeyCapture = null;
+ isCapturingHotkey = false;
+ buttonText = formatHotkey(hotkey);
+ statusMessage = 'Hotkey change cancelled.';
+}
+
+function startHotkeyCapture() {
+ isCapturingHotkey = true;
+ buttonText = 'Listening...';
+ statusMessage = 'Press the new key combination, or Escape to cancel.';
const handleKeydown = (event: KeyboardEvent) => {
+ // Never trap keyboard users: Escape cancels, a plain Tab moves on.
+ if (event.key === 'Escape') {
+ event.preventDefault();
+ cancelHotkeyCapture();
+ return;
+ }
+ if (event.key === 'Tab' && !event.ctrlKey && !event.altKey) {
+ cancelHotkeyCapture();
+ return;
+ }
+
event.preventDefault();
const modifiers: Modifier[] = [];
@@ -268,28 +320,24 @@ function startHotkeyCapture(_modifyHotkeyButton: Button) {
if (modifiers.length === 0) {
return;
}
- buttonText = `Hotkey: ${modifiers.join('+')}+${key}`;
- // Create a plain object to avoid proxy cloning issues
+ const formattedKey = key.length === 1 ? key.toUpperCase() : key;
+ buttonText = `${modifiers.join('+')} + ${formattedKey}`;
const newHotkey = {
modifiers: [...modifiers],
- key: key,
+ key: formattedKey,
};
hotkey = newHotkey;
-
- // Call ProtocolClient directly with the plain object to avoid proxy issues
ProtocolClient.setHotkey(newHotkey);
-
- // Remove listener
window.removeEventListener('keydown', handleKeydown);
-
- // change button color
- isBlue = !isBlue;
+ stopHotkeyCapture = null;
+ isCapturingHotkey = false;
+ statusMessage = `Hotkey set to ${buttonText}.`;
}
};
- // Add temporary key listener
window.addEventListener('keydown', handleKeydown);
+ stopHotkeyCapture = () => window.removeEventListener('keydown', handleKeydown);
}
async function refreshWeirpacks() {
@@ -312,12 +360,13 @@ async function handleWeirpackUpload(event: Event) {
await ProtocolClient.addWeirpack(file.name, bytes);
}
await refreshWeirpacks();
+ statusMessage = 'Weirpack uploaded.';
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to upload Weirpack.';
weirpackError = message;
} finally {
weirpackBusy = false;
- input.value = '';
+ if (input) input.value = '';
}
}
@@ -327,6 +376,7 @@ async function removeWeirpack(id: string) {
try {
await ProtocolClient.removeWeirpack(id);
await refreshWeirpacks();
+ statusMessage = 'Weirpack removed.';
} catch (error) {
const message = error instanceof Error ? error.message : 'Failed to remove Weirpack.';
weirpackError = message;
@@ -334,249 +384,344 @@ async function removeWeirpack(id: string) {
weirpackBusy = false;
}
}
-
-// Import removed
</script>
-<!-- centered wrapper with side gutters -->
-<div class="min-h-screen px-4 py-10">
- <div class="mx-auto max-w-screen-lg space-y-4">
- <Card class="flex items-center gap-3">
- <div class="flex h-9 w-9 items-center justify-center rounded-xl">
- <img src={logo} alt="Harper logo" class="h-5 w-auto" />
+<main class="flex min-h-screen flex-col px-4 py-6 font-sans lg:h-screen lg:overflow-hidden lg:px-8">
+ <!-- Skip links: visible only while focused -->
+ <a href="#rules-list" class="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-50 focus:rounded-md focus:bg-primary focus:px-3 focus:py-2 focus:text-sm focus:font-semibold focus:text-black">Skip to rules</a>
+ <a href="#settings" class="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-50 focus:rounded-md focus:bg-primary focus:px-3 focus:py-2 focus:text-sm focus:font-semibold focus:text-black">Skip to settings</a>
+ <!-- Screen reader announcements -->
+ <p class="sr-only" role="status" aria-live="polite" aria-atomic="true">{statusMessage}</p>
+
+ <div class="mx-auto flex min-h-0 w-full max-w-1600 flex-1 flex-col gap-6">
+ <!-- Header -->
+ <Card class="flex shrink-0 items-center gap-3.5 p-3">
+ <div class="flex h-10 w-10 items-center justify-center rounded-xl bg-gray-100 dark:bg-slate-800">
+ <img src={logo} alt="Harper logo" class="h-6 w-auto" />
</div>
<div class="flex flex-col">
- <h1 class="text-base tracking-wide font-serif">Harper</h1>
- <p class="text-xs">Settings</p>
+ <h1 class="text-base font-semibold tracking-tight">Harper</h1>
+ <p class="text-xs text-gray-500 dark:text-[#d1d5db]!">Extension Settings</p>
</div>
</Card>
- <!-- ── GENERAL ───────────────────────────── -->
- <Card class="space-y-6">
- <h2 class="pb-1 text-xs uppercase tracking-wider">General</h2>
-
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <h3 class="text-sm">English Dialect</h3>
- <Select size="sm" class="w-44" bind:value={dialect}>
- <option value={Dialect.American}>🇺🇸 American</option>
- <option value={Dialect.British}>🇬🇧 British</option>
- <option value={Dialect.Australian}>🇦🇺 Australian</option>
- <option value={Dialect.Canadian}>🇨🇦 Canadian</option>
- <option value={Dialect.Indian}>🇮🇳 Indian</option>
- </Select>
- </div>
- </div>
+ {#if loaded}
+ <div class="grid min-h-0 flex-1 gap-6 lg:grid-cols-[minmax(0,7fr)_minmax(0,5fr)] lg:grid-rows-[minmax(0,1fr)]">
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">Ignore Non-English Text</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Skip text that Harper detects as not English.
+ <!-- ══ LEFT COLUMN: Rules (sticky, fills viewport height) ══ -->
+ <Card class="flex min-h-0 min-w-0 max-h-[75vh] flex-col gap-4 p-6 lg:max-h-none">
+ <div class="flex shrink-0 items-baseline justify-between gap-3">
+ <h2 class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-[#d1d5db]!">Rules</h2>
+ <p class="font-mono text-xs text-gray-600 dark:text-[#e5e7eb]!">
+ {totalRules} total · {customizedRules} customized
</p>
</div>
- <input
- type="checkbox"
- checked={isolateEnglish}
- onchange={setIsolateEnglishFromCheckbox}
- class="h-5 w-5"
- />
- </div>
- </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">Enable on New Sites by Default</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Can make some apps behave abnormally.
- </p>
+ <div class="flex shrink-0 flex-wrap items-center gap-2.5">
+ <Input
+ bind:value={searchQuery}
+ id="rule-search"
+ aria-label="Search rules"
+ aria-controls="rules-list"
+ autocomplete="off"
+ placeholder="Search rules..."
+ size="sm"
+ class="min-w-12rem flex-1 outline-none! focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ />
+ <Button size="sm" class="cursor-pointer bg-primary! text-black! hover:bg-primary/85! outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!" on:click={() => { resetRulesToDefaults(); statusMessage = 'All rules reset to defaults.'; }}>Reset to Defaults</Button>
+ <Button size="sm" color="light" class="cursor-pointer outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!" on:click={toggleAllRules}>
+ {anyRulesEnabled ? 'Disable All Rules' : 'Enable All Rules'}
+ </Button>
</div>
- <input
- type="checkbox"
- bind:checked={defaultEnabled}
- class="h-5 w-5"
- />
- </div>
- </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between gap-4">
- <div class="flex flex-col">
- <h3 class="text-sm">Delay</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Wait this many milliseconds after typing stops before refreshing
- highlights.
- </p>
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex (scrollable region must be keyboard-focusable) -->
+ <div
+ id="rules-list"
+ role="region"
+ aria-label="Rules"
+ tabindex="0"
+ class="rule-scroll min-h-0 flex-1 space-y-4 overflow-y-auto rounded-md pr-1 [scrollbar-width:thin] focus-visible:outline focus-visible:outline-offset-2 focus-visible:outline-primary"
+ >
+ {#key displayStructuredSettings.length}
+ <StructuredRuleSettings
+ settings={displayStructuredSettings}
+ {lintConfig}
+ {lintDescriptions}
+ {searchQueryLower}
+ {expandedGroups}
+ handleLintConfigChange={updateLintConfig}
+ handleToggleGroup={toggleGroup}
+ />
+ {/key}
</div>
- <input
- type="number"
- min="0"
- step="50"
- bind:value={delay}
- class="w-44 rounded-lg border border-cream-200 bg-white px-3 py-2.5 text-sm text-gray-900 shadow-sm outline-none transition focus:border-cream-300 focus:ring-2 focus:ring-primary-300 dark:border-cream-700 dark:bg-cream-900 dark:text-white dark:focus:border-cream-600 dark:focus:ring-primary-600"
- />
- </div>
- </div>
+ </Card>
+
+ <!-- ══ RIGHT COLUMN: General + Weirpacks ══ -->
+ <div id="settings" tabindex="-1" aria-label="Extension settings" role="region" class="min-h-0 min-w-0 space-y-6 outline-none! lg:overflow-y-auto lg:pr-1 [scrollbar-width:thin]">
+
+ <!-- ── GENERAL ───────────────────────────── -->
+ <Card class="space-y-6 p-6">
+ <h2 class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-[#d1d5db]!">General</h2>
+
+ <div class="divide-y divide-gray-100 dark:divide-slate-800/60">
+ <!-- English Dialect -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="dialect-label" class="text-base font-semibold">English Dialect</h3>
+ <p id="dialect-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Select target spelling and grammar rules.</p>
+ </div>
+ <Select
+ size="sm"
+ class="h-9 w-48 shrink-0 outline-none! focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ bind:value={dialect}
+ aria-labelledby="dialect-label" aria-describedby="dialect-desc"
+ >
+ <option value={Dialect.American}>American English</option>
+ <option value={Dialect.British}>British English</option>
+ <option value={Dialect.Australian}>Australian English</option>
+ <option value={Dialect.Canadian}>Canadian English</option>
+ <option value={Dialect.Indian}>Indian English</option>
+ </Select>
+ </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">Export Enabled Domains</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Downloads JSON of domains explicitly enabled.
- </p>
- </div>
- <Button size="sm" on:click={exportEnabledDomainsCSV}
- >Export JSON</Button
- >
- </div>
- </div>
+ <!-- Ignore Non-English Text -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="isolate-label" class="text-base font-semibold">Ignore Non-English Text</h3>
+ <p id="isolate-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Skip text that Harper detects as not English.</p>
+ </div>
+
+ <div class="h-9 w-48 shrink-0 rounded-lg border border-gray-200 p-1 dark:border-slate-700 dark:bg-slate-900">
+ <div
+ class="relative flex h-full w-full"
+ role="radiogroup"
+ aria-labelledby="isolate-label" aria-describedby="isolate-desc"
+ >
+ <div
+ class="absolute inset-y-0 left-0 w-1/2 rounded-md bg-primary transition-transform duration-300 ease-out motion-reduce:transition-none"
+ class:translate-x-0={isolateEnglish}
+ class:translate-x-full={!isolateEnglish}
+ ></div>
+
+ <button
+ type="button"
+ role="radio"
+ aria-checked={isolateEnglish}
+ tabindex={isolateEnglish ? 0 : -1}
+ onkeydown={(e) => handleRadioKeydown(e, setIsolateEnglish)}
+ class="relative z-10 flex-1 cursor-pointer rounded-md py-1 text-center text-xs font-semibold transition-colors duration-200 motion-reduce:transition-none {isolateEnglish ? 'text-black' : 'text-gray-500 hover:text-gray-900 dark:text-[#d1d5db]! dark:hover:text-white!'}"
+ onclick={() => setIsolateEnglish(true)}
+ >
+ On
+ </button>
+ <button
+ type="button"
+ role="radio"
+ aria-checked={!isolateEnglish}
+ tabindex={!isolateEnglish ? 0 : -1}
+ onkeydown={(e) => handleRadioKeydown(e, setIsolateEnglish)}
+ class="relative z-10 flex-1 cursor-pointer rounded-md py-1 text-center text-xs font-semibold transition-colors duration-200 motion-reduce:transition-none {!isolateEnglish ? 'text-black' : 'text-gray-500 hover:text-gray-900 dark:text-[#d1d5db]! dark:hover:text-white!'}"
+ onclick={() => setIsolateEnglish(false)}
+ >
+ Off
+ </button>
+ </div>
+ </div>
+ </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">Activation Key</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- If you're finding that you're accidentally triggering Harper.
- </p>
- </div>
- <Select size="sm" class="w-44" bind:value={activationKey}>
- <option value={ActivationKey.Shift}>Double Shift</option>
- <option value={ActivationKey.Control}>Double Control</option>
- <option value={ActivationKey.Off}>Off</option>
- </Select>
- </div>
- </div>
+ <!-- Enable on New Sites by Default -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="default-enabled-label" class="text-base font-semibold">Enable on New Sites by Default</h3>
+ <p id="default-enabled-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Automatically run Harper on newly visited websites.</p>
+ </div>
+
+ <div class="h-9 w-48 shrink-0 rounded-lg border border-gray-200 p-1 dark:border-slate-700 dark:bg-slate-900">
+ <div
+ class="relative flex h-full w-full"
+ role="radiogroup"
+ aria-labelledby="default-enabled-label" aria-describedby="default-enabled-desc"
+ >
+ <div
+ class="absolute inset-y-0 left-0 w-1/2 rounded-md bg-primary transition-transform duration-300 ease-out motion-reduce:transition-none"
+ class:translate-x-0={defaultEnabled}
+ class:translate-x-full={!defaultEnabled}
+ ></div>
+
+ <button
+ type="button"
+ role="radio"
+ aria-checked={defaultEnabled}
+ tabindex={defaultEnabled ? 0 : -1}
+ onkeydown={(e) => handleRadioKeydown(e, (v) => (defaultEnabled = v))}
+ class="relative z-10 flex-1 cursor-pointer rounded-md py-1 text-center text-xs font-semibold transition-colors duration-200 motion-reduce:transition-none {defaultEnabled ? 'text-black' : 'text-gray-500 hover:text-gray-900 dark:text-[#d1d5db]! dark:hover:text-white!'}"
+ onclick={() => (defaultEnabled = true)}
+ >
+ On
+ </button>
+ <button
+ type="button"
+ role="radio"
+ aria-checked={!defaultEnabled}
+ tabindex={!defaultEnabled ? 0 : -1}
+ onkeydown={(e) => handleRadioKeydown(e, (v) => (defaultEnabled = v))}
+ class="relative z-10 flex-1 cursor-pointer rounded-md py-1 text-center text-xs font-semibold transition-colors duration-200 motion-reduce:transition-none {!defaultEnabled ? 'text-black' : 'text-gray-500 hover:text-gray-900 dark:text-[#d1d5db]! dark:hover:text-white!'}"
+ onclick={() => (defaultEnabled = false)}
+ >
+ Off
+ </button>
+ </div>
+ </div>
+ </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">Apply Last Suggestion Hotkey</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Applies suggestion to last highlighted word.
- </p>
- </div>
- <Textarea readonly bind:value={buttonText} />
- <Button
- size="sm"
- color="light"
- style="background-color: {isBlue ? 'blue' : ''}"
- bind:this={modifyHotkeyButton}
- on:click={() => {
- startHotkeyCapture(modifyHotkeyButton);
- isBlue = !isBlue;
- }}>Modify Hotkey</Button
- >
- </div>
- </div>
+ <!-- Delay -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="delay-label" class="text-base font-semibold">Delay (ms)</h3>
+ <p id="delay-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Wait time after typing stops before refreshing highlights.</p>
+ </div>
+ <Input
+ type="number"
+ min="0"
+ step="50"
+ bind:value={delay}
+ aria-labelledby="delay-label" aria-describedby="delay-desc"
+ class="h-9 w-48 shrink-0 text-sm font-semibold dark:text-white! outline-none! focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ />
+ </div>
- <div class="space-y-5">
- <div class="flex items-center justify-between">
- <div class="flex flex-col">
- <h3 class="text-sm">User Dictionary</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Each word should be on its own line.
- </p>
- </div>
- <Textarea bind:value={userDict}></Textarea>
- </div>
- </div>
- </Card>
+ <!-- Export Enabled Domains -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="export-label" class="text-base font-semibold">Export Enabled Domains</h3>
+ <p id="export-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Downloads a JSON list of domains explicitly enabled.</p>
+ </div>
+ <Button size="sm" class="h-9 w-48 shrink-0 cursor-pointer text-xs font-semibold bg-primary! text-black! hover:bg-primary/85! outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!" aria-describedby="export-desc" on:click={exportEnabledDomainsCSV}>Export JSON</Button>
+ </div>
- <Card class="space-y-4">
- <h2 class="pb-1 text-xs uppercase tracking-wider">Weirpacks</h2>
+ <!-- Activation Key -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="activation-label" class="text-base font-semibold">Activation Key</h3>
+ <p id="activation-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Requires a quick double-press before activating highlights.</p>
+ </div>
+ <Select
+ size="sm"
+ class="h-9 w-48 shrink-0 outline-none! focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ bind:value={activationKey}
+ aria-labelledby="activation-label" aria-describedby="activation-desc"
+ >
+ <option value={ActivationKey.Shift}>Double Shift</option>
+ <option value={ActivationKey.Control}>Double Control</option>
+ <option value={ActivationKey.Off}>Off</option>
+ </Select>
+ </div>
- <div class="space-y-2 flex flex-row w-full justify-between">
- <p class="text-xs text-gray-600 dark:text-gray-400">
- Upload one or more <code>.weirpack</code> files to add custom rule
- packs.
- <a href="https://writewithharper.com/docs/weir#Weirpacks"
- >What is a Weirpack?</a
- >
- </p>
- <input
- type="file"
- accept=".weirpack,application/zip"
- multiple
- disabled={weirpackBusy}
- onchange={handleWeirpackUpload}
- class="block w-1/4 text-sm file:rounded-md file:border-0 file:bg-primary file:text-white disabled:opacity-50"
- />
- </div>
+ <!-- Apply Last Suggestion Hotkey -->
+ <div class="flex items-center justify-between gap-4 py-3.5">
+ <div class="flex flex-col">
+ <h3 id="hotkey-label" class="text-base font-semibold">Apply Last Suggestion Hotkey</h3>
+ <p id="hotkey-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Applies suggestions to the last highlighted word.</p>
+ </div>
+ <div class="flex h-9 w-48 shrink-0 items-center justify-between gap-2">
+ <kbd aria-labelledby="hotkey-label" class="flex h-full flex-1 items-center justify-center whitespace-nowrap rounded-md border border-gray-200 bg-gray-100 px-2 font-mono text-xs font-semibold text-gray-800 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100">
+ {buttonText}
+ </kbd>
+ <Button
+ size="sm"
+ class="h-full shrink-0 cursor-pointer text-xs font-semibold bg-primary! text-black! hover:bg-primary/85! outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ aria-label={isCapturingHotkey ? 'Cancel changing hotkey' : `Modify hotkey, currently ${buttonText}`}
+ on:click={isCapturingHotkey ? cancelHotkeyCapture : startHotkeyCapture}
+ >
+ {isCapturingHotkey ? 'Cancel' : 'Modify'}
+ </Button>
+ </div>
+ </div>
- {#if weirpackError}
- <p class="text-xs text-red-700 dark:text-red-400">{weirpackError}</p>
- {/if}
-
- {#if weirpacks.length === 0}
- <p class="text-sm text-gray-600 dark:text-gray-400">
- No Weirpacks installed.
- </p>
- {:else}
- <div class="space-y-3">
- {#each weirpacks as weirpack}
- <div
- class="flex items-center justify-between gap-3 rounded-md border border-primary-100 p-3"
- >
- <div class="min-w-0">
- <p class="truncate text-sm">
- {weirpack.name}{weirpack.version
- ? ` v${weirpack.version}`
- : ""}
- </p>
- <p class="truncate text-xs text-gray-600 dark:text-gray-400">
- {weirpack.filename}
- </p>
+ <!-- User Dictionary -->
+ <div class="flex flex-col gap-2 py-3.5">
+ <div>
+ <h3 id="dictionary-label" class="text-base font-semibold">User Dictionary</h3>
+ <p id="dictionary-desc" class="text-xs text-gray-600 dark:text-[#d1d5db]!">Add custom words to ignore (one word per line).</p>
+ </div>
+ <Textarea
+ bind:value={userDict}
+ aria-labelledby="dictionary-label" aria-describedby="dictionary-desc"
+ rows={3}
+ placeholder="customword&#10;anotherterm"
+ class="w-full resize-y text-xs outline-none! focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ ></Textarea>
</div>
+ </div>
+ </Card>
+
+ <!-- ── WEIRPACKS ───────────────────────────── -->
+ <Card class="space-y-4 p-6">
+ <h2 class="text-xs font-bold uppercase tracking-wider text-gray-500 dark:text-[#d1d5db]!">Weirpacks</h2>
+
+ <div class="flex items-center justify-between gap-4">
+ <p class="text-xs text-gray-600 dark:text-[#d1d5db]!">
+ Upload custom <code>.weirpack</code> rule packs.
+ <a href="https://writewithharper.com/docs/weir#Weirpacks" target="_blank" rel="noopener" class="text-primary hover:underline">
+ What is a Weirpack?
+ </a>
+ </p>
+
+ <input
+ type="file"
+ accept=".weirpack,application/zip"
+ multiple
+ disabled={weirpackBusy}
+ bind:this={fileInputRef}
+ onchange={handleWeirpackUpload}
+ class="hidden"
+ />
+
<Button
size="sm"
- color="light"
+ class="h-9 w-48 shrink-0 cursor-pointer text-xs font-semibold bg-primary! text-black! hover:bg-primary/85! outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
disabled={weirpackBusy}
- on:click={() => removeWeirpack(weirpack.id)}
+ on:click={() => fileInputRef?.click()}
>
- Remove
+ {weirpackBusy ? 'Uploading...' : 'Browse Weirpacks'}
</Button>
</div>
- {/each}
- </div>
- {/if}
- </Card>
- <!-- ── RULES ─────────────────────────────── -->
- <Card class="space-y-4">
- <div class="flex items-center justify-between gap-4">
- <h2 class="text-xs uppercase tracking-wider">Rules</h2>
- <Input
- bind:value={searchQuery}
- placeholder="Search for a rule…"
- size="sm"
- class="w-60"
- />
- </div>
- <div class="flex flex-wrap gap-3">
- <Button size="sm" on:click={resetRulesToDefaults}
- >Reset to Default Rules</Button
- >
- <Button size="sm" on:click={toggleAllRules}>
- {anyRulesEnabled ? "Disable All Rules" : "Enable All Rules"}
- </Button>
- </div>
-
- <div class="rule-scroll space-y-4 max-h-80 overflow-y-auto pr-1">
- {#key displayStructuredSettings.length}
- <StructuredRuleSettings
- settings={displayStructuredSettings}
- {lintConfig}
- {lintDescriptions}
- {searchQueryLower}
- {expandedGroups}
- handleLintConfigChange={updateLintConfig}
- handleToggleGroup={toggleGroup}
- />
- {/key}
+ {#if weirpackError}
+ <p role="alert" class="text-xs text-red-600 dark:text-red-300!">{weirpackError}</p>
+ {/if}
+
+ {#if weirpacks.length === 0}
+ <p class="text-xs text-gray-500 dark:text-[#d1d5db]!">No custom Weirpacks installed.</p>
+ {:else}
+ <div class="space-y-2.5">
+ {#each weirpacks as weirpack}
+ <div class="flex items-center justify-between gap-3 rounded-lg border border-gray-200 p-3 dark:border-slate-800 dark:bg-slate-800/40">
+ <div class="min-w-0">
+ <p class="truncate text-xs font-semibold">
+ {weirpack.name}{weirpack.version ? ` v${weirpack.version}` : ''}
+ </p>
+ <p class="truncate font-mono text-[11px] text-gray-500 dark:text-[#d1d5db]!">
+ {weirpack.filename}
+ </p>
+ </div>
+ <Button
+ size="sm"
+ color="light"
+ class="cursor-pointer outline-none! focus:outline-none! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!"
+ disabled={weirpackBusy}
+ aria-label={`Remove ${weirpack.name}`}
+ on:click={() => removeWeirpack(weirpack.id)}
+ >
+ Remove
+ </Button>
+ </div>
+ {/each}
+ </div>
+ {/if}
+ </Card>
+ </div>
</div>
- </Card>
+ {/if}
</div>
-</div>
+</main>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/options/StructuredRuleSettings.svelte b/packages/chrome-plugin/src/options/StructuredRuleSettings.svelte
index 4b8d04e30..f4fed4ebc 100644
--- a/packages/chrome-plugin/src/options/StructuredRuleSettings.svelte
+++ b/packages/chrome-plugin/src/options/StructuredRuleSettings.svelte
@@ -241,7 +241,7 @@ function buildRenderNodes(
name,
title: `Choose an option for ${name}.`,
options: [
- { value: 'default', label: '⚙️ Default' },
+ { value: 'default', label: 'Default' },
...setting.OneOfMany.names.map((value, index) => ({
value,
label: setting.OneOfMany.labels?.[index] ?? value,
@@ -300,97 +300,156 @@ $: {
void lintDescriptions;
renderedNodes = nodes ?? buildRenderNodes(settings, groupPath, forceShow, indent).nodes;
}
+
+function idFor(prefix: string, key: string): string {
+ return `${prefix}-${key.replace(/[^a-zA-Z0-9]+/g, '-')}`;
+}
+
+const selectClass =
+ 'h-9 w-36 shrink-0 rounded-md border border-gray-200 bg-white px-3 text-xs font-semibold text-gray-900 dark:border-white/15! dark:bg-white/5! dark:text-white dark:[color-scheme:dark] dark:[&_option]:bg-[#1c1c1c] dark:[&_option]:text-white outline-none! transition-colors focus:border-primary! focus:ring-0! focus-visible:ring-2! focus-visible:ring-primary!';
+const dividerClass = 'border-t border-gray-100 pt-3 dark:border-white/10!';
</script>
-<div class="space-y-4">
- {#each renderedNodes as node}
- {#if node.kind === 'group'}
- <div class="space-y-3">
- <div class="flex items-start justify-between gap-4" style={rowStyle(node.indent)}>
- <div class="space-y-0.5">
- <h3 class="text-sm">{node.label}</h3>
- <p class="text-xs text-gray-600 dark:text-gray-400">{node.description}</p>
- <p class="text-xs text-gray-600 dark:text-gray-400">{node.ruleCount} rules</p>
- </div>
- <div class="flex items-center gap-2">
- <button
- type="button"
- class="cursor-pointer inline-flex items-center gap-2 justify-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-center text-gray-900 transition-colors hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:border-gray-600 dark:hover:bg-gray-700 dark:focus:ring-gray-700"
- title={node.expanded
- ? `Collapse the ${node.label} category`
- : `Expand the ${node.label} category`}
- onclick={() => handleToggleGroup(node.groupKey)}
- >
- {node.expanded ? 'Collapse' : 'Expand'}
- </button>
- <Select
- size="md"
- title={`Set all rules in the ${node.label} category to their default, on, or off state.`}
- value={node.state === 'mixed' ? 'default' : node.state}
- onchange={(event: Event) => updateGroup(node.ruleNames, (event.target as HTMLSelectElement).value)}
- >
- <option value="default">{node.state === 'mixed' ? '⚙️ Default (mixed)' : '⚙️ Default'}</option>
- <option value="enable">✅ On</option>
- <option value="disable">🚫 Off</option>
- </Select>
- </div>
- </div>
-
- {#if node.expanded}
- <svelte:self
- nodes={node.childNodes}
- settings={[]}
- {lintConfig}
- {lintDescriptions}
- {searchQueryLower}
- {expandedGroups}
- groupPath={[]}
- indent={indent}
- forceShow={forceShow}
- {handleLintConfigChange}
- {handleToggleGroup}
- />
- {/if}
- </div>
- {:else if node.kind === 'bool'}
- <div class="flex items-start justify-between gap-4" style={rowStyle(node.indent)}>
- <div class="space-y-0.5">
- <h3 class="text-sm">{node.label}</h3>
- <p class="text-xs">{@html node.description}</p>
- </div>
- <Select
- size="md"
- title={node.title}
- value={node.value}
- onchange={(event: Event) => {
- const nextConfig: LintConfig = { ...lintConfig };
- nextConfig[node.name] = configStringToValue(
- (event.target as HTMLSelectElement).value,
- );
- handleLintConfigChange(nextConfig);
- }}
- >
- <option value="default">⚙️ Default</option>
- <option value="enable">✅ On</option>
- <option value="disable">🚫 Off</option>
- </Select>
- </div>
- {:else if node.kind === 'oneOfMany'}
- <div class="flex items-start justify-between gap-4" style={rowStyle(node.indent)}>
- <div class="space-y-0.5">
- <h3 class="text-sm">{node.name}</h3>
- </div>
- <Select
- size="md"
- title={node.title}
- value={node.value}
- onchange={(event: Event) => updateOneOfMany(node.setting, (event.target as HTMLSelectElement).value)}
- >
- {#each node.options as option}
- <option value={option.value}>{option.label}</option>
- {/each}
- </Select>
- </div>
- {/if}
- {/each}
-</div>
+<div class="space-y-2">
+ {#if nodes === undefined}
+ <!-- Search result announcements (top-level instance only) -->
+ <p class="sr-only" role="status" aria-live="polite" aria-atomic="true">
+ {#if searchQueryLower !== ''}
+ {renderedNodes.length === 0
+ ? 'No categories match your search.'
+ : `${renderedNodes.length} ${renderedNodes.length === 1 ? 'category matches' : 'categories match'} your search.`}
+ {/if}
+ </p>
+ {#if renderedNodes.length === 0}
+ <p class="py-8 text-center text-sm text-gray-600 dark:text-[#d1d5db]!">No rules match your search.</p>
+ {/if}
+ {/if}
+
+ {#each renderedNodes as node}
+ {#if node.kind === 'group'}
+ {@const labelId = idFor('grp-label', node.groupKey)}
+ {@const descId = idFor('grp-desc', node.groupKey)}
+ {@const panelId = idFor('grp-panel', node.groupKey)}
+ <!-- Top-level groups are cards; nested groups are flat rows -->
+ <div
+ class={node.indent === 0
+ ? 'rounded-lg border border-gray-200 bg-gray-50/60 p-3 transition-colors motion-reduce:transition-none dark:border-white/10! dark:bg-white/[0.03]! dark:hover:bg-white/[0.05]!'
+ : dividerClass}
+ >
+ <div class="flex items-start justify-between gap-4" style={rowStyle(node.indent)}>
+ <!-- Disclosure button: the whole title area toggles the group -->
+ <button
+ type="button"
+ class="group flex min-w-0 flex-1 cursor-pointer items-start gap-2 rounded-md text-left outline-none! focus-visible:ring-2! focus-visible:ring-primary!"
+ aria-expanded={node.expanded}
+ aria-controls={panelId}
+ aria-labelledby={labelId}
+ aria-describedby={descId}
+ onclick={() => handleToggleGroup(node.groupKey)}
+ >
+ <svg
+ class="mt-0.5 h-4 w-4 shrink-0 text-gray-400 transition-transform duration-150 motion-reduce:transition-none group-hover:text-primary dark:text-[#d1d5db]! dark:group-hover:text-primary! {node.expanded ? 'rotate-90' : ''}"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ focusable="false"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M7.21 14.77a.75.75 0 0 1 .02-1.06L11.168 10 7.23 6.29a.75.75 0 1 1 1.04-1.08l4.5 4.25a.75.75 0 0 1 0 1.08l-4.5 4.25a.75.75 0 0 1-1.06-.02Z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ <span class="min-w-0 space-y-0.5">
+ <span class="flex items-center gap-2">
+ <span id={labelId} class="text-sm font-bold text-gray-900 group-hover:text-primary dark:text-white">{node.label}</span>
+ <span aria-hidden="true" class="rounded-full bg-gray-200 px-2 py-0.5 font-mono text-[11px] font-semibold text-gray-700 dark:bg-primary/20! dark:text-primary!">{node.ruleCount}</span>
+ </span>
+ <span id={descId} class="block text-xs text-gray-600 dark:text-[#d1d5db]!">
+ {node.description}<span class="sr-only"> ({node.ruleCount} rules)</span>
+ </span>
+ </span>
+ </button>
+
+ <Select
+ size="sm"
+ title={`Set all rules in the ${node.label} category to their default, on, or off state.`}
+ aria-label={`${node.label}: set all ${node.ruleCount} rules`}
+ value={node.state === 'mixed' ? 'default' : node.state}
+ class={selectClass}
+ onchange={(event: Event) => updateGroup(node.ruleNames, (event.target as HTMLSelectElement).value)}
+ >
+ <option value="default">{node.state === 'mixed' ? 'Default (Mixed)' : 'Default'}</option>
+ <option value="enable">On</option>
+ <option value="disable">Off</option>
+ </Select>
+ </div>
+
+ {#if node.expanded}
+ <div id={panelId} role="group" aria-labelledby={labelId} class="mt-3 space-y-3">
+ <svelte:self
+ nodes={node.childNodes}
+ settings={[]}
+ {lintConfig}
+ {lintDescriptions}
+ {searchQueryLower}
+ {expandedGroups}
+ groupPath={[]}
+ indent={indent}
+ forceShow={forceShow}
+ {handleLintConfigChange}
+ {handleToggleGroup}
+ />
+ </div>
+ {/if}
+ </div>
+ {:else if node.kind === 'bool'}
+ {@const labelId = idFor('rule-label', node.name)}
+ {@const descId = idFor('rule-desc', node.name)}
+ <div class="flex items-start justify-between gap-4 {dividerClass}" style={rowStyle(node.indent)}>
+ <div class="min-w-0 space-y-0.5">
+ <h3 id={labelId} class="text-sm font-bold text-gray-900 dark:text-white">{node.label}</h3>
+ <p id={descId} class="text-xs text-gray-600 dark:text-[#d1d5db]!">{@html node.description}</p>
+ </div>
+ <Select
+ size="sm"
+ title={node.title}
+ aria-labelledby={labelId}
+ aria-describedby={descId}
+ value={node.value}
+ class={selectClass}
+ onchange={(event: Event) => {
+ const nextConfig: LintConfig = { ...lintConfig };
+ nextConfig[node.name] = configStringToValue(
+ (event.target as HTMLSelectElement).value,
+ );
+ handleLintConfigChange(nextConfig);
+ }}
+ >
+ <option value="default">Default</option>
+ <option value="enable">On</option>
+ <option value="disable">Off</option>
+ </Select>
+ </div>
+ {:else if node.kind === 'oneOfMany'}
+ {@const labelId = idFor('choice-label', node.name)}
+ <div class="flex items-start justify-between gap-4 {dividerClass}" style={rowStyle(node.indent)}>
+ <div class="min-w-0 space-y-0.5">
+ <h3 id={labelId} class="text-sm font-bold text-gray-900 dark:text-white">{node.name}</h3>
+ </div>
+ <Select
+ size="sm"
+ title={node.title}
+ aria-labelledby={labelId}
+ value={node.value}
+ class={selectClass}
+ onchange={(event: Event) => updateOneOfMany(node.setting, (event.target as HTMLSelectElement).value)}
+ >
+ {#each node.options as option}
+ <option value={option.value}>{option.label}</option>
+ {/each}
+ </Select>
+ </div>
+ {/if}
+ {/each}
+</div>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/popup/DomainReview.svelte b/packages/chrome-plugin/src/popup/DomainReview.svelte
index 3e57df15d..e70a90845 100644
--- a/packages/chrome-plugin/src/popup/DomainReview.svelte
+++ b/packages/chrome-plugin/src/popup/DomainReview.svelte
@@ -1,21 +1,28 @@
<script lang="ts">
-import { Button, Input, Label, Select } from 'components';
+import { Button, Input, Label } from 'components';
import ProtocolClient from '../ProtocolClient';
let {
- domain,
- works,
- feedback,
+ domain: initialDomain,
+ works: initialWorks,
+ feedback: initialFeedback,
onSubmit,
}: { domain: string; works: boolean; feedback: string; onSubmit: () => void } = $props();
+// Local copies so the form can be edited without mutating props.
+let domain = $state(initialDomain);
+let works = $state(initialWorks);
+let feedback = $state(initialFeedback);
+
let submitting = $state(false);
let successful = $state(false);
+let failed = $state(false);
async function handleSubmit(event: SubmitEvent) {
event.preventDefault();
submitting = true;
+ failed = false;
const success = await ProtocolClient.postFormData(
'https://writewithharper.com/api/domain-reviews',
@@ -29,53 +36,100 @@ async function handleSubmit(event: SubmitEvent) {
submitting = false;
if (success) {
- onSubmit();
successful = true;
+ setTimeout(onSubmit, 1200);
+ } else {
+ failed = true;
}
}
+
+const segment =
+ 'flex-1 rounded-md px-3 py-1 text-sm font-semibold transition-colors cursor-pointer text-center';
</script>
-<div class="p-5">
- <h1 class="text-2xl font-semibold">Domain Review</h1>
- <p class="text-sm">
- Only the data you enter below will be sent to the Harper maintainer.
- </p>
- <form class="mt-4 space-y-6" onsubmit={handleSubmit}>
- <div class="space-y-3">
- <div class="flex items-baseline gap-2">
- <Label class=" ">Which domain would you like to tell us about?</Label>
- </div>
- <Input
- name="domain"
- bind:value={domain}
- placeholder="example.com"
- class="dark:bg-slate-900 dark:border-slate-700 "
- />
- <div class="flex items-baseline gap-2">
- <Label class=" ">Would you say that Harper works well on this domain?</Label>
- </div>
- <Select
- name="works"
- bind:value={works}
- class="dark:bg-slate-900 dark:border-slate-700 "
- >
- <option value={true}>Yes</option>
- <option value={false}>No</option>
- </Select>
-
- <div class="flex items-baseline gap-2">
- <Label class=" ">Additional Feedback</Label>
- </div>
- <Input
- name="feedback"
- placeholder="Tell us what went wrong."
- bind:value={feedback}
- class="dark:bg-slate-900 dark:border-slate-700 "
- />
-
- <div class="flex items-center justify-between pt-2">
- <Button state={submitting ? (successful ? "success" : "loading") : "idle"} type="submit" disabled={submitting}>Submit</Button>
- </div>
- </div>
- </form>
-</div>
+<div class="flex h-full flex-col justify-between px-5 py-3">
+ <div>
+ <h1 class="text-lg font-bold text-gray-900 dark:text-white">Review this site</h1>
+ <p class="mt-0.5 text-xs text-gray-600 dark:text-slate-300">
+ Only what you enter below is sent to the Harper maintainer.
+ </p>
+ </div>
+
+ <form class="mt-2.5 flex flex-1 flex-col justify-between overflow-hidden" onsubmit={handleSubmit}>
+ <!-- Scrollable Inputs Area (Prevents pushing button out of bounds) -->
+ <div class="space-y-2.5 overflow-y-auto pr-0.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
+ <div class="space-y-1">
+ <Label class="text-xs font-bold text-gray-900 dark:text-white">Domain</Label>
+ <Input
+ name="domain"
+ bind:value={domain}
+ placeholder="example.com"
+ class="w-full border-gray-200 text-gray-900 outline-none! transition-colors focus:border-primary! focus:ring-0! dark:border-slate-700 dark:bg-slate-900 dark:text-white"
+ />
+ </div>
+
+ <div class="space-y-1">
+ <Label class="text-xs font-bold text-gray-900 dark:text-white">Does Harper work well here?</Label>
+ <div class="rounded-lg border border-gray-200 p-1 dark:border-slate-700 dark:bg-slate-900">
+ <div
+ class="relative flex w-full"
+ role="radiogroup"
+ aria-label="Does Harper work well on this domain?"
+ >
+ <!-- Animated Sliding Background -->
+ <div
+ class="absolute inset-y-0 left-0 w-1/2 rounded-md bg-primary transition-transform duration-300 ease-out"
+ class:translate-x-0={works}
+ class:translate-x-full={!works}
+ ></div>
+
+ <button
+ type="button"
+ role="radio"
+ aria-checked={works}
+ class="relative z-10 {segment} {works ? 'text-black' : 'text-gray-600 hover:text-gray-900 dark:text-slate-300 dark:hover:text-white'}"
+ onclick={() => (works = true)}
+ >
+ Yes
+ </button>
+ <button
+ type="button"
+ role="radio"
+ aria-checked={!works}
+ class="relative z-10 {segment} {!works ? 'text-black' : 'text-gray-600 hover:text-gray-900 dark:text-slate-300 dark:hover:text-white'}"
+ onclick={() => (works = false)}
+ >
+ No
+ </button>
+ </div>
+ </div>
+ </div>
+
+ <div class="space-y-1">
+ <Label class="text-xs font-bold text-gray-900 dark:text-white">{works ? 'Anything else? (optional)' : 'What went wrong?'}</Label>
+ <textarea
+ name="feedback"
+ rows="4.5"
+ bind:value={feedback}
+ placeholder={works ? 'Optional notes' : 'e.g. underlines are misplaced, editor loses focus'}
+ class="w-full resize-none rounded-md border border-gray-200 bg-transparent px-3 py-1.5 text-sm text-gray-900 placeholder:text-gray-400 outline-none! transition-colors focus:border-primary! focus:ring-0! dark:border-slate-700 dark:bg-slate-900 dark:text-white dark:placeholder:text-slate-400"
+ ></textarea>
+ </div>
+ </div>
+
+ {#if failed}
+ <p class="py-1 text-xs text-red-500 dark:text-red-400" role="alert">Couldn't send your review. Check your connection and try again.</p>
+ {/if}
+
+ <div class="pt-2">
+ <Button
+ class="w-full shrink-0 {successful ? '' : 'bg-primary! text-black! hover:bg-primary/85!'} ring-0! focus:ring-0! focus-visible:ring-0! focus:shadow-none! focus-visible:shadow-none! focus-visible:outline! focus-visible:outline-1! focus-visible:outline-offset-2! focus-visible:outline-primary!"
+ state={successful ? 'success' : submitting ? 'loading' : 'idle'}
+ type="submit"
+ disabled={submitting || successful}
+ >
+ {successful ? 'Sent. Thank you!' : 'Send review'}
+ </Button>
+ </div>
+ </form>
+</div>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/popup/Main.svelte b/packages/chrome-plugin/src/popup/Main.svelte
index 6dfae1cdb..0e7ed8ed1 100644
--- a/packages/chrome-plugin/src/popup/Main.svelte
+++ b/packages/chrome-plugin/src/popup/Main.svelte
@@ -7,8 +7,12 @@ import ProtocolClient from '../ProtocolClient';
let { onReviewDomain }: { onReviewDomain: (works: boolean, domain: string) => void } = $props();
+// UI State Flags
+let loaded = $state(false);
+
let enabled = $state(true);
let domain = $state('');
+let site = $derived(domain || 'this page');
let installDate: Date | null = $state(null);
let hasBeenReviewed: boolean | null = $state(null);
@@ -17,28 +21,24 @@ const REVIEW_URL =
const isFirefox = isFirefoxExtension();
-if (!isFirefox) {
- ProtocolClient.getInstalledOn().then((d) => {
- if (d == null) {
- return;
- }
-
- installDate = new Date(d);
- });
-
- ProtocolClient.getReviewed().then((r) => {
- hasBeenReviewed = r;
- });
-}
-
-getCurrentTabDomain().then((d) => {
- domain = d ?? '';
-});
-
-$effect(() => {
- ProtocolClient.getDomainEnabled(domain).then((e) => {
- enabled = e;
- });
+// Fetch all initial data concurrently before showing the UI to prevent layout flashing
+Promise.all([
+ getCurrentTabDomain().then(async (d) => {
+ domain = d ?? '';
+ enabled = await ProtocolClient.getDomainEnabled(domain);
+ }),
+ !isFirefox
+ ? ProtocolClient.getInstalledOn().then((d) => {
+ if (d != null) installDate = new Date(d);
+ })
+ : Promise.resolve(),
+ !isFirefox
+ ? ProtocolClient.getReviewed().then((r) => {
+ hasBeenReviewed = r;
+ })
+ : Promise.resolve(),
+]).then(() => {
+ loaded = true;
});
/**
@@ -53,14 +53,13 @@ export async function getCurrentTabDomain(): Promise<string | undefined> {
try {
const { hostname } = new URL(tab.url);
- return hostname.replace(/^www\\./, '');
+ return hostname.replace(/^www\./, '');
} catch {
return undefined;
}
}
function toggleDomainEnabled() {
- console.log('toggle');
enabled = !enabled;
ProtocolClient.setDomainEnabled(domain, enabled);
}
@@ -92,67 +91,110 @@ function daysSince(date: Date): number {
}
</script>
-<main>
- <section class="p-6 space-y-5 text-gray-800 flex flex-row">
- <Button
- size="lg"
- class="rounded-full! aspect-square h-24 w-24 p-0 shadow-lg transition-colors flex! flex-row justify-center"
- color={enabled ? 'var(--color-primary)' : 'var(--color-cream-50)'}
- on:click={toggleDomainEnabled}
- >
- <svg
- xmlns="http://www.w3.org/2000/svg"
- class="h-9 w-9"
- fill="none"
- viewBox="0 0 24 24"
- stroke="currentColor"
- stroke-width="2"
+<main class="flex h-full flex-col justify-between">
+ {#if loaded}
+ <section
+ class="flex flex-1 flex-col items-center justify-center px-5 py-6 transition-colors"
+ style={enabled
+ ? 'background-image: radial-gradient(circle at 25% 50%, color-mix(in srgb, var(--color-primary) 12%, transparent), transparent 75%)'
+ : ''}
>
- <path
- color={enabled ? 'var(--color-cream-50)' : 'var(--color-primary)'}
- stroke-linecap="round"
- stroke-linejoin="round"
- d="M12 5v7m5.657-4.657a8 8 0 11-11.314 0"
- />
- </svg>
- </Button>
-
- <section class="items-end p-2">
- <h1 class="text-2xl dark:text-white text-right">
- {generateGreeting()}
- </h1>
-
- <p class="text-sm font-medium font-sans dark:text-white text-right">
- Harper is {enabled ? 'enabled on ' : 'disabled on '}{domain.length > 10 ? "this page" : domain}.
- </p>
- </section>
- </section>
-
-
- {#if !isFirefox && installDate != null && daysSince(installDate) > 14 && hasBeenReviewed === false}
- <section class="bg-primary flex flex-row justify-between p-4">
- <div class="font-bold">
- It looks like you're enjoying Harper.<br>
- Would you mind giving us a review?
- </div>
- <Button on:click={openReviewPage}>
- Review
- </Button>
- </section>
- {:else}
- <section class="flex flex-row justify-between p-2 items-center">
- <p class="text-sm font-medium font-sans dark:text-white text-left">
- Does Harper work well on this site?
- </p>
-
- <div class="flex flex-row *:ml-1">
- <Button size="xs" on:click={() => reviewDomain(true)}>
- <Fa icon={faThumbsUp} />
- </Button>
- <Button size="xs" on:click={() => reviewDomain(false)}>
- <Fa icon={faThumbsDown} />
- </Button>
- </div>
- </section>
- {/if}
-</main>
+ <!-- Row Layout: power button left, greeting + status right -->
+ <div class="flex w-full flex-row items-center gap-5">
+
+ <!-- 1. Power Button -->
+ <Button
+ size="lg"
+ class="rounded-full! aspect-square h-24 w-24 shrink-0 p-0 shadow-lg transition-colors flex! flex-row items-center justify-center"
+ color={enabled ? 'var(--color-primary)' : 'var(--color-cream-50)'}
+ on:click={toggleDomainEnabled}
+ aria-pressed={enabled}
+ aria-label={enabled ? `Turn Harper off on ${site}` : `Turn Harper on for ${site}`}
+ title={enabled ? 'Click to pause Harper here' : 'Click to enable Harper here'}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ class="h-9 w-9"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ stroke-width="2"
+ style="color: {enabled ? 'var(--color-cream-50)' : 'var(--color-primary)'}"
+ aria-hidden="true"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ d="M12 5v7m5.657-4.657a8 8 0 11-11.314 0"
+ />
+ </svg>
+ </Button>
+
+ <!-- 2. Greeting + status -->
+ <div class="flex min-w-0 flex-1 flex-col items-start gap-2 text-left">
+
+ <!-- 1. Greeting -->
+ <h2 class="text-2xl font-medium dark:text-white">{generateGreeting()}</h2>
+
+ <!-- 2. Status Bar -->
+ <div
+ class="flex max-w-full items-start gap-2 text-sm text-gray-600 dark:text-gray-200"
+ title={site}
+ >
+ <span
+ class="mt-1.5 h-2 w-2 shrink-0 rounded-full {enabled ? 'bg-emerald-400 shadow-[0_0_6px_1px_rgba(52,211,153,0.4)]' : 'bg-slate-500'}"
+ aria-hidden="true"
+ ></span>
+ <span class="min-w-0">
+ <span class="font-medium text-gray-500 dark:text-white/80">
+ {enabled ? 'Harper is enabled on' : 'Harper is paused on'}
+ </span>
+ <span class="block font-semibold text-gray-900 [overflow-wrap:anywhere] dark:text-white">{site}</span>
+ </span>
+ </div>
+
+ </div>
+
+ </div>
+ </section>
+
+ {#if !isFirefox && installDate != null && daysSince(installDate) > 14 && hasBeenReviewed === false}
+ <section class="flex shrink-0 flex-row items-center justify-between gap-3 bg-primary px-5 py-3 text-black">
+ <div class="text-sm font-semibold leading-snug">
+ Enjoying Harper? A quick review helps a lot.
+ </div>
+ <Button on:click={openReviewPage}>Review</Button>
+ </section>
+ {:else}
+ <!-- Review Section pinned at bottom -->
+ <section
+ class="flex shrink-0 flex-row items-center justify-between gap-3 border-t border-gray-100 px-5 py-3 dark:border-slate-800 dark:bg-slate-900/50"
+ >
+ <p class="whitespace-nowrap text-sm font-medium dark:text-slate-200">
+ Does Harper work well here?
+ </p>
+
+ <div class="flex w-24 shrink-0 flex-row rounded-md border border-gray-200 p-0.5 dark:border-slate-700 dark:bg-slate-900">
+ <button
+ type="button"
+ aria-label="Harper works well on this site"
+ title="Works well"
+ class="flex flex-1 cursor-pointer items-center justify-center rounded-sm py-1.5 text-sm text-gray-600 transition-colors hover:bg-primary hover:text-black dark:text-gray-300 dark:hover:text-black"
+ onclick={() => reviewDomain(true)}
+ >
+ <Fa icon={faThumbsUp} />
+ </button>
+ <button
+ type="button"
+ aria-label="Harper has problems on this site"
+ title="Has problems"
+ class="flex flex-1 cursor-pointer items-center justify-center rounded-sm py-1.5 text-sm text-gray-600 transition-colors hover:bg-primary hover:text-black dark:text-gray-300 dark:hover:text-black"
+ onclick={() => reviewDomain(false)}
+ >
+ <Fa icon={faThumbsDown} />
+ </button>
+ </div>
+ </section>
+ {/if}
+ {/if}
+</main>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/popup/Onboarding.svelte b/packages/chrome-plugin/src/popup/Onboarding.svelte
index 2ae5acef3..fc22825ed 100644
--- a/packages/chrome-plugin/src/popup/Onboarding.svelte
+++ b/packages/chrome-plugin/src/popup/Onboarding.svelte
@@ -1,32 +1,61 @@
<script lang="ts">
-import { Badge, Button } from 'components';
+import { Button } from 'components';
let { onConfirm }: { onConfirm: () => void } = $props();
+let isConfirming = $state(false);
+
const steps = [
'Start typing in any large text box — emails, docs, blog posts, you name it.',
'Keep writing — Harper quietly highlights potential hiccups as you go.',
- 'Click a highlight to open focused, context‑aware suggestions.',
+ 'Click a highlight to open focused, context-aware suggestions.',
];
+
+function handleStart() {
+ if (isConfirming) return;
+ isConfirming = true;
+ // Allow button press state/animation to register briefly before transitioning views
+ setTimeout(() => {
+ onConfirm();
+ }, 180);
+}
</script>
-<main class="p-6 space-y-6">
- <h2 class="text-base font-semibold">
- Welcome! Let’s see Harper in action:
- </h2>
+<main class="flex h-full flex-col justify-between px-5 py-4 select-none">
+ <div class="space-y-4">
+ <div>
+ <h2 class="text-base font-semibold dark:text-white">
+ Welcome! Let’s see Harper in action:
+ </h2>
+ <p class="mt-0.5 text-xs text-gray-500 dark:text-slate-400">
+ Three quick tips to get the most out of your writing assistant.
+ </p>
+ </div>
- <ul class="space-y-6">
- {#each steps as line, i}
- <li class="flex gap-4 items-start">
- <Badge class="w-8 h-8 bg-primary-300 text-primary-900 font-semibold flex items-center justify-center rounded-lg dark:bg-slate-900 dark:text-slate-100">
- {i + 1}
- </Badge>
- <p class="text-sm text-gray-700 dark:text-slate-300">{line}</p>
- </li>
- {/each}
- </ul>
+ <ul class="space-y-3.5 pt-1">
+ {#each steps as line, i}
+ <li class="flex items-start gap-3">
+ <span
+ class="mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-primary/15 text-xs font-bold text-primary ring-1 ring-primary/30 dark:bg-primary/20 dark:text-primary dark:ring-primary/40"
+ >
+ {i + 1}
+ </span>
+ <p class="text-sm leading-relaxed text-gray-700 dark:text-slate-300">
+ {line}
+ </p>
+ </li>
+ {/each}
+ </ul>
+ </div>
- <Button color="primary" class="w-full h-10" on:click={onConfirm}>
- Let's start writing
- </Button>
-</main>
+ <div class="pt-3">
+ <Button
+ color="primary"
+ class="h-9 w-full text-xs font-semibold bg-primary! text-black! hover:bg-primary/85!"
+ disabled={isConfirming}
+ on:click={handleStart}
+ >
+ {isConfirming ? 'Getting started...' : "Let's start writing"}
+ </Button>
+ </div>
+</main>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/popup/Popup.svelte b/packages/chrome-plugin/src/popup/Popup.svelte
index a9844c4ac..d751ca516 100644
--- a/packages/chrome-plugin/src/popup/Popup.svelte
+++ b/packages/chrome-plugin/src/popup/Popup.svelte
@@ -2,6 +2,7 @@
import { faArrowLeft } from '@fortawesome/free-solid-svg-icons';
import { Button, Link } from 'components';
import { onMount } from 'svelte';
+import { fly } from 'svelte/transition';
import Fa from 'svelte-fa';
import logo from '/logo.png';
import detectBrowserEngine from '../detectBrowserEngine';
@@ -17,6 +18,14 @@ let version = `v${chrome.runtime.getManifest().version}`;
let latestVersion: string | null = $state(null);
let versionMismatch = $state(false);
+let hoveredFooterIndex = $state<number | null>(null);
+let activeFooterIndex = $state<number>(0);
+
+function handleMouseEnter(index: number) {
+ activeFooterIndex = index;
+ hoveredFooterIndex = index;
+}
+
onMount(async () => {
try {
const response = await fetch('https://writewithharper.com/latestversion');
@@ -57,43 +66,165 @@ function openUpdateHelpPage() {
url,
});
}
+
+// Per-page heights: compact for the main view, taller for forms.
+const PAGE_HEIGHTS: Record<string, number> = { main: 410, 'report-error': 580 };
+let heightPx = $derived(PAGE_HEIGHTS[popupState.page] ?? 500);
+const WIDTH_PX = 340;
+
+// Browser popups size themselves to the document, and stale CSS (e.g. #app min-h-screen) can keep
+// them at the larger size. Setting the size explicitly forces the popup to resize.
+$effect(() => {
+ const app = document.getElementById('app'); // global CSS gives #app min-h-screen
+ for (const el of [document.documentElement, document.body, app]) {
+ if (!el) continue;
+ el.style.width = `${WIDTH_PX}px`;
+ el.style.height = `${heightPx}px`;
+ el.style.minHeight = '0';
+ el.style.margin = '0';
+ el.style.overflow = 'hidden';
+ }
+});
+
+const footerLink = 'text-xs text-gray-500 dark:text-slate-400 no-underline!';
</script>
-<div class="w-[340px] border border-gray-200 font-sans flex flex-col rounded-lg shadow-sm select-none dark:border-slate-800 dark:text-slate-100">
- <header class="flex flex-row justify-between items-center gap-2 px-3 py-2 rounded-t-lg">
- <div class="flex flex-row justify-start items-center gap-1">
- <img src={logo} alt="Harper logo" class="h-6 w-auto rounded-lg mx-2" />
- <span class="font-semibold text-sm">Harper</span>
- </div>
+<div
+ style="width: {WIDTH_PX}px; height: {heightPx}px;"
+ class="font-sans flex flex-col select-none overflow-hidden rounded-xl border border-gray-200 dark:border-slate-800 dark:text-slate-100"
+>
+ <header
+ class="flex shrink-0 flex-row items-center justify-between gap-2 border-b border-gray-100 px-4 py-3 dark:border-slate-800"
+ >
+ <div class="flex flex-row items-center gap-2.5">
+ <img src={logo} alt="Harper logo" class="h-6 w-6 rounded-md" />
+ <span class="text-sm font-semibold tracking-tight">Harper</span>
+ </div>
+
+ {#if popupState.page != 'main'}
+ <Button
+ class="bg-primary! text-black! hover:bg-primary/85!"
+ on:click={() => {
+ popupState = main();
+ }}
+ >
+ <Fa icon={faArrowLeft} />
+ </Button>
+ {:else}
+ <button
+ type="button"
+ class="flex cursor-pointer items-center gap-1 rounded-md px-1.5 py-0.5 font-mono text-xs transition-colors
+ {versionMismatch
+ ? 'border border-primary text-primary hover:bg-primary hover:text-black'
+ : 'text-gray-500 hover:text-gray-900 dark:text-slate-400 dark:hover:text-white'}"
+ onclick={openUpdateHelpPage}
+ title={versionMismatch
+ ? `Newer version available: ${latestVersion ?? ''}. Click to find out more.`
+ : 'How to update'}
+ >
+ {#if versionMismatch}
+ <span class="text-xs" aria-label="Update available">⚠️</span>
+ {/if}
+ <span class="text-xs font-mono">{version}</span>
+ </button>
+ {/if}
+ </header>
- {#if popupState.page != "main"}
- <Button on:click={() => {
- popupState = main();
- }}><Fa icon={faArrowLeft}/></Button>
- {:else}
- <button type="button" class="cursor-pointer" onclick={openUpdateHelpPage}>
- {#if versionMismatch}
- <span class="ml-1" title={`Newer version available: ${latestVersion ?? ''}. Click to find out more.`}>⚠️</span>
+ <!-- Flex container ensuring children take up full available height -->
+ <div class="relative flex min-h-0 flex-1 flex-col overflow-hidden">
+ {#if popupState.page == 'onboarding'}
+ <div class="flex h-full flex-col" in:fly={{ y: 12, duration: 250 }}>
+ <Onboarding
+ onConfirm={() => {
+ popupState = main();
+ }}
+ />
+ </div>
+ {:else if popupState.page == 'main'}
+ <div class="flex h-full flex-col" in:fly={{ y: 12, duration: 250 }}>
+ <Main
+ onReviewDomain={(works, domain) => {
+ popupState = { page: 'domain-review', works, domain, feedback: '' };
+ }}
+ />
+ </div>
+ {:else if popupState.page == 'report-error'}
+ <div class="flex h-full flex-col" in:fly={{ y: 12, duration: 250 }}>
+ <ReportProblematicLint
+ example={popupState.example}
+ rule_id={popupState.rule_id}
+ feedback={popupState.feedback}
+ onSubmit={() => {
+ popupState = main();
+ }}
+ />
+ </div>
+ {:else if popupState.page == 'domain-review'}
+ <div class="flex h-full flex-col" in:fly={{ y: 12, duration: 250 }}>
+ <DomainReview
+ works={popupState.works}
+ domain={popupState.domain}
+ feedback={popupState.feedback}
+ onSubmit={() => {
+ popupState = main();
+ }}
+ />
+ </div>
{/if}
- <span class="text-sm font-mono">{version}</span>
- </button>
- {/if}
- </header>
-
- {#if popupState.page == "onboarding"}
- <Onboarding onConfirm={() => { popupState = main();}} />
- {:else if popupState.page == "main"}
- <Main onReviewDomain={(works, domain) => { popupState = { page: 'domain-review', works, domain, feedback: "" }} }/>
- {:else if popupState.page == 'report-error'}
- <ReportProblematicLint example={popupState.example} rule_id={popupState.rule_id} feedback={popupState.feedback} onSubmit={() => { popupState = main();}} />
- {:else if popupState.page == 'domain-review'}
- <DomainReview works={popupState.works} domain={popupState.domain} feedback={popupState.feedback} onSubmit={() => { popupState = main();}} />
- {/if}
-
- <footer class="flex items-center justify-center gap-6 px-3 py-2 text-sm border-t border-gray-100 rounded-b-lg bg-white/60 dark:border-slate-800 dark:bg-slate-900/70 dark:text-slate-100">
- <Link href="https://github.com/Automattic/harper" target="_blank" rel="noopener" class="text-primary">GitHub</Link>
- <Link href="https://discord.com/invite/JBqcAaKrzQ" target="_blank" rel="noopener" class="text-primary">Discord</Link>
- <Link href="https://writewithharper.com" target="_blank" rel="noopener" class="text-primary">Discover</Link>
- <Link on:click={openSettings}>Settings</Link>
- </footer>
-</div>
+ </div>
+
+ <footer
+ class="border-t border-gray-100 bg-white/60 p-1.5 dark:border-slate-800 dark:bg-slate-900/70"
+ onmouseleave={() => (hoveredFooterIndex = null)}
+ >
+ <div class="relative flex w-full items-center">
+ <!-- Gliding Orange Hover Pill -->
+ <div
+ class="absolute inset-y-0 left-0 w-1/4 rounded-md bg-primary transition-all duration-300 ease-out"
+ style="transform: translateX(calc({activeFooterIndex} * 100%)); opacity: {hoveredFooterIndex === null ? 0 : 1};"
+ ></div>
+
+ <Link
+ href="https://github.com/Automattic/harper"
+ target="_blank"
+ rel="noopener"
+ class="relative z-10 flex-1 rounded-md py-1 text-center font-medium no-underline! transition-colors duration-200 {footerLink} {hoveredFooterIndex === 0 ? 'text-black! font-semibold' : ''}"
+ style="text-decoration: none;"
+ onmouseenter={() => handleMouseEnter(0)}
+ >
+ GitHub
+ </Link>
+
+ <Link
+ href="https://discord.com/invite/JBqcAaKrzQ"
+ target="_blank"
+ rel="noopener"
+ class="relative z-10 flex-1 rounded-md py-1 text-center font-medium no-underline! transition-colors duration-200 {footerLink} {hoveredFooterIndex === 1 ? 'text-black! font-semibold' : ''}"
+ style="text-decoration: none;"
+ onmouseenter={() => handleMouseEnter(1)}
+ >
+ Discord
+ </Link>
+
+ <Link
+ href="https://writewithharper.com"
+ target="_blank"
+ rel="noopener"
+ class="relative z-10 flex-1 rounded-md py-1 text-center font-medium no-underline! transition-colors duration-200 {footerLink} {hoveredFooterIndex === 2 ? 'text-black! font-semibold' : ''}"
+ style="text-decoration: none;"
+ onmouseenter={() => handleMouseEnter(2)}
+ >
+ Discover
+ </Link>
+
+ <button
+ type="button"
+ onclick={openSettings}
+ class="relative z-10 flex-1 cursor-pointer rounded-md bg-transparent py-1 text-center font-medium transition-colors duration-200 text-xs no-underline! {hoveredFooterIndex === 3 ? 'text-black! font-semibold' : 'text-primary dark:text-white'}"
+ onmouseenter={() => handleMouseEnter(3)}
+ >
+ Settings
+ </button>
+ </div>
+ </footer>
+</div>
\ No newline at end of file
diff --git a/packages/chrome-plugin/src/popup/ReportProblematicLint.svelte b/packages/chrome-plugin/src/popup/ReportProblematicLint.svelte
index 4add8f715..ba39fd14c 100644
--- a/packages/chrome-plugin/src/popup/ReportProblematicLint.svelte
+++ b/packages/chrome-plugin/src/popup/ReportProblematicLint.svelte
@@ -11,11 +11,13 @@ let {
let submitting = $state(false);
let successful = $state(false);
+let failed = $state(false);
async function handleSubmit(event: SubmitEvent) {
event.preventDefault();
submitting = true;
+ failed = false;
const success = await ProtocolClient.postFormData(
'https://writewithharper.com/api/problematic-lints',
@@ -30,54 +32,85 @@ async function handleSubmit(event: SubmitEvent) {
submitting = false;
if (success) {
- onSubmit();
successful = true;
+ setTimeout(onSubmit, 1200);
+ } else {
+ failed = true;
}
}
+
+// The `!` suffix is needed: the shared Input component ships its own orange-tinted
+// background/border, which otherwise wins over these utilities. Colors deliberately avoid
+// `dark:` variants (they don't apply reliably here): the tinted fill, inherited text color and
+// translucent border read correctly on both light and dark popup backgrounds.
+const inputClass =
+ 'w-full bg-slate-500/10! border-slate-500/40! text-inherit! caret-primary ' +
+ 'placeholder:text-primary/70! placeholder:opacity-100 ' +
+ 'focus:border-primary! focus:ring-1 focus:ring-primary';
+const textareaClass = `min-h-14 flex-1 resize-none rounded-lg border px-3 py-2 text-sm leading-snug outline-none! transition-colors ${inputClass}`;
+const labelClass = 'shrink-0 text-xs! font-medium! leading-none text-inherit!';
</script>
-<div class="p-5">
- <h1 class="text-2xl font-semibold">Report Problematic Lint</h1>
- <p class="text-sm">
- Only the data you enter below will be sent to the Harper maintainer.
- </p>
- <form class="mt-4 space-y-6" onsubmit={handleSubmit}>
- <div class="space-y-3">
- <div class="flex items-baseline gap-2">
- <Label class=" ">What text caused (or should cause) feedback from Harper?</Label>
- </div>
- <Input
+<form class="flex h-full min-h-0 flex-col" onsubmit={handleSubmit}>
+ <!-- Fixed intro, so the title never scrolls under the header -->
+ <div class="shrink-0 px-5 pt-3 pb-2.5">
+ <h1 class="font-sans! text-xl font-semibold tracking-tight ">
+ Report Problematic Lint
+ </h1>
+ <p class="mt-1 text-xs leading-snug opacity-70">
+ Only the data you enter below will be sent to the Harper maintainer.
+ </p>
+ </div>
+
+ <!-- Compact fields: sized to fit the popup without scrolling -->
+ <div class="flex min-h-0 flex-1 flex-col gap-3 px-5 pb-3">
+ <Checkbox name="is_false_positive" value="true" hidden />
+
+ <div class="flex min-h-0 flex-1 flex-col gap-1.5">
+ <Label class={labelClass}>What text caused (or should cause) feedback from Harper?</Label>
+ <textarea
name="example"
bind:value={example}
- placeholder="Give us an example."
- class="dark:bg-slate-900 dark:border-slate-700 "
- />
-
- <Checkbox name="is_false_positive" value="true" hidden />
+ placeholder="Paste the text, plus any context that helps."
+ class={textareaClass}
+ ></textarea>
+ </div>
- <div class="flex items-baseline gap-2">
- <Label class=" ">What rule caused (or should cause) feedback from Harper?</Label>
- </div>
- <Input
+ <div class="flex min-h-0 flex-1 flex-col gap-1.5">
+ <Label class={labelClass}>What rule caused (or should cause) feedback from Harper?</Label>
+ <textarea
name="rule_id"
- placeholder="We'd appreciate the specific rule ID, if applicable."
bind:value={rule_id}
- class="dark:bg-slate-900 dark:border-slate-700 "
- />
+ placeholder="Rule ID, and anything else worth knowing."
+ class={textareaClass}
+ ></textarea>
+ </div>
- <div class="flex items-baseline gap-2">
- <Label class=" ">Additional Feedback</Label>
- </div>
+ <div class="flex shrink-0 flex-col gap-1.5">
+ <Label class={labelClass}>Additional Feedback</Label>
<Input
name="feedback"
- placeholder="Anything you want to add?"
bind:value={feedback}
- class="dark:bg-slate-900 dark:border-slate-700 "
+ placeholder="Anything you want to add?"
+ class={inputClass}
/>
-
- <div class="flex items-center justify-between pt-2">
- <Button state={submitting ? (successful ? "success" : "loading") : "idle"} type="submit" disabled={submitting}>Submit</Button>
- </div>
</div>
- </form>
-</div>
+ </div>
+
+ {#if failed}
+ <p class="shrink-0 px-5 pb-2 text-xs text-red-500 dark:text-red-400" role="alert">
+ Couldn't send your report. Please try again.
+ </p>
+ {/if}
+
+ <div class="shrink-0 px-5 pb-4">
+ <Button
+ class="w-full shrink-0 {successful ? '' : 'bg-primary! text-black! hover:bg-primary/85!'} ring-0! focus:ring-0! focus-visible:ring-0! focus:shadow-none! focus-visible:shadow-none! focus-visible:outline! focus-visible:outline-1! focus-visible:outline-offset-2! focus-visible:outline-primary!"
+ state={successful ? 'success' : submitting ? 'loading' : 'idle'}
+ type="submit"
+ disabled={submitting || successful}
+ >
+ {successful ? 'Sent. Thank you!' : 'Send report'}
+ </Button>
+ </div>
+</form>
\ No newline at end of file
diff --git a/packages/chrome-plugin/tests/options_structured_rules.spec.ts b/packages/chrome-plugin/tests/options_structured_rules.spec.ts
index fa8d9825e..0589ac043 100644
--- a/packages/chrome-plugin/tests/options_structured_rules.spec.ts
+++ b/packages/chrome-plugin/tests/options_structured_rules.spec.ts
@@ -1,14 +1,19 @@
+import type { Page } from '@playwright/test';
import { expect, test } from './fixtures';
import { getStoredLintConfig, openExtensionPage } from './testUtils';
const STYLE_CATEGORY = 'Style and Redundancy';
const STYLE_DESCRIPTION =
'Highlights wordy, repetitive, or overly weak phrasing that can usually be tightened up.';
-const STYLE_BUTTON_TITLE = `Expand the ${STYLE_CATEGORY} category`;
-const STYLE_BUTTON_COLLAPSE_TITLE = `Collapse the ${STYLE_CATEGORY} category`;
const STYLE_DROPDOWN_TITLE = `Set all rules in the ${STYLE_CATEGORY} category to their default, on, or off state.`;
const REPEATED_WORDS_TITLE = 'Set Repeated Words to its default, on, or off state.';
+/** The category disclosure button (name comes from the category label; state from aria-expanded). */
+const styleToggle = (page: Page, expanded: boolean) =>
+ page.getByRole('button', { name: STYLE_CATEGORY, exact: true, expanded });
+
+const searchBox = (page: Page) => page.getByLabel('Search rules', { exact: true });
+
test.describe('structured rule settings', () => {
test.describe.configure({ mode: 'serial' });
test.setTimeout(90_000);
@@ -23,9 +28,8 @@ test.describe('structured rule settings', () => {
}) => {
await openExtensionPage(context, page, 'options.html');
- await expect(page.getByTitle(STYLE_BUTTON_TITLE)).toBeVisible({ timeout: 15000 });
+ await expect(styleToggle(page, false)).toBeVisible({ timeout: 15000 });
await expect(page.getByTitle(STYLE_DROPDOWN_TITLE)).toBeVisible({ timeout: 15000 });
- await expect(page.locator('h3', { hasText: STYLE_CATEGORY })).toBeVisible({ timeout: 15000 });
await expect(page.getByText(STYLE_DESCRIPTION)).toBeVisible({ timeout: 15000 });
await expect(page.locator('h3', { hasText: 'Repeated Words' })).toHaveCount(0);
});
@@ -33,21 +37,35 @@ test.describe('structured rule settings', () => {
test('expands categories and indents nested rules', async ({ context, page }) => {
await openExtensionPage(context, page, 'options.html');
- await page.getByTitle(STYLE_BUTTON_TITLE).click();
+ await styleToggle(page, false).click();
+
+ await expect(styleToggle(page, true)).toBeVisible();
await expect(page.locator('[style*="padding-left: 1.5rem"]').first()).toBeVisible();
+
+ await styleToggle(page, true).click();
+ await expect(styleToggle(page, false)).toBeVisible();
});
test('search expands matching categories and reveals nested rules', async ({ context, page }) => {
await openExtensionPage(context, page, 'options.html');
await expect(page.getByTitle(STYLE_DROPDOWN_TITLE)).toBeVisible({ timeout: 15000 });
- await page.getByPlaceholder('Search for a rule…').fill('wordy');
+ await searchBox(page).fill('wordy');
- await expect(page.locator('h3', { hasText: STYLE_CATEGORY })).toBeVisible();
+ await expect(styleToggle(page, true)).toBeVisible();
await expect(page.getByText(STYLE_DESCRIPTION)).toBeVisible();
await expect(page.getByTitle(REPEATED_WORDS_TITLE)).toBeVisible({ timeout: 15000 });
});
+ test('search with no matches shows an empty state', async ({ context, page }) => {
+ await openExtensionPage(context, page, 'options.html');
+ await expect(page.getByTitle(STYLE_DROPDOWN_TITLE)).toBeVisible({ timeout: 15000 });
+
+ await searchBox(page).fill('zzzz-no-such-rule');
+
+ await expect(page.getByText('No rules match your search.')).toBeVisible();
+ });
+
test('category dropdown bulk updates constituent flat rules', async ({ context, page }) => {
await openExtensionPage(context, page, 'options.html');
@@ -90,7 +108,7 @@ test.describe('structured rule settings', () => {
await openExtensionPage(context, page, 'options.html');
await expect(page.getByTitle(STYLE_DROPDOWN_TITLE)).toBeVisible({ timeout: 15000 });
- await page.getByPlaceholder('Search for a rule…').fill('Repeated Words');
+ await searchBox(page).fill('Repeated Words');
await expect(page.getByTitle(REPEATED_WORDS_TITLE)).toBeVisible({ timeout: 15000 });
await page.getByTitle(REPEATED_WORDS_TITLE).selectOption('disable');
diff --git a/packages/chrome-plugin/tests/review_banner.spec.ts b/packages/chrome-plugin/tests/review_banner.spec.ts
index db838dd2f..68ab22ea9 100644
--- a/packages/chrome-plugin/tests/review_banner.spec.ts
+++ b/packages/chrome-plugin/tests/review_banner.spec.ts
@@ -13,8 +13,8 @@ test.describe('review banner', () => {
await page.getByText("Let's start writing").click();
- await expect(page.getByText('Harper is')).toBeVisible();
- await expect(page.getByText('Would you mind giving us a review?')).toHaveCount(0);
+ await expect(page.getByRole('button', { name: /^Turn Harper (on|off)/ })).toBeVisible();
+ await expect(page.getByText('Enjoying Harper? A quick review helps a lot.')).toHaveCount(0);
});
test('review request shown after 14 days', async ({ context, page }) => {
@@ -45,9 +45,9 @@ test.describe('review banner', () => {
await page.getByText("Let's start writing").click();
- await expect(page.getByText('Harper is')).toBeVisible();
+ await expect(page.getByRole('button', { name: /^Turn Harper (on|off)/ })).toBeVisible();
// WASM startup can delay replies; test.slow() does not extend assertion timeouts.
- await expect(page.getByText('Would you mind giving us a review?')).toHaveCount(1, {
+ await expect(page.getByText('Enjoying Harper? A quick review helps a lot.')).toHaveCount(1, {
timeout: 30000,
});
});
diff --git a/packages/chrome-plugin/tsconfig.json b/packages/chrome-plugin/tsconfig.json
index 09099555a..4837abc82 100644
--- a/packages/chrome-plugin/tsconfig.json
+++ b/packages/chrome-plugin/tsconfig.json
@@ -3,10 +3,10 @@
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
+ "types": ["svelte", "vite/client", "chrome"],
"allowJs": false,
"skipLibCheck": true,
"verbatimModuleSyntax": true,
- "esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e35b1afb0..3351d2782 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -80,7 +80,7 @@ importers:
version: 5.43.12
svelte-check:
specifier: ^4.0.0
tailwindcss:
specifier: ^4.2.2
version: 4.2.4
@@ -11570,8 +11570,8 @@ packages:
resolution: {integrity: sha512-tDuKQJUTfjvi9Fcrs1s6YAQAB9mzhTSbBZMfNgtWNmJlHuoFeXO6dzBFdGeCWRvYL50jQGK0jPsBZYxqZQJ2SA==}
- resolution: {integrity: sha512-fegtha91tq2DHphyoiBXVHjVi2YG9zFaRnboT9C28tO1en9Y3wJsfspuy40F+u5wl3hHVbw7cnd1b67kEGHb8g==}
+ resolution: {integrity: sha512-p+PfyL5U0ediGzvwPzMSdD9MnC8rHW6nWJJVLIQvqN7RsSqfaZ+7n4c9GILqH36EYR0eXB9CzAeCRnKFr/9uJg==}
resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==}
@@ -15691,7 +15691,7 @@ snapshots:
'@paulirish/[email protected]':
dependencies:
- third-party-web: 0.29.2
+ third-party-web: 0.30.0
'@php-wasm/[email protected]': {}
@@ -26333,6 +26333,18 @@ snapshots:
brace: 0.11.1
sirv-cli: 1.0.14
+ dependencies:
+ '@jridgewell/trace-mapping': 0.3.25
+ chokidar: 4.0.3
+ fdir: 6.4.4([email protected])
+ picocolors: 1.1.1
+ sade: 1.8.1
+ svelte: 5.43.12
+ typescript: 5.6.3
+ transitivePeerDependencies:
+ - picomatch
+
dependencies:
'@jridgewell/trace-mapping': 0.3.25
@@ -26563,7 +26575,7 @@ snapshots: