Initial revision

This commit is contained in:
Adrian Rumpold
2025-05-21 09:20:41 +02:00
commit dfd89fbf26
23 changed files with 4260 additions and 0 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

54
README.md Normal file
View File

@@ -0,0 +1,54 @@
# React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
```js
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
```

28
eslint.config.js Normal file
View File

@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)

13
index.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NIST AI Glossary Browser</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

3689
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

34
package.json Normal file
View File

@@ -0,0 +1,34 @@
{
"name": "nist-ai-glossary-browser",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.76.1",
"@tanstack/react-query-devtools": "^5.76.1",
"axios": "^1.9.0",
"papaparse": "^5.5.3",
"react": "^19.1.0",
"react-dom": "^19.1.0"
},
"devDependencies": {
"@eslint/js": "^9.25.0",
"@types/papaparse": "^5.3.16",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@vitejs/plugin-react": "^4.4.1",
"eslint": "^9.25.0",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.19",
"globals": "^16.0.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5"
}
}

1
public/vite.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

45
src/App.tsx Normal file
View File

@@ -0,0 +1,45 @@
import { useState } from "react";
import AlphabeticalFilter from "./components/AlphabeticalFilter/AlphabeticalFilter";
import GlossaryEntry from "./components/GlossaryEntry/GlossaryEntry";
import StringFilter from "./components/StringFilter/StringFilter";
import useGlossary from "./hooks/useGlossary";
function App() {
const { data: glossary, error, isPending } = useGlossary();
const [alphabeticalFilter, setAlphabeticalFilter] = useState("");
const [stringFilter, setStringFilter] = useState("");
if (isPending) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
const entries = glossary?.definitions
.filter((entry) => {
if (!stringFilter) {
return true;
}
return entry.term.toLowerCase().includes(stringFilter.toLowerCase());
})
.filter((entry) => {
if (!alphabeticalFilter) {
return true;
}
return entry.term
.toLowerCase()
.startsWith(alphabeticalFilter.toLowerCase());
});
return (
<div>
<StringFilter onChange={setStringFilter} />
<AlphabeticalFilter onChange={setAlphabeticalFilter} />
{entries.length} entries found
<dl>
{entries.map((term) => (
<GlossaryEntry term={term} key={term.term} />
))}
</dl>
</div>
);
}
export default App;

View File

@@ -0,0 +1,18 @@
.alphabetical-filter {
display: flex;
flex-flow: row wrap;
align-items: center;
gap: 1ch;
button {
display: flex;
justify-content: center;
align-items: center;
width: 2rem;
height: 2rem;
padding: 0;
}
.selected {
background-color: var(--color-accent);
}
}

View File

@@ -0,0 +1,39 @@
import { useState } from "react";
import "./AlphabeticalFilter.css";
type AlphabeticalFilterProps = {
onChange: (value: string) => void;
};
function AlphabeticalFilter({ onChange }: AlphabeticalFilterProps) {
const [selectedLetter, setSelectedLetter] = useState<string | null>(null);
const letters = Array.from({ length: 26 }, (_, i) =>
String.fromCharCode(65 + i)
);
const handleClick = (letter: string) => {
if (selectedLetter === letter) {
setSelectedLetter(null);
onChange("");
return;
}
setSelectedLetter(letter);
onChange(letter);
};
const buttons = letters.map((letter) => (
<button
onClick={() => handleClick(letter)}
key={letter}
className={[
"alphabetical-filter-button",
selectedLetter === letter ? "selected" : "",
].join(" ")}
>
{letter}
</button>
));
return <div className="alphabetical-filter">{buttons}</div>;
}
export default AlphabeticalFilter;

View File

@@ -0,0 +1,21 @@
dt {
font-weight: bold;
}
dd {
max-width: 64ch;
}
dd + dd {
margin-top: 1rem;
border-top: 1px solid var(--color-border);
padding-top: 1rem;
}
dd + dt {
margin-top: 2rem;
}
dt + dd {
margin-top: 1rem;
}

View File

@@ -0,0 +1,18 @@
import type { GlossaryTerm } from "../../lib/nist-api";
import "./GlossaryEntry.css";
type GlossaryEntryProps = {
term: GlossaryTerm;
};
function GlossaryEntry({ term }: GlossaryEntryProps) {
return (
<>
<dt key={term.term}>{term.term}</dt>
{term.definitions.map((def, index) => (
<dd key={term.term + index}>{def.definition}</dd>
))}
</>
);
}
export default GlossaryEntry;

View File

@@ -0,0 +1,21 @@
import { useState } from "react";
function StringFilter({ onChange }: { onChange: (value: string) => void }) {
const [inputValue, setInputValue] = useState("");
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue = event.target.value;
setInputValue(newValue);
onChange(newValue);
};
return (
<input
type="text"
value={inputValue}
onChange={handleChange}
placeholder="Type to filter..."
/>
);
}
export default StringFilter;

10
src/hooks/useGlossary.ts Normal file
View File

@@ -0,0 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import { fetchGlossary } from "../lib/nist-api";
const useGlossary = () =>
useQuery({
queryKey: ["glossary"],
queryFn: fetchGlossary,
staleTime: 5 * 60 * 1000, // 5 minutes
});
export default useGlossary;

60
src/index.css Normal file
View File

@@ -0,0 +1,60 @@
@import "theme.css";
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
background-color: var(--color-background);
color: var(--color-text);
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: var(--color-accent);
text-decoration: inherit;
}
a:hover {
color: var(--color-accent-hover);
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
#root {
display: flex;
flex-direction: column;
place-items: center;
width: 100%;
padding: 2rem;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: var(--color-accent-hover);
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

83
src/lib/nist-api.ts Normal file
View File

@@ -0,0 +1,83 @@
import { Axios } from "axios";
import Papa from "papaparse";
export type Definition = {
definition: string;
citationKey: string;
};
export type Citation = {
key: string;
title: string;
authors: string;
publication: string;
volume?: string;
issue?: string;
pages?: string;
year: string;
url: string;
};
export type GlossaryTerm = {
term: string;
definitions: Definition[];
relatedTerms: string;
legalDefinition: string;
};
export type Glossary = {
definitions: GlossaryTerm[];
citations: Citation[];
};
const glossaryUrl =
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTRBYglcOtgaMrdF11aFxfEY3EmB31zslYI4q2_7ZZ8z_1lKm7OHtF0t4xIsckuogNZ3hRZAaDQuv_K/pub?output=csv";
export const fetchGlossary = async () => {
const resp = await new Axios().get(glossaryUrl);
const data = resp.data;
return parseGlossary(data);
};
const parseGlossary = (data: string): Glossary => {
const parsed = Papa.parse<string[]>(data, {
delimiter: ",",
header: false,
dynamicTyping: true,
skipEmptyLines: true,
});
const glossary: Glossary = { definitions: [], citations: [] };
for (const record of parsed.data.slice(1)) {
const fields = record.map((field) =>
field !== null ? field.trim() : field
);
const term = fields[0];
const definitions: Definition[] = [];
for (let f = 1; f < fields.length - 2; f += 2) {
const def = fields[f];
const cit = fields[f + 1];
if (def && cit) {
definitions.push({
definition: def,
citationKey: cit,
});
}
}
const relatedTerms = fields[fields.length - 2];
const legalDefinition = fields[fields.length - 1];
if (term && definitions.length > 0) {
glossary.definitions.push({
term,
definitions,
relatedTerms,
legalDefinition,
});
}
}
return glossary;
};

16
src/main.tsx Normal file
View File

@@ -0,0 +1,16 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
const queryClient = new QueryClient();
createRoot(document.getElementById("root")!).render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<App />
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</StrictMode>
);

19
src/theme.css Normal file
View File

@@ -0,0 +1,19 @@
:root {
color: rgba(255, 255, 255, 0.87);
--color-background: #242424;
--color-text: #ffffff;
--color-accent: #646cff;
--color-accent-hover: #535bf2;
--color-border: #444444;
}
@media (prefers-color-scheme: light) {
:root {
--color-background: #ffffff;
--color-text: #213547;
--color-accent: #747bff;
--color-accent-hover: #646cff;
--color-border: #d9d9d9;
}
}

1
src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1 @@
/// <reference types="vite/client" />

27
tsconfig.app.json Normal file
View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}

7
tsconfig.json Normal file
View File

@@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

25
tsconfig.node.json Normal file
View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}

7
vite.config.ts Normal file
View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
})