@ai-matrx/records-ui 0.106.0 → 0.107.1

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
@@ -3038,7 +3038,8 @@ function formatControl(args) {
3038
3038
  {
3039
3039
  id,
3040
3040
  type: def.editor,
3041
- ...ownDetails && def.editor !== "url" ? { autoComplete: def.editor === "email" ? "email" : "tel" } : {},
3041
+ inputMode: def.editor,
3042
+ ...ownDetails ? { autoComplete: def.editor } : {},
3042
3043
  value: text,
3043
3044
  disabled,
3044
3045
  onChange: (e) => commit(e.target.value)
@@ -3493,7 +3494,7 @@ function isPersonsName(field) {
3493
3494
  const words = `${field.key} ${field.label ?? ""}`.toLowerCase();
3494
3495
  return /(^|[\s_])(full[\s_]?)?name(\s|$)/.test(words) && !/(therapist|doctor|physician|company|business|pet|room)/.test(words);
3495
3496
  }
3496
- function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose, onCommit, onCancel, addsChoices, initialSearch, asForm }) {
3497
+ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose, onCommit, onCancel, addsChoices, initialSearch, asForm, onChosen }) {
3497
3498
  const host = useRecordsUi();
3498
3499
  const kind = editorKindFor(field);
3499
3500
  const inputId = id ?? `field-${field.key}`;
@@ -3557,7 +3558,8 @@ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose,
3557
3558
  {
3558
3559
  id: inputId,
3559
3560
  type: kind === "email" ? "email" : kind === "phone" ? "tel" : "url",
3560
- ...ownDetails && kind !== "url" ? { autoComplete: kind === "email" ? "email" : "tel" } : {},
3561
+ inputMode: kind === "email" ? "email" : kind === "phone" ? "tel" : "url",
3562
+ ...ownDetails ? { autoComplete: kind === "email" ? "email" : kind === "phone" ? "tel" : "url" } : {},
3561
3563
  value: value === null || value === void 0 ? "" : String(value),
3562
3564
  disabled,
3563
3565
  onChange: (e) => onChange(e.target.value === "" ? null : e.target.value)
@@ -3567,7 +3569,7 @@ function FieldControl({ field, value, onChange, disabled, id, autoOpen, onClose,
3567
3569
  return /* @__PURE__ */ jsx18(CheckboxControl, { field, value, onChange, disabled, id: inputId });
3568
3570
  case "select":
3569
3571
  case "multi_select":
3570
- return /* @__PURE__ */ jsx18(OptionControl, { field, value, onChange, disabled, id: inputId, autoOpen, onClose, onCancel, addsChoices, initialSearch, asForm });
3572
+ return /* @__PURE__ */ jsx18(OptionControl, { field, value, onChange, disabled, id: inputId, autoOpen, onClose, onCancel, addsChoices, initialSearch, asForm, onChosen });
3571
3573
  case "member":
3572
3574
  return /* @__PURE__ */ jsx18(PersonPicker, { field, value, onChange, disabled, id: inputId, autoOpen, onClose, onCancel, initialSearch });
3573
3575
  case "entity_reference":
@@ -3749,7 +3751,7 @@ function inTheStoresOrder(options) {
3749
3751
  const made = (o) => String(o.created_at ?? "");
3750
3752
  return [...options].sort((a, b) => position(a) - position(b) || made(a).localeCompare(made(b)));
3751
3753
  }
3752
- function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose, onCancel, addsChoices, initialSearch, asForm }) {
3754
+ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose, onCancel, addsChoices, initialSearch, asForm, onChosen }) {
3753
3755
  const client = useOptionalRecordsClient7();
3754
3756
  const [options, setOptions] = useState15(null);
3755
3757
  const [refusal2, setRefusal] = useState15(null);
@@ -3768,7 +3770,7 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
3768
3770
  }, [client, field.id, reread]);
3769
3771
  const handed = publicChoicesOf(field);
3770
3772
  if (!client && handed.length > 0) {
3771
- return /* @__PURE__ */ jsx18(ChoiceAnswer, { field, choices: handed, value, onChange, disabled, id });
3773
+ return /* @__PURE__ */ jsx18(ChoiceAnswer, { field, choices: handed, value, onChange, disabled, id, onChosen });
3772
3774
  }
3773
3775
  if (!client) {
3774
3776
  return /* @__PURE__ */ jsxs16("div", { className: "flex flex-col gap-1", children: [
@@ -3798,6 +3800,7 @@ function OptionControl({ field, value, onChange, disabled, id, autoOpen, onClose
3798
3800
  onChange,
3799
3801
  disabled,
3800
3802
  id,
3803
+ onChosen,
3801
3804
  isChosen: (choice, v) => {
3802
3805
  const option = options.find((o) => optionKey2(o) === choice.key);
3803
3806
  return option ? isTheChosen(option, v) : false;
@@ -4068,20 +4071,24 @@ function ChoiceAnswer({
4068
4071
  onChange,
4069
4072
  disabled,
4070
4073
  id,
4071
- isChosen
4074
+ isChosen,
4075
+ onChosen
4072
4076
  }) {
4073
4077
  const [search, setSearch] = useState15("");
4074
4078
  const held = field.multi ? choiceValuesOf(value) : value === null || value === void 0 || value === "" ? [] : [value];
4075
4079
  const on = (choice) => held.some((v) => isChosen ? isChosen(choice, v) : String(v) === choice.key || String(v) === choice.label);
4076
4080
  const press = (choice) => {
4077
4081
  if (!field.multi) {
4078
- onChange(on(choice) ? null : choice.key);
4082
+ const picking = !on(choice);
4083
+ onChange(picking ? choice.key : null);
4084
+ if (picking) onChosen?.();
4079
4085
  return;
4080
4086
  }
4081
4087
  const keys = choices.filter((c) => c.key === choice.key ? !on(c) : on(c)).map((c) => c.key);
4082
4088
  onChange(keys.length === 0 ? null : keys);
4083
4089
  };
4084
4090
  const lettered = choices.length <= CHOICE_LETTERS.length;
4091
+ const tabStop = choices.find((c) => on(c))?.key ?? choices[0]?.key;
4085
4092
  const option = (choice) => {
4086
4093
  const chosen = on(choice);
4087
4094
  const letter = lettered ? CHOICE_LETTERS[choices.indexOf(choice)] : null;
@@ -4093,6 +4100,7 @@ function ChoiceAnswer({
4093
4100
  "aria-checked": chosen,
4094
4101
  "aria-label": choice.label,
4095
4102
  disabled,
4103
+ tabIndex: field.multi || choice.key === tabStop ? 0 : -1,
4096
4104
  onClick: () => press(choice),
4097
4105
  "data-records-choice-answer": choice.key,
4098
4106
  className: cn13(
@@ -4119,8 +4127,25 @@ function ChoiceAnswer({
4119
4127
  );
4120
4128
  };
4121
4129
  const onKeyDown = (event) => {
4122
- if (!lettered || disabled || event.metaKey || event.ctrlKey || event.altKey) return;
4130
+ if (disabled || event.metaKey || event.ctrlKey || event.altKey) return;
4123
4131
  if (event.target.tagName === "INPUT") return;
4132
+ const arrow = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[event.key];
4133
+ if (arrow) {
4134
+ const buttons = Array.from(
4135
+ event.currentTarget.querySelectorAll("[data-records-choice-answer]")
4136
+ );
4137
+ const here = buttons.indexOf(event.target);
4138
+ if (buttons.length === 0) return;
4139
+ event.preventDefault();
4140
+ const next = buttons[(Math.max(here, 0) + arrow + buttons.length) % buttons.length];
4141
+ next.focus();
4142
+ if (!field.multi) {
4143
+ const choice = choices.find((c) => c.key === next.dataset["recordsChoiceAnswer"]);
4144
+ if (choice && !on(choice)) onChange(choice.key);
4145
+ }
4146
+ return;
4147
+ }
4148
+ if (!lettered) return;
4124
4149
  const at = CHOICE_LETTERS.indexOf(event.key.toUpperCase());
4125
4150
  if (event.key.length !== 1 || at < 0 || at >= choices.length) return;
4126
4151
  event.preventDefault();