@dxos/react-ui-table 0.4.10-main.c42bfdb → 0.4.10-main.c61b011
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 +340 -213
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts +5 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +1 -1
- 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/helpers.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- 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/usePinLastRow.d.ts +1 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +1 -1
- 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/schema/SchemaToTable.stories.d.ts.map +1 -1
- package/dist/types/src/schema/schema.d.ts.map +1 -1
- package/dist/types/src/schema/schemaToColumns.d.ts +1 -1
- package/dist/types/src/schema/schemaToColumns.d.ts.map +1 -1
- package/package.json +20 -17
- package/src/components/ColumnMenu/ColumnMenu.stories.tsx +30 -0
- package/src/components/ColumnMenu/ColumnMenu.tsx +34 -32
- package/src/components/ColumnMenu/ColumnSettingsForm.tsx +69 -63
- 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/helpers.tsx +9 -7
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useColumnSizing.ts +45 -0
- package/src/hooks/usePinLastRow.ts +47 -26
- package/src/hooks/useRowSelection.ts +39 -0
- package/src/schema/SchemaToTable.stories.tsx +16 -17
- package/src/schema/schema.test.ts +1 -1
- package/src/schema/schema.ts +36 -37
- package/src/schema/schemaToColumns.ts +2 -1
|
@@ -5,10 +5,10 @@
|
|
|
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
|
|
|
@@ -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
|
};
|
package/src/schema/schema.ts
CHANGED
|
@@ -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
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
|
|
|
@@ -54,40 +82,11 @@ const typeToColumn = (type: AST.AST): ClassifiedColumnType => {
|
|
|
54
82
|
return 'display';
|
|
55
83
|
};
|
|
56
84
|
|
|
57
|
-
const propertyToColumn = (
|
|
58
|
-
let type =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
type = unwrapOptionProperty(property);
|
|
85
|
+
const propertyToColumn = (prop: AST.PropertySignature): ClassifiedColumnType => {
|
|
86
|
+
let type = prop.type;
|
|
87
|
+
if (prop.isOptional) {
|
|
88
|
+
type = unwrapOptionProperty(prop);
|
|
62
89
|
}
|
|
63
90
|
|
|
64
91
|
return typeToColumn(type);
|
|
65
92
|
};
|
|
66
|
-
|
|
67
|
-
const isStruct = (node: AST.AST) => AST.isTypeLiteral(node);
|
|
68
|
-
|
|
69
|
-
export const classifySchemaProperties = (schema: S.Schema<any, any>) => {
|
|
70
|
-
const recurse = (node: AST.AST, path: string[], acc: [string, ClassifiedColumnType][]) => {
|
|
71
|
-
const properties = AST.getPropertySignatures(node);
|
|
72
|
-
properties.forEach((prop) => {
|
|
73
|
-
const propName = prop.name.toString();
|
|
74
|
-
|
|
75
|
-
if (prop.isOptional) {
|
|
76
|
-
const unwrappedAst = unwrapOptionProperty(prop);
|
|
77
|
-
if (isStruct(unwrappedAst)) {
|
|
78
|
-
return recurse(unwrappedAst, [...path, propName], acc);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (isStruct(prop.type)) {
|
|
83
|
-
recurse(prop.type, [...path, propName], acc);
|
|
84
|
-
} else {
|
|
85
|
-
acc.push([path.concat(propName).join('.'), propertyToColumn(prop)]);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return acc;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
return recurse(schema.ast, [], []);
|
|
93
|
-
};
|
|
@@ -2,9 +2,10 @@
|
|
|
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
10
|
import { createColumnBuilder } from '../helpers';
|
|
10
11
|
|