@dxos/react-ui-table 0.8.4-main.c4373fc → 0.8.4-main.d05673bc65

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