@dxos/react-ui-table 0.8.4-main.5ad4a44 → 0.8.4-main.66e292d

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 (92) hide show
  1. package/dist/lib/browser/chunk-5XWSB3JP.mjs +71 -0
  2. package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-OZTXLZGM.mjs → chunk-KNC7XYT6.mjs} +521 -542
  4. package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +75 -59
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +14 -27
  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-S56Z4V4X.mjs → chunk-CWSGS3Y2.mjs} +521 -542
  12. package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-MKTMOY46.mjs +72 -0
  14. package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +75 -59
  16. package/dist/lib/node-esm/index.mjs.map +3 -3
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +14 -27
  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.map +1 -1
  22. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -2
  23. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  24. package/dist/types/src/components/Table/Relations.stories.d.ts +7 -7
  25. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  26. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/Table.stories.d.ts +67 -4
  28. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  30. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
  31. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  32. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
  33. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  34. package/dist/types/src/components/testing.d.ts +0 -2
  35. package/dist/types/src/components/testing.d.ts.map +1 -1
  36. package/dist/types/src/hooks/index.d.ts +2 -1
  37. package/dist/types/src/hooks/index.d.ts.map +1 -1
  38. package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
  39. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  40. package/dist/types/src/hooks/useTableModel.d.ts +4 -5
  41. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  42. package/dist/types/src/model/table-model.d.ts +7 -9
  43. package/dist/types/src/model/table-model.d.ts.map +1 -1
  44. package/dist/types/src/model/table-sorting.d.ts +8 -4
  45. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  46. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  47. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  48. package/dist/types/src/testing/useTestTableModel.d.ts +21 -15
  49. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  50. package/dist/types/src/translations.d.ts +2 -2
  51. package/dist/types/src/types/Table.d.ts +28 -0
  52. package/dist/types/src/types/Table.d.ts.map +1 -0
  53. package/dist/types/src/types/index.d.ts +1 -1
  54. package/dist/types/src/types/index.d.ts.map +1 -1
  55. package/dist/types/src/util/dynamic-table.d.ts +7 -6
  56. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  57. package/dist/types/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +41 -40
  59. package/src/components/Table/DynamicTable.stories.tsx +7 -7
  60. package/src/components/Table/DynamicTable.tsx +12 -4
  61. package/src/components/Table/Relations.stories.tsx +24 -35
  62. package/src/components/Table/RowActionsMenu.tsx +21 -13
  63. package/src/components/Table/Table.stories.tsx +58 -53
  64. package/src/components/TableCellEditor/FormCellEditor.tsx +11 -11
  65. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +11 -9
  66. package/src/components/TableCellEditor/TableCellEditor.tsx +4 -4
  67. package/src/components/TableToolbar/TableToolbar.tsx +32 -22
  68. package/src/components/testing.ts +3 -3
  69. package/src/hooks/index.ts +2 -1
  70. package/src/hooks/useProjectionModel.ts +19 -0
  71. package/src/hooks/useTableModel.ts +11 -13
  72. package/src/model/table-model.test.ts +5 -5
  73. package/src/model/table-model.ts +34 -40
  74. package/src/model/table-presentation.test.ts +5 -5
  75. package/src/model/table-presentation.ts +9 -9
  76. package/src/model/table-sorting.ts +28 -19
  77. package/src/playwright/TableManager.ts +3 -3
  78. package/src/playwright/smoke.spec.ts +8 -6
  79. package/src/testing/useTestTableModel.ts +32 -24
  80. package/src/translations.ts +2 -2
  81. package/src/types/Table.ts +89 -0
  82. package/src/types/index.ts +1 -1
  83. package/src/util/dynamic-table.ts +12 -16
  84. package/dist/lib/browser/chunk-4K7JPALT.mjs +0 -66
  85. package/dist/lib/browser/chunk-4K7JPALT.mjs.map +0 -7
  86. package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +0 -7
  87. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs +0 -67
  88. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +0 -7
  89. package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +0 -7
  90. package/dist/types/src/types/schema.d.ts +0 -28
  91. package/dist/types/src/types/schema.d.ts.map +0 -1
  92. package/src/types/schema.ts +0 -73
@@ -1,12 +1,11 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
- schema_exports
4
- } from "./chunk-MK6OVUF6.mjs";
3
+ Table_exports
4
+ } from "./chunk-MKTMOY46.mjs";
5
5
 
6
6
  // src/util/dynamic-table.ts
7
- import { Filter, Obj, Query } from "@dxos/echo";
8
- import { getTypename, toJsonSchema } from "@dxos/echo/internal";
9
- import { ProjectionModel, createView, getSchemaFromPropertyDefinitions } from "@dxos/schema";
7
+ import { Filter, Obj, Query, Ref, Type } from "@dxos/echo";
8
+ import { ProjectionModel, View, getSchemaFromPropertyDefinitions } from "@dxos/schema";
10
9
  var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
11
10
  if (typename && properties) {
12
11
  const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
@@ -16,8 +15,8 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
16
15
  };
17
16
  } else if (schema) {
18
17
  return {
19
- typename: getTypename(schema),
20
- jsonSchema: toJsonSchema(schema)
18
+ typename: Type.getTypename(schema),
19
+ jsonSchema: Type.toJsonSchema(schema)
21
20
  };
22
21
  } else if (typename && jsonSchema) {
23
22
  return {
@@ -29,25 +28,25 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
29
28
  }
30
29
  };
31
30
  var makeDynamicTable = ({ jsonSchema, properties }) => {
32
- const table = Obj.make(schema_exports.Table, {
33
- sizes: {}
34
- });
35
- const view = createView({
31
+ const view = View.make({
36
32
  query: Query.select(Filter.everything()),
37
33
  jsonSchema,
38
- presentation: table,
39
34
  ...properties && {
40
35
  fields: properties.map((property) => property.name)
41
36
  }
42
37
  });
38
+ const object = Obj.make(Table_exports.Table, {
39
+ view: Ref.make(view),
40
+ sizes: {}
41
+ });
43
42
  const projection = new ProjectionModel(jsonSchema, view.projection);
44
43
  projection.normalizeView();
45
44
  if (properties && projection.fields) {
46
- setProperties(view, projection, table, properties);
45
+ setProperties(view, projection, object, properties);
47
46
  }
48
47
  return {
49
48
  projection,
50
- view
49
+ object
51
50
  };
52
51
  };
53
52
  var setProperties = (view, projection, table, properties) => {
@@ -274,14 +273,13 @@ var narrowSchema = (schema, paths) => {
274
273
  // src/model/table-model.ts
275
274
  import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
276
275
  import { Resource as Resource2 } from "@dxos/context";
277
- import { Obj as Obj2, Ref } from "@dxos/echo";
278
- import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
276
+ import { Format as Format2, Obj as Obj2, Ref as Ref2 } from "@dxos/echo";
277
+ import { getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
279
278
  import { invariant } from "@dxos/invariant";
280
279
  import { ObjectId } from "@dxos/keys";
281
280
  import { getSnapshot, isLiveObject } from "@dxos/live-object";
282
- import { fullyQualifiedId } from "@dxos/react-client/echo";
283
281
  import { formatForEditing, parseValue } from "@dxos/react-ui-form";
284
- import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
282
+ import { validateSchema } from "@dxos/schema";
285
283
 
286
284
  // src/util/tag.ts
287
285
  var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
@@ -302,20 +300,34 @@ var extractTagIds = (value) => {
302
300
  // src/model/selection-model.ts
303
301
  import { computed, effect, signal } from "@preact/signals-core";
304
302
  import { Resource } from "@dxos/context";
305
- function _define_property(obj, key, value) {
306
- if (key in obj) {
307
- Object.defineProperty(obj, key, {
308
- value,
309
- enumerable: true,
310
- configurable: true,
311
- writable: true
312
- });
313
- } else {
314
- obj[key] = value;
315
- }
316
- return obj;
317
- }
318
303
  var SelectionModel = class extends Resource {
304
+ _rows;
305
+ _selectionMode;
306
+ _initialSelection;
307
+ _onSelectionChanged;
308
+ _selection;
309
+ _validSelectedIds = computed(() => {
310
+ const rows = this._rows.value;
311
+ if (!rows) {
312
+ return /* @__PURE__ */ new Set();
313
+ }
314
+ const validIds = new Set(rows.map((row) => row.id));
315
+ return new Set([
316
+ ...this._selection.value
317
+ ].filter((id) => validIds.has(id)));
318
+ });
319
+ _hasSelection = computed(() => this._validSelectedIds.value.size > 0);
320
+ _allSelected = computed(() => {
321
+ const rows = this._rows.value;
322
+ if (rows.length === 0) {
323
+ return false;
324
+ }
325
+ return rows.every((row) => this._selection.value.has(row.id));
326
+ });
327
+ constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
328
+ super(), this._rows = _rows, this._selectionMode = _selectionMode, this._initialSelection = _initialSelection, this._onSelectionChanged = _onSelectionChanged;
329
+ this._selection = signal(new Set(this._initialSelection));
330
+ }
319
331
  async _open() {
320
332
  const selectionWatcher = effect(() => {
321
333
  touch(this._selection.value);
@@ -338,80 +350,80 @@ var SelectionModel = class extends Resource {
338
350
  get selectionMode() {
339
351
  return this._selectionMode;
340
352
  }
341
- constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
342
- 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), //
343
- // Manipulation
344
- //
345
- _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(() => {
346
- const rows = this._rows.value;
347
- if (!rows) {
348
- return /* @__PURE__ */ new Set();
349
- }
350
- const validIds = new Set(rows.map((row) => row.id));
351
- return new Set([
352
- ...this._selection.value
353
- ].filter((id) => validIds.has(id)));
354
- }), this._hasSelection = computed(() => this._validSelectedIds.value.size > 0), this._allSelected = computed(() => {
355
- const rows = this._rows.value;
356
- if (rows.length === 0) {
357
- return false;
353
+ getSelectedRows = () => {
354
+ const selectedIds = this._validSelectedIds.value;
355
+ return this._rows.value.filter((row) => selectedIds.has(row.id));
356
+ };
357
+ isRowIndexSelected = (rowIndex) => {
358
+ const row = this._rows.value[rowIndex];
359
+ return this._selection.value.has(row.id);
360
+ };
361
+ isObjectSelected = (object) => {
362
+ return this._selection.value.has(object.id);
363
+ };
364
+ //
365
+ // Manipulation
366
+ //
367
+ toggleSelectionForRowIndex = (rowIndex) => {
368
+ const row = this._rows.value[rowIndex];
369
+ const newSelection = new Set(this._selection.value);
370
+ if (newSelection.has(row.id)) {
371
+ newSelection.delete(row.id);
372
+ } else {
373
+ if (this._selectionMode === "single") {
374
+ newSelection.clear();
358
375
  }
359
- return rows.every((row) => this._selection.value.has(row.id));
360
- }), this.getSelectedRows = () => {
361
- const selectedIds = this._validSelectedIds.value;
362
- return this._rows.value.filter((row) => selectedIds.has(row.id));
363
- }, this.isRowIndexSelected = (rowIndex) => {
364
- const row = this._rows.value[rowIndex];
365
- return this._selection.value.has(row.id);
366
- }, this.isObjectSelected = (object) => {
367
- return this._selection.value.has(object.id);
368
- }, this.toggleSelectionForRowIndex = (rowIndex) => {
369
- const row = this._rows.value[rowIndex];
370
- const newSelection = new Set(this._selection.value);
371
- if (newSelection.has(row.id)) {
372
- newSelection.delete(row.id);
373
- } else {
374
- if (this._selectionMode === "single") {
375
- newSelection.clear();
376
- }
377
- newSelection.add(row.id);
376
+ newSelection.add(row.id);
377
+ }
378
+ this._selection.value = newSelection;
379
+ };
380
+ setSelection = (mode) => {
381
+ switch (mode) {
382
+ case "all": {
383
+ this._selection.value = new Set(this._rows.value.map((row) => row.id));
384
+ break;
378
385
  }
379
- this._selection.value = newSelection;
380
- }, this.setSelection = (mode) => {
381
- switch (mode) {
382
- case "all": {
383
- this._selection.value = new Set(this._rows.value.map((row) => row.id));
384
- break;
385
- }
386
- case "none": {
387
- this._selection.value = /* @__PURE__ */ new Set();
388
- break;
389
- }
386
+ case "none": {
387
+ this._selection.value = /* @__PURE__ */ new Set();
388
+ break;
390
389
  }
391
- };
392
- this._selection = signal(new Set(this._initialSelection));
393
- }
390
+ }
391
+ };
394
392
  };
395
393
 
396
394
  // src/model/table-sorting.ts
397
395
  import { computed as computed2, signal as signal2 } from "@preact/signals-core";
398
396
  import orderBy from "lodash.orderby";
399
- import { FormatEnum, TypeEnum, getValue } from "@dxos/echo/internal";
397
+ import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
400
398
  import { formatForDisplay } from "@dxos/react-ui-form";
401
- function _define_property2(obj, key, value) {
402
- if (key in obj) {
403
- Object.defineProperty(obj, key, {
404
- value,
405
- enumerable: true,
406
- configurable: true,
407
- writable: true
399
+ var TableSorting = class {
400
+ _displayToDataIndex = /* @__PURE__ */ new Map();
401
+ _rows;
402
+ _getView;
403
+ _projection;
404
+ _localSort = signal2(void 0);
405
+ _isDirty;
406
+ sortedRows;
407
+ constructor({ rows, projection, getView }) {
408
+ this._rows = rows;
409
+ this._getView = getView;
410
+ this._projection = projection;
411
+ this._isDirty = computed2(() => {
412
+ const local = this._localSort.value;
413
+ const viewSort = this._getView().sort?.[0];
414
+ if (local?.type === "cleared") {
415
+ return viewSort !== void 0;
416
+ }
417
+ if (local?.type === "active") {
418
+ if (!viewSort) {
419
+ return true;
420
+ }
421
+ return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
422
+ }
423
+ return false;
408
424
  });
409
- } else {
410
- obj[key] = value;
425
+ this.sortedRows = this.initialiseSortedRows();
411
426
  }
412
- return obj;
413
- }
414
- var TableSorting = class {
415
427
  /**
416
428
  * @reactive
417
429
  * @returns Local sort if present, falls back to view sort.
@@ -424,7 +436,7 @@ var TableSorting = class {
424
436
  if (local?.type === "active") {
425
437
  return local.sort;
426
438
  }
427
- return this._view.sort?.[0];
439
+ return this._getView().sort?.[0];
428
440
  }
429
441
  /**
430
442
  * @reactive
@@ -467,12 +479,13 @@ var TableSorting = class {
467
479
  }
468
480
  save() {
469
481
  if (this._localSort.value !== void 0) {
482
+ const view = this._getView();
470
483
  if (this._localSort.value.type === "active") {
471
- this._view.sort = [
484
+ view.sort = [
472
485
  this._localSort.value.sort
473
486
  ];
474
487
  } else {
475
- this._view.sort = [];
488
+ view.sort = [];
476
489
  }
477
490
  this._localSort.value = void 0;
478
491
  }
@@ -529,7 +542,7 @@ var TableSorting = class {
529
542
  if (value == null) {
530
543
  return value;
531
544
  }
532
- if (format === FormatEnum.SingleSelect) {
545
+ if (format === Format.TypeFormat.SingleSelect) {
533
546
  const options = props.options;
534
547
  if (!options) {
535
548
  return void 0;
@@ -537,7 +550,7 @@ var TableSorting = class {
537
550
  const option = options.find((option2) => option2.id === value);
538
551
  return option ? options.indexOf(option) : void 0;
539
552
  }
540
- if (format === FormatEnum.Ref && field.referencePath) {
553
+ if (format === Format.TypeFormat.Ref && field.referencePath) {
541
554
  const refValue = getValue(value.target, field.referencePath);
542
555
  return refValue;
543
556
  }
@@ -547,51 +560,9 @@ var TableSorting = class {
547
560
  value
548
561
  });
549
562
  }
550
- constructor(rows, _view, _projection) {
551
- _define_property2(this, "_view", void 0);
552
- _define_property2(this, "_projection", void 0);
553
- _define_property2(this, "_displayToDataIndex", void 0);
554
- _define_property2(this, "_rows", void 0);
555
- _define_property2(this, "_localSort", void 0);
556
- _define_property2(this, "_isDirty", void 0);
557
- _define_property2(this, "sortedRows", void 0);
558
- this._view = _view;
559
- this._projection = _projection;
560
- this._displayToDataIndex = /* @__PURE__ */ new Map();
561
- this._localSort = signal2(void 0);
562
- this._rows = rows;
563
- this._isDirty = computed2(() => {
564
- const local = this._localSort.value;
565
- const viewSort = this._view.sort?.[0];
566
- if (local?.type === "cleared") {
567
- return viewSort !== void 0;
568
- }
569
- if (local?.type === "active") {
570
- if (!viewSort) {
571
- return true;
572
- }
573
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
574
- }
575
- return false;
576
- });
577
- this.sortedRows = this.initialiseSortedRows();
578
- }
579
563
  };
580
564
 
581
565
  // src/model/table-model.ts
582
- function _define_property3(obj, key, value) {
583
- if (key in obj) {
584
- Object.defineProperty(obj, key, {
585
- value,
586
- enumerable: true,
587
- configurable: true,
588
- writable: true
589
- });
590
- } else {
591
- obj[key] = value;
592
- }
593
- return obj;
594
- }
595
566
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
596
567
  var defaultFeatures = {
597
568
  selection: {
@@ -602,23 +573,90 @@ var defaultFeatures = {
602
573
  schemaEditable: false
603
574
  };
604
575
  var TableModel = class extends Resource2 {
576
+ _object;
577
+ _projection;
578
+ _visibleRange = signal3({
579
+ start: {
580
+ row: 0,
581
+ col: 0
582
+ },
583
+ end: {
584
+ row: 0,
585
+ col: 0
586
+ }
587
+ });
588
+ _onInsertRow;
589
+ _onDeleteRows;
590
+ _onDeleteColumn;
591
+ _onCellUpdate;
592
+ _onRowOrderChange;
593
+ _onRowAction;
594
+ _rowActions;
595
+ _features;
596
+ _rows = signal3([]);
597
+ _draftRows = signal3([]);
598
+ _sorting;
599
+ _pinnedRows;
600
+ _selection;
601
+ _columnMeta;
602
+ constructor({ object, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
603
+ top: [],
604
+ bottom: []
605
+ }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
606
+ super();
607
+ this._object = object;
608
+ this._projection = projection;
609
+ this._projection.normalizeView();
610
+ this._features = {
611
+ ...defaultFeatures,
612
+ ...features
613
+ };
614
+ invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
615
+ F: __dxlog_file,
616
+ L: 137,
617
+ S: this,
618
+ A: [
619
+ "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
620
+ "'Single selection is not compatible with editable tables.'"
621
+ ]
622
+ });
623
+ this._sorting = new TableSorting({
624
+ rows: this._rows,
625
+ getView: () => this.view,
626
+ projection: this._projection
627
+ });
628
+ if (sorting.length > 0) {
629
+ const [sort] = sorting;
630
+ this._sorting.setSort(sort.fieldId, sort.direction);
631
+ }
632
+ this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
633
+ this._pinnedRows = pinnedRows;
634
+ this._rowActions = rowActions;
635
+ this._onInsertRow = onInsertRow;
636
+ this._onDeleteRows = onDeleteRows;
637
+ this._onDeleteColumn = onDeleteColumn;
638
+ this._onCellUpdate = onCellUpdate;
639
+ this._onRowOrderChange = onRowOrderChange;
640
+ this._onRowAction = onRowAction;
641
+ }
605
642
  get id() {
606
- return fullyQualifiedId(this._view);
643
+ return Obj2.getDXN(this._object).toString();
607
644
  }
608
645
  get view() {
609
- return this._view;
610
- }
611
- get table() {
612
- invariant(this._table, "Model not initialized", {
646
+ const view = this._object.view.target;
647
+ invariant(view, "Table model not initialized", {
613
648
  F: __dxlog_file,
614
- L: 187,
649
+ L: 176,
615
650
  S: this,
616
651
  A: [
617
- "this._table",
618
- "'Model not initialized'"
652
+ "view",
653
+ "'Table model not initialized'"
619
654
  ]
620
655
  });
621
- return this._table;
656
+ return view;
657
+ }
658
+ get table() {
659
+ return this._object;
622
660
  }
623
661
  get projection() {
624
662
  return this._projection;
@@ -650,7 +688,7 @@ var TableModel = class extends Resource2 {
650
688
  get columnMeta() {
651
689
  invariant(this._columnMeta, void 0, {
652
690
  F: __dxlog_file,
653
- L: 226,
691
+ L: 219,
654
692
  S: this,
655
693
  A: [
656
694
  "this._columnMeta",
@@ -673,17 +711,7 @@ var TableModel = class extends Resource2 {
673
711
  // Initialisation
674
712
  //
675
713
  async _open() {
676
- const presentation = this._view.presentation.target ?? await this._view.presentation.load();
677
- invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
678
- F: __dxlog_file,
679
- L: 249,
680
- S: this,
681
- A: [
682
- "Obj.instanceOf(Table.Table, presentation)",
683
- ""
684
- ]
685
- });
686
- this._table = presentation;
714
+ await this._object.view.load();
687
715
  this.initializeColumnMeta();
688
716
  this.initializeEffects();
689
717
  await this._selection.open(this._ctx);
@@ -744,6 +772,17 @@ var TableModel = class extends Resource2 {
744
772
  });
745
773
  this._ctx.onDispose(draftRowsWatcher);
746
774
  }
775
+ //
776
+ // Data
777
+ //
778
+ setRows = (obj) => {
779
+ this._rows.value = obj;
780
+ };
781
+ getRowCount = () => this._rows.value.length;
782
+ /**
783
+ * @reactive
784
+ */
785
+ getDraftRowCount = () => this._draftRows.value.length;
747
786
  // TODO(ZaymonFC): Return .value instead of exposing the signal.
748
787
  get draftRows() {
749
788
  return this._draftRows;
@@ -762,6 +801,14 @@ var TableModel = class extends Resource2 {
762
801
  const validationErrors = draftRow.validationErrors || [];
763
802
  return validationErrors.some((error) => error.path === fieldPath);
764
803
  }
804
+ getColumnCount = () => this._projection?.fields.length ?? 0;
805
+ insertRow = () => {
806
+ const result = this._onInsertRow?.();
807
+ if (result === "draft" && this._draftRows.value.length === 0) {
808
+ this.createDraftRow();
809
+ }
810
+ return result ?? "final";
811
+ };
765
812
  createDraftRow() {
766
813
  if (!this._projection) {
767
814
  return;
@@ -801,6 +848,187 @@ var TableModel = class extends Resource2 {
801
848
  const schema = toEffectSchema(this._projection.baseSchema);
802
849
  return validateSchema(schema, data) || [];
803
850
  }
851
+ commitDraftRow = (draftRowIndex) => {
852
+ if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
853
+ return false;
854
+ }
855
+ const draftRow = this._draftRows.value[draftRowIndex];
856
+ if (!draftRow.valid) {
857
+ return false;
858
+ }
859
+ const insertRowResult = this._onInsertRow?.(draftRow.data);
860
+ if (insertRowResult === "final") {
861
+ const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
862
+ this._draftRows.value = newDraftRows;
863
+ }
864
+ return insertRowResult === "final";
865
+ };
866
+ deleteRow = (rowIndex) => {
867
+ const row = this._sorting.getDataIndex(rowIndex);
868
+ const obj = this._rows.value[row];
869
+ const objectsToDelete = [];
870
+ if (this.features.selection.enabled && this._selection.hasSelection.value) {
871
+ const selectedRows = this._selection.getSelectedRows();
872
+ objectsToDelete.push(...selectedRows);
873
+ } else {
874
+ objectsToDelete.push(obj);
875
+ }
876
+ this._onDeleteRows?.(row, objectsToDelete);
877
+ };
878
+ handleRowAction = (actionId, rowIndex) => {
879
+ if (!this._onRowAction) {
880
+ return;
881
+ }
882
+ const row = this._sorting.getDataIndex(rowIndex);
883
+ const data = this._rows.value[row];
884
+ if (data) {
885
+ this._onRowAction(actionId, data);
886
+ }
887
+ };
888
+ getCellData = (cell) => {
889
+ const { col, row, plane } = cell;
890
+ const fields = this._projection?.fields ?? [];
891
+ if (col < 0 || col >= fields.length) {
892
+ return void 0;
893
+ }
894
+ const field = fields[col];
895
+ let value;
896
+ if (plane === "frozenRowsEnd") {
897
+ if (row >= 0 && row < this._draftRows.value.length) {
898
+ value = getValue2(this._draftRows.value[row].data, field.path);
899
+ } else {
900
+ return void 0;
901
+ }
902
+ } else {
903
+ const dataIndex = this._sorting.getDataIndex(row);
904
+ value = getValue2(this._rows.value[dataIndex], field.path);
905
+ }
906
+ if (value == null) {
907
+ return "";
908
+ }
909
+ const { props } = this._projection.getFieldProjection(field.id);
910
+ switch (props.format) {
911
+ case Format2.TypeFormat.Ref: {
912
+ if (!field.referencePath) {
913
+ return "";
914
+ }
915
+ return getValue2(value.target, field.referencePath);
916
+ }
917
+ default: {
918
+ return formatForEditing({
919
+ type: props.type,
920
+ format: props.format,
921
+ value
922
+ });
923
+ }
924
+ }
925
+ };
926
+ validateCellData = async ({ col, row, plane }, value) => {
927
+ const fields = this._projection?.fields ?? [];
928
+ if (col < 0 || col >= fields.length) {
929
+ return {
930
+ valid: false,
931
+ error: "Invalid column index"
932
+ };
933
+ }
934
+ const field = fields[col];
935
+ const { props } = this._projection.getFieldProjection(field.id);
936
+ const transformedValue = editorTextToCellValue(props, value);
937
+ const isDraftRow = plane === "frozenRowsEnd";
938
+ if (isDraftRow) {
939
+ const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
940
+ if (isInvalidDraftRowIndex) {
941
+ return {
942
+ valid: false,
943
+ error: "Invalid draft row index"
944
+ };
945
+ }
946
+ const draftRow = this._draftRows.value[row];
947
+ const snapshot = {
948
+ ...draftRow.data
949
+ };
950
+ setValue(snapshot, field.path, transformedValue);
951
+ const validationErrors = this.validateDraftRowData(snapshot);
952
+ if (validationErrors.length > 0) {
953
+ const error = validationErrors.find((err) => err.path === field.path);
954
+ if (error) {
955
+ return {
956
+ valid: false,
957
+ error: error.message
958
+ };
959
+ }
960
+ }
961
+ return {
962
+ valid: true
963
+ };
964
+ } else {
965
+ const rowIdx = this._sorting.getDataIndex(row);
966
+ const currentRow = this._rows.value[rowIdx];
967
+ invariant(currentRow, "Invalid row index", {
968
+ F: __dxlog_file,
969
+ L: 516,
970
+ S: this,
971
+ A: [
972
+ "currentRow",
973
+ "'Invalid row index'"
974
+ ]
975
+ });
976
+ const snapshot = getSnapshot(currentRow);
977
+ setValue(snapshot, field.path, transformedValue);
978
+ const schema = Obj2.getSchema(currentRow);
979
+ invariant(schema, void 0, {
980
+ F: __dxlog_file,
981
+ L: 522,
982
+ S: this,
983
+ A: [
984
+ "schema",
985
+ ""
986
+ ]
987
+ });
988
+ const validationResult = validateSchema(schema, snapshot);
989
+ if (validationResult && validationResult.length > 0) {
990
+ const error = validationResult[0];
991
+ invariant(error.path === field.path, void 0, {
992
+ F: __dxlog_file,
993
+ L: 527,
994
+ S: this,
995
+ A: [
996
+ "error.path === field.path",
997
+ ""
998
+ ]
999
+ });
1000
+ return {
1001
+ valid: false,
1002
+ error: error.message
1003
+ };
1004
+ }
1005
+ return {
1006
+ valid: true
1007
+ };
1008
+ }
1009
+ };
1010
+ setCellData = (cell, value) => {
1011
+ const { col, row, plane } = cell;
1012
+ const fields = this._projection?.fields ?? [];
1013
+ if (col < 0 || col >= fields.length) {
1014
+ return;
1015
+ }
1016
+ const field = fields[col];
1017
+ const { props } = this._projection.getFieldProjection(field.id);
1018
+ const transformedValue = editorTextToCellValue(props, value);
1019
+ if (props.format === Format2.TypeFormat.Ref && !isLiveObject(value)) {
1020
+ return;
1021
+ }
1022
+ if (plane === "frozenRowsEnd") {
1023
+ if (row >= 0 && row < this._draftRows.value.length) {
1024
+ setValue(this._draftRows.value[row].data, field.path, transformedValue);
1025
+ this.validateDraftRow(row);
1026
+ }
1027
+ } else {
1028
+ const rowIdx = this._sorting.getDataIndex(row);
1029
+ setValue(this._rows.value[rowIdx], field.path, transformedValue);
1030
+ }
1031
+ };
804
1032
  /**
805
1033
  * Updates a cell's value using a transform function.
806
1034
  * @param {DxGridPlanePosition} position - The position of the cell to update.
@@ -881,251 +1109,17 @@ var TableModel = class extends Resource2 {
881
1109
  saveView() {
882
1110
  this._sorting.save();
883
1111
  }
884
- constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
885
- top: [],
886
- bottom: []
887
- }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
888
- super(), _define_property3(this, "_view", void 0), _define_property3(this, "_projection", void 0), _define_property3(this, "_table", void 0), _define_property3(this, "_visibleRange", signal3({
889
- start: {
890
- row: 0,
891
- col: 0
892
- },
893
- end: {
894
- row: 0,
895
- col: 0
896
- }
897
- })), _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), //
898
- // Data
899
- //
900
- _define_property3(this, "setRows", (obj) => {
901
- this._rows.value = obj;
902
- }), _define_property3(this, "getRowCount", () => this._rows.value.length), /**
903
- * @reactive
904
- */
905
- _define_property3(this, "getDraftRowCount", () => this._draftRows.value.length), _define_property3(this, "getColumnCount", () => this._projection?.fields.length ?? 0), _define_property3(this, "insertRow", () => {
906
- const result = this._onInsertRow?.();
907
- if (result === "draft" && this._draftRows.value.length === 0) {
908
- this.createDraftRow();
909
- }
910
- return result ?? "final";
911
- }), _define_property3(this, "commitDraftRow", (draftRowIndex) => {
912
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
913
- return false;
914
- }
915
- const draftRow = this._draftRows.value[draftRowIndex];
916
- if (!draftRow.valid) {
917
- return false;
918
- }
919
- const insertRowResult = this._onInsertRow?.(draftRow.data);
920
- if (insertRowResult === "final") {
921
- const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
922
- this._draftRows.value = newDraftRows;
923
- }
924
- return insertRowResult === "final";
925
- }), _define_property3(this, "deleteRow", (rowIndex) => {
926
- const row = this._sorting.getDataIndex(rowIndex);
927
- const obj = this._rows.value[row];
928
- const objectsToDelete = [];
929
- if (this.features.selection.enabled && this._selection.hasSelection.value) {
930
- const selectedRows = this._selection.getSelectedRows();
931
- objectsToDelete.push(...selectedRows);
932
- } else {
933
- objectsToDelete.push(obj);
934
- }
935
- this._onDeleteRows?.(row, objectsToDelete);
936
- }), _define_property3(this, "handleRowAction", (actionId, rowIndex) => {
937
- if (!this._onRowAction) {
938
- return;
939
- }
940
- const row = this._sorting.getDataIndex(rowIndex);
941
- const data = this._rows.value[row];
942
- if (data) {
943
- this._onRowAction(actionId, data);
944
- }
945
- }), _define_property3(this, "getCellData", (cell) => {
946
- const { col, row, plane } = cell;
947
- const fields = this._projection?.fields ?? [];
948
- if (col < 0 || col >= fields.length) {
949
- return void 0;
950
- }
951
- const field = fields[col];
952
- let value;
953
- if (plane === "frozenRowsEnd") {
954
- if (row >= 0 && row < this._draftRows.value.length) {
955
- value = getValue2(this._draftRows.value[row].data, field.path);
956
- } else {
957
- return void 0;
958
- }
959
- } else {
960
- const dataIndex = this._sorting.getDataIndex(row);
961
- value = getValue2(this._rows.value[dataIndex], field.path);
962
- }
963
- if (value == null) {
964
- return "";
965
- }
966
- const { props } = this._projection.getFieldProjection(field.id);
967
- switch (props.format) {
968
- case FormatEnum2.Ref: {
969
- if (!field.referencePath) {
970
- return "";
971
- }
972
- return getValue2(value.target, field.referencePath);
973
- }
974
- default: {
975
- return formatForEditing({
976
- type: props.type,
977
- format: props.format,
978
- value
979
- });
980
- }
981
- }
982
- }), _define_property3(this, "validateCellData", async ({ col, row, plane }, value) => {
983
- const fields = this._projection?.fields ?? [];
984
- if (col < 0 || col >= fields.length) {
985
- return {
986
- valid: false,
987
- error: "Invalid column index"
988
- };
989
- }
990
- const field = fields[col];
991
- const { props } = this._projection.getFieldProjection(field.id);
992
- const transformedValue = editorTextToCellValue(props, value);
993
- const isDraftRow = plane === "frozenRowsEnd";
994
- if (isDraftRow) {
995
- const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
996
- if (isInvalidDraftRowIndex) {
997
- return {
998
- valid: false,
999
- error: "Invalid draft row index"
1000
- };
1001
- }
1002
- const draftRow = this._draftRows.value[row];
1003
- const snapshot = {
1004
- ...draftRow.data
1005
- };
1006
- setValue(snapshot, field.path, transformedValue);
1007
- const validationErrors = this.validateDraftRowData(snapshot);
1008
- if (validationErrors.length > 0) {
1009
- const error = validationErrors.find((err) => err.path === field.path);
1010
- if (error) {
1011
- return {
1012
- valid: false,
1013
- error: error.message
1014
- };
1015
- }
1016
- }
1017
- return {
1018
- valid: true
1019
- };
1020
- } else {
1021
- const rowIdx = this._sorting.getDataIndex(row);
1022
- const currentRow = this._rows.value[rowIdx];
1023
- invariant(currentRow, "Invalid row index", {
1024
- F: __dxlog_file,
1025
- L: 522,
1026
- S: this,
1027
- A: [
1028
- "currentRow",
1029
- "'Invalid row index'"
1030
- ]
1031
- });
1032
- const snapshot = getSnapshot(currentRow);
1033
- setValue(snapshot, field.path, transformedValue);
1034
- const schema2 = getSchema(currentRow);
1035
- invariant(schema2, void 0, {
1036
- F: __dxlog_file,
1037
- L: 528,
1038
- S: this,
1039
- A: [
1040
- "schema",
1041
- ""
1042
- ]
1043
- });
1044
- const validationResult = validateSchema(schema2, snapshot);
1045
- if (validationResult && validationResult.length > 0) {
1046
- const error = validationResult[0];
1047
- invariant(error.path === field.path, void 0, {
1048
- F: __dxlog_file,
1049
- L: 533,
1050
- S: this,
1051
- A: [
1052
- "error.path === field.path",
1053
- ""
1054
- ]
1055
- });
1056
- return {
1057
- valid: false,
1058
- error: error.message
1059
- };
1060
- }
1061
- return {
1062
- valid: true
1063
- };
1064
- }
1065
- }), _define_property3(this, "setCellData", (cell, value) => {
1066
- const { col, row, plane } = cell;
1067
- const fields = this._projection?.fields ?? [];
1068
- if (col < 0 || col >= fields.length) {
1069
- return;
1070
- }
1071
- const field = fields[col];
1072
- const { props } = this._projection.getFieldProjection(field.id);
1073
- const transformedValue = editorTextToCellValue(props, value);
1074
- if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
1075
- return;
1076
- }
1077
- if (plane === "frozenRowsEnd") {
1078
- if (row >= 0 && row < this._draftRows.value.length) {
1079
- setValue(this._draftRows.value[row].data, field.path, transformedValue);
1080
- this.validateDraftRow(row);
1081
- }
1082
- } else {
1083
- const rowIdx = this._sorting.getDataIndex(row);
1084
- setValue(this._rows.value[rowIdx], field.path, transformedValue);
1085
- }
1086
- });
1087
- this._view = view;
1088
- this._projection = projection ?? new ProjectionModel2(schema, view.projection);
1089
- this._projection.normalizeView();
1090
- this._features = {
1091
- ...defaultFeatures,
1092
- ...features
1093
- };
1094
- invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1095
- F: __dxlog_file,
1096
- L: 149,
1097
- S: this,
1098
- A: [
1099
- "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1100
- "'Single selection is not compatible with editable tables.'"
1101
- ]
1102
- });
1103
- this._sorting = new TableSorting(this._rows, this._view, this._projection);
1104
- if (sorting.length > 0) {
1105
- const [sort] = sorting;
1106
- this._sorting.setSort(sort.fieldId, sort.direction);
1107
- }
1108
- this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
1109
- this._pinnedRows = pinnedRows;
1110
- this._rowActions = rowActions;
1111
- this._onInsertRow = onInsertRow;
1112
- this._onDeleteRows = onDeleteRows;
1113
- this._onDeleteColumn = onDeleteColumn;
1114
- this._onCellUpdate = onCellUpdate;
1115
- this._onRowOrderChange = onRowOrderChange;
1116
- this._onRowAction = onRowAction;
1117
- }
1118
1112
  };
1119
1113
  var editorTextToCellValue = (props, value) => {
1120
1114
  switch (props.format) {
1121
- case FormatEnum2.Ref: {
1115
+ case Format2.TypeFormat.Ref: {
1122
1116
  if (isLiveObject(value)) {
1123
- return Ref.make(value);
1117
+ return Ref2.make(value);
1124
1118
  } else {
1125
1119
  return value;
1126
1120
  }
1127
1121
  }
1128
- case FormatEnum2.SingleSelect: {
1122
+ case Format2.TypeFormat.SingleSelect: {
1129
1123
  const ids = extractTagIds(value);
1130
1124
  if (ids && ids.length > 0) {
1131
1125
  return ids[0];
@@ -1133,7 +1127,7 @@ var editorTextToCellValue = (props, value) => {
1133
1127
  return value;
1134
1128
  }
1135
1129
  }
1136
- case FormatEnum2.MultiSelect: {
1130
+ case Format2.TypeFormat.MultiSelect: {
1137
1131
  const ids = extractTagIds(value);
1138
1132
  return ids || value;
1139
1133
  }
@@ -1149,108 +1143,96 @@ var editorTextToCellValue = (props, value) => {
1149
1143
 
1150
1144
  // src/model/modal-controller.ts
1151
1145
  import { signal as signal4 } from "@preact/signals-core";
1152
- function _define_property4(obj, key, value) {
1153
- if (key in obj) {
1154
- Object.defineProperty(obj, key, {
1155
- value,
1156
- enumerable: true,
1157
- configurable: true,
1158
- writable: true
1159
- });
1160
- } else {
1161
- obj[key] = value;
1162
- }
1163
- return obj;
1164
- }
1165
1146
  var ModalController = class {
1147
+ _state = signal4({
1148
+ type: "closed"
1149
+ });
1150
+ _triggerRef = {
1151
+ current: null
1152
+ };
1166
1153
  get state() {
1167
1154
  return this._state;
1168
1155
  }
1169
1156
  get trigger() {
1170
1157
  return this._triggerRef;
1171
1158
  }
1172
- constructor() {
1173
- _define_property4(this, "_state", signal4({
1174
- type: "closed"
1175
- }));
1176
- _define_property4(this, "_triggerRef", {
1177
- current: null
1178
- });
1179
- _define_property4(this, "setTrigger", (trigger) => {
1180
- this._triggerRef.current = trigger;
1181
- });
1182
- _define_property4(this, "showRowMenu", (rowIndex) => {
1183
- this._state.value = {
1184
- type: "row",
1185
- rowIndex
1186
- };
1187
- });
1188
- _define_property4(this, "showColumnMenu", (fieldId) => {
1189
- this._state.value = {
1190
- type: "column",
1191
- fieldId
1192
- };
1193
- });
1194
- _define_property4(this, "showColumnCreator", () => {
1195
- this._state.value = {
1196
- type: "columnSettings",
1197
- mode: {
1198
- type: "create"
1199
- }
1200
- };
1201
- });
1202
- _define_property4(this, "showReferencePanel", (targetId, schemaId) => {
1203
- this._state.value = {
1204
- type: "refPanel",
1205
- targetId,
1206
- typename: schemaId
1207
- };
1208
- });
1209
- _define_property4(this, "openColumnSettings", () => {
1210
- if (this._state.value.type === "column") {
1211
- const fieldId = this._state.value.fieldId;
1212
- requestAnimationFrame(() => {
1213
- this._state.value = {
1214
- type: "columnSettings",
1215
- mode: {
1216
- type: "edit",
1217
- fieldId
1218
- }
1219
- };
1220
- });
1159
+ setTrigger = (trigger) => {
1160
+ this._triggerRef.current = trigger;
1161
+ };
1162
+ showRowMenu = (rowIndex) => {
1163
+ this._state.value = {
1164
+ type: "row",
1165
+ rowIndex
1166
+ };
1167
+ };
1168
+ showColumnMenu = (fieldId) => {
1169
+ this._state.value = {
1170
+ type: "column",
1171
+ fieldId
1172
+ };
1173
+ };
1174
+ showColumnCreator = () => {
1175
+ this._state.value = {
1176
+ type: "columnSettings",
1177
+ mode: {
1178
+ type: "create"
1221
1179
  }
1222
- });
1223
- _define_property4(this, "close", () => {
1224
- this._state.value = {
1225
- type: "closed"
1226
- };
1227
- });
1228
- }
1180
+ };
1181
+ };
1182
+ showReferencePanel = (targetId, schemaId) => {
1183
+ this._state.value = {
1184
+ type: "refPanel",
1185
+ targetId,
1186
+ typename: schemaId
1187
+ };
1188
+ };
1189
+ openColumnSettings = () => {
1190
+ if (this._state.value.type === "column") {
1191
+ const fieldId = this._state.value.fieldId;
1192
+ requestAnimationFrame(() => {
1193
+ this._state.value = {
1194
+ type: "columnSettings",
1195
+ mode: {
1196
+ type: "edit",
1197
+ fieldId
1198
+ }
1199
+ };
1200
+ });
1201
+ }
1202
+ };
1203
+ close = () => {
1204
+ this._state.value = {
1205
+ type: "closed"
1206
+ };
1207
+ };
1229
1208
  };
1230
1209
 
1231
1210
  // src/model/table-presentation.ts
1232
1211
  import { signal as signal5 } from "@preact/signals-core";
1233
1212
  import * as Predicate from "effect/Predicate";
1234
1213
  import { Obj as Obj3 } from "@dxos/echo";
1235
- import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1214
+ import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1236
1215
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1237
1216
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1238
1217
  import { mx } from "@dxos/react-ui-theme";
1239
1218
  import { VIEW_FIELD_LIMIT } from "@dxos/schema";
1240
- function _define_property5(obj, key, value) {
1241
- if (key in obj) {
1242
- Object.defineProperty(obj, key, {
1243
- value,
1244
- enumerable: true,
1245
- configurable: true,
1246
- writable: true
1247
- });
1248
- } else {
1249
- obj[key] = value;
1250
- }
1251
- return obj;
1252
- }
1253
1219
  var TablePresentation = class {
1220
+ model;
1221
+ _visibleRange;
1222
+ fieldProjectionCache = /* @__PURE__ */ new Map();
1223
+ constructor(model, _visibleRange = signal5({
1224
+ start: {
1225
+ row: 0,
1226
+ col: 0
1227
+ },
1228
+ end: {
1229
+ row: 0,
1230
+ col: 0
1231
+ }
1232
+ })) {
1233
+ this.model = model;
1234
+ this._visibleRange = _visibleRange;
1235
+ }
1254
1236
  getCells(range, plane) {
1255
1237
  this.fieldProjectionCache.clear();
1256
1238
  let cells;
@@ -1316,12 +1298,12 @@ var TablePresentation = class {
1316
1298
  return "";
1317
1299
  }
1318
1300
  switch (props.format) {
1319
- case FormatEnum3.Boolean:
1320
- case FormatEnum3.SingleSelect:
1321
- case FormatEnum3.MultiSelect: {
1301
+ case Format3.TypeFormat.Boolean:
1302
+ case Format3.TypeFormat.SingleSelect:
1303
+ case Format3.TypeFormat.MultiSelect: {
1322
1304
  return "";
1323
1305
  }
1324
- case FormatEnum3.Ref: {
1306
+ case Format3.TypeFormat.Ref: {
1325
1307
  if (!field.referencePath) {
1326
1308
  return "";
1327
1309
  }
@@ -1374,14 +1356,14 @@ var TablePresentation = class {
1374
1356
  cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1375
1357
  }
1376
1358
  }
1377
- if (props.format === FormatEnum3.Ref && props.referenceSchema) {
1359
+ if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
1378
1360
  const targetObj = getValue3(obj, field.path)?.target;
1379
1361
  if (targetObj) {
1380
1362
  const dxn = Obj3.getDXN(targetObj)?.toString();
1381
1363
  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>`;
1382
1364
  }
1383
1365
  }
1384
- if (props.format === FormatEnum3.Boolean) {
1366
+ if (props.format === Format3.TypeFormat.Boolean) {
1385
1367
  const value = getValue3(obj, field.path);
1386
1368
  cell.accessoryHtml = tableControls.switch.render({
1387
1369
  colIndex,
@@ -1390,7 +1372,7 @@ var TablePresentation = class {
1390
1372
  });
1391
1373
  cell.readonly = "no-text-select";
1392
1374
  }
1393
- if (props.format === FormatEnum3.SingleSelect) {
1375
+ if (props.format === Format3.TypeFormat.SingleSelect) {
1394
1376
  const value = getValue3(obj, field.path);
1395
1377
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1396
1378
  if (options) {
@@ -1400,7 +1382,7 @@ var TablePresentation = class {
1400
1382
  }
1401
1383
  }
1402
1384
  }
1403
- if (props.format === FormatEnum3.MultiSelect) {
1385
+ if (props.format === Format3.TypeFormat.MultiSelect) {
1404
1386
  const values = getValue3(obj, field.path);
1405
1387
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1406
1388
  if (options && values && values.length > 0) {
@@ -1636,23 +1618,6 @@ var TablePresentation = class {
1636
1618
  }
1637
1619
  return cells;
1638
1620
  }
1639
- constructor(model, _visibleRange = signal5({
1640
- start: {
1641
- row: 0,
1642
- col: 0
1643
- },
1644
- end: {
1645
- row: 0,
1646
- col: 0
1647
- }
1648
- })) {
1649
- _define_property5(this, "model", void 0);
1650
- _define_property5(this, "_visibleRange", void 0);
1651
- _define_property5(this, "fieldProjectionCache", void 0);
1652
- this.model = model;
1653
- this._visibleRange = _visibleRange;
1654
- this.fieldProjectionCache = /* @__PURE__ */ new Map();
1655
- }
1656
1621
  };
1657
1622
  var cellClassesForRowSelection = (selected, selectionMode) => {
1658
1623
  if (!selected) {
@@ -1676,31 +1641,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1676
1641
  }
1677
1642
  };
1678
1643
 
1644
+ // src/hooks/useAddRow.ts
1645
+ import { useCallback } from "react";
1646
+ import { Obj as Obj4 } from "@dxos/echo";
1647
+ var useAddRow = ({ space, schema }) => {
1648
+ return useCallback((data) => {
1649
+ if (space && schema) {
1650
+ try {
1651
+ space.db.add(Obj4.make(schema, data ?? {}));
1652
+ return "final";
1653
+ } catch (error) {
1654
+ return "draft";
1655
+ }
1656
+ }
1657
+ return "final";
1658
+ }, [
1659
+ space,
1660
+ schema
1661
+ ]);
1662
+ };
1663
+
1664
+ // src/hooks/useProjectionModel.ts
1665
+ import { useMemo } from "react";
1666
+ import { Type as Type2 } from "@dxos/echo";
1667
+ import { ProjectionModel as ProjectionModel2 } from "@dxos/schema";
1668
+ var useProjectionModel = (schema, table) => useMemo(() => {
1669
+ if (schema && table?.view.target?.projection) {
1670
+ const projection = new ProjectionModel2(Type2.toJsonSchema(schema), table.view.target.projection);
1671
+ projection.normalizeView();
1672
+ return projection;
1673
+ }
1674
+ }, [
1675
+ schema,
1676
+ table?.view.target?.projection
1677
+ ]);
1678
+
1679
1679
  // src/hooks/useTableModel.ts
1680
1680
  import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
1681
1681
  import { effect as effect3 } from "@preact/signals-core";
1682
1682
  import orderBy2 from "lodash.orderby";
1683
- import { useEffect, useMemo, useState } from "react";
1684
- import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
1683
+ import { useEffect, useMemo as useMemo2, useState } from "react";
1684
+ import { Obj as Obj5 } from "@dxos/echo";
1685
1685
  import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
1686
1686
  import { isNonNullable } from "@dxos/util";
1687
- var useTableModel = ({ view, schema, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1687
+ var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1688
1688
  var _effect = _useSignals();
1689
1689
  try {
1690
- const selected = useSelected(view && fullyQualifiedId2(view), "multi");
1691
- const initialSelection = useMemo(() => selected, [
1692
- view
1690
+ const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
1691
+ const initialSelection = useMemo2(() => selected, [
1692
+ object
1693
1693
  ]);
1694
1694
  const [model, setModel] = useState();
1695
1695
  useEffect(() => {
1696
- if (!view || !schema) {
1696
+ if (!object || !projection) {
1697
1697
  return;
1698
1698
  }
1699
1699
  let model2;
1700
1700
  const t = setTimeout(async () => {
1701
1701
  model2 = new TableModel({
1702
- view,
1703
- schema,
1702
+ object,
1704
1703
  projection,
1705
1704
  features,
1706
1705
  rowActions,
@@ -1716,8 +1715,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1716
1715
  void model2?.close();
1717
1716
  };
1718
1717
  }, [
1719
- view,
1720
- schema,
1718
+ object,
1721
1719
  projection,
1722
1720
  features,
1723
1721
  rowActions,
@@ -1764,26 +1762,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1764
1762
  }
1765
1763
  };
1766
1764
 
1767
- // src/hooks/useAddRow.ts
1768
- import { useCallback } from "react";
1769
- import { Obj as Obj4 } from "@dxos/echo";
1770
- var useAddRow = ({ space, schema }) => {
1771
- return useCallback((data) => {
1772
- if (space && schema) {
1773
- try {
1774
- space.db.add(Obj4.make(schema, data ?? {}));
1775
- return "final";
1776
- } catch (error) {
1777
- return "draft";
1778
- }
1779
- }
1780
- return "final";
1781
- }, [
1782
- space,
1783
- schema
1784
- ]);
1785
- };
1786
-
1787
1765
  export {
1788
1766
  getBaseSchema,
1789
1767
  makeDynamicTable,
@@ -1799,7 +1777,8 @@ export {
1799
1777
  ModalController,
1800
1778
  TablePresentation,
1801
1779
  cellClassesForRowSelection,
1802
- useTableModel,
1803
- useAddRow
1780
+ useAddRow,
1781
+ useProjectionModel,
1782
+ useTableModel
1804
1783
  };
1805
- //# sourceMappingURL=chunk-S56Z4V4X.mjs.map
1784
+ //# sourceMappingURL=chunk-CWSGS3Y2.mjs.map