@dxos/react-ui-table 0.8.4-main.5ea62a8 → 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 (115) 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-RQYXNWWN.mjs → chunk-KNC7XYT6.mjs} +529 -568
  4. package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +187 -322
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +15 -25
  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-QNDUGIS7.mjs → chunk-CWSGS3Y2.mjs} +529 -568
  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 +187 -322
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +15 -25
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/types/index.mjs +3 -3
  21. package/dist/types/src/components/Table/DynamicTable.d.ts +2 -2
  22. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +5 -5
  24. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/Relations.stories.d.ts +73 -9
  26. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  28. package/dist/types/src/components/Table/Table.d.ts +5 -2
  29. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  30. package/dist/types/src/components/Table/Table.stories.d.ts +72 -10
  31. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  32. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -5
  33. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  34. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -3
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +3 -4
  37. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  38. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  39. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  40. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
  41. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  42. package/dist/types/src/components/testing.d.ts +3 -5
  43. package/dist/types/src/components/testing.d.ts.map +1 -1
  44. package/dist/types/src/hooks/index.d.ts +2 -1
  45. package/dist/types/src/hooks/index.d.ts.map +1 -1
  46. package/dist/types/src/hooks/useAddRow.d.ts +1 -1
  47. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  48. package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
  49. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  50. package/dist/types/src/hooks/useTableModel.d.ts +4 -5
  51. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  52. package/dist/types/src/model/modal-controller.d.ts +0 -7
  53. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  54. package/dist/types/src/model/table-model.d.ts +8 -10
  55. package/dist/types/src/model/table-model.d.ts.map +1 -1
  56. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  57. package/dist/types/src/model/table-sorting.d.ts +8 -5
  58. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  59. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  60. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  61. package/dist/types/src/testing/useTestTableModel.d.ts +21 -29
  62. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  63. package/dist/types/src/translations.d.ts +2 -2
  64. package/dist/types/src/types/Table.d.ts +28 -0
  65. package/dist/types/src/types/Table.d.ts.map +1 -0
  66. package/dist/types/src/types/index.d.ts +1 -1
  67. package/dist/types/src/types/index.d.ts.map +1 -1
  68. package/dist/types/src/util/dynamic-table.d.ts +9 -9
  69. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  70. package/dist/types/src/util/schema.d.ts +1 -1
  71. package/dist/types/src/util/schema.d.ts.map +1 -1
  72. package/dist/types/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +53 -52
  74. package/src/components/Table/DynamicTable.stories.tsx +14 -13
  75. package/src/components/Table/DynamicTable.tsx +15 -10
  76. package/src/components/Table/Relations.stories.tsx +133 -29
  77. package/src/components/Table/RowActionsMenu.tsx +21 -13
  78. package/src/components/Table/Table.stories.tsx +85 -79
  79. package/src/components/Table/Table.tsx +13 -9
  80. package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
  81. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +21 -47
  82. package/src/components/TableCellEditor/TableCellEditor.tsx +20 -115
  83. package/src/components/TableCellEditor/index.ts +1 -0
  84. package/src/components/TableToolbar/TableToolbar.tsx +32 -22
  85. package/src/components/testing.ts +4 -4
  86. package/src/hooks/index.ts +2 -1
  87. package/src/hooks/useAddRow.ts +1 -1
  88. package/src/hooks/useProjectionModel.ts +19 -0
  89. package/src/hooks/useTableModel.ts +11 -13
  90. package/src/model/modal-controller.ts +0 -28
  91. package/src/model/table-model.test.ts +19 -9
  92. package/src/model/table-model.ts +42 -41
  93. package/src/model/table-presentation.test.ts +22 -20
  94. package/src/model/table-presentation.ts +12 -13
  95. package/src/model/table-sorting.ts +31 -13
  96. package/src/playwright/TableManager.ts +3 -3
  97. package/src/playwright/smoke.spec.ts +8 -6
  98. package/src/testing/useTestTableModel.ts +33 -22
  99. package/src/translations.ts +2 -2
  100. package/src/types/Table.ts +89 -0
  101. package/src/types/index.ts +1 -1
  102. package/src/util/dynamic-table.ts +17 -21
  103. package/src/util/schema.ts +4 -4
  104. package/dist/lib/browser/chunk-63UUF4IG.mjs +0 -66
  105. package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-RQYXNWWN.mjs.map +0 -7
  107. package/dist/lib/node-esm/chunk-K734DJB7.mjs +0 -67
  108. package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
  109. package/dist/lib/node-esm/chunk-QNDUGIS7.mjs.map +0 -7
  110. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  111. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  112. package/dist/types/src/types/schema.d.ts +0 -28
  113. package/dist/types/src/types/schema.d.ts.map +0 -1
  114. package/src/components/Table/CreateRefPanel.tsx +0 -103
  115. 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-K734DJB7.mjs";
3
+ Table_exports
4
+ } from "./chunk-MKTMOY46.mjs";
5
5
 
6
6
  // src/util/dynamic-table.ts
7
- import { Obj } from "@dxos/echo";
8
- import { getTypename, toJsonSchema } from "@dxos/echo-schema";
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 {
@@ -28,25 +27,26 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
28
27
  throw new Error("invalid properties");
29
28
  }
30
29
  };
31
- var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
32
- const table = Obj.make(schema_exports.Table, {
33
- sizes: {}
34
- });
35
- const view = createView({
36
- typename,
30
+ var makeDynamicTable = ({ jsonSchema, properties }) => {
31
+ const view = View.make({
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);
43
+ projection.normalizeView();
44
44
  if (properties && projection.fields) {
45
- setProperties(view, projection, table, properties);
45
+ setProperties(view, projection, object, properties);
46
46
  }
47
47
  return {
48
48
  projection,
49
- view
49
+ object
50
50
  };
51
51
  };
52
52
  var setProperties = (view, projection, table, properties) => {
@@ -68,7 +68,7 @@ var setProperties = (view, projection, table, properties) => {
68
68
  }
69
69
  if (property.sort) {
70
70
  const fieldId = field.id;
71
- view.query.sort = [
71
+ view.sort = [
72
72
  {
73
73
  fieldId,
74
74
  direction: property.sort
@@ -256,14 +256,14 @@ var tableControls = {
256
256
  };
257
257
 
258
258
  // src/util/schema.ts
259
- import { Schema } from "effect";
260
- import { TypeLiteral, isTypeLiteral } from "effect/SchemaAST";
259
+ import * as Schema from "effect/Schema";
260
+ import * as SchemaAST from "effect/SchemaAST";
261
261
  var narrowSchema = (schema, paths) => {
262
262
  const ast = schema?.ast;
263
- if (isTypeLiteral(ast)) {
263
+ if (SchemaAST.isTypeLiteral(ast)) {
264
264
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
265
265
  if (propertySignatures.length > 0) {
266
- const narrowType = new TypeLiteral(propertySignatures, []);
266
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
267
267
  return Schema.make(narrowType);
268
268
  }
269
269
  }
@@ -273,14 +273,13 @@ var narrowSchema = (schema, paths) => {
273
273
  // src/model/table-model.ts
274
274
  import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
275
275
  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-schema";
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";
278
278
  import { invariant } from "@dxos/invariant";
279
279
  import { ObjectId } from "@dxos/keys";
280
280
  import { getSnapshot, isLiveObject } from "@dxos/live-object";
281
- import { fullyQualifiedId } from "@dxos/react-client/echo";
282
281
  import { formatForEditing, parseValue } from "@dxos/react-ui-form";
283
- import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
282
+ import { validateSchema } from "@dxos/schema";
284
283
 
285
284
  // src/util/tag.ts
286
285
  var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
@@ -301,20 +300,34 @@ var extractTagIds = (value) => {
301
300
  // src/model/selection-model.ts
302
301
  import { computed, effect, signal } from "@preact/signals-core";
303
302
  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
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
+ }
318
331
  async _open() {
319
332
  const selectionWatcher = effect(() => {
320
333
  touch(this._selection.value);
@@ -337,80 +350,80 @@ var SelectionModel = class extends Resource {
337
350
  get selectionMode() {
338
351
  return this._selectionMode;
339
352
  }
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;
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();
357
375
  }
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);
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;
377
385
  }
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
- }
386
+ case "none": {
387
+ this._selection.value = /* @__PURE__ */ new Set();
388
+ break;
389
389
  }
390
- };
391
- this._selection = signal(new Set(this._initialSelection));
392
- }
390
+ }
391
+ };
393
392
  };
394
393
 
395
394
  // src/model/table-sorting.ts
396
395
  import { computed as computed2, signal as signal2 } from "@preact/signals-core";
397
396
  import orderBy from "lodash.orderby";
398
- import { FormatEnum, TypeEnum, getValue } from "@dxos/echo-schema";
397
+ import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
399
398
  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
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;
407
424
  });
408
- } else {
409
- obj[key] = value;
425
+ this.sortedRows = this.initialiseSortedRows();
410
426
  }
411
- return obj;
412
- }
413
- var TableSorting = class {
414
427
  /**
415
428
  * @reactive
416
429
  * @returns Local sort if present, falls back to view sort.
@@ -423,7 +436,7 @@ var TableSorting = class {
423
436
  if (local?.type === "active") {
424
437
  return local.sort;
425
438
  }
426
- return this._view.query.sort?.[0];
439
+ return this._getView().sort?.[0];
427
440
  }
428
441
  /**
429
442
  * @reactive
@@ -466,12 +479,13 @@ var TableSorting = class {
466
479
  }
467
480
  save() {
468
481
  if (this._localSort.value !== void 0) {
482
+ const view = this._getView();
469
483
  if (this._localSort.value.type === "active") {
470
- this._view.query.sort = [
484
+ view.sort = [
471
485
  this._localSort.value.sort
472
486
  ];
473
487
  } else {
474
- this._view.query.sort = [];
488
+ view.sort = [];
475
489
  }
476
490
  this._localSort.value = void 0;
477
491
  }
@@ -528,7 +542,7 @@ var TableSorting = class {
528
542
  if (value == null) {
529
543
  return value;
530
544
  }
531
- if (format === FormatEnum.SingleSelect) {
545
+ if (format === Format.TypeFormat.SingleSelect) {
532
546
  const options = props.options;
533
547
  if (!options) {
534
548
  return void 0;
@@ -536,7 +550,7 @@ var TableSorting = class {
536
550
  const option = options.find((option2) => option2.id === value);
537
551
  return option ? options.indexOf(option) : void 0;
538
552
  }
539
- if (format === FormatEnum.Ref && field.referencePath) {
553
+ if (format === Format.TypeFormat.Ref && field.referencePath) {
540
554
  const refValue = getValue(value.target, field.referencePath);
541
555
  return refValue;
542
556
  }
@@ -546,51 +560,9 @@ var TableSorting = class {
546
560
  value
547
561
  });
548
562
  }
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.query.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
563
  };
579
564
 
580
565
  // 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
566
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
595
567
  var defaultFeatures = {
596
568
  selection: {
@@ -601,23 +573,90 @@ var defaultFeatures = {
601
573
  schemaEditable: false
602
574
  };
603
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
+ }
604
642
  get id() {
605
- return fullyQualifiedId(this._view);
643
+ return Obj2.getDXN(this._object).toString();
606
644
  }
607
645
  get view() {
608
- return this._view;
609
- }
610
- get table() {
611
- invariant(this._table, "Model not initialized", {
646
+ const view = this._object.view.target;
647
+ invariant(view, "Table model not initialized", {
612
648
  F: __dxlog_file,
613
- L: 180,
649
+ L: 176,
614
650
  S: this,
615
651
  A: [
616
- "this._table",
617
- "'Model not initialized'"
652
+ "view",
653
+ "'Table model not initialized'"
618
654
  ]
619
655
  });
620
- return this._table;
656
+ return view;
657
+ }
658
+ get table() {
659
+ return this._object;
621
660
  }
622
661
  get projection() {
623
662
  return this._projection;
@@ -672,17 +711,7 @@ var TableModel = class extends Resource2 {
672
711
  // Initialisation
673
712
  //
674
713
  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: 242,
679
- S: this,
680
- A: [
681
- "Obj.instanceOf(Table.Table, presentation)",
682
- ""
683
- ]
684
- });
685
- this._table = presentation;
714
+ await this._object.view.load();
686
715
  this.initializeColumnMeta();
687
716
  this.initializeEffects();
688
717
  await this._selection.open(this._ctx);
@@ -743,6 +772,17 @@ var TableModel = class extends Resource2 {
743
772
  });
744
773
  this._ctx.onDispose(draftRowsWatcher);
745
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;
746
786
  // TODO(ZaymonFC): Return .value instead of exposing the signal.
747
787
  get draftRows() {
748
788
  return this._draftRows;
@@ -761,6 +801,14 @@ var TableModel = class extends Resource2 {
761
801
  const validationErrors = draftRow.validationErrors || [];
762
802
  return validationErrors.some((error) => error.path === fieldPath);
763
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
+ };
764
812
  createDraftRow() {
765
813
  if (!this._projection) {
766
814
  return;
@@ -800,6 +848,187 @@ var TableModel = class extends Resource2 {
800
848
  const schema = toEffectSchema(this._projection.baseSchema);
801
849
  return validateSchema(schema, data) || [];
802
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
+ };
803
1032
  /**
804
1033
  * Updates a cell's value using a transform function.
805
1034
  * @param {DxGridPlanePosition} position - The position of the cell to update.
@@ -880,250 +1109,17 @@ var TableModel = class extends Resource2 {
880
1109
  saveView() {
881
1110
  this._sorting.save();
882
1111
  }
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: 515,
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: 521,
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: 526,
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._features = {
1089
- ...defaultFeatures,
1090
- ...features
1091
- };
1092
- invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1093
- F: __dxlog_file,
1094
- L: 142,
1095
- S: this,
1096
- A: [
1097
- "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1098
- "'Single selection is not compatible with editable tables.'"
1099
- ]
1100
- });
1101
- this._sorting = new TableSorting(this._rows, this._view, this._projection);
1102
- if (sorting.length > 0) {
1103
- const [sort] = sorting;
1104
- this._sorting.setSort(sort.fieldId, sort.direction);
1105
- }
1106
- this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
1107
- this._pinnedRows = pinnedRows;
1108
- this._rowActions = rowActions;
1109
- this._onInsertRow = onInsertRow;
1110
- this._onDeleteRows = onDeleteRows;
1111
- this._onDeleteColumn = onDeleteColumn;
1112
- this._onCellUpdate = onCellUpdate;
1113
- this._onRowOrderChange = onRowOrderChange;
1114
- this._onRowAction = onRowAction;
1115
- }
1116
1112
  };
1117
1113
  var editorTextToCellValue = (props, value) => {
1118
1114
  switch (props.format) {
1119
- case FormatEnum2.Ref: {
1115
+ case Format2.TypeFormat.Ref: {
1120
1116
  if (isLiveObject(value)) {
1121
- return Ref.make(value);
1117
+ return Ref2.make(value);
1122
1118
  } else {
1123
1119
  return value;
1124
1120
  }
1125
1121
  }
1126
- case FormatEnum2.SingleSelect: {
1122
+ case Format2.TypeFormat.SingleSelect: {
1127
1123
  const ids = extractTagIds(value);
1128
1124
  if (ids && ids.length > 0) {
1129
1125
  return ids[0];
@@ -1131,7 +1127,7 @@ var editorTextToCellValue = (props, value) => {
1131
1127
  return value;
1132
1128
  }
1133
1129
  }
1134
- case FormatEnum2.MultiSelect: {
1130
+ case Format2.TypeFormat.MultiSelect: {
1135
1131
  const ids = extractTagIds(value);
1136
1132
  return ids || value;
1137
1133
  }
@@ -1147,128 +1143,96 @@ var editorTextToCellValue = (props, value) => {
1147
1143
 
1148
1144
  // src/model/modal-controller.ts
1149
1145
  import { signal as signal4 } from "@preact/signals-core";
1150
- import { log } from "@dxos/log";
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
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
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, "openCreateRef", (typename, anchorCell, initialValues, onCreate) => {
1224
- if (anchorCell) {
1225
- this._triggerRef.current = anchorCell;
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(() => {
1226
1193
  this._state.value = {
1227
- type: "createRefPanel",
1228
- typename,
1229
- initialValues,
1230
- onCreate
1194
+ type: "columnSettings",
1195
+ mode: {
1196
+ type: "edit",
1197
+ fieldId
1198
+ }
1231
1199
  };
1232
- } else {
1233
- log.warn("anchor cell not found while creating new ref", void 0, {
1234
- F: __dxlog_file2,
1235
- L: 86,
1236
- S: this,
1237
- C: (f, a) => f(...a)
1238
- });
1239
- }
1240
- });
1241
- _define_property4(this, "close", () => {
1242
- this._state.value = {
1243
- type: "closed"
1244
- };
1245
- });
1246
- }
1200
+ });
1201
+ }
1202
+ };
1203
+ close = () => {
1204
+ this._state.value = {
1205
+ type: "closed"
1206
+ };
1207
+ };
1247
1208
  };
1248
1209
 
1249
1210
  // src/model/table-presentation.ts
1250
1211
  import { signal as signal5 } from "@preact/signals-core";
1251
- import { isNotNullable } from "effect/Predicate";
1212
+ import * as Predicate from "effect/Predicate";
1252
1213
  import { Obj as Obj3 } from "@dxos/echo";
1253
- import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo-schema";
1214
+ import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1254
1215
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1255
1216
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1256
1217
  import { mx } from "@dxos/react-ui-theme";
1257
1218
  import { VIEW_FIELD_LIMIT } from "@dxos/schema";
1258
- function _define_property5(obj, key, value) {
1259
- if (key in obj) {
1260
- Object.defineProperty(obj, key, {
1261
- value,
1262
- enumerable: true,
1263
- configurable: true,
1264
- writable: true
1265
- });
1266
- } else {
1267
- obj[key] = value;
1268
- }
1269
- return obj;
1270
- }
1271
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
+ }
1272
1236
  getCells(range, plane) {
1273
1237
  this.fieldProjectionCache.clear();
1274
1238
  let cells;
@@ -1334,12 +1298,12 @@ var TablePresentation = class {
1334
1298
  return "";
1335
1299
  }
1336
1300
  switch (props.format) {
1337
- case FormatEnum3.Boolean:
1338
- case FormatEnum3.SingleSelect:
1339
- case FormatEnum3.MultiSelect: {
1301
+ case Format3.TypeFormat.Boolean:
1302
+ case Format3.TypeFormat.SingleSelect:
1303
+ case Format3.TypeFormat.MultiSelect: {
1340
1304
  return "";
1341
1305
  }
1342
- case FormatEnum3.Ref: {
1306
+ case Format3.TypeFormat.Ref: {
1343
1307
  if (!field.referencePath) {
1344
1308
  return "";
1345
1309
  }
@@ -1386,20 +1350,20 @@ var TablePresentation = class {
1386
1350
  }
1387
1351
  return "Object";
1388
1352
  };
1389
- const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
1353
+ const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
1390
1354
  return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
1391
1355
  }).join("");
1392
1356
  cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1393
1357
  }
1394
1358
  }
1395
- if (props.format === FormatEnum3.Ref && props.referenceSchema) {
1359
+ if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
1396
1360
  const targetObj = getValue3(obj, field.path)?.target;
1397
1361
  if (targetObj) {
1398
1362
  const dxn = Obj3.getDXN(targetObj)?.toString();
1399
- cell.accessoryHtml = `<dx-ref-tag refId=${dxn} class="dx-button is-6 pli-[3px] pbe-[2px] min-bs-0 absolute inline-end-2 block-start-[.2rem]" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
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>`;
1400
1364
  }
1401
1365
  }
1402
- if (props.format === FormatEnum3.Boolean) {
1366
+ if (props.format === Format3.TypeFormat.Boolean) {
1403
1367
  const value = getValue3(obj, field.path);
1404
1368
  cell.accessoryHtml = tableControls.switch.render({
1405
1369
  colIndex,
@@ -1408,7 +1372,7 @@ var TablePresentation = class {
1408
1372
  });
1409
1373
  cell.readonly = "no-text-select";
1410
1374
  }
1411
- if (props.format === FormatEnum3.SingleSelect) {
1375
+ if (props.format === Format3.TypeFormat.SingleSelect) {
1412
1376
  const value = getValue3(obj, field.path);
1413
1377
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1414
1378
  if (options) {
@@ -1418,7 +1382,7 @@ var TablePresentation = class {
1418
1382
  }
1419
1383
  }
1420
1384
  }
1421
- if (props.format === FormatEnum3.MultiSelect) {
1385
+ if (props.format === Format3.TypeFormat.MultiSelect) {
1422
1386
  const values = getValue3(obj, field.path);
1423
1387
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1424
1388
  if (options && values && values.length > 0) {
@@ -1654,23 +1618,6 @@ var TablePresentation = class {
1654
1618
  }
1655
1619
  return cells;
1656
1620
  }
1657
- constructor(model, _visibleRange = signal5({
1658
- start: {
1659
- row: 0,
1660
- col: 0
1661
- },
1662
- end: {
1663
- row: 0,
1664
- col: 0
1665
- }
1666
- })) {
1667
- _define_property5(this, "model", void 0);
1668
- _define_property5(this, "_visibleRange", void 0);
1669
- _define_property5(this, "fieldProjectionCache", void 0);
1670
- this.model = model;
1671
- this._visibleRange = _visibleRange;
1672
- this.fieldProjectionCache = /* @__PURE__ */ new Map();
1673
- }
1674
1621
  };
1675
1622
  var cellClassesForRowSelection = (selected, selectionMode) => {
1676
1623
  if (!selected) {
@@ -1694,31 +1641,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1694
1641
  }
1695
1642
  };
1696
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
+
1697
1679
  // src/hooks/useTableModel.ts
1698
1680
  import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
1699
1681
  import { effect as effect3 } from "@preact/signals-core";
1700
1682
  import orderBy2 from "lodash.orderby";
1701
- import { useEffect, useMemo, useState } from "react";
1702
- 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";
1703
1685
  import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
1704
1686
  import { isNonNullable } from "@dxos/util";
1705
- var useTableModel = ({ view, schema, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1687
+ var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1706
1688
  var _effect = _useSignals();
1707
1689
  try {
1708
- const selected = useSelected(view && fullyQualifiedId2(view), "multi");
1709
- const initialSelection = useMemo(() => selected, [
1710
- view
1690
+ const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
1691
+ const initialSelection = useMemo2(() => selected, [
1692
+ object
1711
1693
  ]);
1712
1694
  const [model, setModel] = useState();
1713
1695
  useEffect(() => {
1714
- if (!view || !schema) {
1696
+ if (!object || !projection) {
1715
1697
  return;
1716
1698
  }
1717
1699
  let model2;
1718
1700
  const t = setTimeout(async () => {
1719
1701
  model2 = new TableModel({
1720
- view,
1721
- schema,
1702
+ object,
1722
1703
  projection,
1723
1704
  features,
1724
1705
  rowActions,
@@ -1734,8 +1715,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1734
1715
  void model2?.close();
1735
1716
  };
1736
1717
  }, [
1737
- view,
1738
- schema,
1718
+ object,
1739
1719
  projection,
1740
1720
  features,
1741
1721
  rowActions,
@@ -1782,26 +1762,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1782
1762
  }
1783
1763
  };
1784
1764
 
1785
- // src/hooks/useAddRow.ts
1786
- import { useCallback } from "react";
1787
- import { Obj as Obj4 } from "@dxos/echo";
1788
- var useAddRow = ({ space, schema }) => {
1789
- return useCallback((data) => {
1790
- if (space && schema) {
1791
- try {
1792
- space.db.add(Obj4.make(schema, data ?? {}));
1793
- return "final";
1794
- } catch (error) {
1795
- return "draft";
1796
- }
1797
- }
1798
- return "final";
1799
- }, [
1800
- space,
1801
- schema
1802
- ]);
1803
- };
1804
-
1805
1765
  export {
1806
1766
  getBaseSchema,
1807
1767
  makeDynamicTable,
@@ -1817,7 +1777,8 @@ export {
1817
1777
  ModalController,
1818
1778
  TablePresentation,
1819
1779
  cellClassesForRowSelection,
1820
- useTableModel,
1821
- useAddRow
1780
+ useAddRow,
1781
+ useProjectionModel,
1782
+ useTableModel
1822
1783
  };
1823
- //# sourceMappingURL=chunk-QNDUGIS7.mjs.map
1784
+ //# sourceMappingURL=chunk-CWSGS3Y2.mjs.map