@dxos/react-ui-table 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8

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