@m4l/components 0.1.31 → 0.1.32

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 (63) hide show
  1. package/components/CommonActions/components/ActionCancel/{index.01a86ee6.js → index.641ea102.js} +1 -1
  2. package/components/CommonActions/components/ActionFormCancel/{index.e18a3161.js → index.3b9e5121.js} +2 -2
  3. package/components/CommonActions/components/ActionIntro/{index.fdd7e34d.js → index.d53e0d31.js} +1 -1
  4. package/components/CommonActions/components/Actions/{index.c87086ac.js → index.545d7067.js} +22 -24
  5. package/components/DataGrid/contexts/DataGridContext/index.d.ts +5 -0
  6. package/components/DataGrid/contexts/{BaseContext → DataGridContext}/types.d.ts +4 -16
  7. package/components/DataGrid/contexts/FilterContext/types.d.ts +8 -4
  8. package/components/DataGrid/hooks/useDataGrid.d.ts +3 -0
  9. package/components/DataGrid/{index.fc1ace65.js → index.b6a45f67.js} +335 -311
  10. package/components/DataGrid/{components → subcomponents}/Actions/index.d.ts +0 -0
  11. package/components/DataGrid/{components → subcomponents}/Actions/styles.d.ts +0 -0
  12. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Density/index.d.ts +0 -0
  13. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Density/styles.d.ts +0 -0
  14. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Filter/index.d.ts +0 -0
  15. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Filter/styles.d.ts +0 -0
  16. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/RowsCount/index.d.ts +0 -0
  17. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/RowsCount/styles.d.ts +0 -0
  18. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Settings/index.d.ts +0 -0
  19. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Settings/styles.d.ts +0 -0
  20. package/components/DataGrid/{components/Actions/components/Settings → subcomponents/Actions/subcomponents/Settings/subcomponents}/ColumnsConfig/index.d.ts +0 -0
  21. package/components/DataGrid/{components/Actions/components/Settings → subcomponents/Actions/subcomponents/Settings/subcomponents}/ColumnsConfig/styles.d.ts +0 -0
  22. package/components/DataGrid/{components/Actions/components/Settings/ColumnsConfig/components → subcomponents/Actions/subcomponents/Settings/subcomponents/ColumnsConfig/subcomponents}/FormatterColumn/index.d.ts +0 -0
  23. package/components/DataGrid/{components/Actions/components/Settings → subcomponents/Actions/subcomponents/Settings/subcomponents}/ColumnsConfig/types.d.ts +1 -1
  24. package/components/DataGrid/{components/Actions/components → subcomponents/Actions/subcomponents}/Settings/types.d.ts +0 -0
  25. package/components/DataGrid/{components → subcomponents}/Actions/types.d.ts +1 -1
  26. package/components/DataGrid/{components → subcomponents}/Table/hooks/getDragHeaderRenderer.d.ts +0 -0
  27. package/components/DataGrid/{components → subcomponents}/Table/hooks/useFocusRef.d.ts +0 -0
  28. package/components/DataGrid/{components → subcomponents}/Table/hooks/useSortColumnsRows.d.ts +1 -1
  29. package/components/DataGrid/{components → subcomponents}/Table/index.d.ts +0 -0
  30. package/components/DataGrid/{components → subcomponents}/Table/styles.d.ts +0 -0
  31. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/ActionsColumn.d.ts +0 -0
  32. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/CheckboxFormatter.d.ts +0 -0
  33. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/CustomIcons.d.ts +0 -0
  34. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/DraggableHeaderRenderer.d.ts +0 -0
  35. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/SelectColumn.d.ts +0 -0
  36. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/SkeletonFormatter/index.d.ts +0 -0
  37. package/components/DataGrid/{components/Table/components → subcomponents/Table/subcomponents}/SkeletonFormatter/styles.d.ts +0 -0
  38. package/components/DataGrid/{components → subcomponents}/editors/TextEditor/index.d.ts +0 -0
  39. package/components/DataGrid/types.d.ts +6 -4
  40. package/components/DataGrid/utils/getDataGridRowsFromSet.d.ts +1 -0
  41. package/components/DynamicFilter/{index.12df5a80.js → index.b3b19031.js} +8 -8
  42. package/components/ModalDialog/{index.6bec80b1.js → index.81b8e093.js} +2 -2
  43. package/components/ObjectLogs/{index.93488e5f.js → index.af1c3382.js} +3 -4
  44. package/components/Period/{index.f17be628.js → index.9ce96aed.js} +2 -2
  45. package/components/formatters/BooleanFormatter/{index.35185e99.js → index.81f4ea70.js} +18 -15
  46. package/components/formatters/PointsFormatter/index.d.ts +1 -0
  47. package/components/formatters/PointsFormatter/types.d.ts +3 -2
  48. package/components/formatters/UncertaintyFormatter/index.d.ts +1 -0
  49. package/components/formatters/UncertaintyFormatter/types.d.ts +4 -3
  50. package/components/formatters/{index.b7532df7.js → index.a0309e3a.js} +47 -50
  51. package/components/formatters/index.d.ts +2 -2
  52. package/components/hook-form/RHFPeriod/{index.e8c2c210.js → index.116158c4.js} +1 -1
  53. package/components/index.d.ts +2 -1
  54. package/components/mui_extended/Button/{index.6bdb0b2d.js → index.bd85b59c.js} +1 -1
  55. package/components/mui_extended/Pager/{index.66593ad3.js → index.a98c43cc.js} +1 -1
  56. package/components/mui_extended/Popover/{index.4c70cdba.js → index.f38042fc.js} +3 -3
  57. package/contexts/ModalContext/{index.6d1021d4.js → index.9a44cced.js} +3 -3
  58. package/hooks/useModal/{index.ee8b9d9f.js → index.2a92d33a.js} +1 -1
  59. package/index.js +27 -24
  60. package/package.json +1 -1
  61. package/react-data-grid.d46d625e.js +1 -1
  62. package/components/DataGrid/contexts/BaseContext/index.d.ts +0 -5
  63. package/components/DataGrid/hooks/useBase.d.ts +0 -1
@@ -1,14 +1,14 @@
1
1
  import { styled, alpha } from "@mui/material/styles";
2
- import { forwardRef, useRef, useLayoutEffect, createContext, useState, useContext, useEffect, useMemo, useCallback } from "react";
3
- import { S as SELECT_COLUMN_KEY, a as SelectCellFormatter, u as useRowSelection, H as HeaderRenderer, D as DataGrid$1 } from "../../react-data-grid.d46d625e.js";
2
+ import { forwardRef, createContext, useState, useMemo, useEffect, useCallback, useContext, useRef, useLayoutEffect } from "react";
3
+ import { S as SELECT_COLUMN_KEY, u as useRowSelection, a as SelectCellFormatter, H as HeaderRenderer, D as DataGrid$1 } from "../../react-data-grid.d46d625e.js";
4
4
  import { useDrag, useDrop, DndProvider } from "react-dnd";
5
5
  import { HTML5Backend } from "react-dnd-html5-backend";
6
6
  import { SvgIcon, Checkbox, InputBase, Skeleton } from "@mui/material";
7
7
  import { jsx, jsxs } from "react/jsx-runtime";
8
- import { voidFunction, useModuleDictionary, useModuleSkeleton } from "@m4l/core";
9
- import { A as ActionsColumn, a as Actions } from "../CommonActions/components/Actions/index.c87086ac.js";
10
- import { g as getModalDialogComponentsDictionary, d as defaultModalDialogDictionary } from "../ModalDialog/index.6bec80b1.js";
11
- import { g as getPagerComponentsDictionary, d as defaultPagerDictionary } from "../mui_extended/Pager/index.66593ad3.js";
8
+ import { voidFunction, useModuleDictionary, useModuleSkeleton, getPropertyByString } from "@m4l/core";
9
+ import { A as ActionsColumn, a as Actions } from "../CommonActions/components/Actions/index.545d7067.js";
10
+ import { g as getModalDialogComponentsDictionary, d as defaultModalDialogDictionary } from "../ModalDialog/index.81b8e093.js";
11
+ import { g as getPagerComponentsDictionary, d as defaultPagerDictionary } from "../mui_extended/Pager/index.a98c43cc.js";
12
12
  const WrapperGrid = styled("div")(() => ({
13
13
  display: "flex",
14
14
  flexDirection: "column",
@@ -202,25 +202,208 @@ const CheckboxFormatter = forwardRef(
202
202
  });
203
203
  }
204
204
  );
205
- const filterColumnClassName = "filter-cell";
206
- const filterHeight = 35;
207
- function SelectFormatter(props) {
208
- const [isRowSelected, onRowSelectionChange] = useRowSelection();
209
- const onChange = (checked, isShiftClick) => {
210
- onRowSelectionChange({
211
- row: props.row,
212
- checked,
213
- isShiftClick
214
- });
205
+ const DataGridContext = createContext(null);
206
+ const getColumnConfigByKey = (key, storeColumnsConfig) => {
207
+ let indexFind = -1;
208
+ return [storeColumnsConfig.find((column, index) => {
209
+ if (column.key === key) {
210
+ indexFind = index;
211
+ }
212
+ return column.key === key;
213
+ }), indexFind];
214
+ };
215
+ function getColumnsConfig(id, columns, remoteConfig = void 0) {
216
+ let columnsConfig;
217
+ if (remoteConfig) {
218
+ columnsConfig = remoteConfig.columnsConfig;
219
+ } else {
220
+ try {
221
+ const item = window.localStorage.getItem(`${id}_columns_config`);
222
+ columnsConfig = item !== null ? JSON.parse(item) : [];
223
+ } catch (e) {
224
+ columnsConfig = [];
225
+ }
226
+ }
227
+ return columns.map((column, index) => {
228
+ const [columnConfig = {
229
+ ...column
230
+ }, columnConfigIndex] = getColumnConfigByKey(column.key, columnsConfig);
231
+ return {
232
+ key: column.key,
233
+ name: column.name,
234
+ hidden: column.hidden === void 0 ? false : column.hidden,
235
+ index: columnConfigIndex > -1 ? columnConfigIndex : index,
236
+ visible: columnConfig.visible === void 0 ? true : columnConfig.visible,
237
+ frozen: columnConfig.frozen === void 0 ? false : columnConfig.frozen,
238
+ orginalIndex: index,
239
+ originalVisible: column.visible === void 0 ? true : column.visible,
240
+ originalFrozen: column.frozen === void 0 ? false : column.frozen
241
+ };
242
+ }).sort((a, b) => a.index - b.index);
243
+ }
244
+ function getColumnsWidth(id, columns, remoteConfig) {
245
+ const newMap = /* @__PURE__ */ new Map();
246
+ let storeColumnsWidth;
247
+ try {
248
+ const item = window.localStorage.getItem(`${id}_columns_width`);
249
+ storeColumnsWidth = item !== null ? new Map(JSON.parse(item)) : /* @__PURE__ */ new Map();
250
+ } catch (e) {
251
+ storeColumnsWidth = /* @__PURE__ */ new Map();
252
+ }
253
+ for (let i = 0; i < columns.length; i++) {
254
+ let width;
255
+ if (remoteConfig) {
256
+ try {
257
+ width = remoteConfig.columnsWidths.get(columns[i].key);
258
+ } catch (error) {
259
+ }
260
+ }
261
+ if (width === void 0) {
262
+ const storeWidth = storeColumnsWidth.get(columns[i].key);
263
+ if (typeof storeWidth === "number") {
264
+ width = storeWidth;
265
+ }
266
+ }
267
+ if (width !== void 0) {
268
+ newMap.set(columns[i].key, width);
269
+ }
270
+ }
271
+ return newMap;
272
+ }
273
+ function saveColumnsWidth(id, storeColumnsWidth) {
274
+ localStorage.setItem(`${id}_columns_width`, JSON.stringify([...storeColumnsWidth]));
275
+ }
276
+ function saveColumnsConfig(id, columnsConfig) {
277
+ localStorage.setItem(`${id}_columns_config`, JSON.stringify(columnsConfig));
278
+ }
279
+ function getIndexRowHeightVariant(variant) {
280
+ if (variant === "compact") {
281
+ return 0;
282
+ }
283
+ if (variant === "standard") {
284
+ return 1;
285
+ }
286
+ return 2;
287
+ }
288
+ function DataGridProvider(props) {
289
+ const {
290
+ id,
291
+ children,
292
+ columns,
293
+ remoteConfig,
294
+ rows,
295
+ rowsCount,
296
+ rowActionsGetter,
297
+ rowHeights = [36, 52, 67],
298
+ rowHeaderHeights = [44, 63, 75],
299
+ initialRowHeightVariant = "compact",
300
+ checkedRows,
301
+ onCheckedRowsChange,
302
+ rowKeyGetter
303
+ } = props;
304
+ const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
305
+ const [columnsConfig, setColumnsConfigOptions] = useState(() => []);
306
+ const [rowsFilterCount, setRowFilterCount] = useState(rowsCount);
307
+ const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
308
+ if (typeof rowHeights !== typeof rowHeaderHeights) {
309
+ throw new Error("Must be same type rowheights and rowHeaderTypes");
310
+ }
311
+ if (typeof rowHeights === "number" && typeof rowHeaderHeights === "number") {
312
+ return {
313
+ rowHVariant: "compact",
314
+ rowHeight: rowHeights,
315
+ rowHeaderHeight: rowHeaderHeights
316
+ };
317
+ }
318
+ if (typeof rowHeights !== "number" && rowHeights.length !== 3) {
319
+ throw new Error("Must be 3 heights");
320
+ }
321
+ if (typeof rowHeaderHeights !== "number" && rowHeaderHeights.length !== 3) {
322
+ throw new Error("Must be 3 HeaderHeights");
323
+ }
324
+ return {
325
+ rowHVariant: initialRowHeightVariant,
326
+ rowHeight: typeof rowHeights !== "number" ? rowHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeights,
327
+ rowHeaderHeight: typeof rowHeaderHeights !== "number" ? rowHeaderHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeaderHeights
328
+ };
329
+ });
330
+ const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
331
+ let timerSaveColumns;
332
+ useEffect(() => {
333
+ }, [columnsConfig]);
334
+ useEffect(() => {
335
+ setColumnsWidths(getColumnsWidth(id, columns, remoteConfig));
336
+ setColumnsConfigOptions(getColumnsConfig(id, columns, remoteConfig));
337
+ }, [columns, id, remoteConfig]);
338
+ const onChangeColumnsConfig = useCallback((newColumnsConfig) => {
339
+ saveColumnsConfig(id, newColumnsConfig);
340
+ setColumnsConfigOptions(newColumnsConfig);
341
+ }, [setColumnsConfigOptions, id]);
342
+ const onChangeColumnsOrder = useCallback((sourceKey, targetKey) => {
343
+ if (sourceKey === targetKey)
344
+ return;
345
+ const sourceColumnIndex = columnsConfig.findIndex((c) => c.key === sourceKey);
346
+ const targetColumnIndex = columnsConfig.findIndex((c) => c.key === targetKey);
347
+ const reorderedColumnsConfig = [...columnsConfig];
348
+ reorderedColumnsConfig.splice(targetColumnIndex, 0, reorderedColumnsConfig.splice(sourceColumnIndex, 1)[0]);
349
+ onChangeColumnsConfig(reorderedColumnsConfig);
350
+ }, [columnsConfig, onChangeColumnsConfig]);
351
+ const onChangeColumnWidth = (columnKey, width) => {
352
+ columnsWidths.set(columnKey, Math.round(width));
353
+ if (timerSaveColumns) {
354
+ clearTimeout(timerSaveColumns);
355
+ }
356
+ timerSaveColumns = setTimeout(() => {
357
+ saveColumnsWidth(id, columnsWidths);
358
+ }, 500);
215
359
  };
216
- const cellFormater = SelectCellFormatter({
217
- value: isRowSelected,
218
- isCellSelected: props.isCellSelected,
219
- onChange,
220
- "aria-label": "Select"
360
+ useEffect(() => {
361
+ setColumnsConfigOptions(getColumnsConfig(id, columns));
362
+ }, [columns]);
363
+ const setRowFilterCountInternal = (newRowsCount) => {
364
+ setRowFilterCount(newRowsCount);
365
+ };
366
+ const setCurrentRowHeightInternal = useCallback((newVariant) => {
367
+ if (typeof rowHeights === "number" || typeof rowHeaderHeights === "number") {
368
+ throw new Error("Only use setCurrentRowHeight with vector rowHeights");
369
+ }
370
+ setCurrentRowHeightVariant({
371
+ rowHVariant: newVariant,
372
+ rowHeight: rowHeights[getIndexRowHeightVariant(newVariant)],
373
+ rowHeaderHeight: rowHeaderHeights[getIndexRowHeightVariant(newVariant)]
374
+ });
375
+ }, [setCurrentRowHeightVariant, rowHeights, rowHeaderHeights]);
376
+ return /* @__PURE__ */ jsx(DataGridContext.Provider, {
377
+ value: {
378
+ columnsConfig,
379
+ columnsWidths,
380
+ onChangeColumnsConfig,
381
+ onChangeColumnsOrder,
382
+ onChangeColumnWidth,
383
+ rowsCount: rowsFilterCount,
384
+ setRowsCount: setRowFilterCountInternal,
385
+ rowActionsGetter,
386
+ currentRowHeightVariant: currentRowHeightVariant.rowHVariant,
387
+ currentRowHeight: currentRowHeightVariant.rowHeight,
388
+ currentRowHeaderHeight: currentRowHeightVariant.rowHeaderHeight,
389
+ rowHeights: finalRowHeights,
390
+ setRowHeightVariant: setCurrentRowHeightInternal,
391
+ rows,
392
+ checkedRows,
393
+ onCheckedRowsChange,
394
+ rowKeyGetter
395
+ },
396
+ children
221
397
  });
222
- return cellFormater;
223
398
  }
399
+ function useDataGrid() {
400
+ const context = useContext(DataGridContext);
401
+ if (!context)
402
+ throw new Error("useDataGrid context must be use inside DataGridContext");
403
+ return context;
404
+ }
405
+ const filterColumnClassName = "filter-cell";
406
+ const filterHeight = 35;
224
407
  function SelectGroupFormatter(props) {
225
408
  const [isRowSelected, onRowSelectionChange] = useRowSelection();
226
409
  const onChange = (checked) => {
@@ -238,6 +421,52 @@ function SelectGroupFormatter(props) {
238
421
  });
239
422
  return cellFormater;
240
423
  }
424
+ function SelectFormatter(props) {
425
+ const {
426
+ checkedRows,
427
+ onCheckedRowsChange,
428
+ rowKeyGetter
429
+ } = useDataGrid();
430
+ const onChange = (checked, _isShiftClick) => {
431
+ const newCheckedRows = new Set(checkedRows);
432
+ if (checked) {
433
+ newCheckedRows.add(rowKeyGetter(props.row));
434
+ } else {
435
+ newCheckedRows.delete(rowKeyGetter(props.row));
436
+ }
437
+ onCheckedRowsChange && onCheckedRowsChange(newCheckedRows);
438
+ };
439
+ return /* @__PURE__ */ jsx(SelectCellFormatter, {
440
+ value: checkedRows?.has(rowKeyGetter(props.row)) || false,
441
+ isCellSelected: props.isCellSelected,
442
+ onChange,
443
+ "aria-label": "Select"
444
+ });
445
+ }
446
+ const SelectColumnHeaderRenderer = (props) => {
447
+ const {
448
+ rows,
449
+ rowKeyGetter,
450
+ onCheckedRowsChange,
451
+ checkedRows
452
+ } = useDataGrid();
453
+ const onAllRowsCheckedChange = (checked) => {
454
+ if (!onCheckedRowsChange)
455
+ return;
456
+ if (checked) {
457
+ onCheckedRowsChange(new Set(rows.map((r) => rowKeyGetter(r))));
458
+ } else {
459
+ onCheckedRowsChange(/* @__PURE__ */ new Set());
460
+ }
461
+ };
462
+ const allRowsChecked = rows.length === checkedRows?.size;
463
+ return SelectCellFormatter({
464
+ "aria-label": "Select All",
465
+ isCellSelected: props.isCellSelected,
466
+ value: allRowsChecked,
467
+ onChange: onAllRowsCheckedChange
468
+ });
469
+ };
241
470
  const SelectColumn = {
242
471
  key: SELECT_COLUMN_KEY,
243
472
  name: "",
@@ -246,13 +475,8 @@ const SelectColumn = {
246
475
  resizable: false,
247
476
  sortable: false,
248
477
  frozen: true,
249
- type: "number",
250
- headerRenderer: (props) => SelectCellFormatter({
251
- "aria-label": "Select All",
252
- isCellSelected: props.isCellSelected,
253
- value: props.allRowsSelected,
254
- onChange: props.onAllRowsSelectionChange
255
- }),
478
+ type: "boolean",
479
+ headerRenderer: SelectColumnHeaderRenderer,
256
480
  formatter: SelectFormatter,
257
481
  groupFormatter: SelectGroupFormatter
258
482
  };
@@ -268,11 +492,11 @@ function useFocusRef(isSelected) {
268
492
  tabIndex: isSelected ? 0 : -1
269
493
  };
270
494
  }
271
- const initialState$1 = {
495
+ const initialState = {
272
496
  activeFilters: false,
273
497
  setActiveFilters: voidFunction
274
498
  };
275
- const FilterContext = createContext(initialState$1);
499
+ const FilterContext = createContext(initialState);
276
500
  function FilterProvider({
277
501
  children,
278
502
  initialActiveFilters
@@ -280,12 +504,15 @@ function FilterProvider({
280
504
  const [filterOptions, setFilterOptions] = useState({
281
505
  activeFilters: initialActiveFilters
282
506
  });
283
- const onChangeFilter = (columnkey, value) => {
507
+ const onChangeFilter = (column, value) => {
284
508
  const newMap = filterOptions.filters ? new Map(filterOptions.filters) : /* @__PURE__ */ new Map();
285
509
  if (value !== "") {
286
- newMap.set(columnkey, value);
510
+ newMap.set(column.key, {
511
+ value,
512
+ customFilter: column.customFilter
513
+ });
287
514
  } else {
288
- newMap.delete(columnkey);
515
+ newMap.delete(column.key);
289
516
  }
290
517
  setFilterOptions({
291
518
  ...filterOptions,
@@ -362,7 +589,7 @@ function DraggableHeaderRenderer(props) {
362
589
  const handleChange = (e) => {
363
590
  if (activeFilters) {
364
591
  if (onChangeFilter)
365
- onChangeFilter(column.key, e.target.value);
592
+ onChangeFilter(column, e.target.value);
366
593
  }
367
594
  setFilter(e.target.value);
368
595
  };
@@ -430,220 +657,6 @@ const getDragHeaderRenderer = (handleColumnsReorder) => {
430
657
  }
431
658
  return HeaderRenderer2;
432
659
  };
433
- const initialState = {
434
- columnsWidths: /* @__PURE__ */ new Map(),
435
- onChangeColumnsConfig: voidFunction,
436
- onChangeColumnsOrder: voidFunction,
437
- onChangeColumnWidth: voidFunction,
438
- columnsConfig: [{
439
- key: "string",
440
- visible: true,
441
- hidden: false,
442
- index: 0,
443
- frozen: true,
444
- name: "string;",
445
- orginalIndex: 0,
446
- originalVisible: true,
447
- originalFrozen: false
448
- }],
449
- isSkeleton: false,
450
- rowsCount: 0,
451
- setRowsCount: voidFunction,
452
- rowHeights: 36,
453
- currentRowHeight: 36,
454
- currentRowHeaderHeight: 40,
455
- currentRowHeightVariant: "compact",
456
- setRowHeightVariant: voidFunction
457
- };
458
- const BaseContext = createContext(initialState);
459
- const getColumnConfigByKey = (key, storeColumnsConfig) => {
460
- let indexFind = -1;
461
- return [storeColumnsConfig.find((column, index) => {
462
- if (column.key === key) {
463
- indexFind = index;
464
- }
465
- return column.key === key;
466
- }), indexFind];
467
- };
468
- function getColumnsConfig(id, columns, remoteConfig = void 0) {
469
- let columnsConfig;
470
- if (remoteConfig) {
471
- columnsConfig = remoteConfig.columnsConfig;
472
- } else {
473
- try {
474
- const item = window.localStorage.getItem(`${id}_columns_config`);
475
- columnsConfig = item !== null ? JSON.parse(item) : [];
476
- } catch (e) {
477
- columnsConfig = [];
478
- }
479
- }
480
- return columns.map((column, index) => {
481
- const [columnConfig = {
482
- ...column
483
- }, columnConfigIndex] = getColumnConfigByKey(column.key, columnsConfig);
484
- return {
485
- key: column.key,
486
- name: column.name,
487
- hidden: column.hidden === void 0 ? false : column.hidden,
488
- index: columnConfigIndex > -1 ? columnConfigIndex : index,
489
- visible: columnConfig.visible === void 0 ? true : columnConfig.visible,
490
- frozen: columnConfig.frozen === void 0 ? false : columnConfig.frozen,
491
- orginalIndex: index,
492
- originalVisible: column.visible === void 0 ? true : column.visible,
493
- originalFrozen: column.frozen === void 0 ? false : column.frozen
494
- };
495
- }).sort((a, b) => a.index - b.index);
496
- }
497
- function getColumnsWidth(id, columns, remoteConfig) {
498
- const newMap = /* @__PURE__ */ new Map();
499
- let storeColumnsWidth;
500
- try {
501
- const item = window.localStorage.getItem(`${id}_columns_width`);
502
- storeColumnsWidth = item !== null ? new Map(JSON.parse(item)) : /* @__PURE__ */ new Map();
503
- } catch (e) {
504
- storeColumnsWidth = /* @__PURE__ */ new Map();
505
- }
506
- for (let i = 0; i < columns.length; i++) {
507
- let width;
508
- if (remoteConfig) {
509
- try {
510
- width = remoteConfig.columnsWidths.get(columns[i].key);
511
- } catch (error) {
512
- }
513
- }
514
- if (width === void 0) {
515
- const storeWidth = storeColumnsWidth.get(columns[i].key);
516
- if (typeof storeWidth === "number") {
517
- width = storeWidth;
518
- }
519
- }
520
- if (width !== void 0) {
521
- newMap.set(columns[i].key, width);
522
- }
523
- }
524
- return newMap;
525
- }
526
- function saveColumnsWidth(id, storeColumnsWidth) {
527
- localStorage.setItem(`${id}_columns_width`, JSON.stringify([...storeColumnsWidth]));
528
- }
529
- function saveColumnsConfig(id, columnsConfig) {
530
- localStorage.setItem(`${id}_columns_config`, JSON.stringify(columnsConfig));
531
- }
532
- function getIndexRowHeightVariant(variant) {
533
- if (variant === "compact") {
534
- return 0;
535
- }
536
- if (variant === "standard") {
537
- return 1;
538
- }
539
- return 2;
540
- }
541
- function BaseProvider(props) {
542
- const {
543
- id,
544
- children,
545
- isSkeleton,
546
- columns,
547
- remoteConfig,
548
- rowsCount,
549
- rowActionsGetter,
550
- rowHeights,
551
- rowHeaderHeights,
552
- initialRowHeightVariant
553
- } = props;
554
- const [columnsWidths, setColumnsWidths] = useState(/* @__PURE__ */ new Map());
555
- const [columnsConfig, setColumnsConfigOptions] = useState(() => []);
556
- const [rowsFilterCount, setRowFilterCount] = useState(rowsCount);
557
- const [currentRowHeightVariant, setCurrentRowHeightVariant] = useState(() => {
558
- if (typeof rowHeights !== typeof rowHeaderHeights) {
559
- throw new Error("Must be same type rowheights and rowHeaderTypes");
560
- }
561
- if (typeof rowHeights === "number" && typeof rowHeaderHeights === "number") {
562
- return {
563
- rowHVariant: "compact",
564
- rowHeight: rowHeights,
565
- rowHeaderHeight: rowHeaderHeights
566
- };
567
- }
568
- if (typeof rowHeights !== "number" && rowHeights.length !== 3) {
569
- throw new Error("Must be 3 heights");
570
- }
571
- if (typeof rowHeaderHeights !== "number" && rowHeaderHeights.length !== 3) {
572
- throw new Error("Must be 3 HeaderHeights");
573
- }
574
- return {
575
- rowHVariant: initialRowHeightVariant,
576
- rowHeight: typeof rowHeights !== "number" ? rowHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeights,
577
- rowHeaderHeight: typeof rowHeaderHeights !== "number" ? rowHeaderHeights[getIndexRowHeightVariant(initialRowHeightVariant)] : rowHeaderHeights
578
- };
579
- });
580
- const finalRowHeights = useMemo(() => rowHeights, [rowHeights]);
581
- let timerSaveColumns;
582
- useEffect(() => {
583
- }, [columnsConfig]);
584
- useEffect(() => {
585
- setColumnsWidths(getColumnsWidth(id, columns, remoteConfig));
586
- setColumnsConfigOptions(getColumnsConfig(id, columns, remoteConfig));
587
- }, [columns, id, remoteConfig]);
588
- const onChangeColumnsConfig = useCallback((newColumnsConfig) => {
589
- saveColumnsConfig(id, newColumnsConfig);
590
- setColumnsConfigOptions(newColumnsConfig);
591
- }, [setColumnsConfigOptions, id]);
592
- const onChangeColumnsOrder = useCallback((sourceKey, targetKey) => {
593
- if (sourceKey === targetKey)
594
- return;
595
- const sourceColumnIndex = columnsConfig.findIndex((c) => c.key === sourceKey);
596
- const targetColumnIndex = columnsConfig.findIndex((c) => c.key === targetKey);
597
- const reorderedColumnsConfig = [...columnsConfig];
598
- reorderedColumnsConfig.splice(targetColumnIndex, 0, reorderedColumnsConfig.splice(sourceColumnIndex, 1)[0]);
599
- onChangeColumnsConfig(reorderedColumnsConfig);
600
- }, [columnsConfig, onChangeColumnsConfig]);
601
- const onChangeColumnWidth = (columnKey, width) => {
602
- columnsWidths.set(columnKey, Math.round(width));
603
- if (timerSaveColumns) {
604
- clearTimeout(timerSaveColumns);
605
- }
606
- timerSaveColumns = setTimeout(() => {
607
- saveColumnsWidth(id, columnsWidths);
608
- }, 500);
609
- };
610
- useEffect(() => {
611
- setColumnsConfigOptions(getColumnsConfig(id, columns));
612
- }, [columns]);
613
- const setRowFilterCountInternal = (newRowsCount) => {
614
- setRowFilterCount(newRowsCount);
615
- };
616
- const setCurrentRowHeightInternal = useCallback((newVariant) => {
617
- if (typeof rowHeights === "number" || typeof rowHeaderHeights === "number") {
618
- throw new Error("Only use setCurrentRowHeight with vector rowHeights");
619
- }
620
- setCurrentRowHeightVariant({
621
- rowHVariant: newVariant,
622
- rowHeight: rowHeights[getIndexRowHeightVariant(newVariant)],
623
- rowHeaderHeight: rowHeaderHeights[getIndexRowHeightVariant(newVariant)]
624
- });
625
- }, [setCurrentRowHeightVariant, rowHeights, rowHeaderHeights]);
626
- return /* @__PURE__ */ jsx(BaseContext.Provider, {
627
- value: {
628
- isSkeleton,
629
- columnsConfig,
630
- columnsWidths,
631
- onChangeColumnsConfig,
632
- onChangeColumnsOrder,
633
- onChangeColumnWidth,
634
- rowsCount: rowsFilterCount,
635
- setRowsCount: setRowFilterCountInternal,
636
- rowActionsGetter,
637
- currentRowHeightVariant: currentRowHeightVariant.rowHVariant,
638
- currentRowHeight: currentRowHeightVariant.rowHeight,
639
- currentRowHeaderHeight: currentRowHeightVariant.rowHeaderHeight,
640
- rowHeights: finalRowHeights,
641
- setRowHeightVariant: setCurrentRowHeightInternal
642
- },
643
- children
644
- });
645
- }
646
- const useBase = () => useContext(BaseContext);
647
660
  const WrapperSkeleton = styled("div")(() => ({
648
661
  display: "flex",
649
662
  width: "100%",
@@ -685,7 +698,7 @@ function getComparator(columns, sortColumn) {
685
698
  }
686
699
  }
687
700
  const getColumIndex = (key, columnsConfig) => columnsConfig.findIndex((columnConfig) => columnConfig.key === key);
688
- const getInOrderColumns = (columns, isMultipleRows, columnsConfig, columnsWidths, rowActionsGetter) => {
701
+ const getInOrderColumns = (columns, hasCheckedRows, columnsConfig, columnsWidths, rowActionsGetter) => {
689
702
  let filteredSortedColumns = columns.filter((column) => {
690
703
  const columnConfigIndex = getColumIndex(column.key, columnsConfig);
691
704
  const visible = columnConfigIndex > -1 ? columnsConfig[columnConfigIndex].visible : true;
@@ -706,7 +719,7 @@ const getInOrderColumns = (columns, isMultipleRows, columnsConfig, columnsWidths
706
719
  if (rowActionsGetter) {
707
720
  filteredSortedColumns = [ActionsColumn, ...filteredSortedColumns];
708
721
  }
709
- if (isMultipleRows) {
722
+ if (hasCheckedRows) {
710
723
  filteredSortedColumns = [SelectColumn, ...filteredSortedColumns];
711
724
  }
712
725
  return filteredSortedColumns;
@@ -724,12 +737,18 @@ const getAligByType = (columnType) => {
724
737
  }
725
738
  return "left";
726
739
  };
727
- const useSortColumnsRows = (sourceColumns, sourceRows, isMultipleRows) => {
728
- const { columnsConfig, columnsWidths, onChangeColumnsOrder, rowActionsGetter, isSkeleton } = useBase();
729
- const [columns, setColumns] = useState(
730
- () => []
731
- );
740
+ const useSortColumnsRows = (sourceColumns, sourceRows) => {
741
+ const {
742
+ columnsConfig,
743
+ columnsWidths,
744
+ onChangeColumnsOrder,
745
+ rowActionsGetter,
746
+ checkedRows,
747
+ onCheckedRowsChange
748
+ } = useDataGrid();
749
+ const [columns, setColumns] = useState(() => []);
732
750
  const [sortColumns, setSortColumns] = useState([]);
751
+ const isSkeleton = useModuleSkeleton();
733
752
  const { activeFilters, filters } = useFilters();
734
753
  const findKeyInColumns = (key, cols) => {
735
754
  const index = cols.findIndex((column) => key === column.key && column.hidden === false);
@@ -739,7 +758,7 @@ const useSortColumnsRows = (sourceColumns, sourceRows, isMultipleRows) => {
739
758
  setColumns(
740
759
  getInOrderColumns(
741
760
  sourceColumns,
742
- isMultipleRows,
761
+ !!checkedRows && !!onCheckedRowsChange,
743
762
  columnsConfig,
744
763
  columnsWidths,
745
764
  rowActionsGetter
@@ -783,15 +802,19 @@ const useSortColumnsRows = (sourceColumns, sourceRows, isMultipleRows) => {
783
802
  let valReturn = true;
784
803
  for (let i = 0; i < filters.size; i++) {
785
804
  const entry = iterator.next().value;
786
- const key = entry[0];
787
- const value = `${entry[1]}`;
788
- let valRow;
805
+ const columnKey = entry[0];
806
+ const columnFilter = entry[1];
807
+ let valCell;
789
808
  try {
790
- valRow = `${r[key]}`;
809
+ if (columnFilter.customFilter) {
810
+ valReturn = valReturn && columnFilter.customFilter(r, columnFilter.value);
811
+ } else {
812
+ valCell = getPropertyByString(r, columnKey) || "";
813
+ valReturn = valReturn && valCell.includes(columnFilter.value);
814
+ }
791
815
  } catch (error) {
792
816
  continue;
793
817
  }
794
- valReturn = valReturn && valRow.includes(value);
795
818
  if (!valReturn)
796
819
  break;
797
820
  }
@@ -816,18 +839,20 @@ const useSortColumnsRows = (sourceColumns, sourceRows, isMultipleRows) => {
816
839
  };
817
840
  function Table(props) {
818
841
  const {
819
- isMultipleSelect = false,
820
842
  columns,
821
843
  rows,
822
844
  withActions,
823
- onRowsChange
845
+ onRowsChange,
846
+ rowKeyGetter,
847
+ selectedRows,
848
+ onSelectedRowsChange
824
849
  } = props;
825
850
  const {
826
851
  finalColumns,
827
852
  sortColumns,
828
853
  setSortColumns,
829
854
  finalRows
830
- } = useSortColumnsRows(columns, rows, isMultipleSelect);
855
+ } = useSortColumnsRows(columns, rows);
831
856
  const {
832
857
  activeFilters
833
858
  } = useFilters();
@@ -836,43 +861,17 @@ function Table(props) {
836
861
  setRowsCount,
837
862
  currentRowHeight,
838
863
  currentRowHeaderHeight
839
- } = useBase();
840
- const [selectedRows, setSelectedRows] = useState(() => new Set(props.selectedRows));
841
- useEffect(() => {
842
- setSelectedRows(new Set(props.selectedRows));
843
- }, [props.selectedRows]);
864
+ } = useDataGrid();
844
865
  const ref_data_grid = useRef(null);
845
- const updateExternal = (mapRowsSelected) => {
846
- if (props.onRowsSelectedChange) {
847
- const rawRowsSelected = [];
848
- if (mapRowsSelected.size > 0) {
849
- const iterator = mapRowsSelected.entries();
850
- for (let i = 0; i < mapRowsSelected.size; i++) {
851
- const entry = iterator.next().value;
852
- const key = entry[1];
853
- const row = finalRows.find((frow) => props.rowKeyGetter(frow) === key);
854
- if (row) {
855
- rawRowsSelected.push(row);
856
- }
857
- }
858
- }
859
- props.onRowsSelectedChange(mapRowsSelected, rawRowsSelected);
860
- }
861
- };
862
- const onInternalSelectedRowsChange = (mapRowsSelected) => {
863
- setSelectedRows(mapRowsSelected);
864
- updateExternal(mapRowsSelected);
865
- };
866
866
  const onRowClick = (row) => {
867
- if (!isMultipleSelect) {
867
+ if (selectedRows && onSelectedRowsChange) {
868
868
  if (selectedRows.entries().next().value) {
869
- if (selectedRows.entries().next().value[1] === props.rowKeyGetter(row)) {
869
+ if (selectedRows.entries().next().value[1] === rowKeyGetter(row)) {
870
870
  return;
871
871
  }
872
872
  }
873
- const mySet = /* @__PURE__ */ new Set([props.rowKeyGetter(row)]);
874
- setSelectedRows(mySet);
875
- updateExternal(mySet);
873
+ const mySet = /* @__PURE__ */ new Set([rowKeyGetter(row)]);
874
+ onSelectedRowsChange(mySet);
876
875
  }
877
876
  };
878
877
  useEffect(() => {
@@ -914,10 +913,10 @@ function Table(props) {
914
913
  rows: finalRows,
915
914
  onRowsChange,
916
915
  selectedRows,
917
- onSelectedRowsChange: onInternalSelectedRowsChange,
916
+ onSelectedRowsChange,
918
917
  onRowClick,
919
918
  rowHeight: currentRowHeight,
920
- rowKeyGetter: props.rowKeyGetter,
919
+ rowKeyGetter,
921
920
  cellNavigationMode: "LOOP_OVER_ROW",
922
921
  components: {
923
922
  checkboxFormatter: CheckboxFormatter
@@ -933,42 +932,49 @@ function Table(props) {
933
932
  }
934
933
  function DataGrid(props) {
935
934
  const {
935
+ id,
936
936
  withActions = true,
937
937
  rows,
938
938
  columns,
939
939
  actionsProps,
940
+ selectedRows,
941
+ onSelectedRowsChange,
942
+ rowKeyGetter,
940
943
  rowActionsGetter,
941
944
  onRowsChange,
942
- rowHeaderHeights = [44, 63, 75],
943
- rowHeights = [36, 52, 67],
944
- initialRowHeightVariant = "compact"
945
+ rowHeaderHeights,
946
+ rowHeights,
947
+ initialRowHeightVariant,
948
+ checkedRows,
949
+ onCheckedRowsChange
945
950
  } = props;
946
- const isSkeleton = useModuleSkeleton();
947
951
  return /* @__PURE__ */ jsx(WrapperGrid, {
948
952
  id: `WrapperGrid_${props.id}`,
949
- children: /* @__PURE__ */ jsx(BaseProvider, {
953
+ children: /* @__PURE__ */ jsx(DataGridProvider, {
950
954
  id: props.id,
951
- isSkeleton,
952
955
  columns: props.columns,
953
956
  rowHeights,
954
957
  rowHeaderHeights,
955
958
  initialRowHeightVariant,
956
959
  rowsCount: rows.length,
957
960
  rowActionsGetter,
961
+ checkedRows,
962
+ onCheckedRowsChange,
963
+ rowKeyGetter,
964
+ rows,
958
965
  children: /* @__PURE__ */ jsxs(FilterProvider, {
959
966
  initialActiveFilters: false,
960
967
  children: [withActions && actionsProps && /* @__PURE__ */ jsx(Actions, {
961
968
  ...actionsProps
962
969
  }), /* @__PURE__ */ jsx(Table, {
963
- id: props.id,
970
+ id,
964
971
  withActions,
965
972
  columns,
966
973
  rows,
967
- isMultipleSelect: props.isMultipleSelect,
968
- selectedRows: props.selectedRows,
969
- rowKeyGetter: props.rowKeyGetter,
970
- onRowsChange,
971
- onRowsSelectedChange: props.onRowsSelectedChange
974
+ selectedRows,
975
+ onSelectedRowsChange,
976
+ rowKeyGetter,
977
+ onRowsChange
972
978
  })]
973
979
  })
974
980
  })
@@ -1064,12 +1070,30 @@ function NumberEditor({
1064
1070
  onBlur: () => onClose(true)
1065
1071
  });
1066
1072
  }
1073
+ const getDataGridRowsFromSet = (set, rows, rowKeyGetter) => {
1074
+ const rowsFinded = [];
1075
+ if (set) {
1076
+ if (set.size > 0) {
1077
+ const iterator = set.entries();
1078
+ for (let i = 0; i < set.size; i++) {
1079
+ const entry = iterator.next().value;
1080
+ const key = entry[1];
1081
+ const row = rows.find((frow) => rowKeyGetter(frow) === key);
1082
+ if (row) {
1083
+ rowsFinded.push(row);
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+ return rowsFinded;
1089
+ };
1067
1090
  export {
1068
1091
  DataGrid as D,
1069
1092
  NumberEditor as N,
1070
1093
  OriginalDataGridWrapperStyled as O,
1071
1094
  TextEditor as T,
1072
1095
  useFilters as a,
1096
+ getDataGridRowsFromSet as b,
1073
1097
  getDataGridComponentsDictionary as g,
1074
- useBase as u
1098
+ useDataGrid as u
1075
1099
  };