@ai-matrx/records-ui 0.116.113 → 0.116.115
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.
- package/CHANGELOG.md +8 -0
- package/dist/{SaveToTable-GRDFTAC4.js → SaveToTable-FVDYG5QS.js} +3 -3
- package/dist/{chunk-FZVW6XVB.js → chunk-ESOQXQAE.js} +2 -2
- package/dist/{chunk-LGQLATW5.js → chunk-KUEASKVB.js} +4 -4
- package/dist/{chunk-Z3EUU2NM.js → chunk-OY553AFP.js} +2 -2
- package/dist/{chunk-N76I4VXM.js → chunk-PYLGLSKU.js} +2 -2
- package/dist/{chunk-JTEIYLII.js → chunk-RKI2YQHW.js} +2 -2
- package/dist/chunk-RKI2YQHW.js.map +1 -0
- package/dist/entity-doors.cjs +3 -4
- package/dist/entity-doors.cjs.map +1 -1
- package/dist/entity-doors.js +3 -4
- package/dist/entity-doors.js.map +1 -1
- package/dist/entity-ref.cjs +4 -5
- package/dist/entity-ref.cjs.map +1 -1
- package/dist/entity-ref.js +4 -5
- package/dist/entity-ref.js.map +1 -1
- package/dist/helpers.cjs +2 -3
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.js +2 -2
- package/dist/helpers.js.map +1 -1
- package/dist/index.cjs +394 -394
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -5
- package/dist/pickers.cjs +158 -158
- package/dist/pickers.cjs.map +1 -1
- package/dist/pickers.js +3 -3
- package/dist/skeleton.js +3 -3
- package/package.json +2 -2
- package/dist/chunk-JTEIYLII.js.map +0 -1
- /package/dist/{SaveToTable-GRDFTAC4.js.map → SaveToTable-FVDYG5QS.js.map} +0 -0
- /package/dist/{chunk-FZVW6XVB.js.map → chunk-ESOQXQAE.js.map} +0 -0
- /package/dist/{chunk-LGQLATW5.js.map → chunk-KUEASKVB.js.map} +0 -0
- /package/dist/{chunk-Z3EUU2NM.js.map → chunk-OY553AFP.js.map} +0 -0
- /package/dist/{chunk-N76I4VXM.js.map → chunk-PYLGLSKU.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.116.115
|
|
4
|
+
|
|
5
|
+
- Fixed: `/helpers` (and the `/skeleton` chunk) no longer import the `@ai-matrx/records` root: `setPersonTimeZone` reaches `setReadersTimeZone` through `@ai-matrx/records/views`. Guard: `check-light-entries` in `build` (it was red).
|
|
6
|
+
|
|
7
|
+
## 0.116.114
|
|
8
|
+
|
|
9
|
+
- Fixed: the "host not configured" warning for entity references fires once per page, not once per entry: its flag rides the entity-ref host's global slot instead of a module `let` that `/entity-doors` and `/entity-ref` each carried. Guard: `check-ships-once --state` in `build`. No API change.
|
|
10
|
+
|
|
3
11
|
## 0.116.113
|
|
4
12
|
|
|
5
13
|
- `EntityRef` `wrap` accepts `"lines"`: the label wraps at word boundaries, at most two lines, then ellipsis (a title a person reads). `true` (break-all) and the default (truncate) are unchanged. No consumer action required.
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
SAVE_TO_TABLE_TYPES,
|
|
4
4
|
SaveToTable,
|
|
5
5
|
shapesOfSource
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PYLGLSKU.js";
|
|
7
7
|
import "./chunk-MTA5CGMH.js";
|
|
8
8
|
import "./chunk-DZ4KNUSS.js";
|
|
9
9
|
import "./chunk-YHPVSUK6.js";
|
|
10
10
|
import "./chunk-LBZZDHV6.js";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-RKI2YQHW.js";
|
|
12
12
|
import "./chunk-WCQSJPLS.js";
|
|
13
13
|
import "./chunk-HKYEHBQT.js";
|
|
14
14
|
export {
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
SaveToTable,
|
|
17
17
|
shapesOfSource
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=SaveToTable-
|
|
19
|
+
//# sourceMappingURL=SaveToTable-FVDYG5QS.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
EMBEDDED_PLAIN_FOOTER_CLASS,
|
|
4
4
|
EMBEDDED_TABLE_CLASS
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-OY553AFP.js";
|
|
6
6
|
|
|
7
7
|
// src/skeletonLayout.ts
|
|
8
8
|
var RECORDS_SKELETON_LAYOUTS = [
|
|
@@ -304,4 +304,4 @@ export {
|
|
|
304
304
|
RecordsSkeleton,
|
|
305
305
|
TablePageSkeleton
|
|
306
306
|
};
|
|
307
|
-
//# sourceMappingURL=chunk-
|
|
307
|
+
//# sourceMappingURL=chunk-ESOQXQAE.js.map
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
isYearValue,
|
|
6
6
|
shownAsOf,
|
|
7
7
|
useEmbeddedLook
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OY553AFP.js";
|
|
9
9
|
import {
|
|
10
10
|
HtmlSampleFrame,
|
|
11
11
|
HtmlSampleTokensProvider
|
|
@@ -90,7 +90,7 @@ import {
|
|
|
90
90
|
storedChoiceColor,
|
|
91
91
|
subscribePersonTimeZone,
|
|
92
92
|
systemStampOf
|
|
93
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-RKI2YQHW.js";
|
|
94
94
|
import {
|
|
95
95
|
ADD_FIELD_SAVE_LABEL,
|
|
96
96
|
EDIT_FIELD_SAVE_LABEL,
|
|
@@ -4646,7 +4646,7 @@ import { OutboundLink as OutboundLink5 } from "@ai-matrx/kit/outbound-react";
|
|
|
4646
4646
|
import { humanizeIdentifier } from "@ai-matrx/kit/text-case";
|
|
4647
4647
|
import { momentZoneOptions } from "@ai-matrx/design-system/field-formats";
|
|
4648
4648
|
import { jsx as jsx25, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
4649
|
-
var SaveToTable = lazy(() => import("./SaveToTable-
|
|
4649
|
+
var SaveToTable = lazy(() => import("./SaveToTable-FVDYG5QS.js").then((m) => ({ default: m.SaveToTable })));
|
|
4650
4650
|
var LONGEST_READ = 5e5;
|
|
4651
4651
|
var FENCE = /^```(?:json)?[ \t]*\r?\n([\s\S]*?)\r?\n?```$/;
|
|
4652
4652
|
function isPlainObject(v) {
|
|
@@ -14340,4 +14340,4 @@ export {
|
|
|
14340
14340
|
RecordNameText,
|
|
14341
14341
|
HeldChangeDecision
|
|
14342
14342
|
};
|
|
14343
|
-
//# sourceMappingURL=chunk-
|
|
14343
|
+
//# sourceMappingURL=chunk-KUEASKVB.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
dateFormatFor,
|
|
4
4
|
editorKindFor
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RKI2YQHW.js";
|
|
6
6
|
|
|
7
7
|
// src/presentation.ts
|
|
8
8
|
import { COLOR_ROTATION, parseTableStyle, tableStyleIsEmpty } from "@ai-matrx/design-system/data-table/table-style";
|
|
@@ -447,4 +447,4 @@ export {
|
|
|
447
447
|
EMBEDDED_TABLE_CLASS,
|
|
448
448
|
EMBEDDED_PLAIN_FOOTER_CLASS
|
|
449
449
|
};
|
|
450
|
-
//# sourceMappingURL=chunk-
|
|
450
|
+
//# sourceMappingURL=chunk-OY553AFP.js.map
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
fieldTypeLabel,
|
|
42
42
|
hasTimePart,
|
|
43
43
|
isDateField
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-RKI2YQHW.js";
|
|
45
45
|
import {
|
|
46
46
|
fieldTypeChoice
|
|
47
47
|
} from "./chunk-WCQSJPLS.js";
|
|
@@ -5206,4 +5206,4 @@ export {
|
|
|
5206
5206
|
shapesOfSource,
|
|
5207
5207
|
SaveToTable
|
|
5208
5208
|
};
|
|
5209
|
-
//# sourceMappingURL=chunk-
|
|
5209
|
+
//# sourceMappingURL=chunk-PYLGLSKU.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/personZone.ts
|
|
8
8
|
import { setColorRuleTimeZone, setDisplayTimeZone } from "@ai-matrx/design-system/data-table/table-style";
|
|
9
|
-
import { setReadersTimeZone } from "@ai-matrx/records";
|
|
9
|
+
import { setReadersTimeZone } from "@ai-matrx/records/views";
|
|
10
10
|
import { globalSlot } from "@ai-matrx/kit/global-slot";
|
|
11
11
|
var state = globalSlot("ai-matrx.records-ui.person-time-zone", () => ({
|
|
12
12
|
zone: null,
|
|
@@ -358,4 +358,4 @@ export {
|
|
|
358
358
|
addDays,
|
|
359
359
|
daysBetween
|
|
360
360
|
};
|
|
361
|
-
//# sourceMappingURL=chunk-
|
|
361
|
+
//# sourceMappingURL=chunk-RKI2YQHW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/personZone.ts","../src/docs.ts","../src/choiceLooks.ts","../src/parity.ts","../src/dates.ts"],"sourcesContent":["// The person's time zone, as the app saved it (userPreferences.display.timeZone).\n//\n// The host app tells this package once (`setPersonTimeZone(\"America/Los_Angeles\")`); every \"today\" and\n// \"now\" a screen draws (the calendar's today marker and now-line, a timeline's today, a date picker's\n// today) is read in that zone instead of the device's. With nothing set the device zone applies, as before.\n// Nothing here stores a zone: the host's saved preference is the one place, this is its mirror.\n\nimport { setColorRuleTimeZone, setDisplayTimeZone } from \"@ai-matrx/design-system/data-table/table-style\";\nimport { setReadersTimeZone } from \"@ai-matrx/records/views\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\n\n// No React here: `@ai-matrx/records-ui/helpers` serves this file alone (the host sets the zone at\n// boot), and the root entry carries its own copy — so the zone lives in ONE realm-wide slot that\n// both copies read, never a module `let` that would split in two. The hook is `./personTime`.\nconst state = globalSlot(\"ai-matrx.records-ui.person-time-zone\", () => ({\n zone: null as string | null,\n listeners: new Set<() => void>(),\n}));\n\nfunction valid(z: unknown): z is string {\n if (typeof z !== \"string\" || !z.trim()) return false;\n try {\n new Intl.DateTimeFormat(\"en-US\", { timeZone: z });\n return true;\n } catch {\n return false;\n }\n}\n\n/** The host app's saved zone (IANA). `null` / junk clears it: the device zone applies. */\nexport function setPersonTimeZone(next: string | null | undefined): void {\n const clean = valid(next) ? next : null;\n if (clean === state.zone) return;\n state.zone = clean;\n // \"Today\" in a color rule is the person's day, not the device's (lane NOTION-SMALL-2).\n setColorRuleTimeZone(clean);\n // And every moment a screen prints (grid cell, panel, card, export) reads in it too: ONE zone, one slot.\n setDisplayTimeZone(clean);\n // And a relative day (\"Today\", \"Overdue\") a view asks the store is cut in it before it is sent (ADVERSARIAL-11 F3).\n setReadersTimeZone(clean);\n state.listeners.forEach((l) => l());\n}\n\nexport function getPersonTimeZone(): string | null {\n return state.zone;\n}\n\n/** Calls `listener` whenever the zone changes; returns the unsubscribe. */\nexport function subscribePersonTimeZone(listener: () => void): () => void {\n state.listeners.add(listener);\n return () => {\n state.listeners.delete(listener);\n };\n}\n\n/**\n * `at` as a Date whose LOCAL fields (getFullYear, getHours, ...) read the wall clock in the person's zone.\n * For day / hour math only: never compare it with a stored instant.\n */\nexport function personWallNow(at: Date = new Date()): Date {\n const zone = state.zone;\n if (!zone) return at;\n const parts = new Intl.DateTimeFormat(\"en-US\", {\n timeZone: zone,\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n hourCycle: \"h23\",\n }).formatToParts(at);\n const n = (t: string) => Number(parts.find((p) => p.type === t)?.value ?? 0);\n return new Date(n(\"year\"), n(\"month\") - 1, n(\"day\"), n(\"hour\"), n(\"minute\"), n(\"second\"));\n}\n\n/**\n * The inverse of `personWallNow`: the INSTANT at which the person's wall clock reads the local fields\n * of `wall` (getFullYear, getHours, ...). A calendar drop at \"9:30 on Nov 3\" writes this, so the card\n * reads 9:30 on Nov 3 again in the person's zone. With no zone set it is `wall` itself (device zone).\n */\nexport function instantFromPersonWall(wall: Date): Date {\n const zone = state.zone;\n if (!zone) return wall;\n const target = Date.UTC(wall.getFullYear(), wall.getMonth(), wall.getDate(), wall.getHours(), wall.getMinutes(), wall.getSeconds(), wall.getMilliseconds());\n let guess = target;\n for (let i = 0; i < 3; i += 1) {\n const seen = personWallNow(new Date(guess));\n const shown = Date.UTC(seen.getFullYear(), seen.getMonth(), seen.getDate(), seen.getHours(), seen.getMinutes(), seen.getSeconds(), wall.getMilliseconds());\n guess -= shown - target;\n }\n return new Date(guess);\n}\n","// 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 COLOR-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 color-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 color\".\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\";\nimport { momentZoneOptions } from \"@ai-matrx/design-system/field-formats\";\nimport { personWallNow } from \"./personZone\";\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\", ...momentZoneOptions(at) });\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 instant = value instanceof Date ? value : new Date(value as string | number);\n if (Number.isNaN(instant.getTime())) return null;\n // The day is the one on the PERSON's wall clock (their saved zone), not the device's.\n const at = personWallNow(instant);\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":";;;;;;;AAOA,SAAS,sBAAsB,0BAA0B;AACzD,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAK3B,IAAM,QAAQ,WAAW,wCAAwC,OAAO;AAAA,EACtE,MAAM;A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,CAAC,CAAC;AAChE,SAAO,GAAG,mBAAmB,QAAW,EAAE,OAAO,SAAS,KAAK,WAAW,MAAM,UAAU,CAAC;AAC7F;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"]}
|
package/dist/entity-doors.cjs
CHANGED
|
@@ -6,17 +6,16 @@ var source = require('@ai-matrx/content-ir/source');
|
|
|
6
6
|
var uuid = require('@ai-matrx/kit/uuid');
|
|
7
7
|
|
|
8
8
|
// src/entity-ref/slot.ts
|
|
9
|
-
var bound = globalSlot.globalSlot("ai-matrx.records-ui.entity-ref-host", () => ({ host: null }));
|
|
9
|
+
var bound = globalSlot.globalSlot("ai-matrx.records-ui.entity-ref-host", () => ({ host: null, warned: false }));
|
|
10
10
|
function configureEntityRefs(host) {
|
|
11
11
|
bound.host = host;
|
|
12
12
|
}
|
|
13
13
|
function entityRefsConfigured() {
|
|
14
14
|
return Boolean(bound.host);
|
|
15
15
|
}
|
|
16
|
-
var warned = false;
|
|
17
16
|
function announceUnconfigured() {
|
|
18
|
-
if (warned) return;
|
|
19
|
-
warned = true;
|
|
17
|
+
if (bound.warned) return;
|
|
18
|
+
bound.warned = true;
|
|
20
19
|
if (typeof console !== "undefined") {
|
|
21
20
|
console.warn(
|
|
22
21
|
"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. Call configureEntityRefs(...) before rendering references."
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":["globalSlot","openOutbound","findCodeRanges","codeSpanText"],"mappings":";;;;;;;;AAuHA,IAAM,QAAQA,qBAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,IAAI,MAAA,GAAS,KAAA;AACb,SAAS,oBAAA,GAA6B;AACpC,EAAA,IAAI,MAAA,EAAQ;AACZ,EAAA,MAAA,GAAS,IAAA;AACT,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KAEF;AAAA,EACF;AACF;AAEA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,SAAA,EAAW,CAAC,KAAA,KAAU,KAAA;AAAA,EACtB,UAAU,MAAM;AAClB,CAAA;AAEO,SAAS,iBAAiB,GAAA,EAA6B;AAC5D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,YAAA,IAAgB,GAAA,CAAI,IAAA;AACrC,EAAA,IAAI,IAAA,EAAMC,qBAAA,CAAa,IAAA,EAAM,QAAA,EAAU,UAAU,CAAA;AACnD;AAYA,IAAM,YAAY,MAAM,IAAA;AAGjB,SAAS,kBAAA,GAA2C;AACzD,EAAA,OAAO,KAAA,CAAM,IAAA;AACf;AAEO,SAAS,cAAA,GAAiC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A,CAAK,IAAI,CAAA,EACrC,KAAA,KAAU,IAAA,EACV,KAAA,GAAQ,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EACjC;AACA,IAAA,MAAM,EAAA,GAAK,MAAM,CAAC,CAAA;AAClB,IAAA,MAAM,QAAQ,KAAA,CAAM,KAAA;AACpB,IAAA,MAAM,KAAA,GACJ,uBAAA,CAAwB,IAAA,CAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAC,CAAA,KAChD,YAAA,IAAgB,UAAA,CAAW,YAAY,CAAA,GAAI,YAAA,GAAe,IAAA,CAAA;AAC7D,IAAA,IAAI,UAAU,IAAA,EAAM;AACpB,IAAA,IAAI,QAAQ,MAAA,EAAQ;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,KAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAA,EAAG,CAAA;AAAA,IACjE;AACA,IAAA,QAAA,CAAS,KAAK,EAAE,IAAA,EAAM,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACxC,IAAA,MAAA,GAAS,QAAQ,EAAA,CAAG,MAAA;AAAA,EACtB;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.cjs","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. \" +\n \"Call configureEntityRefs(...) before rendering references.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":["globalSlot","openOutbound","findCodeRanges","codeSpanText"],"mappings":";;;;;;;;AAyHA,IAAM,KAAA,GAAQA,sBAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,IAAA,EAA8B,MAAA,EAAQ,KAAA,EAAM,CAAE,CAAA;AAGtH,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,SAAS,oB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A,QAAA,CAAS,KAAK,EAAE,IAAA,EAAM,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACxC,IAAA,MAAA,GAAS,QAAQ,EAAA,CAAG,MAAA;AAAA,EACtB;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.cjs","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\n// `warned` rides the same slot: /entity-doors and /entity-ref each bundle this module, so a module-level\n// flag would warn once per copy (check-ships-once --state).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null, warned: false }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nfunction announceUnconfigured(): void {\n if (bound.warned) return;\n bound.warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. \" +\n \"Call configureEntityRefs(...) before rendering references.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
package/dist/entity-doors.js
CHANGED
|
@@ -4,17 +4,16 @@ import { findCodeRanges, codeSpanText } from '@ai-matrx/content-ir/source';
|
|
|
4
4
|
export { isUuidValue } from '@ai-matrx/kit/uuid';
|
|
5
5
|
|
|
6
6
|
// src/entity-ref/slot.ts
|
|
7
|
-
var bound = globalSlot("ai-matrx.records-ui.entity-ref-host", () => ({ host: null }));
|
|
7
|
+
var bound = globalSlot("ai-matrx.records-ui.entity-ref-host", () => ({ host: null, warned: false }));
|
|
8
8
|
function configureEntityRefs(host) {
|
|
9
9
|
bound.host = host;
|
|
10
10
|
}
|
|
11
11
|
function entityRefsConfigured() {
|
|
12
12
|
return Boolean(bound.host);
|
|
13
13
|
}
|
|
14
|
-
var warned = false;
|
|
15
14
|
function announceUnconfigured() {
|
|
16
|
-
if (warned) return;
|
|
17
|
-
warned = true;
|
|
15
|
+
if (bound.warned) return;
|
|
16
|
+
bound.warned = true;
|
|
18
17
|
if (typeof console !== "undefined") {
|
|
19
18
|
console.warn(
|
|
20
19
|
"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. Call configureEntityRefs(...) before rendering references."
|
package/dist/entity-doors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":[],"mappings":";;;;;;AAuHA,IAAM,QAAQ,UAAA,CAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,MAA6B,CAAE,CAAA;AAGvG,SAAS,oBAAoB,IAA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Q;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,KAAK,KAAA,CAAM,MAAA,EAAQ,KAAK,CAAA,EAAG,CAAA;AAAA,IACjE;AACA,IAAA,QAAA,CAAS,KAAK,EAAE,IAAA,EAAM,KAAA,EAAO,EAAA,EAAI,OAAO,CAAA;AACxC,IAAA,MAAA,GAAS,QAAQ,EAAA,CAAG,MAAA;AAAA,EACtB;AACA,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG,OAAO,CAAC,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,CAAA;AACzD,EAAA,IAAI,MAAA,GAAS,KAAK,MAAA,EAAQ;AACxB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA,EAAG,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,QAAA;AACT","file":"entity-doors.js","sourcesContent":["/**\n * src/entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nlet warned = false;\nfunction announceUnconfigured(): void {\n if (warned) return;\n warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. \" +\n \"Call configureEntityRefs(...) before rendering references.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/entity-ref/slot.ts","../src/entity-ref/doors.ts"],"names":[],"mappings":";;;;;;AAyHA,IAAM,KAAA,GAAQ,WAAW,qCAAA,EAAuC,OAAO,EAAE,IAAA,EAAM,IAAA,EAA8B,MAAA,EAAQ,KAAA,EAAM,CAAE,CAAA;AAGtH,SAAS,oBAAoB,IAAA,EAAkC;AACpE,EAAA,KAAA,CAAM,IAAA,GAAO,IAAA;AACf;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,OAAO,OAAA,CAAQ,MAAM,IAAI,CAAA;AAC3B;AAEA,SAAS,oBAAA,GAA6B;AACpC,EAAA,IAAI,MAAM,MAAA,EAAQ;AAClB,EAAA,KAAA,CAAM,MAAA,GAAS,IAAA;AACf,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAA,CAAQ,IAAA;AAAA,MACN;AAAA,KAEF;AAAA,EACF;AACF;AAEA,IAAM,qBAAA,GAA2C;AAAA,EAC/C,SAAA,EAAW,CAAC,KAAA,KAAU,KAAA;AAAA,EACtB,UAAU,MAAM;AAClB,CAAA;AAEO,SAAS,iBAAiB,GAAA,EAA6B;AAC5D,EAAA,MAAM,IAAA,GAAO,GAAA,CAAI,YAAA,IAAgB,GAAA,CAAI,IAAA;AACrC,EAAA,IAAI,IAAA,EAAM,YAAA,CAAa,IAAA,EAAM,QAA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entity-ref/slot.ts — @ai-matrx/records-ui/entity-doors (no \"use client\": pure, server-safe)\n *\n * THE ENTITY-REF HOST: what a reference to another record needs from the app that draws it.\n *\n * A reference (`EntityRef`, `EntityDoorControls`, `TextWithDoors`, `toastDoor`, `NewTabLink`) is\n * drawn EVERYWHERE — table cells, chat bubbles, toasts, sentences — far outside any\n * `<RecordsUiProvider>`. So, unlike the screens' host, this one is bound ONCE per page through\n * `configureEntityRefs(...)` (a module-level slot on `globalThis`, so every module-graph copy of the\n * package reads the same binding) before anything renders.\n *\n * The ports, each with a default that ANNOUNCES ITSELF instead of pretending:\n *\n * registry token → label, icon, route, title column (the app's scopes/entity registry).\n * Default: knows no token — every reference draws its name with no door.\n * adminHref the admin-shell twin of a record's route. Default: none.\n * hasPeek whether a quick-look exists for a kind. Default: none.\n * openPeek opens the app's ONE quick-look host. Default: opens `fallbackHref` in a new tab.\n * useAddress a HOOK resolving tokens whose address depends on more than the id (an agent's kind,\n * a team's organization). Default: none — the registry route is used.\n * Link the app's router link. Default: design-system's registered tap-target link, else <a>.\n * ErrorMenu the actions drawn beside a KNOWN refusal. Default: none.\n *\n * Unconfigured, every reference carries `data-entity-ref-host=\"unconfigured\"` and the first draw\n * warns once in the console, naming `configureEntityRefs`.\n *\n * The host MUST be configured before the first render: `useAddress` is a hook, and the number of\n * hooks a component calls cannot change between renders.\n */\n\nimport type { ComponentType, MouseEvent, ReactNode, Ref } from \"react\";\nimport { globalSlot } from \"@ai-matrx/kit/global-slot\";\nimport { openOutbound } from \"@ai-matrx/kit/outbound\";\n\n/** One registered entity type, as a reference draws it. */\nexport interface EntityRefDescriptor {\n /** Singular display label (\"Agent\", \"Note\"). */\n label: string;\n /** The type's icon. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Canonical route to one record, or null when the type has no page. */\n hrefFor: ((id: string) => string) | null;\n /** The column a generic quick-look reads the title from; null = no generic quick-look. */\n titleColumn: string | null;\n /**\n * True when the type's table is NOT browser-readable (a candidates lister stands in), so a\n * generic quick-look would always fail and is not offered.\n */\n listCandidatesOnly: boolean;\n}\n\n/** The entity registry as a reference needs it. */\nexport interface EntityRefRegistry {\n /** Raw token (a kind column owned by another system) → canonical token. */\n canonical(token: string): string;\n /** Canonical token → descriptor, or null for a token nobody registered. */\n describe(token: string): EntityRefDescriptor | null;\n}\n\n/** A quick-look request. */\nexport interface EntityRefPeekAsk {\n /** Peek catalog key. */\n kind: string;\n id: string;\n /** The destination the CALLER resolved, when a token alone cannot name it. */\n href?: string | null | undefined;\n anchor?: Element | null | undefined;\n trigger?: \"hover\" | \"click\" | undefined;\n /** Where the record opens when the host has no quick-look surface mounted. */\n fallbackHref?: string | null | undefined;\n}\n\n/** An address resolved by the host's `useAddress` hook. */\nexport type EntityAddress =\n | { state: \"ready\"; href: string }\n /** A REAL href that works while resolving (a server-side redirect route). */\n | { state: \"resolving\"; href: string }\n /** The record genuinely cannot be reached; `reason` is the sentence the UI says. */\n | { state: \"refused\"; reason: string };\n\nexport interface EntityRefLinkProps {\n href: string;\n target?: string | undefined;\n rel?: string | undefined;\n prefetch?: boolean | undefined;\n title?: string | undefined;\n className?: string | undefined;\n onClick?: ((event: MouseEvent<HTMLAnchorElement>) => void) | undefined;\n \"aria-label\"?: string | undefined;\n \"data-tap-target\"?: boolean | undefined;\n children?: ReactNode;\n ref?: Ref<HTMLAnchorElement> | undefined;\n}\n\n/** A person as an identity resolver answers them (UserIdentity-compatible). */\nexport interface EntityRefPerson {\n id?: string | null;\n email?: string | null;\n displayName?: string | null;\n avatarUrl?: string | null;\n}\n\nexport interface EntityRefHost {\n registry: EntityRefRegistry;\n adminHref?: ((token: string, id: string) => string | null) | undefined;\n hasPeek?: ((kind: string) => boolean) | undefined;\n openPeek?: ((ask: EntityRefPeekAsk) => void) | undefined;\n /**\n * A HOOK, called on every render of every reference: `id` is null for the tokens the host does\n * not resolve itself, and the hook returns null for them. Must call the same hooks every time.\n */\n useAddress?: ((token: string, id: string | null, context: string) => EntityAddress | null) | undefined;\n Link?: ComponentType<EntityRefLinkProps> | undefined;\n ErrorMenu?: ComponentType<{ error: string }> | undefined;\n /** Draws one person (avatar + name), compact. Default: the name as text. */\n Person?: ComponentType<{ user: EntityRefPerson; className?: string }> | undefined;\n}\n\n// One binding for every module-graph copy of the package (kit's globalSlot, like the person's zone).\n// `warned` rides the same slot: /entity-doors and /entity-ref each bundle this module, so a module-level\n// flag would warn once per copy (check-ships-once --state).\nconst bound = globalSlot(\"ai-matrx.records-ui.entity-ref-host\", () => ({ host: null as EntityRefHost | null, warned: false }));\n\n/** Bind the app's entity-ref host. Call once, at module load, before anything renders. */\nexport function configureEntityRefs(host: EntityRefHost | null): void {\n bound.host = host;\n}\n\n/** True once a host has been bound. */\nexport function entityRefsConfigured(): boolean {\n return Boolean(bound.host);\n}\n\nfunction announceUnconfigured(): void {\n if (bound.warned) return;\n bound.warned = true;\n if (typeof console !== \"undefined\") {\n console.warn(\n \"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. \" +\n \"Call configureEntityRefs(...) before rendering references.\",\n );\n }\n}\n\nconst UNCONFIGURED_REGISTRY: EntityRefRegistry = {\n canonical: (token) => token,\n describe: () => null,\n};\n\nexport function fallbackOpenPeek(ask: EntityRefPeekAsk): void {\n const href = ask.fallbackHref ?? ask.href;\n if (href) openOutbound(href, \"_blank\", \"noopener\");\n}\n\n/** The bound host's non-drawing ports, defaults filled (defaults announce themselves). */\nexport interface EntityRefPorts {\n configured: boolean;\n registry: EntityRefRegistry;\n adminHref: (token: string, id: string) => string | null;\n hasPeek: (kind: string) => boolean;\n openPeek: (ask: EntityRefPeekAsk) => void;\n useAddress: (token: string, id: string | null, context: string) => EntityAddress | null;\n}\n\nconst noAddress = () => null;\n\n/** The raw bound host, or null. */\nexport function boundEntityRefHost(): EntityRefHost | null {\n return bound.host;\n}\n\nexport function entityRefPorts(): EntityRefPorts {\n const host = boundEntityRefHost();\n if (!host) announceUnconfigured();\n return {\n configured: Boolean(host),\n registry: host?.registry ?? UNCONFIGURED_REGISTRY,\n adminHref: host?.adminHref ?? (() => null),\n hasPeek: host?.hasPeek ?? (() => false),\n openPeek: host?.openPeek ?? fallbackOpenPeek,\n useAddress: host?.useAddress ?? noAddress,\n };\n}\n\n/** A modified click (new tab/window, middle button) keeps the browser's native behavior. */\nexport function isNativeNewTabClick(e: {\n metaKey?: boolean;\n ctrlKey?: boolean;\n shiftKey?: boolean;\n altKey?: boolean;\n button?: number;\n}): boolean {\n return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);\n}\n\n","/**\n * Door resolution — the ONE place a (token, id) pair becomes reachable doors.\n *\n * THE DOOR LAW (common-docs/policies/no-dead-ends.md): if the UI names a thing\n * that has an identity in our system, the UI must let the user reach it. Two\n * different presentations need the same answer:\n *\n * `EntityRef` — a NAME with doors (the default; prefer it always)\n * `MatrxUuidCell` — an ID with doors (only when the name genuinely isn't\n * loaded — a raw FK column in a dense admin table)\n *\n * Both call `resolveEntityDoors`, so a registry edit lights up both at once and\n * neither can drift from the other. This module is deliberately component-free\n * and cheap to import: it pulls the entity registry (icons + `hrefFor`) and the\n * peek KIND LIST — never `features/organizations/peek/registry.ts`, which\n * statically imports all 19 peek components (THE FRAGMENTATION LAW).\n *\n * Adding a door for a new entity type is a registry edit, never a change here:\n * route → `hrefFor` in `features/scopes/registry/entityRegistry.ts`\n * peek → `features/organizations/peek/registry.ts` + `kinds-list.ts` for a\n * BESPOKE preview. Every registered entity with a readable title\n * column already gets the generic `RegistryPeek` for free, so a new\n * entity is previewable the moment it is registered — write a bespoke\n * one only when the kind deserves more than title/description/dates.\n */\n\nimport type { ComponentType } from \"react\";\nimport { entityRefPorts, type EntityRefDescriptor } from \"./slot\";\nimport { codeSpanText, findCodeRanges } from \"@ai-matrx/content-ir/source\";\nimport { isUuidValue } from \"@ai-matrx/kit/uuid\";\n\n// The one isUuidValue (kit): shape after trim. Re-exported so `/entity-doors` keeps offering it.\nexport { isUuidValue };\n\n/**\n * True when a value is a real uuid — the guard a surface needs BEFORE handing an\n * id to `EntityRef` / `EntityDoorControls`.\n *\n * Door resolution deliberately does not validate ids (a token's `hrefFor` is\n * free to use slugs), so any surface that DERIVES an id — parsing it out of a\n * surface key, reading an untyped column — must check first, or it mints a link\n * to `/agents/<junk>`: a door that opens on nothing, which the doctrine ranks\n * worse than no door at all.\n *\n * It lives here, beside `resolveEntityDoors`, because this module is the one\n * component-free entry point on the door path. It used to live only inside\n * `MatrxUuidCell`, which meant guarding an id dragged a table cell (and its\n * tooltip/toast/peek-host graph) into whatever chunk needed the check —\n * THE FRAGMENTATION LAW, paid for a three-line regex. Every importer was moved\n * to this module in the same change — there is deliberately no re-export left\n * behind in `MatrxUuidCell`, because that tripped `no-barrel-files` and the\n * rule is right.\n */\n\n/**\n * Entity tokens whose peek is registered under a different catalog key.\n * Keep this at zero entries wherever possible — the real fix is aligning the\n * peek registry key with the canonical token.\n */\nconst PEEK_KEY_BY_TOKEN: Record<string, string> = {\n app: \"agent_app\",\n pick_list: \"pick_list\",\n structured_list: \"pick_list\",\n};\n\n/**\n * True when `RegistryPeek` can preview this entity even though no bespoke peek\n * is registered — it reads the registry's own schema/table/title column, so it\n * needs a title column and a table the BROWSER can actually read.\n *\n * `listCandidates` is the marker for the exception: a token only carries one\n * because its schema isn't PostgREST-exposed (`data_store` → `rag`), and\n * offering a preview button that always fails is its own dead end.\n */\nfunction hasRegistryPeek(info: EntityRefDescriptor | null): boolean {\n return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;\n}\n\nexport interface EntityDoors {\n /** Canonical route to the record, or null when the token has no `hrefFor`. */\n href: string | null;\n /** True when a peek is registered for this token. */\n canPeek: boolean;\n /** Catalog key to hand `<ResourcePeekHost kind=…>`. */\n peekKind: string;\n /** Registry icon for the entity type, when one is registered. */\n Icon: ComponentType<{ className?: string }> | null;\n /** Singular display label (\"Agent\", \"Note\"), or null for unknown tokens. */\n label: string | null;\n}\n\n/**\n * Resolve every door we can open for one record.\n *\n * `hrefOverride` wins over the registry route — for records that live in two\n * shells (a system agent under `/administration/…` vs a personal one under\n * `/agents/…`). It is honored EXACTLY: an explicit `null` means \"this\n * particular record has no door\" and must not fall through to the registry,\n * which would send the user somewhere the caller deliberately ruled out. Only\n * `undefined` (no opinion) defers.\n *\n * Unknown tokens degrade to \"no doors\", never throw: a surface passing a token\n * we don't register yet must still render its text.\n */\nexport function resolveEntityDoors(\n token: string,\n id: string,\n hrefOverride?: string | null,\n): EntityDoors {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;\n return {\n href:\n hrefOverride !== undefined\n ? hrefOverride\n : (host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null),\n canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),\n peekKind,\n Icon: info?.Icon ?? null,\n label: info?.label ?? null,\n };\n}\n\n/**\n * Resolve an FK COLUMN NAME to a canonical entity token — `agent_id` → `agent`,\n * `task_id` → `task`. Deliberately strict: exact `<token>_id` only, and only\n * for tokens that actually have a door. Anything else returns null rather than\n * guessing, because a wrong link is worse than no link (a `<token>_id` that\n * points somewhere else would send the user to another record entirely).\n *\n * Used by generic surfaces that render a row's raw columns (the data-table row\n * inspector) and therefore can't be told each column's target by hand.\n */\nexport function doorTokenFromColumnName(column: string): string | null {\n const name = column.trim().toLowerCase();\n if (!name.endsWith(\"_id\")) return null;\n const token = name.slice(0, -3);\n if (!token) return null;\n return hasAnyDoor(token) ? token : null;\n}\n\n/**\n * True when the platform can open this token at all (route or peek).\n * Use it to decide whether a bare id is worth rendering as a door — never to\n * decide whether to render the record at all.\n */\nexport function hasAnyDoor(token: string): boolean {\n const host = entityRefPorts();\n const info = host.registry.describe(token);\n return (\n Boolean(info?.hrefFor) ||\n host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) ||\n hasRegistryPeek(info)\n );\n}\n\n// ── Ids inside SENTENCES ─────────────────────────────────────────────────────\n//\n// 🚨 THE DEFECT THIS CLOSES: our servers write refusals for people —\n// \"resolved system agent 8f0bbfc2-… breaks the mandate contract\" — and every\n// screen printed them as flat text. The sentence NAMES a record that has an\n// identity in our system, so THE DOOR LAW applies to it exactly as it does to\n// a table cell: the person reading the refusal must be able to open the agent\n// it is accusing, without hand-copying a uuid into a URL bar.\n//\n// A server sentence is verbatim by policy (`ServerNotes`, `RunFailureCard`),\n// so nothing here rewrites, shortens or re-orders a word — the only change is\n// that the ids inside it become reachable.\n\n/**\n * Everyday nouns that name a registered entity by a different word than its\n * canonical token. Only add an entry you have VERIFIED points at the same\n * record type — a wrong door is worse than no door.\n */\nconst NOUN_ALIASES: Record<string, string> = {\n org: \"organization\",\n organisation: \"organization\",\n bot: \"agent\",\n workflow_definition: \"workflow\",\n // scheduler.sch_task — the scheduler's own sentences say \"scheduled task\".\n schedule: \"sch_task\",\n scheduled_task: \"sch_task\",\n};\n\n/** A word as it appears in prose → a candidate entity token. */\nfunction nounToToken(word: string): string {\n const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, \"\");\n // \"agents\" / \"mandates\" — prose pluralises, tokens don't.\n const singular =\n bare.length > 3 && bare.endsWith(\"s\") && !bare.endsWith(\"ss\")\n ? bare.slice(0, -1)\n : bare;\n return NOUN_ALIASES[singular] ?? singular;\n}\n\n/**\n * The entity token a sentence was talking about right before it printed an id.\n *\n * Deliberately conservative — it reads at most the four words in front of the\n * id, nearest first, and accepts only a word that resolves to a token the\n * platform can actually OPEN (`hasAnyDoor`). Anything else returns null and\n * the caller prints the id as it always did. Guessing here would mint links to\n * `/agents/<a workflow id>`: a door onto the wrong record, which reads as a\n * fact and is a lie.\n */\nexport function tokenFromPrecedingWords(preceding: string): string | null {\n const words = preceding.trim().split(/\\s+/).filter(Boolean).slice(-4);\n // The compound ending at the id first, longest first (\"scheduled task\" →\n // `sch_task`, \"agent version\" → `agent_version`). A bare noun that is ALSO a\n // token must not win over the compound it closes: \"scheduled task <id>\"\n // resolved to `task` and minted a door onto /tasks/<a schedule id> — the\n // wrong record, which reads as a fact and is a lie (2026-09-11).\n for (let len = words.length; len >= 2; len--) {\n const joined = words.slice(-len).map(nounToToken).filter(Boolean).join(\"_\");\n const phrase = NOUN_ALIASES[joined] ?? joined;\n if (phrase && hasAnyDoor(phrase)) return phrase;\n }\n // Then the nearest single noun that opens.\n for (let i = words.length - 1; i >= 0; i--) {\n const single = nounToToken(words[i] ?? \"\");\n if (single && hasAnyDoor(single)) return single;\n }\n return null;\n}\n\n/**\n * One piece of a sentence: plain prose, an id we can open a door on, or a run\n * the author marked as CODE with markdown backticks.\n */\nexport type SentenceSegment =\n | { kind: \"text\"; text: string }\n | { kind: \"code\"; text: string }\n | { kind: \"ref\"; id: string; token: string };\n\nconst UUID_IN_TEXT_RE =\n /\\b[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\\b/gi;\n\n/**\n * INLINE CODE, THE WAY ITS AUTHOR WROTE IT.\n *\n * 🚨 THE DEFECT (V-PARITY/UX R-O2, both walk rounds). Sentences that name a\n * field, a key or a variable mark it the one way every author on this platform\n * marks it — markdown backticks:\n *\n * Its structured output is missing `title`, `slides` — whatever reads this\n * job's result requires them.\n *\n * Printed through a plain `<span>` the backtick CHARACTERS land on a subject\n * matter expert's screen. There is no second renderer for this: every sentence\n * somebody else wrote already reaches a person through `TextWithDoors`, so the\n * marks are understood HERE, beside the ids, and every one of its ~10 adopting\n * surfaces is fixed by the same three lines.\n *\n * Deliberately ONLY single-backtick spans, and never across a newline: this is\n * a sentence renderer, not a markdown engine. Anything else — an unmatched\n * backtick, a fenced block — stays exactly as it was typed.\n */\n\n/**\n * Split a server-authored sentence into prose, inline code and openable ids.\n *\n * `defaultToken` is what the CALL SITE knows that the sentence does not — a\n * mandate-resolution refusal is always about an agent, so its screen may say\n * so. It is used only when the prose itself names nothing openable.\n *\n * Every character of the input survives into the output in order — apart from\n * the two backticks delimiting an inline-code run, which are MARKUP the author\n * wrote to say \"this is code\" and were never words meant to be read. A caller\n * that joins the segments back together gets the server's words unchanged.\n */\nexport function segmentSentenceIds(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const out: SentenceSegment[] = [];\n let prose = 0;\n // Inline code by THE one code-range rule (@ai-matrx/content-ir/source).\n for (const range of text.includes(\"`\") ? findCodeRanges(text) : []) {\n if (range.kind !== \"span\" || range.start < prose) continue;\n if (range.start > prose) {\n out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));\n }\n out.push({ kind: \"code\", text: codeSpanText(text.slice(range.start, range.end)) });\n prose = range.end;\n }\n if (out.length === 0) return segmentIdsOnly(text, defaultToken);\n if (prose < text.length) {\n out.push(...segmentIdsOnly(text.slice(prose), defaultToken));\n }\n return out;\n}\n\n/** The id half, run over one run of prose that carries no code marks. */\nfunction segmentIdsOnly(\n text: string,\n defaultToken?: string | null,\n): SentenceSegment[] {\n const segments: SentenceSegment[] = [];\n let cursor = 0;\n UUID_IN_TEXT_RE.lastIndex = 0;\n for (\n let match = UUID_IN_TEXT_RE.exec(text);\n match !== null;\n match = UUID_IN_TEXT_RE.exec(text)\n ) {\n const id = match[0];\n const start = match.index;\n const token =\n tokenFromPrecedingWords(text.slice(cursor, start)) ??\n (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);\n if (token === null) continue; // No door we trust — leave it in the prose.\n if (start > cursor) {\n segments.push({ kind: \"text\", text: text.slice(cursor, start) });\n }\n segments.push({ kind: \"ref\", id, token });\n cursor = start + id.length;\n }\n if (segments.length === 0) return [{ kind: \"text\", text }];\n if (cursor < text.length) {\n segments.push({ kind: \"text\", text: text.slice(cursor) });\n }\n return segments;\n}\n"]}
|
package/dist/entity-ref.cjs
CHANGED
|
@@ -55,17 +55,16 @@ module.exports = __toCommonJS(entityRefEntry_exports);
|
|
|
55
55
|
// src/entity-ref/slot.ts
|
|
56
56
|
var import_global_slot = require("@ai-matrx/kit/global-slot");
|
|
57
57
|
var import_outbound = require("@ai-matrx/kit/outbound");
|
|
58
|
-
var bound = (0, import_global_slot.globalSlot)("ai-matrx.records-ui.entity-ref-host", () => ({ host: null }));
|
|
58
|
+
var bound = (0, import_global_slot.globalSlot)("ai-matrx.records-ui.entity-ref-host", () => ({ host: null, warned: false }));
|
|
59
59
|
function configureEntityRefs(host) {
|
|
60
60
|
bound.host = host;
|
|
61
61
|
}
|
|
62
62
|
function entityRefsConfigured() {
|
|
63
63
|
return Boolean(bound.host);
|
|
64
64
|
}
|
|
65
|
-
var warned = false;
|
|
66
65
|
function announceUnconfigured() {
|
|
67
|
-
if (warned) return;
|
|
68
|
-
warned = true;
|
|
66
|
+
if (bound.warned) return;
|
|
67
|
+
bound.warned = true;
|
|
69
68
|
if (typeof console !== "undefined") {
|
|
70
69
|
console.warn(
|
|
71
70
|
"[@ai-matrx/records-ui/entity-ref] Entity reference host is not configured. Call configureEntityRefs(...) before rendering references."
|
|
@@ -389,7 +388,7 @@ function EntityRef({
|
|
|
389
388
|
"data-entity-ref-controls": true,
|
|
390
389
|
"data-reveal-on-hover": alwaysShowActions ? void 0 : "true",
|
|
391
390
|
className: (0, import_design_system.cn)(
|
|
392
|
-
"entity-ref-controls inline-flex shrink-0 items-center gap-0.5"
|
|
391
|
+
"entity-ref-controls inline-flex h-[1lh] shrink-0 items-center gap-0.5"
|
|
393
392
|
),
|
|
394
393
|
children: [
|
|
395
394
|
canPeek && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|