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
|
|
@ -1,4 +1,4 @@
|
|||
import { useState, type ComponentType, type ReactNode } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
SECTION MANIFEST
|
||||
|
|
@ -33,69 +33,25 @@ import { useState, type ComponentType, type ReactNode } from "react";
|
|||
want them.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
/* What every section Component is handed on top of its own props. */
|
||||
export type SectionInjected = { accent: string; view?: string };
|
||||
|
||||
export type SectionToggleProps = {
|
||||
view: string;
|
||||
setView: (value: string) => void;
|
||||
accent: string;
|
||||
options: string[];
|
||||
};
|
||||
|
||||
export type SectionViews = {
|
||||
options: string[];
|
||||
default?: string;
|
||||
Toggle: ComponentType<SectionToggleProps>;
|
||||
};
|
||||
|
||||
export type SectionHeading = {
|
||||
id: string;
|
||||
title: string;
|
||||
blurb?: string;
|
||||
accent: string;
|
||||
background: string;
|
||||
};
|
||||
|
||||
export type SectionEntry<P extends object = Record<string, unknown>> = SectionHeading & {
|
||||
Component: ComponentType<P & SectionInjected>;
|
||||
/* The Component decides P; props are checked against it. */
|
||||
props?: NoInfer<P>;
|
||||
views?: SectionViews;
|
||||
};
|
||||
|
||||
/* A manifest mixes components with different props, which no single
|
||||
array element type can check. This checks each entry against its
|
||||
own Component where it's written, then forgets P so the entries
|
||||
fit one array. */
|
||||
export function defineSection<P extends object>(entry: SectionEntry<P>): SectionEntry {
|
||||
return entry as unknown as SectionEntry;
|
||||
}
|
||||
|
||||
export type ManifestSection = SectionHeading & {
|
||||
actions?: ReactNode;
|
||||
content: ReactNode;
|
||||
};
|
||||
|
||||
export function useSectionManifest(manifest: SectionEntry[]): ManifestSection[] {
|
||||
export function useSectionManifest(manifest) {
|
||||
// One entry per section that has a toggle, seeded from its
|
||||
// declared default so the control is right before anything loads.
|
||||
const [views, setViews] = useState<Record<string, string | null>>(() =>
|
||||
const [views, setViews] = useState(() =>
|
||||
Object.fromEntries(
|
||||
manifest
|
||||
.filter(entry => entry.views)
|
||||
.map(entry => [
|
||||
entry.id,
|
||||
entry.views?.default ?? entry.views?.options[0] ?? null,
|
||||
entry.views.default ?? entry.views.options?.[0] ?? null,
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
const setView = (id: string, value: string) => setViews(prev => ({ ...prev, [id]: value }));
|
||||
const setView = (id, value) => setViews(prev => ({ ...prev, [id]: value }));
|
||||
|
||||
return manifest.map(entry => {
|
||||
const { Component, props, views: spec, ...heading } = entry;
|
||||
const view = views[entry.id] ?? undefined;
|
||||
const view = views[entry.id];
|
||||
const Toggle = spec?.Toggle;
|
||||
|
||||
return {
|
||||
|
|
@ -103,7 +59,7 @@ export function useSectionManifest(manifest: SectionEntry[]): ManifestSection[]
|
|||
|
||||
actions: Toggle ? (
|
||||
<Toggle
|
||||
view={view ?? ""}
|
||||
view={view}
|
||||
setView={value => setView(entry.id, value)}
|
||||
accent={entry.accent}
|
||||
options={spec.options}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue