@ai-matrx/records-ui 0.115.93 → 0.115.95

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 useEffect24, useMemo as useMemo13, useState as useState33 } from "react";
17
+ import { useEffect as useEffect25, useMemo as useMemo13, useState as useState33 } 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
 
@@ -872,7 +872,7 @@ function AddChoicesInline({ field, onAdded, disabled = false }) {
872
872
  }
873
873
 
874
874
  // src/editors.tsx
875
- import { useCallback as useCallback7, useEffect as useEffect23, useLayoutEffect as useLayoutEffect2, useRef as useRef17, useState as useState32 } from "react";
875
+ import { useCallback as useCallback7, useEffect as useEffect24, useLayoutEffect as useLayoutEffect2, useRef as useRef18, useState as useState32 } 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
877
  import { useOptionalRecordsClient as useOptionalRecordsClient12 } from "@ai-matrx/records/react";
878
878
  import {
@@ -2045,7 +2045,7 @@ function RelationPicker({ field, value, onChange, disabled, id, className, allow
2045
2045
  }
2046
2046
 
2047
2047
  // src/buttonCell.tsx
2048
- import { useState as useState27 } from "react";
2048
+ import { useEffect as useEffect21, useRef as useRef15, useState as useState27 } 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";
@@ -8220,6 +8220,15 @@ function buttonPressWords(label, pressed) {
8220
8220
  const status = pressed.status ?? "ran";
8221
8221
  return [`${pressed.automation ?? label}: ${status}.`, pressed.says].filter(Boolean).join(" ");
8222
8222
  }
8223
+ var POLL_EVERY_MS = 1200;
8224
+ var POLL_FOR_MS = 12e4;
8225
+ function runAnswerWords(label, run) {
8226
+ const steps = run.steps ?? [];
8227
+ const failedStep = [...steps].reverse().find((s) => s.status === "failed");
8228
+ if (run.status === "failed") return [failedStep?.output_text ?? failedStep?.says, run.says].filter((t, i, all) => t && all.indexOf(t) === i).join(" ") || `${label} failed.`;
8229
+ const answered = [...steps].reverse().find((s) => s.output_text && s.output_text.trim() !== "");
8230
+ return answered?.output_text?.trim() || run.says || `${label} ran.`;
8231
+ }
8223
8232
  var stop = (event) => event.stopPropagation();
8224
8233
  function ButtonValue({ field, recordId, inCell }) {
8225
8234
  const client = useOptionalRecordsClient10();
@@ -8227,6 +8236,8 @@ function ButtonValue({ field, recordId, inCell }) {
8227
8236
  const [busy, setBusy] = useState27(false);
8228
8237
  const [said2, setSaid] = useState27(null);
8229
8238
  const [settingUp, setSettingUp] = useState27(false);
8239
+ const waitingOn = useRef15(0);
8240
+ useEffect21(() => () => void (waitingOn.current += 1), []);
8230
8241
  if (!b) return null;
8231
8242
  const color = isStyleColor2(b.color) ? CHOICE_CHIP_CLASS2[b.color] : NEUTRAL_CHIP_CLASS2;
8232
8243
  const needs = buttonNeeds2(b);
@@ -8243,60 +8254,100 @@ function ButtonValue({ field, recordId, inCell }) {
8243
8254
  const opened = typeof window !== "undefined" ? openOutbound(pressed.url, "_blank", "noopener") : null;
8244
8255
  return setSaid({ kind: "ran", says: opened ? `${b.label} opened.` : `${b.label} is ready:`, link: pressed.url });
8245
8256
  }
8246
- setSaid({ kind: "ran", says: buttonPressWords(b.label, pressed) });
8257
+ const words = buttonPressWords(b.label, pressed);
8258
+ if (pressed.do === "run_automation" && pressed.status === "waiting" && pressed.run_id && b.automation_id) {
8259
+ const mine = waitingOn.current += 1;
8260
+ setBusy(true);
8261
+ setSaid({ kind: "waiting", says: `${b.label} is running` });
8262
+ const until = Date.now() + POLL_FOR_MS;
8263
+ while (waitingOn.current === mine) {
8264
+ await new Promise((r) => setTimeout(r, POLL_EVERY_MS));
8265
+ if (waitingOn.current !== mine) return;
8266
+ const runs = await client.automationRuns({ automation_id: b.automation_id, limit: 10 });
8267
+ if (!runs.ok) {
8268
+ setBusy(false);
8269
+ return setSaid({ kind: "refused", error: runs.error });
8270
+ }
8271
+ const run = runs.data.runs.find((r) => r.run_id === pressed.run_id);
8272
+ if (run && run.status !== "waiting") {
8273
+ setBusy(false);
8274
+ return setSaid(run.status === "ran" ? { kind: "ran", says: runAnswerWords(b.label, run) } : { kind: "failed", says: runAnswerWords(b.label, run) });
8275
+ }
8276
+ if (Date.now() > until) {
8277
+ setBusy(false);
8278
+ return setSaid({ kind: "ran", says: `${b.label} is still running. Its answer will be in the automation's runs.` });
8279
+ }
8280
+ }
8281
+ return;
8282
+ }
8283
+ setSaid({ kind: "ran", says: words });
8247
8284
  };
8248
8285
  return /* @__PURE__ */ jsxs33(Fragment12, { children: [
8249
- /* @__PURE__ */ jsxs33(Popover4, { open: said2 !== null, onOpenChange: (open) => open ? null : setSaid(null), children: [
8250
- /* @__PURE__ */ jsx35(PopoverTrigger4, { asChild: true, children: /* @__PURE__ */ jsx35(
8251
- Button16,
8252
- {
8253
- type: "button",
8254
- size: "xs",
8255
- variant: "outline",
8256
- "data-records-button": field.key,
8257
- "data-records-button-unset": needs ? "" : void 0,
8258
- "aria-busy": busy || void 0,
8259
- disabled: busy,
8260
- className: cn23("max-w-full gap-1 border px-2 font-medium", inCell ? "h-5" : "h-6", color, needs && "border-dashed opacity-80"),
8261
- onPointerDown: stop,
8262
- onDoubleClick: stop,
8263
- onClick: (event) => {
8264
- event.stopPropagation();
8265
- event.preventDefault();
8266
- void press();
8267
- },
8268
- children: /* @__PURE__ */ jsx35("span", { className: "truncate", children: b.label })
8269
- }
8270
- ) }),
8271
- /* @__PURE__ */ jsxs33(PopoverContent4, { className: "w-72 space-y-2 p-3 text-sm", onClick: stop, onPointerDown: stop, "data-records-button-said": said2?.kind, children: [
8272
- said2?.kind === "refused" ? /* @__PURE__ */ jsx35(RefusalLine, { error: said2.error }) : null,
8273
- said2?.kind === "public" ? /* @__PURE__ */ jsx35("p", { children: "Buttons run for signed-in people." }) : null,
8274
- said2?.kind === "ran" ? /* @__PURE__ */ jsxs33("p", { className: "break-words", children: [
8275
- said2.says,
8276
- " ",
8277
- said2.link ? /* @__PURE__ */ jsx35(OutboundLink6, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
8278
- ] }) : null,
8279
- said2?.kind === "needs" ? /* @__PURE__ */ jsxs33(Fragment12, { children: [
8280
- /* @__PURE__ */ jsx35("p", { children: said2.says }),
8281
- tableId ? /* @__PURE__ */ jsxs33(
8286
+ /* @__PURE__ */ jsxs33(
8287
+ Popover4,
8288
+ {
8289
+ open: said2 !== null,
8290
+ onOpenChange: (open) => {
8291
+ if (open) return;
8292
+ waitingOn.current += 1;
8293
+ setBusy(false);
8294
+ setSaid(null);
8295
+ },
8296
+ children: [
8297
+ /* @__PURE__ */ jsx35(PopoverTrigger4, { asChild: true, children: /* @__PURE__ */ jsx35(
8282
8298
  Button16,
8283
8299
  {
8284
8300
  type: "button",
8285
- size: "sm",
8286
- "data-records-button-set-up": "",
8287
- onClick: () => {
8288
- setSaid(null);
8289
- setSettingUp(true);
8301
+ size: "xs",
8302
+ variant: "outline",
8303
+ "data-records-button": field.key,
8304
+ "data-records-button-unset": needs ? "" : void 0,
8305
+ "aria-busy": busy || void 0,
8306
+ disabled: busy,
8307
+ className: cn23("max-w-full gap-1 border px-2 font-medium", inCell ? "h-5" : "h-6", color, needs && "border-dashed opacity-80"),
8308
+ onPointerDown: stop,
8309
+ onDoubleClick: stop,
8310
+ onClick: (event) => {
8311
+ event.stopPropagation();
8312
+ event.preventDefault();
8313
+ void press();
8290
8314
  },
8291
- children: [
8292
- "Set up ",
8293
- b.label
8294
- ]
8315
+ children: /* @__PURE__ */ jsx35("span", { className: "truncate", children: b.label })
8295
8316
  }
8296
- ) : null
8297
- ] }) : null
8298
- ] })
8299
- ] }),
8317
+ ) }),
8318
+ /* @__PURE__ */ jsxs33(PopoverContent4, { className: "w-72 space-y-2 p-3 text-sm", onClick: stop, onPointerDown: stop, "data-records-button-said": said2?.kind, children: [
8319
+ said2?.kind === "refused" ? /* @__PURE__ */ jsx35(RefusalLine, { error: said2.error }) : null,
8320
+ said2?.kind === "waiting" ? /* @__PURE__ */ jsx35("p", { className: "matrx-shimmer rounded px-1 py-0.5", role: "status", "aria-live": "polite", children: said2.says }) : null,
8321
+ said2?.kind === "failed" ? /* @__PURE__ */ jsx35("p", { className: "break-words text-destructive", role: "alert", children: said2.says }) : null,
8322
+ said2?.kind === "public" ? /* @__PURE__ */ jsx35("p", { children: "Buttons run for signed-in people." }) : null,
8323
+ said2?.kind === "ran" ? /* @__PURE__ */ jsxs33("p", { className: "break-words", children: [
8324
+ said2.says,
8325
+ " ",
8326
+ said2.link ? /* @__PURE__ */ jsx35(OutboundLink6, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
8327
+ ] }) : null,
8328
+ said2?.kind === "needs" ? /* @__PURE__ */ jsxs33(Fragment12, { children: [
8329
+ /* @__PURE__ */ jsx35("p", { children: said2.says }),
8330
+ tableId ? /* @__PURE__ */ jsxs33(
8331
+ Button16,
8332
+ {
8333
+ type: "button",
8334
+ size: "sm",
8335
+ "data-records-button-set-up": "",
8336
+ onClick: () => {
8337
+ setSaid(null);
8338
+ setSettingUp(true);
8339
+ },
8340
+ children: [
8341
+ "Set up ",
8342
+ b.label
8343
+ ]
8344
+ }
8345
+ ) : null
8346
+ ] }) : null
8347
+ ] })
8348
+ ]
8349
+ }
8350
+ ),
8300
8351
  settingUp && tableId ? /* @__PURE__ */ jsx35(Dialog2, { open: true, onOpenChange: (open) => open ? null : setSettingUp(false), children: /* @__PURE__ */ jsxs33(DialogContent2, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", onClick: stop, onPointerDown: stop, children: [
8301
8352
  /* @__PURE__ */ jsxs33(DialogHeader2, { children: [
8302
8353
  /* @__PURE__ */ jsx35(DialogTitle2, { children: `Column settings \xB7 ${fieldName(field)}` }),
@@ -8308,7 +8359,7 @@ function ButtonValue({ field, recordId, inCell }) {
8308
8359
  }
8309
8360
 
8310
8361
  // src/FloatingRefusal.tsx
8311
- import { useLayoutEffect, useRef as useRef15, useState as useState28 } from "react";
8362
+ import { useLayoutEffect, useRef as useRef16, useState as useState28 } from "react";
8312
8363
  import { createPortal } from "react-dom";
8313
8364
  import { Fragment as Fragment13, jsx as jsx36, jsxs as jsxs34 } from "react/jsx-runtime";
8314
8365
  var GAP = 4;
@@ -8326,8 +8377,8 @@ function placeFor(anchor, note) {
8326
8377
  return { position: "fixed", top: a.top + (a.height - height) / 2, left: Math.max(a.left, a.right - width - 8) };
8327
8378
  }
8328
8379
  function FloatingRefusal({ text, why }) {
8329
- const spot = useRef15(null);
8330
- const note = useRef15(null);
8380
+ const spot = useRef16(null);
8381
+ const note = useRef16(null);
8331
8382
  const [style, setStyle] = useState28(null);
8332
8383
  const [floating, setFloating] = useState28(false);
8333
8384
  useLayoutEffect(() => {
@@ -8372,7 +8423,7 @@ function FloatingRefusal({ text, why }) {
8372
8423
  }
8373
8424
 
8374
8425
  // src/formatControls.tsx
8375
- import { useEffect as useEffect21, useRef as useRef16, useState as useState29 } from "react";
8426
+ import { useEffect as useEffect22, useRef as useRef17, useState as useState29 } from "react";
8376
8427
  import { BasicInput as BasicInput10, BasicTextarea as BasicTextarea3 } from "@ai-matrx/design-system";
8377
8428
  import { getFieldFormat as getFieldFormat4, parseFieldInput } from "@ai-matrx/design-system/field-formats";
8378
8429
  import { jsx as jsx37, jsxs as jsxs35 } from "react/jsx-runtime";
@@ -8393,8 +8444,8 @@ function keptValue(format, raw) {
8393
8444
  }
8394
8445
  function NumberInFormat({ format, value, onChange, disabled, id }) {
8395
8446
  const [text, setText] = useState29(() => typedText(format, value));
8396
- const lastSent = useRef16(void 0);
8397
- useEffect21(() => {
8447
+ const lastSent = useRef17(void 0);
8448
+ useEffect22(() => {
8398
8449
  if (value === lastSent.current) return;
8399
8450
  setText(typedText(format, value));
8400
8451
  }, [value, format]);
@@ -8629,7 +8680,7 @@ function TypedDateHelper({
8629
8680
  }
8630
8681
 
8631
8682
  // src/choiceNudge.ts
8632
- import { useEffect as useEffect22, useState as useState31 } from "react";
8683
+ import { useEffect as useEffect23, useState as useState31 } from "react";
8633
8684
  import { useOptionalRecordsClient as useOptionalRecordsClient11 } from "@ai-matrx/records/react";
8634
8685
  var asked2 = /* @__PURE__ */ new WeakMap();
8635
8686
  function choiceNudgeOf(client) {
@@ -8646,7 +8697,7 @@ function choiceNudgeOf(client) {
8646
8697
  function useChoiceNudge(enabled = true) {
8647
8698
  const client = useOptionalRecordsClient11();
8648
8699
  const [nudge, setNudge] = useState31(null);
8649
- useEffect22(() => {
8700
+ useEffect23(() => {
8650
8701
  if (!enabled || !client) return;
8651
8702
  let live = true;
8652
8703
  void choiceNudgeOf(client).then((answer) => {
@@ -8797,7 +8848,7 @@ function openingText(field, value) {
8797
8848
  return format ? typedText(format, value) : String(value);
8798
8849
  }
8799
8850
  function ReadsAsNote({ typed, always, children }) {
8800
- const note = useRef17(null);
8851
+ const note = useRef18(null);
8801
8852
  const [repeats, setRepeats] = useState32(false);
8802
8853
  useLayoutEffect2(() => {
8803
8854
  if (always) return;
@@ -8813,7 +8864,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
8813
8864
  const needsChoices = kind === "select" || kind === "multi_select";
8814
8865
  const nudge = useChoiceNudge(needsChoices);
8815
8866
  const [choices, setChoices] = useState32(null);
8816
- useEffect23(() => {
8867
+ useEffect24(() => {
8817
8868
  if (!needsChoices || !client) return;
8818
8869
  let cancelled = false;
8819
8870
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -8823,7 +8874,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
8823
8874
  cancelled = true;
8824
8875
  };
8825
8876
  }, [client, field.id, needsChoices]);
8826
- useEffect23(() => {
8877
+ useEffect24(() => {
8827
8878
  if (choices && nudge && value.judged === null) onChange({ ...value, judged: judgeTyped(field, value.text, choices, nudge) });
8828
8879
  }, [choices, nudge, value, field, onChange]);
8829
8880
  const judged = value.judged;
@@ -9022,8 +9073,8 @@ function TypedWordsControl({ field, value, onChange, disabled, id }) {
9022
9073
  const [text, setText] = useState32(() => openingText(field, value));
9023
9074
  const [refusal, setRefusal] = useState32(null);
9024
9075
  const [why, setWhy] = useState32(void 0);
9025
- const sent = useRef17(value);
9026
- useEffect23(() => {
9076
+ const sent = useRef18(value);
9077
+ useEffect24(() => {
9027
9078
  if (value === sent.current) return;
9028
9079
  sent.current = value;
9029
9080
  setText(openingText(field, value));
@@ -9169,7 +9220,7 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
9169
9220
  const [options, setOptions] = useState32(null);
9170
9221
  const [refusal, setRefusal] = useState32(null);
9171
9222
  const [reread, setReread] = useState32(0);
9172
- useEffect23(() => {
9223
+ useEffect24(() => {
9173
9224
  if (!client) return;
9174
9225
  let cancelled = false;
9175
9226
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -9336,7 +9387,7 @@ function OpenChoicePicker({
9336
9387
  const client = useOptionalRecordsClient12();
9337
9388
  const nudge = useChoiceNudge();
9338
9389
  const [open, setOpenState] = useState32(autoOpen === true);
9339
- const onCloseRef = useRef17(onClose);
9390
+ const onCloseRef = useRef18(onClose);
9340
9391
  onCloseRef.current = onClose;
9341
9392
  const setOpen = useCallback7((next) => {
9342
9393
  setOpenState(next);
@@ -9604,7 +9655,7 @@ function ChoiceAnswer({
9604
9655
  }
9605
9656
 
9606
9657
  // src/RecordsMount.tsx
9607
- import { useRef as useRef18 } from "react";
9658
+ import { useRef as useRef19 } from "react";
9608
9659
 
9609
9660
  // src/dataSource.ts
9610
9661
  import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
@@ -9651,7 +9702,7 @@ function readTablesAnywhere(dataSource) {
9651
9702
  }
9652
9703
  function useTablesAnywhere(dataSource) {
9653
9704
  const [state2, setState] = useState33({ loading: true, error: null, rows: [] });
9654
- useEffect24(() => {
9705
+ useEffect25(() => {
9655
9706
  let live = true;
9656
9707
  void readTablesAnywhere(dataSource).then((result) => {
9657
9708
  if (live) setState(result);
@@ -9844,7 +9895,7 @@ function RecordPicker({ tableId, value, onChange, disabled }) {
9844
9895
  }
9845
9896
 
9846
9897
  // src/DataBindingPicker.tsx
9847
- import { useEffect as useEffect25, useMemo as useMemo14 } from "react";
9898
+ import { useEffect as useEffect26, useMemo as useMemo14 } from "react";
9848
9899
  import { isEntityReferenceConfig } from "@ai-matrx/records";
9849
9900
  import { useFields as useFields4, useTable as useTable3 } from "@ai-matrx/records/react";
9850
9901
  import { BasicInput as BasicInput12, Button as Button19, CreatablePicker as CreatablePicker2, cn as cn26 } from "@ai-matrx/design-system";
@@ -9940,7 +9991,7 @@ function BindingDetails({
9940
9991
  const fields = useFields4(tableId);
9941
9992
  const fieldList = useMemo14(() => fields.data ?? [], [fields.data]);
9942
9993
  const shape = binding.semantic_type;
9943
- useEffect25(() => {
9994
+ useEffect26(() => {
9944
9995
  if (disabled || shape === "value" || binding.transform || fields.loading || fieldList.length === 0) return;
9945
9996
  onChange({
9946
9997
  ...binding,
@@ -10162,7 +10213,7 @@ function RecordNameWords({ tableId, recordId }) {
10162
10213
  }
10163
10214
 
10164
10215
  // src/HeldChangeDecision.tsx
10165
- import { useEffect as useEffect26, useState as useState34 } from "react";
10216
+ import { useEffect as useEffect27, useState as useState34 } from "react";
10166
10217
  import { RecordsProvider as RecordsProvider3, useRecordsClient as useRecordsClient10 } from "@ai-matrx/records/react";
10167
10218
  import { Button as Button20 } from "@ai-matrx/design-system";
10168
10219
  import { jsx as jsx44, jsxs as jsxs42 } from "react/jsx-runtime";
@@ -10178,7 +10229,7 @@ function Decision({
10178
10229
  const [may, setMay] = useState34(null);
10179
10230
  const [busy, setBusy] = useState34(null);
10180
10231
  const [error, setError] = useState34(null);
10181
- useEffect26(() => {
10232
+ useEffect27(() => {
10182
10233
  let live = true;
10183
10234
  void client.workApprovalMayDecide({ approval_id: approvalId }).then((res) => {
10184
10235
  if (!live) return;