@asteby/metacore-runtime-react 53.4.1 → 53.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +73 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/setup/addon-config-surface.d.ts +119 -0
- package/dist/setup/addon-config-surface.d.ts.map +1 -0
- package/dist/setup/addon-config-surface.js +662 -0
- package/dist/setup/connector-blocks-model.d.ts +79 -0
- package/dist/setup/connector-blocks-model.d.ts.map +1 -0
- package/dist/setup/connector-blocks-model.js +96 -0
- package/dist/setup/connector-blocks.d.ts +48 -0
- package/dist/setup/connector-blocks.d.ts.map +1 -0
- package/dist/setup/connector-blocks.js +132 -0
- package/dist/setup/connector-form-model.d.ts +40 -0
- package/dist/setup/connector-form-model.d.ts.map +1 -0
- package/dist/setup/connector-form-model.js +76 -0
- package/dist/setup/flow-model.d.ts +49 -0
- package/dist/setup/flow-model.d.ts.map +1 -0
- package/dist/setup/flow-model.js +124 -0
- package/dist/setup/health-card.d.ts +25 -0
- package/dist/setup/health-card.d.ts.map +1 -0
- package/dist/setup/health-card.js +21 -0
- package/dist/setup/index.d.ts +13 -0
- package/dist/setup/index.d.ts.map +1 -0
- package/dist/setup/index.js +15 -0
- package/dist/setup/messages.d.ts +15 -0
- package/dist/setup/messages.d.ts.map +1 -0
- package/dist/setup/messages.js +320 -0
- package/dist/setup/records-table.d.ts +24 -0
- package/dist/setup/records-table.d.ts.map +1 -0
- package/dist/setup/records-table.js +80 -0
- package/dist/setup/setup-flow.d.ts +30 -0
- package/dist/setup/setup-flow.d.ts.map +1 -0
- package/dist/setup/setup-flow.js +277 -0
- package/dist/setup/setup-form-step.d.ts +20 -0
- package/dist/setup/setup-form-step.d.ts.map +1 -0
- package/dist/setup/setup-form-step.js +173 -0
- package/dist/setup/step-status-badge.d.ts +12 -0
- package/dist/setup/step-status-badge.d.ts.map +1 -0
- package/dist/setup/step-status-badge.js +21 -0
- package/dist/setup/tone.d.ts +8 -0
- package/dist/setup/tone.d.ts.map +1 -0
- package/dist/setup/tone.js +33 -0
- package/dist/setup/types.d.ts +130 -0
- package/dist/setup/types.d.ts.map +1 -0
- package/dist/setup/types.js +1 -0
- package/package.json +9 -5
- package/src/__tests__/addon-config-surface.test.tsx +260 -0
- package/src/__tests__/connector-blocks.test.tsx +302 -0
- package/src/__tests__/setup-components.test.tsx +147 -0
- package/src/__tests__/setup-flow-model.test.ts +117 -0
- package/src/__tests__/setup-flow.test.tsx +424 -0
- package/src/index.ts +29 -0
- package/src/setup/addon-config-surface.tsx +1426 -0
- package/src/setup/connector-blocks-model.ts +163 -0
- package/src/setup/connector-blocks.tsx +341 -0
- package/src/setup/connector-form-model.ts +115 -0
- package/src/setup/flow-model.ts +156 -0
- package/src/setup/health-card.tsx +131 -0
- package/src/setup/index.ts +35 -0
- package/src/setup/messages.ts +334 -0
- package/src/setup/records-table.tsx +186 -0
- package/src/setup/setup-flow.tsx +562 -0
- package/src/setup/setup-form-step.tsx +342 -0
- package/src/setup/step-status-badge.tsx +47 -0
- package/src/setup/tone.ts +44 -0
- package/src/setup/types.ts +147 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { Fragment, useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
+
import { Check, Copy, RefreshCw } from 'lucide-react'
|
|
3
|
+
import { Button } from '@asteby/metacore-ui/primitives'
|
|
4
|
+
import { cn } from '@asteby/metacore-ui/lib'
|
|
5
|
+
import { useSetupT } from './messages'
|
|
6
|
+
import { RECORD_TONE, TONE_BADGE } from './tone'
|
|
7
|
+
import type { RecordStatus, SetupDiagnostic, SetupFix, SetupRecord } from './types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Copies text with a fallback: the async Clipboard API when the page may use
|
|
11
|
+
* it, otherwise a hidden textarea + `execCommand('copy')` (http pages, older
|
|
12
|
+
* webviews, denied permission). Resolves to whether something was copied.
|
|
13
|
+
*/
|
|
14
|
+
export async function copyText(text: string): Promise<boolean> {
|
|
15
|
+
try {
|
|
16
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {
|
|
17
|
+
await navigator.clipboard.writeText(text)
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
20
|
+
} catch {
|
|
21
|
+
/* fall through to the legacy path */
|
|
22
|
+
}
|
|
23
|
+
if (typeof document === 'undefined') return false
|
|
24
|
+
const ta = document.createElement('textarea')
|
|
25
|
+
ta.value = text
|
|
26
|
+
ta.setAttribute('readonly', '')
|
|
27
|
+
ta.style.position = 'fixed'
|
|
28
|
+
ta.style.opacity = '0'
|
|
29
|
+
document.body.appendChild(ta)
|
|
30
|
+
ta.select()
|
|
31
|
+
try {
|
|
32
|
+
return document.execCommand('copy')
|
|
33
|
+
} catch {
|
|
34
|
+
return false
|
|
35
|
+
} finally {
|
|
36
|
+
document.body.removeChild(ta)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function CopyButton({ text, what }: { text: string; what: string }) {
|
|
41
|
+
const t = useSetupT()
|
|
42
|
+
const [state, setState] = useState<'idle' | 'copied' | 'failed'>('idle')
|
|
43
|
+
const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)
|
|
44
|
+
useEffect(() => () => clearTimeout(timer.current), [])
|
|
45
|
+
const onCopy = useCallback(async () => {
|
|
46
|
+
const ok = await copyText(text)
|
|
47
|
+
setState(ok ? 'copied' : 'failed')
|
|
48
|
+
clearTimeout(timer.current)
|
|
49
|
+
timer.current = setTimeout(() => setState('idle'), 2500)
|
|
50
|
+
}, [text])
|
|
51
|
+
return (
|
|
52
|
+
<span className='inline-flex items-center gap-1'>
|
|
53
|
+
<Button
|
|
54
|
+
type='button'
|
|
55
|
+
variant='ghost'
|
|
56
|
+
size='sm'
|
|
57
|
+
className='h-7 w-7 shrink-0 p-0'
|
|
58
|
+
onClick={onCopy}
|
|
59
|
+
aria-label={t('records.copy_label', { what })}
|
|
60
|
+
title={t('records.copy')}
|
|
61
|
+
>
|
|
62
|
+
{state === 'copied' ? (
|
|
63
|
+
<Check className='h-3.5 w-3.5 text-emerald-600 dark:text-emerald-400' aria-hidden='true' />
|
|
64
|
+
) : (
|
|
65
|
+
<Copy className='h-3.5 w-3.5' aria-hidden='true' />
|
|
66
|
+
)}
|
|
67
|
+
</Button>
|
|
68
|
+
<span role='status' className={cn('text-xs', state === 'failed' ? 'text-destructive' : 'text-muted-foreground', state === 'idle' && 'sr-only')}>
|
|
69
|
+
{state === 'copied' ? t('records.copied') : state === 'failed' ? t('records.copy_failed') : ''}
|
|
70
|
+
</span>
|
|
71
|
+
</span>
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function diagOf(d: SetupRecord['diagnostic']): SetupDiagnostic | null {
|
|
76
|
+
if (!d) return null
|
|
77
|
+
return typeof d === 'string' ? { message: d } : d
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface RecordsTableProps {
|
|
81
|
+
records: SetupRecord[]
|
|
82
|
+
caption?: string
|
|
83
|
+
/** Fix button of a row's diagnostic (`fix.action|url|step`). */
|
|
84
|
+
onFix?: (fix: SetupFix, record: SetupRecord) => void
|
|
85
|
+
/** Shows a "check now" button above the table. */
|
|
86
|
+
onRecheck?: () => void
|
|
87
|
+
rechecking?: boolean
|
|
88
|
+
className?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Type / name / value table (DNS records and the like) with per-row copy,
|
|
93
|
+
* status and diagnostic. Scrolls horizontally on narrow screens instead of
|
|
94
|
+
* squeezing the values; values wrap (`break-all`) so a long DKIM key is readable.
|
|
95
|
+
*/
|
|
96
|
+
export function RecordsTable({ records, caption, onFix, onRecheck, rechecking, className }: RecordsTableProps) {
|
|
97
|
+
const t = useSetupT()
|
|
98
|
+
if (!records || records.length === 0) {
|
|
99
|
+
return <p className={cn('text-sm text-muted-foreground', className)}>{t('records.empty')}</p>
|
|
100
|
+
}
|
|
101
|
+
return (
|
|
102
|
+
<div className={cn('flex flex-col gap-2', className)}>
|
|
103
|
+
{onRecheck ? (
|
|
104
|
+
<div className='flex justify-end'>
|
|
105
|
+
<Button type='button' variant='outline' size='sm' onClick={onRecheck} disabled={rechecking} className='gap-2'>
|
|
106
|
+
<RefreshCw className={cn('h-3.5 w-3.5', rechecking && 'animate-spin motion-reduce:animate-none')} aria-hidden='true' />
|
|
107
|
+
{t('records.recheck')}
|
|
108
|
+
</Button>
|
|
109
|
+
</div>
|
|
110
|
+
) : null}
|
|
111
|
+
<div className='overflow-x-auto rounded-md border'>
|
|
112
|
+
<table className='w-full min-w-[34rem] border-collapse text-left text-sm'>
|
|
113
|
+
{caption ? <caption className='sr-only'>{caption}</caption> : null}
|
|
114
|
+
<thead className='bg-muted/50 text-xs text-muted-foreground'>
|
|
115
|
+
<tr>
|
|
116
|
+
<th scope='col' className='px-3 py-2 font-medium'>{t('records.type')}</th>
|
|
117
|
+
<th scope='col' className='px-3 py-2 font-medium'>{t('records.name')}</th>
|
|
118
|
+
<th scope='col' className='px-3 py-2 font-medium'>{t('records.value')}</th>
|
|
119
|
+
<th scope='col' className='px-3 py-2 font-medium'>{t('records.status')}</th>
|
|
120
|
+
</tr>
|
|
121
|
+
</thead>
|
|
122
|
+
<tbody>
|
|
123
|
+
{records.map((r, i) => {
|
|
124
|
+
const status: RecordStatus = r.status ?? 'pending'
|
|
125
|
+
const diag = diagOf(r.diagnostic)
|
|
126
|
+
const tone = RECORD_TONE[status] ?? 'neutral'
|
|
127
|
+
return (
|
|
128
|
+
<Fragment key={r.id ?? `${r.type}-${r.name}-${i}`}>
|
|
129
|
+
<tr className={cn(!diag && i < records.length - 1 && 'border-b')}>
|
|
130
|
+
<td className='whitespace-nowrap px-3 py-2 align-top'>
|
|
131
|
+
<span className='rounded border bg-muted px-1.5 py-0.5 font-mono text-xs'>{r.type}</span>
|
|
132
|
+
</td>
|
|
133
|
+
<td className='px-3 py-2 align-top'>
|
|
134
|
+
<div className='flex items-start gap-1'>
|
|
135
|
+
<code className='break-all font-mono text-xs'>{r.name}</code>
|
|
136
|
+
<CopyButton text={r.name} what={t('records.name').toLowerCase()} />
|
|
137
|
+
</div>
|
|
138
|
+
</td>
|
|
139
|
+
<td className='px-3 py-2 align-top'>
|
|
140
|
+
<div className='flex items-start gap-1'>
|
|
141
|
+
<code className='break-all font-mono text-xs'>{r.value}</code>
|
|
142
|
+
<CopyButton text={r.value} what={t('records.value').toLowerCase()} />
|
|
143
|
+
</div>
|
|
144
|
+
{r.found && r.found !== r.value ? (
|
|
145
|
+
<p className='pt-1 text-xs text-muted-foreground break-all'>{t('records.found', { value: r.found })}</p>
|
|
146
|
+
) : null}
|
|
147
|
+
</td>
|
|
148
|
+
<td className='px-3 py-2 align-top'>
|
|
149
|
+
<span className={cn('inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-medium', TONE_BADGE[tone])} data-record-status={status}>
|
|
150
|
+
{t(`record.status.${status}`)}
|
|
151
|
+
</span>
|
|
152
|
+
</td>
|
|
153
|
+
</tr>
|
|
154
|
+
{diag ? (
|
|
155
|
+
<tr className={cn(i < records.length - 1 && 'border-b')}>
|
|
156
|
+
<DiagnosticCell diag={diag} onFix={onFix ? (f) => onFix(f, r) : undefined} />
|
|
157
|
+
</tr>
|
|
158
|
+
) : null}
|
|
159
|
+
</Fragment>
|
|
160
|
+
)
|
|
161
|
+
})}
|
|
162
|
+
</tbody>
|
|
163
|
+
</table>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function DiagnosticCell({ diag, onFix }: { diag: SetupDiagnostic; onFix?: (f: SetupFix) => void }) {
|
|
170
|
+
const t = useSetupT()
|
|
171
|
+
return (
|
|
172
|
+
<td colSpan={4} className='bg-muted/30 px-3 py-2 text-xs'>
|
|
173
|
+
<div className='flex flex-wrap items-center justify-between gap-2'>
|
|
174
|
+
<p className='min-w-0 flex-1 text-muted-foreground'>
|
|
175
|
+
{diag.message}
|
|
176
|
+
{diag.detail ? <span className='block break-words'>{diag.detail}</span> : null}
|
|
177
|
+
</p>
|
|
178
|
+
{diag.fix && onFix ? (
|
|
179
|
+
<Button type='button' size='sm' variant='outline' className='h-7' onClick={() => onFix(diag.fix!)}>
|
|
180
|
+
{diag.fix.label ?? t('flow.fix')}
|
|
181
|
+
</Button>
|
|
182
|
+
) : null}
|
|
183
|
+
</div>
|
|
184
|
+
</td>
|
|
185
|
+
)
|
|
186
|
+
}
|