@homebound/beam 4.56.3 → 4.57.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
@@ -19156,6 +19156,89 @@ var import_runtime86 = require("@homebound/truss/runtime");
19156
19156
  // src/inputs/MenuSelectField/MenuSelectField.tsx
19157
19157
  var import_react86 = require("react");
19158
19158
 
19159
+ // src/inputs/Value.ts
19160
+ var VALUE_PREFIX = "__VALUE--";
19161
+ function keyToValue(key) {
19162
+ if (typeof key === "number") {
19163
+ return key;
19164
+ } else if (typeof key === "string") {
19165
+ if (key === `${VALUE_PREFIX}null` || key === "__VALUE:null") {
19166
+ return null;
19167
+ } else if (key === `${VALUE_PREFIX}undefined` || key === "__VALUE:undefined") {
19168
+ return void 0;
19169
+ } else if (key.startsWith(`${VALUE_PREFIX}boolean--`) || key.startsWith("__VALUE:boolean:")) {
19170
+ const parts = key.includes("--boolean--") ? key.split("--") : key.split(":");
19171
+ return parts[parts.length - 1] === "true";
19172
+ } else if (key.startsWith(`${VALUE_PREFIX}number--`) || key.startsWith("__VALUE:number:")) {
19173
+ const parts = key.includes("--number--") ? key.split("--") : key.split(":");
19174
+ return Number(parts[parts.length - 1]);
19175
+ } else {
19176
+ return key;
19177
+ }
19178
+ } else {
19179
+ throw new Error(`Unsupported key ${key}`);
19180
+ }
19181
+ }
19182
+ function valueToKey(value) {
19183
+ if (typeof value === "string") {
19184
+ return value;
19185
+ } else if (typeof value === "number") {
19186
+ return `${VALUE_PREFIX}number--${value}`;
19187
+ } else if (typeof value === "boolean") {
19188
+ return `${VALUE_PREFIX}boolean--${value}`;
19189
+ } else if (value === null) {
19190
+ return `${VALUE_PREFIX}null`;
19191
+ } else if (value === void 0) {
19192
+ return `${VALUE_PREFIX}undefined`;
19193
+ } else {
19194
+ throw new Error(`Unsupported value ${value}`);
19195
+ }
19196
+ }
19197
+
19198
+ // src/inputs/internal/selectFieldHelpers.ts
19199
+ function initializeOptions(optionsOrLoad, getOptionValue, getOptionLabel, unsetLabel, autoSort) {
19200
+ const result = [];
19201
+ if (unsetLabel) {
19202
+ result.push(unsetOption);
19203
+ }
19204
+ const userOptions = [];
19205
+ if (Array.isArray(optionsOrLoad)) {
19206
+ userOptions.push(...optionsOrLoad);
19207
+ } else {
19208
+ const { options, current: current2 } = optionsOrLoad;
19209
+ if (options) {
19210
+ userOptions.push(...options);
19211
+ }
19212
+ if (current2) {
19213
+ const toCheck = Array.isArray(current2) ? current2 : [current2];
19214
+ toCheck.forEach((current3) => {
19215
+ const value = getOptionValue(current3);
19216
+ const found = options && options.find((o) => getOptionValue(o) === value);
19217
+ if (!found) {
19218
+ userOptions.push(current3);
19219
+ }
19220
+ });
19221
+ }
19222
+ }
19223
+ result.push(...autoSort ? sortOptions(userOptions, getOptionLabel) : userOptions);
19224
+ return result;
19225
+ }
19226
+ var unsetOption = {};
19227
+ function disabledOptionToKeyedTuple(disabledOption) {
19228
+ if (typeof disabledOption === "object" && disabledOption !== null) {
19229
+ return [valueToKey(disabledOption.value), disabledOption.reason];
19230
+ } else {
19231
+ return [valueToKey(disabledOption), void 0];
19232
+ }
19233
+ }
19234
+ function sortOptions(options, getOptionLabel) {
19235
+ return [...options].sort((a, b) => {
19236
+ const labelA = getOptionLabel(a).toLowerCase();
19237
+ const labelB = getOptionLabel(b).toLowerCase();
19238
+ return labelA.localeCompare(labelB);
19239
+ });
19240
+ }
19241
+
19159
19242
  // src/inputs/MenuSelectField/internal/AnchoredOverlay.tsx
19160
19243
  var import_react80 = require("react");
19161
19244
  var import_react_aria31 = require("react-aria");
@@ -20155,89 +20238,6 @@ var import_react85 = require("react");
20155
20238
  var import_react_aria37 = require("react-aria");
20156
20239
  var import_react_stately7 = require("react-stately");
20157
20240
 
20158
- // src/inputs/Value.ts
20159
- var VALUE_PREFIX = "__VALUE--";
20160
- function keyToValue(key) {
20161
- if (typeof key === "number") {
20162
- return key;
20163
- } else if (typeof key === "string") {
20164
- if (key === `${VALUE_PREFIX}null` || key === "__VALUE:null") {
20165
- return null;
20166
- } else if (key === `${VALUE_PREFIX}undefined` || key === "__VALUE:undefined") {
20167
- return void 0;
20168
- } else if (key.startsWith(`${VALUE_PREFIX}boolean--`) || key.startsWith("__VALUE:boolean:")) {
20169
- const parts = key.includes("--boolean--") ? key.split("--") : key.split(":");
20170
- return parts[parts.length - 1] === "true";
20171
- } else if (key.startsWith(`${VALUE_PREFIX}number--`) || key.startsWith("__VALUE:number:")) {
20172
- const parts = key.includes("--number--") ? key.split("--") : key.split(":");
20173
- return Number(parts[parts.length - 1]);
20174
- } else {
20175
- return key;
20176
- }
20177
- } else {
20178
- throw new Error(`Unsupported key ${key}`);
20179
- }
20180
- }
20181
- function valueToKey(value) {
20182
- if (typeof value === "string") {
20183
- return value;
20184
- } else if (typeof value === "number") {
20185
- return `${VALUE_PREFIX}number--${value}`;
20186
- } else if (typeof value === "boolean") {
20187
- return `${VALUE_PREFIX}boolean--${value}`;
20188
- } else if (value === null) {
20189
- return `${VALUE_PREFIX}null`;
20190
- } else if (value === void 0) {
20191
- return `${VALUE_PREFIX}undefined`;
20192
- } else {
20193
- throw new Error(`Unsupported value ${value}`);
20194
- }
20195
- }
20196
-
20197
- // src/inputs/internal/selectFieldHelpers.ts
20198
- function initializeOptions(optionsOrLoad, getOptionValue, getOptionLabel, unsetLabel, autoSort) {
20199
- const result = [];
20200
- if (unsetLabel) {
20201
- result.push(unsetOption);
20202
- }
20203
- const userOptions = [];
20204
- if (Array.isArray(optionsOrLoad)) {
20205
- userOptions.push(...optionsOrLoad);
20206
- } else {
20207
- const { options, current: current2 } = optionsOrLoad;
20208
- if (options) {
20209
- userOptions.push(...options);
20210
- }
20211
- if (current2) {
20212
- const toCheck = Array.isArray(current2) ? current2 : [current2];
20213
- toCheck.forEach((current3) => {
20214
- const value = getOptionValue(current3);
20215
- const found = options && options.find((o) => getOptionValue(o) === value);
20216
- if (!found) {
20217
- userOptions.push(current3);
20218
- }
20219
- });
20220
- }
20221
- }
20222
- result.push(...autoSort ? sortOptions(userOptions, getOptionLabel) : userOptions);
20223
- return result;
20224
- }
20225
- var unsetOption = {};
20226
- function disabledOptionToKeyedTuple(disabledOption) {
20227
- if (typeof disabledOption === "object" && disabledOption !== null) {
20228
- return [valueToKey(disabledOption.value), disabledOption.reason];
20229
- } else {
20230
- return [valueToKey(disabledOption), void 0];
20231
- }
20232
- }
20233
- function sortOptions(options, getOptionLabel) {
20234
- return [...options].sort((a, b) => {
20235
- const labelA = getOptionLabel(a).toLowerCase();
20236
- const labelB = getOptionLabel(b).toLowerCase();
20237
- return labelA.localeCompare(labelB);
20238
- });
20239
- }
20240
-
20241
20241
  // src/inputs/MenuSelectField/internal/menuTree.ts
20242
20242
  function buildMenuTree(roots, getKey, getChildren) {
20243
20243
  const nodes = /* @__PURE__ */ new Map();
@@ -20419,10 +20419,11 @@ var import_jsx_runtime115 = require("react/jsx-runtime");
20419
20419
  function useMenuSelectField(props) {
20420
20420
  const {
20421
20421
  options: optionsProp,
20422
- getOptionValue = defaultOptionValue,
20423
- getOptionLabel = defaultOptionLabel,
20422
+ getOptionValue: propGetOptionValue = defaultOptionValue,
20423
+ getOptionLabel: propGetOptionLabel = defaultOptionLabel,
20424
20424
  getOptionMenuLabel,
20425
20425
  getOptionSearchText,
20426
+ unsetLabel,
20426
20427
  autoSort = true,
20427
20428
  onSearch,
20428
20429
  disabledOptions,
@@ -20465,11 +20466,13 @@ function useMenuSelectField(props) {
20465
20466
  const [search, setSearch] = (0, import_react85.useState)("");
20466
20467
  const [optionsLoading, setOptionsLoading] = (0, import_react85.useState)(false);
20467
20468
  const didRequestOptionsRef = (0, import_react85.useRef)(false);
20469
+ const getOptionLabel = (option) => unsetLabel && option === unsetOption ? unsetLabel : propGetOptionLabel(option);
20470
+ const getOptionValue = (option) => unsetLabel && option === unsetOption ? void 0 : propGetOptionValue(option);
20468
20471
  const options = (0, import_react85.useMemo)(
20469
- () => initializeOptions(optionsProp, getOptionValue, getOptionLabel, void 0, autoSort),
20472
+ () => initializeOptions(optionsProp, getOptionValue, getOptionLabel, unsetLabel, autoSort),
20470
20473
  // getOptionValue and getOptionLabel are typically inline lambdas
20471
20474
  // oxlint-disable-next-line react-hooks/exhaustive-deps
20472
- [optionsProp, autoSort]
20475
+ [optionsProp, autoSort, unsetLabel]
20473
20476
  );
20474
20477
  const { hoverProps, isHovered } = (0, import_react_aria37.useHover)({});
20475
20478
  const { focusProps, isFocusVisible } = (0, import_react_aria37.useFocusRing)();
@@ -20536,10 +20539,12 @@ function useMenuSelectField(props) {
20536
20539
  );
20537
20540
  }, [menuTree, allOptions, search, serverSearch, contains, expandedKeys, searchCollapsedKeys]);
20538
20541
  const filteredOptions = (0, import_react85.useMemo)(
20539
- () => menuTree || !search || serverSearch ? options : options.filter((o) => matchesSearch(o, search, getOptionLabel, getOptionSearchText, contains)),
20542
+ () => menuTree || !search || serverSearch ? options : options.filter(
20543
+ (option) => unsetLabel && option === unsetOption ? contains(getOptionLabel(option), search) : matchesSearch(option, search, getOptionLabel, getOptionSearchText, contains)
20544
+ ),
20540
20545
  // getOptionLabel and getOptionSearchText are typically inline lambdas
20541
20546
  // oxlint-disable-next-line react-hooks/exhaustive-deps
20542
- [menuTree, options, search, serverSearch, contains]
20547
+ [menuTree, options, search, serverSearch, contains, unsetLabel]
20543
20548
  );
20544
20549
  function onSelectionChange(keys) {
20545
20550
  if (keys === "all") return;
@@ -20589,7 +20594,7 @@ function useMenuSelectField(props) {
20589
20594
  }, [treeRows, filteredOptions]);
20590
20595
  const state = (0, import_react_stately7.useListState)({
20591
20596
  items: collectionItems,
20592
- children: (item) => /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(import_react_stately7.Item, { textValue: getOptionLabel(item.option), children: getOptionMenuLabel ? getOptionMenuLabel(item.option) : getOptionLabel(item.option) }, item.key),
20597
+ children: (item) => /* @__PURE__ */ (0, import_jsx_runtime115.jsx)(import_react_stately7.Item, { textValue: getOptionLabel(item.option), children: getOptionMenuLabel ? getOptionMenuLabel(item.option, Boolean(unsetLabel) && item.option === unsetOption) : getOptionLabel(item.option) }, item.key),
20593
20598
  selectionMode: multiple ? "multiple" : "single",
20594
20599
  selectedKeys: selectedRowKeys,
20595
20600
  disabledKeys: disabledRowKeys,
@@ -20980,17 +20985,24 @@ function BaseMenuSelectField(props) {
20980
20985
  // src/inputs/MenuSelectField/MenuSelectField.tsx
20981
20986
  var import_jsx_runtime117 = require("react/jsx-runtime");
20982
20987
  function MenuSelectField(props) {
20983
- const { value, proposedValue, onSelect, ...rest } = props;
20984
- const values = (0, import_react86.useMemo)(() => value === void 0 ? [] : [value], [value]);
20988
+ const { value, proposedValue, onSelect, unsetLabel, ...rest } = props;
20989
+ const values = (0, import_react86.useMemo)(() => {
20990
+ if (value !== void 0) return [value];
20991
+ return unsetLabel ? [void 0] : [];
20992
+ }, [value, unsetLabel]);
20985
20993
  const proposedValues = (0, import_react86.useMemo)(() => proposedValue === void 0 ? void 0 : [proposedValue], [proposedValue]);
20986
20994
  return /* @__PURE__ */ (0, import_jsx_runtime117.jsx)(
20987
20995
  BaseMenuSelectField,
20988
20996
  {
20989
20997
  ...rest,
20998
+ unsetLabel,
20990
20999
  selectionMode: "single",
20991
21000
  values,
20992
21001
  proposedValues,
20993
- onCommit: (next, opts) => onSelect(next[0], opts[0])
21002
+ onCommit: (next, opts) => {
21003
+ const option = opts[0];
21004
+ onSelect(next[0], option === unsetOption ? void 0 : option);
21005
+ }
20994
21006
  }
20995
21007
  );
20996
21008
  }
@@ -32000,7 +32012,6 @@ var import_jsx_runtime241 = require("react/jsx-runtime");
32000
32012
  function singleFilter(props) {
32001
32013
  return (key) => new SingleFilter(key, props);
32002
32014
  }
32003
- var allOption = {};
32004
32015
  var SingleFilter = class extends BaseFilter {
32005
32016
  formatSelectedFilterLabel(value) {
32006
32017
  const { options } = this.props;
@@ -32008,26 +32019,15 @@ var SingleFilter = class extends BaseFilter {
32008
32019
  return resolveOptionSelectedFilterLabel(options, getOptionValue, getOptionLabel, value);
32009
32020
  }
32010
32021
  render(value, setValue, tid, inModal, vertical) {
32011
- const { label, defaultValue, options: maybeOptions, nothingSelectedText, autoSort, ...props } = this.props;
32012
- const { getOptionValue, getOptionLabel } = optionReaders2(this.props);
32013
- const unsetText = nothingSelectedText ?? "All";
32014
- const isStaticList = Array.isArray(maybeOptions);
32015
- const options = isStaticList ? [
32016
- allOption,
32017
- ...initializeOptions(maybeOptions, getOptionValue, getOptionLabel, void 0, autoSort ?? true)
32018
- ] : maybeOptions;
32022
+ const { label, defaultValue, nothingSelectedText, unsetLabel, ...props } = this.props;
32019
32023
  return /* @__PURE__ */ (0, import_jsx_runtime241.jsx)(
32020
32024
  MenuSelectField,
32021
32025
  {
32022
32026
  ...props,
32023
- autoSort: isStaticList ? false : autoSort,
32024
- options,
32025
- getOptionValue: (option) => option === allOption ? void 0 : getOptionValue(option),
32026
- getOptionLabel: (option) => option === allOption ? unsetText : getOptionLabel(option),
32027
+ unsetLabel: unsetLabel ?? nothingSelectedText ?? "All",
32027
32028
  value,
32028
32029
  label: this.label,
32029
32030
  labelStyle: inModal ? "hidden" : !inModal && !vertical ? "inline" : "above",
32030
- nothingSelectedText: unsetText,
32031
32031
  onSelect: (next) => setValue(next || void 0),
32032
32032
  ...this.testId(tid)
32033
32033
  }