@ai-matrx/records-ui 0.116.60 → 0.116.62

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.cjs CHANGED
@@ -7957,6 +7957,15 @@ function WithWords(props) {
7957
7957
  {
7958
7958
  field: props.field,
7959
7959
  refs: withKnown,
7960
+ autoOpen: props.autoOpen,
7961
+ onClose: props.onClose,
7962
+ onCancel: props.onCancel,
7963
+ initialSearch: props.initialSearch,
7964
+ onTakeOff: (ref) => {
7965
+ const rest = withKnown.filter((x) => !(x.token === ref.token && x.id === ref.id));
7966
+ props.onChange((0, import_records8.entityRefsToWrite)(rest, Boolean(props.field.multi)));
7967
+ },
7968
+ labelOf: (r) => r.label ?? words?.data?.find((w) => w.token === r.token && w.id === r.id)?.label ?? WITHHELD_ENTITY_LABEL,
7960
7969
  onPick: (picked) => {
7961
7970
  setKnown((k) => [...k.filter((x) => !(x.token === picked.token && x.id === picked.id)), picked]);
7962
7971
  const multi = Boolean(props.field.multi);
@@ -7965,18 +7974,32 @@ function WithWords(props) {
7965
7974
  }
7966
7975
  }
7967
7976
  );
7977
+ if (props.autoOpen && !props.disabled) return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { id: props.id, className: (0, import_design_system20.cn)("flex min-w-0 max-w-full flex-wrap items-center gap-1", props.className), children: picker });
7968
7978
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Chips, { ...props, value: withKnown, words, picker });
7969
7979
  }
7970
7980
  function EntityReferencePicker({
7971
7981
  field,
7972
7982
  refs,
7973
- onPick
7983
+ onPick,
7984
+ autoOpen,
7985
+ onClose,
7986
+ onCancel,
7987
+ initialSearch,
7988
+ onTakeOff,
7989
+ labelOf
7974
7990
  }) {
7975
7991
  const allowed = allowedKindsOf(field);
7976
7992
  const kinds = (0, import_react32.useEntityReferenceKinds)();
7977
7993
  const labelOfKind = (token) => kinds.data?.find((k) => k.token === token)?.label ?? token.replace(/_/g, " ");
7978
- const [open, setOpen] = (0, import_react31.useState)(false);
7979
- const [search, setSearch] = (0, import_react31.useState)("");
7994
+ const [open, setOpenState] = (0, import_react31.useState)(autoOpen === true);
7995
+ const onCloseRef = (0, import_react31.useRef)(onClose);
7996
+ onCloseRef.current = onClose;
7997
+ const setOpen = (0, import_react31.useCallback)((next) => {
7998
+ setOpenState(next);
7999
+ if (!next) onCloseRef.current?.();
8000
+ }, []);
8001
+ const anchored = autoOpen === true;
8002
+ const [search, setSearch] = (0, import_react31.useState)(initialSearch ?? "");
7980
8003
  const [only, setOnly] = (0, import_react31.useState)(null);
7981
8004
  const tokens = only ? [only] : allowed;
7982
8005
  const found = (0, import_react32.useEntityReferenceSearch)(tokens, search, open);
@@ -8019,6 +8042,10 @@ function EntityReferencePicker({
8019
8042
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
8020
8043
  PickOrAdd,
8021
8044
  {
8045
+ anchored,
8046
+ ...anchored && onCancel ? { onEscape: onCancel } : {},
8047
+ multi,
8048
+ ...anchored ? { chips: refs.map((r) => ({ id: `${r.token}:${r.id}`, label: labelOf(r), onRemove: () => onTakeOff(r) })) } : {},
8022
8049
  triggerLabel: `Pick for ${field.label}`,
8023
8050
  triggerText: refs.length > 0 && !multi ? "Change" : "Pick",
8024
8051
  open,
@@ -10768,6 +10795,7 @@ var import_records20 = require("@ai-matrx/records");
10768
10795
  var import_react62 = require("@ai-matrx/records/react");
10769
10796
  init_Refusal();
10770
10797
  init_names();
10798
+ init_plainWords();
10771
10799
  init_refusals();
10772
10800
  var import_jsx_runtime40 = require("react/jsx-runtime");
10773
10801
  var PREVIEW_GROUPS = 1e3;
@@ -10801,7 +10829,14 @@ function FieldRulePreview({ field, tableId, rules }) {
10801
10829
  void client.recordAggregate({ table_id: tableId, groupBy: [field.key], measures: [{ op: "count" }], limit: PREVIEW_GROUPS }).then((answer) => {
10802
10830
  if (cancelled) return;
10803
10831
  if (!answer.ok) {
10804
- setRefusal(answer.error);
10832
+ setRefusal(
10833
+ answer.error.code === "unreachable" ? (0, refusals_exports.refusal)(
10834
+ "unreachable",
10835
+ `${name}'s values could not be counted.`,
10836
+ "The check still applies when you save.",
10837
+ refusalForAPerson(answer.error).forEngineers
10838
+ ) : answer.error
10839
+ );
10805
10840
  return;
10806
10841
  }
10807
10842
  const numbers = holdsNumbers(field);
@@ -13953,7 +13988,7 @@ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose,
13953
13988
  case "member":
13954
13989
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(PersonPicker, { field, value, onChange, disabled, id: inputId, autoOpen, onClose, onCancel, initialSearch });
13955
13990
  case "entity_reference":
13956
- return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(EntityReferenceControl, { field, value, onChange, disabled, id: inputId });
13991
+ return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(EntityReferenceControl, { field, value, onChange, disabled, id: inputId, autoOpen, onClose, onCancel, initialSearch });
13957
13992
  case "attachment":
13958
13993
  if (hostTakesFiles(host)) {
13959
13994
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(AttachmentControl, { field, value, onChange, disabled, id: inputId, autoOpen, onClose });