@ai-matrx/records-ui 0.116.23 → 0.116.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/README.md +3 -3
  3. package/dist/SaveToTable-P3MPRSCW.js +20 -0
  4. package/dist/{chunk-MUK63ANA.js → chunk-4ZS4WEEE.js} +3 -3
  5. package/dist/chunk-4ZS4WEEE.js.map +1 -0
  6. package/dist/{chunk-SYHUPGCU.js → chunk-6Z537SLG.js} +1 -1
  7. package/dist/{chunk-SYHUPGCU.js.map → chunk-6Z537SLG.js.map} +1 -1
  8. package/dist/{chunk-ODABFEHG.js → chunk-7RSMA3NK.js} +3 -3
  9. package/dist/chunk-7RSMA3NK.js.map +1 -0
  10. package/dist/{chunk-VHZKLE63.js → chunk-FLIERNH7.js} +9 -9
  11. package/dist/chunk-FLIERNH7.js.map +1 -0
  12. package/dist/{chunk-ZNIXJ5RY.js → chunk-KQR2RA4V.js} +3 -3
  13. package/dist/{chunk-WQGFKNE2.js → chunk-OJTJ4HJI.js} +26 -26
  14. package/dist/chunk-OJTJ4HJI.js.map +1 -0
  15. package/dist/{chunk-PPWNFIJ5.js → chunk-OV6QBL5R.js} +2 -2
  16. package/dist/{chunk-PPWNFIJ5.js.map → chunk-OV6QBL5R.js.map} +1 -1
  17. package/dist/{chunk-5IX4BL72.js → chunk-QBMUTXTQ.js} +2 -2
  18. package/dist/{chunk-5IX4BL72.js.map → chunk-QBMUTXTQ.js.map} +1 -1
  19. package/dist/{chunk-MCDA6L7E.js → chunk-TC5S4VOW.js} +2 -2
  20. package/dist/chunk-TC5S4VOW.js.map +1 -0
  21. package/dist/{chunk-FECWKOWW.js → chunk-W7GR64CB.js} +1 -1
  22. package/dist/chunk-W7GR64CB.js.map +1 -0
  23. package/dist/{chunk-FHL4GG6R.js → chunk-WCQSJPLS.js} +2 -2
  24. package/dist/chunk-WCQSJPLS.js.map +1 -0
  25. package/dist/data-source.cjs.map +1 -1
  26. package/dist/data-source.d.cts +1 -1
  27. package/dist/data-source.d.ts +1 -1
  28. package/dist/data-source.js.map +1 -1
  29. package/dist/first-page.cjs.map +1 -1
  30. package/dist/first-page.d.cts +1 -1
  31. package/dist/first-page.d.ts +1 -1
  32. package/dist/first-page.js.map +1 -1
  33. package/dist/helpers.cjs +4 -4
  34. package/dist/helpers.cjs.map +1 -1
  35. package/dist/helpers.d.cts +9 -9
  36. package/dist/helpers.d.ts +9 -9
  37. package/dist/helpers.js +4 -4
  38. package/dist/helpers.js.map +1 -1
  39. package/dist/html-frame.cjs.map +1 -1
  40. package/dist/html-frame.d.cts +1 -1
  41. package/dist/html-frame.d.ts +1 -1
  42. package/dist/html-frame.js +1 -1
  43. package/dist/index.cjs +603 -251
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.cts +162 -115
  46. package/dist/index.d.ts +162 -115
  47. package/dist/index.js +590 -224
  48. package/dist/index.js.map +1 -1
  49. package/dist/object-actions.cjs +2 -2
  50. package/dist/object-actions.cjs.map +1 -1
  51. package/dist/object-actions.js +3 -3
  52. package/dist/pickers.cjs +23 -23
  53. package/dist/pickers.cjs.map +1 -1
  54. package/dist/pickers.js +8 -8
  55. package/dist/skeleton.cjs.map +1 -1
  56. package/dist/skeleton.js +4 -4
  57. package/dist/table-shape.cjs.map +1 -1
  58. package/dist/table-shape.js +1 -1
  59. package/package.json +3 -3
  60. package/dist/SaveToTable-PGOQVYVS.js +0 -20
  61. package/dist/chunk-FECWKOWW.js.map +0 -1
  62. package/dist/chunk-FHL4GG6R.js.map +0 -1
  63. package/dist/chunk-MCDA6L7E.js.map +0 -1
  64. package/dist/chunk-MUK63ANA.js.map +0 -1
  65. package/dist/chunk-ODABFEHG.js.map +0 -1
  66. package/dist/chunk-VHZKLE63.js.map +0 -1
  67. package/dist/chunk-WQGFKNE2.js.map +0 -1
  68. /package/dist/{SaveToTable-PGOQVYVS.js.map → SaveToTable-P3MPRSCW.js.map} +0 -0
  69. /package/dist/{chunk-ZNIXJ5RY.js.map → chunk-KQR2RA4V.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ - **A section card shows and edits real schema tables (2026-10-18).** BREAKING: `SectionCard` takes `source` instead of `tableId` — the same union as `RecordsTableCard`: `{ kind: "table", id }` (a custom Table, unchanged) or `{ kind: "entity", token, filter? }` (a table made with `platform.create_entity_table`, e.g. `web_brand_choice`), drawn by the new `EntitySectionCard` over the one standard-source path (`entityTable.tsx`): the door's columns (bookkeeping and the pinned parent left out; a column the door marks read-only is text), edits through `entity_update` with the version seen and put back with the store's sentence on refusal, Add filed in the active organization. `filter` (`{ brand_id }`) shows one parent's rows — asked of the door as `eq` clauses, stamped on rows added — and is also accepted by `RecordsTableCard`'s entity source and `useEntitySourceTable` (`EntityFilter`, `entityFilterWhere` exported). Guard: `a-section-card-shows-and-edits-a-standard-table.test.tsx` (red without the change). Consumer action: replace `<SectionCard tableId={id} />` with `<SectionCard source={{ kind: "table", id }} />`.
5
6
  - **Build guard moves to the shared `../scripts/check-ships-once.mjs --apart first-page,helpers,data-source` (2026-10-18).** It replaces the private `scripts/check-client-modules-ship-once.mjs` (removed). It checks the client side the same way, and also checks the server side and stamps; the light doors stay apart. Output unchanged. Consumer action: none.
6
7
  - **Package build and current design-system shortcut contract.** The server-safe `/first-page` bindings now emit a complete declaration instead of failing TS4023 on inferred sibling types. Table action chords use the design system's current `formatTapShortcut` export; the prior npm release still imported the removed `formatShortcut` name and broke consumer bundles with current design-system. Consumer action: refresh `@ai-matrx/records-ui` to latest alongside current `@ai-matrx/design-system`.
7
8
  - **"Let AI fill" with Describe image now names the attachment columns it reads.** Setting up a column from the Describe image preset declares `inputs` = the table's attachment column keys (via `@ai-matrx/records` `presetInputs`); before, no `inputs` were sent, the model was shown nothing and every row answered "nothing found". The server shows the model the row's image attachments. Needs `@ai-matrx/records` with `presetInputs`. Consumer action: none.
@@ -23,11 +24,45 @@
23
24
  - Tests: `vitest.setup.ts` gives jsdom a no-op `performance.mark` / `measure`.
24
25
  - **New subpath `@ai-matrx/records-ui/data-source`:** `recordsDataSource`, `personActor` and the who-changed words (`whenWords`, `actorWords`, `actorBadge`, `lastChangeSentence`, `SOMEBODY`, `THE_SYSTEM`) alone. `/helpers` also carries the field-type words, the colour resolver and the table builders, which read `@ai-matrx/records/core`; this entry reaches `@ai-matrx/kit` only, and shares the one data-source cache with `/helpers` and the root. Additive. Consumer action: a shell-reachable service that only binds its supabase client or says when imports from `/data-source`.
25
26
 
26
- ## 0.116.23
27
+ ## 0.116.25
27
28
 
28
29
  UNVERIFIED: this release has no Unreleased entry and the source comparison could not be made (the caller supplied no source comparison). Whether source changed is unknown; consumer action is unknown.
29
30
  Check the package's gitHead on npm against this version's gitHead: `git diff <previous gitHead> <this gitHead> -- apps/shared/records-ui/src`.
30
31
 
32
+ ## 0.116.24
33
+
34
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
35
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
36
+ Diff: `git diff f64802f769 2328dcd19a -- apps/shared/records-ui/src`
37
+
38
+ Changed shipped source files (7):
39
+ - `apps/shared/records-ui/src/EntitySectionCard.tsx`
40
+ - `apps/shared/records-ui/src/RecordsTableCard.tsx`
41
+ - `apps/shared/records-ui/src/SectionCard.tsx`
42
+ - `apps/shared/records-ui/src/entityDoors.fixture.ts`
43
+ - `apps/shared/records-ui/src/entityTable.tsx`
44
+ - `apps/shared/records-ui/src/index.ts`
45
+ - `apps/shared/records-ui/src/sectionKeys.ts`
46
+
47
+ ## 0.116.23
48
+
49
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
50
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
51
+ Diff: `git diff 30340788d1 f64802f769 -- apps/shared/records-ui/src`
52
+
53
+ Changed shipped source files (2):
54
+ - `apps/shared/records-ui/src/SectionCard.tsx`
55
+ - `apps/shared/records-ui/src/looks/designLooks.tsx`
56
+
57
+ ## 0.116.22
58
+
59
+ SOURCE CHANGED WITH NO RELEASE NOTE. This release shipped source changes that nobody described in an Unreleased entry,
60
+ so they may include breaking API changes. Consumer action is UNKNOWN: read the diff before upgrading.
61
+ Diff: `git diff 1191ea6333 30340788d1 -- apps/shared/records-ui/src`
62
+
63
+ Changed shipped source files (1):
64
+ - `apps/shared/records-ui/src/looks/tableTokens.tsx`
65
+
31
66
  ## 0.116.21
32
67
 
33
68
  Automatic changed-only republish (docs/metadata drift since the last published version; verified: `git diff 1a5be7266f 1191ea6333 -- apps/shared/records-ui/src`
package/README.md CHANGED
@@ -128,7 +128,7 @@ exportable, historied — and the whole graph is created in ONE act
128
128
  (`custom.work_template_instantiate` judges it before writing any of it), so a
129
129
  half-made checklist is not a state this store can be in. The states and the
130
130
  moves offered come from `custom.work_states()`; a move the store does not list
131
- as next is not shown greyed out, it is not there.
131
+ as next is not shown grayed out, it is not there.
132
132
 
133
133
  `BookingSlots` holds the slot **first** and takes the details second — taking
134
134
  details first is how two people fill in a form and one of them finds out at the
@@ -184,7 +184,7 @@ match would pass.
184
184
  because it is what the store said, and the conflict comes with it field by
185
185
  field.
186
186
  - **Absent, never dead.** A control a person may not use is not rendered. There
187
- is no disabled "+" and no greyed settings panel anywhere in this package.
187
+ is no disabled "+" and no grayed settings panel anywhere in this package.
188
188
  - **A Field decides its editor.** The thirteen parity types come from the store
189
189
  (`custom.parity_field_types()`), generated into `@ai-matrx/records`. The unit
190
190
  and the format are on the Field because they change what the value MEANS.
@@ -192,7 +192,7 @@ match would pass.
192
192
  offered as a field proposal; a list that is not live says so; a door that does
193
193
  not exist yet is named, with the lane that owes it.
194
194
  - **Dense, one-row headers, light and dark, iOS-safe**, through the design
195
- system's own tokens — this package sets no colours of its own.
195
+ system's own tokens — this package sets no colors of its own.
196
196
 
197
197
  ## The demo
198
198
 
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ SAVE_TO_TABLE_TYPES,
5
+ SaveToTable,
6
+ shapesOfSource
7
+ } from "./chunk-FLIERNH7.js";
8
+ import "./chunk-KQR2RA4V.js";
9
+ import "./chunk-7RSMA3NK.js";
10
+ import "./chunk-6Z537SLG.js";
11
+ import "./chunk-OV6QBL5R.js";
12
+ import "./chunk-4ZS4WEEE.js";
13
+ import "./chunk-WCQSJPLS.js";
14
+ import "./chunk-HKYEHBQT.js";
15
+ export {
16
+ SAVE_TO_TABLE_TYPES,
17
+ SaveToTable,
18
+ shapesOfSource
19
+ };
20
+ //# sourceMappingURL=SaveToTable-P3MPRSCW.js.map
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  fieldTypeChoice,
4
4
  isSystemFieldKind
5
- } from "./chunk-FHL4GG6R.js";
5
+ } from "./chunk-WCQSJPLS.js";
6
6
 
7
7
  // src/docs.ts
8
8
  function fieldToken(fieldId) {
@@ -162,7 +162,7 @@ function fieldTypeLabel(field) {
162
162
  const known = fieldTypeChoice(kind)?.label;
163
163
  if (known) return field.multi && kind !== "multi_select" ? `${known} (many)` : known;
164
164
  const plain = {
165
- // `boolean` is the BEHAVIOUR word; `checkbox` is the type a person picks. Both are
165
+ // `boolean` is the BEHAVIOR word; `checkbox` is the type a person picks. Both are
166
166
  // written the way a person writes them, never as a raw token.
167
167
  boolean: "Yes / no",
168
168
  date: "Date",
@@ -287,4 +287,4 @@ export {
287
287
  addDays,
288
288
  daysBetween
289
289
  };
290
- //# sourceMappingURL=chunk-MUK63ANA.js.map
290
+ //# sourceMappingURL=chunk-4ZS4WEEE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/docs.ts","../src/choiceLooks.ts","../src/parity.ts","../src/dates.ts"],"sourcesContent":["// src/docs.ts — @ai-matrx/records-ui · SCR-20, SCR-21, SCR-22\n//\n// DOCUMENTS OVER RECORDS. A template is a body whose tokens point at Fields BY\n// ID; a render is written ONCE and frozen with the SHA-256 of its own text; a\n// signature seals that exact version and is immutable once made.\n//\n// Three things this package refuses to re-implement, because the store already\n// does them and doing them twice is how two answers appear:\n// · which tokens a body contains — `custom.doc_tokens`;\n// · which of them this Table cannot answer, and why — `custom.doc_unresolved_tokens`;\n// · whether a signature still holds — `custom.doc_signature_intact`.\n//\n// The token syntax is the store's own: `{{field:<the field's id>}}`. A name\n// would be a token that silently stops resolving the day somebody renames a\n// Field, which is the exact failure REC-17 exists to prevent.\n\nimport type { Field, Uuid } from \"@ai-matrx/records\";\n\n/** The one token form, written the way the store's own pattern reads it. */\nexport function fieldToken(fieldId: Uuid): string {\n return `{{field:${fieldId}}}`;\n}\n\n/** THE DECLARATIVE SPEC an agent writes. One template, whole, in one object. */\nexport interface DocTemplateSpec {\n name: string;\n /** The body, tokens and all. */\n body: string;\n}\n\n/**\n * A template written in terms of Field KEYS — which is how an agent thinks and\n * how a person reads — turned into the store's id-based tokens. The agent writes\n * `{{title}}`; what is stored points at the Field's id, so a rename never\n * silently empties the document.\n *\n * A key this Table does not have is LEFT EXACTLY AS IT IS, so\n * `custom.doc_unresolved_tokens` names it and the screen shows the store's own\n * reason — it is never quietly deleted from the body.\n */\nexport function bodyFromKeys(body: string, fields: Field[]): string {\n const byKey = new Map(fields.map((f) => [f.key, f.id]));\n return body.replace(/\\{\\{\\s*([a-zA-Z0-9_]+)\\s*\\}\\}/g, (whole, key: string) => {\n const id = byKey.get(key);\n return id ? fieldToken(id) : whole;\n });\n}\n\n/** The reverse, for a person reading a stored body: ids shown as the Field's label. */\nexport function bodyForReading(body: string, fields: Field[]): string {\n const byId = new Map(fields.map((f) => [f.id, f.label || f.key]));\n return body.replace(/\\{\\{\\s*field:([0-9a-fA-F-]{36})\\s*\\}\\}/g, (whole, id: string) => {\n const label = byId.get(id);\n return label ? `{{${label}}}` : whole;\n });\n}\n\n/** VAL-10: a signature is a Value on a text Field whose format is `signature`. */\nexport function isSignatureField(field: Field): boolean {\n return field.type === \"text\" && (field.format ?? \"\").toLowerCase() === \"signature\";\n}\n","// src/choiceLooks.ts — @ai-matrx/records-ui · merge tranche 6f (early)\n//\n// A CHOICE WEARS THE COLOR ITS OWNER GAVE IT.\n//\n// The older /data grid let a person paint each choice of a list (\"Completed\" green, \"Scheduled\"\n// blue), and those colors are kept on the Field itself: `display_format.options.choices`, the\n// document `custom.field_update` writes (the /data Sheet's seam writes it the same way, and a\n// column's settings here write it back). The grid used to ignore it and HASH THE WORD into a\n// color, so a column painted green on /data came up amber here, and a color a person set in the\n// settings changed nothing on screen — the silent half of a setting.\n//\n// Pure: no React, no store call. The Field the grid already holds carries everything.\n\nimport { newerKindOf } from \"@ai-matrx/records/field-kinds\";\nimport type { Field } from \"@ai-matrx/records\";\n// The values from the pure `table-style` subpath (no \"use client\", no grid): `@ai-matrx/records-ui/helpers`\n// reaches this file through `fieldTypeLabel`, and the data-table root would drag the whole grid with it.\nimport { CHOICE_CHIP_CLASS, NEUTRAL_CHIP_CLASS, STYLE_COLORS } from \"@ai-matrx/design-system/data-table/table-style\";\nimport type { ChoiceColorLookup, StyleColor } from \"@ai-matrx/design-system/data-table\";\n\n/** One choice's look, as the Field keeps it. */\nexport interface ChoiceLook {\n value: string;\n label?: string;\n color?: StyleColor;\n}\n\n/** The Field's display document, which the store keeps beside its declared keys. */\nexport function displayFormatOf(field: Field): { id: string; options: Record<string, unknown> } | null {\n const raw = (field as unknown as { display_format?: unknown }).display_format;\n if (!raw || typeof raw !== \"object\") return null;\n const id = (raw as { id?: unknown }).id;\n if (typeof id !== \"string\" || id === \"\") return null;\n const options = (raw as { options?: unknown }).options;\n return { id, options: options && typeof options === \"object\" ? (options as Record<string, unknown>) : {} };\n}\n\nfunction isStyleColor(v: unknown): v is StyleColor {\n return typeof v === \"string\" && (STYLE_COLORS as readonly string[]).includes(v);\n}\n\n/** Every choice look the Field keeps, in its own order. A color outside the palette is dropped. */\nexport function choiceLooksOf(field: Field): ChoiceLook[] {\n const display = displayFormatOf(field);\n const choices = display?.options[\"choices\"];\n if (!Array.isArray(choices)) return [];\n const out: ChoiceLook[] = [];\n for (const c of choices) {\n if (!c || typeof c !== \"object\") continue;\n const value = (c as { value?: unknown }).value;\n if (typeof value !== \"string\" || value.trim() === \"\") continue;\n const color = (c as { color?: unknown }).color;\n const label = (c as { label?: unknown }).label;\n out.push({\n value: value.trim(),\n ...(typeof label === \"string\" && label.trim() !== \"\" ? { label: label.trim() } : {}),\n ...(isStyleColor(color) ? { color } : {}),\n });\n }\n return out;\n}\n\n/**\n * ONE WORD, HOWEVER IT WAS WRITTEN. A moved list keeps its words as `completed` / `truck_4` and\n * shows them as `Completed` / `Truck 4`; a color kept against either spelling is the same choice.\n */\nexport function choiceWord(value: unknown): string {\n return String(value ?? \"\")\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\");\n}\n\n/**\n * NOTION'S STATUS COLORS, BY GROUP: To-do gray, In progress blue, Complete green. A status choice\n * the column paints nothing for wears its group's color, so a fresh Status column reads the way\n * Notion's does with nobody picking a color. A choice with a color of its own keeps it\n * (`storedChoiceColor` asks the column first).\n */\nexport const STATUS_GROUP_COLOR = { todo: \"gray\", in_progress: \"blue\", done: \"green\" } as const satisfies Record<string, StyleColor>;\n\n/** The color a status choice's GROUP gives it, or `undefined` when the column is not a Status. */\nexport function statusGroupColor(field: Field, value: unknown): StyleColor | undefined {\n if (newerKindOf(field) !== \"status\" || value === null || value === undefined || value === \"\") return undefined;\n const word = choiceWord(value);\n if (word === \"\") return undefined;\n const groups = ((field.config ?? {}) as Record<string, unknown>)[\"status_groups\"];\n if (groups && typeof groups === \"object\") {\n // the group is kept under the choice's KEY; the cell may hold its WORDS (\"In progress\" ↔ in_progress)\n for (const [key, group] of Object.entries(groups as Record<string, unknown>)) {\n if (choiceWord(key) !== word) continue;\n return group === \"in_progress\" ? STATUS_GROUP_COLOR.in_progress : group === \"done\" ? STATUS_GROUP_COLOR.done : STATUS_GROUP_COLOR.todo;\n }\n }\n return STATUS_GROUP_COLOR.todo;\n}\n\n/** The color this Field keeps for this value, or `undefined` when it keeps none. */\nexport function storedChoiceColor(field: Field, value: unknown): StyleColor | undefined {\n if (value === null || value === undefined || value === \"\") return undefined;\n const word = choiceWord(value);\n if (word === \"\") return undefined;\n for (const look of choiceLooksOf(field)) {\n if (!look.color) continue;\n if (choiceWord(look.value) === word || (look.label && choiceWord(look.label) === word)) return look.color;\n }\n return statusGroupColor(field, value);\n}\n\n/**\n * THE COLOUR-BY LOOKUP, STORED COLORS FIRST. A value whose column keeps a color for it wears\n * that color; any other value still paints, deterministically, through `fallback` — a colour-by\n * that silently did nothing would be the screen lying about a setting a person just changed.\n */\nexport function storedChoiceColorLookup(\n fields: readonly Field[],\n fallback: ChoiceColorLookup,\n): ChoiceColorLookup {\n const byKey = new Map(fields.map((f) => [f.key, f] as const));\n return (fieldKey, value) => {\n const field = byKey.get(fieldKey);\n return (field ? storedChoiceColor(field, value) : undefined) ?? fallback(fieldKey, value);\n };\n}\n\n/**\n * THE ORDER A NEW CHOICE IS PAINTED IN (Airtable): each choice added to a list takes the next\n * palette color the list does not wear yet, so a fresh list reads as distinct chips with nobody\n * picking a color. Gray last — it reads as \"no colour\".\n */\nexport const NEW_CHOICE_PALETTE: readonly StyleColor[] = [\"blue\", \"green\", \"amber\", \"red\", \"violet\", \"teal\", \"slate\"];\n\n/** The color the next choice of a list takes, given the colors its choices already wear. */\nexport function nextChoiceColor(worn: ReadonlyArray<StyleColor | null | undefined>): StyleColor {\n const taken = new Set(worn.filter((c): c is StyleColor => Boolean(c)));\n const free = NEW_CHOICE_PALETTE.find((c) => !taken.has(c));\n return free ?? NEW_CHOICE_PALETTE[worn.length % NEW_CHOICE_PALETTE.length]!;\n}\n\n/**\n * THE ONE CHIP A CHOICE IS DRAWN AS — the grid cell, the picker's list and its chip, a form's\n * pills: the color the column keeps for the value (by any of the words given — its key, its\n * label), else the neutral chip. One answer, so no surface paints a choice its own way.\n */\nexport function choiceChipLookOf(field: Field, ...words: unknown[]): { className: string; color: StyleColor | null } {\n for (const word of words) {\n const color = storedChoiceColor(field, word);\n if (color) return { className: CHOICE_CHIP_CLASS[color], color };\n }\n return { className: NEUTRAL_CHIP_CLASS, color: null };\n}\n","// src/parity.ts — @ai-matrx/records-ui\n//\n// FLD-11, the parity floor. A Field stores a BEHAVIOR (one of five) plus\n// modifiers, unit and format; a person picked one of THIRTEEN parity types in\n// the UI. This resolves the second from the first, using the same facts the\n// store's own `custom.parity_field_types()` describes — which is generated into\n// `@ai-matrx/records` and imported here, never retyped.\n//\n// Nothing in this file decides policy. It decides which editor to draw.\n\nimport { displayFormatOf } from \"./choiceLooks\";\nimport {\n KERNEL_TABLES,\n PARITY_FIELD_TYPES,\n fieldKindFor,\n newerKindOf,\n isButtonField,\n type FieldKind,\n type KernelTargets,\n type ParityFieldType,\n} from \"@ai-matrx/records/field-kinds\";\nimport type { Field } from \"@ai-matrx/records\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\nimport { isSignatureField } from \"./docs\";\nimport { fieldTypeChoice, isSystemFieldKind, type PickableFieldType } from \"./fieldTypes\";\n\n/** The kernel ids come from the store's own kernel rows, never from a literal here. */\nconst kernelId = (name: string): string =>\n KERNEL_TABLES.find((t) => t.name === name)?.id ?? \"\";\nconst KERNEL_FILE_TABLE = kernelId(\"File\");\nconst KERNEL_PERSON_TABLE = kernelId(\"Person\");\n\nexport const PARITY_LABEL: Record<ParityFieldType, string> = {\n attachment: \"Attachment\",\n checkbox: \"Yes / no\",\n currency: \"Currency\",\n datetime: \"Date\",\n email: \"Email\",\n formula: \"Formula\",\n lookup: \"Lookup\",\n member: \"Person\",\n multi_select: \"Multi-select\",\n percent: \"Percent\",\n phone: \"Phone\",\n rollup: \"Rollup\",\n select: \"Select\",\n url: \"Link\",\n};\n\n/** The \"made of\" sentence the store itself publishes, for the field editor's help text. */\nexport const PARITY_MADE_OF: Record<string, string> = Object.fromEntries(\n PARITY_FIELD_TYPES.map((p) => [p.parity_type, p.made_of]),\n);\n\n/**\n * Plain text and plain number are behaviors with no parity type of their own.\n *\n * 🚨 THIS IS NOW AN ALIAS, AND THAT IS THE POINT (TAILS-3, 2026-09-21). The\n * classifier moved into `@ai-matrx/records` as `FieldKind` so that the editor a\n * person types into and the COERCION applied to what they typed are decided by\n * one body. They were decided by two, and the public booking page paid for it:\n * \"Vehicle Year takes a number, and it was given a string\" on every table with\n * a number field.\n */\nexport type EditorKind = FieldKind;\n\n/** The kernel ids come from the store's own kernel rows, never from a literal here. */\nconst KERNEL: KernelTargets = { file: KERNEL_FILE_TABLE, person: KERNEL_PERSON_TABLE };\n\n/**\n * Which editor one Field wants. Reads the Field's own declaration only — the\n * behavior, the modifiers, the format, the relation target and the config —\n * because those are what the store stores, and a screen that guessed from a\n * value would draw a different editor for an empty record.\n *\n * It is `fieldKindFor` with this package's kernel ids bound. Nothing here\n * decides anything the core does not.\n */\nexport function editorKindFor(field: Field): EditorKind {\n return fieldKindFor(field, KERNEL);\n}\n\n/**\n * WHICH KIND A PERSON PICKED, read back off the Field the store keeps — the ONE reader every\n * \"what does this column hold\" answer goes through (the Settings column list, the column panel).\n *\n * `editorKindFor` answers which EDITOR to draw, and for two families that is not the kind a\n * person picked: a Signature is a text Field whose format is `signature` (it draws a line of\n * text), and the store's stamps — Record number, Created time, Last changed time — are formula\n * Fields whose `config.system` names the stamp. Read through the editor classifier alone, the\n * Settings list called a Signature \"Text\" and a Record number \"Worked out from other columns\"\n * (lane 10 W1-A, guard `every-pickable-kind-reads-back-as-itself.test.tsx`).\n *\n * `undefined` when the Field is none of the kinds the menu offers.\n */\nexport function pickableTypeOf(field: Field): PickableFieldType | undefined {\n if (isSignatureField(field)) return \"signature\";\n // NOTION-PROPS-3: a button is text wearing the format `button`.\n if (isButtonField(field)) return \"button\";\n // LANE 10 P4: the nine newer kinds, each a base type wearing a format (`newerKindOf`).\n const newer = newerKindOf(field);\n if (newer) return newer;\n // A RATING OR A TIME made as a plain column wearing its look (`LOOK_KINDS`): named by that kind.\n const look = displayFormatOf(field)?.id;\n if (look === \"rating\" && field.type === \"range\") return \"rating\";\n if (look === \"time\" && field.type === \"text\") return \"time\";\n if ((look === \"color_pair\" || look === \"type_style\" || look === \"shadow\") && field.type === \"text\") return look;\n if (look === \"measure\" && field.type === \"range\") return \"measure\";\n const system = (field.config as Record<string, unknown> | undefined)?.[\"system\"];\n if (field.type === \"formula\" && typeof system === \"string\" && isSystemFieldKind(system)) return system;\n const kind = editorKindFor(field);\n return fieldTypeChoice(kind) ? (kind as PickableFieldType) : undefined;\n}\n\n/**\n * The type word a person sees in a header or a settings row — and it is the\n * SAME word the field panel offers, read from `FIELD_TYPE_CHOICES`, so a column\n * added as \"Money\" is never described anywhere else as \"Currency\".\n */\nexport function fieldTypeLabel(field: Field): string {\n const kind = pickableTypeOf(field) ?? editorKindFor(field);\n const known = fieldTypeChoice(kind)?.label;\n if (known) return field.multi && kind !== \"multi_select\" ? `${known} (many)` : known;\n const plain: Record<string, string> = {\n // `boolean` is the BEHAVIOR word; `checkbox` is the type a person picks. Both are\n // written the way a person writes them, never as a raw token.\n boolean: \"Yes / no\",\n date: \"Date\",\n json: \"Structured data\",\n relation: \"Link to a record\",\n };\n // Never a raw token on a screen: an editor kind this table has not named is\n // still written the way a person writes it.\n return plain[kind] ?? humanizeIdentifier(kind);\n}\n","/**\n * 🚨 THE ONE DATE HELPER EVERY LAYOUT READS (lane UI-FIX-18, VERIFIER-18 H2 / M1).\n *\n * MEASURED 2026-09-24 on production, browser in America/Los_Angeles: Kitchen's start date,\n * stored `2026-04-01`, read **Apr 1** in the grid, **Mar 31** on the calendar, **3/31** in\n * the gallery, and Backyard Deck's May 1 read **4/30** in the record panel. The grid was right\n * because it formats through the design system's registry (`formatFieldValue`), which reads a\n * bare `YYYY-MM-DD` as a day on a calendar. Every other surface called `new Date(\"2026-04-01\")`\n * itself — which JavaScript parses as UTC MIDNIGHT — and then printed it in the viewer's zone,\n * so everybody west of Greenwich saw the day before.\n *\n * THE CLASS, NOT THE INSTANCE. No component in this package parses or prints a date on its\n * own any more; it asks this file, and this file asks the SAME registry the grid asks. The\n * calendar's day key is the one thing the registry does not answer, and it is answered here\n * by the same rule: a bare calendar date IS its own day (read the characters), an instant\n * (`…Z`, `…+hh:mm`) is placed on the viewer's own calendar.\n *\n * The store's own stamps — Created time and Last changed time (`fx.created_time`,\n * `fx.modified_time`) — are instants, and are printed like every other date-and-time cell\n * (VERIFIER-18 M1 found `2026-09-25T00:13:34.564Z` in the grid, the gallery and the panel).\n */\nimport { formatFieldValue, type FieldFormatConfig } from \"@ai-matrx/design-system/field-formats\";\nimport type { Field } from \"@ai-matrx/records\";\n\n/** A day on a calendar with no time and no zone — `2026-04-01`, or a zoneless local midnight. */\nconst BARE_CALENDAR_DATE = /^(\\d{4})-(\\d{2})-(\\d{2})(?:[T ]00:00(?::00(?:\\.0+)?)?)?$/;\n\ntype SystemStamp = \"autonumber\" | \"created_time\" | \"modified_time\";\n\n/** The store's own stamp this Field is, when it is one (`config.system`). */\nexport function systemStampOf(field: Pick<Field, \"type\" | \"config\">): SystemStamp | null {\n if (field.type !== \"formula\") return null;\n const system = String((field.config ?? {})[\"system\"] ?? \"\");\n return system === \"autonumber\" || system === \"created_time\" || system === \"modified_time\" ? system : null;\n}\n\n/**\n * Does this value (or, with no value, this Field) carry a TIME OF DAY as well as a date?\n *\n * A DATE IS A DATE (chair ruling, 2026-09-24). The control and the text follow the STORED\n * VALUE's shape, never `config.kind` alone: a value with no time part — `1988-06-14`, a date\n * of birth on a `kind: \"datetime\"` Field — gets a date-only control and a date-only reading\n * everywhere (grid, form, panel, calendar). With no value yet, only a Field that says so\n * outright carries a time: the older `format: \"datetime\"`, or the store's own Created / Last\n * changed stamps (instants by construction).\n */\nexport function carriesTimeOfDay(field: Pick<Field, \"type\" | \"config\" | \"format\">, value?: unknown): boolean {\n if (value !== undefined && value !== null && value !== \"\") return hasTimePart(value);\n const stamp = systemStampOf(field);\n if (stamp === \"created_time\" || stamp === \"modified_time\") return true;\n return (field.format ?? \"\").toLowerCase() === \"datetime\";\n}\n\n/**\n * THE TIME OF DAY A MOMENT CARRIES, in the reader's clock (\"3:30 PM\") — the same words the grid's\n * date-and-time cell ends in — or null for a bare day. A calendar's month card and a timeline's bar\n * show it before the title (lane 10 P4, verifier V8 #7), as Google Calendar does.\n */\nexport function timeOfDayWords(value: unknown): string | null {\n if (!hasTimePart(value)) return null;\n const at = value instanceof Date ? value : new Date(value as string | number);\n return Number.isNaN(at.getTime()) ? null : at.toLocaleTimeString(undefined, { hour: \"numeric\", minute: \"2-digit\" });\n}\n\n/** A value that names a moment in the day, not just the day. */\nexport function hasTimePart(value: unknown): boolean {\n if (value instanceof Date || typeof value === \"number\") return true;\n if (typeof value !== \"string\") return false;\n const trimmed = value.trim();\n if (BARE_CALENDAR_DATE.test(trimmed)) return false;\n return /^\\d{4}-\\d{2}-\\d{2}[T ]\\d/.test(trimmed);\n}\n\n/** Is this Field a date column at all — a dated range, or the store's own time stamp? */\nexport function isDateField(field: Pick<Field, \"type\" | \"config\">): boolean {\n const stamp = systemStampOf(field);\n if (stamp === \"created_time\" || stamp === \"modified_time\") return true;\n if (field.type !== \"range\") return false;\n const kind = String((field.config ?? {})[\"kind\"] ?? \"\");\n return kind === \"date\" || kind === \"datetime\";\n}\n\n/**\n * The format a date-ish Field draws with, or `undefined` for a Field that is not one. With a\n * value, it is that value's own shape; without, the Field's (`carriesTimeOfDay`).\n * `presentation.formatForField` answers dates through this, so the grid and every card agree.\n */\nexport function dateFormatFor(\n field: Pick<Field, \"type\" | \"config\" | \"format\">,\n value?: unknown,\n): FieldFormatConfig | undefined {\n if (!isDateField(field)) return undefined;\n return carriesTimeOfDay(field, value) ? { id: \"datetime\" } : { id: \"date\" };\n}\n\n/**\n * THE TEXT OF ONE DATE VALUE, in the viewer's language — through the design system's\n * registry, exactly as the grid prints it, in the value's own shape. `null` when the value is\n * not a date at all, so the caller can fall back to its own reading (THE FALLBACK LAW).\n */\nexport function dateText(field: Pick<Field, \"type\" | \"config\" | \"format\">, value: unknown): string | null {\n const format = dateFormatFor(field, value) ?? (isDateLike(value) ? { id: hasTimePart(value) ? \"datetime\" : \"date\" } : undefined);\n if (!format) return null;\n const result = formatFieldValue(value, format);\n return result.ok && !result.empty ? result.text : null;\n}\n\nfunction isDateLike(value: unknown): boolean {\n return typeof value === \"string\" && /^\\d{4}-\\d{2}-\\d{2}/.test(value.trim());\n}\n\nfunction pad(n: number): string {\n return n < 10 ? `0${n}` : String(n);\n}\n\n/**\n * THE CALENDAR DAY a value falls on, as `YYYY-MM-DD` — the key a calendar files a card under.\n *\n * A bare calendar date is its own day. An instant is placed on the VIEWER's calendar: a visit\n * logged at 5:13 PM Pacific on 24 September is on the 24th for the person in Pacific time,\n * even though it is already the 25th in UTC.\n */\nexport function calendarDayOf(value: unknown): string | null {\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n const bare = BARE_CALENDAR_DATE.exec(trimmed);\n if (bare) return `${bare[1]}-${bare[2]}-${bare[3]}`;\n if (trimmed === \"\") return null;\n } else if (typeof value !== \"number\" && !(value instanceof Date)) {\n return null;\n }\n const at = value instanceof Date ? value : new Date(value as string | number);\n if (Number.isNaN(at.getTime())) return null;\n return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}`;\n}\n\n/** The heading of one calendar day — `Apr 1, 2026` — built on local midnight, never UTC. */\nexport function calendarDayLabel(day: string): string {\n const m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(day);\n if (!m) return day;\n const at = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]));\n return at.toLocaleDateString(undefined, { month: \"short\", day: \"numeric\", year: \"numeric\" });\n}\n\n// ---------------------------------------------------------------------------------------------\n// DAY ARITHMETIC ON THE VIEWER'S OWN CALENDAR (lane VIEWS-AND-FIELDS, sublane TL, 2026-10-02).\n// A day key is `YYYY-MM-DD`, built and read at LOCAL midnight — never `new Date(\"YYYY-MM-DD\")`,\n// which is UTC midnight and lands on the day before for everybody west of Greenwich. The timeline\n// places and moves bars with these; a move is always a whole number of days.\n\n/** The day key of a moment, on the viewer's calendar. */\nexport function dayKeyOf(at: Date): string {\n return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())}`;\n}\n\n/** A day key as local midnight. */\nexport function dayAt(day: string): Date {\n const [y, m, d] = day.split(\"-\").map(Number);\n return new Date(y!, (m ?? 1) - 1, d ?? 1);\n}\n\n/** The day `n` days after (or before, when negative) `day`. */\nexport function addDays(day: string, n: number): string {\n const at = dayAt(day);\n at.setDate(at.getDate() + n);\n return dayKeyOf(at);\n}\n\n/** Whole days from `from` to `to` (negative when `to` is earlier). DST-safe: rounds the hour away. */\nexport function daysBetween(from: string, to: string): number {\n return Math.round((dayAt(to).getTime() - dayAt(from).getTime()) / 86_400_000);\n}\n"],"mappings":";;;;;;;AAmBO,SAAS,WAAW,SAAuB;AAChD,SAAO,WAAW,OAAO;AAC3B;AAmBO,SAAS,aAAa,MAAc,QAAyB;AAClE,QAAM,QAAQ,IAAI,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AACtD,SAAO,KAAK,QAAQ,kCAAkC,CAAC,OAAO,QAAgB;AAC5E,UAAM,KAAK,MAAM,IAAI,GAAG;AACxB,WAAO,KAAK,WAAW,EAAE,IAAI;AAAA,EAC/B,CAAC;AACH;AAGO,SAAS,eAAe,MAAc,QAAyB;AACpE,QAAM,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AAChE,SAAO,KAAK,QAAQ,2CAA2C,CAAC,OAAO,OAAe;AACpF,UAAM,QAAQ,KAAK,IAAI,EAAE;AACzB,WAAO,QAAQ,KAAK,KAAK,OAAO;AAAA,EAClC,CAAC;AACH;AAGO,SAAS,iBAAiB,OAAuB;AACtD,SAAO,MAAM,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F;AASO,SAAS,SAAS,IAAkB;AACzC,SAAO,GAAG,GAAG,YAAY,CAAC,IAAI,IAAI,GAAG,SAAS,IAAI,CAAC,CAAC,IAAI,IAAI,GAAG,QAAQ,CAAC,CAAC;AAC3E;AAGO,SAAS,MAAM,KAAmB;AACvC,QAAM,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,MAAM,GAAG,EAAE,IAAI,MAAM;AAC3C,SAAO,IAAI,KAAK,IAAK,KAAK,KAAK,GAAG,KAAK,CAAC;AAC1C;AAGO,SAAS,QAAQ,KAAa,GAAmB;AACtD,QAAM,KAAK,MAAM,GAAG;AACpB,KAAG,QAAQ,GAAG,QAAQ,IAAI,CAAC;AAC3B,SAAO,SAAS,EAAE;AACpB;AAGO,SAAS,YAAY,MAAc,IAAoB;AAC5D,SAAO,KAAK,OAAO,MAAM,EAAE,EAAE,QAAQ,IAAI,MAAM,IAAI,EAAE,QAAQ,KAAK,KAAU;AAC9E;","names":["newerKindOf","newerKindOf"]}
@@ -590,4 +590,4 @@ export {
590
590
  guessColumn,
591
591
  shapeTextOfNode
592
592
  };
593
- //# sourceMappingURL=chunk-SYHUPGCU.js.map
593
+ //# sourceMappingURL=chunk-6Z537SLG.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/tableShape.ts","../src/kindValues.ts"],"sourcesContent":["// src/tableShape.ts — @ai-matrx/records-ui · lane SAVE-AS-TABLE-EVERYWHERE\n//\n// WHAT IN THIS TEXT IS ALREADY A TABLE. Arman, 2026-09-29: anywhere information appears in a shape\n// the system understands — a markdown table, a list or even a few bullet points, key:value lines,\n// a CSV or TSV paste, a kind value, JSON rows — the SAME \"Save to a table\" must exist. This module\n// is the one reader of those shapes: every menu asks it whether to offer the action, and the one\n// screen (`SaveToTable`) asks it for the rows. It is pure (no React, no store) so a guard, a server\n// render and a menu predicate read the same answer.\n//\n// IT IS A PARSE, NOT AN IMPORTER. It turns words into headers and rows and says what it read, in a\n// sentence. What a column IS in a table that already exists is the store's (`custom.io_import_plan`);\n// `guessColumn` only proposes the types of a NEW table's columns, and the person changes any of it\n// before anything is made.\n\nimport { codeSpanText, findTableEnd, mapInlineCodeSpans, rowCells, tableStartsAt } from \"@ai-matrx/content-ir/source\";\nimport { kindValueOf } from \"./kindValues\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\nimport { parseDelimited as readDelimited } from \"@ai-matrx/kit/delimited\";\n\n/** What kind of thing the rows were read from. */\nexport type TableShapeKind = \"table\" | \"csv\" | \"tsv\" | \"list\" | \"key_value\" | \"kind\" | \"rows\";\n\n/** Another honest way to read a list: every item split at the same delimiter. */\nexport interface TableShapeSplit {\n /** The delimiter, exactly as it sits in the items. */\n delimiter: string;\n /** The choice in words (\"Split at the dash\"). */\n label: string;\n headers: string[];\n rows: Array<Record<string, string>>;\n}\n\nexport interface TableShape {\n kind: TableShapeKind;\n /** Column labels, unique and never blank, in the order the text has them. */\n headers: string[];\n /** Every row, keyed by label. A cell the text left empty is \"\". */\n rows: Array<Record<string, string>>;\n /** One sentence a person reads: what was found and how big it is. */\n said: string;\n /** A name the text itself suggests (the heading above it), or null. */\n name: string | null;\n /** For a list: the other readings on offer. Empty for everything else. */\n splits: TableShapeSplit[];\n /** Where the shape sits in the text, as character offsets (a kind value / JSON value has none). */\n at: { start: number; end: number } | null;\n}\n\n/** The fewest items a plain list needs before it reads as rows (\"even a few bullet points\"). */\nexport const FEWEST_LIST_ITEMS = 2;\n/** The fewest `Key: value` lines that read as one record. */\nexport const FEWEST_KEY_VALUE_PAIRS = 2;\n/** Past this many characters a text is not read at all — a paste that big is a file, and the file import reads files. */\nexport const LONGEST_TEXT_READ = 2_000_000;\n\n// ── cells ──────────────────────────────────────────────────────────────────\n\n/** A markdown cell as the words it shows: emphasis, code ticks and link syntax removed (code spans by THE rule, `findInlineCodeSpans`). */\nexport function cellWords(raw: string): string {\n return mapInlineCodeSpans(raw, (_range, span) => codeSpanText(span))\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, \"$1\")\n .replace(/\\[([^\\]]+)\\]\\(([^)]*)\\)/g, \"$1\")\n .replace(/\\*\\*([^*]+)\\*\\*/g, \"$1\")\n .replace(/__([^_]+)__/g, \"$1\")\n .replace(/(^|[^\\w*])\\*([^*\\n]+)\\*(?=[^\\w*]|$)/g, \"$1$2\")\n .replace(/(^|[^\\w_])_([^_\\n]+)_(?=[^\\w_]|$)/g, \"$1$2\")\n .replace(/~~([^~]+)~~/g, \"$1\")\n .replace(/\\\\\\|/g, \"|\")\n .trim();\n}\n\n/** Labels made unique and never blank: a second \"Name\" is \"Name 2\", a blank is \"Column 3\". */\nexport function uniqueLabels(raw: readonly string[]): string[] {\n const seen = new Map<string, number>();\n return raw.map((label, index) => {\n const base = label.trim() || `Column ${index + 1}`;\n const key = base.toLowerCase();\n const count = (seen.get(key) ?? 0) + 1;\n seen.set(key, count);\n return count === 1 ? base : `${base} ${count}`;\n });\n}\n\nfunction rowsOf(headers: string[], matrix: string[][]): Array<Record<string, string>> {\n return matrix\n .filter((cells) => cells.some((c) => c.trim() !== \"\"))\n .map((cells) => {\n const row: Record<string, string> = {};\n headers.forEach((h, i) => {\n row[h] = (cells[i] ?? \"\").trim();\n });\n return row;\n });\n}\n\nfunction plural(n: number, one: string, many: string): string {\n return `${n} ${n === 1 ? one : many}`;\n}\n\nfunction sizeWords(rows: number, columns: number): string {\n return `${plural(rows, \"row\", \"rows\")} and ${plural(columns, \"column\", \"columns\")}`;\n}\n\n// ── the name the text suggests ─────────────────────────────────────────────\n\nconst HEADING = /^\\s{0,3}#{1,6}\\s+(.+?)\\s*#*\\s*$/;\nconst BOLD_LINE = /^\\s*\\*\\*([^*]+)\\*\\*:?\\s*$/;\nconst LEAD_IN = /^\\s*([^|\\-*+#>`].{1,80}?):\\s*$/;\n\n/**\n * The name the text gives what follows: the line right above it when that is a heading, a bold\n * line or a lead-in ending in a colon (\"Exercises:\"), else the nearest heading within a few lines.\n */\nfunction nameAbove(lines: string[], lineIndex: number): string | null {\n let looked = 0;\n for (let i = lineIndex - 1; i >= 0 && looked < 4; i -= 1) {\n const line = lines[i] ?? \"\";\n if (line.trim() === \"\") continue;\n looked += 1;\n const m = HEADING.exec(line) ?? (looked === 1 ? (BOLD_LINE.exec(line) ?? LEAD_IN.exec(line)) : null);\n if (m) return cellWords(m[1]!).replace(/:$/, \"\").trim() || null;\n }\n return null;\n}\n\n// ── markdown tables ────────────────────────────────────────────────────────\n\n/** A table row's cells, read by THE GFM rule (`@ai-matrx/content-ir/source`) and reduced to words. */\nfunction splitPipes(line: string): string[] {\n return rowCells(line).map(cellWords);\n}\n\n// ── lists and key:value lines ──────────────────────────────────────────────\n\nconst LIST_ITEM = /^(\\s*)(?:[-*+•]|\\d{1,3}[.)])\\s+(?:\\[[ xX]\\]\\s+)?(.*)$/;\n/** `Key: value` — the key short, the kind of words a column is named with. */\nconst KEY_VALUE = /^\\s*(?:\\*\\*|__)?([^:*_|]{1,40}?)(?::(?:\\*\\*|__)|(?:\\*\\*|__):|:)\\s+(.+)$/;\n\ninterface ListItem {\n depth: number;\n text: string;\n children: string[];\n}\n\nfunction keyValueOf(text: string): { key: string; value: string } | null {\n const m = KEY_VALUE.exec(text);\n if (!m) return null;\n const key = cellWords(m[1]!);\n const value = cellWords(m[2]!);\n if (!key || !value) return null;\n // A key is a column's name: a few words, not a clause, not a time of day (\"10:30\").\n if (key.split(/\\s+/).length > 5 || /^\\d+$/.test(key) || /https?$/i.test(key)) return null;\n return { key, value };\n}\n\n/** Records from key:value pairs: a new record starts each time the first key comes round again. */\nfunction recordsFromPairs(pairs: Array<{ key: string; value: string }>): Array<Map<string, string>> {\n const records: Array<Map<string, string>> = [];\n let current = new Map<string, string>();\n const first = pairs[0]?.key.toLowerCase();\n for (const pair of pairs) {\n const k = pair.key.toLowerCase();\n if (current.size > 0 && (k === first || [...current.keys()].some((c) => c.toLowerCase() === k))) {\n records.push(current);\n current = new Map();\n }\n current.set(pair.key, pair.value);\n }\n if (current.size > 0) records.push(current);\n return records;\n}\n\nfunction shapeFromRecords(\n records: Array<Map<string, string>>,\n base: Omit<TableShape, \"headers\" | \"rows\" | \"said\" | \"kind\" | \"splits\">,\n from: string,\n): TableShape {\n const order: string[] = [];\n for (const r of records) for (const k of r.keys()) if (!order.some((o) => o.toLowerCase() === k.toLowerCase())) order.push(k);\n const headers = uniqueLabels(order);\n const rows = records.map((r) => {\n const row: Record<string, string> = {};\n order.forEach((k, i) => {\n const hit = [...r.entries()].find(([rk]) => rk.toLowerCase() === k.toLowerCase());\n row[headers[i]!] = hit ? hit[1] : \"\";\n });\n return row;\n });\n return {\n ...base,\n kind: \"key_value\",\n headers,\n rows,\n splits: [],\n said:\n rows.length === 1\n ? `One record with ${plural(headers.length, \"value\", \"values\")} from ${from}`\n : `${sizeWords(rows.length, headers.length)} from ${from}`,\n };\n}\n\nconst SPLITS: Array<{ delimiter: string; label: string }> = [\n { delimiter: \" — \", label: \"Split at the dash\" },\n { delimiter: \" – \", label: \"Split at the dash\" },\n { delimiter: \" - \", label: \"Split at the hyphen\" },\n { delimiter: \": \", label: \"Split at the colon\" },\n { delimiter: \" | \", label: \"Split at the bar\" },\n { delimiter: \"\\t\", label: \"Split at the tab\" },\n { delimiter: \", \", label: \"Split at each comma\" },\n];\n\nfunction listSplits(items: string[]): TableShapeSplit[] {\n const out: TableShapeSplit[] = [];\n for (const { delimiter, label } of SPLITS) {\n if (!items.every((t) => t.includes(delimiter))) continue;\n if (out.some((s) => s.label === label)) continue;\n const every = delimiter === \", \";\n const parts = items.map((t) => (every ? t.split(delimiter) : [t.slice(0, t.indexOf(delimiter)), t.slice(t.indexOf(delimiter) + delimiter.length)]));\n const width = Math.max(...parts.map((p) => p.length));\n const headers = uniqueLabels(width === 2 ? [\"Item\", \"Detail\"] : Array.from({ length: width }, (_, i) => (i === 0 ? \"Item\" : `Detail ${i}`)));\n out.push({ delimiter, label, headers, rows: rowsOf(headers, parts.map((p) => p.map((c) => cellWords(c)))) });\n }\n return out;\n}\n\nfunction shapeFromList(items: ListItem[], name: string | null, at: TableShape[\"at\"]): TableShape | null {\n const top = items.filter((i) => i.depth === 0);\n if (top.length === 0) return null;\n // (1) Every item names a record and its children are that record's values.\n const withChildren = top.filter((i) => i.children.length > 0);\n if (withChildren.length === top.length && top.length >= 1) {\n const childPairs = top.map((i) => i.children.map(keyValueOf));\n if (childPairs.every((ps) => ps.length > 0 && ps.every((p) => p !== null))) {\n const lead = \"Name\";\n const records = top.map((item, idx) => {\n const r = new Map<string, string>();\n r.set(lead, cellWords(item.text).replace(/:$/, \"\"));\n for (const p of childPairs[idx]!) r.set(p!.key, p!.value);\n return r;\n });\n return shapeFromRecords(records, { name, at }, \"a list\");\n }\n }\n // (2) Every item is `Key: value` — one record, or several when the keys come round again.\n const pairs = top.map((i) => keyValueOf(i.text));\n if (pairs.length >= FEWEST_KEY_VALUE_PAIRS && pairs.every((p) => p !== null)) {\n const records = recordsFromPairs(pairs as Array<{ key: string; value: string }>);\n const sameKeys = records.every((r) => r.size === records[0]!.size);\n if (records.length === 1 || (sameKeys && records[0]!.size >= 2)) return shapeFromRecords(records, { name, at }, \"a list\");\n }\n // (3) A plain list — one column, or split, and the children kept beside their item.\n if (top.length < FEWEST_LIST_ITEMS) return null;\n const texts = top.map((i) => cellWords(i.text));\n const anyChildren = top.some((i) => i.children.length > 0);\n const headers = anyChildren ? [\"Item\", \"Details\"] : [\"Item\"];\n const rows = top.map((item, idx) => {\n const row: Record<string, string> = { Item: texts[idx]! };\n if (anyChildren) row.Details = item.children.map(cellWords).join(\"; \");\n return row;\n });\n return {\n kind: \"list\",\n headers,\n rows,\n name,\n at,\n splits: anyChildren ? [] : listSplits(texts),\n said: `${plural(rows.length, \"item\", \"items\")} from a list`,\n };\n}\n\n// ── CSV / TSV ──────────────────────────────────────────────────────────────\n\n/** CSV/TSV rows with the all-blank lines dropped — THE one reader (kit `parseDelimited`). */\nexport function parseDelimited(text: string, delimiter: \",\" | \"\\t\"): string[][] {\n return readDelimited(text, { delimiter, skipEmptyLines: \"greedy\" }).data;\n}\n\n/** A whole text that is delimited rows: every line the same width, at least two columns. */\nfunction delimitedShape(text: string, delimiter: \",\" | \"\\t\", fenced: boolean, at: TableShape[\"at\"], name: string | null): TableShape | null {\n const matrix = parseDelimited(text.trim(), delimiter);\n if (matrix.length < 2) return null;\n const width = matrix[0]!.length;\n if (width < 2) return null;\n const same = matrix.filter((r) => r.length === width).length;\n if (same / matrix.length < 0.9) return null;\n if (!fenced) {\n // Prose has commas too. A CSV cell is short; a sentence is not.\n const cells = matrix.flat();\n const long = cells.filter((c) => c.trim().length > 80).length;\n if (delimiter === \",\" && (long / cells.length > 0.2 || matrix.length < 2)) return null;\n }\n const headers = uniqueLabels(matrix[0]!.map((c) => c.trim()));\n const rows = rowsOf(headers, matrix.slice(1));\n if (rows.length === 0) return null;\n const kind = delimiter === \"\\t\" ? \"tsv\" : \"csv\";\n return {\n kind,\n headers,\n rows,\n name,\n at,\n splits: [],\n said: `${sizeWords(rows.length, headers.length)} from ${kind === \"tsv\" ? \"pasted spreadsheet cells\" : \"CSV\"}`,\n };\n}\n\n// ── JSON and kind values ───────────────────────────────────────────────────\n\nfunction cellOf(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") return String(value);\n if (Array.isArray(value) && value.every((v) => typeof v !== \"object\" || v === null)) return value.map(cellOf).join(\", \");\n // A nested object (a kind value included) is kept whole, `__kind` and all — it is part of the data.\n return JSON.stringify(value);\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** A key as a column's label: `body_area` → \"Body area\"; a key already in words stays as written. */\nfunction labelOfKey(key: string): string {\n return /[\\s]/.test(key) || /^[A-Z]/.test(key) ? key : humanizeIdentifier(key);\n}\n\nfunction shapeFromObjects(objects: Array<Record<string, unknown>>, kind: TableShapeKind, from: string, name: string | null): TableShape | null {\n if (objects.length === 0) return null;\n const keys: string[] = [];\n for (const o of objects) for (const k of Object.keys(o)) if (k !== \"__kind\" && !keys.includes(k)) keys.push(k);\n if (keys.length === 0) return null;\n const headers = uniqueLabels(keys.map(labelOfKey));\n const rows = objects.map((o) => {\n const row: Record<string, string> = {};\n keys.forEach((k, i) => {\n row[headers[i]!] = cellOf(o[k]);\n });\n return row;\n });\n return { kind, headers, rows, name, at: null, splits: [], said: `${sizeWords(rows.length, headers.length)} from ${from}` };\n}\n\n/**\n * THE ROWS A VALUE HOLDS — a kind value (`__kind`, or a Matrx directive read by the one decoder),\n * a JSON array of objects, or an object whose largest member is one. Null when it holds none.\n */\nexport function shapeOfValue(value: unknown, name: string | null = null): TableShape | null {\n let v: unknown = value;\n if (typeof v === \"string\") {\n const t = v.trim();\n const fence = /^```(?:json|matrx)?\\s*\\n?([\\s\\S]*?)\\n?```$/.exec(t);\n const body = fence ? fence[1]!.trim() : t;\n if (!(body.startsWith(\"{\") || body.startsWith(\"[\"))) return null;\n try {\n v = JSON.parse(body);\n } catch {\n return null;\n }\n }\n if (Array.isArray(v)) {\n const objects = v.filter(isPlainObject);\n if (objects.length === 0 || objects.length < v.length) return null;\n return shapeFromObjects(objects, \"rows\", \"JSON rows\", name);\n }\n if (!isPlainObject(v)) return null;\n const kv = kindValueOf(v);\n if (kv) {\n const label = kv.kind.replace(/^directive_v\\d+_/, \"\").replace(/_/g, \" \");\n if (kv.items.length > 0) return shapeFromObjects(kv.items, \"kind\", `a ${label}`, name);\n const scalars = Object.fromEntries(Object.entries(v).filter(([k, x]) => k !== \"__kind\" && (typeof x !== \"object\" || x === null)));\n const shape = shapeFromObjects([scalars], \"kind\", `a ${label}`, name);\n if (shape) return shape;\n }\n // An object carrying one list of records: {\"exercises\": [{…}, {…}]} — the largest one.\n let best: { key: string; items: Array<Record<string, unknown>> } | null = null;\n for (const [key, member] of Object.entries(v)) {\n if (Array.isArray(member) && member.length > 0 && member.every(isPlainObject)) {\n if (!best || member.length > best.items.length) best = { key, items: member };\n }\n }\n if (best) return shapeFromObjects(best.items, kv ? \"kind\" : \"rows\", \"JSON rows\", name ?? labelOfKey(best.key));\n return null;\n}\n\n// ── the document reader ────────────────────────────────────────────────────\n\n/**\n * EVERY SHAPE IN A TEXT, top to bottom: markdown tables, lists, runs of `Key: value` lines,\n * fenced CSV / TSV / JSON blocks — and when the whole text is one CSV or TSV paste, that.\n * An empty array means the text holds nothing that reads as rows, and a menu offers nothing.\n */\nexport function readTableShapes(text: string): TableShape[] {\n if (typeof text !== \"string\" || text.trim() === \"\" || text.length > LONGEST_TEXT_READ) return [];\n const whole = text.trim();\n\n // A whole value (a kind value / JSON rows pasted or stored as the content).\n if (whole.startsWith(\"{\") || whole.startsWith(\"[\") || /^```(?:json|matrx)/.test(whole)) {\n const s = shapeOfValue(whole);\n if (s) return [{ ...s, at: { start: 0, end: text.length } }];\n }\n // A whole paste of spreadsheet cells or CSV (no markdown at all).\n if (!/^\\s*[|#>*-]/m.test(whole)) {\n if (whole.includes(\"\\t\")) {\n const s = delimitedShape(whole, \"\\t\", false, { start: 0, end: text.length }, null);\n if (s) return [s];\n }\n const s = delimitedShape(whole, \",\", false, { start: 0, end: text.length }, null);\n if (s) return [s];\n }\n\n const lines = text.split(/\\r?\\n/);\n const offsets: number[] = [];\n let pos = 0;\n for (const line of lines) {\n offsets.push(pos);\n pos += line.length + 1;\n }\n const endOf = (i: number) => (offsets[i] ?? 0) + (lines[i]?.length ?? 0);\n const shapes: TableShape[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i] ?? \"\";\n\n // Fenced blocks: CSV / TSV / JSON are read; any other fence is skipped whole.\n const fence = /^\\s*```\\s*([\\w-]*)\\s*$/.exec(line);\n if (fence) {\n let j = i + 1;\n while (j < lines.length && !/^\\s*```\\s*$/.test(lines[j] ?? \"\")) j += 1;\n const body = lines.slice(i + 1, j).join(\"\\n\");\n const lang = fence[1]!.toLowerCase();\n const at = { start: offsets[i]!, end: endOf(Math.min(j, lines.length - 1)) };\n const name = nameAbove(lines, i);\n let s: TableShape | null = null;\n if (lang === \"csv\") s = delimitedShape(body, \",\", true, at, name);\n else if (lang === \"tsv\") s = delimitedShape(body, \"\\t\", true, at, name);\n else if (lang === \"json\" || lang === \"matrx\") s = shapeOfValue(body, name);\n if (s) shapes.push({ ...s, at });\n i = j + 1;\n continue;\n }\n\n // A markdown table: a row of pipes, then the separator row.\n if (tableStartsAt(lines, i)) {\n const headers = uniqueLabels(splitPipes(line));\n const j = findTableEnd(lines, i);\n const matrix: string[][] = [];\n for (let r = i + 2; r < j; r += 1) matrix.push(splitPipes(lines[r]!));\n const rows = rowsOf(headers, matrix);\n if (headers.length >= 1 && rows.length >= 1) {\n shapes.push({\n kind: \"table\",\n headers,\n rows,\n name: nameAbove(lines, i),\n at: { start: offsets[i]!, end: endOf(j - 1) },\n splits: [],\n said: `${sizeWords(rows.length, headers.length)} from a table`,\n });\n }\n i = j;\n continue;\n }\n\n // A list: consecutive items (a single blank line between items is still the same list).\n const item = LIST_ITEM.exec(line);\n if (item) {\n const baseIndent = item[1]!.length;\n const items: ListItem[] = [];\n let j = i;\n while (j < lines.length) {\n const l = lines[j] ?? \"\";\n const m = LIST_ITEM.exec(l);\n if (m) {\n const depth = m[1]!.length > baseIndent ? 1 : 0;\n if (depth === 0) items.push({ depth: 0, text: m[2]!, children: [] });\n else if (items.length > 0) items[items.length - 1]!.children.push(m[2]!);\n j += 1;\n continue;\n }\n if (l.trim() === \"\" && LIST_ITEM.test(lines[j + 1] ?? \"\")) {\n j += 1;\n continue;\n }\n // A wrapped line of the item above it.\n if (l.trim() !== \"\" && /^\\s{2,}\\S/.test(l) && items.length > 0) {\n items[items.length - 1]!.text += ` ${l.trim()}`;\n j += 1;\n continue;\n }\n break;\n }\n const s = shapeFromList(items, nameAbove(lines, i), { start: offsets[i]!, end: endOf(j - 1) });\n if (s) shapes.push(s);\n i = j;\n continue;\n }\n\n // A run of `Key: value` lines outside a list (a form result, a record written out).\n if (keyValueOf(line)) {\n let j = i;\n const pairs: Array<{ key: string; value: string }> = [];\n while (j < lines.length) {\n const l = lines[j] ?? \"\";\n const p = keyValueOf(l);\n if (p) {\n pairs.push(p);\n j += 1;\n continue;\n }\n if (l.trim() === \"\" && keyValueOf(lines[j + 1] ?? \"\")) {\n j += 1;\n continue;\n }\n break;\n }\n if (pairs.length >= FEWEST_KEY_VALUE_PAIRS) {\n const records = recordsFromPairs(pairs);\n const sameKeys = records.every((r) => r.size === records[0]!.size);\n if (records.length === 1 || (sameKeys && records[0]!.size >= 2)) {\n shapes.push(shapeFromRecords(records, { name: nameAbove(lines, i), at: { start: offsets[i]!, end: endOf(j - 1) } }, \"key and value lines\"));\n } else {\n // Keys that come round in no fixed order are a conversation: who, and what they said.\n const headers = [\"Name\", \"Text\"];\n shapes.push({\n kind: \"key_value\",\n headers,\n rows: pairs.map((p) => ({ Name: p.key, Text: p.value })),\n name: nameAbove(lines, i),\n at: { start: offsets[i]!, end: endOf(j - 1) },\n splits: [],\n said: `${plural(pairs.length, \"line\", \"lines\")}, each a name and what was said`,\n });\n }\n }\n i = Math.max(j, i + 1);\n continue;\n }\n i += 1;\n }\n return shapes;\n}\n\n/** The first shape in a text, or null — what a one-shape menu item acts on. */\nexport function readFirstTableShape(text: string): TableShape | null {\n return readTableShapes(text)[0] ?? null;\n}\n\n/** True when the text holds anything that reads as rows — every menu's \"offer it?\" predicate. */\nexport function hasTableShape(text: string): boolean {\n return readTableShapes(text).length > 0;\n}\n\n/** Headers + string rows — the shape a table renderer already holds, read as a TableShape. */\nexport function shapeOfGrid(\n headers: readonly string[],\n cells: ReadonlyArray<ReadonlyArray<string>>,\n name: string | null = null,\n /** What the rows came out of, in a word: \"table\" (a rendered table), \"sheet\" (a workbook's sheet). */\n from: string = \"table\",\n): TableShape | null {\n const labels = uniqueLabels(headers.map((h) => cellWords(String(h ?? \"\"))));\n const rows = rowsOf(labels, cells.map((r) => r.map((c) => cellWords(String(c ?? \"\")))));\n if (labels.length === 0) return null;\n // Column names with no rows under them are still a table to make (the file importer's header-only\n // file: \"the table will be created with these columns and no rows yet\").\n const said = rows.length === 0 ? `${plural(labels.length, \"column\", \"columns\")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a ${from}`;\n return { kind: \"table\", headers: labels, rows, name, at: null, splits: [], said };\n}\n\n// ── what a NEW table's columns should be ───────────────────────────────────\n\n/** A type word `custom.field_declare` takes, from `FIELD_TYPE_CHOICES`. */\nexport type GuessedFieldType =\n | \"text\"\n | \"long_text\"\n | \"number\"\n | \"currency\"\n | \"percent\"\n | \"datetime\"\n | \"checkbox\"\n | \"email\"\n | \"url\"\n | \"phone\"\n | \"select\";\n\nexport interface ColumnGuess {\n type: GuessedFieldType;\n /** A choice column's words, in the order the text first used them. */\n options?: string[];\n /** A money column's symbol. */\n unit?: string;\n /** A date column that never carries a time of day. */\n kind?: \"date\" | \"datetime\";\n}\n\n/** The most words a choice column's list may hold before it reads as text. */\nexport const MOST_GUESSED_CHOICES = 12;\n\nconst NUMBER = /^[+-]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?$/;\nconst MONEY = /^([$€£¥])\\s?([+-]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?)$/;\nconst PERCENT = /^[+-]?\\d+(?:\\.\\d+)?\\s?%$/;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}(?:[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?)?$/;\nconst SLASH_DATE = /^\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}$/;\nconst WORD_DATE = /^(?:\\d{1,2}\\s+)?(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\\.?\\s+\\d{1,2}(?:st|nd|rd|th)?,?\\s+\\d{4}$|^\\d{1,2}\\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\\.?\\s+\\d{4}$/i;\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\nconst URL_WORD = /^https?:\\/\\/\\S+$/i;\nconst PHONE = /^\\+?[\\d\\s().-]{7,20}$/;\nconst YES = new Set([\"yes\", \"true\", \"y\", \"✓\", \"✔\", \"checked\", \"done\"]);\nconst NO = new Set([\"no\", \"false\", \"n\", \"✗\", \"✘\", \"unchecked\", \"\"]);\n\nfunction isDate(v: string): boolean {\n return ISO_DATE.test(v) || SLASH_DATE.test(v) || WORD_DATE.test(v);\n}\n\n/**\n * WHAT A NEW TABLE'S COLUMN SHOULD HOLD, proposed from every value in it. A column is a number, a\n * date, a yes/no, an email… only when EVERY non-blank value reads as one — one value that does not\n * (\"10-15\" among the Reps) keeps the column text, because a guess that loses a person's words is\n * worse than a text column. A few short words that repeat are a Choice, with those words as its\n * choices. It is a proposal the person sees and changes before anything is made.\n */\nexport function guessColumn(values: ReadonlyArray<string>): ColumnGuess {\n const filled = values.map((v) => String(v ?? \"\").trim()).filter((v) => v !== \"\");\n if (filled.length === 0) return { type: \"text\" };\n const every = (test: (v: string) => boolean) => filled.every(test);\n if (every((v) => YES.has(v.toLowerCase()) || NO.has(v.toLowerCase())) && filled.some((v) => YES.has(v.toLowerCase())) && filled.some((v) => !/^\\d+$/.test(v))) {\n return { type: \"checkbox\" };\n }\n if (every((v) => NUMBER.test(v))) return { type: \"number\" };\n if (every((v) => MONEY.test(v))) {\n const symbols = new Set(filled.map((v) => MONEY.exec(v)![1]!));\n if (symbols.size === 1) return { type: \"currency\", unit: [...symbols][0]! };\n }\n if (every((v) => PERCENT.test(v))) return { type: \"percent\" };\n if (every(isDate)) return { type: \"datetime\", kind: every((v) => !/\\d:\\d/.test(v)) ? \"date\" : \"datetime\" };\n if (every((v) => EMAIL.test(v))) return { type: \"email\" };\n if (every((v) => URL_WORD.test(v))) return { type: \"url\" };\n if (every((v) => PHONE.test(v) && (v.match(/\\d/g)?.length ?? 0) >= 7)) return { type: \"phone\" };\n if (filled.some((v) => v.length > 120 || v.includes(\"\\n\"))) return { type: \"long_text\" };\n const distinct: string[] = [];\n for (const v of filled) if (!distinct.some((d) => d.toLowerCase() === v.toLowerCase())) distinct.push(v);\n const short = every((v) => v.length <= 40 && v.split(/\\s+/).length <= 5);\n // Counts and ranges (\"10\", \"10-15\") repeat too, and they are measurements, not a list to pick from.\n const words = filled.filter((v) => !/\\d/.test(v)).length >= filled.length / 2;\n if (filled.length >= 3 && short && words && distinct.length < filled.length && distinct.length <= MOST_GUESSED_CHOICES) {\n return { type: \"select\", options: distinct };\n }\n return { type: \"text\" };\n}\n\n// ── what a selection over RENDERED content holds ───────────────────────────\n\nconst BLOCK_TAGS = new Set([\"P\", \"DIV\", \"SECTION\", \"ARTICLE\", \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"BLOCKQUOTE\", \"PRE\", \"HEADER\", \"FOOTER\", \"BR\", \"HR\", \"DL\", \"DT\", \"DD\"]);\n\n/**\n * THE WORDS OF A SELECTION, WITH ITS SHAPE KEPT (VERIFIER-30 #1). A browser selection over a rendered\n * answer flattens to text in which a table's header cells come one per line and a list's bullets are\n * gone, so `readTableShapes` found nothing in exactly the places a person selects rows. This walks the\n * selected DOM (a `Range.cloneContents()` fragment, or any node) and writes it back as the shapes it\n * was drawn from: a table's rows as a markdown table (the first row its heading), a list's items as\n * bullets (nested items indented), every other block on its own line.\n */\nexport function shapeTextOfNode(node: Node): string {\n const out: string[] = [];\n let line = \"\";\n let rows: string[][] = [];\n const flushLine = () => {\n if (line.trim() !== \"\") out.push(line.trim());\n line = \"\";\n };\n const flushRows = () => {\n if (rows.length === 0) return;\n flushLine();\n const width = Math.max(...rows.map((r) => r.length));\n const pad = (r: string[]) => [...r, ...Array.from({ length: width - r.length }, () => \"\")];\n const cell = (c: string) => c.replace(/\\|/g, \"\\\\|\").replace(/\\s+/g, \" \").trim();\n out.push(`| ${pad(rows[0]!).map(cell).join(\" | \")} |`);\n out.push(`|${Array.from({ length: width }, () => \"---\").join(\"|\")}|`);\n for (const r of rows.slice(1)) out.push(`| ${pad(r).map(cell).join(\" | \")} |`);\n rows = [];\n };\n const textOf = (n: Node): string => (n.textContent ?? \"\").replace(/\\s+/g, \" \").trim();\n const walk = (n: Node, depth: number): void => {\n if (n.nodeType === 3) {\n line += n.textContent ?? \"\";\n return;\n }\n if (n.nodeType !== 1 && n.nodeType !== 11) return;\n const el = n as Element;\n const tag = n.nodeType === 1 ? el.tagName.toUpperCase() : \"#fragment\";\n if (tag === \"TR\") {\n const cells = Array.from(el.children).filter((c) => /^(TD|TH)$/i.test(c.tagName));\n rows.push(cells.map((c) => textOf(c)));\n return;\n }\n if (tag === \"TABLE\" || tag === \"THEAD\" || tag === \"TBODY\" || tag === \"TFOOT\") {\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n if (tag === \"TABLE\") flushRows();\n return;\n }\n flushRows();\n if (tag === \"LI\") {\n flushLine();\n const own: string[] = [];\n const nested: Node[] = [];\n for (const child of Array.from(n.childNodes)) {\n if (child.nodeType === 1 && /^(UL|OL)$/i.test((child as Element).tagName)) nested.push(child);\n else own.push(child.textContent ?? \"\");\n }\n const words = own.join(\"\").replace(/\\s+/g, \" \").trim();\n if (words) out.push(`${\" \".repeat(depth)}- ${words}`);\n for (const list of nested) walk(list, depth + 1);\n return;\n }\n if (tag === \"UL\" || tag === \"OL\") {\n flushLine();\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n flushLine();\n return;\n }\n const block = BLOCK_TAGS.has(tag);\n if (block) flushLine();\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n if (block) flushLine();\n };\n walk(node, 0);\n flushRows();\n flushLine();\n return out.join(\"\\n\");\n}\n","// src/kindValues.ts — @ai-matrx/records-ui · lane REFERENCE-CARRY\n//\n// A CELL THAT HOLDS A KIND. A value is a kind value when it names its own shape — `__kind` — or\n// when it is a stored Matrx directive written before the Kind Directives merge (the retired 4-key\n// shell `{\"matrx_version\": 1, \"kind\": \"reference\", \"type\": \"scope\", \"items\": [...]}`, usually inside\n// a ```matrx fence). Before this, a text cell holding either printed the raw fence: Arman's\n// Department table, 2026-09-28 — Team Leader read ```matrx {\"matrx_version\":1,…}```.\n//\n// THE SHELL IS UNDERSTOOD IN ONE PLACE. Whether an object is a directive — the current shell, or\n// the retired one stored before the merge — is `@ai-matrx/content-ir/directives`' `tryDecodeDirective`\n// alone (its containment guard keeps the retired shell there). This module only takes the object out\n// of its fence and hands it, untouched, to the host's `renderKind` port, which draws it through the\n// kind system. New values are stored as `__kind` JSON, never as a fence.\n\nimport { tryDecodeDirective } from \"@ai-matrx/content-ir/directives\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\n\n/** What a cell holds when it holds a kind. */\nexport interface KindValue {\n /** The parsed object, exactly as stored (`__kind` kept — it is part of the data). */\n value: Record<string, unknown>;\n /**\n * The kind's own name: `__kind`, or for a directive the slug the one decoder reads\n * (`directive_v1_reference_scope`, the retired shell included).\n */\n kind: string;\n /** True when the one decoder read this as a Matrx directive. */\n directive: boolean;\n /** The items a directive carries (a reference's chips), when it carries any. */\n items: Record<string, unknown>[];\n}\n\nconst KIND_KEY = \"__kind\";\n/** One fenced block and nothing else: ```matrx {…}``` or ```json {…}```. */\nconst WHOLE_FENCE = /^\\s*```(?:matrx|json)?[ \\t]*\\r?\\n?([\\s\\S]*?)\\r?\\n?[ \\t]*```\\s*$/;\n\nfunction asObject(value: unknown): Record<string, unknown> | null {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;\n}\n\nfunction parseJsonObject(text: string): Record<string, unknown> | null {\n const trimmed = text.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) return null;\n try {\n return asObject(JSON.parse(trimmed));\n } catch {\n return null;\n }\n}\n\nfunction fromObject(obj: Record<string, unknown>): KindValue | null {\n // THE ONE DECODER decides what a directive is — the current two-key shell and, for stored\n // content only, the retired 4-key one. A directive it cannot honour is not drawn as one.\n const directive = tryDecodeDirective(obj);\n if (directive) return { value: obj, kind: directive.slug, directive: true, items: [...directive.items] };\n const named = obj[KIND_KEY];\n if (typeof named === \"string\" && named.trim() !== \"\") {\n const items = Array.isArray(obj.items) ? obj.items.filter((i): i is Record<string, unknown> => asObject(i) !== null) : [];\n return { value: obj, kind: named.trim(), directive: false, items };\n }\n return null;\n}\n/**\n * The kind value a cell holds, or null. An object with `__kind`, a string that is such an object's\n * JSON, or a string that is ONE fenced block of it (```matrx / ```json), the retired directive shell\n * included. Text that merely mentions a fence among other words is text, and stays text.\n */\nexport function kindValueOf(value: unknown): KindValue | null {\n const obj = asObject(value);\n if (obj) return fromObject(obj);\n if (typeof value !== \"string\" || value.length > 200_000) return null;\n const fenced = WHOLE_FENCE.exec(value);\n const parsed = parseJsonObject(fenced ? fenced[1]! : value);\n return parsed ? fromObject(parsed) : null;\n}\n\n/** The words an item names itself by (a reference's label, a title, a name). */\nexport function kindItemWords(item: Record<string, unknown>): string | null {\n for (const key of [\"label\", \"title\", \"name\", \"display_name\"]) {\n const v = item[key];\n if (typeof v === \"string\" && v.trim() !== \"\") return v.trim();\n }\n return null;\n}\n\n/**\n * A kind value in words, for a sentence, a card, a copy or an export: the items' own names when it\n * carries named items (\"Arman Sadeghi, Tahir Mahfooz\"), else what kind of thing it is.\n */\nexport function kindValueWords(kv: KindValue): string {\n const named = kv.items.map(kindItemWords).filter((w): w is string => w !== null);\n if (named.length > 0) return named.join(\", \");\n return kindLabel(kv.kind);\n}\n\n/** A kind's name the way a person reads it: `directive_v1_reference_scope` → \"Reference Scope\". */\nexport function kindLabel(kind: string): string {\n return humanizeIdentifier(kind.replace(/^directive_v\\d+_/, \"\").replace(/_v\\d+$/, \"\")) || \"Structured value\";\n}\n"],"mappings":";;;AAcA,SAAS,cAAc,cAAc,oBAAoB,UAAU,qBAAqB;;;ACAxF,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAi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eAAe,EAAE;AAAA,MACvC;AACA,YAAM,QAAQ,IAAI,KAAK,EAAE,EAAE,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACrD,UAAI,MAAO,KAAI,KAAK,GAAG,KAAK,OAAO,KAAK,CAAC,KAAK,KAAK,EAAE;AACrD,iBAAW,QAAQ,OAAQ,MAAK,MAAM,QAAQ,CAAC;AAC/C;AAAA,IACF;AACA,QAAI,QAAQ,QAAQ,QAAQ,MAAM;AAChC,gBAAU;AACV,iBAAW,SAAS,MAAM,KAAK,EAAE,UAAU,EAAG,MAAK,OAAO,KAAK;AAC/D,gBAAU;AACV;AAAA,IACF;AACA,UAAM,QAAQ,WAAW,IAAI,GAAG;AAChC,QAAI,MAAO,WAAU;AACrB,eAAW,SAAS,MAAM,KAAK,EAAE,UAAU,EAAG,MAAK,OAAO,KAAK;AAC/D,QAAI,MAAO,WAAU;AAAA,EACvB;AACA,OAAK,MAAM,CAAC;AACZ,YAAU;AACV,YAAU;AACV,SAAO,IAAI,KAAK,IAAI;AACtB;","names":["humanizeIdentifier","s","i"]}
1
+ {"version":3,"sources":["../src/tableShape.ts","../src/kindValues.ts"],"sourcesContent":["// src/tableShape.ts — @ai-matrx/records-ui · lane SAVE-AS-TABLE-EVERYWHERE\n//\n// WHAT IN THIS TEXT IS ALREADY A TABLE. Arman, 2026-09-29: anywhere information appears in a shape\n// the system understands — a markdown table, a list or even a few bullet points, key:value lines,\n// a CSV or TSV paste, a kind value, JSON rows — the SAME \"Save to a table\" must exist. This module\n// is the one reader of those shapes: every menu asks it whether to offer the action, and the one\n// screen (`SaveToTable`) asks it for the rows. It is pure (no React, no store) so a guard, a server\n// render and a menu predicate read the same answer.\n//\n// IT IS A PARSE, NOT AN IMPORTER. It turns words into headers and rows and says what it read, in a\n// sentence. What a column IS in a table that already exists is the store's (`custom.io_import_plan`);\n// `guessColumn` only proposes the types of a NEW table's columns, and the person changes any of it\n// before anything is made.\n\nimport { codeSpanText, findTableEnd, mapInlineCodeSpans, rowCells, tableStartsAt } from \"@ai-matrx/content-ir/source\";\nimport { kindValueOf } from \"./kindValues\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\nimport { parseDelimited as readDelimited } from \"@ai-matrx/kit/delimited\";\n\n/** What kind of thing the rows were read from. */\nexport type TableShapeKind = \"table\" | \"csv\" | \"tsv\" | \"list\" | \"key_value\" | \"kind\" | \"rows\";\n\n/** Another honest way to read a list: every item split at the same delimiter. */\nexport interface TableShapeSplit {\n /** The delimiter, exactly as it sits in the items. */\n delimiter: string;\n /** The choice in words (\"Split at the dash\"). */\n label: string;\n headers: string[];\n rows: Array<Record<string, string>>;\n}\n\nexport interface TableShape {\n kind: TableShapeKind;\n /** Column labels, unique and never blank, in the order the text has them. */\n headers: string[];\n /** Every row, keyed by label. A cell the text left empty is \"\". */\n rows: Array<Record<string, string>>;\n /** One sentence a person reads: what was found and how big it is. */\n said: string;\n /** A name the text itself suggests (the heading above it), or null. */\n name: string | null;\n /** For a list: the other readings on offer. Empty for everything else. */\n splits: TableShapeSplit[];\n /** Where the shape sits in the text, as character offsets (a kind value / JSON value has none). */\n at: { start: number; end: number } | null;\n}\n\n/** The fewest items a plain list needs before it reads as rows (\"even a few bullet points\"). */\nexport const FEWEST_LIST_ITEMS = 2;\n/** The fewest `Key: value` lines that read as one record. */\nexport const FEWEST_KEY_VALUE_PAIRS = 2;\n/** Past this many characters a text is not read at all — a paste that big is a file, and the file import reads files. */\nexport const LONGEST_TEXT_READ = 2_000_000;\n\n// ── cells ──────────────────────────────────────────────────────────────────\n\n/** A markdown cell as the words it shows: emphasis, code ticks and link syntax removed (code spans by THE rule, `findInlineCodeSpans`). */\nexport function cellWords(raw: string): string {\n return mapInlineCodeSpans(raw, (_range, span) => codeSpanText(span))\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n .replace(/!\\[([^\\]]*)\\]\\([^)]*\\)/g, \"$1\")\n .replace(/\\[([^\\]]+)\\]\\(([^)]*)\\)/g, \"$1\")\n .replace(/\\*\\*([^*]+)\\*\\*/g, \"$1\")\n .replace(/__([^_]+)__/g, \"$1\")\n .replace(/(^|[^\\w*])\\*([^*\\n]+)\\*(?=[^\\w*]|$)/g, \"$1$2\")\n .replace(/(^|[^\\w_])_([^_\\n]+)_(?=[^\\w_]|$)/g, \"$1$2\")\n .replace(/~~([^~]+)~~/g, \"$1\")\n .replace(/\\\\\\|/g, \"|\")\n .trim();\n}\n\n/** Labels made unique and never blank: a second \"Name\" is \"Name 2\", a blank is \"Column 3\". */\nexport function uniqueLabels(raw: readonly string[]): string[] {\n const seen = new Map<string, number>();\n return raw.map((label, index) => {\n const base = label.trim() || `Column ${index + 1}`;\n const key = base.toLowerCase();\n const count = (seen.get(key) ?? 0) + 1;\n seen.set(key, count);\n return count === 1 ? base : `${base} ${count}`;\n });\n}\n\nfunction rowsOf(headers: string[], matrix: string[][]): Array<Record<string, string>> {\n return matrix\n .filter((cells) => cells.some((c) => c.trim() !== \"\"))\n .map((cells) => {\n const row: Record<string, string> = {};\n headers.forEach((h, i) => {\n row[h] = (cells[i] ?? \"\").trim();\n });\n return row;\n });\n}\n\nfunction plural(n: number, one: string, many: string): string {\n return `${n} ${n === 1 ? one : many}`;\n}\n\nfunction sizeWords(rows: number, columns: number): string {\n return `${plural(rows, \"row\", \"rows\")} and ${plural(columns, \"column\", \"columns\")}`;\n}\n\n// ── the name the text suggests ─────────────────────────────────────────────\n\nconst HEADING = /^\\s{0,3}#{1,6}\\s+(.+?)\\s*#*\\s*$/;\nconst BOLD_LINE = /^\\s*\\*\\*([^*]+)\\*\\*:?\\s*$/;\nconst LEAD_IN = /^\\s*([^|\\-*+#>`].{1,80}?):\\s*$/;\n\n/**\n * The name the text gives what follows: the line right above it when that is a heading, a bold\n * line or a lead-in ending in a colon (\"Exercises:\"), else the nearest heading within a few lines.\n */\nfunction nameAbove(lines: string[], lineIndex: number): string | null {\n let looked = 0;\n for (let i = lineIndex - 1; i >= 0 && looked < 4; i -= 1) {\n const line = lines[i] ?? \"\";\n if (line.trim() === \"\") continue;\n looked += 1;\n const m = HEADING.exec(line) ?? (looked === 1 ? (BOLD_LINE.exec(line) ?? LEAD_IN.exec(line)) : null);\n if (m) return cellWords(m[1]!).replace(/:$/, \"\").trim() || null;\n }\n return null;\n}\n\n// ── markdown tables ────────────────────────────────────────────────────────\n\n/** A table row's cells, read by THE GFM rule (`@ai-matrx/content-ir/source`) and reduced to words. */\nfunction splitPipes(line: string): string[] {\n return rowCells(line).map(cellWords);\n}\n\n// ── lists and key:value lines ──────────────────────────────────────────────\n\nconst LIST_ITEM = /^(\\s*)(?:[-*+•]|\\d{1,3}[.)])\\s+(?:\\[[ xX]\\]\\s+)?(.*)$/;\n/** `Key: value` — the key short, the kind of words a column is named with. */\nconst KEY_VALUE = /^\\s*(?:\\*\\*|__)?([^:*_|]{1,40}?)(?::(?:\\*\\*|__)|(?:\\*\\*|__):|:)\\s+(.+)$/;\n\ninterface ListItem {\n depth: number;\n text: string;\n children: string[];\n}\n\nfunction keyValueOf(text: string): { key: string; value: string } | null {\n const m = KEY_VALUE.exec(text);\n if (!m) return null;\n const key = cellWords(m[1]!);\n const value = cellWords(m[2]!);\n if (!key || !value) return null;\n // A key is a column's name: a few words, not a clause, not a time of day (\"10:30\").\n if (key.split(/\\s+/).length > 5 || /^\\d+$/.test(key) || /https?$/i.test(key)) return null;\n return { key, value };\n}\n\n/** Records from key:value pairs: a new record starts each time the first key comes round again. */\nfunction recordsFromPairs(pairs: Array<{ key: string; value: string }>): Array<Map<string, string>> {\n const records: Array<Map<string, string>> = [];\n let current = new Map<string, string>();\n const first = pairs[0]?.key.toLowerCase();\n for (const pair of pairs) {\n const k = pair.key.toLowerCase();\n if (current.size > 0 && (k === first || [...current.keys()].some((c) => c.toLowerCase() === k))) {\n records.push(current);\n current = new Map();\n }\n current.set(pair.key, pair.value);\n }\n if (current.size > 0) records.push(current);\n return records;\n}\n\nfunction shapeFromRecords(\n records: Array<Map<string, string>>,\n base: Omit<TableShape, \"headers\" | \"rows\" | \"said\" | \"kind\" | \"splits\">,\n from: string,\n): TableShape {\n const order: string[] = [];\n for (const r of records) for (const k of r.keys()) if (!order.some((o) => o.toLowerCase() === k.toLowerCase())) order.push(k);\n const headers = uniqueLabels(order);\n const rows = records.map((r) => {\n const row: Record<string, string> = {};\n order.forEach((k, i) => {\n const hit = [...r.entries()].find(([rk]) => rk.toLowerCase() === k.toLowerCase());\n row[headers[i]!] = hit ? hit[1] : \"\";\n });\n return row;\n });\n return {\n ...base,\n kind: \"key_value\",\n headers,\n rows,\n splits: [],\n said:\n rows.length === 1\n ? `One record with ${plural(headers.length, \"value\", \"values\")} from ${from}`\n : `${sizeWords(rows.length, headers.length)} from ${from}`,\n };\n}\n\nconst SPLITS: Array<{ delimiter: string; label: string }> = [\n { delimiter: \" — \", label: \"Split at the dash\" },\n { delimiter: \" – \", label: \"Split at the dash\" },\n { delimiter: \" - \", label: \"Split at the hyphen\" },\n { delimiter: \": \", label: \"Split at the colon\" },\n { delimiter: \" | \", label: \"Split at the bar\" },\n { delimiter: \"\\t\", label: \"Split at the tab\" },\n { delimiter: \", \", label: \"Split at each comma\" },\n];\n\nfunction listSplits(items: string[]): TableShapeSplit[] {\n const out: TableShapeSplit[] = [];\n for (const { delimiter, label } of SPLITS) {\n if (!items.every((t) => t.includes(delimiter))) continue;\n if (out.some((s) => s.label === label)) continue;\n const every = delimiter === \", \";\n const parts = items.map((t) => (every ? t.split(delimiter) : [t.slice(0, t.indexOf(delimiter)), t.slice(t.indexOf(delimiter) + delimiter.length)]));\n const width = Math.max(...parts.map((p) => p.length));\n const headers = uniqueLabels(width === 2 ? [\"Item\", \"Detail\"] : Array.from({ length: width }, (_, i) => (i === 0 ? \"Item\" : `Detail ${i}`)));\n out.push({ delimiter, label, headers, rows: rowsOf(headers, parts.map((p) => p.map((c) => cellWords(c)))) });\n }\n return out;\n}\n\nfunction shapeFromList(items: ListItem[], name: string | null, at: TableShape[\"at\"]): TableShape | null {\n const top = items.filter((i) => i.depth === 0);\n if (top.length === 0) return null;\n // (1) Every item names a record and its children are that record's values.\n const withChildren = top.filter((i) => i.children.length > 0);\n if (withChildren.length === top.length && top.length >= 1) {\n const childPairs = top.map((i) => i.children.map(keyValueOf));\n if (childPairs.every((ps) => ps.length > 0 && ps.every((p) => p !== null))) {\n const lead = \"Name\";\n const records = top.map((item, idx) => {\n const r = new Map<string, string>();\n r.set(lead, cellWords(item.text).replace(/:$/, \"\"));\n for (const p of childPairs[idx]!) r.set(p!.key, p!.value);\n return r;\n });\n return shapeFromRecords(records, { name, at }, \"a list\");\n }\n }\n // (2) Every item is `Key: value` — one record, or several when the keys come round again.\n const pairs = top.map((i) => keyValueOf(i.text));\n if (pairs.length >= FEWEST_KEY_VALUE_PAIRS && pairs.every((p) => p !== null)) {\n const records = recordsFromPairs(pairs as Array<{ key: string; value: string }>);\n const sameKeys = records.every((r) => r.size === records[0]!.size);\n if (records.length === 1 || (sameKeys && records[0]!.size >= 2)) return shapeFromRecords(records, { name, at }, \"a list\");\n }\n // (3) A plain list — one column, or split, and the children kept beside their item.\n if (top.length < FEWEST_LIST_ITEMS) return null;\n const texts = top.map((i) => cellWords(i.text));\n const anyChildren = top.some((i) => i.children.length > 0);\n const headers = anyChildren ? [\"Item\", \"Details\"] : [\"Item\"];\n const rows = top.map((item, idx) => {\n const row: Record<string, string> = { Item: texts[idx]! };\n if (anyChildren) row.Details = item.children.map(cellWords).join(\"; \");\n return row;\n });\n return {\n kind: \"list\",\n headers,\n rows,\n name,\n at,\n splits: anyChildren ? [] : listSplits(texts),\n said: `${plural(rows.length, \"item\", \"items\")} from a list`,\n };\n}\n\n// ── CSV / TSV ──────────────────────────────────────────────────────────────\n\n/** CSV/TSV rows with the all-blank lines dropped — THE one reader (kit `parseDelimited`). */\nexport function parseDelimited(text: string, delimiter: \",\" | \"\\t\"): string[][] {\n return readDelimited(text, { delimiter, skipEmptyLines: \"greedy\" }).data;\n}\n\n/** A whole text that is delimited rows: every line the same width, at least two columns. */\nfunction delimitedShape(text: string, delimiter: \",\" | \"\\t\", fenced: boolean, at: TableShape[\"at\"], name: string | null): TableShape | null {\n const matrix = parseDelimited(text.trim(), delimiter);\n if (matrix.length < 2) return null;\n const width = matrix[0]!.length;\n if (width < 2) return null;\n const same = matrix.filter((r) => r.length === width).length;\n if (same / matrix.length < 0.9) return null;\n if (!fenced) {\n // Prose has commas too. A CSV cell is short; a sentence is not.\n const cells = matrix.flat();\n const long = cells.filter((c) => c.trim().length > 80).length;\n if (delimiter === \",\" && (long / cells.length > 0.2 || matrix.length < 2)) return null;\n }\n const headers = uniqueLabels(matrix[0]!.map((c) => c.trim()));\n const rows = rowsOf(headers, matrix.slice(1));\n if (rows.length === 0) return null;\n const kind = delimiter === \"\\t\" ? \"tsv\" : \"csv\";\n return {\n kind,\n headers,\n rows,\n name,\n at,\n splits: [],\n said: `${sizeWords(rows.length, headers.length)} from ${kind === \"tsv\" ? \"pasted spreadsheet cells\" : \"CSV\"}`,\n };\n}\n\n// ── JSON and kind values ───────────────────────────────────────────────────\n\nfunction cellOf(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (typeof value === \"string\") return value;\n if (typeof value === \"number\" || typeof value === \"boolean\") return String(value);\n if (Array.isArray(value) && value.every((v) => typeof v !== \"object\" || v === null)) return value.map(cellOf).join(\", \");\n // A nested object (a kind value included) is kept whole, `__kind` and all — it is part of the data.\n return JSON.stringify(value);\n}\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return typeof v === \"object\" && v !== null && !Array.isArray(v);\n}\n\n/** A key as a column's label: `body_area` → \"Body area\"; a key already in words stays as written. */\nfunction labelOfKey(key: string): string {\n return /[\\s]/.test(key) || /^[A-Z]/.test(key) ? key : humanizeIdentifier(key);\n}\n\nfunction shapeFromObjects(objects: Array<Record<string, unknown>>, kind: TableShapeKind, from: string, name: string | null): TableShape | null {\n if (objects.length === 0) return null;\n const keys: string[] = [];\n for (const o of objects) for (const k of Object.keys(o)) if (k !== \"__kind\" && !keys.includes(k)) keys.push(k);\n if (keys.length === 0) return null;\n const headers = uniqueLabels(keys.map(labelOfKey));\n const rows = objects.map((o) => {\n const row: Record<string, string> = {};\n keys.forEach((k, i) => {\n row[headers[i]!] = cellOf(o[k]);\n });\n return row;\n });\n return { kind, headers, rows, name, at: null, splits: [], said: `${sizeWords(rows.length, headers.length)} from ${from}` };\n}\n\n/**\n * THE ROWS A VALUE HOLDS — a kind value (`__kind`, or a Matrx directive read by the one decoder),\n * a JSON array of objects, or an object whose largest member is one. Null when it holds none.\n */\nexport function shapeOfValue(value: unknown, name: string | null = null): TableShape | null {\n let v: unknown = value;\n if (typeof v === \"string\") {\n const t = v.trim();\n const fence = /^```(?:json|matrx)?\\s*\\n?([\\s\\S]*?)\\n?```$/.exec(t);\n const body = fence ? fence[1]!.trim() : t;\n if (!(body.startsWith(\"{\") || body.startsWith(\"[\"))) return null;\n try {\n v = JSON.parse(body);\n } catch {\n return null;\n }\n }\n if (Array.isArray(v)) {\n const objects = v.filter(isPlainObject);\n if (objects.length === 0 || objects.length < v.length) return null;\n return shapeFromObjects(objects, \"rows\", \"JSON rows\", name);\n }\n if (!isPlainObject(v)) return null;\n const kv = kindValueOf(v);\n if (kv) {\n const label = kv.kind.replace(/^directive_v\\d+_/, \"\").replace(/_/g, \" \");\n if (kv.items.length > 0) return shapeFromObjects(kv.items, \"kind\", `a ${label}`, name);\n const scalars = Object.fromEntries(Object.entries(v).filter(([k, x]) => k !== \"__kind\" && (typeof x !== \"object\" || x === null)));\n const shape = shapeFromObjects([scalars], \"kind\", `a ${label}`, name);\n if (shape) return shape;\n }\n // An object carrying one list of records: {\"exercises\": [{…}, {…}]} — the largest one.\n let best: { key: string; items: Array<Record<string, unknown>> } | null = null;\n for (const [key, member] of Object.entries(v)) {\n if (Array.isArray(member) && member.length > 0 && member.every(isPlainObject)) {\n if (!best || member.length > best.items.length) best = { key, items: member };\n }\n }\n if (best) return shapeFromObjects(best.items, kv ? \"kind\" : \"rows\", \"JSON rows\", name ?? labelOfKey(best.key));\n return null;\n}\n\n// ── the document reader ────────────────────────────────────────────────────\n\n/**\n * EVERY SHAPE IN A TEXT, top to bottom: markdown tables, lists, runs of `Key: value` lines,\n * fenced CSV / TSV / JSON blocks — and when the whole text is one CSV or TSV paste, that.\n * An empty array means the text holds nothing that reads as rows, and a menu offers nothing.\n */\nexport function readTableShapes(text: string): TableShape[] {\n if (typeof text !== \"string\" || text.trim() === \"\" || text.length > LONGEST_TEXT_READ) return [];\n const whole = text.trim();\n\n // A whole value (a kind value / JSON rows pasted or stored as the content).\n if (whole.startsWith(\"{\") || whole.startsWith(\"[\") || /^```(?:json|matrx)/.test(whole)) {\n const s = shapeOfValue(whole);\n if (s) return [{ ...s, at: { start: 0, end: text.length } }];\n }\n // A whole paste of spreadsheet cells or CSV (no markdown at all).\n if (!/^\\s*[|#>*-]/m.test(whole)) {\n if (whole.includes(\"\\t\")) {\n const s = delimitedShape(whole, \"\\t\", false, { start: 0, end: text.length }, null);\n if (s) return [s];\n }\n const s = delimitedShape(whole, \",\", false, { start: 0, end: text.length }, null);\n if (s) return [s];\n }\n\n const lines = text.split(/\\r?\\n/);\n const offsets: number[] = [];\n let pos = 0;\n for (const line of lines) {\n offsets.push(pos);\n pos += line.length + 1;\n }\n const endOf = (i: number) => (offsets[i] ?? 0) + (lines[i]?.length ?? 0);\n const shapes: TableShape[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i] ?? \"\";\n\n // Fenced blocks: CSV / TSV / JSON are read; any other fence is skipped whole.\n const fence = /^\\s*```\\s*([\\w-]*)\\s*$/.exec(line);\n if (fence) {\n let j = i + 1;\n while (j < lines.length && !/^\\s*```\\s*$/.test(lines[j] ?? \"\")) j += 1;\n const body = lines.slice(i + 1, j).join(\"\\n\");\n const lang = fence[1]!.toLowerCase();\n const at = { start: offsets[i]!, end: endOf(Math.min(j, lines.length - 1)) };\n const name = nameAbove(lines, i);\n let s: TableShape | null = null;\n if (lang === \"csv\") s = delimitedShape(body, \",\", true, at, name);\n else if (lang === \"tsv\") s = delimitedShape(body, \"\\t\", true, at, name);\n else if (lang === \"json\" || lang === \"matrx\") s = shapeOfValue(body, name);\n if (s) shapes.push({ ...s, at });\n i = j + 1;\n continue;\n }\n\n // A markdown table: a row of pipes, then the separator row.\n if (tableStartsAt(lines, i)) {\n const headers = uniqueLabels(splitPipes(line));\n const j = findTableEnd(lines, i);\n const matrix: string[][] = [];\n for (let r = i + 2; r < j; r += 1) matrix.push(splitPipes(lines[r]!));\n const rows = rowsOf(headers, matrix);\n if (headers.length >= 1 && rows.length >= 1) {\n shapes.push({\n kind: \"table\",\n headers,\n rows,\n name: nameAbove(lines, i),\n at: { start: offsets[i]!, end: endOf(j - 1) },\n splits: [],\n said: `${sizeWords(rows.length, headers.length)} from a table`,\n });\n }\n i = j;\n continue;\n }\n\n // A list: consecutive items (a single blank line between items is still the same list).\n const item = LIST_ITEM.exec(line);\n if (item) {\n const baseIndent = item[1]!.length;\n const items: ListItem[] = [];\n let j = i;\n while (j < lines.length) {\n const l = lines[j] ?? \"\";\n const m = LIST_ITEM.exec(l);\n if (m) {\n const depth = m[1]!.length > baseIndent ? 1 : 0;\n if (depth === 0) items.push({ depth: 0, text: m[2]!, children: [] });\n else if (items.length > 0) items[items.length - 1]!.children.push(m[2]!);\n j += 1;\n continue;\n }\n if (l.trim() === \"\" && LIST_ITEM.test(lines[j + 1] ?? \"\")) {\n j += 1;\n continue;\n }\n // A wrapped line of the item above it.\n if (l.trim() !== \"\" && /^\\s{2,}\\S/.test(l) && items.length > 0) {\n items[items.length - 1]!.text += ` ${l.trim()}`;\n j += 1;\n continue;\n }\n break;\n }\n const s = shapeFromList(items, nameAbove(lines, i), { start: offsets[i]!, end: endOf(j - 1) });\n if (s) shapes.push(s);\n i = j;\n continue;\n }\n\n // A run of `Key: value` lines outside a list (a form result, a record written out).\n if (keyValueOf(line)) {\n let j = i;\n const pairs: Array<{ key: string; value: string }> = [];\n while (j < lines.length) {\n const l = lines[j] ?? \"\";\n const p = keyValueOf(l);\n if (p) {\n pairs.push(p);\n j += 1;\n continue;\n }\n if (l.trim() === \"\" && keyValueOf(lines[j + 1] ?? \"\")) {\n j += 1;\n continue;\n }\n break;\n }\n if (pairs.length >= FEWEST_KEY_VALUE_PAIRS) {\n const records = recordsFromPairs(pairs);\n const sameKeys = records.every((r) => r.size === records[0]!.size);\n if (records.length === 1 || (sameKeys && records[0]!.size >= 2)) {\n shapes.push(shapeFromRecords(records, { name: nameAbove(lines, i), at: { start: offsets[i]!, end: endOf(j - 1) } }, \"key and value lines\"));\n } else {\n // Keys that come round in no fixed order are a conversation: who, and what they said.\n const headers = [\"Name\", \"Text\"];\n shapes.push({\n kind: \"key_value\",\n headers,\n rows: pairs.map((p) => ({ Name: p.key, Text: p.value })),\n name: nameAbove(lines, i),\n at: { start: offsets[i]!, end: endOf(j - 1) },\n splits: [],\n said: `${plural(pairs.length, \"line\", \"lines\")}, each a name and what was said`,\n });\n }\n }\n i = Math.max(j, i + 1);\n continue;\n }\n i += 1;\n }\n return shapes;\n}\n\n/** The first shape in a text, or null — what a one-shape menu item acts on. */\nexport function readFirstTableShape(text: string): TableShape | null {\n return readTableShapes(text)[0] ?? null;\n}\n\n/** True when the text holds anything that reads as rows — every menu's \"offer it?\" predicate. */\nexport function hasTableShape(text: string): boolean {\n return readTableShapes(text).length > 0;\n}\n\n/** Headers + string rows — the shape a table renderer already holds, read as a TableShape. */\nexport function shapeOfGrid(\n headers: readonly string[],\n cells: ReadonlyArray<ReadonlyArray<string>>,\n name: string | null = null,\n /** What the rows came out of, in a word: \"table\" (a rendered table), \"sheet\" (a workbook's sheet). */\n from: string = \"table\",\n): TableShape | null {\n const labels = uniqueLabels(headers.map((h) => cellWords(String(h ?? \"\"))));\n const rows = rowsOf(labels, cells.map((r) => r.map((c) => cellWords(String(c ?? \"\")))));\n if (labels.length === 0) return null;\n // Column names with no rows under them are still a table to make (the file importer's header-only\n // file: \"the table will be created with these columns and no rows yet\").\n const said = rows.length === 0 ? `${plural(labels.length, \"column\", \"columns\")} and no rows yet` : `${sizeWords(rows.length, labels.length)} from a ${from}`;\n return { kind: \"table\", headers: labels, rows, name, at: null, splits: [], said };\n}\n\n// ── what a NEW table's columns should be ───────────────────────────────────\n\n/** A type word `custom.field_declare` takes, from `FIELD_TYPE_CHOICES`. */\nexport type GuessedFieldType =\n | \"text\"\n | \"long_text\"\n | \"number\"\n | \"currency\"\n | \"percent\"\n | \"datetime\"\n | \"checkbox\"\n | \"email\"\n | \"url\"\n | \"phone\"\n | \"select\";\n\nexport interface ColumnGuess {\n type: GuessedFieldType;\n /** A choice column's words, in the order the text first used them. */\n options?: string[];\n /** A money column's symbol. */\n unit?: string;\n /** A date column that never carries a time of day. */\n kind?: \"date\" | \"datetime\";\n}\n\n/** The most words a choice column's list may hold before it reads as text. */\nexport const MOST_GUESSED_CHOICES = 12;\n\nconst NUMBER = /^[+-]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?$/;\nconst MONEY = /^([$€£¥])\\s?([+-]?(?:\\d{1,3}(?:,\\d{3})+|\\d+)(?:\\.\\d+)?)$/;\nconst PERCENT = /^[+-]?\\d+(?:\\.\\d+)?\\s?%$/;\nconst ISO_DATE = /^\\d{4}-\\d{2}-\\d{2}(?:[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?)?$/;\nconst SLASH_DATE = /^\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}$/;\nconst WORD_DATE = /^(?:\\d{1,2}\\s+)?(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\\.?\\s+\\d{1,2}(?:st|nd|rd|th)?,?\\s+\\d{4}$|^\\d{1,2}\\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\\.?\\s+\\d{4}$/i;\nconst EMAIL = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]{2,}$/;\nconst URL_WORD = /^https?:\\/\\/\\S+$/i;\nconst PHONE = /^\\+?[\\d\\s().-]{7,20}$/;\nconst YES = new Set([\"yes\", \"true\", \"y\", \"✓\", \"✔\", \"checked\", \"done\"]);\nconst NO = new Set([\"no\", \"false\", \"n\", \"✗\", \"✘\", \"unchecked\", \"\"]);\n\nfunction isDate(v: string): boolean {\n return ISO_DATE.test(v) || SLASH_DATE.test(v) || WORD_DATE.test(v);\n}\n\n/**\n * WHAT A NEW TABLE'S COLUMN SHOULD HOLD, proposed from every value in it. A column is a number, a\n * date, a yes/no, an email… only when EVERY non-blank value reads as one — one value that does not\n * (\"10-15\" among the Reps) keeps the column text, because a guess that loses a person's words is\n * worse than a text column. A few short words that repeat are a Choice, with those words as its\n * choices. It is a proposal the person sees and changes before anything is made.\n */\nexport function guessColumn(values: ReadonlyArray<string>): ColumnGuess {\n const filled = values.map((v) => String(v ?? \"\").trim()).filter((v) => v !== \"\");\n if (filled.length === 0) return { type: \"text\" };\n const every = (test: (v: string) => boolean) => filled.every(test);\n if (every((v) => YES.has(v.toLowerCase()) || NO.has(v.toLowerCase())) && filled.some((v) => YES.has(v.toLowerCase())) && filled.some((v) => !/^\\d+$/.test(v))) {\n return { type: \"checkbox\" };\n }\n if (every((v) => NUMBER.test(v))) return { type: \"number\" };\n if (every((v) => MONEY.test(v))) {\n const symbols = new Set(filled.map((v) => MONEY.exec(v)![1]!));\n if (symbols.size === 1) return { type: \"currency\", unit: [...symbols][0]! };\n }\n if (every((v) => PERCENT.test(v))) return { type: \"percent\" };\n if (every(isDate)) return { type: \"datetime\", kind: every((v) => !/\\d:\\d/.test(v)) ? \"date\" : \"datetime\" };\n if (every((v) => EMAIL.test(v))) return { type: \"email\" };\n if (every((v) => URL_WORD.test(v))) return { type: \"url\" };\n if (every((v) => PHONE.test(v) && (v.match(/\\d/g)?.length ?? 0) >= 7)) return { type: \"phone\" };\n if (filled.some((v) => v.length > 120 || v.includes(\"\\n\"))) return { type: \"long_text\" };\n const distinct: string[] = [];\n for (const v of filled) if (!distinct.some((d) => d.toLowerCase() === v.toLowerCase())) distinct.push(v);\n const short = every((v) => v.length <= 40 && v.split(/\\s+/).length <= 5);\n // Counts and ranges (\"10\", \"10-15\") repeat too, and they are measurements, not a list to pick from.\n const words = filled.filter((v) => !/\\d/.test(v)).length >= filled.length / 2;\n if (filled.length >= 3 && short && words && distinct.length < filled.length && distinct.length <= MOST_GUESSED_CHOICES) {\n return { type: \"select\", options: distinct };\n }\n return { type: \"text\" };\n}\n\n// ── what a selection over RENDERED content holds ───────────────────────────\n\nconst BLOCK_TAGS = new Set([\"P\", \"DIV\", \"SECTION\", \"ARTICLE\", \"H1\", \"H2\", \"H3\", \"H4\", \"H5\", \"H6\", \"BLOCKQUOTE\", \"PRE\", \"HEADER\", \"FOOTER\", \"BR\", \"HR\", \"DL\", \"DT\", \"DD\"]);\n\n/**\n * THE WORDS OF A SELECTION, WITH ITS SHAPE KEPT (VERIFIER-30 #1). A browser selection over a rendered\n * answer flattens to text in which a table's header cells come one per line and a list's bullets are\n * gone, so `readTableShapes` found nothing in exactly the places a person selects rows. This walks the\n * selected DOM (a `Range.cloneContents()` fragment, or any node) and writes it back as the shapes it\n * was drawn from: a table's rows as a markdown table (the first row its heading), a list's items as\n * bullets (nested items indented), every other block on its own line.\n */\nexport function shapeTextOfNode(node: Node): string {\n const out: string[] = [];\n let line = \"\";\n let rows: string[][] = [];\n const flushLine = () => {\n if (line.trim() !== \"\") out.push(line.trim());\n line = \"\";\n };\n const flushRows = () => {\n if (rows.length === 0) return;\n flushLine();\n const width = Math.max(...rows.map((r) => r.length));\n const pad = (r: string[]) => [...r, ...Array.from({ length: width - r.length }, () => \"\")];\n const cell = (c: string) => c.replace(/\\|/g, \"\\\\|\").replace(/\\s+/g, \" \").trim();\n out.push(`| ${pad(rows[0]!).map(cell).join(\" | \")} |`);\n out.push(`|${Array.from({ length: width }, () => \"---\").join(\"|\")}|`);\n for (const r of rows.slice(1)) out.push(`| ${pad(r).map(cell).join(\" | \")} |`);\n rows = [];\n };\n const textOf = (n: Node): string => (n.textContent ?? \"\").replace(/\\s+/g, \" \").trim();\n const walk = (n: Node, depth: number): void => {\n if (n.nodeType === 3) {\n line += n.textContent ?? \"\";\n return;\n }\n if (n.nodeType !== 1 && n.nodeType !== 11) return;\n const el = n as Element;\n const tag = n.nodeType === 1 ? el.tagName.toUpperCase() : \"#fragment\";\n if (tag === \"TR\") {\n const cells = Array.from(el.children).filter((c) => /^(TD|TH)$/i.test(c.tagName));\n rows.push(cells.map((c) => textOf(c)));\n return;\n }\n if (tag === \"TABLE\" || tag === \"THEAD\" || tag === \"TBODY\" || tag === \"TFOOT\") {\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n if (tag === \"TABLE\") flushRows();\n return;\n }\n flushRows();\n if (tag === \"LI\") {\n flushLine();\n const own: string[] = [];\n const nested: Node[] = [];\n for (const child of Array.from(n.childNodes)) {\n if (child.nodeType === 1 && /^(UL|OL)$/i.test((child as Element).tagName)) nested.push(child);\n else own.push(child.textContent ?? \"\");\n }\n const words = own.join(\"\").replace(/\\s+/g, \" \").trim();\n if (words) out.push(`${\" \".repeat(depth)}- ${words}`);\n for (const list of nested) walk(list, depth + 1);\n return;\n }\n if (tag === \"UL\" || tag === \"OL\") {\n flushLine();\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n flushLine();\n return;\n }\n const block = BLOCK_TAGS.has(tag);\n if (block) flushLine();\n for (const child of Array.from(n.childNodes)) walk(child, depth);\n if (block) flushLine();\n };\n walk(node, 0);\n flushRows();\n flushLine();\n return out.join(\"\\n\");\n}\n","// src/kindValues.ts — @ai-matrx/records-ui · lane REFERENCE-CARRY\n//\n// A CELL THAT HOLDS A KIND. A value is a kind value when it names its own shape — `__kind` — or\n// when it is a stored Matrx directive written before the Kind Directives merge (the retired 4-key\n// shell `{\"matrx_version\": 1, \"kind\": \"reference\", \"type\": \"scope\", \"items\": [...]}`, usually inside\n// a ```matrx fence). Before this, a text cell holding either printed the raw fence: Arman's\n// Department table, 2026-09-28 — Team Leader read ```matrx {\"matrx_version\":1,…}```.\n//\n// THE SHELL IS UNDERSTOOD IN ONE PLACE. Whether an object is a directive — the current shell, or\n// the retired one stored before the merge — is `@ai-matrx/content-ir/directives`' `tryDecodeDirective`\n// alone (its containment guard keeps the retired shell there). This module only takes the object out\n// of its fence and hands it, untouched, to the host's `renderKind` port, which draws it through the\n// kind system. New values are stored as `__kind` JSON, never as a fence.\n\nimport { tryDecodeDirective } from \"@ai-matrx/content-ir/directives\";\nimport { humanizeIdentifier } from \"@ai-matrx/kit/text-case\";\n\n/** What a cell holds when it holds a kind. */\nexport interface KindValue {\n /** The parsed object, exactly as stored (`__kind` kept — it is part of the data). */\n value: Record<string, unknown>;\n /**\n * The kind's own name: `__kind`, or for a directive the slug the one decoder reads\n * (`directive_v1_reference_scope`, the retired shell included).\n */\n kind: string;\n /** True when the one decoder read this as a Matrx directive. */\n directive: boolean;\n /** The items a directive carries (a reference's chips), when it carries any. */\n items: Record<string, unknown>[];\n}\n\nconst KIND_KEY = \"__kind\";\n/** One fenced block and nothing else: ```matrx {…}``` or ```json {…}```. */\nconst WHOLE_FENCE = /^\\s*```(?:matrx|json)?[ \\t]*\\r?\\n?([\\s\\S]*?)\\r?\\n?[ \\t]*```\\s*$/;\n\nfunction asObject(value: unknown): Record<string, unknown> | null {\n return typeof value === \"object\" && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;\n}\n\nfunction parseJsonObject(text: string): Record<string, unknown> | null {\n const trimmed = text.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) return null;\n try {\n return asObject(JSON.parse(trimmed));\n } catch {\n return null;\n }\n}\n\nfunction fromObject(obj: Record<string, unknown>): KindValue | null {\n // THE ONE DECODER decides what a directive is — the current two-key shell and, for stored\n // content only, the retired 4-key one. A directive it cannot honor is not drawn as one.\n const directive = tryDecodeDirective(obj);\n if (directive) return { value: obj, kind: directive.slug, directive: true, items: [...directive.items] };\n const named = obj[KIND_KEY];\n if (typeof named === \"string\" && named.trim() !== \"\") {\n const items = Array.isArray(obj.items) ? obj.items.filter((i): i is Record<string, unknown> => asObject(i) !== null) : [];\n return { value: obj, kind: named.trim(), directive: false, items };\n }\n return null;\n}\n/**\n * The kind value a cell holds, or null. An object with `__kind`, a string that is such an object's\n * JSON, or a string that is ONE fenced block of it (```matrx / ```json), the retired directive shell\n * included. Text that merely mentions a fence among other words is text, and stays text.\n */\nexport function kindValueOf(value: unknown): KindValue | null {\n const obj = asObject(value);\n if (obj) return fromObject(obj);\n if (typeof value !== \"string\" || value.length > 200_000) return null;\n const fenced = WHOLE_FENCE.exec(value);\n const parsed = parseJsonObject(fenced ? fenced[1]! : value);\n return parsed ? fromObject(parsed) : null;\n}\n\n/** The words an item names itself by (a reference's label, a title, a name). */\nexport function kindItemWords(item: Record<string, unknown>): string | null {\n for (const key of [\"label\", \"title\", \"name\", \"display_name\"]) {\n const v = item[key];\n if (typeof v === \"string\" && v.trim() !== \"\") return v.trim();\n }\n return null;\n}\n\n/**\n * A kind value in words, for a sentence, a card, a copy or an export: the items' own names when it\n * carries named items (\"Arman Sadeghi, Tahir Mahfooz\"), else what kind of thing it is.\n */\nexport function kindValueWords(kv: KindValue): string {\n const named = kv.items.map(kindItemWords).filter((w): w is string => w !== null);\n if (named.length > 0) return named.join(\", \");\n return kindLabel(kv.kind);\n}\n\n/** A kind's name the way a person reads it: `directive_v1_reference_scope` → \"Reference Scope\". */\nexport function kindLabel(kind: string): string {\n return humanizeIdentifier(kind.replace(/^directive_v\\d+_/, \"\").replace(/_v\\d+$/, \"\")) || \"Structured value\";\n}\n"],"mappings":";;;AAcA,SAAS,cAAc,cAAc,oBAAoB,UAAU,qBAAqB;;;ACAxF,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AAiBnC,IAAM,WAAW;AAEjB,IAAM,cAAc;AAEpB,SAAS,SAAS,OAAgD;AAChE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ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,UAAI,MAAO,KAAI,KAAK,GAAG,KAAK,OAAO,KAAK,CAAC,KAAK,KAAK,EAAE;AACrD,iBAAW,QAAQ,OAAQ,MAAK,MAAM,QAAQ,CAAC;AAC/C;AAAA,IACF;AACA,QAAI,QAAQ,QAAQ,QAAQ,MAAM;AAChC,gBAAU;AACV,iBAAW,SAAS,MAAM,KAAK,EAAE,UAAU,EAAG,MAAK,OAAO,KAAK;AAC/D,gBAAU;AACV;AAAA,IACF;AACA,UAAM,QAAQ,WAAW,IAAI,GAAG;AAChC,QAAI,MAAO,WAAU;AACrB,eAAW,SAAS,MAAM,KAAK,EAAE,UAAU,EAAG,MAAK,OAAO,KAAK;AAC/D,QAAI,MAAO,WAAU;AAAA,EACvB;AACA,OAAK,MAAM,CAAC;AACZ,YAAU;AACV,YAAU;AACV,SAAO,IAAI,KAAK,IAAI;AACtB;","names":["humanizeIdentifier","s","i"]}
@@ -3,7 +3,7 @@ import {
3
3
  NOT_ANSWERED_YET,
4
4
  whatYouMayDo,
5
5
  whatYouMayDoWithTable
6
- } from "./chunk-PPWNFIJ5.js";
6
+ } from "./chunk-OV6QBL5R.js";
7
7
  import {
8
8
  __reExport
9
9
  } from "./chunk-HKYEHBQT.js";
@@ -341,7 +341,7 @@ function refusalForAPerson(error) {
341
341
  const said = (messageIsForEngineers ? "" : message.kept ?? "").trim();
342
342
  const forEngineers = [
343
343
  error.sqlstate ? `SQLSTATE ${error.sqlstate}.` : null,
344
- // The client's own note about a class it did not recognise, or a call that
344
+ // The client's own note about a class it did not recognize, or a call that
345
345
  // never reached the store. It is rendered out of sight, never as a sentence.
346
346
  error.diagnostic ? error.diagnostic : null,
347
347
  messageIsForEngineers ? `Message: ${error.message}` : null,
@@ -1398,4 +1398,4 @@ export {
1398
1398
  choiceNudgeOf,
1399
1399
  useChoiceNudge
1400
1400
  };
1401
- //# sourceMappingURL=chunk-ODABFEHG.js.map
1401
+ //# sourceMappingURL=chunk-7RSMA3NK.js.map