@dxos/react-ui-table 0.8.4-main.f9ba587 → 0.8.4-main.fcc0d83b33

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 (185) hide show
  1. package/dist/lib/browser/chunk-FBURZBPH.mjs +70 -0
  2. package/dist/lib/browser/chunk-FBURZBPH.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-YGC7LZJN.mjs +1695 -0
  6. package/dist/lib/browser/chunk-YGC7LZJN.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +1158 -2872
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/testing/index.mjs +115 -0
  11. package/dist/lib/browser/testing/index.mjs.map +7 -0
  12. package/dist/lib/browser/translations.mjs +36 -0
  13. package/dist/lib/browser/translations.mjs.map +7 -0
  14. package/dist/lib/browser/types/index.mjs +4 -5
  15. package/dist/lib/node-esm/chunk-DKKMSVKP.mjs +71 -0
  16. package/dist/lib/node-esm/chunk-DKKMSVKP.mjs.map +7 -0
  17. package/dist/lib/node-esm/chunk-GKIWDEZ7.mjs +1697 -0
  18. package/dist/lib/node-esm/chunk-GKIWDEZ7.mjs.map +7 -0
  19. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  20. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  21. package/dist/lib/node-esm/index.mjs +1158 -2872
  22. package/dist/lib/node-esm/index.mjs.map +4 -4
  23. package/dist/lib/node-esm/meta.json +1 -1
  24. package/dist/lib/node-esm/testing/index.mjs +116 -0
  25. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  26. package/dist/lib/node-esm/translations.mjs +37 -0
  27. package/dist/lib/node-esm/translations.mjs.map +7 -0
  28. package/dist/lib/node-esm/types/index.mjs +4 -5
  29. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
  30. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/ColumnSettings.d.ts +4 -2
  32. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
  34. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +35 -3
  36. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/Table/Relations.stories.d.ts +111 -0
  38. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  39. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  40. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  41. package/dist/types/src/components/Table/Table.d.ts +21 -18
  42. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  43. package/dist/types/src/components/Table/Table.stories.d.ts +110 -6
  44. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  45. package/dist/types/src/components/Table/TableContent.d.ts +17 -0
  46. package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
  47. package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
  48. package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
  49. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  50. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  51. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +14 -9
  52. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  53. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +12 -18
  54. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  55. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +38 -5
  56. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  57. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  58. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  59. package/dist/types/src/components/index.d.ts +0 -1
  60. package/dist/types/src/components/index.d.ts.map +1 -1
  61. package/dist/types/src/components/testing.d.ts +26 -56
  62. package/dist/types/src/components/testing.d.ts.map +1 -1
  63. package/dist/types/src/hooks/index.d.ts +2 -1
  64. package/dist/types/src/hooks/index.d.ts.map +1 -1
  65. package/dist/types/src/hooks/useAddRow.d.ts +6 -6
  66. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  67. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  68. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  69. package/dist/types/src/hooks/useTableModel.d.ts +11 -10
  70. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  71. package/dist/types/src/index.d.ts +0 -3
  72. package/dist/types/src/index.d.ts.map +1 -1
  73. package/dist/types/src/model/modal-controller.d.ts +5 -8
  74. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  75. package/dist/types/src/model/selection-model.d.ts +18 -8
  76. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  77. package/dist/types/src/model/table-model.d.ts +116 -34
  78. package/dist/types/src/model/table-model.d.ts.map +1 -1
  79. package/dist/types/src/model/table-presentation.d.ts +5 -2
  80. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  81. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  82. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  83. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  84. package/dist/types/src/testing/index.d.ts +2 -0
  85. package/dist/types/src/testing/index.d.ts.map +1 -0
  86. package/dist/types/src/testing/useTestTableModel.d.ts +25 -0
  87. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
  88. package/dist/types/src/translations.d.ts +21 -23
  89. package/dist/types/src/translations.d.ts.map +1 -1
  90. package/dist/types/src/types/Table.d.ts +26 -0
  91. package/dist/types/src/types/Table.d.ts.map +1 -0
  92. package/dist/types/src/types/index.d.ts +1 -1
  93. package/dist/types/src/types/index.d.ts.map +1 -1
  94. package/dist/types/src/util/dynamic-table.d.ts +15 -14
  95. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  96. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  97. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  98. package/dist/types/src/util/index.d.ts +2 -1
  99. package/dist/types/src/util/index.d.ts.map +1 -1
  100. package/dist/types/src/util/query-ast.d.ts +7 -0
  101. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  102. package/dist/types/src/util/schema.d.ts +1 -1
  103. package/dist/types/src/util/schema.d.ts.map +1 -1
  104. package/dist/types/src/util/signals.d.ts.map +1 -1
  105. package/dist/types/src/util/sort.d.ts +12 -0
  106. package/dist/types/src/util/sort.d.ts.map +1 -0
  107. package/dist/types/src/util/table-buttons.d.ts +20 -20
  108. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  109. package/dist/types/src/util/table-controls.d.ts +4 -4
  110. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  111. package/dist/types/src/util/tag.d.ts.map +1 -1
  112. package/dist/types/tsconfig.tsbuildinfo +1 -1
  113. package/package.json +80 -69
  114. package/src/components/Table/ColumnActionsMenu.tsx +18 -13
  115. package/src/components/Table/ColumnSettings.tsx +18 -15
  116. package/src/components/Table/DynamicTable.stories.tsx +40 -36
  117. package/src/components/Table/DynamicTable.tsx +38 -34
  118. package/src/components/Table/Relations.stories.tsx +281 -0
  119. package/src/components/Table/RowActionsMenu.tsx +28 -18
  120. package/src/components/Table/Table.stories.tsx +198 -220
  121. package/src/components/Table/Table.tsx +47 -376
  122. package/src/components/Table/TableContent.tsx +421 -0
  123. package/src/components/Table/TableToolbar.tsx +111 -0
  124. package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -6
  125. package/src/components/TableCellEditor/FormCellEditor.tsx +153 -49
  126. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +38 -77
  127. package/src/components/TableCellEditor/TableCellEditor.tsx +104 -233
  128. package/src/components/TableCellEditor/index.ts +1 -0
  129. package/src/components/index.ts +0 -1
  130. package/src/components/testing.ts +46 -37
  131. package/src/hooks/index.ts +2 -1
  132. package/src/hooks/useAddRow.ts +14 -14
  133. package/src/hooks/useProjectionModel.ts +39 -0
  134. package/src/hooks/useTableModel.ts +41 -35
  135. package/src/index.ts +0 -5
  136. package/src/model/modal-controller.ts +24 -41
  137. package/src/model/selection-model.ts +75 -41
  138. package/src/model/table-model.test.ts +91 -56
  139. package/src/model/table-model.ts +468 -187
  140. package/src/model/table-presentation.test.ts +77 -60
  141. package/src/model/table-presentation.ts +112 -66
  142. package/src/playwright/TableManager.ts +13 -6
  143. package/src/playwright/playwright.config.ts +1 -1
  144. package/src/playwright/smoke.spec.ts +180 -43
  145. package/src/testing/index.ts +5 -0
  146. package/src/testing/useTestTableModel.ts +133 -0
  147. package/src/translations.ts +20 -22
  148. package/src/types/Table.ts +79 -0
  149. package/src/types/index.ts +2 -2
  150. package/src/util/dynamic-table.test.ts +77 -0
  151. package/src/util/dynamic-table.ts +51 -36
  152. package/src/util/index.ts +2 -1
  153. package/src/util/query-ast.ts +22 -0
  154. package/src/util/schema.ts +4 -4
  155. package/src/util/sort.ts +90 -0
  156. package/src/util/table-buttons.ts +4 -3
  157. package/src/util/table-controls.ts +6 -3
  158. package/dist/lib/browser/chunk-Q5QQXJUO.mjs +0 -27
  159. package/dist/lib/browser/chunk-Q5QQXJUO.mjs.map +0 -7
  160. package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs +0 -29
  161. package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs.map +0 -7
  162. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  163. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  164. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  165. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  166. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  167. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  168. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
  169. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
  170. package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
  171. package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
  172. package/dist/types/src/model/table-sorting.d.ts +0 -53
  173. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  174. package/dist/types/src/types/table.d.ts +0 -56
  175. package/dist/types/src/types/table.d.ts.map +0 -1
  176. package/dist/types/src/util/table.d.ts +0 -14
  177. package/dist/types/src/util/table.d.ts.map +0 -1
  178. package/src/components/Table/CreateRefPanel.tsx +0 -84
  179. package/src/components/Table/relations.stories.tsx +0 -123
  180. package/src/components/TableCellEditor/extension.ts +0 -61
  181. package/src/components/TableToolbar/TableToolbar.tsx +0 -102
  182. package/src/components/TableToolbar/index.ts +0 -5
  183. package/src/model/table-sorting.ts +0 -216
  184. package/src/types/table.ts +0 -27
  185. package/src/util/table.ts +0 -127
@@ -1,216 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { computed, signal, type Signal, type ReadonlySignal } from '@preact/signals-core';
6
- import orderBy from 'lodash.orderby';
7
-
8
- import { getValue, FormatEnum, TypeEnum, type SortDirectionType, type FieldSortType } from '@dxos/echo-schema';
9
- import { formatForDisplay } from '@dxos/react-ui-form';
10
- import type { PropertyType, FieldType, ViewProjection, ViewType } from '@dxos/schema';
11
-
12
- import { type TableRow } from './table-model';
13
-
14
- /**
15
- * Represents the local sort state.
16
- * - undefined: No local sort set, fallback to view sort.
17
- * - cleared: Sort explicitly cleared by user.
18
- * - active: Active local sort with sort configuration.
19
- */
20
- type LocalSort = { type: 'cleared' } | { type: 'active'; sort: FieldSortType } | undefined;
21
-
22
- /**
23
- * Manages table sorting functionality through display and data index mapping.
24
- *
25
- * When a table is sorted, rows visually reorder but we need to maintain references
26
- * to the original data positions. This is handled through two types of indices:
27
- *
28
- * - Display indices: The visual positions after sorting
29
- * - Data indices: The original positions in the source data
30
- *
31
- * The _displayToDataIndex map maintains these relationships, enabling lookups
32
- * between visual and source positions.
33
- *
34
- * Example mapping between display and data indices:
35
- *
36
- * Original Data: Sorted Display: Mapping: (Display → Data)
37
- * ┌──────────────┐ ┌──────────────┐ ┌────────┐
38
- * │ 0: "Banana" │ => │ 0: "Apple" │ => │ 0 => 1 │
39
- * │ 1: "Apple" │ => │ 1: "Banana" │ => │ 1 => 0 │
40
- * │ 2: "Cherry" │ => │ 2: "Cherry" │ => │ 2 => 2 │
41
- * └──────────────┘ └──────────────┘ └────────┘
42
- */
43
- export class TableSorting<T extends TableRow> {
44
- private readonly _displayToDataIndex = new Map<number, number>();
45
- private readonly _rows: Signal<T[]>;
46
- private readonly _localSort = signal<LocalSort>(undefined);
47
- private readonly _isDirty: ReadonlySignal<boolean>;
48
- public readonly sortedRows: ReadonlySignal<T[]>;
49
-
50
- constructor(
51
- rows: Signal<T[]>,
52
- private readonly _view: ViewType | undefined,
53
- private readonly _projection: ViewProjection,
54
- ) {
55
- this._rows = rows;
56
- this._isDirty = computed(() => {
57
- const local = this._localSort.value;
58
- const viewSort = this._view?.query.sort?.[0];
59
- if (local?.type === 'cleared') {
60
- return viewSort !== undefined;
61
- }
62
- if (local?.type === 'active') {
63
- if (!viewSort) {
64
- return true;
65
- }
66
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
67
- }
68
- return false;
69
- });
70
- this.sortedRows = this.initialiseSortedRows();
71
- }
72
-
73
- /**
74
- * @reactive
75
- * @returns Local sort if present, falls back to view sort.
76
- */
77
- public get sorting(): FieldSortType | undefined {
78
- const local = this._localSort.value;
79
- if (local?.type === 'cleared') {
80
- return undefined;
81
- }
82
- if (local?.type === 'active') {
83
- return local.sort;
84
- }
85
-
86
- return this._view?.query.sort?.[0];
87
- }
88
-
89
- /**
90
- * @reactive
91
- * @returns Whether local sort differs from view sort.
92
- */
93
- public get isDirty(): boolean {
94
- return this._isDirty.value;
95
- }
96
-
97
- public getDataIndex(displayIndex: number): number {
98
- return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
99
- }
100
-
101
- public setSort(fieldId: string, direction: SortDirectionType): void {
102
- this._localSort.value = {
103
- type: 'active',
104
- sort: { fieldId, direction },
105
- };
106
- }
107
-
108
- public toggleSort(fieldId: string): void {
109
- if (!this._view || !this.sorting || this.sorting.fieldId !== fieldId) {
110
- return;
111
- }
112
-
113
- switch (this.sorting.direction) {
114
- case 'asc': {
115
- this.setSort(fieldId, 'desc');
116
- break;
117
- }
118
- case 'desc': {
119
- this.setSort(fieldId, 'asc');
120
- break;
121
- }
122
- }
123
- }
124
-
125
- public clearSort(): void {
126
- this._localSort.value = { type: 'cleared' };
127
- }
128
-
129
- public save(): void {
130
- if (this._view && this._localSort.value !== undefined) {
131
- if (this._localSort.value.type === 'active') {
132
- this._view.query.sort = [this._localSort.value.sort];
133
- } else {
134
- this._view.query.sort = [];
135
- }
136
- this._localSort.value = undefined;
137
- }
138
- }
139
-
140
- //
141
- // Initialisation.
142
- //
143
-
144
- private initialiseSortedRows(): ReadonlySignal<T[]> {
145
- return computed(() => {
146
- this._displayToDataIndex.clear();
147
- const sort = this.sorting;
148
- if (!sort || !this._view) {
149
- return this._rows.value;
150
- }
151
-
152
- const field = this._view.fields.find((f) => f.id === sort.fieldId);
153
- if (!field) {
154
- return this._rows.value;
155
- }
156
-
157
- const { props } = this._projection.getFieldProjection(field.id);
158
-
159
- const dataWithIndices = this._rows.value.map((item, index) => {
160
- const sortValue = this.getSortValue(props, field, item);
161
- const isEmpty = !(props.type === TypeEnum.Boolean) && (sortValue == null || sortValue === '');
162
-
163
- return { item, index, value: sortValue, isEmpty };
164
- });
165
-
166
- const ordered = orderBy(dataWithIndices, ['isEmpty', 'value'], ['asc', sort.direction]);
167
-
168
- ordered.forEach(({ index: dataIndex }, displayIndex) => {
169
- if (displayIndex !== dataIndex) {
170
- this._displayToDataIndex.set(displayIndex, dataIndex);
171
- }
172
- });
173
-
174
- return ordered.map(({ item }) => item);
175
- });
176
- }
177
-
178
- private getSortValue(props: PropertyType, field: FieldType, item: T) {
179
- const { type, format } = props;
180
- const value = getValue(item, field.path);
181
-
182
- if (type === TypeEnum.Boolean) {
183
- return !!value; // Coerce null/undefined to false for booleans.
184
- }
185
- if (type === TypeEnum.Number) {
186
- return value;
187
- }
188
- if (value == null) {
189
- return value;
190
- }
191
-
192
- /**
193
- * For single select fields, the sort value is determined by the index of the option in the
194
- * options array. This ensures sort order matches the configured option order.
195
- */
196
- if (format === FormatEnum.SingleSelect) {
197
- const options = props.options;
198
- if (!options) {
199
- return undefined;
200
- }
201
-
202
- const option = options.find((option) => option.id === value);
203
- return option ? options.indexOf(option) : undefined;
204
- }
205
-
206
- // TODO(ZaymonFC): Should we format this returned value for display based on the referenced prop format?
207
- // Right now we're going to be sorting based on the raw values.
208
- // Maybe we need to recurse this function with the referenced prop format and field?
209
- if (format === FormatEnum.Ref && field.referencePath) {
210
- const refValue = getValue(value.target, field.referencePath);
211
- return refValue;
212
- }
213
-
214
- return formatForDisplay({ type, format, value });
215
- }
216
- }
@@ -1,27 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- // import { ThreadType } from '@dxos/plugin-space/types';
8
- import { Type } from '@dxos/echo';
9
- import { ObjectId, Ref, Expando, LabelAnnotation } from '@dxos/echo-schema';
10
- import { ViewType } from '@dxos/schema';
11
-
12
- export const TableSchema = Schema.Struct({
13
- id: ObjectId,
14
- name: Schema.optional(Schema.String),
15
- view: Schema.optional(Ref(ViewType)),
16
- // TODO(burdon): Document why threads is included here?
17
- threads: Schema.optional(Schema.Array(Ref(Expando /* ThreadType */))),
18
- }).pipe(LabelAnnotation.set(['name']));
19
-
20
- // TODO(burdon): Move out of react-ui-xxx.
21
- export const TableType = TableSchema.pipe(
22
- Type.Obj({
23
- typename: 'dxos.org/type/Table',
24
- version: '0.1.0',
25
- }),
26
- );
27
- export interface TableType extends Schema.Schema.Type<typeof TableType> {}
package/src/util/table.ts DELETED
@@ -1,127 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Schema } from 'effect';
6
-
7
- import {
8
- type EchoSchema,
9
- Format,
10
- FormatEnum,
11
- type JsonPath,
12
- type JsonProp,
13
- Ref,
14
- TypedObject,
15
- TypeEnum,
16
- } from '@dxos/echo-schema';
17
- import { type Client, PublicKey } from '@dxos/react-client';
18
- import { live, type Space } from '@dxos/react-client/echo';
19
- import { createFieldId, createView, getSchemaProperties, ViewProjection, type ViewType } from '@dxos/schema';
20
-
21
- import { type TableType } from '../types';
22
-
23
- // TODO(ZaymonFC): We don't need the client anymore.
24
- type InitialiseTableProps = {
25
- client: Client;
26
- space: Space;
27
- table: TableType;
28
- typename?: string;
29
- initialRow?: boolean;
30
- };
31
-
32
- export const initializeTable = async ({
33
- client,
34
- space,
35
- table,
36
- typename,
37
- initialRow = true,
38
- }: InitialiseTableProps): Promise<Schema.Schema.AnyNoContext> => {
39
- if (typename) {
40
- const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
41
- if (!schema) {
42
- throw new Error(`Schema not found: ${typename}`);
43
- }
44
-
45
- const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
46
-
47
- table.view = Ref.make(
48
- createView({
49
- // TODO(ZaymonFC): Don't hardcode name?
50
- name: 'View',
51
- typename: schema.typename,
52
- jsonSchema: schema.jsonSchema,
53
- fields,
54
- }),
55
- );
56
-
57
- return schema;
58
- } else {
59
- const [schema] = await space.db.schemaRegistry.register([createContactSchema()]);
60
- const fields = ContactFields;
61
-
62
- table.view = Ref.make(
63
- createView({
64
- name: 'View',
65
- typename: schema.typename,
66
- jsonSchema: schema.jsonSchema,
67
- fields,
68
- }),
69
- );
70
-
71
- createProjection(schema, table.view.target!);
72
-
73
- if (initialRow) {
74
- // TODO(burdon): Last (first) row should not be in db and should be managed by the model.
75
- space.db.add(live(schema, {}));
76
- }
77
-
78
- return schema;
79
- }
80
- };
81
-
82
- const createContactSchema = () =>
83
- TypedObject({
84
- typename: `example.com/type/${PublicKey.random().truncate()}`,
85
- version: '0.1.0',
86
- })({
87
- name: Schema.optional(Schema.String).annotations({ title: 'Name' }),
88
- active: Schema.optional(Schema.Boolean).annotations({ title: 'Active' }),
89
- email: Schema.optional(Format.Email),
90
- salary: Schema.optional(Format.Currency()).annotations({ title: 'Salary' }),
91
- });
92
-
93
- const ContactFields = ['name', 'email', 'salary', 'active'];
94
-
95
- const createProjection = (schema: EchoSchema, view: ViewType): ViewProjection => {
96
- const projection = new ViewProjection(schema.jsonSchema, view);
97
- projection.setFieldProjection({
98
- field: {
99
- id: view.fields.find((f) => f.path === 'salary')!.id,
100
- path: 'salary' as JsonPath,
101
- size: 150,
102
- },
103
- });
104
- projection.setFieldProjection({
105
- field: {
106
- id: view.fields.find((f) => f.path === 'active')!.id,
107
- path: 'active' as JsonPath,
108
- size: 100,
109
- },
110
- });
111
- projection.setFieldProjection({
112
- field: {
113
- id: createFieldId(),
114
- path: 'manager' as JsonPath,
115
- referencePath: 'name' as JsonPath,
116
- },
117
- props: {
118
- property: 'manager' as JsonProp,
119
- type: TypeEnum.Ref,
120
- format: FormatEnum.Ref,
121
- referenceSchema: schema.typename,
122
- title: 'Manager',
123
- },
124
- });
125
-
126
- return projection;
127
- };