@ai-matrx/records-ui 0.95.3 → 0.95.4

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
@@ -5,6 +5,40 @@ import { useEffect as useEffect12, useMemo as useMemo7, useState as useState16 }
5
5
  import { RecordsProvider as RecordsProvider2, useFields, useRecords, useTable } from "@ai-matrx/records/react";
6
6
  import { Button as Button9, CreatablePicker } from "@ai-matrx/design-system";
7
7
 
8
+ // src/askOnce.ts
9
+ var asked = /* @__PURE__ */ new WeakMap();
10
+ function askOnce(client, key, ask, freshMs) {
11
+ let held = asked.get(client);
12
+ if (!held) {
13
+ held = /* @__PURE__ */ new Map();
14
+ asked.set(client, held);
15
+ }
16
+ const now = Date.now();
17
+ const kept = held.get(key);
18
+ if (kept && now - kept.at <= freshMs) return kept.answer;
19
+ const answer = ask().then(
20
+ (result) => {
21
+ if (!result.ok) held.delete(key);
22
+ return result;
23
+ },
24
+ (thrown) => {
25
+ held.delete(key);
26
+ throw thrown;
27
+ }
28
+ );
29
+ held.set(key, { at: now, answer });
30
+ return answer;
31
+ }
32
+ function forgetAsked(client, prefix) {
33
+ const held = asked.get(client);
34
+ if (!held) return;
35
+ for (const key of [...held.keys()]) if (key.startsWith(prefix)) held.delete(key);
36
+ }
37
+ var FIELD_OPTIONS_FRESH_MS = 2e3;
38
+ function fieldOptionsOnce(client, fieldId) {
39
+ return askOnce(client, `field_options:${fieldId}`, () => client.fieldOptions({ field_id: fieldId }), FIELD_OPTIONS_FRESH_MS);
40
+ }
41
+
8
42
  // src/editors.tsx
9
43
  import { useCallback as useCallback4, useEffect as useEffect10, useRef as useRef9, useState as useState14 } from "react";
10
44
  import { allowsOtherValues, choiceValuesOf, coerceTypedAnswer, newerKindOf as newerKindOf4, decideTypedChoice, isTheChosen, optionKey as optionKey2, rankTypedMatches as rankTypedMatches3, readTypedTime as readTypedTime2, typedDateText as typedDateText2, typedTimeText as typedTimeText2 } from "@ai-matrx/records";
@@ -1324,31 +1358,31 @@ var FILES = /* @__PURE__ */ new WeakMap();
1324
1358
  function signatureFilesOf(client, recordId) {
1325
1359
  let held = SOURCES.get(client);
1326
1360
  if (!held) SOURCES.set(client, held = /* @__PURE__ */ new Map());
1327
- let asked2 = held.get(recordId);
1328
- if (!asked2) {
1329
- asked2 = client.recordValuesVersioned({ record_id: recordId }).then((answered) => {
1361
+ let asked3 = held.get(recordId);
1362
+ if (!asked3) {
1363
+ asked3 = client.recordValuesVersioned({ record_id: recordId }).then((answered) => {
1330
1364
  if (!answered.ok) return {};
1331
1365
  return Object.fromEntries(answered.data.map((v) => [v.field_key, signatureFileOf(v.source)]));
1332
1366
  });
1333
- held.set(recordId, asked2);
1367
+ held.set(recordId, asked3);
1334
1368
  }
1335
- return asked2;
1369
+ return asked3;
1336
1370
  }
1337
1371
  function drawingOf(client, fileId) {
1338
1372
  let held = FILES.get(client);
1339
1373
  if (!held) FILES.set(client, held = /* @__PURE__ */ new Map());
1340
- let asked2 = held.get(fileId);
1341
- if (!asked2) {
1342
- asked2 = client.recordRead({ record_id: fileId }).then((answered) => {
1374
+ let asked3 = held.get(fileId);
1375
+ if (!asked3) {
1376
+ asked3 = client.recordRead({ record_id: fileId }).then((answered) => {
1343
1377
  if (!answered.ok) return { src: null, hostFileId: null };
1344
1378
  const doc = answered.data.document ?? {};
1345
1379
  const content = drawnSignatureOf(doc["content"]);
1346
1380
  const hostFileId = typeof doc["file_id"] === "string" && doc["file_id"] !== "" ? doc["file_id"] : null;
1347
1381
  return { src: content, hostFileId };
1348
1382
  });
1349
- held.set(fileId, asked2);
1383
+ held.set(fileId, asked3);
1350
1384
  }
1351
- return asked2;
1385
+ return asked3;
1352
1386
  }
1353
1387
  function DrawnImage({ src, inCell }) {
1354
1388
  return /* @__PURE__ */ jsx6(
@@ -1595,7 +1629,7 @@ function RecordLabelProvider({ children }) {
1595
1629
  const [archivedRefs, setArchivedRefs] = useState5({});
1596
1630
  const [settled, setSettled] = useState5({});
1597
1631
  const [waitingLines, setWaitingLines] = useState5({});
1598
- const asked2 = useRef3(/* @__PURE__ */ new Set());
1632
+ const asked3 = useRef3(/* @__PURE__ */ new Set());
1599
1633
  const chased = useRef3(/* @__PURE__ */ new Set());
1600
1634
  const timers = useRef3(/* @__PURE__ */ new Map());
1601
1635
  const startWaitClock = useCallback((field, target) => {
@@ -1633,12 +1667,12 @@ function RecordLabelProvider({ children }) {
1633
1667
  const want = useCallback(
1634
1668
  (field) => {
1635
1669
  if (!pointsAtRecords(field)) return;
1636
- if (asked2.current.has(field.id)) return;
1637
- asked2.current.add(field.id);
1670
+ if (asked3.current.has(field.id)) return;
1671
+ asked3.current.add(field.id);
1638
1672
  startWaitClock(field, null);
1639
1673
  void (async () => {
1640
1674
  if (field.type === "list") {
1641
- const result = await client.fieldOptions({ field_id: field.id });
1675
+ const result = await fieldOptionsOnce(client, field.id);
1642
1676
  if (result.ok) {
1643
1677
  setNames((current) => {
1644
1678
  const next = { ...current };
@@ -1722,7 +1756,7 @@ function RecordLabelProvider({ children }) {
1722
1756
  const once = choiceKeyName(field.id, id);
1723
1757
  if (settled[field.id] && !rereadFor.current.has(once)) {
1724
1758
  rereadFor.current.add(once);
1725
- asked2.current.delete(field.id);
1759
+ asked3.current.delete(field.id);
1726
1760
  want(field);
1727
1761
  }
1728
1762
  return null;
@@ -2964,15 +2998,15 @@ function TypedDateHelper({ kind, text, onText, label }) {
2964
2998
  // src/choiceNudge.ts
2965
2999
  import { useEffect as useEffect9, useState as useState13 } from "react";
2966
3000
  import { useOptionalRecordsClient as useOptionalRecordsClient6 } from "@ai-matrx/records/react";
2967
- var asked = /* @__PURE__ */ new WeakMap();
3001
+ var asked2 = /* @__PURE__ */ new WeakMap();
2968
3002
  function choiceNudgeOf(client) {
2969
- let answer = asked.get(client);
3003
+ let answer = asked2.get(client);
2970
3004
  if (!answer) {
2971
3005
  answer = Promise.resolve().then(() => client.choiceNudge()).then(
2972
3006
  (result) => result.ok ? result.data : "ask",
2973
3007
  () => "ask"
2974
3008
  );
2975
- asked.set(client, answer);
3009
+ asked2.set(client, answer);
2976
3010
  }
2977
3011
  return answer;
2978
3012
  }
@@ -3120,7 +3154,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
3120
3154
  useEffect10(() => {
3121
3155
  if (!needsChoices || !client) return;
3122
3156
  let cancelled = false;
3123
- void client.fieldOptions({ field_id: field.id }).then((result) => {
3157
+ void fieldOptionsOnce(client, field.id).then((result) => {
3124
3158
  if (!cancelled) setChoices(result.ok ? inTheStoresOrder(result.data ?? []) : []);
3125
3159
  });
3126
3160
  return () => {
@@ -3454,7 +3488,7 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
3454
3488
  useEffect10(() => {
3455
3489
  if (!client) return;
3456
3490
  let cancelled = false;
3457
- void client.fieldOptions({ field_id: field.id }).then((result) => {
3491
+ void fieldOptionsOnce(client, field.id).then((result) => {
3458
3492
  if (cancelled) return;
3459
3493
  if (result.ok) setOptions(inTheStoresOrder(result.data ?? []));
3460
3494
  else setRefusal(result.error);
@@ -3517,7 +3551,10 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
3517
3551
  initialSearch,
3518
3552
  addsChoices,
3519
3553
  allowOther: allowsOtherValues(field),
3520
- onChoicesChanged: () => setReread((n) => n + 1)
3554
+ onChoicesChanged: () => {
3555
+ if (client) forgetAsked(client, `field_options:${field.id}`);
3556
+ setReread((n) => n + 1);
3557
+ }
3521
3558
  }
3522
3559
  );
3523
3560
  }