@dxos/react-ui-table 0.8.4-main.67995b8 → 0.8.4-main.c4373fc

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 (130) hide show
  1. package/dist/lib/browser/chunk-4K7JPALT.mjs +66 -0
  2. package/dist/lib/browser/chunk-4K7JPALT.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-OZTXLZGM.mjs} +544 -491
  4. package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +584 -673
  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 +13 -8
  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-MK6OVUF6.mjs +67 -0
  12. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +7 -0
  13. package/dist/lib/node-esm/{chunk-Y66YLSTC.mjs → chunk-S56Z4V4X.mjs} +544 -491
  14. package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +584 -673
  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 +13 -8
  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/DynamicTable.d.ts +2 -2
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +51 -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 +108 -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 +8 -4
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +42 -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.map +1 -1
  38. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -6
  39. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +12 -17
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
  43. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  45. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  46. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  47. package/dist/types/src/components/testing.d.ts +3 -3
  48. package/dist/types/src/components/testing.d.ts.map +1 -1
  49. package/dist/types/src/hooks/useAddRow.d.ts +3 -2
  50. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  51. package/dist/types/src/hooks/useTableModel.d.ts +2 -2
  52. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  53. package/dist/types/src/model/modal-controller.d.ts +0 -7
  54. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  55. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  56. package/dist/types/src/model/table-model.d.ts +9 -7
  57. package/dist/types/src/model/table-model.d.ts.map +1 -1
  58. package/dist/types/src/model/table-presentation.d.ts +2 -1
  59. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  60. package/dist/types/src/model/table-sorting.d.ts +2 -3
  61. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  62. package/dist/types/src/testing/useTestTableModel.d.ts +3 -22
  63. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  64. package/dist/types/src/translations.d.ts +2 -2
  65. package/dist/types/src/types/index.d.ts +1 -1
  66. package/dist/types/src/types/index.d.ts.map +1 -1
  67. package/dist/types/src/types/schema.d.ts +25 -5
  68. package/dist/types/src/types/schema.d.ts.map +1 -1
  69. package/dist/types/src/util/dynamic-table.d.ts +4 -5
  70. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  71. package/dist/types/src/util/index.d.ts +0 -1
  72. package/dist/types/src/util/index.d.ts.map +1 -1
  73. package/dist/types/src/util/schema.d.ts +1 -1
  74. package/dist/types/src/util/schema.d.ts.map +1 -1
  75. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  76. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  77. package/dist/types/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +59 -58
  79. package/src/components/Table/ColumnActionsMenu.tsx +1 -1
  80. package/src/components/Table/ColumnSettings.tsx +1 -1
  81. package/src/components/Table/DynamicTable.stories.tsx +15 -11
  82. package/src/components/Table/DynamicTable.tsx +8 -10
  83. package/src/components/Table/Relations.stories.tsx +248 -0
  84. package/src/components/Table/RowActionsMenu.tsx +3 -3
  85. package/src/components/Table/Table.stories.tsx +66 -54
  86. package/src/components/Table/Table.tsx +140 -115
  87. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  88. package/src/components/TableCellEditor/FormCellEditor.tsx +153 -42
  89. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +24 -64
  90. package/src/components/TableCellEditor/TableCellEditor.tsx +74 -224
  91. package/src/components/TableCellEditor/index.ts +1 -0
  92. package/src/components/TableToolbar/TableToolbar.tsx +2 -2
  93. package/src/components/testing.ts +2 -2
  94. package/src/hooks/useAddRow.ts +7 -5
  95. package/src/hooks/useTableModel.ts +2 -2
  96. package/src/model/modal-controller.ts +1 -29
  97. package/src/model/selection-model.ts +3 -2
  98. package/src/model/table-model.test.ts +19 -10
  99. package/src/model/table-model.ts +37 -25
  100. package/src/model/table-presentation.test.ts +23 -21
  101. package/src/model/table-presentation.ts +74 -33
  102. package/src/model/table-sorting.ts +16 -7
  103. package/src/playwright/smoke.spec.ts +129 -37
  104. package/src/testing/useTestTableModel.ts +11 -7
  105. package/src/translations.ts +2 -2
  106. package/src/types/index.ts +1 -1
  107. package/src/types/schema.ts +63 -6
  108. package/src/util/dynamic-table.ts +13 -13
  109. package/src/util/index.ts +0 -1
  110. package/src/util/schema.ts +4 -4
  111. package/src/util/table-buttons.ts +4 -3
  112. package/src/util/table-controls.ts +4 -1
  113. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
  114. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  115. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  116. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  117. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  118. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
  119. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  120. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  121. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  122. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  123. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  124. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  125. package/dist/types/src/util/table.d.ts +0 -11
  126. package/dist/types/src/util/table.d.ts.map +0 -1
  127. package/src/components/Table/CreateRefPanel.tsx +0 -86
  128. package/src/components/Table/relations.stories.tsx +0 -116
  129. package/src/components/TableCellEditor/extension.ts +0 -61
  130. package/src/util/table.ts +0 -49
@@ -2,40 +2,47 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { computed, effect, signal, type ReadonlySignal } from '@preact/signals-core';
5
+ import { type ReadonlySignal, computed, effect, signal } from '@preact/signals-core';
6
6
 
7
7
  import { Resource } from '@dxos/context';
8
8
  import { Obj, Ref } from '@dxos/echo';
9
9
  import {
10
- type FieldSortType,
11
10
  FormatEnum,
12
- getValue,
13
- setValue,
14
11
  type JsonProp,
15
- getSnapshot,
12
+ type JsonSchemaType,
16
13
  getSchema,
14
+ getValue,
15
+ setValue,
17
16
  toEffectSchema,
18
- type JsonSchemaType,
19
- } from '@dxos/echo-schema';
17
+ } from '@dxos/echo/internal';
20
18
  import { invariant } from '@dxos/invariant';
21
19
  import { ObjectId } from '@dxos/keys';
22
- import { isLiveObject } from '@dxos/live-object';
20
+ import { getSnapshot, isLiveObject } from '@dxos/live-object';
23
21
  import { fullyQualifiedId } from '@dxos/react-client/echo';
22
+ import { type Label } from '@dxos/react-ui';
24
23
  import { formatForEditing, parseValue } from '@dxos/react-ui-form';
25
24
  import {
26
25
  type DxGridAxisMeta,
27
- type DxGridPlaneRange,
28
26
  type DxGridPlanePosition,
27
+ type DxGridPlaneRange,
29
28
  type DxGridPosition,
30
29
  } from '@dxos/react-ui-grid';
31
- import { type DataType, ProjectionModel, type PropertyType, validateSchema, type ValidationError } from '@dxos/schema';
30
+ import {
31
+ type DataType,
32
+ type FieldSortType,
33
+ ProjectionModel,
34
+ type PropertyType,
35
+ type ValidationError,
36
+ validateSchema,
37
+ } from '@dxos/schema';
32
38
 
33
- import { type SelectionMode, SelectionModel } from './selection-model';
34
- import { TableSorting } from './table-sorting';
35
- import { TableView } from '../types';
39
+ import { Table } from '../types';
36
40
  import { touch } from '../util';
37
41
  import { extractTagIds } from '../util/tag';
38
42
 
43
+ import { type SelectionMode, SelectionModel } from './selection-model';
44
+ import { TableSorting } from './table-sorting';
45
+
39
46
  // Domain types for cell classification
40
47
  export type TableCellType = 'standard' | 'draft' | 'header';
41
48
 
@@ -53,7 +60,7 @@ export type TableRow = Record<JsonProp, any> & { id: string };
53
60
 
54
61
  export type TableRowAction = {
55
62
  id: string;
56
- translationKey: string;
63
+ label: Label;
57
64
  };
58
65
 
59
66
  export type TableFeatures = {
@@ -68,6 +75,8 @@ const defaultFeatures: TableFeatures = {
68
75
  schemaEditable: false,
69
76
  };
70
77
 
78
+ export type InsertRowResult = 'draft' | 'final';
79
+
71
80
  export type TableModelProps<T extends TableRow = TableRow> = {
72
81
  view: DataType.View;
73
82
  schema: JsonSchemaType;
@@ -78,7 +87,7 @@ export type TableModelProps<T extends TableRow = TableRow> = {
78
87
  pinnedRows?: { top: number[]; bottom: number[] };
79
88
  rowActions?: TableRowAction[];
80
89
  onResolveSchema?: (typename: string) => Promise<JsonSchemaType>;
81
- onInsertRow?: (data?: any) => boolean;
90
+ onInsertRow?: (data?: any) => InsertRowResult;
82
91
  onDeleteRows?: (index: number, obj: T[]) => void;
83
92
  onDeleteColumn?: (fieldId: string) => void;
84
93
  onCellUpdate?: (cell: DxGridPosition) => void;
@@ -89,14 +98,14 @@ export type TableModelProps<T extends TableRow = TableRow> = {
89
98
  export class TableModel<T extends TableRow = TableRow> extends Resource {
90
99
  private readonly _view: DataType.View;
91
100
  private readonly _projection: ProjectionModel;
92
- private _table?: TableView;
101
+ private _table?: Table.Table;
93
102
 
94
103
  private readonly _visibleRange = signal<DxGridPlaneRange>({
95
104
  start: { row: 0, col: 0 },
96
105
  end: { row: 0, col: 0 },
97
106
  });
98
107
 
99
- private readonly _onInsertRow?: (data?: any) => boolean;
108
+ private readonly _onInsertRow?: (data?: any) => InsertRowResult;
100
109
  private readonly _onDeleteRows?: TableModelProps<T>['onDeleteRows'];
101
110
  private readonly _onDeleteColumn?: TableModelProps<T>['onDeleteColumn'];
102
111
  private readonly _onCellUpdate?: TableModelProps<T>['onCellUpdate'];
@@ -132,6 +141,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
132
141
  super();
133
142
  this._view = view;
134
143
  this._projection = projection ?? new ProjectionModel(schema, view.projection);
144
+ this._projection.normalizeView();
135
145
 
136
146
  // TODO(ZaymonFC): Use our more robust config merging module?
137
147
  this._features = { ...defaultFeatures, ...features };
@@ -173,7 +183,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
173
183
  return this._view;
174
184
  }
175
185
 
176
- public get table(): TableView {
186
+ public get table(): Table.Table {
177
187
  invariant(this._table, 'Model not initialized');
178
188
  return this._table;
179
189
  }
@@ -236,7 +246,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
236
246
 
237
247
  protected override async _open(): Promise<void> {
238
248
  const presentation = this._view.presentation.target ?? (await this._view.presentation.load());
239
- invariant(Obj.instanceOf(TableView, presentation));
249
+ invariant(Obj.instanceOf(Table.Table, presentation));
240
250
  this._table = presentation;
241
251
 
242
252
  this.initializeColumnMeta();
@@ -254,7 +264,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
254
264
  return {
255
265
  grid: meta,
256
266
  frozenColsStart: { 0: { size: 30, resizeable: false } },
257
- frozenColsEnd: { 0: { size: 40, resizeable: false } },
267
+ frozenColsEnd: { 0: { size: 32, resizeable: false } },
258
268
  };
259
269
  });
260
270
  }
@@ -334,11 +344,12 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
334
344
 
335
345
  public getColumnCount = (): number => this._projection?.fields.length ?? 0;
336
346
 
337
- public insertRow = (): void => {
347
+ public insertRow = (): InsertRowResult => {
338
348
  const result = this._onInsertRow?.();
339
- if (result === false && this._draftRows.value.length === 0) {
349
+ if (result === 'draft' && this._draftRows.value.length === 0) {
340
350
  this.createDraftRow();
341
351
  }
352
+ return result ?? 'final';
342
353
  };
343
354
 
344
355
  private createDraftRow(): void {
@@ -393,14 +404,14 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
393
404
  return false;
394
405
  }
395
406
 
396
- const success = this._onInsertRow?.(draftRow.data);
407
+ const insertRowResult = this._onInsertRow?.(draftRow.data);
397
408
 
398
- if (success) {
409
+ if (insertRowResult === 'final') {
399
410
  const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
400
411
  this._draftRows.value = newDraftRows;
401
412
  }
402
413
 
403
- return success ?? false;
414
+ return insertRowResult === 'final';
404
415
  };
405
416
 
406
417
  public deleteRow = (rowIndex: number): void => {
@@ -497,6 +508,7 @@ export class TableModel<T extends TableRow = TableRow> extends Resource {
497
508
  setValue(snapshot, field.path, transformedValue);
498
509
 
499
510
  const validationErrors = this.validateDraftRowData(snapshot);
511
+ // TODO(thure): These errors sometimes result in a useless message like “is missing” (what is missing?)
500
512
  if (validationErrors.length > 0) {
501
513
  const error = validationErrors.find((err) => err.path === field.path);
502
514
  if (error) {
@@ -2,18 +2,19 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
6
- import { describe, expect, it, beforeEach } from 'vitest';
5
+ import * as Schema from 'effect/Schema';
6
+ import { beforeEach, describe, expect, it } from 'vitest';
7
7
 
8
- import { Obj } from '@dxos/echo';
9
- import { TypedObject } from '@dxos/echo-schema';
8
+ import { Filter, Query } from '@dxos/echo';
9
+ import { TypedObject } from '@dxos/echo/internal';
10
+ import { createEchoSchema } from '@dxos/echo/testing';
10
11
  import { live } from '@dxos/live-object';
11
- import { createEchoSchema } from '@dxos/live-object/testing';
12
12
  import { createView } from '@dxos/schema';
13
13
 
14
+ import { Table } from '../types';
15
+
14
16
  import { TableModel, type TableModelProps } from './table-model';
15
17
  import { TablePresentation } from './table-presentation';
16
- import { TableView } from '../types';
17
18
 
18
19
  describe('TablePresentation', () => {
19
20
  describe('row reactivity', () => {
@@ -26,8 +27,8 @@ describe('TablePresentation', () => {
26
27
  updateCount = 0;
27
28
  ({ data } = live({
28
29
  data: [
29
- { col1: 'A', col2: 1, col3: true },
30
- { col1: 'B', col2: 2, col3: false },
30
+ { title: 'A', count: 1 },
31
+ { title: 'B', count: 2 },
31
32
  ],
32
33
  }));
33
34
 
@@ -44,8 +45,8 @@ describe('TablePresentation', () => {
44
45
  presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 1, col: 2 } }, 'grid');
45
46
 
46
47
  // Trigger a row update.
47
- data[0].col1 = 'New Value';
48
- expect(updateCount).toBe(1);
48
+ data[0].title = 'New Value';
49
+ expect(updateCount).toBe(2);
49
50
 
50
51
  // Verify the new value through getCells.
51
52
  const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 0, col: 0 } }, 'grid');
@@ -56,15 +57,14 @@ describe('TablePresentation', () => {
56
57
  // Set up visible range to include our test data.
57
58
  presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 2, col: 2 } }, 'grid');
58
59
 
59
- data.push({ col1: 'C', col2: 3, col3: true });
60
- expect(updateCount).toBe(1);
60
+ data.push({ title: 'C', count: 3 });
61
+ expect(updateCount).toBe(2);
61
62
 
62
63
  const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 2, col: 2 } }, 'grid');
63
64
 
64
65
  // Verify the new row's data.
65
66
  expect(cells['0,2']?.value).toBe('C');
66
67
  expect(cells['1,2']?.value).toBe('3');
67
- expect(cells['2,2']?.value).toBe('true');
68
68
  });
69
69
 
70
70
  it('should handle combined operations reactively', () => {
@@ -72,32 +72,34 @@ describe('TablePresentation', () => {
72
72
  presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 2, col: 2 } }, 'grid');
73
73
 
74
74
  // Multiple operations.
75
- data[0].col1 = 'Updated A';
76
- data.push({ col1: 'C', col2: 3, col3: true });
75
+ data[0].title = 'Updated A';
76
+ data.push({ title: 'C', count: 3, completed: true });
77
77
  data.splice(1, 1);
78
78
 
79
79
  // We expect one update per operation affecting visible rows.
80
- expect(updateCount).toBe(3);
80
+ expect(updateCount).toBe(4);
81
81
 
82
82
  const cells = presentation.getCells({ start: { row: 0, col: 0 }, end: { row: 1, col: 2 } }, 'grid');
83
83
 
84
84
  // Verify final state.
85
85
  expect(cells['0,0']?.value).toBe('Updated A');
86
86
  expect(cells['0,1']?.value).toBe('C');
87
- expect(cells['1,1']?.value).toBe('3');
88
- expect(cells['2,1']?.value).toBe('true');
89
87
  });
90
88
  });
91
89
  });
92
90
 
93
91
  class Test extends TypedObject({ typename: 'example.com/type/Test', version: '0.1.0' })({
94
92
  title: Schema.String,
95
- completed: Schema.Boolean,
93
+ count: Schema.Number,
96
94
  }) {}
97
95
 
98
96
  const createTableModel = (props: Partial<TableModelProps> = {}): TableModel => {
99
97
  const schema = createEchoSchema(Test);
100
- const table = Obj.make(TableView, { sizes: {} });
101
- const view = createView({ typename: schema.typename, jsonSchema: schema.jsonSchema, presentation: table });
98
+ const table = Table.make();
99
+ const view = createView({
100
+ query: Query.select(Filter.type(schema)),
101
+ jsonSchema: schema.jsonSchema,
102
+ presentation: table,
103
+ });
102
104
  return new TableModel({ view, schema: schema.jsonSchema, ...props });
103
105
  };
@@ -3,10 +3,10 @@
3
3
  //
4
4
 
5
5
  import { signal } from '@preact/signals-core';
6
- import { isNotNullable } from 'effect/Predicate';
6
+ import * as Predicate from 'effect/Predicate';
7
7
 
8
8
  import { Obj } from '@dxos/echo';
9
- import { FormatEnum, getValue, TypeEnum } from '@dxos/echo-schema';
9
+ import { FormatEnum, TypeEnum, getValue } from '@dxos/echo/internal';
10
10
  import { cellClassesForFieldType, formatForDisplay } from '@dxos/react-ui-form';
11
11
  import {
12
12
  type DxGridCellValue,
@@ -16,12 +16,13 @@ import {
16
16
  toPlaneCellIndex,
17
17
  } from '@dxos/react-ui-grid';
18
18
  import { mx } from '@dxos/react-ui-theme';
19
- import { VIEW_FIELD_LIMIT, type FieldType } from '@dxos/schema';
19
+ import { type FieldType, VIEW_FIELD_LIMIT } from '@dxos/schema';
20
20
 
21
- import { type SelectionMode } from './selection-model';
22
- import { type TableRow, type TableModel } from './table-model';
23
21
  import { tableButtons, tableControls } from '../util';
24
22
 
23
+ import { type SelectionMode } from './selection-model';
24
+ import { type TableModel, type TableRow } from './table-model';
25
+
25
26
  /**
26
27
  * Presentation layer for a table component, handling cell rendering and grid display logic.
27
28
  * Manages rendering of table cells, headers, selection columns, and action columns across
@@ -67,6 +68,9 @@ export class TablePresentation<T extends TableRow = TableRow> {
67
68
  case 'frozenRowsEnd':
68
69
  cells = this.getDraftRowCells(range);
69
70
  break;
71
+ case 'fixedEndStart':
72
+ cells = this.getDraftIconCells(range);
73
+ break;
70
74
  case 'fixedEndEnd':
71
75
  cells = this.getDraftActionCells(range);
72
76
  break;
@@ -137,20 +141,22 @@ export class TablePresentation<T extends TableRow = TableRow> {
137
141
  };
138
142
 
139
143
  const classes = [];
140
- const formatClasses = cellClassesForFieldType({ type: props.type, format: props.format });
144
+ const formatClasses = cellClassesForFieldType(props);
145
+
141
146
  if (formatClasses) {
142
147
  classes.push(formatClasses);
143
148
  }
149
+
144
150
  const rowSelectionClasses = cellClassesForRowSelection(
145
151
  this.model.selection.isObjectSelected(obj),
146
152
  this.model.selection.selectionMode,
147
153
  );
154
+
148
155
  if (rowSelectionClasses) {
149
156
  classes.push(rowSelectionClasses);
150
157
  }
151
- if (classes.length > 0) {
152
- cell.className = mx(classes.flat());
153
- }
158
+
159
+ cell.className = mx(classes);
154
160
 
155
161
  // Arrays.
156
162
  if (props.type === TypeEnum.Array) {
@@ -184,7 +190,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
184
190
 
185
191
  const tags = targetArray
186
192
  .map(getLabel)
187
- .filter(isNotNullable)
193
+ .filter(Predicate.isNotNullable)
188
194
  .map((title) => {
189
195
  return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
190
196
  })
@@ -199,7 +205,7 @@ export class TablePresentation<T extends TableRow = TableRow> {
199
205
  const targetObj = getValue(obj, field.path)?.target;
200
206
  if (targetObj) {
201
207
  const dxn = Obj.getDXN(targetObj)?.toString();
202
- cell.accessoryHtml = `<dx-ref-tag refId=${dxn} class="dx-button is-6 pli-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
208
+ cell.accessoryHtml = `<div role="none" class="absolute inline-end-0 inset-block-0 p-[--dx-grid-cell-content-padding-block]"><dx-anchor refId=${dxn} class="dx-button is-6 aspect-square min-bs-0" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor></div>`;
203
209
  }
204
210
  }
205
211
 
@@ -275,23 +281,34 @@ export class TablePresentation<T extends TableRow = TableRow> {
275
281
  const fields = this.model.projection?.fields ?? [];
276
282
  const draftRows = this.model.draftRows.value;
277
283
 
278
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
279
- const draftRow = draftRows[row];
284
+ // Return cells of the CTA row if no draft row is active
285
+ if (draftRows.length === 0) {
280
286
  for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
281
- const field = fields[col];
282
- if (!field) {
283
- continue;
284
- }
287
+ cells[toPlaneCellIndex({ col, row: 0 })] = {
288
+ value: '',
289
+ readonly: true,
290
+ className: 'dx-grid__row--cta__cell',
291
+ };
292
+ }
293
+ } else {
294
+ for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
295
+ const draftRow = draftRows[row];
296
+ for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
297
+ const cellIndex = toPlaneCellIndex({ col, row });
298
+ const field = fields[col];
299
+ if (!field) {
300
+ continue;
301
+ }
285
302
 
286
- this.createDataCell(cells, draftRow.data, field, col, row);
303
+ this.createDataCell(cells, draftRow.data, field, col, row);
287
304
 
288
- if (this.model.hasDraftRowValidationError(row, field.path)) {
289
- const cellIndex = toPlaneCellIndex({ col, row });
290
- const cellValue = cells[cellIndex];
291
- if (cellValue) {
292
- const existingClasses = cellValue.className || '';
293
- const draftClasses = 'dx-grid__cell--flagged';
294
- cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
305
+ if (this.model.hasDraftRowValidationError(row, field.path)) {
306
+ const cellValue = cells[cellIndex];
307
+ if (cellValue) {
308
+ const existingClasses = cellValue.className || '';
309
+ const draftClasses = 'dx-grid__cell--flagged';
310
+ cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
311
+ }
295
312
  }
296
313
  }
297
314
  }
@@ -310,14 +327,14 @@ export class TablePresentation<T extends TableRow = TableRow> {
310
327
 
311
328
  cells[toPlaneCellIndex({ col, row: 0 })] = {
312
329
  // TODO(burdon): Use same logic as form for fallback title.
313
- value: props.title ?? field.path,
314
- readonly: true,
330
+ value: '',
315
331
  resizeHandle: 'col',
316
332
  accessoryHtml: `
333
+ <span class="grow min-is-0 truncate">${props.title ?? field.path}</span>
317
334
  ${direction !== undefined ? tableButtons.sort.render({ fieldId: field.id, direction }) : ''}
318
335
  ${tableButtons.columnSettings.render({ fieldId: field.id })}
319
336
  `,
320
- className: '!bg-toolbarSurface',
337
+ className: '!bg-toolbarSurface !text-description [&>div]:flex [&>div]:items-stretch',
321
338
  };
322
339
  }
323
340
 
@@ -400,14 +417,39 @@ export class TablePresentation<T extends TableRow = TableRow> {
400
417
  const cells: DxGridPlaneCells = {};
401
418
  const draftRows = this.model.draftRows.value;
402
419
 
403
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
404
- const draftRow = draftRows[row];
405
- const disabled = !draftRow.valid;
420
+ // Return cells of the CTA row if no draft row is active
421
+ if (draftRows.length === 0) {
422
+ cells[toPlaneCellIndex({ col: 0, row: 0 })] = {
423
+ value: '',
424
+ className: 'dx-grid__row--cta__cell',
425
+ readonly: true,
426
+ };
427
+ } else {
428
+ for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
429
+ const draftRow = draftRows[row];
430
+ const disabled = !draftRow.valid;
431
+
432
+ cells[toPlaneCellIndex({ col: 0, row })] = {
433
+ value: '',
434
+ readonly: true,
435
+ accessoryHtml: tableButtons.saveDraftRow.render({ rowIndex: row, disabled }),
436
+ };
437
+ }
438
+ }
439
+
440
+ return cells;
441
+ }
442
+
443
+ private getDraftIconCells(range: DxGridPlaneRange): DxGridPlaneCells {
444
+ const cells: DxGridPlaneCells = {};
445
+ const draftRows = this.model.draftRows.value;
406
446
 
447
+ for (let row = range.start.row; row <= range.end.row; row++) {
407
448
  cells[toPlaneCellIndex({ col: 0, row })] = {
408
449
  value: '',
409
450
  readonly: true,
410
- accessoryHtml: tableButtons.saveDraftRow.render({ rowIndex: row, disabled }),
451
+ accessoryHtml: '<dx-icon icon="ph--plus--regular" class="contents"></dx-icon>',
452
+ className: mx('[&>div]:grid [&>div]:place-content-center', draftRows.length < 1 && 'dx-grid__row--cta__cell'),
411
453
  };
412
454
  }
413
455
 
@@ -426,7 +468,6 @@ export const cellClassesForRowSelection = (selected: boolean, selectionMode: Sel
426
468
 
427
469
  switch (selectionMode) {
428
470
  case 'single':
429
- // TODO(ZaymonFC): @thure, do we need a grid version of 'currentRelated'?
430
471
  return ['!bg-currentRelated dx-grid__cell--no-focus-unfurl hover:bg-hoverSurface !cursor-pointer'];
431
472
  case 'multiple':
432
473
  return ['!bg-gridCellSelected'];
@@ -2,15 +2,24 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { computed, signal, type Signal, type ReadonlySignal } from '@preact/signals-core';
5
+ import { type ReadonlySignal, type Signal, computed, signal } from '@preact/signals-core';
6
6
  import orderBy from 'lodash.orderby';
7
7
 
8
- import { getValue, FormatEnum, TypeEnum, type SortDirectionType, type FieldSortType } from '@dxos/echo-schema';
8
+ import { FormatEnum, TypeEnum, getValue } from '@dxos/echo/internal';
9
9
  import { formatForDisplay } from '@dxos/react-ui-form';
10
- import type { PropertyType, FieldType, DataType, ProjectionModel } from '@dxos/schema';
10
+ import type {
11
+ DataType,
12
+ FieldSortType,
13
+ FieldType,
14
+ ProjectionModel,
15
+ PropertyType,
16
+ SortDirectionType,
17
+ } from '@dxos/schema';
11
18
 
12
19
  import { type TableRow } from './table-model';
13
20
 
21
+ // TODO(wittjosiah): Remove. Use ordering in queries instead.
22
+
14
23
  /**
15
24
  * Represents the local sort state.
16
25
  * - undefined: No local sort set, fallback to view sort.
@@ -55,7 +64,7 @@ export class TableSorting<T extends TableRow> {
55
64
  this._rows = rows;
56
65
  this._isDirty = computed(() => {
57
66
  const local = this._localSort.value;
58
- const viewSort = this._view.query.sort?.[0];
67
+ const viewSort = this._view.sort?.[0];
59
68
  if (local?.type === 'cleared') {
60
69
  return viewSort !== undefined;
61
70
  }
@@ -83,7 +92,7 @@ export class TableSorting<T extends TableRow> {
83
92
  return local.sort;
84
93
  }
85
94
 
86
- return this._view.query.sort?.[0];
95
+ return this._view.sort?.[0];
87
96
  }
88
97
 
89
98
  /**
@@ -129,9 +138,9 @@ export class TableSorting<T extends TableRow> {
129
138
  public save(): void {
130
139
  if (this._localSort.value !== undefined) {
131
140
  if (this._localSort.value.type === 'active') {
132
- this._view.query.sort = [this._localSort.value.sort];
141
+ this._view.sort = [this._localSort.value.sort];
133
142
  } else {
134
- this._view.query.sort = [];
143
+ this._view.sort = [];
135
144
  }
136
145
  this._localSort.value = undefined;
137
146
  }