@dxos/react-ui-table 0.6.11 → 0.6.12-main.568932b

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 (55) hide show
  1. package/dist/lib/browser/index.mjs +49 -60
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts +12 -0
  5. package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
  6. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts +83 -0
  7. package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
  8. package/dist/types/src/components/ColumnMenu/index.d.ts +1 -1
  9. package/dist/types/src/components/ColumnMenu/index.d.ts.map +1 -1
  10. package/dist/types/src/components/Form/Form.stories.d.ts +42 -0
  11. package/dist/types/src/components/Form/Form.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/Table/TableContext.d.ts +2 -4
  13. package/dist/types/src/components/Table/TableContext.d.ts.map +1 -1
  14. package/dist/types/src/components/Table/TableHead.d.ts.map +1 -1
  15. package/dist/types/src/components/Table/index.d.ts +2 -1
  16. package/dist/types/src/components/Table/index.d.ts.map +1 -1
  17. package/dist/types/src/helpers.d.ts +1 -1
  18. package/dist/types/src/helpers.d.ts.map +1 -1
  19. package/dist/types/src/hooks/useRowSelection.d.ts.map +1 -1
  20. package/dist/types/src/schema/{SchemaToTable.stories.d.ts → Schema.stories.d.ts} +2 -3
  21. package/dist/types/src/schema/Schema.stories.d.ts.map +1 -0
  22. package/dist/types/src/schema/{schemaToColumns.d.ts → column-utils.d.ts} +2 -2
  23. package/dist/types/src/schema/column-utils.d.ts.map +1 -0
  24. package/dist/types/src/schema/index.d.ts +3 -1
  25. package/dist/types/src/schema/index.d.ts.map +1 -1
  26. package/dist/types/src/schema/schema.d.ts +2 -3
  27. package/dist/types/src/schema/schema.d.ts.map +1 -1
  28. package/dist/types/src/schema/types.d.ts +1 -1
  29. package/dist/types/src/schema/types.d.ts.map +1 -1
  30. package/package.json +22 -20
  31. package/src/components/ColumnMenu/ColumnMenu.stories.tsx +9 -9
  32. package/src/components/ColumnMenu/ColumnMenu.tsx +2 -2
  33. package/src/components/ColumnMenu/{ColumnSettingsForm.stories.tsx → ColumnSettings.stories.tsx} +18 -15
  34. package/src/components/ColumnMenu/{ColumnSettingsForm.tsx → ColumnSettings.tsx} +34 -36
  35. package/src/components/ColumnMenu/index.ts +1 -1
  36. package/src/components/Form/Form.stories.tsx +69 -0
  37. package/src/components/Table/Table.stories.tsx +2 -2
  38. package/src/components/Table/Table.tsx +3 -3
  39. package/src/components/Table/TableContext.tsx +13 -7
  40. package/src/components/Table/TableHead.tsx +0 -1
  41. package/src/components/Table/index.ts +2 -1
  42. package/src/helpers.tsx +4 -6
  43. package/src/hooks/useRowSelection.ts +1 -0
  44. package/src/schema/{SchemaToTable.stories.tsx → Schema.stories.tsx} +6 -15
  45. package/src/schema/{schemaToColumns.ts → column-utils.ts} +5 -5
  46. package/src/schema/index.ts +3 -1
  47. package/src/schema/schema.test.ts +21 -93
  48. package/src/schema/schema.ts +23 -30
  49. package/src/schema/types.ts +4 -2
  50. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts +0 -12
  51. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.d.ts.map +0 -1
  52. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts +0 -63
  53. package/dist/types/src/components/ColumnMenu/ColumnSettingsForm.stories.d.ts.map +0 -1
  54. package/dist/types/src/schema/SchemaToTable.stories.d.ts.map +0 -1
  55. package/dist/types/src/schema/schemaToColumns.d.ts.map +0 -1
@@ -2,64 +2,49 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
5
+ import { Schema as S } from '@effect/schema';
6
+ import { describe, expect, test } from 'vitest';
6
7
 
7
- import { S } from '@dxos/echo-schema';
8
- import { describe, test } from '@dxos/test';
8
+ import { getColumnTypes } from './schema';
9
9
 
10
- import { classifySchemaProperties } from './schema';
10
+ // TODO(burdon): Realistic data.
11
11
 
12
- describe('schema->column-type', () => {
12
+ describe('getColumnTypes', () => {
13
13
  test('basic', () => {
14
- const simpleSchema = S.Struct({
14
+ const schema = S.Struct({
15
15
  field1: S.String,
16
16
  field2: S.Number,
17
+ field3: S.Date,
17
18
  });
18
19
 
19
- const columns = classifySchemaProperties(simpleSchema);
20
-
20
+ const columns = getColumnTypes(schema);
21
21
  expect(columns).to.deep.equal([
22
22
  ['field1', 'string'],
23
23
  ['field2', 'number'],
24
+ ['field3', 'date'],
24
25
  ]);
25
26
  });
26
27
 
27
28
  test('optional properties', () => {
28
- const simpleSchema = S.Struct({
29
+ const schema = S.Struct({
29
30
  field1: S.optional(S.String),
30
31
  field2: S.optional(S.Number),
31
32
  });
32
33
 
33
- const columns = classifySchemaProperties(simpleSchema);
34
-
34
+ const columns = getColumnTypes(schema);
35
35
  expect(columns).to.deep.equal([
36
36
  ['field1', 'string'],
37
37
  ['field2', 'number'],
38
38
  ]);
39
39
  });
40
40
 
41
- test('dates', () => {
42
- const simpleSchema = S.Struct({
43
- field1: S.Date,
44
- field2: S.optional(S.Date),
45
- });
46
-
47
- const columns = classifySchemaProperties(simpleSchema);
48
-
49
- expect(columns).to.deep.equal([
50
- ['field1', 'date'],
51
- ['field2', 'date'],
52
- ]);
53
- });
54
-
55
- test('Piped validators', () => {
56
- const simpleSchema = S.Struct({
57
- name: S.optional(S.String.pipe(S.nonEmpty(), S.maxLength(10))),
41
+ test('piped validators', () => {
42
+ const schema = S.Struct({
43
+ name: S.optional(S.String.pipe(S.nonEmptyString(), S.maxLength(10))),
58
44
  age: S.Number.pipe(S.negative()),
59
45
  });
60
46
 
61
- const columns = classifySchemaProperties(simpleSchema);
62
-
47
+ const columns = getColumnTypes(schema);
63
48
  expect(columns).to.deep.equal([
64
49
  ['name', 'string'],
65
50
  ['age', 'number'],
@@ -67,81 +52,24 @@ describe('schema->column-type', () => {
67
52
  });
68
53
 
69
54
  test('nested schema', () => {
70
- const simpleSchema = S.Struct({
71
- name: S.String,
72
- nested: S.Struct({
73
- age: S.Number,
74
- }),
75
- someUnion: S.Union(S.String, S.Number),
76
- });
77
-
78
- const columns = classifySchemaProperties(simpleSchema);
79
-
80
- expect(columns).to.deep.equal([
81
- ['name', 'string'],
82
- ['nested.age', 'number'],
83
- ['someUnion', 'display'],
84
- ]);
85
- });
86
-
87
- test('deeply nested schema', () => {
88
- const simpleSchema = S.Struct({
55
+ const schema = S.Struct({
89
56
  name: S.String,
90
- nested: S.Struct({
57
+ nested1: S.Struct({
91
58
  age: S.Number,
92
59
  deeplyNested: S.Struct({
93
- height: S.Number,
60
+ height: S.optional(S.Number),
94
61
  }),
95
62
  }),
96
- });
97
-
98
- const columns = classifySchemaProperties(simpleSchema);
99
-
100
- expect(columns).to.deep.equal([
101
- ['name', 'string'],
102
- ['nested.age', 'number'],
103
- ['nested.deeplyNested.height', 'number'],
104
- ]);
105
- });
106
-
107
- test('even more deeply nested schema with optionals', () => {
108
- const simpleSchema = S.Struct({
109
- name: S.String,
110
- nested: S.Struct({
111
- age: S.Number,
112
- deeplyNested: S.optional(
113
- S.Struct({
114
- height: S.optional(S.Number),
115
- }),
116
- ),
117
- }),
118
- });
119
-
120
- const columns = classifySchemaProperties(simpleSchema);
121
-
122
- expect(columns).to.deep.equal([
123
- ['name', 'string'],
124
- ['nested.age', 'number'],
125
- ['nested.deeplyNested.height', 'number'],
126
- ]);
127
- });
128
-
129
- test('multiple-nested schemata as sibblings', () => {
130
- const simpleSchema = S.Struct({
131
- name: S.String,
132
- nested: S.Struct({
133
- age: S.Number,
134
- }),
135
63
  nested2: S.Struct({
136
64
  height: S.Number,
137
65
  }),
138
66
  });
139
67
 
140
- const columns = classifySchemaProperties(simpleSchema);
141
-
68
+ const columns = getColumnTypes(schema);
142
69
  expect(columns).to.deep.equal([
143
70
  ['name', 'string'],
144
- ['nested.age', 'number'],
71
+ ['nested1.age', 'number'],
72
+ ['nested1.deeplyNested.height', 'number'],
145
73
  ['nested2.height', 'number'],
146
74
  ]);
147
75
  });
@@ -2,30 +2,27 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import * as AST from '@effect/schema/AST';
6
- import type * as S from '@effect/schema/Schema';
5
+ import { AST, type S } from '@dxos/effect';
7
6
 
8
7
  import { type ColumnType } from './types';
9
8
 
10
- // TODO(burdon): Reconcile with react-ui-table.
11
- export type ClassifiedColumnType = ColumnType | 'display';
12
-
13
- // TODO(burdon): Rename getX? and return typed array?
14
- export const classifySchemaProperties = (schema: S.Schema<any, any>): [string, ClassifiedColumnType][] => {
15
- const recurse = (node: AST.AST, path: string[], acc: [string, ClassifiedColumnType][]) => {
16
- const properties = AST.getPropertySignatures(node);
17
- properties.forEach((prop) => {
9
+ // TODO(burdon): Factor out to @dxos/effect?
10
+ // TODO(burdon): Return struct (with prop metadata).
11
+ export const getColumnTypes = (schema: S.Schema<any, any>): [string, ColumnType][] => {
12
+ const visitNode = (node: AST.AST, path: string[] = [], acc: [string, ColumnType][] = []) => {
13
+ const props = AST.getPropertySignatures(node);
14
+ props.forEach((prop) => {
18
15
  const propName = prop.name.toString();
19
16
 
20
17
  if (prop.isOptional) {
21
18
  const unwrappedAst = unwrapOptionProperty(prop);
22
19
  if (isStruct(unwrappedAst)) {
23
- return recurse(unwrappedAst, [...path, propName], acc);
20
+ return visitNode(unwrappedAst, [...path, propName], acc);
24
21
  }
25
22
  }
26
23
 
27
24
  if (isStruct(prop.type)) {
28
- recurse(prop.type, [...path, propName], acc);
25
+ visitNode(prop.type, [...path, propName], acc);
29
26
  } else {
30
27
  acc.push([path.concat(propName).join('.'), propertyToColumn(prop)]);
31
28
  }
@@ -34,27 +31,31 @@ export const classifySchemaProperties = (schema: S.Schema<any, any>): [string, C
34
31
  return acc;
35
32
  };
36
33
 
37
- return recurse(schema.ast, [], []);
34
+ return visitNode(schema.ast);
38
35
  };
39
36
 
37
+ // TODO(burdon): Document AST?
40
38
  const isStruct = (node: AST.AST) => AST.isTypeLiteral(node);
41
39
 
42
- const isOptionalUnion = (prop: AST.PropertySignature) => AST.isUnion(prop.type) && prop.isOptional;
43
-
44
- const unwrapOptionProperty = (prop: AST.PropertySignature) => {
45
- if (!isOptionalUnion(prop)) {
46
- throw new Error(`Not an optional property: ${String(prop.name)}`);
40
+ const propertyToColumn = (prop: AST.PropertySignature): ColumnType => {
41
+ let type = prop.type;
42
+ if (prop.isOptional) {
43
+ type = unwrapOptionProperty(prop);
47
44
  }
48
45
 
46
+ return typeToColumn(type);
47
+ };
48
+
49
+ const unwrapOptionProperty = (prop: AST.PropertySignature) => {
49
50
  if (!AST.isUnion(prop.type)) {
50
51
  throw new Error(`Not a union type: ${String(prop.name)}`);
51
52
  }
52
53
 
53
- const [type, _undefinedCase] = prop.type.types;
54
+ const [type] = prop.type.types;
54
55
  return type;
55
56
  };
56
57
 
57
- const typeToColumn = (type: AST.AST): ClassifiedColumnType => {
58
+ const typeToColumn = (type: AST.AST): ColumnType => {
58
59
  if (AST.isStringKeyword(type)) {
59
60
  return 'string';
60
61
  } else if (AST.isNumberKeyword(type)) {
@@ -80,14 +81,6 @@ const typeToColumn = (type: AST.AST): ClassifiedColumnType => {
80
81
  }
81
82
  }
82
83
 
83
- return 'display';
84
- };
85
-
86
- const propertyToColumn = (prop: AST.PropertySignature): ClassifiedColumnType => {
87
- let type = prop.type;
88
- if (prop.isOptional) {
89
- type = unwrapOptionProperty(prop);
90
- }
91
-
92
- return typeToColumn(type);
84
+ // TODO(burdon): Better fallback?
85
+ return 'json';
93
86
  };
@@ -4,12 +4,14 @@
4
4
 
5
5
  export type TableDef = {
6
6
  id: string;
7
- name?: string; // TODO(burdon): Required?
7
+ name?: string;
8
8
  columns: ColumnProps[];
9
9
  };
10
10
 
11
- export type ColumnType = 'number' | 'boolean' | 'date' | 'string' | 'ref';
11
+ // TODO(burdon): Use Effect defs?
12
+ export type ColumnType = 'number' | 'boolean' | 'date' | 'string' | 'json' | 'ref';
12
13
 
14
+ // TODO(burdon): Effect schema?
13
15
  export type ColumnProps = {
14
16
  id: string;
15
17
  prop: string;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { type TableDef, type ColumnProps } from '../../schema';
3
- export type ColumnSettingsFormProps = {
4
- column: ColumnProps;
5
- tableDef: TableDef;
6
- tablesToReference: TableDef[];
7
- onUpdate?: ((id: string, column: ColumnProps) => void) | undefined;
8
- onDelete?: ((id: string) => void) | undefined;
9
- onClose?: () => void;
10
- };
11
- export declare const ColumnSettingsForm: ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose, }: ColumnSettingsFormProps) => React.JSX.Element;
12
- //# sourceMappingURL=ColumnSettingsForm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ColumnSettingsForm.d.ts","sourceRoot":"","sources":["../../../../../src/components/ColumnMenu/ColumnSettingsForm.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAKhD,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAmB,MAAM,cAAc,CAAC;AAGhF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,QAAQ,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACnE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC9C,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,0EAO5B,uBAAuB,sBAkLzB,CAAC"}
@@ -1,63 +0,0 @@
1
- import '@dxos-theme';
2
- import React from 'react';
3
- import { type ColumnSettingsFormProps } from './ColumnSettingsForm';
4
- import { type TableDef } from '../../schema';
5
- declare const _default: {
6
- title: string;
7
- component: ({ column, tableDef, tablesToReference, onUpdate, onDelete, onClose, }: ColumnSettingsFormProps) => React.JSX.Element;
8
- decorators: import("@storybook/react/*").Decorator[];
9
- };
10
- export default _default;
11
- export declare const Default: {
12
- args: ColumnSettingsFormProps;
13
- };
14
- export declare const NumberColumn: {
15
- args: {
16
- column: {
17
- id: string;
18
- prop: string;
19
- type: string;
20
- label: string;
21
- digits: number;
22
- };
23
- tableDef: TableDef;
24
- tablesToReference: TableDef[];
25
- onUpdate?: ((id: string, column: import("../../schema").ColumnProps) => void) | undefined;
26
- onDelete?: ((id: string) => void) | undefined;
27
- onClose?: () => void;
28
- };
29
- };
30
- export declare const ReferenceColumn: {
31
- args: {
32
- column: {
33
- id: string;
34
- prop: string;
35
- type: string;
36
- label: string;
37
- refTable: string;
38
- refProp: string;
39
- };
40
- tableDef: TableDef;
41
- tablesToReference: TableDef[];
42
- onUpdate?: ((id: string, column: import("../../schema").ColumnProps) => void) | undefined;
43
- onDelete?: ((id: string) => void) | undefined;
44
- onClose?: () => void;
45
- };
46
- };
47
- export declare const NewColumn: {
48
- args: {
49
- column: {
50
- id: string;
51
- prop: string;
52
- type: string;
53
- label: string;
54
- };
55
- tableDef: TableDef;
56
- tablesToReference: TableDef[];
57
- onUpdate?: ((id: string, column: import("../../schema").ColumnProps) => void) | undefined;
58
- onDelete?: ((id: string) => void) | undefined;
59
- onClose?: () => void;
60
- };
61
- };
62
- export declare const Interactive: (args: ColumnSettingsFormProps) => React.JSX.Element;
63
- //# sourceMappingURL=ColumnSettingsForm.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ColumnSettingsForm.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/ColumnMenu/ColumnSettingsForm.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AACrB,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAsB,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;;;;;;AAE7C,wBAIE;AAqCF,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;CAWxB,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;CAY3B,CAAC;AAEF,eAAO,MAAM,SAAS;;;;;;;;;;;;;;CAUrB,CAAC;AAQF,eAAO,MAAM,WAAW,SANA,uBAAuB,sBAMH,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SchemaToTable.stories.d.ts","sourceRoot":"","sources":["../../../../src/schema/SchemaToTable.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAIrB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;;AAS1B,wBAWE;AAuBF,eAAO,MAAM,WAAW;;CAmBvB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemaToColumns.d.ts","sourceRoot":"","sources":["../../../../src/schema/schemaToColumns.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAK3C,eAAO,MAAM,kBAAkB,GAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAAG,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAoCjF,CAAC"}