@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,11 +1,10 @@
1
1
  import {
2
- schema_exports
3
- } from "./chunk-63UUF4IG.mjs";
2
+ Table_exports
3
+ } from "./chunk-5XWSB3JP.mjs";
4
4
 
5
5
  // src/util/dynamic-table.ts
6
- import { Obj } from "@dxos/echo";
7
- import { getTypename, toJsonSchema } from "@dxos/echo-schema";
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 {
@@ -27,25 +26,26 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
27
26
  throw new Error("invalid properties");
28
27
  }
29
28
  };
30
- var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
31
- const table = Obj.make(schema_exports.Table, {
32
- sizes: {}
33
- });
34
- const view = createView({
35
- typename,
29
+ var makeDynamicTable = ({ jsonSchema, properties }) => {
30
+ const view = View.make({
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);
42
+ projection.normalizeView();
43
43
  if (properties && projection.fields) {
44
- setProperties(view, projection, table, properties);
44
+ setProperties(view, projection, object, properties);
45
45
  }
46
46
  return {
47
47
  projection,
48
- view
48
+ object
49
49
  };
50
50
  };
51
51
  var setProperties = (view, projection, table, properties) => {
@@ -67,7 +67,7 @@ var setProperties = (view, projection, table, properties) => {
67
67
  }
68
68
  if (property.sort) {
69
69
  const fieldId = field.id;
70
- view.query.sort = [
70
+ view.sort = [
71
71
  {
72
72
  fieldId,
73
73
  direction: property.sort
@@ -255,14 +255,14 @@ var tableControls = {
255
255
  };
256
256
 
257
257
  // src/util/schema.ts
258
- import { Schema } from "effect";
259
- import { TypeLiteral, isTypeLiteral } from "effect/SchemaAST";
258
+ import * as Schema from "effect/Schema";
259
+ import * as SchemaAST from "effect/SchemaAST";
260
260
  var narrowSchema = (schema, paths) => {
261
261
  const ast = schema?.ast;
262
- if (isTypeLiteral(ast)) {
262
+ if (SchemaAST.isTypeLiteral(ast)) {
263
263
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
264
264
  if (propertySignatures.length > 0) {
265
- const narrowType = new TypeLiteral(propertySignatures, []);
265
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
266
266
  return Schema.make(narrowType);
267
267
  }
268
268
  }
@@ -272,14 +272,13 @@ var narrowSchema = (schema, paths) => {
272
272
  // src/model/table-model.ts
273
273
  import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
274
274
  import { Resource as Resource2 } from "@dxos/context";
275
- import { Obj as Obj2, Ref } from "@dxos/echo";
276
- import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo-schema";
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";
277
277
  import { invariant } from "@dxos/invariant";
278
278
  import { ObjectId } from "@dxos/keys";
279
279
  import { getSnapshot, isLiveObject } from "@dxos/live-object";
280
- import { fullyQualifiedId } from "@dxos/react-client/echo";
281
280
  import { formatForEditing, parseValue } from "@dxos/react-ui-form";
282
- import { ProjectionModel as ProjectionModel2, validateSchema } from "@dxos/schema";
281
+ import { validateSchema } from "@dxos/schema";
283
282
 
284
283
  // src/util/tag.ts
285
284
  var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
@@ -300,20 +299,34 @@ var extractTagIds = (value) => {
300
299
  // src/model/selection-model.ts
301
300
  import { computed, effect, signal } from "@preact/signals-core";
302
301
  import { Resource } from "@dxos/context";
303
- function _define_property(obj, key, value) {
304
- if (key in obj) {
305
- Object.defineProperty(obj, key, {
306
- value,
307
- enumerable: true,
308
- configurable: true,
309
- writable: true
310
- });
311
- } else {
312
- obj[key] = value;
313
- }
314
- return obj;
315
- }
316
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
+ }
317
330
  async _open() {
318
331
  const selectionWatcher = effect(() => {
319
332
  touch(this._selection.value);
@@ -336,80 +349,80 @@ var SelectionModel = class extends Resource {
336
349
  get selectionMode() {
337
350
  return this._selectionMode;
338
351
  }
339
- constructor(_rows, _selectionMode, _initialSelection, _onSelectionChanged) {
340
- 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), //
341
- // Manipulation
342
- //
343
- _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(() => {
344
- const rows = this._rows.value;
345
- if (!rows) {
346
- return /* @__PURE__ */ new Set();
347
- }
348
- const validIds = new Set(rows.map((row) => row.id));
349
- return new Set([
350
- ...this._selection.value
351
- ].filter((id) => validIds.has(id)));
352
- }), this._hasSelection = computed(() => this._validSelectedIds.value.size > 0), this._allSelected = computed(() => {
353
- const rows = this._rows.value;
354
- if (rows.length === 0) {
355
- 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();
356
374
  }
357
- return rows.every((row) => this._selection.value.has(row.id));
358
- }), this.getSelectedRows = () => {
359
- const selectedIds = this._validSelectedIds.value;
360
- return this._rows.value.filter((row) => selectedIds.has(row.id));
361
- }, this.isRowIndexSelected = (rowIndex) => {
362
- const row = this._rows.value[rowIndex];
363
- return this._selection.value.has(row.id);
364
- }, this.isObjectSelected = (object) => {
365
- return this._selection.value.has(object.id);
366
- }, this.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();
374
- }
375
- 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;
376
384
  }
377
- this._selection.value = newSelection;
378
- }, this.setSelection = (mode) => {
379
- switch (mode) {
380
- case "all": {
381
- this._selection.value = new Set(this._rows.value.map((row) => row.id));
382
- break;
383
- }
384
- case "none": {
385
- this._selection.value = /* @__PURE__ */ new Set();
386
- break;
387
- }
385
+ case "none": {
386
+ this._selection.value = /* @__PURE__ */ new Set();
387
+ break;
388
388
  }
389
- };
390
- this._selection = signal(new Set(this._initialSelection));
391
- }
389
+ }
390
+ };
392
391
  };
393
392
 
394
393
  // src/model/table-sorting.ts
395
394
  import { computed as computed2, signal as signal2 } from "@preact/signals-core";
396
395
  import orderBy from "lodash.orderby";
397
- import { FormatEnum, TypeEnum, getValue } from "@dxos/echo-schema";
396
+ import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
398
397
  import { formatForDisplay } from "@dxos/react-ui-form";
399
- function _define_property2(obj, key, value) {
400
- if (key in obj) {
401
- Object.defineProperty(obj, key, {
402
- value,
403
- enumerable: true,
404
- configurable: true,
405
- 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;
406
423
  });
407
- } else {
408
- obj[key] = value;
424
+ this.sortedRows = this.initialiseSortedRows();
409
425
  }
410
- return obj;
411
- }
412
- var TableSorting = class {
413
426
  /**
414
427
  * @reactive
415
428
  * @returns Local sort if present, falls back to view sort.
@@ -422,7 +435,7 @@ var TableSorting = class {
422
435
  if (local?.type === "active") {
423
436
  return local.sort;
424
437
  }
425
- return this._view.query.sort?.[0];
438
+ return this._getView().sort?.[0];
426
439
  }
427
440
  /**
428
441
  * @reactive
@@ -465,12 +478,13 @@ var TableSorting = class {
465
478
  }
466
479
  save() {
467
480
  if (this._localSort.value !== void 0) {
481
+ const view = this._getView();
468
482
  if (this._localSort.value.type === "active") {
469
- this._view.query.sort = [
483
+ view.sort = [
470
484
  this._localSort.value.sort
471
485
  ];
472
486
  } else {
473
- this._view.query.sort = [];
487
+ view.sort = [];
474
488
  }
475
489
  this._localSort.value = void 0;
476
490
  }
@@ -527,7 +541,7 @@ var TableSorting = class {
527
541
  if (value == null) {
528
542
  return value;
529
543
  }
530
- if (format === FormatEnum.SingleSelect) {
544
+ if (format === Format.TypeFormat.SingleSelect) {
531
545
  const options = props.options;
532
546
  if (!options) {
533
547
  return void 0;
@@ -535,7 +549,7 @@ var TableSorting = class {
535
549
  const option = options.find((option2) => option2.id === value);
536
550
  return option ? options.indexOf(option) : void 0;
537
551
  }
538
- if (format === FormatEnum.Ref && field.referencePath) {
552
+ if (format === Format.TypeFormat.Ref && field.referencePath) {
539
553
  const refValue = getValue(value.target, field.referencePath);
540
554
  return refValue;
541
555
  }
@@ -545,51 +559,9 @@ var TableSorting = class {
545
559
  value
546
560
  });
547
561
  }
548
- constructor(rows, _view, _projection) {
549
- _define_property2(this, "_view", void 0);
550
- _define_property2(this, "_projection", void 0);
551
- _define_property2(this, "_displayToDataIndex", void 0);
552
- _define_property2(this, "_rows", void 0);
553
- _define_property2(this, "_localSort", void 0);
554
- _define_property2(this, "_isDirty", void 0);
555
- _define_property2(this, "sortedRows", void 0);
556
- this._view = _view;
557
- this._projection = _projection;
558
- this._displayToDataIndex = /* @__PURE__ */ new Map();
559
- this._localSort = signal2(void 0);
560
- this._rows = rows;
561
- this._isDirty = computed2(() => {
562
- const local = this._localSort.value;
563
- const viewSort = this._view.query.sort?.[0];
564
- if (local?.type === "cleared") {
565
- return viewSort !== void 0;
566
- }
567
- if (local?.type === "active") {
568
- if (!viewSort) {
569
- return true;
570
- }
571
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
572
- }
573
- return false;
574
- });
575
- this.sortedRows = this.initialiseSortedRows();
576
- }
577
562
  };
578
563
 
579
564
  // src/model/table-model.ts
580
- function _define_property3(obj, key, value) {
581
- if (key in obj) {
582
- Object.defineProperty(obj, key, {
583
- value,
584
- enumerable: true,
585
- configurable: true,
586
- writable: true
587
- });
588
- } else {
589
- obj[key] = value;
590
- }
591
- return obj;
592
- }
593
565
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
594
566
  var defaultFeatures = {
595
567
  selection: {
@@ -600,23 +572,90 @@ var defaultFeatures = {
600
572
  schemaEditable: false
601
573
  };
602
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
+ }
603
641
  get id() {
604
- return fullyQualifiedId(this._view);
642
+ return Obj2.getDXN(this._object).toString();
605
643
  }
606
644
  get view() {
607
- return this._view;
608
- }
609
- get table() {
610
- invariant(this._table, "Model not initialized", {
645
+ const view = this._object.view.target;
646
+ invariant(view, "Table model not initialized", {
611
647
  F: __dxlog_file,
612
- L: 180,
648
+ L: 176,
613
649
  S: this,
614
650
  A: [
615
- "this._table",
616
- "'Model not initialized'"
651
+ "view",
652
+ "'Table model not initialized'"
617
653
  ]
618
654
  });
619
- return this._table;
655
+ return view;
656
+ }
657
+ get table() {
658
+ return this._object;
620
659
  }
621
660
  get projection() {
622
661
  return this._projection;
@@ -671,17 +710,7 @@ var TableModel = class extends Resource2 {
671
710
  // Initialisation
672
711
  //
673
712
  async _open() {
674
- const presentation = this._view.presentation.target ?? await this._view.presentation.load();
675
- invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
676
- F: __dxlog_file,
677
- L: 242,
678
- S: this,
679
- A: [
680
- "Obj.instanceOf(Table.Table, presentation)",
681
- ""
682
- ]
683
- });
684
- this._table = presentation;
713
+ await this._object.view.load();
685
714
  this.initializeColumnMeta();
686
715
  this.initializeEffects();
687
716
  await this._selection.open(this._ctx);
@@ -742,6 +771,17 @@ var TableModel = class extends Resource2 {
742
771
  });
743
772
  this._ctx.onDispose(draftRowsWatcher);
744
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;
745
785
  // TODO(ZaymonFC): Return .value instead of exposing the signal.
746
786
  get draftRows() {
747
787
  return this._draftRows;
@@ -760,6 +800,14 @@ var TableModel = class extends Resource2 {
760
800
  const validationErrors = draftRow.validationErrors || [];
761
801
  return validationErrors.some((error) => error.path === fieldPath);
762
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
+ };
763
811
  createDraftRow() {
764
812
  if (!this._projection) {
765
813
  return;
@@ -799,6 +847,187 @@ var TableModel = class extends Resource2 {
799
847
  const schema = toEffectSchema(this._projection.baseSchema);
800
848
  return validateSchema(schema, data) || [];
801
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
+ };
802
1031
  /**
803
1032
  * Updates a cell's value using a transform function.
804
1033
  * @param {DxGridPlanePosition} position - The position of the cell to update.
@@ -879,250 +1108,17 @@ var TableModel = class extends Resource2 {
879
1108
  saveView() {
880
1109
  this._sorting.save();
881
1110
  }
882
- constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
883
- top: [],
884
- bottom: []
885
- }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
886
- super(), _define_property3(this, "_view", void 0), _define_property3(this, "_projection", void 0), _define_property3(this, "_table", void 0), _define_property3(this, "_visibleRange", signal3({
887
- start: {
888
- row: 0,
889
- col: 0
890
- },
891
- end: {
892
- row: 0,
893
- col: 0
894
- }
895
- })), _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), //
896
- // Data
897
- //
898
- _define_property3(this, "setRows", (obj) => {
899
- this._rows.value = obj;
900
- }), _define_property3(this, "getRowCount", () => this._rows.value.length), /**
901
- * @reactive
902
- */
903
- _define_property3(this, "getDraftRowCount", () => this._draftRows.value.length), _define_property3(this, "getColumnCount", () => this._projection?.fields.length ?? 0), _define_property3(this, "insertRow", () => {
904
- const result = this._onInsertRow?.();
905
- if (result === "draft" && this._draftRows.value.length === 0) {
906
- this.createDraftRow();
907
- }
908
- return result ?? "final";
909
- }), _define_property3(this, "commitDraftRow", (draftRowIndex) => {
910
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
911
- return false;
912
- }
913
- const draftRow = this._draftRows.value[draftRowIndex];
914
- if (!draftRow.valid) {
915
- return false;
916
- }
917
- const insertRowResult = this._onInsertRow?.(draftRow.data);
918
- if (insertRowResult === "final") {
919
- const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
920
- this._draftRows.value = newDraftRows;
921
- }
922
- return insertRowResult === "final";
923
- }), _define_property3(this, "deleteRow", (rowIndex) => {
924
- const row = this._sorting.getDataIndex(rowIndex);
925
- const obj = this._rows.value[row];
926
- const objectsToDelete = [];
927
- if (this.features.selection.enabled && this._selection.hasSelection.value) {
928
- const selectedRows = this._selection.getSelectedRows();
929
- objectsToDelete.push(...selectedRows);
930
- } else {
931
- objectsToDelete.push(obj);
932
- }
933
- this._onDeleteRows?.(row, objectsToDelete);
934
- }), _define_property3(this, "handleRowAction", (actionId, rowIndex) => {
935
- if (!this._onRowAction) {
936
- return;
937
- }
938
- const row = this._sorting.getDataIndex(rowIndex);
939
- const data = this._rows.value[row];
940
- if (data) {
941
- this._onRowAction(actionId, data);
942
- }
943
- }), _define_property3(this, "getCellData", (cell) => {
944
- const { col, row, plane } = cell;
945
- const fields = this._projection?.fields ?? [];
946
- if (col < 0 || col >= fields.length) {
947
- return void 0;
948
- }
949
- const field = fields[col];
950
- let value;
951
- if (plane === "frozenRowsEnd") {
952
- if (row >= 0 && row < this._draftRows.value.length) {
953
- value = getValue2(this._draftRows.value[row].data, field.path);
954
- } else {
955
- return void 0;
956
- }
957
- } else {
958
- const dataIndex = this._sorting.getDataIndex(row);
959
- value = getValue2(this._rows.value[dataIndex], field.path);
960
- }
961
- if (value == null) {
962
- return "";
963
- }
964
- const { props } = this._projection.getFieldProjection(field.id);
965
- switch (props.format) {
966
- case FormatEnum2.Ref: {
967
- if (!field.referencePath) {
968
- return "";
969
- }
970
- return getValue2(value.target, field.referencePath);
971
- }
972
- default: {
973
- return formatForEditing({
974
- type: props.type,
975
- format: props.format,
976
- value
977
- });
978
- }
979
- }
980
- }), _define_property3(this, "validateCellData", async ({ col, row, plane }, value) => {
981
- const fields = this._projection?.fields ?? [];
982
- if (col < 0 || col >= fields.length) {
983
- return {
984
- valid: false,
985
- error: "Invalid column index"
986
- };
987
- }
988
- const field = fields[col];
989
- const { props } = this._projection.getFieldProjection(field.id);
990
- const transformedValue = editorTextToCellValue(props, value);
991
- const isDraftRow = plane === "frozenRowsEnd";
992
- if (isDraftRow) {
993
- const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
994
- if (isInvalidDraftRowIndex) {
995
- return {
996
- valid: false,
997
- error: "Invalid draft row index"
998
- };
999
- }
1000
- const draftRow = this._draftRows.value[row];
1001
- const snapshot = {
1002
- ...draftRow.data
1003
- };
1004
- setValue(snapshot, field.path, transformedValue);
1005
- const validationErrors = this.validateDraftRowData(snapshot);
1006
- if (validationErrors.length > 0) {
1007
- const error = validationErrors.find((err) => err.path === field.path);
1008
- if (error) {
1009
- return {
1010
- valid: false,
1011
- error: error.message
1012
- };
1013
- }
1014
- }
1015
- return {
1016
- valid: true
1017
- };
1018
- } else {
1019
- const rowIdx = this._sorting.getDataIndex(row);
1020
- const currentRow = this._rows.value[rowIdx];
1021
- invariant(currentRow, "Invalid row index", {
1022
- F: __dxlog_file,
1023
- L: 515,
1024
- S: this,
1025
- A: [
1026
- "currentRow",
1027
- "'Invalid row index'"
1028
- ]
1029
- });
1030
- const snapshot = getSnapshot(currentRow);
1031
- setValue(snapshot, field.path, transformedValue);
1032
- const schema2 = getSchema(currentRow);
1033
- invariant(schema2, void 0, {
1034
- F: __dxlog_file,
1035
- L: 521,
1036
- S: this,
1037
- A: [
1038
- "schema",
1039
- ""
1040
- ]
1041
- });
1042
- const validationResult = validateSchema(schema2, snapshot);
1043
- if (validationResult && validationResult.length > 0) {
1044
- const error = validationResult[0];
1045
- invariant(error.path === field.path, void 0, {
1046
- F: __dxlog_file,
1047
- L: 526,
1048
- S: this,
1049
- A: [
1050
- "error.path === field.path",
1051
- ""
1052
- ]
1053
- });
1054
- return {
1055
- valid: false,
1056
- error: error.message
1057
- };
1058
- }
1059
- return {
1060
- valid: true
1061
- };
1062
- }
1063
- }), _define_property3(this, "setCellData", (cell, value) => {
1064
- const { col, row, plane } = cell;
1065
- const fields = this._projection?.fields ?? [];
1066
- if (col < 0 || col >= fields.length) {
1067
- return;
1068
- }
1069
- const field = fields[col];
1070
- const { props } = this._projection.getFieldProjection(field.id);
1071
- const transformedValue = editorTextToCellValue(props, value);
1072
- if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
1073
- return;
1074
- }
1075
- if (plane === "frozenRowsEnd") {
1076
- if (row >= 0 && row < this._draftRows.value.length) {
1077
- setValue(this._draftRows.value[row].data, field.path, transformedValue);
1078
- this.validateDraftRow(row);
1079
- }
1080
- } else {
1081
- const rowIdx = this._sorting.getDataIndex(row);
1082
- setValue(this._rows.value[rowIdx], field.path, transformedValue);
1083
- }
1084
- });
1085
- this._view = view;
1086
- this._projection = projection ?? new ProjectionModel2(schema, view.projection);
1087
- this._features = {
1088
- ...defaultFeatures,
1089
- ...features
1090
- };
1091
- invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1092
- F: __dxlog_file,
1093
- L: 142,
1094
- S: this,
1095
- A: [
1096
- "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1097
- "'Single selection is not compatible with editable tables.'"
1098
- ]
1099
- });
1100
- this._sorting = new TableSorting(this._rows, this._view, this._projection);
1101
- if (sorting.length > 0) {
1102
- const [sort] = sorting;
1103
- this._sorting.setSort(sort.fieldId, sort.direction);
1104
- }
1105
- this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
1106
- this._pinnedRows = pinnedRows;
1107
- this._rowActions = rowActions;
1108
- this._onInsertRow = onInsertRow;
1109
- this._onDeleteRows = onDeleteRows;
1110
- this._onDeleteColumn = onDeleteColumn;
1111
- this._onCellUpdate = onCellUpdate;
1112
- this._onRowOrderChange = onRowOrderChange;
1113
- this._onRowAction = onRowAction;
1114
- }
1115
1111
  };
1116
1112
  var editorTextToCellValue = (props, value) => {
1117
1113
  switch (props.format) {
1118
- case FormatEnum2.Ref: {
1114
+ case Format2.TypeFormat.Ref: {
1119
1115
  if (isLiveObject(value)) {
1120
- return Ref.make(value);
1116
+ return Ref2.make(value);
1121
1117
  } else {
1122
1118
  return value;
1123
1119
  }
1124
1120
  }
1125
- case FormatEnum2.SingleSelect: {
1121
+ case Format2.TypeFormat.SingleSelect: {
1126
1122
  const ids = extractTagIds(value);
1127
1123
  if (ids && ids.length > 0) {
1128
1124
  return ids[0];
@@ -1130,7 +1126,7 @@ var editorTextToCellValue = (props, value) => {
1130
1126
  return value;
1131
1127
  }
1132
1128
  }
1133
- case FormatEnum2.MultiSelect: {
1129
+ case Format2.TypeFormat.MultiSelect: {
1134
1130
  const ids = extractTagIds(value);
1135
1131
  return ids || value;
1136
1132
  }
@@ -1146,128 +1142,96 @@ var editorTextToCellValue = (props, value) => {
1146
1142
 
1147
1143
  // src/model/modal-controller.ts
1148
1144
  import { signal as signal4 } from "@preact/signals-core";
1149
- import { log } from "@dxos/log";
1150
- function _define_property4(obj, key, value) {
1151
- if (key in obj) {
1152
- Object.defineProperty(obj, key, {
1153
- value,
1154
- enumerable: true,
1155
- configurable: true,
1156
- writable: true
1157
- });
1158
- } else {
1159
- obj[key] = value;
1160
- }
1161
- return obj;
1162
- }
1163
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
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, "openCreateRef", (typename, anchorCell, initialValues, onCreate) => {
1223
- if (anchorCell) {
1224
- this._triggerRef.current = anchorCell;
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(() => {
1225
1192
  this._state.value = {
1226
- type: "createRefPanel",
1227
- typename,
1228
- initialValues,
1229
- onCreate
1193
+ type: "columnSettings",
1194
+ mode: {
1195
+ type: "edit",
1196
+ fieldId
1197
+ }
1230
1198
  };
1231
- } else {
1232
- log.warn("anchor cell not found while creating new ref", void 0, {
1233
- F: __dxlog_file2,
1234
- L: 86,
1235
- S: this,
1236
- C: (f, a) => f(...a)
1237
- });
1238
- }
1239
- });
1240
- _define_property4(this, "close", () => {
1241
- this._state.value = {
1242
- type: "closed"
1243
- };
1244
- });
1245
- }
1199
+ });
1200
+ }
1201
+ };
1202
+ close = () => {
1203
+ this._state.value = {
1204
+ type: "closed"
1205
+ };
1206
+ };
1246
1207
  };
1247
1208
 
1248
1209
  // src/model/table-presentation.ts
1249
1210
  import { signal as signal5 } from "@preact/signals-core";
1250
- import { isNotNullable } from "effect/Predicate";
1211
+ import * as Predicate from "effect/Predicate";
1251
1212
  import { Obj as Obj3 } from "@dxos/echo";
1252
- import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo-schema";
1213
+ import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1253
1214
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1254
1215
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1255
1216
  import { mx } from "@dxos/react-ui-theme";
1256
1217
  import { VIEW_FIELD_LIMIT } from "@dxos/schema";
1257
- function _define_property5(obj, key, value) {
1258
- if (key in obj) {
1259
- Object.defineProperty(obj, key, {
1260
- value,
1261
- enumerable: true,
1262
- configurable: true,
1263
- writable: true
1264
- });
1265
- } else {
1266
- obj[key] = value;
1267
- }
1268
- return obj;
1269
- }
1270
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
+ }
1271
1235
  getCells(range, plane) {
1272
1236
  this.fieldProjectionCache.clear();
1273
1237
  let cells;
@@ -1333,12 +1297,12 @@ var TablePresentation = class {
1333
1297
  return "";
1334
1298
  }
1335
1299
  switch (props.format) {
1336
- case FormatEnum3.Boolean:
1337
- case FormatEnum3.SingleSelect:
1338
- case FormatEnum3.MultiSelect: {
1300
+ case Format3.TypeFormat.Boolean:
1301
+ case Format3.TypeFormat.SingleSelect:
1302
+ case Format3.TypeFormat.MultiSelect: {
1339
1303
  return "";
1340
1304
  }
1341
- case FormatEnum3.Ref: {
1305
+ case Format3.TypeFormat.Ref: {
1342
1306
  if (!field.referencePath) {
1343
1307
  return "";
1344
1308
  }
@@ -1385,20 +1349,20 @@ var TablePresentation = class {
1385
1349
  }
1386
1350
  return "Object";
1387
1351
  };
1388
- const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
1352
+ const tags = targetArray.map(getLabel).filter(Predicate.isNotNullable).map((title) => {
1389
1353
  return `<span class="dx-tag" data-hue="neutral">${title}</span>`;
1390
1354
  }).join("");
1391
1355
  cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1392
1356
  }
1393
1357
  }
1394
- if (props.format === FormatEnum3.Ref && props.referenceSchema) {
1358
+ if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
1395
1359
  const targetObj = getValue3(obj, field.path)?.target;
1396
1360
  if (targetObj) {
1397
1361
  const dxn = Obj3.getDXN(targetObj)?.toString();
1398
- 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>`;
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>`;
1399
1363
  }
1400
1364
  }
1401
- if (props.format === FormatEnum3.Boolean) {
1365
+ if (props.format === Format3.TypeFormat.Boolean) {
1402
1366
  const value = getValue3(obj, field.path);
1403
1367
  cell.accessoryHtml = tableControls.switch.render({
1404
1368
  colIndex,
@@ -1407,7 +1371,7 @@ var TablePresentation = class {
1407
1371
  });
1408
1372
  cell.readonly = "no-text-select";
1409
1373
  }
1410
- if (props.format === FormatEnum3.SingleSelect) {
1374
+ if (props.format === Format3.TypeFormat.SingleSelect) {
1411
1375
  const value = getValue3(obj, field.path);
1412
1376
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1413
1377
  if (options) {
@@ -1417,7 +1381,7 @@ var TablePresentation = class {
1417
1381
  }
1418
1382
  }
1419
1383
  }
1420
- if (props.format === FormatEnum3.MultiSelect) {
1384
+ if (props.format === Format3.TypeFormat.MultiSelect) {
1421
1385
  const values = getValue3(obj, field.path);
1422
1386
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1423
1387
  if (options && values && values.length > 0) {
@@ -1653,23 +1617,6 @@ var TablePresentation = class {
1653
1617
  }
1654
1618
  return cells;
1655
1619
  }
1656
- constructor(model, _visibleRange = signal5({
1657
- start: {
1658
- row: 0,
1659
- col: 0
1660
- },
1661
- end: {
1662
- row: 0,
1663
- col: 0
1664
- }
1665
- })) {
1666
- _define_property5(this, "model", void 0);
1667
- _define_property5(this, "_visibleRange", void 0);
1668
- _define_property5(this, "fieldProjectionCache", void 0);
1669
- this.model = model;
1670
- this._visibleRange = _visibleRange;
1671
- this.fieldProjectionCache = /* @__PURE__ */ new Map();
1672
- }
1673
1620
  };
1674
1621
  var cellClassesForRowSelection = (selected, selectionMode) => {
1675
1622
  if (!selected) {
@@ -1693,31 +1640,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1693
1640
  }
1694
1641
  };
1695
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
+
1696
1678
  // src/hooks/useTableModel.ts
1697
1679
  import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
1698
1680
  import { effect as effect3 } from "@preact/signals-core";
1699
1681
  import orderBy2 from "lodash.orderby";
1700
- import { useEffect, useMemo, useState } from "react";
1701
- 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";
1702
1684
  import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
1703
1685
  import { isNonNullable } from "@dxos/util";
1704
- var useTableModel = ({ view, schema, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1686
+ var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1705
1687
  var _effect = _useSignals();
1706
1688
  try {
1707
- const selected = useSelected(view && fullyQualifiedId2(view), "multi");
1708
- const initialSelection = useMemo(() => selected, [
1709
- view
1689
+ const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
1690
+ const initialSelection = useMemo2(() => selected, [
1691
+ object
1710
1692
  ]);
1711
1693
  const [model, setModel] = useState();
1712
1694
  useEffect(() => {
1713
- if (!view || !schema) {
1695
+ if (!object || !projection) {
1714
1696
  return;
1715
1697
  }
1716
1698
  let model2;
1717
1699
  const t = setTimeout(async () => {
1718
1700
  model2 = new TableModel({
1719
- view,
1720
- schema,
1701
+ object,
1721
1702
  projection,
1722
1703
  features,
1723
1704
  rowActions,
@@ -1733,8 +1714,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1733
1714
  void model2?.close();
1734
1715
  };
1735
1716
  }, [
1736
- view,
1737
- schema,
1717
+ object,
1738
1718
  projection,
1739
1719
  features,
1740
1720
  rowActions,
@@ -1781,26 +1761,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1781
1761
  }
1782
1762
  };
1783
1763
 
1784
- // src/hooks/useAddRow.ts
1785
- import { useCallback } from "react";
1786
- import { Obj as Obj4 } from "@dxos/echo";
1787
- var useAddRow = ({ space, schema }) => {
1788
- return useCallback((data) => {
1789
- if (space && schema) {
1790
- try {
1791
- space.db.add(Obj4.make(schema, data ?? {}));
1792
- return "final";
1793
- } catch (error) {
1794
- return "draft";
1795
- }
1796
- }
1797
- return "final";
1798
- }, [
1799
- space,
1800
- schema
1801
- ]);
1802
- };
1803
-
1804
1764
  export {
1805
1765
  getBaseSchema,
1806
1766
  makeDynamicTable,
@@ -1816,7 +1776,8 @@ export {
1816
1776
  ModalController,
1817
1777
  TablePresentation,
1818
1778
  cellClassesForRowSelection,
1819
- useTableModel,
1820
- useAddRow
1779
+ useAddRow,
1780
+ useProjectionModel,
1781
+ useTableModel
1821
1782
  };
1822
- //# sourceMappingURL=chunk-RQYXNWWN.mjs.map
1783
+ //# sourceMappingURL=chunk-KNC7XYT6.mjs.map