@dxos/react-ui-table 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (129) hide show
  1. package/dist/lib/browser/{chunk-G7MGPBSR.mjs → chunk-I5IFW7UF.mjs} +633 -663
  2. package/dist/lib/browser/chunk-I5IFW7UF.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
  4. package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1131 -999
  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 +29 -41
  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-LD5JEBA6.mjs → chunk-DDJKYJFY.mjs} +633 -662
  12. package/dist/lib/node-esm/chunk-DDJKYJFY.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
  14. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1131 -999
  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 +29 -41
  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 +4 -18
  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 +12 -9
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  32. package/dist/types/src/components/Table/Table.d.ts +8 -8
  33. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  34. package/dist/types/src/components/Table/Table.stories.d.ts +71 -5
  35. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  37. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -12
  38. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +4 -4
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  43. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +4 -4
  44. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  45. package/dist/types/src/components/testing.d.ts +22 -15
  46. package/dist/types/src/components/testing.d.ts.map +1 -1
  47. package/dist/types/src/hooks/index.d.ts +2 -1
  48. package/dist/types/src/hooks/index.d.ts.map +1 -1
  49. package/dist/types/src/hooks/useAddRow.d.ts +5 -6
  50. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  51. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  52. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  53. package/dist/types/src/hooks/useTableModel.d.ts +8 -8
  54. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  55. package/dist/types/src/model/modal-controller.d.ts +5 -1
  56. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  57. package/dist/types/src/model/selection-model.d.ts +17 -8
  58. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  59. package/dist/types/src/model/table-model.d.ts +102 -23
  60. package/dist/types/src/model/table-model.d.ts.map +1 -1
  61. package/dist/types/src/model/table-presentation.d.ts +3 -1
  62. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  63. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  64. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  65. package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
  66. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  67. package/dist/types/src/translations.d.ts +4 -4
  68. package/dist/types/src/translations.d.ts.map +1 -1
  69. package/dist/types/src/types/Table.d.ts +31 -0
  70. package/dist/types/src/types/Table.d.ts.map +1 -0
  71. package/dist/types/src/types/index.d.ts +1 -1
  72. package/dist/types/src/types/index.d.ts.map +1 -1
  73. package/dist/types/src/util/dynamic-table.d.ts +13 -11
  74. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  75. package/dist/types/src/util/index.d.ts +2 -0
  76. package/dist/types/src/util/index.d.ts.map +1 -1
  77. package/dist/types/src/util/query-ast.d.ts +7 -0
  78. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  79. package/dist/types/src/util/sort.d.ts +12 -0
  80. package/dist/types/src/util/sort.d.ts.map +1 -0
  81. package/dist/types/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +53 -53
  83. package/src/components/Table/ColumnActionsMenu.tsx +10 -6
  84. package/src/components/Table/ColumnSettings.tsx +6 -6
  85. package/src/components/Table/DynamicTable.stories.tsx +12 -13
  86. package/src/components/Table/DynamicTable.tsx +21 -14
  87. package/src/components/Table/Relations.stories.tsx +35 -39
  88. package/src/components/Table/RowActionsMenu.tsx +24 -15
  89. package/src/components/Table/Table.stories.tsx +71 -75
  90. package/src/components/Table/Table.tsx +335 -305
  91. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  92. package/src/components/TableCellEditor/FormCellEditor.tsx +110 -133
  93. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +16 -12
  94. package/src/components/TableCellEditor/TableCellEditor.tsx +31 -31
  95. package/src/components/TableToolbar/TableToolbar.tsx +44 -31
  96. package/src/components/testing.ts +38 -12
  97. package/src/hooks/index.ts +2 -1
  98. package/src/hooks/useAddRow.ts +8 -10
  99. package/src/hooks/useProjectionModel.ts +39 -0
  100. package/src/hooks/useTableModel.ts +35 -33
  101. package/src/model/modal-controller.ts +23 -12
  102. package/src/model/selection-model.ts +75 -44
  103. package/src/model/table-model.test.ts +82 -54
  104. package/src/model/table-model.ts +428 -163
  105. package/src/model/table-presentation.test.ts +59 -49
  106. package/src/model/table-presentation.ts +31 -26
  107. package/src/playwright/TableManager.ts +5 -5
  108. package/src/playwright/playwright.config.ts +1 -1
  109. package/src/playwright/smoke.spec.ts +8 -5
  110. package/src/testing/useTestTableModel.ts +44 -37
  111. package/src/translations.ts +3 -3
  112. package/src/types/Table.ts +90 -0
  113. package/src/types/index.ts +1 -1
  114. package/src/util/dynamic-table.ts +39 -27
  115. package/src/util/index.ts +2 -0
  116. package/src/util/query-ast.ts +19 -0
  117. package/src/util/sort.ts +90 -0
  118. package/dist/lib/browser/chunk-4K7JPALT.mjs +0 -66
  119. package/dist/lib/browser/chunk-4K7JPALT.mjs.map +0 -7
  120. package/dist/lib/browser/chunk-G7MGPBSR.mjs.map +0 -7
  121. package/dist/lib/node-esm/chunk-LD5JEBA6.mjs.map +0 -7
  122. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs +0 -67
  123. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +0 -7
  124. package/dist/types/src/model/table-sorting.d.ts +0 -52
  125. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  126. package/dist/types/src/types/schema.d.ts +0 -28
  127. package/dist/types/src/types/schema.d.ts.map +0 -1
  128. package/src/model/table-sorting.ts +0 -225
  129. package/src/types/schema.ts +0 -73
@@ -0,0 +1,90 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Match from 'effect/Match';
6
+ import * as Schema from 'effect/Schema';
7
+ import * as SchemaAST from 'effect/SchemaAST';
8
+
9
+ import { Obj, Ref, Type } from '@dxos/echo';
10
+ import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
11
+ import { View, ViewAnnotation } from '@dxos/schema';
12
+
13
+ export const Table = Schema.Struct({
14
+ name: Schema.String.pipe(Schema.optional),
15
+
16
+ view: Type.Ref(View.View).pipe(FormInputAnnotation.set(false)),
17
+
18
+ sizes: Schema.Record({
19
+ // TODO(wittjosiah): Should be JsonPath.
20
+ key: Schema.String,
21
+ value: Schema.Number,
22
+ }).pipe(Schema.mutable, FormInputAnnotation.set(false)),
23
+ }).pipe(
24
+ Type.object({
25
+ typename: 'dxos.org/type/Table',
26
+ version: '0.2.0',
27
+ }),
28
+ LabelAnnotation.set(['name']),
29
+ ViewAnnotation.set(true),
30
+ );
31
+
32
+ export interface Table extends Schema.Schema.Type<typeof Table> {}
33
+
34
+ type MakeProps = {
35
+ name?: string;
36
+ sizes?: Record<string, number>;
37
+ view: View.View;
38
+ /** Required to auto-size columns. */
39
+ jsonSchema?: JsonSchemaType;
40
+ };
41
+
42
+ /**
43
+ * Make a table as a view of a data set.
44
+ */
45
+ export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
46
+ const table = Obj.make(Table, { name, view: Ref.make(view), sizes } as Obj.MakeProps<typeof Table>);
47
+
48
+ // Preset sizes.
49
+ if (jsonSchema) {
50
+ const schema = Type.toEffectSchema(jsonSchema);
51
+ const properties = SchemaAST.getPropertySignatures(schema.ast);
52
+ for (const property of properties) {
53
+ const name = property.name.toString() as JsonPath;
54
+ if (sizes?.[name]) {
55
+ table.sizes[name] = sizes[name];
56
+ continue;
57
+ }
58
+
59
+ Match.type<SchemaAST.AST>().pipe(
60
+ Match.when({ _tag: 'BooleanKeyword' }, () => {
61
+ table.sizes[name] = 100;
62
+ }),
63
+ Match.when({ _tag: 'NumberKeyword' }, () => {
64
+ table.sizes[name] = 100;
65
+ }),
66
+ Match.orElse(() => {
67
+ // Noop.
68
+ }),
69
+ )(property.type);
70
+ }
71
+ }
72
+
73
+ return table;
74
+ };
75
+
76
+ //
77
+ // V1
78
+ //
79
+
80
+ export const TableV1 = Schema.Struct({
81
+ sizes: Schema.Record({
82
+ key: Schema.String,
83
+ value: Schema.Number,
84
+ }).pipe(Schema.mutable),
85
+ }).pipe(
86
+ Type.object({
87
+ typename: 'dxos.org/type/Table',
88
+ version: '0.1.0',
89
+ }),
90
+ );
@@ -2,4 +2,4 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * as Table from './schema';
5
+ export * as Table from './Table';
@@ -2,17 +2,14 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import type * as Schema from 'effect/Schema';
5
+ import { type Registry } from '@effect-atom/atom-react';
6
6
 
7
- import { Filter, Obj, Query } from '@dxos/echo';
8
- import { getTypename, toJsonSchema } from '@dxos/echo/internal';
9
- import type { JsonSchemaType } from '@dxos/echo/internal';
7
+ import { Filter, type JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type } from '@dxos/echo';
10
8
  import {
11
- type DataType,
12
9
  ProjectionModel,
13
10
  type SchemaPropertyDefinition,
14
- type SortDirectionType,
15
- createView,
11
+ View,
12
+ createDirectChangeCallback,
16
13
  getSchemaFromPropertyDefinitions,
17
14
  } from '@dxos/schema';
18
15
 
@@ -22,7 +19,7 @@ import { Table } from '../types';
22
19
  type PropertyDisplayProps = {
23
20
  size: number;
24
21
  title: string;
25
- sort: SortDirectionType;
22
+ sort: QueryAST.OrderDirection;
26
23
  };
27
24
 
28
25
  export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<PropertyDisplayProps>;
@@ -32,21 +29,21 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
32
29
  */
33
30
  // TODO(burdon): Remove variance.
34
31
  export const getBaseSchema = ({
32
+ schema,
35
33
  typename,
36
34
  properties,
37
35
  jsonSchema,
38
- schema,
39
36
  }: {
37
+ schema?: Type.Entity.Any;
40
38
  typename?: string;
41
39
  properties?: TablePropertyDefinition[];
42
- jsonSchema?: JsonSchemaType;
43
- schema?: Schema.Schema.AnyNoContext;
44
- }): { typename: string; jsonSchema: JsonSchemaType } => {
40
+ jsonSchema?: JsonSchema.JsonSchema;
41
+ }): { typename: string; jsonSchema: JsonSchema.JsonSchema } => {
45
42
  if (typename && properties) {
46
43
  const schema = getSchemaFromPropertyDefinitions(typename, properties);
47
44
  return { typename: schema.typename, jsonSchema: schema.jsonSchema };
48
45
  } else if (schema) {
49
- return { typename: getTypename(schema)!, jsonSchema: toJsonSchema(schema) };
46
+ return { typename: Type.getTypename(schema)!, jsonSchema: Type.toJsonSchema(schema) };
50
47
  } else if (typename && jsonSchema) {
51
48
  return { typename, jsonSchema };
52
49
  } else {
@@ -55,40 +52,49 @@ export const getBaseSchema = ({
55
52
  };
56
53
 
57
54
  export const makeDynamicTable = ({
55
+ registry,
58
56
  jsonSchema,
59
57
  properties,
60
58
  }: {
61
- jsonSchema: JsonSchemaType;
59
+ registry: Registry.Registry;
60
+ jsonSchema: JsonSchema.JsonSchema;
62
61
  properties?: TablePropertyDefinition[];
63
- }): { projection: ProjectionModel; view: DataType.View } => {
64
- const table = Obj.make(Table.Table, { sizes: {} });
65
- const view = createView({
62
+ }): { projection: ProjectionModel; object: Table.Table } => {
63
+ const view = View.make({
66
64
  query: Query.select(Filter.everything()),
67
65
  jsonSchema,
68
- presentation: table,
69
66
  ...(properties && { fields: properties.map((property) => property.name) }),
70
67
  });
68
+ const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
71
69
 
72
- const projection = new ProjectionModel(jsonSchema, view.projection);
70
+ // Use direct change callback for in-memory objects (non-ECHO backed).
71
+ const projection = new ProjectionModel({
72
+ registry,
73
+ view,
74
+ baseSchema: jsonSchema,
75
+ change: createDirectChangeCallback(view.projection, jsonSchema),
76
+ });
73
77
  projection.normalizeView();
74
- if (properties && projection.fields) {
75
- setProperties(view, projection, table, properties);
78
+ if (properties && projection.getFields()) {
79
+ setProperties(view, projection, object, properties);
76
80
  }
77
81
 
78
- return { projection, view };
82
+ return { projection, object };
79
83
  };
80
84
 
81
85
  const setProperties = (
82
- view: DataType.View,
86
+ view: View.View,
83
87
  projection: ProjectionModel,
84
88
  table: Table.Table,
85
89
  properties: TablePropertyDefinition[],
86
90
  ) => {
87
91
  for (const property of properties) {
88
- const field = projection.fields.find((field) => field.path === property.name);
92
+ const field = projection.getFields().find((field) => field.path === property.name);
89
93
  if (field) {
90
94
  if (property.size !== undefined) {
91
- table.sizes[field.path] = property.size;
95
+ Obj.change(table, (t) => {
96
+ t.sizes[field.path] = property.size!;
97
+ });
92
98
  }
93
99
 
94
100
  if (property.title !== undefined) {
@@ -100,8 +106,14 @@ const setProperties = (
100
106
  }
101
107
 
102
108
  if (property.sort) {
103
- const fieldId = field.id;
104
- view.sort = [{ fieldId, direction: property.sort }];
109
+ // Apply sort to query instead of deprecated view.sort
110
+ const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
111
+ // Use any type parameter since we're working with dynamic field paths
112
+ const newQuery = currentQuery.orderBy(Order.property<any>(field.path as string, property.sort));
113
+ Obj.change(view, (v) => {
114
+ // Type assertion needed because Query AST types have some variance issues.
115
+ v.query.ast = newQuery.ast as typeof v.query.ast;
116
+ });
105
117
  }
106
118
  }
107
119
  }
package/src/util/index.ts CHANGED
@@ -3,7 +3,9 @@
3
3
  //
4
4
 
5
5
  export * from './dynamic-table';
6
+ export * from './query-ast';
6
7
  export * from './signals';
8
+ export * from './sort';
7
9
  export * from './table-buttons';
8
10
  export * from './table-controls';
9
11
  export * from './schema';
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type QueryAST } from '@dxos/echo';
6
+
7
+ /**
8
+ * Extracts order clauses from a query AST.
9
+ * Handles nested structures (options, order, etc.).
10
+ */
11
+ export const extractOrder = (queryAst: QueryAST.Query): readonly QueryAST.Order[] | undefined => {
12
+ if (queryAst.type === 'order') {
13
+ return queryAst.order;
14
+ }
15
+ if (queryAst.type === 'options') {
16
+ return extractOrder(queryAst.query);
17
+ }
18
+ return undefined;
19
+ };
@@ -0,0 +1,90 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Format, type QueryAST } from '@dxos/echo';
6
+
7
+ /**
8
+ * Gets a normalized sort value for a given value and format.
9
+ * This ensures consistent sorting behavior across different data types.
10
+ */
11
+ export const getSortValue = (value: any, format: Format.TypeFormat): any => {
12
+ // Handle null/undefined
13
+ if (value === undefined || value === null) {
14
+ return null;
15
+ }
16
+
17
+ // Handle dates chronologically if schema indicates date format
18
+ const isDateFormat = format === Format.TypeFormat.DateTime || format === Format.TypeFormat.Date;
19
+ if (isDateFormat) {
20
+ const date = new Date(value);
21
+ if (!isNaN(date.getTime())) {
22
+ return date.getTime();
23
+ }
24
+ // Fallback to string if date parsing fails
25
+ return String(value);
26
+ }
27
+
28
+ // Handle numbers if schema indicates number format
29
+ if (
30
+ format === Format.TypeFormat.Number ||
31
+ format === Format.TypeFormat.Integer ||
32
+ format === Format.TypeFormat.Currency ||
33
+ format === Format.TypeFormat.Percent ||
34
+ format === Format.TypeFormat.Duration
35
+ ) {
36
+ const num = typeof value === 'number' ? value : Number(value);
37
+ if (!isNaN(num)) {
38
+ return num;
39
+ }
40
+ // Fallback to string if number parsing fails
41
+ return String(value);
42
+ }
43
+
44
+ // Default to string comparison
45
+ if (typeof value === 'string') {
46
+ return value;
47
+ }
48
+ if (typeof value === 'number') {
49
+ return value;
50
+ }
51
+
52
+ // Fallback to string representation
53
+ return String(value);
54
+ };
55
+
56
+ /**
57
+ * Compares two values for sorting based on the field format.
58
+ * Handles dates, numbers, and strings appropriately.
59
+ */
60
+ export const compareValues = (
61
+ aValue: any,
62
+ bValue: any,
63
+ format: Format.TypeFormat,
64
+ direction: QueryAST.OrderDirection,
65
+ ): number => {
66
+ // Handle null/undefined values - nulls sort to the end
67
+ if (aValue === undefined || aValue === null) {
68
+ return bValue === undefined || bValue === null ? 0 : 1;
69
+ }
70
+ if (bValue === undefined || bValue === null) {
71
+ return -1;
72
+ }
73
+
74
+ // Get normalized sort values
75
+ const aSortValue = getSortValue(aValue, format);
76
+ const bSortValue = getSortValue(bValue, format);
77
+
78
+ // Compare based on type
79
+ let comparison = 0;
80
+ if (typeof aSortValue === 'number' && typeof bSortValue === 'number') {
81
+ comparison = aSortValue - bSortValue;
82
+ } else if (typeof aSortValue === 'string' && typeof bSortValue === 'string') {
83
+ comparison = aSortValue.localeCompare(bSortValue);
84
+ } else {
85
+ // Mixed types - convert both to strings
86
+ comparison = String(aSortValue).localeCompare(String(bSortValue));
87
+ }
88
+
89
+ return direction === 'desc' ? -comparison : comparison;
90
+ };
@@ -1,66 +0,0 @@
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/schema.ts
8
- var schema_exports = {};
9
- __export(schema_exports, {
10
- Table: () => Table,
11
- make: () => make,
12
- makeView: () => makeView
13
- });
14
- import * as Match from "effect/Match";
15
- import * as Schema from "effect/Schema";
16
- import { Obj, Type } from "@dxos/echo";
17
- import { JsonPath, toEffectSchema } from "@dxos/echo/internal";
18
- import { ViewAnnotation } from "@dxos/echo/internal";
19
- import { createViewFromSpace, getSchemaProperties } from "@dxos/schema";
20
- var Table = Schema.Struct({
21
- sizes: Schema.Record({
22
- key: JsonPath,
23
- value: Schema.Number
24
- }).pipe(Schema.mutable)
25
- }).pipe(Type.Obj({
26
- typename: "dxos.org/type/Table",
27
- version: "0.1.0"
28
- }), ViewAnnotation.set(true));
29
- var make = (props = {}) => Obj.make(Table, {
30
- sizes: {},
31
- ...props
32
- });
33
- var makeView = async ({ sizes, ...props }) => {
34
- const table = Obj.make(Table, {
35
- sizes: {}
36
- });
37
- const { jsonSchema, view } = await createViewFromSpace({
38
- ...props,
39
- presentation: table
40
- });
41
- const schema = toEffectSchema(jsonSchema);
42
- const shouldIncludeId = props.fields?.find((field) => field === "id") !== void 0;
43
- const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
44
- for (const property of properties) {
45
- if (sizes?.[property.name]) {
46
- table.sizes[property.name] = sizes[property.name];
47
- continue;
48
- }
49
- Match.type().pipe(Match.when("boolean", () => {
50
- table.sizes[property.name] = 100;
51
- }), Match.when("number", () => {
52
- table.sizes[property.name] = 100;
53
- }), Match.orElse(() => {
54
- }))(property.type);
55
- }
56
- return {
57
- jsonSchema,
58
- schema,
59
- view
60
- };
61
- };
62
-
63
- export {
64
- schema_exports
65
- };
66
- //# sourceMappingURL=chunk-4K7JPALT.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/schema.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { JsonPath, type JsonSchemaType, toEffectSchema } from '@dxos/echo/internal';\nimport { ViewAnnotation } from '@dxos/echo/internal';\nimport { type SimpleType } from '@dxos/effect';\nimport { type CreateViewFromSpaceProps, type DataType, createViewFromSpace, getSchemaProperties } from '@dxos/schema';\n\nexport const Table = Schema.Struct({\n sizes: Schema.Record({\n key: JsonPath,\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 ViewAnnotation.set(true),\n);\n\nexport type Table = Schema.Schema.Type<typeof Table>;\n\n/**\n * Make a table view.\n */\nexport const make = (props: Partial<Obj.MakeProps<typeof Table>> = {}) => Obj.make(Table, { sizes: {}, ...props });\n\ntype MakeViewProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {\n sizes?: Record<string, number>;\n};\n\nexport const makeView = async ({\n sizes,\n ...props\n}: MakeViewProps): Promise<{\n jsonSchema: JsonSchemaType;\n view: DataType.View;\n schema: ReturnType<typeof toEffectSchema>;\n}> => {\n const table = Obj.make(Table, { sizes: {} });\n const { jsonSchema, view } = await createViewFromSpace({ ...props, presentation: table });\n\n // Preset sizes.\n const schema = toEffectSchema(jsonSchema);\n const shouldIncludeId = props.fields?.find((field) => field === 'id') !== undefined;\n const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);\n for (const property of properties) {\n if (sizes?.[property.name]) {\n table.sizes[property.name as JsonPath] = sizes[property.name];\n continue;\n }\n\n Match.type<SimpleType>().pipe(\n Match.when('boolean', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.when('number', () => {\n table.sizes[property.name as JsonPath] = 100;\n }),\n Match.orElse(() => {\n // Noop.\n }),\n )(property.type);\n }\n\n return { jsonSchema, schema, view };\n};\n"],
5
- "mappings": ";;;;;;;AAAA;;;;;;AAIA,YAAYA,WAAW;AACvB,YAAYC,YAAY;AAExB,SAASC,KAAKC,YAAY;AAC1B,SAASC,UAA+BC,sBAAsB;AAC9D,SAASC,sBAAsB;AAE/B,SAAuDC,qBAAqBC,2BAA2B;AAEhG,IAAMC,QAAeC,cAAO;EACjCC,OAAcC,cAAO;IACnBC,KAAKC;IACLC,OAAcC;EAChB,CAAA,EAAGC,KAAYC,cAAO;AACxB,CAAA,EAAGD,KACDE,KAAKC,IAAI;EACPC,UAAU;EACVC,SAAS;AACX,CAAA,GACAC,eAAeC,IAAI,IAAA,CAAA;AAQd,IAAMC,OAAO,CAACC,QAA8C,CAAC,MAAMN,IAAIK,KAAKhB,OAAO;EAAEE,OAAO,CAAC;EAAG,GAAGe;AAAM,CAAA;AAMzG,IAAMC,WAAW,OAAO,EAC7BhB,OACA,GAAGe,MAAAA,MACW;AAKd,QAAME,QAAQR,IAAIK,KAAKhB,OAAO;IAAEE,OAAO,CAAC;EAAE,CAAA;AAC1C,QAAM,EAAEkB,YAAYC,KAAI,IAAK,MAAMC,oBAAoB;IAAE,GAAGL;IAAOM,cAAcJ;EAAM,CAAA;AAGvF,QAAMK,SAASC,eAAeL,UAAAA;AAC9B,QAAMM,kBAAkBT,MAAMU,QAAQC,KAAK,CAACC,UAAUA,UAAU,IAAA,MAAUC;AAC1E,QAAMC,aAAaC,oBAAoBR,OAAOS,KAAK,CAAC,GAAGP,eAAAA;AACvD,aAAWQ,YAAYH,YAAY;AACjC,QAAI7B,QAAQgC,SAASC,IAAI,GAAG;AAC1BhB,YAAMjB,MAAMgC,SAASC,IAAI,IAAgBjC,MAAMgC,SAASC,IAAI;AAC5D;IACF;AAEAC,IAAMC,WAAI,EAAe7B,KACjB8B,WAAK,WAAW,MAAA;AACpBnB,YAAMjB,MAAMgC,SAASC,IAAI,IAAgB;IAC3C,CAAA,GACMG,WAAK,UAAU,MAAA;AACnBnB,YAAMjB,MAAMgC,SAASC,IAAI,IAAgB;IAC3C,CAAA,GACMI,aAAO,MAAA;IAEb,CAAA,CAAA,EACAL,SAASG,IAAI;EACjB;AAEA,SAAO;IAAEjB;IAAYI;IAAQH;EAAK;AACpC;",
6
- "names": ["Match", "Schema", "Obj", "Type", "JsonPath", "toEffectSchema", "ViewAnnotation", "createViewFromSpace", "getSchemaProperties", "Table", "Struct", "sizes", "Record", "key", "JsonPath", "value", "Number", "pipe", "mutable", "Type", "Obj", "typename", "version", "ViewAnnotation", "set", "make", "props", "makeView", "table", "jsonSchema", "view", "createViewFromSpace", "presentation", "schema", "toEffectSchema", "shouldIncludeId", "fields", "find", "field", "undefined", "properties", "getSchemaProperties", "ast", "property", "name", "Match", "type", "when", "orElse"]
7
- }