@homebound/beam 4.40.0 → 4.41.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.d.cts CHANGED
@@ -9533,6 +9533,8 @@ type GridTableLayoutProps<F extends Record<string, unknown>, R extends Kinded, X
9533
9533
  /** Shows "N Rows Selected · Clear" before the columns selector; Clear deselects every row. */
9534
9534
  selectionSummary?: boolean;
9535
9535
  hideEditColumns?: boolean;
9536
+ /** When set, columns that share a name use one Edit Columns switch. */
9537
+ shareColumnVisibility?: boolean;
9536
9538
  totalCount?: number;
9537
9539
  /** When true, shows a view toggle button and renders the table with `as="card"` when in card view. */
9538
9540
  withCardView?: boolean;
@@ -11030,6 +11032,8 @@ interface TriggerNoticeProps extends Omit<SnackbarNoticeProps, "id" | "onClose">
11030
11032
  type EditColumnsButtonProps<R extends Kinded> = {
11031
11033
  columns: GridColumn<R>[];
11032
11034
  api: GridTableApi<R>;
11035
+ /** When set, columns that share a name use one Edit Columns switch. */
11036
+ shareColumnVisibility?: boolean;
11033
11037
  defaultOpen?: boolean;
11034
11038
  } & Pick<OverlayTriggerProps, "placement" | "disabled" | "tooltip">;
11035
11039
  declare function EditColumnsButton<R extends Kinded>(props: EditColumnsButtonProps<R>): React$1.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -9533,6 +9533,8 @@ type GridTableLayoutProps<F extends Record<string, unknown>, R extends Kinded, X
9533
9533
  /** Shows "N Rows Selected · Clear" before the columns selector; Clear deselects every row. */
9534
9534
  selectionSummary?: boolean;
9535
9535
  hideEditColumns?: boolean;
9536
+ /** When set, columns that share a name use one Edit Columns switch. */
9537
+ shareColumnVisibility?: boolean;
9536
9538
  totalCount?: number;
9537
9539
  /** When true, shows a view toggle button and renders the table with `as="card"` when in card view. */
9538
9540
  withCardView?: boolean;
@@ -11030,6 +11032,8 @@ interface TriggerNoticeProps extends Omit<SnackbarNoticeProps, "id" | "onClose">
11030
11032
  type EditColumnsButtonProps<R extends Kinded> = {
11031
11033
  columns: GridColumn<R>[];
11032
11034
  api: GridTableApi<R>;
11035
+ /** When set, columns that share a name use one Edit Columns switch. */
11036
+ shareColumnVisibility?: boolean;
11033
11037
  defaultOpen?: boolean;
11034
11038
  } & Pick<OverlayTriggerProps, "placement" | "disabled" | "tooltip">;
11035
11039
  declare function EditColumnsButton<R extends Kinded>(props: EditColumnsButtonProps<R>): React$1.JSX.Element;
package/dist/index.js CHANGED
@@ -6283,7 +6283,7 @@ var ColumnState = class {
6283
6283
  constructor(states, storage, column2) {
6284
6284
  this.states = states;
6285
6285
  this.column = column2;
6286
- this.visible = storage.wasVisible(column2.id) ?? (column2.canHide ? !(column2.initHidden ?? true) : true);
6286
+ this.visible = !column2.canHide || (storage.wasVisible(column2.id) ?? !(column2.initHidden ?? true));
6287
6287
  if (this.visible && (storage.wasExpanded(column2.id) ?? column2.initExpanded)) {
6288
6288
  this.expanded = true;
6289
6289
  this.doExpand();
@@ -6294,10 +6294,17 @@ var ColumnState = class {
6294
6294
  children = void 0;
6295
6295
  visible = true;
6296
6296
  expanded = false;
6297
+ /**
6298
+ * Whether this column is shown. We check `canHide` here too b/c when `props.columns` changes,
6299
+ * `addColumn` can replace a hidden column's definition with one that can't be hidden.
6300
+ */
6301
+ get isVisible() {
6302
+ return this.visible || !this.column.canHide;
6303
+ }
6297
6304
  setVisible(visible) {
6298
- const wasVisible = this.visible;
6299
- this.visible = visible;
6300
- if (!wasVisible && visible && this.column.initExpanded && this.children === void 0) {
6305
+ const wasVisible = this.isVisible;
6306
+ this.visible = visible || !this.column.canHide;
6307
+ if (!wasVisible && this.visible && this.column.initExpanded && this.children === void 0) {
6301
6308
  this.expanded = true;
6302
6309
  this.doExpand();
6303
6310
  }
@@ -6321,9 +6328,13 @@ var ColumnState = class {
6321
6328
  this.children = expandColumns.map((ec) => this.states.addColumn(ec));
6322
6329
  }
6323
6330
  }
6331
+ /** Returns this column and all of its loaded children, whether visible and expanded or not. */
6332
+ get selfAndChildren() {
6333
+ return [this, ...(this.children ?? []).flatMap((c) => c.selfAndChildren)];
6334
+ }
6324
6335
  /** Returns this column, if visible, and its children, if expanded. */
6325
6336
  get maybeSelfAndChildren() {
6326
- if (!this.visible) {
6337
+ if (!this.isVisible) {
6327
6338
  return [];
6328
6339
  } else if (this.expanded && this.children) {
6329
6340
  return [this, ...this.children.flatMap((c) => c.maybeSelfAndChildren)];
@@ -7573,9 +7584,13 @@ var ColumnStates = class {
7573
7584
  allVisibleColumns(showIn) {
7574
7585
  return this.columns.flatMap((cs) => cs.maybeSelfAndChildren).filter((cs) => !cs.column.showIn || cs.column.showIn === showIn).filter((cs) => showIn === "csv" ? isContentColumn(cs.column) : true);
7575
7586
  }
7587
+ /**
7588
+ * Shows the current columns in `ids` and hides the others. Columns that can't be hidden, like layout gutters, stay shown.
7589
+ * Columns not currently in the table keep their visibility, so a column that's temporarily removed comes back as it was.
7590
+ */
7576
7591
  setVisibleColumns(ids) {
7577
- for (const cs of this.map.values()) {
7578
- cs.setVisible(cs.column.isLayoutGutter ? true : ids.includes(cs.column.id));
7592
+ for (const cs of this.columns.flatMap((c) => c.selfAndChildren)) {
7593
+ cs.setVisible(ids.includes(cs.column.id));
7579
7594
  }
7580
7595
  }
7581
7596
  loadExpanded(storageKey) {
@@ -25124,7 +25139,8 @@ function EditColumnsButton(props) {
25124
25139
  defaultOpen,
25125
25140
  disabled,
25126
25141
  columns,
25127
- api
25142
+ api,
25143
+ shareColumnVisibility = false
25128
25144
  } = props;
25129
25145
  const state = useMenuTriggerState4({
25130
25146
  defaultOpen
@@ -25139,26 +25155,13 @@ function EditColumnsButton(props) {
25139
25155
  const {
25140
25156
  sm
25141
25157
  } = useBreakpoint();
25142
- const options = useMemo42(() => columns.filter((column2) => column2.canHide).filter((column2) => {
25143
- if (!column2.name || column2.name.length === 0 || !column2.id || column2.id.length === 0) {
25144
- console.warn("Column is missing 'name' and/or 'id' property required by the Edit Columns button", column2);
25145
- return false;
25146
- }
25147
- return true;
25148
- }).map((column2) => ({
25149
- label: column2.name,
25150
- value: column2.id,
25151
- tooltip: column2.tooltip
25152
- })), [columns]);
25158
+ const options = useMemo42(() => buildColumnOptions(columns, shareColumnVisibility), [columns, shareColumnVisibility]);
25153
25159
  const selectedValues = useComputed(() => api.getVisibleColumnIds(), [api]);
25154
25160
  const setSelectedValues = useCallback27((ids) => {
25155
25161
  api.resetColumnWidths();
25156
25162
  api.setVisibleColumns(columns.filter((column2) => column2.canHide ? ids.includes(column2.id) : true).map((c) => c.id));
25157
25163
  }, [columns, api]);
25158
- const hasHiddenColumn = useMemo42(() => {
25159
- const selectableOptionValues = options.map((option) => option.value);
25160
- return selectableOptionValues.some((option) => !selectedValues.includes(option));
25161
- }, [options, selectedValues]);
25164
+ const hasHiddenColumn = useMemo42(() => options.some((option) => option.ids.some((id) => !selectedValues.includes(id))), [options, selectedValues]);
25162
25165
  return /* @__PURE__ */ jsx179(OverlayTrigger, { ...props, trigger: sm ? {
25163
25166
  icon: hasHiddenColumn ? "columnsBadged" : "columns",
25164
25167
  variant: "outline"
@@ -25186,7 +25189,7 @@ function EditColumnsButton(props) {
25186
25189
  /* @__PURE__ */ jsx179("span", { className: "fw4 fz_14px lh_20px mw0", children: option.label }),
25187
25190
  option.tooltip ? /* @__PURE__ */ jsx179(ColumnTooltipIcon, { ...tid[`tooltip_${option.value}`], tooltip: closeMenuOnClickTooltip(option.tooltip, state.close), color: "--b-text-link-default" /* TextLinkDefault */, label: option.label }) : null
25188
25191
  ] }),
25189
- /* @__PURE__ */ jsx179(Switch, { compact: true, selected: selectedValues.includes(option.value), onChange: (value) => setSelectedValues(value ? [...selectedValues, option.value] : selectedValues.filter((v) => v !== option.value)), labelStyle: "hidden", label: option.label, ...tid[`option${option.value}`] })
25192
+ /* @__PURE__ */ jsx179(Switch, { compact: true, selected: option.ids.every((id) => selectedValues.includes(id)), onChange: (value) => setSelectedValues(value ? [...selectedValues, ...option.ids] : selectedValues.filter((id) => !option.ids.includes(id))), labelStyle: "hidden", label: option.label, ...tid[`option${option.value}`] })
25190
25193
  ] }, option.value)) }),
25191
25194
  /* @__PURE__ */ jsx179("div", { ...trussProps105({
25192
25195
  display: "df",
@@ -25203,6 +25206,54 @@ function EditColumnsButton(props) {
25203
25206
  }), children: /* @__PURE__ */ jsx179(Button, { variant: "tertiary", label: "Reset Column Widths", onClick: () => api.resetColumnWidths() }) })
25204
25207
  ] }) });
25205
25208
  }
25209
+ function buildColumnOptions(columns, shareColumnVisibility) {
25210
+ const hideable = columns.filter((column2) => {
25211
+ if (!column2.canHide) return false;
25212
+ if (!column2.name || column2.name.length === 0 || !column2.id || column2.id.length === 0) {
25213
+ console.warn("Column is missing 'name' and/or 'id' property required by the Edit Columns button", column2);
25214
+ return false;
25215
+ }
25216
+ return true;
25217
+ });
25218
+ if (!shareColumnVisibility) {
25219
+ return hideable.map((column2) => ({
25220
+ label: column2.name,
25221
+ value: column2.id,
25222
+ ids: [column2.id],
25223
+ tooltip: column2.tooltip
25224
+ }));
25225
+ }
25226
+ const byLabel = /* @__PURE__ */ new Map();
25227
+ const warnedLabels = /* @__PURE__ */ new Set();
25228
+ for (const column2 of hideable) {
25229
+ const label = leafColumnName(column2);
25230
+ const existing = byLabel.get(label);
25231
+ if (!existing) {
25232
+ byLabel.set(label, {
25233
+ label,
25234
+ value: column2.id,
25235
+ ids: [column2.id],
25236
+ tooltip: column2.tooltip
25237
+ });
25238
+ continue;
25239
+ }
25240
+ existing.ids.push(column2.id);
25241
+ if (existing.tooltip !== column2.tooltip && !warnedLabels.has(label)) {
25242
+ warnedLabels.add(label);
25243
+ console.warn(`Edit Columns columns labeled "${label}" have different tooltips. Using the first.`);
25244
+ }
25245
+ }
25246
+ return [...byLabel.values()];
25247
+ }
25248
+ function leafColumnName(column2) {
25249
+ const {
25250
+ name,
25251
+ groupLabel
25252
+ } = column2;
25253
+ const prefix = groupLabel ? `${groupLabel}: ` : void 0;
25254
+ if (name && prefix && name.startsWith(prefix)) return name.slice(prefix.length);
25255
+ return name;
25256
+ }
25206
25257
  function closeMenuOnClickTooltip(tooltip, closeMenu) {
25207
25258
  if (typeof tooltip !== "function") return tooltip;
25208
25259
  return () => {
@@ -25427,6 +25478,7 @@ function GridTableLayoutActionsComponent(props) {
25427
25478
  searchProps,
25428
25479
  hasHideableColumns,
25429
25480
  columns,
25481
+ shareColumnVisibility,
25430
25482
  api,
25431
25483
  withCardView,
25432
25484
  view,
@@ -25520,7 +25572,7 @@ function GridTableLayoutActionsComponent(props) {
25520
25572
  ] }),
25521
25573
  (hasHideableColumns || withCardView || !!actions?.length || selectionSummary) && /* @__PURE__ */ jsxs96("div", { className: "df aic g_12px", children: [
25522
25574
  selectionSummary && api && /* @__PURE__ */ jsx184(SelectionSummaryAction, { api, numberOnly: sm }),
25523
- hasHideableColumns && view === "list" && columns && api && /* @__PURE__ */ jsx184(EditColumnsButton, { columns, api, tooltip: "Display columns" }),
25575
+ hasHideableColumns && view === "list" && columns && api && /* @__PURE__ */ jsx184(EditColumnsButton, { columns, api, shareColumnVisibility, tooltip: "Display columns" }),
25524
25576
  withCardView && view !== void 0 && setView && /* @__PURE__ */ jsx184(ViewToggleButton, { view, onChange: setView }),
25525
25577
  !!actions?.length && /* @__PURE__ */ jsx184(HeaderActions, { actions, ...testId.actions })
25526
25578
  ] })
@@ -26399,6 +26451,7 @@ function GridTableLayoutComponent(props) {
26399
26451
  actions,
26400
26452
  selectionSummary = false,
26401
26453
  hideEditColumns = false,
26454
+ shareColumnVisibility = false,
26402
26455
  withCardView,
26403
26456
  defaultView = "list",
26404
26457
  emptyFallback: layoutEmptyFallback,
@@ -26453,6 +26506,7 @@ function GridTableLayoutComponent(props) {
26453
26506
  searchProps: filterSearchProps,
26454
26507
  hasHideableColumns,
26455
26508
  columns,
26509
+ shareColumnVisibility,
26456
26510
  api,
26457
26511
  withCardView,
26458
26512
  view,