@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.
Files changed (68) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +73 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -0
  6. package/dist/setup/addon-config-surface.d.ts +119 -0
  7. package/dist/setup/addon-config-surface.d.ts.map +1 -0
  8. package/dist/setup/addon-config-surface.js +662 -0
  9. package/dist/setup/connector-blocks-model.d.ts +79 -0
  10. package/dist/setup/connector-blocks-model.d.ts.map +1 -0
  11. package/dist/setup/connector-blocks-model.js +96 -0
  12. package/dist/setup/connector-blocks.d.ts +48 -0
  13. package/dist/setup/connector-blocks.d.ts.map +1 -0
  14. package/dist/setup/connector-blocks.js +132 -0
  15. package/dist/setup/connector-form-model.d.ts +40 -0
  16. package/dist/setup/connector-form-model.d.ts.map +1 -0
  17. package/dist/setup/connector-form-model.js +76 -0
  18. package/dist/setup/flow-model.d.ts +49 -0
  19. package/dist/setup/flow-model.d.ts.map +1 -0
  20. package/dist/setup/flow-model.js +124 -0
  21. package/dist/setup/health-card.d.ts +25 -0
  22. package/dist/setup/health-card.d.ts.map +1 -0
  23. package/dist/setup/health-card.js +21 -0
  24. package/dist/setup/index.d.ts +13 -0
  25. package/dist/setup/index.d.ts.map +1 -0
  26. package/dist/setup/index.js +15 -0
  27. package/dist/setup/messages.d.ts +15 -0
  28. package/dist/setup/messages.d.ts.map +1 -0
  29. package/dist/setup/messages.js +320 -0
  30. package/dist/setup/records-table.d.ts +24 -0
  31. package/dist/setup/records-table.d.ts.map +1 -0
  32. package/dist/setup/records-table.js +80 -0
  33. package/dist/setup/setup-flow.d.ts +30 -0
  34. package/dist/setup/setup-flow.d.ts.map +1 -0
  35. package/dist/setup/setup-flow.js +277 -0
  36. package/dist/setup/setup-form-step.d.ts +20 -0
  37. package/dist/setup/setup-form-step.d.ts.map +1 -0
  38. package/dist/setup/setup-form-step.js +173 -0
  39. package/dist/setup/step-status-badge.d.ts +12 -0
  40. package/dist/setup/step-status-badge.d.ts.map +1 -0
  41. package/dist/setup/step-status-badge.js +21 -0
  42. package/dist/setup/tone.d.ts +8 -0
  43. package/dist/setup/tone.d.ts.map +1 -0
  44. package/dist/setup/tone.js +33 -0
  45. package/dist/setup/types.d.ts +130 -0
  46. package/dist/setup/types.d.ts.map +1 -0
  47. package/dist/setup/types.js +1 -0
  48. package/package.json +9 -5
  49. package/src/__tests__/addon-config-surface.test.tsx +260 -0
  50. package/src/__tests__/connector-blocks.test.tsx +302 -0
  51. package/src/__tests__/setup-components.test.tsx +147 -0
  52. package/src/__tests__/setup-flow-model.test.ts +117 -0
  53. package/src/__tests__/setup-flow.test.tsx +424 -0
  54. package/src/index.ts +29 -0
  55. package/src/setup/addon-config-surface.tsx +1426 -0
  56. package/src/setup/connector-blocks-model.ts +163 -0
  57. package/src/setup/connector-blocks.tsx +341 -0
  58. package/src/setup/connector-form-model.ts +115 -0
  59. package/src/setup/flow-model.ts +156 -0
  60. package/src/setup/health-card.tsx +131 -0
  61. package/src/setup/index.ts +35 -0
  62. package/src/setup/messages.ts +334 -0
  63. package/src/setup/records-table.tsx +186 -0
  64. package/src/setup/setup-flow.tsx +562 -0
  65. package/src/setup/setup-form-step.tsx +342 -0
  66. package/src/setup/step-status-badge.tsx +47 -0
  67. package/src/setup/tone.ts +44 -0
  68. 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
+ }