@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,120 @@
|
|
|
1
|
+
import type { ResolvedDecision, ResolvedInsight } from '@astra-spec/sdk';
|
|
2
|
+
import { forwardRef, type HTMLAttributes } from 'react';
|
|
3
|
+
import { doiHref } from '../model/doi.js';
|
|
4
|
+
import { recordTitle } from '../model/records.js';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { useLabels } from '../lib/labels.js';
|
|
7
|
+
import { DetailLayout, DetailMain, DetailSection } from '../primitives/detail-layout.js';
|
|
8
|
+
import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
|
|
9
|
+
import { Prose, type TextRenderer } from '../primitives/prose.js';
|
|
10
|
+
import { RelationList } from '../primitives/relation-list.js';
|
|
11
|
+
import { relationItemForRecord } from './relation-items.js';
|
|
12
|
+
|
|
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
|
+
export interface InsightDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
23
|
+
record: ResolvedInsight;
|
|
24
|
+
/** Decisions that cite this insight; see `informedDecisions()`. */
|
|
25
|
+
decisions: ResolvedDecision[];
|
|
26
|
+
renderText?: TextRenderer | undefined;
|
|
27
|
+
/** Opens the source paper (with this insight focused) when the host can show it. */
|
|
28
|
+
onOpenSource?: (() => void) | undefined;
|
|
29
|
+
onOpenDecision?: ((decision: ResolvedDecision) => void) | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Claim, source paper and passage, notes, and the decisions an insight informs. */
|
|
33
|
+
export const InsightDetail = forwardRef<HTMLDivElement, InsightDetailProps>(function InsightDetail({
|
|
34
|
+
record: insight,
|
|
35
|
+
decisions,
|
|
36
|
+
renderText,
|
|
37
|
+
onOpenSource,
|
|
38
|
+
onOpenDecision,
|
|
39
|
+
className,
|
|
40
|
+
...props
|
|
41
|
+
}, ref) {
|
|
42
|
+
const source = primaryLiteratureEvidence(insight);
|
|
43
|
+
const sourceLocation = source?.location?.page ? ` · page ${source.location.page}` : '';
|
|
44
|
+
return (
|
|
45
|
+
<DetailLayout data-slot="insight-detail" {...props} ref={ref} layout="single" className={cn('astra-insight-detail', className)}>
|
|
46
|
+
<DetailMain>
|
|
47
|
+
{insight.claim ? (
|
|
48
|
+
<DetailSection label="Claim" heading="section">
|
|
49
|
+
<Prose text={insight.claim} field="claim" renderText={renderText} />
|
|
50
|
+
</DetailSection>
|
|
51
|
+
) : 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
|
+
{source?.quote ? (
|
|
67
|
+
<section className="astra-insight-detail__source-quote">
|
|
68
|
+
<h4>Source passage</h4>
|
|
69
|
+
<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}
|
|
77
|
+
{insight.notes ? (
|
|
78
|
+
<section className="astra-insight-detail__notes">
|
|
79
|
+
<h4>Notes</h4>
|
|
80
|
+
<div><Prose text={insight.notes} field="notes" renderText={renderText} /></div>
|
|
81
|
+
</section>
|
|
82
|
+
) : null}
|
|
83
|
+
<RelationList
|
|
84
|
+
className="astra-detail__relations"
|
|
85
|
+
title="Informs decisions"
|
|
86
|
+
items={decisions.map((decision) => relationItemForRecord(
|
|
87
|
+
decision,
|
|
88
|
+
undefined,
|
|
89
|
+
undefined,
|
|
90
|
+
{ onOpen: onOpenDecision ? () => { onOpenDecision(decision); } : undefined },
|
|
91
|
+
))}
|
|
92
|
+
empty="No decisions cite this insight."
|
|
93
|
+
/>
|
|
94
|
+
</DetailMain>
|
|
95
|
+
</DetailLayout>
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export interface InsightDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'>, Omit<InsightDetailProps, 'className'> {}
|
|
100
|
+
|
|
101
|
+
export function InsightDialog({ record, decisions, renderText, onOpenSource, onOpenDecision, ...dialog }: InsightDialogProps) {
|
|
102
|
+
const labels = useLabels();
|
|
103
|
+
return (
|
|
104
|
+
<DetailDialog
|
|
105
|
+
{...dialog}
|
|
106
|
+
kind="prior_insight"
|
|
107
|
+
kindLabel={labels.kinds.prior_insight}
|
|
108
|
+
title={recordTitle(record)}
|
|
109
|
+
closeLabel={labels.closeRecord(labels.kinds.prior_insight)}
|
|
110
|
+
>
|
|
111
|
+
<InsightDetail
|
|
112
|
+
record={record}
|
|
113
|
+
decisions={decisions}
|
|
114
|
+
renderText={renderText}
|
|
115
|
+
onOpenSource={onOpenSource}
|
|
116
|
+
onOpenDecision={onOpenDecision}
|
|
117
|
+
/>
|
|
118
|
+
</DetailDialog>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { ResolvedInsight } from '@astra-spec/sdk';
|
|
2
|
+
import {
|
|
3
|
+
forwardRef,
|
|
4
|
+
type ButtonHTMLAttributes,
|
|
5
|
+
type HTMLAttributes,
|
|
6
|
+
type KeyboardEvent as ReactKeyboardEvent,
|
|
7
|
+
type MouseEvent as ReactMouseEvent,
|
|
8
|
+
type Ref,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { recordTitle } from '../model/records.js';
|
|
11
|
+
import { cn } from '../lib/cn.js';
|
|
12
|
+
import { Prose, type TextRenderer } from '../primitives/prose.js';
|
|
13
|
+
|
|
14
|
+
export interface InsightEvidenceTitleProps {
|
|
15
|
+
name: string;
|
|
16
|
+
tag?: string | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function InsightEvidenceTitle({ name, tag }: InsightEvidenceTitleProps) {
|
|
20
|
+
return (
|
|
21
|
+
<span className="astra-evidence__title">
|
|
22
|
+
<span className="astra-evidence__glyph--insight" aria-hidden="true">◈</span>
|
|
23
|
+
<span className="astra-evidence__name">{name}</span>
|
|
24
|
+
{tag ? <span className="astra-evidence__tag">{tag}</span> : null}
|
|
25
|
+
</span>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface InsightTriggerProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
|
|
30
|
+
insight: ResolvedInsight;
|
|
31
|
+
onOpen: () => void;
|
|
32
|
+
/** Tag shown after the name in the `title` variant; `null` hides it. */
|
|
33
|
+
tag?: string | null | undefined;
|
|
34
|
+
/** `title` shows the name; `claim` shows the full claim text. */
|
|
35
|
+
variant?: 'title' | 'claim' | undefined;
|
|
36
|
+
renderText?: TextRenderer | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A clickable reference to an insight, as a title or as its claim. */
|
|
40
|
+
export const InsightTrigger = forwardRef<HTMLElement, InsightTriggerProps>(function InsightTrigger({
|
|
41
|
+
insight,
|
|
42
|
+
onOpen,
|
|
43
|
+
tag = 'prior insight',
|
|
44
|
+
variant = 'title',
|
|
45
|
+
renderText,
|
|
46
|
+
className,
|
|
47
|
+
onClick,
|
|
48
|
+
onKeyDown,
|
|
49
|
+
...props
|
|
50
|
+
}, ref) {
|
|
51
|
+
const title = recordTitle(insight);
|
|
52
|
+
const open = (event: ReactMouseEvent<HTMLElement>) => {
|
|
53
|
+
onClick?.(event as never);
|
|
54
|
+
onOpen();
|
|
55
|
+
};
|
|
56
|
+
const keyOpen = (event: ReactKeyboardEvent<HTMLElement>) => {
|
|
57
|
+
onKeyDown?.(event as never);
|
|
58
|
+
if (event.defaultPrevented) return;
|
|
59
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
onOpen();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (variant === 'claim') {
|
|
65
|
+
// A div rather than a <button>: block prose inside a button would inherit
|
|
66
|
+
// UA control fonts and shift the layout.
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
{...(props as HTMLAttributes<HTMLDivElement>)}
|
|
70
|
+
ref={ref as Ref<HTMLDivElement>}
|
|
71
|
+
data-slot="insight-trigger"
|
|
72
|
+
className={cn('astra-insight-trigger', className)}
|
|
73
|
+
data-variant="claim"
|
|
74
|
+
role="button"
|
|
75
|
+
tabIndex={0}
|
|
76
|
+
aria-label={props['aria-label'] ?? `Open insight details: ${title}`}
|
|
77
|
+
onClick={open}
|
|
78
|
+
onKeyDown={keyOpen}
|
|
79
|
+
>
|
|
80
|
+
<span className="astra-evidence__glyph--insight" aria-hidden="true">◈</span>
|
|
81
|
+
<div className="astra-insight-trigger__claim">
|
|
82
|
+
<Prose text={insight.claim} field="claim" renderText={renderText} />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return (
|
|
88
|
+
<button
|
|
89
|
+
{...props}
|
|
90
|
+
ref={ref as Ref<HTMLButtonElement>}
|
|
91
|
+
type="button"
|
|
92
|
+
data-slot="insight-trigger"
|
|
93
|
+
className={cn('astra-insight-trigger', className)}
|
|
94
|
+
data-variant="title"
|
|
95
|
+
aria-label={props['aria-label'] ?? `Open insight details: ${title}`}
|
|
96
|
+
onClick={open}
|
|
97
|
+
onKeyDown={onKeyDown}
|
|
98
|
+
>
|
|
99
|
+
<InsightEvidenceTitle name={title} tag={tag ?? undefined} />
|
|
100
|
+
</button>
|
|
101
|
+
);
|
|
102
|
+
});
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import type { ResolvedOutput } from '@astra-spec/sdk';
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useRef, useState, type HTMLAttributes, type ReactNode } from 'react';
|
|
3
|
+
import type { OutputRelations } from '../model/relations.js';
|
|
4
|
+
import { isVisualOutput, recordTitle } from '../model/records.js';
|
|
5
|
+
import { cn } from '../lib/cn.js';
|
|
6
|
+
import { useLabels } from '../lib/labels.js';
|
|
7
|
+
import { ArtifactPreview, type ArtifactRenderer } from './artifact-preview.js';
|
|
8
|
+
import { DialogAction, useDialogDismissGuard, useOptionalDialog } from '../primitives/dialog.js';
|
|
9
|
+
import { Prose, type TextRenderer } from '../primitives/prose.js';
|
|
10
|
+
import { RelationList } from '../primitives/relation-list.js';
|
|
11
|
+
import { relationItemsForLinks, type OpenRecordHandler } from './relation-items.js';
|
|
12
|
+
|
|
13
|
+
export interface OutputPreviewProps {
|
|
14
|
+
output: ResolvedOutput;
|
|
15
|
+
compact?: boolean | undefined;
|
|
16
|
+
renderArtifact?: ArtifactRenderer | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The host's artifact renderer, or the built-in placeholder preview. */
|
|
20
|
+
export function OutputPreview({ output, compact = false, renderArtifact }: OutputPreviewProps) {
|
|
21
|
+
return renderArtifact
|
|
22
|
+
? <>{renderArtifact(output, { compact })}</>
|
|
23
|
+
: <ArtifactPreview output={output} compact={compact} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What the detail shows in its artifact box: the host's rendering when it
|
|
28
|
+
* returns one, the built-in preview for figures and tables, nothing for other
|
|
29
|
+
* output types (a data file or a metric has no picture to frame).
|
|
30
|
+
*/
|
|
31
|
+
function artifactNode(output: ResolvedOutput, renderArtifact: ArtifactRenderer | undefined): ReactNode {
|
|
32
|
+
if (renderArtifact) return renderArtifact(output, { compact: false });
|
|
33
|
+
return isVisualOutput(output) ? <ArtifactPreview output={output} compact={false} /> : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface OutputDetailProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
37
|
+
record: ResolvedOutput;
|
|
38
|
+
relations: OutputRelations;
|
|
39
|
+
renderArtifact?: ArtifactRenderer | undefined;
|
|
40
|
+
renderText?: TextRenderer | undefined;
|
|
41
|
+
onOpenRecord?: OpenRecordHandler | undefined;
|
|
42
|
+
/** Full-screen artifact state (controlled). */
|
|
43
|
+
expanded?: boolean | undefined;
|
|
44
|
+
onExpandedChange?: ((expanded: boolean) => void) | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Artifact preview with provenance: description, recipe, alias, decisions, and inputs. */
|
|
48
|
+
export const OutputDetail = forwardRef<HTMLDivElement, OutputDetailProps>(function OutputDetail({
|
|
49
|
+
record: output,
|
|
50
|
+
relations,
|
|
51
|
+
renderArtifact,
|
|
52
|
+
renderText,
|
|
53
|
+
onOpenRecord,
|
|
54
|
+
expanded = false,
|
|
55
|
+
onExpandedChange,
|
|
56
|
+
className,
|
|
57
|
+
...props
|
|
58
|
+
}, ref) {
|
|
59
|
+
const labels = useLabels();
|
|
60
|
+
const artifact = artifactNode(output, renderArtifact);
|
|
61
|
+
// Reader layout (artifact column + details rail) only when there is an
|
|
62
|
+
// artifact to frame: a host renderer may opt out of a figure or table by
|
|
63
|
+
// returning null, and the details then take the single column instead.
|
|
64
|
+
const visual = artifact != null;
|
|
65
|
+
const exitFullScreen = useCallback(() => { onExpandedChange?.(false); }, [onExpandedChange]);
|
|
66
|
+
// Inside a modal dialog, Escape reaches the full-screen layer through the
|
|
67
|
+
// dialog's cancel event (the guard), which fires after any keydown handling
|
|
68
|
+
// and cannot close the dialog underneath. Elsewhere the layer listens itself.
|
|
69
|
+
const dialog = useOptionalDialog();
|
|
70
|
+
const inModalDialog = dialog?.mode === 'modal';
|
|
71
|
+
useDialogDismissGuard(expanded, exitFullScreen);
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (!expanded || inModalDialog) return undefined;
|
|
74
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
75
|
+
if (event.key === 'Escape') exitFullScreen();
|
|
76
|
+
};
|
|
77
|
+
document.addEventListener('keydown', onKeyDown);
|
|
78
|
+
return () => { document.removeEventListener('keydown', onKeyDown); };
|
|
79
|
+
}, [expanded, inModalDialog, exitFullScreen]);
|
|
80
|
+
// The full-screen layer is a modal: focus enters it, everything outside it
|
|
81
|
+
// (up to the enclosing native dialog, or the document) is inert while it
|
|
82
|
+
// is open, and focus returns to the control that opened it.
|
|
83
|
+
const layerRef = useRef<HTMLDivElement | null>(null);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const layer = layerRef.current;
|
|
86
|
+
if (!expanded || !layer) return undefined;
|
|
87
|
+
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
88
|
+
const boundary: HTMLElement = layer.closest('dialog') ?? document.body;
|
|
89
|
+
const inerted: Element[] = [];
|
|
90
|
+
let node: HTMLElement = layer;
|
|
91
|
+
while (node !== boundary) {
|
|
92
|
+
const parent: HTMLElement | null = node.parentElement;
|
|
93
|
+
if (!parent) break;
|
|
94
|
+
for (const sibling of Array.from(parent.children)) {
|
|
95
|
+
if (sibling !== node && !sibling.hasAttribute('inert')) {
|
|
96
|
+
sibling.setAttribute('inert', '');
|
|
97
|
+
inerted.push(sibling);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
node = parent;
|
|
101
|
+
}
|
|
102
|
+
(layer.querySelector<HTMLElement>('button') ?? layer).focus();
|
|
103
|
+
return () => {
|
|
104
|
+
for (const element of inerted) element.removeAttribute('inert');
|
|
105
|
+
if (opener?.isConnected) opener.focus();
|
|
106
|
+
};
|
|
107
|
+
}, [expanded]);
|
|
108
|
+
|
|
109
|
+
const supportingDetails = (
|
|
110
|
+
<aside className="astra-output-detail__provenance" aria-label="Output provenance and dependencies">
|
|
111
|
+
{output.description ? (
|
|
112
|
+
<section className="astra-output-detail__description">
|
|
113
|
+
<h4>Description</h4>
|
|
114
|
+
<div className="astra-output-detail__description-text">
|
|
115
|
+
<Prose text={output.description} field="description" renderText={renderText} />
|
|
116
|
+
</div>
|
|
117
|
+
</section>
|
|
118
|
+
) : null}
|
|
119
|
+
{output.recipe?.command ? (
|
|
120
|
+
<section className="astra-output-detail__recipe">
|
|
121
|
+
<h4>Recipe</h4>
|
|
122
|
+
<pre><code>{output.recipe.command}</code></pre>
|
|
123
|
+
{output.recipe.container
|
|
124
|
+
? <p>Container: <code>{output.recipe.container}</code></p>
|
|
125
|
+
: null}
|
|
126
|
+
</section>
|
|
127
|
+
) : null}
|
|
128
|
+
{output.resolvedFrom ? (
|
|
129
|
+
<RelationList
|
|
130
|
+
className="astra-detail__relations"
|
|
131
|
+
title="Resolved alias"
|
|
132
|
+
items={relationItemsForLinks([relations.alias ?? { canonicalPath: output.resolvedFrom }], onOpenRecord)}
|
|
133
|
+
empty={null}
|
|
134
|
+
/>
|
|
135
|
+
) : null}
|
|
136
|
+
<RelationList
|
|
137
|
+
className="astra-detail__relations"
|
|
138
|
+
title="Decision dependencies"
|
|
139
|
+
items={relationItemsForLinks(relations.decisions, onOpenRecord)}
|
|
140
|
+
empty="No decision dependencies are declared for this output."
|
|
141
|
+
/>
|
|
142
|
+
{relations.indirectDecisions?.length ? (
|
|
143
|
+
<RelationList
|
|
144
|
+
className="astra-detail__relations"
|
|
145
|
+
title="Indirect decision dependencies"
|
|
146
|
+
description="Through upstream outputs."
|
|
147
|
+
items={relationItemsForLinks(relations.indirectDecisions, onOpenRecord)}
|
|
148
|
+
empty={null}
|
|
149
|
+
/>
|
|
150
|
+
) : null}
|
|
151
|
+
<RelationList
|
|
152
|
+
className="astra-detail__relations"
|
|
153
|
+
title="Inputs and upstream outputs"
|
|
154
|
+
items={relationItemsForLinks(relations.inputs, onOpenRecord)}
|
|
155
|
+
empty="No upstream dependencies are declared for this output."
|
|
156
|
+
/>
|
|
157
|
+
</aside>
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div
|
|
162
|
+
data-slot="output-detail"
|
|
163
|
+
{...props}
|
|
164
|
+
ref={ref}
|
|
165
|
+
className={cn('astra-output-detail__layout', className)}
|
|
166
|
+
data-layout={visual ? 'reader' : 'single'}
|
|
167
|
+
>
|
|
168
|
+
<div className="astra-output-detail__result">
|
|
169
|
+
{artifact != null ? (
|
|
170
|
+
<div
|
|
171
|
+
ref={layerRef}
|
|
172
|
+
className="astra-output-detail__artifact"
|
|
173
|
+
data-type={output.type}
|
|
174
|
+
{...(expanded
|
|
175
|
+
? { 'data-expanded': '', role: 'dialog', 'aria-modal': 'true', 'aria-label': `Full-screen ${output.type}: ${recordTitle(output)}` }
|
|
176
|
+
: {})}
|
|
177
|
+
>
|
|
178
|
+
{expanded ? (
|
|
179
|
+
<div className="astra-output-detail__fullscreen-header">
|
|
180
|
+
<span>
|
|
181
|
+
<small>{labels.actions.fullScreen}</small>
|
|
182
|
+
<strong>{recordTitle(output)}</strong>
|
|
183
|
+
</span>
|
|
184
|
+
<button type="button" onClick={() => onExpandedChange?.(false)}>
|
|
185
|
+
<span aria-hidden="true">×</span>
|
|
186
|
+
<span>{labels.actions.exitFullScreen}</span>
|
|
187
|
+
</button>
|
|
188
|
+
</div>
|
|
189
|
+
) : null}
|
|
190
|
+
<div className="astra-output-detail__preview" data-type={output.type}>
|
|
191
|
+
{artifact}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
) : null}
|
|
195
|
+
{!visual ? supportingDetails : null}
|
|
196
|
+
</div>
|
|
197
|
+
{visual ? <div className="astra-output-detail__provenance-slot">{supportingDetails}</div> : null}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
export interface OutputDialogActionsProps {
|
|
203
|
+
record: ResolvedOutput;
|
|
204
|
+
onOpenArtifact?: ((output: ResolvedOutput) => void | Promise<void>) | undefined;
|
|
205
|
+
expanded: boolean;
|
|
206
|
+
onExpandedChange: (expanded: boolean) => void;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Header actions for an output: open the artifact in the host, enter full screen. */
|
|
210
|
+
export function OutputDialogActions({ record: output, onOpenArtifact, expanded, onExpandedChange }: OutputDialogActionsProps) {
|
|
211
|
+
const labels = useLabels();
|
|
212
|
+
const visual = isVisualOutput(output);
|
|
213
|
+
return (
|
|
214
|
+
<>
|
|
215
|
+
{onOpenArtifact && output.artifact ? (
|
|
216
|
+
<DialogAction onClick={() => { void onOpenArtifact(output); }}>
|
|
217
|
+
<span aria-hidden="true">↗</span>
|
|
218
|
+
<span>{labels.actions.openArtifact}</span>
|
|
219
|
+
</DialogAction>
|
|
220
|
+
) : null}
|
|
221
|
+
{visual ? (
|
|
222
|
+
<DialogAction
|
|
223
|
+
aria-label={`View ${output.type} full screen`}
|
|
224
|
+
aria-expanded={expanded}
|
|
225
|
+
onClick={() => { onExpandedChange(true); }}
|
|
226
|
+
>
|
|
227
|
+
<span aria-hidden="true">⛶</span>
|
|
228
|
+
<span>{labels.actions.fullScreen}</span>
|
|
229
|
+
</DialogAction>
|
|
230
|
+
) : null}
|
|
231
|
+
</>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Full-screen state for an output, reset whenever the output changes (a controlled host is asked to reset). */
|
|
236
|
+
export function useOutputExpanded(output: ResolvedOutput, controlled?: { expanded?: boolean | undefined; onExpandedChange?: ((next: boolean) => void) | undefined }) {
|
|
237
|
+
const [internal, setInternal] = useState(false);
|
|
238
|
+
const [lastPath, setLastPath] = useState(output.canonicalPath);
|
|
239
|
+
if (lastPath !== output.canonicalPath) {
|
|
240
|
+
setLastPath(output.canonicalPath);
|
|
241
|
+
setInternal(false);
|
|
242
|
+
}
|
|
243
|
+
const isControlled = controlled?.expanded !== undefined;
|
|
244
|
+
const expanded = isControlled ? Boolean(controlled.expanded) : internal;
|
|
245
|
+
const onChange = controlled?.onExpandedChange;
|
|
246
|
+
const seenPath = useRef(output.canonicalPath);
|
|
247
|
+
const controlledExpanded = isControlled && Boolean(controlled.expanded);
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
if (seenPath.current === output.canonicalPath) return;
|
|
250
|
+
seenPath.current = output.canonicalPath;
|
|
251
|
+
if (controlledExpanded) onChange?.(false);
|
|
252
|
+
}, [output.canonicalPath, controlledExpanded, onChange]);
|
|
253
|
+
const setExpanded = useCallback((next: boolean) => {
|
|
254
|
+
if (!isControlled) setInternal(next);
|
|
255
|
+
onChange?.(next);
|
|
256
|
+
}, [isControlled, onChange]);
|
|
257
|
+
return [expanded, setExpanded] as const;
|
|
258
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ResolvedOutput } from '@astra-spec/sdk';
|
|
2
|
+
import type { OutputRelations } from '../model/relations.js';
|
|
3
|
+
import { isVisualOutput, recordTitle } from '../model/records.js';
|
|
4
|
+
import { useLabels } from '../lib/labels.js';
|
|
5
|
+
import type { ArtifactRenderer } from './artifact-preview.js';
|
|
6
|
+
import { DetailDialog, type DetailDialogProps } from '../primitives/dialog.js';
|
|
7
|
+
import type { TextRenderer } from '../primitives/prose.js';
|
|
8
|
+
import { OutputDetail, OutputDialogActions, useOutputExpanded } from './output-detail.js';
|
|
9
|
+
import type { OpenRecordHandler } from './relation-items.js';
|
|
10
|
+
|
|
11
|
+
export interface OutputDialogProps extends Pick<DetailDialogProps, 'mode' | 'backText' | 'className' | 'onBack' | 'onClose'> {
|
|
12
|
+
record: ResolvedOutput;
|
|
13
|
+
relations: OutputRelations;
|
|
14
|
+
renderArtifact?: ArtifactRenderer | undefined;
|
|
15
|
+
renderText?: TextRenderer | undefined;
|
|
16
|
+
onOpenArtifact?: ((output: ResolvedOutput) => void | Promise<void>) | undefined;
|
|
17
|
+
onOpenRecord?: OpenRecordHandler | undefined;
|
|
18
|
+
expanded?: boolean | undefined;
|
|
19
|
+
onExpandedChange?: ((expanded: boolean) => void) | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function OutputDialog({
|
|
23
|
+
record: output,
|
|
24
|
+
relations,
|
|
25
|
+
renderArtifact,
|
|
26
|
+
renderText,
|
|
27
|
+
onOpenArtifact,
|
|
28
|
+
onOpenRecord,
|
|
29
|
+
expanded: controlledExpanded,
|
|
30
|
+
onExpandedChange,
|
|
31
|
+
...dialog
|
|
32
|
+
}: OutputDialogProps) {
|
|
33
|
+
const labels = useLabels();
|
|
34
|
+
const [expanded, setExpanded] = useOutputExpanded(output, { expanded: controlledExpanded, onExpandedChange });
|
|
35
|
+
return (
|
|
36
|
+
<DetailDialog
|
|
37
|
+
{...dialog}
|
|
38
|
+
kind="output"
|
|
39
|
+
layout={isVisualOutput(output) ? 'reader' : undefined}
|
|
40
|
+
kindLabel={output.type}
|
|
41
|
+
title={recordTitle(output)}
|
|
42
|
+
closeLabel={labels.closeRecord(labels.kinds.output)}
|
|
43
|
+
actions={(
|
|
44
|
+
<OutputDialogActions
|
|
45
|
+
record={output}
|
|
46
|
+
onOpenArtifact={onOpenArtifact}
|
|
47
|
+
expanded={expanded}
|
|
48
|
+
onExpandedChange={setExpanded}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
>
|
|
52
|
+
<OutputDetail
|
|
53
|
+
record={output}
|
|
54
|
+
relations={relations}
|
|
55
|
+
renderArtifact={renderArtifact}
|
|
56
|
+
renderText={renderText}
|
|
57
|
+
onOpenRecord={onOpenRecord}
|
|
58
|
+
expanded={expanded}
|
|
59
|
+
onExpandedChange={setExpanded}
|
|
60
|
+
/>
|
|
61
|
+
</DetailDialog>
|
|
62
|
+
);
|
|
63
|
+
}
|