@dxos/react-ui-table 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b
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-CJQ6T4LL.mjs +77 -0
- package/dist/lib/browser/chunk-CJQ6T4LL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-V7A7ZA5E.mjs} +576 -544
- package/dist/lib/browser/chunk-V7A7ZA5E.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +694 -760
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/{chunk-Y66YLSTC.mjs → chunk-P73ALX3N.mjs} +576 -544
- package/dist/lib/node-esm/chunk-P73ALX3N.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs +78 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +694 -760
- 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 +16 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -3
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +5 -6
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +37 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +13 -9
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +14 -9
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +11 -18
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -5
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +3 -2
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +5 -6
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +0 -7
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +14 -14
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +2 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +9 -6
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +19 -34
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts +28 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +10 -11
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +0 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -51
- package/src/components/Table/ColumnActionsMenu.tsx +5 -2
- package/src/components/Table/ColumnSettings.tsx +3 -4
- package/src/components/Table/DynamicTable.stories.tsx +21 -19
- package/src/components/Table/DynamicTable.tsx +24 -18
- package/src/components/Table/Relations.stories.tsx +233 -0
- package/src/components/Table/RowActionsMenu.tsx +23 -15
- package/src/components/Table/Table.stories.tsx +104 -99
- package/src/components/Table/Table.tsx +338 -295
- package/src/components/TableCellEditor/CellValidationMessage.tsx +2 -2
- package/src/components/TableCellEditor/FormCellEditor.tsx +143 -39
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +30 -66
- package/src/components/TableCellEditor/TableCellEditor.tsx +86 -236
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +34 -24
- package/src/components/testing.ts +4 -4
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +7 -5
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +13 -15
- package/src/model/modal-controller.ts +1 -29
- package/src/model/selection-model.ts +3 -2
- package/src/model/table-model.test.ts +21 -12
- package/src/model/table-model.ts +64 -58
- package/src/model/table-presentation.test.ts +25 -23
- package/src/model/table-presentation.ts +82 -41
- package/src/model/table-sorting.ts +32 -14
- package/src/playwright/TableManager.ts +5 -5
- package/src/playwright/smoke.spec.ts +132 -38
- package/src/testing/useTestTableModel.ts +32 -24
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +90 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +21 -27
- package/src/util/index.ts +0 -1
- package/src/util/schema.ts +4 -4
- package/src/util/table-buttons.ts +4 -3
- package/src/util/table-controls.ts +4 -1
- package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
- package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -8
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -11
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/Table/relations.stories.tsx +0 -116
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/types/schema.ts +0 -16
- package/src/util/table.ts +0 -49
|
@@ -2,40 +2,49 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useCallback, useMemo, useRef } from 'react';
|
|
5
|
+
import { type RefObject, useCallback, useMemo, useRef } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type Type } from '@dxos/echo';
|
|
8
|
+
import { isMutable } from '@dxos/echo/internal';
|
|
8
9
|
import { useGlobalFilteredObjects } from '@dxos/plugin-search';
|
|
9
10
|
import { faker } from '@dxos/random';
|
|
10
|
-
import {
|
|
11
|
-
import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
11
|
+
import { Filter, type Space, useQuery, useSchema } from '@dxos/react-client/echo';
|
|
12
12
|
import { useClientProvider } from '@dxos/react-client/testing';
|
|
13
|
-
import {
|
|
13
|
+
import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
14
14
|
|
|
15
15
|
import { type TableController } from '../components';
|
|
16
|
-
import {
|
|
17
|
-
import { TablePresentation } from '../model';
|
|
16
|
+
import { useAddRow, useProjectionModel, useTableModel } from '../hooks';
|
|
17
|
+
import { type TableModel, TablePresentation } from '../model';
|
|
18
|
+
import { Table } from '../types';
|
|
18
19
|
|
|
19
20
|
faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
|
|
20
21
|
|
|
22
|
+
export type TestTableModel<T extends Type.Entity.Any = Type.Entity.Any> = {
|
|
23
|
+
schema: T | undefined;
|
|
24
|
+
table: Table.Table | undefined;
|
|
25
|
+
projection: ProjectionModel | undefined;
|
|
26
|
+
tableRef: RefObject<TableController | null>;
|
|
27
|
+
model: TableModel | undefined;
|
|
28
|
+
presentation: TablePresentation | undefined;
|
|
29
|
+
space: Space | undefined;
|
|
30
|
+
handleInsertRow: () => void;
|
|
31
|
+
handleSaveView: () => void;
|
|
32
|
+
handleDeleteRows: (rowIndex: number, objects: any[]) => void;
|
|
33
|
+
handleDeleteColumn: (fieldId: string) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
21
36
|
/**
|
|
22
37
|
* Custom hook to create and manage a test table model for storybook demonstrations.
|
|
23
38
|
* Provides table data, schema, and handlers for table operations.
|
|
24
39
|
*/
|
|
25
|
-
export const useTestTableModel = () => {
|
|
26
|
-
const client = useClient();
|
|
40
|
+
export const useTestTableModel = <T extends Type.Entity.Any = Type.Entity.Any>(): TestTableModel<T> => {
|
|
27
41
|
const { space } = useClientProvider();
|
|
28
42
|
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const projection = useMemo(() => {
|
|
35
|
-
if (schema && view?.projection) {
|
|
36
|
-
return new ProjectionModel(toJsonSchema(schema), view.projection);
|
|
37
|
-
}
|
|
38
|
-
}, [schema, view?.projection]);
|
|
43
|
+
const tables = useQuery(space, Filter.type(Table.Table));
|
|
44
|
+
const table = tables.at(0);
|
|
45
|
+
const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
|
|
46
|
+
const schema = useSchema<T>(space, typename);
|
|
47
|
+
const projection = useProjectionModel(schema, table);
|
|
39
48
|
|
|
40
49
|
const features = useMemo(
|
|
41
50
|
() => ({
|
|
@@ -79,8 +88,7 @@ export const useTestTableModel = () => {
|
|
|
79
88
|
);
|
|
80
89
|
|
|
81
90
|
const model = useTableModel({
|
|
82
|
-
|
|
83
|
-
schema: jsonSchema,
|
|
91
|
+
object: table,
|
|
84
92
|
projection,
|
|
85
93
|
features,
|
|
86
94
|
rows: filteredObjects,
|
|
@@ -92,7 +100,8 @@ export const useTestTableModel = () => {
|
|
|
92
100
|
});
|
|
93
101
|
|
|
94
102
|
const handleInsertRow = useCallback(() => {
|
|
95
|
-
model?.insertRow();
|
|
103
|
+
const insertResult = model?.insertRow();
|
|
104
|
+
tableRef.current?.handleInsertRowResult?.(insertResult);
|
|
96
105
|
}, [model]);
|
|
97
106
|
|
|
98
107
|
const handleSaveView = useCallback(() => {
|
|
@@ -107,13 +116,12 @@ export const useTestTableModel = () => {
|
|
|
107
116
|
|
|
108
117
|
return {
|
|
109
118
|
schema,
|
|
110
|
-
|
|
119
|
+
table,
|
|
111
120
|
projection,
|
|
112
121
|
tableRef,
|
|
113
122
|
model,
|
|
114
123
|
presentation,
|
|
115
124
|
space,
|
|
116
|
-
client,
|
|
117
125
|
handleInsertRow,
|
|
118
126
|
handleSaveView,
|
|
119
127
|
handleDeleteRows,
|
package/src/translations.ts
CHANGED
|
@@ -14,8 +14,8 @@ export const translations = [
|
|
|
14
14
|
'create object label': 'Create table',
|
|
15
15
|
'table name placeholder': 'Table name',
|
|
16
16
|
'settings title': 'Table settings',
|
|
17
|
-
'table schema label': '
|
|
18
|
-
'new schema': 'New
|
|
17
|
+
'table schema label': 'Type',
|
|
18
|
+
'new schema': 'New type',
|
|
19
19
|
'continue label': 'Continue',
|
|
20
20
|
'create stack section label': 'Create table',
|
|
21
21
|
'add row label': 'Add row',
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
import { Obj, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
11
|
+
import { View, ViewAnnotation } from '@dxos/schema';
|
|
12
|
+
|
|
13
|
+
const TableSchema = Schema.Struct({
|
|
14
|
+
name: Schema.String.pipe(Schema.optional),
|
|
15
|
+
|
|
16
|
+
view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
17
|
+
|
|
18
|
+
sizes: Schema.Record({
|
|
19
|
+
// TODO(wittjosiah): Should be JsonPath.
|
|
20
|
+
key: Schema.String,
|
|
21
|
+
value: Schema.Number,
|
|
22
|
+
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
23
|
+
}).pipe(
|
|
24
|
+
Type.Obj({
|
|
25
|
+
typename: 'dxos.org/type/Table',
|
|
26
|
+
version: '0.2.0',
|
|
27
|
+
}),
|
|
28
|
+
LabelAnnotation.set(['name']),
|
|
29
|
+
ViewAnnotation.set(true),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export interface Table extends Schema.Schema.Type<typeof TableSchema> {}
|
|
33
|
+
export interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}
|
|
34
|
+
export const Table: Schema.Schema<Table, TableEncoded> = TableSchema;
|
|
35
|
+
|
|
36
|
+
type MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {
|
|
37
|
+
view: View.View;
|
|
38
|
+
/** Required to auto-size columns. */
|
|
39
|
+
jsonSchema?: JsonSchemaType;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Make a table as a view of a data set.
|
|
44
|
+
*/
|
|
45
|
+
export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
|
|
46
|
+
const table = Obj.make(Table, { name, view: Ref.make(view), sizes });
|
|
47
|
+
|
|
48
|
+
// Preset sizes.
|
|
49
|
+
if (jsonSchema) {
|
|
50
|
+
const schema = Type.toEffectSchema(jsonSchema);
|
|
51
|
+
const properties = SchemaAST.getPropertySignatures(schema.ast);
|
|
52
|
+
for (const property of properties) {
|
|
53
|
+
const name = property.name.toString() as JsonPath;
|
|
54
|
+
if (sizes?.[name]) {
|
|
55
|
+
table.sizes[name] = sizes[name];
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Match.type<SchemaAST.AST>().pipe(
|
|
60
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => {
|
|
61
|
+
table.sizes[name] = 100;
|
|
62
|
+
}),
|
|
63
|
+
Match.when({ _tag: 'NumberKeyword' }, () => {
|
|
64
|
+
table.sizes[name] = 100;
|
|
65
|
+
}),
|
|
66
|
+
Match.orElse(() => {
|
|
67
|
+
// Noop.
|
|
68
|
+
}),
|
|
69
|
+
)(property.type);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return table;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//
|
|
77
|
+
// V1
|
|
78
|
+
//
|
|
79
|
+
|
|
80
|
+
export const TableV1 = Schema.Struct({
|
|
81
|
+
sizes: Schema.Record({
|
|
82
|
+
key: Schema.String,
|
|
83
|
+
value: Schema.Number,
|
|
84
|
+
}).pipe(Schema.mutable),
|
|
85
|
+
}).pipe(
|
|
86
|
+
Type.Obj({
|
|
87
|
+
typename: 'dxos.org/type/Table',
|
|
88
|
+
version: '0.1.0',
|
|
89
|
+
}),
|
|
90
|
+
);
|
package/src/types/index.ts
CHANGED
|
@@ -2,20 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
|
|
7
|
-
import { Obj } from '@dxos/echo';
|
|
8
|
-
import { getTypename, toJsonSchema } from '@dxos/echo-schema';
|
|
9
|
-
import type { JsonSchemaType, SortDirectionType } from '@dxos/echo-schema';
|
|
5
|
+
import { Filter, type JsonSchema, Obj, Query, Ref, Type } from '@dxos/echo';
|
|
10
6
|
import {
|
|
11
|
-
createView,
|
|
12
|
-
type DataType,
|
|
13
|
-
getSchemaFromPropertyDefinitions,
|
|
14
7
|
ProjectionModel,
|
|
15
8
|
type SchemaPropertyDefinition,
|
|
9
|
+
type SortDirectionType,
|
|
10
|
+
View,
|
|
11
|
+
getSchemaFromPropertyDefinitions,
|
|
16
12
|
} from '@dxos/schema';
|
|
17
13
|
|
|
18
|
-
import {
|
|
14
|
+
import { Table } from '../types';
|
|
19
15
|
|
|
20
16
|
// TODO(ZaymonFC): Upstream these extra fields to SchemaPropertyDefinition to enhance schema-tools schema creation.
|
|
21
17
|
type PropertyDisplayProps = {
|
|
@@ -31,21 +27,21 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
|
|
|
31
27
|
*/
|
|
32
28
|
// TODO(burdon): Remove variance.
|
|
33
29
|
export const getBaseSchema = ({
|
|
30
|
+
schema,
|
|
34
31
|
typename,
|
|
35
32
|
properties,
|
|
36
33
|
jsonSchema,
|
|
37
|
-
schema,
|
|
38
34
|
}: {
|
|
35
|
+
schema?: Type.Entity.Any;
|
|
39
36
|
typename?: string;
|
|
40
37
|
properties?: TablePropertyDefinition[];
|
|
41
|
-
jsonSchema?:
|
|
42
|
-
|
|
43
|
-
}): { typename: string; jsonSchema: JsonSchemaType } => {
|
|
38
|
+
jsonSchema?: JsonSchema.JsonSchema;
|
|
39
|
+
}): { typename: string; jsonSchema: JsonSchema.JsonSchema } => {
|
|
44
40
|
if (typename && properties) {
|
|
45
41
|
const schema = getSchemaFromPropertyDefinitions(typename, properties);
|
|
46
42
|
return { typename: schema.typename, jsonSchema: schema.jsonSchema };
|
|
47
43
|
} else if (schema) {
|
|
48
|
-
return { typename: getTypename(schema)!, jsonSchema: toJsonSchema(schema) };
|
|
44
|
+
return { typename: Type.getTypename(schema)!, jsonSchema: Type.toJsonSchema(schema) };
|
|
49
45
|
} else if (typename && jsonSchema) {
|
|
50
46
|
return { typename, jsonSchema };
|
|
51
47
|
} else {
|
|
@@ -54,34 +50,32 @@ export const getBaseSchema = ({
|
|
|
54
50
|
};
|
|
55
51
|
|
|
56
52
|
export const makeDynamicTable = ({
|
|
57
|
-
typename,
|
|
58
53
|
jsonSchema,
|
|
59
54
|
properties,
|
|
60
55
|
}: {
|
|
61
|
-
|
|
62
|
-
jsonSchema: JsonSchemaType;
|
|
56
|
+
jsonSchema: JsonSchema.JsonSchema;
|
|
63
57
|
properties?: TablePropertyDefinition[];
|
|
64
|
-
}): { projection: ProjectionModel;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
typename,
|
|
58
|
+
}): { projection: ProjectionModel; object: Table.Table } => {
|
|
59
|
+
const view = View.make({
|
|
60
|
+
query: Query.select(Filter.everything()),
|
|
68
61
|
jsonSchema,
|
|
69
|
-
presentation: table,
|
|
70
62
|
...(properties && { fields: properties.map((property) => property.name) }),
|
|
71
63
|
});
|
|
64
|
+
const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
|
|
72
65
|
|
|
73
66
|
const projection = new ProjectionModel(jsonSchema, view.projection);
|
|
67
|
+
projection.normalizeView();
|
|
74
68
|
if (properties && projection.fields) {
|
|
75
|
-
setProperties(view, projection,
|
|
69
|
+
setProperties(view, projection, object, properties);
|
|
76
70
|
}
|
|
77
71
|
|
|
78
|
-
return { projection,
|
|
72
|
+
return { projection, object };
|
|
79
73
|
};
|
|
80
74
|
|
|
81
75
|
const setProperties = (
|
|
82
|
-
view:
|
|
76
|
+
view: View.View,
|
|
83
77
|
projection: ProjectionModel,
|
|
84
|
-
table:
|
|
78
|
+
table: Table.Table,
|
|
85
79
|
properties: TablePropertyDefinition[],
|
|
86
80
|
) => {
|
|
87
81
|
for (const property of properties) {
|
|
@@ -101,7 +95,7 @@ const setProperties = (
|
|
|
101
95
|
|
|
102
96
|
if (property.sort) {
|
|
103
97
|
const fieldId = field.id;
|
|
104
|
-
view.
|
|
98
|
+
view.sort = [{ fieldId, direction: property.sort }];
|
|
105
99
|
}
|
|
106
100
|
}
|
|
107
101
|
}
|
package/src/util/index.ts
CHANGED
package/src/util/schema.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates a narrowed schema from an original schema that only includes
|
|
@@ -20,14 +20,14 @@ export const narrowSchema = <S extends Schema.Schema.AnyNoContext>(
|
|
|
20
20
|
): Schema.Schema<unknown, unknown> | undefined => {
|
|
21
21
|
const ast = (schema as any)?.ast;
|
|
22
22
|
|
|
23
|
-
if (isTypeLiteral(ast)) {
|
|
23
|
+
if (SchemaAST.isTypeLiteral(ast)) {
|
|
24
24
|
// Filter property signatures that match any of the provided paths
|
|
25
25
|
const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
|
|
26
26
|
|
|
27
27
|
// If we found at least one matching property
|
|
28
28
|
if (propertySignatures.length > 0) {
|
|
29
29
|
// Create a new TypeLiteral with only the matching properties
|
|
30
|
-
const narrowType = new TypeLiteral(propertySignatures, []);
|
|
30
|
+
const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
|
|
31
31
|
return Schema.make(narrowType);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -26,7 +26,7 @@ const createButton = ({
|
|
|
26
26
|
disabled = false,
|
|
27
27
|
icon,
|
|
28
28
|
testId,
|
|
29
|
-
type = 'primary',
|
|
29
|
+
type: _type = 'primary',
|
|
30
30
|
}: {
|
|
31
31
|
attr: string;
|
|
32
32
|
data: Record<string, string>;
|
|
@@ -39,8 +39,7 @@ const createButton = ({
|
|
|
39
39
|
.map(([k, v]) => `${k}="${v}"`)
|
|
40
40
|
.join(' ');
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? 'disabled' : ''}><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
42
|
+
return `<button ${attr} data-testid="${testId}" class="dx-button is-6 aspect-square pli-0.5 min-bs-0" ${dataAttrs} ${disabled ? 'disabled' : ''} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
const addColumnButton = {
|
|
@@ -67,6 +66,7 @@ const columnSettingsButton = {
|
|
|
67
66
|
icon: columnSettingsButton.icon,
|
|
68
67
|
data: {
|
|
69
68
|
'data-field-id': fieldId,
|
|
69
|
+
'data-variant': 'ghost',
|
|
70
70
|
},
|
|
71
71
|
testId: 'table-column-settings-button',
|
|
72
72
|
});
|
|
@@ -130,6 +130,7 @@ const saveDraftRowButton = {
|
|
|
130
130
|
disabled,
|
|
131
131
|
data: {
|
|
132
132
|
'data-row-index': rowIndex.toString(),
|
|
133
|
+
'data-variant': 'primary',
|
|
133
134
|
},
|
|
134
135
|
testId: 'table-save-draft-row-button',
|
|
135
136
|
});
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// Core types.
|
|
6
|
+
import { accessoryHandlesPointerdownAttrs } from '@dxos/lit-grid';
|
|
7
|
+
|
|
6
8
|
export type TableControl = 'checkbox' | 'switch';
|
|
7
9
|
|
|
8
10
|
export type ControlData =
|
|
@@ -41,7 +43,7 @@ const renderInput = (
|
|
|
41
43
|
preventToggle = false,
|
|
42
44
|
testId: string,
|
|
43
45
|
) => {
|
|
44
|
-
return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}"/>`;
|
|
46
|
+
return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}" data-dx-grid-action="accessory"/>`;
|
|
45
47
|
};
|
|
46
48
|
|
|
47
49
|
export const CheckboxStory = ({
|
|
@@ -64,6 +66,7 @@ export const SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = fa
|
|
|
64
66
|
[CONTROL_IDENTIFIERS.switch]: '',
|
|
65
67
|
'data-row-index': rowIndex.toString(),
|
|
66
68
|
'data-col-index': colIndex.toString(),
|
|
69
|
+
...accessoryHandlesPointerdownAttrs,
|
|
67
70
|
};
|
|
68
71
|
|
|
69
72
|
return renderInput(BASE_CLASSES.switch, attrs, checked, disabled, true, 'table-switch');
|