@dxos/react-ui-table 0.8.4-main.2c6827d → 0.8.4-main.3c1ae3b

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 (103) hide show
  1. package/dist/lib/browser/chunk-CJQ6T4LL.mjs +77 -0
  2. package/dist/lib/browser/chunk-CJQ6T4LL.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-V7A7ZA5E.mjs} +119 -111
  4. package/dist/lib/browser/chunk-V7A7ZA5E.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +162 -147
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +15 -31
  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-TRR3C5NX.mjs → chunk-P73ALX3N.mjs} +119 -111
  12. package/dist/lib/node-esm/chunk-P73ALX3N.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs +78 -0
  14. package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +162 -147
  16. package/dist/lib/node-esm/index.mjs.map +3 -3
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +15 -31
  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/ColumnActionsMenu.d.ts +1 -2
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +4 -5
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +3 -17
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +10 -6
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/Table.d.ts +8 -8
  32. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.stories.d.ts +70 -4
  34. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  35. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  36. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -11
  37. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  38. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
  39. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +3 -3
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  42. package/dist/types/src/components/testing.d.ts +0 -2
  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/useProjectionModel.d.ts +5 -0
  47. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  48. package/dist/types/src/hooks/useTableModel.d.ts +4 -5
  49. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  50. package/dist/types/src/model/table-model.d.ts +6 -8
  51. package/dist/types/src/model/table-model.d.ts.map +1 -1
  52. package/dist/types/src/model/table-sorting.d.ts +7 -3
  53. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  54. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  55. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  56. package/dist/types/src/testing/useTestTableModel.d.ts +19 -15
  57. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  58. package/dist/types/src/translations.d.ts +2 -2
  59. package/dist/types/src/types/Table.d.ts +28 -0
  60. package/dist/types/src/types/Table.d.ts.map +1 -0
  61. package/dist/types/src/types/index.d.ts +1 -1
  62. package/dist/types/src/types/index.d.ts.map +1 -1
  63. package/dist/types/src/util/dynamic-table.d.ts +9 -9
  64. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  65. package/dist/types/tsconfig.tsbuildinfo +1 -1
  66. package/package.json +38 -38
  67. package/src/components/Table/ColumnActionsMenu.tsx +4 -1
  68. package/src/components/Table/ColumnSettings.tsx +2 -3
  69. package/src/components/Table/DynamicTable.stories.tsx +7 -9
  70. package/src/components/Table/DynamicTable.tsx +18 -10
  71. package/src/components/Table/Relations.stories.tsx +9 -18
  72. package/src/components/Table/Table.stories.tsx +52 -59
  73. package/src/components/Table/Table.tsx +317 -304
  74. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  75. package/src/components/TableCellEditor/FormCellEditor.tsx +101 -108
  76. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +11 -8
  77. package/src/components/TableCellEditor/TableCellEditor.tsx +29 -29
  78. package/src/components/TableToolbar/TableToolbar.tsx +1 -1
  79. package/src/components/testing.ts +3 -3
  80. package/src/hooks/index.ts +2 -1
  81. package/src/hooks/useProjectionModel.ts +19 -0
  82. package/src/hooks/useTableModel.ts +11 -13
  83. package/src/model/table-model.test.ts +4 -4
  84. package/src/model/table-model.ts +29 -38
  85. package/src/model/table-presentation.test.ts +4 -4
  86. package/src/model/table-presentation.ts +9 -9
  87. package/src/model/table-sorting.ts +21 -12
  88. package/src/playwright/TableManager.ts +5 -5
  89. package/src/playwright/smoke.spec.ts +1 -1
  90. package/src/testing/useTestTableModel.ts +31 -27
  91. package/src/translations.ts +2 -2
  92. package/src/types/Table.ts +90 -0
  93. package/src/types/index.ts +1 -1
  94. package/src/util/dynamic-table.ts +11 -16
  95. package/dist/lib/browser/chunk-2PFAPQL4.mjs +0 -66
  96. package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +0 -7
  97. package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +0 -7
  98. package/dist/lib/node-esm/chunk-6POOFFYF.mjs +0 -67
  99. package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +0 -7
  100. package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +0 -7
  101. package/dist/types/src/types/schema.d.ts +0 -28
  102. package/dist/types/src/types/schema.d.ts.map +0 -1
  103. package/src/types/schema.ts +0 -73
@@ -0,0 +1,77 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/types/Table.ts
8
+ var Table_exports = {};
9
+ __export(Table_exports, {
10
+ Table: () => Table,
11
+ TableV1: () => TableV1,
12
+ make: () => make
13
+ });
14
+ import * as Match from "effect/Match";
15
+ import * as Schema from "effect/Schema";
16
+ import * as SchemaAST from "effect/SchemaAST";
17
+ import { Obj, Ref, Type } from "@dxos/echo";
18
+ import { FormInputAnnotation, LabelAnnotation } from "@dxos/echo/internal";
19
+ import { View, ViewAnnotation } from "@dxos/schema";
20
+ var TableSchema = Schema.Struct({
21
+ name: Schema.String.pipe(Schema.optional),
22
+ view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
23
+ sizes: Schema.Record({
24
+ // TODO(wittjosiah): Should be JsonPath.
25
+ key: Schema.String,
26
+ value: Schema.Number
27
+ }).pipe(Schema.mutable, FormInputAnnotation.set(false))
28
+ }).pipe(Type.Obj({
29
+ typename: "dxos.org/type/Table",
30
+ version: "0.2.0"
31
+ }), LabelAnnotation.set([
32
+ "name"
33
+ ]), ViewAnnotation.set(true));
34
+ var Table = TableSchema;
35
+ var make = ({ name, sizes = {}, view, jsonSchema }) => {
36
+ const table = Obj.make(Table, {
37
+ name,
38
+ view: Ref.make(view),
39
+ sizes
40
+ });
41
+ if (jsonSchema) {
42
+ const schema = Type.toEffectSchema(jsonSchema);
43
+ const properties = SchemaAST.getPropertySignatures(schema.ast);
44
+ for (const property of properties) {
45
+ const name2 = property.name.toString();
46
+ if (sizes?.[name2]) {
47
+ table.sizes[name2] = sizes[name2];
48
+ continue;
49
+ }
50
+ Match.type().pipe(Match.when({
51
+ _tag: "BooleanKeyword"
52
+ }, () => {
53
+ table.sizes[name2] = 100;
54
+ }), Match.when({
55
+ _tag: "NumberKeyword"
56
+ }, () => {
57
+ table.sizes[name2] = 100;
58
+ }), Match.orElse(() => {
59
+ }))(property.type);
60
+ }
61
+ }
62
+ return table;
63
+ };
64
+ var TableV1 = Schema.Struct({
65
+ sizes: Schema.Record({
66
+ key: Schema.String,
67
+ value: Schema.Number
68
+ }).pipe(Schema.mutable)
69
+ }).pipe(Type.Obj({
70
+ typename: "dxos.org/type/Table",
71
+ version: "0.1.0"
72
+ }));
73
+
74
+ export {
75
+ Table_exports
76
+ };
77
+ //# sourceMappingURL=chunk-CJQ6T4LL.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/Table.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\nimport * as SchemaAST from 'effect/SchemaAST';\n\nimport { Obj, Ref, Type } from '@dxos/echo';\nimport { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';\nimport { View, ViewAnnotation } from '@dxos/schema';\n\nconst TableSchema = Schema.Struct({\n name: Schema.String.pipe(Schema.optional),\n\n view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),\n\n sizes: Schema.Record({\n // TODO(wittjosiah): Should be JsonPath.\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable, FormInputAnnotation.set(false)),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.2.0',\n }),\n LabelAnnotation.set(['name']),\n ViewAnnotation.set(true),\n);\n\nexport interface Table extends Schema.Schema.Type<typeof TableSchema> {}\nexport interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}\nexport const Table: Schema.Schema<Table, TableEncoded> = TableSchema;\n\ntype MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {\n view: View.View;\n /** Required to auto-size columns. */\n jsonSchema?: JsonSchemaType;\n};\n\n/**\n * Make a table as a view of a data set.\n */\nexport const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {\n const table = Obj.make(Table, { name, view: Ref.make(view), sizes });\n\n // Preset sizes.\n if (jsonSchema) {\n const schema = Type.toEffectSchema(jsonSchema);\n const properties = SchemaAST.getPropertySignatures(schema.ast);\n for (const property of properties) {\n const name = property.name.toString() as JsonPath;\n if (sizes?.[name]) {\n table.sizes[name] = sizes[name];\n continue;\n }\n\n Match.type<SchemaAST.AST>().pipe(\n Match.when({ _tag: 'BooleanKeyword' }, () => {\n table.sizes[name] = 100;\n }),\n Match.when({ _tag: 'NumberKeyword' }, () => {\n table.sizes[name] = 100;\n }),\n Match.orElse(() => {\n // Noop.\n }),\n )(property.type);\n }\n }\n\n return table;\n};\n\n//\n// V1\n//\n\nexport const TableV1 = Schema.Struct({\n sizes: Schema.Record({\n key: Schema.String,\n value: Schema.Number,\n }).pipe(Schema.mutable),\n}).pipe(\n Type.Obj({\n typename: 'dxos.org/type/Table',\n version: '0.1.0',\n }),\n);\n"],
5
+ "mappings": ";;;;;;;AAAA;;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AACxB,YAAYC,eAAe;AAE3B,SAASC,KAAKC,KAAKC,YAAY;AAC/B,SAASC,qBAAyDC,uBAAuB;AACzF,SAASC,MAAMC,sBAAsB;AAErC,IAAMC,cAAqBC,cAAO;EAChCC,MAAaC,cAAOC,KAAYC,eAAQ;EAExCC,MAAMC,KAAKC,IAAIC,KAAKA,IAAI,EAAEL,KAAKM,oBAAoBC,IAAI,KAAA,CAAA;EAEvDC,OAAcC,cAAO;;IAEnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,gBAASP,oBAAoBC,IAAI,KAAA,CAAA;AAClD,CAAA,EAAGP,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,gBAAgBV,IAAI;EAAC;CAAO,GAC5BW,eAAeX,IAAI,IAAA,CAAA;AAKd,IAAMY,QAA4CvB;AAWlD,IAAMwB,OAAO,CAAC,EAAEtB,MAAMU,QAAQ,CAAC,GAAGN,MAAMmB,WAAU,MAAa;AACpE,QAAMC,QAAQR,IAAIM,KAAKD,OAAO;IAAErB;IAAMI,MAAME,IAAIgB,KAAKlB,IAAAA;IAAOM;EAAM,CAAA;AAGlE,MAAIa,YAAY;AACd,UAAME,SAASpB,KAAKqB,eAAeH,UAAAA;AACnC,UAAMI,aAAuBC,gCAAsBH,OAAOI,GAAG;AAC7D,eAAWC,YAAYH,YAAY;AACjC,YAAM3B,QAAO8B,SAAS9B,KAAK+B,SAAQ;AACnC,UAAIrB,QAAQV,KAAAA,GAAO;AACjBwB,cAAMd,MAAMV,KAAAA,IAAQU,MAAMV,KAAAA;AAC1B;MACF;AAEAgC,MAAMC,WAAI,EAAkB/B,KACpBgC,WAAK;QAAEC,MAAM;MAAiB,GAAG,MAAA;AACrCX,cAAMd,MAAMV,KAAAA,IAAQ;MACtB,CAAA,GACMkC,WAAK;QAAEC,MAAM;MAAgB,GAAG,MAAA;AACpCX,cAAMd,MAAMV,KAAAA,IAAQ;MACtB,CAAA,GACMoC,aAAO,MAAA;MAEb,CAAA,CAAA,EACAN,SAASG,IAAI;IACjB;EACF;AAEA,SAAOT;AACT;AAMO,IAAMa,UAAiBtC,cAAO;EACnCW,OAAcC,cAAO;IACnBC,KAAYX;IACZY,OAAcC;EAChB,CAAA,EAAGZ,KAAYa,cAAO;AACxB,CAAA,EAAGb,KACDG,KAAKW,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;",
6
+ "names": ["Match", "Schema", "SchemaAST", "Obj", "Ref", "Type", "FormInputAnnotation", "LabelAnnotation", "View", "ViewAnnotation", "TableSchema", "Struct", "name", "String", "pipe", "optional", "view", "Type", "Ref", "View", "FormInputAnnotation", "set", "sizes", "Record", "key", "value", "Number", "mutable", "Obj", "typename", "version", "LabelAnnotation", "ViewAnnotation", "Table", "make", "jsonSchema", "table", "schema", "toEffectSchema", "properties", "getPropertySignatures", "ast", "property", "toString", "Match", "type", "when", "_tag", "orElse", "TableV1"]
7
+ }
@@ -1,12 +1,11 @@
1
1
  import {
2
- schema_exports
3
- } from "./chunk-2PFAPQL4.mjs";
2
+ Table_exports
3
+ } from "./chunk-CJQ6T4LL.mjs";
4
4
 
5
5
  // src/util/dynamic-table.ts
6
- import { Filter, Obj, Query } from "@dxos/echo";
7
- import { getTypename, toJsonSchema } from "@dxos/echo/internal";
6
+ import { Filter, Obj, Query, Ref, Type } from "@dxos/echo";
8
7
  import { ProjectionModel, View, getSchemaFromPropertyDefinitions } from "@dxos/schema";
9
- var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
8
+ var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
10
9
  if (typename && properties) {
11
10
  const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
12
11
  return {
@@ -15,8 +14,8 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
15
14
  };
16
15
  } else if (schema) {
17
16
  return {
18
- typename: getTypename(schema),
19
- jsonSchema: toJsonSchema(schema)
17
+ typename: Type.getTypename(schema),
18
+ jsonSchema: Type.toJsonSchema(schema)
20
19
  };
21
20
  } else if (typename && jsonSchema) {
22
21
  return {
@@ -28,25 +27,25 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
28
27
  }
29
28
  };
30
29
  var makeDynamicTable = ({ jsonSchema, properties }) => {
31
- const table = Obj.make(schema_exports.Table, {
32
- sizes: {}
33
- });
34
30
  const view = View.make({
35
31
  query: Query.select(Filter.everything()),
36
32
  jsonSchema,
37
- presentation: table,
38
33
  ...properties && {
39
34
  fields: properties.map((property) => property.name)
40
35
  }
41
36
  });
37
+ const object = Obj.make(Table_exports.Table, {
38
+ view: Ref.make(view),
39
+ sizes: {}
40
+ });
42
41
  const projection = new ProjectionModel(jsonSchema, view.projection);
43
42
  projection.normalizeView();
44
43
  if (properties && projection.fields) {
45
- setProperties(view, projection, table, properties);
44
+ setProperties(view, projection, object, properties);
46
45
  }
47
46
  return {
48
47
  projection,
49
- view
48
+ object
50
49
  };
51
50
  };
52
51
  var setProperties = (view, projection, table, properties) => {
@@ -273,13 +272,13 @@ var narrowSchema = (schema, paths) => {
273
272
  // src/model/table-model.ts
274
273
  import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
275
274
  import { Resource as Resource2 } from "@dxos/context";
276
- import { Obj as Obj2, Ref } from "@dxos/echo";
277
- import { FormatEnum as FormatEnum2, getSchema, getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
275
+ import { Format as Format2, Obj as Obj2, Ref as Ref2 } from "@dxos/echo";
276
+ import { getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
278
277
  import { invariant } from "@dxos/invariant";
279
278
  import { ObjectId } from "@dxos/keys";
280
279
  import { getSnapshot, isLiveObject } from "@dxos/live-object";
281
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;
@@ -394,23 +393,23 @@ var SelectionModel = class extends Resource {
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/internal";
396
+ import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
398
397
  import { formatForDisplay } from "@dxos/react-ui-form";
399
398
  var TableSorting = class {
400
- _view;
401
- _projection;
402
399
  _displayToDataIndex = /* @__PURE__ */ new Map();
403
400
  _rows;
401
+ _getView;
402
+ _projection;
404
403
  _localSort = signal2(void 0);
405
404
  _isDirty;
406
405
  sortedRows;
407
- constructor(rows, _view, _projection) {
408
- this._view = _view;
409
- this._projection = _projection;
406
+ constructor({ rows, projection, getView }) {
410
407
  this._rows = rows;
408
+ this._getView = getView;
409
+ this._projection = projection;
411
410
  this._isDirty = computed2(() => {
412
411
  const local = this._localSort.value;
413
- const viewSort = this._view.sort?.[0];
412
+ const viewSort = this._getView().sort?.[0];
414
413
  if (local?.type === "cleared") {
415
414
  return viewSort !== void 0;
416
415
  }
@@ -436,7 +435,7 @@ var TableSorting = class {
436
435
  if (local?.type === "active") {
437
436
  return local.sort;
438
437
  }
439
- return this._view.sort?.[0];
438
+ return this._getView().sort?.[0];
440
439
  }
441
440
  /**
442
441
  * @reactive
@@ -479,12 +478,13 @@ var TableSorting = class {
479
478
  }
480
479
  save() {
481
480
  if (this._localSort.value !== void 0) {
481
+ const view = this._getView();
482
482
  if (this._localSort.value.type === "active") {
483
- this._view.sort = [
483
+ view.sort = [
484
484
  this._localSort.value.sort
485
485
  ];
486
486
  } else {
487
- this._view.sort = [];
487
+ view.sort = [];
488
488
  }
489
489
  this._localSort.value = void 0;
490
490
  }
@@ -541,7 +541,7 @@ var TableSorting = class {
541
541
  if (value == null) {
542
542
  return value;
543
543
  }
544
- if (format === FormatEnum.SingleSelect) {
544
+ if (format === Format.TypeFormat.SingleSelect) {
545
545
  const options = props.options;
546
546
  if (!options) {
547
547
  return void 0;
@@ -549,7 +549,7 @@ var TableSorting = class {
549
549
  const option = options.find((option2) => option2.id === value);
550
550
  return option ? options.indexOf(option) : void 0;
551
551
  }
552
- if (format === FormatEnum.Ref && field.referencePath) {
552
+ if (format === Format.TypeFormat.Ref && field.referencePath) {
553
553
  const refValue = getValue(value.target, field.referencePath);
554
554
  return refValue;
555
555
  }
@@ -572,9 +572,8 @@ var defaultFeatures = {
572
572
  schemaEditable: false
573
573
  };
574
574
  var TableModel = class extends Resource2 {
575
- _view;
575
+ _object;
576
576
  _projection;
577
- _table;
578
577
  _visibleRange = signal3({
579
578
  start: {
580
579
  row: 0,
@@ -599,13 +598,13 @@ var TableModel = class extends Resource2 {
599
598
  _pinnedRows;
600
599
  _selection;
601
600
  _columnMeta;
602
- constructor({ view, schema, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
601
+ constructor({ object, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
603
602
  top: [],
604
603
  bottom: []
605
604
  }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
606
605
  super();
607
- this._view = view;
608
- this._projection = projection ?? new ProjectionModel2(schema, view.projection);
606
+ this._object = object;
607
+ this._projection = projection;
609
608
  this._projection.normalizeView();
610
609
  this._features = {
611
610
  ...defaultFeatures,
@@ -613,17 +612,21 @@ var TableModel = class extends Resource2 {
613
612
  };
614
613
  invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
615
614
  F: __dxlog_file,
616
- L: 148,
615
+ L: 137,
617
616
  S: this,
618
617
  A: [
619
618
  "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
620
619
  "'Single selection is not compatible with editable tables.'"
621
620
  ]
622
621
  });
623
- this._sorting = new TableSorting(this._rows, this._view, this._projection);
622
+ this._sorting = new TableSorting({
623
+ rows: this._rows,
624
+ getView: () => this.view,
625
+ projection: this._projection
626
+ });
624
627
  if (sorting.length > 0) {
625
- const [sort] = sorting;
626
- this._sorting.setSort(sort.fieldId, sort.direction);
628
+ const { fieldId, direction } = sorting[0];
629
+ this._sorting.setSort(fieldId, direction);
627
630
  }
628
631
  this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", initialSelection, () => this._onRowOrderChange?.());
629
632
  this._pinnedRows = pinnedRows;
@@ -636,22 +639,23 @@ var TableModel = class extends Resource2 {
636
639
  this._onRowAction = onRowAction;
637
640
  }
638
641
  get id() {
639
- return Obj2.getDXN(this._view).toString();
642
+ return Obj2.getDXN(this._object).toString();
640
643
  }
641
644
  get view() {
642
- return this._view;
643
- }
644
- get table() {
645
- invariant(this._table, "Model not initialized", {
645
+ const view = this._object.view.target;
646
+ invariant(view, "Table model not initialized", {
646
647
  F: __dxlog_file,
647
- L: 186,
648
+ L: 176,
648
649
  S: this,
649
650
  A: [
650
- "this._table",
651
- "'Model not initialized'"
651
+ "view",
652
+ "'Table model not initialized'"
652
653
  ]
653
654
  });
654
- return this._table;
655
+ return view;
656
+ }
657
+ get table() {
658
+ return this._object;
655
659
  }
656
660
  get projection() {
657
661
  return this._projection;
@@ -683,7 +687,7 @@ var TableModel = class extends Resource2 {
683
687
  get columnMeta() {
684
688
  invariant(this._columnMeta, void 0, {
685
689
  F: __dxlog_file,
686
- L: 225,
690
+ L: 219,
687
691
  S: this,
688
692
  A: [
689
693
  "this._columnMeta",
@@ -706,17 +710,7 @@ var TableModel = class extends Resource2 {
706
710
  // Initialisation
707
711
  //
708
712
  async _open() {
709
- const presentation = this._view.presentation.target ?? await this._view.presentation.load();
710
- invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
711
- F: __dxlog_file,
712
- L: 248,
713
- S: this,
714
- A: [
715
- "Obj.instanceOf(Table.Table, presentation)",
716
- ""
717
- ]
718
- });
719
- this._table = presentation;
713
+ await this._object.view.load();
720
714
  this.initializeColumnMeta();
721
715
  this.initializeEffects();
722
716
  await this._selection.open(this._ctx);
@@ -913,7 +907,7 @@ var TableModel = class extends Resource2 {
913
907
  }
914
908
  const { props } = this._projection.getFieldProjection(field.id);
915
909
  switch (props.format) {
916
- case FormatEnum2.Ref: {
910
+ case Format2.TypeFormat.Ref: {
917
911
  if (!field.referencePath) {
918
912
  return "";
919
913
  }
@@ -971,7 +965,7 @@ var TableModel = class extends Resource2 {
971
965
  const currentRow = this._rows.value[rowIdx];
972
966
  invariant(currentRow, "Invalid row index", {
973
967
  F: __dxlog_file,
974
- L: 525,
968
+ L: 516,
975
969
  S: this,
976
970
  A: [
977
971
  "currentRow",
@@ -980,10 +974,10 @@ var TableModel = class extends Resource2 {
980
974
  });
981
975
  const snapshot = getSnapshot(currentRow);
982
976
  setValue(snapshot, field.path, transformedValue);
983
- const schema = getSchema(currentRow);
977
+ const schema = Obj2.getSchema(currentRow);
984
978
  invariant(schema, void 0, {
985
979
  F: __dxlog_file,
986
- L: 531,
980
+ L: 522,
987
981
  S: this,
988
982
  A: [
989
983
  "schema",
@@ -995,7 +989,7 @@ var TableModel = class extends Resource2 {
995
989
  const error = validationResult[0];
996
990
  invariant(error.path === field.path, void 0, {
997
991
  F: __dxlog_file,
998
- L: 536,
992
+ L: 527,
999
993
  S: this,
1000
994
  A: [
1001
995
  "error.path === field.path",
@@ -1021,7 +1015,7 @@ var TableModel = class extends Resource2 {
1021
1015
  const field = fields[col];
1022
1016
  const { props } = this._projection.getFieldProjection(field.id);
1023
1017
  const transformedValue = editorTextToCellValue(props, value);
1024
- if (props.format === FormatEnum2.Ref && !isLiveObject(value)) {
1018
+ if (props.format === Format2.TypeFormat.Ref && !isLiveObject(value)) {
1025
1019
  return;
1026
1020
  }
1027
1021
  if (plane === "frozenRowsEnd") {
@@ -1117,14 +1111,14 @@ var TableModel = class extends Resource2 {
1117
1111
  };
1118
1112
  var editorTextToCellValue = (props, value) => {
1119
1113
  switch (props.format) {
1120
- case FormatEnum2.Ref: {
1114
+ case Format2.TypeFormat.Ref: {
1121
1115
  if (isLiveObject(value)) {
1122
- return Ref.make(value);
1116
+ return Ref2.make(value);
1123
1117
  } else {
1124
1118
  return value;
1125
1119
  }
1126
1120
  }
1127
- case FormatEnum2.SingleSelect: {
1121
+ case Format2.TypeFormat.SingleSelect: {
1128
1122
  const ids = extractTagIds(value);
1129
1123
  if (ids && ids.length > 0) {
1130
1124
  return ids[0];
@@ -1132,7 +1126,7 @@ var editorTextToCellValue = (props, value) => {
1132
1126
  return value;
1133
1127
  }
1134
1128
  }
1135
- case FormatEnum2.MultiSelect: {
1129
+ case Format2.TypeFormat.MultiSelect: {
1136
1130
  const ids = extractTagIds(value);
1137
1131
  return ids || value;
1138
1132
  }
@@ -1216,7 +1210,7 @@ var ModalController = class {
1216
1210
  import { signal as signal5 } from "@preact/signals-core";
1217
1211
  import * as Predicate from "effect/Predicate";
1218
1212
  import { Obj as Obj3 } from "@dxos/echo";
1219
- import { FormatEnum as FormatEnum3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1213
+ import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
1220
1214
  import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1221
1215
  import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1222
1216
  import { mx } from "@dxos/react-ui-theme";
@@ -1303,12 +1297,12 @@ var TablePresentation = class {
1303
1297
  return "";
1304
1298
  }
1305
1299
  switch (props.format) {
1306
- case FormatEnum3.Boolean:
1307
- case FormatEnum3.SingleSelect:
1308
- case FormatEnum3.MultiSelect: {
1300
+ case Format3.TypeFormat.Boolean:
1301
+ case Format3.TypeFormat.SingleSelect:
1302
+ case Format3.TypeFormat.MultiSelect: {
1309
1303
  return "";
1310
1304
  }
1311
- case FormatEnum3.Ref: {
1305
+ case Format3.TypeFormat.Ref: {
1312
1306
  if (!field.referencePath) {
1313
1307
  return "";
1314
1308
  }
@@ -1361,14 +1355,14 @@ var TablePresentation = class {
1361
1355
  cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1362
1356
  }
1363
1357
  }
1364
- if (props.format === FormatEnum3.Ref && props.referenceSchema) {
1358
+ if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
1365
1359
  const targetObj = getValue3(obj, field.path)?.target;
1366
1360
  if (targetObj) {
1367
1361
  const dxn = Obj3.getDXN(targetObj)?.toString();
1368
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>`;
1369
1363
  }
1370
1364
  }
1371
- if (props.format === FormatEnum3.Boolean) {
1365
+ if (props.format === Format3.TypeFormat.Boolean) {
1372
1366
  const value = getValue3(obj, field.path);
1373
1367
  cell.accessoryHtml = tableControls.switch.render({
1374
1368
  colIndex,
@@ -1377,7 +1371,7 @@ var TablePresentation = class {
1377
1371
  });
1378
1372
  cell.readonly = "no-text-select";
1379
1373
  }
1380
- if (props.format === FormatEnum3.SingleSelect) {
1374
+ if (props.format === Format3.TypeFormat.SingleSelect) {
1381
1375
  const value = getValue3(obj, field.path);
1382
1376
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1383
1377
  if (options) {
@@ -1387,7 +1381,7 @@ var TablePresentation = class {
1387
1381
  }
1388
1382
  }
1389
1383
  }
1390
- if (props.format === FormatEnum3.MultiSelect) {
1384
+ if (props.format === Format3.TypeFormat.MultiSelect) {
1391
1385
  const values = getValue3(obj, field.path);
1392
1386
  const options = this.model.projection.getFieldProjection(field.id).props.options;
1393
1387
  if (options && values && values.length > 0) {
@@ -1646,31 +1640,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
1646
1640
  }
1647
1641
  };
1648
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
+
1649
1678
  // src/hooks/useTableModel.ts
1650
1679
  import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
1651
1680
  import { effect as effect3 } from "@preact/signals-core";
1652
1681
  import orderBy2 from "lodash.orderby";
1653
- import { useEffect, useMemo, useState } from "react";
1654
- import { Obj as Obj4 } from "@dxos/echo";
1682
+ import { useEffect, useMemo as useMemo2, useState } from "react";
1683
+ import { Obj as Obj5 } from "@dxos/echo";
1655
1684
  import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
1656
1685
  import { isNonNullable } from "@dxos/util";
1657
- var useTableModel = ({ view, schema, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1686
+ var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
1658
1687
  var _effect = _useSignals();
1659
1688
  try {
1660
- const selected = useSelected(view && Obj4.getDXN(view).toString(), "multi");
1661
- const initialSelection = useMemo(() => selected, [
1662
- view
1689
+ const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
1690
+ const initialSelection = useMemo2(() => selected, [
1691
+ object
1663
1692
  ]);
1664
1693
  const [model, setModel] = useState();
1665
1694
  useEffect(() => {
1666
- if (!view || !schema) {
1695
+ if (!object || !projection) {
1667
1696
  return;
1668
1697
  }
1669
1698
  let model2;
1670
1699
  const t = setTimeout(async () => {
1671
1700
  model2 = new TableModel({
1672
- view,
1673
- schema,
1701
+ object,
1674
1702
  projection,
1675
1703
  features,
1676
1704
  rowActions,
@@ -1686,8 +1714,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1686
1714
  void model2?.close();
1687
1715
  };
1688
1716
  }, [
1689
- view,
1690
- schema,
1717
+ object,
1691
1718
  projection,
1692
1719
  features,
1693
1720
  rowActions,
@@ -1734,26 +1761,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
1734
1761
  }
1735
1762
  };
1736
1763
 
1737
- // src/hooks/useAddRow.ts
1738
- import { useCallback } from "react";
1739
- import { Obj as Obj5 } from "@dxos/echo";
1740
- var useAddRow = ({ space, schema }) => {
1741
- return useCallback((data) => {
1742
- if (space && schema) {
1743
- try {
1744
- space.db.add(Obj5.make(schema, data ?? {}));
1745
- return "final";
1746
- } catch (error) {
1747
- return "draft";
1748
- }
1749
- }
1750
- return "final";
1751
- }, [
1752
- space,
1753
- schema
1754
- ]);
1755
- };
1756
-
1757
1764
  export {
1758
1765
  getBaseSchema,
1759
1766
  makeDynamicTable,
@@ -1769,7 +1776,8 @@ export {
1769
1776
  ModalController,
1770
1777
  TablePresentation,
1771
1778
  cellClassesForRowSelection,
1772
- useTableModel,
1773
- useAddRow
1779
+ useAddRow,
1780
+ useProjectionModel,
1781
+ useTableModel
1774
1782
  };
1775
- //# sourceMappingURL=chunk-GS2UNGJK.mjs.map
1783
+ //# sourceMappingURL=chunk-V7A7ZA5E.mjs.map