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