@astra-spec/ui 0.0.5 → 0.0.7

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 (172) hide show
  1. package/README.md +47 -4
  2. package/blocks.css +1 -0
  3. package/components.css +6 -0
  4. package/dist/blocks/analysis-tree.d.ts.map +1 -1
  5. package/dist/blocks/analysis-tree.js +4 -7
  6. package/dist/blocks/analysis-tree.js.map +1 -1
  7. package/dist/blocks/decisions-list.d.ts.map +1 -1
  8. package/dist/blocks/decisions-list.js +1 -1
  9. package/dist/blocks/decisions-list.js.map +1 -1
  10. package/dist/blocks/findings-list.d.ts.map +1 -1
  11. package/dist/blocks/findings-list.js +2 -4
  12. package/dist/blocks/findings-list.js.map +1 -1
  13. package/dist/blocks/index.d.ts +2 -4
  14. package/dist/blocks/index.d.ts.map +1 -1
  15. package/dist/blocks/index.js +1 -2
  16. package/dist/blocks/index.js.map +1 -1
  17. package/dist/blocks/outputs-list.d.ts +2 -7
  18. package/dist/blocks/outputs-list.d.ts.map +1 -1
  19. package/dist/blocks/outputs-list.js +11 -21
  20. package/dist/blocks/outputs-list.js.map +1 -1
  21. package/dist/blocks/papers-list.d.ts.map +1 -1
  22. package/dist/blocks/papers-list.js +3 -3
  23. package/dist/blocks/papers-list.js.map +1 -1
  24. package/dist/components/figure-zoom.d.ts +6 -0
  25. package/dist/components/figure-zoom.d.ts.map +1 -0
  26. package/dist/components/figure-zoom.js +28 -0
  27. package/dist/components/figure-zoom.js.map +1 -0
  28. package/dist/components/finding-detail.d.ts +4 -2
  29. package/dist/components/finding-detail.d.ts.map +1 -1
  30. package/dist/components/finding-detail.js +41 -25
  31. package/dist/components/finding-detail.js.map +1 -1
  32. package/dist/components/index.d.ts +9 -0
  33. package/dist/components/index.d.ts.map +1 -1
  34. package/dist/components/index.js +5 -0
  35. package/dist/components/index.js.map +1 -1
  36. package/dist/components/insight-trigger.js +2 -2
  37. package/dist/components/insight-trigger.js.map +1 -1
  38. package/dist/components/output-card.d.ts +13 -0
  39. package/dist/components/output-card.d.ts.map +1 -0
  40. package/dist/components/output-card.js +12 -0
  41. package/dist/components/output-card.js.map +1 -0
  42. package/dist/components/output-detail.d.ts +6 -2
  43. package/dist/components/output-detail.d.ts.map +1 -1
  44. package/dist/components/output-detail.js +49 -13
  45. package/dist/components/output-detail.js.map +1 -1
  46. package/dist/components/output-dialog.d.ts +6 -1
  47. package/dist/components/output-dialog.d.ts.map +1 -1
  48. package/dist/components/output-dialog.js +2 -2
  49. package/dist/components/output-dialog.js.map +1 -1
  50. package/dist/components/output-entry.d.ts +17 -0
  51. package/dist/components/output-entry.d.ts.map +1 -0
  52. package/dist/components/output-entry.js +21 -0
  53. package/dist/components/output-entry.js.map +1 -0
  54. package/dist/components/output-provenance.d.ts +6 -0
  55. package/dist/components/output-provenance.d.ts.map +1 -0
  56. package/dist/components/output-provenance.js +16 -0
  57. package/dist/components/output-provenance.js.map +1 -0
  58. package/dist/components/output-status.d.ts +8 -0
  59. package/dist/components/output-status.d.ts.map +1 -0
  60. package/dist/components/output-status.js +17 -0
  61. package/dist/components/output-status.js.map +1 -0
  62. package/dist/components/paper-detail.d.ts.map +1 -1
  63. package/dist/components/paper-detail.js +11 -15
  64. package/dist/components/paper-detail.js.map +1 -1
  65. package/dist/components/paper-row.d.ts +9 -0
  66. package/dist/components/paper-row.d.ts.map +1 -0
  67. package/dist/components/paper-row.js +11 -0
  68. package/dist/components/paper-row.js.map +1 -0
  69. package/dist/components/record-dialog.d.ts +5 -1
  70. package/dist/components/record-dialog.d.ts.map +1 -1
  71. package/dist/components/record-dialog.js +7 -4
  72. package/dist/components/record-dialog.js.map +1 -1
  73. package/dist/lib/labels.d.ts +34 -2
  74. package/dist/lib/labels.d.ts.map +1 -1
  75. package/dist/lib/labels.js +35 -4
  76. package/dist/lib/labels.js.map +1 -1
  77. package/dist/model/index.d.ts +4 -2
  78. package/dist/model/index.d.ts.map +1 -1
  79. package/dist/model/index.js +1 -1
  80. package/dist/model/index.js.map +1 -1
  81. package/dist/model/kind.d.ts +1 -1
  82. package/dist/model/kind.d.ts.map +1 -1
  83. package/dist/model/kind.js +0 -1
  84. package/dist/model/kind.js.map +1 -1
  85. package/dist/model/output-provenance.d.ts +17 -0
  86. package/dist/model/output-provenance.d.ts.map +1 -0
  87. package/dist/model/output-provenance.js +2 -0
  88. package/dist/model/output-provenance.js.map +1 -0
  89. package/dist/model/output-status.d.ts +17 -0
  90. package/dist/model/output-status.d.ts.map +1 -0
  91. package/dist/model/output-status.js +2 -0
  92. package/dist/model/output-status.js.map +1 -0
  93. package/dist/model/relations.d.ts +37 -12
  94. package/dist/model/relations.d.ts.map +1 -1
  95. package/dist/model/relations.js +76 -23
  96. package/dist/model/relations.js.map +1 -1
  97. package/dist/primitives/dialog.d.ts.map +1 -1
  98. package/dist/primitives/dialog.js +9 -1
  99. package/dist/primitives/dialog.js.map +1 -1
  100. package/dist/primitives/index.d.ts +2 -0
  101. package/dist/primitives/index.d.ts.map +1 -1
  102. package/dist/primitives/index.js +1 -0
  103. package/dist/primitives/index.js.map +1 -1
  104. package/dist/primitives/output-status-glyph.d.ts +8 -0
  105. package/dist/primitives/output-status-glyph.d.ts.map +1 -0
  106. package/dist/primitives/output-status-glyph.js +13 -0
  107. package/dist/primitives/output-status-glyph.js.map +1 -0
  108. package/dist/primitives/tooltip.d.ts +7 -0
  109. package/dist/primitives/tooltip.d.ts.map +1 -0
  110. package/dist/primitives/tooltip.js +31 -0
  111. package/dist/primitives/tooltip.js.map +1 -0
  112. package/dist/views/inventory.d.ts +12 -1
  113. package/dist/views/inventory.d.ts.map +1 -1
  114. package/dist/views/inventory.js +23 -17
  115. package/dist/views/inventory.js.map +1 -1
  116. package/package.json +3 -2
  117. package/primitives.css +1 -0
  118. package/src/blocks/analysis-tree.tsx +4 -30
  119. package/src/blocks/decisions-list.tsx +5 -3
  120. package/src/blocks/findings-list.tsx +8 -7
  121. package/src/blocks/index.ts +2 -4
  122. package/src/blocks/outputs-list.tsx +43 -106
  123. package/src/blocks/papers-list.tsx +2 -18
  124. package/src/components/figure-zoom.tsx +72 -0
  125. package/src/components/finding-detail.tsx +106 -30
  126. package/src/components/index.ts +13 -0
  127. package/src/components/insight-trigger.tsx +2 -2
  128. package/src/components/output-card.tsx +51 -0
  129. package/src/components/output-detail.tsx +69 -21
  130. package/src/components/output-dialog.tsx +9 -0
  131. package/src/components/output-entry.tsx +61 -0
  132. package/src/components/output-provenance.tsx +86 -0
  133. package/src/components/output-status.tsx +38 -0
  134. package/src/components/paper-detail.tsx +52 -54
  135. package/src/components/paper-row.tsx +41 -0
  136. package/src/components/record-dialog.tsx +13 -1
  137. package/src/lib/labels.tsx +69 -6
  138. package/src/model/index.ts +6 -2
  139. package/src/model/kind.ts +1 -2
  140. package/src/model/output-provenance.ts +18 -0
  141. package/src/model/output-status.ts +18 -0
  142. package/src/model/relations.ts +92 -26
  143. package/src/primitives/dialog.tsx +7 -1
  144. package/src/primitives/index.ts +2 -0
  145. package/src/primitives/output-status-glyph.tsx +37 -0
  146. package/src/primitives/tooltip.tsx +51 -0
  147. package/src/views/inventory.tsx +54 -22
  148. package/styles/base.css +2 -1
  149. package/styles/blocks/analysis-tree.css +22 -25
  150. package/styles/blocks/findings-list.css +50 -0
  151. package/styles/blocks/outputs-list.css +0 -421
  152. package/styles/blocks/papers-list.css +4 -70
  153. package/styles/components/evidence.css +1 -18
  154. package/styles/components/figure-zoom.css +62 -0
  155. package/styles/components/finding-detail.css +62 -0
  156. package/styles/components/insight-list.css +0 -4
  157. package/styles/components/insight-trigger.css +8 -6
  158. package/styles/components/output-card.css +290 -0
  159. package/styles/components/output-detail.css +91 -3
  160. package/styles/components/output-entry.css +141 -0
  161. package/styles/components/output-provenance.css +94 -0
  162. package/styles/components/output-status.css +31 -0
  163. package/styles/components/paper-detail.css +112 -59
  164. package/styles/components/paper-row.css +72 -0
  165. package/styles/primitives/dialog.css +4 -22
  166. package/styles/primitives/tooltip.css +22 -0
  167. package/styles/views/inventory.css +35 -2
  168. package/dist/blocks/prior-insights-list.d.ts +0 -9
  169. package/dist/blocks/prior-insights-list.d.ts.map +0 -1
  170. package/dist/blocks/prior-insights-list.js +0 -29
  171. package/dist/blocks/prior-insights-list.js.map +0 -1
  172. package/src/blocks/prior-insights-list.tsx +0 -52
@@ -1,15 +1,22 @@
1
- import type { ResolvedInsight } from '@astra-spec/sdk';
2
- import { Fragment, forwardRef, type HTMLAttributes } from 'react';
3
- import { recordTitle } from '../model/records.js';
1
+ import type { ResolvedAnalysisNode, ResolvedInsight, ResolvedOutput } from '@astra-spec/sdk';
2
+ import { Fragment, forwardRef, useId, type HTMLAttributes, type ReactNode } from 'react';
4
3
  import { doiHref } from '../model/doi.js';
5
- import { findingLiterature, type FindingEvidenceLink } from '../model/relations.js';
4
+ import { recordTitle } from '../model/records.js';
5
+ import {
6
+ findingLiterature,
7
+ groupFindingEvidence,
8
+ type FindingEvidenceGroup,
9
+ type FindingEvidenceLink,
10
+ } from '../model/relations.js';
6
11
  import { cn } from '../lib/cn.js';
7
12
  import { useLabels } from '../lib/labels.js';
8
- import { DetailLayout, DetailMain } from '../primitives/detail-layout.js';
13
+ import { CountHeading, DetailLayout, DetailMain, DetailSection } from '../primitives/detail-layout.js';
9
14
  import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
10
15
  import { Prose } from '../primitives/prose.js';
11
16
  import type { TextRenderer } from '../lib/prose.js';
12
- import { RelationList } from '../primitives/relation-list.js';
17
+ import type { ArtifactRenderer } from './artifact-preview.js';
18
+ import { OutputCard } from './output-card.js';
19
+ import { OutputEntry } from './output-entry.js';
13
20
  import type { OpenRecordHandler } from '../lib/detail-stack.js';
14
21
 
15
22
  export interface FindingDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
@@ -17,48 +24,117 @@ export interface FindingDetailProps extends Omit<HTMLAttributes<HTMLDivElement>,
17
24
  /** Artifact-backed evidence resolved to outputs; see `findingEvidence()`. */
18
25
  evidence: FindingEvidenceLink[];
19
26
  renderText?: TextRenderer | undefined;
27
+ renderArtifact?: ArtifactRenderer | undefined;
20
28
  onOpenRecord?: OpenRecordHandler | undefined;
21
29
  }
22
30
 
23
- /** Notes, the supporting results a finding cites, and its literature sources. */
31
+ /** A resolved group, narrowed to the ones a result renderer can draw. */
32
+ type ResolvedGroup = FindingEvidenceGroup & { output: ResolvedOutput; analysis: ResolvedAnalysisNode };
33
+
34
+ const isResolved = (group: FindingEvidenceGroup): group is ResolvedGroup =>
35
+ Boolean(group.output && group.analysis);
36
+
37
+ /**
38
+ * One run of results of a kind. The label only earns its space when a finding
39
+ * rests on more than one kind: with a single run, what they are is evident.
40
+ */
41
+ function ResultRun({ label, labelled, children }: { label: string; labelled: boolean; children: ReactNode }) {
42
+ const id = useId();
43
+ if (!labelled) return <>{children}</>;
44
+ return (
45
+ <section aria-labelledby={id}>
46
+ <h5 id={id} className="astra-finding-detail__group-heading">{label}</h5>
47
+ {children}
48
+ </section>
49
+ );
50
+ }
51
+
52
+ /** The claim, the results it rests on, and the literature it cites. */
24
53
  export const FindingDetail = forwardRef<HTMLDivElement, FindingDetailProps>(function FindingDetail({
25
54
  record,
26
55
  evidence,
27
56
  renderText,
57
+ renderArtifact,
28
58
  onOpenRecord,
29
59
  className,
30
60
  ...props
31
61
  }, ref) {
32
62
  const literature = findingLiterature(record);
63
+ const results = groupFindingEvidence(evidence);
64
+ // Grouped the way the inventory groups an analysis's outputs, so a result
65
+ // looks the same wherever it is met. Unresolved artifacts have no record to
66
+ // draw, so they keep their name and nothing more.
67
+ const resolved = results.filter(isResolved);
68
+ const ofType = (type: ResolvedOutput['type']) => resolved.filter(({ output }) => output.type === type);
69
+ const figures = ofType('figure');
70
+ const tables = ofType('table');
71
+ const metrics = ofType('metric');
72
+ const files = resolved.filter(({ output }) => !['figure', 'table', 'metric'].includes(output.type));
73
+ const unresolved = results.filter((group) => !isResolved(group));
74
+ // Labels only appear once a finding rests on more than one kind of result.
75
+ const runs = [figures.length, tables.length, metrics.length, files.length + unresolved.length];
76
+ const labelled = runs.filter(Boolean).length > 1;
77
+ const open = (group: ResolvedGroup) => () => { onOpenRecord?.(group.output, group.analysis); };
78
+ // Say what the result is to this finding; the card's own name would only
79
+ // say what kind of artifact it is.
80
+ const resultLabel = (group: ResolvedGroup) => `View supporting result: ${recordTitle(group.output)}`;
33
81
  return (
34
82
  <DetailLayout data-slot="finding-detail" {...props} ref={ref} layout="single" className={cn('astra-finding-detail', className)}>
35
83
  <DetailMain>
84
+ <DetailSection label="Claim" heading="section">
85
+ <Prose text={record.claim} field="claim" renderText={renderText} />
86
+ </DetailSection>
36
87
  {record.notes ? (
37
88
  <section className="astra-finding-detail__notes">
38
89
  <h4>Notes</h4>
39
90
  <div><Prose text={record.notes} field="notes" renderText={renderText} /></div>
40
91
  </section>
41
92
  ) : null}
42
- <RelationList
43
- className="astra-finding-detail__results"
44
- title="Supporting results"
45
- empty="No supporting results are linked to this finding."
46
- items={evidence.map((item, index) => {
47
- const title = item.output
48
- ? recordTitle(item.output)
49
- : item.evidence.artifact ?? `Result ${index + 1}`;
50
- const { output, analysis } = item;
51
- return {
52
- key: `${item.evidence.resolvedOutputPath ?? item.evidence.artifact ?? 'result'}-${index}`,
53
- label: title,
54
- identifier: output?.canonicalPath ?? item.evidence.artifact,
55
- detail: output?.type ?? 'Unavailable',
56
- kind: 'output' as const,
57
- accessibleLabel: output ? `View supporting result: ${title}` : undefined,
58
- onOpen: output && analysis && onOpenRecord ? () => { onOpenRecord(output, analysis); } : undefined,
59
- };
60
- })}
61
- />
93
+ <section className="astra-finding-detail__results">
94
+ <CountHeading title="Supporting results" count={results.length} />
95
+ {results.length ? (
96
+ <>
97
+ {([['Figures', figures], ['Tables', tables]] as const).map(([label, groups]) => (
98
+ groups.length ? (
99
+ <ResultRun key={label} label={label} labelled={labelled}>
100
+ <div className="astra-finding-detail__gallery">
101
+ {groups.map((group) => (
102
+ <OutputCard key={group.key} output={group.output} renderArtifact={renderArtifact} aria-label={resultLabel(group)} onOpen={open(group)} />
103
+ ))}
104
+ </div>
105
+ </ResultRun>
106
+ ) : null
107
+ ))}
108
+ {metrics.length ? (
109
+ <ResultRun label="Metrics" labelled={labelled}>
110
+ <ul className="astra-finding-detail__tiles">
111
+ {metrics.map((group) => (
112
+ <li key={group.key}>
113
+ <OutputEntry output={group.output} renderArtifact={renderArtifact} aria-label={resultLabel(group)} onOpen={open(group)} />
114
+ </li>
115
+ ))}
116
+ </ul>
117
+ </ResultRun>
118
+ ) : null}
119
+ {files.length || unresolved.length ? (
120
+ <ResultRun label="Output files" labelled={labelled}>
121
+ <ul className="astra-finding-detail__files">
122
+ {files.map((group) => (
123
+ <li key={group.key}>
124
+ <OutputEntry output={group.output} aria-label={resultLabel(group)} onOpen={open(group)} />
125
+ </li>
126
+ ))}
127
+ {unresolved.map((group) => (
128
+ <li key={group.key} className="astra-finding-detail__unresolved">
129
+ {group.artifact ?? group.key}
130
+ </li>
131
+ ))}
132
+ </ul>
133
+ </ResultRun>
134
+ ) : null}
135
+ </>
136
+ ) : <p>No supporting results are linked to this finding.</p>}
137
+ </section>
62
138
  {literature.map((source, index) => {
63
139
  const doi = source.doi ?? '';
64
140
  const location = source.location?.page ? ` · page ${source.location.page}` : '';
@@ -84,17 +160,17 @@ export const FindingDetail = forwardRef<HTMLDivElement, FindingDetailProps>(func
84
160
 
85
161
  export interface FindingDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'>, Omit<FindingDetailProps, 'className'> {}
86
162
 
87
- export function FindingDialog({ record, evidence, renderText, onOpenRecord, ...dialog }: FindingDialogProps) {
163
+ export function FindingDialog({ record, evidence, renderText, renderArtifact, onOpenRecord, ...dialog }: FindingDialogProps) {
88
164
  const labels = useLabels();
89
165
  return (
90
166
  <DetailDialog
91
167
  {...dialog}
92
168
  kind="finding"
93
169
  kindLabel={labels.kinds.finding}
94
- title={record.claim}
170
+ title={recordTitle(record)}
95
171
  closeLabel={labels.closeRecord(labels.kinds.finding)}
96
172
  >
97
- <FindingDetail record={record} evidence={evidence} renderText={renderText} onOpenRecord={onOpenRecord} />
173
+ <FindingDetail record={record} evidence={evidence} renderText={renderText} renderArtifact={renderArtifact} onOpenRecord={onOpenRecord} />
98
174
  </DetailDialog>
99
175
  );
100
176
  }
@@ -32,3 +32,16 @@ export type { ArtifactPreviewProps, ArtifactRenderOptions, ArtifactRenderer } fr
32
32
 
33
33
  export { PaperPdfViewer } from './paper-pdf-viewer.js';
34
34
  export type { PaperPdfViewerProps, PdfLoadState, PdfPassage } from './paper-pdf-viewer.js';
35
+
36
+ export { OutputCard } from './output-card.js';
37
+ export type { OutputCardProps } from './output-card.js';
38
+ export { OutputEntry } from './output-entry.js';
39
+ export type { OutputEntryProps } from './output-entry.js';
40
+
41
+ export { PaperRow } from './paper-row.js';
42
+ export type { PaperRowProps } from './paper-row.js';
43
+
44
+ export { OutputStatusIndicator } from './output-status.js';
45
+ export type { OutputStatusIndicatorProps } from './output-status.js';
46
+
47
+ export { OutputProvenance, type OutputProvenanceProps } from './output-provenance.js';
@@ -21,7 +21,7 @@ export interface InsightEvidenceTitleProps {
21
21
  export function InsightEvidenceTitle({ name, tag }: InsightEvidenceTitleProps) {
22
22
  return (
23
23
  <span className="astra-evidence__title">
24
- <KindGlyph className="astra-evidence__glyph--insight" kind="prior_insight" />
24
+ <KindGlyph kind="prior_insight" />
25
25
  <span className="astra-evidence__name">{name}</span>
26
26
  {tag ? <span className="astra-evidence__tag">{tag}</span> : null}
27
27
  </span>
@@ -79,7 +79,7 @@ export const InsightTrigger = forwardRef<HTMLElement, InsightTriggerProps>(funct
79
79
  onClick={open}
80
80
  onKeyDown={keyOpen}
81
81
  >
82
- <KindGlyph className="astra-evidence__glyph--insight" kind="prior_insight" />
82
+ <KindGlyph className="astra-insight-trigger__glyph" kind="prior_insight" />
83
83
  <div className="astra-insight-trigger__claim">
84
84
  <Prose text={insight.claim} field="claim" renderText={renderText} />
85
85
  </div>
@@ -0,0 +1,51 @@
1
+ import type { ResolvedOutput } from '@astra-spec/sdk';
2
+ import { forwardRef, type HTMLAttributes } from 'react';
3
+ import type { OutputStatus } from '../model/output-status.js';
4
+ import { OutputStatusIndicator } from './output-status.js';
5
+ import { recordTitle } from '../model/records.js';
6
+ import { cn } from '../lib/cn.js';
7
+ import type { ArtifactRenderer } from './artifact-preview.js';
8
+ import { OutputPreview } from './output-detail.js';
9
+
10
+ export interface OutputCardProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'children'> {
11
+ output: ResolvedOutput;
12
+ status?: OutputStatus | undefined;
13
+ renderArtifact?: ArtifactRenderer | undefined;
14
+ onOpen: () => void;
15
+ }
16
+
17
+ /** A gallery card: compact preview and title, with a type label for non-figures. */
18
+ export const OutputCard = forwardRef<HTMLButtonElement, OutputCardProps>(function OutputCard({
19
+ output,
20
+ status,
21
+ renderArtifact,
22
+ onOpen,
23
+ className,
24
+ onClick,
25
+ 'aria-label': hostLabel,
26
+ ...props
27
+ }, ref) {
28
+ const title = recordTitle(output);
29
+ return (
30
+ <button
31
+ data-slot="output-card"
32
+ {...props}
33
+ ref={ref}
34
+ type="button"
35
+ className={cn('astra-output-card', className)}
36
+ aria-label={hostLabel ?? `Open ${output.type}: ${title}`}
37
+ onClick={(event) => { onClick?.(event); onOpen(); }}
38
+ >
39
+ <OutputStatusIndicator status={status} />
40
+ <span className="astra-output-card__preview">
41
+ <OutputPreview output={output} compact renderArtifact={renderArtifact} />
42
+ <span className="astra-output-card__open" aria-hidden="true">Open ↗</span>
43
+ </span>
44
+ <span className="astra-output-card__body">
45
+ {output.type !== 'figure' ? <span className="astra-output-card__kind">{output.type}</span> : null}
46
+ <strong>{title}</strong>
47
+ {output.label ? <code>{output.id}</code> : null}
48
+ </span>
49
+ </button>
50
+ );
51
+ });
@@ -10,6 +10,7 @@ import { Prose } from '../primitives/prose.js';
10
10
  import type { TextRenderer } from '../lib/prose.js';
11
11
  import { RelationList } from '../primitives/relation-list.js';
12
12
  import { relationItemsForLinks } from './relation-items.js';
13
+ import { FigureZoom } from './figure-zoom.js';
13
14
  import type { OpenRecordHandler } from '../lib/detail-stack.js';
14
15
 
15
16
  export interface OutputPreviewProps {
@@ -26,19 +27,28 @@ export function OutputPreview({ output, compact = false, renderArtifact }: Outpu
26
27
  }
27
28
 
28
29
  /**
29
- * What the detail shows in its artifact box: the host's rendering when it
30
- * returns one, the built-in preview for figures and tables, nothing for other
31
- * output types (a data file or a metric has no picture to frame).
30
+ * What the detail shows in its artifact box: only a figure or a table has a
31
+ * picture to frame, rendered by the host when it supplies a renderer. A data
32
+ * file or a metric gets no box — an empty reader column is all whitespace —
33
+ * so the host renderer is not consulted for them here; `OutputPreview` still
34
+ * asks it for the compact preview of any type, and a metric's value is asked
35
+ * for as a compact rendering below.
32
36
  */
33
37
  function artifactNode(output: ResolvedOutput, renderArtifact: ArtifactRenderer | undefined): ReactNode {
34
- if (renderArtifact) return renderArtifact(output, { compact: false });
35
- return isVisualOutput(output) ? <ArtifactPreview output={output} compact={false} /> : null;
38
+ if (!isVisualOutput(output)) return null;
39
+ return renderArtifact
40
+ ? renderArtifact(output, { compact: false })
41
+ : <ArtifactPreview output={output} compact={false} />;
36
42
  }
37
43
 
38
44
  export interface OutputDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
39
45
  record: ResolvedOutput;
40
46
  relations: OutputRelations;
41
47
  renderArtifact?: ArtifactRenderer | undefined;
48
+ /** Recorded execution information, shown below Recipe. */
49
+ renderProvenance?: ((output: ResolvedOutput) => ReactNode) | undefined;
50
+ /** Host-provided link to the current code file, shown beside Recipe. */
51
+ renderCodeLink?: ((output: ResolvedOutput) => ReactNode) | undefined;
42
52
  renderText?: TextRenderer | undefined;
43
53
  onOpenRecord?: OpenRecordHandler | undefined;
44
54
  /** Full-screen artifact state (controlled). */
@@ -46,11 +56,42 @@ export interface OutputDetailProps extends Omit<HTMLAttributes<HTMLDivElement>,
46
56
  onExpandedChange?: ((expanded: boolean) => void) | undefined;
47
57
  }
48
58
 
59
+ /**
60
+ * One decision per row. A decision the output declares reads plainly; one it
61
+ * inherits says which upstream output carries it, so a list that mixes the two
62
+ * still shows where each came from.
63
+ */
64
+ function decisionDependencyItems(relations: OutputRelations, onOpenRecord: OpenRecordHandler | undefined) {
65
+ return relationItemsForLinks(relations.decisions, onOpenRecord).map((item, index) => {
66
+ const via = relations.decisions[index]?.via;
67
+ const origins = via?.map(({ record, canonicalPath }) => record ? recordTitle(record) : canonicalPath);
68
+ if (!origins?.length) return item;
69
+ const detail = `via ${origins.join(', ')}`;
70
+ return {
71
+ ...item,
72
+ // The truncated text is for sighted readers; assistive technology gets
73
+ // the full list, whether or not the row becomes a navigation trigger
74
+ // (only a trigger carries `accessibleLabel`).
75
+ detail: origins.length > 1
76
+ ? (
77
+ <span title={detail}>
78
+ <span aria-hidden="true">via {origins[0]} +{origins.length - 1} more</span>
79
+ <span className="astra-output-detail__visually-hidden">{detail}</span>
80
+ </span>
81
+ )
82
+ : detail,
83
+ accessibleLabel: item.accessibleLabel ? `${item.accessibleLabel}, ${detail}` : undefined,
84
+ };
85
+ });
86
+ }
87
+
49
88
  /** Artifact preview with provenance: description, recipe, alias, decisions, and inputs. */
50
89
  export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(function OutputDetail({
51
90
  record: output,
52
91
  relations,
53
92
  renderArtifact,
93
+ renderProvenance,
94
+ renderCodeLink,
54
95
  renderText,
55
96
  onOpenRecord,
56
97
  expanded = false,
@@ -60,6 +101,10 @@ export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(functi
60
101
  }, ref) {
61
102
  const labels = useLabels();
62
103
  const artifact = artifactNode(output, renderArtifact);
104
+ // A metric's whole artifact is one number: it reads as a pill at the head of
105
+ // the provenance, above the description, not as a figure stretched across a
106
+ // reader column.
107
+ const metric = output.type === 'metric' ? renderArtifact?.(output, { compact: true }) : null;
63
108
  // Reader layout (artifact column + details rail) only when there is an
64
109
  // artifact to frame: a host renderer may opt out of a figure or table by
65
110
  // returning null, and the details then take the single column instead.
@@ -110,6 +155,12 @@ export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(functi
110
155
 
111
156
  const supportingDetails = (
112
157
  <aside className="astra-output-detail__provenance" aria-label="Output provenance and dependencies">
158
+ {metric ? (
159
+ <section className="astra-output-detail__metric">
160
+ <h4>Metric</h4>
161
+ <div className="astra-output-detail__metric-pill">{metric}</div>
162
+ </section>
163
+ ) : null}
113
164
  {output.description ? (
114
165
  <section className="astra-output-detail__description">
115
166
  <h4>Description</h4>
@@ -129,17 +180,9 @@ export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(functi
129
180
  <RelationList
130
181
  className="astra-detail__relations"
131
182
  title="Decision dependencies"
132
- items={relationItemsForLinks(relations.decisions, onOpenRecord)}
133
- empty="No decision dependencies are declared for this output."
183
+ items={decisionDependencyItems(relations, onOpenRecord)}
184
+ empty="No decisions affect this output."
134
185
  />
135
- {relations.indirectDecisions?.length ? (
136
- <RelationList
137
- className="astra-detail__relations"
138
- title="Indirect decision dependencies"
139
- items={relationItemsForLinks(relations.indirectDecisions, onOpenRecord)}
140
- empty={null}
141
- />
142
- ) : null}
143
186
  <RelationList
144
187
  className="astra-detail__relations"
145
188
  title="Inputs and upstream outputs"
@@ -150,13 +193,17 @@ export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(functi
150
193
  />
151
194
  {output.recipe?.command ? (
152
195
  <section className="astra-output-detail__recipe">
153
- <h4>Recipe</h4>
196
+ <div className="astra-output-detail__recipe-heading">
197
+ <h4>Recipe</h4>
198
+ {renderCodeLink?.(output)}
199
+ </div>
154
200
  <pre><code>{output.recipe.command}</code></pre>
155
201
  {output.recipe.container
156
202
  ? <p>Container: <code>{output.recipe.container}</code></p>
157
203
  : null}
158
204
  </section>
159
205
  ) : null}
206
+ {renderProvenance?.(output)}
160
207
  </aside>
161
208
  );
162
209
 
@@ -191,7 +238,9 @@ export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(functi
191
238
  </div>
192
239
  ) : null}
193
240
  <div className="astra-output-detail__preview" data-type={output.type}>
194
- {artifact}
241
+ {output.type === 'figure'
242
+ ? <FigureZoom key={output.canonicalPath}>{artifact}</FigureZoom>
243
+ : artifact}
195
244
  </div>
196
245
  </div>
197
246
  ) : null}
@@ -209,10 +258,10 @@ export interface OutputDialogActionsProps {
209
258
  onExpandedChange: (expanded: boolean) => void;
210
259
  }
211
260
 
212
- /** Header actions for an output: open the artifact in the host, enter full screen. */
261
+ /** Header actions: open the artifact in the host, or expand a table. */
213
262
  export function OutputDialogActions({ record: output, onOpenArtifact, expanded, onExpandedChange }: OutputDialogActionsProps) {
214
263
  const labels = useLabels();
215
- const visual = isVisualOutput(output);
264
+ const canExpand = output.type === 'table';
216
265
  return (
217
266
  <>
218
267
  {onOpenArtifact && output.artifact ? (
@@ -221,7 +270,7 @@ export function OutputDialogActions({ record: output, onOpenArtifact, expanded,
221
270
  <span>{labels.actions.openArtifact}</span>
222
271
  </DialogAction>
223
272
  ) : null}
224
- {visual ? (
273
+ {canExpand ? (
225
274
  <DialogAction
226
275
  aria-label={`View ${output.type} full screen`}
227
276
  aria-expanded={expanded}
@@ -234,4 +283,3 @@ export function OutputDialogActions({ record: output, onOpenArtifact, expanded,
234
283
  </>
235
284
  );
236
285
  }
237
-
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from 'react';
1
2
  import type { ResolvedOutput } from '@astra-spec/sdk';
2
3
  import type { OutputRelations } from '../model/relations.js';
3
4
  import { isVisualOutput, recordTitle } from '../model/records.js';
@@ -13,6 +14,10 @@ export interface OutputDialogProps extends Pick<DetailDialogProps, 'mode' | 'bac
13
14
  record: ResolvedOutput;
14
15
  relations: OutputRelations;
15
16
  renderArtifact?: ArtifactRenderer | undefined;
17
+ /** Host renderer for recorded output provenance, shown below Recipe. */
18
+ renderProvenance?: ((output: ResolvedOutput) => ReactNode) | undefined;
19
+ /** Host-provided link to the current code file, shown beside Recipe. */
20
+ renderCodeLink?: ((output: ResolvedOutput) => ReactNode) | undefined;
16
21
  renderText?: TextRenderer | undefined;
17
22
  onOpenArtifact?: ((output: ResolvedOutput) => void | Promise<void>) | undefined;
18
23
  onOpenRecord?: OpenRecordHandler | undefined;
@@ -24,6 +29,8 @@ export function OutputDialog({
24
29
  record: output,
25
30
  relations,
26
31
  renderArtifact,
32
+ renderProvenance,
33
+ renderCodeLink,
27
34
  renderText,
28
35
  onOpenArtifact,
29
36
  onOpenRecord,
@@ -54,6 +61,8 @@ export function OutputDialog({
54
61
  record={output}
55
62
  relations={relations}
56
63
  renderArtifact={renderArtifact}
64
+ renderProvenance={renderProvenance}
65
+ renderCodeLink={renderCodeLink}
57
66
  renderText={renderText}
58
67
  onOpenRecord={onOpenRecord}
59
68
  expanded={expanded}
@@ -0,0 +1,61 @@
1
+ import type { ResolvedOutput } from '@astra-spec/sdk';
2
+ import { forwardRef, type HTMLAttributes } from 'react';
3
+ import type { OutputStatus } from '../model/output-status.js';
4
+ import { OutputStatusIndicator } from './output-status.js';
5
+ import { recordTitle } from '../model/records.js';
6
+ import { cn } from '../lib/cn.js';
7
+ import type { ArtifactRenderer } from './artifact-preview.js';
8
+
9
+ export interface OutputEntryProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'children'> {
10
+ output: ResolvedOutput;
11
+ status?: OutputStatus | undefined;
12
+ renderArtifact?: ArtifactRenderer | undefined;
13
+ onOpen: () => void;
14
+ }
15
+
16
+ /**
17
+ * One output at a glance, for the types a gallery card would waste space on: a
18
+ * metric reads as its value over its name, anything else as its name. The row
19
+ * it wraps in decides how a run of these is laid out.
20
+ */
21
+ export const OutputEntry = forwardRef<HTMLButtonElement, OutputEntryProps>(function OutputEntry({
22
+ output,
23
+ status,
24
+ renderArtifact,
25
+ onOpen,
26
+ className,
27
+ onClick,
28
+ 'aria-label': hostLabel,
29
+ ...props
30
+ }, ref) {
31
+ const title = recordTitle(output);
32
+ const metric = output.type === 'metric';
33
+ // Why the document itself has nothing to show, before any host status.
34
+ const absenceNote = !output.active ? 'Inactive' : !output.artifact ? 'Not yet generated' : undefined;
35
+ return (
36
+ <button
37
+ data-slot="output-entry"
38
+ {...props}
39
+ ref={ref}
40
+ type="button"
41
+ className={cn('astra-output-entry', className)}
42
+ data-kind={metric ? 'metric' : 'file'}
43
+ aria-label={hostLabel ?? `Open ${output.type}: ${title}`}
44
+ onClick={(event) => { onClick?.(event); onOpen(); }}
45
+ >
46
+ <OutputStatusIndicator status={status} />
47
+ <span className="astra-output-entry__name">
48
+ {title}
49
+ {!metric && absenceNote && !status ? <span className="astra-output-entry__status">{absenceNote}</span> : null}
50
+ </span>
51
+ {metric ? (
52
+ <span className="astra-output-entry__value">
53
+ {status?.state === 'stale' && !output.artifact
54
+ ? <span className="astra-artifact__metric-value" aria-label="No value">–</span>
55
+ : renderArtifact?.(output, { compact: true })
56
+ ?? <span className="astra-output-entry__status">{absenceNote ?? 'Preview unavailable'}</span>}
57
+ </span>
58
+ ) : null}
59
+ </button>
60
+ );
61
+ });
@@ -0,0 +1,86 @@
1
+ import { forwardRef, useState, type HTMLAttributes } from 'react';
2
+ import { cn } from '../lib/cn.js';
3
+ import { useLabels } from '../lib/labels.js';
4
+ import type { OutputProvenanceData } from '../model/output-provenance.js';
5
+ import { DetailDialog } from '../primitives/dialog.js';
6
+ import { OutputStatusGlyph } from '../primitives/output-status-glyph.js';
7
+
8
+ export type OutputProvenanceProps = HTMLAttributes<HTMLDivElement> & OutputProvenanceData;
9
+
10
+ /** Compact run summary with the full execution metadata in a detail dialog. */
11
+ export const OutputProvenance = forwardRef<HTMLDivElement, OutputProvenanceProps>(function OutputProvenance({
12
+ status, run, error, className, ...props
13
+ }, ref) {
14
+ const labels = useLabels();
15
+ const copy = labels.provenance;
16
+ const [detailsOpen, setDetailsOpen] = useState(false);
17
+ const stateLabel = status ? labels.status[status.state] : copy.unknown;
18
+ const finished = run ? new Date(run.finishedAt) : null;
19
+ return (
20
+ <div data-slot="output-provenance" {...props} ref={ref} className={cn('astra-output-provenance', className)}>
21
+ <div className="astra-output-provenance__heading">
22
+ <h4>{copy.title}</h4>
23
+ {run ? <button type="button" aria-haspopup="dialog" onClick={() => { setDetailsOpen(true); }}>{copy.details}</button> : null}
24
+ </div>
25
+ <dl className="astra-output-provenance__summary">
26
+ <div>
27
+ <dt>{copy.status}</dt>
28
+ <dd>
29
+ <span className="astra-output-provenance__status">
30
+ {status ? (
31
+ <span className="astra-output-provenance__icon" data-state={status.state} aria-hidden="true">
32
+ <OutputStatusGlyph state={status.state} />
33
+ </span>
34
+ ) : null}
35
+ {stateLabel}
36
+ </span>
37
+ {status?.detail ? <p className="astra-output-provenance__reason">{status.detail}</p> : null}
38
+ </dd>
39
+ </div>
40
+ {run ? <>
41
+ <div>
42
+ <dt>{copy.lastRun}</dt>
43
+ <dd><time dateTime={run.finishedAt}>{finished && !Number.isNaN(finished.getTime()) ? finished.toLocaleString() : run.finishedAt}</time></dd>
44
+ </div>
45
+ <div>
46
+ <dt>{copy.revision}</dt>
47
+ <dd><code title={run.gitRevision}>{run.gitRevision.slice(0, 8)}</code></dd>
48
+ </div>
49
+ </> : null}
50
+ </dl>
51
+ {error ? <p role="alert">{error}</p> : run === undefined ? <p role="status">{copy.loading}</p> : run === null ? <p>{copy.noRun}</p> : null}
52
+ {detailsOpen && run ? (
53
+ <DetailDialog
54
+ mode="modal"
55
+ title={copy.runDetails}
56
+ closeLabel={copy.closeDetails}
57
+ onClose={() => { setDetailsOpen(false); }}
58
+ panelClassName="astra-output-provenance__dialog-panel"
59
+ >
60
+ <div className="astra-output-provenance__details">
61
+ <section>
62
+ <h4>{copy.recipe}</h4>
63
+ <pre><code>{run.recipe}</code></pre>
64
+ </section>
65
+ <section>
66
+ <h4>{copy.inputs}</h4>
67
+ {Object.keys(run.inputVersions).length ? (
68
+ <dl>{Object.entries(run.inputVersions).map(([name, version]) => (
69
+ <div key={name}><dt>{name}</dt><dd><code>{version}</code></dd></div>
70
+ ))}</dl>
71
+ ) : <p>{copy.noInputs}</p>}
72
+ </section>
73
+ <section>
74
+ <h4>{copy.environment}</h4>
75
+ <p><code>{run.environment}</code></p>
76
+ </section>
77
+ <section>
78
+ <h4>{copy.cliVersion}</h4>
79
+ <p>{run.cliVersion}</p>
80
+ </section>
81
+ </div>
82
+ </DetailDialog>
83
+ ) : null}
84
+ </div>
85
+ );
86
+ });