@dxos/react-ui-table 0.4.10-main.35cfb0c → 0.4.10-main.36e0428
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/lib/browser/index.mjs +646 -397
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/{ColumnMenu.d.ts → ColumnMenu/ColumnMenu.d.ts} +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +1 -0
- package/dist/types/src/components/{ColumnMenu.stories.d.ts → ColumnMenu/ColumnMenu.stories.d.ts} +6 -2
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -0
- package/dist/types/src/components/{ColumnSettingsForm.d.ts → ColumnMenu/ColumnSettingsForm.d.ts} +5 -4
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +1 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts +3 -0
- package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts +17 -4
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +32 -1
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableBody.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableRootContext.d.ts +17 -0
- package/dist/types/src/components/Table/TableRootContext.d.ts.map +1 -0
- package/dist/types/src/components/Table/index.d.ts +1 -0
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/components/Table/props.d.ts +2 -3
- package/dist/types/src/components/Table/props.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useColumnSizing.d.ts +12 -0
- package/dist/types/src/hooks/useColumnSizing.d.ts.map +1 -0
- package/dist/types/src/hooks/useColumnSorting.d.ts.map +1 -0
- package/dist/types/src/hooks/usePinLastRow.d.ts +3 -0
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +1 -0
- package/dist/types/src/hooks/useRowSelection.d.ts +7 -0
- package/dist/types/src/hooks/useRowSelection.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +1 -0
- package/dist/types/src/schema/index.d.ts +3 -0
- package/dist/types/src/schema/index.d.ts.map +1 -0
- package/dist/types/src/{components/schema → schema}/schema.d.ts +1 -1
- package/dist/types/src/schema/schema.d.ts.map +1 -0
- package/dist/types/src/schema/schema.test.d.ts.map +1 -0
- package/dist/types/src/{components/schema → schema}/schemaToColumns.d.ts +1 -1
- package/dist/types/src/schema/schemaToColumns.d.ts.map +1 -0
- package/dist/types/src/{schema.d.ts → schema/types.d.ts} +1 -1
- package/dist/types/src/schema/types.d.ts.map +1 -0
- package/package.json +20 -17
- package/src/components/{ColumnMenu.stories.tsx → ColumnMenu/ColumnMenu.stories.tsx} +31 -1
- package/src/components/{ColumnMenu.tsx → ColumnMenu/ColumnMenu.tsx} +36 -34
- package/src/components/{ColumnSettingsForm.tsx → ColumnMenu/ColumnSettingsForm.tsx} +83 -75
- package/src/components/ColumnMenu/index.ts +6 -0
- package/src/components/Table/Table.stories.tsx +244 -74
- package/src/components/Table/Table.tsx +81 -97
- package/src/components/Table/TableBody.tsx +6 -1
- package/src/components/Table/TableRootContext.ts +39 -0
- package/src/components/Table/index.ts +1 -0
- package/src/components/Table/props.ts +17 -24
- package/src/components/index.ts +1 -1
- package/src/helpers.tsx +9 -7
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useColumnSizing.ts +45 -0
- package/src/hooks/usePinLastRow.ts +64 -0
- package/src/hooks/useRowSelection.ts +39 -0
- package/src/index.ts +3 -1
- package/src/{components/schema → schema}/SchemaToTable.stories.tsx +17 -18
- package/src/schema/index.ts +6 -0
- package/src/{components/schema → schema}/schema.test.ts +1 -1
- package/src/{components/schema → schema}/schema.ts +37 -41
- package/src/{components/schema → schema}/schemaToColumns.ts +7 -9
- package/dist/types/src/components/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/components/ColumnSettingsForm.d.ts.map +0 -1
- package/dist/types/src/components/hooks/useColumnSorting.d.ts.map +0 -1
- package/dist/types/src/components/hooks/usePinLastRow.d.ts +0 -3
- package/dist/types/src/components/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/components/schema/SchemaToTable.stories.d.ts.map +0 -1
- package/dist/types/src/components/schema/schema.d.ts.map +0 -1
- package/dist/types/src/components/schema/schema.test.d.ts.map +0 -1
- package/dist/types/src/components/schema/schemaToColumns.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts.map +0 -1
- package/src/components/hooks/usePinLastRow.ts +0 -43
- /package/dist/types/src/{components/hooks → hooks}/useColumnSorting.d.ts +0 -0
- /package/dist/types/src/{components/schema → schema}/SchemaToTable.stories.d.ts +0 -0
- /package/dist/types/src/{components/schema → schema}/schema.test.d.ts +0 -0
- /package/src/{components/hooks → hooks}/useColumnSorting.ts +0 -0
- /package/src/{schema.ts → schema/types.ts} +0 -0
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
import '@dxosTheme';
|
|
6
6
|
|
|
7
7
|
import * as Arbitrary from '@effect/schema/Arbitrary';
|
|
8
|
-
import * as S from '@effect/schema/Schema';
|
|
9
8
|
import * as fc from 'fast-check';
|
|
10
|
-
import React
|
|
9
|
+
import React from 'react';
|
|
11
10
|
|
|
11
|
+
import { S } from '@dxos/echo-schema';
|
|
12
12
|
import { DensityProvider } from '@dxos/react-ui';
|
|
13
13
|
import { withTheme } from '@dxos/storybook-utils';
|
|
14
14
|
|
|
15
15
|
import { schemaToColumnDefs } from './schemaToColumns';
|
|
16
|
-
import { Table } from '../
|
|
16
|
+
import { Table } from '../components';
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
19
|
title: 'react-ui-table/SchemaTable',
|
|
@@ -51,22 +51,21 @@ const items = fc.sample(exampleSchemaArbitrary, 10);
|
|
|
51
51
|
|
|
52
52
|
export const SchemaTable = {
|
|
53
53
|
render: () => {
|
|
54
|
-
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
55
|
-
|
|
56
54
|
return (
|
|
57
|
-
<
|
|
58
|
-
<Table
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
<Table.Root>
|
|
56
|
+
<Table.Viewport classNames='inset-0 fixed'>
|
|
57
|
+
<Table.Table<ExampleSchema>
|
|
58
|
+
role='grid'
|
|
59
|
+
rowsSelectable='multi'
|
|
60
|
+
keyAccessor={(row) => JSON.stringify(row)}
|
|
61
|
+
columns={columns}
|
|
62
|
+
data={items}
|
|
63
|
+
fullWidth
|
|
64
|
+
stickyHeader
|
|
65
|
+
border
|
|
66
|
+
/>
|
|
67
|
+
</Table.Viewport>
|
|
68
|
+
</Table.Root>
|
|
70
69
|
);
|
|
71
70
|
},
|
|
72
71
|
};
|
|
@@ -2,26 +2,54 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as AST from '@effect/schema/AST';
|
|
6
6
|
import type * as S from '@effect/schema/Schema';
|
|
7
7
|
|
|
8
|
-
import { type ColumnType } from '
|
|
8
|
+
import { type ColumnType } from './types';
|
|
9
9
|
|
|
10
10
|
export type ClassifiedColumnType = ColumnType | 'display';
|
|
11
11
|
|
|
12
|
+
// TODO(burdon): Rename getX? and return typed array?
|
|
13
|
+
export const classifySchemaProperties = (schema: S.Schema<any, any>): [string, ClassifiedColumnType][] => {
|
|
14
|
+
const recurse = (node: AST.AST, path: string[], acc: [string, ClassifiedColumnType][]) => {
|
|
15
|
+
const properties = AST.getPropertySignatures(node);
|
|
16
|
+
properties.forEach((prop) => {
|
|
17
|
+
const propName = prop.name.toString();
|
|
18
|
+
|
|
19
|
+
if (prop.isOptional) {
|
|
20
|
+
const unwrappedAst = unwrapOptionProperty(prop);
|
|
21
|
+
if (isStruct(unwrappedAst)) {
|
|
22
|
+
return recurse(unwrappedAst, [...path, propName], acc);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isStruct(prop.type)) {
|
|
27
|
+
recurse(prop.type, [...path, propName], acc);
|
|
28
|
+
} else {
|
|
29
|
+
acc.push([path.concat(propName).join('.'), propertyToColumn(prop)]);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return acc;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return recurse(schema.ast, [], []);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const isStruct = (node: AST.AST) => AST.isTypeLiteral(node);
|
|
40
|
+
|
|
12
41
|
const isOptionalUnion = (prop: AST.PropertySignature) => AST.isUnion(prop.type) && prop.isOptional;
|
|
13
42
|
|
|
14
43
|
const unwrapOptionProperty = (prop: AST.PropertySignature) => {
|
|
15
44
|
if (!isOptionalUnion(prop)) {
|
|
16
|
-
throw new Error(
|
|
45
|
+
throw new Error(`Not an optional property: ${String(prop.name)}`);
|
|
17
46
|
}
|
|
18
47
|
|
|
19
48
|
if (!AST.isUnion(prop.type)) {
|
|
20
|
-
throw new Error(
|
|
49
|
+
throw new Error(`Not a union type: ${String(prop.name)}`);
|
|
21
50
|
}
|
|
22
51
|
|
|
23
52
|
const [type, _undefinedCase] = prop.type.types;
|
|
24
|
-
|
|
25
53
|
return type;
|
|
26
54
|
};
|
|
27
55
|
|
|
@@ -44,7 +72,6 @@ const typeToColumn = (type: AST.AST): ClassifiedColumnType => {
|
|
|
44
72
|
|
|
45
73
|
if (AST.isTransform(type)) {
|
|
46
74
|
const identifier = AST.getIdentifierAnnotation(type);
|
|
47
|
-
|
|
48
75
|
if (identifier._tag === 'Some') {
|
|
49
76
|
if (identifier.value === 'DateFromString') {
|
|
50
77
|
return 'date';
|
|
@@ -55,42 +82,11 @@ const typeToColumn = (type: AST.AST): ClassifiedColumnType => {
|
|
|
55
82
|
return 'display';
|
|
56
83
|
};
|
|
57
84
|
|
|
58
|
-
const propertyToColumn = (
|
|
59
|
-
let type =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
type = unwrapOptionProperty(property);
|
|
85
|
+
const propertyToColumn = (prop: AST.PropertySignature): ClassifiedColumnType => {
|
|
86
|
+
let type = prop.type;
|
|
87
|
+
if (prop.isOptional) {
|
|
88
|
+
type = unwrapOptionProperty(prop);
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
return typeToColumn(type);
|
|
66
92
|
};
|
|
67
|
-
|
|
68
|
-
const isStruct = (node: AST.AST) => AST.isTypeLiteral(node);
|
|
69
|
-
|
|
70
|
-
export const classifySchemaProperties = (schema: S.Schema<any, any>) => {
|
|
71
|
-
const recurse = (node: AST.AST, path: string[], acc: [string, ClassifiedColumnType][]) => {
|
|
72
|
-
const properties = AST.getPropertySignatures(node);
|
|
73
|
-
|
|
74
|
-
properties.forEach((prop) => {
|
|
75
|
-
const propName = prop.name.toString();
|
|
76
|
-
|
|
77
|
-
if (prop.isOptional) {
|
|
78
|
-
const unwrappedAst = unwrapOptionProperty(prop);
|
|
79
|
-
|
|
80
|
-
if (isStruct(unwrappedAst)) {
|
|
81
|
-
return recurse(unwrappedAst, [...path, propName], acc);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (isStruct(prop.type)) {
|
|
86
|
-
recurse(prop.type, [...path, propName], acc);
|
|
87
|
-
} else {
|
|
88
|
-
acc.push([path.concat(propName).join('.'), propertyToColumn(prop)]);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return acc;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return recurse(schema.ast, [], []);
|
|
96
|
-
};
|
|
@@ -2,22 +2,21 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type * as S from '@effect/schema/Schema';
|
|
6
5
|
import { type ColumnDef } from '@tanstack/react-table';
|
|
7
6
|
|
|
7
|
+
import type { S } from '@dxos/echo-schema';
|
|
8
|
+
|
|
8
9
|
import { classifySchemaProperties } from './schema';
|
|
9
|
-
import { createColumnBuilder } from '
|
|
10
|
+
import { createColumnBuilder } from '../helpers';
|
|
10
11
|
|
|
11
12
|
export const schemaToColumnDefs = <T>(schema: S.Schema<T, any>): ColumnDef<T, any>[] => {
|
|
12
|
-
const classified = classifySchemaProperties(schema);
|
|
13
|
-
|
|
14
13
|
const { helper, builder } = createColumnBuilder<T>();
|
|
15
14
|
|
|
15
|
+
const classified = classifySchemaProperties(schema);
|
|
16
16
|
return classified.map(([name, type]) => {
|
|
17
17
|
const propertyKey = name.toString();
|
|
18
18
|
|
|
19
19
|
let column: Partial<ColumnDef<any, any>> | undefined;
|
|
20
|
-
|
|
21
20
|
switch (type) {
|
|
22
21
|
case 'string': {
|
|
23
22
|
column = builder.string({ label: propertyKey });
|
|
@@ -39,10 +38,9 @@ export const schemaToColumnDefs = <T>(schema: S.Schema<T, any>): ColumnDef<T, an
|
|
|
39
38
|
column = builder.display({ label: propertyKey, id: propertyKey });
|
|
40
39
|
break;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
throw new Error(`Unhandled column type: ${type}`);
|
|
41
|
+
default: {
|
|
42
|
+
throw new Error(`Unhandled column type: ${type}`);
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
return helper.accessor(propertyKey as any, column);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnMenu.d.ts","sourceRoot":"","sources":["../../../../src/components/ColumnMenu.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAQ7F,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,MAAM,eAAe,CAAC,KAAK,SAAS,OAAO,EAAE,MAAM,IAAI;IAC3D,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACtC,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,UAAU,sGAqFtB,CAAC;AAEF,eAAO,MAAM,mBAAmB;aAOe,MAAM,IAAI;iBAkBxD,CAAC;AAEF,eAAO,MAAM,aAAa;eAIb,aAAa,GAAG,KAAK;iBACnB,GAAG,KAAK,IAAI;wBAsB1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnMenu.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/ColumnMenu.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAQpB,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;;;;;;AAE7C,wBAIE;AAEF,eAAO,MAAM,OAAO;;;;;;;2CAUa,OAAO;;;;;;;yBAY5B,GAAG;;;;CASd,CAAC;AAEF,eAAO,MAAM,YAAY;;CA2CxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ColumnSettingsForm.d.ts","sourceRoot":"","sources":["../../../../src/components/ColumnSettingsForm.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAmB,MAAM,WAAW,CAAC;AAS7E,eAAO,MAAM,kBAAkB;YAQrB,WAAW;cACT,QAAQ;eACP,QAAQ,EAAE;qBACJ,MAAM,UAAU,WAAW,KAAK,IAAI;qBACpC,MAAM,KAAK,IAAI;aACvB,MAAM,IAAI;iBA4KpB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useColumnSorting.d.ts","sourceRoot":"","sources":["../../../../../src/components/hooks/useColumnSorting.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGxE,eAAO,MAAM,gBAAgB,WAAY,OAAO,GAAG,CAAC;;;8BAoCjB,aAAa;;;CAU/C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePinLastRow.d.ts","sourceRoot":"","sources":["../../../../../src/components/hooks/usePinLastRow.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAGnD,eAAO,MAAM,aAAa,eACZ,OAAO,GAAG,SAAS,SACxB,MAAM,GAAG,CAAC,QACX,GAAG,qBACU,MAAM,OAAO,GAAG,IAAI,SA+BxC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaToTable.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/schema/SchemaToTable.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;;;;;;AAapB,wBAWE;AAuBF,eAAO,MAAM,WAAW;;CAoBvB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../../src/components/schema/schema.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAEhD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,SAAS,CAAC;AA4D1D,eAAO,MAAM,wBAAwB,WAAY,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,qCA0BlE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.test.d.ts","sourceRoot":"","sources":["../../../../../src/components/schema/schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schemaToColumns.d.ts","sourceRoot":"","sources":["../../../../../src/components/schema/schemaToColumns.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAKvD,eAAO,MAAM,kBAAkB,6DAuC9B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/schema.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IAGf,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Table } from '@tanstack/react-table';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
export const usePinLastRow = (
|
|
9
|
-
pinLastRow: boolean | undefined,
|
|
10
|
-
table: Table<any>,
|
|
11
|
-
data: any,
|
|
12
|
-
getScrollElement?: () => Element | null,
|
|
13
|
-
) => {
|
|
14
|
-
const [pinnedRowKey, setPinnedRowKey] = useState<string>();
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (!pinLastRow) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const rows = table.getRowModel().rows;
|
|
22
|
-
const rowToPin = rows[rows.length - 1];
|
|
23
|
-
const rowId = rowToPin.id;
|
|
24
|
-
|
|
25
|
-
if (rowId === pinnedRowKey) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
table.resetRowPinning();
|
|
30
|
-
rowToPin.pin('bottom');
|
|
31
|
-
|
|
32
|
-
const scrollElement = getScrollElement?.();
|
|
33
|
-
const isFirstRender = pinnedRowKey === undefined;
|
|
34
|
-
|
|
35
|
-
if (scrollElement && !isFirstRender) {
|
|
36
|
-
requestAnimationFrame(() => {
|
|
37
|
-
scrollElement.scrollTo({ top: scrollElement.scrollHeight });
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setPinnedRowKey(rowId);
|
|
42
|
-
}, [pinLastRow, table, getScrollElement, pinnedRowKey, setPinnedRowKey, data]);
|
|
43
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|