@astra-spec/ui 0.0.3 → 0.0.4

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 (245) hide show
  1. package/README.md +173 -20
  2. package/TOKENS.md +6 -3
  3. package/components.css +1 -0
  4. package/dist/blocks/decisions-list.d.ts +0 -1
  5. package/dist/blocks/decisions-list.d.ts.map +1 -1
  6. package/dist/blocks/decisions-list.js +1 -5
  7. package/dist/blocks/decisions-list.js.map +1 -1
  8. package/dist/blocks/index.d.ts +3 -3
  9. package/dist/blocks/index.d.ts.map +1 -1
  10. package/dist/blocks/index.js +2 -2
  11. package/dist/blocks/index.js.map +1 -1
  12. package/dist/blocks/inputs-list.js +1 -1
  13. package/dist/blocks/inputs-list.js.map +1 -1
  14. package/dist/blocks/outputs-list.d.ts +2 -2
  15. package/dist/blocks/outputs-list.d.ts.map +1 -1
  16. package/dist/blocks/outputs-list.js +15 -19
  17. package/dist/blocks/outputs-list.js.map +1 -1
  18. package/dist/blocks/section.d.ts +1 -4
  19. package/dist/blocks/section.d.ts.map +1 -1
  20. package/dist/blocks/section.js +1 -12
  21. package/dist/blocks/section.js.map +1 -1
  22. package/dist/components/artifact-preview.d.ts +2 -54
  23. package/dist/components/artifact-preview.d.ts.map +1 -1
  24. package/dist/components/artifact-preview.js +2 -107
  25. package/dist/components/artifact-preview.js.map +1 -1
  26. package/dist/components/decision-detail.d.ts +1 -1
  27. package/dist/components/decision-detail.d.ts.map +1 -1
  28. package/dist/components/decision-detail.js.map +1 -1
  29. package/dist/components/finding-detail.d.ts +2 -2
  30. package/dist/components/finding-detail.d.ts.map +1 -1
  31. package/dist/components/finding-detail.js.map +1 -1
  32. package/dist/components/index.d.ts +9 -13
  33. package/dist/components/index.d.ts.map +1 -1
  34. package/dist/components/index.js +6 -8
  35. package/dist/components/index.js.map +1 -1
  36. package/dist/components/input-detail.d.ts +1 -2
  37. package/dist/components/input-detail.d.ts.map +1 -1
  38. package/dist/components/input-detail.js +0 -3
  39. package/dist/components/input-detail.js.map +1 -1
  40. package/dist/components/insight-detail.d.ts +2 -8
  41. package/dist/components/insight-detail.d.ts.map +1 -1
  42. package/dist/components/insight-detail.js +5 -11
  43. package/dist/components/insight-detail.js.map +1 -1
  44. package/dist/components/insight-trigger.d.ts +1 -1
  45. package/dist/components/insight-trigger.d.ts.map +1 -1
  46. package/dist/components/insight-trigger.js.map +1 -1
  47. package/dist/components/output-detail.d.ts +2 -7
  48. package/dist/components/output-detail.d.ts.map +1 -1
  49. package/dist/components/output-detail.js +3 -30
  50. package/dist/components/output-detail.js.map +1 -1
  51. package/dist/components/output-dialog.d.ts +2 -2
  52. package/dist/components/output-dialog.d.ts.map +1 -1
  53. package/dist/components/output-dialog.js +2 -1
  54. package/dist/components/output-dialog.js.map +1 -1
  55. package/dist/components/paper-detail.d.ts +14 -14
  56. package/dist/components/paper-detail.d.ts.map +1 -1
  57. package/dist/components/paper-detail.js +49 -29
  58. package/dist/components/paper-detail.js.map +1 -1
  59. package/dist/components/paper-pdf-viewer.d.ts +19 -0
  60. package/dist/components/paper-pdf-viewer.d.ts.map +1 -0
  61. package/dist/components/paper-pdf-viewer.js +250 -0
  62. package/dist/components/paper-pdf-viewer.js.map +1 -0
  63. package/dist/components/record-dialog.d.ts +7 -5
  64. package/dist/components/record-dialog.d.ts.map +1 -1
  65. package/dist/components/record-dialog.js +7 -5
  66. package/dist/components/record-dialog.js.map +1 -1
  67. package/dist/components/record-preview.d.ts +2 -2
  68. package/dist/components/record-preview.d.ts.map +1 -1
  69. package/dist/components/record-preview.js +2 -2
  70. package/dist/components/record-preview.js.map +1 -1
  71. package/dist/components/relation-items.d.ts +1 -1
  72. package/dist/components/relation-items.d.ts.map +1 -1
  73. package/dist/components/relation-items.js +10 -3
  74. package/dist/components/relation-items.js.map +1 -1
  75. package/dist/{components/use-detail-stack.d.ts → lib/detail-stack.d.ts} +17 -2
  76. package/dist/lib/detail-stack.d.ts.map +1 -0
  77. package/dist/{components/use-detail-stack.js → lib/detail-stack.js} +15 -2
  78. package/dist/lib/detail-stack.js.map +1 -0
  79. package/dist/lib/index.d.ts +14 -0
  80. package/dist/lib/index.d.ts.map +1 -0
  81. package/dist/lib/index.js +9 -0
  82. package/dist/lib/index.js.map +1 -0
  83. package/dist/lib/labels.d.ts +20 -0
  84. package/dist/lib/labels.d.ts.map +1 -1
  85. package/dist/lib/labels.js +20 -0
  86. package/dist/lib/labels.js.map +1 -1
  87. package/dist/lib/pdf-quote.d.ts +47 -0
  88. package/dist/lib/pdf-quote.d.ts.map +1 -0
  89. package/dist/lib/pdf-quote.js +154 -0
  90. package/dist/lib/pdf-quote.js.map +1 -0
  91. package/dist/lib/pdf-runtime.d.ts +102 -0
  92. package/dist/lib/pdf-runtime.d.ts.map +1 -0
  93. package/dist/lib/pdf-runtime.js +48 -0
  94. package/dist/lib/pdf-runtime.js.map +1 -0
  95. package/dist/lib/preview-data.d.ts +55 -0
  96. package/dist/lib/preview-data.d.ts.map +1 -0
  97. package/dist/lib/preview-data.js +108 -0
  98. package/dist/lib/preview-data.js.map +1 -0
  99. package/dist/lib/prose.d.ts +37 -0
  100. package/dist/lib/prose.d.ts.map +1 -0
  101. package/dist/lib/prose.js +60 -0
  102. package/dist/lib/prose.js.map +1 -0
  103. package/dist/lib/use-isomorphic-layout-effect.d.ts +4 -0
  104. package/dist/lib/use-isomorphic-layout-effect.d.ts.map +1 -0
  105. package/dist/lib/use-isomorphic-layout-effect.js +4 -0
  106. package/dist/lib/use-isomorphic-layout-effect.js.map +1 -0
  107. package/dist/lib/use-output-expanded.d.ts +7 -0
  108. package/dist/lib/use-output-expanded.d.ts.map +1 -0
  109. package/dist/lib/use-output-expanded.js +29 -0
  110. package/dist/lib/use-output-expanded.js.map +1 -0
  111. package/dist/model/index.d.ts +5 -3
  112. package/dist/model/index.d.ts.map +1 -1
  113. package/dist/model/index.js +3 -2
  114. package/dist/model/index.js.map +1 -1
  115. package/dist/{primitives → model}/kind.d.ts +3 -0
  116. package/dist/model/kind.d.ts.map +1 -0
  117. package/dist/model/kind.js +25 -0
  118. package/dist/model/kind.js.map +1 -0
  119. package/dist/model/papers.d.ts +6 -6
  120. package/dist/model/papers.d.ts.map +1 -1
  121. package/dist/model/papers.js +8 -0
  122. package/dist/model/papers.js.map +1 -1
  123. package/dist/model/records.d.ts +5 -1
  124. package/dist/model/records.d.ts.map +1 -1
  125. package/dist/model/records.js +9 -0
  126. package/dist/model/records.js.map +1 -1
  127. package/dist/primitives/badge.d.ts +1 -1
  128. package/dist/primitives/badge.d.ts.map +1 -1
  129. package/dist/primitives/button.js +1 -1
  130. package/dist/primitives/button.js.map +1 -1
  131. package/dist/primitives/dialog.d.ts +1 -1
  132. package/dist/primitives/dialog.d.ts.map +1 -1
  133. package/dist/primitives/dialog.js +3 -3
  134. package/dist/primitives/dialog.js.map +1 -1
  135. package/dist/primitives/index.d.ts +4 -9
  136. package/dist/primitives/index.d.ts.map +1 -1
  137. package/dist/primitives/index.js +2 -5
  138. package/dist/primitives/index.js.map +1 -1
  139. package/dist/primitives/preview-popover.d.ts +1 -1
  140. package/dist/primitives/preview-popover.d.ts.map +1 -1
  141. package/dist/primitives/preview-popover.js +1 -1
  142. package/dist/primitives/preview-popover.js.map +1 -1
  143. package/dist/primitives/prose.d.ts +1 -35
  144. package/dist/primitives/prose.d.ts.map +1 -1
  145. package/dist/primitives/prose.js +2 -58
  146. package/dist/primitives/prose.js.map +1 -1
  147. package/dist/primitives/record-list.d.ts +1 -1
  148. package/dist/primitives/record-list.d.ts.map +1 -1
  149. package/dist/primitives/record-list.js +1 -1
  150. package/dist/primitives/record-list.js.map +1 -1
  151. package/dist/primitives/relation-list.d.ts +1 -1
  152. package/dist/primitives/relation-list.d.ts.map +1 -1
  153. package/dist/primitives/relation-list.js +1 -1
  154. package/dist/primitives/relation-list.js.map +1 -1
  155. package/dist/primitives/slot.d.ts.map +1 -0
  156. package/dist/{lib → primitives}/slot.js +1 -1
  157. package/dist/primitives/slot.js.map +1 -0
  158. package/dist/primitives/surface-header.d.ts +1 -1
  159. package/dist/primitives/surface-header.d.ts.map +1 -1
  160. package/dist/views/inventory.d.ts +7 -5
  161. package/dist/views/inventory.d.ts.map +1 -1
  162. package/dist/views/inventory.js +5 -4
  163. package/dist/views/inventory.js.map +1 -1
  164. package/package.json +11 -1
  165. package/src/blocks/decisions-list.tsx +1 -6
  166. package/src/blocks/index.ts +2 -3
  167. package/src/blocks/inputs-list.tsx +1 -1
  168. package/src/blocks/outputs-list.tsx +53 -30
  169. package/src/blocks/section.tsx +1 -14
  170. package/src/components/artifact-preview.tsx +6 -161
  171. package/src/components/decision-detail.tsx +2 -1
  172. package/src/components/finding-detail.tsx +3 -2
  173. package/src/components/index.ts +10 -30
  174. package/src/components/input-detail.tsx +2 -5
  175. package/src/components/insight-detail.tsx +20 -35
  176. package/src/components/insight-trigger.tsx +2 -1
  177. package/src/components/output-detail.tsx +17 -38
  178. package/src/components/output-dialog.tsx +4 -3
  179. package/src/components/paper-detail.tsx +121 -66
  180. package/src/components/paper-pdf-viewer.tsx +319 -0
  181. package/src/components/record-dialog.tsx +15 -10
  182. package/src/components/record-preview.tsx +5 -4
  183. package/src/components/relation-items.ts +15 -5
  184. package/src/{components/use-detail-stack.ts → lib/detail-stack.ts} +24 -1
  185. package/src/lib/index.ts +22 -0
  186. package/src/lib/labels.tsx +40 -0
  187. package/src/lib/pdf-quote.ts +189 -0
  188. package/src/lib/pdf-runtime.ts +131 -0
  189. package/src/lib/preview-data.ts +155 -0
  190. package/src/lib/prose.tsx +87 -0
  191. package/src/lib/use-isomorphic-layout-effect.ts +4 -0
  192. package/src/lib/use-output-expanded.ts +27 -0
  193. package/src/model/index.ts +4 -2
  194. package/src/{primitives → model}/kind.ts +14 -0
  195. package/src/model/papers.ts +9 -7
  196. package/src/model/records.ts +12 -0
  197. package/src/primitives/badge.tsx +1 -1
  198. package/src/primitives/button.tsx +1 -1
  199. package/src/primitives/dialog.tsx +3 -5
  200. package/src/primitives/index.ts +4 -17
  201. package/src/primitives/preview-popover.tsx +2 -2
  202. package/src/primitives/prose.tsx +1 -86
  203. package/src/primitives/record-list.tsx +1 -1
  204. package/src/primitives/relation-list.tsx +1 -1
  205. package/src/{lib → primitives}/slot.tsx +1 -1
  206. package/src/primitives/surface-header.tsx +1 -1
  207. package/src/views/inventory.tsx +12 -8
  208. package/styles/blocks/analysis-tree.css +2 -2
  209. package/styles/blocks/decisions-list.css +4 -4
  210. package/styles/blocks/outputs-list.css +246 -19
  211. package/styles/blocks/papers-list.css +2 -2
  212. package/styles/components/artifact-preview.css +6 -6
  213. package/styles/components/decision-detail.css +2 -2
  214. package/styles/components/evidence.css +2 -2
  215. package/styles/components/input-detail.css +4 -4
  216. package/styles/components/insight-detail.css +56 -94
  217. package/styles/components/insight-list.css +3 -3
  218. package/styles/components/insight-trigger.css +1 -4
  219. package/styles/components/output-detail.css +25 -140
  220. package/styles/components/paper-detail.css +76 -95
  221. package/styles/components/paper-doi.css +3 -12
  222. package/styles/components/paper-pdf-viewer.css +120 -0
  223. package/styles/components/record-preview.css +10 -10
  224. package/styles/primitives/badge.css +1 -1
  225. package/styles/primitives/count-heading.css +2 -2
  226. package/styles/primitives/detail-layout.css +5 -5
  227. package/styles/primitives/dialog.css +9 -9
  228. package/styles/primitives/record-list.css +17 -17
  229. package/styles/primitives/relation-list.css +6 -6
  230. package/styles/primitives/surface-header.css +5 -5
  231. package/styles/tokens.css +11 -3
  232. package/styles/views/inventory.css +3 -3
  233. package/dist/components/detail-entry.d.ts +0 -15
  234. package/dist/components/detail-entry.d.ts.map +0 -1
  235. package/dist/components/detail-entry.js +0 -14
  236. package/dist/components/detail-entry.js.map +0 -1
  237. package/dist/components/use-detail-stack.d.ts.map +0 -1
  238. package/dist/components/use-detail-stack.js.map +0 -1
  239. package/dist/lib/slot.d.ts.map +0 -1
  240. package/dist/lib/slot.js.map +0 -1
  241. package/dist/primitives/kind.d.ts.map +0 -1
  242. package/dist/primitives/kind.js +0 -14
  243. package/dist/primitives/kind.js.map +0 -1
  244. package/src/components/detail-entry.ts +0 -19
  245. /package/dist/{lib → primitives}/slot.d.ts +0 -0
@@ -1,17 +1,16 @@
1
1
  /** Blocks: sections of the inventory page, composable into any layout. */
2
2
  export { AnalysisTree } from './analysis-tree.js';
3
3
  export type { AnalysisTreeProps } from './analysis-tree.js';
4
- export { InventoryOutline, sectionKind, InventoryRecords, InventorySection } from './section.js';
4
+ export { InventoryOutline, InventoryRecords, InventorySection } from './section.js';
5
5
  export type {
6
6
  InventoryOutlineEntry,
7
7
  InventoryOutlineProps,
8
8
  InventoryRecordsProps,
9
- InventorySectionId,
10
9
  InventorySectionProps,
11
10
  } from './section.js';
12
11
  export { OutputCard, OutputsList } from './outputs-list.js';
13
12
  export type { OutputCardProps, OutputsListProps } from './outputs-list.js';
14
- export { ALL_TAGS, DecisionsList, decisionTagLabel } from './decisions-list.js';
13
+ export { ALL_TAGS, DecisionsList } from './decisions-list.js';
15
14
  export type { DecisionsListProps } from './decisions-list.js';
16
15
  export { InputsList } from './inputs-list.js';
17
16
  export type { InputsListProps } from './inputs-list.js';
@@ -2,7 +2,7 @@ import type { ResolvedAnalysisNode, ResolvedInput } from '@astra-spec/sdk';
2
2
  import { forwardRef, type HTMLAttributes } from 'react';
3
3
  import { recordTitle } from '../model/records.js';
4
4
  import { useLabels } from '../lib/labels.js';
5
- import { inputSourceLabel } from '../components/input-detail.js';
5
+ import { inputSourceLabel } from '../model/records.js';
6
6
  import { EmptyState, RecordIdentity, RecordList } from '../primitives/record-list.js';
7
7
  import { InventoryRecords } from './section.js';
8
8
 
@@ -4,7 +4,7 @@ import { recordTitle } from '../model/records.js';
4
4
  import { cn } from '../lib/cn.js';
5
5
  import { useLabels } from '../lib/labels.js';
6
6
  import type { ArtifactRenderer } from '../components/artifact-preview.js';
7
- import { EmptyState, RecordIdentity, RecordList } from '../primitives/record-list.js';
7
+ import { EmptyState } from '../primitives/record-list.js';
8
8
  import { OutputPreview } from '../components/output-detail.js';
9
9
 
10
10
  export interface OutputsListProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
@@ -19,7 +19,7 @@ export interface OutputCardProps extends Omit<HTMLAttributes<HTMLButtonElement>,
19
19
  onOpen: () => void;
20
20
  }
21
21
 
22
- /** A gallery card: compact preview, type, and title. */
22
+ /** A gallery card: compact preview and title, with a type label for non-figures. */
23
23
  export const OutputCard = forwardRef<HTMLButtonElement, OutputCardProps>(function OutputCard({
24
24
  output,
25
25
  renderArtifact,
@@ -44,7 +44,7 @@ export const OutputCard = forwardRef<HTMLButtonElement, OutputCardProps>(functio
44
44
  <span className="astra-output-card__open" aria-hidden="true">Open ↗</span>
45
45
  </span>
46
46
  <span className="astra-output-card__body">
47
- <span className="astra-output-card__kind">{output.type}</span>
47
+ {output.type !== 'figure' ? <span className="astra-output-card__kind">{output.type}</span> : null}
48
48
  <strong>{recordTitle(output)}</strong>
49
49
  {output.label ? <code>{output.id}</code> : null}
50
50
  </span>
@@ -84,40 +84,61 @@ function OutputGallery({
84
84
  );
85
85
  }
86
86
 
87
- function OutputFiles({ outputs, onOpen }: { outputs: ResolvedOutput[]; onOpen: (output: ResolvedOutput) => void }) {
87
+ function CompactOutputs({
88
+ title,
89
+ outputs,
90
+ renderArtifact,
91
+ onOpen,
92
+ }: {
93
+ title: string;
94
+ outputs: ResolvedOutput[];
95
+ renderArtifact?: ArtifactRenderer | undefined;
96
+ onOpen: (output: ResolvedOutput) => void;
97
+ }) {
88
98
  const id = useId();
89
99
  if (!outputs.length) return null;
90
100
  return (
91
- <section className="astra-inventory-outputs__group astra-inventory-outputs__files" aria-labelledby={id}>
101
+ <section className="astra-inventory-outputs__group" aria-labelledby={id}>
92
102
  <h3 id={id} className="astra-inventory-outputs__group-heading">
93
- <span>Other outputs</span>
103
+ <span>{title}</span>
94
104
  </h3>
95
- <RecordList
96
- label="Other outputs"
97
- columnTemplate="minmax(14rem, 1fr) 1.5rem"
98
- columns={[
99
- { label: 'Output', className: 'astra-record-list__primary' },
100
- { className: 'astra-record-list__arrow' },
101
- ]}
102
- rows={outputs.map((output) => ({
103
- key: output.canonicalPath,
104
- accessibleLabel: recordTitle(output),
105
- onOpen: () => { onOpen(output); },
106
- cells: [
107
- <RecordIdentity
108
- kind="output"
109
- title={recordTitle(output)}
110
- subtitle={output.label ? output.id : output.format?.toUpperCase()}
111
- />,
112
- <span aria-hidden="true">→</span>,
113
- ],
114
- }))}
115
- />
105
+ <ul className="astra-inventory-outputs__compact-grid" data-layout={outputs[0]?.type === 'metric' ? 'tiles' : 'grid'}>
106
+ {outputs.map((output) => {
107
+ const metric = output.type === 'metric';
108
+ const status = !output.active ? 'Inactive' : !output.artifact ? 'Not yet generated' : undefined;
109
+ return (
110
+ <li key={output.canonicalPath}>
111
+ <button
112
+ type="button"
113
+ className="astra-output-entry"
114
+ data-kind={metric ? 'metric' : 'file'}
115
+ aria-label={`Open ${output.type}: ${recordTitle(output)}`}
116
+ onClick={() => { onOpen(output); }}
117
+ >
118
+ <span className="astra-output-entry__name">
119
+ {recordTitle(output)}
120
+ {!metric && status ? <span className="astra-output-entry__status">{status}</span> : null}
121
+ </span>
122
+ {metric ? (
123
+ <span className="astra-output-entry__value">
124
+ {renderArtifact?.(output, { compact: true })
125
+ ?? <span className="astra-output-entry__status">{status ?? 'Preview unavailable'}</span>}
126
+ </span>
127
+ ) : (
128
+ <span className="astra-output-entry__format">{output.format ? output.format.replace(/^\./, '').toUpperCase() : 'FILE'}</span>
129
+ )}
130
+ </button>
131
+ </li>
132
+ );
133
+ })}
134
+ </ul>
116
135
  </section>
117
136
  );
118
137
  }
119
138
 
120
- /** Figures and tables as galleries, everything else as a list. */
139
+ const GROUPED_TYPES = new Set<ResolvedOutput['type']>(['figure', 'table', 'metric']);
140
+
141
+ /** Figures and tables as galleries, metrics as compact tiles, files as a compact grid. */
121
142
  export const OutputsList = forwardRef<HTMLDivElement, OutputsListProps>(function OutputsList({
122
143
  analysis,
123
144
  renderArtifact,
@@ -128,7 +149,8 @@ export const OutputsList = forwardRef<HTMLDivElement, OutputsListProps>(function
128
149
  const labels = useLabels();
129
150
  const figures = analysis.outputs.filter(({ type }) => type === 'figure');
130
151
  const tables = analysis.outputs.filter(({ type }) => type === 'table');
131
- const files = analysis.outputs.filter(({ type }) => type !== 'figure' && type !== 'table');
152
+ const metrics = analysis.outputs.filter(({ type }) => type === 'metric');
153
+ const files = analysis.outputs.filter(({ type }) => !GROUPED_TYPES.has(type));
132
154
  if (!analysis.outputs.length) {
133
155
  return <EmptyState data-slot="outputs-list" {...props} ref={ref} className={className}>{labels.empty.outputs}</EmptyState>;
134
156
  }
@@ -137,7 +159,8 @@ export const OutputsList = forwardRef<HTMLDivElement, OutputsListProps>(function
137
159
  <div data-slot="outputs-list" {...props} ref={ref} className={cn('astra-inventory-outputs', className)}>
138
160
  <OutputGallery title="Figures" outputs={figures} renderArtifact={renderArtifact} onOpen={open} />
139
161
  <OutputGallery title="Tables" outputs={tables} renderArtifact={renderArtifact} onOpen={open} />
140
- <OutputFiles outputs={files} onOpen={open} />
162
+ <CompactOutputs title="Metrics" outputs={metrics} renderArtifact={renderArtifact} onOpen={open} />
163
+ <CompactOutputs title="Output files" outputs={files} onOpen={open} />
141
164
  </div>
142
165
  );
143
166
  });
@@ -1,10 +1,8 @@
1
1
  import { forwardRef, type HTMLAttributes, type ReactNode } from 'react';
2
2
  import { cn } from '../lib/cn.js';
3
- import { surfaceGlyph, type SurfaceKind } from '../primitives/kind.js';
3
+ import { surfaceGlyph, type InventorySectionId, type SurfaceKind } from '../model/kind.js';
4
4
  import { useLabels } from '../lib/labels.js';
5
5
 
6
- export type InventorySectionId = 'outputs' | 'decisions' | 'inputs' | 'findings' | 'prior_insights' | 'papers';
7
-
8
6
  export interface InventorySectionProps extends Omit<HTMLAttributes<HTMLElement>, 'title'> {
9
7
  /** Anchor id for the heading; also the outline link target. */
10
8
  id: string;
@@ -46,17 +44,6 @@ export const InventorySection = forwardRef<HTMLElement, InventorySectionProps>(f
46
44
  );
47
45
  });
48
46
 
49
- /** The record kind each inventory section lists; drives the outline glyph and colour. */
50
- export function sectionKind(section: InventorySectionId): SurfaceKind {
51
- switch (section) {
52
- case 'outputs': return 'output';
53
- case 'decisions': return 'decision';
54
- case 'inputs': return 'input';
55
- case 'findings': return 'finding';
56
- case 'prior_insights': return 'prior_insight';
57
- case 'papers': return 'paper';
58
- }
59
- }
60
47
 
61
48
  export interface InventoryOutlineEntry {
62
49
  id: string;
@@ -1,59 +1,7 @@
1
1
  import type { ResolvedOutput } from '@astra-spec/sdk';
2
2
  import { forwardRef, useEffect, useState, type HTMLAttributes, type ReactNode } from 'react';
3
3
  import { cn } from '../lib/cn.js';
4
-
5
- export interface TablePreviewData {
6
- kind: 'table';
7
- headers: string[];
8
- rows: (string | number | boolean | null)[][];
9
- /** Exact number of rows in the source. Leave unset when the source was sampled and the total is unknown. */
10
- totalRows?: number | undefined;
11
- totalColumns?: number | undefined;
12
- /** The preview does not show everything: rows or columns were cut, or the source itself was a sample. */
13
- truncated?: boolean | undefined;
14
- }
15
-
16
- export interface ImagePreviewData {
17
- kind: 'image';
18
- url: string;
19
- alt?: string | undefined;
20
- width?: number | undefined;
21
- height?: number | undefined;
22
- }
23
-
24
- export interface MetricPreviewData {
25
- kind: 'metric';
26
- value: number | string;
27
- uncertainty?: number | string | undefined;
28
- unit?: string | undefined;
29
- label?: string | undefined;
30
- }
31
-
32
- export interface TextPreviewData {
33
- kind: 'text';
34
- text: string;
35
- language?: string | undefined;
36
- truncated?: boolean | undefined;
37
- }
38
-
39
- export interface LoadingPreviewData {
40
- kind: 'loading';
41
- message?: string | undefined;
42
- }
43
-
44
- export interface UnavailablePreviewData {
45
- kind: 'unavailable';
46
- reason?: string | undefined;
47
- }
48
-
49
- /** Host-safe data that a portable component can render without reading a file. */
50
- export type ArtifactPreviewData =
51
- | TablePreviewData
52
- | ImagePreviewData
53
- | MetricPreviewData
54
- | TextPreviewData
55
- | LoadingPreviewData
56
- | UnavailablePreviewData;
4
+ import type { ArtifactPreviewData } from '../lib/preview-data.js';
57
5
 
58
6
  export interface ArtifactRenderOptions {
59
7
  compact: boolean;
@@ -70,10 +18,11 @@ export interface ArtifactPreviewProps extends Omit<HTMLAttributes<HTMLElement>,
70
18
  preview?: ArtifactPreviewData | undefined;
71
19
  compact?: boolean | undefined;
72
20
  caption?: ReactNode | undefined;
73
- /** Pure helpers exported below build the default preview data. */
21
+ /** Builders in `lib/preview-data` produce this from data the host already loaded. */
74
22
  locale?: string | undefined;
75
23
  }
76
24
 
25
+ /** Numbers are rounded for display; strings are the host's exact choice and pass through. */
77
26
  function compactValue(value: string | number | undefined, locale: string | undefined): string {
78
27
  if (value == null || value === '') return 'Value unavailable';
79
28
  return typeof value === 'number'
@@ -190,10 +139,10 @@ export const ArtifactPreview = forwardRef<HTMLElement, ArtifactPreviewProps>(fun
190
139
  if (preview.kind === 'metric') {
191
140
  return (
192
141
  <div {...shared} ref={ref as never} className={cn(rootClass, 'astra-artifact__metric')}>
193
- {preview.label ? <span>{preview.label}</span> : null}
142
+ {preview.label ? <span className="astra-artifact__metric-label">{preview.label}</span> : null}
194
143
  <strong className="astra-artifact__metric-value">{compactValue(preview.value, locale)}</strong>
195
- {preview.uncertainty !== undefined ? (
196
- <span className="astra-artifact__metric-uncertainty">± {preview.uncertainty}</span>
144
+ {preview.uncertainty != null && preview.uncertainty !== '' ? (
145
+ <span className="astra-artifact__metric-uncertainty">± {compactValue(preview.uncertainty, locale)}</span>
197
146
  ) : null}
198
147
  {preview.unit ? <span className="astra-artifact__metric-unit">{preview.unit}</span> : null}
199
148
  </div>
@@ -208,107 +157,3 @@ export const ArtifactPreview = forwardRef<HTMLElement, ArtifactPreviewProps>(fun
208
157
  );
209
158
  });
210
159
 
211
- /* ------------------------------------------------------------------ */
212
- /* Pure helpers hosts can use to build preview data (no I/O) */
213
- /* ------------------------------------------------------------------ */
214
-
215
- export interface DelimitedPreviewOptions {
216
- delimiter?: string | undefined;
217
- maxRows?: number | undefined;
218
- maxColumns?: number | undefined;
219
- /** Set when the source text was itself cut short by the host. */
220
- sourceTruncated?: boolean | undefined;
221
- }
222
-
223
- /** RFC 4180-style rows: quoted cells may hold delimiters, doubled quotes, and line breaks. Blank rows are dropped. */
224
- function parseDelimited(text: string, delimiter: string): { rows: string[][]; unterminated: boolean } {
225
- const rows: string[][] = [];
226
- let row: string[] = [];
227
- let cell = '';
228
- let quoted = false;
229
- const endCell = () => { row.push(cell.trim()); cell = ''; };
230
- const endRow = () => {
231
- endCell();
232
- if (row.some((value) => value.length > 0)) rows.push(row);
233
- row = [];
234
- };
235
- for (let index = 0; index < text.length; index += 1) {
236
- const character = text.charAt(index);
237
- if (quoted) {
238
- if (character !== '"') cell += character;
239
- else if (text.charAt(index + 1) === '"') { cell += '"'; index += 1; } else quoted = false;
240
- } else if (character === '"') quoted = true;
241
- else if (character === delimiter) endCell();
242
- else if (character === '\n' || character === '\r') {
243
- if (character === '\r' && text.charAt(index + 1) === '\n') index += 1;
244
- endRow();
245
- } else cell += character;
246
- }
247
- endRow();
248
- return { rows, unterminated: quoted };
249
- }
250
-
251
- /** Turns delimited text (CSV, TSV) into table preview data. */
252
- export function tablePreviewFromDelimited(text: string, options: DelimitedPreviewOptions = {}): TablePreviewData {
253
- const delimiter = options.delimiter ?? ',';
254
- const maxRows = options.maxRows ?? 30;
255
- const maxColumns = options.maxColumns ?? 30;
256
- const parsed = parseDelimited(text, delimiter);
257
- const [allHeaders = [], ...records] = parsed.rows;
258
- // A byte-limited sample may end inside a record (or inside a quoted cell);
259
- // that record is dropped, and the total row count is unknown.
260
- const sampled = Boolean(options.sourceTruncated);
261
- const lastComplete = /\r?\n$/.test(text) && !parsed.unterminated;
262
- const body = sampled && !lastComplete ? records.slice(0, -1) : records;
263
- const headers = allHeaders.slice(0, maxColumns);
264
- const rows = body.slice(0, maxRows).map((cells) => cells.slice(0, maxColumns));
265
- return {
266
- kind: 'table',
267
- headers,
268
- rows,
269
- ...(sampled ? {} : { totalRows: body.length }),
270
- totalColumns: allHeaders.length,
271
- truncated: sampled || body.length > maxRows || allHeaders.length > maxColumns,
272
- };
273
- }
274
-
275
- /** Turns an array of flat objects (e.g. parsed JSON records) into table preview data. */
276
- export function tablePreviewFromRows(
277
- records: readonly Record<string, unknown>[],
278
- options: Pick<DelimitedPreviewOptions, 'maxRows' | 'maxColumns' | 'sourceTruncated'> = {},
279
- ): TablePreviewData {
280
- const maxRows = options.maxRows ?? 30;
281
- const maxColumns = options.maxColumns ?? 30;
282
- const allHeaders = [...new Set(records.flatMap((record) => Object.keys(record)))];
283
- const headers = allHeaders.slice(0, maxColumns);
284
- const rows = records.slice(0, maxRows).map((record) => headers.map((header) => {
285
- const value = record[header];
286
- if (value == null) return null;
287
- if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string') return value;
288
- return JSON.stringify(value);
289
- }));
290
- return {
291
- kind: 'table',
292
- headers,
293
- rows,
294
- totalRows: records.length,
295
- totalColumns: allHeaders.length,
296
- truncated: Boolean(options.sourceTruncated) || records.length > maxRows || allHeaders.length > maxColumns,
297
- };
298
- }
299
-
300
- /** Reads a metric from a scalar or a `{ value, uncertainty?, unit?, label? }` object; `undefined` when the shape is not a metric. */
301
- export function metricPreviewFromJson(value: unknown): MetricPreviewData | undefined {
302
- if (typeof value === 'number' || typeof value === 'string') return { kind: 'metric', value };
303
- if (value && typeof value === 'object' && 'value' in value) {
304
- const record = value as Record<string, unknown>;
305
- const metric = record.value;
306
- if (typeof metric !== 'number' && typeof metric !== 'string') return undefined;
307
- const result: MetricPreviewData = { kind: 'metric', value: metric };
308
- if (typeof record.uncertainty === 'number' || typeof record.uncertainty === 'string') result.uncertainty = record.uncertainty;
309
- if (typeof record.unit === 'string') result.unit = record.unit;
310
- if (typeof record.label === 'string') result.label = record.label;
311
- return result;
312
- }
313
- return undefined;
314
- }
@@ -4,7 +4,8 @@ import { recordTitle } from '../model/records.js';
4
4
  import { useLabels } from '../lib/labels.js';
5
5
  import { CountHeading, DetailLayout, DetailMain, DetailSection } from '../primitives/detail-layout.js';
6
6
  import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
7
- import { Prose, type TextRenderer } from '../primitives/prose.js';
7
+ import { Prose } from '../primitives/prose.js';
8
+ import type { TextRenderer } from '../lib/prose.js';
8
9
  import { InsightTrigger } from './insight-trigger.js';
9
10
 
10
11
  export interface DecisionDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
@@ -7,9 +7,10 @@ import { cn } from '../lib/cn.js';
7
7
  import { useLabels } from '../lib/labels.js';
8
8
  import { DetailLayout, DetailMain } from '../primitives/detail-layout.js';
9
9
  import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
10
- import { Prose, type TextRenderer } from '../primitives/prose.js';
10
+ import { Prose } from '../primitives/prose.js';
11
+ import type { TextRenderer } from '../lib/prose.js';
11
12
  import { RelationList } from '../primitives/relation-list.js';
12
- import type { OpenRecordHandler } from './relation-items.js';
13
+ import type { OpenRecordHandler } from '../lib/detail-stack.js';
13
14
 
14
15
  export interface FindingDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
15
16
  record: ResolvedInsight;
@@ -1,11 +1,5 @@
1
- /** ASTRA-aware components: compact previews, one detail body and dialog per record kind, papers, the RecordDialog router, and the detail stack. */
2
- export { recordEntry, paperEntry, sameEntry } from './detail-entry.js';
3
- export type { DetailEntry } from './detail-entry.js';
4
- export { useDetailStack } from './use-detail-stack.js';
5
- export type { DetailStack, DetailStackOptions } from './use-detail-stack.js';
6
- export { relationItemForRecord, relationItemsForLinks } from './relation-items.js';
7
- export type { OpenRecordHandler } from './relation-items.js';
8
- export { OutputDetail, OutputDialogActions, OutputPreview, useOutputExpanded } from './output-detail.js';
1
+ /** ASTRA-aware components: one detail body and dialog per record kind, papers and their PDF reader, compact previews, and the RecordDialog router. */
2
+ export { OutputDetail, OutputDialogActions, OutputPreview } from './output-detail.js';
9
3
  export type { OutputDetailProps, OutputDialogActionsProps, OutputPreviewProps } from './output-detail.js';
10
4
  export { OutputDialog } from './output-dialog.js';
11
5
  export type { OutputDialogProps } from './output-dialog.js';
@@ -13,14 +7,14 @@ export { DecisionDetail, DecisionDialog } from './decision-detail.js';
13
7
  export type { DecisionDetailProps, DecisionDialogProps } from './decision-detail.js';
14
8
  export { FindingDetail, FindingDialog } from './finding-detail.js';
15
9
  export type { FindingDetailProps, FindingDialogProps } from './finding-detail.js';
16
- export { InputDetail, InputDialog, inputSourceLabel } from './input-detail.js';
10
+ export { InputDetail, InputDialog } from './input-detail.js';
17
11
  export type { InputDetailProps, InputDialogProps } from './input-detail.js';
18
- export { InsightDetail, InsightDialog, primaryLiteratureEvidence } from './insight-detail.js';
12
+ export { InsightDetail, InsightDialog } from './insight-detail.js';
19
13
  export type { InsightDetailProps, InsightDialogProps } from './insight-detail.js';
20
14
  export { InsightEvidenceTitle, InsightTrigger } from './insight-trigger.js';
21
15
  export type { InsightEvidenceTitleProps, InsightTriggerProps } from './insight-trigger.js';
22
16
  export { PaperDetail, PaperDialog, PaperDialogActions } from './paper-detail.js';
23
- export type { PaperDetailProps, PaperDialogActionsProps, PaperDialogProps, PaperRenderOptions, PaperRenderer } from './paper-detail.js';
17
+ export type { PaperDetailProps, PaperDialogActionsProps, PaperDialogProps, OpenPaperFileHandler } from './paper-detail.js';
24
18
  export { RecordDialog } from './record-dialog.js';
25
19
  export type { RecordDialogProps } from './record-dialog.js';
26
20
  export { RecordPreview } from './record-preview.js';
@@ -33,22 +27,8 @@ export type {
33
27
  RecordPreviewReferenceRenderer,
34
28
  RecordPreviewTarget,
35
29
  } from './record-preview.js';
36
- export {
37
- ArtifactPreview,
38
- metricPreviewFromJson,
39
- tablePreviewFromDelimited,
40
- tablePreviewFromRows,
41
- } from './artifact-preview.js';
42
- export type {
43
- ArtifactPreviewData,
44
- ArtifactPreviewProps,
45
- ArtifactRenderOptions,
46
- ArtifactRenderer,
47
- DelimitedPreviewOptions,
48
- ImagePreviewData,
49
- LoadingPreviewData,
50
- MetricPreviewData,
51
- TablePreviewData,
52
- TextPreviewData,
53
- UnavailablePreviewData,
54
- } from './artifact-preview.js';
30
+ export { ArtifactPreview } from './artifact-preview.js';
31
+ export type { ArtifactPreviewProps, ArtifactRenderOptions, ArtifactRenderer } from './artifact-preview.js';
32
+
33
+ export { PaperPdfViewer } from './paper-pdf-viewer.js';
34
+ export type { PaperPdfViewerProps, PdfLoadState, PdfPassage } from './paper-pdf-viewer.js';
@@ -4,11 +4,8 @@ import { recordTitle } from '../model/records.js';
4
4
  import { useLabels } from '../lib/labels.js';
5
5
  import { DetailLayout, DetailMain, DetailSection } from '../primitives/detail-layout.js';
6
6
  import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
7
- import { Prose, type TextRenderer } from '../primitives/prose.js';
8
-
9
- export function inputSourceLabel(record: ResolvedInput): string {
10
- return record.source ?? record.ref ?? record.resolvedFrom ?? 'Source not declared';
11
- }
7
+ import { Prose } from '../primitives/prose.js';
8
+ import type { TextRenderer } from '../lib/prose.js';
12
9
 
13
10
  export interface InputDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
14
11
  record: ResolvedInput;
@@ -1,24 +1,17 @@
1
1
  import type { ResolvedDecision, ResolvedInsight } from '@astra-spec/sdk';
2
2
  import { forwardRef, type HTMLAttributes } from 'react';
3
3
  import { doiHref } from '../model/doi.js';
4
+ import { primaryLiteratureEvidence } from '../model/papers.js';
4
5
  import { recordTitle } from '../model/records.js';
5
6
  import { cn } from '../lib/cn.js';
6
7
  import { useLabels } from '../lib/labels.js';
7
8
  import { DetailLayout, DetailMain, DetailSection } from '../primitives/detail-layout.js';
8
9
  import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
9
- import { Prose, type TextRenderer } from '../primitives/prose.js';
10
+ import { Prose } from '../primitives/prose.js';
11
+ import type { TextRenderer } from '../lib/prose.js';
10
12
  import { RelationList } from '../primitives/relation-list.js';
11
13
  import { relationItemForRecord } from './relation-items.js';
12
14
 
13
- /**
14
- * The literature evidence an insight is presented against: the first entry
15
- * with a DOI. A quote without a DOI names no paper to open, so it is skipped;
16
- * the passage shown and the paper opened always belong to this one entry.
17
- */
18
- export function primaryLiteratureEvidence(insight: ResolvedInsight) {
19
- return insight.evidence.find((evidence) => Boolean(evidence.doi));
20
- }
21
-
22
15
  export interface InsightDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
23
16
  record: ResolvedInsight;
24
17
  /** Decisions that cite this insight; see `informedDecisions()`. */
@@ -29,7 +22,7 @@ export interface InsightDetailProps extends Omit<HTMLAttributes<HTMLDivElement>,
29
22
  onOpenDecision?: ((decision: ResolvedDecision) => void) | undefined;
30
23
  }
31
24
 
32
- /** Claim, source paper and passage, notes, and the decisions an insight informs. */
25
+ /** Claim, source passage, notes, and the decisions an insight informs. */
33
26
  export const InsightDetail = forwardRef<HTMLDivElement, InsightDetailProps>(function InsightDetail({
34
27
  record: insight,
35
28
  decisions,
@@ -40,7 +33,18 @@ export const InsightDetail = forwardRef<HTMLDivElement, InsightDetailProps>(func
40
33
  ...props
41
34
  }, ref) {
42
35
  const source = primaryLiteratureEvidence(insight);
43
- const sourceLocation = source?.location?.page ? ` · page ${source.location.page}` : '';
36
+ // The way to the paper: through the host when it can show it, else doi.org.
37
+ const sourceAction = source?.doi ? (
38
+ onOpenSource ? (
39
+ <button type="button" className="astra-insight-detail__open-source" onClick={onOpenSource}>
40
+ {source.quote ? 'Locate passage in paper' : 'Open source paper'} <span aria-hidden="true">→</span>
41
+ </button>
42
+ ) : (
43
+ <a className="astra-insight-detail__open-source" href={doiHref(source.doi)} target="_blank" rel="noreferrer">
44
+ Open source paper <span aria-hidden="true">↗</span>
45
+ </a>
46
+ )
47
+ ) : null;
44
48
  return (
45
49
  <DetailLayout data-slot="insight-detail" {...props} ref={ref} layout="single" className={cn('astra-insight-detail', className)}>
46
50
  <DetailMain>
@@ -49,31 +53,12 @@ export const InsightDetail = forwardRef<HTMLDivElement, InsightDetailProps>(func
49
53
  <Prose text={insight.claim} field="claim" renderText={renderText} />
50
54
  </DetailSection>
51
55
  ) : null}
52
- {source?.doi ? (
53
- <section className="astra-insight-detail__paper astra-paper-doi">
54
- <h4>Source paper</h4>
55
- {onOpenSource ? (
56
- <button type="button" onClick={onOpenSource}>
57
- {source.doi}{sourceLocation} ↗
58
- </button>
59
- ) : (
60
- <a href={doiHref(source.doi)} target="_blank" rel="noreferrer">
61
- {source.doi}{sourceLocation} ↗
62
- </a>
63
- )}
64
- </section>
65
- ) : null}
66
56
  {source?.quote ? (
67
- <section className="astra-insight-detail__source-quote">
68
- <h4>Source passage</h4>
57
+ <figure className="astra-insight-detail__source-quote">
69
58
  <blockquote><Prose text={source.quote.exact} field="quote" renderText={renderText} /></blockquote>
70
- {source.doi && onOpenSource ? (
71
- <button type="button" className="astra-insight-detail__open-source" onClick={onOpenSource}>
72
- Locate passage in paper <span aria-hidden="true">→</span>
73
- </button>
74
- ) : null}
75
- </section>
76
- ) : null}
59
+ {sourceAction ? <figcaption>{sourceAction}</figcaption> : null}
60
+ </figure>
61
+ ) : sourceAction}
77
62
  {insight.notes ? (
78
63
  <section className="astra-insight-detail__notes">
79
64
  <h4>Notes</h4>
@@ -9,7 +9,8 @@ import {
9
9
  } from 'react';
10
10
  import { recordTitle } from '../model/records.js';
11
11
  import { cn } from '../lib/cn.js';
12
- import { Prose, type TextRenderer } from '../primitives/prose.js';
12
+ import { Prose } from '../primitives/prose.js';
13
+ import type { TextRenderer } from '../lib/prose.js';
13
14
 
14
15
  export interface InsightEvidenceTitleProps {
15
16
  name: string;