@join-x5/react-data-grid 1.3.1-alpha-0 → 1.4.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 (49) hide show
  1. package/dist/DataGrid.es.js +81 -59
  2. package/dist/DataGrid.es.js.map +1 -1
  3. package/dist/Table/index.es.js +34 -34
  4. package/dist/Table/index.es.js.map +1 -1
  5. package/dist/TableBody/DataGridTableBody.d.ts +12 -0
  6. package/dist/TableBody/DataGridTableBody.es.js +41 -0
  7. package/dist/TableBody/DataGridTableBody.es.js.map +1 -0
  8. package/dist/TableBody/DataGridTableBodyVirtual.d.ts +2 -0
  9. package/dist/TableBody/DataGridTableBodyVirtual.es.js +18 -0
  10. package/dist/TableBody/DataGridTableBodyVirtual.es.js.map +1 -0
  11. package/dist/TableBody/hook.d.ts +839 -0
  12. package/dist/TableBody/hook.es.js +49 -0
  13. package/dist/TableBody/hook.es.js.map +1 -0
  14. package/dist/TableBody/index.d.ts +3 -11
  15. package/dist/TableBody/types.d.ts +2 -0
  16. package/dist/TableCell/hook.es.js +8 -9
  17. package/dist/TableCell/hook.es.js.map +1 -1
  18. package/dist/TableCell/index.es.js +120 -133
  19. package/dist/TableCell/index.es.js.map +1 -1
  20. package/dist/TableHead/index.d.ts +4 -2
  21. package/dist/TableHead/index.es.js +16 -13
  22. package/dist/TableHead/index.es.js.map +1 -1
  23. package/dist/TableHeadCell/index.es.js +71 -74
  24. package/dist/TableHeadCell/index.es.js.map +1 -1
  25. package/dist/TableInputCell/date.es.js +29 -32
  26. package/dist/TableInputCell/date.es.js.map +1 -1
  27. package/dist/TableInputCell/dropdown.es.js +29 -32
  28. package/dist/TableInputCell/dropdown.es.js.map +1 -1
  29. package/dist/TableInputCell/hook.d.ts +30 -30
  30. package/dist/TableInputCell/hook.es.js +30 -33
  31. package/dist/TableInputCell/hook.es.js.map +1 -1
  32. package/dist/TableInputCell/text.es.js +39 -41
  33. package/dist/TableInputCell/text.es.js.map +1 -1
  34. package/dist/TableInputCell/textarea.es.js +38 -40
  35. package/dist/TableInputCell/textarea.es.js.map +1 -1
  36. package/dist/TableRow/index.d.ts +2 -3
  37. package/dist/TableRow/index.es.js +16 -17
  38. package/dist/TableRow/index.es.js.map +1 -1
  39. package/dist/hook.es.js +14 -17
  40. package/dist/hook.es.js.map +1 -1
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.es.js +61 -60
  44. package/dist/index.es.js.map +1 -1
  45. package/dist/types.d.ts +36 -2
  46. package/package.json +13 -12
  47. package/dist/TableBody/index.es.js +0 -26
  48. package/dist/TableBody/index.es.js.map +0 -1
  49. package/dist/TableRow/types.d.ts +0 -2
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { useContext as x } from "react";
3
+ import { useVirtualizer as b } from "@tanstack/react-virtual";
4
+ import { DataGridContext as h } from "../DataGridContext.es.js";
5
+ import { getDataGridTableRow as y } from "../TableRow/index.es.js";
6
+ const v = (c) => {
7
+ const {
8
+ table: l,
9
+ components: u,
10
+ rowProps: e,
11
+ wrapperRef: r,
12
+ virtualize: n,
13
+ ...m
14
+ } = c, p = x(h), s = l.getRowModel().rows, o = b({
15
+ count: s.length,
16
+ estimateSize: () => 40,
17
+ getScrollElement: () => r.current,
18
+ measureElement: (t) => t.getBoundingClientRect().height,
19
+ overscan: 5,
20
+ ...typeof n == "object" ? n : void 0
21
+ }), d = u?.row ?? y, f = (t) => o.measureElement(t), g = o.getVirtualItems().map((t) => {
22
+ const i = s[t.index], a = {
23
+ ref: f,
24
+ "data-index": t.index,
25
+ style: {
26
+ position: "absolute",
27
+ left: 0,
28
+ top: 0,
29
+ width: "100%",
30
+ transform: `translateY(${t.start}px)`
31
+ }
32
+ };
33
+ return e && Object.assign(a, typeof e == "function" ? e(i) : e), d(i, a);
34
+ }), w = {
35
+ "data-qa": `${p.qa}-body`,
36
+ style: {
37
+ height: o.getTotalSize(),
38
+ ...m.style
39
+ }
40
+ };
41
+ return r.current || setTimeout(o.measure), {
42
+ containerProps: w,
43
+ child: g
44
+ };
45
+ };
46
+ export {
47
+ v as useVirtualTableBody
48
+ };
49
+ //# sourceMappingURL=hook.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.es.js","sources":["../../src/TableBody/hook.ts"],"sourcesContent":["'use client';\n\nimport {useContext} from 'react';\nimport {useVirtualizer} from '@tanstack/react-virtual';\n\nimport {DataGridContext} from 'DataGridContext';\nimport {getDataGridTableRow} from 'TableRow';\n\nimport type {Table} from '@tanstack/react-table';\nimport type {VirtualItem} from '@tanstack/react-virtual';\nimport type {TableRowProps} from 'TableRow';\nimport type {DataGridProps} from 'types';\nimport type {TableBodyProps} from './types';\n\nexport type DataGridTableBodyVirtualProps = {\n table: Table<unknown>;\n} & Pick<DataGridProps, 'components' | 'rowProps'> &\n Required<Pick<DataGridProps, 'virtualize' | 'wrapperRef'>> &\n TableBodyProps;\n\nexport const useVirtualTableBody = (props: DataGridTableBodyVirtualProps) => {\n const {table, components, rowProps, wrapperRef, virtualize, ...rest} = props;\n\n const context = useContext(DataGridContext);\n const rows = table.getRowModel().rows;\n\n const rowVirtualizer = useVirtualizer<HTMLDivElement, HTMLTableRowElement>({\n count: rows.length,\n estimateSize: () => 40,\n getScrollElement: () => wrapperRef.current,\n measureElement: el => el.getBoundingClientRect().height,\n overscan: 5,\n\n ...(typeof virtualize === 'object' ? virtualize : undefined),\n });\n\n const iterator = components?.row ?? getDataGridTableRow;\n const rowRef = (node: HTMLTableRowElement) => rowVirtualizer.measureElement(node);\n\n const child = rowVirtualizer.getVirtualItems().map((item: VirtualItem) => {\n const row = rows[item.index];\n\n const itemProps = {\n ref: rowRef,\n\n 'data-index': item.index,\n\n style: {\n position: 'absolute',\n left: 0,\n top: 0,\n width: '100%',\n transform: `translateY(${item.start}px)`,\n },\n } as TableRowProps;\n\n if (rowProps) {\n Object.assign(itemProps, typeof rowProps === 'function' ? rowProps(row) : rowProps);\n }\n\n return iterator(row, itemProps);\n });\n\n const containerProps = {\n 'data-qa': `${context.qa}-body`,\n\n style: {\n height: rowVirtualizer.getTotalSize(),\n\n ...rest.style,\n },\n };\n\n if (!wrapperRef.current) {\n setTimeout(rowVirtualizer.measure);\n }\n\n return {containerProps, child};\n};\n"],"names":["table","components","rowProps","wrapperRef","virtualize","rest","length","current","height","undefined","rowRef","index","getTotalSize","style","containerProps","child"],"mappings":";;;;;AAoBO;AACL;AAAM;AAACA;AAAOC;AAAYC;AAAUC;AAAYC;AAAeC;AAKY;AAC7DC;AACQ;AACeC;AACcC;AACvC;AAEwCC;AAOlD;AAEkB;AACXC;AAEcC;AAEZ;AACK;AACJ;AACD;AACE;AAC4B;AAAA;AAIvC;AAI8B;AAGT;AACG;AAEjB;AACkBC;AAEfC;AAAAA;AAIZ;AAIO;AAACC;AAAgBC;AAC1B;;;;"}
@@ -1,11 +1,3 @@
1
- import { Table } from '@tanstack/react-table';
2
- import { DataGridProps } from 'types';
3
- export declare const TableBody: import('@emotion/styled').StyledComponent<{
4
- theme?: import('@emotion/react').Theme;
5
- as?: React.ElementType;
6
- }, import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
7
- type DataGridTableBodyProps = {
8
- table: Table<unknown>;
9
- } & Pick<DataGridProps, 'components'>;
10
- export declare const getDataGridTableBody: (table: DataGridTableBodyProps["table"], components: DataGridProps["components"]) => import("@emotion/react/jsx-runtime").JSX.Element;
11
- export {};
1
+ export * from './DataGridTableBody';
2
+ export { getDataGridTableBodyVirtual } from './DataGridTableBodyVirtual';
3
+ export * from './types';
@@ -0,0 +1,2 @@
1
+ import { HTMLAttributes } from 'react';
2
+ export type TableBodyProps = HTMLAttributes<HTMLTableSectionElement>;
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { useContext as o } from "react";
3
3
  import { ColumnArea as r } from "@join-x5/react-data-grid-settings";
4
- import { DataGridContext as d } from "../DataGridContext.es.js";
5
- const c = (t, e) => {
4
+ import { DataGridContext as l } from "../DataGridContext.es.js";
5
+ const a = (t, e) => {
6
6
  const i = t.getIsPinned();
7
7
  e.columnArea = (() => {
8
8
  switch (t.getIsPinned()) {
@@ -12,10 +12,9 @@ const c = (t, e) => {
12
12
  return r.FixedRight;
13
13
  }
14
14
  return r.Default;
15
- })(), i && (e.style ?? (e.style = {}), i === "left" ? (e.style.left = `${t.getStart("left")}px`, e.isLastFixed = t.getIsLastColumn("left")) : (e.style.right = `${t.getAfter("right")}px`, e.isLastFixed = t.getIsFirstColumn("right")));
16
- }, h = (t) => {
17
- var a, l;
18
- const e = o(d), i = typeof e.isMultiline == "boolean" ? e.isMultiline : (a = e.isMultiline) == null ? void 0 : a.call(e, t), n = `calc(var(--header-${(l = t.column) == null ? void 0 : l.id}-size) * 1px)`, s = {
15
+ })(), i && (e.style ??= {}, i === "left" ? (e.style.left = `${t.getStart("left")}px`, e.isLastFixed = t.getIsLastColumn("left")) : (e.style.right = `${t.getAfter("right")}px`, e.isLastFixed = t.getIsFirstColumn("right")));
16
+ }, u = (t) => {
17
+ const e = o(l), i = typeof e.isMultiline == "boolean" ? e.isMultiline : e.isMultiline?.(t), n = `calc(var(--header-${t.column?.id}-size) * 1px)`, s = {
19
18
  isMultiline: i,
20
19
  qa: e.qa,
21
20
  isBordered: e.isBordered,
@@ -33,10 +32,10 @@ const c = (t, e) => {
33
32
  maxWidth: n
34
33
  }
35
34
  };
36
- return c(t.column, s), e.cellProps && Object.assign(s, e.cellProps instanceof Function ? e.cellProps(t) : e.cellProps), s;
35
+ return a(t.column, s), e.cellProps && Object.assign(s, typeof e.cellProps == "function" ? e.cellProps(t) : e.cellProps), s;
37
36
  };
38
37
  export {
39
- c as areaProps,
40
- h as useDataGridTableCell
38
+ a as areaProps,
39
+ u as useDataGridTableCell
41
40
  };
42
41
  //# sourceMappingURL=hook.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hook.es.js","sources":["../../src/TableCell/hook.ts"],"sourcesContent":["'use client';\n\nimport {useContext} from 'react';\n\nimport {ColumnArea} from '@join-x5/react-data-grid-settings';\n\nimport {DataGridContext} from 'DataGridContext';\n\nimport type {Column, Cell as ReactTableCell} from '@tanstack/react-table';\nimport type {TableCellProps} from './types';\n\nexport const areaProps = (column: Column<unknown>, props: TableCellProps): void => {\n const isPinned = column.getIsPinned();\n\n props.columnArea = (() => {\n switch (column.getIsPinned()) {\n case 'left':\n return ColumnArea.FixedLeft;\n case 'right':\n return ColumnArea.FixedRight;\n }\n\n return ColumnArea.Default;\n })();\n\n if (!isPinned) {\n return;\n }\n\n props.style ??= {};\n\n if (isPinned === 'left') {\n props.style.left = `${column.getStart('left')}px`;\n props.isLastFixed = column.getIsLastColumn('left');\n } else {\n props.style.right = `${column.getAfter('right')}px`;\n props.isLastFixed = column.getIsFirstColumn('right');\n }\n};\n\nexport const useDataGridTableCell = (cell: ReactTableCell<unknown, unknown>) => {\n const context = useContext(DataGridContext);\n\n const isMultiline = typeof context.isMultiline === 'boolean' ? context.isMultiline : context.isMultiline?.(cell);\n const width = `calc(var(--header-${cell.column?.id}-size) * 1px)`;\n\n const resultProps: TableCellProps = {\n isMultiline,\n\n qa: context.qa,\n isBordered: context.isBordered,\n isShadowed: context.isShadowed,\n size: context.size,\n verticalAlign: context.verticalAlign,\n writingMode: context.writingMode,\n userSelect: context.userSelect,\n wordBreak: context.wordBreak,\n whiteSpace: context.whiteSpace,\n\n isRowSelected: cell.row.getIsSelected(),\n isResizing: cell.column.getIsResizing(),\n\n style: {\n width,\n maxWidth: width,\n },\n };\n\n areaProps(cell.column, resultProps);\n\n if (context.cellProps) {\n Object.assign(resultProps, context.cellProps instanceof Function ? context.cellProps(cell) : context.cellProps);\n }\n\n return resultProps;\n};\n"],"names":["FixedLeft","FixedRight","Default","isMultiline","qa","isBordered","isShadowed","size","verticalAlign","writingMode","userSelect","wordBreak","whiteSpace","getIsSelected","getIsResizing","width","areaProps"],"mappings":";;;;AAWO;AACL;AAaA;AAVE;AAA2B;AAEvB;AAAkBA;AAElB;AAAkBC;AAGtB;AAAkBC;AAgBtB;;AAGE;AAKoC;AAClCC;AAEYC;AACQC;AACAC;AACNC;AACSC;AACFC;AACDC;AACDC;AACCC;AAEIC;AACAC;AAEjB;AACLC;AACUA;AAAAA;AAIdC;AAOF;;;;;"}
1
+ {"version":3,"file":"hook.es.js","sources":["../../src/TableCell/hook.ts"],"sourcesContent":["'use client';\n\nimport {useContext} from 'react';\n\nimport {ColumnArea} from '@join-x5/react-data-grid-settings';\n\nimport {DataGridContext} from 'DataGridContext';\n\nimport type {Column, Cell as ReactTableCell} from '@tanstack/react-table';\nimport type {TableCellProps} from './types';\n\nexport const areaProps = (column: Column<unknown>, props: TableCellProps): void => {\n const isPinned = column.getIsPinned();\n\n props.columnArea = (() => {\n switch (column.getIsPinned()) {\n case 'left':\n return ColumnArea.FixedLeft;\n case 'right':\n return ColumnArea.FixedRight;\n }\n\n return ColumnArea.Default;\n })();\n\n if (!isPinned) {\n return;\n }\n\n props.style ??= {};\n\n if (isPinned === 'left') {\n props.style.left = `${column.getStart('left')}px`;\n props.isLastFixed = column.getIsLastColumn('left');\n } else {\n props.style.right = `${column.getAfter('right')}px`;\n props.isLastFixed = column.getIsFirstColumn('right');\n }\n};\n\nexport const useDataGridTableCell = (cell: ReactTableCell<unknown, unknown>) => {\n const context = useContext(DataGridContext);\n\n const isMultiline = typeof context.isMultiline === 'boolean' ? context.isMultiline : context.isMultiline?.(cell);\n const width = `calc(var(--header-${cell.column?.id}-size) * 1px)`;\n\n const resultProps: TableCellProps = {\n isMultiline,\n\n qa: context.qa,\n isBordered: context.isBordered,\n isShadowed: context.isShadowed,\n size: context.size,\n verticalAlign: context.verticalAlign,\n writingMode: context.writingMode,\n userSelect: context.userSelect,\n wordBreak: context.wordBreak,\n whiteSpace: context.whiteSpace,\n\n isRowSelected: cell.row.getIsSelected(),\n isResizing: cell.column.getIsResizing(),\n\n style: {\n width,\n maxWidth: width,\n },\n };\n\n areaProps(cell.column, resultProps);\n\n if (context.cellProps) {\n Object.assign(resultProps, typeof context.cellProps === 'function' ? context.cellProps(cell) : context.cellProps);\n }\n\n return resultProps;\n};\n"],"names":["FixedLeft","FixedRight","Default","isMultiline","qa","isBordered","isShadowed","size","verticalAlign","writingMode","userSelect","wordBreak","whiteSpace","getIsSelected","getIsResizing","width","areaProps"],"mappings":";;;;AAWO;AACL;AAaA;AAVE;AAA2B;AAEvB;AAAkBA;AAElB;AAAkBC;AAGtB;AAAkBC;AAgBtB;AAGE;AAKoC;AAClCC;AAEYC;AACQC;AACAC;AACNC;AACSC;AACFC;AACDC;AACDC;AACCC;AAEIC;AACAC;AAEjB;AACLC;AACUA;AAAAA;AAIdC;AAOF;;;;;"}