diff --git a/src/lib/components/common/ActionButton.svelte b/src/lib/components/common/ActionButton.svelte new file mode 100644 index 0000000..b137325 --- /dev/null +++ b/src/lib/components/common/ActionButton.svelte @@ -0,0 +1,44 @@ + + + + + diff --git a/src/lib/components/common/ErrorCard.svelte b/src/lib/components/common/ErrorCard.svelte new file mode 100644 index 0000000..dca77a9 --- /dev/null +++ b/src/lib/components/common/ErrorCard.svelte @@ -0,0 +1,29 @@ + + +{#if error} +
+
+
+ +
+ {title} +

{error}

+
+
+
+
+{/if} + + diff --git a/src/lib/components/common/ExamplesCard.svelte b/src/lib/components/common/ExamplesCard.svelte new file mode 100644 index 0000000..ce6b636 --- /dev/null +++ b/src/lib/components/common/ExamplesCard.svelte @@ -0,0 +1,51 @@ + + +
+
+ + +

{title}

+
+
+ {#each examples as example, i (i)} + + {/each} +
+
+
+ + diff --git a/src/lib/components/common/ResultsCard.svelte b/src/lib/components/common/ResultsCard.svelte new file mode 100644 index 0000000..8cfd8a3 --- /dev/null +++ b/src/lib/components/common/ResultsCard.svelte @@ -0,0 +1,45 @@ + + +
+
+

{title}

+ {#if showCopyButton && onCopy} + + {/if} +
+
+ {@render children()} +
+
+ + diff --git a/src/lib/components/common/StatusOverview.svelte b/src/lib/components/common/StatusOverview.svelte new file mode 100644 index 0000000..f17b867 --- /dev/null +++ b/src/lib/components/common/StatusOverview.svelte @@ -0,0 +1,39 @@ + + +
+ {#each items as item (item.label)} +
+ +
+ {item.value} +
{item.label}
+
+
+ {/each} +
+ + diff --git a/src/lib/components/common/WarningCard.svelte b/src/lib/components/common/WarningCard.svelte new file mode 100644 index 0000000..635f2b9 --- /dev/null +++ b/src/lib/components/common/WarningCard.svelte @@ -0,0 +1,38 @@ + + +{#if warnings.length > 0} +
+
+
+ +
+ {#if title} + {title} + {/if} + {#each warnings as warning (warning)} +

{warning}

+ {/each} +
+
+
+
+{/if} + + diff --git a/src/lib/components/global/Icon.svelte b/src/lib/components/global/Icon.svelte index cb919c2..e438dd8 100644 --- a/src/lib/components/global/Icon.svelte +++ b/src/lib/components/global/Icon.svelte @@ -18,7 +18,7 @@ xl: 'w-10 h-10', }; - type IconName = keyof typeof iconMap; + export type IconName = keyof typeof iconMap; /** * Get SVG content for the given icon name diff --git a/src/lib/components/tools/IPDistance.svelte b/src/lib/components/tools/IPDistance.svelte index 69f3dbc..20cb82d 100644 --- a/src/lib/components/tools/IPDistance.svelte +++ b/src/lib/components/tools/IPDistance.svelte @@ -240,7 +240,7 @@
- + Calculating distances...
diff --git a/src/lib/components/tools/NthIP.svelte b/src/lib/components/tools/NthIP.svelte index 620bb61..42c9cd8 100644 --- a/src/lib/components/tools/NthIP.svelte +++ b/src/lib/components/tools/NthIP.svelte @@ -221,7 +221,7 @@
- + Calculating IPs...
diff --git a/src/lib/composables/index.ts b/src/lib/composables/index.ts new file mode 100644 index 0000000..d59157c --- /dev/null +++ b/src/lib/composables/index.ts @@ -0,0 +1,7 @@ +// Central export file for all composables +export { useClipboard } from './useClipboard.svelte.js'; +export { useDiagnosticState } from './useDiagnosticState.svelte.js'; +export { useExamples } from './useExamples.svelte.js'; + +// Re-export types +export type { DiagnosticState } from './useDiagnosticState.svelte.js'; diff --git a/src/lib/composables/useClipboard.svelte.ts b/src/lib/composables/useClipboard.svelte.ts new file mode 100644 index 0000000..a7ce424 --- /dev/null +++ b/src/lib/composables/useClipboard.svelte.ts @@ -0,0 +1,58 @@ +/** + * Clipboard composable for copying text with auto-reset feedback + * Replaces the repeated copiedState pattern across 81+ files + */ + +export function useClipboard(autoResetMs: number = 1500) { + let copiedStates = $state>({}); + + /** + * Copy text to clipboard with feedback + * @param text - Text to copy + * @param id - Unique identifier for this copy action (optional) + */ + async function copy(text: string, id: string = 'default') { + try { + await navigator.clipboard.writeText(text); + copiedStates[id] = true; + setTimeout(() => { + copiedStates[id] = false; + }, autoResetMs); + return true; + } catch (error) { + console.error('Failed to copy to clipboard:', error); + return false; + } + } + + /** + * Check if a specific copy action is in "copied" state + */ + function isCopied(id: string = 'default'): boolean { + return copiedStates[id] ?? false; + } + + /** + * Reset a specific copy state + */ + function reset(id: string = 'default') { + copiedStates[id] = false; + } + + /** + * Reset all copy states + */ + function resetAll() { + copiedStates = {}; + } + + return { + get copiedStates() { + return copiedStates; + }, + copy, + isCopied, + reset, + resetAll, + }; +} diff --git a/src/lib/composables/useDiagnosticState.svelte.ts b/src/lib/composables/useDiagnosticState.svelte.ts new file mode 100644 index 0000000..4b2e308 --- /dev/null +++ b/src/lib/composables/useDiagnosticState.svelte.ts @@ -0,0 +1,60 @@ +/** + * Common state management for diagnostic/tool pages + * Replaces the repeated state pattern across 80+ files + */ + +export interface DiagnosticState { + loading: boolean; + error: string | null; + results: T | null; +} + +export function useDiagnosticState() { + let loading = $state(false); + let error = $state(null); + let results = $state(null); + + function setLoading(value: boolean) { + loading = value; + } + + function setError(errorMessage: string | null) { + error = errorMessage; + loading = false; + } + + function setResults(data: T | null) { + results = data; + error = null; + loading = false; + } + + function reset() { + loading = false; + error = null; + results = null; + } + + function startOperation() { + loading = true; + error = null; + results = null; + } + + return { + get loading() { + return loading; + }, + get error() { + return error; + }, + get results() { + return results; + }, + setLoading, + setError, + setResults, + reset, + startOperation, + }; +} diff --git a/src/lib/composables/useExamples.svelte.ts b/src/lib/composables/useExamples.svelte.ts new file mode 100644 index 0000000..0daaf5f --- /dev/null +++ b/src/lib/composables/useExamples.svelte.ts @@ -0,0 +1,35 @@ +/** + * Example selection management for diagnostic/tool pages + * Handles example loading and selection tracking + */ + +export function useExamples(examples: T[]) { + let selectedIndex = $state(null); + + function select(index: number) { + selectedIndex = index; + } + + function clear() { + selectedIndex = null; + } + + function isSelected(index: number): boolean { + return selectedIndex === index; + } + + function getSelected(): T | null { + if (selectedIndex === null) return null; + return examples[selectedIndex] ?? null; + } + + return { + get selectedIndex() { + return selectedIndex; + }, + select, + clear, + isSelected, + getSelected, + }; +} diff --git a/src/routes/diagnostics/dns/caa-effective/+page.svelte b/src/routes/diagnostics/dns/caa-effective/+page.svelte index 087c405..3e6b1a2 100644 --- a/src/routes/diagnostics/dns/caa-effective/+page.svelte +++ b/src/routes/diagnostics/dns/caa-effective/+page.svelte @@ -247,7 +247,7 @@
- {/each} -
- -
+ `${ex.domain} (${ex.type})`} + getDescription={(ex) => ex.description} + getTooltip={(ex) => `Query ${ex.type} records for ${ex.domain}`} + />
@@ -193,7 +175,7 @@ bind:value={domainName} placeholder="example.com" onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) performLookup(); }} /> @@ -208,7 +190,7 @@ id="type" bind:value={recordType} onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) performLookup(); }} > @@ -225,7 +207,7 @@ id="dns-resolver" bind:value={resolver} onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) performLookup(); }} > @@ -240,7 +222,7 @@ bind:value={customResolver} placeholder="8.8.8.8 or custom IP" onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) performLookup(); }} /> @@ -250,7 +232,7 @@ type="checkbox" bind:checked={useCustomResolver} onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) performLookup(); }} /> @@ -260,45 +242,32 @@
- + + Lookup DNS Records +
- {#if results?.warnings?.length > 0} -
-
-
- -
- {#each results.warnings as warning, index (index)} -

{warning}

- {/each} -
-
-
-
- {/if} + - {#if results?.noRecords} + {#if diagnosticState.results?.noRecords}
No Records Found -

{results.message}

-

Using resolver: {results.resolver}

+

{diagnosticState.results.message}

+

Using resolver: {diagnosticState.results.resolver}

@@ -306,72 +275,41 @@ {/if} - {#if results && !results.noRecords} -
-
-

DNS Records Found

- {#if results.Answer?.length > 0} - - {/if} -
-
- {#if results.Answer?.length > 0} -
- {#each results.Answer as record, i (i)} -
-
{record.data}
- {#if record.TTL} -
- TTL: {record.TTL}s -
- {/if} -
- {/each} -
- {:else} -
-
- -

No records found for {domainName} ({recordType})

+ {#if diagnosticState.results && !diagnosticState.results.noRecords} + 0} + > + {#if diagnosticState.results.Answer?.length > 0} +
+ {#each diagnosticState.results.Answer as record, i (i)} +
+
{record.data}
+ {#if record.TTL} +
+ TTL: {record.TTL}s +
+ {/if}
-
- {/if} -
-
- {/if} - - {#if error} -
-
-
- -
- Lookup Failed -

{error}

+ {/each} +
+ {:else} +
+
+ +

No records found for {domainName} ({recordType})

-
-
+ {/if} + {/if} + +
diff --git a/src/routes/diagnostics/dns/ns-soa-check/+page.svelte b/src/routes/diagnostics/dns/ns-soa-check/+page.svelte index 2b0980a..00f97c5 100644 --- a/src/routes/diagnostics/dns/ns-soa-check/+page.svelte +++ b/src/routes/diagnostics/dns/ns-soa-check/+page.svelte @@ -212,7 +212,7 @@
- {/each} -
- -
+ `${ex.domain} (${ex.type})`} + getDescription={(ex) => ex.description} + getTooltip={(ex) => `Check ${ex.type} record propagation for ${ex.domain}`} + />
@@ -193,7 +175,7 @@ bind:value={domainName} placeholder="example.com" onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) checkPropagation(); }} /> @@ -207,7 +189,7 @@ id="type" bind:value={recordType} onchange={() => { - clearExampleSelection(); + examples.clear(); if (domainName) checkPropagation(); }} > @@ -220,21 +202,22 @@
- + + Check DNS Propagation +
- {#if results} + {#if diagnosticState.results}
@@ -253,16 +236,16 @@ {/if}
-
- {#each results as result, resultIndex (resultIndex)} + {#each diagnosticState.results as result, resultIndex (resultIndex)} {@const res = result as { resolver: string }} {@const info = resolverInfo[res.resolver as keyof typeof resolverInfo]} {@const status = getStatusColor(result)} @@ -321,19 +304,7 @@
{/if} - {#if error} -
-
-
- -
- Propagation Check Failed -

{error}

-
-
-
-
- {/if} +
diff --git a/src/routes/diagnostics/dns/reverse-lookup/+page.svelte b/src/routes/diagnostics/dns/reverse-lookup/+page.svelte index d33b2d9..4322293 100644 --- a/src/routes/diagnostics/dns/reverse-lookup/+page.svelte +++ b/src/routes/diagnostics/dns/reverse-lookup/+page.svelte @@ -241,7 +241,7 @@ disabled={loading || !ipAddress.trim() || !isValidIP(ipAddress.trim())} > {#if loading} - + Performing Reverse Lookup... {:else} diff --git a/src/routes/diagnostics/dns/soa-serial/+page.svelte b/src/routes/diagnostics/dns/soa-serial/+page.svelte index a6553ac..9d82179 100644 --- a/src/routes/diagnostics/dns/soa-serial/+page.svelte +++ b/src/routes/diagnostics/dns/soa-serial/+page.svelte @@ -179,7 +179,7 @@
- {/each} -
- -
+ ex.domain} + getDescription={(ex) => ex.description} + getTooltip={(ex) => `Check DMARC policy for ${ex.domain}`} + />
@@ -173,7 +154,7 @@
-
-
- {#if results && results.hasRecord} + {#if diagnosticState.results && diagnosticState.results.hasRecord}

DMARC Policy Analysis

-
- {#if results.parsed && results.deliverabilityHints} + {#if diagnosticState.results.parsed && diagnosticState.results.deliverabilityHints}
-
- +
+

Email Deliverability Impact

-

{results.deliverabilityHints.policyImpact}

- {#if results.deliverabilityHints.alignmentComplexity?.strict} -

{results.deliverabilityHints.alignmentComplexity.strict}

+

{diagnosticState.results.deliverabilityHints.policyImpact}

+ {#if diagnosticState.results.deliverabilityHints.alignmentComplexity?.strict} +

+ {diagnosticState.results.deliverabilityHints.alignmentComplexity.strict} +

{/if}
- {#if results.deliverabilityHints.recommendations.length > 0} - {@const hintsData = (results as { deliverabilityHints: { recommendations: string[] } }) + {#if diagnosticState.results.deliverabilityHints.recommendations.length > 0} + {@const hintsData = (diagnosticState.results as { deliverabilityHints: { recommendations: string[] } }) .deliverabilityHints}
Deliverability Recommendations
@@ -250,7 +233,7 @@

DMARC Record

_dmarc.{domain}
- {results.record} + {diagnosticState.results.record}
@@ -259,19 +242,19 @@

Policy Configuration

-
+
Main Policy
- {results.parsed.policy} + {diagnosticState.results.parsed.policy} - {#if results.parsed.policy === 'reject'} + {#if diagnosticState.results.parsed.policy === 'reject'} Reject non-compliant messages - {:else if results.parsed.policy === 'quarantine'} + {:else if diagnosticState.results.parsed.policy === 'quarantine'} Quarantine suspicious messages - {:else if results.parsed.policy === 'none'} + {:else if diagnosticState.results.parsed.policy === 'none'} Monitor only, no action {:else} Unknown policy @@ -281,40 +264,46 @@
- {#if results.parsed.subdomainPolicy} -
+ {#if diagnosticState.results.parsed.subdomainPolicy} +
Subdomain Policy
- {results.parsed.subdomainPolicy} + {diagnosticState.results.parsed.subdomainPolicy}
{/if} -
+
Coverage
- {results.parsed.percentage}% + {diagnosticState.results.parsed.percentage}% of messages affected
-
+
DKIM Alignment
- {results.parsed.alignment.dkim === 's' ? 'Strict' : 'Relaxed'} + {diagnosticState.results.parsed.alignment.dkim === 's' ? 'Strict' : 'Relaxed'} - {results.parsed.alignment.dkim === 's' + {diagnosticState.results.parsed.alignment.dkim === 's' ? 'Exact domain match required' : 'Organizational domain match allowed'} @@ -322,15 +311,17 @@
-
+
SPF Alignment
- {results.parsed.alignment.spf === 's' ? 'Strict' : 'Relaxed'} + {diagnosticState.results.parsed.alignment.spf === 's' ? 'Strict' : 'Relaxed'} - {results.parsed.alignment.spf === 's' + {diagnosticState.results.parsed.alignment.spf === 's' ? 'Exact domain match required' : 'Organizational domain match allowed'} @@ -344,15 +335,15 @@ Failure Options
- {results.parsed.reporting.failureOptions} + {diagnosticState.results.parsed.reporting.failureOptions} - {#if results.parsed.reporting.failureOptions === '0'} + {#if diagnosticState.results.parsed.reporting.failureOptions === '0'} DKIM and SPF failure - {:else if results.parsed.reporting.failureOptions === '1'} + {:else if diagnosticState.results.parsed.reporting.failureOptions === '1'} Any alignment failure - {:else if results.parsed.reporting.failureOptions === 'd'} + {:else if diagnosticState.results.parsed.reporting.failureOptions === 'd'} DKIM failure only - {:else if results.parsed.reporting.failureOptions === 's'} + {:else if diagnosticState.results.parsed.reporting.failureOptions === 's'} SPF failure only {:else} Custom configuration @@ -373,8 +364,8 @@ Aggregate Reports (RUA)
- {#if results.parsed.reporting.aggregate} - + {#if diagnosticState.results.parsed.reporting.aggregate} + Daily summaries of DMARC activity {:else} Not configured @@ -389,8 +380,8 @@ Forensic Reports (RUF)
- {#if results.parsed.reporting.forensic} - + {#if diagnosticState.results.parsed.reporting.forensic} + Real-time failure reports with message samples {:else} Not configured @@ -406,7 +397,7 @@ {/if} - {#if results && results.hasRecord === false} + {#if diagnosticState.results && diagnosticState.results.hasRecord === false}
@@ -429,19 +420,7 @@
{/if} - {#if error} -
-
-
- -
- DMARC Check Failed -

{error}

-
-
-
-
- {/if} +
diff --git a/src/routes/diagnostics/email/greylist-tester/+page.svelte b/src/routes/diagnostics/email/greylist-tester/+page.svelte index 0e41a3c..cc38fe7 100644 --- a/src/routes/diagnostics/email/greylist-tester/+page.svelte +++ b/src/routes/diagnostics/email/greylist-tester/+page.svelte @@ -1,6 +1,8 @@ @@ -95,7 +94,7 @@ bind:value={domain} placeholder="mail.example.com" onkeydown={(e) => e.key === 'Enter' && checkTLS()} - disabled={loading} + disabled={diagnosticState.loading} /> -
- -
-
- - -

Quick Examples

-
-
- {#each examples as example (`${example.domain}:${example.port}`)} - - {/each} -
-
-
+ + `${ex.domain}:${ex.port}`} + getDescription={(ex) => ex.desc} + getTooltip={(ex) => `Check TLS for ${ex.domain} on port ${ex.port}`} + /> - {#if loading} + {#if diagnosticState.loading}
@@ -152,28 +143,18 @@
{/if} - - {#if error} -
-
-
- - {error} -
-
-
- {/if} + - {#if results} + {#if diagnosticState.results}
-

TLS Check Results for {results.domain}:{results.port}

+

TLS Check Results for {diagnosticState.results.domain}:{diagnosticState.results.port}

- {#if results.supportsSTARTTLS} + {#if diagnosticState.results.supportsSTARTTLS}
@@ -182,7 +163,7 @@
{/if} - {#if results.supportsDirectTLS} + {#if diagnosticState.results.supportsDirectTLS}
@@ -191,7 +172,7 @@
{/if} - {#if !results.supportsSTARTTLS && !results.supportsDirectTLS} + {#if !diagnosticState.results.supportsSTARTTLS && !diagnosticState.results.supportsDirectTLS}
@@ -203,23 +184,23 @@
- {#if results.tlsVersion || results.cipherSuite} + {#if diagnosticState.results.tlsVersion || diagnosticState.results.cipherSuite}

Connection Details

- {#if results.tlsVersion} + {#if diagnosticState.results.tlsVersion}
TLS Version - {results.tlsVersion} + {diagnosticState.results.tlsVersion}
{/if} - {#if results.cipherSuite} + {#if diagnosticState.results.cipherSuite}
Cipher Suite - {results.cipherSuite} + {diagnosticState.results.cipherSuite}
{/if}
@@ -227,7 +208,7 @@ {/if} - {#if results.certificate} + {#if diagnosticState.results.certificate}

@@ -236,38 +217,44 @@
Common Name - {results.certificate.commonName} + {diagnosticState.results.certificate.commonName}
Issuer - {results.certificate.issuer} + {diagnosticState.results.certificate.issuer}
Valid From - {new Date(results.certificate.validFrom).toLocaleDateString()} + {new Date(diagnosticState.results.certificate.validFrom).toLocaleDateString()}
Valid To - - {new Date(results.certificate.validTo).toLocaleDateString()} - {#if results.certificate.daysUntilExpiry < 30} - Expires in {results.certificate.daysUntilExpiry} days + + {new Date(diagnosticState.results.certificate.validTo).toLocaleDateString()} + {#if diagnosticState.results.certificate.daysUntilExpiry < 30} + Expires in {diagnosticState.results.certificate.daysUntilExpiry} days {/if}
Serial Number - {results.certificate.serialNumber} + {diagnosticState.results.certificate.serialNumber}
Fingerprint - {results.certificate.fingerprint} + {diagnosticState.results.certificate.fingerprint}
- {#if results.certificate.altNames.length > 0} + {#if diagnosticState.results.certificate.altNames.length > 0}
- Alternative Names ({results.certificate.altNames.length}) + Alternative Names ({diagnosticState.results.certificate.altNames.length})
- {#each results.certificate.altNames as altName (altName)} + {#each diagnosticState.results.certificate.altNames as altName (altName)} {altName} {/each}
@@ -357,14 +344,6 @@