@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,145 @@
|
|
|
1
|
+
import { createContext, useContext, useMemo, type ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
/** Every user-facing string the components render, overridable per host. */
|
|
4
|
+
export interface AstraLabels {
|
|
5
|
+
sections: {
|
|
6
|
+
outputs: string;
|
|
7
|
+
decisions: string;
|
|
8
|
+
inputs: string;
|
|
9
|
+
findings: string;
|
|
10
|
+
prior_insights: string;
|
|
11
|
+
papers: string;
|
|
12
|
+
};
|
|
13
|
+
outline: string;
|
|
14
|
+
analysisTree: string;
|
|
15
|
+
back: string;
|
|
16
|
+
backTo: string;
|
|
17
|
+
close: string;
|
|
18
|
+
notFound: string;
|
|
19
|
+
closeRecord: (kindLabel: string) => string;
|
|
20
|
+
/** The count shown beside a section heading, e.g. "65 outputs". */
|
|
21
|
+
sectionCount: (section: keyof AstraLabels['sections'], count: number) => string;
|
|
22
|
+
kinds: {
|
|
23
|
+
analysis: string;
|
|
24
|
+
input: string;
|
|
25
|
+
decision: string;
|
|
26
|
+
output: string;
|
|
27
|
+
finding: string;
|
|
28
|
+
prior_insight: string;
|
|
29
|
+
paper: string;
|
|
30
|
+
};
|
|
31
|
+
empty: {
|
|
32
|
+
outputs: string;
|
|
33
|
+
decisions: string;
|
|
34
|
+
inputs: string;
|
|
35
|
+
findings: string;
|
|
36
|
+
prior_insights: string;
|
|
37
|
+
papers: string;
|
|
38
|
+
};
|
|
39
|
+
actions: {
|
|
40
|
+
openArtifact: string;
|
|
41
|
+
fullScreen: string;
|
|
42
|
+
exitFullScreen: string;
|
|
43
|
+
fetchPaper: string;
|
|
44
|
+
openPaper: string;
|
|
45
|
+
locate: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const SECTION_NOUNS: Record<keyof AstraLabels['sections'], [string, string]> = {
|
|
50
|
+
outputs: ['output', 'outputs'],
|
|
51
|
+
decisions: ['decision', 'decisions'],
|
|
52
|
+
inputs: ['input', 'inputs'],
|
|
53
|
+
findings: ['finding', 'findings'],
|
|
54
|
+
prior_insights: ['prior insight', 'prior insights'],
|
|
55
|
+
papers: ['paper', 'papers'],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const defaultLabels: AstraLabels = {
|
|
59
|
+
sections: {
|
|
60
|
+
outputs: 'Outputs',
|
|
61
|
+
decisions: 'Decisions',
|
|
62
|
+
inputs: 'Inputs',
|
|
63
|
+
findings: 'Findings',
|
|
64
|
+
prior_insights: 'Prior Insights',
|
|
65
|
+
papers: 'Papers',
|
|
66
|
+
},
|
|
67
|
+
outline: 'On this page',
|
|
68
|
+
analysisTree: 'Project hierarchy',
|
|
69
|
+
back: 'Back',
|
|
70
|
+
backTo: 'Back to previous record',
|
|
71
|
+
close: 'Close all details',
|
|
72
|
+
closeRecord: (kindLabel) => `Close ${kindLabel.toLowerCase()} details`,
|
|
73
|
+
sectionCount: (section, count) => `${count} ${count === 1 ? SECTION_NOUNS[section][0] : SECTION_NOUNS[section][1]}`,
|
|
74
|
+
notFound: 'This record is no longer available.',
|
|
75
|
+
kinds: {
|
|
76
|
+
analysis: 'Analysis',
|
|
77
|
+
input: 'Input',
|
|
78
|
+
decision: 'Decision',
|
|
79
|
+
output: 'Output',
|
|
80
|
+
finding: 'Finding',
|
|
81
|
+
prior_insight: 'Insight',
|
|
82
|
+
paper: 'Paper',
|
|
83
|
+
},
|
|
84
|
+
empty: {
|
|
85
|
+
outputs: 'No outputs are declared in this analysis.',
|
|
86
|
+
decisions: 'No decisions are declared in this analysis.',
|
|
87
|
+
inputs: 'No inputs are declared in this analysis.',
|
|
88
|
+
findings: 'No findings are declared in this analysis.',
|
|
89
|
+
prior_insights: 'No prior insights are declared in this analysis.',
|
|
90
|
+
papers: 'No supporting papers are linked to this analysis.',
|
|
91
|
+
},
|
|
92
|
+
actions: {
|
|
93
|
+
openArtifact: 'Open artifact',
|
|
94
|
+
fullScreen: 'Full screen',
|
|
95
|
+
exitFullScreen: 'Exit full screen',
|
|
96
|
+
fetchPaper: 'Fetch paper',
|
|
97
|
+
openPaper: 'Open',
|
|
98
|
+
locate: 'Locate',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** Deep partial of the label set, for host overrides. */
|
|
103
|
+
export type AstraLabelOverrides = {
|
|
104
|
+
[K in keyof AstraLabels]?: (AstraLabels[K] extends object
|
|
105
|
+
? AstraLabels[K] extends (...args: never[]) => unknown
|
|
106
|
+
? AstraLabels[K]
|
|
107
|
+
: { [P in keyof AstraLabels[K]]?: AstraLabels[K][P] | undefined }
|
|
108
|
+
: AstraLabels[K]) | undefined;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function defined<T extends object>(value: T): Partial<T> {
|
|
112
|
+
return Object.fromEntries(Object.entries(value).filter(([, member]) => member !== undefined)) as Partial<T>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const LabelsContext = createContext<AstraLabels>(defaultLabels);
|
|
116
|
+
|
|
117
|
+
function merge(base: AstraLabels, overrides: AstraLabelOverrides): AstraLabels {
|
|
118
|
+
return {
|
|
119
|
+
...base,
|
|
120
|
+
...defined(overrides),
|
|
121
|
+
sections: { ...base.sections, ...defined(overrides.sections ?? {}) },
|
|
122
|
+
kinds: { ...base.kinds, ...defined(overrides.kinds ?? {}) },
|
|
123
|
+
empty: { ...base.empty, ...defined(overrides.empty ?? {}) },
|
|
124
|
+
actions: { ...base.actions, ...defined(overrides.actions ?? {}) },
|
|
125
|
+
} as AstraLabels;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function mergeLabels(overrides: AstraLabelOverrides | undefined): AstraLabels {
|
|
129
|
+
return overrides ? merge(defaultLabels, overrides) : defaultLabels;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface LabelsProviderProps {
|
|
133
|
+
labels?: AstraLabelOverrides | undefined;
|
|
134
|
+
children: ReactNode;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function LabelsProvider({ labels, children }: LabelsProviderProps) {
|
|
138
|
+
const parent = useContext(LabelsContext);
|
|
139
|
+
const value = useMemo(() => (labels ? merge(parent, labels) : parent), [labels, parent]);
|
|
140
|
+
return <LabelsContext.Provider value={value}>{children}</LabelsContext.Provider>;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function useLabels(): AstraLabels {
|
|
144
|
+
return useContext(LabelsContext);
|
|
145
|
+
}
|
package/src/lib/slot.tsx
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
cloneElement,
|
|
4
|
+
forwardRef,
|
|
5
|
+
isValidElement,
|
|
6
|
+
type HTMLAttributes,
|
|
7
|
+
type ReactElement,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
type Ref,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { cn } from './cn.js';
|
|
12
|
+
|
|
13
|
+
export interface SlotProps extends HTMLAttributes<HTMLElement> {
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type SlottableElement = ReactElement<Record<string, unknown> & { ref?: Ref<HTMLElement> }>;
|
|
18
|
+
|
|
19
|
+
function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): Ref<T> {
|
|
20
|
+
return (value: T | null) => {
|
|
21
|
+
// React 19 callback refs may return a cleanup; when any does, return one
|
|
22
|
+
// cleanup that runs them and detaches the others instead of letting React
|
|
23
|
+
// call this ref again with null.
|
|
24
|
+
const cleanups = refs.map((ref): unknown => {
|
|
25
|
+
if (typeof ref === 'function') {
|
|
26
|
+
const callback: (instance: T | null) => unknown = ref;
|
|
27
|
+
return callback(value);
|
|
28
|
+
}
|
|
29
|
+
if (ref) (ref as { current: T | null }).current = value;
|
|
30
|
+
return undefined;
|
|
31
|
+
});
|
|
32
|
+
if (!cleanups.some((cleanup) => typeof cleanup === 'function')) return undefined;
|
|
33
|
+
return () => {
|
|
34
|
+
refs.forEach((ref, index) => {
|
|
35
|
+
const cleanup = cleanups[index];
|
|
36
|
+
if (typeof cleanup === 'function') (cleanup as () => void)();
|
|
37
|
+
else if (typeof ref === 'function') ref(null);
|
|
38
|
+
else if (ref) (ref as { current: T | null }).current = null;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The child's own ref across React versions. React 18 keeps it on the
|
|
46
|
+
* element and, in development, defines a warning getter `props.ref`;
|
|
47
|
+
* React 19 keeps it in `props` and warns on `element.ref`. Only the real one
|
|
48
|
+
* is read, so neither build logs nor drops the ref.
|
|
49
|
+
*/
|
|
50
|
+
function elementRef(element: SlottableElement): Ref<HTMLElement> | undefined {
|
|
51
|
+
const isWarning = (target: object) => {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- the getter is inspected for React's warning flag, never called
|
|
53
|
+
const getter = Object.getOwnPropertyDescriptor(target, 'ref')?.get;
|
|
54
|
+
return Boolean(getter && 'isReactWarning' in getter && getter.isReactWarning);
|
|
55
|
+
};
|
|
56
|
+
if (isWarning(element.props)) return (element as { ref?: Ref<HTMLElement> }).ref;
|
|
57
|
+
if (isWarning(element)) return element.props.ref;
|
|
58
|
+
return element.props.ref ?? (element as { ref?: Ref<HTMLElement> }).ref;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Renders its single child with the slot's props merged in (the `asChild`
|
|
63
|
+
* pattern): class names are concatenated, event handlers are composed, and
|
|
64
|
+
* refs are forwarded. Used by Button and the dialog parts.
|
|
65
|
+
*/
|
|
66
|
+
export const Slot = forwardRef<HTMLElement, SlotProps>(function Slot({ children, ...props }, ref) {
|
|
67
|
+
const child = Children.only(children);
|
|
68
|
+
if (!isValidElement(child)) return null;
|
|
69
|
+
const element = child as SlottableElement;
|
|
70
|
+
const childProps = element.props;
|
|
71
|
+
const merged: Record<string, unknown> = { ...props };
|
|
72
|
+
for (const [key, value] of Object.entries(childProps)) {
|
|
73
|
+
// A child prop set to undefined does not erase the slot's prop.
|
|
74
|
+
if (value === undefined) continue;
|
|
75
|
+
const slotValue = merged[key];
|
|
76
|
+
if (key === 'className') merged[key] = cn(slotValue as string | undefined, value as string | undefined);
|
|
77
|
+
else if (key === 'style') merged[key] = { ...(slotValue as object | undefined), ...(value as object) };
|
|
78
|
+
else if (/^on[A-Z]/.test(key) && typeof slotValue === 'function' && typeof value === 'function') {
|
|
79
|
+
merged[key] = (...args: unknown[]) => {
|
|
80
|
+
(value as (...a: unknown[]) => void)(...args);
|
|
81
|
+
(slotValue as (...a: unknown[]) => void)(...args);
|
|
82
|
+
};
|
|
83
|
+
} else merged[key] = value;
|
|
84
|
+
}
|
|
85
|
+
merged.ref = mergeRefs(ref, elementRef(element));
|
|
86
|
+
return cloneElement(element, merged);
|
|
87
|
+
});
|
package/src/model/doi.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Model: pure, React-free derivations over the SDK's resolved analysis. */
|
|
2
|
+
export { analysisTitle, countLabel, isInsight, isVisualOutput, recordTitle, selectedOptionLabel } from './records.js';
|
|
3
|
+
export { locateRecord } from './locate-record.js';
|
|
4
|
+
export type { LocatedRecord } from './locate-record.js';
|
|
5
|
+
export {
|
|
6
|
+
decisionInsightPaths,
|
|
7
|
+
decisionInsights,
|
|
8
|
+
findingEvidence,
|
|
9
|
+
findingLiterature,
|
|
10
|
+
indirectDecisionPaths,
|
|
11
|
+
informedDecisions,
|
|
12
|
+
linkedRecord,
|
|
13
|
+
outputRelations,
|
|
14
|
+
} from './relations.js';
|
|
15
|
+
export type { FindingEvidenceLink, LinkedRecord, OutputRelations } from './relations.js';
|
|
16
|
+
export {
|
|
17
|
+
analysesForPaperView,
|
|
18
|
+
collectInventoryPapers,
|
|
19
|
+
findPaper,
|
|
20
|
+
insightDois,
|
|
21
|
+
paperEvidence,
|
|
22
|
+
paperForDoi,
|
|
23
|
+
paperMetadataFor,
|
|
24
|
+
} from './papers.js';
|
|
25
|
+
export type {
|
|
26
|
+
InventoryPaper,
|
|
27
|
+
InventoryPaperMetadata,
|
|
28
|
+
InventoryPaperMetadataMap,
|
|
29
|
+
PaperFetchStatus,
|
|
30
|
+
PaperFocusEvidence,
|
|
31
|
+
} from './papers.js';
|
|
32
|
+
export { doiHref } from './doi.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AnalysisIndex, ResolvedAnalysisNode, ResolvedRecord } from '@astra-spec/sdk';
|
|
2
|
+
|
|
3
|
+
export interface LocatedRecord {
|
|
4
|
+
record: ResolvedRecord;
|
|
5
|
+
analysis: ResolvedAnalysisNode;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Resolves a canonical path to the record and the analysis that declares it. */
|
|
9
|
+
export function locateRecord(index: AnalysisIndex, canonicalPath: string): LocatedRecord | undefined {
|
|
10
|
+
const record = index.recordByPath.get(canonicalPath);
|
|
11
|
+
const analysis = index.analysisByRecordPath.get(canonicalPath);
|
|
12
|
+
return record && analysis ? { record, analysis } : undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeDoi,
|
|
3
|
+
walkAnalyses,
|
|
4
|
+
type AnalysisIndex,
|
|
5
|
+
type ResolvedAnalysisDocument,
|
|
6
|
+
type ResolvedAnalysisNode,
|
|
7
|
+
type ResolvedDecision,
|
|
8
|
+
type ResolvedEvidence,
|
|
9
|
+
type ResolvedInsight,
|
|
10
|
+
} from '@astra-spec/sdk';
|
|
11
|
+
import { decisionInsights } from './relations.js';
|
|
12
|
+
|
|
13
|
+
export interface InventoryPaper {
|
|
14
|
+
doi: string;
|
|
15
|
+
title: string;
|
|
16
|
+
authors?: string | undefined;
|
|
17
|
+
pdfUrl?: string | undefined;
|
|
18
|
+
insights: ResolvedInsight[];
|
|
19
|
+
decisions: ResolvedDecision[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type PaperFetchStatus = 'idle' | 'fetching' | 'error';
|
|
23
|
+
|
|
24
|
+
export interface InventoryPaperMetadata {
|
|
25
|
+
title?: string | undefined;
|
|
26
|
+
authors?: string | undefined;
|
|
27
|
+
pdfUrl?: string | undefined;
|
|
28
|
+
/** Host-owned fetch state; the dialog reflects it and disables the fetch control while pending. */
|
|
29
|
+
status?: PaperFetchStatus | undefined;
|
|
30
|
+
error?: string | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type InventoryPaperMetadataMap = Readonly<Record<string, InventoryPaperMetadata>>;
|
|
34
|
+
|
|
35
|
+
export interface PaperFocusEvidence {
|
|
36
|
+
/** Changes on every locate request, including a repeat of the same passage, so a host can react to each one. */
|
|
37
|
+
key: string;
|
|
38
|
+
insight: ResolvedInsight;
|
|
39
|
+
evidence: ResolvedEvidence;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Looks up metadata by DOI, whichever spelling the host used as the key. */
|
|
43
|
+
export function paperMetadataFor(doi: string, metadata: InventoryPaperMetadataMap): InventoryPaperMetadata | undefined {
|
|
44
|
+
const direct = metadata[normalizeDoi(doi)] ?? metadata[doi];
|
|
45
|
+
if (direct) return direct;
|
|
46
|
+
const key = normalizeDoi(doi);
|
|
47
|
+
const match = Object.keys(metadata).find((candidate) => normalizeDoi(candidate) === key);
|
|
48
|
+
return match === undefined ? undefined : metadata[match];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function paperFromDoi(doi: string, paperMetadata: InventoryPaperMetadataMap): InventoryPaper {
|
|
52
|
+
const canonicalDoi = normalizeDoi(doi);
|
|
53
|
+
const metadata = paperMetadataFor(doi, paperMetadata);
|
|
54
|
+
return {
|
|
55
|
+
doi: canonicalDoi,
|
|
56
|
+
title: metadata?.title ?? canonicalDoi,
|
|
57
|
+
authors: metadata?.authors,
|
|
58
|
+
pdfUrl: metadata?.pdfUrl,
|
|
59
|
+
insights: [],
|
|
60
|
+
decisions: [],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function insightDois(insight: ResolvedInsight): string[] {
|
|
65
|
+
const seen = new Set<string>();
|
|
66
|
+
const dois: string[] = [];
|
|
67
|
+
for (const { doi } of insight.evidence) {
|
|
68
|
+
if (!doi) continue;
|
|
69
|
+
const key = normalizeDoi(doi);
|
|
70
|
+
if (seen.has(key)) continue;
|
|
71
|
+
seen.add(key);
|
|
72
|
+
dois.push(doi);
|
|
73
|
+
}
|
|
74
|
+
return dois;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Quoted evidence an insight draws from a given paper. */
|
|
78
|
+
export function paperEvidence(insight: ResolvedInsight, doi: string): ResolvedEvidence[] {
|
|
79
|
+
const key = normalizeDoi(doi);
|
|
80
|
+
return insight.evidence.filter((evidence) => evidence.quote && normalizeDoi(evidence.doi ?? '') === key);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The root inventory aggregates cited papers; child inventories stay local. */
|
|
84
|
+
export function analysesForPaperView(document: ResolvedAnalysisDocument, analysis: ResolvedAnalysisNode): ResolvedAnalysisNode[] {
|
|
85
|
+
return analysis.canonicalPath === '$' ? [...walkAnalyses(document)] : [analysis];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function collectInventoryPapers(
|
|
89
|
+
document: ResolvedAnalysisDocument,
|
|
90
|
+
index: AnalysisIndex,
|
|
91
|
+
analysis: ResolvedAnalysisNode,
|
|
92
|
+
paperMetadata: InventoryPaperMetadataMap = {},
|
|
93
|
+
): InventoryPaper[] {
|
|
94
|
+
const analyses = analysesForPaperView(document, analysis);
|
|
95
|
+
const insights = new Map<string, ResolvedInsight>();
|
|
96
|
+
const decisions = new Map<string, ResolvedDecision>();
|
|
97
|
+
|
|
98
|
+
for (const candidate of analyses) {
|
|
99
|
+
for (const record of candidate.decisions) decisions.set(record.canonicalPath, record);
|
|
100
|
+
for (const record of [...candidate.prior_insights, ...candidate.findings]) insights.set(record.canonicalPath, record);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (analysis.canonicalPath !== '$') {
|
|
104
|
+
for (const decision of decisions.values()) {
|
|
105
|
+
for (const insight of decisionInsights(index, decision)) insights.set(insight.canonicalPath, insight);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const papers = new Map<string, InventoryPaper>();
|
|
110
|
+
for (const insight of insights.values()) {
|
|
111
|
+
for (const doi of insightDois(insight)) {
|
|
112
|
+
const key = normalizeDoi(doi);
|
|
113
|
+
const paper = papers.get(key) ?? paperFromDoi(doi, paperMetadata);
|
|
114
|
+
if (!paper.insights.some((candidate) => candidate.canonicalPath === insight.canonicalPath)) {
|
|
115
|
+
paper.insights.push(insight);
|
|
116
|
+
}
|
|
117
|
+
papers.set(key, paper);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const decision of decisions.values()) {
|
|
122
|
+
const dois = new Set(decisionInsights(index, decision).flatMap(insightDois).map(normalizeDoi));
|
|
123
|
+
for (const key of dois) {
|
|
124
|
+
papers.get(key)?.decisions.push(decision);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return [...papers.values()].sort((left, right) => left.doi.localeCompare(right.doi));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The paper a DOI denotes within one analysis' scope (see `collectInventoryPapers`), whether or not the host listed it. */
|
|
132
|
+
export function paperForDoi(
|
|
133
|
+
document: ResolvedAnalysisDocument,
|
|
134
|
+
index: AnalysisIndex,
|
|
135
|
+
analysis: ResolvedAnalysisNode,
|
|
136
|
+
doi: string,
|
|
137
|
+
paperMetadata: InventoryPaperMetadataMap = {},
|
|
138
|
+
): InventoryPaper | undefined {
|
|
139
|
+
return findPaper(collectInventoryPapers(document, index, analysis, paperMetadata), doi);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Finds a paper in a collection by DOI, tolerant of formatting differences. */
|
|
143
|
+
export function findPaper(papers: readonly InventoryPaper[], doi: string): InventoryPaper | undefined {
|
|
144
|
+
const key = normalizeDoi(doi);
|
|
145
|
+
return papers.find((paper) => normalizeDoi(paper.doi) === key);
|
|
146
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ResolvedAnalysisNode,
|
|
3
|
+
ResolvedDecision,
|
|
4
|
+
ResolvedInsight,
|
|
5
|
+
ResolvedOutput,
|
|
6
|
+
ResolvedRecord,
|
|
7
|
+
} from '@astra-spec/sdk';
|
|
8
|
+
|
|
9
|
+
function nonEmpty(value: string | undefined): string | undefined {
|
|
10
|
+
const trimmed = value?.trim();
|
|
11
|
+
if (!trimmed) return undefined;
|
|
12
|
+
return trimmed;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function analysisTitle(analysis: ResolvedAnalysisNode): string {
|
|
16
|
+
return nonEmpty(analysis.name)
|
|
17
|
+
?? nonEmpty(analysis.id)
|
|
18
|
+
?? (analysis.canonicalPath === '$' ? 'Analysis' : analysis.canonicalPath);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function recordTitle(record: ResolvedRecord): string {
|
|
22
|
+
return nonEmpty(record.label) ?? record.id;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function selectedOptionLabel(decision: ResolvedDecision): string {
|
|
26
|
+
if (!decision.selectedOptionId) return decision.active ? 'Not selected' : 'Inactive';
|
|
27
|
+
return decision.options.find(({ id }) => id === decision.selectedOptionId)?.label
|
|
28
|
+
?? decision.selectedOptionId;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isInsight(record: ResolvedRecord | undefined): record is ResolvedInsight {
|
|
32
|
+
return record?.kind === 'prior_insight' || record?.kind === 'finding';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Figures and tables get the reader layout; everything else is a single-column detail. */
|
|
36
|
+
export function isVisualOutput(output: ResolvedOutput): boolean {
|
|
37
|
+
return output.type === 'figure' || output.type === 'table';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Pluralises a count with the given singular/plural nouns. */
|
|
41
|
+
export function countLabel(count: number, singular: string, plural = `${singular}s`): string {
|
|
42
|
+
return `${count} ${count === 1 ? singular : plural}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ResolvedAnalysisNode,
|
|
3
|
+
ResolvedDecision,
|
|
4
|
+
ResolvedEvidence,
|
|
5
|
+
ResolvedInsight,
|
|
6
|
+
ResolvedOutput,
|
|
7
|
+
ResolvedRecord,
|
|
8
|
+
} from '@astra-spec/sdk';
|
|
9
|
+
import { walkAnalyses, type AnalysisIndex, type ResolvedAnalysisDocument } from '@astra-spec/sdk';
|
|
10
|
+
import { locateRecord } from './locate-record.js';
|
|
11
|
+
import { isInsight } from './records.js';
|
|
12
|
+
|
|
13
|
+
/** A referenced record; `record`/`analysis` are absent when the path does not resolve. */
|
|
14
|
+
export interface LinkedRecord {
|
|
15
|
+
canonicalPath: string;
|
|
16
|
+
record?: ResolvedRecord | undefined;
|
|
17
|
+
analysis?: ResolvedAnalysisNode | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface OutputRelations {
|
|
21
|
+
inputs: LinkedRecord[];
|
|
22
|
+
/** Decisions the output declares directly. */
|
|
23
|
+
decisions: LinkedRecord[];
|
|
24
|
+
/**
|
|
25
|
+
* Decisions reached through upstream outputs (see `indirectDecisionPaths`).
|
|
26
|
+
* `outputRelations()` always fills it (possibly empty); optional so hosts
|
|
27
|
+
* assembling relations by hand can leave it out.
|
|
28
|
+
*/
|
|
29
|
+
indirectDecisions?: LinkedRecord[] | undefined;
|
|
30
|
+
alias?: LinkedRecord | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FindingEvidenceLink {
|
|
34
|
+
evidence: ResolvedEvidence;
|
|
35
|
+
output?: ResolvedOutput | undefined;
|
|
36
|
+
analysis?: ResolvedAnalysisNode | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function linkedRecord(index: AnalysisIndex, canonicalPath: string): LinkedRecord {
|
|
40
|
+
const located = locateRecord(index, canonicalPath);
|
|
41
|
+
return {
|
|
42
|
+
canonicalPath,
|
|
43
|
+
...(located ? { record: located.record, analysis: located.analysis } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Decisions an output depends on only through its upstream outputs: the
|
|
49
|
+
* provenance of every input that is (or aliases) an output, followed
|
|
50
|
+
* recursively, minus the output's own direct decisions. Document order of
|
|
51
|
+
* discovery; cycles are ignored.
|
|
52
|
+
*/
|
|
53
|
+
export function indirectDecisionPaths(index: AnalysisIndex, output: ResolvedOutput): string[] {
|
|
54
|
+
const direct = new Set(output.provenance.decisionPaths);
|
|
55
|
+
const seen = new Set<string>([output.canonicalPath]);
|
|
56
|
+
const found: string[] = [];
|
|
57
|
+
const queue = [...output.provenance.inputPaths];
|
|
58
|
+
// Array iteration sees entries pushed while it runs, so the walk is a BFS.
|
|
59
|
+
for (const path of queue) {
|
|
60
|
+
if (seen.has(path)) continue;
|
|
61
|
+
seen.add(path);
|
|
62
|
+
let record = index.recordByPath.get(path);
|
|
63
|
+
if (record?.kind === 'input' && record.resolvedFrom) record = index.recordByPath.get(record.resolvedFrom);
|
|
64
|
+
if (record?.kind !== 'output') continue;
|
|
65
|
+
for (const decisionPath of record.provenance.decisionPaths) {
|
|
66
|
+
if (!direct.has(decisionPath) && !found.includes(decisionPath)) found.push(decisionPath);
|
|
67
|
+
}
|
|
68
|
+
queue.push(...record.provenance.inputPaths);
|
|
69
|
+
if (record.resolvedFrom) queue.push(record.resolvedFrom);
|
|
70
|
+
}
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Inputs, direct and indirect decisions, and alias source an output depends on; a record referenced twice (e.g. through an alias) is listed once. */
|
|
75
|
+
export function outputRelations(index: AnalysisIndex, output: ResolvedOutput): OutputRelations {
|
|
76
|
+
const unique = (paths: readonly string[]) => [...new Set(paths)];
|
|
77
|
+
return {
|
|
78
|
+
inputs: unique(output.provenance.inputPaths).map((path) => linkedRecord(index, path)),
|
|
79
|
+
decisions: unique(output.provenance.decisionPaths).map((path) => linkedRecord(index, path)),
|
|
80
|
+
indirectDecisions: indirectDecisionPaths(index, output).map((path) => linkedRecord(index, path)),
|
|
81
|
+
...(output.resolvedFrom ? { alias: linkedRecord(index, output.resolvedFrom) } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Artifact-backed evidence of a finding, resolved to outputs where possible. */
|
|
86
|
+
export function findingEvidence(index: AnalysisIndex, finding: ResolvedInsight): FindingEvidenceLink[] {
|
|
87
|
+
return finding.evidence
|
|
88
|
+
.filter((evidence) => Boolean(evidence.artifact) || Boolean(evidence.resolvedOutputPath))
|
|
89
|
+
.map((evidence) => {
|
|
90
|
+
const located = evidence.resolvedOutputPath
|
|
91
|
+
? locateRecord(index, evidence.resolvedOutputPath)
|
|
92
|
+
: undefined;
|
|
93
|
+
const output = located?.record.kind === 'output' ? located.record : undefined;
|
|
94
|
+
return {
|
|
95
|
+
evidence,
|
|
96
|
+
...(output && located ? { output, analysis: located.analysis } : {}),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Literature evidence (a DOI, with or without a quote) a finding or insight cites. */
|
|
102
|
+
export function findingLiterature(finding: ResolvedInsight): ResolvedEvidence[] {
|
|
103
|
+
return finding.evidence.filter((evidence) => Boolean(evidence.doi));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Insight paths cited by a decision's options, selected option first. */
|
|
107
|
+
export function decisionInsightPaths(decision: ResolvedDecision): string[] {
|
|
108
|
+
const selected = decision.options.find(({ id }) => id === decision.selectedOptionId);
|
|
109
|
+
return [...new Set([
|
|
110
|
+
...(selected?.resolvedInsightPaths ?? []),
|
|
111
|
+
...decision.options
|
|
112
|
+
.filter(({ id }) => id !== decision.selectedOptionId)
|
|
113
|
+
.flatMap(({ resolvedInsightPaths }) => resolvedInsightPaths),
|
|
114
|
+
])];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function decisionInsights(index: Pick<AnalysisIndex, 'recordByPath'>, decision: ResolvedDecision): ResolvedInsight[] {
|
|
118
|
+
return decisionInsightPaths(decision)
|
|
119
|
+
.map((path) => index.recordByPath.get(path))
|
|
120
|
+
.filter(isInsight);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Decisions anywhere in the document whose options cite this insight. */
|
|
124
|
+
export function informedDecisions(document: ResolvedAnalysisDocument, insight: ResolvedInsight): ResolvedDecision[] {
|
|
125
|
+
const decisions = new Map<string, ResolvedDecision>();
|
|
126
|
+
for (const analysis of walkAnalyses(document)) {
|
|
127
|
+
for (const decision of analysis.decisions) {
|
|
128
|
+
if (decision.options.some(({ resolvedInsightPaths }) => resolvedInsightPaths.includes(insight.canonicalPath))) {
|
|
129
|
+
decisions.set(decision.canonicalPath, decision);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return [...decisions.values()];
|
|
134
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { forwardRef, type HTMLAttributes } from 'react';
|
|
2
|
+
import { cn } from '../lib/cn.js';
|
|
3
|
+
import type { SurfaceKind } from './kind.js';
|
|
4
|
+
|
|
5
|
+
export type BadgeTone = 'neutral' | 'kind' | 'status' | 'universe';
|
|
6
|
+
export type BadgeStatus = 'available' | 'current' | 'materialized' | 'ready' | 'error' | 'missing' | 'stale';
|
|
7
|
+
|
|
8
|
+
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
9
|
+
kind?: SurfaceKind | undefined;
|
|
10
|
+
status?: BadgeStatus | (string & {}) | undefined;
|
|
11
|
+
tone?: BadgeTone | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Badge = forwardRef<HTMLSpanElement, BadgeProps>(function Badge({
|
|
15
|
+
className,
|
|
16
|
+
kind,
|
|
17
|
+
status,
|
|
18
|
+
tone = kind ? 'kind' : status ? 'status' : 'neutral',
|
|
19
|
+
...props
|
|
20
|
+
}, ref) {
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
data-slot="badge"
|
|
24
|
+
{...props}
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={cn('astra-badge', className)}
|
|
27
|
+
data-tone={tone}
|
|
28
|
+
{...(kind ? { 'data-kind': kind } : {})}
|
|
29
|
+
{...(status ? { 'data-status': status } : {})}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
});
|