@astra-spec/ui 0.0.1
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/LICENSE +29 -0
- package/README.md +261 -0
- package/TOKENS.md +93 -0
- package/blocks.css +7 -0
- package/components.css +13 -0
- package/dist/blocks/analysis-tree.d.ts +13 -0
- package/dist/blocks/analysis-tree.d.ts.map +1 -0
- package/dist/blocks/analysis-tree.js +19 -0
- package/dist/blocks/analysis-tree.js.map +1 -0
- package/dist/blocks/decisions-list.d.ts +17 -0
- package/dist/blocks/decisions-list.d.ts.map +1 -0
- package/dist/blocks/decisions-list.js +56 -0
- package/dist/blocks/decisions-list.js.map +1 -0
- package/dist/blocks/findings-list.d.ts +9 -0
- package/dist/blocks/findings-list.d.ts.map +1 -0
- package/dist/blocks/findings-list.js +35 -0
- package/dist/blocks/findings-list.js.map +1 -0
- package/dist/blocks/index.d.ts +18 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/blocks/index.js +10 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/inputs-list.d.ts +9 -0
- package/dist/blocks/inputs-list.d.ts.map +1 -0
- package/dist/blocks/inputs-list.js +32 -0
- package/dist/blocks/inputs-list.js.map +1 -0
- package/dist/blocks/outputs-list.d.ts +18 -0
- package/dist/blocks/outputs-list.d.ts.map +1 -0
- package/dist/blocks/outputs-list.js +47 -0
- package/dist/blocks/outputs-list.js.map +1 -0
- package/dist/blocks/papers-list.d.ts +16 -0
- package/dist/blocks/papers-list.d.ts.map +1 -0
- package/dist/blocks/papers-list.js +20 -0
- package/dist/blocks/papers-list.js.map +1 -0
- package/dist/blocks/prior-insights-list.d.ts +9 -0
- package/dist/blocks/prior-insights-list.d.ts.map +1 -0
- package/dist/blocks/prior-insights-list.js +29 -0
- package/dist/blocks/prior-insights-list.js.map +1 -0
- package/dist/blocks/section.d.ts +36 -0
- package/dist/blocks/section.d.ts.map +1 -0
- package/dist/blocks/section.js +30 -0
- package/dist/blocks/section.js.map +1 -0
- package/dist/components/artifact-preview.d.ts +71 -0
- package/dist/components/artifact-preview.d.ts.map +1 -0
- package/dist/components/artifact-preview.js +170 -0
- package/dist/components/artifact-preview.js.map +1 -0
- package/dist/components/decision-detail.d.ts +17 -0
- package/dist/components/decision-detail.d.ts.map +1 -0
- package/dist/components/decision-detail.js +21 -0
- package/dist/components/decision-detail.js.map +1 -0
- package/dist/components/detail-entry.d.ts +15 -0
- package/dist/components/detail-entry.d.ts.map +1 -0
- package/dist/components/detail-entry.js +14 -0
- package/dist/components/detail-entry.js.map +1 -0
- package/dist/components/finding-detail.d.ts +19 -0
- package/dist/components/finding-detail.d.ts.map +1 -0
- package/dist/components/finding-detail.js +39 -0
- package/dist/components/finding-detail.js.map +1 -0
- package/dist/components/index.d.ts +28 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +15 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/input-detail.d.ts +15 -0
- package/dist/components/input-detail.d.ts.map +1 -0
- package/dist/components/input-detail.js +21 -0
- package/dist/components/input-detail.js.map +1 -0
- package/dist/components/insight-detail.d.ts +25 -0
- package/dist/components/insight-detail.d.ts.map +1 -0
- package/dist/components/insight-detail.js +30 -0
- package/dist/components/insight-detail.js.map +1 -0
- package/dist/components/insight-trigger.d.ts +20 -0
- package/dist/components/insight-trigger.d.ts.map +1 -0
- package/dist/components/insight-trigger.js +32 -0
- package/dist/components/insight-trigger.js.map +1 -0
- package/dist/components/output-detail.d.ts +39 -0
- package/dist/components/output-detail.d.ts.map +1 -0
- package/dist/components/output-detail.js +124 -0
- package/dist/components/output-detail.js.map +1 -0
- package/dist/components/output-dialog.d.ts +18 -0
- package/dist/components/output-dialog.d.ts.map +1 -0
- package/dist/components/output-dialog.js +11 -0
- package/dist/components/output-dialog.js.map +1 -0
- package/dist/components/paper-detail.d.ts +34 -0
- package/dist/components/paper-detail.d.ts.map +1 -0
- package/dist/components/paper-detail.js +60 -0
- package/dist/components/paper-detail.js.map +1 -0
- package/dist/components/record-dialog.d.ts +33 -0
- package/dist/components/record-dialog.d.ts.map +1 -0
- package/dist/components/record-dialog.js +114 -0
- package/dist/components/record-dialog.js.map +1 -0
- package/dist/components/relation-items.d.ts +9 -0
- package/dist/components/relation-items.d.ts.map +1 -0
- package/dist/components/relation-items.js +20 -0
- package/dist/components/relation-items.js.map +1 -0
- package/dist/components/use-detail-stack.d.ts +31 -0
- package/dist/components/use-detail-stack.d.ts.map +1 -0
- package/dist/components/use-detail-stack.js +49 -0
- package/dist/components/use-detail-stack.js.map +1 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/cn.d.ts.map +1 -0
- package/dist/lib/cn.js +6 -0
- package/dist/lib/cn.js.map +1 -0
- package/dist/lib/labels.d.ts +61 -0
- package/dist/lib/labels.d.ts.map +1 -0
- package/dist/lib/labels.js +79 -0
- package/dist/lib/labels.js.map +1 -0
- package/dist/lib/slot.d.ts +11 -0
- package/dist/lib/slot.d.ts.map +1 -0
- package/dist/lib/slot.js +83 -0
- package/dist/lib/slot.js.map +1 -0
- package/dist/model/doi.d.ts +2 -0
- package/dist/model/doi.d.ts.map +1 -0
- package/dist/model/doi.js +5 -0
- package/dist/model/doi.js.map +1 -0
- package/dist/model/index.d.ts +10 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +7 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/locate-record.d.ts +8 -0
- package/dist/model/locate-record.d.ts.map +1 -0
- package/dist/model/locate-record.js +7 -0
- package/dist/model/locate-record.js.map +1 -0
- package/dist/model/papers.d.ts +38 -0
- package/dist/model/papers.d.ts.map +1 -0
- package/dist/model/papers.js +91 -0
- package/dist/model/papers.js.map +1 -0
- package/dist/model/records.d.ts +10 -0
- package/dist/model/records.d.ts.map +1 -0
- package/dist/model/records.js +32 -0
- package/dist/model/records.js.map +1 -0
- package/dist/model/relations.d.ts +45 -0
- package/dist/model/relations.d.ts.map +1 -0
- package/dist/model/relations.js +98 -0
- package/dist/model/relations.js.map +1 -0
- package/dist/primitives/badge.d.ts +11 -0
- package/dist/primitives/badge.d.ts.map +1 -0
- package/dist/primitives/badge.js +7 -0
- package/dist/primitives/badge.js.map +1 -0
- package/dist/primitives/button.d.ts +18 -0
- package/dist/primitives/button.d.ts.map +1 -0
- package/dist/primitives/button.js +12 -0
- package/dist/primitives/button.js.map +1 -0
- package/dist/primitives/detail-layout.d.ts +26 -0
- package/dist/primitives/detail-layout.d.ts.map +1 -0
- package/dist/primitives/detail-layout.js +21 -0
- package/dist/primitives/detail-layout.js.map +1 -0
- package/dist/primitives/dialog.d.ts +133 -0
- package/dist/primitives/dialog.d.ts.map +1 -0
- package/dist/primitives/dialog.js +266 -0
- package/dist/primitives/dialog.js.map +1 -0
- package/dist/primitives/index.d.ts +25 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +14 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/kind.d.ts +6 -0
- package/dist/primitives/kind.d.ts.map +1 -0
- package/dist/primitives/kind.js +14 -0
- package/dist/primitives/kind.js.map +1 -0
- package/dist/primitives/prose.d.ts +36 -0
- package/dist/primitives/prose.d.ts.map +1 -0
- package/dist/primitives/prose.js +57 -0
- package/dist/primitives/prose.js.map +1 -0
- package/dist/primitives/record-list.d.ts +31 -0
- package/dist/primitives/record-list.d.ts.map +1 -0
- package/dist/primitives/record-list.js +17 -0
- package/dist/primitives/record-list.js.map +1 -0
- package/dist/primitives/relation-list.d.ts +22 -0
- package/dist/primitives/relation-list.d.ts.map +1 -0
- package/dist/primitives/relation-list.js +13 -0
- package/dist/primitives/relation-list.js.map +1 -0
- package/dist/primitives/surface-header.d.ts +31 -0
- package/dist/primitives/surface-header.d.ts.map +1 -0
- package/dist/primitives/surface-header.js +13 -0
- package/dist/primitives/surface-header.js.map +1 -0
- package/dist/views/index.d.ts +4 -0
- package/dist/views/index.d.ts.map +1 -0
- package/dist/views/index.js +3 -0
- package/dist/views/index.js.map +1 -0
- package/dist/views/inventory.d.ts +46 -0
- package/dist/views/inventory.d.ts.map +1 -0
- package/dist/views/inventory.js +101 -0
- package/dist/views/inventory.js.map +1 -0
- package/package.json +127 -0
- package/primitives.css +15 -0
- package/src/blocks/analysis-tree.tsx +109 -0
- package/src/blocks/decisions-list.tsx +113 -0
- package/src/blocks/findings-list.tsx +61 -0
- package/src/blocks/index.ts +23 -0
- package/src/blocks/inputs-list.tsx +51 -0
- package/src/blocks/outputs-list.tsx +143 -0
- package/src/blocks/papers-list.tsx +65 -0
- package/src/blocks/prior-insights-list.tsx +52 -0
- package/src/blocks/section.tsx +113 -0
- package/src/components/artifact-preview.tsx +314 -0
- package/src/components/decision-detail.tsx +93 -0
- package/src/components/detail-entry.ts +19 -0
- package/src/components/finding-detail.tsx +99 -0
- package/src/components/index.ts +44 -0
- package/src/components/input-detail.tsx +67 -0
- package/src/components/insight-detail.tsx +120 -0
- package/src/components/insight-trigger.tsx +102 -0
- package/src/components/output-detail.tsx +258 -0
- package/src/components/output-dialog.tsx +63 -0
- package/src/components/paper-detail.tsx +216 -0
- package/src/components/record-dialog.tsx +232 -0
- package/src/components/relation-items.ts +31 -0
- package/src/components/use-detail-stack.ts +78 -0
- package/src/lib/cn.ts +5 -0
- package/src/lib/labels.tsx +145 -0
- package/src/lib/slot.tsx +87 -0
- package/src/model/doi.ts +5 -0
- package/src/model/index.ts +32 -0
- package/src/model/locate-record.ts +13 -0
- package/src/model/papers.ts +146 -0
- package/src/model/records.ts +43 -0
- package/src/model/relations.ts +134 -0
- package/src/primitives/badge.tsx +32 -0
- package/src/primitives/button.tsx +58 -0
- package/src/primitives/detail-layout.tsx +84 -0
- package/src/primitives/dialog.tsx +555 -0
- package/src/primitives/index.ts +48 -0
- package/src/primitives/kind.ts +19 -0
- package/src/primitives/prose.tsx +74 -0
- package/src/primitives/record-list.tsx +103 -0
- package/src/primitives/relation-list.tsx +95 -0
- package/src/primitives/surface-header.tsx +87 -0
- package/src/views/index.ts +3 -0
- package/src/views/inventory.tsx +224 -0
- package/styles/base.css +49 -0
- package/styles/blocks/analysis-tree.css +64 -0
- package/styles/blocks/decisions-list.css +73 -0
- package/styles/blocks/outputs-list.css +349 -0
- package/styles/blocks/papers-list.css +98 -0
- package/styles/blocks/records.css +72 -0
- package/styles/components/artifact-preview.css +242 -0
- package/styles/components/decision-detail.css +159 -0
- package/styles/components/evidence.css +79 -0
- package/styles/components/finding-detail.css +63 -0
- package/styles/components/input-detail.css +95 -0
- package/styles/components/insight-detail.css +138 -0
- package/styles/components/insight-list.css +46 -0
- package/styles/components/insight-trigger.css +54 -0
- package/styles/components/output-detail.css +732 -0
- package/styles/components/paper-detail.css +249 -0
- package/styles/components/paper-doi.css +36 -0
- package/styles/primitives/badge.css +107 -0
- package/styles/primitives/button.css +116 -0
- package/styles/primitives/count-heading.css +27 -0
- package/styles/primitives/detail-layout.css +225 -0
- package/styles/primitives/dialog.css +634 -0
- package/styles/primitives/empty-state.css +10 -0
- package/styles/primitives/kind.css +41 -0
- package/styles/primitives/prose.css +15 -0
- package/styles/primitives/record-list.css +425 -0
- package/styles/primitives/relation-list.css +184 -0
- package/styles/primitives/surface-header.css +183 -0
- package/styles/tokens.css +119 -0
- package/styles/views/inventory.css +186 -0
- package/styles.css +2 -0
- package/views.css +3 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { ResolvedDecision, ResolvedInsight } from '@astra-spec/sdk';
|
|
2
|
+
import { forwardRef, useCallback, useMemo, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';
|
|
3
|
+
import { doiHref } from '../model/doi.js';
|
|
4
|
+
import { countLabel } from '../model/records.js';
|
|
5
|
+
import { paperEvidence, type InventoryPaper, type InventoryPaperMetadata, type PaperFocusEvidence } from '../model/papers.js';
|
|
6
|
+
import { cn } from '../lib/cn.js';
|
|
7
|
+
import { useLabels } from '../lib/labels.js';
|
|
8
|
+
import { CountHeading } from '../primitives/detail-layout.js';
|
|
9
|
+
import { DetailDialog, DialogAction, type DetailDialogProps } from '../primitives/dialog.js';
|
|
10
|
+
import { Prose, type TextRenderer } from '../primitives/prose.js';
|
|
11
|
+
import { RelationList } from '../primitives/relation-list.js';
|
|
12
|
+
import { InsightTrigger } from './insight-trigger.js';
|
|
13
|
+
import { relationItemForRecord } from './relation-items.js';
|
|
14
|
+
|
|
15
|
+
export interface PaperRenderOptions {
|
|
16
|
+
focusEvidence?: PaperFocusEvidence | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Host slot for PDF, HTML, or any other paper presentation. */
|
|
20
|
+
export type PaperRenderer = (paper: InventoryPaper, options: PaperRenderOptions) => ReactNode;
|
|
21
|
+
|
|
22
|
+
export interface PaperDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
23
|
+
record: InventoryPaper;
|
|
24
|
+
/** Fetch state for this DOI, if the host tracks it. */
|
|
25
|
+
metadata?: Pick<InventoryPaperMetadata, 'status' | 'error'> | undefined;
|
|
26
|
+
/** Insight whose first quoted passage is focused initially. */
|
|
27
|
+
focusInsight?: ResolvedInsight | undefined;
|
|
28
|
+
renderText?: TextRenderer | undefined;
|
|
29
|
+
renderPaper?: PaperRenderer | undefined;
|
|
30
|
+
/** Notify the host to fetch this DOI; refreshed metadata returns through props. */
|
|
31
|
+
onFetchPaper?: ((doi: string) => void) | undefined;
|
|
32
|
+
onOpenInsight?: ((insight: ResolvedInsight) => void) | undefined;
|
|
33
|
+
onOpenDecision?: ((decision: ResolvedDecision) => void) | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function initialFocus(paper: InventoryPaper, focusInsight: ResolvedInsight | undefined): PaperFocusEvidence | undefined {
|
|
37
|
+
if (!focusInsight) return undefined;
|
|
38
|
+
const evidence = paperEvidence(focusInsight, paper.doi)[0];
|
|
39
|
+
return evidence?.quote ? { key: `${focusInsight.canonicalPath}-source`, insight: focusInsight, evidence } : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Host-rendered paper content beside the insights and decisions it supports. */
|
|
43
|
+
export const PaperDetail = forwardRef<HTMLDivElement, PaperDetailProps>(function PaperDetail({
|
|
44
|
+
record: paper,
|
|
45
|
+
metadata,
|
|
46
|
+
focusInsight,
|
|
47
|
+
renderText,
|
|
48
|
+
renderPaper,
|
|
49
|
+
onFetchPaper,
|
|
50
|
+
onOpenInsight,
|
|
51
|
+
onOpenDecision,
|
|
52
|
+
className,
|
|
53
|
+
...props
|
|
54
|
+
}, ref) {
|
|
55
|
+
const labels = useLabels();
|
|
56
|
+
const [focusKey, setFocusKey] = useState<string | undefined>(undefined);
|
|
57
|
+
const [override, setOverride] = useState<PaperFocusEvidence | undefined>(undefined);
|
|
58
|
+
const key = `${paper.doi}|${focusInsight?.canonicalPath ?? ''}`;
|
|
59
|
+
if (focusKey !== key) {
|
|
60
|
+
setFocusKey(key);
|
|
61
|
+
setOverride(undefined);
|
|
62
|
+
}
|
|
63
|
+
// One object per request, kept across unrelated re-renders, with a key
|
|
64
|
+
// that changes on every locate click so a repeat of the same passage is
|
|
65
|
+
// still a new request to the host.
|
|
66
|
+
const focusEvidence = useMemo(() => override ?? initialFocus(paper, focusInsight), [override, paper, focusInsight]);
|
|
67
|
+
const sequence = useRef(0);
|
|
68
|
+
const locate = useCallback((insight: ResolvedInsight, evidence: PaperFocusEvidence['evidence']) => {
|
|
69
|
+
sequence.current += 1;
|
|
70
|
+
setOverride({ key: `${insight.canonicalPath}-${sequence.current}`, insight, evidence });
|
|
71
|
+
}, []);
|
|
72
|
+
const canRender = Boolean(paper.pdfUrl && renderPaper);
|
|
73
|
+
const fetching = metadata?.status === 'fetching';
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div data-slot="paper-detail" {...props} ref={ref} className={cn('astra-paper-detail__layout', className)}>
|
|
77
|
+
<div className="astra-paper-detail__artifact">
|
|
78
|
+
{canRender && renderPaper ? (
|
|
79
|
+
<>{renderPaper(paper, { focusEvidence })}</>
|
|
80
|
+
) : (
|
|
81
|
+
<div className="astra-paper-detail__unavailable" {...(fetching ? { 'aria-busy': true } : {})}>
|
|
82
|
+
{!paper.pdfUrl && onFetchPaper ? (
|
|
83
|
+
<>
|
|
84
|
+
<p {...(metadata?.status === 'error' ? { role: 'alert' } : {})}>
|
|
85
|
+
{metadata?.status === 'error'
|
|
86
|
+
? (metadata.error ?? 'The paper could not be fetched.')
|
|
87
|
+
: 'No paper content is available from this host.'}
|
|
88
|
+
</p>
|
|
89
|
+
<button type="button" disabled={fetching} onClick={() => { onFetchPaper(paper.doi); }}>
|
|
90
|
+
{labels.actions.fetchPaper}
|
|
91
|
+
</button>
|
|
92
|
+
</>
|
|
93
|
+
) : (
|
|
94
|
+
<p>
|
|
95
|
+
{paper.pdfUrl
|
|
96
|
+
? 'This host has not supplied an embedded paper renderer.'
|
|
97
|
+
: 'Follow the DOI for the published version.'}
|
|
98
|
+
</p>
|
|
99
|
+
)}
|
|
100
|
+
</div>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
<aside className="astra-paper-detail__rail" aria-label="Paper insights and decisions">
|
|
104
|
+
<section className="astra-paper-doi">
|
|
105
|
+
<h4>DOI</h4>
|
|
106
|
+
<a href={doiHref(paper.doi)} target="_blank" rel="noreferrer">
|
|
107
|
+
{paper.doi} ↗
|
|
108
|
+
</a>
|
|
109
|
+
</section>
|
|
110
|
+
<section className="astra-insight-list">
|
|
111
|
+
<CountHeading title="Insights from this paper" count={paper.insights.length} />
|
|
112
|
+
<ul className="astra-evidence astra-paper-detail__insights">
|
|
113
|
+
{paper.insights.map((insight) => {
|
|
114
|
+
const evidence = paperEvidence(insight, paper.doi);
|
|
115
|
+
return (
|
|
116
|
+
<li key={insight.canonicalPath} className="astra-evidence__item astra-paper-insight">
|
|
117
|
+
<InsightTrigger insight={insight} tag={null} onOpen={() => onOpenInsight?.(insight)} />
|
|
118
|
+
<div className="astra-paper-insight__claim">
|
|
119
|
+
<Prose text={insight.claim} field="claim" renderText={renderText} />
|
|
120
|
+
</div>
|
|
121
|
+
{evidence.length ? (
|
|
122
|
+
<div className="astra-paper-insight__sources">
|
|
123
|
+
<span>{countLabel(evidence.length, 'passage')}</span>
|
|
124
|
+
{canRender ? (
|
|
125
|
+
<div>
|
|
126
|
+
{evidence.map((source, index) => (
|
|
127
|
+
<button
|
|
128
|
+
key={`${insight.canonicalPath}-${index}`}
|
|
129
|
+
type="button"
|
|
130
|
+
className="astra-paper-insight__locate"
|
|
131
|
+
onClick={() => { locate(insight, source); }}
|
|
132
|
+
aria-label={`Locate source passage ${index + 1} in paper`}
|
|
133
|
+
>
|
|
134
|
+
{labels.actions.locate}{evidence.length > 1 ? ` ${index + 1}` : ''}
|
|
135
|
+
</button>
|
|
136
|
+
))}
|
|
137
|
+
</div>
|
|
138
|
+
) : null}
|
|
139
|
+
</div>
|
|
140
|
+
) : null}
|
|
141
|
+
</li>
|
|
142
|
+
);
|
|
143
|
+
})}
|
|
144
|
+
</ul>
|
|
145
|
+
</section>
|
|
146
|
+
<RelationList
|
|
147
|
+
className="astra-detail__relations"
|
|
148
|
+
title="Informs decisions"
|
|
149
|
+
items={paper.decisions.map((decision) => relationItemForRecord(
|
|
150
|
+
decision,
|
|
151
|
+
undefined,
|
|
152
|
+
undefined,
|
|
153
|
+
{ onOpen: onOpenDecision ? () => { onOpenDecision(decision); } : undefined },
|
|
154
|
+
))}
|
|
155
|
+
empty="No decisions cite insights from this paper."
|
|
156
|
+
/>
|
|
157
|
+
</aside>
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
export interface PaperDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'>, Omit<PaperDetailProps, 'className'> {}
|
|
163
|
+
|
|
164
|
+
/** Header action linking to the paper's hosted content, when there is one. */
|
|
165
|
+
export interface PaperDialogActionsProps {
|
|
166
|
+
record: InventoryPaper;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function PaperDialogActions({ record: paper }: PaperDialogActionsProps) {
|
|
170
|
+
const labels = useLabels();
|
|
171
|
+
if (!paper.pdfUrl) return null;
|
|
172
|
+
return (
|
|
173
|
+
<DialogAction asChild>
|
|
174
|
+
<a href={paper.pdfUrl} target="_blank" rel="noreferrer">
|
|
175
|
+
<span aria-hidden="true">↗</span>
|
|
176
|
+
<span>{labels.actions.openPaper}</span>
|
|
177
|
+
</a>
|
|
178
|
+
</DialogAction>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function PaperDialog({
|
|
183
|
+
record: paper,
|
|
184
|
+
metadata,
|
|
185
|
+
focusInsight,
|
|
186
|
+
renderText,
|
|
187
|
+
renderPaper,
|
|
188
|
+
onFetchPaper,
|
|
189
|
+
onOpenInsight,
|
|
190
|
+
onOpenDecision,
|
|
191
|
+
...dialog
|
|
192
|
+
}: PaperDialogProps) {
|
|
193
|
+
const labels = useLabels();
|
|
194
|
+
return (
|
|
195
|
+
<DetailDialog
|
|
196
|
+
{...dialog}
|
|
197
|
+
kind="paper"
|
|
198
|
+
layout="reader"
|
|
199
|
+
kindLabel={labels.kinds.paper}
|
|
200
|
+
title={paper.title}
|
|
201
|
+
closeLabel={labels.closeRecord(labels.kinds.paper)}
|
|
202
|
+
actions={<PaperDialogActions record={paper} />}
|
|
203
|
+
>
|
|
204
|
+
<PaperDetail
|
|
205
|
+
record={paper}
|
|
206
|
+
metadata={metadata}
|
|
207
|
+
focusInsight={focusInsight}
|
|
208
|
+
renderText={renderText}
|
|
209
|
+
renderPaper={renderPaper}
|
|
210
|
+
onFetchPaper={onFetchPaper}
|
|
211
|
+
onOpenInsight={onOpenInsight}
|
|
212
|
+
onOpenDecision={onOpenDecision}
|
|
213
|
+
/>
|
|
214
|
+
</DetailDialog>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnalysisIndex,
|
|
3
|
+
ResolvedAnalysisDocument,
|
|
4
|
+
ResolvedAnalysisNode,
|
|
5
|
+
ResolvedDecision,
|
|
6
|
+
ResolvedInsight,
|
|
7
|
+
ResolvedOutput,
|
|
8
|
+
ResolvedRecord,
|
|
9
|
+
} from '@astra-spec/sdk';
|
|
10
|
+
import type { ReactNode } from 'react';
|
|
11
|
+
import { locateRecord } from '../model/locate-record.js';
|
|
12
|
+
import { findPaper, paperForDoi, paperMetadataFor, type InventoryPaper, type InventoryPaperMetadataMap } from '../model/papers.js';
|
|
13
|
+
import { isInsight, isVisualOutput, recordTitle } from '../model/records.js';
|
|
14
|
+
import { decisionInsights, findingEvidence, informedDecisions, outputRelations } from '../model/relations.js';
|
|
15
|
+
import { useLabels } from '../lib/labels.js';
|
|
16
|
+
import type { ArtifactRenderer } from './artifact-preview.js';
|
|
17
|
+
import { DetailDialog, type DetailDialogProps, type DialogLayout } from '../primitives/dialog.js';
|
|
18
|
+
import type { SurfaceKind } from '../primitives/kind.js';
|
|
19
|
+
import type { TextRenderer } from '../primitives/prose.js';
|
|
20
|
+
import { DecisionDetail } from './decision-detail.js';
|
|
21
|
+
import type { DetailEntry } from './detail-entry.js';
|
|
22
|
+
import { FindingDetail } from './finding-detail.js';
|
|
23
|
+
import { InputDetail } from './input-detail.js';
|
|
24
|
+
import { InsightDetail, primaryLiteratureEvidence } from './insight-detail.js';
|
|
25
|
+
import { OutputDetail, OutputDialogActions, useOutputExpanded } from './output-detail.js';
|
|
26
|
+
import { PaperDetail, PaperDialogActions, type PaperRenderer } from './paper-detail.js';
|
|
27
|
+
|
|
28
|
+
export interface RecordDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'> {
|
|
29
|
+
entry: DetailEntry;
|
|
30
|
+
document: ResolvedAnalysisDocument;
|
|
31
|
+
index: AnalysisIndex;
|
|
32
|
+
/** Papers in scope, from `collectInventoryPapers()`; needed for paper entries and insight sources. */
|
|
33
|
+
papers?: readonly InventoryPaper[] | undefined;
|
|
34
|
+
paperMetadata?: InventoryPaperMetadataMap | undefined;
|
|
35
|
+
renderArtifact?: ArtifactRenderer | undefined;
|
|
36
|
+
renderText?: TextRenderer | undefined;
|
|
37
|
+
renderPaper?: PaperRenderer | undefined;
|
|
38
|
+
onOpenArtifact?: ((output: ResolvedOutput) => void | Promise<void>) | undefined;
|
|
39
|
+
onFetchPaper?: ((doi: string) => void) | undefined;
|
|
40
|
+
/** Navigation to another record from within the detail (drill-down). */
|
|
41
|
+
onOpenRecord?: ((record: ResolvedRecord, analysis: ResolvedAnalysisNode) => void) | undefined;
|
|
42
|
+
onOpenPaper?: ((doi: string, analysis: ResolvedAnalysisNode, focusInsightPath?: string) => void) | undefined;
|
|
43
|
+
/** Body rendered (inside the dialog shell) when the entry no longer resolves, e.g. after a document refresh; nothing renders without it. */
|
|
44
|
+
fallback?: ReactNode | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Chrome {
|
|
48
|
+
kind: SurfaceKind;
|
|
49
|
+
kindLabel: ReactNode;
|
|
50
|
+
title: ReactNode;
|
|
51
|
+
layout?: DialogLayout | undefined;
|
|
52
|
+
actions?: ReactNode | undefined;
|
|
53
|
+
body: ReactNode;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Renders the right detail dialog for a stack entry, deriving relations,
|
|
58
|
+
* evidence, insights, and papers from the index. One persistent dialog
|
|
59
|
+
* element hosts every kind, so drilling down keeps focus and the top layer.
|
|
60
|
+
*/
|
|
61
|
+
export function RecordDialog({
|
|
62
|
+
entry,
|
|
63
|
+
document,
|
|
64
|
+
index,
|
|
65
|
+
papers = [],
|
|
66
|
+
paperMetadata = {},
|
|
67
|
+
renderArtifact,
|
|
68
|
+
renderText,
|
|
69
|
+
renderPaper,
|
|
70
|
+
onOpenArtifact,
|
|
71
|
+
onFetchPaper,
|
|
72
|
+
onOpenRecord,
|
|
73
|
+
onOpenPaper,
|
|
74
|
+
fallback = null,
|
|
75
|
+
...dialog
|
|
76
|
+
}: RecordDialogProps) {
|
|
77
|
+
const labels = useLabels();
|
|
78
|
+
const analysis = index.analysisByPath.get(entry.analysisPath);
|
|
79
|
+
const located = entry.kind === 'record' ? locateRecord(index, entry.canonicalPath) : undefined;
|
|
80
|
+
// Papers are looked up in the host's list first, then derived for the
|
|
81
|
+
// entry's own analysis: a record reached by drill-down may cite a paper the
|
|
82
|
+
// viewed analysis does not list.
|
|
83
|
+
const paper = entry.kind === 'paper' && analysis
|
|
84
|
+
? findPaper(papers, entry.doi) ?? paperForDoi(document, index, analysis, entry.doi, paperMetadata)
|
|
85
|
+
: undefined;
|
|
86
|
+
const output = located?.record.kind === 'output' ? located.record : undefined;
|
|
87
|
+
const [expanded, setExpanded] = useOutputExpanded(output ?? PLACEHOLDER_OUTPUT);
|
|
88
|
+
|
|
89
|
+
const openByPath = (canonicalPath: string) => {
|
|
90
|
+
const target = locateRecord(index, canonicalPath);
|
|
91
|
+
if (target) onOpenRecord?.(target.record, target.analysis);
|
|
92
|
+
};
|
|
93
|
+
const openInsight = (insight: ResolvedInsight) => { openByPath(insight.canonicalPath); };
|
|
94
|
+
const openDecision = (decision: ResolvedDecision) => { openByPath(decision.canonicalPath); };
|
|
95
|
+
|
|
96
|
+
let chrome: Chrome | undefined;
|
|
97
|
+
if (entry.kind === 'paper' && paper && analysis) {
|
|
98
|
+
const focusRecord = entry.focusInsightPath ? index.recordByPath.get(entry.focusInsightPath) : undefined;
|
|
99
|
+
chrome = {
|
|
100
|
+
kind: 'paper',
|
|
101
|
+
kindLabel: labels.kinds.paper,
|
|
102
|
+
title: paper.title,
|
|
103
|
+
layout: 'reader',
|
|
104
|
+
actions: <PaperDialogActions record={paper} />,
|
|
105
|
+
body: (
|
|
106
|
+
<PaperDetail
|
|
107
|
+
record={paper}
|
|
108
|
+
metadata={paperMetadataFor(paper.doi, paperMetadata)}
|
|
109
|
+
focusInsight={isInsight(focusRecord) ? focusRecord : undefined}
|
|
110
|
+
renderText={renderText}
|
|
111
|
+
renderPaper={renderPaper}
|
|
112
|
+
onFetchPaper={onFetchPaper}
|
|
113
|
+
onOpenInsight={openInsight}
|
|
114
|
+
onOpenDecision={openDecision}
|
|
115
|
+
/>
|
|
116
|
+
),
|
|
117
|
+
};
|
|
118
|
+
} else if (located && analysis) {
|
|
119
|
+
const { record } = located;
|
|
120
|
+
switch (record.kind) {
|
|
121
|
+
case 'output':
|
|
122
|
+
chrome = {
|
|
123
|
+
kind: 'output',
|
|
124
|
+
kindLabel: record.type,
|
|
125
|
+
title: recordTitle(record),
|
|
126
|
+
layout: isVisualOutput(record) ? 'reader' : undefined,
|
|
127
|
+
actions: (
|
|
128
|
+
<OutputDialogActions record={record} onOpenArtifact={onOpenArtifact} expanded={expanded} onExpandedChange={setExpanded} />
|
|
129
|
+
),
|
|
130
|
+
body: (
|
|
131
|
+
<OutputDetail
|
|
132
|
+
record={record}
|
|
133
|
+
relations={outputRelations(index, record)}
|
|
134
|
+
renderArtifact={renderArtifact}
|
|
135
|
+
renderText={renderText}
|
|
136
|
+
onOpenRecord={onOpenRecord}
|
|
137
|
+
expanded={expanded}
|
|
138
|
+
onExpandedChange={setExpanded}
|
|
139
|
+
/>
|
|
140
|
+
),
|
|
141
|
+
};
|
|
142
|
+
break;
|
|
143
|
+
case 'input':
|
|
144
|
+
chrome = {
|
|
145
|
+
kind: 'input',
|
|
146
|
+
kindLabel: labels.kinds.input,
|
|
147
|
+
title: recordTitle(record),
|
|
148
|
+
body: <InputDetail record={record} renderText={renderText} />,
|
|
149
|
+
};
|
|
150
|
+
break;
|
|
151
|
+
case 'decision':
|
|
152
|
+
chrome = {
|
|
153
|
+
kind: 'decision',
|
|
154
|
+
kindLabel: labels.kinds.decision,
|
|
155
|
+
title: recordTitle(record),
|
|
156
|
+
body: (
|
|
157
|
+
<DecisionDetail
|
|
158
|
+
record={record}
|
|
159
|
+
insights={decisionInsights(index, record)}
|
|
160
|
+
renderText={renderText}
|
|
161
|
+
onOpenInsight={openInsight}
|
|
162
|
+
/>
|
|
163
|
+
),
|
|
164
|
+
};
|
|
165
|
+
break;
|
|
166
|
+
case 'finding':
|
|
167
|
+
chrome = {
|
|
168
|
+
kind: 'finding',
|
|
169
|
+
kindLabel: labels.kinds.finding,
|
|
170
|
+
title: record.claim,
|
|
171
|
+
body: (
|
|
172
|
+
<FindingDetail
|
|
173
|
+
record={record}
|
|
174
|
+
evidence={findingEvidence(index, record)}
|
|
175
|
+
renderText={renderText}
|
|
176
|
+
onOpenRecord={onOpenRecord}
|
|
177
|
+
/>
|
|
178
|
+
),
|
|
179
|
+
};
|
|
180
|
+
break;
|
|
181
|
+
case 'prior_insight': {
|
|
182
|
+
// The same rule InsightDetail displays by, so the passage it shows
|
|
183
|
+
// and the paper this opens come from one evidence entry.
|
|
184
|
+
const sourceDoi = primaryLiteratureEvidence(record)?.doi;
|
|
185
|
+
const sourcePaper = sourceDoi
|
|
186
|
+
? findPaper(papers, sourceDoi) ?? paperForDoi(document, index, located.analysis, sourceDoi, paperMetadata)
|
|
187
|
+
: undefined;
|
|
188
|
+
chrome = {
|
|
189
|
+
kind: 'prior_insight',
|
|
190
|
+
kindLabel: labels.kinds.prior_insight,
|
|
191
|
+
title: recordTitle(record),
|
|
192
|
+
body: (
|
|
193
|
+
<InsightDetail
|
|
194
|
+
record={record}
|
|
195
|
+
decisions={informedDecisions(document, record)}
|
|
196
|
+
renderText={renderText}
|
|
197
|
+
onOpenSource={sourcePaper && onOpenPaper
|
|
198
|
+
? () => { onOpenPaper(sourcePaper.doi, analysis, record.canonicalPath); }
|
|
199
|
+
: undefined}
|
|
200
|
+
onOpenDecision={openDecision}
|
|
201
|
+
/>
|
|
202
|
+
),
|
|
203
|
+
};
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!chrome) {
|
|
210
|
+
if (fallback == null) return null;
|
|
211
|
+
return (
|
|
212
|
+
<DetailDialog {...dialog} kind="analysis" title={labels.notFound} closeLabel={labels.close}>
|
|
213
|
+
{fallback}
|
|
214
|
+
</DetailDialog>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return (
|
|
218
|
+
<DetailDialog
|
|
219
|
+
{...dialog}
|
|
220
|
+
kind={chrome.kind}
|
|
221
|
+
layout={chrome.layout}
|
|
222
|
+
kindLabel={chrome.kindLabel}
|
|
223
|
+
title={chrome.title}
|
|
224
|
+
closeLabel={labels.closeRecord(labels.kinds[chrome.kind])}
|
|
225
|
+
actions={chrome.actions}
|
|
226
|
+
>
|
|
227
|
+
{chrome.body}
|
|
228
|
+
</DetailDialog>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const PLACEHOLDER_OUTPUT = { canonicalPath: '' } as ResolvedOutput;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ResolvedAnalysisNode, ResolvedRecord } from '@astra-spec/sdk';
|
|
2
|
+
import type { LinkedRecord } from '../model/relations.js';
|
|
3
|
+
import { recordTitle } from '../model/records.js';
|
|
4
|
+
import type { RelationItem } from '../primitives/relation-list.js';
|
|
5
|
+
|
|
6
|
+
export type OpenRecordHandler = (record: ResolvedRecord, analysis: ResolvedAnalysisNode) => void;
|
|
7
|
+
|
|
8
|
+
/** Builds a relation-list item for a record, with navigation when the caller handles it. */
|
|
9
|
+
export function relationItemForRecord(
|
|
10
|
+
record: ResolvedRecord,
|
|
11
|
+
analysis: ResolvedAnalysisNode | undefined,
|
|
12
|
+
onOpen: OpenRecordHandler | undefined,
|
|
13
|
+
overrides: Partial<RelationItem> = {},
|
|
14
|
+
): RelationItem {
|
|
15
|
+
const title = recordTitle(record);
|
|
16
|
+
return {
|
|
17
|
+
key: record.canonicalPath,
|
|
18
|
+
label: title,
|
|
19
|
+
kind: record.kind,
|
|
20
|
+
accessibleLabel: `View ${record.kind}: ${title}`,
|
|
21
|
+
onOpen: analysis && onOpen ? () => { onOpen(record, analysis); } : undefined,
|
|
22
|
+
...overrides,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Builds relation-list items for linked records; unresolved links show their path. */
|
|
27
|
+
export function relationItemsForLinks(links: LinkedRecord[], onOpen: OpenRecordHandler | undefined): RelationItem[] {
|
|
28
|
+
return links.map((link) => (link.record
|
|
29
|
+
? relationItemForRecord(link.record, link.analysis, onOpen, { identifier: link.canonicalPath })
|
|
30
|
+
: { key: link.canonicalPath, label: link.canonicalPath, identifier: link.canonicalPath }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { ResolvedAnalysisNode, ResolvedRecord } from '@astra-spec/sdk';
|
|
3
|
+
import { paperEntry, recordEntry, type DetailEntry } from './detail-entry.js';
|
|
4
|
+
|
|
5
|
+
export interface DetailStackOptions {
|
|
6
|
+
/** Controlled stack; pair with `onChange`. */
|
|
7
|
+
value?: readonly DetailEntry[] | undefined;
|
|
8
|
+
defaultValue?: readonly DetailEntry[] | undefined;
|
|
9
|
+
onChange?: ((next: DetailEntry[]) => void) | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface DetailStack {
|
|
13
|
+
stack: readonly DetailEntry[];
|
|
14
|
+
active: DetailEntry | undefined;
|
|
15
|
+
previous: DetailEntry | undefined;
|
|
16
|
+
/** Replaces the stack with a single entry. */
|
|
17
|
+
open: (entry: DetailEntry) => void;
|
|
18
|
+
openRecord: (record: ResolvedRecord, analysis: ResolvedAnalysisNode) => void;
|
|
19
|
+
openPaper: (doi: string, analysis: ResolvedAnalysisNode, focusInsightPath?: string) => void;
|
|
20
|
+
/** Pushes an entry on top of the current one (drill-down). */
|
|
21
|
+
push: (entry: DetailEntry) => void;
|
|
22
|
+
pushRecord: (record: ResolvedRecord, analysis: ResolvedAnalysisNode) => void;
|
|
23
|
+
pushPaper: (doi: string, analysis: ResolvedAnalysisNode, focusInsightPath?: string) => void;
|
|
24
|
+
back: () => void;
|
|
25
|
+
close: () => void;
|
|
26
|
+
set: (next: readonly DetailEntry[]) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const EMPTY: DetailEntry[] = [];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Headless navigation state for record details: a stack of entries with
|
|
33
|
+
* open/push/back/close. Works controlled (`value` + `onChange`) or
|
|
34
|
+
* uncontrolled (`defaultValue`), like a React input.
|
|
35
|
+
*/
|
|
36
|
+
export function useDetailStack({ value, defaultValue, onChange }: DetailStackOptions = {}): DetailStack {
|
|
37
|
+
const [internal, setInternal] = useState<readonly DetailEntry[]>(defaultValue ?? EMPTY);
|
|
38
|
+
const controlled = value !== undefined;
|
|
39
|
+
const stack = controlled ? value : internal;
|
|
40
|
+
const latest = useRef(stack);
|
|
41
|
+
useEffect(() => { latest.current = stack; });
|
|
42
|
+
|
|
43
|
+
const onChangeRef = useRef(onChange);
|
|
44
|
+
useEffect(() => { onChangeRef.current = onChange; });
|
|
45
|
+
|
|
46
|
+
// Uncontrolled updates read the latest stack (not the render-time one) so
|
|
47
|
+
// two calls in the same tick compose, and notify the host once per change.
|
|
48
|
+
// Controlled updates are proposals computed from the value the host last
|
|
49
|
+
// rendered; the host decides, like a controlled input.
|
|
50
|
+
const update = useCallback((compute: (current: readonly DetailEntry[]) => readonly DetailEntry[]) => {
|
|
51
|
+
const next = [...compute(latest.current)];
|
|
52
|
+
if (!controlled) {
|
|
53
|
+
latest.current = next;
|
|
54
|
+
setInternal(next);
|
|
55
|
+
}
|
|
56
|
+
onChangeRef.current?.(next);
|
|
57
|
+
}, [controlled]);
|
|
58
|
+
const set = useCallback((next: readonly DetailEntry[]) => { update(() => next); }, [update]);
|
|
59
|
+
|
|
60
|
+
return useMemo<DetailStack>(() => {
|
|
61
|
+
const open = (entry: DetailEntry) => { update(() => [entry]); };
|
|
62
|
+
const push = (entry: DetailEntry) => { update((current) => [...current, entry]); };
|
|
63
|
+
return {
|
|
64
|
+
stack,
|
|
65
|
+
active: stack.at(-1),
|
|
66
|
+
previous: stack.length > 1 ? stack.at(-2) : undefined,
|
|
67
|
+
open,
|
|
68
|
+
openRecord: (record, analysis) => { open(recordEntry(record.canonicalPath, analysis.canonicalPath)); },
|
|
69
|
+
openPaper: (doi, analysis, focusInsightPath) => { open(paperEntry(doi, analysis.canonicalPath, focusInsightPath)); },
|
|
70
|
+
push,
|
|
71
|
+
pushRecord: (record, analysis) => { push(recordEntry(record.canonicalPath, analysis.canonicalPath)); },
|
|
72
|
+
pushPaper: (doi, analysis, focusInsightPath) => { push(paperEntry(doi, analysis.canonicalPath, focusInsightPath)); },
|
|
73
|
+
back: () => { update((current) => current.slice(0, -1)); },
|
|
74
|
+
close: () => { update(() => EMPTY); },
|
|
75
|
+
set,
|
|
76
|
+
};
|
|
77
|
+
}, [stack, set, update]);
|
|
78
|
+
}
|
package/src/lib/cn.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Joins class names, skipping falsy values. astra-ui has no utility classes to dedupe, so no runtime dependency is needed. */
|
|
2
|
+
export function cn(...inputs: (string | false | null | undefined)[]): string | undefined {
|
|
3
|
+
const joined = inputs.filter(Boolean).join(' ');
|
|
4
|
+
return joined || undefined;
|
|
5
|
+
}
|