@linzjs/step-ag-grid 32.7.0 → 33.0.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.
Files changed (58) hide show
  1. package/dist/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
  2. package/dist/step-ag-grid.cjs +115 -181
  3. package/dist/step-ag-grid.cjs.map +1 -1
  4. package/dist/step-ag-grid.esm.js +115 -181
  5. package/dist/step-ag-grid.esm.js.map +1 -1
  6. package/package.json +17 -17
  7. package/src/components/Grid.tsx +6 -4
  8. package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
  9. package/src/components/gridHook/useGridRangeSelection.ts +8 -6
  10. package/src/react-menu3/components/ControlledMenu.tsx +5 -3
  11. package/src/react-menu3/components/MenuList.tsx +6 -3
  12. package/src/react-menu3/hooks/useItems.ts +1 -1
  13. package/src/stories/components/ActionButton.stories.tsx +12 -11
  14. package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
  15. package/src/stories/grid/GridCopy.stories.tsx +38 -35
  16. package/src/stories/grid/GridDragRow.stories.tsx +41 -36
  17. package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
  18. package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
  19. package/src/stories/grid/GridInlineText.stories.tsx +42 -35
  20. package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
  21. package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
  22. package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
  23. package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
  24. package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
  25. package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
  26. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
  27. package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
  28. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
  29. package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
  30. package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
  31. package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
  32. package/src/stories/grid/GridSorting.stories.tsx +81 -79
  33. package/src/stories/grid/GridViewList.stories.tsx +31 -26
  34. package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
  35. package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
  36. package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
  37. package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
  38. package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
  39. package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
  40. package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
  41. package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
  42. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
  43. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
  44. package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
  45. package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
  46. package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
  47. package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
  48. package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
  49. package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
  50. package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
  51. package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
  52. package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
  53. package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
  54. package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
  55. package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
  56. package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
  57. package/src/styles/GridLoadableCell.scss +1 -1
  58. package/src/utils/useSharedInterval.ts +3 -3
@@ -3,7 +3,6 @@ import { LuiMiniSpinner, LuiIcon, useShowLUIMessage, LuiStatusSpinner, LuiButton
3
3
  import React13, { forwardRef, useContext, useRef, useState, useImperativeHandle, useLayoutEffect, useCallback, useMemo, createContext, memo, useEffect, createElement, Suspense, Component as Component$1, useReducer, cloneElement, Fragment as Fragment$1, useId } from 'react';
4
4
  import ReactDOM, { createPortal, unstable_batchedUpdates, flushSync } from 'react-dom';
5
5
  import { negate, isEmpty, findIndex, defer, debounce as debounce$1, compact, xorBy, last, difference, omit, delay, sortBy, partition, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
6
- import { createRoot } from 'react-dom/client';
7
6
 
8
7
  const ComponentLoadingWrapper = (props) => {
9
8
  return props.loading ? /* @__PURE__ */ jsx(LuiMiniSpinner, { size: 22, divProps: { role: "status", ["aria-label"]: "Loading", style: { padding: 16 } } }) : /* @__PURE__ */ jsxs("div", { style: { pointerEvents: props.saving ? "none" : "inherit" }, className: props.className, children: [
@@ -57821,6 +57820,13 @@ var AgGridReact = class extends Component$1 {
57821
57820
  return /* @__PURE__ */ React13.createElement(AgGridReactUi, { ...this.props, passGridApi: this.setGridApi });
57822
57821
  }
57823
57822
  };
57823
+ function useGridCustomComponent(methods) {
57824
+ const { setMethods } = useContext(CustomContext);
57825
+ setMethods(methods);
57826
+ }
57827
+ function useGridFilter$1(callbacks) {
57828
+ return useGridCustomComponent(callbacks);
57829
+ }
57824
57830
 
57825
57831
  function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
57826
57832
 
@@ -58560,7 +58566,7 @@ const useItems = (menuRef, focusRef) => {
58560
58566
  const index = items.indexOf(item);
58561
58567
  if (index > -1) {
58562
58568
  items.splice(index, 1);
58563
- if (item.contains(document.activeElement)) {
58569
+ if (item.contains(item.ownerDocument.activeElement)) {
58564
58570
  focusRef?.current?.focus();
58565
58571
  setHoverItem(void 0);
58566
58572
  }
@@ -59255,7 +59261,8 @@ const MenuList = ({
59255
59261
  return;
59256
59262
  }
59257
59263
  if (!scrollNodes.menu) {
59258
- scrollNodes.menu = (boundingBoxRef ? boundingBoxRef.current : getScrollAncestor(rootMenuRef?.current)) || window;
59264
+ const thisWindow = containerRef.current.ownerDocument.defaultView ?? window;
59265
+ scrollNodes.menu = (boundingBoxRef ? boundingBoxRef.current : getScrollAncestor(rootMenuRef?.current)) || thisWindow;
59259
59266
  }
59260
59267
  const positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
59261
59268
  const { menuRect } = positionHelpers;
@@ -59347,7 +59354,8 @@ const MenuList = ({
59347
59354
  useEffect(() => {
59348
59355
  let { menu: menuScroll } = scrollNodes;
59349
59356
  if (!isOpen || !menuScroll) return;
59350
- menuScroll = menuScroll.addEventListener ? menuScroll : window;
59357
+ const thisWindow = containerRef?.current?.ownerDocument.defaultView ?? window;
59358
+ menuScroll = menuScroll.addEventListener ? menuScroll : thisWindow;
59351
59359
  if (!scrollNodes.anchors) {
59352
59360
  scrollNodes.anchors = [];
59353
59361
  let anchorScroll = getScrollAncestor(rootAnchorRef && rootAnchorRef.current);
@@ -59453,7 +59461,7 @@ const MenuList = ({
59453
59461
  } else if (captureFocus) {
59454
59462
  const id = setTimeout(
59455
59463
  () => {
59456
- if (menuRef.current && !menuRef.current.contains(document.activeElement)) {
59464
+ if (menuRef.current && !menuRef.current.contains(menuRef.current.ownerDocument.activeElement)) {
59457
59465
  const popupElement = focusRef.current?.nextSibling;
59458
59466
  if (!focusFirstInput(popupElement)) {
59459
59467
  focusRef.current?.focus();
@@ -59805,7 +59813,7 @@ const ControlledMenuFr = ({
59805
59813
  }
59806
59814
  };
59807
59815
  const onBlur = (e) => {
59808
- if (isMenuOpen(state) && !e.currentTarget.contains(e.relatedTarget || document.activeElement) && !isWithinMenu(e.relatedTarget)) {
59816
+ if (isMenuOpen(state) && !e.currentTarget.contains(e.relatedTarget || e.currentTarget.ownerDocument.activeElement) && !isWithinMenu(e.relatedTarget)) {
59809
59817
  safeCall(onClose, { reason: CloseReason.BLUR });
59810
59818
  if (skipOpen) {
59811
59819
  skipOpen.current = true;
@@ -59847,8 +59855,9 @@ const ControlledMenuFr = ({
59847
59855
  }
59848
59856
  if (portal) {
59849
59857
  if (typeof portal === "boolean") {
59850
- if (portal && typeof document !== "undefined") {
59851
- return createPortal(menuList, document.body);
59858
+ const thisDocument = containerRef.current?.ownerDocument ?? (typeof document !== "undefined" ? document : void 0);
59859
+ if (portal && thisDocument) {
59860
+ return createPortal(menuList, thisDocument.body);
59852
59861
  }
59853
59862
  } else {
59854
59863
  return portal.target ? createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
@@ -60863,13 +60872,14 @@ const useGridRangeSelection = ({
60863
60872
  [rangeEndRef]
60864
60873
  );
60865
60874
  useEffect(() => {
60866
- document.addEventListener("mousedown", trackMouseDown, { capture: true });
60867
- document.addEventListener("mouseup", trackMouseUp, { capture: true });
60875
+ const doc = gridDivRef.current?.ownerDocument;
60876
+ doc?.addEventListener("mousedown", trackMouseDown, { capture: true });
60877
+ doc?.addEventListener("mouseup", trackMouseUp, { capture: true });
60868
60878
  return () => {
60869
- document.removeEventListener("mousemove", trackMouseDown, { capture: true });
60870
- document.removeEventListener("mouseup", trackMouseUp, { capture: true });
60879
+ doc?.removeEventListener("mousemove", trackMouseDown, { capture: true });
60880
+ doc?.removeEventListener("mouseup", trackMouseUp, { capture: true });
60871
60881
  };
60872
- }, [trackMouseDown, trackMouseUp]);
60882
+ }, [trackMouseDown, trackMouseUp, gridDivRef]);
60873
60883
  const onCellMouseOver = useCallback(
60874
60884
  (e, mouseDown) => {
60875
60885
  if (!enableRangeSelection) {
@@ -60894,7 +60904,7 @@ const useGridRangeSelection = ({
60894
60904
  if (rangeStartRef.current && rangeEndRef.current && (rangeStartRef.current.rowId !== rangeEndRef.current.rowId || rangeStartRef.current.colId !== rangeEndRef.current.colId)) {
60895
60905
  e.api.stopEditing();
60896
60906
  hasSelectedMoreThanOneCellRef.current = true;
60897
- window.getSelection()?.removeAllRanges();
60907
+ gridDivRef.current?.ownerDocument.defaultView?.getSelection()?.removeAllRanges();
60898
60908
  }
60899
60909
  updateRangeSelectionCellClasses();
60900
60910
  },
@@ -60904,7 +60914,8 @@ const useGridRangeSelection = ({
60904
60914
  hasSelectedMoreThanOneCellRef,
60905
60915
  rangeEndRef,
60906
60916
  rangeSortedNodesRef,
60907
- rangeStartRef
60917
+ rangeStartRef,
60918
+ gridDivRef
60908
60919
  ]
60909
60920
  );
60910
60921
  const onCellMouseDown = useCallback(
@@ -61420,7 +61431,7 @@ const Grid = ({
61420
61431
  const api = event.api;
61421
61432
  if (sizeColumns === "fit") {
61422
61433
  delay(() => {
61423
- if (!anyUpdating() && document.querySelectorAll(".szh-menu--state-open").length === 0) {
61434
+ if (!anyUpdating() && !gridDivRef.current?.ownerDocument.querySelectorAll(".szh-menu--state-open").length) {
61424
61435
  if (!api.isDestroyed()) {
61425
61436
  api.redrawRows();
61426
61437
  }
@@ -61629,15 +61640,17 @@ const Grid = ({
61629
61640
  }, [params.loading, rowData, showNoRowsOverlay]);
61630
61641
  const startDragYRef = useRef(null);
61631
61642
  const clearHighlightRowClasses = useCallback(() => {
61632
- document.querySelectorAll(`.ag-row-highlight-above`)?.forEach((el) => {
61643
+ const gridRoot = gridDivRef.current;
61644
+ gridRoot?.querySelectorAll(`.ag-row-highlight-above`)?.forEach((el) => {
61633
61645
  el.classList.remove("ag-row-highlight-above");
61634
61646
  });
61635
- document.querySelectorAll(`.ag-row-highlight-below`)?.forEach((el) => {
61647
+ gridRoot?.querySelectorAll(`.ag-row-highlight-below`)?.forEach((el) => {
61636
61648
  el.classList.remove("ag-row-highlight-below");
61637
61649
  });
61638
61650
  }, []);
61639
61651
  const clearDragRowClasses = useCallback(() => {
61640
- document.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
61652
+ const gridRoot = gridDivRef.current;
61653
+ gridRoot?.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
61641
61654
  el.classList.remove("ag-row-dragging");
61642
61655
  });
61643
61656
  }, []);
@@ -62215,20 +62228,87 @@ const EMPTY_KEY = "__EMPTY__";
62215
62228
  const DEFAULT_EMPTY_LABEL = "-";
62216
62229
  const filterStateMap = /* @__PURE__ */ new Map();
62217
62230
  const filterClickCountMap = /* @__PURE__ */ new Map();
62218
- const FilterUI = ({
62219
- allValues,
62220
- selected,
62221
- labels,
62222
- labelFormatter,
62223
- onToggleAll,
62224
- onToggleOne
62225
- }) => {
62231
+ const normalizeCellValue = (value) => {
62232
+ if (typeof value === "string") return value.trim() === "" ? EMPTY_KEY : value;
62233
+ return EMPTY_KEY;
62234
+ };
62235
+ const loadFieldValues = (params) => {
62236
+ const field = params.colDef.field;
62237
+ const values = /* @__PURE__ */ new Set();
62238
+ params.api.forEachNode((node) => {
62239
+ const data = node.data ?? {};
62240
+ values.add(normalizeCellValue(data[field]));
62241
+ });
62242
+ const { customOrder } = params;
62243
+ const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
62244
+ return Array.from(values).sort((a, b) => {
62245
+ if (orderMap) {
62246
+ const aIdx = orderMap.get(a) ?? Infinity;
62247
+ const bIdx = orderMap.get(b) ?? Infinity;
62248
+ if (aIdx !== bIdx) return aIdx - bIdx;
62249
+ }
62250
+ if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
62251
+ if (b === EMPTY_KEY) return 1;
62252
+ return a.localeCompare(b);
62253
+ });
62254
+ };
62255
+ const GridFilterColumnsMultiSelect = (props) => {
62256
+ const { model, onModelChange, colDef, column, labels: labelsParam, labelFormatter } = props;
62257
+ const containerRef = useRef(null);
62258
+ const allValues = useMemo(() => loadFieldValues(props), []);
62259
+ const labels = useMemo(
62260
+ () => ({ [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labelsParam }),
62261
+ [labelsParam]
62262
+ );
62263
+ const selected = useMemo(() => new Set(model?.values ?? allValues), [model, allValues]);
62264
+ useGridFilter$1({
62265
+ doesFilterPass: (p) => {
62266
+ if (selected.size === 0) return false;
62267
+ const field = colDef.field;
62268
+ if (!p.data || typeof p.data !== "object") return selected.has(EMPTY_KEY);
62269
+ const raw = p.data[field];
62270
+ return selected.has(normalizeCellValue(raw));
62271
+ }
62272
+ });
62273
+ useEffect(() => {
62274
+ const ownerDocument = containerRef.current?.ownerDocument;
62275
+ const columnId = column.getColId();
62276
+ const filterButton = ownerDocument?.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
62277
+ if (!filterButton) {
62278
+ return;
62279
+ }
62280
+ const listener = (e) => {
62281
+ const clickCount = filterClickCountMap.get(columnId) || 0;
62282
+ filterClickCountMap.set(columnId, clickCount + 1);
62283
+ if (clickCount === 0) {
62284
+ e.stopImmediatePropagation();
62285
+ e.preventDefault();
62286
+ props.api.hidePopupMenu();
62287
+ filterStateMap.set(columnId, false);
62288
+ return;
62289
+ }
62290
+ const isOpen = filterStateMap.get(columnId) || false;
62291
+ if (isOpen) {
62292
+ e.stopImmediatePropagation();
62293
+ e.preventDefault();
62294
+ props.api.hidePopupMenu();
62295
+ filterStateMap.set(columnId, false);
62296
+ } else {
62297
+ filterStateMap.set(columnId, true);
62298
+ }
62299
+ };
62300
+ filterButton.addEventListener("click", listener, true);
62301
+ return () => filterButton.removeEventListener("click", listener, true);
62302
+ }, [column, props.api]);
62226
62303
  const allChecked = allValues.length > 0 && selected.size === allValues.length;
62227
62304
  const getDisplayLabel = (raw) => {
62228
62305
  const base = raw === EMPTY_KEY ? labels[EMPTY_KEY] ?? DEFAULT_EMPTY_LABEL : labels[raw] ?? raw;
62229
62306
  return labelFormatter ? labelFormatter(base) : base;
62230
62307
  };
62231
- return /* @__PURE__ */ jsxs("div", { className: "GridFilterColsMultiSelect", children: [
62308
+ const applySelection = (next) => {
62309
+ onModelChange(next.size === allValues.length ? null : { values: Array.from(next) });
62310
+ };
62311
+ return /* @__PURE__ */ jsxs("div", { className: "GridFilterColsMultiSelect", ref: containerRef, children: [
62232
62312
  /* @__PURE__ */ jsx("span", { className: "LuiSelect-label-text", children: "Filter column" }),
62233
62313
  /* @__PURE__ */ jsx(
62234
62314
  LuiCheckboxInput,
@@ -62237,7 +62317,7 @@ const FilterUI = ({
62237
62317
  label: "Select All",
62238
62318
  value: "true",
62239
62319
  isChecked: allChecked,
62240
- onChange: (e) => onToggleAll(e.target.checked)
62320
+ onChange: (e) => applySelection(e.target.checked ? new Set(allValues) : /* @__PURE__ */ new Set())
62241
62321
  }
62242
62322
  ),
62243
62323
  allValues.map((val) => /* @__PURE__ */ jsx(
@@ -62247,163 +62327,17 @@ const FilterUI = ({
62247
62327
  label: getDisplayLabel(val),
62248
62328
  value: val,
62249
62329
  isChecked: selected.has(val),
62250
- onChange: (e) => onToggleOne(val, e.target.checked)
62330
+ onChange: (e) => {
62331
+ const next = new Set(selected);
62332
+ if (e.target.checked) next.add(val);
62333
+ else next.delete(val);
62334
+ applySelection(next);
62335
+ }
62251
62336
  },
62252
62337
  val
62253
62338
  ))
62254
62339
  ] });
62255
62340
  };
62256
- class GridFilterColumnsMultiSelect {
62257
- params;
62258
- selectedValues = /* @__PURE__ */ new Set();
62259
- labels = {};
62260
- allValues = [];
62261
- gui;
62262
- labelFormatter;
62263
- reactRoot = null;
62264
- filterButtonClickListener = null;
62265
- filterButton = null;
62266
- normalizeCellValue(value) {
62267
- if (typeof value === "string") return value.trim() === "" ? EMPTY_KEY : value;
62268
- return EMPTY_KEY;
62269
- }
62270
- loadFieldValues() {
62271
- const field = this.params.colDef.field;
62272
- const values = /* @__PURE__ */ new Set();
62273
- this.params.api.forEachNode((node) => {
62274
- const data = node.data ?? {};
62275
- const raw = data[field];
62276
- const norm = this.normalizeCellValue(raw);
62277
- values.add(norm);
62278
- });
62279
- const { customOrder } = this.params;
62280
- const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
62281
- return Array.from(values).sort((a, b) => {
62282
- if (orderMap) {
62283
- const aIdx = orderMap.get(a) ?? Infinity;
62284
- const bIdx = orderMap.get(b) ?? Infinity;
62285
- if (aIdx !== bIdx) return aIdx - bIdx;
62286
- }
62287
- if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
62288
- if (b === EMPTY_KEY) return 1;
62289
- return a.localeCompare(b);
62290
- });
62291
- }
62292
- init(params) {
62293
- this.params = params;
62294
- this.labels = { ...params.labels };
62295
- this.labelFormatter = params.labelFormatter;
62296
- if (!(EMPTY_KEY in this.labels)) {
62297
- this.labels[EMPTY_KEY] = DEFAULT_EMPTY_LABEL;
62298
- }
62299
- this.allValues = this.loadFieldValues();
62300
- this.selectedValues = new Set(this.allValues);
62301
- this.gui = document.createElement("div");
62302
- this.reactRoot = createRoot(this.gui);
62303
- this.render();
62304
- this.setupFilterButtonListener();
62305
- }
62306
- setupFilterButtonListener() {
62307
- const columnId = this.params.column.getColId();
62308
- this.filterButton = document.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
62309
- if (this.filterButton) {
62310
- this.filterButtonClickListener = (e) => {
62311
- const clickCount = filterClickCountMap.get(columnId) || 0;
62312
- filterClickCountMap.set(columnId, clickCount + 1);
62313
- if (clickCount === 0) {
62314
- e.stopImmediatePropagation();
62315
- e.preventDefault();
62316
- this.params.api.hidePopupMenu();
62317
- filterStateMap.set(columnId, false);
62318
- return;
62319
- }
62320
- const isOpen = filterStateMap.get(columnId) || false;
62321
- if (isOpen) {
62322
- e.stopImmediatePropagation();
62323
- e.preventDefault();
62324
- this.params.api.hidePopupMenu();
62325
- filterStateMap.set(columnId, false);
62326
- } else {
62327
- filterStateMap.set(columnId, true);
62328
- }
62329
- };
62330
- this.filterButton.addEventListener("click", this.filterButtonClickListener, true);
62331
- }
62332
- }
62333
- render() {
62334
- if (!this.reactRoot) return;
62335
- this.reactRoot.render(
62336
- /* @__PURE__ */ jsx(
62337
- FilterUI,
62338
- {
62339
- allValues: this.allValues,
62340
- selected: this.selectedValues,
62341
- labels: this.labels,
62342
- labelFormatter: this.labelFormatter,
62343
- onToggleAll: this.handleToggleAll.bind(this),
62344
- onToggleOne: this.handleToggleOne.bind(this)
62345
- }
62346
- )
62347
- );
62348
- }
62349
- handleToggleAll(checked) {
62350
- if (checked) {
62351
- this.allValues.forEach((val) => this.selectedValues.add(val));
62352
- } else {
62353
- this.selectedValues.clear();
62354
- }
62355
- this.render();
62356
- this.params.filterChangedCallback();
62357
- }
62358
- handleToggleOne(value, checked) {
62359
- if (checked) {
62360
- this.selectedValues.add(value);
62361
- } else {
62362
- this.selectedValues.delete(value);
62363
- }
62364
- this.render();
62365
- this.params.filterChangedCallback();
62366
- }
62367
- getGui() {
62368
- return this.gui;
62369
- }
62370
- isFilterActive() {
62371
- return this.selectedValues.size !== this.allValues.length;
62372
- }
62373
- doesFilterPass(p) {
62374
- if (this.selectedValues.size === 0) {
62375
- return false;
62376
- }
62377
- const field = this.params.colDef.field;
62378
- if (!p.data || typeof p.data !== "object") {
62379
- return this.selectedValues.has(EMPTY_KEY);
62380
- }
62381
- const raw = p.data[field];
62382
- const norm = this.normalizeCellValue(raw);
62383
- return this.selectedValues.has(norm);
62384
- }
62385
- getModel() {
62386
- if (this.selectedValues.size !== this.allValues.length) {
62387
- return { values: Array.from(this.selectedValues) };
62388
- }
62389
- return null;
62390
- }
62391
- setModel(model) {
62392
- this.selectedValues = new Set(model?.values || []);
62393
- this.render();
62394
- }
62395
- destroy() {
62396
- if (this.filterButtonClickListener && this.filterButton) {
62397
- this.filterButton.removeEventListener("click", this.filterButtonClickListener, true);
62398
- this.filterButtonClickListener = null;
62399
- this.filterButton = null;
62400
- }
62401
- if (this.reactRoot) {
62402
- this.reactRoot.unmount();
62403
- this.reactRoot = null;
62404
- }
62405
- }
62406
- }
62407
62341
  const createCheckboxMultiFilterParams = (labels = {}, labelFormatter, customOrder) => ({
62408
62342
  labels: { [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labels },
62409
62343
  labelFormatter,