@dxos/react-ui-table 0.8.2-main.12df754 → 0.8.2-main.2f9c567

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 (56) hide show
  1. package/dist/lib/browser/chunk-UGGYKLOH.mjs +28 -0
  2. package/dist/lib/browser/chunk-UGGYKLOH.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +81 -116
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-TGG6OZ54.cjs → chunk-2QLLIPZK.cjs} +13 -11
  8. package/dist/lib/node/chunk-2QLLIPZK.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +142 -177
  10. package/dist/lib/node/index.cjs.map +4 -4
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/types/index.cjs +3 -3
  13. package/dist/lib/node/types/index.cjs.map +1 -1
  14. package/dist/lib/node-esm/{chunk-KKLP54L3.mjs → chunk-N2RRVR7F.mjs} +11 -9
  15. package/dist/lib/node-esm/chunk-N2RRVR7F.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +81 -116
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/types/index.mjs +1 -1
  20. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
  21. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  22. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
  24. package/dist/types/src/components/testing.d.ts +39 -39
  25. package/dist/types/src/components/testing.d.ts.map +1 -1
  26. package/dist/types/src/model/table-model.d.ts.map +1 -1
  27. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  28. package/dist/types/src/types/table.d.ts +43 -43
  29. package/dist/types/src/types/table.d.ts.map +1 -1
  30. package/dist/types/src/util/table-buttons.d.ts +0 -14
  31. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  32. package/dist/types/src/util/table.d.ts +2 -2
  33. package/dist/types/src/util/table.d.ts.map +1 -1
  34. package/dist/types/src/util/tag.d.ts +11 -0
  35. package/dist/types/src/util/tag.d.ts.map +1 -0
  36. package/package.json +35 -33
  37. package/src/components/Table/CreateRefPanel.tsx +3 -3
  38. package/src/components/Table/Table.stories.tsx +3 -4
  39. package/src/components/Table/Table.tsx +18 -24
  40. package/src/components/Table/relations.stories.tsx +33 -23
  41. package/src/components/testing.ts +7 -6
  42. package/src/model/table-model.test.ts +4 -3
  43. package/src/model/table-model.ts +17 -0
  44. package/src/model/table-presentation.test.ts +4 -3
  45. package/src/model/table-presentation.ts +3 -5
  46. package/src/types/table.ts +16 -8
  47. package/src/util/table-buttons.ts +0 -23
  48. package/src/util/table.ts +8 -12
  49. package/src/util/tag.ts +33 -0
  50. package/dist/lib/browser/chunk-YWNRUF4J.mjs +0 -26
  51. package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +0 -7
  52. package/dist/lib/node/chunk-TGG6OZ54.cjs.map +0 -7
  53. package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +0 -7
  54. package/dist/types/src/components/Table/RefPanel.d.ts +0 -9
  55. package/dist/types/src/components/Table/RefPanel.d.ts.map +0 -1
  56. package/src/components/Table/RefPanel.tsx +0 -52
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-table",
3
- "version": "0.8.2-main.12df754",
3
+ "version": "0.8.2-main.2f9c567",
4
4
  "description": "A table component.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -51,31 +51,33 @@
51
51
  "@radix-ui/react-slot": "1.1.2",
52
52
  "@radix-ui/react-use-controllable-state": "1.1.0",
53
53
  "date-fns": "^3.3.1",
54
+ "effect": "3.14.21",
54
55
  "lodash.orderby": "^4.6.0",
55
- "@dxos/context": "0.8.2-main.12df754",
56
- "@dxos/debug": "0.8.2-main.12df754",
57
- "@dxos/echo-schema": "0.8.2-main.12df754",
58
- "@dxos/keys": "0.8.2-main.12df754",
59
- "@dxos/effect": "0.8.2-main.12df754",
60
- "@dxos/lit-grid": "0.8.2-main.12df754",
61
- "@dxos/invariant": "0.8.2-main.12df754",
62
- "@dxos/live-object": "0.8.2-main.12df754",
63
- "@dxos/plugin-search": "0.8.2-main.12df754",
64
- "@dxos/log": "0.8.2-main.12df754",
65
- "@dxos/plugin-space": "0.8.2-main.12df754",
66
- "@dxos/react-client": "0.8.2-main.12df754",
67
- "@dxos/react-ui-editor": "0.8.2-main.12df754",
68
- "@dxos/react-ui-attention": "0.8.2-main.12df754",
69
- "@dxos/react-ui-grid": "0.8.2-main.12df754",
70
- "@dxos/react-ui-menu": "0.8.2-main.12df754",
71
- "@dxos/react-ui-form": "0.8.2-main.12df754",
72
- "@dxos/react-ui-stack": "0.8.2-main.12df754",
73
- "@dxos/react-ui-searchlist": "0.8.2-main.12df754",
74
- "@dxos/react-ui-types": "0.8.2-main.12df754",
75
- "@dxos/react-ui-tag-picker": "0.8.2-main.12df754",
76
- "@dxos/schema": "0.8.2-main.12df754",
77
- "@dxos/react-ui-syntax-highlighter": "0.8.2-main.12df754",
78
- "@dxos/util": "0.8.2-main.12df754"
56
+ "@dxos/debug": "0.8.2-main.2f9c567",
57
+ "@dxos/echo-schema": "0.8.2-main.2f9c567",
58
+ "@dxos/effect": "0.8.2-main.2f9c567",
59
+ "@dxos/context": "0.8.2-main.2f9c567",
60
+ "@dxos/invariant": "0.8.2-main.2f9c567",
61
+ "@dxos/lit-grid": "0.8.2-main.2f9c567",
62
+ "@dxos/echo": "0.8.2-main.2f9c567",
63
+ "@dxos/keys": "0.8.2-main.2f9c567",
64
+ "@dxos/live-object": "0.8.2-main.2f9c567",
65
+ "@dxos/log": "0.8.2-main.2f9c567",
66
+ "@dxos/plugin-search": "0.8.2-main.2f9c567",
67
+ "@dxos/plugin-space": "0.8.2-main.2f9c567",
68
+ "@dxos/react-client": "0.8.2-main.2f9c567",
69
+ "@dxos/react-ui-attention": "0.8.2-main.2f9c567",
70
+ "@dxos/react-ui-editor": "0.8.2-main.2f9c567",
71
+ "@dxos/react-ui-form": "0.8.2-main.2f9c567",
72
+ "@dxos/react-ui-grid": "0.8.2-main.2f9c567",
73
+ "@dxos/react-ui-menu": "0.8.2-main.2f9c567",
74
+ "@dxos/react-ui-stack": "0.8.2-main.2f9c567",
75
+ "@dxos/react-ui-searchlist": "0.8.2-main.2f9c567",
76
+ "@dxos/react-ui-tag-picker": "0.8.2-main.2f9c567",
77
+ "@dxos/react-ui-syntax-highlighter": "0.8.2-main.2f9c567",
78
+ "@dxos/react-ui-types": "0.8.2-main.2f9c567",
79
+ "@dxos/schema": "0.8.2-main.2f9c567",
80
+ "@dxos/util": "0.8.2-main.2f9c567"
79
81
  },
80
82
  "devDependencies": {
81
83
  "@phosphor-icons/react": "^2.1.5",
@@ -86,19 +88,19 @@
86
88
  "react": "~18.2.0",
87
89
  "react-dom": "~18.2.0",
88
90
  "vite": "5.4.7",
89
- "@dxos/random": "0.8.2-main.12df754",
90
- "@dxos/echo-signals": "0.8.2-main.12df754",
91
- "@dxos/react-ui": "0.8.2-main.12df754",
92
- "@dxos/react-ui-theme": "0.8.2-main.12df754",
93
- "@dxos/storybook-utils": "0.8.2-main.12df754",
94
- "@dxos/test-utils": "0.8.2-main.12df754"
91
+ "@dxos/echo-signals": "0.8.2-main.2f9c567",
92
+ "@dxos/random": "0.8.2-main.2f9c567",
93
+ "@dxos/react-ui": "0.8.2-main.2f9c567",
94
+ "@dxos/react-ui-theme": "0.8.2-main.2f9c567",
95
+ "@dxos/storybook-utils": "0.8.2-main.2f9c567",
96
+ "@dxos/test-utils": "0.8.2-main.2f9c567"
95
97
  },
96
98
  "peerDependencies": {
97
99
  "@phosphor-icons/react": "^2.1.5",
98
100
  "react": "~18.2.0",
99
101
  "react-dom": "~18.2.0",
100
- "@dxos/react-ui": "0.8.2-main.12df754",
101
- "@dxos/react-ui-theme": "0.8.2-main.12df754"
102
+ "@dxos/react-ui": "0.8.2-main.2f9c567",
103
+ "@dxos/react-ui-theme": "0.8.2-main.2f9c567"
102
104
  },
103
105
  "publishConfig": {
104
106
  "access": "public"
@@ -2,9 +2,9 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { Schema } from 'effect';
5
6
  import React, { useCallback, useMemo } from 'react';
6
7
 
7
- import { S } from '@dxos/echo-schema';
8
8
  import { live } from '@dxos/react-client/echo';
9
9
  import { Popover } from '@dxos/react-ui';
10
10
  import { Form } from '@dxos/react-ui-form';
@@ -20,14 +20,14 @@ export const CreateRefPanel = ({ model, modals, __gridScope }: GridScopedProps<C
20
20
  const space = model?.space;
21
21
  const state = modals.state.value;
22
22
 
23
- const schema = useMemo<S.Schema<any> | undefined>(() => {
23
+ const schema = useMemo<Schema.Schema<any> | undefined>(() => {
24
24
  if (!space || state?.type !== 'createRefPanel') {
25
25
  return;
26
26
  }
27
27
 
28
28
  const [schema] = space.db.schemaRegistry.query({ typename: state.typename }).runSync();
29
29
  if (schema) {
30
- const omit = S.omit<any, any, ['id']>('id');
30
+ const omit = Schema.omit<any, any, ['id']>('id');
31
31
  return omit(schema);
32
32
  }
33
33
  }, [space, state]);
@@ -28,8 +28,7 @@ import { TableType } from '../../types';
28
28
  import { initializeTable } from '../../util';
29
29
  import { TableToolbar } from '../TableToolbar';
30
30
 
31
- // NOTE(ZaymonFC): We rely on this seed being 0 in the smoke tests.
32
- faker.seed(0);
31
+ faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
33
32
 
34
33
  /**
35
34
  * Custom hook to create and manage a test table model for storybook demonstrations.
@@ -247,7 +246,7 @@ export const StaticSchema: StoryObj = {
247
246
  parameters: { translations },
248
247
  decorators: [
249
248
  withClientProvider({
250
- types: [TableType, ViewType, Testing.Contact, Testing.Org],
249
+ types: [TableType, ViewType, Testing.Contact, Testing.Organization],
251
250
  createIdentity: true,
252
251
  createSpace: true,
253
252
  onSpaceCreated: async ({ client, space }) => {
@@ -257,7 +256,7 @@ export const StaticSchema: StoryObj = {
257
256
  const factory = createObjectFactory(space.db, faker as any);
258
257
  await factory([
259
258
  { type: Testing.Contact, count: 10 },
260
- { type: Testing.Org, count: 1 },
259
+ { type: Testing.Organization, count: 1 },
261
260
  ]);
262
261
  },
263
262
  }),
@@ -19,27 +19,29 @@ import { invariant } from '@dxos/invariant';
19
19
  import { Filter } from '@dxos/react-client/echo';
20
20
  import { useTranslation } from '@dxos/react-ui';
21
21
  import { useAttention } from '@dxos/react-ui-attention';
22
- import { closestCell, type DxGridElement, type DxGridPosition, type GridContentProps, Grid } from '@dxos/react-ui-grid';
22
+ import {
23
+ closestCell,
24
+ type DxGridElement,
25
+ type DxGridPosition,
26
+ type GridContentProps,
27
+ Grid,
28
+ type DxGridPlane,
29
+ type DxGridPlaneRange,
30
+ gridSeparatorInlineEnd,
31
+ gridSeparatorBlockEnd,
32
+ } from '@dxos/react-ui-grid';
23
33
  import { mx } from '@dxos/react-ui-theme';
24
34
  import { isNotFalsy, safeParseInt } from '@dxos/util';
25
35
 
26
36
  import { ColumnActionsMenu } from './ColumnActionsMenu';
27
37
  import { ColumnSettings } from './ColumnSettings';
28
38
  import { CreateRefPanel } from './CreateRefPanel';
29
- import { RefPanel } from './RefPanel';
30
39
  import { RowActionsMenu } from './RowActionsMenu';
31
40
  import { ModalController, type TableModel, type TablePresentation } from '../../model';
32
41
  import { translationKey } from '../../translations';
33
42
  import { tableButtons, tableControls } from '../../util';
34
43
  import { createOption, TableCellEditor, type TableCellEditorProps } from '../TableCellEditor';
35
44
 
36
- // NOTE(Zan): These fragments add border to inline-end and block-end of the grid using pseudo-elements.
37
- // These are offset by 1px to avoid double borders in planks.
38
- const inlineEndLine =
39
- '[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator';
40
- const blockEndLine =
41
- '[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator';
42
-
43
45
  //
44
46
  // Table.Root
45
47
  //
@@ -98,20 +100,17 @@ const TableMain = forwardRef<TableController, TableMainProps>(
98
100
  };
99
101
  }, [model]);
100
102
 
101
- // TODO(burdon): Replace useEffect below.
102
- // const getCells = useCallback<GridContentProps['getCells']>(
103
- // (range: DxGridRange, plane: DxGridPlane) => presentation?.getCells(range, plane) ?? {},
104
- // [presentation],
105
- // );
103
+ const getCells = useCallback<NonNullable<GridContentProps['getCells']>>(
104
+ (range: DxGridPlaneRange, plane: DxGridPlane) => presentation?.getCells(range, plane) ?? {},
105
+ [presentation],
106
+ );
106
107
 
107
108
  useEffect(() => {
108
109
  if (!presentation || !dxGrid) {
109
110
  return;
110
111
  }
111
-
112
- // TODO(burdon): Pass to Grid.Content?
113
- dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
114
- }, [presentation, dxGrid]);
112
+ dxGrid.getCells = getCells;
113
+ }, [presentation, dxGrid, getCells]);
115
114
 
116
115
  /**
117
116
  * Provides an external controller that can be called to repaint the table.
@@ -181,10 +180,6 @@ const TableMain = forwardRef<TableController, TableMainProps>(
181
180
  modals.showColumnCreator();
182
181
  break;
183
182
  }
184
- case 'referencedCell': {
185
- modals.showReferencePanel(data.targetId, data.schemaId);
186
- break;
187
- }
188
183
  case 'sort': {
189
184
  model?.sorting?.toggleSort(data.fieldId);
190
185
  break;
@@ -356,7 +351,7 @@ const TableMain = forwardRef<TableController, TableMainProps>(
356
351
  onQuery={handleQuery}
357
352
  />
358
353
  <Grid.Content
359
- className={mx('[--dx-grid-base:var(--surface-bg)]', inlineEndLine, blockEndLine)}
354
+ className={mx('[--dx-grid-base:var(--surface-bg)]', gridSeparatorInlineEnd, gridSeparatorBlockEnd)}
360
355
  frozen={frozen}
361
356
  // getCells={getCells}
362
357
  columns={model.columnMeta.value}
@@ -373,7 +368,6 @@ const TableMain = forwardRef<TableController, TableMainProps>(
373
368
  <ColumnActionsMenu model={model} modals={modals} />
374
369
  <ColumnSettings model={model} modals={modals} onNewColumn={handleNewColumn} />
375
370
  <CreateRefPanel model={model} modals={modals} />
376
- <RefPanel model={model} modals={modals} />
377
371
  </Grid.Root>
378
372
  );
379
373
  },
@@ -5,20 +5,21 @@
5
5
  import '@dxos-theme';
6
6
 
7
7
  import { type StoryObj, type Meta } from '@storybook/react';
8
+ import { SchemaAST } from 'effect';
8
9
  import React, { useEffect, useMemo } from 'react';
9
10
 
10
- import { AST, type BaseObject, ImmutableSchema, type BaseSchema, type HasId } from '@dxos/echo-schema';
11
+ import { type BaseObject, ImmutableSchema, type BaseSchema, type HasId } from '@dxos/echo-schema';
11
12
  import { getAnnotation } from '@dxos/effect';
12
13
  import { faker } from '@dxos/random';
13
- import { live, makeRef, type Live } from '@dxos/react-client/echo';
14
- import { withClientProvider } from '@dxos/react-client/testing';
15
- import { createView, ViewProjection, ViewType } from '@dxos/schema';
16
- import { createGenerator, Testing, type ValueGenerator } from '@dxos/schema/testing';
14
+ import { live, makeRef } from '@dxos/react-client/echo';
15
+ import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
16
+ import { DataType, createView, ViewProjection, ViewType } from '@dxos/schema';
17
+ import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
17
18
  import { withLayout, withTheme } from '@dxos/storybook-utils';
18
19
 
19
20
  import { Table } from './Table';
20
21
  import { useTableModel } from '../../hooks';
21
- import { TablePresentation, type TableRow } from '../../model';
22
+ import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
22
23
  import translations from '../../translations';
23
24
  import { TableType } from '../../types';
24
25
 
@@ -30,10 +31,12 @@ const generator: ValueGenerator = faker as any;
30
31
  // TODO(burdon): Reconcile schemas types and utils (see API PR).
31
32
  // TODO(burdon): Base type for T (with id); see ECHO API PR?
32
33
  const useTestModel = <T extends BaseObject & HasId>(schema: BaseSchema<T>, count: number) => {
34
+ const { space } = useClientProvider();
35
+
33
36
  const table = useMemo(() => {
34
- // const { typename } = pipe(schema.ast, AST.getAnnotation<TypeAnnotation>(TypeAnnotationId), Option.getOrThrow);
37
+ // const { typename } = pipe(schema.ast, SchemaAST.getAnnotation<TypeAnnotation>(TypeAnnotationId), Option.getOrThrow);
35
38
  const typename = schema.typename;
36
- const name = getAnnotation<string>(AST.TitleAnnotationId)(schema.ast) ?? typename;
39
+ const name = getAnnotation<string>(SchemaAST.TitleAnnotationId)(schema.ast) ?? typename;
37
40
  const view = createView({ name, typename, jsonSchema: schema.jsonSchema });
38
41
  return live(TableType, { view: makeRef(view) });
39
42
  }, [schema]);
@@ -47,16 +50,24 @@ const useTestModel = <T extends BaseObject & HasId>(schema: BaseSchema<T>, count
47
50
  return new ViewProjection(schema.jsonSchema, table.view.target);
48
51
  }, [schema, table]);
49
52
 
50
- const model = useTableModel<TableRow>({ table, projection, rows: [] });
53
+ const features = useMemo<TableFeatures>(
54
+ () => ({ schemaEditable: false, dataEditable: true, selection: { enabled: false } }),
55
+ [],
56
+ );
57
+
58
+ const model = useTableModel<TableRow>({ table, projection, rows: [], features });
51
59
  useEffect(() => {
52
- if (!model) {
60
+ if (!model || !space) {
53
61
  return;
54
62
  }
55
63
 
56
- const objectGenerator = createGenerator(generator, schema, { optional: true });
57
- const objects: Live<T>[] = Array.from({ length: count }).map(() => objectGenerator.createObject());
58
- model.setRows(objects);
59
- }, [model]);
64
+ const objectGenerator = createAsyncGenerator(generator, schema, { optional: true, db: space?.db });
65
+ void objectGenerator.createObjects(count).then((objects) => {
66
+ model.setRows(objects);
67
+ });
68
+ }, [model, space]);
69
+
70
+ console.log(projection?.getFieldProjections());
60
71
 
61
72
  const presentation = useMemo(() => {
62
73
  if (!model) {
@@ -71,21 +82,20 @@ const useTestModel = <T extends BaseObject & HasId>(schema: BaseSchema<T>, count
71
82
 
72
83
  const DefaultStory = () => {
73
84
  // TODO(burdon): Remove need for ImmutableSchema wrapper at API-level.
74
- const orgSchema = useMemo(() => new ImmutableSchema(Testing.Org), []);
75
- const { model: orgModel, presentation: orgPresentation } = useTestModel<Testing.Org>(orgSchema, 50);
85
+ const orgSchema = useMemo(() => new ImmutableSchema(DataType.Organization), []);
86
+ const { model: orgModel, presentation: orgPresentation } = useTestModel<DataType.Organization>(orgSchema, 50);
76
87
 
77
88
  // TODO(burdon): Generate links with references.
78
- const contactSchema = useMemo(() => new ImmutableSchema(Testing.Contact), []);
79
- const { model: contactModel, presentation: contactPresentation } = useTestModel<Testing.Contact>(contactSchema, 50);
89
+ const contactSchema = useMemo(() => new ImmutableSchema(DataType.Person), []);
90
+ const { model: contactModel, presentation: contactPresentation } = useTestModel<DataType.Person>(contactSchema, 50);
80
91
 
81
- // TODO(burdon): Scrolling isn't working.
82
92
  return (
83
- <div className='grow grid grid-cols-2 divide-x divide-separator'>
93
+ <div className='is-full bs-full grid grid-cols-2 divide-x divide-separator'>
84
94
  <Table.Root>
85
- <Table.Main model={orgModel} presentation={orgPresentation} />
95
+ <Table.Main model={orgModel} presentation={orgPresentation} ignoreAttention />
86
96
  </Table.Root>
87
97
  <Table.Root>
88
- <Table.Main model={contactModel} presentation={contactPresentation} />
98
+ <Table.Main model={contactModel} presentation={contactPresentation} ignoreAttention />
89
99
  </Table.Root>
90
100
  </div>
91
101
  );
@@ -97,7 +107,7 @@ const meta: Meta<typeof DefaultStory> = {
97
107
  parameters: { translations },
98
108
  decorators: [
99
109
  withClientProvider({
100
- types: [TableType, ViewType, Testing.Org, Testing.Contact],
110
+ types: [TableType, ViewType, DataType.Organization, DataType.Person],
101
111
  createIdentity: true,
102
112
  createSpace: true,
103
113
  }),
@@ -2,9 +2,10 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { Schema } from 'effect';
5
6
  import { useEffect } from 'react';
6
7
 
7
- import { setValue, toJsonSchema, S, TypeEnum, TypedObject, FormatEnum } from '@dxos/echo-schema';
8
+ import { setValue, toJsonSchema, TypeEnum, TypedObject, FormatEnum, ObjectId } from '@dxos/echo-schema';
8
9
  import { faker } from '@dxos/random';
9
10
  import { live, makeRef } from '@dxos/react-client/echo';
10
11
  import { createView, type ViewProjection } from '@dxos/schema';
@@ -12,11 +13,11 @@ import { createView, type ViewProjection } from '@dxos/schema';
12
13
  import { TableType } from '../types';
13
14
 
14
15
  export const TestSchema = TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
15
- id: S.String,
16
- name: S.optional(S.String),
17
- age: S.optional(S.Number),
18
- active: S.optional(S.Boolean),
19
- netWorth: S.optional(S.Number),
16
+ id: ObjectId,
17
+ name: Schema.optional(Schema.String),
18
+ age: Schema.optional(Schema.Number),
19
+ active: Schema.optional(Schema.Boolean),
20
+ netWorth: Schema.optional(Schema.Number),
20
21
  });
21
22
 
22
23
  export const createTable = (schema = TestSchema) => {
@@ -3,9 +3,10 @@
3
3
  //
4
4
 
5
5
  import { computed } from '@preact/signals-core';
6
+ import { Schema } from 'effect';
6
7
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
7
8
 
8
- import { S, TypedObject } from '@dxos/echo-schema';
9
+ import { TypedObject } from '@dxos/echo-schema';
9
10
  import { updateCounter } from '@dxos/echo-schema/testing';
10
11
  import { registerSignalsRuntime } from '@dxos/echo-signals';
11
12
  import { createEchoSchema } from '@dxos/live-object/testing';
@@ -99,8 +100,8 @@ describe('TableModel', () => {
99
100
  });
100
101
 
101
102
  class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
102
- title: S.String,
103
- completed: S.Boolean,
103
+ title: Schema.String,
104
+ completed: Schema.Boolean,
104
105
  }) {}
105
106
 
106
107
  const createTableModel = (props: Partial<TableModelProps> = {}): TableModel => {
@@ -21,6 +21,7 @@ import { type ViewType, type ViewProjection } from '@dxos/schema';
21
21
  import { type SelectionMode, SelectionModel } from './selection-model';
22
22
  import { TableSorting } from './table-sorting';
23
23
  import { touch } from '../util';
24
+ import { extractTagIds } from '../util/tag';
24
25
 
25
26
  // TODO(burdon): Use schema types.
26
27
  export type TableRow = Record<JsonProp, any> & { id: string };
@@ -348,6 +349,22 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
348
349
  break;
349
350
  }
350
351
 
352
+ case FormatEnum.SingleSelect: {
353
+ const ids = extractTagIds(value);
354
+ if (ids && ids.length > 0) {
355
+ setValue(this._rows.value[rowIdx], field.path, ids[0]);
356
+ }
357
+ break;
358
+ }
359
+
360
+ case FormatEnum.MultiSelect: {
361
+ const ids = extractTagIds(value);
362
+ if (ids) {
363
+ setValue(this._rows.value[rowIdx], field.path, ids);
364
+ }
365
+ break;
366
+ }
367
+
351
368
  default: {
352
369
  setValue(
353
370
  this._rows.value[rowIdx],
@@ -2,9 +2,10 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { Schema } from 'effect';
5
6
  import { describe, expect, it, beforeEach } from 'vitest';
6
7
 
7
- import { S, TypedObject } from '@dxos/echo-schema';
8
+ import { TypedObject } from '@dxos/echo-schema';
8
9
  import { live, makeRef } from '@dxos/live-object';
9
10
  import { createEchoSchema } from '@dxos/live-object/testing';
10
11
  import { createView, ViewProjection } from '@dxos/schema';
@@ -89,8 +90,8 @@ describe('TablePresentation', () => {
89
90
  });
90
91
 
91
92
  class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
92
- title: S.String,
93
- completed: S.Boolean,
93
+ title: Schema.String,
94
+ completed: Schema.Boolean,
94
95
  }) {}
95
96
 
96
97
  const createTableModel = (props: Partial<TableModelProps> = {}): TableModel => {
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { signal } from '@preact/signals-core';
6
6
 
7
- import { FormatEnum, getValue } from '@dxos/echo-schema';
7
+ import { FormatEnum, getDXN, getValue } from '@dxos/echo-schema';
8
8
  import { cellClassesForFieldType, formatForDisplay } from '@dxos/react-ui-form';
9
9
  import {
10
10
  type DxGridPlane,
@@ -124,10 +124,8 @@ export class TablePresentation<T extends TableRow = TableRow> {
124
124
  if (props.format === FormatEnum.Ref && props.referenceSchema) {
125
125
  const targetObj = getValue(obj, field.path)?.target;
126
126
  if (targetObj) {
127
- cell.accessoryHtml = tableButtons.referencedCell.render({
128
- targetId: targetObj.id as any as string,
129
- schemaId: props.referenceSchema,
130
- });
127
+ const dxn = getDXN(targetObj)?.toString();
128
+ cell.accessoryHtml = `<dx-ref-tag ref=${dxn} class="dx-button block is-6 pli-[3px] plb-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
131
129
  }
132
130
  }
133
131
 
@@ -2,20 +2,28 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { EchoObject, Expando, LabelAnnotationId, ObjectId, Ref, S } from '@dxos/echo-schema';
5
+ import { Schema } from 'effect';
6
+
7
+ import { Type } from '@dxos/echo';
6
8
  // import { ThreadType } from '@dxos/plugin-space/types';
9
+ import { LabelAnnotationId } from '@dxos/echo-schema';
7
10
  import { ViewType } from '@dxos/schema';
8
11
 
9
- export const TableSchema = S.Struct({
10
- id: ObjectId,
11
- name: S.optional(S.String),
12
- view: S.optional(Ref(ViewType)),
12
+ export const TableSchema = Schema.Struct({
13
+ id: Type.ObjectId,
14
+ name: Schema.optional(Schema.String),
15
+ view: Schema.optional(Type.Ref(ViewType)),
13
16
  // TODO(burdon): Document why threads is included here?
14
- threads: S.optional(S.Array(Ref(Expando /* ThreadType */))),
17
+ threads: Schema.optional(Schema.Array(Type.Ref(Type.Expando /* ThreadType */))),
15
18
  }).annotations({
16
19
  // TODO(burdon): Move annotation to property.
17
20
  [LabelAnnotationId]: 'name',
18
21
  });
19
22
 
20
- export const TableType = TableSchema.pipe(EchoObject({ typename: 'dxos.org/type/Table', version: '0.1.0' }));
21
- export interface TableType extends S.Schema.Type<typeof TableType> {}
23
+ export const TableType = TableSchema.pipe(
24
+ Type.def({
25
+ typename: 'dxos.org/type/Table',
26
+ version: '0.1.0',
27
+ }),
28
+ );
29
+ export interface TableType extends Schema.Schema.Type<typeof TableType> {}
@@ -15,7 +15,6 @@ export const BUTTON_IDENTIFIERS: { [K in TableButton]: string } = {
15
15
  type ButtonData =
16
16
  | { type: 'columnSettings'; fieldId: string }
17
17
  | { type: 'newColumn'; disabled?: boolean }
18
- | { type: 'referencedCell'; schemaId: string; targetId: string }
19
18
  | { type: 'rowMenu'; rowIndex: number }
20
19
  | { type: 'sort'; fieldId: string; direction?: 'asc' | 'desc' };
21
20
 
@@ -76,27 +75,6 @@ const columnSettingsButton = {
76
75
  }),
77
76
  } as const;
78
77
 
79
- const referencedCellButton = {
80
- attr: BUTTON_IDENTIFIERS.referencedCell,
81
- icon: 'ph--link-simple-horizontal--regular',
82
- render: ({ targetId, schemaId }: Omit<Extract<ButtonData, { type: 'referencedCell' }>, 'type'>) => {
83
- return createButton({
84
- attr: BUTTON_IDENTIFIERS.referencedCell,
85
- icon: referencedCellButton.icon,
86
- data: {
87
- 'data-target-id': targetId,
88
- 'data-schema-id': schemaId,
89
- },
90
- testId: 'table-ref-cell-button',
91
- });
92
- },
93
- getData: (el: HTMLElement): Extract<ButtonData, { type: 'referencedCell' }> => ({
94
- type: 'referencedCell',
95
- targetId: el.getAttribute('data-target-id')!,
96
- schemaId: el.getAttribute('data-schema-id')!,
97
- }),
98
- } as const;
99
-
100
78
  const rowMenuButton = {
101
79
  attr: BUTTON_IDENTIFIERS.rowMenu,
102
80
  icon: 'ph--dots-three--regular',
@@ -143,7 +121,6 @@ const sortButton = {
143
121
  export const tableButtons = {
144
122
  addColumn: addColumnButton,
145
123
  columnSettings: columnSettingsButton,
146
- referencedCell: referencedCellButton,
147
124
  rowMenu: rowMenuButton,
148
125
  sort: sortButton,
149
126
  } as const;
package/src/util/table.ts CHANGED
@@ -2,14 +2,14 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { Schema, SchemaAST } from 'effect';
6
+
5
7
  import {
6
- AST,
7
8
  type EchoSchema,
8
9
  Format,
9
10
  FormatEnum,
10
11
  type JsonPath,
11
12
  type JsonProp,
12
- S,
13
13
  TypedObject,
14
14
  TypeEnum,
15
15
  } from '@dxos/echo-schema';
@@ -34,18 +34,14 @@ export const initializeTable = async ({
34
34
  table,
35
35
  typename,
36
36
  initialRow = true,
37
- }: InitialiseTableProps): Promise<S.Schema.AnyNoContext> => {
37
+ }: InitialiseTableProps): Promise<Schema.Schema.AnyNoContext> => {
38
38
  if (typename) {
39
39
  const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
40
40
  if (!schema) {
41
41
  throw new Error(`Schema not found: ${typename}`);
42
42
  }
43
43
 
44
- // We need to get the schema properties here.
45
- // For now, only simple types and refs, not compound types are going to be supported.
46
- const fields = getSchemaProperties(schema.ast)
47
- .filter((prop) => prop.format !== FormatEnum.Ref)
48
- .map((prop) => prop.name);
44
+ const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
49
45
 
50
46
  table.view = makeRef(
51
47
  createView({
@@ -86,10 +82,10 @@ const ContactSchema = TypedObject({
86
82
  typename: `example.com/type/${PublicKey.random().truncate()}`,
87
83
  version: '0.1.0',
88
84
  })({
89
- name: S.optional(S.String).annotations({ [AST.TitleAnnotationId]: 'Name' }),
90
- active: S.optional(S.Boolean),
91
- email: S.optional(Format.Email),
92
- salary: S.optional(Format.Currency()).annotations({ [AST.TitleAnnotationId]: 'Salary' }),
85
+ name: Schema.optional(Schema.String).annotations({ [SchemaAST.TitleAnnotationId]: 'Name' }),
86
+ active: Schema.optional(Schema.Boolean),
87
+ email: Schema.optional(Format.Email),
88
+ salary: Schema.optional(Format.Currency()).annotations({ [SchemaAST.TitleAnnotationId]: 'Salary' }),
93
89
  });
94
90
 
95
91
  const ContactFields = ['name', 'email', 'salary', 'active'];
@@ -0,0 +1,33 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ // TODO(ZaymonFC): Push this into the tag picker module.
6
+
7
+ /**
8
+ * Regex pattern for matching tags in the format [Label](id)
9
+ */
10
+ export const TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
11
+
12
+ /**
13
+ * Extracts tag IDs from a string in the format [Label](id)
14
+ * @param value The string to extract IDs from
15
+ * @returns Array of extracted IDs or undefined if no matches or value is not a string
16
+ */
17
+ export const extractTagIds = (value: unknown): string[] | undefined => {
18
+ if (typeof value !== 'string') {
19
+ return undefined;
20
+ }
21
+
22
+ const ids: string[] = [];
23
+ let match;
24
+
25
+ // Use the global regex to find all matches
26
+ while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
27
+ if (match[2]) {
28
+ ids.push(match[2]);
29
+ }
30
+ }
31
+
32
+ return ids.length > 0 ? ids : undefined;
33
+ };