@homebound/beam 2.415.5 → 2.416.0-alpha.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.
@@ -35,6 +35,7 @@ function fail(message) {
35
35
  function toToggleState(isSelected, onChange) {
36
36
  return {
37
37
  isSelected,
38
+ defaultSelected: false,
38
39
  setSelected: onChange,
39
40
  toggle: () => onChange(!isSelected)
40
41
  };
@@ -92,4 +93,4 @@ export {
92
93
  isDefined,
93
94
  pluralize
94
95
  };
95
- //# sourceMappingURL=chunk-ZQBDHF22.js.map
96
+ //# sourceMappingURL=chunk-XH44AYND.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/defaultTestId.ts","../src/utils/useTestIds.tsx","../src/utils/index.ts"],"sourcesContent":["import { camelCase } from \"change-case\";\n\n/**\n * Guesses an id based on a label string, i.e. given `Homeowner Contract`,\n * returns `homeownerContract`.\n *\n * This is useful for our (non-bound) form fields that will probably have a label,\n * but may not have a `data-testid` set by the encompassing page.\n *\n * (Bound form fields typically set their test id from their form-state field's key.)\n */\nexport function defaultTestId(label: string): string {\n // Strip `m:4` to `m4` to prevent it from becoming `m_4` which our rtl-utils assumes\n // means \"the 4th element with a data-testid value of 'm'\".\n return camelCase(label.replace(\":\", \"\"));\n}\n","import { defaultTestId } from \"src/utils/defaultTestId\";\n\nexport type TestIds = Record<string, object>;\n\n/**\n * Provides a way to easily generate `data-testid`s.\n *\n * The test ids are made of a `${prefix}_${key}`, where:\n *\n * - The prefix is the component name, like \"profile\", and\n * - The key is the specific DOM element that's being tagged, like \"firstName\"\n *\n * To determine the prefix, the component passes us their props, which we'll use\n * to look for an incoming `data-testid` to become the prefix the `data-testid`s\n * that we create. I.e.:\n *\n * ```tsx\n * const { a, b } = props;\n * const tid = useTestIds(props);\n *\n * return <Foo {...tid.foo} />;\n * ```\n *\n * This allows components that embed the component to customize the prefix, i.e.\n * `<TextField data-testid=\"firstName\" />` and `<TextField data-testid=\"lastName\" />`\n * would produce, within `TextField` itself, ids like:\n *\n * - `firstName_input`\n * - `firstName_errors`\n * - `lastName_input`\n * - `lastName_errors`\n *\n * @param props the component's `props` object, which we'll scan for `data-testid` to use as the prefix\n * @param defaultPrefix the default prefix to use if no `data-testid` is found on `props`\n */\nexport function useTestIds(props: object, defaultPrefix?: string): Record<string, object> {\n const prefix: string | undefined =\n (props as any)[\"data-testid\"] ||\n // Pass defaultPrefix through defaultTestId to allow `useTestIds(..., label)` usage\n (defaultPrefix ? defaultTestId(defaultPrefix) : undefined);\n const rootId = { \"data-testid\": prefix };\n return newMethodMissingProxy(rootId, (key) => {\n // If we get tagged ids, remove the colon so that we can do `r.foo_m2` for `m:2`\n key = key.replace(\":\", \"\");\n return { \"data-testid\": prefix ? `${prefix}_${key}` : key };\n }) as any;\n}\n\n/** Uses `object` for any keys that exist on it, otherwise calls `methodMissing` fn. */\nexport function newMethodMissingProxy<T extends object, Y>(\n object: T,\n methodMissing: (key: string) => Y,\n): T & Record<string, Y> {\n return new Proxy(object, {\n get(object, property) {\n if (Reflect.has(object, property)) {\n return Reflect.get(object, property);\n } else if (property === \"then\") {\n return undefined;\n } else {\n return methodMissing(String(property));\n }\n },\n }) as any;\n}\n","import { MutableRefObject } from \"react\";\nimport type { CheckboxGroupState, ToggleState } from \"react-stately\";\n\nexport function fail(message?: string): never {\n throw new Error(message || \"Failed\");\n}\n\n/** Adapts our state to what useToggleState returns in a stateless manner. */\nexport function toToggleState(isSelected: boolean, onChange: (value: boolean) => void): ToggleState {\n return {\n isSelected,\n defaultSelected: false,\n setSelected: onChange,\n toggle: () => onChange(!isSelected),\n };\n}\n\n/** Adapts our state to what use*Group returns in a stateless manner. */\nexport function toGroupState<T extends string>(values: T[], onChange: (value: T[]) => void): CheckboxGroupState {\n const addValue = (value: T) => onChange([...values, value]);\n const removeValue = (value: T) => onChange(values.filter((_value) => _value !== value));\n\n return {\n value: values,\n defaultValue: [],\n setValue: onChange,\n isSelected: (value: T) => values.includes(value),\n addValue,\n removeValue,\n toggleValue: (value: T) => (values.includes(value) ? addValue(value) : removeValue(value)),\n isDisabled: false,\n isReadOnly: false,\n // We do not use the validation state, as our Switch groups do not support error states. However, this field is required by the `CheckboxGroupState` so we need to include it.\n // If we ever update our SwitchGroup component to support error states, we'll need to update this.\n validationState: \"valid\",\n isInvalid: false,\n isRequired: false,\n setInvalid: () => {},\n realtimeValidation: { isInvalid: false, validationErrors: [], validationDetails: {} as ValidityState },\n displayValidation: { isInvalid: false, validationErrors: [], validationDetails: {} as ValidityState },\n updateValidation: () => {},\n resetValidation: () => {},\n commitValidation: () => {},\n };\n}\n\n/**\n * Utility to maybe call a function if undefined with arguments\n *\n * @example\n * maybeCall(onChange, true)\n * maybeCall(onBlur)\n * maybeCall(onSelect, { id: 1, value: \"book 1\"}, true)\n */\nexport function maybeCall(callback: Function | undefined, ...args: any[]) {\n return callback && callback(...args);\n}\n\nexport * from \"./useTestIds\";\n\n/** Casts `Object.keys` to \"what it should be\", as long as your instance doesn't have keys it shouldn't. */\nexport function safeKeys<T>(instance: T): (keyof T)[] {\n return Object.getOwnPropertyNames(instance) as any;\n}\n\n// Returns object with specified key removed\nexport const omitKey = <T, K extends keyof T>(key: K, { [key]: _, ...obj }: T) => obj as T;\n\nexport const noop = (..._: any) => {};\n\ntype Entries<T> = {\n [K in keyof T]: [K, T[K]];\n}[keyof T][];\n\nexport function safeEntries<T extends object>(obj: T): Entries<T> {\n return Object.entries(obj) as any;\n}\n\nexport class EmptyRef<T> implements MutableRefObject<T> {\n get current(): T {\n throw new Error(\"BeamProvider is missing\");\n }\n\n set current(_) {\n throw new Error(\"BeamProvider is missing\");\n }\n}\n\nexport const isAbsoluteUrl = (url: string) => /^(http(s?)):\\/\\//i.test(url);\n\nexport function areArraysEqual(a: any[], b: any[]): boolean {\n return a.length === b.length && a.every((val, idx) => val === b[idx]);\n}\n\nexport function isPromise(obj: any | Promise<any>): obj is Promise<any> {\n return typeof obj === \"object\" && \"then\" in obj && typeof obj.then === \"function\";\n}\n\nexport function isFunction(f: any): f is Function {\n return typeof f === \"function\";\n}\n\nexport function isDefined<T extends any>(param: T | undefined | null): param is T {\n return param !== null && param !== undefined;\n}\n\nexport function pluralize(count: number | unknown[], noun: string, pluralNoun?: string): string {\n if ((Array.isArray(count) ? count.length : count) === 1) return noun;\n return pluralNoun || `${noun}s`;\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAWnB,SAAS,cAAc,OAAuB;AAGnD,SAAO,UAAU,MAAM,QAAQ,KAAK,EAAE,CAAC;AACzC;;;ACoBO,SAAS,WAAW,OAAe,eAAgD;AACxF,QAAM,SACH,MAAc,aAAa;AAAA,GAE3B,gBAAgB,cAAc,aAAa,IAAI;AAClD,QAAM,SAAS,EAAE,eAAe,OAAO;AACvC,SAAO,sBAAsB,QAAQ,CAAC,QAAQ;AAE5C,UAAM,IAAI,QAAQ,KAAK,EAAE;AACzB,WAAO,EAAE,eAAe,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK,IAAI;AAAA,EAC5D,CAAC;AACH;AAGO,SAAS,sBACd,QACA,eACuB;AACvB,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAIA,SAAQ,UAAU;AACpB,UAAI,QAAQ,IAAIA,SAAQ,QAAQ,GAAG;AACjC,eAAO,QAAQ,IAAIA,SAAQ,QAAQ;AAAA,MACrC,WAAW,aAAa,QAAQ;AAC9B,eAAO;AAAA,MACT,OAAO;AACL,eAAO,cAAc,OAAO,QAAQ,CAAC;AAAA,MACvC;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AC7DO,SAAS,KAAK,SAAyB;AAC5C,QAAM,IAAI,MAAM,WAAW,QAAQ;AACrC;AAGO,SAAS,cAAc,YAAqB,UAAiD;AAClG,SAAO;AAAA,IACL;AAAA,IACA,iBAAiB;AAAA,IACjB,aAAa;AAAA,IACb,QAAQ,MAAM,SAAS,CAAC,UAAU;AAAA,EACpC;AACF;AAuCO,SAAS,UAAU,aAAmC,MAAa;AACxE,SAAO,YAAY,SAAS,GAAG,IAAI;AACrC;AAKO,SAAS,SAAY,UAA0B;AACpD,SAAO,OAAO,oBAAoB,QAAQ;AAC5C;AAGO,IAAM,UAAU,CAAuB,KAAQ,EAAE,CAAC,MAAM,GAAG,GAAG,IAAI,MAAS;AAE3E,IAAM,OAAO,IAAI,MAAW;AAAC;AAM7B,SAAS,YAA8B,KAAoB;AAChE,SAAO,OAAO,QAAQ,GAAG;AAC3B;AAEO,IAAM,WAAN,MAAiD;AAAA,EACtD,IAAI,UAAa;AACf,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAAA,EAEA,IAAI,QAAQ,GAAG;AACb,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACF;AAEO,IAAM,gBAAgB,CAAC,QAAgB,oBAAoB,KAAK,GAAG;AAMnE,SAAS,UAAU,KAA8C;AACtE,SAAO,OAAO,QAAQ,YAAY,UAAU,OAAO,OAAO,IAAI,SAAS;AACzE;AAEO,SAAS,WAAW,GAAuB;AAChD,SAAO,OAAO,MAAM;AACtB;AAEO,SAAS,UAAyB,OAAyC;AAChF,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEO,SAAS,UAAU,OAA2B,MAAc,YAA6B;AAC9F,OAAK,MAAM,QAAQ,KAAK,IAAI,MAAM,SAAS,WAAW,EAAG,QAAO;AAChE,SAAO,cAAc,GAAG,IAAI;AAC9B;","names":["object"]}
package/dist/index.cjs CHANGED
@@ -4388,6 +4388,7 @@ function fail(message) {
4388
4388
  function toToggleState(isSelected, onChange) {
4389
4389
  return {
4390
4390
  isSelected,
4391
+ defaultSelected: false,
4391
4392
  setSelected: onChange,
4392
4393
  toggle: () => onChange(!isSelected)
4393
4394
  };
@@ -7094,7 +7095,7 @@ function Button(props) {
7094
7095
  const result = onPress(e);
7095
7096
  if (isPromise(result)) {
7096
7097
  setAsyncInProgress(true);
7097
- result.finally(() => setAsyncInProgress(false));
7098
+ void result.finally(() => setAsyncInProgress(false));
7098
7099
  }
7099
7100
  return result;
7100
7101
  },
@@ -8501,7 +8502,7 @@ var RowState = class {
8501
8502
  }
8502
8503
  }
8503
8504
  /** Used by node when doing `console.log(rs)`. */
8504
- [Symbol.for("nodejs.util.inspect.custom")]() {
8505
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
8505
8506
  return `RowState@${this.row.id}`;
8506
8507
  }
8507
8508
  };
@@ -9077,7 +9078,7 @@ function Menu(props) {
9077
9078
  const { items: items2, ...others } = tree;
9078
9079
  const [itemsSection, persistentSection] = items2;
9079
9080
  if (search) {
9080
- const filteredChildren = itemsSection.children.filter((item) => contains(item.value.label, search));
9081
+ const filteredChildren = (itemsSection.children ?? []).filter((item) => contains(item.value.label, search));
9081
9082
  const { items: items3, ...otherValues } = itemsSection.value;
9082
9083
  const filteredValue = items3?.filter((item) => contains(item.label, search));
9083
9084
  return {
@@ -9518,18 +9519,21 @@ function ListBoxChip({ label }) {
9518
9519
  }
9519
9520
 
9520
9521
  // src/inputs/Value.ts
9522
+ var VALUE_PREFIX = "__VALUE--";
9521
9523
  function keyToValue(key) {
9522
9524
  if (typeof key === "number") {
9523
9525
  return key;
9524
9526
  } else if (typeof key === "string") {
9525
- if (key === "__VALUE:null") {
9527
+ if (key === `${VALUE_PREFIX}null` || key === "__VALUE:null") {
9526
9528
  return null;
9527
- } else if (key === "__VALUE:undefined") {
9529
+ } else if (key === `${VALUE_PREFIX}undefined` || key === "__VALUE:undefined") {
9528
9530
  return void 0;
9529
- } else if (key.startsWith("__VALUE:boolean:")) {
9530
- return key.split(":")[2] === "true";
9531
- } else if (key.startsWith("__VALUE:number")) {
9532
- return Number(key.split(":")[2]);
9531
+ } else if (key.startsWith(`${VALUE_PREFIX}boolean--`) || key.startsWith("__VALUE:boolean:")) {
9532
+ const parts = key.includes("--boolean--") ? key.split("--") : key.split(":");
9533
+ return parts[parts.length - 1] === "true";
9534
+ } else if (key.startsWith(`${VALUE_PREFIX}number--`) || key.startsWith("__VALUE:number:")) {
9535
+ const parts = key.includes("--number--") ? key.split("--") : key.split(":");
9536
+ return Number(parts[parts.length - 1]);
9533
9537
  } else {
9534
9538
  return key;
9535
9539
  }
@@ -9541,13 +9545,13 @@ function valueToKey(value) {
9541
9545
  if (typeof value === "string") {
9542
9546
  return value;
9543
9547
  } else if (typeof value === "number") {
9544
- return `__VALUE:number:${value}`;
9548
+ return `${VALUE_PREFIX}number--${value}`;
9545
9549
  } else if (typeof value === "boolean") {
9546
- return `__VALUE:boolean:${value}`;
9550
+ return `${VALUE_PREFIX}boolean--${value}`;
9547
9551
  } else if (value === null) {
9548
- return "__VALUE:null";
9552
+ return `${VALUE_PREFIX}null`;
9549
9553
  } else if (value === void 0) {
9550
- return "__VALUE:undefined";
9554
+ return `${VALUE_PREFIX}undefined`;
9551
9555
  } else {
9552
9556
  throw new Error(`Unsupported value ${value}`);
9553
9557
  }
@@ -10118,7 +10122,8 @@ function VirtualizedOptions(props) {
10118
10122
  allowCollapsing
10119
10123
  } = props;
10120
10124
  const virtuosoRef = (0, import_react45.useRef)(null);
10121
- const focusedItem = state.collection.getItem(state.selectionManager.focusedKey);
10125
+ const focusedKey = state.selectionManager.focusedKey;
10126
+ const focusedItem = focusedKey != null ? state.collection.getItem(focusedKey) : null;
10122
10127
  const selectedItem = state.selectionManager.selectedKeys.size > 0 ? state.collection.getItem([...state.selectionManager.selectedKeys.values()][0]) : void 0;
10123
10128
  (0, import_react45.useEffect)(
10124
10129
  () => {
@@ -10588,6 +10593,7 @@ function TreeSelectFieldBase(props) {
10588
10593
  state.selectionManager.state = (0, import_react_stately6.useMultipleSelectionState)({
10589
10594
  selectionMode: "multiple",
10590
10595
  selectedKeys: fieldState.selectedKeys,
10596
+ disabledKeys: Object.keys(disabledOptionsWithReasons),
10591
10597
  onSelectionChange: (newKeys) => {
10592
10598
  if (newKeys === "all") {
10593
10599
  return;
@@ -10880,7 +10886,9 @@ function ComboBoxInput(props) {
10880
10886
  onKeyDown: (e) => {
10881
10887
  if (isMultiSelect) {
10882
10888
  if (isTree) {
10883
- const item = state.collection.getItem(state.selectionManager.focusedKey);
10889
+ const focusedKey = state.selectionManager.focusedKey;
10890
+ if (focusedKey == null) return;
10891
+ const item = state.collection.getItem(focusedKey);
10884
10892
  if (item && (e.key === "ArrowRight" || e.key === "ArrowLeft")) {
10885
10893
  if (!isLeveledNode(item)) return;
10886
10894
  const leveledOption = item.value;
@@ -10902,7 +10910,10 @@ function ComboBoxInput(props) {
10902
10910
  if (state.isOpen) {
10903
10911
  e.preventDefault();
10904
10912
  }
10905
- state.selectionManager.toggleSelection(state.selectionManager.focusedKey);
10913
+ const focusedKey = state.selectionManager.focusedKey;
10914
+ if (focusedKey != null) {
10915
+ state.selectionManager.toggleSelection(focusedKey);
10916
+ }
10906
10917
  return;
10907
10918
  }
10908
10919
  if (e.key === "Escape") {
@@ -11124,7 +11135,8 @@ function ComboBoxBase(props) {
11124
11135
  // Do not allow an empty selection if single select mode
11125
11136
  disallowEmptySelection: !multiselect,
11126
11137
  selectedKeys,
11127
- onSelectionChange
11138
+ onSelectionChange,
11139
+ disabledKeys: Object.keys(disabledOptionsWithReasons)
11128
11140
  });
11129
11141
  const [debouncedSearch] = (0, import_use_debounce5.useDebounce)(searchValue, 300);
11130
11142
  (0, import_react49.useEffect)(() => {
@@ -11308,6 +11320,7 @@ function Autocomplete(props) {
11308
11320
  allowsCustomValue: true,
11309
11321
  children: (item) => /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_react_stately8.Item, { textValue: getOptionLabel(item), children: getOptionMenuLabel ? getOptionMenuLabel(item) : getOptionLabel(item) }, getOptionValue(item)),
11310
11322
  onSelectionChange: (key) => {
11323
+ if (key == null) return;
11311
11324
  const selectedItem = options.find((i) => getOptionValue(i) === key);
11312
11325
  if (selectedItem) {
11313
11326
  onInputChange(getOptionLabel(selectedItem));
@@ -12146,7 +12159,6 @@ function RadioGroupField(props) {
12146
12159
  /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(Label, { label, ...labelProps, ...tid.label, hidden: labelStyle === "hidden" }),
12147
12160
  /* @__PURE__ */ (0, import_jsx_runtime70.jsxs)("div", { ...radioGroupProps, children: [
12148
12161
  options.map((option) => {
12149
- const isDisabled = state.isDisabled || !!option.disabled;
12150
12162
  return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(import_react58.Fragment, { children: maybeTooltip({
12151
12163
  title: resolveTooltip(option.disabled),
12152
12164
  placement: "bottom",
@@ -12155,7 +12167,8 @@ function RadioGroupField(props) {
12155
12167
  {
12156
12168
  parentId: name,
12157
12169
  option,
12158
- state: { ...state, isDisabled },
12170
+ state,
12171
+ isOptionDisabled: !!option.disabled,
12159
12172
  ...otherProps,
12160
12173
  ...tid[option.value]
12161
12174
  }
@@ -12173,13 +12186,18 @@ function Radio(props) {
12173
12186
  parentId,
12174
12187
  option: { description, label, value },
12175
12188
  state,
12189
+ isOptionDisabled,
12176
12190
  ...others
12177
12191
  } = props;
12178
- const disabled = state.isDisabled;
12179
12192
  const labelId = `${parentId}-${value}-label`;
12180
12193
  const descriptionId = `${parentId}-${value}-description`;
12181
12194
  const ref = (0, import_react58.useRef)(null);
12182
- const { inputProps } = (0, import_react_aria34.useRadio)({ value, "aria-labelledby": labelId }, state, ref);
12195
+ const { inputProps, isDisabled } = (0, import_react_aria34.useRadio)(
12196
+ { value, "aria-labelledby": labelId, isDisabled: isOptionDisabled },
12197
+ state,
12198
+ ref
12199
+ );
12200
+ const disabled = isDisabled;
12183
12201
  const { focusProps, isFocusVisible } = (0, import_react_aria34.useFocusRing)();
12184
12202
  const { hoverProps, isHovered } = (0, import_react_aria34.useHover)({ isDisabled: disabled });
12185
12203
  return /* @__PURE__ */ (0, import_jsx_runtime70.jsxs)("label", { css: Css.df.cursorPointer.mb1.if(disabled).add("cursor", "initial").$, ...hoverProps, children: [
@@ -12719,7 +12737,7 @@ function ToggleButton(props) {
12719
12737
  const result = onChange(e);
12720
12738
  if (isPromise(result)) {
12721
12739
  setAsyncInProgress(true);
12722
- result.finally(() => setAsyncInProgress(false));
12740
+ void result.finally(() => setAsyncInProgress(false));
12723
12741
  }
12724
12742
  return result;
12725
12743
  }
@@ -14355,7 +14373,7 @@ function renderVirtual(style, id, columns, visibleDataRows, keptSelectedRows, fi
14355
14373
  const result = infiniteScroll.onEndReached(index);
14356
14374
  if (isPromise(result)) {
14357
14375
  setFetchMoreInProgress(true);
14358
- result.finally(() => setFetchMoreInProgress(false));
14376
+ void result.finally(() => setFetchMoreInProgress(false));
14359
14377
  }
14360
14378
  }
14361
14379
  } : {}
@@ -17825,7 +17843,10 @@ function ButtonDatePicker(props) {
17825
17843
  const { defaultOpen, disabled, trigger, onSelect, ...datePickerProps } = props;
17826
17844
  const state = (0, import_react_stately18.useMenuTriggerState)({ isOpen: defaultOpen });
17827
17845
  const buttonRef = (0, import_react105.useRef)(null);
17828
- const { menuTriggerProps, menuProps } = (0, import_react_aria46.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
17846
+ const {
17847
+ menuTriggerProps,
17848
+ menuProps: { autoFocus: _af, ...menuProps }
17849
+ } = (0, import_react_aria46.useMenuTrigger)({ isDisabled: !!disabled }, state, buttonRef);
17829
17850
  const tid = useTestIds(
17830
17851
  props,
17831
17852
  isTextButton(trigger) ? defaultTestId(labelOr(trigger, "buttonDatePicker")) : isNavLinkButton(trigger) ? defaultTestId(trigger.navLabel) : isIconButton(trigger) ? trigger.icon : trigger.name