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