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

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 (120) hide show
  1. package/dist/lib/browser/chunk-63UUF4IG.mjs +66 -0
  2. package/dist/lib/browser/chunk-63UUF4IG.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-BBXDTWCX.mjs} +537 -466
  4. package/dist/lib/browser/chunk-BBXDTWCX.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +730 -669
  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 +9 -6
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types/index.mjs +3 -3
  11. package/dist/lib/node-esm/chunk-K734DJB7.mjs +67 -0
  12. package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +7 -0
  13. package/dist/lib/node-esm/{chunk-Y66YLSTC.mjs → chunk-RNQDU7IQ.mjs} +537 -466
  14. package/dist/lib/node-esm/chunk-RNQDU7IQ.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +730 -669
  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 +9 -6
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/types/index.mjs +3 -3
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -1
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +1 -1
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/CreateRefPanel.d.ts +1 -1
  26. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +50 -2
  29. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  30. package/dist/types/src/components/Table/Relations.stories.d.ts +44 -0
  31. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  33. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  34. package/dist/types/src/components/Table/Table.d.ts +3 -2
  35. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  36. package/dist/types/src/components/Table/Table.stories.d.ts +42 -3
  37. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  38. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -3
  40. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +8 -15
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  43. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -3
  44. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  46. package/dist/types/src/hooks/useAddRow.d.ts +2 -1
  47. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  48. package/dist/types/src/hooks/useTableModel.d.ts +1 -1
  49. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  50. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  51. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  52. package/dist/types/src/model/table-model.d.ts +9 -7
  53. package/dist/types/src/model/table-model.d.ts.map +1 -1
  54. package/dist/types/src/model/table-presentation.d.ts +2 -1
  55. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  56. package/dist/types/src/model/table-sorting.d.ts +2 -3
  57. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  58. package/dist/types/src/testing/useTestTableModel.d.ts +2 -21
  59. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  60. package/dist/types/src/translations.d.ts +2 -2
  61. package/dist/types/src/types/index.d.ts +1 -1
  62. package/dist/types/src/types/index.d.ts.map +1 -1
  63. package/dist/types/src/types/schema.d.ts +24 -4
  64. package/dist/types/src/types/schema.d.ts.map +1 -1
  65. package/dist/types/src/util/dynamic-table.d.ts +2 -2
  66. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  67. package/dist/types/src/util/index.d.ts +0 -1
  68. package/dist/types/src/util/index.d.ts.map +1 -1
  69. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  70. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  71. package/dist/types/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +47 -42
  73. package/src/components/Table/ColumnActionsMenu.tsx +1 -1
  74. package/src/components/Table/ColumnSettings.tsx +1 -1
  75. package/src/components/Table/CreateRefPanel.tsx +25 -8
  76. package/src/components/Table/DynamicTable.stories.tsx +7 -4
  77. package/src/components/Table/DynamicTable.tsx +4 -3
  78. package/src/components/Table/{relations.stories.tsx → Relations.stories.tsx} +40 -23
  79. package/src/components/Table/RowActionsMenu.tsx +3 -3
  80. package/src/components/Table/Table.stories.tsx +39 -28
  81. package/src/components/Table/Table.tsx +138 -112
  82. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  83. package/src/components/TableCellEditor/FormCellEditor.tsx +143 -42
  84. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +12 -24
  85. package/src/components/TableCellEditor/TableCellEditor.tsx +74 -137
  86. package/src/components/TableToolbar/TableToolbar.tsx +2 -2
  87. package/src/components/testing.ts +1 -1
  88. package/src/hooks/useAddRow.ts +6 -4
  89. package/src/hooks/useTableModel.ts +1 -1
  90. package/src/model/modal-controller.ts +1 -1
  91. package/src/model/selection-model.ts +3 -2
  92. package/src/model/table-model.test.ts +9 -5
  93. package/src/model/table-model.ts +35 -24
  94. package/src/model/table-presentation.test.ts +10 -5
  95. package/src/model/table-presentation.ts +72 -30
  96. package/src/model/table-sorting.ts +16 -7
  97. package/src/playwright/smoke.spec.ts +129 -37
  98. package/src/testing/useTestTableModel.ts +7 -5
  99. package/src/translations.ts +2 -2
  100. package/src/types/index.ts +1 -1
  101. package/src/types/schema.ts +62 -5
  102. package/src/util/dynamic-table.ts +10 -9
  103. package/src/util/index.ts +0 -1
  104. package/src/util/schema.ts +1 -1
  105. package/src/util/table-buttons.ts +4 -3
  106. package/src/util/table-controls.ts +4 -1
  107. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
  108. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  109. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  110. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  111. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  112. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
  113. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  114. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  115. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  116. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  117. package/dist/types/src/util/table.d.ts +0 -11
  118. package/dist/types/src/util/table.d.ts.map +0 -1
  119. package/src/components/TableCellEditor/extension.ts +0 -61
  120. package/src/util/table.ts +0 -49
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-table",
3
- "version": "0.8.4-main.c1de068",
3
+ "version": "0.8.4-main.e098934",
4
4
  "description": "A table component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -10,21 +10,25 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  "./deprecated": {
13
+ "source": "./src/deprecated/index.ts",
13
14
  "types": "./dist/types/src/deprecated/index.d.ts",
14
15
  "browser": "./dist/lib/browser/deprecated/index.mjs",
15
16
  "node": "./dist/lib/node-esm/deprecated/index.mjs"
16
17
  },
17
18
  ".": {
19
+ "source": "./src/index.ts",
18
20
  "types": "./dist/types/src/index.d.ts",
19
21
  "browser": "./dist/lib/browser/index.mjs",
20
22
  "node": "./dist/lib/node-esm/index.mjs"
21
23
  },
22
24
  "./testing": {
25
+ "source": "./src/testing/index.ts",
23
26
  "types": "./dist/types/src/testing/index.d.ts",
24
27
  "browser": "./dist/lib/browser/testing/index.mjs",
25
28
  "node": "./dist/lib/node-esm/testing/index.mjs"
26
29
  },
27
30
  "./types": {
31
+ "source": "./src/types/index.ts",
28
32
  "types": "./dist/types/src/types/index.d.ts",
29
33
  "browser": "./dist/lib/browser/types/index.mjs",
30
34
  "node": "./dist/lib/node-esm/types/index.mjs"
@@ -49,9 +53,9 @@
49
53
  "src"
50
54
  ],
51
55
  "dependencies": {
52
- "@codemirror/autocomplete": "^6.18.1",
53
- "@codemirror/state": "^6.4.1",
54
- "@codemirror/view": "^6.34.1",
56
+ "@codemirror/autocomplete": "^6.18.7",
57
+ "@codemirror/state": "^6.5.2",
58
+ "@codemirror/view": "^6.38.2",
55
59
  "@fluentui/react-tabster": "^9.24.2",
56
60
  "@preact-signals/safe-react": "^0.9.0",
57
61
  "@preact/signals-core": "^1.9.0",
@@ -61,51 +65,52 @@
61
65
  "@radix-ui/react-use-controllable-state": "1.1.0",
62
66
  "date-fns": "^3.3.1",
63
67
  "lodash.orderby": "^4.6.0",
64
- "@dxos/context": "0.8.4-main.c1de068",
65
- "@dxos/debug": "0.8.4-main.c1de068",
66
- "@dxos/echo": "0.8.4-main.c1de068",
67
- "@dxos/effect": "0.8.4-main.c1de068",
68
- "@dxos/echo-schema": "0.8.4-main.c1de068",
69
- "@dxos/echo-db": "0.8.4-main.c1de068",
70
- "@dxos/invariant": "0.8.4-main.c1de068",
71
- "@dxos/lit-grid": "0.8.4-main.c1de068",
72
- "@dxos/keys": "0.8.4-main.c1de068",
73
- "@dxos/live-object": "0.8.4-main.c1de068",
74
- "@dxos/plugin-search": "0.8.4-main.c1de068",
75
- "@dxos/log": "0.8.4-main.c1de068",
76
- "@dxos/react-client": "0.8.4-main.c1de068",
77
- "@dxos/react-ui-attention": "0.8.4-main.c1de068",
78
- "@dxos/random": "0.8.4-main.c1de068",
79
- "@dxos/react-ui-form": "0.8.4-main.c1de068",
80
- "@dxos/react-ui-grid": "0.8.4-main.c1de068",
81
- "@dxos/react-ui-editor": "0.8.4-main.c1de068",
82
- "@dxos/react-ui-menu": "0.8.4-main.c1de068",
83
- "@dxos/react-ui-searchlist": "0.8.4-main.c1de068",
84
- "@dxos/react-ui-stack": "0.8.4-main.c1de068",
85
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.c1de068",
86
- "@dxos/react-ui-tag-picker": "0.8.4-main.c1de068",
87
- "@dxos/react-ui-types": "0.8.4-main.c1de068",
88
- "@dxos/schema": "0.8.4-main.c1de068",
89
- "@dxos/util": "0.8.4-main.c1de068"
68
+ "@dxos/async": "0.8.4-main.e098934",
69
+ "@dxos/context": "0.8.4-main.e098934",
70
+ "@dxos/echo": "0.8.4-main.e098934",
71
+ "@dxos/echo-db": "0.8.4-main.e098934",
72
+ "@dxos/effect": "0.8.4-main.e098934",
73
+ "@dxos/echo-schema": "0.8.4-main.e098934",
74
+ "@dxos/invariant": "0.8.4-main.e098934",
75
+ "@dxos/keys": "0.8.4-main.e098934",
76
+ "@dxos/lit-grid": "0.8.4-main.e098934",
77
+ "@dxos/live-object": "0.8.4-main.e098934",
78
+ "@dxos/debug": "0.8.4-main.e098934",
79
+ "@dxos/log": "0.8.4-main.e098934",
80
+ "@dxos/plugin-search": "0.8.4-main.e098934",
81
+ "@dxos/random": "0.8.4-main.e098934",
82
+ "@dxos/react-client": "0.8.4-main.e098934",
83
+ "@dxos/react-ui-attention": "0.8.4-main.e098934",
84
+ "@dxos/react-ui-editor": "0.8.4-main.e098934",
85
+ "@dxos/react-ui-form": "0.8.4-main.e098934",
86
+ "@dxos/react-ui-grid": "0.8.4-main.e098934",
87
+ "@dxos/react-ui-menu": "0.8.4-main.e098934",
88
+ "@dxos/react-ui-searchlist": "0.8.4-main.e098934",
89
+ "@dxos/react-ui-stack": "0.8.4-main.e098934",
90
+ "@dxos/react-ui-tag-picker": "0.8.4-main.e098934",
91
+ "@dxos/react-ui-types": "0.8.4-main.e098934",
92
+ "@dxos/util": "0.8.4-main.e098934",
93
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.e098934",
94
+ "@dxos/schema": "0.8.4-main.e098934"
90
95
  },
91
96
  "devDependencies": {
92
97
  "@effect-rx/rx-react": "0.38.0",
93
- "@effect/platform": "0.89.0",
98
+ "@effect/platform": "0.90.2",
94
99
  "@types/lodash.orderby": "^4.6.9",
95
100
  "@types/react": "~18.2.0",
96
101
  "@types/react-dom": "~18.2.0",
97
- "effect": "3.17.0",
102
+ "effect": "3.17.7",
98
103
  "fast-check": "^3.19.0",
99
104
  "react": "~18.2.0",
100
105
  "react-dom": "~18.2.0",
101
- "vite": "5.4.7",
102
- "@dxos/echo-signals": "0.8.4-main.c1de068",
103
- "@dxos/plugin-search": "0.8.4-main.c1de068",
104
- "@dxos/random": "0.8.4-main.c1de068",
105
- "@dxos/react-ui": "0.8.4-main.c1de068",
106
- "@dxos/react-ui-theme": "0.8.4-main.c1de068",
107
- "@dxos/storybook-utils": "0.8.4-main.c1de068",
108
- "@dxos/test-utils": "0.8.4-main.c1de068"
106
+ "vite": "7.1.1",
107
+ "@dxos/plugin-search": "0.8.4-main.e098934",
108
+ "@dxos/echo-signals": "0.8.4-main.e098934",
109
+ "@dxos/random": "0.8.4-main.e098934",
110
+ "@dxos/react-ui": "0.8.4-main.e098934",
111
+ "@dxos/react-ui-theme": "0.8.4-main.e098934",
112
+ "@dxos/storybook-utils": "0.8.4-main.e098934",
113
+ "@dxos/test-utils": "0.8.4-main.e098934"
109
114
  },
110
115
  "peerDependencies": {
111
116
  "@effect-rx/rx-react": "^0.34.1",
@@ -113,8 +118,8 @@
113
118
  "effect": "^3.13.3",
114
119
  "react": "~18.2.0",
115
120
  "react-dom": "~18.2.0",
116
- "@dxos/react-ui": "0.8.4-main.c1de068",
117
- "@dxos/react-ui-theme": "0.8.4-main.c1de068"
121
+ "@dxos/react-ui": "0.8.4-main.e098934",
122
+ "@dxos/react-ui-theme": "0.8.4-main.e098934"
118
123
  },
119
124
  "publishConfig": {
120
125
  "access": "public"
@@ -6,7 +6,7 @@ import React from 'react';
6
6
 
7
7
  import { DropdownMenu, useTranslation } from '@dxos/react-ui';
8
8
 
9
- import { type TableModel, type ModalController } from '../../model';
9
+ import { type ModalController, type TableModel } from '../../model';
10
10
  import { translationKey } from '../../translations';
11
11
 
12
12
  type ColumnActionsMenuProps = { model: TableModel; modals: ModalController };
@@ -10,7 +10,7 @@ import { Popover } from '@dxos/react-ui';
10
10
  import { FieldEditor } from '@dxos/react-ui-form';
11
11
  import { type FieldType } from '@dxos/schema';
12
12
 
13
- import { type TableModel, type ModalController } from '../../model';
13
+ import { type ModalController, type TableModel } from '../../model';
14
14
 
15
15
  type ColumnSettingsProps = {
16
16
  registry?: SchemaRegistry;
@@ -5,49 +5,66 @@
5
5
  import { Schema } from 'effect';
6
6
  import React, { useCallback, useMemo } from 'react';
7
7
 
8
+ import { Type } from '@dxos/echo';
8
9
  import { live } from '@dxos/live-object';
9
10
  // TODO(wittjosiah): Remove dependency on react-client.
11
+ import { useClient } from '@dxos/react-client';
10
12
  import { getSpace } from '@dxos/react-client/echo';
11
13
  import { Popover } from '@dxos/react-ui';
12
14
  import { Form } from '@dxos/react-ui-form';
13
15
  import { type GridScopedProps, useGridContext } from '@dxos/react-ui-grid';
14
16
 
15
- import { type TableModel, type ModalController } from '../../model';
17
+ import { type ModalController, type TableModel } from '../../model';
16
18
 
17
19
  export type CreateRefPanelProps = { model?: TableModel; modals: ModalController };
18
20
 
19
21
  // TODO(burdon): Factor out Space dependency (to plugin?)
20
22
  export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<CreateRefPanelProps>) => {
21
23
  const { id: gridId } = useGridContext('TableCellEditor', __gridScope);
24
+ const client = useClient();
22
25
  const space = model && getSpace(model?.view);
23
26
  const state = modals.state.value;
24
27
 
25
- const schema = useMemo<Schema.Schema<any> | undefined>(() => {
28
+ const getSchema = useCallback(() => {
26
29
  if (!space || state?.type !== 'createRefPanel') {
27
30
  return;
28
31
  }
29
32
 
30
- const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
31
- if (schema) {
32
- const omit = Schema.omit<any, any, ['id']>('id');
33
- return omit(schema);
33
+ const staticSchema = client.graph.schemaRegistry.schemas.find(
34
+ (schema) => Type.getTypename(schema) === state.typename,
35
+ );
36
+ if (staticSchema) {
37
+ return staticSchema;
34
38
  }
39
+
40
+ const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
41
+ return schema;
35
42
  }, [space, state]);
36
43
 
44
+ const schema = useMemo<Schema.Schema<any> | undefined>(() => {
45
+ const schema = getSchema();
46
+ if (!schema) {
47
+ return;
48
+ }
49
+
50
+ const omit = Schema.omit<any, any, ['id']>('id');
51
+ return omit(schema);
52
+ }, [getSchema]);
53
+
37
54
  const handleSave = useCallback(
38
55
  (values: any) => {
39
56
  if (!model || !space || state?.type !== 'createRefPanel') {
40
57
  return;
41
58
  }
42
59
 
43
- const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
60
+ const schema = getSchema();
44
61
  if (schema) {
45
62
  const obj = space.db.add(live(schema, values));
46
63
  state.onCreate?.(obj);
47
64
  }
48
65
  void modals.close();
49
66
  },
50
- [modals, space, state],
67
+ [model, modals, space, state],
51
68
  );
52
69
 
53
70
  const handleCancel = useCallback(() => {
@@ -4,7 +4,7 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React, { useMemo, useState } from 'react';
9
9
 
10
10
  import { Obj } from '@dxos/echo';
@@ -17,10 +17,11 @@ import { type SchemaPropertyDefinition } from '@dxos/schema';
17
17
  import { Testing } from '@dxos/schema/testing';
18
18
  import { withLayout, withTheme } from '@dxos/storybook-utils';
19
19
 
20
- import { DynamicTable } from './DynamicTable';
21
20
  import { type TableFeatures } from '../../model';
22
21
  import { translations } from '../../translations';
23
22
 
23
+ import { DynamicTable } from './DynamicTable';
24
+
24
25
  faker.seed(0);
25
26
 
26
27
  const useTestPropertiesAndObjects = () => {
@@ -56,15 +57,17 @@ const DynamicTableStory = () => {
56
57
  // Story definitions.
57
58
  //
58
59
 
59
- const meta: Meta = {
60
+ const meta = {
60
61
  title: 'ui/react-ui-table/DynamicTable',
61
62
  component: DynamicTable,
62
63
  parameters: { translations },
63
64
  decorators: [withLayout({ fullscreen: true }), withTheme],
64
- };
65
+ } satisfies Meta<typeof DynamicTable>;
65
66
 
66
67
  export default meta;
67
68
 
69
+ type Story = StoryObj<typeof meta>;
70
+
68
71
  export const Default: StoryObj = {
69
72
  render: DynamicTableStory,
70
73
  };
@@ -3,16 +3,17 @@
3
3
  //
4
4
 
5
5
  import { type Schema } from 'effect';
6
- import React, { useRef, useMemo, useCallback } from 'react';
6
+ import React, { useCallback, useMemo, useRef } from 'react';
7
7
 
8
8
  import { type JsonSchemaType } from '@dxos/echo-schema';
9
9
  import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
10
10
  import { mx } from '@dxos/react-ui-theme';
11
11
 
12
- import { Table, type TableController } from './Table';
13
12
  import { useTableModel } from '../../hooks';
14
13
  import { type TableFeatures, TablePresentation, type TableRowAction } from '../../model';
15
- import { getBaseSchema, makeDynamicTable, type TablePropertyDefinition } from '../../util';
14
+ import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from '../../util';
15
+
16
+ import { Table, type TableController } from './Table';
16
17
 
17
18
  type DynamicTableProps = ThemedClassName<{
18
19
  name?: string; // TODO(burdon): Remove?
@@ -4,7 +4,7 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React, { useEffect, useMemo, useState } from 'react';
9
9
 
10
10
  import { Type } from '@dxos/echo';
@@ -12,16 +12,17 @@ import { type JsonSchemaType } from '@dxos/echo-schema';
12
12
  import { faker } from '@dxos/random';
13
13
  import { useClient } from '@dxos/react-client';
14
14
  import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
15
+ import { useAsyncEffect } from '@dxos/react-ui';
15
16
  import { DataType } from '@dxos/schema';
16
- import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
17
+ import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
17
18
  import { withLayout, withTheme } from '@dxos/storybook-utils';
18
19
 
19
- import { Table } from './Table';
20
20
  import { useTableModel } from '../../hooks';
21
21
  import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
22
22
  import { translations } from '../../translations';
23
- import { TableView } from '../../types';
24
- import { createTable } from '../../util';
23
+ import { Table } from '../../types';
24
+
25
+ import { Table as TableComponent } from './Table';
25
26
 
26
27
  faker.seed(1);
27
28
  const generator: ValueGenerator = faker as any;
@@ -41,20 +42,24 @@ const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
41
42
  [],
42
43
  );
43
44
 
44
- useEffect(() => {
45
+ useAsyncEffect(async () => {
45
46
  if (!space) {
46
47
  return;
47
48
  }
48
49
 
49
- const timeout = setTimeout(async () => {
50
- const { jsonSchema, view } = await createTable({ client, space, typename: Type.getTypename(schema) });
51
- setJsonSchema(jsonSchema);
52
- setView(view);
53
- });
54
- return () => clearTimeout(timeout);
50
+ const {
51
+ jsonSchema,
52
+ schema: effectSchema,
53
+ view,
54
+ } = await Table.makeView({ client, space, typename: Type.getTypename(schema) });
55
+ setJsonSchema(jsonSchema);
56
+ setView(view);
57
+ space.db.add(view);
58
+ await space.db.schemaRegistry.register([effectSchema]);
55
59
  }, [client, space, schema]);
56
60
 
57
61
  const model = useTableModel<TableRow>({ view, schema: jsonSchema, rows: [], features });
62
+
58
63
  useEffect(() => {
59
64
  if (!model || !space) {
60
65
  return;
@@ -84,33 +89,45 @@ const DefaultStory = () => {
84
89
 
85
90
  return (
86
91
  <div className='is-full bs-full grid grid-cols-2 divide-x divide-separator'>
87
- <Table.Root>
88
- <Table.Main model={orgModel} presentation={orgPresentation} client={client} ignoreAttention />
89
- </Table.Root>
90
- <Table.Root>
91
- <Table.Main model={contactModel} presentation={contactPresentation} client={client} ignoreAttention />
92
- </Table.Root>
92
+ <TableComponent.Root>
93
+ <TableComponent.Main
94
+ model={orgModel}
95
+ schema={DataType.Organization}
96
+ presentation={orgPresentation}
97
+ client={client}
98
+ ignoreAttention
99
+ />
100
+ </TableComponent.Root>
101
+ <TableComponent.Root>
102
+ <TableComponent.Main
103
+ model={contactModel}
104
+ schema={DataType.Person}
105
+ presentation={contactPresentation}
106
+ client={client}
107
+ ignoreAttention
108
+ />
109
+ </TableComponent.Root>
93
110
  </div>
94
111
  );
95
112
  };
96
113
 
97
- const meta: Meta<typeof DefaultStory> = {
98
- title: 'ui/react-ui-table/relations',
114
+ const meta = {
115
+ title: 'ui/react-ui-table/Relations',
99
116
  render: DefaultStory,
100
117
  parameters: { translations, controls: { disable: true } },
101
118
  decorators: [
102
119
  withClientProvider({
103
- types: [DataType.View, DataType.Organization, DataType.Person, TableView],
120
+ types: [DataType.View, DataType.Organization, DataType.Person, Table.Table],
104
121
  createIdentity: true,
105
122
  createSpace: true,
106
123
  }),
107
124
  withTheme,
108
125
  withLayout({ fullscreen: true }),
109
126
  ],
110
- };
127
+ } satisfies Meta<typeof DefaultStory>;
111
128
 
112
129
  export default meta;
113
130
 
114
- type Story = StoryObj<typeof DefaultStory>;
131
+ type Story = StoryObj<typeof meta>;
115
132
 
116
133
  export const Default: Story = {};
@@ -4,9 +4,9 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { DropdownMenu, useTranslation } from '@dxos/react-ui';
7
+ import { DropdownMenu, toLocalizedString, useTranslation } from '@dxos/react-ui';
8
8
 
9
- import { type TableModel, type ModalController } from '../../model';
9
+ import { type ModalController, type TableModel } from '../../model';
10
10
  import { translationKey } from '../../translations';
11
11
 
12
12
  type RowActionsMenuProps = { model: TableModel; modals: ModalController };
@@ -38,7 +38,7 @@ export const RowActionsMenu = ({ model, modals }: RowActionsMenuProps) => {
38
38
  model.handleRowAction(action.id, state.rowIndex);
39
39
  }}
40
40
  >
41
- {t(action.translationKey)}
41
+ {toLocalizedString(action.label, t)}
42
42
  </DropdownMenu.Item>
43
43
  ))}
44
44
  </DropdownMenu.Viewport>
@@ -4,36 +4,37 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import { Schema } from 'effect';
9
9
  import React, { useCallback } from 'react';
10
10
 
11
- import { Obj, Type } from '@dxos/echo';
11
+ import { Filter, Obj, Query, Type } from '@dxos/echo';
12
12
  import {
13
- FormatEnum,
14
13
  EchoObject,
15
- GeneratorAnnotation,
16
14
  FormatAnnotation,
15
+ FormatEnum,
16
+ GeneratorAnnotation,
17
+ LabelAnnotation,
17
18
  PropertyMetaAnnotationId,
18
19
  } from '@dxos/echo-schema';
19
20
  import { invariant } from '@dxos/invariant';
20
21
  import { faker } from '@dxos/random';
21
22
  import { PublicKey } from '@dxos/react-client';
22
- import { live, type Space } from '@dxos/react-client/echo';
23
+ import { type Space, live } from '@dxos/react-client/echo';
23
24
  import { withClientProvider } from '@dxos/react-client/testing';
24
25
  import { ViewEditor } from '@dxos/react-ui-form';
25
26
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
26
- import { getSchemaFromPropertyDefinitions, DataType } from '@dxos/schema';
27
+ import { DataType, getSchemaFromPropertyDefinitions } from '@dxos/schema';
27
28
  import { Testing, createObjectFactory } from '@dxos/schema/testing';
28
29
  import { withLayout, withTheme } from '@dxos/storybook-utils';
29
30
 
30
- import { Table } from './Table';
31
31
  import { useTestTableModel } from '../../testing';
32
32
  import { translations } from '../../translations';
33
- import { TableView } from '../../types';
34
- import { createTable } from '../../util';
33
+ import { Table } from '../../types';
35
34
  import { TableToolbar } from '../TableToolbar';
36
35
 
36
+ import { Table as TableComponent } from './Table';
37
+
37
38
  const TestSchema = Schema.Struct({
38
39
  // TODO(wittjosiah): Should be title. Currently name to work with default label.
39
40
  name: Schema.optional(Schema.String).annotations({ title: 'Title' }),
@@ -58,7 +59,10 @@ const TestSchema = Schema.Struct({
58
59
  parent: Schema.optional(Schema.suspend((): Type.Ref<TestSchema> => Type.Ref(TestSchema))).annotations({
59
60
  title: 'Parent',
60
61
  }),
61
- }).pipe(Type.Obj({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }));
62
+ }).pipe(
63
+ Type.Obj({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }),
64
+ LabelAnnotation.set(['name']),
65
+ );
62
66
  interface TestSchema extends Schema.Schema.Type<typeof TestSchema> {}
63
67
 
64
68
  const StoryViewEditor = ({
@@ -72,13 +76,13 @@ const StoryViewEditor = ({
72
76
  space?: Space;
73
77
  handleDeleteColumn: (fieldId: string) => void;
74
78
  }) => {
75
- const handleTypenameChanged = useCallback(
79
+ const handleQueryChanged = useCallback(
76
80
  (typename: string) => {
77
81
  invariant(schema);
78
82
  invariant(Type.isMutable(schema));
79
83
  schema.updateTypename(typename);
80
84
  invariant(view);
81
- view.query.typename = typename;
85
+ view.query = Query.select(Filter.typename(typename)).ast;
82
86
  },
83
87
  [schema, view],
84
88
  );
@@ -92,7 +96,7 @@ const StoryViewEditor = ({
92
96
  registry={space?.db.schemaRegistry}
93
97
  schema={schema}
94
98
  view={view}
95
- onTypenameChanged={handleTypenameChanged}
99
+ onQueryChanged={handleQueryChanged}
96
100
  onDelete={handleDeleteColumn}
97
101
  />
98
102
  );
@@ -124,8 +128,8 @@ const DefaultStory = () => {
124
128
  <div className='grow grid grid-cols-[1fr_350px]'>
125
129
  <div className='grid grid-rows-[min-content_1fr] min-bs-0 overflow-hidden'>
126
130
  <TableToolbar classNames='border-be border-subduedSeparator' onAdd={handleInsertRow} onSave={handleSaveView} />
127
- <Table.Root>
128
- <Table.Main
131
+ <TableComponent.Root>
132
+ <TableComponent.Main
129
133
  ref={tableRef}
130
134
  model={model}
131
135
  presentation={presentation}
@@ -133,11 +137,11 @@ const DefaultStory = () => {
133
137
  client={client}
134
138
  ignoreAttention
135
139
  />
136
- </Table.Root>
140
+ </TableComponent.Root>
137
141
  </div>
138
142
  <div className='flex flex-col h-full border-l border-separator overflow-y-auto'>
139
143
  <StoryViewEditor view={view} schema={schema} space={space} handleDeleteColumn={handleDeleteColumn} />
140
- <SyntaxHighlighter language='json' className='w-full text-xs'>
144
+ <SyntaxHighlighter language='json' className='text-xs'>
141
145
  {JSON.stringify({ view, schema }, null, 2)}
142
146
  </SyntaxHighlighter>
143
147
  </div>
@@ -153,7 +157,7 @@ type StoryProps = { rows?: number };
153
157
 
154
158
  // TODO(burdon): Need super simple story.
155
159
 
156
- const meta: Meta<StoryProps> = {
160
+ const meta = {
157
161
  title: 'ui/react-ui-table/Table',
158
162
  render: DefaultStory,
159
163
  parameters: {
@@ -167,12 +171,17 @@ const meta: Meta<StoryProps> = {
167
171
  withTheme,
168
172
  withLayout({ fullscreen: true }),
169
173
  withClientProvider({
170
- types: [DataType.View, TableView],
174
+ types: [DataType.View, Table.Table],
171
175
  createIdentity: true,
172
176
  createSpace: true,
173
177
  onSpaceCreated: async ({ client, space }) => {
174
178
  const [schema] = await space.db.schemaRegistry.register([TestSchema]);
175
- const { view } = await createTable({ client, space, typename: schema.typename });
179
+ const { view } = await Table.makeView({ client, space, typename: schema.typename });
180
+ view.projection.fields = [
181
+ view.projection.fields.find((field) => field.path === 'name')!,
182
+ ...view.projection.fields.filter((field) => field.path !== 'name'),
183
+ ];
184
+
176
185
  space.db.add(view);
177
186
 
178
187
  Array.from({ length: 10 }).map(() => {
@@ -187,22 +196,24 @@ const meta: Meta<StoryProps> = {
187
196
  },
188
197
  }),
189
198
  ],
190
- };
199
+ } satisfies Meta<typeof TableComponent>;
191
200
 
192
201
  export default meta;
193
202
 
194
- export const Default = {};
203
+ type Story = StoryObj<typeof meta>;
204
+
205
+ export const Default: Story = {};
195
206
 
196
207
  export const StaticSchema: StoryObj = {
197
208
  render: DefaultStory,
198
209
  parameters: { translations },
199
210
  decorators: [
200
211
  withClientProvider({
201
- types: [DataType.View, TableView, Testing.Contact, Testing.Organization],
212
+ types: [DataType.View, Table.Table, Testing.Contact, Testing.Organization],
202
213
  createIdentity: true,
203
214
  createSpace: true,
204
215
  onSpaceCreated: async ({ client, space }) => {
205
- const { view } = await createTable({ client, space, typename: Testing.Contact.typename });
216
+ const { view } = await Table.makeView({ client, space, typename: Testing.Contact.typename });
206
217
  space.db.add(view);
207
218
 
208
219
  const factory = createObjectFactory(space.db, faker as any);
@@ -239,11 +250,11 @@ export const ArrayOfObjects: StoryObj = {
239
250
  parameters: { translations },
240
251
  decorators: [
241
252
  withClientProvider({
242
- types: [DataType.View, TableView, Testing.Contact, Testing.Organization, ContactWithArrayOfEmails],
253
+ types: [DataType.View, Table.Table, Testing.Contact, Testing.Organization, ContactWithArrayOfEmails],
243
254
  createIdentity: true,
244
255
  createSpace: true,
245
256
  onSpaceCreated: async ({ client, space }) => {
246
- const { view } = await createTable({ client, space, typename: ContactWithArrayOfEmails.typename });
257
+ const { view } = await Table.makeView({ client, space, typename: ContactWithArrayOfEmails.typename });
247
258
  space.db.add(view);
248
259
 
249
260
  const factory = createObjectFactory(space.db, faker as any);
@@ -265,7 +276,7 @@ export const Tags: Meta<StoryProps> = {
265
276
  parameters: { translations },
266
277
  decorators: [
267
278
  withClientProvider({
268
- types: [DataType.View, TableView],
279
+ types: [DataType.View, Table.Table],
269
280
  createIdentity: true,
270
281
  createSpace: true,
271
282
  onSpaceCreated: async ({ client, space }) => {
@@ -296,7 +307,7 @@ export const Tags: Meta<StoryProps> = {
296
307
  const [storedSchema] = await space.db.schemaRegistry.register([schema]);
297
308
 
298
309
  // Initialize table.
299
- const { view } = await createTable({ client, space, typename });
310
+ const { view } = await Table.makeView({ client, space, typename });
300
311
  space.db.add(view);
301
312
 
302
313
  // Populate.