Revert the implicit-any typing of src/
Reverts 2428f44. The .d.ts files beside the JS modules and the
annotations threaded through src/ to satisfy noImplicitAny go;
tsconfig turns noImplicitAny off instead. The JS modules become
TypeScript in the next commit, so their types come from inference.
Kept from that commit, since they're runtime fixes rather than types:
- OrganizationDetail's website and email pills get an href and label
(they arrive as bare strings, not link objects).
- The chapter map falls back to FALLBACK_COLOR for a region with no
colour instead of painting its tiles black.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4618ad8e67
commit
5cedc68fd7
38 changed files with 340 additions and 1302 deletions
|
|
@ -4,15 +4,7 @@ import { Link } from "react-router-dom";
|
|||
ARROW LINK
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
type ArrowLinkProps = {
|
||||
to: string;
|
||||
label: string;
|
||||
color: string;
|
||||
/** Tailwind size classes for the circle. */
|
||||
size?: string;
|
||||
};
|
||||
|
||||
export default function ArrowLink({ to, label, color, size = "h-9 w-9" }: ArrowLinkProps) {
|
||||
export default function ArrowLink({ to, label, color, size = "h-9 w-9" }) {
|
||||
return (
|
||||
<Link
|
||||
to={to}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ export default function Layout() {
|
|||
|
||||
const targets = sections
|
||||
.map((s) => document.querySelector(s.hash))
|
||||
.filter((el): el is Element => el !== null);
|
||||
.filter(Boolean);
|
||||
if (targets.length === 0) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
|
|
|
|||
|
|
@ -29,27 +29,9 @@
|
|||
/>
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
const TEAL = "#138ba0";
|
||||
|
||||
export type ShellSection = {
|
||||
id: string;
|
||||
title: string;
|
||||
blurb?: string;
|
||||
accent: string;
|
||||
background: string;
|
||||
actions?: ReactNode;
|
||||
content: ReactNode;
|
||||
};
|
||||
|
||||
type PageShellProps = {
|
||||
title: ReactNode;
|
||||
intro?: ReactNode;
|
||||
sections: ShellSection[];
|
||||
};
|
||||
|
||||
export function Section({ section }: { section: ShellSection }) {
|
||||
export function Section({ section }) {
|
||||
const {
|
||||
id,
|
||||
title,
|
||||
|
|
@ -88,7 +70,7 @@ export function Section({ section }: { section: ShellSection }) {
|
|||
);
|
||||
}
|
||||
|
||||
export default function PageShell({ title, intro, sections }: PageShellProps) {
|
||||
export default function PageShell({ title, intro, sections }) {
|
||||
return (
|
||||
<>
|
||||
{/* Page header */}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ export default function PeopleTiles({
|
|||
|
||||
Promise.all(
|
||||
specs.map((spec) =>
|
||||
get<TeamResponse>(`/teams/${spec.id}/people`, { ttl }).then((data) => ({
|
||||
get(`/teams/${spec.id}/people`, { ttl }).then((data: TeamResponse) => ({
|
||||
spec,
|
||||
data,
|
||||
})),
|
||||
|
|
@ -208,8 +208,8 @@ export default function PeopleTiles({
|
|||
let live = true;
|
||||
setFailed(false);
|
||||
|
||||
get<{ people: Person[] }>(`/people?ids=${encodeURIComponent(slugKey)}`, { ttl })
|
||||
.then((data) => {
|
||||
get(`/people?ids=${encodeURIComponent(slugKey)}`, { ttl })
|
||||
.then((data: { people: Person[] }) => {
|
||||
if (!live) return;
|
||||
const byId: Record<string, Person> = {};
|
||||
for (const person of data.people) byId[String(person.id)] = person;
|
||||
|
|
@ -314,10 +314,11 @@ function resolveAll(
|
|||
}
|
||||
|
||||
const { peopleslug, ...overrides } = entry;
|
||||
const defined: Partial<Person> = Object.fromEntries(
|
||||
Object.entries(overrides).filter(([, value]) => value !== undefined),
|
||||
);
|
||||
resolved.push({ ...base, ...defined });
|
||||
const merged: Person = { ...base };
|
||||
for (const [key, value] of Object.entries(overrides)) {
|
||||
if (value !== undefined) (merged as Record<string, unknown>)[key] = value;
|
||||
}
|
||||
resolved.push(merged);
|
||||
}
|
||||
|
||||
return resolved;
|
||||
|
|
|
|||
|
|
@ -32,16 +32,7 @@
|
|||
able to read and copy.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useRef, useState, type ChangeEvent, type ReactNode } from "react";
|
||||
|
||||
import type { FieldErrors } from "../../lib/api.js";
|
||||
import type {
|
||||
AdminFieldSpec,
|
||||
AdminOption,
|
||||
AdminOptions,
|
||||
AdminRow,
|
||||
CollectionSpec,
|
||||
} from "../../lib/adminSchema.js";
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
const input =
|
||||
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
|
||||
|
|
@ -65,56 +56,37 @@ const inputLocked =
|
|||
|
||||
/* ── Dotted paths ────────────────────────────────────────────── */
|
||||
|
||||
export function getPath(object: unknown, path: string | null | undefined): unknown {
|
||||
export function getPath(object, path) {
|
||||
// An entity with no slug has no heading path either, and a missing
|
||||
// path should read as "no value" rather than throwing on .split.
|
||||
if (!path) return undefined;
|
||||
return path
|
||||
.split(".")
|
||||
.reduce<unknown>((value, key) => (value == null ? undefined : (value as AdminRow)[key]), object);
|
||||
return path.split(".").reduce((value, key) => value?.[key], object);
|
||||
}
|
||||
|
||||
export function setPath(object: AdminRow | null | undefined, path: string, value: unknown): AdminRow {
|
||||
export function setPath(object, path, value) {
|
||||
const [head, ...rest] = path.split(".");
|
||||
if (rest.length === 0) return { ...object, [head]: value };
|
||||
const inner = (object?.[head] ?? {}) as AdminRow;
|
||||
return { ...object, [head]: setPath(inner, rest.join("."), value) };
|
||||
return { ...object, [head]: setPath(object?.[head] ?? {}, rest.join("."), value) };
|
||||
}
|
||||
|
||||
/* ── Field ───────────────────────────────────────────────────── */
|
||||
|
||||
/* [value, label, the option row it came from]. Manifest options
|
||||
have no row, which is what filterBy's `!raw` lets through. */
|
||||
type Choice = [id: string, label: string, raw?: AdminOption];
|
||||
|
||||
type FieldProps = {
|
||||
field: AdminFieldSpec;
|
||||
/* Whatever the row holds at field.path; shown as text. */
|
||||
value: unknown;
|
||||
row?: AdminRow;
|
||||
options?: AdminOptions | null;
|
||||
error?: string;
|
||||
onChange: (value: string | number) => void;
|
||||
};
|
||||
|
||||
export function Field({ field, value, row, options, error, onChange }: FieldProps) {
|
||||
export function Field({ field, value, row, options, error, onChange }) {
|
||||
const id = `f-${field.path.replace(/\./g, "-")}`;
|
||||
const widget = field.widget ?? "text";
|
||||
const locked = Boolean(field.readOnly);
|
||||
const text = value == null ? "" : String(value);
|
||||
|
||||
let list: Choice[] = [];
|
||||
let list = null;
|
||||
let orphaned = false;
|
||||
|
||||
if (widget === "select") {
|
||||
list = field.optionsFrom
|
||||
? (options?.[field.optionsFrom] ?? []).map((o): Choice => [o.id, o.label, o])
|
||||
: (field.options ?? []).map((o): Choice =>
|
||||
typeof o === "string" ? [o, o] : [o[0], o[1]],
|
||||
? (options?.[field.optionsFrom] ?? []).map((o) => [o.id, o.label, o])
|
||||
: (field.options ?? []).map((o) =>
|
||||
Array.isArray(o) ? [o[0], o[1]] : [o, o],
|
||||
);
|
||||
const { filterBy } = field;
|
||||
if (filterBy && row) {
|
||||
list = list.filter(([, , raw]) => !raw || filterBy(raw, row));
|
||||
if (field.filterBy && row) {
|
||||
list = list.filter(([, , raw]) => !raw || field.filterBy(raw, row));
|
||||
}
|
||||
|
||||
// A stored value with no matching option renders as the blank
|
||||
|
|
@ -130,9 +102,8 @@ export function Field({ field, value, row, options, error, onChange }: FieldProp
|
|||
const common = {
|
||||
id,
|
||||
className: `${input} ${error ? inputError : ""}`,
|
||||
value: text,
|
||||
onChange: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) =>
|
||||
onChange(e.target.value),
|
||||
value: value ?? "",
|
||||
onChange: (e) => onChange(e.target.value),
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -174,7 +145,7 @@ export function Field({ field, value, row, options, error, onChange }: FieldProp
|
|||
}`}
|
||||
>
|
||||
<option value="">{field.blankLabel ?? "— choose —"}</option>
|
||||
{orphaned && <option value={text}>{text} — no longer exists</option>}
|
||||
{orphaned && <option value={value}>{value} — no longer exists</option>}
|
||||
{list.map(([id2, label]) => (
|
||||
<option key={id2} value={id2}>
|
||||
{label}
|
||||
|
|
@ -185,7 +156,7 @@ export function Field({ field, value, row, options, error, onChange }: FieldProp
|
|||
<div className="flex gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={/^#[0-9a-f]{6}$/i.test(text) ? text : "#138ba0"}
|
||||
value={/^#[0-9a-f]{6}$/i.test(value ?? "") ? value : "#138ba0"}
|
||||
disabled={locked}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="h-9 w-12 shrink-0 rounded border border-[#4a6b72]/25 bg-white disabled:opacity-50"
|
||||
|
|
@ -217,7 +188,7 @@ export function Field({ field, value, row, options, error, onChange }: FieldProp
|
|||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
value={text}
|
||||
value={value ?? ""}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={field.placeholder}
|
||||
className="w-full border-0 bg-transparent p-0 text-[#26454c] outline-none placeholder:text-[#4a6b72]/45"
|
||||
|
|
@ -253,36 +224,26 @@ export function Field({ field, value, row, options, error, onChange }: FieldProp
|
|||
);
|
||||
}
|
||||
|
||||
export function FieldGrid({ children }: { children: ReactNode }) {
|
||||
export function FieldGrid({ children }) {
|
||||
return <div className="grid gap-4 sm:grid-cols-2">{children}</div>;
|
||||
}
|
||||
|
||||
/* ── Repeater ────────────────────────────────────────────────── */
|
||||
|
||||
type RepeaterProps = {
|
||||
spec: CollectionSpec;
|
||||
rows: AdminRow[] | null | undefined;
|
||||
options?: AdminOptions | null;
|
||||
errors?: Partial<FieldErrors> | null;
|
||||
/** Where this collection's rows sit in the server's error keys. */
|
||||
errorPrefix: string;
|
||||
onChange: (rows: AdminRow[]) => void;
|
||||
};
|
||||
|
||||
export function Repeater({ spec, rows, options, errors, errorPrefix, onChange }: RepeaterProps) {
|
||||
export function Repeater({ spec, rows, options, errors, errorPrefix, onChange }) {
|
||||
const list = rows ?? [];
|
||||
|
||||
// Which row is in flight, and which one it's currently over.
|
||||
// Both are per-Repeater, which is what keeps a drag inside a
|
||||
// nested collection from being accepted by the outer one.
|
||||
const [dragIndex, setDragIndex] = useState<number | null>(null);
|
||||
const [overIndex, setOverIndex] = useState<number | null>(null);
|
||||
const rowRefs = useRef<Array<HTMLDivElement | null>>([]);
|
||||
const [dragIndex, setDragIndex] = useState(null);
|
||||
const [overIndex, setOverIndex] = useState(null);
|
||||
const rowRefs = useRef([]);
|
||||
|
||||
const update = (index: number, next: AdminRow) =>
|
||||
const update = (index, next) =>
|
||||
onChange(list.map((row, i) => (i === index ? next : row)));
|
||||
|
||||
const move = (index: number, delta: number) => {
|
||||
const move = (index, delta) => {
|
||||
const target = index + delta;
|
||||
if (target < 0 || target >= list.length) return;
|
||||
const next = [...list];
|
||||
|
|
@ -290,7 +251,7 @@ export function Repeater({ spec, rows, options, errors, errorPrefix, onChange }:
|
|||
onChange(next);
|
||||
};
|
||||
|
||||
const relocate = (from: number | null, to: number | null) => {
|
||||
const relocate = (from, to) => {
|
||||
if (from === to || from == null || to == null) return;
|
||||
const next = [...list];
|
||||
const [moved] = next.splice(from, 1);
|
||||
|
|
@ -423,7 +384,7 @@ export function Repeater({ spec, rows, options, errors, errorPrefix, onChange }:
|
|||
<div key={nested.key} className="mt-4 border-t border-[#4a6b72]/15 pt-2">
|
||||
<Repeater
|
||||
spec={nested}
|
||||
rows={row[nested.key] as AdminRow[] | undefined}
|
||||
rows={row[nested.key]}
|
||||
options={options}
|
||||
errors={errors}
|
||||
errorPrefix={`${errorPrefix}${index}.${nested.key}.`}
|
||||
|
|
@ -439,15 +400,7 @@ export function Repeater({ spec, rows, options, errors, errorPrefix, onChange }:
|
|||
);
|
||||
}
|
||||
|
||||
type IconButtonProps = {
|
||||
label: string;
|
||||
onClick: () => void;
|
||||
danger?: boolean;
|
||||
disabled?: boolean;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
function IconButton({ label, onClick, danger, disabled, children }: IconButtonProps) {
|
||||
function IconButton({ label, onClick, danger, disabled, children }) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue