@ai-matrx/records-ui 0.116.85 → 0.116.87

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.
@@ -860,6 +860,192 @@ function PickOrAdd({
860
860
  ] });
861
861
  }
862
862
 
863
+ // src/PersonPicker.tsx
864
+ import { useCallback, useEffect as useEffect3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
865
+ import { rankTypedMatches } from "@ai-matrx/records";
866
+ import { useOptionalRecordsClient } from "@ai-matrx/records/react";
867
+ import { cn as cn5 } from "@ai-matrx/design-system";
868
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
869
+ function personFromRow(row) {
870
+ const data = row.document ?? {};
871
+ const userId = data["user_id"];
872
+ return {
873
+ id: row.id,
874
+ userId: typeof userId === "string" && userId !== "" ? userId : null,
875
+ name: String(data["full_name"] ?? data["name"] ?? data["email"] ?? "").trim()
876
+ };
877
+ }
878
+ function memberName(member) {
879
+ const display = (member.name ?? "").trim();
880
+ if (display !== "") return display;
881
+ const email = (member.email ?? "").trim();
882
+ if (email !== "") return email;
883
+ return "A member with no name set";
884
+ }
885
+ async function personRecordForMember(client, personTableId, people, member) {
886
+ const held = people.find((p) => p.userId === member.userId);
887
+ if (held) return { ok: true, data: held.id };
888
+ const written = await client.recordWrite({
889
+ table_id: personTableId,
890
+ data: {
891
+ user_id: member.userId,
892
+ full_name: memberName(member),
893
+ ...member.email ? { email: member.email } : {}
894
+ }
895
+ });
896
+ return written;
897
+ }
898
+ function PersonPicker({ field, value, onChange, disabled, id, className, autoOpen, onClose, onCancel, initialSearch }) {
899
+ const client = useOptionalRecordsClient();
900
+ const host = useRecordsUi();
901
+ const [members, setMembers] = useState3(null);
902
+ const [people, setPeople] = useState3([]);
903
+ const [error, setError] = useState3(null);
904
+ const [search, setSearch] = useState3(initialSearch ?? "");
905
+ const [open, setOpenState] = useState3(autoOpen === true);
906
+ const onCloseRef = useRef2(onClose);
907
+ onCloseRef.current = onClose;
908
+ const setOpen = useCallback((next) => {
909
+ setOpenState(next);
910
+ if (!next) onCloseRef.current?.();
911
+ }, []);
912
+ const [busy, setBusy] = useState3(false);
913
+ const membersPort = host.members;
914
+ const personTable = field.relation_target;
915
+ const picked = useMemo2(
916
+ () => Array.isArray(value) ? value.map(String) : value === null || value === void 0 ? [] : [String(value)],
917
+ [value]
918
+ );
919
+ const load = useCallback(async () => {
920
+ if (!membersPort || !client) return;
921
+ const [roster, records] = await Promise.all([
922
+ membersPort(),
923
+ personTable ? client.list({ table_id: personTable, limit: 500 }) : Promise.resolve(null)
924
+ ]);
925
+ setMembers(roster);
926
+ if (records && !records.ok) {
927
+ setError(records.error);
928
+ return;
929
+ }
930
+ setPeople(records ? records.data.rows.map(personFromRow).filter((p) => p.userId !== null) : []);
931
+ }, [membersPort, client, personTable]);
932
+ useEffect3(() => {
933
+ if (!open) return;
934
+ void load();
935
+ }, [open, load]);
936
+ useEffect3(() => {
937
+ if (picked.length === 0 || !personTable || people.length > 0 || !client) return;
938
+ let cancelled = false;
939
+ void client.list({ table_id: personTable, limit: 500 }).then((result) => {
940
+ if (cancelled || !result.ok) return;
941
+ setPeople(result.data.rows.map(personFromRow).filter((p) => p.userId !== null));
942
+ });
943
+ return () => {
944
+ cancelled = true;
945
+ };
946
+ }, [client, personTable, picked.length, people.length]);
947
+ const listed = rankTypedMatches(members ?? [], search, memberName);
948
+ if (!membersPort || !client) {
949
+ return /* @__PURE__ */ jsx6("p", { className: cn5("text-xs text-muted-foreground", className), children: NO_MEMBERS_REASON });
950
+ }
951
+ if (!personTable) {
952
+ return /* @__PURE__ */ jsxs5("p", { className: cn5("text-xs text-muted-foreground", className), children: [
953
+ fieldName(field),
954
+ " is a person field, but it does not say which Table the people are records of yet, so there is nothing to pick from. A table admin sets its target in the field editor."
955
+ ] });
956
+ }
957
+ const displayNameOf = (userId, recordName2) => {
958
+ const member = userId ? (members ?? []).find((m) => m.userId === userId) : void 0;
959
+ const own = (member?.name ?? "").trim();
960
+ if (own !== "") return own;
961
+ const kept2 = (recordName2 ?? people.find((p) => p.userId === userId)?.name ?? "").trim();
962
+ const email = (member?.email ?? "").trim();
963
+ return kept2 !== "" && kept2 !== email ? kept2 : null;
964
+ };
965
+ const nameOfRecord = (recordId) => {
966
+ const person = people.find((p) => p.id === recordId);
967
+ if (!person) return "Loading\u2026";
968
+ const member = (members ?? []).find((m) => m.userId === person.userId);
969
+ return displayNameOf(person.userId, person.name) ?? (member ? memberName(member) : person.name || "A member with no name set");
970
+ };
971
+ const pick = async (member) => {
972
+ setBusy(true);
973
+ setError(null);
974
+ const resolved = await personRecordForMember(client, personTable, people, member);
975
+ setBusy(false);
976
+ if (!resolved.ok) {
977
+ setError(resolved.error);
978
+ return;
979
+ }
980
+ if (!people.some((p) => p.id === resolved.data)) {
981
+ setPeople((held) => [...held, { id: resolved.data, userId: member.userId, name: memberName(member) }]);
982
+ }
983
+ if (!field.multi) {
984
+ onChange(picked[0] === resolved.data ? null : resolved.data);
985
+ setOpen(false);
986
+ return;
987
+ }
988
+ const next = new Set(picked);
989
+ if (next.has(resolved.data)) next.delete(resolved.data);
990
+ else next.add(resolved.data);
991
+ onChange(next.size === 0 ? null : [...next]);
992
+ };
993
+ const drop = (recordId) => {
994
+ const next = picked.filter((id2) => id2 !== recordId);
995
+ onChange(next.length === 0 ? null : field.multi ? next : next[0] ?? null);
996
+ };
997
+ const visible = listed;
998
+ const pickedUserIds = new Set(
999
+ picked.map((recordId) => people.find((p) => p.id === recordId)?.userId).filter(Boolean)
1000
+ );
1001
+ const anchored = autoOpen === true;
1002
+ const cellChips = picked.map((recordId) => /* @__PURE__ */ jsx6(PersonChip, { name: nameOfRecord(recordId), ...disabled || anchored ? {} : { onRemove: () => drop(recordId) } }, recordId));
1003
+ return /* @__PURE__ */ jsxs5("div", { className: cn5("flex flex-wrap items-center gap-1", className), children: [
1004
+ anchored && !disabled ? null : cellChips,
1005
+ disabled ? null : (
1006
+ // THE ONE "PICK OR ADD" BUILDER (lane CELL-EDITORS, 2026-10-06): the person list used to carry
1007
+ // its own copy of the list's layout and keys; it now draws the same rows, ticks, highlight and
1008
+ // head chips as every other picker, and in a grid cell hangs from the cell.
1009
+ /* @__PURE__ */ jsx6(
1010
+ PickOrAdd,
1011
+ {
1012
+ ...anchored && onCancel ? { onEscape: onCancel } : {},
1013
+ anchored,
1014
+ multi: field.multi,
1015
+ triggerId: id,
1016
+ triggerLabel: `Pick a person for ${fieldName(field)}`,
1017
+ triggerText: picked.length === 0 ? "Pick a person" : "Change",
1018
+ open,
1019
+ onOpenChange: setOpen,
1020
+ search,
1021
+ onSearch: setSearch,
1022
+ chips: picked.map((recordId) => ({ id: recordId, label: nameOfRecord(recordId), person: true, onRemove: () => drop(recordId) })),
1023
+ items: visible.map((member) => ({
1024
+ id: member.userId,
1025
+ label: displayNameOf(member.userId) ?? memberName(member),
1026
+ // A name and an email with nothing between them read as one run-on string (verdict,
1027
+ // 19 September). They are two facts, so they are drawn as two.
1028
+ detail: displayNameOf(member.userId) !== null && member.email ? member.email : null,
1029
+ picked: pickedUserIds.has(member.userId),
1030
+ person: true,
1031
+ disabled: busy
1032
+ })),
1033
+ onPick: (userId) => {
1034
+ const member = visible.find((m) => m.userId === userId);
1035
+ if (member && !busy) void pick(member);
1036
+ },
1037
+ notice: /* @__PURE__ */ jsxs5(Fragment2, { children: [
1038
+ error ? /* @__PURE__ */ jsx6(RefusalLine, { error, className: "p-2" }) : null,
1039
+ members === null ? /* @__PURE__ */ jsx6("p", { className: "p-2 text-xs text-muted-foreground", children: "Reading the members\u2026" }) : null
1040
+ ] }),
1041
+ empty: members !== null ? /* @__PURE__ */ jsx6("p", { className: "p-2 text-xs text-muted-foreground", children: members.length === 0 ? "This organization has no other members yet, so there is nobody to assign." : "Nobody in this organization matches." }) : null,
1042
+ children: anchored ? cellChips : null
1043
+ }
1044
+ )
1045
+ )
1046
+ ] });
1047
+ }
1048
+
863
1049
  // src/recordVersions.ts
864
1050
  var recordVersions_exports = {};
865
1051
  __reExport(recordVersions_exports, versions_star);
@@ -931,15 +1117,15 @@ function madeOn(stamp) {
931
1117
  }
932
1118
 
933
1119
  // src/tablePicking.tsx
934
- import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo2, useState as useState4 } from "react";
1120
+ import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo3, useState as useState5 } from "react";
935
1121
  import { withTablePlacement } from "@ai-matrx/records";
936
1122
  import { useRecordsClient, useTables } from "@ai-matrx/records/react";
937
- import { Checkbox, cn as cn5 } from "@ai-matrx/design-system";
1123
+ import { Checkbox, cn as cn6 } from "@ai-matrx/design-system";
938
1124
 
939
1125
  // src/readRefusals.tsx
940
- import { useCallback, useEffect as useEffect3, useId, useState as useState3, useSyncExternalStore } from "react";
1126
+ import { useCallback as useCallback2, useEffect as useEffect4, useId, useState as useState4, useSyncExternalStore } from "react";
941
1127
  import { Button as Button2, ErrorNotice } from "@ai-matrx/design-system";
942
- import { jsx as jsx6 } from "react/jsx-runtime";
1128
+ import { jsx as jsx7 } from "react/jsx-runtime";
943
1129
  var kept = [];
944
1130
  var listeners = /* @__PURE__ */ new Set();
945
1131
  var docks = [];
@@ -956,18 +1142,18 @@ async function askWithOneRetry(ask, pauseMs = READ_RETRY_PAUSE_MS) {
956
1142
  return ask();
957
1143
  }
958
1144
  function useReadAgain() {
959
- const [n, setN] = useState3(0);
960
- return [n, useCallback(() => setN((v) => v + 1), [])];
1145
+ const [n, setN] = useState4(0);
1146
+ return [n, useCallback2(() => setN((v) => v + 1), [])];
961
1147
  }
962
1148
  function useReadRefusal(key) {
963
- useEffect3(
1149
+ useEffect4(
964
1150
  () => () => {
965
1151
  kept = kept.filter((k) => k.key !== key);
966
1152
  emit();
967
1153
  },
968
1154
  [key]
969
1155
  );
970
- const take = useCallback(
1156
+ const take = useCallback2(
971
1157
  (answer, retry) => {
972
1158
  if (answer.ok) {
973
1159
  if (kept.some((k) => k.key === key)) {
@@ -987,7 +1173,7 @@ function useReadRefusal(key) {
987
1173
  }
988
1174
  function ReadRefusalDock() {
989
1175
  const id = useId();
990
- useEffect3(() => {
1176
+ useEffect4(() => {
991
1177
  docks.push(id);
992
1178
  emit();
993
1179
  return () => {
@@ -1000,32 +1186,32 @@ function ReadRefusalDock() {
1000
1186
  if (now.length === 0 || docks[0] !== id) return null;
1001
1187
  const retryAll = () => now.forEach((k) => k.retry());
1002
1188
  const first = now[0];
1003
- return /* @__PURE__ */ jsx6("div", { "data-read-refusal-dock": "", className: "pointer-events-none fixed inset-x-0 bottom-3 z-50 flex justify-center px-3", children: /* @__PURE__ */ jsx6("div", { className: "pointer-events-auto w-full max-w-md rounded-lg border bg-background shadow-sm", children: /* @__PURE__ */ jsx6(
1189
+ return /* @__PURE__ */ jsx7("div", { "data-read-refusal-dock": "", className: "pointer-events-none fixed inset-x-0 bottom-3 z-50 flex justify-center px-3", children: /* @__PURE__ */ jsx7("div", { className: "pointer-events-auto w-full max-w-md rounded-lg border bg-background shadow-sm", children: /* @__PURE__ */ jsx7(
1004
1190
  ErrorNotice,
1005
1191
  {
1006
1192
  size: "compact",
1007
1193
  error: refusalTimedOut(first.error) ? { code: "timed_out" } : first.error,
1008
1194
  message: refusalTimedOut(first.error) ? null : refusalSaid(first.error),
1009
1195
  operation: `read ${first.key}`,
1010
- actions: /* @__PURE__ */ jsx6(Button2, { type: "button", size: "sm", variant: "outline", "data-error-retry": "", onClick: retryAll, children: "Try again" })
1196
+ actions: /* @__PURE__ */ jsx7(Button2, { type: "button", size: "sm", variant: "outline", "data-error-retry": "", onClick: retryAll, children: "Try again" })
1011
1197
  }
1012
1198
  ) }) });
1013
1199
  }
1014
1200
 
1015
1201
  // src/tablePicking.tsx
1016
- import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
1202
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1017
1203
  function usePickerTables() {
1018
1204
  const client = useRecordsClient();
1019
1205
  const tables = useTables();
1020
- const [facts, setFacts] = useState4("reading");
1021
- const [nonce, setNonce] = useState4(0);
1206
+ const [facts, setFacts] = useState5("reading");
1207
+ const [nonce, setNonce] = useState5(0);
1022
1208
  const reloadTables = tables.reload;
1023
- const reload = useCallback2(() => {
1209
+ const reload = useCallback3(() => {
1024
1210
  reloadTables();
1025
1211
  setNonce((n) => n + 1);
1026
1212
  }, [reloadTables]);
1027
1213
  const reads = useReadRefusal("table_facts");
1028
- useEffect4(() => {
1214
+ useEffect5(() => {
1029
1215
  let alive = true;
1030
1216
  void askWithOneRetry(() => client.tableFacts()).then((answered) => {
1031
1217
  if (!alive) return;
@@ -1035,7 +1221,7 @@ function usePickerTables() {
1035
1221
  alive = false;
1036
1222
  };
1037
1223
  }, [client, nonce]);
1038
- const data = useMemo2(
1224
+ const data = useMemo3(
1039
1225
  () => withTablePlacement(tables.data ?? [], facts === "reading" ? null : facts),
1040
1226
  [tables.data, facts]
1041
1227
  );
@@ -1048,8 +1234,8 @@ function ShowListsToggle({
1048
1234
  className
1049
1235
  }) {
1050
1236
  if (count === 0) return null;
1051
- return /* @__PURE__ */ jsxs5("label", { className: cn5("flex items-center gap-1.5 text-[11px] text-muted-foreground", className), children: [
1052
- /* @__PURE__ */ jsx7(Checkbox, { checked: on, onCheckedChange: (next) => onChange(next === true), "aria-label": "Show lists" }),
1237
+ return /* @__PURE__ */ jsxs6("label", { className: cn6("flex items-center gap-1.5 text-[11px] text-muted-foreground", className), children: [
1238
+ /* @__PURE__ */ jsx8(Checkbox, { checked: on, onCheckedChange: (next) => onChange(next === true), "aria-label": "Show lists" }),
1053
1239
  "Show lists (",
1054
1240
  count,
1055
1241
  ")"
@@ -1218,9 +1404,9 @@ var ABSENCE_WORD_LABEL = {
1218
1404
  };
1219
1405
 
1220
1406
  // src/FilePicker.tsx
1221
- import { useCallback as useCallback3, useId as useId2, useRef as useRef2, useState as useState5 } from "react";
1222
- import { Button as Button3, cn as cn6 } from "@ai-matrx/design-system";
1223
- import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
1407
+ import { useCallback as useCallback4, useId as useId2, useRef as useRef3, useState as useState6 } from "react";
1408
+ import { Button as Button3, cn as cn7 } from "@ai-matrx/design-system";
1409
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1224
1410
  function FilePicker({
1225
1411
  label,
1226
1412
  accept,
@@ -1233,16 +1419,16 @@ function FilePicker({
1233
1419
  className
1234
1420
  }) {
1235
1421
  const inputId = useId2();
1236
- const input = useRef2(null);
1237
- const [over, setOver] = useState5(false);
1238
- const take = useCallback3(
1422
+ const input = useRef3(null);
1423
+ const [over, setOver] = useState6(false);
1424
+ const take = useCallback4(
1239
1425
  (file) => {
1240
1426
  if (!file || disabled) return;
1241
1427
  onFile(file);
1242
1428
  },
1243
1429
  [disabled, onFile]
1244
1430
  );
1245
- const onDrop = useCallback3(
1431
+ const onDrop = useCallback4(
1246
1432
  (e) => {
1247
1433
  e.preventDefault();
1248
1434
  setOver(false);
@@ -1250,11 +1436,11 @@ function FilePicker({
1250
1436
  },
1251
1437
  [take]
1252
1438
  );
1253
- return /* @__PURE__ */ jsxs6(
1439
+ return /* @__PURE__ */ jsxs7(
1254
1440
  "div",
1255
1441
  {
1256
1442
  "data-matrx-file-picker": true,
1257
- className: cn6("flex min-w-0 flex-col gap-1", className),
1443
+ className: cn7("flex min-w-0 flex-col gap-1", className),
1258
1444
  onDragOver: (e) => {
1259
1445
  if (disabled) return;
1260
1446
  e.preventDefault();
@@ -1263,16 +1449,16 @@ function FilePicker({
1263
1449
  onDragLeave: () => setOver(false),
1264
1450
  onDrop,
1265
1451
  children: [
1266
- /* @__PURE__ */ jsxs6(
1452
+ /* @__PURE__ */ jsxs7(
1267
1453
  "div",
1268
1454
  {
1269
- className: cn6(
1455
+ className: cn7(
1270
1456
  "flex min-w-0 flex-wrap items-center gap-2 rounded-md border border-dashed px-2 py-1.5",
1271
1457
  over ? "border-primary bg-primary/5" : "border-border",
1272
1458
  disabled && "opacity-60"
1273
1459
  ),
1274
1460
  children: [
1275
- /* @__PURE__ */ jsx8(
1461
+ /* @__PURE__ */ jsx9(
1276
1462
  "input",
1277
1463
  {
1278
1464
  ref: input,
@@ -1289,7 +1475,7 @@ function FilePicker({
1289
1475
  }
1290
1476
  }
1291
1477
  ),
1292
- /* @__PURE__ */ jsx8(
1478
+ /* @__PURE__ */ jsx9(
1293
1479
  Button3,
1294
1480
  {
1295
1481
  type: "button",
@@ -1300,20 +1486,20 @@ function FilePicker({
1300
1486
  children: chosenName ? "Choose a different file" : label
1301
1487
  }
1302
1488
  ),
1303
- chosenName ? /* @__PURE__ */ jsx8("span", { className: "min-w-0 flex-1 truncate text-xs", title: chosenName, children: chosenName }) : /* @__PURE__ */ jsx8("span", { className: "text-xs text-muted-foreground", children: "or drop it here" }),
1304
- chosenName && onClear ? /* @__PURE__ */ jsx8(Button3, { type: "button", size: "sm", variant: "ghost", disabled, onClick: onClear, children: "Cancel" }) : null
1489
+ chosenName ? /* @__PURE__ */ jsx9("span", { className: "min-w-0 flex-1 truncate text-xs", title: chosenName, children: chosenName }) : /* @__PURE__ */ jsx9("span", { className: "text-xs text-muted-foreground", children: "or drop it here" }),
1490
+ chosenName && onClear ? /* @__PURE__ */ jsx9(Button3, { type: "button", size: "sm", variant: "ghost", disabled, onClick: onClear, children: "Cancel" }) : null
1305
1491
  ]
1306
1492
  }
1307
1493
  ),
1308
- hint && !chosenName ? /* @__PURE__ */ jsx8("p", { className: "text-xs text-muted-foreground", children: hint }) : null
1494
+ hint && !chosenName ? /* @__PURE__ */ jsx9("p", { className: "text-xs text-muted-foreground", children: hint }) : null
1309
1495
  ]
1310
1496
  }
1311
1497
  );
1312
1498
  }
1313
1499
 
1314
1500
  // src/choiceNudge.ts
1315
- import { useEffect as useEffect5, useState as useState6 } from "react";
1316
- import { useOptionalRecordsClient } from "@ai-matrx/records/react";
1501
+ import { useEffect as useEffect6, useState as useState7 } from "react";
1502
+ import { useOptionalRecordsClient as useOptionalRecordsClient2 } from "@ai-matrx/records/react";
1317
1503
  var asked = /* @__PURE__ */ new WeakMap();
1318
1504
  function choiceNudgeOf(client) {
1319
1505
  let answer = asked.get(client);
@@ -1327,9 +1513,9 @@ function choiceNudgeOf(client) {
1327
1513
  return answer;
1328
1514
  }
1329
1515
  function useChoiceNudge(enabled = true) {
1330
- const client = useOptionalRecordsClient();
1331
- const [nudge, setNudge] = useState6(null);
1332
- useEffect5(() => {
1516
+ const client = useOptionalRecordsClient2();
1517
+ const [nudge, setNudge] = useState7(null);
1518
+ useEffect6(() => {
1333
1519
  if (!enabled || !client) return;
1334
1520
  let live = true;
1335
1521
  void choiceNudgeOf(client).then((answer) => {
@@ -1343,10 +1529,74 @@ function useChoiceNudge(enabled = true) {
1343
1529
  return nudge;
1344
1530
  }
1345
1531
 
1532
+ // src/userIds.ts
1533
+ var PERSON_NOT_IN_ORGANIZATION = "A person no longer in this organization";
1534
+
1535
+ // src/memberNames.ts
1536
+ import { useEffect as useEffect7, useMemo as useMemo4, useState as useState8 } from "react";
1537
+ import { useOptionalRecordsClient as useOptionalRecordsClient3 } from "@ai-matrx/records/react";
1538
+ import { isUuidShape as isUuidShape2 } from "@ai-matrx/kit/uuid";
1539
+ function memberWords(member) {
1540
+ const name = member?.name?.trim();
1541
+ if (name) return name;
1542
+ const email = member?.email?.trim();
1543
+ return email ? email : null;
1544
+ }
1545
+ function useMemberRoster() {
1546
+ const host = useRecordsUi();
1547
+ const members = host.members;
1548
+ const [roster, setRoster] = useState8(null);
1549
+ useEffect7(() => {
1550
+ if (!members) {
1551
+ setRoster(/* @__PURE__ */ new Map());
1552
+ return;
1553
+ }
1554
+ let cancelled = false;
1555
+ void members().then((list) => !cancelled && setRoster(new Map(list.map((m) => [m.userId.toLowerCase(), m])))).catch(() => !cancelled && setRoster(/* @__PURE__ */ new Map()));
1556
+ return () => {
1557
+ cancelled = true;
1558
+ };
1559
+ }, [members]);
1560
+ return roster;
1561
+ }
1562
+ async function resolveKeptPerson(client, id, roster) {
1563
+ if (client) {
1564
+ try {
1565
+ const read = await client.recordRead({ record_id: id });
1566
+ if (read.ok) {
1567
+ const person = personFromRow({ id, document: read.data.document });
1568
+ const member = person.userId ? roster.get(person.userId.toLowerCase()) : void 0;
1569
+ const named = memberWords(member) ?? (person.name !== "" ? person.name : null);
1570
+ const doc = read.data.document ?? {};
1571
+ const email = (typeof doc["email"] === "string" && doc["email"].trim() !== "" ? doc["email"].trim() : null) ?? member?.email?.trim() ?? null;
1572
+ if (person.userId || named) return { id, recordId: id, name: named ?? PERSON_NOT_IN_ORGANIZATION, userId: person.userId, email };
1573
+ }
1574
+ } catch {
1575
+ }
1576
+ }
1577
+ const direct = roster.get(id.toLowerCase());
1578
+ return { id, recordId: null, name: memberWords(direct) ?? PERSON_NOT_IN_ORGANIZATION, userId: direct ? id : null, email: direct?.email?.trim() || null };
1579
+ }
1580
+ function useKeptPeople(value, roster) {
1581
+ const client = useOptionalRecordsClient3();
1582
+ const ids = useMemo4(() => (Array.isArray(value) ? value : [value]).filter(isUuidShape2), [value]);
1583
+ const key = ids.join(",");
1584
+ const [people, setPeople] = useState8(null);
1585
+ useEffect7(() => {
1586
+ if (!roster) return;
1587
+ let cancelled = false;
1588
+ void Promise.all(ids.map((id) => resolveKeptPerson(client, id, roster))).then((named) => !cancelled && setPeople(named));
1589
+ return () => {
1590
+ cancelled = true;
1591
+ };
1592
+ }, [key, roster, client]);
1593
+ return people;
1594
+ }
1595
+
1346
1596
  // src/PickOne.tsx
1347
- import { useState as useState7 } from "react";
1348
- import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, cn as cn7 } from "@ai-matrx/design-system";
1349
- import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1597
+ import { useState as useState9 } from "react";
1598
+ import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, cn as cn8 } from "@ai-matrx/design-system";
1599
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1350
1600
  var PICK_ONE_SEARCH_AFTER = 7;
1351
1601
  var EMPTY = "__records_pick_one_empty__";
1352
1602
  var inner = (v) => v === "" ? EMPTY : v;
@@ -1362,13 +1612,13 @@ function PickOne({
1362
1612
  disabled,
1363
1613
  attrs
1364
1614
  }) {
1365
- const [open, setOpen] = useState7(false);
1366
- const [search, setSearch] = useState7("");
1615
+ const [open, setOpen] = useState9(false);
1616
+ const [search, setSearch] = useState9("");
1367
1617
  const current = options.find((o) => o.value === value);
1368
1618
  if (options.length > PICK_ONE_SEARCH_AFTER) {
1369
1619
  const q = search.trim().toLowerCase();
1370
1620
  const shown = q === "" ? options : options.filter((o) => o.label.toLowerCase().includes(q));
1371
- return /* @__PURE__ */ jsx9("span", { className: cn7("inline-flex min-w-0", className), "data-records-pick-one": "search", "data-pick-value": value, ...attrs ?? {}, children: /* @__PURE__ */ jsx9(
1621
+ return /* @__PURE__ */ jsx10("span", { className: cn8("inline-flex min-w-0", className), "data-records-pick-one": "search", "data-pick-value": value, ...attrs ?? {}, children: /* @__PURE__ */ jsx10(
1372
1622
  PickOrAdd,
1373
1623
  {
1374
1624
  triggerSize: "compact",
@@ -1394,29 +1644,29 @@ function PickOne({
1394
1644
  setOpen(false);
1395
1645
  setSearch("");
1396
1646
  },
1397
- empty: /* @__PURE__ */ jsx9("p", { className: "p-2 text-xs text-muted-foreground", children: "No match" })
1647
+ empty: /* @__PURE__ */ jsx10("p", { className: "p-2 text-xs text-muted-foreground", children: "No match" })
1398
1648
  }
1399
1649
  ) });
1400
1650
  }
1401
- return /* @__PURE__ */ jsxs7(Select, { value: current ? inner(current.value) : "", onValueChange: (v) => onChange(outer(v)), disabled: disabled ?? false, children: [
1402
- /* @__PURE__ */ jsx9(
1651
+ return /* @__PURE__ */ jsxs8(Select, { value: current ? inner(current.value) : "", onValueChange: (v) => onChange(outer(v)), disabled: disabled ?? false, children: [
1652
+ /* @__PURE__ */ jsx10(
1403
1653
  SelectTrigger,
1404
1654
  {
1405
1655
  id,
1406
1656
  size: "sm",
1407
1657
  "aria-label": label,
1408
- className: cn7("h-7 w-auto min-w-[7rem] text-xs", className),
1658
+ className: cn8("h-7 w-auto min-w-[7rem] text-xs", className),
1409
1659
  "data-records-pick-one": "list",
1410
1660
  "data-pick-value": value,
1411
1661
  ...attrs ?? {},
1412
- children: /* @__PURE__ */ jsx9(SelectValue, { placeholder })
1662
+ children: /* @__PURE__ */ jsx10(SelectValue, { placeholder })
1413
1663
  }
1414
1664
  ),
1415
- /* @__PURE__ */ jsx9(SelectContent, { children: groupsOf(options).map(
1416
- ([group, items]) => group ? /* @__PURE__ */ jsxs7(SelectGroup, { children: [
1417
- /* @__PURE__ */ jsx9(SelectLabel, { children: group }),
1418
- items.map((o) => /* @__PURE__ */ jsx9(SelectItem, { value: inner(o.value), "data-pick-value": o.value, "data-pick-group": group, children: o.label }, inner(o.value)))
1419
- ] }, group) : items.map((o) => /* @__PURE__ */ jsx9(SelectItem, { value: inner(o.value), "data-pick-value": o.value, children: o.label }, inner(o.value)))
1665
+ /* @__PURE__ */ jsx10(SelectContent, { children: groupsOf(options).map(
1666
+ ([group, items]) => group ? /* @__PURE__ */ jsxs8(SelectGroup, { children: [
1667
+ /* @__PURE__ */ jsx10(SelectLabel, { children: group }),
1668
+ items.map((o) => /* @__PURE__ */ jsx10(SelectItem, { value: inner(o.value), "data-pick-value": o.value, "data-pick-group": group, children: o.label }, inner(o.value)))
1669
+ ] }, group) : items.map((o) => /* @__PURE__ */ jsx10(SelectItem, { value: inner(o.value), "data-pick-value": o.value, children: o.label }, inner(o.value)))
1420
1670
  ) })
1421
1671
  ] });
1422
1672
  }
@@ -1476,6 +1726,13 @@ export {
1476
1726
  RefusalLine,
1477
1727
  PersonChip,
1478
1728
  PickOrAdd,
1729
+ memberName,
1730
+ personRecordForMember,
1731
+ PersonPicker,
1732
+ PERSON_NOT_IN_ORGANIZATION,
1733
+ useMemberRoster,
1734
+ resolveKeptPerson,
1735
+ useKeptPeople,
1479
1736
  recordVersions_exports,
1480
1737
  writeOnTheWinningVersion_exports,
1481
1738
  PickOne,
@@ -1527,4 +1784,4 @@ export {
1527
1784
  choiceNudgeOf,
1528
1785
  useChoiceNudge
1529
1786
  };
1530
- //# sourceMappingURL=chunk-3I6HFES6.js.map
1787
+ //# sourceMappingURL=chunk-HYC2SPZZ.js.map