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