@linzjs/step-ag-grid 35.0.3 → 35.2.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 (42) hide show
  1. package/dist/index.css +17 -0
  2. package/dist/src/components/Grid.d.ts +5 -1
  3. package/dist/src/components/GridRangeSelectContextMenu.d.ts +12 -1
  4. package/dist/src/components/gridFilter/GridFilterCopyButton.d.ts +9 -0
  5. package/dist/src/components/gridFilter/index.d.ts +1 -0
  6. package/dist/src/components/gridHook/copyGridCells.d.ts +19 -0
  7. package/dist/src/components/gridHook/copyGridCells.test.d.ts +1 -0
  8. package/dist/src/components/gridHook/useGridColumnStateStorage.d.ts +26 -0
  9. package/dist/src/components/gridHook/useGridColumnStateStorage.test.d.ts +1 -0
  10. package/dist/src/components/gridHook/useGridCopy.d.ts +5 -2
  11. package/dist/src/components/gridHook/useGridCopySettings.d.ts +2 -0
  12. package/dist/src/contexts/GridContext.d.ts +35 -0
  13. package/dist/src/contexts/GridContextProvider.copy.test.d.ts +1 -0
  14. package/dist/src/utils/storageKeySync.d.ts +6 -0
  15. package/dist/src/utils/storageKeySync.test.d.ts +1 -0
  16. package/dist/step-ag-grid.cjs +601 -265
  17. package/dist/step-ag-grid.cjs.map +1 -1
  18. package/dist/step-ag-grid.esm.js +602 -267
  19. package/dist/step-ag-grid.esm.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/components/Grid.tsx +69 -27
  22. package/src/components/GridRangeSelectContextMenu.tsx +54 -51
  23. package/src/components/gridFilter/GridFilterColumnsToggle.tsx +45 -12
  24. package/src/components/gridFilter/GridFilterCopyButton.tsx +93 -0
  25. package/src/components/gridFilter/index.ts +1 -0
  26. package/src/components/gridHook/copyGridCells.test.ts +142 -0
  27. package/src/components/gridHook/copyGridCells.ts +225 -0
  28. package/src/components/gridHook/useGridColumnStateStorage.test.tsx +127 -0
  29. package/src/components/gridHook/useGridColumnStateStorage.ts +114 -0
  30. package/src/components/gridHook/useGridCopy.ts +88 -211
  31. package/src/components/gridHook/useGridCopySettings.ts +21 -6
  32. package/src/contexts/GridContext.tsx +44 -0
  33. package/src/contexts/GridContextProvider.copy.test.tsx +158 -0
  34. package/src/contexts/GridContextProvider.tsx +129 -2
  35. package/src/stories/grid/GridColumnState.stories.tsx +161 -0
  36. package/src/stories/grid/GridCopy.stories.tsx +35 -20
  37. package/src/stories/grid/GridCopyEditable.stories.tsx +131 -0
  38. package/src/stories/grid/GridCopyMultiple.stories.tsx +119 -0
  39. package/src/styles/GridFilterCopyButton.scss +22 -0
  40. package/src/styles/index.scss +1 -0
  41. package/src/utils/storageKeySync.test.ts +48 -0
  42. package/src/utils/storageKeySync.ts +24 -0
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { LuiMiniSpinner, LuiIcon, useShowLUIMessage, LuiStatusSpinner, LuiButtonGroup, LuiButton, LuiCheckboxInput, useFilterCharacters } from '@linzjs/lui';
3
3
  import React14, { 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
- 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';
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, set, get, flatten, castArray } from 'lodash-es';
6
6
 
7
7
  const ComponentLoadingWrapper = (props) => {
8
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: [
@@ -62385,6 +62385,13 @@ const GridContext = createContext({
62385
62385
  isExternalFilterPresent: NoContext,
62386
62386
  doesExternalFilterPass: NoContext,
62387
62387
  downloadCsv: NoContext,
62388
+ copyToClipboard: NoContext,
62389
+ getCopyScope: () => "all",
62390
+ getSelectedDataForCopy: NoContext,
62391
+ getCopyData: NoContext,
62392
+ setRangeCopy: NoContext,
62393
+ copyEnabled: false,
62394
+ setCopyEnabled: NoContext,
62388
62395
  onBulkEditingComplete: NoContext,
62389
62396
  setOnBulkEditingComplete: NoContext,
62390
62397
  showNoRowsOverlay: NoContext
@@ -64935,6 +64942,93 @@ const useGridContextMenu = ({
64935
64942
  };
64936
64943
  };
64937
64944
 
64945
+ const listeners = /* @__PURE__ */ new Map();
64946
+ const subscribeStorageKey = (key, listener) => {
64947
+ const keyListeners = listeners.get(key) ?? /* @__PURE__ */ new Set();
64948
+ listeners.set(key, keyListeners);
64949
+ keyListeners.add(listener);
64950
+ return () => {
64951
+ keyListeners.delete(listener);
64952
+ if (keyListeners.size === 0) listeners.delete(key);
64953
+ };
64954
+ };
64955
+ const publishStorageKey = (storage, key, value, source) => {
64956
+ try {
64957
+ storage.setItem(key, value);
64958
+ } catch (ex) {
64959
+ console.error(ex);
64960
+ }
64961
+ listeners.get(key)?.forEach((listener) => listener !== source && listener(value));
64962
+ };
64963
+
64964
+ const columnStateStorageKey = (colIds) => isEmpty(colIds) ? null : "stepAgGrid_columnState_" + colIds.join("_");
64965
+ const toStoredColumnState = (columnState, userSizedColIds) => ({
64966
+ columns: columnState.map(({ colId, width, flex, sort, sortIndex }) => ({ colId, width, flex, sort, sortIndex })),
64967
+ userSizedColIds: [...userSizedColIds]
64968
+ });
64969
+ const parseStoredColumnState = (stored) => {
64970
+ if (!stored) return void 0;
64971
+ try {
64972
+ const parsed = JSON.parse(stored);
64973
+ if (Array.isArray(parsed?.columns) && parsed.columns.every((col) => typeof col?.colId === "string") && Array.isArray(parsed.userSizedColIds) && parsed.userSizedColIds.every((id) => typeof id === "string")) {
64974
+ return parsed;
64975
+ }
64976
+ console.error(`stored column state is invalid: ${stored}`);
64977
+ } catch (ex) {
64978
+ console.error(ex);
64979
+ }
64980
+ return void 0;
64981
+ };
64982
+ const applyStoredColumnState = (api, { columns, userSizedColIds: storedUserSizedColIds }, userSizedColIds) => {
64983
+ const widths = new Map(columns.map((col) => [col.colId, col.width]));
64984
+ storedUserSizedColIds.forEach((colId) => {
64985
+ const width = widths.get(colId);
64986
+ if (width != null) {
64987
+ userSizedColIds.set(colId, width);
64988
+ }
64989
+ });
64990
+ api.applyColumnState({ state: columns, applyOrder: false });
64991
+ };
64992
+ const useGridColumnStateStorage = ({
64993
+ enabled,
64994
+ gridApi,
64995
+ gridDivRef,
64996
+ userSizedColIds
64997
+ }) => {
64998
+ const { getColumnIds } = useGridContext();
64999
+ const storageKey = useMemo(() => enabled ? columnStateStorageKey(getColumnIds()) : null, [enabled, getColumnIds]);
65000
+ const getStorage = useCallback(() => gridDivRef.current?.ownerDocument.defaultView?.localStorage, [gridDivRef]);
65001
+ const apply = useCallback(
65002
+ (stored) => {
65003
+ const columnState = parseStoredColumnState(stored);
65004
+ if (gridApi && !gridApi.isDestroyed() && columnState) {
65005
+ applyStoredColumnState(gridApi, columnState, userSizedColIds.current);
65006
+ }
65007
+ },
65008
+ [gridApi, userSizedColIds]
65009
+ );
65010
+ const listenerRef = useRef(void 0);
65011
+ useEffect(() => {
65012
+ if (!storageKey) return;
65013
+ const listener = (value) => apply(value);
65014
+ listenerRef.current = listener;
65015
+ if (!isChromatic()) {
65016
+ apply(getStorage()?.getItem(storageKey) ?? null);
65017
+ }
65018
+ return subscribeStorageKey(storageKey, listener);
65019
+ }, [apply, getStorage, storageKey]);
65020
+ const saveColumnState = useCallback(
65021
+ (api) => {
65022
+ const storage = getStorage();
65023
+ if (!storageKey || !storage) return;
65024
+ const value = JSON.stringify(toStoredColumnState(api.getColumnState(), userSizedColIds.current.keys()));
65025
+ publishStorageKey(storage, storageKey, value, listenerRef.current);
65026
+ },
65027
+ [getStorage, storageKey, userSizedColIds]
65028
+ );
65029
+ return { saveColumnState };
65030
+ };
65031
+
64938
65032
  const typedEntries = (obj) => Object.entries(obj);
64939
65033
 
64940
65034
  const gridCopyOptions = {
@@ -64943,13 +65037,21 @@ const gridCopyOptions = {
64943
65037
  json: { text: "Json", icon: "ic_file_attached_outline", developer: true }
64944
65038
  };
64945
65039
  const CopyOptionsStorageKey = "stepAgGrid_defaultCopy";
65040
+ const isCopyOptionsKey = (key) => Object.keys(gridCopyOptions).includes(key);
65041
+ const getDefaultCopyType = () => {
65042
+ const defaultCopy = window.localStorage.getItem(CopyOptionsStorageKey) ?? "";
65043
+ return isCopyOptionsKey(defaultCopy) ? defaultCopy : "html";
65044
+ };
64946
65045
  const useGridCopySettings = () => {
64947
- const [copyType, _setCopyType] = useState(() => {
64948
- const defaultCopy = window.localStorage.getItem(CopyOptionsStorageKey) ?? "";
64949
- return Object.keys(gridCopyOptions).includes(defaultCopy) ? defaultCopy : "html";
64950
- });
65046
+ const [copyType, _setCopyType] = useState(getDefaultCopyType);
65047
+ const listenerRef = useRef(void 0);
65048
+ useEffect(() => {
65049
+ const listener = (value) => isCopyOptionsKey(value) && _setCopyType(value);
65050
+ listenerRef.current = listener;
65051
+ return subscribeStorageKey(CopyOptionsStorageKey, listener);
65052
+ }, []);
64951
65053
  const setCopyType = useCallback((key) => {
64952
- window.localStorage.setItem(CopyOptionsStorageKey, key);
65054
+ publishStorageKey(window.localStorage, CopyOptionsStorageKey, key, listenerRef.current);
64953
65055
  _setCopyType(key);
64954
65056
  }, []);
64955
65057
  return {
@@ -64958,59 +65060,231 @@ const useGridCopySettings = () => {
64958
65060
  };
64959
65061
  };
64960
65062
 
65063
+ const GridCopyOptionsMenuItems = ({
65064
+ onCopy,
65065
+ copyType,
65066
+ setCopyType,
65067
+ developer: showDeveloper = false,
65068
+ header = "Copy as"
65069
+ }) => /* @__PURE__ */ jsxs(Fragment, { children: [
65070
+ /* @__PURE__ */ jsx(MenuHeader, { children: header }),
65071
+ typedEntries(gridCopyOptions).map(([key, { icon, text, developer }]) => {
65072
+ return (!developer || showDeveloper) && /* @__PURE__ */ jsx(MenuItem, { onClick: () => onCopy(key), children: /* @__PURE__ */ jsxs("div", { className: "copyMenuMenuItem", children: [
65073
+ /* @__PURE__ */ jsx(LuiIcon, { name: icon, alt: text, size: "md" }),
65074
+ /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
65075
+ ] }) }, key);
65076
+ }),
65077
+ /* @__PURE__ */ jsx(MenuDivider, {}),
65078
+ /* @__PURE__ */ jsx(MenuHeader, { children: "Set copy default" }),
65079
+ typedEntries(gridCopyOptions).map(([key, { text, developer }]) => {
65080
+ return !developer && /* @__PURE__ */ jsx(MenuItem, { onClick: () => setCopyType(key), children: /* @__PURE__ */ jsxs(
65081
+ "div",
65082
+ {
65083
+ className: clsx("copyMenuMenuItem", copyType === key ? "" : "copyMenuMenuItem__buttonDefault--hidden"),
65084
+ children: [
65085
+ /* @__PURE__ */ jsx(LuiIcon, { name: "ic_tick", alt: "Default", size: "sm" }),
65086
+ /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
65087
+ ]
65088
+ }
65089
+ ) }, "default_" + key);
65090
+ })
65091
+ ] });
64961
65092
  const GridRangeSelectContextMenu = ({
64962
65093
  event,
64963
65094
  context
64964
65095
  }) => {
64965
65096
  const developerContextMenu = !!event?.event?.ctrlKey && !!event?.event?.shiftKey;
64966
- const onCopy = useMemo(() => context?.onCopy, [context?.onCopy]);
64967
- const onClick = useCallback(
64968
- (type) => {
64969
- onCopy?.(type);
64970
- },
64971
- [onCopy]
64972
- );
64973
- return /* @__PURE__ */ jsxs(Fragment, { children: [
64974
- /* @__PURE__ */ jsx(MenuHeader, { children: "Copy as" }),
64975
- typedEntries(gridCopyOptions).map(([key, { icon, text, developer }]) => {
64976
- return (!developer || developerContextMenu) && /* @__PURE__ */ jsx(MenuItem, { onClick: () => void onClick(key), children: /* @__PURE__ */ jsxs("div", { className: "copyMenuMenuItem", children: [
64977
- /* @__PURE__ */ jsx(LuiIcon, { name: icon, alt: text, size: "md" }),
64978
- /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
64979
- ] }) }, key);
64980
- }),
64981
- /* @__PURE__ */ jsx(MenuDivider, {}),
64982
- /* @__PURE__ */ jsx(MenuHeader, { children: "Set copy default" }),
64983
- typedEntries(gridCopyOptions).map(([key, { text, developer }]) => {
64984
- return !developer && /* @__PURE__ */ jsx(
64985
- MenuItem,
64986
- {
64987
- onClick: (e) => {
64988
- context?.setCopyType(key);
64989
- e.keepOpen = true;
64990
- },
64991
- children: /* @__PURE__ */ jsxs(
64992
- "div",
64993
- {
64994
- className: clsx(
64995
- "copyMenuMenuItem",
64996
- context?.copyType === key ? "" : "copyMenuMenuItem__buttonDefault--hidden"
64997
- ),
64998
- children: [
64999
- /* @__PURE__ */ jsx(LuiIcon, { name: "ic_tick", alt: "CSV", size: "sm" }),
65000
- /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
65001
- ]
65002
- }
65003
- )
65004
- },
65005
- "default_" + key
65006
- );
65007
- })
65008
- ] });
65097
+ return context ? /* @__PURE__ */ jsx(GridCopyOptionsMenuItems, { ...context, developer: developerContextMenu }) : null;
65009
65098
  };
65010
65099
 
65011
65100
  const agGridSelectRowColId = "ag-Grid-SelectionColumn";
65012
65101
 
65102
+ const isCopyableColId = (colId, getColDef) => colId !== "gridCellFiller" && getColDef(colId)?.headerComponentParams?.exportable !== false;
65103
+ const copyGridCells = ({
65104
+ type,
65105
+ selectedColIds,
65106
+ selectedNodes,
65107
+ selectedRowIds,
65108
+ getColDef,
65109
+ getCellValue,
65110
+ showToast
65111
+ }) => {
65112
+ const json = type === "json";
65113
+ const filteredSelectedColIds = selectedColIds.filter(
65114
+ (colId) => colId === agGridSelectRowColId || isCopyableColId(colId, getColDef)
65115
+ );
65116
+ const formatters = compact(
65117
+ filteredSelectedColIds.map((colKey) => {
65118
+ return (rowNode) => {
65119
+ if (colKey === agGridSelectRowColId) {
65120
+ return selectedRowIds.includes(rowNode.data.id);
65121
+ } else {
65122
+ const v = getCellValue({ rowNode, colKey });
65123
+ if (json && v !== void 0) {
65124
+ return v;
65125
+ }
65126
+ const f = getCellValue({ rowNode, colKey, useFormatter: true });
65127
+ return v == f ? v : f;
65128
+ }
65129
+ };
65130
+ })
65131
+ );
65132
+ const headers = filteredSelectedColIds.map((colId) => {
65133
+ if (colId === agGridSelectRowColId) return type === "json" ? "selected" : "Selected";
65134
+ if (json) {
65135
+ return colId;
65136
+ }
65137
+ return getColDef(colId)?.headerName ?? "?";
65138
+ });
65139
+ const maxCellLength = {};
65140
+ headers.forEach((headerName, i) => {
65141
+ const colId = filteredSelectedColIds[i];
65142
+ maxCellLength[colId] = headerName.length;
65143
+ });
65144
+ const rows = [];
65145
+ if (type === "csv" || type === "html") {
65146
+ rows.push(headers);
65147
+ }
65148
+ selectedNodes.forEach((node) => {
65149
+ const row = [];
65150
+ rows.push(row);
65151
+ formatters.forEach((formatter, i) => {
65152
+ const colId = filteredSelectedColIds[i];
65153
+ let value = formatter(node);
65154
+ if (typeof value === "string") {
65155
+ value = value.replaceAll("\xA0", " ");
65156
+ }
65157
+ if (!json) {
65158
+ if (value === "-" || value === "\u2013" || value == null) {
65159
+ value = "";
65160
+ }
65161
+ value = String(value);
65162
+ if (value === "-" || value === "\u2013") {
65163
+ value = "";
65164
+ }
65165
+ maxCellLength[colId] = Math.max(maxCellLength[colId], value.length);
65166
+ }
65167
+ switch (type) {
65168
+ case "json":
65169
+ value = value === "undefined" || value !== null && typeof value === "object" || typeof value === "string" ? JSON.stringify(value) : value;
65170
+ break;
65171
+ case "markdown":
65172
+ value = encodeMarkdownValue(value);
65173
+ break;
65174
+ case "csv":
65175
+ value = encodeCSVValue(value);
65176
+ break;
65177
+ }
65178
+ row.push(String(value));
65179
+ });
65180
+ });
65181
+ let result = "";
65182
+ let html = `<table style="
65183
+ font-family: 'Open Sans', system-ui, sans-serif;
65184
+ font-size: 10px;
65185
+ line-height: 10px;
65186
+ border: 1px solid #d1d9e0;
65187
+ border-collapse: collapse;
65188
+ ">`;
65189
+ if (json) {
65190
+ result += "[\n";
65191
+ }
65192
+ rows.forEach((row, rowIndex) => {
65193
+ if (json) {
65194
+ result += " { ";
65195
+ }
65196
+ if (rowIndex == 1) {
65197
+ html += '<tbody style="font-weight: 400;">';
65198
+ }
65199
+ if (rowIndex == 0) {
65200
+ html += '<thead style="font-weight: 600;">';
65201
+ }
65202
+ if (rowIndex === 0 || (rowIndex & 1) === 1) {
65203
+ html += "<tr>";
65204
+ } else {
65205
+ html += '<tr style="background-color: #f6f8fa;">';
65206
+ }
65207
+ if (rowIndex === 1 && type === "html") {
65208
+ Object.values(maxCellLength).forEach((maxLength) => {
65209
+ result += "|" + "-".repeat(maxLength + 2);
65210
+ });
65211
+ result += "|\n";
65212
+ }
65213
+ row.forEach((cell, i) => {
65214
+ switch (type) {
65215
+ case "csv":
65216
+ if (i !== 0) {
65217
+ result += ", ";
65218
+ }
65219
+ result += cell;
65220
+ break;
65221
+ case "html":
65222
+ if (i === 0) {
65223
+ result += "|";
65224
+ }
65225
+ const colId = filteredSelectedColIds[i];
65226
+ result += " " + cell.padEnd(maxCellLength[colId], " ") + " ";
65227
+ result += "|";
65228
+ html += rowIndex === 0 ? '<th style="border: 1px solid #d1d9e0; padding:6px 13px; text-align: left;">' : '<td style="border: 1px solid #d1d9e0; padding:6px 13px;">';
65229
+ html += cell;
65230
+ html += rowIndex === 0 ? "</th>" : "</td>";
65231
+ break;
65232
+ case "json":
65233
+ if (i !== 0) {
65234
+ result += ", ";
65235
+ }
65236
+ result += JSON.stringify(headers[i]) + ": " + cell;
65237
+ break;
65238
+ }
65239
+ });
65240
+ html += "</tr>";
65241
+ if (rowIndex == 0) {
65242
+ html += "</thead>";
65243
+ }
65244
+ if (rowIndex == rows.length - 1) {
65245
+ html += "</tbody>";
65246
+ }
65247
+ if (json) {
65248
+ result += rowIndex < rows.length - 1 ? " }," : " }";
65249
+ }
65250
+ result += "\n";
65251
+ });
65252
+ if (json) {
65253
+ result += "]\n";
65254
+ }
65255
+ html += "</table>";
65256
+ showToast({
65257
+ message: `${gridCopyOptions[type].text} copied`,
65258
+ messageType: "toast",
65259
+ messageLevel: "info"
65260
+ });
65261
+ if (type === "html") {
65262
+ const clipboardItem = new ClipboardItem({
65263
+ "text/html": new Blob([html], { type: "text/html" }),
65264
+ "text/plain": new Blob([result], { type: "text/plain" })
65265
+ // fallback
65266
+ });
65267
+ void navigator.clipboard.write([clipboardItem]).catch((err) => console.error("Failed to copy: ", err));
65268
+ } else {
65269
+ void navigator.clipboard.writeText(result).catch((err) => console.error("Failed to copy: ", err));
65270
+ }
65271
+ };
65272
+ const encodeMarkdownValue = (value) => {
65273
+ return value.replaceAll("|", "\\|");
65274
+ };
65275
+ const encodeCSVValue = (value) => {
65276
+ let str = String(value);
65277
+ if (/[",\n]/.test(str)) {
65278
+ str = '"' + str.replace(/"/g, '""') + '"';
65279
+ }
65280
+ return str;
65281
+ };
65282
+
65283
+ let lastActiveGridElement = null;
65284
+ const isEditableElement = (el) => el instanceof Element && (!!el.closest("input, textarea, select") || el.isContentEditable);
65013
65285
  const useGridCopy = ({
65286
+ gridDivRef,
65287
+ gridDocument,
65014
65288
  ranges,
65015
65289
  rangeStartRef,
65016
65290
  rangeEndRef,
@@ -65018,193 +65292,41 @@ const useGridCopy = ({
65018
65292
  cellContextMenu
65019
65293
  }) => {
65020
65294
  const showToast = useShowLUIMessage();
65021
- const { getSelectedRowIds } = useGridContext();
65022
- const { getColDef, getCellValue } = useGridContext();
65295
+ const { getColDef, getCellValue, getSelectedRowIds, setRangeCopy } = useGridContext();
65023
65296
  const { copyType, setCopyType } = useGridCopySettings();
65297
+ const hasRange = useCallback(
65298
+ () => rangeStartRef.current !== null && rangeEndRef.current !== null && hasSelectedMoreThanOneCellRef.current,
65299
+ [rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef]
65300
+ );
65024
65301
  const onCopy = useCallback(
65025
65302
  (type = copyType) => {
65026
65303
  const rangeStart = rangeStartRef.current;
65027
65304
  const rangeEnd = rangeEndRef.current;
65028
- if (rangeStart === null || rangeEnd === null || !hasSelectedMoreThanOneCellRef.current) {
65305
+ if (rangeStart === null || rangeEnd === null || !hasRange()) {
65029
65306
  return;
65030
65307
  }
65031
65308
  if (rangeStart.rowId === rangeEnd.rowId && rangeStart.colId === rangeEnd.colId) {
65032
65309
  type = "html";
65033
65310
  }
65034
- const json = type === "json";
65035
65311
  const { selectedColIds, selectedNodes } = ranges();
65036
- const filteredSelectedColIds = selectedColIds.filter(
65037
- (colId) => colId === agGridSelectRowColId || colId !== "gridCellFiller" && getColDef(colId)?.headerComponentParams?.exportable !== false
65038
- );
65039
- const selectedRowIds = getSelectedRowIds();
65040
- const formatters = compact(
65041
- filteredSelectedColIds.map((colKey) => {
65042
- return (rowNode) => {
65043
- if (colKey === agGridSelectRowColId) {
65044
- return selectedRowIds.includes(rowNode.data.id);
65045
- } else {
65046
- const v = getCellValue({ rowNode, colKey });
65047
- if (json && v !== void 0) {
65048
- return v;
65049
- }
65050
- const f = getCellValue({ rowNode, colKey, useFormatter: true });
65051
- return v == f ? v : f;
65052
- }
65053
- };
65054
- })
65055
- );
65056
- const headers = filteredSelectedColIds.map((colId) => {
65057
- if (colId === agGridSelectRowColId) return type === "json" ? "selected" : "Selected";
65058
- if (json) {
65059
- return colId;
65060
- }
65061
- return getColDef(colId)?.headerName ?? "?";
65062
- });
65063
- const maxCellLength = {};
65064
- headers.forEach((headerName, i) => {
65065
- const colId = filteredSelectedColIds[i];
65066
- maxCellLength[colId] = headerName.length;
65067
- });
65068
- const rows = [];
65069
- if (type === "csv" || type === "html") {
65070
- rows.push(headers);
65071
- }
65072
- selectedNodes.forEach((node) => {
65073
- const row = [];
65074
- rows.push(row);
65075
- formatters.forEach((formatter, i) => {
65076
- const colId = filteredSelectedColIds[i];
65077
- let value = formatter(node);
65078
- if (typeof value === "string") {
65079
- value = value.replaceAll("\xA0", " ");
65080
- }
65081
- if (!json) {
65082
- if (value === "-" || value === "\u2013" || value == null) {
65083
- value = "";
65084
- }
65085
- value = String(value);
65086
- if (value === "-" || value === "\u2013") {
65087
- value = "";
65088
- }
65089
- maxCellLength[colId] = Math.max(maxCellLength[colId], value.length);
65090
- }
65091
- switch (type) {
65092
- case "json":
65093
- value = value === "undefined" || value !== null && typeof value === "object" || typeof value === "string" ? JSON.stringify(value) : value;
65094
- break;
65095
- case "markdown":
65096
- value = encodeMarkdownValue(value);
65097
- break;
65098
- case "csv":
65099
- value = encodeCSVValue(value);
65100
- break;
65101
- }
65102
- row.push(String(value));
65103
- });
65104
- });
65105
- let result = "";
65106
- let html = `<table style="
65107
- font-family: 'Open Sans', system-ui, sans-serif;
65108
- font-size: 10px;
65109
- line-height: 10px;
65110
- border: 1px solid #d1d9e0;
65111
- border-collapse: collapse;
65112
- ">`;
65113
- if (json) {
65114
- result += "[\n";
65115
- }
65116
- rows.forEach((row, rowIndex) => {
65117
- if (json) {
65118
- result += " { ";
65119
- }
65120
- if (rowIndex == 1) {
65121
- html += '<tbody style="font-weight: 400;">';
65122
- }
65123
- if (rowIndex == 0) {
65124
- html += '<thead style="font-weight: 600;">';
65125
- }
65126
- if (rowIndex === 0 || (rowIndex & 1) === 1) {
65127
- html += "<tr>";
65128
- } else {
65129
- html += '<tr style="background-color: #f6f8fa;">';
65130
- }
65131
- if (rowIndex === 1 && type === "html") {
65132
- Object.values(maxCellLength).forEach((maxLength) => {
65133
- result += "|" + "-".repeat(maxLength + 2);
65134
- });
65135
- result += "|\n";
65136
- }
65137
- row.forEach((cell, i) => {
65138
- switch (type) {
65139
- case "csv":
65140
- if (i !== 0) {
65141
- result += ", ";
65142
- }
65143
- result += cell;
65144
- break;
65145
- case "html":
65146
- if (i === 0) {
65147
- result += "|";
65148
- }
65149
- const colId = filteredSelectedColIds[i];
65150
- result += " " + cell.padEnd(maxCellLength[colId], " ") + " ";
65151
- result += "|";
65152
- html += rowIndex === 0 ? '<th style="border: 1px solid #d1d9e0; padding:6px 13px; text-align: left;">' : '<td style="border: 1px solid #d1d9e0; padding:6px 13px;">';
65153
- html += cell;
65154
- html += rowIndex === 0 ? "</th>" : "</td>";
65155
- break;
65156
- case "json":
65157
- if (i !== 0) {
65158
- result += ", ";
65159
- }
65160
- result += JSON.stringify(headers[i]) + ": " + cell;
65161
- break;
65162
- }
65163
- });
65164
- html += "</tr>";
65165
- if (rowIndex == 0) {
65166
- html += "</thead>";
65167
- }
65168
- if (rowIndex == rows.length - 1) {
65169
- html += "</tbody>";
65170
- }
65171
- if (json) {
65172
- result += " }";
65173
- }
65174
- result += "\n";
65175
- });
65176
- if (json) {
65177
- result += "]\n";
65178
- }
65179
- html += "</table>";
65180
- showToast({
65181
- message: `${gridCopyOptions[type].text} copied`,
65182
- messageType: "toast",
65183
- messageLevel: "info"
65312
+ copyGridCells({
65313
+ type,
65314
+ selectedColIds,
65315
+ selectedNodes,
65316
+ selectedRowIds: getSelectedRowIds(),
65317
+ getColDef,
65318
+ getCellValue,
65319
+ showToast
65184
65320
  });
65185
- if (type === "html") {
65186
- const clipboardItem = new ClipboardItem({
65187
- "text/html": new Blob([html], { type: "text/html" }),
65188
- "text/plain": new Blob([result], { type: "text/plain" })
65189
- // fallback
65190
- });
65191
- void navigator.clipboard.write([clipboardItem]).catch((err) => console.error("Failed to copy: ", err));
65192
- } else {
65193
- void navigator.clipboard.writeText(result).catch((err) => console.error("Failed to copy: ", err));
65194
- }
65195
65321
  },
65196
- [
65197
- getCellValue,
65198
- ranges,
65199
- copyType,
65200
- rangeStartRef,
65201
- hasSelectedMoreThanOneCellRef,
65202
- rangeEndRef,
65203
- showToast,
65204
- getColDef,
65205
- getSelectedRowIds
65206
- ]
65322
+ [getCellValue, ranges, copyType, rangeStartRef, hasRange, rangeEndRef, showToast, getColDef, getSelectedRowIds]
65207
65323
  );
65324
+ const onCopyRef = useRef(onCopy);
65325
+ onCopyRef.current = onCopy;
65326
+ useEffect(() => {
65327
+ setRangeCopy({ hasRange, getRange: ranges, copy: (type) => onCopyRef.current(type) });
65328
+ return () => setRangeCopy(void 0);
65329
+ }, [hasRange, ranges, setRangeCopy]);
65208
65330
  const onCopyEvent = useCallback(
65209
65331
  (e) => {
65210
65332
  const rangeStart = rangeStartRef.current;
@@ -65217,6 +65339,31 @@ const useGridCopy = ({
65217
65339
  },
65218
65340
  [onCopy, rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef]
65219
65341
  );
65342
+ useEffect(() => {
65343
+ const gridDiv = gridDivRef.current;
65344
+ const doc = gridDocument ?? gridDiv?.ownerDocument;
65345
+ if (!gridDiv || !doc) return;
65346
+ const setActive = () => {
65347
+ lastActiveGridElement = gridDiv;
65348
+ };
65349
+ const onDocumentCopy = (e) => {
65350
+ if (gridDiv.contains(e.target) || // handled by onCopyEvent
65351
+ lastActiveGridElement !== gridDiv || !hasRange() || isEditableElement(e.target) || !doc.getSelection()?.isCollapsed) {
65352
+ return;
65353
+ }
65354
+ e.preventDefault();
65355
+ onCopyRef.current();
65356
+ };
65357
+ gridDiv.addEventListener("mousedown", setActive, true);
65358
+ gridDiv.addEventListener("focusin", setActive, true);
65359
+ doc.addEventListener("copy", onDocumentCopy);
65360
+ return () => {
65361
+ gridDiv.removeEventListener("mousedown", setActive, true);
65362
+ gridDiv.removeEventListener("focusin", setActive, true);
65363
+ doc.removeEventListener("copy", onDocumentCopy);
65364
+ if (lastActiveGridElement === gridDiv) lastActiveGridElement = null;
65365
+ };
65366
+ }, [gridDivRef, gridDocument, hasRange]);
65220
65367
  const { cellContextMenu: rangeSelectContextMenu, contextMenuComponent: rangeSelectContextMenuComponent } = useGridContextMenu({
65221
65368
  contextMenu: GridRangeSelectContextMenu,
65222
65369
  context: { onCopy, copyType, setCopyType }
@@ -65233,16 +65380,6 @@ const useGridCopy = ({
65233
65380
  rangeSelectContextMenuComponent
65234
65381
  };
65235
65382
  };
65236
- const encodeMarkdownValue = (value) => {
65237
- return value.replaceAll("|", "\\|");
65238
- };
65239
- const encodeCSVValue = (value) => {
65240
- let str = String(value);
65241
- if (/[",\n]/.test(str)) {
65242
- str = '"' + str.replace(/"/g, '""') + '"';
65243
- }
65244
- return str;
65245
- };
65246
65383
 
65247
65384
  const useGridRangeSelection = ({
65248
65385
  enableRangeSelection,
@@ -65664,6 +65801,7 @@ const Grid = ({
65664
65801
  // ─── Selection ────────────────────────────────
65665
65802
  autoSelectFirstRow,
65666
65803
  enableRangeSelection = false,
65804
+ enableCopy = false,
65667
65805
  externalSelectedIds,
65668
65806
  externalSelectedItems,
65669
65807
  selectColumnPinned = "left",
@@ -65679,6 +65817,7 @@ const Grid = ({
65679
65817
  // ─── Callbacks / Events ───────────────────────
65680
65818
  onCellFocused: paramsOnCellFocused,
65681
65819
  onColumnMoved,
65820
+ saveColumnState = false,
65682
65821
  // ─── Row Behavior ─────────────────────────────
65683
65822
  suppressColumnVirtualization = true,
65684
65823
  // ─── Miscellaneous ────────────────────────────
@@ -65693,6 +65832,7 @@ const Grid = ({
65693
65832
  setApis,
65694
65833
  setExternallySelectedItemsAreInSync,
65695
65834
  setOnBulkEditingComplete,
65835
+ setCopyEnabled,
65696
65836
  gridReady,
65697
65837
  gridRenderState,
65698
65838
  externallySelectedItemsAreInSync,
@@ -65719,6 +65859,7 @@ const Grid = ({
65719
65859
  [propStartCellEditing]
65720
65860
  );
65721
65861
  const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
65862
+ const [gridApi, setGridApi] = useState();
65722
65863
  const gridDivRef = useRef(null);
65723
65864
  const lastSelectedIds = useRef(void 0);
65724
65865
  const [staleGrid, setStaleGrid] = useState(false);
@@ -65786,6 +65927,7 @@ const Grid = ({
65786
65927
  }
65787
65928
  }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
65788
65929
  const lastOwnerDocumentRef = useRef(void 0);
65930
+ const [gridDocument, setGridDocument] = useState();
65789
65931
  const wasVisibleRef = useRef(false);
65790
65932
  useInterval(() => {
65791
65933
  const visible = !!gridDivRef.current?.checkVisibility?.();
@@ -65803,6 +65945,7 @@ const Grid = ({
65803
65945
  const currentDocument = gridDivRef.current?.ownerDocument;
65804
65946
  if (currentDocument !== lastOwnerDocumentRef.current) {
65805
65947
  lastOwnerDocumentRef.current = currentDocument;
65948
+ setGridDocument(currentDocument);
65806
65949
  if (currentDocument) {
65807
65950
  needsAutoSize.current = true;
65808
65951
  }
@@ -65938,6 +66081,7 @@ const Grid = ({
65938
66081
  const onGridReady = useCallback(
65939
66082
  (event) => {
65940
66083
  setApis(event.api, hasExternallySelectedItems, enableMultilineBulkEdit, dataTestId);
66084
+ setGridApi(event.api);
65941
66085
  event.api.showNoRowsOverlay();
65942
66086
  synchroniseExternallySelectedItemsToGrid();
65943
66087
  },
@@ -66053,16 +66197,35 @@ const Grid = ({
66053
66197
  rangeSortedNodesRef
66054
66198
  });
66055
66199
  const { onCopyEvent, rangeSelectInterceptContextMenu, rangeSelectContextMenuComponent } = useGridCopy({
66200
+ gridDivRef,
66201
+ gridDocument,
66056
66202
  ranges,
66057
66203
  rangeStartRef,
66058
66204
  rangeEndRef,
66059
66205
  hasSelectedMoreThanOneCellRef,
66060
66206
  cellContextMenu
66061
66207
  });
66062
- const onSortChanged = useCallback(() => {
66063
- clearRangeSelection();
66064
- ensureSelectedRowIsVisible();
66065
- }, [clearRangeSelection, ensureSelectedRowIsVisible]);
66208
+ useEffect(() => {
66209
+ setCopyEnabled(enableCopy);
66210
+ return () => setCopyEnabled(false);
66211
+ }, [enableCopy, setCopyEnabled]);
66212
+ const userSizedColIds = useRef(/* @__PURE__ */ new Map());
66213
+ const { saveColumnState: saveColumnStateToStorage } = useGridColumnStateStorage({
66214
+ enabled: saveColumnState,
66215
+ gridApi,
66216
+ gridDivRef,
66217
+ userSizedColIds
66218
+ });
66219
+ const onSortChanged = useCallback(
66220
+ (e) => {
66221
+ clearRangeSelection();
66222
+ ensureSelectedRowIsVisible();
66223
+ if (e.source === "uiColumnSorted") {
66224
+ saveColumnStateToStorage(e.api);
66225
+ }
66226
+ },
66227
+ [clearRangeSelection, ensureSelectedRowIsVisible, saveColumnStateToStorage]
66228
+ );
66066
66229
  const onCellClicked = useCallback(
66067
66230
  (event) => {
66068
66231
  if (enableRangeSelection && rangeStartRef.current && rangeEndRef.current) {
@@ -66087,25 +66250,30 @@ const Grid = ({
66087
66250
  },
66088
66251
  [clearRangeSelection, enableRangeSelection, singleClickEdit, startCellEditing]
66089
66252
  );
66090
- const userSizedColIds = useRef(/* @__PURE__ */ new Map());
66091
- const onColumnResized = useCallback((e) => {
66092
- const colId = e.column?.getColId();
66093
- if (colId == null) {
66094
- return;
66095
- }
66096
- const width = e.column?.getActualWidth();
66097
- if (width == null) {
66098
- return;
66099
- }
66100
- switch (e.source) {
66101
- case "uiColumnResized":
66102
- userSizedColIds.current.set(colId, width);
66103
- break;
66104
- case "autosizeColumns":
66105
- userSizedColIds.current.delete(colId);
66106
- break;
66107
- }
66108
- }, []);
66253
+ const onColumnResized = useCallback(
66254
+ (e) => {
66255
+ const colId = e.column?.getColId();
66256
+ if (colId == null) {
66257
+ return;
66258
+ }
66259
+ const width = e.column?.getActualWidth();
66260
+ if (width == null) {
66261
+ return;
66262
+ }
66263
+ switch (e.source) {
66264
+ case "uiColumnResized":
66265
+ userSizedColIds.current.set(colId, width);
66266
+ if (e.finished) {
66267
+ saveColumnStateToStorage(e.api);
66268
+ }
66269
+ break;
66270
+ case "autosizeColumns":
66271
+ userSizedColIds.current.delete(colId);
66272
+ break;
66273
+ }
66274
+ },
66275
+ [saveColumnStateToStorage]
66276
+ );
66109
66277
  const columnMoved = useCallback(
66110
66278
  (e) => {
66111
66279
  clearRangeSelection();
@@ -66933,6 +67101,17 @@ const GridFilterHeaderIconButton = forwardRef(
66933
67101
  }
66934
67102
  );
66935
67103
 
67104
+ const parseInvisibleIds = (stored) => {
67105
+ const invisibleIds = JSON.parse(stored);
67106
+ if (!Array.isArray(invisibleIds)) {
67107
+ console.error(`stored invisible ids not an array: ${stored}`);
67108
+ } else if (!invisibleIds.every((id) => typeof id === "string")) {
67109
+ console.error(`stored invisible ids not strings: ${stored}`);
67110
+ } else {
67111
+ return invisibleIds;
67112
+ }
67113
+ return void 0;
67114
+ };
66936
67115
  const GridFilterColumnsToggle = ({ saveState = true }) => {
66937
67116
  const [loaded, setLoaded] = useState(false);
66938
67117
  const { getColumns, getColumnIds, invisibleColumnIds, setInvisibleColumnIds } = useContext(GridContext);
@@ -66952,14 +67131,8 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
66952
67131
  if (!stored) {
66953
67132
  resetColumns();
66954
67133
  } else {
66955
- const invisibleIds = JSON.parse(stored ?? "[]");
66956
- if (!Array.isArray(invisibleIds)) {
66957
- console.error(`stored invisible ids not an array: ${stored}`);
66958
- } else if (!invisibleIds.every((id) => typeof id === "string")) {
66959
- console.error(`stored invisible ids not strings: ${stored}`);
66960
- } else {
66961
- if (invisibleIds) setInvisibleColumnIds(invisibleIds);
66962
- }
67134
+ const invisibleIds = parseInvisibleIds(stored);
67135
+ if (invisibleIds) setInvisibleColumnIds(invisibleIds);
66963
67136
  }
66964
67137
  } catch (ex) {
66965
67138
  console.error(ex);
@@ -66972,14 +67145,37 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
66972
67145
  window.localStorage.setItem(columnStorageKey, JSON.stringify(invisibleColumnIds));
66973
67146
  }
66974
67147
  }, [columnStorageKey, invisibleColumnIds, loaded, saveState]);
67148
+ const listenerRef = useRef(void 0);
67149
+ useEffect(() => {
67150
+ if (!columnStorageKey || !saveState) return;
67151
+ const listener = (value) => {
67152
+ try {
67153
+ const invisibleIds = parseInvisibleIds(value);
67154
+ if (invisibleIds) setInvisibleColumnIds(invisibleIds);
67155
+ } catch (ex) {
67156
+ console.error(ex);
67157
+ }
67158
+ };
67159
+ listenerRef.current = listener;
67160
+ return subscribeStorageKey(columnStorageKey, listener);
67161
+ }, [columnStorageKey, saveState, setInvisibleColumnIds]);
67162
+ const changeInvisibleColumnIds = useCallback(
67163
+ (invisibleIds) => {
67164
+ setInvisibleColumnIds(invisibleIds);
67165
+ if (columnStorageKey && saveState) {
67166
+ publishStorageKey(window.localStorage, columnStorageKey, JSON.stringify(invisibleIds), listenerRef.current);
67167
+ }
67168
+ },
67169
+ [columnStorageKey, saveState, setInvisibleColumnIds]
67170
+ );
66975
67171
  const toggleColumn = useCallback(
66976
67172
  (colId) => {
66977
67173
  if (!colId || !invisibleColumnIds) return;
66978
- setInvisibleColumnIds(
67174
+ changeInvisibleColumnIds(
66979
67175
  invisibleColumnIds.includes(colId) ? invisibleColumnIds.filter((id) => id !== colId) : [...invisibleColumnIds, colId]
66980
67176
  );
66981
67177
  },
66982
- [invisibleColumnIds, setInvisibleColumnIds]
67178
+ [changeInvisibleColumnIds, invisibleColumnIds]
66983
67179
  );
66984
67180
  const numericRegExp = /^\d+$/;
66985
67181
  const isNonManageableColumn = (col) => col.lockVisible || col.colId == null || numericRegExp.test(col.colId);
@@ -67030,7 +67226,7 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
67030
67226
  onClick: (e) => {
67031
67227
  if (e.key !== "Tab") {
67032
67228
  e.keepOpen = e.key !== "Enter";
67033
- resetColumns();
67229
+ changeInvisibleColumnIds(getColumnIds("initialHide"));
67034
67230
  }
67035
67231
  },
67036
67232
  children: [
@@ -67045,6 +67241,72 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
67045
67241
  );
67046
67242
  };
67047
67243
 
67244
+ const copyScopeHeader = {
67245
+ range: "Copy range",
67246
+ selection: "Copy selection",
67247
+ all: "Copy all"
67248
+ };
67249
+ const copyTypeTooltipText = (copyType) => copyType === "html" ? "text / HTML" : gridCopyOptions[copyType].text;
67250
+ const GridFilterCopyMenuItems = ({ developer }) => {
67251
+ const { copyToClipboard, getCopyScope } = useGridContext();
67252
+ const { copyType, setCopyType } = useGridCopySettings();
67253
+ return /* @__PURE__ */ jsx(
67254
+ GridCopyOptionsMenuItems,
67255
+ {
67256
+ header: copyScopeHeader[getCopyScope()],
67257
+ onCopy: copyToClipboard,
67258
+ copyType,
67259
+ setCopyType,
67260
+ developer
67261
+ }
67262
+ );
67263
+ };
67264
+ const GridFilterCopyButton = () => {
67265
+ const { copyEnabled, copyToClipboard, getCopyScope } = useGridContext();
67266
+ const { copyType } = useGridCopySettings();
67267
+ const [copyScope, setCopyScope] = useState("all");
67268
+ const updateCopyScope = useCallback(() => setCopyScope(getCopyScope()), [getCopyScope]);
67269
+ const [developerMenu, setDeveloperMenu] = useState(false);
67270
+ if (!copyEnabled) return null;
67271
+ const copyTitle = `${copyScopeHeader[copyScope]} as ${copyTypeTooltipText(copyType)}`;
67272
+ return /* @__PURE__ */ jsxs("div", { className: "lui-split-button GridFilterCopyButton", onMouseEnter: updateCopyScope, onFocus: updateCopyScope, children: [
67273
+ /* @__PURE__ */ jsx(
67274
+ LuiButton,
67275
+ {
67276
+ type: "button",
67277
+ level: "secondary",
67278
+ className: "lui-button-icon-only lui-split-button-primary-btn GridFilterCopyButton-copy",
67279
+ title: copyTitle,
67280
+ buttonProps: { "aria-label": copyTitle },
67281
+ onClick: () => copyToClipboard(copyType),
67282
+ children: /* @__PURE__ */ jsx(LuiIcon, { name: "ic_copy", alt: copyTitle, size: "md" })
67283
+ }
67284
+ ),
67285
+ /* @__PURE__ */ jsx(
67286
+ Menu,
67287
+ {
67288
+ menuButton: /* @__PURE__ */ jsx(
67289
+ "button",
67290
+ {
67291
+ type: "button",
67292
+ className: "popup-toggle-button popup-toggle-button-secondary GridFilterCopyButton-caret",
67293
+ title: "Copy options",
67294
+ "aria-label": "Copy options",
67295
+ onClick: (e) => setDeveloperMenu(e.ctrlKey && e.shiftKey),
67296
+ children: /* @__PURE__ */ jsx(LuiIcon, { name: "ic_expand_more", alt: "Copy options", size: "md" })
67297
+ }
67298
+ ),
67299
+ menuClassName: "step-ag-grid-react-menu",
67300
+ className: "GridContextMenu",
67301
+ align: "end",
67302
+ portal: true,
67303
+ unmountOnClose: true,
67304
+ children: /* @__PURE__ */ jsx(GridFilterCopyMenuItems, { developer: developerMenu })
67305
+ }
67306
+ )
67307
+ ] });
67308
+ };
67309
+
67048
67310
  const useTimeoutHook = () => {
67049
67311
  const timeout = useRef(void 0);
67050
67312
  const clearTimeouts = () => {
@@ -69188,10 +69450,12 @@ const colStateFlexed = (colState) => !!colState.flex;
69188
69450
  const colStateNotFlexed = (colState) => !colState.flex;
69189
69451
  const GridContextProvider = (props) => {
69190
69452
  const { modifyUpdating, anyUpdating } = useContext(GridUpdatingContext);
69453
+ const showToast = useShowLUIMessage();
69191
69454
  const [gridApi, setGridApi] = useState();
69192
69455
  const [gridReady, setGridReady] = useState(false);
69193
69456
  const [quickFilter, _setQuickFilter] = useState("");
69194
69457
  const [invisibleColumnIds, _setInvisibleColumnIds] = useState();
69458
+ const [copyEnabled, setCopyEnabled] = useState(false);
69195
69459
  const testId = useRef(void 0);
69196
69460
  const hasExternallySelectedItemsRef = useRef(false);
69197
69461
  const enableMultilineBulkEditRef = useRef(false);
@@ -69820,6 +70084,70 @@ const GridContextProvider = (props) => {
69820
70084
  },
69821
70085
  [gridApi]
69822
70086
  );
70087
+ const rangeCopyRef = useRef(void 0);
70088
+ const setRangeCopy = useCallback((rangeCopy) => {
70089
+ rangeCopyRef.current = rangeCopy;
70090
+ }, []);
70091
+ const getCopyRows = useCallback(() => {
70092
+ const nodes = [];
70093
+ if (gridApi && !gridApi.isDestroyed()) {
70094
+ gridApi.forEachNodeAfterFilterAndSort((node) => {
70095
+ if (node.data && !node.group) nodes.push(node);
70096
+ });
70097
+ }
70098
+ const selectedNodes = nodes.filter((node) => node.isSelected());
70099
+ return isEmpty(selectedNodes) ? { scope: "all", nodes } : { scope: "selection", nodes: selectedNodes };
70100
+ }, [gridApi]);
70101
+ const getDisplayedCopyColIds = useCallback(
70102
+ () => gridApi && !gridApi.isDestroyed() ? gridApi.getAllDisplayedColumns().map((col) => col.getColId()).filter((colId) => colId !== agGridSelectRowColId) : [],
70103
+ [gridApi]
70104
+ );
70105
+ const getCopyTarget = useCallback(() => {
70106
+ const rangeCopy = rangeCopyRef.current;
70107
+ const { selectedColIds, selectedNodes } = rangeCopy?.hasRange() ? rangeCopy.getRange() : { selectedColIds: getDisplayedCopyColIds(), selectedNodes: getCopyRows().nodes };
70108
+ return {
70109
+ colIds: selectedColIds.filter((colId) => colId !== agGridSelectRowColId && isCopyableColId(colId, getColDef)),
70110
+ nodes: selectedNodes
70111
+ };
70112
+ }, [getColDef, getCopyRows, getDisplayedCopyColIds]);
70113
+ const getSelectedDataForCopy = useCallback(() => {
70114
+ const { colIds, nodes } = getCopyTarget();
70115
+ const fields = compact(colIds.map((colId) => getColDef(colId)?.field));
70116
+ return nodes.map((node) => {
70117
+ const data = {};
70118
+ fields.forEach((field) => set(data, field, get(node.data, field)));
70119
+ return data;
70120
+ });
70121
+ }, [getColDef, getCopyTarget]);
70122
+ const getCopyData = useCallback(() => {
70123
+ const { colIds, nodes } = getCopyTarget();
70124
+ return nodes.map(
70125
+ (rowNode) => Object.fromEntries(colIds.map((colKey) => [colKey, gridApi?.getCellValue({ rowNode, colKey })]))
70126
+ );
70127
+ }, [getCopyTarget, gridApi]);
70128
+ const getCopyScope = useCallback(
70129
+ () => rangeCopyRef.current?.hasRange() ? "range" : getCopyRows().scope,
70130
+ [getCopyRows]
70131
+ );
70132
+ const copyToClipboard = useCallback(
70133
+ (type = getDefaultCopyType()) => {
70134
+ if (rangeCopyRef.current?.hasRange()) {
70135
+ rangeCopyRef.current.copy(type);
70136
+ return;
70137
+ }
70138
+ if (!gridApi || gridApi.isDestroyed()) return;
70139
+ copyGridCells({
70140
+ type,
70141
+ selectedColIds: getDisplayedCopyColIds(),
70142
+ selectedNodes: getCopyRows().nodes,
70143
+ selectedRowIds: getSelectedRowIds(),
70144
+ getColDef,
70145
+ getCellValue,
70146
+ showToast
70147
+ });
70148
+ },
70149
+ [getCellValue, getColDef, getCopyRows, getDisplayedCopyColIds, getSelectedRowIds, gridApi, showToast]
70150
+ );
69823
70151
  return /* @__PURE__ */ jsx(
69824
70152
  GridContext.Provider,
69825
70153
  {
@@ -69864,6 +70192,13 @@ const GridContextProvider = (props) => {
69864
70192
  isExternalFilterPresent,
69865
70193
  doesExternalFilterPass,
69866
70194
  downloadCsv,
70195
+ copyToClipboard,
70196
+ getCopyScope,
70197
+ getSelectedDataForCopy,
70198
+ getCopyData,
70199
+ setRangeCopy,
70200
+ copyEnabled,
70201
+ setCopyEnabled,
69867
70202
  onBulkEditingComplete,
69868
70203
  setOnBulkEditingComplete,
69869
70204
  showNoRowsOverlay
@@ -70078,5 +70413,5 @@ const useDeferredPromise = () => {
70078
70413
  };
70079
70414
  };
70080
70415
 
70081
- export { ActionButton, CancelPromise, ChromaticAllowGridAutosize, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellBearingValueFormatter, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormInlineTextInput, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridInlineTextInput, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, agGridSelectRowColId, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, compareNaturalInsensitive, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isChromatic, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, reorderRows, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textInputValidatorPropsToSummary, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
70416
+ export { ActionButton, CancelPromise, ChromaticAllowGridAutosize, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellBearingValueFormatter, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterCopyButton, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormInlineTextInput, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridInlineTextInput, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, agGridSelectRowColId, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, compareNaturalInsensitive, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isChromatic, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, reorderRows, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textInputValidatorPropsToSummary, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
70082
70417
  //# sourceMappingURL=step-ag-grid.esm.js.map