@dxos/react-ui-table 0.8.4-main.28f8d3d → 0.8.4-main.406dc2a

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 (108) 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-ZAOSIG3L.mjs → chunk-OZTXLZGM.mjs} +526 -536
  4. package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +373 -481
  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 +11 -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-ZOFFI3JJ.mjs → chunk-S56Z4V4X.mjs} +526 -536
  14. package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +373 -481
  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 +11 -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/DynamicTable.d.ts +2 -2
  22. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +51 -3
  24. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/Relations.stories.d.ts +104 -5
  26. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/Table.d.ts +8 -5
  28. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Table.stories.d.ts +41 -3
  30. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -6
  32. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  33. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +8 -13
  34. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
  36. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  38. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  39. package/dist/types/src/components/testing.d.ts +3 -3
  40. package/dist/types/src/components/testing.d.ts.map +1 -1
  41. package/dist/types/src/hooks/useAddRow.d.ts +3 -2
  42. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  43. package/dist/types/src/hooks/useTableModel.d.ts +1 -1
  44. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  45. package/dist/types/src/model/modal-controller.d.ts +0 -7
  46. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  47. package/dist/types/src/model/table-model.d.ts +7 -6
  48. package/dist/types/src/model/table-model.d.ts.map +1 -1
  49. package/dist/types/src/model/table-presentation.d.ts +1 -1
  50. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  51. package/dist/types/src/model/table-sorting.d.ts +1 -2
  52. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  53. package/dist/types/src/testing/useTestTableModel.d.ts +3 -22
  54. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  55. package/dist/types/src/types/index.d.ts +1 -1
  56. package/dist/types/src/types/index.d.ts.map +1 -1
  57. package/dist/types/src/types/schema.d.ts +25 -5
  58. package/dist/types/src/types/schema.d.ts.map +1 -1
  59. package/dist/types/src/util/dynamic-table.d.ts +4 -5
  60. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  61. package/dist/types/src/util/index.d.ts +0 -1
  62. package/dist/types/src/util/index.d.ts.map +1 -1
  63. package/dist/types/src/util/schema.d.ts +1 -1
  64. package/dist/types/src/util/schema.d.ts.map +1 -1
  65. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  66. package/dist/types/tsconfig.tsbuildinfo +1 -1
  67. package/package.json +51 -50
  68. package/src/components/Table/DynamicTable.stories.tsx +12 -9
  69. package/src/components/Table/DynamicTable.tsx +4 -7
  70. package/src/components/Table/Relations.stories.tsx +162 -38
  71. package/src/components/Table/Table.stories.tsx +59 -52
  72. package/src/components/Table/Table.tsx +109 -90
  73. package/src/components/TableCellEditor/FormCellEditor.tsx +153 -42
  74. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +22 -63
  75. package/src/components/TableCellEditor/TableCellEditor.tsx +62 -208
  76. package/src/components/TableCellEditor/index.ts +1 -0
  77. package/src/components/testing.ts +2 -2
  78. package/src/hooks/useAddRow.ts +7 -5
  79. package/src/hooks/useTableModel.ts +1 -1
  80. package/src/model/modal-controller.ts +0 -28
  81. package/src/model/table-model.test.ts +18 -10
  82. package/src/model/table-model.ts +26 -17
  83. package/src/model/table-presentation.test.ts +21 -20
  84. package/src/model/table-presentation.ts +58 -39
  85. package/src/model/table-sorting.ts +15 -6
  86. package/src/playwright/smoke.spec.ts +46 -46
  87. package/src/testing/useTestTableModel.ts +9 -6
  88. package/src/types/index.ts +1 -1
  89. package/src/types/schema.ts +63 -6
  90. package/src/util/dynamic-table.ts +11 -11
  91. package/src/util/index.ts +0 -1
  92. package/src/util/schema.ts +4 -4
  93. package/src/util/table-buttons.ts +3 -3
  94. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  95. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  96. package/dist/lib/browser/chunk-ZAOSIG3L.mjs.map +0 -7
  97. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  98. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  99. package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs.map +0 -7
  100. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  101. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  102. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  103. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  104. package/dist/types/src/util/table.d.ts +0 -12
  105. package/dist/types/src/util/table.d.ts.map +0 -1
  106. package/src/components/Table/CreateRefPanel.tsx +0 -86
  107. package/src/components/TableCellEditor/extension.ts +0 -61
  108. package/src/util/table.ts +0 -53
@@ -1,10 +1,10 @@
1
1
  import {
2
- TableView
3
- } from "./chunk-L2LSB6KV.mjs";
2
+ schema_exports
3
+ } from "./chunk-4K7JPALT.mjs";
4
4
 
5
5
  // src/util/dynamic-table.ts
6
- import { Obj } from "@dxos/echo";
7
- import { getTypename, toJsonSchema } from "@dxos/echo-schema";
6
+ import { Filter, Obj, Query } from "@dxos/echo";
7
+ import { getTypename, toJsonSchema } from "@dxos/echo/internal";
8
8
  import { ProjectionModel, createView, getSchemaFromPropertyDefinitions } from "@dxos/schema";
9
9
  var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
10
10
  if (typename && properties) {
@@ -27,12 +27,12 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
27
27
  throw new Error("invalid properties");
28
28
  }
29
29
  };
30
- var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
31
- const table = Obj.make(TableView, {
30
+ var makeDynamicTable = ({ jsonSchema, properties }) => {
31
+ const table = Obj.make(schema_exports.Table, {
32
32
  sizes: {}
33
33
  });
34
34
  const view = createView({
35
- typename,
35
+ query: Query.select(Filter.everything()),
36
36
  jsonSchema,
37
37
  presentation: table,
38
38
  ...properties && {
@@ -40,6 +40,7 @@ var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
40
40
  }
41
41
  });
42
42
  const projection = new ProjectionModel(jsonSchema, view.projection);
43
+ projection.normalizeView();
43
44
  if (properties && projection.fields) {
44
45
  setProperties(view, projection, table, properties);
45
46
  }
@@ -67,7 +68,7 @@ var setProperties = (view, projection, table, properties) => {
67
68
  }
68
69
  if (property.sort) {
69
70
  const fieldId = field.id;
70
- view.query.sort = [
71
+ view.sort = [
71
72
  {
72
73
  fieldId,
73
74
  direction: property.sort
@@ -81,41 +82,6 @@ var setProperties = (view, projection, table, properties) => {
81
82
  // src/util/signals.ts
82
83
  var touch = (value) => value;
83
84
 
84
- // src/util/table.ts
85
- import { Match } from "effect";
86
- import { Obj as Obj2 } from "@dxos/echo";
87
- import { toEffectSchema } from "@dxos/echo-schema";
88
- import { createViewFromSpace, getSchemaProperties } from "@dxos/schema";
89
- var createTable = async ({ sizes, ...props }) => {
90
- const table = Obj2.make(TableView, {
91
- sizes: {}
92
- });
93
- const { jsonSchema, view } = await createViewFromSpace({
94
- ...props,
95
- presentation: table
96
- });
97
- const schema = toEffectSchema(jsonSchema);
98
- const shouldIncludeId = props.fields?.find((field) => field === "id") !== void 0;
99
- const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
100
- for (const property of properties) {
101
- if (sizes?.[property.name]) {
102
- table.sizes[property.name] = sizes[property.name];
103
- continue;
104
- }
105
- Match.type().pipe(Match.when("boolean", () => {
106
- table.sizes[property.name] = 100;
107
- }), Match.when("number", () => {
108
- table.sizes[property.name] = 100;
109
- }), Match.orElse(() => {
110
- }))(property.type);
111
- }
112
- return {
113
- jsonSchema,
114
- schema,
115
- view
116
- };
117
- };
118
-
119
85
  // src/util/table-buttons.ts
120
86
  var BUTTON_IDENTIFIERS = {
121
87
  columnSettings: "data-table-column-settings-button",
@@ -125,10 +91,9 @@ var BUTTON_IDENTIFIERS = {
125
91
  saveDraftRow: "data-table-save-draft-row-button",
126
92
  sort: "data-table-sort-button"
127
93
  };
128
- var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
94
+ var createButton = ({ attr, data, disabled = false, icon, testId, type: _type = "primary" }) => {
129
95
  const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
130
- const positionClass = type === "primary" ? "inline-end-2" : "inline-end-9";
131
- return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? "disabled" : ""} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
96
+ return `<button ${attr} data-testid="${testId}" class="dx-button is-6 aspect-square pli-0.5 min-bs-0" ${dataAttrs} ${disabled ? "disabled" : ""} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
132
97
  };
133
98
  var addColumnButton = {
134
99
  attr: BUTTON_IDENTIFIERS.newColumn,
@@ -154,7 +119,8 @@ var columnSettingsButton = {
154
119
  attr: BUTTON_IDENTIFIERS.columnSettings,
155
120
  icon: columnSettingsButton.icon,
156
121
  data: {
157
- "data-field-id": fieldId
122
+ "data-field-id": fieldId,
123
+ "data-variant": "ghost"
158
124
  },
159
125
  testId: "table-column-settings-button"
160
126
  });
@@ -290,14 +256,14 @@ var tableControls = {
290
256
  };
291
257
 
292
258
  // src/util/schema.ts
293
- import { Schema } from "effect";
294
- import { TypeLiteral, isTypeLiteral } from "effect/SchemaAST";
259
+ import * as Schema from "effect/Schema";
260
+ import * as SchemaAST from "effect/SchemaAST";
295
261
  var narrowSchema = (schema, paths) => {
296
262
  const ast = schema?.ast;
297
- if (isTypeLiteral(ast)) {
263
+ if (SchemaAST.isTypeLiteral(ast)) {
298
264
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
299
265
  if (propertySignatures.length > 0) {
300
- const narrowType = new TypeLiteral(propertySignatures, []);
266
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
301
267
  return Schema.make(narrowType);
302
268
  }
303
269
  }
@@ -307,11 +273,11 @@ var narrowSchema = (schema, paths) => {
307
273
  // src/model/table-model.ts
308
274
  import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
309
275
  import { Resource as Resource2 } from "@dxos/context";
310
- import { Obj as Obj3, Ref } from "@dxos/echo";
311
- import { FormatEnum as FormatEnum2, getSchema, getSnapshot, getValue as getValue2, setValue, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
276
+ import { Obj as Obj2, Ref } from "@dxos/echo";
277
+ import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
312
278
  import { invariant } from "@dxos/invariant";
313
279
  import { ObjectId } from "@dxos/keys";
314
- import { isLiveObject } from "@dxos/live-object";
280
+ import { getSnapshot, isLiveObject } from "@dxos/live-object";
315
281
  import { fullyQualifiedId } from "@dxos/react-client/echo";
316
282
  import { formatForEditing, parseValue } from "@dxos/react-ui-form";
317
283
  import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
@@ -335,17 +301,47 @@ var extractTagIds = (value) => {
335
301
  // src/model/selection-model.ts
336
302
  import { computed, effect, signal } from "@preact/signals-core";
337
303
  import { Resource } from "@dxos/context";
304
+ function _define_property(obj, key, value) {
305
+ if (key in obj) {
306
+ Object.defineProperty(obj, key, {
307
+ value,
308
+ enumerable: true,
309
+ configurable: true,
310
+ writable: true
311
+ });
312
+ } else {
313
+ obj[key] = value;
314
+ }
315
+ return obj;
316
+ }
338
317
  var SelectionModel = class extends Resource {
339
- _rows;
340
- _selectionMode;
341
- _initialSelection;
342
- _onSelectionChanged;
343
- _selection;
344
- _validSelectedIds;
345
- _hasSelection;
346
- _allSelected;
318
+ async _open() {
319
+ const selectionWatcher = effect(() => {
320
+ touch(this._selection.value);
321
+ this._onSelectionChanged?.();
322
+ });
323
+ this._ctx.onDispose(selectionWatcher);
324
+ }
325
+ //
326
+ // Getters
327
+ //
328
+ get selection() {
329
+ return this._selection;
330
+ }
331
+ get hasSelection() {
332
+ return this._hasSelection;
333
+ }
334
+ get allRowsSeleted() {
335
+ return this._allSelected;
336
+ }
337
+ get selectionMode() {
338
+ return this._selectionMode;
339
+ }
347
340
  constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
348
- super(), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged, this._validSelectedIds = computed(() => {
341
+ super(), _define_property(this, "_rows", void 0), _define_property(this, "_selectionMode", void 0), _define_property(this, "_initialSelection", void 0), _define_property(this, "_onSelectionChanged", void 0), _define_property(this, "_selection", void 0), _define_property(this, "_validSelectedIds", void 0), _define_property(this, "_hasSelection", void 0), _define_property(this, "_allSelected", void 0), _define_property(this, "getSelectedRows", void 0), _define_property(this, "isRowIndexSelected", void 0), _define_property(this, "isObjectSelected", void 0), //
342
+ // Manipulation
343
+ //
344
+ _define_property(this, "toggleSelectionForRowIndex", void 0), _define_property(this, "setSelection", void 0), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged, this._validSelectedIds = computed(() => {
349
345
  const rows = this._rows.value;
350
346
  if (!rows) {
351
347
  return /* @__PURE__ */ new Set();
@@ -394,73 +390,27 @@ var SelectionModel = class extends Resource {
394
390
  };
395
391
  this._selection = signal(new Set(this._initialSelection));
396
392
  }
397
- async _open() {
398
- const selectionWatcher = effect(() => {
399
- touch(this._selection.value);
400
- this._onSelectionChanged?.();
401
- });
402
- this._ctx.onDispose(selectionWatcher);
403
- }
404
- //
405
- // Getters
406
- //
407
- get selection() {
408
- return this._selection;
409
- }
410
- get hasSelection() {
411
- return this._hasSelection;
412
- }
413
- get allRowsSeleted() {
414
- return this._allSelected;
415
- }
416
- get selectionMode() {
417
- return this._selectionMode;
418
- }
419
- getSelectedRows;
420
- isRowIndexSelected;
421
- isObjectSelected;
422
- //
423
- // Manipulation
424
- //
425
- toggleSelectionForRowIndex;
426
- setSelection;
427
393
  };
428
394
 
429
395
  // src/model/table-sorting.ts
430
396
  import { computed as computed2, signal as signal2 } from "@preact/signals-core";
431
397
  import orderBy from "lodash.orderby";
432
- import { FormatEnum, TypeEnum, getValue } from "@dxos/echo-schema";
398
+ import { FormatEnum, TypeEnum, getValue } from "@dxos/echo/internal";
433
399
  import { formatForDisplay } from "@dxos/react-ui-form";
434
- var TableSorting = class {
435
- _view;
436
- _projection;
437
- _displayToDataIndex;
438
- _rows;
439
- _localSort;
440
- _isDirty;
441
- sortedRows;
442
- constructor(rows, _view, _projection) {
443
- this._view = _view;
444
- this._projection = _projection;
445
- this._displayToDataIndex = /* @__PURE__ */ new Map();
446
- this._localSort = signal2(void 0);
447
- this._rows = rows;
448
- this._isDirty = computed2(() => {
449
- const local = this._localSort.value;
450
- const viewSort = this._view.query.sort?.[0];
451
- if (local?.type === "cleared") {
452
- return viewSort !== void 0;
453
- }
454
- if (local?.type === "active") {
455
- if (!viewSort) {
456
- return true;
457
- }
458
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
459
- }
460
- return false;
400
+ function _define_property2(obj, key, value) {
401
+ if (key in obj) {
402
+ Object.defineProperty(obj, key, {
403
+ value,
404
+ enumerable: true,
405
+ configurable: true,
406
+ writable: true
461
407
  });
462
- this.sortedRows = this.initialiseSortedRows();
408
+ } else {
409
+ obj[key] = value;
463
410
  }
411
+ return obj;
412
+ }
413
+ var TableSorting = class {
464
414
  /**
465
415
  * @reactive
466
416
  * @returns Local sort if present, falls back to view sort.
@@ -473,7 +423,7 @@ var TableSorting = class {
473
423
  if (local?.type === "active") {
474
424
  return local.sort;
475
425
  }
476
- return this._view.query.sort?.[0];
426
+ return this._view.sort?.[0];
477
427
  }
478
428
  /**
479
429
  * @reactive
@@ -517,11 +467,11 @@ var TableSorting = class {
517
467
  save() {
518
468
  if (this._localSort.value !== void 0) {
519
469
  if (this._localSort.value.type === "active") {
520
- this._view.query.sort = [
470
+ this._view.sort = [
521
471
  this._localSort.value.sort
522
472
  ];
523
473
  } else {
524
- this._view.query.sort = [];
474
+ this._view.sort = [];
525
475
  }
526
476
  this._localSort.value = void 0;
527
477
  }
@@ -596,9 +546,51 @@ var TableSorting = class {
596
546
  value
597
547
  });
598
548
  }
549
+ constructor(rows, _view, _projection) {
550
+ _define_property2(this, "_view", void 0);
551
+ _define_property2(this, "_projection", void 0);
552
+ _define_property2(this, "_displayToDataIndex", void 0);
553
+ _define_property2(this, "_rows", void 0);
554
+ _define_property2(this, "_localSort", void 0);
555
+ _define_property2(this, "_isDirty", void 0);
556
+ _define_property2(this, "sortedRows", void 0);
557
+ this._view = _view;
558
+ this._projection = _projection;
559
+ this._displayToDataIndex = /* @__PURE__ */ new Map();
560
+ this._localSort = signal2(void 0);
561
+ this._rows = rows;
562
+ this._isDirty = computed2(() => {
563
+ const local = this._localSort.value;
564
+ const viewSort = this._view.sort?.[0];
565
+ if (local?.type === "cleared") {
566
+ return viewSort !== void 0;
567
+ }
568
+ if (local?.type === "active") {
569
+ if (!viewSort) {
570
+ return true;
571
+ }
572
+ return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
573
+ }
574
+ return false;
575
+ });
576
+ this.sortedRows = this.initialiseSortedRows();
577
+ }
599
578
  };
600
579
 
601
580
  // src/model/table-model.ts
581
+ function _define_property3(obj, key, value) {
582
+ if (key in obj) {
583
+ Object.defineProperty(obj, key, {
584
+ value,
585
+ enumerable: true,
586
+ configurable: true,
587
+ writable: true
588
+ });
589
+ } else {
590
+ obj[key] = value;
591
+ }
592
+ return obj;
593
+ }
602
594
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
603
595
  var defaultFeatures = {
604
596
  selection: {
@@ -609,68 +601,6 @@ var defaultFeatures = {
609
601
  schemaEditable: false
610
602
  };
611
603
  var TableModel = class extends Resource2 {
612
- _view;
613
- _projection;
614
- _table;
615
- _visibleRange = signal3({
616
- start: {
617
- row: 0,
618
- col: 0
619
- },
620
- end: {
621
- row: 0,
622
- col: 0
623
- }
624
- });
625
- _onInsertRow;
626
- _onDeleteRows;
627
- _onDeleteColumn;
628
- _onCellUpdate;
629
- _onRowOrderChange;
630
- _onRowAction;
631
- _rowActions;
632
- _features;
633
- _rows = signal3([]);
634
- _draftRows = signal3([]);
635
- _sorting;
636
- _pinnedRows;
637
- _selection;
638
- _columnMeta;
639
- constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
640
- top: [],
641
- bottom: []
642
- }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
643
- super();
644
- this._view = view;
645
- this._projection = projection ?? new ProjectionModel2(schema, view.projection);
646
- this._features = {
647
- ...defaultFeatures,
648
- ...features
649
- };
650
- invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
651
- F: __dxlog_file,
652
- L: 141,
653
- S: this,
654
- A: [
655
- "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
656
- "'Single selection is not compatible with editable tables.'"
657
- ]
658
- });
659
- this._sorting = new TableSorting(this._rows, this._view, this._projection);
660
- if (sorting.length > 0) {
661
- const [sort] = sorting;
662
- this._sorting.setSort(sort.fieldId, sort.direction);
663
- }
664
- this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
665
- this._pinnedRows = pinnedRows;
666
- this._rowActions = rowActions;
667
- this._onInsertRow = onInsertRow;
668
- this._onDeleteRows = onDeleteRows;
669
- this._onDeleteColumn = onDeleteColumn;
670
- this._onCellUpdate = onCellUpdate;
671
- this._onRowOrderChange = onRowOrderChange;
672
- this._onRowAction = onRowAction;
673
- }
674
604
  get id() {
675
605
  return fullyQualifiedId(this._view);
676
606
  }
@@ -680,7 +610,7 @@ var TableModel = class extends Resource2 {
680
610
  get table() {
681
611
  invariant(this._table, "Model not initialized", {
682
612
  F: __dxlog_file,
683
- L: 179,
613
+ L: 187,
684
614
  S: this,
685
615
  A: [
686
616
  "this._table",
@@ -719,7 +649,7 @@ var TableModel = class extends Resource2 {
719
649
  get columnMeta() {
720
650
  invariant(this._columnMeta, void 0, {
721
651
  F: __dxlog_file,
722
- L: 218,
652
+ L: 226,
723
653
  S: this,
724
654
  A: [
725
655
  "this._columnMeta",
@@ -743,12 +673,12 @@ var TableModel = class extends Resource2 {
743
673
  //
744
674
  async _open() {
745
675
  const presentation = this._view.presentation.target ?? await this._view.presentation.load();
746
- invariant(Obj3.instanceOf(TableView, presentation), void 0, {
676
+ invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
747
677
  F: __dxlog_file,
748
- L: 241,
678
+ L: 249,
749
679
  S: this,
750
680
  A: [
751
- "Obj.instanceOf(TableView, presentation)",
681
+ "Obj.instanceOf(Table.Table, presentation)",
752
682
  ""
753
683
  ]
754
684
  });
@@ -777,7 +707,7 @@ var TableModel = class extends Resource2 {
777
707
  },
778
708
  frozenColsEnd: {
779
709
  0: {
780
- size: 40,
710
+ size: 32,
781
711
  resizeable: false
782
712
  }
783
713
  }
@@ -813,17 +743,6 @@ var TableModel = class extends Resource2 {
813
743
  });
814
744
  this._ctx.onDispose(draftRowsWatcher);
815
745
  }
816
- //
817
- // Data
818
- //
819
- setRows = (obj) => {
820
- this._rows.value = obj;
821
- };
822
- getRowCount = () => this._rows.value.length;
823
- /**
824
- * @reactive
825
- */
826
- getDraftRowCount = () => this._draftRows.value.length;
827
746
  // TODO(ZaymonFC): Return .value instead of exposing the signal.
828
747
  get draftRows() {
829
748
  return this._draftRows;
@@ -842,13 +761,6 @@ var TableModel = class extends Resource2 {
842
761
  const validationErrors = draftRow.validationErrors || [];
843
762
  return validationErrors.some((error) => error.path === fieldPath);
844
763
  }
845
- getColumnCount = () => this._projection?.fields.length ?? 0;
846
- insertRow = () => {
847
- const result = this._onInsertRow?.();
848
- if (result === false && this._draftRows.value.length === 0) {
849
- this.createDraftRow();
850
- }
851
- };
852
764
  createDraftRow() {
853
765
  if (!this._projection) {
854
766
  return;
@@ -885,190 +797,9 @@ var TableModel = class extends Resource2 {
885
797
  this._draftRows.value = newDraftRows;
886
798
  }
887
799
  validateDraftRowData(data) {
888
- const schema = toEffectSchema2(this._projection.baseSchema);
800
+ const schema = toEffectSchema(this._projection.baseSchema);
889
801
  return validateSchema(schema, data) || [];
890
802
  }
891
- commitDraftRow = (draftRowIndex) => {
892
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
893
- return false;
894
- }
895
- const draftRow = this._draftRows.value[draftRowIndex];
896
- if (!draftRow.valid) {
897
- return false;
898
- }
899
- const success = this._onInsertRow?.(draftRow.data);
900
- if (success) {
901
- const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
902
- this._draftRows.value = newDraftRows;
903
- }
904
- return success ?? false;
905
- };
906
- deleteRow = (rowIndex) => {
907
- const row = this._sorting.getDataIndex(rowIndex);
908
- const obj = this._rows.value[row];
909
- const objectsToDelete = [];
910
- if (this.features.selection.enabled && this._selection.hasSelection.value) {
911
- const selectedRows = this._selection.getSelectedRows();
912
- objectsToDelete.push(...selectedRows);
913
- } else {
914
- objectsToDelete.push(obj);
915
- }
916
- this._onDeleteRows?.(row, objectsToDelete);
917
- };
918
- handleRowAction = (actionId, rowIndex) => {
919
- if (!this._onRowAction) {
920
- return;
921
- }
922
- const row = this._sorting.getDataIndex(rowIndex);
923
- const data = this._rows.value[row];
924
- if (data) {
925
- this._onRowAction(actionId, data);
926
- }
927
- };
928
- getCellData = (cell) => {
929
- const { col, row, plane } = cell;
930
- const fields = this._projection?.fields ?? [];
931
- if (col < 0 || col >= fields.length) {
932
- return void 0;
933
- }
934
- const field = fields[col];
935
- let value;
936
- if (plane === "frozenRowsEnd") {
937
- if (row >= 0 && row < this._draftRows.value.length) {
938
- value = getValue2(this._draftRows.value[row].data, field.path);
939
- } else {
940
- return void 0;
941
- }
942
- } else {
943
- const dataIndex = this._sorting.getDataIndex(row);
944
- value = getValue2(this._rows.value[dataIndex], field.path);
945
- }
946
- if (value == null) {
947
- return "";
948
- }
949
- const { props } = this._projection.getFieldProjection(field.id);
950
- switch (props.format) {
951
- case FormatEnum2.Ref: {
952
- if (!field.referencePath) {
953
- return "";
954
- }
955
- return getValue2(value.target, field.referencePath);
956
- }
957
- default: {
958
- return formatForEditing({
959
- type: props.type,
960
- format: props.format,
961
- value
962
- });
963
- }
964
- }
965
- };
966
- validateCellData = async ({ col, row, plane }, value) => {
967
- const fields = this._projection?.fields ?? [];
968
- if (col < 0 || col >= fields.length) {
969
- return {
970
- valid: false,
971
- error: "Invalid column index"
972
- };
973
- }
974
- const field = fields[col];
975
- const { props } = this._projection.getFieldProjection(field.id);
976
- const transformedValue = editorTextToCellValue(props, value);
977
- const isDraftRow = plane === "frozenRowsEnd";
978
- if (isDraftRow) {
979
- const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
980
- if (isInvalidDraftRowIndex) {
981
- return {
982
- valid: false,
983
- error: "Invalid draft row index"
984
- };
985
- }
986
- const draftRow = this._draftRows.value[row];
987
- const snapshot = {
988
- ...draftRow.data
989
- };
990
- setValue(snapshot, field.path, transformedValue);
991
- const validationErrors = this.validateDraftRowData(snapshot);
992
- if (validationErrors.length > 0) {
993
- const error = validationErrors.find((err) => err.path === field.path);
994
- if (error) {
995
- return {
996
- valid: false,
997
- error: error.message
998
- };
999
- }
1000
- }
1001
- return {
1002
- valid: true
1003
- };
1004
- } else {
1005
- const rowIdx = this._sorting.getDataIndex(row);
1006
- const currentRow = this._rows.value[rowIdx];
1007
- invariant(currentRow, "Invalid row index", {
1008
- F: __dxlog_file,
1009
- L: 513,
1010
- S: this,
1011
- A: [
1012
- "currentRow",
1013
- "'Invalid row index'"
1014
- ]
1015
- });
1016
- const snapshot = getSnapshot(currentRow);
1017
- setValue(snapshot, field.path, transformedValue);
1018
- const schema = getSchema(currentRow);
1019
- invariant(schema, void 0, {
1020
- F: __dxlog_file,
1021
- L: 519,
1022
- S: this,
1023
- A: [
1024
- "schema",
1025
- ""
1026
- ]
1027
- });
1028
- const validationResult = validateSchema(schema, snapshot);
1029
- if (validationResult && validationResult.length > 0) {
1030
- const error = validationResult[0];
1031
- invariant(error.path === field.path, void 0, {
1032
- F: __dxlog_file,
1033
- L: 524,
1034
- S: this,
1035
- A: [
1036
- "error.path === field.path",
1037
- ""
1038
- ]
1039
- });
1040
- return {
1041
- valid: false,
1042
- error: error.message
1043
- };
1044
- }
1045
- return {
1046
- valid: true
1047
- };
1048
- }
1049
- };
1050
- setCellData = (cell, value) => {
1051
- const { col, row, plane } = cell;
1052
- const fields = this._projection?.fields ?? [];
1053
- if (col < 0 || col >= fields.length) {
1054
- return;
1055
- }
1056
- const field = fields[col];
1057
- const { props } = this._projection.getFieldProjection(field.id);
1058
- const transformedValue = editorTextToCellValue(props, value);
1059
- if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
1060
- return;
1061
- }
1062
- if (plane === "frozenRowsEnd") {
1063
- if (row >= 0 && row < this._draftRows.value.length) {
1064
- setValue(this._draftRows.value[row].data, field.path, transformedValue);
1065
- this.validateDraftRow(row);
1066
- }
1067
- } else {
1068
- const rowIdx = this._sorting.getDataIndex(row);
1069
- setValue(this._rows.value[rowIdx], field.path, transformedValue);
1070
- }
1071
- };
1072
803
  /**
1073
804
  * Updates a cell's value using a transform function.
1074
805
  * @param {DxGridPlanePosition} position - The position of the cell to update.
@@ -1149,6 +880,240 @@ var TableModel = class extends Resource2 {
1149
880
  saveView() {
1150
881
  this._sorting.save();
1151
882
  }
883
+ constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
884
+ top: [],
885
+ bottom: []
886
+ }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
887
+ super(), _define_property3(this, "_view", void 0), _define_property3(this, "_projection", void 0), _define_property3(this, "_table", void 0), _define_property3(this, "_visibleRange", signal3({
888
+ start: {
889
+ row: 0,
890
+ col: 0
891
+ },
892
+ end: {
893
+ row: 0,
894
+ col: 0
895
+ }
896
+ })), _define_property3(this, "_onInsertRow", void 0), _define_property3(this, "_onDeleteRows", void 0), _define_property3(this, "_onDeleteColumn", void 0), _define_property3(this, "_onCellUpdate", void 0), _define_property3(this, "_onRowOrderChange", void 0), _define_property3(this, "_onRowAction", void 0), _define_property3(this, "_rowActions", void 0), _define_property3(this, "_features", void 0), _define_property3(this, "_rows", signal3([])), _define_property3(this, "_draftRows", signal3([])), _define_property3(this, "_sorting", void 0), _define_property3(this, "_pinnedRows", void 0), _define_property3(this, "_selection", void 0), _define_property3(this, "_columnMeta", void 0), //
897
+ // Data
898
+ //
899
+ _define_property3(this, "setRows", (obj) => {
900
+ this._rows.value = obj;
901
+ }), _define_property3(this, "getRowCount", () => this._rows.value.length), /**
902
+ * @reactive
903
+ */
904
+ _define_property3(this, "getDraftRowCount", () => this._draftRows.value.length), _define_property3(this, "getColumnCount", () => this._projection?.fields.length ?? 0), _define_property3(this, "insertRow", () => {
905
+ const result = this._onInsertRow?.();
906
+ if (result === "draft" && this._draftRows.value.length === 0) {
907
+ this.createDraftRow();
908
+ }
909
+ return result ?? "final";
910
+ }), _define_property3(this, "commitDraftRow", (draftRowIndex) => {
911
+ if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
912
+ return false;
913
+ }
914
+ const draftRow = this._draftRows.value[draftRowIndex];
915
+ if (!draftRow.valid) {
916
+ return false;
917
+ }
918
+ const insertRowResult = this._onInsertRow?.(draftRow.data);
919
+ if (insertRowResult === "final") {
920
+ const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
921
+ this._draftRows.value = newDraftRows;
922
+ }
923
+ return insertRowResult === "final";
924
+ }), _define_property3(this, "deleteRow", (rowIndex) => {
925
+ const row = this._sorting.getDataIndex(rowIndex);
926
+ const obj = this._rows.value[row];
927
+ const objectsToDelete = [];
928
+ if (this.features.selection.enabled && this._selection.hasSelection.value) {
929
+ const selectedRows = this._selection.getSelectedRows();
930
+ objectsToDelete.push(...selectedRows);
931
+ } else {
932
+ objectsToDelete.push(obj);
933
+ }
934
+ this._onDeleteRows?.(row, objectsToDelete);
935
+ }), _define_property3(this, "handleRowAction", (actionId, rowIndex) => {
936
+ if (!this._onRowAction) {
937
+ return;
938
+ }
939
+ const row = this._sorting.getDataIndex(rowIndex);
940
+ const data = this._rows.value[row];
941
+ if (data) {
942
+ this._onRowAction(actionId, data);
943
+ }
944
+ }), _define_property3(this, "getCellData", (cell) => {
945
+ const { col, row, plane } = cell;
946
+ const fields = this._projection?.fields ?? [];
947
+ if (col < 0 || col >= fields.length) {
948
+ return void 0;
949
+ }
950
+ const field = fields[col];
951
+ let value;
952
+ if (plane === "frozenRowsEnd") {
953
+ if (row >= 0 && row < this._draftRows.value.length) {
954
+ value = getValue2(this._draftRows.value[row].data, field.path);
955
+ } else {
956
+ return void 0;
957
+ }
958
+ } else {
959
+ const dataIndex = this._sorting.getDataIndex(row);
960
+ value = getValue2(this._rows.value[dataIndex], field.path);
961
+ }
962
+ if (value == null) {
963
+ return "";
964
+ }
965
+ const { props } = this._projection.getFieldProjection(field.id);
966
+ switch (props.format) {
967
+ case FormatEnum2.Ref: {
968
+ if (!field.referencePath) {
969
+ return "";
970
+ }
971
+ return getValue2(value.target, field.referencePath);
972
+ }
973
+ default: {
974
+ return formatForEditing({
975
+ type: props.type,
976
+ format: props.format,
977
+ value
978
+ });
979
+ }
980
+ }
981
+ }), _define_property3(this, "validateCellData", async ({ col, row, plane }, value) => {
982
+ const fields = this._projection?.fields ?? [];
983
+ if (col < 0 || col >= fields.length) {
984
+ return {
985
+ valid: false,
986
+ error: "Invalid column index"
987
+ };
988
+ }
989
+ const field = fields[col];
990
+ const { props } = this._projection.getFieldProjection(field.id);
991
+ const transformedValue = editorTextToCellValue(props, value);
992
+ const isDraftRow = plane === "frozenRowsEnd";
993
+ if (isDraftRow) {
994
+ const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
995
+ if (isInvalidDraftRowIndex) {
996
+ return {
997
+ valid: false,
998
+ error: "Invalid draft row index"
999
+ };
1000
+ }
1001
+ const draftRow = this._draftRows.value[row];
1002
+ const snapshot = {
1003
+ ...draftRow.data
1004
+ };
1005
+ setValue(snapshot, field.path, transformedValue);
1006
+ const validationErrors = this.validateDraftRowData(snapshot);
1007
+ if (validationErrors.length > 0) {
1008
+ const error = validationErrors.find((err) => err.path === field.path);
1009
+ if (error) {
1010
+ return {
1011
+ valid: false,
1012
+ error: error.message
1013
+ };
1014
+ }
1015
+ }
1016
+ return {
1017
+ valid: true
1018
+ };
1019
+ } else {
1020
+ const rowIdx = this._sorting.getDataIndex(row);
1021
+ const currentRow = this._rows.value[rowIdx];
1022
+ invariant(currentRow, "Invalid row index", {
1023
+ F: __dxlog_file,
1024
+ L: 522,
1025
+ S: this,
1026
+ A: [
1027
+ "currentRow",
1028
+ "'Invalid row index'"
1029
+ ]
1030
+ });
1031
+ const snapshot = getSnapshot(currentRow);
1032
+ setValue(snapshot, field.path, transformedValue);
1033
+ const schema2 = getSchema(currentRow);
1034
+ invariant(schema2, void 0, {
1035
+ F: __dxlog_file,
1036
+ L: 528,
1037
+ S: this,
1038
+ A: [
1039
+ "schema",
1040
+ ""
1041
+ ]
1042
+ });
1043
+ const validationResult = validateSchema(schema2, snapshot);
1044
+ if (validationResult && validationResult.length > 0) {
1045
+ const error = validationResult[0];
1046
+ invariant(error.path === field.path, void 0, {
1047
+ F: __dxlog_file,
1048
+ L: 533,
1049
+ S: this,
1050
+ A: [
1051
+ "error.path === field.path",
1052
+ ""
1053
+ ]
1054
+ });
1055
+ return {
1056
+ valid: false,
1057
+ error: error.message
1058
+ };
1059
+ }
1060
+ return {
1061
+ valid: true
1062
+ };
1063
+ }
1064
+ }), _define_property3(this, "setCellData", (cell, value) => {
1065
+ const { col, row, plane } = cell;
1066
+ const fields = this._projection?.fields ?? [];
1067
+ if (col < 0 || col >= fields.length) {
1068
+ return;
1069
+ }
1070
+ const field = fields[col];
1071
+ const { props } = this._projection.getFieldProjection(field.id);
1072
+ const transformedValue = editorTextToCellValue(props, value);
1073
+ if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
1074
+ return;
1075
+ }
1076
+ if (plane === "frozenRowsEnd") {
1077
+ if (row >= 0 && row < this._draftRows.value.length) {
1078
+ setValue(this._draftRows.value[row].data, field.path, transformedValue);
1079
+ this.validateDraftRow(row);
1080
+ }
1081
+ } else {
1082
+ const rowIdx = this._sorting.getDataIndex(row);
1083
+ setValue(this._rows.value[rowIdx], field.path, transformedValue);
1084
+ }
1085
+ });
1086
+ this._view = view;
1087
+ this._projection = projection ?? new ProjectionModel2(schema, view.projection);
1088
+ this._projection.normalizeView();
1089
+ this._features = {
1090
+ ...defaultFeatures,
1091
+ ...features
1092
+ };
1093
+ invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1094
+ F: __dxlog_file,
1095
+ L: 149,
1096
+ S: this,
1097
+ A: [
1098
+ "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1099
+ "'Single selection is not compatible with editable tables.'"
1100
+ ]
1101
+ });
1102
+ this._sorting = new TableSorting(this._rows, this._view, this._projection);
1103
+ if (sorting.length > 0) {
1104
+ const [sort] = sorting;
1105
+ this._sorting.setSort(sort.fieldId, sort.direction);
1106
+ }
1107
+ this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
1108
+ this._pinnedRows = pinnedRows;
1109
+ this._rowActions = rowActions;
1110
+ this._onInsertRow = onInsertRow;
1111
+ this._onDeleteRows = onDeleteRows;
1112
+ this._onDeleteColumn = onDeleteColumn;
1113
+ this._onCellUpdate = onCellUpdate;
1114
+ this._onRowOrderChange = onRowOrderChange;
1115
+ this._onRowAction = onRowAction;
1116
+ }
1152
1117
  };
1153
1118
  var editorTextToCellValue = (props, value) => {
1154
1119
  switch (props.format) {
@@ -1183,117 +1148,108 @@ var editorTextToCellValue = (props, value) => {
1183
1148
 
1184
1149
  // src/model/modal-controller.ts
1185
1150
  import { signal as signal4 } from "@preact/signals-core";
1186
- import { log } from "@dxos/log";
1187
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
1151
+ function _define_property4(obj, key, value) {
1152
+ if (key in obj) {
1153
+ Object.defineProperty(obj, key, {
1154
+ value,
1155
+ enumerable: true,
1156
+ configurable: true,
1157
+ writable: true
1158
+ });
1159
+ } else {
1160
+ obj[key] = value;
1161
+ }
1162
+ return obj;
1163
+ }
1188
1164
  var ModalController = class {
1189
- _state = signal4({
1190
- type: "closed"
1191
- });
1192
- _triggerRef = {
1193
- current: null
1194
- };
1195
1165
  get state() {
1196
1166
  return this._state;
1197
1167
  }
1198
1168
  get trigger() {
1199
1169
  return this._triggerRef;
1200
1170
  }
1201
- setTrigger = (trigger) => {
1202
- this._triggerRef.current = trigger;
1203
- };
1204
- showRowMenu = (rowIndex) => {
1205
- this._state.value = {
1206
- type: "row",
1207
- rowIndex
1208
- };
1209
- };
1210
- showColumnMenu = (fieldId) => {
1211
- this._state.value = {
1212
- type: "column",
1213
- fieldId
1214
- };
1215
- };
1216
- showColumnCreator = () => {
1217
- this._state.value = {
1218
- type: "columnSettings",
1219
- mode: {
1220
- type: "create"
1171
+ constructor() {
1172
+ _define_property4(this, "_state", signal4({
1173
+ type: "closed"
1174
+ }));
1175
+ _define_property4(this, "_triggerRef", {
1176
+ current: null
1177
+ });
1178
+ _define_property4(this, "setTrigger", (trigger) => {
1179
+ this._triggerRef.current = trigger;
1180
+ });
1181
+ _define_property4(this, "showRowMenu", (rowIndex) => {
1182
+ this._state.value = {
1183
+ type: "row",
1184
+ rowIndex
1185
+ };
1186
+ });
1187
+ _define_property4(this, "showColumnMenu", (fieldId) => {
1188
+ this._state.value = {
1189
+ type: "column",
1190
+ fieldId
1191
+ };
1192
+ });
1193
+ _define_property4(this, "showColumnCreator", () => {
1194
+ this._state.value = {
1195
+ type: "columnSettings",
1196
+ mode: {
1197
+ type: "create"
1198
+ }
1199
+ };
1200
+ });
1201
+ _define_property4(this, "showReferencePanel", (targetId, schemaId) => {
1202
+ this._state.value = {
1203
+ type: "refPanel",
1204
+ targetId,
1205
+ typename: schemaId
1206
+ };
1207
+ });
1208
+ _define_property4(this, "openColumnSettings", () => {
1209
+ if (this._state.value.type === "column") {
1210
+ const fieldId = this._state.value.fieldId;
1211
+ requestAnimationFrame(() => {
1212
+ this._state.value = {
1213
+ type: "columnSettings",
1214
+ mode: {
1215
+ type: "edit",
1216
+ fieldId
1217
+ }
1218
+ };
1219
+ });
1221
1220
  }
1222
- };
1223
- };
1224
- showReferencePanel = (targetId, schemaId) => {
1225
- this._state.value = {
1226
- type: "refPanel",
1227
- targetId,
1228
- typename: schemaId
1229
- };
1230
- };
1231
- openColumnSettings = () => {
1232
- if (this._state.value.type === "column") {
1233
- const fieldId = this._state.value.fieldId;
1234
- requestAnimationFrame(() => {
1235
- this._state.value = {
1236
- type: "columnSettings",
1237
- mode: {
1238
- type: "edit",
1239
- fieldId
1240
- }
1241
- };
1242
- });
1243
- }
1244
- };
1245
- openCreateRef = (typename, anchorCell, initialValues, onCreate) => {
1246
- if (anchorCell) {
1247
- this._triggerRef.current = anchorCell;
1221
+ });
1222
+ _define_property4(this, "close", () => {
1248
1223
  this._state.value = {
1249
- type: "createRefPanel",
1250
- typename,
1251
- initialValues,
1252
- onCreate
1224
+ type: "closed"
1253
1225
  };
1254
- } else {
1255
- log.warn("anchor cell not found while creating new ref", void 0, {
1256
- F: __dxlog_file2,
1257
- L: 86,
1258
- S: this,
1259
- C: (f, a) => f(...a)
1260
- });
1261
- }
1262
- };
1263
- close = () => {
1264
- this._state.value = {
1265
- type: "closed"
1266
- };
1267
- };
1226
+ });
1227
+ }
1268
1228
  };
1269
1229
 
1270
1230
  // src/model/table-presentation.ts
1271
1231
  import { signal as signal5 } from "@preact/signals-core";
1272
- import { isNotNullable } from "effect/Predicate";
1273
- import { Obj as Obj4 } from "@dxos/echo";
1274
- import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo-schema";
1232
+ import * as Predicate from "effect/Predicate";
1233
+ import { Obj as Obj3 } from "@dxos/echo";
1234
+ import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1275
1235
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1276
1236
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1277
1237
  import { mx } from "@dxos/react-ui-theme";
1278
1238
  import { VIEW_FIELD_LIMIT } from "@dxos/schema";
1279
- var TablePresentation = class {
1280
- model;
1281
- _visibleRange;
1282
- fieldProjectionCache;
1283
- constructor(model, _visibleRange = signal5({
1284
- start: {
1285
- row: 0,
1286
- col: 0
1287
- },
1288
- end: {
1289
- row: 0,
1290
- col: 0
1291
- }
1292
- })) {
1293
- this.model = model;
1294
- this._visibleRange = _visibleRange;
1295
- this.fieldProjectionCache = /* @__PURE__ */ new Map();
1239
+ function _define_property5(obj, key, value) {
1240
+ if (key in obj) {
1241
+ Object.defineProperty(obj, key, {
1242
+ value,
1243
+ enumerable: true,
1244
+ configurable: true,
1245
+ writable: true
1246
+ });
1247
+ } else {
1248
+ obj[key] = value;
1296
1249
  }
1250
+ return obj;
1251
+ }
1252
+ var TablePresentation = class {
1297
1253
  getCells(range, plane) {
1298
1254
  this.fieldProjectionCache.clear();
1299
1255
  let cells;
@@ -1321,7 +1277,7 @@ var TablePresentation = class {
1321
1277
  cells = this.getDraftRowCells(range);
1322
1278
  break;
1323
1279
  case "fixedEndStart":
1324
- cells = this.getDraftSelectCells(range);
1280
+ cells = this.getDraftIconCells(range);
1325
1281
  break;
1326
1282
  case "fixedEndEnd":
1327
1283
  cells = this.getDraftActionCells(range);
@@ -1381,10 +1337,7 @@ var TablePresentation = class {
1381
1337
  }
1382
1338
  };
1383
1339
  const classes = [];
1384
- const formatClasses = cellClassesForFieldType({
1385
- type: props.type,
1386
- format: props.format
1387
- });
1340
+ const formatClasses = cellClassesForFieldType(props);
1388
1341
  if (formatClasses) {
1389
1342
  classes.push(formatClasses);
1390
1343
  }
@@ -1392,9 +1345,7 @@ var TablePresentation = class {
1392
1345
  if (rowSelectionClasses) {
1393
1346
  classes.push(rowSelectionClasses);
1394
1347
  }
1395
- if (classes.length > 0) {
1396
- cell.className = mx(classes.flat());
1397
- }
1348
+ cell.className = mx(classes);
1398
1349
  if (props.type === TypeEnum2.Array) {
1399
1350
  const targetArray = getValue3(obj, field.path);
1400
1351
  if (targetArray && Array.isArray(targetArray)) {
@@ -1416,7 +1367,7 @@ var TablePresentation = class {
1416
1367
  }
1417
1368
  return "Object";
1418
1369
  };
1419
- const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
1370
+ const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
1420
1371
  return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
1421
1372
  }).join("");
1422
1373
  cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
@@ -1425,8 +1376,8 @@ var TablePresentation = class {
1425
1376
  if (props.format === FormatEnum3.Ref && props.referenceSchema) {
1426
1377
  const targetObj = getValue3(obj, field.path)?.target;
1427
1378
  if (targetObj) {
1428
- const dxn = Obj4.getDXN(targetObj)?.toString();
1429
- cell.accessoryHtml = `<dx-ref-tag refId=${dxn} class="dx-button is-6 pli-[3px] pbe-[2px] min-bs-0 absolute inline-end-2 block-start-[.2rem]" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
1379
+ const dxn = Obj3.getDXN(targetObj)?.toString();
1380
+ 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>`;
1430
1381
  }
1431
1382
  }
1432
1383
  if (props.format === FormatEnum3.Boolean) {
@@ -1488,27 +1439,39 @@ var TablePresentation = class {
1488
1439
  const cells = {};
1489
1440
  const fields = this.model.projection?.fields ?? [];
1490
1441
  const draftRows = this.model.draftRows.value;
1491
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1492
- const draftRow = draftRows[row];
1442
+ if (draftRows.length === 0) {
1493
1443
  for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1494
- const cellIndex = toPlaneCellIndex({
1444
+ cells[toPlaneCellIndex({
1495
1445
  col,
1496
- row
1497
- });
1498
- const field = fields[col];
1499
- if (!field) {
1500
- continue;
1501
- }
1502
- this.createDataCell(cells, draftRow.data, field, col, row);
1503
- if (this.model.hasDraftRowValidationError(row, field.path)) {
1504
- const cellValue = cells[cellIndex];
1505
- if (cellValue) {
1506
- const existingClasses = cellValue.className || "";
1507
- const draftClasses = "dx-grid__cell--flagged";
1508
- cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
1446
+ row: 0
1447
+ })] = {
1448
+ value: "",
1449
+ readonly: true,
1450
+ className: "dx-grid__row--cta__cell"
1451
+ };
1452
+ }
1453
+ } else {
1454
+ for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1455
+ const draftRow = draftRows[row];
1456
+ for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1457
+ const cellIndex = toPlaneCellIndex({
1458
+ col,
1459
+ row
1460
+ });
1461
+ const field = fields[col];
1462
+ if (!field) {
1463
+ continue;
1464
+ }
1465
+ this.createDataCell(cells, draftRow.data, field, col, row);
1466
+ if (this.model.hasDraftRowValidationError(row, field.path)) {
1467
+ const cellValue = cells[cellIndex];
1468
+ if (cellValue) {
1469
+ const existingClasses = cellValue.className || "";
1470
+ const draftClasses = "dx-grid__cell--flagged";
1471
+ cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
1472
+ }
1509
1473
  }
1510
1474
  }
1511
- cells[cellIndex].className += " !bg-toolbarSurface";
1512
1475
  }
1513
1476
  }
1514
1477
  return cells;
@@ -1525,10 +1488,10 @@ var TablePresentation = class {
1525
1488
  row: 0
1526
1489
  })] = {
1527
1490
  // TODO(burdon): Use same logic as form for fallback title.
1528
- value: props.title ?? field.path,
1529
- readonly: true,
1491
+ value: "",
1530
1492
  resizeHandle: "col",
1531
1493
  accessoryHtml: `
1494
+ <span class="grow min-is-0 truncate">${props.title ?? field.path}</span>
1532
1495
  ${direction !== void 0 ? tableButtons.sort.render({
1533
1496
  fieldId: field.id,
1534
1497
  direction
@@ -1537,7 +1500,7 @@ var TablePresentation = class {
1537
1500
  fieldId: field.id
1538
1501
  })}
1539
1502
  `,
1540
- className: "!bg-toolbarSurface"
1503
+ className: "!bg-toolbarSurface !text-description [&>div]:flex [&>div]:items-stretch"
1541
1504
  };
1542
1505
  }
1543
1506
  return cells;
@@ -1628,39 +1591,67 @@ var TablePresentation = class {
1628
1591
  getDraftActionCells(range) {
1629
1592
  const cells = {};
1630
1593
  const draftRows = this.model.draftRows.value;
1631
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1632
- const draftRow = draftRows[row];
1633
- const disabled = !draftRow.valid;
1594
+ if (draftRows.length === 0) {
1634
1595
  cells[toPlaneCellIndex({
1635
1596
  col: 0,
1636
- row
1597
+ row: 0
1637
1598
  })] = {
1638
1599
  value: "",
1639
- readonly: true,
1640
- accessoryHtml: tableButtons.saveDraftRow.render({
1641
- rowIndex: row,
1642
- disabled
1643
- }),
1644
- className: "!bg-toolbarSurface"
1600
+ className: "dx-grid__row--cta__cell",
1601
+ readonly: true
1645
1602
  };
1603
+ } else {
1604
+ for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1605
+ const draftRow = draftRows[row];
1606
+ const disabled = !draftRow.valid;
1607
+ cells[toPlaneCellIndex({
1608
+ col: 0,
1609
+ row
1610
+ })] = {
1611
+ value: "",
1612
+ readonly: true,
1613
+ accessoryHtml: tableButtons.saveDraftRow.render({
1614
+ rowIndex: row,
1615
+ disabled
1616
+ })
1617
+ };
1618
+ }
1646
1619
  }
1647
1620
  return cells;
1648
1621
  }
1649
- getDraftSelectCells(range) {
1622
+ getDraftIconCells(range) {
1650
1623
  const cells = {};
1651
1624
  const draftRows = this.model.draftRows.value;
1652
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1625
+ for (let row = range.start.row; row <= range.end.row; row++) {
1653
1626
  cells[toPlaneCellIndex({
1654
1627
  col: 0,
1655
1628
  row
1656
1629
  })] = {
1657
1630
  value: "",
1658
1631
  readonly: true,
1659
- className: "!bg-toolbarSurface"
1632
+ accessoryHtml: '<dx-icon icon="ph--plus--regular" class="contents"></dx-icon>',
1633
+ className: mx("[&>div]:grid [&>div]:place-content-center", draftRows.length < 1 && "dx-grid__row--cta__cell")
1660
1634
  };
1661
1635
  }
1662
1636
  return cells;
1663
1637
  }
1638
+ constructor(model, _visibleRange = signal5({
1639
+ start: {
1640
+ row: 0,
1641
+ col: 0
1642
+ },
1643
+ end: {
1644
+ row: 0,
1645
+ col: 0
1646
+ }
1647
+ })) {
1648
+ _define_property5(this, "model", void 0);
1649
+ _define_property5(this, "_visibleRange", void 0);
1650
+ _define_property5(this, "fieldProjectionCache", void 0);
1651
+ this.model = model;
1652
+ this._visibleRange = _visibleRange;
1653
+ this.fieldProjectionCache = /* @__PURE__ */ new Map();
1654
+ }
1664
1655
  };
1665
1656
  var cellClassesForRowSelection = (selected, selectionMode) => {
1666
1657
  if (!selected) {
@@ -1774,18 +1765,18 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1774
1765
 
1775
1766
  // src/hooks/useAddRow.ts
1776
1767
  import { useCallback } from "react";
1777
- import { Obj as Obj5 } from "@dxos/echo";
1768
+ import { Obj as Obj4 } from "@dxos/echo";
1778
1769
  var useAddRow = ({ space, schema }) => {
1779
1770
  return useCallback((data) => {
1780
1771
  if (space && schema) {
1781
1772
  try {
1782
- space.db.add(Obj5.make(schema, data ?? {}));
1783
- return true;
1773
+ space.db.add(Obj4.make(schema, data ?? {}));
1774
+ return "final";
1784
1775
  } catch (error) {
1785
- return false;
1776
+ return "draft";
1786
1777
  }
1787
1778
  }
1788
- return false;
1779
+ return "final";
1789
1780
  }, [
1790
1781
  space,
1791
1782
  schema
@@ -1796,7 +1787,6 @@ export {
1796
1787
  getBaseSchema,
1797
1788
  makeDynamicTable,
1798
1789
  touch,
1799
- createTable,
1800
1790
  BUTTON_IDENTIFIERS,
1801
1791
  tableButtons,
1802
1792
  CONTROL_IDENTIFIERS,
@@ -1811,4 +1801,4 @@ export {
1811
1801
  useTableModel,
1812
1802
  useAddRow
1813
1803
  };
1814
- //# sourceMappingURL=chunk-ZAOSIG3L.mjs.map
1804
+ //# sourceMappingURL=chunk-OZTXLZGM.mjs.map