@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
@@ -2,40 +2,52 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useCallback, useMemo, useRef } from 'react';
5
+ import type * as Schema from 'effect/Schema';
6
+ import { type RefObject, useCallback, useMemo, useRef } from 'react';
6
7
 
7
- import { isMutable, toJsonSchema } from '@dxos/echo-schema';
8
+ import { isMutable } from '@dxos/echo/internal';
8
9
  import { useGlobalFilteredObjects } from '@dxos/plugin-search';
9
10
  import { faker } from '@dxos/random';
10
- import { useClient } from '@dxos/react-client';
11
- import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
11
+ import { type Client, useClient } from '@dxos/react-client';
12
+ import { Filter, type Space, useQuery, useSchema } from '@dxos/react-client/echo';
12
13
  import { useClientProvider } from '@dxos/react-client/testing';
13
- import { DataType, ProjectionModel } from '@dxos/schema';
14
+ import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
14
15
 
15
16
  import { type TableController } from '../components';
16
- import { useAddRow, useTableModel } from '../hooks';
17
- import { TablePresentation } from '../model';
17
+ import { useAddRow, useProjectionModel, useTableModel } from '../hooks';
18
+ import { type TableModel, TablePresentation } from '../model';
19
+ import { Table } from '../types';
18
20
 
19
21
  faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
20
22
 
23
+ export type TestTableModel = {
24
+ schema: Schema.Schema.AnyNoContext | undefined;
25
+ table: Table.Table | undefined;
26
+ projection: ProjectionModel | undefined;
27
+ tableRef: RefObject<TableController | null>;
28
+ model: TableModel | undefined;
29
+ presentation: TablePresentation | undefined;
30
+ space: Space | undefined;
31
+ client: Client | undefined;
32
+ handleInsertRow: () => void;
33
+ handleSaveView: () => void;
34
+ handleDeleteRows: (rowIndex: number, objects: any[]) => void;
35
+ handleDeleteColumn: (fieldId: string) => void;
36
+ };
37
+
21
38
  /**
22
39
  * Custom hook to create and manage a test table model for storybook demonstrations.
23
40
  * Provides table data, schema, and handlers for table operations.
24
41
  */
25
- export const useTestTableModel = () => {
42
+ export const useTestTableModel = (): TestTableModel => {
26
43
  const client = useClient();
27
44
  const { space } = useClientProvider();
28
45
 
29
- const views = useQuery(space, Filter.type(DataType.View));
30
- const view = useMemo(() => views.at(0), [views]);
31
- const schema = useSchema(client, space, view?.query.typename);
32
- const jsonSchema = useMemo(() => (schema ? toJsonSchema(schema) : undefined), [schema]);
33
-
34
- const projection = useMemo(() => {
35
- if (schema && view?.projection) {
36
- return new ProjectionModel(toJsonSchema(schema), view.projection);
37
- }
38
- }, [schema, view?.projection]);
46
+ const tables = useQuery(space, Filter.type(Table.Table));
47
+ const table = tables.at(0);
48
+ const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
49
+ const schema = useSchema(client, space, typename);
50
+ const projection = useProjectionModel(schema, table);
39
51
 
40
52
  const features = useMemo(
41
53
  () => ({
@@ -79,8 +91,7 @@ export const useTestTableModel = () => {
79
91
  );
80
92
 
81
93
  const model = useTableModel({
82
- view,
83
- schema: jsonSchema,
94
+ object: table,
84
95
  projection,
85
96
  features,
86
97
  rows: filteredObjects,
@@ -94,7 +105,7 @@ export const useTestTableModel = () => {
94
105
  const handleInsertRow = useCallback(() => {
95
106
  const insertResult = model?.insertRow();
96
107
  tableRef.current?.handleInsertRowResult?.(insertResult);
97
- }, [model, tableRef.current]);
108
+ }, [model]);
98
109
 
99
110
  const handleSaveView = useCallback(() => {
100
111
  model?.saveView();
@@ -108,7 +119,7 @@ export const useTestTableModel = () => {
108
119
 
109
120
  return {
110
121
  schema,
111
- view,
122
+ table,
112
123
  projection,
113
124
  tableRef,
114
125
  model,
@@ -14,8 +14,8 @@ export const translations = [
14
14
  'create object label': 'Create table',
15
15
  'table name placeholder': 'Table name',
16
16
  'settings title': 'Table settings',
17
- 'table schema label': 'Record type',
18
- 'new schema': 'New record type',
17
+ 'table schema label': 'Type',
18
+ 'new schema': 'New type',
19
19
  'continue label': 'Continue',
20
20
  'create stack section label': 'Create table',
21
21
  'add row label': 'Add row',
@@ -0,0 +1,89 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import * as Match from 'effect/Match';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { Obj, Ref, Type } from '@dxos/echo';
9
+ import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
10
+ import { type SimpleType } from '@dxos/effect';
11
+ import { View, ViewAnnotation, getSchemaProperties } from '@dxos/schema';
12
+
13
+ const TableSchema = 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.Obj({
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 TableSchema> {}
33
+ export interface TableEncoded extends Schema.Schema.Encoded<typeof TableSchema> {}
34
+ export const Table: Schema.Schema<Table, TableEncoded> = TableSchema;
35
+
36
+ type MakeProps = Omit<Partial<Obj.MakeProps<typeof Table>>, 'view'> & {
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 });
47
+
48
+ // Preset sizes.
49
+ if (jsonSchema) {
50
+ const schema = Type.toEffectSchema(jsonSchema);
51
+ const properties = getSchemaProperties(schema.ast, {});
52
+ for (const property of properties) {
53
+ if (sizes?.[property.name]) {
54
+ table.sizes[property.name] = sizes[property.name];
55
+ continue;
56
+ }
57
+
58
+ Match.type<SimpleType>().pipe(
59
+ Match.when('boolean', () => {
60
+ table.sizes[property.name as JsonPath] = 100;
61
+ }),
62
+ Match.when('number', () => {
63
+ table.sizes[property.name as JsonPath] = 100;
64
+ }),
65
+ Match.orElse(() => {
66
+ // Noop.
67
+ }),
68
+ )(property.type);
69
+ }
70
+ }
71
+
72
+ return table;
73
+ };
74
+
75
+ //
76
+ // V1
77
+ //
78
+
79
+ export const TableV1 = Schema.Struct({
80
+ sizes: Schema.Record({
81
+ key: Schema.String,
82
+ value: Schema.Number,
83
+ }).pipe(Schema.mutable),
84
+ }).pipe(
85
+ Type.Obj({
86
+ typename: 'dxos.org/type/Table',
87
+ version: '0.1.0',
88
+ }),
89
+ );
@@ -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,16 +2,14 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import type * as Schema from 'effect/Schema';
6
6
 
7
- import { Obj } from '@dxos/echo';
8
- import { getTypename, toJsonSchema } from '@dxos/echo-schema';
9
- import type { JsonSchemaType, SortDirectionType } from '@dxos/echo-schema';
7
+ import { Filter, type JsonSchema, Obj, Query, Ref, Type } from '@dxos/echo';
10
8
  import {
11
- type DataType,
12
9
  ProjectionModel,
13
10
  type SchemaPropertyDefinition,
14
- createView,
11
+ type SortDirectionType,
12
+ View,
15
13
  getSchemaFromPropertyDefinitions,
16
14
  } from '@dxos/schema';
17
15
 
@@ -38,14 +36,14 @@ export const getBaseSchema = ({
38
36
  }: {
39
37
  typename?: string;
40
38
  properties?: TablePropertyDefinition[];
41
- jsonSchema?: JsonSchemaType;
39
+ jsonSchema?: JsonSchema.JsonSchema;
42
40
  schema?: Schema.Schema.AnyNoContext;
43
- }): { typename: string; jsonSchema: JsonSchemaType } => {
41
+ }): { typename: string; jsonSchema: JsonSchema.JsonSchema } => {
44
42
  if (typename && properties) {
45
43
  const schema = getSchemaFromPropertyDefinitions(typename, properties);
46
44
  return { typename: schema.typename, jsonSchema: schema.jsonSchema };
47
45
  } else if (schema) {
48
- return { typename: getTypename(schema)!, jsonSchema: toJsonSchema(schema) };
46
+ return { typename: Type.getTypename(schema)!, jsonSchema: Type.toJsonSchema(schema) };
49
47
  } else if (typename && jsonSchema) {
50
48
  return { typename, jsonSchema };
51
49
  } else {
@@ -54,32 +52,30 @@ export const getBaseSchema = ({
54
52
  };
55
53
 
56
54
  export const makeDynamicTable = ({
57
- typename,
58
55
  jsonSchema,
59
56
  properties,
60
57
  }: {
61
- typename: string;
62
- jsonSchema: JsonSchemaType;
58
+ jsonSchema: JsonSchema.JsonSchema;
63
59
  properties?: TablePropertyDefinition[];
64
- }): { projection: ProjectionModel; view: DataType.View } => {
65
- const table = Obj.make(Table.Table, { sizes: {} });
66
- const view = createView({
67
- typename,
60
+ }): { projection: ProjectionModel; object: Table.Table } => {
61
+ const view = View.make({
62
+ query: Query.select(Filter.everything()),
68
63
  jsonSchema,
69
- presentation: table,
70
64
  ...(properties && { fields: properties.map((property) => property.name) }),
71
65
  });
66
+ const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
72
67
 
73
68
  const projection = new ProjectionModel(jsonSchema, view.projection);
69
+ projection.normalizeView();
74
70
  if (properties && projection.fields) {
75
- setProperties(view, projection, table, properties);
71
+ setProperties(view, projection, object, properties);
76
72
  }
77
73
 
78
- return { projection, view };
74
+ return { projection, object };
79
75
  };
80
76
 
81
77
  const setProperties = (
82
- view: DataType.View,
78
+ view: View.View,
83
79
  projection: ProjectionModel,
84
80
  table: Table.Table,
85
81
  properties: TablePropertyDefinition[],
@@ -101,7 +97,7 @@ const setProperties = (
101
97
 
102
98
  if (property.sort) {
103
99
  const fieldId = field.id;
104
- view.query.sort = [{ fieldId, direction: property.sort }];
100
+ view.sort = [{ fieldId, direction: property.sort }];
105
101
  }
106
102
  }
107
103
  }
@@ -2,8 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
6
- import { TypeLiteral, isTypeLiteral } from 'effect/SchemaAST';
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
7
 
8
8
  /**
9
9
  * Creates a narrowed schema from an original schema that only includes
@@ -20,14 +20,14 @@ export const narrowSchema = <S extends Schema.Schema.AnyNoContext>(
20
20
  ): Schema.Schema<unknown, unknown> | undefined => {
21
21
  const ast = (schema as any)?.ast;
22
22
 
23
- if (isTypeLiteral(ast)) {
23
+ if (SchemaAST.isTypeLiteral(ast)) {
24
24
  // Filter property signatures that match any of the provided paths
25
25
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
26
26
 
27
27
  // If we found at least one matching property
28
28
  if (propertySignatures.length > 0) {
29
29
  // Create a new TypeLiteral with only the matching properties
30
- const narrowType = new TypeLiteral(propertySignatures, []);
30
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
31
31
  return Schema.make(narrowType);
32
32
  }
33
33
  }
@@ -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 { Schema } from "effect";
15
- import { Match } from "effect";
16
- import { Obj, Type } from "@dxos/echo";
17
- import { JsonPath, toEffectSchema } from "@dxos/echo-schema";
18
- import { ViewAnnotation } from "@dxos/echo-schema";
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-63UUF4IG.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 { Schema } from 'effect';\nimport { Match } from 'effect';\n\nimport { Obj, Type } from '@dxos/echo';\nimport { JsonPath, type JsonSchemaType, toEffectSchema } from '@dxos/echo-schema';\nimport { ViewAnnotation } from '@dxos/echo-schema';\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,SAASA,cAAc;AACvB,SAASC,aAAa;AAEtB,SAASC,KAAKC,YAAY;AAC1B,SAASC,UAA+BC,sBAAsB;AAC9D,SAASC,sBAAsB;AAE/B,SAAuDC,qBAAqBC,2BAA2B;AAEhG,IAAMC,QAAQC,OAAOC,OAAO;EACjCC,OAAOF,OAAOG,OAAO;IACnBC,KAAKC;IACLC,OAAON,OAAOO;EAChB,CAAA,EAAGC,KAAKR,OAAOS,OAAO;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,KAAKjB,OAAO;EAAEG,OAAO,CAAC;EAAG,GAAGe;AAAM,CAAA;AAMzG,IAAMC,WAAW,OAAO,EAC7BhB,OACA,GAAGe,MAAAA,MACW;AAKd,QAAME,QAAQR,IAAIK,KAAKjB,OAAO;IAAEG,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,UAAMC,KAAI,EAAe7B,KACvB4B,MAAME,KAAK,WAAW,MAAA;AACpBnB,YAAMjB,MAAMgC,SAASC,IAAI,IAAgB;IAC3C,CAAA,GACAC,MAAME,KAAK,UAAU,MAAA;AACnBnB,YAAMjB,MAAMgC,SAASC,IAAI,IAAgB;IAC3C,CAAA,GACAC,MAAMG,OAAO,MAAA;IAEb,CAAA,CAAA,EACAL,SAASG,IAAI;EACjB;AAEA,SAAO;IAAEjB;IAAYI;IAAQH;EAAK;AACpC;",
6
- "names": ["Schema", "Match", "Obj", "Type", "JsonPath", "toEffectSchema", "ViewAnnotation", "createViewFromSpace", "getSchemaProperties", "Table", "Schema", "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
- }