@dxos/react-ui-table 0.8.1-staging.391c573 → 0.8.1-staging.9eaf14f

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 (191) hide show
  1. package/dist/lib/browser/{chunk-3FR6NHPD.mjs → chunk-YWNRUF4J.mjs} +8 -6
  2. package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +625 -225
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/types/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-NB3SFHGA.cjs → chunk-TGG6OZ54.cjs} +10 -8
  8. package/dist/lib/node/chunk-TGG6OZ54.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +618 -220
  10. package/dist/lib/node/index.cjs.map +4 -4
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/types/index.cjs +3 -3
  13. package/dist/lib/node/types/index.cjs.map +1 -1
  14. package/dist/lib/node-esm/{chunk-RLVVOZW5.mjs → chunk-KKLP54L3.mjs} +8 -6
  15. package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +625 -225
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/types/index.mjs +1 -1
  20. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  21. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  22. package/dist/types/src/components/Table/DynamicTable.d.ts +24 -0
  23. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -0
  24. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +10 -0
  25. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -0
  26. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/Table.d.ts +1 -0
  28. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Table.stories.d.ts +4 -3
  30. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/index.d.ts +1 -0
  32. package/dist/types/src/components/Table/index.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/relations.stories.d.ts +9 -0
  34. package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -0
  35. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/testing.d.ts +7 -7
  38. package/dist/types/src/components/testing.d.ts.map +1 -1
  39. package/dist/types/src/hooks/useTableModel.d.ts +8 -9
  40. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  41. package/dist/types/src/model/index.d.ts +1 -0
  42. package/dist/types/src/model/index.d.ts.map +1 -1
  43. package/dist/types/src/model/selection-model.d.ts +6 -3
  44. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  45. package/dist/types/src/model/table-model.d.ts +42 -16
  46. package/dist/types/src/model/table-model.d.ts.map +1 -1
  47. package/dist/types/src/model/table-presentation.d.ts +4 -4
  48. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  49. package/dist/types/src/model/table-sorting.d.ts +2 -2
  50. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  51. package/dist/types/src/types/table.d.ts +7 -32
  52. package/dist/types/src/types/table.d.ts.map +1 -1
  53. package/dist/types/src/util/dynamic-table.d.ts +31 -0
  54. package/dist/types/src/util/dynamic-table.d.ts.map +1 -0
  55. package/dist/types/src/util/index.d.ts +1 -0
  56. package/dist/types/src/util/index.d.ts.map +1 -1
  57. package/dist/types/src/util/table-controls.d.ts +2 -2
  58. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  59. package/dist/types/src/util/table.d.ts +5 -3
  60. package/dist/types/src/util/table.d.ts.map +1 -1
  61. package/package.json +37 -36
  62. package/src/components/Table/ColumnActionsMenu.tsx +6 -4
  63. package/src/components/Table/ColumnSettings.tsx +5 -6
  64. package/src/components/Table/CreateRefPanel.tsx +3 -3
  65. package/src/components/Table/DynamicTable.stories.tsx +155 -0
  66. package/src/components/Table/DynamicTable.tsx +104 -0
  67. package/src/components/Table/RefPanel.tsx +3 -3
  68. package/src/components/Table/RowActionsMenu.tsx +18 -3
  69. package/src/components/Table/Table.stories.tsx +170 -115
  70. package/src/components/Table/Table.tsx +71 -26
  71. package/src/components/Table/index.ts +1 -0
  72. package/src/components/Table/relations.stories.tsx +113 -0
  73. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +15 -5
  74. package/src/components/TableCellEditor/TableCellEditor.tsx +102 -4
  75. package/src/components/testing.ts +0 -1
  76. package/src/hooks/useTableModel.ts +35 -14
  77. package/src/model/index.ts +1 -0
  78. package/src/model/selection-model.ts +12 -2
  79. package/src/model/table-model.test.ts +2 -2
  80. package/src/model/table-model.ts +117 -32
  81. package/src/model/table-presentation.test.ts +2 -2
  82. package/src/model/table-presentation.ts +94 -22
  83. package/src/model/table-sorting.ts +3 -2
  84. package/src/playwright/smoke.spec.ts +2 -3
  85. package/src/types/table.ts +9 -10
  86. package/src/util/dynamic-table.ts +103 -0
  87. package/src/util/index.ts +1 -0
  88. package/src/util/table-controls.ts +4 -4
  89. package/src/util/table.ts +68 -65
  90. package/dist/lib/browser/_deprecated/index.mjs +0 -1483
  91. package/dist/lib/browser/_deprecated/index.mjs.map +0 -7
  92. package/dist/lib/browser/chunk-3FR6NHPD.mjs.map +0 -7
  93. package/dist/lib/node/_deprecated/index.cjs +0 -1511
  94. package/dist/lib/node/_deprecated/index.cjs.map +0 -7
  95. package/dist/lib/node/chunk-NB3SFHGA.cjs.map +0 -7
  96. package/dist/lib/node-esm/_deprecated/index.mjs +0 -1485
  97. package/dist/lib/node-esm/_deprecated/index.mjs.map +0 -7
  98. package/dist/lib/node-esm/chunk-RLVVOZW5.mjs.map +0 -7
  99. package/dist/types/src/_deprecated/components/Cell/Cell.d.ts +0 -12
  100. package/dist/types/src/_deprecated/components/Cell/Cell.d.ts.map +0 -1
  101. package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts +0 -13
  102. package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts.map +0 -1
  103. package/dist/types/src/_deprecated/components/Cell/index.d.ts +0 -2
  104. package/dist/types/src/_deprecated/components/Cell/index.d.ts.map +0 -1
  105. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts +0 -23
  106. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
  107. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts +0 -36
  108. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
  109. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts +0 -15
  110. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
  111. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts +0 -84
  112. package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
  113. package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts +0 -3
  114. package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts.map +0 -1
  115. package/dist/types/src/_deprecated/components/Table/Table.d.ts +0 -20
  116. package/dist/types/src/_deprecated/components/Table/Table.d.ts.map +0 -1
  117. package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts +0 -116
  118. package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts.map +0 -1
  119. package/dist/types/src/_deprecated/components/Table/TableBody.d.ts +0 -12
  120. package/dist/types/src/_deprecated/components/Table/TableBody.d.ts.map +0 -1
  121. package/dist/types/src/_deprecated/components/Table/TableContext.d.ts +0 -13
  122. package/dist/types/src/_deprecated/components/Table/TableContext.d.ts.map +0 -1
  123. package/dist/types/src/_deprecated/components/Table/TableHead.d.ts +0 -9
  124. package/dist/types/src/_deprecated/components/Table/TableHead.d.ts.map +0 -1
  125. package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts +0 -17
  126. package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts.map +0 -1
  127. package/dist/types/src/_deprecated/components/Table/index.d.ts +0 -5
  128. package/dist/types/src/_deprecated/components/Table/index.d.ts.map +0 -1
  129. package/dist/types/src/_deprecated/components/Table/props.d.ts +0 -42
  130. package/dist/types/src/_deprecated/components/Table/props.d.ts.map +0 -1
  131. package/dist/types/src/_deprecated/components/index.d.ts +0 -4
  132. package/dist/types/src/_deprecated/components/index.d.ts.map +0 -1
  133. package/dist/types/src/_deprecated/helpers.d.ts +0 -91
  134. package/dist/types/src/_deprecated/helpers.d.ts.map +0 -1
  135. package/dist/types/src/_deprecated/hooks/index.d.ts +0 -5
  136. package/dist/types/src/_deprecated/hooks/index.d.ts.map +0 -1
  137. package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts +0 -12
  138. package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts.map +0 -1
  139. package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts +0 -15
  140. package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts.map +0 -1
  141. package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts +0 -3
  142. package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts.map +0 -1
  143. package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts +0 -7
  144. package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts.map +0 -1
  145. package/dist/types/src/_deprecated/index.d.ts +0 -8
  146. package/dist/types/src/_deprecated/index.d.ts.map +0 -1
  147. package/dist/types/src/_deprecated/schema/Schema.stories.d.ts +0 -11
  148. package/dist/types/src/_deprecated/schema/Schema.stories.d.ts.map +0 -1
  149. package/dist/types/src/_deprecated/schema/column-utils.d.ts +0 -7
  150. package/dist/types/src/_deprecated/schema/column-utils.d.ts.map +0 -1
  151. package/dist/types/src/_deprecated/schema/index.d.ts +0 -3
  152. package/dist/types/src/_deprecated/schema/index.d.ts.map +0 -1
  153. package/dist/types/src/_deprecated/schema/types.d.ts +0 -27
  154. package/dist/types/src/_deprecated/schema/types.d.ts.map +0 -1
  155. package/dist/types/src/_deprecated/theme.d.ts +0 -29
  156. package/dist/types/src/_deprecated/theme.d.ts.map +0 -1
  157. package/dist/types/src/_deprecated/translations.d.ts +0 -21
  158. package/dist/types/src/_deprecated/translations.d.ts.map +0 -1
  159. package/dist/types/src/_deprecated/types.d.ts +0 -26
  160. package/dist/types/src/_deprecated/types.d.ts.map +0 -1
  161. package/src/_deprecated/components/Cell/Cell.tsx +0 -88
  162. package/src/_deprecated/components/Cell/CellCombobox.tsx +0 -103
  163. package/src/_deprecated/components/Cell/index.ts +0 -5
  164. package/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.tsx +0 -129
  165. package/src/_deprecated/components/ColumnMenu/ColumnMenu.tsx +0 -182
  166. package/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.tsx +0 -108
  167. package/src/_deprecated/components/ColumnMenu/ColumnSettings.tsx +0 -207
  168. package/src/_deprecated/components/ColumnMenu/index.ts +0 -6
  169. package/src/_deprecated/components/Table/Table.stories.tsx +0 -508
  170. package/src/_deprecated/components/Table/Table.tsx +0 -301
  171. package/src/_deprecated/components/Table/TableBody.tsx +0 -82
  172. package/src/_deprecated/components/Table/TableContext.tsx +0 -34
  173. package/src/_deprecated/components/Table/TableHead.tsx +0 -78
  174. package/src/_deprecated/components/Table/TableRootContext.ts +0 -39
  175. package/src/_deprecated/components/Table/index.ts +0 -8
  176. package/src/_deprecated/components/Table/props.ts +0 -60
  177. package/src/_deprecated/components/index.ts +0 -7
  178. package/src/_deprecated/helpers.tsx +0 -526
  179. package/src/_deprecated/hooks/index.ts +0 -8
  180. package/src/_deprecated/hooks/useColumnSizing.ts +0 -46
  181. package/src/_deprecated/hooks/useColumnSorting.ts +0 -64
  182. package/src/_deprecated/hooks/usePinLastRow.ts +0 -47
  183. package/src/_deprecated/hooks/useRowSelection.ts +0 -40
  184. package/src/_deprecated/index.ts +0 -12
  185. package/src/_deprecated/schema/Schema.stories.tsx +0 -59
  186. package/src/_deprecated/schema/column-utils.ts +0 -54
  187. package/src/_deprecated/schema/index.ts +0 -6
  188. package/src/_deprecated/schema/types.ts +0 -40
  189. package/src/_deprecated/theme.ts +0 -82
  190. package/src/_deprecated/translations.ts +0 -26
  191. package/src/_deprecated/types.ts +0 -38
@@ -30,16 +30,20 @@ var node_exports = {};
30
30
  __export(node_exports, {
31
31
  BUTTON_IDENTIFIERS: () => BUTTON_IDENTIFIERS,
32
32
  CONTROL_IDENTIFIERS: () => CONTROL_IDENTIFIERS,
33
+ CheckboxStory: () => CheckboxStory,
34
+ DynamicTable: () => DynamicTable,
33
35
  ModalController: () => ModalController,
36
+ SwitchStory: () => SwitchStory,
34
37
  Table: () => Table,
35
38
  TableModel: () => TableModel,
36
39
  TablePresentation: () => TablePresentation,
37
- TableSchema: () => import_chunk_NB3SFHGA.TableSchema,
40
+ TableSchema: () => import_chunk_TGG6OZ54.TableSchema,
38
41
  TableToolbar: () => TableToolbar,
39
- TableType: () => import_chunk_NB3SFHGA.TableType,
42
+ TableType: () => import_chunk_TGG6OZ54.TableType,
43
+ cellClassesForRowSelection: () => cellClassesForRowSelection,
44
+ getBaseSchems: () => getBaseSchems,
40
45
  initializeTable: () => initializeTable,
41
- renderCheckbox: () => renderCheckbox,
42
- renderSwitch: () => renderSwitch,
46
+ makeDynamicTable: () => makeDynamicTable,
43
47
  tableButtons: () => tableButtons,
44
48
  tableControls: () => tableControls,
45
49
  touch: () => touch,
@@ -47,7 +51,7 @@ __export(node_exports, {
47
51
  useTableModel: () => useTableModel
48
52
  });
49
53
  module.exports = __toCommonJS(node_exports);
50
- var import_chunk_NB3SFHGA = require("./chunk-NB3SFHGA.cjs");
54
+ var import_chunk_TGG6OZ54 = require("./chunk-TGG6OZ54.cjs");
51
55
  var import_react = __toESM(require("react"));
52
56
  var import_echo_schema = require("@dxos/echo-schema");
53
57
  var import_invariant = require("@dxos/invariant");
@@ -60,17 +64,15 @@ var import_util = require("@dxos/util");
60
64
  var import_react2 = __toESM(require("react"));
61
65
  var import_react_ui2 = require("@dxos/react-ui");
62
66
  var import_react3 = __toESM(require("react"));
63
- var import_echo2 = require("@dxos/react-client/echo");
64
67
  var import_react_ui3 = require("@dxos/react-ui");
65
68
  var import_react_ui_form = require("@dxos/react-ui-form");
66
69
  var import_react4 = __toESM(require("react"));
67
70
  var import_echo_schema2 = require("@dxos/echo-schema");
68
- var import_echo3 = require("@dxos/react-client/echo");
71
+ var import_echo2 = require("@dxos/react-client/echo");
69
72
  var import_react_ui4 = require("@dxos/react-ui");
70
73
  var import_react_ui_form2 = require("@dxos/react-ui-form");
71
74
  var import_react_ui_grid2 = require("@dxos/react-ui-grid");
72
75
  var import_react5 = __toESM(require("react"));
73
- var import_echo4 = require("@dxos/react-client/echo");
74
76
  var import_react_ui5 = require("@dxos/react-ui");
75
77
  var import_react_ui_form3 = require("@dxos/react-ui-form");
76
78
  var import_react6 = __toESM(require("react"));
@@ -80,14 +82,15 @@ var import_context = require("@dxos/context");
80
82
  var import_echo_schema3 = require("@dxos/echo-schema");
81
83
  var import_invariant2 = require("@dxos/invariant");
82
84
  var import_live_object = require("@dxos/live-object");
83
- var import_react_client = require("@dxos/react-client");
84
85
  var import_react_ui_form4 = require("@dxos/react-ui-form");
85
86
  var import_signals_core2 = require("@preact/signals-core");
86
87
  var import_context2 = require("@dxos/context");
87
- var import_echo_schema4 = require("@dxos/echo-schema");
88
- var import_react_client2 = require("@dxos/react-client");
89
- var import_echo5 = require("@dxos/react-client/echo");
88
+ var import_live_object2 = require("@dxos/live-object");
90
89
  var import_schema = require("@dxos/schema");
90
+ var import_echo_schema4 = require("@dxos/echo-schema");
91
+ var import_react_client = require("@dxos/react-client");
92
+ var import_echo3 = require("@dxos/react-client/echo");
93
+ var import_schema2 = require("@dxos/schema");
91
94
  var import_signals_core3 = require("@preact/signals-core");
92
95
  var import_lodash = __toESM(require("lodash.orderby"));
93
96
  var import_echo_schema5 = require("@dxos/echo-schema");
@@ -99,20 +102,27 @@ var import_echo_schema6 = require("@dxos/echo-schema");
99
102
  var import_react_ui_form6 = require("@dxos/react-ui-form");
100
103
  var import_react_ui_grid3 = require("@dxos/react-ui-grid");
101
104
  var import_react_ui_theme2 = require("@dxos/react-ui-theme");
102
- var import_schema2 = require("@dxos/schema");
105
+ var import_schema3 = require("@dxos/schema");
103
106
  var import_react7 = __toESM(require("react"));
104
107
  var import_echo_schema7 = require("@dxos/echo-schema");
105
108
  var import_invariant3 = require("@dxos/invariant");
109
+ var import_react_ui7 = require("@dxos/react-ui");
110
+ var import_react_ui_editor = require("@dxos/react-ui-editor");
106
111
  var import_react_ui_grid4 = require("@dxos/react-ui-grid");
112
+ var import_react_ui_tag_picker = require("@dxos/react-ui-tag-picker");
107
113
  var import_autocomplete = require("@codemirror/autocomplete");
108
114
  var import_view = require("@codemirror/view");
109
115
  var import_react8 = __toESM(require("react"));
110
- var import_live_object2 = require("@dxos/live-object");
111
- var import_react_ui_menu = require("@dxos/react-ui-menu");
116
+ var import_react_ui8 = require("@dxos/react-ui");
117
+ var import_react_ui_theme3 = require("@dxos/react-ui-theme");
112
118
  var import_signals_core6 = require("@preact/signals-core");
113
119
  var import_react9 = require("react");
120
+ var import_echo4 = require("@dxos/react-client/echo");
114
121
  var import_react_ui_attention2 = require("@dxos/react-ui-attention");
115
122
  var import_util2 = require("@dxos/util");
123
+ var import_react10 = __toESM(require("react"));
124
+ var import_live_object3 = require("@dxos/live-object");
125
+ var import_react_ui_menu = require("@dxos/react-ui-menu");
116
126
  var translationKey = "table";
117
127
  var translations_default = [
118
128
  {
@@ -166,10 +176,10 @@ var ColumnActionsMenu = ({ model, modals }) => {
166
176
  }, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Item, {
167
177
  "data-testid": "column-clear-sort",
168
178
  onClick: () => model.sorting?.clearSort()
169
- }, t("column action clear sorting")), model.getColumnCount() > 1 && /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Item, {
179
+ }, t("column action clear sorting")), model.getColumnCount() > 1 && model.features.schemaEditable && /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Item, {
170
180
  "data-testid": "column-delete",
171
181
  onClick: () => model.deleteColumn(state.fieldId)
172
- }, t("column action delete")), /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Item, {
182
+ }, t("column action delete")), model.features.schemaEditable && /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Item, {
173
183
  "data-testid": "column-settings",
174
184
  onClick: () => modals.openColumnSettings()
175
185
  }, t("column action settings"))), /* @__PURE__ */ import_react2.default.createElement(import_react_ui2.DropdownMenu.Arrow, null))));
@@ -177,7 +187,7 @@ var ColumnActionsMenu = ({ model, modals }) => {
177
187
  var ColumnSettings = ({ model, modals, onNewColumn }) => {
178
188
  const [newField, setNewField] = (0, import_react3.useState)();
179
189
  const state = modals.state.value;
180
- const space = (0, import_echo2.getSpace)(model?.table);
190
+ const space = model?.space;
181
191
  (0, import_react3.useEffect)(() => {
182
192
  if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
183
193
  setNewField(model.projection.createFieldProjection());
@@ -195,12 +205,12 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
195
205
  if (state?.type === "columnSettings") {
196
206
  const { mode } = state;
197
207
  if (mode.type === "edit") {
198
- return model?.table?.view?.target?.fields.find((f) => f.id === mode.fieldId);
208
+ return model?.view?.fields.find((f) => f.id === mode.fieldId);
199
209
  }
200
210
  }
201
211
  return void 0;
202
212
  }, [
203
- model?.table?.view?.target?.fields,
213
+ model?.view?.fields,
204
214
  state
205
215
  ]);
206
216
  const field = existingField ?? newField;
@@ -218,7 +228,7 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
218
228
  state,
219
229
  newField
220
230
  ]);
221
- if (!model?.table?.view?.target || !model.projection || !field) {
231
+ if (!model?.view || !model.projection || !field) {
222
232
  return null;
223
233
  }
224
234
  return /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.DropdownMenu.Root, {
@@ -229,7 +239,7 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
229
239
  }), /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.DropdownMenu.Portal, null, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.DropdownMenu.Content, {
230
240
  classNames: "md:is-64"
231
241
  }, /* @__PURE__ */ import_react3.default.createElement(import_react_ui3.DropdownMenu.Viewport, null, /* @__PURE__ */ import_react3.default.createElement(import_react_ui_form.FieldEditor, {
232
- view: model.table.view.target,
242
+ view: model.view,
233
243
  projection: model.projection,
234
244
  field,
235
245
  registry: space?.db.schemaRegistry,
@@ -239,7 +249,7 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
239
249
  };
240
250
  var CreateRefPanel = ({ model, modals, __gridScope }) => {
241
251
  const { id: gridId } = (0, import_react_ui_grid2.useGridContext)("TableCellEditor", __gridScope);
242
- const space = (0, import_echo3.getSpace)(model?.table);
252
+ const space = model?.space;
243
253
  const state = modals.state.value;
244
254
  const schema = (0, import_react4.useMemo)(() => {
245
255
  if (!space || state?.type !== "createRefPanel") {
@@ -264,7 +274,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
264
274
  typename: state.typename
265
275
  }).runSync();
266
276
  if (schema2) {
267
- const obj = space.db.add((0, import_echo3.create)(schema2, values));
277
+ const obj = space.db.add((0, import_echo2.create)(schema2, values));
268
278
  state.onCreate?.(obj);
269
279
  }
270
280
  void modals.close();
@@ -280,7 +290,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
280
290
  }, [
281
291
  modals
282
292
  ]);
283
- if (!model?.table?.view || !model.projection) {
293
+ if (!model?.view || !model.projection) {
284
294
  return null;
285
295
  }
286
296
  return /* @__PURE__ */ import_react4.default.createElement(import_react_ui4.Popover.Root, {
@@ -312,10 +322,10 @@ var getRefTargetObj = (space, id) => {
312
322
  };
313
323
  var RefPanel = ({ model, modals }) => {
314
324
  const state = modals.state.value;
315
- const space = (0, import_echo4.getSpace)(model.table);
325
+ const space = model?.space;
316
326
  const targetObj = getRefTargetObj(space, state?.type === "refPanel" ? state.targetId : void 0);
317
327
  const schema = space && state?.type === "refPanel" ? space.db.schemaRegistry.getSchema(state.typename) : void 0;
318
- if (!model.table?.view || !model.projection) {
328
+ if (!model.view || !model.projection) {
319
329
  return null;
320
330
  }
321
331
  return /* @__PURE__ */ import_react5.default.createElement(import_react_ui5.Popover.Root, {
@@ -349,22 +359,99 @@ var RowActionsMenu = ({ model, modals }) => {
349
359
  onOpenChange: modals.close
350
360
  }, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.VirtualTrigger, {
351
361
  virtualRef: modals.trigger
352
- }), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Viewport, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Item, {
362
+ }), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Content, null, /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Viewport, null, model.features.dataEditable !== false && /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Item, {
353
363
  "data-testid": "row-menu-delete",
354
364
  onClick: () => model.deleteRow(state.rowIndex)
355
- }, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Arrow, null)));
365
+ }, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Item, {
366
+ key: action.id,
367
+ "data-testid": `row-action-${action.id}`,
368
+ onClick: () => {
369
+ modals.close();
370
+ model.handleRowAction(action.id, state.rowIndex);
371
+ }
372
+ }, t(action.translationKey)))), /* @__PURE__ */ import_react6.default.createElement(import_react_ui6.DropdownMenu.Arrow, null)));
373
+ };
374
+ var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
375
+ if (typename && properties) {
376
+ const schema2 = (0, import_schema.getSchemaFromPropertyDefinitions)(typename, properties);
377
+ return {
378
+ typename: schema2.typename,
379
+ jsonSchema: schema2.jsonSchema
380
+ };
381
+ } else if (schema) {
382
+ return {
383
+ typename: schema.typename,
384
+ jsonSchema: schema.jsonSchema
385
+ };
386
+ } else if (typename && jsonSchema) {
387
+ return {
388
+ typename,
389
+ jsonSchema
390
+ };
391
+ } else {
392
+ throw new Error("invalid properties");
393
+ }
394
+ };
395
+ var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
396
+ const view = (0, import_schema.createView)({
397
+ name: "dynamic-table",
398
+ typename,
399
+ jsonSchema,
400
+ ...properties && {
401
+ fields: properties.map((property) => property.name)
402
+ }
403
+ });
404
+ const table = (0, import_live_object2.create)(import_chunk_TGG6OZ54.TableType, {
405
+ name: "dynamic-table",
406
+ view: (0, import_live_object2.makeRef)(view)
407
+ });
408
+ const projection = new import_schema.ViewProjection(jsonSchema, view);
409
+ if (properties && view.fields) {
410
+ setProperties(view, projection, properties);
411
+ }
412
+ return {
413
+ table,
414
+ projection
415
+ };
416
+ };
417
+ var setProperties = (view, projection, properties) => {
418
+ for (const property of properties) {
419
+ const field = view.fields.find((field2) => field2.path === property.name);
420
+ if (field) {
421
+ if (property.size !== void 0) {
422
+ field.size = property.size;
423
+ }
424
+ if (property.title !== void 0) {
425
+ const fieldProjection = projection.getFieldProjection(field.id);
426
+ projection.setFieldProjection({
427
+ ...fieldProjection,
428
+ props: {
429
+ ...fieldProjection.props,
430
+ title: property.title
431
+ }
432
+ });
433
+ }
434
+ if (property.sort) {
435
+ const fieldId = field.id;
436
+ view.query.sort = [
437
+ {
438
+ fieldId,
439
+ direction: property.sort
440
+ }
441
+ ];
442
+ }
443
+ }
444
+ }
356
445
  };
357
446
  var touch = (value) => value;
358
- var initializeTable = async ({ space, table, initialRow = true, initialSchema }) => {
359
- if (initialSchema) {
360
- const schema = await space.db.schemaRegistry.query({
361
- typename: initialSchema
362
- }).firstOrUndefined();
447
+ var initializeTable = async ({ client, space, table, typename, initialRow = true }) => {
448
+ if (typename) {
449
+ const schema = await space.db.graph.getSchemaByTypename(typename, space.db);
363
450
  if (!schema) {
364
- throw new Error(`Schema not found: ${initialSchema}`);
451
+ throw new Error(`Schema not found: ${typename}`);
365
452
  }
366
- const fields = (0, import_schema.getSchemaProperties)(schema.ast).filter((prop) => prop.format !== import_echo_schema4.FormatEnum.Ref).map((prop) => prop.name);
367
- table.view = (0, import_echo5.makeRef)((0, import_schema.createView)({
453
+ const fields = (0, import_schema2.getSchemaProperties)(schema.ast).filter((prop) => prop.format !== import_echo_schema4.FormatEnum.Ref).map((prop) => prop.name);
454
+ table.view = (0, import_echo3.makeRef)((0, import_schema2.createView)({
368
455
  // TODO(ZaymonFC): Don't hardcode name?
369
456
  name: "View",
370
457
  typename: schema.typename,
@@ -373,68 +460,74 @@ var initializeTable = async ({ space, table, initialRow = true, initialSchema })
373
460
  }));
374
461
  return schema;
375
462
  } else {
376
- const ContactSchema = (0, import_echo_schema4.TypedObject)({
377
- typename: `example.com/type/${import_react_client2.PublicKey.random().truncate()}`,
378
- version: "0.1.0"
379
- })({
380
- name: import_echo_schema4.S.optional(import_echo_schema4.S.String).annotations({
381
- [import_echo_schema4.AST.TitleAnnotationId]: "Name"
382
- }),
383
- active: import_echo_schema4.S.optional(import_echo_schema4.S.Boolean),
384
- email: import_echo_schema4.S.optional(import_echo_schema4.Format.Email),
385
- salary: import_echo_schema4.S.optional(import_echo_schema4.Format.Currency()).annotations({
386
- [import_echo_schema4.AST.TitleAnnotationId]: "Salary"
387
- })
388
- });
389
- const [contactSchema] = await space.db.schemaRegistry.register([
463
+ const [schema] = await space.db.schemaRegistry.register([
390
464
  ContactSchema
391
465
  ]);
392
- table.view = (0, import_echo5.makeRef)((0, import_schema.createView)({
466
+ const fields = ContactFields;
467
+ table.view = (0, import_echo3.makeRef)((0, import_schema2.createView)({
393
468
  name: "View",
394
- typename: contactSchema.typename,
395
- jsonSchema: contactSchema.jsonSchema,
396
- fields: [
397
- "name",
398
- "email",
399
- "salary",
400
- "active"
401
- ]
469
+ typename: schema.typename,
470
+ jsonSchema: schema.jsonSchema,
471
+ fields
402
472
  }));
403
- const projection = new import_schema.ViewProjection(contactSchema, table.view.target);
404
- projection.setFieldProjection({
405
- field: {
406
- id: table.view.target.fields.find((f) => f.path === "salary").id,
407
- path: "salary",
408
- size: 150
409
- }
410
- });
411
- projection.setFieldProjection({
412
- field: {
413
- id: table.view.target.fields.find((f) => f.path === "active").id,
414
- path: "active",
415
- size: 100
416
- }
417
- });
418
- projection.setFieldProjection({
419
- field: {
420
- id: (0, import_schema.createFieldId)(),
421
- path: "manager",
422
- referencePath: "name"
423
- },
424
- props: {
425
- property: "manager",
426
- type: import_echo_schema4.TypeEnum.Ref,
427
- format: import_echo_schema4.FormatEnum.Ref,
428
- referenceSchema: contactSchema.typename,
429
- title: "Manager"
430
- }
431
- });
473
+ createProjection(schema, table.view.target);
432
474
  if (initialRow) {
433
- space.db.add((0, import_echo5.create)(contactSchema, {}));
475
+ space.db.add((0, import_echo3.create)(schema, {}));
434
476
  }
435
- return contactSchema;
477
+ return schema;
436
478
  }
437
479
  };
480
+ var ContactSchema = (0, import_echo_schema4.TypedObject)({
481
+ typename: `example.com/type/${import_react_client.PublicKey.random().truncate()}`,
482
+ version: "0.1.0"
483
+ })({
484
+ name: import_echo_schema4.S.optional(import_echo_schema4.S.String).annotations({
485
+ [import_echo_schema4.AST.TitleAnnotationId]: "Name"
486
+ }),
487
+ active: import_echo_schema4.S.optional(import_echo_schema4.S.Boolean),
488
+ email: import_echo_schema4.S.optional(import_echo_schema4.Format.Email),
489
+ salary: import_echo_schema4.S.optional(import_echo_schema4.Format.Currency()).annotations({
490
+ [import_echo_schema4.AST.TitleAnnotationId]: "Salary"
491
+ })
492
+ });
493
+ var ContactFields = [
494
+ "name",
495
+ "email",
496
+ "salary",
497
+ "active"
498
+ ];
499
+ var createProjection = (schema, view) => {
500
+ const projection = new import_schema2.ViewProjection(schema.jsonSchema, view);
501
+ projection.setFieldProjection({
502
+ field: {
503
+ id: view.fields.find((f) => f.path === "salary").id,
504
+ path: "salary",
505
+ size: 150
506
+ }
507
+ });
508
+ projection.setFieldProjection({
509
+ field: {
510
+ id: view.fields.find((f) => f.path === "active").id,
511
+ path: "active",
512
+ size: 100
513
+ }
514
+ });
515
+ projection.setFieldProjection({
516
+ field: {
517
+ id: (0, import_schema2.createFieldId)(),
518
+ path: "manager",
519
+ referencePath: "name"
520
+ },
521
+ props: {
522
+ property: "manager",
523
+ type: import_echo_schema4.TypeEnum.Ref,
524
+ format: import_echo_schema4.FormatEnum.Ref,
525
+ referenceSchema: schema.typename,
526
+ title: "Manager"
527
+ }
528
+ });
529
+ return projection;
530
+ };
438
531
  var BUTTON_IDENTIFIERS = {
439
532
  columnSettings: "data-table-column-settings-button",
440
533
  newColumn: "data-table-new-column-button",
@@ -563,7 +656,7 @@ var renderAttributes = (data) => {
563
656
  var renderInput = (baseClass, attrs, checked = false, disabled = false, preventToggle = false, testId) => {
564
657
  return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? "checked" : ""} ${preventToggle ? 'onclick="return false"' : ""} ${disabled ? "disabled" : ""} data-testid="${testId}"/>`;
565
658
  };
566
- var renderCheckbox = ({ rowIndex, header = false, checked = false, disabled = false }) => {
659
+ var CheckboxStory = ({ rowIndex, header = false, checked = false, disabled = false }) => {
567
660
  const attrs = {
568
661
  [CONTROL_IDENTIFIERS.checkbox]: "",
569
662
  "data-row-index": rowIndex.toString(),
@@ -573,7 +666,7 @@ var renderCheckbox = ({ rowIndex, header = false, checked = false, disabled = fa
573
666
  };
574
667
  return renderInput(BASE_CLASSES.checkbox, attrs, checked, disabled, true, "table-selection");
575
668
  };
576
- var renderSwitch = ({ colIndex, rowIndex, checked = false, disabled = false }) => {
669
+ var SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = false }) => {
577
670
  const attrs = {
578
671
  [CONTROL_IDENTIFIERS.switch]: "",
579
672
  "data-row-index": rowIndex.toString(),
@@ -584,7 +677,7 @@ var renderSwitch = ({ colIndex, rowIndex, checked = false, disabled = false }) =
584
677
  var tableControls = {
585
678
  checkbox: {
586
679
  attr: CONTROL_IDENTIFIERS.checkbox,
587
- render: renderCheckbox,
680
+ render: CheckboxStory,
588
681
  getData: (el) => ({
589
682
  type: "checkbox",
590
683
  rowIndex: Number(el.getAttribute("data-row-index")),
@@ -593,7 +686,7 @@ var tableControls = {
593
686
  },
594
687
  switch: {
595
688
  attr: CONTROL_IDENTIFIERS.switch,
596
- render: renderSwitch,
689
+ render: SwitchStory,
597
690
  getData: (el) => ({
598
691
  type: "switch",
599
692
  rowIndex: Number(el.getAttribute("data-row-index")),
@@ -602,9 +695,10 @@ var tableControls = {
602
695
  }
603
696
  };
604
697
  var SelectionModel = class extends import_context2.Resource {
605
- constructor(_rows, _onSelectionChanged) {
698
+ constructor(_rows, _selectionMode, _onSelectionChanged) {
606
699
  super();
607
700
  this._rows = _rows;
701
+ this._selectionMode = _selectionMode;
608
702
  this._onSelectionChanged = _onSelectionChanged;
609
703
  this._selection = (0, import_signals_core2.signal)(/* @__PURE__ */ new Set());
610
704
  this._validSelectedIds = (0, import_signals_core2.computed)(() => {
@@ -642,6 +736,9 @@ var SelectionModel = class extends import_context2.Resource {
642
736
  if (newSelection.has(row.id)) {
643
737
  newSelection.delete(row.id);
644
738
  } else {
739
+ if (this._selectionMode === "single") {
740
+ newSelection.clear();
741
+ }
645
742
  newSelection.add(row.id);
646
743
  }
647
744
  this._selection.value = newSelection;
@@ -678,6 +775,9 @@ var SelectionModel = class extends import_context2.Resource {
678
775
  get allRowsSeleted() {
679
776
  return this._allSelected;
680
777
  }
778
+ get selectionMode() {
779
+ return this._selectionMode;
780
+ }
681
781
  };
682
782
  var TableSorting = class {
683
783
  constructor(rows, _view, _projection) {
@@ -839,13 +939,20 @@ var TableSorting = class {
839
939
  }
840
940
  };
841
941
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
942
+ var defaultFeatures = {
943
+ selection: {
944
+ enabled: true,
945
+ mode: "multiple"
946
+ },
947
+ dataEditable: false,
948
+ schemaEditable: false
949
+ };
842
950
  var TableModel = class extends import_context.Resource {
843
- constructor({ table, projection, sorting = [], pinnedRows = {
951
+ constructor({ id, space, view, projection, features = {}, sorting = [], pinnedRows = {
844
952
  top: [],
845
953
  bottom: []
846
- }, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChanged }) {
954
+ }, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
847
955
  super();
848
- this.id = `table-model-${import_react_client.PublicKey.random().truncate()}`;
849
956
  this._visibleRange = (0, import_signals_core.signal)({
850
957
  start: {
851
958
  row: 0,
@@ -861,7 +968,7 @@ var TableModel = class extends import_context.Resource {
861
968
  this._rows.value = obj;
862
969
  };
863
970
  this.getRowCount = () => this._rows.value.length;
864
- this.getColumnCount = () => this.table.view?.target?.fields.length ?? 0;
971
+ this.getColumnCount = () => this._view?.fields.length ?? 0;
865
972
  this.insertRow = (rowIndex) => {
866
973
  const row = rowIndex !== void 0 ? this._sorting.getDataIndex(rowIndex) : this._rows.value.length;
867
974
  this._onInsertRow?.(row);
@@ -870,7 +977,7 @@ var TableModel = class extends import_context.Resource {
870
977
  const row = this._sorting.getDataIndex(rowIndex);
871
978
  const obj = this._rows.value[row];
872
979
  const objectsToDelete = [];
873
- if (this._selection.hasSelection.value) {
980
+ if (this.features.selection.enabled && this._selection.hasSelection.value) {
874
981
  const selectedRows = this._selection.getSelectedRows();
875
982
  objectsToDelete.push(...selectedRows);
876
983
  } else {
@@ -878,8 +985,18 @@ var TableModel = class extends import_context.Resource {
878
985
  }
879
986
  this._onDeleteRows?.(row, objectsToDelete);
880
987
  };
988
+ this.handleRowAction = (actionId, rowIndex) => {
989
+ if (!this._onRowAction) {
990
+ return;
991
+ }
992
+ const row = this._sorting.getDataIndex(rowIndex);
993
+ const data = this._rows.value[row];
994
+ if (data) {
995
+ this._onRowAction(actionId, data);
996
+ }
997
+ };
881
998
  this.getCellData = ({ col, row }) => {
882
- const fields = this.table.view?.target?.fields ?? [];
999
+ const fields = this._view?.fields ?? [];
883
1000
  if (col < 0 || col >= fields.length) {
884
1001
  return void 0;
885
1002
  }
@@ -908,7 +1025,7 @@ var TableModel = class extends import_context.Resource {
908
1025
  };
909
1026
  this.setCellData = ({ col, row }, value) => {
910
1027
  const rowIdx = this._sorting.getDataIndex(row);
911
- const fields = this.table.view?.target?.fields ?? [];
1028
+ const fields = this._view?.fields ?? [];
912
1029
  if (col < 0 || col >= fields.length) {
913
1030
  return;
914
1031
  }
@@ -931,22 +1048,45 @@ var TableModel = class extends import_context.Resource {
931
1048
  }
932
1049
  }
933
1050
  };
934
- this._table = table;
1051
+ this._id = id;
1052
+ this._space = space;
1053
+ this._view = view;
935
1054
  this._projection = projection;
936
- this._sorting = new TableSorting(this._rows, table.view?.target, projection);
1055
+ this._features = {
1056
+ ...defaultFeatures,
1057
+ ...features
1058
+ };
1059
+ (0, import_invariant2.invariant)(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
1060
+ F: __dxlog_file,
1061
+ L: 114,
1062
+ S: this,
1063
+ A: [
1064
+ "!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
1065
+ "'Single selection is not compatible with editable tables.'"
1066
+ ]
1067
+ });
1068
+ this._sorting = new TableSorting(this._rows, this._view, projection);
937
1069
  if (sorting.length > 0) {
938
1070
  const [sort] = sorting;
939
1071
  this._sorting.setSort(sort.fieldId, sort.direction);
940
1072
  }
941
1073
  this._pinnedRows = pinnedRows;
1074
+ this._rowActions = rowActions;
942
1075
  this._onInsertRow = onInsertRow;
943
1076
  this._onDeleteRows = onDeleteRows;
944
1077
  this._onDeleteColumn = onDeleteColumn;
945
1078
  this._onCellUpdate = onCellUpdate;
946
- this._onRowOrderChanged = onRowOrderChanged;
1079
+ this._onRowOrderChange = onRowOrderChange;
1080
+ this._onRowAction = onRowAction;
1081
+ }
1082
+ get id() {
1083
+ return this._id;
1084
+ }
1085
+ get space() {
1086
+ return this._space;
947
1087
  }
948
- get table() {
949
- return this._table;
1088
+ get view() {
1089
+ return this._view;
950
1090
  }
951
1091
  get projection() {
952
1092
  return this._projection;
@@ -954,19 +1094,31 @@ var TableModel = class extends import_context.Resource {
954
1094
  get rows() {
955
1095
  return this._sorting.sortedRows;
956
1096
  }
1097
+ get features() {
1098
+ return this._features;
1099
+ }
957
1100
  /**
958
1101
  * @reactive
959
1102
  */
960
1103
  get sorting() {
961
1104
  return this._sorting;
962
1105
  }
1106
+ /**
1107
+ * Gets the row data at the specified display index.
1108
+ */
1109
+ getRowAt(displayIndex) {
1110
+ if (displayIndex < 0 || displayIndex >= this._sorting.sortedRows.value.length) {
1111
+ return void 0;
1112
+ }
1113
+ return this._sorting.sortedRows.value[displayIndex];
1114
+ }
963
1115
  get pinnedRows() {
964
1116
  return this._pinnedRows;
965
1117
  }
966
1118
  get columnMeta() {
967
1119
  (0, import_invariant2.invariant)(this._columnMeta, void 0, {
968
1120
  F: __dxlog_file,
969
- L: 117,
1121
+ L: 183,
970
1122
  S: this,
971
1123
  A: [
972
1124
  "this._columnMeta",
@@ -982,18 +1134,21 @@ var TableModel = class extends import_context.Resource {
982
1134
  get isViewDirty() {
983
1135
  return this._sorting.isDirty;
984
1136
  }
1137
+ get rowActions() {
1138
+ return this._rowActions;
1139
+ }
985
1140
  //
986
1141
  // Initialisation
987
1142
  //
988
1143
  async _open() {
989
1144
  this.initializeColumnMeta();
990
1145
  this.initializeEffects();
991
- this._selection = new SelectionModel(this._sorting.sortedRows, () => this._onRowOrderChanged?.());
1146
+ this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", () => this._onRowOrderChange?.());
992
1147
  await this._selection.open(this._ctx);
993
1148
  }
994
1149
  initializeColumnMeta() {
995
1150
  this._columnMeta = (0, import_signals_core.computed)(() => {
996
- const fields = this._table.view?.target?.fields ?? [];
1151
+ const fields = this._view?.fields ?? [];
997
1152
  const meta = Object.fromEntries(fields.map((field, index) => [
998
1153
  index,
999
1154
  {
@@ -1021,7 +1176,7 @@ var TableModel = class extends import_context.Resource {
1021
1176
  initializeEffects() {
1022
1177
  const rowOrderWatcher = (0, import_signals_core.effect)(() => {
1023
1178
  touch(this._sorting.sortedRows.value);
1024
- this._onRowOrderChanged?.();
1179
+ this._onRowOrderChange?.();
1025
1180
  });
1026
1181
  this._ctx.onDispose(rowOrderWatcher);
1027
1182
  const rowEffectManager = (0, import_signals_core.effect)(() => {
@@ -1030,7 +1185,7 @@ var TableModel = class extends import_context.Resource {
1030
1185
  for (let row = start.row; row <= end.row; row++) {
1031
1186
  rowEffects.push((0, import_signals_core.effect)(() => {
1032
1187
  const obj = this._sorting.sortedRows.value[row];
1033
- this?._table?.view?.target?.fields.forEach((field) => touch((0, import_echo_schema3.getValue)(obj, field.path)));
1188
+ this._view?.fields.forEach((field) => touch((0, import_echo_schema3.getValue)(obj, field.path)));
1034
1189
  this._onCellUpdate?.({
1035
1190
  row,
1036
1191
  col: start.col,
@@ -1049,7 +1204,7 @@ var TableModel = class extends import_context.Resource {
1049
1204
  */
1050
1205
  updateCellData({ col, row }, update) {
1051
1206
  const dataRow = this._sorting.getDataIndex(row);
1052
- const fields = this.table.view?.target?.fields ?? [];
1207
+ const fields = this._view?.fields ?? [];
1053
1208
  const field = fields[col];
1054
1209
  const value = (0, import_echo_schema3.getValue)(this._rows.value[dataRow], field.path);
1055
1210
  const updatedValue = update(value);
@@ -1059,10 +1214,10 @@ var TableModel = class extends import_context.Resource {
1059
1214
  // Column Operations
1060
1215
  //
1061
1216
  deleteColumn(fieldId) {
1062
- if (!this.table.view) {
1217
+ if (!this._view) {
1063
1218
  return;
1064
1219
  }
1065
- const field = this.table.view.target?.fields.find((field2) => field2.id === fieldId);
1220
+ const field = this._view?.fields.find((field2) => field2.id === fieldId);
1066
1221
  if (field && this._onDeleteColumn) {
1067
1222
  this._onDeleteColumn(field.id);
1068
1223
  }
@@ -1071,7 +1226,7 @@ var TableModel = class extends import_context.Resource {
1071
1226
  // Resize
1072
1227
  //
1073
1228
  setColumnWidth(columnIndex, width) {
1074
- const fields = this.table.view?.target?.fields ?? [];
1229
+ const fields = this._view?.fields ?? [];
1075
1230
  if (columnIndex < fields.length) {
1076
1231
  const newWidth = Math.max(0, width);
1077
1232
  const field = fields[columnIndex];
@@ -1197,27 +1352,40 @@ var TablePresentation = class {
1197
1352
  this._visibleRange = _visibleRange;
1198
1353
  }
1199
1354
  getCells(range, plane) {
1355
+ let cells;
1200
1356
  switch (plane) {
1201
1357
  case "grid":
1202
1358
  this._visibleRange.value = range;
1203
- return this.getMainGridCells(range);
1359
+ cells = this.getMainGridCells(range);
1360
+ break;
1204
1361
  case "frozenRowsStart":
1205
- return this.getHeaderCells(range);
1362
+ cells = this.getHeaderCells(range);
1363
+ break;
1206
1364
  case "frozenColsStart":
1207
- return this.getSelectionColumnCells(range);
1365
+ cells = this.getSelectionColumnCells(range);
1366
+ break;
1208
1367
  case "frozenColsEnd":
1209
- return this.getActionColumnCells(range);
1368
+ cells = this.getActionColumnCells(range);
1369
+ break;
1210
1370
  case "fixedStartStart":
1211
- return this.getSelectAllCell();
1371
+ cells = this.getSelectAllCell();
1372
+ break;
1212
1373
  case "fixedStartEnd":
1213
- return this.getNewColumnCell();
1374
+ cells = this.getNewColumnCell();
1375
+ break;
1214
1376
  default:
1215
- return {};
1377
+ cells = {};
1216
1378
  }
1379
+ if (plane === "grid" && this.model.features.dataEditable === false) {
1380
+ Object.values(cells).forEach((cell) => {
1381
+ cell.readonly = "text-select";
1382
+ });
1383
+ }
1384
+ return cells;
1217
1385
  }
1218
1386
  getMainGridCells(range) {
1219
1387
  const cells = {};
1220
- const fields = this.model.table.view?.target?.fields ?? [];
1388
+ const fields = this.model.view?.fields ?? [];
1221
1389
  const addCell = (obj, field, colIndex, displayIndex) => {
1222
1390
  const { props } = this.model.projection.getFieldProjection(field.id);
1223
1391
  const cell = {
@@ -1228,7 +1396,8 @@ var TablePresentation = class {
1228
1396
  }
1229
1397
  switch (props.format) {
1230
1398
  case import_echo_schema6.FormatEnum.Boolean:
1231
- case import_echo_schema6.FormatEnum.SingleSelect: {
1399
+ case import_echo_schema6.FormatEnum.SingleSelect:
1400
+ case import_echo_schema6.FormatEnum.MultiSelect: {
1232
1401
  return "";
1233
1402
  }
1234
1403
  case import_echo_schema6.FormatEnum.Ref: {
@@ -1255,7 +1424,7 @@ var TablePresentation = class {
1255
1424
  if (formatClasses) {
1256
1425
  classes.push(formatClasses);
1257
1426
  }
1258
- const rowSelectionClasses = (0, import_react_ui_form6.cellClassesForRowSelection)(this.model.selection.isObjectSelected(obj));
1427
+ const rowSelectionClasses = cellClassesForRowSelection(this.model.selection.isObjectSelected(obj), this.model.selection.selectionMode);
1259
1428
  if (rowSelectionClasses) {
1260
1429
  classes.push(rowSelectionClasses);
1261
1430
  }
@@ -1278,7 +1447,7 @@ var TablePresentation = class {
1278
1447
  rowIndex: displayIndex,
1279
1448
  checked: value ?? false
1280
1449
  });
1281
- cell.readonly = true;
1450
+ cell.readonly = "no-text-select";
1282
1451
  }
1283
1452
  if (props.format === import_echo_schema6.FormatEnum.SingleSelect) {
1284
1453
  const value = (0, import_echo_schema6.getValue)(obj, field.path);
@@ -1290,6 +1459,22 @@ var TablePresentation = class {
1290
1459
  }
1291
1460
  }
1292
1461
  }
1462
+ if (props.format === import_echo_schema6.FormatEnum.MultiSelect) {
1463
+ const values = (0, import_echo_schema6.getValue)(obj, field.path);
1464
+ const options = this.model.projection.getFieldProjection(field.id).props.options;
1465
+ if (options && values && values.length > 0) {
1466
+ const tags = values.map((value) => {
1467
+ const option = options.find((o) => o.id === value);
1468
+ if (option) {
1469
+ return `<span class="dx-tag" data-hue="${option.color}">${option.title}</span>`;
1470
+ }
1471
+ return null;
1472
+ }).filter(Boolean).join(" ");
1473
+ if (tags) {
1474
+ cell.accessoryHtml = tags;
1475
+ }
1476
+ }
1477
+ }
1293
1478
  const idx = (0, import_react_ui_grid3.toPlaneCellIndex)({
1294
1479
  col: colIndex,
1295
1480
  row: displayIndex
@@ -1309,7 +1494,7 @@ var TablePresentation = class {
1309
1494
  }
1310
1495
  getHeaderCells(range) {
1311
1496
  const cells = {};
1312
- const fields = this.model.table.view?.target?.fields ?? [];
1497
+ const fields = this.model.view?.fields ?? [];
1313
1498
  for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
1314
1499
  const { field, props } = this.model.projection.getFieldProjection(fields[col].id);
1315
1500
  const sorting = this.model.sorting?.sorting;
@@ -1340,13 +1525,13 @@ var TablePresentation = class {
1340
1525
  const cells = {};
1341
1526
  for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
1342
1527
  const isSelected = this.model.selection.isRowIndexSelected(row);
1343
- const classes = (0, import_react_ui_form6.cellClassesForRowSelection)(isSelected);
1528
+ const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
1344
1529
  cells[(0, import_react_ui_grid3.toPlaneCellIndex)({
1345
1530
  col: 0,
1346
1531
  row
1347
1532
  })] = {
1348
1533
  value: "",
1349
- readonly: true,
1534
+ readonly: "no-text-select",
1350
1535
  className: classes ? (0, import_react_ui_theme2.mx)(classes) : void 0,
1351
1536
  accessoryHtml: tableControls.checkbox.render({
1352
1537
  rowIndex: row,
@@ -1360,7 +1545,7 @@ var TablePresentation = class {
1360
1545
  const cells = {};
1361
1546
  for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
1362
1547
  const isSelected = this.model.selection.isRowIndexSelected(row);
1363
- const classes = (0, import_react_ui_form6.cellClassesForRowSelection)(isSelected);
1548
+ const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
1364
1549
  cells[(0, import_react_ui_grid3.toPlaneCellIndex)({
1365
1550
  col: 0,
1366
1551
  row
@@ -1376,6 +1561,18 @@ var TablePresentation = class {
1376
1561
  return cells;
1377
1562
  }
1378
1563
  getSelectAllCell() {
1564
+ if (!this.model.features.selection.enabled || this.model.selection.selectionMode === "single") {
1565
+ return {
1566
+ [(0, import_react_ui_grid3.toPlaneCellIndex)({
1567
+ col: 0,
1568
+ row: 0
1569
+ })]: {
1570
+ className: "!bg-gridHeader",
1571
+ readonly: true,
1572
+ value: ""
1573
+ }
1574
+ };
1575
+ }
1379
1576
  return {
1380
1577
  [(0, import_react_ui_grid3.toPlaneCellIndex)({
1381
1578
  col: 0,
@@ -1398,9 +1595,9 @@ var TablePresentation = class {
1398
1595
  col: 0,
1399
1596
  row: 0
1400
1597
  })]: {
1401
- accessoryHtml: tableButtons.addColumn.render({
1402
- disabled: (this.model.table.view?.target?.fields?.length ?? 0) >= import_schema2.VIEW_FIELD_LIMIT
1403
- }),
1598
+ accessoryHtml: this.model.features.schemaEditable ? tableButtons.addColumn.render({
1599
+ disabled: (this.model.view?.fields?.length ?? 0) >= import_schema3.VIEW_FIELD_LIMIT
1600
+ }) : void 0,
1404
1601
  className: "!bg-gridHeader",
1405
1602
  readonly: true,
1406
1603
  value: ""
@@ -1408,6 +1605,28 @@ var TablePresentation = class {
1408
1605
  };
1409
1606
  }
1410
1607
  };
1608
+ var cellClassesForRowSelection = (selected, selectionMode) => {
1609
+ if (!selected) {
1610
+ if (selectionMode === "single") {
1611
+ return [
1612
+ "!cursor-pointer"
1613
+ ];
1614
+ } else {
1615
+ return void 0;
1616
+ }
1617
+ }
1618
+ switch (selectionMode) {
1619
+ case "single":
1620
+ return [
1621
+ "!bg-currentRelated hover:bg-hoverSurface",
1622
+ "!cursor-pointer"
1623
+ ];
1624
+ case "multiple":
1625
+ return [
1626
+ "!bg-gridCellSelected"
1627
+ ];
1628
+ }
1629
+ };
1411
1630
  var completion = ({ debug, onQuery, onMatch }) => {
1412
1631
  return [
1413
1632
  import_view.EditorView.theme({
@@ -1453,6 +1672,7 @@ var isCreateOption = (data) => typeof data === "object" && data[newValue];
1453
1672
  var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
1454
1673
  const { id: gridId, editing, setEditing } = (0, import_react_ui_grid4.useGridContext)("TableCellEditor", __gridScope);
1455
1674
  const suppressNextBlur = (0, import_react7.useRef)(false);
1675
+ const { themeMode } = (0, import_react_ui7.useThemeContext)();
1456
1676
  const fieldProjection = (0, import_react7.useMemo)(() => {
1457
1677
  if (!model || !editing) {
1458
1678
  return;
@@ -1462,7 +1682,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1462
1682
  const fieldProjection2 = model.projection.getFieldProjection(field.id);
1463
1683
  (0, import_invariant3.invariant)(fieldProjection2, void 0, {
1464
1684
  F: __dxlog_file3,
1465
- L: 67,
1685
+ L: 71,
1466
1686
  S: void 0,
1467
1687
  A: [
1468
1688
  "fieldProjection",
@@ -1485,7 +1705,10 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1485
1705
  setEditing(null);
1486
1706
  }, [
1487
1707
  model,
1488
- editing
1708
+ editing,
1709
+ onEnter,
1710
+ onFocus,
1711
+ setEditing
1489
1712
  ]);
1490
1713
  const handleBlur = (0, import_react7.useCallback)((value) => {
1491
1714
  if (!model || !editing) {
@@ -1517,9 +1740,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1517
1740
  editing,
1518
1741
  onFocus,
1519
1742
  onEnter,
1520
- fieldProjection,
1521
- determineNavigationAxis,
1522
- determineNavigationDelta
1743
+ fieldProjection
1523
1744
  ]);
1524
1745
  const extension = (0, import_react7.useMemo)(() => {
1525
1746
  if (!fieldProjection) {
@@ -1533,6 +1754,37 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1533
1754
  }
1534
1755
  })
1535
1756
  ];
1757
+ const format = fieldProjection.props.format;
1758
+ if (format === import_echo_schema7.FormatEnum.SingleSelect || format === import_echo_schema7.FormatEnum.MultiSelect) {
1759
+ extension2.push((0, import_react_ui_editor.createMarkdownExtensions)({
1760
+ themeMode
1761
+ }));
1762
+ const options = fieldProjection.props.options || [];
1763
+ const mode = format === import_echo_schema7.FormatEnum.SingleSelect ? "single-select" : "multi-select";
1764
+ extension2.push((0, import_react_ui_tag_picker.tagPickerExtension)({
1765
+ mode,
1766
+ inGrid: true,
1767
+ onSearch: (text, selectedIds) => {
1768
+ return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
1769
+ id: option.id,
1770
+ label: option.title,
1771
+ hue: option.color
1772
+ }));
1773
+ },
1774
+ onUpdate: (ids) => {
1775
+ if (model && editing) {
1776
+ if (ids.length === 0) {
1777
+ return;
1778
+ }
1779
+ if (mode === "single-select") {
1780
+ handleEnter(ids[0]);
1781
+ } else {
1782
+ handleEnter(ids);
1783
+ }
1784
+ }
1785
+ }
1786
+ }));
1787
+ }
1536
1788
  if (onQuery) {
1537
1789
  switch (fieldProjection.props.format) {
1538
1790
  case import_echo_schema7.FormatEnum.Ref: {
@@ -1568,11 +1820,49 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
1568
1820
  modals,
1569
1821
  editing,
1570
1822
  fieldProjection,
1571
- handleClose
1823
+ handleClose,
1824
+ themeMode
1572
1825
  ]);
1573
1826
  const getCellContent = (0, import_react7.useCallback)(() => {
1574
1827
  if (model && editing) {
1575
- const value = model.getCellData((0, import_react_ui_grid4.parseCellIndex)(editing.index));
1828
+ const cell = (0, import_react_ui_grid4.parseCellIndex)(editing.index);
1829
+ const { col } = cell;
1830
+ const field = model.projection.view.fields[col];
1831
+ const fieldProjection2 = model.projection.getFieldProjection(field.id);
1832
+ if (fieldProjection2?.props.format === import_echo_schema7.FormatEnum.SingleSelect || fieldProjection2?.props.format === import_echo_schema7.FormatEnum.MultiSelect) {
1833
+ const value2 = model.getCellData(cell);
1834
+ if (value2 !== void 0) {
1835
+ const options = fieldProjection2.props.options || [];
1836
+ if (fieldProjection2.props.format === import_echo_schema7.FormatEnum.MultiSelect && Array.isArray(value2)) {
1837
+ const tagItems = value2.map((id) => {
1838
+ const option = options.find((o) => o.id === id);
1839
+ if (option) {
1840
+ return {
1841
+ id,
1842
+ label: option.title,
1843
+ hue: option.color
1844
+ };
1845
+ }
1846
+ return void 0;
1847
+ }).filter((item) => item !== void 0);
1848
+ return (0, import_react_ui_tag_picker.createLinks)(tagItems);
1849
+ } else {
1850
+ const option = options.find((o) => o.id === value2);
1851
+ if (option) {
1852
+ const tagItem = {
1853
+ id: value2,
1854
+ label: option.title,
1855
+ hue: option.color
1856
+ };
1857
+ return (0, import_react_ui_tag_picker.createLinks)([
1858
+ tagItem
1859
+ ]);
1860
+ }
1861
+ }
1862
+ }
1863
+ return "";
1864
+ }
1865
+ const value = model.getCellData(cell);
1576
1866
  return value !== void 0 ? String(value) : "";
1577
1867
  }
1578
1868
  }, [
@@ -1612,27 +1902,40 @@ var determineNavigationDelta = ({ key, shift }) => {
1612
1902
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
1613
1903
  var inlineEndLine = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator";
1614
1904
  var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator";
1615
- var frozen = {
1616
- frozenRowsStart: 1,
1617
- frozenColsStart: 1,
1618
- frozenColsEnd: 1
1619
- };
1620
1905
  var TableRoot = ({ children, role }) => {
1621
1906
  return /* @__PURE__ */ import_react.default.createElement("div", {
1622
1907
  role: "none",
1623
- className: (0, import_react_ui_theme.mx)("relative border-bs !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]")
1908
+ className: (0, import_react_ui_theme.mx)("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]")
1624
1909
  }, children);
1625
1910
  };
1626
- var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentation, ignoreAttention }, forwardedRef) => {
1911
+ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentation, ignoreAttention, onRowClick }, forwardedRef) => {
1627
1912
  const [dxGrid, setDxGrid] = (0, import_react.useState)(null);
1628
- const { hasAttention } = (0, import_react_ui_attention.useAttention)(model?.table ? (0, import_echo.fullyQualifiedId)(model.table) : "table");
1913
+ const { hasAttention } = (0, import_react_ui_attention.useAttention)(model?.id ?? "table");
1629
1914
  const { t } = (0, import_react_ui.useTranslation)(translationKey);
1630
1915
  const modals = (0, import_react.useMemo)(() => new ModalController(), []);
1916
+ const frozen = (0, import_react.useMemo)(() => {
1917
+ const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
1918
+ return {
1919
+ frozenRowsStart: 1,
1920
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
1921
+ frozenColsEnd: noActionColumn ? 0 : 1
1922
+ };
1923
+ }, [
1924
+ model
1925
+ ]);
1926
+ (0, import_react.useEffect)(() => {
1927
+ if (!presentation || !dxGrid) {
1928
+ return;
1929
+ }
1930
+ dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
1931
+ }, [
1932
+ presentation,
1933
+ dxGrid
1934
+ ]);
1631
1935
  (0, import_react.useImperativeHandle)(forwardedRef, () => {
1632
1936
  if (!presentation || !dxGrid) {
1633
1937
  return {};
1634
1938
  }
1635
- dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
1636
1939
  return {
1637
1940
  update: (cell) => {
1638
1941
  if (cell) {
@@ -1648,6 +1951,16 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1648
1951
  dxGrid
1649
1952
  ]);
1650
1953
  const handleGridClick = (0, import_react.useCallback)((event) => {
1954
+ const rowIndex = (0, import_util.safeParseInt)(event.target.ariaRowIndex ?? "");
1955
+ if (rowIndex != null) {
1956
+ if (onRowClick) {
1957
+ const row = model?.getRowAt(rowIndex);
1958
+ row && onRowClick(row);
1959
+ }
1960
+ if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
1961
+ model.selection.toggleSelectionForRowIndex(rowIndex);
1962
+ }
1963
+ }
1651
1964
  if (!modals) {
1652
1965
  return;
1653
1966
  }
@@ -1724,6 +2037,9 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1724
2037
  dxGrid
1725
2038
  ]);
1726
2039
  const handleEnter = (0, import_react.useCallback)((cell) => {
2040
+ if (!model?.features.dataEditable) {
2041
+ return;
2042
+ }
1727
2043
  if (model && cell.row === model.getRowCount() - 1) {
1728
2044
  model.insertRow(cell.row);
1729
2045
  if (dxGrid) {
@@ -1738,6 +2054,9 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1738
2054
  dxGrid
1739
2055
  ]);
1740
2056
  const handleKeyDown = (0, import_react.useCallback)((event) => {
2057
+ if (!model?.features.dataEditable) {
2058
+ return;
2059
+ }
1741
2060
  const cell = (0, import_react_ui_grid.closestCell)(event.target);
1742
2061
  if (!model || !cell) {
1743
2062
  return;
@@ -1779,10 +2098,10 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1779
2098
  ]);
1780
2099
  const handleQuery = (0, import_react.useCallback)(async ({ field, props }, text) => {
1781
2100
  if (model && props.referenceSchema && field.referencePath) {
1782
- const space = (0, import_echo.getSpace)(model.table);
2101
+ const space = model.space;
1783
2102
  (0, import_invariant.invariant)(space, void 0, {
1784
2103
  F: __dxlog_file4,
1785
- L: 264,
2104
+ L: 312,
1786
2105
  S: void 0,
1787
2106
  A: [
1788
2107
  "space",
@@ -1815,7 +2134,8 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1815
2134
  }
1816
2135
  return [];
1817
2136
  }, [
1818
- model
2137
+ model,
2138
+ t
1819
2139
  ]);
1820
2140
  if (!model || !modals) {
1821
2141
  return /* @__PURE__ */ import_react.default.createElement("span", {
@@ -1824,7 +2144,7 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1824
2144
  });
1825
2145
  }
1826
2146
  return /* @__PURE__ */ import_react.default.createElement(import_react_ui_grid.Grid.Root, {
1827
- id: model.table.id ?? "table-grid"
2147
+ id: model.id ?? "table-grid"
1828
2148
  }, /* @__PURE__ */ import_react.default.createElement(TableCellEditor, {
1829
2149
  model,
1830
2150
  modals,
@@ -1832,16 +2152,17 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1832
2152
  onFocus: handleFocus,
1833
2153
  onQuery: handleQuery
1834
2154
  }), /* @__PURE__ */ import_react.default.createElement(import_react_ui_grid.Grid.Content, {
1835
- onWheelCapture: handleWheel,
1836
2155
  className: (0, import_react_ui_theme.mx)("[--dx-grid-base:var(--surface-bg)]", inlineEndLine, blockEndLine),
1837
2156
  frozen,
2157
+ // getCells={getCells}
1838
2158
  columns: model.columnMeta.value,
1839
2159
  limitRows: model.getRowCount() ?? 0,
1840
- limitColumns: model.table.view?.target?.fields?.length ?? 0,
2160
+ limitColumns: model.view?.fields?.length ?? 0,
2161
+ overscroll: "trap",
1841
2162
  onAxisResize: handleAxisResize,
1842
2163
  onClick: handleGridClick,
1843
2164
  onKeyDown: handleKeyDown,
1844
- overscroll: "trap",
2165
+ onWheelCapture: handleWheel,
1845
2166
  ref: setDxGrid
1846
2167
  }), /* @__PURE__ */ import_react.default.createElement(RowActionsMenu, {
1847
2168
  model,
@@ -1853,10 +2174,10 @@ var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, presentat
1853
2174
  model,
1854
2175
  modals,
1855
2176
  onNewColumn: handleNewColumn
1856
- }), /* @__PURE__ */ import_react.default.createElement(RefPanel, {
2177
+ }), /* @__PURE__ */ import_react.default.createElement(CreateRefPanel, {
1857
2178
  model,
1858
2179
  modals
1859
- }), /* @__PURE__ */ import_react.default.createElement(CreateRefPanel, {
2180
+ }), /* @__PURE__ */ import_react.default.createElement(RefPanel, {
1860
2181
  model,
1861
2182
  modals
1862
2183
  }));
@@ -1865,6 +2186,133 @@ var Table = {
1865
2186
  Root: TableRoot,
1866
2187
  Main: TableMain
1867
2188
  };
2189
+ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
2190
+ const [model, setModel] = (0, import_react9.useState)();
2191
+ (0, import_react9.useEffect)(() => {
2192
+ if (!table || !projection) {
2193
+ return;
2194
+ }
2195
+ let model2;
2196
+ const t = setTimeout(async () => {
2197
+ model2 = new TableModel({
2198
+ id: (0, import_echo4.fullyQualifiedId)(table),
2199
+ space: (0, import_echo4.getSpace)(table),
2200
+ view: table.view?.target,
2201
+ projection,
2202
+ features,
2203
+ rowActions,
2204
+ onRowAction,
2205
+ ...props
2206
+ });
2207
+ await model2.open();
2208
+ setModel(model2);
2209
+ });
2210
+ return () => {
2211
+ clearTimeout(t);
2212
+ void model2?.close();
2213
+ };
2214
+ }, [
2215
+ table,
2216
+ projection,
2217
+ table?.view?.target,
2218
+ features,
2219
+ rowActions
2220
+ ]);
2221
+ (0, import_react9.useEffect)(() => {
2222
+ if (rows) {
2223
+ model?.setRows(rows);
2224
+ }
2225
+ }, [
2226
+ model,
2227
+ rows
2228
+ ]);
2229
+ const { select, clear } = (0, import_react_ui_attention2.useSelectionActions)([
2230
+ table?.id,
2231
+ table?.view?.target?.query.typename
2232
+ ].filter(import_util2.isNonNullable));
2233
+ (0, import_react9.useEffect)(() => {
2234
+ if (!model) {
2235
+ return;
2236
+ }
2237
+ const unsubscribe = (0, import_signals_core6.effect)(() => {
2238
+ const selectedItems = [
2239
+ ...model.selection.selection.value
2240
+ ];
2241
+ select(selectedItems);
2242
+ onSelectionChanged?.(selectedItems);
2243
+ });
2244
+ return () => {
2245
+ clear();
2246
+ unsubscribe();
2247
+ };
2248
+ }, [
2249
+ model,
2250
+ onSelectionChanged
2251
+ ]);
2252
+ return model;
2253
+ };
2254
+ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
2255
+ const { table, projection } = (0, import_react8.useMemo)(() => {
2256
+ const props2 = getBaseSchems({
2257
+ typename: name,
2258
+ properties,
2259
+ jsonSchema,
2260
+ schema
2261
+ });
2262
+ return makeDynamicTable({
2263
+ ...props2,
2264
+ properties
2265
+ });
2266
+ }, [
2267
+ name,
2268
+ properties,
2269
+ schema,
2270
+ jsonSchema
2271
+ ]);
2272
+ const tableRef = (0, import_react8.useRef)(null);
2273
+ const handleCellUpdate = (0, import_react8.useCallback)((cell) => {
2274
+ tableRef.current?.update?.(cell);
2275
+ }, []);
2276
+ const handleRowOrderChange = (0, import_react8.useCallback)(() => {
2277
+ tableRef.current?.update?.();
2278
+ }, []);
2279
+ const features = (0, import_react_ui8.useDefaultValue)(props.features, () => ({
2280
+ selection: {
2281
+ enabled: false
2282
+ },
2283
+ dataEditable: false
2284
+ }));
2285
+ const model = useTableModel({
2286
+ table,
2287
+ rows,
2288
+ projection,
2289
+ features,
2290
+ rowActions,
2291
+ onCellUpdate: handleCellUpdate,
2292
+ onRowOrderChange: handleRowOrderChange,
2293
+ onRowAction
2294
+ });
2295
+ const presentation = (0, import_react8.useMemo)(() => {
2296
+ if (model) {
2297
+ return new TablePresentation(model);
2298
+ }
2299
+ }, [
2300
+ model
2301
+ ]);
2302
+ return /* @__PURE__ */ import_react8.default.createElement("div", {
2303
+ role: "none",
2304
+ className: (0, import_react_ui_theme3.mx)("is-full bs-full grow grid", classNames)
2305
+ }, /* @__PURE__ */ import_react8.default.createElement("div", {
2306
+ role: "none",
2307
+ className: "grid min-bs-0 overflow-hidden"
2308
+ }, /* @__PURE__ */ import_react8.default.createElement(Table.Root, null, /* @__PURE__ */ import_react8.default.createElement(Table.Main, {
2309
+ ref: tableRef,
2310
+ model,
2311
+ presentation,
2312
+ ignoreAttention: true,
2313
+ onRowClick
2314
+ }))));
2315
+ };
1868
2316
  var createTableToolbarActions = (state) => {
1869
2317
  const add = (0, import_react_ui_menu.createMenuAction)("add-row", {
1870
2318
  type: "add-row",
@@ -1917,89 +2365,39 @@ var createTableToolbarActions = (state) => {
1917
2365
  };
1918
2366
  };
1919
2367
  var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
1920
- const state = (0, import_react8.useMemo)(() => (0, import_live_object2.create)({
2368
+ const state = (0, import_react10.useMemo)(() => (0, import_live_object3.create)({
1921
2369
  viewDirty
1922
2370
  }), []);
1923
- const actionsCreator = (0, import_react8.useCallback)(() => createTableToolbarActions(state), [
2371
+ const actionsCreator = (0, import_react10.useCallback)(() => createTableToolbarActions(state), [
1924
2372
  state
1925
2373
  ]);
1926
2374
  const menu = (0, import_react_ui_menu.useMenuActions)(actionsCreator);
1927
- return /* @__PURE__ */ import_react8.default.createElement(import_react_ui_menu.MenuProvider, {
2375
+ return /* @__PURE__ */ import_react10.default.createElement(import_react_ui_menu.MenuProvider, {
1928
2376
  ...menu,
1929
2377
  attendableId,
1930
2378
  onAction
1931
- }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui_menu.ToolbarMenu, {
2379
+ }, /* @__PURE__ */ import_react10.default.createElement(import_react_ui_menu.ToolbarMenu, {
1932
2380
  classNames
1933
2381
  }));
1934
2382
  };
1935
- var useTableModel = ({ objects, table, projection, ...props }) => {
1936
- const [model, setModel] = (0, import_react9.useState)();
1937
- (0, import_react9.useEffect)(() => {
1938
- if (!table || !projection) {
1939
- return;
1940
- }
1941
- let model2;
1942
- const t = setTimeout(async () => {
1943
- model2 = new TableModel({
1944
- table,
1945
- projection,
1946
- ...props
1947
- });
1948
- await model2.open();
1949
- setModel(model2);
1950
- });
1951
- return () => {
1952
- clearTimeout(t);
1953
- void model2?.close();
1954
- };
1955
- }, [
1956
- table,
1957
- projection
1958
- ]);
1959
- (0, import_react9.useEffect)(() => {
1960
- if (objects) {
1961
- model?.setRows(objects);
1962
- }
1963
- }, [
1964
- model,
1965
- objects
1966
- ]);
1967
- const { select, clear } = (0, import_react_ui_attention2.useSelectionActions)([
1968
- table?.id,
1969
- table?.view?.target?.query.typename
1970
- ].filter(import_util2.isNonNullable));
1971
- (0, import_react9.useEffect)(() => {
1972
- if (!model) {
1973
- return;
1974
- }
1975
- const unsubscribe = (0, import_signals_core6.effect)(() => {
1976
- select([
1977
- ...model.selection.selection.value
1978
- ]);
1979
- });
1980
- return () => {
1981
- clear();
1982
- unsubscribe();
1983
- };
1984
- }, [
1985
- model
1986
- ]);
1987
- return model;
1988
- };
1989
2383
  // Annotate the CommonJS export names for ESM import in node:
1990
2384
  0 && (module.exports = {
1991
2385
  BUTTON_IDENTIFIERS,
1992
2386
  CONTROL_IDENTIFIERS,
2387
+ CheckboxStory,
2388
+ DynamicTable,
1993
2389
  ModalController,
2390
+ SwitchStory,
1994
2391
  Table,
1995
2392
  TableModel,
1996
2393
  TablePresentation,
1997
2394
  TableSchema,
1998
2395
  TableToolbar,
1999
2396
  TableType,
2397
+ cellClassesForRowSelection,
2398
+ getBaseSchems,
2000
2399
  initializeTable,
2001
- renderCheckbox,
2002
- renderSwitch,
2400
+ makeDynamicTable,
2003
2401
  tableButtons,
2004
2402
  tableControls,
2005
2403
  touch,