@dxos/react-ui-table 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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 (176) 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 +1139 -1193
  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 +33 -42
  11. package/dist/lib/browser/testing/index.mjs.map +3 -3
  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 -3
  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 +1139 -1193
  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 +33 -42
  25. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  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 -3
  29. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
  30. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -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 +23 -39
  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 +96 -29
  38. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  39. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  40. package/dist/types/src/components/Table/Table.d.ts +20 -18
  41. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  42. package/dist/types/src/components/Table/Table.stories.d.ts +96 -31
  43. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/Table/TableContent.d.ts +17 -0
  45. package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
  46. package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
  47. package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
  48. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  49. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  50. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -12
  51. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  52. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +7 -7
  53. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  54. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +25 -28
  55. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  56. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  57. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  58. package/dist/types/src/components/index.d.ts +0 -1
  59. package/dist/types/src/components/index.d.ts.map +1 -1
  60. package/dist/types/src/components/testing.d.ts +23 -16
  61. package/dist/types/src/components/testing.d.ts.map +1 -1
  62. package/dist/types/src/hooks/index.d.ts +2 -1
  63. package/dist/types/src/hooks/index.d.ts.map +1 -1
  64. package/dist/types/src/hooks/useAddRow.d.ts +5 -6
  65. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  66. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  67. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  68. package/dist/types/src/hooks/useTableModel.d.ts +9 -9
  69. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  70. package/dist/types/src/index.d.ts +0 -2
  71. package/dist/types/src/index.d.ts.map +1 -1
  72. package/dist/types/src/model/modal-controller.d.ts +5 -8
  73. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  74. package/dist/types/src/model/selection-model.d.ts +18 -9
  75. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  76. package/dist/types/src/model/table-model.d.ts +106 -26
  77. package/dist/types/src/model/table-model.d.ts.map +1 -1
  78. package/dist/types/src/model/table-presentation.d.ts +3 -1
  79. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  80. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  81. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  82. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  83. package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
  84. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  85. package/dist/types/src/translations.d.ts +21 -23
  86. package/dist/types/src/translations.d.ts.map +1 -1
  87. package/dist/types/src/types/Table.d.ts +26 -0
  88. package/dist/types/src/types/Table.d.ts.map +1 -0
  89. package/dist/types/src/types/index.d.ts +1 -1
  90. package/dist/types/src/types/index.d.ts.map +1 -1
  91. package/dist/types/src/util/dynamic-table.d.ts +14 -12
  92. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  93. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  94. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  95. package/dist/types/src/util/index.d.ts +2 -0
  96. package/dist/types/src/util/index.d.ts.map +1 -1
  97. package/dist/types/src/util/query-ast.d.ts +7 -0
  98. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  99. package/dist/types/src/util/schema.d.ts +1 -1
  100. package/dist/types/src/util/schema.d.ts.map +1 -1
  101. package/dist/types/src/util/signals.d.ts.map +1 -1
  102. package/dist/types/src/util/sort.d.ts +12 -0
  103. package/dist/types/src/util/sort.d.ts.map +1 -0
  104. package/dist/types/src/util/table-buttons.d.ts +20 -20
  105. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  106. package/dist/types/src/util/table-controls.d.ts +4 -4
  107. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  108. package/dist/types/src/util/tag.d.ts.map +1 -1
  109. package/dist/types/tsconfig.tsbuildinfo +1 -1
  110. package/package.json +67 -76
  111. package/src/components/Table/ColumnActionsMenu.tsx +17 -12
  112. package/src/components/Table/ColumnSettings.tsx +8 -9
  113. package/src/components/Table/DynamicTable.stories.tsx +34 -33
  114. package/src/components/Table/DynamicTable.tsx +33 -36
  115. package/src/components/Table/Relations.stories.tsx +196 -48
  116. package/src/components/Table/RowActionsMenu.tsx +27 -17
  117. package/src/components/Table/Table.stories.tsx +144 -127
  118. package/src/components/Table/Table.tsx +43 -403
  119. package/src/components/Table/TableContent.tsx +421 -0
  120. package/src/components/Table/TableToolbar.tsx +111 -0
  121. package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -6
  122. package/src/components/TableCellEditor/FormCellEditor.tsx +125 -131
  123. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +32 -55
  124. package/src/components/TableCellEditor/TableCellEditor.tsx +39 -124
  125. package/src/components/TableCellEditor/index.ts +1 -0
  126. package/src/components/index.ts +0 -1
  127. package/src/components/testing.ts +44 -18
  128. package/src/hooks/index.ts +2 -1
  129. package/src/hooks/useAddRow.ts +8 -10
  130. package/src/hooks/useProjectionModel.ts +39 -0
  131. package/src/hooks/useTableModel.ts +36 -34
  132. package/src/index.ts +0 -4
  133. package/src/model/modal-controller.ts +23 -40
  134. package/src/model/selection-model.ts +75 -44
  135. package/src/model/table-model.test.ts +93 -56
  136. package/src/model/table-model.ts +437 -170
  137. package/src/model/table-presentation.test.ts +67 -56
  138. package/src/model/table-presentation.ts +45 -41
  139. package/src/playwright/TableManager.ts +13 -6
  140. package/src/playwright/playwright.config.ts +1 -1
  141. package/src/playwright/smoke.spec.ts +59 -13
  142. package/src/testing/useTestTableModel.ts +48 -39
  143. package/src/translations.ts +20 -22
  144. package/src/types/Table.ts +79 -0
  145. package/src/types/index.ts +1 -1
  146. package/src/util/dynamic-table.test.ts +70 -0
  147. package/src/util/dynamic-table.ts +43 -31
  148. package/src/util/index.ts +2 -0
  149. package/src/util/query-ast.ts +22 -0
  150. package/src/util/schema.ts +4 -4
  151. package/src/util/sort.ts +90 -0
  152. package/src/util/table-buttons.ts +1 -1
  153. package/src/util/table-controls.ts +2 -2
  154. package/dist/lib/browser/chunk-63UUF4IG.mjs +0 -66
  155. package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-GPZSXPSA.mjs +0 -1822
  157. package/dist/lib/browser/chunk-GPZSXPSA.mjs.map +0 -7
  158. package/dist/lib/node-esm/chunk-K734DJB7.mjs +0 -67
  159. package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
  160. package/dist/lib/node-esm/chunk-XUD6W42C.mjs +0 -1823
  161. package/dist/lib/node-esm/chunk-XUD6W42C.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/TableToolbar/TableToolbar.d.ts +0 -21
  165. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
  166. package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
  167. package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
  168. package/dist/types/src/model/table-sorting.d.ts +0 -52
  169. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  170. package/dist/types/src/types/schema.d.ts +0 -28
  171. package/dist/types/src/types/schema.d.ts.map +0 -1
  172. package/src/components/Table/CreateRefPanel.tsx +0 -103
  173. package/src/components/TableToolbar/TableToolbar.tsx +0 -102
  174. package/src/components/TableToolbar/index.ts +0 -5
  175. package/src/model/table-sorting.ts +0 -225
  176. package/src/types/schema.ts +0 -73
@@ -3,597 +3,607 @@ import {
3
3
  BUTTON_IDENTIFIERS,
4
4
  CONTROL_IDENTIFIERS,
5
5
  CheckboxStory,
6
- ModalController,
7
6
  SwitchStory,
8
7
  TableModel,
9
8
  TablePresentation,
10
9
  cellClassesForRowSelection,
11
- getBaseSchema,
12
- makeDynamicTable,
13
- narrowSchema,
10
+ compareValues,
11
+ createDirectChangeCallback,
12
+ createEchoChangeCallback,
13
+ extractOrder,
14
+ getSortValue,
14
15
  tableButtons,
15
16
  tableControls,
16
- touch,
17
17
  useAddRow,
18
+ useProjectionModel,
18
19
  useTableModel
19
- } from "./chunk-XUD6W42C.mjs";
20
- import "./chunk-K734DJB7.mjs";
21
-
22
- // src/translations.ts
23
- var translationKey = "react-ui-table";
24
- var translations = [
25
- {
26
- "en-US": {
27
- [translationKey]: {
28
- "object placeholder": "New table",
29
- "create object label": "Create table",
30
- "table name placeholder": "Table name",
31
- "settings title": "Table settings",
32
- "table schema label": "Record type",
33
- "new schema": "New record type",
34
- "continue label": "Continue",
35
- "create stack section label": "Create table",
36
- "add row label": "Add row",
37
- "create comment": "Create thread",
38
- "column action sort descending": "Sort Descending",
39
- "column action sort ascending": "Sort Ascending",
40
- "column action clear sorting": "Clear Sorting",
41
- "column action settings": "Column Settings",
42
- "column action delete": "Delete Column",
43
- "delete row label": "Delete row",
44
- "bulk delete row label": "Delete selected rows",
45
- "column deleted label": "Column deleted",
46
- "new column button label": "Create column",
47
- "create new object label": "Create new object \u201C{{text}}\u201D",
48
- "save view label": "Save changes to view"
49
- }
50
- }
51
- }
52
- ];
20
+ } from "./chunk-GKIWDEZ7.mjs";
21
+ import {
22
+ Table_exports
23
+ } from "./chunk-DKKMSVKP.mjs";
24
+ import "./chunk-HSLMI22Q.mjs";
53
25
 
54
26
  // src/components/Table/Table.tsx
55
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
56
- import React8, { forwardRef, useCallback as useCallback5, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo5, useState as useState4 } from "react";
27
+ import { Atom as Atom4 } from "@effect-atom/atom-react";
28
+ import { createContext } from "@radix-ui/react-context";
29
+ import React9, { forwardRef, useImperativeHandle, useRef as useRef3 } from "react";
30
+
31
+ // src/components/Table/TableContent.tsx
32
+ import { Atom as Atom2, RegistryContext, useAtomValue as useAtomValue4 } from "@effect-atom/atom-react";
33
+ import * as String2 from "effect/String";
34
+ import React7, { useCallback as useCallback4, useContext, useEffect as useEffect3, useMemo as useMemo4, useState as useState4 } from "react";
35
+ import { log } from "@dxos/log";
57
36
  import { useAttention } from "@dxos/react-ui-attention";
58
37
  import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
59
38
  import { DxEditRequest } from "@dxos/react-ui-grid";
60
- import { mx } from "@dxos/react-ui-theme";
39
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
40
+
41
+ // src/util/dynamic-table.ts
42
+ import { Filter, JsonSchema, Obj, Order, Query, Ref, Type } from "@dxos/echo";
43
+ import { ProjectionModel, ViewModel, createEchoChangeCallback as createEchoChangeCallback2, getSchemaFromPropertyDefinitions } from "@dxos/schema";
44
+ var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
45
+ if (typename && properties) {
46
+ const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
47
+ return {
48
+ typename: schema2.typename,
49
+ jsonSchema: JsonSchema.toJsonSchema(schema2)
50
+ };
51
+ } else if (schema) {
52
+ return {
53
+ typename: Type.getTypename(schema),
54
+ jsonSchema: JsonSchema.toJsonSchema(schema)
55
+ };
56
+ } else if (typename && jsonSchema) {
57
+ return {
58
+ typename,
59
+ jsonSchema
60
+ };
61
+ } else {
62
+ throw new Error("invalid properties");
63
+ }
64
+ };
65
+ var makeDynamicTable = ({ registry, jsonSchema, properties }) => {
66
+ const view = ViewModel.make({
67
+ query: Query.select(Filter.everything()),
68
+ jsonSchema,
69
+ ...properties && {
70
+ fields: properties.map((property) => property.name)
71
+ }
72
+ });
73
+ const object = Obj.make(Table_exports.Table, {
74
+ view: Ref.make(view),
75
+ sizes: {}
76
+ });
77
+ const projection = new ProjectionModel({
78
+ registry,
79
+ view,
80
+ baseSchema: jsonSchema,
81
+ change: createEchoChangeCallback2(view, jsonSchema)
82
+ });
83
+ projection.normalizeView();
84
+ if (properties && projection.getFields()) {
85
+ setProperties(view, projection, object, properties);
86
+ }
87
+ return {
88
+ projection,
89
+ object
90
+ };
91
+ };
92
+ var setProperties = (view, projection, table, properties) => {
93
+ for (const property of properties) {
94
+ const field = projection.getFields().find((field2) => field2.path === property.name);
95
+ if (field) {
96
+ if (property.size !== void 0) {
97
+ Obj.update(table, (table2) => {
98
+ table2.sizes[field.path] = property.size;
99
+ });
100
+ }
101
+ if (property.title !== void 0) {
102
+ const fieldProjection = projection.getFieldProjection(field.id);
103
+ projection.setFieldProjection({
104
+ ...fieldProjection,
105
+ props: {
106
+ ...fieldProjection.props,
107
+ title: property.title
108
+ }
109
+ });
110
+ }
111
+ if (property.sort) {
112
+ const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
113
+ const newQuery = currentQuery.orderBy(Order.property(field.path, property.sort));
114
+ Obj.update(view, (view2) => {
115
+ view2.query.ast = newQuery.ast;
116
+ });
117
+ }
118
+ }
119
+ }
120
+ };
121
+
122
+ // src/util/signals.ts
123
+ var touch = (value) => value;
124
+
125
+ // src/util/schema.ts
126
+ import * as Schema from "effect/Schema";
127
+ import * as SchemaAST from "effect/SchemaAST";
128
+ var narrowSchema = (schema, paths) => {
129
+ const ast = schema?.ast;
130
+ if (SchemaAST.isTypeLiteral(ast)) {
131
+ const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
132
+ if (propertySignatures.length > 0) {
133
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
134
+ return Schema.make(narrowType);
135
+ }
136
+ }
137
+ return void 0;
138
+ };
139
+
140
+ // src/model/modal-controller.ts
141
+ import { Atom } from "@effect-atom/atom-react";
142
+ var ModalController = class {
143
+ _registry;
144
+ _state;
145
+ _triggerRef = {
146
+ current: null
147
+ };
148
+ constructor(registry) {
149
+ this._registry = registry;
150
+ this._state = Atom.make({
151
+ type: "closed"
152
+ });
153
+ }
154
+ get state() {
155
+ return this._state;
156
+ }
157
+ get stateValue() {
158
+ return this._registry.get(this._state);
159
+ }
160
+ get trigger() {
161
+ return this._triggerRef;
162
+ }
163
+ setTrigger = (trigger) => {
164
+ this._triggerRef.current = trigger;
165
+ };
166
+ showRowMenu = (rowIndex) => {
167
+ this._registry.set(this._state, {
168
+ type: "row",
169
+ rowIndex
170
+ });
171
+ };
172
+ showColumnMenu = (fieldId) => {
173
+ this._registry.set(this._state, {
174
+ type: "column",
175
+ fieldId
176
+ });
177
+ };
178
+ showColumnCreator = () => {
179
+ this._registry.set(this._state, {
180
+ type: "columnSettings",
181
+ mode: {
182
+ type: "create"
183
+ }
184
+ });
185
+ };
186
+ showReferencePanel = (targetId, schemaId) => {
187
+ this._registry.set(this._state, {
188
+ type: "refPanel",
189
+ targetId,
190
+ typename: schemaId
191
+ });
192
+ };
193
+ openColumnSettings = () => {
194
+ const currentState = this._registry.get(this._state);
195
+ if (currentState.type === "column") {
196
+ const fieldId = currentState.fieldId;
197
+ requestAnimationFrame(() => {
198
+ this._registry.set(this._state, {
199
+ type: "columnSettings",
200
+ mode: {
201
+ type: "edit",
202
+ fieldId
203
+ }
204
+ });
205
+ });
206
+ }
207
+ };
208
+ close = () => {
209
+ this._registry.set(this._state, {
210
+ type: "closed"
211
+ });
212
+ };
213
+ };
61
214
 
62
215
  // src/components/TableCellEditor/TableCellEditor.tsx
63
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
64
216
  import { EditorView } from "@codemirror/view";
65
217
  import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
66
218
  import { debounce } from "@dxos/async";
67
- import { FormatEnum, TypeEnum } from "@dxos/echo-schema";
219
+ import { Format, TypeEnum } from "@dxos/echo/internal";
68
220
  import { invariant as invariant2 } from "@dxos/invariant";
69
- import { createMarkdownExtensions } from "@dxos/react-ui-editor";
70
221
  import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
71
- import { createLinks, tagPicker } from "@dxos/react-ui-tag-picker";
72
222
 
73
223
  // src/components/TableCellEditor/CellValidationMessage.tsx
74
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
75
224
  import React from "react";
76
225
  import { useGridContext } from "@dxos/react-ui-grid";
77
- var CellValidationMessage = ({ validationError, variant = "error", __gridScope }) => {
78
- var _effect = _useSignals();
79
- try {
80
- const { editing, editBox: box } = useGridContext("GridSheetCellEditor", __gridScope);
81
- if (!editing || !validationError) {
82
- return null;
83
- }
84
- const bgClass = variant === "error" ? "bg-errorSurface" : "bg-warningSurface";
85
- const textClass = variant === "error" ? "text-errorSurfaceText" : "text-warningSurfaceText";
86
- return /* @__PURE__ */ React.createElement("div", {
87
- role: "none",
88
- className: `absolute ${bgClass} ${textClass} rounded-bs-sm text-xs p-1`,
89
- style: {
90
- ...{
91
- "--dx-gridCellWidth": `${box?.inlineSize ?? 200}px`
92
- },
93
- zIndex: 10,
94
- insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
95
- insetInlineStart: box.insetInlineStart,
96
- inlineSize: box.inlineSize
97
- }
98
- }, validationError);
99
- } finally {
100
- _effect.f();
226
+ var CellValidationMessage = ({ __gridScope, validationError, variant = "error" }) => {
227
+ const { editing, editBox: box } = useGridContext("GridSheetCellEditor", __gridScope);
228
+ if (!editing || !validationError) {
229
+ return null;
101
230
  }
231
+ const bgClass = variant === "error" ? "bg-error-surface" : "bg-warning-surface";
232
+ const textClass = variant === "error" ? "text-error-surface-text" : "text-warning-surface-text";
233
+ return /* @__PURE__ */ React.createElement("div", {
234
+ className: `absolute ${bgClass} ${textClass} rounded-h-sm text-xs p-1`,
235
+ style: {
236
+ ...{
237
+ "--dx-grid-cell-width": `${box?.inlineSize ?? 200}px`
238
+ },
239
+ zIndex: 10,
240
+ insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
241
+ insetInlineStart: box.insetInlineStart,
242
+ inlineSize: box.inlineSize
243
+ }
244
+ }, validationError);
102
245
  };
103
246
 
104
247
  // src/components/TableCellEditor/FormCellEditor.tsx
105
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
106
248
  import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
107
- import { Filter, Obj } from "@dxos/echo";
108
- import { Ref, getValue } from "@dxos/echo-schema";
249
+ import { Entity } from "@dxos/echo";
250
+ import { Ref as Ref2, getValue } from "@dxos/echo/internal";
109
251
  import { invariant } from "@dxos/invariant";
110
- import { getSnapshot } from "@dxos/live-object";
111
- import { getSpace } from "@dxos/react-client/echo";
112
252
  import { Popover } from "@dxos/react-ui";
113
253
  import { Form } from "@dxos/react-ui-form";
114
- import { cellQuery, parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
115
- import { getDeep, isNotFalsy, setDeep } from "@dxos/util";
254
+ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
255
+ import { getDeep, isTruthy, setDeep } from "@dxos/util";
256
+ import { translationKey } from "#translations";
116
257
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
117
258
  var createOptionLabel = [
118
- "create new object label",
259
+ "create-new-object.label",
119
260
  {
120
261
  ns: translationKey
121
262
  }
122
263
  ];
123
- var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, __gridScope, ...formProps }) => {
124
- var _effect = _useSignals2();
125
- try {
126
- const { editing: contextEditing, setEditing, id: gridId } = useGridContext2("ArrayEditor", __gridScope);
127
- const [editing, setLocalEditing] = useState(false);
128
- const anchorRef = useRef(null);
129
- const getSchema = useCallback((typeAnnotation) => {
130
- const space = getSpace(model.view);
131
- invariant(space, void 0, {
132
- F: __dxlog_file,
133
- L: 53,
134
- S: void 0,
135
- A: [
136
- "space",
137
- ""
138
- ]
139
- });
140
- let schema2;
141
- if (client) {
142
- schema2 = client.graph.schemaRegistry.getSchema(typeAnnotation.typename);
143
- }
144
- if (!schema2) {
145
- schema2 = space.db.schemaRegistry.getSchema(typeAnnotation.typename);
146
- }
147
- return {
148
- space,
149
- schema: schema2
150
- };
151
- }, [
152
- client,
153
- model
154
- ]);
155
- const handleQueryRefOptions = useCallback(async (typeAnnotation) => {
156
- const { schema: schema2, space } = getSchema(typeAnnotation);
157
- if (model && schema2 && space) {
158
- const { objects } = await space.db.query(Filter.type(schema2)).run();
159
- return objects.map((obj) => {
160
- return {
161
- dxn: Obj.getDXN(obj),
162
- label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
163
- };
164
- }).filter(isNotFalsy);
165
- }
166
- return [];
167
- }, [
168
- client,
169
- model
170
- ]);
171
- const originalRow = useMemo(() => {
172
- if (model && contextEditing) {
173
- const cell = parseCellIndex(contextEditing.index);
174
- if (model.isDraftCell(cell)) {
175
- const draftRow = model.draftRows.value[cell.row];
176
- invariant(draftRow, void 0, {
177
- F: __dxlog_file,
178
- L: 94,
179
- S: void 0,
180
- A: [
181
- "draftRow",
182
- ""
183
- ]
184
- });
185
- return draftRow.data;
186
- } else {
187
- const row = model.getRowAt(cell.row);
188
- invariant(row, void 0, {
189
- F: __dxlog_file,
190
- L: 98,
191
- S: void 0,
192
- A: [
193
- "row",
194
- ""
195
- ]
196
- });
197
- return row;
198
- }
199
- }
264
+ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onCreate, ...formProps }) => {
265
+ const anchorRef = useRef(null);
266
+ const { id: _gridId, editing: contextEditing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
267
+ const [editing, setLocalEditing] = useState(false);
268
+ useEffect(() => {
269
+ if (contextEditing && contextEditing.cellElement) {
270
+ anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
271
+ setLocalEditing(true);
272
+ } else {
273
+ anchorRef.current = null;
274
+ setLocalEditing(false);
275
+ }
276
+ }, [
277
+ contextEditing
278
+ ]);
279
+ const narrowedSchema = useMemo(() => {
280
+ if (!schema) {
200
281
  return void 0;
201
- }, [
202
- model,
203
- contextEditing
282
+ }
283
+ return narrowSchema(schema, [
284
+ fieldProjection.field.path
204
285
  ]);
205
- const handleSave = useCallback((values) => {
206
- const path = fieldProjection.field.path;
207
- const value = getDeep(values, [
208
- path
209
- ]);
210
- setDeep(originalRow, [
211
- path
212
- ], value);
213
- contextEditing?.cellElement?.focus();
286
+ }, [
287
+ JSON.stringify(schema),
288
+ fieldProjection.field.path
289
+ ]);
290
+ const originalRow = useMemo(() => {
291
+ if (model && contextEditing) {
292
+ const cell = parseCellIndex(contextEditing.index);
293
+ if (model.isDraftCell(cell)) {
294
+ const draftRow = model.getDraftRows()[cell.row];
295
+ invariant(draftRow, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 52, S: void 0, A: ["draftRow", ""] });
296
+ return draftRow.data;
297
+ } else {
298
+ const row = model.getRowAt(cell.row);
299
+ invariant(row, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 56, S: void 0, A: ["row", ""] });
300
+ return row;
301
+ }
302
+ }
303
+ return void 0;
304
+ }, [
305
+ model,
306
+ contextEditing
307
+ ]);
308
+ const initialFormValues = useMemo(() => originalRow ? JSON.parse(JSON.stringify(originalRow)) : {}, [
309
+ originalRow
310
+ ]);
311
+ const [formValues, setFormValues] = useState(initialFormValues);
312
+ const handleValuesChanged = useCallback((values) => {
313
+ setFormValues(values);
314
+ }, []);
315
+ const handleOpenChange = useCallback((nextOpen) => {
316
+ if (nextOpen === false) {
214
317
  setEditing(null);
215
- setLocalEditing(false);
216
318
  onSave?.();
217
- }, [
218
- fieldProjection.field.path,
219
- onSave,
220
- contextEditing,
221
- originalRow
319
+ }
320
+ setLocalEditing(nextOpen);
321
+ }, []);
322
+ const handleSave = useCallback((values) => {
323
+ if (!originalRow) {
324
+ return;
325
+ }
326
+ const path = fieldProjection.field.path;
327
+ const value = getDeep(values, [
328
+ path
222
329
  ]);
223
- const handleCreate = useCallback((object) => {
224
- const ref = Ref.make(object);
225
- const path = fieldProjection.field.path;
330
+ if (model) {
331
+ model.changeRow(originalRow, (mutableRow) => {
332
+ setDeep(mutableRow, [
333
+ path
334
+ ], value);
335
+ });
336
+ } else {
226
337
  setDeep(originalRow, [
227
338
  path
228
- ], ref);
229
- contextEditing?.cellElement?.focus();
230
- setEditing(null);
231
- setLocalEditing(false);
232
- onSave?.();
233
- }, [
234
- fieldProjection.field.path,
235
- onSave,
236
- contextEditing,
237
- originalRow
238
- ]);
239
- const handleCreateFromQuery = useCallback(async (typeAnnotation, query) => {
240
- if (model && modals && contextEditing?.index) {
241
- setLocalEditing(false);
242
- modals.openCreateRef(typeAnnotation.typename, document.querySelector(cellQuery(contextEditing.index, gridId)), {
243
- [fieldProjection.field.referencePath]: query
244
- }, handleCreate);
245
- }
246
- }, [
247
- model,
248
- modals,
249
- client,
250
- contextEditing?.index,
251
- gridId,
252
- fieldProjection,
253
- handleSave
254
- ]);
255
- useEffect(() => {
256
- if (contextEditing && contextEditing.cellElement) {
257
- anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
258
- setLocalEditing(true);
339
+ ], value);
340
+ }
341
+ contextEditing?.cellElement?.focus();
342
+ setEditing(null);
343
+ setLocalEditing(false);
344
+ onSave?.();
345
+ }, [
346
+ fieldProjection.field.path,
347
+ onSave,
348
+ contextEditing,
349
+ originalRow,
350
+ model
351
+ ]);
352
+ const handleCreate = useCallback((schema2, values) => {
353
+ const objectWithId = onCreate?.(schema2, values);
354
+ if (objectWithId && originalRow) {
355
+ const ref = Ref2.make(objectWithId);
356
+ const path = fieldProjection.field.path;
357
+ if (model) {
358
+ model.changeRow(originalRow, (mutableRow) => {
359
+ setDeep(mutableRow, [
360
+ path
361
+ ], ref);
362
+ });
259
363
  } else {
260
- anchorRef.current = null;
261
- setLocalEditing(false);
364
+ setDeep(originalRow, [
365
+ path
366
+ ], ref);
262
367
  }
263
- }, [
264
- contextEditing
265
- ]);
266
- const narrowedSchema = useMemo(() => {
267
- if (!schema) {
268
- return void 0;
269
- }
270
- return narrowSchema(schema, [
271
- fieldProjection.field.path
272
- ]);
273
- }, [
274
- JSON.stringify(schema),
275
- fieldProjection.field.path
276
- ]);
277
- const formValues = useMemo(() => originalRow ? getSnapshot(originalRow) : {}, [
278
- originalRow
279
- ]);
280
- const handleOpenChange = useCallback((nextOpen) => {
281
- if (nextOpen === false) {
282
- setEditing(null);
283
- onSave?.();
284
- }
285
- setLocalEditing(nextOpen);
286
- }, []);
287
- if (!editing) {
288
- return null;
289
368
  }
290
- return /* @__PURE__ */ React2.createElement(Popover.Root, {
291
- open: editing,
292
- onOpenChange: handleOpenChange
293
- }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
294
- virtualRef: anchorRef
295
- }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
296
- tabIndex: -1,
297
- classNames: "popover-card-width density-fine"
298
- }, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form, {
299
- autoFocus: true,
300
- values: formValues,
301
- schema: narrowedSchema,
302
- onSave: handleSave,
303
- ...formProps,
304
- onQueryRefOptions: handleQueryRefOptions,
305
- onCreateFromQuery: handleCreateFromQuery,
306
- createOptionIcon: "ph--plus--regular",
307
- createOptionLabel
308
- })))));
309
- } finally {
310
- _effect.f();
369
+ contextEditing?.cellElement?.focus();
370
+ setEditing(null);
371
+ setLocalEditing(false);
372
+ onSave?.();
373
+ }, [
374
+ fieldProjection.field.path,
375
+ onSave,
376
+ contextEditing,
377
+ originalRow,
378
+ onCreate,
379
+ model
380
+ ]);
381
+ const getOptions = useCallback((results) => results.map((obj) => {
382
+ return {
383
+ id: Entity.getDXN(obj).toString(),
384
+ label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
385
+ };
386
+ }).filter(isTruthy), [
387
+ fieldProjection
388
+ ]);
389
+ if (!editing) {
390
+ return null;
311
391
  }
392
+ return /* @__PURE__ */ React2.createElement(Popover.Root, {
393
+ open: editing,
394
+ onOpenChange: handleOpenChange
395
+ }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
396
+ virtualRef: anchorRef
397
+ }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
398
+ tabIndex: -1,
399
+ classNames: "dx-card-popover-width dx-density-fine"
400
+ }, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Root, {
401
+ ...formProps,
402
+ autoFocus: true,
403
+ schema: narrowedSchema,
404
+ values: formValues,
405
+ onValuesChanged: handleValuesChanged,
406
+ projection: model?.projection,
407
+ createInitialValuePath: fieldProjection.field.referencePath,
408
+ createOptionIcon: "ph--plus--regular",
409
+ createOptionLabel,
410
+ db: model?.db,
411
+ getOptions,
412
+ onCreate: handleCreate,
413
+ onSave: handleSave
414
+ }, /* @__PURE__ */ React2.createElement(Form.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Content, null, /* @__PURE__ */ React2.createElement(Form.FieldSet, null), /* @__PURE__ */ React2.createElement(Form.Actions, null))))))));
312
415
  };
313
416
 
314
417
  // src/components/TableCellEditor/TableCellEditor.tsx
315
418
  var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
316
- var adaptValidationMessage = (message) => message ? message.endsWith("is missing") ? "Can\u2019t be blank" : message : null;
317
- var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __gridScope }) => {
318
- var _effect = _useSignals3();
319
- try {
320
- const { editing } = useGridContext3("TableValueEditor", __gridScope);
321
- const fieldProjection = useMemo2(() => {
322
- if (!model || !editing) {
323
- return;
324
- }
325
- const { col } = parseCellIndex2(editing.index);
326
- const field = model.projection.fields[col];
327
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
328
- invariant2(fieldProjection2, void 0, {
329
- F: __dxlog_file2,
330
- L: 71,
331
- S: void 0,
332
- A: [
333
- "fieldProjection",
334
- ""
335
- ]
336
- });
337
- return fieldProjection2;
338
- }, [
339
- model,
340
- editing
341
- ]);
342
- if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === FormatEnum.SingleSelect || fieldProjection?.props.format === FormatEnum.Ref) {
343
- return /* @__PURE__ */ React3.createElement(FormCellEditor, {
344
- fieldProjection,
345
- model,
346
- schema,
347
- __gridScope,
348
- onSave,
349
- client,
350
- modals
351
- });
419
+ var TableValueEditor = ({ __gridScope, schema, model, modals, onFocus, onSave, onCreate }) => {
420
+ const { editing } = useGridContext3("TableValueEditor", __gridScope);
421
+ const fieldProjection = useMemo2(() => {
422
+ if (!model || !editing) {
423
+ return;
352
424
  }
353
- return /* @__PURE__ */ React3.createElement(TableCellEditor, {
425
+ const { col } = parseCellIndex2(editing.index);
426
+ const field = model.projection.getFields()[col];
427
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
428
+ invariant2(fieldProjection2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 21, S: void 0, A: ["fieldProjection", ""] });
429
+ return fieldProjection2;
430
+ }, [
431
+ model,
432
+ editing
433
+ ]);
434
+ if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === Format.TypeFormat.SingleSelect || fieldProjection?.props.format === Format.TypeFormat.Ref) {
435
+ return /* @__PURE__ */ React3.createElement(FormCellEditor, {
436
+ __gridScope,
437
+ schema,
354
438
  model,
439
+ fieldProjection,
355
440
  modals,
356
- onFocus,
357
441
  onSave,
358
- __gridScope
442
+ onCreate
359
443
  });
360
- } finally {
361
- _effect.f();
362
- }
363
- };
364
- var editorSlots = {
365
- scroll: {
366
- className: "!plb-[--dx-grid-cell-editor-padding-block]"
367
444
  }
445
+ return /* @__PURE__ */ React3.createElement(TableCellEditor, {
446
+ model,
447
+ modals,
448
+ onFocus,
449
+ onSave,
450
+ __gridScope
451
+ });
368
452
  };
369
- var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
370
- var _effect = _useSignals3();
371
- try {
372
- const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
373
- const suppressNextBlur = useRef2(false);
374
- const [validationError, setValidationError] = useState2(null);
375
- const [validationVariant, setValidationVariant] = useState2("error");
376
- const fieldProjection = useMemo2(() => {
377
- if (!model || !editing) {
378
- return;
379
- }
380
- const { col } = parseCellIndex2(editing.index);
381
- const field = model.projection.fields[col];
382
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
383
- invariant2(fieldProjection2, void 0, {
384
- F: __dxlog_file2,
385
- L: 120,
386
- S: void 0,
387
- A: [
388
- "fieldProjection",
389
- ""
390
- ]
391
- });
392
- return fieldProjection2;
393
- }, [
394
- model,
395
- editing
396
- ]);
397
- const handleEnter = useCallback2(async (value) => {
398
- if (!model || !editing) {
399
- return;
400
- }
401
- const cell = parseCellIndex2(editing.index);
402
- const validationResult = await model.validateCellData(cell, value);
403
- if (validationResult.valid) {
404
- setValidationError(null);
405
- model.setCellData(cell, value);
406
- onFocus?.();
407
- setEditing(null);
408
- onSave?.();
409
- } else {
410
- setValidationError(adaptValidationMessage(validationResult.error));
411
- setValidationVariant("error");
412
- }
413
- }, [
414
- model,
415
- editing,
416
- onFocus,
417
- setEditing
418
- ]);
419
- const handleBlur = useCallback2(async (value) => {
420
- if (suppressNextBlur.current) {
421
- suppressNextBlur.current = false;
422
- } else if (model && editing) {
423
- const cell = parseCellIndex2(editing.index);
424
- if (value !== void 0) {
425
- const result = await model.validateCellData(cell, value);
426
- if (result.valid) {
427
- setValidationError(null);
428
- model.setCellData(cell, value);
429
- setEditing(null);
430
- onSave?.();
431
- }
432
- }
433
- }
434
- }, [
435
- model,
436
- editing
437
- ]);
438
- const handleClose = useCallback2(async (value, event) => {
439
- if (!model || !editing || !fieldProjection) {
440
- return;
441
- }
453
+ var TableCellEditor = ({ __gridScope, model, modals, onFocus, onSave }) => {
454
+ const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
455
+ const suppressNextBlur = useRef2(false);
456
+ const [validationError, setValidationError] = useState2(null);
457
+ const [validationVariant, setValidationVariant] = useState2("error");
458
+ const fieldProjection = useMemo2(() => {
459
+ if (!model || !editing) {
460
+ return;
461
+ }
462
+ const { col } = parseCellIndex2(editing.index);
463
+ const field = model.projection.getFields()[col];
464
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
465
+ invariant2(fieldProjection2, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 59, S: void 0, A: ["fieldProjection", ""] });
466
+ return fieldProjection2;
467
+ }, [
468
+ model,
469
+ editing
470
+ ]);
471
+ const handleEnter = useCallback2(async (value) => {
472
+ if (!model || !editing) {
473
+ return;
474
+ }
475
+ const cell = parseCellIndex2(editing.index);
476
+ const validationResult = await model.validateCellData(cell, value);
477
+ if (validationResult.valid) {
478
+ setValidationError(null);
479
+ model.setCellData(cell, value);
480
+ onFocus?.();
481
+ setEditing(null);
482
+ onSave?.();
483
+ } else {
484
+ setValidationError(validationResult.error);
485
+ setValidationVariant("error");
486
+ }
487
+ }, [
488
+ model,
489
+ editing,
490
+ onFocus,
491
+ setEditing
492
+ ]);
493
+ const handleBlur = useCallback2(async (value) => {
494
+ if (suppressNextBlur.current) {
495
+ suppressNextBlur.current = false;
496
+ } else if (model && editing) {
442
497
  const cell = parseCellIndex2(editing.index);
443
498
  if (value !== void 0) {
444
499
  const result = await model.validateCellData(cell, value);
445
500
  if (result.valid) {
446
- suppressNextBlur.current = true;
447
501
  setValidationError(null);
448
502
  model.setCellData(cell, value);
449
503
  setEditing(null);
450
504
  onSave?.();
451
- if (event && onFocus) {
452
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event), cell);
453
- }
454
- } else {
455
- setValidationError(result.error);
456
- setValidationVariant("error");
457
505
  }
458
- } else {
506
+ }
507
+ }
508
+ }, [
509
+ model,
510
+ editing
511
+ ]);
512
+ const handleClose = useCallback2(async (value, event) => {
513
+ if (!model || !editing || !fieldProjection) {
514
+ return;
515
+ }
516
+ const cell = parseCellIndex2(editing.index);
517
+ if (value !== void 0) {
518
+ const result = await model.validateCellData(cell, value);
519
+ if (result.valid) {
459
520
  suppressNextBlur.current = true;
460
521
  setValidationError(null);
522
+ model.setCellData(cell, value);
461
523
  setEditing(null);
462
524
  onSave?.();
463
525
  if (event && onFocus) {
464
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
526
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event), cell);
465
527
  }
528
+ } else {
529
+ setValidationError(result.error);
530
+ setValidationVariant("error");
466
531
  }
467
- }, [
468
- model,
469
- editing,
470
- onFocus,
471
- fieldProjection,
472
- setEditing,
473
- onSave
474
- ]);
475
- const extensions = useMemo2(() => {
476
- if (!fieldProjection) {
477
- return [];
478
- }
479
- const extensions2 = [
480
- editorKeys({
481
- onClose: handleClose,
482
- ...editing?.initialContent && {
483
- onNav: handleClose
484
- }
485
- })
486
- ];
487
- const format = fieldProjection.props.format;
488
- if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
489
- const options = fieldProjection.props.options || [];
490
- const mode = format === FormatEnum.SingleSelect ? "single-select" : "multi-select";
491
- extensions2.push(createMarkdownExtensions());
492
- extensions2.push(tagPicker({
493
- mode,
494
- keymap: false,
495
- onSearch: (text, selectedIds) => {
496
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
497
- id: option.id,
498
- label: option.title,
499
- hue: option.color
500
- }));
501
- },
502
- onUpdate: (ids) => {
503
- if (model && editing) {
504
- if (ids.length === 0) {
505
- return;
506
- }
507
- if (mode === "single-select") {
508
- void handleEnter(ids[0]);
509
- } else {
510
- void handleEnter(ids);
511
- }
512
- }
513
- }
514
- }));
515
- }
516
- if (model && editing) {
517
- extensions2.push(EditorView.updateListener.of(debounce((update) => {
518
- const content = update.state.doc.toString();
519
- const cell = parseCellIndex2(editing.index);
520
- void model.validateCellData(cell, content).then((result) => {
521
- if (result.valid) {
522
- setValidationError(null);
523
- } else {
524
- setValidationError(result.error);
525
- setValidationVariant("error");
526
- }
527
- });
528
- }, 10)));
532
+ } else {
533
+ suppressNextBlur.current = true;
534
+ setValidationError(null);
535
+ setEditing(null);
536
+ onSave?.();
537
+ if (event && onFocus) {
538
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
529
539
  }
530
- return extensions2;
531
- }, [
532
- model,
533
- modals,
534
- editing,
535
- fieldProjection,
536
- handleClose
537
- ]);
538
- const getCellContent = useCallback2(() => {
539
- if (model && editing) {
540
+ }
541
+ }, [
542
+ model,
543
+ editing,
544
+ onFocus,
545
+ fieldProjection,
546
+ setEditing,
547
+ onSave
548
+ ]);
549
+ const extensions = useMemo2(() => {
550
+ if (!fieldProjection) {
551
+ return [];
552
+ }
553
+ const extensions2 = [
554
+ editorKeys({
555
+ onClose: handleClose,
556
+ ...editing?.initialContent && {
557
+ onNav: handleClose
558
+ }
559
+ })
560
+ ];
561
+ if (model && editing) {
562
+ extensions2.push(EditorView.updateListener.of(debounce((update) => {
563
+ const content = update.state.doc.toString();
540
564
  const cell = parseCellIndex2(editing.index);
541
- const { col } = cell;
542
- const field = model.projection.fields[col];
543
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
544
- if (fieldProjection2?.props.format === FormatEnum.SingleSelect || fieldProjection2?.props.format === FormatEnum.MultiSelect) {
545
- const value2 = model.getCellData(cell);
546
- if (value2 !== void 0) {
547
- const options = fieldProjection2.props.options || [];
548
- if (fieldProjection2.props.format === FormatEnum.MultiSelect) {
549
- const tagItems = value2.split(",").map((id) => {
550
- const option = options.find((o) => o.id === id);
551
- if (option) {
552
- return {
553
- id,
554
- label: option.title,
555
- hue: option.color
556
- };
557
- }
558
- return void 0;
559
- }).filter((item) => item !== void 0);
560
- return createLinks(tagItems);
561
- } else {
562
- const option = options.find((o) => o.id === value2);
563
- if (option) {
564
- const tagItem = {
565
- id: value2,
566
- label: option.title,
567
- hue: option.color
568
- };
569
- return createLinks([
570
- tagItem
571
- ]);
572
- }
573
- }
565
+ void model.validateCellData(cell, content).then((result) => {
566
+ if (result.valid) {
567
+ setValidationError(null);
568
+ } else {
569
+ setValidationError(result.error);
570
+ setValidationVariant("error");
574
571
  }
575
- return "";
576
- }
577
- const value = model.getCellData(cell);
578
- return value !== void 0 ? String(value) : "";
572
+ });
573
+ }, 10)));
574
+ }
575
+ return extensions2;
576
+ }, [
577
+ model,
578
+ modals,
579
+ editing,
580
+ fieldProjection,
581
+ handleClose
582
+ ]);
583
+ const getCellContent = useCallback2(() => {
584
+ if (model && editing) {
585
+ const cell = parseCellIndex2(editing.index);
586
+ const value = model.getCellData(cell);
587
+ return value !== void 0 ? String(value) : "";
588
+ }
589
+ }, [
590
+ model,
591
+ editing
592
+ ]);
593
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CellValidationMessage, {
594
+ validationError,
595
+ variant: validationVariant,
596
+ __gridScope
597
+ }), /* @__PURE__ */ React3.createElement(GridCellEditor, {
598
+ extensions,
599
+ slots: {
600
+ content: {
601
+ className: "!py-(--dx-grid-cell-editor-padding-block)"
579
602
  }
580
- }, [
581
- model,
582
- editing
583
- ]);
584
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CellValidationMessage, {
585
- validationError,
586
- variant: validationVariant,
587
- __gridScope
588
- }), /* @__PURE__ */ React3.createElement(GridCellEditor, {
589
- extensions,
590
- getCellContent,
591
- onBlur: handleBlur,
592
- slots: editorSlots
593
- }));
594
- } finally {
595
- _effect.f();
596
- }
603
+ },
604
+ getCellContent,
605
+ onBlur: handleBlur
606
+ }));
597
607
  };
598
608
  var determineNavigationAxis = ({ key }) => {
599
609
  switch (key) {
@@ -621,248 +631,142 @@ var determineNavigationDelta = ({ key, shift }) => {
621
631
  };
622
632
 
623
633
  // src/components/Table/ColumnActionsMenu.tsx
624
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
634
+ import { useAtomValue } from "@effect-atom/atom-react";
625
635
  import React4 from "react";
626
636
  import { DropdownMenu, useTranslation } from "@dxos/react-ui";
637
+ import { translationKey as translationKey2 } from "#translations";
627
638
  var ColumnActionsMenu = ({ model, modals }) => {
628
- var _effect = _useSignals4();
629
- try {
630
- const { t } = useTranslation(translationKey);
631
- const state = modals.state.value;
632
- if (state?.type !== "column") {
633
- return null;
634
- }
635
- const currentSort = model.sorting?.sorting;
636
- const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
637
- return /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
638
- modal: false,
639
- open: true,
640
- onOpenChange: modals.close
641
- }, /* @__PURE__ */ React4.createElement(DropdownMenu.VirtualTrigger, {
642
- virtualRef: modals.trigger
643
- }), /* @__PURE__ */ React4.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
644
- "data-testid": "column-sort-descending",
645
- onClick: () => model.sorting?.setSort(state.fieldId, "desc")
646
- }, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
647
- "data-testid": "column-sort-ascending",
648
- onClick: () => model.sorting?.setSort(state.fieldId, "asc")
649
- }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
650
- "data-testid": "column-clear-sort",
651
- onClick: () => model.sorting?.clearSort()
652
- }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
653
- "data-testid": "column-delete",
654
- onClick: () => model.deleteColumn(state.fieldId)
655
- }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
656
- "data-testid": "column-settings",
657
- onClick: () => modals.openColumnSettings()
658
- }, t("column action settings"))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))));
659
- } finally {
660
- _effect.f();
639
+ const { t } = useTranslation(translationKey2);
640
+ const state = useAtomValue(modals.state);
641
+ if (state?.type !== "column") {
642
+ return null;
661
643
  }
644
+ const currentSort = model.getSorting();
645
+ const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
646
+ return /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
647
+ modal: false,
648
+ open: true,
649
+ onOpenChange: modals.close
650
+ }, /* @__PURE__ */ React4.createElement(DropdownMenu.VirtualTrigger, {
651
+ virtualRef: modals.trigger
652
+ }), /* @__PURE__ */ React4.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
653
+ "data-testid": "column-sort-descending",
654
+ onClick: () => model.setSort(state.fieldId, "desc")
655
+ }, t("column-action-sort-descending.menu")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
656
+ "data-testid": "column-sort-ascending",
657
+ onClick: () => model.setSort(state.fieldId, "asc")
658
+ }, t("column-action-sort-ascending.menu")), isCurrentColumnSorted && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
659
+ "data-testid": "column-clear-sort",
660
+ onClick: () => model.clearSort()
661
+ }, t("column-action-clear-sorting.menu")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
662
+ "data-testid": "column-delete",
663
+ onClick: () => model.deleteColumn(state.fieldId)
664
+ }, t("column-action-delete.menu")), model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
665
+ "data-testid": "column-settings",
666
+ onClick: () => modals.openColumnSettings()
667
+ }, t("column-action-settings.menu"))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))));
662
668
  };
663
669
 
664
670
  // src/components/Table/ColumnSettings.tsx
665
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
671
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
666
672
  import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useState as useState3 } from "react";
667
673
  import { Popover as Popover2 } from "@dxos/react-ui";
668
674
  import { FieldEditor } from "@dxos/react-ui-form";
669
675
  var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
670
- var _effect = _useSignals5();
671
- try {
672
- const [newField, setNewField] = useState3();
673
- const state = modals.state.value;
674
- useEffect2(() => {
675
- if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
676
- setNewField(model.projection.createFieldProjection());
677
- requestAnimationFrame(() => {
678
- onNewColumn();
679
- });
680
- } else {
681
- setNewField(void 0);
682
- }
683
- }, [
684
- model?.projection,
685
- state
686
- ]);
687
- const existingField = useMemo3(() => {
688
- if (state?.type === "columnSettings") {
689
- const { mode } = state;
690
- if (mode.type === "edit") {
691
- return model?.projection?.fields.find((f) => f.id === mode.fieldId);
692
- }
693
- }
694
- return void 0;
695
- }, [
696
- model?.projection?.fields,
697
- state
698
- ]);
699
- const field = existingField ?? newField;
700
- const handleSave = useCallback3(() => {
701
- modals.close();
702
- }, [
703
- modals
704
- ]);
705
- const handleCancel = useCallback3(() => {
706
- if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
707
- model?.projection.deleteFieldProjection(newField.id);
708
- }
709
- }, [
710
- model?.projection,
711
- state,
712
- newField
713
- ]);
714
- if (!model?.projection || !field) {
715
- return null;
676
+ const [newField, setNewField] = useState3();
677
+ const state = useAtomValue2(modals.state);
678
+ useEffect2(() => {
679
+ if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
680
+ setNewField(model.projection.createFieldProjection());
681
+ requestAnimationFrame(() => {
682
+ onNewColumn();
683
+ });
684
+ } else {
685
+ setNewField(void 0);
716
686
  }
717
- return /* @__PURE__ */ React5.createElement(Popover2.Root, {
718
- modal: false,
719
- open: state?.type === "columnSettings"
720
- }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
721
- virtualRef: modals.trigger
722
- }), /* @__PURE__ */ React5.createElement(Popover2.Portal, null, /* @__PURE__ */ React5.createElement(Popover2.Content, {
723
- classNames: "md:is-64"
724
- }, /* @__PURE__ */ React5.createElement(Popover2.Viewport, null, /* @__PURE__ */ React5.createElement(FieldEditor, {
725
- projection: model.projection,
726
- field,
727
- registry,
728
- onSave: handleSave,
729
- onCancel: handleCancel
730
- })), /* @__PURE__ */ React5.createElement(Popover2.Arrow, null))));
731
- } finally {
732
- _effect.f();
733
- }
734
- };
735
-
736
- // src/components/Table/CreateRefPanel.tsx
737
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
738
- import { Schema } from "effect";
739
- import React6, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
740
- import { Type } from "@dxos/echo";
741
- import { live } from "@dxos/live-object";
742
- import { useClient } from "@dxos/react-client";
743
- import { getSpace as getSpace2 } from "@dxos/react-client/echo";
744
- import { Popover as Popover3 } from "@dxos/react-ui";
745
- import { Form as Form2 } from "@dxos/react-ui-form";
746
- import { useGridContext as useGridContext4 } from "@dxos/react-ui-grid";
747
- var CreateRefPanel = ({ model, modals, __gridScope }) => {
748
- var _effect = _useSignals6();
749
- try {
750
- const { id: gridId } = useGridContext4("TableCellEditor", __gridScope);
751
- const client = useClient();
752
- const space = model && getSpace2(model?.view);
753
- const state = modals.state.value;
754
- const getSchema = useCallback4(() => {
755
- if (!space || state?.type !== "createRefPanel") {
756
- return;
757
- }
758
- const staticSchema = client.graph.schemaRegistry.schemas.find((schema3) => Type.getTypename(schema3) === state.typename);
759
- if (staticSchema) {
760
- return staticSchema;
761
- }
762
- const [schema2] = space.db.schemaRegistry.query({
763
- typename: state.typename
764
- }).runSync();
765
- return schema2;
766
- }, [
767
- space,
768
- state
769
- ]);
770
- const schema = useMemo4(() => {
771
- const schema2 = getSchema();
772
- if (!schema2) {
773
- return;
687
+ }, [
688
+ model?.projection,
689
+ state
690
+ ]);
691
+ const existingField = useMemo3(() => {
692
+ if (state?.type === "columnSettings") {
693
+ const { mode } = state;
694
+ if (mode.type === "edit") {
695
+ return model?.projection?.getFields().find((f) => f.id === mode.fieldId);
774
696
  }
775
- const omit = Schema.omit("id");
776
- return omit(schema2);
777
- }, [
778
- getSchema
779
- ]);
780
- const handleSave = useCallback4((values) => {
781
- if (!model || !space || state?.type !== "createRefPanel") {
782
- return;
783
- }
784
- const schema2 = getSchema();
785
- if (schema2) {
786
- const obj = space.db.add(live(schema2, values));
787
- state.onCreate?.(obj);
788
- }
789
- void modals.close();
790
- }, [
791
- model,
792
- modals,
793
- space,
794
- state
795
- ]);
796
- const handleCancel = useCallback4(() => {
797
- if (model) {
798
- modals.close();
799
- }
800
- }, [
801
- modals
802
- ]);
803
- if (!model?.projection) {
804
- return null;
805
697
  }
806
- return /* @__PURE__ */ React6.createElement(Popover3.Root, {
807
- modal: false,
808
- open: state?.type === "createRefPanel" && !!schema,
809
- onOpenChange: (nextOpen) => {
810
- if (model && !nextOpen) {
811
- return modals.close();
812
- }
813
- }
814
- }, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
815
- virtualRef: modals.trigger
816
- }), /* @__PURE__ */ React6.createElement(Popover3.Portal, null, /* @__PURE__ */ React6.createElement(Popover3.Content, {
817
- classNames: "md:is-64",
818
- "data-grid": gridId
819
- }, /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React6.createElement(Form2, {
820
- schema,
821
- values: state.initialValues ?? {},
822
- onSave: handleSave,
823
- onCancel: handleCancel
824
- })), /* @__PURE__ */ React6.createElement(Popover3.Arrow, null))));
825
- } finally {
826
- _effect.f();
698
+ return void 0;
699
+ }, [
700
+ model?.projection,
701
+ state
702
+ ]);
703
+ const field = existingField ?? newField;
704
+ const handleSave = useCallback3(() => {
705
+ modals.close();
706
+ }, [
707
+ modals
708
+ ]);
709
+ const handleCancel = useCallback3(() => {
710
+ if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
711
+ model?.projection.deleteFieldProjection(newField.id);
712
+ }
713
+ }, [
714
+ model?.projection,
715
+ state,
716
+ newField
717
+ ]);
718
+ if (!model?.projection || !field) {
719
+ return null;
827
720
  }
721
+ return /* @__PURE__ */ React5.createElement(Popover2.Root, {
722
+ modal: false,
723
+ open: state?.type === "columnSettings"
724
+ }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
725
+ virtualRef: modals.trigger
726
+ }), /* @__PURE__ */ React5.createElement(Popover2.Portal, null, /* @__PURE__ */ React5.createElement(Popover2.Content, {
727
+ classNames: "md:w-64"
728
+ }, /* @__PURE__ */ React5.createElement(Popover2.Viewport, null, /* @__PURE__ */ React5.createElement(FieldEditor, {
729
+ projection: model.projection,
730
+ field,
731
+ registry,
732
+ onSave: handleSave,
733
+ onCancel: handleCancel
734
+ })), /* @__PURE__ */ React5.createElement(Popover2.Arrow, null))));
828
735
  };
829
736
 
830
737
  // src/components/Table/RowActionsMenu.tsx
831
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
832
- import React7 from "react";
738
+ import { useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
739
+ import React6 from "react";
833
740
  import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
741
+ import { translationKey as translationKey3 } from "#translations";
834
742
  var RowActionsMenu = ({ model, modals }) => {
835
- var _effect = _useSignals7();
836
- try {
837
- const { t } = useTranslation2(translationKey);
838
- const hasSelection = model.selection.hasSelection.value;
839
- const state = modals.state.value;
840
- if (state?.type !== "row") {
841
- return null;
842
- }
843
- return /* @__PURE__ */ React7.createElement(DropdownMenu2.Root, {
844
- modal: false,
845
- open: true,
846
- onOpenChange: modals.close
847
- }, /* @__PURE__ */ React7.createElement(DropdownMenu2.VirtualTrigger, {
848
- virtualRef: modals.trigger
849
- }), /* @__PURE__ */ React7.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React7.createElement(DropdownMenu2.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
850
- "data-testid": "row-menu-delete",
851
- onClick: () => model.deleteRow(state.rowIndex)
852
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
853
- key: action.id,
854
- "data-testid": `row-action-${action.id}`,
855
- onClick: () => {
856
- modals.close();
857
- model.handleRowAction(action.id, state.rowIndex);
858
- }
859
- }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React7.createElement(DropdownMenu2.Arrow, null)));
860
- } finally {
861
- _effect.f();
743
+ const { t } = useTranslation2(translationKey3);
744
+ const hasSelection = model.selection.hasSelection;
745
+ const state = useAtomValue3(modals.state);
746
+ if (state?.type !== "row") {
747
+ return null;
862
748
  }
749
+ return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
750
+ modal: false,
751
+ open: true,
752
+ onOpenChange: modals.close
753
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
754
+ virtualRef: modals.trigger
755
+ }), /* @__PURE__ */ React6.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Viewport, null, model.rowActions?.length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Group, null, model.rowActions?.map((action) => /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
756
+ key: action.id,
757
+ "data-testid": `row-action-${action.id}`,
758
+ onClick: () => {
759
+ modals.close();
760
+ model.handleRowAction(action.id, state.rowIndex);
761
+ }
762
+ }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
763
+ "data-testid": "row-menu-delete",
764
+ onClick: () => model.deleteRow(state.rowIndex)
765
+ }, t(hasSelection ? "bulk-delete-row.label" : "delete-row.label"))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
863
766
  };
864
767
 
865
- // src/components/Table/Table.tsx
768
+ // src/components/Table/TableContent.tsx
769
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/Table/TableContent.tsx";
866
770
  var columnDefault = {
867
771
  grid: {
868
772
  minSize: 80,
@@ -875,480 +779,412 @@ var rowDefault = {
875
779
  focusUnfurl: false
876
780
  }
877
781
  };
878
- var TableRoot = ({ children, role = "article" }) => {
879
- var _effect = _useSignals8();
880
- try {
881
- return /* @__PURE__ */ React8.createElement("div", {
882
- role: "none",
883
- className: mx("relative !border-separator [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]", role === "card--popover" && "popover-card-height", role === "section" && "attention-surface", role === "card--intrinsic" && "[&_.dx-grid]:bs-[--dx-grid-content-block-size]", [
884
- "card--popover",
885
- "section",
886
- "card--extrinsic"
887
- ].includes(role) && "overflow-hidden", [
888
- "article",
889
- "slide"
890
- ].includes(role) && "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:bs-0")
891
- }, children);
892
- } finally {
893
- _effect.f();
894
- }
895
- };
896
- var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
897
- var _effect = _useSignals8();
898
- try {
899
- const [dxGrid, setDxGrid] = useState4(null);
900
- const { hasAttention } = useAttention(model?.id ?? "table");
901
- const modals = useMemo5(() => new ModalController(), []);
902
- const draftRowCount = model?.getDraftRowCount() ?? 0;
903
- const handleSave = useCallback5(() => {
904
- dxGrid?.updateCells(true);
905
- dxGrid?.requestUpdate();
906
- }, [
907
- dxGrid
908
- ]);
909
- const frozen = useMemo5(() => {
910
- const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
911
- return {
912
- frozenRowsStart: 1,
913
- frozenRowsEnd: Math.max(1, draftRowCount),
914
- frozenColsStart: model?.features.selection.enabled ? 1 : 0,
915
- frozenColsEnd: noActionColumn ? 0 : 1
916
- };
917
- }, [
918
- model,
919
- draftRowCount
920
- ]);
921
- const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
922
- presentation
923
- ]);
924
- useEffect3(() => {
925
- if (!presentation || !dxGrid) {
926
- return;
927
- }
928
- dxGrid.getCells = getCells;
929
- }, [
930
- presentation,
931
- dxGrid,
932
- getCells
933
- ]);
934
- const handleInsertRowResult = useCallback5((insertResult) => {
935
- if (insertResult === "draft") {
936
- requestAnimationFrame(() => {
937
- dxGrid?.setFocus({
938
- plane: "frozenRowsEnd",
939
- col: 0,
940
- row: 0
941
- });
942
- dxGrid?.refocus();
782
+ var emptyColumnMeta = Atom2.make({
783
+ grid: {}
784
+ });
785
+ var emptyRowsAtom = Atom2.make([]);
786
+ var emptyCellUpdateAtom = Atom2.make(0);
787
+ var TABLE_CONTENT_NAME = "Table.Content";
788
+ var TableContent = composable(({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId, ...props }, forwardedRef) => {
789
+ const registry = useContext(RegistryContext);
790
+ const [dxGrid, setDxGrid] = useState4(null);
791
+ const { hasAttention } = useAttention(model?.id ?? "table");
792
+ const modals = useMemo4(() => new ModalController(registry), [
793
+ registry
794
+ ]);
795
+ const columnMeta = useAtomValue4(model?.columnMeta ?? emptyColumnMeta);
796
+ const rows = useAtomValue4(model?.rows ?? emptyRowsAtom);
797
+ const cellUpdateCounter = useAtomValue4(model?.cellUpdate ?? emptyCellUpdateAtom);
798
+ const columnCount = Object.keys(columnMeta.grid).length || model?.projection.getFields().length || 0;
799
+ const draftRowCount = model?.getDraftRowCount() ?? 0;
800
+ const frozen = useMemo4(() => {
801
+ const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
802
+ return {
803
+ frozenRowsStart: 1,
804
+ frozenRowsEnd: Math.max(1, draftRowCount),
805
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
806
+ frozenColsEnd: noActionColumn ? 0 : 1
807
+ };
808
+ }, [
809
+ model,
810
+ draftRowCount
811
+ ]);
812
+ const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
813
+ presentation
814
+ ]);
815
+ useEffect3(() => {
816
+ if (!dxGrid || !presentation) {
817
+ return;
818
+ }
819
+ dxGrid.getCells = getCells;
820
+ }, [
821
+ dxGrid,
822
+ presentation,
823
+ getCells
824
+ ]);
825
+ useEffect3(() => {
826
+ if (!dxGrid) {
827
+ return;
828
+ }
829
+ dxGrid.updateCells(true);
830
+ dxGrid.requestUpdate();
831
+ }, [
832
+ dxGrid,
833
+ rows,
834
+ cellUpdateCounter
835
+ ]);
836
+ const handleInsertRowResult = useCallback4((insertResult) => {
837
+ if (insertResult === "draft") {
838
+ requestAnimationFrame(() => {
839
+ dxGrid?.setFocus({
840
+ plane: "frozenRowsEnd",
841
+ col: 0,
842
+ row: 0
943
843
  });
944
- } else {
844
+ dxGrid?.refocus();
845
+ });
846
+ } else {
847
+ requestAnimationFrame(() => {
848
+ dxGrid?.setFocus({
849
+ plane: "grid",
850
+ col: 0,
851
+ row: model ? model.getRowCount() - 1 : 0
852
+ });
853
+ dxGrid?.refocus();
854
+ });
855
+ }
856
+ }, [
857
+ model,
858
+ dxGrid
859
+ ]);
860
+ const handleSave = useCallback4(() => {
861
+ dxGrid?.updateCells(true);
862
+ dxGrid?.requestUpdate();
863
+ }, [
864
+ dxGrid
865
+ ]);
866
+ const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
867
+ if (model && dxGrid) {
868
+ const didCommitSuccessfully = model.commitDraftRow(rowIndex);
869
+ if (didCommitSuccessfully) {
945
870
  requestAnimationFrame(() => {
946
- dxGrid?.setFocus({
947
- plane: "grid",
948
- col: 0,
949
- row: model ? model.getRowCount() - 1 : 0
950
- });
951
- dxGrid?.refocus();
871
+ dxGrid.scrollToEndRow();
952
872
  });
953
873
  }
954
- }, [
955
- model,
956
- dxGrid
957
- ]);
958
- useImperativeHandle(forwardedRef, () => {
959
- if (!presentation || !dxGrid) {
960
- return {};
961
- }
962
- return {
963
- update: (cell) => {
964
- if (cell) {
965
- dxGrid.updateIfWithinBounds(cell, true);
966
- } else {
967
- dxGrid.updateCells(true);
968
- dxGrid.requestUpdate();
969
- }
970
- },
971
- handleInsertRowResult
972
- };
973
- }, [
974
- presentation,
975
- dxGrid,
976
- model
977
- ]);
978
- const handleSaveDraftRow = useCallback5((rowIndex = 0) => {
979
- if (model && dxGrid) {
980
- const didCommitSuccessfully = model.commitDraftRow(rowIndex);
981
- if (didCommitSuccessfully) {
982
- requestAnimationFrame(() => {
983
- dxGrid.scrollToEndRow();
984
- });
874
+ }
875
+ }, [
876
+ model,
877
+ dxGrid
878
+ ]);
879
+ const handleGridClick = useCallback4((event) => {
880
+ const cell = closestCell(event.target);
881
+ if (cell) {
882
+ const { row: rowIndex, plane } = cell;
883
+ if (onRowClick) {
884
+ if (plane === "grid") {
885
+ const row = model?.getRowAt(rowIndex);
886
+ row && onRowClick(row);
887
+ } else {
888
+ onRowClick(cell);
985
889
  }
986
890
  }
987
- }, [
988
- model,
989
- dxGrid
990
- ]);
991
- const handleGridClick = useCallback5((event) => {
992
- const cell = closestCell(event.target);
993
- if (cell) {
994
- const { row: rowIndex, plane } = cell;
995
- if (onRowClick) {
996
- if (plane === "grid") {
997
- const row = model?.getRowAt(rowIndex);
998
- row && onRowClick(row);
999
- } else {
1000
- onRowClick(cell);
1001
- }
1002
- }
1003
- if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
1004
- model.selection.toggleSelectionForRowIndex(rowIndex);
1005
- }
891
+ if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
892
+ model.selection.toggleSelectionForRowIndex(rowIndex);
1006
893
  }
1007
- if (!modals) {
894
+ }
895
+ if (!modals) {
896
+ return;
897
+ }
898
+ const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
899
+ const tableButtonElement = event.target.closest(buttonSelector);
900
+ if (tableButtonElement) {
901
+ const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
902
+ if (!button) {
1008
903
  return;
1009
904
  }
1010
- const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
1011
- const tableButtonElement = event.target.closest(buttonSelector);
1012
- if (tableButtonElement) {
1013
- const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
1014
- if (!button) {
1015
- return;
905
+ modals.setTrigger(tableButtonElement);
906
+ const data = button.getData(tableButtonElement);
907
+ switch (data.type) {
908
+ case "rowMenu": {
909
+ modals.showRowMenu(data.rowIndex);
910
+ break;
1016
911
  }
1017
- modals.setTrigger(tableButtonElement);
1018
- const data = button.getData(tableButtonElement);
1019
- switch (data.type) {
1020
- case "rowMenu": {
1021
- modals.showRowMenu(data.rowIndex);
1022
- break;
1023
- }
1024
- case "columnSettings": {
1025
- modals.showColumnMenu(data.fieldId);
1026
- break;
1027
- }
1028
- case "newColumn": {
1029
- modals.showColumnCreator();
1030
- break;
1031
- }
1032
- case "sort": {
1033
- model?.sorting?.toggleSort(data.fieldId);
1034
- break;
1035
- }
1036
- case "saveDraftRow": {
1037
- handleSaveDraftRow();
1038
- break;
1039
- }
912
+ case "columnSettings": {
913
+ modals.showColumnMenu(data.fieldId);
914
+ break;
1040
915
  }
1041
- return;
1042
- }
1043
- const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
1044
- const controlElement = event.target.closest(controlSelector);
1045
- if (controlElement) {
1046
- const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
1047
- if (!control) {
1048
- return;
916
+ case "newColumn": {
917
+ modals.showColumnCreator();
918
+ break;
1049
919
  }
1050
- const data = control.getData(controlElement);
1051
- switch (data.type) {
1052
- case "checkbox": {
1053
- if (data.header) {
1054
- model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
1055
- } else {
1056
- model?.selection.toggleSelectionForRowIndex(data.rowIndex);
1057
- }
1058
- break;
1059
- }
1060
- case "switch": {
1061
- if (model) {
1062
- model.updateCellData({
1063
- row: data.rowIndex,
1064
- col: data.colIndex
1065
- }, (value) => !value);
1066
- }
1067
- break;
1068
- }
920
+ case "sort": {
921
+ model?.toggleSort(data.fieldId);
922
+ break;
1069
923
  }
1070
- }
1071
- }, [
1072
- model,
1073
- modals,
1074
- dxGrid
1075
- ]);
1076
- const handleFocus = useCallback5((increment, delta, cell) => {
1077
- if (dxGrid && model) {
1078
- if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1) {
1079
- handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
1080
- } else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
1081
- handleSaveDraftRow(cell.row);
1082
- handleInsertRowResult(model.insertRow());
1083
- } else {
1084
- dxGrid.refocus(increment, delta);
924
+ case "saveDraftRow": {
925
+ handleSaveDraftRow();
926
+ break;
1085
927
  }
1086
928
  }
1087
- }, [
1088
- dxGrid,
1089
- model
1090
- ]);
1091
- const handleKeyDown = useCallback5((event) => {
1092
- if (!model?.features.dataEditable) {
1093
- return;
1094
- }
1095
- const cell = closestCell(event.target);
1096
- if (!model || !cell) {
929
+ return;
930
+ }
931
+ const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
932
+ const controlElement = event.target.closest(controlSelector);
933
+ if (controlElement) {
934
+ const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
935
+ if (!control) {
1097
936
  return;
1098
937
  }
1099
- if (event.metaKey || event.ctrlKey) {
1100
- switch (event.key) {
1101
- case "c": {
1102
- try {
1103
- const cellData = model.getCellData(cell);
1104
- const textContent = cellData?.toString() ?? "";
1105
- void navigator.clipboard.writeText(textContent);
1106
- event.preventDefault();
1107
- } catch (error) {
1108
- console.warn("Failed to copy cell content:", error);
1109
- }
1110
- break;
938
+ const data = control.getData(controlElement);
939
+ switch (data.type) {
940
+ case "checkbox": {
941
+ if (data.header) {
942
+ model?.selection.setSelection(model.selection.allRowsSelected ? "none" : "all");
943
+ } else {
944
+ model?.selection.toggleSelectionForRowIndex(data.rowIndex);
1111
945
  }
1112
- case "v": {
1113
- event.preventDefault();
1114
- void navigator.clipboard.readText().then((clipboardText) => {
1115
- try {
1116
- model.setCellData(cell, clipboardText);
1117
- handleSave();
1118
- } catch {
1119
- const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
1120
- if (cellElement) {
1121
- const rect = cellElement.getBoundingClientRect();
1122
- const editRequest = new DxEditRequest({
1123
- cellIndex: `${cell.plane},${cell.col},${cell.row}`,
1124
- cellBox: {
1125
- insetInlineStart: rect.left,
1126
- insetBlockStart: rect.top,
1127
- inlineSize: rect.width,
1128
- blockSize: rect.height
1129
- },
1130
- cellElement,
1131
- initialContent: clipboardText
1132
- });
1133
- cellElement.dispatchEvent(editRequest);
1134
- }
1135
- }
1136
- });
1137
- break;
946
+ break;
947
+ }
948
+ case "switch": {
949
+ if (model) {
950
+ model.updateCellData({
951
+ row: data.rowIndex,
952
+ col: data.colIndex
953
+ }, (value) => !value);
1138
954
  }
955
+ break;
1139
956
  }
1140
957
  }
958
+ }
959
+ }, [
960
+ model,
961
+ modals,
962
+ dxGrid
963
+ ]);
964
+ const handleFocus = useCallback4((increment, delta, cell) => {
965
+ if (dxGrid && model) {
966
+ if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
967
+ handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
968
+ } else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
969
+ handleSaveDraftRow(cell.row);
970
+ handleInsertRowResult(model.insertRow());
971
+ } else {
972
+ dxGrid.refocus(increment, delta);
973
+ }
974
+ }
975
+ }, [
976
+ dxGrid,
977
+ model
978
+ ]);
979
+ const handleKeyDown = useCallback4((event) => {
980
+ if (!model?.features.dataEditable) {
981
+ return;
982
+ }
983
+ const cell = closestCell(event.target);
984
+ if (!model || !cell) {
985
+ return;
986
+ }
987
+ if (event.metaKey || event.ctrlKey) {
1141
988
  switch (event.key) {
1142
- case "Backspace":
1143
- case "Delete": {
989
+ case "c": {
1144
990
  try {
1145
- model.setCellData(cell, void 0);
991
+ const cellData = model.getCellData(cell);
992
+ const textContent = cellData?.toString() ?? "";
993
+ void navigator.clipboard.writeText(textContent);
1146
994
  event.preventDefault();
1147
- } catch {
995
+ } catch (error) {
996
+ log.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 262, S: void 0 });
1148
997
  }
1149
998
  break;
1150
999
  }
1000
+ case "v": {
1001
+ event.preventDefault();
1002
+ void navigator.clipboard.readText().then((clipboardText) => {
1003
+ try {
1004
+ model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
1005
+ handleSave();
1006
+ } catch {
1007
+ const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
1008
+ if (cellElement) {
1009
+ const rect = cellElement.getBoundingClientRect();
1010
+ const editRequest = new DxEditRequest({
1011
+ cellIndex: `${cell.plane},${cell.col},${cell.row}`,
1012
+ cellBox: {
1013
+ insetInlineStart: rect.left,
1014
+ insetBlockStart: rect.top,
1015
+ inlineSize: rect.width,
1016
+ blockSize: rect.height
1017
+ },
1018
+ cellElement,
1019
+ initialContent: clipboardText
1020
+ });
1021
+ cellElement.dispatchEvent(editRequest);
1022
+ }
1023
+ }
1024
+ });
1025
+ break;
1026
+ }
1151
1027
  }
1152
- }, [
1153
- model,
1154
- dxGrid,
1155
- handleSave
1156
- ]);
1157
- const handleAxisResize = useCallback5((event) => {
1158
- if (event.axis === "col") {
1159
- const columnIndex = parseInt(event.index, 10);
1160
- model?.setColumnWidth(columnIndex, event.size);
1161
- }
1162
- }, [
1163
- model
1164
- ]);
1165
- const handleWheel = useCallback5((event) => {
1166
- if (!ignoreAttention && !hasAttention) {
1167
- event.stopPropagation();
1168
- }
1169
- }, [
1170
- hasAttention,
1171
- ignoreAttention
1172
- ]);
1173
- const handleNewColumn = useCallback5(() => {
1174
- const columns = model?.getColumnCount();
1175
- if (dxGrid && columns) {
1176
- dxGrid.scrollToColumn(columns - 1);
1028
+ }
1029
+ switch (event.key) {
1030
+ case "Backspace":
1031
+ case "Delete": {
1032
+ try {
1033
+ model.setCellData(cell, void 0);
1034
+ event.preventDefault();
1035
+ handleSave();
1036
+ } catch {
1037
+ }
1038
+ break;
1177
1039
  }
1178
- }, [
1179
- model,
1180
- dxGrid
1181
- ]);
1182
- if (!model || !modals) {
1183
- return /* @__PURE__ */ React8.createElement("span", {
1184
- role: "none",
1185
- className: "attention-surface"
1186
- });
1187
1040
  }
1188
- return /* @__PURE__ */ React8.createElement(Grid.Root, {
1189
- id: model.id ?? "table-grid"
1190
- }, /* @__PURE__ */ React8.createElement(TableValueEditor, {
1191
- model,
1192
- modals,
1193
- schema,
1194
- onFocus: handleFocus,
1195
- onSave: handleSave,
1196
- client
1197
- }), /* @__PURE__ */ React8.createElement(Grid.Content, {
1198
- className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1199
- frozen,
1200
- columns: model.columnMeta.value,
1201
- columnDefault,
1202
- rowDefault,
1203
- limitRows: model.getRowCount() ?? 0,
1204
- limitColumns: model.projection.fields.length,
1205
- overscroll: "trap",
1206
- onAxisResize: handleAxisResize,
1207
- onClick: handleGridClick,
1208
- onKeyDownCapture: handleKeyDown,
1209
- onWheelCapture: handleWheel,
1210
- ref: setDxGrid
1211
- }), /* @__PURE__ */ React8.createElement(RowActionsMenu, {
1212
- model,
1213
- modals
1214
- }), /* @__PURE__ */ React8.createElement(ColumnActionsMenu, {
1215
- model,
1216
- modals
1217
- }), /* @__PURE__ */ React8.createElement(ColumnSettings, {
1218
- model,
1219
- modals,
1220
- onNewColumn: handleNewColumn
1221
- }), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
1222
- model,
1223
- modals
1224
- }));
1225
- } finally {
1226
- _effect.f();
1041
+ }, [
1042
+ model,
1043
+ dxGrid,
1044
+ handleSave
1045
+ ]);
1046
+ const handleAxisResize = useCallback4((event) => {
1047
+ if (event.axis === "col") {
1048
+ const columnIndex = parseInt(event.index, 10);
1049
+ model?.setColumnWidth(columnIndex, event.size);
1050
+ }
1051
+ }, [
1052
+ model
1053
+ ]);
1054
+ const handleWheel = useCallback4((event) => {
1055
+ if (!ignoreAttention && !hasAttention) {
1056
+ event.stopPropagation();
1057
+ }
1058
+ }, [
1059
+ hasAttention,
1060
+ ignoreAttention
1061
+ ]);
1062
+ const handleNewColumn = useCallback4(() => {
1063
+ const columns = model?.getColumnCount();
1064
+ if (dxGrid && columns) {
1065
+ dxGrid.scrollToColumn(columns - 1);
1066
+ }
1067
+ }, [
1068
+ model,
1069
+ dxGrid
1070
+ ]);
1071
+ const { controllerRef } = useTableContext(TABLE_CONTENT_NAME);
1072
+ controllerRef.current = useMemo4(() => {
1073
+ if (!dxGrid || !presentation) {
1074
+ return {};
1075
+ }
1076
+ return {
1077
+ update: (cell) => {
1078
+ if (cell) {
1079
+ dxGrid.updateIfWithinBounds(cell, true);
1080
+ } else {
1081
+ dxGrid.updateCells(true);
1082
+ dxGrid.requestUpdate();
1083
+ }
1084
+ },
1085
+ handleInsertRowResult
1086
+ };
1087
+ }, [
1088
+ dxGrid,
1089
+ model,
1090
+ presentation
1091
+ ]);
1092
+ if (!model || !modals) {
1093
+ return /* @__PURE__ */ React7.createElement("span", {
1094
+ role: "none",
1095
+ className: "dx-attention-surface"
1096
+ });
1227
1097
  }
1098
+ return /* @__PURE__ */ React7.createElement("div", {
1099
+ ...composableProps(props, {
1100
+ classNames: "dx-container relative"
1101
+ }),
1102
+ ref: forwardedRef
1103
+ }, /* @__PURE__ */ React7.createElement(Grid.Root, {
1104
+ id: model.id ?? "table-grid"
1105
+ }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
1106
+ model,
1107
+ modals,
1108
+ schema,
1109
+ onFocus: handleFocus,
1110
+ onSave: handleSave,
1111
+ onCreate
1112
+ }), /* @__PURE__ */ React7.createElement(Grid.Content, {
1113
+ className: mx("[--dx-grid-base:var(--base-surface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1114
+ frozen,
1115
+ columns: columnMeta,
1116
+ columnDefault,
1117
+ rowDefault,
1118
+ limitRows: rows.length,
1119
+ limitColumns: columnCount,
1120
+ overscroll: "trap",
1121
+ onAxisResize: handleAxisResize,
1122
+ onClick: handleGridClick,
1123
+ onKeyDownCapture: handleKeyDown,
1124
+ onWheelCapture: handleWheel,
1125
+ ...testId && {
1126
+ "data-testid": testId
1127
+ },
1128
+ ref: setDxGrid
1129
+ }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
1130
+ model,
1131
+ modals
1132
+ }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
1133
+ model,
1134
+ modals
1135
+ }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
1136
+ model,
1137
+ modals,
1138
+ onNewColumn: handleNewColumn
1139
+ })));
1228
1140
  });
1229
- var Table = {
1230
- Root: TableRoot,
1231
- Main: TableMain
1232
- };
1141
+ TableContent.displayName = TABLE_CONTENT_NAME;
1233
1142
 
1234
- // src/components/Table/DynamicTable.tsx
1235
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
1236
- import React9, { useCallback as useCallback6, useMemo as useMemo6, useRef as useRef3 } from "react";
1237
- import { useDefaultValue } from "@dxos/react-ui";
1238
- import { mx as mx2 } from "@dxos/react-ui-theme";
1239
- var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
1240
- var _effect = _useSignals9();
1241
- try {
1242
- const { typename, jsonSchema } = useMemo6(() => getBaseSchema({
1243
- typename: name,
1244
- properties,
1245
- jsonSchema: _jsonSchema,
1246
- schema
1247
- }), [
1248
- name,
1249
- properties,
1250
- _jsonSchema,
1251
- schema
1252
- ]);
1253
- const { projection, view } = useMemo6(() => makeDynamicTable({
1254
- typename,
1255
- jsonSchema,
1256
- properties
1257
- }), [
1258
- typename,
1259
- jsonSchema,
1260
- properties
1261
- ]);
1262
- const tableRef = useRef3(null);
1263
- const handleCellUpdate = useCallback6((cell) => {
1264
- tableRef.current?.update?.(cell);
1265
- }, []);
1266
- const handleRowOrderChange = useCallback6(() => {
1267
- tableRef.current?.update?.();
1268
- }, []);
1269
- const features = useDefaultValue(props.features, () => ({
1270
- selection: {
1271
- enabled: false
1272
- },
1273
- dataEditable: false
1274
- }));
1275
- const model = useTableModel({
1276
- rows,
1277
- view,
1278
- schema: jsonSchema,
1279
- projection,
1280
- features,
1281
- rowActions,
1282
- onCellUpdate: handleCellUpdate,
1283
- onRowOrderChange: handleRowOrderChange,
1284
- onRowAction
1143
+ // src/components/Table/TableToolbar.tsx
1144
+ import { Atom as Atom3, RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
1145
+ import React8, { useContext as useContext2, useEffect as useEffect4, useMemo as useMemo5 } from "react";
1146
+ import { Menu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
1147
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
1148
+ import { translationKey as translationKey4 } from "#translations";
1149
+ var createTableToolbarActions = ({ stateAtom, onAdd, onSave, customActions }) => Atom3.make((get) => {
1150
+ const nodes = [];
1151
+ if (onAdd) {
1152
+ const add = createMenuAction("add-row", onAdd, {
1153
+ type: "add-row",
1154
+ icon: "ph--plus--regular",
1155
+ label: [
1156
+ "add-row.label",
1157
+ {
1158
+ ns: translationKey4
1159
+ }
1160
+ ],
1161
+ testId: "table.toolbar.add-row"
1285
1162
  });
1286
- const presentation = useMemo6(() => {
1287
- if (model) {
1288
- return new TablePresentation(model);
1289
- }
1290
- }, [
1291
- model
1292
- ]);
1293
- return /* @__PURE__ */ React9.createElement("div", {
1294
- role: "none",
1295
- className: mx2("is-full bs-full grow grid", classNames)
1296
- }, /* @__PURE__ */ React9.createElement("div", {
1297
- role: "none",
1298
- className: "grid min-bs-0 overflow-hidden"
1299
- }, /* @__PURE__ */ React9.createElement(Table.Root, null, /* @__PURE__ */ React9.createElement(Table.Main, {
1300
- ref: tableRef,
1301
- model,
1302
- presentation,
1303
- ignoreAttention: true,
1304
- onRowClick
1305
- }))));
1306
- } finally {
1307
- _effect.f();
1163
+ nodes.push(add);
1164
+ }
1165
+ if (onSave) {
1166
+ const state = get(stateAtom);
1167
+ const save = createMenuAction("save-view", onSave, {
1168
+ type: "save-view",
1169
+ icon: "ph--floppy-disk--regular",
1170
+ label: [
1171
+ "save-view.label",
1172
+ {
1173
+ ns: translationKey4
1174
+ }
1175
+ ],
1176
+ testId: "table.toolbar.save-view",
1177
+ iconOnly: false,
1178
+ hidden: !state.viewDirty
1179
+ });
1180
+ nodes.push(save);
1308
1181
  }
1309
- };
1310
-
1311
- // src/components/TableToolbar/TableToolbar.tsx
1312
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
1313
- import { Rx } from "@effect-rx/rx-react";
1314
- import React10, { useMemo as useMemo7 } from "react";
1315
- import { live as live2 } from "@dxos/live-object";
1316
- import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
1317
- import { rxFromSignal } from "@dxos/react-ui-menu";
1318
- var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.make((get) => {
1319
- const add = createMenuAction("add-row", onAdd, {
1320
- type: "add-row",
1321
- icon: "ph--plus--regular",
1322
- label: [
1323
- "add row",
1324
- {
1325
- ns: translationKey
1326
- }
1327
- ],
1328
- testId: "table.toolbar.add-row"
1329
- });
1330
- const save = createMenuAction("save-view", onSave, {
1331
- type: "save-view",
1332
- icon: "ph--floppy-disk--regular",
1333
- label: [
1334
- "save view label",
1335
- {
1336
- ns: translationKey
1337
- }
1338
- ],
1339
- testId: "table.toolbar.save-view",
1340
- iconOnly: false,
1341
- hidden: get(rxFromSignal(() => !state.viewDirty))
1342
- });
1343
1182
  const gap = createGapSeparator();
1344
- const nodes = [
1345
- add,
1346
- save,
1347
- ...gap.nodes
1348
- ];
1183
+ nodes.push(...gap.nodes);
1349
1184
  const edges = nodes.map(({ id: target }) => ({
1350
1185
  source: "root",
1351
- target
1186
+ target,
1187
+ relation: "child"
1352
1188
  }));
1353
1189
  if (customActions) {
1354
1190
  const custom = get(customActions);
@@ -1360,33 +1196,138 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
1360
1196
  edges
1361
1197
  };
1362
1198
  });
1363
- var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
1364
- var _effect = _useSignals10();
1365
- try {
1366
- const state = useMemo7(() => live2({
1199
+ var TableToolbar = composable2(({ attendableId, viewDirty, onAdd, onSave, customActions, ...props }, forwardedRef) => {
1200
+ const registry = useContext2(RegistryContext2);
1201
+ const stateAtom = useMemo5(() => Atom3.make({
1202
+ viewDirty
1203
+ }), []);
1204
+ useEffect4(() => {
1205
+ registry.set(stateAtom, {
1367
1206
  viewDirty
1368
- }), []);
1369
- const actionsCreator = useMemo7(() => createTableToolbarActions({
1370
- state,
1371
- onAdd,
1372
- onSave,
1373
- customActions
1374
- }), [
1375
- state,
1376
- onAdd,
1377
- onSave,
1378
- customActions
1379
- ]);
1380
- const menu = useMenuActions(actionsCreator);
1381
- return /* @__PURE__ */ React10.createElement(MenuProvider, {
1382
- ...menu,
1383
- attendableId
1384
- }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
1385
- classNames
1207
+ });
1208
+ }, [
1209
+ registry,
1210
+ stateAtom,
1211
+ viewDirty
1212
+ ]);
1213
+ const actionsCreator = useMemo5(() => createTableToolbarActions({
1214
+ stateAtom,
1215
+ onAdd,
1216
+ onSave,
1217
+ customActions
1218
+ }), [
1219
+ stateAtom,
1220
+ onAdd,
1221
+ onSave,
1222
+ customActions
1223
+ ]);
1224
+ const menuActions = useMenuActions(actionsCreator);
1225
+ return /* @__PURE__ */ React8.createElement(Menu.Root, {
1226
+ ...menuActions,
1227
+ attendableId
1228
+ }, /* @__PURE__ */ React8.createElement(Menu.Toolbar, {
1229
+ ...composableProps2(props),
1230
+ ref: forwardedRef
1231
+ }));
1232
+ });
1233
+ TableToolbar.displayName = "TableToolbar";
1234
+
1235
+ // src/components/Table/Table.tsx
1236
+ var emptyColumnMeta2 = Atom4.make({
1237
+ grid: {}
1238
+ });
1239
+ var [TableContextProvider, useTableContext] = createContext("Table");
1240
+ var TABLE_ROOT_NAME = "Table.Root";
1241
+ var TableRoot = /* @__PURE__ */ forwardRef(({ children }, forwardedRef) => {
1242
+ const controllerRef = useRef3({});
1243
+ useImperativeHandle(forwardedRef, () => ({
1244
+ update: (cell) => controllerRef.current?.update?.(cell),
1245
+ handleInsertRowResult: (result) => controllerRef.current?.handleInsertRowResult?.(result)
1246
+ }), []);
1247
+ return /* @__PURE__ */ React9.createElement(TableContextProvider, {
1248
+ controllerRef
1249
+ }, children);
1250
+ });
1251
+ TableRoot.displayName = TABLE_ROOT_NAME;
1252
+ var Table = {
1253
+ Root: TableRoot,
1254
+ Toolbar: TableToolbar,
1255
+ Content: TableContent
1256
+ };
1257
+
1258
+ // src/components/Table/DynamicTable.tsx
1259
+ import { RegistryContext as RegistryContext3 } from "@effect-atom/atom-react";
1260
+ import React10, { useCallback as useCallback5, useContext as useContext3, useEffect as useEffect5, useMemo as useMemo6, useRef as useRef4, useState as useState5 } from "react";
1261
+ import { useDefaultValue } from "@dxos/react-ui";
1262
+ import { mx as mx2 } from "@dxos/ui-theme";
1263
+ var DynamicTable = ({ classNames, schema, name = "com.example.dynamicTable", rows, properties, jsonSchema: jsonSchemaProp, rowActions, onRowClick, onRowAction, ...props }) => {
1264
+ const registry = useContext3(RegistryContext3);
1265
+ const [dynamicTable, setDynamicTable] = useState5();
1266
+ const { jsonSchema } = useMemo6(() => getBaseSchema({
1267
+ typename: name,
1268
+ properties,
1269
+ jsonSchema: jsonSchemaProp,
1270
+ schema
1271
+ }), [
1272
+ name,
1273
+ properties,
1274
+ jsonSchemaProp,
1275
+ schema
1276
+ ]);
1277
+ useEffect5(() => {
1278
+ setDynamicTable(makeDynamicTable({
1279
+ registry,
1280
+ jsonSchema,
1281
+ properties
1386
1282
  }));
1387
- } finally {
1388
- _effect.f();
1389
- }
1283
+ }, [
1284
+ registry,
1285
+ jsonSchema,
1286
+ properties
1287
+ ]);
1288
+ const tableRef = useRef4(null);
1289
+ const handleCellUpdate = useCallback5((cell) => {
1290
+ tableRef.current?.update?.(cell);
1291
+ }, []);
1292
+ const handleRowOrderChange = useCallback5(() => {
1293
+ tableRef.current?.update?.();
1294
+ }, []);
1295
+ const features = useDefaultValue(props.features, () => ({
1296
+ selection: {
1297
+ enabled: false
1298
+ },
1299
+ dataEditable: false
1300
+ }));
1301
+ const model = useTableModel({
1302
+ rows,
1303
+ object: dynamicTable?.object,
1304
+ projection: dynamicTable?.projection,
1305
+ features,
1306
+ rowActions,
1307
+ onCellUpdate: handleCellUpdate,
1308
+ onRowOrderChange: handleRowOrderChange,
1309
+ onRowAction
1310
+ });
1311
+ const presentation = useMemo6(() => {
1312
+ if (model) {
1313
+ return new TablePresentation(registry, model);
1314
+ }
1315
+ }, [
1316
+ registry,
1317
+ model
1318
+ ]);
1319
+ return /* @__PURE__ */ React10.createElement("div", {
1320
+ className: mx2("dx-expander grid", classNames)
1321
+ }, /* @__PURE__ */ React10.createElement("div", {
1322
+ className: "grid min-h-0 overflow-hidden"
1323
+ }, /* @__PURE__ */ React10.createElement(Table.Root, {
1324
+ ref: tableRef
1325
+ }, /* @__PURE__ */ React10.createElement(Table.Content, {
1326
+ model,
1327
+ presentation,
1328
+ ignoreAttention: true,
1329
+ onRowClick
1330
+ }))));
1390
1331
  };
1391
1332
  export {
1392
1333
  BUTTON_IDENTIFIERS,
@@ -1398,16 +1339,21 @@ export {
1398
1339
  Table,
1399
1340
  TableModel,
1400
1341
  TablePresentation,
1401
- TableToolbar,
1402
1342
  cellClassesForRowSelection,
1343
+ compareValues,
1344
+ createDirectChangeCallback,
1345
+ createEchoChangeCallback,
1346
+ extractOrder,
1403
1347
  getBaseSchema,
1348
+ getSortValue,
1404
1349
  makeDynamicTable,
1405
1350
  narrowSchema,
1406
1351
  tableButtons,
1407
1352
  tableControls,
1408
1353
  touch,
1409
- translations,
1410
1354
  useAddRow,
1355
+ useProjectionModel,
1356
+ useTableContext,
1411
1357
  useTableModel
1412
1358
  };
1413
1359
  //# sourceMappingURL=index.mjs.map