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