@dxos/react-ui-table 0.8.4-main.e8ec1fe → 0.8.4-main.effb148878

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 (166) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-KC62K4WS.mjs} +643 -722
  5. package/dist/lib/browser/chunk-KC62K4WS.mjs.map +7 -0
  6. package/dist/lib/browser/chunk-VWQWF3CP.mjs +67 -0
  7. package/dist/lib/browser/chunk-VWQWF3CP.mjs.map +7 -0
  8. package/dist/lib/browser/index.mjs +1103 -1023
  9. package/dist/lib/browser/index.mjs.map +4 -4
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/testing/index.mjs +35 -46
  12. package/dist/lib/browser/testing/index.mjs.map +3 -3
  13. package/dist/lib/browser/translations.mjs +36 -0
  14. package/dist/lib/browser/translations.mjs.map +7 -0
  15. package/dist/lib/browser/types/index.mjs +4 -3
  16. package/dist/lib/node-esm/{chunk-TRR3C5NX.mjs → chunk-62FOU4M7.mjs} +643 -721
  17. package/dist/lib/node-esm/chunk-62FOU4M7.mjs.map +7 -0
  18. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  19. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  20. package/dist/lib/node-esm/chunk-UBXOF64L.mjs +68 -0
  21. package/dist/lib/node-esm/chunk-UBXOF64L.mjs.map +7 -0
  22. package/dist/lib/node-esm/index.mjs +1103 -1023
  23. package/dist/lib/node-esm/index.mjs.map +4 -4
  24. package/dist/lib/node-esm/meta.json +1 -1
  25. package/dist/lib/node-esm/testing/index.mjs +35 -46
  26. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  27. package/dist/lib/node-esm/translations.mjs +37 -0
  28. package/dist/lib/node-esm/translations.mjs.map +7 -0
  29. package/dist/lib/node-esm/types/index.mjs +4 -3
  30. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
  31. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  32. package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
  33. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  34. package/dist/types/src/components/Table/DynamicTable.d.ts +6 -7
  35. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  36. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +22 -37
  37. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  38. package/dist/types/src/components/Table/Relations.stories.d.ts +85 -80
  39. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  40. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  41. package/dist/types/src/components/Table/Table.d.ts +20 -21
  42. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  43. package/dist/types/src/components/Table/Table.stories.d.ts +93 -26
  44. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/Table/TableContent.d.ts +18 -0
  46. package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
  47. package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
  48. package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
  49. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  50. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  51. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -12
  52. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  53. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
  54. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  55. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +24 -26
  56. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  57. package/dist/types/src/components/index.d.ts +0 -1
  58. package/dist/types/src/components/index.d.ts.map +1 -1
  59. package/dist/types/src/components/testing.d.ts +22 -15
  60. package/dist/types/src/components/testing.d.ts.map +1 -1
  61. package/dist/types/src/hooks/index.d.ts +2 -1
  62. package/dist/types/src/hooks/index.d.ts.map +1 -1
  63. package/dist/types/src/hooks/useAddRow.d.ts +5 -6
  64. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  65. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  66. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  67. package/dist/types/src/hooks/useTableModel.d.ts +9 -9
  68. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  69. package/dist/types/src/index.d.ts +0 -2
  70. package/dist/types/src/index.d.ts.map +1 -1
  71. package/dist/types/src/model/modal-controller.d.ts +5 -1
  72. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  73. package/dist/types/src/model/selection-model.d.ts +18 -9
  74. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  75. package/dist/types/src/model/table-model.d.ts +103 -24
  76. package/dist/types/src/model/table-model.d.ts.map +1 -1
  77. package/dist/types/src/model/table-presentation.d.ts +3 -1
  78. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  79. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  80. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  81. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  82. package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
  83. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  84. package/dist/types/src/translations.d.ts +21 -23
  85. package/dist/types/src/translations.d.ts.map +1 -1
  86. package/dist/types/src/types/Table.d.ts +32 -0
  87. package/dist/types/src/types/Table.d.ts.map +1 -0
  88. package/dist/types/src/types/index.d.ts +1 -1
  89. package/dist/types/src/types/index.d.ts.map +1 -1
  90. package/dist/types/src/util/dynamic-table.d.ts +14 -11
  91. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  92. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  93. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  94. package/dist/types/src/util/index.d.ts +2 -0
  95. package/dist/types/src/util/index.d.ts.map +1 -1
  96. package/dist/types/src/util/query-ast.d.ts +7 -0
  97. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  98. package/dist/types/src/util/schema.d.ts.map +1 -1
  99. package/dist/types/src/util/signals.d.ts.map +1 -1
  100. package/dist/types/src/util/sort.d.ts +12 -0
  101. package/dist/types/src/util/sort.d.ts.map +1 -0
  102. package/dist/types/src/util/table-buttons.d.ts +20 -20
  103. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  104. package/dist/types/src/util/table-controls.d.ts +4 -4
  105. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  106. package/dist/types/src/util/tag.d.ts.map +1 -1
  107. package/dist/types/tsconfig.tsbuildinfo +1 -1
  108. package/package.json +69 -79
  109. package/src/components/Table/ColumnActionsMenu.tsx +17 -12
  110. package/src/components/Table/ColumnSettings.tsx +8 -9
  111. package/src/components/Table/DynamicTable.stories.tsx +32 -32
  112. package/src/components/Table/DynamicTable.tsx +32 -33
  113. package/src/components/Table/Relations.stories.tsx +104 -64
  114. package/src/components/Table/RowActionsMenu.tsx +6 -4
  115. package/src/components/Table/Table.stories.tsx +125 -112
  116. package/src/components/Table/Table.tsx +43 -407
  117. package/src/components/Table/TableContent.tsx +426 -0
  118. package/src/components/{TableToolbar → Table}/TableToolbar.tsx +44 -45
  119. package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -6
  120. package/src/components/TableCellEditor/FormCellEditor.tsx +120 -136
  121. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +25 -19
  122. package/src/components/TableCellEditor/TableCellEditor.tsx +35 -33
  123. package/src/components/index.ts +0 -1
  124. package/src/components/testing.ts +38 -17
  125. package/src/hooks/index.ts +2 -1
  126. package/src/hooks/useAddRow.ts +8 -10
  127. package/src/hooks/useProjectionModel.ts +38 -0
  128. package/src/hooks/useTableModel.ts +36 -34
  129. package/src/index.ts +0 -4
  130. package/src/model/modal-controller.ts +23 -12
  131. package/src/model/selection-model.ts +75 -44
  132. package/src/model/table-model.test.ts +77 -55
  133. package/src/model/table-model.ts +431 -168
  134. package/src/model/table-presentation.test.ts +54 -50
  135. package/src/model/table-presentation.ts +44 -40
  136. package/src/playwright/TableManager.ts +13 -6
  137. package/src/playwright/playwright.config.ts +1 -1
  138. package/src/playwright/smoke.spec.ts +52 -8
  139. package/src/testing/useTestTableModel.ts +49 -43
  140. package/src/translations.ts +20 -22
  141. package/src/types/Table.ts +81 -0
  142. package/src/types/index.ts +1 -1
  143. package/src/util/dynamic-table.test.ts +63 -0
  144. package/src/util/dynamic-table.ts +48 -33
  145. package/src/util/index.ts +2 -0
  146. package/src/util/query-ast.ts +22 -0
  147. package/src/util/sort.ts +90 -0
  148. package/src/util/table-buttons.ts +1 -1
  149. package/src/util/table-controls.ts +2 -2
  150. package/dist/lib/browser/chunk-2PFAPQL4.mjs +0 -66
  151. package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +0 -7
  152. package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +0 -7
  153. package/dist/lib/node-esm/chunk-6POOFFYF.mjs +0 -67
  154. package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +0 -7
  156. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
  157. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
  158. package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
  159. package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
  160. package/dist/types/src/model/table-sorting.d.ts +0 -52
  161. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  162. package/dist/types/src/types/schema.d.ts +0 -28
  163. package/dist/types/src/types/schema.d.ts.map +0 -1
  164. package/src/components/TableToolbar/index.ts +0 -5
  165. package/src/model/table-sorting.ts +0 -225
  166. package/src/types/schema.ts +0 -73
@@ -1,225 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type ReadonlySignal, type Signal, computed, signal } from '@preact/signals-core';
6
- import orderBy from 'lodash.orderby';
7
-
8
- import { FormatEnum, TypeEnum, getValue } from '@dxos/echo/internal';
9
- import { formatForDisplay } from '@dxos/react-ui-form';
10
- import {
11
- type FieldSortType,
12
- type FieldType,
13
- type ProjectionModel,
14
- type PropertyType,
15
- type SortDirectionType,
16
- type View,
17
- } from '@dxos/schema';
18
-
19
- import { type TableRow } from './table-model';
20
-
21
- // TODO(wittjosiah): Remove. Use ordering in queries instead.
22
-
23
- /**
24
- * Represents the local sort state.
25
- * - undefined: No local sort set, fallback to view sort.
26
- * - cleared: Sort explicitly cleared by user.
27
- * - active: Active local sort with sort configuration.
28
- */
29
- type LocalSort = { type: 'cleared' } | { type: 'active'; sort: FieldSortType } | undefined;
30
-
31
- /**
32
- * Manages table sorting functionality through display and data index mapping.
33
- *
34
- * When a table is sorted, rows visually reorder but we need to maintain references
35
- * to the original data positions. This is handled through two types of indices:
36
- *
37
- * - Display indices: The visual positions after sorting
38
- * - Data indices: The original positions in the source data
39
- *
40
- * The _displayToDataIndex map maintains these relationships, enabling lookups
41
- * between visual and source positions.
42
- *
43
- * Example mapping between display and data indices:
44
- *
45
- * Original Data: Sorted Display: Mapping: (Display → Data)
46
- * ┌──────────────┐ ┌──────────────┐ ┌────────┐
47
- * │ 0: "Banana" │ => │ 0: "Apple" │ => │ 0 => 1 │
48
- * │ 1: "Apple" │ => │ 1: "Banana" │ => │ 1 => 0 │
49
- * │ 2: "Cherry" │ => │ 2: "Cherry" │ => │ 2 => 2 │
50
- * └──────────────┘ └──────────────┘ └────────┘
51
- */
52
- export class TableSorting<T extends TableRow> {
53
- private readonly _displayToDataIndex = new Map<number, number>();
54
- private readonly _rows: Signal<T[]>;
55
- private readonly _localSort = signal<LocalSort>(undefined);
56
- private readonly _isDirty: ReadonlySignal<boolean>;
57
- public readonly sortedRows: ReadonlySignal<T[]>;
58
-
59
- constructor(
60
- rows: Signal<T[]>,
61
- private readonly _view: View.View,
62
- private readonly _projection: ProjectionModel,
63
- ) {
64
- this._rows = rows;
65
- this._isDirty = computed(() => {
66
- const local = this._localSort.value;
67
- const viewSort = this._view.sort?.[0];
68
- if (local?.type === 'cleared') {
69
- return viewSort !== undefined;
70
- }
71
- if (local?.type === 'active') {
72
- if (!viewSort) {
73
- return true;
74
- }
75
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
76
- }
77
- return false;
78
- });
79
- this.sortedRows = this.initialiseSortedRows();
80
- }
81
-
82
- /**
83
- * @reactive
84
- * @returns Local sort if present, falls back to view sort.
85
- */
86
- public get sorting(): FieldSortType | undefined {
87
- const local = this._localSort.value;
88
- if (local?.type === 'cleared') {
89
- return undefined;
90
- }
91
- if (local?.type === 'active') {
92
- return local.sort;
93
- }
94
-
95
- return this._view.sort?.[0];
96
- }
97
-
98
- /**
99
- * @reactive
100
- * @returns Whether local sort differs from view sort.
101
- */
102
- public get isDirty(): boolean {
103
- return this._isDirty.value;
104
- }
105
-
106
- public getDataIndex(displayIndex: number): number {
107
- return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
108
- }
109
-
110
- public setSort(fieldId: string, direction: SortDirectionType): void {
111
- this._localSort.value = {
112
- type: 'active',
113
- sort: { fieldId, direction },
114
- };
115
- }
116
-
117
- public toggleSort(fieldId: string): void {
118
- if (!this.sorting || this.sorting.fieldId !== fieldId) {
119
- return;
120
- }
121
-
122
- switch (this.sorting.direction) {
123
- case 'asc': {
124
- this.setSort(fieldId, 'desc');
125
- break;
126
- }
127
- case 'desc': {
128
- this.setSort(fieldId, 'asc');
129
- break;
130
- }
131
- }
132
- }
133
-
134
- public clearSort(): void {
135
- this._localSort.value = { type: 'cleared' };
136
- }
137
-
138
- public save(): void {
139
- if (this._localSort.value !== undefined) {
140
- if (this._localSort.value.type === 'active') {
141
- this._view.sort = [this._localSort.value.sort];
142
- } else {
143
- this._view.sort = [];
144
- }
145
- this._localSort.value = undefined;
146
- }
147
- }
148
-
149
- //
150
- // Initialisation.
151
- //
152
-
153
- private initialiseSortedRows(): ReadonlySignal<T[]> {
154
- return computed(() => {
155
- this._displayToDataIndex.clear();
156
- const sort = this.sorting;
157
- if (!sort) {
158
- return this._rows.value;
159
- }
160
-
161
- const field = this._projection.fields.find((f) => f.id === sort.fieldId);
162
- if (!field) {
163
- return this._rows.value;
164
- }
165
-
166
- const { props } = this._projection.getFieldProjection(field.id);
167
-
168
- const dataWithIndices = this._rows.value.map((item, index) => {
169
- const sortValue = this.getSortValue(props, field, item);
170
- const isEmpty = !(props.type === TypeEnum.Boolean) && (sortValue == null || sortValue === '');
171
-
172
- return { item, index, value: sortValue, isEmpty };
173
- });
174
-
175
- const ordered = orderBy(dataWithIndices, ['isEmpty', 'value'], ['asc', sort.direction]);
176
-
177
- ordered.forEach(({ index: dataIndex }, displayIndex) => {
178
- if (displayIndex !== dataIndex) {
179
- this._displayToDataIndex.set(displayIndex, dataIndex);
180
- }
181
- });
182
-
183
- return ordered.map(({ item }) => item);
184
- });
185
- }
186
-
187
- private getSortValue(props: PropertyType, field: FieldType, item: T) {
188
- const { type, format } = props;
189
- const value = getValue(item, field.path);
190
-
191
- if (type === TypeEnum.Boolean) {
192
- return !!value; // Coerce null/undefined to false for booleans.
193
- }
194
- if (type === TypeEnum.Number) {
195
- return value;
196
- }
197
- if (value == null) {
198
- return value;
199
- }
200
-
201
- /**
202
- * For single select fields, the sort value is determined by the index of the option in the
203
- * options array. This ensures sort order matches the configured option order.
204
- */
205
- if (format === FormatEnum.SingleSelect) {
206
- const options = props.options;
207
- if (!options) {
208
- return undefined;
209
- }
210
-
211
- const option = options.find((option) => option.id === value);
212
- return option ? options.indexOf(option) : undefined;
213
- }
214
-
215
- // TODO(ZaymonFC): Should we format this returned value for display based on the referenced prop format?
216
- // Right now we're going to be sorting based on the raw values.
217
- // Maybe we need to recurse this function with the referenced prop format and field?
218
- if (format === FormatEnum.Ref && field.referencePath) {
219
- const refValue = getValue(value.target, field.referencePath);
220
- return refValue;
221
- }
222
-
223
- return formatForDisplay({ type, format, value });
224
- }
225
- }
@@ -1,73 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Match from 'effect/Match';
6
- import * as Schema from 'effect/Schema';
7
-
8
- import { Obj, Type } from '@dxos/echo';
9
- import { JsonPath, type JsonSchemaType, toEffectSchema } from '@dxos/echo/internal';
10
- import { ViewAnnotation } from '@dxos/echo/internal';
11
- import { type SimpleType } from '@dxos/effect';
12
- import { View, getSchemaProperties } from '@dxos/schema';
13
-
14
- export const Table = Schema.Struct({
15
- sizes: Schema.Record({
16
- key: JsonPath,
17
- value: Schema.Number,
18
- }).pipe(Schema.mutable),
19
- }).pipe(
20
- Type.Obj({
21
- typename: 'dxos.org/type/Table',
22
- version: '0.1.0',
23
- }),
24
- ViewAnnotation.set(true),
25
- );
26
-
27
- export type Table = Schema.Schema.Type<typeof Table>;
28
-
29
- /**
30
- * Make a table view.
31
- */
32
- export const make = (props: Partial<Obj.MakeProps<typeof Table>> = {}) => Obj.make(Table, { sizes: {}, ...props });
33
-
34
- type MakeViewProps = Omit<View.MakeFromSpaceProps, 'presentation'> & {
35
- sizes?: Record<string, number>;
36
- };
37
-
38
- export const makeView = async ({
39
- sizes,
40
- ...props
41
- }: MakeViewProps): Promise<{
42
- jsonSchema: JsonSchemaType;
43
- view: View.View;
44
- schema: ReturnType<typeof toEffectSchema>;
45
- }> => {
46
- const table = Obj.make(Table, { sizes: {} });
47
- const { jsonSchema, view } = await View.makeFromSpace({ ...props, presentation: table });
48
-
49
- // Preset sizes.
50
- const schema = toEffectSchema(jsonSchema);
51
- const shouldIncludeId = props.fields?.find((field) => field === 'id') !== undefined;
52
- const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
53
- for (const property of properties) {
54
- if (sizes?.[property.name]) {
55
- table.sizes[property.name as JsonPath] = sizes[property.name];
56
- continue;
57
- }
58
-
59
- Match.type<SimpleType>().pipe(
60
- Match.when('boolean', () => {
61
- table.sizes[property.name as JsonPath] = 100;
62
- }),
63
- Match.when('number', () => {
64
- table.sizes[property.name as JsonPath] = 100;
65
- }),
66
- Match.orElse(() => {
67
- // Noop.
68
- }),
69
- )(property.type);
70
- }
71
-
72
- return { jsonSchema, schema, view };
73
- };