@dxos/react-ui-table 0.8.4-main.422d1c7879 → 0.8.4-main.43cb759274
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/LICENSE +102 -5
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/{chunk-G5EDJPD2.mjs → chunk-X7A7G6RR.mjs} +26 -81
- package/dist/lib/browser/chunk-X7A7G6RR.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BF54SSNL.mjs → chunk-YURROGGF.mjs} +12 -15
- package/dist/lib/browser/chunk-YURROGGF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +48 -122
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -6
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/translations.mjs +36 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -1
- package/dist/lib/node-esm/{chunk-SIRDIPHZ.mjs → chunk-DLAGRBKD.mjs} +12 -15
- package/dist/lib/node-esm/chunk-DLAGRBKD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZZ3SYTIL.mjs → chunk-Q4HSBRJJ.mjs} +26 -81
- package/dist/lib/node-esm/chunk-Q4HSBRJJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +48 -122
- 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 +7 -6
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/translations.mjs +37 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +2 -1
- 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 +3 -4
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +21 -20
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +83 -82
- 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 +2 -2
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +83 -82
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +2 -1
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableToolbar.d.ts +1 -1
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +19 -19
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +4 -5
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +19 -19
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +11 -5
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +6 -6
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/signals.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts.map +1 -1
- package/dist/types/src/util/table-buttons.d.ts +20 -20
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +4 -4
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/tag.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +54 -50
- package/src/components/Table/ColumnActionsMenu.tsx +2 -1
- package/src/components/Table/ColumnSettings.tsx +2 -2
- package/src/components/Table/DynamicTable.stories.tsx +8 -7
- package/src/components/Table/DynamicTable.tsx +10 -11
- package/src/components/Table/Relations.stories.tsx +8 -6
- package/src/components/Table/RowActionsMenu.tsx +3 -2
- package/src/components/Table/Table.stories.tsx +28 -29
- package/src/components/Table/TableContent.tsx +8 -3
- package/src/components/Table/TableToolbar.tsx +2 -2
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -2
- package/src/components/TableCellEditor/FormCellEditor.tsx +6 -5
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +7 -4
- package/src/components/testing.ts +2 -7
- package/src/hooks/useProjectionModel.ts +5 -6
- package/src/hooks/useTableModel.ts +1 -1
- package/src/index.ts +0 -4
- package/src/model/table-model.test.ts +4 -9
- package/src/model/table-model.ts +13 -13
- package/src/model/table-presentation.test.ts +4 -9
- package/src/model/table-presentation.ts +5 -6
- package/src/testing/useTestTableModel.ts +4 -5
- package/src/types/Table.ts +12 -13
- package/src/util/dynamic-table.test.ts +12 -19
- package/src/util/dynamic-table.ts +19 -18
- package/dist/lib/browser/chunk-BF54SSNL.mjs.map +0 -7
- package/dist/lib/browser/chunk-G5EDJPD2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZZ3SYTIL.mjs.map +0 -7
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { View } from '@dxos/echo';
|
|
8
|
+
import { Obj, Type, View } from '@dxos/echo';
|
|
10
9
|
import { random } from '@dxos/random';
|
|
11
10
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
11
|
import { Grid, type GridEditing, defaultRowSize } from '@dxos/react-ui-grid';
|
|
@@ -14,8 +13,9 @@ import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
|
14
13
|
import { ViewModel } from '@dxos/schema';
|
|
15
14
|
import { Task } from '@dxos/types';
|
|
16
15
|
|
|
16
|
+
import { translations } from '#translations';
|
|
17
|
+
|
|
17
18
|
import { useTestTableModel } from '../../testing';
|
|
18
|
-
import { translations } from '../../translations';
|
|
19
19
|
import { Table } from '../../types';
|
|
20
20
|
import { TableCellEditor } from './TableCellEditor';
|
|
21
21
|
|
|
@@ -52,7 +52,10 @@ const meta = {
|
|
|
52
52
|
createIdentity: true,
|
|
53
53
|
createSpace: true,
|
|
54
54
|
onCreateSpace: async ({ space }) => {
|
|
55
|
-
const { view, jsonSchema } = await ViewModel.makeFromDatabase({
|
|
55
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({
|
|
56
|
+
db: space.db,
|
|
57
|
+
typename: Type.getTypename(Task.Task),
|
|
58
|
+
});
|
|
56
59
|
const table = Table.make({ view, jsonSchema });
|
|
57
60
|
space.db.add(table);
|
|
58
61
|
Array.from({ length: 10 }).forEach(() => {
|
|
@@ -6,7 +6,7 @@ import { Atom } from '@effect-atom/atom-react';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import { useEffect } from 'react';
|
|
8
8
|
|
|
9
|
-
import { Format, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN, Format, Type } from '@dxos/echo';
|
|
10
10
|
import { TypeEnum } from '@dxos/echo/internal';
|
|
11
11
|
import { setValue } from '@dxos/effect';
|
|
12
12
|
import { random } from '@dxos/random';
|
|
@@ -17,12 +17,7 @@ export const TestSchema = Schema.Struct({
|
|
|
17
17
|
age: Schema.optional(Schema.Number),
|
|
18
18
|
active: Schema.optional(Schema.Boolean),
|
|
19
19
|
netWorth: Schema.optional(Schema.Number),
|
|
20
|
-
}).pipe(
|
|
21
|
-
Type.object({
|
|
22
|
-
typename: 'com.example.type.test',
|
|
23
|
-
version: '0.1.0',
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
20
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.test', '0.1.0')));
|
|
26
21
|
|
|
27
22
|
export type TestItem = {
|
|
28
23
|
name: string;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
import { useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { Type } from '@dxos/echo';
|
|
9
9
|
import { useAsyncEffect } from '@dxos/react-ui';
|
|
10
10
|
import { ProjectionModel, createEchoChangeCallback } from '@dxos/schema';
|
|
11
11
|
|
|
@@ -21,13 +21,12 @@ export const useProjectionModel = <S extends Type.AnyEntity>(
|
|
|
21
21
|
useAsyncEffect(async () => {
|
|
22
22
|
if (schema && table) {
|
|
23
23
|
const view = await table.view.load();
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
const jsonSchema = Type.isMutable(schema) ? schema.jsonSchema : JsonSchema.toJsonSchema(schema);
|
|
24
|
+
// Use the live jsonSchema reference for reactivity.
|
|
25
|
+
const jsonSchema = schema.jsonSchema;
|
|
27
26
|
|
|
28
27
|
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
29
|
-
// Pass
|
|
30
|
-
const change = createEchoChangeCallback(view, Type.
|
|
28
|
+
// Pass the type entity only when stored, to allow schema mutations.
|
|
29
|
+
const change = createEchoChangeCallback(view, Type.getDatabase(schema) != null ? schema : undefined);
|
|
31
30
|
|
|
32
31
|
const projection = new ProjectionModel({ registry, view, baseSchema: jsonSchema, change });
|
|
33
32
|
projection.normalizeView();
|
|
@@ -44,7 +44,7 @@ export const useTableModel = <T extends TableRow = TableRow>({
|
|
|
44
44
|
...props
|
|
45
45
|
}: UseTableModelProps<T>): TableModel<T> | undefined => {
|
|
46
46
|
const registry = useContext(RegistryContext);
|
|
47
|
-
const selected = useSelected(object && Obj.
|
|
47
|
+
const selected = useSelected(object && Obj.getURI(object), 'multi');
|
|
48
48
|
const initialSelection = useMemo(() => selected, [object]);
|
|
49
49
|
|
|
50
50
|
const [model, setModel] = useState<TableModel<T>>();
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Registry } from '@effect-atom/atom-react';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import { Filter, JsonSchema, Query, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN, Filter, JsonSchema, Query, Type } from '@dxos/echo';
|
|
10
10
|
import { createEchoSchema } from '@dxos/echo/testing';
|
|
11
11
|
import { ProjectionModel, ViewModel, createDirectChangeCallback } from '@dxos/schema';
|
|
12
12
|
|
|
@@ -118,15 +118,10 @@ describe('TableModel', () => {
|
|
|
118
118
|
const Test = Schema.Struct({
|
|
119
119
|
title: Schema.String,
|
|
120
120
|
completed: Schema.Boolean,
|
|
121
|
-
}).pipe(
|
|
122
|
-
Type.object({
|
|
123
|
-
typename: 'com.example.type.test',
|
|
124
|
-
version: '0.1.0',
|
|
125
|
-
}),
|
|
126
|
-
);
|
|
121
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.test', '0.1.0')));
|
|
127
122
|
|
|
128
123
|
const createTableModel = (registry: Registry.Registry, props: Partial<TableModelProps> = {}): TableModel => {
|
|
129
|
-
const schema = createEchoSchema(Test);
|
|
124
|
+
const schema = createEchoSchema(Type.getSchema(Test));
|
|
130
125
|
const view = ViewModel.make({
|
|
131
126
|
query: Query.select(Filter.type(schema)),
|
|
132
127
|
jsonSchema: schema.jsonSchema,
|
|
@@ -136,7 +131,7 @@ const createTableModel = (registry: Registry.Registry, props: Partial<TableModel
|
|
|
136
131
|
registry,
|
|
137
132
|
view,
|
|
138
133
|
baseSchema: schema.jsonSchema,
|
|
139
|
-
change: createDirectChangeCallback(view.projection, JsonSchema.toJsonSchema(schema)),
|
|
134
|
+
change: createDirectChangeCallback(view.projection, JsonSchema.toJsonSchema(Type.getSchema(schema))),
|
|
140
135
|
});
|
|
141
136
|
projection.normalizeView();
|
|
142
137
|
return new TableModel({
|
package/src/model/table-model.ts
CHANGED
|
@@ -5,13 +5,12 @@
|
|
|
5
5
|
import { Atom, type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
|
|
7
7
|
import { Resource } from '@dxos/context';
|
|
8
|
-
import { type Database, Format, Obj, Order, Query, type QueryAST, Ref } from '@dxos/echo';
|
|
9
|
-
import { type View } from '@dxos/echo';
|
|
8
|
+
import { type Database, Format, Obj, Order, Query, type QueryAST, Ref, Type, type View } from '@dxos/echo';
|
|
10
9
|
import { type JsonProp, type JsonSchemaType, type Mutable, toEffectSchema } from '@dxos/echo/internal';
|
|
11
10
|
import { getSnapshot } from '@dxos/echo/internal';
|
|
12
11
|
import { getValue, setValue } from '@dxos/effect';
|
|
13
12
|
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import {
|
|
13
|
+
import { EntityId } from '@dxos/keys';
|
|
15
14
|
import { type Label } from '@dxos/react-ui';
|
|
16
15
|
import { formatForEditing, parseValue } from '@dxos/react-ui-form';
|
|
17
16
|
import {
|
|
@@ -38,7 +37,7 @@ export type FieldSortType = {
|
|
|
38
37
|
import { type SelectionMode, SelectionModel } from './selection-model';
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
|
-
* Callback type for wrapping mutations in Obj.
|
|
40
|
+
* Callback type for wrapping mutations in Obj.update().
|
|
42
41
|
* Contains separate callbacks for table object and row mutations.
|
|
43
42
|
*/
|
|
44
43
|
export type TableChangeCallback<T extends TableRow> = {
|
|
@@ -53,10 +52,10 @@ export type TableChangeCallback<T extends TableRow> = {
|
|
|
53
52
|
* Use this when the table and rows are stored in the ECHO database.
|
|
54
53
|
*/
|
|
55
54
|
export const createEchoChangeCallback = <T extends TableRow>(table: Table.Table): TableChangeCallback<T> => ({
|
|
56
|
-
table: (mutate) => Obj.
|
|
55
|
+
table: (mutate) => Obj.update(table, (table) => mutate(table as unknown as Table.Table)),
|
|
57
56
|
row: (row, mutate) => {
|
|
58
57
|
if (Obj.isObject(row)) {
|
|
59
|
-
Obj.
|
|
58
|
+
Obj.update(row, (row) => mutate(row as T));
|
|
60
59
|
} else {
|
|
61
60
|
mutate(row);
|
|
62
61
|
}
|
|
@@ -112,7 +111,7 @@ export type TableModelProps<T extends TableRow = TableRow> = {
|
|
|
112
111
|
projection: ProjectionModel;
|
|
113
112
|
db?: Database.Database;
|
|
114
113
|
/**
|
|
115
|
-
* Callbacks to wrap mutations in Obj.
|
|
114
|
+
* Callbacks to wrap mutations in Obj.update().
|
|
116
115
|
* Use createEchoChangeCallback() for ECHO-backed objects or createDirectChangeCallback() for plain objects.
|
|
117
116
|
*/
|
|
118
117
|
change?: TableChangeCallback<T>;
|
|
@@ -300,7 +299,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
300
299
|
}
|
|
301
300
|
|
|
302
301
|
public get id(): string {
|
|
303
|
-
return Obj.
|
|
302
|
+
return Obj.getURI(this._object);
|
|
304
303
|
}
|
|
305
304
|
|
|
306
305
|
public get view(): View.View {
|
|
@@ -524,7 +523,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
524
523
|
}
|
|
525
524
|
|
|
526
525
|
// NOTE(ZaymonFC): This is initialized with id because it's required in all schemata?
|
|
527
|
-
const draftData = { id:
|
|
526
|
+
const draftData = { id: EntityId.random() } as any as T;
|
|
528
527
|
const validationErrors = this.validateDraftRowData(draftData);
|
|
529
528
|
|
|
530
529
|
const draftRow: DraftRow<T> = {
|
|
@@ -695,8 +694,9 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
695
694
|
const snapshot = { ...getSnapshot(currentRow) };
|
|
696
695
|
setValue(snapshot, field.path, transformedValue);
|
|
697
696
|
|
|
698
|
-
const
|
|
699
|
-
invariant(
|
|
697
|
+
const type = Obj.getType(currentRow as unknown as Obj.Unknown);
|
|
698
|
+
invariant(type);
|
|
699
|
+
const schema = Type.getSchema(type);
|
|
700
700
|
|
|
701
701
|
const validationResult = validateSchema(schema, snapshot);
|
|
702
702
|
if (validationResult && validationResult.length > 0) {
|
|
@@ -894,13 +894,13 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
|
|
|
894
894
|
if (field) {
|
|
895
895
|
// Persist sort to view.query.ast
|
|
896
896
|
const newQuery = baseQuery.orderBy(Order.property<any>(field.path as string, inMemorySort.direction));
|
|
897
|
-
Obj.
|
|
897
|
+
Obj.update(view, (view) => {
|
|
898
898
|
view.query.ast = newQuery.ast as Mutable<typeof newQuery.ast>;
|
|
899
899
|
});
|
|
900
900
|
}
|
|
901
901
|
} else {
|
|
902
902
|
// Clear sort from view.query.ast
|
|
903
|
-
Obj.
|
|
903
|
+
Obj.update(view, (view) => {
|
|
904
904
|
view.query.ast = baseQuery.ast as Mutable<typeof baseQuery.ast>;
|
|
905
905
|
});
|
|
906
906
|
}
|
|
@@ -6,7 +6,7 @@ import { Registry } from '@effect-atom/atom-react';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import { Filter, JsonSchema, Query, Type } from '@dxos/echo';
|
|
9
|
+
import { DXN, Filter, JsonSchema, Query, Type } from '@dxos/echo';
|
|
10
10
|
import { createEchoSchema } from '@dxos/echo/testing';
|
|
11
11
|
import { ProjectionModel, ViewModel, createDirectChangeCallback } from '@dxos/schema';
|
|
12
12
|
|
|
@@ -89,15 +89,10 @@ describe('TablePresentation', () => {
|
|
|
89
89
|
const Test = Schema.Struct({
|
|
90
90
|
title: Schema.String,
|
|
91
91
|
count: Schema.Number,
|
|
92
|
-
}).pipe(
|
|
93
|
-
Type.object({
|
|
94
|
-
typename: 'com.example.type.test',
|
|
95
|
-
version: '0.1.0',
|
|
96
|
-
}),
|
|
97
|
-
);
|
|
92
|
+
}).pipe(Type.makeObject(DXN.make('com.example.type.test', '0.1.0')));
|
|
98
93
|
|
|
99
94
|
const createTableModel = (registry: Registry.Registry, props: Partial<TableModelProps> = {}): TableModel => {
|
|
100
|
-
const schema = createEchoSchema(Test);
|
|
95
|
+
const schema = createEchoSchema(Type.getSchema(Test));
|
|
101
96
|
const view = ViewModel.make({
|
|
102
97
|
query: Query.select(Filter.type(schema)),
|
|
103
98
|
jsonSchema: schema.jsonSchema,
|
|
@@ -107,7 +102,7 @@ const createTableModel = (registry: Registry.Registry, props: Partial<TableModel
|
|
|
107
102
|
registry,
|
|
108
103
|
view,
|
|
109
104
|
baseSchema: schema.jsonSchema,
|
|
110
|
-
change: createDirectChangeCallback(view.projection, JsonSchema.toJsonSchema(schema)),
|
|
105
|
+
change: createDirectChangeCallback(view.projection, JsonSchema.toJsonSchema(Type.getSchema(schema))),
|
|
111
106
|
});
|
|
112
107
|
projection.normalizeView();
|
|
113
108
|
return new TableModel({ registry, object, projection, ...props });
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import { Atom, type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
import * as Predicate from 'effect/Predicate';
|
|
7
7
|
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import { type View } from '@dxos/echo';
|
|
8
|
+
import { Obj, type View } from '@dxos/echo';
|
|
10
9
|
import { Format, TypeEnum, getValue } from '@dxos/echo/internal';
|
|
11
10
|
import { cellClassesForFieldType, formatForDisplay } from '@dxos/react-ui-form';
|
|
12
11
|
import {
|
|
@@ -209,8 +208,8 @@ export class TablePresentation<T extends TableRow = TableRow> {
|
|
|
209
208
|
if (props.format === Format.TypeFormat.Ref && props.referenceSchema) {
|
|
210
209
|
const targetObj = getValue(obj, field.path)?.target;
|
|
211
210
|
if (targetObj) {
|
|
212
|
-
const
|
|
213
|
-
cell.accessoryHtml = `<div role="none" class="absolute end-0 inset-y-0 p-(--dx-grid-cell-content-padding-block)"><dx-anchor
|
|
211
|
+
const uri = Obj.getURI(targetObj);
|
|
212
|
+
cell.accessoryHtml = `<div role="none" class="absolute end-0 inset-y-0 p-(--dx-grid-cell-content-padding-block)"><dx-anchor uri=${uri} class="dx-button w-6 aspect-square min-h-0" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor></div>`;
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
|
|
@@ -473,8 +472,8 @@ export const cellClassesForRowSelection = (selected: boolean, selectionMode: Sel
|
|
|
473
472
|
|
|
474
473
|
switch (selectionMode) {
|
|
475
474
|
case 'single':
|
|
476
|
-
return ['dx-grid__cell--no-focus-unfurl
|
|
475
|
+
return ['dx-grid__cell--no-focus-unfurl bg-current-surface! hover:bg-hover-surface cursor-pointer!'];
|
|
477
476
|
case 'multiple':
|
|
478
|
-
return ['
|
|
477
|
+
return ['bg-grid-cell-selected!'];
|
|
479
478
|
}
|
|
480
479
|
};
|
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
6
|
import { type RefObject, useCallback, useContext, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
|
-
import { type Database,
|
|
9
|
-
import { isMutable } from '@dxos/echo/internal';
|
|
8
|
+
import { type Database, Filter, Type } from '@dxos/echo';
|
|
10
9
|
import { random } from '@dxos/random';
|
|
11
|
-
import {
|
|
10
|
+
import { useQuery, useType } from '@dxos/react-client/echo';
|
|
12
11
|
import { useClientStory } from '@dxos/react-client/testing';
|
|
13
12
|
import { useGlobalFilteredObjects } from '@dxos/react-ui-search';
|
|
14
13
|
import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
@@ -46,14 +45,14 @@ export const useTestTableModel = <T extends Type.AnyObj = Type.AnyObj>(): TestTa
|
|
|
46
45
|
const tables = useQuery(space?.db, Filter.type(Table.Table));
|
|
47
46
|
const table = tables.at(0);
|
|
48
47
|
const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
|
|
49
|
-
const schema =
|
|
48
|
+
const schema = useType<T>(space?.db, typename);
|
|
50
49
|
const projection = useProjectionModel(schema, table, registry);
|
|
51
50
|
|
|
52
51
|
const features = useMemo(
|
|
53
52
|
() => ({
|
|
54
53
|
selection: { enabled: true, mode: 'multiple' as const },
|
|
55
54
|
dataEditable: true,
|
|
56
|
-
schemaEditable: schema &&
|
|
55
|
+
schemaEditable: schema != null && Type.getDatabase(schema) != null,
|
|
57
56
|
}),
|
|
58
57
|
[schema],
|
|
59
58
|
);
|
package/src/types/Table.ts
CHANGED
|
@@ -6,12 +6,15 @@ import * as Match from 'effect/Match';
|
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// QueryAST is referenced indirectly through `Type.InstanceType<typeof TableSchema>`
|
|
10
|
+
// (Ref.Ref(View.View) → View.View → QueryAST.Query) in the emitted .d.ts; the
|
|
11
|
+
// namespace import keeps the inferred types portable.
|
|
12
|
+
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
13
|
+
import { DXN, Annotation, JsonSchema, Obj, QueryAST, Ref, Type, View } from '@dxos/echo';
|
|
11
14
|
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
12
15
|
import { ViewAnnotation } from '@dxos/schema';
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
const TableSchema = Schema.Struct({
|
|
15
18
|
name: Schema.String.pipe(Schema.optional),
|
|
16
19
|
|
|
17
20
|
view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
@@ -22,19 +25,15 @@ export const Table = Schema.Struct({
|
|
|
22
25
|
value: Schema.Number,
|
|
23
26
|
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
24
27
|
}).pipe(
|
|
25
|
-
Type.object({
|
|
26
|
-
typename: 'org.dxos.type.table',
|
|
27
|
-
version: '0.1.0',
|
|
28
|
-
}),
|
|
29
28
|
LabelAnnotation.set(['name']),
|
|
30
|
-
ViewAnnotation.set(
|
|
31
|
-
Annotation.IconAnnotation.set({
|
|
32
|
-
|
|
33
|
-
hue: 'green',
|
|
34
|
-
}),
|
|
29
|
+
ViewAnnotation.set(['view']),
|
|
30
|
+
Annotation.IconAnnotation.set({ icon: 'ph--table--regular', hue: 'green' }),
|
|
31
|
+
Type.makeObject(DXN.make('org.dxos.type.table', '0.1.0')),
|
|
35
32
|
);
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
// TODO(wittjosiah): Try to clean up this type inference.
|
|
35
|
+
export interface Table extends Type.InstanceType<typeof TableSchema> {}
|
|
36
|
+
export const Table = TableSchema;
|
|
38
37
|
|
|
39
38
|
type MakeProps = {
|
|
40
39
|
name?: string;
|
|
@@ -11,13 +11,14 @@ import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '.
|
|
|
11
11
|
|
|
12
12
|
describe('makeDynamicTable', () => {
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Confirms makeDynamicTable + setProperties (title) works with plain objects.
|
|
14
|
+
* Builds the Type entity from a JSON schema, then makes the table.
|
|
15
|
+
* Confirms makeDynamicTable + setProperties (title) works for the jsonSchema path.
|
|
17
16
|
*/
|
|
18
|
-
test('makeDynamicTable
|
|
17
|
+
test('makeDynamicTable from a jsonSchema with properties with title does not throw', () => {
|
|
19
18
|
const registry = Registry.make();
|
|
20
19
|
const jsonSchema = {
|
|
20
|
+
typename: 'com.example.type.dynamicTablePlain',
|
|
21
|
+
version: '0.1.0',
|
|
21
22
|
type: 'object' as const,
|
|
22
23
|
properties: {
|
|
23
24
|
id: { type: 'string' as const },
|
|
@@ -31,11 +32,8 @@ describe('makeDynamicTable', () => {
|
|
|
31
32
|
];
|
|
32
33
|
|
|
33
34
|
expect(() => {
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
jsonSchema,
|
|
37
|
-
properties,
|
|
38
|
-
});
|
|
35
|
+
const { type } = getBaseSchema({ jsonSchema });
|
|
36
|
+
const { projection, object } = makeDynamicTable({ registry, type, properties });
|
|
39
37
|
expect(projection).toBeDefined();
|
|
40
38
|
expect(object).toBeDefined();
|
|
41
39
|
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
@@ -43,25 +41,20 @@ describe('makeDynamicTable', () => {
|
|
|
43
41
|
});
|
|
44
42
|
|
|
45
43
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* cloned schema. This test ensures that flow does not throw.
|
|
44
|
+
* Builds the Type entity from property definitions, then makes the table.
|
|
45
|
+
* Confirms makeDynamicTable + setProperties (title) works for the property-definitions path.
|
|
49
46
|
*/
|
|
50
|
-
test('makeDynamicTable
|
|
47
|
+
test('makeDynamicTable from getBaseSchema(typename, properties) with properties with title does not throw', () => {
|
|
51
48
|
const registry = Registry.make();
|
|
52
49
|
const typename = 'com.example.type.dynamicTableTest';
|
|
53
50
|
const properties: TablePropertyDefinition[] = [
|
|
54
51
|
{ name: 'id', format: Format.TypeFormat.String },
|
|
55
52
|
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
56
53
|
];
|
|
57
|
-
const { jsonSchema } = getBaseSchema({ typename, properties });
|
|
58
54
|
|
|
59
55
|
expect(() => {
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
jsonSchema,
|
|
63
|
-
properties,
|
|
64
|
-
});
|
|
56
|
+
const { type } = getBaseSchema({ typename, properties });
|
|
57
|
+
const { projection, object } = makeDynamicTable({ registry, type, properties });
|
|
65
58
|
expect(projection).toBeDefined();
|
|
66
59
|
expect(object).toBeDefined();
|
|
67
60
|
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import { type Registry } from '@effect-atom/atom-react';
|
|
6
6
|
import type * as Types from 'effect/Types';
|
|
7
7
|
|
|
8
|
-
import { Filter, JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type } from '@dxos/echo';
|
|
9
|
-
import { type View } from '@dxos/echo';
|
|
8
|
+
import { Filter, type JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type, type View } from '@dxos/echo';
|
|
10
9
|
import {
|
|
11
10
|
ProjectionModel,
|
|
12
11
|
type SchemaPropertyDefinition,
|
|
13
12
|
ViewModel,
|
|
14
13
|
createEchoChangeCallback,
|
|
14
|
+
getSchemaFromJsonSchema,
|
|
15
15
|
getSchemaFromPropertyDefinitions,
|
|
16
16
|
} from '@dxos/schema';
|
|
17
17
|
|
|
@@ -31,40 +31,41 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
|
|
|
31
31
|
*/
|
|
32
32
|
// TODO(burdon): Remove variance.
|
|
33
33
|
export const getBaseSchema = ({
|
|
34
|
-
|
|
34
|
+
type,
|
|
35
35
|
typename,
|
|
36
36
|
properties,
|
|
37
37
|
jsonSchema,
|
|
38
38
|
}: {
|
|
39
|
-
|
|
39
|
+
type?: Type.AnyEntity;
|
|
40
40
|
typename?: string;
|
|
41
41
|
properties?: TablePropertyDefinition[];
|
|
42
42
|
jsonSchema?: Types.DeepMutable<JsonSchema.JsonSchema>;
|
|
43
|
-
}): { typename: string;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} else if (typename && jsonSchema) {
|
|
50
|
-
return { typename, jsonSchema };
|
|
51
|
-
} else {
|
|
43
|
+
}): { typename: string; type: Type.AnyEntity } => {
|
|
44
|
+
const resolved =
|
|
45
|
+
typename && properties
|
|
46
|
+
? getSchemaFromPropertyDefinitions(typename, properties)
|
|
47
|
+
: (type ?? (jsonSchema ? getSchemaFromJsonSchema(jsonSchema, typename) : undefined));
|
|
48
|
+
if (!resolved) {
|
|
52
49
|
throw new Error('invalid properties');
|
|
53
50
|
}
|
|
51
|
+
|
|
52
|
+
return { typename: Type.getTypename(resolved)!, type: resolved };
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export const makeDynamicTable = ({
|
|
57
56
|
registry,
|
|
58
|
-
|
|
57
|
+
type,
|
|
59
58
|
properties,
|
|
60
59
|
}: {
|
|
61
60
|
registry: Registry.Registry;
|
|
62
|
-
|
|
61
|
+
type: Type.AnyEntity;
|
|
63
62
|
properties?: TablePropertyDefinition[];
|
|
64
63
|
}): { projection: ProjectionModel; object: Table.Table } => {
|
|
64
|
+
const jsonSchema = type.jsonSchema;
|
|
65
65
|
const view = ViewModel.make({
|
|
66
66
|
query: Query.select(Filter.everything()),
|
|
67
67
|
jsonSchema,
|
|
68
|
+
type,
|
|
68
69
|
...(properties && { fields: properties.map((property) => property.name) }),
|
|
69
70
|
});
|
|
70
71
|
const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
|
|
@@ -73,7 +74,7 @@ export const makeDynamicTable = ({
|
|
|
73
74
|
registry,
|
|
74
75
|
view,
|
|
75
76
|
baseSchema: jsonSchema,
|
|
76
|
-
change: createEchoChangeCallback(view,
|
|
77
|
+
change: createEchoChangeCallback(view, type),
|
|
77
78
|
});
|
|
78
79
|
projection.normalizeView();
|
|
79
80
|
if (properties && projection.getFields()) {
|
|
@@ -93,7 +94,7 @@ const setProperties = (
|
|
|
93
94
|
const field = projection.getFields().find((field) => field.path === property.name);
|
|
94
95
|
if (field) {
|
|
95
96
|
if (property.size !== undefined) {
|
|
96
|
-
Obj.
|
|
97
|
+
Obj.update(table, (table) => {
|
|
97
98
|
table.sizes[field.path] = property.size!;
|
|
98
99
|
});
|
|
99
100
|
}
|
|
@@ -111,7 +112,7 @@ const setProperties = (
|
|
|
111
112
|
const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
|
|
112
113
|
// Use any type parameter since we're working with dynamic field paths
|
|
113
114
|
const newQuery = currentQuery.orderBy(Order.property<any>(field.path as string, property.sort));
|
|
114
|
-
Obj.
|
|
115
|
+
Obj.update(view, (view) => {
|
|
115
116
|
// Type assertion needed because Query AST types have some variance issues.
|
|
116
117
|
view.query.ast = newQuery.ast as typeof view.query.ast;
|
|
117
118
|
});
|
|
@@ -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';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';\nimport { View } from '@dxos/echo';\nimport { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';\nimport { ViewAnnotation } from '@dxos/schema';\n\nexport const Table = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n\n view: Ref.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.object({\n typename: 'org.dxos.type.table',\n version: '0.1.0',\n }),\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(true),\n Annotation.IconAnnotation.set({\n icon: 'ph--table--regular',\n hue: 'green',\n }),\n);\n\nexport interface Table extends Schema.Schema.Type<typeof Table> {}\n\ntype MakeProps = {\n name?: string;\n sizes?: Record<string, number>;\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 } as Obj.MakeProps<typeof Table>);\n\n // Preset sizes.\n if (jsonSchema) {\n const schema = JsonSchema.toEffectSchema(jsonSchema);\n const properties = SchemaAST.getPropertySignatures(schema.ast);\n for (const property of properties) {\n const name = property.name.toString() as JsonPath;\n if (sizes?.[name]) {\n table.sizes[name] = sizes[name];\n continue;\n }\n\n Match.type<SchemaAST.AST>().pipe(\n Match.when({ _tag: 'BooleanKeyword' }, () => {\n table.sizes[name] = 100;\n }),\n Match.when({ _tag: 'NumberKeyword' }, () => {\n table.sizes[name] = 100;\n }),\n Match.orElse(() => {\n // Noop.\n }),\n )(property.type);\n }\n }\n\n return table;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAAA;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAE3B,SAASC,YAAYC,YAAYC,KAAKC,KAAKC,YAAY;AACvD,SAASC,YAAY;AACrB,SAASC,qBAAyDC,uBAAuB;AACzF,SAASC,sBAAsB;AAExB,IAAMC,QAAeC,cAAO;EACjCC,MAAaC,cAAOC,KAAYC,eAAQ;EAExCC,MAAMC,IAAIA,IAAIC,KAAKA,IAAI,EAAEJ,KAAKK,oBAAoBC,IAAI,KAAA,CAAA;EAEtDC,OAAcC,cAAO;;IAEnBC,KAAYV;IACZW,OAAcC;EAChB,CAAA,EAAGX,KAAYY,gBAASP,oBAAoBC,IAAI,KAAA,CAAA;AAClD,CAAA,EAAGN,KACDa,KAAKC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,gBAAgBX,IAAI;EAAC;CAAO,GAC5BY,eAAeZ,IAAI,IAAA,GACnBa,WAAWC,eAAed,IAAI;EAC5Be,MAAM;EACNC,KAAK;AACP,CAAA,CAAA;AAgBK,IAAMC,OAAO,CAAC,EAAEzB,MAAMS,QAAQ,CAAC,GAAGL,MAAMsB,WAAU,MAAa;AACpE,QAAMC,QAAQC,IAAIH,KAAK3B,OAAO;IAAEE;IAAMI,MAAMC,IAAIoB,KAAKrB,IAAAA;IAAOK;EAAM,CAAA;AAGlE,MAAIiB,YAAY;AACd,UAAMG,SAASC,WAAWC,eAAeL,UAAAA;AACzC,UAAMM,aAAuBC,gCAAsBJ,OAAOK,GAAG;AAC7D,eAAWC,YAAYH,YAAY;AACjC,YAAMhC,QAAOmC,SAASnC,KAAKoC,SAAQ;AACnC,UAAI3B,QAAQT,KAAAA,GAAO;AACjB2B,cAAMlB,MAAMT,KAAAA,IAAQS,MAAMT,KAAAA;AAC1B;MACF;AAEAqC,MAAMC,WAAI,EAAkBpC,KACpBqC,WAAK;QAAEC,MAAM;MAAiB,GAAG,MAAA;AACrCb,cAAMlB,MAAMT,KAAAA,IAAQ;MACtB,CAAA,GACMuC,WAAK;QAAEC,MAAM;MAAgB,GAAG,MAAA;AACpCb,cAAMlB,MAAMT,KAAAA,IAAQ;MACtB,CAAA,GACMyC,aAAO,MAAA;MAEb,CAAA,CAAA,EACAN,SAASG,IAAI;IACjB;EACF;AAEA,SAAOX;AACT;",
|
|
6
|
-
"names": ["Match", "Schema", "SchemaAST", "Annotation", "JsonSchema", "Obj", "Ref", "Type", "View", "FormInputAnnotation", "LabelAnnotation", "ViewAnnotation", "Table", "Struct", "name", "String", "pipe", "optional", "view", "Ref", "View", "FormInputAnnotation", "set", "sizes", "Record", "key", "value", "Number", "mutable", "Type", "object", "typename", "version", "LabelAnnotation", "ViewAnnotation", "Annotation", "IconAnnotation", "icon", "hue", "make", "jsonSchema", "table", "Obj", "schema", "JsonSchema", "toEffectSchema", "properties", "getPropertySignatures", "ast", "property", "toString", "Match", "type", "when", "_tag", "orElse"]
|
|
7
|
-
}
|