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

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 (158) hide show
  1. package/dist/lib/browser/chunk-DSR2MRZB.mjs +80 -0
  2. package/dist/lib/browser/chunk-DSR2MRZB.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-PTHMYAAM.mjs +1751 -0
  4. package/dist/lib/browser/chunk-PTHMYAAM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1190 -1139
  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 +31 -38
  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-GI72MQSG.mjs +1753 -0
  12. package/dist/lib/node-esm/chunk-GI72MQSG.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-HTZJSULI.mjs +81 -0
  14. package/dist/lib/node-esm/chunk-HTZJSULI.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1190 -1139
  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 +31 -38
  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 +2 -3
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +3 -3
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +37 -3
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.d.ts +17 -13
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +108 -4
  36. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +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 +13 -9
  40. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +11 -18
  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 -4
  44. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  46. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  47. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +5 -5
  48. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  49. package/dist/types/src/components/testing.d.ts +23 -16
  50. package/dist/types/src/components/testing.d.ts.map +1 -1
  51. package/dist/types/src/hooks/index.d.ts +2 -1
  52. package/dist/types/src/hooks/index.d.ts.map +1 -1
  53. package/dist/types/src/hooks/useAddRow.d.ts +6 -6
  54. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  55. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  56. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  57. package/dist/types/src/hooks/useTableModel.d.ts +10 -10
  58. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  59. package/dist/types/src/model/modal-controller.d.ts +5 -8
  60. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  61. package/dist/types/src/model/selection-model.d.ts +17 -8
  62. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  63. package/dist/types/src/model/table-model.d.ts +112 -30
  64. package/dist/types/src/model/table-model.d.ts.map +1 -1
  65. package/dist/types/src/model/table-presentation.d.ts +5 -2
  66. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  67. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  68. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  69. package/dist/types/src/testing/useTestTableModel.d.ts +18 -34
  70. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  71. package/dist/types/src/translations.d.ts +4 -4
  72. package/dist/types/src/translations.d.ts.map +1 -1
  73. package/dist/types/src/types/Table.d.ts +31 -0
  74. package/dist/types/src/types/Table.d.ts.map +1 -0
  75. package/dist/types/src/types/index.d.ts +1 -1
  76. package/dist/types/src/types/index.d.ts.map +1 -1
  77. package/dist/types/src/util/dynamic-table.d.ts +14 -12
  78. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  79. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  80. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  81. package/dist/types/src/util/index.d.ts +2 -1
  82. package/dist/types/src/util/index.d.ts.map +1 -1
  83. package/dist/types/src/util/query-ast.d.ts +7 -0
  84. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  85. package/dist/types/src/util/schema.d.ts +1 -1
  86. package/dist/types/src/util/schema.d.ts.map +1 -1
  87. package/dist/types/src/util/sort.d.ts +12 -0
  88. package/dist/types/src/util/sort.d.ts.map +1 -0
  89. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  90. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  91. package/dist/types/tsconfig.tsbuildinfo +1 -1
  92. package/package.json +61 -56
  93. package/src/components/Table/ColumnActionsMenu.tsx +11 -7
  94. package/src/components/Table/ColumnSettings.tsx +9 -10
  95. package/src/components/Table/DynamicTable.stories.tsx +28 -24
  96. package/src/components/Table/DynamicTable.tsx +33 -27
  97. package/src/components/Table/Relations.stories.tsx +240 -0
  98. package/src/components/Table/RowActionsMenu.tsx +26 -17
  99. package/src/components/Table/Table.stories.tsx +146 -116
  100. package/src/components/Table/Table.tsx +353 -297
  101. package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -6
  102. package/src/components/TableCellEditor/FormCellEditor.tsx +134 -40
  103. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +31 -66
  104. package/src/components/TableCellEditor/TableCellEditor.tsx +88 -238
  105. package/src/components/TableCellEditor/index.ts +1 -0
  106. package/src/components/TableToolbar/TableToolbar.tsx +54 -38
  107. package/src/components/testing.ts +39 -13
  108. package/src/hooks/index.ts +2 -1
  109. package/src/hooks/useAddRow.ts +14 -14
  110. package/src/hooks/useProjectionModel.ts +39 -0
  111. package/src/hooks/useTableModel.ts +36 -34
  112. package/src/model/modal-controller.ts +24 -41
  113. package/src/model/selection-model.ts +75 -43
  114. package/src/model/table-model.test.ts +92 -55
  115. package/src/model/table-model.ts +453 -175
  116. package/src/model/table-presentation.test.ts +70 -58
  117. package/src/model/table-presentation.ts +111 -64
  118. package/src/playwright/TableManager.ts +13 -6
  119. package/src/playwright/playwright.config.ts +1 -1
  120. package/src/playwright/smoke.spec.ts +171 -33
  121. package/src/testing/useTestTableModel.ts +46 -35
  122. package/src/translations.ts +3 -3
  123. package/src/types/Table.ts +95 -0
  124. package/src/types/index.ts +1 -1
  125. package/src/util/dynamic-table.test.ts +70 -0
  126. package/src/util/dynamic-table.ts +46 -33
  127. package/src/util/index.ts +2 -1
  128. package/src/util/query-ast.ts +22 -0
  129. package/src/util/schema.ts +4 -4
  130. package/src/util/sort.ts +90 -0
  131. package/src/util/table-buttons.ts +4 -3
  132. package/src/util/table-controls.ts +6 -3
  133. package/dist/lib/browser/chunk-5XLSHLOG.mjs +0 -1751
  134. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  136. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  137. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  138. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  139. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs +0 -1752
  140. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
  141. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  142. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  143. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  144. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  145. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  146. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  147. package/dist/types/src/model/table-sorting.d.ts +0 -53
  148. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  149. package/dist/types/src/types/schema.d.ts +0 -8
  150. package/dist/types/src/types/schema.d.ts.map +0 -1
  151. package/dist/types/src/util/table.d.ts +0 -11
  152. package/dist/types/src/util/table.d.ts.map +0 -1
  153. package/src/components/Table/CreateRefPanel.tsx +0 -86
  154. package/src/components/Table/relations.stories.tsx +0 -116
  155. package/src/components/TableCellEditor/extension.ts +0 -61
  156. package/src/model/table-sorting.ts +0 -216
  157. package/src/types/schema.ts +0 -16
  158. package/src/util/table.ts +0 -49
@@ -1,116 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
8
- import React, { useEffect, useMemo, useState } from 'react';
9
-
10
- import { Type } from '@dxos/echo';
11
- import { type JsonSchemaType } from '@dxos/echo-schema';
12
- import { faker } from '@dxos/random';
13
- import { useClient } from '@dxos/react-client';
14
- import { useClientProvider, withClientProvider } from '@dxos/react-client/testing';
15
- import { DataType } from '@dxos/schema';
16
- import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
17
- import { withLayout, withTheme } from '@dxos/storybook-utils';
18
-
19
- import { Table } from './Table';
20
- import { useTableModel } from '../../hooks';
21
- import { type TableFeatures, TablePresentation, type TableRow } from '../../model';
22
- import { translations } from '../../translations';
23
- import { TableView } from '../../types';
24
- import { createTable } from '../../util';
25
-
26
- faker.seed(1);
27
- const generator: ValueGenerator = faker as any;
28
-
29
- // TODO(burdon): Many-to-many relations.
30
- // TODO(burdon): Mutable and immutable views.
31
- // TODO(burdon): Reconcile schemas types and utils (see API PR).
32
- // TODO(burdon): Base type for T (with id); see ECHO API PR?
33
- const useTestModel = <S extends Type.Obj.Any>(schema: S, count: number) => {
34
- const client = useClient();
35
- const { space } = useClientProvider();
36
- const [view, setView] = useState<DataType.View>();
37
- const [jsonSchema, setJsonSchema] = useState<JsonSchemaType>();
38
-
39
- const features = useMemo<TableFeatures>(
40
- () => ({ schemaEditable: false, dataEditable: true, selection: { enabled: false } }),
41
- [],
42
- );
43
-
44
- useEffect(() => {
45
- if (!space) {
46
- return;
47
- }
48
-
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);
55
- }, [client, space, schema]);
56
-
57
- const model = useTableModel<TableRow>({ view, schema: jsonSchema, rows: [], features });
58
- useEffect(() => {
59
- if (!model || !space) {
60
- return;
61
- }
62
-
63
- const objectGenerator = createAsyncGenerator(generator, schema, { db: space?.db, force: true });
64
- void objectGenerator.createObjects(count).then((objects) => {
65
- model.setRows(objects);
66
- });
67
- }, [model, space]);
68
-
69
- const presentation = useMemo(() => {
70
- if (!model) {
71
- return;
72
- }
73
-
74
- return new TablePresentation(model);
75
- }, [model]);
76
-
77
- return { model, presentation };
78
- };
79
-
80
- const DefaultStory = () => {
81
- const client = useClient();
82
- const { model: orgModel, presentation: orgPresentation } = useTestModel(DataType.Organization, 50);
83
- const { model: contactModel, presentation: contactPresentation } = useTestModel(DataType.Person, 50);
84
-
85
- return (
86
- <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>
93
- </div>
94
- );
95
- };
96
-
97
- const meta: Meta<typeof DefaultStory> = {
98
- title: 'ui/react-ui-table/relations',
99
- render: DefaultStory,
100
- parameters: { translations, controls: { disable: true } },
101
- decorators: [
102
- withClientProvider({
103
- types: [DataType.View, DataType.Organization, DataType.Person, TableView],
104
- createIdentity: true,
105
- createSpace: true,
106
- }),
107
- withTheme,
108
- withLayout({ fullscreen: true }),
109
- ],
110
- };
111
-
112
- export default meta;
113
-
114
- type Story = StoryObj<typeof DefaultStory>;
115
-
116
- export const Default: Story = {};
@@ -1,61 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import {
6
- autocompletion,
7
- pickedCompletion,
8
- type CompletionContext,
9
- type CompletionResult,
10
- } from '@codemirror/autocomplete';
11
- import { type Extension } from '@codemirror/state';
12
- import { EditorView } from '@codemirror/view';
13
-
14
- export type CompletionOptions = {
15
- debug?: boolean;
16
- onQuery: (text: string) => Promise<CompletionResult['options']>;
17
- onMatch: (data: any) => void;
18
- };
19
-
20
- /**
21
- * Autocomplete Codemirror extension.
22
- * https://codemirror.net/docs/ref/#autocomplete.autocompletion
23
- */
24
- export const completion = ({ debug, onQuery, onMatch }: CompletionOptions): Extension => {
25
- return [
26
- EditorView.theme({
27
- '.cm-completionDialog': {
28
- width: 'var(--dx-gridCellWidth)',
29
- },
30
- }),
31
-
32
- autocompletion({
33
- icons: false,
34
- activateOnTyping: true,
35
- closeOnBlur: !debug,
36
- override: [
37
- async (context: CompletionContext): Promise<CompletionResult> => {
38
- const text = context.state.doc.toString();
39
- return {
40
- from: 0,
41
- options: await onQuery(text),
42
- };
43
- },
44
- ],
45
-
46
- // TODO(burdon): Consts from grid (to line-up with grid).
47
- tooltipClass: () => 'cm-completionDialog !mt-[8px] !-ml-[4px] [&>ul]:!max-h-[264px]',
48
- optionClass: () => 'flex h-[33px] items-center',
49
- }),
50
-
51
- // Check for accepted completion metadata in the transaction.
52
- EditorView.updateListener.of((update) => {
53
- update.transactions.forEach((tr) => {
54
- const completion = tr.annotation(pickedCompletion);
55
- if (completion) {
56
- onMatch((completion as any).data);
57
- }
58
- });
59
- }),
60
- ];
61
- };
@@ -1,216 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { computed, signal, type Signal, type ReadonlySignal } from '@preact/signals-core';
6
- import orderBy from 'lodash.orderby';
7
-
8
- import { getValue, FormatEnum, TypeEnum, type SortDirectionType, type FieldSortType } from '@dxos/echo-schema';
9
- import { formatForDisplay } from '@dxos/react-ui-form';
10
- import type { PropertyType, FieldType, DataType, ProjectionModel } from '@dxos/schema';
11
-
12
- import { type TableRow } from './table-model';
13
-
14
- /**
15
- * Represents the local sort state.
16
- * - undefined: No local sort set, fallback to view sort.
17
- * - cleared: Sort explicitly cleared by user.
18
- * - active: Active local sort with sort configuration.
19
- */
20
- type LocalSort = { type: 'cleared' } | { type: 'active'; sort: FieldSortType } | undefined;
21
-
22
- /**
23
- * Manages table sorting functionality through display and data index mapping.
24
- *
25
- * When a table is sorted, rows visually reorder but we need to maintain references
26
- * to the original data positions. This is handled through two types of indices:
27
- *
28
- * - Display indices: The visual positions after sorting
29
- * - Data indices: The original positions in the source data
30
- *
31
- * The _displayToDataIndex map maintains these relationships, enabling lookups
32
- * between visual and source positions.
33
- *
34
- * Example mapping between display and data indices:
35
- *
36
- * Original Data: Sorted Display: Mapping: (Display → Data)
37
- * ┌──────────────┐ ┌──────────────┐ ┌────────┐
38
- * │ 0: "Banana" │ => │ 0: "Apple" │ => │ 0 => 1 │
39
- * │ 1: "Apple" │ => │ 1: "Banana" │ => │ 1 => 0 │
40
- * │ 2: "Cherry" │ => │ 2: "Cherry" │ => │ 2 => 2 │
41
- * └──────────────┘ └──────────────┘ └────────┘
42
- */
43
- export class TableSorting<T extends TableRow> {
44
- private readonly _displayToDataIndex = new Map<number, number>();
45
- private readonly _rows: Signal<T[]>;
46
- private readonly _localSort = signal<LocalSort>(undefined);
47
- private readonly _isDirty: ReadonlySignal<boolean>;
48
- public readonly sortedRows: ReadonlySignal<T[]>;
49
-
50
- constructor(
51
- rows: Signal<T[]>,
52
- private readonly _view: DataType.View,
53
- private readonly _projection: ProjectionModel,
54
- ) {
55
- this._rows = rows;
56
- this._isDirty = computed(() => {
57
- const local = this._localSort.value;
58
- const viewSort = this._view.query.sort?.[0];
59
- if (local?.type === 'cleared') {
60
- return viewSort !== undefined;
61
- }
62
- if (local?.type === 'active') {
63
- if (!viewSort) {
64
- return true;
65
- }
66
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
67
- }
68
- return false;
69
- });
70
- this.sortedRows = this.initialiseSortedRows();
71
- }
72
-
73
- /**
74
- * @reactive
75
- * @returns Local sort if present, falls back to view sort.
76
- */
77
- public get sorting(): FieldSortType | undefined {
78
- const local = this._localSort.value;
79
- if (local?.type === 'cleared') {
80
- return undefined;
81
- }
82
- if (local?.type === 'active') {
83
- return local.sort;
84
- }
85
-
86
- return this._view.query.sort?.[0];
87
- }
88
-
89
- /**
90
- * @reactive
91
- * @returns Whether local sort differs from view sort.
92
- */
93
- public get isDirty(): boolean {
94
- return this._isDirty.value;
95
- }
96
-
97
- public getDataIndex(displayIndex: number): number {
98
- return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
99
- }
100
-
101
- public setSort(fieldId: string, direction: SortDirectionType): void {
102
- this._localSort.value = {
103
- type: 'active',
104
- sort: { fieldId, direction },
105
- };
106
- }
107
-
108
- public toggleSort(fieldId: string): void {
109
- if (!this.sorting || this.sorting.fieldId !== fieldId) {
110
- return;
111
- }
112
-
113
- switch (this.sorting.direction) {
114
- case 'asc': {
115
- this.setSort(fieldId, 'desc');
116
- break;
117
- }
118
- case 'desc': {
119
- this.setSort(fieldId, 'asc');
120
- break;
121
- }
122
- }
123
- }
124
-
125
- public clearSort(): void {
126
- this._localSort.value = { type: 'cleared' };
127
- }
128
-
129
- public save(): void {
130
- if (this._localSort.value !== undefined) {
131
- if (this._localSort.value.type === 'active') {
132
- this._view.query.sort = [this._localSort.value.sort];
133
- } else {
134
- this._view.query.sort = [];
135
- }
136
- this._localSort.value = undefined;
137
- }
138
- }
139
-
140
- //
141
- // Initialisation.
142
- //
143
-
144
- private initialiseSortedRows(): ReadonlySignal<T[]> {
145
- return computed(() => {
146
- this._displayToDataIndex.clear();
147
- const sort = this.sorting;
148
- if (!sort) {
149
- return this._rows.value;
150
- }
151
-
152
- const field = this._projection.fields.find((f) => f.id === sort.fieldId);
153
- if (!field) {
154
- return this._rows.value;
155
- }
156
-
157
- const { props } = this._projection.getFieldProjection(field.id);
158
-
159
- const dataWithIndices = this._rows.value.map((item, index) => {
160
- const sortValue = this.getSortValue(props, field, item);
161
- const isEmpty = !(props.type === TypeEnum.Boolean) && (sortValue == null || sortValue === '');
162
-
163
- return { item, index, value: sortValue, isEmpty };
164
- });
165
-
166
- const ordered = orderBy(dataWithIndices, ['isEmpty', 'value'], ['asc', sort.direction]);
167
-
168
- ordered.forEach(({ index: dataIndex }, displayIndex) => {
169
- if (displayIndex !== dataIndex) {
170
- this._displayToDataIndex.set(displayIndex, dataIndex);
171
- }
172
- });
173
-
174
- return ordered.map(({ item }) => item);
175
- });
176
- }
177
-
178
- private getSortValue(props: PropertyType, field: FieldType, item: T) {
179
- const { type, format } = props;
180
- const value = getValue(item, field.path);
181
-
182
- if (type === TypeEnum.Boolean) {
183
- return !!value; // Coerce null/undefined to false for booleans.
184
- }
185
- if (type === TypeEnum.Number) {
186
- return value;
187
- }
188
- if (value == null) {
189
- return value;
190
- }
191
-
192
- /**
193
- * For single select fields, the sort value is determined by the index of the option in the
194
- * options array. This ensures sort order matches the configured option order.
195
- */
196
- if (format === FormatEnum.SingleSelect) {
197
- const options = props.options;
198
- if (!options) {
199
- return undefined;
200
- }
201
-
202
- const option = options.find((option) => option.id === value);
203
- return option ? options.indexOf(option) : undefined;
204
- }
205
-
206
- // TODO(ZaymonFC): Should we format this returned value for display based on the referenced prop format?
207
- // Right now we're going to be sorting based on the raw values.
208
- // Maybe we need to recurse this function with the referenced prop format and field?
209
- if (format === FormatEnum.Ref && field.referencePath) {
210
- const refValue = getValue(value.target, field.referencePath);
211
- return refValue;
212
- }
213
-
214
- return formatForDisplay({ type, format, value });
215
- }
216
- }
@@ -1,16 +0,0 @@
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>;
package/src/util/table.ts DELETED
@@ -1,49 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Match } from 'effect';
6
-
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';
11
-
12
- import { TableView } from '../types';
13
-
14
- type CreateTableProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {
15
- sizes?: Record<string, number>;
16
- };
17
-
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;
33
- }
34
-
35
- Match.type<SimpleType>().pipe(
36
- Match.when('boolean', () => {
37
- table.sizes[property.name as JsonPath] = 100;
38
- }),
39
- Match.when('number', () => {
40
- table.sizes[property.name as JsonPath] = 100;
41
- }),
42
- Match.orElse(() => {
43
- // Noop.
44
- }),
45
- )(property.type);
46
- }
47
-
48
- return { jsonSchema, view };
49
- };