@ai-matrx/records-ui 0.116.79 → 0.116.80

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.
@@ -0,0 +1,795 @@
1
+ "use client";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/entityRefEntry.ts
32
+ var entityRefEntry_exports = {};
33
+ __export(entityRefEntry_exports, {
34
+ ENTITY_DOOR_CONTROL_CLASS: () => ENTITY_DOOR_CONTROL_CLASS,
35
+ EntityDoorControls: () => EntityDoorControls,
36
+ EntityRef: () => EntityRef,
37
+ NEW_TAB_CONTROL_CLASS: () => NEW_TAB_CONTROL_CLASS,
38
+ NewTabLink: () => NewTabLink,
39
+ RecordStamps: () => RecordStamps,
40
+ TextWithDoors: () => TextWithDoors,
41
+ configureEntityRefs: () => configureEntityRefs,
42
+ doorTokenFromColumnName: () => doorTokenFromColumnName,
43
+ entityRefsConfigured: () => entityRefsConfigured,
44
+ hasAnyDoor: () => hasAnyDoor,
45
+ isNativeNewTabClick: () => isNativeNewTabClick,
46
+ isUuidValue: () => isUuidValue,
47
+ resolveEntityDoors: () => resolveEntityDoors,
48
+ segmentSentenceIds: () => segmentSentenceIds,
49
+ toastDoor: () => toastDoor,
50
+ tokenFromPrecedingWords: () => tokenFromPrecedingWords,
51
+ useEntityHref: () => useEntityHref
52
+ });
53
+ module.exports = __toCommonJS(entityRefEntry_exports);
54
+
55
+ // src/entity-ref/slot.ts
56
+ var import_global_slot = require("@ai-matrx/kit/global-slot");
57
+ var bound = (0, import_global_slot.globalSlot)("ai-matrx.records-ui.entity-ref-host", () => ({ host: null }));
58
+ function configureEntityRefs(host) {
59
+ bound.host = host;
60
+ }
61
+ function entityRefsConfigured() {
62
+ return Boolean(bound.host);
63
+ }
64
+ var warned = false;
65
+ function announceUnconfigured() {
66
+ if (warned) return;
67
+ warned = true;
68
+ if (typeof console !== "undefined") {
69
+ console.warn(
70
+ "[@ai-matrx/records-ui/entity-ref] no host configured: references draw names with no doors. Call configureEntityRefs(...) once before the first render."
71
+ );
72
+ }
73
+ }
74
+ var UNCONFIGURED_REGISTRY = {
75
+ canonical: (token) => token,
76
+ describe: () => null
77
+ };
78
+ function fallbackOpenPeek(ask) {
79
+ const href = ask.fallbackHref ?? ask.href;
80
+ if (href && typeof window !== "undefined") window.open(href, "_blank", "noopener");
81
+ }
82
+ var noAddress = () => null;
83
+ function boundEntityRefHost() {
84
+ return bound.host;
85
+ }
86
+ function entityRefPorts() {
87
+ const host = boundEntityRefHost();
88
+ if (!host) announceUnconfigured();
89
+ return {
90
+ configured: Boolean(host),
91
+ registry: host?.registry ?? UNCONFIGURED_REGISTRY,
92
+ adminHref: host?.adminHref ?? (() => null),
93
+ hasPeek: host?.hasPeek ?? (() => false),
94
+ openPeek: host?.openPeek ?? fallbackOpenPeek,
95
+ useAddress: host?.useAddress ?? noAddress
96
+ };
97
+ }
98
+ function isNativeNewTabClick(e) {
99
+ return Boolean(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button === 1);
100
+ }
101
+
102
+ // src/entity-ref/doors.ts
103
+ var import_source = require("@ai-matrx/content-ir/source");
104
+ var import_uuid = require("@ai-matrx/kit/uuid");
105
+ function isUuidValue(value) {
106
+ return typeof value === "string" && (0, import_uuid.isRfc9562Uuid)(value.trim());
107
+ }
108
+ var PEEK_KEY_BY_TOKEN = {
109
+ app: "agent_app",
110
+ pick_list: "pick_list",
111
+ structured_list: "pick_list"
112
+ };
113
+ function hasRegistryPeek(info) {
114
+ return Boolean(info?.titleColumn) && !info?.listCandidatesOnly;
115
+ }
116
+ function resolveEntityDoors(token, id, hrefOverride) {
117
+ const host = entityRefPorts();
118
+ const info = host.registry.describe(token);
119
+ const peekKind = PEEK_KEY_BY_TOKEN[token] ?? token;
120
+ return {
121
+ href: hrefOverride !== void 0 ? hrefOverride : host.adminHref(token, id) ?? info?.hrefFor?.(id) ?? null,
122
+ canPeek: host.hasPeek(peekKind) || hasRegistryPeek(info),
123
+ peekKind,
124
+ Icon: info?.Icon ?? null,
125
+ label: info?.label ?? null
126
+ };
127
+ }
128
+ function doorTokenFromColumnName(column) {
129
+ const name = column.trim().toLowerCase();
130
+ if (!name.endsWith("_id")) return null;
131
+ const token = name.slice(0, -3);
132
+ if (!token) return null;
133
+ return hasAnyDoor(token) ? token : null;
134
+ }
135
+ function hasAnyDoor(token) {
136
+ const host = entityRefPorts();
137
+ const info = host.registry.describe(token);
138
+ return Boolean(info?.hrefFor) || host.hasPeek(PEEK_KEY_BY_TOKEN[token] ?? token) || hasRegistryPeek(info);
139
+ }
140
+ var NOUN_ALIASES = {
141
+ org: "organization",
142
+ organisation: "organization",
143
+ bot: "agent",
144
+ workflow_definition: "workflow",
145
+ // scheduler.sch_task — the scheduler's own sentences say "scheduled task".
146
+ schedule: "sch_task",
147
+ scheduled_task: "sch_task"
148
+ };
149
+ function nounToToken(word) {
150
+ const bare = word.toLowerCase().replace(/[^a-z0-9_]/g, "");
151
+ const singular = bare.length > 3 && bare.endsWith("s") && !bare.endsWith("ss") ? bare.slice(0, -1) : bare;
152
+ return NOUN_ALIASES[singular] ?? singular;
153
+ }
154
+ function tokenFromPrecedingWords(preceding) {
155
+ const words = preceding.trim().split(/\s+/).filter(Boolean).slice(-4);
156
+ for (let len = words.length; len >= 2; len--) {
157
+ const joined = words.slice(-len).map(nounToToken).filter(Boolean).join("_");
158
+ const phrase = NOUN_ALIASES[joined] ?? joined;
159
+ if (phrase && hasAnyDoor(phrase)) return phrase;
160
+ }
161
+ for (let i = words.length - 1; i >= 0; i--) {
162
+ const single = nounToToken(words[i] ?? "");
163
+ if (single && hasAnyDoor(single)) return single;
164
+ }
165
+ return null;
166
+ }
167
+ var UUID_IN_TEXT_RE = /\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;
168
+ function segmentSentenceIds(text, defaultToken) {
169
+ const out = [];
170
+ let prose = 0;
171
+ for (const range of text.includes("`") ? (0, import_source.findCodeRanges)(text) : []) {
172
+ if (range.kind !== "span" || range.start < prose) continue;
173
+ if (range.start > prose) {
174
+ out.push(...segmentIdsOnly(text.slice(prose, range.start), defaultToken));
175
+ }
176
+ out.push({ kind: "code", text: (0, import_source.codeSpanText)(text.slice(range.start, range.end)) });
177
+ prose = range.end;
178
+ }
179
+ if (out.length === 0) return segmentIdsOnly(text, defaultToken);
180
+ if (prose < text.length) {
181
+ out.push(...segmentIdsOnly(text.slice(prose), defaultToken));
182
+ }
183
+ return out;
184
+ }
185
+ function segmentIdsOnly(text, defaultToken) {
186
+ const segments = [];
187
+ let cursor = 0;
188
+ UUID_IN_TEXT_RE.lastIndex = 0;
189
+ for (let match = UUID_IN_TEXT_RE.exec(text); match !== null; match = UUID_IN_TEXT_RE.exec(text)) {
190
+ const id = match[0];
191
+ const start = match.index;
192
+ const token = tokenFromPrecedingWords(text.slice(cursor, start)) ?? (defaultToken && hasAnyDoor(defaultToken) ? defaultToken : null);
193
+ if (token === null) continue;
194
+ if (start > cursor) {
195
+ segments.push({ kind: "text", text: text.slice(cursor, start) });
196
+ }
197
+ segments.push({ kind: "ref", id, token });
198
+ cursor = start + id.length;
199
+ }
200
+ if (segments.length === 0) return [{ kind: "text", text }];
201
+ if (cursor < text.length) {
202
+ segments.push({ kind: "text", text: text.slice(cursor) });
203
+ }
204
+ return segments;
205
+ }
206
+
207
+ // src/entity-ref/EntityRef.tsx
208
+ var import_icons = require("@ai-matrx/design-system/icons");
209
+ var import_design_system = require("@ai-matrx/design-system");
210
+
211
+ // src/entity-ref/useEntityHref.ts
212
+ function useEntityHref(token, id, hrefOverride) {
213
+ const host = entityRefPorts();
214
+ const canonicalToken = host.registry.canonical(token);
215
+ const door = host.useAddress(
216
+ canonicalToken,
217
+ hrefOverride ? null : id,
218
+ `EntityRef token="${token}"`
219
+ );
220
+ if (hrefOverride) return { href: hrefOverride, refusal: null, resolving: false };
221
+ if (door) {
222
+ if (door.state === "ready") return { href: door.href, refusal: null, resolving: false };
223
+ if (door.state === "resolving") return { href: door.href, refusal: null, resolving: true };
224
+ return { href: null, refusal: door.reason, resolving: false };
225
+ }
226
+ const info = host.registry.describe(canonicalToken);
227
+ return {
228
+ href: host.adminHref(canonicalToken, id) ?? info?.hrefFor?.(id) ?? null,
229
+ refusal: null,
230
+ resolving: false
231
+ };
232
+ }
233
+
234
+ // src/entity-ref/host.tsx
235
+ var import_tap_target = require("@ai-matrx/design-system/tap-target");
236
+ var import_jsx_runtime = require("react/jsx-runtime");
237
+ function PlainLink({ href, prefetch: _prefetch, children, ref, ...rest }) {
238
+ const Registered = (0, import_tap_target.getTapTargetLinkComponent)();
239
+ if (Registered) {
240
+ const R = Registered;
241
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(R, { href, ref, ...rest, children });
242
+ }
243
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href, ref, ...rest, children });
244
+ }
245
+ function PlainPerson({ user, className }) {
246
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className, children: user.displayName || user.email || "Unknown person" });
247
+ }
248
+ function entityRefHost() {
249
+ const host = boundEntityRefHost();
250
+ return { ...entityRefPorts(), Link: host?.Link ?? PlainLink, ErrorMenu: host?.ErrorMenu ?? null, Person: host?.Person ?? PlainPerson };
251
+ }
252
+ function hostMark(host) {
253
+ return host.configured ? void 0 : "unconfigured";
254
+ }
255
+ function ArrowUpRightGlyph({ className }) {
256
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
257
+ "svg",
258
+ {
259
+ xmlns: "http://www.w3.org/2000/svg",
260
+ width: "24",
261
+ height: "24",
262
+ viewBox: "0 0 24 24",
263
+ fill: "none",
264
+ stroke: "currentColor",
265
+ strokeWidth: 2,
266
+ strokeLinecap: "round",
267
+ strokeLinejoin: "round",
268
+ className: className ? `lucide-arrow-up-right ${className}` : "lucide-arrow-up-right",
269
+ "aria-hidden": true,
270
+ children: [
271
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 7h10v10" }),
272
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M7 17 17 7" })
273
+ ]
274
+ }
275
+ );
276
+ }
277
+
278
+ // src/entity-ref/EntityRef.tsx
279
+ var import_jsx_runtime2 = require("react/jsx-runtime");
280
+ var CONTROL_CLASS = "flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground";
281
+ function EntityRef({
282
+ token,
283
+ id,
284
+ name,
285
+ href,
286
+ showIcon = true,
287
+ disablePeek = false,
288
+ disableNewTab = false,
289
+ openInNewTab = false,
290
+ wrap = false,
291
+ fill = false,
292
+ labelClassName,
293
+ nameClassName,
294
+ alwaysShowActions = false,
295
+ extraActions,
296
+ onOpen,
297
+ className,
298
+ children
299
+ }) {
300
+ const host = entityRefHost();
301
+ const AppLink = host.Link;
302
+ const ErrorAlchemyMenu = host.ErrorMenu;
303
+ const canonicalToken = host.registry.canonical(token);
304
+ const info = host.registry.describe(canonicalToken);
305
+ const {
306
+ href: resolvedHref,
307
+ refusal,
308
+ resolving: hrefResolving
309
+ } = useEntityHref(token, id, href);
310
+ const canPeek = !disablePeek && host.hasPeek(canonicalToken);
311
+ const label = name?.trim() || `${(0, import_design_system.displayId)(id)}\u2026`;
312
+ const labelBody = children ?? label;
313
+ const Icon = info?.Icon ?? null;
314
+ const showNewTab = Boolean(resolvedHref) && !disableNewTab && !openInNewTab;
315
+ const hasControls = canPeek || showNewTab || Boolean(extraActions);
316
+ const stop = (e) => e.stopPropagation();
317
+ const labelFit = (0, import_design_system.cn)(
318
+ wrap ? "break-all" : "truncate",
319
+ fill && "grow",
320
+ labelClassName,
321
+ nameClassName
322
+ );
323
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
324
+ "span",
325
+ {
326
+ className: (0, import_design_system.cn)(
327
+ "entity-ref group/entity-ref inline-flex min-w-0 max-w-full items-center gap-1",
328
+ className
329
+ ),
330
+ "data-entity-ref-host": hostMark(host),
331
+ children: [
332
+ showIcon && Icon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: "h-3.5 w-3.5 shrink-0 text-muted-foreground" }),
333
+ resolvedHref ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
334
+ AppLink,
335
+ {
336
+ href: resolvedHref,
337
+ target: openInNewTab ? "_blank" : void 0,
338
+ rel: openInNewTab ? "noopener noreferrer" : void 0,
339
+ prefetch: openInNewTab || hrefResolving ? false : void 0,
340
+ onClick: (e) => {
341
+ stop(e);
342
+ if (!onOpen || isNativeNewTabClick(e)) return;
343
+ e.preventDefault();
344
+ onOpen();
345
+ },
346
+ title: openInNewTab ? `Open ${label} in a new tab` : `Open ${label}`,
347
+ "data-tap-target": true,
348
+ className: (0, import_design_system.cn)(
349
+ "min-w-0 text-inherit underline-offset-2 hover:text-primary hover:underline",
350
+ labelFit
351
+ ),
352
+ children: labelBody
353
+ }
354
+ ) : onOpen ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
355
+ "button",
356
+ {
357
+ type: "button",
358
+ onClick: (e) => {
359
+ stop(e);
360
+ onOpen();
361
+ },
362
+ title: `Open ${label}`,
363
+ className: (0, import_design_system.cn)(
364
+ "min-w-0 text-left text-inherit underline-offset-2 hover:text-primary hover:underline",
365
+ labelFit
366
+ ),
367
+ children: labelBody
368
+ }
369
+ ) : (
370
+ /* No door. NOTHING FAILS SILENTLY: when we KNOW the record cannot be
371
+ reached (`refusal`), the title says so in a sentence naming the id
372
+ — a name with no explanation reads as a broken page. While an
373
+ address is still resolving there is nothing to confess yet. */
374
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
375
+ "span",
376
+ {
377
+ className: (0, import_design_system.cn)("min-w-0", refusal && "cursor-help", labelFit),
378
+ title: refusal ?? label,
379
+ "aria-describedby": void 0,
380
+ "data-agent-link-refused": refusal ? "true" : void 0,
381
+ "data-agent-link-resolving": hrefResolving ? "true" : void 0,
382
+ children: [
383
+ labelBody,
384
+ refusal && ErrorAlchemyMenu ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorAlchemyMenu, { error: refusal }) : null
385
+ ]
386
+ }
387
+ )
388
+ ),
389
+ hasControls && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
390
+ "span",
391
+ {
392
+ "data-entity-ref-controls": true,
393
+ "data-reveal-on-hover": alwaysShowActions ? void 0 : "true",
394
+ className: (0, import_design_system.cn)(
395
+ "entity-ref-controls inline-flex shrink-0 items-center gap-0.5"
396
+ ),
397
+ children: [
398
+ canPeek && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
399
+ "button",
400
+ {
401
+ type: "button",
402
+ title: `Quick look at ${label}`,
403
+ "aria-label": `Quick look at ${label}`,
404
+ onClick: (e) => {
405
+ stop(e);
406
+ host.openPeek({
407
+ kind: canonicalToken,
408
+ id,
409
+ // Keep the peek's footer aligned with the door that opened it.
410
+ // `AppletRef`, for example, deliberately overrides the generic
411
+ // app route with the administration editor route.
412
+ href,
413
+ anchor: e.currentTarget,
414
+ trigger: "click",
415
+ fallbackHref: resolvedHref
416
+ });
417
+ },
418
+ className: CONTROL_CLASS,
419
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.LightbulbIcon, { className: "h-3 w-3" })
420
+ }
421
+ ),
422
+ resolvedHref && showNewTab && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
423
+ AppLink,
424
+ {
425
+ href: resolvedHref,
426
+ target: "_blank",
427
+ rel: "noopener noreferrer",
428
+ prefetch: false,
429
+ onClick: stop,
430
+ title: `Open ${label} in a new tab`,
431
+ "aria-label": `Open ${label} in a new tab`,
432
+ className: CONTROL_CLASS,
433
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.ExternalLinkIcon, { className: "h-3 w-3" })
434
+ }
435
+ ),
436
+ extraActions
437
+ ]
438
+ }
439
+ )
440
+ ]
441
+ }
442
+ );
443
+ }
444
+
445
+ // src/entity-ref/EntityDoorControls.tsx
446
+ var import_icons2 = require("@ai-matrx/design-system/icons");
447
+ var import_controls = require("@ai-matrx/design-system/controls");
448
+ var import_design_system2 = require("@ai-matrx/design-system");
449
+ var import_jsx_runtime3 = require("react/jsx-runtime");
450
+ var ENTITY_DOOR_CONTROL_CLASS = "flex h-5 w-5 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground";
451
+ function EntityDoorControls({
452
+ token,
453
+ id,
454
+ name,
455
+ href,
456
+ disablePeek = false,
457
+ disableNewTab = false,
458
+ showOpen = false,
459
+ alwaysShowActions = false,
460
+ revealOnHover = false,
461
+ extraActions,
462
+ size = "sm",
463
+ className
464
+ }) {
465
+ const glyph = "h-3 w-3";
466
+ const host = entityRefHost();
467
+ const Link = host.Link;
468
+ const doors = resolveEntityDoors(token, id, href);
469
+ const resolvedHref = doors.href;
470
+ const canPeek = !disablePeek && doors.canPeek;
471
+ const label = name?.trim() || `${(0, import_design_system2.displayId)(id)}\u2026`;
472
+ if (!canPeek && !resolvedHref && !extraActions) return null;
473
+ const stop = (e) => e.stopPropagation();
474
+ const openPeek = (anchor) => host.openPeek({
475
+ kind: doors.peekKind,
476
+ id,
477
+ // Forward the CALLER's `href`, not our resolved one. When a caller
478
+ // overrode it — because the token alone cannot say which surface
479
+ // this record opens on — the dialog would otherwise send "Open"
480
+ // somewhere our new-tab link does not go. Passing `resolvedHref`
481
+ // here instead would set the override on EVERY peek, including the
482
+ // ones where nobody overrode anything, and would then suppress the
483
+ // hardcoded href a token-less bespoke peek supplies for itself.
484
+ // `undefined` (no caller opinion) is the correct default.
485
+ href,
486
+ anchor,
487
+ trigger: "click",
488
+ fallbackHref: resolvedHref
489
+ });
490
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
491
+ "span",
492
+ {
493
+ className: (0, import_design_system2.cn)(
494
+ // THE control carries its own 3px half-gap, so a `md` cluster adds none.
495
+ "inline-flex shrink-0 items-center",
496
+ size !== "md" && "gap-0.5",
497
+ revealOnHover && !alwaysShowActions && "opacity-0 transition-opacity group-hover/entity-ref:opacity-100 group-hover:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100",
498
+ className
499
+ ),
500
+ children: [
501
+ size === "md" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
502
+ canPeek && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
503
+ import_controls.Button,
504
+ {
505
+ variant: "quiet",
506
+ icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons2.LightbulbIcon, {}),
507
+ title: `Quick look at ${label}`,
508
+ "aria-label": `Quick look at ${label}`,
509
+ onClick: (e) => {
510
+ stop(e);
511
+ openPeek(e.currentTarget);
512
+ }
513
+ }
514
+ ),
515
+ resolvedHref && showOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_controls.Button, { variant: "quiet", icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ArrowUpRightGlyph, {}), asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
516
+ Link,
517
+ {
518
+ href: resolvedHref,
519
+ "data-tap-target": true,
520
+ onClick: stop,
521
+ title: `Open ${label}`,
522
+ "aria-label": `Open ${label}`
523
+ }
524
+ ) }),
525
+ resolvedHref && !disableNewTab && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_controls.Button, { variant: "quiet", icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons2.ExternalLinkIcon, {}), asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
526
+ Link,
527
+ {
528
+ href: resolvedHref,
529
+ "data-tap-target": true,
530
+ target: "_blank",
531
+ rel: "noopener noreferrer",
532
+ onClick: stop,
533
+ title: `Open ${label} in a new tab`,
534
+ "aria-label": `Open ${label} in a new tab`
535
+ }
536
+ ) })
537
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
538
+ canPeek && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
539
+ "button",
540
+ {
541
+ type: "button",
542
+ title: `Quick look at ${label}`,
543
+ "aria-label": `Quick look at ${label}`,
544
+ onClick: (e) => {
545
+ stop(e);
546
+ openPeek(e.currentTarget);
547
+ },
548
+ className: ENTITY_DOOR_CONTROL_CLASS,
549
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons2.LightbulbIcon, { className: glyph })
550
+ }
551
+ ),
552
+ resolvedHref && showOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
553
+ Link,
554
+ {
555
+ href: resolvedHref,
556
+ "data-tap-target": true,
557
+ onClick: stop,
558
+ title: `Open ${label}`,
559
+ "aria-label": `Open ${label}`,
560
+ className: ENTITY_DOOR_CONTROL_CLASS,
561
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ArrowUpRightGlyph, { className: glyph })
562
+ }
563
+ ),
564
+ resolvedHref && !disableNewTab && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
565
+ Link,
566
+ {
567
+ href: resolvedHref,
568
+ "data-tap-target": true,
569
+ target: "_blank",
570
+ rel: "noopener noreferrer",
571
+ onClick: stop,
572
+ title: `Open ${label} in a new tab`,
573
+ "aria-label": `Open ${label} in a new tab`,
574
+ className: ENTITY_DOOR_CONTROL_CLASS,
575
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons2.ExternalLinkIcon, { className: glyph })
576
+ }
577
+ )
578
+ ] }),
579
+ extraActions
580
+ ]
581
+ }
582
+ ) });
583
+ }
584
+
585
+ // src/entity-ref/NewTabLink.tsx
586
+ var import_icons3 = require("@ai-matrx/design-system/icons");
587
+ var import_design_system3 = require("@ai-matrx/design-system");
588
+ var import_jsx_runtime4 = require("react/jsx-runtime");
589
+ var NEW_TAB_CONTROL_CLASS = "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring";
590
+ function NewTabLink({
591
+ href,
592
+ label,
593
+ className,
594
+ iconClassName,
595
+ children,
596
+ onOpen
597
+ }) {
598
+ const AppLink = entityRefHost().Link;
599
+ if (!href) return null;
600
+ const words = `Open ${label} in a new tab`;
601
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
602
+ AppLink,
603
+ {
604
+ href,
605
+ target: "_blank",
606
+ rel: "noopener noreferrer",
607
+ prefetch: false,
608
+ "data-tap-target": true,
609
+ onClick: (event) => {
610
+ event.stopPropagation();
611
+ onOpen?.();
612
+ },
613
+ title: words,
614
+ "aria-label": children ? void 0 : words,
615
+ className: (0, import_design_system3.cn)(children ? "inline-flex items-center gap-1.5" : NEW_TAB_CONTROL_CLASS, className),
616
+ children: [
617
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_icons3.ExternalLinkIcon, { className: (0, import_design_system3.cn)("h-3.5 w-3.5", iconClassName), "aria-hidden": true }),
618
+ children
619
+ ]
620
+ }
621
+ );
622
+ }
623
+
624
+ // src/entity-ref/TextWithDoors.tsx
625
+ var import_react = __toESM(require("react"), 1);
626
+ var import_jsx_runtime5 = require("react/jsx-runtime");
627
+ function TextWithDoors({
628
+ text,
629
+ defaultToken,
630
+ openInNewTab = true,
631
+ refClassName
632
+ }) {
633
+ if (!text) return null;
634
+ const segments = segmentSentenceIds(text, defaultToken);
635
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: segments.map(
636
+ (segment, index) => segment.kind === "text" ? (
637
+ // Position IS the identity of a prose run — the segments are a
638
+ // deterministic split of one immutable string, never a reorderable list.
639
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react.default.Fragment, { children: segment.text }, `t${index}`)
640
+ ) : segment.kind === "code" ? (
641
+ // 🚨 THE AUTHOR'S BACKTICKS ARE MARKUP, NOT WORDS (R-O2). A sentence
642
+ // naming `title` and `slides` reaches a subject matter expert, and
643
+ // the marks are how its author said "these are field names" — so
644
+ // they become a `<code>`, not two stray punctuation characters on
645
+ // the screen. Same font treatment as an id, one class of thing.
646
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
647
+ "code",
648
+ {
649
+ className: "rounded bg-muted px-1 py-px font-mono text-[0.95em]",
650
+ children: segment.text
651
+ },
652
+ `c${index}`
653
+ )
654
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
655
+ EntityRef,
656
+ {
657
+ token: segment.token,
658
+ id: segment.id,
659
+ name: segment.id,
660
+ showIcon: false,
661
+ disablePeek: true,
662
+ disableNewTab: true,
663
+ wrap: true,
664
+ openInNewTab,
665
+ className: refClassName ?? "align-baseline font-mono text-[0.95em]"
666
+ },
667
+ `r${index}:${segment.id}`
668
+ )
669
+ ) });
670
+ }
671
+
672
+ // src/entity-ref/toastDoor.tsx
673
+ var import_jsx_runtime6 = require("react/jsx-runtime");
674
+ function toastDoor(token, id, options = {}) {
675
+ if (!id) return void 0;
676
+ const { href } = resolveEntityDoors(token, id, options.href);
677
+ if (!href) return void 0;
678
+ const Link = entityRefHost().Link;
679
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
680
+ Link,
681
+ {
682
+ href,
683
+ className: "shrink-0 rounded bg-primary px-2 py-1 type-secondary font-medium text-primary-foreground transition-colors hover:bg-primary/90",
684
+ children: options.label ?? "Open"
685
+ }
686
+ );
687
+ }
688
+
689
+ // src/entity-ref/RecordStamps.tsx
690
+ var import_design_system4 = require("@ai-matrx/design-system");
691
+ var import_jsx_runtime7 = require("react/jsx-runtime");
692
+ function Stamp({
693
+ label,
694
+ at,
695
+ actorId,
696
+ formatTimestamp,
697
+ resolveActor,
698
+ tone,
699
+ showActor = true
700
+ }) {
701
+ if (!at) return null;
702
+ const actor = resolveActor?.(actorId) ?? null;
703
+ const Person = entityRefHost().Person;
704
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "min-w-0", children: [
705
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("dt", { className: "type-meta font-semibold uppercase tracking-wide text-muted-foreground", children: label }),
706
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
707
+ "dd",
708
+ {
709
+ className: (0, import_design_system4.cn)(
710
+ "mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 type-secondary text-foreground",
711
+ tone === "warning" && "text-warning"
712
+ ),
713
+ children: [
714
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "whitespace-nowrap", children: formatTimestamp(at) }),
715
+ !showActor ? null : actor ? actor.user ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Person, { user: actor.user, className: "min-w-0 gap-1.5 type-secondary" }) : actor.loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-muted-foreground", children: "resolving\u2026" }) : (
716
+ // Honest: we know an account acted, and we cannot name it (they
717
+ // are not a current member of this organization). Showing the id
718
+ // as a door would be a lie — it is offered as a support handle.
719
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
720
+ "span",
721
+ {
722
+ className: "truncate font-mono type-meta text-muted-foreground",
723
+ title: `Account ${actor.id} \u2014 no longer a member of this organization`,
724
+ children: [
725
+ "a former member \xB7 ",
726
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_design_system4.RecordId, { value: actor.id, label: "Account" })
727
+ ]
728
+ }
729
+ )
730
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "text-muted-foreground", children: "by the system" })
731
+ ]
732
+ }
733
+ )
734
+ ] });
735
+ }
736
+ function RecordStamps({
737
+ createdAt,
738
+ createdBy,
739
+ component = false,
740
+ updatedAt,
741
+ updatedBy,
742
+ deletedAt,
743
+ version,
744
+ formatTimestamp,
745
+ resolveActor,
746
+ className
747
+ }) {
748
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
749
+ "dl",
750
+ {
751
+ className: (0, import_design_system4.cn)(
752
+ "grid grid-cols-2 gap-x-4 gap-y-2.5 type-secondary sm:grid-cols-4",
753
+ className
754
+ ),
755
+ children: [
756
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
757
+ Stamp,
758
+ {
759
+ label: "Created",
760
+ at: createdAt,
761
+ actorId: component ? null : createdBy,
762
+ showActor: !component,
763
+ formatTimestamp,
764
+ resolveActor
765
+ }
766
+ ),
767
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
768
+ Stamp,
769
+ {
770
+ label: "Last updated",
771
+ at: updatedAt,
772
+ actorId: updatedBy,
773
+ formatTimestamp,
774
+ resolveActor
775
+ }
776
+ ),
777
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
778
+ Stamp,
779
+ {
780
+ label: "Moved to trash",
781
+ at: deletedAt,
782
+ formatTimestamp,
783
+ resolveActor,
784
+ tone: "warning"
785
+ }
786
+ ),
787
+ typeof version === "number" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "min-w-0", children: [
788
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("dt", { className: "type-meta font-semibold uppercase tracking-wide text-muted-foreground", children: "Row version" }),
789
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("dd", { className: "mt-0.5 type-secondary tabular-nums text-foreground", children: version })
790
+ ] }) : null
791
+ ]
792
+ }
793
+ );
794
+ }
795
+ //# sourceMappingURL=entity-ref.cjs.map