@ai-matrx/records-ui 0.115.84 → 0.115.86

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/dist/pickers.js CHANGED
@@ -14,7 +14,7 @@ var __copyProps = (to, from, except, desc) => {
14
14
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
15
 
16
16
  // src/TablePickers.tsx
17
- import { useEffect as useEffect22, useMemo as useMemo12, useState as useState31 } from "react";
17
+ import { useEffect as useEffect23, useMemo as useMemo13, useState as useState32 } from "react";
18
18
  import { RecordsProvider as RecordsProvider2, useFields as useFields3, useRecords as useRecords3, useTable as useTable2 } from "@ai-matrx/records/react";
19
19
  import { Button as Button18, CreatablePicker } from "@ai-matrx/design-system";
20
20
 
@@ -676,19 +676,19 @@ function quiet(may, say) {
676
676
  }
677
677
  function useTableRights(table) {
678
678
  const host = useRecordsUi();
679
- const asked2 = useTableRightsAsked(table, host);
680
- return useMemo(() => quiet(asked2, host.sayLevelNeeded), [asked2, host.sayLevelNeeded]);
679
+ const asked3 = useTableRightsAsked(table, host);
680
+ return useMemo(() => quiet(asked3, host.sayLevelNeeded), [asked3, host.sayLevelNeeded]);
681
681
  }
682
682
  function useTableRightsAsked(table, host) {
683
683
  const bound = Boolean(host.rights);
684
- const asked2 = useMyLevel(bound || !table ? null : table.id);
684
+ const asked3 = useMyLevel(bound || !table ? null : table.id);
685
685
  return useMemo(() => {
686
686
  if (!table) return NO_RIGHTS;
687
687
  if (host.rights) return host.rights(table);
688
- if (asked2.loading) return tableRights(NOT_ANSWERED_YET);
689
- const level = asked2.error ? null : asked2.data;
688
+ if (asked3.loading) return tableRights(NOT_ANSWERED_YET);
689
+ const level = asked3.error ? null : asked3.data;
690
690
  return tableRights(whatYouMayDoWithTable(table, level, true));
691
- }, [host, table, bound, asked2.loading, asked2.error, asked2.data]);
691
+ }, [host, table, bound, asked3.loading, asked3.error, asked3.data]);
692
692
  }
693
693
 
694
694
  // src/ArchivedOrganizationNotice.tsx
@@ -872,9 +872,9 @@ function AddChoicesInline({ field, onAdded, disabled = false }) {
872
872
  }
873
873
 
874
874
  // src/editors.tsx
875
- import { useCallback as useCallback7, useEffect as useEffect21, useLayoutEffect as useLayoutEffect2, useRef as useRef16, useState as useState30 } from "react";
875
+ import { useCallback as useCallback7, useEffect as useEffect22, useLayoutEffect as useLayoutEffect2, useRef as useRef16, useState as useState31 } from "react";
876
876
  import { isButtonField as isButtonField3, allowsOtherValues, choiceValuesOf, coerceTypedAnswer, newerKindOf as newerKindOf5, decideTypedChoice, isTheChosen, optionKey as optionKey4, rankTypedMatches as rankTypedMatches4, readTypedTime as readTypedTime2, typedDateText as typedDateText2, typedTimeText as typedTimeText2 } from "@ai-matrx/records";
877
- import { useOptionalRecordsClient as useOptionalRecordsClient11 } from "@ai-matrx/records/react";
877
+ import { useOptionalRecordsClient as useOptionalRecordsClient12 } from "@ai-matrx/records/react";
878
878
  import {
879
879
  BasicInput as BasicInput11,
880
880
  BasicTextarea as BasicTextarea4,
@@ -2045,11 +2045,11 @@ function RelationPicker({ field, value, onChange, disabled, id, className, allow
2045
2045
  }
2046
2046
 
2047
2047
  // src/buttonCell.tsx
2048
- import { useState as useState25 } from "react";
2048
+ import { useState as useState26 } from "react";
2049
2049
  import { Button as Button16, Dialog as Dialog2, DialogContent as DialogContent2, DialogDescription, DialogHeader as DialogHeader2, DialogTitle as DialogTitle2, Popover as Popover4, PopoverContent as PopoverContent4, PopoverTrigger as PopoverTrigger4, cn as cn23 } from "@ai-matrx/design-system";
2050
2050
  import { CHOICE_CHIP_CLASS as CHOICE_CHIP_CLASS2, NEUTRAL_CHIP_CLASS as NEUTRAL_CHIP_CLASS2, isStyleColor as isStyleColor2 } from "@ai-matrx/design-system/data-table";
2051
2051
  import { buttonNeeds as buttonNeeds2, buttonOf as buttonOf2 } from "@ai-matrx/records";
2052
- import { useOptionalRecordsClient as useOptionalRecordsClient9 } from "@ai-matrx/records/react";
2052
+ import { useOptionalRecordsClient as useOptionalRecordsClient10 } from "@ai-matrx/records/react";
2053
2053
 
2054
2054
  // src/columnName.ts
2055
2055
  var said = (name) => name.trim().replace(/\s+/g, " ");
@@ -2087,7 +2087,7 @@ function columnNameProblemLine(name, noun = "column") {
2087
2087
  }
2088
2088
 
2089
2089
  // src/FieldEditor.tsx
2090
- import { useEffect as useEffect18, useMemo as useMemo11, useRef as useRef13, useState as useState24 } from "react";
2090
+ import { useEffect as useEffect19, useMemo as useMemo12, useRef as useRef13, useState as useState25 } from "react";
2091
2091
  import {
2092
2092
  tableShapeChanged as tableShapeChanged3,
2093
2093
  useEntityFieldMutation,
@@ -2635,8 +2635,8 @@ function FormulaTextEditor({
2635
2635
  const report = useRef5(onChecked);
2636
2636
  report.current = onChecked;
2637
2637
  useEffect7(() => {
2638
- const asked2 = text.trim();
2639
- if (asked2 === "") {
2638
+ const asked3 = text.trim();
2639
+ if (asked3 === "") {
2640
2640
  setParsed(null);
2641
2641
  setError(null);
2642
2642
  report.current(null);
@@ -2645,7 +2645,7 @@ function FormulaTextEditor({
2645
2645
  report.current(null);
2646
2646
  let cancelled = false;
2647
2647
  const timer = setTimeout(() => {
2648
- void client.formulaPreview({ table_id: tableId, record_id: sampled, text: asked2 }).then((previewed) => previewed.ok ? previewed : client.formulaParse({ table_id: tableId, text: asked2 })).then((answered) => {
2648
+ void client.formulaPreview({ table_id: tableId, record_id: sampled, text: asked3 }).then((previewed) => previewed.ok ? previewed : client.formulaParse({ table_id: tableId, text: asked3 })).then((answered) => {
2649
2649
  if (cancelled) return;
2650
2650
  if (!answered.ok) {
2651
2651
  setError(answered.error);
@@ -2834,7 +2834,7 @@ function EntityReferenceKindPicker({ value, onChange, locked = false, className
2834
2834
  }
2835
2835
 
2836
2836
  // src/SourceArchivedNotice.tsx
2837
- import { useCallback as useCallback6, useEffect as useEffect13, useState as useState19 } from "react";
2837
+ import { useCallback as useCallback6, useEffect as useEffect14, useState as useState20 } from "react";
2838
2838
  import { Button as Button11 } from "@ai-matrx/design-system";
2839
2839
  import { tableShapeChanged, useRecordsClient as useRecordsClient6 } from "@ai-matrx/records/react";
2840
2840
 
@@ -2966,31 +2966,31 @@ var FILES = /* @__PURE__ */ new WeakMap();
2966
2966
  function signatureFilesOf(client, recordId) {
2967
2967
  let held = SOURCES.get(client);
2968
2968
  if (!held) SOURCES.set(client, held = /* @__PURE__ */ new Map());
2969
- let asked2 = held.get(recordId);
2970
- if (!asked2) {
2971
- asked2 = client.recordValuesVersioned({ record_id: recordId }).then((answered) => {
2969
+ let asked3 = held.get(recordId);
2970
+ if (!asked3) {
2971
+ asked3 = client.recordValuesVersioned({ record_id: recordId }).then((answered) => {
2972
2972
  if (!answered.ok) return {};
2973
2973
  return Object.fromEntries(answered.data.map((v) => [v.field_key, signatureFileOf(v.source)]));
2974
2974
  });
2975
- held.set(recordId, asked2);
2975
+ held.set(recordId, asked3);
2976
2976
  }
2977
- return asked2;
2977
+ return asked3;
2978
2978
  }
2979
2979
  function drawingOf(client, fileId) {
2980
2980
  let held = FILES.get(client);
2981
2981
  if (!held) FILES.set(client, held = /* @__PURE__ */ new Map());
2982
- let asked2 = held.get(fileId);
2983
- if (!asked2) {
2984
- asked2 = client.recordRead({ record_id: fileId }).then((answered) => {
2982
+ let asked3 = held.get(fileId);
2983
+ if (!asked3) {
2984
+ asked3 = client.recordRead({ record_id: fileId }).then((answered) => {
2985
2985
  if (!answered.ok) return { src: null, hostFileId: null };
2986
2986
  const doc = answered.data.document ?? {};
2987
2987
  const content = drawnSignatureOf(doc["content"]);
2988
2988
  const hostFileId = typeof doc["file_id"] === "string" && doc["file_id"] !== "" ? doc["file_id"] : null;
2989
2989
  return { src: content, hostFileId };
2990
2990
  });
2991
- held.set(fileId, asked2);
2991
+ held.set(fileId, asked3);
2992
2992
  }
2993
- return asked2;
2993
+ return asked3;
2994
2994
  }
2995
2995
  function DrawnImage({ src, inCell }) {
2996
2996
  return /* @__PURE__ */ jsx14(
@@ -3233,12 +3233,12 @@ function pointsAtRecords(field) {
3233
3233
  }
3234
3234
  function RecordLabelProvider({ children }) {
3235
3235
  const client = useRecordsClient5();
3236
- const [names, setNames] = useState12({});
3236
+ const [names2, setNames] = useState12({});
3237
3237
  const [archivedRefs, setArchivedRefs] = useState12({});
3238
3238
  const [iconsOf, setIconsOf] = useState12({});
3239
3239
  const [settled, setSettled] = useState12({});
3240
3240
  const [waitingLines, setWaitingLines] = useState12({});
3241
- const asked2 = useRef7(/* @__PURE__ */ new Set());
3241
+ const asked3 = useRef7(/* @__PURE__ */ new Set());
3242
3242
  const chased = useRef7(/* @__PURE__ */ new Set());
3243
3243
  const timers = useRef7(/* @__PURE__ */ new Map());
3244
3244
  const startWaitClock = useCallback3((field, target) => {
@@ -3276,8 +3276,8 @@ function RecordLabelProvider({ children }) {
3276
3276
  const want = useCallback3(
3277
3277
  (field) => {
3278
3278
  if (!pointsAtRecords(field)) return;
3279
- if (asked2.current.has(field.id)) return;
3280
- asked2.current.add(field.id);
3279
+ if (asked3.current.has(field.id)) return;
3280
+ asked3.current.add(field.id);
3281
3281
  startWaitClock(field, null);
3282
3282
  void (async () => {
3283
3283
  if (field.type === "list") {
@@ -3363,22 +3363,22 @@ function RecordLabelProvider({ children }) {
3363
3363
  const lookupWords = useCallback3(
3364
3364
  (field, id) => {
3365
3365
  if (field.type === "list" && !isId(id)) {
3366
- const named = names[choiceKeyName(field.id, id)];
3366
+ const named = names2[choiceKeyName(field.id, id)];
3367
3367
  if (named !== void 0) return named;
3368
3368
  const once = choiceKeyName(field.id, id);
3369
3369
  if (settled[field.id] && !rereadFor.current.has(once)) {
3370
3370
  rereadFor.current.add(once);
3371
- asked2.current.delete(field.id);
3371
+ asked3.current.delete(field.id);
3372
3372
  want(field);
3373
3373
  }
3374
3374
  return null;
3375
3375
  }
3376
- const known = names[id];
3376
+ const known = names2[id];
3377
3377
  if (known !== void 0) return known;
3378
3378
  if (settled[field.id]) chase(field, id);
3379
3379
  return null;
3380
3380
  },
3381
- [names, settled, chase, want]
3381
+ [names2, settled, chase, want]
3382
3382
  );
3383
3383
  const lookup = useMemo7(
3384
3384
  () => {
@@ -4531,13 +4531,13 @@ var BRACE = /\{([^{}]*)\}/g;
4531
4531
  function formulaTextNow(text, expr, fields) {
4532
4532
  if (!text || !fields || fields.length === 0) return text;
4533
4533
  const refs = fieldRefsOf(expr);
4534
- const names = [...text.matchAll(BRACE)].map((m) => m[1] ?? "");
4535
- if (refs.length === 0 || refs.length !== names.length) return text;
4534
+ const names2 = [...text.matchAll(BRACE)].map((m) => m[1] ?? "");
4535
+ if (refs.length === 0 || refs.length !== names2.length) return text;
4536
4536
  const byId = new Map(fields.map((f) => [String(f.id), f]));
4537
4537
  const becomes = /* @__PURE__ */ new Map();
4538
4538
  const replacement = [];
4539
- for (let i2 = 0; i2 < names.length; i2 += 1) {
4540
- const name = names[i2];
4539
+ for (let i2 = 0; i2 < names2.length; i2 += 1) {
4540
+ const name = names2[i2];
4541
4541
  const field = byId.get(refs[i2]);
4542
4542
  if (!field) return text;
4543
4543
  const now = fieldName(field);
@@ -4567,6 +4567,54 @@ function formulaSourceArchived(field, document2) {
4567
4567
  // src/values.tsx
4568
4568
  import { autonumberPrefixOf as autonumberPrefixOf2, autonumberWords as autonumberWords2, isButtonField as isButtonField2, newerKindWords, sourceArchivedOf as sourceArchivedOf2 } from "@ai-matrx/records";
4569
4569
 
4570
+ // src/userIds.ts
4571
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
4572
+ var PERSON_NOT_IN_ORGANIZATION = "A person no longer in this organization";
4573
+ function isUserId(value) {
4574
+ return typeof value === "string" && UUID.test(value);
4575
+ }
4576
+
4577
+ // src/personNames.ts
4578
+ import { useSyncExternalStore } from "react";
4579
+ var names = /* @__PURE__ */ new Map();
4580
+ var asked = /* @__PURE__ */ new Set();
4581
+ var listeners = /* @__PURE__ */ new Set();
4582
+ var version = 0;
4583
+ var resolver = null;
4584
+ var opener = null;
4585
+ async function openStoredPerson(id, open) {
4586
+ if (!open) return;
4587
+ const who = opener ? await opener(id) : null;
4588
+ open(who ?? { recordId: id });
4589
+ }
4590
+ function bump() {
4591
+ version += 1;
4592
+ for (const l of listeners) l();
4593
+ }
4594
+ function rememberPerson(id, name) {
4595
+ const key = id.toLowerCase();
4596
+ if (names.get(key) === name) return;
4597
+ names.set(key, name);
4598
+ bump();
4599
+ }
4600
+ function knownPerson(id) {
4601
+ const key = id.toLowerCase();
4602
+ const held = names.get(key);
4603
+ if (held !== void 0) return held;
4604
+ if (resolver && !asked.has(key)) {
4605
+ asked.add(key);
4606
+ const run = resolver;
4607
+ void run(id).then((name) => {
4608
+ if (name) rememberPerson(key, name);
4609
+ }).catch(() => asked.delete(key));
4610
+ }
4611
+ return null;
4612
+ }
4613
+
4614
+ // src/memberNames.ts
4615
+ import { useEffect as useEffect13, useMemo as useMemo10, useState as useState19 } from "react";
4616
+ import { useOptionalRecordsClient as useOptionalRecordsClient7 } from "@ai-matrx/records/react";
4617
+
4570
4618
  // src/PersonPicker.tsx
4571
4619
  import { useCallback as useCallback5, useEffect as useEffect12, useMemo as useMemo9, useRef as useRef11, useState as useState18 } from "react";
4572
4620
  import { rankTypedMatches as rankTypedMatches2 } from "@ai-matrx/records";
@@ -4753,6 +4801,49 @@ function PersonPicker({ field, value, onChange, disabled, id, className, autoOpe
4753
4801
  ] });
4754
4802
  }
4755
4803
 
4804
+ // src/memberNames.ts
4805
+ function memberWords(member) {
4806
+ const name = member?.name?.trim();
4807
+ if (name) return name;
4808
+ const email = member?.email?.trim();
4809
+ return email ? email : null;
4810
+ }
4811
+ function useMemberRoster() {
4812
+ const host = useRecordsUi();
4813
+ const members = host.members;
4814
+ const [roster, setRoster] = useState19(null);
4815
+ useEffect13(() => {
4816
+ if (!members) {
4817
+ setRoster(/* @__PURE__ */ new Map());
4818
+ return;
4819
+ }
4820
+ let cancelled = false;
4821
+ void members().then((list) => !cancelled && setRoster(new Map(list.map((m) => [m.userId.toLowerCase(), m])))).catch(() => !cancelled && setRoster(/* @__PURE__ */ new Map()));
4822
+ return () => {
4823
+ cancelled = true;
4824
+ };
4825
+ }, [members]);
4826
+ return roster;
4827
+ }
4828
+ async function resolveKeptPerson(client, id, roster) {
4829
+ if (client) {
4830
+ try {
4831
+ const read = await client.recordRead({ record_id: id });
4832
+ if (read.ok) {
4833
+ const person = personFromRow({ id, document: read.data.document });
4834
+ const member = person.userId ? roster.get(person.userId.toLowerCase()) : void 0;
4835
+ const named = memberWords(member) ?? (person.name !== "" ? person.name : null);
4836
+ const doc = read.data.document ?? {};
4837
+ const email = (typeof doc["email"] === "string" && doc["email"].trim() !== "" ? doc["email"].trim() : null) ?? member?.email?.trim() ?? null;
4838
+ if (person.userId || named) return { id, recordId: id, name: named ?? PERSON_NOT_IN_ORGANIZATION, userId: person.userId, email };
4839
+ }
4840
+ } catch {
4841
+ }
4842
+ }
4843
+ const direct = roster.get(id.toLowerCase());
4844
+ return { id, recordId: null, name: memberWords(direct) ?? PERSON_NOT_IN_ORGANIZATION, userId: direct ? id : null, email: direct?.email?.trim() || null };
4845
+ }
4846
+
4756
4847
  // src/values.tsx
4757
4848
  import { OutboundLink as OutboundLink5 } from "@ai-matrx/kit/outbound-react";
4758
4849
  import { Fragment as Fragment8, jsx as jsx24, jsxs as jsxs22 } from "react/jsx-runtime";
@@ -4842,7 +4933,7 @@ function renderValue(field, value, document2, labels, stillWaitingFor, look) {
4842
4933
  }
4843
4934
  if (kind === "member") {
4844
4935
  const ids = (Array.isArray(value) ? value : [value]).filter((v) => v !== null && v !== void 0 && v !== "");
4845
- return /* @__PURE__ */ jsx24("span", { className: "flex min-w-0 flex-wrap gap-1", "data-records-person-chips": "", children: ids.map((id, i) => /* @__PURE__ */ jsx24(PersonChip, { name: scalarText(field, id, labels, stillWaitingFor) }, `${String(id)}-${i}`)) });
4936
+ return /* @__PURE__ */ jsx24("span", { className: "flex min-w-0 flex-wrap gap-1", "data-records-person-chips": "", children: ids.map((id, i) => /* @__PURE__ */ jsx24(LivePersonChip, { id: String(id), name: scalarText(field, id, labels, stillWaitingFor) }, `${String(id)}-${i}`)) });
4846
4937
  }
4847
4938
  const kv = kind === "attachment" ? null : kindValueOf(value);
4848
4939
  if (kv) return /* @__PURE__ */ jsx24(KindValueCell, { kv, where: "cell", title: field.label });
@@ -4914,6 +5005,20 @@ function renderValue(field, value, document2, labels, stillWaitingFor, look) {
4914
5005
  }
4915
5006
  return /* @__PURE__ */ jsx24("span", { className: cn20("truncate", kind === "number" || kind === "currency" || kind === "percent" ? "tabular-nums" : ""), children: scalarText(field, value, labels, stillWaitingFor) });
4916
5007
  }
5008
+ function LivePersonChip({ id, name }) {
5009
+ const open = useRecordsUi().openPerson;
5010
+ return /* @__PURE__ */ jsx24(PersonChip, { name, ...open ? { onOpen: () => void openStoredPerson(id, open) } : {} });
5011
+ }
5012
+ var NEVER_AN_ID_KINDS = /* @__PURE__ */ new Set(["member", "person", "number", "currency", "percent", "date", "datetime", "checkbox", "boolean"]);
5013
+ function personWordsOf(kind, value) {
5014
+ const items = Array.isArray(value) ? value : [value];
5015
+ const ids = items.filter(isUserId);
5016
+ if (ids.length === 0) return null;
5017
+ const wordsColumn = !NEVER_AN_ID_KINDS.has(kind);
5018
+ const named = ids.map((id) => knownPerson(id));
5019
+ if (wordsColumn && named.some((n) => n === null)) return null;
5020
+ return named.map((n) => n ?? PERSON_NOT_IN_ORGANIZATION).join(", ");
5021
+ }
4917
5022
  function scalarText(field, value, labels, stillWaitingFor) {
4918
5023
  if (value === null || value === void 0) return "\u2014";
4919
5024
  if (sourceArchivedOf2(value)) return SOURCE_ARCHIVED_WORDS;
@@ -4931,6 +5036,8 @@ function scalarText(field, value, labels, stillWaitingFor) {
4931
5036
  if (isId(value) && (field.type === "list" || field.type === "relation")) {
4932
5037
  return labels?.(field, String(value)) ?? stillWaitingFor ?? "Loading\u2026";
4933
5038
  }
5039
+ const personal = personWordsOf(kind, value);
5040
+ if (personal !== null) return personal;
4934
5041
  if (field.type === "list" && typeof value === "string" && labels) {
4935
5042
  const words = labels(field, value);
4936
5043
  if (words) return words;
@@ -4961,15 +5068,15 @@ function bringBackLabel(state2) {
4961
5068
  }
4962
5069
  function SourceArchivedNotice({ fieldId, tableId }) {
4963
5070
  const client = useRecordsClient6();
4964
- const [state2, setState] = useState19(null);
4965
- const [busy, setBusy] = useState19(false);
4966
- const [refused, setRefused] = useState19(null);
5071
+ const [state2, setState] = useState20(null);
5072
+ const [busy, setBusy] = useState20(false);
5073
+ const [refused, setRefused] = useState20(null);
4967
5074
  const read = useCallback6(async () => {
4968
5075
  const answer = await client.fieldSourceArchived({ field_id: fieldId });
4969
5076
  if (answer.ok) setState(answer.data);
4970
5077
  else setRefused(answer.error);
4971
5078
  }, [client, fieldId]);
4972
- useEffect13(() => {
5079
+ useEffect14(() => {
4973
5080
  void read();
4974
5081
  }, [read]);
4975
5082
  if (refused && !state2) return /* @__PURE__ */ jsx25(RefusalNotice, { error: refused });
@@ -5007,13 +5114,13 @@ function SourceArchivedNotice({ fieldId, tableId }) {
5007
5114
  }
5008
5115
 
5009
5116
  // src/Condition.tsx
5010
- import { createContext as createContext4, useContext as useContext4, useEffect as useEffect14, useState as useState20 } from "react";
5117
+ import { createContext as createContext4, useContext as useContext4, useEffect as useEffect15, useState as useState21 } from "react";
5011
5118
  import { BasicInput as BasicInput7, Button as Button12 } from "@ai-matrx/design-system";
5012
5119
  import { optionKey as optionKey2, optionLabel as optionLabel2, rankTypedMatches as rankTypedMatches3 } from "@ai-matrx/records";
5013
- import { useOptionalRecordsClient as useOptionalRecordsClient7 } from "@ai-matrx/records/react";
5120
+ import { useOptionalRecordsClient as useOptionalRecordsClient8 } from "@ai-matrx/records/react";
5014
5121
 
5015
5122
  // src/personTime.ts
5016
- import { useSyncExternalStore } from "react";
5123
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
5017
5124
 
5018
5125
  // src/personZone.ts
5019
5126
  import { setColorRuleTimeZone } from "@ai-matrx/design-system/data-table/table-style";
@@ -5050,7 +5157,7 @@ function personWallNow(at = /* @__PURE__ */ new Date()) {
5050
5157
 
5051
5158
  // src/personTime.ts
5052
5159
  function usePersonTimeZone() {
5053
- return useSyncExternalStore(
5160
+ return useSyncExternalStore2(
5054
5161
  subscribePersonTimeZone,
5055
5162
  getPersonTimeZone,
5056
5163
  () => null
@@ -5146,11 +5253,11 @@ function isChoiceColumn(f) {
5146
5253
  return kind === "select" || kind === "multi_select";
5147
5254
  }
5148
5255
  function ChoiceValue({ field, value, onChange }) {
5149
- const client = useOptionalRecordsClient7();
5150
- const [choices, setChoices] = useState20(null);
5151
- const [open, setOpen] = useState20(false);
5152
- const [search, setSearch] = useState20("");
5153
- useEffect14(() => {
5256
+ const client = useOptionalRecordsClient8();
5257
+ const [choices, setChoices] = useState21(null);
5258
+ const [open, setOpen] = useState21(false);
5259
+ const [search, setSearch] = useState21("");
5260
+ useEffect15(() => {
5154
5261
  if (!client) return;
5155
5262
  let cancelled = false;
5156
5263
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((got) => {
@@ -5480,7 +5587,7 @@ function ConditionGroup({
5480
5587
  className
5481
5588
  }) {
5482
5589
  const { joiner, args } = clausesOf(expr);
5483
- const [drafting, setDrafting] = useState20(null);
5590
+ const [drafting, setDrafting] = useState21(null);
5484
5591
  const nested = depth > 0;
5485
5592
  const replaceAt = (index, next) => {
5486
5593
  const nextArgs = args.slice();
@@ -5607,10 +5714,73 @@ function ConditionGroup({
5607
5714
  }
5608
5715
 
5609
5716
  // src/FieldRetype.tsx
5610
- import { useEffect as useEffect15, useState as useState21 } from "react";
5717
+ import { useEffect as useEffect16, useState as useState22 } from "react";
5611
5718
  import { previewRetype } from "@ai-matrx/records";
5612
5719
  import { tableShapeChanged as tableShapeChanged2, useRecordsClient as useRecordsClient7 } from "@ai-matrx/records/react";
5613
5720
  import { Button as Button13, Select as Select4, SelectContent as SelectContent4, SelectItem as SelectItem4, SelectTrigger as SelectTrigger4, SelectValue as SelectValue4 } from "@ai-matrx/design-system";
5721
+
5722
+ // src/personRetype.ts
5723
+ var PAGE = 500;
5724
+ var CEILING = 2e4;
5725
+ function idsIn(value) {
5726
+ return (Array.isArray(value) ? value : [value]).filter(isUserId);
5727
+ }
5728
+ async function readPersonColumn(client, tableId, key) {
5729
+ const out = [];
5730
+ for (let offset = 0; offset < CEILING; offset += PAGE) {
5731
+ const page = await client.list({ table_id: tableId, limit: PAGE, offset });
5732
+ if (!page.ok) throw new Error(page.error.message ?? "The records could not be read");
5733
+ for (const row of page.data.rows) {
5734
+ const doc = row.document ?? {};
5735
+ let ids = idsIn(doc[key]);
5736
+ if (ids.length === 0 && Array.isArray(doc["_retired"])) {
5737
+ const kept = doc["_retired"].filter((e) => e.key === key);
5738
+ const last = kept[kept.length - 1];
5739
+ if (last) ids = idsIn(last.value);
5740
+ }
5741
+ if (ids.length > 0) out.push({ recordId: row.id, ids });
5742
+ }
5743
+ if (page.data.rows.length < PAGE) break;
5744
+ }
5745
+ return out;
5746
+ }
5747
+ async function resolvePeople(client, rows, roster) {
5748
+ const distinct = [...new Set(rows.flatMap((r) => r.ids))];
5749
+ const people = await Promise.all(distinct.map((id) => resolveKeptPerson(client, id, roster)));
5750
+ return new Map(people.map((p) => [p.id, p]));
5751
+ }
5752
+ function wordsFor(ids, people, as) {
5753
+ const said2 = ids.map((id) => as === "name" ? people.get(id)?.name : people.get(id)?.email).filter((w) => typeof w === "string" && w.trim() !== "" && !w.startsWith("A person no longer"));
5754
+ return said2.length > 0 ? said2.join(", ") : null;
5755
+ }
5756
+ function previewPersonWords(rows, people, as) {
5757
+ let converts = 0;
5758
+ let keptAside = 0;
5759
+ const examples = [];
5760
+ for (const row of rows) {
5761
+ if (wordsFor(row.ids, people, as) !== null) converts += 1;
5762
+ else {
5763
+ keptAside += 1;
5764
+ const who = people.get(row.ids[0] ?? "")?.name;
5765
+ if (who && examples.length < 5 && !examples.includes(who)) examples.push(who);
5766
+ }
5767
+ }
5768
+ return { converts, keptAside, examples, partial: false };
5769
+ }
5770
+ async function writePersonWords(client, tableId, rows, people, key, as) {
5771
+ const changes = [];
5772
+ for (const row of rows) {
5773
+ const words = wordsFor(row.ids, people, as);
5774
+ if (words !== null) changes.push({ op: "update", record_id: row.recordId, patch: { [key]: words } });
5775
+ }
5776
+ for (let i = 0; i < changes.length; i += 100) {
5777
+ const done = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
5778
+ if (!done.ok) throw new Error(done.error.message ?? "The words could not be written");
5779
+ }
5780
+ return changes.length;
5781
+ }
5782
+
5783
+ // src/FieldRetype.tsx
5614
5784
  import { jsx as jsx27, jsxs as jsxs25 } from "react/jsx-runtime";
5615
5785
  var RETYPE_TARGETS = [
5616
5786
  { id: "text", behaviour: "text", kind: null, label: "Text", holds: "words", via: "behaviour" },
@@ -5634,6 +5804,7 @@ var RETYPE_TARGETS = [
5634
5804
  ];
5635
5805
  var PREVIEW_GROUPS = 1e3;
5636
5806
  function retypeableFrom(field) {
5807
+ if (isPersonField(field)) return true;
5637
5808
  const behaviour = String(field.type);
5638
5809
  return behaviour === "text" || behaviour === "range" || behaviour === "boolean";
5639
5810
  }
@@ -5648,7 +5819,11 @@ function whyNotRetypeable(field) {
5648
5819
  }
5649
5820
  return "Its kind is not changed here.";
5650
5821
  }
5822
+ function isPersonField(field) {
5823
+ return String(editorKindFor(field)) === "member";
5824
+ }
5651
5825
  function currentTarget(field) {
5826
+ if (isPersonField(field)) return "person";
5652
5827
  const kind = String(editorKindFor(field));
5653
5828
  if (String(field.type) === "boolean") return "checkbox";
5654
5829
  if (kind === "datetime" || kind === "date") return "date";
@@ -5656,23 +5831,51 @@ function currentTarget(field) {
5656
5831
  if (String(field.type) === "range") return "number";
5657
5832
  return "text";
5658
5833
  }
5834
+ function failure(e, fallback) {
5835
+ return { code: "internal", message: e instanceof Error && e.message ? e.message : fallback };
5836
+ }
5659
5837
  function FieldRetype({ field, tableId, onRetyped }) {
5660
5838
  const client = useRecordsClient7();
5661
5839
  const notify = useRecordsUi().notify;
5662
- const [to, setTo] = useState21(null);
5663
- const [preview, setPreview] = useState21(null);
5664
- const [asking, setAsking] = useState21(false);
5665
- const [refusal, setRefusal] = useState21(null);
5666
- const [busy, setBusy] = useState21(false);
5667
- const [said2, setSaid] = useState21(null);
5840
+ const [to, setTo] = useState22(null);
5841
+ const [preview, setPreview] = useState22(null);
5842
+ const [asking, setAsking] = useState22(false);
5843
+ const [refusal, setRefusal] = useState22(null);
5844
+ const [busy, setBusy] = useState22(false);
5845
+ const [said2, setSaid] = useState22(null);
5846
+ const roster = useMemberRoster();
5847
+ const person = isPersonField(field);
5848
+ const [read, setRead] = useState22(null);
5668
5849
  const name = fieldName(field);
5669
5850
  const targets = RETYPE_TARGETS.filter((t) => t.id !== currentTarget(field));
5670
- useEffect15(() => {
5851
+ useEffect16(() => {
5671
5852
  if (!to) return;
5672
5853
  let cancelled = false;
5673
5854
  setPreview(null);
5674
5855
  setRefusal(null);
5675
5856
  setAsking(true);
5857
+ if (person) {
5858
+ if (!roster) return;
5859
+ void readPersonColumn(client, tableId, field.key).then(async (rows) => {
5860
+ const people = await resolvePeople(client, rows, roster);
5861
+ if (cancelled) return;
5862
+ setRead({ rows, people });
5863
+ setAsking(false);
5864
+ if (to.id === "text" || to.id === "email") {
5865
+ setPreview(previewPersonWords(rows, people, to.id === "email" ? "email" : "name"));
5866
+ return;
5867
+ }
5868
+ const groups = rows.map((r) => ({ value: r.ids.map((id) => people.get(id)?.name ?? "").join(", "), count: 1 }));
5869
+ setPreview(previewRetype({ type: to.behaviour, kind: to.kind }, groups, false));
5870
+ }).catch((e) => {
5871
+ if (cancelled) return;
5872
+ setAsking(false);
5873
+ setRefusal(failure(e, "The people could not be read"));
5874
+ });
5875
+ return () => {
5876
+ cancelled = true;
5877
+ };
5878
+ }
5676
5879
  void client.recordAggregate({ table_id: tableId, groupBy: [field.key], measures: [{ op: "count" }], limit: PREVIEW_GROUPS }).then((answer) => {
5677
5880
  if (cancelled) return;
5678
5881
  setAsking(false);
@@ -5686,7 +5889,7 @@ function FieldRetype({ field, tableId, onRetyped }) {
5686
5889
  return () => {
5687
5890
  cancelled = true;
5688
5891
  };
5689
- }, [client, tableId, field.key, to]);
5892
+ }, [client, tableId, field.key, to, person, roster]);
5690
5893
  if (!retypeableFrom(field)) {
5691
5894
  return /* @__PURE__ */ jsx27("p", { className: "text-[11px] text-muted-foreground", "data-records-retype": "not-here", children: whyNotRetypeable(field) });
5692
5895
  }
@@ -5723,12 +5926,30 @@ function FieldRetype({ field, tableId, onRetyped }) {
5723
5926
  undo: async () => {
5724
5927
  const back = await client.migrateUndo({ migration_id: migration });
5725
5928
  if (!back.ok) throw new Error(refusalSentence(back.error));
5929
+ if (person && read && (to.id === "text" || to.id === "email")) {
5930
+ const changes = read.rows.map((r) => ({ op: "update", record_id: r.recordId, patch: { [field.key]: field.multi ? r.ids : r.ids[0] ?? null } }));
5931
+ for (let i = 0; i < changes.length; i += 100) {
5932
+ const put = await client.recordChangeMany({ table_id: tableId, changes: changes.slice(i, i + 100) });
5933
+ if (!put.ok) throw new Error(refusalSentence(put.error));
5934
+ }
5935
+ }
5726
5936
  tableShapeChanged2(tableId);
5727
5937
  onRetyped?.();
5728
5938
  }
5729
5939
  });
5730
5940
  }
5731
5941
  }
5942
+ if (person && read && (to.id === "text" || to.id === "email")) {
5943
+ const as = to.id === "email" ? "email" : "name";
5944
+ try {
5945
+ const written = await writePersonWords(client, tableId, read.rows, read.people, field.key, as);
5946
+ holding = written;
5947
+ aside = read.rows.length - written;
5948
+ } catch (e) {
5949
+ setRefusal(failure(e, "The words could not be written"));
5950
+ return;
5951
+ }
5952
+ }
5732
5953
  setSaid(
5733
5954
  `${name} now holds ${to.holds}. ${holding} ${holding === 1 ? "record holds" : "records hold"} a value` + (aside > 0 ? `; ${aside} ${aside === 1 ? "value that did not fit was" : "values that did not fit were"} kept with ${aside === 1 ? "its record" : "their records"}, with the reason.` : ".")
5734
5955
  );
@@ -5766,7 +5987,7 @@ function FieldRetype({ field, tableId, onRetyped }) {
5766
5987
  }
5767
5988
 
5768
5989
  // src/FieldRulePreview.tsx
5769
- import { useEffect as useEffect16, useMemo as useMemo10, useRef as useRef12, useState as useState22 } from "react";
5990
+ import { useEffect as useEffect17, useMemo as useMemo11, useRef as useRef12, useState as useState23 } from "react";
5770
5991
  import { previewRuleChange } from "@ai-matrx/records";
5771
5992
  import { useRecordsClient as useRecordsClient8 } from "@ai-matrx/records/react";
5772
5993
  import { jsx as jsx28, jsxs as jsxs26 } from "react/jsx-runtime";
@@ -5787,13 +6008,13 @@ function groupValue(value, numbers) {
5787
6008
  }
5788
6009
  function FieldRulePreview({ field, tableId, rules }) {
5789
6010
  const client = useRecordsClient8();
5790
- const [preview, setPreview] = useState22(null);
5791
- const [refusal, setRefusal] = useState22(null);
5792
- const key = useMemo10(() => ruleWords(rules), [rules]);
6011
+ const [preview, setPreview] = useState23(null);
6012
+ const [refusal, setRefusal] = useState23(null);
6013
+ const key = useMemo11(() => ruleWords(rules), [rules]);
5793
6014
  const latest = useRef12(rules);
5794
6015
  latest.current = rules;
5795
6016
  const name = fieldName(field);
5796
- useEffect16(() => {
6017
+ useEffect17(() => {
5797
6018
  let cancelled = false;
5798
6019
  setPreview(null);
5799
6020
  setRefusal(null);
@@ -6324,11 +6545,11 @@ function nextFieldSort(fields) {
6324
6545
  import { autonumberPrefixOf as autonumberPrefixOf3, buttonNeeds, buttonOf } from "@ai-matrx/records";
6325
6546
 
6326
6547
  // src/ButtonSettings.tsx
6327
- import { useEffect as useEffect17, useState as useState23 } from "react";
6548
+ import { useEffect as useEffect18, useState as useState24 } from "react";
6328
6549
  import { BasicInput as BasicInput8, Button as Button14, Label as Label7 } from "@ai-matrx/design-system";
6329
6550
  import { STYLE_COLORS as STYLE_COLORS3 } from "@ai-matrx/design-system/data-table";
6330
6551
  import { buttonUrlPlaceholders } from "@ai-matrx/records";
6331
- import { useOptionalRecordsClient as useOptionalRecordsClient8 } from "@ai-matrx/records/react";
6552
+ import { useOptionalRecordsClient as useOptionalRecordsClient9 } from "@ai-matrx/records/react";
6332
6553
 
6333
6554
  // src/AccentSwatches.tsx
6334
6555
  import { PORTAL_ACCENTS } from "@ai-matrx/records";
@@ -6389,11 +6610,11 @@ function ButtonSettingsEditor({
6389
6610
  tableId,
6390
6611
  fields
6391
6612
  }) {
6392
- const client = useOptionalRecordsClient8();
6393
- const [actions, setActions] = useState23(null);
6394
- const [actionsRefused, setActionsRefused] = useState23(null);
6395
- const [automations, setAutomations] = useState23(null);
6396
- useEffect17(() => {
6613
+ const client = useOptionalRecordsClient9();
6614
+ const [actions, setActions] = useState24(null);
6615
+ const [actionsRefused, setActionsRefused] = useState24(null);
6616
+ const [automations, setAutomations] = useState24(null);
6617
+ useEffect18(() => {
6397
6618
  if (!client || !tableId) return;
6398
6619
  let live = true;
6399
6620
  if (value.do === "run_action" && actions === null) {
@@ -6525,12 +6746,12 @@ function NewRowAction({
6525
6746
  columns,
6526
6747
  onMade
6527
6748
  }) {
6528
- const client = useOptionalRecordsClient8();
6749
+ const client = useOptionalRecordsClient9();
6529
6750
  const settable = settableColumns(columns);
6530
- const [fieldId, setFieldId] = useState23("");
6531
- const [setTo, setSetTo] = useState23("");
6532
- const [busy, setBusy] = useState23(false);
6533
- const [refused, setRefused] = useState23(null);
6751
+ const [fieldId, setFieldId] = useState24("");
6752
+ const [setTo, setSetTo] = useState24("");
6753
+ const [busy, setBusy] = useState24(false);
6754
+ const [refused, setRefused] = useState24(null);
6534
6755
  if (settable.length === 0) return /* @__PURE__ */ jsx32("p", { className: "text-xs text-muted-foreground", children: "No column to set" });
6535
6756
  const make = async () => {
6536
6757
  if (!client || fieldId === "") return;
@@ -6692,33 +6913,33 @@ function FieldEditor(props) {
6692
6913
  const copyOf = field ? void 0 : props.copyOf;
6693
6914
  const start = field ?? copyOf;
6694
6915
  const startAs = start ? void 0 : props.startAs;
6695
- const [label, setLabel] = useState24(field?.label ?? (copyOf ? `${copyOf.label} (1)` : startAs?.label ?? ""));
6696
- const [type, setType] = useState24(() => startAs ? startAs.type : startingType(start));
6697
- const [required, setRequired] = useState24(start?.required ?? false);
6698
- const [multi, setMulti] = useState24(start?.multi ?? false);
6699
- const [dated, setDated] = useState24(start?.dated ?? false);
6700
- const [sensitivity, setSensitivity] = useState24(String(start?.sensitivity ?? "internal"));
6701
- const [contextPolicy, setContextPolicy] = useState24(String(start?.context_policy ?? "include"));
6702
- const [rules, setRules] = useState24(start?.rules ?? []);
6703
- const [startsWith, setStartsWith] = useState24(start?.default ?? null);
6704
- const [ratingMax, setRatingMax] = useState24(() => start ? ratingMaxOf2(start) : 5);
6705
- const savedRules = useMemo11(
6916
+ const [label, setLabel] = useState25(field?.label ?? (copyOf ? `${copyOf.label} (1)` : startAs?.label ?? ""));
6917
+ const [type, setType] = useState25(() => startAs ? startAs.type : startingType(start));
6918
+ const [required, setRequired] = useState25(start?.required ?? false);
6919
+ const [multi, setMulti] = useState25(start?.multi ?? false);
6920
+ const [dated, setDated] = useState25(start?.dated ?? false);
6921
+ const [sensitivity, setSensitivity] = useState25(String(start?.sensitivity ?? "internal"));
6922
+ const [contextPolicy, setContextPolicy] = useState25(String(start?.context_policy ?? "include"));
6923
+ const [rules, setRules] = useState25(start?.rules ?? []);
6924
+ const [startsWith, setStartsWith] = useState25(start?.default ?? null);
6925
+ const [ratingMax, setRatingMax] = useState25(() => start ? ratingMaxOf2(start) : 5);
6926
+ const savedRules = useMemo12(
6706
6927
  () => field ? type === "rating" ? rulesWithTopStar(field.rules ?? [], ratingMaxOf2(field)) : field.rules ?? [] : [],
6707
6928
  [field, type]
6708
6929
  );
6709
- const editedRules = useMemo11(() => type === "rating" ? rulesWithTopStar(rules, ratingMax) : rules, [type, rules, ratingMax]);
6710
- const [statusGroups, setStatusGroups] = useState24({});
6711
- const [statusKeys, setStatusKeys] = useState24({});
6712
- const [symbology, setSymbology] = useState24(String(start?.config?.["symbology"] ?? ""));
6930
+ const editedRules = useMemo12(() => type === "rating" ? rulesWithTopStar(rules, ratingMax) : rules, [type, rules, ratingMax]);
6931
+ const [statusGroups, setStatusGroups] = useState25({});
6932
+ const [statusKeys, setStatusKeys] = useState25({});
6933
+ const [symbology, setSymbology] = useState25(String(start?.config?.["symbology"] ?? ""));
6713
6934
  const descriptionStart = String(start?.config?.["description"] ?? "");
6714
- const [description, setDescription] = useState24(descriptionStart);
6715
- const buttonStart = useMemo11(() => buttonOf(start) ?? { label: "" }, [start]);
6716
- const [buttonSettings, setButtonSettings] = useState24(buttonStart);
6935
+ const [description, setDescription] = useState25(descriptionStart);
6936
+ const buttonStart = useMemo12(() => buttonOf(start) ?? { label: "" }, [start]);
6937
+ const [buttonSettings, setButtonSettings] = useState25(buttonStart);
6717
6938
  const prefixStart = autonumberPrefixOf3(start);
6718
- const [numberPrefix, setNumberPrefix] = useState24(prefixStart);
6939
+ const [numberPrefix, setNumberPrefix] = useState25(prefixStart);
6719
6940
  const dependencyStart = start?.config?.["dependency"] === true;
6720
- const [dependency, setDependency] = useState24(dependencyStart);
6721
- useEffect18(() => {
6941
+ const [dependency, setDependency] = useState25(dependencyStart);
6942
+ useEffect19(() => {
6722
6943
  if (!field || type !== "status") return;
6723
6944
  let live = true;
6724
6945
  void client.fieldOptions({ field_id: field.id }).then((got) => {
@@ -6728,20 +6949,20 @@ function FieldEditor(props) {
6728
6949
  live = false;
6729
6950
  };
6730
6951
  }, [client, field, type]);
6731
- useEffect18(() => {
6952
+ useEffect19(() => {
6732
6953
  if (field || type !== "status") return;
6733
6954
  setNewChoices(
6734
6955
  (rows) => rows.length > 0 ? rows : STATUS_STARTING_CHOICES.map((c, i) => ({ id: null, words: c.words, row: `status-${i}` }))
6735
6956
  );
6736
6957
  }, [field, type]);
6737
- useEffect18(() => {
6958
+ useEffect19(() => {
6738
6959
  if (field || type !== "select" && type !== "multi_select") return;
6739
6960
  setNewChoices((rows) => rows.length > 0 ? rows : [newChoiceRow([])]);
6740
6961
  }, [field, type]);
6741
- const [allowOther, setAllowOther] = useState24(start?.config?.["allow_other"] === true);
6742
- const [newChoices, setNewChoices] = useState24([]);
6962
+ const [allowOther, setAllowOther] = useState25(start?.config?.["allow_other"] === true);
6963
+ const [newChoices, setNewChoices] = useState25([]);
6743
6964
  const copyOfId = copyOf?.id ?? null;
6744
- useEffect18(() => {
6965
+ useEffect19(() => {
6745
6966
  if (!copyOf || !copyOfId) return;
6746
6967
  let live = true;
6747
6968
  void client.fieldOptions({ field_id: copyOfId }).then((got) => {
@@ -6753,53 +6974,53 @@ function FieldEditor(props) {
6753
6974
  live = false;
6754
6975
  };
6755
6976
  }, [client, copyOfId]);
6756
- const [choiceList, setChoiceList] = useState24(null);
6757
- const [choiceListStart, setChoiceListStart] = useState24(null);
6758
- const [rehome, setRehome] = useState24({});
6759
- const [rehomed, setRehomed] = useState24(null);
6760
- const [rehomeRefused, setRehomeRefused] = useState24(null);
6761
- const [unit, setUnit] = useState24(start?.unit ?? "$");
6762
- const [withTime, setWithTime] = useState24(String(start?.config?.["kind"] ?? "date") === "datetime");
6763
- const [via, setVia] = useState24(String(start?.config?.["via"] ?? ""));
6764
- const [pick, setPick] = useState24(String(start?.config?.["pick"] ?? ""));
6765
- const [agg, setAgg] = useState24(
6977
+ const [choiceList, setChoiceList] = useState25(null);
6978
+ const [choiceListStart, setChoiceListStart] = useState25(null);
6979
+ const [rehome, setRehome] = useState25({});
6980
+ const [rehomed, setRehomed] = useState25(null);
6981
+ const [rehomeRefused, setRehomeRefused] = useState25(null);
6982
+ const [unit, setUnit] = useState25(start?.unit ?? "$");
6983
+ const [withTime, setWithTime] = useState25(String(start?.config?.["kind"] ?? "date") === "datetime");
6984
+ const [via, setVia] = useState25(String(start?.config?.["via"] ?? ""));
6985
+ const [pick, setPick] = useState25(String(start?.config?.["pick"] ?? ""));
6986
+ const [agg, setAgg] = useState25(
6766
6987
  start?.config?.["agg"] ?? "count"
6767
6988
  );
6768
- const [of, setOf] = useState24(String(start?.config?.["of"] ?? ""));
6989
+ const [of, setOf] = useState25(String(start?.config?.["of"] ?? ""));
6769
6990
  const savedRollupFilter = field?.config?.["filter"] ?? null;
6770
- const [rollupFilter, setRollupFilter] = useState24(
6991
+ const [rollupFilter, setRollupFilter] = useState25(
6771
6992
  field ? savedRollupFilter : copyOf?.config?.["filter"] ?? null
6772
6993
  );
6773
6994
  const rollupFilterChanged = JSON.stringify(rollupFilter) !== JSON.stringify(savedRollupFilter);
6774
- const [relationTarget, setRelationTarget] = useState24(String(start?.relation_target ?? ""));
6775
- const [showOnOther, setShowOnOther] = useState24(true);
6776
- const [nestsSubItems, setNestsSubItems] = useState24(false);
6777
- const [reverseRefused, setReverseRefused] = useState24(null);
6995
+ const [relationTarget, setRelationTarget] = useState25(String(start?.relation_target ?? ""));
6996
+ const [showOnOther, setShowOnOther] = useState25(true);
6997
+ const [nestsSubItems, setNestsSubItems] = useState25(false);
6998
+ const [reverseRefused, setReverseRefused] = useState25(null);
6778
6999
  const otherTable = useTable(!field && type === "relation" && relationTarget !== "" ? relationTarget : null);
6779
- const [display, setDisplay] = useState24(start?.display ?? null);
6780
- const [formulaOp, setFormulaOp] = useState24(() => formulaOpOf(start));
6781
- const [formulaFields, setFormulaFields] = useState24(() => formulaFieldIdsOf(start));
6782
- const [formulaSeparator, setFormulaSeparator] = useState24(() => formulaSeparatorOf(start));
6783
- const [allowedTypes, setAllowedTypes] = useState24(() => entityReferenceKindsOf(start));
7000
+ const [display, setDisplay] = useState25(start?.display ?? null);
7001
+ const [formulaOp, setFormulaOp] = useState25(() => formulaOpOf(start));
7002
+ const [formulaFields, setFormulaFields] = useState25(() => formulaFieldIdsOf(start));
7003
+ const [formulaSeparator, setFormulaSeparator] = useState25(() => formulaSeparatorOf(start));
7004
+ const [allowedTypes, setAllowedTypes] = useState25(() => entityReferenceKindsOf(start));
6784
7005
  const startingFormulaText = start ? formulaTextNow(String(start.config?.["formula_text"] ?? ""), start.config?.["expr"] ?? start.expr, fields.data) : "";
6785
- const [formulaText, setFormulaText] = useState24(startingFormulaText);
7006
+ const [formulaText, setFormulaText] = useState25(startingFormulaText);
6786
7007
  const shownFormula = useRef13(startingFormulaText);
6787
- useEffect18(() => {
7008
+ useEffect19(() => {
6788
7009
  if (shownFormula.current === startingFormulaText) return;
6789
7010
  setFormulaText((typed) => typed === shownFormula.current ? startingFormulaText : typed);
6790
7011
  shownFormula.current = startingFormulaText;
6791
7012
  }, [startingFormulaText]);
6792
- const [formulaWritten, setFormulaWritten] = useState24(() => startingFormulaText.trim() !== "" || Boolean(field) || startAs?.type === "formula");
6793
- const [formulaOk, setFormulaOk] = useState24(null);
6794
- const [askingToRemove, setAskingToRemove] = useState24(false);
6795
- const [attempted, setAttempted] = useState24(false);
6796
- const [showsAs, setShowsAs] = useState24(() => start ? startingChoice(start) : { format: null, retype: null });
6797
- const [backfillError, setBackfillError] = useState24(null);
6798
- const [notLanded, setNotLanded] = useState24(false);
7013
+ const [formulaWritten, setFormulaWritten] = useState25(() => startingFormulaText.trim() !== "" || Boolean(field) || startAs?.type === "formula");
7014
+ const [formulaOk, setFormulaOk] = useState25(null);
7015
+ const [askingToRemove, setAskingToRemove] = useState25(false);
7016
+ const [attempted, setAttempted] = useState25(false);
7017
+ const [showsAs, setShowsAs] = useState25(() => start ? startingChoice(start) : { format: null, retype: null });
7018
+ const [backfillError, setBackfillError] = useState25(null);
7019
+ const [notLanded, setNotLanded] = useState25(false);
6799
7020
  const liveField = field ? fields.data?.find((f) => f.id === field.id) ?? field : void 0;
6800
7021
  const heldAs = liveField ? JSON.stringify([liveField.type, liveField.config?.["kind"] ?? null, liveField.format ?? null, liveField.multi ?? false, liveField.unit ?? null]) : "";
6801
7022
  const seededAs = useRef13(heldAs);
6802
- useEffect18(() => {
7023
+ useEffect19(() => {
6803
7024
  if (!liveField || seededAs.current === heldAs) return;
6804
7025
  seededAs.current = heldAs;
6805
7026
  setType(startingType(liveField));
@@ -6808,24 +7029,24 @@ function FieldEditor(props) {
6808
7029
  setUnit(liveField.unit ?? "$");
6809
7030
  setWithTime(String(liveField.config?.["kind"] ?? "date") === "datetime");
6810
7031
  }, [heldAs]);
6811
- const others = useMemo11(
7032
+ const others = useMemo12(
6812
7033
  () => (fields.data ?? []).filter((f) => f.id !== field?.id),
6813
7034
  [fields.data, field?.id]
6814
7035
  );
6815
- const relations = useMemo11(() => others.filter((f) => sourceKindOf(f) !== null), [others]);
7036
+ const relations = useMemo12(() => others.filter((f) => sourceKindOf(f) !== null), [others]);
6816
7037
  const reverse = useReverseColumns(onEntity ? null : tableId);
6817
- const backLinks = useMemo11(() => (reverse.data ?? []).map(backLinkAsSource), [reverse.data]);
6818
- const totalSources = useMemo11(() => [...relations, ...backLinks], [relations, backLinks]);
7038
+ const backLinks = useMemo12(() => (reverse.data ?? []).map(backLinkAsSource), [reverse.data]);
7039
+ const totalSources = useMemo12(() => [...relations, ...backLinks], [relations, backLinks]);
6819
7040
  const sourcesFor = (kind) => kind === "rollup" || kind === "count" ? totalSources : relations;
6820
7041
  const choice = fieldTypeChoice(type);
6821
7042
  const editing = Boolean(field);
6822
- useEffect18(() => {
7043
+ useEffect19(() => {
6823
7044
  if (!editing) setStartsWith(null);
6824
7045
  }, [type, editing]);
6825
7046
  const newDefault = !editing && !onEntity && newColumnTakesADefault(type) ? defaultToKeep(startsWith) : null;
6826
7047
  const farFieldsOfLink = useFields2(field && sourceKindOf(field) === "link" && !onEntity ? field.relation_target ?? null : null);
6827
7048
  const farTable = useTable(field && sourceKindOf(field) === "link" && !onEntity ? field.relation_target ?? null : null);
6828
- const linkReaders = useMemo11(
7049
+ const linkReaders = useMemo12(
6829
7050
  () => field ? readingThroughLink(field, farFieldsOfLink.data ?? []) : [],
6830
7051
  [field, farFieldsOfLink.data]
6831
7052
  );
@@ -7781,12 +8002,12 @@ function RollupFilterQuestion({
7781
8002
  }) {
7782
8003
  const far = relation?.relation_target ?? null;
7783
8004
  const farFields = useFields2(far);
7784
- const conditionFields = useMemo11(
8005
+ const conditionFields = useMemo12(
7785
8006
  () => (farFields.data ?? []).filter((f) => f.type !== "formula").map((f) => ({ id: f.id, key: f.key, label: fieldName(f), field: f })),
7786
8007
  [farFields.data]
7787
8008
  );
7788
8009
  const lastFar = useRef13(far);
7789
- useEffect18(() => {
8010
+ useEffect19(() => {
7790
8011
  if (lastFar.current !== null && far !== lastFar.current && !editing) onChange(null);
7791
8012
  lastFar.current = far;
7792
8013
  }, [far, editing, onChange]);
@@ -7895,11 +8116,11 @@ function buttonPressWords(label, pressed) {
7895
8116
  }
7896
8117
  var stop = (event) => event.stopPropagation();
7897
8118
  function ButtonValue({ field, recordId, inCell }) {
7898
- const client = useOptionalRecordsClient9();
8119
+ const client = useOptionalRecordsClient10();
7899
8120
  const b = buttonOf2(field);
7900
- const [busy, setBusy] = useState25(false);
7901
- const [said2, setSaid] = useState25(null);
7902
- const [settingUp, setSettingUp] = useState25(false);
8121
+ const [busy, setBusy] = useState26(false);
8122
+ const [said2, setSaid] = useState26(null);
8123
+ const [settingUp, setSettingUp] = useState26(false);
7903
8124
  if (!b) return null;
7904
8125
  const color = isStyleColor2(b.color) ? CHOICE_CHIP_CLASS2[b.color] : NEUTRAL_CHIP_CLASS2;
7905
8126
  const needs = buttonNeeds2(b);
@@ -7981,7 +8202,7 @@ function ButtonValue({ field, recordId, inCell }) {
7981
8202
  }
7982
8203
 
7983
8204
  // src/FloatingRefusal.tsx
7984
- import { useLayoutEffect, useRef as useRef14, useState as useState26 } from "react";
8205
+ import { useLayoutEffect, useRef as useRef14, useState as useState27 } from "react";
7985
8206
  import { createPortal } from "react-dom";
7986
8207
  import { Fragment as Fragment12, jsx as jsx35, jsxs as jsxs33 } from "react/jsx-runtime";
7987
8208
  var GAP = 4;
@@ -8001,8 +8222,8 @@ function placeFor(anchor, note) {
8001
8222
  function FloatingRefusal({ text, why }) {
8002
8223
  const spot = useRef14(null);
8003
8224
  const note = useRef14(null);
8004
- const [style, setStyle] = useState26(null);
8005
- const [floating, setFloating] = useState26(false);
8225
+ const [style, setStyle] = useState27(null);
8226
+ const [floating, setFloating] = useState27(false);
8006
8227
  useLayoutEffect(() => {
8007
8228
  const here = spot.current;
8008
8229
  if (!here) return;
@@ -8045,7 +8266,7 @@ function FloatingRefusal({ text, why }) {
8045
8266
  }
8046
8267
 
8047
8268
  // src/formatControls.tsx
8048
- import { useEffect as useEffect19, useRef as useRef15, useState as useState27 } from "react";
8269
+ import { useEffect as useEffect20, useRef as useRef15, useState as useState28 } from "react";
8049
8270
  import { BasicInput as BasicInput10, BasicTextarea as BasicTextarea3 } from "@ai-matrx/design-system";
8050
8271
  import { getFieldFormat as getFieldFormat4, parseFieldInput } from "@ai-matrx/design-system/field-formats";
8051
8272
  import { jsx as jsx36, jsxs as jsxs34 } from "react/jsx-runtime";
@@ -8065,9 +8286,9 @@ function keptValue(format, raw) {
8065
8286
  return parsed;
8066
8287
  }
8067
8288
  function NumberInFormat({ format, value, onChange, disabled, id }) {
8068
- const [text, setText] = useState27(() => typedText(format, value));
8289
+ const [text, setText] = useState28(() => typedText(format, value));
8069
8290
  const lastSent = useRef15(void 0);
8070
- useEffect19(() => {
8291
+ useEffect20(() => {
8071
8292
  if (value === lastSent.current) return;
8072
8293
  setText(typedText(format, value));
8073
8294
  }, [value, format]);
@@ -8141,7 +8362,7 @@ function formatControl(args) {
8141
8362
  }
8142
8363
 
8143
8364
  // src/typedDateHelper.tsx
8144
- import { useState as useState28 } from "react";
8365
+ import { useState as useState29 } from "react";
8145
8366
  import { Popover as Popover5, PopoverContent as PopoverContent5, PopoverTrigger as PopoverTrigger5, cn as cn24 } from "@ai-matrx/design-system";
8146
8367
  import { readTypedDate, readTypedTime, typedDateText, typedTimeText } from "@ai-matrx/records";
8147
8368
  import { jsx as jsx37, jsxs as jsxs35 } from "react/jsx-runtime";
@@ -8165,7 +8386,7 @@ function readBox(text, kind) {
8165
8386
  }
8166
8387
  return { day: read.day, time: null };
8167
8388
  }
8168
- function wordsFor(kind, day, time) {
8389
+ function wordsFor2(kind, day, time) {
8169
8390
  if (kind === "time") return time ? typedTimeText(time.h, time.m) : "";
8170
8391
  if (!day) return "";
8171
8392
  const dayText = typedDateText(day);
@@ -8192,12 +8413,12 @@ function TypedDateHelper({
8192
8413
  onPicked,
8193
8414
  startOpen = false
8194
8415
  }) {
8195
- const [open, setOpen] = useState28(startOpen);
8416
+ const [open, setOpen] = useState29(startOpen);
8196
8417
  const held = readBox(text, kind);
8197
8418
  usePersonTimeZone();
8198
8419
  const today = personWallNow();
8199
8420
  const start = held.day ? new Date(Number(held.day.slice(0, 4)), Number(held.day.slice(5, 7)) - 1, 1) : new Date(today.getFullYear(), today.getMonth(), 1);
8200
- const [month, setMonth] = useState28(null);
8421
+ const [month, setMonth] = useState29(null);
8201
8422
  const shown2 = month ?? { y: start.getFullYear(), m: start.getMonth() };
8202
8423
  const first = new Date(shown2.y, shown2.m, 1).getDay();
8203
8424
  const days = new Date(shown2.y, shown2.m + 1, 0).getDate();
@@ -8206,7 +8427,7 @@ function TypedDateHelper({
8206
8427
  const times = Array.from({ length: 48 }, (_, i) => ({ h: Math.floor(i / 2), m: i % 2 * 30 }));
8207
8428
  const pickDay = (d) => {
8208
8429
  const day = `${shown2.y}-${pad(shown2.m + 1)}-${pad(d)}`;
8209
- onText(wordsFor(kind, day, held.time));
8430
+ onText(wordsFor2(kind, day, held.time));
8210
8431
  if (kind === "date") {
8211
8432
  setOpen(false);
8212
8433
  onPicked?.();
@@ -8214,7 +8435,7 @@ function TypedDateHelper({
8214
8435
  };
8215
8436
  const pickTime = (t) => {
8216
8437
  const day = kind === "datetime" ? held.day ?? todayKey : null;
8217
- onText(wordsFor(kind, day, t));
8438
+ onText(wordsFor2(kind, day, t));
8218
8439
  setOpen(false);
8219
8440
  onPicked?.();
8220
8441
  };
@@ -8302,24 +8523,24 @@ function TypedDateHelper({
8302
8523
  }
8303
8524
 
8304
8525
  // src/choiceNudge.ts
8305
- import { useEffect as useEffect20, useState as useState29 } from "react";
8306
- import { useOptionalRecordsClient as useOptionalRecordsClient10 } from "@ai-matrx/records/react";
8307
- var asked = /* @__PURE__ */ new WeakMap();
8526
+ import { useEffect as useEffect21, useState as useState30 } from "react";
8527
+ import { useOptionalRecordsClient as useOptionalRecordsClient11 } from "@ai-matrx/records/react";
8528
+ var asked2 = /* @__PURE__ */ new WeakMap();
8308
8529
  function choiceNudgeOf(client) {
8309
- let answer = asked.get(client);
8530
+ let answer = asked2.get(client);
8310
8531
  if (!answer) {
8311
8532
  answer = Promise.resolve().then(() => client.choiceNudge()).then(
8312
8533
  (result) => result.ok ? result.data : "ask",
8313
8534
  () => "ask"
8314
8535
  );
8315
- asked.set(client, answer);
8536
+ asked2.set(client, answer);
8316
8537
  }
8317
8538
  return answer;
8318
8539
  }
8319
8540
  function useChoiceNudge(enabled = true) {
8320
- const client = useOptionalRecordsClient10();
8321
- const [nudge, setNudge] = useState29(null);
8322
- useEffect20(() => {
8541
+ const client = useOptionalRecordsClient11();
8542
+ const [nudge, setNudge] = useState30(null);
8543
+ useEffect21(() => {
8323
8544
  if (!enabled || !client) return;
8324
8545
  let live = true;
8325
8546
  void choiceNudgeOf(client).then((answer) => {
@@ -8471,7 +8692,7 @@ function openingText(field, value) {
8471
8692
  }
8472
8693
  function ReadsAsNote({ typed, always, children }) {
8473
8694
  const note = useRef16(null);
8474
- const [repeats, setRepeats] = useState30(false);
8695
+ const [repeats, setRepeats] = useState31(false);
8475
8696
  useLayoutEffect2(() => {
8476
8697
  if (always) return;
8477
8698
  const words = (t) => (t ?? "").replace(/^Reads as/, "").replace(/\s+/g, "").toLowerCase();
@@ -8481,12 +8702,12 @@ function ReadsAsNote({ typed, always, children }) {
8481
8702
  return /* @__PURE__ */ jsx38("span", { ref: note, "data-records-typed-reads-as": "", "data-records-cell-note": "", className: "text-[10px] text-muted-foreground", children });
8482
8703
  }
8483
8704
  function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCancel }) {
8484
- const client = useOptionalRecordsClient11();
8705
+ const client = useOptionalRecordsClient12();
8485
8706
  const kind = String(editorKindFor(field));
8486
8707
  const needsChoices = kind === "select" || kind === "multi_select";
8487
8708
  const nudge = useChoiceNudge(needsChoices);
8488
- const [choices, setChoices] = useState30(null);
8489
- useEffect21(() => {
8709
+ const [choices, setChoices] = useState31(null);
8710
+ useEffect22(() => {
8490
8711
  if (!needsChoices || !client) return;
8491
8712
  let cancelled = false;
8492
8713
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -8496,7 +8717,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
8496
8717
  cancelled = true;
8497
8718
  };
8498
8719
  }, [client, field.id, needsChoices]);
8499
- useEffect21(() => {
8720
+ useEffect22(() => {
8500
8721
  if (choices && nudge && value.judged === null) onChange({ ...value, judged: judgeTyped(field, value.text, choices, nudge) });
8501
8722
  }, [choices, nudge, value, field, onChange]);
8502
8723
  const judged = value.judged;
@@ -8572,7 +8793,7 @@ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose,
8572
8793
  const host = useRecordsUi();
8573
8794
  const kind = editorKindFor(field);
8574
8795
  const inputId = id ?? `field-${field.key}`;
8575
- const ownDetails = useOptionalRecordsClient11() === null;
8796
+ const ownDetails = useOptionalRecordsClient12() === null;
8576
8797
  if (isTypedDraft(value)) return /* @__PURE__ */ jsx38(TypedTextControl, { field, value, onChange, disabled, id: inputId, onCommit, onCancel });
8577
8798
  if (isSignatureField(field)) return /* @__PURE__ */ jsx38(SignaturePad, { id: inputId, value, onChange, disabled });
8578
8799
  if (isButtonField3(field)) return /* @__PURE__ */ jsx38(ButtonValue, { field });
@@ -8692,11 +8913,11 @@ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose,
8692
8913
  }
8693
8914
  }
8694
8915
  function TypedWordsControl({ field, value, onChange, disabled, id }) {
8695
- const [text, setText] = useState30(() => openingText(field, value));
8696
- const [refusal, setRefusal] = useState30(null);
8697
- const [why, setWhy] = useState30(void 0);
8916
+ const [text, setText] = useState31(() => openingText(field, value));
8917
+ const [refusal, setRefusal] = useState31(null);
8918
+ const [why, setWhy] = useState31(void 0);
8698
8919
  const sent = useRef16(value);
8699
- useEffect21(() => {
8920
+ useEffect22(() => {
8700
8921
  if (value === sent.current) return;
8701
8922
  sent.current = value;
8702
8923
  setText(openingText(field, value));
@@ -8776,8 +8997,8 @@ function CheckboxControl({ field, value, onChange, disabled, id }) {
8776
8997
  }
8777
8998
  function JsonControl({ field, value, onChange, disabled, id }) {
8778
8999
  const initial = value === null || value === void 0 ? "" : typeof value === "string" ? value : JSON.stringify(value, null, 2);
8779
- const [text, setText] = useState30(initial);
8780
- const [broken, setBroken] = useState30(null);
9000
+ const [text, setText] = useState31(initial);
9001
+ const [broken, setBroken] = useState31(null);
8781
9002
  return /* @__PURE__ */ jsxs36("div", { className: "flex flex-col gap-1", children: [
8782
9003
  /* @__PURE__ */ jsx38(
8783
9004
  BasicTextarea4,
@@ -8838,11 +9059,11 @@ function inTheStoresOrder(options) {
8838
9059
  return [...options].sort((a, b) => position(a) - position(b) || made(a).localeCompare(made(b)));
8839
9060
  }
8840
9061
  function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose, onCancel, addsChoices, initialSearch, asForm, onChosen }) {
8841
- const client = useOptionalRecordsClient11();
8842
- const [options, setOptions] = useState30(null);
8843
- const [refusal, setRefusal] = useState30(null);
8844
- const [reread, setReread] = useState30(0);
8845
- useEffect21(() => {
9062
+ const client = useOptionalRecordsClient12();
9063
+ const [options, setOptions] = useState31(null);
9064
+ const [refusal, setRefusal] = useState31(null);
9065
+ const [reread, setReread] = useState31(0);
9066
+ useEffect22(() => {
8846
9067
  if (!client) return;
8847
9068
  let cancelled = false;
8848
9069
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -9006,18 +9227,18 @@ function OpenChoicePicker({
9006
9227
  allowOther = true,
9007
9228
  onChoicesChanged
9008
9229
  }) {
9009
- const client = useOptionalRecordsClient11();
9230
+ const client = useOptionalRecordsClient12();
9010
9231
  const nudge = useChoiceNudge();
9011
- const [open, setOpenState] = useState30(autoOpen === true);
9232
+ const [open, setOpenState] = useState31(autoOpen === true);
9012
9233
  const onCloseRef = useRef16(onClose);
9013
9234
  onCloseRef.current = onClose;
9014
9235
  const setOpen = useCallback7((next) => {
9015
9236
  setOpenState(next);
9016
9237
  if (!next) onCloseRef.current?.();
9017
9238
  }, []);
9018
- const [search, setSearch] = useState30(initialSearch ?? "");
9019
- const [adding, setAdding] = useState30(false);
9020
- const [addRefused, setAddRefused] = useState30(null);
9239
+ const [search, setSearch] = useState31(initialSearch ?? "");
9240
+ const [adding, setAdding] = useState31(false);
9241
+ const [addRefused, setAddRefused] = useState31(null);
9021
9242
  const titleOf = (option) => recordName(option.data, null, "Unnamed choice");
9022
9243
  const held = withoutAddition(value);
9023
9244
  const current = choiceValuesOf(held.value);
@@ -9174,7 +9395,7 @@ function ChoiceAnswer({
9174
9395
  isChosen,
9175
9396
  onChosen
9176
9397
  }) {
9177
- const [search, setSearch] = useState30("");
9398
+ const [search, setSearch] = useState31("");
9178
9399
  const held = field.multi ? choiceValuesOf(value) : value === null || value === void 0 || value === "" ? [] : [value];
9179
9400
  const on = (choice) => held.some((v) => isChosen ? isChosen(choice, v) : String(v) === choice.key || String(v) === choice.label);
9180
9401
  const press = (choice) => {
@@ -9288,10 +9509,10 @@ var dataSources = globalSlot2("ai-matrx.records-ui.data-sources", () => /* @__PU
9288
9509
 
9289
9510
  // src/RecordsMount.tsx
9290
9511
  import { RecordsProvider } from "@ai-matrx/records/react";
9291
- import { jsx as jsx39 } from "react/jsx-runtime";
9512
+ import { jsx as jsx39, jsxs as jsxs37 } from "react/jsx-runtime";
9292
9513
 
9293
9514
  // src/TablePickers.tsx
9294
- import { Fragment as Fragment14, jsx as jsx40, jsxs as jsxs37 } from "react/jsx-runtime";
9515
+ import { Fragment as Fragment14, jsx as jsx40, jsxs as jsxs38 } from "react/jsx-runtime";
9295
9516
  var SHARED_FOR_MS = 5e3;
9296
9517
  var sharedReads = /* @__PURE__ */ new WeakMap();
9297
9518
  function readTablesAnywhere(dataSource) {
@@ -9323,8 +9544,8 @@ function readTablesAnywhere(dataSource) {
9323
9544
  return read;
9324
9545
  }
9325
9546
  function useTablesAnywhere(dataSource) {
9326
- const [state2, setState] = useState31({ loading: true, error: null, rows: [] });
9327
- useEffect22(() => {
9547
+ const [state2, setState] = useState32({ loading: true, error: null, rows: [] });
9548
+ useEffect23(() => {
9328
9549
  let live = true;
9329
9550
  void readTablesAnywhere(dataSource).then((result) => {
9330
9551
  if (live) setState(result);
@@ -9361,7 +9582,7 @@ function TablePicker({ dataSource, value, onChange, disabled, tables }) {
9361
9582
  hint: t.organization_name,
9362
9583
  keywords: t.organization_name,
9363
9584
  ...twin && second ? {
9364
- render: /* @__PURE__ */ jsxs37("span", { className: "flex min-w-0 flex-col", children: [
9585
+ render: /* @__PURE__ */ jsxs38("span", { className: "flex min-w-0 flex-col", children: [
9365
9586
  /* @__PURE__ */ jsx40("span", { className: "truncate", children: t.table_name }),
9366
9587
  /* @__PURE__ */ jsx40("span", { className: "truncate text-[11px] text-muted-foreground", children: second })
9367
9588
  ] })
@@ -9369,7 +9590,7 @@ function TablePicker({ dataSource, value, onChange, disabled, tables }) {
9369
9590
  };
9370
9591
  });
9371
9592
  const missing = Boolean(value) && !list.loading && !list.error && !list.rows.some((t) => t.table_id === value);
9372
- return /* @__PURE__ */ jsxs37("div", { className: "flex flex-col gap-1", children: [
9593
+ return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-1", children: [
9373
9594
  /* @__PURE__ */ jsx40(
9374
9595
  CreatablePicker,
9375
9596
  {
@@ -9398,10 +9619,10 @@ function TableScope({ dataSource, userId, tableId, children, fallback = null, un
9398
9619
  }
9399
9620
  function ColumnValuesEditor({ tableId, value, onChange, disabled, addLabel }) {
9400
9621
  const fields = useFields3(tableId);
9401
- const all = useMemo12(() => fields.data ?? [], [fields.data]);
9402
- const byKey = useMemo12(() => new Map(all.map((f) => [f.key, f])), [all]);
9622
+ const all = useMemo13(() => fields.data ?? [], [fields.data]);
9623
+ const byKey = useMemo13(() => new Map(all.map((f) => [f.key, f])), [all]);
9403
9624
  const keys = Object.keys(value);
9404
- const [adding, setAdding] = useState31(false);
9625
+ const [adding, setAdding] = useState32(false);
9405
9626
  const optionsFor = (current) => all.filter((f) => f.key === current || !(f.key in value)).map((f) => ({ value: f.key, label: fieldName(f) }));
9406
9627
  const rename = (from, to) => {
9407
9628
  if (from === to) return;
@@ -9414,7 +9635,7 @@ function ColumnValuesEditor({ tableId, value, onChange, disabled, addLabel }) {
9414
9635
  void _gone;
9415
9636
  onChange(rest);
9416
9637
  };
9417
- return /* @__PURE__ */ jsxs37("div", { className: "flex flex-col gap-2", children: [
9638
+ return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-2", children: [
9418
9639
  fields.error && /* @__PURE__ */ jsx40(RefusalLine, { error: fields.error }),
9419
9640
  keys.map((key) => {
9420
9641
  const field = byKey.get(key);
@@ -9467,8 +9688,8 @@ function ColumnValueRow({
9467
9688
  }) {
9468
9689
  const orphan = columnKey !== null && !loading && field === void 0;
9469
9690
  const shown2 = orphan ? [{ value: columnKey, label: columnKey, hint: "Not a column" }, ...options] : options;
9470
- return /* @__PURE__ */ jsxs37("div", { className: "flex flex-col gap-1 rounded-md border border-border/60 p-2", children: [
9471
- /* @__PURE__ */ jsxs37("div", { className: "flex items-center gap-2", children: [
9691
+ return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-1 rounded-md border border-border/60 p-2", children: [
9692
+ /* @__PURE__ */ jsxs38("div", { className: "flex items-center gap-2", children: [
9472
9693
  /* @__PURE__ */ jsx40("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx40(
9473
9694
  CreatablePicker,
9474
9695
  {
@@ -9497,7 +9718,7 @@ function RecordPicker({ tableId, value, onChange, disabled }) {
9497
9718
  label: rowNameIn(table.data ?? null, row)
9498
9719
  }));
9499
9720
  const missing = Boolean(value) && !records.loading && !records.error && !rows.some((r) => r.id === value);
9500
- return /* @__PURE__ */ jsxs37("div", { className: "flex flex-col gap-1", children: [
9721
+ return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-1", children: [
9501
9722
  /* @__PURE__ */ jsx40(
9502
9723
  CreatablePicker,
9503
9724
  {
@@ -9517,11 +9738,11 @@ function RecordPicker({ tableId, value, onChange, disabled }) {
9517
9738
  }
9518
9739
 
9519
9740
  // src/DataBindingPicker.tsx
9520
- import { useEffect as useEffect23, useMemo as useMemo13 } from "react";
9741
+ import { useEffect as useEffect24, useMemo as useMemo14 } from "react";
9521
9742
  import { isEntityReferenceConfig } from "@ai-matrx/records";
9522
9743
  import { useFields as useFields4, useTable as useTable3 } from "@ai-matrx/records/react";
9523
9744
  import { BasicInput as BasicInput12, Button as Button19, CreatablePicker as CreatablePicker2, cn as cn26 } from "@ai-matrx/design-system";
9524
- import { jsx as jsx41, jsxs as jsxs38 } from "react/jsx-runtime";
9745
+ import { jsx as jsx41, jsxs as jsxs39 } from "react/jsx-runtime";
9525
9746
  var DATA_BINDING_SHAPES = [
9526
9747
  { value: "collection", label: "The whole table" },
9527
9748
  { value: "reference", label: "One record" },
@@ -9588,7 +9809,7 @@ function DataBindingPicker({ dataSource, userId, binding, onChange, disabled, de
9588
9809
  ...binding.semantic_type === "collection" && defaultRowLimit ? { limit: defaultRowLimit } : {}
9589
9810
  });
9590
9811
  };
9591
- return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-2", children: [
9812
+ return /* @__PURE__ */ jsxs39("div", { className: "flex flex-col gap-2", children: [
9592
9813
  /* @__PURE__ */ jsx41(TablePicker, { dataSource, value: tableId, onChange: selectTable, disabled: Boolean(disabled), tables }),
9593
9814
  /* @__PURE__ */ jsx41(TableScope, { dataSource, userId, tableId, tables, children: tableId && /* @__PURE__ */ jsx41(
9594
9815
  BindingDetails,
@@ -9611,9 +9832,9 @@ function BindingDetails({
9611
9832
  }) {
9612
9833
  const table = useTable3(tableId);
9613
9834
  const fields = useFields4(tableId);
9614
- const fieldList = useMemo13(() => fields.data ?? [], [fields.data]);
9835
+ const fieldList = useMemo14(() => fields.data ?? [], [fields.data]);
9615
9836
  const shape = binding.semantic_type;
9616
- useEffect23(() => {
9837
+ useEffect24(() => {
9617
9838
  if (disabled || shape === "value" || binding.transform || fields.loading || fieldList.length === 0) return;
9618
9839
  onChange({
9619
9840
  ...binding,
@@ -9654,7 +9875,7 @@ function BindingDetails({
9654
9875
  const fieldOptions = fieldList.map((f) => ({ value: f.key, label: fieldName(f) }));
9655
9876
  const template = binding.transform?.template ?? "";
9656
9877
  const setTemplate = (next) => onChange({ ...binding, transform: { join: "\n", ...binding.transform, name: "list", template: next } });
9657
- return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-2", children: [
9878
+ return /* @__PURE__ */ jsxs39("div", { className: "flex flex-col gap-2", children: [
9658
9879
  /* @__PURE__ */ jsx41("div", { className: "flex flex-wrap gap-1", role: "radiogroup", "aria-label": "What to read", children: DATA_BINDING_SHAPES.map((s) => /* @__PURE__ */ jsx41(
9659
9880
  Button19,
9660
9881
  {
@@ -9692,7 +9913,7 @@ function BindingDetails({
9692
9913
  ariaLabel: "Column"
9693
9914
  }
9694
9915
  ),
9695
- shape !== "value" && /* @__PURE__ */ jsxs38("div", { className: "flex flex-col gap-1", children: [
9916
+ shape !== "value" && /* @__PURE__ */ jsxs39("div", { className: "flex flex-col gap-1", children: [
9696
9917
  /* @__PURE__ */ jsx41(
9697
9918
  "textarea",
9698
9919
  {
@@ -9718,7 +9939,7 @@ function BindingDetails({
9718
9939
  p.token
9719
9940
  )) })
9720
9941
  ] }),
9721
- shape === "collection" && /* @__PURE__ */ jsxs38("label", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
9942
+ shape === "collection" && /* @__PURE__ */ jsxs39("label", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
9722
9943
  "Up to",
9723
9944
  /* @__PURE__ */ jsx41(
9724
9945
  BasicInput12,
@@ -9737,7 +9958,7 @@ function BindingDetails({
9737
9958
  ),
9738
9959
  "rows"
9739
9960
  ] }),
9740
- /* @__PURE__ */ jsxs38("div", { className: "flex flex-wrap items-center gap-1", role: "radiogroup", "aria-label": "If nothing is found", children: [
9961
+ /* @__PURE__ */ jsxs39("div", { className: "flex flex-wrap items-center gap-1", role: "radiogroup", "aria-label": "If nothing is found", children: [
9741
9962
  /* @__PURE__ */ jsx41("span", { className: "text-xs text-muted-foreground", children: "If nothing is found" }),
9742
9963
  DATA_BINDING_MISSING.map((m) => /* @__PURE__ */ jsx41(
9743
9964
  Button19,
@@ -9759,7 +9980,7 @@ function BindingDetails({
9759
9980
 
9760
9981
  // src/PickedSummaries.tsx
9761
9982
  import { useFields as useFields5, useRecord, useTable as useTable4 } from "@ai-matrx/records/react";
9762
- import { Fragment as Fragment15, jsx as jsx42, jsxs as jsxs39 } from "react/jsx-runtime";
9983
+ import { Fragment as Fragment15, jsx as jsx42, jsxs as jsxs40 } from "react/jsx-runtime";
9763
9984
  function TableNameText({ dataSource, tableId }) {
9764
9985
  const tables = useTablesAnywhere(dataSource);
9765
9986
  if (!tableId) return /* @__PURE__ */ jsx42(Fragment15, { children: "\u2014" });
@@ -9797,7 +10018,7 @@ function ColumnValuesWords({ tableId, value }) {
9797
10018
  const field = (fields.data ?? []).find((f) => f.key === key);
9798
10019
  if (parts.length) parts.push(/* @__PURE__ */ jsx42("span", { children: ", " }, `${key}-sep`));
9799
10020
  parts.push(
9800
- /* @__PURE__ */ jsxs39("span", { children: [
10021
+ /* @__PURE__ */ jsxs40("span", { children: [
9801
10022
  field ? fieldName(field) : "A removed column",
9802
10023
  " is ",
9803
10024
  field ? renderValue(field, stored, void 0, labels) : "\u2014"
@@ -9835,10 +10056,10 @@ function RecordNameWords({ tableId, recordId }) {
9835
10056
  }
9836
10057
 
9837
10058
  // src/HeldChangeDecision.tsx
9838
- import { useEffect as useEffect24, useState as useState32 } from "react";
10059
+ import { useEffect as useEffect25, useState as useState33 } from "react";
9839
10060
  import { RecordsProvider as RecordsProvider3, useRecordsClient as useRecordsClient10 } from "@ai-matrx/records/react";
9840
10061
  import { Button as Button20 } from "@ai-matrx/design-system";
9841
- import { jsx as jsx43, jsxs as jsxs40 } from "react/jsx-runtime";
10062
+ import { jsx as jsx43, jsxs as jsxs41 } from "react/jsx-runtime";
9842
10063
  function HeldChangeDecision({ dataSource, userId, organizationId, approvalId, onDecided, approveLabel }) {
9843
10064
  return /* @__PURE__ */ jsx43(RecordsProvider3, { config: { dataSource, actor: personActor(userId), organizationId }, children: /* @__PURE__ */ jsx43(Decision, { approvalId, onDecided, approveLabel: approveLabel ?? "Approve" }) });
9844
10065
  }
@@ -9848,10 +10069,10 @@ function Decision({
9848
10069
  approveLabel
9849
10070
  }) {
9850
10071
  const client = useRecordsClient10();
9851
- const [may, setMay] = useState32(null);
9852
- const [busy, setBusy] = useState32(null);
9853
- const [error, setError] = useState32(null);
9854
- useEffect24(() => {
10072
+ const [may, setMay] = useState33(null);
10073
+ const [busy, setBusy] = useState33(null);
10074
+ const [error, setError] = useState33(null);
10075
+ useEffect25(() => {
9855
10076
  let live = true;
9856
10077
  void client.workApprovalMayDecide({ approval_id: approvalId }).then((res) => {
9857
10078
  if (!live) return;
@@ -9874,8 +10095,8 @@ function Decision({
9874
10095
  else setError(res.error);
9875
10096
  };
9876
10097
  if (may === null) return /* @__PURE__ */ jsx43("p", { className: "text-xs text-muted-foreground", children: "Checking who can decide\u2026" });
9877
- return /* @__PURE__ */ jsxs40("div", { className: "flex flex-col gap-1.5", children: [
9878
- may ? /* @__PURE__ */ jsxs40("div", { className: "flex gap-2", children: [
10098
+ return /* @__PURE__ */ jsxs41("div", { className: "flex flex-col gap-1.5", children: [
10099
+ may ? /* @__PURE__ */ jsxs41("div", { className: "flex gap-2", children: [
9879
10100
  /* @__PURE__ */ jsx43(Button20, { type: "button", size: "sm", disabled: busy !== null, onClick: () => void decide(true), children: busy === "approve" ? "Approving\u2026" : approveLabel }),
9880
10101
  /* @__PURE__ */ jsx43(Button20, { type: "button", size: "sm", variant: "outline", disabled: busy !== null, onClick: () => void decide(false), children: busy === "refuse" ? "Refusing\u2026" : "Refuse" })
9881
10102
  ] }) : !error && /* @__PURE__ */ jsx43("p", { className: "text-xs text-muted-foreground", children: "An owner or admin of this organization decides this." }),