@homebound/beam 3.62.0 → 3.63.0

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/index.cjs CHANGED
@@ -12236,7 +12236,6 @@ function TreeOption(props) {
12236
12236
  const {
12237
12237
  item,
12238
12238
  state,
12239
- allowCollapsing = true,
12240
12239
  disabledReason
12241
12240
  } = props;
12242
12241
  const leveledOption = item.value;
@@ -12265,7 +12264,7 @@ function TreeOption(props) {
12265
12264
  shouldFocusOnHover: false
12266
12265
  }, state, ref);
12267
12266
  const isGroup = groupKeys.includes(item.key);
12268
- const canCollapse = allowCollapsing && !!option.children?.length;
12267
+ const canCollapse = !!option.children?.length;
12269
12268
  function toggleCollapsed() {
12270
12269
  if (!canCollapse) return;
12271
12270
  setCollapsedKeys((prevKeys) => collapsedKeys.includes(item.key) ? prevKeys.filter((k) => k !== item.key) : [...prevKeys, item.key]);
@@ -12323,7 +12322,7 @@ function TreeOption(props) {
12323
12322
  ...isFocused && !isGroup ? listItemStyles.focus : {},
12324
12323
  ...isDisabled && !isGroup ? listItemStyles.disabled : {}
12325
12324
  }), children: [
12326
- allowCollapsing && /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("span", { className: "w_18px fs0 df aic", children: canCollapse && /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("button", { onClick: (e) => {
12325
+ /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("span", { className: "w_18px fs0 df aic", children: canCollapse && /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("button", { onClick: (e) => {
12327
12326
  e.preventDefault();
12328
12327
  e.stopPropagation();
12329
12328
  toggleCollapsed();
@@ -12382,16 +12381,7 @@ function isLeveledNode(node) {
12382
12381
  // src/inputs/internal/VirtualizedOptions.tsx
12383
12382
  var import_jsx_runtime53 = require("react/jsx-runtime");
12384
12383
  function VirtualizedOptions(props) {
12385
- const {
12386
- state,
12387
- items,
12388
- onListHeightChange,
12389
- scrollOnFocus,
12390
- loading,
12391
- disabledOptionsWithReasons,
12392
- isTree,
12393
- allowCollapsing
12394
- } = props;
12384
+ const { state, items, onListHeightChange, scrollOnFocus, loading, disabledOptionsWithReasons, isTree } = props;
12395
12385
  const virtuosoRef = (0, import_react49.useRef)(null);
12396
12386
  const focusedKey = state.selectionManager.focusedKey;
12397
12387
  const focusedItem = focusedKey != null ? state.collection.getItem(focusedKey) : null;
@@ -12432,7 +12422,6 @@ function VirtualizedOptions(props) {
12432
12422
  {
12433
12423
  item,
12434
12424
  state,
12435
- allowCollapsing,
12436
12425
  disabledReason: disabledOptionsWithReasons[item.key]
12437
12426
  },
12438
12427
  item.key
@@ -12531,8 +12520,7 @@ function ListBox(props) {
12531
12520
  horizontalLayout = false,
12532
12521
  loading,
12533
12522
  disabledOptionsWithReasons = {},
12534
- isTree,
12535
- allowCollapsing
12523
+ isTree
12536
12524
  } = props;
12537
12525
  const {
12538
12526
  listBoxProps
@@ -12610,8 +12598,7 @@ function ListBox(props) {
12610
12598
  scrollOnFocus: props.shouldUseVirtualFocus,
12611
12599
  loading,
12612
12600
  disabledOptionsWithReasons,
12613
- isTree,
12614
- allowCollapsing
12601
+ isTree
12615
12602
  }
12616
12603
  ) })
12617
12604
  ] });
@@ -12704,7 +12691,8 @@ function TreeSelectFieldBase(props) {
12704
12691
  sensitivity: "base"
12705
12692
  });
12706
12693
  const {
12707
- collapsedKeys
12694
+ collapsedKeys,
12695
+ setCollapsedKeys
12708
12696
  } = useTreeSelectFieldProvider();
12709
12697
  const groupKeys = (0, import_react51.useMemo)(() => _groupOptions?.map((option) => valueToKey(option)) ?? [], [_groupOptions]);
12710
12698
  const groupKeySet = (0, import_react51.useMemo)(() => new Set(groupKeys), [groupKeys]);
@@ -12746,8 +12734,7 @@ function TreeSelectFieldBase(props) {
12746
12734
  selectedChipOptions: selectedChipState.options,
12747
12735
  allOptions: initialOptions,
12748
12736
  selectedOptionsLabels: selectedChipState.labels,
12749
- optionsLoading: false,
12750
- allowCollapsing: true
12737
+ optionsLoading: false
12751
12738
  };
12752
12739
  }, [initialOptions, values, chipDisplay, getOptionLabel, isReadOnly, nothingSelectedText, getOptionValue, groupKeySet]);
12753
12740
  const [fieldState, setFieldState] = (0, import_react51.useState)(() => initTreeFieldState());
@@ -12769,14 +12756,26 @@ function TreeSelectFieldBase(props) {
12769
12756
  setFieldState(initTreeFieldState());
12770
12757
  }
12771
12758
  }, [getOptionValue, initTreeFieldState, values]);
12759
+ const preSearchCollapsedKeys = (0, import_react51.useRef)(void 0);
12760
+ (0, import_react51.useEffect)(() => {
12761
+ if (fieldState.searchValue) {
12762
+ if (preSearchCollapsedKeys.current === void 0) {
12763
+ preSearchCollapsedKeys.current = collapsedKeys;
12764
+ if (collapsedKeys.length > 0) setCollapsedKeys([]);
12765
+ }
12766
+ } else if (preSearchCollapsedKeys.current !== void 0) {
12767
+ const keys = preSearchCollapsedKeys.current;
12768
+ preSearchCollapsedKeys.current = void 0;
12769
+ setCollapsedKeys(keys);
12770
+ }
12771
+ }, [fieldState.searchValue, collapsedKeys, setCollapsedKeys]);
12772
12772
  const filteredOptions = (0, import_react51.useMemo)(() => getFilteredOptions(fieldState.allOptions, fieldState.searchValue, collapsedKeys, contains, getOptionLabel, getOptionValue), [fieldState.allOptions, fieldState.searchValue, collapsedKeys, contains, getOptionLabel, getOptionValue]);
12773
12773
  const onInputChange = (0, import_react51.useCallback)((inputValue) => {
12774
12774
  setFieldState((prevState) => {
12775
12775
  return {
12776
12776
  ...prevState,
12777
12777
  inputValue,
12778
- searchValue: inputValue.length === 0 ? void 0 : inputValue,
12779
- allowCollapsing: inputValue.length === 0
12778
+ searchValue: inputValue.length === 0 ? void 0 : inputValue
12780
12779
  };
12781
12780
  });
12782
12781
  }, []);
@@ -12804,8 +12803,7 @@ function TreeSelectFieldBase(props) {
12804
12803
  setFieldState((prevState) => ({
12805
12804
  ...prevState,
12806
12805
  inputValue: "",
12807
- searchValue: void 0,
12808
- allowCollapsing: true
12806
+ searchValue: void 0
12809
12807
  }));
12810
12808
  }
12811
12809
  }
@@ -12840,9 +12838,8 @@ function TreeSelectFieldBase(props) {
12840
12838
  if (newKeys.size === 0) {
12841
12839
  setFieldState((prevState) => ({
12842
12840
  ...prevState,
12843
- inputValue: nothingSelectedText,
12844
- searchValue: void 0,
12845
- allowCollapsing: true,
12841
+ // Unselecting the last option shouldn't drop the search either
12842
+ inputValue: prevState.searchValue ?? nothingSelectedText,
12846
12843
  selectedKeys: [],
12847
12844
  selectedOptions: [],
12848
12845
  selectedChipOptions: [],
@@ -12916,9 +12913,9 @@ function TreeSelectFieldBase(props) {
12916
12913
  const selectedChipState = getSelectedChipState(fieldState.allOptions, selectedOptions, selectedKeys, chipDisplay, getOptionLabel, getOptionValue);
12917
12914
  setFieldState((prevState) => ({
12918
12915
  ...prevState,
12919
- // Since we reset the list of options upon selection changes, then set the `inputValue` to empty string to reflect that.
12920
- inputValue: "",
12921
- searchValue: void 0,
12916
+ // Keep any search in place, so picking several options out of the same filtered list doesn't
12917
+ // make the user retype it; when they're not searching the input stays empty as before.
12918
+ inputValue: prevState.searchValue ?? "",
12922
12919
  selectedKeys: [...selectedKeys],
12923
12920
  selectedOptions,
12924
12921
  selectedChipOptions: selectedChipState.options,
@@ -12950,8 +12947,7 @@ function TreeSelectFieldBase(props) {
12950
12947
  setFieldState((prevState) => ({
12951
12948
  ...prevState,
12952
12949
  inputValue: selectedOptions.length === 1 ? getOptionLabel(selectedOptions[0]) : selectedOptions.length === 0 ? nothingSelectedText : "",
12953
- searchValue: void 0,
12954
- allowCollapsing: true
12950
+ searchValue: void 0
12955
12951
  }));
12956
12952
  }
12957
12953
  }
@@ -13021,17 +13017,16 @@ function TreeSelectFieldBase(props) {
13021
13017
  onClose: () => state.toggle(),
13022
13018
  isOpen: state.isOpen,
13023
13019
  minWidth: 320,
13024
- children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(ListBox, { ...listBoxProps, positionProps, state, listBoxRef, selectedOptions: fieldState.selectedChipOptions, getOptionLabel, getOptionValue: (o) => valueToKey(getOptionValue(o)), horizontalLayout: labelStyle === "left", loading: fieldState.optionsLoading, allowCollapsing: fieldState.allowCollapsing, disabledOptionsWithReasons, isTree: true })
13020
+ children: /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(ListBox, { ...listBoxProps, positionProps, state, listBoxRef, selectedOptions: fieldState.selectedChipOptions, getOptionLabel, getOptionValue: (o) => valueToKey(getOptionValue(o)), horizontalLayout: labelStyle === "left", loading: fieldState.optionsLoading, disabledOptionsWithReasons, isTree: true })
13025
13021
  }
13026
13022
  )
13027
13023
  ] });
13028
13024
  }
13029
- function levelOptions(o, level, filtering, collapsedKeys, getOptionValue) {
13030
- const actualLevel = filtering ? 0 : level;
13025
+ function levelOptions(o, level, collapsedKeys, getOptionValue) {
13031
13026
  return [
13032
- [o, actualLevel],
13033
- // Flat map the children if the parent is not collapsed or if we are filtering (for the search results)
13034
- ...o.children?.length && (!collapsedKeys.includes(valueToKey(getOptionValue(o))) || filtering) ? o.children.flatMap((oc) => levelOptions(oc, actualLevel + 1, filtering, collapsedKeys, getOptionValue)) : []
13027
+ [o, level],
13028
+ // Flat map the children if the parent is not collapsed
13029
+ ...o.children?.length && !collapsedKeys.includes(valueToKey(getOptionValue(o))) ? o.children.flatMap((oc) => levelOptions(oc, level + 1, collapsedKeys, getOptionValue)) : []
13035
13030
  ];
13036
13031
  }
13037
13032
  function getTopLevelSelections(o, selectedKeys, getOptionValue) {
@@ -13040,7 +13035,16 @@ function getTopLevelSelections(o, selectedKeys, getOptionValue) {
13040
13035
  return [];
13041
13036
  }
13042
13037
  function getFilteredOptions(allOptions, searchValue, collapsedKeys, contains, getOptionLabel, getOptionValue) {
13043
- return allOptions.flatMap((option) => levelOptions(option, 0, !!searchValue, collapsedKeys, getOptionValue).filter(([nestedOption]) => searchValue ? contains(getOptionLabel(nestedOption), searchValue) : true));
13038
+ if (!searchValue) return allOptions.flatMap((option) => levelOptions(option, 0, collapsedKeys, getOptionValue));
13039
+ const search = searchValue;
13040
+ return allOptions.flatMap((option) => matchedOptions(option, 0, false));
13041
+ function matchedOptions(o, level, hasMatchedParent) {
13042
+ const isDirectlyMatched = contains(getOptionLabel(o), search);
13043
+ const children = o.children?.flatMap((oc) => matchedOptions(oc, level + 1, hasMatchedParent || isDirectlyMatched));
13044
+ if (!isDirectlyMatched && !hasMatchedParent && !children?.length) return [];
13045
+ const isCollapsed = collapsedKeys.includes(valueToKey(getOptionValue(o)));
13046
+ return isCollapsed ? [[o, level]] : [[o, level], ...children ?? []];
13047
+ }
13044
13048
  }
13045
13049
  function isOptionFullySelected(option, selectedKeys, disabledKeys, groupKeys, getOptionValue) {
13046
13050
  const key = valueToKey(getOptionValue(option));
@@ -25781,6 +25785,7 @@ function FormSectionLayout(props) {
25781
25785
  title,
25782
25786
  description,
25783
25787
  actions,
25788
+ initialFields,
25784
25789
  sections
25785
25790
  } = props;
25786
25791
  const tid = useTestIds(props, "formSectionLayout");
@@ -25799,6 +25804,7 @@ function FormSectionLayout(props) {
25799
25804
  ] }),
25800
25805
  actions && /* @__PURE__ */ (0, import_jsx_runtime207.jsx)("div", { className: "df gap1 fs0", ...tid.actions, children: actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime207.jsx)(Button, { ...action }, `${action.label}`)) })
25801
25806
  ] }),
25807
+ initialFields,
25802
25808
  /* @__PURE__ */ (0, import_jsx_runtime207.jsx)("div", { className: "df fdc gap6", children: sections.map((section, i) => /* @__PURE__ */ (0, import_jsx_runtime207.jsx)(FormSection, { ...section }, defaultTestId(section.title) || i)) })
25803
25809
  ] });
25804
25810
  }