@dxos/react-ui-table 0.8.3 → 0.8.4-main.c1de068

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/lib/browser/chunk-5XLSHLOG.mjs +1751 -0
  2. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-L2LSB6KV.mjs +18 -0
  4. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +240 -1639
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +121 -0
  9. package/dist/lib/browser/testing/index.mjs.map +7 -0
  10. package/dist/lib/browser/types/index.mjs +3 -5
  11. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +20 -0
  12. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs +1752 -0
  14. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +240 -1639
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +122 -0
  19. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/types/index.mjs +3 -5
  21. package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -1
  22. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
  24. package/dist/types/src/components/Table/DynamicTable.d.ts +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  26. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Table.stories.d.ts +1 -1
  30. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/relations.stories.d.ts +1 -1
  32. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
  33. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +2 -1
  34. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  35. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +2 -1
  36. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -2
  38. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +1 -1
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  41. package/dist/types/src/components/testing.d.ts +3 -40
  42. package/dist/types/src/components/testing.d.ts.map +1 -1
  43. package/dist/types/src/hooks/index.d.ts +1 -0
  44. package/dist/types/src/hooks/index.d.ts.map +1 -1
  45. package/dist/types/src/hooks/useAddRow.d.ts +13 -0
  46. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -0
  47. package/dist/types/src/hooks/useTableModel.d.ts +7 -6
  48. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  49. package/dist/types/src/index.d.ts +1 -2
  50. package/dist/types/src/index.d.ts.map +1 -1
  51. package/dist/types/src/model/selection-model.d.ts +2 -1
  52. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  53. package/dist/types/src/model/table-model.d.ts +56 -20
  54. package/dist/types/src/model/table-model.d.ts.map +1 -1
  55. package/dist/types/src/model/table-presentation.d.ts +8 -0
  56. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  57. package/dist/types/src/model/table-sorting.d.ts +2 -2
  58. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  59. package/dist/types/src/playwright/playwright.config.d.ts +3 -0
  60. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -0
  61. package/dist/types/src/testing/index.d.ts +2 -0
  62. package/dist/types/src/testing/index.d.ts.map +1 -0
  63. package/dist/types/src/testing/useTestTableModel.d.ts +41 -0
  64. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
  65. package/dist/types/src/translations.d.ts +3 -4
  66. package/dist/types/src/translations.d.ts.map +1 -1
  67. package/dist/types/src/types/index.d.ts +1 -1
  68. package/dist/types/src/types/index.d.ts.map +1 -1
  69. package/dist/types/src/types/schema.d.ts +8 -0
  70. package/dist/types/src/types/schema.d.ts.map +1 -0
  71. package/dist/types/src/util/dynamic-table.d.ts +3 -4
  72. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  73. package/dist/types/src/util/table-buttons.d.ts +15 -1
  74. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  75. package/dist/types/src/util/table.d.ts +8 -11
  76. package/dist/types/src/util/table.d.ts.map +1 -1
  77. package/dist/types/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +48 -40
  79. package/src/components/Table/ColumnSettings.tsx +14 -10
  80. package/src/components/Table/CreateRefPanel.tsx +5 -3
  81. package/src/components/Table/DynamicTable.stories.tsx +2 -2
  82. package/src/components/Table/DynamicTable.tsx +13 -7
  83. package/src/components/Table/Table.stories.tsx +104 -148
  84. package/src/components/Table/Table.tsx +50 -32
  85. package/src/components/Table/relations.stories.tsx +27 -35
  86. package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -1
  87. package/src/components/TableCellEditor/FormCellEditor.tsx +30 -21
  88. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +24 -28
  89. package/src/components/TableCellEditor/TableCellEditor.tsx +79 -21
  90. package/src/components/testing.ts +7 -24
  91. package/src/hooks/index.ts +1 -0
  92. package/src/hooks/useAddRow.ts +36 -0
  93. package/src/hooks/useTableModel.ts +20 -16
  94. package/src/index.ts +1 -2
  95. package/src/model/selection-model.ts +4 -2
  96. package/src/model/table-model.test.ts +7 -8
  97. package/src/model/table-model.ts +267 -78
  98. package/src/model/table-presentation.test.ts +6 -7
  99. package/src/model/table-presentation.ts +215 -132
  100. package/src/model/table-sorting.ts +9 -9
  101. package/src/playwright/playwright.config.ts +17 -0
  102. package/src/playwright/smoke.spec.ts +21 -20
  103. package/src/testing/index.ts +5 -0
  104. package/src/testing/useTestTableModel.ts +122 -0
  105. package/src/translations.ts +5 -3
  106. package/src/types/index.ts +2 -2
  107. package/src/types/schema.ts +16 -0
  108. package/src/util/dynamic-table.ts +19 -17
  109. package/src/util/table-buttons.ts +24 -1
  110. package/src/util/table.ts +33 -111
  111. package/dist/lib/browser/chunk-TL7CKQQV.mjs +0 -27
  112. package/dist/lib/browser/chunk-TL7CKQQV.mjs.map +0 -7
  113. package/dist/lib/node/chunk-O2VPBNS5.cjs +0 -50
  114. package/dist/lib/node/chunk-O2VPBNS5.cjs.map +0 -7
  115. package/dist/lib/node/index.cjs +0 -2739
  116. package/dist/lib/node/index.cjs.map +0 -7
  117. package/dist/lib/node/meta.json +0 -1
  118. package/dist/lib/node/types/index.cjs +0 -31
  119. package/dist/lib/node/types/index.cjs.map +0 -7
  120. package/dist/lib/node-esm/chunk-GBT6GD4G.mjs +0 -29
  121. package/dist/lib/node-esm/chunk-GBT6GD4G.mjs.map +0 -7
  122. package/dist/types/src/types/table.d.ts +0 -56
  123. package/dist/types/src/types/table.d.ts.map +0 -1
  124. package/src/playwright/playwright.config.cts +0 -18
  125. package/src/types/table.ts +0 -27
@@ -0,0 +1,122 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { useCallback, useMemo, useRef } from 'react';
6
+
7
+ import { isMutable, toJsonSchema } from '@dxos/echo-schema';
8
+ import { useGlobalFilteredObjects } from '@dxos/plugin-search';
9
+ import { faker } from '@dxos/random';
10
+ import { useClient } from '@dxos/react-client';
11
+ import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
12
+ import { useClientProvider } from '@dxos/react-client/testing';
13
+ import { DataType, ProjectionModel } from '@dxos/schema';
14
+
15
+ import { type TableController } from '../components';
16
+ import { useTableModel, useAddRow } from '../hooks';
17
+ import { TablePresentation } from '../model';
18
+
19
+ faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
20
+
21
+ /**
22
+ * Custom hook to create and manage a test table model for storybook demonstrations.
23
+ * Provides table data, schema, and handlers for table operations.
24
+ */
25
+ export const useTestTableModel = () => {
26
+ const client = useClient();
27
+ const { space } = useClientProvider();
28
+
29
+ const views = useQuery(space, Filter.type(DataType.View));
30
+ const view = useMemo(() => views.at(0), [views]);
31
+ const schema = useSchema(client, space, view?.query.typename);
32
+ const jsonSchema = useMemo(() => (schema ? toJsonSchema(schema) : undefined), [schema]);
33
+
34
+ const projection = useMemo(() => {
35
+ if (schema && view?.projection) {
36
+ return new ProjectionModel(toJsonSchema(schema), view.projection);
37
+ }
38
+ }, [schema, view?.projection]);
39
+
40
+ const features = useMemo(
41
+ () => ({
42
+ selection: { enabled: true, mode: 'multiple' as const },
43
+ dataEditable: true,
44
+ schemaEditable: schema && isMutable(schema),
45
+ }),
46
+ [schema],
47
+ );
48
+
49
+ const objects = useQuery(space, schema ? Filter.type(schema) : Filter.nothing());
50
+ const filteredObjects = useGlobalFilteredObjects(objects);
51
+
52
+ const tableRef = useRef<TableController>(null);
53
+ const handleCellUpdate = useCallback((cell: any) => {
54
+ tableRef.current?.update?.(cell);
55
+ }, []);
56
+
57
+ const handleRowOrderChange = useCallback(() => {
58
+ tableRef.current?.update?.();
59
+ }, []);
60
+
61
+ const addRow = useAddRow({ space, schema });
62
+
63
+ const handleDeleteRows = useCallback(
64
+ (_: number, objects: any[]) => {
65
+ for (const object of objects) {
66
+ space?.db.remove(object);
67
+ }
68
+ },
69
+ [space],
70
+ );
71
+
72
+ const handleDeleteColumn = useCallback(
73
+ (fieldId: string) => {
74
+ if (projection) {
75
+ projection.deleteFieldProjection(fieldId);
76
+ }
77
+ },
78
+ [projection],
79
+ );
80
+
81
+ const model = useTableModel({
82
+ view,
83
+ schema: jsonSchema,
84
+ projection,
85
+ features,
86
+ rows: filteredObjects,
87
+ onInsertRow: addRow,
88
+ onDeleteRows: handleDeleteRows,
89
+ onDeleteColumn: handleDeleteColumn,
90
+ onCellUpdate: handleCellUpdate,
91
+ onRowOrderChange: handleRowOrderChange,
92
+ });
93
+
94
+ const handleInsertRow = useCallback(() => {
95
+ model?.insertRow();
96
+ }, [model]);
97
+
98
+ const handleSaveView = useCallback(() => {
99
+ model?.saveView();
100
+ }, [model]);
101
+
102
+ const presentation = useMemo(() => {
103
+ if (model) {
104
+ return new TablePresentation(model);
105
+ }
106
+ }, [model]);
107
+
108
+ return {
109
+ schema,
110
+ view,
111
+ projection,
112
+ tableRef,
113
+ model,
114
+ presentation,
115
+ space,
116
+ client,
117
+ handleInsertRow,
118
+ handleSaveView,
119
+ handleDeleteRows,
120
+ handleDeleteColumn,
121
+ };
122
+ };
@@ -2,9 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- export const translationKey = 'table';
5
+ import { type Resource } from '@dxos/react-ui';
6
6
 
7
- export default [
7
+ export const translationKey = 'react-ui-table';
8
+
9
+ export const translations = [
8
10
  {
9
11
  'en-US': {
10
12
  [translationKey]: {
@@ -32,4 +34,4 @@ export default [
32
34
  },
33
35
  },
34
36
  },
35
- ] as const;
37
+ ] as const satisfies Resource[];
@@ -1,5 +1,5 @@
1
1
  //
2
- // Copyright 2024 DXOS.org
2
+ // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './table';
5
+ export * from './schema';
@@ -0,0 +1,16 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Schema } from 'effect';
6
+
7
+ import { Type } from '@dxos/echo';
8
+ import { JsonPath } from '@dxos/effect';
9
+
10
+ export const TableView = Schema.Struct({
11
+ sizes: Schema.Record({
12
+ key: JsonPath,
13
+ value: Schema.Number,
14
+ }).pipe(Schema.mutable),
15
+ }).pipe(Type.Obj({ typename: 'dxos.org/type/TableView', version: '0.1.0' }));
16
+ export type TableView = Schema.Schema.Type<typeof TableView>;
@@ -4,18 +4,18 @@
4
4
 
5
5
  import { type Schema } from 'effect';
6
6
 
7
- import { Obj, Ref } from '@dxos/echo';
7
+ import { Obj } from '@dxos/echo';
8
8
  import { getTypename, toJsonSchema } from '@dxos/echo-schema';
9
9
  import type { JsonSchemaType, SortDirectionType } from '@dxos/echo-schema';
10
10
  import {
11
11
  createView,
12
+ type DataType,
12
13
  getSchemaFromPropertyDefinitions,
13
- ViewProjection,
14
- type ViewType,
14
+ ProjectionModel,
15
15
  type SchemaPropertyDefinition,
16
16
  } from '@dxos/schema';
17
17
 
18
- import { TableType } from '../types';
18
+ import { TableView } from '../types';
19
19
 
20
20
  // TODO(ZaymonFC): Upstream these extra fields to SchemaPropertyDefinition to enhance schema-tools schema creation.
21
21
  type PropertyDisplayProps = {
@@ -61,32 +61,34 @@ export const makeDynamicTable = ({
61
61
  typename: string;
62
62
  jsonSchema: JsonSchemaType;
63
63
  properties?: TablePropertyDefinition[];
64
- }): { table: TableType; projection: ViewProjection } => {
64
+ }): { projection: ProjectionModel; view: DataType.View } => {
65
+ const table = Obj.make(TableView, { sizes: {} });
65
66
  const view = createView({
66
- name: 'dynamic-table',
67
67
  typename,
68
68
  jsonSchema,
69
+ presentation: table,
69
70
  ...(properties && { fields: properties.map((property) => property.name) }),
70
71
  });
71
72
 
72
- const table = Obj.make(TableType, { name: 'dynamic-table', view: Ref.make(view) });
73
- const projection = new ViewProjection(jsonSchema, view);
74
- if (properties && view.fields) {
75
- setProperties(view, projection, properties);
73
+ const projection = new ProjectionModel(jsonSchema, view.projection);
74
+ if (properties && projection.fields) {
75
+ setProperties(view, projection, table, properties);
76
76
  }
77
77
 
78
- return {
79
- table,
80
- projection,
81
- };
78
+ return { projection, view };
82
79
  };
83
80
 
84
- const setProperties = (view: ViewType, projection: ViewProjection, properties: TablePropertyDefinition[]) => {
81
+ const setProperties = (
82
+ view: DataType.View,
83
+ projection: ProjectionModel,
84
+ table: TableView,
85
+ properties: TablePropertyDefinition[],
86
+ ) => {
85
87
  for (const property of properties) {
86
- const field = view.fields.find((field) => field.path === property.name);
88
+ const field = projection.fields.find((field) => field.path === property.name);
87
89
  if (field) {
88
90
  if (property.size !== undefined) {
89
- field.size = property.size;
91
+ table.sizes[field.path] = property.size;
90
92
  }
91
93
 
92
94
  if (property.title !== undefined) {
@@ -2,13 +2,14 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export type TableButton = 'columnSettings' | 'rowMenu' | 'newColumn' | 'referencedCell' | 'sort';
5
+ export type TableButton = 'columnSettings' | 'rowMenu' | 'newColumn' | 'referencedCell' | 'sort' | 'saveDraftRow';
6
6
 
7
7
  export const BUTTON_IDENTIFIERS: { [K in TableButton]: string } = {
8
8
  columnSettings: 'data-table-column-settings-button',
9
9
  newColumn: 'data-table-new-column-button',
10
10
  referencedCell: 'data-table-ref-cell-button',
11
11
  rowMenu: 'data-table-row-menu-button',
12
+ saveDraftRow: 'data-table-save-draft-row-button',
12
13
  sort: 'data-table-sort-button',
13
14
  } as const;
14
15
 
@@ -16,6 +17,7 @@ type ButtonData =
16
17
  | { type: 'columnSettings'; fieldId: string }
17
18
  | { type: 'newColumn'; disabled?: boolean }
18
19
  | { type: 'rowMenu'; rowIndex: number }
20
+ | { type: 'saveDraftRow'; rowIndex: number; disabled?: boolean }
19
21
  | { type: 'sort'; fieldId: string; direction?: 'asc' | 'desc' };
20
22
 
21
23
  const createButton = ({
@@ -118,9 +120,30 @@ const sortButton = {
118
120
  }),
119
121
  } as const;
120
122
 
123
+ const saveDraftRowButton = {
124
+ attr: BUTTON_IDENTIFIERS.saveDraftRow,
125
+ icon: 'ph--floppy-disk--regular',
126
+ render: ({ rowIndex, disabled }: Omit<Extract<ButtonData, { type: 'saveDraftRow' }>, 'type'>) => {
127
+ return createButton({
128
+ attr: BUTTON_IDENTIFIERS.saveDraftRow,
129
+ icon: saveDraftRowButton.icon,
130
+ disabled,
131
+ data: {
132
+ 'data-row-index': rowIndex.toString(),
133
+ },
134
+ testId: 'table-save-draft-row-button',
135
+ });
136
+ },
137
+ getData: (el: HTMLElement): Extract<ButtonData, { type: 'saveDraftRow' }> => ({
138
+ type: 'saveDraftRow',
139
+ rowIndex: Number(el.getAttribute('data-row-index')!),
140
+ }),
141
+ } as const;
142
+
121
143
  export const tableButtons = {
122
144
  addColumn: addColumnButton,
123
145
  columnSettings: columnSettingsButton,
124
146
  rowMenu: rowMenuButton,
147
+ saveDraftRow: saveDraftRowButton,
125
148
  sort: sortButton,
126
149
  } as const;
package/src/util/table.ts CHANGED
@@ -2,126 +2,48 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import { Match } from 'effect';
6
6
 
7
- import {
8
- type EchoSchema,
9
- Format,
10
- FormatEnum,
11
- type JsonPath,
12
- type JsonProp,
13
- Ref,
14
- TypedObject,
15
- TypeEnum,
16
- } from '@dxos/echo-schema';
17
- import { type Client, PublicKey } from '@dxos/react-client';
18
- import { live, type Space } from '@dxos/react-client/echo';
19
- import { createFieldId, createView, getSchemaProperties, ViewProjection, type ViewType } from '@dxos/schema';
7
+ import { Obj } from '@dxos/echo';
8
+ import { type JsonPath, toEffectSchema, type JsonSchemaType } from '@dxos/echo-schema';
9
+ import { type SimpleType } from '@dxos/effect';
10
+ import { type CreateViewFromSpaceProps, type DataType, createViewFromSpace, getSchemaProperties } from '@dxos/schema';
20
11
 
21
- import { type TableType } from '../types';
12
+ import { TableView } from '../types';
22
13
 
23
- // TODO(ZaymonFC): We don't need the client anymore.
24
- type InitialiseTableProps = {
25
- client: Client;
26
- space: Space;
27
- table: TableType;
28
- typename?: string;
29
- initialRow?: boolean;
14
+ type CreateTableProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {
15
+ sizes?: Record<string, number>;
30
16
  };
31
17
 
32
- export const initializeTable = async ({
33
- client,
34
- space,
35
- table,
36
- typename,
37
- initialRow = true,
38
- }: InitialiseTableProps): Promise<Schema.Schema.AnyNoContext> => {
39
- if (typename) {
40
- const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
41
- if (!schema) {
42
- throw new Error(`Schema not found: ${typename}`);
18
+ export const createTable = async ({
19
+ sizes,
20
+ ...props
21
+ }: CreateTableProps): Promise<{ jsonSchema: JsonSchemaType; view: DataType.View }> => {
22
+ const table = Obj.make(TableView, { sizes: {} });
23
+ const { jsonSchema, view } = await createViewFromSpace({ ...props, presentation: table });
24
+
25
+ // Preset sizes.
26
+ const schema = toEffectSchema(jsonSchema);
27
+ const shouldIncludeId = props.fields?.find((field) => field === 'id') !== undefined;
28
+ const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
29
+ for (const property of properties) {
30
+ if (sizes?.[property.name]) {
31
+ table.sizes[property.name as JsonPath] = sizes[property.name];
32
+ continue;
43
33
  }
44
34
 
45
- const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
46
-
47
- table.view = Ref.make(
48
- createView({
49
- // TODO(ZaymonFC): Don't hardcode name?
50
- name: 'View',
51
- typename: schema.typename,
52
- jsonSchema: schema.jsonSchema,
53
- fields,
35
+ Match.type<SimpleType>().pipe(
36
+ Match.when('boolean', () => {
37
+ table.sizes[property.name as JsonPath] = 100;
54
38
  }),
55
- );
56
-
57
- return schema;
58
- } else {
59
- const [schema] = await space.db.schemaRegistry.register([createContactSchema()]);
60
- const fields = ContactFields;
61
-
62
- table.view = Ref.make(
63
- createView({
64
- name: 'View',
65
- typename: schema.typename,
66
- jsonSchema: schema.jsonSchema,
67
- fields,
39
+ Match.when('number', () => {
40
+ table.sizes[property.name as JsonPath] = 100;
68
41
  }),
69
- );
70
-
71
- createProjection(schema, table.view.target!);
72
-
73
- if (initialRow) {
74
- // TODO(burdon): Last (first) row should not be in db and should be managed by the model.
75
- space.db.add(live(schema, {}));
76
- }
77
-
78
- return schema;
42
+ Match.orElse(() => {
43
+ // Noop.
44
+ }),
45
+ )(property.type);
79
46
  }
80
- };
81
-
82
- const createContactSchema = () =>
83
- TypedObject({
84
- typename: `example.com/type/${PublicKey.random().truncate()}`,
85
- version: '0.1.0',
86
- })({
87
- name: Schema.optional(Schema.String).annotations({ title: 'Name' }),
88
- active: Schema.optional(Schema.Boolean).annotations({ title: 'Active' }),
89
- email: Schema.optional(Format.Email),
90
- salary: Schema.optional(Format.Currency()).annotations({ title: 'Salary' }),
91
- });
92
-
93
- const ContactFields = ['name', 'email', 'salary', 'active'];
94
-
95
- const createProjection = (schema: EchoSchema, view: ViewType): ViewProjection => {
96
- const projection = new ViewProjection(schema.jsonSchema, view);
97
- projection.setFieldProjection({
98
- field: {
99
- id: view.fields.find((f) => f.path === 'salary')!.id,
100
- path: 'salary' as JsonPath,
101
- size: 150,
102
- },
103
- });
104
- projection.setFieldProjection({
105
- field: {
106
- id: view.fields.find((f) => f.path === 'active')!.id,
107
- path: 'active' as JsonPath,
108
- size: 100,
109
- },
110
- });
111
- projection.setFieldProjection({
112
- field: {
113
- id: createFieldId(),
114
- path: 'manager' as JsonPath,
115
- referencePath: 'name' as JsonPath,
116
- },
117
- props: {
118
- property: 'manager' as JsonProp,
119
- type: TypeEnum.Ref,
120
- format: FormatEnum.Ref,
121
- referenceSchema: schema.typename,
122
- title: 'Manager',
123
- },
124
- });
125
47
 
126
- return projection;
48
+ return { jsonSchema, view };
127
49
  };
@@ -1,27 +0,0 @@
1
- // packages/ui/react-ui-table/src/types/table.ts
2
- import { Schema } from "effect";
3
- import { Type } from "@dxos/echo";
4
- import { ObjectId, Ref, Expando, LabelAnnotation } from "@dxos/echo-schema";
5
- import { ViewType } from "@dxos/schema";
6
- var TableSchema = Schema.Struct({
7
- id: ObjectId,
8
- name: Schema.optional(Schema.String),
9
- view: Schema.optional(Ref(ViewType)),
10
- // TODO(burdon): Document why threads is included here?
11
- threads: Schema.optional(Schema.Array(Ref(
12
- Expando
13
- /* ThreadType */
14
- )))
15
- }).pipe(LabelAnnotation.set([
16
- "name"
17
- ]));
18
- var TableType = TableSchema.pipe(Type.Obj({
19
- typename: "dxos.org/type/Table",
20
- version: "0.1.0"
21
- }));
22
-
23
- export {
24
- TableSchema,
25
- TableType
26
- };
27
- //# sourceMappingURL=chunk-TL7CKQQV.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/table.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\n// import { ThreadType } from '@dxos/plugin-space/types';\nimport { Type } from '@dxos/echo';\nimport { ObjectId, Ref, Expando, LabelAnnotation } from '@dxos/echo-schema';\nimport { ViewType } from '@dxos/schema';\n\nexport const TableSchema = Schema.Struct({\n id: ObjectId,\n name: Schema.optional(Schema.String),\n view: Schema.optional(Ref(ViewType)),\n // TODO(burdon): Document why threads is included here?\n threads: Schema.optional(Schema.Array(Ref(Expando /* ThreadType */))),\n}).pipe(LabelAnnotation.set(['name']));\n\n// TODO(burdon): Move out of react-ui-xxx.\nexport const TableType = TableSchema.pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.1.0',\n }),\n);\nexport interface TableType extends Schema.Schema.Type<typeof TableType> {}\n"],
5
- "mappings": ";AAIA,SAASA,cAAc;AAGvB,SAASC,YAAY;AACrB,SAASC,UAAUC,KAAKC,SAASC,uBAAuB;AACxD,SAASC,gBAAgB;AAElB,IAAMC,cAAcC,OAAOC,OAAO;EACvCC,IAAIC;EACJC,MAAMJ,OAAOK,SAASL,OAAOM,MAAM;EACnCC,MAAMP,OAAOK,SAASG,IAAIC,QAAAA,CAAAA;;EAE1BC,SAASV,OAAOK,SAASL,OAAOW,MAAMH;IAAII;;EAAsB,CAAA,CAAA;AAClE,CAAA,EAAGC,KAAKC,gBAAgBC,IAAI;EAAC;CAAO,CAAA;AAG7B,IAAMC,YAAYjB,YAAYc,KACnCI,KAAKC,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;",
6
- "names": ["Schema", "Type", "ObjectId", "Ref", "Expando", "LabelAnnotation", "ViewType", "TableSchema", "Schema", "Struct", "id", "ObjectId", "name", "optional", "String", "view", "Ref", "ViewType", "threads", "Array", "Expando", "pipe", "LabelAnnotation", "set", "TableType", "Type", "Obj", "typename", "version"]
7
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_O2VPBNS5_exports = {};
20
- __export(chunk_O2VPBNS5_exports, {
21
- TableSchema: () => TableSchema,
22
- TableType: () => TableType
23
- });
24
- module.exports = __toCommonJS(chunk_O2VPBNS5_exports);
25
- var import_effect = require("effect");
26
- var import_echo = require("@dxos/echo");
27
- var import_echo_schema = require("@dxos/echo-schema");
28
- var import_schema = require("@dxos/schema");
29
- var TableSchema = import_effect.Schema.Struct({
30
- id: import_echo_schema.ObjectId,
31
- name: import_effect.Schema.optional(import_effect.Schema.String),
32
- view: import_effect.Schema.optional((0, import_echo_schema.Ref)(import_schema.ViewType)),
33
- // TODO(burdon): Document why threads is included here?
34
- threads: import_effect.Schema.optional(import_effect.Schema.Array((0, import_echo_schema.Ref)(
35
- import_echo_schema.Expando
36
- /* ThreadType */
37
- )))
38
- }).pipe(import_echo_schema.LabelAnnotation.set([
39
- "name"
40
- ]));
41
- var TableType = TableSchema.pipe(import_echo.Type.Obj({
42
- typename: "dxos.org/type/Table",
43
- version: "0.1.0"
44
- }));
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- TableSchema,
48
- TableType
49
- });
50
- //# sourceMappingURL=chunk-O2VPBNS5.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/table.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\n// import { ThreadType } from '@dxos/plugin-space/types';\nimport { Type } from '@dxos/echo';\nimport { ObjectId, Ref, Expando, LabelAnnotation } from '@dxos/echo-schema';\nimport { ViewType } from '@dxos/schema';\n\nexport const TableSchema = Schema.Struct({\n id: ObjectId,\n name: Schema.optional(Schema.String),\n view: Schema.optional(Ref(ViewType)),\n // TODO(burdon): Document why threads is included here?\n threads: Schema.optional(Schema.Array(Ref(Expando /* ThreadType */))),\n}).pipe(LabelAnnotation.set(['name']));\n\n// TODO(burdon): Move out of react-ui-xxx.\nexport const TableType = TableSchema.pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.1.0',\n }),\n);\nexport interface TableType extends Schema.Schema.Type<typeof TableType> {}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAuB;AAGvB,kBAAqB;AACrB,yBAAwD;AACxD,oBAAyB;AAElB,IAAMA,cAAcC,qBAAOC,OAAO;EACvCC,IAAIC;EACJC,MAAMJ,qBAAOK,SAASL,qBAAOM,MAAM;EACnCC,MAAMP,qBAAOK,aAASG,wBAAIC,sBAAAA,CAAAA;;EAE1BC,SAASV,qBAAOK,SAASL,qBAAOW,UAAMH;IAAII;;EAAsB,CAAA,CAAA;AAClE,CAAA,EAAGC,KAAKC,mCAAgBC,IAAI;EAAC;CAAO,CAAA;AAG7B,IAAMC,YAAYjB,YAAYc,KACnCI,iBAAKC,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;",
6
- "names": ["TableSchema", "Schema", "Struct", "id", "ObjectId", "name", "optional", "String", "view", "Ref", "ViewType", "threads", "Array", "Expando", "pipe", "LabelAnnotation", "set", "TableType", "Type", "Obj", "typename", "version"]
7
- }