@dxos/react-ui-table 0.8.4-main.1da679c → 0.8.4-main.21d9917

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