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