@dxos/react-ui-table 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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 (172) hide show
  1. package/dist/lib/browser/chunk-BF54SSNL.mjs +70 -0
  2. package/dist/lib/browser/chunk-BF54SSNL.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-F7Y374KL.mjs +1751 -0
  4. package/dist/lib/browser/chunk-F7Y374KL.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1195 -2846
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +114 -0
  9. package/dist/lib/browser/testing/index.mjs.map +7 -0
  10. package/dist/lib/browser/types/index.mjs +3 -5
  11. package/dist/lib/node-esm/chunk-CCJ4LOVM.mjs +1753 -0
  12. package/dist/lib/node-esm/chunk-CCJ4LOVM.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs +71 -0
  14. package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1195 -2846
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +115 -0
  19. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/types/index.mjs +3 -5
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +2 -3
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +4 -2
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +35 -3
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +110 -0
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.d.ts +21 -18
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +109 -6
  36. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/Table/TableContent.d.ts +17 -0
  38. package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
  39. package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
  40. package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
  41. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  42. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  43. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +14 -9
  44. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  45. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +12 -18
  46. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  47. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +38 -5
  48. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  49. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  50. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  51. package/dist/types/src/components/index.d.ts +0 -1
  52. package/dist/types/src/components/index.d.ts.map +1 -1
  53. package/dist/types/src/components/testing.d.ts +26 -56
  54. package/dist/types/src/components/testing.d.ts.map +1 -1
  55. package/dist/types/src/hooks/index.d.ts +2 -1
  56. package/dist/types/src/hooks/index.d.ts.map +1 -1
  57. package/dist/types/src/hooks/useAddRow.d.ts +6 -6
  58. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  59. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  60. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  61. package/dist/types/src/hooks/useTableModel.d.ts +11 -10
  62. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  63. package/dist/types/src/index.d.ts +0 -1
  64. package/dist/types/src/index.d.ts.map +1 -1
  65. package/dist/types/src/model/modal-controller.d.ts +5 -8
  66. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  67. package/dist/types/src/model/selection-model.d.ts +17 -7
  68. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  69. package/dist/types/src/model/table-model.d.ts +116 -34
  70. package/dist/types/src/model/table-model.d.ts.map +1 -1
  71. package/dist/types/src/model/table-presentation.d.ts +5 -2
  72. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  73. package/dist/types/src/playwright/TableManager.d.ts +2 -1
  74. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  75. package/dist/types/src/testing/index.d.ts +2 -0
  76. package/dist/types/src/testing/index.d.ts.map +1 -0
  77. package/dist/types/src/testing/useTestTableModel.d.ts +25 -0
  78. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -0
  79. package/dist/types/src/translations.d.ts +21 -23
  80. package/dist/types/src/translations.d.ts.map +1 -1
  81. package/dist/types/src/types/Table.d.ts +26 -0
  82. package/dist/types/src/types/Table.d.ts.map +1 -0
  83. package/dist/types/src/types/index.d.ts +1 -1
  84. package/dist/types/src/types/index.d.ts.map +1 -1
  85. package/dist/types/src/util/dynamic-table.d.ts +15 -14
  86. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  87. package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
  88. package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
  89. package/dist/types/src/util/index.d.ts +2 -1
  90. package/dist/types/src/util/index.d.ts.map +1 -1
  91. package/dist/types/src/util/query-ast.d.ts +7 -0
  92. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  93. package/dist/types/src/util/schema.d.ts +1 -1
  94. package/dist/types/src/util/schema.d.ts.map +1 -1
  95. package/dist/types/src/util/sort.d.ts +12 -0
  96. package/dist/types/src/util/sort.d.ts.map +1 -0
  97. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  98. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  99. package/dist/types/tsconfig.tsbuildinfo +1 -1
  100. package/package.json +70 -55
  101. package/src/components/Table/ColumnActionsMenu.tsx +16 -12
  102. package/src/components/Table/ColumnSettings.tsx +18 -15
  103. package/src/components/Table/DynamicTable.stories.tsx +38 -35
  104. package/src/components/Table/DynamicTable.tsx +38 -34
  105. package/src/components/Table/Relations.stories.tsx +245 -0
  106. package/src/components/Table/RowActionsMenu.tsx +26 -17
  107. package/src/components/Table/Table.stories.tsx +196 -218
  108. package/src/components/Table/Table.tsx +47 -376
  109. package/src/components/Table/TableContent.tsx +421 -0
  110. package/src/components/Table/TableToolbar.tsx +111 -0
  111. package/src/components/TableCellEditor/CellValidationMessage.tsx +6 -6
  112. package/src/components/TableCellEditor/FormCellEditor.tsx +152 -49
  113. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +37 -77
  114. package/src/components/TableCellEditor/TableCellEditor.tsx +104 -233
  115. package/src/components/TableCellEditor/index.ts +1 -0
  116. package/src/components/index.ts +0 -1
  117. package/src/components/testing.ts +46 -37
  118. package/src/hooks/index.ts +2 -1
  119. package/src/hooks/useAddRow.ts +14 -14
  120. package/src/hooks/useProjectionModel.ts +39 -0
  121. package/src/hooks/useTableModel.ts +41 -35
  122. package/src/index.ts +0 -1
  123. package/src/model/modal-controller.ts +24 -41
  124. package/src/model/selection-model.ts +75 -41
  125. package/src/model/table-model.test.ts +91 -56
  126. package/src/model/table-model.ts +468 -187
  127. package/src/model/table-presentation.test.ts +69 -59
  128. package/src/model/table-presentation.ts +112 -66
  129. package/src/playwright/TableManager.ts +13 -6
  130. package/src/playwright/playwright.config.ts +1 -1
  131. package/src/playwright/smoke.spec.ts +180 -43
  132. package/src/testing/index.ts +5 -0
  133. package/src/testing/useTestTableModel.ts +133 -0
  134. package/src/translations.ts +20 -22
  135. package/src/types/Table.ts +79 -0
  136. package/src/types/index.ts +2 -2
  137. package/src/util/dynamic-table.test.ts +70 -0
  138. package/src/util/dynamic-table.ts +51 -36
  139. package/src/util/index.ts +2 -1
  140. package/src/util/query-ast.ts +22 -0
  141. package/src/util/schema.ts +4 -4
  142. package/src/util/sort.ts +90 -0
  143. package/src/util/table-buttons.ts +4 -3
  144. package/src/util/table-controls.ts +6 -3
  145. package/dist/lib/browser/chunk-Q5QQXJUO.mjs +0 -27
  146. package/dist/lib/browser/chunk-Q5QQXJUO.mjs.map +0 -7
  147. package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs +0 -29
  148. package/dist/lib/node-esm/chunk-ZNOU6LHG.mjs.map +0 -7
  149. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  150. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  151. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  152. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  153. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  154. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  155. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
  156. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
  157. package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
  158. package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
  159. package/dist/types/src/model/table-sorting.d.ts +0 -53
  160. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  161. package/dist/types/src/types/table.d.ts +0 -56
  162. package/dist/types/src/types/table.d.ts.map +0 -1
  163. package/dist/types/src/util/table.d.ts +0 -14
  164. package/dist/types/src/util/table.d.ts.map +0 -1
  165. package/src/components/Table/CreateRefPanel.tsx +0 -84
  166. package/src/components/Table/relations.stories.tsx +0 -123
  167. package/src/components/TableCellEditor/extension.ts +0 -61
  168. package/src/components/TableToolbar/TableToolbar.tsx +0 -102
  169. package/src/components/TableToolbar/index.ts +0 -5
  170. package/src/model/table-sorting.ts +0 -216
  171. package/src/types/table.ts +0 -27
  172. package/src/util/table.ts +0 -127
@@ -1,313 +1,86 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
  import {
3
- TableSchema,
4
- TableType
5
- } from "./chunk-ZNOU6LHG.mjs";
3
+ BUTTON_IDENTIFIERS,
4
+ CONTROL_IDENTIFIERS,
5
+ CheckboxStory,
6
+ SwitchStory,
7
+ TableModel,
8
+ TablePresentation,
9
+ cellClassesForRowSelection,
10
+ compareValues,
11
+ createDirectChangeCallback,
12
+ createEchoChangeCallback,
13
+ extractOrder,
14
+ getSortValue,
15
+ tableButtons,
16
+ tableControls,
17
+ useAddRow,
18
+ useProjectionModel,
19
+ useTableModel
20
+ } from "./chunk-CCJ4LOVM.mjs";
21
+ import {
22
+ Table_exports
23
+ } from "./chunk-SIRDIPHZ.mjs";
6
24
 
7
25
  // src/translations.ts
8
- var translationKey = "react-ui-table";
26
+ var translationKey = "@dxos/react-ui-table";
9
27
  var translations = [
10
28
  {
11
29
  "en-US": {
12
30
  [translationKey]: {
13
- "object placeholder": "New table",
14
- "create object label": "Create table",
15
- "table name placeholder": "Table name",
16
- "settings title": "Table settings",
17
- "table schema label": "Schema",
18
- "new schema": "New schema",
19
- "continue label": "Continue",
20
- "create stack section label": "Create table",
21
- "add row label": "Add row",
22
- "create comment": "Create thread",
23
- "column action sort descending": "Sort Descending",
24
- "column action sort ascending": "Sort Ascending",
25
- "column action clear sorting": "Clear Sorting",
26
- "column action settings": "Column Settings",
27
- "column action delete": "Delete Column",
28
- "delete row label": "Delete row",
29
- "bulk delete row label": "Delete selected rows",
30
- "column deleted label": "Column deleted",
31
- "new column button label": "Create column",
32
- "create new object label": "Create new object \u201C{{text}}\u201D",
33
- "save view label": "Save changes to view"
31
+ "object.placeholder": "New table",
32
+ "create-object.label": "Create table",
33
+ "table-name.placeholder": "Table name",
34
+ "settings.title": "Table settings",
35
+ "table-schema.label": "Type",
36
+ "continue.label": "Continue",
37
+ "create-stack-section.label": "Create table",
38
+ "add-row.label": "Add row",
39
+ "column-action-sort-descending.menu": "Sort Descending",
40
+ "column-action-sort-ascending.menu": "Sort Ascending",
41
+ "column-action-clear-sorting.menu": "Clear Sorting",
42
+ "column-action-settings.menu": "Column Settings",
43
+ "column-action-delete.menu": "Delete Column",
44
+ "delete-row.label": "Delete row",
45
+ "bulk-delete-row.label": "Delete selected rows",
46
+ "column-deleted.label": "Column deleted",
47
+ "new-column-button.label": "Create column",
48
+ "create-new-object.label": "Create new object \u201C{{text}}\u201D",
49
+ "save-view.label": "Save changes to view"
34
50
  }
35
51
  }
36
52
  }
37
53
  ];
38
54
 
39
55
  // src/components/Table/Table.tsx
40
- import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
41
- import React8, { forwardRef, useCallback as useCallback5, useImperativeHandle, useState as useState3, useMemo as useMemo5, useEffect as useEffect4 } from "react";
42
- import { getValue as getValue4 } from "@dxos/echo-schema";
43
- import { invariant as invariant4 } from "@dxos/invariant";
44
- import { Filter } from "@dxos/react-client/echo";
45
- import { useTranslation as useTranslation3 } from "@dxos/react-ui";
46
- import { useAttention } from "@dxos/react-ui-attention";
47
- import { closestCell, Grid, gridSeparatorInlineEnd, gridSeparatorBlockEnd } from "@dxos/react-ui-grid";
48
- import { mx as mx2 } from "@dxos/react-ui-theme";
49
- import { isNotFalsy, safeParseInt } from "@dxos/util";
50
-
51
- // src/components/Table/ColumnActionsMenu.tsx
52
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
53
- import React from "react";
54
- import { DropdownMenu, useTranslation } from "@dxos/react-ui";
55
- var ColumnActionsMenu = ({ model, modals }) => {
56
- var _effect = _useSignals();
57
- try {
58
- const { t } = useTranslation(translationKey);
59
- const state = modals.state.value;
60
- if (state?.type !== "column") {
61
- return null;
62
- }
63
- const currentSort = model.sorting?.sorting;
64
- const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
65
- return /* @__PURE__ */ React.createElement(DropdownMenu.Root, {
66
- modal: false,
67
- open: true,
68
- onOpenChange: modals.close
69
- }, /* @__PURE__ */ React.createElement(DropdownMenu.VirtualTrigger, {
70
- virtualRef: modals.trigger
71
- }), /* @__PURE__ */ React.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React.createElement(DropdownMenu.Content, null, /* @__PURE__ */ React.createElement(DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
72
- "data-testid": "column-sort-descending",
73
- onClick: () => model.sorting?.setSort(state.fieldId, "desc")
74
- }, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
75
- "data-testid": "column-sort-ascending",
76
- onClick: () => model.sorting?.setSort(state.fieldId, "asc")
77
- }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
78
- "data-testid": "column-clear-sort",
79
- onClick: () => model.sorting?.clearSort()
80
- }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
81
- "data-testid": "column-delete",
82
- onClick: () => model.deleteColumn(state.fieldId)
83
- }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ React.createElement(DropdownMenu.Item, {
84
- "data-testid": "column-settings",
85
- onClick: () => modals.openColumnSettings()
86
- }, t("column action settings"))), /* @__PURE__ */ React.createElement(DropdownMenu.Arrow, null))));
87
- } finally {
88
- _effect.f();
89
- }
90
- };
91
-
92
- // src/components/Table/ColumnSettings.tsx
93
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
94
- import React2, { useCallback, useEffect, useMemo, useState } from "react";
95
- import { Popover } from "@dxos/react-ui";
96
- import { FieldEditor } from "@dxos/react-ui-form";
97
- var ColumnSettings = ({ model, modals, onNewColumn }) => {
98
- var _effect = _useSignals2();
99
- try {
100
- const [newField, setNewField] = useState();
101
- const state = modals.state.value;
102
- const space = model?.space;
103
- useEffect(() => {
104
- if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
105
- setNewField(model.projection.createFieldProjection());
106
- requestAnimationFrame(() => {
107
- onNewColumn();
108
- });
109
- } else {
110
- setNewField(void 0);
111
- }
112
- }, [
113
- model?.projection,
114
- state
115
- ]);
116
- const existingField = useMemo(() => {
117
- if (state?.type === "columnSettings") {
118
- const { mode } = state;
119
- if (mode.type === "edit") {
120
- return model?.view?.fields.find((f) => f.id === mode.fieldId);
121
- }
122
- }
123
- return void 0;
124
- }, [
125
- model?.view?.fields,
126
- state
127
- ]);
128
- const field = existingField ?? newField;
129
- const handleSave = useCallback(() => {
130
- modals.close();
131
- }, [
132
- modals
133
- ]);
134
- const handleCancel = useCallback(() => {
135
- if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
136
- model?.projection?.deleteFieldProjection(newField.id);
137
- }
138
- }, [
139
- model?.projection,
140
- state,
141
- newField
142
- ]);
143
- if (!model?.view || !model.projection || !field) {
144
- return null;
145
- }
146
- return /* @__PURE__ */ React2.createElement(Popover.Root, {
147
- modal: false,
148
- open: state?.type === "columnSettings"
149
- }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
150
- virtualRef: modals.trigger
151
- }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
152
- classNames: "md:is-64"
153
- }, /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(FieldEditor, {
154
- view: model.view,
155
- projection: model.projection,
156
- field,
157
- registry: space?.db.schemaRegistry,
158
- onSave: handleSave,
159
- onCancel: handleCancel
160
- })), /* @__PURE__ */ React2.createElement(Popover.Arrow, null))));
161
- } finally {
162
- _effect.f();
163
- }
164
- };
165
-
166
- // src/components/Table/CreateRefPanel.tsx
167
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
168
- import { Schema } from "effect";
169
- import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
170
- import { live } from "@dxos/react-client/echo";
171
- import { Popover as Popover2 } from "@dxos/react-ui";
172
- import { Form } from "@dxos/react-ui-form";
173
- import { useGridContext } from "@dxos/react-ui-grid";
174
- var CreateRefPanel = ({ model, modals, __gridScope }) => {
175
- var _effect = _useSignals3();
176
- try {
177
- const { id: gridId } = useGridContext("TableCellEditor", __gridScope);
178
- const space = model?.space;
179
- const state = modals.state.value;
180
- const schema = useMemo2(() => {
181
- if (!space || state?.type !== "createRefPanel") {
182
- return;
183
- }
184
- const [schema2] = space.db.schemaRegistry.query({
185
- typename: state.typename
186
- }).runSync();
187
- if (schema2) {
188
- const omit = Schema.omit("id");
189
- return omit(schema2);
190
- }
191
- }, [
192
- space,
193
- state
194
- ]);
195
- const handleSave = useCallback2((values) => {
196
- if (!model || !space || state?.type !== "createRefPanel") {
197
- return;
198
- }
199
- const [schema2] = space.db.schemaRegistry.query({
200
- typename: state.typename
201
- }).runSync();
202
- if (schema2) {
203
- const obj = space.db.add(live(schema2, values));
204
- state.onCreate?.(obj);
205
- }
206
- void modals.close();
207
- }, [
208
- modals,
209
- space,
210
- state
211
- ]);
212
- const handleCancel = useCallback2(() => {
213
- if (model) {
214
- modals.close();
215
- }
216
- }, [
217
- modals
218
- ]);
219
- if (!model?.view || !model.projection) {
220
- return null;
221
- }
222
- return /* @__PURE__ */ React3.createElement(Popover2.Root, {
223
- modal: false,
224
- open: state?.type === "createRefPanel" && !!schema,
225
- onOpenChange: (nextOpen) => {
226
- if (model && !nextOpen) {
227
- return modals.close();
228
- }
229
- }
230
- }, /* @__PURE__ */ React3.createElement(Popover2.VirtualTrigger, {
231
- virtualRef: modals.trigger
232
- }), /* @__PURE__ */ React3.createElement(Popover2.Portal, null, /* @__PURE__ */ React3.createElement(Popover2.Content, {
233
- classNames: "md:is-64",
234
- "data-grid": gridId
235
- }, /* @__PURE__ */ React3.createElement(Popover2.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React3.createElement(Form, {
236
- schema,
237
- values: state.initialValues ?? {},
238
- onSave: handleSave,
239
- onCancel: handleCancel
240
- })), /* @__PURE__ */ React3.createElement(Popover2.Arrow, null))));
241
- } finally {
242
- _effect.f();
243
- }
244
- };
245
-
246
- // src/components/Table/RowActionsMenu.tsx
247
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
248
- import React4 from "react";
249
- import { DropdownMenu as DropdownMenu2, useTranslation as useTranslation2 } from "@dxos/react-ui";
250
- var RowActionsMenu = ({ model, modals }) => {
251
- var _effect = _useSignals4();
252
- try {
253
- const { t } = useTranslation2(translationKey);
254
- const hasSelection = model.selection.hasSelection.value;
255
- const state = modals.state.value;
256
- if (state?.type !== "row") {
257
- return null;
258
- }
259
- return /* @__PURE__ */ React4.createElement(DropdownMenu2.Root, {
260
- modal: false,
261
- open: true,
262
- onOpenChange: modals.close
263
- }, /* @__PURE__ */ React4.createElement(DropdownMenu2.VirtualTrigger, {
264
- virtualRef: modals.trigger
265
- }), /* @__PURE__ */ React4.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React4.createElement(DropdownMenu2.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ React4.createElement(DropdownMenu2.Item, {
266
- "data-testid": "row-menu-delete",
267
- onClick: () => model.deleteRow(state.rowIndex)
268
- }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React4.createElement(DropdownMenu2.Item, {
269
- key: action.id,
270
- "data-testid": `row-action-${action.id}`,
271
- onClick: () => {
272
- modals.close();
273
- model.handleRowAction(action.id, state.rowIndex);
274
- }
275
- }, t(action.translationKey)))), /* @__PURE__ */ React4.createElement(DropdownMenu2.Arrow, null)));
276
- } finally {
277
- _effect.f();
278
- }
279
- };
280
-
281
- // src/model/table-model.ts
282
- import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
283
- import { Resource as Resource2 } from "@dxos/context";
284
- import { Ref as Ref3 } from "@dxos/echo";
285
- import { FormatEnum as FormatEnum3, getValue as getValue2, setValue, getSnapshot, getSchema, toEffectSchema } from "@dxos/echo-schema";
286
- import { invariant } from "@dxos/invariant";
287
- import { ObjectId } from "@dxos/keys";
288
- import { isLiveObject } from "@dxos/live-object";
289
- import { formatForEditing, parseValue } from "@dxos/react-ui-form";
290
- import { validateSchema } from "@dxos/schema";
56
+ import { Atom as Atom4 } from "@effect-atom/atom-react";
57
+ import { createContext } from "@radix-ui/react-context";
58
+ import React9, { forwardRef, useImperativeHandle, useRef as useRef3 } from "react";
291
59
 
292
- // src/model/selection-model.ts
293
- import { computed, effect, signal } from "@preact/signals-core";
294
- import { Resource } from "@dxos/context";
60
+ // src/components/Table/TableContent.tsx
61
+ import { Atom as Atom2, RegistryContext, useAtomValue as useAtomValue4 } from "@effect-atom/atom-react";
62
+ import * as String2 from "effect/String";
63
+ import React7, { useCallback as useCallback4, useContext, useEffect as useEffect3, useMemo as useMemo4, useState as useState4 } from "react";
64
+ import { log } from "@dxos/log";
65
+ import { useAttention } from "@dxos/react-ui-attention";
66
+ import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
67
+ import { DxEditRequest } from "@dxos/react-ui-grid";
68
+ import { composable, composableProps, mx } from "@dxos/ui-theme";
295
69
 
296
70
  // src/util/dynamic-table.ts
297
- import { Obj, Ref } from "@dxos/echo";
298
- import { getTypename, toJsonSchema } from "@dxos/echo-schema";
299
- import { createView, getSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
300
- var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
71
+ import { Filter, JsonSchema, Obj, Order, Query, Ref, Type } from "@dxos/echo";
72
+ import { ProjectionModel, ViewModel, createEchoChangeCallback as createEchoChangeCallback2, getSchemaFromPropertyDefinitions } from "@dxos/schema";
73
+ var getBaseSchema = ({ schema, typename, properties, jsonSchema }) => {
301
74
  if (typename && properties) {
302
75
  const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
303
76
  return {
304
77
  typename: schema2.typename,
305
- jsonSchema: schema2.jsonSchema
78
+ jsonSchema: JsonSchema.toJsonSchema(schema2)
306
79
  };
307
80
  } else if (schema) {
308
81
  return {
309
- typename: getTypename(schema),
310
- jsonSchema: toJsonSchema(schema)
82
+ typename: Type.getTypename(schema),
83
+ jsonSchema: JsonSchema.toJsonSchema(schema)
311
84
  };
312
85
  } else if (typename && jsonSchema) {
313
86
  return {
@@ -318,34 +91,41 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
318
91
  throw new Error("invalid properties");
319
92
  }
320
93
  };
321
- var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
322
- const view = createView({
323
- name: "dynamic-table",
324
- typename,
94
+ var makeDynamicTable = ({ registry, jsonSchema, properties }) => {
95
+ const view = ViewModel.make({
96
+ query: Query.select(Filter.everything()),
325
97
  jsonSchema,
326
98
  ...properties && {
327
99
  fields: properties.map((property) => property.name)
328
100
  }
329
101
  });
330
- const table = Obj.make(TableType, {
331
- name: "dynamic-table",
332
- view: Ref.make(view)
102
+ const object = Obj.make(Table_exports.Table, {
103
+ view: Ref.make(view),
104
+ sizes: {}
105
+ });
106
+ const projection = new ProjectionModel({
107
+ registry,
108
+ view,
109
+ baseSchema: jsonSchema,
110
+ change: createEchoChangeCallback2(view, jsonSchema)
333
111
  });
334
- const projection = new ViewProjection(jsonSchema, view);
335
- if (properties && view.fields) {
336
- setProperties(view, projection, properties);
112
+ projection.normalizeView();
113
+ if (properties && projection.getFields()) {
114
+ setProperties(view, projection, object, properties);
337
115
  }
338
116
  return {
339
- table,
340
- projection
117
+ projection,
118
+ object
341
119
  };
342
120
  };
343
- var setProperties = (view, projection, properties) => {
121
+ var setProperties = (view, projection, table, properties) => {
344
122
  for (const property of properties) {
345
- const field = view.fields.find((field2) => field2.path === property.name);
123
+ const field = projection.getFields().find((field2) => field2.path === property.name);
346
124
  if (field) {
347
125
  if (property.size !== void 0) {
348
- field.size = property.size;
126
+ Obj.change(table, (table2) => {
127
+ table2.sizes[field.path] = property.size;
128
+ });
349
129
  }
350
130
  if (property.title !== void 0) {
351
131
  const fieldProjection = projection.getFieldProjection(field.id);
@@ -358,13 +138,11 @@ var setProperties = (view, projection, properties) => {
358
138
  });
359
139
  }
360
140
  if (property.sort) {
361
- const fieldId = field.id;
362
- view.query.sort = [
363
- {
364
- fieldId,
365
- direction: property.sort
366
- }
367
- ];
141
+ const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
142
+ const newQuery = currentQuery.orderBy(Order.property(field.path, property.sort));
143
+ Obj.change(view, (view2) => {
144
+ view2.query.ast = newQuery.ast;
145
+ });
368
146
  }
369
147
  }
370
148
  }
@@ -373,1910 +151,410 @@ var setProperties = (view, projection, properties) => {
373
151
  // src/util/signals.ts
374
152
  var touch = (value) => value;
375
153
 
376
- // src/util/table.ts
377
- import { Schema as Schema2 } from "effect";
378
- import { Format, FormatEnum, Ref as Ref2, TypedObject, TypeEnum } from "@dxos/echo-schema";
379
- import { PublicKey } from "@dxos/react-client";
380
- import { live as live2 } from "@dxos/react-client/echo";
381
- import { createFieldId, createView as createView2, getSchemaProperties, ViewProjection as ViewProjection2 } from "@dxos/schema";
382
- var initializeTable = async ({ client, space, table, typename, initialRow = true }) => {
383
- if (typename) {
384
- const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
385
- if (!schema) {
386
- throw new Error(`Schema not found: ${typename}`);
387
- }
388
- const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
389
- table.view = Ref2.make(createView2({
390
- // TODO(ZaymonFC): Don't hardcode name?
391
- name: "View",
392
- typename: schema.typename,
393
- jsonSchema: schema.jsonSchema,
394
- fields
395
- }));
396
- return schema;
397
- } else {
398
- const [schema] = await space.db.schemaRegistry.register([
399
- createContactSchema()
400
- ]);
401
- const fields = ContactFields;
402
- table.view = Ref2.make(createView2({
403
- name: "View",
404
- typename: schema.typename,
405
- jsonSchema: schema.jsonSchema,
406
- fields
407
- }));
408
- createProjection(schema, table.view.target);
409
- if (initialRow) {
410
- space.db.add(live2(schema, {}));
411
- }
412
- return schema;
413
- }
414
- };
415
- var createContactSchema = () => TypedObject({
416
- typename: `example.com/type/${PublicKey.random().truncate()}`,
417
- version: "0.1.0"
418
- })({
419
- name: Schema2.optional(Schema2.String).annotations({
420
- title: "Name"
421
- }),
422
- active: Schema2.optional(Schema2.Boolean).annotations({
423
- title: "Active"
424
- }),
425
- email: Schema2.optional(Format.Email),
426
- salary: Schema2.optional(Format.Currency()).annotations({
427
- title: "Salary"
428
- })
429
- });
430
- var ContactFields = [
431
- "name",
432
- "email",
433
- "salary",
434
- "active"
435
- ];
436
- var createProjection = (schema, view) => {
437
- const projection = new ViewProjection2(schema.jsonSchema, view);
438
- projection.setFieldProjection({
439
- field: {
440
- id: view.fields.find((f) => f.path === "salary").id,
441
- path: "salary",
442
- size: 150
443
- }
444
- });
445
- projection.setFieldProjection({
446
- field: {
447
- id: view.fields.find((f) => f.path === "active").id,
448
- path: "active",
449
- size: 100
450
- }
451
- });
452
- projection.setFieldProjection({
453
- field: {
454
- id: createFieldId(),
455
- path: "manager",
456
- referencePath: "name"
457
- },
458
- props: {
459
- property: "manager",
460
- type: TypeEnum.Ref,
461
- format: FormatEnum.Ref,
462
- referenceSchema: schema.typename,
463
- title: "Manager"
464
- }
465
- });
466
- return projection;
467
- };
468
-
469
- // src/util/table-buttons.ts
470
- var BUTTON_IDENTIFIERS = {
471
- columnSettings: "data-table-column-settings-button",
472
- newColumn: "data-table-new-column-button",
473
- referencedCell: "data-table-ref-cell-button",
474
- rowMenu: "data-table-row-menu-button",
475
- saveDraftRow: "data-table-save-draft-row-button",
476
- sort: "data-table-sort-button"
477
- };
478
- var createButton = ({ attr, data, disabled = false, icon, testId, type = "primary" }) => {
479
- const dataAttrs = Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
480
- const positionClass = type === "primary" ? "inline-end-2" : "inline-end-9";
481
- return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? "disabled" : ""}><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
482
- };
483
- var addColumnButton = {
484
- attr: BUTTON_IDENTIFIERS.newColumn,
485
- icon: "ph--plus--regular",
486
- render: ({ disabled }) => {
487
- return createButton({
488
- attr: BUTTON_IDENTIFIERS.newColumn,
489
- icon: addColumnButton.icon,
490
- disabled,
491
- data: {},
492
- testId: "table-new-column-button"
493
- });
494
- },
495
- getData: (_el) => ({
496
- type: "newColumn"
497
- })
498
- };
499
- var columnSettingsButton = {
500
- attr: BUTTON_IDENTIFIERS.columnSettings,
501
- icon: "ph--caret-down--regular",
502
- render: ({ fieldId }) => {
503
- return createButton({
504
- attr: BUTTON_IDENTIFIERS.columnSettings,
505
- icon: columnSettingsButton.icon,
506
- data: {
507
- "data-field-id": fieldId
508
- },
509
- testId: "table-column-settings-button"
510
- });
511
- },
512
- getData: (el) => ({
513
- type: "columnSettings",
514
- fieldId: el.getAttribute("data-field-id")
515
- })
516
- };
517
- var rowMenuButton = {
518
- attr: BUTTON_IDENTIFIERS.rowMenu,
519
- icon: "ph--dots-three--regular",
520
- render: ({ rowIndex }) => {
521
- return createButton({
522
- attr: BUTTON_IDENTIFIERS.rowMenu,
523
- icon: rowMenuButton.icon,
524
- data: {
525
- "data-row-index": rowIndex.toString()
526
- },
527
- testId: "table-row-menu-button"
528
- });
529
- },
530
- getData: (el) => ({
531
- type: "rowMenu",
532
- rowIndex: Number(el.getAttribute("data-row-index"))
533
- })
534
- };
535
- var sortButton = {
536
- attr: BUTTON_IDENTIFIERS.sort,
537
- icon: "ph--sort-ascending--regular",
538
- render: ({ fieldId, direction }) => {
539
- return createButton({
540
- attr: BUTTON_IDENTIFIERS.sort,
541
- icon: direction === "desc" ? "ph--sort-descending--regular" : "ph--sort-ascending--regular",
542
- data: {
543
- "data-field-id": fieldId,
544
- "data-direction": direction ?? ""
545
- },
546
- testId: "table-sort-button",
547
- // TODO(ZaymonFC): All buttons should be rendered into an absolutely positioned flex container.
548
- // This is a bit hacky.
549
- type: "secondary"
550
- });
551
- },
552
- getData: (el) => ({
553
- type: "sort",
554
- fieldId: el.getAttribute("data-field-id"),
555
- direction: el.getAttribute("data-direction")
556
- })
557
- };
558
- var saveDraftRowButton = {
559
- attr: BUTTON_IDENTIFIERS.saveDraftRow,
560
- icon: "ph--floppy-disk--regular",
561
- render: ({ rowIndex, disabled }) => {
562
- return createButton({
563
- attr: BUTTON_IDENTIFIERS.saveDraftRow,
564
- icon: saveDraftRowButton.icon,
565
- disabled,
566
- data: {
567
- "data-row-index": rowIndex.toString()
568
- },
569
- testId: "table-save-draft-row-button"
570
- });
571
- },
572
- getData: (el) => ({
573
- type: "saveDraftRow",
574
- rowIndex: Number(el.getAttribute("data-row-index"))
575
- })
576
- };
577
- var tableButtons = {
578
- addColumn: addColumnButton,
579
- columnSettings: columnSettingsButton,
580
- rowMenu: rowMenuButton,
581
- saveDraftRow: saveDraftRowButton,
582
- sort: sortButton
583
- };
584
-
585
- // src/util/table-controls.ts
586
- var CONTROL_IDENTIFIERS = {
587
- checkbox: "data-table-checkbox",
588
- switch: "data-table-switch"
589
- };
590
- var BASE_CLASSES = {
591
- checkbox: "absolute inset-block-[.375rem] inline-end-[.375rem] dx-checkbox",
592
- switch: "absolute inset-block-[.25rem] inline-end-[.25rem] dx-checkbox--switch"
593
- };
594
- var renderAttributes = (data) => {
595
- return Object.entries(data).map(([k, v]) => `${k}="${v}"`).join(" ");
596
- };
597
- var renderInput = (baseClass, attrs, checked = false, disabled = false, preventToggle = false, testId) => {
598
- return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? "checked" : ""} ${preventToggle ? 'onclick="return false"' : ""} ${disabled ? "disabled" : ""} data-testid="${testId}"/>`;
599
- };
600
- var CheckboxStory = ({ rowIndex, header = false, checked = false, disabled = false }) => {
601
- const attrs = {
602
- [CONTROL_IDENTIFIERS.checkbox]: "",
603
- "data-row-index": rowIndex.toString(),
604
- ...header && {
605
- "data-header": ""
606
- }
607
- };
608
- return renderInput(BASE_CLASSES.checkbox, attrs, checked, disabled, true, "table-selection");
609
- };
610
- var SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = false }) => {
611
- const attrs = {
612
- [CONTROL_IDENTIFIERS.switch]: "",
613
- "data-row-index": rowIndex.toString(),
614
- "data-col-index": colIndex.toString()
615
- };
616
- return renderInput(BASE_CLASSES.switch, attrs, checked, disabled, true, "table-switch");
617
- };
618
- var tableControls = {
619
- checkbox: {
620
- attr: CONTROL_IDENTIFIERS.checkbox,
621
- render: CheckboxStory,
622
- getData: (el) => ({
623
- type: "checkbox",
624
- rowIndex: Number(el.getAttribute("data-row-index")),
625
- header: el.hasAttribute("data-header")
626
- })
627
- },
628
- switch: {
629
- attr: CONTROL_IDENTIFIERS.switch,
630
- render: SwitchStory,
631
- getData: (el) => ({
632
- type: "switch",
633
- rowIndex: Number(el.getAttribute("data-row-index")),
634
- colIndex: Number(el.getAttribute("data-col-index"))
635
- })
636
- }
637
- };
638
-
639
154
  // src/util/schema.ts
640
- import { Schema as Schema3 } from "effect";
641
- import { isTypeLiteral, TypeLiteral } from "effect/SchemaAST";
155
+ import * as Schema from "effect/Schema";
156
+ import * as SchemaAST from "effect/SchemaAST";
642
157
  var narrowSchema = (schema, paths) => {
643
158
  const ast = schema?.ast;
644
- if (isTypeLiteral(ast)) {
159
+ if (SchemaAST.isTypeLiteral(ast)) {
645
160
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
646
161
  if (propertySignatures.length > 0) {
647
- const narrowType = new TypeLiteral(propertySignatures, []);
648
- return Schema3.make(narrowType);
162
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
163
+ return Schema.make(narrowType);
649
164
  }
650
165
  }
651
166
  return void 0;
652
167
  };
653
168
 
654
- // src/model/selection-model.ts
655
- var SelectionModel = class extends Resource {
656
- constructor(_rows, _selectionMode, _onSelectionChanged) {
657
- super(), this._rows = _rows, this._selectionMode = _selectionMode, this._onSelectionChanged = _onSelectionChanged, this._selection = signal(/* @__PURE__ */ new Set()), this._validSelectedIds = computed(() => {
658
- const rows = this._rows.value;
659
- if (!rows) {
660
- return /* @__PURE__ */ new Set();
661
- }
662
- const validIds = new Set(rows.map((row) => row.id));
663
- return new Set([
664
- ...this._selection.value
665
- ].filter((id) => validIds.has(id)));
666
- }), this._hasSelection = computed(() => this._validSelectedIds.value.size > 0), this._allSelected = computed(() => {
667
- const rows = this._rows.value;
668
- if (rows.length === 0) {
669
- return false;
670
- }
671
- return rows.every((row) => this._selection.value.has(row.id));
672
- }), this.getSelectedRows = () => {
673
- const selectedIds = this._validSelectedIds.value;
674
- return this._rows.value.filter((row) => selectedIds.has(row.id));
675
- }, this.isRowIndexSelected = (rowIndex) => {
676
- const row = this._rows.value[rowIndex];
677
- return this._selection.value.has(row.id);
678
- }, this.isObjectSelected = (object) => {
679
- return this._selection.value.has(object.id);
680
- }, this.toggleSelectionForRowIndex = (rowIndex) => {
681
- const row = this._rows.value[rowIndex];
682
- const newSelection = new Set(this._selection.value);
683
- if (newSelection.has(row.id)) {
684
- newSelection.delete(row.id);
685
- } else {
686
- if (this._selectionMode === "single") {
687
- newSelection.clear();
688
- }
689
- newSelection.add(row.id);
690
- }
691
- this._selection.value = newSelection;
692
- }, this.setSelection = (mode) => {
693
- switch (mode) {
694
- case "all": {
695
- this._selection.value = new Set(this._rows.value.map((row) => row.id));
696
- break;
697
- }
698
- case "none": {
699
- this._selection.value = /* @__PURE__ */ new Set();
700
- break;
701
- }
702
- }
703
- };
704
- }
705
- async _open() {
706
- const selectionWatcher = effect(() => {
707
- touch(this._selection.value);
708
- this._onSelectionChanged?.();
169
+ // src/model/modal-controller.ts
170
+ import { Atom } from "@effect-atom/atom-react";
171
+ var ModalController = class {
172
+ _registry;
173
+ _state;
174
+ _triggerRef = {
175
+ current: null
176
+ };
177
+ constructor(registry) {
178
+ this._registry = registry;
179
+ this._state = Atom.make({
180
+ type: "closed"
709
181
  });
710
- this._ctx.onDispose(selectionWatcher);
711
- }
712
- //
713
- // Getters
714
- //
715
- get selection() {
716
- return this._selection;
717
182
  }
718
- get hasSelection() {
719
- return this._hasSelection;
183
+ get state() {
184
+ return this._state;
720
185
  }
721
- get allRowsSeleted() {
722
- return this._allSelected;
186
+ get stateValue() {
187
+ return this._registry.get(this._state);
723
188
  }
724
- get selectionMode() {
725
- return this._selectionMode;
189
+ get trigger() {
190
+ return this._triggerRef;
726
191
  }
727
- };
728
-
729
- // src/model/table-sorting.ts
730
- import { computed as computed2, signal as signal2 } from "@preact/signals-core";
731
- import orderBy from "lodash.orderby";
732
- import { getValue, FormatEnum as FormatEnum2, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
733
- import { formatForDisplay } from "@dxos/react-ui-form";
734
- var TableSorting = class {
735
- constructor(rows, _view, _projection) {
736
- this._view = _view;
737
- this._projection = _projection;
738
- this._displayToDataIndex = /* @__PURE__ */ new Map();
739
- this._localSort = signal2(void 0);
740
- this._rows = rows;
741
- this._isDirty = computed2(() => {
742
- const local = this._localSort.value;
743
- const viewSort = this._view?.query.sort?.[0];
744
- if (local?.type === "cleared") {
745
- return viewSort !== void 0;
746
- }
747
- if (local?.type === "active") {
748
- if (!viewSort) {
749
- return true;
750
- }
751
- return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
192
+ setTrigger = (trigger) => {
193
+ this._triggerRef.current = trigger;
194
+ };
195
+ showRowMenu = (rowIndex) => {
196
+ this._registry.set(this._state, {
197
+ type: "row",
198
+ rowIndex
199
+ });
200
+ };
201
+ showColumnMenu = (fieldId) => {
202
+ this._registry.set(this._state, {
203
+ type: "column",
204
+ fieldId
205
+ });
206
+ };
207
+ showColumnCreator = () => {
208
+ this._registry.set(this._state, {
209
+ type: "columnSettings",
210
+ mode: {
211
+ type: "create"
752
212
  }
753
- return false;
754
213
  });
755
- this.sortedRows = this.initialiseSortedRows();
756
- }
757
- /**
758
- * @reactive
759
- * @returns Local sort if present, falls back to view sort.
760
- */
761
- get sorting() {
762
- const local = this._localSort.value;
763
- if (local?.type === "cleared") {
764
- return void 0;
214
+ };
215
+ showReferencePanel = (targetId, schemaId) => {
216
+ this._registry.set(this._state, {
217
+ type: "refPanel",
218
+ targetId,
219
+ typename: schemaId
220
+ });
221
+ };
222
+ openColumnSettings = () => {
223
+ const currentState = this._registry.get(this._state);
224
+ if (currentState.type === "column") {
225
+ const fieldId = currentState.fieldId;
226
+ requestAnimationFrame(() => {
227
+ this._registry.set(this._state, {
228
+ type: "columnSettings",
229
+ mode: {
230
+ type: "edit",
231
+ fieldId
232
+ }
233
+ });
234
+ });
765
235
  }
766
- if (local?.type === "active") {
767
- return local.sort;
236
+ };
237
+ close = () => {
238
+ this._registry.set(this._state, {
239
+ type: "closed"
240
+ });
241
+ };
242
+ };
243
+
244
+ // src/components/TableCellEditor/TableCellEditor.tsx
245
+ import { EditorView } from "@codemirror/view";
246
+ import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
247
+ import { debounce } from "@dxos/async";
248
+ import { Format, TypeEnum } from "@dxos/echo/internal";
249
+ import { invariant as invariant2 } from "@dxos/invariant";
250
+ import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
251
+
252
+ // src/components/TableCellEditor/CellValidationMessage.tsx
253
+ import React from "react";
254
+ import { useGridContext } from "@dxos/react-ui-grid";
255
+ var CellValidationMessage = ({ __gridScope, validationError, variant = "error" }) => {
256
+ const { editing, editBox: box } = useGridContext("GridSheetCellEditor", __gridScope);
257
+ if (!editing || !validationError) {
258
+ return null;
259
+ }
260
+ const bgClass = variant === "error" ? "bg-error-surface" : "bg-warning-surface";
261
+ const textClass = variant === "error" ? "text-error-surface-text" : "text-warning-surface-text";
262
+ return /* @__PURE__ */ React.createElement("div", {
263
+ role: "none",
264
+ className: `absolute ${bgClass} ${textClass} rounded-h-sm text-xs p-1`,
265
+ style: {
266
+ ...{
267
+ "--dx-grid-cell-width": `${box?.inlineSize ?? 200}px`
268
+ },
269
+ zIndex: 10,
270
+ insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
271
+ insetInlineStart: box.insetInlineStart,
272
+ inlineSize: box.inlineSize
768
273
  }
769
- return this._view?.query.sort?.[0];
770
- }
771
- /**
772
- * @reactive
773
- * @returns Whether local sort differs from view sort.
774
- */
775
- get isDirty() {
776
- return this._isDirty.value;
777
- }
778
- getDataIndex(displayIndex) {
779
- return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
780
- }
781
- setSort(fieldId, direction) {
782
- this._localSort.value = {
783
- type: "active",
784
- sort: {
785
- fieldId,
786
- direction
787
- }
788
- };
274
+ }, validationError);
275
+ };
276
+
277
+ // src/components/TableCellEditor/FormCellEditor.tsx
278
+ import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
279
+ import { Entity } from "@dxos/echo";
280
+ import { Ref as Ref2, getValue } from "@dxos/echo/internal";
281
+ import { invariant } from "@dxos/invariant";
282
+ import { Popover } from "@dxos/react-ui";
283
+ import { Form } from "@dxos/react-ui-form";
284
+ import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
285
+ import { getDeep, isTruthy, setDeep } from "@dxos/util";
286
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
287
+ var createOptionLabel = [
288
+ "create-new-object.label",
289
+ {
290
+ ns: translationKey
789
291
  }
790
- toggleSort(fieldId) {
791
- if (!this._view || !this.sorting || this.sorting.fieldId !== fieldId) {
792
- return;
292
+ ];
293
+ var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onCreate, ...formProps }) => {
294
+ const anchorRef = useRef(null);
295
+ const { id: _gridId, editing: contextEditing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
296
+ const [editing, setLocalEditing] = useState(false);
297
+ useEffect(() => {
298
+ if (contextEditing && contextEditing.cellElement) {
299
+ anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
300
+ setLocalEditing(true);
301
+ } else {
302
+ anchorRef.current = null;
303
+ setLocalEditing(false);
793
304
  }
794
- switch (this.sorting.direction) {
795
- case "asc": {
796
- this.setSort(fieldId, "desc");
797
- break;
798
- }
799
- case "desc": {
800
- this.setSort(fieldId, "asc");
801
- break;
802
- }
305
+ }, [
306
+ contextEditing
307
+ ]);
308
+ const narrowedSchema = useMemo(() => {
309
+ if (!schema) {
310
+ return void 0;
803
311
  }
804
- }
805
- clearSort() {
806
- this._localSort.value = {
807
- type: "cleared"
808
- };
809
- }
810
- save() {
811
- if (this._view && this._localSort.value !== void 0) {
812
- if (this._localSort.value.type === "active") {
813
- this._view.query.sort = [
814
- this._localSort.value.sort
815
- ];
312
+ return narrowSchema(schema, [
313
+ fieldProjection.field.path
314
+ ]);
315
+ }, [
316
+ JSON.stringify(schema),
317
+ fieldProjection.field.path
318
+ ]);
319
+ const originalRow = useMemo(() => {
320
+ if (model && contextEditing) {
321
+ const cell = parseCellIndex(contextEditing.index);
322
+ if (model.isDraftCell(cell)) {
323
+ const draftRow = model.getDraftRows()[cell.row];
324
+ invariant(draftRow, void 0, {
325
+ F: __dxlog_file,
326
+ L: 74,
327
+ S: void 0,
328
+ A: [
329
+ "draftRow",
330
+ ""
331
+ ]
332
+ });
333
+ return draftRow.data;
816
334
  } else {
817
- this._view.query.sort = [];
335
+ const row = model.getRowAt(cell.row);
336
+ invariant(row, void 0, {
337
+ F: __dxlog_file,
338
+ L: 78,
339
+ S: void 0,
340
+ A: [
341
+ "row",
342
+ ""
343
+ ]
344
+ });
345
+ return row;
818
346
  }
819
- this._localSort.value = void 0;
820
347
  }
821
- }
822
- //
823
- // Initialisation.
824
- //
825
- initialiseSortedRows() {
826
- return computed2(() => {
827
- this._displayToDataIndex.clear();
828
- const sort = this.sorting;
829
- if (!sort || !this._view) {
830
- return this._rows.value;
831
- }
832
- const field = this._view.fields.find((f) => f.id === sort.fieldId);
833
- if (!field) {
834
- return this._rows.value;
835
- }
836
- const { props } = this._projection.getFieldProjection(field.id);
837
- const dataWithIndices = this._rows.value.map((item, index) => {
838
- const sortValue = this.getSortValue(props, field, item);
839
- const isEmpty = !(props.type === TypeEnum2.Boolean) && (sortValue == null || sortValue === "");
840
- return {
841
- item,
842
- index,
843
- value: sortValue,
844
- isEmpty
845
- };
846
- });
847
- const ordered = orderBy(dataWithIndices, [
848
- "isEmpty",
849
- "value"
850
- ], [
851
- "asc",
852
- sort.direction
853
- ]);
854
- ordered.forEach(({ index: dataIndex }, displayIndex) => {
855
- if (displayIndex !== dataIndex) {
856
- this._displayToDataIndex.set(displayIndex, dataIndex);
857
- }
858
- });
859
- return ordered.map(({ item }) => item);
860
- });
861
- }
862
- getSortValue(props, field, item) {
863
- const { type, format } = props;
864
- const value = getValue(item, field.path);
865
- if (type === TypeEnum2.Boolean) {
866
- return !!value;
348
+ return void 0;
349
+ }, [
350
+ model,
351
+ contextEditing
352
+ ]);
353
+ const initialFormValues = useMemo(() => originalRow ? JSON.parse(JSON.stringify(originalRow)) : {}, [
354
+ originalRow
355
+ ]);
356
+ const [formValues, setFormValues] = useState(initialFormValues);
357
+ const handleValuesChanged = useCallback((values) => {
358
+ setFormValues(values);
359
+ }, []);
360
+ const handleOpenChange = useCallback((nextOpen) => {
361
+ if (nextOpen === false) {
362
+ setEditing(null);
363
+ onSave?.();
867
364
  }
868
- if (type === TypeEnum2.Number) {
869
- return value;
365
+ setLocalEditing(nextOpen);
366
+ }, []);
367
+ const handleSave = useCallback((values) => {
368
+ if (!originalRow) {
369
+ return;
870
370
  }
871
- if (value == null) {
872
- return value;
371
+ const path = fieldProjection.field.path;
372
+ const value = getDeep(values, [
373
+ path
374
+ ]);
375
+ if (model) {
376
+ model.changeRow(originalRow, (mutableRow) => {
377
+ setDeep(mutableRow, [
378
+ path
379
+ ], value);
380
+ });
381
+ } else {
382
+ setDeep(originalRow, [
383
+ path
384
+ ], value);
873
385
  }
874
- if (format === FormatEnum2.SingleSelect) {
875
- const options = props.options;
876
- if (!options) {
877
- return void 0;
386
+ contextEditing?.cellElement?.focus();
387
+ setEditing(null);
388
+ setLocalEditing(false);
389
+ onSave?.();
390
+ }, [
391
+ fieldProjection.field.path,
392
+ onSave,
393
+ contextEditing,
394
+ originalRow,
395
+ model
396
+ ]);
397
+ const handleCreate = useCallback((schema2, values) => {
398
+ const objectWithId = onCreate?.(schema2, values);
399
+ if (objectWithId && originalRow) {
400
+ const ref = Ref2.make(objectWithId);
401
+ const path = fieldProjection.field.path;
402
+ if (model) {
403
+ model.changeRow(originalRow, (mutableRow) => {
404
+ setDeep(mutableRow, [
405
+ path
406
+ ], ref);
407
+ });
408
+ } else {
409
+ setDeep(originalRow, [
410
+ path
411
+ ], ref);
878
412
  }
879
- const option = options.find((option2) => option2.id === value);
880
- return option ? options.indexOf(option) : void 0;
881
- }
882
- if (format === FormatEnum2.Ref && field.referencePath) {
883
- const refValue = getValue(value.target, field.referencePath);
884
- return refValue;
885
413
  }
886
- return formatForDisplay({
887
- type,
888
- format,
889
- value
890
- });
891
- }
414
+ contextEditing?.cellElement?.focus();
415
+ setEditing(null);
416
+ setLocalEditing(false);
417
+ onSave?.();
418
+ }, [
419
+ fieldProjection.field.path,
420
+ onSave,
421
+ contextEditing,
422
+ originalRow,
423
+ onCreate,
424
+ model
425
+ ]);
426
+ const getOptions = useCallback((results) => results.map((obj) => {
427
+ return {
428
+ id: Entity.getDXN(obj).toString(),
429
+ label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
430
+ };
431
+ }).filter(isTruthy), [
432
+ fieldProjection
433
+ ]);
434
+ if (!editing) {
435
+ return null;
436
+ }
437
+ return /* @__PURE__ */ React2.createElement(Popover.Root, {
438
+ open: editing,
439
+ onOpenChange: handleOpenChange
440
+ }, /* @__PURE__ */ React2.createElement(Popover.VirtualTrigger, {
441
+ virtualRef: anchorRef
442
+ }), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
443
+ tabIndex: -1,
444
+ classNames: "dx-card-popover-width dx-density-fine"
445
+ }, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Root, {
446
+ ...formProps,
447
+ autoFocus: true,
448
+ schema: narrowedSchema,
449
+ values: formValues,
450
+ onValuesChanged: handleValuesChanged,
451
+ projection: model?.projection,
452
+ createInitialValuePath: fieldProjection.field.referencePath,
453
+ createOptionIcon: "ph--plus--regular",
454
+ createOptionLabel,
455
+ db: model?.db,
456
+ getOptions,
457
+ onCreate: handleCreate,
458
+ onSave: handleSave
459
+ }, /* @__PURE__ */ React2.createElement(Form.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Content, null, /* @__PURE__ */ React2.createElement(Form.FieldSet, null), /* @__PURE__ */ React2.createElement(Form.Actions, null))))))));
892
460
  };
893
461
 
894
- // src/util/tag.ts
895
- var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
896
- var extractTagIds = (value) => {
897
- if (typeof value !== "string") {
898
- return void 0;
899
- }
900
- const ids = [];
901
- let match;
902
- while ((match = TAG_PATTERN_REGEX.exec(value)) !== null) {
903
- if (match[2]) {
904
- ids.push(match[2]);
462
+ // src/components/TableCellEditor/TableCellEditor.tsx
463
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
464
+ var TableValueEditor = ({ __gridScope, schema, model, modals, onFocus, onSave, onCreate }) => {
465
+ const { editing } = useGridContext3("TableValueEditor", __gridScope);
466
+ const fieldProjection = useMemo2(() => {
467
+ if (!model || !editing) {
468
+ return;
905
469
  }
906
- }
907
- return ids.length > 0 ? ids : void 0;
908
- };
909
-
910
- // src/model/table-model.ts
911
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
912
- var defaultFeatures = {
913
- selection: {
914
- enabled: true,
915
- mode: "multiple"
916
- },
917
- dataEditable: false,
918
- schemaEditable: false
919
- };
920
- var TableModel = class extends Resource2 {
921
- constructor({ id, space, view, projection, features = {}, sorting = [], pinnedRows = {
922
- top: [],
923
- bottom: []
924
- }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
925
- super();
926
- this._visibleRange = signal3({
927
- start: {
928
- row: 0,
929
- col: 0
930
- },
931
- end: {
932
- row: 0,
933
- col: 0
934
- }
935
- });
936
- this._rows = signal3([]);
937
- this._draftRows = signal3([]);
938
- //
939
- // Data
940
- //
941
- this.setRows = (obj) => {
942
- this._rows.value = obj;
943
- };
944
- this.getRowCount = () => this._rows.value.length;
945
- /**
946
- * @reactive
947
- */
948
- this.getDraftRowCount = () => this._draftRows.value.length;
949
- this.getColumnCount = () => this._view?.fields.length ?? 0;
950
- this.insertRow = () => {
951
- const result = this._onInsertRow?.();
952
- if (result === false && this._draftRows.value.length === 0) {
953
- this.createDraftRow();
954
- }
955
- };
956
- this.commitDraftRow = (draftRowIndex) => {
957
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
958
- return false;
959
- }
960
- const draftRow = this._draftRows.value[draftRowIndex];
961
- if (!draftRow.valid) {
962
- return false;
963
- }
964
- const success = this._onInsertRow?.(draftRow.data);
965
- if (success) {
966
- const newDraftRows = this._draftRows.value.filter((_, index) => index !== draftRowIndex);
967
- this._draftRows.value = newDraftRows;
968
- }
969
- return success ?? false;
970
- };
971
- this.deleteRow = (rowIndex) => {
972
- const row = this._sorting.getDataIndex(rowIndex);
973
- const obj = this._rows.value[row];
974
- const objectsToDelete = [];
975
- if (this.features.selection.enabled && this._selection.hasSelection.value) {
976
- const selectedRows = this._selection.getSelectedRows();
977
- objectsToDelete.push(...selectedRows);
978
- } else {
979
- objectsToDelete.push(obj);
980
- }
981
- this._onDeleteRows?.(row, objectsToDelete);
982
- };
983
- this.handleRowAction = (actionId, rowIndex) => {
984
- if (!this._onRowAction) {
985
- return;
986
- }
987
- const row = this._sorting.getDataIndex(rowIndex);
988
- const data = this._rows.value[row];
989
- if (data) {
990
- this._onRowAction(actionId, data);
991
- }
992
- };
993
- this.getCellData = (cell) => {
994
- const { col, row, plane } = cell;
995
- const fields = this._view?.fields ?? [];
996
- if (col < 0 || col >= fields.length) {
997
- return void 0;
998
- }
999
- const field = fields[col];
1000
- let value;
1001
- if (plane === "frozenRowsEnd") {
1002
- if (row >= 0 && row < this._draftRows.value.length) {
1003
- value = getValue2(this._draftRows.value[row].data, field.path);
1004
- } else {
1005
- return void 0;
1006
- }
1007
- } else {
1008
- const dataIndex = this._sorting.getDataIndex(row);
1009
- value = getValue2(this._rows.value[dataIndex], field.path);
1010
- }
1011
- if (value == null) {
1012
- return "";
1013
- }
1014
- const { props } = this._projection.getFieldProjection(field.id);
1015
- switch (props.format) {
1016
- case FormatEnum3.Ref: {
1017
- if (!field.referencePath) {
1018
- return "";
1019
- }
1020
- return getValue2(value.target, field.referencePath);
1021
- }
1022
- default: {
1023
- return formatForEditing({
1024
- type: props.type,
1025
- format: props.format,
1026
- value
1027
- });
1028
- }
1029
- }
1030
- };
1031
- this.validateCellData = async ({ col, row, plane }, value) => {
1032
- const fields = this._view?.fields ?? [];
1033
- if (col < 0 || col >= fields.length) {
1034
- return {
1035
- valid: false,
1036
- error: "Invalid column index"
1037
- };
1038
- }
1039
- const field = fields[col];
1040
- const { props } = this._projection.getFieldProjection(field.id);
1041
- const transformedValue = editorTextToCellValue(props, value);
1042
- const isDraftRow = plane === "frozenRowsEnd";
1043
- if (isDraftRow) {
1044
- const isInvalidDraftRowIndex = row < 0 || row >= this._draftRows.value.length;
1045
- if (isInvalidDraftRowIndex) {
1046
- return {
1047
- valid: false,
1048
- error: "Invalid draft row index"
1049
- };
1050
- }
1051
- const draftRow = this._draftRows.value[row];
1052
- const snapshot = {
1053
- ...draftRow.data
1054
- };
1055
- setValue(snapshot, field.path, transformedValue);
1056
- const validationErrors = this.validateDraftRowData(snapshot);
1057
- if (validationErrors.length > 0) {
1058
- const error = validationErrors.find((err) => err.path === field.path);
1059
- if (error) {
1060
- return {
1061
- valid: false,
1062
- error: error.message
1063
- };
1064
- }
1065
- }
1066
- return {
1067
- valid: true
1068
- };
1069
- } else {
1070
- const rowIdx = this._sorting.getDataIndex(row);
1071
- const currentRow = this._rows.value[rowIdx];
1072
- invariant(currentRow, "Invalid row index", {
1073
- F: __dxlog_file,
1074
- L: 507,
1075
- S: this,
1076
- A: [
1077
- "currentRow",
1078
- "'Invalid row index'"
1079
- ]
1080
- });
1081
- const snapshot = getSnapshot(currentRow);
1082
- setValue(snapshot, field.path, transformedValue);
1083
- const schema = getSchema(currentRow);
1084
- invariant(schema, void 0, {
1085
- F: __dxlog_file,
1086
- L: 513,
1087
- S: this,
1088
- A: [
1089
- "schema",
1090
- ""
1091
- ]
1092
- });
1093
- const validationResult = validateSchema(schema, snapshot);
1094
- if (validationResult && validationResult.length > 0) {
1095
- const error = validationResult[0];
1096
- invariant(error.path === field.path, void 0, {
1097
- F: __dxlog_file,
1098
- L: 518,
1099
- S: this,
1100
- A: [
1101
- "error.path === field.path",
1102
- ""
1103
- ]
1104
- });
1105
- return {
1106
- valid: false,
1107
- error: error.message
1108
- };
1109
- }
1110
- return {
1111
- valid: true
1112
- };
1113
- }
1114
- };
1115
- this.setCellData = (cell, value) => {
1116
- const { col, row, plane } = cell;
1117
- const fields = this._view?.fields ?? [];
1118
- if (col < 0 || col >= fields.length) {
1119
- return;
1120
- }
1121
- const field = fields[col];
1122
- const { props } = this._projection.getFieldProjection(field.id);
1123
- const transformedValue = editorTextToCellValue(props, value);
1124
- if (props.format === FormatEnum3.Ref && !isLiveObject(value)) {
1125
- return;
1126
- }
1127
- if (plane === "frozenRowsEnd") {
1128
- if (row >= 0 && row < this._draftRows.value.length) {
1129
- setValue(this._draftRows.value[row].data, field.path, transformedValue);
1130
- this.validateDraftRow(row);
1131
- }
1132
- } else {
1133
- const rowIdx = this._sorting.getDataIndex(row);
1134
- setValue(this._rows.value[rowIdx], field.path, transformedValue);
1135
- }
1136
- };
1137
- this._id = id;
1138
- this._space = space;
1139
- this._view = view;
1140
- this._projection = projection;
1141
- this._features = {
1142
- ...defaultFeatures,
1143
- ...features
1144
- };
1145
- invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1146
- F: __dxlog_file,
1147
- L: 145,
1148
- S: this,
470
+ const { col } = parseCellIndex2(editing.index);
471
+ const field = model.projection.getFields()[col];
472
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
473
+ invariant2(fieldProjection2, void 0, {
474
+ F: __dxlog_file2,
475
+ L: 66,
476
+ S: void 0,
1149
477
  A: [
1150
- "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1151
- "'Single selection is not compatible with editable tables.'"
478
+ "fieldProjection",
479
+ ""
1152
480
  ]
1153
481
  });
1154
- this._sorting = new TableSorting(this._rows, this._view, projection);
1155
- if (sorting.length > 0) {
1156
- const [sort] = sorting;
1157
- this._sorting.setSort(sort.fieldId, sort.direction);
1158
- }
1159
- this._pinnedRows = pinnedRows;
1160
- this._rowActions = rowActions;
1161
- this._onInsertRow = onInsertRow;
1162
- this._onDeleteRows = onDeleteRows;
1163
- this._onDeleteColumn = onDeleteColumn;
1164
- this._onCellUpdate = onCellUpdate;
1165
- this._onRowOrderChange = onRowOrderChange;
1166
- this._onRowAction = onRowAction;
1167
- }
1168
- get id() {
1169
- return this._id;
1170
- }
1171
- get space() {
1172
- return this._space;
1173
- }
1174
- get view() {
1175
- return this._view;
1176
- }
1177
- get projection() {
1178
- return this._projection;
1179
- }
1180
- get rows() {
1181
- return this._sorting.sortedRows;
1182
- }
1183
- get features() {
1184
- return this._features;
1185
- }
1186
- /**
1187
- * @reactive
1188
- */
1189
- get sorting() {
1190
- return this._sorting;
482
+ return fieldProjection2;
483
+ }, [
484
+ model,
485
+ editing
486
+ ]);
487
+ if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === Format.TypeFormat.SingleSelect || fieldProjection?.props.format === Format.TypeFormat.Ref) {
488
+ return /* @__PURE__ */ React3.createElement(FormCellEditor, {
489
+ __gridScope,
490
+ schema,
491
+ model,
492
+ fieldProjection,
493
+ modals,
494
+ onSave,
495
+ onCreate
496
+ });
1191
497
  }
1192
- /**
1193
- * Gets the row data at the specified display index.
1194
- */
1195
- getRowAt(displayIndex) {
1196
- if (displayIndex < 0 || displayIndex >= this._sorting.sortedRows.value.length) {
1197
- return void 0;
498
+ return /* @__PURE__ */ React3.createElement(TableCellEditor, {
499
+ model,
500
+ modals,
501
+ onFocus,
502
+ onSave,
503
+ __gridScope
504
+ });
505
+ };
506
+ var TableCellEditor = ({ __gridScope, model, modals, onFocus, onSave }) => {
507
+ const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
508
+ const suppressNextBlur = useRef2(false);
509
+ const [validationError, setValidationError] = useState2(null);
510
+ const [validationVariant, setValidationVariant] = useState2("error");
511
+ const fieldProjection = useMemo2(() => {
512
+ if (!model || !editing) {
513
+ return;
1198
514
  }
1199
- return this._sorting.sortedRows.value[displayIndex];
1200
- }
1201
- get pinnedRows() {
1202
- return this._pinnedRows;
1203
- }
1204
- get columnMeta() {
1205
- invariant(this._columnMeta, void 0, {
1206
- F: __dxlog_file,
1207
- L: 214,
1208
- S: this,
515
+ const { col } = parseCellIndex2(editing.index);
516
+ const field = model.projection.getFields()[col];
517
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
518
+ invariant2(fieldProjection2, void 0, {
519
+ F: __dxlog_file2,
520
+ L: 113,
521
+ S: void 0,
1209
522
  A: [
1210
- "this._columnMeta",
523
+ "fieldProjection",
1211
524
  ""
1212
525
  ]
1213
526
  });
1214
- return this._columnMeta;
1215
- }
1216
- get selection() {
1217
- return this._selection;
1218
- }
1219
- /** @reactive */
1220
- get isViewDirty() {
1221
- return this._sorting.isDirty;
1222
- }
1223
- get rowActions() {
1224
- return this._rowActions;
1225
- }
1226
- //
1227
- // Initialisation
1228
- //
1229
- async _open() {
1230
- this.initializeColumnMeta();
1231
- this.initializeEffects();
1232
- this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", () => this._onRowOrderChange?.());
1233
- await this._selection.open(this._ctx);
1234
- }
1235
- initializeColumnMeta() {
1236
- this._columnMeta = computed3(() => {
1237
- const fields = this._view?.fields ?? [];
1238
- const meta = Object.fromEntries(fields.map((field, index) => [
1239
- index,
1240
- {
1241
- size: field?.size ?? 256,
1242
- resizeable: true
1243
- }
1244
- ]));
1245
- return {
1246
- grid: meta,
1247
- frozenColsStart: {
1248
- 0: {
1249
- size: 30,
1250
- resizeable: false
1251
- }
1252
- },
1253
- frozenColsEnd: {
1254
- 0: {
1255
- size: 40,
1256
- resizeable: false
1257
- }
1258
- }
1259
- };
1260
- });
1261
- }
1262
- initializeEffects() {
1263
- const rowOrderWatcher = effect2(() => {
1264
- touch(this._sorting.sortedRows.value);
1265
- this._onRowOrderChange?.();
1266
- });
1267
- this._ctx.onDispose(rowOrderWatcher);
1268
- const rowEffectManager = effect2(() => {
1269
- const { start, end } = touch(this._visibleRange.value);
1270
- const rowEffects = [];
1271
- for (let row = start.row; row <= end.row; row++) {
1272
- rowEffects.push(effect2(() => {
1273
- const obj = this._sorting.sortedRows.value[row];
1274
- this._view?.fields.forEach((field) => touch(getValue2(obj, field.path)));
1275
- this._onCellUpdate?.({
1276
- row,
1277
- col: start.col,
1278
- plane: "grid"
1279
- });
1280
- }));
1281
- }
1282
- return () => rowEffects.forEach((cleanup) => cleanup());
1283
- });
1284
- this._ctx.onDispose(rowEffectManager);
1285
- const draftRowsWatcher = effect2(() => {
1286
- touch(this._draftRows.value);
1287
- this._onRowOrderChange?.();
1288
- });
1289
- this._ctx.onDispose(draftRowsWatcher);
1290
- }
1291
- // TODO(ZaymonFC): Return .value instead of exposing the signal.
1292
- get draftRows() {
1293
- return this._draftRows;
1294
- }
1295
- /**
1296
- * Checks if a specific field path has validation errors for a given draft row.
1297
- * @param draftRowIndex - The index of the draft row to check
1298
- * @param fieldPath - The path of the field to check for validation errors
1299
- * @returns true if the field has validation errors, false otherwise
1300
- */
1301
- hasDraftRowValidationError(draftRowIndex, fieldPath) {
1302
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
1303
- return false;
1304
- }
1305
- const draftRow = this._draftRows.value[draftRowIndex];
1306
- const validationErrors = draftRow.validationErrors || [];
1307
- return validationErrors.some((error) => error.path === fieldPath);
1308
- }
1309
- createDraftRow() {
1310
- if (!this._view) {
1311
- return;
1312
- }
1313
- const draftData = {
1314
- id: ObjectId.random()
1315
- };
1316
- const validationErrors = this.validateDraftRowData(draftData);
1317
- const draftRow = {
1318
- data: draftData,
1319
- valid: validationErrors.length === 0,
1320
- validationErrors
1321
- };
1322
- this._draftRows.value = [
1323
- ...this._draftRows.value,
1324
- draftRow
1325
- ];
1326
- }
1327
- validateDraftRow(draftRowIndex) {
1328
- if (draftRowIndex < 0 || draftRowIndex >= this._draftRows.value.length) {
1329
- return;
1330
- }
1331
- const draftRow = this._draftRows.value[draftRowIndex];
1332
- const validationErrors = this.validateDraftRowData(draftRow.data);
1333
- const updatedDraftRow = {
1334
- ...draftRow,
1335
- valid: validationErrors.length === 0,
1336
- validationErrors
1337
- };
1338
- const newDraftRows = [
1339
- ...this._draftRows.value
1340
- ];
1341
- newDraftRows[draftRowIndex] = updatedDraftRow;
1342
- this._draftRows.value = newDraftRows;
1343
- }
1344
- validateDraftRowData(data) {
1345
- const schema = toEffectSchema(this._projection.schema);
1346
- return validateSchema(schema, data) || [];
1347
- }
1348
- /**
1349
- * Updates a cell's value using a transform function.
1350
- * @param {DxGridPlanePosition} position - The position of the cell to update.
1351
- * @param {(value: any) => any} update - A function that takes the current value and returns the updated value.
1352
- */
1353
- updateCellData({ col, row }, update) {
1354
- const dataRow = this._sorting.getDataIndex(row);
1355
- const fields = this._view?.fields ?? [];
1356
- const field = fields[col];
1357
- const value = getValue2(this._rows.value[dataRow], field.path);
1358
- const updatedValue = update(value);
1359
- setValue(this._rows.value[dataRow], field.path, updatedValue);
1360
- }
1361
- /**
1362
- * Gets the domain-appropriate cell type for a given cell position.
1363
- * This abstracts away the low-level grid plane concepts and provides domain-specific types.
1364
- * @param cell - The cell position to classify
1365
- * @returns The domain-appropriate cell type
1366
- */
1367
- getCellType(cell) {
1368
- switch (cell.plane) {
1369
- case "frozenRowsEnd":
1370
- return "draft";
1371
- case "frozenRowsStart":
1372
- return "header";
1373
- case "grid":
1374
- default:
1375
- return "standard";
1376
- }
1377
- }
1378
- /**
1379
- * Convenience method to check if a cell is a draft cell.
1380
- * @param cell - The cell position to check
1381
- * @returns true if the cell is a draft cell, false otherwise
1382
- */
1383
- isDraftCell(cell) {
1384
- return this.getCellType(cell) === "draft";
1385
- }
1386
- //
1387
- // Column Operations
1388
- //
1389
- deleteColumn(fieldId) {
1390
- if (!this._view) {
527
+ return fieldProjection2;
528
+ }, [
529
+ model,
530
+ editing
531
+ ]);
532
+ const handleEnter = useCallback2(async (value) => {
533
+ if (!model || !editing) {
1391
534
  return;
1392
535
  }
1393
- const field = this._view?.fields.find((field2) => field2.id === fieldId);
1394
- if (field && this._onDeleteColumn) {
1395
- this._onDeleteColumn(field.id);
1396
- }
1397
- }
1398
- //
1399
- // Resize
1400
- //
1401
- setColumnWidth(columnIndex, width) {
1402
- const fields = this._view?.fields ?? [];
1403
- if (columnIndex < fields.length) {
1404
- const newWidth = Math.max(0, width);
1405
- const field = fields[columnIndex];
1406
- if (field) {
1407
- field.size = newWidth;
1408
- }
1409
- }
1410
- }
1411
- //
1412
- // Pinning
1413
- //
1414
- // TODO(burdon): Change to setPinned(on/off).
1415
- pinRow(rowIndex, side) {
1416
- this._pinnedRows[side].push(rowIndex);
1417
- }
1418
- unpinRow(rowIndex) {
1419
- this._pinnedRows.top = this._pinnedRows.top.filter((index) => index !== rowIndex);
1420
- this._pinnedRows.bottom = this._pinnedRows.bottom.filter((index) => index !== rowIndex);
1421
- }
1422
- //
1423
- // View operations
1424
- //
1425
- saveView() {
1426
- this._sorting.save();
1427
- }
1428
- };
1429
- var editorTextToCellValue = (props, value) => {
1430
- switch (props.format) {
1431
- case FormatEnum3.Ref: {
1432
- if (isLiveObject(value)) {
1433
- return Ref3.make(value);
1434
- } else {
1435
- return value;
1436
- }
1437
- }
1438
- case FormatEnum3.SingleSelect: {
1439
- const ids = extractTagIds(value);
1440
- if (ids && ids.length > 0) {
1441
- return ids[0];
1442
- } else {
1443
- return value;
1444
- }
1445
- }
1446
- case FormatEnum3.MultiSelect: {
1447
- const ids = extractTagIds(value);
1448
- return ids || value;
1449
- }
1450
- default: {
1451
- return parseValue({
1452
- type: props.type,
1453
- format: props.format,
1454
- value
1455
- });
1456
- }
1457
- }
1458
- };
1459
-
1460
- // src/model/modal-controller.ts
1461
- import { signal as signal4 } from "@preact/signals-core";
1462
- import { log } from "@dxos/log";
1463
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
1464
- var ModalController = class {
1465
- constructor() {
1466
- this._state = signal4({
1467
- type: "closed"
1468
- });
1469
- this._triggerRef = {
1470
- current: null
1471
- };
1472
- this.setTrigger = (trigger) => {
1473
- this._triggerRef.current = trigger;
1474
- };
1475
- this.showRowMenu = (rowIndex) => {
1476
- this._state.value = {
1477
- type: "row",
1478
- rowIndex
1479
- };
1480
- };
1481
- this.showColumnMenu = (fieldId) => {
1482
- this._state.value = {
1483
- type: "column",
1484
- fieldId
1485
- };
1486
- };
1487
- this.showColumnCreator = () => {
1488
- this._state.value = {
1489
- type: "columnSettings",
1490
- mode: {
1491
- type: "create"
1492
- }
1493
- };
1494
- };
1495
- this.showReferencePanel = (targetId, schemaId) => {
1496
- this._state.value = {
1497
- type: "refPanel",
1498
- targetId,
1499
- typename: schemaId
1500
- };
1501
- };
1502
- this.openColumnSettings = () => {
1503
- if (this._state.value.type === "column") {
1504
- const fieldId = this._state.value.fieldId;
1505
- requestAnimationFrame(() => {
1506
- this._state.value = {
1507
- type: "columnSettings",
1508
- mode: {
1509
- type: "edit",
1510
- fieldId
1511
- }
1512
- };
1513
- });
1514
- }
1515
- };
1516
- this.openCreateRef = (typename, anchorCell, initialValues, onCreate) => {
1517
- if (anchorCell) {
1518
- this._triggerRef.current = anchorCell;
1519
- this._state.value = {
1520
- type: "createRefPanel",
1521
- typename,
1522
- initialValues,
1523
- onCreate
1524
- };
1525
- } else {
1526
- log.warn("anchor cell not found while creating new ref", void 0, {
1527
- F: __dxlog_file2,
1528
- L: 86,
1529
- S: this,
1530
- C: (f, a) => f(...a)
1531
- });
1532
- }
1533
- };
1534
- this.close = () => {
1535
- this._state.value = {
1536
- type: "closed"
1537
- };
1538
- };
1539
- }
1540
- get state() {
1541
- return this._state;
1542
- }
1543
- get trigger() {
1544
- return this._triggerRef;
1545
- }
1546
- };
1547
-
1548
- // src/model/table-presentation.ts
1549
- import { signal as signal5 } from "@preact/signals-core";
1550
- import { isNotNullable } from "effect/Predicate";
1551
- import { Obj as Obj2 } from "@dxos/echo";
1552
- import { FormatEnum as FormatEnum4, getValue as getValue3, TypeEnum as TypeEnum3 } from "@dxos/echo-schema";
1553
- import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
1554
- import { toPlaneCellIndex } from "@dxos/react-ui-grid";
1555
- import { mx } from "@dxos/react-ui-theme";
1556
- import { VIEW_FIELD_LIMIT } from "@dxos/schema";
1557
- var TablePresentation = class {
1558
- constructor(model, _visibleRange = signal5({
1559
- start: {
1560
- row: 0,
1561
- col: 0
1562
- },
1563
- end: {
1564
- row: 0,
1565
- col: 0
1566
- }
1567
- })) {
1568
- this.model = model;
1569
- this._visibleRange = _visibleRange;
1570
- this.fieldProjectionCache = /* @__PURE__ */ new Map();
1571
- }
1572
- getCells(range, plane) {
1573
- this.fieldProjectionCache.clear();
1574
- let cells;
1575
- switch (plane) {
1576
- case "grid":
1577
- this._visibleRange.value = range;
1578
- cells = this.getMainGridCells(range);
1579
- break;
1580
- case "frozenRowsStart":
1581
- cells = this.getHeaderCells(range);
1582
- break;
1583
- case "frozenColsStart":
1584
- cells = this.getSelectionColumnCells(range);
1585
- break;
1586
- case "frozenColsEnd":
1587
- cells = this.getActionColumnCells(range);
1588
- break;
1589
- case "fixedStartStart":
1590
- cells = this.getSelectAllCell();
1591
- break;
1592
- case "fixedStartEnd":
1593
- cells = this.getNewColumnCell();
1594
- break;
1595
- case "frozenRowsEnd":
1596
- cells = this.getDraftRowCells(range);
1597
- break;
1598
- case "fixedEndEnd":
1599
- cells = this.getDraftActionCells(range);
1600
- break;
1601
- default:
1602
- cells = {};
1603
- }
1604
- if (plane === "grid" && this.model.features.dataEditable === false) {
1605
- Object.values(cells).forEach((cell) => {
1606
- cell.readonly = "text-select";
1607
- });
1608
- }
1609
- return cells;
1610
- }
1611
- /**
1612
- * Gets a field projection, using cache if available within the current render pass.
1613
- */
1614
- getFieldProjection(fieldId) {
1615
- let projection = this.fieldProjectionCache.get(fieldId);
1616
- if (!projection) {
1617
- projection = this.model.projection.getFieldProjection(fieldId);
1618
- this.fieldProjectionCache.set(fieldId, projection);
1619
- }
1620
- return projection;
1621
- }
1622
- createDataCell(cells, obj, field, colIndex, displayIndex) {
1623
- const { props } = this.getFieldProjection(field.id);
1624
- const cell = {
1625
- get value() {
1626
- const value = getValue3(obj, field.path);
1627
- if (value == null) {
1628
- return "";
1629
- }
1630
- if (props.type === "array") {
1631
- return "";
1632
- }
1633
- switch (props.format) {
1634
- case FormatEnum4.Boolean:
1635
- case FormatEnum4.SingleSelect:
1636
- case FormatEnum4.MultiSelect: {
1637
- return "";
1638
- }
1639
- case FormatEnum4.Ref: {
1640
- if (!field.referencePath) {
1641
- return "";
1642
- }
1643
- return getValue3(value.target, field.referencePath);
1644
- }
1645
- default: {
1646
- return formatForDisplay2({
1647
- type: props.type,
1648
- format: props.format,
1649
- value
1650
- });
1651
- }
1652
- }
1653
- }
1654
- };
1655
- const classes = [];
1656
- const formatClasses = cellClassesForFieldType({
1657
- type: props.type,
1658
- format: props.format
1659
- });
1660
- if (formatClasses) {
1661
- classes.push(formatClasses);
1662
- }
1663
- const rowSelectionClasses = cellClassesForRowSelection(this.model.selection.isObjectSelected(obj), this.model.selection.selectionMode);
1664
- if (rowSelectionClasses) {
1665
- classes.push(rowSelectionClasses);
1666
- }
1667
- if (classes.length > 0) {
1668
- cell.className = mx(classes.flat());
1669
- }
1670
- if (props.type === TypeEnum3.Array) {
1671
- const targetArray = getValue3(obj, field.path);
1672
- if (targetArray && Array.isArray(targetArray)) {
1673
- const getLabel = (value) => {
1674
- if (!value) {
1675
- return void 0;
1676
- }
1677
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1678
- return String(value);
1679
- }
1680
- if (Array.isArray(value)) {
1681
- return "Array";
1682
- }
1683
- if (typeof value === "object" && value.name) {
1684
- return value.name;
1685
- }
1686
- if (typeof value === "object" && value.value) {
1687
- return `${value.value}`;
1688
- }
1689
- return "Object";
1690
- };
1691
- const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
1692
- return `<span class="dx-tag rounded-xl" data-hue="neutral">${title}</span>`;
1693
- }).join("");
1694
- cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
1695
- }
1696
- }
1697
- if (props.format === FormatEnum4.Ref && props.referenceSchema) {
1698
- const targetObj = getValue3(obj, field.path)?.target;
1699
- if (targetObj) {
1700
- const dxn = Obj2.getDXN(targetObj)?.toString();
1701
- cell.accessoryHtml = `<dx-ref-tag refId=${dxn} class="dx-button is-6 pli-[3px] pbe-[2px] min-bs-0 absolute inline-end-1"><dx-icon icon="ph--link-simple--regular"/></dx-ref-tag>`;
1702
- }
1703
- }
1704
- if (props.format === FormatEnum4.Boolean) {
1705
- const value = getValue3(obj, field.path);
1706
- cell.accessoryHtml = tableControls.switch.render({
1707
- colIndex,
1708
- rowIndex: displayIndex,
1709
- checked: value ?? false
1710
- });
1711
- cell.readonly = "no-text-select";
1712
- }
1713
- if (props.format === FormatEnum4.SingleSelect) {
1714
- const value = getValue3(obj, field.path);
1715
- const options = this.model.projection.getFieldProjection(field.id).props.options;
1716
- if (options) {
1717
- const option = options.find((o) => o.id === value);
1718
- if (option) {
1719
- cell.accessoryHtml = `<span class="dx-tag" data-hue="${option.color}">${option.title}</span>`;
1720
- }
1721
- }
1722
- }
1723
- if (props.format === FormatEnum4.MultiSelect) {
1724
- const values = getValue3(obj, field.path);
1725
- const options = this.model.projection.getFieldProjection(field.id).props.options;
1726
- if (options && values && values.length > 0) {
1727
- const tags = values.map((value) => {
1728
- const option = options.find((o) => o.id === value);
1729
- if (option) {
1730
- return `<span class="dx-tag" data-hue="${option.color}">${option.title}</span>`;
1731
- }
1732
- return null;
1733
- }).filter(Boolean).join("");
1734
- if (tags) {
1735
- cell.accessoryHtml = tags;
1736
- }
1737
- }
1738
- }
1739
- const idx = toPlaneCellIndex({
1740
- col: colIndex,
1741
- row: displayIndex
1742
- });
1743
- cells[idx] = cell;
1744
- }
1745
- getMainGridCells(range) {
1746
- const cells = {};
1747
- const fields = this.model.view?.fields ?? [];
1748
- for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
1749
- for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1750
- const field = fields[col];
1751
- if (!field) {
1752
- continue;
1753
- }
1754
- this.createDataCell(cells, this.model.rows.value[row], field, col, row);
1755
- }
1756
- }
1757
- return cells;
1758
- }
1759
- getDraftRowCells(range) {
1760
- const cells = {};
1761
- const fields = this.model.view?.fields ?? [];
1762
- const draftRows = this.model.draftRows.value;
1763
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1764
- const draftRow = draftRows[row];
1765
- for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1766
- const field = fields[col];
1767
- if (!field) {
1768
- continue;
1769
- }
1770
- this.createDataCell(cells, draftRow.data, field, col, row);
1771
- if (this.model.hasDraftRowValidationError(row, field.path)) {
1772
- const cellIndex = toPlaneCellIndex({
1773
- col,
1774
- row
1775
- });
1776
- const cellValue = cells[cellIndex];
1777
- if (cellValue) {
1778
- const existingClasses = cellValue.className || "";
1779
- const draftClasses = "dx-grid__cell--flagged";
1780
- cellValue.className = existingClasses ? `${existingClasses} ${draftClasses}` : draftClasses;
1781
- }
1782
- }
1783
- }
1784
- }
1785
- return cells;
1786
- }
1787
- getHeaderCells(range) {
1788
- const cells = {};
1789
- const fields = this.model.view?.fields ?? [];
1790
- for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1791
- const { field, props } = this.getFieldProjection(fields[col].id);
1792
- const sorting = this.model.sorting?.sorting;
1793
- const direction = sorting?.fieldId === field.id ? sorting.direction : void 0;
1794
- cells[toPlaneCellIndex({
1795
- col,
1796
- row: 0
1797
- })] = {
1798
- // TODO(burdon): Use same logic as form for fallback title.
1799
- value: props.title ?? field.path,
1800
- readonly: true,
1801
- resizeHandle: "col",
1802
- accessoryHtml: `
1803
- ${direction !== void 0 ? tableButtons.sort.render({
1804
- fieldId: field.id,
1805
- direction
1806
- }) : ""}
1807
- ${tableButtons.columnSettings.render({
1808
- fieldId: field.id
1809
- })}
1810
- `,
1811
- className: "!bg-toolbarSurface"
1812
- };
1813
- }
1814
- return cells;
1815
- }
1816
- getSelectionColumnCells(range) {
1817
- const cells = {};
1818
- for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
1819
- const isSelected = this.model.selection.isRowIndexSelected(row);
1820
- const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
1821
- cells[toPlaneCellIndex({
1822
- col: 0,
1823
- row
1824
- })] = {
1825
- value: "",
1826
- readonly: "no-text-select",
1827
- className: classes ? mx(classes) : void 0,
1828
- accessoryHtml: tableControls.checkbox.render({
1829
- rowIndex: row,
1830
- checked: isSelected
1831
- })
1832
- };
1833
- }
1834
- return cells;
1835
- }
1836
- getActionColumnCells(range) {
1837
- const cells = {};
1838
- for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
1839
- const isSelected = this.model.selection.isRowIndexSelected(row);
1840
- const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
1841
- cells[toPlaneCellIndex({
1842
- col: 0,
1843
- row
1844
- })] = {
1845
- value: "",
1846
- readonly: true,
1847
- className: classes ? mx(classes) : void 0,
1848
- accessoryHtml: tableButtons.rowMenu.render({
1849
- rowIndex: row
1850
- })
1851
- };
1852
- }
1853
- return cells;
1854
- }
1855
- getSelectAllCell() {
1856
- if (!this.model.features.selection.enabled || this.model.selection.selectionMode === "single") {
1857
- return {
1858
- [toPlaneCellIndex({
1859
- col: 0,
1860
- row: 0
1861
- })]: {
1862
- className: "!bg-toolbarSurface",
1863
- readonly: true,
1864
- value: ""
1865
- }
1866
- };
1867
- }
1868
- return {
1869
- [toPlaneCellIndex({
1870
- col: 0,
1871
- row: 0
1872
- })]: {
1873
- accessoryHtml: tableControls.checkbox.render({
1874
- rowIndex: 0,
1875
- header: true,
1876
- checked: this.model.selection.allRowsSeleted.value
1877
- }),
1878
- className: "!bg-toolbarSurface",
1879
- readonly: true,
1880
- value: ""
1881
- }
1882
- };
1883
- }
1884
- getNewColumnCell() {
1885
- return {
1886
- [toPlaneCellIndex({
1887
- col: 0,
1888
- row: 0
1889
- })]: {
1890
- accessoryHtml: this.model.features.schemaEditable ? tableButtons.addColumn.render({
1891
- disabled: (this.model.view?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
1892
- }) : void 0,
1893
- className: "!bg-toolbarSurface",
1894
- readonly: true,
1895
- value: ""
1896
- }
1897
- };
1898
- }
1899
- getDraftActionCells(range) {
1900
- const cells = {};
1901
- const draftRows = this.model.draftRows.value;
1902
- for (let row = range.start.row; row <= range.end.row && row < draftRows.length; row++) {
1903
- const draftRow = draftRows[row];
1904
- const disabled = !draftRow.valid;
1905
- cells[toPlaneCellIndex({
1906
- col: 0,
1907
- row
1908
- })] = {
1909
- value: "",
1910
- readonly: true,
1911
- accessoryHtml: tableButtons.saveDraftRow.render({
1912
- rowIndex: row,
1913
- disabled
1914
- })
1915
- };
1916
- }
1917
- return cells;
1918
- }
1919
- };
1920
- var cellClassesForRowSelection = (selected, selectionMode) => {
1921
- if (!selected) {
1922
- if (selectionMode === "single") {
1923
- return [
1924
- "!cursor-pointer"
1925
- ];
1926
- } else {
1927
- return void 0;
1928
- }
1929
- }
1930
- switch (selectionMode) {
1931
- case "single":
1932
- return [
1933
- "!bg-currentRelated hover:bg-hoverSurface",
1934
- "!cursor-pointer"
1935
- ];
1936
- case "multiple":
1937
- return [
1938
- "!bg-gridCellSelected"
1939
- ];
1940
- }
1941
- };
1942
-
1943
- // src/components/TableCellEditor/TableCellEditor.tsx
1944
- import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
1945
- import React7, { useCallback as useCallback4, useEffect as useEffect3, useMemo as useMemo4, useRef as useRef2, useState as useState2 } from "react";
1946
- import { FormatEnum as FormatEnum5, TypeEnum as TypeEnum4 } from "@dxos/echo-schema";
1947
- import { invariant as invariant3 } from "@dxos/invariant";
1948
- import { useThemeContext } from "@dxos/react-ui";
1949
- import { createMarkdownExtensions } from "@dxos/react-ui-editor";
1950
- import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext4, GridCellEditor } from "@dxos/react-ui-grid";
1951
- import { tagPicker, createLinks } from "@dxos/react-ui-tag-picker";
1952
-
1953
- // src/components/TableCellEditor/CellValidationMessage.tsx
1954
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1955
- import React5 from "react";
1956
- import { useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
1957
- var CellValidationMessage = ({ validationError, variant = "error", __gridScope }) => {
1958
- var _effect = _useSignals5();
1959
- try {
1960
- const { editing, editBox: box } = useGridContext2("GridSheetCellEditor", __gridScope);
1961
- if (!editing || !validationError) {
1962
- return null;
1963
- }
1964
- const bgClass = variant === "error" ? "bg-errorSurface" : "bg-warningSurface";
1965
- const textClass = variant === "error" ? "text-errorSurfaceText" : "text-warningSurfaceText";
1966
- return /* @__PURE__ */ React5.createElement("div", {
1967
- role: "none",
1968
- className: `absolute ${bgClass} ${textClass} rounded-bs-sm text-xs p-1`,
1969
- style: {
1970
- ...{
1971
- "--dx-gridCellWidth": `${box?.inlineSize ?? 200}px`
1972
- },
1973
- zIndex: 10,
1974
- insetBlockEnd: `calc(100% - ${box.insetBlockStart}px)`,
1975
- insetInlineStart: box.insetInlineStart,
1976
- inlineSize: box.inlineSize
1977
- }
1978
- }, validationError);
1979
- } finally {
1980
- _effect.f();
1981
- }
1982
- };
1983
-
1984
- // src/components/TableCellEditor/FormCellEditor.tsx
1985
- import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
1986
- import React6, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
1987
- import { getSnapshot as getSnapshot2 } from "@dxos/echo-schema";
1988
- import { invariant as invariant2 } from "@dxos/invariant";
1989
- import { Popover as Popover3 } from "@dxos/react-ui";
1990
- import { Form as Form2 } from "@dxos/react-ui-form";
1991
- import { parseCellIndex, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
1992
- import { getDeep, setDeep } from "@dxos/util";
1993
- var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
1994
- var FormCellEditor = ({ fieldProjection, model, schema, __gridScope }) => {
1995
- var _effect = _useSignals6();
1996
- try {
1997
- const { editing, setEditing } = useGridContext3("ArrayEditor", __gridScope);
1998
- const cellRef = useRef(null);
1999
- useEffect2(() => {
2000
- if (editing && editing.cellElement) {
2001
- cellRef.current = editing.cellElement;
2002
- }
2003
- }, [
2004
- editing?.cellElement
2005
- ]);
2006
- const narrowedSchema = useMemo3(() => {
2007
- if (!schema) {
2008
- return void 0;
2009
- }
2010
- return narrowSchema(schema, [
2011
- fieldProjection.field.path
2012
- ]);
2013
- }, [
2014
- JSON.stringify(schema),
2015
- fieldProjection.field.path
2016
- ]);
2017
- const originalRow = useMemo3(() => {
2018
- if (model && editing) {
2019
- const cell = parseCellIndex(editing.index);
2020
- const row = model.getRowAt(cell.row);
2021
- invariant2(row, void 0, {
2022
- F: __dxlog_file3,
2023
- L: 47,
2024
- S: void 0,
2025
- A: [
2026
- "row",
2027
- ""
2028
- ]
2029
- });
2030
- return row;
2031
- }
2032
- return void 0;
2033
- }, [
2034
- model,
2035
- editing
2036
- ]);
2037
- const formValues = useMemo3(() => {
2038
- if (originalRow) {
2039
- return getSnapshot2(originalRow);
2040
- }
2041
- }, [
2042
- originalRow
2043
- ]);
2044
- const handleSave = useCallback3((values) => {
2045
- const path = fieldProjection.field.path;
2046
- const value = getDeep(values, [
2047
- path
2048
- ]);
2049
- setDeep(originalRow, [
2050
- path
2051
- ], value);
536
+ const cell = parseCellIndex2(editing.index);
537
+ const validationResult = await model.validateCellData(cell, value);
538
+ if (validationResult.valid) {
539
+ setValidationError(null);
540
+ model.setCellData(cell, value);
541
+ onFocus?.();
2052
542
  setEditing(null);
2053
- }, [
2054
- fieldProjection.field.path,
2055
- originalRow
2056
- ]);
2057
- const handleOpenChange = useCallback3((nextOpen) => {
2058
- if (nextOpen === false) {
2059
- setEditing(null);
2060
- }
2061
- }, [
2062
- setEditing
2063
- ]);
2064
- if (!editing) {
2065
- return null;
2066
- }
2067
- return /* @__PURE__ */ React6.createElement(Popover3.Root, {
2068
- open: editing !== null,
2069
- onOpenChange: handleOpenChange
2070
- }, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
2071
- virtualRef: cellRef
2072
- }), /* @__PURE__ */ React6.createElement(Popover3.Content, {
2073
- tabIndex: -1,
2074
- classNames: "popover-card-width"
2075
- }, /* @__PURE__ */ React6.createElement(Popover3.Arrow, null), /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, /* @__PURE__ */ React6.createElement(Form2, {
2076
- values: formValues,
2077
- schema: narrowedSchema,
2078
- onSave: handleSave
2079
- }))));
2080
- } finally {
2081
- _effect.f();
2082
- }
2083
- };
2084
-
2085
- // src/components/TableCellEditor/extension.ts
2086
- import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
2087
- import { EditorView } from "@codemirror/view";
2088
- var completion = ({ debug, onQuery, onMatch }) => {
2089
- return [
2090
- EditorView.theme({
2091
- ".cm-completionDialog": {
2092
- width: "var(--dx-gridCellWidth)"
2093
- }
2094
- }),
2095
- autocompletion({
2096
- icons: false,
2097
- activateOnTyping: true,
2098
- closeOnBlur: !debug,
2099
- override: [
2100
- async (context) => {
2101
- const text = context.state.doc.toString();
2102
- return {
2103
- from: 0,
2104
- options: await onQuery(text)
2105
- };
2106
- }
2107
- ],
2108
- // TODO(burdon): Consts from grid (to line-up with grid).
2109
- tooltipClass: () => "cm-completionDialog !mt-[8px] !-ml-[4px] [&>ul]:!max-h-[264px]",
2110
- optionClass: () => "flex h-[33px] items-center"
2111
- }),
2112
- // Check for accepted completion metadata in the transaction.
2113
- EditorView.updateListener.of((update) => {
2114
- update.transactions.forEach((tr) => {
2115
- const completion2 = tr.annotation(pickedCompletion);
2116
- if (completion2) {
2117
- onMatch(completion2.data);
2118
- }
2119
- });
2120
- })
2121
- ];
2122
- };
2123
-
2124
- // src/components/TableCellEditor/TableCellEditor.tsx
2125
- var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
2126
- var newValue = Symbol.for("newValue");
2127
- var createOption = (text) => ({
2128
- [newValue]: true,
2129
- text
2130
- });
2131
- var isCreateOption = (data) => typeof data === "object" && data[newValue];
2132
- var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onQuery, __gridScope }) => {
2133
- var _effect = _useSignals7();
2134
- try {
2135
- const { editing } = useGridContext4("TableValueEditor", __gridScope);
2136
- const fieldProjection = useMemo4(() => {
2137
- if (!model || !editing) {
2138
- return;
2139
- }
2140
- const { col } = parseCellIndex2(editing.index);
2141
- const field = model.projection.view.fields[col];
2142
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
2143
- invariant3(fieldProjection2, void 0, {
2144
- F: __dxlog_file4,
2145
- L: 74,
2146
- S: void 0,
2147
- A: [
2148
- "fieldProjection",
2149
- ""
2150
- ]
2151
- });
2152
- return fieldProjection2;
2153
- }, [
2154
- model,
2155
- editing
2156
- ]);
2157
- if (fieldProjection?.props.type === TypeEnum4.Array) {
2158
- return /* @__PURE__ */ React7.createElement(FormCellEditor, {
2159
- fieldProjection,
2160
- model,
2161
- schema,
2162
- __gridScope
2163
- });
543
+ onSave?.();
544
+ } else {
545
+ setValidationError(validationResult.error);
546
+ setValidationVariant("error");
2164
547
  }
2165
- return /* @__PURE__ */ React7.createElement(TableCellEditor, {
2166
- model,
2167
- modals,
2168
- onEnter,
2169
- onFocus,
2170
- onQuery,
2171
- __gridScope
2172
- });
2173
- } finally {
2174
- _effect.f();
2175
- }
2176
- };
2177
- var editorSlots = {
2178
- scroller: {
2179
- className: "!plb-[--dx-grid-cell-editor-padding-block]"
2180
- }
2181
- };
2182
- var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
2183
- var _effect = _useSignals7();
2184
- try {
2185
- const { id: gridId, editing, setEditing } = useGridContext4("TableCellEditor", __gridScope);
2186
- const suppressNextBlur = useRef2(false);
2187
- const { themeMode } = useThemeContext();
2188
- const [_validationError, setValidationError] = useState2(null);
2189
- const [_validationVariant, setValidationVariant] = useState2("error");
2190
- const fieldProjection = useMemo4(() => {
2191
- if (!model || !editing) {
2192
- return;
2193
- }
2194
- const { col } = parseCellIndex2(editing.index);
2195
- const field = model.projection.view.fields[col];
2196
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
2197
- invariant3(fieldProjection2, void 0, {
2198
- F: __dxlog_file4,
2199
- L: 119,
2200
- S: void 0,
2201
- A: [
2202
- "fieldProjection",
2203
- ""
2204
- ]
2205
- });
2206
- return fieldProjection2;
2207
- }, [
2208
- model,
2209
- editing
2210
- ]);
2211
- useEffect3(() => {
2212
- if (!model || !editing || !fieldProjection) {
2213
- setValidationError(null);
2214
- return;
2215
- }
2216
- const cell = parseCellIndex2(editing.index);
2217
- const { row, col } = cell;
2218
- if (model.isDraftCell(cell)) {
2219
- const field = model.projection.view.fields[col];
2220
- const hasValidationError = model.hasDraftRowValidationError(row, field.path);
2221
- if (hasValidationError) {
2222
- const draftRows = model.draftRows.value;
2223
- if (row >= 0 && row < draftRows.length) {
2224
- const draftRow = draftRows[row];
2225
- const validationError = draftRow.validationErrors?.find((error) => error.path === field.path);
2226
- if (validationError) {
2227
- setValidationError(validationError.message);
2228
- setValidationVariant("warning");
2229
- }
2230
- }
2231
- } else {
2232
- setValidationError(null);
2233
- }
2234
- } else {
2235
- setValidationError(null);
2236
- }
2237
- }, [
2238
- model,
2239
- editing,
2240
- fieldProjection
2241
- ]);
2242
- const handleEnter = useCallback4(async (value) => {
2243
- if (!model || !editing) {
2244
- return;
2245
- }
2246
- const cell = parseCellIndex2(editing.index);
2247
- const validationResult = await model.validateCellData(cell, value);
2248
- if (validationResult.valid) {
2249
- setValidationError(null);
2250
- model.setCellData(cell, value);
2251
- onEnter?.(cell);
2252
- onFocus?.();
2253
- setEditing(null);
2254
- } else {
2255
- setValidationError(validationResult.error);
2256
- setValidationVariant("error");
2257
- }
2258
- }, [
2259
- model,
2260
- editing,
2261
- onEnter,
2262
- onFocus,
2263
- setEditing
2264
- ]);
2265
- const handleBlur = useCallback4(async (value) => {
2266
- if (!model || !editing) {
2267
- return;
2268
- }
2269
- if (suppressNextBlur.current) {
2270
- suppressNextBlur.current = false;
2271
- }
2272
- }, [
2273
- model,
2274
- editing
2275
- ]);
2276
- const handleClose = useCallback4(async (value, event) => {
2277
- if (!model || !editing || !fieldProjection) {
2278
- return;
2279
- }
548
+ }, [
549
+ model,
550
+ editing,
551
+ onFocus,
552
+ setEditing
553
+ ]);
554
+ const handleBlur = useCallback2(async (value) => {
555
+ if (suppressNextBlur.current) {
556
+ suppressNextBlur.current = false;
557
+ } else if (model && editing) {
2280
558
  const cell = parseCellIndex2(editing.index);
2281
559
  if (value !== void 0) {
2282
560
  const result = await model.validateCellData(cell, value);
@@ -2284,169 +562,109 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
2284
562
  setValidationError(null);
2285
563
  model.setCellData(cell, value);
2286
564
  setEditing(null);
2287
- onEnter?.(cell);
2288
- if (event && onFocus) {
2289
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
2290
- }
2291
- } else {
2292
- setValidationError(result.error);
2293
- setValidationVariant("error");
565
+ onSave?.();
2294
566
  }
2295
- } else {
567
+ }
568
+ }
569
+ }, [
570
+ model,
571
+ editing
572
+ ]);
573
+ const handleClose = useCallback2(async (value, event) => {
574
+ if (!model || !editing || !fieldProjection) {
575
+ return;
576
+ }
577
+ const cell = parseCellIndex2(editing.index);
578
+ if (value !== void 0) {
579
+ const result = await model.validateCellData(cell, value);
580
+ if (result.valid) {
581
+ suppressNextBlur.current = true;
2296
582
  setValidationError(null);
583
+ model.setCellData(cell, value);
2297
584
  setEditing(null);
585
+ onSave?.();
2298
586
  if (event && onFocus) {
2299
- onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
587
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event), cell);
2300
588
  }
589
+ } else {
590
+ setValidationError(result.error);
591
+ setValidationVariant("error");
2301
592
  }
2302
- }, [
2303
- model,
2304
- editing,
2305
- onFocus,
2306
- onEnter,
2307
- fieldProjection,
2308
- setEditing
2309
- ]);
2310
- const extension = useMemo4(() => {
2311
- if (!fieldProjection) {
2312
- return [];
2313
- }
2314
- const extension2 = [
2315
- editorKeys({
2316
- onClose: handleClose,
2317
- ...editing?.initialContent && {
2318
- onNav: handleClose
2319
- }
2320
- })
2321
- ];
2322
- const format = fieldProjection.props.format;
2323
- if (format === FormatEnum5.SingleSelect || format === FormatEnum5.MultiSelect) {
2324
- extension2.push(createMarkdownExtensions({
2325
- themeMode
2326
- }));
2327
- const options = fieldProjection.props.options || [];
2328
- const mode = format === FormatEnum5.SingleSelect ? "single-select" : "multi-select";
2329
- extension2.push(tagPicker({
2330
- mode,
2331
- keymap: false,
2332
- onSearch: (text, selectedIds) => {
2333
- return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
2334
- id: option.id,
2335
- label: option.title,
2336
- hue: option.color
2337
- }));
2338
- },
2339
- onUpdate: (ids) => {
2340
- if (model && editing) {
2341
- if (ids.length === 0) {
2342
- return;
2343
- }
2344
- if (mode === "single-select") {
2345
- void handleEnter(ids[0]);
2346
- } else {
2347
- void handleEnter(ids);
2348
- }
2349
- }
2350
- }
2351
- }));
593
+ } else {
594
+ suppressNextBlur.current = true;
595
+ setValidationError(null);
596
+ setEditing(null);
597
+ onSave?.();
598
+ if (event && onFocus) {
599
+ onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
2352
600
  }
2353
- if (onQuery) {
2354
- switch (fieldProjection.props.format) {
2355
- case FormatEnum5.Ref: {
2356
- extension2.push([
2357
- completion({
2358
- onQuery: (text) => onQuery(fieldProjection, text),
2359
- onMatch: (data) => {
2360
- if (model && editing && modals) {
2361
- if (isCreateOption(data)) {
2362
- const { field, props } = fieldProjection;
2363
- if (props.referenceSchema) {
2364
- suppressNextBlur.current = true;
2365
- modals.openCreateRef(props.referenceSchema, document.querySelector(cellQuery(editing.index, gridId)), {
2366
- [field.referencePath]: data.text
2367
- }, (data2) => {
2368
- void handleEnter(data2);
2369
- });
2370
- }
2371
- } else {
2372
- void handleEnter(data);
2373
- }
2374
- }
2375
- }
2376
- })
2377
- ]);
2378
- break;
2379
- }
601
+ }
602
+ }, [
603
+ model,
604
+ editing,
605
+ onFocus,
606
+ fieldProjection,
607
+ setEditing,
608
+ onSave
609
+ ]);
610
+ const extensions = useMemo2(() => {
611
+ if (!fieldProjection) {
612
+ return [];
613
+ }
614
+ const extensions2 = [
615
+ editorKeys({
616
+ onClose: handleClose,
617
+ ...editing?.initialContent && {
618
+ onNav: handleClose
2380
619
  }
2381
- }
2382
- return extension2;
2383
- }, [
2384
- model,
2385
- modals,
2386
- editing,
2387
- fieldProjection,
2388
- handleClose,
2389
- themeMode
2390
- ]);
2391
- const getCellContent = useCallback4(() => {
2392
- if (model && editing) {
620
+ })
621
+ ];
622
+ if (model && editing) {
623
+ extensions2.push(EditorView.updateListener.of(debounce((update) => {
624
+ const content = update.state.doc.toString();
2393
625
  const cell = parseCellIndex2(editing.index);
2394
- const { col } = cell;
2395
- const field = model.projection.view.fields[col];
2396
- const fieldProjection2 = model.projection.getFieldProjection(field.id);
2397
- if (fieldProjection2?.props.format === FormatEnum5.SingleSelect || fieldProjection2?.props.format === FormatEnum5.MultiSelect) {
2398
- const value2 = model.getCellData(cell);
2399
- if (value2 !== void 0) {
2400
- const options = fieldProjection2.props.options || [];
2401
- if (fieldProjection2.props.format === FormatEnum5.MultiSelect) {
2402
- const tagItems = value2.split(",").map((id) => {
2403
- const option = options.find((o) => o.id === id);
2404
- if (option) {
2405
- return {
2406
- id,
2407
- label: option.title,
2408
- hue: option.color
2409
- };
2410
- }
2411
- return void 0;
2412
- }).filter((item) => item !== void 0);
2413
- return createLinks(tagItems);
2414
- } else {
2415
- const option = options.find((o) => o.id === value2);
2416
- if (option) {
2417
- const tagItem = {
2418
- id: value2,
2419
- label: option.title,
2420
- hue: option.color
2421
- };
2422
- return createLinks([
2423
- tagItem
2424
- ]);
2425
- }
2426
- }
626
+ void model.validateCellData(cell, content).then((result) => {
627
+ if (result.valid) {
628
+ setValidationError(null);
629
+ } else {
630
+ setValidationError(result.error);
631
+ setValidationVariant("error");
2427
632
  }
2428
- return "";
2429
- }
2430
- const value = model.getCellData(cell);
2431
- return value !== void 0 ? String(value) : "";
633
+ });
634
+ }, 10)));
635
+ }
636
+ return extensions2;
637
+ }, [
638
+ model,
639
+ modals,
640
+ editing,
641
+ fieldProjection,
642
+ handleClose
643
+ ]);
644
+ const getCellContent = useCallback2(() => {
645
+ if (model && editing) {
646
+ const cell = parseCellIndex2(editing.index);
647
+ const value = model.getCellData(cell);
648
+ return value !== void 0 ? String(value) : "";
649
+ }
650
+ }, [
651
+ model,
652
+ editing
653
+ ]);
654
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(CellValidationMessage, {
655
+ validationError,
656
+ variant: validationVariant,
657
+ __gridScope
658
+ }), /* @__PURE__ */ React3.createElement(GridCellEditor, {
659
+ extensions,
660
+ slots: {
661
+ content: {
662
+ className: "!py-(--dx-grid-cell-editor-padding-block)"
2432
663
  }
2433
- }, [
2434
- model,
2435
- editing
2436
- ]);
2437
- return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(CellValidationMessage, {
2438
- validationError: _validationError,
2439
- variant: _validationVariant,
2440
- __gridScope
2441
- }), /* @__PURE__ */ React7.createElement(GridCellEditor, {
2442
- extension,
2443
- getCellContent,
2444
- onBlur: handleBlur,
2445
- slots: editorSlots
2446
- }));
2447
- } finally {
2448
- _effect.f();
2449
- }
664
+ },
665
+ getCellContent,
666
+ onBlur: handleBlur
667
+ }));
2450
668
  };
2451
669
  var determineNavigationAxis = ({ key }) => {
2452
670
  switch (key) {
@@ -2473,542 +691,563 @@ var determineNavigationDelta = ({ key, shift }) => {
2473
691
  return shift ? -1 : 1;
2474
692
  };
2475
693
 
2476
- // src/components/Table/Table.tsx
2477
- var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
2478
- var TableRoot = ({ children, role }) => {
2479
- var _effect = _useSignals8();
2480
- try {
2481
- return /* @__PURE__ */ React8.createElement("div", {
2482
- role: "none",
2483
- className: mx2("relative !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-[--dx-grid-content-inline-size]" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]")
2484
- }, children);
2485
- } finally {
2486
- _effect.f();
694
+ // src/components/Table/ColumnActionsMenu.tsx
695
+ import { useAtomValue } from "@effect-atom/atom-react";
696
+ import React4 from "react";
697
+ import { DropdownMenu, useTranslation } from "@dxos/react-ui";
698
+ var ColumnActionsMenu = ({ model, modals }) => {
699
+ const { t } = useTranslation(translationKey);
700
+ const state = useAtomValue(modals.state);
701
+ if (state?.type !== "column") {
702
+ return null;
703
+ }
704
+ const currentSort = model.getSorting();
705
+ const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
706
+ return /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
707
+ modal: false,
708
+ open: true,
709
+ onOpenChange: modals.close
710
+ }, /* @__PURE__ */ React4.createElement(DropdownMenu.VirtualTrigger, {
711
+ virtualRef: modals.trigger
712
+ }), /* @__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, {
713
+ "data-testid": "column-sort-descending",
714
+ onClick: () => model.setSort(state.fieldId, "desc")
715
+ }, t("column-action-sort-descending.menu")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
716
+ "data-testid": "column-sort-ascending",
717
+ onClick: () => model.setSort(state.fieldId, "asc")
718
+ }, t("column-action-sort-ascending.menu")), isCurrentColumnSorted && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
719
+ "data-testid": "column-clear-sort",
720
+ onClick: () => model.clearSort()
721
+ }, t("column-action-clear-sorting.menu")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
722
+ "data-testid": "column-delete",
723
+ onClick: () => model.deleteColumn(state.fieldId)
724
+ }, t("column-action-delete.menu")), model.features.schemaEditable && /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
725
+ "data-testid": "column-settings",
726
+ onClick: () => modals.openColumnSettings()
727
+ }, t("column-action-settings.menu"))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))));
728
+ };
729
+
730
+ // src/components/Table/ColumnSettings.tsx
731
+ import { useAtomValue as useAtomValue2 } from "@effect-atom/atom-react";
732
+ import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useState as useState3 } from "react";
733
+ import { Popover as Popover2 } from "@dxos/react-ui";
734
+ import { FieldEditor } from "@dxos/react-ui-form";
735
+ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
736
+ const [newField, setNewField] = useState3();
737
+ const state = useAtomValue2(modals.state);
738
+ useEffect2(() => {
739
+ if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
740
+ setNewField(model.projection.createFieldProjection());
741
+ requestAnimationFrame(() => {
742
+ onNewColumn();
743
+ });
744
+ } else {
745
+ setNewField(void 0);
746
+ }
747
+ }, [
748
+ model?.projection,
749
+ state
750
+ ]);
751
+ const existingField = useMemo3(() => {
752
+ if (state?.type === "columnSettings") {
753
+ const { mode } = state;
754
+ if (mode.type === "edit") {
755
+ return model?.projection?.getFields().find((f) => f.id === mode.fieldId);
756
+ }
757
+ }
758
+ return void 0;
759
+ }, [
760
+ model?.projection,
761
+ state
762
+ ]);
763
+ const field = existingField ?? newField;
764
+ const handleSave = useCallback3(() => {
765
+ modals.close();
766
+ }, [
767
+ modals
768
+ ]);
769
+ const handleCancel = useCallback3(() => {
770
+ if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
771
+ model?.projection.deleteFieldProjection(newField.id);
772
+ }
773
+ }, [
774
+ model?.projection,
775
+ state,
776
+ newField
777
+ ]);
778
+ if (!model?.projection || !field) {
779
+ return null;
780
+ }
781
+ return /* @__PURE__ */ React5.createElement(Popover2.Root, {
782
+ modal: false,
783
+ open: state?.type === "columnSettings"
784
+ }, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
785
+ virtualRef: modals.trigger
786
+ }), /* @__PURE__ */ React5.createElement(Popover2.Portal, null, /* @__PURE__ */ React5.createElement(Popover2.Content, {
787
+ classNames: "md:w-64"
788
+ }, /* @__PURE__ */ React5.createElement(Popover2.Viewport, null, /* @__PURE__ */ React5.createElement(FieldEditor, {
789
+ projection: model.projection,
790
+ field,
791
+ registry,
792
+ onSave: handleSave,
793
+ onCancel: handleCancel
794
+ })), /* @__PURE__ */ React5.createElement(Popover2.Arrow, null))));
795
+ };
796
+
797
+ // src/components/Table/RowActionsMenu.tsx
798
+ import { useAtomValue as useAtomValue3 } from "@effect-atom/atom-react";
799
+ import React6 from "react";
800
+ import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
801
+ var RowActionsMenu = ({ model, modals }) => {
802
+ const { t } = useTranslation2(translationKey);
803
+ const hasSelection = model.selection.hasSelection;
804
+ const state = useAtomValue3(modals.state);
805
+ if (state?.type !== "row") {
806
+ return null;
807
+ }
808
+ return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
809
+ modal: false,
810
+ open: true,
811
+ onOpenChange: modals.close
812
+ }, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
813
+ virtualRef: modals.trigger
814
+ }), /* @__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, {
815
+ key: action.id,
816
+ "data-testid": `row-action-${action.id}`,
817
+ onClick: () => {
818
+ modals.close();
819
+ model.handleRowAction(action.id, state.rowIndex);
820
+ }
821
+ }, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
822
+ "data-testid": "row-menu-delete",
823
+ onClick: () => model.deleteRow(state.rowIndex)
824
+ }, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
825
+ };
826
+
827
+ // src/components/Table/TableContent.tsx
828
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/Table/TableContent.tsx";
829
+ var columnDefault = {
830
+ grid: {
831
+ minSize: 80,
832
+ maxSize: 640
2487
833
  }
2488
834
  };
2489
- var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
2490
- var _effect = _useSignals8();
2491
- try {
2492
- const [dxGrid, setDxGrid] = useState3(null);
2493
- const { hasAttention } = useAttention(model?.id ?? "table");
2494
- const { t } = useTranslation3(translationKey);
2495
- const modals = useMemo5(() => new ModalController(), []);
2496
- const draftRowCount = model?.getDraftRowCount() ?? 0;
2497
- const frozen = useMemo5(() => {
2498
- const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
2499
- return {
2500
- frozenRowsStart: 1,
2501
- frozenRowsEnd: draftRowCount,
2502
- frozenColsStart: model?.features.selection.enabled ? 1 : 0,
2503
- frozenColsEnd: noActionColumn ? 0 : 1
2504
- };
2505
- }, [
2506
- model,
2507
- draftRowCount
2508
- ]);
2509
- const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
2510
- presentation
2511
- ]);
2512
- useEffect4(() => {
2513
- if (!presentation || !dxGrid) {
2514
- return;
2515
- }
2516
- dxGrid.getCells = getCells;
2517
- }, [
2518
- presentation,
2519
- dxGrid,
2520
- getCells
2521
- ]);
2522
- useImperativeHandle(forwardedRef, () => {
2523
- if (!presentation || !dxGrid) {
2524
- return {};
835
+ var rowDefault = {
836
+ frozenRowsStart: {
837
+ readonly: true,
838
+ focusUnfurl: false
839
+ }
840
+ };
841
+ var emptyColumnMeta = Atom2.make({
842
+ grid: {}
843
+ });
844
+ var emptyRowsAtom = Atom2.make([]);
845
+ var emptyCellUpdateAtom = Atom2.make(0);
846
+ var TABLE_CONTENT_NAME = "Table.Content";
847
+ var TableContent = composable(({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId, ...props }, forwardedRef) => {
848
+ const registry = useContext(RegistryContext);
849
+ const [dxGrid, setDxGrid] = useState4(null);
850
+ const { hasAttention } = useAttention(model?.id ?? "table");
851
+ const modals = useMemo4(() => new ModalController(registry), [
852
+ registry
853
+ ]);
854
+ const columnMeta = useAtomValue4(model?.columnMeta ?? emptyColumnMeta);
855
+ const rows = useAtomValue4(model?.rows ?? emptyRowsAtom);
856
+ const cellUpdateCounter = useAtomValue4(model?.cellUpdate ?? emptyCellUpdateAtom);
857
+ const columnCount = Object.keys(columnMeta.grid).length || model?.projection.getFields().length || 0;
858
+ const draftRowCount = model?.getDraftRowCount() ?? 0;
859
+ const frozen = useMemo4(() => {
860
+ const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
861
+ return {
862
+ frozenRowsStart: 1,
863
+ frozenRowsEnd: Math.max(1, draftRowCount),
864
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
865
+ frozenColsEnd: noActionColumn ? 0 : 1
866
+ };
867
+ }, [
868
+ model,
869
+ draftRowCount
870
+ ]);
871
+ const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
872
+ presentation
873
+ ]);
874
+ useEffect3(() => {
875
+ if (!dxGrid || !presentation) {
876
+ return;
877
+ }
878
+ dxGrid.getCells = getCells;
879
+ }, [
880
+ dxGrid,
881
+ presentation,
882
+ getCells
883
+ ]);
884
+ useEffect3(() => {
885
+ if (!dxGrid) {
886
+ return;
887
+ }
888
+ dxGrid.updateCells(true);
889
+ dxGrid.requestUpdate();
890
+ }, [
891
+ dxGrid,
892
+ rows,
893
+ cellUpdateCounter
894
+ ]);
895
+ const handleInsertRowResult = useCallback4((insertResult) => {
896
+ if (insertResult === "draft") {
897
+ requestAnimationFrame(() => {
898
+ dxGrid?.setFocus({
899
+ plane: "frozenRowsEnd",
900
+ col: 0,
901
+ row: 0
902
+ });
903
+ dxGrid?.refocus();
904
+ });
905
+ } else {
906
+ requestAnimationFrame(() => {
907
+ dxGrid?.setFocus({
908
+ plane: "grid",
909
+ col: 0,
910
+ row: model ? model.getRowCount() - 1 : 0
911
+ });
912
+ dxGrid?.refocus();
913
+ });
914
+ }
915
+ }, [
916
+ model,
917
+ dxGrid
918
+ ]);
919
+ const handleSave = useCallback4(() => {
920
+ dxGrid?.updateCells(true);
921
+ dxGrid?.requestUpdate();
922
+ }, [
923
+ dxGrid
924
+ ]);
925
+ const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
926
+ if (model && dxGrid) {
927
+ const didCommitSuccessfully = model.commitDraftRow(rowIndex);
928
+ if (didCommitSuccessfully) {
929
+ requestAnimationFrame(() => {
930
+ dxGrid.scrollToEndRow();
931
+ });
2525
932
  }
2526
- return {
2527
- update: (cell) => {
2528
- if (cell) {
2529
- dxGrid.updateIfWithinBounds(cell);
2530
- } else {
2531
- dxGrid.updateCells(true);
2532
- dxGrid.requestUpdate();
2533
- }
2534
- }
2535
- };
2536
- }, [
2537
- presentation,
2538
- dxGrid
2539
- ]);
2540
- const handleGridClick = useCallback5((event) => {
2541
- const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
2542
- if (rowIndex != null) {
2543
- if (onRowClick) {
933
+ }
934
+ }, [
935
+ model,
936
+ dxGrid
937
+ ]);
938
+ const handleGridClick = useCallback4((event) => {
939
+ const cell = closestCell(event.target);
940
+ if (cell) {
941
+ const { row: rowIndex, plane } = cell;
942
+ if (onRowClick) {
943
+ if (plane === "grid") {
2544
944
  const row = model?.getRowAt(rowIndex);
2545
945
  row && onRowClick(row);
946
+ } else {
947
+ onRowClick(cell);
2546
948
  }
2547
- if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
2548
- model.selection.toggleSelectionForRowIndex(rowIndex);
2549
- }
2550
949
  }
2551
- if (!modals) {
950
+ if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
951
+ model.selection.toggleSelectionForRowIndex(rowIndex);
952
+ }
953
+ }
954
+ if (!modals) {
955
+ return;
956
+ }
957
+ const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
958
+ const tableButtonElement = event.target.closest(buttonSelector);
959
+ if (tableButtonElement) {
960
+ const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
961
+ if (!button) {
2552
962
  return;
2553
963
  }
2554
- const buttonSelector = Object.values(tableButtons).map((button) => `button[${button.attr}]`).join(",");
2555
- const tableButtonElement = event.target.closest(buttonSelector);
2556
- if (tableButtonElement) {
2557
- const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
2558
- if (!button) {
2559
- return;
964
+ modals.setTrigger(tableButtonElement);
965
+ const data = button.getData(tableButtonElement);
966
+ switch (data.type) {
967
+ case "rowMenu": {
968
+ modals.showRowMenu(data.rowIndex);
969
+ break;
2560
970
  }
2561
- modals.setTrigger(tableButtonElement);
2562
- const data = button.getData(tableButtonElement);
2563
- switch (data.type) {
2564
- case "rowMenu": {
2565
- modals.showRowMenu(data.rowIndex);
2566
- break;
2567
- }
2568
- case "columnSettings": {
2569
- modals.showColumnMenu(data.fieldId);
2570
- break;
2571
- }
2572
- case "newColumn": {
2573
- modals.showColumnCreator();
2574
- break;
2575
- }
2576
- case "sort": {
2577
- model?.sorting?.toggleSort(data.fieldId);
2578
- break;
2579
- }
2580
- case "saveDraftRow": {
2581
- if (model) {
2582
- const didCommitSuccessfully = model.commitDraftRow(data.rowIndex);
2583
- if (dxGrid && didCommitSuccessfully) {
2584
- requestAnimationFrame(() => {
2585
- dxGrid.scrollToEndRow();
2586
- });
2587
- }
2588
- }
2589
- break;
2590
- }
971
+ case "columnSettings": {
972
+ modals.showColumnMenu(data.fieldId);
973
+ break;
2591
974
  }
2592
- return;
2593
- }
2594
- const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
2595
- const controlElement = event.target.closest(controlSelector);
2596
- if (controlElement) {
2597
- const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
2598
- if (!control) {
2599
- return;
975
+ case "newColumn": {
976
+ modals.showColumnCreator();
977
+ break;
2600
978
  }
2601
- const data = control.getData(controlElement);
2602
- switch (data.type) {
2603
- case "checkbox": {
2604
- if (data.header) {
2605
- model?.selection.setSelection(model.selection.allRowsSeleted.value ? "none" : "all");
2606
- } else {
2607
- model?.selection.toggleSelectionForRowIndex(data.rowIndex);
2608
- }
2609
- break;
2610
- }
2611
- case "switch": {
2612
- if (model) {
2613
- model.updateCellData({
2614
- row: data.rowIndex,
2615
- col: data.colIndex
2616
- }, (value) => !value);
2617
- }
2618
- break;
2619
- }
979
+ case "sort": {
980
+ model?.toggleSort(data.fieldId);
981
+ break;
2620
982
  }
2621
- }
2622
- }, [
2623
- model,
2624
- modals,
2625
- dxGrid
2626
- ]);
2627
- const handleFocus = useCallback5((increment, delta) => {
2628
- if (dxGrid) {
2629
- dxGrid.refocus(increment, delta);
2630
- }
2631
- }, [
2632
- dxGrid
2633
- ]);
2634
- const handleEnter = useCallback5((cell) => {
2635
- if (!model?.features.dataEditable) {
2636
- return;
2637
- }
2638
- if (model && cell.row === model.getRowCount() - 1) {
2639
- model.insertRow();
2640
- if (dxGrid) {
2641
- requestAnimationFrame(() => {
2642
- dxGrid?.scrollToRow(cell.row + 1);
2643
- dxGrid?.refocus("row", 1);
2644
- });
983
+ case "saveDraftRow": {
984
+ handleSaveDraftRow();
985
+ break;
2645
986
  }
2646
987
  }
2647
- }, [
2648
- model,
2649
- dxGrid
2650
- ]);
2651
- const handleKeyDown = useCallback5((event) => {
2652
- if (!model?.features.dataEditable) {
2653
- return;
2654
- }
2655
- const cell = closestCell(event.target);
2656
- if (!model || !cell) {
988
+ return;
989
+ }
990
+ const controlSelector = Object.values(tableControls).map((control) => `input[${control.attr}]`).join(",");
991
+ const controlElement = event.target.closest(controlSelector);
992
+ if (controlElement) {
993
+ const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
994
+ if (!control) {
2657
995
  return;
2658
996
  }
2659
- switch (event.key) {
2660
- case "Backspace":
2661
- case "Delete": {
2662
- model.setCellData(cell, void 0);
997
+ const data = control.getData(controlElement);
998
+ switch (data.type) {
999
+ case "checkbox": {
1000
+ if (data.header) {
1001
+ model?.selection.setSelection(model.selection.allRowsSelected ? "none" : "all");
1002
+ } else {
1003
+ model?.selection.toggleSelectionForRowIndex(data.rowIndex);
1004
+ }
1005
+ break;
1006
+ }
1007
+ case "switch": {
1008
+ if (model) {
1009
+ model.updateCellData({
1010
+ row: data.rowIndex,
1011
+ col: data.colIndex
1012
+ }, (value) => !value);
1013
+ }
2663
1014
  break;
2664
1015
  }
2665
1016
  }
2666
- }, [
2667
- model
2668
- ]);
2669
- const handleAxisResize = useCallback5((event) => {
2670
- if (event.axis === "col") {
2671
- const columnIndex = parseInt(event.index, 10);
2672
- model?.setColumnWidth(columnIndex, event.size);
2673
- }
2674
- }, [
2675
- model
2676
- ]);
2677
- const handleWheel = useCallback5((event) => {
2678
- if (!ignoreAttention && !hasAttention) {
2679
- event.stopPropagation();
2680
- }
2681
- }, [
2682
- hasAttention,
2683
- ignoreAttention
2684
- ]);
2685
- const handleNewColumn = useCallback5(() => {
2686
- const columns = model?.getColumnCount();
2687
- if (dxGrid && columns) {
2688
- dxGrid.scrollToColumn(columns - 1);
1017
+ }
1018
+ }, [
1019
+ model,
1020
+ modals,
1021
+ dxGrid
1022
+ ]);
1023
+ const handleFocus = useCallback4((increment, delta, cell) => {
1024
+ if (dxGrid && model) {
1025
+ if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
1026
+ handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
1027
+ } else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
1028
+ handleSaveDraftRow(cell.row);
1029
+ handleInsertRowResult(model.insertRow());
1030
+ } else {
1031
+ dxGrid.refocus(increment, delta);
2689
1032
  }
2690
- }, [
2691
- model,
2692
- dxGrid
2693
- ]);
2694
- const handleQuery = useCallback5(async ({ field, props }, text) => {
2695
- if (model && props.referenceSchema && field.referencePath) {
2696
- const space = model.space;
2697
- invariant4(space, void 0, {
2698
- F: __dxlog_file5,
2699
- L: 325,
2700
- S: void 0,
2701
- A: [
2702
- "space",
2703
- ""
2704
- ]
2705
- });
2706
- let schema2;
2707
- if (client) {
2708
- schema2 = client.graph.schemaRegistry.getSchema(props.referenceSchema);
2709
- }
2710
- if (!schema2) {
2711
- schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
1033
+ }
1034
+ }, [
1035
+ dxGrid,
1036
+ model
1037
+ ]);
1038
+ const handleKeyDown = useCallback4((event) => {
1039
+ if (!model?.features.dataEditable) {
1040
+ return;
1041
+ }
1042
+ const cell = closestCell(event.target);
1043
+ if (!model || !cell) {
1044
+ return;
1045
+ }
1046
+ if (event.metaKey || event.ctrlKey) {
1047
+ switch (event.key) {
1048
+ case "c": {
1049
+ try {
1050
+ const cellData = model.getCellData(cell);
1051
+ const textContent = cellData?.toString() ?? "";
1052
+ void navigator.clipboard.writeText(textContent);
1053
+ event.preventDefault();
1054
+ } catch (error) {
1055
+ log.catch(error, void 0, {
1056
+ F: __dxlog_file3,
1057
+ L: 278,
1058
+ S: void 0,
1059
+ C: (f, a) => f(...a)
1060
+ });
1061
+ }
1062
+ break;
2712
1063
  }
2713
- if (schema2) {
2714
- const { objects } = await space.db.query(Filter.type(schema2)).run();
2715
- const options = objects.map((obj) => {
2716
- const value = getValue4(obj, field.referencePath);
2717
- if (!value || typeof value !== "string") {
2718
- return void 0;
2719
- }
2720
- return {
2721
- label: value,
2722
- data: obj
2723
- };
2724
- }).filter(isNotFalsy);
2725
- return [
2726
- ...options,
2727
- {
2728
- label: t("create new object label", {
2729
- text
2730
- }),
2731
- data: createOption(text)
1064
+ case "v": {
1065
+ event.preventDefault();
1066
+ void navigator.clipboard.readText().then((clipboardText) => {
1067
+ try {
1068
+ model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
1069
+ handleSave();
1070
+ } catch {
1071
+ const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
1072
+ if (cellElement) {
1073
+ const rect = cellElement.getBoundingClientRect();
1074
+ const editRequest = new DxEditRequest({
1075
+ cellIndex: `${cell.plane},${cell.col},${cell.row}`,
1076
+ cellBox: {
1077
+ insetInlineStart: rect.left,
1078
+ insetBlockStart: rect.top,
1079
+ inlineSize: rect.width,
1080
+ blockSize: rect.height
1081
+ },
1082
+ cellElement,
1083
+ initialContent: clipboardText
1084
+ });
1085
+ cellElement.dispatchEvent(editRequest);
1086
+ }
2732
1087
  }
2733
- ];
1088
+ });
1089
+ break;
2734
1090
  }
2735
1091
  }
2736
- return [];
2737
- }, [
2738
- model,
2739
- client,
2740
- t
2741
- ]);
2742
- if (!model || !modals) {
2743
- return /* @__PURE__ */ React8.createElement("span", {
2744
- role: "none",
2745
- className: "attention-surface"
2746
- });
2747
1092
  }
2748
- return /* @__PURE__ */ React8.createElement(Grid.Root, {
2749
- id: model.id ?? "table-grid"
2750
- }, /* @__PURE__ */ React8.createElement(TableValueEditor, {
2751
- model,
2752
- modals,
2753
- schema,
2754
- onEnter: handleEnter,
2755
- onFocus: handleFocus,
2756
- onQuery: handleQuery
2757
- }), /* @__PURE__ */ React8.createElement(Grid.Content, {
2758
- className: mx2("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
2759
- frozen,
2760
- columns: model.columnMeta.value,
2761
- limitRows: model.getRowCount() ?? 0,
2762
- limitColumns: model.view?.fields?.length ?? 0,
2763
- overscroll: "trap",
2764
- onAxisResize: handleAxisResize,
2765
- onClick: handleGridClick,
2766
- onKeyDown: handleKeyDown,
2767
- onWheelCapture: handleWheel,
2768
- ref: setDxGrid
2769
- }), /* @__PURE__ */ React8.createElement(RowActionsMenu, {
2770
- model,
2771
- modals
2772
- }), /* @__PURE__ */ React8.createElement(ColumnActionsMenu, {
2773
- model,
2774
- modals
2775
- }), /* @__PURE__ */ React8.createElement(ColumnSettings, {
2776
- model,
2777
- modals,
2778
- onNewColumn: handleNewColumn
2779
- }), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
2780
- model,
2781
- modals
2782
- }));
2783
- } finally {
2784
- _effect.f();
2785
- }
2786
- });
2787
- var Table = {
2788
- Root: TableRoot,
2789
- Main: TableMain
2790
- };
2791
-
2792
- // src/components/Table/DynamicTable.tsx
2793
- import { useSignals as _useSignals10 } from "@preact-signals/safe-react/tracking";
2794
- import React9, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback7 } from "react";
2795
- import { useDefaultValue } from "@dxos/react-ui";
2796
- import { mx as mx3 } from "@dxos/react-ui-theme";
2797
-
2798
- // src/hooks/useTableModel.ts
2799
- import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
2800
- import { effect as effect3 } from "@preact/signals-core";
2801
- import orderBy2 from "lodash.orderby";
2802
- import { useEffect as useEffect5, useState as useState4 } from "react";
2803
- import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
2804
- import { useSelectionActions } from "@dxos/react-ui-attention";
2805
- import { isNonNullable } from "@dxos/util";
2806
- var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
2807
- var _effect = _useSignals9();
2808
- try {
2809
- const [model, setModel] = useState4();
2810
- useEffect5(() => {
2811
- if (!table || !projection) {
2812
- return;
2813
- }
2814
- let model2;
2815
- const t = setTimeout(async () => {
2816
- model2 = new TableModel({
2817
- id: fullyQualifiedId(table),
2818
- space: getSpace(table),
2819
- view: table.view?.target,
2820
- projection,
2821
- features,
2822
- rowActions,
2823
- onRowAction,
2824
- ...props
2825
- });
2826
- await model2.open();
2827
- setModel(model2);
2828
- });
2829
- return () => {
2830
- clearTimeout(t);
2831
- void model2?.close();
2832
- };
2833
- }, [
2834
- table,
2835
- projection,
2836
- table?.view?.target,
2837
- features,
2838
- rowActions
2839
- ]);
2840
- useEffect5(() => {
2841
- if (rows) {
2842
- const sortedRows = orderBy2(rows, [
2843
- (row) => String(row.id)
2844
- ], [
2845
- "asc"
2846
- ]);
2847
- model?.setRows(sortedRows);
2848
- }
2849
- }, [
2850
- model,
2851
- rows
2852
- ]);
2853
- const { multiSelect, clear } = useSelectionActions([
2854
- table?.id,
2855
- table?.view?.target?.query.typename
2856
- ].filter(isNonNullable));
2857
- useEffect5(() => {
2858
- if (!model) {
2859
- return;
2860
- }
2861
- const unsubscribe = effect3(() => {
2862
- const selectedItems = [
2863
- ...model.selection.selection.value
2864
- ];
2865
- multiSelect(selectedItems);
2866
- onSelectionChanged?.(selectedItems);
2867
- });
2868
- return () => {
2869
- clear();
2870
- unsubscribe();
2871
- };
2872
- }, [
2873
- model,
2874
- onSelectionChanged
2875
- ]);
2876
- return model;
2877
- } finally {
2878
- _effect.f();
2879
- }
2880
- };
2881
-
2882
- // src/hooks/useAddRow.ts
2883
- import { useCallback as useCallback6 } from "react";
2884
- import { Obj as Obj3 } from "@dxos/echo";
2885
- var useAddRow = ({ space, schema }) => {
2886
- return useCallback6((data) => {
2887
- if (space && schema) {
2888
- try {
2889
- space.db.add(Obj3.make(schema, data ?? {}));
2890
- return true;
2891
- } catch (error) {
2892
- return false;
1093
+ switch (event.key) {
1094
+ case "Backspace":
1095
+ case "Delete": {
1096
+ try {
1097
+ model.setCellData(cell, void 0);
1098
+ event.preventDefault();
1099
+ handleSave();
1100
+ } catch {
1101
+ }
1102
+ break;
2893
1103
  }
2894
1104
  }
2895
- return false;
2896
1105
  }, [
2897
- space,
2898
- schema
1106
+ model,
1107
+ dxGrid,
1108
+ handleSave
2899
1109
  ]);
2900
- };
2901
-
2902
- // src/components/Table/DynamicTable.tsx
2903
- var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
2904
- var _effect = _useSignals10();
2905
- try {
2906
- const { table, projection } = useMemo6(() => {
2907
- const props2 = getBaseSchema({
2908
- typename: name,
2909
- properties,
2910
- jsonSchema,
2911
- schema
2912
- });
2913
- return makeDynamicTable({
2914
- ...props2,
2915
- properties
2916
- });
2917
- }, [
2918
- name,
2919
- properties,
2920
- schema,
2921
- jsonSchema
2922
- ]);
2923
- const tableRef = useRef3(null);
2924
- const handleCellUpdate = useCallback7((cell) => {
2925
- tableRef.current?.update?.(cell);
2926
- }, []);
2927
- const handleRowOrderChange = useCallback7(() => {
2928
- tableRef.current?.update?.();
2929
- }, []);
2930
- const features = useDefaultValue(props.features, () => ({
2931
- selection: {
2932
- enabled: false
1110
+ const handleAxisResize = useCallback4((event) => {
1111
+ if (event.axis === "col") {
1112
+ const columnIndex = parseInt(event.index, 10);
1113
+ model?.setColumnWidth(columnIndex, event.size);
1114
+ }
1115
+ }, [
1116
+ model
1117
+ ]);
1118
+ const handleWheel = useCallback4((event) => {
1119
+ if (!ignoreAttention && !hasAttention) {
1120
+ event.stopPropagation();
1121
+ }
1122
+ }, [
1123
+ hasAttention,
1124
+ ignoreAttention
1125
+ ]);
1126
+ const handleNewColumn = useCallback4(() => {
1127
+ const columns = model?.getColumnCount();
1128
+ if (dxGrid && columns) {
1129
+ dxGrid.scrollToColumn(columns - 1);
1130
+ }
1131
+ }, [
1132
+ model,
1133
+ dxGrid
1134
+ ]);
1135
+ const { controllerRef } = useTableContext(TABLE_CONTENT_NAME);
1136
+ controllerRef.current = useMemo4(() => {
1137
+ if (!dxGrid || !presentation) {
1138
+ return {};
1139
+ }
1140
+ return {
1141
+ update: (cell) => {
1142
+ if (cell) {
1143
+ dxGrid.updateIfWithinBounds(cell, true);
1144
+ } else {
1145
+ dxGrid.updateCells(true);
1146
+ dxGrid.requestUpdate();
1147
+ }
2933
1148
  },
2934
- dataEditable: false
2935
- }));
2936
- const model = useTableModel({
2937
- table,
2938
- rows,
2939
- projection,
2940
- features,
2941
- rowActions,
2942
- onCellUpdate: handleCellUpdate,
2943
- onRowOrderChange: handleRowOrderChange,
2944
- onRowAction
2945
- });
2946
- const presentation = useMemo6(() => {
2947
- if (model) {
2948
- return new TablePresentation(model);
2949
- }
2950
- }, [
2951
- model
2952
- ]);
2953
- return /* @__PURE__ */ React9.createElement("div", {
2954
- role: "none",
2955
- className: mx3("is-full bs-full grow grid", classNames)
2956
- }, /* @__PURE__ */ React9.createElement("div", {
1149
+ handleInsertRowResult
1150
+ };
1151
+ }, [
1152
+ dxGrid,
1153
+ model,
1154
+ presentation
1155
+ ]);
1156
+ if (!model || !modals) {
1157
+ return /* @__PURE__ */ React7.createElement("span", {
2957
1158
  role: "none",
2958
- className: "grid min-bs-0 overflow-hidden"
2959
- }, /* @__PURE__ */ React9.createElement(Table.Root, null, /* @__PURE__ */ React9.createElement(Table.Main, {
2960
- ref: tableRef,
2961
- model,
2962
- presentation,
2963
- ignoreAttention: true,
2964
- onRowClick
2965
- }))));
2966
- } finally {
2967
- _effect.f();
1159
+ className: "dx-attention-surface"
1160
+ });
2968
1161
  }
2969
- };
1162
+ return /* @__PURE__ */ React7.createElement("div", {
1163
+ ...composableProps(props, {
1164
+ classNames: "dx-container relative"
1165
+ }),
1166
+ ref: forwardedRef
1167
+ }, /* @__PURE__ */ React7.createElement(Grid.Root, {
1168
+ id: model.id ?? "table-grid"
1169
+ }, /* @__PURE__ */ React7.createElement(TableValueEditor, {
1170
+ model,
1171
+ modals,
1172
+ schema,
1173
+ onFocus: handleFocus,
1174
+ onSave: handleSave,
1175
+ onCreate
1176
+ }), /* @__PURE__ */ React7.createElement(Grid.Content, {
1177
+ className: mx("[--dx-grid-base:var(--base-surface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
1178
+ frozen,
1179
+ columns: columnMeta,
1180
+ columnDefault,
1181
+ rowDefault,
1182
+ limitRows: rows.length,
1183
+ limitColumns: columnCount,
1184
+ overscroll: "trap",
1185
+ onAxisResize: handleAxisResize,
1186
+ onClick: handleGridClick,
1187
+ onKeyDownCapture: handleKeyDown,
1188
+ onWheelCapture: handleWheel,
1189
+ ...testId && {
1190
+ "data-testid": testId
1191
+ },
1192
+ ref: setDxGrid
1193
+ }), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
1194
+ model,
1195
+ modals
1196
+ }), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
1197
+ model,
1198
+ modals
1199
+ }), /* @__PURE__ */ React7.createElement(ColumnSettings, {
1200
+ model,
1201
+ modals,
1202
+ onNewColumn: handleNewColumn
1203
+ })));
1204
+ });
1205
+ TableContent.displayName = TABLE_CONTENT_NAME;
2970
1206
 
2971
- // src/components/TableToolbar/TableToolbar.tsx
2972
- import { useSignals as _useSignals11 } from "@preact-signals/safe-react/tracking";
2973
- import { Rx } from "@effect-rx/rx-react";
2974
- import React10, { useMemo as useMemo7 } from "react";
2975
- import { live as live3 } from "@dxos/live-object";
2976
- import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
2977
- import { rxFromSignal } from "@dxos/react-ui-menu";
2978
- var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.make((get) => {
2979
- const add = createMenuAction("add-row", onAdd, {
2980
- type: "add-row",
2981
- icon: "ph--plus--regular",
2982
- label: [
2983
- "add row",
2984
- {
2985
- ns: translationKey
2986
- }
2987
- ],
2988
- testId: "table.toolbar.add-row"
2989
- });
2990
- const save = createMenuAction("save-view", onSave, {
2991
- type: "save-view",
2992
- icon: "ph--floppy-disk--regular",
2993
- label: [
2994
- "save view label",
2995
- {
2996
- ns: translationKey
2997
- }
2998
- ],
2999
- testId: "table.toolbar.save-view",
3000
- iconOnly: false,
3001
- hidden: get(rxFromSignal(() => !state.viewDirty))
3002
- });
1207
+ // src/components/Table/TableToolbar.tsx
1208
+ import { Atom as Atom3, RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
1209
+ import React8, { useContext as useContext2, useEffect as useEffect4, useMemo as useMemo5 } from "react";
1210
+ import { Menu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
1211
+ import { composable as composable2, composableProps as composableProps2 } from "@dxos/ui-theme";
1212
+ var createTableToolbarActions = ({ stateAtom, onAdd, onSave, customActions }) => Atom3.make((get) => {
1213
+ const nodes = [];
1214
+ if (onAdd) {
1215
+ const add = createMenuAction("add-row", onAdd, {
1216
+ type: "add-row",
1217
+ icon: "ph--plus--regular",
1218
+ label: [
1219
+ "add-row.label",
1220
+ {
1221
+ ns: translationKey
1222
+ }
1223
+ ],
1224
+ testId: "table.toolbar.add-row"
1225
+ });
1226
+ nodes.push(add);
1227
+ }
1228
+ if (onSave) {
1229
+ const state = get(stateAtom);
1230
+ const save = createMenuAction("save-view", onSave, {
1231
+ type: "save-view",
1232
+ icon: "ph--floppy-disk--regular",
1233
+ label: [
1234
+ "save-view.label",
1235
+ {
1236
+ ns: translationKey
1237
+ }
1238
+ ],
1239
+ testId: "table.toolbar.save-view",
1240
+ iconOnly: false,
1241
+ hidden: !state.viewDirty
1242
+ });
1243
+ nodes.push(save);
1244
+ }
3003
1245
  const gap = createGapSeparator();
3004
- const nodes = [
3005
- add,
3006
- save,
3007
- ...gap.nodes
3008
- ];
1246
+ nodes.push(...gap.nodes);
3009
1247
  const edges = nodes.map(({ id: target }) => ({
3010
1248
  source: "root",
3011
- target
1249
+ target,
1250
+ relation: "child"
3012
1251
  }));
3013
1252
  if (customActions) {
3014
1253
  const custom = get(customActions);
@@ -3020,33 +1259,140 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
3020
1259
  edges
3021
1260
  };
3022
1261
  });
3023
- var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
3024
- var _effect = _useSignals11();
3025
- try {
3026
- const state = useMemo7(() => live3({
1262
+ var TableToolbar = composable2(({ attendableId, viewDirty, onAdd, onSave, customActions, ...props }, forwardedRef) => {
1263
+ const registry = useContext2(RegistryContext2);
1264
+ const stateAtom = useMemo5(() => Atom3.make({
1265
+ viewDirty
1266
+ }), []);
1267
+ useEffect4(() => {
1268
+ registry.set(stateAtom, {
3027
1269
  viewDirty
3028
- }), []);
3029
- const actionsCreator = useMemo7(() => createTableToolbarActions({
3030
- state,
3031
- onAdd,
3032
- onSave,
3033
- customActions
3034
- }), [
3035
- state,
3036
- onAdd,
3037
- onSave,
3038
- customActions
3039
- ]);
3040
- const menu = useMenuActions(actionsCreator);
3041
- return /* @__PURE__ */ React10.createElement(MenuProvider, {
3042
- ...menu,
3043
- attendableId
3044
- }, /* @__PURE__ */ React10.createElement(ToolbarMenu, {
3045
- classNames
1270
+ });
1271
+ }, [
1272
+ registry,
1273
+ stateAtom,
1274
+ viewDirty
1275
+ ]);
1276
+ const actionsCreator = useMemo5(() => createTableToolbarActions({
1277
+ stateAtom,
1278
+ onAdd,
1279
+ onSave,
1280
+ customActions
1281
+ }), [
1282
+ stateAtom,
1283
+ onAdd,
1284
+ onSave,
1285
+ customActions
1286
+ ]);
1287
+ const menuActions = useMenuActions(actionsCreator);
1288
+ return /* @__PURE__ */ React8.createElement(Menu.Root, {
1289
+ ...menuActions,
1290
+ attendableId
1291
+ }, /* @__PURE__ */ React8.createElement(Menu.Toolbar, {
1292
+ ...composableProps2(props),
1293
+ ref: forwardedRef
1294
+ }));
1295
+ });
1296
+ TableToolbar.displayName = "TableToolbar";
1297
+
1298
+ // src/components/Table/Table.tsx
1299
+ var emptyColumnMeta2 = Atom4.make({
1300
+ grid: {}
1301
+ });
1302
+ var [TableContextProvider, useTableContext] = createContext("Table");
1303
+ var TABLE_ROOT_NAME = "Table.Root";
1304
+ var TableRoot = /* @__PURE__ */ forwardRef(({ children }, forwardedRef) => {
1305
+ const controllerRef = useRef3({});
1306
+ useImperativeHandle(forwardedRef, () => ({
1307
+ update: (cell) => controllerRef.current?.update?.(cell),
1308
+ handleInsertRowResult: (result) => controllerRef.current?.handleInsertRowResult?.(result)
1309
+ }), []);
1310
+ return /* @__PURE__ */ React9.createElement(TableContextProvider, {
1311
+ controllerRef
1312
+ }, children);
1313
+ });
1314
+ TableRoot.displayName = TABLE_ROOT_NAME;
1315
+ var Table = {
1316
+ Root: TableRoot,
1317
+ Toolbar: TableToolbar,
1318
+ Content: TableContent
1319
+ };
1320
+
1321
+ // src/components/Table/DynamicTable.tsx
1322
+ import { RegistryContext as RegistryContext3 } from "@effect-atom/atom-react";
1323
+ import React10, { useCallback as useCallback5, useContext as useContext3, useEffect as useEffect5, useMemo as useMemo6, useRef as useRef4, useState as useState5 } from "react";
1324
+ import { useDefaultValue } from "@dxos/react-ui";
1325
+ import { mx as mx2 } from "@dxos/ui-theme";
1326
+ var DynamicTable = ({ classNames, schema, name = "com.example.dynamic-table", rows, properties, jsonSchema: jsonSchemaProp, rowActions, onRowClick, onRowAction, ...props }) => {
1327
+ const registry = useContext3(RegistryContext3);
1328
+ const [dynamicTable, setDynamicTable] = useState5();
1329
+ const { jsonSchema } = useMemo6(() => getBaseSchema({
1330
+ typename: name,
1331
+ properties,
1332
+ jsonSchema: jsonSchemaProp,
1333
+ schema
1334
+ }), [
1335
+ name,
1336
+ properties,
1337
+ jsonSchemaProp,
1338
+ schema
1339
+ ]);
1340
+ useEffect5(() => {
1341
+ setDynamicTable(makeDynamicTable({
1342
+ registry,
1343
+ jsonSchema,
1344
+ properties
3046
1345
  }));
3047
- } finally {
3048
- _effect.f();
3049
- }
1346
+ }, [
1347
+ registry,
1348
+ jsonSchema,
1349
+ properties
1350
+ ]);
1351
+ const tableRef = useRef4(null);
1352
+ const handleCellUpdate = useCallback5((cell) => {
1353
+ tableRef.current?.update?.(cell);
1354
+ }, []);
1355
+ const handleRowOrderChange = useCallback5(() => {
1356
+ tableRef.current?.update?.();
1357
+ }, []);
1358
+ const features = useDefaultValue(props.features, () => ({
1359
+ selection: {
1360
+ enabled: false
1361
+ },
1362
+ dataEditable: false
1363
+ }));
1364
+ const model = useTableModel({
1365
+ rows,
1366
+ object: dynamicTable?.object,
1367
+ projection: dynamicTable?.projection,
1368
+ features,
1369
+ rowActions,
1370
+ onCellUpdate: handleCellUpdate,
1371
+ onRowOrderChange: handleRowOrderChange,
1372
+ onRowAction
1373
+ });
1374
+ const presentation = useMemo6(() => {
1375
+ if (model) {
1376
+ return new TablePresentation(registry, model);
1377
+ }
1378
+ }, [
1379
+ registry,
1380
+ model
1381
+ ]);
1382
+ return /* @__PURE__ */ React10.createElement("div", {
1383
+ role: "none",
1384
+ className: mx2("dx-expander grid", classNames)
1385
+ }, /* @__PURE__ */ React10.createElement("div", {
1386
+ role: "none",
1387
+ className: "grid min-h-0 overflow-hidden"
1388
+ }, /* @__PURE__ */ React10.createElement(Table.Root, {
1389
+ ref: tableRef
1390
+ }, /* @__PURE__ */ React10.createElement(Table.Content, {
1391
+ model,
1392
+ presentation,
1393
+ ignoreAttention: true,
1394
+ onRowClick
1395
+ }))));
3050
1396
  };
3051
1397
  export {
3052
1398
  BUTTON_IDENTIFIERS,
@@ -3058,12 +1404,13 @@ export {
3058
1404
  Table,
3059
1405
  TableModel,
3060
1406
  TablePresentation,
3061
- TableSchema,
3062
- TableToolbar,
3063
- TableType,
3064
1407
  cellClassesForRowSelection,
1408
+ compareValues,
1409
+ createDirectChangeCallback,
1410
+ createEchoChangeCallback,
1411
+ extractOrder,
3065
1412
  getBaseSchema,
3066
- initializeTable,
1413
+ getSortValue,
3067
1414
  makeDynamicTable,
3068
1415
  narrowSchema,
3069
1416
  tableButtons,
@@ -3071,6 +1418,8 @@ export {
3071
1418
  touch,
3072
1419
  translations,
3073
1420
  useAddRow,
1421
+ useProjectionModel,
1422
+ useTableContext,
3074
1423
  useTableModel
3075
1424
  };
3076
1425
  //# sourceMappingURL=index.mjs.map