@linzjs/step-ag-grid 35.1.0 → 35.2.1

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 (33) hide show
  1. package/dist/index.css +17 -0
  2. package/dist/src/components/Grid.d.ts +3 -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/useGridCopy.d.ts +5 -2
  9. package/dist/src/components/gridHook/useGridCopySettings.d.ts +2 -0
  10. package/dist/src/contexts/GridContext.d.ts +35 -0
  11. package/dist/src/contexts/GridContextProvider.copy.test.d.ts +1 -0
  12. package/dist/step-ag-grid.cjs +434 -233
  13. package/dist/step-ag-grid.cjs.map +1 -1
  14. package/dist/step-ag-grid.esm.js +435 -235
  15. package/dist/step-ag-grid.esm.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/components/Grid.tsx +15 -0
  18. package/src/components/GridRangeSelectContextMenu.tsx +54 -51
  19. package/src/components/gridFilter/GridFilterCopyButton.tsx +93 -0
  20. package/src/components/gridFilter/index.ts +1 -0
  21. package/src/components/gridHook/copyGridCells.test.ts +142 -0
  22. package/src/components/gridHook/copyGridCells.ts +225 -0
  23. package/src/components/gridHook/useGridCopy.ts +88 -211
  24. package/src/components/gridHook/useGridCopySettings.ts +21 -6
  25. package/src/contexts/GridContext.tsx +44 -0
  26. package/src/contexts/GridContextProvider.copy.test.tsx +158 -0
  27. package/src/contexts/GridContextProvider.tsx +129 -2
  28. package/src/contexts/GridPopoverContextProvider.tsx +7 -2
  29. package/src/stories/grid/GridCopy.stories.tsx +35 -20
  30. package/src/stories/grid/GridCopyEditable.stories.tsx +131 -0
  31. package/src/stories/grid/GridCopyMultiple.stories.tsx +119 -0
  32. package/src/styles/GridFilterCopyButton.scss +22 -0
  33. package/src/styles/index.scss +1 -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
@@ -65030,13 +65037,21 @@ const gridCopyOptions = {
65030
65037
  json: { text: "Json", icon: "ic_file_attached_outline", developer: true }
65031
65038
  };
65032
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
+ };
65033
65045
  const useGridCopySettings = () => {
65034
- const [copyType, _setCopyType] = useState(() => {
65035
- const defaultCopy = window.localStorage.getItem(CopyOptionsStorageKey) ?? "";
65036
- return Object.keys(gridCopyOptions).includes(defaultCopy) ? defaultCopy : "html";
65037
- });
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
+ }, []);
65038
65053
  const setCopyType = useCallback((key) => {
65039
- window.localStorage.setItem(CopyOptionsStorageKey, key);
65054
+ publishStorageKey(window.localStorage, CopyOptionsStorageKey, key, listenerRef.current);
65040
65055
  _setCopyType(key);
65041
65056
  }, []);
65042
65057
  return {
@@ -65045,59 +65060,231 @@ const useGridCopySettings = () => {
65045
65060
  };
65046
65061
  };
65047
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
+ ] });
65048
65092
  const GridRangeSelectContextMenu = ({
65049
65093
  event,
65050
65094
  context
65051
65095
  }) => {
65052
65096
  const developerContextMenu = !!event?.event?.ctrlKey && !!event?.event?.shiftKey;
65053
- const onCopy = useMemo(() => context?.onCopy, [context?.onCopy]);
65054
- const onClick = useCallback(
65055
- (type) => {
65056
- onCopy?.(type);
65057
- },
65058
- [onCopy]
65059
- );
65060
- return /* @__PURE__ */ jsxs(Fragment, { children: [
65061
- /* @__PURE__ */ jsx(MenuHeader, { children: "Copy as" }),
65062
- typedEntries(gridCopyOptions).map(([key, { icon, text, developer }]) => {
65063
- return (!developer || developerContextMenu) && /* @__PURE__ */ jsx(MenuItem, { onClick: () => void onClick(key), children: /* @__PURE__ */ jsxs("div", { className: "copyMenuMenuItem", children: [
65064
- /* @__PURE__ */ jsx(LuiIcon, { name: icon, alt: text, size: "md" }),
65065
- /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
65066
- ] }) }, key);
65067
- }),
65068
- /* @__PURE__ */ jsx(MenuDivider, {}),
65069
- /* @__PURE__ */ jsx(MenuHeader, { children: "Set copy default" }),
65070
- typedEntries(gridCopyOptions).map(([key, { text, developer }]) => {
65071
- return !developer && /* @__PURE__ */ jsx(
65072
- MenuItem,
65073
- {
65074
- onClick: (e) => {
65075
- context?.setCopyType(key);
65076
- e.keepOpen = true;
65077
- },
65078
- children: /* @__PURE__ */ jsxs(
65079
- "div",
65080
- {
65081
- className: clsx(
65082
- "copyMenuMenuItem",
65083
- context?.copyType === key ? "" : "copyMenuMenuItem__buttonDefault--hidden"
65084
- ),
65085
- children: [
65086
- /* @__PURE__ */ jsx(LuiIcon, { name: "ic_tick", alt: "CSV", size: "sm" }),
65087
- /* @__PURE__ */ jsx("div", { className: "copyMenuMenuItem__text", children: text })
65088
- ]
65089
- }
65090
- )
65091
- },
65092
- "default_" + key
65093
- );
65094
- })
65095
- ] });
65097
+ return context ? /* @__PURE__ */ jsx(GridCopyOptionsMenuItems, { ...context, developer: developerContextMenu }) : null;
65096
65098
  };
65097
65099
 
65098
65100
  const agGridSelectRowColId = "ag-Grid-SelectionColumn";
65099
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);
65100
65285
  const useGridCopy = ({
65286
+ gridDivRef,
65287
+ gridDocument,
65101
65288
  ranges,
65102
65289
  rangeStartRef,
65103
65290
  rangeEndRef,
@@ -65105,193 +65292,41 @@ const useGridCopy = ({
65105
65292
  cellContextMenu
65106
65293
  }) => {
65107
65294
  const showToast = useShowLUIMessage();
65108
- const { getSelectedRowIds } = useGridContext();
65109
- const { getColDef, getCellValue } = useGridContext();
65295
+ const { getColDef, getCellValue, getSelectedRowIds, setRangeCopy } = useGridContext();
65110
65296
  const { copyType, setCopyType } = useGridCopySettings();
65297
+ const hasRange = useCallback(
65298
+ () => rangeStartRef.current !== null && rangeEndRef.current !== null && hasSelectedMoreThanOneCellRef.current,
65299
+ [rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef]
65300
+ );
65111
65301
  const onCopy = useCallback(
65112
65302
  (type = copyType) => {
65113
65303
  const rangeStart = rangeStartRef.current;
65114
65304
  const rangeEnd = rangeEndRef.current;
65115
- if (rangeStart === null || rangeEnd === null || !hasSelectedMoreThanOneCellRef.current) {
65305
+ if (rangeStart === null || rangeEnd === null || !hasRange()) {
65116
65306
  return;
65117
65307
  }
65118
65308
  if (rangeStart.rowId === rangeEnd.rowId && rangeStart.colId === rangeEnd.colId) {
65119
65309
  type = "html";
65120
65310
  }
65121
- const json = type === "json";
65122
65311
  const { selectedColIds, selectedNodes } = ranges();
65123
- const filteredSelectedColIds = selectedColIds.filter(
65124
- (colId) => colId === agGridSelectRowColId || colId !== "gridCellFiller" && getColDef(colId)?.headerComponentParams?.exportable !== false
65125
- );
65126
- const selectedRowIds = getSelectedRowIds();
65127
- const formatters = compact(
65128
- filteredSelectedColIds.map((colKey) => {
65129
- return (rowNode) => {
65130
- if (colKey === agGridSelectRowColId) {
65131
- return selectedRowIds.includes(rowNode.data.id);
65132
- } else {
65133
- const v = getCellValue({ rowNode, colKey });
65134
- if (json && v !== void 0) {
65135
- return v;
65136
- }
65137
- const f = getCellValue({ rowNode, colKey, useFormatter: true });
65138
- return v == f ? v : f;
65139
- }
65140
- };
65141
- })
65142
- );
65143
- const headers = filteredSelectedColIds.map((colId) => {
65144
- if (colId === agGridSelectRowColId) return type === "json" ? "selected" : "Selected";
65145
- if (json) {
65146
- return colId;
65147
- }
65148
- return getColDef(colId)?.headerName ?? "?";
65149
- });
65150
- const maxCellLength = {};
65151
- headers.forEach((headerName, i) => {
65152
- const colId = filteredSelectedColIds[i];
65153
- maxCellLength[colId] = headerName.length;
65154
- });
65155
- const rows = [];
65156
- if (type === "csv" || type === "html") {
65157
- rows.push(headers);
65158
- }
65159
- selectedNodes.forEach((node) => {
65160
- const row = [];
65161
- rows.push(row);
65162
- formatters.forEach((formatter, i) => {
65163
- const colId = filteredSelectedColIds[i];
65164
- let value = formatter(node);
65165
- if (typeof value === "string") {
65166
- value = value.replaceAll("\xA0", " ");
65167
- }
65168
- if (!json) {
65169
- if (value === "-" || value === "\u2013" || value == null) {
65170
- value = "";
65171
- }
65172
- value = String(value);
65173
- if (value === "-" || value === "\u2013") {
65174
- value = "";
65175
- }
65176
- maxCellLength[colId] = Math.max(maxCellLength[colId], value.length);
65177
- }
65178
- switch (type) {
65179
- case "json":
65180
- value = value === "undefined" || value !== null && typeof value === "object" || typeof value === "string" ? JSON.stringify(value) : value;
65181
- break;
65182
- case "markdown":
65183
- value = encodeMarkdownValue(value);
65184
- break;
65185
- case "csv":
65186
- value = encodeCSVValue(value);
65187
- break;
65188
- }
65189
- row.push(String(value));
65190
- });
65191
- });
65192
- let result = "";
65193
- let html = `<table style="
65194
- font-family: 'Open Sans', system-ui, sans-serif;
65195
- font-size: 10px;
65196
- line-height: 10px;
65197
- border: 1px solid #d1d9e0;
65198
- border-collapse: collapse;
65199
- ">`;
65200
- if (json) {
65201
- result += "[\n";
65202
- }
65203
- rows.forEach((row, rowIndex) => {
65204
- if (json) {
65205
- result += " { ";
65206
- }
65207
- if (rowIndex == 1) {
65208
- html += '<tbody style="font-weight: 400;">';
65209
- }
65210
- if (rowIndex == 0) {
65211
- html += '<thead style="font-weight: 600;">';
65212
- }
65213
- if (rowIndex === 0 || (rowIndex & 1) === 1) {
65214
- html += "<tr>";
65215
- } else {
65216
- html += '<tr style="background-color: #f6f8fa;">';
65217
- }
65218
- if (rowIndex === 1 && type === "html") {
65219
- Object.values(maxCellLength).forEach((maxLength) => {
65220
- result += "|" + "-".repeat(maxLength + 2);
65221
- });
65222
- result += "|\n";
65223
- }
65224
- row.forEach((cell, i) => {
65225
- switch (type) {
65226
- case "csv":
65227
- if (i !== 0) {
65228
- result += ", ";
65229
- }
65230
- result += cell;
65231
- break;
65232
- case "html":
65233
- if (i === 0) {
65234
- result += "|";
65235
- }
65236
- const colId = filteredSelectedColIds[i];
65237
- result += " " + cell.padEnd(maxCellLength[colId], " ") + " ";
65238
- result += "|";
65239
- html += rowIndex === 0 ? '<th style="border: 1px solid #d1d9e0; padding:6px 13px; text-align: left;">' : '<td style="border: 1px solid #d1d9e0; padding:6px 13px;">';
65240
- html += cell;
65241
- html += rowIndex === 0 ? "</th>" : "</td>";
65242
- break;
65243
- case "json":
65244
- if (i !== 0) {
65245
- result += ", ";
65246
- }
65247
- result += JSON.stringify(headers[i]) + ": " + cell;
65248
- break;
65249
- }
65250
- });
65251
- html += "</tr>";
65252
- if (rowIndex == 0) {
65253
- html += "</thead>";
65254
- }
65255
- if (rowIndex == rows.length - 1) {
65256
- html += "</tbody>";
65257
- }
65258
- if (json) {
65259
- result += " }";
65260
- }
65261
- result += "\n";
65262
- });
65263
- if (json) {
65264
- result += "]\n";
65265
- }
65266
- html += "</table>";
65267
- showToast({
65268
- message: `${gridCopyOptions[type].text} copied`,
65269
- messageType: "toast",
65270
- messageLevel: "info"
65312
+ copyGridCells({
65313
+ type,
65314
+ selectedColIds,
65315
+ selectedNodes,
65316
+ selectedRowIds: getSelectedRowIds(),
65317
+ getColDef,
65318
+ getCellValue,
65319
+ showToast
65271
65320
  });
65272
- if (type === "html") {
65273
- const clipboardItem = new ClipboardItem({
65274
- "text/html": new Blob([html], { type: "text/html" }),
65275
- "text/plain": new Blob([result], { type: "text/plain" })
65276
- // fallback
65277
- });
65278
- void navigator.clipboard.write([clipboardItem]).catch((err) => console.error("Failed to copy: ", err));
65279
- } else {
65280
- void navigator.clipboard.writeText(result).catch((err) => console.error("Failed to copy: ", err));
65281
- }
65282
65321
  },
65283
- [
65284
- getCellValue,
65285
- ranges,
65286
- copyType,
65287
- rangeStartRef,
65288
- hasSelectedMoreThanOneCellRef,
65289
- rangeEndRef,
65290
- showToast,
65291
- getColDef,
65292
- getSelectedRowIds
65293
- ]
65322
+ [getCellValue, ranges, copyType, rangeStartRef, hasRange, rangeEndRef, showToast, getColDef, getSelectedRowIds]
65294
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]);
65295
65330
  const onCopyEvent = useCallback(
65296
65331
  (e) => {
65297
65332
  const rangeStart = rangeStartRef.current;
@@ -65304,6 +65339,31 @@ const useGridCopy = ({
65304
65339
  },
65305
65340
  [onCopy, rangeStartRef, rangeEndRef, hasSelectedMoreThanOneCellRef]
65306
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]);
65307
65367
  const { cellContextMenu: rangeSelectContextMenu, contextMenuComponent: rangeSelectContextMenuComponent } = useGridContextMenu({
65308
65368
  contextMenu: GridRangeSelectContextMenu,
65309
65369
  context: { onCopy, copyType, setCopyType }
@@ -65320,16 +65380,6 @@ const useGridCopy = ({
65320
65380
  rangeSelectContextMenuComponent
65321
65381
  };
65322
65382
  };
65323
- const encodeMarkdownValue = (value) => {
65324
- return value.replaceAll("|", "\\|");
65325
- };
65326
- const encodeCSVValue = (value) => {
65327
- let str = String(value);
65328
- if (/[",\n]/.test(str)) {
65329
- str = '"' + str.replace(/"/g, '""') + '"';
65330
- }
65331
- return str;
65332
- };
65333
65383
 
65334
65384
  const useGridRangeSelection = ({
65335
65385
  enableRangeSelection,
@@ -65751,6 +65801,7 @@ const Grid = ({
65751
65801
  // ─── Selection ────────────────────────────────
65752
65802
  autoSelectFirstRow,
65753
65803
  enableRangeSelection = false,
65804
+ enableCopy = false,
65754
65805
  externalSelectedIds,
65755
65806
  externalSelectedItems,
65756
65807
  selectColumnPinned = "left",
@@ -65781,6 +65832,7 @@ const Grid = ({
65781
65832
  setApis,
65782
65833
  setExternallySelectedItemsAreInSync,
65783
65834
  setOnBulkEditingComplete,
65835
+ setCopyEnabled,
65784
65836
  gridReady,
65785
65837
  gridRenderState,
65786
65838
  externallySelectedItemsAreInSync,
@@ -65875,6 +65927,7 @@ const Grid = ({
65875
65927
  }
65876
65928
  }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
65877
65929
  const lastOwnerDocumentRef = useRef(void 0);
65930
+ const [gridDocument, setGridDocument] = useState();
65878
65931
  const wasVisibleRef = useRef(false);
65879
65932
  useInterval(() => {
65880
65933
  const visible = !!gridDivRef.current?.checkVisibility?.();
@@ -65892,6 +65945,7 @@ const Grid = ({
65892
65945
  const currentDocument = gridDivRef.current?.ownerDocument;
65893
65946
  if (currentDocument !== lastOwnerDocumentRef.current) {
65894
65947
  lastOwnerDocumentRef.current = currentDocument;
65948
+ setGridDocument(currentDocument);
65895
65949
  if (currentDocument) {
65896
65950
  needsAutoSize.current = true;
65897
65951
  }
@@ -66143,12 +66197,18 @@ const Grid = ({
66143
66197
  rangeSortedNodesRef
66144
66198
  });
66145
66199
  const { onCopyEvent, rangeSelectInterceptContextMenu, rangeSelectContextMenuComponent } = useGridCopy({
66200
+ gridDivRef,
66201
+ gridDocument,
66146
66202
  ranges,
66147
66203
  rangeStartRef,
66148
66204
  rangeEndRef,
66149
66205
  hasSelectedMoreThanOneCellRef,
66150
66206
  cellContextMenu
66151
66207
  });
66208
+ useEffect(() => {
66209
+ setCopyEnabled(enableCopy);
66210
+ return () => setCopyEnabled(false);
66211
+ }, [enableCopy, setCopyEnabled]);
66152
66212
  const userSizedColIds = useRef(/* @__PURE__ */ new Map());
66153
66213
  const { saveColumnState: saveColumnStateToStorage } = useGridColumnStateStorage({
66154
66214
  enabled: saveColumnState,
@@ -66656,15 +66716,16 @@ const GridPopoverContextProvider = (props2) => {
66656
66716
  );
66657
66717
  const field = props.colDef?.field ?? "";
66658
66718
  const colId = props.colDef?.colId ?? field ?? "";
66719
+ const updatingKey = props.colDef?.field ?? props.colDef?.colId ?? "";
66659
66720
  const updateValue = useCallback(
66660
66721
  async (saveFn, tabDirection) => {
66661
66722
  if (hasSaved.current) {
66662
66723
  return true;
66663
66724
  }
66664
66725
  hasSaved.current = true;
66665
- return saving ? false : await updatingCells({ selectedRows, field }, saveFn, setSaving, tabDirection);
66726
+ return saving ? false : await updatingCells({ selectedRows, field: updatingKey }, saveFn, setSaving, tabDirection);
66666
66727
  },
66667
- [field, saving, selectedRows, updatingCells]
66728
+ [saving, selectedRows, updatingCells, updatingKey]
66668
66729
  );
66669
66730
  return /* @__PURE__ */ jsx(
66670
66731
  GridPopoverContext.Provider,
@@ -67181,6 +67242,72 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
67181
67242
  );
67182
67243
  };
67183
67244
 
67245
+ const copyScopeHeader = {
67246
+ range: "Copy range",
67247
+ selection: "Copy selection",
67248
+ all: "Copy all"
67249
+ };
67250
+ const copyTypeTooltipText = (copyType) => copyType === "html" ? "text / HTML" : gridCopyOptions[copyType].text;
67251
+ const GridFilterCopyMenuItems = ({ developer }) => {
67252
+ const { copyToClipboard, getCopyScope } = useGridContext();
67253
+ const { copyType, setCopyType } = useGridCopySettings();
67254
+ return /* @__PURE__ */ jsx(
67255
+ GridCopyOptionsMenuItems,
67256
+ {
67257
+ header: copyScopeHeader[getCopyScope()],
67258
+ onCopy: copyToClipboard,
67259
+ copyType,
67260
+ setCopyType,
67261
+ developer
67262
+ }
67263
+ );
67264
+ };
67265
+ const GridFilterCopyButton = () => {
67266
+ const { copyEnabled, copyToClipboard, getCopyScope } = useGridContext();
67267
+ const { copyType } = useGridCopySettings();
67268
+ const [copyScope, setCopyScope] = useState("all");
67269
+ const updateCopyScope = useCallback(() => setCopyScope(getCopyScope()), [getCopyScope]);
67270
+ const [developerMenu, setDeveloperMenu] = useState(false);
67271
+ if (!copyEnabled) return null;
67272
+ const copyTitle = `${copyScopeHeader[copyScope]} as ${copyTypeTooltipText(copyType)}`;
67273
+ return /* @__PURE__ */ jsxs("div", { className: "lui-split-button GridFilterCopyButton", onMouseEnter: updateCopyScope, onFocus: updateCopyScope, children: [
67274
+ /* @__PURE__ */ jsx(
67275
+ LuiButton,
67276
+ {
67277
+ type: "button",
67278
+ level: "secondary",
67279
+ className: "lui-button-icon-only lui-split-button-primary-btn GridFilterCopyButton-copy",
67280
+ title: copyTitle,
67281
+ buttonProps: { "aria-label": copyTitle },
67282
+ onClick: () => copyToClipboard(copyType),
67283
+ children: /* @__PURE__ */ jsx(LuiIcon, { name: "ic_copy", alt: copyTitle, size: "md" })
67284
+ }
67285
+ ),
67286
+ /* @__PURE__ */ jsx(
67287
+ Menu,
67288
+ {
67289
+ menuButton: /* @__PURE__ */ jsx(
67290
+ "button",
67291
+ {
67292
+ type: "button",
67293
+ className: "popup-toggle-button popup-toggle-button-secondary GridFilterCopyButton-caret",
67294
+ title: "Copy options",
67295
+ "aria-label": "Copy options",
67296
+ onClick: (e) => setDeveloperMenu(e.ctrlKey && e.shiftKey),
67297
+ children: /* @__PURE__ */ jsx(LuiIcon, { name: "ic_expand_more", alt: "Copy options", size: "md" })
67298
+ }
67299
+ ),
67300
+ menuClassName: "step-ag-grid-react-menu",
67301
+ className: "GridContextMenu",
67302
+ align: "end",
67303
+ portal: true,
67304
+ unmountOnClose: true,
67305
+ children: /* @__PURE__ */ jsx(GridFilterCopyMenuItems, { developer: developerMenu })
67306
+ }
67307
+ )
67308
+ ] });
67309
+ };
67310
+
67184
67311
  const useTimeoutHook = () => {
67185
67312
  const timeout = useRef(void 0);
67186
67313
  const clearTimeouts = () => {
@@ -69324,10 +69451,12 @@ const colStateFlexed = (colState) => !!colState.flex;
69324
69451
  const colStateNotFlexed = (colState) => !colState.flex;
69325
69452
  const GridContextProvider = (props) => {
69326
69453
  const { modifyUpdating, anyUpdating } = useContext(GridUpdatingContext);
69454
+ const showToast = useShowLUIMessage();
69327
69455
  const [gridApi, setGridApi] = useState();
69328
69456
  const [gridReady, setGridReady] = useState(false);
69329
69457
  const [quickFilter, _setQuickFilter] = useState("");
69330
69458
  const [invisibleColumnIds, _setInvisibleColumnIds] = useState();
69459
+ const [copyEnabled, setCopyEnabled] = useState(false);
69331
69460
  const testId = useRef(void 0);
69332
69461
  const hasExternallySelectedItemsRef = useRef(false);
69333
69462
  const enableMultilineBulkEditRef = useRef(false);
@@ -69956,6 +70085,70 @@ const GridContextProvider = (props) => {
69956
70085
  },
69957
70086
  [gridApi]
69958
70087
  );
70088
+ const rangeCopyRef = useRef(void 0);
70089
+ const setRangeCopy = useCallback((rangeCopy) => {
70090
+ rangeCopyRef.current = rangeCopy;
70091
+ }, []);
70092
+ const getCopyRows = useCallback(() => {
70093
+ const nodes = [];
70094
+ if (gridApi && !gridApi.isDestroyed()) {
70095
+ gridApi.forEachNodeAfterFilterAndSort((node) => {
70096
+ if (node.data && !node.group) nodes.push(node);
70097
+ });
70098
+ }
70099
+ const selectedNodes = nodes.filter((node) => node.isSelected());
70100
+ return isEmpty(selectedNodes) ? { scope: "all", nodes } : { scope: "selection", nodes: selectedNodes };
70101
+ }, [gridApi]);
70102
+ const getDisplayedCopyColIds = useCallback(
70103
+ () => gridApi && !gridApi.isDestroyed() ? gridApi.getAllDisplayedColumns().map((col) => col.getColId()).filter((colId) => colId !== agGridSelectRowColId) : [],
70104
+ [gridApi]
70105
+ );
70106
+ const getCopyTarget = useCallback(() => {
70107
+ const rangeCopy = rangeCopyRef.current;
70108
+ const { selectedColIds, selectedNodes } = rangeCopy?.hasRange() ? rangeCopy.getRange() : { selectedColIds: getDisplayedCopyColIds(), selectedNodes: getCopyRows().nodes };
70109
+ return {
70110
+ colIds: selectedColIds.filter((colId) => colId !== agGridSelectRowColId && isCopyableColId(colId, getColDef)),
70111
+ nodes: selectedNodes
70112
+ };
70113
+ }, [getColDef, getCopyRows, getDisplayedCopyColIds]);
70114
+ const getSelectedDataForCopy = useCallback(() => {
70115
+ const { colIds, nodes } = getCopyTarget();
70116
+ const fields = compact(colIds.map((colId) => getColDef(colId)?.field));
70117
+ return nodes.map((node) => {
70118
+ const data = {};
70119
+ fields.forEach((field) => set(data, field, get(node.data, field)));
70120
+ return data;
70121
+ });
70122
+ }, [getColDef, getCopyTarget]);
70123
+ const getCopyData = useCallback(() => {
70124
+ const { colIds, nodes } = getCopyTarget();
70125
+ return nodes.map(
70126
+ (rowNode) => Object.fromEntries(colIds.map((colKey) => [colKey, gridApi?.getCellValue({ rowNode, colKey })]))
70127
+ );
70128
+ }, [getCopyTarget, gridApi]);
70129
+ const getCopyScope = useCallback(
70130
+ () => rangeCopyRef.current?.hasRange() ? "range" : getCopyRows().scope,
70131
+ [getCopyRows]
70132
+ );
70133
+ const copyToClipboard = useCallback(
70134
+ (type = getDefaultCopyType()) => {
70135
+ if (rangeCopyRef.current?.hasRange()) {
70136
+ rangeCopyRef.current.copy(type);
70137
+ return;
70138
+ }
70139
+ if (!gridApi || gridApi.isDestroyed()) return;
70140
+ copyGridCells({
70141
+ type,
70142
+ selectedColIds: getDisplayedCopyColIds(),
70143
+ selectedNodes: getCopyRows().nodes,
70144
+ selectedRowIds: getSelectedRowIds(),
70145
+ getColDef,
70146
+ getCellValue,
70147
+ showToast
70148
+ });
70149
+ },
70150
+ [getCellValue, getColDef, getCopyRows, getDisplayedCopyColIds, getSelectedRowIds, gridApi, showToast]
70151
+ );
69959
70152
  return /* @__PURE__ */ jsx(
69960
70153
  GridContext.Provider,
69961
70154
  {
@@ -70000,6 +70193,13 @@ const GridContextProvider = (props) => {
70000
70193
  isExternalFilterPresent,
70001
70194
  doesExternalFilterPass,
70002
70195
  downloadCsv,
70196
+ copyToClipboard,
70197
+ getCopyScope,
70198
+ getSelectedDataForCopy,
70199
+ getCopyData,
70200
+ setRangeCopy,
70201
+ copyEnabled,
70202
+ setCopyEnabled,
70003
70203
  onBulkEditingComplete,
70004
70204
  setOnBulkEditingComplete,
70005
70205
  showNoRowsOverlay
@@ -70214,5 +70414,5 @@ const useDeferredPromise = () => {
70214
70414
  };
70215
70415
  };
70216
70416
 
70217
- 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 };
70417
+ 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 };
70218
70418
  //# sourceMappingURL=step-ag-grid.esm.js.map