@dxos/react-ui-table 0.8.4-main.ead640a → 0.8.4-main.effb148878

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