@dxos/react-ui-table 0.8.4-main.3c1ae3b → 0.8.4-main.3fbcb4aa9b

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