SPB Git

Repository Public

helpers.ts 25.3 KB 412 lines typescript

1/**2 * Pure helpers of the block forms: list moves, spreadsheet paste parsing, rectangular grids, and the edits that must3 * keep a block valid as a whole (table / comparison / matrix columns, diagram node deletion, chart points, datasets,4 * simulation parameters). No React, no DOM.5 */6import type { z } from "zod";7import { TONES, type BlockOf, type Locale, type SimKind, type Tone } from "@/schema";8import { paramDefs, SIMULATIONS, snapParam, validateSimulation } from "@/sim/registry";910// ── Lists ───────────────────────────────────────────────────────────────────────────────────────────1112/** Moves one item by `delta` places; out-of-range moves return an unchanged copy. */13export function moveItem<T>(list: readonly T[], index: number, delta: number): T[] {14  const out = [...list];15  const to = index + delta;16  if (index < 0 || index >= out.length || to < 0 || to >= out.length) return out;17  const [x] = out.splice(index, 1);18  out.splice(to, 0, x);19  return out;20}21export const removeItem = <T>(list: readonly T[], index: number): T[] => list.filter((_, i) => i !== index);22export const replaceItem = <T>(list: readonly T[], index: number, item: T): T[] => list.map((x, i) => (i === index ? item : x));2324/** "" → undefined: optional strings are removed from the block rather than stored empty. */25export const optional = (s: string): string | undefined => (s.trim() === "" ? undefined : s);2627// ── Paste parsing ───────────────────────────────────────────────────────────────────────────────────2829/** Tab (spreadsheet copy) wins, then semicolon (French CSV), then comma. */30export function detectDelimiter(text: string): "\t" | ";" | "," {31  if (text.includes("\t")) return "\t";32  if (text.includes(";")) return ";";33  return ",";34}3536/** True when a clipboard text is clearly a block of cells (several columns or several lines), not a word or a sentence. */37export const looksLikeGrid = (text: string): boolean => text.includes("\t") || /\n/.test(text.replace(/\r\n?/g, "\n").trim());3839/**40 * Tab-, semicolon- or comma-separated text → rows of trimmed cells. Double-quoted cells may contain the delimiter,41 * line breaks and doubled quotes. Trailing empty lines are dropped; rows are not padded (see `rectangular`).42 */43export function parseDelimited(text: string): string[][] {44  const src = text.replace(/\r\n?/g, "\n");45  const d = detectDelimiter(src);46  const rows: string[][] = [];47  let row: string[] = [], cell = "", quoted = false, wasQuoted = false;48  const endCell = () => { row.push(wasQuoted ? cell : cell.trim()); cell = ""; wasQuoted = false; };49  for (let i = 0; i < src.length; i++) {50    const ch = src[i];51    if (quoted) {52      if (ch === '"') { if (src[i + 1] === '"') { cell += '"'; i++; } else quoted = false; }53      else cell += ch;54    } else if (ch === '"' && cell.trim() === "") { quoted = true; wasQuoted = true; cell = ""; }55    else if (ch === d) endCell();56    else if (ch === "\n") { endCell(); rows.push(row); row = []; }57    else cell += ch;58  }59  endCell();60  rows.push(row);61  while (rows.length > 0 && rows[rows.length - 1].every((c) => c === "")) rows.pop();62  return rows;63}6465/** A number as typed or pasted: decimal comma, thin or non-breaking spaces, thousands separators, a trailing %. */66export function parseNumber(text: string): number | null {67  let s = text.trim().replace(/[\s  ]/g, "").replace(/−/g, "-").replace(/%$/, "");68  if (s === "") return null;69  if (/^[-+]?\d{1,3}(,\d{3})+(\.\d+)?$/.test(s)) s = s.replace(/,/g, "");70  else if (s.includes(",") && !s.includes(".")) s = s.replace(",", ".");71  if (!/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(s)) return null;72  const n = Number(s);73  return Number.isFinite(n) ? n : null;74}7576/** Shortest text that reads back as the same number. */77export const numberText = (n: number): string => String(Number(n.toPrecision(12)));7879// ── Rectangular grids ───────────────────────────────────────────────────────────────────────────────8081/** Every row cut or padded to `cols` cells; at least `minRows` rows. */82export function rectangular<T>(rows: readonly (readonly T[])[], cols: number, fill: T, minRows = 1): T[][] {83  const out = rows.map((r) => Array.from({ length: cols }, (_, i) => (i < r.length ? r[i] : fill)));84  while (out.length < minRows) out.push(Array.from({ length: cols }, () => fill));85  return out;86}8788export interface PasteResult { grid: string[][]; droppedRows: number; droppedCols: number }8990/**91 * Writes `data` into a rectangular grid from the cell `at`, growing the grid up to the limits. The result is92 * rectangular; what did not fit is counted.93 */94export function pasteCells(grid: readonly (readonly string[])[], at: { row: number; col: number }, data: readonly (readonly string[])[], limits: { maxRows: number; maxCols: number; growCols?: boolean; maxCell?: number }): PasteResult {95  const cols0 = grid[0]?.length ?? 0;96  const width = data.reduce((m, r) => Math.max(m, r.length), 0);97  const cols = limits.growCols ? Math.min(limits.maxCols, Math.max(cols0, at.col + width)) : cols0;98  const rowsN = Math.min(limits.maxRows, Math.max(grid.length, at.row + data.length));99  const out = rectangular(grid, cols, "", rowsN).slice(0, rowsN);100  data.forEach((r, i) => r.forEach((c, j) => {101    const R = at.row + i, C = at.col + j;102    if (R < rowsN && C < cols) out[R][C] = limits.maxCell ? c.slice(0, limits.maxCell) : c;103  }));104  return { grid: out, droppedRows: Math.max(0, at.row + data.length - rowsN), droppedCols: Math.max(0, at.col + width - cols) };105}106107// ── Table ───────────────────────────────────────────────────────────────────────────────────────────108109type TableBlock = BlockOf<"table">;110export const TABLE_MAX = { rows: 40, cols: 8, cell: 600 } as const;111112export function tableAddColumn(b: TableBlock, label: string): TableBlock {113  if (b.columns.length >= TABLE_MAX.cols) return b;114  return { ...b, columns: [...b.columns, { label, align: "left" }], rows: b.rows.map((r) => [...r, ""]) };115}116export function tableRemoveColumn(b: TableBlock, index: number): TableBlock {117  if (b.columns.length <= 1) return b;118  return { ...b, columns: removeItem(b.columns, index), rows: b.rows.map((r) => removeItem(r, index)) };119}120export function tableMoveColumn(b: TableBlock, index: number, delta: number): TableBlock {121  return { ...b, columns: moveItem(b.columns, index, delta), rows: b.rows.map((r) => moveItem(r, index, delta)) };122}123export function tableAddRow(b: TableBlock): TableBlock {124  if (b.rows.length >= TABLE_MAX.rows) return b;125  return { ...b, rows: [...b.rows, b.columns.map(() => "")] };126}127export function tableRemoveRow(b: TableBlock, index: number): TableBlock {128  return b.rows.length <= 1 ? b : { ...b, rows: removeItem(b.rows, index) };129}130/** Paste into the body of a table: rows and columns grow up to the schema limits, new columns get `columnLabel(n)`. */131export function tablePaste(b: TableBlock, at: { row: number; col: number }, data: readonly (readonly string[])[], columnLabel: (n: number) => string): { block: TableBlock; droppedRows: number; droppedCols: number } {132  const base = rectangular(b.rows, b.columns.length, "");133  const r = pasteCells(base, at, data, { maxRows: TABLE_MAX.rows, maxCols: TABLE_MAX.cols, growCols: true, maxCell: TABLE_MAX.cell });134  const cols = r.grid[0]?.length ?? b.columns.length;135  const columns = [...b.columns];136  while (columns.length < cols) columns.push({ label: columnLabel(columns.length + 1), align: "left" });137  return { block: { ...b, columns, rows: r.grid }, droppedRows: r.droppedRows, droppedCols: r.droppedCols };138}139140// ── Comparison ──────────────────────────────────────────────────────────────────────────────────────141142type ComparisonBlock = BlockOf<"comparison">;143export function comparisonAddColumn(b: ComparisonBlock, title: string): ComparisonBlock {144  if (b.columns.length >= 4) return b;145  return { ...b, columns: [...b.columns, { title, tone: "neutral" }], rows: b.rows.map((r) => ({ ...r, cells: [...r.cells, ""] })) };146}147export function comparisonRemoveColumn(b: ComparisonBlock, index: number): ComparisonBlock {148  if (b.columns.length <= 2) return b;149  return { ...b, columns: removeItem(b.columns, index), rows: b.rows.map((r) => ({ ...r, cells: removeItem(r.cells, index) })) };150}151export function comparisonMoveColumn(b: ComparisonBlock, index: number, delta: number): ComparisonBlock {152  return { ...b, columns: moveItem(b.columns, index, delta), rows: b.rows.map((r) => ({ ...r, cells: moveItem(r.cells, index, delta) })) };153}154155// ── Matrix ──────────────────────────────────────────────────────────────────────────────────────────156157type MatrixBlock = BlockOf<"matrix">;158export const MATRIX_MAX = 16;159160export function matrixAddRow(b: MatrixBlock, label: string): MatrixBlock {161  if (b.rowLabels.length >= MATRIX_MAX) return b;162  return { ...b, rowLabels: [...b.rowLabels, label], values: [...rectangular(b.values, b.colLabels.length, 0, b.rowLabels.length), b.colLabels.map(() => 0)] };163}164export function matrixRemoveRow(b: MatrixBlock, index: number): MatrixBlock {165  if (b.rowLabels.length <= 1) return b;166  return { ...b, rowLabels: removeItem(b.rowLabels, index), values: removeItem(b.values, index) };167}168export function matrixMoveRow(b: MatrixBlock, index: number, delta: number): MatrixBlock {169  return { ...b, rowLabels: moveItem(b.rowLabels, index, delta), values: moveItem(b.values, index, delta) };170}171export function matrixAddColumn(b: MatrixBlock, label: string): MatrixBlock {172  if (b.colLabels.length >= MATRIX_MAX) return b;173  return { ...b, colLabels: [...b.colLabels, label], values: b.values.map((r) => [...r, 0]) };174}175export function matrixRemoveColumn(b: MatrixBlock, index: number): MatrixBlock {176  if (b.colLabels.length <= 1) return b;177  return { ...b, colLabels: removeItem(b.colLabels, index), values: b.values.map((r) => removeItem(r, index)) };178}179export function matrixMoveColumn(b: MatrixBlock, index: number, delta: number): MatrixBlock {180  return { ...b, colLabels: moveItem(b.colLabels, index, delta), values: b.values.map((r) => moveItem(r, index, delta)) };181}182/** Paste numbers into a matrix: it grows up to 16 × 16 (labels `rowLabel(n)` / `colLabel(n)`); cells that are not numbers are left as they were. */183export function matrixPaste(b: MatrixBlock, at: { row: number; col: number }, data: readonly (readonly string[])[], rowLabel: (n: number) => string, colLabel: (n: number) => string): { block: MatrixBlock; droppedRows: number; droppedCols: number; invalid: number } {184  const width = data.reduce((m, r) => Math.max(m, r.length), 0);185  const cols = Math.min(MATRIX_MAX, Math.max(b.colLabels.length, at.col + width));186  const rowsN = Math.min(MATRIX_MAX, Math.max(b.rowLabels.length, at.row + data.length));187  const values = rectangular(b.values, cols, 0, rowsN).slice(0, rowsN);188  let invalid = 0;189  data.forEach((r, i) => r.forEach((c, j) => {190    const R = at.row + i, C = at.col + j;191    if (R >= rowsN || C >= cols) return;192    const n = parseNumber(c);193    if (n === null) { if (c !== "") invalid++; } else values[R][C] = n;194  }));195  const rowLabels = [...b.rowLabels], colLabels = [...b.colLabels];196  while (rowLabels.length < rowsN) rowLabels.push(rowLabel(rowLabels.length + 1));197  while (colLabels.length < cols) colLabels.push(colLabel(colLabels.length + 1));198  return { block: { ...b, rowLabels, colLabels, values }, droppedRows: Math.max(0, at.row + data.length - rowsN), droppedCols: Math.max(0, at.col + width - cols), invalid };199}200201// ── Diagram ─────────────────────────────────────────────────────────────────────────────────────────202203type DiagramBlock = BlockOf<"diagram">;204205const cleanSteps = (d: DiagramBlock, nodes: ReadonlySet<string>, edges: ReadonlySet<string>): DiagramBlock["animation"] =>206  d.animation && { steps: d.animation.steps.map((s) => ({ ...s, nodes: s.nodes.filter((n) => nodes.has(n)), edges: s.edges.filter((e) => edges.has(e)) })) };207208/** Removes a node, the edges that touch it, and every mention of both in the animation steps. The last node stays. */209export function removeDiagramNode(d: DiagramBlock, nodeId: string): DiagramBlock {210  if (d.nodes.length <= 1 || !d.nodes.some((n) => n.id === nodeId)) return d;211  const nodes = d.nodes.filter((n) => n.id !== nodeId);212  const edges = d.edges.filter((e) => e.from !== nodeId && e.to !== nodeId);213  const next: DiagramBlock = { ...d, nodes, edges };214  const animation = cleanSteps(d, new Set(nodes.map((n) => n.id)), new Set(edges.map((e) => e.id)));215  if (animation) next.animation = animation;216  return next;217}218/** Removes an edge and its mentions in the animation steps. */219export function removeDiagramEdge(d: DiagramBlock, edgeId: string): DiagramBlock {220  const edges = d.edges.filter((e) => e.id !== edgeId);221  const next: DiagramBlock = { ...d, edges };222  const animation = cleanSteps(d, new Set(d.nodes.map((n) => n.id)), new Set(edges.map((e) => e.id)));223  if (animation) next.animation = animation;224  return next;225}226/** Removes a group; its nodes stay and simply leave the group. */227export function removeDiagramGroup(d: DiagramBlock, groupId: string): DiagramBlock {228  return {229    ...d,230    groups: d.groups.filter((g) => g.id !== groupId),231    nodes: d.nodes.map((n) => { if (n.group !== groupId) return n; const { group: _group, ...rest } = n; void _group; return rest; }),232  };233}234235// ── Chart ───────────────────────────────────────────────────────────────────────────────────────────236237type ChartBlock = BlockOf<"chart">;238export type ChartSeries = ChartBlock["series"][number];239export type ChartPoint = ChartSeries["points"][number];240export const CHART_MAX_POINTS = 600;241export const CHART_MAX_SERIES = 8;242const SERIES_TONES: Tone[] = ["blue", "amber", "teal", "violet", "red", "green", "pink", "neutral"];243export const seriesTone = (index: number): Tone => SERIES_TONES[index % SERIES_TONES.length] ?? TONES[0];244245/** Points as the text grid `x | y | lo | hi`. */246export const pointsToGrid = (points: readonly ChartPoint[]): string[][] =>247  points.map((p) => [typeof p.x === "number" ? numberText(p.x) : p.x, numberText(p.y), p.lo === undefined ? "" : numberText(p.lo), p.hi === undefined ? "" : numberText(p.hi)]);248249/** One grid row → a point, or null when x (numeric axis) or y is not a number. Empty lo / hi are simply absent. */250export function rowToPoint(row: readonly string[], xType: "number" | "category"): ChartPoint | null {251  const y = parseNumber(row[1] ?? "");252  if (y === null) return null;253  const xText = (row[0] ?? "").trim();254  let x: number | string;255  if (xType === "number") { const n = parseNumber(xText); if (n === null) return null; x = n; } else x = xText.slice(0, 60);256  const point: ChartPoint = { x, y };257  const lo = parseNumber(row[2] ?? ""), hi = parseNumber(row[3] ?? "");258  if (lo !== null) point.lo = lo;259  if (hi !== null) point.hi = hi;260  return point;261}262263/** A text grid → points (at most 600). Blank lines are ignored; unreadable lines and lines past the limit are counted. */264export function gridToPoints(rows: readonly (readonly string[])[], xType: "number" | "category"): { points: ChartPoint[]; skipped: number; dropped: number } {265  const points: ChartPoint[] = [];266  let skipped = 0, dropped = 0;267  for (const row of rows) {268    if (row.every((c) => c.trim() === "")) continue;269    const p = rowToPoint(row, xType);270    if (!p) skipped++;271    else if (points.length >= CHART_MAX_POINTS) dropped++;272    else points.push(p);273  }274  return { points, skipped, dropped };275}276277/** Points after the horizontal axis changed type: numbers become labels, labels become numbers (their rank when unreadable). */278export function convertPointsX(points: readonly ChartPoint[], xType: "number" | "category"): ChartPoint[] {279  return points.map((p, i) => ({ ...p, x: xType === "category" ? (typeof p.x === "number" ? numberText(p.x) : p.x) : typeof p.x === "number" ? p.x : parseNumber(p.x) ?? i + 1 }));280}281282export interface Dataset { columns: { name: string; type: "number" | "string" }[]; rows: (string | number)[][] }283export interface DatasetImport { series: ChartSeries[]; xType: "number" | "category"; total: number; unreadable: number; dropped: number }284285const cellNumber = (v: string | number | undefined): number | null => (typeof v === "number" ? (Number.isFinite(v) ? v : null) : typeof v === "string" ? parseNumber(v) : null);286287/**288 * Builds chart series from a dataset: one series per y column, x from one column (numeric when that column is289 * numeric, labels otherwise). Lines without a readable x or y are left out; when more than 600 remain, 600 evenly290 * spaced lines are kept (first and last included) and `dropped` says how many were left out.291 */292export function datasetToSeries(ds: Dataset, xCol: number, yCols: readonly number[], maxPoints = CHART_MAX_POINTS): DatasetImport {293  const xType: "number" | "category" = ds.columns[xCol]?.type === "number" ? "number" : "category";294  const series: ChartSeries[] = [];295  let unreadable = 0, dropped = 0;296  yCols.slice(0, CHART_MAX_SERIES).forEach((yCol, k) => {297    const points: ChartPoint[] = [];298    for (const row of ds.rows) {299      const y = cellNumber(row[yCol]);300      const x = xType === "number" ? cellNumber(row[xCol]) : row[xCol] === undefined ? null : String(row[xCol]).trim().slice(0, 60);301      if (y === null || x === null) continue;302      points.push({ x, y });303    }304    unreadable = Math.max(unreadable, ds.rows.length - points.length);305    let kept = points;306    if (points.length > maxPoints) {307      kept = Array.from({ length: maxPoints }, (_, i) => points[Math.round((i * (points.length - 1)) / (maxPoints - 1))]);308      dropped = Math.max(dropped, points.length - maxPoints);309    }310    if (kept.length > 0) series.push({ name: (ds.columns[yCol]?.name ?? "").trim().slice(0, 200) || `y${k + 1}`, tone: seriesTone(k), points: kept });311  });312  return { series, xType, total: ds.rows.length, unreadable, dropped };313}314315// ── Simulation ──────────────────────────────────────────────────────────────────────────────────────316317type SimBlock = BlockOf<"simulation">;318319/** Starting `config` of a kind: only what the kind cannot do without. */320export function simDefaultConfig(kind: SimKind): SimBlock["config"] {321  return kind === "function-plot" ? { expr: "a * sin(x)" } : {};322}323/** Exactly the sliders of this kind and configuration: unknown keys dropped, missing ones at their default, values on the slider grid. */324export function simParams(kind: SimKind, config: SimBlock["config"], given: Readonly<Record<string, number>> = {}): Record<string, number> {325  const out: Record<string, number> = {};326  for (const def of paramDefs(kind, config)) out[def.key] = snapParam(def, Object.hasOwn(given, def.key) ? given[def.key] : def.default);327  return out;328}329/** A simulation block after its kind changed: parameters and configuration go back to that kind's defaults. */330export function simWithKind(block: SimBlock, kind: SimKind): SimBlock {331  const config = simDefaultConfig(kind);332  return { ...block, kind, config, params: simParams(kind, config) };333}334/**335 * Options that stopped meaning anything are removed (bounds of a function-plot parameter that is no longer in any336 * expression). Nothing is removed while the configuration has another problem, so a typo does not cost the bounds.337 */338export function pruneSimConfig(kind: SimKind, config: SimBlock["config"]): SimBlock["config"] {339  let problems: string[];340  try { problems = SIMULATIONS[kind].validateConfig?.(config) ?? []; } catch { return config; }341  const unknown = problems.map((p) => /^config\.([a-zA-Z][a-zA-Z0-9]*): unknown option/.exec(p)?.[1]);342  if (problems.length === 0 || unknown.some((k) => k === undefined)) return config;343  return Object.fromEntries(Object.entries(config).filter(([k]) => !unknown.includes(k)));344}345/** A simulation block after its configuration changed: stale options dropped, sliders re-derived. */346export function simWithConfig(block: SimBlock, config: SimBlock["config"]): SimBlock {347  const next = pruneSimConfig(block.kind, config);348  return { ...block, config: next, params: simParams(block.kind, next, block.params) };349}350351export interface FormIssue { path: string; message: string }352353/** Problems reported by the simulation itself, addressed to the field they concern (`config.expr`…) when they name one. */354export function simulationIssues(block: SimBlock): FormIssue[] {355  return validateSimulation(block).map((message) => {356    const m = /^(config|params)\.([a-zA-Z][a-zA-Z0-9]*)/.exec(message);357    return { path: m ? `${m[1]}.${m[2]}` : "config", message: message.replace(/^config\./, "") };358  });359}360361// ── Schema issues in plain words ────────────────────────────────────────────────────────────────────362363const CUSTOM: [RegExp, string, string][] = [364  [/at least one correct choice/, "Cochez au moins une bonne réponse.", "Mark at least one choice as correct."],365  [/one cell per column/, "Chaque ligne doit avoir une cellule par colonne.", "Every row needs one cell per column."],366  [/rowLabels × colLabels/, "La grille de valeurs doit avoir une ligne par étiquette de ligne et une colonne par étiquette de colonne.", "The grid of values needs one row per row label and one column per column label."],367  [/x and y go together/, "Donnez les deux coordonnées x et y, ou aucune.", "Give both x and y, or neither."],368  [/unknown endpoint/, "Une flèche pointe vers un nœud qui n’existe plus.", "An arrow points to a node that no longer exists."],369  [/unknown group/, "Un nœud appartient à un groupe qui n’existe plus.", "A node belongs to a group that no longer exists."],370  [/duplicate (node|edge) id/, "Deux éléments du diagramme portent le même identifiant.", "Two elements of the diagram share the same identifier."],371  [/animation: unknown/, "Une étape de l’animation cite un élément qui n’existe plus.", "An animation step mentions an element that no longer exists."],372  [/^id:/, "Identifiant invalide (minuscules, chiffres et tirets).", "Invalid identifier (lower-case letters, digits and dashes)."],373];374375type ZIssue = z.core.$ZodIssue;376function plain(issue: ZIssue, fr: boolean): string {377  switch (issue.code) {378    case "too_small": {379      const min = Number(issue.minimum);380      if (issue.origin === "string") return min <= 1 ? (fr ? "Ce champ ne peut pas être vide." : "This field cannot be empty.") : fr ? `Au moins ${min} caractères.` : `At least ${min} characters.`;381      if (issue.origin === "array") return fr ? `Il en faut au moins ${min}.` : `At least ${min} needed.`;382      return fr ? `La valeur minimale est ${min}.` : `The minimum is ${min}.`;383    }384    case "too_big": {385      const max = Number(issue.maximum);386      if (issue.origin === "string") return fr ? `Trop long : ${max} caractères au plus.` : `Too long: at most ${max} characters.`;387      if (issue.origin === "array") return fr ? `Trop d’éléments : ${max} au plus.` : `Too many items: at most ${max}.`;388      return fr ? `La valeur maximale est ${max}.` : `The maximum is ${max}.`;389    }390    case "invalid_type": return fr ? "Valeur manquante ou d’un type inattendu." : "Missing value, or a value of the wrong kind.";391    case "invalid_value": return fr ? "Choisissez une des valeurs proposées." : "Pick one of the proposed values.";392    case "invalid_format": return fr ? "Format invalide." : "Invalid format.";393    case "not_multiple_of": return fr ? "Un nombre entier est attendu." : "A whole number is expected.";394    case "unrecognized_keys": return fr ? `Champ inconnu : ${issue.keys.join(", ")}.` : `Unknown field: ${issue.keys.join(", ")}.`;395    case "custom": {396      const hit = CUSTOM.find(([re]) => re.test(issue.message));397      return hit ? (fr ? hit[1] : hit[2]) : issue.message;398    }399    default: return fr ? "Valeur invalide." : "Invalid value.";400  }401}402403/** Zod issues → one plain sentence per path (the first issue of a path wins), in the interface language. */404export function plainIssues(error: z.ZodError, locale: Locale): FormIssue[] {405  const out: FormIssue[] = [];406  for (const issue of error.issues) {407    const path = issue.path.join(".");408    if (!out.some((o) => o.path === path)) out.push({ path, message: plain(issue, locale === "fr") });409  }410  return out.slice(0, 20);411}412
Files main
Menu

Theme