Found by reviewing the plugin rather than running it. Nothing was live — the table does not exist and the plugin is not installed — so all of these were waiting for the first person to use it. ── The second unnamed design could not be saved ── `uniqueIndex(userId, title)`, and every design starts life called "Untitled": `titleOf` returns it for a document with no title and the API defaults to it. So the first saved, the second collided, and the insert threw under a panel that could only say "Changes are not being saved." Renaming one design to match another did the same. Two designs may share a name, as files and notes and dashboards do. Nothing looks a design up by title, so uniqueness bought nothing. The index is now ordinary and on the columns the list query actually uses. The lesson from `dashboards.id` that the schema comment cites is that a key must be scoped to its owner. `userId` on the row does that; making the pair unique as well imported the collision it was citing, one account at a time. ── New did not start a new design ── It cleared `?doc=`, and no parameter already means "open what I had last", answered with `/documents/latest`. So New handed back the design on screen and pointed the next save at its id. There is a `new` sentinel now, in its own module because both panels read it and neither owns it. ── Two ways the load effect raced the debounced save ── Changing `?doc=` does not unmount the panel, so the unmount flush never ran for it: an edit made within the debounce and navigated away from was written after `latest.current` had been replaced, which is to say never. And the first save of a new design puts its id in the URL, which lands in the same effect — re-reading the row overwrote in-memory state with the copy the server had just been given, discarding whatever was drawn during the round trip. The effect now flushes what is pending before it reads, and does not re-read a document it already holds. The editor is keyed on a load generation rather than on `row?.id`, which could not express "blank again" and left the previous design on screen with `rowId` cleared underneath it. ── The typecheck ── 354 of the 355 errors were upstream's tree measured against this platform's settings, which it was never written for. `bunx tsgo` is how this repo is kept clean and it could not be clean while this plugin existed. `exclude` does not help: adapter.ts imports the tree back in. So vendor.sh marks each vendored file unchecked in the same deterministic pass that rewrites its imports. Types still resolve; only the errors inside those files are silenced, which is what the adapter already says the seam is for. Whole repo: 0. ── PROVENANCE.md understated what is done to the copy ── It said "the one edit vendor.sh makes" and described the import rewrite. It also runs apply-host.py, which places our own lib/host.ts and wires three export paths. Four files are not upstream and the document whose job is making the copy trustworthy did not say so. It lists all four now. Also: web/host.ts imported a path only correct at its destination, so the file could never typecheck where it is edited — apply-host.py rewrites that line when placing it, and re-marks the placed copy, which it overwrites after vendor.sh has marked it. PUT is no longer full-replace: omitting `title` renamed a design to "Untitled" and omitting `ui` nulled it, a trap set for the second caller. And a document is bounded at 4 MB, measured in bytes, where the title was capped at 200 and the document at nothing.
125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
// @ts-nocheck — vendored, see PROVENANCE.md
|
|
"use client";
|
|
|
|
import { useMemo, useState } from "react";
|
|
import { CATEGORIES, KIND_ORDER, KIND_SPEC, Category, Kind, Palette } from "../lib/tokens";
|
|
import { Icon } from "./M3Node";
|
|
import { KIND_TEXT, t, useLang } from "../lib/i18n";
|
|
import { Field, Section, Tile } from "./ui";
|
|
|
|
const CATEGORY_TEXT = {
|
|
ja: { actions: "操作", navigation: "ナビゲーション", containment: "コンテナ", inputs: "入力", content: "コンテンツ", progress: "進捗" },
|
|
zh: { actions: "操作", navigation: "导航", containment: "容器", inputs: "输入", content: "内容", progress: "进度" },
|
|
ko: { actions: "동작", navigation: "내비게이션", containment: "컨테이너", inputs: "입력", content: "콘텐츠", progress: "진행 상태" },
|
|
} satisfies Record<string, Record<Category, string>>;
|
|
|
|
export function PartsPalette({
|
|
palette: p,
|
|
favorites,
|
|
onToggleFavorite,
|
|
onPartPointerDown,
|
|
overBin,
|
|
}: {
|
|
palette: Palette;
|
|
favorites: Kind[];
|
|
onToggleFavorite: (k: Kind) => void;
|
|
onPartPointerDown: (e: React.PointerEvent, kind: Kind) => void;
|
|
overBin: boolean;
|
|
}) {
|
|
const lang = useLang();
|
|
const [q, setQ] = useState("");
|
|
const labelOf = (k: Kind) => lang === "en" ? KIND_SPEC[k].label : KIND_TEXT[lang][k]?.noun ?? KIND_SPEC[k].label;
|
|
|
|
const filtered = useMemo(() => {
|
|
const s = q.trim().toLowerCase();
|
|
if (!s) return KIND_ORDER;
|
|
return KIND_ORDER.filter((k) => {
|
|
const sp = KIND_SPEC[k];
|
|
return labelOf(k).toLowerCase().includes(s) || sp.label.toLowerCase().includes(s) || sp.noun.includes(s) || k.toLowerCase().includes(s);
|
|
});
|
|
}, [q, lang]);
|
|
|
|
const tile = (k: Kind) => {
|
|
const s = KIND_SPEC[k];
|
|
return (
|
|
<Tile
|
|
key={k}
|
|
icon={s.paletteIcon}
|
|
label={labelOf(k)}
|
|
p={p}
|
|
onPointerDown={(e) => onPartPointerDown(e, k)}
|
|
starred={favorites.includes(k)}
|
|
onStar={() => onToggleFavorite(k)}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const grid: React.CSSProperties = {
|
|
display: "grid",
|
|
gridTemplateColumns: "repeat(auto-fill, minmax(78px, 1fr))",
|
|
gap: 6,
|
|
};
|
|
|
|
return (
|
|
<div style={{ display: "flex", flexDirection: "column", height: "100%", position: "relative" }}>
|
|
<div style={{ padding: "12px 12px 8px" }}>
|
|
<Field value={q} onChange={setQ} placeholder={t("search", lang)} p={p} icon="search" height={40} />
|
|
</div>
|
|
|
|
<div className="no-scrollbar" style={{ flex: 1, overflowY: "auto", overflowX: "hidden", padding: "0 8px" }}>
|
|
{!q && favorites.length > 0 && (
|
|
<Section id="fav" icon="star" title={t("favorites", lang)} p={p}>
|
|
<div style={grid}>{favorites.filter((k) => KIND_SPEC[k]).map(tile)}</div>
|
|
</Section>
|
|
)}
|
|
{q ? (
|
|
<div style={{ ...grid, padding: "4px 4px 12px" }}>
|
|
{filtered.map(tile)}
|
|
{filtered.length === 0 && (
|
|
<div style={{ gridColumn: "1 / -1", color: p.outline, fontSize: 13, padding: 12, textAlign: "center" }}>
|
|
<Icon name="search_off" size={28} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
) : (
|
|
CATEGORIES.map((c) => (
|
|
<Section key={c.key} id={`cat:${c.key}`} icon={c.icon} title={lang === "en" ? c.label : CATEGORY_TEXT[lang][c.key]} p={p}>
|
|
<div style={grid}>{KIND_ORDER.filter((k) => KIND_SPEC[k].category === c.key).map(tile)}</div>
|
|
</Section>
|
|
))
|
|
)}
|
|
</div>
|
|
|
|
{overBin && (
|
|
<div
|
|
style={{
|
|
position: "absolute",
|
|
inset: 0,
|
|
background: "rgba(179,38,30,0.10)",
|
|
display: "grid",
|
|
placeItems: "center",
|
|
pointerEvents: "none",
|
|
color: p.error,
|
|
borderRadius: "inherit",
|
|
}}
|
|
>
|
|
<div
|
|
style={{
|
|
width: 72,
|
|
height: 72,
|
|
borderRadius: 36,
|
|
background: p.errorContainer,
|
|
color: p.onErrorContainer,
|
|
display: "grid",
|
|
placeItems: "center",
|
|
boxShadow: "0 4px 14px rgba(0,0,0,0.14)",
|
|
}}
|
|
>
|
|
<Icon name="delete" size={34} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|