@dxos/react-ui-table 0.8.4-main.70d3990 → 0.8.4-main.74a063c4e0
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/{chunk-5XWSB3JP.mjs → chunk-BF54SSNL.mjs} +27 -28
- package/dist/lib/browser/chunk-BF54SSNL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KNC7XYT6.mjs → chunk-NTWHM2PX.mjs} +620 -652
- package/dist/lib/browser/chunk-NTWHM2PX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1164 -1021
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +22 -21
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-MKTMOY46.mjs → chunk-SIRDIPHZ.mjs} +27 -28
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-CWSGS3Y2.mjs → chunk-Z3TLFG6Z.mjs} +620 -651
- package/dist/lib/node-esm/chunk-Z3TLFG6Z.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1164 -1021
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +22 -21
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +21 -37
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +82 -81
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +28 -21
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +84 -83
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +21 -0
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts +25 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -12
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +24 -26
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +22 -13
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +5 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +2 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +6 -5
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -8
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +100 -18
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +3 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +5 -8
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +21 -23
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +13 -15
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +12 -10
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +55 -56
- package/src/components/Table/ColumnActionsMenu.tsx +15 -11
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +22 -23
- package/src/components/Table/DynamicTable.tsx +32 -40
- package/src/components/Table/Relations.stories.tsx +56 -48
- package/src/components/Table/RowActionsMenu.tsx +3 -2
- package/src/components/Table/Table.stories.tsx +89 -78
- package/src/components/Table/Table.tsx +43 -407
- package/src/components/Table/TableContent.tsx +421 -0
- package/src/components/{TableToolbar → Table}/TableToolbar.tsx +43 -44
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -5
- package/src/components/TableCellEditor/FormCellEditor.tsx +118 -135
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +16 -14
- package/src/components/TableCellEditor/TableCellEditor.tsx +33 -29
- package/src/components/index.ts +0 -1
- package/src/components/testing.ts +42 -16
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +29 -9
- package/src/hooks/useTableModel.ts +27 -23
- package/src/model/modal-controller.ts +23 -12
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +81 -54
- package/src/model/table-model.ts +410 -138
- package/src/model/table-presentation.test.ts +58 -49
- package/src/model/table-presentation.ts +34 -29
- package/src/playwright/TableManager.ts +12 -5
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +51 -7
- package/src/testing/useTestTableModel.ts +26 -27
- package/src/translations.ts +20 -22
- package/src/types/Table.ts +28 -38
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +36 -19
- package/src/util/index.ts +2 -0
- package/src/util/query-ast.ts +22 -0
- package/src/util/sort.ts +90 -0
- package/src/util/table-buttons.ts +1 -1
- package/src/util/table-controls.ts +2 -2
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +0 -7
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +0 -7
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
- package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -56
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/src/components/TableToolbar/index.ts +0 -5
- package/src/model/table-sorting.ts +0 -234
package/src/translations.ts
CHANGED
|
@@ -4,33 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
export const translationKey = 'react-ui-table';
|
|
7
|
+
export const translationKey = '@dxos/react-ui-table';
|
|
8
8
|
|
|
9
9
|
export const translations = [
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'object
|
|
14
|
-
'create
|
|
15
|
-
'table
|
|
16
|
-
'settings
|
|
17
|
-
'table
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'column
|
|
24
|
-
'column
|
|
25
|
-
'column
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'create new object label': 'Create new object “{{text}}”',
|
|
33
|
-
'save view label': 'Save changes to view',
|
|
13
|
+
'object.placeholder': 'New table',
|
|
14
|
+
'create-object.label': 'Create table',
|
|
15
|
+
'table-name.placeholder': 'Table name',
|
|
16
|
+
'settings.title': 'Table settings',
|
|
17
|
+
'table-schema.label': 'Type',
|
|
18
|
+
'continue.label': 'Continue',
|
|
19
|
+
'create-stack-section.label': 'Create table',
|
|
20
|
+
'add-row.label': 'Add row',
|
|
21
|
+
'column-action-sort-descending.menu': 'Sort Descending',
|
|
22
|
+
'column-action-sort-ascending.menu': 'Sort Ascending',
|
|
23
|
+
'column-action-clear-sorting.menu': 'Clear Sorting',
|
|
24
|
+
'column-action-settings.menu': 'Column Settings',
|
|
25
|
+
'column-action-delete.menu': 'Delete Column',
|
|
26
|
+
'delete-row.label': 'Delete row',
|
|
27
|
+
'bulk-delete-row.label': 'Delete selected rows',
|
|
28
|
+
'column-deleted.label': 'Column deleted',
|
|
29
|
+
'new-column-button.label': 'Create column',
|
|
30
|
+
'create-new-object.label': 'Create new object “{{text}}”',
|
|
31
|
+
'save-view.label': 'Save changes to view',
|
|
34
32
|
},
|
|
35
33
|
},
|
|
36
34
|
},
|
package/src/types/Table.ts
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import * as Match from 'effect/Match';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
8
|
|
|
8
|
-
import { Obj, Ref, Type } from '@dxos/echo';
|
|
9
|
+
import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { View } from '@dxos/echo';
|
|
9
11
|
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
10
|
-
import {
|
|
11
|
-
import { View, ViewAnnotation, getSchemaProperties } from '@dxos/schema';
|
|
12
|
+
import { ViewAnnotation } from '@dxos/schema';
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
+
export const Table = Schema.Struct({
|
|
14
15
|
name: Schema.String.pipe(Schema.optional),
|
|
15
16
|
|
|
16
|
-
view:
|
|
17
|
+
view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
17
18
|
|
|
18
19
|
sizes: Schema.Record({
|
|
19
20
|
// TODO(wittjosiah): Should be JsonPath.
|
|
@@ -21,19 +22,23 @@ const TableSchema = Schema.Struct({
|
|
|
21
22
|
value: Schema.Number,
|
|
22
23
|
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
23
24
|
}).pipe(
|
|
24
|
-
Type.
|
|
25
|
-
typename: 'dxos.
|
|
26
|
-
version: '0.
|
|
25
|
+
Type.object({
|
|
26
|
+
typename: 'org.dxos.type.table',
|
|
27
|
+
version: '0.1.0',
|
|
27
28
|
}),
|
|
28
29
|
LabelAnnotation.set(['name']),
|
|
29
30
|
ViewAnnotation.set(true),
|
|
31
|
+
Annotation.IconAnnotation.set({
|
|
32
|
+
icon: 'ph--table--regular',
|
|
33
|
+
hue: 'green',
|
|
34
|
+
}),
|
|
30
35
|
);
|
|
31
36
|
|
|
32
|
-
export interface Table extends Schema.Schema.Type<typeof
|
|
33
|
-
export interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}
|
|
34
|
-
export const Table: Schema.Schema<Table, TableEncoded> = TableSchema;
|
|
37
|
+
export interface Table extends Schema.Schema.Type<typeof Table> {}
|
|
35
38
|
|
|
36
|
-
type MakeProps =
|
|
39
|
+
type MakeProps = {
|
|
40
|
+
name?: string;
|
|
41
|
+
sizes?: Record<string, number>;
|
|
37
42
|
view: View.View;
|
|
38
43
|
/** Required to auto-size columns. */
|
|
39
44
|
jsonSchema?: JsonSchemaType;
|
|
@@ -43,24 +48,25 @@ type MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {
|
|
|
43
48
|
* Make a table as a view of a data set.
|
|
44
49
|
*/
|
|
45
50
|
export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
|
|
46
|
-
const table = Obj.make(Table, { name, view: Ref.make(view), sizes });
|
|
51
|
+
const table = Obj.make(Table, { name, view: Ref.make(view), sizes } as Obj.MakeProps<typeof Table>);
|
|
47
52
|
|
|
48
53
|
// Preset sizes.
|
|
49
54
|
if (jsonSchema) {
|
|
50
|
-
const schema =
|
|
51
|
-
const properties =
|
|
55
|
+
const schema = JsonSchema.toEffectSchema(jsonSchema);
|
|
56
|
+
const properties = SchemaAST.getPropertySignatures(schema.ast);
|
|
52
57
|
for (const property of properties) {
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
const name = property.name.toString() as JsonPath;
|
|
59
|
+
if (sizes?.[name]) {
|
|
60
|
+
table.sizes[name] = sizes[name];
|
|
55
61
|
continue;
|
|
56
62
|
}
|
|
57
63
|
|
|
58
|
-
Match.type<
|
|
59
|
-
Match.when('
|
|
60
|
-
table.sizes[
|
|
64
|
+
Match.type<SchemaAST.AST>().pipe(
|
|
65
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => {
|
|
66
|
+
table.sizes[name] = 100;
|
|
61
67
|
}),
|
|
62
|
-
Match.when('
|
|
63
|
-
table.sizes[
|
|
68
|
+
Match.when({ _tag: 'NumberKeyword' }, () => {
|
|
69
|
+
table.sizes[name] = 100;
|
|
64
70
|
}),
|
|
65
71
|
Match.orElse(() => {
|
|
66
72
|
// Noop.
|
|
@@ -71,19 +77,3 @@ export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table =
|
|
|
71
77
|
|
|
72
78
|
return table;
|
|
73
79
|
};
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
// V1
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
export const TableV1 = Schema.Struct({
|
|
80
|
-
sizes: Schema.Record({
|
|
81
|
-
key: Schema.String,
|
|
82
|
-
value: Schema.Number,
|
|
83
|
-
}).pipe(Schema.mutable),
|
|
84
|
-
}).pipe(
|
|
85
|
-
Type.Obj({
|
|
86
|
-
typename: 'dxos.org/type/Table',
|
|
87
|
-
version: '0.1.0',
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { Format } from '@dxos/echo';
|
|
9
|
+
|
|
10
|
+
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from './dynamic-table';
|
|
11
|
+
|
|
12
|
+
describe('makeDynamicTable', () => {
|
|
13
|
+
/**
|
|
14
|
+
* Base case: plain jsonSchema (not from Echo / JsonSchema.toJsonSchema). Does not exercise the path
|
|
15
|
+
* where projection or schema are reactive, so this does not reproduce the Obj.change regression.
|
|
16
|
+
* Confirms makeDynamicTable + setProperties (title) works with plain objects.
|
|
17
|
+
*/
|
|
18
|
+
test('makeDynamicTable with plain jsonSchema and properties with title does not throw', () => {
|
|
19
|
+
const registry = Registry.make();
|
|
20
|
+
const jsonSchema = {
|
|
21
|
+
type: 'object' as const,
|
|
22
|
+
properties: {
|
|
23
|
+
id: { type: 'string' as const },
|
|
24
|
+
name: { type: 'string' as const },
|
|
25
|
+
},
|
|
26
|
+
required: ['id'],
|
|
27
|
+
};
|
|
28
|
+
const properties: TablePropertyDefinition[] = [
|
|
29
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
30
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
expect(() => {
|
|
34
|
+
const { projection, object } = makeDynamicTable({
|
|
35
|
+
registry,
|
|
36
|
+
jsonSchema,
|
|
37
|
+
properties,
|
|
38
|
+
});
|
|
39
|
+
expect(projection).toBeDefined();
|
|
40
|
+
expect(object).toBeDefined();
|
|
41
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
42
|
+
}).not.toThrow();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Regression test for the path where jsonSchema comes from getBaseSchema(typename, properties).
|
|
47
|
+
* That path uses Echo (ViewModel.make, JsonSchema.toJsonSchema); mutations must run inside Obj.change and on a
|
|
48
|
+
* cloned schema. This test ensures that flow does not throw.
|
|
49
|
+
*/
|
|
50
|
+
test('makeDynamicTable with jsonSchema from getBaseSchema(typename, properties) and properties with title does not throw', () => {
|
|
51
|
+
const registry = Registry.make();
|
|
52
|
+
const typename = 'com.example.type.dynamic-table-test';
|
|
53
|
+
const properties: TablePropertyDefinition[] = [
|
|
54
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
55
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
56
|
+
];
|
|
57
|
+
const { jsonSchema } = getBaseSchema({ typename, properties });
|
|
58
|
+
|
|
59
|
+
expect(() => {
|
|
60
|
+
const { projection, object } = makeDynamicTable({
|
|
61
|
+
registry,
|
|
62
|
+
jsonSchema,
|
|
63
|
+
properties,
|
|
64
|
+
});
|
|
65
|
+
expect(projection).toBeDefined();
|
|
66
|
+
expect(object).toBeDefined();
|
|
67
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
68
|
+
}).not.toThrow();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import type * as Types from 'effect/Types';
|
|
6
7
|
|
|
7
|
-
import { Filter,
|
|
8
|
+
import { Filter, JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type } from '@dxos/echo';
|
|
9
|
+
import { type View } from '@dxos/echo';
|
|
8
10
|
import {
|
|
9
11
|
ProjectionModel,
|
|
10
12
|
type SchemaPropertyDefinition,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
ViewModel,
|
|
14
|
+
createEchoChangeCallback,
|
|
13
15
|
getSchemaFromPropertyDefinitions,
|
|
14
16
|
} from '@dxos/schema';
|
|
15
17
|
|
|
@@ -19,7 +21,7 @@ import { Table } from '../types';
|
|
|
19
21
|
type PropertyDisplayProps = {
|
|
20
22
|
size: number;
|
|
21
23
|
title: string;
|
|
22
|
-
sort:
|
|
24
|
+
sort: QueryAST.OrderDirection;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<PropertyDisplayProps>;
|
|
@@ -29,21 +31,21 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
|
|
|
29
31
|
*/
|
|
30
32
|
// TODO(burdon): Remove variance.
|
|
31
33
|
export const getBaseSchema = ({
|
|
34
|
+
schema,
|
|
32
35
|
typename,
|
|
33
36
|
properties,
|
|
34
37
|
jsonSchema,
|
|
35
|
-
schema,
|
|
36
38
|
}: {
|
|
39
|
+
schema?: Type.AnyEntity;
|
|
37
40
|
typename?: string;
|
|
38
41
|
properties?: TablePropertyDefinition[];
|
|
39
|
-
jsonSchema?: JsonSchema.JsonSchema
|
|
40
|
-
|
|
41
|
-
}): { typename: string; jsonSchema: JsonSchema.JsonSchema } => {
|
|
42
|
+
jsonSchema?: Types.DeepMutable<JsonSchema.JsonSchema>;
|
|
43
|
+
}): { typename: string; jsonSchema: Types.DeepMutable<JsonSchema.JsonSchema> } => {
|
|
42
44
|
if (typename && properties) {
|
|
43
45
|
const schema = getSchemaFromPropertyDefinitions(typename, properties);
|
|
44
|
-
return { typename: schema.typename, jsonSchema: schema
|
|
46
|
+
return { typename: schema.typename, jsonSchema: JsonSchema.toJsonSchema(schema) };
|
|
45
47
|
} else if (schema) {
|
|
46
|
-
return { typename: Type.getTypename(schema)!, jsonSchema:
|
|
48
|
+
return { typename: Type.getTypename(schema)!, jsonSchema: JsonSchema.toJsonSchema(schema) };
|
|
47
49
|
} else if (typename && jsonSchema) {
|
|
48
50
|
return { typename, jsonSchema };
|
|
49
51
|
} else {
|
|
@@ -52,22 +54,29 @@ export const getBaseSchema = ({
|
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
export const makeDynamicTable = ({
|
|
57
|
+
registry,
|
|
55
58
|
jsonSchema,
|
|
56
59
|
properties,
|
|
57
60
|
}: {
|
|
58
|
-
|
|
61
|
+
registry: Registry.Registry;
|
|
62
|
+
jsonSchema: Types.DeepMutable<JsonSchema.JsonSchema>;
|
|
59
63
|
properties?: TablePropertyDefinition[];
|
|
60
64
|
}): { projection: ProjectionModel; object: Table.Table } => {
|
|
61
|
-
const view =
|
|
65
|
+
const view = ViewModel.make({
|
|
62
66
|
query: Query.select(Filter.everything()),
|
|
63
67
|
jsonSchema,
|
|
64
68
|
...(properties && { fields: properties.map((property) => property.name) }),
|
|
65
69
|
});
|
|
66
70
|
const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
|
|
67
71
|
|
|
68
|
-
const projection = new ProjectionModel(
|
|
72
|
+
const projection = new ProjectionModel({
|
|
73
|
+
registry,
|
|
74
|
+
view,
|
|
75
|
+
baseSchema: jsonSchema,
|
|
76
|
+
change: createEchoChangeCallback(view, jsonSchema),
|
|
77
|
+
});
|
|
69
78
|
projection.normalizeView();
|
|
70
|
-
if (properties && projection.
|
|
79
|
+
if (properties && projection.getFields()) {
|
|
71
80
|
setProperties(view, projection, object, properties);
|
|
72
81
|
}
|
|
73
82
|
|
|
@@ -81,10 +90,12 @@ const setProperties = (
|
|
|
81
90
|
properties: TablePropertyDefinition[],
|
|
82
91
|
) => {
|
|
83
92
|
for (const property of properties) {
|
|
84
|
-
const field = projection.
|
|
93
|
+
const field = projection.getFields().find((field) => field.path === property.name);
|
|
85
94
|
if (field) {
|
|
86
95
|
if (property.size !== undefined) {
|
|
87
|
-
table
|
|
96
|
+
Obj.change(table, (obj) => {
|
|
97
|
+
obj.sizes[field.path] = property.size!;
|
|
98
|
+
});
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
if (property.title !== undefined) {
|
|
@@ -96,8 +107,14 @@ const setProperties = (
|
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
if (property.sort) {
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
// Apply sort to query instead of deprecated view.sort
|
|
111
|
+
const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
|
|
112
|
+
// Use any type parameter since we're working with dynamic field paths
|
|
113
|
+
const newQuery = currentQuery.orderBy(Order.property<any>(field.path as string, property.sort));
|
|
114
|
+
Obj.change(view, (obj) => {
|
|
115
|
+
// Type assertion needed because Query AST types have some variance issues.
|
|
116
|
+
obj.query.ast = newQuery.ast as typeof obj.query.ast;
|
|
117
|
+
});
|
|
101
118
|
}
|
|
102
119
|
}
|
|
103
120
|
}
|
package/src/util/index.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type QueryAST } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts order clauses from a query AST.
|
|
9
|
+
* Handles nested structures (options, order, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export const extractOrder = (queryAst: QueryAST.Query): readonly QueryAST.Order[] | undefined => {
|
|
12
|
+
if (queryAst.type === 'order') {
|
|
13
|
+
return queryAst.order;
|
|
14
|
+
}
|
|
15
|
+
if (queryAst.type === 'options') {
|
|
16
|
+
return extractOrder(queryAst.query);
|
|
17
|
+
}
|
|
18
|
+
if (queryAst.type === 'from') {
|
|
19
|
+
return extractOrder(queryAst.query);
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
package/src/util/sort.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Format, type QueryAST } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets a normalized sort value for a given value and format.
|
|
9
|
+
* This ensures consistent sorting behavior across different data types.
|
|
10
|
+
*/
|
|
11
|
+
export const getSortValue = (value: any, format: Format.TypeFormat): any => {
|
|
12
|
+
// Handle null/undefined
|
|
13
|
+
if (value === undefined || value === null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Handle dates chronologically if schema indicates date format
|
|
18
|
+
const isDateFormat = format === Format.TypeFormat.DateTime || format === Format.TypeFormat.Date;
|
|
19
|
+
if (isDateFormat) {
|
|
20
|
+
const date = new Date(value);
|
|
21
|
+
if (!isNaN(date.getTime())) {
|
|
22
|
+
return date.getTime();
|
|
23
|
+
}
|
|
24
|
+
// Fallback to string if date parsing fails
|
|
25
|
+
return String(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Handle numbers if schema indicates number format
|
|
29
|
+
if (
|
|
30
|
+
format === Format.TypeFormat.Number ||
|
|
31
|
+
format === Format.TypeFormat.Integer ||
|
|
32
|
+
format === Format.TypeFormat.Currency ||
|
|
33
|
+
format === Format.TypeFormat.Percent ||
|
|
34
|
+
format === Format.TypeFormat.Duration
|
|
35
|
+
) {
|
|
36
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
37
|
+
if (!isNaN(num)) {
|
|
38
|
+
return num;
|
|
39
|
+
}
|
|
40
|
+
// Fallback to string if number parsing fails
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Default to string comparison
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fallback to string representation
|
|
53
|
+
return String(value);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compares two values for sorting based on the field format.
|
|
58
|
+
* Handles dates, numbers, and strings appropriately.
|
|
59
|
+
*/
|
|
60
|
+
export const compareValues = (
|
|
61
|
+
aValue: any,
|
|
62
|
+
bValue: any,
|
|
63
|
+
format: Format.TypeFormat,
|
|
64
|
+
direction: QueryAST.OrderDirection,
|
|
65
|
+
): number => {
|
|
66
|
+
// Handle null/undefined values - nulls sort to the end
|
|
67
|
+
if (aValue === undefined || aValue === null) {
|
|
68
|
+
return bValue === undefined || bValue === null ? 0 : 1;
|
|
69
|
+
}
|
|
70
|
+
if (bValue === undefined || bValue === null) {
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Get normalized sort values
|
|
75
|
+
const aSortValue = getSortValue(aValue, format);
|
|
76
|
+
const bSortValue = getSortValue(bValue, format);
|
|
77
|
+
|
|
78
|
+
// Compare based on type
|
|
79
|
+
let comparison = 0;
|
|
80
|
+
if (typeof aSortValue === 'number' && typeof bSortValue === 'number') {
|
|
81
|
+
comparison = aSortValue - bSortValue;
|
|
82
|
+
} else if (typeof aSortValue === 'string' && typeof bSortValue === 'string') {
|
|
83
|
+
comparison = aSortValue.localeCompare(bSortValue);
|
|
84
|
+
} else {
|
|
85
|
+
// Mixed types - convert both to strings
|
|
86
|
+
comparison = String(aSortValue).localeCompare(String(bSortValue));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return direction === 'desc' ? -comparison : comparison;
|
|
90
|
+
};
|
|
@@ -39,7 +39,7 @@ const createButton = ({
|
|
|
39
39
|
.map(([k, v]) => `${k}="${v}"`)
|
|
40
40
|
.join(' ');
|
|
41
41
|
|
|
42
|
-
return `<button ${attr} data-testid="${testId}" class="dx-button
|
|
42
|
+
return `<button ${attr} data-testid="${testId}" class="dx-button w-6 aspect-square px-0.5 min-h-0" ${dataAttrs} ${disabled ? 'disabled' : ''} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const addColumnButton = {
|
|
@@ -25,8 +25,8 @@ export const CONTROL_IDENTIFIERS = {
|
|
|
25
25
|
} as const;
|
|
26
26
|
|
|
27
27
|
const BASE_CLASSES = {
|
|
28
|
-
checkbox: 'absolute inset-
|
|
29
|
-
switch: 'absolute inset-
|
|
28
|
+
checkbox: 'absolute inset-y-[.375rem] end-[.375rem] dx-checkbox',
|
|
29
|
+
switch: 'absolute inset-y-[.25rem] end-[.25rem] dx-checkbox--switch',
|
|
30
30
|
} as const;
|
|
31
31
|
|
|
32
32
|
const renderAttributes = (data: Record<string, string>) => {
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types/Table.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Ref, Type } from '@dxos/echo';\nimport { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';\nimport { type SimpleType } from '@dxos/effect';\nimport { View, ViewAnnotation, getSchemaProperties } from '@dxos/schema';\n\nconst TableSchema = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n\n view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),\n\n sizes: Schema.Record({\n // TODO(wittjosiah): Should be JsonPath.\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable, FormInputAnnotation.set(false)),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.2.0',\n }),\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(true),\n);\n\nexport interface Table extends Schema.Schema.Type<typeof TableSchema> {}\nexport interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}\nexport const Table: Schema.Schema<Table, TableEncoded> = TableSchema;\n\ntype MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {\n view: View.View;\n /** Required to auto-size columns. */\n jsonSchema?: JsonSchemaType;\n};\n\n/**\n * Make a table as a view of a data set.\n */\nexport const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {\n const table = Obj.make(Table, { name, view: Ref.make(view), sizes });\n\n // Preset sizes.\n if (jsonSchema) {\n const schema = Type.toEffectSchema(jsonSchema);\n const properties = getSchemaProperties(schema.ast, {});\n for (const property of properties) {\n if (sizes?.[property.name]) {\n table.sizes[property.name] = sizes[property.name];\n continue;\n }\n\n Match.type<SimpleType>().pipe(\n Match.when('boolean', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.when('number', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.orElse(() => {\n // Noop.\n }),\n )(property.type);\n }\n }\n\n return table;\n};\n\n//\n// V1\n//\n\nexport const TableV1 = Schema.Struct({\n sizes: Schema.Record({\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.1.0',\n }),\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AAExB,SAASC,KAAKC,KAAKC,YAAY;AAC/B,SAASC,qBAAyDC,uBAAuB;AAEzF,SAASC,MAAMC,gBAAgBC,2BAA2B;AAE1D,IAAMC,cAAqBC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EAExCC,MAAMC,KAAKC,IAAIC,KAAKA,IAAI,EAAEL,KAAKM,oBAAoBC,IAAI,KAAA,CAAA;EAEvDC,OAAcC,cAAO;;IAEnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,gBAASP,oBAAoBC,IAAI,KAAA,CAAA;AAClD,CAAA,EAAGP,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,gBAAgBV,IAAI;EAAC;CAAO,GAC5BW,eAAeX,IAAI,IAAA,CAAA;AAKd,IAAMY,QAA4CvB;AAWlD,IAAMwB,OAAO,CAAC,EAAEtB,MAAMU,QAAQ,CAAC,GAAGN,MAAMmB,WAAU,MAAa;AACpE,QAAMC,QAAQR,IAAIM,KAAKD,OAAO;IAAErB;IAAMI,MAAME,IAAIgB,KAAKlB,IAAAA;IAAOM;EAAM,CAAA;AAGlE,MAAIa,YAAY;AACd,UAAME,SAASpB,KAAKqB,eAAeH,UAAAA;AACnC,UAAMI,aAAaC,oBAAoBH,OAAOI,KAAK,CAAC,CAAA;AACpD,eAAWC,YAAYH,YAAY;AACjC,UAAIjB,QAAQoB,SAAS9B,IAAI,GAAG;AAC1BwB,cAAMd,MAAMoB,SAAS9B,IAAI,IAAIU,MAAMoB,SAAS9B,IAAI;AAChD;MACF;AAEA+B,MAAMC,WAAI,EAAe9B,KACjB+B,WAAK,WAAW,MAAA;AACpBT,cAAMd,MAAMoB,SAAS9B,IAAI,IAAgB;MAC3C,CAAA,GACMiC,WAAK,UAAU,MAAA;AACnBT,cAAMd,MAAMoB,SAAS9B,IAAI,IAAgB;MAC3C,CAAA,GACMkC,aAAO,MAAA;MAEb,CAAA,CAAA,EACAJ,SAASE,IAAI;IACjB;EACF;AAEA,SAAOR;AACT;AAMO,IAAMW,UAAiBpC,cAAO;EACnCW,OAAcC,cAAO;IACnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,cAAO;AACxB,CAAA,EAAGb,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;",
|
|
6
|
-
"names": ["Match", "Schema", "Obj", "Ref", "Type", "FormInputAnnotation", "LabelAnnotation", "View", "ViewAnnotation", "getSchemaProperties", "TableSchema", "Struct", "name", "String", "pipe", "optional", "view", "Type", "Ref", "View", "FormInputAnnotation", "set", "sizes", "Record", "key", "value", "Number", "mutable", "Obj", "typename", "version", "LabelAnnotation", "ViewAnnotation", "Table", "make", "jsonSchema", "table", "schema", "toEffectSchema", "properties", "getSchemaProperties", "ast", "property", "Match", "type", "when", "orElse", "TableV1"]
|
|
7
|
-
}
|