@ai-matrx/records-ui 0.115.94 → 0.115.96

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,76 +8236,121 @@ 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);
8233
8244
  const tableId = field.entity_definition_id;
8234
8245
  const press = async () => {
8235
8246
  if (!client || !recordId) return setSaid({ kind: "public" });
8236
- if (needs) return setSaid({ kind: "needs", says: needs });
8247
+ if (needs && b.do) return setSaid({ kind: "needs", says: needs });
8237
8248
  setBusy(true);
8238
8249
  const answered = await client.buttonPress({ record_id: recordId, field_id: field.id });
8239
8250
  setBusy(false);
8240
- if (!answered.ok) return setSaid({ kind: "refused", error: answered.error });
8251
+ if (!answered.ok) {
8252
+ if (needs && (answered.error.sqlstate === "22023" || answered.error.code === "invalid_argument")) return setSaid({ kind: "needs", says: needs });
8253
+ return setSaid({ kind: "refused", error: answered.error });
8254
+ }
8241
8255
  const pressed = answered.data;
8242
8256
  if (pressed.do === "open_url") {
8243
8257
  const opened = typeof window !== "undefined" ? openOutbound(pressed.url, "_blank", "noopener") : null;
8244
8258
  return setSaid({ kind: "ran", says: opened ? `${b.label} opened.` : `${b.label} is ready:`, link: pressed.url });
8245
8259
  }
8246
- setSaid({ kind: "ran", says: buttonPressWords(b.label, pressed) });
8260
+ const words = buttonPressWords(b.label, pressed);
8261
+ if (pressed.do === "run_automation" && pressed.status === "waiting" && pressed.run_id && b.automation_id) {
8262
+ const mine = waitingOn.current += 1;
8263
+ setBusy(true);
8264
+ setSaid({ kind: "waiting", says: `${b.label} is running` });
8265
+ const until = Date.now() + POLL_FOR_MS;
8266
+ while (waitingOn.current === mine) {
8267
+ await new Promise((r) => setTimeout(r, POLL_EVERY_MS));
8268
+ if (waitingOn.current !== mine) return;
8269
+ const runs = await client.automationRuns({ automation_id: b.automation_id, limit: 10 });
8270
+ if (!runs.ok) {
8271
+ setBusy(false);
8272
+ return setSaid({ kind: "refused", error: runs.error });
8273
+ }
8274
+ const run = runs.data.runs.find((r) => r.run_id === pressed.run_id);
8275
+ if (run && run.status !== "waiting") {
8276
+ setBusy(false);
8277
+ return setSaid(run.status === "ran" ? { kind: "ran", says: runAnswerWords(b.label, run) } : { kind: "failed", says: runAnswerWords(b.label, run) });
8278
+ }
8279
+ if (Date.now() > until) {
8280
+ setBusy(false);
8281
+ return setSaid({ kind: "ran", says: `${b.label} is still running. Its answer will be in the automation's runs.` });
8282
+ }
8283
+ }
8284
+ return;
8285
+ }
8286
+ setSaid({ kind: "ran", says: words });
8247
8287
  };
8248
8288
  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(
8289
+ /* @__PURE__ */ jsxs33(
8290
+ Popover4,
8291
+ {
8292
+ open: said2 !== null,
8293
+ onOpenChange: (open) => {
8294
+ if (open) return;
8295
+ waitingOn.current += 1;
8296
+ setBusy(false);
8297
+ setSaid(null);
8298
+ },
8299
+ children: [
8300
+ /* @__PURE__ */ jsx35(PopoverTrigger4, { asChild: true, children: /* @__PURE__ */ jsx35(
8282
8301
  Button16,
8283
8302
  {
8284
8303
  type: "button",
8285
- size: "sm",
8286
- "data-records-button-set-up": "",
8287
- onClick: () => {
8288
- setSaid(null);
8289
- setSettingUp(true);
8304
+ size: "xs",
8305
+ variant: "outline",
8306
+ "data-records-button": field.key,
8307
+ "data-records-button-unset": needs ? "" : void 0,
8308
+ "aria-busy": busy || void 0,
8309
+ disabled: busy,
8310
+ className: cn23("max-w-full gap-1 border px-2 font-medium", inCell ? "h-5" : "h-6", color, needs && "border-dashed opacity-80"),
8311
+ onPointerDown: stop,
8312
+ onDoubleClick: stop,
8313
+ onClick: (event) => {
8314
+ event.stopPropagation();
8315
+ event.preventDefault();
8316
+ void press();
8290
8317
  },
8291
- children: [
8292
- "Set up ",
8293
- b.label
8294
- ]
8318
+ children: /* @__PURE__ */ jsx35("span", { className: "truncate", children: b.label })
8295
8319
  }
8296
- ) : null
8297
- ] }) : null
8298
- ] })
8299
- ] }),
8320
+ ) }),
8321
+ /* @__PURE__ */ jsxs33(PopoverContent4, { className: "w-72 space-y-2 p-3 text-sm", onClick: stop, onPointerDown: stop, "data-records-button-said": said2?.kind, children: [
8322
+ said2?.kind === "refused" ? /* @__PURE__ */ jsx35(RefusalLine, { error: said2.error }) : null,
8323
+ said2?.kind === "waiting" ? /* @__PURE__ */ jsx35("p", { className: "matrx-shimmer rounded px-1 py-0.5", role: "status", "aria-live": "polite", children: said2.says }) : null,
8324
+ said2?.kind === "failed" ? /* @__PURE__ */ jsx35("p", { className: "break-words text-destructive", role: "alert", children: said2.says }) : null,
8325
+ said2?.kind === "public" ? /* @__PURE__ */ jsx35("p", { children: "Buttons run for signed-in people." }) : null,
8326
+ said2?.kind === "ran" ? /* @__PURE__ */ jsxs33("p", { className: "break-words", children: [
8327
+ said2.says,
8328
+ " ",
8329
+ said2.link ? /* @__PURE__ */ jsx35(OutboundLink6, { href: said2.link, className: "text-primary underline", children: said2.link }) : null
8330
+ ] }) : null,
8331
+ said2?.kind === "needs" ? /* @__PURE__ */ jsxs33(Fragment12, { children: [
8332
+ /* @__PURE__ */ jsx35("p", { children: said2.says }),
8333
+ tableId ? /* @__PURE__ */ jsxs33(
8334
+ Button16,
8335
+ {
8336
+ type: "button",
8337
+ size: "sm",
8338
+ "data-records-button-set-up": "",
8339
+ onClick: () => {
8340
+ setSaid(null);
8341
+ setSettingUp(true);
8342
+ },
8343
+ children: [
8344
+ "Set up ",
8345
+ b.label
8346
+ ]
8347
+ }
8348
+ ) : null
8349
+ ] }) : null
8350
+ ] })
8351
+ ]
8352
+ }
8353
+ ),
8300
8354
  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
8355
  /* @__PURE__ */ jsxs33(DialogHeader2, { children: [
8302
8356
  /* @__PURE__ */ jsx35(DialogTitle2, { children: `Column settings \xB7 ${fieldName(field)}` }),
@@ -8308,7 +8362,7 @@ function ButtonValue({ field, recordId, inCell }) {
8308
8362
  }
8309
8363
 
8310
8364
  // src/FloatingRefusal.tsx
8311
- import { useLayoutEffect, useRef as useRef15, useState as useState28 } from "react";
8365
+ import { useLayoutEffect, useRef as useRef16, useState as useState28 } from "react";
8312
8366
  import { createPortal } from "react-dom";
8313
8367
  import { Fragment as Fragment13, jsx as jsx36, jsxs as jsxs34 } from "react/jsx-runtime";
8314
8368
  var GAP = 4;
@@ -8326,8 +8380,8 @@ function placeFor(anchor, note) {
8326
8380
  return { position: "fixed", top: a.top + (a.height - height) / 2, left: Math.max(a.left, a.right - width - 8) };
8327
8381
  }
8328
8382
  function FloatingRefusal({ text, why }) {
8329
- const spot = useRef15(null);
8330
- const note = useRef15(null);
8383
+ const spot = useRef16(null);
8384
+ const note = useRef16(null);
8331
8385
  const [style, setStyle] = useState28(null);
8332
8386
  const [floating, setFloating] = useState28(false);
8333
8387
  useLayoutEffect(() => {
@@ -8372,7 +8426,7 @@ function FloatingRefusal({ text, why }) {
8372
8426
  }
8373
8427
 
8374
8428
  // src/formatControls.tsx
8375
- import { useEffect as useEffect21, useRef as useRef16, useState as useState29 } from "react";
8429
+ import { useEffect as useEffect22, useRef as useRef17, useState as useState29 } from "react";
8376
8430
  import { BasicInput as BasicInput10, BasicTextarea as BasicTextarea3 } from "@ai-matrx/design-system";
8377
8431
  import { getFieldFormat as getFieldFormat4, parseFieldInput } from "@ai-matrx/design-system/field-formats";
8378
8432
  import { jsx as jsx37, jsxs as jsxs35 } from "react/jsx-runtime";
@@ -8393,8 +8447,8 @@ function keptValue(format, raw) {
8393
8447
  }
8394
8448
  function NumberInFormat({ format, value, onChange, disabled, id }) {
8395
8449
  const [text, setText] = useState29(() => typedText(format, value));
8396
- const lastSent = useRef16(void 0);
8397
- useEffect21(() => {
8450
+ const lastSent = useRef17(void 0);
8451
+ useEffect22(() => {
8398
8452
  if (value === lastSent.current) return;
8399
8453
  setText(typedText(format, value));
8400
8454
  }, [value, format]);
@@ -8629,7 +8683,7 @@ function TypedDateHelper({
8629
8683
  }
8630
8684
 
8631
8685
  // src/choiceNudge.ts
8632
- import { useEffect as useEffect22, useState as useState31 } from "react";
8686
+ import { useEffect as useEffect23, useState as useState31 } from "react";
8633
8687
  import { useOptionalRecordsClient as useOptionalRecordsClient11 } from "@ai-matrx/records/react";
8634
8688
  var asked2 = /* @__PURE__ */ new WeakMap();
8635
8689
  function choiceNudgeOf(client) {
@@ -8646,7 +8700,7 @@ function choiceNudgeOf(client) {
8646
8700
  function useChoiceNudge(enabled = true) {
8647
8701
  const client = useOptionalRecordsClient11();
8648
8702
  const [nudge, setNudge] = useState31(null);
8649
- useEffect22(() => {
8703
+ useEffect23(() => {
8650
8704
  if (!enabled || !client) return;
8651
8705
  let live = true;
8652
8706
  void choiceNudgeOf(client).then((answer) => {
@@ -8797,7 +8851,7 @@ function openingText(field, value) {
8797
8851
  return format ? typedText(format, value) : String(value);
8798
8852
  }
8799
8853
  function ReadsAsNote({ typed, always, children }) {
8800
- const note = useRef17(null);
8854
+ const note = useRef18(null);
8801
8855
  const [repeats, setRepeats] = useState32(false);
8802
8856
  useLayoutEffect2(() => {
8803
8857
  if (always) return;
@@ -8813,7 +8867,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
8813
8867
  const needsChoices = kind === "select" || kind === "multi_select";
8814
8868
  const nudge = useChoiceNudge(needsChoices);
8815
8869
  const [choices, setChoices] = useState32(null);
8816
- useEffect23(() => {
8870
+ useEffect24(() => {
8817
8871
  if (!needsChoices || !client) return;
8818
8872
  let cancelled = false;
8819
8873
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -8823,7 +8877,7 @@ function TypedTextControl({ field, value, onChange, disabled, id, onCommit, onCa
8823
8877
  cancelled = true;
8824
8878
  };
8825
8879
  }, [client, field.id, needsChoices]);
8826
- useEffect23(() => {
8880
+ useEffect24(() => {
8827
8881
  if (choices && nudge && value.judged === null) onChange({ ...value, judged: judgeTyped(field, value.text, choices, nudge) });
8828
8882
  }, [choices, nudge, value, field, onChange]);
8829
8883
  const judged = value.judged;
@@ -9022,8 +9076,8 @@ function TypedWordsControl({ field, value, onChange, disabled, id }) {
9022
9076
  const [text, setText] = useState32(() => openingText(field, value));
9023
9077
  const [refusal, setRefusal] = useState32(null);
9024
9078
  const [why, setWhy] = useState32(void 0);
9025
- const sent = useRef17(value);
9026
- useEffect23(() => {
9079
+ const sent = useRef18(value);
9080
+ useEffect24(() => {
9027
9081
  if (value === sent.current) return;
9028
9082
  sent.current = value;
9029
9083
  setText(openingText(field, value));
@@ -9169,7 +9223,7 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
9169
9223
  const [options, setOptions] = useState32(null);
9170
9224
  const [refusal, setRefusal] = useState32(null);
9171
9225
  const [reread, setReread] = useState32(0);
9172
- useEffect23(() => {
9226
+ useEffect24(() => {
9173
9227
  if (!client) return;
9174
9228
  let cancelled = false;
9175
9229
  void (0, askOnce_exports.fieldOptionsOnce)(client, field.id).then((result) => {
@@ -9336,7 +9390,7 @@ function OpenChoicePicker({
9336
9390
  const client = useOptionalRecordsClient12();
9337
9391
  const nudge = useChoiceNudge();
9338
9392
  const [open, setOpenState] = useState32(autoOpen === true);
9339
- const onCloseRef = useRef17(onClose);
9393
+ const onCloseRef = useRef18(onClose);
9340
9394
  onCloseRef.current = onClose;
9341
9395
  const setOpen = useCallback7((next) => {
9342
9396
  setOpenState(next);
@@ -9604,7 +9658,7 @@ function ChoiceAnswer({
9604
9658
  }
9605
9659
 
9606
9660
  // src/RecordsMount.tsx
9607
- import { useRef as useRef18 } from "react";
9661
+ import { useRef as useRef19 } from "react";
9608
9662
 
9609
9663
  // src/dataSource.ts
9610
9664
  import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
@@ -9651,7 +9705,7 @@ function readTablesAnywhere(dataSource) {
9651
9705
  }
9652
9706
  function useTablesAnywhere(dataSource) {
9653
9707
  const [state2, setState] = useState33({ loading: true, error: null, rows: [] });
9654
- useEffect24(() => {
9708
+ useEffect25(() => {
9655
9709
  let live = true;
9656
9710
  void readTablesAnywhere(dataSource).then((result) => {
9657
9711
  if (live) setState(result);
@@ -9844,7 +9898,7 @@ function RecordPicker({ tableId, value, onChange, disabled }) {
9844
9898
  }
9845
9899
 
9846
9900
  // src/DataBindingPicker.tsx
9847
- import { useEffect as useEffect25, useMemo as useMemo14 } from "react";
9901
+ import { useEffect as useEffect26, useMemo as useMemo14 } from "react";
9848
9902
  import { isEntityReferenceConfig } from "@ai-matrx/records";
9849
9903
  import { useFields as useFields4, useTable as useTable3 } from "@ai-matrx/records/react";
9850
9904
  import { BasicInput as BasicInput12, Button as Button19, CreatablePicker as CreatablePicker2, cn as cn26 } from "@ai-matrx/design-system";
@@ -9940,7 +9994,7 @@ function BindingDetails({
9940
9994
  const fields = useFields4(tableId);
9941
9995
  const fieldList = useMemo14(() => fields.data ?? [], [fields.data]);
9942
9996
  const shape = binding.semantic_type;
9943
- useEffect25(() => {
9997
+ useEffect26(() => {
9944
9998
  if (disabled || shape === "value" || binding.transform || fields.loading || fieldList.length === 0) return;
9945
9999
  onChange({
9946
10000
  ...binding,
@@ -10162,7 +10216,7 @@ function RecordNameWords({ tableId, recordId }) {
10162
10216
  }
10163
10217
 
10164
10218
  // src/HeldChangeDecision.tsx
10165
- import { useEffect as useEffect26, useState as useState34 } from "react";
10219
+ import { useEffect as useEffect27, useState as useState34 } from "react";
10166
10220
  import { RecordsProvider as RecordsProvider3, useRecordsClient as useRecordsClient10 } from "@ai-matrx/records/react";
10167
10221
  import { Button as Button20 } from "@ai-matrx/design-system";
10168
10222
  import { jsx as jsx44, jsxs as jsxs42 } from "react/jsx-runtime";
@@ -10178,7 +10232,7 @@ function Decision({
10178
10232
  const [may, setMay] = useState34(null);
10179
10233
  const [busy, setBusy] = useState34(null);
10180
10234
  const [error, setError] = useState34(null);
10181
- useEffect26(() => {
10235
+ useEffect27(() => {
10182
10236
  let live = true;
10183
10237
  void client.workApprovalMayDecide({ approval_id: approvalId }).then((res) => {
10184
10238
  if (!live) return;